Share via


MESSAGE_HANDLER

MESSAGE_HANDLER( msg**,** func )

Parameters

msg

[in] The Windows message.

func

[in] The name of the message-handler function.

Remarks

Defines an entry in a message map. MESSAGE_HANDLER maps a Windows message to the specified handler function. For example:

class CMyClass : ...
{
public:
   ...

   BEGIN_MSG_MAP(CMyClass)
      MESSAGE_HANDLER(WM_PAINT, OnPaint)
      ...
   END_MSG_MAP()

   // When a CMyClass object receives a WM_PAINT
   // message, the message is directed to
   // CMyClass::OnPaint for the actual processing.
   LRESULT OnPaint( ... )
   { ... }

};

Any function specified in a MESSAGE_HANDLER macro must defined as follows:

LRESULT MessageHandler(UINT uMsg, WPARAM wParam, LPARAM lParam, BOOL& bHandled);

The message map sets bHandled to TRUE before MessageHandler is called. If MessageHandler does not fully handle the message, it should set bHandled to FALSE to indicate the message needs further processing.

Note   Always begin a message map with BEGIN_MSG_MAP. You can then declare subsequent alternate message maps with ALT_MSG_MAP. The END_MSG_MAP macro marks the end of the message map. Every message map must have exactly one instance of BEGIN_MSG_MAP and END_MSG_MAP.

In addition to MESSAGE_HANDLER, you can use COMMAND_HANDLER and NOTIFY_HANDLER to map and messages, respectively.

For more information about using message maps in ATL, see Message Maps in the article "ATL Window Classes."

ATL Macros and Global Functions

See Also

MESSAGE_RANGE_HANDLER