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 tstrings类的一些技巧

Delphi二值图像投影算法

Delphi暴力关机代码

Delphi 如何识别应用程序没有响应

Delphi 自带单元字符md5加密

Delphi 根据开始和结束符取得中间字符串

Delphi fmx 截图

Delphi 消息实现窗口最小化,最大化,关闭(Delphi)

Delphi app检测智能手机震动

Delphi application.restore; 简单用法

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



打赏

取消

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

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

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

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

评论

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