Wrap mouse around a window

Started by
3 comments, last by kath_roberts 22 years, 1 month ago
Hello, Does anyone know how to wrap the mouse around a window in Windows API, so that rather than stopping at the edge of the screen it goes back to the beginning (eg. so you can rotate around a character continuously)? Thanks.
Advertisement
I believe your window has to capture the mouse... then you do the check. If the mouse has exceeded the left edge (pos) move cursor to the right edge... same applies for up and down edges.
But can you really just set the cursor position? How?!

Cheers!
From the MSDN (msdn.microsoft.com):

BOOL SetCursorPos(int x, int y);
returns nonzero value if successfull.
....

int g_mousex = 0;
int g_mousey = 0;
RECT g_rect = {0,0,0,0};

LRESULT CALLBACK WindowProc(HWND hwnd, UINT msg, WPARAM wparam, LPARAM lparam)
{
case WM_MOUSEMOVE:
{
GetClientRect(hwnd, &g_rect); // Get window dimension

g_rect.right -= 12; // right offset
g_rect.left += 12; // left offset

g_mousex = GET_X_LPARAM(); // Get mouse X pos
g_mousey = GET_Y_LPARAM(); // Get mouse Y pos

if (g_mousex >= g_rect.right)
{
SetCursorPos(rect.left, g_mousey);

}//if

else if (g_mousex <= g_rect.left)
{
SetCursorPos(g_rect.right, g_mousey);

}//else if

break;

}//WM_MOUSEMOVE

.......

}//WindowProc

This topic is closed to new replies.

Advertisement