Click here to Skip to main content
15,889,651 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
I have one tree control on my dialog i want to show the checked item
see we can select multiple checkboxes i want to show last checked item

What I have tried:

void CTreeSetControlDlg::OnNMClickTreereletion(NMHDR *pNMHDR, LRESULT *pResult)
{
	// TODO: Add your control notification handler code here
	// Select the item that is at the point myPoint.
	static int i=0;
	CString m;
	HTREEITEM hItem=NULL;
	if(WM_LBUTTONDOWN)
	{
		hItem=m_treeRel.GetSelectedItem();
		m=m_treeRel.GetItemText(hItem);
		//m.Format(_T("Captured...%d"),i);
		ShowMessage(m);
		i++;
	}

	*pResult = 0;
}
Posted
Updated 6-Feb-17 21:01pm

1 solution

You are handling the NM_CLICK notification which is send when clicking the left button within the tree control. So there is no need to check if the left button is down.

But when this message is handled by your code, the default handling has not yet been called so that the clicked item is not yet selected.

To get the clicked item you can use something like
UINT uFlags = 0;
CPoint pt(0, 0);
GetCursorPos(&pt);
m_treeRel.ScreenToClient(&pt);
HTREEITEM hItem = m_treeRel.HitTest(pt, &uFlags);
if(NULL != hItem && (TVHT_ONITEM  & uFlags))
{
    // Do something with clicked item
}

It is not quite clear what you finally want to achieve. But there are often multiple notifications and messages that might be used for specific tasks. So you should also have a look at these. A candidate might be the TVN_SELCHANGING notification code (Windows)[^].
 
Share this answer
 
Comments
Premnath Mali 7-Feb-17 4:00am    
actually i'm working on checkbox so with this solution i'm getting clicked item
but if i unchecked the item still its returning the same item

but its fine i got actually what i want thankssssssssssssssssssssssss for it!!!!
Jochen Arndt 7-Feb-17 4:31am    
Fine to hear that you solved it and thank you for aceppting the answer.

To check if clicked on the check box test for the TVHT_ONITEMSTATEICON flag.
The current check box state can be determined as usual with GetCheck(hItem) but note that your handler is called before the state is updated (checked: will be unchecked; uncheked: will be checked).
Premnath Mali 10-Feb-17 7:26am    
Thanks for this also....!!!
This is also helpful for me...!

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900