void CDocSelectDlg::OnOK() { CTreeCtrl* pTree = (CTreeCtrl*)GetDlgItem(IDC_DOCLIST_TRE); HTREEITEM hItem = pTree->GetRootItem(); int i = 0; int nItemsDeleted = 0; while (hItem) { if (! pTree->GetCheck(hItem)) { m_aDocNames.RemoveAt(i - nItemsDeleted); nItemsDeleted++; i++; } hItem = pTree->GetNextSiblingItem(hItem); } CDialog::OnOK(); }
HTREEITEM CPanelBase::FindTree( CTreeCtrl &treeCtrl, const wstring &findText ) { HTREEITEM hRoot = treeCtrl.GetRootItem(); vector<HTREEITEM> items; items.reserve(treeCtrl.GetCount()); wstring lowerText = findText; lowerCasew(lowerText); items.push_back(hRoot); while (!items.empty()) { HTREEITEM hItem = items.back(); items.pop_back(); CString itemText = treeCtrl.GetItemText(hItem); CString lowerItemText = lowerCasew((wstring)itemText).c_str(); const int idx = lowerItemText.Find(lowerText.c_str()); if (idx >= 0) return hItem; HTREEITEM hfirstChild = treeCtrl.GetChildItem(hItem); if (hfirstChild) { items.push_back(hfirstChild); while (HTREEITEM hNextItem = treeCtrl.GetNextSiblingItem(hfirstChild)) { items.push_back(hNextItem); hfirstChild = hNextItem; } } } return NULL; }
HTREEITEM GetTreeItemFromData(CTreeCtrl& treeCtrl, DWORD dwData, HTREEITEM hStartAtItem /*=NULL*/) { // Traverse from given item (or all items if hFromItem is NULL) HTREEITEM hItem; if ( hStartAtItem ) hItem=hStartAtItem; else hItem = treeCtrl.GetRootItem(); while ( hItem ) { if ( dwData == (DWORD)treeCtrl.GetItemData( hItem ) ) return hItem; // Get first child node HTREEITEM hNextItem = treeCtrl.GetChildItem( hItem ); if ( !hNextItem ) { // Get next sibling child hNextItem = treeCtrl.GetNextSiblingItem( hItem ); if ( !hNextItem ) { HTREEITEM hParentItem=hItem; while ( !hNextItem && hParentItem ) { // No more children: Get next sibling to parent hParentItem = treeCtrl.GetParentItem( hParentItem ); hNextItem = treeCtrl.GetNextSiblingItem( hParentItem ); } } } hItem = hNextItem; } return NULL; }