代码之家  ›  专栏  ›  技术社区  ›  Tommy Herbert

如何阻止MFC应用程序在启动时调用OnFileNew()?

  •  2
  • Tommy Herbert  · 技术社区  · 17 年前

    我使用VisualStudio的应用程序向导创建了一个带有多文档界面的框架MFC程序。当我启动这个程序时,它会自动创建一个子帧,我不希望它这样做-我需要主帧的客户端区域为空,直到用户选择打开一个文件。

    调试器告诉我,当应用程序类的InitInstance()函数调用ProcessShellCommand()时,会创建一个CChildFrame对象,但对于我来说,什么是重写此行为的好入口点?

    4 回复  |  直到 17 年前
        1
  •  5
  •   titanae    17 年前

    这样,它可以从外壳等保持打印/打开。

    // Parse command line for standard shell commands, DDE, file open
    CCommandLineInfo cmdInfo;
    ParseCommandLine(cmdInfo);
    
    if ( cmdInfo.m_nShellCommand == CCommandLineInfo::FileNew )
    {
        cmdInfo.m_nShellCommand = CCommandLineInfo::FileNothing ;
    }
    
    // Dispatch commands specified on the command line
    if (!ProcessShellCommand(cmdInfo))
        return FALSE;
    
        2
  •  4
  •   jeffm    17 年前

    这对我来说很有用——改变

    if (!ProcessShellCommand(cmdInfo))
    

    if (cmdInfo.m_nShellCommand != CCommandLineInfo::FileNew && !ProcessShellCommand(cmdInfo))
    

    在应用程序的InitInstance()函数中。

        3
  •  1
  •   Serge Wautier    17 年前

    跳过InitInstance()中的ProcessShellCommand()调用(在FileNew的情况下)确实是一种方法。

        4
  •  1
  •   Jatin Zaveri    16 年前

    在XXXApp.cpp文件中

    在这种方法中:-

        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; 
    

    */