请问怎么在“打开”和“另存为”对话框中加入文件过滤器?
本人只在文档类中使用了Serialize()函数来实现文件的打开和保存,而没有显式地使用CFileDialog类,但是默认的“打开”和“另存为”对话框中是没有文件过滤的,请问高手如何在其中加入文件类型过滤?谢谢。
[解决办法]
先关联Serialize与CFileDialog 以下代码已调试通过
保存如下:
OnFileSave()
{
//设置默认文件路径与文件名强制指定后缀名
CFileDialog dlg( FALSE, _T( ".qeq "), _T( "电路 "), OFN_HIDEREADONLY|OFN_OVERWRITEPROMPT,
" Files(*.qeq)|*.qeq|| " );
if (IDOK==dlg.DoModal())
{
CString filepathname;
filepathname = dlg.GetPathName();
if (filepathname.Right(4)!= ".qeq ")
{
filepathname = filepathname+ ".qeq ";
}
//AfxMessageBox(filepathname);
int mPos1 = 0;
int mPos2 = 0;
mPos1 = filepathname.Find( "\\ ",mPos1);
mPos2 = filepathname.Find( ". ",mPos2);
theApp.strSavepath = filepathname.Left(mPos2);
theApp.strCirname = filepathname.Mid(mPos1+1,mPos2-mPos1-1);
//AfxMessageBox(theApp.strCirname);
//AfxMessageBox(theApp.strSavepath);
//AfxMessageBox( "break1 ");
CFile theFile;
theFile.Open( filepathname,CFile::modeWrite|CFile::modeCreate);
CArchive ar(&theFile, CArchive::store);
//AfxMessageBox( "break2 ");
}
打开情况:
OnFileOpen()
{
CString filepathname;
//指定默认文件名过滤文件
CFileDialog dlg(TRUE,_T( ".qeq "),_T( "电路 "),
OFN_HIDEREADONLY|OFN_OVERWRITEPROMPT,
_T( "File(*.qeq)|*.qeq|| "));
if (IDOK == dlg.DoModal())
{
filepathname = dlg.GetPathName();
CFile theFile;
theFile.Open( filepathname,CFile::modeRead);
CArchive ar(&theFile, CArchive::load);
}