Solved

CTreeCtrl right click selected item update

Posted on 2003-11-15
2
795 Views
Last Modified: 2013-11-20
This one has been driving me crazy.  I want to allow a user to perform actions on objects in a CTreeCtrl.  The problem is the SelectedItem of a CTreeCtrl does not update when just the right mouse button is clicked on an item.  I need it to so the user obtains the object they right click on to bring the context menu up.  To do this in the function NM_RCLICK is mapped to I get the cursor point, then after creating the popup MapWindowPoints to the CTreeCtrl and then run HitTest to find the object that the cursor is suposedly over.  It doesn't work.  It chooses an object 5 below the one the cursor is on.  Any ideas why this is or another way to get the current highlighted object (checking for TVIS_SELECTED doesn't work.  I tried that first).  Here is my current code:
    HTREEITEM hItem;

      CPoint point;

    CMenu mnuTop;


    GetCursorPos(&point);

    mnuTop.LoadMenu(IDR_BATCHES_POPUP);

    CMenu* pPopup = mnuTop.GetSubMenu(0);
    ASSERT_VALID(pPopup);
   
    pPopup->TrackPopupMenu(TPM_LEFTBUTTON | TPM_RIGHTBUTTON |
                           TPM_LEFTALIGN, point.x, point.y, AfxGetMainWnd(), NULL);

    *pResult = 0;

      //Set item right clicked on as selected
      this->MapWindowPoints(FromHandle(m_BatchTree.m_hWnd), &point, 1);
      hItem = m_BatchTree.HitTest(point);
      if(hItem) m_BatchTree.SelectItem(hItem);

Thanks.
0
Comment
Question by:stringsandbeyond
[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 48

Accepted Solution

by:
AlexFM earned 50 total points
ID: 9757666
This is code fragment from my project, it works:

    POINT point;
    POINT pt_screen;

    if ( ! GetCursorPos(&point) )
        return;

    pt_screen = point;                      // keep screen point (we need it to show menu)
    m_tree_control.ScreenToClient(&point);  // convert to tree control coordinates

    HTREEITEM hItem = m_tree_control.HitTest(point); // what item is under this point

    if ( ! hItem )
        return;

   ...
0
 

Author Comment

by:stringsandbeyond
ID: 9757767
Thanks.

I had assumed GetCursorPos() was returning client coords of the class it was called from.  It seems it returns screen coords.  Thanks.
0

Featured Post

Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
ODBC Connection Logging, ADO.NET 6 73
if loop in java 3 174
Doc'in system (example?) BA 7 127
listing all the respondents to a twitter feed - Java 5 46
Exception Handling is in the core of any application that is able to dignify its name. In this article, I'll guide you through the process of writing a DRY (Don't Repeat Yourself) Exception Handling mechanism, using Aspect Oriented Programming.
Have you tried to learn about Unicode, UTF-8, and multibyte text encoding and all the articles are just too "academic" or too technical? This article aims to make the whole topic easy for just about anyone to understand.
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.
This video shows how to use Hyena, from SystemTools Software, to update 100 user accounts from an external text file. View in 1080p for best video quality.
Suggested Courses

734 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