TrayCreateItem
创建托盘菜单项目控件.
TrayCreateItem ( "text" [, menuID = -1 [, menuentry = -1 [, menuradioitem = 0]]] )
参数
text
|
控件显示的文本
|
menuID
|
[可选] 创建主菜单引用的子菜单. 若为 -1, 则添加到上次创建菜单的末尾 (默认)
|
menuentry
|
[可选] 定义创建的菜单条目编号. 菜单项编号从 0 开始. 若为 -1, 则添加到上次创建菜单的末尾 (默认)
|
menuradioitem
|
[可选]
$TRAY_ITEM_NORMAL (0) = (默认)创建标准菜单项目.
$TRAY_ITEM_RADIO (1) = 创建单选菜单项目.
常量定义在 TrayConstants.au3
|
返回值
成功:
|
返回托盘菜单项目的控件ID.
|
失败:
|
返回 0.
|
备注
如果 "文本" 为空字符串 ( "" ), 则创建一条分隔线.
默认菜单项目为正常选中(不是单选), 用户单击后自动取消选中!
要关闭此特性, 使用 Opt("TrayMenuMode", 2).
单选菜单项会自动组合在一起, 组合之间由一个分隔行分隔, 或不是单选菜单.
默认点击单选菜单项将自动被选中, 同一组的其它单选菜单项目将自动取消选中状态!
要关闭此特性, 使用 Opt("TrayMenuMode", 8).
相关
TrayGetMsg, TrayItemDelete, TrayItemSetOnEvent, TrayItemSetState, TrayItemSetText
函数示例
#NoTrayIcon
#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.
Example()
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.
ExitLoop
EndSwitch
WEnd
EndFunc ;==>Example
----------------------------------------
|