MainFrm.cpp
上传用户:heseme
上传日期:2009-12-23
资源大小:228k
文件大小:5k
开发平台:

Visual C++

  1. // MainFrm.cpp : implementation of the CMainFrame class
  2. //
  3. #include "stdafx.h"
  4. #include "FireWall1.h"
  5. #include "Struct.h"
  6. #include "MainFrm.h"
  7. #ifdef _DEBUG
  8. #define new DEBUG_NEW
  9. #undef THIS_FILE
  10. static char THIS_FILE[] = __FILE__;
  11. #endif
  12. extern BOOL m_bhide;
  13. //extern CListCtrl m_listView;
  14. //extern CListCtrl m_listView1;
  15. extern BOOL flag ;
  16. #define MAXITEMNUMBER 10
  17. extern USHORT logType;
  18. char myBuf[140];
  19. //extern int number;
  20. //#define MAXITEMNUMBER 10
  21. //extern LV_ITEM lvItem;
  22. //extern LV_ITEM lvItem1;
  23. //extern CListCtrl m_listView;
  24. //extern CListCtrl m_listView1;
  25. /////////////////////////////////////////////////////////////////////////////
  26. // CMainFrame
  27. IMPLEMENT_DYNCREATE(CMainFrame, CFrameWnd)
  28. BEGIN_MESSAGE_MAP(CMainFrame, CFrameWnd)
  29. //{{AFX_MSG_MAP(CMainFrame)
  30. ON_WM_CREATE()
  31. ON_COMMAND(ID_STOP_LOG, OnStopLog)
  32. ON_UPDATE_COMMAND_UI(ID_STOP_LOG, OnUpdateStopLog)
  33. ON_MESSAGE(MYWN_NOTIFYICON,MyTaskBarProc)
  34. ON_WM_DESTROY()
  35.     ON_WM_SYSCOMMAND()
  36. //}}AFX_MSG_MAP
  37. // ON_MESSAGE(M_LOGVIEW,OnLogView)
  38. END_MESSAGE_MAP()
  39. static UINT indicators[] =
  40. {
  41. ID_SEPARATOR,           // status line indicator
  42. ID_INDICATOR_CAPS,
  43. ID_INDICATOR_NUM,
  44. ID_INDICATOR_SCRL,
  45. };
  46. /////////////////////////////////////////////////////////////////////////////
  47. // CMainFrame construction/destruction
  48. CMainFrame::CMainFrame()
  49. {
  50. // TODO: add member initialization code here
  51. }
  52. CMainFrame::~CMainFrame()
  53. {
  54. }
  55. int CMainFrame::OnCreate(LPCREATESTRUCT lpCreateStruct)
  56. {
  57. if (CFrameWnd::OnCreate(lpCreateStruct) == -1)
  58. return -1;
  59. if (!m_wndToolBar.CreateEx(this, TBSTYLE_FLAT, WS_CHILD | WS_VISIBLE | CBRS_TOP
  60. | CBRS_GRIPPER | CBRS_TOOLTIPS | CBRS_FLYBY | CBRS_SIZE_DYNAMIC) ||
  61. !m_wndToolBar.LoadToolBar(IDR_MAINFRAME))
  62. {
  63. TRACE0("Failed to create toolbarn");
  64. return -1;      // fail to create
  65. }
  66. if (!m_wndStatusBar.Create(this) ||
  67. !m_wndStatusBar.SetIndicators(indicators,
  68.   sizeof(indicators)/sizeof(UINT)))
  69. {
  70. TRACE0("Failed to create status barn");
  71. return -1;      // fail to create
  72. }
  73. // TODO: Delete these three lines if you don't want the toolbar to
  74. //  be dockable
  75. m_wndToolBar.EnableDocking(CBRS_ALIGN_ANY);
  76. EnableDocking(CBRS_ALIGN_ANY);
  77. DockControlBar(&m_wndToolBar);
  78. /*
  79. HICON hicon=AfxGetApp()->LoadIcon(IDI_ICON1);
  80. char c[10] = "防火墙";
  81. ((CFireWall1App*)AfxGetApp())->MyTaskAddIcon(AfxGetMainWnd()->GetSafeHwnd(), IDI_ICON1, hicon, c);
  82. */
  83. return 0;
  84. }
  85. BOOL CMainFrame::PreCreateWindow(CREATESTRUCT& cs)
  86. {
  87. if( !CFrameWnd::PreCreateWindow(cs) )
  88. return FALSE;
  89. // TODO: Modify the Window class or styles here by modifying
  90. //  the CREATESTRUCT cs
  91. return TRUE;
  92. }
  93. /////////////////////////////////////////////////////////////////////////////
  94. // CMainFrame diagnostics
  95. #ifdef _DEBUG
  96. void CMainFrame::AssertValid() const
  97. {
  98. CFrameWnd::AssertValid();
  99. }
  100. void CMainFrame::Dump(CDumpContext& dc) const
  101. {
  102. CFrameWnd::Dump(dc);
  103. }
  104. #endif //_DEBUG
  105. /////////////////////////////////////////////////////////////////////////////
  106. // CMainFrame message handlers
  107. void CMainFrame::OnStopLog() 
  108. {
  109. // TODO: Add your command handler code here
  110. }
  111. void CMainFrame::OnUpdateStopLog(CCmdUI* pCmdUI) 
  112. {
  113. // TODO: Add your command update UI handler code here
  114. }
  115. BOOL CMainFrame::MyTaskBarDelIcon(HWND hwnd, UINT uID)
  116. {
  117. BOOL res;
  118. NOTIFYICONDATA tnid;
  119. tnid.cbSize = sizeof(NOTIFYICONDATA);
  120. tnid.hWnd = hwnd;
  121. tnid.uID = uID;
  122. res = Shell_NotifyIcon(NIM_DELETE,&tnid);
  123. return res;
  124. }
  125. BOOL CMainFrame::MyTaskChangeIcon(HWND hwnd, UINT uID)
  126. {
  127. BOOL res;
  128. HICON hicon;
  129. hicon=LoadIcon(AfxGetApp()->m_hInstance,MAKEINTRESOURCE(m_bhide?IDI_ICON2:IDI_ICON1));
  130. NOTIFYICONDATA tnid;
  131. tnid.cbSize = sizeof(NOTIFYICONDATA);
  132. tnid.hWnd = hwnd;
  133. tnid.uID = uID;
  134. tnid.uFlags = NIF_MESSAGE|NIF_ICON|NIF_TIP;
  135. tnid.uCallbackMessage = MYWN_NOTIFYICON;
  136. tnid.hIcon = hicon;
  137. char lpszTip[10] = "防火墙";
  138. if(lpszTip)
  139. lstrcpyn(tnid.szTip,lpszTip,sizeof(tnid.szTip));
  140. else
  141. tnid.szTip[0] = '';
  142. res = Shell_NotifyIcon(NIM_MODIFY,&tnid);
  143. if(hicon)
  144. DestroyIcon(hicon);
  145. return res;
  146. }
  147. LRESULT CMainFrame::MyTaskBarProc(WPARAM wParam, LPARAM lParam)
  148. {
  149. UINT uID = (UINT)wParam;
  150. UINT uMsg = (UINT)lParam;
  151. if(uID == IDI_ICON1)
  152. {
  153. switch(uMsg)
  154. {
  155. case WM_LBUTTONDOWN:
  156.             MyTaskChangeIcon(m_hWnd,IDI_ICON1);
  157. ShowWindow(SW_SHOW);
  158. SetForegroundWindow();
  159. m_bhide=(m_bhide?FALSE:TRUE);
  160. break;
  161. case WM_RBUTTONUP:
  162. {
  163. CMenu menu;
  164. menu.LoadMenu(IDR_MENU_ICON);
  165. CPoint point;
  166. GetCursorPos(&point);
  167. ////--------
  168. SetForegroundWindow();
  169. ////--------
  170. menu.GetSubMenu(0)->TrackPopupMenu(TPM_LEFTBUTTON|TPM_RIGHTBUTTON, 
  171. point.x, point.y, this, NULL);
  172. ////--------
  173. }
  174. break;
  175. default:
  176. break;
  177. }
  178. }
  179.     return 1L;
  180. }
  181. void CMainFrame::OnDestroy() 
  182. {
  183. CFrameWnd::OnDestroy();
  184.     MyTaskBarDelIcon(m_hWnd,IDI_ICON1);  
  185. }
  186. void CMainFrame::OnSysCommand(UINT nID, LPARAM lParam)
  187. {
  188. if(nID==61472)
  189. ShowWindow(SW_HIDE);
  190.     else
  191. CFrameWnd::OnSysCommand(nID,lParam);
  192. }
  193. BOOL CMainFrame::OnCmdMsg(UINT nID, int nCode, void* pExtra, AFX_CMDHANDLERINFO* pHandlerInfo) 
  194. {
  195. // TODO: Add your specialized code here and/or call the base class
  196. return CFrameWnd::OnCmdMsg(nID, nCode, pExtra, pHandlerInfo);
  197. }
  198. BOOL CMainFrame::OnCreateClient(LPCREATESTRUCT lpcs, CCreateContext* pContext) 
  199. {
  200. return CFrameWnd::OnCreateClient(lpcs, pContext);
  201. }