I. Timer Working principle:
Windows timers are relatively simple extensions of timer logic constructed based on PC hardware and rom bios.
For every program with a timer, Windows stores a number of times that the hardware timer answers each time. When the number is reduced to 0, Windows places a wm_timer message in the application message queue, and reset the count to the initial value.
The position of wm_timer is in the message queue of the application, so it is not asynchronous, But in order with other messages. If the application is processing other messages when the wm_timer message is received, the wm_timer will be postponed.
Wm_timer is the same as wm_paint. There cannot be multiple wm_timer messages in the message queue. If a new wm_timer message is added to the queue and one is found, the two will be merged into one.
2. After killtimer, the timer stops, but the generated wm_timer message will continue to be executed.
3. Use a callback function to process timer transactions.
Static void callback timerproc (hwnd, uint message, uint itimerid, DWORD dwtime );
Settimer (2,1000, timerproc );
The callback function must be a static member function or a global function.
After the callback function is used, the content in the ontimer () function will not be executed.
4. do not specify the timer for the window and ID
Int timerid = settimer (null, 0,1000, timerproc );
Killtimer (null, timerid );