delphi 简单电池电量显示


本文整理自网络,侵删。

 

 

Project1.dpr

program Project1;

uses
  Forms,Windows,
  Unit1 in 'Unit1.pas' {Form1};

{$R *.res}

begin
  Application.Initialize;
  SetWindowLong(Application.Handle,GWL_EXSTYLE,WS_EX_TOOLWINDOW);//使程序不显示在任务栏中
  Application.Title := '电池电量显示';
  Application.CreateForm(TForm1, Form1);
  Application.Run;
end.

======================================================================
Unit1.pas

unit Unit1;

interface

uses
  Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
  Dialogs, StdCtrls, ExtCtrls, RzStatus, Menus;

type
  TForm1 = class(TForm)
    Timer1: TTimer;
    RzProgressStatus1: TRzProgressStatus;
    PopupMenu1: TPopupMenu;
    N1: TMenuItem;
    procedure Timer1Timer(Sender: TObject);
    procedure N1Click(Sender: TObject);
    procedure RzProgressStatus1MouseDown(Sender: TObject;
      Button: TMouseButton; Shift: TShiftState; X, Y: Integer);
    procedure FormCreate(Sender: TObject);
  private
    { Private declarations }
  public
    { Public declarations }
  end;

var
  Form1: TForm1;

implementation

{$R *.dfm}

procedure TForm1.Timer1Timer(Sender: TObject);
var
  Power: TSystemPowerStatus;
begin
   GetSystemPowerStatus(Power);
   RzProgressStatus1.Percent:=Power.BatteryLifePercent;//获取电量百分比
   //根据电量百分比显示不同颜色
   if Power.BatteryLifePercent>=40 then
    begin
      RzProgressStatus1.BarColor:=clLime;
      RzProgressStatus1.BarColorStop:=clGreen;
    end
   else if  (Power.BatteryLifePercent<40) and (Power.BatteryLifePercent>=10) then
    begin
      RzProgressStatus1.BarColor:=clYellow;
      RzProgressStatus1.BarColorStop:=clOlive;
    end
   else if Power.BatteryLifePercent<10 then
    begin
      RzProgressStatus1.BarColor:=clRed;
      RzProgressStatus1.BarColorStop:=clMaroon;
    end;
end;

procedure TForm1.N1Click(Sender: TObject);
begin
Close;
end;

procedure TForm1.RzProgressStatus1MouseDown(Sender: TObject;
  Button: TMouseButton; Shift: TShiftState; X, Y: Integer);
begin
 //为控件添加拖动事件,使其可以被拖动
 ReleaseCapture;
 SendMessage(Handle, WM_SYSCOMMAND, 61457, 0);
end;

procedure TForm1.FormCreate(Sender: TObject);
begin
  //指定显示位置..桌面右下角
  Form1.Left:=Screen.Width-RzProgressStatus1.Width+2;
  Form1.Top:=Screen.Height-RzProgressStatus1.Height-29;
end;

end.

 

来源:http://www.cnblogs.com/lahcs/archive/2009/03/17/1414099.html

相关阅读 >>

Delphi 如何比较两个二维数组是否相等

Delphi 新版内存表 fdmemtable

快速查询posex与posrightex

Delphi 域名转ip并判断ip是否可以联通 复制代码

Delphi实现线程池组件(完整源码)

Delphi实现使用tidhttp控件向https地址post请求

Delphi使用sqlite数据库时的中文路径问题

Delphi获取进程的命令行参数

Delphi try 抛出异常消息

Delphi 如何判断某一窗口最大化

更多相关阅读请进入《Delphi》频道 >>



打赏

取消

感谢您的支持,我会继续努力的!

扫码支持
扫码打赏,您说多少就多少

打开支付宝扫一扫,即可进行扫码打赏哦

分享从这里开始,精彩与您同在

评论

管理员已关闭评论功能...