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.

相关阅读 >>

Delphi trunc转换函数

Delphi mailurlmaybeinvalid 检测邮箱地址有效性

Delphi 先加载原内容在写入增加新内容

Delphi 无法结束进程的程序

dbgrideh 组件在borland开发工具中应用全攻略

winapi 字符及字符串函数(11): lstrcpyn - 复制字符串, 同时指定要复制的长度

Delphi intraweb 在iis下发布的web.config

Delphi 使用edge browser浏览器组件

Delphi webbrowser 无法调用当前浏览器的版本

Delphi rs232c串行通讯接口的应用

更多相关阅读请进入《Delphi》频道 >>



打赏

取消

感谢您的支持,我会继续努力的!

扫码支持
扫码打赏,您说多少就多少

打开支付宝扫一扫,即可进行扫码打赏哦

分享从这里开始,精彩与您同在

评论

管理员已关闭评论功能...