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

Visual C++

  1. // FireWall1.cpp : Defines the class behaviors for the application.
  2. //
  3. #include "stdafx.h"
  4. #include "FireWall1.h"
  5. #include "MainFrm.h"
  6. #include "FireWall1Doc.h"
  7. #include "FireWall1View.h"
  8. #ifdef _DEBUG
  9. #define new DEBUG_NEW
  10. #undef THIS_FILE
  11. static char THIS_FILE[] = __FILE__;
  12. #endif
  13. FILE *pfoutBigSet=NULL;
  14. BOOL m_bhide;
  15. int global_set;//bit 0,=1表示网络策略OK;
  16. //bit 1,=1,表示包过滤策略OK;
  17. //bit 2,=1,表示服务策略OK;
  18. /////////////////////////////////////////////////////////////////////////////
  19. // CFireWall1App
  20. BEGIN_MESSAGE_MAP(CFireWall1App, CWinApp)
  21. //{{AFX_MSG_MAP(CFireWall1App)
  22. ON_COMMAND(ID_APP_ABOUT, OnAppAbout)
  23. // NOTE - the ClassWizard will add and remove mapping macros here.
  24. //    DO NOT EDIT what you see in these blocks of generated code!
  25. //}}AFX_MSG_MAP
  26. // Standard file based document commands
  27. ON_COMMAND(ID_FILE_NEW, CWinApp::OnFileNew)
  28. ON_COMMAND(ID_FILE_OPEN, CWinApp::OnFileOpen)
  29. END_MESSAGE_MAP()
  30. /////////////////////////////////////////////////////////////////////////////
  31. // CFireWall1App construction
  32. CFireWall1App::CFireWall1App()
  33. {
  34. // TODO: add construction code here,
  35. global_set=0;
  36. bFound=FALSE;
  37. // Place all significant initialization in InitInstance
  38. }
  39. /////////////////////////////////////////////////////////////////////////////
  40. // The one and only CFireWall1App object
  41. CFireWall1App theApp;
  42. /////////////////////////////////////////////////////////////////////////////
  43. // CFireWall1App initialization
  44. BOOL CFireWall1App::InitInstance()
  45. {
  46.  hMutexOneInstance = CreateMutex(NULL,TRUE,_T("PreventSecondInstance"));
  47.     if(GetLastError() == ERROR_ALREADY_EXISTS)
  48.         bFound = TRUE;
  49.     if(hMutexOneInstance) 
  50.         ReleaseMutex(hMutexOneInstance);
  51.     if (bFound == TRUE) return FALSE;
  52. AfxEnableControlContainer();
  53. // Standard initialization
  54. // If you are not using these features and wish to reduce the size
  55. //  of your final executable, you should remove from the following
  56. //  the specific initialization routines you do not need.
  57. #ifdef _AFXDLL
  58. Enable3dControls(); // Call this when using MFC in a shared DLL
  59. #else
  60. Enable3dControlsStatic(); // Call this when linking to MFC statically
  61. #endif
  62. // Change the registry key under which our settings are stored.
  63. // TODO: You should modify this string to be something appropriate
  64. // such as the name of your company or organization.
  65. SetRegistryKey(_T("Local AppWizard-Generated Applications"));
  66. LoadStdProfileSettings();  // Load standard INI file options (including MRU)
  67. // Register the application's document templates.  Document templates
  68. //  serve as the connection between documents, frame windows and views.
  69. CSingleDocTemplate* pDocTemplate;
  70. pDocTemplate = new CSingleDocTemplate(
  71. IDR_MAINFRAME,
  72. RUNTIME_CLASS(CFireWall1Doc),
  73. RUNTIME_CLASS(CMainFrame),       // main SDI frame window
  74. RUNTIME_CLASS(CFireWall1View));
  75. AddDocTemplate(pDocTemplate);
  76. // Parse command line for standard shell commands, DDE, file open
  77. CCommandLineInfo cmdInfo;
  78. ParseCommandLine(cmdInfo);
  79. // Dispatch commands specified on the command line
  80. if (!ProcessShellCommand(cmdInfo))
  81. return FALSE;
  82. // The one and only window has been initialized, so show and update it.
  83. HICON hicon=LoadIcon(IDI_ICON1);
  84. char c[10] = "防火墙";
  85. MyTaskAddIcon(AfxGetMainWnd()->GetSafeHwnd(), IDI_ICON1, hicon, c);
  86. m_pMainWnd->ShowWindow(SW_HIDE);
  87. m_pMainWnd->UpdateWindow();
  88. m_bhide=TRUE;
  89. char str[15];
  90. memset(str,0,15);
  91. pfoutBigSet=fopen("bigset.txt","r");
  92. if(pfoutBigSet)
  93. {
  94. ReadCommand(pfoutBigSet,str);
  95. sscanf(str,"%d",&global_set);
  96. }
  97. ::SetWindowText(AfxGetMainWnd()->GetSafeHwnd(),"托普防火墙");
  98. return TRUE;
  99. }
  100. /////////////////////////////////////////////////////////////////////////////
  101. // CAboutDlg dialog used for App About
  102. class CAboutDlg : public CDialog
  103. {
  104. public:
  105. CAboutDlg();
  106. // Dialog Data
  107. //{{AFX_DATA(CAboutDlg)
  108. enum { IDD = IDD_ABOUTBOX };
  109. //}}AFX_DATA
  110. // ClassWizard generated virtual function overrides
  111. //{{AFX_VIRTUAL(CAboutDlg)
  112. protected:
  113. virtual void DoDataExchange(CDataExchange* pDX);    // DDX/DDV support
  114. //}}AFX_VIRTUAL
  115. // Implementation
  116. protected:
  117. //{{AFX_MSG(CAboutDlg)
  118. virtual void OnOK();
  119. //}}AFX_MSG
  120. DECLARE_MESSAGE_MAP()
  121. };
  122. CAboutDlg::CAboutDlg() : CDialog(CAboutDlg::IDD)
  123. {
  124. //{{AFX_DATA_INIT(CAboutDlg)
  125. //}}AFX_DATA_INIT
  126. }
  127. void CAboutDlg::DoDataExchange(CDataExchange* pDX)
  128. {
  129. CDialog::DoDataExchange(pDX);
  130. //{{AFX_DATA_MAP(CAboutDlg)
  131. //}}AFX_DATA_MAP
  132. }
  133. BEGIN_MESSAGE_MAP(CAboutDlg, CDialog)
  134. //{{AFX_MSG_MAP(CAboutDlg)
  135. //}}AFX_MSG_MAP
  136. END_MESSAGE_MAP()
  137. // App command to run the dialog
  138. void CFireWall1App::OnAppAbout()
  139. {
  140. CAboutDlg aboutDlg;
  141. aboutDlg.DoModal();
  142. }
  143. /////////////////////////////////////////////////////////////////////////////
  144. // CFireWall1App message handlers
  145. void CFireWall1App::ReadCommand(FILE *pf, char *pbuf)
  146. {
  147. while(feof(pf)==0) {
  148. *pbuf=fgetc(pf);
  149. if(*pbuf=='n') break;
  150. pbuf++;
  151. }
  152. *pbuf--=0;
  153. if(*pbuf=='r')*pbuf=0;
  154. }
  155. void CAboutDlg::OnOK() 
  156. {
  157. // TODO: Add extra validation here
  158. CDialog::OnOK();
  159. }
  160. BOOL CFireWall1App::MyTaskAddIcon(HWND hwnd, UINT uID, HICON hicon, LPSTR lpszTip)
  161. {
  162. BOOL res;
  163. NOTIFYICONDATA tnid;
  164. tnid.cbSize = sizeof(NOTIFYICONDATA);
  165. tnid.hWnd = hwnd;
  166. tnid.uID = uID;
  167. tnid.uFlags = NIF_MESSAGE|NIF_ICON|NIF_TIP;
  168. tnid.uCallbackMessage = MYWN_NOTIFYICON;
  169. tnid.hIcon = hicon;
  170. if(lpszTip)
  171. lstrcpyn(tnid.szTip,lpszTip,sizeof(tnid.szTip));
  172. else
  173. tnid.szTip[0] = '';
  174. res = Shell_NotifyIcon(NIM_ADD,&tnid);
  175. if(hicon)
  176. DestroyIcon(hicon);
  177. return res;
  178. }