function GetAssociatedIcon(
const AExtension:
string; ASmall: Boolean): HIcon;
var
Info: TSHFileInfo;
DateiInfo: SHFILEINFO;
begin
SHGetFileInfo(PChar(AExtension), 0, DateiInfo, SizeOf(DateiInfo), SHGFI_ICON
or SHGFI_LARGEICON);
Result := DateiInfo.hIcon;
end;
.....
var
icon: TIcon;
ListItem: TListItem;
Line:Integer;
begin
ListView1.Items.Clear;
For Line := 0
To FileListBox1.Items.Count -1
do
begin
icon := TIcon.Create;
try
If (ExtractFileExt(FileListBox1.Items[Line]) = '
.exe')
or (ExtractFileExt(FileListBox1.Items[Line]) = '
.EXE')
Then
icon.Handle := ExtractIcon(
Handle, PChar(FileListBox1.Items[Line]), 0)
else
icon.Handle := GetKleinIcon(ExtractFileExt(FileListBox1.Items[Line]), True);
with ListView1
do
begin
ListItem := Items.Add;
Listitem.Caption := FileListBox1.Items[Line];
ListView1.LargeImages := ImageList2;
ListView1.ViewStyle := vsSmallIcon;
ListItem.ImageIndex := ImageList2.AddIcon(Icon);
If icon.Handle = 0
Then ListItem.ImageIndex := 0;
end;
finally
icon.Free;
end;
end;
...