2015-03-13 113 views
-1

我想通过Visual Studio 2013中的MFC项目菜单中的默认打开按钮来打开文件。我使用了浏览按钮,并且使用了“OnBnClickedButton”函数来获取打开的文件的地址,但现在没有这样的功能。 我该怎么办?MFC中的打开对话框C++

回答

1

向导创建没有打开(或保存)代码的私有实现一个默认的MFC应用程序(SDI或MDI),它会调用默认框架代码(请参阅ScottMcP-MVP答案)

通常,应该在应用程序中为ID_FILE_OPEN添加一个处理程序来调用CFileDialog并自己处理该文件。

的CFileDialog是一个模式对话框

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. 
} 
更好地利用
1

请参阅MSDN页的CWinApp :: OnFileOpen