是否可以创建一个不会停用父窗口的子窗口?
通常,当创建子窗口(WS_POPUP)时,子窗口将变为激活状态,而父窗口将变为非激活状态。然而,对于菜单,两者都保持活动状态。至少我假设菜单处于活动状态,它至少有焦点。
示例:单击记事本中的文件菜单,菜单出现,但记事本窗口看起来仍然处于活动状态。
是否可以通过窗口样式或响应特定消息来反映此行为?
谢谢
另一个例子:组合框似乎显示一个子窗口,但不停用该窗口。您可以单击该子窗口,同时仍然保持激活的主窗口。关于如何获取该窗口的类/样式有什么想法吗?
Normally when creating a sub window (WS_POPUP), the child window will become activate and the parent will become deactivated. However, with menus, both remain active. At least I am assuming the menu is active, it at least has focus.
Example: Click on the file menu in notepad, the menu appears, yet the notepad window still looks active.
Is it possible to mirror this behavior with either a window style or responding to a particular message?
Thanks
Another example: Combo boxes seem to show a subwindow, yet do not deactivate the window. And you can click on that subwindow, while still maintaining an activate main window. Any ideas on how to grab the class /style of that window?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(4)
组合框中的列表下拉菜单有点麻烦,它既是弹出窗口又是子窗口,我不能推荐这种方法(未记录的样式组合,以及 IIRC,使用“正常”来执行此操作有点错误“浮动窗口/工具栏)
这给您留下了两个选项:
The list dropdown in a combobox is a bit of a hack, it is both a popup and a child window, I can't recommend that approach (Undocumented style combination, and IIRC, it is a bit buggy to do this with a "normal" floating window/toolbar)
This leaves you with two options:
我很惊讶创建一个新的弹出窗口会激活它。通常您需要调用 SetActiveWindow 。但是请查看 WM_ACTIVATE 和 WM_NCACTIVATE 了解如何阻止窗口停用。
I am surprised that creating a new popup window activates it. Normally you'd need to call SetActiveWindow. However check out WM_ACTIVATE and WM_NCACTIVATE on how to stop the window becoming deactivated.
许多人忽略的一个事实是,Windows 没有单独的窗口管理器组件: - 大多数窗口管理职责由每个窗口执行 - 通常在 DefWindowProc 中。
大多数窗口定位和激活/取消激活最终都是通过调用 SetWindowPos 完成的,它总是发送一条 WM_WINDOWPOSCHANGING 消息,允许窗口对发生的情况有最终决定权。
DefWindowProc 还激活自己的窗口以响应鼠标单击等。
所有这一切的结果是,很可能创建从不接受激活的窗口 - 它确实需要广泛了解哪些消息和情况可能导致激活。
最终我可以说,为远程调试配置调试设置非常方便 - 这样您就可以与调试器交互,而不会影响系统的激活状态 - 因此在问题 WM_ACTIVATE 处理程序中将断点放入窗口中,然后简单地调试任何导致意外激活的情况。
如果您还想处理键盘焦点,则可能会更棘手 - 通常焦点会分配给激活的窗口 - 但通常由 DefWindowProc 负责分配两者。我只是认为它很危险,因为有一个窗口仍然明显处于激活状态,而另一个窗口具有焦点。这会让任何辅助软件都感到非常困惑。
我很想执行消息循环级别的消息挂钩 - 类似于 IsDialogMessage - 来过滤用于弹出窗口的击键。
A fact that a lot of people miss is that windows does not have a separate window manager component :- most of the window management duties are performed by each window - usually in DefWindowProc.
Most window positioning and activation / de-activation is done - ultimately - via a call to SetWindowPos - which always sends a WM_WINDOWPOSCHANGING message allowing the window to have a final say on what happens.
DefWindowProc also activate its own window in response to mouse clicks and so on.
The result of all this is, it is quite possible to create windows that never accept activation - it does require an extensive understanding of what messages and situations might have led to an activation.
Ultimately I can say that it is VERY handy to have a debugging setup configured for remote debugging - so that you can interact with your debugger without effecting the activation state of the system - and hence drop a breakpoint into the window in questions WM_ACTIVATE handler and simply debug any situation leading to an unwanted activation.
If You want to handle keyboard focus as well, it might be trickier - normally focus is given to an activated window - but again its usually the DefWindowProc responsible for assigning both. I just see it dangerous as having one window, still obviously activated, and another with focus. This will confuse any assistive software greatly.
I'd be tempted to perform a message loop level message hook - Similar to IsDialogMessage - to filter keystrokes intended for the popup window.
如果您使用 WS_EX_NOACTIVATE 创建弹出窗口,它将不会由用户输入激活(您仍然可以通过编程方式激活它),因此您的主应用程序窗口仍将保持活动状态。
If you create your popup window with WS_EX_NOACTIVATE it will not be activated by user input (You could still activate it programatically) and therefore your main application window will still remain active.