Link to home
Start Free TrialLog in
Avatar of sakee
sakee

asked on

OnFileOpen of Visual C++

OnCommand(ID_FILE_OPEN,OnFileOpen) 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
Avatar of SteveGTR
SteveGTR
Flag of United States of America image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of sakee
sakee

ASKER

hello steve,

can you provide a little more information than this? been trying in vain for some days already.

thanks.

sakee
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()->OpenDocumentFile(newName);
  // 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()->OpenDocumentFile(newName):

  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