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.
Note CContainedWindow is a specialization of CContainedWindowT. If you want to change the base class or traits, use CContainedWindowT directly.
CContainedWindow implements a window contained within another object. CContainedWindow’s window procedure uses a message map in the containing object to direct messages to the appropriate handlers. When constructing a CContainedWindow object, you specify which message map should be used.
CContainedWindow 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 CContainedWindow::WindowProc. Create then creates a window based on this new window class. Each instance of CContainedWindow can superclass a different window class.
CContainedWindow also supports window subclassing. The SubclassWindow method attaches an existing window to the CContainedWindow object and changes the window procedure to CContainedWindow::WindowProc. Each instance of CContainedWindow can subclass a different window.
Note For any given CContainedWindow 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 Object Wizard, the wizard will automatically add a CContainedWindow 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 : ...
{
public:
// 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'
BEGIN_MSG_MAP(CAtlEdit)
...
MESSAGE_HANDLER(WM_CREATE, OnCreate)
...
// 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)
{
...
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 Object Wizard | Creating an ATL Project |
Windows | Windows and subsequent topics in the Platform SDK |
Subclassing | Window Procedure Subclassing in the Platform SDK |
Superclassing | Window Procedure Superclassing in the Platform SDK |
#include <atlwin.h>
See Also
CWindow, CWindowImpl, CMessageMap, BEGIN_MSG_MAP, ALT_MSG_MAP