0

This successfully retrieves the screen coordinates but I would like it to display coordinates relative to a particular window that is being moused over:

POINT p;
                if (GetCursorPos(&p))
                {
                    std::cout << p.x << "," << p.y << std::endl;
                    //cursor position now in p.x and p.y
                }

Can I modify the code to do that?

1 Answer 1

0

Yes, that's exactly what ScreenToClient does:

if (not ScreenToClient(window, &p)) { /* handle error */ }

If this is your own window, you'll also be receiving WM_MOUSEMOVE messages that you can use to keep track of the cursor position and won't need to poll for it. Depending what you want this for, there's even WM_MOUSEHOVER.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.