Solved

CTreeCtrl right click selected item update

Posted on 2003-11-15
2
799 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

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: 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: Dialogs (1) modal - maintaining the database. Continuing from the ninth article about sudoku.   You might have heard of modal and modeless dialogs.  Here with this Sudoku application will we use one of each type: a modal dialog …
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.
Visualize your data even better in Access queries. Given a date and a value, this lesson shows how to compare that value with the previous value, calculate the difference, and display a circle if the value is the same, an up triangle if it increased…

622 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