tags:

views:

621

answers:

4

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?

+3  A: 

This worked for me -- change

if (!ProcessShellCommand(cmdInfo))

to

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

in your app's InitInstance() function.

jeffm
Thanks, I'll try that.
Tommy Herbert
It works! But will skipping ProcessShellCommand() altogether have unwanted consequences? What does that function do? (I've failed to find its definition in my project.)
Tommy Herbert
I've looked it up in the Visual Studio docs, and it looks like all the function does is to process the parameter, so this is great. Thanks again.
Tommy Herbert
Because you're only skipping the "FileNew" command, which you don't want to do on startup anyway, I don't think it will be a problem. You're still processing the other commands, so I think it will still work if for instance you passed a filename to open on the command line. (But I haven't tried it.)
jeffm
+1  A: 

Skipping the ProcessShellCommand() call (in case of FileNew) in InitInstance() is indeed the way to go.

Serge - appTranslator
+2  A: 

This works, it maintains printing/opening from the shell etc.

// 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;
titanae
I think this is equivalent to jeffm's answer. It's longer but clearer, and it's closer to what I ended up doing.
Tommy Herbert
A: 

Do one thing..

in your XXXApp.cpp file

in this Method:-

comment the following line.. /*

    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; 

*/

like this....

Jatin Zaveri