2
votes

We have come across some behaviour involving the taskbar icons that Windows 7 displays for different applications. I'm wondering whether anybody could shed some light on this:

  • Windows 7 is set with font-size = 110%.
  • Two MFC dialog applications A.exe and B.exe have exactly the same .ico resource embedded in them.
  • A.exe has a shortcut associated with it; B.exe does not.
  • Running A.exe shows a nice interpolated icon on the taskbar.
  • Running B.exe shows a different icon on the taskbar (not interpolated).

We would wish that the same icon appears on the taskbar for A.exe and B.exe - this is easily achieved by making a shortcut to B.exe to give the same behaviour. However, I'm really trying to understand more on what's going on.

In trying to understand what was going on I have handled the WM_GETICON message inside B.exe, returning an icon according to the sizes given by GetSystemMetrics SM_CXICON/SM_CYICON or SM_CXSMALLICON/SM_CYSMALLICON size. However, this didn't seem to affect the icon shown in the taskbar.

I also know that we could create an .ico file to be built into B.exe with lots of different sizes of icons - maybe this would improve things, but that's a tedious solution!

Any ideas?

1
what do You mean by "A.exe has a shortcut associated with it; B.exe does not." What does the shortcut being associated mean here??...TheCodeArtist
After I have created the executable A.exe, I have browsed to the folder containing A.exe using Windows Explorer, clicked on A.exe to select it, right-clicked and chosen the 'Create Shortcut' option.Andrew Wyatt
Are you sure that A.exe and B.exe are identical? In particular, does A.exe have a manifest that specifies dpiAware = true?Eric Brown
The original problem was in a working applications. However to test out what was going on we created A.exe and B.exe, which were two separate MFC dialog applications in Visual Studio 2008. We probably used the project defaults, and built the two applications with no change, except that I ensured the .ico resource was the same icon in both projects. I hadn't come across the dpiAware manifest setting - I'll check that out and see how it affects this problem.Andrew Wyatt

1 Answers

0
votes

Just met this issue with following simple scenario(all on win7):

  1. create A.exe with icon B
  2. create B.lnk associated to A.exe with different icon C (by winapi CreateLink)
  3. run with clicking B.lnk. On some win7 machines, taskbar's icon is C. But, on some other machine(also win7), it's B.

If the icon is C, it even can't be changed by following code:

const HANDLE bigicon = ::LoadImage(::GetModuleHandle(0), MAKEINTRESOURCE(IDI_TO_ICON), IMAGE_ICON, 256, 256, 0);
if (bigicon) {
    ::SendMessage(theMainWnd, WM_SETICON, ICON_BIG, (LPARAM)bigicon);
    ::SendMessage(GetWindow(theMainWnd, GW_OWNER), WM_SETICON, ICON_BIG, (LPARAM)bigicon);
}
const HANDLE smallicon = ::LoadImage(::GetModuleHandle(0), MAKEINTRESOURCE(IDI_TO_ICON_SMALL), IMAGE_ICON, ::GetSystemMetrics(SM_CXSMICON), ::GetSystemMetrics(SM_CYSMICON), 0);
if (smallicon) {
    ::SendMessage(theMainWnd, WM_SETICON, ICON_SMALL, (LPARAM)smallicon);
    ::SendMessage(GetWindow(theMainWnd, GW_OWNER), WM_SETICON, ICON_SMALL, (LPARAM)smallicon);
}