找回密码
 加入
搜索
查看: 1914|回复: 9

[AU3基础] TrayCreateItem 循环菜单示例

[复制链接]
发表于 2018-8-4 18:10:37 | 显示全部楼层 |阅读模式
写代码用到这个,论坛里搜索没找到相关信息
估计是太简单没人发
放一下做示例好了

[mw_shl_code=applescript,true]#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))        ;请在 @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[/mw_shl_code]
发表于 2018-8-5 09:58:45 | 显示全部楼层
进来看看大神的作品
发表于 2018-8-6 09:42:29 | 显示全部楼层
m 循环菜单示例
发表于 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[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



发表于 2018-8-8 13:21:35 | 显示全部楼层
看看了,说不定还能用上
您需要登录后才可以回帖 登录 | 加入

本版积分规则

QQ|手机版|小黑屋|AUTOIT CN ( 鲁ICP备19019924号-1 )谷歌 百度

GMT+8, 2024-11-16 14:47 , Processed in 0.077972 second(s), 19 queries .

Powered by Discuz! X3.5 Licensed

© 2001-2024 Discuz! Team.

快速回复 返回顶部 返回列表