MFCServiceDlg.cpp 15 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601
  1. // MFCServiceDlg.cpp : 实现文件
  2. //
  3. #include "stdafx.h"
  4. #include "MFCService.h"
  5. #include "MFCServiceDlg.h"
  6. #include "SysLib.h"
  7. #include "ascprocess.h"
  8. #include "tcpprocess.h"
  9. #include "rtuprocess.h"
  10. #include "icpdasprocess.h"
  11. #include "SnmpProcess.h"
  12. #include "NoticeQueue.h"
  13. #include "MainPro.h"
  14. #include "CheckDog.h"
  15. #include "upsparadigmProcess.h"
  16. #include "stulzprocess.h"
  17. #include "Separate.h"
  18. #include "MostDevice.h"
  19. #include "stdio.h"
  20. #include "tchar.h"
  21. #include <windows.h>
  22. #include "winsvc.h"
  23. #include "ping.h"
  24. #include ".\mfcservicedlg.h"
  25. #ifdef _DEBUG
  26. #define new DEBUG_NEW
  27. #endif
  28. HINSTANCE g_hLangDLL;
  29. int CALLBACK Sms_NoticeConfig( BOOL bEnableAlarm )
  30. {
  31. if( bEnableAlarm==1 )
  32. LOG4C((LOG_NOTICE, "收到恢复所有报警通知短信"));
  33. if( bEnableAlarm==0 )
  34. LOG4C((LOG_NOTICE, "收到关闭所有报警通知短信"));
  35. g_bAlarmNoticeFlag = bEnableAlarm;
  36. return 0;
  37. }
  38. // 用于应用程序“关于”菜单项的 CAboutDlg 对话框
  39. class CAboutDlg : public CDialog
  40. {
  41. public:
  42. CAboutDlg();
  43. // 对话框数据
  44. enum { IDD = IDD_ABOUTBOX };
  45. protected:
  46. virtual void DoDataExchange(CDataExchange* pDX); // DDX/DDV 支持
  47. // 实现
  48. protected:
  49. DECLARE_MESSAGE_MAP()
  50. };
  51. CAboutDlg::CAboutDlg() : CDialog(CAboutDlg::IDD)
  52. {
  53. }
  54. void CAboutDlg::DoDataExchange(CDataExchange* pDX)
  55. {
  56. CDialog::DoDataExchange(pDX);
  57. }
  58. BEGIN_MESSAGE_MAP(CAboutDlg, CDialog)
  59. END_MESSAGE_MAP()
  60. // CMFCServiceDlg 对话框
  61. CMFCServiceDlg::CMFCServiceDlg(CWnd* pParent /*=NULL*/)
  62. : CDialog(CMFCServiceDlg::IDD, pParent)
  63. {
  64. m_hIcon = AfxGetApp()->LoadIcon(IDR_MAINFRAME);
  65. m_switching = SERVICE_OFF;
  66. isNotify=FALSE;
  67. }
  68. void CMFCServiceDlg::DoDataExchange(CDataExchange* pDX)
  69. {
  70. CDialog::DoDataExchange(pDX);
  71. }
  72. BEGIN_MESSAGE_MAP(CMFCServiceDlg, CDialog)
  73. ON_WM_SYSCOMMAND()
  74. ON_WM_PAINT()
  75. ON_WM_QUERYDRAGICON()
  76. //}}AFX_MSG_MAP
  77. ON_MESSAGE(WM_SHOWTASK,onShowTask)
  78. ON_BN_CLICKED(Btn_Start, OnBnClickedStart)
  79. ON_BN_CLICKED(Btn_Stop, OnBnClickedStop)
  80. ON_WM_DESTROY()
  81. ON_WM_TIMER()
  82. END_MESSAGE_MAP()
  83. // CMFCServiceDlg 消息处理程序
  84. BOOL CMFCServiceDlg::OnInitDialog()
  85. {
  86. CDialog::OnInitDialog();
  87. // 将\“关于...\”菜单项添加到系统菜单中。
  88. // IDM_ABOUTBOX 必须在系统命令范围内。
  89. ASSERT((IDM_ABOUTBOX & 0xFFF0) == IDM_ABOUTBOX);
  90. ASSERT(IDM_ABOUTBOX < 0xF000);
  91. CMenu* pSysMenu = GetSystemMenu(FALSE);
  92. if (pSysMenu != NULL)
  93. {
  94. CString strAboutMenu;
  95. strAboutMenu.LoadString(IDS_ABOUTBOX);
  96. if (!strAboutMenu.IsEmpty())
  97. {
  98. pSysMenu->AppendMenu(MF_SEPARATOR);
  99. pSysMenu->AppendMenu(MF_STRING, IDM_ABOUTBOX, strAboutMenu);
  100. }
  101. }
  102. // 设置此对话框的图标。当应用程序主窗口不是对话框时,框架将自动
  103. // 执行此操作
  104. SetIcon(m_hIcon, TRUE); // 设置大图标
  105. SetIcon(m_hIcon, FALSE); // 设置小图标
  106. // TODO: 在此添加额外的初始化代码
  107. if (m_switching == SERVICE_OFF)
  108. {
  109. (CButton *)(GetDlgItem(Btn_Start))->EnableWindow(TRUE);
  110. (CButton *)(GetDlgItem(Btn_Stop))->EnableWindow(FALSE);
  111. sprintf(nid.szTip,_T("名称:MFCIOService\n作用:采集设备数据\n公司:tryto\n服务状态:停止"));//信息提示条为"计划任务提醒"
  112. }
  113. else
  114. {
  115. (CButton *)(GetDlgItem(Btn_Start))->EnableWindow(FALSE);
  116. (CButton *)(GetDlgItem(Btn_Stop))->EnableWindow(TRUE);
  117. }
  118. return TRUE; // 除非设置了控件的焦点,否则返回 TRUE
  119. }
  120. void CMFCServiceDlg::OnSysCommand(UINT nID, LPARAM lParam)
  121. {
  122. if ((nID & 0xFFF0) == IDM_ABOUTBOX)
  123. {
  124. CAboutDlg dlgAbout;
  125. dlgAbout.DoModal();
  126. }
  127. else if ((nID & 0xFFF0) == SC_CLOSE) //触发关闭按钮
  128. {
  129. //OnClose(); //不进行关闭;
  130. LOG4C((LOG_NOTICE,"开启托盘"));
  131. ExcuteNofify(); //开启托盘;
  132. //SetTimer(0,100,NULL);
  133. }
  134. else
  135. {
  136. CDialog::OnSysCommand(nID, lParam);
  137. }
  138. }
  139. // 如果向对话框添加最小化按钮,则需要下面的代码
  140. // 来绘制该图标。对于使用文档/视图模型的 MFC 应用程序,
  141. // 这将由框架自动完成。
  142. void CMFCServiceDlg::OnPaint()
  143. {
  144. if (IsIconic())
  145. {
  146. CPaintDC dc(this); // 用于绘制的设备上下文
  147. SendMessage(WM_ICONERASEBKGND, reinterpret_cast<WPARAM>(dc.GetSafeHdc()), 0);
  148. // 使图标在工作矩形中居中
  149. int cxIcon = GetSystemMetrics(SM_CXICON);
  150. int cyIcon = GetSystemMetrics(SM_CYICON);
  151. CRect rect;
  152. GetClientRect(&rect);
  153. int x = (rect.Width() - cxIcon + 1) / 2;
  154. int y = (rect.Height() - cyIcon + 1) / 2;
  155. // 绘制图标
  156. dc.DrawIcon(x, y, m_hIcon);
  157. }
  158. else
  159. {
  160. CDialog::OnPaint();
  161. }
  162. }
  163. //当用户拖动最小化窗口时系统调用此函数取得光标显示。
  164. HCURSOR CMFCServiceDlg::OnQueryDragIcon()
  165. {
  166. return static_cast<HCURSOR>(m_hIcon);
  167. }
  168. LRESULT CMFCServiceDlg::onShowTask(WPARAM wParam,LPARAM lParam)//wParam接收的是图标的ID,而lParam接收的是鼠标的行为
  169. {
  170. if(wParam!=IDR_MAINFRAME)
  171. return 1;
  172. switch(lParam)
  173. {
  174. case WM_RBUTTONUP: //右键起来时弹出快捷菜单,这里只有一个"关闭"
  175. {
  176. LPPOINT lpoint=new tagPOINT;
  177. ::GetCursorPos(lpoint); //得到鼠标位置
  178. CMenu menu;
  179. menu.CreatePopupMenu(); //声明一个弹出式菜单
  180. if (m_switching == SERVICE_OFF)
  181. {
  182. menu.AppendMenu(MF_STRING,Btn_Start,_T("启动服务"));
  183. }
  184. else
  185. menu.AppendMenu(MF_STRING,Btn_Stop,_T("停止服务"));
  186. menu.AppendMenu(MF_STRING,WM_DESTROY,_T("退出服务")); //增加菜单项"关闭",点击则发送消息WM_DESTROY给主窗口(已隐藏),将程序结束。
  187. menu.TrackPopupMenu(TPM_RIGHTALIGN|TPM_TOPALIGN,lpoint->x,lpoint->y,this);//确定弹出式菜单的位置
  188. SetForegroundWindow();
  189. HMENU hmenu=menu.Detach(); //资源回收
  190. menu.DestroyMenu();
  191. delete lpoint;
  192. }break;
  193. case WM_LBUTTONDBLCLK: //双击左键的处理
  194. {
  195. //this->ShowWindow(SW_SHOW); //简单的显示主窗口完事儿
  196. //KillTimer(0);
  197. }break;
  198. }
  199. return 0;
  200. }
  201. void CMFCServiceDlg::ExcuteNofify()
  202. {
  203. // TODO: 在此添加控件通知处理程序代码
  204. if (!isNotify)
  205. {
  206. //CString strOnTip = "名称:MFCIOService\n作用:采集设备数据\n公司:StoneU\n服务开启";
  207. //CString strOffTip = "名称:MFCIOService\n作用:采集设备数据\n公司:StoneU\n服务停止";
  208. nid.cbSize=(DWORD)sizeof(NOTIFYICONDATA);
  209. nid.hWnd=this->m_hWnd;
  210. nid.uID=IDR_MAINFRAME;
  211. nid.uFlags=NIF_ICON|NIF_MESSAGE|NIF_TIP|NIF_INFO;
  212. nid.uCallbackMessage=WM_SHOWTASK;//自定义的消息名称,注意:这里的消息是用户自定义消息
  213. nid.hIcon=LoadIcon(AfxGetInstanceHandle(),MAKEINTRESOURCE(IDR_MAINFRAME));
  214. if(m_switching == SERVICE_OFF)
  215. {
  216. sprintf(nid.szTip,_T("名称:MFCIOService\n作用:采集设备数据\n公司:tryto\n服务状态:停止"));//信息提示条为"计划任务提醒"
  217. sprintf(nid.szInfo,_T("服务已停止"));
  218. }
  219. else
  220. {
  221. sprintf(nid.szTip,_T("名称:MFCIOService\n作用:采集设备数据\n公司:tryto\n服务状态:开启"));//信息提示条为"计划任务提醒"
  222. sprintf(nid.szInfo,_T("服务已开启"));
  223. }
  224. //sprintf(nid.szTip,_T("名称:MFCIOService\n作用:采集设备数据\n公司:StoneU\n"));//信息提示条为"计划任务提醒"
  225. sprintf(nid.szInfoTitle,_T("内容"));
  226. nid.dwInfoFlags=NIIF_INFO;
  227. nid.uTimeout=5000;
  228. Shell_NotifyIcon(NIM_ADD,&nid);//在托盘区添加图标
  229. }
  230. //AnimateWindow(1000,AW_HIDE|AW_BLEND); //可以缓慢消失窗口
  231. // KillTimer(0);
  232. ShowWindow(SW_HIDE);//隐藏主窗口
  233. }
  234. BOOL CMFCServiceDlg::InitIOService()
  235. {
  236. // 创建运行控制事件;
  237. MTVERIFY (g_hRunObject = ::CreateEvent(
  238. NULL, /* Security */
  239. TRUE, /* Manual event */
  240. 0, /* Clear on creation */
  241. 0));
  242. //软件时间限制代码
  243. //if( ProgramEncrypt(NULL) == 0 ) return FALSE;
  244. g_pDevicesManager = new CDevicesManager();
  245. // 初始化软件狗
  246. #if IS_USE_DOG
  247. if( InitDog() != 0 )
  248. {
  249. if( g_hRunObject != NULL )
  250. {
  251. MTVERIFY( CloseHandle( g_hRunObject ) );
  252. g_hRunObject = NULL;
  253. }
  254. return FALSE;
  255. }
  256. #endif
  257. //LOG4C((LOG_NOTICE, "%s", g_strConnectString));
  258. //连接数据库
  259. //LOG4C((LOG_NOTICE, "Enter OpenDataBase"));
  260. CDBConnection::GetInstancePtr()->OpenDataBase(g_strConnectString);
  261. //LOG4C((LOG_NOTICE, "Leave OpenDataBase"));
  262. //LOG4C((LOG_NOTICE, "Enter DBConnectionCheckThreadStart"));
  263. // 数据库连接状态 判断线程;
  264. CDBConnection::GetInstancePtr()->DBConnectionCheckThreadStart();
  265. //LOG4C((LOG_NOTICE, "Leave DBConnectionCheckThreadStart"));
  266. //LOG4C((LOG_NOTICE, "Enter SetDBType"));
  267. // 设置数据库类型;
  268. CDBInterface::GetInstancePtr()->SetDBType(g_strDBType);
  269. //LOG4C((LOG_NOTICE, "Leave SetDBType"));
  270. //LOG4C((LOG_NOTICE, "Enter InitUserRoleInfo"));
  271. // 分配用户角色
  272. CDBInterface::GetInstancePtr()->InitUserRoleInfo();
  273. //LOG4C((LOG_NOTICE, "Leave InitUserRoleInfo"));
  274. //LOG4C((LOG_NOTICE, "Enter InitNotice"));
  275. // 创建 变量删除控制 事件;
  276. MTVERIFY( g_hDeleteVarSem = CreateEvent(NULL, TRUE, TRUE, "DeleteVarList") );
  277. // 初始化 变量提示互斥;
  278. InitializeCriticalSection( &g_csVarNotice );
  279. // 初始化 发送报警互斥;
  280. InitializeCriticalSection( &g_csSendNotice );
  281. // ***************初始化 语音报警功能模块***************;
  282. if( g_nSendNotice )
  283. {
  284. InitNotice();
  285. }
  286. else
  287. LOG4C((LOG_NOTICE, "没有启用语言报警"));
  288. // ***************初始化 短信报警功能模块***************;
  289. if( g_nSendSms==1 )
  290. {
  291. CString strCommPort = CString(g_strSmsComPort);
  292. strCommPort = strCommPort.Mid( 3 );
  293. if( 0==InitSms( 0, atoi(strCommPort), g_nSmsRate, g_nSmsDataBit,
  294. g_nSmsStopBit, g_nSmsParity, g_nSmsInterval, g_nSmsLanguageTrans, g_nSmsMaxChar, g_nSmsMakeCall ) )
  295. {
  296. #if 1
  297. if( pSmsDllSetCallBack )
  298. {
  299. LOG4C((LOG_NOTICE, "启用短信回调函数"));
  300. pSmsDllSetCallBack( Sms_NoticeConfig );
  301. }else
  302. LOG4C((LOG_NOTICE,"open com failed~"));
  303. #endif
  304. }
  305. }
  306. else if( g_nSendSms==2 )
  307. {
  308. LOG4C((LOG_NOTICE, "启用支持短信平台服务"));
  309. }
  310. else
  311. LOG4C((LOG_NOTICE, "没有启用短信报警"));
  312. // ***************初始化 Email报警功能模块***************;
  313. if( g_nSendEmail )
  314. {
  315. InitEmail(g_strEmailSMTPSrv, g_nEmailSMTPPort, g_nEmailIsNeed, g_strEmailUserAcc, g_strEmailUserPwd,
  316. g_strEmailFromAddr, g_nEmailTimeOut);
  317. }
  318. else
  319. LOG4C((LOG_NOTICE, "没有启用email报警"));
  320. #if 0
  321. // 创建 TCP通信服务器 = 所有变量只用一个端口进行通信;
  322. g_pTcpServer = new CServerSocket();
  323. CString strPort;
  324. strPort.Format("%d", SOCKET_SERVER_PORT);
  325. // 开始 客户端 与 服务端通信线程;
  326. g_pTcpServer->SvrStart(strPort);
  327. #else
  328. //LOG4C((LOG_NOTICE, "open listen port"));
  329. // 创建 TCP通信服务器 = 多个端口进行通信,按变量每份100进行端口创建;
  330. g_pServerSocket[0] = new CServerSocket();
  331. CString strPort;
  332. strPort.Format("%d", SOCKET_SERVER_PORT);
  333. // 开始 客户端 与 服务端通信线程;
  334. g_pServerSocket[0]->SvrStart(strPort);
  335. #endif
  336. // 初始化ping命令 功能模块;
  337. InitPing();
  338. // 开始采集I/O设备
  339. StartMain();
  340. //UnInitIOService();
  341. return TRUE;
  342. }
  343. void CMFCServiceDlg::UnInitIOService()
  344. {
  345. MTVERIFY( SetEvent( g_hDeleteVarSem ) );
  346. DeleteCriticalSection( &g_csVarNotice );
  347. DeleteCriticalSection( &g_csSendNotice );
  348. if( g_hDeleteVarSem )
  349. {
  350. MTVERIFY( CloseHandle( g_hDeleteVarSem) );
  351. g_hDeleteVarSem = NULL;
  352. }
  353. if (g_hRunObject != NULL)
  354. MTVERIFY( SetEvent( g_hRunObject ) );
  355. EndMain();
  356. #if 0
  357. if (g_pTcpServer != NULL)
  358. {
  359. g_pTcpServer->SocketStop();
  360. delete g_pTcpServer;
  361. g_pTcpServer = NULL;
  362. }
  363. #else
  364. for( int i = 0; i < MAX_SERVER_LISTEN; i++ )
  365. {
  366. if( NULL != g_pServerSocket[i] )
  367. {
  368. g_pServerSocket[i]->SocketStop();
  369. delete g_pServerSocket[i];
  370. g_pServerSocket[i] = NULL;
  371. }
  372. }
  373. #endif
  374. UnInitRtuDll();
  375. UnInitTcpDll();
  376. UnInitAscDll();
  377. UnInitIcpdasDll();
  378. UnInitSnmpDll();
  379. UnInitParadigmDll();
  380. UnInitStulzDll();
  381. UnInitSeparateDll();
  382. UnInitNotice();
  383. if( g_nSendEmail )
  384. {
  385. UnInitEmail();
  386. }
  387. if( g_nSendSms==1 )
  388. {
  389. UnInitSms();
  390. }
  391. //回收用户角色
  392. CDBInterface::GetInstancePtr()->UnInitUserRoleInfo();
  393. CDBConnection::GetInstancePtr()->DBConnectionCheckThreadStop();
  394. // 释放软件狗
  395. #if IS_USE_DOG
  396. UnInitDog();
  397. #endif
  398. if( g_pDevicesManager )
  399. {
  400. delete g_pDevicesManager;
  401. g_pDevicesManager = NULL;
  402. }
  403. if( g_hRunObject != NULL )
  404. {
  405. MTVERIFY( CloseHandle( g_hRunObject ) );
  406. }
  407. if(g_hLangDLL)
  408. {
  409. AfxFreeLibrary(g_hLangDLL);
  410. }
  411. UnInitPing();
  412. }
  413. void CMFCServiceDlg::OnBnClickedStart()
  414. {
  415. (CButton *)(GetDlgItem(Btn_Start))->EnableWindow(FALSE);
  416. (CButton *)(GetDlgItem(Btn_Stop))->EnableWindow();
  417. if ( !InitIOService())
  418. {
  419. MessageBox("服务退出");
  420. (CButton *)(GetDlgItem(Btn_Start))->EnableWindow();
  421. (CButton *)(GetDlgItem(Btn_Stop))->EnableWindow(FALSE);
  422. return;
  423. }
  424. if (m_switching == SERVICE_OFF)
  425. {
  426. m_switching = SEEVICE_ON;
  427. }
  428. nid.cbSize=(DWORD)sizeof(NOTIFYICONDATA);
  429. nid.hWnd=this->m_hWnd;
  430. nid.uID=IDR_MAINFRAME;
  431. nid.uFlags=NIF_ICON|NIF_MESSAGE|NIF_TIP|NIF_INFO;
  432. nid.uCallbackMessage=WM_SHOWTASK;//自定义的消息名称,注意:这里的消息是用户自定义消息
  433. nid.hIcon=LoadIcon(AfxGetInstanceHandle(),MAKEINTRESOURCE(IDR_MAINFRAME));
  434. sprintf(nid.szTip,_T("名称:MFCIOService\n作用:采集设备数据\n公司:tryto\n服务状态:开启"));//信息提示条为"计划任务提醒"
  435. //sprintf(nid.szTip,_T("名称:MFCIOService\n作用:采集设备数据\n公司:StoneU\n"));//信息提示条为"计划任务提醒"
  436. sprintf(nid.szInfo,_T("服务已启动"));
  437. sprintf(nid.szInfoTitle,_T("内容"));
  438. nid.dwInfoFlags=NIIF_INFO;
  439. nid.uTimeout=5000;
  440. Shell_NotifyIcon(NIM_MODIFY,&nid);//在托盘区添加图标
  441. }
  442. void CMFCServiceDlg::OnBnClickedStop()
  443. {
  444. (CButton *)(GetDlgItem(Btn_Start))->EnableWindow();
  445. (CButton *)(GetDlgItem(Btn_Stop))->EnableWindow(FALSE);
  446. UnInitIOService();
  447. if (m_switching == SEEVICE_ON)
  448. {
  449. m_switching = SERVICE_OFF;
  450. }
  451. nid.cbSize=(DWORD)sizeof(NOTIFYICONDATA);
  452. nid.hWnd=this->m_hWnd;
  453. nid.uID=IDR_MAINFRAME;
  454. nid.uFlags=NIF_ICON|NIF_MESSAGE|NIF_TIP|NIF_INFO;
  455. nid.uCallbackMessage=WM_SHOWTASK;//自定义的消息名称,注意:这里的消息是用户自定义消息
  456. nid.hIcon=LoadIcon(AfxGetInstanceHandle(),MAKEINTRESOURCE(IDR_MAINFRAME));
  457. sprintf(nid.szTip,_T("名称:MFCIOService\n作用:采集设备数据\n公司:tryto\n服务状态:停止"));//信息提示条为"计划任务提醒"
  458. //sprintf(nid.szTip,_T("名称:MFCIOService\n作用:采集设备数据\n公司:StoneU\n"));//信息提示条为"计划任务提醒"
  459. sprintf(nid.szInfo,_T("服务已停止"));
  460. sprintf(nid.szInfoTitle,_T("内容"));
  461. nid.dwInfoFlags=NIIF_INFO;
  462. nid.uTimeout=5000;
  463. Shell_NotifyIcon(NIM_MODIFY,&nid);//在托盘区添加图标
  464. }
  465. void CMFCServiceDlg::OnDestroy()
  466. {
  467. CDialog::OnDestroy();
  468. //KillTimer(0);
  469. Shell_NotifyIcon(NIM_DELETE,&nid);
  470. }
  471. void CMFCServiceDlg::OnTimer(UINT nIDEvent)
  472. {
  473. // TODO: 在此添加消息处理程序代码和/或调用默认值
  474. LOG4C((LOG_NOTICE,"时间控制器"));
  475. nid.cbSize=(DWORD)sizeof(NOTIFYICONDATA);
  476. nid.hWnd=this->m_hWnd;
  477. nid.uID=IDR_MAINFRAME;
  478. nid.uFlags=NIF_ICON|NIF_MESSAGE|NIF_TIP|NIF_INFO;
  479. nid.uCallbackMessage=WM_SHOWTASK;//自定义的消息名称,注意:这里的消息是用户自定义消息
  480. nid.hIcon=LoadIcon(AfxGetInstanceHandle(),MAKEINTRESOURCE(IDR_MAINFRAME));
  481. if(m_switching == SERVICE_OFF)
  482. {
  483. sprintf(nid.szTip,_T("名称:MFCIOService\n作用:采集设备数据\n公司:tryto\n服务状态:停止"));//信息提示条为"计划任务提醒"
  484. }
  485. else
  486. {
  487. sprintf(nid.szTip,_T("名称:MFCIOService\n作用:采集设备数据\n公司:tryto\n服务状态:开启"));//信息提示条为"计划任务提醒"
  488. }
  489. //sprintf(nid.szTip,_T("名称:MFCIOService\n作用:采集设备数据\n公司:StoneU\n"));//信息提示条为"计划任务提醒"
  490. sprintf(nid.szInfo,_T("采集服务"));
  491. sprintf(nid.szInfoTitle,_T("内容"));
  492. nid.dwInfoFlags=NIIF_INFO;
  493. nid.uTimeout=5000;
  494. Shell_NotifyIcon(NIM_ADD,&nid);//在托盘区添加图标
  495. CDialog::OnTimer(nIDEvent);
  496. }