试试这样 。
手里有没有编译环境,瞎写一下哈。。。
在TForm中定义一个变量标识。FActive: Boolean;
然后定义消息。
WM_begin
= WM_USER + 1001;
WM_END = WM_USER + 1002;
Type
TForm1 = class(TForm)
procedure FormCreate(Sender: TObject);
public
procedure WMbegin
(var Msg: TMessage);message WM_begin
;
procedure WMEnd(var Msg:TMessage);message WM_end;
end;
var
Form1: TForm1;
tt: TTestThread;
//实现
procedure TForm1.FormCreate(Sender: TObject);
begin
tt := TTestThread.Create(Handle, False);
end;
procedure TForm1.WMbegin
(var Msg: TMessage);
begin
FActive := True;
end;
procedure TForm1.WMEND(var Msg: TMessage)
begin
FActive := False;
end;
然后在线程类中,如TTestThread = class(TThread)
private
FHandle: THandle;
protected
procedure Execute;override;
Constructor Create(Handle: THandle;
CreateSuspended: Boolean);
end;
Constructor TTestThread.Create(Handle:THandle;
CreateSuspended: Boolean);
begin
FHandle := Handle;
inherited Create(CreateSuspended);
end;
procedure TTestThread.Execute;
begin
SendMessage(FHandle, WM_begin
, 0, 0);
//DoSomething;
SendMessage(Fhandle, WM_END, 0, 0);
end;