管理

Delphi提取EXE,DLL文件图标

Posted on 2008-11-29 15:51  lzhdim  阅读(868)  评论(0编辑  收藏  举报

//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;
end;

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

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;

Copyright © 2000-2022 Lzhdim Technology Software All Rights Reserved