HOWTO: Prevent Creation of Initial Macintosh DocumentLast reviewed: October 8, 1997Article ID: Q152029 |
The information in this article applies to:
- Microsoft Visual C++, Macintosh Cross-Development, versions 2.0, 4.0
SUMMARYSometimes it is preferable not to initially open a new document in an MFC application. To implement this behavior on Windows, you can remove the call to OnFileNew() or ParseCommandLine() from InitInstance. On the Macintosh, you need to override CWinApp::CreateInitialDocument(). This article describes how to accomplish these behaviors.
MORE INFORMATIONIn a Windows MFC application, a new document is initially created if the Command Line is empty. Since Macintosh applications do not have Command Lines, the open application Apple Event is sent to the application and is handled by _AfxOpenAppHandler(), which calls CreateInitialDocument() to open a new document:
// From Visual C++ 4.0 OSErr PASCAL _AfxOpenAppHandler(AppleEvent* pae, AppleEvent* paeReply, long lRefcon) { CWinApp* pApp; OSErr err = HandlerCommon(pae, lRefcon, pApp); if (err == noErr) { if (pApp->CreateInitialDocument()) err = noErr; else err = errAEEventNotHandled; } AfxOleSetUserCtrl(TRUE); return err; } // From Visual C++ 4.0 BOOL CWinApp::CreateInitialDocument() { if (m_pMainWnd != NULL) m_pMainWnd->SendMessage(WM_COMMAND, ID_FILE_NEW); else if (m_pDocManager != NULL) { POSITION pos = m_pDocManager->GetFirstDocTemplatePosition(); if (pos != NULL) { CDocTemplate* pTemplate = m_pDocManager->GetNextDocTemplate(pos); // if MDI, or SDI but we haven't opened any documents yet, // open a new one if (pTemplate != NULL && (pTemplate->IsKindOf(RUNTIME_CLASS(CMultiDocTemplate)) || m_pDocManager->GetOpenDocumentCount() == 0)) { OnFileNew(); } } } return TRUE; }When a new document is not needed, you can override CreateInitialDocument() and have it return TRUE. This is desirable to prevent the file type dialog from appearing in applications supporting multiple document types:
BOOL CMyWinApp::CreateInitialDocument() { return TRUE; } REFERENCESSee "Creating Initial Documents" in the Macintosh Porting Guide within the Online Documentation.
|
Additional query words: WM_MACINTOSH WLM_MACEVENT
© 1998 Microsoft Corporation. All rights reserved. Terms of Use. |