2015-03-13 117 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