unit Unit2;
interface
uses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs, StdCtrls;
type
TMyThread =
class(TThread)
private
FWNDHandle: Cardinal;
procedure WndProc(
var Msg: TMessage);
protected
procedure Execute;
override;
public
Constructor Create(CreateSuspended: Boolean);
Reintroduce;
overload;
Constructor Create;
Reintroduce;
overload;
Destructor Destroy;
override;
property GetWNDHandle: Cardinal
read FWNDHandle;
end;
TForm2 =
class(TForm)
Button1: TButton;
Button2: TButton;
procedure Button1Click(Sender: TObject);
procedure Button2Click(Sender: TObject);
private
FMyThread :TMyThread;
{ Private-Deklarationen }
public
Fmsg:TMessage;
{ Public-Deklarationen }
end;
var
Form2: TForm2;
implementation
{$R *.dfm}
constructor TMyThread.Create(CreateSuspended: Boolean);
begin
inherited Create(CreateSuspended);
FWNDHandle := AllocateHWnd(WndProc);
end;
constructor TMyThread.Create;
begin
inherited Create;
FWNDHandle := AllocateHWnd(WndProc);
end;
destructor TMyThread.Destroy;
begin
DeallocateHWnd(FWNDHandle);
inherited;
end;
procedure TMyThread.Execute;
begin
while not Terminated
do
begin
Sleep(10);
end;
end;
procedure TMyThread.WndProc(
var Msg: TMessage);
begin
OutputDebugString(PWideChar('
TMyThread.WndProc - Msg: #' + IntToStr(Msg.Msg) + '
-'+ IntToStr(Msg.WParam)));
end;
procedure TForm2.Button1Click(Sender: TObject);
begin
FMyThread := TMyThread.Create(false);
end;
procedure TForm2.Button2Click(Sender: TObject);
begin
Fmsg.Msg := 12345;
FMsg.WParam := 2345;
SendMessage(FMyThread.GetWNDHandle,FMsg.Msg,FMsg.WParam,FMsg.LParam);
end;
end.