ShellPlus Customer login
ShellPlus
Shell+ components
    Home
    News
    Overview
    Download
    Examples
    Customer's area
    Flash Demo
 
Developer Tools
    Shell Reset Tool
 
Shell+ Tutorial
    Namespace Extensions
    ShortCut menu
    Property Sheet
    Icon Handler
    Thumbnails
    InfoTip Handler
    Copy Hook
    Balloon TrayIcon
    Control Panel
    Shortcut Files
    Drag&Drop Menu
    Shell Change Notify
 
 
Documents
    Articles Index
    Press Releases
 
Purchase
    Buy now
    Resellers network
    Resellers wanted
 
Support
    Contact directly
    Customer's area
 
About/Contacts
    Shell+ Developers

Embarcader Technology Partner

 
ExtractIcon Handler Example

    This example shows how to control icon images drawn by Windows shell.

    The ExtractIcon handler is an ActiveX library like all other Shell Extensions. The first step to be done is to create a new ActiveX Library. Create it with the following sequence of operations: open the Repository dialog using File | New | Other... menu, then select the ActiveX tab and click the ActiveX Library icon.

Create new ActiveX library example
Fig. 1. New ActiveX Library creation.

    Save the created project.

    The next step is to add the instance of TSxDataModule to the project. Every Shell+ component should be placed on SxDataModule 1. This special descendant of TDataModule supplies several internal methods that allow Shell+ components to safely operates in multiple Shell threads and automates their registration and initialization. Note that you can place several Shell+ components onto the same SxDataModule as well as you can add multiple TSxDataModule instances to your project. It is easy to add new SxDataModule to the project - just click corresponding icon in the Repository:

Create new Shell extension module
Fig. 2. How to create new SxDataModule instance.

    You can save your project now.

    The next step is to create the ExtractIcon itself. Shell+ Library contains a special component that takes care about all ExtractIcon functionality. The only thing you need to do is to place it on SxDataModule and set its properties. Select the Shell+ tab in the palette, click the TsxExtractIcon component and insert it into module.

    Take a look on ExtractIcon properties. First of all you will see that the new GUID was created and assigned to the component's CLSID property. It is this GUID will be used by system to identify your CopyHook handler. Other properties are described in the table below:

CLSID

GUID, used be system to identify ExtractIcon handler, created automatically in design time

Description

Description of the ExtractIcon extension. Enter desired text here.

ExtensionName

Short name of the extension, MyExtractIcon for example

FileType

File type. It is for this type of file Windows will ask our extension for icon. Use the Object Inspector's lookup to select appropriate file type or enter it manually.

Name

Component name, nothing special.

DontCache

This property controls whether Windows will ask the icon every time it needs it or icon will be cached. If you need to draw different icons for the same file type then set this property to True.

IconFileName
IconIndex
IconIndexOpen

These properties give you a way to supply icon images from exe or dll files. IconFileName is the name of file with icons while IconIndex and IconIndexOpen are two indexes that indicate what icons to be used. Note that IconIndex property is used in most cases, the only case when the IconIndexOpen icon is used is the folder-like shell item that is in opened state.

IconLarge
IconLargeOpen

Use these properties if you wish to supply your icons directly with your module. In opposite to the previous properties icon images will be stored in the dll itself. These icons will be shown in the "Large Icons" mode.

IconSmall
IconSmallOpen

These properties are similar to IconLarge and IconLargeOpen except they will be shown in"Small Icons" mode.

OverwriteExistent

Only one ExtractIcon handler can be assigned to the same filetype at the moment. Playing with shell extensions you can easy override the existing handler. Use this property to control whether to override an existing icon handler or leave it unchanged. In addition you can use the OnKeyAlreadyExist event to dynamically get the previous handler and decide whether to override it.

Table 1. TSxExtractIcon component properties.

    As you've just seen TSxExtractIcon supplies several ways to store and handle icon images. In this example we shell use the ImageList component to store icons. Place it on the form and add two icons into it. You can use any icons as you wish, the first one will be used to indicate the empty text document while the second will represent the document with a text.
    Now fill TSxExtractIcon properties as shown below:

ExtractIcon component properties
Fig. TSxExtractIcon component properties

    As it was mentioned above the TSxExtractIcon component can ask the end user whether to override an existing icon handler. Let's create a special query form that will be used below to illustrate this opportunity. This form will be shown at Shell Extension registration to confirm overwriting of an existing icon handler. Create a new form and configure it as shown below:

Confirmation query window
Fig 4. Confirmation query window.

    Every time the Shell needs the icon to be displayed it calls the Shell extension's method to receive it. As a result the TSxExtractIcon.OnExtractIcon event of is fired in our example. This event gives you a lot of opportunities: you can return any icon as you wish depending on file size, contents or any other condition. In our example the size of file is used as a criteria what icon to be shown.
    Select the Events tab of the Object Inspector and double click the OnExtractIcon event. Add the following code to the event handler:

procedure TSxModule1.SxExtractIcon1ExtractIcon(Sender: TObject;
  var IconLarge, IconSmall: TIcon);
begin
  if FileGetSize((Sender as TSxExtractIcon).FileName)<>0 then
     // this icon will be shown for file with contents
     ImageList.GetIcon(1,IconLarge) 
  else
     // this one will be used for an empty file
     ImageList.GetIcon(0,IconLarge); 
end;

    If another icon-handler extension was registered for the file type and the OverwriteExistent property was set to True then the OnKeyAlreadyExists event will be fired. Let's implement its handler as follows:

procedure TSxModule1.SxExtractIcon1KeyAlreadyExist(RegisteredClass: TGUID;
  var Overwrite: Boolean);
begin
  Overwrite:=MessageDlg('Extension already registered. Owerwrite?', 
             mtWarning, [mbYes, mbNo], 0)=mrYes;
  if Overwrite then
  begin
    GUIDWindow:=TGUIDWindow.CreateParented(0);
    try
      GUIDWindow.Caption:='Store this GUID';
      GUIDWindow.ShowModal;
    finally
      GUIDWindow.Free;
    end;
  end;
end;

    Save the project and compile it - it is ready now! As well as any other ActiveX library the Shell+ project requires registration. You can register it in several ways:

  • from command prompt using MS regsvr32 utility: regsvr32.exe Project1.dll
  • from command prompt using Borland's tregsvr utility: tregsvr Project1.dll

To know more about shell extension installation please follow the link.

Now is a time to test the example. To do it create a new text document on your desktop: Right click | New | Text Document. Note that the icon of newly created file is exactly that you've specified for an empty text document:

Empty Icon Example

To continue the test add a couple of words to the document and save it. As you will see the file will be displayed with a new icon. It is this icon was assigned to files with contents:

Filled Icon Example

    Don't forget to uninstall the example when all tests are finished. Note that it is an example only and it will show its confirmation window until you will not unregister it. As well as installation the uninstallation can be done in many ways:

  • from command prompt using MS regsvr32 utility: regsvr32.exe /u Project1.dll
  • from command prompt using Borland's tregsvr utility: tregsvr -u Project1.dll

The detailed information about extension uninstallation is available here.


1. The only exception is the TSxTrayIcon component that does not need to be placed on SxDataModule instance.


Download example

Use links below to download source codes of this example as well as binary files:

Delphi 10.1 Berlin (x64)
ExtractIcon-D24X64.zip
1.09Mb
3.15.296.396
11.09.2016
Delphi 10.1 Berlin
ExtractIcon-D24.zip
888.51Kb
3.15.296.396
11.09.2016
Delphi 10 Seattle (x64)
ExtractIcon-D23X64.zip
1.09Mb
3.15.296.396
11.09.2016
Delphi 10 Seattle
ExtractIcon-D23.zip
881.18Kb
3.15.296.396
11.09.2016
Delphi XE8 (x64)
ExtractIcon-D22X64.zip
1.09Mb
3.12.289.357
15.05.2015
Delphi XE8
ExtractIcon-D22.zip
879.80Kb
3.12.289.357
15.05.2015
Delphi XE7 (x64)
ExtractIcon-D21X64.zip
1.09Mb
3.11.289.357
19.09.2014
Delphi XE7
ExtractIcon-D21.zip
94.08Kb
3.11.289.357
19.09.2014
Delphi XE6 (x64)
ExtractIcon-D20X64.zip
1.10Mb
3.10.287.331
16.09.2014
Delphi XE6
ExtractIcon-D20.zip
93.98Kb
3.10.287.331
16.09.2014
Delphi XE5 (x64)
ExtractIcon-D19X64.zip
1.05Mb
3.10.287.331
16.03.2014
Delphi XE5
ExtractIcon-D19.zip
93.91Kb
3.10.287.331
16.03.2014
Delphi XE4 (x64)
ExtractIcon-D18X64.zip
1.05Mb
3.10.287.331
16.03.2014
Delphi XE4
ExtractIcon-D18.zip
93.85Kb
3.10.287.331
16.03.2014
Delphi XE3 (x64)
ExtractIcon-D17X64.zip
1.03Mb
3.10.287.331
16.03.2014
Delphi XE3
ExtractIcon-D17.zip
93.80Kb
3.10.287.331
16.03.2014
Delphi XE2 (x64)
ExtractIcon-D16X64.zip
784.16Kb
3.10.287.331
16.03.2014
Delphi XE2
ExtractIcon-D16.zip
93.59Kb
3.10.287.331
16.03.2014
Delphi XE
ExtractIcon-D15.zip
89.71Kb
3.10.287.331
16.03.2014
Delphi 2010
ExtractIcon-D14.zip
89.31Kb
3.10.287.331
16.03.2014
Delphi 2009
ExtractIcon-D12.zip
58.92Kb
3.10.287.331
16.03.2014
Delphi 2007
ExtractIcon-D11.zip
58.04Kb
3.10.287.331
16.03.2014
Delphi 2006
ExtractIcon-D10.zip
58.04Kb
3.10.287.331
16.03.2014
Delphi 2005
ExtractIcon-D9.zip
58.92Kb
3.10.287.331
16.03.2014
Delphi 7
ExtractIcon-D7.zip
264.88Kb
3.12.289.357
16.05.2015
Delphi 6
ExtractIcon-D6.zip
58.03Kb
3.8.287.331
09.05.2012

  Top


Components | Download | Purchase | Support | About Us
Copyright © 2016 ALDYN Software. All rights reserved.
Copyright © 2001 - 2011 Shell+ Development Group. All rights reserved.