Sign in to follow this  
theproject

win32 , problems setting cursor coordinate

Recommended Posts

Hi there, I'm trying to make a simple FPS while learning Direct3D, the problem here particularly is with the win32 API: Im using the normal win32 messages to process input, and, of course when the mouse moves i have to rotate my camera. The camera works fine, but when i get the WM_MOUSEMOVE message i want to reset the coordinate to the center of the screen (of course)after rotating the camera, the problem is exactly here: If i call the SetCursorPos (x,y); my windows is simply not drawn ( i see the border but not its content). I know this is a very simple question but i've been searching throughout msdn and i couldn't figure out what im doing wrong. Since I suspect of my main window attributes or whatever i'll post here the important part of it: wc.cbSize=sizeof(WNDCLASSEX); wc.style = CS_CLASSDC; wc.lpfnWndProc = (WNDPROC)msgHandler; wc.cbClsExtra = 0L; wc.cbWndExtra = 0L; wc.hInstance = GetModuleHandle(NULL);//hInstance; wc.hIcon = NULL; /*No icon*/ wc.hCursor = NULL; /*No cursor*/ wc.hbrBackground = NULL; wc.lpszMenuName = NULL; wc.lpszClassName = (LPCTSTR)TEXT("WindowClass"); wc.hIconSm=NULL; Please help, thanks in advance :)

Share this post


Link to post
Share on other sites
Sure:

LRESULT CALLBACK WndProc(HWND hwnd, UINT msg, WPARAM wParam, LPARAM lParam){
static int xPos=0;
static int yPos=0;
POINT center;

center.x=global.scrWidth/2;
center.y=global.scrHeight/2;


switch( msg ){

case WM_DESTROY:
::PostQuitMessage(0);
break;

//Mouse events
case WM_KEYDOWN:
if( wParam == VK_ESCAPE )
::DestroyWindow(hwnd);
break;

case WM_LBUTTONDOWN:
break;

case WM_RBUTTONDOWN:
break;

case WM_MOUSEMOVE: //Compute camera rotation based on mouse position
//global.cam.RotateRight((GET_X_LPARAM(lParam) - xPos)*0.0001f);
//global.cam.RotateDown((GET_Y_LPARAM(lParam) - yPos)*0.0001f);
//ClientToScreen (hwnd, ¢er);
SetCursorPos (center.x, center.y);

break;

//Keyboard events

default:
return ::DefWindowProc(hwnd, msg, wParam, lParam);
}

return 0;
}



It's here, i know this is horrible in terms of procedural abstraction and design in general but this is only a test, so that i don't make lot's of classes based on something i don't know if it works.

Share this post


Link to post
Share on other sites
My guess would be that global.srcWidth and global.srcHeight aren't being set properly. Check to see what those values are right before you call SetCursorPos().

Edit: or, even better, just check to see what center.x and center.y are before calling that function.

Share this post


Link to post
Share on other sites
Also, I suspect SetCursorPos just does this but cannot hurt to try:
SendMessage(hWnd, WM_MOUSEMOVE, (WPARAM)0, (LPARAM)MAKELPARAM(center.x,center.y));

Also you likely want to check to see if the current mouse positions is == to center.x/y so you don't process your own message but it also keeps focus on your window (least in my experience).

Also I just skimmed this but for the overall knowledge might be a short and decent read for you:
http://blogs.msdn.com/oldnewthing/archive/2003/10/01/55108.aspx

Share this post


Link to post
Share on other sites
thanks a lot for your replies, i put an If testing if the new position was different then the old one and it worked. i Didn't knew that calling setCusorPos would generate a new message back to me saying "the mouse moved".

Thanks a lot :D cya

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this