Why is my icon being drawn at the wrong size when I call DrawIcon?
Some time ago I had a problem with icon drawing.
When I tried to draw an icon with
DrawIcon it ended up being drawn at the wrong size.
A call to
GetIconInfo confirmed that the icon was
48×48, but it drew at 32×32.
The answer is documented in a backwards sort of way
DrawIconEx function, which says at the bottom,
To duplicate DrawIcon (hDC, X, Y, hIcon), call DrawIconEx as follows:DrawIconEx (hDC, X, Y, hIcon, 0, 0, 0, NULL, DI_NORMAL | DI_COMPAT | DI_DEFAULTSIZE);
Aha, if you use
DrawIcon, then the icon size is ignored
and it is drawn with
The fix, therefore, was to switch to the
DrawIconEx function so I could remove the
thereby permitting the icon to be drawn at its actual size.
- DrawIcon(hdc, pt.x, pt.y, hico); + DrawIconEx(hdc, pt.x, pt.y, hico, 0, 0, 0, NULL, DI_NORMAL | DI_COMPAT);
A bonus quirk of the
(and therefore of the
is that the drawing is done at the default icon size,
even if you asked it to draw a cursor.