Share via


Using Contained Windows

ATL implements contained windows with CContainedWindow. A contained window represents a window that delegates its messages to a container object instead of handling them in its own class.

Note   You do not need to derive a class from CContainedWindow in order to use contained windows.

With contained windows, you can either superclass an existing Windows class or subclass an existing window. To create a window that superclasses an existing Windows class, first specify the existing class name in the constructor for the CContainedWindow object. Then call CContainedWindow::Create. To subclass an existing window, you don't need to specify a Windows class name (pass NULL to the constructor). Simply call the CContainedWindow::SubclassWindow method with the handle to the window being subclassed.

You typically use contained windows as data members of a container class. The container does not need to be a window; however, it must derive from CMessageMap.

A contained window can use alternate message maps to handle its messages. If you have more than one contained window, you should declare several alternate message maps, each corresponding to a separate contained window.

Following is an example of a container class with two contained windows:

class CMyContainer : public CMessageMap, ...
{
public:
   CContainedWindow m_wndEdit;
   CContainedWindow m_wndList;

   CMyContainer() : m_wndEdit("Edit", this, 1),
                    m_wndList("List", this, 2)
   {
   }

   ...

   BEGIN_MSG_MAP(CMyContainer)
   ALT_MSG_MAP(1)
      // handlers for the Edit window go here
   ALT_MSG_MAP(2)
      // handlers for the List window go here
   END_MSG_MAP()

};

For more information about contained windows, see the sample. For more information about superclassing and subclassing, see and in the Win32 SDK.