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

 
CopyHook Handle Example

    This example shows how to monitor creation, deletion, renaming or copying of folders.

    The CopyHook handler is an ActiveX library like all other Shell Extensions. The first step 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 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:

Creation 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 CopyHook itself. Shell+ Library contains a special component that takes care about all CopyHook 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 TSxCopyHook component and insert it into module.

    Take a look on the properties of the CopyHook component. 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 CopyHook handler, created automatically in design time

Description

Description of the hook. Enter desired description here.

ExtensionName

Short name of the CopyHook extension, MyCopyHook for example.

FileType

Type of files that will be monitored. Note that "Directory" and "Printers" are the only types that Windows allows to monitor with CopyHooks.

Table 1. TSxCopyHook properties

    Set components properties now as shown below:

TSxCopyHook component properties

Fig. 3. TSxCopyHook properties sample

        Now the example is almost ready, it can be compiled and installed into system but it does nothing. The next step is to add some operations to be done when hook is activated. These operations should be placed into OnCopyHook event handler. This event will be fired every time the shell performs an operation with hooked objects. Processing the event you receive a chance to monitor the file operation or even enable or prohibit it. Let's implement this functionality in our example.

    Create the form that will ask user about permission to perform an operation with hooked objects:

Confirm folder operation dialog
Fig 4. Operation permission query

    Buttons "Yes", "No" and "Cancel" should have a usual ModalResult property value - mrYes, mrNo and mrCancel respectively.

    Now implement OnCopyHook event as follows:

procedure TSxModule1.SxCopyHook1CopyHook(Sender: TSxCopyHook; Wnd: Integer;
  CopyFunct: TSxCopyFunct; CopyFlags: TSxCopyFlags; SrcFile,
  DstFile: String; SrcAttr, DstAttr: TSxFileType;
  var Result: TSxCopyHookResult);
begin
  ConfirmWindow:=TConfirmWindow.CreateParented(Wnd); // Confirmation dialog
  try
    ConfirmWindow.eSourceFolder.Text:=SrcFile; // Source file
    ConfirmWindow.eDestFolder.Text:=DstFile;  // Destination file
    case CopyFunct of // Kind of operation
      cfCopy: ConfirmWindow.eOperation.Text:='Copying';
      cfDelete: ConfirmWindow.eOperation.Text:='Deleteon';
      cfMove: ConfirmWindow.eOperation.Text:='Moving';
      cfRename: ConfirmWindow.eOperation.Text:='Renaming';
    end;
    case ConfirmWindow.ShowModal of
      mrYes: Result:=chrYes;
      mrNo:  Result:=chrNo;
      mrCancel: Result:=chrCancel;
    end;
  finally
    ConfirmWindow.Free;
  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.

The final step is to test how the example works.

   Create a new folder on your desktop or in any directory. You can use New | Folder items from the context menu. The newly created folder will have name "---------" or "New Folder" (it depends on the OS version). Try to rename it and you will see the confirmation window shown by our example. It will look like this one:

Confirm File operation example

    Press "Yes" to confirm folder renaming. If you will choose "Cancel" or "No" then renaming operation will be canceled.

The deletion operation works in the similar way. Select the test folder and delete it. Windows will show the confirmation dialog and - if the operation was confirmed - our sample confirmation window will be shown:

Confirm file operation example

The folder will be deleted if the "Yes" button was pressed only.

    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)
CopyHook-D24X64.zip
1.10Mb
3.15.296.396
11.09.2016
Delphi 10.1 Berlin
CopyHook-D24.zip
892.60Kb
3.15.296.396
11.09.2016
Delphi 10 Seattle (x64)
CopyHook-D23X64.zip
1.10Mb
3.15.296.396
11.09.2016
Delphi 10 Seattle
CopyHook-D23.zip
884.78Kb
3.15.296.396
11.09.2016
Delphi XE8 (x64)
CopyHook-D22X64.zip
1.10Mb
3.12.289.357
15.05.2015
Delphi XE8
CopyHook-D22.zip
883.38Kb
3.12.289.357
15.05.2015
Delphi XE7 (x64)
CopyHook-D21X64.zip
1.10Mb
3.11.289.357
19.09.2014
Delphi XE7
CopyHook-D21.zip
82.75Kb
3.11.289.357
19.09.2014
Delphi XE6 (x64)
CopyHook-D20X64.zip
1.11Mb
3.10.287.331
16.09.2014
Delphi XE6
CopyHook-D20.zip
82.67Kb
3.10.287.331
16.09.2014
Delphi XE5 (x64)
CopyHook-D19X64.zip
1.06Mb
3.10.287.331
16.03.2014
Delphi XE5
CopyHook-D19.zip
82.19Kb
3.10.287.331
16.03.2014
Delphi XE4 (x64)
CopyHook-D18X64.zip
1.05Mb
3.10.287.331
16.03.2014
Delphi XE4
CopyHook-D18.zip
82.11Kb
3.10.287.331
16.03.2014
Delphi XE3 (x64)
CopyHook-D17X64.zip
1.03Mb
3.10.287.331
16.03.2014
Delphi XE3
CopyHook-D17.zip
82.08Kb
3.10.287.331
16.03.2014
Delphi XE2 (x64)
CopyHook-D16X64.zip
787.67Kb
3.10.287.331
16.03.2014
Delphi XE2
CopyHook-D16.zip
81.94Kb
3.10.287.331
16.03.2014
Delphi XE
CopyHook-D15.zip
78.65Kb
3.10.287.331
16.03.2014
Delphi 2010
CopyHook-D14.zip
78.35Kb
3.10.287.331
16.03.2014
Delphi 2009
CopyHook-D12.zip
47.22Kb
3.10.287.331
16.03.2014
Delphi 2007
CopyHook-D11.zip
46.33Kb
3.10.287.331
16.03.2014
Delphi 2006
CopyHook-D10.zip
46.42Kb
3.10.287.331
16.03.2014
Delphi 2005
CopyHook-D9.zip
47.49Kb
3.10.287.331
16.03.2014
Delphi 7
CopyHook-D7.zip
257.14Kb
3.12.289.357
16.05.2015
Delphi 6
CopyHook-D6.zip
46.22Kb
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.