My problem is that the following function is called twice:
ON_NOTIFY(TVN_SELCHANGED, IDC_TREE1, &MainHamsterDlg::OnClickTree)
void MainHamsterDlg::OnClickTree(NMHDR* pNMHDR, LRESULT* pResult)
{
CTreeCtrl* pCtrl = (CTreeCtrl*)GetDlgItem(IDC_TREE1);
HTREEITEM hItem = pCtrl->GetSelectedItem();
BOOL hItemm = pCtrl->ItemHasChildren(hItem);
if (hItem && hItemm)
{
HTREEITEM hChild = pCtrl->GetChildItem(hItem);
pCtrl->SelectItem(hChild); <--- Cause of the "loop"
}
*pResult = 1;
}
I need my code to automatically go to a child element of the tree. (In future I will write some code to detect what has been selected and it will cause some actions.)
My code works correctly when I click on a leaf, because:
if (hItem && hItemm)
ensures that:
pCtrl->SelectItem(hChild);
won't be executed. How can I make my code work when an internal node is clicked?