本文整理自网络,侵删。
unit IconChanger; //国外拔过来的 www.delphitop.com
interface
uses windows, Classes;
var PVFile : PByte;
type ICONINFORMATION = packed record width : Byte; height : Byte; colorc : Byte; res : Byte; planes : Word; bitcnt : Word; bytes : DWORD; offset : DWORD; end;
ICONHEADER = packed record res : Word; restype: Word; count : Word; end;
ICONDIRENTRYCOMMON = packed record width : Byte; height : Byte; colorc : Byte; res : Byte; planes : Word; bitcnt : Word; bytes : DWORD; id : Word; end;
function UpdateApplicationIcon(srcicon : string; destexe : string) : Boolean;
implementation
function UpdateApplicationIcon(srcicon : string; destexe : string) : Boolean;var i : Integer; Src, grpic : TMemoryStream; id : ICONINFORMATION; ih : ICONHEADER; ic : ICONDIRENTRYCOMMON; hinst : LongInt; oldentry : Int64;begin Result := False; Src := TMemoryStream.Create; grpic := TMemoryStream.Create; Src.LoadFromFile(srcicon); Src.Read(ih, SizeOf(ICONHEADER)); grpic.Write(ih, SizeOf(ih)); oldentry := Src.Position; for i := 0 to ih.count - 1 do begin Src.Position := oldentry; hinst := BeginUpdateResource(PChar(destexe), False); Src.Read(id, SizeOf(ICONINFORMATION)); ic.width := id.width; ic.height := id.height; ic.colorc := id.colorc; ic.res := id.res; ic.planes := id.planes; ic.bitcnt := id.bitcnt; ic.id := i; ic.bytes := id.bytes; grpic.Write(ic, SizeOf(ic)); GetMem(PVFile, id.bytes); oldentry := Src.Position; Src.Seek(id.offset, soFromBeginning); Src.Read(PVFile^, id.bytes); UpdateResource(hinst, RT_ICON, MAKEINTRESOURCE(i), LANG_NEUTRAL, PVFile, id.bytes); EndUpdateResource(hinst, False); end; hinst := BeginUpdateResource(PChar(destexe), False); UpdateResource(hinst, RT_GROUP_ICON, MAKEINTRESOURCE(0), LANG_NEUTRAL, grpic.Memory, grpic.Size); EndUpdateResource(hinst, False); grpic.Free; Src.Free;end;
end.
相关阅读 >>
Delphi winapi: setvolumelabel - 设置磁盘卷标
Delphi searchrec.attr and fadirectory
Delphi 获取image.picture.data的数据
Delphi xe5 android获取手机联系人,并用listview显示
更多相关阅读请进入《Delphi》频道 >>