I have a regular MFC application which uses Doc/View architecture. When the application starts it automatically creates a view of an empty document. I want to disable this automatic view on startup and show a view only when the user clicks on "New Document" from the File menu.
Is there any way to do so?
CMultiDocTemplate* template = new CMultiDocTemplate(IDR_DorlionTYPE,
RUNTIME_CLASS(CDocument),
RUNTIME_CLASS(CChildFrame), // custom MDI child frame
RUNTIME_CLASS(CView));
if (!CView)
return FALSE;
I used
without the if-statement.
See CCommandLineInfo::m_nShellCommand
Standard MFC (wizard generated) code assumes that you would always want to see a new document if the program is just run by itself (as opposed to double-clicking on the data file or running it with a command-line option to open the file); insert the following lines before the call to
ProcessShellCommand()
to disable this "feature":[if you are interested, you can step through the MFC source code for
ParseCommandLine()
where it setsm_nShellCommand
toCCommandLineInfo::FileNew
if there's nothing in the command line]With my MFC application I wanted something similar however I found that the accepted answer was only a partial solution for me. If a file name is specified on the command line of the MFC application when it is started up, using the accepted answer will not open the file.
I wanted to (1) allow a file to be opened when the MFC application is invoked from a command line and (2) change the current working folder.
In the
InitInstance()
override of the application which extendsCWinAppEx
I used the following source: