• Advertisement

Archived

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

Mouse input -> why?!?!

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

Maybe this is really more of a winAPI question but.. I was attempting to use mouse input as screen position information when i found out that GetCursorPos(&pos) from the windows object POINT pos (or something like that) gets the cursor postion relative to the entire screen no matter what active window is up. I never really had to to use mouse stuff before so i guess i never knew. Does anyone know how to get the mouse position while bounded within the active window so it can ACTUALLY be useful? (ie: window is 640 x 480...so mouse position shouldn''t be more than 640 and 480 ...ever)

Share this post


Link to post
Share on other sites
Advertisement
there is several solutions to your problem depending on what you are using for your window. you can use
CWnd::GetWindowPos
or you can use
the CBaseControlWindow Class which alows for you to find the position and size of the window so you will always beable to tell if your in the bounds of your window relative to the cursor possition.

CBaseControlWindow::GetWindowPosition
CBaseControlWindow Class
Retrieves the current coordinates for the window.

HRESULT GetWindowPosition(
long *pLeft,
long *pTop,
long *pWidth,
long *pHeight
);


Parameters
pLeft
Contains the left coordinate, in screen coordinates.
pTop
Contains the top coordinate, in screen coordinates.
pWidth
Contains the window width, in screen coordinates.
pHeight
Contains the window height, in screen coordinates.
Return Values
Returns an HRESULT value.

check for more documentation for these two commands
CWnd::GetWindowPos
CBaseControlWindow::GetWindowPosition



Share this post


Link to post
Share on other sites
If you are not using MFC, you can use GetWindowPlacement to get the position of the top left corner of the window, but you probably just want the client area (ie not caption bar+menubar+borders ect.) in which case you should use GetWindowInfo. Just subtract start position of the client area from the mouse coordinate to get client coordinates. You need to trap WM_SIZE and WM_MOVE functions and update accordingly.

Share this post


Link to post
Share on other sites
as long as people are aking about the mouse in the windows API, i have a question too.

How do you set the mouse to the center of the screen? Im trying to get the mouse mickey for an fps style engine, but once it reaches the right edge you can''t move the mouse more right, so you cant turn right beyond that point. Same with left.

Share this post


Link to post
Share on other sites
To set the mouse position, do the following:

(1) Use DirectInput

When you''ve performed those steps, your problem will be solved. Also your problem with the mouse position will be solved. Basically, DirectInput gives you full control over the mouse, so you can change its sensitivity, position, range, etc.

~CGameProgrammer( );

Share this post


Link to post
Share on other sites
>>How do you set the mouse to the center of the screen? Im trying to get the mouse mickey for an fps style engine, but once it reaches the right edge you can''t move the mouse more right, so you cant turn right beyond that point. Same with left. <<

setcursorpos(..)
u might wanna take a peak at sdl for handling your input

http://uk.geocities.com/sloppyturds/gotterdammerung.html

Share this post


Link to post
Share on other sites
I tried to implement GetWindowInfo but it takes a PWINDOWINFO struct as an argument. When I declare one of these the compiler doesn''t recognize it. I shouldn''t have to include anything besides windows.h right?
Don''t i just pass the HWND of my window and the PWINDOWINFO to the function (as MSDN says):

BOOL GetWindowInfo(
HWND hwnd, // handle to window
PWINDOWINFO pwi // window information
);

and then retrieve mouse coordinates from
pwi.rcClient.left/right/top/bottom etc ( the RECT struct) ?

Share this post


Link to post
Share on other sites

  • Advertisement