Jump to content

This site uses cookies. By continuing to browse the site you are agreeing to our use of cookies. Find out more here. X
X


Photo

_ProcessGetWin


  • Please log in to reply
5 replies to this topic

#1 funkey

funkey

    New Dad

  • Active Members
  • PipPipPipPipPipPip
  • 628 posts

Posted 01 June 2010 - 09:48 PM

AutoIt         
#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.

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.








#2 UEZ

UEZ

    Never say never

  • MVPs
  • 4,799 posts

Posted 02 June 2010 - 06:31 PM

Hi funkey,

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

Vista x32

BR,
UEZ

Edited by UEZ, 02 June 2010 - 06:31 PM.

 
The own fart smells best!
Her 'sikim hıyar' diyene bir avuç tuz alıp koşma!
¯\_(ツ)_/¯


#3 Yashied

Yashied

    Happy in Moscow

  • MVPs
  • 2,574 posts

Posted 02 June 2010 - 07:14 PM

Look at _WinAPI_EnumProcessWindows() from WinAPIEx.au3.

:mellow:

#4 funkey

funkey

    New Dad

  • Active Members
  • PipPipPipPipPipPip
  • 628 posts

Posted 02 June 2010 - 10:11 PM

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, 02 June 2010 - 11:18 PM.

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.


#5 TTQ

TTQ

    Seeker

  • New Members
  • 3 posts

Posted 03 June 2010 - 04:30 AM

Thanks funkey, It worked

Edited by TTQ, 03 June 2010 - 04:32 AM.


#6 UEZ

UEZ

    Never say never

  • MVPs
  • 4,799 posts

Posted 03 June 2010 - 12:06 PM

Yep, it is working now!

BR,
UEZ

 
The own fart smells best!
Her 'sikim hıyar' diyene bir avuç tuz alıp koşma!
¯\_(ツ)_/¯





0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users