换气扇规格:AutoIT中多定时器用法实例

来源:百度文库 编辑:中财网 时间:2024/04/29 15:55:38
AutoIT中多定时器用法实例(转载)

在Autoit中实现VB的Timer控件,用过VB的人都知道Timer控件,即在一段时间间隔内重复运行一段代码,此间暂停脚本运行,这一点和Autoit的AdlibEnable函数很相似。但与之不同的是前者可以建立无数个Timer控件,而后者只能AdlibEnable一次。

#Include
#include

GuiCreate("Timer",  124,  99)

$Label_1 =  GuiCtrlCreateLabel("Time loading...",  10,  10,  140,  20)
$Label_2 =  GuiCtrlCreateLabel("00",  10,  40,  70,  20)
$Label_3 =  GuiCtrlCreateLabel("00",  10,  70,  80,  20)

Global  $pTimerProc = DLLCallbackRegister("_TimerProc","int" ,"hwnd;uint;uint;dword")
Global  $uiTimer =  DllCall("user32.dll",  "uint",  "SetTimer",  "hwnd",  0,  "uint",  0,  "int",  1000,  "ptr",  DllCallbackGetPtr ($pTimerProc))
Global  $pTimerProc2 = DLLCallbackRegister("_TimerProc","int" ,"hwnd;uint;uint;dword")
Global  $uiTimer2 =  DllCall("user32.dll",  "uint",  "SetTimer",  "hwnd",  0,  "uint",  0,  "int",  200,  "ptr",  DllCallbackGetPtr ($pTimerProc2))
Global  $pTimerProc3 = DLLCallbackRegister("_TimerProc","int","hwnd;uint;uint;dword")
Global  $uiTimer3 =  DllCall("user32.dll",  "uint",  "SetTimer",  "hwnd",  0,  "uint",  0,  "int",  700,  "ptr",  DllCallbackGetPtr ($pTimerProc3))

GuiSetState()
While  1
     $msg =  GuiGetMsg()
     Select
     Case  $msg =  $GUI_EVENT_CLOSE
         DllCall("user32.dll",  "int",  "KillTimer",  "hwnd",  0,  "uint",  $uiTimer[0])
       DllCallbackFree ($pTimerProc)
        DllCall("user32.dll",  "int",  "KillTimer",  "hwnd",  0,  "uint",  $uiTimer2[0])
       DllCallbackFree  ($pTimerProc2)
        DllCall("user32.dll",  "int",  "KillTimer",  "hwnd",  0,  "uint",  $uiTimer3[0])
       DllCallbackFree  ($pTimerProc3)
        Exit
     Case  Else
         ;;;
     EndSelect
WEnd
Exit

Func _TimerProc($hWnd,  $uiMsg,  $idEvent,  $dwTime)
     ;$idEvent能分辨是哪个Timer控件调用了这个函数
     ;$dwTime表示已开机的时间
     Switch  $idEvent
         Case  $uiTimer[0]
             GUICtrlSetData($Label_1,_Now  (  ))
         Case  $uiTimer2[0]
             GUICtrlSetData($Label_2,GUICtrlRead($Label_2)+1)
         Case  $uiTimer3[0]
             GUICtrlSetData($Label_3,GUICtrlRead($Label_3)+1)
     EndSwitch
EndFunc