xpban2006 发表于 2010-4-5 13:38:21

我想做一个程序运行时间实时显示的程序,帮忙~

我有个程序想实时显示运行了多长时间,格式:XX天XX时XX分XX秒,一点头绪没有,大家帮忙看看怎么做啊,谢谢啦~

l4ever 发表于 2010-4-5 14:40:51

http://l4ever.cn/archives/1310

afan 发表于 2010-4-5 15:09:21

本帖最后由 afan 于 2010-4-5 15:11 编辑

#include <Date.au3>

GUICreate('运行时间实时显示', 300, 100)
GUICtrlCreateLabel('本程序已运行:', 90, 70, 100, 15)
Dim $tl = GUICtrlCreateLabel('00天,00时,00分,00秒', 180, 70, 150, 15)
GUISetState()
Dim $timer = TimerInit(), $Day = 0
AdlibRegister('Timer', 500)

While 1

        Switch GUIGetMsg()
                Case -3
                        Exit
        EndSwitch

WEnd

Func Timer()
        Local $Secs, $Mins, $Hour, $Time, $ticks, $sTime
        $ticks = Int(TimerDiff($timer)) * 5000 ;这里*5000是为了测试,将时间提速5000倍
        If $ticks >= 86400000 Then
                $Day += 1
                $timer = TimerInit()
                $ticks = 0
        EndIf
        _TicksToTime($ticks, $Hour, $Mins, $Secs)
        $Time = StringFormat('%02s天,%02s时,%02s分,%02s秒', $Day, $Hour, $Mins, $Secs)
        If $sTime <> $Time Then GUICtrlSetData($tl, $Time)
        $sTime = $Time
EndFunc   ;==>Timer;注,第21行代码*5000是为了测试,将时间提速5000倍,实际应用则应取消*5000

xpban2006 发表于 2010-4-5 18:05:39

试试,谢谢!
页: [1]
查看完整版本: 我想做一个程序运行时间实时显示的程序,帮忙~