| Last Modified On : | October 13, 2008 9:20 AM PDT |
Rate |
|
by Lester Memmott
In an ideal world, mobile systems would run all day without requiring the support of AC power – and with the recent launch of Intel® Centrino® Mobile Technology this is becoming closer to reality. However, in addition to the advances in hardware, software developers can now make applications power-aware by handling the WM_POWERBROADCAST message provided by the Windows* Operating System and scaling features accordingly. This whitepaper describes how to handle the WM_POWERBROADCAST message and also describes the sequence of messages for four typical cases. Additional introductory material is available from the MSDN documentation at http://msdn.microsoft.com*. MSDN, however, does not describe the expected sequence of messages in the event of AC power loss, AC power reconnect, system standby and natural battery depletion when off of AC power. These areas are explored here with a detailed analysis.
WM_POWERBROADCAST: Microsoft Windows Operating System message sent to applications to indicate system-wide power state changes.
AC Power: High voltage power supplied to a mobile system by plugging into a power outlet. This act, generally, recharges the system battery.
MSDN: Microsoft Developer Network. See http://msdn.microsoft.com*
Hardware advances have made mobile systems lighter and more energy efficient. In addition to these advances, software developers can make applications power-aware such that they enable users to work for longer periods of time before having to reconnect to recharge the system battery. For example, when on AC power, an anti-virus scanner would run full-featured, providing file scanning on all files opened and also running periodic system wide scans. When on battery power the scanner could defer the system wide scans until a later time and continue processing safely, analyzing just the open files.
Under the Windows Operating System, applications are notified of system power changes through the WM_POWERBROADCAST message. Note that the WM_POWER message is now obsolete and should be replaced with WM_POWERBROADCAST. These messages are handled through the standard message loop using GetMessage(). A sample application provided with this whitepaper shows a reference implementation for the concepts presented.
The WM_POWERBROADCAST comes with two parameters: wParam & lParam. The wParam can be a number of items which specifies the event received. The documentation for each of these is provided at MSDN as:
| Event | Meaning |
| PBT_APMBATTERYLOW | Battery power is low. |
| PBT_APMOEMEVENT | OEM-defined event occurred. |
| PBT_APMPOWERSTATUSC HANGE | Power status has changed. |
| PBT_APMQUERYSUSPEND | Request for permission to suspend. |
| PBT_APMQUERYSUSPENDFAILED | Suspension request denied. |
| PBT_APMRESUMEAUTOMATIC | Operation resuming automatically after event. |
| PBT_APMRESUMECRITICAL | Operation resuming after critical suspension. |
| PBT_APMRESUMESUSPEND | Operation resuming after suspension. |
| PBT_APMSUSPEND | System is suspending operation. |
The lParam is function specific and is not generally used.
Knowing that these messages can be received is beneficial, but it is more helpful to understand the expected sequence of these events when undergoing normal system transitions. The transitions analyzed are:
The following sections show the results using a Dell Latitude* P4-M 2.4 GHz laptop. The data was captured using Spy++*, a tool installed with MSVC which allows Windows messages to be monitor for a specific running application. For each case described, capturing the data was done using the following steps:
The data provided is the following:
Analysis
Case 1: AC Power Disconnect
This test was run by running Spy++ as outlined above and then removi ng AC power. Items in italic are commentary added to the Spy++ output.
Test Sequence
System on AC Power
Disconnect Power Cable
<00001> 000501B4 P WM_POWERBROADCAST (long)dwPowerEvent:PBT_APMPOWERSTATUSCHANGE dwData:00000000
Analysis
Case 2: AC Power Connect
This test was run by starting Spy++ as outlined above and then connecting AC Power. Items in italic are commentary added to the Spy++ output.
Test Sequence
On Battery Power
Connect AC Power Cable
<00001> 000501B4 P WM_POWERBROADCAST (long)dwPowerEvent:PBT_APMPOWERSTATUSCHANGE dwData:00000000
<00002> 000501B4 P WM_POWERBROADCAST (long)dwPowerEvent:PBT_APMPOWERSTATUSCHANGE dwData:00000000
<00003> 000501B4 P WM_POWERBROADCAST (long)dwPowerEvent:PBT_APMPOWERSTATUSCHANGE dwData:00000000
Analysis
Case 3: Standby and Resume
This test was run by starting Spy++ as outlined above, putting the system into standby mode and then starting the system backup again. Items in italic are commentary added. The system was on AC power the whole item.
Test Sequence
Start Standby Process
<00001> 000201FA S WM_POWERBROADCAST (long)dwPowerEvent:PBT_APMQUERYSUSPEND dwData:00000001
<00002> 000201FA R WM_POWERBROADCAST fSucceeded:True (//Return true to indicate that suspend is OK.)
<00003> 000201FA P WM_POWERBROADCAST (long)dwPowerEvent:PBT_APMPOWERSTATUSCHANGE dwData:00000000
<00004> 000201FA S WM_POWERBROADCAST (long)dwPowerEvent:PBT_APMSUSPEND dwData:00000000
<00005> 000201FA R WM_POWERBROADCAST fSucceeded:True
<00006> 000201FA R WM_POWERBROADCAST fSucceeded:True
System now in standby mode
<00007> 000201FA S WM_POWERBROADCAST (long)dwPowerEvent:PBT_APMRESUMESUSPEND dwData:00000000
<00008> 000201FA R WM_POWERBROADCAST fSucceeded:True
<00009> 000201FA P WM_POWERBROADCAST (long)dwPowerEvent:PBT_APMPOWERSTATUSCHANGE dwData:00000000
<00010> 000201FA P WM_POWERBROADCAST (long)dwPowerEvent:PBT_APMPOWERSTATUSCHANGE dwData:00000000
<00011> 000201FA P WM_POWERBROADCAST (long)dwPowerEvent:PBT_APMPOWERSTATUSCHANGE dwData:00000000
System now powered back up
Analysis
Case 4: Battery from 100% to Critical State
This test was run by charging the system to 100% battery, starting Spy++ as outlined above and then discharging the battery over time. To accelerate the discharge rate a batch file repetitively copied files from a DVD to the hard drive and a hard drive search was done for all files containing a long random string. Items in italic are commentary added.
Test Sequence
Disconnect Power
<00001> 000201FA P WM_POWERBROADCAST (long)dwPowerEvent:PBT_APMPOWERSTATUSCHANGE dwData:00000000
<00002> 000201FA P WM_POWERBROADCAST (long)dwPowerEvent:PBT_APMPOWERSTATUSCHANGE dwData:00000000
<00003> 000201FA P WM_POWERBROADCAST (long)dwPowerEvent:PBT_APMPOWERSTATUSCHANGE dwData:00000000
<00004> 000201FA P WM_POWERBROADCAST (long)dwPowerEvent:PBT_APMPOWERSTATUSCHANGE dwData:00000000
<00005> 000201FA P WM_POWERBROADCAST (long)dwPowerEvent:PBT_APMPOWERSTATUSCHANGE dwData:00000000
<00006> 000201FA P WM_POWERBROADCAST (long)dwPowerEvent:PBT_APMPOWERSTATUSCHANGE dwData:00000000
<00007> 000201FA P WM_POWERBROADCAST (long)dwPowerEvent:PBT_APMPOWERSTATUSCHANGE dwData:00000000
<00008> 000201FA P WM_POWERBROADCAST (long)dwPowerEvent:PBT_APMPOWERSTATUSCHANGE dwData:00000000
<00009> 000201FA P WM_POWERBROADCAST (long)dwPowerEvent:PBT_APMPOWERSTATUSCHANGE dwData:00000000
<00010> 000201FA P WM_POWERBROADCAST (long)dwPowerEvent:PBT_APMPOWERSTATUSCHANGE dwData:00000000
<00011> 000201FA P WM_POWERBROADCAST (long)dwPowerEvent:PBT_APMPOWERSTATUSCHANGE dwData:00000000
<00012> 000201FA P WM_POWERBROADCAST (long)dwPowerEvent:PBT_APMPOWERSTATUSCHANGE dwData:00000000
<00013> 000201FA P WM_POWERBROADCAST (long)dwPowerEvent:PBT_APMPOWERSTATUSCHANGE dwData:00000000
<00014> 000201FA P WM_POWERBROADCAST (long)dwPowerEvent:PBT_APMPOWERSTATUSCHANGE dwData:00000000
<00015> 000201FA P WM_POWERBROADCAST (long)dwPowerEvent:PBT_APMPOWERSTATUSCHANGE dwData:00000000
<00016> 000201FA P WM_POWERBROADCAST (long)dwPowerEvent:PBT_APMPOWERSTATUSCHANGE dwData:00000000
<00017> 000201FA P WM_POWERBROADCAST (long)dwPowerEvent:PBT_APMPOWERSTATUSCHANGE dwData:00000000
<00018> 000201FA P WM_POWERBROADCAST (long)dwPowerEvent:PBT_APMPOWERSTATUSCHANGE dwData:00000000
<00019> 000201FA P WM_POWERBROADCAST (long)dwPowerEvent:PBT_APMPOWERSTATUSCHANGE dwData:00000000
<00020> 000201FA P WM_POWERBROADCAST (long)dwPowerEvent:PBT_APMPOWERSTATUSCHANGE dwData:00000000
<00021> 000201FA P WM_POWERBROADCAST (long)dwPowerEvent:PBT_APMPOWERSTATUSCHANGE dwData:00000000
<00022> 000201FA P WM_POWERBROADCAST (long)dwPowerEvent:PBT_APMPOWERSTATUSCHANGE dwData:00000000
<00023> 000201FA P WM_POWERBROADCAST (long)dwPowerEvent:PBT_APMPOWERSTATUSCHANGE dwData:00000000
<00024> 000201FA P WM_POWERBROADCAST (long)dwPowerEvent:PBT_APMPOWERSTATUSCHANGE dwData:00000000
<00025> 000201FA P WM_POWERBROADCAST (long)dwPowerEvent:PBT_APMPOWERSTATUSCHANGE dwData:00000000
<00026> 000201FA P WM_POWERBROADCAST (long)dwPowerEvent:PBT_APMPOWERSTATUSCHANGE dwData:00000000
<00027> 000201FA P WM_POWERBROADCAST (long)dwPowerEvent:PBT_APMPOWERSTATUSCHANGE dwData:00000000
<00028> 000201FA P WM_POWERBROADCAST (long)dwPowerEvent:PBT_APMPOWERSTATUSCHANGE dwData:00000000
<00029> 000201FA P WM_POWERBROADCAST (long)dwPowerEvent:PBT_APMPOWERSTATUSCHANGE dwData:00000000
<00030> 000201FA P WM_POWERBROADCAST (long)dwPowerEvent:PBT_APMPOWERSTATUSCHANGE dwData:00000000
<00031> 000201FA P WM_POWERBROADCAST (long)dwPowerEvent:PBT_APMPOWERSTATUSCHANGE dwData:00000000
<00032> 000201FA P WM_POWERBROADCAST (long)dwPowerEvent:PBT_APMPOWERSTATUSCHANGE dwData:00000000
<00033> 000201FA P WM_POWERBROADCAST (long)dwPowerEvent:PBT_APMPOWERSTATUSCHANGE dwData:00000000
<00034> 000201FA P WM_POWERBROADCAST (long)dwPowerEvent:PBT_APMPOWERSTATUSCHANGE dwData:00000000
<00035> 000201FA P WM_POWERBROADCAST (long)dwPowerEvent:PBT_APMPOWERSTATUSCHANGE dwData:00000000
<00036> 000201FA P WM_POWERBROADCAST (long)dwPowerEvent:PBT_APMPOWERSTATUSCHANGE dwData:00000000
<00037> 000201FA P WM_POWERBROADCAST (long)dwPowerEvent:PBT_APMPOWERSTATUSCHANGE dwData:00000000
The system issued an alert indicating that AC power should be connected
Note that the messages above were sent at even periodic intervals through the discharge cycle.
Analysis
The WM_POWERBROADCAST message by itself doesn’t provide enough details to know that AC power was disconnected or reconnected. When the message is received, GetSystemPowerStatus() must be called to get the details.
Articles
Developer Centers
Community
Other Resources

English | 中文 | Русский | Français
Lester Memmott (Intel)
|