开发者

CFileDialog - Selected filter and "Hint" showing all files

开发者 https://www.devze.com 2022-12-24 09:56 出处:网络
I have CFileDialog and set filter for it (Text files *.txt). When it opens, I see only TXT files, thats right. But! w开发者_JS百科hen I\'m typing text into filename, the hint (under filename field) is

I have CFileDialog and set filter for it (Text files *.txt).

When it opens, I see only TXT files, thats right. But! w开发者_JS百科hen I'm typing text into filename, the hint (under filename field) is showing all files (files with any extension).

Can be this behavior changed by some flag? I want force hint to show only TXT files.

...
CFileDialog f(TRUE,NULL,NULL,OFN_HIDEREADONLY|OFN_NOCHANGEDIR,_T("Text files (*.txt)|*.txt|All files (*.*)|*.*||"));
if( f.DoModal() != IDOK ) return;
...


My experience with this is that the file filter will control what is shown in the list of files, but when you type the auto-complete is matching against everything in the current directory. I can't think of a good way to prove that it can't be done, but I haven't seen anything in the MFC docs or code that would let you do that.

You can subclass the CFileDialog and override the CFileDialog::OnFileNameOK() function to reject the entry of any file name that doesn't match your criteria. you might also be able to get the functionality you want by overriding CFileDialog::OnFileNameChange() to reject a user supplied file name before they click the Open (or Save) button, but I have not done that myself to know exactly how it would work out.

0

精彩评论

暂无评论...
验证码 换一张
取 消