找回密码
 加入
搜索
楼主: solox

[GUI管理] 为什么没有办法跳出循环?

 火.. [复制链接]
 楼主| 发表于 2013-11-21 21:09:45 | 显示全部楼层
回复 15# user3000


    嗯,看来要好好学一学多进程了
发表于 2013-11-26 23:18:03 | 显示全部楼层
回复  魔导


    你这个跟我的原程序是异曲同工,当_Start函数很大时,AU3对_Stop()函数的响应非常不好 ...
solox 发表于 2013-11-20 23:48



    这类问题已讨论较多次了~
13#肥猫的代码肯定可以实现一楼不能实现的问题,HotKeySet 优先级是很高的。
发表于 2013-11-27 00:24:30 | 显示全部楼层
本帖最后由 骗子 于 2013-11-27 00:31 编辑

不知道是不是这个效果?抄袭某位论坛前辈的,缺点是如果循环命令耗时很长的话,点击停止以后并不会立即停止,而是等操作完完成一次循环才会停,
能想到的方法只有在循环中添加检测$start的值,如果是0的话直接中断返回。
#include <GUIConstants.au3>
Opt("GUIOnEventMode", 1)
Global $start = 0, $i = 1
$Form = GUICreate("Test", 420, 200)
$button1 = GUICtrlCreateButton("开始循环", 15, 10)
$button2 = GUICtrlCreateButton("停止循环", 15, 40)
GUISetOnEvent($GUI_EVENT_CLOSE, "_FormClose")
GUICtrlSetOnEvent($button1, "_Start")
GUICtrlSetOnEvent($button2, "_Stop")
GUISetState(@SW_SHOW)

While 1
        Sleep(10)
        If $start = 1 Then _xunhuan()
WEnd

Func _FormClose()
        GUIDelete($Form)
        Exit
EndFunc   ;==>_FormClose
Func _xunhuan()
;~   循环体
        $i += 1
        WinSetTitle($Form, '', $i)
        Sleep(2000)
        If $start = 0 Then Return
        WinSetTitle($Form, '', "Test")
        Sleep(2000)
EndFunc   ;==>_xunhuan
Func _Start()
        $start = 1
EndFunc   ;==>_Start

Func _Stop()
        $start = 0
EndFunc   ;==>_Stop
发表于 2013-11-27 01:08:18 | 显示全部楼层
回复 1# solox

郁闷,核心中的主循环不用,一直闲着,后面又说太忙,处理不了..
#include <GUIConstants.au3>
Opt("GUIOnEventMode", 1)
Global $start = 0
$Form = GUICreate("Test",420,200)
$button1 = GUICtrlCreateButton("开始循环",15,10)
$button2 = GUICtrlCreateButton("停止循环",15,40)
GUISetOnEvent($GUI_EVENT_CLOSE,"_FormClose")
GUICtrlSetOnEvent($button1,"_Start")
GUICtrlSetOnEvent($button2,"_Stop")
GUISetState(@SW_SHOW)
 
While 1
         While $start
                ConsoleWrite(Random()&@LF)
                                Sleep(10)
                wEnd
                Sleep(10)
WEnd
 
Func _FormClose()
        GUIDelete($Form)
        Exit
EndFunc
 
Func _Start()
        $start = 1
EndFunc
 
Func _Stop()
        $start = 0
EndFunc
您需要登录后才可以回帖 登录 | 加入

本版积分规则

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

GMT+8, 2024-5-3 02:47 , Processed in 0.068475 second(s), 13 queries .

Powered by Discuz! X3.5 Licensed

© 2001-2024 Discuz! Team.

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