标签:
树控件对应的类:
CTreeControl
添加树节点:
1 HTREEITEM hRootNode = m_tvwTree.InsertItem(_T("人")); 2 HTREEITEM hNode = m_tvwTree.InsertItem(_T("老人"), hRootNode, TVI_LAST); 3 HTREEITEM hChildNode = m_tvwTree.InsertItem(_T("男人"), hNode, TVI_LAST);
NM_CLICK消息处理函数:
1 void CTestTreecontrolDlg::OnNMClickTree1(NMHDR *pNMHDR, LRESULT *pResult) 2 { 3 CPoint PT; 4 ::GetCursorPos(&PT); 5 ::ScreenToClient(pNMHDR->hwndFrom, &PT); 6 7 UINT uFlags; 8 HTREEITEM hSelectedItem = m_tvwTree.HitTest(PT, &uFlags); 9 if(NULL == hSelectedItem) 10 { 11 return; 12 } 13 14 if(uFlags & TVHT_ONITEM) 15 { 16 CString str = m_tvwTree.GetItemText(hSelectedItem); 17 AfxMessageBox(str); 18 } 19 20 *pResult = 0; 21 }
TVN_SELCHANGED消息处理函数:
1 void CTestTreecontrolDlg::OnTvnSelchangedTree1(NMHDR *pNMHDR, LRESULT *pResult) 2 { 3 LPNMTREEVIEW pNMTreeView = reinterpret_cast<LPNMTREEVIEW>(pNMHDR); 4 5 HTREEITEM hSelectedItem = m_tvwTree.GetSelectedItem(); 6 if(NULL == hSelectedItem) 7 { 8 return; 9 } 10 11 CString str = m_tvwTree.GetItemText(hSelectedItem); 12 if(str.IsEmpty()) 13 { 14 return; 15 } 16 17 AfxMessageBox(str); 18 19 *pResult = 0; 20 }
标签:
原文地址:http://www.cnblogs.com/believe9-9/p/4878918.html