我有一个使用文档/ View 架构的常规 MFC 应用程序。当应用程序启动时,它会自动创建一个空文档的 View 。我想在启动时禁用此自动 View ,并仅在用户单击"file"菜单中的“新建文档”时显示 View 。
有什么办法可以做到吗?
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()
之前插入以下行以禁用此“功能”:
if (cmdInfo.m_nShellCommand == CCommandLineInfo::FileNew) // actually none
cmdInfo.m_nShellCommand = CCommandLineInfo::FileNothing;
[如果您有兴趣,可以单步查看 ParseCommandLine()
的 MFC 源代码,其中它将 m_nShellCommand
设置为 CCommandLineInfo::FileNew
如果命令行中没有任何内容]
关于c++ - 如何在 MFC 应用程序首次启动时禁用自动文档/ View 创建,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/24609936/