Jump to content
Sign in to follow this  
0000

PID and Window Name

Recommended Posts

Hehe...

I need smthing like that

$pid=1111

$name = ""

[some Function] = $pid

MsgBox(0,$pid,"Window Name: "&$name)

Some Functions will find from the PID window name :)?

So how about that?

Share this post


Link to post
Share on other sites

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

Share this post


Link to post
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

Share this post


Link to post
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
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.

Share this post


Link to post
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 :)

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  

×
×
  • Create New...