检测应用程序窗口
我使用 CBT Windows Hook 来检测窗口创建/deletion/min-max/move-size 事件。
我工作得很好,但我需要过滤来自普通小部件的事件。实际上,我只需要通过 CBT 挂钩通知用户认为是窗口的那些窗口。
我面临的问题让我很生气,因为即使我按如下方式过滤窗口,我也会不断收到虚假事件:
BOOL FilterWindowHandle(HWND hwnd)
{
// Filtered window having WS_CHILDWINDOW style
if ((GetWindowLongPtr(hwnd, GWL_STYLE) & WS_CHILDWINDOW) != 0)
return (TRUE);
// Filtered window not having WS_CAPTION style
if ((GetWindowLongPtr(hwnd, GWL_STYLE) & WS_CAPTION) == 0)
return (TRUE);
// Not filtered
return (FALSE);
}
这些虚假事件来自阴影效果、菜单和屏幕上显示的所有内容。
是否有一种强大的方法来过滤其子窗口的真实窗口?
我避免了 WS_BORDER 或类似的测试,因为某些应用程序可以创建没有边框的主窗口......还是我错了?
I use CBT Windows Hook to detect window creation/deletion/min-max/move-size events.
I works well, but I need to filter whose events coming from normal widgets. Practically I need to being notified by CBT hook only for those windows that the user consider windows.
The problem that I'm facing make me mad, since I continuosly get spurious events even if I filter window as follow:
BOOL FilterWindowHandle(HWND hwnd)
{
// Filtered window having WS_CHILDWINDOW style
if ((GetWindowLongPtr(hwnd, GWL_STYLE) & WS_CHILDWINDOW) != 0)
return (TRUE);
// Filtered window not having WS_CAPTION style
if ((GetWindowLongPtr(hwnd, GWL_STYLE) & WS_CAPTION) == 0)
return (TRUE);
// Not filtered
return (FALSE);
}
Those spurious events comes from shadow effects, menus and everything displayed on screen.
Is there a robust method to filter real windows from its children?
I avoid the test of WS_BORDER
or similar, since some applications could create their main window without border... or am I wrong?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
非常适合“用户认为是窗口的事物”的是 Alt-Tab 列表(或任务栏上)中显示的一组窗口。
这篇 OldNewThing 文章解释了这些规则(尽管这些规则不是固定的或保证保持不变):
一般规则是:
这可以用显式窗口样式覆盖:
有关更多详细信息,请参阅这两个引用的完整 OldNewThing 帖子。
A good fit for "things the user considers windows" is the set of windows displayed in the Alt-Tab list (or on the Taskbar).
This OldNewThing article explains the rules (although the rules are not fixed or guaranteed to remain the same):
The general rule is:
This can be overridden with explicit window styles:
See the full OldNewThing post which those two quotes come from for more detail.
我过去使用的一个有用的标准是测试窗口是否是顶级窗口,即它的父窗口是否为 NULL。
A useful criteria that I've used in the past is to test whether the window is a top-level window, i.e. its parent is NULL.