
When a menu has submenus, is it possible to trigger an action only when a submenu is opened? For example, refreshing this submenu?
Code: Select all
Menu, SubMenu, Add, Foo, SubMenuItem
Menu, Tray, Add, ..., :SubMenu
MsgBox, Test now...
return
SubMenuItem:
MsgBox, Submenu item clicked
return
SubMenu:
:SubMenu:
MsgBox, Submenu opened
return
JnLlnd wrote:I would think it is not possible but you never know what you can discover until you as a question on this forum
When a menu has submenus, is it possible to trigger an action only when a submenu is opened? For example, refreshing this submenu?
When the user points to a menu item that opens a submenu, the system sends the owner window the WM_INITMENUPOPUP message before displaying the submenu. This message gives the application an opportunity to modify the submenu before it is displayed.
Code: Select all
OnMessage(0x117, "WM_INITMENUPOPUP")
Menu, MyMenu, Add, Item1, MenuHandler
Menu, MyMenu, Add, Item2, MenuHandler
Menu, MyMenu, Add
Menu, Submenu1, Add, Item1, MenuHandler
Menu, Submenu1, Add, Item2, MenuHandler
Menu, MyMenu, Add, My Submenu, :Submenu1
Menu, MyMenu, Add
Menu, MyMenu, Add, Item3, MenuHandler
return
MenuHandler:
MsgBox You selected %A_ThisMenuItem% from the menu %A_ThisMenu%.
return
#z::Menu, MyMenu, Show
WM_INITMENUPOPUP(a,b,c,d)
{
msgbox, opened
}
Code: Select all
Menu, FileMenu, Add, &Open`tCtrl+O, GuiClose
Menu, FileMenu, Add, E&xit, GuiClose
Menu, HelpSubMenu, Add, SubItem, GuiClose
Menu, HelpMenu, Add, &About, GuiClose
Menu, HelpMenu, Add, SubMenu, :HelpSubMenu
Menu, MyMenuBar, Add, &File, :FileMenu
Menu, MyMenuBar, Add, &Help with submenu, :HelpMenu
Gui, Menu, MyMenuBar
Gui, Show, w400 h300, Title
OnMessage(0x211, "WM_ENTERMENULOOP")
OnMessage(0x117, "WM_INITMENUPOPUP")
return
GuiClose:
GuiEscape:
ExitApp
return
WM_INITMENUPOPUP(wParam, lParam, msg, hwnd) {
MouseGetPos, x, y
ToolTip, %wParam%`n%lParam%`n%msg%`n%hwnd%, x+200, y+200
}
WM_ENTERMENULOOP(){
Return 100
}
Users browsing this forum: Bad husband, Bing [Bot], Google [Bot], LeFunk, mikeyww and 45 guests