unit Unit1;
interface
uses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs, Buttons, ExtCtrls, ShellAPI;
type
TForm1 =
class(TForm)
Image1: TImage;
procedure FormCreate(Sender: TObject);
private
{ Private-Deklarationen }
public
{ Public-Deklarationen }
end;
var
Form1: TForm1;
implementation
{$R *.dfm}
procedure GetAssociatedIconEx(
const Filename :
String; Icon : TIcon);
var
SHFileInfo: TSHFileInfo;
begin
// CoInitialize has to be called before SHGetFileInfo (done by Delphi)
FillChar(SHFileInfo, SizeOf(TSHFileInfo), 0);
if (SHGetFileInfo(PChar(Filename), FILE_ATTRIBUTE_NORMAL, SHFileInfo,
SizeOf(TSHFileInfo), SHGFI_USEFILEATTRIBUTES
or SHGFI_ICON
or SHGFI_SMALLICON) <> 0)
then
// or SHGFI_LARGEICON, SHGFI_LINKOVERLAY, SHGFI_OPENICON, SHGFI_SELECTED
try
// get it
Icon.Handle := CopyIcon(SHFileInfo.hIcon);
finally
// you are responsible for destroying the icon handle
DestroyIcon(SHFileInfo.hIcon);
end;
end;
procedure TForm1.FormCreate(Sender: TObject);
begin
GetAssociatedIconEx('
c:\test.htm',Image1.Picture.Icon);
end;
end.