Best Icon size for displaying in the tray

22,703

Solution 1

You should be using 32bpp icons with partial transparency for best effect.

The icon uses the small system size. Get this by calling GetSystemMetrics passing SM_CXSMICON. If you use font scaling this can be, for example, 20px rather than the more common 16px. I've never found MS documentation for this fact but you can readily verify it for yourself by trial and error. Not really a happy state of affairs, but it is what it is.

Update: TOndrej points out that the docs for LoadIconMetric gives tacit approval of the notification area icon being small icon size. I don't understand why this information is not included with that for notification icons.

Solution 2

You should probably include both 32x32 and 16x16 icons and load the appropriate one at runtime:

Notification area icons should be high-DPI aware. An application should provide both a 16x16 pixel icon and a 32x32 icon in its resource file, and then use LoadIconMetric to ensure that the correct icon is loaded and scaled appropriately.

(source: MSDN)

Share:
22,703
Lobuno
Author by

Lobuno

Updated on July 09, 2022

Comments

  • Lobuno
    Lobuno almost 2 years

    I am working on a Delphi program which will display an icon on the "tray". I am doing it "the hard way" (using the Shell_NotifyIcon api, etc and not a component, for reasons outside the point here). It's working fine but sometimes it seems like the icon is a little "blurry" in some systems. Now, I have experimented using 16x16 bmp, 32x32, etc. It seems like the system scales it down to the needed size, but the results are different depending on the OS version (or perhaps something else as well)....

    Have any of you any experience about the best size and color depth of a BMP to be extracted and displayed on the tray using Shell_NotifyIcon from a ListImage?

  • David Heffernan
    David Heffernan over 12 years
    Sadly the documentation doesn't do the job here. If you don't put in an icon that is the small icon size, then you will have aliasing and the dreaded jaggies. This I know from bitter experience.
  • Ken White
    Ken White over 12 years
    You should probably include a note that this only works on Vista and higher, or Windows Server 2008 and higher (LoadIconMetric isn't available on earlier Windows platforms). There are still a lot of WinXP and Server 2003 systems out there. :)
  • David Heffernan
    David Heffernan over 12 years
    If anyone is interested I have excellent code that will create icons of any size given a resource name and this works on XP and up but takes advantage of new functions where they exist. I could post a q and answer it with my own code if there was interest.
  • Lobuno
    Lobuno over 12 years
    Hmm... GetSystemMetrics(SM_CXICON) is giving me 32 on my system... On the other hand GetSystemMetrics(SM_CXSMICON) gives me 16... The help file indicates that SM_CXSMICON is the recommended width of a small icon (sure it says nothing about "tray" or "Notification bar" for that matter.
  • Sam
    Sam over 12 years
    The link I posted explains that LIM_SMALL corresponds to SM_CXSMICON. The code example uses LIM_SMALL.
  • David Heffernan
    David Heffernan over 12 years
    @TOndrej That link on LoadIconMetric is the closest I have seen to a blessing for small icon size for notification icon. Crazy that MSDN don't put that info on the notification icon docs. Anyway, the text you found there would be much better in your answer than that you reference from that other page, IMHO.
  • David Heffernan
    David Heffernan over 12 years
    @Lobuno As promised, here is the code I discussed: stackoverflow.com/questions/8112953
  • ispiro
    ispiro almost 3 years
    After changing dpi I still get the same (16). My question.