title image


Smiley Hier isser (viel war nicht nötig ...)
IMHO ist dein Code schon ziemlich korrekt gewesen ... hab noch 2 TRYs eingebaut (zur Sicherheit). Dieses Beispiel funzt bei mir ... Problem ist, die vorhandene Ressource zu treffen (vorher auflisten, dann wählen lassen wäre ein Workaround).



program Project1;

{$APPTYPE CONSOLE}

uses Windows;



type

PICONDIRENTRYCOMMON = ^ICONDIRENTRYCOMMON;

ICONDIRENTRYCOMMON = packed record

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?

end;



PICONDIRENTRY = ^ICONDIRENTRY;

ICONDIRENTRY = packed record

common: ICONDIRENTRYCOMMON;

dwImageOffset: DWord; // Where in the file is this image?

end;



PICONDIR = ^ICONDIR;

ICONDIR = packed record

idReserved: Word; // Reserved (must be 0)

idType: Word; // Resource Type (1 for icons)

idCount: Word; // How many images?

idEntries: ICONDIRENTRY; // An entry for each image (idCount of 'em)

end;



PGRPICONDIRENTRY = ^GRPICONDIRENTRY;

GRPICONDIRENTRY = packed record

common: ICONDIRENTRYCOMMON;

nID: Word; // the ID

end;



PGRPICONDIR = ^GRPICONDIR;

GRPICONDIR = packed record

idReserved: Word; // Reserved (must be 0)

idType: Word; // Resource type (1 for icons)

idCount: Word; // How many images?

idEntries: GRPICONDIRENTRY; // The entries for each image

end;



function UpdateApplicationIcon(icofile: PChar; exefile: PChar; resID:PcHar; LangID:DWORD): Boolean;

var

hInst,hFile: THandle;

id: ICONDIR;

pid: PICONDIR;

pgid: PGRPICONDIR;

uRead: DWord;

nSize: DWord;

pvFile: PByte;

begin

result := False;

hFile := CreateFile(icofile, GENERIC_READ, FILE_SHARE_READ, nil, OPEN_EXISTING, FILE_ATTRIBUTE_NORMAL, 0);

if hFile <> INVALID_HANDLE_VALUE then

try

ReadFile(hFile, id, sizeof(id), uRead, nil);

SetFilePointer(hFile, 0, nil, FILE_BEGIN);

GetMem(pid, sizeof(ICONDIR) + sizeof(ICONDIRENTRY));

GetMem(pgid, sizeof(GRPICONDIR) + sizeof(GRPICONDIRENTRY));



ReadFile(hFile, pid^, sizeof(ICONDIR) + sizeof(ICONDIRENTRY), uRead, nil);

move(pid^, pgid^, sizeof(GRPICONDIR));



pgid^.idEntries.common := pid^.idEntries.common;

pgid^.idEntries.nID := 1;

nSize := pid^.idEntries.common.dwBytesInRes;



GetMem(pvFile, nSize);

SetFilePointer(hFile, pid^.idEntries.dwImageOffset, nil, FILE_BEGIN);

ReadFile(hFile, pvFile^, nSize, uRead, nil);



hInst := BeginUpdateResource(exefile, False);

if hInst <> 0 then

try

result:=UpdateResource(hInst, RT_ICON, resID, LangID, pvFile, nSize);

finally

EndUpdateResource(hInst, False);

end;



FreeMem(pvFile);

FreeMem(pgid);

FreeMem(pid);



finally

CloseHandle(hFile);

end;

end;





begin

if ParamCount < 2 then

begin

Writeln('First Parameter indicates the icon file and the second indicates the executable');

halt(0);

end;

if UpdateApplicationIcon(@ParamStr(1)[1], @ParamStr(2)[1], MAKEINTRESOURCE(1), 1031) then

Writeln('Icon successfully updated')

else

Writeln('Icon update failed Errorcode:', GetLastError());

end.

geschrieben von

Login

E-Mail:
  

Passwort:
  

Beitrag anfügen

Symbol:
 
 
 
 
 
 
 
 
 
 
 
 
 

Überschrift: