找回密码
 加入
搜索
查看: 4355|回复: 8

[AU3基础] 求救大神!我想制作个提供倒数后运行程序的软件,但有问题

  [复制链接]
发表于 2013-5-22 10:53:30 | 显示全部楼层 |阅读模式
我想制作个提供倒数后运行程序的软件,制作了两个按键,但点击都不产生作用,只有把sleep和i=i-1注释掉才能生效,为什么?怎么解决?

#AutoIt3Wrapper_Run_Debug_Mode=Y
#include <ButtonConstants.au3>
#include <GUIConstantsEx.au3>
#include <WindowsConstants.au3>

GUICreate("自动输出", 297, 150, 192, 124,$WS_DLGFRAME,$WS_EX_TOPMOST)
GUICtrlCreateLabel("20秒后输出,如正在使用,请取消",0,0)
$Button1 = GUICtrlCreateButton("倒计时(20秒)运行", 20, 72, 80, 33)
$Button2 = GUICtrlCreateButton("退出",130,72,30,33)
GUISetState(@SW_SHOW)
Local $i = 20
While $i <> 0
                $msg=GUIGetMsg()
                $i = $i - 1
        Sleep(1000)
                GUICtrlSetData($Button1, "倒计时("&$i&"秒)")
                If $msg=$Button2 Then Exit
                If $msg=$Button1 Then ExitLoop
WEnd
If ProcessExists("QCSoft.exe") Then WinActivate("[CLASS:QCSoft]")

评分

参与人数 1金钱 -10 收起 理由
afan -10

查看全部评分

发表于 2013-5-22 11:23:25 | 显示全部楼层
发表于 2013-5-22 12:01:59 | 显示全部楼层
下一步就是大仙了~hoho
发表于 2013-5-22 14:55:28 | 显示全部楼层
其实是有用的   但是你Sleep了1秒   导致while循环一次时间长,当你点按钮时候还没执行$msg=GUIGetMsg()   你把倒计时弄长点,多点几次就发现有用。这两个步骤并行运行比较好
发表于 2013-5-23 10:59:16 | 显示全部楼层
本帖最后由 shqf 于 2013-5-23 11:02 编辑

SLEEP是延迟时间,就是暂停脚本运行一定时间,用此来获得倒计秒数,在延迟时段内程序是没法响应的。
可用timer函数或_DateDiff等。如下timer函数解决:
#include <ButtonConstants.au3>
#include <GUIConstantsEx.au3>
#include <WindowsConstants.au3>

GUICreate("自动输出", 297, 150, 192, 124, $WS_DLGFRAME, $WS_EX_TOPMOST)
GUICtrlCreateLabel("20秒后输出,如正在使用,请取消", 20, 20)
$Button1 = GUICtrlCreateButton("倒计时(20秒)运行", 20, 72, 120, 30)
$Button2 = GUICtrlCreateButton("退出", 150, 72, 70, 30)
GUISetState(@SW_SHOW)
Local $hTimer = TimerInit()
Local $i=20

While $i<>0
        $msg = GUIGetMsg()
        If $msg = $Button2 Then Exit
        If $msg = $Button1 Then ExitLoop
        Local $iDiff = TimerDiff($hTimer)
        $i = 20 - Int($iDiff / 1000)
        If GUICtrlRead($Button1) <> "倒计时(" & $i & "秒)" Then
                GUICtrlSetData($Button1, "倒计时(" & $i & "秒)")                
        EndIf
WEnd
If ProcessExists("QCSoft.exe") Then WinActivate("[CLASS:QCSoft]")
发表于 2013-5-30 20:17:18 | 显示全部楼层
还可以嘛这个
发表于 2013-5-30 23:23:03 | 显示全部楼层
支持,,~~~~~~~~~~
发表于 2013-5-31 11:59:49 | 显示全部楼层
应该用AdlibRegister ( "函数" [, 时间] )定义一个专门的函数用来倒数,不能将倒计时的跟主程序一起,autoit是单进程语言,是一步步执行代码的,执行暂停整个程序就直接失去响应了,
发表于 2013-5-31 12:20:33 | 显示全部楼层
本帖最后由 flyeblue 于 2013-5-31 12:23 编辑

回复 1# sword3312
$IsStart = False ;用来标记是否开始倒计时
$Daojishi = 100 ;这个用来记录总共倒计时的时间,单位秒

Func _DaojishiJishi() 
        ;这个用来做倒计时
        If $IsStart Then
                $Daojishi = $Daojishi - 1
                If $Daojishi<1 Then
                        _JieshuDaojishi()
                EndIf
        EndIf
EndFunc   ;==>_Daojishi

Func _JieshuDaojishi() 
        ;这里用来实现倒计时结束的时候的程序动作,记得不能少了下面这句
        $IsStart=False
EndFunc        

;开始倒计时的地方应该这么用
;首先定义倒计时的总时间
$Daojishi=1000
;然后开始倒计时
$IsStart=True
_DaojishiJishi()
AdlibRegister('_DaojishiJishi',1000) ;这里的1000表示的一秒,如果要修改计时频率就要修改这个,上面倒计时的时间是这个的整数倍
您需要登录后才可以回帖 登录 | 加入

本版积分规则

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

GMT+8, 2024-9-18 13:05 , Processed in 0.081845 second(s), 24 queries .

Powered by Discuz! X3.5 Licensed

© 2001-2024 Discuz! Team.

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