Jump to content
  • Advertisement

Archived

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

Cipher3D

ARGGH! Mouse position relative to client area

This topic is 5547 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

I have a "dire" problem...it is pretty simple...how do you find out the position of the mouse cursor relative to your client area? (my window is not fullscreen - e.g. windowed - and it has menus and stuff). Thanx a lot. Cipher

Share this post


Link to post
Share on other sites
Advertisement
WM_MOUSEMOVE, WM_LBUTTONDOWN etc. all give coords relative to the client area.

Share this post


Link to post
Share on other sites
There''s probably a better way to do this, but this works fine:


  
//\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\

// Get the position of the cursor.

POINT c_core::get_cursor_pos()
{
static POINT pos;
static RECT wrect;
static RECT crect;
static int border_width;

// Get the cursor position.

GetCursorPos(&pos);

// Compensate for screen position.

GetWindowRect(window_handle, &wrect);
pos.x -= wrect.left;
pos.y -= wrect.top;

// Compensate for borders.

GetClientRect(window_handle, &crect);
border_width = ((wrect.right-wrect.left) - (crect.right-crect.left)) / 2;
pos.x -= border_width;
pos.y -= ((wrect.bottom-wrect.top) - (crect.bottom-crect.top)) - border_width;

return pos;
}

Share this post


Link to post
Share on other sites
quote:
Original post by Holy Fuzz
There''s probably a better way to do this, but this works fine:



It''s called ScreenToClient.

MSN

Share this post


Link to post
Share on other sites

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

Participate in the game development conversation and more when you create an account on GameDev.net!

Sign me up!