Function Reference


Creates a menuitem control for the tray.

TrayCreateItem ( "text" [, menuID = -1 [, menuentry = -1 [, menuradioitem = 0]]] )


text The text of the control.
menuID [optional] Allows you to create a submenu in the referenced menu. If equal -1 it will be added 'behind' the last created item (default setting).
menuentry [optional] Allows you to define the entry number to be created. The entries are numbered starting at 0. If equal -1 it will be added 'behind' the last created entry (default setting).
menuradioitem [optional]
    $TRAY_ITEM_NORMAL (0) = (default) create a normal menuitem.
    $TRAY_ITEM_RADIO (1) = create a menuradioitem.

Constants are defined in TrayConstants.au3.

Return Value

Success: the identifier (controlID) of the new tray menuitem.
Failure: 0.


If the 'text' parameter is an empty string ( "" ) then a separator line is created.

By default, normal checked menuitems (not radio menuitems) will be automatically unchecked if you click it!
To turn off this behaviour use Opt("TrayMenuMode", 2).

Radio menuitems are automatically grouped together and these groups are separated by a separator line or a normal item which is not a radio item.
By default, a clicked radio menuitem will be checked automatically and all other radio items in the same group will be unchecked!
To turn off this behaviour use Opt("TrayMenuMode", 8).


TrayGetMsg, TrayItemDelete, TrayItemSetOnEvent, TrayItemSetState, TrayItemSetText


#include <AutoItConstants.au3>
#include <MsgBoxConstants.au3>
#include <TrayConstants.au3> ; Required for the $TRAY_CHECKED and $TRAY_ICONSTATE_SHOW constants.

Opt("TrayMenuMode", 3) ; The default tray menu items will not be shown and items are not checked when selected. These are options 1 and 2 for TrayMenuMode.


Func Example()
    ; Create a tray item with the radio item parameter selected.
    TrayCreateItem("Radio 1", -1, -1, $TRAY_ITEM_RADIO)
    TrayItemSetState(-1, $TRAY_CHECKED)
    TrayCreateItem("Radio 2", -1, -1, $TRAY_ITEM_RADIO)
    TrayCreateItem("Radio 3", -1, -1, $TRAY_ITEM_RADIO)

    TrayCreateItem("") ; Create a separator line.

    Local $idAbout = TrayCreateItem("About")
    TrayCreateItem("") ; Create a separator line.

    Local $idExit = TrayCreateItem("Exit")

    TraySetState($TRAY_ICONSTATE_SHOW) ; Show the tray menu.

    While 1
        Switch TrayGetMsg()
            Case $idAbout ; Display a message box about the AutoIt version and installation path of the AutoIt executable.
                MsgBox($MB_SYSTEMMODAL, "", "AutoIt tray menu example." & @CRLF & @CRLF & _
                        "Version: " & @AutoItVersion & @CRLF & _
                        "Install Path: " & StringLeft(@AutoItExe, StringInStr(@AutoItExe, "\", 0, -1) - 1)) ; Find the folder of a full path.

            Case $idExit ; Exit the loop.
EndFunc   ;==>Example