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

I needed to add some icons to my project as a resource (I cannot use TImageList in this case due to an error in TCoolTrayIcon, and I cannot quickly replace the component).

I created a .rc script icon to add two ico files to the Delphi resource file:

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

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

 {$R icons.res} 

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

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

and then just use the descriptors.

Now, before the problem - after that, the project icon that was added to the project settings (size from 16x16 to 48x48) is replaced by the first icon (16x16 redicon), which I added to {$ R icons.res}.

How to prevent this? How to add additional icons to the project as a resource without replacing the icon added to Project Settings β†’ Application β†’ Download Icon?

+7
source share
1 answer

VCL prints the name 'MAINICON' for your application 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 file is the main icon of the application. The order that the shell uses is in alphabetical order by icon name.

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

+7
source

All Articles