function GetShellIcon(FileName:
string; NoFile: boolean): integer;
var
SHFileInfo: TSHFileInfo;
Tmp:
string;
Txt: textfile;
begin
Result := 0;
//Falls ein Laufwerksbuchstabe übergeben wurde...
if Length(FileName) = 1
then
FileName := FileName + '
:';
//Laufwerke sollten mit \ enden...
if (Length(FileName) = 2)
and (copy(FileName, length(FileName), 1) = '
:')
and (copy(FileName, length(FileName), 1) <> '
\')
then
FileName := FileName + '
\';
// CoInitialize has to be called before SHGetFileInfo (done by Delphi)
FillChar(SHFileInfo, SizeOf(TSHFileInfo), 0);
//Dateiino lesen...
if NoFile = False
then
ShGetFileInfo(PChar(FileName), 0, SHFileInfo, SizeOf(TSHFileInfo),
SHGFI_SYSICONINDEX
or SHGFI_SMALLICON
or SHGFI_ICON)
else
ShGetFileInfo(PChar(FileName), FILE_ATTRIBUTE_ARCHIVE, SHFileInfo,
SizeOf(TSHFileInfo), SHGFI_SYSICONINDEX
or SHGFI_SMALLICON
or
SHGFI_ICON
or SHGFI_USEFILEATTRIBUTES);
try
//IconIndex liefern...
Result := SHFileInfo.iIcon;
finally
// icon handle freigeben
DestroyIcon(SHFileInfo.hIcon);
end;
end;