Jump to content
  • Advertisement
Sign in to follow this  
Demx

Win32 Mouse Coordinates wrong

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

hi ,

im using win32 to get mouse events and coordinates .. this is my code :




LRESULT CALLBACK MsgProc(HWND hWnd, UINT msg, WPARAM wParam, LPARAM lParam)

switch( msg )
{

case WM_LBUTTONDOWN:

int x = LOWORD( lParam ) ;
int y = HIWORD( lParam ) ;

app.setTarget( x, y );

return 0;

};

}



but for some reason the x and y returned from the lParam are wrong ..

thx for any reply smile.png

Share this post


Link to post
Share on other sites
Advertisement
i did this :



case WM_LBUTTONDOWN:

/*
int x = LOWORD(lParam);
int y = HIWORD(lParam);
*/

int x = GET_X_LPARAM( lParam );
int y = GET_Y_LPARAM( lParam );

app.setTarget( x, y );

return 0;


but the values are still wrong :P

Share this post


Link to post
Share on other sites
If you only want the coordinates, you could try the following (from NeHe's gluUnproject tutorial):


[font=Ubuntu, Arial, sans-serif]

POINT mouse; // Stores The X And Y Coords For The Current Mouse Position[/font]
[font=Ubuntu, Arial, sans-serif]

GetCursorPos(&mouse); // Gets The Current Cursor Coordinates (Mouse Coordinates)[/font]
[font=Ubuntu, Arial, sans-serif]

ScreenToClient(hWnd, &mouse);[/font]

Share this post


Link to post
Share on other sites
i tried all these solutions but none worked lol,

to explain the problem better :
i created a sprite and positioned it at (250;250) pixels. If i click on the left-top edge of the sprite
instead of 250;250 the mouse gives me 244;230.. so the coordinates are for some reason
messed up..

Share this post


Link to post
Share on other sites
The X and Y coordinates you get from the lParam of WM_LBUTTONDOWN are in client coodinates, meaning relative to the client area of the window. That code snippet involving GetCursorPos that someone posted above will also end up in client coordinates. Either you don't want client coordinates or you have a bug somewhere else. Anyway, to say more, would need to know what app.setTarget() does. Is it maybe expecting coodinates that are relative to the window rect or to the screen?

Share this post


Link to post
Share on other sites
Can you define "wrong"? What values are you getting? What values are you expecting to get? Remember that some of the Windows API will give you coords relative to the screen and some will give you coords relative to the window (which may mean the full window rect or the client rect) - it's your responsibility to know which coords you're getting and to translate from one to the other (in the case of WM_LBUTTONDOWN the coords are relative to the upper-left corner of the window's client area).

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement
×

Important Information

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

GameDev.net 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!