隐藏另一个应用程序的任务栏按钮
我希望能够从任务栏隐藏另一个应用程序的窗口,而不隐藏窗口本身。 具体来说,我希望有几个不同的 Web 浏览器正在运行、可见、可在 Alt+Tab 列表中使用,但不占用任务栏上的空间。
(如果有人好奇为什么:我编写了一个仪表板应用程序,它使用 Vista 的 DwmRegisterThumbnail API 来同时显示多个窗口的实时预览 - 如果您愿意的话,可以说是一种“画中画”。此时,还具有任务栏按钮对于这些窗口似乎是多余的。)
我知道更改其他窗口的样式以包含 WS_EX_TOOLWINDOW
会将其从任务栏中隐藏,我首先尝试了这一点。 但是,正如预期的那样,它产生了一些我不想要的副作用:标题栏变短了(我猜也不全是坏事),最小化和最大化按钮消失了(不好)。 我还必须隐藏并重新显示窗口以使任务栏识别更改,这在我对 IE 窗口执行此操作时导致了重新绘制工件。
我的下一个想法是,由于默认情况下,具有所有者的窗口在任务栏上是隐藏的,也许我可以将其他窗口更改为我所拥有的。 但 MSDN 非常清楚“ [a]创建拥有的窗口后,应用程序无法将该窗口的所有权转移给另一个窗口。”
我发现 这个问题 的措辞与我的类似,但它是特别是关于您自己的进程中的窗口,您可以完全控制窗口所有权。
有谁知道隐藏任务栏按钮的任何其他方法,该方法适用于另一个进程的窗口?
更新:Tormod 让我走上了 ITaskbarList 的正确轨道——它工作得很好。 pinvoke.net 页面有一些错误(错误的 GUID、按字母顺序而不是按接口顺序声明的方法),但我对其进行了编辑、更正,并且还添加了如何通过其组件类实例化 ITaskbarList 的示例。
更新2:如果您使用DeleteTab隐藏窗口的任务栏按钮,然后将该窗口设为活动窗口(例如通过SetForegroundWindow
或Alt+Tab),其任务栏按钮将重新出现。 为了保持任务栏按钮隐藏,我必须添加一个计时器并不断调用DeleteTab。 只要您不介意任务栏按钮在窗口获得焦点时短暂地重新出现,就可以很好地工作。
I would like to be able to hide another application's window from the taskbar, without hiding the window itself. Specifically, I want to have several different Web browsers running, visible, available in the Alt+Tab list, but not taking up space on the taskbar.
(If anyone's curious why: I've written a dashboard app that uses Vista's DwmRegisterThumbnail APIs to show live previews of several windows at once -- a sort of "picture in picture", if you will. At that point, also having taskbar buttons for those windows seems redundant.)
I am aware that changing the other window's style to include WS_EX_TOOLWINDOW
will hide it from the taskbar, and I tried this first. But, as expected, it had some side effects I didn't want: the title bar got shorter (not all bad, I guess) and the minimize and maximize buttons went away (not good). I also had to hide and re-show the window to get the taskbar to recognize the change, which caused repainting artifacts when I did it to IE windows.
My next thought was that, since windows with owners are hidden from the taskbar by default, maybe I could change the other windows to be owned by mine. But MSDN is pretty clear that "[a]fter creating an owned window, an application cannot transfer ownership of the window to another window."
I found this question that's worded similarly to mine, but it's specifically about windows from your own process, where you have complete control over window ownership.
Does anyone know of any other ways to hide a taskbar button, that will work for windows from another process?
Update: Tormod put me on the right track with ITaskbarList -- it works great. The pinvoke.net page had some errors (wrong GUID, methods declared alphabetically instead of in interface order), but I edited it, made corrections, and also added an example of how to instantiate the ITaskbarList via its coclass.
Update 2: If you use DeleteTab to hide a window's taskbar button, and then make that the active window (e.g. via SetForegroundWindow
or Alt+Tab), its taskbar button will reappear. To keep the taskbar button hidden, I had to add a timer and keep calling DeleteTab. As long as you don't mind the taskbar button reappearing briefly whenever the window gets focused, this works well.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
来自 MSDN:
看起来 COM 互操作是可靠地操作任务栏内容的方法。 特别是,您需要调用以下函数:
您可以找到ITaskbarList 接口的 C# 签名位于 pinvoke.net: ITaskbarList。
From MSDN:
It seems like COM interop is the way to go to reliably manipulate the contents of the taskbar. In particular, you would need to call the following functions:
You can find the C# signature for the ITaskbarList interface at pinvoke.net: ITaskbarList.
您是否尝试过删除
WS_EX_APPWINDOW
< /a>?Have you tried removing
WS_EX_APPWINDOW
?