Click to open or copy the MDI project files.
The MDI sample uses the framework's multiple-document interface (MDI) support without using the document/view architecture.
For an additional MDI sample, see MDIDOCVW.
MDI also illustrates the Microsoft Windows timer, CColorDialog, CBitmap, and changing the default cursor of a window.
The MDI sample application provides a parent window with two distinct types of MDI child windows: a Bounce window, in which a ball bounces around; and a Hello window, which simply displays the text "Hello, World!" You can create multiple instances of each type of window.
Click New Bounce or New Hello on the File menu to create a new MDI child window. Both MDI child windows determine what menus are shown when they are active. Both windows have a Color menu. When you choose a color from this menu, the color of the bouncing ball or of the Hello text is updated. Choose the Custom item to call a color dialog box, from which you can select a special color.
The Bounce window also has a Speed menu, from which you can select the speed at which the ball moves around the screen.
If you minimize the Bounce window, notice that there isn't a static icon. Rather, a small ball bounces around in the icon. In contrast, the Hello window has a normal icon.
Unlike an MDI application produced by AppWizard, this sample application does not use the framework's support for documents and views. Thus, it does not use document templates; the application's InitInstance does not call AddDocTemplate.
This application nevertheless takes full advantage of the framework's MDI support. CMainFrame is derived from CMDIFrameWnd. CBounceWnd and CHelloWnd are derived from CMDIChildWnd. Commands on the Window menu, such as Tile, are handled by the framework's default implementation in CMDIFrameWnd.
Although CBounceWnd and CHelloWnd both override Create, the override is not necessary to take advantage of the framework's MDI support. The override of Create illustrates how to change the default cursor and icon of a window. Changing the default cursor or icon of a window requires registering a new WNDCLASS by calling AFXRegisterWndClass and passing the name of the WNDCLASS in the call to Create.
This sample demonstrates the following keywords:
AfxGetInstanceHandle; AfxRegisterWndClass; CBitmap::CreateCompatibleBitmap; CCmdUI::SetCheck; CColorDialog::DoModal; CColorDialog::GetColor; CDC::BitBlt; CDC::CreateCompatibleDC; CDC::DeleteDC; CDC::DrawText; CDC::Ellipse; CDC::FillRect; CDC::GetDeviceCaps; CDC::SelectObject; CDC::SetBkColor; CDC::SetTextColor; CFrameWnd::LoadFrame; CFrameWnd::rectDefault; CGdiObject::DeleteObject; CMDIChildWnd::Create; CMenu::LoadMenu; CWinApp::Enable3dControls; CWinApp::InitInstance; CWnd::DestroyWindow; CWnd::GetClientRect; CWnd::GetCurrentMessage; CWnd::GetDC; CWnd::Invalidate; CWnd::KillTimer; CWnd::MessageBox; CWnd::OnCreate; CWnd::OnPaint; CWnd::OnSize; CWnd::OnTimer; CWnd::ReleaseDC; CWnd::SetTimer; CWnd::ShowWindow; CWnd::UpdateWindow; GetSysColor; LOWORD; LoadCursor; LoadIcon; MAKEINTRESOURCE; RGB; max; min