CMDIChild Class |
Description
This class provides a child window for MDI (Multi Document Interface) applications. MDI applications are capable of hosting several child windows within a frame.
The CMDIChild class inherits much of its default implementation from CWnd, and adds the additional functionality required for MDI applications.
CMDIChild Members
CMDIChild | CMDIChild();Constructor for CMDIChild. |
CMDIFrame* GetMDIFrame() const;Returns a pointer to the MDI Frame.
virtual CWnd* GetView() const {return m_pView;}Returns a pointer to the MDI Child's view window.
MDIActivate
void MDIActivate() const;Activates this MDI child.
void MDIDestroy() const;Destroys this MDI child.
void MDIMaximize() const;Maximizes this MDI Child.
void MDIRestore() const;Restores this MDI child from a maximized or minimized state.
virtual void RecalcLayout();Repositions the view window when the MDI child is restored.
virtual void SetChildMenu(LPCTSTR MenuName);Sets the MDI child menu, given its Resource ID.
void SetHandles(HMENU MenuName, HACCEL AccelName);Sets the MDI child's menu and accelerator table.
virtual void SetView(CWnd& pwndView);Sets the view window for the MDI child.
Overridables
Create | virtual HWND Create(HWND hWndParent = NULL);Creates the MDI child window. |
OnClose | virtual void OnClose();Called when the MDI child window is about to be closed. Override this to prevent the MDI child window from being closed. |
OnCreate | virtual void OnCreate();Called when the MDI child window is created. |
OnMDIActivate | virtual LRESULT OnMDIActivate(WPARAM wParam, LPARAM lParam);Called when the MDI child window is activated. |
OnWindowPosChanged | virtual LRESULT OnWindowPosChanged(WPARAM wParam, LPARAM lParam);Called when the MDI child window is moved. |
Base class Members
For base class members, refer to the members of CWnd.
Remarks
Setting the MDI Child's View window and Menu
Each type of MDI child will have a view window and will usually have a unique menu. The menu which is displayed in the MDI frame will belong the the MDI child that has keyboard focus, or the MDI frame's menu if no MDI child is active. The SetView function sets the view window, and the SetChildMenu seta the menu of a MDI child, as follows.
CSimpleMDIChild::CSimpleMDIChild() { // Set m_View as the view window of the MDI child SetView(m_View); // Set the menu for this MDI child SetChildMenu(_T("MdiMenuView")); }
The MDI child's menu would be defined in the resource script file (usually Resource.rc) as follows.
MDIMENU MENU BEGIN POPUP "&File" BEGIN MENUITEM "New &View\tCtrl+N", IDM_FILE_NEW MENUITEM "&Close", IDM_FILE_CLOSE MENUITEM SEPARATOR MENUITEM "E&xit", IDM_FILE_EXIT END POPUP "&View" BEGIN MENUITEM "&Tool Bar", IDW_VIEW_TOOLBAR, CHECKED MENUITEM "&Status Bar", IDW_VIEW_STATUSBAR, CHECKED END POPUP "&Window" BEGIN MENUITEM "&Cascade\tShift+F5", IDW_WINDOW_CASCADE MENUITEM "&Tile\tShift+F4", IDW_WINDOW_TILE MENUITEM "Arrange &Icons", IDW_WINDOW_ARRANGE MENUITEM "Close &All", IDW_WINDOW_CLOSEALL END POPUP "&Help" BEGIN MENUITEM "&About", IDM_HELP_ABOUT END END
Setting the MDI Child's Title and Icon
Each type of MDI child usually has an icon. The MDI child's icon and title are is set as follows.
void CMDIChildView::OnInitialUpdate() { ::SetWindowText(m_hWnd, _T("MDI Child Window")); SetIconLarge(IDI_VIEW); SetIconSmall(IDI_VIEW); }
Refer to the MDI Frames section for information on how to use CMDIChild with CMDIFrame.
Summary Information
Header file | mdi.h |
Win32/64 support | Yes |
WinCE support | No |