Bone 发表于 2018-8-4 18:10:37

TrayCreateItem 循环菜单示例

写代码用到这个,论坛里搜索没找到相关信息
估计是太简单没人发
放一下做示例好了

#include <TrayConstants.au3>
#include <MsgBoxConstants.au3>
#include <WinAPIFiles.au3>
Opt("TrayMenuMode", 3)
Opt("TrayOnEventMode", 1) ; Enable TrayOnEventMode.

Local $MenuItem

;生成菜单
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))        ;请在 @TRAY_ID 处按F1
EndFunc ;==>About

Func _About()
MsgBox($MB_SYSTEMMODAL, "", "AutoIt 托盘菜单示例." & @CRLF & @CRLF & _
"AutoIt 版本: " & @AutoItVersion & @CRLF & _
"安装路径: " & StringLeft(@AutoItExe, StringInStr(@AutoItExe, "\", $STR_NOCASESENSEBASIC, -1) - 1)) ; 查找完整路径的文件夹.
EndFunc

Func _Close()
Exit
EndFunc

862228699 发表于 2018-8-4 23:37:13

什么码。。。

chzj589 发表于 2018-8-5 07:21:04

看看{:face (130):}

cfanpc 发表于 2018-8-5 09:58:45

进来看看大神的作品

fybhwsx 发表于 2018-8-5 11:14:58

学习学习。。。

229989799 发表于 2018-8-6 09:42:29

m 循环菜单示例

志艺风云 发表于 2018-8-6 12:14:00

回复看看。

志艺风云 发表于 2018-8-6 12:35:06

既然是基础,这样可能更易懂。
#include <TrayConstants.au3>
#include <MsgBoxConstants.au3>
#include <WinAPIFiles.au3>
Opt("TrayMenuMode", 3)
Opt("TrayOnEventMode", 1) ; Enable TrayOnEventMode.
Local $MenuItem
;生成菜单
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
                        MsgBox(0, @TRAY_ID, TrayItemGetText(@TRAY_ID))
                Case $MenuItem
                        MsgBox(0, @TRAY_ID, TrayItemGetText(@TRAY_ID))
                Case $MenuItem
                        MsgBox(0, @TRAY_ID, TrayItemGetText(@TRAY_ID))
                Case $MenuItem
                        MsgBox(0, @TRAY_ID, TrayItemGetText(@TRAY_ID))
                Case $MenuItem
                        MsgBox(0, @TRAY_ID, TrayItemGetText(@TRAY_ID))
                Case $MenuItem
                        MsgBox(0, @TRAY_ID, TrayItemGetText(@TRAY_ID))
                Case $MenuItem
                        MsgBox(0, @TRAY_ID, TrayItemGetText(@TRAY_ID))
                Case $MenuItem
                        MsgBox(0, @TRAY_ID, TrayItemGetText(@TRAY_ID))
                Case $MenuItem
                        MsgBox(0, @TRAY_ID, TrayItemGetText(@TRAY_ID))
                Case $MenuItem
                        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



redapple2008 发表于 2018-8-8 13:21:35

看看了,说不定还能用上

xiting521 发表于 2018-8-31 10:01:45

{:face (368):}
页: [1]
查看完整版本: TrayCreateItem 循环菜单示例