很好做,临时给你写了个函数,拿去用吧,nt/2000/xp下才能用,如果在9x下用,需要客户
安装额外的包,我忘了叫什么了,呵呵
type
icondir = packed record
reserved: word;
ictype: word;
count: word;
width: byte;
height: byte;
colorcount: byte;
reserve: byte;
schema: word;
bitcount: word;
bytesinres: dword;
imageoffset: dword;
end;
function puticon(exe, ico: string;
resid, lang: integer): boolean;
var icon: thandle;
hexe: thandle;
buffer: pointer;
size, read: dword;
idir: icondir;
begin
result := true;
icon := createfile(pchar(ico), generic_read, file_share_read, nil, Open_existing, file_attribute_normal, 0);
if icon = 0 then
result := false;
if not ReadFile(icon, idir, sizeof(idir), read, nil) then
result := false;
size := idir.bytesinres;
getmem(buffer, size);
SetFilePointer(icon, idir.imageoffset, NiL, FILE_begin
);
if not ReadFile(icon, buffer^, size, read, nil) then
result := false;
closehandle(icon);
hEXE := begin
UpdateResource(pchar(exe), false);
if hEXE<>0 then
begin
if not UpdateResource(hEXE, RT_ICON, MAKEINTRESOURCE(resid), lang, buffer, read) then
result := false;
if not EndUpdateResource(hEXE, false) then
result := false;
end;
freemem(buffer);
end;
注意,要换图标,你必须先用enum出资源,然后把里面的图标替换掉,有一个资源专门指定那个
图标作为exe的图标,替换掉就成了