MFC应用程序首次启动时如何禁用自动创建文档/视图 [英] How to disable auto document/view creation when MFC application first starts
问题描述
我有一个使用Doc/View体系结构的常规MFC应用程序.当应用程序启动时,它会自动创建一个空文档的视图.我想在启动时禁用此自动视图,仅在用户从文件"菜单中单击新建文档"时显示视图.
I have a regular MFC application which uses Doc/View architecture. When the application starts it automatically creates a view of an empty document. I want to disable this automatic view on startup and show a view only when the user clicks on "New Document" from the File menu.
有什么办法吗?
CMultiDocTemplate* template = new CMultiDocTemplate(IDR_DorlionTYPE,
RUNTIME_CLASS(CDocument),
RUNTIME_CLASS(CChildFrame), // custom MDI child frame
RUNTIME_CLASS(CView));
if (!CView)
return FALSE;
推荐答案
标准MFC(由向导生成)代码假定,如果程序仅由其自身运行,则您始终希望看到一个新文档(与双击不同).在数据文件上运行或使用命令行选项运行它以打开文件);在对ProcessShellCommand()
的调用之前插入以下行以禁用此功能":
Standard MFC (wizard generated) code assumes that you would always want to see a new document if the program is just run by itself (as opposed to double-clicking on the data file or running it with a command-line option to open the file); insert the following lines before the call to ProcessShellCommand()
to disable this "feature":
if (cmdInfo.m_nShellCommand == CCommandLineInfo::FileNew) // actually none
cmdInfo.m_nShellCommand = CCommandLineInfo::FileNothing;
[如果您有兴趣,可以逐步浏览ParseCommandLine()
的MFC源代码,如果命令行中没有任何内容,则它将m_nShellCommand
设置为CCommandLineInfo::FileNew
]
[if you are interested, you can step through the MFC source code for ParseCommandLine()
where it sets m_nShellCommand
to CCommandLineInfo::FileNew
if there's nothing in the command line]
这篇关于MFC应用程序首次启动时如何禁用自动创建文档/视图的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!