Windows program design Reading Notes-timer.

Source: Internet
Author: User

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 );

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.