Click here to Skip to main content
13,904,776 members
Click here to Skip to main content
Add your own
alternative version


35 bookmarked
Posted 24 Nov 2004
Licenced CPOL

Opening / Saving multiple types of documents in MFC MDI applications

, 24 Nov 2004
Rate this:
Please Sign up or sign in to vote.
A simple Visual C++ 6.0 multiple document (MDI) project that allows opening / saving multiple types of documents.


This is a simple visual C++ 6.0 multiple document (MDI) project that allows opening / saving multiple types of documents. Normally, when you start an MDI project, you are allowed to associate one file type (i.e. extension) with your project. If you want to be able to open / save more that one type, you need to change your program a bit (Figure 1). MyFirstProject is a simple empty project that handles multiple types.

Sample Image - MDI_MultipleExtension.jpg

What you need to do

All the altered codes are marked (as //Babak) so you can find them easily and just implement them exactly in your own project. Here is a summary of what you need to do:

  • Derive a class from CDocManager (here named CMultDocManager)
    • Override DoPromptFileName
    • Override OnFileNew
    • You will need to copy _AfxAppendFilterSuffix (with a slight change) from mfc/src/ docmgr.cpp (bad programming style)
  • Derive a class from CMultiDocTemplate (here named CMultMultiDocTemplate)
    (this is so your program can recognize multiple file types seperated by a semicolon
    • Override GetDocString
    • Override MatchDocType

(for the last two steps, just add the files MultDocManager.h/cpp and MultMultiDocTemplate.h/cpp to your project)

  • Set m_pDocManager of your main application class (the one that is derived from CWinApp) to new CmultDocManager
  • Open the .rc file of the project and make copies of IDR_...TYPE (for various file types)
  • Go through all the projcet files and everytime IDR_...TYPE is used, also use the new ones you made
  • Override DoSave in your main document class (the one that is derived from CDocument)


  • “MFC Document/View documentation and enhancements” by Roger Allen on
  • “How to support two file extensions per MFC document type” Micorosft support document Article ID 141921
  • “DocMgrEx.exe Assoc Multiple File Extension w/2 Doc Tyle” Micorosft support document Article ID 198538
  • “Selecting multiple files in File Open dialog” by Kaus Gutter on
  • “Opening multiple documents of several types at once” by Ernesto Perales Soto on


This article, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)


About the Author

Toronto Rehabilitation Institute - UHN
Canada Canada
Babak Taati

You may also be interested in...


Comments and Discussions

QuestionMore than two extensions Pin
Member 83901214-Mar-12 1:29
memberMember 83901214-Mar-12 1:29 
GeneralSaving Pin
cmckni327-Nov-05 13:02
membercmckni327-Nov-05 13:02 
GeneralRe: Saving Pin
cmckni327-Nov-05 14:54
membercmckni327-Nov-05 14:54 
GeneralRight Click 'New' Menu Pin
nDiddy1-Mar-05 12:27
membernDiddy1-Mar-05 12:27 
GeneralRe: Right Click 'New' Menu Pin
cmckni327-Nov-05 11:48
membercmckni327-Nov-05 11:48 
Generalsome questions Pin
SwingKid2-Dec-04 17:02
memberSwingKid2-Dec-04 17:02 
GeneralRe: some questions Pin
BabakTaati3-Dec-04 7:58
memberBabakTaati3-Dec-04 7:58 


The part that is commented adds an extension (e.g. .ex1 or .ex2) at the end of the 'suggested file name' when the save dialog box comes up. The problem is, when you change the file type, (from the combo box, for instance from "First1 files" to "First2 files") the extension for the suggested file name doesn't change. I couldn't figure out an elegant way of handlnig this, so I just commented the whole thing.

the way it is now, it suggests a file name (with no extension) and sticks the extension (ex1 or ex2, whichever you chose from teh combo box) at the end of it.

Any one has a better suggestion?


In what I was trying to do, I had two file formats that contained the same information just written differently in file. So all I needed to do was to have a switch in my Serialize function that loaded/saved the files according to their extension. But the data structure in the document class and the visualizaton (view class) were the same. So *I* didn't need to have two different document/view classes. But I guess if the documents you are trying to load are not of the same general type (in my case, a set of 3D points), then you'll need to have seperate document/view classes for them.

> Or there is a variable somewhere to tell the single
> Document class what type of document has been opened

You can just add a flag to your document class.

same general idea

GeneralRe: some questions Pin
SwingKid4-Dec-04 10:17
memberSwingKid4-Dec-04 10:17 
GeneralSalam Pin
A. Riazi25-Nov-04 19:48
professionalA. Riazi25-Nov-04 19:48 
GeneralRe: Salam Pin
Bruno Norberto26-Nov-04 1:17
memberBruno Norberto26-Nov-04 1:17 
GeneralRe: Pin
BabakTaati26-Nov-04 8:12
memberBabakTaati26-Nov-04 8:12 

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 | Cookies | Terms of Use | Mobile
Web06 | 2.8.190306.1 | Last Updated 24 Nov 2004
Article Copyright 2004 by BabakTaati
Everything else Copyright © CodeProject, 1999-2019
Layout: fixed | fluid