win32 , problems setting cursor coordinate

Started by
4 comments, last by theproject 18 years ago
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 :)
Advertisement
Post the code where you call SetCursorPos(), if you will. Thanks.
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, &center);
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.
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.
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

"Those who would give up essential liberty to purchase a little temporary safety deserve neither liberty nor safety." --Benjamin Franklin

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

This topic is closed to new replies.

Advertisement