4.1.5 Timer Input

Windows sends timer input to your application when a specified interval elapses for a particular timer. To receive timer input, your application must set a timer by using the SetTimer function. The application receives the timer input in two ways:

Windows places a WM_TIMER message in your application's queue.

Windows calls a callback function defined in your application. You specify the callback function when you call the SetTimer function.

The following example shows how to set a timer so that it generates input at 5-second (5000-millisecond) intervals:

idTimer = SetTimer(hWnd, 1, 5000, (TIMERPROC) NULL);

The second argument to SetTimer is any nonzero value that your application uses to identify the particular timer. The last argument specifies the callback function that will receive timer input. Setting this argument to NULL tells Windows to provide timer input as a WM_TIMER message. Because there is no callback function specified for timer input, Windows sends the timer input through the application queue.

The SetTimer function returns a timer identifier—an integer that identifies the timer. You can use this timer identifier to turn the timer off by using it in the KillTimer function.