How do I ask Windows for the size of system tray icons?

keelo picture keelo · Feb 20, 2009 · Viewed 12.2k times · Source

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.

Answer

Mark Ransom picture Mark Ransom · Feb 20, 2009

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.