Windows Icon Files - Programming Hints
We created STL Icon Converter - a c++/mfc windows application that allows you to convert images (bmp, gif, jpeg...)
to windows icon files (.ico) - after finding it surprisingly difficult to do programatically.
We also found it very difficult to find any program examples on the web for helping you do this.
So... I thought I'd put some handy hints here, for those of you who feel like a challenge, and are too
cheap to pay the £6.99 license fee!
- ICON Structures
- File Content
typedef struct
{
WORD idReserved; // Reserved (must be 0)
WORD idType; // Resource Type (1 for icons)
WORD idCount; // How many images?
ICONDIRENTRY idEntries[1]; // An entry for each image (idCount of 'em)
} ICONDIR, *LPICONDIR;
typedef struct
{
BYTE bWidth; // Width, in pixels, of the image
BYTE bHeight; // Height, in pixels, of the image
BYTE bColorCount; // Number of colors in image (0 if >=8bpp)
BYTE bReserved; // Reserved (must be 0)
WORD wPlanes; // Color Planes
WORD wBitCount; // Bits per pixel
DWORD dwBytesInRes; // How many bytes in this resource?
DWORD dwImageOffset;// Where in the file is this image?
} ICONDIRENTRY, *LPICONDIRENTRY;
typedef struct
{
BITMAPINFOHEADER icHeader; // DIB header
RGBQUAD icColors[1]; // Color table
BYTE icXOR[1]; // DIB bits for XOR mask
BYTE icAND[1]; // DIB bits for AND mask
} ICONIMAGE, *LPICONIMAGE;
- Write an ICONDIRENTRY
- Write a BITMAPINFOHEADER (note: the height entry must be twice the height of the image, to allow for the fact that the image is followed by a 1 bpp mask image)
- Write out RGBQUADs for the palette
- Follow with the actual bitmap bits
- And finally a 1 bit per pixel mask image
- Note these need to be DWORD aligned, so pad with extra bytes where necessary
» buy a license for £6.99
» STL port forward

