Article ID: 152029
Article Last Modified on 7/1/2004
// 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;
}
Additional query words: WM_MACINTOSH WLM_MACEVENT
Keywords: kbhowto kbnoupdate kbdocview KB152029