Solved

CMenu

Posted on 2000-03-09
2
527 Views
Last Modified: 2013-11-20
Hi,

I want to show popup menu in my program (when user click right mouse button). I do this by followin way:

void CTESTDlg::OnRButtonDown(UINT nFlags, CPoint point) {
      CDialog::OnRButtonDown(nFlags, point);
 
  CMenu *PopupMenu;

  PopupMenu = new CMenu;
  PopupMenu->CreatePopupMenu();
  PopupMenu->AppendMenu(MF_STRING, 1, "Test1");
  PopupMenu->AppendMenu(MF_STRING, 2, "Test2");
  PopupMenu->AppendMenu(MF_STRING, 3, "Test3");
  PopupMenu->AppendMenu(MF_STRING, 4, "Test4");
  PopupMenu->AppendMenu(MF_STRING, 5, "Test5");

  POINT DesktopPoint;
  DesktopPoint.x = point.x;
  DesktopPoint.y = point.y;
  ClientToScreen(&DesktopPoint);
 
  BOOL bResponse = PopupMenu->TrackPopupMenu(TPM_LEFTALIGN, DesktopPoint.x, DesktopPoint.y, this);
}

How can I get selected item ID (witch element user select in popmenu) after PopupMenu->TrackPopupMenu()?

regards,
  mahno
0
Comment
Question by:mahno
2 Comments
 
LVL 31

Accepted Solution

by:
Zoppo earned 20 total points
ID: 2600543
Hi mahno,

by default you do not get the selected id but the framework sends to your application a WM_COMMAND message with the menu identifier in the same manner as frame window menu does. So, you can simply add a command message handler and a update command message handler using ClassWizard.

The other possibility is to pass the TrackPopupMenu the TPM_RETURNCMD flag. This causes the TrackPopupMenu function to wait until a item is selected or the menu is canceled. The return value is the id. I.e.:


UINT mId = PopupMenu->TrackPopupMenu(TPM_RETURNCMD|TPM_LEFTALIGN, DesktopPoint.x, DesktopPoint.y, this);
if ( mId == 0 )
{
 // canceled or error
}

BTW, I'm not really sure if the TPM_RETURNCMD flag is fully supported by CMenu::TrackPopupMenu(), but I know it is with ::TrackPopupMenu()...

hope that helps,

ZOPPO
0
 
LVL 1

Author Comment

by:mahno
ID: 2600643
Thanks, Zoppo
0

Featured Post

Independent Software Vendors: 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
Doc'in system (example?) BA 7 120
only14 challenge 19 84
FizzBuzz challenge 9 86
mapBully challenge 6 179
Introduction: Load and Save to file, Document-View interaction inside the SDI. Continuing from the second article about sudoku.   Open the project in visual studio. From the class view select CSudokuDoc and double click to open the header …
Introduction: Database storage, where is the exe actually on the disc? Playing a game selected randomly (how to generate random numbers).  Error trapping with try..catch to help the code run even if something goes wrong. Continuing from the seve…
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.

696 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