MAINFRM.CPP
上传用户:lvjun8202
上传日期:2013-04-30
资源大小:797k
文件大小:32k
- // MainFrm.cpp : implementation of the CMainFrame class
- //
- #include "stdafx.h"
- #include "OAM.h"
- #include "MainFrm.h"
- #include "OAMDoc.h"
- #include "Splash.h"
- #include "Agent.h"
- #include "snmp1.h"
- #include "MainView.h"
- #include "usermanagement.h"
- #include "GlobalVariable.h"
- #include "string.h"
- #include "DlgSet.h"
- #ifdef _DEBUG
- #define new DEBUG_NEW
- #undef THIS_FILE
- static char THIS_FILE[] = __FILE__;
- #endif
- /////////////////////////////////////////////////////////////////////////////
- // CMainFrame
-
- IMPLEMENT_DYNCREATE(CMainFrame, CFrameWnd)
- BEGIN_MESSAGE_MAP(CMainFrame, CFrameWnd)
- ON_WM_INITMENUPOPUP()
- ON_WM_MENUSELECT()
- ON_UPDATE_COMMAND_UI(ID_INDICATOR_DATE, OnUpdateDate)
- ON_UPDATE_COMMAND_UI(ID_INDICATOR_TIME, OnUpdateTime)
- //{{AFX_MSG_MAP(CMainFrame)
- ON_WM_CREATE()
- ON_WM_TIMER()
- ON_WM_CLOSE()
- ON_WM_INITMENU()
- ON_COMMAND(ID_NOT_REPORT, OnNotReport)
- ON_UPDATE_COMMAND_UI(ID_NOT_REPORT, OnUpdateNotReport)
- ON_COMMAND(ID_SETAGENT, OnSetagent)
- ON_COMMAND(ID_ACTION_GET, OnActionGet)
- ON_COMMAND(ID_ACTION_GETBULK, OnActionGetbulk)
- ON_COMMAND(ID_ACTION_GETNEXT, OnActionGetnext)
- ON_COMMAND(ID_ACTION_SET, OnActionSet)
- ON_MESSAGE(wMsg,OnRecv)
- ON_COMMAND(ID_USER, OnUser)
- ON_UPDATE_COMMAND_UI(ID_ACTION_GET, OnUpdateActionGet)
- ON_UPDATE_COMMAND_UI(ID_ACTION_GETNEXT, OnUpdateActionGetnext)
- ON_UPDATE_COMMAND_UI(ID_ACTION_SET, OnUpdateActionSet)
- ON_UPDATE_COMMAND_UI(ID_USER, OnUpdateUser)
- //}}AFX_MSG_MAP
- // Global help commands
- ON_CBN_SELENDOK(ID_VIEW_ADDRESS,OnNewAddress)
- ON_COMMAND(IDOK, OnNewAddressEnter)
- ON_COMMAND_EX(ID_VIEW_ADDRESS, OnBarCheck)
- ON_UPDATE_COMMAND_UI(ID_VIEW_ADDRESS, OnUpdateControlBarMenu)
- ON_COMMAND_EX(ID_VIEW_WORKSPACE, OnBarCheck)
- ON_UPDATE_COMMAND_UI(ID_VIEW_WORKSPACE, OnUpdateControlBarMenu)
- ON_COMMAND_EX(ID_VIEW_PROMPT, OnBarCheck)
- ON_UPDATE_COMMAND_UI(ID_VIEW_PROMPT, OnUpdateControlBarMenu)
- ON_COMMAND_EX(ID_VIEW_OUTPUT, OnBarCheck)
- ON_UPDATE_COMMAND_UI(ID_VIEW_OUTPUT, OnUpdateControlBarMenu)
- ON_COMMAND(ID_HELP_FINDER, CFrameWnd::OnHelpFinder)
- ON_COMMAND(ID_HELP, CFrameWnd::OnHelp)
- ON_COMMAND(ID_CONTEXT_HELP, CFrameWnd::OnContextHelp)
- ON_COMMAND(ID_DEFAULT_HELP, CFrameWnd::OnHelpFinder)
- ON_NOTIFY(TBN_DROPDOWN, AFX_IDW_TOOLBAR, OnDropDown)
- END_MESSAGE_MAP()
- static UINT indicators[] =
- {
- ID_SEPARATOR, // status line indicator
- ID_INDICATOR_CAPS,
- ID_INDICATOR_NUM,
- ID_INDICATOR_SCRL,
- };
- /////////////////////////////////////////////////////////////////////////////
- // CMainFrame construction/destruction
- CMainFrame::CMainFrame()
- {
- m_nStatusPane1Width = -1;
- m_bMenuSelect = FALSE;
- NoReport=FALSE;
- int i;
- SelfFlag=0;
- for(i=0;i<=9;i++ )
- {
- m_value[i]=new smiVALUE[100];
- m_sOid[i]=new char[100];
- str[i]=new char[100];
- }
- CGlobalVariable::m_pMainFrame=this;
- for(int k=0;k<=16;k++)
- for (int j=0;j<=3;j++)
- test[k][j]=0;
-
- }
- CMainFrame::~CMainFrame()
- {
- /* int nCount = m_arrRecentView.GetSize();
-
- for (int i = 0; i < nCount; i++)
- delete m_arrRecentView.GetAt(i);
- m_arrRecentView.RemoveAll();*/
- }
- int CMainFrame::OnCreate(LPCREATESTRUCT lpCreateStruct)
- {
- if (CFrameWnd::OnCreate(lpCreateStruct) == -1)
- return -1;
- // CSplashWnd::ShowSplashScreen(this);
-
- CGlobalVariable::Init();
- if(!CreateToolBar())
- {
- return -1;
- }
- if (!m_wndStatusBar.Create(this) ||
- !m_wndStatusBar.SetIndicators(indicators,
- sizeof(indicators)/sizeof(UINT)))
- {
- TRACE0("Failed to create status barn");
- return -1; // fail to create
- }
- SetInitialSize(50,100,200,100);
-
- if (!m_wndReportBar.Create(this, ID_VIEW_OUTPUT,
- _T("操作报告"), CSize(300,100), CBRS_BOTTOM))
- {
- TRACE0("Failed to create dialog bar m_wndReportListBarn");
- return -1; // fail to create
- }
- if (!m_wndWorkspace.Create(this, ID_VIEW_WORKSPACE,
- _T("工作区"), CSize(300,100), CBRS_LEFT))
- {
- TRACE0("Failed to create dialog bar m_wndWorkspacen");
- return -1; // fail to create
- }
- m_wndWorkspace.EnableDockingOnSizeBar(CBRS_ALIGN_ANY);
- m_wndReportBar.EnableDockingOnSizeBar(CBRS_BOTTOM | CBRS_LEFT| CBRS_RIGHT);
- EnableDockingSizeBar(CBRS_ALIGN_ANY);
- DockSizeBar(&m_wndWorkspace) ;
- DockSizeBar(&m_wndReportBar);
- m_3DManager.Install(this); /*显示漂亮的动态*/
- _pMainFrame = this;
- int nOrigSize = sizeof(indicators) / sizeof(UINT);
- UINT* pIndicators = new UINT[nOrigSize + 2];
- memcpy(pIndicators, indicators, sizeof(indicators));
- // Call the Status Bar Component's status bar creation function
- if (!InitStatusBar(pIndicators, nOrigSize, 60))
- {
- TRACE0("Failed to initialize Status Barn");
- return -1;
- }
- delete[] pIndicators;
- return 0;
- }
- BOOL CMainFrame::PreCreateWindow(CREATESTRUCT& cs)
- {
- if( !CFrameWnd::PreCreateWindow(cs) )
- return FALSE;
- // TODO: Modify the Window class or styles here by modifying
- // the CREATESTRUCT cs
- cs.style = WS_OVERLAPPED | WS_CAPTION// | FWS_ADDTOTITLE
- | WS_THICKFRAME | WS_SYSMENU | WS_MINIMIZEBOX | WS_MAXIMIZEBOX | WS_MAXIMIZE;
- cs.cx = 800;
- cs.cy = 600;
- return TRUE;
- }
- /////////////////////////////////////////////////////////////////////////////
- // CMainFrame diagnostics
- #ifdef _DEBUG
- void CMainFrame::AssertValid() const
- {
- CFrameWnd::AssertValid();
- }
- void CMainFrame::Dump(CDumpContext& dc) const
- {
- CFrameWnd::Dump(dc);
- }
- #endif //_DEBUG
- /////////////////////////////////////////////////////////////////////////////
- // CMainFrame message handlers
- BOOL CMainFrame::CreateToolBar()
- {
- if (!m_wndToolBar.CreateEx(this))
- {
- TRACE0("Failed to create toolbarn");
- return FALSE; // fail to create
- }
- m_wndToolBar.ModifyStyle(0,TBSTYLE_CUSTOMERASE);
- if (!m_wndMenuBar.CreateEx(this)||(m_wndMenuBar.SetOwner(this),m_wndMenuBar.LoadMenu(IDR_MAINFRAME)))
- {
-
- TRACE0("Failed to create menu barn");
- return FALSE; // fail to create
- }
- m_wndMenuBar.ModifyStyle(0, TBSTYLE_TRANSPARENT|TBSTYLE_FLAT|TBSTYLE_CUSTOMERASE );
- if (!m_wndReBar.Create(this))
- {
- TRACE0("Failed to create rebarn");
- return FALSE; // fail to create
- }
- // m_wndReBar.GetReBarCtrl().ModifyStyle(RBS_BANDBORDERS ,0);
- CString str;
- CImageList imageList;
- HBITMAP hBitmap;
- BITMAP bm;
- CBitmap * pBitmap;
- hBitmap = (HBITMAP)LoadImage(AfxGetInstanceHandle(),"toolbar1.bmp",
- IMAGE_BITMAP,0,0,LR_LOADFROMFILE|LR_CREATEDIBSECTION);
- if(hBitmap == NULL)
- return FALSE;
- pBitmap = CBitmap::FromHandle(hBitmap);
- GetObject(hBitmap,sizeof(BITMAP),&bm);
- if(imageList.Create(bm.bmWidth/8, bm.bmHeight, ILC_COLORDDB|ILC_MASK, 8, 1)
- && imageList.Add(pBitmap, RGB(255,0,255)) != -1)
- {
- }
- m_wndToolBar.GetToolBarCtrl().SetHotImageList(&imageList);
- imageList.Detach();
- ::DeleteObject(hBitmap);
- // Create and set the normal toolbar image list.
- hBitmap = (HBITMAP)LoadImage(AfxGetInstanceHandle(),"toolbar1.bmp",
- IMAGE_BITMAP,0,0,LR_LOADFROMFILE|LR_CREATEDIBSECTION);
- if(hBitmap == NULL)
- return FALSE;
- pBitmap = CBitmap::FromHandle(hBitmap);
- GetObject(hBitmap,sizeof(BITMAP),&bm);
- if(imageList.Create(bm.bmWidth/8, bm.bmHeight, ILC_COLORDDB|ILC_MASK, 8, 1)
- && imageList.Add(pBitmap, RGB(255,0,255)) != -1)
- {
- }
- m_wndToolBar.GetToolBarCtrl().SetImageList(&imageList);
- imageList.Detach();
- ::DeleteObject(hBitmap);
- // Create and set the disabled toolbar image list.
- hBitmap = (HBITMAP)LoadImage(AfxGetInstanceHandle(),"toolbar1.bmp",
- IMAGE_BITMAP,0,0,LR_LOADFROMFILE|LR_CREATEDIBSECTION);
- if(hBitmap == NULL)
- return FALSE;
- pBitmap = CBitmap::FromHandle(hBitmap);
- GetObject(hBitmap,sizeof(BITMAP),&bm);
- if(imageList.Create(bm.bmWidth/8, bm.bmHeight, ILC_COLORDDB|ILC_MASK, 8, 1)
- && imageList.Add(pBitmap, RGB(255,0,255)) != -1)
- {
- }
- m_wndToolBar.GetToolBarCtrl().SetDisabledImageList(&imageList);
- imageList.Detach();
- ::DeleteObject(hBitmap);
-
- m_wndToolBar.ModifyStyle(0, TBSTYLE_FLAT | TBSTYLE_TRANSPARENT);
- m_wndToolBar.SetButtons(NULL, 5);
-
- // set up each toolbar button
- m_wndToolBar.SetButtonInfo(0, ID_ACTION_GET, TBSTYLE_BUTTON, 0);
- m_wndToolBar.SetButtonText(0, "取属性值");
- m_wndToolBar.SetButtonInfo(1, ID_ACTION_GETNEXT, TBSTYLE_BUTTON, 1);
- m_wndToolBar.SetButtonText(1, "取下一个属性值");
- m_wndToolBar.SetButtonInfo(2, ID_ACTION_SET, TBSTYLE_BUTTON, 2);
- m_wndToolBar.SetButtonText(2, "设置属性值");
- m_wndToolBar.SetButtonInfo(3, ID_USER, TBSTYLE_BUTTON, 3);
- m_wndToolBar.SetButtonText(3, "用户管理");
- m_wndToolBar.SetButtonInfo(4, ID_SETAGENT, TBSTYLE_BUTTON, 4);
- m_wndToolBar.SetButtonText(4, "设置代理");
-
- CRect rectToolBar;
- // set up toolbar button sizes
- m_wndToolBar.GetItemRect(0, &rectToolBar);
- m_wndToolBar.GetToolBarCtrl().SetButtonWidth(50, 150);
- m_wndToolBar.GetToolBarCtrl().SetExtendedStyle(TBSTYLE_EX_DRAWDDARROWS);
- // m_wndToolBar.SetSizes(rectToolBar.Size(), CSize(30,20));
- // create a combo box for the address bar
- if (!m_wndAddress.Create(CBS_DROPDOWN | WS_CHILD, CRect(0, 0, 200, 120), this, ID_VIEW_ADDRESS))
- {
- TRACE0("Failed to create comboboxn");
- return -1; // fail to create
- }
- m_wndAddress.SetFont(&m_fontSys);
- CGlobalVariable::m_pAddressCombo = &m_wndAddress;
- // create the animation control
- m_wndAnimate.Create(WS_CHILD | WS_VISIBLE, CRect(0, 0, 10, 10), this, AFX_IDW_TOOLBAR + 2);
- m_wndAnimate.Open(IDR_VC6);
- m_wndAnimate.Play(0,-1,-1);
- // add the toolbar, animation, and address bar to the rebar
- m_wndReBar.AddBar(&m_wndMenuBar, NULL, NULL, RBBS_FIXEDSIZE | RBBS_FIXEDBMP);
- m_wndReBar.AddBar(&m_wndAnimate, NULL, NULL, RBBS_FIXEDSIZE | RBBS_FIXEDBMP);
- m_wndReBar.AddBar(&m_wndToolBar, "", NULL, RBBS_FIXEDBMP | RBBS_BREAK);
- str = _T("所选oid");
- m_wndReBar.AddBar(&m_wndAddress, str, NULL, RBBS_FIXEDBMP | RBBS_BREAK);
- CRect rcMenuBar;
- m_wndMenuBar.GetItemRect(0, &rcMenuBar);
- // set up min/max sizes and ideal sizes for pieces of the rebar
- REBARBANDINFO rbbi;
- rbbi.cbSize = sizeof(rbbi);
- rbbi.fMask = RBBIM_CHILDSIZE | RBBIM_IDEALSIZE | RBBIM_SIZE;// | RBBIM_STYLE;
- // rbbi.fStyle = RBBS_NOGRIPPER;
- rbbi.cxMinChild = rcMenuBar.Width();
- rbbi.cyMinChild = rcMenuBar.Height();
- rbbi.cx = rbbi.cxIdeal = rcMenuBar.Width() * m_wndMenuBar.GetToolBarCtrl().GetButtonCount();
- m_wndReBar.GetReBarCtrl().SetBandInfo(0, &rbbi);
- rbbi.cxMinChild = 0;
- rbbi.fMask = RBBIM_CHILDSIZE | RBBIM_IDEALSIZE | RBBIM_SIZE ;
- rbbi.cxMinChild = rectToolBar.Width();
- rbbi.cyMinChild = rectToolBar.Height();
- rbbi.cx = rbbi.cxIdeal = rectToolBar.Width() * 9;
- m_wndReBar.GetReBarCtrl().SetBandInfo(2, &rbbi);
- rbbi.cxMinChild = 0;
- return TRUE;
- }
- void CMainFrame::OnTimer(UINT nIDEvent)
- {
- // TODO: Add your message handler code here and/or call default
- // if((nIDEvent == 98 || nIDEvent == 99 )&& _pMainDoc)
- //if(nIDEvent == 99 && _pMainDoc)
- // _pMainDoc->OnTimer(nIDEvent);
- CFrameWnd::OnTimer(nIDEvent);
- this->m_wndReportBar.WriteReportLine("+++++++++++++timer+++++++",0);
- }
- void CMainFrame::OnNewAddress()
- {
- // gets called when an item in the Address combo box is selected
- // just navigate to the newly selected location.
- CString str;
- m_wndAddress.GetLBText(m_wndAddress.GetCurSel(), str);
- if(CGlobalVariable::m_pStationTreeView)
- 1==1;
- // CGlobalVariable::m_pStationTreeView->SelectAdress(str);
- // ((CMfcieView*)GetActiveView())->Navigate2(str, 0, NULL);
- }
- void CMainFrame::OnNewAddressEnter()
- {
- // gets called when an item is entered manually into the edit box portion
- // of the Address combo box.
- // navigate to the newly selected location and also add this address to the
- // list of addresses in the combo box.
- CString str;
- m_wndAddress.GetWindowText(str);
- // m_wndAddress.GetLBText(m_wndAddress.GetCurSel(), str);
- // m_wndAddress.GetEditCtrl()->GetWindowText(str);
- // ((CMfcieView*)GetActiveView())->Navigate2(str, 0, NULL);
- m_wndAddress.AddNewAdress(str);
- /* if(CGlobalVariable::m_pStationTreeView)
- CGlobalVariable::m_pStationTreeView->SelectAdress(str);*/
- }
- BOOL CMainFrame::PreTranslateMessage(MSG* pMsg)
- {
- // TODO: Add your specialized code here and/or call the base class
-
- return m_wndMenuBar.TranslateFrameMessage(pMsg) ?
- TRUE : CFrameWnd::PreTranslateMessage(pMsg);
- // return CFrameWnd::PreTranslateMessage(pMsg);
- }
- void CMainFrame::OnDropDown(NMHDR *pNotifyStruct, LRESULT *pResult)
- {
- // this function handles the dropdown menus from the toolbar
- /* NMTOOLBAR* pNMToolBar = (NMTOOLBAR*)pNotifyStruct;
- CRect rect;
- // translate the current toolbar item rectangle into screen coordinates
- // so that we'll know where to pop up the menu
- m_wndToolBar.GetToolBarCtrl().GetRect(pNMToolBar->iItem, &rect);
- rect.top = rect.bottom;
- ::ClientToScreen(pNMToolBar->hdr.hwndFrom, &rect.TopLeft());
- if(pNMToolBar->iItem == ID_BACK || pNMToolBar->iItem == ID_FORWARD)
- {
- CMenu menu;
- menu.CreatePopupMenu();
- while(m_astrCurrentURLs.GetSize()>0)
- m_astrCurrentURLs.RemoveAt(0);
- int nHist;
- if(pNMToolBar->iItem == ID_BACK)
- nHist = m_nCurrentPosition-1;
- else
- nHist = m_nCurrentPosition+1;
- CString str;
- int nPos = 0;
- while(nHist>=0 && nHist<m_arrRecentView.GetSize())
- {
- CViewMgrItem * pMgrItem = m_arrRecentView.GetAt(nHist);
- if(pMgrItem)
- {
- if(pMgrItem->m_nView == ID_MAIN_VIEW)
- str = _T("主屏");
- else if(pMgrItem->m_nView == ID_STATISTICS_VIEW)
- str = _T("统计");
- else //if(pMgrItem->m_pCompenentFormer)
- str = pMgrItem->m_strName;
- menu.AppendMenu(MF_STRING, 0x1e00+nPos, str);
- m_astrCurrentURLs.InsertAt(nPos,str);
- nPos++;
- }
- if(pNMToolBar->iItem == ID_BACK)
- nHist--;
- else
- nHist++;
- }
- menu.TrackPopupMenu(TPM_LEFTALIGN|TPM_RIGHTBUTTON, rect.left, rect.top + 1, this);
- menu.DestroyMenu();
- }
- *pResult = TBDDRET_DEFAULT;*/
- }
- void CMainFrame::OnClose()
- {
- // TODO: Add your message handler code here and/or call default
-
- //SaveBarState(_T("HJD04EBar"));
- if(MessageBox("确实要退出吗?","友情提醒!",MB_ICONQUESTION|MB_OKCANCEL) == IDOK)
- {
- CFrameWnd::OnClose();
- }
- }
- void CMainFrame::OnMenuSelect(UINT nItemID, UINT nFlags, HMENU hSysMenu)
- {
- CFrameWnd::OnMenuSelect(nItemID, nFlags, hSysMenu);
-
- // CG: The following block was inserted by 'Status Bar' component.
- {
- // Restore first pane of the statusbar?
- if (nFlags == 0xFFFF && hSysMenu == 0 && m_nStatusPane1Width != -1)
- {
- m_bMenuSelect = FALSE;
- m_wndStatusBar.SetPaneInfo(0,
- m_nStatusPane1ID, m_nStatusPane1Style, m_nStatusPane1Width);
- m_nStatusPane1Width = -1; // Set it to illegal value
- }
- else
- {
- m_bMenuSelect = TRUE;
- }
- }
- }
- void CMainFrame::OnInitMenuPopup(CMenu* pPopupMenu, UINT nIndex, BOOL bSysMenu)
- {
- CFrameWnd::OnInitMenuPopup(pPopupMenu, nIndex, bSysMenu);
-
- // CG: The following block was inserted by 'Status Bar' component.
- {
- // store width of first pane and its style
- if (m_nStatusPane1Width == -1 && m_bMenuSelect)
- {
- m_wndStatusBar.GetPaneInfo(0, m_nStatusPane1ID,
- m_nStatusPane1Style, m_nStatusPane1Width);
- m_wndStatusBar.SetPaneInfo(0, m_nStatusPane1ID,
- SBPS_NOBORDERS|SBPS_STRETCH, 16384);
- }
- }
- }
- void CMainFrame::OnUpdateDate(CCmdUI* pCmdUI)
- {
- // CG: This function was inserted by 'Status Bar' component.
- // Get current date and format it
- CTime time = CTime::GetCurrentTime();
- CString strDate = time.Format(_T("%x"));
- // BLOCK: compute the width of the date string
- CSize size;
- {
- HGDIOBJ hOldFont = NULL;
- HFONT hFont = (HFONT)m_wndStatusBar.SendMessage(WM_GETFONT);
- CClientDC dc(NULL);
- if (hFont != NULL)
- hOldFont = dc.SelectObject(hFont);
- size = dc.GetTextExtent(strDate);
- if (hOldFont != NULL)
- dc.SelectObject(hOldFont);
- }
- // Update the pane to reflect the current date
- UINT nID, nStyle;
- int nWidth;
- m_wndStatusBar.GetPaneInfo(m_nDatePaneNo, nID, nStyle, nWidth);
- m_wndStatusBar.SetPaneInfo(m_nDatePaneNo, nID, nStyle, size.cx);
- pCmdUI->SetText(strDate);
- pCmdUI->Enable(TRUE);
- }
- void CMainFrame::OnUpdateTime(CCmdUI* pCmdUI)
- {
- // CG: This function was inserted by 'Status Bar' component.
- // Get current date and format it
- CTime time = CTime::GetCurrentTime();
- CString strTime = time.Format(_T("%X"));
- // BLOCK: compute the width of the date string
- CSize size;
- {
- HGDIOBJ hOldFont = NULL;
- HFONT hFont = (HFONT)m_wndStatusBar.SendMessage(WM_GETFONT);
- CClientDC dc(NULL);
- if (hFont != NULL)
- hOldFont = dc.SelectObject(hFont);
- size = dc.GetTextExtent(strTime);
- if (hOldFont != NULL)
- dc.SelectObject(hOldFont);
- }
- // Update the pane to reflect the current time
- UINT nID, nStyle;
- int nWidth;
- m_wndStatusBar.GetPaneInfo(m_nTimePaneNo, nID, nStyle, nWidth);
- m_wndStatusBar.SetPaneInfo(m_nTimePaneNo, nID, nStyle, size.cx);
- pCmdUI->SetText(strTime);
- pCmdUI->Enable(TRUE);
- }
- BOOL CMainFrame::InitStatusBar(UINT *pIndicators, int nSize, int nSeconds)
- {
- // CG: This function was inserted by 'Status Bar' component.
- // Create an index for the DATE pane
- m_nDatePaneNo = nSize++;
- pIndicators[m_nDatePaneNo] = ID_INDICATOR_DATE;
- // Create an index for the TIME pane
- m_nTimePaneNo = nSize++;
- nSeconds = 1;
- pIndicators[m_nTimePaneNo] = ID_INDICATOR_TIME;
- // TODO: Select an appropriate time interval for updating
- // the status bar when idling.
- m_wndStatusBar.SetTimer(0x1000, nSeconds * 1000, NULL);
- return m_wndStatusBar.SetIndicators(pIndicators, nSize);
- }
- void CMainFrame::OnInitMenu(CMenu* pMenu)
- {
- CFrameWnd::OnInitMenu(pMenu);
-
- // CG: This block added by 'Tip of the Day' component.
- /* {
- // TODO: This code adds the "Tip of the Day" menu item
- // on the fly. It may be removed after adding the menu
- // item to all applicable menu items using the resource
- // editor.
- // Add Tip of the Day menu item on the fly!
- static CMenu* pSubMenu = NULL;
- CString strHelp; strHelp.LoadString(CG_IDS_TIPOFTHEDAYHELP);
- CString strMenu;
- int nMenuCount = pMenu->GetMenuItemCount();
- BOOL bFound = FALSE;
- for (int i=0; i < nMenuCount; i++)
- {
- pMenu->GetMenuString(i, strMenu, MF_BYPOSITION);
- if (strMenu == strHelp)
- {
- pSubMenu = pMenu->GetSubMenu(i);
- bFound = TRUE;
- ASSERT(pSubMenu != NULL);
- }
- }
- CString strTipMenu;
- strTipMenu.LoadString(CG_IDS_TIPOFTHEDAYMENU);
- if (!bFound)
- {
- // Help menu is not available. Please add it!
- if (pSubMenu == NULL)
- {
- // The same pop-up menu is shared between mainfrm and frame
- // with the doc.
- static CMenu popUpMenu;
- pSubMenu = &popUpMenu;
- pSubMenu->CreatePopupMenu();
- pSubMenu->InsertMenu(0, MF_STRING|MF_BYPOSITION,
- CG_IDS_TIPOFTHEDAY, strTipMenu);
- }
- pMenu->AppendMenu(MF_STRING|MF_BYPOSITION|MF_ENABLED|MF_POPUP,
- (UINT)pSubMenu->m_hMenu, strHelp);
- DrawMenuBar();
- }
- else
- {
- // Check to see if the Tip of the Day menu has already been added.
- pSubMenu->GetMenuString(0, strMenu, MF_BYPOSITION);
- if (strMenu != strTipMenu)
- {
- // Tip of the Day submenu has not been added to the
- // first position, so add it.
- pSubMenu->InsertMenu(0, MF_BYPOSITION); // Separator
- pSubMenu->InsertMenu(0, MF_STRING|MF_BYPOSITION,
- CG_IDS_TIPOFTHEDAY, strTipMenu);
- }
- }
- }
- */
- }
- void CMainFrame::OnNotReport()
- {
- // TODO: Add your command handler code here
- NoReport=!NoReport;
- }
- void CMainFrame::OnUpdateNotReport(CCmdUI* pCmdUI)
- {
- // TODO: Add your command update UI handler code here
- pCmdUI->SetCheck (NoReport);
- }
- void CMainFrame::OnSetagent()
- {
- CAgent dlg;
-
- dlg.m_agent=this->m_agent;
- if(dlg.DoModal()==IDCANCEL)
- {
-
- // this->m_wndReportBar.WriteReportLine("欢迎进入snmp管理系统", 0);
- // this->m_wndReportBar.WriteReportLine("请设置代理相应的信息", 0);
- }
- //
- else
- {
-
- this->m_wndReportBar.WriteReportLine("*******************", 0);
- this->m_wndReportBar.WriteReportLine("修改参数信息为", 0);
- this->m_wndReportBar.WriteReportLine("*******************", 0);
- this->m_wndReportBar.WriteReportLine("当前管理代理设备ip", 0);
- this->m_wndReportBar.WriteReportLine(dlg.m_agent, 0);
- this->m_wndReportBar.WriteReportLine("当前管理社区标志", 0);
- this->m_wndReportBar.WriteReportLine(dlg.m_community, 0);
- this->m_agent =dlg.m_agent;
- this->m_community =dlg.m_community;
- }
- }
- void CMainFrame::OnActionGet()
- {
- flag=1; /*表示是 get操作*/
- CString str1;
- m_wndAddress.GetWindowText(str1);
- SelfFlag=0;
- CString a=str1.Left(22);
- if (!strcmp(a,"1.3.6.1.4.1.26.5.1.5.1"))
- SelfFlag=1; /*表明是board操作*/
- Start(1);
-
- }
- void CMainFrame::OnActionGetbulk()
- {
- // TODO: Add your command handler code here
- flag=3;
- Start(3);
-
- }
- void CMainFrame::OnActionGetnext()
- {
- // TODO: Add your command handler code here
- SelfFlag=0;
- CString str1;
- m_wndAddress.GetWindowText(str1);
- if (!strcmp(str1.Left(22),"1.3.6.1.4.1.26.5.1.5.1")) SelfFlag=1; /*表明是board操作*/
- flag=2;
- Start(2);
- }
- void CMainFrame::OnActionSet()
- {
- CDlgSet dlg;
- smiVALUE value;
- smiOCTETS str;
- if(pSnmp.sessionID==FALSE)
- {
- pSnmp.CreateSession(CMainFrame::m_hWnd,wMsg);
- pSnmp.sessionID=TRUE;
- }
- dlg.pMain=this;
- if(dlg.DoModal()==IDOK)
- {
-
-
- value.syntax=SNMP_SYNTAX_OCTETS;
- str.ptr=new unsigned char;
- strcpy((char*)str.ptr,dlg.m_sValue);
- str.len=lstrlen(dlg.m_sValue);
- value.value.string=str;
- CString str1;
- m_wndAddress.GetWindowText(str1);
- str1=str1+_T(".") + "0";
- pSnmp.CreateVbl(str1,&value);
- Start(4); /*标明是set操作*/
- }
-
-
- }
- void CMainFrame::OnRecv() /*响应*/
- {
- int nIpin;
- CString strIp;
- CString strTemp;
- smiLPINT PDU_type=new smiINT;
- char* pSrc =new char[100];
- int status;
- CString strHead;
- CTime NowTime;
- int output=0;/*在正常的输出窗口输出*/
- //status =pSnmp.Receive(m_sOid,m_value,PDU_type,pSrc);
- status=pSnmp.Receive(m_sOid,m_value,PDU_type,pSrc);
- if (!status)
- {
- NowTime=CTime::GetCurrentTime();
- strHead = NowTime.Format("%Y-%m-%d %H:%M:%S "); this->m_wndReportBar.WriteReportLine((strHead+"------接收消息失败---"),2);
- return;
- }
- if (*PDU_type==SNMP_PDU_TRAP )
- {
- NowTime=CTime::GetCurrentTime();
- strHead = NowTime.Format("%Y-%m-%d %H:%M:%S ");
- this->m_wndReportBar.WriteReportLine((strHead+"接收陷进---from @"),1);
- this->m_wndReportBar.WriteReportLine(pSrc,1);
- output=1;
- delete pSrc;
- return;
- }
- //if (status) /*接收包正确*/
-
- //{
- for(int i=1;i<=pSnmp.nCount;i++)
- {
- switch(m_value[i]->syntax)
- {
- case SNMP_SYNTAX_INT:
- // case SNMP_SYNTAX_INT32:
- smiINT sNumber;
- sNumber=m_value[i]->value.sNumber;
- nIpin=sNumber;
- wsprintf(str[i],"%d",sNumber);
- break;
- case SNMP_SYNTAX_UINT32:
- case SNMP_SYNTAX_CNTR32:
- case SNMP_SYNTAX_GAUGE32:
- case SNMP_SYNTAX_TIMETICKS:
- smiUINT32 uNumber;
- uNumber=m_value[i]->value.uNumber;
- nIpin=uNumber;
- wsprintf(str[i],"%d",uNumber);
- break;
- case SNMP_SYNTAX_CNTR64:
- smiCNTR64 hNumber;
- hNumber=m_value[i]->value.hNumber;
- break;
- case SNMP_SYNTAX_OCTETS:
- str[i]=(char *)m_value[i]->value.string.ptr;
- break;
- case SNMP_SYNTAX_OPAQUE:
- case SNMP_SYNTAX_NSAPADDR:
- str[i]=(char *)m_value[i]->value.string.ptr;
- break;
- case SNMP_SYNTAX_IPADDR:
- strIp.Format("%d",*m_value[i]->value.string.ptr);
- strIp+=".";
- strTemp.Format("%d",*(m_value[i]->value.string.ptr+1));
- strIp+=strTemp;
- strIp+=".";
- strTemp.Format("%d",*(m_value[i]->value.string.ptr+2));
- strIp+=strTemp;
- strIp+=".";
- strTemp.Format("%d",*(m_value[i]->value.string.ptr+3));
- strIp+=strTemp;
- strcpy(str[i],strIp);
- break;
- case SNMP_SYNTAX_OID:
- smiOID oid;
- oid=m_value[i]->value.oid;
- SnmpOidToStr(&oid,30,str[i]);
- //SnmpFreeDescriptor (SNMP_SYNTAX_OID, (smiLPOPAQUE)&oid);
- break;
- case SNMP_SYNTAX_NULL:
- case SNMP_SYNTAX_NOSUCHOBJECT:
- case SNMP_SYNTAX_NOSUCHINSTANCE:
- case SNMP_SYNTAX_ENDOFMIBVIEW:
- smiBYTE empty;
- empty=m_value[i]->value.empty;
- str[i]="No such name,please check!";
- break;
- default:
- break;
- }
-
- CString temp,temp1;
- CString str2;
- char* pBoard=new char[4];
- CString pTemp;
- if (flag!=5)
- m_wndAddress.GetWindowText(str2);
-
-
- temp1= CString(m_sOid[i]);
- if (SelfFlag) /*表明是设备操作*/
- {
- this->m_wndReportBar.WriteReportLine("接收命令---getresponse", output);
- this->m_wndReportBar.WriteReportLine("from------", output);
- this->m_wndReportBar.WriteReportLine(pSrc,0);
- this->m_wndReportBar.WriteReportLine("oid值", output);
- this->m_wndReportBar.WriteReportLine(CString(m_sOid[i]), output);
- int type;
- unsigned int short mask=0x8000;
- if(flag==5)/*表明是刷新操作*/
- {
- type=4-i;
- }
- else
- {
- if(str2.Right(1) == _T("1") )
- type=1;
- else if(str2.Right(1) == _T("2") )
- type=2;
- else if(str2.Right(1) == _T("3") )
- type=3;/*在位否*/
- else
- type=5;/*其他*/
- }
- if (type<4 )
- {
- if (type==3) this->m_wndReportBar.WriteReportLine("当前在位的板位",0);
- for(int board=0;board<16;board++)
- {
- test[board][type]=(mask & nIpin)?1:0;
- mask>>=1;
- if(type==3)
- {
-
- if(!test[board][type])
- {
-
- wsprintf(pBoard,"%d",board);
- pTemp=_T("板位----") + CString(pBoard);
- this->m_wndReportBar.WriteReportLine(pTemp,0);
- }
- }
- else
- {
- if(!test[board][3]) /*表示在位*/
- {
-
- wsprintf(pBoard,"%d",board);
- pTemp=_T("板位") + CString(pBoard);
- // this->m_wndReportBar.WriteReportLine(pTemp,0);
- if(type==2)
- {
- if(!test[board][type])
- this->m_wndReportBar.WriteReportLine(pTemp+"---容量10M",0);
- else
- this->m_wndReportBar.WriteReportLine(pTemp+"---容量100M",0);
- }
- if(type==1)/*连接状况*/
- {
- if(!test[board][type])
- this->m_wndReportBar.WriteReportLine(pTemp+"---连接正常",0);
- else
- this->m_wndReportBar.WriteReportLine(pTemp+"---连接非正常",0);
- }
-
- }
- }
- }
- }
- }
- if (flag==1)
- {
- this->m_wndReportBar.WriteReportLine("*******************", output);
- this->m_wndReportBar.WriteReportLine("接收命令---getresponse", output);
- this->m_wndReportBar.WriteReportLine("from------", output);
- this->m_wndReportBar.WriteReportLine(pSrc,0);
- this->m_wndReportBar.WriteReportLine("oid值", output);
- this->m_wndReportBar.WriteReportLine(CString(m_sOid[i]), output);
- this->m_wndReportBar.WriteReportLine("命令值", output);
- this->m_wndReportBar.WriteReportLine(CString(str[i]), output);
-
- }
- if (flag==2)
- {
- m_wndAddress.SetWindowText(CString(m_sOid[i]));
- this->m_wndReportBar.WriteReportLine("*******************", output);
- this->m_wndReportBar.WriteReportLine("接收命令--getNextresponse", output);
- this->m_wndReportBar.WriteReportLine("from------", output);
- this->m_wndReportBar.WriteReportLine(pSrc,0);
- this->m_wndReportBar.WriteReportLine("oid值", output);
- this->m_wndReportBar.WriteReportLine(CString(m_sOid[i]), output);
- this->m_wndReportBar.WriteReportLine("命令值", output);
- this->m_wndReportBar.WriteReportLine(CString(str[i]), output);
- this->m_wndReportBar.WriteReportLine("*******************", output);
- }
- if (flag==3)
- {
- m_wndAddress.SetWindowText(CString(m_sOid[i]));
- this->m_wndReportBar.WriteReportLine("*******************", output);
- this->m_wndReportBar.WriteReportLine("接收命令--getbulkponse", output);
- this->m_wndReportBar.WriteReportLine("from------", output);
- this->m_wndReportBar.WriteReportLine(pSrc,0);
- this->m_wndReportBar.WriteReportLine("oid值", output);
- this->m_wndReportBar.WriteReportLine(CString(m_sOid[i]), output);
- this->m_wndReportBar.WriteReportLine("命令值", output);
- this->m_wndReportBar.WriteReportLine(CString(str[i]), output);
- this->m_wndReportBar.WriteReportLine("*******************", output);
- }
- if (flag==4)
- {
- m_wndAddress.SetWindowText(CString(m_sOid[i]));
- this->m_wndReportBar.WriteReportLine("*******************", output);
- this->m_wndReportBar.WriteReportLine("接收命令--getSetResponse", output);
- this->m_wndReportBar.WriteReportLine("from------", output);
- this->m_wndReportBar.WriteReportLine(pSrc,0);
- this->m_wndReportBar.WriteReportLine("oid值", output);
- this->m_wndReportBar.WriteReportLine(CString(m_sOid[i]), output);
- this->m_wndReportBar.WriteReportLine("命令值", output);
- this->m_wndReportBar.WriteReportLine(CString(str[i]), output);
- this->m_wndReportBar.WriteReportLine("*******************", output);
- }
- }
- delete PDU_type;
- // if (flag==1)
- // Next(m_sOid[1]);
- //}
-
-
- }
- void CMainFrame::Start(int flag1)
- {
- CString str;
- SelfFlag=0;
- if(flag1 !=4) /*表明是SET操作,VARLIST已经添好了*/
- {
- if(pSnmp.sessionID==FALSE)
- {
- pSnmp.CreateSession(CMainFrame::m_hWnd,wMsg);
- pSnmp.sessionID=TRUE;
- }
- pSnmp.Register();
- if (flag1==5) /*表明是刷新操作*/
- {
- flag=5;
- SelfFlag=1;
- str="1.3.6.1.4.1.26.5.1.5.1.3.0";
- pSnmp.CreateVbl(str,NULL);
- str="1.3.6.1.4.1.26.5.1.5.1.1.0";
- pSnmp.SetVbl(str,NULL);
- str="1.3.6.1.4.1.26.5.1.5.1.2.0";
- pSnmp.SetVbl(str,NULL);
- }
- else
- {
-
- m_wndAddress.GetWindowText(str);
- str=str+_T(".") + "0";
-
- pSnmp.CreateVbl(str,NULL);
-
- }
- }
- switch (flag1)
- {
- case 1:
- case 5: /*刷新命令*/
- pSnmp.CreatePdu(SNMP_PDU_GET,NULL,NULL,NULL);
- break;
- case 2:
- pSnmp.CreatePdu(SNMP_PDU_GETNEXT,NULL,NULL,NULL);
- break;
- case 3:
- pSnmp.CreatePdu(SNMP_PDU_GETBULK,NULL,1,3);
- break;
- case 4:
- pSnmp.CreatePdu(SNMP_PDU_SET,NULL,NULL,NULL);
- break;
- default:
- break;
- }
- pSnmp.Send(m_agent,m_community);
- this->m_wndReportBar.WriteReportLine("*******************", 0);
- this->m_wndReportBar.WriteReportLine("发送命令", 0);
- this->m_wndReportBar.WriteReportLine("*******************", 0);
- this->m_wndReportBar.WriteReportLine("当前管理代理设备ip", 0);
- this->m_wndReportBar.WriteReportLine(m_agent, 0);
- this->m_wndReportBar.WriteReportLine("当前管理社区标志", 0);
- this->m_wndReportBar.WriteReportLine(m_community, 0);
- }
- void CMainFrame::OnAddnode()
- {
-
- }
- void CMainFrame::Next(LPTSTR Oid)
- {
- CString str(Oid);
- static i=0;
- //AfxMessageBox(str.Left(20));
- CString str1;
- m_wndAddress.GetWindowText(str1);
-
- if(!strcmp(str.Left(19),str1))
- {
- m_OidNext[i]=new char[50];
- m_valueNext[i]=new char[50];
- strcpy(m_OidNext[i],m_sOid[1]);
- strcpy(m_valueNext[i],CMainFrame::str[1]);
- //AfxMessageBox(CMainFrame::str[1]);
- //AfxMessageBox(m_sOid[1]);
- //*(m_valueNext+i)=CSnmpManagerDlg::str[1];
- pSnmp.CreateVbl(Oid,NULL);
- pSnmp.CreatePdu(SNMP_PDU_GETNEXT,NULL,NULL,NULL);
- pSnmp.Send(m_agent,m_community);
- i++;
- }
- else
- {
- /* m_bNext=FALSE;
- CDlgPrint pDlg;
- for(int j=0;j<i;j++)
- {
- delete[50] m_OidNext[i];
- delete[50] m_valueNext[i];
- }
- pDlg.m_Oid=m_OidNext;
- pDlg.m_value=m_valueNext;
- pDlg.n=i;
- pDlg.DoModal();*/
-
- /* for(int i=0;i<2;i++)
- {
- this->w_wndReportBar.WriteReportLine("*******************", 0);
- this->m_wndReportBard.WriteReportLine("命令值", 0);
- this->m_wndReportBar.WriteReportLine(CString(*(m_Oid+i)), 0);
- this->m_wndReportBar.WriteReportLine(CString(*(m_value+i)), 0);
-
- }
- */
-
- }
- }
- void CMainFrame::OnUser()
- {
- CUserManagement dlg;
- dlg.DoModal();
- }
- void CMainFrame::OnUpdateActionGet(CCmdUI* pCmdUI)
- {
- // TODO: Add your command update UI handler code here
- pCmdUI->Enable(m_power);
-
- }
- void CMainFrame::OnUpdateActionGetnext(CCmdUI* pCmdUI)
- {
- // TODO: Add your command update UI handler code here
- pCmdUI->Enable(m_power);
-
- }
- void CMainFrame::OnUpdateActionSet(CCmdUI* pCmdUI)
- {
- // TODO: Add your command update UI handler code here
- pCmdUI->Enable(m_power);
- }
- void CMainFrame::OnUpdateUser(CCmdUI* pCmdUI)
- {
- // TODO: Add your command update UI handler code here
- pCmdUI->Enable(m_power);
-
- }