SRC_MON = 0 'number of the source monitor
DST_MON = 0 'number of the destination monitor
GUI = False 'set this to true to show a dialog for entering the destination monitor

If GUI = False Then
	For i = 0 To WScript.Arguments.Count - 1
		Select Case WScript.Arguments(i)
			Case "/d"
				DST_MON = CLng(WScript.Arguments(i + 1))
			Case "/s"
				SRC_MON = CLng(WScript.Arguments(i + 1))
		End Select
	Next
End If

If SRC_MON = 0 Then
	'check on which monitor the mouse is, then use that as the source monitor
	Set sys = CreateObject("UltraMon.System")
	curX = sys.CursorPosX
	curY = sys.CursorPosY

	For Each mon In sys.Monitors
		If curX >= mon.Left And curX <= (mon.Left + mon.Width) And curY >= mon.Top And curY <= (mon.Top + mon.Width) Then
			SRC_MON = mon.ID
			Exit For
		End If
	Next
End If

If GUI = True Then
	str = InputBox("Enter the number of the monitor to which applications should get moved:", WScript.ScriptName)
	If str = "" Then
		WScript.Quit
	Else
		DST_MON = CLng(str)
	End If
End If

If DST_MON = 0 Then
	'move apps to next monitor
	DST_MON = -1 'MOVEMONITOR_NEXT
End If

Set wnd = CreateObject("UltraMon.Window")
For Each w In wnd.GetAppWindows(True)
	If w.Monitor = SRC_MON Then
		w.Monitor = DST_MON
		w.ApplyChanges 1 + 2 'WNDCHANGE_RESIZE_TO_FIT + WNDCHANGE_CLIP_TO_WORKSPACE
	End If
Next


