menu events
BlitzMax Forums/MaxGUI Module/menu events
| ||
I have multiple windows and potentially multiple menus. I am trying to capture menu events from the specific window but it doesn't catch the EVENT_MENU ACTION. Code 1 Repeat WaitEvent() Select EventSource() Case mainWindow Select EventID() Case EVENT_WINDOWCLOSE End Case EVENT_MENUACTION Print "menu action" Select EventData() Case MENU_EXIT End EndSelect End Select End Select Forever I can only capture the menu actions from outside the SourceID() like this Repeat WaitEvent() Select EventSource() Case mainWindow Select EventID() Case EVENT_WINDOWCLOSE End End Select End Select Select EventID() Case EVENT_MENUACTION Select EventData() Case MENU_EXIT End EndSelect End Select Forever So am I right in thinking that if I have multiple menus in multiple windows that I have to check all the menus in one EventID() outside of specific EventSource() for local windows? This isn't a problem if this is the way it works, I was just assuming that a menu tied to a window would generate EventID() under the EventSource of the window it is in. John |
| ||
The source I think is the menu gadget handle returned by CreateMenu not the parent window gadget. CreateMenu example modified with extra logging: ' createmenu.bmx Import MaxGui.Drivers Strict Local window:TGadget Local filemenu:TGadget Local editmenu:TGadget Local helpmenu:TGadget Const MENU_NEW=101 Const MENU_OPEN=102 Const MENU_SAVE=103 Const MENU_CLOSE=104 Const MENU_EXIT=105 Const MENU_CUT=106 Const MENU_COPY=107 Const MENU_PASTE=108 Const MENU_ABOUT=109 window=CreateWindow("My Window",40,40,320,240) filemenu=CreateMenu("&File",0,WindowMenu(window)) CreateMenu"&New",MENU_NEW,filemenu,KEY_N,MODIFIER_COMMAND CreateMenu"&Open",MENU_OPEN,filemenu,KEY_O,MODIFIER_COMMAND CreateMenu"&Close",MENU_CLOSE,filemenu,KEY_W,MODIFIER_COMMAND CreateMenu"",0,filemenu CreateMenu"&Save",MENU_SAVE,filemenu,KEY_S,MODIFIER_COMMAND CreateMenu"",0,filemenu CreateMenu"E&xit",MENU_EXIT,filemenu,KEY_F4,MODIFIER_COMMAND editmenu=CreateMenu("&Edit",0,WindowMenu(window)) CreateMenu "Cu&t",MENU_CUT,editmenu,KEY_X,MODIFIER_COMMAND CreateMenu "&Copy",MENU_COPY,editmenu,KEY_C,MODIFIER_COMMAND CreateMenu "&Paste",MENU_PASTE,editmenu,KEY_V,MODIFIER_COMMAND helpmenu=CreateMenu("&Help",0,WindowMenu(window)) CreateMenu "&About",MENU_ABOUT,helpmenu UpdateWindowMenu window While True WaitEvent If CurrentEvent.source DebugLog CurrentEvent.ToString()+" src="+CurrentEvent.source.tostring() EndIf Select EventID() Case EVENT_WINDOWCLOSE End Case EVENT_MENUACTION Select EventData() Case MENU_EXIT End Case MENU_ABOUT Notify "Incrediabler~n(C)2005 Incredible Software" End Select End Select Wend |
| ||
I think I get it now, the menu event doesn't come from a window source. Which is why this code doesn't work. Import MaxGui.Drivers Strict Local window1:TGadget=CreateWindow("Window 1",0,0,200,200) Local window2:TGadget=CreateWindow("Window 2",250,0,200,200) Local menu1:TGadget=CreateMenu("Menu 1",0,WindowMenu(window1)) Const item1=100 Local menuItem1:TGadget=CreateMenu("Item 1",item1,menu1) UpdateWindowMenu window1 Local menu2:TGadget=CreateMenu("Menu 2",0,WindowMenu(window2)) Const item2=200 Local menuItem2:TGadget=CreateMenu("Item 2",item2,menu2) UpdateWindowMenu window2 Repeat WaitEvent Select EventSource() Case window1 Select EventID() Case EVENT_WINDOWCLOSE End Case EVENT_MENUACTION Print"Menu 1 action" End Select Case window2 Select EventID() Case EVENT_WINDOWCLOSE End Case EVENT_MENUACTION Print"Menu 2 action" End Select End Select Forever But then you would think that you could source a menu but this doesn't work either? Repeat WaitEvent Select EventSource() Case window1 Select EventID() Case EVENT_WINDOWCLOSE End End Select Case window2 Select EventID() Case EVENT_WINDOWCLOSE End End Select Case menu1 Select EventID() Case EVENT_MENUACTION Print"Menu 1 action" End Select Case menu2 Select EventID() Case EVENT_MENUACTION Print"Menu 2 action" End Select End Select Forever so I guess not all TGadets generate SourceID information. |
| ||
Menus with children don't generate events. If you, however, replace menu1 with menuItem1, you should find that the sub-menu generates an event. |