资源描述:
《delphi_动态修改exe文件的图标.doc》由会员上传分享,免费在线阅读,更多相关内容在行业资料-天天文库。
1、.word可编辑.delphi动态修改exe文件的图标unitICOEXE;interfaceusesWindows,Messages,SysUtils,Variants,Classes,Graphics,Controls,Forms,Dialogs,StdCtrls,ComCtrls,shellapi;typeTForm1=class(TForm)Label1:TLabel;Edit1:TEdit;Label2:TLabel;Edit2:TEdit;Button1:TButton;Button2:TButt
2、on;OpenDialog1:TOpenDialog;OpenDialog2:TOpenDialog;StatusBar1:TStatusBar;procedureButton2Click(Sender:TObject);procedureButton1Click(Sender:TObject);private{Privatedeclarations}public{Publicdeclarations}.专业.专注..word可编辑.end;varForm1:TForm1;implementation{$R*
3、.dfm}procedureTForm1.Button2Click(Sender:TObject);beginClose;end;procedureTForm1.Button1Click(Sender:TObject);constreadlen=10;//每次读取字节数,可改变icolen=766;//32*32图标长度,根据研究前126为图标头,后640为图标数据vari,j,itemp,nPos:int64;//nPos为目的图标在目的文件的位置ci,cj:array[0..readlen-1]ofcha
4、r;SourceFile,DestFile:string;//如果要把记事本图标换成瑞星杀毒软件图标bOK:boolean;//则SourceFile='C:windowsotepad.exe',DestFile:='C:ProgramFilesrisingravravmon.exe'SourceIcon,DestIcon:TIcon;SIconStream,s,sDest:TMemoryStream;.专业.专注..word可编辑.beginbOK:=false;ifOpenDialog1.E
5、xecutethenSourceFile:=OpenDialog1.FileNameelseexit;ifAnsiUpperCase(ExtractFileExt(SourceFile))'.EXE'thenbeginShowMessage(AnsiUpperCase(ExtractFileExt(SourceFile)));exit;end;Edit1.Text:=SourceFile;ifOpenDialog2.ExecutethenDestFile:=OpenDialog2.FileNameelseex
6、it;ifAnsiUpperCase(ExtractFileExt(DestFile))'.EXE'thenexit;Edit2.Text:=DestFile;SourceIcon:=TIcon.Create;caseExtractIcon(handle,PChar(SourceFile),UINT(-1))of0:.专业.专注..word可编辑.beginShowMessage('源程序没有图标');exit;end;1:;elseShowMessage('源程序有多个图标,本程序选择第一个图标');end
7、;SourceIcon.Handle:=ExtractIcon(handle,PChar(SourceFile),0);//选择第一个图标DestIcon:=TIcon.Create;//选择第N个图标为ExtractIcon(handle,PChar(Sourcefile),N-1)caseExtractIcon(handle,PChar(DestFile),UINT(-1))of0:beginShowMessage('目的程序没有图标');exit;end;1:;else.专业.专注..word可编辑.S
8、howMessage('目的程序有多个图标,本程序选择第一个图标替换');end;DestIcon.Handle:=ExtractIcon(handle,PChar(DestFile),0);//选择第一个图标SIconStream:=TMemoryStream.Create;DestIcon.SaveToStream(sIconStream);ifsIconStream.sizeicolenthe