C++ – How to stop the MFC application from calling OnFileNew() when it starts


I used Visual Studio's Application Wizard to create a skeleton MFC program with a multi-document interface. When I start this program, it automatically creates a child frame, which I don't want it to do – I need the main frame's client area to be empty until the user chooses to open a file.

The debugger tells me that a CChildFrame object is created when the application class's InitInstance() function calls ProcessShellCommand(), but what is a good entry point for me to override this behaviour?

Best Solution

This worked for me -- change

if (!ProcessShellCommand(cmdInfo))


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

in your app's InitInstance() function.