WinAPI: GetSystemPowerStatus - 获取系统电源状态的信息


//声明

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;
//效果图:
WinAPI: GetSystemPowerStatus - 获取系统电源状态的信息

你可能感兴趣的:(System)