zoukankan      html  css  js  c++  java
  • 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.
  • 相关阅读:
    iOS-MVC设计模式
    LoadRunner中文转码
    LoadRunner中Base64编码解码
    jmeter持续集成化(一)---jmeter+Ant+DOS构建执行脚本
    LoadRunner MD5加密
    Jmeter元件--BeanShell Timer
    ftp上传下载
    Shell编程实例
    Oracle数据库sqlplus操作
    oracle执行计划分析
  • 原文地址:https://www.cnblogs.com/china1/p/3419836.html
Copyright © 2011-2022 走看看