将焦点和捕获锁定到特定窗口

发布于 2024-07-16 10:55:58 字数 110 浏览 5 评论 0原文

我可以使用切换机制调用 setfocus 和 setcapture,并在 OnLButtonDown 中确保消息不会被传递,但在您单击左键时似乎会失败。 有什么方法可以确保具有捕获和焦点的窗口不会放弃它?

I can call a setfocus and setcapture using a toggle mechanism and in OnLButtonDown make sure the message doesn't get passed on, but that seems to fail the moment you left click. Is there any way to ensure that the window which has capture and focus does not give it up?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

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

发布评论

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

评论(1

唯憾梦倾城 2024-07-23 10:55:58

对于颜色选择器,请尝试阅读这篇文章,了解从屏幕上的任何位置获取颜色。

这个是一个更完整的实用程序,让您做您想做的事。 不同之处在于捕获组合键 [Alt+Ctrl+P] 上的停止,您希望在单击时停止。

在第二个链接中,以下函数调用将对您有用:

SetWindowPos(&wndTopMost, 0, 0, 0, 0, SWP_NOMOVE | SWP_NOSIZE);
RegisterHotKey(m_hWnd, 0x1FEB, MOD_CONTROL | MOD_ALT, 0x50);

第一个函数使窗口保持活动状态,第二个函数注册 Alt+Ctrl+P (按下该函数时,窗口将收到 WM_HOTKEY 事件,在此您可以停止捕捉颜色)。 遗憾的是,您不能将 RegisterHotKey 与鼠标按钮一起使用。 查看 SetWindowsHookEx

您将需要使用 SetWindowsHookEx ,您可以确保您的应用程序即使没有焦点也能接收事件。 使用挂钩“WH_MOUSE”以及 鼠标调用 SetWindowsHookEx程序

在此过程中,您将收到鼠标消息,停止捕获鼠标移动的位置(锁定颜色),并使用 SetWindowPos 将窗口移动到顶部。 然后使用 UnhookWindowsHookEx 取消注册您的挂钩。

这是您可能需要学习的大量内容,但是我为您链接的所有 MSDN 页面都有大量信息可以帮助您,更不用说您是否愿意使用组合键而不是第二个链接非常适合您。

希望有帮助。

For a color picker, try reading this article on getting colors from anywhere on screen.

This one is a more complete utility, let's you do what you want. The difference is capturing stops on a key combination [Alt+Ctrl+P], where you want to stop on a click.

In the second link, the following function calls will be useful for you:

SetWindowPos(&wndTopMost, 0, 0, 0, 0, SWP_NOMOVE | SWP_NOSIZE);
RegisterHotKey(m_hWnd, 0x1FEB, MOD_CONTROL | MOD_ALT, 0x50);

The first one keeps the window active, and the second registers Alt+Ctrl+P (And when that is pressed the window will receive a WM_HOTKEY event, where upon you can stop capturing colors). Sadly you cannot use RegisterHotKey with mouse buttons. You will want to look into SetWindowsHookEx

With SetWindowsHookEx, you can make sure your application will receive events even without focus. Call SetWindowsHookEx with the hook "WH_MOUSE", along with a Mouse Procedure.

It is in this procedure you will get the mouse message, stop capturing where the mouse moves (lock the color), and use SetWindowPos to move your window to the top. Then unregister your hook with UnhookWindowsHookEx.

This is quite a bit of stuff you might need to learn, but all the MSDN pages I've linked you to have plenty of information that should help you out, not to mention if you're willing to settle with a key combination instead the second link is perfect for you.

Hope that helps.

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