Mouse input -> why?!?!

Started by
5 comments, last by wing_majin 22 years, 2 months ago
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)
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



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.
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.
Jeff Bland (Reverse_Gecko)reversegecko@gmail.com
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( );

~CGameProgrammer( );Developer Image Exchange -- New Features: Upload screenshots of your games (size is unlimited) and upload the game itself (up to 10MB). Free. No registration needed.
>>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
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) ?

This topic is closed to new replies.

Advertisement