delphi 修改exe应用程序图标


本文整理自网络,侵删。

 
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 对非活动窗口进行屏幕截图

Delphi winapi: setvolumelabel - 设置磁盘卷标

Delphi如何计算一个文件目录的大小

Delphi searchrec.attr and fadirectory

Delphi 获取image.picture.data的数据

Delphi xe5 android获取手机联系人,并用listview显示

Delphi的获取某坐标的颜色值

Delphi xe6 读取android设备联系人

Delphi tadodataset 中文使用说明

Delphi 监控其它进程

更多相关阅读请进入《Delphi》频道 >>



打赏

取消

感谢您的支持,我会继续努力的!

扫码支持
扫码打赏,您说多少就多少

打开支付宝扫一扫,即可进行扫码打赏哦

分享从这里开始,精彩与您同在

评论

管理员已关闭评论功能...