snmp_cwdmView.cpp
上传用户:lvjun8202
上传日期:2013-04-30
资源大小:797k
文件大小:10k
- // snmp_cwdmView.cpp : implementation of the CSnmp_cwdmView class
- //
- #include "stdafx.h"
- #include "OAM.h"
- #include "OAMDoc.h"
- #include "snmp_cwdmView.h"
- #include "NewItemDlg.h"
- #ifdef _DEBUG
- #define new DEBUG_NEW
- #undef THIS_FILE
- static char THIS_FILE[] = __FILE__;
- #endif
- /////////////////////////////////////////////////////////////////////////////
- // CSnmp_cwdmView
- IMPLEMENT_DYNCREATE(CSnmp_cwdmView, CTreeView)
- BEGIN_MESSAGE_MAP(CSnmp_cwdmView, CTreeView)
- //{{AFX_MSG_MAP(CSnmp_cwdmView)
- ON_COMMAND(IDD_NEWITEM1, OnNewitem)
- ON_WM_SIZE()
- ON_COMMAND(IDD_DELETE, OnDelete)
- ON_NOTIFY_REFLECT(TVN_SELCHANGED, OnSelchanged)
- ON_WM_RBUTTONDOWN()
- ON_WM_LBUTTONDOWN()
- //}}AFX_MSG_MAP
- // Standard printing commands
- ON_COMMAND(ID_FILE_PRINT, CTreeView::OnFilePrint)
- ON_COMMAND(ID_FILE_PRINT_DIRECT, CTreeView::OnFilePrint)
- ON_COMMAND(ID_FILE_PRINT_PREVIEW, CTreeView::OnFilePrintPreview)
- END_MESSAGE_MAP()
- /////////////////////////////////////////////////////////////////////////////
- // CSnmp_cwdmView construction/destruction
- CSnmp_cwdmView::CSnmp_cwdmView()
- {
- // TODO: add construction code here
- // this->SetWindowPos(NULL,0,24,200,4000,SWP_NOZORDER);
- }
- CSnmp_cwdmView::~CSnmp_cwdmView()
- {
- }
- BOOL CSnmp_cwdmView::PreCreateWindow(CREATESTRUCT& cs)
- {
- // TODO: Modify the Window class or styles here by modifying
- // the CREATESTRUCT cs
- if (!CTreeView::PreCreateWindow(cs))
- return FALSE;
- //SAMPLE: want buttons and lines everywhere!
- // cs.style |= TVS_HASLINES | TVS_HASBUTTONS | TVS_LINESATROOT;
- cs.style |= TVS_HASLINES|TVS_HASBUTTONS|TVS_LINESATROOT|TVS_SINGLEEXPAND ;
- return TRUE;
- // return CTreeView::PreCreateWindow(cs);
- }
- /////////////////////////////////////////////////////////////////////////////
- // CSnmp_cwdmView drawing
- void CSnmp_cwdmView::OnDraw(CDC* pDC)
- {
- COAMDoc* pDoc = GetDocument();
- //this->SetWindowPos(NULL,0,24,2000,4000,SWP_NOZORDER);
- ASSERT_VALID(pDoc);
- // TODO: add draw code for native data here
- }
- void CSnmp_cwdmView::OnInitialUpdate()
- {
- CTreeView::OnInitialUpdate();
- // this->SetWindowPos(NULL,0,24,200,4000,SWP_NOZORDER);
- CTreeCtrl& theTree = GetTreeCtrl();
- CGlobalVariable::m_pStationTreeView = this;
- char lpszPathName[150] = "mymib";
- CGlobalVariable::m_pMainDoc->OnOpenDocument(lpszPathName);
- // CGlobalVariable::m_pMainDoc->LoadMe();
- }
- /////////////////////////////////////////////////////////////////////////////
- // CSnmp_cwdmView printing
- BOOL CSnmp_cwdmView::OnPreparePrinting(CPrintInfo* pInfo)
- {
- // default preparation
- return DoPreparePrinting(pInfo);
- }
- void CSnmp_cwdmView::OnBeginPrinting(CDC* /*pDC*/, CPrintInfo* /*pInfo*/)
- {
- // TODO: add extra initialization before printing
- }
- void CSnmp_cwdmView::OnEndPrinting(CDC* /*pDC*/, CPrintInfo* /*pInfo*/)
- {
- // TODO: add cleanup after printing
- }
- void CSnmp_cwdmView::RecursiveWriteItems(CArchive& ar, CTreeCtrl& refCtrl, HTREEITEM hItem)
- {
- //SAMPLE: loop through each item at the level of hItem (eg,
- // hItem and all of its siblings)
- do
- {
- CString str = refCtrl.GetItemText(hItem);
- DWORD data= refCtrl.GetItemData(hItem);
- ar << (BYTE) recordRegular;
- ar << str;
- ar << (BYTE) recordData;
- ar << data;
- //SAMPLE: if a given item has children, mark a push in the indentation
- // level and recurse to get all those children
- if (refCtrl.ItemHasChildren(hItem))
- {
- ar << (BYTE) recordPush;
- RecursiveWriteItems(ar, refCtrl, refCtrl.GetChildItem(hItem));
- }
- }
- while ((hItem = refCtrl.GetNextSiblingItem(hItem)) != NULL);
- //SAMPLE: done working at this level--mark a pop and return
- // either to our caller or the next less nested level.
- ar << (BYTE) recordPop;
- }
- void CSnmp_cwdmView::WriteTreeViewContent(CArchive& ar, CTreeCtrl& refCtrl)
- {
- UINT nCount = refCtrl.GetCount();
- ar << nCount;
- // short circuit the zero-element case
- if (nCount == 0)
- return;
- //SAMPLE: there's real work to do! Start recursing at the root item
- HTREEITEM hItem = refCtrl.GetRootItem();
- RecursiveWriteItems(ar, refCtrl, hItem);
- }
- void CSnmp_cwdmView::ReadTreeViewContent(CArchive& ar, CTreeCtrl& refCtrl)
- {
- //SAMPLE: start out by deleting all the content from the control
- refCtrl.DeleteAllItems();
- // GetTreeCtrl().DeleteAllItems();
- //SAMPLE: figure out if the control was empty when it was stored
- UINT nCount;
- ar >> nCount;
- //SAMPLE: if so, just short circuit the zero-element case
- if (nCount == 0)
- return;
- //SAMPLE: otherwise, start sucking data in!
- m_nIndex = 0;
- m_hItems[m_nIndex] = TVI_ROOT;
- HTREEITEM hAfter = TVI_FIRST;
-
- //SAMPLE: while we're above the root, keep reading
- while (m_nIndex >= 0)
- {
- //SAMPLE: get a record type
- BYTE byteType;
- ar >> byteType;
- static CString str;
- switch (byteType)
- {
- //SAMPLE: for a regular record, we'll just insert it into
- // the control. Note how we'll insert after the most recently
- // added item, and we'll insert as a child of the item on
- // our hItems stack.
- case recordRegular:
- {
-
- ar >> str;break;
- }
-
- case recordData:
- {
- LPARAM data;
- ar >> data;
- //hAfter = refCtrl.InsertItem(str,m_hItems[m_nIndex], hAfter);
- hAfter = GetTreeCtrl().InsertItem(str,m_hItems[m_nIndex], hAfter);
- //refCtrl.SetItemData(hAfter,data);
- GetTreeCtrl().SetItemData(hAfter,data);
- break;}
-
- //SAMPLE: if we're going one deeper, we'll need to bump the stack
- // and reset the insertion flag. Note that this sample can only
- // handle 99 levels of items in the control. You might want to fix
- // this code to use a dynamic array (eg, a CArray). Whatever you do,
- // the error recovery here needs to be a bit better!
- case recordPush:
- //ASSERT(m_nIndex < 99);
- m_hItems[++m_nIndex] = hAfter;
- hAfter = TVI_FIRST;
- break;
- //SAMPLE: if we're going one less deep, we'll pop the stack
- case recordPop:
- m_nIndex--;
- break;
- default:
- {
- // ASSERT(FALSE);
- //TODO: pick a better exception type
- AfxThrowMemoryException();
- }
- }
- }
- refCtrl.Expand((refCtrl.GetRootItem()),TVE_EXPAND);
- }
- void CSnmp_cwdmView::Serialize(CArchive& ar)
- {
- //SAMPLE: when we're serialized, we'll turn around and call our Write/Read
- // helper functions. Just neater code, that's all.
- if (ar.IsStoring())
- {
- WriteTreeViewContent(ar, GetTreeCtrl());
- }
- else
- {
- ReadTreeViewContent(ar, GetTreeCtrl());
- }
- }
- /////////////////////////////////////////////////////////////////////////////
- // CSnmp_cwdmView diagnostics
- #ifdef _DEBUG
- void CSnmp_cwdmView::AssertValid() const
- {
- CTreeView::AssertValid();
- }
- void CSnmp_cwdmView::Dump(CDumpContext& dc) const
- {
- CTreeView::Dump(dc);
- }
- COAMDoc* CSnmp_cwdmView::GetDocument() // non-debug version is inline
- {
- ASSERT(m_pDocument->IsKindOf(RUNTIME_CLASS(COAMDoc)));
- return (COAMDoc*)m_pDocument;
- }
- #endif //_DEBUG
- /////////////////////////////////////////////////////////////////////////////
- // CSnmp_cwdmView message handlers
- void CSnmp_cwdmView::OnNewitem()
- {
- CNewItemDlg dlg;
- CTreeCtrl& theCtrl = GetTreeCtrl();
- dlg.m_pTreeCtrl = &theCtrl;
- if (dlg.DoModal() == IDOK)
- {
- //SAMPLE: the dialog has modified our content directly,
- // but it's up to us to set the dirty flag
- GetDocument()->SetModifiedFlag();
- }
-
- }
- void CSnmp_cwdmView::OnDelete()
- {
- HTREEITEM htItem = GetTreeCtrl().GetSelectedItem();
- if ((htItem != NULL) )
- {
- GetTreeCtrl().DeleteItem(htItem);
- GetDocument()->SetModifiedFlag();
- }
- }
- void CSnmp_cwdmView::OnSize(UINT nType, int cx, int cy)
- {
- CTreeView::OnSize(nType, cx, cy);
-
- // TODO: Add your message handler code here
-
- }
- void CSnmp_cwdmView::OnSelchanged(NMHDR* pNMHDR, LRESULT* pResult)
- {
- NM_TREEVIEW* pNMTreeView = (NM_TREEVIEW*)pNMHDR;
- HTREEITEM hti = GetTreeCtrl().GetSelectedItem();
- if (hti)
- {
- CString str;// = GetTreeCtrl().GetItemText(hti);
- CString str_oid;
- GetFullPath(hti,str,str_oid);
- if(CGlobalVariable::m_pAddressCombo)
- {
- CGlobalVariable::m_pAddressCombo->AddNewAdress(str_oid);
- // CMainFrame::m_oid=str_oid;
- }
- long nData;
- //GetTreeCtrl().GetItemImage (hti, nImage, nImage);
- nData = GetTreeCtrl().GetItemData(hti);
- GetTreeCtrl().Select(hti, TVGN_DROPHILITE);
-
-
- }
-
-
- *pResult = 0;
- }
- BOOL CSnmp_cwdmView::GetFullPath(HTREEITEM hItem,CString &str,CString& str_oid)
- {
- char temp[4];
- CString str_oid1;
- while(hItem)
- {
- if(str != _T(""))
- {
- char temp1[4];
- str = GetTreeCtrl().GetItemText(hItem) + _T(".") + str;
- _itoa(GetTreeCtrl().GetItemData(hItem),temp1,10);
- str_oid1=(temp1);
- str_oid=str_oid1+_T(".") +str_oid;
- }
- else
- {
- str = GetTreeCtrl().GetItemText(hItem);
- _itoa(GetTreeCtrl().GetItemData(hItem),temp,10);
- str_oid=temp;
- }
- hItem = GetTreeCtrl().GetParentItem(hItem);
- }
- return TRUE;
- }
- void CSnmp_cwdmView::OnRButtonDown(UINT nFlags, CPoint point)
- {
-
- UINT uFlags;
- HTREEITEM htItem = GetTreeCtrl().HitTest(point, &uFlags);
- if ((htItem != NULL) && (uFlags & TVHT_ONITEM))
- {
- GetTreeCtrl().Select(htItem, TVGN_DROPHILITE);
- /* if (point.x == -1 && point.y == -1)
- {
- //keystroke invocation
- CRect rect;
- GetClientRect(&rect);
- ClientToScreen(&rect);
-
- point = rect.TopLeft();
- point.Offset(5,5);
- }
-
- CMenu menu;
- VERIFY(menu.LoadMenu(IDR_TREE));
-
- CMenu* pPopup = menu.GetSubMenu(0);
- //ASSERT(pPopup != NULL);
- CWnd* pWndPopupOwner = this;
- while (pWndPopupOwner->GetStyle() & WS_CHILD)
- pWndPopupOwner = pWndPopupOwner->GetParent();
- pPopup->TrackPopupMenu(TPM_LEFTALIGN | TPM_RIGHTBUTTON, point.x, point.y,
- pWndPopupOwner);
- }*/
- }
- }
- void CSnmp_cwdmView::OnLButtonDown(UINT nFlags, CPoint point)
- {
- // TODO: Add your message handler code here and/or call default
-
- CTreeView::OnLButtonDown(nFlags, point);
- }