【框架-MFC】关于CFileDialog保存文件获取扩展名(后缀名)
2016-11-07 15:49
387 查看
方法1、通过CFileDialog.m_ofn.nFilterIndex过滤器编号来区分当前选择的扩展名
CFileDialog fileDialog(FALSE, NULL,NULL,OFN_HIDEREADONLY|OFN_OVERWRITEPROMPT,\_T("DataFile(*.tif)|*.tif|Data File(*.sct)|*.sct||"),this);
if(fileDialog.DoModal()==IDOK)
{
if (fileDialog.m_ofn.nFilterIndex == 1)
{
//tif
}
else if (fileDialog.m_ofn.nFilterIndex == 2)
{
//sct
}
}
方法2、通过GetSaveFileName函数,追加扩展名,第二个参数不能为NULL,可以是L""
CFileDialog fileDialog(FALSE,L"",NULL,OFN_HIDEREADONLY|OFN_OVERWRITEPROMPT,\_T("DataFile(*.tif)|*.tif|Data File(*.sct)|*.sct||"),this);
if(fileDialog.DoModal()==IDOK)
{
GetSaveFileName(&fileDialog.m_ofn);
//获取扩展名,没有‘.’
fileDialog.GetFileExt();
}
方法3、重写CFileDialog 中的OnInitDialog和OnTypeChange函数
BOOL CFileDialogEx::OnInitDialog(){
CFileDialog::OnInitDialog();
SetDefExt("tif");
returnTRUE; // return TRUE unless you set thefocus to a control
}
void CFileDialogEx::OnTypeChange()
{
intn=m_ofn.nFilterIndex;
if(n==1)
{
SetDefExt(("tif"));
}
elseif (n==2)
{
SetDefExt(("sct"));
}
CFileDialog::OnTypeChange();
}
CFileDialogEx fileDialog(FALSE,L"",NULL,OFN_HIDEREADONLY|OFN_OVERWRITEPROMPT,\
_T("DataFile(*.tif)|*.tif|Data File(*.sct)|*.sct||"),this);
if(fileDialog.DoModal()==IDOK)
{
//获取扩展名,没有‘.’
fileDialog.GetFileExt();
}
相关文章推荐
- MFC之CFileDialog文件保存扩展名问题 解决办法
- MFC之CFileDialog文件保存扩展名问题
- MFC之CFileDialog文件保存扩展名问题
- MFC打开/保存文件对话框:CFileDialog
- MFC学习(20)MFC打开/保存文件对话框——CFileDialog之一
- MFC 打开保存对话框 获取保存文件路径 {无错版} vs 2010
- MFC 对话框 关于exe文件绝对路径的获取,截获。
- MFC浏览文件夹,浏览保存文件, 获取当前路径
- MFC学习(21)MFC打开/保存文件对话框——CFileDialog之二
- MFC打开/保存文件对话框:CFileDialog
- MFC打开/保存文件对话框:CFileDialog
- MFC打开/保存文件对话框:CFileDialog
- 关于可扩展的web架构设计的探索-框架结构的描述文件
- MFC如何用CFileDialog来打开和保存文件
- MFC中CFileDialog打开和保存文件对话框
- MFC 浏览文件夹,浏览保存文件, 获取当前路径
- MFC打开/保存文件对话框:CFileDialog
- 关于可扩展的web架构设计的探索-框架结构的描述文件
- MFC打开/保存文件对话框:CFileDialog
- MFC打开/保存文件对话框:CFileDialog