找回密码
 加入
搜索
查看: 3249|回复: 6

如何通过clickon一个button去跳出另一个button触发的循环

  [复制链接]
发表于 2008-6-6 10:43:43 | 显示全部楼层 |阅读模式
大致代码是这样:
CREATE button1 和button2
While 1
        $nMsg = GUIGetMsg()
        Switch $nMsg
                Case $GUI_EVENT_CLOSE
                        Exit
                Case $Button1
                        while1
                                                wend  问题在这里,当这个循环开始以后,我希望用另一个button来使这个循环停止!
                Case $Button2
                        设法使button1的循环停止
        EndSwitch
WEnd
我试过如下方式,不过没成功: 在循环里的开头加上$nMSG的判断,如果$nMsg=button2的话就跳出循环.

我怀疑我这里有一点逻辑错误, 是不是在button1的循环里的时候, 程序是不会理会其他code的? 假如是这样,有没有其他方式可以实现?
发表于 2008-6-6 10:47:29 | 显示全部楼层
用事件模式
 楼主| 发表于 2008-6-6 11:01:18 | 显示全部楼层
请问事件模式是不是指koda里面的option->事件模式?
我这个GUI是用koda来生成code的, 但是我虽然选择了事件模式,但是实际效果却和loop模式一样
请教一下怎么设置?
发表于 2008-6-6 13:10:32 | 显示全部楼层
用do...until试试看
发表于 2008-6-6 14:06:55 | 显示全部楼层
这个问题我在写贪食蛇的时候遇到过,可以这样
#include <ButtonConstants.au3>
#include <GUIConstantsEx.au3>
#include <StaticConstants.au3>
#include <WindowsConstants.au3>
Opt("GUIOnEventMode", 1)
#Region ### START Koda GUI section ### Form=
$Form1 = GUICreate("Form1", 205, 76, 193, 125)
GUISetOnEvent($GUI_EVENT_CLOSE, "Form1Close")
$Label1 = GUICtrlCreateLabel("0", 16, 16, 108, 41)
$Button1 = GUICtrlCreateButton("循环", 136, 8, 57, 25, 0)
GUICtrlSetOnEvent(-1, "Button1Click")
$Button2 = GUICtrlCreateButton("暂停", 136, 40, 57, 25, 0)
GUICtrlSetOnEvent(-1, "Button2Click")
GUISetState(@SW_SHOW)
#EndRegion ### START Koda GUI section ### Form=

While 1
        Sleep(100)
WEnd

Func Button1Click()
AdlibEnable("test",100)
EndFunc   ;==>Button1Click

Func Button2Click()
AdlibDisable()
EndFunc   ;==>Button2Click
Func Form1Close()
        Exit
EndFunc   ;==>Form1Close

Func test()
                GUICtrlSetData($Label1, GUICtrlRead($Label1) + 1)
        EndFunc
        
发表于 2008-6-6 14:18:02 | 显示全部楼层
楼上的很赞...
发表于 2008-9-24 11:55:09 | 显示全部楼层
While 1
        $nMsg = GUIGetMsg()
        Switch $nMsg
                Case $GUI_EVENT_CLOSE
                        Exit
                Case $Button1
                        while 1
          $nMsg = GUIGetMsg()
            Switch $nMsg
                       Case $GUI_EVENT_CLOSE
                                Exit
                       Case $Button2
              ExitLoop
                         ----------
                        wend
      EndSwitch
WEnd

不知道这个循环套用,可否?
您需要登录后才可以回帖 登录 | 加入

本版积分规则

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

GMT+8, 2024-9-23 13:28 , Processed in 0.079979 second(s), 24 queries .

Powered by Discuz! X3.5 Licensed

© 2001-2024 Discuz! Team.

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