Notification when power source switches from AC to DC and back?

1.2k views Asked by At

I'm writing a Windows service using WinAPIs in C++. I'm curious if I can receive a notification when the system is switched from AC power (or plugged in) to DC power (or battery power) and vice versa?

1

There are 1 answers

8
selbie On BEST ANSWER

PowerSettingRegisterNotification to register a callback function when the power state changes. Then notification can queue up a call to GetSystemPowerStatus to get the AC/DC state.

There's also WM_POWERBROADCAST notification message.