简体   繁体   中英

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?

请参阅MSDN页面上的CWinApp :: OnFileOpen

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM