#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