Guest User

Untitled

a guest
Jul 20th, 2018
78
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 6.01 KB | None | 0 0
  1. 'script configuration:
  2. 'the coordinates of each monitor, either of the full screen area or parts of it, need to be specified, ordered from left to right.
  3. 'to take taskbars and desktop toolbars into account when maximizing or moving a window, specify the workspace coordinates instead of
  4. 'the screen coordinates. both types of coordinates are shown for each monitor under UltraMon menu > About
  5. '
  6. 'sample script configuration:
  7. 'two monitors at 1024x768, the first monitor is split in a left and right half, the second monitor isn't split:
  8. 'MONITORS = Array("0,0,512,768","512,0,1024,768","1024,0,2048,768")
  9. '
  10. 'optional command-line arguments for the script:
  11. '
  12. '/m: maximize window after moving it
  13. '/n: move window to next monitor (default)
  14. '/p: move window to previous monitor
  15. '/r: only resize window if necessary (resize to fit). default is resize proportionally
  16.  
  17. Option Explicit
  18. Dim MONITORS
  19. MONITORS = Array("0,0,1440,900","1440,-180,2400,1080","2400,-180,3360,1080")
  20.  
  21. If UBound(MONITORS) = -1 Then
  22. MsgBox "You'll need to configure the script before using it for the first time. To do this, right-click the script and select Edit from the menu, then read the instructions at the top of the script.",, "VMonMoveWnd3"
  23. WScript.Quit
  24. End If
  25.  
  26. Const SHOWSTATE_NORMAL = 2
  27. Const POS_LEFT = 0
  28. Const POS_TOP = 1
  29. Const POS_RIGHT = 2
  30. Const POS_BOTTOM = 3
  31.  
  32. Dim moveNext, resizeToFit, args, maximize
  33. moveNext = True
  34. resizeToFit = False
  35. maximize = False
  36. Set args = WScript.Arguments
  37. For i = 0 To args.Count - 1
  38. Select Case args(i)
  39. Case "/m"
  40. maximize = True
  41. Case "/n"
  42. moveNext = True
  43. Case "/p"
  44. moveNext = False
  45. Case "/r"
  46. resizeToFit = True
  47. End Select
  48. Next
  49.  
  50. Dim wnd
  51. Set wnd = CreateObject("UltraMon.Window")
  52. If wnd.GetForegroundWindow() = True Then
  53. Dim wndLeft, wndRight, wndTop, wndBottom, wndWidth, wndHeight
  54. wndLeft = wnd.Left
  55. wndTop = wnd.Top
  56. wndWidth = wnd.Width
  57. wndHeight = wnd.Height
  58. wndRight = wnd.Left + wndWidth
  59. wndBottom = wnd.Top + wndHeight
  60.  
  61. 'msgbox "wnd: " & wndLeft & "," & wndTop & " - " & wndRight & "," & wndBottom
  62.  
  63. Dim i, str, rect, intLeft, intTop, intRight, intBottom, area, maxArea, maxAreaMonIndex
  64. maxAreaMonIndex = -1
  65. For i = 0 To UBound(MONITORS)
  66. str = Split(MONITORS(i), ",")
  67. rect = Array(CLng(str(0)), CLng(str(1)), CLng(str(2)), CLng(str(3)))
  68. If Not (wndRight <= rect(POS_LEFT) Or wndLeft >= rect(POS_RIGHT) Or wndTop >= rect(POS_BOTTOM) Or wndBottom <= rect(POS_TOP)) Then
  69. intLeft = wndLeft
  70. If intLeft < rect(POS_LEFT) Then intLeft = rect(POS_LEFT)
  71. intTop = wndTop
  72. If intTop < rect(POS_TOP) Then intTop = rect(POS_TOP)
  73. intRight = wndRight
  74. If intRight > rect(POS_RIGHT) Then intRight = rect(POS_RIGHT)
  75. intBottom = wndBottom
  76. If intBottom > rect(POS_BOTTOM) Then intBottom = rect(POS_BOTTOM)
  77.  
  78. area = (intRight - intLeft) * (intBottom - intTop)
  79. If area > maxArea Then
  80. maxArea = area
  81. maxAreaMonIndex = i
  82. End If
  83.  
  84. 'msgbox "mon: " & MONITORS(i) & " int: " & intLeft & "," & intTop & " - " & intRight & "," & intBottom & " area: " & area
  85. End If
  86. Next
  87.  
  88. If maxAreaMonIndex <> -1 Then MoveWindow wnd, maxAreaMonIndex, moveNext, resizeToFit, maximize
  89. End If
  90.  
  91. Sub MoveWindow(wnd, curMonIndex, moveNext, resizeToFit, maximize)
  92. Dim curLeft, curTop, curWidth, curHeight, curMonLeft, curMonTop, curMonWidth, curMonHeight
  93. Dim newMonIndex, newMonLeft, newMonTop, newMonWidth, newMonHeight
  94.  
  95. curLeft = wnd.Left
  96. curTop = wnd.Top
  97. curWidth = wnd.Width
  98. curHeight = wnd.Height
  99.  
  100. str = Split(MONITORS(curMonIndex), ",")
  101. rect = Array(CLng(str(0)), CLng(str(1)), CLng(str(2)), CLng(str(3)))
  102. curMonLeft = rect(POS_LEFT)
  103. curMonTop = rect(POS_TOP)
  104. curMonWidth = rect(POS_RIGHT) - rect(POS_LEFT)
  105. curMonHeight = rect(POS_BOTTOM) - rect(POS_TOP)
  106.  
  107. newMonIndex = curMonIndex
  108. newMonLeft = 0
  109. newMonTop = 0
  110. newMonWidth = 0
  111. newMonHeight = 0
  112.  
  113. If moveNext Then
  114. newMonIndex = newMonIndex + 1
  115. If newMonIndex > UBound(MONITORS) Then newMonIndex = 0
  116. Else
  117. newMonIndex = newMonIndex - 1
  118. If newMonIndex < 0 Then newMonIndex = UBound(MONITORS)
  119. End If
  120.  
  121. str = Split(MONITORS(newMonIndex), ",")
  122. rect = Array(CLng(str(0)), CLng(str(1)), CLng(str(2)), CLng(str(3)))
  123. newMonLeft = rect(POS_LEFT)
  124. newMonTop = rect(POS_TOP)
  125. newMonWidth = rect(POS_RIGHT) - rect(POS_LEFT)
  126. newMonHeight = rect(POS_BOTTOM) - rect(POS_TOP)
  127.  
  128. If newMonWidth <> 0 Then
  129. Dim newLeft, newTop, newWidth, newHeight, offsetX, offsetY, offsetXRel, offsetYRel
  130. Dim newOffsetX, newOffsetY, relWidth, relHeight
  131.  
  132. If maximize = True Then
  133. newLeft = newMonLeft
  134. newTop = newMonTop
  135. newWidth = newMonWidth
  136. newHeight = newMonHeight
  137. Else
  138. offsetX = curLeft - curMonLeft
  139. offsetY = curTop - curMonTop
  140.  
  141. If newMonWidth = curMonWidth And newMonHeight = curMonHeight Then
  142. newLeft = newMonLeft + offsetX
  143. newTop = newMonTop + offsetY
  144. newWidth = curWidth
  145. newHeight = curHeight
  146. Else
  147. If resizeToFit = True Then
  148. offsetXRel = offsetX / curMonWidth
  149. offsetYRel = offsetY / curMonHeight
  150. newOffsetX = newMonWidth * offsetXRel
  151. newOffsetY = newMonHeight * offsetYRel
  152.  
  153. newWidth = curWidth
  154. If newWidth > newMonWidth Then newWidth = newMonWidth
  155. newHeight = curHeight
  156. If newHeight > newMonHeight Then newHeight = newMonHeight
  157.  
  158. If newOffsetX + newWidth > newMonWidth Then newOffsetX = newMonWidth - newWidth
  159. If newOffsetY + newHeight > newMonHeight Then newOffsetY = newMonHeight - newHeight
  160.  
  161. newLeft = newMonLeft + newOffsetX
  162. newTop = newMonTop + newOffsetY
  163. Else
  164. offsetXRel = offsetX / curMonWidth
  165. offsetYRel = offsetY / curMonHeight
  166. relWidth = curWidth / curMonWidth
  167. relHeight = curHeight / curMonHeight
  168. newLeft = newMonLeft + newMonWidth * offsetXRel
  169. newTop = newMonTop + newMonHeight * offsetYRel
  170. newWidth = newMonWidth * relWidth
  171. newHeight = newMonHeight * relHeight
  172.  
  173. 'MsgBox "newWnd: " & newWidth & "x" & newHeight & " @ " & newLeft & "," & newTop
  174. End If
  175. End If
  176. End If
  177.  
  178. wnd.ShowState = SHOWSTATE_NORMAL
  179. wnd.Left = newLeft
  180. wnd.Top = newTop
  181. wnd.Width = newWidth
  182. wnd.Height = newHeight
  183. wnd.ApplyChanges 0
  184. End If
  185. End Sub
Add Comment
Please, Sign In to add comment