[Last Call] Learn about multicloud storage options and how to improve your company's cloud strategy. Register Now

x
?
Solved

CMenu

Posted on 2000-03-09
2
Medium Priority
?
536 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 80 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: 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 …
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.
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, Percona Solution Engineer Rick Golba discuss how (and why) you implement high availability in a database environment. To discuss how Percona Consulting can help with your design and architecture needs for your database and infrastr…

656 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