⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 unit1.pas

📁 Delphi7编程80例(完全版)
💻 PAS
字号:
unit Unit1;

interface

uses
  Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms, Dialogs,
  StdCtrls;

type
  TForm1 = class(TForm)
    Button1: TButton;
    Label1: TLabel;
    Label2: TLabel;
    Label3: TLabel;
    Label4: TLabel;
    Label5: TLabel;
    Button2: TButton;
    Label6: TLabel;
    procedure Button1Click(Sender: TObject);
    procedure Button2Click(Sender: TObject);
  private
    { Private declarations }
  public
    { Public declarations }
  end;

var
  Form1: TForm1;

implementation

{$R *.DFM}

procedure TForm1.Button1Click(Sender: TObject);
var lpsps:SYSTEM_POWER_STATUS;
begin
  GetSystemPowerStatus(lpsps);
  Case lpsps.ACLineStatus of
   0:Label1.Caption:='电源状态    脱机';
   1:Label1.Caption:='电源状态    联机';
   2:Label1.Caption:='电源状态    未知';
  end;
  Case lpsps.BatteryFlag of
   1:  Label2.Caption:='电池状态    高';
   2:  Label2.Caption:='电池状态    低';
   4:  Label2.Caption:='电池状态    临界';
   8:  Label2.Caption:='电池状态    充电';
   128:Label2.Caption:='电池状态    无系统电池';
   255:Label2.Caption:='电池状态    未知';
  end;
  Case lpsps.BatteryLifePercent of
   0..100:Label3.Caption:='剩余电池    '+IntToStr(lpsps.BatteryLifePercent*100)+'%';//注意选择标志的用法
   255:   Label3.Caption:='剩余电池    未知';
  end;
  If lpsps.BatteryLifeTime=$FFFFFFFF Then
   Label4.Caption:='电池剩余时间    未知'
  Else
   Label4.Caption:='电池剩余时间    '+IntToStr(lpsps.BatteryLifeTime)+'秒';
  If lpsps.BatteryFullLifeTime=$FFFFFFFF Then
   Label5.Caption:='电池总使用时间    未知'
  Else
   Label5.Caption:='电池总使用时间    '+IntToStr(lpsps.BatteryFullLifeTime)+'秒';
end;

procedure TForm1.Button2Click(Sender: TObject);
begin
If SetSystemPowerState(false,false)=true then
 Label6.Caption:='成功休眠'
Else
 Label6.Caption:='不支持休眠或休眠失败';
end;

end.

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -