unit ShellIconListView;
interface
uses
SysUtils, Classes, Controls, ComCtrls, CommCtrl, ShellAPI, Windows;
type
TShellIconListView =
class(TCustomListView)
private
FileInfoBig, FileInfoSmall: TShFileInfo;
FBigImages: TImageList;
FSmallShellImages: TImageList;
FUseBigImages: Boolean;
FUseSmallImages: Boolean;
FBigShellIconsLoaded: Boolean;
FSmallShellIconsLoaded: Boolean;
FIndexFileExtension: Integer;
FIndexTypeAusgabe: Integer;
procedure SetUseBigImages(
const Value: Boolean);
procedure SetUseSmallImages(
const Value: Boolean);
procedure SetIndexFileExtension(
const Value: Integer);
procedure SetIndexTypeAusgabe(
const Value: Integer);
{ Private-Deklarationen }
protected
property SmallShellIconsLoaded: Boolean
read FSmallShellIconsLoaded
default False;
property BigShellIconsLoaded: Boolean
read FBigShellIconsLoaded
default False;
{ Protected-Deklarationen }
public
constructor Create(AOwner: TComponent);
override;
property SmallShellImages: TImageList
read FSmallShellImages;
property BigImages: TImageList
read FBigImages;
procedure UpdateIcons;
procedure LoadShellIcons;
{ Public-Deklarationen }
published
property UseBigImages: Boolean
read FUseBigImages
write SetUseBigImages
default True;
property UseSmallImages: Boolean
read FUseSmallImages
write SetUseSmallImages
default True;
property IndexFileExtension: Integer
read FIndexFileExtension
write SetIndexFileExtension
default -1;
//-2 = NotInUse | -1 = Caption | 0.. SubItems
property IndexTypeAusgabe: Integer
read FIndexTypeAusgabe
write SetIndexTypeAusgabe
default 0;
//-2 = NotInUse | -1 = Caption | 0.. SubItems
property Action;
property Align;
property AllocBy;
property Anchors;
property BevelEdges;
property BevelInner;
property BevelOuter;
property BevelKind
default bkNone;
property BevelWidth;
property BiDiMode;
property BorderStyle;
property BorderWidth;
property Checkboxes;
property Color;
property Columns;
property ColumnClick;
property Constraints;
property Ctl3D;
property DragCursor;
property DragKind;
property DragMode;
property Enabled;
property Font;
property FlatScrollBars;
property FullDrag;
property GridLines;
property HideSelection;
property HotTrack;
property HotTrackStyles;
property HoverTime;
property IconOptions;
property Items;
property MultiSelect;
property OwnerData;
property OwnerDraw;
property ReadOnly default False;
property RowSelect;
property ParentBiDiMode;
property ParentColor
default False;
property ParentFont;
property ParentShowHint;
property PopupMenu;
property ShowColumnHeaders;
property ShowWorkAreas;
property ShowHint;
property SortType;
property StateImages;
property TabOrder;
property TabStop
default True;
property ViewStyle;
property Visible;
property OnAdvancedCustomDraw;
property OnAdvancedCustomDrawItem;
property OnAdvancedCustomDrawSubItem;
property OnChange;
property OnChanging;
property OnClick;
property OnColumnClick;
property OnColumnDragged;
property OnColumnRightClick;
property OnCompare;
property OnContextPopup;
property OnCustomDraw;
property OnCustomDrawItem;
property OnCustomDrawSubItem;
property OnData;
property OnDataFind;
property OnDataHint;
property OnDataStateChange;
property OnDblClick;
property OnDeletion;
property OnDrawItem;
property OnEdited;
property OnEditing;
property OnEndDock;
property OnEndDrag;
property OnEnter;
property OnExit;
property OnGetImageIndex;
property OnGetSubItemImage;
property OnDragDrop;
property OnDragOver;
property OnInfoTip;
property OnInsert;
property OnKeyDown;
property OnKeyPress;
property OnKeyUp;
property OnMouseDown;
property OnMouseMove;
property OnMouseUp;
property OnResize;
property OnSelectItem;
property OnStartDock;
property OnStartDrag;
{ Published-Deklarationen }
end;
procedure Register;
implementation
procedure Register;
begin
RegisterComponents('
Beispiele', [TShellIconListView]);
end;
{ TShellIconListView }
procedure TShellIconListView.LoadShellIcons;
var
HIb, HIs: HImageList;
begin
if FUseSmallImages
then begin
ZeroMemory(@FileInfoSmall, SizeOf(FileinfoSmall));
if not Assigned(FSmallShellImages)
then begin
FSmallShellImages := TImageList.Create(Self);
FSmallShellImages.ShareImages := True;
SmallImages := FSmallShellImages;
FSmallShellIconsLoaded := False;
end;
if not FSmallShellIconsLoaded
then begin
HIs := HImageList(ShGetFileInfo('
', FILE_ATTRIBUTE_NORMAL, FileInfoSmall, SizeOf(FileInfoSmall), SHGFI_SYSICONINDEX
or SHGFI_SMALLICON));
if (HIs <> 0)
then FSmallShellImages.Handle := HIs;
FSmallShellIconsLoaded := True;
end;
end;
if FUseBigImages
then begin
ZeroMemory(@FileInfoBig, SizeOf(FileInfoBig));
if not Assigned(FBigImages)
then begin
FBigImages := TImageList.Create(Self);
FBigImages.ShareImages := True;
LargeImages := FBigImages;
FBigShellIconsLoaded := False;
end;
if not FBigShellIconsLoaded
then begin
HIb := HImageList(ShGetFileInfo('
', FILE_ATTRIBUTE_NORMAL, FileInfoBig, SizeOf(FileInfoBig), SHGFI_SYSICONINDEX
or SHGFI_LARGEICON));
if (HIb <> 0)
then FBigImages.Handle := HIb;
FBigShellIconsLoaded := True;
end;
end;
end;
procedure TShellIconListView.SetUseBigImages(
const Value: Boolean);
begin
FUseBigImages := Value;
if FUseBigImages
then LoadShellIcons
else BigImages.Free;
end;
procedure TShellIconListView.SetIndexFileExtension(
const Value: Integer);
begin
FIndexFileExtension := Value;
end;
procedure TShellIconListView.SetIndexTypeAusgabe(
const Value: Integer);
begin
FIndexTypeAusgabe := Value;
end;
procedure TShellIconListView.SetUseSmallImages(
const Value: Boolean);
begin
FUseSmallImages := Value;
if FUseSmallImages
then LoadShellIcons
else SmallShellImages.Free;
end;
procedure TShellIconListView.UpdateIcons;
var
I: Integer;
S:
String;
begin
for I := 0
to Items.Count-1
do begin
if (FIndexFileExtension > -1)
and not (Items[I].SubItems.Count > FIndexFileExtension)
then
Continue;
if FIndexFileExtension = -1
then S := ExtractFileExt(Items[I].Caption)
else
if FIndexFileExtension > -1
then S := ExtractFileExt(Items[I].SubItems[FIndexFileExtension])
else
S := '
';
if S <> '
'
then
if ViewStyle = vsIcon
then begin
ZeroMemory(@FileInfoBig, SizeOf(FileInfoBig));
ShGetFileInfo(PChar(S), FILE_ATTRIBUTE_NORMAL, FileInfoBig,sizeof(FileInfoBig),
SHGFI_ICON
or SHGFI_SYSICONINDEX
or SHGFI_LARGEICON
or SHGFI_USEFILEATTRIBUTES);
Items[I].ImageIndex := FileInfoBig.iIcon;
if FIndexTypeAusgabe = -1
then Items[I].Caption := FileInfoBig.szTypeName
else
if FIndexTypeAusgabe > -1
then begin
While Items[I].SubItems.Count <= FIndexTypeAusgabe
do
Items[I].SubItems.Add('
');
Items[I].SubItems[FIndexTypeAusgabe] := FileInfoBig.szTypeName;
end;
end else begin
ZeroMemory(@FileInfoSmall, SizeOf(FileInfoSmall));
ShGetFileInfo(PChar(S), FILE_ATTRIBUTE_NORMAL, FileInfoSmall,sizeof(FileInfoSmall),
SHGFI_ICON
or SHGFI_SYSICONINDEX
or SHGFI_SMALLICON
or SHGFI_USEFILEATTRIBUTES);
Items[I].ImageIndex := FileInfoSmall.iIcon;
if FIndexTypeAusgabe = -1
then Items[I].Caption := FileInfoSmall.szTypeName
else
if FIndexTypeAusgabe > -1
then begin
While Items[I].SubItems.Count <= FIndexTypeAusgabe
do
Items[I].SubItems.Add('
');
Items[I].SubItems[FIndexTypeAusgabe] := FileInfoSmall.szTypeName;
end;
end;
end;
end;
constructor TShellIconListView.Create(AOwner: TComponent);
begin
inherited;
LoadShellIcons;
end;
end.