Building a recipe application using Vista and .NET 3.0 (Part IV: ThumbnailProvider interface)

ThumbnailProvider interface

The ThumbnailProvider interface is new to Windows Vista and enables thumbnails to show up in a beautiful 32-bit color, 256 x 256 pixel resolution. This sample’s ThumbnailProvider implementation, doesn’t show much above and beyond what Mike Taulty’s blog showed with the exception of:

- Support for images pulled from the internet or local file system, absolute or relative.

- Debugging support, using DbMon.exe (comes with Windows SDK). Debugging becomes invaluable in a ThumbnailProvider when the XML happens to be invalid or a something else goes wrong when the shell calls out to the implementation. ThumbnailProviders load up out-of-process, so sometimes it’s tricky to debug the application via Visual Studio. As a result it’s very handy to use DbMon.exe for most debugging. The best thing about sending debugging messages to DbMon is that the application works identically whether DbMon is running or not, and no recompile is necessary. Find DBMon.exe in: “\program files\microsoft sdks\Windows\v6.0\Bin”.

- How to pull an image from a resource.

- And lastly it’s a bit more useful, but not much ;)


File location issue with ThumbnailProvider

It is recommended that the Thumbnail Provider be implemented using the IInitializeWithStream interface to load the stream. This issue is that the stream that is handed to us does not know where the file was loaded from, so we cannot calculate relative paths to any supporting files or images. As a workaround, the application must make some assumptions about where content resides; in this specific case, where the Thumbnail images reside. So I added a line of code that assumes that there is a “Recipe” folder in the users profile and gets images relative to that. Alternately, the images can be encoded and embedded in the XML itself.


Installing the ThumbnailProvider

1. Download the zip file (202kb) and unzip to the desktop (preferably outside of your user profile if you want it available machine-wide) i.e “c:\demos\ECBThumbnailProvider” will work nicely.

2. Compile the project with Visual Studio or MSBuild. (I provided a compiled debug version that works with RTM .NET 3.0 bits.)

3. You *must* edit the install.cmd file to reflect the path of the folder you placed the project in (unless you used the path I defined above.)

4. Run Install.cmd as Administrator.

5. Move the “Recipe” folder located in the project into your “c:\users\%your username%” folder. i.e.“C:\users\hanshu”

6. The “Thumbnails” should appear as in Fig. 2. If they do not, you may need to modify the contents of the file by changing a single character in the file and saving to trigger a file change to force a redraw.


       Fig. 2 – Screenshot of an example recipe folder


In the next installment, I'll talk about Windows search and how to make the contents of the Electronic Cookbook files searchable.