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
Solved

CMenu

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

Announcing the Most Valuable Experts of 2016

MVEs are more concerned with the satisfaction of those they help than with the considerable points they can earn. They are the types of people you feel privileged to call colleagues. Join us in honoring this amazing group of Experts.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

In this article, I'll describe -- and show pictures of -- some of the significant additions that have been made available to programmers in the MFC Feature Pack for Visual C++ 2008.  These same feature are in the MFC libraries that come with Visual …
Introduction: Ownerdraw of the grid button.  A singleton class implentation and usage. Continuing from the fifth article about sudoku.   Open the project in visual studio. Go to the class view – CGridButton should be visible as a class.  R…
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.
Although Jacob Bernoulli (1654-1705) has been credited as the creator of "Binomial Distribution Table", Gottfried Leibniz (1646-1716) did his dissertation on the subject in 1666; Leibniz you may recall is the co-inventor of "Calculus" and beat Isaac…

791 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