从 Windows 10 的任务栏中删除 window
Remove window from taskbar on Windows 10
我想从具有多个桌面的 Windows 10 上的任务栏中删除 window。
对于 Windows 8.1,我使用了 ITaskbarList::DeleteTab 并且效果很好。
对于 Windows 10,此方法也会从任务栏中隐藏 Windows,但之后我会在所有桌面上看到此 window。我只想在一个桌面上看到这个 window。
有谁知道在 Windows 10 中从任务栏隐藏 window 并将此 window 保留在一个桌面上的方法吗?
下面你可以看到,我在"hide window from task bar in Windows 10"下的意思:
根据我的理解,根据我的经验测试,出现在任务栏预览中的 windows 与通常出现在任务栏中的 windows 完全相同。很久以前,比如说在 Windows 2000 年,应用程序的每个符合条件的 windows 都只会显示为任务栏上的按钮。从 Windows XP 开始,任务栏分组成为一个选项,因此单个应用程序中所有符合条件的 windows 都可以分组在一起,并在任务栏上显示为单个按钮。然后,在 Windows Vista 中,当您将鼠标悬停在相应的任务栏按钮上时,可以显示这些打开的预览 windows。 Windows 8 和 Windows 10 都没有改变这个基本规则;他们只改变了预览的外观。
因此,关于windows出现在任务栏上的规则,我们可以参考MSDN documentation:
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.
陈峰对这些规则的总结比较准确here。引用他的话:
There are some basic rules on which windows go into the taskbar. In short:
- If the
WS_EX_APPWINDOW
extended style is set, then it will show (when visible).
- If the window is a top-level unowned window, then it will show (when visible).
- Otherwise it doesn't show.
(Though the ITaskbarList interface muddies this up a bit.)
你之前把事情搞得一团糟,打电话给ITaskbarList::DeleteTab
。那是没有必要的。要确保 window 不会出现在任务栏中,只需应用与 window 确实 出现在任务栏中的规则相反的规则。
如果您有一个顶级无主 window,它将显示在任务栏中,除非您 删除 WS_EX_APPWINDOW
扩展 window 风格。如果您有一个自有的 window,那么它将 不会 显示在任务栏中,除非 WS_EX_APPWINDOW
扩展 window 样式设置为强制显示在任务栏中.
因此,如果您有 WS_EX_APPWINDOW
扩展 window 样式集,则应将其删除。那是强制 window 显示在任务栏中。
否则,您应该为您的 window 设置所有者。例如,让第二个 window 归第一个所有。
TL;DR:
- 从扩展样式中删除
WS_EX_APPWINDOW
和 WS_EX_TOOLWINDOW
。
- 设置 window 的所有者。
示例:
从扩展样式中删除标志:
SetWindowLong(myHWND, GWL_EXSTYLE,
GetWindowLong(myHWND, GWL_EXSTYLE) & ~WS_EX_APPWINDOW & ~WS_EX_TOOLWINDOW);
设置所有者:
SetWindowLongPtr(myHWND, GWLP_HWNDPARENT, myOwnerHWND);
完整解释:
尽管 很棒,但它并不能完全回答确切的问题。
确切的问题是:“如何显示一个window,它没有出现在任务栏中,却只出现在一个虚拟桌面上?
正如 Cody 所解释的,有几种方法可以删除 window 的任务栏按钮。但是,只有一种方式可以同时显示在一个虚拟桌面上。
如果您在扩展样式中包含标志 WS_EX_APPWINDOW
,它将强制 window 显示在任务栏中。这就是为什么在这种情况下必须清除它的原因。
如果在扩展样式中包含标志 WS_EX_TOOLWINDOW
,它将强制 window not 在任务栏中显示,but 将强制 window 在所有虚拟桌面上显示。因此这里也不是一个选项。
最后,如果您的 window 没有任何标志,当且仅当它没有所有者时,它才会显示在任务栏中。无论哪种方式,它都会 而不是 在所有虚拟桌面上强制执行。因此,解决方案是既不设置标志又设置所有者。
将WS_EX_NOACTIVATE添加到window的ex样式中。
https://docs.microsoft.com/en-us/windows/win32/winmsg/extended-window-styles
A top-level window created with this style does not become the
foreground window when the user clicks it. The system does not bring
this window to the foreground when the user minimizes or closes the
foreground window. The window should not be activated through
programmatic access or via keyboard navigation by accessible
technology, such as Narrator. To activate the window, use the
SetActiveWindow or SetForegroundWindow function. The window does not
appear on the taskbar by default. To force the window to appear on the
taskbar, use the WS_EX_APPWINDOW style.
我想从具有多个桌面的 Windows 10 上的任务栏中删除 window。 对于 Windows 8.1,我使用了 ITaskbarList::DeleteTab 并且效果很好。
对于 Windows 10,此方法也会从任务栏中隐藏 Windows,但之后我会在所有桌面上看到此 window。我只想在一个桌面上看到这个 window。
有谁知道在 Windows 10 中从任务栏隐藏 window 并将此 window 保留在一个桌面上的方法吗?
下面你可以看到,我在"hide window from task bar in Windows 10"下的意思:
根据我的理解,根据我的经验测试,出现在任务栏预览中的 windows 与通常出现在任务栏中的 windows 完全相同。很久以前,比如说在 Windows 2000 年,应用程序的每个符合条件的 windows 都只会显示为任务栏上的按钮。从 Windows XP 开始,任务栏分组成为一个选项,因此单个应用程序中所有符合条件的 windows 都可以分组在一起,并在任务栏上显示为单个按钮。然后,在 Windows Vista 中,当您将鼠标悬停在相应的任务栏按钮上时,可以显示这些打开的预览 windows。 Windows 8 和 Windows 10 都没有改变这个基本规则;他们只改变了预览的外观。
因此,关于windows出现在任务栏上的规则,我们可以参考MSDN documentation:
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 theWS_EX_TOOLWINDOW
extended style. As an alternative, you can create a hidden window and make this hidden window the owner of your visible window.
陈峰对这些规则的总结比较准确here。引用他的话:
There are some basic rules on which windows go into the taskbar. In short:
- If the
WS_EX_APPWINDOW
extended style is set, then it will show (when visible).- If the window is a top-level unowned window, then it will show (when visible).
- Otherwise it doesn't show.
(Though the ITaskbarList interface muddies this up a bit.)
你之前把事情搞得一团糟,打电话给ITaskbarList::DeleteTab
。那是没有必要的。要确保 window 不会出现在任务栏中,只需应用与 window 确实 出现在任务栏中的规则相反的规则。
如果您有一个顶级无主 window,它将显示在任务栏中,除非您 删除 WS_EX_APPWINDOW
扩展 window 风格。如果您有一个自有的 window,那么它将 不会 显示在任务栏中,除非 WS_EX_APPWINDOW
扩展 window 样式设置为强制显示在任务栏中.
因此,如果您有 WS_EX_APPWINDOW
扩展 window 样式集,则应将其删除。那是强制 window 显示在任务栏中。
否则,您应该为您的 window 设置所有者。例如,让第二个 window 归第一个所有。
TL;DR:
- 从扩展样式中删除
WS_EX_APPWINDOW
和WS_EX_TOOLWINDOW
。 - 设置 window 的所有者。
示例:
从扩展样式中删除标志:
SetWindowLong(myHWND, GWL_EXSTYLE,
GetWindowLong(myHWND, GWL_EXSTYLE) & ~WS_EX_APPWINDOW & ~WS_EX_TOOLWINDOW);
设置所有者:
SetWindowLongPtr(myHWND, GWLP_HWNDPARENT, myOwnerHWND);
完整解释:
尽管
确切的问题是:“如何显示一个window,它没有出现在任务栏中,却只出现在一个虚拟桌面上?
正如 Cody 所解释的,有几种方法可以删除 window 的任务栏按钮。但是,只有一种方式可以同时显示在一个虚拟桌面上。
如果您在扩展样式中包含标志 WS_EX_APPWINDOW
,它将强制 window 显示在任务栏中。这就是为什么在这种情况下必须清除它的原因。
如果在扩展样式中包含标志 WS_EX_TOOLWINDOW
,它将强制 window not 在任务栏中显示,but 将强制 window 在所有虚拟桌面上显示。因此这里也不是一个选项。
最后,如果您的 window 没有任何标志,当且仅当它没有所有者时,它才会显示在任务栏中。无论哪种方式,它都会 而不是 在所有虚拟桌面上强制执行。因此,解决方案是既不设置标志又设置所有者。
将WS_EX_NOACTIVATE添加到window的ex样式中。 https://docs.microsoft.com/en-us/windows/win32/winmsg/extended-window-styles
A top-level window created with this style does not become the foreground window when the user clicks it. The system does not bring this window to the foreground when the user minimizes or closes the foreground window. The window should not be activated through programmatic access or via keyboard navigation by accessible technology, such as Narrator. To activate the window, use the SetActiveWindow or SetForegroundWindow function. The window does not appear on the taskbar by default. To force the window to appear on the taskbar, use the WS_EX_APPWINDOW style.