Using XP-style, 32-bit png's as icons in Delphi - Shawn Oster
Shawn Oster (gravatar)

Using XP-style, 32-bit png's as icons in Delphi

There are some pretty great looking icons out there, with lovely drop shadows and alpha-blending, problem is they look pretty bad in Delphi since it doesn't fully support them. Below is how I use XP-style, 32-bit png images as icons inside my Delphi applications.

Create a resource file

  1. Get your image into an .ico format.  I use icon sushi to convert png images into icos.
  2. Create a new text file, save it as icons.rc (you can call it whatever you want).
  3. Edit the file and for each icon create an icon resource entry, like this:
    icon_edit    ICON    "edit.ico"

    icon_edit is the name of the resource, this is how you'll refer to it in code when you load it.

    ICON is the type of resource, in this case... well, you get it.

    "edit.ico" is the name of the icon file and it can include a path. A common pattern I use is to put all my icons in a folder, imaginatively named "icons" and then I include them like this:

    icon_edit ICON ".\icons\edit.ico"
    icon_copy ICON ".\icons\editcopy.ico"
    icon_paste ICON ".\icons\editpaste.ico"

  4. Compile the resource script into a resource file. I use Borland's Resource Compiler, brcc32. To make it so I don't have to drop down to DOS all the time I create a little batch file that I can double-click. It looks like this:
    brcc32 icons.rc

  5. Include the resource file in your project. You can include a resource in any of your unit files but I prefer to include it in the unit from where I'll be using it, such as the main form or a datamodule. Include it like this:
    {$R icons.res}
Prepare your Form

  1. Add a TImageList to your form. Change the Width & Height properties to match the size of the icons you want to load (32x32 for example).

  2. Download this file: It has routines that will enable your TImageList to support 32-bit XP style icons. I can't take any credit for these routines. I found them on someone else's site describing the exact same thing I am but I can't find it anymore.

  3. Unzip and add the uXPIcons.pas unit to your project.

  4. Create a new procedure called "InitializeImageList()" or some other fun name.

  5. Add the following code to your new procedure:
    AddIconResourceToImageList('icon_edit', ImageList1);
    AddIconResourceToImageList('icon_copy', ImageList1);

  6. AddIconResourceToImageList returns an integer which is the index of the icon just added, which can be used to set the GlyphIndex for any control that takes both an ImageList and a GlyphIndex.

  7. Call "InitializeImageList()" from your FormCreate().

  8. Run it and rock.

Update: One thing you'll notice is that now your main application icon has been replaced by the first icon in your resource file.  My suggestion is to just make sure your application icon is first in your resource file.  It actually works better for me since I often have to create versions of my applications with different main icons and being able to swap them out via different resource files using a build script is much easier. tags: , , , ,


  • Steve Trefethen (gravatar)

    Steve Trefethen said
    February 27, 2008

    Shawn, Good stuff. Btw, if you're interested I'm sure the guys at would be glad to add you to the list. Just shoot them an email.

  • Matt T. (gravatar)

    Matt T. said
    February 27, 2008

    For some reason when using this technique BDS 2006 keeps changing my application icon to one of the icons I add to the rc file. Any ideas why?

  • Steve Trefethen (gravatar)

    Steve Trefethen said
    February 27, 2008

    Then that's probably a good call. I've actually just requested to be moved off of DelphiFeeds because of that same issue.

  • Matt, that's something I've noticed as well and I simply put my application icon in as the first resource. I know, not the most elegant solution but it works, especially considering the fact that my app icon is almost always a 24-bit PNG as well.

  • Steve, thanks for the compliment. I'd probably add my feed except 1 out of every 5 posts is actually Delphi-related, the rest tend to be random writings :)

Your Information
Mrs. Gravatar (gravatar)

<-- It's a gravatar

your comment