本帖最后由 ahkang 于 2009-12-1 03:00 编辑
同样也有修改成 UDF 了的,效果如图:
UDF 调用脚本如下:#InClude "Count_Down.Au3"
$Time=30
$i=$Time
$Caption='倒计时的 UDF 函数测试窗口'
$Font='楷体_GB2312'
;$FontColor=0x008000 ;设置字体为绿色
$FontColor=0xFF0000 ;设置字体为红色
$Program=@WindowsDir&'\NotePad.eXe'
_CountDown()
UDF 文件内容如下(提示:UDF 文件名为“Count_Down.Au3”):#InClude <ButtonConstants.Au3>
#InClude <GUIConstantsEx.Au3>
#InClude <ProgressConstants.Au3>
#InClude <StaticConstants.Au3>
#InClude <WindowsConstants.Au3>
Global $Time
Global $i
Global $Program
Global $Form1
Global $Label1
Global $Progress1
Global $Button1
Global $Button2
;----------------------------------------------------------------------------
Global $Caption
Global $Font
Global $FontColor
Global $YES='确定(&Y)'
Global $Exit='退出(&X)'
Func _CountDown()
;----------------------------------------------------------------------------
#Region ### START Koda GUI section ### Form=
$Form1 = GUICreate($Caption, 350, 172, Default, Default)
$Label1 = GUICtrlCreateLabel($Time & ' 秒后将进入主程序!', 56, 32, 280, 28)
GUICtrlSetFont(-1, 18, 400, 0, $Font)
GUICtrlSetColor(-1, $FontColor)
$Progress1 = GUICtrlCreateProgress(8, 88, 333, 17)
$Button1 = GUICtrlCreateButton($YES&' → 还有 '& $Time & ' 秒', 53, 128, 158, 25, 0)
$Button2 = GUICtrlCreateButton($Exit, 220, 128, 73, 25, 0)
GUISetState(@SW_SHOW)
#EndRegion ### END Koda GUI section ###
;----------------------------------------------------------------------------
AdlibRegister('_Time', 1000)
;----------------------------------------------------------------------------
While 1
$nMsg = GUIGetMsg()
Switch $nMsg
Case $GUI_EVENT_CLOSE, $Button2
Exit
Case $Button1
ExitLoop
EndSwitch
If $Time <= 0 Then ExitLoop
WEnd
Main()
Exit
EndFunc
;----------------------------------------------------------------------------
Func _Time()
$Time -= 1
$BtnText=' → 还有 '& $Time & ' 秒'
$LabText=$Time & ' 秒后将进入主程序!'
GUICtrlSetData($Label1, $LabText)
GUICtrlSetData($Button1,$YES&$BtnText)
GUICtrlSetData($Progress1, ($i - $Time) / $i * 100)
If $Time <= 0 Then AdlibUnRegister('_Time')
EndFunc ;==>_Time
;----------------------------------------------------------------------------
Func Main()
Run($Program)
EndFunc ;==>Main
|