delphi中Time消息的使用方法


本文整理自网络,侵删。

 
unit Unit1;
interface
uses
 Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,Dialogs, StdCtrls;
const
 TIMER_ID = 200;
type
 TForm1 = class(TForm)
    Label1: TLabel;
    btkilltime: TButton;
    btsettime: TButton;
    procedure Button1Click(Sender: TObject);
    procedure btkilltimeClick(Sender: TObject);
    procedure btsettimeClick(Sender: TObject);
 private
    { Private declarations }
 public
{ Public declarations }
// WM_TIMECHANGE只在用户手动改变系统时间时才会产生作用,且只需直接定义就起作用。
procedure WMTIMECHANGE(var Message: TWMTIMECHANGE); message WM_TIMECHANGE;
// WM_TIMER需配合KillTimer和SetTimer才能起作用;它保持与系统时间同步触发事件;
    procedure WMTimer(var Message: TWMTimer); message WM_TIMER;
 end;   
var
 Form1: TForm1;
implementation
{$R *.dfm}
procedure TForm1.WMTIMECHANGE(var Message: TWMTIMECHANGE);
begin
 ShowMessage('sss');
end;
 
procedure TForm1.WMTimer(var Message: TWMTimer);
begin
   Label1.Caption:=TimeToStr(now);
end;
 
procedure TForm1.btkilltimeClick(Sender: TObject);
begin
// KillTimer作用:向WINDOWS删除时间消息;参数200必须与SetTimer中参数200保持一致,此参数代表所注册的消息ID;
KillTimer(self.Handle, 200); // KillTimer(self.Handle, TIMER_ID);
end;
 
procedure TForm1.btsettimeClick(Sender: TObject);
begin
   // SetTimer作用:向WINDOWS注册时间消息;参数1000代表每隔1秒触发一次WM_TIMER消息;
 SetTimer(self.Handle, 200, 1000, nil); // SetTimer(self.Handle, TIMER_ID, 1000, nil);
end;
 
end.

相关阅读 >>

Delphi 获取文件大小方法

Delphi 使用 {$include} 或 {$i} 指令管理和调用自定义函数

Delphi wmi 取硬件信息

Delphi xe将图标和图像添加为资源

Delphi向imagelist中加入png类型的资源图片

Delphi idhttpserver使用注意问题

Delphi 软关闭显示器的代码

Delphi xe中windows7新的taskbar功能的使用

Delphi把一个字符串中的某个子串,用另一个子串去替换

Delphi操作excel说明

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



打赏

取消

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

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

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

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

评论

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