We have a Windows desktop application written in Delphi that works fine on Windows 7, except that the icon of the main form looks blurry in Windows’ new taskbar. As long as the application has not been started the icon looks fine (i.e. when it’s pinned to the taskbar). Once it has been started Windows uses the icon of the main form (instead of the .exe resource icon) and it’s blurry (it looks like a 16×16 version of the icon is scaled up).
The icon that we use for the .exe and for the main form are exactly the same and it contains all kinds of resolutions, including 48×48 with alpha blending.
My theory is that Delphi ignores/deletes the extra resolutions of the icon when I import the .ico file for the main form in Delphi. Is there a way to prevent/fix this? What’s the best way to ensure that an application written in Delphi uses the correct icon resolution in Windows 7’s taskbar?
The problem lies within lazy programming within the VCL not fitting with the behavioral change of the OS. More or less it is like this;
TCustomForm.CreateWnd, after the window handle is created, calls;
Notice the “1” in place of wParam, that’s ICON_BIG. Actually the VCL sets the large icon of the form. But the icon’s requested size (TIcon.FRequestedSize) is 16×16 (by default), and so the TIcon of the form returns a handle for the small icon. That’s the size for the system small icon and is determined in the constructor CreateNew with calls to GetSystemMetrics.
Since earlier versions of Windows used the small icon on the taskbar this was no problem. Hovewer the Alt+Tab dialog had the problem other way around; if an icon was assigned to a form it showed “blurred” in the Alt+Tab dialog. Anyway, Windows 7, still, by default returns 16×16 for the small icon (SM_CXSMICON/SM_CYSMICON) and 32×32 for the large icon (SM_CXICON/SM_CYICON), but the large taskbar displays the large icon, if there is one that is..
The correct approach would be to assign a large image (if there is one in the icon) for the large icon and assign a small image (if there is one) to the small icon. Granted, since the sizes would not have to have exact matches, this would require a complex algorithm. Instead, a simpler but broken design is implemented.
For a workaround, I don’t assign an icon to the forms in the OI and instead use this;
and include an “icons.res” with named icons having 16×16 and 32×32 images, in the project. All the forms in their OnCreate call