当笔记本电脑运行在电池(或AC)上时,如何检测(从德尔福)?
解决方法
要在Vista和
Windows 7上的状态更改时通知您,您可以使用
RegisterPowerSettingNotification.
对于Windows 2000及更高版本,请查看GetSystemPowerStatus,或转到MSDN阅读约Power Management.
(有人总是在我打字时发帖:-()
function GetBattery : Boolean;
var
SysPowerStatus: TSystemPowerStatus;
begin
Win32Check(GetSystemPowerStatus(SysPowerStatus));
case SysPowerStatus.ACLinestatus of
0: Result := False;
1: begin
Result := True;
// You can return life with
// String := Format('Battery power left: %u percent.',SysPowerStatus.BatteryLifePercent]);
end;
else
raise Exception.Create('UnkNown battery status');
end;
end;