ShowMenu.ahk

Summary
ShowMenu.ahk
ShowMenuShow menu from the text.
ShowMenu_DataGet data associated with menu item

ShowMenu

ShowMenu(mDef,  
mnu = "",
sub = "",
sep = "`n",
r = 0)

Show menu from the text.

Parameters

MDefTextual menu definition.
MnuMenu to show.  Label with the same name as menu will be launched on item selection.  “” means first menu will be shown (default)
SubOptional subroutine that will override default label (named by menu)
SepOptional separator char used for menu items in menu definition, by default new line

Returns

Message describing error if it occurred or new line separated list of created menus.  If return value is blank, ShowMenu just displayed menu already created in one of previous calls.

Remarks

You must have in the code label with the same name as that given to the menu, otherwise ShowMenu returns “No Label” error (unless you used “sub” parameter in which case the same applies to that subroutine).  There must be no white space between menu name and start of the line.  Set each menu item on new line, use “-” to define separator.

Metachars

To create submenu, use “item = [submenu]” notation where submenu must exist in the textual menu definition.  Referencing any particular menu as submenu multiple times will work correctly, but circular references must be avoided.  To make item checked, use “+” as first character of its name, to make it disabled use “*”.  To associated user data use “=data” after the item.  If text after = doesn’t contain valid submenu reference, it will be seen as user data.  This also means that submenu items can contain data.  To make menu definition more compact use something else then new line as item separator for instance “|” :

[Mnu1]
item1|item2|item3|-|item4=[Mnu2]|item5
[Mnu2]
menu21 = menu21|menu22|menu23|menu24

You can then use this command to show the menu

ShowMenu(mDef, "", "", "|")             ;use first menu found and | as item separator

About

ShowMenu_Data

ShowMenu_Data(mDef,  
item = "")

Get data associated with menu item

Parameters

mDefTextual menu definition.
itemMenu item which associated data will be returned, if omited defaults to A_ThisMenuItem

Returns

Associated data or empty string if no data is associated with item.

ShowMenu(mDef,  
mnu = "",
sub = "",
sep = "`n",
r = 0)
Show menu from the text.
ShowMenu_Data(mDef,  
item = "")
Get data associated with menu item
Close