problem with APIs (BeginUpdateResource, UpdateRe.......etc)
Posted: Thu Jun 29, 2006 9:15 am
hi
i wrote this little code to change the icon of my program, but it didn't work, i don't know where is the problem, is it in this APIs or in my program, or in my code..
this is the code:
btw, i can chage the icon of my program in (Resource Hacker)...
and after this code the file size is increased by the size of the icon
could you please correct this code, or give me the simplest code to change the icon ... " i use windows XP "
Thank you alot in advance....
i wrote this little code to change the icon of my program, but it didn't work, i don't know where is the problem, is it in this APIs or in my program, or in my code..
this is the code:
Code: Select all
procedure TForm1.Button1Click(Sender: TObject);
var
hFile, hIcon Thandle;
p: Pointer;
dwReadBytes: DWORD;
begin
hFile:= BeginUpdateResource(Pchar('MyFile.exe'), TRUE);
hIcon:= CreateFile(Pchar('AnyIcon.ico'), GENERIC_READ, FILE_SHARE_READ, NIL,
OPEN_EXISTING, FILE_ATTRIBUTE_NORMAL, 0);
If hIcon <> INVALID_HANDLE_VALUE then
GetMem(p, GetFileSize(hIcon, nil));
ReadFile(hIcon, p^, GetFileSize(hIcon, nil), dwReadBytes, nil);
UpdateResource(hFile, RT_GROUP_ICON, Pchar('ICON'), 0, p, GetFileSize(hFile, nil));
UpdateResource(hFile, RT_ICON, Pchar('1'), 0, p, GetFileSize(hFile, nil));
EndUpdateResource(hFile, false);
CloseHandle(hFile);
CloseHandle(hIcon);
end;
btw, i can chage the icon of my program in (Resource Hacker)...
and after this code the file size is increased by the size of the icon
could you please correct this code, or give me the simplest code to change the icon ... " i use windows XP "
Thank you alot in advance....