Getting menus as objects

Get help with using AutoHotkey (v1.1 and older) and its commands and hotkeys
laulau
Posts: 35
Joined: 06 Nov 2020, 16:53

Getting menus as objects

16 Nov 2020, 12:22

When i use the Menu command to create context menus is there a way i can get the menus and iterate over the menu items for example to list them or save them?

The way i do it now is to store the same data in a colletion when i add them to a menu, but if the menus are available then i wouldnt have to do that.
User avatar
mikeyww
Posts: 26942
Joined: 09 Sep 2014, 18:38

Re: Getting menus as objects

16 Nov 2020, 12:34

Sure, if your script creates the menu, then you know what the menu items are. You can use a loop to create or save any of the items.
laulau
Posts: 35
Joined: 06 Nov 2020, 16:53

Re: Getting menus as objects

16 Nov 2020, 14:58

mikeyww wrote:
16 Nov 2020, 12:34
Sure, if your script creates the menu, then you know what the menu items are. You can use a loop to create or save any of the items.
My question is if i need to keep track of it or if i can get the information from the menu objects when needed?
User avatar
mikeyww
Posts: 26942
Joined: 09 Sep 2014, 18:38

Re: Getting menus as objects

16 Nov 2020, 15:16

If you don't keep track, it would take extra work. Below is some information.

https://autohotkey.com/board/topic/39011-how-to-get-popup-menu-items/
Each menu item is assigned an ID when it is first added to the menu. Scripts cannot rely on an item receiving a particular ID, but can retrieve the ID of an item by using GetMenuItemID as shown in the MenuGetHandle example. This ID cannot be used with the Menu command, but can be used with various Win32 functions.
laulau
Posts: 35
Joined: 06 Nov 2020, 16:53

Re: Getting menus as objects

16 Nov 2020, 15:18

mikeyww wrote:
16 Nov 2020, 15:16
If you don't keep track, it would take extra work. Below is some information.

https://autohotkey.com/board/topic/39011-how-to-get-popup-menu-items/
Each menu item is assigned an ID when it is first added to the menu. Scripts cannot rely on an item receiving a particular ID, but can retrieve the ID of an item by using GetMenuItemID as shown in the MenuGetHandle example. This ID cannot be used with the Menu command, but can be used with various Win32 functions.
Thanks! Yeah i already decided i want to keep track on them myself because i will probably want to add metadata further on. But i remainded curious.

Return to “Ask for Help (v1)”

Who is online

Users browsing this forum: filipemb, Google [Bot], mapcarter, peter_ahk and 307 guests