Wrap mouse around a window
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.
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.
From the MSDN (msdn.microsoft.com):
BOOL SetCursorPos(int x, int y);
returns nonzero value if successfull.
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
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
Popular Topics
Advertisement