Registering for Power Events
Applications can better adapt their behavior to the current power state of the computer by registering for power events. An application should register for each power change event that might impact its behavior.
An application or service uses the RegisterPowerSettingNotification function to register for notifications. When the corresponding power setting changes, the system sends notifications as follows:
- An application receives a WM_POWERBROADCAST message with a wParam of PBT_POWERSETTINGCHANGE and an lParam that points to a POWERBROADCAST_SETTING structure.
- A service receives a call to the HandlerEx callback function it registered by calling the RegisterServiceCtrlHandlerEx function. The lpEventData parameter sent to the HandlerEx callback function points to a POWERBROADCAST_SETTING structure.
In the POWERBROADCAST_SETTING structure, the PowerSetting member contains the GUID that identifies the notification and the Data member contains the new value of the power setting.
For a list of power setting GUIDs for notifications that are most useful to applications, see Power Setting GUIDs.