sakee
asked on
OnFileOpen of Visual C++
OnCommand(ID_FILE_OPEN,OnF ileOpen) function calls OnFileOpen() to handle events of ID_FILE_OPEN. But I am not sure how to access the filename that is read by OnFileOpen().
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Your goal is to "access the filename that is read by OnFileOpen().". When all else fails, even before then really, I look at the MFC source code. It explains so much!
appdlg.cpp has the code for OnFileOpen:
void CWinApp::OnFileOpen()
{
ASSERT(m_pDocManager != NULL);
m_pDocManager->OnFileOpen( );
}
docmgr.cpp has the above OnFileOpen():
void CDocManager::OnFileOpen()
{
// prompt the user (with all document templates)
CString newName;
if (!DoPromptFileName(newName , AFX_IDS_OPENFILE,
OFN_HIDEREADONLY | OFN_FILEMUSTEXIST, TRUE, NULL))
return; // open cancelled
AfxGetApp()->OpenDocumentF ile(newNam e);
// if returns NULL, the user has already been alerted
}
You want the file name then override the OpenDocumentFile function on your CWinApp class. It is called from the last line of the above function (AfxGetApp()->OpenDocument File(newNa me):
virtual CDocument* OpenDocumentFile(LPCTSTR lpszFileName);
That's how you access the filename read by OnFileOpen.
Maybe you really want to do something else? Let me know and I'll try to help.
Steve
appdlg.cpp has the code for OnFileOpen:
void CWinApp::OnFileOpen()
{
ASSERT(m_pDocManager != NULL);
m_pDocManager->OnFileOpen(
}
docmgr.cpp has the above OnFileOpen():
void CDocManager::OnFileOpen()
{
// prompt the user (with all document templates)
CString newName;
if (!DoPromptFileName(newName
OFN_HIDEREADONLY | OFN_FILEMUSTEXIST, TRUE, NULL))
return; // open cancelled
AfxGetApp()->OpenDocumentF
// if returns NULL, the user has already been alerted
}
You want the file name then override the OpenDocumentFile function on your CWinApp class. It is called from the last line of the above function (AfxGetApp()->OpenDocument
virtual CDocument* OpenDocumentFile(LPCTSTR lpszFileName);
That's how you access the filename read by OnFileOpen.
Maybe you really want to do something else? Let me know and I'll try to help.
Steve
ASKER
can you provide a little more information than this? been trying in vain for some days already.
thanks.
sakee