[已解决][自问自答][方便搜索]执行死循环导致GUI按键不响应的解决方案
本帖最后由 easefull 于 2011-4-18 03:38 编辑貌似,这已经是AutoIt的经典GUI问题了.
原贴地址:http://www.autoitx.com/forum.php?mod=viewthread&tid=16334
示例:
#include <GUIConstantsEx.au3>
$Form1= GUICreate("游戏", 351, 271, 192, 124)
$Label1 = GUICtrlCreateLabel("---", 32, 64, 80, 20)
$Button1 = GUICtrlCreateButton("开始", 112, 16, 43, 25)
$Button4 = GUICtrlCreateButton("停止", 180, 16, 43, 25)
GUISetState(@SW_SHOW)
Global $new = 0
Local $msg
While 1
$msg = GUIGetMsg()
Select
Case $msg = $GUI_EVENT_CLOSE
ExitLoop
Case $msg = $Button1 ;开始
$i = 1
_Change()
Case $msg = $Button4 ;停止
$i = 0
_Change()
EndSelect
WEnd
GUIDelete()
Func _Change()
While $i
$new = $new + Random(-10,10,1)
GUICtrlSetData($Label1,$new)
Sleep(1000)
If ( $i = 0 ) Then
ExitLoop
EndIf
WEnd
EndFunc
本帖最后由 easefull 于 2011-4-18 03:33 编辑
消息模式的解决方案
作者:水木子
来源:http://www.autoitx.com/forum.php?mod=redirect&goto=findpost&ptid=16334&pid=177960&fromuid=7652895$Form1 = GUICreate("游戏", 350, 280)
$Label1 = GUICtrlCreateLabel("---", 32, 64, 80, 20)
$Button1 = GUICtrlCreateButton("开始", 112, 16, 43, 25)
$Button4 = GUICtrlCreateButton("停止", 180, 16, 43, 25)
GUISetState()
While 1
$msg = GUIGetMsg()
Select
Case $msg = -3
ExitLoop
Case $msg = $Button1 ;开始
Dim $new
AdlibRegister('_Change', 1000)
Case $msg = $Button4 ;停止
AdlibUnRegister('_Change')
MsgBox(0, '', '已停止!')
EndSelect
WEnd
Func _Change()
$new = $new + Random(-10, 10, 1)
GUICtrlSetData($Label1, $new)
EndFunc ;==>_Change 本帖最后由 easefull 于 2011-4-18 03:34 编辑
事件模式的解决方案
作者:风行者
来源:http://www.autoitx.com/forum.php?mod=redirect&goto=findpost&ptid=16334&pid=177962&fromuid=7652895
#include <GUIConstantsEx.au3>
Opt("GUIOnEventMode",1)
$Form1 = GUICreate("游戏", 351, 271, 192, 124)
GUISetOnEvent($GUI_EVENT_CLOSE,"close")
$Label1 = GUICtrlCreateLabel("---", 32, 64, 80, 20)
$Button1 = GUICtrlCreateButton("开始", 112, 16, 43, 25)
GUICtrlSetOnEvent(-1,"button1")
$Button4 = GUICtrlCreateButton("停止", 180, 16, 43, 25)
GUICtrlSetOnEvent(-1,"button4")
GUISetState(@SW_SHOW)
Global $i = False
While 1
Local $new
If $i = True Then
$new = $new + Random(-10,10,1)
GUICtrlSetData($Label1,$new)
EndIf
Sleep(1000)
WEnd
GUIDelete()
Func close()
Exit
EndFunc
Func button1()
$i = True
EndFunc
Func button4()
$i = False
EndFunc 这个经典呀,波垂下来 看不懂。。。。。。。
页:
[1]