Jump to content

_ProcessGetWin


funkey
 Share

Recommended Posts

#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

Programming today is a race between software engineers striving to
build bigger and better idiot-proof programs, and the Universe
trying to produce bigger and better idiots.
So far, the Universe is winning.

Link to comment
Share on other sites

Hi funkey,

I'm getting 3 times [0] 0 back! :mellow:

Vista x32

BR,

UEZ

Edited by UEZ

Please don't send me any personal message and ask for support! I will not reply!

Selection of finest graphical examples at Codepen.io

The own fart smells best!
Her 'sikim hıyar' diyene bir avuç tuz alıp koşma!
¯\_(ツ)_/¯  ٩(●̮̮̃•̃)۶ ٩(-̮̮̃-̃)۶ૐ

Link to comment
Share on other sites

Thanks Yashied for showing me _WinAPI_EnumProcessWindows(). So it was easier to find the bug I had. I improved my function to show the window classes too.

UEZ, can you please test the new version in post #1.

Edited by funkey

Programming today is a race between software engineers striving to
build bigger and better idiot-proof programs, and the Universe
trying to produce bigger and better idiots.
So far, the Universe is winning.

Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...