Googled for a long time examples of replacing the icon (I thought that the topic was already worn out), the only more or less working example

function EnumLangsFunc(hModule: Cardinal; lpType, lpName: PAnsiChar; wLanguage: Word; lParam: Integer): Boolean; stdcall; begin PWord(lParam)^ := wLanguage; Result := False; end; function GetResourceLanguage(hModule: Cardinal; lpType, lpName: PAnsiChar; var wLanguage: Word): Boolean; begin wLanguage := 0; EnumResourceLanguages(hModule, lpType, lpName, @EnumLangsFunc,Integer(@wLanguage)); Result := True; end; procedure updateIcons(const fileName, icoFileName: string); type PIcoItemHeader = ^TIcoItemHeader; TIcoItemHeader = packed record Width: byte; Height: byte; Colors: byte; Reserved: byte; Planes: word; BitCount: word; ImageSize: dword; end; PIcoItem = ^TIcoItem; TIcoItem = packed record Header: TIcoItemHeader; Offset: dword; end; PIcoHeader = ^TIcoHeader; TIcoHeader = packed record Reserved: word; Typ: word; ItemCount: word; Items: array [0..MaxInt shr 4 - 1] of TIcoItem; end; PGroupIconDirItem = ^TGroupIconDirItem; TGroupIconDirItem = packed record Header: TIcoItemHeader; Id: word; end; PGroupIconDir = ^TGroupIconDir; TGroupIconDir = packed record Reserved: word; Typ: word; ItemCount: word; Items: array [0..MaxInt shr 4 - 1] of TGroupIconDirItem; end; var ch: char; H: THandle; M: HMODULE; R: HRSRC; Res: HGLOBAL; GroupIconDir, NewGroupIconDir: PGroupIconDir; I: integer; wLanguage: word; FS: TFileStream; Ico: PIcoHeader; N: cardinal; NewGroupIconDirSize: longint; begin Ico:=nil; GroupIconDir:=nil; try fs:=TFileStream.Create(IcoFileName,fmOpenRead,fmShareDenyWrite); try N:=fs.Size; GetMem(Ico, N); fs.Read(Ico^,N) finally fs.Free end; H:=BeginUpdateResource(pChar(FileName), false); try M:=LoadLibraryEx(PChar(FileName), 0, LOAD_LIBRARY_AS_DATAFILE); try R := FindResource(M, 'MAINICON', RT_GROUP_ICON); if r <> 0 then begin GetResourceLanguage(M, RT_GROUP_ICON, 'MAINICON', wLanguage); Res:=LoadResource(M, R); GroupIconDir:=LockResource(Res); UpdateResource(H, RT_GROUP_ICON, 'MAINICON', wLanguage, nil, 0); for I:=0 to GroupIconDir.ItemCount-1 do begin wLanguage:=GetSystemDefaultLangID; UpdateResource(H, RT_ICON, MakeIntResource(GroupIconDir.Items[I].Id), wLanguage, nil, 0); end; NewGroupIconDirSize:=3*SizeOf(word)+Ico.ItemCount*sizeOf(TGroupIconDirItem); GetMem(NewGroupIconDir, NewGroupIconDirSize); try NewGroupIconDir.Reserved:=GroupIconDir.Reserved; NewGroupIconDir.Typ:=GroupIconDir.Typ; NewGroupIconDir.ItemCount:=Ico.ItemCount; for I:=0 to NewGroupIconDir.ItemCount-1 do begin NewGroupIconDir.Items[I].Header:=Ico.Items[I].Header; NewGroupIconDir.Items[I].Id:=I+1 end; for I:=0 to NewGroupIconDir.ItemCount-1 do UpdateResource(H, RT_ICON, MakeIntResource(NewGroupIconDir.Items[I].Id), wLanguage, Pointer(DWORD(Ico) + Ico.Items[I].Offset), Ico.Items[I].Header.ImageSize); UpdateResource(H, RT_GROUP_ICON, 'MAINICON', wLanguage, NewGroupIconDir, NewGroupIconDirSize); finally FreeMem(NewGroupIconDir) end; end; finally FreeLibrary(M) end; except EndUpdateResource(H, true); raise end; EndUpdateResource(H, False); finally FreeMem(Ico) end; end; 

But replaces the icons, not all EXE, can you tell me what the problem is? or advise a working example

  • "not all icons replace" - what's this? How far? - Igor
  • @Igor figurative expression)) which means "does not replace all icons," I'm sorry, if I did not put it that way - Lolidze
  • Now it is much clearer what is happening. - Igor
  • @Igor can help? - Lolidze
  • 2
    Why even replace other people's icons? - teran

0