Click here to Skip to main content
15,896,207 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
I have this piece of code

C++
ON_NOTIFY(NM_CLICK ,ID_TREENOTES, OnClickTree)

void CShortcutPaneConfServer::OnClickTree(NMHDR* pNMHDR, LRESULT* pResult ) {
	CPoint pt;
     GetCursorPos( &pt );
     m_wndTreeNotes.ScreenToClient( &pt ) ;
	
	UINT nFlags = 0;
     HTREEITEM hItem = m_wndTreeNotes.HitTest( pt, &nFlags ) ;
     if( hItem == NULL  ||  !(nFlags & (TVHT_ONITEMLABEL|TVHT_ONITEMICON)) )
		return;

Unfortunately hItem is always NULL, even if I click on an Item... what's missing?

PS: Im in a mdichildframe, it could affect in some way cursor coordinates see screentoclient?
Posted
Updated 28-Feb-12 1:12am
v2
Comments
Schehaider_Aymen 28-Feb-12 7:20am    
is it a MFC CTreeView based or CFormView with a CtreeCtr ??

1 solution

I think that you missed The Mouse location into your TreeCtrl, try as below :

C++
void CShortcutPaneConfServer::OnClickTree(NMHDR* pNMHDR, LRESULT* pResult ) {
// TODO: Add your control notification handler code here
*pResult = 0;

    CPoint Point;
    //retrieve the mouse position (missed in yout code)
         DWORD dwPos;
         dwPos = GetMessagePos(); 
         Point.x = LOWORD (dwPos);
         Point.y = HIWORD (dwPos); 


m_wndTreeNotes.ScreenToClient( &Point );
 UINT Flags = TVHT_ONITEMLABEL;
HTREEITEM ht = m_wndTreeNotes.HitTest( Point ,&Flags );
if( ht== NULL  ||  !(Flags & (TVHT_ONITEMLABEL|TVHT_ONITEMICON)) )
return;

}
 
Share this answer
 
v3
Comments
druscelli 28-Feb-12 8:02am    
in my code there is GetCursorPos( &pt ); on the top I checked it works... I can see the coordinates on it...
Schehaider_Aymen 28-Feb-12 8:16am    
Did u check if the code i gave works for u ?? Any further problem ?

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