简体   繁体   English

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

[英]Locking focus and capture to a specific window

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. 我可以使用切换机制调用setfocus和setcapture,并在OnLButtonDown中确保消息不会继续传递,但这似乎在您单击鼠标左键时失败。 Is there any way to ensure that the window which has capture and focus does not give it up? 有什么方法可以确保具有捕获和焦点的窗口不会放弃它?

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. 不同之处在于,您要在单击组合键[Alt + Ctrl + P]上停止捕获。

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). 第一个使窗口保持活动状态,第二个使窗口保持Alt + Ctrl + P(然后按下该窗口将收到WM_HOTKEY事件,从此您可以停止捕获颜色)。 Sadly you cannot use RegisterHotKey with mouse buttons. 遗憾的是,您不能通过鼠标按钮使用RegisterHotKey。 You will want to look into SetWindowsHookEx 您将要研究SetWindowsHookEx

With SetWindowsHookEx, you can make sure your application will receive events even without focus. 使用SetWindowsHookEx,您可以确保应用程序即使没有焦点也将接收事件。 Call SetWindowsHookEx with the hook "WH_MOUSE", along with a Mouse Procedure . 调用带有钩子“ WH_MOUSE”的SetWindowsHookEx,以及一个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. 在此过程中,您将获得鼠标消息,停止捕获鼠标移动的位置(锁定颜色),并使用SetWindowPos将窗口移至顶部。 Then unregister your hook with UnhookWindowsHookEx . 然后使用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. 这可能是您可能需要学习的很多知识,但是我链接到的所有MSDN页面都包含大量信息,这些信息应该可以为您提供帮助,更不用说您是否愿意使用按键组合了,第二个链接非常适合您。

Hope that helps. 希望能有所帮助。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM