//聲明GetSystemPowerStatus(
var lpSystemPowerStatus: TSystemPowerStatus {TSystemPowerStatus 結構}
): BOOL;
//TSystemPowerStatus 是 _SYSTEM_POWER_STATUS 結構的重定義:
_SYSTEM_POWER_STATUS = packed record
ACLineStatus : Byte; {0:電源斷電; 1:電源正常; 255:電源狀態未知}
BatteryFlag : Byte; {1:電量充足; 2:電量低; 4:電池基本耗盡; 8:充電; 128:沒有電池; 255:電池狀態未知}
BatteryLifePercent : Byte; {0..100:所剩電量百分數; 255:未知}
Reserved1 : Byte; {保留, 須為 0}
BatteryLifeTime : DWORD; {電池剩余能量; -1 表示未知}
BatteryFullLifeTime : DWORD; {電池總能量; -1 表示未知}
end;
//舉例:
procedure TForm1.FormCreate(Sender: TObject);
var
Power: TSystemPowerStatus;
begin
GetSystemPowerStatus(Power);
Memo1.Clear;
with Memo1.Lines do
begin
Add(Format('電源狀態: %d',[Power.ACLineStatus]));
Add(Format('電池狀態: %d',[Power.BatteryFlag]));
Add(Format('電量百分比: %d',[Power.BatteryLifePercent]));
Add(Format('剩余能量: %d',[Power.BatteryLifeTime]));
Add(Format('總能量: %d',[Power.BatteryFullLifeTime]));
end;
end;
//效果圖: