CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 7 of 7
  1. #1
    Join Date
    Jun 1999
    Posts
    1

    CTreeCtrl and RButtonUp

    In my TreeView control...

    I used ClassWizard to connect the WM_RBUTTONUP to the Member function OnRButtonUp. The problem with this is that it only occurs when I double right click OR when I move the cursor while the right mouse button is down. I want to add a popup menu where I right-clicked and get the hItem that was clicked.

    Any help would be appreciated,

    WDW


  2. #2
    Join Date
    Jul 2010
    Posts
    1

    Resolved Re: CTreeCtrl and RButtonUp

    This appears to happen when you only implement a message handler for WM_RBUTTONUP. Try processing both WM_RBUTTONDOWN and WM_RBUTTONUP and your method will be invoked when the user single clicks with the right mouse button on a tree item.

  3. #3
    Join Date
    Jun 2010
    Location
    Germany
    Posts
    2,675

    Re: CTreeCtrl and RButtonUp

    Good intent, but the post you are replying to is a little more than 11 years old, and the guy who wrote it didn't ever post again since then. I'm pretty sure he won't read that.

    You should better answer a more recent question next time.

    But anyway, welcome to CodeGuru!
    Last edited by Eri523; January 1st, 2012 at 06:31 PM.

  4. #4
    Join Date
    Jan 2009
    Posts
    28

    Re: CTreeCtrl and RButtonUp

    Heh,

    I apologize for once again resurrecting an old thread. This page actually comes up with a high search engine ranking when you search for CTreeCtrl not recieving the WM_RBUTTONUP message.

    Since the information here is incorrect lets fix that so the next guy gets good information.

    The CTreeCtrl has what I could consider a design flaw in that it internally processes the WM_RBUTTONDOWN and WM_RBUTTONUP messages. If your wondering where your WM_RBUTTONUP went... it was consumed by the CTreeCtrl class... and in its place... a WM_NOTIFY containing a NM_RCLICK was sent to the parent window followed by a WM_CONTEXTMENU message to the parent window.

    So... if you want to handle WM_RBUTTONUP in a CTreeCtrl derived class... you will need to add a ON_NOTIFY_REFLECT handler for the NM_RCLICK message and then sendmessage the WM_CONTEXTMENU to your own window handle.

    Best Wishes,
    -David Delaune

  5. #5
    Arjay's Avatar
    Arjay is offline Moderator / EX MS MVP Power Poster
    Join Date
    Aug 2004
    Posts
    13,490

    Re: CTreeCtrl and RButtonUp

    To display a context menu, just handle the WM_CONTEXTMENU msg.

  6. #6
    Join Date
    Jan 2009
    Posts
    28

    Re: CTreeCtrl and RButtonUp

    Quote Originally Posted by Arjay View Post
    To display a context menu, just handle the WM_CONTEXTMENU msg.
    Hi Arjay,

    Unfortunately a CTreeCtrl derived class will never recieve a WM_CONTEXTMENU message in response to a right click. If you want to display a context menu when the user right clicks in your CTreeCtrl derived class you will need to add a ON_NOTIFY_REFLECT handler for the NM_RCLICK message and then sendmessage the WM_CONTEXTMENU manually.

    Best Wishes,
    -David Delaune

  7. #7
    Arjay's Avatar
    Arjay is offline Moderator / EX MS MVP Power Poster
    Join Date
    Aug 2004
    Posts
    13,490

    Re: CTreeCtrl and RButtonUp

    If the tree control is a derived class, yes you must reflect and use on notify (like when deriving all control clases); otherwise just handle the wm_contextmeu msg.

    The main point is to handle WM_CONTEXTMENU over the right button up/down messages.

Posting Permissions

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





Click Here to Expand Forum to Full Width

Featured