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

 
ExtractImage Handler Example

    Thumbnail images that user can see in the thumbnail view mode are produced by special type of shell extensions known as ExtractImage Handlers. Taking this example you will learn how to quickly implement your own thumbnail image handler.

    The ExtractImage 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.

Creation of new ActiveX Library
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 the example now.

    Add the TSxExtractImage component now. This component handles shell requests of image extraction and allows you to easy customize its behavior using a few lines of code. As usual when you place the component onto SxDataModule the CLSID property is set with a newly generated GUID. It is this GUID will be used by Shell to identify your extension. Other properties are presented in the table below:


CLSID

GUID. It is used to identify the extension, t is generated automatically when you drop component onto SxDataModule.

Description

The description of your extension, enter desired text here.

ExtensionName

Short extension name, MyImageHandler for example.

FileType

File type to be handled by the extension. Shell will call our extension to get thumbnail for files of the specified type only.

Name

As usual it is a Delphi's name of component.

Image

If assigned this property is used as a static thumbnail image. If you need to supply thumbnail dynamically then use the OnExtractImage event. This event is considered below.

OverwriteExistent

Only one thumbnail handler can be installed for a given file type. It is possible to override an existing thumbnail handler when you install your own one. To avoid possible problems you can control whether to override previous handler. If the OverwriteExistent is true then the existing handler will be overwritten. The OnKeyAlreadyExist event allows you to determine CLSID of the previously installed extension to allow or prohibit overriding and/or for backup purposes.

Table 1. TSxExtractImage properties.

    Use Object Inspector to set TSxExtractImage properties as shown below.

TSxExtractImage component properties
Fig 3. Setting TSxExtractImage properties

    Every time shell needs the image to display it calls a specific interface supplied by the extension library. You have not to care about all implementation details. The only thing you will have to do is to handle the OnExtractImage event. This event is fired as a result of shell request. The event handler should return the image and it is this image will be shown by the system.

    Select the Events tab of the Object Inspector and double click the OnExtractImage handler. The body of the handler will be created by Delphi, add the following code there:

procedure TSxModule1.SxExtractImage1ExtractImage(Sender: TSxExtractImage;
  Image: TBitmap; Size: TSxSize);
var
  TempBitmap:TBitmap;
begin
  TempBitmap:=TBitmap.Create; // create temporary image
  try
    // set it's size
    TempBitmap.Width:=Size.cx; 
    TempBitmap.Height:=Size.cy;
    // prepare to draw something
    TempBitmap.Canvas.Font.Name:='Arial';
    TempBitmap.Canvas.Font.Size:=5;
    // call auxiliary drawing function, its code follows below
    RenderTextFile(Sender.FileName,TempBitmap);
    // return the result
    Image.Assign(TempBitmap);
  finally
    TempBitmap.Free;
  end;
end;

    The rendering procedure is simple enough, it draws document contents as a plain text, line by line:

procedure RenderTextFile(FileName:String;var Bitmap:TBitmap);
var
  TempFile:TextFile;
  i:Integer;
  TempString:String;
begin
  AssignFile(TempFile,FileName);
  try
    Reset(TempFile);
    i:=0;
    repeat
      if not EOF(TempFile) then
         ReadLn(TempFile,TempString)
      else
         Break;
      Bitmap.Canvas.TextOut(0,i,TempString);
      i:=i+Bitmap.Canvas.TextHeight('A');
    until(i>Bitmap.Height);
  finally
    CloseFile(TempFile);
  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.

    Create an empty text document in any acceptable folder and switch the folder view to Thumbnails mode. If the example works correctly then thumbnail image of the test document should be empty:

Thumbnail image preview example

Fig 4. Switch to Thumbnails view mode.

    Edit the test document now and add any text text to it. Save the changed document and in a few seconds system will refresh the thumbnail. Now it is not clear! It contains the text you've entered in it! The picture you see is a result of drawing performed by RenderTextFile:

Thumbnail image preview example

Fig. 5. Thumbnail image of document with text.

 


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


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

Delphi 10.1 Berlin (x64)
ExtractImage-D24X64.zip
1.08Mb
3.15.296.396
11.09.2016
Delphi 10.1 Berlin
ExtractImage-D24.zip
876.99Kb
3.15.296.396
11.09.2016
Delphi 10 Seattle (x64)
ExtractImage-D23X64.zip
1.08Mb
3.15.296.396
11.09.2016
Delphi 10 Seattle
ExtractImage-D23.zip
869.53Kb
3.15.296.396
11.09.2016
Delphi XE8 (x64)
ExtractImage-D22X64.zip
1.08Mb
3.12.289.357
15.05.2015
Delphi XE8
ExtractImage-D22.zip
868.06Kb
3.12.289.357
15.05.2015
Delphi XE7 (x64)
ExtractImage-D21X64.zip
1.08Mb
3.11.289.357
19.09.2014
Delphi XE7
ExtractImage-D21.zip
80.36Kb
3.11.289.357
19.09.2014
Delphi XE6 (x64)
ExtractImage-D20X64.zip
1.09Mb
3.10.287.331
16.09.2014
Delphi XE6
ExtractImage-D20.zip
80.08Kb
3.10.287.331
16.09.2014
Delphi XE5 (x64)
ExtractImage-D19X64.zip
1.04Mb
3.10.287.331
16.03.2014
Delphi XE5
ExtractImage-D19.zip
80.12Kb
3.10.287.331
16.03.2014
Delphi XE4 (x64)
ExtractImage-D18X64.zip
1.04Mb
3.10.287.331
16.03.2014
Delphi XE4
ExtractImage-D18.zip
80.04Kb
3.10.287.331
16.03.2014
Delphi XE3 (x64)
ExtractImage-D17X64.zip
1.02Mb
3.10.287.331
16.03.2014
Delphi XE3
ExtractImage-D17.zip
80.01Kb
3.10.287.331
16.03.2014
Delphi XE2 (x64)
ExtractImage-D16X64.zip
772.77Kb
3.10.287.331
16.03.2014
Delphi XE2
ExtractImage-D16.zip
79.70Kb
3.10.287.331
16.03.2014
Delphi XE
ExtractImage-D15.zip
76.11Kb
3.10.287.331
16.03.2014
Delphi 2010
ExtractImage-D14.zip
75.94Kb
3.10.287.331
16.03.2014
Delphi 2009
ExtractImage-D12.zip
43.90Kb
3.10.287.331
16.03.2014
Delphi 2007
ExtractImage-D11.zip
43.08Kb
3.10.287.331
16.03.2014
Delphi 2006
ExtractImage-D10.zip
43.14Kb
3.10.287.331
16.03.2014
Delphi 2005
ExtractImage-D9.zip
44.09Kb
3.10.287.331
16.03.2014
Delphi 7
ExtractImage-D7.zip
248.83Kb
3.12.289.357
16.05.2015
Delphi 6
ExtractImage-D6.zip
43.38Kb
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.