帮我看看我的自定义消息,怎么没有反映啊
unit Unit1;interfaceuses
  Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms, Dialogs,
  StdCtrls;
 const WM_SHOW  = WM_USER+1024;
type
  TForm1 = class(TForm)
    Edit1: TEdit;
    Edit2: TEdit;
    Button1: TButton;
    procedure Edit1KeyPress(Sender: TObject; var Key: Char);
  private
    { Private declarations }
  public
  procedure WMSHOW(var MSG:Tmessage); message WM_SHOW;
    { Public declarations }
  end;var
  Form1: TForm1;implementation{$R *.DFM}procedure TForm1.Edit1KeyPress(Sender: TObject; var Key: Char);
 begin
 IF KEY=#13 THEN
       sendmessage(Hedit,WM_SHOW,0,0);
 end;
procedure TForm1.WMSHOW(VAR MSG:Tmessage);
begin
  showmessage('系统收到消息');
  inherited;
end;
end.

解决方案 »

  1.   

    你要把消息发给哪个窗口啊?你发给你的form试试,把Hedit换成self.handle
      

  2.   

    对了,Hedit应该是个句柄,你是否已经赋值
      

  3.   

    不是每个窗口都能接受到你的消息。你看看处理edit消息的窗口过程吧。
      

  4.   

    不好意思,刚才我写错了,应该是这样的:
    unit Unit1;interfaceuses
      Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms, Dialogs,
      StdCtrls;
     const WM_SHOW  = WM_USER+1024;
    type
      TForm1 = class(TForm)
        Edit1: TEdit;
        procedure Edit1KeyPress(Sender: TObject; var Key: Char);
      private
        { Private declarations }
      public
      procedure WMSHOW(var MSG:Tmessage); message WM_SHOW;
        { Public declarations }
      end;var
      Form1: TForm1;implementation{$R *.DFM}procedure TForm1.Edit1KeyPress(Sender: TObject; var Key: Char);
    begin
         sendmessage(application.handle,WM_SHOW,0,0);
     end;
    procedure TForm1.WMSHOW(VAR MSG:Tmessage);
    begin
      showmessage('系统收到消息');
    end;
    end.
      

  5.   

    我也不知道为什么,我换成给EDIT2赋值也不对
    unit Unit1;interfaceuses
      Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms, Dialogs,
      StdCtrls;
    type
      TForm1 = class(TForm)
        Edit1: TEdit;
        Edit2: TEdit;
        Button1: TButton;
        procedure Edit1KeyPress(Sender: TObject; var Key: Char);
      private
        { Private declarations }
      public
      procedure WMSHOW(var MSG:Tmessage); message WM_SHOW;
        { Public declarations }
      end;var
      Form1: TForm1;implementation{$R *.DFM}procedure TForm1.Edit1KeyPress(Sender: TObject; var Key: Char);
    var
      Hwindow,Hedit:Thandle;
     begin
     IF KEY=#13 THEN
     begin
       Hwindow:=0;
       Hedit:=0 ;
       Hwindow:=findwindowex(0,Hwindow,'TForm1','Form1');
       if Hwindow=0 then exit
       else begin
         Hedit:=findwindowex(Hwindow,Hedit,'TEdit','Edit2');
         sendmessage(Hedit,WM_SETTEXT,0,0);
     end;
    end;
    end;end.
      

  6.   

    unit Unit1;interfaceuses
      Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
      Dialogs, StdCtrls;const WM_SHOW  = WM_USER+1024;type
      TForm1 = class(TForm)
        Edit1: TEdit;
        procedure Edit1KeyPress(Sender: TObject; var Key: Char);
      private
        { Private declarations }
      public
        procedure WMSHOW(var MSG:Tmessage); message WM_SHOW;
      end;var
      Form1: TForm1;implementation{$R *.dfm}procedure TForm1.Edit1KeyPress(Sender: TObject; var Key: Char);
    begin
      sendmessage(handle,WM_SHOW,0,0);//改这里就行了
    end;procedure TForm1.WMSHOW(var MSG: Tmessage);
    begin
      showmessage('系统收到消息');
    end;end.
      

  7.   

    unit Unit1;interfaceuses
      Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
      Dialogs, StdCtrls;const WM_SHOW  = WM_USER+1024;type
      TForm1 = class(TForm)
        Edit1: TEdit;
        procedure Edit1KeyPress(Sender: TObject; var Key: Char);
      private
        { Private declarations }
      public
        procedure WMSHOW(var MSG:Tmessage); message WM_SHOW;
      end;var
      Form1: TForm1;implementation{$R *.dfm}procedure TForm1.Edit1KeyPress(Sender: TObject; var Key: Char);
    begin
      sendmessage(handle,WM_SHOW,0,0);//改这里就行了
    end;procedure TForm1.WMSHOW(var MSG: Tmessage);
    begin
      showmessage('系统收到消息');
    end;end.
      

  8.   

    谢谢上面各位,但我还想问问网虫先生:
      你改的那里Hanldle是什么的句柄啊,我看程序里也没有定义,而且为什么application.Handle不对啊,还有就是我如果想直接给EDIT2发消息,用下面的程序怎么就不可以啊:(   
      Hwindow:=0;
       Hedit:=0 ;
       Hwindow:=findwindowex(0,Hwindow,'TForm1','Form1');
       if Hwindow=0 then exit
       else begin
         Hedit:=findwindowex(Hwindow,Hedit,'TEdit','Edit2');
         sendmessage(Hedit,WM_SETTEXT,0,0);
      

  9.   

    这个消息应该发送给Form1,
    Handle应该是Form1的