本帖最后由 smooth 于 2014-3-25 11:38 编辑
我弄了一个计时器,目的是想在执行主函数的时候,能让它显示在界面上,让用户了解执行主函数耗用多少时间,但是遇到一个矛盾的问题,就是当主函数_BackupDB()在前,注册函数AdlibRegister('timer')在后,计时器不启动。当注册函数AdlibRegister('timer')在前,_BackupDB()在后,又不执行_BackupDB()函数。困惑。
代码片段:
ElseIf MsgBox(65, '备份确认', '您确定要开始备份吗?', '', $Form1) = 1 Then
Global $Form_M = GUICreate("", 280, 100, -1, -1, BitOR($DS_MODALFRAME, $WS_POPUPWINDOW), '', '')
GUICtrlCreateLabel("正在执行备份操作,请稍候...... ", 30, 40, 180, 80)
GUICtrlCreateAvi($Findfileavi, 0, 220, 30, 32, 32, $ACS_AUTOPLAY)
Global $time = GUICtrlCreateLabel("00:00:00 ", 24, 12, 240, 40)
GUICtrlSetFont(-1, 50, 400, 0, "MS Sans Serif")
GUISetState(@SW_SHOW)
WinWaitActive($Form_M)
WinSetOnTop($Form_M, "", 1)
AdlibRegister('timer')
_BackupDB()
GUIDelete($Form_M)
代码片段:
AdlibUnRegister('Timer')
Func timer()
While 1
$k = Number(StringLeft(GUICtrlRead($time), 2))
$i = Number(StringMid(GUICtrlRead($time), 4, 2))
$j = Number(StringRight(StringTrimRight(GUICtrlRead($time), 1), 2))
If $j <> 59 Then
$j += 1
Else
$j = 0
If $i < 59 Then
$i += 1
Else
$i = 0
If $k < 23 Then
$k += 1
Else
$k = 0
EndIf
EndIf
EndIf
GUICtrlSetData($time, StringFormat("%02d:%02d:%02d\n", $k, $i, $j))
Sleep(1000)
WEnd
EndFunc ;==>Timer
|