BEGIN_MSG_MAP

BEGIN_MSG_MAP( theClass )

Parameters

theClass

[in] The name of the class containing the message map.

Remarks

Marks the beginning of the default message map. CWindowImpl::WindowProc uses the default message map to process messages sent to the window. The message map directs messages either to the appropriate handler function or to another message map.

The following macros map a message to a handler function. This function must be defined in theClass.

Macro Description
MESSAGE_HANDLER Maps a Windows message to a handler function.
MESSAGE_RANGE_HANDLER Maps a contiguous range of Windows messages to a handler function.
COMMAND_HANDLER Maps a WM_COMMAND message to a handler function, based on the notification code and the identifier of the menu item, control, or accelerator.
COMMAND_ID_HANDLER Maps a WM_COMMAND message to a handler function, based on the identifier of the menu item, control, or accelerator.
COMMAND_CODE_HANDLER Maps a WM_COMMAND message to a handler function, based on the notification code.
COMMAND_RANGE_HANDLER Maps a contiguous range of WM_COMMAND messages to a handler function, based on the identifier of the menu item, control, or accelerator.
NOTIFY_HANDLER Maps a WM_NOTIFY message to a handler function, based on the notification code and the control identifier.
NOTIFY_ID_HANDLER Maps a WM_NOTIFY message to a handler function, based on the control identifier.
NOTIFY_CODE_HANDLER Maps a WM_NOTIFY message to a handler function, based on the notification code.
NOTIFY_RANGE_HANDLER Maps a contiguous range of WM_NOTIFY messages to a handler function, based on the control identifier.

The following macros direct a message to another message map. This process is called "chaining."

Macro Description
CHAIN_MSG_MAP Chains to the default message map in the base class.
CHAIN_MSG_MAP_MEMBER Chains to the default message map in a data member of the class.
CHAIN_MSG_MAP_ALT Chains to an alternate message map in the base class.
CHAIN_MSG_MAP_ALT_MEMBER Chains to an alternate message map in a data member of the class.
CHAIN_MSG_MAP_DYNAMIC Chains to the default message map in another class at run time.

Example

class CMyWindow : ...
{
public:
   ...

   BEGIN_MSG_MAP(CMyWindow)
      MESSAGE_HANDLER(WM_PAINT, OnPaint)
      MESSAGE_HANDLER(WM_SETFOCUS, OnSetFocus)
      CHAIN_MSG_MAP(CMyBaseWindow)
   END_MSG_MAP()

   LRESULT OnPaint(UINT uMsg, WPARAM wParam,
                   LPARAM lParam, BOOL& bHandled)
   { ... }

   LRESULT OnSetFocus(UINT uMsg, WPARAM wParam,
                      LPARAM lParam, BOOL& bHandled)
   { ... }
};

When a CMyWindow object receives a WM_PAINT message, the message is directed to CMyWindow::OnPaint for the actual processing. If OnPaint indicates the message requires further processing, the message will then be directed to the default message map in CMyBaseWindow.

In addition to the default message map, you can define an alternate message map with ALT_MSG_MAP. Always begin a message map with BEGIN_MSG_MAP. You can then declare subsequent alternate message maps. The following example shows the default message map and one alternate message map, each containing one handler function:

BEGIN_MSG_MAP(CMyClass)
   MESSAGE_HANDLER(WM_PAINT, OnPaint)
ALT_MSG_MAP(1)
   MESSAGE_HANDLER(WM_SETFOCUS, OnSetFocus)
END_MSG_MAP()

The next example shows two alternate message maps. The default message map is empty.

BEGIN_MSG_MAP(CMyClass)
ALT_MSG_MAP(1)
   MESSAGE_HANDLER(WM_PAINT, OnPaint)
   MESSAGE_HANDLER(WM_SETFOCUS, OnSetFocus)
ALT_MSG_MAP(2)
   MESSAGE_HANDLER(WM_CREATE, OnCreate)
END_MSG_MAP()

The END_MSG_MAP macro marks the end of the message map. Note that there is always exactly one instance of BEGIN_MSG_MAP and END_MSG_MAP.

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

CMessageMap, CDynamicChain