How to Use peekmessage resources in mobile apps

Source: Internet
Author: User
Original article address: http://www.intel.com/cd/ids/#/apac/zho/recent/325179.htmchallenge Determine and minimize the impact of peekmessage calls on battery life in Windows *-based mobile apps. When talking about the optimization technology for applications running on battery power supply devices, some application developers may doubt or understand why they need to consider this issue.

Because peekmessage has been widely used as a key component of message loop in many old applications over the years, it is particularly important to solve the power problem in applications. Basically, peekmessage calls make the system busy checking messages and occupy a lot of the system.

Solution Note the power prompt whenProgramEnable proper idle status when idle. You can write an application to make it more energy-efficient, allow windows to be idle, and monitor the approximate length of time when the unprocessed message of the application is idle. Because it is difficult to use peekmessage properly, we have designed a backup method to address potential problems of peekmessage.

One way to directly control peekmessage usage in an application is to build your own message loop. By ensuring that you have covered the basic elements in the Microsoft basic class * (MFC *) main message loop, your application can directly control the message pump. The following is a brief pseudo-concept compatible with MFC:CodeExample:

While (bdoingbackgroundprocessing) {MSG; while (: peekmessage (& MSG, null, 0, 0, pm_noremove) {If (! Pumpmessage () {bdoingbackgroundprocessing = false;: postquitmessage (); break ;}// enable MFC to perform idle processing for long minutes le = 0; while (afxgetapp () -> onidle (lidle ++); // perform some background processing here // use another onidle call}
In this Code, as long as there is idle processing in progress, peekmessage is called. Pumpmessage is used for normal message conversion and scheduling. The problem with using this code is that pumpmessage is called. When Source code It can be found in thrdcore. cpp without being formally archived, so it may change in later versions.

The problem with peekmessage in a loop is that Windows cannot enter idle state. The energy-saving application processes all messages and processes them in the background. Then, it calls waitmessage to go to sleep until a new message is displayed. You can use waitmessage to release the system to process other tasks:

If (peekmessage (...)! = NULL) // If a message exists, the else if (there is background processing to do) of the message will be converted and scheduled. // The else is processed in the background without any background processing, no waiting message-enter sleep status waitmessage ();
Write Applications to achieve self-management, as shown in the pseudo code above, which helps improve the power usage of the battery power supply system.

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.