Sign in to follow this  
Followers 0
Shocker

Get wrong Handle from PID?

2 posts in this topic

#1 ·  Posted

Hi there...

Need a handle and try to get it from PID. I use  _WinGetByPID but i get a "wrong" handle from this Process (use Window Info to check). If i use it for notepad.exe, calc.exe or mspaint.exe i get the right one. What's going wrong? :blink:

 

MsgBox(0, "", _WinGetByPID("calc.exe", 1))

Func _WinGetByPID($iPID, $iArray = 1) ; 0 Will Return 1 Base Array & 1 Will Return The First Window.
    Local $aError[1] = [0], $aWinList, $sReturn
    If IsString($iPID) Then
        $iPID = ProcessExists($iPID)
    EndIf
    $aWinList = WinList()
    For $A = 1 To $aWinList[0][0]
        If WinGetProcess($aWinList[$A][1]) = $iPID And BitAND(WinGetState($aWinList[$A][1]), 2) Then
            If $iArray Then
                Return $aWinList[$A][1]
            EndIf
            $sReturn &= $aWinList[$A][1] & Chr(1)
        EndIf
    Next
    If $sReturn Then
        Return StringSplit(StringTrimRight($sReturn, 1), Chr(1))
    EndIf
    Return SetError(1, 0, $aError)
EndFunc   ;==>_WinGetByPID

 

Share this post


Link to post
Share on other sites



#2 ·  Posted

Think i found my mistake in Line 10. Have changed WinGetProcess($aWinList[$A][1]) into WinGetProcess($aWinList[$A][0]) and now script return correct handle.

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