如何在 Inno Setup 中获取电池数据?

How to get battery data in Inno Setup?

我理解应该类似于下面的代码:

[Code]
type
  TSystemPowerStatus = {???};

function GetBattery(SYSTEM_POWER_STATUS: TSystemPowerStatus): Boolean;
external 'GetSystemPowerStatus@Kernel32.dll stdcall';

procedure ShowBatteryStatus();
var
  PowerStatus: TSystemPowerStatus; 
  State: String;
begin
  GetBattery(PowerStatus);
  State := IntToStr(PowerStatus.BatteryLifePercent);
  MsgBox(format('Battery Precents: %p',[State]), mbInformation, MB_OK);
end;

function InitializeSetup: Boolean;
begin
  ShowBatteryStatus()
  Result := True
end;

但是我找不到 TSystemPowerStatus 的正确类型。

无法识别 struct 类型。

有人可以帮忙吗?

谢谢!

这对我有用:

[Code]
type
  TSystemPowerStatus = record
    ACLineStatus : Byte;
    BatteryFlag : Byte;
    BatteryLifePercent : Byte;
    Reserved1 : Byte;
    BatteryLifeTime : DWORD;
    BatteryFullLifeTime : DWORD;
  end;

function GetSystemPowerStatus(var SYSTEM_POWER_STATUS: TSystemPowerStatus): Boolean;
external 'GetSystemPowerStatus@Kernel32.dll stdcall';

procedure ShowBatteryStatus();
var
  PowerStatus: TSystemPowerStatus; 
  State: String;

begin
  PowerStatus.ACLineStatus := 0;
  PowerStatus.BatteryFlag := 0;
  PowerStatus.BatteryLifePercent  := 0;
  PowerStatus.Reserved1 := 0;
  PowerStatus.BatteryLifeTime := 0;
  PowerStatus.BatteryFullLifeTime := 0;

  if (GetSystemPowerStatus(PowerStatus)) then
  begin
    State := IntToStr(PowerStatus.BatteryLifePercent);
    MsgBox(format('Battery Precents: %s',[State]), mbInformation, MB_OK);
  end
  else begin
    MsgBox(SysErrorMessage(DLLGetLastError), mbError, mb_Ok);    
  end;
end;

function InitializeSetup: Boolean;
begin
  ShowBatteryStatus()
  Result := True
end;