Posts for category 'Software'

Vista style file dialogs in .Net

Vista style file dialog

Microsoft Windows Vista has brand new common file dialogs, but unfortunately the OpenFileDialog, SaveFileDialog and FolderBrowserDialog classes from System.Windows.Forms do not use them; they still get the old-style dialogs.

Ookii.VistaDialogs is a .Net 2.0 class library that allows you to use these new-style dialogs exactly the same way as you use the normal dialogs. In addition, it has been created in such a way that you can target both Vista and older versions of Windows (which don't have this new-style dialog) without any additional effort on your part.

The curious might want to know why exactly .Net doesn't use the new style dialogs. Vista provides a new, more powerful, API for accessing the common file dialogs, and obviously .Net 2.0 doesn't use this API, but this isn't the problem. In most cases, even when you just use the old GetOpenFileName API you get the new style dialog. The thing is, the Vista style dialogs do not support hooks, so if you use a hook, you get the old style dialog. And that's where the problem lies: .Net uses a hook so it can't use the Vista style dialogs.

Unfortunately, some of the functionality provided by .Net's FileDialog classes could only be achieved using hooks with the old API, so if I wanted to use the Vista style dialogs, I'd have to use the new API, and try to replicate all the functionality that way. The benefit to this is of course that if I want to, I can easily add more advanced functionality from the new API in the future (currently, Ookii.VistaDialogs just replicates the old functionality with the new dialogs, it doesn't expose any of the new features of the new API).

Using the new API seemed simple enough; it was after all a bunch of COM objects. Unfortunately, there was no type library for these objects, and their IDL definitions were hidden in a huge (60,000 lines) IDL file. Also, one of the functions took a HWND as parameter, which would need to be a IntPtr in my library to make sure I can correctly support both x86 and x64, and I needed some methods to use the PreserveSig attribute to get the functionality I need. TlbImp isn't good at those last two.

So what I ended up doing was creating my own IDL file with just those definitions from the big file I needed, compiling that into a type library with the MIDL compiler, then importing that using TlbImp, disassembling the generated interop library with Reflector, and then manually making the changes I needed.

Then, I could finally start on the classes themself, which fortunately wasn't all that difficult (the new API really is great). These classes have the exact same public interface as the original FileDialog classes in .Net, so all you need to do is replace all instances of the original classes with my classes in your code, and you're good to go. Like I said the classes fall back if the Vista style dialog is not supported, so it supports older versions of Windows as well.

Check it out

Categories: Software
Posted on: 2006-09-19 15:25 UTC. Show comments (1)

New download: Find As You Type

I'm proud to announce a brand new download on Find As You Type for Internet Explorer.

Find As You Type provides "interactive search" capabilities similar to Firefox and Emacs, but for Internet Explorer. It works on Internet Explorer 5 and higher (including IE7, of course). It'll work on x86 and x64 versions of Windows.

This has been my first venture into creating an IE add-on, and also the first big unmanaged C++ Win32 project I've done in a long while. Although MS is keen to emphasise that IE, like Firefox, can indeed be extended (and not just for spyware either!), but it's difficult, very difficult.

Over the next few days I intend to make a few blog posts documenting some of the pitfalls I've encountered. In particular I'll cover those issues that are not only under-documented on MSDN, but whose answer can't be easily found using a Google search.

The following is a list of these articles. I will add links as more articles become available.

Categories: Software
Posted on: 2006-08-30 20:36 UTC. Show comments (3)

Latest posts




RSS Subscribe