m_ImageList.Create(24,24,ILC_COLOR24|ILC_MASK,1,1); m_ImageList.Add(LoadIcon(AfxGetResourceHandle(),MAKEINTRESOURCE(IDI_ICON1))); m_ImageList.Add(LoadIcon(AfxGetResourceHandle(),MAKEINTRESOURCE(IDI_ICON2))); m_ImageList.Add(LoadIcon(AfxGetResourceHandle(),MAKEINTRESOURCE(IDI_ICON3))); m_ImageList.Add(LoadIcon(AfxGetResourceHandle(),MAKEINTRESOURCE(IDI_ICON4))); m_OrgInfo.SetImageList(&m_ImageList,TVSIL_NORMAL); HTREEITEM hProvince = m_OrgInfo.InsertItem("shanghai",0,0); HTREEITEM hTown = m_OrgInfo.InsertItem("huangshan",1,1,hProvince); m_OrgInfo.InsertItem("hangzhou",1,1,hProvince); m_OrgInfo.InsertItem("beijing",1,1,hProvince); m_OrgInfo.InsertItem("日本",2,2,hTown); m_OrgInfo.InsertItem("美国",2,2,hTown); void CEx85DesZoneDlg::IterateTree(HTREEITEM hItem) { if (hItem!=NULL) { if (m_OrgInfo.GetCheck(hItem)) { m_SelItemList.Add(hItem); } HTREEITEM hSibling = m_OrgInfo.GetNextItem(hItem,TVGN_NEXT); while (hSibling) { if (m_OrgInfo.GetCheck(hSibling)) { m_SelItemList.Add(hSibling); } HTREEITEM hSibChild = m_OrgInfo.GetChildItem(hSibling); if (hSibChild) { IterateTree(hSibChild); } hSibling = m_OrgInfo.GetNextItem(hSibling,TVGN_NEXT); } HTREEITEM hChild = m_OrgInfo.GetChildItem(hItem); if (hChild!=hItem) { IterateTree(hChild); } } } void CEx85DesZoneDlg::OnBnClickedOk() { // TODO: 在此添加控件通知处理程序代码 //OnOK(); m_SelItemList.RemoveAll(); m_SelList.ResetContent(); HTREEITEM hRoot = m_OrgInfo.GetRootItem(); IterateTree(hRoot); int nCount = m_SelItemList.GetSize(); HTREEITEM hItem = NULL; CString szItemText = ""; for (int i = 0;i<nCount;i++) { hItem = m_SelItemList.GetAt(i); if (hItem!=NULL) { szItemText = m_OrgInfo.GetItemText(hItem); m_SelList.AddString(szItemText); } } }