?
Solved

OnFileOpen of Visual C++

Posted on 2000-01-10
3
Medium Priority
?
504 Views
Last Modified: 2008-03-10
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().
0
Comment
Question by:sakee
  • 2
3 Comments
 
LVL 30

Accepted Solution

by:
SteveGTR earned 200 total points
ID: 2338943
Override CWinApp::OpenDocumentFile. OnFileOpen() calls this with the file name selected by the user:

virtual CDocument* OpenDocumentFile( LPCTSTR lpszFileName);

Good Luck,
Steve

0
 

Author Comment

by:sakee
ID: 2356491
hello steve,

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

thanks.

sakee
0
 
LVL 30

Expert Comment

by:SteveGTR
ID: 2356704
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
0

Featured Post

Never miss a deadline with monday.com

The revolutionary project management tool is here!   Plan visually with a single glance and make sure your projects get done.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

C++ Properties One feature missing from standard C++ that you will find in many other Object Oriented Programming languages is something called a Property (http://www.experts-exchange.com/Programming/Languages/CPP/A_3912-Object-Properties-in-C.ht…
This article shows you how to optimize memory allocations in C++ using placement new. Applicable especially to usecases dealing with creation of large number of objects. A brief on problem: Lets take example problem for simplicity: - I have a G…
The goal of the tutorial is to teach the user how to use functions in C++. The video will cover how to define functions, how to call functions and how to create functions prototypes. Microsoft Visual C++ 2010 Express will be used as a text editor an…
The viewer will learn how to pass data into a function in C++. This is one step further in using functions. Instead of only printing text onto the console, the function will be able to perform calculations with argumentents given by the user.

594 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question