问题
I'm trying to write a small app that monitors how much power is left in a notebook battery and I'd like to know which Win32 function I could use to accomplish that.
回答1:
For Vista and up you can use RegisterPowerSettingNotification
For earlier functions see the Power Management Functions in this section of the MSDN page "Power Management Functions: Windows Server 2003 and Earlier"
You can see example code of the Vista method on codeproject.
回答2:
I recommend the use of the Win32 GetSystemPowerStatus function. A code snippet :
int getBatteryLevel()
{
SYSTEM_POWER_STATUS status;
GetSystemPowerStatus(&status);
return status.BatteryLifePercent;
}
回答3:
There is a very detailed article in the following link, as well as a n example project (tested working on Win8.1): http://www.codeproject.com/Articles/15829/Vista-Goodies-in-C-Monitoring-the-Computer-s-Power
来源:https://stackoverflow.com/questions/233446/monitor-battery-charge-with-win32-api