Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Adding a .res file to project replaces the default icon.How to prevent it?

I needed to add some icons to my project as a resource (I can't use a TImageList in this case, because of a bug in TCoolTrayIcon, and I can't replace the component quickly).

I've created an icons.rc script to add the two ico files to a Delphi resource file:

redicon ICON "c:\icon\red.ico"
greenicon ICON "c:\icon\green.ico"

it compiles fine to icons.res, so I add it to the first unit of my Delphi 7 project:

{$R icons.res}

then I store the handles in OnCreate() of the MainForm:

hRedIcon := LoadIcon(hInstance,'redicon');
hGreenIcon := LoadIcon(hInstance,'greenicon');

and then use the handles just fine.

Now to the problem - after doing that the project icon that was added in the project options (in sizes of 16x16 to 48x48) is replaced by the first icon (16x16 redicon) I've added in {$R icons.res}.

How to prevent this? How to add additional icons to a project as a resource without replacing the icon that is added in Project Options -> Application -> Load Icon?

like image 869
Casady Avatar asked Mar 22 '13 07:03

Casady


1 Answers

The VCL hard codes the name 'MAINICON' for your application's icon. This can be seen in the code in TApplication.Create:

FIcon.Handle := LoadIcon(MainInstance, 'MAINICON');

On the other hand, the shell assumes that the first icon in your executable is the main application icon. The order that the shell uses is alphabetical by icon name.

The consequence of this is that all your icons should have names that appear after MAINICON in the alphabet.

like image 54
David Heffernan Avatar answered Oct 21 '22 21:10

David Heffernan