添加子节点
1 switch(nCurDate) 2 { 3 case 1: 4 m_showDetails.DeleteAllItems( ); 5 hRoot = m_showDetails.InsertItem( "A区", TVI_ROOT); 6 hfirstChild = m_showDetails.InsertItem("宿舍楼",hRoot); 7 8 hsecondChild = m_showDetails.InsertItem("1楼",hfirstChild); 9 hsecondChild = m_showDetails.InsertItem("2楼",hfirstChild); 10 hsecondChild = m_showDetails.InsertItem("3楼",hfirstChild); 11 12 hfirstChild = m_showDetails.InsertItem("教学楼",hRoot,hfirstChild); 13 14 hsecondChild = m_showDetails.InsertItem("阶梯教室",hfirstChild); 15 hsecondChild = m_showDetails.InsertItem("实验室",hfirstChild); 16 ShowAllNode(hRoot,m_showDetails); 17 break; 18 case 2: 19 m_showDetails.DeleteAllItems( ); 20 hRoot = m_showDetails.InsertItem( "B区", TVI_ROOT); 21 hfirstChild = m_showDetails.InsertItem("科技楼",hRoot); 22 23 hsecondChild = m_showDetails.InsertItem("1楼",hfirstChild); 24 hsecondChild = m_showDetails.InsertItem("2楼",hfirstChild); 25 hsecondChild = m_showDetails.InsertItem("3楼",hfirstChild); 26 27 hfirstChild = m_showDetails.InsertItem("信息楼",hRoot,hfirstChild); 28 29 hsecondChild = m_showDetails.InsertItem("1号机房",hfirstChild); 30 hsecondChild = m_showDetails.InsertItem("2号机房",hfirstChild); 31 hsecondChild = m_showDetails.InsertItem("3号机房",hfirstChild); 32 33 ShowAllNode(hRoot,m_showDetails); 34 break; 35 }
递归展示所有节点
1 void CdemoDlg::ShowAllNode(HTREEITEM hItem, CTreeCtrl& m_treeShow) 2 { 3 HTREEITEM hChild = m_treeShow.GetChildItem(hItem); 4 while(hChild) 5 { 6 m_treeShow.Expand(hItem,TVE_EXPAND); 7 ShowAllNode(hChild,m_treeShow); 8 hChild = m_treeShow.GetNextSiblingItem(hChild); 9 } 10 }