Solved

CWinApp::OnFileOpen();

Posted on 2001-09-06
8
1,423 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
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
Announcing the Most Valuable Experts of 2016

MVEs are more concerned with the satisfaction of those they help than with the considerable points they can earn. They are the types of people you feel privileged to call colleagues. Join us in honoring this amazing group of Experts.

 
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

Announcing the Most Valuable Experts of 2016

MVEs are more concerned with the satisfaction of those they help than with the considerable points they can earn. They are the types of people you feel privileged to call colleagues. Join us in honoring this amazing group of Experts.

Question has a verified solution.

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

Suggested Solutions

Introduction: The undo support, implementing a stack. Continuing from the eigth article about sudoku.   We need a mechanism to keep track of the digits entered so as to implement an undo mechanism.  This should be a ‘Last In First Out’ collec…
If you use Adobe Reader X it is possible you can't open OLE PDF documents in the standard. The reason is the 'save box mode' in adobe reader X. Many people think the protected Mode of adobe reader x is only to stop the write access. But this fe…
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.
I've attached the XLSM Excel spreadsheet I used in the video and also text files containing the macros used below. https://filedb.experts-exchange.com/incoming/2017/03_w12/1151775/Permutations.txt https://filedb.experts-exchange.com/incoming/201…

828 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