Sign in to follow this  
Followers 0
Qvintus

[Need help] Getting hwnd using PID?

7 posts in this topic

Hello I was wondering if it's possible to get the hwnd using PID?

Currently I found:

WinList - Though this requires the window name, wich could be the same for 2 instances in some situations.

ProcessList - Can return PID but not hwnd

WinGetHandle - Requires window name again

Anything I have overlooked for now? Or is ther some sort of bypass somewhere?

Basicly I want to finde the hwnd using a ProcessList where 2 windows

mostly will have the same name, meaning I can't finde it using the window name.

Any ideas?

Share this post


Link to post
Share on other sites



Hello I was wondering if it's possible to get the hwnd using PID?

Currently I found:

WinList - Though this requires the window name, wich could be the same for 2 instances in some situations.

ProcessList - Can return PID but not hwnd

WinGetHandle - Requires window name again

Anything I have overlooked for now? Or is ther some sort of bypass somewhere?

Basicly I want to finde the hwnd using a ProcessList where 2 windows

mostly will have the same name, meaning I can't finde it using the window name.

Any ideas?

WinList()

&

WinGetProcess()


Share this post


Link to post
Share on other sites

I already know how to get PID, I need to use the PID to somehow get the hwnd.

If I can use WinList for that then please explain a little more of what parameter it should be in.

Also if I should use "[PID:" & $pid &"]" or something wiered like that?

Share this post


Link to post
Share on other sites

#4 ·  Posted (edited)

WinGetProcess()

---

To be used on your hwnd's from winlist to see if its the PID your looking for.

But, this can return multiple matches, as a process can have multiple windows. so some additional window title information is probably needed to make sure you get the one your after.

---

See example in next message.

Edited by iEvKI3gv9Wrkd41u

"Straight_and_Crooked_Thinking" : A "classic guide to ferreting out untruths, half-truths, and other distortions of facts in political and social discussions."
"The Secrets of Quantum Physics" : New and excellent 2 part documentary on Quantum Physics by Jim Al-Khalili. (Dec 2014)

"Believing what you know ain't so" ...

Knock Knock ...
 

Share this post


Link to post
Share on other sites

I already know how to get PID, I need to use the PID to somehow get the hwnd.

If I can use WinList for that then please explain a little more of what parameter it should be in.

Also if I should use "[PID:" & $pid &"]" or something wiered like that?

Just an Example:

Global $PID2 = ""
$Amow = 100
$hWnd2 = ""
$aPID = Run("Notepad.exe")
Sleep($Amow)
$theWinlist = Winlist()
    Do
        For $i = 1 To $theWinlist[0][0]
            If $theWinlist[$i][0] <> "" Then
                $iPID2 = WinGetProcess($theWinlist[$i][1])
                If $iPID2 = $aPID Then
                    $hWnd2 = $theWinlist[$i][1]
                    ExitLoop
                EndIf
            EndIf
        Next
    Until $hWnd2 <> 0
    MsgBox(0, "Handle is", $hWnd2)
WinClose($hWnd2)
1 person likes this

Share this post


Link to post
Share on other sites

#6 ·  Posted (edited)

Thx for your replys but I ended out using the WinAPIEx.au3

_WinAPI_EnumProcessWindows(PID)

:)

Post I found it in:

Edited by Qvintus

Share this post


Link to post
Share on other sites

Perfect code, JoHanatCent. As long as there is only one exe with that name, it works on everything I tried :)

Share this post


Link to post
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
Sign in to follow this  
Followers 0