For this article you require VC++ 6.0 or VC++ 5.0 with Internet Client SDK. Further
Internet Explorer 4.0 or greater must be installed with Shell Integration.
You may have noticed that when mouse is placed over .doc
files (shown in explorer or any where by shell) generated from Word 97 a tooltip
showing the author name popups as shown in the screen shot below (The mouse
pointer disappeared from the screen shot but it can be understood that it is
over offer.doc)
The aim of this article is to show how this could be done for your file types. In particular I would show how this
could be done for .cpp file popping out some useful information for the file.
How Shell Pops up a ToolTip
There was not much documentation available for how this
could be done so nor any samples are available. All I knew was that Shell uses
COM for supporting all such extensions and such extensions can be
implemented by implementing some interfaces and registering appropriate entries
at appropriate places. In such a situation Regmon utility developed by Mark
Russinovich and Bryce Cogswell came to rescue. You can download this utility
from http://www.sysinternals.com . It shows all the queries which are being
done on registry by different applications.
All that I did was to start regmon to monitor all the
Registry related calls from explorer.exe. I placed the mouse over a doc file and
found out what is being queried in the registry. Soon it became clear that
explorer queries for
HKEY_CLASSES_ROOT\.doc\ShellEx\{00021500-0000-0000-C000-000000000046}
and it creates an object of CLSID specified as the deafult value for this key.
In this case it was {83799FE0-1F5A-11d1-95C7-00609797EA4F}. It was not hard to figure out
that the registry entry was for a inproc-server of type "DocFile InfoTip
Handler". The next step was to observe what are the interfaces supported by
this object through OLEView.exe. Here is a screen shot of what OLEView
showed.
Since IPersistFile is
derived from
IPersist it can be concluded that
essentially "DocFile InfoTip Handler" implements IPersistFile and IQueryInfo. Luckily
documentation for both these interfaces were available and soon it was clear how
shell displays tooltips for files. Here is how it all happens :
- When mouse is placed over a file item (let’s say
file extension is .xxx) displayed in explorer. Shell queries for for the
registry entry
HKEY_CLASSES_ROOT\.doc\ShellEx\{00021500-0000-0000-C000-000000000046}
- It then checks the default value present at this
key. The value should be CLSID is string form of a COM class. If it is a
valid value shell creates an object of that class.
- Once the object is created Shell queries for
IPersistFile and calls the Load method of it passing the filename of the item over which
mouse is placed. Obviously the intention is that that the object would find
out information about the file show that it can display the tooltip.
- After that IQueryInfo
is queried for and the method GetInfoTip is
called. GetInfoTip has an out parameter *ppwszTip of type LPWSTR which recieves the address of the tool tip buffer.
- Finally shell displays the tooltip.
With this much information in hand it was fairly trivial
to develop an ATL project with an object implementing the interfaces.
The Sample Application
The sample application is an ATL project that implements
these interfaces. To make it useful the sample pops up tooltips for .c, cpp, .h
files. When the mouse is placed over any of these files shell creates the
object. The application gets the first 256 characters of the file and checks
whether it begins with ‘//’ or ‘/*’. If it begins with ‘//’ the first line of
comment is displayed as a tooltip otherwise for C-Style comments the text before
the comment ends (subject to 256 characters) is displayed as tooltip. Here is a
screen shot:
Download demo project – 27 KB infotip.zip