how do I stop a document being opened at app startup.
Graham -- Cunningham@tgd.swissptt.ch Monday, June 24, 1996 Winnt3.51 vc4.1 Well this should be easy, I looked in the FAQ and it tells me that all I need to do is to do the following cmdInfo.m_nShellCommand = CCommandLineInfo::FileNothing In my SDI app this cause CWinApp::Run to post an exit app message cause there m_pMainWnd is set to null. I think the frame doesnt get created automatically in this case so I have done the following in InitInstance but have I missed something or does the FAQ need updating? CMainFrame* pMainFrame = new CMainFrame; if (!pMainFrame->LoadFrame(IDR_MAINFRAME); return FALSE; m_pMainWnd = pMainFrame;
Graham -- Cunningham@tgd.swissptt.ch Thursday, June 27, 1996 [Mini-digest: 4 responses] just so people know what I have tried already here is an answer that I sent back to David Elliot when he asked me why I dont simply override OnFileNew or OpenDocumentFile in CMyApp. ProcessShellCommand calls CWinApp::OnFileNew directly and this then calls the CDocManager::OnFileNew which calls the template CSingleDocTemplate::OpenDocumentFile(). You could go to the bother of deriving your own template class and handling this there but simply setting CCommandLineInfo::FileNothing and then remembering to create your own frame seems easier/less error prone. The problem is caused cause FileNothing isnt handled by the ProcessShellCommand and so there is never a frame created as there would be for FileNew (the default) and FileOpen. Thanks anyway I was personally hoping to be able to override OnFileNew or OpenDocumentFile in CMyApp but these just arent involved in the template process. >---------- >Von: Cunningham Graham, IK 23 >Gesendet: Montag, 24. Juni 1996 14:50 >An: 'mfc-l' >Betreff: how do I stop a document being opened at app startup. > >Winnt3.51 vc4.1 > >Well this should be easy, I looked in the FAQ and it tells me that all >I >need to do is to do the following >cmdInfo.m_nShellCommand = CCommandLineInfo::FileNothing > >In my SDI app this cause CWinApp::Run to post an exit app message cause >there m_pMainWnd is set to null. I think the frame doesnt get created >automatically in this case so I have done the following in InitInstance >but have I missed something or does the FAQ need updating? > >CMainFrame* pMainFrame = new CMainFrame; >if (!pMainFrame->LoadFrame(IDR_MAINFRAME); > return FALSE; >m_pMainWnd = pMainFrame; > > > -----From: "michael"That's really puzzling that the following line didn't work for you in preventing the opening of a document at launch time: cmdInfo.m_nShellCommand = CCommandLineInfo::FileNothing; Here's a snipet of code (20+ lines) from my InitInstance() routine that worked for me. (Caveat: I'm using Win 95 and you're running on NT.) ---------------------------------------------------------------------------- ----------------- o o o // create main MDI Frame window CMainFrame* pMainFrame = new CMainFrame; if (!pMainFrame->LoadFrame(IDR_MAINFRAME)) return FALSE; m_pMainWnd = pMainFrame; // Parse command line for standard shell commands, DDE, file open CCommandLineInfo cmdInfo; ParseCommandLine(cmdInfo); // Dispatch commands specified on the command line cmdInfo.m_nShellCommand = CCommandLineInfo::FileNothing; if (!ProcessShellCommand(cmdInfo)) return FALSE; // The main window has been initialized, so show and update it. pMainFrame->ShowWindow(m_nCmdShow); pMainFrame->UpdateWindow(); return TRUE; } --------------------------- Michael L. Thal Data Tree Corporation voice: (619) 231-3300 fax: (619) 231-3301 -----From: Sheir Rahman Ali There is probably a line in your CWinApp InitInstance() that says FileNewOpen() or something like that. Just take it out (or comment it out) and your app will start up without an initial document. TTYL rahman ******************************************* * Sheir Rahman Ali * * "Licensed Remote Controll Operator" * ******************************************* -----From: "Frederic Steppe" In a SDI application, there is always an active document/view. What you can do to avoid having an empty document is to pick the last used one from the MRU list and open it (see messages about how to do that in this list), or create a second doc template which just look like an empty MDI frame (simple view with the background of a frame) and create that kind of document/view at startup. Frederic Steppe (frederics@msn.com)
Dave Kolb -- sasdxk@unx.sas.com Monday, July 01, 1996 At 09:19 AM 6/27/96 +0200, Cunningham Graham, IK 23 wrote: >[Mini-digest: 4 responses] > >just so people know what I have tried already here is an answer that I >sent back to David Elliot when he asked me why I dont simply override >OnFileNew or OpenDocumentFile in CMyApp. > >ProcessShellCommand calls CWinApp::OnFileNew directly and this then >calls the CDocManager::OnFileNew which calls the template >CSingleDocTemplate::OpenDocumentFile(). You could go to the bother of >deriving your own template class and handling this there but simply >setting CCommandLineInfo::FileNothing and then remembering to create >your own frame seems easier/less error prone. The problem is caused >cause FileNothing isnt handled by the ProcessShellCommand and so there >is never a frame created as there would be for FileNew (the default) and >FileOpen. > >Thanks anyway I was personally hoping to be able to override OnFileNew >or OpenDocumentFile in CMyApp but these just arent involved in the >template process. Seems like the FileNothing flag should have worked. Here's the end of InitInstance in my app where I set FileNothing if FileNew was set. Works fine for me. I just didn't want an empty new document as I'm a viewer not an editor. Dave Kolb ... AddDocTemplate(pDocTemplate); // create main MDI Frame window CsvMFrame* pMainFrame = new CsvMFrame; if (!pMainFrame->LoadFrame(IDR_MAINFRAME)) return FALSE; m_pMainWnd = pMainFrame; // Enable drag/drop open m_pMainWnd->DragAcceptFiles(); // Enable DDE Execute open - this allow multiple opens per instance via Explorer! EnableShellOpen(); // Do not register all filetypes as open actions as we use a .reg file // since we have non-standard actions // RegisterShellFileTypes(TRUE); // Parse command line for standard shell commands, DDE, file open CCommandLineInfo cmdInfo; ParseCommandLine(cmdInfo); /* Command-line argument was parsed for following formats: app New file. app filename Open file. app /p filename Print file to default printer. app /pt filename printer driver port Print file to the specified printer. app /dde */ // reset command info FileNew flag if set so no new file is created at startup if (cmdInfo.m_nShellCommand == CCommandLineInfo::FileNew) cmdInfo.m_nShellCommand = CCommandLineInfo::FileNothing; // Dispatch commands specified on the command line (e.g. /p or /pt) if (!ProcessShellCommand(cmdInfo)) return FALSE; // create the main frame at the previously saved location WINDOWPLACEMENT wp; if (ReadWindowPlacement(&wp)) { // reset show to min or max if that's the way we went down last if (wp.showCmd == SW_SHOWMAXIMIZED || wp.showCmd == SW_SHOWMINIMIZED) m_nCmdShow = wp.showCmd; // restore our window placement position pMainFrame->SetWindowPlacement(&wp); } // The main window has been initialized, so show and update it. pMainFrame->ShowWindow(m_nCmdShow); pMainFrame->UpdateWindow(); return TRUE; Dave Kolb Compuserve: 72410,407@compuserve.com SAS Institute, Inc. EMAIL: sasdxk@unx.sas.com SAS Campus Drive - R3282 Phone: (919) 677-8000 x6827 Cary, NC 27513-2414 USA FAX: (919) 677-8123
Luca Orlandi -- Luca.Orlandi@inferentia.it Monday, July 08, 1996 MFC 3.x introduced the CCommandLineInfo class: BOOL CBUZApp::InitInstance() { ... // Parse command line for standard shell commands, DDE, file open CCommandLineInfo cmdInfo; ParseCommandLine(cmdInfo); // Do not process file new - lrkwz if( cmdInfo.m_nShellCommand == CCommandLineInfo::FileNew ) cmdInfo.m_nShellCommand = CCommandLineInfo::FileNothing; // Dispatch commands specified on the command line if (!ProcessShellCommand(cmdInfo)) return FALSE; ... } this worked for me. Luca Orlandi ------------------------ http://www.inferentia.it/net.drive http://www.inferentia.it/users/lrkwz
| Вернуться в корень Архива |