?
Solved

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

Posted on 2003-12-11
2
Medium Priority
?
5,357 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
2 Comments
 
LVL 9

Accepted Solution

by:
Priyesh earned 1000 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

Get proactive database performance tuning online

At Percona’s web store you can order full Percona Database Performance Audit in minutes. Find out the health of your database, and how to improve it. Pay online with a credit card. Improve your database performance now!

Question has a verified solution.

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

Introduction: Ownerdraw of the grid button.  A singleton class implentation and usage. Continuing from the fifth article about sudoku.   Open the project in visual studio. Go to the class view – CGridButton should be visible as a class.  R…
Ready to get certified? Check out some courses that help you prepare for third-party exams.
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.
In this video, Percona Solutions Engineer Barrett Chambers discusses some of the basic syntax differences between MySQL and MongoDB. To learn more check out our webinar on MongoDB administration for MySQL DBA: https://www.percona.com/resources/we…
Suggested Courses

764 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