Problems with File Extensions in Vista Save As dialog RRS feed

  • Question

  • Hey,


    I am attempting to make the Vista Save As dialog work the same way the XP version of Save As works in my application.  I am interacting with the Vista Save As dialog partly through CFileDialog (Visual Studio "Orcas") and partly through the interfaces.    The problem I am having at the moment has to do with changing the extension associated with the file to be saved when the user changes the file type via the "Save as type" drop down list.


    In the XP Save As dialog, when the user changed the Save As type, my code would completely handle grabbing the current filename and replacing the extension with one appropriate for the new type.  I implemented that for Vista using IFileDialog::GetFileName and SetFileName, and it pretty much works, with one annoying UI quirk:  The text I put into the "File name:" box is left "selected" even though the "File name:" box does not have the focus.  That makes me (and users) think that the "File name:" box has focus, even though the "Save as type:" drop down is what really has focus.  So I start typing to change the file name and the "Save as type" changes.  Seems like a bug to me.


    Dissatisfied with that UI quirk, I read some more and learned that if I call IFileDialog.SetDefaultExtension with a non-empty default extension, the Vista Save As dialog takes over responsibility for changing the extension when the user changes file type.  It turns out that this sort of almost works.  It works pretty well if the "Hide extensions for known file types" box in Explorer folder options is *unchecked*.  If that box is checked (which I believe is Vista's default setting), however, it completely falls apart.  Suppose you are trying to save "foo.xyz" as "foo.abc", for example.  Save As comes up with "foo" as the suggested filename and "XYZ File" as the Save As type.  You change the Save As type to "ABC Files" and click Save.  You are now prompted as follows by the Vista Save As dialog:  "foo.xyz already exists.  Do you want to replace it?"  Huh?  I am trying to save foo.abc, not foo.xyz.  And the filename returned in the lpstrFile member of OPENFILENAME is "foo.xyz", not "foo.abc" (same for IFileDialog::GetResult()).  So the Vista Save As dialog's programmatic interface behaves completely differently based on a View setting for whether extensions are displayed.  Nice.


    So I guess I go back to taking care of the extension myself and living with the UI bug, unless anyone has suggestions.






    Thursday, August 23, 2007 1:15 PM

All replies

  • Any progress on this issue? I'm encountering the exact same problem.

    Tuesday, September 22, 2009 6:27 PM

  • I have tried to get around the issue of the selected text by getting the foreground window and iterating the child windows until I get to the filename component. Then I send the component a CB_SETEDITSEL message to clear the selection. It appears to work, but it's not exactly an ideal solution.
    Tuesday, September 22, 2009 6:33 PM
  • Law001 - you wouldn't want to maybe post your code that searches for the right window and sends CB_SETEDITSEL, would you?  Might save me some time.



    Thursday, September 29, 2011 2:07 PM