既然是基础,这样可能更易懂。
#include <TrayConstants.au3>
#include <MsgBoxConstants.au3>
#include <WinAPIFiles.au3>
Opt("TrayMenuMode", 3)
Opt("TrayOnEventMode", 1) ; Enable TrayOnEventMode.
Local $MenuItem[10]
;生成菜单
For $i = 0 To 9
$MenuItem[$i] = TrayCreateItem("菜单 " & $i)
TrayItemSetOnEvent(-1, "TrayEvent")
Next
TrayCreateItem("")
Local $TrayAbout = TrayCreateItem("关于(&A)")
TrayItemSetOnEvent(-1, "_About") ;设置该菜单点击时需要调用的函数名称
TrayCreateItem("")
Local $TrayClose = TrayCreateItem("退出(&X)")
TrayItemSetOnEvent(-1, "_Close")
TraySetOnEvent($TRAY_EVENT_PRIMARYDOUBLE, "TrayEvent") ;设置鼠标点击方式激活函数过程
TraySetOnEvent($TRAY_EVENT_PRIMARYDOUBLE, "_About")
TraySetOnEvent($TRAY_EVENT_PRIMARYDOUBLE, "_Close")
While 1
Sleep(100)
WEnd
Func TrayEvent()
;MsgBox(0, @TRAY_ID, TrayItemGetText(@TRAY_ID))
Switch @TRAY_ID
Case $MenuItem[0]
MsgBox(0, @TRAY_ID, TrayItemGetText(@TRAY_ID))
Case $MenuItem[1]
MsgBox(0, @TRAY_ID, TrayItemGetText(@TRAY_ID))
Case $MenuItem[2]
MsgBox(0, @TRAY_ID, TrayItemGetText(@TRAY_ID))
Case $MenuItem[3]
MsgBox(0, @TRAY_ID, TrayItemGetText(@TRAY_ID))
Case $MenuItem[4]
MsgBox(0, @TRAY_ID, TrayItemGetText(@TRAY_ID))
Case $MenuItem[5]
MsgBox(0, @TRAY_ID, TrayItemGetText(@TRAY_ID))
Case $MenuItem[6]
MsgBox(0, @TRAY_ID, TrayItemGetText(@TRAY_ID))
Case $MenuItem[7]
MsgBox(0, @TRAY_ID, TrayItemGetText(@TRAY_ID))
Case $MenuItem[8]
MsgBox(0, @TRAY_ID, TrayItemGetText(@TRAY_ID))
Case $MenuItem[9]
MsgBox(0, @TRAY_ID, TrayItemGetText(@TRAY_ID))
EndSwitch
EndFunc ;==>TrayEvent
Func _About()
MsgBox($MB_SYSTEMMODAL, "", "AutoIt 托盘菜单示例." & @CRLF & @CRLF & _
"AutoIt 版本: " & @AutoItVersion & @CRLF & _
"安装路径: " & StringLeft(@AutoItExe, StringInStr(@AutoItExe, "\", $STR_NOCASESENSEBASIC, -1) - 1)) ; 查找完整路径的文件夹.
EndFunc ;==>_About
Func _Close()
Exit
EndFunc ;==>_Close
|