views:

150

answers:

1

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?

+1  A: 

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.

GMan