Edit: Hide/Show mouse using ShowCursor - http://msdn.microsoft.com/en-us/library/ms648396
Keep resetting the mouse position to the center of the screen if you are working in a relative movement mode and track the movement.
This is pretty much Win32 related not having anything to do with Direct3D. I'm personally using it along side Direct Input which takes care of joysticks / gamepads.
Here is part of the code I'm using
case WM_MOUSEMOVE:
{
//Most other messages are only sent to windows with the current focus
//but mouse move is sent whenever the mose is hovering over, so we need
//to ignore it if we don't have focus
if (!IsWindowActive)
break;
//X and Y can be relative or absolute
if (!MouseAbsolute)
{
if (IgnoreNextMouseMove)
{
IgnoreNextMouseMove = false;
return 0;
}
POINT temp;
GetCursorPos(&temp);
// WM_MOUSEMOVE is 2 shorts, so I think it is safe to assume all mouse cooridnates are words
int16 MouseX = (WORD)temp.x;
int16 MouseY = (WORD)temp.y;
//Add new changes to any existing
//InputDriverInteral resets these to 0 when the axis is read
uint16 cX = wX + wLength/2;
uint16 cY = wY + wHeight/2;
// This is a float array
Axis[IA_MOUSE_X] += (MouseX - cX) / (float)wLength;
Axis[IA_MOUSE_Y] += (MouseY - cY) / (float)wHeight;
// This is a struct array with a float and a bool
m_AxisMap[IA_MOUSE_X].Value = pDriver->Axis[IA_MOUSE_X];
m_AxisMap[IA_MOUSE_X].Changed = true;
m_AxisMap[IA_MOUSE_Y].Value = pDriver->Axis[IA_MOUSE_Y];
m_AxisMap[IA_MOUSE_Y].Changed = true;
// Set cursor position will send WM_MOUSEMOVE so we need to ignore that message
IgnoreNextMouseMove = true;
SetCursorPos(cX, cY);
}else
{
int16 MouseX = LOWORD(lParam);
int16 MouseY = HIWORD(lParam);
//Get our absolute position within the window
Axis[IA_MOUSE_X] = (float)MouseX / wLength;
//Do the same as above but for y (note that windows is top left but we want from bottom left)
//Get our absolute position within the window
Axis[IA_MOUSE_Y] = (float)MouseY / wHeight;
// Flag these axis as changed
m_AxisMap[IA_MOUSE_X].Value = pDriver->Axis[IA_MOUSE_X];
m_AxisMap[IA_MOUSE_X].Changed = true;
m_AxisMap[IA_MOUSE_Y].Value = pDriver->Axis[IA_MOUSE_Y];
m_AxisMap[IA_MOUSE_Y].Changed = true;
}
//Send an event notification
pDriver->SendThreadingEvent();
}
break;
It works pretty well and the only issues I've had is if the user moves the mouse at an insane rate. The windows mouse position is limited to the size of the user's desktop so it cannot capture movement beyond that.
If you want to see the complete code for better context take a look:
http://code.google.com/p/cobaltlibrary/source/browse/trunk/Drivers/Source/Input/DInput8/DInput_WinProc.cpp