Posted By

shadevampire on 06/04/11


Tagged

check windows status battery percent remaining


Versions (?)

windows check battery status in c++


 / Published in: C++
 

URL: http://www.dreamincode.net/code/snippet468.htm

  1. #include <windows.h>
  2. #include <iostream>
  3.  
  4. #define UNKNOWN 0xFFFFFFFF
  5.  
  6. using namespace std;
  7.  
  8. int main() {
  9. SYSTEM_POWER_STATUS status;
  10.  
  11. GetSystemPowerStatus( &status );
  12. int life = status.BatteryLifePercent;
  13. int secs = status.BatteryLifeTime;
  14.  
  15. cout << life << "% -> ";
  16. switch (status.BatteryFlag) {
  17. case 1: cout << "High";
  18. break;
  19. case 2: cout << "Low";
  20. break;
  21. case 4: cout << "Critical";
  22. break;
  23. case 8: cout << "Charging";
  24. break;
  25. case 128: cout << "No system battery";
  26. break;
  27. case 256: cout << "Unknown status";
  28. break;
  29. }
  30.  
  31. if (secs == UNKNOWN) {
  32. cout << endl << "Amount of time remaining is unkown";
  33. }
  34. else cout << endl << secs << " seconds remaining";
  35.  
  36. Sleep( 2000 );
  37. return 0;
  38. }

Report this snippet  

You need to login to post a comment.