Retrieves the identifier of the thread that created the specified window
#include <WinAPISysWin.au3>
_WinAPI_GetWindowThreadProcessId ( $hWnd, ByRef $iPID )
| $hWnd | Window handle |
| $iPID | Variable to hold the return the process ID (PID) of the thread. |
Search GetWindowThreadProcessId in MSDN Library.
#include <MsgBoxConstants.au3>
#include <WinAPISysWin.au3>
Example()
Func Example()
; Run Notepad
Run("notepad.exe")
; Retrieve the handle of the Notepad window using the classname of Notepad.
Local $hWnd = WinWaitActive("[CLASS:Notepad]", "")
; Retrieve the identifier of the thread and pass a variable to the $iPID parameter to store the PID.
Local $iPID = 0
Local $iThread = _WinAPI_GetWindowThreadProcessId($hWnd, $iPID)
; Display the process thread and PID of the Notepad window.
MsgBox($MB_SYSTEMMODAL, '', "Process thread: " & $iThread & @CRLF & _
"Process ID (PID): " & $iPID)
; Close the Notepad window using the handle returned by WinGetHandle.
WinClose($hWnd)
EndFunc ;==>Example