delphi3000.com - the free delphi knowledge platform
delphi3000.com - the free delphi knowledge platform
500 Users Online NOW
Have a look at your member-status

connecting people's knowledge


  - Recent ArticlesRSS feed for Recent Articles on delphi3000.com
  - List of All Articles
  - Top Viewed Articles
  - Articles (+Attachem.)
  - Articles Of Interest
  - Categories
  - Top Uploader
  - Search
  - Index

  - My Home
  - Submit an Article
  - My Articles
  - My Personal Data
  - My Bookmarks
  - Activities
  - Login/Logout

  - Sign Up
  - Why Sign Up
  - Newsletter

  - Press
  - Advertise

  - Contact
  - Feedback





Community
Borland
ClubeDelphi
Dr. Bob
UK-BUG
Delphi Meetings
Planeta Delphi



Loremo - the 1.5 liter car coming in 2009




Startblatt.de






Share this article with friendsShare this article with friends
Rate this articleRate this article - to keep the quality of delphi3000.com !
Comment this article or read through previous comments (0)


Getting System Power InformationGo to Magnus Flysjö's websiteFormat this article printer-friendly!Bookmark function is only available for registered users!
Reteriving battery information for notebooks
Product:
Delphi all versions
Category:
Win API
Skill Level:
Scoring:
Last Update:
05/22/2002
Search Keys:
delphi delphi3000 article borland vcl code-snippet Battery Power Notebook API GetSystemPowerStatus
Times Scored:
1
Visits:
2096
Uploader: Magnus Flysjö
Company: Hypode Sweden
Reference: N/A
 
Question/Problem/Abstract:
I would like my application to know how long time there is left before the battery is empty on my notebook.

Is there an easy way?
Answer:



Here is an easy way to get the power status for the current computer.
This code also works on desktops, but will only return information that the computer is connected to a power source. (AC)

All this information is reterived with the Windows API "GetSystemPowerStatus"

When running this code on a notebook you will get information such as:
- AC Line Status
- Battery status (High, Low, Critical, Charging, No battery)
- Battery Life in Percent (value between 0-100)
- Current time till battery uncharged (time in seconds)      
- Battery time when fully charged. (time in seconds)


Below is the code. Modify Button1Click to your own needs.
----

function GetSystemPowerInfo(var PowerInfo : TSystemPowerStatus) : boolean;
begin
result := GetSystemPowerStatus(PowerInfo);
end;

procedure TForm1.Button1Click(Sender: TObject);
var PowerInfo : TSystemPowerStatus;
begin
FillChar(PowerInfo,SizeOf(TSystemPowerStatus),0);
if GetSystemPowerInfo(PowerInfo) then begin
  Case PowerInfo.ACLineStatus of
   0: Label1.Caption := 'Offline';
   1: Label1.Caption := 'Online';
  else
   Label1.Caption := 'Unknown status.';
  end;
  Case PowerInfo.BatteryFlag of
   1: Label2.Caption := 'High';
   2: Label2.Caption := 'Low';
   4: Label2.Caption := 'Critical';
   8: Label2.Caption := 'Charging';
   128: Label2.Caption := 'No system battery';
  else
   Label2.Caption := 'Unknown status';
  end;
  if PowerInfo.BatteryLifePercent <= 100 then begin
   Label3.Caption := inttostr(PowerInfo.BatteryLifePercent )+'%';
  end else Label3.Caption := 'No system battery';
  if PowerInfo.BatteryLifeTime < MAXDWORD then begin
   Label4.Caption := inttostr(PowerInfo.BatteryLifeTime div 60) + ' min';
  end else Label4.Caption := 'No system battery';
  if PowerInfo.BatteryFullLifeTime < MAXDWORD then begin
   Label5.Caption := inttostr(PowerInfo.BatteryFullLifeTime div 60) + ' min';
  end else Label5.Caption := 'No system battery';
end else Label1.Caption := 'Failed to get power status';
end;

---





Please rate this article!
Skill level:
BeginnerExpert

Useful:
No!Very!

Overall rating:
PoorExcellent



Comments to this article
Write a new comment













 
Sign up to consume product discounts for Bronze memberships !

read more


  Visit our Sponsor

 

  Community Ad of
I. Siticov
 
   














 







     
  Copyright © 2000 - 2007 delphi3000.com - All rights reserved. Terms of use. || Privacy
delphi3000.com is a service by bluestep.com IT-Services GmbH (Vienna)