【已解决】痛苦的while循环
本帖最后由 mozha 于 2010-6-18 23:39 编辑$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)
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
论坛上各种方法都试了,用按钮都不行? 点击按钮后,在消息模式下是不会在未执行完而响应其它控件点击而中断的 $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 比较喜欢事件模式#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
本帖最后由 mozha 于 2010-6-18 23:37 编辑
谢谢大家!
风行者的事件模式好用
问题解决了,{:face (356):} 谢谢楼主分享 好东西。。。。 试试看。。。 好东西。。。。 好东西。。。。。
页:
[1]