Skip to content

Instantly share code, notes, and snippets.

@2no
Created May 30, 2014 09:37
Show Gist options
  • Save 2no/9d5918439945edb67dfd to your computer and use it in GitHub Desktop.
Save 2no/9d5918439945edb67dfd to your computer and use it in GitHub Desktop.
Cygwin, gcc-g++ $ make battery
#include <iostream>
#include <windows.h>
int main(int argc, char *argv[])
{
SYSTEM_POWER_STATUS powerStatus;
int percent = 0;
if (GetSystemPowerStatus(&powerStatus) == TRUE) {
percent = (int)powerStatus.BatteryLifePercent;
}
std::cout << percent << std::endl;
return 0;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment