I need to write code in C that will indicate and notify me when the laptop battery power is low. I know that I can use the following:
BOOL WINAPI GetSystemPowerStatus(
__out LPSYSTEM_POWER_STATUS lpSystemPowerStatus
);
But I want to send a function to the operating system that will notify me when power is low.
I want to have an “empty” loop in my code, and when battery is low, the code will send me a notification (printf or trace).
I think I should be using kernel functions, but I can’t find them
I have never used these APIs, but what you are looking for seems to be
WM_POWERBROADCAST.There are various values for
wParamthat you could check upon receiving that message, such asPBT_APMBATTERYLOW. When you receive aWM_POWERBROADCASTmessage with the appropriatewParamvalue, callGetSystemPowerStatus()from there.