Important:
This is retired content. This content is outdated and is no longer being maintained. It is provided as a courtesy for individuals who are still using these technologies. This content may contain URLs that were valid when originally published, but now link to sites or pages that no longer exist.
A version of this page is also available for
4/8/2010

This function creates a timer with the specified time-out value.

Syntax

UINT SetTimer(
  HWND 
hWnd, 
  UINT 
nIDEvent, 
  UINT 
uElapse, 
  TIMERPROC 
lpTimerFunc 
); 

Parameters

hWnd

[in] Handle to the window to be associated with the timer. This window must be owned by the calling thread. If this parameter is NULL, no window is associated with the timer and the nIDEventparameter is ignored.

nIDEvent

[in] Specifies a nonzero timer identifier. If the hWndparameter is NULL, this parameter is ignored.

uElapse

[in] Specifies the time-out value, in milliseconds.

lpTimerFunc

[in] Long pointer to the function to be notified when the time-out value elapses. For more information about the function, see TimerProc.

If lpTimerFuncis NULL, the system posts a WM_TIMERmessage to the application queue. The hwndmember of the message's MSGstructure contains the value of the hWndparameter.

Return Value

An integer identifying the new timer indicates success. An application can pass this value, or the string identifier, if it exists, to the KillTimerfunction to destroy the timer. Zero indicates failure. To get extended error information, call GetLastError.

Remarks

If the uElapseparameter is set to INFINITE, KillTimerfails to destroy the timer.

An application can process WM_TIMER messages by including a WM_TIMER case statement in the window procedure or by specifying a TimerProccallback function when creating the timer. When you specify a TimerProccallback function, the default window procedure calls the callback function when it processes WM_TIMER. Therefore, you need to dispatch messages in the calling thread, even when you use TimerProcinstead of processing WM_TIMER.

The wParamparameter of the WM_TIMER message contains the value of the nIDEventparameter.

If SetTimeris called with hWndset to NULL and lpTimerFuncset to NULL, WM_TIMER message will not be delivered.

Requirements

Header winuser.h
Windows Embedded CE Windows CE 2.0 and later
Windows Mobile Windows Mobile Version 5.0 and later

See Also