[消息循环]窗体循环和拖盘循环问题【已解决】
本帖最后由 pp648852 于 2012-2-5 21:53 编辑#NoTrayIcon
Opt("TrayMenuMode", 1 + 2)
#include <ButtonConstants.au3>
#include <GUIConstantsEx.au3>
#include <WindowsConstants.au3>
#region ### START Koda GUI section ### Form=
$Form1 = GUICreate("Form1", 320, 200)
$Button1 = GUICtrlCreateButton("Button1", 24, 152, 75, 25)
$Button2 = GUICtrlCreateButton("Button2", 208, 152, 75, 25)
Global $prefsitem = TrayCreateItem("参数选择")
TrayCreateItem("")
Global $aboutitem = TrayCreateItem("关于...")
TrayCreateItem("")
Global $exititem = TrayCreateItem("退出")
GUISetState(@SW_SHOW)
TraySetState()
#endregion ### END Koda GUI section ###
Global $XyInfo
_MouseInfo()
_Main()
Exit
Func _MouseInfo()
While 1
$XyInfo = GUIGetCursorInfo()
If $XyInfo < 0 Or $XyInfo < -31 Or _
$XyInfo > 320 Or $XyInfo > 200 Then
;~ MsgBox(16,'提示','已超出窗口范围')
_Tray()
Else
ExitLoop
EndIf
WEnd
EndFunc ;==>_MouseInfo
Func _Main()
While 1
$nMsg = GUIGetMsg()
Switch $nMsg
Case $GUI_EVENT_CLOSE
Exit
Case $GUI_EVENT_MINIMIZE
;~ WinWaitActive($Form1)
Case $Button1
MsgBox(0, '测试1', '只是一个测试')
Case $Button2
MsgBox(0, '测试2', '只是一个测试')
EndSwitch
_MouseInfo()
WEnd
EndFunc ;==>_Main
Func _Tray()
While 1
Local $msg = TrayGetMsg()
Select
Case $msg = $prefsitem
MsgBox(64, "参数选择:", "系统版本:" & @OSVersion)
Case $msg = $aboutitem
MsgBox(64, "关于:", "AutoIt3-托盘示例.")
Case $msg = $exititem
Exit
EndSelect
_MouseInfo()
WEnd
EndFunc ;==>_Tray
点击最小化后,程序出错退出,请高手帮帮忙看看代码!
我想让它“点击最小化后,跳到拖盘循环”
还有移出窗体范围再移进,GUI窗体就无响应,怎么回事?
本帖最后由 半芯竹 于 2012-2-5 21:02 编辑
回复 1# pp648852
#include <GuiConstantsEx.au3>
#include <GUIEdit.au3>
#Include <APIConstants.au3>
#Include <WinAPIEx.au3>
#include <ButtonConstants.au3>
#include <EditConstants.au3>
#include <WindowsConstants.au3>
#include <Constants.au3>
#NoTrayIcon
Opt("TrayOnEventMode", 1)
Opt("TrayMenuMode",1+2)
Opt("TrayAutoPause",0)
#region ### START Koda GUI section ### Form=
$Form1 = GUICreate("Form1", 320, 200,-1,-1,-1, -1, WinGetHandle(AutoItWinGetTitle()))
$Button1 = GUICtrlCreateButton("Button1", 24, 152, 75, 25)
$Button2 = GUICtrlCreateButton("Button2", 208, 152, 75, 25)
Global $prefsitem = TrayCreateItem("参数选择")
TrayItemSetOnEvent($prefsitem, "select1")
Global $aboutitem = TrayCreateItem("关于...")
TrayItemSetOnEvent($aboutitem, "aboutscript")
Global $exititem = TrayCreateItem("退出")
TrayItemSetOnEvent($exititem, "ExitScript")
GUISetState(@SW_SHOW)
TraySetState()
#endregion ### END Koda GUI section ###
TraySetOnEvent ($TRAY_EVENT_PRIMARYDOWN,'show')
TraySetClick (8)
While 1
Switch GUIGetMsg($Form1)
Case $GUI_EVENT_MINIMIZE
GUISetState(@SW_HIDE, $Form1)
Case $GUI_EVENT_CLOSE
ExitScript()
Case $Button1
MsgBox(0, '测试1', '只是一个测试')
Case $Button2
MsgBox(0, '测试2', '只是一个测试')
EndSwitch
WEnd
Func Select1()
MsgBox(0,0,'This is a test!')
EndFunc
Func ExitScript()
Exit
EndFunc
Func aboutscript()
MsgBox(0,"关于本程序!","程序版本:2012.01.20"&@LF&"编译时间:20012.01.20 "&@LF&"程序作者:半芯竹."&@LF&"版权所有:Copyright(c) 2012 半芯竹 ."&@LF&"My Blog :JosonYang.Blog.163.com.")
EndFunc
Func show()
GUISetState(@SW_SHOW, $Form1)
WinActivate($Form1)
EndFunc 回复 2# 半芯竹
只能采用“OnEvent模式”啊? 回复 3# pp648852
这样子有啥不好呢?那你有啥高见呢?老大。。。。 本帖最后由 pp648852 于 2012-2-5 21:15 编辑
"怎么不能加亮啊" 回复 4# 半芯竹
“OnEvent模式”我还不会{:face (303):} 本帖最后由 pp648852 于 2012-2-5 21:48 编辑
回复 4# 半芯竹
我把代码简化了!
#NoTrayIcon
#include <GuiConstantsEx.au3>
#include <GUIEdit.au3>
#include <APIConstants.au3>
#include <WinAPIEx.au3>
#include <ButtonConstants.au3>
#include <EditConstants.au3>
#include <WindowsConstants.au3>
#include <Constants.au3>
Opt("TrayOnEventMode", 1)
Opt("TrayMenuMode", 1 + 2)
#region ### START Koda GUI section ###
$Form1 = GUICreate("Form1", 320, 200)
$Button1 = GUICtrlCreateButton("Button1", 24, 152, 75, 25)
$Button2 = GUICtrlCreateButton("Button2", 208, 152, 75, 25)
Global $prefsitem = TrayCreateItem("参数选择")
TrayItemSetOnEvent($prefsitem, "select1")
Global $aboutitem = TrayCreateItem("关于...")
TrayItemSetOnEvent($aboutitem, "aboutscript")
Global $exititem = TrayCreateItem("退出")
TrayItemSetOnEvent($exititem, "ExitScript")
GUISetState(@SW_SHOW)
TraySetState()
#endregion ### END Koda GUI section ###
TraySetOnEvent($TRAY_EVENT_PRIMARYDOWN, 'show')
TraySetClick(8)
While 1
Switch GUIGetMsg()
Case $GUI_EVENT_MINIMIZE
GUISetState(@SW_HIDE, $Form1)
Case $GUI_EVENT_CLOSE
ExitScript()
Case $Button1
MsgBox(0, '测试1', '只是一个测试')
Case $Button2
MsgBox(0, '测试2', '只是一个测试')
EndSwitch
WEnd
Func Select1()
MsgBox(0, 0, 'This is a test!')
EndFunc ;==>Select1
Func ExitScript()
Exit
EndFunc ;==>ExitScript
Func aboutscript()
MsgBox(0, "关于本程序!", "程序版本:2012.01.20" & @LF & "编译时间:20012.01.20 " & @LF & "程序作者:半芯竹." & @LF & "版权所有:Copyright(c) 2012 半芯竹 ." & @LF & "My Blog :JosonYang.Blog.163.com.")
EndFunc ;==>aboutscript
Func show()
GUISetState(@SW_SHOW, $Form1)
WinActivate($Form1)
EndFunc ;==>show
回复 7# pp648852
你这也叫简化。什么人啊。哎。。服你了。。。我不想回帖都成水贴。。。。
如果解决了,就编辑标题+[已解决] 很有用,又学了一种方法
页:
[1]