I want to prevent a window from being moved between monitors by checking for the message WM_MOVE and using the SetWindowPos function to keep the window within the bounds of the display. When I try to do this, the window briefly flashes where the mouse is and snaps to a small area on the bottom of the screen. I'm not sure why this is happening, since the code is just like any other collision detection:
case WM_MOVE:
{
int nX = (int)(short)LOWORD(lParam);
int nY = (int)(short)HIWORD(lParam);
if (nX < pDisplayDevice->getLeft()) {
nX = pDisplayDevice->getLeft();
} else if (nX + int(uNormalWidth) > pDisplayDevice->getRight()) {
nX = pDisplayDevice->getRight() - int(uNormalWidth);
}
if (nY < pDisplayDevice->getTop()) {
nY = pDisplayDevice->getTop();
} else if (nY + int(uNormalHeight) > pDisplayDevice->getBottom()) {
nY = pDisplayDevice->getBottom() - int(uNormalHeight);
}
SetWindowPos(hWnd, 0, nX, nY, uNormalWidth, uNormalHeight, 0);
}
break;
pDisplayDevice is basically a pointer to a Rect that contains the coordinates of the display, and uNormalWidth/uNormalHeight are the width and height of the window in windowed mode.
uNormalWidthanduNormalHeight? - PMF