One-day Windows API training (67) settimer and killtimer Functions

Source: Internet
Author: User

The previous section introduced the use of a pair of timer API functions, and now introduces the use of another pair of API functions. It is easier to use than the previous function, but it generally uses a window Program And its accuracy is not as high as the previous API functions, which is very suitable for some scenarios where the requirements are not high. It uses the Message notification method and receives a message every time it arrives.

The settimer and killtimer functions are declared as follows:

Winapi
Settimer (
_ In_opt hwnd,
_ In uint_ptr nidevent,
_ In uint uelapse,
_ In_opt timerproc lptimerfunc );

Winuserapi
Bool
Winapi
Killtimer (
_ In_opt hwnd,
_ In uint_ptr uidevent );

Hwnd is the handle of the window receiving timer.
Nidevent is the ID of the timer event.
Uelapse is the millisecond value of the timer.
Lptimerfunc is the callback function for timed arrival.

An example of calling a function is as follows:
#001 // set the timer.
#002: settimer (m_hwnd, // The handle pointing to the window.
#003 idt_timer1, // timer ID.
#004 1000, // 1 second
#005 (timerproc) null); // No callback function is used.

Receive the wm_timer message and disable the Timer:
#001 case wm_timer:
#002 {
#003 if (idt_timer1 = wparam)
#004 {
#005 outputdebugstring (_ T ("timer Test message disabled \ r \ n "));
#006: killtimer (m_hwnd, idt_timer1 );
#007}
#008
#009}
#010 break;

This article from the csdn blog, reproduced please indicate the source: http://blog.csdn.net/caimouse/archive/2007/11/07/1872372.aspx

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.