[INCLUDE]
GetOptMonitorFromPoint

[CODE]
Public Sub MoveRectToWorkArea(ByRef xWin As RECT, Optional ByVal NoOverlap As Boolean = True)
  Dim xLong2 As Long
  Dim xLong3 As Long
  Dim xType1 As RECT

  Const WindowOverlapBottom As Long = 48& '128&
  Const WindowOverlapSide As Long = 96&

  Call GetOptMonitorFromPoint(xWin.Left + xWin.Right / 2&, xWin.Top + xWin.Bottom / 2&, xType1)
  xLong2 = xType1.Right - xType1.Left
  xLong3 = xType1.Bottom - xType1.Top

  xWin.Right = xWin.Right - xWin.Left
  xWin.Bottom = xWin.Bottom - xWin.Top

  If xWin.Right > xLong2 Then xWin.Right = xLong2
  If xWin.Bottom > xLong3 Then xWin.Bottom = xLong3
  
  If NoOverlap Then
    If xWin.Left + xWin.Right > xLong2 Then xWin.Left = xLong2 - xWin.Right
    If xWin.Top + xWin.Bottom > xLong3 Then xWin.Top = xLong3 - xWin.Bottom
    If xWin.Left < xType1.Left Then xWin.Left = xType1.Left
    Else
    If xWin.Left + xWin.Right < xType1.Left + WindowOverlapSide Then xWin.Left = xType1.Left + WindowOverlapSide - xWin.Right
    If xWin.Left > xLong2 - WindowOverlapSide Then xWin.Left = xLong2 - WindowOverlapSide
    If xWin.Top > xLong3 - WindowOverlapBottom Then xWin.Top = xLong3 - WindowOverlapBottom
    End If
  If xWin.Top < xType1.Top Then xWin.Top = xType1.Top
  End Sub
