Want to win a PS4? Go Premium and enter to win our High-Tech Treats giveaway. Enter to Win

x
?
Solved

Popup menu inside TreeView problem

Posted on 2003-10-22
2
Medium Priority
?
941 Views
Last Modified: 2013-11-20
Hi.
I want to create a popup menu on a right cick in a tree view.
The popup should be different if the click was on an item or not.
My problem is that the popup created upon clicking not on an item isn't
shown in the right place (next to mouse cursor) but a bit far from it.

My code follows :

void CLeftView::OnNMRclick(NMHDR *pNMHDR, LRESULT *pResult)
{
    CMenu mPopups, *pFloatingPopup = NULL;
    mPopups.LoadMenu(IDR_POPUPS);
    CPoint pos;
    GetCursorPos(&pos);
    GetTreeCtrl().ScreenToClient(&pos);
    UINT uFlags;
    HTREEITEM hItem = GetTreeCtrl().HitTest(pos, &uFlags);

    if (hItem != NULL && (uFlags & TVHT_ONITEM) != 0)
    {
        GetTreeCtrl().SelectItem(hItem);
        pFloatingPopup = mPopups.GetSubMenu(0);
    }
    else // not on item
        pFloatingPopup = mPopups.GetSubMenu(1);


    pFloatingPopup->TrackPopupMenu(TPM_LEFTALIGN |TPM_RIGHTBUTTON, pos.x,
pos.y, AfxGetMainWnd());

    *pResult = 0;
}

Any ideas as to why that happens and a fix ?

0
Comment
Question by:dkremer
[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 200 total points
ID: 9599654
TrackPopupMenu x, y parameters are screen coordinates and you already converted pos to client coordinates.

void CLeftView::OnNMRclick(NMHDR *pNMHDR, LRESULT *pResult)
{
   CMenu mPopups, *pFloatingPopup = NULL;
   mPopups.LoadMenu(IDR_POPUPS);
   CPoint pos, pos1;
   GetCursorPos(&pos);
   pos1 = pos;
   GetTreeCtrl().ScreenToClient(&pos);
   UINT uFlags;
   HTREEITEM hItem = GetTreeCtrl().HitTest(pos, &uFlags);

   if (hItem != NULL && (uFlags & TVHT_ONITEM) != 0)
   {
       GetTreeCtrl().SelectItem(hItem);
       pFloatingPopup = mPopups.GetSubMenu(0);
   }
   else // not on item
       pFloatingPopup = mPopups.GetSubMenu(1);


   pFloatingPopup->TrackPopupMenu(TPM_LEFTALIGN |TPM_RIGHTBUTTON, pos1.x,
pos1.y, AfxGetMainWnd());

   *pResult = 0;
}
0
 
LVL 1

Author Comment

by:dkremer
ID: 9604914
My bad.
Don't need to switch from screen to client since TrackPopupMenu takes screen coordinates.
0

Featured Post

Keep up with what's happening at Experts Exchange!

Sign up to receive Decoded, a new monthly digest with product updates, feature release info, continuing education opportunities, and more.

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…
If you use Adobe Reader X it is possible you can't open OLE PDF documents in the standard. The reason is the 'save box mode' in adobe reader X. Many people think the protected Mode of adobe reader x is only to stop the write access. But this fe…
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 lesson discusses how to use a Mainform + Subforms in Microsoft Access to find and enter data for payments on orders. The sample data comes from a custom shop that builds and sells movable storage structures that are delivered to your property. …
Suggested Courses

610 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