MFC选择文件并保存到当前路径

时间:2021-07-07 07:12:36
char CurrentDirectory[MAX_PATH]; 
CString fileName = "*.obj"; //默认打开的文件名
CString FilePathName;
CString Directory;
CString SaveFileName;
int ret = GetCurrentDirectory(MAX_PATH,CurrentDirectory);
Directory.Format(_T("%s"),CurrentDirectory);
SaveFileName = Directory + _T("\\test.obj");
CString filter = "文件 (*.obj)|*.obj||"; //文件过虑的类型
CFileDialog openFileDlg(TRUE, NULL, fileName, OFN_HIDEREADONLY|OFN_READONLY, filter, NULL);
if(openFileDlg.DoModal()==IDOK)
{
FilePathName = openFileDlg.GetPathName(); //文件名保存在了FilePathName里
CopyFile(FilePathName, SaveFileName ,FALSE);
}
else
{
return;
}