Udostępnij za pośrednictwem


MDIDOCVW Sample: Demonstrates MDI Using Doc/View Architecture

The MDIDOCVW sample uses MFC's 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) and Bounce (which displays a bouncing ball of color in a view). MDIDOCVW also illustrates the Microsoft Windows timer, CColorDialog, CBitmap, and changing the default cursor of a window.

The MDIDOCVW sample 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!"

For a sample that uses MDI support without the document/view architecture, see MDI.

Security noteSecurity Note:

This sample code is provided to illustrate a concept and should not be used in applications or Web sites, as it may not illustrate the safest coding practices. Microsoft assumes no liability for incidental or consequential damages should the sample code be used for purposes other than as intended.

To get samples and instructions for installing them:

  • On the Visual Studio Help menu, click Samples.

    For more information, see Visual Studio Samples.

  • The most recent version and complete list of samples is available online from the Visual Studio 2008 Samples page.

  • You can also locate samples on your computer's hard disk. By default, samples and a Readme file are copied into a folder under \Program Files\Visual Studio 9.0\Samples\. For Express editions of Visual Studio, all samples are located online.

Building and Running the Sample

To build and run the MDIDOCVW sample

  1. Open the solution mdi.sln.

  2. On the Build menu, click Build.

  3. On the Debug menu, click Start Without Debugging.

Click New Bounce or New Hello on the File menu to create a new MDI child window. Both types of MDI child windows determine what menus are shown when they are active. Both types of 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. 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 the speed 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.

Changing the Default Cursor

Although CBounceView and CHelloView both override Create, the override is not necessary to take advantage of the framework's MDI support. 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.

Keywords

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

Note

Some samples, such as this one, have not been modified to reflect the changes in the Visual C++ wizards, libraries, and compiler, but still demonstrate how to complete your desired task.

See Also

Other Resources

MFC Samples