//打开单文件
void COpenSaveFileDialogDlg::OnBnClickedButtonOpen()
{
BOOL isOpen = TRUE; //是否打开(否则为保存)
CString defaultDir = L"E:\\FileTest"; //默认打开的文件路径
CString fileName = L""; //默认打开的文件名
CString filter = L"文件 (*.doc; *.ppt; *.xls)|*.doc;*.ppt;*.xls||"; //文件过虑的类型
CFileDialog openFileDlg(isOpen, defaultDir, fileName, OFN_HIDEREADONLY | OFN_READONLY, filter, NULL);
openFileDlg.GetOFN().lpstrInitialDir = L"E:\\FileTest\\test.doc";
INT_PTR result = openFileDlg.DoModal();
CString filePath = defaultDir + "\\test.doc";
if (result = = IDOK) {
filePath = openFileDlg.GetPathName();
}
CWnd::SetDlgItemTextW(IDC_EDIT_SRC, filePath);
}
//保存文件
void COpenSaveFileDialogDlg::OnBnClickedB
MFC--打开保存文件操作
![](https://img-home.csdnimg.cn/images/20240711042549.png)