[RESOLVED] How to know CTreeCtrl Checked State has changed
I have a CTreeCtrl with checkboxes in a dialog that looks like this...
http://4dgraphics.net/ConfigToolbars.gif
I need to get notified when the checked state of an item in the tree control has changed.
ON_NOTIFY(NM_CLICK... Does not seem to provide any information about WHICH item was clicked...
ON_NOTIFY(TVN_SELCHANGED... Is only triggered when the item is selected which does not happen if the user clicks on the checkbox, only when the user clicks on the item text.
I have an app that catches WM_LBUTTONDOWN and is then able to determine if the click was on a checkbox using CTreeCtrl::HitTest but this app is using a CTreeView. I cannot figure out how to set up the handler for WM_LBUTTONDOWN on the CTreeCtrl (or even if it is possible at all).
Bottom line... I need to know when a CTreeCtrl item checked state has changed, and which item changed.
Please help!!! :confused:
Re: How to know CTreeCtrl Checked State has changed
Thanks to a post by clem in Oct 2000 I was able to get this figured out... :)
Code:
// Handler for ON_NOTIFY(NM_CLICK...
void CShowToolbars::OnClickToolbarTree(NMHDR* pNMHDR, LRESULT* pResult)
{
///////////////////////////////////////////////////////////////////////////////////////////
// DON'T bother using this...
NM_TREEVIEW* pNMTreeView = (NM_TREEVIEW*)pNMHDR;
///////////////////////////////////////////////////////////////////////////////////////////
// get the mouse position relative to the treectrl
CPoint ptMouse;
UINT uFlags;
GetCursorPos (&ptMouse);
m_ctrlToolbarTree.ScreenToClient(&ptMouse); //Mouse coords
// determine if this location is on a treectrl item
HTREEITEM hItem = m_ctrlToolbarTree.HitTest(ptMouse, &uFlags);
// action depends on whether the click was on the checkbox or the label
if ((hItem != NULL) && (TVHT_ONITEMSTATEICON & uFlags))
{
//click was on state icon
}
else if ((hItem != NULL) && (TVHT_ONITEMLABEL & uFlags))
{
//click was on label
}
*pResult = 0;
}