description | title | ms.date | f1_keywords | helpviewer_keywords | ms.assetid | ||||||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
Learn more about: CWindowImpl Class |
CWindowImpl Class |
11/04/2016 |
|
|
02eefd45-a0a6-4d1b-99f6-dbf627e2cc2f |
Provides methods for creating or subclassing a window.
Important
This class and its members cannot be used in applications that execute in the Windows Runtime.
template <class T, class TBase = CWindow, class TWinTraits = CControlWinTraits>
class ATL_NO_VTABLE CWindowImpl : public CWindowImplBaseT<TBase, TWinTraits>
T
Your new class, derived from CWindowImpl
.
TBase
The base class of your class. By default, the base class is CWindow.
TWinTraits
A traits class that defines styles for your window. The default is CControlWinTraits
.
Name | Description |
---|---|
CWindowImpl::Create | Creates a window. |
Name | Description |
---|---|
DefWindowProc | Provides default message processing. |
GetCurrentMessage | Returns the current message. |
GetWindowProc | Returns the current window procedure. |
OnFinalMessage | Called after the last message is received (typically WM_NCDESTROY). |
SubclassWindow | Subclasses a window. |
UnsubclassWindow | Restores a previously subclassed window. |
Name | Description |
---|---|
GetWndClassInfo | Returns a static instance of CWndClassInfo, which manages the window class information. |
WindowProc | Processes messages sent to the window. |
Name | Description |
---|---|
m_pfnSuperWindowProc | Points to the window class's original window procedure. |
You can use CWindowImpl
to create a window or subclass an existing window. the CWindowImpl
window procedure uses a message map to direct messages to the appropriate handlers.
CWindowImpl::Create
creates a window based on the window class information that's managed by CWndClassInfo. CWindowImpl
contains the DECLARE_WND_CLASS macro, which means CWndClassInfo
registers 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
registers a window class that's based on an existing class but uses CWindowImpl::WindowProc
. For example:
[!code-cppNVC_ATL_Windowing#43]
Note
Because CWndClassInfo
manages the information for just one window class, each window created through an instance of CWindowImpl
is 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
. Don't invoke both methods on the same object.
In addition to CWindowImpl
, ATL provides CContainedWindow to create a window that's contained in another object.
The base class destructor (~ CWindowImplRoot
) ensures that the window is gone before the object is destroyed.
CWindowImpl
derives from CWindowImplBaseT
, which derives from CWindowImplRoot
, which derives from TBase
and CMessageMap.
For more information about | See |
---|---|
Creating controls | ATL Tutorial |
Using windows in ATL | ATL Window Classes |
ATL Project Wizard | Creating an ATL Project |
TBase
CWindowImplRoot
CWindowImplBaseT
CWindowImpl
Header: atlwin.h
Creates a window based on a new window class.
HWND Create(
HWND hWndParent,
_U_RECT rect = NULL,
LPCTSTR szWindowName = NULL,
DWORD dwStyle = 0,
DWORD dwExStyle = 0,
_U_MENUorID MenuOrID = 0U,
LPVOID lpCreateParam = NULL);
hWndParent
[in] The handle to the parent or owner window.
rect
[in] A RECT structure specifying the position of the window. The RECT
can be passed by pointer or by reference.
szWindowName
[in] Specifies the name of the window. The default value is NULL.
dwStyle
[in] The style of the window. This value is combined with the style provided by the traits class for the window. The default value gives the traits class full control over the style. For a list of possible values, see CreateWindow in the Windows SDK.
dwExStyle
[in] The extended window style. This value is combined with the style provided by the traits class for the window. The default value gives the traits class full control over the style. For a list of possible values, see CreateWindowEx in the Windows SDK.
MenuOrID
[in] For a child window, the window identifier. For a top-level window, a menu handle for the window. The default value is 0U.
lpCreateParam
[in] A pointer to window-creation data. For a full description, see the description for the final parameter to CreateWindowEx.
If successful, the handle to the newly created window. Otherwise, NULL.
Create
first registers the window class if it has not yet been registered. The newly created window is automatically attached to the CWindowImpl
object.
Note
Do not call Create
if you have already called SubclassWindow.
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
If 0 is used as the value for the MenuOrID parameter, it must be specified as 0U (the default value) to avoid a compiler error.
Called by WindowProc to process messages not handled by the message map.
LRESULT DefWindowProc(
UINT uMsg,
WPARAM wParam,
LPARAM lParam);
LRESULT DefWindowProc();
uMsg
[in] The message sent to the window.
wParam
[in] Additional message-specific information.
lParam
[in] Additional message-specific information.
The result of the message processing.
By default, DefWindowProc
calls the CallWindowProc Win32 function to send the message information to the window procedure specified in m_pfnSuperWindowProc.
The function with no parameters automatically retrieves the needed parameters from the current message.
Returns the current message, packaged in the MSG
structure.
const MSG* GetCurrentMessage();
The current message.
Returns WindowProc
, the current window procedure.
virtual WNDPROC GetWindowProc();
The current window procedure.
Override this method to replace the window procedure with your own.
Called by Create to access the window class information.
static CWndClassInfo& GetWndClassInfo();
A static instance of CWndClassInfo.
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.
Depending on the window, points to one of the following window procedures.
WNDPROC m_pfnSuperWindowProc;
Type of window | Window 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
.
Called after receiving the last message (typically WM_NCDESTROY).
virtual void OnFinalMessage(HWND hWnd);
hWnd
[in] A handle to the window being destroyed.
The default implementation of OnFinalMessage
does nothing, but you can override this function to handle cleanup before destroying a window. If you want to automatically delete your object upon the window destruction, you can call delete this;
in this function.
Subclasses the window identified by hWnd and attaches it to the CWindowImpl
object.
BOOL SubclassWindow(HWND hWnd);
hWnd
[in] The handle to the window being subclassed.
TRUE if the window is successfully subclassed; otherwise, FALSE.
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.
Detaches the subclassed window from the CWindowImpl
object and restores the original window procedure, saved in m_pfnSuperWindowProc.
HWND UnsubclassWindow();
The handle to the window previously subclassed.
This static function implements the window procedure.
static LRESULT CALLBACK WindowProc(
HWND hWnd,
UINT uMsg,
WPARAM wParam,
LPARAM lParam);
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.
The result of the message processing.
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. If the final message is not handled, WindowProc
does the following:
-
Performs unsubclassing if the window was unsubclassed.
-
Clears
m_hWnd
. -
Calls OnFinalMessage before the window is destroyed.
You can override WindowProc
to provide a different mechanism for handling messages.