Solved

CMenu

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

Accepted Solution

by:
Zoppo earned 20 total points
Comment Utility
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
Comment Utility
Thanks, Zoppo
0

Featured Post

Do You Know the 4 Main Threat Actor Types?

Do you know the main threat actor types? Most attackers fall into one of four categories, each with their own favored tactics, techniques, and procedures.

Join & Write a Comment

Suggested Solutions

Introduction: Finishing the grid – keyboard support for arrow keys to manoeuvre, entering the numbers.  The PreTranslateMessage function is to be used to intercept and respond to keyboard events. Continuing from the fourth article about sudoku. …
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.
Access reports are powerful and flexible. Learn how to create a query and then a grouped report using the wizard. Modify the report design after the wizard is done to make it look better. There will be another video to explain how to put the final p…

762 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

Need Help in Real-Time?

Connect with top rated Experts

6 Experts available now in Live!

Get 1:1 Help Now