# 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: | Returns 1.
Failure: | Returns 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.

Related

TrayItemGetState

Example

#Include <Constants.au3>
#NoTrayIcon
Opt("TrayMenuMode",1) ; Default tray menu items (Script Paused/Exit) will not be shown.
$chkitem = TrayCreateItem("Check it")
TrayCreateItem("")
$checkeditem = TrayCreateItem("Checked")
TrayCreateItem("")
$exititem = TrayCreateItem("Exit")
TraySetState()
While 1
$msg = TrayGetMsg()
Select
Case $msg = 0
ContinueLoop
Case $msg = $chkitem
TrayItemSetState($checkeditem,$TRAY_CHECKED)
Case $msg = $exititem
ExitLoop
EndSelect
WEnd
Exit