MDIDOCVW Sample: Demonstrates MDI Using Doc/View Architecture
The MDIDOCVW sample uses MFC multiple-document interface (MDI) support and the document/view architecture. The sample contains two document types, Hello, which prints out a string in a view (in this example, "Hello World!"), and Bounce, which displays a bouncing ball of color in a view. MDIDOCVW also illustrates the Windows timer, CColorDialog, CBitmap, and how to change the default cursor of a window.
The MDIDOCVW sample provides a parent window that has two distinct kinds of MDI child windows: a Hello window and a Bounce window.
For a sample that uses MDI support without the document/view architecture, see MDI Sample: Demonstrates MDI Without Using Doc/View Architecture.
This sample code is intended to illustrate a concept, and it shows only the code that is relevant to that concept. It may not meet the security requirements for a specific environment, and it should not be used exactly as shown. We recommend that you add security and error-handling code to make your projects more secure and robust. Microsoft provides this sample code "AS IS" with no warranties.
To get samples and instructions for installing them:
To access samples from Visual Studio
On the Help menu, click Samples.
By default, these samples are installed in drive:\Program Files\Microsoft Visual Studio 10.0\Samples\.
For the most recent version of this sample and a list of other samples, see Visual Studio Samples on the MSDN Web site.
To build and run the MDIDOCVW sample
On the Build menu, click Build.
On the Debug menu, click Start Without Debugging.
On the File menu, click New Bounce or New Hello to create an MDI child window. Both kinds of MDI child windows determine what menus are shown when they are active. Both kinds of windows have a Color menu. When you select a color on this menu, the color of the bouncing ball or of the Hello text is updated. Click Custom to call a Color dialog box, from which you can select a custom color.
The Bounce window also has a Speed menu, from which you can select how fast the ball moves around the screen.
A toolbar implements most of the menu commands. The toolbar also implements check box buttons for the five basic colors.
Although CBounceView and CHelloView both override Create, the override is not required to take advantage of the MDI support of the framework. The override of Create, found in the CBounceViewclass, illustrates how to change the default cursor. Changing the default cursor 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:
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; CWinApp::InitInstance; CWnd::DestroyWindow; CWnd::GetClientRect; CWnd::GetCurrentMessage; CWnd::GetDC; CWnd::KillTimer; CWnd::MessageBox; CWnd::OnCreate; CWnd::OnSize; CWnd::OnTimer; CWnd::ReleaseDC; CWnd::SetTimer; CWnd::ShowWindow; CWnd::UpdateWindow; GetSysColor; LOWORD; RGB; max; min
This sample may not exactly demonstrate some features of the Visual C++ wizards, libraries, and compiler, but it still shows how to complete the intended task.