Solved

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

Posted on 2003-12-11
2
5,046 Views
Last Modified: 2013-11-20
Hi,
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:
ON_NOTIFY(NM_CLICK, IDC_MY_TREE_CTRL, OnClickMyTreeCtrl)


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:
mMyTreeCtrl.GetSelectedItem()
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?

Thanks!
0
Comment
Question by:benhere
2 Comments
 
LVL 9

Accepted Solution

by:
Priyesh earned 250 total points
ID: 9925532
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)) ;
      }
}
0
 
LVL 2

Author Comment

by:benhere
ID: 9929292
Works fine, thanks a lot! :-)
0

Featured Post

Live: Real-Time Solutions, Start Here

Receive instant 1:1 support from technology experts, using our real-time conversation and whiteboard interface. Your first 5 minutes are always free.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
Windows Drag & Drop Location 2 100
Expand LInux Boot partition remotly 3 90
Replacement selected text 2 61
Execute multiple curl cmds with sleep and send output to file 10 97
Introduction: Displaying information on the statusbar.   Continuing from the third article about sudoku.   Open the project in visual studio. Status bar – let’s display the timestamp there.  We need to get the timestamp from the document s…
Introduction: Finishing the grid – keyboard support for arrow keys to manoeuvre, entering the numbers.  The PreTranslateMessage function is to be used to intercept and respond to keyboard events. Continuing from the fourth article about sudoku. …
This Micro Tutorial will teach you how to censor certain areas of your screen. The example in this video will show a little boy's face being blurred. This will be demonstrated using Adobe Premiere Pro CS6.
This video will show you how to get GIT to work in Eclipse.   It will walk you through how to install the EGit plugin in eclipse and how to checkout an existing repository.

815 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

9 Experts available now in Live!

Get 1:1 Help Now