找回密码
 加入
搜索
查看: 2916|回复: 5

[AU3基础] <分享>For 循环“开始、暂停、结束”源码

[复制链接]
发表于 2011-7-31 09:17:24 | 显示全部楼层 |阅读模式
本帖最后由 lion.lee 于 2011-8-2 11:59 编辑

因为这个问题困扰了很久,在论坛搜索了很多大牛的代码,但离自己的要求多少有点距离,终于在不懈的尝试下完成了符合自己要求的东东,为更多像我一样的菜鸟,特将源码发上来,给大家参考一下
#include <ButtonConstants.au3>
#include <GUIConstantsEx.au3>
#include <WindowsConstants.au3>
Opt("GUIOnEventMode", 1)
#Region ### START Koda GUI section ### Form=
$Form1 = GUICreate("Form1", 623, 449, 192, 114)
$Button1 = GUICtrlCreateButton("开始", 48, 224, 113, 33)
$Button2 = GUICtrlCreateButton("暂停", 192, 224, 113, 33)
$Button3 = GUICtrlCreateButton("结束", 336, 224, 113, 33)
$Button4 = GUICtrlCreateButton("显示", 192, 136, 113, 33)
GUISetState(@SW_SHOW)
GUISetOnEvent($GUI_EVENT_CLOSE, "gui")
GUICtrlSetOnEvent($Button1, "gui")
GUICtrlSetOnEvent($Button2, "gui")
GUICtrlSetOnEvent($Button3, "gui")
#EndRegion ### END Koda GUI section ###
Global $start = False, $ipstart = True

While 1
        If $ipstart = True Then
                For $i = 1 To 40 Step 1
                        If $start = True And $ipstart = True Then
                                GUICtrlSetData($Button4, $i)
                        Else
                                While $start = False
                                        Sleep(100)
                                WEnd
                        EndIf
                        Sleep(100)
                Next
                $ipstart = False
        EndIf
        Sleep(100)
WEnd

Func gui()
        Switch @GUI_CtrlId
                Case $GUI_EVENT_CLOSE
                        Exit
                Case $Button1
                        $start = True
                        $ipstart = True
                        $i = 1
                Case $Button2
                        If $start = True Then
                                $start = False
                                GUICtrlSetData($Button2, "继续")
                        Else
                                $start = True
                                GUICtrlSetData($Button2, "暂停")
                        EndIf
                Case $Button3
                        $ipstart = False
        EndSwitch
EndFunc   ;==>gui
发表于 2011-7-31 10:20:28 | 显示全部楼层
回复 1# lion.lee


    只能说你搜得不够认真
http://www.autoitx.com/forum.php ... AD%BB%B7&page=1

不过,我也还没有解决如上面链接里我发的那个帖子,如何让两个同时不停地显示数字
 楼主| 发表于 2011-7-31 12:03:55 | 显示全部楼层
首先谢谢Happytc前辈的指点,我又多学了一点。那个帖子的内容对于我这种菜鸟稍微难了点。呵呵!
我需要开始、暂停、停止这3个按钮是为了仿优化大师的局域网扫描工具。谁有现成的代码,能不能发上来学习一下啊?多谢了!
发表于 2011-7-31 19:58:53 | 显示全部楼层
我一般都是把要做的事扔到一个函数里,然后AdlibRegister
当然这样问题也很多,比如函数本身的不宜再作循环,这样容易还是容易假死,必须引入全局变量,这也很危险。
发表于 2011-7-31 23:23:09 | 显示全部楼层
回复 4# bakefish


    一般少用AdlibRegister函数,它的确不合适处理窗口的事
还是用事件模式吧,虽然我也喜欢用消息循环模式。其实可以用事件模式,但把要做的主要事(函数)放在主循环里,这样比较清析点吧,纯是个人意见
发表于 2022-2-7 20:36:21 | 显示全部楼层

注册回调函数即可
您需要登录后才可以回帖 登录 | 加入

本版积分规则

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

GMT+8, 2024-5-3 18:31 , Processed in 0.080766 second(s), 23 queries .

Powered by Discuz! X3.5 Licensed

© 2001-2024 Discuz! Team.

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