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

[AU3基础] 帮我实现这个功能,计时功能

    [复制链接]
发表于 2010-9-18 01:14:50 | 显示全部楼层 |阅读模式
当我按下“开始”按钮时,
循环执行一个自定义函数,而就在按下“开始”按钮的同时,开始计时,当按下“停止”按钮时,自定义函数停止,
时间计时也停止,而显示运行了多久!

循环的函数不是跟时间一样,一秒循环一次的,循环时间可能10秒一次循环
发表于 2010-9-18 10:19:52 | 显示全部楼层
开始 执行 timerinit
停止 执行 timerdiff
发表于 2010-9-18 14:02:39 | 显示全部楼层
计时功能楼上正解。。。
 楼主| 发表于 2010-9-18 17:40:14 | 显示全部楼层
回复 2# liufenglg


    我还是举个例子吧,这个例子里,时间是按我循环的时间跳的,并不是我想要的每秒计时
例子有点傻
#include <ButtonConstants.au3>
#include <GUIConstantsEx.au3>
#include <WindowsConstants.au3>
#include <StaticConstants.au3>
#include <Date.au3>

Opt("GUIOnEventMode", 1)
#Region ### START Koda GUI section ### Form=C:\Documents and Settings\Administrator\桌面\例子.au3
$Form1 = GUICreate("例子",160,100)
GUISetOnEvent($GUI_EVENT_CLOSE, "Form1Close")
GUISetOnEvent($GUI_EVENT_MINIMIZE, "Form1Minimize")
GUISetOnEvent($GUI_EVENT_MAXIMIZE, "")
GUISetOnEvent($GUI_EVENT_RESTORE, "Form1Restore")
$Label1 = GUICtrlCreateLabel("已经运行0次",8,10,90,25)
GUICtrlSetColor(-1,0xFF0000)
$Label2 = GUICtrlCreateLabel("运行时间:    00时00分00秒",8,50,90,50)
$Button1 = GUICtrlCreateButton("开始",100,10,50,25)
GUICtrlSetOnEvent(-1,"Button1Click")
$Button2 = GUICtrlCreateButton("停止",100,50,50,25)
GUICtrlSetOnEvent(-1,"Button2Click")
GUISetState(@SW_SHOW)
#EndRegion ### END Koda GUI section ###

Local $Hour, $Mins, $Secs , $timer , $t = 0 ,$Time

While 1
        Sleep(500)
WEnd



Func Button1Click()
        
        $timer = TimerInit()
        AdlibRegister("Timer",50)
        AdlibRegister("set",50)
EndFunc

Func Button2Click()
        AdlibUnRegister("set")
EndFunc

Func set()
        $t += 1
                Sleep(5000) ;之所以这里加上延时,是因为我需要的那个程序这里需要停顿一下,具体时间由变量控制,这里举个例子,停10秒        
                GUICtrlSetColor($Label1,0xFFFF00)
                Sleep(6000)
                GUICtrlSetColor($Label1,0xFF0000)
                GUICtrlSetData($Label1, "已经运行"&$t&"次")
EndFunc

Func Timer();计时运算函数
        
        _TicksToTime(Int(TimerDiff($timer)), $Hour, $Mins, $Secs)
        Local $sTime = $Time
        $Time = StringFormat("%02i时%02i分%02i秒", $Hour, $Mins, $Secs)
        If $sTime <> $Time Then GUICtrlSetData($Label2, "运行时间:    "&$Time)
EndFunc


Func Form1Close()
        Exit
EndFunc

Func Form1Minimize()
        
EndFunc

Func Form1Maximize()
        
EndFunc

Func Form1Restore()
        
EndFunc
发表于 2010-9-18 17:55:14 | 显示全部楼层
回复 4# riverboat2
不是已经回答你的吗?
还有问题?
 楼主| 发表于 2010-9-18 18:17:01 | 显示全部楼层
回复 5# 3mile


    哦,不是,第一次提问,早上重复提了这个问题,所以看这个有回答就想多参考参考的
你那个回答过的问题,我已经给回复了~帮忙再看下,SORRY
 楼主| 发表于 2010-9-18 18:18:02 | 显示全部楼层
回复 5# 3mile


下次不再重复提问了,有错必改!
您需要登录后才可以回帖 登录 | 加入

本版积分规则

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

GMT+8, 2024-9-21 20:38 , Processed in 0.079168 second(s), 21 queries .

Powered by Discuz! X3.5 Licensed

© 2001-2024 Discuz! Team.

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