Udostępnij za pośrednictwem


CDynamicChain Class

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

class CDynamicChain

Remarks

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
{
public:
   CMyChainWnd() {}

   BEGIN_MSG_MAP(CMyChainWnd)
      MESSAGE_HANDLER(WM_PAINT, OnPaint)
      MESSAGE_HANDLER(WM_SETFOCUS, OnSetFocus)
      // dynamically chain to the default 
      // message map in another object
      CHAIN_MSG_MAP_DYNAMIC(1313)
                // '1313' identifies the object 
                // and the message map that will be 
                // chained to. '1313' is defined 
                // through the SetChainEntry method
   END_MSG_MAP()

   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."

Requirements

Header: atlwin.h

See Also

Reference

CWindowImpl Class

Other Resources

CDynamicChain Members

ATL Class Overview