CString strCurrentPath; //用于设置默认打开为软件根目录
GetCurrentDirectory(200,strCurrentPath.GetBuffer(200));
strCurrentPath.ReleaseBuffer();
CFileDialog dlg(TRUE);//TRUE为OPEN对话框,FALSE为SAVE AS对话框
dlg.m_ofn.lpstrInitialDir=strCurrentPath; //用于设置对话框的默认目录为strCurrentPath
if(dlg.DoModal()==IDOK)
{
FileName=dlg.GetFileName();
FILE* fp=fopen(FileName,"r"); //只读方式
Read(fp); //读取文本fgets()、fscanf()
fclose(fp);
}
CFileDialog dlg(FALSE);//TRUE为OPEN对话框,FALSE为SAVE AS对话框
dlg.m_ofn.lpstrInitialDir=strCurrentPath; //用于设置对话框的默认目录为strCurrentPath
if(dlg.DoModal()==IDOK)
{
FileName=dlg.GetFileName();
FILE* fp=fopen(FileName,"w"); //只写方式
write(fp); //写入文本fprintf
fclose(fp);
}