code
Code: Select all
Structure ICONDIRENTRY
bWidth.a; // Width, in pixels, of the image
bHeight.a; // Height, in pixels, of the image
bColorCount.a; // Number of colors in image (0 if >=8bpp)
bReserved.a ; // Reserved ( must be 0)
wPlanes.u ; // Color Planes
wBitCount.u ; // Bits per pixel
dwBytesInRes.l; // How many bytes in this resource?
dwImageOffset.l; // Where in the file is this image?
EndStructure
Structure ICONDIR
idReserved.u; // Reserved (must be 0)
idType.u ; // Resource Type (1 for icons)
idCount.u ; // How many images?
EndStructure
Structure GroupIconData
bWidth.a; // Width, in pixels, of the image
bHeight.a; // Height, in pixels, of the image
bColorCount.a; // Number of colors in image (0 if >=8bpp)
bReserved.a ; // Reserved ( must be 0)
wPlanes.u ; // Color Planes
wBitCount.u ; // Bits per pixel
dwBytesInRes.l; // How many bytes in this resource?
OrdinalName.u ; // Where in the file is this image?
EndStructure
Structure IconGroupHeader
idReserved.u; // Reserved (must be 0)
idType.u ; // Resource Type (1 for icons)
idCount.u ; // How many images?
GroupIconData.GroupIconData[0]
EndStructure
EnableExplicit
Procedure SetExeIcone(exepath.s, ;exe full path
*pdata.ICONDIR, ;icon data
*name, ;name Resource
lang = 0) ;lang Resource
;return 1 = successfully.
Protected Result
Protected *hgi.IconGroupHeader = AllocateMemory(SizeOf(IconGroupHeader)+
(SizeOf(GroupIconData) * (*pdata\idCount+1)))
If *hgi
CopyStructure(*pdata, *hgi, ICONDIR)
With *hgi
Protected hResource = BeginUpdateResource_(exepath, 0);
If hResource <> 0
Protected ii, *icd.ICONDIRENTRY
For ii = 0 To *pdata\idCount-1
*icd = *pdata + SizeOf(ICONDIR) + (SizeOf(ICONDIRENTRY) * ii)
CopyStructure(*icd, \GroupIconData[ii],GroupIconData)
\GroupIconData[ii]\OrdinalName = ii+1
Result = UpdateResource_(hResource, #RT_ICON, \GroupIconData[ii]\OrdinalName,lang,
*pdata + *icd\dwImageOffset, *icd\dwBytesInRes)
If Result = 0
Break
EndIf
Next
If Result <> 0
Result = UpdateResource_(hResource, #RT_GROUP_ICON, *name, lang,
*hgi, SizeOf(IconGroupHeader)+(SizeOf(GroupIconData) * (*pdata\idCount)))
EndIf
EndUpdateResource_(hResource, 0)
EndWith
EndIf
FreeMemory(*hgi)
EndIf
ProcedureReturn Result
EndProcedure
Define filename.s="test.exe"
Define iconpath.s="2.ico"
Define size =FileSize(iconpath)
If size>0
Define *mem=AllocateMemory(size)
ReadFile(0,iconpath)
ReadData(0,*mem,size)
CloseFile(0)
EndIf
Debug SetExeIcone(filename,*mem,1,2057)
End