确定窗口是否有任务栏按钮
我正在寻找一种方法来检查给定窗口是否有任务栏按钮。也就是说,给定一个窗口句柄,如果该窗口位于任务栏中,我需要一个 TRUE,否则需要一个 FALSE。
相反,我想知道是否有一种方法可以获取属于给定任务栏按钮的窗口的句柄,我认为这需要一种方法来枚举任务栏按钮。
(前者是我需要的部分,后者是可选的。)
非常感谢。
I am looking for a way to check if a given window has a taskbar button. That is, given a handle to a window, I need a TRUE if the window is in the taskbar, and FALSE otherwise.
Conversely, I am wondering if there is a way to get a handle to the window that belongs to a given taskbar button, which I suppose would require a way to enumerate through the taskbar buttons.
(The first former is the part that I need, and the latter part is optional.)
Thanks a lot.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
Windows 使用启发式方法来决定是否为窗口提供任务栏按钮,有时在决定之前会存在延迟,因此 100% 准确地做到这一点将非常困难。这是规则的粗略开始。有一些现代风格的标志可以让你很容易知道,但是当这些风格缺失时,任务栏就只能靠猜测了。
首先,您将需要两个窗口样式标志。
现在的规则,有三个规则是确定的。
ExStyle & WS_EX_APPWINDOW
,则 TASKBARExStyle & WS_EX_TOOLWINDOW
,Style & 则为 NOT_TASKBAR WS_CHILD
然后 NOT_TASKBAR其余的都是猜测:
Style & WS_OVERLAPPED
建议使用 TASKBARStyle & WS_POPUP
建议 NOT_TASKBAR,特别是如果GetParent() != NULL
ExStyle & WS_EX_OVERLAPPEDWINDOW
建议 TASKBARExStyle & WS_EX_CLIENTEDGE
建议 NOT_TASKBARExStyle & WS_EX_DLGMODALFRAME
建议 NOT_TASKBAR我确信还有其他猜测规则,事实上,猜测规则随着 Windows 版本的不同而发生了变化。
Windows uses heuristics to decide whether or not to give a taskbar button to a window, and sometimes there is a delay before it can decide, so doing this 100% accurately is going to be quite hard. Here's a rough start on the rules. There are modern style flags that make it easy to know, but when those styles are missing the taskbar is reduced to guessing.
First off, you will need both of the the window style flags.
Now the rules, there are three rules that are certain.
ExStyle & WS_EX_APPWINDOW
, then TASKBARExStyle & WS_EX_TOOLWINDOW
, then NOT_TASKBARStyle & WS_CHILD
then NOT_TASKBARThe rest are guesses:
Style & WS_OVERLAPPED
suggests TASKBARStyle & WS_POPUP
suggests NOT_TASKBAR especially ifGetParent() != NULL
ExStyle & WS_EX_OVERLAPPEDWINDOW
suggests TASKBARExStyle & WS_EX_CLIENTEDGE
suggests NOT_TASKBARExStyle & WS_EX_DLGMODALFRAME
suggests NOT_TASKBARI'm sure that there are other rules for guessing, and in fact that the guessing rules have changed from version to version of Windows.
顶级窗口
WS_EX_APPWINDOW ->任务栏,无论其他样式!
OWNER 必须为 NULL (GetWindow(window, GW_OWNER))
否:WS_EX_NOACTIVATE 或 WS_EX_TOOLWINDOW:
顺序很重要。
第二个问题:在 Windows XP/Vista 中,可以进入任务栏进程并获取所有窗口 ID:
这在 Windows 7 中不再可能。所以你需要循环所有顶层窗口。
Toplevel window
WS_EX_APPWINDOW -> taskbar, no matter the other styles!
OWNER must be NULL (GetWindow(window, GW_OWNER))
no: WS_EX_NOACTIVATE or WS_EX_TOOLWINDOW:
order is important.
second question: in windows xp/vista it was possible to get into the process of the taskbar and get all window ID´s:
this not possible with windows 7 anymore. so you need to loop over all toplevel windows.
这篇 MSDN 文章 有一些关于 Shell 何时以及为何决定为窗口创建任务栏按钮的有用信息:
This MSDN article has some good information about when and why the Shell decides to create a taskbar button for a window: