SNMPAppDlg.cpp
上传用户:yfy060102
上传日期:2021-05-22
资源大小:60k
文件大小:7k
源码类别:

SNMP编程

开发平台:

Visual C++

  1. // SNMPAppDlg.cpp : implementation file
  2. //
  3. #include "stdafx.h"
  4. #include "SNMPApp.h"
  5. #include "SNMPAppDlg.h"
  6. #ifdef _DEBUG
  7. #define new DEBUG_NEW
  8. #undef THIS_FILE
  9. static char THIS_FILE[] = __FILE__;
  10. #endif
  11. #define WM_ROUTERFINISH WM_USER+777
  12. #define WM_PRINTSTR WM_USER+778
  13. #define WM_SUBNETFINISH WM_USER+779
  14. UINT DoFindTopology(LPVOID pParam);
  15. UINT DoFindSubnet(LPVOID pParam);
  16. enum {normal=0,bold=1,italic=2};
  17. enum {black=0,blue=0x00ff0000,green=0x0000ff00,red=0x000000ff};
  18. class CAboutDlg : public CDialog
  19. {
  20. public:
  21. CAboutDlg();
  22. // Dialog Data
  23. //{{AFX_DATA(CAboutDlg)
  24. enum { IDD = IDD_ABOUTBOX };
  25. //}}AFX_DATA
  26. // ClassWizard generated virtual function overrides
  27. //{{AFX_VIRTUAL(CAboutDlg)
  28. protected:
  29. virtual void DoDataExchange(CDataExchange* pDX);    // DDX/DDV support
  30. //}}AFX_VIRTUAL
  31. // Implementation
  32. protected:
  33. //{{AFX_MSG(CAboutDlg)
  34. //}}AFX_MSG
  35. DECLARE_MESSAGE_MAP()
  36. };
  37. CAboutDlg::CAboutDlg() : CDialog(CAboutDlg::IDD)
  38. {
  39. //{{AFX_DATA_INIT(CAboutDlg)
  40. //}}AFX_DATA_INIT
  41. }
  42. void CAboutDlg::DoDataExchange(CDataExchange* pDX)
  43. {
  44. CDialog::DoDataExchange(pDX);
  45. //{{AFX_DATA_MAP(CAboutDlg)
  46. //}}AFX_DATA_MAP
  47. }
  48. BEGIN_MESSAGE_MAP(CAboutDlg, CDialog)
  49. //{{AFX_MSG_MAP(CAboutDlg)
  50. // No message handlers
  51. //}}AFX_MSG_MAP
  52. END_MESSAGE_MAP()
  53. /////////////////////////////////////////////////////////////////////////////
  54. // CSNMPAppDlg dialog
  55. CSNMPAppDlg::CSNMPAppDlg(CWnd* pParent /*=NULL*/)
  56. : CDialog(CSNMPAppDlg::IDD, pParent)
  57. {
  58. //{{AFX_DATA_INIT(CSNMPAppDlg)
  59. m_input = _T("202.113.16.17");
  60. m_community = _T("public");
  61. m_num = _T("3");
  62. //}}AFX_DATA_INIT
  63. // Note that LoadIcon does not require a subsequent DestroyIcon in Win32
  64. m_hIcon = AfxGetApp()->LoadIcon(IDR_MAINFRAME);
  65. pThread1=NULL;
  66. pThread2=NULL;
  67. }
  68. void CSNMPAppDlg::DoDataExchange(CDataExchange* pDX)
  69. {
  70. CDialog::DoDataExchange(pDX);
  71. //{{AFX_DATA_MAP(CSNMPAppDlg)
  72. DDX_Text(pDX, IDC_INPUT, m_input);
  73. DDX_Text(pDX, IDC_EDTCOMMUNITY, m_community);
  74. DDX_Text(pDX, IDC_EDTNUM, m_num);
  75. //}}AFX_DATA_MAP
  76. }
  77. BEGIN_MESSAGE_MAP(CSNMPAppDlg, CDialog)
  78. //{{AFX_MSG_MAP(CSNMPAppDlg)
  79. ON_WM_SYSCOMMAND()
  80. ON_WM_PAINT()
  81. ON_WM_QUERYDRAGICON()
  82. ON_MESSAGE(WM_ROUTERFINISH,OnRouterFinish)
  83. ON_MESSAGE(WM_SUBNETFINISH,OnSubnetFinish)
  84. ON_BN_CLICKED(IDC_BTN_GETTOP, OnBtnGettop)
  85. ON_BN_CLICKED(IDC_BTN_SUBNET, OnBtnSubnet)
  86. ON_BN_CLICKED(IDC_BTN_STOP, OnBtnStop)
  87. ON_MESSAGE(WM_PRINTSTR,OnPrintStr)
  88. //}}AFX_MSG_MAP
  89. END_MESSAGE_MAP()
  90. /////////////////////////////////////////////////////////////////////////////
  91. // CSNMPAppDlg message handlers
  92. BOOL CSNMPAppDlg::OnInitDialog()
  93. {
  94. CDialog::OnInitDialog();
  95. // Add "About..." menu item to system menu.
  96. // IDM_ABOUTBOX must be in the system command range.
  97. ASSERT((IDM_ABOUTBOX & 0xFFF0) == IDM_ABOUTBOX);
  98. ASSERT(IDM_ABOUTBOX < 0xF000);
  99. CMenu* pSysMenu = GetSystemMenu(FALSE);
  100. if (pSysMenu != NULL)
  101. {
  102. CString strAboutMenu;
  103. strAboutMenu.LoadString(IDS_ABOUTBOX);
  104. if (!strAboutMenu.IsEmpty())
  105. {
  106. pSysMenu->AppendMenu(MF_SEPARATOR);
  107. pSysMenu->AppendMenu(MF_STRING, IDM_ABOUTBOX, strAboutMenu);
  108. }
  109. }
  110. // Set the icon for this dialog.  The framework does this automatically
  111. //  when the application's main window is not a dialog
  112. SetIcon(m_hIcon, TRUE); // Set big icon
  113. SetIcon(m_hIcon, FALSE); // Set small icon
  114. // TODO: Add extra initialization here
  115. m_edit.SubclassDlgItem(IDC_INFWIN,this);
  116. CWnd *pbtnSubnet=GetDlgItem(IDC_BTN_SUBNET);
  117. pbtnSubnet->EnableWindow(FALSE);
  118. CWnd *pbtnStop=GetDlgItem(IDC_BTN_STOP);
  119. pbtnStop->EnableWindow(FALSE);
  120. return TRUE;  // return TRUE  unless you set the focus to a control
  121. }
  122. void CSNMPAppDlg::OnSysCommand(UINT nID, LPARAM lParam)
  123. {
  124. if ((nID & 0xFFF0) == IDM_ABOUTBOX)
  125. {
  126. CAboutDlg dlgAbout;
  127. dlgAbout.DoModal();
  128. }
  129. else
  130. {
  131. CDialog::OnSysCommand(nID, lParam);
  132. }
  133. }
  134. // If you add a minimize button to your dialog, you will need the code below
  135. //  to draw the icon.  For MFC applications using the document/view model,
  136. //  this is automatically done for you by the framework.
  137. void CSNMPAppDlg::OnPaint() 
  138. {
  139. if (IsIconic())
  140. {
  141. CPaintDC dc(this); // device context for painting
  142. SendMessage(WM_ICONERASEBKGND, (WPARAM) dc.GetSafeHdc(), 0);
  143. // Center icon in client rectangle
  144. int cxIcon = GetSystemMetrics(SM_CXICON);
  145. int cyIcon = GetSystemMetrics(SM_CYICON);
  146. CRect rect;
  147. GetClientRect(&rect);
  148. int x = (rect.Width() - cxIcon + 1) / 2;
  149. int y = (rect.Height() - cyIcon + 1) / 2;
  150. // Draw the icon
  151. dc.DrawIcon(x, y, m_hIcon);
  152. }
  153. else
  154. {
  155. CDialog::OnPaint();
  156. }
  157. }
  158. // The system calls this to obtain the cursor to display while the user drags
  159. //  the minimized window.
  160. HCURSOR CSNMPAppDlg::OnQueryDragIcon()
  161. {
  162. return (HCURSOR) m_hIcon;
  163. }
  164. void CSNMPAppDlg::OnRouterFinish()
  165. {
  166. CWnd *pbtnOK=GetDlgItem(IDOK);
  167. pbtnOK->EnableWindow(TRUE);
  168. CWnd *pbtnSubnet=GetDlgItem(IDC_BTN_SUBNET);
  169. pbtnSubnet->EnableWindow(TRUE);
  170. CWnd *pbtnGettop=GetDlgItem(IDC_BTN_GETTOP);
  171. pbtnGettop->EnableWindow(FALSE);
  172. }
  173. void CSNMPAppDlg::OnBtnGettop() 
  174. {
  175. CWnd *pbtnOK=GetDlgItem(IDOK);
  176. pbtnOK->EnableWindow(FALSE);
  177. CWnd *pbtnSubnet=GetDlgItem(IDC_BTN_SUBNET);
  178. pbtnSubnet->EnableWindow(FALSE);
  179. CWnd *pbtnGettop=GetDlgItem(IDC_BTN_GETTOP);
  180. pbtnGettop->EnableWindow(FALSE);
  181. UpdateData();
  182. pThread1=AfxBeginThread((AFX_THREADPROC)DoFindTopology,(void*)this);
  183. }
  184. void CSNMPAppDlg::OnBtnSubnet() 
  185. {
  186. CWnd *pbtnOK=GetDlgItem(IDOK);
  187. pbtnOK->EnableWindow(FALSE);
  188. CWnd *pbtnGettop=GetDlgItem(IDC_BTN_GETTOP);
  189. pbtnGettop->EnableWindow(FALSE);
  190. CWnd *pbtnSubnet=GetDlgItem(IDC_BTN_SUBNET);
  191. pbtnSubnet->EnableWindow(FALSE);
  192. AfxBeginThread((AFX_THREADPROC)DoFindSubnet,(void*)this);
  193. CWnd *pbtnStop=GetDlgItem(IDC_BTN_STOP);
  194. pbtnStop->EnableWindow(TRUE);
  195. }
  196. void CSNMPAppDlg::OnSubnetFinish()
  197. {
  198. CWnd *pbtnOK=GetDlgItem(IDOK);
  199. pbtnOK->EnableWindow(TRUE);
  200. CWnd *pbtnSubnet=GetDlgItem(IDC_BTN_SUBNET);
  201. pbtnSubnet->EnableWindow(FALSE);
  202. CWnd *pbtnStop=GetDlgItem(IDC_BTN_STOP);
  203. pbtnStop->EnableWindow(FALSE);
  204. }
  205. void CSNMPAppDlg::OnBtnStop()
  206. {
  207. extern BOOL g_Stop;
  208. g_Stop=TRUE;
  209. }
  210. void CSNMPAppDlg::OnPrintStr(WPARAM wParam, LPARAM lParam)
  211. {
  212. COLORREF color=(COLORREF)lParam;
  213. int style=wParam;
  214. extern CString infprint;
  215. CHARFORMAT cf,oldcf;
  216. m_edit.GetDefaultCharFormat(cf);
  217. cf.crTextColor=color;
  218. switch (style)
  219. {
  220. case bold:
  221. cf.dwMask |=CFM_BOLD;
  222. cf.dwEffects=CFE_BOLD;
  223. break;
  224. case italic:
  225. cf.dwMask |=CFM_ITALIC;
  226. cf.dwEffects=CFE_ITALIC;
  227. break;
  228. case normal:
  229. default:
  230. break;
  231. }
  232. m_edit.SetSel(-1,-1);
  233. long start1,end1,start2,end2;
  234. m_edit.GetSel(start1,end1);
  235. m_edit.ReplaceSel(infprint);
  236. m_edit.GetSel(start2,end2);
  237. m_edit.SetSel(end1,end2);
  238. m_edit.SetSelectionCharFormat(cf);
  239. m_edit.SetSel(-1,-1);
  240. }
  241. BOOL CSNMPAppDlg::DestroyWindow() 
  242. {
  243. extern CObArray routerSet;
  244. for (int i=0;i<routerSet.GetSize();i++)
  245. {
  246. CRouter* pRouter=(CRouter*)routerSet.GetAt(i);
  247. delete pRouter;
  248. }
  249. return CDialog::DestroyWindow();
  250. }