CTreeCtrl check state
-
I have a CTreeCtrl with check boxes on a dialog that I need to detect when the check box has been checked/unchecked. I am currently using the following code in the OnClick event handler, but it always gives TVHT_NOWHERE: UINT uFlags = 0; CPoint point = GetCurrentMessage()->pt; ScreenToClient( &point ); HTREEITEM hItem = m_ctrlDrivers.HitTest( point, &uFlags ); if( uFlags & TVHT_ONITEMSTATEICON ) // Check box has been clicked Anyone know where I'm going wrong?
-
I have a CTreeCtrl with check boxes on a dialog that I need to detect when the check box has been checked/unchecked. I am currently using the following code in the OnClick event handler, but it always gives TVHT_NOWHERE: UINT uFlags = 0; CPoint point = GetCurrentMessage()->pt; ScreenToClient( &point ); HTREEITEM hItem = m_ctrlDrivers.HitTest( point, &uFlags ); if( uFlags & TVHT_ONITEMSTATEICON ) // Check box has been clicked Anyone know where I'm going wrong?
A suggestion. Try to use the "ptDrag" member of the NM_TREEVIEW structure instead of GetCurrentMessage()->pt. There is no need to convert ptDrag to client coordinates, because it is already in client coords. If this doesn't work, using the OnLButtonDown handler instead of OnClick is a second chance. HTH Holger Persch
-
A suggestion. Try to use the "ptDrag" member of the NM_TREEVIEW structure instead of GetCurrentMessage()->pt. There is no need to convert ptDrag to client coordinates, because it is already in client coords. If this doesn't work, using the OnLButtonDown handler instead of OnClick is a second chance. HTH Holger Persch
Hi Holger, Thanks for your help. I've tried your first suggestion. This only gives me TVHT_BELOW from the HitTest. As for your second suggestion, the OnLButtonDown event handler for the dialog does not get triggered when the tree control is clicked on :o( Derek.
-
I have a CTreeCtrl with check boxes on a dialog that I need to detect when the check box has been checked/unchecked. I am currently using the following code in the OnClick event handler, but it always gives TVHT_NOWHERE: UINT uFlags = 0; CPoint point = GetCurrentMessage()->pt; ScreenToClient( &point ); HTREEITEM hItem = m_ctrlDrivers.HitTest( point, &uFlags ); if( uFlags & TVHT_ONITEMSTATEICON ) // Check box has been clicked Anyone know where I'm going wrong?
I've solved the problem. The ScreenToClient call needs to be done on the control to convert the point to control coordinates, hence: UINT uFlags = 0; CPoint point = GetCurrentMessage()->pt; m_ctrlDrivers.ScreenToClient( &point ); HTREEITEM hItem = m_ctrlDrivers.HitTest( point, &uFlags ); if( uFlags & TVHT_ONITEMSTATEICON ) // Check box has been clicked Thanks for your help. Derek.