DetectAC         Detect AC power status on Windows
Print

Why detect AC power status?

Laptops are becoming more and more popular. One advantage is that they can be used without power supply with the help of a battery. Unfortunately when a laptop is not connected to a power supply the performace will be degraded (sometimes considerably). It can be useful to detect this and show a message to the user explaining why the application might not perform very well.
This code snippet shows how the "detecting part" can be done using the Windows API.

Code snippet

bool
  Utils::GetBatteryCharging()
  {
       SYSTEM_POWER_STATUS _status;
       GetSystemPowerStatus(&_status);
       if(_status.ACLineStatus == 0)
       {
           return false;
       } else {
           return true;
       }
  }

Dont forget to include windows headers also for this to work:

#include "windows.h"

--Borundin? 20:26, 4 July 2008 (BST)

 


Contributors to this page: jacmoe133512 points  and Borundin11 points  .
Page last modified on Saturday 02 of January, 2010 23:25:00 UTC by jacmoe133512 points .


The content on this page is licensed under the terms of the Creative Commons Attribution-ShareAlike License.
As an exception, any source code contributed within the content is released into the Public Domain.