fastnick1oo 0 Posted October 13, 2007 (edited) Func _WinGetHandleByPID($iPID) If Not IsNumber($iPID) Then SetError(1) Return 0 EndIf If $iPID < 0 Then SetError(2) Return 0 EndIf Local $wList = WinList() Local $hWnd[1][2] = [[0], [0]] For $i = 1 To $wList[0][0] If WinGetProcess($wList[$i][1]) = $iPID Then $hWnd[0][0] = UBound($hWnd, 1) ReDim $hWnd[UBound($hWnd, 1)+1][2] $hWnd[UBound($hWnd, 1)-1][0] = $wList[$i][0] $hWnd[UBound($hWnd, 1)-1][1] = $wList[$i][1] EndIf Next Return $hWnd EndFunc Is it best way to obtain window(s) handle if you just have PID? I usually use Run() and then want to ControlSend() it, so I use my function. Any other ideas? Edited October 13, 2007 by fastnick1oo SciTE - much better than notepad. ; ] Share this post Link to post Share on other sites
random667 0 Posted October 13, 2007 (edited) This script will popup a msgbox with the Handle of the current active window. While 1 $handle = WinGetHandle ( WinGetTitle ( "" ) ) MsgBox (4096, "handle is", $handle , 1 ) WEnd Edited October 13, 2007 by random667 It is really sad to see a family torn apart by something as simple as a pack of wolves. Share this post Link to post Share on other sites
fastnick1oo 0 Posted October 13, 2007 This script will popup a msgbox with the Handle of the current active window....and if I want to do it the right way: by PID? SciTE - much better than notepad. ; ] Share this post Link to post Share on other sites
random667 0 Posted October 13, 2007 ...and if I want to do it the right way: by PID? maybe something like this? $handle = WinGetHandle ( WinGetTitle ( $iPID ) ) It is really sad to see a family torn apart by something as simple as a pack of wolves. Share this post Link to post Share on other sites
LarryDalooza 42 Posted October 13, 2007 Func _WinGetHandleByPID($iPID) If Not IsNumber($iPID) Then SetError(1) Return 0 EndIf If $iPID < 0 Then SetError(2) Return 0 EndIf Local $wList = WinList() Local $hWnd[1][2] = [[0], [0]] For $i = 1 To $wList[0][0] If WinGetProcess($wList[$i][1]) = $iPID Then $hWnd[0][0] = UBound($hWnd, 1) ReDim $hWnd[UBound($hWnd, 1)+1][2] $hWnd[UBound($hWnd, 1)-1][0] = $wList[$i][0] $hWnd[UBound($hWnd, 1)-1][1] = $wList[$i][1] EndIf Next Return $hWnd EndFunc Is it best way to obtain window(s) handle if you just have PID? I usually use Run() and then want to ControlSend() it, so I use my function. Any other ideas?This is best. No more ideas needed. Lar. AutoIt has helped make me wealthy Share this post Link to post Share on other sites
SmOke_N 211 Posted October 13, 2007 There is an error here: Local $hWnd[1][2] = [[0], [0]] This is nice if you know the PID... a couple of things. Redimming constantly if there are a large amount of windows for that PID open, can be a bit slow. If you take a look at this way (a bit longer), but you can throw in the name of the executable (mind you, this one will get z order, I usually use ProcessList and go through 2 loops (1 for the win's and 1 for the processes)), or the PID. You have a few options as well, if want all windows visible or not... -1 if you want just non visible ones 0, or if you want only visible ones (default) 1. expandcollapse popup#include <array.au3> $a1 = _WinGetHandleByPID(232) $a2 = _WinGetHandleByPID("notepad.exe", -1) $a3 = _WinGetHandleByPID("notepad.exe", 0) $a4 = _WinGetHandleByPID("notepad.exe", 1) _ArrayDisplay($a1, "1") _ArrayDisplay($a2, "2") _ArrayDisplay($a3, "3") _ArrayDisplay($a4, "4") ;$nVisible = -1 "All (Visble or not)", $nVisible = 0 "Not Visible Only", $nVisible = 1 "Visible Only" Func _WinGetHandleByPID($vProc, $nVisible = 1) $vProc = ProcessExists($vProc); If Not $vProc Then Return SetError(1, 0, 0) Local $aWL = WinList() Local $aTemp[UBound($aWL)][2], $nAdd = 0 For $iCC = 1 To $aWL[0][0] If $nVisible = -1 And WinGetProcess($aWL[$iCC][1]) = $vProc Then $nAdd += 1 $aTemp[$nAdd][0] = $aWL[$iCC][0] $aTemp[$nAdd][1] = $aWL[$iCC][1] ElseIf $nVisible = 0 And WinGetProcess($aWL[$iCC][1]) = $vProc And _ BitAND(WinGetState($aWL[$iCC][1]), 2) = 0 Then $nAdd += 1 $aTemp[$nAdd][0] = $aWL[$iCC][0] $aTemp[$nAdd][1] = $aWL[$iCC][1] ElseIf $nVisible > 0 And WinGetProcess($aWL[$iCC][1]) = $vProc And _ BitAND(WinGetState($aWL[$iCC][1]), 2) Then $nAdd += 1 $aTemp[$nAdd][0] = $aWL[$iCC][0] $aTemp[$nAdd][1] = $aWL[$iCC][1] EndIf Next If $nAdd = 0 Then Return SetError(2, 0, 0);No windows found ReDim $aTemp[$nAdd + 1][2] $aTemp[0][0] = $nAdd Return $aTemp EndFuncA bit longer, but more options, and possibly faster if there are a lot of windows open for that PID Common sense plays a role in the basics of understanding AutoIt... If you're lacking in that, do us all a favor, and step away from the computer. Share this post Link to post Share on other sites
fastnick1oo 0 Posted October 13, 2007 SmOke_N nice example, thats what I wanted to see. Really nice.(i saw few mistakes in my code :"> ) SciTE - much better than notepad. ; ] Share this post Link to post Share on other sites