VOID CScale3DCUserManageView::InitTree() { TVINSERTSTRUCT tvInsert; tvInsert.hParent = NULL; tvInsert.hInsertAfter = NULL; tvInsert.item.mask = TVIF_TEXT; tvInsert.item.pszText = _T("全部用户"); m_treeRoot = m_TreeUser.InsertItem(&tvInsert); //添加根节点 tvInsert.hParent = m_treeRoot; tvInsert.hInsertAfter = TVI_LAST; tvInsert.item.mask = TVIF_TEXT; tvInsert.item.pszText = _T("超级管理员"); m_itemSuperUser = m_TreeUser.InsertItem(&tvInsert); m_TreeUser.SetItemData(m_itemSuperUser, 0);//超级管理员节点 tvInsert.hParent = m_treeRoot; tvInsert.hInsertAfter = TVI_LAST; tvInsert.item.mask = TVIF_TEXT; tvInsert.item.pszText = _T("管理员"); m_itemAmdin = m_TreeUser.InsertItem(&tvInsert); m_TreeUser.SetItemData(m_itemAmdin, 0);//管理员节点 tvInsert.hParent = m_treeRoot; tvInsert.hInsertAfter = TVI_LAST; tvInsert.item.mask = TVIF_TEXT; tvInsert.item.pszText = _T("普通用户"); m_itemUser = m_TreeUser.InsertItem(&tvInsert); m_TreeUser.SetItemData(m_itemUser, 0);//超级管理员节点 }
点击树控件节点,获取节点信息
void CScale3DCUserManageView::OnNMClickTree1(NMHDR *pNMHDR, LRESULT *pResult) { // TODO: 在此添加控件通知处理程序代码 CPoint pt; UINT nFlags; GetCursorPos(&pt); ::ScreenToClient(m_TreeUser.m_hWnd, &pt); HTREEITEM hItemSelect = m_TreeUser.HitTest(pt, &nFlags); CString sMsg= m_TreeUser.GetItemText(hItemSelect); INT nData = m_TreeUser.GetItemData(hItemSelect); if (1 == nData) { for (INT i=0;i<m_stAllUserInfo.size();i++) { if (sMsg == m_stAllUserInfo[i].szName) { m_EditUserName.SetWindowText(sMsg); m_editPassword1.SetWindowText(m_stAllUserInfo[i].szPassWord); m_editPassword2.SetWindowText(m_stAllUserInfo[i].szPassWord); m_comLimits.SetCurSel(m_stAllUserInfo[i].nIdentity-1); } } } if (hItemSelect != NULL) { if (m_TreeUser.ItemHasChildren(hItemSelect)) { m_TreeUser.Expand(hItemSelect, TVE_EXPAND); } } *pResult = 0; }
原文地址:http://blog.51cto.com/9233403/2093764