第二种写法和第一种差不多,唯一的区别是,第一种方法多了一个消息队列。
所有的线程建立的时候都没有消息队列,直到它调用任何一个USER或者GDI函数位置
unit Unit1;
interface
uses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs, StdCtrls;
type
TForm1 = class(TForm)
mmo1: TMemo;
procedure FormCreate(Sender: TObject);
procedure FormDestroy(Sender: TObject);
private
{ Private declarations }
public
{ Public declarations }
end;
var
TimerID : Integer;
MyMsg : TMsg;
Form1: TForm1;
implementation
{$R *.dfm}
procedure Timerproc( window : Hwnd ; message,idEvent :UInt; dwTime: dword);stdcall;
begin
Form1.mmo1.Lines.Add('Running...');
end;
procedure TForm1.FormCreate(Sender: TObject);
begin
TimerID := SetTimer(0,0,1000,@TimerProc);
end;
procedure TForm1.FormDestroy(Sender: TObject);
begin
KillTimer(0,TimerID);
end;
end.