A timer is a system resource that can notify an application at regular intervals. An application associates a timer with a window and sets the timer for a specific time-out period. Each time the specified interval, or time-out value, for a specified timer elapses, the system uses a WM_TIMER message to notify the window associated with the timer; because the accuracy of a timer depends on the system clock rate and how often the application retrieves messages from the message queue, the time-out value is only approximate. The smallest possible interval that a timer can measure is the system tick interval.
To create a timer, call the SetTimer function. The timer can be associated with a particular window or with just the thread. If you associate the timer with a window, message loop processing will cause the WM_TIMER message to be dispatched to the window procedure for the window. If you do not associate the timer with a window, you must design the message loop to recognize and handle the WM_TIMER message.
If the call to SetTimer includes a TimerProc callback function, the procedure is called when the timer expires. This call is done inside the GetMessage or PeekMessage function. This means that a thread must be executing a message loop to service a timer, even if you are using a timer callback procedure.
A new timer starts timing its interval as soon as it is created. An application can change a time-out value for a timer by calling the SetTimer function, and it can destroy a timer by calling the KillTimer function. To use system resources efficiently, applications should destroy unnecessary timers.
You can use the timer and window identifiers to identify timers that are associated with a window. You can identify timers that are not associated with a particular window by using the identifier that is returned by the SetTimer call.
Timer messages have low priority in the message queue. Although you know that the window associated with a timer is notified sometime after the timer interval expires, you cannot know the exact time it will receive the notification.
Timers expire at regular intervals, but a timer that expires multiple times before being serviced does not generate multiple WM_TIMER messages.