NewItemDlg.cpp
资源名称:SNMP范例源代码.zip [点击查看]
上传用户:shgx688
上传日期:2009-12-27
资源大小:855k
文件大小:4k
源码类别:
SNMP编程
开发平台:
MultiPlatform
- // NewItemDlg.cpp : implementation file
- //
- #include "stdafx.h"
- #include "OAM.h"
- #include "NewItemDlg.h"
- #ifdef _DEBUG
- #define new DEBUG_NEW
- #undef THIS_FILE
- static char THIS_FILE[] = __FILE__;
- #endif
- /////////////////////////////////////////////////////////////////////////////
- // CNewItemDlg dialog
- /////////////////////////////////////////////////////////////////////////////
- // CNewItemDlg dialog
- CNewItemDlg::CNewItemDlg(CWnd* pParent /*=NULL*/)
- : CDialog(CNewItemDlg::IDD, pParent)
- {
- //{{AFX_DATA_INIT(CNewItemDlg)
- m_nButtonMode = 0;
- m_data = 0;
- m_text = _T("");
- //}}AFX_DATA_INIT
- m_pTreeCtrl = NULL;
- }
- void CNewItemDlg::DoDataExchange(CDataExchange* pDX)
- {
- CDialog::DoDataExchange(pDX);
- //{{AFX_DATA_MAP(CNewItemDlg)
- DDX_Radio(pDX, IDC_BEFORE, m_nButtonMode);
- DDX_Text(pDX, IDC_DATA, m_data);
- DDX_Text(pDX, IDC_NEW, m_text);
- DDX_Control(pDX, IDOK, m_btOk);
- DDX_Control(pDX, IDCANCEL, m_btCancel);
- //}}AFX_DATA_MAP
- }
- BEGIN_MESSAGE_MAP(CNewItemDlg, CDialog)
- //{{AFX_MSG_MAP(CNewItemDlg)
- ON_EN_CHANGE(IDC_NEW, OnChangeNew)
- //}}AFX_MSG_MAP
- END_MESSAGE_MAP()
- /////////////////////////////////////////////////////////////////////////////
- // CNewItemDlg message handlers
- BOOL CNewItemDlg::OnInitDialog()
- {
- //SAMPLE: we'd better have an associated tree control!
- // ASSERT(m_pTreeCtrl != NULL);
- CDialog::OnInitDialog();
- //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!
- //SAMPLE: we set focus for ourselves, so return FALSE
- pEdit->SetFocus();
- m_btOk.LoadAVI(IDR_AVI_OK);
- m_btCancel.LoadAVI(IDR_AVI_CANCEL);
- UpdateData(FALSE);
- return TRUE;
- }
- void CNewItemDlg::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 CNewItemDlg::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();
- }