RAD Studio |  |

Example: Message Handler

Here is the declaration of a message handler for a user-defined message called CM_CHANGECOLOR.

Copy Code

    const
      CM_CHANGECOLOR = WM_APP + 400;
    type
      TMyComponent = class(TControl)
      .
      .
      .
    protected
      procedure CMChangeColor(var Message: TMessage); message CM_CHANGECOLOR;
    end;
    procedure TMyComponent.CMChangeColor(var Message: TMessage);
    begin
      Color := Message.lParam;
      inherited;
    end;

Copy Code

    #define CM_CHANGECOLOR (WM_APP + 400)
    class TMyControl : public TControl
    {
    protected:
        void __fastcall CMChangeColor(TMessage &Message);
    BEGIN_MESSAGE_MAP
      MESSAGE_HANDLER(CM_CHANGECOLOR, TMessage, CMChangeColor)
    END_MESSAGE_MAP(TControl)
    };
    void __fastcall TMyControl::CMChangeColor(TMessage &Message)
    {
      Color = Message.LParam;                   // set color from long parameter
      TControl::CMChangeColor(Message);         // call the inherited message handler
    }

Copyright(C) 2009 Embarcadero Technologies, Inc. All Rights Reserved.
What do you think about this topic? Send feedback!