CTreeCtrl: How to cath the Mouse Click on an item?

I am trying to catch the Mouse Click event on a node item of a CTreeCtrl, but I have trouble getting the HTREEITEM refering to the node item that has been clicked.

I mapped the following message:

And have the following function:
void CMyDialog::OnClickMyTreeCtrl(NMHDR* pNMHDR, LRESULT* pResult)
   HTREEITEM lNodeItem = ((NM_TREEVIEW*)pNMHDR)->itemNew.hItem;
   *pResult = 0;

But lNodeItem is always NULL.
And if I try this:
It is the item that was previously selected before the click event.

Any ideas on how I could get the HTREEITEM when a node item is clicked?

Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

Check if this works

void CMyDialog::OnClickMyTreeCtrl(NMHDR* pNMHDR, LRESULT* pResult)
      CPoint pt ;
      GetCursorPos(&pt) ;
      m_Tree.ScreenToClient(&pt) ;

      UINT unFlags = 0 ;
      HTREEITEM hItem = m_Tree.HitTest(pt, &unFlags) ;
      if((unFlags & TVHT_ONITEMLABEL) && hItem != NULL)
            TRACE("%s\n", m_Tree.GetItemText(hItem)) ;

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
benhereAuthor Commented:
Works fine, thanks a lot! :-)
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
System Programming

From novice to tech pro — start learning today.