Function Reference


_WinAPI_SetTimer

Creates a timer with the specified time-out value

#include <WinAPISysWin.au3>
_WinAPI_SetTimer ( $hWnd, $iTimerID, $iElapse, $pTimerFunc )

Parameters

$hWnd Handle to the window to be associated with the timer. This window must be owned by the calling
process. If a 0 value for $hWnd is passed in along with an $iTimerID of an existing timer, that
timer will be replaced in the same way that an existing non-zero $hWnd timer will be.
$iTimerID The timer identifier. If the $hWnd parameter is 0, and the $iTimerID does not match an existing
timer then it is ignored and a new timer ID is generated. If the $hWnd parameter is not 0 and
the window specified by $hWnd already has a timer with the value $iTimerID, then the existing
timer is replaced by the new timer. When _WinAPI_SetTimer() replaces a timer, the timer is reset.
Therefore, a message will be sent after the current time-out value elapses, but the previously
set time-out value is ignored. If the call is not intended to replace an existing timer,
$iTimerID should be 0 if the $hWnd is 0.
$iElapse The time-out value, in milliseconds.
$pTimerFunc The address of a callback function to be notified when the time-out value elapses. If this
parameter is 0, the system posts a WM_TIMER message to the application queue.
(See MSDN for more information)

Return Value

Success: The timer identifier. An application can pass this value to the _WinAPI_KillTimer() function to
destroy the timer.
Failure: 0.

Remarks

The timer identifier, $iTimerID, is specific to the associated window. Another window can have its own timer
which has the same identifier as a timer owned by another window. The timers are distinct.

See Also

Search SetTimer in MSDN Library.

Example

#include <Misc.au3>
#include <WinAPISysWin.au3>

Opt('TrayAutoPause', 0)

Local $hTimerProc = DllCallbackRegister('_TimerProc', 'none', 'hwnd;uint;uint_ptr;dword')
Global $g_iCount = 0

Local $iTimerID = _WinAPI_SetTimer(0, 0, 1000, DllCallbackGetPtr($hTimerProc))

Do
    Sleep(100)
Until _IsPressed('1B')

_WinAPI_KillTimer(0, $iTimerID)
DllCallbackFree($hTimerProc)

Func _TimerProc($hWnd, $iMsg, $iTimerID, $iTime)
    #forceref $hWnd, $iMsg, $iTimerId, $iTime

    ConsoleWrite($g_iCount & @CRLF)
    $g_iCount += 1
EndFunc   ;==>_TimerProc