请问怎么在“打开”和“另存为”对话框中加入文件过滤器? 本人只在文档类中使用了Serialize()函数来实现文件的打开和保存,而没有显式地使用CFileDialog类,但是默认的“打开”和“另存为”对话框中是没有文件过滤的,请问高手如何在其中加入文件类型过滤?谢谢。 解决方案 » 免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货 ============================================CString csFilter;csFilter = "MIDI 文件(*.mid;*.midi)|*.mid;*.midi|所有文件(*.*)|*.*||";CFileDialog fd(FALSE,NULL,NULL,OFN_HIDEREADONLY | OFN_OVERWRITEPROMPT,csFilter,NULL);fd.Domodal();============================================ static BASED_CODE char szFilter[] = "... ||"; 先关联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); } MFC 单文档自定义标题问题 第一次写小游戏,遇到了一些技术细节问题,输不出图形出来,倾全力100分寻找解决方法 如何判断一个文件是否是ZIP格式的文件? listctrl 空值问题... 书上的题目:数组下标(?)怎么理解 关于URLDownloadToFile成功、失败的问题 Group box的问题 CString的问题,急 MSXML加载XML如何过滤注释节点 高分请教:ADO调用存储过程,参数传递顺序导致数据类型转换错误 建立socket通讯中的问题 子窗口获得焦点的问题,搞不清楚了
============================================CString csFilter;csFilter = "MIDI 文件(*.mid;*.midi)|*.mid;*.midi|所有文件(*.*)|*.*||";CFileDialog fd(FALSE,NULL,NULL,OFN_HIDEREADONLY | OFN_OVERWRITEPROMPT,csFilter,NULL);fd.Domodal();============================================
static BASED_CODE char szFilter[] = "... ||";
保存如下:
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);
}