Monitor battery charge with Win32 API

随声附和 提交于 2019-11-29 10:40:29

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.

I recommend the use of the Win32 GetSystemPowerStatus function. A code snippet :

int getBatteryLevel()
{
    SYSTEM_POWER_STATUS status;
    GetSystemPowerStatus(&status);
    return status.BatteryLifePercent;
}

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

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!