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

1

9

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?

Gisela answered 22/3, 2013 at 7:12 Comment(6)
please show us your .dpr code.Tarpaulin
I always include the main icon in a resource file that I control.Leishmaniasis
can u include it in a separate DLL ? "resource DLLs" are rather frequently usedRubberneck
whosrdaddy, the dpr file of the project is rather large, so I cannot post it here. But yes, it has a {$R *.RES} line, which was created by Delphi.Gisela
David, if I add the project Icon using a resource file, do I need to use some specific resource name?Gisela
the code I've posted here is only example code (I've much more icons). After reading your comments I have changed the names of the icons, so that all start with "z", and the problem is solved! Please change your comment to an answer, so I can accept it.Gisela
L
10

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.

Leishmaniasis answered 22/3, 2013 at 9:11 Comment(1)
I think it's time for Delphi to fix this bug and change the name of the main incon to someting like AA_MAINICON... It's frustrating to rename all my icons with names starting with "N" to "Z".Numbersnumbfish

© 2022 - 2024 — McMap. All rights reserved.