找回密码
 加入
搜索
查看: 7246|回复: 9

[AU3基础] 【已解决】痛苦的while循环

  [复制链接]
发表于 2010-6-18 22:38:39 | 显示全部楼层 |阅读模式
本帖最后由 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
论坛上各种方法都试了,用按钮都不行?

评分

参与人数 1金钱 +10 收起 理由
afan + 10 感谢主动将修改帖子分类为[已解决],请继续 ...

查看全部评分

发表于 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

评分

参与人数 1金钱 +20 收起 理由
afan + 20

查看全部评分

发表于 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

评分

参与人数 1金钱 +20 收起 理由
afan + 20

查看全部评分

 楼主| 发表于 2010-6-18 23:23:53 | 显示全部楼层
本帖最后由 mozha 于 2010-6-18 23:37 编辑

谢谢大家!
风行者的事件模式好用
问题解决了,
发表于 2010-6-19 00:31:46 | 显示全部楼层
谢谢楼主分享
发表于 2010-7-27 22:57:51 | 显示全部楼层
好东西。。。。
发表于 2013-4-13 18:38:09 | 显示全部楼层
试试看。。。
发表于 2014-5-28 21:12:48 | 显示全部楼层
好东西。。。。
您需要登录后才可以回帖 登录 | 加入

本版积分规则

QQ|手机版|小黑屋|AUTOIT CN ( 鲁ICP备19019924号-1 )谷歌 百度

GMT+8, 2024-5-18 09:04 , Processed in 0.077043 second(s), 20 queries .

Powered by Discuz! X3.5 Licensed

© 2001-2024 Discuz! Team.

快速回复 返回顶部 返回列表