views:

2052

answers:

3

I noticed that my app sends icons to the Windows tray with a size of 16x16 pixels--and my Vista PC I've got a doublewide taskbar that appears to show icons at 18x18. The resizing artifacts on my app's icon look awful. How can I ask Windows what size the icons should be?

edit:

I'm generating the icon dynamically, with a pixel font text overlay. It seems wasteful to generate a bunch of icon sizes dynamically, so it would be nice to avoid building an icon with all the "possible" sizes (not that I'm even sure what those are).

GetSystemMetrics(SM_CXSMICON) returns 16--the incorrect value.

GetThemeBackgroundContentRect didn't help, either.

+2  A: 

Create your icons in multiple formats, and let Windows select the one it wants.

Here's the Wikipedia article on the .ico format.

If you really need to know, GetSystemMetrics with a parameter of SM_CXICON or SM_CYICON will tell you the width and height that Windows wants to load.

Mark Ransom
+1  A: 

Mark's core answer is the right one: Create your icons in multiple formats and let Windows choose the right one. Don't forget to do 32x32 and 64x64 icons for HighDPI scenarios.

But SM_CXICON/SM_CYICON won't necessarily return the size that will be used in the taskbar. The taskbar chooses the right icon size for it's size (this is much more important in Window 7).

Just provide appropriately sized icons and you should be ok.

Larry Osterman
I guess I should have mentioned: I'm generating the icon dynamically, with a pixel font text overlay. It seems wasteful to generate a bunch of icon sizes dynamically.GetSystemMetrics(SM_CXSMICON) returns 16--the incorrect value again.
Kevin Watters
Unfortunately that information doesn't change my answer - you still need to produce multiple icon sizes. Or just produce a 256x256 icon and let the system scale it down for you.
Larry Osterman
Generating a 256x256 with pixel fonts will result in unreadable text when the icon is resampled to 16x16, unfortunately.
Kevin Watters
A good point Kevin. As far as I know there's no way of knowing what icon size will be chosen by the shell and it absolutely does change - for example, I believe that Win7 uses 64x64 (unless you specify small icons or run in classic mode).
Larry Osterman
A: 

Your best bet may be GetThemeBackgroundContentRect passing TBN_BACKGROUND as iPartId for the tray notify background.

GetThemeBackgroundContentRect should return the size defined by the current theme that may be used for drawing without overlapping the borders of the parent element. If I'm reading this correctly, that would be the largest sized notification icon permissible and presumably the size that is being used.

Testing with multiple DPI settings is probably the easiest way to tell if this is returning the correct value.

Zooba
GetThemeBackgroundContentRect with TBN_BACKGROUND did not vary with the tray icon size changing, either.
Kevin Watters