unit Icons;

interface

uses
  Windows, Messages, SysUtils, Classes, Graphics, Controls,
  Forms, Dialogs,shellapi,registry;

function ExtractIconFromFile(const FileName : String;
                             nIndex   : Integer; LargeIcon : Boolean) : tIcon;


implementation

// TDroppedObject.ExtractIconFromFile /////////////////////////////////////////
function ExtractIconFromFile(const FileName : String;
                             nIndex   : Integer; LargeIcon : Boolean) : tIcon;
var
  Icon : TIcon;
  hIco : HIcon;
  sIcon,lIcon  : HIcon;
begin
  // Try to extract the icon from the file passed as argument
  ExtractIconEx(pChar(FileName), nIndex, lIcon, sIcon, 1);
  If LargeIcon=True Then hIco:=lIcon Else hIco:=sIcon;
  If hIco <> 0 then
  Begin
   Icon := TIcon.Create;
   Icon.ReleaseHandle;
   Icon.Handle := hIco;
   ExtractIconFromFile:=Icon;
  End
  Else
  Begin
//     hIco := ExtractIcon(HInstance,
//                          '%SystemRoot%\system32\shell32.dll', nResNum);
    ExtractIconEx('%SystemRoot%\system32\shell32.dll', 0, lIcon, sIcon, 1);
  If LargeIcon=True Then hIco:=lIcon Else hIco:=sIcon;

     Icon := TIcon.Create;
     Icon.ReleaseHandle;
     Icon.Handle := hIco;
     ExtractIconFromFile:=Icon;
  End;
end;

end.


