MFC Tree Control: How to detect which part of an item the user clicked on?
CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 1 of 1

Thread: MFC Tree Control: How to detect which part of an item the user clicked on?

Hybrid View

  1. #1
    Join Date
    Jun 2001
    Location
    Switzerland
    Posts
    4,443

    MFC Tree Control: How to detect which part of an item the user clicked on?

    Q: How to detect which part of an item the user clicked on?

    A: It does not matter whether we're talking about a left click, a right click or just hoovering with the mouse. IOW, the message you handle is irrelevant - the method of detecting what exactly is under the cursor is the same:

    Code:
    void CYourDialog::OnClickTree(NMHDR* pNMHDR, LRESULT* pResult) 
    {
      CPoint    point;
      UINT      uFlags;
      HTREEITEM hItem;
    
      GetCursorPos(&point);   
      m_tree.ScreenToClient(&point);
      hItem = m_tree.HitTest(point, &uFlags);
      if(hItem)
      {
        // There is an item under the cursor.
        // See what exactly was under the cursor:
        switch(uFlags)
        {
          case TVHT_ONITEMSTATEICON:
            // It was the icon
            break;
    
          case TVHT_ONITEMBUTTON:
            // It was the button
            break;
    
          // ...and so on
        }
      }
    
      *pResult = 0;
    }
    Last edited by Andreas Masur; July 25th, 2005 at 04:52 PM.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  


Windows Mobile Development Center


Click Here to Expand Forum to Full Width

This is a CodeGuru survey question.


Featured


HTML5 Development Center