MFC C++:setfocus 是否也设置捕获?

发布于 2024-12-17 11:08:50 字数 301 浏览 2 评论 0原文

我有一个 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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

雾里花 2024-12-24 11:08:50

不存在“键盘捕获”这样的东西。只有键盘焦点。

具有键盘焦点的窗口是接收键盘相关消息的窗口。
鼠标消息通常发送到鼠标光标正下方的窗口,而不考虑焦点。也就是说,除非鼠标被“捕获”,否则在这种情况下,无论鼠标光标在哪里,鼠标消息都会发送到捕获鼠标的窗口。

也就是说,你真的需要捕获鼠标吗?事实上,很少有必要这样做。并且它应该仅作为用户操作的结果来完成,而不是您自己完成。

附言。出于安全考虑,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:

  • Local captures: mouse messages are sent to the capturing window, only if the mouse is over a window that belongs to the same application.
  • Global capture: mouse messages are sent to the capturing window, no matter where the mouse cursor is.

The SetCapture function creates a global capture only if it is called while processing a WM_?BUTTON_DOWN message.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文