Click here to Skip to main content
13,550,709 members
Click here to Skip to main content
Add your own
alternative version


26 bookmarked
Posted 20 May 2004

SVDI: a "Single View, Multiple Documents" MFC Architecture

, 20 May 2004
Rate this:
Please Sign up or sign in to vote.
An article on a "Single View, Multiple Documents" MFC Architecture with a new VC++ code wizard


This article shows a document/view architecture different from SDI and MDI. It uses one view to display multiple documents.

Background: SDI and MDI architectures

Typically, MFC AppWizard suggests two kinds of Document-View Architectures.

  • SDI, Single Document Interface: only one document is displayed in a single view, which is contained in the main frame window (CFrameWnd). When you select the "File, New" command, the document data are destroyed (see CDocument::DeleteContents) and replaced by a new content. There is no "File, Close" command. The document, the view and the frame are destroyed together when the user exits the application. All this is managed through a CSingleDocTemplate template object.
  • MDI, Multiple Document Interface: there can be zero, one or several documents. Each document is displayed in a separate view, which is contained in a child frame window (CMDIChildWnd). All child frame windows are contained in the main frame window (CMDIFrameWnd). When you select the "File, New" command, a new document, a new view and a new child frame are created. When you select the "File, Close" command, the active document, the active view and the active child frame are destroyed. All this is managed through a CMultiDocTemplate template object.

SDI and MDI comply with this assumption: for each document there is a view and a frame (CFrameWnd in SDI, CMDIChildWnd in MDI). All three objects are created and destroyed together. All documents are displayed (of course some windows can be hidden or minimized).

Looking at the MFC source code, I noticed that:

  • when a document is created, most of the work is achieved by the OpenDocumentFile method of template object;
  • when a document is destroyed, most of the work is achieved by method CDocument::OnCloseDocument.

Single View, multiple documents: SVDI Architecture

The aim of this article is to show another kind of architecture called SVDI, Single View Document Interface. It is a "Single View, Multiple Documents" Architecture. There can be zero, one or several documents, zero or one view, and one main frame window. The view is created when the first document is created, and destroyed when the last document is destroyed. Only one document can be displayed at a time.

When you select the "File, New" command, a new document is created; if there is no view, a view is created to display the document. When you select the "File, Close" command, the active document is destroyed. If there are some other documents, one of them is displayed in the view; otherwise the view is destroyed. This does not comply with the preceding assumption.

For the sake of simplicity, there are only a few minor differences between the SDI and SVDI architectures. I just added a new template class called CSingleViewMultiDocTemplate, which does nearly all work concerning the opening of a document (see CSingleViewMultiDocTemplate::OpenDocumentFile). A few methods are overloaded. The "File, Close" command and a list of documents in the View menu have been added.

Using the code

You can either:

  • Make your own application, taking your inspiration from my demo projects;
  • If you have Visual C++ .NET, use the wizard I have created for you, which generates automatically a SDI, SVDI or MDI application;
  • If you don't have Visual C++ .NET, create your SDI application as usual, and convert it to a SVDI application following the method given above.
Have fun!


This project has been successfully tested with Microsoft Visual C++ .NET 2002 Professional (French version) and Microsoft Visual C++ .NET 2003 Professional (English version). The wizard should work with all English/French versions of Microsoft Visual C++ 2002/2003 (sorry for people from other countries, some files are specific to each localized version).

Note for Microsoft Visual C++ 6 users: unfortunately I do not have Visual C++ 6, so I did no test the demos. You will have to re-create an empty project and add all the files.


This article has no explicit license attached to it but may contain usage terms in the article text or the download files themselves. If in doubt please contact the author via the discussion board below.

A list of licenses authors might use can be found here


About the Author

Software Developer (Senior)
France France
No Biography provided

You may also be interested in...

Comments and Discussions

QuestionWizard installation fails ? Pin
Michael B Pliam9-Nov-10 7:29
memberMichael B Pliam9-Nov-10 7:29 
GeneralClose to my heart's desire -- but not quite Pin
Michael B Pliam9-Nov-10 7:18
memberMichael B Pliam9-Nov-10 7:18 
GeneralCMDIChildWnd Pin
Acolytee24-Jun-05 17:48
memberAcolytee24-Jun-05 17:48 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.

Permalink | Advertise | Privacy | Terms of Use | Mobile
Web01 | 2.8.180515.1 | Last Updated 21 May 2004
Article Copyright 2004 by chris109
Everything else Copyright © CodeProject, 1999-2018
Layout: fixed | fluid