Compiling compressed Windows Vista icons

Log-in or register.
rsrc/cpvi.png image

How to compile Windows Vista icons?

January 28th 2006

This article explains basic properties of Windows Vista icons and describes how to use Vista icons in your applications.

Find more information about Vista icons in an article explaining differences between XP and Vista icons.

Vista icons

Windows Vista icons contain a high resolution 256x256 pixels images. These images are used exclusively by Vista and they are stored using PNG-based compression. Explorer dynamically resamples them to required resolution.

An example vista icon with projected shadow
An icon with Vista image format. Large resolution makes it possible to add an additional effect - a projected shadow.

Compiling Vista icons

Although numerous dynamic libraries and executables in the current Vista build contain compressed icons, Visual Studio (including VS2005) resource compiler refuses to accept them and aborts with:
"error RC2176 : old DIB in VistaIcon.ico; pass it through SDKPAINT".

Solution

It is hard to guess when or how is Microsoft going to address this issue. Right now, it is necessary to use alternate resource compiler, manager, or tool.

The following tool was prepared to deal with the problem. It has a very simple command-line interface and you can integrate it into your build process as a post-build step. The tool can replace or add an icon into an executable file using the Windows resource API.

Download the tool from here: ReplaceVistaIcon.exe

The tool accepts two to four arguments:

ReplaceVistaIcon.exe executable.dll icon.ico [icon_ID [language_code]]

Note: If you have an exe file with multiple icons, Windows Explorer uses the first icon as the application icon when browsing folders or in start menu. Compile your application with an XP-compatible icon and then replace it using the tool. Although the tool is able to add new icon into an executable, it would add it at the end of icon list and Windows Explorer would ignore it.
Conclusion

If you have experience with Vista icons in other build environments such as gcc, Delphi, or Builder, please share your knowledge and add a comment below.

Resources

RealWorld Icon Editor homepage.

Recent comments

- show all comments
user icon Anonymous on April 28th 2010

Can you provide a link to the source code? I can't find it in codeproject.

user icon Anonymous on October 14th 2010

I use delphi 2007.. and have windows 7 x64... I have the icons working like this..

I use icoFX to create a multi layer icon.. eg the different size icons are in one .ico file.. 256x256, 48x48, 32x32 and 16x16. Save as 159.ico.

Create a new resource script file (resources\setup.rc) and add:
#define ICON_1 159
ICON_1 ICON "159.ico"

Compile script with rc.exe

Comment out the default resource file (.RES) from your delphi project file (PROJECT/VIEW SOURCE), and add your new one created from the .rc file that has the icon info in it.

//{$R *.res}
{$R .\resources\setup.res}

This stops delphi from using the default icon definded in the project.
Then add this line after Application.Initialiation;

Application.Icon.Handle := LoadIcon( hInstance, '#159' );

Windows Vista and 7 can now display what ever icon it wants.

Hope this helps..

user icon Anonymous on November 18th 2010

Is there any information available on the return codes for replaceVistaIcon?

user icon Vlasta site administrator on November 18th 2010

the usual - 0=success, 1=failure

user icon Anonymous on March 10th 2013

Thank s for the tool I still have some tools built with delphi 6. I can now solve my icon problem on Win Vista/7/8 instead replace manually my app icon after each build :-) :-)

user icon Anonymous on May 20th 2013

does it work on windows 7?

user icon Vlasta site administrator on May 20th 2013

yes

user icon Anonymous on May 20th 2013

thank you very much sir

user icon Anonymous on January 10th 2016

Hi! With MinGW apps targeting 32 bit ReplaceVistaIcon break debug information (application that is processed with ReplaceVistaIcon crashes gdb).

user icon Anonymous on July 17th 2020

C:-( HMMMMMMMMMMMM I DON'T NO

user icon Anonymous
Select background
I wish there were...