Mouse position

"Diogo de Andrade" <[email protected]> Tue, 18 Oct 2005 12:35:00 +0100
Newsgroups gmane.games.devel.windows
Organization Spellcaster Studios
Message-ID <003101c5d3d7$fd1246f0$2001a8c0@rivendell>
Hey all.
 
I'm having a small problem getting the coordinate of the mouse in the
window. My current system gets the coordinate like this:
 
POINT pt;
GetCursorPos(&pt);
 
Then I want to transform this coordinate (in absolute screen
coordinates, as I see it) to my engine's coordinates (which has logical
coordinates, to account for different resolutions, bitmap scaling,
etc)... 
I get the window rectangle (also in screen coordinates):
 
RECT rect;
GetWindowRect(m_window,&rect);
 
Finally, I do the conversion itself
 
float sx=rect.right-rect.left;
float sy=rect.bottom-rect.top;
 
float relative_x=virtual_res_x*(pt.x-rect.left)/sx;
float relative_y=virtual_res_y*(pt.y-rect.top)/sy;
 
This works almost perfectly, except when I approach the cursor from the
top of the window... The window has the standard bar (created with
WS_OVERLAPPED | WS_CAPTION | WS_SYSMENU | WS_THICKFRAME | WS_MINIMIZEBOX
| WS_MAXIMIZEBOX | WS_VISIBLE | WS_POPUPWINDOW), and apparently
GetWindowRect gets the whole window, including the top bar, instead of
getting only the "drawable" part of it... I imagine the problem is that
m_window above is a parent window with 2 children (the system bar, and
the drawable part), but I can't find how to get just the drawable
rectangle to do the conversion... This works fine if I create the window
without border of title/system bar... So, my question is: how do I get
the drawable part of the window's rectangle?
 
Thanks in advance!
 
Diogo de Andrade
Creative & Technical Director
Spellcaster Studios
[email protected]
www.spellcasterstudios.com