Date: 2017aug28
OS: Windows
Language: C++
Framework: MFC
Q. MFC: What does CTreeCtrl::GetChildItem() do?
A. It gets the *first* child of the input hItem.
You can not call it repeatedly to get the next child.
It should have been called GetFirstChildItem().
The comment in some versions of afxcmn.h is wrong. eg:
// Retrieves the next child item after the specified item. <-- wrong
HTREEITEM GetChildItem(_In_ HTREEITEM hItem) const;
To get remaining children you can repeatedly call GetNextItem(, TVGN_NEXT)
void ListAllChildren(CTreeCtrl &tree; HTREEITEM hItem) {
for (HTREEITEM hChild = tree.GetChildItem(hItem); hChild != NULL; hChild = tree.GetNextItem(hChild, TVGN_NEXT)) {
// Do something with hChild
}
}