最近在写一个运用html页面做控制界面的程序,程序已经写好,想完善下,实现一个这样的功能:
当点击关闭窗口的按钮,程序隐藏,只可以看到系统托盘程序图标;
当左键点击该系统托盘图标,立即显示隐藏掉的窗口;
当点鼠标右键可以设置一些参数。
就像金山词霸那样。
这段代码实际运行的效果不满足我的需求。
#include <Constants.au3>
#NoTrayIcon
Opt("TrayMenuMode", 1)
Opt("trayOnEventMode", 1)
$Quit = TrayCreateItem("退出")
TrayItemSetOnEvent($Quit, "TrayMsg")
TraySetOnEvent($TRAY_EVENT_PRIMARYDOWN, "TrayMsg")
TraySetState()
While 1
Sleep(500)
WEnd
Func TrayMsg()
Switch @TRAY_ID
Case $TRAY_EVENT_PRIMARYDOWN
MsgBox(48, "提示", "单击了鼠标左键")
Case $Quit
Exit
EndSwitch
EndFunc
如下这段代码,比较接近,但却又没有右键设置功能了#include <GUIConstants.au3>
#include <IE.au3>
#include <Constants.au3>
Opt("TrayOnEventMode",1)
Opt("TrayAutoPause",0)
Opt("TrayMenuMode",1) ; Default tray menu items (Script Paused/Exit) will not be shown.
Local $wintitle="whatever"
$LogViewer = GUICreate($wintitle,300,300)
$Button_1 = GuiCtrlCreateButton("true exit", 10, 10, 100, 40)
guisetstate()
TraySetOnEvent($TRAY_EVENT_PRIMARYDOWN, "showWin")
Local $infoitem = TrayCreateItem("showWin")
TrayItemSetOnEvent(-1,"showWin")
TrayCreateItem("")
Local $exititem = TrayCreateItem("Exit")
TrayItemSetOnEvent(-1,"ExitScript")
TrayCreateItem("")
Local $msg = TrayCreateItem("test")
TrayItemSetOnEvent(-1,"test")
TrayCreateItem("")
TraySetClick(0);0的时候单击即可显示主界面,但没法显示系统托盘的菜单了;1的时候菜单有效,$TRAY_EVENT_PRIMARYDOWN也响应
TraySetState()
While 1
$nMsg = GUIGetMsg()
Switch $nMsg
Case $GUI_EVENT_CLOSE
exit
case $GUI_EVENT_MINIMIZE
WinSetState($wintitle,"",@SW_HIDE)
case $Button_1
exit
EndSwitch
Wend
Func showWin()
GUISetState(@SW_RESTORE, $LogViewer)
WinSetState($wintitle,"",@SW_SHOW)
EndFunc
func test()
MsgBox(0,"","test")
EndFunc
Func ExitScript()
Exit
EndFunc
[ 本帖最后由 ccxw1983 于 2009-3-26 13:00 编辑 ] |