-1

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

4

2 回答 2

2

由向导创建的默认 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.
}
于 2015-03-13T17:58:56.323 回答
1

请参阅 CWinApp::OnFileOpen 的 MSDN 页面

于 2015-03-13T17:56:57.300 回答