CFileDialog保存文件问题
CFileDialog*pFileDlg=newCFileDialog(FALSE,//TRUEforopen,FALSEforsaveasNULL,//defaultf...
CFileDialog *pFileDlg=new CFileDialog(FALSE, //TRUE for open , FALSE for save as
NULL, //default file_extension_name
NULL, //default filename
OFN_HIDEREADONLY | OFN_OVERWRITEPROMPT,
"MORPAS数据 (*.HD)| *.HD|ASCII栅格数据 (*.grd)| *.grd|Binary栅格数据 (*.grd)| *.grd|(ASCII)XYZ数据 (*.dat)| *.dat||", //File filters
NULL);
pFileDlg->m_ofn.lpstrTitle="保存数据文件";
pFileDlg->m_ofn.nFilterIndex=FDType;
char cf[256];
int i,j;
double xyz[6];
sprintf(cf,"%s",m_strTitle);
pFileDlg->m_ofn.lpstrFile=cf;
if(pFileDlg->DoModal()!=IDOK)
{
delete pFileDlg;
return;
}
CString PathName,FileExt,str;
FileExt=pFileDlg->GetFileExt();
PathName=pFileDlg->GetFileName();
FDType=pFileDlg->m_ofn.nFilterIndex;
大家帮忙看看为什么加上pFileDlg->m_ofn.lpstrFile=cf;这句后
FileExt=pFileDlg->GetFileExt();
PathName=pFileDlg->GetFileName();这两句就出错
但是任务要求必须有一个默认的文件名,那一句又少不了~~ 展开
NULL, //default file_extension_name
NULL, //default filename
OFN_HIDEREADONLY | OFN_OVERWRITEPROMPT,
"MORPAS数据 (*.HD)| *.HD|ASCII栅格数据 (*.grd)| *.grd|Binary栅格数据 (*.grd)| *.grd|(ASCII)XYZ数据 (*.dat)| *.dat||", //File filters
NULL);
pFileDlg->m_ofn.lpstrTitle="保存数据文件";
pFileDlg->m_ofn.nFilterIndex=FDType;
char cf[256];
int i,j;
double xyz[6];
sprintf(cf,"%s",m_strTitle);
pFileDlg->m_ofn.lpstrFile=cf;
if(pFileDlg->DoModal()!=IDOK)
{
delete pFileDlg;
return;
}
CString PathName,FileExt,str;
FileExt=pFileDlg->GetFileExt();
PathName=pFileDlg->GetFileName();
FDType=pFileDlg->m_ofn.nFilterIndex;
大家帮忙看看为什么加上pFileDlg->m_ofn.lpstrFile=cf;这句后
FileExt=pFileDlg->GetFileExt();
PathName=pFileDlg->GetFileName();这两句就出错
但是任务要求必须有一个默认的文件名,那一句又少不了~~ 展开
1个回答
展开全部
在 pFileDlg->m_ofn.lpstrFile=cf; 前加上下面这句话:
pFileDlg->m_ofn.nMaxFile = 256;
运行通过
原因如下:
MSDN中关于CFileDialog有以下原文:
Do this by replacing m_ofn.lpstrFile with a pointer to a buffer you have allocated, after constructing the CFileDialog, but before calling DoModal. Additionally, you must set m_ofn.nMaxFile with the number of characters in the buffer pointed to by m_ofn.lpstrFile.
大意就是要指定nMaxFile值,否则你在按下保存后
pFileDlg变为NULL了(与API的内部实现方式有关)
pFileDlg->m_ofn.nMaxFile = 256;
运行通过
原因如下:
MSDN中关于CFileDialog有以下原文:
Do this by replacing m_ofn.lpstrFile with a pointer to a buffer you have allocated, after constructing the CFileDialog, but before calling DoModal. Additionally, you must set m_ofn.nMaxFile with the number of characters in the buffer pointed to by m_ofn.lpstrFile.
大意就是要指定nMaxFile值,否则你在按下保存后
pFileDlg变为NULL了(与API的内部实现方式有关)
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询