Function Reference


TrayItemSetState

Sets the state of a tray menu/item control.

TrayItemSetState ( controlID, state )

Parameters

controlID The control identifier (controlID) as returned by a TrayCreateItem or TrayCreateMenu function.
state See the State table below.

Return Value

Success: 1.
Failure: 0.

Remarks

State table

State Value Comments
No Change 0
$TRAY_CHECKED 1 Menuitem will be checked
$TRAY_UNCHECKED 4 Menuitem will be unchecked
$TRAY_ENABLE 64 Menuitem will be enabled
$TRAY_DISABLE 128 Menuitem will be greyed out
$TRAY_FOCUS 256 Menuitem will be selected
$TRAY_DEFAULT 512 Menuitem will be set as default menuitem

State values can be summed up as for example $TRAY_CHECKED + $TRAY_DEFAULT sets the menuitem in an checked and default state.

To reset/delete the $TRAY_DEFAULT-state for a menuitem just use this function on the item with another state, for instance with $TRAY_ENABLE.

When you set $TRAY_DEFAULT state for a menuitem, the default behavior of primary double click on tray icon is to execute this default menuitem. To disable this behavior use Opt("TrayMenuMode", 4).

The above constants are defined in #include <TrayConstants.au3>.

Related

TrayCreateItem, TrayCreateMenu, TrayItemGetState, TraySetState

Example

#NoTrayIcon
#include <MsgBoxConstants.au3>
#include <StringConstants.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.

Example()

Func Example()
        Local $idSetState = TrayCreateItem("Set 'About' State")
        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 $idSetState
                                ; Set the 'About' item state to checked.
                                TrayItemSetState($idAbout, $TRAY_CHECKED)

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