Advertisement
User57

GetWinInfo

Aug 26th, 2024
80
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
AutoIt 8.61 KB | Help | 0 0
  1. #Region ;**** Directives created by AutoIt3Wrapper_GUI ****
  2. #AutoIt3Wrapper_Icon=Info (gray).ICO
  3. #AutoIt3Wrapper_Change2CUI=y
  4. #EndRegion ;**** Directives created by AutoIt3Wrapper_GUI ****
  5.  
  6. #include <Array.au3>
  7. #include <WinAPISysWin.au3>
  8.  
  9. ;~ chcp 65001
  10.  
  11. Global $P1_hWnd = "TOP"
  12.  
  13. If $CmdLine[0] > 0 Then $P1_hWnd = $CmdLine[1]
  14. If $CmdLine[0] > 1 Then Exit ConsoleWrite("!! Wrong Number of parameters" & @CRLF)
  15.  
  16. If $P1_hWnd = "/?" Or $P1_hWnd = "/help" Then
  17.  
  18.     Local $sTxt = ""
  19.     $sTxt &= "" & @CRLF
  20.     $sTxt &= "************************************************************************************************************************" & @CRLF
  21.     $sTxt &= " Name:" & @CRLF
  22.     $sTxt &= "     GetWinInfo " & @CRLF
  23.     $sTxt &= "" & @CRLF
  24.     $sTxt &= " Description: " & @CRLF
  25.     $sTxt &= "     Returns information about runing windows." & @CRLF
  26.     $sTxt &= "" & @CRLF
  27.     $sTxt &= " Syntax: " & @CRLF
  28.     $sTxt &= "     GetWinInfo [$hWnd]" & @CRLF
  29.     $sTxt &= "" & @CRLF
  30.     $sTxt &= " Parameters: $hWnd" & @CRLF
  31.     $sTxt &= "     ""TOP""    - Enumerates all top level windows. (Default)" & @CRLF
  32.     $sTxt &= "     ""ALL""    - Enumerates all windows." & @CRLF
  33.     $sTxt &= "     ""handle"" - specify a specific window by passing a handle as a string." & @CRLF
  34.     $sTxt &= "" & @CRLF
  35.     $sTxt &= " Return values: " & @CRLF
  36.     $sTxt &= "     The function returns an array with the following structure:" & @CRLF
  37.     $sTxt &= "" & @CRLF
  38.     $sTxt &= "     Handle: ; PID: ; Class: ; Title:" & @CRLF
  39.     $sTxt &= "          Styles:" & @CRLF
  40.     $sTxt &= "          ExStyles:" & @CRLF
  41.     $sTxt &= "" & @CRLF
  42.     $sTxt &= " Notes: " & @CRLF
  43.     $sTxt &= "     his function uses the _WinAPI_EnumWindows() and _WinAPI_GetWindowText() functions to retrieve information about windows." & @CRLF
  44.     $sTxt &= "" & @CRLF
  45.     $sTxt &= "************************************************************************************************************************" & @CRLF
  46.  
  47.     ConsoleWrite($sTxt & @CRLF)
  48.     Exit
  49. EndIf
  50.  
  51. GetWinInfo($P1_hWnd)
  52.  
  53. Exit
  54.  
  55.  
  56. ; #FUNCTION# --------------------------------------------------------------------------------------------------------------------
  57. ; Name...........: GetWinInfo($hWnd = "TOP")
  58. ; Description....: Returns information about runing windows.
  59. ; Syntax.........: GetWinInfo($hWnd = "TOP")
  60. ; Parameters.....: $hWnd - Handle of the window to get information for. (Default is "TOP")
  61. ;                  With "TOP" Enumerates all top level windows
  62. ;                  With "ALL" Enumerates all windows
  63. ;                  You can also specify a specific window handle by passing it as a string.
  64. ; Return values..: Handle: ; PID: ; Class: ; Title:
  65. ;                       Styles:
  66. ;                       ExStyles:
  67. ; Author ........:
  68. ; Notes .........: This function uses the _WinAPI_EnumWindows() and _WinAPI_GetWindowText() functions to retrieve information about windows.
  69. ; Link ..........: https://www.autoitscript.com/
  70. ; Dependencies...: #include <Array.au3>, #include <WinAPISysWin.au3>
  71. ;--------------------------------------------------------------------------------------------------------------------------------
  72. Func GetWinInfo($hWnd = "TOP")
  73.     ;0=Handle; 1=Class; 2=Title; 3=PID; 4=Styles ;5=ExStyles
  74.  
  75.     Local $aWindows
  76.     If $hWnd = "TOP" Then
  77.         $aWindows = _WinAPI_EnumWindowsTop()
  78.     Else
  79.         $aWindows = _WinAPI_EnumWindows()
  80.     EndIf
  81.  
  82.     Local $aResult[$aWindows[0][0]][6]
  83.     For $i = 1 To $aWindows[0][0]
  84.         $aResult[$i - 1][0] = $aWindows[$i][0]
  85.         $aResult[$i - 1][1] = $aWindows[$i][1]
  86.         Local $aTtl = StringSplit(WinGetTitle($aWindows[$i][0]), @CRLF)
  87.         $aResult[$i - 1][2] = "'" & ($aTtl[0] = 1 ? $aTtl[1] : StringStripCR($aTtl[1]) & " ...") & "'"
  88.         $aResult[$i - 1][3] = WinGetProcess($aWindows[$i][0])
  89.         Local $aStyle = GetWindowStyleAndExStyle($aWindows[$i][0])
  90.         $aResult[$i - 1][4] = $aStyle[1]
  91.         $aResult[$i - 1][5] = $aStyle[2]
  92.     Next
  93.     ;_ArrayDisplay($aResult, "_WinAPI_EnumWindows", Default, Default, Default, "Handle|Class|Title|PID|Styles|ExStyles")
  94.  
  95.     Local $sOut = ""
  96.  
  97.     For $i = 0 To UBound($aResult) - 1
  98.  
  99.         If $hWnd = "TOP" Or $hWnd = "ALL" Then
  100.             $sOut &= "Handle:" & $aResult[$i][0] & " ; "
  101.             $sOut &= "PID:" & $aResult[$i][3] & " ; "
  102.             $sOut &= "Class:" & $aResult[$i][1] & " ; "
  103.             $sOut &= "Title:" & $aResult[$i][2] & @CRLF
  104.             $sOut &= @TAB & "Styles:" & @CRLF
  105.             $sOut &= $aResult[$i][4] & @CRLF
  106.             $sOut &= @CRLF
  107.             $sOut &= @TAB & "ExStyles:" & @CRLF
  108.             $sOut &= $aResult[$i][5] & @CRLF
  109.             $sOut &= @CRLF
  110.         Else
  111.             If $hWnd = $aResult[$i][0] Then
  112.                 $sOut &= "Handle:" & $aResult[$i][0] & " ; "
  113.                 $sOut &= "PID:" & $aResult[$i][3] & " ; "
  114.                 $sOut &= "Class:" & $aResult[$i][1] & " ; "
  115.                 $sOut &= "Title:" & $aResult[$i][2] & @CRLF
  116.                 $sOut &= @TAB & "Styles:" & @CRLF
  117.                 $sOut &= $aResult[$i][4] & @CRLF
  118.                 $sOut &= @CRLF
  119.                 $sOut &= @TAB & "ExStyles:" & @CRLF
  120.                 $sOut &= $aResult[$i][5] & @CRLF
  121.                 $sOut &= @CRLF
  122.             EndIf
  123.         EndIf
  124.  
  125.     Next
  126.  
  127. ;~  ConsoleWrite($sOut)
  128.  
  129.     ConsoleWrite(BinaryToString(StringToBinary($sOut, 4), 1))
  130.  
  131. EndFunc   ;==>GetWinInfo
  132. ;--------------------------------------------------------------------------------------------------------------------------------
  133. ; Get the handle of the active window
  134. Func GetWindowStyleAndExStyle($hWnd)
  135.  
  136.     ; Get the window styles and extended styles using GetWindowLong
  137.     Local $style = _WinAPI_GetWindowLong($hWnd, $GWL_STYLE)
  138.     Local $exStyle = _WinAPI_GetWindowLong($hWnd, $GWL_EXSTYLE)
  139.  
  140.     ; Array of window styles
  141.     Local $aStyles[24][2] = [["WS_BORDER", 0x00800000], _
  142.             ["WS_CAPTION", 0x00C00000], _
  143.             ["WS_CHILD", 0x40000000], _
  144.             ["WS_CHILDWINDOW", 0x40000000], _
  145.             ["WS_CLIPCHILDREN", 0x02000000], _
  146.             ["WS_CLIPSIBLINGS", 0x04000000], _
  147.             ["WS_DISABLED", 0x08000000], _
  148.             ["WS_DLGFRAME", 0x00400000], _
  149.             ["WS_GROUP", 0x00020000], _
  150.             ["WS_HSCROLL", 0x00100000], _
  151.             ["WS_ICONIC", 0x20000000], _
  152.             ["WS_MAXIMIZE", 0x01000000], _
  153.             ["WS_MAXIMIZEBOX", 0x00010000], _
  154.             ["WS_MINIMIZE", 0x20000000], _
  155.             ["WS_MINIMIZEBOX", 0x00020000], _
  156.             ["WS_OVERLAPPED", 0x00000000], _
  157.             ["WS_POPUP", 0x80000000], _
  158.             ["WS_SIZEBOX", 0x00040000], _
  159.             ["WS_SYSMENU", 0x00080000], _
  160.             ["WS_TABSTOP", 0x00010000], _
  161.             ["WS_THICKFRAME", 0x00040000], _
  162.             ["WS_TILED", 0x00000000], _
  163.             ["WS_VISIBLE", 0x10000000], _
  164.             ["WS_VSCROLL", 0x00200000]]
  165.  
  166.     ; Array of extended window styles
  167.     Local $aExStyles[25][2] = [["WS_EX_ACCEPTFILES", 0x00000010], _
  168.             ["WS_EX_APPWINDOW", 0x00040000], _
  169.             ["WS_EX_CLIENTEDGE", 0x00000200], _
  170.             ["WS_EX_COMPOSITED", 0x02000000], _
  171.             ["WS_EX_CONTEXTHELP", 0x00000400], _
  172.             ["WS_EX_CONTROLPARENT", 0x00010000], _
  173.             ["WS_EX_DLGMODALFRAME", 0x00000001], _
  174.             ["WS_EX_LAYERED", 0x00080000], _
  175.             ["WS_EX_LAYOUTRTL", 0x00400000], _
  176.             ["WS_EX_LEFT", 0x00000000], _
  177.             ["WS_EX_LEFTSCROLLBAR", 0x00004000], _
  178.             ["WS_EX_LTRREADING", 0x00000000], _
  179.             ["WS_EX_MDICHILD", 0x00000040], _
  180.             ["WS_EX_NOACTIVATE", 0x08000000], _
  181.             ["WS_EX_NOINHERITLAYOUT", 0x00100000], _
  182.             ["WS_EX_NOPARENTNOTIFY", 0x00000004], _
  183.             ["WS_EX_NOREDIRECTIONBITMAP", 0x00200000], _
  184.             ["WS_EX_RIGHT", 0x00001000], _
  185.             ["WS_EX_RIGHTSCROLLBAR", 0x00000000], _
  186.             ["WS_EX_RTLREADING", 0x00002000], _
  187.             ["WS_EX_STATICEDGE", 0x00020000], _
  188.             ["WS_EX_TOOLWINDOW", 0x00000080], _
  189.             ["WS_EX_TOPMOST", 0x00000008], _
  190.             ["WS_EX_TRANSPARENT", 0x00000020], _
  191.             ["WS_EX_WINDOWEDGE", 0x00000100]]
  192.  
  193.     ; Get detailed styles and extended styles
  194.     Local $styleDetails = GetStyleDetails($style, $aStyles)
  195.     Local $exStyleDetails = GetStyleDetails($exStyle, $aExStyles)
  196.  
  197.     ; Return the results
  198.     Local $result[3]
  199.     $result[0] = $hWnd
  200.     $result[1] = $styleDetails
  201.     $result[2] = $exStyleDetails
  202.     Return $result
  203.  
  204. EndFunc   ;==>GetWindowStyleAndExStyle
  205. ;--------------------------------------------------------------------------------------------------------------------------------
  206. ; Function to check if a specific style is present
  207. Func CheckStyle($styleValue, $constant, $constantName)
  208.     If BitAND($styleValue, $constant) Then
  209.         Return $constantName & " (0x" & Hex($constant, 8) & ")"
  210.     EndIf
  211.     Return ""
  212. EndFunc   ;==>CheckStyle
  213. ;--------------------------------------------------------------------------------------------------------------------------------
  214. ; Function to get style details
  215. Func GetStyleDetails($styleValue, $aStyleArray)
  216.     Local $result = ""
  217.     For $i = 0 To UBound($aStyleArray) - 1
  218.         Local $styleDetail = CheckStyle($styleValue, $aStyleArray[$i][1], $aStyleArray[$i][0])
  219.         If $styleDetail <> "" Then
  220.             $result &= @TAB & $styleDetail & @CRLF
  221.         EndIf
  222.     Next
  223.     $result = StringTrimRight($result, 2)
  224.     Return $result
  225. EndFunc   ;==>GetStyleDetails
  226. ;--------------------------------------------------------------------------------------------------------------------------------
  227.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement