大悟还俗

邮箱 key_ok@qq.com 我的收集 http://pan.baidu.com/share/home?uk=1177427271
posts - 236, comments - 8, trackbacks - 0, articles - 0
  新随笔 :: 联系 :: 订阅 订阅 :: 管理

公告

delphi中Time消息的使用方法

Posted on 2013-11-11 13:03 大悟还俗 阅读(...) 评论(...) 编辑 收藏
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.
View Code