Register a thumbnail handler for a folder, rather than a specific file type

1.1k views Asked by At

I need to write a thumbnail handler for all the files under a given folder. This folder is a mounting point for a virtual file system (using Callback File System), and the files are actually not present physically on the local machine (they're stored in the cloud), so if I let the default thumbnail handler do its work, it will try to download the whole files from the server... which is obviously not what I want.

But now I just realized that a thumbnail handler must be registered per file type:

Registration of a thumbnail handler is based on standard file associations.

(from the documentation)

I don't want to register it per file type, because I don't want to change the behavior for files that are not in my virtual folder. Is there a way for my handler to be called for all the files in my virtual folder, and only them?

1

There are 1 answers

9
Werner Henze On BEST ANSWER

I see two ways for you to go.

The simple way: Register your own thumbnail handler and let it work on all files. When you don't support IInitializeWithStream but only IInitializeWithItem or IInitializeWithFile you can check if the item/file is in your virtual file system. If so you can return a thumbnail and otherwise return an error.

The problem with this approach is that only one thumbnail provider can be registered per file type.

The hard way: You can write a shell namespace extension. These can be used to display virtual folders, which can be customized in many ways. This is another way to do what you already did using cbfs, but it is restricted to Explorer only. It would add another way to display your virtual folders.

The shell namespace extension will only work for it's own virtual folder. If you mapped your virtual folders to a drive letter and the user opens that drive in Explorer (and not the shell namespace extension's virtual folder), the user would see regular Explorer view of the files, not your shell namespace extension.

Also: Documentation for shell namespace extensions is a pain, there is not much available. I wrote my own shell namespace extension and every time my objects where queried for an IID I traced that and learned a bit more. I saw that my extension is queried for IID_IThumbnailHandlerFactory, I also saw IIDs like IID_IExtractIconA or IID_IContextMenu, but I did not see IID_IThumbnailProvider, nor did I see IID_IExtractImage. This suggests that you cannot have your own IThumbnailProvider directly attached to the objects you create for the virtual folder, but it could also be that I just missed to set some flag somewhere else so that Explorer does not even try to query me.