CContainedWindowT Class
Collapse the table of content
Expand the table of content
Important This document may not represent best practices for current development, links to downloads and other resources may no longer be valid. Current recommended version can be found here. ArchiveDisclaimer

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 is taken from the SUBEDIT sample and shows how the contained window is declared:

class CAtlEdit : ...
   // Declare a contained window data member
   CContainedWindow m_EditCtrl;

   // 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)
   CAtlEdit() : m_EditCtrl(_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)
      m_EditCtrl.Create(m_hWnd, rc, _T("hello"), 
                        WS_CHILD | WS_VISIBLE | 
                        ES_MULTILINE | ES_AUTOVSCROLL);
      return 0;

For more information about See

Creating controls

ATL Tutorial

Using windows in ATL

ATL Window Classes

ATL Project Wizard

Creating an ATL Project


Windows and subsequent topics in the Platform SDK

Header: atlwin.h

© 2016 Microsoft