Skip to main content
GameDev.net gamedev.net
🔒 Locked

DirectInput - Mouse related

Started by Space_Panda Jan 13, 2003 at 9:37 PM 2 replies 500+ views
Original Post
Space_Panda
Space_Panda
Hi, I''m making a windowed game and I set the mouse cursor to the lower left portion of my playing surface and set a mousex and mousey position variable to zero. Now I initialized like so: if(FAILED(lpdi->CreateDevice(GUID_SysMouse, &lpdimouse, NULL))) return(0); if(FAILED(lpdimouse->SetCooperativeLevel(main_window_handle, DISCL_BACKGROUND| DISCL_NONEXCLUSIVE))) return(0); if(FAILED(lpdimouse->SetDataFormat(&c_dfDIMouse))) return(0); if(FAILED(lpdimouse->Acquire())) return(0); then at each call of my game loop I do the following if(FAILED(lpdimouse->GetDeviceState(sizeof(DIMOUSESTATE), (LPVOID)&mousestate))) return(0); mouse_posx += mousestate.lX; mouse_posy += mousestate.lY; if(mouse_posx > 400) test where test is defined as a MessageBox just to notify me when this happens My problem is that since my playing surface is 400 pixels wide and it starts at the first pixel in the surface, being 0x. Why is it that the message box comes up way before 400. And sometimes if I move the mouse around frantically. The position in which it calls the box changes? This has stumped me.
Smoot
Smoot
I think its because DInput get the screen coords not the window coords for the mouse. This means that even if the mouse isnt in the window, DInput will give you the exact coords of the mouse no matter what, or the change in mouse movement (depends on how you have it setup).

I believe that you can get the WINDOW mouse coords from WM_MOUSEMOVE:

case WM_MOUSEMOVE:
{
g_MousePoint.x = LOWORD(lparam);
g_MousePoint.y = HIWORD(lparam);

g_pDevice->SetCursorPosition(g_MousePoint.x, g_MousePoint.y, D3DCURSOR_IMMEDIATE_UPDATE);
}
return true;
Sleep is for the weak and needy, Mountain Dew and Pizza are for the real men.
Space_Panda
Space_Panda
I am using LPDIRECTINPUT8 to store my direct input not the 3d version of that. Is it possible using this ddinput.lib and not the libraries which contain IDirect3DDevice8 which is D3d8.lib.

This is a two dimensional game using DirectDraw7 and DirectInput8.
Space_Panda
Space_Panda
never mind figured it out. I just set the cursor position to the mouse_posx and mouse_posy. All works now. Thanks for the hint.

Topic Locked

This topic has been locked by a moderator. New replies are not allowed.

Sign in to reply to this topic.