1. Computing
RTL reference|Glossary|Tips/Tricks|FREE App/VCL|Best'O'Net|Books|Link To
 
Windows Shell Extensions – Info Tip
Page 3: Delphi project: Infotip; Registering Infotip Extensions
 More of this Feature
• Page 1: Shell extensions
• Page 2: InfoTip overview

Printer friendly versionPrinter friendly version
 Join the Discussion
"Post your questions, concerns, views and comments to this article..."
Discuss!
 Related Resources
• Win/API articles
• COM/OLE articles

   Delphi project: Infotip

Source download
Compiled Project (169KB) - Contains DPRInfoTip.dll.
Project Files (6KB) - Contains the Delphi project source files.
Registration File (1KB) - Contains two registration files (one for Win9x and one for Win2000).
The accompanying source code contains a complete Infotip Extension for .DPR (Delphi Project files). This Infotip will display the FileName, the project type (Program or Library), the Project Name (from the source file), and the size of the file in bytes.

To begin, we need to create an automation object called DPRInfoTip. First, click File | New... to open the Object Repository, then click on the ActiveX tab and select the ActiveX Library. This will generate an empty ActiveX library and export the necessary function required to be a valid automation object.

Next, click File | New... again and select the ActiveX tab and select the Automation Object. When the Automation Object Wizard opens, enter DPRInfoTip as the CoClass name (see Figure 2 below for an example of how the dialog should look). Leave the remaining options with their default values and click OK, this will generate the basic Type Library and implement a skeleton for the IDPRInfoTip interface, which gets automatically generated.

Automation Object Wizard

Once the files have been created the next thing we need to do is to add support for the additional interfaces that must be supported:

TDPRInfoTip = class(TAutoObject, IDPRInfoTip, IQueryInfo, IPersistFile, IPersist);

Note: We need to implement IPersist also because IPersistFile inherits from IPersist.

The accompanying source code can be used for all InfoTip Extensions, the only code that must be altered is the GenerateTip method. This is the method that determines the text to display in the InfoTip.

In the Initialization method, we call SHGetMalloc, which causes Windows to allocate some memory and return a pointer to it in the pMalloc private variable. In the destructor, we set pMalloc equal to Nil. This releases our hold on the memory so the Windows shell can release the memory when necessary.

IPersistFile::Load
When the mouse hovers over a file, the shell calls the Load method to provide the name of the file. Our implementation stores the name of the file in a private variable, FFile, so it will be available when we need to generate the InfoTip text.

function TDPRInfoTip.Load
  (pszFileName: POleStr;
   dwMode: Integer):
   HResult; 
begin 
 FFile  := pszFileName; 
 Result := S_OK; 
end; 

For all remaining IPersistFile methods, simply return E_NOTIMPL.

IQueryInfo::GetInfoTip
When the shell is ready to display the InfoTip, it calls the GetInfoTip method to retrieve the text to display. Our implementation calls the custom GenerateTip method in order to determine the text to display. It then is converted to a Windows compatible WideString and returned in the ppwszTip parameter.

The GenerateTip method opens the .DPR file and reads contents into a string. The text to be returned first is assigned the filename of the selected file, then the type is assigned the first word in the project file; which is either Program or Library. Finally the project name is extracted from the remainder of the first line and the size of the file in bytes is determined by the size of the stream. The GenerateTip method can be customized to fit the needs of the InfoTip Extension being developed.

   Registering Infotip Extensions
There are two steps to register an InfoTip Extension:

1. Register the COM DLL using regsvr32.exe (Start..Run dialog box)

regsvr32 "C:\...\DPRInfoTip.dll"

2. Add a reference to the associated extension (.dpr) to the HKEY_CLASSES_ROOT registry key.

The default value for this new key must be the CLSID of the COM object that implements the Shell Extension. This can be obtained from the Type Library file that was generated by Delphi (the filename ends in "_TLB.pas"). For our example extension the CLSID is named CLASS_DPRInfoTip and contains the value "{B20433A8-D083-11D4-993A-00D00912C440}".

The easiest way to make the registry changes is to make a copy of the .REG file provided with the source code for this project. Change the CLSID and file extension to the associated values.

One important note, it is necessary to "approve" shell extensions under Windows NT and 2000. This means that you must be logged into the machine with Administrator rights in order to register the extension.

   That's all folks
That's it for this article. In the future articles we'll see how to use Delphi to implement other shell extensions.
In the mean time, if you have any questions regarding this article, please post them to the Delphi Programming Forum.

First page > Shell extensions allow developers to add functionality to the existing Windows shell > Page 1, 2, 3

All graphics (if any) in this feature created by Zarko Gajic.

 More Delphi
· Learn another routine every day - RTL Quick Reference.
· Download free source code applications and components.
· Talk about Delphi Programming, real time.
· Link to the Delphi Programming site from your Web pages.
· Tutorials, articles, tech. tips by date: 2001|2000|1999|1998 or by TOPIC.
· NEXT ARTICLE: New...Access Database from Delphi - DB/13.
Chapter thirteen of the free Delphi Database Course for beginners. How to create an MS Access database without the MS Access. How to add an index to an existing table, how to join two tables and set up referential integrity. No MS Access, only Pure Delphi code.
 Stay informed with all new and interesting things about Delphi (for free).
Subscribe to the Newsletter
Name
Email

 Got some code to share? Got a question? Need some help?

©2013 About.com. All rights reserved.