如何更改EXE、DLL文件中的图标资源 我已经知道如何从exe、dll文件中提取图标资源,那么如何更换呢?向exeScope那样把一个exe文件的图标给换了 解决方案 » 免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货 可以用VC++ (不能在win9x me上),如果有興趣,我再細說 Borland 的程序可以用Resource Workshop 来修改。VC的 可以用VC或LocStudio修改。 我的意思是说如何用Delphi编程实现图标更换,‘生鱼片’朋友说的方法,好像只能提取图标。 是要修改EXE文件的图标?这可是有商业价值的!在http://www.softreg.com.cn/里就有一个。 不过原EXE文件不能被加过壳,否则一定不行,偶是从来没解壳成功过,呵呵,可能是偶的水平太凹了吧 难道大家还没明白我的意思吗?我是说编一个程序,它可以更换别的EXE文件的图标资源。那么怎样做? unit Exeicointerfaceuses Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms, Dialogs, StdCtrls, ComCtrls,shellapi;type TForm1 = class(TForm) Label1: TLabel; Edit1: TEdit; Label2: TLabel; Edit2: TEdit; Button1: TButton; Button2: TButton; OpenDialog1: TOpenDialog; OpenDialog2: TOpenDialog; StatusBar1: TStatusBar; procedure Button2Click(Sender: TObject); procedure Button1Click(Sender: TObject); private { Private declarations } public { Public declarations } end;var Form1: TForm1;implementation{$R *.dfm}procedure TForm1.Button2Click(Sender: TObject);begin Close;end;procedure TForm1.Button1Click(Sender: TObject);const readlen=10; //每次读取字节数,可改变 icolen=766;//32*32图标长度,根据研究前126为图标头,后640为图标数据var i,j,itemp,nPos:int64;// nPos为目的图标在目的文件的位置 ci,cj:array[0..readlen-1] of char; SourceFile,DestFile:String; bOK:boolean; SourceIcon,DestIcon:TIcon; SIconStream,s,sDest:TMemoryStream;begin bOK:=false; if OpenDialog1.Execute then SourceFile:=OpenDialog1.FileName else exit; if AnsiUpperCase(ExtractFileExt(SourceFile))<>'.EXE' then begin ShowMessage(AnsiUpperCase(ExtractFileExt(SourceFile))); exit; end; Edit1.Text:=SourceFile; if OpenDialog2.Execute then DestFile:=OpenDialog2.FileName else exit; if AnsiUpperCase(ExtractFileExt(DestFile))<>'.EXE' then exit; Edit2.Text:=DestFile; SourceIcon:=TIcon.Create; case ExtractIcon(handle,PChar(SourceFile),UINT(-1)) of 0:begin ShowMessage('源程序没有图标');exit;end; 1:; else ShowMessage('源程序有多个图标,本程序选择第一个图标'); end; SourceIcon.Handle:=ExtractIcon(handle,PChar(SourceFile),0);//选择第一个图标 DestIcon:=TIcon.Create;//选择第N个图标为 ExtractIcon(handle,PChar(SourceFile),N-1) case ExtractIcon(handle,PChar(DestFile),UINT(-1)) of 0:begin ShowMessage('目的程序没有图标');exit;end; 1:; else ShowMessage('目的程序有多个图标,本程序选择第一个图标替换'); end; DestIcon.Handle:=ExtractIcon(handle,PChar(DestFile),0);//选择第一个图标 SIconStream:=TMemoryStream.Create; DestIcon.SaveToStream(sIconStream); if sIconStream.size<>icolen then ShowMessage('SIcon.size<>icolen'); SDest:=TMemoryStream.Create; sDest.LoadFromFile(DestFile); i:=0;j:=0; //以下程序查找目的图标在目的程序中的位置 while i< sDest.size do begin itemp:=i; j:=126;{ repeat SDest.Position:=i; sDest.read(ci,Readlen); SiconStream.Position:=j; SIconStream.Read(cj,Readlen); i:=i+Readlen; j:=j+Readlen; until (String(ci)=String(cj)) and (i<sDest.size) and (j<icolen);} ci:='';cj:=''; while (String(ci)=String(cj)) and (i<SDest.size) and (j<icolen) do begin i:=i+readlen; j:=j+readlen; SDest.Position:=i; SDest.read(ci,readlen); SiconStream.Position:=j; SiconStream.Read(cj,readlen); end; if j<icolen then i:=itemp+1 //没找到 else begin nPos:=itemp; //找到 bOK:=true; break; end; end; if bOK=false then exit;//目标文件二进制码中未找到图标 SIconStream.Clear;//将源程序图标存入 SourceIcon.SaveToStream(SIconStream); SIconStream.position:=126; s:=TMemoryStream.Create; sDest.Position:=0; s.CopyFrom(sDest,nPos);//将目的程序图标前数据拷入 s.CopyFrom(SIconStream,640); //将源程序图标拷入 if sDest.size>sDest.Position+640 then //将目的程序剩余数据拷入 begin sDest.Position:=sDest.Position+640; s.CopyFrom(sDest,sDest.Size-sDest.Position); end; s.SaveToFile(Extractfilepath(application.exename)+'Result.exe'); SourceIcon.Free;DestIcon.Free; //改造好的程序存放在本目录Result.exe文件中 SIconStream.Free;s.Free;sDest.Free; ShowMessage(Extractfilepath(application.exename)+'Result.exe');end; 非常感谢‘ehom’老兄。区区30分送上,不成敬意 delphi工程存储路径的相关问题 各位老大救命啊 求助ADOTable的保存问题 特急!!!关于数据连接,和局域网中搜索服务器的问题 SQL方法问题 XML问题:怎么发送XML命令和读取XML文档(在线等待) 请问怎么实现象网络蚂蚁那样的浮动窗口? 寻求触摸屏的后台更新解决方案? 怎样在运行时创建控件? 毕业了,要和女朋友分开了,郁闷 散分 谁用过Delphi的打包工具,怎么可以把程序放如程序菜单里中,和桌面上生成快捷方式?? 怎么判断,键盘按下了↑↓←→这四个按键!
如果有興趣,我再細說
在http://www.softreg.com.cn/里就有一个。
否则一定不行,偶是从来没解壳成功过,
呵呵,可能是偶的水平太凹了吧
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs, StdCtrls, ComCtrls,shellapi;type
TForm1 = class(TForm)
Label1: TLabel;
Edit1: TEdit;
Label2: TLabel;
Edit2: TEdit;
Button1: TButton;
Button2: TButton;
OpenDialog1: TOpenDialog;
OpenDialog2: TOpenDialog;
StatusBar1: TStatusBar;
procedure Button2Click(Sender: TObject);
procedure Button1Click(Sender: TObject);
private
{ Private declarations }
public
{ Public declarations }
end;var
Form1: TForm1;implementation{$R *.dfm}procedure TForm1.Button2Click(Sender: TObject);
begin
Close;
end;procedure TForm1.Button1Click(Sender: TObject);
const
readlen=10; //每次读取字节数,可改变
icolen=766;//32*32图标长度,根据研究前126为图标头,后640为图标数据
var
i,j,itemp,nPos:int64;// nPos为目的图标在目的文件的位置
ci,cj:array[0..readlen-1] of char;
SourceFile,DestFile:String;
bOK:boolean;
SourceIcon,DestIcon:TIcon;
SIconStream,s,sDest:TMemoryStream;
begin
bOK:=false;
if OpenDialog1.Execute then
SourceFile:=OpenDialog1.FileName
else
exit;
if AnsiUpperCase(ExtractFileExt(SourceFile))<>'.EXE' then
begin
ShowMessage(AnsiUpperCase(ExtractFileExt(SourceFile)));
exit;
end;
Edit1.Text:=SourceFile;
if OpenDialog2.Execute then
DestFile:=OpenDialog2.FileName
else
exit;
if AnsiUpperCase(ExtractFileExt(DestFile))<>'.EXE' then
exit;
Edit2.Text:=DestFile;
SourceIcon:=TIcon.Create;
case ExtractIcon(handle,PChar(SourceFile),UINT(-1)) of
0:begin ShowMessage('源程序没有图标');exit;end;
1:;
else ShowMessage('源程序有多个图标,本程序选择第一个图标');
end;
SourceIcon.Handle:=ExtractIcon(handle,PChar(SourceFile),0);//选择第一个图
标
DestIcon:=TIcon.Create;//选择第N个图标为 ExtractIcon(handle,PChar(Source
File),N-1)
case ExtractIcon(handle,PChar(DestFile),UINT(-1)) of
0:begin ShowMessage('目的程序没有图标');exit;end;
1:;
else ShowMessage('目的程序有多个图标,本程序选择第一个图标替换');
end;
DestIcon.Handle:=ExtractIcon(handle,PChar(DestFile),0);//选择第一个图标
SIconStream:=TMemoryStream.Create;
DestIcon.SaveToStream(sIconStream);
if sIconStream.size<>icolen then
ShowMessage('SIcon.size<>icolen');
SDest:=TMemoryStream.Create;
sDest.LoadFromFile(DestFile);
i:=0;j:=0; //以下程序查找目的图标在目的程序中的位置
while i< sDest.size do
begin
itemp:=i;
j:=126;
{ repeat
SDest.Position:=i;
sDest.read(ci,Readlen);
SiconStream.Position:=j;
SIconStream.Read(cj,Readlen);
i:=i+Readlen;
j:=j+Readlen;
until (String(ci)=String(cj)) and (i<sDest.size) and (j<icolen);
} ci:='';cj:='';
while (String(ci)=String(cj)) and (i<SDest.size) and (j<
icolen) do
begin
i:=i+readlen;
j:=j+readlen;
SDest.Position:=i;
SDest.read(ci,readlen);
SiconStream.Position:=j;
SiconStream.Read(cj,readlen);
end;
if j<icolen then
i:=itemp+1 //没找到
else
begin
nPos:=itemp; //找到
bOK:=true;
break;
end;
end;
if bOK=false then
exit;//目标文件二进制码中未找到图标
SIconStream.Clear;//将源程序图标存入
SourceIcon.SaveToStream(SIconStream); SIconStream.position:=126;
s:=TMemoryStream.Create; sDest.Position:=0;
s.CopyFrom(sDest,nPos);//将目的程序图标前数据拷入
s.CopyFrom(SIconStream,640); //将源程序图标拷入
if sDest.size>sDest.Position+640 then //将目的程序剩余数据拷入
begin
sDest.Position:=sDest.Position+640;
s.CopyFrom(sDest,sDest.Size-sDest.Position);
end;
s.SaveToFile(Extractfilepath(application.exename)+'Result.exe');
SourceIcon.Free;DestIcon.Free; //改造好的程序存放在本目录Result.exe文件中
SIconStream.Free;s.Free;sDest.Free;
ShowMessage(Extractfilepath(application.exename)+'Result.exe');
end;