13

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?

Lobuno
  • 1,405
  • 1
  • 18
  • 28

3 Answers3

14

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.

David Heffernan
  • 601,492
  • 42
  • 1,072
  • 1,490
  • 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. – Lobuno Nov 11 '11 at 22:31
  • The link I posted explains that `LIM_SMALL` corresponds to `SM_CXSMICON`. The code example uses `LIM_SMALL`. – Ondrej Kelle Nov 11 '11 at 22:36
  • @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 Nov 11 '11 at 22:44
  • After changing dpi I still get the same (16). [My question](https://stackoverflow.com/questions/68352927/systemparameters-smalliconwidth-returns-16-on-any-dpi-so-how-can-i-check-for-ac). – ispiro Jul 12 '21 at 19:30
8

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)

Ondrej Kelle
  • 36,941
  • 2
  • 65
  • 128
  • 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. – David Heffernan Nov 11 '11 at 22:09
  • 1
    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. :) – Ken White Nov 11 '11 at 22:11
  • 5
    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. – David Heffernan Nov 11 '11 at 22:16
  • 1
    @Lobuno As promised, here is the code I discussed: http://stackoverflow.com/questions/8112953 – David Heffernan Nov 13 '11 at 16:31
0

A single *.ico file is recommended for app icons. *.ico file can store different sizes of icons like 16, 32, 256 etc. You can convert different image files to ico format online here.

For tray icon 16x16 or 32x32 ico would fit.

Official msdn guide for icons: icons in Windows

GorvGoyl
  • 42,508
  • 29
  • 229
  • 225