TrayItemSetState
设置托盘菜单或项目的状态.
TrayItemSetState ( controlID, state )
参数
返回值
备注
状态表
State
|
值
|
状态注释
|
No Change
|
0
|
|
$TRAY_CHECKED
|
1
|
菜单项选中
|
$TRAY_UNCHECKED
|
4
|
菜单项未选中
|
$TRAY_ENABLE
|
64
|
菜单项激活
|
$TRAY_DISABLE
|
128
|
菜单项将变为灰色
|
$TRAY_FOCUS
|
256
|
菜单项选中(具有焦点)
|
$TRAY_DEFAULT
|
512
|
菜单项设置为默认菜单项
|
可以多个状态值相加, 例如: $TRAY_CHECKED + $TRAY_DEFAULT 设置菜单项选中且为默认菜单项.
要重置/删除菜单项的 $TRAY_DEFAULT 状态, 只需将其设置为另一个状态即可. 例如: $TRAY_ENABLE.
当您设置菜单项为 $TRAY_DEFAULT 状态时, 默认双击托盘图标执行此默认菜单项. 使用 Opt("TrayMenuMode", 4) 可禁用此行为.
上述常量需要 #include <TrayConstants.au3>.
相关
TrayCreateItem, TrayCreateMenu, TrayItemGetState, TraySetState
函数示例
#NoTrayIcon
#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.
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, "\", 0, -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
----------------------------------------
|