如何检测笔记本电脑何时使用电池供电? [英] How to detect when the laptop is running on batteries?

查看:258
本文介绍了如何检测笔记本电脑何时使用电池供电?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

当笔记本电脑使用电池(或交流电)运行时,如何检测(通过Delphi)?

How to detect (from Delphi) when the laptop is running on batteries (or AC)?

推荐答案

要通知当状态在Vista和Windows 7上更改时,可以使用 RegisterPowerSettingNotification

To be notified when the status changes on Vista and Windows 7 you can use RegisterPowerSettingNotification.

对于Windows 2000及更高版本,请查看 GetSystemPowerStatus ,或转到MSDN并阅读有关电源管理

For Windows 2000 and later, look at GetSystemPowerStatus, or go to MSDN and read about Power Management.

(有人总是在我正在输入:-()

(Someone always posts while I am typing :-( )

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;

这篇关于如何检测笔记本电脑何时使用电池供电?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆