WORD SetTimer(hWnd,nIDEvent,wElapse,lpTimerFunc)
This function creates a system timer event. When a timer event occurs, Windows passes a WM_TIMER message to the application-supplied function specified by the lpTimerFunc parameter. The function can then process the event. A NULL value for lpTimerFunc causes WM_TIMER messages to be placed in the application queue.
Parameter | Type/Description |
hWnd | HWND Identifies the window to be associated with the timer. If hWnd is NULL, no window is associated with the timer. | |
nIDEvent | int Specifies a nonzero timer-event identifier if the hWnd parameter is not NULL. | |
wElapse | WORD Specifies the elapsed time (in milliseconds) between timer events. | |
lpTimerFunc | FARPROC Is the procedure-instance address of the function to be notified when the timer event takes place. If lpTimerFunc is NULL, the WM_TIMER message is placed in the application queue, and the hwnd member of the MSG structure contains the hWnd parameter given in the SetTimer function call. See the following “Comments” section for details. |
The return value specifies the integer identifier for the new timer event. If the hWnd parameter is NULL, an application passes this value to the KillTimer function to kill the timer event. The return value is zero if the timer was not created.
Timers are a limited global resource; therefore, it is important that an application check the value returned by the SetTimer function to verify that a timer is actually available.
To install a timer function, SetTimer must receive a procedure-instance address of the function, and the function must be exported in the application's module-definition file. A procedure-instance address can be created using the MakeProcInstance function.
The callback function must use the Pascal calling convention and must be declared FAR.
WORD FAR PASCAL TimerFunc(hWnd, wMsg, nIDEvent, dwTime)
HWND hWnd;
WORD wMsg;
int nIDEvent;
DWORD dwTime;
TimerFunc is a placeholder for the application-supplied function name. The actual name must be exported by including it in an EXPORTS statement in the application's module-definition file.
Parameter | Description |
hWnd | Identifies the window associated with the timer event. | |
wMsg | Specifies the WM_TIMER message. | |
nIDEvent | Specifies the timer's ID. | |
dwTime | Specifies the current system time. |