SAMPLE: DocMgrEx.exe Assoc Multiple File Extensions w/1 Doc Type
ID: Q198538
|
The information in this article applies to:
-
The Microsoft Foundation Classes (MFC), included with:
-
Microsoft Visual C++, 32-bit Editions, versions 5.0, 6.0
SUMMARY
DocMgrEx.exe is a sample that shows how to support multiple extensions
associated with one document type (or template) in MFC's Doc/View
architecture.
This sample implements the code required to allow registration,
unregistration, file open, and file save operations in an otherwise regular
MFC application. The classes touched include the following:
- The CWinApp-derived class.
- The undocumented CDocManager class.
- A custom CFileDialog-derived class that allows transparent file
operations with the newly defined CDocManagerEx.
MORE INFORMATION
The following file is available for download from the Microsoft Software
Library:
~ DocMgrEx.exe
Release Date: Jan-07-1999
For more information about downloading files from the Microsoft Software
Library, please see the following article in the Microsoft Knowledge Base:
Q119591
How to Obtain Microsoft Support Files from Online Services
To change the extensions supported by different document types, or to add
new document types, edit the application's string table. In the string
resource associated with the document type resource ID, the fourth "\n"
delimited substring should read as follows:
DocType files (.ex1;.ex2;ex3)
The 5th substring should read as follows:
.ex1;.ex2;.ex3
NOTE: DocType is the external name of the document type; and ex1, ex2, ex3
are the extensions you want to associate with your document type.
When testing the application, you will notice its behavior is similar to
DevStudio with regard to file open/save operations. For example, when
trying to open a file, the user specifies only a file name (without an
extension), the application will successively append the extensions from
the currently active filter, trying to build the file name of an existing
file. If this yields no result, the application will either tell the user
that the file does not exist (if the OFN_FILEMUSTEXIST flag was specified)
or it will create a new file with no extension. Saving operations are very
similar.
Implementation Details
To implement correct registration code we needed to override
CDocManager::RegisterShellFileTypes().
Unregistration is a bit more complicated, because the corresponding
functions in CWinApp and CDocManager were not declared virtual. Therefore,
we needed to implement the correct code in an override of
CDocManager::UnregisterShellFileTypes(), and copy and paste the code from
CWinApp::UnregisterShellFileTypes() and CWinApp::ProcessShellCommand() in
our own CWinApp-derived class.
To implement file operations transparently, we overrode
CDocManager::DoPromptFileName() and CDocManager::OpenDocumentFile(). To
minimize the number of changes, the global function MatchDocType() has been
defined to replace the use of CDocTemplate::MatchDocType() member function.
The new function behaves as expected when multiple extensions are provided
for one document template.
Additional query words:
kbDSupport
Keywords : kbfile kbsample kbDocView kbMFC kbVC500 kbVC600
Version : WINNT:5.0,6.0
Platform : winnt
Issue type :
Last Reviewed: July 22, 1999