Archived

This topic is now archived and is closed to further replies.

kath_roberts

Wrap mouse around a window

Recommended Posts

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.

Share this post


Link to post
Share on other sites
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.

Share this post


Link to post
Share on other sites
....

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

Share this post


Link to post
Share on other sites