BroadCast只是下广播一个消息。那么子控件都能接收这个消息。至于每个控件是否响应这个消息,要看每个控件是否有响应该消息的代码。
打个比方,你可以通知每个人开会。但是至于每个人是否参加会议,则要看他们是否响应。

解决方案 »

  1.   

    那么响应的这段代码是写在什么地方呢?比如一个form向它的所有子控件发送一个broadcast的消息,那么这个form上的一个button如何响应这个消息?
      

  2.   

    那个button里面要有响应消息的代码啊。比如CM_ENTERprocedure CMEnter(var Msg: TMessage); message CM_ENTER;
      

  3.   

    这个过程是写在button的类里么?可以给一个简单的例子么?还是不是很明白
      

  4.   

    难道还要重新写一个button的类?
      

  5.   

    如果不重写button类的话,就必须subclass那个button。
      

  6.   

    subclass是继承么?这样好麻烦,那这样所有的子控件都要重写阿,没有更好的办法么?chechy大虾?
      

  7.   

    而且不能拿鼠标扔到form里,所有的控件都要手工create那不是很郁闷阿
      

  8.   

    subclass不是继承,我翻译不过来。其意义就是用你自己的Window Procedure替代控件缺省的Window Procedure。这样就可以不重写控件了。
      

  9.   

    而且发送自定义消息控件会友缺省window procedure吗?
      

  10.   

    D5DG中的例子,你自己看吧:unit Main;interfaceuses
      SysUtils, WinTypes, WinProcs, Messages, Classes, Graphics, Controls,
      Forms, Dialogs, StdCtrls;type
      TMainForm = class(TForm)
        SendBtn: TButton;
        PostBtn: TButton;
        procedure SendBtnClick(Sender: TObject);
        procedure PostBtnClick(Sender: TObject);
        procedure FormCreate(Sender: TObject);
        procedure FormDestroy(Sender: TObject);
      private
        OldWndProc: Pointer;
        WndProcPtr: Pointer;
        procedure WndMethod(var Msg: TMessage);
        procedure HandleAppMessage(var Msg: TMsg; var Handled: Boolean);
      end;var
      MainForm: TMainForm;implementation{$R *.DFM}uses ScWndPrc;
    procedure TMainForm.HandleAppMessage(var Msg: TMsg; var Handled: Boolean);
    { OnMessage handler for Application object. }
    begin
      if Msg.Message = DDGM_FOOMSG then
        { if it's the user-defined message, then alert the user. }
        ShowMessage(Format('Message seen by OnMessage! Value is: $%x',
          [Msg.Message]));
    end;procedure TMainForm.WndMethod(var Msg: TMessage);
    begin
      if Msg.Msg = DDGM_FOOMSG then
        { if it's the user-defined message, then alert the user. }
        ShowMessage(Format('Message seen by WndMethod! Value is: $%x', [Msg.Msg]));
      with Msg do
        { Pass message on to old window procedure. }
        Result := CallWindowProc(OldWndProc, Application.Handle, Msg, wParam,
          lParam);
    end;procedure TMainForm.SendBtnClick(Sender: TObject);
    begin
      SendMessage(Application.Handle, DDGM_FOOMSG, 0, 0);
    end;procedure TMainForm.PostBtnClick(Sender: TObject);
    begin
      PostMessage(Application.Handle, DDGM_FOOMSG, 0, 0);
    end;procedure TMainForm.FormCreate(Sender: TObject);
    begin
      Application.OnMessage := HandleAppMessage;     // set OnMessage handler
      WndProcPtr := MakeObjectInstance(WndMethod);   // make window proc
      { Set window procedure of application window. }
      OldWndProc := Pointer(SetWindowLong(Application.Handle, GWL_WNDPROC,
        Integer(WndProcPtr)));
    end;procedure TMainForm.FormDestroy(Sender: TObject);
    begin
      { Restore old window procedure for Application window }
      SetWindowLong(Application.Handle, GWL_WNDPROC, Longint(OldWndProc));
      { Free our user-created window procedure }
      FreeObjectInstance(WndProcPtr);
    end;end.unit Scwndprc;interfaceuses Forms, Messages;const
      DDGM_FOOMSG = WM_USER;implementationuses Windows, SysUtils, Dialogs;var
      WProc: Pointer;function NewWndProc(Handle: hWnd; Msg, wParam, lParam: Longint): Longint;
      stdcall;
    { This is a Win32 API-level window procedure. It handles the messages }
    { received by the Application window. }
    begin
      if Msg = DDGM_FOOMSG then
        { If it's our user-defined message, then alert the user. }
        ShowMessage(Format('Message seen by WndProc! Value is: $%x', [Msg]));
      { Pass message on to old window procedure }
      Result := CallWindowProc(WProc, Handle, Msg, wParam, lParam);
    end;initialization
      { Set window procedure of Application window. }
      WProc := Pointer(SetWindowLong(Application.Handle, gwl_WndProc,
        Integer(@NewWndProc)));
    end.
      

  11.   

    my god这样做还不如重写一个button, 用message阿   或者直接override   WinProc