Function: This function returns the ID of the process that creates the specified window thread and the process that creates the window. The last one is optional.
Function prototype; DWORD getwindowthreadprocessld (hwnd, lpdword lpdwprocessld );
Parameters:
Hwnd: Window handle.
Lpdwprocessld: the address that receives the 32-bit value of the Process Identity. If this parameter is not null, getwindwthreadprocessld copies the process identifier to the 32-bit value. Otherwise, the process identifier is not copied.
Return Value: the return value is the thread ID of the window to be created.
Use this function in C # To first import the namespace:
Using system. runtime. interopservices;
Then write the code of the API reference and put it into the class.
[Dllimport ("user32.dll", charset = charset. Auto)]
Public static extern int getwindowthreadprocessid (intptr hwnd, out int ID );
This function has two parameters. The first parameter is the window handle obtained by findwindow, and the second parameter is the variable that stores the process ID. For example:
// Obtain the calculator window handle
Intptr hwnd = findwindow (null, "Calculator ");
If (hwnd! = Intptr. Zero)
{
Int calcid;
// Obtain the process ID
Getwindowthreadprocessid (hwnd, out calcid );
MessageBox. Show (calcid. tostring ());
}
Else
{
MessageBox. Show ("No calculator window found ");
}