Which format and size of icons to use for NotifyIcon
Asked Answered
R

2

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.

Recusant answered 5/9, 2011 at 10:4 Comment(3)
I removed C# since your question isn't specific to it. Feel free to edit back if you feel it is necessary.Enneahedron
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.Monro
@Hans: 32bpp ARGB (bitmap) support was added in XP.Zenobiazeolite
P
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.

Pigeon answered 5/9, 2011 at 10:7 Comment(9)
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)Recusant
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?Pigeon
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.Recusant
Are you 100% sure that you aren't using a .ico file that contains bit 16px and 32px icons?Pigeon
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)Recusant
so by default windows doesn't load the appropriate size if it is supplied?Recusant
An HICON only contains one image. You have to come up with that HICON.Pigeon
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.Ottillia
Update: For the C# NotifyIcon, be sure to first load the correct icon size from an icon before assigning it. See this answer.Ottillia
M
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.

Metalliferous answered 5/9, 2011 at 10:35 Comment(4)
so providing icon in resolutions 16x16,18x18, 20x20, 32x32, 64x64 should solve the problem? testing it nowRecusant
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.Pigeon
@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.Recusant
@Recusant Guessing isn't enough. NOTIFYICONDATA contains an HICON and not a .ico file. So you have to decide.Pigeon

© 2022 - 2024 — McMap. All rights reserved.