Archived

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

Blue*Omega

Relative mouse position

Recommended Posts

hm... this one has been buggin me for a while, but I can''t seem to figure it out. SDK isn''t much help either... anyway''s, on with the question! In direct input, the default format that teh mouse returns information in was how much it moved in any direction since the last check, right? Well, that''s great when I''m making myself Quake V, but at the moment all I want to do is make a simple, 2D, map editor! Is there ANY way I can get the position pf teh mouse relative to the window I''m using? you know... 0,0 is top left, etc. etc. Thanks! ----------------------------- Vash the Stampede "Love & Peace!"

Share this post


Link to post
Share on other sites
Win32''s GetCursorPos()? Or doesn''t this work when DI is exclusive? Then I think you can get the window''s rectangle by calling GetClientRect on it. Subtract the window''s left from the point''s x and the window''s top from the point''s y and that gives it...I think

---------------

I finally got it all together...
...and then forgot where I put it.

Share this post


Link to post
Share on other sites
Code sample:
  
POINT GetRelativeCursorPos(HWND wnd)
{
POINT pt;
GetCursorPos(&pt);
RECT rc;
GetClientRect(wnd,&rc);
pt.x -= rc.left;
pt.y -= rc.top;
return pt;
}

I think that''s right

---------------

I finally got it all together...
...and then forgot where I put it.

Share this post


Link to post
Share on other sites
You can set whether you want relative or non-relative by using setproperty. Here's some code to change to absolute position:

DIPROPDWORD dipdw;
//clear structure
ZeroMemory(&dipdw, sizeof(DIPROPDWORD));
dipdw.diph.dwSize=sizeof(DIPROPDWORD);
dipdw.diph.dwHeaderSize=sizeof(dipdw.diph);
dipdw.diph.dwHow=DIPH_DEVICE;
dipdw.diph.dwObj=0;
dipdw.data=DIPROPAXISMODE_ABS;
g_MouseDevice->SetProperty(DIPROP_AXISMODE, &dipdw.diph);

I havn't tried it and there might be some problems. Try it out. if it doesn't work, tell me and I'll try and figure it out.

[Edited by - kmsixpence on October 17, 2005 7:23:36 PM]

Share this post


Link to post
Share on other sites
Hmm... okay, the GetCursorPos() thing works, but the stupid GetClientRect() or whatever it was simply refuses to give me useful information! I send it my windows handle and get... 0,0.
Huh? Wait! I clearly remember putting my window at 100,100! What''s wrong?

Also, whatever all that DX jusnk was... it did absolutly squat!
(even after changing the "dipdw.data" to "dipdw.dwData" to make it work ^_^)

-----------------------------

Vash the Stampede

"Love & Peace!"

Share this post


Link to post
Share on other sites