有没有办法让CFileDialog在更改扩展过滤器时自动更改文件名? [英] Is there a way to have the CFileDialog automatically change the filename when changing extension filter ?

查看:134
本文介绍了有没有办法让CFileDialog在更改扩展过滤器时自动更改文件名?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如果我有一个带有多个文件扩展名(过滤器)的CFileDialog,有没有办法让它更改文件名根据所选过滤器更改其扩展名?



如果我有(简化)以下过滤器* .txt; * .xls; *。jpg; * .cpp并且在文件对话框中我有一个默认文件名myfile.txt;当我将过滤器从.txt更改为.jpg时,文件名不会更改为myfile.jpg。



这是支持的功能吗? Vista上的CFileDialog?



我试过像我做的那样(pre-vista)但是新文件对话框不支持旧版本所做的相同功能(即获取编辑控件(GetDlgItem(idt1)或SetControlText(edt1,myString))。



如果我将文件对话框样式更改为使用CFileDialog构造函数的bVistaStyle标志的vista;然后它按预期工作。但不是相反。



我想保留vista样式对话框(也更容易符合Win7 / 8标准)



任何想法?





谢谢。

If I have a CFileDialog with multiple file extensions (filters), is there a way to have it change the filename change its extension depending on the selected filter ?

if I have (simplified) the following filter "*.txt;*.xls;*.jpg;*.cpp" and in the file dialog I have a default file name "myfile.txt"; when I change the filter from ".txt" to ".jpg" the filename does not change to "myfile.jpg".

Is this a supported feature of the CFileDialog on Vista ?

I tried doing like I did (pre-vista) but the new file dialog does not support the same features that the old one did (i.e. getting the edit control (GetDlgItem(idt1) or SetControlText(edt1, myString) ).

If I change the file dialog style to be not vista with the bVistaStyle flag of the CFileDialog constructor; then it's working as expected. but not the other way around.

I'd like to keep the vista style dialogs (also easier to be Win7/8 compliant)

Any Ideas ?


Thanks.

推荐答案

对于您的默认文件名,请不要提供扩展名。而不是myfile.txt只需使用myfile。这样(如果你的过滤器设置正确)适当的扩展当用户按下OK时将应用n。



典型的过滤字符串更像是* .txt \0 * .txt \0 * .xls \0 * .xls\0 * .jpg \ 0 * .jpg \ 0 * .cpp \ 0 * .cpp \ 0 \ 0



希望有所帮助。
For your default file name, don't supply an extension. Instead of "myfile.txt" simply use "myfile". This way (if your filter is set up correctly) the proper extension will be applied when the user presses OK.

A typical filter string would be more like "*.txt\0*.txt\0*.xls\0*.xls\0*.jpg\0*.jpg\0*.cpp\0*.cpp\0\0"

Hope that helps.


这篇关于有没有办法让CFileDialog在更改扩展过滤器时自动更改文件名?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆