Page 1 of 1
Determine if Popup Menu was cancelled
Posted: Thu Mar 29, 2007 12:05 pm
by Worm
I'm trying to determine if an item was selected in one of my popup menus or if the menu was hidden by clicking somewhere else. I've tried setting a variable to false before calling DisplayPopupMenu, setting it to true in my EventMenu routine, then checking its value after DisplayPopupMenu, but am having little luck.
Posted: Thu Mar 29, 2007 12:14 pm
by Derek
If an item was selected then it would trigger a menu-event, if the menu was hidden then you won't get an event.
Just check in your loop for the events.
Posted: Thu Mar 29, 2007 1:12 pm
by Worm
Thanks Derek.
I do get the event when a menu item is chosen, but how do I check a *non* event for when the menus hidden. That's the part that is slipping through my fingers.
Posted: Thu Mar 29, 2007 1:35 pm
by srod
Is this what you're after?
Code: Select all
Global flag
If CreatePopupMenu(0)
MenuItem(1, "Cut")
MenuItem(2, "Copy")
MenuItem(3, "Paste")
MenuBar()
OpenSubMenu("Options")
MenuItem(4, "Window...")
MenuItem(5, "Gadget...")
CloseSubMenu()
MenuBar()
MenuItem( 6, "Quit")
EndIf
;
; We just have to open a window and see when an event happen on the menu
;
If OpenWindow(0, 100, 100, 300, 260, "PureBasic - PopupMenu Example")
Repeat
Select WaitWindowEvent()
Case #WM_RBUTTONDOWN
DisplayPopupMenu(0, WindowID(0))
flag=1
Case #PB_Event_Menu
flag=0
Select EventMenu() ; To see which menu has been selected
Case 1 ; Cut
MessageRequester("PureBasic", "Cut", 0)
Case 2 ; Copy
MessageRequester("PureBasic", "Copy", 0)
Case 3 ; Paste
MessageRequester("PureBasic", "Paste", 0)
Case 6 ; Quit
Quit = 1
EndSelect
Case #PB_Event_CloseWindow
Quit = 1
Default
If flag=1
flag=0
Debug "Popup cancelled!"
EndIf
EndSelect
Until Quit = 1
EndIf
End
Posted: Thu Mar 29, 2007 1:38 pm
by Derek
I think you don't, since all you are concerned about in your event loop is events, if one isn't triggered then you don't do anything.
The popup menu being hidden isn't a problem as it will come back if needed.
Posted: Thu Mar 29, 2007 1:41 pm
by Derek
Nice one srod, although I still don't see why you would need to know if 'nothing' has been selected. But whatever.

Posted: Thu Mar 29, 2007 1:42 pm
by Worm
srod, that's exaclty what I was trying to do. Thank you.
Posted: Thu Mar 29, 2007 1:42 pm
by srod
I agree Derek!
@worm: you're welcome.
Posted: Thu Mar 29, 2007 1:44 pm
by Worm
I know it's not the *normal* thing to try to capture this non event, but for my application its something I need to know. If the popup is displayed to a user, I need feed back as to whether they selected an item, or if the menu itself was ignore/canceled.
I appreciate your help, again thanks.