unit Unit1;
interface
uses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs, StdCtrls;
const ClearMessage= WM_USER+1;
type
TForm1 = class(TForm)
edt1: TEdit;
btn1: TButton;
procedure FormCreate(Sender: TObject);
procedure btn1Click(Sender: TObject);
private
{ Private declarations }
public
procedure ClearEdit(var Message: TMessage);
message ClearMessage;
{ Public declarations }
end;
ThdSendMessage= class(TThread)
private
Fhandle:THandle;
public
procedure Execute;override;
constructor create(Ahandle:THandle);
end;
var
Form1: TForm1;
implementation
{$R *.dfm}
procedure TForm1.FormCreate(Sender: TObject);
begin
edt1.Text:=btn1.Caption;
end;
{ ThdSendMessage }
constructor ThdSendMessage.create(Ahandle: THandle);
begin
inherited create(False);
Fhandle:= Ahandle;
FreeOnTerminate:= True;
end;
procedure ThdSendMessage.Execute;
begin
inherited;
//发送清除消息
SendMessage(Fhandle,ClearMessage,Fhandle,0) ;
end;
procedure TForm1.btn1Click(Sender: TObject);
begin
ThdSendMessage.create(Self.Handle);
end;
procedure TForm1.ClearEdit(var Message: TMessage);
begin
inherited;
if Message.Msg= ClearMessage then
edt1.Text:='';
end;
end.