Solved

Receiving events from a popup menu.

Posted on 2000-03-13
10
461 Views
Last Modified: 2013-12-03
Hi,

I have created a popup menu in my application, how do I receive events to inform the app that the user has selected an item in the menu.. I know that there are events such as WM_MENUSELECT and WM_MENUCOMMAND, but when I try to handle them, it says that WM_MENUCOMMAND etc.. is undefined...

thanks in advance

Emma
0
Comment
Question by:middlel
  • 3
  • 2
  • 2
  • +2
10 Comments
 
LVL 9

Expert Comment

by:ShaunWilde
ID: 2611735
are you using Trackpopupmenu? the WM_COMMAND messages should go to the window you gave as the HWnd parameter.
0
 

Author Comment

by:middlel
ID: 2611825
Yes I am using TraclPopupMenu(). I don't want to have to handle the WM_COMMAND message because I would then have to handle or forward on all the other messages that I want to handle... I would much rather be able to handle the menu specific messages...

0
 
LVL 22

Expert Comment

by:nietod
ID: 2611932
>> when I try to handle them, it says that
>> WM_MENUCOMMAND etc.. is undefined...
It IS undefined.  

WM_MENUSELECT is defined though.  What what it that you thought that WM_MENUCOMMAND was doing?

>> I don't want to have to handle the WM_COMMAND
>> message because I would then have to handle or
>> forward on all the other messages that I want to
>> handle.
I don't understand.

0
 
LVL 9

Expert Comment

by:ShaunWilde
ID: 2611953
ahh I see.

WM_MENUCOMMAND is only available on 98 and NT2000 platforms (according to the MSDN)

to get the definition of it you need to set WINVER to be > 0x500 and include winuser.h

#define WINVER 0x500
#include "winuser.h"

0
 
LVL 30

Accepted Solution

by:
Zoppo earned 100 total points
ID: 2611983
Hi middlel,

You can even call TrackPopupMenu with flag TPM_RETURNCMD set, then TrackPopupMenu() doesn't return until the user selected a menu item or cancelled the menu. The return value of TrackPopupMenu() is the menu command id.

ZOPPO
0
How to improve team productivity

Quip adds documents, spreadsheets, and tasklists to your Slack experience
- Elevate ideas to Quip docs
- Share Quip docs in Slack
- Get notified of changes to your docs
- Available on iOS/Android/Desktop/Web
- Online/Offline

 
LVL 14

Expert Comment

by:mcrider
ID: 2611990
When you call the TrackPopupMenu API, if you add  TPM_RETURNCMD to the flag, it will return the menu item number selected...

See: http://msdn.microsoft.com/library/psdk/winui/menus_0hdi.htm


Cheers!®©
0
 

Author Comment

by:middlel
ID: 2612019
Oh, Ok..  I have managed to handle WM_MENUSELECT but it is fired as soon as the mouse hovers over the menu item. I want to know which one has being selected - hence why I probably wanted to use WM_MENUCOMMAND instead..

How do I know when the user has clicked on the item.. I could probably just keep storing the menu item that the user has moved the mouse over, but how do I know if the user has clicked on or cancelled the menu.?

Emma
0
 

Author Comment

by:middlel
ID: 2612044
I have TPM_RETURNCMD set, but do I set my return type as BOOL or int..?

0
 
LVL 30

Expert Comment

by:Zoppo
ID: 2612064
You can use what you want I think coz BOOL is a typedef int ... or cast it to UINT, coz most ID's are passed as UINT...

Check: if retrurn value is zero user cancelled menu.

ZOPPO
0
 
LVL 14

Expert Comment

by:mcrider
ID: 2612108
Use Int...


Cheers!®©
0

Featured Post

Why You Should Analyze Threat Actor TTPs

After years of analyzing threat actor behavior, it’s become clear that at any given time there are specific tactics, techniques, and procedures (TTPs) that are particularly prevalent. By analyzing and understanding these TTPs, you can dramatically enhance your security program.

Join & Write a Comment

If you have ever found yourself doing a repetitive action with the mouse and keyboard, and if you have even a little programming experience, there is a good chance that you can use a text editor to whip together a sort of macro to automate the proce…
After several hours of googling I could not gather any information on this topic. There are several ways of controlling the USB port connected to any storage device. The best example of that is by changing the registry value of "HKEY_LOCAL_MACHINE\S…
This is Part 3 in a 3-part series on Experts Exchange to discuss error handling in VBA code written for Excel. Part 1 of this series discussed basic error handling code using VBA. http://www.experts-exchange.com/videos/1478/Excel-Error-Handlin…
This video explains how to create simple products associated to Magento configurable product and offers fast way of their generation with Store Manager for Magento tool.

706 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

19 Experts available now in Live!

Get 1:1 Help Now