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