MFC C++:setfocus 是否也设置捕获?
我有一个 CDialog 正在调用 DoModal(),对话框已打开,其他所有内容都被禁用,但由于某种原因我只有键盘捕获而没有鼠标。
鼠标捕获仍在其所在的最后一个项目上。
如果我在 DoModal 之前调用 setfocus,它将不起作用,但如果我在 DoModal 之前调用 setCapture,它就会起作用。
谁能给我解释一下吗?
问题是什么?我想了解为什么我需要在 DoModal 之前调用 setCapture 或 releaseCapture (顺便说一句,releaseCapture 也可以工作......)
I have a CDialog that is calling DoModal(), the dialog is opened, everything else is disabled, but for some reason I have only the keyboard capture and not the mouse.
The mouse capture is still on the last item it was on.
If I call setfocus before the DoModal, it doesn't work, but if I do setCapture before the DoModal it works.
Can anyone explain it to me?
What is the problem? I want to understand why I need to call to setCapture or releaseCapture before the DoModal (btw- releaseCapture works as well...)
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
不存在“键盘捕获”这样的东西。只有键盘焦点。
具有键盘焦点的窗口是接收键盘相关消息的窗口。
鼠标消息通常发送到鼠标光标正下方的窗口,而不考虑焦点。也就是说,除非鼠标被“捕获”,否则在这种情况下,无论鼠标光标在哪里,鼠标消息都会发送到捕获鼠标的窗口。
也就是说,你真的需要捕获鼠标吗?事实上,很少有必要这样做。并且它应该仅作为用户操作的结果来完成,而不是您自己完成。
附言。出于安全考虑,Windows 中实际上有两种不同类型的鼠标捕获:
仅当在处理 WM_?BUTTON_DOWN 消息时调用
SetCapture
函数时,该函数才会创建全局捕获。There is no such thing as 'keyboard capture'. There is just keyboard focus.
A window that has the keyboard focus is the one that receives the keyboard related messages.
Mouse messages are normally sent to the window just beneath the mouse cursor, without regard to the focus. That is unless the mouse is "captured", in this case mouse messages are sent to the windows that has captured the mouse, no matter where the mouse cursor is.
That said, do you really need to capture the mouse? Actually that is rarely necessary. And it should be done only as a consequence to a user action, never on your own.
PS. Due to security concerns, in Windows there are actually two different kinds of mouse captures:
The
SetCapture
function creates a global capture only if it is called while processing a WM_?BUTTON_DOWN message.