delphi中从DLL,EXE,ICL中提取图标

    参看了几个别人写下的程序,自己手动用delphi写了个从DLL,EXE,ICL中提取图标的小程序;程序还不太完整,由于Delphi的限制,提取出来的图标会降至16色;
代码如下:

unit Main;

interface

uses
  Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
  Dialogs, Menus, ComCtrls, ShellAPI, ImgList, ExtDlgs, ExtCtrls, StdCtrls;

type
  TMain_Fr 
= class(TForm)
    MainMenu1: TMainMenu;
    N1: TMenuItem;
    DLL1: TMenuItem;
    N2: TMenuItem;
    N3: TMenuItem;
    N4: TMenuItem;
    OpenDialog1: TOpenDialog;
    StatusBar1: TStatusBar;
    ImageList1: TImageList;
    ListView1: TListView;
    SavePictureDialog1: TSavePictureDialog;
    Image1: TImage;
    GroupBox1: TGroupBox;
    Label1: TLabel;
    procedure N3Click(Sender: TObject);
    procedure DLL1Click(Sender: TObject);
    procedure FormCreate(Sender: TObject);
    procedure N2Click(Sender: TObject);
    procedure ListView1Click(Sender: TObject);
  
private
    { 
Private declarations }
  
public
    { 
Public declarations }
  
end;

var
  Main_Fr: TMain_Fr;


implementation

{$R 
*.dfm}
//退出
procedure TMain_Fr.N3Click(Sender: TObject);
begin
  Application.Terminate;
end;
//载入图标
procedure TMain_Fr.DLL1Click(Sender: TObject);
var
  Count,i:
Integer;
  myIcon :TIcon;
  Icon_Item:TListItem;
begin
  
try
    
if OpenDialog1.Execute then
    begin
      StatusBar1.Panels[
3].Text := OpenDialog1.FileName;
      Count :
= ExtractIcon( Application.Handle, PChar(StatusBar1.Panels[3].Text),$FFFFFFFF);
      StatusBar1.Panels[
1].Text := IntToStr(Count);
      
if Count>0 then
      begin
        Self.ListView1.Items.Clear;
        Self.ImageList1.Clear;
        myIcon :
= TIcon.Create;
        
for i := 0 to Count -1 do
        begin
          myIcon.Handle :
= ExtractIcon(Application.Handle,PChar(StatusBar1.Panels[3].Text),i);
          Self.ImageList1.AddIcon(myIcon);
          Icon_Item :
= Self.ListView1.Items.Add;
          Icon_Item.Caption :
= IntToStr(i+1);
          Icon_Item.ImageIndex :
= i;
        
end;
      
end;
    
end;
  except
    
Exit;
  
end;
end;
//初始化
procedure TMain_Fr.FormCreate(Sender: TObject);
begin
  Self.ListView1.LargeImages :
= Self.ImageList1;
  Self.ImageList1.Height :
= 32;
  Self.ImageList1.Width :
= 32;
  Self.Label1.Caption :
= '';
  OpenDialog1.Title:='选择EXE文件或DLL文件:';
  OpenDialog1.Filter:='提取文件(*.EXE;*.DLL;*.ICO;*.ICL)|*.DLL;*.EXE;*.ICO;*.ICL|All files (*.*)|*.*';
  OpenDialog1.FilterIndex:=1;
end;
//另存为图标
procedure TMain_Fr.N2Click(Sender: TObject);
begin
  
if ListView1.ItemIndex >=0 then
  begin
    SavePictureDialog1.DefaultExt :
= GraphicExtension(TIcon);
    SavePictureDialog1.Filter :
= GraphicFilter(TIcon);
    
if SavePictureDialog1.Execute then image1.Picture.SaveToFile(SavePictureDialog1.FileName);
 
end;
end;
//图标选择
procedure TMain_Fr.ListView1Click(Sender: TObject);
begin
  
if ListView1.ItemIndex >=0 then
  begin
    Label1.Caption :
= '您选中了第 '+IntToStr(ListView1.ItemIndex+1)+' 个图标';
    image1.Picture.Icon.Handle := ExtractIcon(Application.Handle,PChar(StatusBar1.Panels[3].Text),ListView1.ItemIndex);
  
end;
end;
 
end.
  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值