One-day training of Windows APIs (66) createwaitabletimer and setwaitabletimer Functions

Source: Internet
Author: User
Users feel that the software is easy to use, that is, they can do some work on a regular basis without the need to participate. For example, update the virus database regularly every day, regularly download movies, and regularly update characters in the game. To implement these functions, you can use the timer API Function Createwaitabletimer And Setwaitabletimer To achieve this. API The clock created by the function is relatively accurate and can achieve 100 Times 10 One second per hundred million. Function Createwaitabletimer And Setwaitabletimer The statement is as follows: Winbaseapi _ Out Handle Winapi Createwaitabletimera ( _ In_opt lpsecurity_attributes lptimerattributes, _ In bool bmanualreset, _ In_opt lpcstr lptimername ); Winbaseapi _ Out Handle Winapi Createwaitabletimerw ( _ In_opt lpsecurity_attributes lptimerattributes, _ In bool bmanualreset, _ In_opt lpcwstr lptimername ); # Ifdef Unicode # Define createwaitabletimer createwaitabletimerw # Else # Define createwaitabletimer createwaitabletimera # Endif //! Unicode Winbaseapi Bool Winapi Setwaitabletimer ( _ In handle htimer, _ In const large_integer * lpduetime, _ In long lperiod, _ In_opt ptimerapcroutine pfncompletionroutine, _ In_opt lpvoid lpargtocompletionroutine, _ In bool fresume ); Lptimerattributes Is the property of the timer. Bmanualreset Whether to manually reset. Lptimername Is the name of the timer. Htimer Is the timer handle. Lpduetime Is to set the timer time interval, when set to positive is absolute time; when set to negative is relative time. Lperiod Is the cycle. Pfncompletionroutine Is to set the callback function. Lpargtocompletionroutine Is the parameter sent to the callback function. Fresume Is to set whether the system is automatically restored. An example of calling a function is as follows: #001 // Create a timer #002 // Cai junsheng 2007/11/06 QQ: 9073204 Shenzhen #003 int createtesttimer (void) #004 { #005 handle htimer = NULL; #006 large_integer liduetime; #007 #008 // Set relative time 10 Seconds. #009 liduetime. quadpart =-100000000; #010 #011 // Create a timer. #012 htimer = createwaitabletimer (null, true, _ T ("testwaitabletimer ")); #013 if (! Htimer) #014 { #015 return 1; #016} #017 #018 outputdebugstring (_ T ("10 Second Timer \ R \ n ")); #019 #020 // Set 10 Seconds. #021 if (! Setwaitabletimer (htimer, & liduetime, 0, null, null, 0 )) #022 { #023 // #024 closehandle (htimer ); #025 return 2; #026} #027 #028 // The timer has a signal. #029 if (waitforsingleobject (htimer, infinite )! = Wait_object_0) #030 { #031 outputdebugstring (_ T ("10 Second timer Error \ R \ n ")); #032 // #033 closehandle (htimer ); #034 return 3; #035} #036 else #037 { #038 // 10 In seconds. #039 outputdebugstring (_ T ("10 Seconds timer arrived \ R \ n ")); #040} #041 #042 // #043 closehandle (htimer ); #044 return 0; #045}

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.