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 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



Comments

  • Visual Studio 2010

    Posted by kevinl33 on 10/12/2010 01:00am

    Has there been any updates to this code recently? It doesn't work so well in VS2010. The program fails when selecting file/open or file/close file/open.

    Reply
  • Clarification

    Posted by anandmalak on 09/04/2005 07:32am

    how to enable print preview. mail to: anand_malak@hotmail.com

    Reply
  • How do you know which one is active

    Posted by Legacy on 06/12/2003 12:00am

    Originally posted by: shinya

    I want to know which mdichild is active. Also is it possible to know which doctype is activated when you have more than 2 types of document.

    Reply
  • Cannot Execute the program!

    Posted by Legacy on 03/10/2003 12:00am

    Originally posted by: Vokey

    Hi,

    I had download the demo proj, and compile it under Visual C++ environment and it compile successfully.
    However I cannot execute the program, it prompt Debug Assertion Failed! and file is olelink.cpp

    How to make the program run?

    Thank you!

    Regards
    Vokey

    Reply
  • How to use single View/Doc frame to support files with different file extension?

    Posted by Legacy on 12/02/2001 12:00am

    Originally posted by: Davis

    I'm developing a project with single doc/view frame to diplay different types of imagesHow to use single View/Doc frame to support files with different types of image(BMP;DIB;GIF;..),Has any good suggestions to me?

    Reply
  • Very good but some bugs

    Posted by Legacy on 03/22/2001 12:00am

    Originally posted by: Ken Jiang

    I very like your Document Template. But I find some bugs.

    Bug 1: Couldn't query user to save modified document in SDIMvTemplate.

    I create a SDIMvTemplate and add two frame template. One is ListView,
    the other is EditView. Then I type some words in EditView. Now, I press
    File|New. The application close my document directly without any querys.

    Bug 2: Couldn't update the frame count in Document.

    In prev example, I type some words in EditView. Then I close the EditView.
    The app query me whether save.
    If I press Window|New Window to create a new frame before typing in EditView.
    Then close ALL EditView. The app don't query me because there is a ListView.
    And if I close ListView, I get the query.

    Bug 3: There may be more than one frame to CFrame.

    I can use Window|New Window to duplicate same frame. So the method CFrame::DestroyFrame
    must find all relative frame window to destroy.

    Thank for your code.

    Jiangke@konka.com
    2001.3.22

    Reply
  • good template but at least one error in the code!

    Posted by Legacy on 08/08/2000 12:00am

    Originally posted by: Markus Krosche

    If your MFC code overloads the
    OnOpenDocument(LPCTSTR lpszPathName) member and you return FALSE the application crashes.

    The solution:
    Change the member CMvDocTemplate::CleanDocument to do
    the following:

    // Must delete the associated frame manager.
    CDocFrameMgr* pDocFrameMgr = GetAssociatedDocFrameMgr(_pDoc );

    // Now you must check whether the pointer pDocFrameMgr
    // is 0 otherwise the application crashes!

    if (pDocFrameMgr) // <--- change this!!!
    {
    m_DocumentFrameList.RemoveAt
    ( m_DocumentFrameList.Find ( pDocFrameMgr ) );

    delete pDocFrameMgr;
    }

    Now the code works ...

    Reply
  • Multiple Views for single document (MDI) 3

    Posted by Legacy on 12/14/1999 12:00am

    Originally posted by: Venkatesh N.K.

    I downloaded your program, but vc++ not allowing to compiling your application why? Please send email for the above reason. And suggest referance for Multiple Views for
    single document.

    With Regards,

    N.K.Venkatesh,

    C-CADD,
    National Aerospace Lab.,
    Bangalore - 37.
    krishna_venky@rediffmail.com
    phone : 5274649 Extn. 4410.

    Reply
  • Most awesome...

    Posted by Legacy on 04/23/1999 12:00am

    Originally posted by: KlangenFarben

    unsure "ctrl+break" is "obscure", but ctrl+L is awesome stuff.
    as is most others.

    can't wait to blow the client's mind next show&tell

    Reply
  • This does not work with CEditView??

    Posted by Legacy on 12/24/1998 12:00am

    Originally posted by: Paul Wardle

    Thanks for this code; it does exactly what I want (or rather it would if it worked :)
    
    

    My intention is to have a text file containing a script (editable, based on CEditView). The document contains all information about the script, and the document also contains the script's runtime information when the script is running. Therefore when the script is executed, it is possible to spawn different views each containing different information about the state of the running script.

    The doc template class seems OK for normal documents, but falls over when I want to call OpenDocument and create a document based upon CEditView (ie. the document's text is all contained within the CEditView's CEdit control on the frame window).

    The CMvDocTemplate::OpenDocumentFile calls CDocument::OnOpenDocument.
    CDocument::OnOpenDocument calls CScriptDoc::Serialize() to load the document.

    *BUT* documents with views based upon CEditView rely on the view being created BEFORE the document. So I cannot call CEditView::Serialize to load the documents in CScriptDoc::Serialize(). CMultiDocTemplate creates the frame window BEFORE calling OnOpenDocument.

    In the project "MvTest", This can be shown by deriving CView1 from CEditView, then changing CMvTestDoc::Serialize() to contain this code (this is similar to the code that AppWizard produces) :

    void CMvTestDoc::Serialize(CArchive& ar)
    { ((CEditView*)m_viewList.GetHead())->SerializeRaw(ar); }

    How can I change the code to work as I need it (is it simply to create a frame window before the call to OnOpenDocument???)

    Thanks for the help in advance, anyone!

    Reply
Leave a Comment
  • Your email address will not be published. All fields are required.

Top White Papers and Webcasts

  • As all sorts of data becomes available for storage, analysis and retrieval - so called 'Big Data' - there are potentially huge benefits, but equally huge challenges...
  • The agile organization needs knowledge to act on, quickly and effectively. Though many organizations are clamouring for "Big Data", not nearly as many know what to do with it...
  • Cloud-based integration solutions can be confusing. Adding to the confusion are the multiple ways IT departments can deliver such integration...

Most Popular Programming Stories

More for Developers

RSS Feeds

Thanks for your registration, follow us on our social networks to keep up-to-date