Click here to Skip to main content
Click here to Skip to main content

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

By , 20 May 2004
 

Introduction

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!

Compatibility

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.

License

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

chris109
Software Developer (Senior)
France France
Member
No Biography provided

Sign Up to vote   Poor Excellent
Add a reason or comment to your vote: x
Votes of 3 or less require a comment

Comments and Discussions

 
You must Sign In to use this message board.
Search this forum  
    Spacing  Noise  Layout  Per page   
GeneralClose to my heart's desire -- but not quitememberMichael B Pliam9 Nov '10 - 7:18 
I have never cared much for MDI. It's cumbersome, confusing to the end user, and quickly gets messy if one wants to do much with it. For those reasons, I have stuck with SDI for many years. But I have always longed for an interface that has only a single frame window that can display multiple views with their associated multiple docs when necessary, where the user can switch views at the click of a button. But if I want to incorporate a CView and a CRichEditView, obviously that would require two separate documents. Several methods have been proposed to construct an SDI interface with multiple views. But each of these examples uses the same document. For example, see :
 
Multiple Views Using SDI by Richard Stringer - December 2, 1998
http://www.codeguru.com/cpp/w-d/doc_view/viewmanagement/article.php/c3341
 

VSWAP32 demonstrates methods of switching between multiple views on a single
document in a single-document interface (SDI) application. VSWAP32 displays
two form views and a normal view that displays the list of data collected in
the two form views.
http://support.microsoft.com/kb/141334[^]
 
But nowhere can I find an SDI interface that allows for multiple views that may require different documents. Some have even suggested that I forget this quest and simply use MDI. Discussions on this point usually get mired down in semantics and go nowhere. You seem to have a handle on what I have been looking for.
 
Any thoughts on this matter would be greatly appreciated by me and many others who avoid MDI

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

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