惯性聚合 高效追踪和阅读你感兴趣的博客、新闻、科技资讯
阅读原文 在惯性聚合中打开

推荐订阅源

Hacker News: Ask HN
Hacker News: Ask HN
月光博客
月光博客
Martin Fowler
Martin Fowler
人人都是产品经理
人人都是产品经理
有赞技术团队
有赞技术团队
Hugging Face - Blog
Hugging Face - Blog
T
Tailwind CSS Blog
爱范儿
爱范儿
博客园_首页
Last Week in AI
Last Week in AI
N
Netflix TechBlog - Medium
NISL@THU
NISL@THU
H
Help Net Security
A
Arctic Wolf
K
Kaspersky official blog
Y
Y Combinator Blog
G
GRAHAM CLULEY
T
Threatpost
I
Intezer
Attack and Defense Labs
Attack and Defense Labs
Jina AI
Jina AI
Recent Announcements
Recent Announcements
D
Docker
博客园 - 聂微东
让小产品的独立变现更简单 - ezindie.com
让小产品的独立变现更简单 - ezindie.com
www.infosecurity-magazine.com
www.infosecurity-magazine.com
GbyAI
GbyAI
The Hacker News
The Hacker News
C
Cyber Attacks, Cyber Crime and Cyber Security
Help Net Security
Help Net Security
Microsoft Azure Blog
Microsoft Azure Blog
G
Google Developers Blog
F
Fortinet All Blogs
S
Security Affairs
Security Archives - TechRepublic
Security Archives - TechRepublic
量子位
AWS News Blog
AWS News Blog
Google DeepMind News
Google DeepMind News
罗磊的独立博客
V
Vulnerabilities – Threatpost
阮一峰的网络日志
阮一峰的网络日志
T
Tor Project blog
freeCodeCamp Programming Tutorials: Python, JavaScript, Git & More
H
Hacker News: Front Page
Security Latest
Security Latest
The Cloudflare Blog
cs.CV updates on arXiv.org
cs.CV updates on arXiv.org
M
MIT News - Artificial intelligence
B
Blog
云风的 BLOG
云风的 BLOG

博客园 - 红马天下

【原创】改造rails使支持gb2312编码 【转载】Rails使用gb2312/gbk与utf8共存的解决方案 【原创】MBCS,Unicode,UTF8以及一个用C++读写UTF8文件的工具类 【原创】Asp.Net从Windows Server 2003 32bit迁移到Windows Server 2008 64bit的找不到组件 这辈子一定要做一件有意义的事 【转载】软件缺陷管理基本概念 【转载】软件配置管理中的分支 【转载】我的Lean & Agile(精简和敏捷)经历(这才是最佳实践) 【转载】微软的管理模式真的值得吹嘘么? 【转载】负载均衡技术全攻略 【转载】MySpace的六次重构 【转载】转一篇自己的书评,关于《重构》 【转载】避免软件重建失败的三种方案 【转载】ASP.NET AJAX进度条 【转载】快速、可伸缩和流式的AJAX代理--跨域持续内容分发 给CHtmlEditView添加自定义拖拽功能IDropTargetpdwEffectDROPEFFECT_COPY ole拖放的若干tips 深入分析eXtreme Toolkit Toolbar的Command消息 在eXtreme Toolkit Pro 11.2.1中使用中文
【转载】让文档模板支持多文件扩展名
红马天下 · 2008-04-23 · via 博客园 - 红马天下

出处:How to support multiple file extensions with one document type in Visual C++ MFC applications

How to support multiple file extensions with one document type in Visual C++ MFC applications

Article ID : 198538
Last Review : November 21, 2006
Revision : 4.1

This article was previously published under Q198538

On This Page

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.

Back to the top

MORE INFORMATION

The following files are available for download from the Microsoft Download Center:

DocMgrEx.exe (http://download.microsoft.com/download/vc60pro/sample11/1/nt4/en-us/docmgrex.exe)

NOTE: To Build this project with VS .NET, change the path in the #include of AfxImpl.h on line 472 of DocManagerEx.cpp:

Change from:
#include <.."src"afximpl.h>

To:
#include <.."src"mfc"afximpl.h>

For more information about how to download Microsoft Support files, click the following article number to view the article in the Microsoft Knowledge Base:

119591 (http://support.microsoft.com/kb/119591/) How to obtain Microsoft support files from online services

Microsoft scanned this file for viruses. Microsoft used the most current virus-detection software that was available on the date that the file was posted. The file is stored on security-enhanced servers that help prevent any unauthorized changes to the file.
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.

Back to the top

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.

Back to the top

REFERENCES

For more information, click the following article number to view the article in the Microsoft Knowledge Base:

141921 (http://support.microsoft.com/kb/141921/) How to support two file extensions per MFC document type