我用自定义消息在主窗口用PostMessage(Findhd, WM_USER+500, 0, 0);向子窗口发送消息,在子窗口接受消息如下:unit bbb;interfaceuses
  Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
  Dialogs; const
  WM_CCC=WM_USER+500;type
  TForm2 = class(TForm)
  private  public
  { Private declarations }
    { Public declarations }
  end; typeTmypaint=recordmsgid:cardinal; msize:word; mcolor:longint; msgresult:longint; end; type
Tmycontrol=class(TControl)
protected
    procedure WMBarIcon1(var
 Message: TMessage); message WM_CCC;end;var
  Form2: TForm2;implementationprocedure Tmycontrol.WMBarIcon1
(var Message:TMessage);
var
  lpData:Tmypaint;
begin
  if Message.WParam = WM_CCC then
  begin
        ShowMessage('ccccccccccc');
  end;
end;{$R *.dfm}end.
为什么我收不到消息?

解决方案 »

  1.   

    type
      TForm2 = class(TForm)
      private
      public
      { Private declarations }
    procedure WMBarIcon1(var Message: TMessage); message WM_CCC;  放到这里才可以.
        { Public declarations }
      end;
      

  2.   

    放在后面也不行,我是在主窗口Form1向子窗口Form2发自定义消息,好象我的消息处理函数procedure Tmycontrol.WMBarIcon1(var Message:TMessage);根本都没有执行
      

  3.   

    呵呵,  //if Message.WParam = WM_CCC then 屏蔽这条
      begin
            ShowMessage('ccccccccccc');
      end;
      

  4.   

    PostMessage(Form2.Handle, WM_USER+500, 0, 0)意味着: Message.WParam = 0;
             Message.LParam = 0;
      

  5.   

    我就是把这句屏蔽掉了发现根本没有执行这个函数,我发消息应该是发送成功的,Findhd := FindWindow(nil,pchar('Form2'));
            if Findhd <> 0 then
            begin
            PostMessage(Findhd, WM_CCC, WM_CCC, 0);
            end else
            ShowMessage('not find windows');
    我把WM_CCC改成WM_Close就会把窗口关掉,
      

  6.   

    看看函数定义,你就明白了。
    PostMessage(
        HWND hWnd, // handle of destination window
        UINT Msg, // message to post 
        WPARAM wParam, // first message parameter
        LPARAM lParam  // second message parameter
       );
      

  7.   

    你这样看看procedure TForm1.N111111Click(Sender: TObject);
    begin
      PostMessage(Form2.Handle, WM_USER+500, 0, 0);
    end;。procedure TForm2.WMBarIcon1(var Message: TMessage);
    begin
      ShowMessage('ccccccccccc');
    end;
    上面运行没有任何问题。
      

  8.   

    const
      WM_CCC=WM_USER+500;type
      TForm2 = class(TForm)
        Button1: TButton;
      private
        procedure WMBarIcon1(var Message: TMessage); message WM_CCC;
      public
        { Public declarations }
      end;
      

  9.   

    我把你的FindWindow(nil,pchar('Form2'))以及PostMessage(hn, WM_USER+500, WM_USER+500, 0)都测试了,没有任何问题,消息马上出来了。