MAINFRM.CPP
上传用户:lvjun8202
上传日期:2013-04-30
资源大小:797k
文件大小:32k
源码类别:

SNMP编程

开发平台:

C/C++

  1. // MainFrm.cpp : implementation of the CMainFrame class
  2. //
  3. #include "stdafx.h"
  4. #include "OAM.h"
  5. #include "MainFrm.h"
  6. #include "OAMDoc.h"
  7. #include "Splash.h"
  8. #include "Agent.h"
  9. #include "snmp1.h"
  10. #include "MainView.h"
  11. #include "usermanagement.h"
  12. #include "GlobalVariable.h"
  13. #include "string.h" 
  14. #include "DlgSet.h"
  15. #ifdef _DEBUG
  16. #define new DEBUG_NEW
  17. #undef THIS_FILE
  18. static char THIS_FILE[] = __FILE__;
  19. #endif
  20. /////////////////////////////////////////////////////////////////////////////
  21. // CMainFrame
  22.  
  23. IMPLEMENT_DYNCREATE(CMainFrame, CFrameWnd)
  24. BEGIN_MESSAGE_MAP(CMainFrame, CFrameWnd)
  25. ON_WM_INITMENUPOPUP()
  26. ON_WM_MENUSELECT()
  27. ON_UPDATE_COMMAND_UI(ID_INDICATOR_DATE, OnUpdateDate)
  28. ON_UPDATE_COMMAND_UI(ID_INDICATOR_TIME, OnUpdateTime)
  29. //{{AFX_MSG_MAP(CMainFrame)
  30. ON_WM_CREATE()
  31. ON_WM_TIMER()
  32. ON_WM_CLOSE()
  33. ON_WM_INITMENU()
  34. ON_COMMAND(ID_NOT_REPORT, OnNotReport)
  35. ON_UPDATE_COMMAND_UI(ID_NOT_REPORT, OnUpdateNotReport)
  36. ON_COMMAND(ID_SETAGENT, OnSetagent)
  37. ON_COMMAND(ID_ACTION_GET, OnActionGet)
  38. ON_COMMAND(ID_ACTION_GETBULK, OnActionGetbulk)
  39. ON_COMMAND(ID_ACTION_GETNEXT, OnActionGetnext)
  40. ON_COMMAND(ID_ACTION_SET, OnActionSet)
  41. ON_MESSAGE(wMsg,OnRecv)
  42. ON_COMMAND(ID_USER, OnUser)
  43. ON_UPDATE_COMMAND_UI(ID_ACTION_GET, OnUpdateActionGet)
  44. ON_UPDATE_COMMAND_UI(ID_ACTION_GETNEXT, OnUpdateActionGetnext)
  45. ON_UPDATE_COMMAND_UI(ID_ACTION_SET, OnUpdateActionSet)
  46. ON_UPDATE_COMMAND_UI(ID_USER, OnUpdateUser)
  47. //}}AFX_MSG_MAP
  48. // Global help commands
  49. ON_CBN_SELENDOK(ID_VIEW_ADDRESS,OnNewAddress)
  50. ON_COMMAND(IDOK, OnNewAddressEnter)
  51. ON_COMMAND_EX(ID_VIEW_ADDRESS, OnBarCheck)
  52. ON_UPDATE_COMMAND_UI(ID_VIEW_ADDRESS, OnUpdateControlBarMenu)
  53. ON_COMMAND_EX(ID_VIEW_WORKSPACE, OnBarCheck)
  54. ON_UPDATE_COMMAND_UI(ID_VIEW_WORKSPACE, OnUpdateControlBarMenu)
  55. ON_COMMAND_EX(ID_VIEW_PROMPT, OnBarCheck)
  56. ON_UPDATE_COMMAND_UI(ID_VIEW_PROMPT, OnUpdateControlBarMenu)
  57. ON_COMMAND_EX(ID_VIEW_OUTPUT, OnBarCheck)
  58. ON_UPDATE_COMMAND_UI(ID_VIEW_OUTPUT, OnUpdateControlBarMenu)
  59. ON_COMMAND(ID_HELP_FINDER, CFrameWnd::OnHelpFinder)
  60. ON_COMMAND(ID_HELP, CFrameWnd::OnHelp)
  61. ON_COMMAND(ID_CONTEXT_HELP, CFrameWnd::OnContextHelp)
  62. ON_COMMAND(ID_DEFAULT_HELP, CFrameWnd::OnHelpFinder)
  63. ON_NOTIFY(TBN_DROPDOWN, AFX_IDW_TOOLBAR, OnDropDown)
  64. END_MESSAGE_MAP()
  65. static UINT indicators[] =
  66. {
  67. ID_SEPARATOR,           // status line indicator
  68. ID_INDICATOR_CAPS,
  69. ID_INDICATOR_NUM,
  70. ID_INDICATOR_SCRL,
  71. };
  72. /////////////////////////////////////////////////////////////////////////////
  73. // CMainFrame construction/destruction
  74. CMainFrame::CMainFrame()
  75. {
  76. m_nStatusPane1Width = -1;
  77. m_bMenuSelect = FALSE;
  78. NoReport=FALSE;
  79. int i;
  80. SelfFlag=0;
  81.     for(i=0;i<=9;i++ )
  82. {
  83. m_value[i]=new smiVALUE[100];
  84. m_sOid[i]=new char[100];
  85. str[i]=new char[100];
  86. }
  87. CGlobalVariable::m_pMainFrame=this;
  88. for(int k=0;k<=16;k++)
  89. for (int j=0;j<=3;j++)
  90. test[k][j]=0;
  91.   
  92. }
  93. CMainFrame::~CMainFrame()
  94. {
  95. /* int nCount = m_arrRecentView.GetSize();
  96. for (int i = 0; i < nCount; i++)
  97. delete m_arrRecentView.GetAt(i);
  98. m_arrRecentView.RemoveAll();*/
  99. }
  100. int CMainFrame::OnCreate(LPCREATESTRUCT lpCreateStruct)
  101. {
  102. if (CFrameWnd::OnCreate(lpCreateStruct) == -1)
  103. return -1;
  104. // CSplashWnd::ShowSplashScreen(this);
  105. CGlobalVariable::Init();
  106. if(!CreateToolBar())
  107. {
  108. return -1;
  109. }
  110. if (!m_wndStatusBar.Create(this) ||
  111. !m_wndStatusBar.SetIndicators(indicators,
  112.   sizeof(indicators)/sizeof(UINT)))
  113. {
  114. TRACE0("Failed to create status barn");
  115. return -1;      // fail to create
  116. }
  117. SetInitialSize(50,100,200,100);
  118.  
  119. if (!m_wndReportBar.Create(this, ID_VIEW_OUTPUT,
  120.    _T("操作报告"), CSize(300,100), CBRS_BOTTOM))
  121. {
  122. TRACE0("Failed to create dialog bar m_wndReportListBarn");
  123. return -1; // fail to create
  124. }
  125. if (!m_wndWorkspace.Create(this, ID_VIEW_WORKSPACE,
  126. _T("工作区"), CSize(300,100), CBRS_LEFT))
  127. {
  128. TRACE0("Failed to create dialog bar m_wndWorkspacen");
  129. return -1; // fail to create
  130. }
  131. m_wndWorkspace.EnableDockingOnSizeBar(CBRS_ALIGN_ANY);
  132. m_wndReportBar.EnableDockingOnSizeBar(CBRS_BOTTOM | CBRS_LEFT| CBRS_RIGHT);
  133. EnableDockingSizeBar(CBRS_ALIGN_ANY);
  134. DockSizeBar(&m_wndWorkspace) ;
  135. DockSizeBar(&m_wndReportBar);
  136. m_3DManager.Install(this); /*显示漂亮的动态*/
  137. _pMainFrame = this;
  138. int nOrigSize = sizeof(indicators) / sizeof(UINT);
  139. UINT* pIndicators = new UINT[nOrigSize + 2];
  140. memcpy(pIndicators, indicators, sizeof(indicators));
  141. // Call the Status Bar Component's status bar creation function
  142. if (!InitStatusBar(pIndicators, nOrigSize, 60))
  143. {
  144. TRACE0("Failed to initialize Status Barn");
  145. return -1;
  146. }
  147. delete[] pIndicators;
  148. return 0;
  149. }
  150. BOOL CMainFrame::PreCreateWindow(CREATESTRUCT& cs)
  151. {
  152. if( !CFrameWnd::PreCreateWindow(cs) )
  153. return FALSE;
  154. // TODO: Modify the Window class or styles here by modifying
  155. //  the CREATESTRUCT cs
  156. cs.style = WS_OVERLAPPED | WS_CAPTION// | FWS_ADDTOTITLE
  157. | WS_THICKFRAME | WS_SYSMENU | WS_MINIMIZEBOX | WS_MAXIMIZEBOX | WS_MAXIMIZE;
  158. cs.cx = 800;
  159. cs.cy = 600;
  160. return TRUE;
  161. }
  162. /////////////////////////////////////////////////////////////////////////////
  163. // CMainFrame diagnostics
  164. #ifdef _DEBUG
  165. void CMainFrame::AssertValid() const
  166. {
  167. CFrameWnd::AssertValid();
  168. }
  169. void CMainFrame::Dump(CDumpContext& dc) const
  170. {
  171. CFrameWnd::Dump(dc);
  172. }
  173. #endif //_DEBUG
  174. /////////////////////////////////////////////////////////////////////////////
  175. // CMainFrame message handlers
  176. BOOL CMainFrame::CreateToolBar()
  177. {
  178. if (!m_wndToolBar.CreateEx(this))
  179. {
  180. TRACE0("Failed to create toolbarn");
  181. return FALSE;      // fail to create
  182. }
  183. m_wndToolBar.ModifyStyle(0,TBSTYLE_CUSTOMERASE);
  184. if (!m_wndMenuBar.CreateEx(this)||(m_wndMenuBar.SetOwner(this),m_wndMenuBar.LoadMenu(IDR_MAINFRAME)))
  185. {
  186. TRACE0("Failed to create menu barn");
  187. return FALSE;      // fail to create
  188. }
  189. m_wndMenuBar.ModifyStyle(0, TBSTYLE_TRANSPARENT|TBSTYLE_FLAT|TBSTYLE_CUSTOMERASE );
  190. if (!m_wndReBar.Create(this))
  191. {
  192. TRACE0("Failed to create rebarn");
  193. return FALSE;      // fail to create
  194. }
  195. // m_wndReBar.GetReBarCtrl().ModifyStyle(RBS_BANDBORDERS ,0);   
  196. CString str;
  197. CImageList imageList;
  198. HBITMAP hBitmap;
  199. BITMAP bm;
  200. CBitmap * pBitmap;
  201. hBitmap = (HBITMAP)LoadImage(AfxGetInstanceHandle(),"toolbar1.bmp",
  202. IMAGE_BITMAP,0,0,LR_LOADFROMFILE|LR_CREATEDIBSECTION);
  203. if(hBitmap == NULL)
  204. return FALSE;
  205. pBitmap = CBitmap::FromHandle(hBitmap);
  206.     GetObject(hBitmap,sizeof(BITMAP),&bm);
  207. if(imageList.Create(bm.bmWidth/8, bm.bmHeight, ILC_COLORDDB|ILC_MASK, 8, 1)
  208. && imageList.Add(pBitmap, RGB(255,0,255)) != -1)
  209. {
  210. }
  211. m_wndToolBar.GetToolBarCtrl().SetHotImageList(&imageList);
  212. imageList.Detach();
  213. ::DeleteObject(hBitmap);
  214. // Create and set the normal toolbar image list.
  215. hBitmap = (HBITMAP)LoadImage(AfxGetInstanceHandle(),"toolbar1.bmp",
  216. IMAGE_BITMAP,0,0,LR_LOADFROMFILE|LR_CREATEDIBSECTION);
  217. if(hBitmap == NULL)
  218. return FALSE;
  219. pBitmap = CBitmap::FromHandle(hBitmap);
  220.     GetObject(hBitmap,sizeof(BITMAP),&bm);
  221. if(imageList.Create(bm.bmWidth/8, bm.bmHeight, ILC_COLORDDB|ILC_MASK, 8, 1)
  222. && imageList.Add(pBitmap, RGB(255,0,255)) != -1)
  223. {
  224. }
  225. m_wndToolBar.GetToolBarCtrl().SetImageList(&imageList);
  226. imageList.Detach();
  227. ::DeleteObject(hBitmap);
  228. // Create and set the disabled toolbar image list.
  229. hBitmap = (HBITMAP)LoadImage(AfxGetInstanceHandle(),"toolbar1.bmp",
  230. IMAGE_BITMAP,0,0,LR_LOADFROMFILE|LR_CREATEDIBSECTION);
  231. if(hBitmap == NULL)
  232. return FALSE;
  233. pBitmap = CBitmap::FromHandle(hBitmap);
  234.     GetObject(hBitmap,sizeof(BITMAP),&bm);
  235. if(imageList.Create(bm.bmWidth/8,  bm.bmHeight, ILC_COLORDDB|ILC_MASK, 8, 1)
  236. && imageList.Add(pBitmap, RGB(255,0,255)) != -1)
  237. {
  238. }
  239. m_wndToolBar.GetToolBarCtrl().SetDisabledImageList(&imageList);
  240. imageList.Detach();
  241. ::DeleteObject(hBitmap);
  242. m_wndToolBar.ModifyStyle(0, TBSTYLE_FLAT | TBSTYLE_TRANSPARENT);
  243. m_wndToolBar.SetButtons(NULL, 5);
  244. // set up each toolbar button
  245. m_wndToolBar.SetButtonInfo(0, ID_ACTION_GET, TBSTYLE_BUTTON, 0);
  246. m_wndToolBar.SetButtonText(0, "取属性值");
  247. m_wndToolBar.SetButtonInfo(1, ID_ACTION_GETNEXT, TBSTYLE_BUTTON, 1);
  248. m_wndToolBar.SetButtonText(1, "取下一个属性值");
  249. m_wndToolBar.SetButtonInfo(2, ID_ACTION_SET, TBSTYLE_BUTTON, 2);
  250. m_wndToolBar.SetButtonText(2, "设置属性值");
  251. m_wndToolBar.SetButtonInfo(3, ID_USER, TBSTYLE_BUTTON, 3);
  252. m_wndToolBar.SetButtonText(3, "用户管理");
  253. m_wndToolBar.SetButtonInfo(4, ID_SETAGENT, TBSTYLE_BUTTON, 4);
  254. m_wndToolBar.SetButtonText(4, "设置代理");
  255. CRect rectToolBar;
  256. // set up toolbar button sizes
  257. m_wndToolBar.GetItemRect(0, &rectToolBar);
  258. m_wndToolBar.GetToolBarCtrl().SetButtonWidth(50, 150);
  259. m_wndToolBar.GetToolBarCtrl().SetExtendedStyle(TBSTYLE_EX_DRAWDDARROWS);
  260. // m_wndToolBar.SetSizes(rectToolBar.Size(), CSize(30,20));
  261. // create a combo box for the address bar
  262. if (!m_wndAddress.Create(CBS_DROPDOWN | WS_CHILD, CRect(0, 0, 200, 120), this, ID_VIEW_ADDRESS))
  263. {
  264. TRACE0("Failed to create comboboxn");
  265. return -1;      // fail to create
  266. }
  267. m_wndAddress.SetFont(&m_fontSys);
  268. CGlobalVariable::m_pAddressCombo = &m_wndAddress;
  269. // create the animation control
  270. m_wndAnimate.Create(WS_CHILD | WS_VISIBLE, CRect(0, 0, 10, 10), this, AFX_IDW_TOOLBAR + 2);
  271. m_wndAnimate.Open(IDR_VC6);
  272. m_wndAnimate.Play(0,-1,-1);
  273. // add the toolbar, animation, and address bar to the rebar
  274. m_wndReBar.AddBar(&m_wndMenuBar, NULL, NULL, RBBS_FIXEDSIZE | RBBS_FIXEDBMP);
  275. m_wndReBar.AddBar(&m_wndAnimate, NULL, NULL, RBBS_FIXEDSIZE | RBBS_FIXEDBMP);
  276. m_wndReBar.AddBar(&m_wndToolBar, "", NULL, RBBS_FIXEDBMP | RBBS_BREAK);
  277. str = _T("所选oid");
  278. m_wndReBar.AddBar(&m_wndAddress, str, NULL, RBBS_FIXEDBMP | RBBS_BREAK);
  279. CRect rcMenuBar;
  280. m_wndMenuBar.GetItemRect(0, &rcMenuBar);
  281. // set up min/max sizes and ideal sizes for pieces of the rebar
  282. REBARBANDINFO rbbi;
  283. rbbi.cbSize = sizeof(rbbi);
  284. rbbi.fMask = RBBIM_CHILDSIZE | RBBIM_IDEALSIZE | RBBIM_SIZE;// | RBBIM_STYLE;
  285. // rbbi.fStyle = RBBS_NOGRIPPER;
  286. rbbi.cxMinChild = rcMenuBar.Width();
  287. rbbi.cyMinChild = rcMenuBar.Height();
  288. rbbi.cx = rbbi.cxIdeal = rcMenuBar.Width() * m_wndMenuBar.GetToolBarCtrl().GetButtonCount();
  289. m_wndReBar.GetReBarCtrl().SetBandInfo(0, &rbbi);
  290. rbbi.cxMinChild = 0;
  291. rbbi.fMask = RBBIM_CHILDSIZE | RBBIM_IDEALSIZE | RBBIM_SIZE ;
  292. rbbi.cxMinChild = rectToolBar.Width();
  293. rbbi.cyMinChild = rectToolBar.Height();
  294. rbbi.cx = rbbi.cxIdeal = rectToolBar.Width() * 9;
  295. m_wndReBar.GetReBarCtrl().SetBandInfo(2, &rbbi);
  296. rbbi.cxMinChild = 0;
  297. return TRUE;
  298. }
  299. void CMainFrame::OnTimer(UINT nIDEvent) 
  300. {
  301. // TODO: Add your message handler code here and/or call default
  302. // if((nIDEvent == 98 || nIDEvent == 99 )&& _pMainDoc)
  303. //if(nIDEvent == 99 && _pMainDoc)
  304. // _pMainDoc->OnTimer(nIDEvent);
  305. CFrameWnd::OnTimer(nIDEvent);
  306. this->m_wndReportBar.WriteReportLine("+++++++++++++timer+++++++",0);
  307. }
  308. void CMainFrame::OnNewAddress()
  309. {
  310. // gets called when an item in the Address combo box is selected
  311. // just navigate to the newly selected location.
  312. CString str;
  313. m_wndAddress.GetLBText(m_wndAddress.GetCurSel(), str);
  314. if(CGlobalVariable::m_pStationTreeView)
  315.         1==1;
  316. // CGlobalVariable::m_pStationTreeView->SelectAdress(str);
  317. // ((CMfcieView*)GetActiveView())->Navigate2(str, 0, NULL);
  318. }
  319. void CMainFrame::OnNewAddressEnter()
  320. {
  321. // gets called when an item is entered manually into the edit box portion
  322. // of the Address combo box.
  323. // navigate to the newly selected location and also add this address to the
  324. // list of addresses in the combo box.
  325. CString str;
  326. m_wndAddress.GetWindowText(str);
  327. // m_wndAddress.GetLBText(m_wndAddress.GetCurSel(), str);
  328. // m_wndAddress.GetEditCtrl()->GetWindowText(str);
  329. // ((CMfcieView*)GetActiveView())->Navigate2(str, 0, NULL);
  330. m_wndAddress.AddNewAdress(str);
  331. /* if(CGlobalVariable::m_pStationTreeView)
  332. CGlobalVariable::m_pStationTreeView->SelectAdress(str);*/
  333. }
  334. BOOL CMainFrame::PreTranslateMessage(MSG* pMsg) 
  335. {
  336. // TODO: Add your specialized code here and/or call the base class
  337. return m_wndMenuBar.TranslateFrameMessage(pMsg) ?
  338. TRUE : CFrameWnd::PreTranslateMessage(pMsg);
  339. // return CFrameWnd::PreTranslateMessage(pMsg);
  340. }
  341. void CMainFrame::OnDropDown(NMHDR *pNotifyStruct, LRESULT *pResult)
  342. {
  343. // this function handles the dropdown menus from the toolbar
  344. /* NMTOOLBAR* pNMToolBar = (NMTOOLBAR*)pNotifyStruct;
  345. CRect rect;
  346. // translate the current toolbar item rectangle into screen coordinates
  347. // so that we'll know where to pop up the menu
  348. m_wndToolBar.GetToolBarCtrl().GetRect(pNMToolBar->iItem, &rect);
  349. rect.top = rect.bottom;
  350. ::ClientToScreen(pNMToolBar->hdr.hwndFrom, &rect.TopLeft());
  351. if(pNMToolBar->iItem == ID_BACK || pNMToolBar->iItem == ID_FORWARD)
  352. {
  353. CMenu menu;
  354. menu.CreatePopupMenu();
  355. while(m_astrCurrentURLs.GetSize()>0)
  356. m_astrCurrentURLs.RemoveAt(0);
  357. int nHist;
  358. if(pNMToolBar->iItem == ID_BACK)
  359. nHist = m_nCurrentPosition-1;
  360. else
  361. nHist = m_nCurrentPosition+1;
  362. CString str;
  363. int nPos = 0;
  364. while(nHist>=0 && nHist<m_arrRecentView.GetSize())
  365. {
  366. CViewMgrItem * pMgrItem = m_arrRecentView.GetAt(nHist);
  367. if(pMgrItem)
  368. {
  369. if(pMgrItem->m_nView == ID_MAIN_VIEW)
  370. str = _T("主屏");
  371. else if(pMgrItem->m_nView == ID_STATISTICS_VIEW)
  372. str = _T("统计");
  373. else //if(pMgrItem->m_pCompenentFormer)
  374. str = pMgrItem->m_strName;
  375. menu.AppendMenu(MF_STRING, 0x1e00+nPos, str);
  376. m_astrCurrentURLs.InsertAt(nPos,str);
  377. nPos++;
  378. }
  379. if(pNMToolBar->iItem == ID_BACK)
  380. nHist--;
  381. else
  382. nHist++;
  383. }
  384. menu.TrackPopupMenu(TPM_LEFTALIGN|TPM_RIGHTBUTTON, rect.left, rect.top + 1, this);
  385. menu.DestroyMenu();
  386. }
  387. *pResult = TBDDRET_DEFAULT;*/
  388. }
  389. void CMainFrame::OnClose() 
  390. {
  391. // TODO: Add your message handler code here and/or call default
  392. //SaveBarState(_T("HJD04EBar"));
  393. if(MessageBox("确实要退出吗?","友情提醒!",MB_ICONQUESTION|MB_OKCANCEL) == IDOK)
  394. {
  395. CFrameWnd::OnClose();
  396. }
  397. }
  398. void CMainFrame::OnMenuSelect(UINT nItemID, UINT nFlags, HMENU hSysMenu)
  399. {
  400.    CFrameWnd::OnMenuSelect(nItemID, nFlags, hSysMenu);
  401.   
  402. // CG: The following block was inserted by 'Status Bar' component.
  403. {
  404. // Restore first pane of the statusbar?
  405. if (nFlags == 0xFFFF && hSysMenu == 0 && m_nStatusPane1Width != -1)
  406. {
  407. m_bMenuSelect = FALSE;
  408. m_wndStatusBar.SetPaneInfo(0, 
  409. m_nStatusPane1ID, m_nStatusPane1Style, m_nStatusPane1Width);
  410. m_nStatusPane1Width = -1;   // Set it to illegal value
  411. }
  412. else 
  413. {
  414. m_bMenuSelect = TRUE;
  415. }
  416. }
  417. }
  418. void CMainFrame::OnInitMenuPopup(CMenu* pPopupMenu, UINT nIndex, BOOL bSysMenu)
  419. {
  420.    CFrameWnd::OnInitMenuPopup(pPopupMenu, nIndex, bSysMenu);
  421.   
  422. // CG: The following block was inserted by 'Status Bar' component.
  423. {
  424. // store width of first pane and its style
  425. if (m_nStatusPane1Width == -1 && m_bMenuSelect)
  426. {
  427. m_wndStatusBar.GetPaneInfo(0, m_nStatusPane1ID, 
  428. m_nStatusPane1Style, m_nStatusPane1Width);
  429. m_wndStatusBar.SetPaneInfo(0, m_nStatusPane1ID, 
  430. SBPS_NOBORDERS|SBPS_STRETCH, 16384);
  431. }
  432. }
  433. }
  434. void CMainFrame::OnUpdateDate(CCmdUI* pCmdUI)
  435. {
  436. // CG: This function was inserted by 'Status Bar' component.
  437. // Get current date and format it
  438. CTime time = CTime::GetCurrentTime();
  439. CString strDate = time.Format(_T("%x"));
  440. // BLOCK: compute the width of the date string
  441. CSize size;
  442. {
  443. HGDIOBJ hOldFont = NULL;
  444. HFONT hFont = (HFONT)m_wndStatusBar.SendMessage(WM_GETFONT);
  445. CClientDC dc(NULL);
  446. if (hFont != NULL) 
  447. hOldFont = dc.SelectObject(hFont);
  448. size = dc.GetTextExtent(strDate);
  449. if (hOldFont != NULL) 
  450. dc.SelectObject(hOldFont);
  451. }
  452. // Update the pane to reflect the current date
  453. UINT nID, nStyle;
  454. int nWidth;
  455. m_wndStatusBar.GetPaneInfo(m_nDatePaneNo, nID, nStyle, nWidth);
  456. m_wndStatusBar.SetPaneInfo(m_nDatePaneNo, nID, nStyle, size.cx);
  457. pCmdUI->SetText(strDate);
  458. pCmdUI->Enable(TRUE);
  459. }
  460. void CMainFrame::OnUpdateTime(CCmdUI* pCmdUI)
  461. {
  462. // CG: This function was inserted by 'Status Bar' component.
  463. // Get current date and format it
  464. CTime time = CTime::GetCurrentTime();
  465. CString strTime = time.Format(_T("%X"));
  466. // BLOCK: compute the width of the date string
  467. CSize size;
  468. {
  469. HGDIOBJ hOldFont = NULL;
  470. HFONT hFont = (HFONT)m_wndStatusBar.SendMessage(WM_GETFONT);
  471. CClientDC dc(NULL);
  472. if (hFont != NULL) 
  473. hOldFont = dc.SelectObject(hFont);
  474. size = dc.GetTextExtent(strTime);
  475. if (hOldFont != NULL) 
  476. dc.SelectObject(hOldFont);
  477. }
  478. // Update the pane to reflect the current time
  479. UINT nID, nStyle;
  480. int nWidth;
  481. m_wndStatusBar.GetPaneInfo(m_nTimePaneNo, nID, nStyle, nWidth);
  482. m_wndStatusBar.SetPaneInfo(m_nTimePaneNo, nID, nStyle, size.cx);
  483. pCmdUI->SetText(strTime);
  484. pCmdUI->Enable(TRUE);
  485. }
  486. BOOL CMainFrame::InitStatusBar(UINT *pIndicators, int nSize, int nSeconds)
  487. {
  488. // CG: This function was inserted by 'Status Bar' component.
  489. // Create an index for the DATE pane
  490. m_nDatePaneNo = nSize++;
  491. pIndicators[m_nDatePaneNo] = ID_INDICATOR_DATE;
  492. // Create an index for the TIME pane
  493. m_nTimePaneNo = nSize++;
  494. nSeconds = 1;
  495. pIndicators[m_nTimePaneNo] = ID_INDICATOR_TIME;
  496. // TODO: Select an appropriate time interval for updating
  497. // the status bar when idling.
  498. m_wndStatusBar.SetTimer(0x1000, nSeconds * 1000, NULL);
  499. return m_wndStatusBar.SetIndicators(pIndicators, nSize);
  500. }
  501. void CMainFrame::OnInitMenu(CMenu* pMenu) 
  502. {
  503. CFrameWnd::OnInitMenu(pMenu);
  504. // CG: This block added by 'Tip of the Day' component.
  505. /* {
  506. // TODO: This code adds the "Tip of the Day" menu item
  507. // on the fly.  It may be removed after adding the menu
  508. // item to all applicable menu items using the resource
  509. // editor.
  510. // Add Tip of the Day menu item on the fly!
  511. static CMenu* pSubMenu = NULL;
  512. CString strHelp; strHelp.LoadString(CG_IDS_TIPOFTHEDAYHELP);
  513. CString strMenu;
  514. int nMenuCount = pMenu->GetMenuItemCount();
  515. BOOL bFound = FALSE;
  516. for (int i=0; i < nMenuCount; i++) 
  517. {
  518. pMenu->GetMenuString(i, strMenu, MF_BYPOSITION);
  519. if (strMenu == strHelp)
  520. pSubMenu = pMenu->GetSubMenu(i);
  521. bFound = TRUE;
  522. ASSERT(pSubMenu != NULL);
  523. }
  524. }
  525. CString strTipMenu;
  526. strTipMenu.LoadString(CG_IDS_TIPOFTHEDAYMENU);
  527. if (!bFound)
  528. {
  529. // Help menu is not available. Please add it!
  530. if (pSubMenu == NULL) 
  531. {
  532. // The same pop-up menu is shared between mainfrm and frame 
  533. // with the doc.
  534. static CMenu popUpMenu;
  535. pSubMenu = &popUpMenu;
  536. pSubMenu->CreatePopupMenu();
  537. pSubMenu->InsertMenu(0, MF_STRING|MF_BYPOSITION, 
  538. CG_IDS_TIPOFTHEDAY, strTipMenu);
  539. pMenu->AppendMenu(MF_STRING|MF_BYPOSITION|MF_ENABLED|MF_POPUP, 
  540. (UINT)pSubMenu->m_hMenu, strHelp);
  541. DrawMenuBar();
  542. else
  543. {      
  544. // Check to see if the Tip of the Day menu has already been added.
  545. pSubMenu->GetMenuString(0, strMenu, MF_BYPOSITION);
  546. if (strMenu != strTipMenu) 
  547. {
  548. // Tip of the Day submenu has not been added to the 
  549. // first position, so add it.
  550. pSubMenu->InsertMenu(0, MF_BYPOSITION);  // Separator
  551. pSubMenu->InsertMenu(0, MF_STRING|MF_BYPOSITION, 
  552. CG_IDS_TIPOFTHEDAY, strTipMenu);
  553. }
  554. }
  555. }
  556. */
  557. }
  558. void CMainFrame::OnNotReport() 
  559. {
  560. // TODO: Add your command handler code here
  561. NoReport=!NoReport;
  562. }
  563. void CMainFrame::OnUpdateNotReport(CCmdUI* pCmdUI) 
  564. {
  565. // TODO: Add your command update UI handler code here
  566. pCmdUI->SetCheck (NoReport);
  567. }
  568. void CMainFrame::OnSetagent() 
  569. {
  570. CAgent dlg;
  571.      dlg.m_agent=this->m_agent;
  572. if(dlg.DoModal()==IDCANCEL)
  573. {
  574. // this->m_wndReportBar.WriteReportLine("欢迎进入snmp管理系统", 0);
  575. // this->m_wndReportBar.WriteReportLine("请设置代理相应的信息", 0);
  576. }
  577.         //
  578.       else
  579. {
  580.  
  581. this->m_wndReportBar.WriteReportLine("*******************", 0);
  582. this->m_wndReportBar.WriteReportLine("修改参数信息为", 0);
  583.    this->m_wndReportBar.WriteReportLine("*******************", 0);
  584. this->m_wndReportBar.WriteReportLine("当前管理代理设备ip", 0);
  585.             this->m_wndReportBar.WriteReportLine(dlg.m_agent, 0);
  586. this->m_wndReportBar.WriteReportLine("当前管理社区标志", 0);
  587.             this->m_wndReportBar.WriteReportLine(dlg.m_community, 0);
  588.             this->m_agent =dlg.m_agent;
  589. this->m_community =dlg.m_community;
  590. }
  591. }
  592. void CMainFrame::OnActionGet() 
  593. {
  594. flag=1; /*表示是 get操作*/
  595. CString str1;
  596. m_wndAddress.GetWindowText(str1);
  597. SelfFlag=0;
  598. CString a=str1.Left(22);
  599.     if (!strcmp(a,"1.3.6.1.4.1.26.5.1.5.1")) 
  600. SelfFlag=1; /*表明是board操作*/
  601.     Start(1);
  602. }
  603. void CMainFrame::OnActionGetbulk() 
  604. {
  605. // TODO: Add your command handler code here
  606. flag=3;
  607. Start(3);
  608. }
  609. void CMainFrame::OnActionGetnext() 
  610. {
  611. // TODO: Add your command handler code here
  612. SelfFlag=0;
  613. CString str1;
  614. m_wndAddress.GetWindowText(str1);
  615. if (!strcmp(str1.Left(22),"1.3.6.1.4.1.26.5.1.5.1")) SelfFlag=1; /*表明是board操作*/
  616. flag=2;
  617. Start(2);
  618. }
  619. void CMainFrame::OnActionSet() 
  620. {
  621. CDlgSet dlg;
  622. smiVALUE value;
  623. smiOCTETS str;
  624. if(pSnmp.sessionID==FALSE)
  625. {
  626. pSnmp.CreateSession(CMainFrame::m_hWnd,wMsg);
  627. pSnmp.sessionID=TRUE;
  628. }
  629. dlg.pMain=this;
  630. if(dlg.DoModal()==IDOK)
  631. {
  632. value.syntax=SNMP_SYNTAX_OCTETS;
  633. str.ptr=new unsigned char;
  634. strcpy((char*)str.ptr,dlg.m_sValue);
  635. str.len=lstrlen(dlg.m_sValue);
  636. value.value.string=str;
  637. CString str1;
  638. m_wndAddress.GetWindowText(str1);
  639. str1=str1+_T(".") + "0"; 
  640. pSnmp.CreateVbl(str1,&value);
  641. Start(4); /*标明是set操作*/
  642. }
  643. }
  644. void CMainFrame::OnRecv() /*响应*/
  645. {
  646. int nIpin;
  647. CString strIp;
  648. CString strTemp;
  649. smiLPINT PDU_type=new smiINT; 
  650.     char* pSrc =new char[100];
  651. int status;
  652. CString strHead;
  653. CTime  NowTime;
  654. int output=0;/*在正常的输出窗口输出*/
  655. //status =pSnmp.Receive(m_sOid,m_value,PDU_type,pSrc);
  656. status=pSnmp.Receive(m_sOid,m_value,PDU_type,pSrc);
  657. if (!status)
  658. {
  659. NowTime=CTime::GetCurrentTime();
  660.   strHead = NowTime.Format("%Y-%m-%d %H:%M:%S "); this->m_wndReportBar.WriteReportLine((strHead+"------接收消息失败---"),2);
  661. return;
  662. }
  663. if (*PDU_type==SNMP_PDU_TRAP )
  664. {
  665. NowTime=CTime::GetCurrentTime();
  666. strHead = NowTime.Format("%Y-%m-%d %H:%M:%S ");
  667. this->m_wndReportBar.WriteReportLine((strHead+"接收陷进---from @"),1);
  668. this->m_wndReportBar.WriteReportLine(pSrc,1);
  669.        output=1;
  670. delete pSrc;
  671. return;
  672. }
  673. //if (status) /*接收包正确*/
  674.     //{
  675. for(int i=1;i<=pSnmp.nCount;i++)
  676. {  
  677. switch(m_value[i]->syntax)
  678. {
  679. case SNMP_SYNTAX_INT: 
  680. // case SNMP_SYNTAX_INT32:
  681. smiINT sNumber;
  682. sNumber=m_value[i]->value.sNumber;
  683. nIpin=sNumber;
  684. wsprintf(str[i],"%d",sNumber);
  685. break;
  686. case SNMP_SYNTAX_UINT32:
  687. case SNMP_SYNTAX_CNTR32:
  688. case SNMP_SYNTAX_GAUGE32: 
  689. case SNMP_SYNTAX_TIMETICKS:
  690. smiUINT32 uNumber;
  691. uNumber=m_value[i]->value.uNumber;
  692. nIpin=uNumber;
  693. wsprintf(str[i],"%d",uNumber);
  694. break;
  695. case SNMP_SYNTAX_CNTR64:
  696. smiCNTR64 hNumber;
  697. hNumber=m_value[i]->value.hNumber;
  698. break;
  699. case SNMP_SYNTAX_OCTETS:
  700. str[i]=(char *)m_value[i]->value.string.ptr;
  701. break;
  702. case SNMP_SYNTAX_OPAQUE: 
  703. case SNMP_SYNTAX_NSAPADDR:
  704. str[i]=(char *)m_value[i]->value.string.ptr;
  705. break;
  706. case SNMP_SYNTAX_IPADDR:
  707. strIp.Format("%d",*m_value[i]->value.string.ptr);
  708. strIp+=".";
  709. strTemp.Format("%d",*(m_value[i]->value.string.ptr+1));
  710. strIp+=strTemp;
  711. strIp+=".";
  712. strTemp.Format("%d",*(m_value[i]->value.string.ptr+2));
  713. strIp+=strTemp;
  714. strIp+=".";
  715. strTemp.Format("%d",*(m_value[i]->value.string.ptr+3));
  716. strIp+=strTemp;
  717. strcpy(str[i],strIp);
  718. break;
  719. case SNMP_SYNTAX_OID:
  720. smiOID oid;
  721. oid=m_value[i]->value.oid;
  722. SnmpOidToStr(&oid,30,str[i]);
  723. //SnmpFreeDescriptor (SNMP_SYNTAX_OID, (smiLPOPAQUE)&oid);
  724. break;
  725. case SNMP_SYNTAX_NULL: 
  726. case SNMP_SYNTAX_NOSUCHOBJECT:
  727. case SNMP_SYNTAX_NOSUCHINSTANCE: 
  728. case SNMP_SYNTAX_ENDOFMIBVIEW:
  729. smiBYTE empty;
  730. empty=m_value[i]->value.empty;
  731. str[i]="No such name,please check!";
  732. break;
  733. default:
  734. break;
  735. }
  736. CString temp,temp1;
  737. CString str2;
  738. char* pBoard=new char[4];
  739. CString pTemp;
  740. if (flag!=5)
  741. m_wndAddress.GetWindowText(str2);
  742. temp1=  CString(m_sOid[i]);
  743. if (SelfFlag) /*表明是设备操作*/
  744. {
  745. this->m_wndReportBar.WriteReportLine("接收命令---getresponse", output);
  746. this->m_wndReportBar.WriteReportLine("from------", output);
  747. this->m_wndReportBar.WriteReportLine(pSrc,0);   
  748. this->m_wndReportBar.WriteReportLine("oid值", output);
  749. this->m_wndReportBar.WriteReportLine(CString(m_sOid[i]), output);
  750. int type;
  751. unsigned int short mask=0x8000;
  752.                if(flag==5)/*表明是刷新操作*/
  753.    {
  754.    type=4-i;
  755.    }
  756.    else
  757.    {
  758. if(str2.Right(1) == _T("1") )
  759. type=1;
  760. else if(str2.Right(1) == _T("2") )
  761. type=2;
  762. else if(str2.Right(1) == _T("3") )
  763. type=3;/*在位否*/
  764. else
  765. type=5;/*其他*/
  766.    }
  767. if (type<4 )
  768. {
  769. if (type==3) this->m_wndReportBar.WriteReportLine("当前在位的板位",0);
  770. for(int board=0;board<16;board++)
  771. {
  772. test[board][type]=(mask & nIpin)?1:0;
  773. mask>>=1;
  774. if(type==3)
  775. {
  776.            
  777. if(!test[board][type])
  778. {
  779. wsprintf(pBoard,"%d",board);
  780. pTemp=_T("板位----") + CString(pBoard);
  781. this->m_wndReportBar.WriteReportLine(pTemp,0);   
  782. }
  783. }
  784. else
  785. {
  786. if(!test[board][3]) /*表示在位*/
  787. {
  788. wsprintf(pBoard,"%d",board);
  789. pTemp=_T("板位") + CString(pBoard);
  790. // this->m_wndReportBar.WriteReportLine(pTemp,0);   
  791. if(type==2)
  792. {
  793. if(!test[board][type])
  794. this->m_wndReportBar.WriteReportLine(pTemp+"---容量10M",0);   
  795. else
  796. this->m_wndReportBar.WriteReportLine(pTemp+"---容量100M",0);   
  797. }
  798. if(type==1)/*连接状况*/
  799. {
  800. if(!test[board][type])
  801. this->m_wndReportBar.WriteReportLine(pTemp+"---连接正常",0);   
  802. else
  803. this->m_wndReportBar.WriteReportLine(pTemp+"---连接非正常",0);   
  804. }
  805. }
  806. }
  807. }
  808. }
  809. }
  810. if (flag==1)
  811. {
  812. this->m_wndReportBar.WriteReportLine("*******************", output);
  813. this->m_wndReportBar.WriteReportLine("接收命令---getresponse", output);
  814. this->m_wndReportBar.WriteReportLine("from------", output);
  815. this->m_wndReportBar.WriteReportLine(pSrc,0);
  816. this->m_wndReportBar.WriteReportLine("oid值", output);
  817. this->m_wndReportBar.WriteReportLine(CString(m_sOid[i]), output);
  818. this->m_wndReportBar.WriteReportLine("命令值", output);
  819. this->m_wndReportBar.WriteReportLine(CString(str[i]), output);
  820. }      
  821. if (flag==2)
  822. {
  823. m_wndAddress.SetWindowText(CString(m_sOid[i]));
  824. this->m_wndReportBar.WriteReportLine("*******************", output);
  825. this->m_wndReportBar.WriteReportLine("接收命令--getNextresponse", output);
  826. this->m_wndReportBar.WriteReportLine("from------", output);
  827.                 this->m_wndReportBar.WriteReportLine(pSrc,0);   
  828. this->m_wndReportBar.WriteReportLine("oid值", output);
  829. this->m_wndReportBar.WriteReportLine(CString(m_sOid[i]), output);
  830. this->m_wndReportBar.WriteReportLine("命令值", output);
  831. this->m_wndReportBar.WriteReportLine(CString(str[i]), output);
  832. this->m_wndReportBar.WriteReportLine("*******************", output);
  833. }
  834. if (flag==3)
  835. {
  836. m_wndAddress.SetWindowText(CString(m_sOid[i]));
  837. this->m_wndReportBar.WriteReportLine("*******************", output);
  838. this->m_wndReportBar.WriteReportLine("接收命令--getbulkponse", output);
  839. this->m_wndReportBar.WriteReportLine("from------", output);
  840.                 this->m_wndReportBar.WriteReportLine(pSrc,0);   
  841. this->m_wndReportBar.WriteReportLine("oid值", output);
  842. this->m_wndReportBar.WriteReportLine(CString(m_sOid[i]), output);
  843. this->m_wndReportBar.WriteReportLine("命令值", output);
  844. this->m_wndReportBar.WriteReportLine(CString(str[i]), output);
  845. this->m_wndReportBar.WriteReportLine("*******************", output);
  846. }
  847. if (flag==4)
  848. {
  849. m_wndAddress.SetWindowText(CString(m_sOid[i]));
  850. this->m_wndReportBar.WriteReportLine("*******************", output);
  851. this->m_wndReportBar.WriteReportLine("接收命令--getSetResponse", output);
  852. this->m_wndReportBar.WriteReportLine("from------", output);
  853.                 this->m_wndReportBar.WriteReportLine(pSrc,0);   
  854. this->m_wndReportBar.WriteReportLine("oid值", output);
  855. this->m_wndReportBar.WriteReportLine(CString(m_sOid[i]), output);
  856. this->m_wndReportBar.WriteReportLine("命令值", output);
  857. this->m_wndReportBar.WriteReportLine(CString(str[i]), output);
  858. this->m_wndReportBar.WriteReportLine("*******************", output);
  859. }
  860. }
  861. delete PDU_type;
  862. // if (flag==1)
  863. // Next(m_sOid[1]);
  864. //}
  865. }
  866. void CMainFrame::Start(int flag1)
  867. {  
  868. CString str;
  869. SelfFlag=0;
  870. if(flag1 !=4) /*表明是SET操作,VARLIST已经添好了*/
  871. {
  872. if(pSnmp.sessionID==FALSE)
  873. {
  874. pSnmp.CreateSession(CMainFrame::m_hWnd,wMsg);
  875. pSnmp.sessionID=TRUE;
  876. }
  877. pSnmp.Register();
  878. if (flag1==5) /*表明是刷新操作*/
  879. {
  880. flag=5;
  881. SelfFlag=1;
  882. str="1.3.6.1.4.1.26.5.1.5.1.3.0";
  883. pSnmp.CreateVbl(str,NULL);
  884. str="1.3.6.1.4.1.26.5.1.5.1.1.0";
  885. pSnmp.SetVbl(str,NULL);
  886. str="1.3.6.1.4.1.26.5.1.5.1.2.0";
  887. pSnmp.SetVbl(str,NULL);
  888. }
  889. else
  890. {
  891. m_wndAddress.GetWindowText(str);
  892. str=str+_T(".") + "0";
  893. pSnmp.CreateVbl(str,NULL);
  894. }
  895. }  
  896. switch (flag1)
  897. {
  898. case 1:
  899.         case 5: /*刷新命令*/
  900. pSnmp.CreatePdu(SNMP_PDU_GET,NULL,NULL,NULL);
  901. break;
  902. case 2:
  903. pSnmp.CreatePdu(SNMP_PDU_GETNEXT,NULL,NULL,NULL);  
  904. break;
  905. case 3:
  906. pSnmp.CreatePdu(SNMP_PDU_GETBULK,NULL,1,3);  
  907. break;
  908. case 4:
  909. pSnmp.CreatePdu(SNMP_PDU_SET,NULL,NULL,NULL);  
  910. break;
  911. default:
  912. break;
  913. }
  914.    pSnmp.Send(m_agent,m_community);
  915. this->m_wndReportBar.WriteReportLine("*******************", 0);
  916. this->m_wndReportBar.WriteReportLine("发送命令", 0);
  917. this->m_wndReportBar.WriteReportLine("*******************", 0);
  918.     this->m_wndReportBar.WriteReportLine("当前管理代理设备ip", 0);
  919.     this->m_wndReportBar.WriteReportLine(m_agent, 0);
  920. this->m_wndReportBar.WriteReportLine("当前管理社区标志", 0);
  921.     this->m_wndReportBar.WriteReportLine(m_community, 0);
  922. }
  923. void CMainFrame::OnAddnode() 
  924. {
  925. }
  926. void CMainFrame::Next(LPTSTR Oid)
  927. {
  928. CString str(Oid);
  929. static i=0;
  930. //AfxMessageBox(str.Left(20));
  931. CString str1;
  932. m_wndAddress.GetWindowText(str1);
  933.    
  934. if(!strcmp(str.Left(19),str1))
  935. {
  936. m_OidNext[i]=new char[50];
  937. m_valueNext[i]=new char[50];
  938. strcpy(m_OidNext[i],m_sOid[1]);
  939. strcpy(m_valueNext[i],CMainFrame::str[1]);
  940.         //AfxMessageBox(CMainFrame::str[1]);
  941. //AfxMessageBox(m_sOid[1]);
  942. //*(m_valueNext+i)=CSnmpManagerDlg::str[1];
  943. pSnmp.CreateVbl(Oid,NULL);
  944. pSnmp.CreatePdu(SNMP_PDU_GETNEXT,NULL,NULL,NULL);
  945. pSnmp.Send(m_agent,m_community);
  946. i++;
  947. }
  948. else 
  949. {
  950. /* m_bNext=FALSE;
  951. CDlgPrint pDlg;
  952. for(int j=0;j<i;j++)
  953. {
  954. delete[50] m_OidNext[i];
  955. delete[50] m_valueNext[i];
  956. }
  957. pDlg.m_Oid=m_OidNext;
  958. pDlg.m_value=m_valueNext;
  959. pDlg.n=i;
  960. pDlg.DoModal();*/
  961. /* for(int i=0;i<2;i++)
  962. {
  963. this->w_wndReportBar.WriteReportLine("*******************", 0);
  964. this->m_wndReportBard.WriteReportLine("命令值", 0);
  965. this->m_wndReportBar.WriteReportLine(CString(*(m_Oid+i)), 0);
  966. this->m_wndReportBar.WriteReportLine(CString(*(m_value+i)), 0);
  967. }
  968. */
  969. }
  970. }
  971. void CMainFrame::OnUser() 
  972. {
  973.   CUserManagement dlg;
  974.   dlg.DoModal();
  975. }
  976. void CMainFrame::OnUpdateActionGet(CCmdUI* pCmdUI) 
  977. {
  978. // TODO: Add your command update UI handler code here
  979. pCmdUI->Enable(m_power);
  980. }
  981. void CMainFrame::OnUpdateActionGetnext(CCmdUI* pCmdUI) 
  982. {
  983. // TODO: Add your command update UI handler code here
  984. pCmdUI->Enable(m_power);
  985. }
  986. void CMainFrame::OnUpdateActionSet(CCmdUI* pCmdUI) 
  987. {
  988. // TODO: Add your command update UI handler code here
  989. pCmdUI->Enable(m_power);
  990. }
  991. void CMainFrame::OnUpdateUser(CCmdUI* pCmdUI) 
  992. {
  993. // TODO: Add your command update UI handler code here
  994. pCmdUI->Enable(m_power);
  995. }