Programming with Microsoft Visual C++.NET 6ed [Electronic resources]

George Shepherd, David Kruglinski

نسخه متنی -صفحه : 319/ 187
نمايش فراداده

The Ex21c Example: An MDI Application

Now let's create an MDI application that doesn't use the document-view architecture.

    Run the MFC Application Wizard to produce the Ex21c project. Select the Multiple Documents option on the Application Type page and deselect Document/View Architecture Support.

    Add code to paint in the dialog box.Add the following boldface code to the CChildView::OnPaint function in the

    ChildView.cpp source code file:

    void CChildView::OnPaint() 
    {
    CPaintDC dc(this); // device context for painting
    dc.TextOut(0, 0, "Hello, world!");
    // Do not call CWnd::OnPaint() for painting messages
    }

    Compile and run the application. You now have a complete MDI application without any dependencies on the document-view architecture.

    As in Ex21b, this example automatically creates a CChildView class. The main difference between Ex21b and Ex21c is that in Ex21c the CChildView class is created in the CChildFrame::OnCreate function instead of in the CMainFrame class.

Now that you've learned how to create three kinds of applications that do not depend on the document-view architecture, you can examine how they're generated to learn how MFC works. Try comparing the generated results to similar applications with document-view architecture support to get a complete picture of how the document-view classes work with the rest of MFC.