zoukankan      html  css  js  c++  java
  • 居然还有WM_TIMECHANGE(只在用户手动改变系统时间时才会产生作用)

    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.

    参考:http://www.cnblogs.com/key-ok/p/3417728.html

  • 相关阅读:
    Xpath语法与lxml库的用法
    Selenium--使用参考
    PhantomJS的替代品--无头浏览器(Headless Chrome)
    为什么只有一个元素的tuple要加逗号?
    反爬利器--设置代理服务器
    LeetCode 221. 最大正方形 | Python
    LeetCode 572. 另一个树的子树 | Python
    LeetCode 98. 验证二叉搜索树 | Python
    LeetCode 45. 跳跃游戏 II | Python
    LeetCode 25. K 个一组翻转链表 | Python
  • 原文地址:https://www.cnblogs.com/findumars/p/4748404.html
Copyright © 2011-2022 走看看