Search code examples
c++visual-studio-2013mfcfileopendialog

open dialog in MFC C++


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?


Solution

  • 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.
    }