5.1 How Icon Handlers Work

only for RuBoard - do not distribute or recompile

5.1 How Icon Handlers Work

Icon handlers are required to implement two interfaces: IPersistFile and IExtractIcon . These interfaces are interesting from a programmatic standpoint for several reasons. IPersistFile is not directly derived from IUnknown ; it's derived from IPersist . And as luck would have it, VB doesn't like to implement interfaces that are not directly derived from IUnknown or IDispatch .

IExtractIcon is the general name given to one of two interfaces: IExtractIconA or IExtractIconW . These interfaces contain the ANSI and Unicode versions, respectively, of IExtractIcon . As fate would have it, we will have to implement both of them. The interfaces are defined almost the same ( typedefs aside). The only difference is how the methods will be implemented. Also, one of the methods , IExtractIcon::Extract , has to return the value S_FALSE (1) . In other words, a vtable swap is in order.

Here's how custom icon handlers work. When the shell is about to display an icon for a file object (for the first time), it checks for the following registry key to determine if there is an icon handler for that particular type:

 HKEY_CLASSES_ROOT\     radfile\         shellex\             IconHandler 

If an icon handler is present, the shell loads it and attempts to call IPersistFile::Load . One of the parameters to the Load method is a pointer to the name of the file whose icon the shell is requesting. Typically, an implementor of IPersistFile would store the name of the file object in a private member variable for later use. The other five methods of IPersistFile are ignored.

The shell then calls IExtractIcon::GetIconLocation to get the icon for the file object in question. If GetIconLocation fails, the shell will use the icon specified by the DefaultIcon registry key. If it succeeds, then the shell examines the pwFlags parameter of GetIconLocation to determine if the GIL_NOTFILENAME bit is turned on. If it is, the shell assumes that the icon handler wants to extract its own icon and calls IExtractIcon::Extract .

Basically, if the icon to be displayed resides in a file, GetIconLocation can provide all the necessary details for displaying the icon. If the icons exist in an image list control or you want to handle loading the icons yourself, Extract is used for this purpose. Extract provides the icons for Explorer in the form of two handles, or HICON s. One handle is the small icon (16 figs/u00d7.gif 16). The other is for the normal- sized icon (32 figs/u00d7.gif 32).

only for RuBoard - do not distribute or recompile


Visual Basic Shell Programming
Visual Basic Shell Programming
ISBN: B00007FY99
EAN: N/A
Year: 2000
Pages: 128

flylib.com © 2008-2017.
If you may any questions please contact us: flylib@qtcs.net