Function Reference


TrayCreateMenu

Creates a menu control for the tray menu.

TrayCreateMenu ( "sub/menutext" [, menuID = -1 [, menuentry = -1]] )

Parameters

sub/menutext The sub/menu text.
menuID [optional] If defined, allows you to create a submenu in the referenced menu. Default -1 (refers to first level menu).
menuentry [optional] Allows you to define the entry number to be created. The entries are numbered starting at 0. Default -1 (at the bottom).

Return Value

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

Related

TrayGetMsg, TrayItemDelete, TrayItemSetState, TrayItemSetText

Example

#NoTrayIcon
#include <MsgBoxConstants.au3>
#include <StringConstants.au3>
#include <TrayConstants.au3> ; Required for the $TRAY_ICONSTATE_SHOW constant.

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.

Example()

Func Example()
        Local $iSettings = TrayCreateMenu("Settings") ; Create a tray menu sub menu with two sub items.
        Local $iDisplay = TrayCreateItem("Display", $iSettings)
        Local $iPrinter = TrayCreateItem("Printer", $iSettings)
        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, "\", $STR_NOCASESENSEBASIC, -1) - 1)) ; Find the folder of a full path.

                        Case $iDisplay, $iPrinter
                                MsgBox($MB_SYSTEMMODAL, "", "A sub menu item was selected from the tray menu.")

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