3

I want to develop an application that works on all three versions of Windows XP, Vista and 7. The application allows people to select files to open and allows them to save the files after some operations. Each of the three versions of Windows has a different style of File open dialog boxes. While XP uses GetOpenFileName with OPENFILENAME structure, it is suggested that we use a "Common File Dialog" with Vista and Windows 7. I can get the file dialog in the suggested style to work for each different version of the OS. However, I would like to make sure that my application opens different styles of dialog box on each version. I do not want to build separate binary for different versions of Windows.

Is it possible to have this logic built-in the application i.e. to allow it to access native open file dialog based on which OS the application is being run.

Thanks,

Abhijit

Abhijit
  • 33
  • 3

1 Answers1

1

You're going to have to do something like

if (isVista())
{
    //Use IFileDialog
}
else
{
    //Use GetOpenFileName
}

Note:

You can't do this if you'll be customizing the dialog; you'll have to use the old version.

Try delay-loading the DLL:

user541686
  • 205,094
  • 128
  • 528
  • 886
  • Thanks @Mehrdad, although I can get this logic to work as the way you have suggested, while linking it looks for Shell32.dll available on Windows 7 i.e. if I have my code block as you suggested and build my application on Windows 7 using Visual Studio 2010, it does not run on Windows XP because the Shell32.dll is a different version. So with this logic, my application unfortunately does not even start :( I had tried what you suggested earlier but it does not solve this problem – Abhijit May 23 '11 at 22:38
  • Take a look at the [/DelayLoad](http://msdn.microsoft.com/en-us/library/yx9zd12s.aspx) flag in your project Properties. – user541686 May 23 '11 at 22:43
  • Thanks a lot @Mehrdad! It worked for me. Can you also clarify why I cannot customize the dialog box. I am just trying to add link to a folder where most users will save the file. Would that be a problem if I try to code it. Just to let you know I did add items to the common place and got it to show up on Windows 7 using Windows 7 native dialog. I have not tried to customize it on Windows XP. Please clarify if you can of what you meant by you earlier comment on customization. Thanks again, I will mark my question as answered. – Abhijit May 23 '11 at 22:59
  • @Abhijit: Glad it helped! By "customizing" I meant that, for example, you can't add a new button to the dialog, if you're using the `IFileDialog` version. Of course, you can do whatever the dialog lets you, and in most cases you don't need something like this. – user541686 May 23 '11 at 23:00
  • Thanks @Mehrdad! I am on my way. – Abhijit May 23 '11 at 23:01