this slowpoke moves

Get PC Power Status

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;

procedure TForm1.Button1Click(Sender: TObject);
var
  dwResult: DWORD;
  HasBattery: Boolean;
  LoadStatutsString: String;
  LoadstatusPercent: Integer;
  s : String;
begin
  dwResult := GetPowerStatus(HasBattery, LoadStatutsString, LoadstatusPercent);
  if dwResult = 0 then
  begin
    if HasBattery then
      s := 'Stromversorgung: Battery'
    else
      s := 'Stromversorgung: Wechselstrom';
    s := s + #13#10+
      'Ladestatus: '+LoadStatutsString+#13#10+
      'Ladestatus in Prozent: '+IntToStr(LoadstatusPercent);
    ShowMessage(s);
  end
  else
    ShowMessage(SysErrorMessage(dwResult));
end;

Keine Kommentare:

Kommentar veröffentlichen

Beliebte Posts

Translate