Cr�e un Timer avec une valeur de d�lai d'attente sp�cifi�
#include <Timers.au3>
_Timer_SetTimer ( $hWnd [, $iElapse = 250 [, $sTimerFunc = "" [, $iTimerID = -1]]] )
$hWnd | Handle de la fen�tre � associer au Timer. Cette fen�tre doit �tre d�tenu par le thread appelant |
$iElapse | [optionnel] Sp�cifie la valeur de d�passement de d�lai, en millisecondes |
$sTimerFunc | [optionnel] Nom de la fonction � notifier quand le d�lai d'attente est �coul� |
$iTimerID | [optionnel] Sp�cifie un identifiant du Timer. Si $iTimerID = -1 alors un nouveau Timer est cr�� Si $iTimerID correspond � un Timer existant, puis le Timer est remplac� Si $iTimerID = -1 et $sTimerFunc = "" alors le Timer utilisera les �v�nements WM_TIMER |
Succ�s: | Retourne un entier identifiant le nouveau Timer |
�chec: | Retourne 0 |
La fonction de rappel est appel�e avec les param�tres suivants:
$hWnd, $Imsg, $iIDTimer, $iTime
$hWnd - Un handle de la fen�tre associ�e au Timer.
$iMsg - Le message WM_TIMER (0x113).
$iIDTimer - L'identifiant du Timer.
$iTime - Le nombre de millisecondes qui se sont �coul�es depuis que le syst�me a d�marr�. Cette valeur est retourn�e par la fonction _Date_Time_GetTickCount().
A l'int�rieur d'une fonction de rappel, _Timer_KillAllTimers() ou _Timer_KillTimer() qui concernent le $iIDTimer en cours ne doivent pas �tre utilis�es.
_Timer_GetTimerID, _Timer_KillAllTimers, _Timer_KillTimer
Consultez SetTimer dans la librairie MSDN.
#include <GUIConstantsEx.au3> #include <GuiStatusBar.au3> #include <ProgressConstants.au3> #include <Timers.au3> #include <WindowsConstants.au3> Global $g_idMemo, $g_hStatus, $g_idProgress, $g_iPercent = 0, $g_iDirection = 1 _Example_CallBack() Func _Example_CallBack() Local $hGUI, $iTimerProgress, $idChange, $iWait = 10, $idState Local $aParts[3] = [75, 330, -1] $hGUI = GUICreate("Utilisation des Timers dans des fonctions CallBack", 400, 320) $g_idMemo = GUICtrlCreateEdit("", 2, 32, 396, 226, BitOR($WS_HSCROLL, $WS_VSCROLL)) GUICtrlSetFont($g_idMemo, 9, 400, 0, "Courier New") $idState = GUICtrlCreateButton("Start Progress Bar", 70, 270, 100, 25) $idChange = GUICtrlCreateButton("Change", 215, 270, 90, 25) GUICtrlSetState($idChange, $GUI_DISABLE) $g_hStatus = _GUICtrlStatusBar_Create($hGUI, $aParts) _GUICtrlStatusBar_SetText($g_hStatus, "Timers") _GUICtrlStatusBar_SetText($g_hStatus, @TAB & @TAB & StringFormat("%02d:%02d:%02d", @HOUR, @MIN, @SEC), 2) $g_idProgress = GUICtrlCreateProgress(0, 0, -1, -1, $PBS_SMOOTH) GUICtrlSetColor($g_idProgress, 0xff0000) _GUICtrlStatusBar_EmbedControl($g_hStatus, 1, GUICtrlGetHandle($g_idProgress)) GUISetState(@SW_SHOW) _Timer_SetTimer($hGUI, 1000, "_UpdateStatusBarClock") ; Cr�e un Timer Local $iMsg = GUIGetMsg() While $iMsg <> $GUI_EVENT_CLOSE Switch $iMsg Case $idState If GUICtrlRead($idState) = "Start Progress Bar" Then ; Cr�e un Timer $iTimerProgress = _Timer_SetTimer($hGUI, $iWait, "_UpdateProgressBar") If (Not @error) And ($iTimerProgress <> 0) Then GUICtrlSetData($idState, "Stop Progress Bar") GUICtrlSetState($idChange, $GUI_ENABLE) EndIf Else GUICtrlSetState($idChange, $GUI_DISABLE) _Timer_KillTimer($hGUI, $iTimerProgress) GUICtrlSetData($idState, "Start Progress Bar") EndIf Case $idChange $iWait = ($iWait = 10 ? 250 : 10) MemoWrite("Timer for _UpdateProgressBar set at: " & $iWait & " milliseconds") ; R�-utilise le Timer avec un intervalle diff�rent $iTimerProgress = _Timer_SetTimer($hGUI, $iWait, "", $iTimerProgress) EndSwitch $iMsg = GUIGetMsg() WEnd ConsoleWrite("Timers d�truits? " & _Timer_KillAllTimers($hGUI) & @CRLF) GUIDelete() EndFunc ;==>_Example_CallBack ; Fonction Callback Func _UpdateStatusBarClock($hWnd, $iMsg, $iIDTimer, $iTime) #forceref $hWnd, $iMsg, $iIDTimer, $iTime _GUICtrlStatusBar_SetText($g_hStatus, @TAB & @TAB & StringFormat("%02d:%02d:%02d", @HOUR, @MIN, @SEC), 2) EndFunc ;==>_UpdateStatusBarClock ; Fonction Callback Func _UpdateProgressBar($hWnd, $iMsg, $iIDTimer, $iTime) #forceref $hWnd, $iMsg, $iIDTimer, $iTime $g_iPercent += 5 * $g_iDirection GUICtrlSetData($g_idProgress, $g_iPercent) If $g_iPercent = 100 Or $g_iPercent = 0 Then $g_iDirection *= -1 If $g_iPercent = 100 Then GUICtrlSetColor($g_idProgress, 0xff0000) ElseIf $g_iPercent = 0 Then GUICtrlSetColor($g_idProgress, 0x0000ff) EndIf EndFunc ;==>_UpdateProgressBar ; �crit une ligne dans le contr�le m�mo Func MemoWrite($sMessage) GUICtrlSetData($g_idMemo, $sMessage & @CRLF, 1) EndFunc ;==>MemoWrite
#include <Timers.au3> Global $g_iMsecs = 0, $g_sResult = '', $g_sCDdrv _Example_TimeOut() Func _Example_TimeOut() $g_sCDdrv = DriveGetDrive("CDROM") $g_sCDdrv = $g_sCDdrv[1] Local $hGUI = GUICreate("", 140, 64, -1, -1, 0) GUICtrlCreateLabel("Ins�rez un CD dans le lecteur", 8, 8, 115, 17) GUISetState(@SW_SHOW) Local $iIDtimer = _Timer_SetTimer($hGUI, 1000, "Check_mounted") ; Cr�e un timer While $g_sResult = '' Sleep(200) WEnd _Timer_KillTimer($hGUI, $iIDtimer) MsgBox(0, '', $g_sResult, 5) ConsoleWrite("Killed All Timers? " & _Timer_KillAllTimers($hGUI) & @CRLF) ; Doit �tre False car tous les chronom�tres ont d�j� �t� �limin�s GUIDelete($hGUI) EndFunc ;==>_Example_TimeOut Func Check_mounted($hWnd, $iMsg, $iIDtimer, $iTime) #forceref $hWnd, $iMsg, $iIDTimer,$iTime $g_sResult = '' If FileExists($g_sCDdrv & '\') Then $g_sResult = DriveGetLabel($g_sCDdrv) & ' ins�r�' & @CRLF $g_sResult &= 'dans le lecteur ' & $g_sCDdrv Else $g_iMsecs += 1000 If $g_iMsecs = 10000 Then $g_sResult = 'timed out' EndIf EndIf EndFunc ;==>Check_mounted