PageRenderTime 29ms CodeModel.GetById 16ms RepoModel.GetById 0ms app.codeStats 0ms

/AutoHotkey.docset/Contents/Resources/Documents/commands/Menu.htm

https://gitlab.com/ahkscript/Autohotkey.docset
HTML | 256 lines | 227 code | 29 blank | 0 comment | 0 complexity | fb928a847b6399cea45270c04c1c909c MD5 | raw file
  1. <!DOCTYPE HTML>
  2. <html>
  3. <head>
  4. <title>Menu</title>
  5. <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
  6. <meta http-equiv="X-UA-Compatible" content="IE=edge">
  7. <link href="../static/theme.css" rel="stylesheet" type="text/css" />
  8. <script src="../static/content.js" type="text/javascript"></script>
  9. </head>
  10. <body>
  11. <h1>Menu</h1>
  12. <p>Creates, deletes, modifies and displays menus and menu items. Changes the tray icon and its tooltip. Controls whether the main window of a <a href="../Scripts.htm#ahk2exe">compiled script</a> can be opened.</p>
  13. <pre class="Syntax">Menu, MenuName, Cmd [, P3, P4, P5]</pre>
  14. <h3>Parameters</h3>
  15. <dl>
  16. <dt>MenuName</dt>
  17. <dd><p>It can be TRAY or the name of any custom menu. A custom menu is automatically created the first time its name is used with the <em>Add</em> command. For example: <code>Menu, MyMenu, Add, Item1</code>.</p>
  18. <p>Once created, a custom menu can be displayed with the <em>Show</em> command. It can also be attached as a submenu to one or more other menus via the <em>Add</em> command.</p></dd>
  19. <dt>Cmd, P3, P4, P5</dt>
  20. <dd><p>These 4 parameters are dependent on each other. See list below for the allowed combinations.</p></dd>
  21. <dt>MenuItemName</dt>
  22. <dd>
  23. <p>The name or position of a menu item. Some common rules apply to this parameter across all sub-commands which use it:</p>
  24. <p>To underline one of the letters in a menu item's name, precede that letter with an ampersand (&amp;). When the menu is displayed, such an item can be selected by pressing the corresponding key on the keyboard. To display a literal ampersand, specify two consecutive ampersands as in this example: <code>Save &amp;&amp; Exit</code></p>
  25. <p>When referring to an existing menu or menu item, the name is not case sensitive but any ampersands must be included. For example: <code>&amp;Open</code></p>
  26. <p><span class="ver">[v1.1.23+]:</span> To identify an existing item by its position in the menu, write the item's position followed by an ampersand. For example, <code>1&amp;</code> indicates the first item.</p>
  27. </dd>
  28. </dl>
  29. <h2>Add or Change Items in a Menu</h2>
  30. <p><strong>Add [, MenuItemName, Label-or-Submenu, Options]</strong>: This is a multipurpose command that adds a menu item, updates one with a new submenu or label, or converts one from a normal item into a submenu (or vice versa). If <em>MenuItemName</em> does not yet exist, it will be added to the menu. Otherwise, <em>MenuItemName</em> is updated with the newly specified <em>Label-or-Submenu</em>.</p>
  31. <p>To add a menu separator line, omit all three parameters.</p>
  32. <p>The label subroutine is run as a new <a href="../misc/Threads.htm">thread</a> when the user selects the menu item (similar to <a href="Gosub.htm">Gosub</a> and <a href="../Hotkeys.htm">hotkey subroutines</a>). If <em>Label-or-Submenu</em> is omitted, <em>MenuItemName</em> will be used as both the label and the menu item's name.</p>
  33. <p id="Functor"><span class="ver">[v1.1.20+]:</span> If it is not the name of an existing label, <em>Label-or-Submenu</em> can be the name of a function, or a single variable reference containing a <a href="../objects/Functor.htm">function object</a>. For example, <code>%funcobj%</code> or <code>% funcobj</code>. Other expressions which return objects are currently unsupported. The function can optionally define parameters as shown below:</p>
  34. <pre class="Syntax"><i>FunctionName</i>(ItemName, ItemPos, MenuName)</pre>
  35. <p>To have <em>MenuItemName</em> become a submenu -- which is a menu item that opens a new menu when selected -- specify for <em>Label-or-Submenu</em> a colon followed by the <em>MenuName</em> of an existing custom menu. For example:</p>
  36. <pre>Menu, MySubmenu, add, Item1
  37. Menu, tray, add, This Menu Item Is A Submenu, :MySubmenu</pre>
  38. <p>If not omitted, <em>Options</em> must be a space- or tab-delimited list of one or more of the following options:</p>
  39. <table class="info">
  40. <tr><td>P<em>n</em></td>
  41. <td>Replace <em>n</em> with the menu item's <a href="../misc/Threads.htm">thread priority</a>, e.g. <code>P1</code>. If this option is omitted when adding a menu item, the priority will be 0, which is the standard default. If omitted when updating a menu item, the item's priority will not be changed. Use a decimal (not hexadecimal) number as the priority.</td></tr>
  42. <tr><td>+Radio</td>
  43. <td><span class="ver">[v1.1.23+]:</span> If the item is checked, a bullet point is used instead of a check mark.</td></tr>
  44. <tr><td>+Right</td>
  45. <td><span class="ver">[v1.1.23+]:</span> The item is right-justified within the menu bar. This only applies to <a href="Gui.htm#Menu">menu bars</a>, not popup menus or submenus.</td></tr>
  46. <tr><td>+Break</td>
  47. <td><span class="ver">[v1.1.23+]:</span> The item begins a new column in a popup menu.</td></tr>
  48. <tr><td>+BarBreak</td>
  49. <td><span class="ver">[v1.1.23+]:</span> As above, but with a dividing line between columns.</td></tr>
  50. </table>
  51. <p>The plus sign (+) is optional and can be replaced with minus (-) to remove the option, as in <code>-Radio</code>. Options are not case sensitive.</p>
  52. <p>To change an existing item's options without affecting its label or submenu, simply omit the <em>Label-or-Submenu</em> parameter.</p>
  53. <p id="Insert"><strong>Insert [, ItemToInsertBefore, NewItemName, Label-or-Submenu, Options]</strong> <span class="ver">[v1.1.23+]</span>: Inserts a new item before the specified item. Usage is identical to <em>Add</em> (above), except for the additional <em>ItemToInsertBefore</em> parameter, which is the name of an existing item or a position&amp; between 1 and <a href="MenuGetHandle.htm#Examples">the current number of items</a> plus 1. Items can also be appended by omitting <em>ItemToInsertBefore</em> (by writing two consecutive commas). Unlike <em>Add</em>, <em>Insert</em> creates a new item even if <em>NewItemName</em> matches the name of an existing item.
  54. <p id="Delete"><strong>Delete [, MenuItemName]</strong>: Deletes <em>MenuItemName</em> from the menu. Standard menu items such as Exit (see below) cannot be individually deleted. If the <em>default</em> menu item is deleted, the effect will be similar to having used the <em>NoDefault</em> option. If <em>MenuItemName</em> is omitted, the entire <em>MenuName</em> menu will be deleted as will any menu items in other menus that use <em>MenuName</em> as a submenu. Deleting a menu also causes the current <a href="#Win32_Menus">Win32 menu</a> of its parent and submenus to be destroyed, to be recreated later as needed.</p>
  55. <p id="DeleteAll"><strong>DeleteAll</strong>: Deletes all custom menu items from the menu, leaving the menu empty unless it contains the <em>standard</em> items (see below). Unlike a menu entirely deleted by the <em>Delete</em> command (see above), an empty menu still exists and thus any other menus that use it as a submenu will retain those submenus. However, the current <a href="#Win32_Menus">Win32 menus</a> of this menu and its parent and submenus are destroyed, to be recreated later as needed.</p>
  56. <p><strong>Rename, MenuItemName [, NewName]</strong>: Renames <em>MenuItemName</em> to <em>NewName</em> (if <em>NewName</em> is blank, <em>MenuItemName</em> will be converted into a separator line). The menu item's current target label or submenu is unchanged. <span class="ver">[v1.1.23+]:</span> A separator line can be converted to a normal item by specifying the position&amp; of the separator and a non-blank <em>NewName</em>, and then using the <em>Add</em> command to give the item a label or submenu.</p>
  57. <p><strong>Check, MenuItemName</strong>: Adds a visible checkmark in the menu next to <em>MenuItemName</em> (if there isn't one already).</p>
  58. <p><strong>Uncheck, MenuItemName</strong>: Removes the checkmark (if there is one) from <em>MenuItemName</em>.</p>
  59. <p><strong>ToggleCheck, MenuItemName</strong>: Adds a checkmark if there wasn't one; otherwise, removes it.</p>
  60. <p><strong>Enable, MenuItemName</strong>: Allows the user to once again select <em>MenuItemName</em> if was previously disabled (grayed).</p>
  61. <p><strong>Disable, MenuItemName</strong>: Changes <em>MenuItemName</em> to a gray color to indicate that the user cannot select it.</p>
  62. <p><strong>ToggleEnable, MenuItemName</strong>: Disables <em>MenuItemName</em> if it was previously enabled; otherwise, enables it.</p>
  63. <p><strong>Default [, MenuItemName]</strong>: Changes the menu's default item to be <em>MenuItemName</em> and makes that item's font bold (setting a default item in menus other than TRAY is currently purely cosmetic). When the user double-clicks the tray icon, its default menu item is launched. If there is no default, double-clicking has no effect. If <em>MenuItemName</em> is omitted, the effect is the same as having used <em>NoDefault</em> below.</p>
  64. <p><strong>NoDefault</strong>: For the tray menu: Changes the menu back to having its standard default menu item, which is OPEN for non-compiled scripts and none for <a href="../Scripts.htm#ahk2exe">compiled scripts</a> (except when the <em>MainWindow</em> option is in effect). If the OPEN menu item does not exist due to a previous use of the NoStandard command below, there will be no default and thus double-clicking the tray icon will have no effect. For menus other than TRAY: Any existing default item is returned to a non-bold font.</p>
  65. <p><strong>Standard</strong>: Inserts the standard menu items at the bottom of the menu (if they are not already present). This command can be used with the tray menu or any other menu.</p>
  66. <p><strong>NoStandard</strong>: Removes all standard (non-custom) menu items from the tray menu (if they are present).</p>
  67. <h2 id="MenuIcon">Set or Remove a Menu Item's Icon <span class="ver">[AHK_L 17+]</span></h2>
  68. <p><strong>Icon, MenuItemName, FileName [, IconNumber, IconWidth]</strong>: Sets <em>MenuItemName</em>'s icon. <em>FileName</em> can either be an icon file or any image in a format supported by AutoHotkey. To use an icon group other than the first one in the file, specify its number for <em>IconNumber</em> (if omitted, it defaults to 1). If <em>IconNumber</em> is negative, its absolute value is assumed to be the resource ID of an icon within an executable file. Specify the desired width of the icon in <em>IconWidth</em>. If the icon group indicated by <em>IconNumber</em> contains multiple icon sizes, the closest match is used and the icon is scaled to the specified size. See the Examples section for usage examples.</p>
  69. <p>Currently it is necessary to specify "actual size" when setting the icon to preserve transparency on Windows Vista and later. For example:</p>
  70. <pre>Menu, MenuName, Icon, MenuItemName, Filename.png,, 0</pre>
  71. <p>Known limitation: Icons on Gui menu bars are positioned incorrectly on Windows XP and older.</p>
  72. <p><span class="ver">[v1.1.23+]:</span> A <a href="../misc/ImageHandles.htm">bitmap or icon handle</a> can be used instead of a filename. For example, <code>HBITMAP:%handle%</code>.</p>
  73. <p><strong>NoIcon, MenuItemName</strong>: Removes <em>MenuItemName</em>'s icon, if any.
  74. <h2>Change the Tray Icon or ToolTip <span class="ver">(<em>MenuName</em> must be TRAY)</span></h2>
  75. <p id="Icon"><strong>Icon [, FileName, IconNumber, 1]</strong>: Changes the script's icon to one of the ones from <em>FileName</em>. The following types of files are supported: ICO, CUR, ANI, EXE, DLL, CPL, SCR, and other types that contain icon resources. To use an icon group other than the first one in the file, specify its number for <em>IconNumber</em> (if omitted, it defaults to 1). For example, <strong>2</strong> would load the default icon from the second icon group. If <em>IconNumber</em> is negative, its absolute value is assumed to be the resource ID of an icon within an executable file. Specify an asterisk (*) for <em>FileName</em> to restore the script to its default icon.</p>
  76. <p>The last parameter: Specify 1 for the last parameter to freeze the icon, or 0 to unfreeze it (or leave it blank to keep the frozen/unfrozen state unchanged). When the icon has been frozen, <a href="Pause.htm">Pause</a> and <a href="Suspend.htm">Suspend</a> will not change it. Note: To freeze or unfreeze the <em>current</em> icon, use 1 or 0 as in the following example: <code>Menu, Tray, Icon,,, 1</code>.</p>
  77. <p>Changing the tray icon also changes the icon displayed by <a href="InputBox.htm">InputBox</a>, <a href="Progress.htm">Progress</a>, and subsequently-created <a href="Gui.htm">GUI</a> windows. <a href="../Scripts.htm#ahk2exe">Compiled scripts</a> are also affected even if a custom icon was specified at the time of compiling. Note: Changing the icon will not unhide the tray icon if it was previously hidden by means such as <a href="_NoTrayIcon.htm">#NoTrayIcon</a>; to do that, use <code>Menu, Tray, Icon</code> (with no parameters).</p>
  78. <p id="distort">Slight distortion may occur when loading tray icons from file types other than .ICO. This is especially true for 16x16 icons. To prevent this, store the desired tray icon inside a .ICO file.</p>
  79. <p>There are some icons built into the operating system's DLLs and CPLs that might be useful. For example: <code>Menu, Tray, Icon, Shell32.dll, 174</code>.</p>
  80. <p>The built-in variables <strong>A_IconNumber</strong> and <strong>A_IconFile</strong> contain the number and name (with full path) of the current icon (both are blank if the icon is the default).</p>
  81. <p><span class="ver">[v1.1.23+]:</span> A <a href="../misc/ImageHandles.htm">bitmap or icon handle</a> can be used instead of a filename. For example, <code>HBITMAP:%handle%</code>.</p>
  82. <p><strong>Icon</strong> (with no parameters): Creates the tray icon if it isn't already present. This will override <a href="_NoTrayIcon.htm">#NoTrayIcon</a> if that directive is also present in the script.</p>
  83. <p><strong>NoIcon</strong>: Removes the tray icon if it exists. If this command is used at the very top of the script, the tray icon might be briefly visible when the script is launched. To prevent that, use <a href="_NoTrayIcon.htm">#NoTrayIcon</a> instead. The built-in variable <strong>A_IconHidden</strong> contains 1 if the tray icon is currently hidden or 0 otherwise.</p>
  84. <p><strong>Tip [, Text]</strong>: Changes the tray icon's tooltip -- which is displayed when the mouse hovers over it. To create a multi-line tooltip, use the linefeed character (`n) in between each line, e.g. Line1`nLine2. Only the first 127 characters of <em>Text</em> are displayed, and <em>Text</em> is truncated at the first tab character, if present. If <em>Text</em> is omitted, the tooltip is restored to its default text. The built-in variable <strong>A_IconTip</strong> contains the current text of the tooltip (blank if the text is at its default).</p>
  85. <h2>Miscellaneous Commands</h2>
  86. <p id="Show"><strong>Show [, X, Y]</strong>: Displays <em>MenuName</em>, allowing the user to select an item with arrow keys, menu shortcuts (underlined letters), or the mouse. Any menu can be shown, including the tray menu but with the exception of <a href="Gui.htm">GUI</a> menu bars. If both X and Y are omitted, the menu is displayed at the current position of the mouse cursor. If only one of them is omitted, the mouse cursor's position will be used for it. X and Y are relative to the active window. Specify &quot;<a href="CoordMode.htm">CoordMode</a>, Menu&quot; beforehand to make them relative to the entire screen.</p>
  87. <p><strong>Color, ColorValue [, Single]</strong>: Changes the background color of the menu to <em>ColorValue</em>, which is one of the 16 primary HTML color names or a 6-digit RGB color value (see <a href="Progress.htm#colors">color chart</a>). Leave <em>ColorValue</em> blank (or specify the word Default) to restore the menu to its default color. If the word Single is not present as the next parameter, any submenus attached to this menu will also be changed in color.</p>
  88. <p><strong>Click, ClickCount</strong>: Specify 1 for <em>ClickCount</em> to allow a single-click to activate the tray menu's default menu item. Specify 2 for <em>ClickCount</em> to return to the default behavior (double-click). For example: <code>Menu, Tray, Click, 1</code>.</p>
  89. <p id="MainWindow"><strong>MainWindow</strong>: This command affects <a href="../Scripts.htm#ahk2exe">compiled scripts</a> only. It allows the script's main window to be opened via the tray icon, which is otherwise impossible. It also enables the items in the main window's View menu such as &quot;Lines most recently executed&quot;, which allows viewing of the script's source code and other info. <em>MenuName</em> must be TRAY.</p>
  90. <p><strong>NoMainWindow</strong> (default): This command affects <a href="../Scripts.htm#ahk2exe">compiled scripts</a> only. It restores the script to its default behavior, that is, it prevents the main window from being opened. Even while this option is in effect, the following commands are still able to show the main window when they are encountered in the script at runtime: <a href="ListLines.htm">ListLines</a>, <a href="ListVars.htm">ListVars</a>, <a href="ListHotkeys.htm">ListHotkeys</a>, and <a href="KeyHistory.htm">KeyHistory</a>. <em>MenuName</em> must be TRAY.</p>
  91. <p><strong>UseErrorLevel [, off]</strong>: If this option is never used in the script, it defaults to OFF. The OFF setting displays a dialog and terminates the <a href="../misc/Threads.htm">current thread</a> whenever the Menu command generates an error. Specify <code>Menu, Tray, UseErrorLevel</code> to prevent the dialog and thread termination; instead, <a href="../misc/ErrorLevel.htm">ErrorLevel</a> will be set to 1 if there was a problem or 0 otherwise. To turn this option back off, specify OFF for the next parameter. This setting is global, meaning it affects all menus, not just <em>MenuName</em>.</p>
  92. <h2 id="Win32_Menus">Win32 Menus</h2>
  93. <p>As items are added to a menu or modified, the name and other properties of each item are recorded by the Menu command, but the actual <a href="https://msdn.microsoft.com/en-us/library/ms646977">Win32 menu</a> is not constructed immediately. This occurs when the menu or its parent menu is attached to a GUI or shown, either for the first time or if the menu has been "destroyed" since it was last shown. Any of the following can cause this Win32 menu to be destroyed, along with any parent menus and submenus:</p>
  94. <ul>
  95. <li>Deleting a menu.</li>
  96. <li>Replacing an item's submenu with a label or a different menu.</li>
  97. <li>Menu, <em>MenuName</em>, <strong>DeleteAll</strong>.</li>
  98. <li>Menu, <em>MenuName</em>, <strong>NoStandard</strong> (if the standard items were present).</li>
  99. </ul>
  100. <p>Any modifications which are made to the menu directly by Win32 API calls only apply to the current "instance" of the menu, and are lost when the menu is destroyed.</p>
  101. <p>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 <a href="MenuGetHandle.htm#Examples">MenuGetHandle example</a>. This ID cannot be used with the Menu command, but can be used with various <a href="https://msdn.microsoft.com/en-us/library/ms646977">Win32 functions</a>.</p>
  102. <h2>Remarks</h2>
  103. <p>The names of menus and menu items can be up to 260 characters long.</p>
  104. <p>Separator lines can be added to the menu by using <code>Menu, <i>MenuName</i>, Add</code> (i.e. omit all other parameters). To delete separator lines individually, identify them by their position in the menu (requires v1.1.23+). For example, use <code>Menu, <i>MenuName</i>, Delete, 3&amp;</code> if there are two items preceding the separator. Alternatively, use <code>Menu, <i>MenuName</i>, DeleteAll</code> and then re-add your custom menu items.</p>
  105. <p>New menu items are always added at the bottom of the menu. For the tray menu: To put your menu items on top of the standard menu items (after adding your own menu items) run <code>Menu, Tray, NoStandard</code> followed by <code>Menu, Tray, Standard</code>.</p>
  106. <p>The standard menu items such as &quot;Pause Script&quot; and &quot;Suspend Hotkeys&quot; cannot be individually operated upon by any menu sub-command.</p>
  107. <p>If a menu ever becomes completely empty -- such as by using <code>Menu, MyMenu, DeleteAll</code> -- it cannot be shown. If the tray menu becomes empty, right-clicking and double-clicking the tray icon will have no effect (in such cases it is usually better to use <a href="_NoTrayIcon.htm">#NoTrayIcon</a>).</p>
  108. <p>If a menu item's subroutine is already running and the user selects the same menu item again, a new <a href="../misc/Threads.htm">thread</a> will be created to run that same subroutine, interrupting the previous thread. To instead buffer such events until later, use <a href="Critical.htm">Critical</a> as the subroutine's first line (however, this will also buffer/defer other threads such as the press of a hotkey).</p>
  109. <p>Whenever a subroutine is launched via a menu item, it starts off fresh with the default values for settings such as <a href="SendMode.htm">SendMode</a>. These defaults can be changed in the <a href="../Scripts.htm#auto">auto-execute section</a>.</p>
  110. <p>The built-in variables <strong><a href="../Variables.htm#ThisMenuItem">A_ThisMenuItem</a></strong> and <strong><a href="../Variables.htm#ThisMenuItemPos">A_ThisMenuItemPos</a></strong> contain the name and position of the custom menu item most recently selected by the user (blank if none). Similarly, <strong>A_ThisMenu</strong> is the name of the menu from which <strong>A_ThisMenuItem</strong> was selected. These variables are useful when building a menu whose contents are not always the same. In such a case, it is usually best to point all such menu items to the same label and have that label refer to the above variables to determine what action to take.</p>
  111. <p>To keep a non-hotkey, non-<a href="Gui.htm">GUI</a> script running -- such as one that contains only custom menus or menu items -- use <a href="_Persistent.htm">#Persistent</a>.</p>
  112. <h2>Related</h2>
  113. <p><a href="Gui.htm">GUI</a>, <a href="../misc/Threads.htm">Threads</a>, <a href="Thread.htm">Thread</a>, <a href="Critical.htm">Critical</a>, <a href="_NoTrayIcon.htm">#NoTrayIcon</a>, <a href="Gosub.htm">Gosub</a>, <a href="Return.htm">Return</a>, <a href="SetTimer.htm">SetTimer</a>, <a href="_Persistent.htm">#Persistent</a></p>
  114. <h2>Examples</h2>
  115. <pre class="NoIndent"><em>; EXAMPLE #1: This is a working script that adds a new menu item to the bottom of the tray icon menu.</em>
  116. #Persistent <em>; Keep the script running until the user exits it.</em>
  117. Menu, tray, add <em>; Creates a separator line.</em>
  118. Menu, tray, add, Item1, MenuHandler <em>; Creates a new menu item.</em>
  119. return
  120. MenuHandler:
  121. MsgBox You selected %A_ThisMenuItem% from menu %A_ThisMenu%.
  122. return</pre>
  123. <p>&nbsp;</p>
  124. <pre class="NoIndent"><em>; EXAMPLE #2: This is a working script that creates a popup menu that is displayed when the user presses the Win-Z hotkey.</em>
  125. <em>; Create the popup menu by adding some items to it.</em>
  126. Menu, MyMenu, Add, Item1, MenuHandler
  127. Menu, MyMenu, Add, Item2, MenuHandler
  128. Menu, MyMenu, Add <em>; Add a separator line.</em>
  129. <em>; Create another menu destined to become a submenu of the above menu.</em>
  130. Menu, Submenu1, Add, Item1, MenuHandler
  131. Menu, Submenu1, Add, Item2, MenuHandler
  132. <em>; Create a submenu in the first menu (a right-arrow indicator). When the user selects it, the second menu is displayed.</em>
  133. Menu, MyMenu, Add, My Submenu, :Submenu1
  134. Menu, MyMenu, Add <em>; Add a separator line below the submenu.</em>
  135. Menu, MyMenu, Add, Item3, MenuHandler <em>; Add another menu item beneath the submenu.</em>
  136. return <em>; End of script's auto-execute section.</em>
  137. MenuHandler:
  138. MsgBox You selected %A_ThisMenuItem% from the menu %A_ThisMenu%.
  139. return
  140. #z::Menu, MyMenu, Show <em>; i.e. press the Win-Z hotkey to show the menu.</em></pre>
  141. <p>&nbsp;</p>
  142. <pre class="NoIndent"><em>; EXAMPLE #3: This is a working script that demonstrates some of the various menu commands.</em>
  143. #Persistent
  144. #SingleInstance
  145. menu, tray, add <em>; separator</em>
  146. menu, tray, add, TestToggle&amp;Check
  147. menu, tray, add, TestToggleEnable
  148. menu, tray, add, TestDefault
  149. menu, tray, add, TestStandard
  150. menu, tray, add, TestDelete
  151. menu, tray, add, TestDeleteAll
  152. menu, tray, add, TestRename
  153. menu, tray, add, Test
  154. return
  155. <em>;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;</em>
  156. TestToggle&amp;Check:
  157. menu, tray, ToggleCheck, TestToggle&amp;Check
  158. menu, tray, Enable, TestToggleEnable <em>; Also enables the next test since it can't undo the disabling of itself.</em>
  159. menu, tray, add, TestDelete <em>; Similar to above.</em>
  160. return
  161. TestToggleEnable:
  162. menu, tray, ToggleEnable, TestToggleEnable
  163. return
  164. TestDefault:
  165. if default = TestDefault
  166. {
  167. menu, tray, NoDefault
  168. default =
  169. }
  170. else
  171. {
  172. menu, tray, Default, TestDefault
  173. default = TestDefault
  174. }
  175. return
  176. TestStandard:
  177. if standard &lt;&gt; n
  178. {
  179. menu, tray, NoStandard
  180. standard = n
  181. }
  182. else
  183. {
  184. menu, tray, Standard
  185. standard = y
  186. }
  187. return
  188. TestDelete:
  189. menu, tray, delete, TestDelete
  190. return
  191. TestDeleteAll:
  192. menu, tray, DeleteAll
  193. return
  194. TestRename:
  195. if NewName &lt;&gt; renamed
  196. {
  197. OldName = TestRename
  198. NewName = renamed
  199. }
  200. else
  201. {
  202. OldName = renamed
  203. NewName = TestRename
  204. }
  205. menu, tray, rename, %OldName%, %NewName%
  206. return
  207. Test:
  208. MsgBox, You selected &quot;%A_ThisMenuItem%&quot; in menu &quot;%A_ThisMenu%&quot;.
  209. return</pre>
  210. <pre class="NoIndent"><em>; EXAMPLE #4: This is a working script that adds icons to its menu items.</em>
  211. Menu, FileMenu, Add, Script Icon, MenuHandler
  212. Menu, FileMenu, Add, Suspend Icon, MenuHandler
  213. Menu, FileMenu, Add, Pause Icon, MenuHandler
  214. Menu, FileMenu, Icon, Script Icon, %A_AhkPath%, 2 <em>;Use the 2nd icon group from the file</em>
  215. Menu, FileMenu, Icon, Suspend Icon, %A_AhkPath%, -206 <em>;Use icon with resource identifier 206</em>
  216. Menu, FileMenu, Icon, Pause Icon, %A_AhkPath%, -207 <em>;Use icon with resource identifier 207</em>
  217. Menu, MyMenuBar, Add, &amp;File, :FileMenu
  218. Gui, Menu, MyMenuBar
  219. Gui, Add, Button, gExit, Exit This Example
  220. Gui, Show
  221. MenuHandler:
  222. Return
  223. Exit:
  224. ExitApp
  225. </pre>
  226. </body>
  227. </html>