Multiple views for a single document (MDI) 3 | CodeGuru

Multiple views for a single document (MDI) 3

Environment: ****** This package differ from other package from the point of view that it didn’t tells you what to do. Its doing it. You can use it exactly like other MFC doc template class. One of my biggest problems was to have multiple view using a Single document. To achieve that, I’ve create a […]

Written By
CodeGuru Staff
CodeGuru Staff
Dec 8, 1998
1 minute read
CodeGuru content and product recommendations are editorially independent. We may make money when you click on links to our partners. Learn More

Environment: ******

This package differ from other package from the point of view that it didn’t tells you what to do. Its doing it. You can use it exactly like other MFC doc template class.

One of my biggest problems was to have multiple view using a Single document. To achieve that, I’ve create a class that act like a standard document template class. This class implements a single document interface with multiple view.

I basically start by creating a class that derived from a multiple document interface. I modify it to support only one document. The reason I didn’t derived from a single document interface is because the architecture of MFC require the use of a MDIDocTemplate to use with a MDIChildFrame.

Here is the architecture diagrams.

This is a sample on how to use it in you Application class. For further information, take a look at the sample application zip files.

    CSDIMVDocTemplate *pDocTemplate = new CSDIMVDocTemplate( IDR_MVTESTTYPE, RUNTIME_CLASS( CMvTestDoc ) );
    pDocTemplate->AddFrameTemplate(
        new CFrameTemplate(
            IDR_MV1,
            RUNTIME_CLASS( CChildFrame1 ),
            RUNTIME_CLASS( CView1 ),
            ID_VIEW_VIEW1,
            SW_SHOWNORMAL,
            TRUE ) );

    pDocTemplate->AddFrameTemplate(
        new CFrameTemplate(
            IDR_MV2,
            RUNTIME_CLASS( CChildFrame1 ),
            RUNTIME_CLASS( CView2 ),
            ID_VIEW_VIEW2,
            SW_SHOWNORMAL,
            TRUE ) );

    pDocTemplate->AddFrameTemplate(
        new CFrameTemplate(
            IDR_MV3,
            RUNTIME_CLASS( CChildFrame2 ),
            RUNTIME_CLASS( CView3 ),
            ID_VIEW_VIEW3,
            SW_SHOWNORMAL,
            TRUE ) );

    pDocTemplate->AddFrameTemplate(
        new CFrameTemplate(
            IDR_MV4,
            RUNTIME_CLASS( CChildFrame2 ),
            RUNTIME_CLASS( CView4 ),
            ID_VIEW_VIEW4,
            SW_SHOWNORMAL,
            TRUE ) );

    AddDocTemplate( pDocTemplate );
    m_server.ConnectTemplate( clsid, pDocTemplate, FALSE );

Now the extension support MDI Multiple view too!

    CMDIMVDocTemplate *pDocTemplate = new CMDIMVDocTemplate( IDR_MVTESTTYPE, RUNTIME_CLASS( CMvTestDoc ) );
    pDocTemplate->AddFrameTemplate(
        new CFrameTemplate(
            IDR_MV1,
            RUNTIME_CLASS( CChildFrame1 ),
            RUNTIME_CLASS( CView1 ),
            ID_VIEW_VIEW1,
            SW_SHOWNORMAL,
            TRUE ) );

    pDocTemplate->AddFrameTemplate(
        new CFrameTemplate(
            IDR_MV2,
            RUNTIME_CLASS( CChildFrame1 ),
            RUNTIME_CLASS( CView2 ),
            ID_VIEW_VIEW2,
            SW_SHOWNORMAL,
            TRUE ) );

    pDocTemplate->AddFrameTemplate(
        new CFrameTemplate(
            IDR_MV3,
            RUNTIME_CLASS( CChildFrame2 ),
            RUNTIME_CLASS( CView3 ),
            ID_VIEW_VIEW3,
            SW_SHOWNORMAL,
            TRUE ) );

    pDocTemplate->AddFrameTemplate(
        new CFrameTemplate(
            IDR_MV4,
            RUNTIME_CLASS( CChildFrame2 ),
            RUNTIME_CLASS( CView4 ),
            ID_VIEW_VIEW4,
            SW_SHOWNORMAL,
            TRUE ) );

    AddDocTemplate( pDocTemplate );
    m_server.ConnectTemplate( clsid, pDocTemplate, FALSE );

Download demo project – 76 KB

Download source – 11 KB

CodeGuru Logo

CodeGuru covers topics related to Microsoft-related software development, mobile development, database management, and web application programming. In addition to tutorials and how-tos that teach programmers how to code in Microsoft-related languages and frameworks like C# and .Net, we also publish articles on software development tools, the latest in developer news, and advice for project managers. Cloud services such as Microsoft Azure and database options including SQL Server and MSSQL are also frequently covered.

Property of TechnologyAdvice. © 2026 TechnologyAdvice. All Rights Reserved

Advertiser Disclosure: Some of the products that appear on this site are from companies from which TechnologyAdvice receives compensation. This compensation may impact how and where products appear on this site including, for example, the order in which they appear. TechnologyAdvice does not include all companies or all types of products available in the marketplace.