Solved

CMenu

Posted on 2000-03-09
2
529 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
[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 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

Free Tool: Subnet Calculator

The subnet calculator helps you design networks by taking an IP address and network mask and returning information such as network, broadcast address, and host range.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

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.
In this video we outline the Physical Segments view of NetCrunch network monitor. By following this brief how-to video, you will be able to learn how NetCrunch visualizes your network, how granular is the information collected, as well as where to f…

724 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