Trigger action on submenu?

Get help with using AutoHotkey and its commands and hotkeys
User avatar
JnLlnd
Posts: 327
Joined: 29 Sep 2013, 21:29
GitHub: JnLlnd
Location: Montreal, Quebec, Canada
Contact:

Trigger action on submenu?

21 Sep 2014, 07:48

I would think it is not possible but you never know what you can discover until you as a question on this forum 8-)

When a menu has submenus, is it possible to trigger an action only when a submenu is opened? For example, refreshing this submenu?
:thumbup: Author of Quick Access Popup, the powerful Windows folders, apps and documents launcher!
:P Quick Access Popup Knowledge base
:ugeek: The Automator's Courses on AutoHotkey
User avatar
Synetech
Posts: 13
Joined: 28 Nov 2015, 16:30

Re: Trigger action on submenu?

28 Dec 2016, 13:32

I tried creating a subroutine label that matches the name of the submenu (with and without the prepended colon), but while AHK did not complain, it also did nothing when the submenu is opened. :(

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
User avatar
JnLlnd
Posts: 327
Joined: 29 Sep 2013, 21:29
GitHub: JnLlnd
Location: Montreal, Quebec, Canada
Contact:

Re: Trigger action on submenu?

28 Dec 2016, 14:00

Good try :-) Thanks for this.
:thumbup: Author of Quick Access Popup, the powerful Windows folders, apps and documents launcher!
:P Quick Access Popup Knowledge base
:ugeek: The Automator's Courses on AutoHotkey
guest3456
Posts: 3163
Joined: 09 Oct 2013, 10:31

Re: Trigger action on submenu?

28 Dec 2016, 14:04

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 8-)

When a menu has submenus, is it possible to trigger an action only when a submenu is opened? For example, refreshing this submenu?

it may be possible:
https://msdn.microsoft.com/en-us/librar ... u_messages
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.
Last edited by guest3456 on 29 Dec 2016, 10:19, edited 1 time in total.

guest3456
Posts: 3163
Joined: 09 Oct 2013, 10:31

Re: Trigger action on submenu?

28 Dec 2016, 14:14

^hmmm i can't get it to work

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
}


guest3456
Posts: 3163
Joined: 09 Oct 2013, 10:31

Re: Trigger action on submenu?

28 Dec 2016, 14:16

more discussion:

https://autohotkey.com/boards/viewtopic.php?t=18777

it works:

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
}

User avatar
JnLlnd
Posts: 327
Joined: 29 Sep 2013, 21:29
GitHub: JnLlnd
Location: Montreal, Quebec, Canada
Contact:

Re: Trigger action on submenu?

29 Dec 2016, 10:49

So, this works when the menu is attached to a Gui. But, from what I've read from the links you posted, not for a standalone menu. Interesting.
:thumbup: Author of Quick Access Popup, the powerful Windows folders, apps and documents launcher!
:P Quick Access Popup Knowledge base
:ugeek: The Automator's Courses on AutoHotkey
User avatar
JnLlnd
Posts: 327
Joined: 29 Sep 2013, 21:29
GitHub: JnLlnd
Location: Montreal, Quebec, Canada
Contact:

Re: Trigger action on submenu?

29 Dec 2016, 11:23

Yes, you are right. But risky, as explained lexikos. Enough risky for me to exclude this option.
:thumbup: Author of Quick Access Popup, the powerful Windows folders, apps and documents launcher!
:P Quick Access Popup Knowledge base
:ugeek: The Automator's Courses on AutoHotkey

Return to “Ask For Help”

Who is online

Users browsing this forum: ark, Bing [Bot], nutnutwin, rjsr213 and 35 guests