8

i couldn't find any information regarding system tray icons, what size should they be in to get the best possible quality. Should i use more than one size (16x16,32x32,64x64)?

I'm currently using 16x16 .ICO icons and they look disorted.

Merlyn Morgan-Graham
  • 58,163
  • 16
  • 128
  • 183
blejzz
  • 3,349
  • 4
  • 39
  • 60
  • I removed C# since your question isn't specific to it. Feel free to edit back if you feel it is necessary. – Merlyn Morgan-Graham Sep 05 '11 at 10:24
  • 3
    Admittedly I don't really understand how 32bpp icons can work. The native .ico file format is restricted to 8bpp. Vista extends it with an icon format that is actually stored as a png. Avoid surprises, use your icon editor to create an 8bpp (256 colors) icon. Avoid detailed line art, it doesn't scale well. – Hans Passant Sep 05 '11 at 12:47
  • @Hans: 32bpp ARGB (bitmap) support was added in XP. – Anders Sep 06 '11 at 21:13

2 Answers2

8

They are small icons (ICON_SMALL). You can find out the size by calling:

GetSystemMetrics(SM_CXSMICON)

I think it's pretty safe to assume that they are square, but if you are paranoid then you can always inquire about SM_CYSMICON.

On my Windows 7 machine they are 16px in size. But if you are using font scaling then they will be larger. For a 125% font scaling (e.g. large fonts) you will need a 20px icon.

If you don't have a 20px version at hand then the best approach is to generate one on the fly and put your 16px version in the middle of the new 20px icon.

Update

The documentation of NOTIFYICONDATA recommends using LoadIconMetric passing LIM_SMALL which is equivalent to the approach I outline above.

However, the NOTIFYICONDATA topic also says to use an icon resource containing just16px and 32px versions of the icon. That advice is bogus because, as anyone can see for themselves, notification icons under large fonts are 20px icons and LoadIconMetric will have scale from 32 to 20. I would recommend supplying 16, 20, 24, 32px versions.

On XP LoadIconMetric doesn't exist so you'd need to implement a fallback routine.

David Heffernan
  • 601,492
  • 42
  • 1,072
  • 1,490
  • the problem is that my 16x16 .ico is disorted.. The icon look something like the system volume icon.. but when you compare my icon and the system volume icon, mine is just awful.. So i must be doing something wrong.. i'm looking for an anwser like: icon needs to be 16x16 32bit colors (or something like that) – blejzz Sep 05 '11 at 10:11
  • You won't get an answer like that. The required size of the icon varies depending on system settings as I explained. Call `GetSystemMetrics(SM_CXSMICON)` to find out the size needed. As for colour depth, it doesn't matter. The system will display the icon you provide. If you provide one with the wrong size then it will resize. That looks terrible. What size is the one you are providing? – David Heffernan Sep 05 '11 at 10:16
  • the current one is 16x16 32bit. The icon in comparison to the system icon looks smaller and disorted and i'm not using font scaling. – blejzz Sep 05 '11 at 10:26
  • Are you 100% sure that you aren't using a .ico file that contains bit 16px and 32px icons? – David Heffernan Sep 05 '11 at 10:28
  • don't fully understand your question, but i think yes, when i open it in visual studio 2010 it says 16x16, 32 bit, BMP (there are no other resolutions besides 16x16) – blejzz Sep 05 '11 at 10:36
  • so by default windows doesn't load the appropriate size if it is supplied? – blejzz Sep 05 '11 at 12:29
  • An HICON only contains one image. You have to come up with that HICON. – David Heffernan Sep 05 '11 at 12:37
  • This is all well and nice, but isn't helpful for C# (the question seemed to have that tag). .NET's NotifyIcon ignores all of this and always uses the 32px icon, then scales it down. – ygoe Jul 19 '20 at 07:57
  • Update: For the C# NotifyIcon, be sure to first load the correct icon size from an icon before assigning it. [See this answer.](https://stackoverflow.com/a/22599852/143684) – ygoe Jul 19 '20 at 08:05
0

I believe it's best to create your icon in multiple sizes and let Windows choose the best one. You're never sure how large the system tray is, because different users may have different settings.

That could also be the reason yours seems distorted. Say you're using a 16x16, but you've set Windows to display them 18x18. If you haven't provided an 18x18 icon, it'll be distorted.

See this question and Larry Osterman's answer.

Community
  • 1
  • 1
Peter
  • 13,733
  • 11
  • 75
  • 122
  • so providing icon in resolutions 16x16,18x18, 20x20, 32x32, 64x64 should solve the problem? testing it now – blejzz Sep 05 '11 at 10:45
  • 1
    I don't see how you can let Windows choose it for you. In the `NOTIFYICONDATA` structure you supply an `HICON` which only contains a single image. Could you elaborate on how you would go about supplying multiple images in the `NOTIFYICONDATA` struct. – David Heffernan Sep 05 '11 at 10:46
  • @David my guess would be through .ico file format. From wikipedia: .ICO files contain one or more small images at multiple sizes and color depths, such that they may be scaled appropriately. – blejzz Sep 05 '11 at 10:48
  • 4
    @blejzz Guessing isn't enough. `NOTIFYICONDATA` contains an `HICON` and not a .ico file. So you have to decide. – David Heffernan Sep 05 '11 at 10:50