mozha 发表于 2010-6-18 22:38:39

【已解决】痛苦的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
论坛上各种方法都试了,用按钮都不行?

afan 发表于 2010-6-18 22:48:13

点击按钮后,在消息模式下是不会在未执行完而响应其它控件点击而中断的

水木子 发表于 2010-6-18 22:55:51

$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

风行者 发表于 2010-6-18 23:20:23

比较喜欢事件模式#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:23:53

本帖最后由 mozha 于 2010-6-18 23:37 编辑

谢谢大家!
风行者的事件模式好用
问题解决了,{:face (356):}

zhongzijie 发表于 2010-6-19 00:31:46

谢谢楼主分享

link369 发表于 2010-7-27 22:57:51

好东西。。。。

pris 发表于 2013-4-13 18:38:09

试试看。。。

qsy666888 发表于 2014-5-28 21:12:48

好东西。。。。

傻娃 发表于 2019-9-23 19:34:51

好东西。。。。。
页: [1]
查看完整版本: 【已解决】痛苦的while循环