NewNode.cpp
上传用户:lvjun8202
上传日期:2013-04-30
资源大小:797k
文件大小:4k
- // NewNode.cpp : implementation file
- //
- #include "stdafx.h"
- #include "snmp_cwdm.h"
- #include "NewNode.h"
- #ifdef _DEBUG
- #define new DEBUG_NEW
- #undef THIS_FILE
- static char THIS_FILE[] = __FILE__;
- #endif
- /////////////////////////////////////////////////////////////////////////////
- // CNewNode dialog
- CNewNode::CNewNode(CWnd* pParent /*=NULL*/)
- : CDialog(CNewNode::IDD, pParent)
- {
- //{{AFX_DATA_INIT(CNewNode)
- m_text = _T("");
- m_data = 0;
- m_nButtonMode = -1;
- //}}AFX_DATA_INIT
- }
- void CNewNode::DoDataExchange(CDataExchange* pDX)
- {
- CDialog::DoDataExchange(pDX);
- //{{AFX_DATA_MAP(CNewNode)
- DDX_Text(pDX, IDC_NEW, m_text);
- DDX_Text(pDX, IDC_DATA, m_data);
- DDX_Radio(pDX, IDC_BEFORE, m_nButtonMode);
- //}}AFX_DATA_MAP
- }
- BEGIN_MESSAGE_MAP(CNewNode, CDialog)
- //{{AFX_MSG_MAP(CNewNode)
- ON_EN_CHANGE(IDC_NEW, OnChangeNew)
- //}}AFX_MSG_MAP
- END_MESSAGE_MAP()
- /////////////////////////////////////////////////////////////////////////////
- // CNewNode message handlers
- void CNewNode::OnChangeNew()
- {
- //SAMPLE: if the IDC_NEW becomes empty, disable the OK button
- CEdit* pEdit = (CEdit*) GetDlgItem(IDC_NEW);
- // ASSERT(pEdit != NULL);
- int n = pEdit->GetWindowTextLength();
- GetDlgItem(IDOK)->EnableWindow((n != 0));
-
- }
- void CNewNode::OnOK()
- {
- //SAMPLE: when the user presses OK, decide what to do
- UpdateData(TRUE);
- // ASSERT(m_pTreeCtrl != NULL);
- HTREEITEM hSelected = m_pTreeCtrl->GetSelectedItem();
- CString str;
- GetDlgItemText(IDC_NEW, str);
- HTREEITEM hParent = m_pTreeCtrl->GetParentItem(hSelected);
- if (hParent == NULL)
- hParent = TVI_ROOT;
- //SAMPLE: insert at root
- if (m_nButtonMode == 3)
- {
- m_pTreeCtrl->InsertItem(TVIF_HANDLE ,str,1,1,0,0,m_data,TVI_ROOT, m_nInsertMethod);
- }
- //HTREEITEM InsertItem(UINT nMask, LPCTSTR lpszItem, int nImage, int nSelectedImage, UINT nState, UINT nStateMask, LPARAM lParam, HTREEITEM hParent, HTREEITEM hInsertAfter );
- //SAMPLE: insert after this item
- else if (m_nButtonMode == 1)
- {
- HTREEITEM temp;
- temp=m_pTreeCtrl->InsertItem(str,hParent, hSelected);
- m_pTreeCtrl->SetItemData(temp,m_data);
- }
- //SAMPLE: insert before the selected item
- else if (m_nButtonMode == 0)
- {
- HTREEITEM hAfter = m_pTreeCtrl->GetPrevSiblingItem(hSelected);
- if (hAfter == NULL)
- hAfter = TVI_FIRST;
- HTREEITEM temp;
- temp=m_pTreeCtrl->InsertItem(str,hParent, hAfter);
- m_pTreeCtrl->SetItemData(temp,m_data);
- }
- //SAMPLE: insert as child of the selected item
- else
- {
- HTREEITEM temp;
- temp= m_pTreeCtrl->InsertItem(str,hSelected, TVI_FIRST);
- m_pTreeCtrl->SetItemData(temp,m_data);
- }
- CDialog::OnOK();
- }
- BOOL CNewNode::OnInitDialog()
- {
- //SAMPLE: we'd better have an associated tree control!
- // ASSERT(m_pTreeCtrl != NULL);
- //SAMPLE: what's selected in our control?
- HTREEITEM hSelected = m_pTreeCtrl->GetSelectedItem();
- //SAMPLE: if nothing, must insert at root
- // otherwise, it's the user's choice.
- if (hSelected == NULL)
- {
- m_nInsertMethod = TVI_ROOT;
- GetDlgItem(IDC_BEFORE)->EnableWindow(FALSE);
- GetDlgItem(IDC_AFTER)->EnableWindow(FALSE);
- GetDlgItem(IDC_CHILD)->EnableWindow(FALSE);
- SetDlgItemText(IDC_CURRENT, _T("No current item; must insert as root item!"));
- m_nButtonMode = 3;
- }
- else
- {
- char sz[1024];
- TVITEM item;
- item.mask = TVIF_TEXT;
- item.pszText = sz;
- item.cchTextMax = 1024;
- item.hItem = hSelected;
- if (m_pTreeCtrl->GetItem(&item))
- SetDlgItemText(IDC_CURRENT, item.pszText);
- else
- {
- MessageBox(_T("Error retieving current text!"));
- EndDialog(IDCANCEL);
- }
- }
- //SAMPLE: initialize the rest of the controls
- CEdit* pEdit = (CEdit*) GetDlgItem(IDC_NEW);
- // ASSERT(pEdit != NULL);
- pEdit->SetLimitText(1024);
- pEdit->SetWindowText(_T("New Item"));
- //SAMPLE: don't forget to call the base class!
- CDialog::OnInitDialog();
- //SAMPLE: we set focus for ourselves, so return FALSE
- pEdit->SetFocus();
- return FALSE;
- }