views:

175

answers:

1

I have CFileDialog and set filter for it (Text files *.txt).
When it opens, I see only TXT files, thats right. But! when 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;
...
A: 

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.

Al Crowley