Solved

CWinApp::OnFileOpen();

Posted on 2001-09-06
8
1,458 Views
Last Modified: 2013-11-20
CWinApp::OnFileOpen();

Is a standard function to open a file!
The function itself does not open the file, but returns a path string Right ?, where is that string returned ?

How does OnFileOpen work ?
0
Comment
Question by:win32
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
8 Comments
 
LVL 2

Expert Comment

by:BogdyPtr
ID: 6460706
The OnOpenFile is suposed to be use with SDI/MDI applications. The OnOpenFile displays an open file dialog, gets the file name and calls the CWinApp::OnOpenDocument with the file path chosed by user.
0
 
LVL 6

Accepted Solution

by:
Triskelion earned 20 total points
ID: 6461237
CWinApp::OnFileOpen
afx_msg void OnFileOpen( );

It is void.  It does not return anything.

From the looks of it, it's stored in a
dlgFile.m_ofn.lpstrFile
that can be retrieved from the
CFileDialog::GetFileName() function.
0
 
LVL 6

Expert Comment

by:Triskelion
ID: 6461304
You need to override the OnFileOpen.
I chose (for this example) to do it in the View, but it can be done anywhere the ID_FILE_OPEN message is passed.

void CMy20179379View::OnFileOpen()
{
     CFileDialog     xDlg
          (
          TRUE, //BOOL bOpenFileDialog,
          NULL, //LPCTSTR lpszDefExt = NULL,
          NULL, //LPCTSTR lpszFileName = NULL,
          (OFN_HIDEREADONLY | OFN_OVERWRITEPROMPT),// DWORD dwFlags = OFN_HIDEREADONLY | OFN_OVERWRITEPROMPT,
          "*.exx",//LPCTSTR lpszFilter = NULL,
          NULL//CWnd* pParentWnd = NULL
          );
     xDlg.DoModal();
     AfxMessageBox(xDlg.GetFileName());
}
0
Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
LVL 3

Expert Comment

by:GGRUNDY
ID: 6463077
Have a look at CFile::Open.

http://msdn.microsoft.com/library/default.asp?url=/library/en-us/vcmfc98/html/_mfc_cfile.3a3a.open.asp

I just have a suspicion this is what you are really after.

Apologies if I am wrong.
0
 
LVL 10

Expert Comment

by:makerp
ID: 6463225
do

CFileDialog *dlg;
*dlg = new........
dlg->DoModal();
CString MyFileName = dlg->GetPathName();
0
 
LVL 6

Expert Comment

by:Triskelion
ID: 6463772
markp, that's practically what I said except I didn't use a pointer to create the dialog box and I used AfxMessageBox to display the string.
0
 
LVL 10

Expert Comment

by:makerp
ID: 6464283
and your point is!, have i proposed an answer, no. besides my code is easier
0
 
LVL 6

Expert Comment

by:Triskelion
ID: 6464621
The code I posted shows all of the parameters for customizing the CFileDialog at creation.

I copied that directly from a test app.
There is no 'easier' concept involved with either of our examples.  You've confused me.

0

Featured Post

Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

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

In this article, I'll describe -- and show pictures of -- some of the significant additions that have been made available to programmers in the MFC Feature Pack for Visual C++ 2008.  These same feature are in the MFC libraries that come with Visual …
Introduction: Database storage, where is the exe actually on the disc? Playing a game selected randomly (how to generate random numbers).  Error trapping with try..catch to help the code run even if something goes wrong. Continuing from the seve…
This video will show you how to get GIT to work in Eclipse.   It will walk you through how to install the EGit plugin in eclipse and how to checkout an existing repository.
There are cases when e.g. an IT administrator wants to have full access and view into selected mailboxes on Exchange server, directly from his own email account in Outlook or Outlook Web Access. This proves useful when for example administrator want…

717 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