CWindowImpl

template< class T >
class CWindowImpl : public CWindowImplBase

Parameters

T Your class, derived from CWindowImpl.

CWindowImpl allows you to create a new window or subclass an existing window. CWindowImpl's window procedure uses a message map to direct messages to the appropriate handlers.

CWindowImpl::Create creates a new window based on the window class information managed by CWndClassInfo. CWindowImpl contains the DECLARE_WND_CLASS macro, which means CWndClassInfo will register a new window class. If you want to superclass an existing window class, derive your class from CWindowImpl and include the DECLARE_WND_SUPERCLASS macro. In this case, CWndClassInfo will register a window class that is based on an existing class but uses CWindowImpl::WindowProc. For example:

class CMyWindow : CComControl<CMyWindow>, ... 
                  // CComControl derives from CWindowImpl
{ 
public: 
   // 1. The NULL parameter means ATL will generate a 
   // name for the superclass 
   // 2. The "EDIT" parameter means the superclass is 
   // based on the standard Windows Edit box 
   DECLARE_WND_SUPERCLASS(NULL, "EDIT") 
   ... 
}; 

Note Because CWndClassInfo manages the information for a single window class, each window created through an instance of CWindowImpl will be based on the same window class.

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

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

In addition to CWindowImpl, ATL provides CContainedWindow to create a window contained within another object.

CWindowImpl derives from CWindowImplBase, which in turn derives from CWindow and CMessageMap.

For more information aboutSee
Creating controlsATL Tutorial
Using windows in ATLATL Window Classes
ATL Object WizardCreating an ATL Project
Windows"Windows" and subsequent topics in the Win32 SDK
Subclassing"Window Procedure Subclassing" in the Win32 SDK
Superclassing"Window Procedure Superclassing" in the Win32 SDK

#include <atlwin.h>

See Also BEGIN_MSG_MAP, CComControl


CWindowImpl Class Members

Methods
CreateCreates a window.
CWindowImplBase Methods
DefWindowProcProvides default message processing.
GetWndClassInfoReturns a static instance of CWndClassInfo, which manages the window class information.
SubclassWindowSubclasses a window.
UnsubclassWindowRestores a previously subclassed window.
WindowProcProcesses messages sent to the window.
Data Members
m_pfnSuperWindowProcPoints to the window class's original window procedure.

CWindowImpl Overview


Methods


CWindowImpl::Create

HWND Create( HWND hWndParent, RECT& rcPos, LPCTSTR szWindowName = NULL, DWORD dwStyle = WS_CHILD | WS_VISIBLE, DWORD dwExStyle = 0, UINT nID = 0 );

Return Value

If successful, the handle to the newly created window. Otherwise, NULL.

Parameters

hWndParent [in] The handle to the parent or owner window.

rcPos [in] A RECT structure specifying the position of the window.

szWindowName [in] Specifies the name of the window. The default value is NULL.

dwStyle [in] The style of the window. The default value is WS_CHILD | WS_VISIBLE. For a list of possible values, see CreateWindow in the Win32 SDK.

dwExStyle [in] The extended window style. The default value is 0, meaning no extended style. For a list of possible values, see CreateWindowEx in the Win32 SDK.

nID [in] For a child window, the window identifier. For a top-level window, an HWND casted to a UINT. The default value is 0.

Remarks

Creates a window based on a new window class. Create first registers the window class if it has not yet been registered. The newly created window is automatically attached to the CWindowImpl object.

To use a window class that is based on an existing window class, derive your class from CWindowImpl and include the DECLARE_WND_SUPERCLASS macro. The existing window class's window procedure is saved in m_pfnSuperWindowProc. For more information, see the CWindowImpl overview.

Note Do not call Create if you have already called SubclassWindow.

CWindowImpl Overview | Class Members

See Also CWindowImpl::GetWndClassInfo, CWndClassInfo::Register, CWindow::m_hWnd


CWindowImpl::DefWindowProc

LRESULT DefWindowProc( UINT uMsg, WPARAM wParam, LPARAM lParam );

Return Value

The result of the message processing.

Parameters

uMsg [in] The message sent to the window.

wParam [in] Additional message-specific information.

lParam [in] Additional message-specific information.

Remarks

Called by WindowProc to process messages not handled by the message map. By default, DefWindowProc calls the CallWindowProc Win32 function to send the message information to the window procedure specified in m_pfnSuperWindowProc.

CWindowImpl Overview | Class Members


CWindowImpl::GetWndClassInfo

static CWndClassInfo& GetWndClassInfo( );

Return Value

A static instance of CWndClassInfo.

Remarks

Called by Create to access the window class information. By default, CWindowImpl obtains this method through the DECLARE_WND_CLASS macro, which specifies a new window class.

To superclass an existing window class, derive your class from CWindowImpl and include the DECLARE_WND_SUPERCLASS macro to override GetWndClassInfo. For more information, see the CWindowImpl overview.

Besides using the DECLARE_WND_CLASS and DECLARE_WND_SUPERCLASS macros, you can override GetWndClassInfo with your own implementation.

CWindowImpl Overview | Class Members


CWindowImpl::SubclassWindow

BOOL SubclassWindow( HWND hWnd );

Return Value

TRUE if the window is successfully subclassed; otherwise, FALSE.

Parameters

hWnd [in] The handle to the window being subclassed.

Remarks

Subclasses the window identified by hWnd and attaches it to the CWindowImpl object. The subclassed window now uses CWindowImpl::WindowProc. The original window procedure is saved in m_pfnSuperWindowProc.

Note Do not call SubclassWindow if you have already called Create.

CWindowImpl Overview | Class Members

See Also CWindowImpl::UnsubclassWindow


CWindowImpl::UnsubclassWindow

HWND UnsubclassWindow( );

Return Value

The handle to the window previously subclassed.

Remarks

Detaches the subclassed window from the CWindowImpl object and restores the original window procedure, saved in m_pfnSuperWindowProc.

CWindowImpl Overview | Class Members

See Also CWindowImpl::SubclassWindow


CWindowImpl::WindowProc

static LRESULT CALLBACK WindowProc( HWND hWnd, UINT uMsg, WPARAM wParam, LPARAM lParam );

Return Value

The result of the message processing.

Parameters

hWnd [in] The handle to the window.

uMsg [in] The message sent to the window.

wParam [in] Additional message-specific information.

lParam [in] Additional message-specific information.

Remarks

This static method implements the window procedure. WindowProc uses the default message map (declared with BEGIN_MSG_MAP) to direct messages to the appropriate handlers. If necessary, WindowProc calls DefWindowProc for additional message processing.

You can override WindowProc to provide a different mechanism for handling messages.

CWindowImpl Overview | Class Members


Data Members


CWindowImpl::m_pfnSuperWindowProc

WNDPROC m_pfnSuperWindowProc;

Remarks

Depending on the window, points to one of the following window procedures:

Type of windowWindow procedure
A window based on a new window class, specified through the DECLARE_WND_CLASS macro.The DefWindowProc Win32 function.
A window based on a window class that modifies an existing class, specified through the DECLARE_WND_SUPERCLASS macro.The existing window class's window procedure.
A subclassed window.The subclassed window's original window procedure.

CWindowImpl::DefWindowProc sends message information to the window procedure saved in m_pfnSuperWindowProc.

CWindowImpl Overview | Class Members

See Also CWindowImpl::Create, CWindowImpl::SubclassWindow