找回密码
 加入
搜索
查看: 10170|回复: 18

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

 火.. [复制链接]
发表于 2013-11-20 13:25:03 | 显示全部楼层 |阅读模式
本帖最后由 solox 于 2013-11-20 13:26 编辑

#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
        Sleep(10)
WEnd

Func _FormClose()
        GUIDelete($Form)
        Exit
EndFunc

Func _Start()
        $start = 1
        While $start
                循环体
        WEnd
EndFunc

Func _Stop()
        $start = 0
WEnd
发表于 2013-11-20 15:37:02 | 显示全部楼层
不懂,按我的理解应该是跳不出循环的,不知道有没有DoEvents( )这类函数方法,我还有一个不理解是:为什么
GUISetOnEvent这类函数可以跳出第一个循环体运行,按照流程程序应该在While 1   Sleep(10) WEnd中死循环,不能接受任何消息,求解惑
发表于 2013-11-20 15:56:00 | 显示全部楼层
不知以下代码如何,没有循环,只需判断,能满足楼主要求吗。
#include <GUIConstants.au3>
Opt("GUIOnEventMode", 1)
Global $start = False
$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)
WEnd

Func _FormClose()
        GUIDelete($Form)
        Exit
EndFunc   ;==>_FormClose

Func _Start()
        $start = True
        AdlibRegister("xh",100)
EndFunc   ;==>_Start

Func xh()
        If $start Then
                ConsoleWrite($start & @CRLF);~                 循环体
        Else
                AdlibUnRegister("xh")
        EndIf
EndFunc   ;==>xh


Func _Stop()
        $start = False
EndFunc   ;==>_Stop

评分

参与人数 1金钱 +10 收起 理由
solox + 10 感谢分享

查看全部评分

 楼主| 发表于 2013-11-20 18:53:04 | 显示全部楼层
发哥,谢谢,我的循环体里面的时间因为各个实时因素的不同,延时会不同,应该无法用 AdlibRegister("xh",100) 固定100毫秒扫一次吧?
发表于 2013-11-20 19:44:15 | 显示全部楼层
回复 4# solox

可以这样子:
Global $start = 0
$Form = GUICreate("Test", 420, 200)
$button1 = GUICtrlCreateButton("开始循环", 15, 10)
$button2 = GUICtrlCreateButton("停止循环", 15, 40)
GUISetState(@SW_SHOW)

While 1
        $msg = GUIGetMsg()
        Switch $msg
                Case -3
                        GUIDelete($Form)
                        Exit
                Case $button1
                        $start = 1                
                        While $start
                                ConsoleWrite($start & @CRLF)
                                $start += 1
                                Switch GUIGetMsg()
                                        Case -3
                                                GUIDelete($Form)
                                                Exit
                                        Case $button2
                                                $start = 0
                                EndSwitch                                
                                Sleep(10)                                
                        WEnd
        EndSwitch
WEnd

评分

参与人数 1金钱 +10 收起 理由
solox + 10 感谢分享

查看全部评分

 楼主| 发表于 2013-11-20 19:54:01 | 显示全部楼层
回复 5# user3000


   谢谢,这个在理想状态是可以的,问题就是如果ConsoleWrite($start & @CRLF)这一句是一大串代码呢?基本上超过100毫秒,这种写法就不行了,GUIGetMsg()大部分情况会得到$GUI_EVENT_MOUSEMOVE。
发表于 2013-11-20 20:01:29 | 显示全部楼层
回复 6# solox


    是啊。处理过多东西是不适合。
完美解决你的问题必须用多线程,但AU3很难做到!
发表于 2013-11-20 20:38:12 | 显示全部楼层
回复 4# solox


    这个时间可以改,可以把你的循环发上来大家看下~
 楼主| 发表于 2013-11-20 21:20:12 | 显示全部楼层
本帖最后由 solox 于 2013-11-20 21:22 编辑

回复 8# haijie1223


Func _Start()
        $start = 1
        While $start
                For $i = 1 To $arrTotal
                        If $arr[$i] = True Then
                                FileWrite($LogFile,@YEAR &"-"& @MON &"-"& @MDAY &" "& @HOUR &":"& @MIN &":"& @SEC & " arr[" & $i & "] is true")
                        Else
                                Sleep(200)
                                _ReWriteArr() ;重排剩余数组函数
                                $i-=$i
                        EndIf
                Next
        WEnd
EndFunc


实际内容比这个要复杂的多,无法按“停止循环”按钮停止,头痛
发表于 2013-11-20 21:41:09 | 显示全部楼层
回复 9# solox


    似乎不是很复杂,我看可以直接放进去。
_ReWriteArr() 可否发上来~
 楼主| 发表于 2013-11-20 21:46:52 | 显示全部楼层
回复 10# haijie1223


   发哥,800多行代码啊。。。主要是无法控制_ReWriteArr()的运行时间,需要Ping服务器,服务器给了反应再继续运行,这个时间无法控制,我测试过,快则几十毫秒,慢则近10秒,而我又不想以最慢的10秒为准,这样这个程序永远不可能快。
发表于 2013-11-20 22:03:29 | 显示全部楼层
回复 11# solox


   嗯,如果这样的话,就给ping加上个超时参数吧~虽然不是很准确,起码给程序可操控性。
发表于 2013-11-20 22:42:22 | 显示全部楼层
看了楼上几位前辈的    向  发哥  3000  看齐~~~~~~~~~·
小弟倒是跳出来了    但跳得很是不雅观   不知楼主是否能接受   
#include <GUIConstants.au3>
Opt("GUIOnEventMode", 1)
HotKeySet('a','_Stop')
$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)
WEnd
 
Func _FormClose()
        GUIDelete($Form)
        Exit
EndFunc
 
Func _Start()
        IniWrite ( @ScriptDir&"\文件名.ini", "字段名", "键名",'')
        Do 
                MsgBox(0,0,'还在跳,还在跳。。。')
        Until IniRead(@ScriptDir&"\文件名.ini", "字段名", "键名",0)
        MsgBox(0,0,'没电了')
EndFunc
 
Func _Stop()
        IniWrite ( @ScriptDir&"\文件名.ini", "字段名", "键名",1)
EndFunc

评分

参与人数 1金钱 +10 收起 理由
solox + 10 感谢分享

查看全部评分

 楼主| 发表于 2013-11-20 23:48:53 | 显示全部楼层
回复 13# 魔导


    你这个跟我的原程序是异曲同工,当_Start函数很大时,AU3对_Stop()函数的响应非常不好,甚至是忽略。
发表于 2013-11-21 00:30:03 | 显示全部楼层
回复 14# solox
那可以考虑用多进程代替,尽量简化循环函数,把循环中复杂部分做成另一EXE,每次调用时向其传递不同参数即可。
您需要登录后才可以回帖 登录 | 加入

本版积分规则

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

GMT+8, 2024-5-3 07:06 , Processed in 0.092006 second(s), 29 queries .

Powered by Discuz! X3.5 Licensed

© 2001-2024 Discuz! Team.

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