TIMER BASICS

You can allocate a timer for your Windows program by calling the SetTimer function. SetTimer includes a parameter specifying an interval that can range (in theory) from 1 msec (millisecond) to 65,535 msec, or about 65.5 seconds. The value indicates the rate at which Windows sends your program WM_TIMER messages. For instance, an interval of 1000 msec causes Windows to send your program a WM_TIMER message every second.

When your program is done using the timer, it calls the KillTimer function to stop the timer messages. You can program a ”one-shot“ timer by calling KillTimer during the processing of the WM_TIMER message. The KillTimer call purges the message queue of any pending WM_TIMER messages. Your program will never receive a stray WM_TIMER message following a KillTimer call.

As you've undoubtedly learned from experimenting with loading multiple instances of CLOCK, Windows allows only 16 timers to be active at one time. If all 16 timers are already allocated, SetTimer returns NULL. Windows programs that use a timer must include some way to deal with this problem.