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?
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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With