SysLib.cpp 38 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206
  1. #include "stdafx.h"
  2. #include <tlhelp32.h>
  3. #include "SysLib.h"
  4. #include <io.h>
  5. #include <odbcinst.h>
  6. #include <afxdb.h>
  7. #include "resource.h"
  8. #include "crc32.h"
  9. #include <odbcinst.h>
  10. //增加自动启动注册表项
  11. INT AddAutoSysRun(CHAR *strExeFile, INT iAutoRunSystem)
  12. {
  13. HKEY hKey = NULL;
  14. DWORD dwErrorCode = 0;
  15. //创建注册表,有该键则读取,无则创建
  16. dwErrorCode = RegCreateKeyEx(HKEY_LOCAL_MACHINE,
  17. "Software\\Microsoft\\Windows\\CurrentVersion\\Run",
  18. 0,
  19. NULL,
  20. REG_OPTION_NON_VOLATILE,
  21. KEY_ALL_ACCESS,
  22. NULL, //Security
  23. &hKey,
  24. NULL);
  25. if (dwErrorCode == ERROR_SUCCESS)
  26. {
  27. if (iAutoRunSystem)
  28. dwErrorCode = RegSetValueEx(hKey, "DataBase Monitor Service", NULL, REG_SZ, (BYTE*)strExeFile, strlen(strExeFile));
  29. else
  30. dwErrorCode = RegDeleteKey(hKey, "DataBase Monitor Service");
  31. }
  32. if (NULL != hKey)
  33. RegCloseKey(hKey);
  34. hKey = NULL;
  35. return 0;
  36. }
  37. int Handle_DeleteTrayNullIcon( BOOL &bNullBeDel )
  38. {
  39. bNullBeDel = FALSE;
  40. HWND hStatus=::FindWindow("Shell_TrayWnd",NULL); //得到任务栏句柄
  41. if (hStatus==NULL)
  42. {
  43. //AfxMessageBox ( "Get Shell_TrayWnd error!" );
  44. return -1;
  45. }
  46. HWND hNotify=FindWindowEx(hStatus,NULL,"TrayNotifyWnd",NULL); //右下角区域
  47. if (hNotify==NULL)
  48. {
  49. //AfxMessageBox ( "Get TrayNotifyWnd error!" );
  50. return -1;
  51. }
  52. HWND hNotify1=FindWindowEx(hNotify,NULL,"SysPager",NULL);
  53. if (hNotify==NULL)
  54. {
  55. //AfxMessageBox ( "Get SysPager error!" );
  56. return -1;
  57. }
  58. HWND hNotify1_0=FindWindowEx(hNotify1,NULL,"ToolBarWindow32",NULL);//右下角区域(不包括时间)
  59. if (hNotify1_0==NULL)
  60. {
  61. //AfxMessageBox ( "Get ToolBarWindow32 error!" );
  62. return -1;
  63. }
  64. //-------------------以上是得到任务栏右下脚一块地方的句柄
  65. DWORD pid = 0;
  66. GetWindowThreadProcessId(hNotify1_0,&pid);
  67. if (pid==NULL)
  68. {
  69. //AfxMessageBox ( "Get pid error!" );
  70. return -1;
  71. }
  72. HANDLE hProcess=OpenProcess(PROCESS_QUERY_INFORMATION|PROCESS_ALL_ACCESS,true,pid);
  73. if (hProcess==NULL)
  74. {
  75. //AfxMessageBox ( "Get hd error!" );
  76. return -1;
  77. }
  78. ::SendMessage(hNotify1_0,WM_PAINT ,NULL,NULL);
  79. CRect rect;
  80. ::GetWindowRect(hNotify1_0,&rect);
  81. ::InvalidateRect(hNotify1_0,&rect,false);
  82. int iNum=::SendMessage(hNotify1_0,TB_BUTTONCOUNT ,NULL,NULL); //获取任务栏上图标个数
  83. unsigned long n = 0;
  84. TBBUTTON *pButton = new TBBUTTON;
  85. CString strInfo = _T("");
  86. wchar_t name[256] = {0};
  87. TBBUTTON BButton;
  88. unsigned long whd,proid;
  89. CString x;
  90. for(int i=0; i<iNum; i++)
  91. {
  92. ::SendMessage(hNotify1_0,TB_GETBUTTON,i,(LPARAM)(&BButton));
  93. ReadProcessMemory(hProcess,&BButton,pButton,sizeof(TBBUTTON),&n);
  94. if (pButton->iString != 0xffffffff)
  95. {
  96. try
  97. {
  98. ReadProcessMemory(hProcess,(void *)pButton->iString,name,255,&n);
  99. }
  100. catch(...)
  101. {
  102. }
  103. strInfo.Format("%d : %s\n",i+1,CString(name));
  104. TRACE(strInfo);
  105. }
  106. try
  107. {
  108. whd=0;
  109. ReadProcessMemory(hProcess,(void *)pButton->dwData,&whd,4,&n);
  110. }
  111. catch(...)
  112. {
  113. }
  114. proid=NULL;
  115. GetWindowThreadProcessId((HWND)whd,&proid);
  116. if(proid==NULL)
  117. {
  118. bNullBeDel = TRUE;
  119. ::SendMessage(hNotify1_0,TB_DELETEBUTTON,i,0);
  120. }
  121. }
  122. delete pButton;
  123. return 0;
  124. }
  125. int GetSysData()
  126. {
  127. CHAR strFile[MAX_FILE_LENGTH + 1] = "";
  128. CHAR strValue[MAX_VALUE_LENGTH + 1] = "";
  129. int iPosFile = 0;
  130. int iLenghtFile = 0;
  131. ////////////////////////////////////////////////////////////////////////////
  132. //获取应用名
  133. GetModuleFileName(AfxGetApp()->m_hInstance, g_strDirectory, MAX_PATH_LENGTH);
  134. iLenghtFile = strlen(g_strDirectory);
  135. for (iPosFile = iLenghtFile - 1; iPosFile >= 0; iPosFile--)
  136. {
  137. if (g_strDirectory[iPosFile] == '\\')
  138. {
  139. memset(g_strAppName, 0, sizeof(g_strAppName));
  140. memcpy(g_strAppName, g_strDirectory + iPosFile + 1, iLenghtFile - iPosFile - 1);
  141. break;
  142. }
  143. }
  144. //获取系统路径
  145. //#ifdef _DEBUG
  146. // GetCurrentDirectory(MAX_PATH_LENGTH, g_strDirectory);
  147. //#else
  148. GetModuleFileName(AfxGetApp()->m_hInstance, g_strDirectory, MAX_PATH_LENGTH);
  149. iLenghtFile = strlen(g_strDirectory);
  150. for (iPosFile = iLenghtFile - 1; iPosFile >= 0; iPosFile--)
  151. {
  152. if (g_strDirectory[iPosFile] == '\\')
  153. {
  154. g_strDirectory[iPosFile] = '\0';
  155. break;
  156. }
  157. }
  158. //#endif
  159. wsprintf(strFile, "%s\\set.ini", g_strDirectory);
  160. //Server
  161. GetPrivateProfileString("Server", "ServerIP", "", g_strServerIP, sizeof(g_strServerIP), strFile);
  162. GetPrivateProfileString("Server", "Port", "", g_strServerPort, sizeof(g_strServerPort), strFile);
  163. int nSTDOUT = GetPrivateProfileInt("Server", "StdOut", 0, strFile);
  164. if ( nSTDOUT == 1 )
  165. {
  166. AllocConsole(); // 开辟控制台;
  167. SetConsoleTitle(_T("EMSoftClient调试输出")); // 设置控制台窗口标题;
  168. freopen("CONOUT$", "w+t", stdout); // 重定向输出;
  169. freopen("CONIN$", "r+t", stdin); // 重定向输入;
  170. HWND hWnd = NULL;
  171. again:
  172. hWnd = ::FindWindow(NULL, _T("EMSoftClient调试输出"));
  173. if( hWnd )
  174. {
  175. if (!::SetWindowPos(hWnd, HWND_TOPMOST, 0,0,0,0, SWP_NOMOVE | SWP_NOSIZE))
  176. {
  177. printf(_T("前置设置失败\n"));
  178. }
  179. else
  180. {
  181. printf(_T("前置设置成功\n"));
  182. }
  183. }
  184. else
  185. {
  186. if (nSTDOUT <= 10)
  187. goto again;
  188. }
  189. }
  190. //是否自动启动系统
  191. GetPrivateProfileString("Other", "AutoRunSystem", "", strValue, sizeof(strValue), strFile);
  192. if (strcmp(strValue, ""))
  193. g_iAutoRunSystem = atoi(strValue);
  194. else
  195. g_iAutoRunSystem = 0;
  196. if (g_iAutoRunSystem <= 0)
  197. g_iAutoRunSystem = 0;
  198. else
  199. g_iAutoRunSystem = 1;
  200. GetPrivateProfileString("User", "UserID", "", g_strLoginUserID, sizeof(g_strLoginUserID), strFile);
  201. GetPrivateProfileString("User", "UserPwd", "", g_strLoginPwd, sizeof(g_strLoginPwd), strFile);
  202. //检查控制,设置是否有密码
  203. GetPrivateProfileString("User", "HaveControlPwd","", strValue,sizeof(strValue), strFile );
  204. g_bHaveControlPwd = atoi( strValue );
  205. g_nIsDemo = GetPrivateProfileInt("Other", "IsDemo", 0, strFile);
  206. //RunParam
  207. g_nIsPoll = GetPrivateProfileInt("RunParam", "IsPoll", 0, strFile);
  208. g_nPollInterval = GetPrivateProfileInt("RunParam", "PollInterval", 1, strFile);
  209. g_nPollCount = GetPrivateProfileInt("Poll", "PollCount", 0, strFile);
  210. CString strPollPath, strPollDesc;
  211. for( int i = 1; i < g_nPollCount + 1; i++ )
  212. {
  213. if( i > MAX_VIEW_NUM - 1 ) break;
  214. strPollPath.Format("PollPath%d", i);
  215. GetPrivateProfileString("Poll",
  216. (char *)(LPCTSTR)strPollPath, "", g_strPollPath[i-1], sizeof(g_strPollPath[i-1]), strFile);
  217. strPollDesc.Format("PollDesc%d", i);
  218. GetPrivateProfileString("Poll",
  219. (char *)(LPCTSTR)strPollDesc, "", g_strPollDesc[i-1], sizeof(g_strPollDesc[i-1]), strFile);
  220. }
  221. //语言
  222. GetPrivateProfileString("Other", "Language", "", g_strLanguage, sizeof(g_strLanguage), strFile);
  223. //Database
  224. GetPrivateProfileString("Database", "DBType", "", g_strDBType, sizeof(g_strDBType), strFile);
  225. GetPrivateProfileString("Database", "AccessFile", "", g_strAccessFile, sizeof(g_strAccessFile), strFile);
  226. GetPrivateProfileString("Database", "ServerName", "", g_strServerName, sizeof(g_strServerName), strFile);
  227. GetPrivateProfileString("Database", "DataBaseName", "", g_strDataBaseName, sizeof(g_strDataBaseName), strFile);
  228. GetPrivateProfileString("Database", "UserName", "", g_strUserName, sizeof(g_strUserName), strFile);
  229. GetPrivateProfileString("Database", "Password", "", g_strPassword, sizeof(g_strPassword), strFile);
  230. g_dwDataBasePort = GetPrivateProfileInt("Database", "DataBasePort", 5432, strFile);
  231. //数据库连接串
  232. if (!_stricmp(g_strDBType, "SQL SERVER"))
  233. sprintf(g_strConnectString, "Provider=sqloledb;Data Source=%s,1433;Initial Catalog=%s;User Id=%s;Password=%s; ",
  234. g_strServerName, g_strDataBaseName, g_strUserName, g_strPassword);
  235. else if (!_stricmp(g_strDBType, "ACCESS97"))
  236. sprintf(g_strConnectString, "Provider=Microsoft.Jet.OLEDB.3.51;Data Source=%s", g_strAccessFile);
  237. else if (!_stricmp(g_strDBType, "ACCESS2000"))
  238. sprintf(g_strConnectString, "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=%s", g_strAccessFile);
  239. else if(!_stricmp(g_strDBType, "PGSQL"))
  240. sprintf(g_strConnectString, "DRIVER={PostgreSQL ODBC Driver(UNICODE)}; SERVER=%s; port=%d; DATABASE=%s; UID=%s; PWD=%s;",
  241. g_strServerName, g_dwDataBasePort, g_strDataBaseName, g_strUserName, g_strPassword);
  242. else
  243. sprintf(g_strConnectString, "Provider=sqloledb;Data Source=%s;Initial Catalog=%s;User Id=%s;Password=%s; ",
  244. g_strServerName, g_strDataBaseName, g_strUserName, g_strPassword);
  245. //用户信息
  246. GetPrivateProfileString("User", "UserID", "", g_strDefaultUserID, sizeof(g_strDefaultUserID), strFile);
  247. GetPrivateProfileString("User", "UserPwd", "", g_strDefaultUserPwd, sizeof(g_strDefaultUserPwd), strFile);
  248. //自动跳到报警画面
  249. g_nAlarmToView = GetPrivateProfileInt("AlarmMode", "AlarmToView", 0, strFile);;
  250. //AlarmMode
  251. g_nAlarmModeIsDlg = GetPrivateProfileInt("AlarmMode", "Dlg", 0, strFile);
  252. g_nAlarmModeIsSound = GetPrivateProfileInt("AlarmMode", "Sound", 0, strFile);
  253. g_nAlarmModeSoundPlayNum = GetPrivateProfileInt("AlarmMode", "PlayNum", 0, strFile);
  254. g_nAlarmModeSoundPlayNum += 1;
  255. //Comm
  256. g_nCommDlgLevel = GetPrivateProfileInt("Common", "LevelDlg", 0, strFile);;
  257. g_nCommWavLevel = GetPrivateProfileInt("Common", "LevelLocalWav", 0, strFile);;
  258. //TTS
  259. g_nTTSType = GetPrivateProfileInt("TTS", "VoiceType", 0, strFile);
  260. //视频采集卡
  261. GetPrivateProfileString("Video", "CapPath", "", g_strVideoCapPath, sizeof(g_strVideoCapPath), strFile);
  262. CString str;
  263. str = CString(g_strVideoCapPath);
  264. str.Replace("\\", "\\\\");
  265. strcpy(g_strVideoCapPath, (char *)(LPCTSTR)str);
  266. //Toolbar显示状态
  267. g_nToolbarTop = GetPrivateProfileInt("Toolbar", "ToolBarTop", 0, strFile);
  268. g_nToolbarLeft = GetPrivateProfileInt("Toolbar", "ToolBarLeft", 0, strFile);
  269. g_nToolbarRun = GetPrivateProfileInt("Toolbar", "ToolBarRun", 0, strFile);
  270. g_nToolBarStatus = GetPrivateProfileInt("Toolbar", "ToolBarStatus", 0, strFile);
  271. ////////////////////////////////////////////////////////////////////////////
  272. //增加自动启动注册表项
  273. #if 0
  274. wsprintf(strFile, "%s\\%s", g_strDirectory, g_strAppName);
  275. AddAutoSysRun(strFile, g_iAutoRunSystem);
  276. #endif
  277. return 0;
  278. }
  279. int GetResourceString()
  280. {
  281. g_strSet.LoadString(IDS_SET);
  282. g_strAdjust.LoadString(IDS_ADJUST);
  283. g_strPictureLink.LoadString(IDS_PICTURELINK);
  284. g_strExit.LoadString(IDS_EXIT);
  285. g_strExLink.LoadString(IDS_EXLINK);
  286. g_strTestAlarm.LoadString(IDS_TESTALARM);
  287. g_strAlarmRed.LoadString(IDS_COMMOND_ALARM_RED);
  288. g_strNoticeRed.LoadString(IDS_COMMOND_NOTICE_RED);
  289. g_strDeviceLog.LoadString(IDS_COMMOND_DEVICE_LOG);
  290. g_strSystemLog.LoadString(IDS_COMMOND_SYSTEM_LOG);
  291. g_strVarManage.LoadString(IDS_COMMOND_VAR_MANAGE);
  292. g_strUserManage.LoadString(IDS_COMMOND_USER_MANAGE);
  293. g_strPwdManage.LoadString(IDS_COMMOND_PWD_MANAGE);
  294. g_strFirstPage.LoadString(IDS_COMMOND_FIRST_PAGE);
  295. g_strNativageTree.LoadString(IDS_COMMOND_NATIVAGE_TREE);
  296. g_strVarTypeID.LoadString(IDS_VARTYPEID);
  297. g_strSelLine.LoadString(IDS_SELLINE);
  298. g_strVarID.LoadString(IDS_VARID);
  299. g_strVarUid1.LoadString(IDS_VARUID1);
  300. g_strVarName1.LoadString(IDS_VARNAME1);
  301. g_strVarDesc.LoadString(IDS_VARDESC);
  302. g_strVarDataLen.LoadString(IDS_VARDATALEN);
  303. g_strOnDesc.LoadString(IDS_ONDESC);
  304. g_strOffDesc.LoadString(IDS_OFFDESC);
  305. g_strMaxValues.LoadString(IDS_MAXVALUES);
  306. g_strMinValues.LoadString(IDS_MINVALUES);
  307. g_strMaxScale.LoadString(IDS_MAXSCALE);
  308. g_strMinScale.LoadString(IDS_MINSCALE);
  309. g_strLowerLimit.LoadString(IDS_LOWERLIMIT);
  310. g_strUpperLimit.LoadString(IDS_UPPERLIMIT);
  311. g_strNormalState.LoadString(IDS_NORMALSTATE);
  312. g_strSetValue.LoadString(IDS_SETVALUE);
  313. g_strRearm.LoadString(IDS_REARM);
  314. g_strOffset.LoadString(IDS_OFFSET);
  315. g_strUint.LoadString(IDS_UNIT);
  316. g_strCollectFreq.LoadString(IDS_COLLECTFREQ);
  317. g_strCoef.LoadString(IDS_COEF);
  318. g_strAlarmLevel.LoadString(IDS_ALARMLEVEL);
  319. g_strReadWrite.LoadString(IDS_READWRITE);
  320. g_strSaveData.LoadString(IDS_SAVEDATA);
  321. g_strCollectThreadData.LoadString(IDS_COLLECTTHRADDATA);
  322. g_strSaveCurve.LoadString(IDS_SAVECURVE);
  323. g_strIsDDE.LoadString(IDS_ISDDE);
  324. g_strRegNum.LoadString(IDS_REGNUM);
  325. g_strFuncID.LoadString(IDS_FUNCID);
  326. g_strChildID.LoadString(IDS_CHILDID);
  327. g_strItemID.LoadString(IDS_ITEMID);
  328. g_strSnmpOid.LoadString(IDS_SNMPOID);
  329. g_strSnmpPublic.LoadString(IDS_SNMPPUBLIC);
  330. g_strDevTypeID.LoadString(IDS_DEVTYPEID);
  331. g_strVarStartAddr.LoadString(IDS_VARSTARTADDR);
  332. g_strRs232Cmd.LoadString(IDS_RS232CMD);
  333. g_strRs232Type.LoadString(IDS_RS232TYPE);
  334. g_strRs232Index.LoadString(IDS_RS232INDEX);
  335. g_strIndentifyTime.LoadString(IDS_IDENTIFYTIME);
  336. g_strRedectTime.LoadString(IDS_REDETECTTIME);
  337. g_strReturnNormalAlarm.LoadString(IDS_RETURNNORMALTOTRIPALARM);
  338. g_strShowCurrValue.LoadString(IDS_SHOWCURRVALUE);
  339. g_strAlarmVarName.LoadString(IDS_ALARMVARNAME);
  340. g_strVarUidIsBlank.LoadString(IDS_VARUIDISBLANK);
  341. g_strVarNameIsBlank.LoadString(IDS_PARAMNAME_CANNOTBLANK);
  342. g_strVarNameExist.LoadString(IDS_VARNAMEEXIST);
  343. g_strVarName2.LoadString(IDS_VARNAME2);
  344. g_strSelDev.LoadString(IDS_SELDEV);
  345. g_strStoneuTech.LoadString(IDS_STONEU_TECH);
  346. g_strPictureFile1.LoadString(IDS_PICTUREFILE1);
  347. g_strCannotLoseAllForm.LoadString(IDS_CANNOTCLOSEALLFORM);
  348. g_strStartBit.LoadString(IDS_STARTBIT);
  349. g_strEndBit.LoadString(IDS_ENDBIT);
  350. g_strVarBitExist.LoadString(IDS_VARBITEXIST);
  351. g_strSelDevice.LoadString(IDS_SELDEV);
  352. g_strOldPasswordCannotBlank.LoadString(IDS_OLDPASSWORDCANNOTBLANK);
  353. g_strOldpasswordInCorrect.LoadString(IDS_OLDPASSWORDINCORRECT);
  354. g_strpasswordInCorrect.LoadString(IDS_PASSWORDINCORRECT);
  355. g_strPasswordNotMatch1.LoadString(IDS_PASSWORDNOTMATCH1);
  356. g_strAll.LoadString(IDS_ALL);
  357. g_strDevName.LoadString(IDS_DEVNAME);
  358. g_strHappentTime1.LoadString(IDS_HAPPENTIME1);
  359. g_strEventArea.LoadString( IDS_EVENTAREA );
  360. g_strCurrValue.LoadString(IDS_CURRVALUE);
  361. g_strDateTime.LoadString(IDS_DATETIME);
  362. g_strHappenTime2.LoadString(IDS_HAPPENTIME2);
  363. g_strWarnContent.LoadString(IDS_WARNCONTENT);
  364. g_strAllDev.LoadString(IDS_ALLDEV);
  365. g_strEthernet.LoadString(IDS_ETHERNET);
  366. g_strMywizard.LoadString(IDS_MYWIZARD);
  367. g_strDevNameInUse.LoadString(IDS_DEVNAMEINUSE);
  368. g_strUserID.LoadString(IDS_USERID);
  369. g_strHintUserName.LoadString(IDS_USERNAME);
  370. g_strTel.LoadString(IDS_TEL);
  371. g_strMobile.LoadString(IDS_MOBIL);
  372. g_strFax.LoadString(IDS_FAX);
  373. g_strMail.LoadString(IDS_EMAIL);
  374. g_strStatus.LoadString(IDS_STATUS);
  375. g_strUserPwd.LoadString(IDS_USERPWD);
  376. g_strUserNameCannotEmpty.LoadString(IDS_USERNAMECANNOTEMPTY);
  377. g_strPasswordNotMatch2.LoadString(IDS_PASSWORDNOTMATCH2);
  378. g_strUserNameExit.LoadString(IDS_USERNAMEEXIT);
  379. g_strID.LoadString(IDS_ID);
  380. g_strDevUid2.LoadString(IDS_DEVUID2);
  381. g_strAlarmStatus.LoadString(IDS_ALARMSTATUS);
  382. g_strAlarmStatusDesc.LoadString(IDS_ALARMSTATUSDESC);
  383. g_strNormalStatusID.LoadString(IDS_NORMALSTATUSID);
  384. g_strAlarmStatusIDCannotEmpty.LoadString(IDS_ALARMSTATUSIDCANNOTEMPTY);
  385. g_strAlarmStatusDescCannotEmpty.LoadString(IDS_ALARMSTATUSDESCCANNOTEMPTY);
  386. g_strNormalStatusIDCannotBlank.LoadString(IDS_NORMALSTATUSIDCANNOTBLANK);
  387. g_strAlarmStatusInfoExist.LoadString(IDS_ALARMSTATUSINFOEXIST);
  388. g_strTimesNewRoman.LoadString(IDS_TIMESNEWROMAN);
  389. g_strEntityProperty.LoadString(IDS_ENTITYPROPERTY);
  390. g_strParamSet.LoadString(IDS_PARAMSET);
  391. g_strHour.LoadString(IDS_HOUR);
  392. g_strDate.LoadString(IDS_DATE);
  393. g_strMean.LoadString(IDS_MEAN);
  394. g_strControl.LoadString(IDS_CONTROL);
  395. g_strTRACE0.LoadString(IDS_TRACE0);
  396. g_strAppwizardCreateApp.LoadString(IDS_APPWIZARDCREATAPP);
  397. g_strPictureFile2.LoadString(IDS_PICTUREFILE2);
  398. g_strSaveModify.LoadString(IDS_SAVEMODIFY);
  399. g_strStoneuIspcms.LoadString(IDS_STONEU_ISPCMS);
  400. g_strUnSelectEntity.LoadString(IDS_UNSELECTENTITY);
  401. g_strIsNotPrimitive.LoadString(IDS_ISNOTPRIMITIVE);
  402. g_strSelect.LoadString(IDS_SELECT);
  403. g_strTrace2.LoadString(IDS_TRACE);
  404. g_strTline.LoadString(IDS_TLINE);
  405. g_strText.LoadString(IDS_TEXT);
  406. g_strRect.LoadString(IDS_RECT);
  407. g_strOval.LoadString(IDS_OVAL);
  408. g_strButton.LoadString(IDS_BUTTON);
  409. g_strData.LoadString(IDS_DATA);
  410. g_strLed.LoadString(IDS_LED);
  411. g_strBar.LoadString(IDS_BAR);
  412. g_strCurve.LoadString(IDS_CURVE);
  413. g_strLine.LoadString(IDS_LINE);
  414. g_strBreaker.LoadString(IDS_BREAKER);
  415. g_strSwitch.LoadString(IDS_SWITCH);
  416. g_strGrid.LoadString(IDS_GRID);
  417. g_strBitmap.LoadString(IDS_BITMAP);
  418. g_strGif.LoadString(IDS_GIF);
  419. g_strTransfer.LoadString(IDS_TRANSFER);
  420. g_strArc.LoadString(IDS_ARC);
  421. g_strArrow.LoadString(IDS_ARROW);
  422. g_strPoly.LoadString(IDS_POLY);
  423. g_strMLine.LoadString(IDS_MLINE);
  424. g_strPipe.LoadString(IDS_PIPE);
  425. g_strZhePipe.LoadString(IDS_ZHEPIPE);
  426. g_strYPipe.LoadString(IDS_YPIPE);
  427. g_strWatch.LoadString(IDS_WATCH);
  428. g_strSingleBar.LoadString(IDS_SINGLEBAR);
  429. g_strRoundRect.LoadString(IDS_ROUNDRECT);
  430. g_strPie.LoadString(IDS_PIE);
  431. g_strFan.LoadString(IDS_FAN);
  432. g_strHisCurve.LoadString(IDS_HISCURVE);
  433. g_strTable.LoadString(IDS_TABLE);
  434. g_strComposite.LoadString(IDS_COMPOSITE);
  435. g_strConnectionFailed.LoadString(IDS_CONNECTIONFAILED);
  436. g_strMoniterSite.LoadString(IDS_MONITORSITE);
  437. g_strDevice.LoadString(IDS_DEVICE);
  438. g_strSerial.LoadString(IDS_SERIAL);
  439. g_strDataDict.LoadString(IDS_DATADICT);
  440. g_strVarSet.LoadString(IDS_VARSET);
  441. g_strScriptManage.LoadString(IDS_SCRIPTMANAGE);
  442. g_strActionWithAlarm.LoadString( IDS_ACTIONWITHALARM );
  443. g_strNoticeList.LoadString( IDS_STRING_NOTICELIST );
  444. g_strSysParam.LoadString(IDS_SYSPARAM);
  445. g_strExitConfirm.LoadString(IDS_EXITCONFIRM);
  446. g_strIPComoccupy.LoadString(IDS_IPCOMOCCUPY);
  447. g_strDevNumCannotBlank.LoadString(IDS_DEVNAMCANNOTBLANK);
  448. g_strDevUidExist.LoadString(IDS_DEVUIDEXIST);
  449. g_strDevNameExist.LoadString(IDS_DEVNAMEEXIST);
  450. g_strSerialPortInUse.LoadString(IDS_SERIALPORTINUSE);
  451. g_strIPNotBlank.LoadString(IDS_IPNOTBLANK);
  452. g_strComcanNot0.LoadString(IDS_COMCANNOT0);
  453. g_strNetDev.LoadString(IDS_NETDEV);
  454. g_strIPConflict.LoadString(IDS_IPCONFLICT);
  455. g_strCannotCreateDirecitory.LoadString(IDS_CANNOTCREATEDIRECTORY);
  456. g_strDelDev.LoadString(IDS_DELDEV);
  457. g_strDelView.LoadString(IDS_DELVIEW);
  458. g_strConfirm.LoadString(IDS_CONFIRM);
  459. g_strEventType.LoadString(IDS_EVENTTYPE);
  460. g_strEventInfo.LoadString(IDS_EVENTINFO);
  461. g_strLowAlarm.LoadString(IDS_LOWALARM);
  462. g_strHighAlarm.LoadString(IDS_UPALARM);
  463. g_strReturnNormal1.LoadString(IDS_RETURNNORMAL1);
  464. g_strReturnNormal2.LoadString(IDS_RETURNNORMAL2);
  465. g_strAlarm.LoadString(IDS_ALARM);
  466. g_strTime.LoadString(IDS_TIME);
  467. g_strVarName3.LoadString(IDS_VARNAME3);
  468. g_strColumnName.LoadString(IDS_COLUMNNAME);
  469. g_strHeader.LoadString(IDS_HEADER);
  470. g_strFormat.LoadString(IDS_FORMAT);
  471. g_strScriptPass.LoadString(IDS_SCRIPTPASS);
  472. g_strScriptNameCannotEmpty.LoadString(IDS_SCRIPTNAMECANNOTEMPTY);
  473. g_strStrVar.LoadString(IDS_STRVAR);
  474. g_strDes.LoadString(IDS_DES);
  475. g_strOne.LoadString(IDS_ONE);
  476. g_strTwo.LoadString(IDS_TWO);
  477. g_strThree.LoadString(IDS_THREE);
  478. g_strFour.LoadString(IDS_FOUR);
  479. g_strFine.LoadString(IDS_FINE);
  480. g_strSix.LoadString(IDS_SIX);
  481. g_strSeven.LoadString(IDS_SEVEN);
  482. g_strEight.LoadString(IDS_EIGHT);
  483. g_strNine.LoadString(IDS_NINE);
  484. g_strTen.LoadString(IDS_TEN);
  485. g_strHandred.LoadString(IDS_HUNDRED);
  486. g_strBilion.LoadString(IDS_BILLION);
  487. g_strWan.LoadString(IDS_WAN);
  488. g_strThousand.LoadString(IDS_THOUSAND);
  489. g_strYuan1.LoadString(IDS_YUAN1);
  490. g_strCent.LoadString(IDS_CENT);
  491. g_strZero.LoadString(IDS_ZERO);
  492. g_strMinute.LoadString(IDS_MINUTE);
  493. g_strYuan2.LoadString(IDS_YUAN2);
  494. g_strDevDataLog.LoadString(IDS_DEVDATALOG);
  495. g_strOverWriteError.LoadString(IDS_OVERWRITEERROR);
  496. g_strSaveas.LoadString(IDS_SAVEAS);
  497. g_strTip.LoadString(IDS_TIP);
  498. g_strScriptError.LoadString(IDS_SCRIPT_ERROR);
  499. g_strLogicDoorinate.LoadString(IDS_LOGIC_COORDINATE);
  500. g_strFontNameCHT.LoadString(IDS_FONT_CHT);
  501. g_strCharacter.LoadString(IDS_CHARACTER);
  502. g_strNormal.LoadString(IDS_NORMAL);
  503. g_strIsNotice.LoadString(IDS_IS_NOTICE);
  504. g_strIsModify.LoadString(IDS_IS_MODIFY);
  505. g_strParamInit.LoadString(IDS_PARAM_INIT);
  506. g_strParamMin.LoadString(IDS_PARAM_MIN);
  507. g_strParamMax.LoadString(IDS_PARAM_MAX);
  508. g_strOCX.LoadString( IDS_OCX );
  509. g_strGIF.LoadString( IDS_GIF );
  510. g_strFlash.LoadString( IDS_FLASH );
  511. g_strRadio.LoadString( IDS_RADIO);
  512. g_strCheck.LoadString( IDS_CHECK);
  513. g_strLogType.LoadString( IDS_LOG_TYPE );
  514. g_strModbusType.LoadString( IDS_LOG_MODBUSTYPE );
  515. g_strLogContent.LoadString( IDS_LOG_CONTENT );
  516. g_strLogHappenTime.LoadString( IDS_LOG_HAPPENTIME );
  517. g_strPastDue.LoadString( IDS_PROMPT_PASTDUE );
  518. g_strEditMoreVarOK.LoadString( IDS_PROMPT_EDITMOREVAROK );
  519. g_strGroup.LoadString( IDS_GROUP );
  520. g_strDClickFirstOperate.LoadString( IDS_PROMPT_DCLICKFIRSTOPERATE );
  521. g_strDelGroup.LoadString( IDS_PROMPT_COMFIR_DELGROUP );
  522. g_strNormalData.LoadString( IDS_NORMALDATA );
  523. g_strAlarmData.LoadString( IDS_ALARMDATA );
  524. g_strDealStatus.LoadString( IDS_DEALSTATUS );
  525. g_strAC_WaitConfig.LoadString( IDS_AC_WAITCONFIG );
  526. g_strAC_ConfigSuccess.LoadString( IDS_AC_CONFIGSUCCESS );
  527. g_strAC_WaitOut.LoadString( IDS_AC_WAITOUT );
  528. g_strAC_ConfigAllEvent.LoadString( IDS_AC_CONFIGALLEVENT );
  529. g_strAC_ConfigChooseEvent.LoadString( IDS_AC_CONFIGCHOOSEEVENT );
  530. g_strAC_DelAllEvent.LoadString( IDS_AC_DELALLEVENT );
  531. g_strAC_DelChooseEvent.LoadString( IDS_AC_DELCHOOSEEVENT );
  532. g_strAdd.LoadString( IDS_ADD );
  533. g_strEdit.LoadString( IDS_EDIT );
  534. g_strDel.LoadString( IDS_DEL );
  535. g_strDevice1.LoadString( IDS_DEVICE );
  536. g_strVariant.LoadString( IDS_VARIANT );
  537. g_strUser.LoadString( IDS_USER );
  538. g_strPwd.LoadString( IDS_PWD );
  539. g_strTimePlan.LoadString( IDS_TIMEPLAN );
  540. g_strRegiserOCX.LoadString( IDS_PROMPT_REGISEROCX );
  541. g_strNoPermit.LoadString( IDS_NO_PERMIT );
  542. g_strModifyPwdOK.LoadString( IDS_MODIFY_PWD_OK );
  543. g_strMonitorNameIsBlank.LoadString( IDS_MONITOR_BLANK );
  544. g_strMonitorNameCannotDel.LoadString( IDS_MONITOR_CANNOTDEL );
  545. g_strInputIsBlank.LoadString( IDS_CANNOT_BLANK );
  546. //界面语言,读取资源文件定义
  547. g_strLogTypeEvent.LoadString( IDS_EVENT_LOG );
  548. g_strLogTypeData.LoadString( IDS_DATA_LOG_TYPE );
  549. g_strLogTypeError.LoadString( IDS_LOG_TYPE_ERROR );
  550. g_strLogTypeWarning.LoadString( IDS_LOG_TYPE_WARNING );
  551. g_strLogModMainThread.LoadString( IDS_LOGMOD_MAIN_THREAD );
  552. g_strLogModDB.LoadString( IDS_LOGMOD_DB );
  553. g_strLogModEmail.LoadString( IDS_LOGMOD_EMAIL );
  554. g_strLogModSms.LoadString( IDS_LOGMOD_SMS );
  555. g_strLogModPing.LoadString( IDS_LOGMOD_PING );
  556. g_strLogModTrap.LoadString( IDS_LOGMOD_TRAP );
  557. g_strLogModSnmp.LoadString( IDS_LOGMOD_SNMP );
  558. g_strLogModDog.LoadString( IDS_LOGMOD_DOG );
  559. g_strLogModNotice.LoadString( IDS_LOGMOD_NOTICE );
  560. g_strLogModContents.LoadString( IDS_SEND_CONTENTS );
  561. g_strLogModTime.LoadString( IDS_SEND_TIME );
  562. //错误提示字符串
  563. CString strError, strMsgHint;
  564. strError.LoadString( IDS_ERROR_EXEC_SQL );
  565. strcpy(g_strErrorExecSql, (char*)(LPCTSTR)strError );
  566. strError.LoadString( IDS_ERROR_DB_DISCONNECTION );
  567. strcpy(g_strErrorDBDisConnection, (char*)(LPCTSTR)strError );
  568. //操作提示
  569. strMsgHint.LoadString( IDS_PROMPT_USERNAME_NOTNULL );
  570. strcpy(g_strMsgUserNotNULL, (char*)(LPCTSTR)strMsgHint);
  571. strMsgHint.LoadString( IDS_PROMPT_PWD_NOT_NULL );
  572. strcpy(g_strMsgPwdNotNULL, (char*)(LPCTSTR)strMsgHint);
  573. strMsgHint.LoadString( IDS_PROMPT_USER_INVALID );
  574. strcpy(g_strMsgUserInvalid, (char*)(LPCTSTR)strMsgHint);
  575. strMsgHint.LoadString( IDS_PROMPT_CONFIRM_DEL );
  576. strcpy(g_strMsgConfirmDel, (char*)(LPCTSTR)strMsgHint);
  577. strMsgHint.LoadString( IDS_PROMPT_SELECT_DEL );
  578. strcpy(g_strMsgSelectDel, (char*)(LPCTSTR)strMsgHint);
  579. strMsgHint.LoadString( IDS_PROMPT_EDIT_SUCCESS );
  580. strcpy(g_strMsgEditSuccess, (char*)(LPCTSTR)strMsgHint);
  581. strMsgHint.LoadString( IDS_PROMPT_SELECT_EDIT );
  582. strcpy(g_strMsgSelectEdit, (char*)(LPCTSTR)strMsgHint);
  583. strMsgHint.LoadString( IDS_PROMPT );
  584. strcpy(g_strMsgPrompt, (char*)(LPCTSTR)strMsgHint);
  585. strMsgHint.LoadString( IDS_PROMPT_CONFIRM_DELRECORD );
  586. strcpy(g_strMsgConfirmDelRecord, (char*)(LPCTSTR)strMsgHint);
  587. strMsgHint.LoadString( IDS_PROMPT_USER_DISENABLE );
  588. strcpy(g_strMsgUserDisable, (char *)(LPCTSTR)strMsgHint);
  589. strMsgHint.LoadString( IDS_MSG_HINT_DB_CONNECTION );
  590. strcpy(g_strMsgDBConnectionSuccess, (char*)(LPCTSTR)strMsgHint );
  591. strMsgHint.LoadString( IDS_MSG_HINT_DB_CONNECTION_FAIL );
  592. strcpy(g_strMsgDBConnectionFail, (char*)(LPCTSTR)strMsgHint );
  593. return 0;
  594. }
  595. VOID TerminateLastProcess()
  596. {
  597. HANDLE hSnapShot = CreateToolhelp32Snapshot(TH32CS_SNAPPROCESS, 0);
  598. if (hSnapShot != NULL)
  599. {
  600. PROCESSENTRY32 ProcessInfo = {0};//声明进程信息变量
  601. ProcessInfo.dwSize = sizeof(ProcessInfo);//设置ProcessInfo的大小
  602. //返回系统中第一个进程的信息
  603. BOOL bStatus = Process32First(hSnapShot, &ProcessInfo);
  604. while (bStatus)
  605. {
  606. if (!_stricmp(g_strAppName, ProcessInfo.szExeFile))//映像名称
  607. {
  608. HANDLE hProcess = OpenProcess(PROCESS_ALL_ACCESS, FALSE, ProcessInfo.th32ProcessID);
  609. ::TerminateProcess(hProcess, 1);
  610. hProcess = NULL;
  611. Sleep(1000);
  612. break;
  613. }
  614. else
  615. //获取下一个进程的信息
  616. bStatus = Process32Next(hSnapShot, &ProcessInfo);
  617. }
  618. }
  619. }
  620. //-------------------------------------------------------------------------------------
  621. //Description:
  622. // This function maps a character string to a wide-character (Unicode) string
  623. //
  624. //Parameters:
  625. // lpcszStr: [in] Pointer to the character string to be converted
  626. // lpwszStr: [out] Pointer to a buffer that receives the translated string.
  627. // dwSize: [in] Size of the buffer
  628. //
  629. //Return Values:
  630. // TRUE: Succeed
  631. // FALSE: Failed
  632. //
  633. //Example:
  634. // MByteToWChar(szA,szW,sizeof(szW)/sizeof(szW[0]));
  635. //---------------------------------------------------------------------------------------
  636. BOOL MByteToWChar(LPCSTR lpcszStr, LPWSTR lpwszStr, DWORD dwSize)
  637. {
  638. // Get the required size of the buffer that receives the Unicode
  639. // string.
  640. DWORD dwMinSize;
  641. dwMinSize = MultiByteToWideChar (CP_ACP, 0, lpcszStr, -1, NULL, 0);
  642. if(dwSize < dwMinSize)
  643. {
  644. return FALSE;
  645. }
  646. // Convert headers from ASCII to Unicode.
  647. MultiByteToWideChar (CP_ACP, 0, lpcszStr, -1, lpwszStr, dwMinSize);
  648. return TRUE;
  649. }
  650. //-------------------------------------------------------------------------------------
  651. //Description:
  652. // This function maps a wide-character string to a new character string
  653. //
  654. //Parameters:
  655. // lpcwszStr: [in] Pointer to the character string to be converted
  656. // lpszStr: [out] Pointer to a buffer that receives the translated string.
  657. // dwSize: [in] Size of the buffer
  658. //
  659. //Return Values:
  660. // TRUE: Succeed
  661. // FALSE: Failed
  662. //
  663. //Example:
  664. // MByteToWChar(szW,szA,sizeof(szA)/sizeof(szA[0]));
  665. //---------------------------------------------------------------------------------------
  666. BOOL WCharToMByte(LPCWSTR lpcwszStr, LPSTR lpszStr, DWORD dwSize)
  667. {
  668. DWORD dwMinSize;
  669. dwMinSize = WideCharToMultiByte(CP_OEMCP,NULL,lpcwszStr,-1,NULL,0,NULL,FALSE);
  670. if(dwSize < dwMinSize)
  671. {
  672. return FALSE;
  673. }
  674. WideCharToMultiByte(CP_OEMCP,NULL,lpcwszStr,-1,lpszStr,dwSize,NULL,FALSE);
  675. return TRUE;
  676. }
  677. //////////////////////////////////////////////////////////////////////////////
  678. //名称:GetExcelDriver
  679. //功能:获取ODBC中Excel驱动
  680. //作者:徐景周(jingzhou_xu@163.net)
  681. //组织:未来工作室(Future Studio)
  682. //日期:2002.9.1
  683. /////////////////////////////////////////////////////////////////////////////
  684. CString GetExcelDriver()
  685. {
  686. char szBuf[2001];
  687. WORD cbBufMax = 2000;
  688. WORD cbBufOut;
  689. char *pszBuf = szBuf;
  690. CString sDriver;
  691. // 获取已安装驱动的名称(涵数在odbcinst.h里)
  692. if (!SQLGetInstalledDrivers(szBuf, cbBufMax, &cbBufOut))
  693. return "";
  694. // 检索已安装的驱动是否有Excel...
  695. do
  696. {
  697. if (strstr(pszBuf, "Excel") != 0)
  698. {
  699. //发现 !
  700. sDriver = CString(pszBuf);
  701. break;
  702. }
  703. pszBuf = strchr(pszBuf, '\0') + 1;
  704. }
  705. while (pszBuf[1] != '\0');
  706. return sDriver;
  707. }
  708. bool IsExistExcelDriver()
  709. {
  710. bool bRet = false;
  711. char szBuf[2001];
  712. WORD cbBufMax = 2000;
  713. WORD cbBufOut;
  714. char *pszBuf = szBuf;
  715. CString sDriver;
  716. // 获取已安装驱动的名称(涵数在odbcinst.h里)
  717. if (!SQLGetInstalledDrivers(szBuf, cbBufMax, &cbBufOut))
  718. return false;
  719. // 检索已安装的驱动是否有Excel...
  720. do
  721. {
  722. if (strstr(pszBuf, "Excel") != 0)
  723. {
  724. //发现 !
  725. sDriver = CString(pszBuf);
  726. bRet = true;
  727. break;
  728. }
  729. pszBuf = strchr(pszBuf, '\0') + 1;
  730. }
  731. while (pszBuf[1] != '\0');
  732. return bRet;
  733. }
  734. ///////////////////////////////////////////////////////////////////////////////
  735. // BOOL MakeSurePathExists( CString &Path,bool FilenameIncluded)
  736. // 参数:
  737. // Path 路径
  738. // FilenameIncluded 路径是否包含文件名
  739. // 返回值:
  740. // 文件是否存在
  741. // 说明:
  742. // 判断Path文件(FilenameIncluded=true)是否存在,存在返回TURE,不存在返回FALSE
  743. // 自动创建目录
  744. //
  745. ///////////////////////////////////////////////////////////////////////////////
  746. BOOL MakeSurePathExists( CString &Path,
  747. bool FilenameIncluded)
  748. {
  749. int Pos=0;
  750. while((Pos=Path.Find('\\',Pos+1))!=-1)
  751. CreateDirectory(Path.Left(Pos),NULL);
  752. if(!FilenameIncluded)
  753. CreateDirectory(Path,NULL);
  754. // return ((!FilenameIncluded)?!_access(Path,0):
  755. // !_access(Path.Left(Path.ReverseFind('\\')),0));
  756. return !_access(Path,0);
  757. }
  758. //获得默认的文件名
  759. BOOL GetDefaultXlsFileName(CString& sExcelFile)
  760. {
  761. ///默认文件名:yyyymmddhhmmss.xls
  762. CString timeStr;
  763. CTime day;
  764. day=CTime::GetCurrentTime();
  765. int filenameday,filenamemonth,filenameyear,filehour,filemin,filesec;
  766. filenameday=day.GetDay();//dd
  767. filenamemonth=day.GetMonth();//mm月份
  768. filenameyear=day.GetYear();//yyyy
  769. filehour=day.GetHour();//hh
  770. filemin=day.GetMinute();//mm分钟
  771. filesec=day.GetSecond();//ss
  772. timeStr.Format("%04d%02d%02d%02d%02d%02d",filenameyear,filenamemonth,filenameday,filehour,filemin,filesec);
  773. sExcelFile = timeStr + ".xls";
  774. // prompt the user (with all document templates)
  775. CFileDialog dlgFile(FALSE,".xls",sExcelFile);
  776. CString title;
  777. CString strFilter;
  778. title = g_strDevDataLog;
  779. strFilter = "Excel文件(*.xls)";
  780. strFilter += (TCHAR)'\0'; // next string please
  781. strFilter += _T("*.xls");
  782. strFilter += (TCHAR)'\0'; // last string
  783. dlgFile.m_ofn.nMaxCustFilter++;
  784. dlgFile.m_ofn.nFilterIndex = 1;
  785. // append the "*.*" all files filter
  786. CString allFilter;
  787. VERIFY(allFilter.LoadString(AFX_IDS_ALLFILTER));
  788. strFilter += allFilter;
  789. strFilter += (TCHAR)'\0'; // next string please
  790. strFilter += _T("*.*");
  791. strFilter += (TCHAR)'\0'; // last string
  792. dlgFile.m_ofn.nMaxCustFilter++;
  793. dlgFile.m_ofn.lpstrFilter = strFilter;
  794. dlgFile.m_ofn.lpstrTitle = title;
  795. if (dlgFile.DoModal()==IDCANCEL)
  796. return FALSE; // open cancelled
  797. sExcelFile = dlgFile.GetPathName();
  798. if (MakeSurePathExists(sExcelFile,true))
  799. {
  800. if(!DeleteFile(sExcelFile))
  801. { // delete the file
  802. MessageBox(NULL, g_strOverWriteError, g_strTip, MB_ICONINFORMATION);
  803. return FALSE;
  804. }
  805. }
  806. return TRUE;
  807. }
  808. ///////////////////////////////////////////////////////////////////////////////
  809. // void ExportListToExcel(CListCtrl* pList, CString strTitle)
  810. // 参数:
  811. // pList 需要导出的List控件指针
  812. // strTitle 导出的数据表标题
  813. // 说明:
  814. // 导出CListCtrl控件的全部数据到Excel文件。Excel文件名由用户通过“另存为”
  815. // 对话框输入指定。创建名为strTitle的工作表,将List控件内的所有数据(包括
  816. // 列名和数据项)以文本的形式保存到Excel工作表中。保持行列关系。
  817. //
  818. // edit by [r]@dotlive.cnblogs.com
  819. ///////////////////////////////////////////////////////////////////////////////
  820. // void ExportListToExcel(CDataGrid* pList, CString strTitle)
  821. // {
  822. // #if 1
  823. // CString warningStr;
  824. // if (pList->GetRowCount()>0)
  825. // {
  826. // CDatabase database;
  827. // CString sDriver;
  828. // CString sExcelFile;
  829. // CString sSql;
  830. // CString tableName = strTitle;
  831. //
  832. // // 检索是否安装有Excel驱动 "Microsoft Excel Driver (*.xls)"
  833. // sDriver = GetExcelDriver();
  834. // if (sDriver.IsEmpty())
  835. // {
  836. // // 没有发现Excel驱动
  837. // //AfxMessageBox("没有安装Excel!\n请先安装Excel软件才能使用导出功能!");
  838. // MessageBox(NULL, "没有安装Excel!\n请先安装Excel软件才能使用导出功能!", g_strTip, MB_ICONINFORMATION);
  839. // return;
  840. // }
  841. //
  842. // ///默认文件名
  843. // if (!GetDefaultXlsFileName(sExcelFile))
  844. // return;
  845. //
  846. // // 创建进行存取的字符串
  847. // sSql.Format("DRIVER={%s};DSN='';FIRSTROWHASNAMES=1;READONLY=FALSE;CREATE_DB=\"%s\";DBQ=%s",sDriver, sExcelFile, sExcelFile);
  848. //
  849. // // 创建数据库 (既Excel表格文件)
  850. // if( database.OpenEx(sSql,CDatabase::noOdbcDialog) )
  851. // {
  852. // // 创建表结构
  853. // int i=0;
  854. // LVCOLUMN columnData;
  855. // CString columnName;
  856. // int columnNum = 0;
  857. // CString strH;
  858. // CString strV;
  859. //
  860. // sSql = "";
  861. // strH = "";
  862. // columnData.mask = LVCF_TEXT;
  863. // columnData.cchTextMax =100;
  864. // columnData.pszText = columnName.GetBuffer (100);
  865. //
  866. // for(i=0;i<pList->GetColumnCount();i++)//GetColumn(i,&columnData)
  867. // {
  868. // if (i!=0)
  869. // {
  870. // sSql = sSql + ", " ;
  871. // strH = strH + ", " ;
  872. // }
  873. //
  874. // CString sName = pList->m_field.GetAt(i).Caption.Trim();
  875. //
  876. // sSql = sSql + " " + sName +" TEXT";
  877. // strH = strH + " " + sName +" ";
  878. // }
  879. // columnName.ReleaseBuffer ();
  880. // columnNum = i;
  881. //
  882. // sSql = "CREATE TABLE " + tableName + " ( " + sSql + " ) ";
  883. // database.ExecuteSQL(sSql);
  884. //
  885. // // 插入数据项
  886. // int nItemIndex;
  887. // for( nItemIndex=1;nItemIndex<pList->GetRowCount();nItemIndex++ )
  888. // {
  889. // strV = "";
  890. // for(i=0;i<columnNum;i++)
  891. // {
  892. // if (i!=0)
  893. // {
  894. // strV = strV + ", " ;
  895. // }
  896. // //strV = strV + " '" + pList->GetItemText(nItemIndex,i) +"' ";
  897. // }
  898. //
  899. // sSql = "INSERT INTO "+ tableName
  900. // +" ("+ strH + ")"
  901. // +" VALUES("+ strV + ")";
  902. // database.ExecuteSQL(sSql);
  903. // }
  904. // }
  905. //
  906. // // 关闭数据库
  907. // database.Close();
  908. //
  909. // warningStr.Format(g_strSaveas,sExcelFile);
  910. // MessageBox(NULL, warningStr, g_strTip, MB_ICONINFORMATION);
  911. // }
  912. // #endif
  913. // }
  914. CString InterceptString(int qlen, CString strSource)
  915. {
  916. int len,i,y;
  917. CString sTemp,sreturn;
  918. strSource.TrimLeft();
  919. strSource.TrimRight();
  920. len=strSource.GetLength();
  921. y=0;
  922. sTemp=strSource.Right(len-qlen);
  923. for(i=0;i<len;i++)
  924. {
  925. //if(sTemp[y]<0 || sTemp[y]>255)
  926. //if(sTemp[i]<0 || sTemp[i]>=128)
  927. //if(sTemp.GetAt(y) & 0x80 )
  928. if(::IsDBCSLeadByte(sTemp.GetAt(y)))
  929. y=y+2;
  930. else
  931. y=y+1;
  932. if(y>=70)
  933. break;
  934. }
  935. sreturn=sTemp.Left(y);
  936. return sreturn;
  937. }
  938. //显示选择文件夹窗口
  939. //参数 sFolderPath:用于返回用户选择的文件夹的路径
  940. //参数 sTitle:用于指定选择文件夹窗口的标题
  941. //返回值 :操作结果,用户取消选择或操作失败返回FALSE,否则TRUE
  942. BOOL BrowseForFolder(CString & sFolderPath, CString sTitle)
  943. {
  944. BROWSEINFO bi;
  945. char Buffer[_MAX_PATH];
  946. bi.hwndOwner = NULL;
  947. bi.pidlRoot = NULL;
  948. bi.pszDisplayName = Buffer;
  949. bi.lpszTitle = sTitle;
  950. bi.ulFlags = 0;
  951. bi.lpfn = NULL;
  952. LPITEMIDLIST pIDList = SHBrowseForFolder(& bi);
  953. if (!pIDList)
  954. return FALSE;
  955. SHGetPathFromIDList(pIDList, Buffer);
  956. sFolderPath = Buffer;
  957. LPMALLOC lpMalloc;
  958. if (FAILED(SHGetMalloc(& lpMalloc)))
  959. return FALSE;
  960. //释放内存
  961. lpMalloc->Free(pIDList);
  962. lpMalloc->Release();
  963. return TRUE;
  964. }
  965. void TimeTicksToInt(CString strSrc, unsigned long &nDest)
  966. {
  967. CString strLeft;
  968. int nIndex = strSrc.Find(":");
  969. if( nIndex != -1 )
  970. {
  971. strLeft = strSrc.Left( nIndex - 1 );
  972. nDest = atoi(strLeft);
  973. }
  974. }
  975. ///目录是否存在的检查:
  976. bool CheckFolderExist(CString strPath)
  977. {
  978. WIN32_FIND_DATA wfd;
  979. bool rValue = false;
  980. HANDLE hFind = FindFirstFile((char *)(LPCTSTR)strPath, &wfd);
  981. if ((hFind != INVALID_HANDLE_VALUE) && (wfd.dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY))
  982. {
  983. rValue = true;
  984. }
  985. FindClose(hFind);
  986. return rValue;
  987. }
  988. BOOL BrowseFile(CString strFile, CString strFilter,
  989. CStringList *pFileList,
  990. CStringList *pFileNameList,
  991. CStringList *pShowNameList) //查找文件函数
  992. {
  993. CFileFind FileFind;
  994. CString SearchTarget = strFile; // + "\\" +strFilter;
  995. if( SearchTarget.Right(1) != "\\" )
  996. SearchTarget += "\\";
  997. SearchTarget += "*.*";
  998. BOOL res = FileFind.FindFile(SearchTarget);
  999. while(res)
  1000. {
  1001. res = FileFind.FindNextFile();
  1002. if(FileFind.IsDirectory() && !FileFind.IsDots())
  1003. {
  1004. //如果是一个子目录,用递归继续往深一层找
  1005. CString strPath = FileFind.GetFilePath();
  1006. CString strTitle = FileFind.GetFileTitle();
  1007. BrowseFile(strPath, strFilter, pFileList, pFileNameList, pShowNameList);
  1008. }
  1009. else if(!FileFind.IsDirectory() && !FileFind.IsDots())
  1010. {
  1011. //显示当前访问的文件
  1012. CString strExtName;
  1013. CString strName;
  1014. strName = FileFind.GetFileName();
  1015. strExtName = strName.Right(strName.GetLength() - strName.Find('.')-1);
  1016. strExtName.MakeUpper();
  1017. if(!strExtName.CompareNoCase(strFilter))//扩展名正确
  1018. {
  1019. CString strPath = FileFind.GetFilePath();
  1020. pFileList->AddTail(strPath);
  1021. pFileNameList->AddTail(strName);
  1022. strName = strName.Left(strName.Find('.'));
  1023. pShowNameList->AddTail(strName);
  1024. }
  1025. }
  1026. }
  1027. FileFind.Close();//关闭
  1028. return TRUE;
  1029. }
  1030. //注册OCX
  1031. BOOL RegisterOCX( CString sOcxPath )
  1032. {
  1033. LPCTSTR pszDllName = sOcxPath;
  1034. HINSTANCE hLib = LoadLibrary(pszDllName);
  1035. if (hLib < (HINSTANCE)HINSTANCE_ERROR)
  1036. {
  1037. return FALSE;
  1038. }
  1039. FARPROC lpDllEntryPoint;
  1040. lpDllEntryPoint = GetProcAddress(hLib,_T("DllRegisterServer"));
  1041. if(lpDllEntryPoint!=NULL)
  1042. {
  1043. if(FAILED(( *lpDllEntryPoint)()))
  1044. {
  1045. FreeLibrary(hLib);
  1046. return FALSE;
  1047. }
  1048. return TRUE;
  1049. }
  1050. else
  1051. return FALSE;
  1052. }
  1053. //注销OCX
  1054. BOOL UnRegisterOCX( CString sOcxPath )
  1055. {
  1056. LPCTSTR pszDllName = sOcxPath;
  1057. HINSTANCE hLib = LoadLibrary(pszDllName);
  1058. if (hLib < (HINSTANCE)HINSTANCE_ERROR)
  1059. {
  1060. return FALSE;
  1061. }
  1062. FARPROC lpDllEntryPoint;
  1063. lpDllEntryPoint = GetProcAddress(hLib,_T("DllUnregisterServer"));
  1064. if(lpDllEntryPoint!=NULL)
  1065. {
  1066. if(FAILED(( *lpDllEntryPoint)()))
  1067. {
  1068. FreeLibrary(hLib);
  1069. return FALSE;
  1070. }
  1071. return TRUE;
  1072. }
  1073. else
  1074. return FALSE;
  1075. }
  1076. WCHAR* StrToWchar(CString strSrc)
  1077. {
  1078. size_t nLen = strSrc.GetLength()+1;
  1079. char *szText = new char[nLen];
  1080. //snprintf(szText, nLen, "%s", strSrc);
  1081. size_t nLenW = ::MultiByteToWideChar(CP_ACP,0,(const char *)szText,int(nLen),NULL,0);
  1082. WCHAR *wszText = new WCHAR[nLenW+1];
  1083. ::MultiByteToWideChar(CP_ACP,0,(const char *)szText,int(nLen),wszText,int(nLenW));
  1084. wszText[nLenW] = L'\0';
  1085. //chn add
  1086. delete []szText;
  1087. szText = NULL;
  1088. return wszText;
  1089. }
  1090. bool g_FindProcess( CString sAppName )
  1091. {
  1092. bool bRet = false;
  1093. HANDLE hSnapShot = CreateToolhelp32Snapshot(TH32CS_SNAPPROCESS, 0);
  1094. if (hSnapShot != NULL)
  1095. {
  1096. PROCESSENTRY32 ProcessInfo = {0};//声明进程信息变量
  1097. ProcessInfo.dwSize = sizeof(ProcessInfo);//设置ProcessInfo的大小
  1098. //返回系统中第一个进程的信息
  1099. BOOL bStatus = Process32First(hSnapShot, &ProcessInfo);
  1100. while (bStatus)
  1101. {
  1102. if (!_stricmp(sAppName, ProcessInfo.szExeFile))//映像名称
  1103. {
  1104. HANDLE hProcess = OpenProcess(PROCESS_ALL_ACCESS, FALSE, ProcessInfo.th32ProcessID);
  1105. bRet = true;
  1106. break;
  1107. }
  1108. else
  1109. {
  1110. //获取下一个进程的信息
  1111. bStatus = Process32Next(hSnapShot, &ProcessInfo);
  1112. }
  1113. }
  1114. }
  1115. return bRet;
  1116. }