snapping windows
-
hey, I override WM_MOVING to change the drag rectangle of a moving window to "snap" to the borders of the desktop... the problem is "unsnapping" -- i can't unsnap because the original drag rectangle isn't stored and whenever i want to move the drag rectangle it keeps moving back to the snapped position:
case WM_MOVING:
{
RECT rcWorkArea;
if (SystemParametersInfo(SPI_GETWORKAREA,0,&rcWorkArea,0))
{
RECT* pRC = (RECT*)lParam;
if (pRC->bottom >= rcWorkArea.bottom - 10) // distance before snapping = 10
OffsetRect(pRC,0,rcWorkArea.bottom - pRC->bottom);
else if (pRC->top <= rcWorkArea.top + 10)
OffsetRect(pRC,0,rcWorkArea.top - pRC->top);
}
return TRUE;
}also, how the hell do i get the position of the mouse! i thought there was a function
GetMousePos
which took in a pointer to a POINT structure but it doesn't exist... so how do i do it?r -€
-
hey, I override WM_MOVING to change the drag rectangle of a moving window to "snap" to the borders of the desktop... the problem is "unsnapping" -- i can't unsnap because the original drag rectangle isn't stored and whenever i want to move the drag rectangle it keeps moving back to the snapped position:
case WM_MOVING:
{
RECT rcWorkArea;
if (SystemParametersInfo(SPI_GETWORKAREA,0,&rcWorkArea,0))
{
RECT* pRC = (RECT*)lParam;
if (pRC->bottom >= rcWorkArea.bottom - 10) // distance before snapping = 10
OffsetRect(pRC,0,rcWorkArea.bottom - pRC->bottom);
else if (pRC->top <= rcWorkArea.top + 10)
OffsetRect(pRC,0,rcWorkArea.top - pRC->top);
}
return TRUE;
}also, how the hell do i get the position of the mouse! i thought there was a function
GetMousePos
which took in a pointer to a POINT structure but it doesn't exist... so how do i do it?r -€
-
hey, I override WM_MOVING to change the drag rectangle of a moving window to "snap" to the borders of the desktop... the problem is "unsnapping" -- i can't unsnap because the original drag rectangle isn't stored and whenever i want to move the drag rectangle it keeps moving back to the snapped position:
case WM_MOVING:
{
RECT rcWorkArea;
if (SystemParametersInfo(SPI_GETWORKAREA,0,&rcWorkArea,0))
{
RECT* pRC = (RECT*)lParam;
if (pRC->bottom >= rcWorkArea.bottom - 10) // distance before snapping = 10
OffsetRect(pRC,0,rcWorkArea.bottom - pRC->bottom);
else if (pRC->top <= rcWorkArea.top + 10)
OffsetRect(pRC,0,rcWorkArea.top - pRC->top);
}
return TRUE;
}also, how the hell do i get the position of the mouse! i thought there was a function
GetMousePos
which took in a pointer to a POINT structure but it doesn't exist... so how do i do it?r -€
If you want to unsnap you will need to track the direction of the mouse movement. i.e. if it is moving away from the edge then do not apply the snap criteria. For this you will need to store the last position of the mouse then compare with current position. You can then decide whether to snap or not. Ant.