日韩性视频-久久久蜜桃-www中文字幕-在线中文字幕av-亚洲欧美一区二区三区四区-撸久久-香蕉视频一区-久久无码精品丰满人妻-国产高潮av-激情福利社-日韩av网址大全-国产精品久久999-日本五十路在线-性欧美在线-久久99精品波多结衣一区-男女午夜免费视频-黑人极品ⅴideos精品欧美棵-人人妻人人澡人人爽精品欧美一区-日韩一区在线看-欧美a级在线免费观看

歡迎訪問 生活随笔!

生活随笔

當前位置: 首頁 > 编程资源 > 编程问答 >内容正文

编程问答

Delphi替换PE图标资源

發布時間:2024/4/18 编程问答 32 豆豆
生活随笔 收集整理的這篇文章主要介紹了 Delphi替换PE图标资源 小編覺得挺不錯的,現在分享給大家,幫大家做個參考.
program Project2;

uses
? Windows,Classes;

type
??? icondirentry=packed record
?????? bwidth:Byte;???? //該目錄對應的資源的寬度
?????? bheight:Byte;?? //該目錄對應的資源的高度
?????? bcolorcount:Byte;??? //該目錄對應的資源的顏色總數,大于8的資源該值為零
?????? breserved:Byte; //保留
?????? wplanes:word; //指定的設備號,如無意外,該值總是為1
?????? wbitcount:word; //該目錄對應的資源的位數(色深)
?????? dwbytesinres:Dword;?? //該目錄對應的資源占用的字節數
?????? dataoffset:Dword; //該目錄對應的資源在文件中的位置(偏移量)
???? end;

???? iconheader=packed record
?????? idreserved:word; //保留
?????? idtype:word; //資源類型,圖標文件為1,光標文件為2
?????? idcount:word; //該ico文件中共有幾個圖標,該值決定了icondirentry結構的數目,可見一個ico文件中可能包含幾個圖標的數據,替換到exe中要分別考慮。
???? end;

var
?? icofile:Tmemorystream;
?? Uh:Cardinal;
?? rdata:Pbyte;
?? header:iconheader;
?? Dgroup:array of icondirentry;
?? i,besti,bestc,bestsize:integer;
?? SourceIcon,TargetFile:String;
begin
?? SourceIcon:='C:/Program Files/58.ico'; //圖標16x16規格
?? TargetFile:='C:/Program Files/1.exe';
?? icofile:=Tmemorystream.Create;
?? icofile.LoadFromFile(Pchar(SourceIcon)); //SourceIcon可以換成ico文件的名稱
?? icofile.Position:=0;
?? icofile.ReadBuffer(header,sizeof(header));
?? setlength(Dgroup,header.idcount);?? //空出一位,防止出錯
?? bestc:=0;
?? bestsize:=0;
?? for i := 0 to header.idcount-1 do??? //忽略空出的一位
?? begin
?????? icofile.ReadBuffer(Dgroup[i],Sizeof(Dgroup[i]));
?????? if Dgroup[i].wbitcount>bestc then????????????????? //找到最適合做主圖標的圖標數據
???????? if Dgroup[i].bwidth>=bestsize then?????????????? //同上
???????? begin
???????????? bestc:=Dgroup[i].wbitcount;
???????????? bestsize:=Dgroup[i].bwidth;
???????????? besti:=i;
???????? end;
?? end;
?? icofile.Position:=Dgroup[besti].dataoffset;
?? getmem(rdata,Dgroup[besti].dwbytesinres);
?? icofile.ReadBuffer(rdata^,Dgroup[besti].dwbytesinres);

?? Uh:=Beginupdateresource(Pchar(TargetFile),false);
?? updateresource(Uh,RT_ICON,pchar(chr(6)),2052,rdata,Dgroup[besti].dwbytesinres); //替換6號位置
endupdateresource(Uh,false);

?? icofile.Free;

end.

總結

以上是生活随笔為你收集整理的Delphi替换PE图标资源的全部內容,希望文章能夠幫你解決所遇到的問題。

如果覺得生活随笔網站內容還不錯,歡迎將生活随笔推薦給好友。