Programming in the On State

When an H/PC is in the on state, some applications may prevent the operating system from switching an H/PC to the idle mode. These applications retain control by using idle loops or by using functions that do not let the operating system block operation. All applications can enhance power management by using functions that let the operating system block a return to the application. To accomplish this, use the GetMessage function, rather than the PeekMessage function, because GetMessage lets the system block a return to the application, and PeekMessage does not. Letting the operating system retain control allows it to determine when the system is inactive so that it can select the most efficient operating state for the H/PC.

If you are programming a power-critical application, use the GetPowerStatusEx function to determine the amount of power remaining on an H/PC. This function returns a variety of information regarding power status, including the amount of remaining power, how long the current charge will last, and recharging status.