Extraer el icono asociado a un fichero  

Enviado Por: Q3 Team
Web : http://www.q3.nu
Email: dlib@q3.nu
Fecha: 04/08/99

Truco accedido 90 veces

 


Por ejemplo, a un fichero *.pas le corresponderia el icono de Delphi.

  • Añade 'ShellApi' en el uses de tu form
  • Pon un TImage (Image1) y un TButton (Button1) en tu form
  • Pon este código en el OnClick del Button1:




     procedure TForm1.Button1Click(Sender: TObject);
     var
        Icono:TIcon;
        Indice:word;
     begin
       Icono:=TIcon.Create;
       {Indice del icono a extraer}
       {Icon Index to extract}
       Indice:=0;
       Icono.handle:=ExtractAssociatedIcon(hInstance,Pchar('c:\kk\dlib.zip'),Indice);
       Image1.Picture.Bitmap.Width:= Icono.Width;
       Image1.Picture.Bitmap.Height:= Icono.Height;
       Image1.Picture.Bitmap.Canvas.Draw(0,0,Icono);
       Icono.Free;
     end;