We recommend using Visual Studio 2017
This documentation is archived and is not being maintained.

CContainedWindowT Class

This class implements a window contained within another object.

template <
   class TBase = CWindow,
   class TWinTraits = CControlWinTraits 
class CContainedWindowT :
   public TBase


The base class of your new class. The default base class is CWindow.


A traits class that defines styles for your window. The default is CControlWinTraits.


CContainedWindow is a specialization of CContainedWindowT. If you want to change the base class or traits, use CContainedWindowT directly.

CContainedWindowT implements a window contained within another object. CContainedWindowT's window procedure uses a message map in the containing object to direct messages to the appropriate handlers. When constructing a CContainedWindowT object, you specify which message map should be used.

CContainedWindowT allows you to create a new window by superclassing an existing window class. The Create method first registers a window class that is based on an existing class but uses CContainedWindowT::WindowProc. Create then creates a window based on this new window class. Each instance of CContainedWindowT can superclass a different window class.

CContainedWindowT also supports window subclassing. The SubclassWindow method attaches an existing window to the CContainedWindowT object and changes the window procedure to CContainedWindowT::WindowProc. Each instance of CContainedWindowT can subclass a different window.


For any given CContainedWindowT object, call either Create or SubclassWindow. You should not invoke both methods on the same object.

When you use the Add control based on option in the ATL Project Wizard, the wizard will automatically add a CContainedWindowT data member to the class implementing the control. The following example shows how the contained window is declared:

   // Declare a contained window data member
   CContainedWindow m_ctlEdit;

   // Initialize the contained window:
   // 1. Pass "Edit" to specify that the contained 
   //    window should be based on the standard 
   //    Windows Edit box
   // 2. Pass 'this' pointer to specify that CAtlEdit 
   //    contains the message map to be used for the 
   //    contained window's message processing
   // 3. Pass the identifier of the message map. '1'
   //    identifies the alternate message map declared
   //    with ALT_MSG_MAP(1)
      : m_ctlEdit(_T("Edit"), this, 1)
      m_bWindowOnly = TRUE;

// Declare the default message map, identified by '0'
// Declare an alternate message map, identified by '1'

// Define OnCreate handler
// When the containing window receives a WM_CREATE
// message, create the contained window by calling
// CContainedWindow::Create
LRESULT OnCreate(UINT /*uMsg*/, WPARAM /*wParam*/, LPARAM /*lParam*/, 
   BOOL& /*bHandled*/)
   RECT rc;
   rc.right -= rc.left;
   rc.bottom -= rc.top;
   rc.top = rc.left = 0;
   m_ctlEdit.Create(m_hWnd, rc, _T("hello"), WS_CHILD | WS_VISIBLE | 
   return 0;

For more information about


Creating controls

ATL Tutorial

Using windows in ATL

ATL Window Classes

ATL Project Wizard

Creating an ATL Project


Windows and subsequent topics in the Windows SDK

Header: atlwin.h