|
ShellBrowser Delphi Components Documentation
|
class procedure SetOnGetCustomIconForPath(const pEventHandler: TCustomizeIconEvent);
|
Parameters |
Description |
|
const pEventHandler: TCustomizeIconEvent |
An event handler that is fired in case an icon is needed for a certain element. |
Set a global event handler that is called when getting the icon for an element. You may specify a different imagelist and index to overwrite the file's image that is otherwise determined by the SystemImageList.
The following example is taken from JamExplorer and shows a small samples implementation for a TJamShellList and TJamShellTree.
unit CustomIconsExample; interface uses Vcl.Forms, ShellControls, Vcl.Controls, Jam.Shell.Controls.Types; type TMainForm = class(TForm) CustomSmallImages: TImageList; //contains the custom icons. In newer Delphi version a TVirtualImageList can be used instead. ShellList: TJamShellList; ShellTree: TJamShellTree; procedure FormCreate(Sender: TObject); private fCustomIconPath: string; procedure GetCustomIcon(Sender: TObject; const pPath: string; var pEventArgs: TCustomizeIconEventArgs); end; implementation uses System.SysUtils, ShellBrowser; procedure TMainForm.FormCreate(Sender: TObject); begin //registers GetCustomIcon as global eventhandler. TGlobalCustomIconHandler.SetOnGetCustomIconForPath(GetCustomIcon) //activates the eventhandler for the ShellList and the ShellTree ShellTree.CustomIcons := true; ShellList.CustomIcons := true; end; procedure TMainForm.GetCustomIcon(Sender: TObject; const pPath: string; var pEventArgs: TCustomizeIconEventArgs); begin if (Sender = ShellList) then begin if (Uppercase(ExtractFileExt(pPath)) = '.TXT') then begin pEventArgs.ImageList := CustomSmallImages; pEventArgs.ImageIndex := 0; end; end else if (Sender = ShellTree) then begin if SamePath(pPath, fCustomIconPath) then begin pEventArgs.ImageList := CustomSmallImages; pEventArgs.ImageIndex := 1; end; end; end; end.