unit Unit2;interfaceuses
  Classes,Windows,Messages;type
  Comthread = class(TThread)
  private
    { Private declarations }
  protected
    procedure Execute; override;
  end;implementationuses unit1;
procedure Comthread.Execute;
begin   PostMessage(Form1.Handle,WM_COMMNOTIFY,0,0);
end;end.
unit Unit1;interfaceuses
  Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
  Dialogs,unit2, StdCtrls;type
  TForm1 = class(TForm)
    Button1: TButton;
    procedure Button1Click(Sender: TObject);
  private
    Procedure   MsgcommProcess(Var   Message:Tmessage);   Message   Wm_commnotify;
    { Private declarations }
  public
    { Public declarations }
  end;var
  Form1: TForm1;const
  Wm_commNotify=Wm_User+12;
implementation{$R *.dfm}procedure TForm1.Button1Click(Sender: TObject);
begin
  Comthread.Create(false);
end;procedure TForm1.MsgcommProcess(var Message : TMessage);
begin
  showmessage('A');
end;
end.
 

解决方案 »

  1.   

    在线程中发消息,要用SendMessage,不要用PostMessage
      

  2.   

    为什么不 能用PostMessage
    我昨天还能响应 ,机器重装 吧代码给删了 
    今天 就响应不了了 
    我就是想不管主线程的运行情况噶 
      

  3.   

    PostMessage是非阻塞的,不论是否成功,立即返回
      

  4.   

    SendMessage是阻塞式的,会等待消息返回
      

  5.   

    unit Unit2; interface uses 
      Classes,Windows,Messages; type 
      Comthread = class(TThread) 
      private 
        { Private declarations } 
      protected 
        procedure Execute; override; 
      end; implementation uses unit1; 
    procedure Comthread.Execute; 
    begin   PostMessage(Form1.Handle,WM_COMMNOTIFY,0,0); 
    end; end. 
    unit Unit1; interface uses 
      Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms, 
      Dialogs,unit2, StdCtrls; 
    const 
      Wm_commNotify=Wm_User+12; // 提到這裏來。
    type 
      TForm1 = class(TForm) 
        Button1: TButton; 
        procedure Button1Click(Sender: TObject); 
      private 
        Procedure  MsgcommProcess(Var  Message:Tmessage);  Message  Wm_commnotify; 
        { Private declarations } 
      public 
        { Public declarations } 
      end; var 
      Form1: TForm1; 
    implementation {$R *.dfm} procedure TForm1.Button1Click(Sender: TObject); 
    begin 
      Comthread.Create(false); 
    end; procedure TForm1.MsgcommProcess(var Message : TMessage); 
    begin 
      showmessage('A'); 
    end; 
    end.
      

  6.   

    wm_commnotify好像是系统消息, 你又定义了一遍,去掉二次定义,或用5楼的方法试试