Einzelnen Beitrag anzeigen

Viktorii

Registriert seit: 19. Jul 2007
358 Beiträge
 
#8

AW: Windows Messages in einem (TThread-)Thread empfangen

  Alt 3. Feb 2011, 14:29
So habe ich es versucht:

Delphi-Quellcode:
procedure TForm1.FormCreate(Sender: TObject);
begin
  FMyThread := TMyThread.Create(false);
end;

procedure TForm1.WndProc(var Msg: TMessage);
begin
  if assigned(FMyThread) then
  begin
    OutputDebugString(PWideChar('TForm1.WndProc - Msg: #' + IntToStr(Msg.Msg)));
    PostMessage(FMyThread.GetWNDHandle,Msg.Msg,Msg.WParam,Msg.LParam);
  end;
  inherited;
end;
Delphi-Quellcode:
type
  TMyThread = class(TThread)
  private
    FWNDHandle: Cardinal;
    procedure WndProc(var Msg: TMessage);
  protected
    procedure Execute; override;
  public
    property GetWNDHandle: Cardinal read FWNDHandle;
  end;

implementation

uses
  Windows, SysUtils;

procedure TMyThread.Execute;
begin
  FWNDHandle := AllocateHWnd(WndProc);

  while not Terminated do
  begin
    //suspend();
  end;

  DeallocateHWnd(FWNDHandle);
end;

procedure TMyThread.WndProc(var Msg: TMessage);
begin
  OutputDebugString(PWideChar('TMyThread.WndProc - Msg: #' + IntToStr(Msg.Msg)));
end;

Aber es scheint nichts im Thread anzukommen
  Mit Zitat antworten Zitat