MainFrame.cpp
上传用户:kklily621
上传日期:2013-06-25
资源大小:252k
文件大小:6k
开发平台:

Visual C++

  1. // MainFrame.cpp : implementation file
  2. //
  3. #include "stdafx.h"
  4. #include "..Property.h"
  5. #include "MainFrame.h"
  6. #include "..MainSheet.h"
  7. #include "....commondebug.h"
  8. #include "..GuiRes.h"
  9. #include "..MainSheet.h"
  10. #include "..PacketMonitor.h"
  11. #include "..LogQuery.h"
  12. #include "..About.h"
  13. #include "..Acl.h"
  14. #include "..SystemSet.h"
  15. #include "....commonxlogfile.h"
  16. #include "..Splash.h"
  17. #ifdef _DEBUG
  18. #define new DEBUG_NEW
  19. #undef THIS_FILE
  20. static char THIS_FILE[] = __FILE__;
  21. #endif
  22. //=============================================================================================
  23. // CMainFrame
  24. extern CPropertyApp theApp;
  25. extern CAclFile m_AclFile;
  26. CMainSheet *dlg = NULL;
  27. CSystemTray m_TrayIcon;
  28. BOOL m_IsSplash = FALSE;
  29. int m_MessageIndex = 0;
  30. IMPLEMENT_DYNCREATE(CMainFrame, CFrameWnd)
  31. CMainFrame::CMainFrame()
  32. {
  33. }
  34. CMainFrame::~CMainFrame()
  35. {
  36. }
  37. BEGIN_MESSAGE_MAP(CMainFrame, CFrameWnd)
  38. //{{AFX_MSG_MAP(CMainFrame)
  39. ON_WM_CREATE()
  40. ON_WM_TIMER()
  41. //}}AFX_MSG_MAP
  42. ON_MESSAGE(WM_ICON_NOTIFY,     OnTrayNotification)
  43. ON_MESSAGE(WM_SESSION_NOTIFY,  OnSessionNotification)
  44. ON_MESSAGE(WM_QUERY_ACL_NOTIFY,  OnAclNotification)
  45. ON_MESSAGE(WM_NET_MESSAGE,  OnShowNetMessage)
  46. END_MESSAGE_MAP()
  47. //=============================================================================================
  48. // CMainFrame message handlers
  49. int CMainFrame::OnCreate(LPCREATESTRUCT lpCreateStruct) 
  50. {
  51. if (CFrameWnd::OnCreate(lpCreateStruct) == -1)
  52. return -1;
  53. if (!m_TrayIcon.Create(this, WM_ICON_NOTIFY, GUI_APP_CAPTION, theApp.LoadIcon(IDI_SMALL_PASS), IDR_MAINFRAME))
  54. return -1;
  55. theApp.SetTrayIcon();
  56. if(!m_TrayIcon.SetMenuDefaultItem(2,TRUE))
  57. return -1;
  58. DWORD dwFlags;
  59. if(InternetGetConnectedState(&dwFlags, 0))
  60. theApp.m_DownloadCommand.InitNetCommand();
  61. else
  62. SetTimer(1, 600000, NULL);
  63. if(!theApp.m_RegisterRequest.m_IsUploaded)
  64. SetTimer(2, 300000, NULL);
  65. // CG: The following line was added by the Splash Screen component. CSplashWnd::ShowSplashScreen(this);
  66. return 0;
  67. }
  68. LRESULT CMainFrame::OnTrayNotification(WPARAM wParam, LPARAM lParam)
  69. {
  70. if(wParam == IDR_MAINFRAME && lParam == WM_LBUTTONDOWN)
  71. {
  72. if(m_MessageIndex != 0)
  73. {
  74. int tmpIndex = m_MessageIndex;
  75. m_MessageIndex = 0;
  76. AfxMessageBox(theApp.m_sMessage[tmpIndex], MB_ICONINFORMATION);
  77. return 0;
  78. }
  79. lParam = WM_LBUTTONDBLCLK;
  80. }
  81.     return m_TrayIcon.OnTrayNotification(wParam, lParam);
  82. }
  83. void CMainFrame::InitMainSheet(int iActivePage)
  84. {
  85. theApp.SetTrayIcon();
  86. if(dlg != NULL)
  87. {
  88. if(iActivePage >= 0)
  89. dlg->SetActivePage(iActivePage);
  90. if(!dlg->IsWindowVisible())
  91. dlg->ShowWindow(SW_SHOW);
  92. dlg->SetForegroundWindow();
  93. return;
  94. }
  95. CLogQuery mLogQuery;
  96. CPacketMonitor mPacketMonitor;
  97. CAcl mAcl;
  98. CSystemSet mSystemSet;
  99. CAbout mAbout;
  100. dlg = new CMainSheet(GUI_APP_CAPTION);
  101. dlg->AddPage(&mPacketMonitor);
  102. dlg->AddPage(&mLogQuery);
  103. dlg->AddPage(&mAcl);
  104. dlg->AddPage(&mSystemSet);
  105. dlg->AddPage(&mAbout);
  106. dlg->SetLogoText(GUI_APP_LOGO);
  107. if(iActivePage >= 0)
  108. dlg->SetActivePage(iActivePage);
  109. dlg->DoModal();
  110. delete dlg;
  111. dlg = NULL;
  112. ODS(_T("XFILTER: release dlg = null"))
  113. }
  114. LRESULT CMainFrame::OnSessionNotification(UINT wParam, LONG lParam)
  115. {
  116. static CXLogFile m_LogFile;
  117. if(theApp.m_XfIoControl == NULL)
  118. return XERR_SUCCESS;
  119. XFILTER_IO_CONTROL ioControl;
  120. ioControl.isession = wParam;
  121. ioControl.session = new SESSION;
  122. theApp.m_XfIoControl(IO_CONTROL_GET_SESSION, &ioControl);
  123. if(ioControl.session->s == 0)
  124. return XERR_SUCCESS;
  125. CPacketMonitor::InsertOneList(
  126. CPacketMonitor::m_pListPacketMonitor, 
  127. ioControl.session,
  128. CPacketMonitor::IsMonitor,
  129. CPacketMonitor::IsScroll
  130. );
  131. if(CAclFile::GetBit(m_AclFile.mAclHeader.bSet, 0))
  132. m_LogFile.AddLog(ioControl.session, m_AclFile.mAclHeader.uiLogSize);
  133. if(ioControl.session->bAction == ACL_ACTION_DENY)
  134. {
  135. if(CAclFile::GetBit(m_AclFile.mAclHeader.bSet, 2))
  136. MessageBeep(0xFFFFFFFF);
  137. if(!m_IsSplash && CAclFile::GetBit(m_AclFile.mAclHeader.bSet, 3))
  138. {
  139. DWORD dwThreadId;
  140. ::CreateThread(NULL, 0, SplashIcon, 0, 0, &dwThreadId);
  141. }
  142. }
  143. free(ioControl.session);
  144. return XERR_SUCCESS;
  145. }
  146. LRESULT CMainFrame::OnAclNotification(UINT wParam, LONG lParam)
  147. {
  148. if(wParam < 0 || wParam > MAX_QUERY_SESSION)
  149. return XERR_INVALID_PARAMETER;
  150. XFILTER_IO_CONTROL ioControl;
  151. ioControl.isession = wParam;
  152. theApp.m_XfIoControl(IO_CONTROL_GET_QUERY_SESSION, &ioControl);
  153. CAcl::AddAclQuery(ioControl.sPathName, FALSE);
  154. theApp.m_XfIoControl(IO_CONTROL_SET_QUERY_SESSION, &ioControl);
  155. return XERR_SUCCESS;
  156. }
  157. DWORD WINAPI SplashIcon(LPVOID pVoid)
  158. {
  159. m_IsSplash = TRUE;
  160. for(int i = 0; i < 3; i++)
  161. {
  162. m_TrayIcon.SetIcon(IDI_SMALL_ALERT);
  163. if(i == 2)
  164. continue;
  165. Sleep(180);
  166. m_TrayIcon.SetIcon(IDI_SMALL_NULL);
  167. Sleep(400);
  168. }
  169. m_IsSplash = FALSE;
  170. return 0;
  171. }
  172. void CMainFrame::OnTimer(UINT nIDEvent) 
  173. {
  174. if(nIDEvent == 1)
  175. {
  176. DWORD dwFlags;
  177. if(InternetGetConnectedState(&dwFlags, 0))
  178. {
  179. theApp.m_DownloadCommand.InitNetCommand();
  180. KillTimer(nIDEvent);
  181. }
  182. }
  183. else if(nIDEvent == 2)
  184. {
  185. if(theApp.m_DownloadCommand.PreUpload())
  186. KillTimer(nIDEvent);
  187. }
  188. CFrameWnd::OnTimer(nIDEvent);
  189. }
  190. LRESULT CMainFrame::OnShowNetMessage(UINT wParam, LONG lParam)
  191. {
  192. if(wParam <= 0 || wParam > MAX_NET_COMMAND)
  193. return XERR_INVALID_PARAMETER;
  194.   ODS(theApp.m_sMessage[wParam]);
  195. static DWORD dwThreadId = NULL;
  196. if(dwThreadId == NULL)
  197. ::CreateThread(NULL, 0, SplashMessage, 0, 0, &dwThreadId);
  198. return XERR_SUCCESS;
  199. }
  200. DWORD WINAPI SplashMessage(LPVOID pVoid)
  201. {
  202. for(int i = 0; i < MAX_NET_COMMAND; i++)
  203. {
  204. if(theApp.m_sMessage[i][0] != '')
  205. {
  206. m_MessageIndex = i;
  207. m_IsSplash = TRUE;
  208. while(m_MessageIndex)
  209. {
  210. m_TrayIcon.SetIcon(IDI_SMALL_MESSAGE);
  211. Sleep(180);
  212. m_TrayIcon.SetIcon(IDI_SMALL_NULL);
  213. Sleep(400);
  214. }
  215. theApp.SetTrayIcon();
  216. m_IsSplash = FALSE;
  217. }
  218. }
  219. ODS("Exit Thread SplashMessage...");
  220. return 0;
  221. }