使用 WS_EX_TOOLWINDOW 时显示任务栏按钮

Show taskbar button when using WS_EX_TOOLWINDOW

CreateWindowEx中使用WS_EX_TOOLWINDOW标志时是否可以显示任务栏按钮?

无主 top-level window 需要 WS_EX_APPWINDOW 样式才能在任务栏上显示自己。

Extended Window Styles 文档明确指出“工具 window 没有出现在任务栏 中”。

MSDN 进一步对此进行了更详细的记录:

The Taskbar

The Shell places a button on the taskbar whenever an application creates an unowned window—that is, a window that does not have a parent and that has the appropriate extended style bits (see Managing Taskbar Buttons, below).

...

Managing Taskbar Buttons

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.

The Shell will remove a window's button from the taskbar only if the window's style supports visible taskbar buttons. If you want to dynamically change a window's style to one that does not support visible taskbar buttons, you must hide the window first (by calling ShowWindow with SW_HIDE), change the window style, and then show the window.

...

Modifying the Contents of the Taskbar

Version 4.71 and later of Shell32.dll adds the capability to modify the contents of the taskbar. From an application, you can now add, remove, and activate taskbar buttons. Activating the item does not activate the window; it shows the item as pressed on the taskbar.

The taskbar modification capabilities are implemented in a Component Object Model (COM) object (CLSID_TaskbarList ) that exposes the ITaskbarList interface (IID_ITaskbarList). You must call the ITaskbarList::HrInit method to initialize the object. You can then use the methods of the ITaskbarList interface to modify the contents of the taskbar.

因此,您可以使用 ITaskbarList::AddTab() 作为您的工具 window:

Any type of window can be added to the taskbar, but it is recommended that the window at least have the WS_CAPTION style.