2

I have a few icons in .ico files in my C++ MFC program. I use DrawIcon and DrawIconEx to draw them onto a memory bitmap and they come out with some sort of shadow-like border at the edge of the edges of the visible content. The pixels look like they are in the transparent part of the icon and in the area that I drew in as white. Windows appears to be

I have edited the .ico files with Axialis IconWorkshop, Visual Studio, and looked at them with a few online ico-to-png converters. They look fine until I draw with them. they were okay for years and something changed in the last few years with Windows 8 or Windows 10.

Any ideas how to draw these things right?

Here's how one of my icons look in an icon editor:

enter image description here

And then how they look wrong in my program (blown up for you to see better): enter image description here

I'm looking for possible viewport-window or other device context settings that might have some effect on this stuff.

I almost posted my own answer because DrawIconEx seemed to fix the problem because I have a high DPI display. But at closer inspection, the garbage is still there, just at the proper smaller pixel count, not scaled up by the DrawIcon function.

David Rector
  • 958
  • 9
  • 31

2 Answers2

1

The DrawIcon and DrawIconEx functions on a high DPI display scales up the icons that they draw. Even though they seem to be trying to draw the icon at a 1:1 size, there is still some scaling going on.

There were a few online sources of information, none of which individually was useful, that together hinted on the cause of the problem. The only possible solution that I found was to create a 40x40, and maybe a 64x64 icon within the same icon file and let the icon drawing functions get the right icon to draw.

This is not really an answer since I have not tried to use a different size icon in the ico file. I just switched my app to be unaware of high DPI displays.

David Rector
  • 958
  • 9
  • 31
0

Just use DrawIconEx without DI_DEFAULTSIZE flag, it's the one causing the mess. E.g. DrawIconEx(Handle, 32, 32, ArrowCur, 0, 0, 0, 0, DI_NORMAL);

GrayFace
  • 1,224
  • 10
  • 13