'How can I show different icons in the task bar and app window?

I have a number of apps written in C++, some of which are MFC apps and MFC Dialog apps.

I have two icons which I need to show. One icon is for the main window of an app, the second icon is for the Windows Taskbar. I can easily set the main window app using WM_SETICON. However, this is also changing the icon I see in the Taskbar.

Each app has the "standard" icon in the exe. That is the icon I see in Explorer and TaskManager when the app is running. I see the EXE's icon in the Taskbar if I don't send WM_SETICON. But, if I send WM_SETICON, it changes the icon on the main window AND in the Taskbar.

How can I still set the main window's icon without changing the icon in the Taskbar?

I think I can do this if I register a window class and give the class the icon I want to see in the app's main window. But, MFC (especially dialog apps) registers the window classes and gives them a generic MFC icon. So, using WM_SETICON appears to be my only way to change the icon in the main window.



Solution 1:[1]

The taskbar displays a list of applicable windows (un-owned, not tool windows etc.), not processes.

From old MSDN:

The Shell creates a button on the taskbar whenever an application creates a window that isn't owned. To ensure that the window button is placed on the taskbar, create an unowned window with the WS_EX_APPWINDOW extended style. To prevent the window button from being placed on the taskbar, create the unowned window with the WS_EX_TOOLWINDOW extended style. As an alternative, you can create a hidden window and make this hidden window the owner of your visible window.

Older Delphi/C++ builder based applications used a "hidden" (still WS_VISIBLE?) window as the owner of its application windows (forms). This design allows you to have a different taskbar icon. The downside of this design is possible issues with taskbar thumbnails/preview and you might have to manually deal with some minimize/restore and focus events.

Having a different icon in the taskbar would just be confusing for users, I recommend that you don't fight Windows on this, just accept the behavior...

See also:

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1