Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Monitor battery charge with Win32 API

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.

like image 830
Fábio Avatar asked Oct 24 '08 13:10

Fábio


2 Answers

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.

like image 115
Brian R. Bondy Avatar answered Sep 28 '22 09:09

Brian R. Bondy


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

int getBatteryLevel()
{
    SYSTEM_POWER_STATUS status;
    GetSystemPowerStatus(&status);
    return status.BatteryLifePercent;
}
like image 31
Bruno STEUX Avatar answered Sep 28 '22 09:09

Bruno STEUX