Delphi-PRAXiS

Delphi-PRAXiS (https://www.delphipraxis.net/forum.php)
-   Library: Windows API / MS.NET Framework API (https://www.delphipraxis.net/20-library-windows-api-ms-net-framework-api/)
-   -   Delphi Status der System-batterie ermitteln (https://www.delphipraxis.net/21787-status-der-system-batterie-ermitteln.html)

Luckie 8. Mai 2004 01:42


Status der System-batterie ermitteln
 
Delphi-Quellcode:
function GetPowerStatus(var HasBattery: Boolean; var LoadStatusString: String;
  var LoadstatusPercent: Integer): DWORD;
var
  SystemPowerStatus: TSystemPowerStatus;
  Text: string;
resourcestring
  rsLoadStatusUnknown = 'Unbekannter Status';
  rsLoadStatusNoBattery = 'Es existiert keine Batterie';
  rsLoadStatusHigh = 'Hoher Ladezustand';
  rsLoadStatusLow = 'Niedriger Ladezustand';
  rsLoadStatusCritical = 'Kritischer Ladezustand';
  rsLoadStatusLoading = 'Batterie wird geladen';
  rsLoadSatusUnknownLoading = 'Unbekannter Ladezustand';
begin
  SetLastError(0);
  if GetSystemPowerStatus(SystemPowerStatus) then
    with SystemPowerStatus do
    begin
      HasBattery := ACLineStatus = 0;

      // Ladezustand der Batterie
      if (BatteryFlag = 255) then
        Text := rsLoadStatusUnknown
      else if (BatteryFlag and 128 = 128) then
        Text := rsLoadStatusNoBattery
      else
      begin
        case (BatteryFlag and (1 or 2 or 4)) of
          1: Text := rsLoadStatusHigh;
          2: Text := rsLoadStatusLow;
          4: Text := rsLoadStatusCritical;
        else
          Text := rsLoadSatusUnknownLoading
        end;
        if (BatteryFlag and 8 = 8) then
          LoadStatusString := Text + rsLoadStatusLoading;
      end;

      // Ladezustand in Prozent
      if (BatteryLifePercent <> 255) then
        LoadstatusPercent := BatteryLifePercent
      else
        LoadstatusPercent := -1;
  end;
  Result := GetLastError;
end;
Nico Bendlin (NicoDE), Michael Puff (Luckie)


Alle Zeitangaben in WEZ +1. Es ist jetzt 17:14 Uhr.

Powered by vBulletin® Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
LinkBacks Enabled by vBSEO © 2011, Crawlability, Inc.
Delphi-PRAXiS (c) 2002 - 2023 by Daniel R. Wolf, 2024 by Thomas Breitkreuz