Virtual Developer Workshop: Containerized Development with Docker

Download files 77K.

What is a MultiSingle document.

In most applications, it is necessary to have one document with many views. The SDI architecture is for one document and one view and the MDI architecture is for many documents with many views. My goal is to have an MDI architecture with one document and many views connected or not to the document. If a chose the 'new' file command, all views must close and a new document with the fist doc template view must be started. If a chose the 'close' file command, all views must close and the client area must be empty. Views not attached to the document (attached to the main frame) can live. If the system menu 'close' command of a child window is actived, the child window will close. If this is the main view (1st doc template) the effect is the same as if you select the 'close' command of the file menu.

This sample is an MSDI application with three views. The 1st view is the main document view derived from CFormView. It must be the 1st doc template view. The 2nd view is a simple drawing derived from CView and is attached to the document. The 3rd view is a COutView derived from CEditView. This view is not a document view and is not closed with the document 'Close' command. It can be opened without document. To close this view, use the system menu of the child window or the close button.

To open these Views, the commands are implemented in the 'View' menu. The document class is responsible to open the document views and the mainframe classe is responsible to open the other views. For the COutView, an other menu is used with new commands to demonstrate the possibilities of MSDI.

The 'New window' command in the 'Window' menu open only new windows if the view is connected to the document. If the view is not attached to the document, it can't open a second view. You can change this as you like, see the CMSDIViewFrame class.

It is not possible to open more than one view of the same class if the view is attached to the document with the 'Create view' command. The function CreateOrActivateFrame checks if the view exist and active it. You can change this if you wish more than one view of the same class.

For independant views (not attached to the document), it is complicate to check if exist because we can't walk trough the views with a document pointer. So we must save the view pointer in the MainFrame and reset it when the COutView::OnDestroy() is called.

The ressource ID will be used to change the view title (the first resource substring). If you have different ressource ID for your views, you can change the menu too. If no menu nor accelerator table is defined for a ressource ID, the derived child window CMSDIViewFrame witch is the base frame class for all child frames exept the fist (CMSDIFirstFrame), will connect to the menu and accelerator of the fist view. It will use the fist ressource substring for the window title.

The CMSDIFirstFrame window class is the base frame class for the main view. It call the application to close all document views if it is closed.

Build MultiSingle (MSDI) document-view with AppWizard.

  • Create an MDI application with AppWizard (in this sample, an "msdi" application).
  • Include msdiapp.h, msdifrm.h & msdivfrm.h in stdafx.h or your library include file. These files will not change and are the only files neded to create an MSDI application.
  • Add msdiapp.cpp, msdifrm.cpp & msdivfrm.cpp in your project or your library in linker option.
  • Derive your CMsdiApp from CMSDIWinApp and not from CWinApp, Replace All CWinApp with CMSDIWinApp in msdi.cpp & msdi.h.
  • Delete the ON_COMMAND for ID_FILE_NEW & ID_FILE_OPEN in msdi.cpp.
  • Replace the Frame classe CMDIChildWnd in the creation of the doc template with the CMSDIFirstFrame class to avoid closing the document with views remaining open.

At this point, the MSDI application work fine. We must now implement the build of multiple views. The best way to do this is to add doc templates like Microsoft in the CHKBOOK sample and make change to the doc string (the third substring) to avoid the MDI Document dialog box.

  • With the application studio, add your views creation commands in the 'View' menu.
  • Add document string for your views like this "ViewTitle\n\n\n\n\n\n". In this sample IDR_GRAFTYPE & IDR_OUTTYPE are the new ressource-ID.
  • Make a copy of the MDI icone for all new ressource-ID. You can change this icone as you like.
  • If necessary, make a copy of the main view menu and change it according to the new view commands.
  • With appwizard, map the messages to the document classe or the mainframe class.
  • Edit the new fuctions and add the view creation. Use NULL for the doc parameter of CreateOrActivateFrame if the view is not a document view.
  • Add the include files for your new views in your document class file msdidoc.cpp, in the mainfrm.cpp if necessary and in your application file msdi.cpp for doc template creation.
  • Add the doc templates creation in your application file msdi.cpp. Use the CMSDIViewFrame classe to have a new frame title for all views. Give the new ressource-ID for all views.

MSDI with Visual C++4.0.

For Visual C++ 4.0, we must remove two functions and make litle change (see WIN32). These functions exist in the Win32 implementation of MFC.

Change between Versions.

Version 1.0. Uploaded as MSDI.ZIP

First implementation of the MSDI Multi(View) Single(Doc) Document Interface.

Version 1.1 (Oct 19 1996) (Uploaded as MSDI32.ZIP

Adding OnDestroy() in the COutView and call the CMainFrame::OnDestroyView() to clear the view pointer.

Version 1.2 (Oct 22 1996) Uploaded as MSDI1632.ZIP

Change name of classe CMSDIFrame to CMSDIFirstFrame.

Change name of classe CViewFrame to CMSDIViewFrame and files viewfrm.* to msdivfrm.*

Implement OnSysCommand() in the CMSDIFirstFrame to close all views if the main view is closed. Call an override function in the class CMSDIWinApp. You can change the behaviour of the first frame system menu close.

Implement OnCreate() in the CMSDIViewFrame for frame with no menu nor accelerator table.

Implement OnUpdateViewView2() to disable the create menu command if the view exist.

Set read only to TRUE in OnInitialUpdate() for the COutView.

Replace the CMSDIWinApp::SaveModified() function name with the name CloseDocument() and make the fuction virtual.

Replace the name CMultiSingleDocTemplate with CMSDITemplate.

Implement the ON_WINDOW_NEW message to create new windows for all view connected to the document. Implement the OnUpdateFrameTitle() to update the frame titel accordingly.

Add a new function GetDocTemplate() to the CMSDIWinApp to retreive the CMSDITemplate* with a CView* as parameter.


For all child windows, a new icon is defined, but the framework display the MFC icon for the main view and the same icon for the graf and output view. I have tryed to change the class and connect the right icon, but the code is to complicate for a generic application.


I'm sure you will have many applications with the MSDI interface. If you have some questions or if you have significant generic add on, please contact me.


  • Problems with views not associated with the document

    Posted by mmann78 on 07/21/2004 04:56pm

    The code works great, but I'm having a problem with views not associated with the document. I have a non-associated view and call CreateOrActivate(), passing NULL for the document to display it. This makes the active document NULL. This is a problem because I have threads running in the background that call GetDocument(). My workaround solution is to save the CDocument pointer (if not NULL) when CreateOrActivateFrame() is called. Then when GetDocument() is called, if the Active MDI doesn't have a document, it returns the saved CDocument pointer. Comments on this solution?

  • Nice Work!! But Doesnt support Swapping b/w Views

    Posted by Legacy on 09/16/2003 07:00am

    Originally posted by: Sreeram

    This project is a nice Demonstration but i am not able to swap from one view to other view. Like if i have two views A and B then i should be able to swap b/w the two views and every time i need not create a new view.

  • Good work but does'nt work with CFormView

    Posted by Legacy on 10/09/2001 07:00am

    Originally posted by: Ganesh

    I used this application and tried to add 2 views derived from CFormView insted of CView..

    But the program crashes in CreateOrActivateFrame() function call .
    Any solution...??????


  • I Like it !

    Posted by Legacy on 07/13/2001 07:00am

    Originally posted by: AndyC

    This is good stuff and well documeted - thanks. I do have one question, how do you go about letting all the view be closed but keep the document open ? I realise that in your artical you stated that this was not the functionality that you wanted but I thought I would just ask.

  • http://www.codeguru.com/doc_view/msdi.shtml - (MDI)

    Posted by Legacy on 12/03/1999 08:00am

    Originally posted by: Eugene

    I have a comment regarding about this website. I find that the download is not working at all in my compiler. I am currently using Visual C++ 6.0 and it keeps giving me strange indication in the the compiler window. Could you please explain to me how do i solve this problem.

    Secondly...i have a MDI program that was developed using the App wizard in visual c++ 6.0 . I am using the CRecorview as my view. For each dialog i have my own recordview class as well as recordset class. In my InitInstance found on my CWinApp class, i have added to document template. Each document template open a separate Record view with different controls in it. The controls i have already added in my dialog template resource.

    My Question is :

    1) How do i bring a particular child window which has a
    different record view in focus. In other words i would
    like to bring a particular child window from the back to
    the front?. Could you please give me the coding to
    perform such task as i'm am still learning.

    Note : There is no handle to the child window in my
    program. It is all developed using app wizard.

  • You must have javascript enabled in order to post comments.

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

Most Popular Programming Stories

More for Developers

RSS Feeds

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