本帖最后由 xiehuahere 于 2012-11-26 14:32 编辑
回复 14# annybaby
有点意思了,但你这个关闭子窗口后再从托盘选择退出,还是弹出“从窗口中退出”,进入了错误的分支。
我给个示例代码吧:
#include <Constants.au3>
#include <GUIConstantsEx.au3>
#include <WindowsConstants.au3>
#include <StaticConstants.au3>
#include <GUIButton.au3>
Global $hGUI, $BtnClose, $BtnQuery
Global $hSubGUI, $BtnClose2
Global $hWinAbout
Opt("GUIOnEventMode", 1)
$hGUI = GUICreate("", 285, 45, -1, -1, $WS_POPUP, BitOR($WS_EX_TOPMOST, $WS_EX_TOOLWINDOW))
$BtnClose = GUICtrlCreateLabel("×", 269, 1, 14, 14, $SS_CENTER + $SS_CENTERIMAGE)
GUICtrlSetFont(-1, 10, 400, 0, "MS Sans Serif")
GUICtrlSetColor(-1, 0x000000)
GUICtrlSetResizing(-1, $GUI_DOCKALL)
GUICtrlSetOnEvent(-1, "_Exit")
$BtnQuery = GUICtrlCreateButton("Create Sub", 100, 18, 65, 26, $BS_DEFPUSHBUTTON)
GUICtrlSetOnEvent(-1, "_CreateSubGUI")
GUISetState()
Opt("TrayOnEventMode", 1)
Opt("TrayMenuMode", 1)
TraySetClick(16) ;释放鼠标右键显示托盘菜单
Local $TrayAbout = TrayCreateItem("About")
TrayItemSetOnEvent(-1, "_About")
TrayCreateItem("")
Local $TrayExit = TrayCreateItem("Exit")
TrayItemSetOnEvent(-1, "_Exit")
TraySetState()
While 1
Sleep(100)
WEnd
Func _CreateSubGUI()
$hSubGUI = GUICreate("", 720, 90, -1, -1, $WS_POPUP, BitOR($WS_EX_TOPMOST, $WS_EX_WINDOWEDGE), $hGUI)
$BtnClose2 = GUICtrlCreateButton("Close", 630, 3, 80, 25)
GUICtrlSetFont(-1, 10, 800, 0, "MS Sans Serif")
GUICtrlSetColor(-1, 0xFF0000)
GUICtrlSetOnEvent(-1, "_Exit")
GUISetState()
EndFunc
Func _About()
TrayItemSetState($TrayAbout, $TRAY_UNCHECKED + $TRAY_DISABLE)
$hWinAbout = GUICreate("About", 300, 200, -1, -1, Bitor($WS_CAPTION,$WS_SYSMENU), $WS_EX_TOPMOST)
GUISetOnEvent($GUI_EVENT_CLOSE, "_Exit")
GUISetState()
EndFunc
Func DestroyQueryWin()
If Not IsHWnd($hSubGUI) Then Return
GUIDelete($hSubGUI)
EndFunc
Func _Exit()
If @TRAY_ID = $TrayExit Then Exit
Switch @GUI_WinHandle
Case $hGUI
Exit
Case $hSubGUI
DestroyQueryWin()
Case $hWinAbout
GUIDelete($hWinAbout)
TrayItemSetState($TrayAbout, $TRAY_ENABLE)
EndSwitch
EndFunc
没有点过托盘图标的情况下,@TRAY_ID不存在。 |