Link to home
Start Free TrialLog in
Avatar of mco
mco

asked on

In CFileDialog file name appears without extension

The following constructor:
CFileDialog d(FALSE, NULL, "bb.txt", NULL);
causes the file dialog to appear with "bb" as the file name (although pressing 'Save' and GetPathName , retrieve the full name with the extension).
This may cause confusion to the user.

I found out that this is happens because only when the "hide file extension for known file types" bit is checked in the folder options settings of the Windows Explorer.


Question: How can I force the file name to appear with the extension, regardless of the folder options settings the user chose for his/her environment?
Avatar of Vinayak Kumbar
Vinayak Kumbar

Hi,

If I am getting ur problem correctly, when u execute ur code, the 'File Name' will have just bb. And that may cause user confusion. So u want to display it as bb.txt. right?

For that there is a work around. Usually we will set the filter to the CFileDialog object and hence the file type will be displayed in the 'Save as type' field. Then that will specify to the user that, file will be saved in text format. To do that, use the following code:

static char BASED_CODE szFilt[] = "File (*.txt)|*.txt||";
     CFileDialog dlg(FALSE, NULL,"bb.txt",NULL, szFilt);
     dlg.DoModal();

Try it out.
VinExpert
Hi,

If u want to do it programatically, then u need to set the values of some registry keys which depends on the OS. Say for example for Win-98

HKEY_CURRENT_USER\\SOFTWARE\\Microsoft\\Windows\\CurrentVersion\\Explorer\\Advanced

and

HKEY_LOCAL_MACHINE\\SOFTWARE\\Microsoft\\Windows\\CurrentVersion\\Explorer\\Advanced

value should be set to 0(zero) to disable that and should be set to 1 to enable it.

This will be different key for NT ofcourse!!!
But, I dont suggest this method as it is complex and changes some global settings.

Try it out.
VinExpert
Avatar of mco

ASKER

Regarding the first comment, I do not have a filter and do not want to put one in. The ".txt" in the code was only an example.
Regarding the second comment, not only is it complex and OS dependent, it is dangerous as you can change the users settings.

Is this problem considered a bug by MS at all?
Hi,

Yes, thats why I expicitly told that, I wont suggest second method.

I guess MS thinks it as feature rather than a bug!!!

VinExpert
ASKER CERTIFIED SOLUTION
Avatar of DanRollins
DanRollins
Flag of United States of America image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
hi mco,
Do you have any additional questions?  Do any comments need clarification?  Does it matter to you that I spent a lot of time working on this?

-- Dan
Avatar of mco

ASKER

Dear Dan,
I appreciate very much your reply. Just today I saw both it and this last comment. Due to unexpected personal reasons I am not at my computer often, and have not gone back to my programming.
I assure you that I will check out your suggestion, and if it works, you will be fully awarded.
I apologize, but it may take some time yet, till I get back to work.