killtimeru.pas
来自「Delphi Win32核心API参考光盘源码 本书包含了常用的Windows」· PAS 代码 · 共 72 行
PAS
72 行
unit KillTimerU;
interface
uses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs, StdCtrls;
type
TForm1 = class(TForm)
Button1: TButton;
Button2: TButton;
Label1: TLabel;
procedure Button1Click(Sender: TObject);
procedure Button2Click(Sender: TObject);
private
{ Private declarations }
public
{ Public declarations }
end;
{our timer callback prototype. notice the export directive}
procedure TimerProc(hWnd:HWND;uMsg:UINT;idEvent:UINT;Time:DWORD);stdcall;export;
var
Form1: TForm1;
DemoCounter: Integer; // a counter to demonstrate that a timer is running
const
EXAMPLETIMER = 1; // a timer identifier
implementation
{$R *.dfm}
{this function is run every time EXAMPLETIMER fires}
procedure TimerProc(hWnd: HWND; uMsg: UINT; idEvent: UINT; Time: DWORD);
begin
{display a message to show that the timer is running}
Form1.Label1.Caption := 'Timer1 is Now Running: ' + IntToStr(DemoCounter);
{increment a counter to show that the timer is running}
Inc(DemoCounter);
end;
procedure TForm1.Button1Click(Sender: TObject);
begin
{reset our counter}
DemoCounter:= 0;
{create a timer to fire once per second}
SetTimer(Form1.Handle, // handle of window for timer messages
EXAMPLETIMER, // timer identifier
1000, // fire every 1000 milliseconds
@TimerProc // address of timer procedure
);
end;
procedure TForm1.Button2Click(Sender: TObject);
begin
{remove our example timer}
KillTimer(Form1.Handle, // handle of window that installed timer
EXAMPLETIMER // timer identifier
);
{clear the caption}
Label1.Caption := '';
end;
end.
⌨️ 快捷键说明
复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?