Jump to content

PID and Window Name


0000
 Share

Recommended Posts

See how it was done in this function:

Func _SetParentWindowPID($PID, $hGUI)
    $hWnd = 0
    $stPID = DllStructCreate("int")
    Do
        $winlist2 = WinList()
        For $i = 1 To $winlist2[0][0]
            If $winlist2[$i][0] <> "" Then
                DllCall("user32.dll", "int", "GetWindowThreadProcessId", "hwnd", $winlist2[$i][1], "ptr", DllStructGetPtr($stPID))
                If DllStructGetData($stPID, 1) = $PID Then
                    $hWnd = $winlist2[$i][1]
                    ExitLoop
                EndIf
            EndIf
        Next
        Sleep(100)
    Until $hWnd <> 0
    $stPID = 0

    If $hWnd <> 0 Then
        $nExStyle = DllCall("user32.dll", "int", "GetWindowLong", "hwnd", $hWnd, "int", -20)
        $nExStyle = $nExStyle[0]
        DllCall("user32.dll", "int", "SetWindowLong", "hwnd", $hWnd, "int", -20, "int", BitOR($nExStyle, $WS_EX_MDICHILD))
        DllCall("user32.dll", "int", "SetParent", "hwnd", $hWnd, "hwnd", $hGUI)
        WinSetState($hWnd, "", @SW_SHOW)
        _WinAPI_RedrawWindow ($hWnd)
    EndIf
    GUISetState()
EndFunc  ;==>_SetParentWindowPID
Link to comment
Share on other sites

Wow... It was like what I said was forgottern. Which also indicated the the OP wanted it handed to them on a shiny silver plate...

$PID = Run ("Notepad.exe")
Sleep (250)
$HWND = _GETHwndFromPID ($PID)
WinWaitActive ($HWND)
WinKill($HWND)
MsgBox (0, "", "Window was killed")

Func _GetHwndFromPID ($PID)
    $hWnd = 0
    $stPID = DllStructCreate("int")
    Do
        $winlist2 = WinList()
        For $i = 1 To $winlist2[0][0]
            If $winlist2[$i][0] <> "" Then
                DllCall("user32.dll", "int", "GetWindowThreadProcessId", "hwnd", $winlist2[$i][1], "ptr", DllStructGetPtr($stPID))
                If DllStructGetData($stPID, 1) = $PID Then
                    $hWnd = $winlist2[$i][1]
                    ExitLoop
                EndIf
            EndIf
        Next
        Sleep(100)
    Until $hWnd <> 0
    Return $hWnd
EndFunc
Link to comment
Share on other sites

  • Moderators

Wow... It was like what I said was forgottern. Which also indicated the the OP wanted it handed to them on a shiny silver plate...

$PID = Run ("Notepad.exe")
Sleep (250)
$HWND = _GETHwndFromPID ($PID)
WinWaitActive ($HWND)
WinKill($HWND)
MsgBox (0, "", "Window was killed")

Func _GetHwndFromPID ($PID)
    $hWnd = 0
    $stPID = DllStructCreate("int")
    Do
        $winlist2 = WinList()
        For $i = 1 To $winlist2[0][0]
            If $winlist2[$i][0] <> "" Then
                DllCall("user32.dll", "int", "GetWindowThreadProcessId", "hwnd", $winlist2[$i][1], "ptr", DllStructGetPtr($stPID))
                If DllStructGetData($stPID, 1) = $PID Then
                    $hWnd = $winlist2[$i][1]
                    ExitLoop
                EndIf
            EndIf
        Next
        Sleep(100)
    Until $hWnd <> 0
    Return $hWnd
EndFunc
What's the point of
DllCall("user32.dll", "int", "GetWindowThreadProcessId", "hwnd", $winlist2[$i][1], "ptr", DllStructGetPtr($stPID))
                If DllStructGetData($stPID, 1) = $PID Then
                    $hWnd = $winlist2[$i][1]
??

WinGetProcess() not good enough?

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.

Link to comment
Share on other sites

What's the point of

DllCall("user32.dll", "int", "GetWindowThreadProcessId", "hwnd", $winlist2[$i][1], "ptr", DllStructGetPtr($stPID))
                If DllStructGetData($stPID, 1) = $PID Then
                    $hWnd = $winlist2[$i][1]
??

WinGetProcess() not good enough?

Nope :)
Link to comment
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
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...