description | title | ms.date | f1_keywords | helpviewer_keywords | ms.assetid | ||||||||||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
Learn more about: CMDIChildWnd Class |
CMDIChildWnd Class |
11/04/2016 |
|
|
6d07f5d4-9a3e-4723-9fa5-e65bb669fdd5 |
Provides the functionality of a Windows multiple document interface (MDI) child window, along with members for managing the window.
class CMDIChildWnd : public CFrameWnd
Name | Description |
---|---|
CMDIChildWnd::CMDIChildWnd | Constructs a CMDIChildWnd object. |
Name | Description |
---|---|
CMDIChildWnd::Create | Creates the Windows MDI child window associated with the CMDIChildWnd object. |
CMDIChildWnd::GetMDIFrame | Returns the parent MDI frame of the MDI client window. |
CMDIChildWnd::MDIActivate | Activates this MDI child window. |
CMDIChildWnd::MDIDestroy | Destroys this MDI child window. |
CMDIChildWnd::MDIMaximize | Maximizes this MDI child window. |
CMDIChildWnd::MDIRestore | Restores this MDI child window from maximized or minimized size. |
CMDIChildWnd::SetHandles | Sets the handles for menu and accelerator resources. |
An MDI child window looks much like a typical frame window, except that the MDI child window appears inside an MDI frame window rather than on the desktop. An MDI child window does not have a menu bar of its own, but instead shares the menu of the MDI frame window. The framework automatically changes the MDI frame menu to represent the currently active MDI child window.
To create a useful MDI child window for your application, derive a class from CMDIChildWnd
. Add member variables to the derived class to store data specific to your application. Implement message-handler member functions and a message map in the derived class to specify what happens when messages are directed to the window.
There are three ways to construct an MDI child window:
-
Directly construct it using
Create
. -
Directly construct it using
LoadFrame
. -
Indirectly construct it through a document template.
Before you call Create
or LoadFrame
, you must construct the frame-window object on the heap using the C++ new
operator. Before calling Create
you can also register a window class with the AfxRegisterWndClass global function to set the icon and class styles for the frame.
Use the Create
member function to pass the frame's creation parameters as immediate arguments.
LoadFrame
requires fewer arguments than Create
, and instead retrieves most of its default values from resources, including the frame's caption, icon, accelerator table, and menu. To be accessible by LoadFrame
, all these resources must have the same resource ID (for example, IDR_MAINFRAME).
When a CMDIChildWnd
object contains views and documents, they are created indirectly by the framework instead of directly by the programmer. The CDocTemplate
object orchestrates the creation of the frame, the creation of the containing views, and the connection of the views to the appropriate document. The parameters of the CDocTemplate
constructor specify the CRuntimeClass
of the three classes involved (document, frame, and view). A CRuntimeClass
object is used by the framework to dynamically create new frames when specified by the user (for example, by using the File New command or the MDI Window New command).
A frame-window class derived from CMDIChildWnd
must be declared with DECLARE_DYNCREATE in order for the above RUNTIME_CLASS mechanism to work correctly.
The CMDIChildWnd
class inherits much of its default implementation from CFrameWnd
. For a detailed list of these features, please refer to the CFrameWnd class description. The CMDIChildWnd
class has the following additional features:
-
In conjunction with the
CMultiDocTemplate
class, multipleCMDIChildWnd
objects from the same document template share the same menu, saving Windows system resources. -
The currently active MDI child window menu entirely replaces the MDI frame window's menu, and the caption of the currently active MDI child window is added to the MDI frame window's caption. For further examples of MDI child window functions that are implemented in conjunction with an MDI frame window, see the
CMDIFrameWnd
class description.
Do not use the C++ delete
operator to destroy a frame window. Use CWnd::DestroyWindow
instead. The CFrameWnd
implementation of PostNcDestroy
will delete the C++ object when the window is destroyed. When the user closes the frame window, the default OnClose
handler will call DestroyWindow
.
For more information on CMDIChildWnd
, see Frame Windows.
CMDIChildWnd
Header: afxwin.h
Call to construct a CMDIChildWnd
object.
CMDIChildWnd();
Call Create
to create the visible window.
See the example for CMDIChildWnd::Create.
Call this member function to create a Windows MDI child window and attach it to the CMDIChildWnd
object.
virtual BOOL Create(
LPCTSTR lpszClassName,
LPCTSTR lpszWindowName,
DWORD dwStyle = WS_CHILD | WS_VISIBLE | WS_OVERLAPPEDWINDOW,
const RECT& rect = rectDefault,
CMDIFrameWnd* pParentWnd = NULL,
CCreateContext* pContext = NULL);
lpszClassName
Points to a null-terminated character string that names the Windows class (a WNDCLASS structure). The class name can be any name registered with the AfxRegisterWndClass global function. Should be NULL for a standard CMDIChildWnd
.
lpszWindowName
Points to a null-terminated character string that represents the window name. Used as text for the title bar.
dwStyle
Specifies the window style attributes. The WS_CHILD style is required.
rect
Contains the size and position of the window. The rectDefault
value allows Windows to specify the size and position of the new CMDIChildWnd
.
pParentWnd
Specifies the window's parent. If NULL, the main application window is used.
pContext
Specifies a CCreateContext structure. This parameter can be NULL.
Nonzero if successful; otherwise 0.
The currently active MDI child frame window can determine the caption of the parent frame window. This feature is disabled by turning off the FWS_ADDTOTITLE style bit of the child frame window.
The framework calls this member function in response to a user command to create a child window, and the framework uses the pContext parameter to properly connect the child window to the application. When you call Create
, pContext can be NULL.
This example menu command handler invokes Create
to create an MDI child window:
[!code-cppNVC_MFCWindowing#7]
The example code calls the Create
method of CHelloWnd
, a class derived from CMDIChildWnd
:
[!code-cppNVC_MFCWindowing#8]
This example shows the Create
implementation of the CHelloWnd
class:
[!code-cppNVC_MFCWindowing#9]
Call this function to return the MDI parent frame.
CMDIFrameWnd* GetMDIFrame();
A pointer to the MDI parent frame window.
The frame returned is two parents removed from the CMDIChildWnd
and is the parent of the window of type MDICLIENT that manages the CMDIChildWnd
object. Call the GetParent member function to return the CMDIChildWnd
object's immediate MDICLIENT parent as a temporary CWnd
pointer.
See the example for CMDIFrameWnd::MDISetMenu.
Call this member function to activate an MDI child window independently of the MDI frame window.
void MDIActivate();
When the frame becomes active, the child window that was last activated will be activated as well.
See the example for CMDIFrameWnd::GetWindowMenuPopup.
Call this member function to destroy an MDI child window.
void MDIDestroy();
The member function removes the title of the child window from the frame window and deactivates the child window.
[!code-cppNVC_MFCWindowing#10]
Call this member function to maximize an MDI child window.
void MDIMaximize();
When a child window is maximized, Windows resizes it to make its client area fill the client area of the frame window. Windows places the child window's Control menu in the frame's menu bar so that the user can restore or close the child window and adds the title of the child window to the frame-window title.
[!code-cppNVC_MFCWindowing#11]
Call this member function to restore an MDI child window from maximized or minimized size.
void MDIRestore();
[!code-cppNVC_MFCWindowing#12]
Sets the handles for menu and accelerator resources.
void SetHandles(
HMENU hMenu,
HACCEL hAccel);
hMenu
The handle of a menu resource.
hAccel
The handle of an accelerator resource.
Call this function to set the menu and accelerator resources used by the MDI child window object.
MFC Sample MDI
MFC Sample MDIDOCVW
MFC Sample SNAPVW
CFrameWnd Class
Hierarchy Chart
CWnd Class
CMDIFrameWnd Class