-1

I'm trying to open a file via the default open button in menu in a MFC project in visual studio 2013. I have used a browse button and I'v used "OnBnClickedButton" function to get the address of opened file but now there is no such function. what should I do?

AmirAhmad
  • 153
  • 3
  • 12

2 Answers2

2

A default MFC application (SDI or MDI) created by the wizard does not have a private implementation of the Open (or Save) code, it will call the default framework code (see ScottMcP-MVP answer)

Normally, you should add an handler for the ID_FILE_OPEN in your application to call CFileDialog and handle the file yourself.

CFileDialog is better used as a modal dialog

CFileDialog dlg(TRUE); // TRUE is to tell the dialog is used as an open CFileDialog.
if ( dlg.DoModal() == IDOK )
{
  CString fullPathName = dlg.GetPathName(); // get the full path name of the selected file.
  //... add some of your own code to open the file and read it.
}
Max
  • 3,128
  • 1
  • 24
  • 24
1

See the MSDN page for CWinApp::OnFileOpen

ScottMcP-MVP
  • 10,337
  • 2
  • 15
  • 15