SublimePorte Posted July 5, 2010 Share Posted July 5, 2010 I have a program which could have several instances open, all of which would appear the same through winmatch of titles/classes etc. Is there a away to get a handle for the window when launching it via it's PID? Link to comment Share on other sites More sharing options...
Yoriz Posted July 5, 2010 Share Posted July 5, 2010 Yes FAQ # 24 How can I get a window handle when all I have is a PID? GDIPlusDispose - A modified version of GDIPlus that auto disposes of its own objects before shutdown of the Dll using the same function Syntax as the original.EzMySql UDF - Use MySql Databases with autoit with syntax similar to SQLite UDF. Link to comment Share on other sites More sharing options...
SublimePorte Posted July 5, 2010 Author Share Posted July 5, 2010 I ended up writing my own function and luckily I did... That function in the FAQ doesn't seem to have a timeout, which could result in endless loops. Also some processes seem to be attached to more than one window. Try running that function with notepad for instance, just hangs for me. Here's what I came up with: Func WinHandFromPID($pid, $winTitle="", $timeout=8) Local $secs = 0 Do $wins = WinList($winTitle) For $i = 1 To UBound($wins)-1 If (WinGetProcess($wins[$i][1]) == $pid) And (BitAND(WinGetState($wins[$i][1]), 2)) Then Return $wins[$i][1] Next Sleep(1000) $secs += 1 Until $secs == $timeout EndFunc Only get's the handle for visible windows. Link to comment Share on other sites More sharing options...
PsaltyDS Posted July 6, 2010 Share Posted July 6, 2010 (edited) Only get's the handle for visible windows. Only gets the handle for the FIRST visible window. As was pointed out earlier, a process can and often does have multiple windows. Try it this way: #include <Array.au3> ; ... ; Returns an array of all Windows associated with a given process Func WinHandFromPID($pid, $winTitle = "", $timeout = 8) Local $secs = TimerInit() Do $wins = WinList($winTitle) For $i = UBound($wins) - 1 To 1 Step -1 If (WinGetProcess($wins[$i][1]) <> $pid) Or (BitAND(WinGetState($wins[$i][1]), 2) = 0) Then _ArrayDelete($wins, $i) Next $wins[0][0] = UBound($wins) - 1 If $wins[0][0] Then Return SetError(0, 0, $wins) Sleep(1000) Until TimerDiff($secs) >= $timeout * 1000 Return SetError(1, 0, $wins) EndFunc ;==>WinHandFromPID Edited July 6, 2010 by PsaltyDS Valuater's AutoIt 1-2-3, Class... Is now in Session!For those who want somebody to write the script for them: RentACoder"Any technology distinguishable from magic is insufficiently advanced." -- Geek's corollary to Clarke's law Link to comment Share on other sites More sharing options...
Earthshine Posted December 19, 2017 Share Posted December 19, 2017 (edited) oops, i was using this thread for another questions. sorry mods! Edited December 19, 2017 by Earthshine My resources are limited. You must ask the right questions Link to comment Share on other sites More sharing options...
jaja714 Posted July 9, 2020 Share Posted July 9, 2020 On 7/5/2010 at 1:35 AM, Yoriz said: Yes FAQ # 24 How can I get a window handle when all I have is a PID? The winlist needs to be inside the do. Then, you can get rid of the first sleep. Link to comment Share on other sites More sharing options...
Recommended Posts
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 accountSign in
Already have an account? Sign in here.
Sign In Now