PDC05: Day Four (Extending Explorer by Providing Metadata, Rich Previews and Thumbnails for Your File Types)
I headed to Marc Miller's (blog) presentation "Windows Vista: Extending Explorer by Providing Metadata, Rich Previews and Thumbnails for Your File Types." It went over precisely the same code I had just been working in the instructor lead lab, but in significantly greater depth. It detailed how the property handlers system works including more information about PROPERTYKEYs and the PROPVARIANT structure. The PROPVARIANT is effectively the same as VARIANT, but with the addtion of new types like 'vector' and 'wide character string."
I am getting a little ahead of myself. Under the Windows Vista API there are now three elements to a file's metadata:
- Properties
These are simple elements which the user can view, and hopefully change. Examples would include author, description, ratings, etc. If you are going to implement a special property handler, then try to add write support so new interface elements (like ratings) can be supported.
- Thumbnails (also called LiveIcons)
This is not your 32x32 bitmap, but a scalable version of the file's content. DeLorme, for instance, would show a copy of the last map the user looked at.
- Previews
This should show more detailed information from inside the file. The Outlook 'Reading Pane' would be a place this would be rendered.
To read, and hopefully write, properties implement the IPropertyStore method. Miller was quite strong in recommending that people who write properties should also implement the IInitializeWithStream interface. This latter interface is super hot, at least to anyone who has worked with structured storage during a fault. When a developer writes directly to a structured storage (IStorage/IStream), they are effectively streaming binary out to a file. When a fault occurs (network goes down, out of space, application implodes, user removes their USB drive) the file is partly written. Since the file is binary and since many developers fail to handle the host of possible errors, serious and unexepected problems may result. I have seen a missing error handler result in a structured storage which crashes an appplication at startup. That is no fun. The new IInitializeWithStream resolves this problem by proving a stream which implements atomic writes. As you write out to the stream, it is actually writing to a temp file. When the stream is closed it replaces the original with the temp file in a single copy action.
The thumbnails are the most interesting feature for most developers. The view should scale from a tiny image, like you might see in details, to a nearly full size image which fills the explorer view. The handler would implement IThumbnailProvider to offer out thumbnails for a file. Most of the examples we see now are simple photographs, resulting in thumbnails which are indistinguishable from the original photo thumbnail. Miller went to great pains to assure us that Microsoft will be decorating these thumbnails we generate with borders and a copy of the file icon in a corner of the bitmap. This shell in the present Windows Vista build does not contain this decoration. If we also try to decorate the file, then by the time Windows Vista is released, our decorationg will be conflicting with Microsoft's.
The previews are provided via the IPreviewProvider interface. The implementer is given a window handle and the window rectangle to draw inside. Most of the demonstration code uses this to render into a richtext area which fills that region, but other options are possible. This area is not intended to be interactive.
During the question and answer period there was some discussion about the process model for these providers. Miller indicated that it was hard to isolate the process due to the chatty nature of the interface. Marshalling those calls across process boundaries would become quite expensive. I pushed on that answer a bit by asking if this was just a nice vector for virus and spyware injection, particularly considering it is being written in unmanaged code. There was no immediate answer, but when I sat back down the fellow beside my said, "Good question." I thought it was just another developer, but it turned out to by Chris Guzak. He told me that they had been able to resolve the process model issue recently, but no one told Marc Miller about it. I was really glad to hear it. I offered to try and beta the change when they had a build with it enabled.
As you can tell from the length of this post, this is probably one of my favorite new Windows Vista features. I like it far more than Sidebar. For the record, Mark, I appreciate your suffering for me!
1 Comments:
Thanks for the writeup Christian. I still remember your question, it took me a little off-guard and so I wasn't able to give you the best concise answer, but I'm glad Chris was able to help clarify. (Though I'm still not sure what he told you that would satisfy all the concerns that you voiced...)
Post a Comment
Links to this post:
Create a Link
<< Home