views:

57

answers:

1

I'm displaying a popup menu using TrackPopupMenu and would like to know when it is dismissed via clicking outside of it. I've looked through all the menu functions but didn't find anything useful in this regard. Spy++ told me that no window message is sent in this case.

So, is there an easy way to do it without installing a mouse hook? Thanks!

+3  A: 

[edit] This is better. If you specify TPM_RETURNCMD in the uFlags parameter, the return value is the menu-item identifier of the item that the user selected. If the user cancels the menu without making a selection, or if an error occurs, then the return value is zero. [edit]

The menu loop is ended when ::TrackPopupMenu() returns :) If a menu item was selected the window having the HWND passed as 6th parameter will receive a WM_COMMAND message with the ID of the selected item. You can probably ::PeekMessage() after ::TrackPopupMenu() returns to see if WM_COMMAND is in the queue.

If you want to be notified while in ::TrackPopupMenu() you can handle WM_EXITMENULOOP.

cheers, AR

Alain Rist
Indeed. Was so simple I didn't think of it ;) Thanks
Alex Jenter