#Include <Array.au3> Global $array $array = _ProcessGetWin("explorer.exe") _ArrayDisplay($array, '_ProcessGetWin - All') $array = _ProcessGetWin("explorer.exe", 0) _ArrayDisplay($array, '_ProcessGetWin - Titles') $array = _ProcessGetWin("explorer.exe", 1) _ArrayDisplay($array, '_ProcessGetWin - Handles') $array = _ProcessGetWin("explorer.exe", 2) _ArrayDisplay($array, '_ProcessGetWin - Classes') ; #FUNCTION# ==================================================================================================================== ; Name...........: _ProcessGetWin ; Description ...: Returns a list of ALL window titles and/or window handles belonging to the given Process ID. ; Syntax.........: _ProcessGetWin($iPID [, $iOption = -1]) ; Parameters ....: $iPID - Numeric Process ID. Default (0) is the current process. ; $iOption - Return window titles AND / OR window handles ; 0 - window titles are returned (1D-array) ; 1 - window handles are returned (1D-array) ; 2 - window classes are returned (1D-array) ; other (Default) - window titles, handles AND classes are returned (2D-array) ; Return values .: Success - Returns an array with all window titles, handles and classes belonging to the given PID (depending on $iOption) ; Failure - Returns @error = 1 if process does not exist ; Author ........: funkey <funkey80 at hotmail dot com> ; Remarks .......: $aHWnd[0] / $aHWnd[0][0] contains the number of windows found ; Related .......: ; Link ..........: ; Example .......: _ProcessGetWin("explorer.exe") ; =============================================================================================================================== Func _ProcessGetWin($iPID = 0, $iOption = -1) Local $aList = WinList(), $aTemp If Not $iPID Then $iPID = @AutoItPID $iPID = ProcessExists($iPID) If $iPID = 0 Then Return SetError(1) Switch $iOption Case 0, 1 Local $aHWnd[1] = [0] For $i = 1 To $aList[0][0] If $iPID = WinGetProcess($aList[$i][1]) Then ReDim $aHWnd[$aHWnd[0] + 2] $aHWnd[0] += 1 $aHWnd[$aHWnd[0]] = $aList[$i][$iOption] EndIf Next Case 2 Local $aHWnd[1] = [0] For $i = 1 To $aList[0][0] If $iPID = WinGetProcess($aList[$i][1]) Then ReDim $aHWnd[$aHWnd[0] + 2] $aHWnd[0] += 1 $aTemp = DllCall("user32.dll", "int", "GetClassNameW", "hwnd", $aList[$i][1], "wstr", "", "int", 4096) $aHWnd[$aHWnd[0]] = $aTemp[2] EndIf Next Case Else Local $aHWnd[1][3] = [[0]] For $i = 1 To $aList[0][0] If $iPID = WinGetProcess($aList[$i][1]) Then ReDim $aHWnd[$aHWnd[0][0] + 2][3] $aHWnd[0][0] += 1 $aHWnd[$aHWnd[0][0]][0] = $aList[$i][0] $aHWnd[$aHWnd[0][0]][1] = $aList[$i][1] $aTemp = DllCall("user32.dll", "int", "GetClassNameW", "hwnd", $aList[$i][1], "wstr", "", "int", 4096) $aHWnd[$aHWnd[0][0]][2] = $aTemp[2] EndIf Next EndSwitch Return $aHWnd EndFunc ;==>_ProcessGetWin
Edit: Fixed a little bug.
Edited by funkey, 03 June 2010 - 11:02 AM.






