Advertisement
Guest User

Untitled

a guest
Mar 24th, 2017
61
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.77 KB | None | 0 0
  1. ; from https://autohotkey.com/board/topic/69464-how-to-determine-a-window-is-in-which-monitor/
  2. ; Tells you which monitor a window is on (given a windowhandle)
  3. GetMonitorIndexFromWindow(windowHandle)
  4. {
  5. ; Starts with 1.
  6. monitorIndex := 1
  7.  
  8. VarSetCapacity(monitorInfo, 40)
  9. NumPut(40, monitorInfo)
  10.  
  11. if (monitorHandle := DllCall("MonitorFromWindow", "uint", windowHandle, "uint", 0x2))
  12. && DllCall("GetMonitorInfo", "uint", monitorHandle, "uint", &monitorInfo)
  13. {
  14. monitorLeft := NumGet(monitorInfo, 4, "Int")
  15. monitorTop := NumGet(monitorInfo, 8, "Int")
  16. monitorRight := NumGet(monitorInfo, 12, "Int")
  17. monitorBottom := NumGet(monitorInfo, 16, "Int")
  18. workLeft := NumGet(monitorInfo, 20, "Int")
  19. workTop := NumGet(monitorInfo, 24, "Int")
  20. workRight := NumGet(monitorInfo, 28, "Int")
  21. workBottom := NumGet(monitorInfo, 32, "Int")
  22. isPrimary := NumGet(monitorInfo, 36, "Int") & 1
  23.  
  24. SysGet, monitorCount, MonitorCount
  25.  
  26. Loop, %monitorCount%
  27. {
  28. SysGet, tempMon, Monitor, %A_Index%
  29.  
  30. ; Compare location to determine the monitor index.
  31. if ((monitorLeft = tempMonLeft) and (monitorTop = tempMonTop)
  32. and (monitorRight = tempMonRight) and (monitorBottom = tempMonBottom))
  33. {
  34. monitorIndex := A_Index
  35. break
  36. }
  37. }
  38. }
  39.  
  40. return monitorIndex
  41. }
  42.  
  43. ; Windows monitors are numbered from 1 up.
  44. ; Find the windowhandle for the 'active' window
  45. ; (might be none!)
  46. GetMonitorIndexForActiveWindow()
  47. {
  48. winHand := WinExist("A")
  49. if !winHand
  50. return 0
  51.  
  52. return GetMonitorIndexFromWindow(winHand)
  53. }
  54.  
  55.  
  56.  
  57. ; Maximize current window
  58. #PgUp::
  59. WinMaximize, A
  60. return
  61.  
  62. ; Minimize current window
  63. #PgDn::
  64. WinMinimize, A
  65. return
  66.  
  67. ; Make active window take up top half of active monitor
  68. #Up::
  69. ;Get the index of the monitor the active window is on (1, 2, etc. 0 if no active wind)
  70. monIdx := GetMonitorIndexForActiveWindow()
  71. if (monIdx)
  72. {
  73. ; Get bounding box of that monitor
  74. SysGet, MonBnd, Monitor, %monIdx%
  75. ; monitor height
  76. monHi := (MonBndBottom-MonBndTop)
  77. ; monitor width
  78. monWid := (MonBndRight - MonBndLeft)
  79. ; half height
  80. newHi := monHi/2
  81. WinMove, A, , %MonBndLeft%, %MonBndTop%, %monWid%, %newHi%
  82. }
  83. return
  84.  
  85. #Down::
  86. ;Get the index of the monitor the active window is on (1, 2, etc. 0 if no active wind)
  87. monIdx := GetMonitorIndexForActiveWindow()
  88. if (monIdx)
  89. {
  90. ; Get bounding box of that monitor
  91. SysGet, MonBnd, Monitor, %monIdx%
  92. monHi := (MonBndBottom-MonBndTop)
  93. ; monitor width
  94. monWid := (MonBndRight - MonBndLeft)
  95. newTop := MonBndTop + (monHi/2)
  96. newHi := monHi/2
  97. WinMove, A, , %MonBndLeft%, %newTop%, %monWid%, %newHi%
  98. }
  99. return
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement