Recent

Author Topic: Multiple application icons (Windows)  (Read 2818 times)

Graham1

  • Jr. Member
  • **
  • Posts: 57
Multiple application icons (Windows)
« on: August 11, 2021, 06:14:34 am »
I know I can add an application icon using 'Load Icon' in the Project Options, and that the icon file I load can include multiple sizes (16x16, 32x32 etc).

But I can't find a way to add more than one icon to an application. Many Windows programs have a choice of icons that can be selected in the shortcut menu (Change icon). Is it possible to do this for Lazarus Windows EXE programs?

Thanks.
Windows 10/11 Home 64-bit (and Linux because I have to)
Lazarus 2.0.12 / FPC 3.2.0 (because libQt5pas 1.2.6)
Linux Mint 20 (because GLIBC_2.31)

Wallaby

  • Jr. Member
  • **
  • Posts: 78
Re: Multiple application icons (Windows)
« Reply #1 on: August 11, 2021, 08:25:42 am »
You can just link however many ICON resources to the app (create an RC file, compile it to RES file and link with $R myfile.res)

Graham1

  • Jr. Member
  • **
  • Posts: 57
Re: Multiple application icons (Windows)
« Reply #2 on: August 11, 2021, 09:15:25 am »
Thank you! I didn't know about that.

I've found if I clear the icon on the main App screen in the Project and add two different icon files (each with 16,32... icons) then it all seems to work fine with the exception that the forms don't show either of the icons - just a default Lazarus form icon. If I don't clear the icon on the Project screen then the form shows that set's 16x16 icon but the taskbar also shows that set's icon even if the other set was selected for the desktop shortcut.

So how can I determine which of the icon sets the user has selected so that I can set the appropriate icon on the form (I assume using Form1.Icon for example)? I'm trying to get the EXE to show one set of icons consistently throughout Windows based on which icon was selected for the shortcut.
Windows 10/11 Home 64-bit (and Linux because I have to)
Lazarus 2.0.12 / FPC 3.2.0 (because libQt5pas 1.2.6)
Linux Mint 20 (because GLIBC_2.31)

Wallaby

  • Jr. Member
  • **
  • Posts: 78
Re: Multiple application icons (Windows)
« Reply #3 on: August 11, 2021, 10:58:01 am »
It doesn't sound necessary, but if you want to go down that path, you will need to:

1) Get the location of desktop (SHGetSpecialFolderPath)
2) Find the LNK file there aka the shortcut to your application
3) Use the IShellLink::GetIconLocation to find out what icon was chosen

Graham1

  • Jr. Member
  • **
  • Posts: 57
Re: Multiple application icons (Windows)
« Reply #4 on: August 13, 2021, 05:58:28 am »
That all sounded too difficult so I decided to just standardise on one set of icons for the form and taskbar and provide different options for the desktop. Even that turned out to be trickier than I'd expected!

I'm not sure if this is totally accurate as Windows can be difficult about refreshing which icons are shown at any time. I found ie4uinit.exe -show forces an update of the desktop icons but still don't know how to make Explorer update. Anyway, I think this is correct:
  • You can add icons using the main Project Application window
  • You can also add icons using the Project Resources window
  • Once compiled the EXE contains the icons in the following order:
           Resources icons sorted alphabetically by their resource name, then
           Application icons
  • The form and taskbar icons will come from the Application icons
  • The default desktop/shortcut/Windows Explorer icon comes from the first icon set in the EXE
So I created the following icon sets:

IconSet1: 16x16, 20x20, 24x24, 32x32, 48x48, 256x256
IconSet2: 32x32, 48x48, 256x256
IconSet3: 32x32, 48x48, 256x256

Then I set:

Project Application:
       IconSet1

Project resources:
       IconSet1, name: SET1
       IconSet2, name: SET2
       IconSet3, name: SET3

This seems to result in the expected icons appearing everywhere with the single exception being the Shortcut > Change Icons screen where the icon for Set1 appears twice (once from the Application icon set and once from the Resources), but I can live with that.
Windows 10/11 Home 64-bit (and Linux because I have to)
Lazarus 2.0.12 / FPC 3.2.0 (because libQt5pas 1.2.6)
Linux Mint 20 (because GLIBC_2.31)

 

TinyPortal © 2005-2018