Guest User

Untitled

a guest
Jul 20th, 2018
92
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.60 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. Option Explicit
  11. Dim MONITORS
  12. MONITORS = Array("0,0,1440,900","1440,-180,2400,1080","2400,-180,3360,1080")
  13.  
  14. If UBound(MONITORS) = -1 Then
  15. 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.",, "VMonMaximizeWnd3"
  16. WScript.Quit
  17. End If
  18.  
  19. Const SHOWSTATE_NORMAL = 2
  20. Const POS_LEFT = 0
  21. Const POS_TOP = 1
  22. Const POS_RIGHT = 2
  23. Const POS_BOTTOM = 3
  24.  
  25. Dim wnd, newLeft, newTop, newWidth, newHeight
  26. Set wnd = CreateObject("UltraMon.Window")
  27. If wnd.GetForegroundWindow() = True Then
  28. Dim wndLeft, wndRight, wndTop, wndBottom, wndWidth, wndHeight
  29. wndLeft = wnd.Left
  30. wndTop = wnd.Top
  31. wndWidth = wnd.Width
  32. wndHeight = wnd.Height
  33. wndRight = wnd.Left + wndWidth
  34. wndBottom = wnd.Top + wndHeight
  35.  
  36. 'msgbox "wnd: " & wndLeft & "," & wndTop & " - " & wndRight & "," & wndBottom
  37.  
  38. Dim i, str, rect, intLeft, intTop, intRight, intBottom, area, maxArea, maxAreaMonIndex
  39. maxAreaMonIndex = -1
  40. For i = 0 To UBound(MONITORS)
  41. str = Split(MONITORS(i), ",")
  42. rect = Array(CLng(str(0)), CLng(str(1)), CLng(str(2)), CLng(str(3)))
  43. If Not (wndRight <= rect(POS_LEFT) Or wndLeft >= rect(POS_RIGHT) Or wndTop >= rect(POS_BOTTOM) Or wndBottom <= rect(POS_TOP)) Then
  44. intLeft = wndLeft
  45. If intLeft < rect(POS_LEFT) Then intLeft = rect(POS_LEFT)
  46. intTop = wndTop
  47. If intTop < rect(POS_TOP) Then intTop = rect(POS_TOP)
  48. intRight = wndRight
  49. If intRight > rect(POS_RIGHT) Then intRight = rect(POS_RIGHT)
  50. intBottom = wndBottom
  51. If intBottom > rect(POS_BOTTOM) Then intBottom = rect(POS_BOTTOM)
  52.  
  53. area = (intRight - intLeft) * (intBottom - intTop)
  54. If area > maxArea Then
  55. maxArea = area
  56. maxAreaMonIndex = i
  57. End If
  58.  
  59. 'msgbox "mon: " & MONITORS(i) & " int: " & intLeft & "," & intTop & " - " & intRight & "," & intBottom & " area: " & area
  60. End If
  61. Next
  62.  
  63. If maxAreaMonIndex <> -1 Then
  64. 'get the maximized position and size for the window
  65. Dim maxLeft, maxTop, maxWidth, maxHeight
  66. str = Split(MONITORS(maxAreaMonIndex), ",")
  67. rect = Array(CLng(str(0)), CLng(str(1)), CLng(str(2)), CLng(str(3)))
  68. maxLeft = rect(POS_LEFT)
  69. maxTop = rect(POS_TOP)
  70. maxWidth = rect(POS_RIGHT) - rect(POS_LEFT)
  71. maxHeight = rect(POS_BOTTOM) - rect(POS_TOP)
  72.  
  73. 'msgbox "max: " & maxLeft & "," & maxTop & " - " & maxLeft + maxWidth & "," & maxTop + maxHeight
  74.  
  75. 'check if window is currently maximized
  76. If wnd.ShowState = SHOWSTATE_NORMAL And wndLeft = maxLeft And wndTop = maxTop And wndWidth = maxWidth And wndHeight = maxHeight Then
  77. 'window is maximized, restore it
  78. newWidth = wndWidth * 0.9
  79. newHeight = wndHeight * 0.9
  80. newLeft = wndLeft + (wndWidth - newWidth) / 2
  81. newTop = wndTop + (wndHeight - newHeight) / 2
  82. Else
  83. 'window isn't maximized, maximize it
  84. newWidth = maxWidth
  85. newHeight = maxHeight
  86. newLeft = maxLeft
  87. newTop = maxTop
  88. End If
  89.  
  90. wnd.ShowState = SHOWSTATE_NORMAL
  91. wnd.Left = newLeft
  92. wnd.Top = newTop
  93. wnd.Width = newWidth
  94. wnd.Height = newHeight
  95. End If
  96.  
  97. wnd.ApplyChanges 0
  98. End If
Add Comment
Please, Sign In to add comment