首页 > 解决方案 > ProcessShellCommand OpenFile 在构造文档或视图类之前调用​​ OpenDocumentFile

问题描述

我有一个带有文档/视图架构的单文档 MFC 项目。在 CWinApp 派生类的源文件中,我们称它为 CMyApp,在 CMyApp::InitInstance 中有这部分初始化代码:

CCommandLineInfo cmdInfo;
ParseCommandLine(cmdInfo);

// Dispatch commands specified on the command line.  Will return FALSE if
// app was launched with /RegServer, /Register, /Unregserver or /Unregister.
if (!ProcessShellCommand(cmdInfo))
        return FALSE;

在我的 CMyApp 类中,我重写了 OpenDocumentFile 函数。然后我给调试器命令行一个完整的文件路径和名称。我在对 ProcessShellCommand 的调用中设置了一个中断,它具有文件名和 m_nShellCommand 到 OpenFile。ProcessShellCommand 首先按预期调用我已覆盖的 OpenDocumentFile 函数,但问题是尚未构造 CMyDocument 和 CMyView 类。如果 MFC 甚至还没有构建类,它如何期望我打开一个文档?我可以做到这一点并且它有效,但似乎我没有按预期做事。

CCommandLineInfo cmdInfo, cmdInfo2;
ParseCommandLine(cmdInfo);
// Dispatch commands specified on the command line.  Will return FALSE if
// app was launched with /RegServer, /Register, /Unregserver or /Unregister.
if (!ProcessShellCommand(cmdInfo2))
    return FALSE;
if (!ProcessShellCommand(cmdInfo))
        return FALSE;

有更好的想法吗?

标签: c++winapimfc

解决方案


推荐阅读