天天看點

Delphi提取EXE,DLL檔案圖示

//uses ShellAPI

procedure   TForm1.Button1Click(Sender:   TObject);

var

      IconIndex:Word;

      h:hICON;

begin

      IconIndex:=0;

      h:=ExtractIcon(HInstance,pchar('c:"windows"notepad.exe'),IconIndex);

      DrawICon(Form1.canvas.Handle,200,100,h);

end;

//用控件ImageList儲存提取的圖示,并在ListView中顯示出來

FIcon.Handle:=hIcon1;

ImageList1.AddIcon(fIcon);

ListItem:=ListView1.Items.Add;

ListItem.ImageIndex:=ImageList1.Count-1;

====================================================

use    shellapi;       //提取出圖示并賦給SpeedButton.Glyph

   procedure    TForm1.Button1Click(Sender:    TObject);   

   var   

       hc:    TIcon;   

       Bitmap    :    TBitmap;   

   begin   

   //打開exe   

       opendialog1.Execute;           

       hc    :=    TIcon.Create;   

       Bitmap    :=    TBitmap.Create;   

   //提取exe圖示   

       hc.Handle    :=    ExtractIcon(hInstance,    PChar(opendialog1.FileName),    0);   

   //将得到的ico轉換為bitmap   

       Bitmap.Width    :=    hc.Width;   

       Bitmap.Height    :=    hc.Height;   

       Bitmap.Canvas.Draw(0,    0,    hc    );   

   //把bitmap傳給speedbutton.glyph   

       SpeedButton1.Glyph:=bitmap;   

   //釋放資源   

       hc.Free;   

       Bitmap.Free;   

   end;

繼續閱讀