开发者

Native File Open/Save Dialog (without Windows Forms or WPF)

开发者 https://www.devze.com 2023-03-14 04:42 出处:网络
How t开发者_运维问答o import and use native Open file dialog? Does I have any benefits of it in application that not use Windows Forms nor WPF? Or just reference it?The standard file dialogs offered b

How t开发者_运维问答o import and use native Open file dialog? Does I have any benefits of it in application that not use Windows Forms nor WPF? Or just reference it?


The standard file dialogs offered by WinForms and WPF are merely wrappers around the native dialogs. So it makes most sense to use these managed C# classes.

If you wish to customise the dialogs in any way (e.g. adding controls to the dialog) then there may be a case for using the native API. But that's mainly because you need to use a different customisation technique for XP from that used for Vista/7. Even in pure native code, customising file dialogs is non-trivial and you should really avoid doing it if you reasonably can.


There are wrappers for the common dialogs in the Windows API Code Pack. Some versions of Windows Forms and WPF, released before Vista, used some parameters when constructing the dialogs that caused Vista (or Windows 7) to say "oh, you know what you want, I won't give you the all-singing all-dancing new versions of the dialogs." Since then there have been service packs, new releases etc that took care of that. If for some reason you can't get the right dialogs, start by installing any service packs for whatever version of Visual Studio you're using. If you still get no satisfaction, try the Code Pack.


This is a matter of what you're doing with your application. If it's written using Windows Forms, use System.Windows.Forms.OpenFileDialog; if it's written using WPF see here: OpenDialog for WPF if for some peculiar reason you must go against the Win32 api, go ahead and read up on GetOpenFileName here: http://msdn.microsoft.com/en-us/library/ms646927%28v=vs.85%29.aspx

0

精彩评论

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

关注公众号