Originally Posted by
Flotonic
That's C++, but beggars can't be picky. Thanks! I'll see what I can do with this. B-)
It is NOT C++... You can do that very easily in standard C....
What it is is a simple windows API call... Like most of them, you provide the requisite struct, call the function and then extract the data you need...
Here's what the GetSystemPowerStatusEx2 function returns...
Code:
typedef struct _SYSTEM_POWER_STATUS_EX2 {
BYTE ACLineStatus;
BYTE BatteryFlag;
BYTE BatteryLifePercent;
BYTE Reserved1;
DWORD BatteryLifeTime;
DWORD BatteryFullLifeTime;
BYTE Reserved2;
BYTE BackupBatteryFlag;
BYTE BackupBatteryLifePercent;
BYTE Reserved3;
DWORD BackupBatteryLifeTime;
DWORD BackupBatteryFullLifeTime;
DWORD BatteryVoltage;
DWORD BatteryCurrent;
DWORD BatteryAverageCurrent;
DWORD BatteryAverageInterval;
DWORD BatterymAHourConsumed;
DWORD BatteryTemperature;
DWORD BackupBatteryVoltage;
BYTE BatteryChemistry;
// Add any extra information after the BatteryChemistry member.
} SYSTEM_POWER_STATUS_EX2, *PSYSTEM_POWER_STATUS_EX2, *LPSYSTEM_POWER_STATUS_EX2;
In C.... #include <winbase.h> and link with coredll.lib....
Code:
float GetBatteryTime(void)
{ SYSTEM_POWER_STATUS_EX2 Stat;
if (GetSystemPowerStatusEx2(&Stat,sizeof(Stat),TRUE))
return (float) Stat.BatteryLifeTime;
else
return -1; } // error message;
Really... it's not that hard.