Skylark Technology

about   clients   support   contact   

Windows Icon Software


Windows Icon Files - Programming Hints

STL Icon Converter

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
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;
File Content
  • First write the ICONDIR structure
  • Then, for each image in the icon:
    • Write an ICONDIRENTRY
  • After that, for each image:
    • 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

  • TA DA!

    » STL icon converter
    » buy a license for £6.99
    » STL port forward

    ©2000-09 Skylark Technology Ltd