参看了几个别人写下的程序,自己手动用delphi写了个从DLL,EXE,ICL中提取图标的小程序;程序还不太完整,由于Delphi的限制,提取出来的图标会降至16色;
代码如下:
unit Main;
Interface uses interface
uses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs, Menus, ComCtrls, ShellAPI, ImgList, ExtDlgs, ExtCtrls, StdCtrls;
type
TMain_Fr = Class (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.
Interface uses interface
uses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs, Menus, ComCtrls, ShellAPI, ImgList, ExtDlgs, ExtCtrls, StdCtrls;
type
TMain_Fr = Class (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.