The windows program of Wince uses a timer.

Source: Internet
Author: User

For Windows under WinCEProgramYou can use API settimer to create a timer. When the timer times out, the window will receive a wm_timer message. We can do the timer time-out processing in the wm_timer message. For windowless programs, because there is no message loop, they cannot receive the wm_timer message, and the timer will not work properly.

So how does a windowless program use settimer for timing? In fact, we only need to add a message loop to the main thread in the windowless program to process wm_timer. For more information, seeCodeAs follows:

Uint utimerid =: settimer (null, null, 1000, null); <br/> MSG; <br/> // message loop <br/> while (getmessage (& MSG, null, 0, 0) <br/>{< br/> switch (MSG. message) <br/>{< br/> case wm_quit: <br/>: killtimer (null, utimerid); <br/> break; <br/> case wm_timer: <br/> // todo: Treat wm_timer message <br/> Break <br/> default: <br/> break; <br/>}< br/>}

 

However, it is still troublesome for windowless programs. When using a timer, you must add the message loop code. In fact, Microsoft also provides an API timesetevent to create a timer, for more precise timing, see the following code:

// Header file and library to be introduced <br/> # include <mmsytem. h> <br/> # pragma comment (Lib, "mmtimer. lib ") <br/> // timer callback function <br/> void callback timerproc (uint wtimerid, uint MSG, DWORD dwuser, DWORD dw1, DWORD dw2 ); <br/> // create a timer <br/> mmresult utimerid = timesetevent (, 1, timerproc, (DWORD) This, time_periodic | time_callback_function ); </P> <p> // timer timeout processing <br/> void callback timerproc (uint wtimerid, uint MSG, DWORD dwuser, DWORD dw1, DWORD dw2) <br/>{< br/> // todo: Place code here <br/>}

Do not forget to call timekillevent to disable the timer.

Related Article

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.