Partager via


CContainedWindowT Class

This class implements a window contained within another object.

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

Parameters

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

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

Notes

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

Remarks

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.

Notes

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:

public:
   // 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)
   CAtlEdit()
      : m_ctlEdit(_T("Edit"), this, 1)
   {
      m_bWindowOnly = TRUE;
   }
// Declare the default message map, identified by '0'
BEGIN_MSG_MAP(CAtlEdit)
   MESSAGE_HANDLER(WM_CREATE, OnCreate)
   MESSAGE_HANDLER(WM_SETFOCUS, OnSetFocus)
   CHAIN_MSG_MAP(CComControl<CAtlEdit>)
// Declare an alternate message map, identified by '1'
ALT_MSG_MAP(1)
   MESSAGE_HANDLER(WM_CHAR, OnChar)
END_MSG_MAP()
// 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;
   GetWindowRect(&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 | 
      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

Windows and subsequent topics in the Windows SDK

Requirements

Header: atlwin.h

See Also

Concepts

CContainedWindowT Members

CWindow Class

CWindowImpl Class

CMessageMap Class

BEGIN_MSG_MAP

ALT_MSG_MAP

ATL Class Overview