Guest User

Untitled

a guest
Apr 21st, 2023
102
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.74 KB | None | 0 0
  1.  
  2.  
  3. #include <Array.au3>
  4. #include <Process.au3>
  5.  
  6.  
  7. HotKeySet("{ESC}", "Toggle")
  8.  
  9.  
  10.  
  11. $status = 0
  12.  
  13. While 1
  14. Sleep(10)
  15. WEnd
  16.  
  17.  
  18.  
  19. Func Toggle()
  20.  
  21. if $status = 0 Then
  22.  
  23. ;Get a list of visable windows with titles.
  24. $aWindows = _GetVisibleWindows()
  25. _ArrayDisplay($aWindows)
  26.  
  27.  
  28. ;would be prettier to loop through all windows and
  29. ;minimize them if hwnd does not match
  30. $hHandleOfActiveWindow = WinGetHandle("[ACTIVE]")
  31. WinMinimizeAll()
  32. Sleep(1)
  33. WinActivate( $hHandleOfActiveWindow)
  34. $status = 1
  35. Else
  36.  
  37. $status = 0
  38. EndIf
  39.  
  40.  
  41.  
  42.  
  43. EndFunc ;==>Toggle
  44.  
  45.  
  46.  
  47.  
  48.  
  49.  
  50.  
  51.  
  52. Func _GetVisibleWindows()
  53. ;Retrieve a list of windows.
  54. Local $aWinList = WinList()
  55. If Not IsArray($aWinList) Then Return SetError(0, 0, 0)
  56.  
  57. ;Loop through the array deleting no title or invisable windows.
  58. Local $sDeleteRows = ""
  59. For $i = 1 To $aWinList[0][0]
  60. If $aWinList[$i][0] = "" Or Not BitAND(WinGetState($aWinList[$i][1]), $WIN_STATE_VISIBLE) Then
  61. $sDeleteRows &= $i & ";"
  62. EndIf
  63. Next
  64. $sDeleteRows = StringTrimRight($sDeleteRows, 1) ;Remove last ";".
  65. _ArrayDelete($aWinList, $sDeleteRows)
  66. $aWinList[0][0] = UBound($aWinList) - 1
  67.  
  68. ;Get Window's Processor ID (PID), and add to the array.
  69. _ArrayColInsert($aWinList, UBound($aWinList, 2))
  70. For $i = 1 To $aWinList[0][0]
  71. $aWinList[$i][2] = WinGetProcess($aWinList[$i][1])
  72. Next
  73.  
  74. ;Get Window's Process Name from PID, and add to the array.
  75. _ArrayColInsert($aWinList, UBound($aWinList, 2))
  76. For $i = 1 To $aWinList[0][0]
  77. $aWinList[$i][3] = _ProcessGetName($aWinList[$i][2])
  78. Next
  79.  
  80. ;Get Windows's Position and Size, and add it to the array.
  81. ;For Position, -3200,-3200 is minimized window, -8,-8 is maximized window on 1st display, and
  82. ;x,-8 is maximized windown on the nth display were x is the nth display width plus -8 (W + -8).
  83. _ArrayColInsert($aWinList, UBound($aWinList, 2)) ;Position (X,Y).
  84. _ArrayColInsert($aWinList, UBound($aWinList, 2)) ;Dimension (WxH).
  85. Local $aWinPosSize
  86. For $i = 1 To $aWinList[0][0]
  87. $aWinPosSize = WinGetPos($aWinList[$i][1])
  88. $aWinList[$i][4] = $aWinPosSize[0] & "," & $aWinPosSize[1]
  89. $aWinList[$i][5] = $aWinPosSize[2] & "x" & $aWinPosSize[3]
  90. Next
  91.  
  92. Return $aWinList
  93. EndFunc ;==>_GetVisibleWindows
Add Comment
Please, Sign In to add comment