123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206 |
- #include "stdafx.h"
- #include <tlhelp32.h>
- #include "SysLib.h"
- #include <io.h>
- #include <odbcinst.h>
- #include <afxdb.h>
- #include "resource.h"
- #include "crc32.h"
- #include <odbcinst.h>
- //增加自动启动注册表项
- INT AddAutoSysRun(CHAR *strExeFile, INT iAutoRunSystem)
- {
- HKEY hKey = NULL;
- DWORD dwErrorCode = 0;
-
- //创建注册表,有该键则读取,无则创建
- dwErrorCode = RegCreateKeyEx(HKEY_LOCAL_MACHINE,
- "Software\\Microsoft\\Windows\\CurrentVersion\\Run",
- 0,
- NULL,
- REG_OPTION_NON_VOLATILE,
- KEY_ALL_ACCESS,
- NULL, //Security
- &hKey,
- NULL);
- if (dwErrorCode == ERROR_SUCCESS)
- {
- if (iAutoRunSystem)
- dwErrorCode = RegSetValueEx(hKey, "DataBase Monitor Service", NULL, REG_SZ, (BYTE*)strExeFile, strlen(strExeFile));
- else
- dwErrorCode = RegDeleteKey(hKey, "DataBase Monitor Service");
- }
- if (NULL != hKey)
- RegCloseKey(hKey);
- hKey = NULL;
- return 0;
- }
- int Handle_DeleteTrayNullIcon( BOOL &bNullBeDel )
- {
- bNullBeDel = FALSE;
- HWND hStatus=::FindWindow("Shell_TrayWnd",NULL); //得到任务栏句柄
- if (hStatus==NULL)
- {
- //AfxMessageBox ( "Get Shell_TrayWnd error!" );
- return -1;
- }
- HWND hNotify=FindWindowEx(hStatus,NULL,"TrayNotifyWnd",NULL); //右下角区域
- if (hNotify==NULL)
- {
- //AfxMessageBox ( "Get TrayNotifyWnd error!" );
- return -1;
- }
- HWND hNotify1=FindWindowEx(hNotify,NULL,"SysPager",NULL);
- if (hNotify==NULL)
- {
- //AfxMessageBox ( "Get SysPager error!" );
- return -1;
- }
- HWND hNotify1_0=FindWindowEx(hNotify1,NULL,"ToolBarWindow32",NULL);//右下角区域(不包括时间)
- if (hNotify1_0==NULL)
- {
- //AfxMessageBox ( "Get ToolBarWindow32 error!" );
- return -1;
- }
- //-------------------以上是得到任务栏右下脚一块地方的句柄
- DWORD pid = 0;
- GetWindowThreadProcessId(hNotify1_0,&pid);
- if (pid==NULL)
- {
- //AfxMessageBox ( "Get pid error!" );
- return -1;
- }
-
- HANDLE hProcess=OpenProcess(PROCESS_QUERY_INFORMATION|PROCESS_ALL_ACCESS,true,pid);
- if (hProcess==NULL)
- {
- //AfxMessageBox ( "Get hd error!" );
- return -1;
- }
- ::SendMessage(hNotify1_0,WM_PAINT ,NULL,NULL);
- CRect rect;
- ::GetWindowRect(hNotify1_0,&rect);
- ::InvalidateRect(hNotify1_0,&rect,false);
- int iNum=::SendMessage(hNotify1_0,TB_BUTTONCOUNT ,NULL,NULL); //获取任务栏上图标个数
-
- unsigned long n = 0;
- TBBUTTON *pButton = new TBBUTTON;
- CString strInfo = _T("");
- wchar_t name[256] = {0};
- TBBUTTON BButton;
- unsigned long whd,proid;
- CString x;
-
- for(int i=0; i<iNum; i++)
- {
- ::SendMessage(hNotify1_0,TB_GETBUTTON,i,(LPARAM)(&BButton));
- ReadProcessMemory(hProcess,&BButton,pButton,sizeof(TBBUTTON),&n);
- if (pButton->iString != 0xffffffff)
- {
- try
- {
- ReadProcessMemory(hProcess,(void *)pButton->iString,name,255,&n);
- }
- catch(...)
- {
- }
- strInfo.Format("%d : %s\n",i+1,CString(name));
- TRACE(strInfo);
- }
-
- try
- {
- whd=0;
- ReadProcessMemory(hProcess,(void *)pButton->dwData,&whd,4,&n);
- }
- catch(...)
- {
- }
- proid=NULL;
- GetWindowThreadProcessId((HWND)whd,&proid);
- if(proid==NULL)
- {
- bNullBeDel = TRUE;
- ::SendMessage(hNotify1_0,TB_DELETEBUTTON,i,0);
- }
- }
- delete pButton;
- return 0;
- }
- int GetSysData()
- {
- CHAR strFile[MAX_FILE_LENGTH + 1] = "";
- CHAR strValue[MAX_VALUE_LENGTH + 1] = "";
- int iPosFile = 0;
- int iLenghtFile = 0;
- ////////////////////////////////////////////////////////////////////////////
- //获取应用名
- GetModuleFileName(AfxGetApp()->m_hInstance, g_strDirectory, MAX_PATH_LENGTH);
- iLenghtFile = strlen(g_strDirectory);
- for (iPosFile = iLenghtFile - 1; iPosFile >= 0; iPosFile--)
- {
- if (g_strDirectory[iPosFile] == '\\')
- {
- memset(g_strAppName, 0, sizeof(g_strAppName));
- memcpy(g_strAppName, g_strDirectory + iPosFile + 1, iLenghtFile - iPosFile - 1);
- break;
- }
- }
-
- //获取系统路径
- //#ifdef _DEBUG
- // GetCurrentDirectory(MAX_PATH_LENGTH, g_strDirectory);
- //#else
- GetModuleFileName(AfxGetApp()->m_hInstance, g_strDirectory, MAX_PATH_LENGTH);
- iLenghtFile = strlen(g_strDirectory);
- for (iPosFile = iLenghtFile - 1; iPosFile >= 0; iPosFile--)
- {
- if (g_strDirectory[iPosFile] == '\\')
- {
- g_strDirectory[iPosFile] = '\0';
- break;
- }
- }
- //#endif
- wsprintf(strFile, "%s\\set.ini", g_strDirectory);
- //Server
- GetPrivateProfileString("Server", "ServerIP", "", g_strServerIP, sizeof(g_strServerIP), strFile);
- GetPrivateProfileString("Server", "Port", "", g_strServerPort, sizeof(g_strServerPort), strFile);
- int nSTDOUT = GetPrivateProfileInt("Server", "StdOut", 0, strFile);
- if ( nSTDOUT == 1 )
- {
- AllocConsole(); // 开辟控制台;
- SetConsoleTitle(_T("EMSoftClient调试输出")); // 设置控制台窗口标题;
- freopen("CONOUT$", "w+t", stdout); // 重定向输出;
- freopen("CONIN$", "r+t", stdin); // 重定向输入;
- HWND hWnd = NULL;
- again:
- hWnd = ::FindWindow(NULL, _T("EMSoftClient调试输出"));
- if( hWnd )
- {
- if (!::SetWindowPos(hWnd, HWND_TOPMOST, 0,0,0,0, SWP_NOMOVE | SWP_NOSIZE))
- {
- printf(_T("前置设置失败\n"));
- }
- else
- {
- printf(_T("前置设置成功\n"));
- }
- }
- else
- {
- if (nSTDOUT <= 10)
- goto again;
- }
- }
- //是否自动启动系统
- GetPrivateProfileString("Other", "AutoRunSystem", "", strValue, sizeof(strValue), strFile);
- if (strcmp(strValue, ""))
- g_iAutoRunSystem = atoi(strValue);
- else
- g_iAutoRunSystem = 0;
- if (g_iAutoRunSystem <= 0)
- g_iAutoRunSystem = 0;
- else
- g_iAutoRunSystem = 1;
- GetPrivateProfileString("User", "UserID", "", g_strLoginUserID, sizeof(g_strLoginUserID), strFile);
- GetPrivateProfileString("User", "UserPwd", "", g_strLoginPwd, sizeof(g_strLoginPwd), strFile);
- //检查控制,设置是否有密码
- GetPrivateProfileString("User", "HaveControlPwd","", strValue,sizeof(strValue), strFile );
- g_bHaveControlPwd = atoi( strValue );
- g_nIsDemo = GetPrivateProfileInt("Other", "IsDemo", 0, strFile);
- //RunParam
- g_nIsPoll = GetPrivateProfileInt("RunParam", "IsPoll", 0, strFile);
- g_nPollInterval = GetPrivateProfileInt("RunParam", "PollInterval", 1, strFile);
- g_nPollCount = GetPrivateProfileInt("Poll", "PollCount", 0, strFile);
- CString strPollPath, strPollDesc;
- for( int i = 1; i < g_nPollCount + 1; i++ )
- {
- if( i > MAX_VIEW_NUM - 1 ) break;
- strPollPath.Format("PollPath%d", i);
- GetPrivateProfileString("Poll",
- (char *)(LPCTSTR)strPollPath, "", g_strPollPath[i-1], sizeof(g_strPollPath[i-1]), strFile);
-
- strPollDesc.Format("PollDesc%d", i);
- GetPrivateProfileString("Poll",
- (char *)(LPCTSTR)strPollDesc, "", g_strPollDesc[i-1], sizeof(g_strPollDesc[i-1]), strFile);
- }
- //语言
- GetPrivateProfileString("Other", "Language", "", g_strLanguage, sizeof(g_strLanguage), strFile);
- //Database
- GetPrivateProfileString("Database", "DBType", "", g_strDBType, sizeof(g_strDBType), strFile);
-
- GetPrivateProfileString("Database", "AccessFile", "", g_strAccessFile, sizeof(g_strAccessFile), strFile);
-
- GetPrivateProfileString("Database", "ServerName", "", g_strServerName, sizeof(g_strServerName), strFile);
-
- GetPrivateProfileString("Database", "DataBaseName", "", g_strDataBaseName, sizeof(g_strDataBaseName), strFile);
-
- GetPrivateProfileString("Database", "UserName", "", g_strUserName, sizeof(g_strUserName), strFile);
-
- GetPrivateProfileString("Database", "Password", "", g_strPassword, sizeof(g_strPassword), strFile);
- g_dwDataBasePort = GetPrivateProfileInt("Database", "DataBasePort", 5432, strFile);
- //数据库连接串
- if (!_stricmp(g_strDBType, "SQL SERVER"))
- sprintf(g_strConnectString, "Provider=sqloledb;Data Source=%s,1433;Initial Catalog=%s;User Id=%s;Password=%s; ",
- g_strServerName, g_strDataBaseName, g_strUserName, g_strPassword);
- else if (!_stricmp(g_strDBType, "ACCESS97"))
- sprintf(g_strConnectString, "Provider=Microsoft.Jet.OLEDB.3.51;Data Source=%s", g_strAccessFile);
- else if (!_stricmp(g_strDBType, "ACCESS2000"))
- sprintf(g_strConnectString, "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=%s", g_strAccessFile);
- else if(!_stricmp(g_strDBType, "PGSQL"))
- sprintf(g_strConnectString, "DRIVER={PostgreSQL ODBC Driver(UNICODE)}; SERVER=%s; port=%d; DATABASE=%s; UID=%s; PWD=%s;",
- g_strServerName, g_dwDataBasePort, g_strDataBaseName, g_strUserName, g_strPassword);
- else
- sprintf(g_strConnectString, "Provider=sqloledb;Data Source=%s;Initial Catalog=%s;User Id=%s;Password=%s; ",
- g_strServerName, g_strDataBaseName, g_strUserName, g_strPassword);
- //用户信息
- GetPrivateProfileString("User", "UserID", "", g_strDefaultUserID, sizeof(g_strDefaultUserID), strFile);
- GetPrivateProfileString("User", "UserPwd", "", g_strDefaultUserPwd, sizeof(g_strDefaultUserPwd), strFile);
- //自动跳到报警画面
- g_nAlarmToView = GetPrivateProfileInt("AlarmMode", "AlarmToView", 0, strFile);;
- //AlarmMode
- g_nAlarmModeIsDlg = GetPrivateProfileInt("AlarmMode", "Dlg", 0, strFile);
- g_nAlarmModeIsSound = GetPrivateProfileInt("AlarmMode", "Sound", 0, strFile);
- g_nAlarmModeSoundPlayNum = GetPrivateProfileInt("AlarmMode", "PlayNum", 0, strFile);
- g_nAlarmModeSoundPlayNum += 1;
- //Comm
- g_nCommDlgLevel = GetPrivateProfileInt("Common", "LevelDlg", 0, strFile);;
- g_nCommWavLevel = GetPrivateProfileInt("Common", "LevelLocalWav", 0, strFile);;
- //TTS
- g_nTTSType = GetPrivateProfileInt("TTS", "VoiceType", 0, strFile);
- //视频采集卡
- GetPrivateProfileString("Video", "CapPath", "", g_strVideoCapPath, sizeof(g_strVideoCapPath), strFile);
- CString str;
- str = CString(g_strVideoCapPath);
- str.Replace("\\", "\\\\");
- strcpy(g_strVideoCapPath, (char *)(LPCTSTR)str);
- //Toolbar显示状态
- g_nToolbarTop = GetPrivateProfileInt("Toolbar", "ToolBarTop", 0, strFile);
- g_nToolbarLeft = GetPrivateProfileInt("Toolbar", "ToolBarLeft", 0, strFile);
- g_nToolbarRun = GetPrivateProfileInt("Toolbar", "ToolBarRun", 0, strFile);
- g_nToolBarStatus = GetPrivateProfileInt("Toolbar", "ToolBarStatus", 0, strFile);
- ////////////////////////////////////////////////////////////////////////////
- //增加自动启动注册表项
- #if 0
- wsprintf(strFile, "%s\\%s", g_strDirectory, g_strAppName);
- AddAutoSysRun(strFile, g_iAutoRunSystem);
- #endif
- return 0;
- }
- int GetResourceString()
- {
- g_strSet.LoadString(IDS_SET);
- g_strAdjust.LoadString(IDS_ADJUST);
- g_strPictureLink.LoadString(IDS_PICTURELINK);
- g_strExit.LoadString(IDS_EXIT);
- g_strExLink.LoadString(IDS_EXLINK);
- g_strTestAlarm.LoadString(IDS_TESTALARM);
- g_strAlarmRed.LoadString(IDS_COMMOND_ALARM_RED);
- g_strNoticeRed.LoadString(IDS_COMMOND_NOTICE_RED);
- g_strDeviceLog.LoadString(IDS_COMMOND_DEVICE_LOG);
- g_strSystemLog.LoadString(IDS_COMMOND_SYSTEM_LOG);
- g_strVarManage.LoadString(IDS_COMMOND_VAR_MANAGE);
- g_strUserManage.LoadString(IDS_COMMOND_USER_MANAGE);
- g_strPwdManage.LoadString(IDS_COMMOND_PWD_MANAGE);
- g_strFirstPage.LoadString(IDS_COMMOND_FIRST_PAGE);
- g_strNativageTree.LoadString(IDS_COMMOND_NATIVAGE_TREE);
- g_strVarTypeID.LoadString(IDS_VARTYPEID);
- g_strSelLine.LoadString(IDS_SELLINE);
- g_strVarID.LoadString(IDS_VARID);
- g_strVarUid1.LoadString(IDS_VARUID1);
- g_strVarName1.LoadString(IDS_VARNAME1);
- g_strVarDesc.LoadString(IDS_VARDESC);
- g_strVarDataLen.LoadString(IDS_VARDATALEN);
- g_strOnDesc.LoadString(IDS_ONDESC);
- g_strOffDesc.LoadString(IDS_OFFDESC);
- g_strMaxValues.LoadString(IDS_MAXVALUES);
- g_strMinValues.LoadString(IDS_MINVALUES);
- g_strMaxScale.LoadString(IDS_MAXSCALE);
- g_strMinScale.LoadString(IDS_MINSCALE);
- g_strLowerLimit.LoadString(IDS_LOWERLIMIT);
- g_strUpperLimit.LoadString(IDS_UPPERLIMIT);
- g_strNormalState.LoadString(IDS_NORMALSTATE);
- g_strSetValue.LoadString(IDS_SETVALUE);
- g_strRearm.LoadString(IDS_REARM);
- g_strOffset.LoadString(IDS_OFFSET);
- g_strUint.LoadString(IDS_UNIT);
- g_strCollectFreq.LoadString(IDS_COLLECTFREQ);
- g_strCoef.LoadString(IDS_COEF);
- g_strAlarmLevel.LoadString(IDS_ALARMLEVEL);
- g_strReadWrite.LoadString(IDS_READWRITE);
- g_strSaveData.LoadString(IDS_SAVEDATA);
- g_strCollectThreadData.LoadString(IDS_COLLECTTHRADDATA);
- g_strSaveCurve.LoadString(IDS_SAVECURVE);
- g_strIsDDE.LoadString(IDS_ISDDE);
- g_strRegNum.LoadString(IDS_REGNUM);
- g_strFuncID.LoadString(IDS_FUNCID);
- g_strChildID.LoadString(IDS_CHILDID);
- g_strItemID.LoadString(IDS_ITEMID);
- g_strSnmpOid.LoadString(IDS_SNMPOID);
- g_strSnmpPublic.LoadString(IDS_SNMPPUBLIC);
- g_strDevTypeID.LoadString(IDS_DEVTYPEID);
- g_strVarStartAddr.LoadString(IDS_VARSTARTADDR);
- g_strRs232Cmd.LoadString(IDS_RS232CMD);
- g_strRs232Type.LoadString(IDS_RS232TYPE);
- g_strRs232Index.LoadString(IDS_RS232INDEX);
- g_strIndentifyTime.LoadString(IDS_IDENTIFYTIME);
- g_strRedectTime.LoadString(IDS_REDETECTTIME);
- g_strReturnNormalAlarm.LoadString(IDS_RETURNNORMALTOTRIPALARM);
- g_strShowCurrValue.LoadString(IDS_SHOWCURRVALUE);
- g_strAlarmVarName.LoadString(IDS_ALARMVARNAME);
- g_strVarUidIsBlank.LoadString(IDS_VARUIDISBLANK);
- g_strVarNameIsBlank.LoadString(IDS_PARAMNAME_CANNOTBLANK);
- g_strVarNameExist.LoadString(IDS_VARNAMEEXIST);
- g_strVarName2.LoadString(IDS_VARNAME2);
- g_strSelDev.LoadString(IDS_SELDEV);
- g_strStoneuTech.LoadString(IDS_STONEU_TECH);
- g_strPictureFile1.LoadString(IDS_PICTUREFILE1);
- g_strCannotLoseAllForm.LoadString(IDS_CANNOTCLOSEALLFORM);
- g_strStartBit.LoadString(IDS_STARTBIT);
- g_strEndBit.LoadString(IDS_ENDBIT);
- g_strVarBitExist.LoadString(IDS_VARBITEXIST);
- g_strSelDevice.LoadString(IDS_SELDEV);
- g_strOldPasswordCannotBlank.LoadString(IDS_OLDPASSWORDCANNOTBLANK);
- g_strOldpasswordInCorrect.LoadString(IDS_OLDPASSWORDINCORRECT);
- g_strpasswordInCorrect.LoadString(IDS_PASSWORDINCORRECT);
- g_strPasswordNotMatch1.LoadString(IDS_PASSWORDNOTMATCH1);
- g_strAll.LoadString(IDS_ALL);
- g_strDevName.LoadString(IDS_DEVNAME);
- g_strHappentTime1.LoadString(IDS_HAPPENTIME1);
- g_strEventArea.LoadString( IDS_EVENTAREA );
- g_strCurrValue.LoadString(IDS_CURRVALUE);
- g_strDateTime.LoadString(IDS_DATETIME);
- g_strHappenTime2.LoadString(IDS_HAPPENTIME2);
- g_strWarnContent.LoadString(IDS_WARNCONTENT);
- g_strAllDev.LoadString(IDS_ALLDEV);
- g_strEthernet.LoadString(IDS_ETHERNET);
- g_strMywizard.LoadString(IDS_MYWIZARD);
- g_strDevNameInUse.LoadString(IDS_DEVNAMEINUSE);
- g_strUserID.LoadString(IDS_USERID);
- g_strHintUserName.LoadString(IDS_USERNAME);
- g_strTel.LoadString(IDS_TEL);
- g_strMobile.LoadString(IDS_MOBIL);
- g_strFax.LoadString(IDS_FAX);
- g_strMail.LoadString(IDS_EMAIL);
- g_strStatus.LoadString(IDS_STATUS);
- g_strUserPwd.LoadString(IDS_USERPWD);
- g_strUserNameCannotEmpty.LoadString(IDS_USERNAMECANNOTEMPTY);
- g_strPasswordNotMatch2.LoadString(IDS_PASSWORDNOTMATCH2);
- g_strUserNameExit.LoadString(IDS_USERNAMEEXIT);
- g_strID.LoadString(IDS_ID);
- g_strDevUid2.LoadString(IDS_DEVUID2);
- g_strAlarmStatus.LoadString(IDS_ALARMSTATUS);
- g_strAlarmStatusDesc.LoadString(IDS_ALARMSTATUSDESC);
- g_strNormalStatusID.LoadString(IDS_NORMALSTATUSID);
- g_strAlarmStatusIDCannotEmpty.LoadString(IDS_ALARMSTATUSIDCANNOTEMPTY);
- g_strAlarmStatusDescCannotEmpty.LoadString(IDS_ALARMSTATUSDESCCANNOTEMPTY);
- g_strNormalStatusIDCannotBlank.LoadString(IDS_NORMALSTATUSIDCANNOTBLANK);
- g_strAlarmStatusInfoExist.LoadString(IDS_ALARMSTATUSINFOEXIST);
- g_strTimesNewRoman.LoadString(IDS_TIMESNEWROMAN);
- g_strEntityProperty.LoadString(IDS_ENTITYPROPERTY);
- g_strParamSet.LoadString(IDS_PARAMSET);
- g_strHour.LoadString(IDS_HOUR);
- g_strDate.LoadString(IDS_DATE);
- g_strMean.LoadString(IDS_MEAN);
- g_strControl.LoadString(IDS_CONTROL);
- g_strTRACE0.LoadString(IDS_TRACE0);
- g_strAppwizardCreateApp.LoadString(IDS_APPWIZARDCREATAPP);
- g_strPictureFile2.LoadString(IDS_PICTUREFILE2);
- g_strSaveModify.LoadString(IDS_SAVEMODIFY);
- g_strStoneuIspcms.LoadString(IDS_STONEU_ISPCMS);
- g_strUnSelectEntity.LoadString(IDS_UNSELECTENTITY);
- g_strIsNotPrimitive.LoadString(IDS_ISNOTPRIMITIVE);
- g_strSelect.LoadString(IDS_SELECT);
- g_strTrace2.LoadString(IDS_TRACE);
- g_strTline.LoadString(IDS_TLINE);
- g_strText.LoadString(IDS_TEXT);
- g_strRect.LoadString(IDS_RECT);
- g_strOval.LoadString(IDS_OVAL);
- g_strButton.LoadString(IDS_BUTTON);
- g_strData.LoadString(IDS_DATA);
- g_strLed.LoadString(IDS_LED);
- g_strBar.LoadString(IDS_BAR);
- g_strCurve.LoadString(IDS_CURVE);
- g_strLine.LoadString(IDS_LINE);
- g_strBreaker.LoadString(IDS_BREAKER);
- g_strSwitch.LoadString(IDS_SWITCH);
- g_strGrid.LoadString(IDS_GRID);
- g_strBitmap.LoadString(IDS_BITMAP);
- g_strGif.LoadString(IDS_GIF);
- g_strTransfer.LoadString(IDS_TRANSFER);
- g_strArc.LoadString(IDS_ARC);
- g_strArrow.LoadString(IDS_ARROW);
- g_strPoly.LoadString(IDS_POLY);
- g_strMLine.LoadString(IDS_MLINE);
- g_strPipe.LoadString(IDS_PIPE);
- g_strZhePipe.LoadString(IDS_ZHEPIPE);
- g_strYPipe.LoadString(IDS_YPIPE);
- g_strWatch.LoadString(IDS_WATCH);
- g_strSingleBar.LoadString(IDS_SINGLEBAR);
- g_strRoundRect.LoadString(IDS_ROUNDRECT);
- g_strPie.LoadString(IDS_PIE);
- g_strFan.LoadString(IDS_FAN);
- g_strHisCurve.LoadString(IDS_HISCURVE);
- g_strTable.LoadString(IDS_TABLE);
- g_strComposite.LoadString(IDS_COMPOSITE);
- g_strConnectionFailed.LoadString(IDS_CONNECTIONFAILED);
- g_strMoniterSite.LoadString(IDS_MONITORSITE);
- g_strDevice.LoadString(IDS_DEVICE);
- g_strSerial.LoadString(IDS_SERIAL);
- g_strDataDict.LoadString(IDS_DATADICT);
- g_strVarSet.LoadString(IDS_VARSET);
- g_strScriptManage.LoadString(IDS_SCRIPTMANAGE);
- g_strActionWithAlarm.LoadString( IDS_ACTIONWITHALARM );
- g_strNoticeList.LoadString( IDS_STRING_NOTICELIST );
- g_strSysParam.LoadString(IDS_SYSPARAM);
- g_strExitConfirm.LoadString(IDS_EXITCONFIRM);
- g_strIPComoccupy.LoadString(IDS_IPCOMOCCUPY);
- g_strDevNumCannotBlank.LoadString(IDS_DEVNAMCANNOTBLANK);
- g_strDevUidExist.LoadString(IDS_DEVUIDEXIST);
- g_strDevNameExist.LoadString(IDS_DEVNAMEEXIST);
- g_strSerialPortInUse.LoadString(IDS_SERIALPORTINUSE);
- g_strIPNotBlank.LoadString(IDS_IPNOTBLANK);
- g_strComcanNot0.LoadString(IDS_COMCANNOT0);
- g_strNetDev.LoadString(IDS_NETDEV);
- g_strIPConflict.LoadString(IDS_IPCONFLICT);
- g_strCannotCreateDirecitory.LoadString(IDS_CANNOTCREATEDIRECTORY);
- g_strDelDev.LoadString(IDS_DELDEV);
- g_strDelView.LoadString(IDS_DELVIEW);
- g_strConfirm.LoadString(IDS_CONFIRM);
- g_strEventType.LoadString(IDS_EVENTTYPE);
- g_strEventInfo.LoadString(IDS_EVENTINFO);
- g_strLowAlarm.LoadString(IDS_LOWALARM);
- g_strHighAlarm.LoadString(IDS_UPALARM);
- g_strReturnNormal1.LoadString(IDS_RETURNNORMAL1);
- g_strReturnNormal2.LoadString(IDS_RETURNNORMAL2);
- g_strAlarm.LoadString(IDS_ALARM);
- g_strTime.LoadString(IDS_TIME);
- g_strVarName3.LoadString(IDS_VARNAME3);
- g_strColumnName.LoadString(IDS_COLUMNNAME);
- g_strHeader.LoadString(IDS_HEADER);
- g_strFormat.LoadString(IDS_FORMAT);
- g_strScriptPass.LoadString(IDS_SCRIPTPASS);
- g_strScriptNameCannotEmpty.LoadString(IDS_SCRIPTNAMECANNOTEMPTY);
- g_strStrVar.LoadString(IDS_STRVAR);
- g_strDes.LoadString(IDS_DES);
- g_strOne.LoadString(IDS_ONE);
- g_strTwo.LoadString(IDS_TWO);
- g_strThree.LoadString(IDS_THREE);
- g_strFour.LoadString(IDS_FOUR);
- g_strFine.LoadString(IDS_FINE);
- g_strSix.LoadString(IDS_SIX);
- g_strSeven.LoadString(IDS_SEVEN);
- g_strEight.LoadString(IDS_EIGHT);
- g_strNine.LoadString(IDS_NINE);
- g_strTen.LoadString(IDS_TEN);
- g_strHandred.LoadString(IDS_HUNDRED);
- g_strBilion.LoadString(IDS_BILLION);
- g_strWan.LoadString(IDS_WAN);
- g_strThousand.LoadString(IDS_THOUSAND);
- g_strYuan1.LoadString(IDS_YUAN1);
- g_strCent.LoadString(IDS_CENT);
- g_strZero.LoadString(IDS_ZERO);
- g_strMinute.LoadString(IDS_MINUTE);
- g_strYuan2.LoadString(IDS_YUAN2);
- g_strDevDataLog.LoadString(IDS_DEVDATALOG);
- g_strOverWriteError.LoadString(IDS_OVERWRITEERROR);
- g_strSaveas.LoadString(IDS_SAVEAS);
- g_strTip.LoadString(IDS_TIP);
- g_strScriptError.LoadString(IDS_SCRIPT_ERROR);
- g_strLogicDoorinate.LoadString(IDS_LOGIC_COORDINATE);
- g_strFontNameCHT.LoadString(IDS_FONT_CHT);
- g_strCharacter.LoadString(IDS_CHARACTER);
- g_strNormal.LoadString(IDS_NORMAL);
- g_strIsNotice.LoadString(IDS_IS_NOTICE);
- g_strIsModify.LoadString(IDS_IS_MODIFY);
- g_strParamInit.LoadString(IDS_PARAM_INIT);
- g_strParamMin.LoadString(IDS_PARAM_MIN);
- g_strParamMax.LoadString(IDS_PARAM_MAX);
- g_strOCX.LoadString( IDS_OCX );
- g_strGIF.LoadString( IDS_GIF );
- g_strFlash.LoadString( IDS_FLASH );
- g_strRadio.LoadString( IDS_RADIO);
- g_strCheck.LoadString( IDS_CHECK);
- g_strLogType.LoadString( IDS_LOG_TYPE );
- g_strModbusType.LoadString( IDS_LOG_MODBUSTYPE );
- g_strLogContent.LoadString( IDS_LOG_CONTENT );
- g_strLogHappenTime.LoadString( IDS_LOG_HAPPENTIME );
- g_strPastDue.LoadString( IDS_PROMPT_PASTDUE );
- g_strEditMoreVarOK.LoadString( IDS_PROMPT_EDITMOREVAROK );
- g_strGroup.LoadString( IDS_GROUP );
- g_strDClickFirstOperate.LoadString( IDS_PROMPT_DCLICKFIRSTOPERATE );
- g_strDelGroup.LoadString( IDS_PROMPT_COMFIR_DELGROUP );
- g_strNormalData.LoadString( IDS_NORMALDATA );
- g_strAlarmData.LoadString( IDS_ALARMDATA );
- g_strDealStatus.LoadString( IDS_DEALSTATUS );
- g_strAC_WaitConfig.LoadString( IDS_AC_WAITCONFIG );
- g_strAC_ConfigSuccess.LoadString( IDS_AC_CONFIGSUCCESS );
- g_strAC_WaitOut.LoadString( IDS_AC_WAITOUT );
- g_strAC_ConfigAllEvent.LoadString( IDS_AC_CONFIGALLEVENT );
- g_strAC_ConfigChooseEvent.LoadString( IDS_AC_CONFIGCHOOSEEVENT );
- g_strAC_DelAllEvent.LoadString( IDS_AC_DELALLEVENT );
- g_strAC_DelChooseEvent.LoadString( IDS_AC_DELCHOOSEEVENT );
- g_strAdd.LoadString( IDS_ADD );
- g_strEdit.LoadString( IDS_EDIT );
- g_strDel.LoadString( IDS_DEL );
- g_strDevice1.LoadString( IDS_DEVICE );
- g_strVariant.LoadString( IDS_VARIANT );
- g_strUser.LoadString( IDS_USER );
- g_strPwd.LoadString( IDS_PWD );
- g_strTimePlan.LoadString( IDS_TIMEPLAN );
- g_strRegiserOCX.LoadString( IDS_PROMPT_REGISEROCX );
- g_strNoPermit.LoadString( IDS_NO_PERMIT );
- g_strModifyPwdOK.LoadString( IDS_MODIFY_PWD_OK );
- g_strMonitorNameIsBlank.LoadString( IDS_MONITOR_BLANK );
- g_strMonitorNameCannotDel.LoadString( IDS_MONITOR_CANNOTDEL );
- g_strInputIsBlank.LoadString( IDS_CANNOT_BLANK );
- //界面语言,读取资源文件定义
- g_strLogTypeEvent.LoadString( IDS_EVENT_LOG );
- g_strLogTypeData.LoadString( IDS_DATA_LOG_TYPE );
- g_strLogTypeError.LoadString( IDS_LOG_TYPE_ERROR );
- g_strLogTypeWarning.LoadString( IDS_LOG_TYPE_WARNING );
- g_strLogModMainThread.LoadString( IDS_LOGMOD_MAIN_THREAD );
- g_strLogModDB.LoadString( IDS_LOGMOD_DB );
- g_strLogModEmail.LoadString( IDS_LOGMOD_EMAIL );
- g_strLogModSms.LoadString( IDS_LOGMOD_SMS );
- g_strLogModPing.LoadString( IDS_LOGMOD_PING );
- g_strLogModTrap.LoadString( IDS_LOGMOD_TRAP );
- g_strLogModSnmp.LoadString( IDS_LOGMOD_SNMP );
- g_strLogModDog.LoadString( IDS_LOGMOD_DOG );
- g_strLogModNotice.LoadString( IDS_LOGMOD_NOTICE );
- g_strLogModContents.LoadString( IDS_SEND_CONTENTS );
- g_strLogModTime.LoadString( IDS_SEND_TIME );
- //错误提示字符串
- CString strError, strMsgHint;
- strError.LoadString( IDS_ERROR_EXEC_SQL );
- strcpy(g_strErrorExecSql, (char*)(LPCTSTR)strError );
- strError.LoadString( IDS_ERROR_DB_DISCONNECTION );
- strcpy(g_strErrorDBDisConnection, (char*)(LPCTSTR)strError );
- //操作提示
- strMsgHint.LoadString( IDS_PROMPT_USERNAME_NOTNULL );
- strcpy(g_strMsgUserNotNULL, (char*)(LPCTSTR)strMsgHint);
- strMsgHint.LoadString( IDS_PROMPT_PWD_NOT_NULL );
- strcpy(g_strMsgPwdNotNULL, (char*)(LPCTSTR)strMsgHint);
- strMsgHint.LoadString( IDS_PROMPT_USER_INVALID );
- strcpy(g_strMsgUserInvalid, (char*)(LPCTSTR)strMsgHint);
- strMsgHint.LoadString( IDS_PROMPT_CONFIRM_DEL );
- strcpy(g_strMsgConfirmDel, (char*)(LPCTSTR)strMsgHint);
- strMsgHint.LoadString( IDS_PROMPT_SELECT_DEL );
- strcpy(g_strMsgSelectDel, (char*)(LPCTSTR)strMsgHint);
- strMsgHint.LoadString( IDS_PROMPT_EDIT_SUCCESS );
- strcpy(g_strMsgEditSuccess, (char*)(LPCTSTR)strMsgHint);
- strMsgHint.LoadString( IDS_PROMPT_SELECT_EDIT );
- strcpy(g_strMsgSelectEdit, (char*)(LPCTSTR)strMsgHint);
- strMsgHint.LoadString( IDS_PROMPT );
- strcpy(g_strMsgPrompt, (char*)(LPCTSTR)strMsgHint);
- strMsgHint.LoadString( IDS_PROMPT_CONFIRM_DELRECORD );
- strcpy(g_strMsgConfirmDelRecord, (char*)(LPCTSTR)strMsgHint);
- strMsgHint.LoadString( IDS_PROMPT_USER_DISENABLE );
- strcpy(g_strMsgUserDisable, (char *)(LPCTSTR)strMsgHint);
- strMsgHint.LoadString( IDS_MSG_HINT_DB_CONNECTION );
- strcpy(g_strMsgDBConnectionSuccess, (char*)(LPCTSTR)strMsgHint );
- strMsgHint.LoadString( IDS_MSG_HINT_DB_CONNECTION_FAIL );
- strcpy(g_strMsgDBConnectionFail, (char*)(LPCTSTR)strMsgHint );
- return 0;
- }
- VOID TerminateLastProcess()
- {
- HANDLE hSnapShot = CreateToolhelp32Snapshot(TH32CS_SNAPPROCESS, 0);
- if (hSnapShot != NULL)
- {
- PROCESSENTRY32 ProcessInfo = {0};//声明进程信息变量
- ProcessInfo.dwSize = sizeof(ProcessInfo);//设置ProcessInfo的大小
- //返回系统中第一个进程的信息
- BOOL bStatus = Process32First(hSnapShot, &ProcessInfo);
- while (bStatus)
- {
- if (!_stricmp(g_strAppName, ProcessInfo.szExeFile))//映像名称
- {
- HANDLE hProcess = OpenProcess(PROCESS_ALL_ACCESS, FALSE, ProcessInfo.th32ProcessID);
- ::TerminateProcess(hProcess, 1);
- hProcess = NULL;
- Sleep(1000);
- break;
- }
- else
- //获取下一个进程的信息
- bStatus = Process32Next(hSnapShot, &ProcessInfo);
- }
- }
- }
- //-------------------------------------------------------------------------------------
- //Description:
- // This function maps a character string to a wide-character (Unicode) string
- //
- //Parameters:
- // lpcszStr: [in] Pointer to the character string to be converted
- // lpwszStr: [out] Pointer to a buffer that receives the translated string.
- // dwSize: [in] Size of the buffer
- //
- //Return Values:
- // TRUE: Succeed
- // FALSE: Failed
- //
- //Example:
- // MByteToWChar(szA,szW,sizeof(szW)/sizeof(szW[0]));
- //---------------------------------------------------------------------------------------
- BOOL MByteToWChar(LPCSTR lpcszStr, LPWSTR lpwszStr, DWORD dwSize)
- {
- // Get the required size of the buffer that receives the Unicode
- // string.
- DWORD dwMinSize;
- dwMinSize = MultiByteToWideChar (CP_ACP, 0, lpcszStr, -1, NULL, 0);
- if(dwSize < dwMinSize)
- {
- return FALSE;
- }
-
- // Convert headers from ASCII to Unicode.
- MultiByteToWideChar (CP_ACP, 0, lpcszStr, -1, lpwszStr, dwMinSize);
- return TRUE;
- }
- //-------------------------------------------------------------------------------------
- //Description:
- // This function maps a wide-character string to a new character string
- //
- //Parameters:
- // lpcwszStr: [in] Pointer to the character string to be converted
- // lpszStr: [out] Pointer to a buffer that receives the translated string.
- // dwSize: [in] Size of the buffer
- //
- //Return Values:
- // TRUE: Succeed
- // FALSE: Failed
- //
- //Example:
- // MByteToWChar(szW,szA,sizeof(szA)/sizeof(szA[0]));
- //---------------------------------------------------------------------------------------
- BOOL WCharToMByte(LPCWSTR lpcwszStr, LPSTR lpszStr, DWORD dwSize)
- {
- DWORD dwMinSize;
- dwMinSize = WideCharToMultiByte(CP_OEMCP,NULL,lpcwszStr,-1,NULL,0,NULL,FALSE);
- if(dwSize < dwMinSize)
- {
- return FALSE;
- }
- WideCharToMultiByte(CP_OEMCP,NULL,lpcwszStr,-1,lpszStr,dwSize,NULL,FALSE);
- return TRUE;
- }
- //////////////////////////////////////////////////////////////////////////////
- //名称:GetExcelDriver
- //功能:获取ODBC中Excel驱动
- //作者:徐景周(jingzhou_xu@163.net)
- //组织:未来工作室(Future Studio)
- //日期:2002.9.1
- /////////////////////////////////////////////////////////////////////////////
- CString GetExcelDriver()
- {
- char szBuf[2001];
- WORD cbBufMax = 2000;
- WORD cbBufOut;
- char *pszBuf = szBuf;
- CString sDriver;
-
- // 获取已安装驱动的名称(涵数在odbcinst.h里)
- if (!SQLGetInstalledDrivers(szBuf, cbBufMax, &cbBufOut))
- return "";
-
- // 检索已安装的驱动是否有Excel...
- do
- {
- if (strstr(pszBuf, "Excel") != 0)
- {
- //发现 !
- sDriver = CString(pszBuf);
- break;
- }
- pszBuf = strchr(pszBuf, '\0') + 1;
- }
- while (pszBuf[1] != '\0');
-
- return sDriver;
- }
- bool IsExistExcelDriver()
- {
- bool bRet = false;
- char szBuf[2001];
- WORD cbBufMax = 2000;
- WORD cbBufOut;
- char *pszBuf = szBuf;
- CString sDriver;
-
- // 获取已安装驱动的名称(涵数在odbcinst.h里)
- if (!SQLGetInstalledDrivers(szBuf, cbBufMax, &cbBufOut))
- return false;
-
- // 检索已安装的驱动是否有Excel...
- do
- {
- if (strstr(pszBuf, "Excel") != 0)
- {
- //发现 !
- sDriver = CString(pszBuf);
- bRet = true;
- break;
- }
- pszBuf = strchr(pszBuf, '\0') + 1;
- }
- while (pszBuf[1] != '\0');
-
- return bRet;
- }
- ///////////////////////////////////////////////////////////////////////////////
- // BOOL MakeSurePathExists( CString &Path,bool FilenameIncluded)
- // 参数:
- // Path 路径
- // FilenameIncluded 路径是否包含文件名
- // 返回值:
- // 文件是否存在
- // 说明:
- // 判断Path文件(FilenameIncluded=true)是否存在,存在返回TURE,不存在返回FALSE
- // 自动创建目录
- //
- ///////////////////////////////////////////////////////////////////////////////
- BOOL MakeSurePathExists( CString &Path,
- bool FilenameIncluded)
- {
- int Pos=0;
- while((Pos=Path.Find('\\',Pos+1))!=-1)
- CreateDirectory(Path.Left(Pos),NULL);
- if(!FilenameIncluded)
- CreateDirectory(Path,NULL);
- // return ((!FilenameIncluded)?!_access(Path,0):
- // !_access(Path.Left(Path.ReverseFind('\\')),0));
-
- return !_access(Path,0);
- }
- //获得默认的文件名
- BOOL GetDefaultXlsFileName(CString& sExcelFile)
- {
- ///默认文件名:yyyymmddhhmmss.xls
- CString timeStr;
- CTime day;
- day=CTime::GetCurrentTime();
- int filenameday,filenamemonth,filenameyear,filehour,filemin,filesec;
- filenameday=day.GetDay();//dd
- filenamemonth=day.GetMonth();//mm月份
- filenameyear=day.GetYear();//yyyy
- filehour=day.GetHour();//hh
- filemin=day.GetMinute();//mm分钟
- filesec=day.GetSecond();//ss
- timeStr.Format("%04d%02d%02d%02d%02d%02d",filenameyear,filenamemonth,filenameday,filehour,filemin,filesec);
-
- sExcelFile = timeStr + ".xls";
- // prompt the user (with all document templates)
- CFileDialog dlgFile(FALSE,".xls",sExcelFile);
- CString title;
- CString strFilter;
-
- title = g_strDevDataLog;
- strFilter = "Excel文件(*.xls)";
- strFilter += (TCHAR)'\0'; // next string please
- strFilter += _T("*.xls");
- strFilter += (TCHAR)'\0'; // last string
- dlgFile.m_ofn.nMaxCustFilter++;
- dlgFile.m_ofn.nFilterIndex = 1;
- // append the "*.*" all files filter
- CString allFilter;
- VERIFY(allFilter.LoadString(AFX_IDS_ALLFILTER));
- strFilter += allFilter;
- strFilter += (TCHAR)'\0'; // next string please
- strFilter += _T("*.*");
- strFilter += (TCHAR)'\0'; // last string
- dlgFile.m_ofn.nMaxCustFilter++;
-
- dlgFile.m_ofn.lpstrFilter = strFilter;
- dlgFile.m_ofn.lpstrTitle = title;
-
- if (dlgFile.DoModal()==IDCANCEL)
- return FALSE; // open cancelled
- sExcelFile = dlgFile.GetPathName();
- if (MakeSurePathExists(sExcelFile,true))
- {
- if(!DeleteFile(sExcelFile))
- { // delete the file
- MessageBox(NULL, g_strOverWriteError, g_strTip, MB_ICONINFORMATION);
- return FALSE;
- }
- }
- return TRUE;
- }
- ///////////////////////////////////////////////////////////////////////////////
- // void ExportListToExcel(CListCtrl* pList, CString strTitle)
- // 参数:
- // pList 需要导出的List控件指针
- // strTitle 导出的数据表标题
- // 说明:
- // 导出CListCtrl控件的全部数据到Excel文件。Excel文件名由用户通过“另存为”
- // 对话框输入指定。创建名为strTitle的工作表,将List控件内的所有数据(包括
- // 列名和数据项)以文本的形式保存到Excel工作表中。保持行列关系。
- //
- // edit by [r]@dotlive.cnblogs.com
- ///////////////////////////////////////////////////////////////////////////////
- // void ExportListToExcel(CDataGrid* pList, CString strTitle)
- // {
- // #if 1
- // CString warningStr;
- // if (pList->GetRowCount()>0)
- // {
- // CDatabase database;
- // CString sDriver;
- // CString sExcelFile;
- // CString sSql;
- // CString tableName = strTitle;
- //
- // // 检索是否安装有Excel驱动 "Microsoft Excel Driver (*.xls)"
- // sDriver = GetExcelDriver();
- // if (sDriver.IsEmpty())
- // {
- // // 没有发现Excel驱动
- // //AfxMessageBox("没有安装Excel!\n请先安装Excel软件才能使用导出功能!");
- // MessageBox(NULL, "没有安装Excel!\n请先安装Excel软件才能使用导出功能!", g_strTip, MB_ICONINFORMATION);
- // return;
- // }
- //
- // ///默认文件名
- // if (!GetDefaultXlsFileName(sExcelFile))
- // return;
- //
- // // 创建进行存取的字符串
- // sSql.Format("DRIVER={%s};DSN='';FIRSTROWHASNAMES=1;READONLY=FALSE;CREATE_DB=\"%s\";DBQ=%s",sDriver, sExcelFile, sExcelFile);
- //
- // // 创建数据库 (既Excel表格文件)
- // if( database.OpenEx(sSql,CDatabase::noOdbcDialog) )
- // {
- // // 创建表结构
- // int i=0;
- // LVCOLUMN columnData;
- // CString columnName;
- // int columnNum = 0;
- // CString strH;
- // CString strV;
- //
- // sSql = "";
- // strH = "";
- // columnData.mask = LVCF_TEXT;
- // columnData.cchTextMax =100;
- // columnData.pszText = columnName.GetBuffer (100);
- //
- // for(i=0;i<pList->GetColumnCount();i++)//GetColumn(i,&columnData)
- // {
- // if (i!=0)
- // {
- // sSql = sSql + ", " ;
- // strH = strH + ", " ;
- // }
- //
- // CString sName = pList->m_field.GetAt(i).Caption.Trim();
- //
- // sSql = sSql + " " + sName +" TEXT";
- // strH = strH + " " + sName +" ";
- // }
- // columnName.ReleaseBuffer ();
- // columnNum = i;
- //
- // sSql = "CREATE TABLE " + tableName + " ( " + sSql + " ) ";
- // database.ExecuteSQL(sSql);
- //
- // // 插入数据项
- // int nItemIndex;
- // for( nItemIndex=1;nItemIndex<pList->GetRowCount();nItemIndex++ )
- // {
- // strV = "";
- // for(i=0;i<columnNum;i++)
- // {
- // if (i!=0)
- // {
- // strV = strV + ", " ;
- // }
- // //strV = strV + " '" + pList->GetItemText(nItemIndex,i) +"' ";
- // }
- //
- // sSql = "INSERT INTO "+ tableName
- // +" ("+ strH + ")"
- // +" VALUES("+ strV + ")";
- // database.ExecuteSQL(sSql);
- // }
- // }
- //
- // // 关闭数据库
- // database.Close();
- //
- // warningStr.Format(g_strSaveas,sExcelFile);
- // MessageBox(NULL, warningStr, g_strTip, MB_ICONINFORMATION);
- // }
- // #endif
- // }
- CString InterceptString(int qlen, CString strSource)
- {
- int len,i,y;
- CString sTemp,sreturn;
- strSource.TrimLeft();
- strSource.TrimRight();
- len=strSource.GetLength();
- y=0;
- sTemp=strSource.Right(len-qlen);
- for(i=0;i<len;i++)
- {
- //if(sTemp[y]<0 || sTemp[y]>255)
- //if(sTemp[i]<0 || sTemp[i]>=128)
- //if(sTemp.GetAt(y) & 0x80 )
- if(::IsDBCSLeadByte(sTemp.GetAt(y)))
- y=y+2;
- else
- y=y+1;
- if(y>=70)
- break;
- }
- sreturn=sTemp.Left(y);
- return sreturn;
- }
- //显示选择文件夹窗口
- //参数 sFolderPath:用于返回用户选择的文件夹的路径
- //参数 sTitle:用于指定选择文件夹窗口的标题
- //返回值 :操作结果,用户取消选择或操作失败返回FALSE,否则TRUE
- BOOL BrowseForFolder(CString & sFolderPath, CString sTitle)
- {
- BROWSEINFO bi;
- char Buffer[_MAX_PATH];
- bi.hwndOwner = NULL;
- bi.pidlRoot = NULL;
- bi.pszDisplayName = Buffer;
- bi.lpszTitle = sTitle;
- bi.ulFlags = 0;
- bi.lpfn = NULL;
- LPITEMIDLIST pIDList = SHBrowseForFolder(& bi);
- if (!pIDList)
- return FALSE;
- SHGetPathFromIDList(pIDList, Buffer);
- sFolderPath = Buffer;
- LPMALLOC lpMalloc;
- if (FAILED(SHGetMalloc(& lpMalloc)))
- return FALSE;
-
- //释放内存
- lpMalloc->Free(pIDList);
- lpMalloc->Release();
-
- return TRUE;
- }
- void TimeTicksToInt(CString strSrc, unsigned long &nDest)
- {
- CString strLeft;
- int nIndex = strSrc.Find(":");
- if( nIndex != -1 )
- {
- strLeft = strSrc.Left( nIndex - 1 );
- nDest = atoi(strLeft);
- }
- }
- ///目录是否存在的检查:
- bool CheckFolderExist(CString strPath)
- {
- WIN32_FIND_DATA wfd;
- bool rValue = false;
- HANDLE hFind = FindFirstFile((char *)(LPCTSTR)strPath, &wfd);
- if ((hFind != INVALID_HANDLE_VALUE) && (wfd.dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY))
- {
- rValue = true;
- }
- FindClose(hFind);
- return rValue;
- }
- BOOL BrowseFile(CString strFile, CString strFilter,
- CStringList *pFileList,
- CStringList *pFileNameList,
- CStringList *pShowNameList) //查找文件函数
- {
- CFileFind FileFind;
- CString SearchTarget = strFile; // + "\\" +strFilter;
- if( SearchTarget.Right(1) != "\\" )
- SearchTarget += "\\";
- SearchTarget += "*.*";
- BOOL res = FileFind.FindFile(SearchTarget);
- while(res)
- {
- res = FileFind.FindNextFile();
- if(FileFind.IsDirectory() && !FileFind.IsDots())
- {
- //如果是一个子目录,用递归继续往深一层找
- CString strPath = FileFind.GetFilePath();
- CString strTitle = FileFind.GetFileTitle();
- BrowseFile(strPath, strFilter, pFileList, pFileNameList, pShowNameList);
- }
- else if(!FileFind.IsDirectory() && !FileFind.IsDots())
- {
- //显示当前访问的文件
- CString strExtName;
- CString strName;
- strName = FileFind.GetFileName();
- strExtName = strName.Right(strName.GetLength() - strName.Find('.')-1);
- strExtName.MakeUpper();
- if(!strExtName.CompareNoCase(strFilter))//扩展名正确
- {
- CString strPath = FileFind.GetFilePath();
- pFileList->AddTail(strPath);
- pFileNameList->AddTail(strName);
- strName = strName.Left(strName.Find('.'));
- pShowNameList->AddTail(strName);
- }
- }
- }
- FileFind.Close();//关闭
- return TRUE;
- }
- //注册OCX
- BOOL RegisterOCX( CString sOcxPath )
- {
- LPCTSTR pszDllName = sOcxPath;
- HINSTANCE hLib = LoadLibrary(pszDllName);
- if (hLib < (HINSTANCE)HINSTANCE_ERROR)
- {
- return FALSE;
- }
- FARPROC lpDllEntryPoint;
- lpDllEntryPoint = GetProcAddress(hLib,_T("DllRegisterServer"));
- if(lpDllEntryPoint!=NULL)
- {
- if(FAILED(( *lpDllEntryPoint)()))
- {
- FreeLibrary(hLib);
- return FALSE;
- }
- return TRUE;
- }
- else
- return FALSE;
- }
- //注销OCX
- BOOL UnRegisterOCX( CString sOcxPath )
- {
- LPCTSTR pszDllName = sOcxPath;
- HINSTANCE hLib = LoadLibrary(pszDllName);
- if (hLib < (HINSTANCE)HINSTANCE_ERROR)
- {
- return FALSE;
- }
- FARPROC lpDllEntryPoint;
- lpDllEntryPoint = GetProcAddress(hLib,_T("DllUnregisterServer"));
- if(lpDllEntryPoint!=NULL)
- {
- if(FAILED(( *lpDllEntryPoint)()))
- {
- FreeLibrary(hLib);
- return FALSE;
- }
-
- return TRUE;
- }
- else
- return FALSE;
- }
- WCHAR* StrToWchar(CString strSrc)
- {
- size_t nLen = strSrc.GetLength()+1;
- char *szText = new char[nLen];
- //snprintf(szText, nLen, "%s", strSrc);
- size_t nLenW = ::MultiByteToWideChar(CP_ACP,0,(const char *)szText,int(nLen),NULL,0);
- WCHAR *wszText = new WCHAR[nLenW+1];
- ::MultiByteToWideChar(CP_ACP,0,(const char *)szText,int(nLen),wszText,int(nLenW));
- wszText[nLenW] = L'\0';
- //chn add
- delete []szText;
- szText = NULL;
- return wszText;
- }
- bool g_FindProcess( CString sAppName )
- {
- bool bRet = false;
- HANDLE hSnapShot = CreateToolhelp32Snapshot(TH32CS_SNAPPROCESS, 0);
- if (hSnapShot != NULL)
- {
- PROCESSENTRY32 ProcessInfo = {0};//声明进程信息变量
- ProcessInfo.dwSize = sizeof(ProcessInfo);//设置ProcessInfo的大小
- //返回系统中第一个进程的信息
- BOOL bStatus = Process32First(hSnapShot, &ProcessInfo);
- while (bStatus)
- {
- if (!_stricmp(sAppName, ProcessInfo.szExeFile))//映像名称
- {
- HANDLE hProcess = OpenProcess(PROCESS_ALL_ACCESS, FALSE, ProcessInfo.th32ProcessID);
- bRet = true;
- break;
- }
- else
- {
- //获取下一个进程的信息
- bStatus = Process32Next(hSnapShot, &ProcessInfo);
- }
- }
- }
- return bRet;
- }
|