
Start-Up MDI app without opening empty document
: I apologize for this simplistic question, I know I have done this
before a
: long time ago, but now can't seem to find the documentation reference.
:
: How can I suppress the opening of an empty document during start-up of
an
: MDI app? I want to force the user to input some options first, before
: either creating a new project or opening an exisitng one.
:
: Thanks,
:
In the BOOL CYourOwnApp::InitInstance() function place this code or
something like it.
// Enable DDE Execute open
EnableShellOpen();
RegisterShellFileTypes(TRUE);
// Parse command line for standard shell commands, DDE, file open
CCommandLineInfo cmdInfo;
ParseCommandLine(cmdInfo);
// ------------ INSERTION
POINT --------------------------------------------
// The following code looks in the Registry's MRU list for the last
file opened
// if it exists it loads it. If the MRU list is empty the app starts
without a
// document view. If the MRU list has a file listed, but the file does
not exist,
// a blank window appears. From then on the OnFileNew() will open a new
blank window.
if (cmdInfo.m_nShellCommand == CCommandLineInfo::FileNew) {
CString sLastPath(GetProfileString("Recent File List", "File1"));
if (! sLastPath.IsEmpty()) {
CFile f;
// If there is a file in MRU list, open it
if (f.Open(sLastPath, CFile::modeRead)) {
cmdInfo.m_nShellCommand = CCommandLineInfo::FileOpen;
cmdInfo.m_strFileName = sLastPath;
}
}
else {
// otherwise, don't display a document on startup
if(cmdInfo.m_nShellCommand == CCommandLineInfo::FileNew)
cmdInfo.m_nShellCommand = CCommandLineInfo::FileNothing;
}
}
// -------- END INSERTION --------------------------------------
// Dispatch commands specified on the command line
if (!ProcessShellCommand(cmdInfo))
return FALSE;
// The main window has been initialized, so show and update it.
pMainFrame->ShowWindow(m_nCmdShow);
pMainFrame->UpdateWindow();