CDynamicChain Class
Collapse the table of content
Expand the table of content

CDynamicChain Class

This class provides methods supporting the dynamic chaining of message maps.

Important note Important

This class and its members cannot be used in applications that execute in the Windows Runtime.

class CDynamicChain




Directs a Windows message to another object's message map.


Removes a message map entry from the collection.


Adds a message map entry to the collection or modifies an existing entry.

CDynamicChain manages a collection of message maps, enabling a Windows message to be directed, at run time, to another object's message map.

To add support for dynamic chaining of message maps, do the following:

  • Derive your class from CDynamicChain. In the message map, specify the CHAIN_MSG_MAP_DYNAMIC macro to chain to another object's default message map.

  • Derive every class you want to chain to from CMessageMap. CMessageMap allows an object to expose its message maps to other objects.

  • Call CDynamicChain::SetChainEntry to identify which object and which message map you want to chain to.

For example, suppose your class is defined as follows:

class CMyChainWnd : public CWindowImpl<CMyChainWnd>,
   public CDynamicChain
   CMyChainWnd() {}

      // dynamically chain to the default
      // message map in another object
                // '1313' identifies the object
                // and the message map that will be
                // chained to. '1313' is defined
                // through the SetChainEntry method

   LRESULT OnPaint(UINT /*nMsg*/, WPARAM /*wParam*/, LPARAM /*lParam*/, 
      BOOL& /*bHandled*/)
      // Do some painting code
      return 0;

   LRESULT OnSetFocus(UINT /*uMsg*/, WPARAM /*wParam*/, LPARAM /*lParam*/, 
      BOOL& /*bHandled*/)
      return 0;

The client then calls CMyWindow::SetChainEntry:

myCtl.SetChainEntry(1313, &chainedObj);

where chainedObj is the chained object and is an instance of a class derived from CMessageMap. Now, if myCtl receives a message that is not handled by OnPaint or OnSetFocus, the window procedure directs the message to chainedObj's default message map.

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

Header: atlwin.h

© 2015 Microsoft