type
...
TIconDir = packed record // die 3 Anfangswörter eines IconFiles
idReserved: Word; // Reserved (must be 0)
idType: Word; // Resource Type (1 for icons)
idCount: Word; // How many images?
end;
TIconDirEntry = packed record // An entry for each image
bWidth: Byte; // Width, in pixels, of the image
bHeight: Byte; // Height, in pixels, of the image
bColorCount: Byte; // Number of colors in image (0 if >=8bpp)
bReserved: Byte; // Reserved ( must be 0)
wPlanes: Word; // Color Planes
wBitCount: Word; // Bits per pixel
dwBytesInRes: DWord; // How many bytes in this resource?
dwImageOffset: DWord; // Where in the file is this image?
end;
.
.
.
procedure TForm1.ExchangeIcon (Ikone : TIcon);
const Filename = 'C:\Programme\Borland\Delphi7\Projects\Probs\IconOverwrite\FileXY.exe';
var URHandle : HWnd;
MemStream : TMemoryStream;
begin
URHandle := BeginUpdateResource(PChar(Filename),FALSE);
if URHandle = 0 then begin
showMessage('keine UR-
Handle erhaltbar!');
exit;
end;
MemStream := TMemoryStream.Create;
try
Ikone.SaveToStream(MemStream); // im Stream entsteht da immer die 1-Icon-Filestruktur!
UpdateResource(URHandle,
RT_ICON,
MakeIntResource(1), // = OrdnerNummer (siehe im ResourceHacker)
1031,
Pointer(longint(MemStream.Memory) + SizeOf(TIconDir) + SizeOf(TIconDirEntry)),
MemStream.Size - SizeOf(TIconDir) - SizeOf(TIconDirEntry));
finally
EndUpdateResource(URHandle, False);
MemStream.free;
end;
end;