Advertisement Jump to content


This topic is now archived and is closed to further replies.


Best way to get window relative mouse-coords?

This topic is 5832 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

Which is the best way to retrieve window-relative mouse coordinates? ...To be used for a custom mouse-pointer or ray-picking in a 3d-environment? Is the WM_MOUSEMOVE message the only way to get that information? Hmm.. maybe i could just use god ol'' GetCursorPos(&point) + ScreenToClient(hwnd, &point) I think i solved it myself *grin* unless anyone''s got a better idea? /Niklas

Share this post

Link to post
Share on other sites
This is my method for Rel => Abs coords...

POINT ptMouse;

GetCursorPos( &ptMouse );
GetWindowPlacement( Window.hWindow(), &objWindow );

m_vtxPosition.X() = ptMouse.x - objWindow.rcNormalPosition.left;
m_vtxPosition.Y() = ptMouse.y -;

But your approach is nice too. Didn''t knew ScreenToClient().

/* Bullmax */
Reality has many forms : good and evil, black and white, yin and yang.

Share this post

Link to post
Share on other sites
Is there a function that takes a rect of the client area?
I haven''t been able to find a function that returned the top and left coordinate of the client screen (without the bar and edges that windows adds). I used getClientRect and getWindowrect and added a certain value to get the relative coordinates, but this is buggy as hell.

Share this post

Link to post
Share on other sites
AdjustWindowRect() will take a client rectangle and expand it based on how big the non-client area is. This could be used to determine the offset of the client area by looking at how much .left and .top have changed when doing the call.

Personally, I tend to use this when wanting a specific client area size. If I want a 640x480 backbuffer in windowed mode, then I use:

rect.left = 0
rect.right = 640 = 0;
rect.bottom = 480;
AdjustRect(&rect, winStyle, FALSE);
d3dpp.BackBufferWidth = rect.right - rect.left;
d3dpp.BackBufferHeight - rect.bottom -;

Share this post

Link to post
Share on other sites

  • Advertisement

Important Information

By using, you agree to our community Guidelines, Terms of Use, and Privacy Policy. is your game development community. Create an account for your GameDev Portfolio and participate in the largest developer community in the games industry.

Sign me up!