This answer is very easy – just use GetWindowThreadProcessId

JWA declares it as followed:

function GetWindowThreadProcessId(hWnd: HWND; lpdwProcessId: LPDWORD): DWORD; stdcall;

The function returns an identifier (not a handle) and also may set lpdwProcessId to the identifier (again not a handle!) if it is not nil. Be aware that identifiers aren’t handles, so you must not close them by using CloseHandle. Identifiers are only numbers that makes an object distinguishable from other objects of the same type.

uses JwaWindows;

var ProcessID,
 ThreadID  : DWORD;
 WndHandle : HWND;

  WndHandle := FindWindow();
  ThreadID := GetWindowThreadProcessId(WndHandle, @ProcessID);

Tell me how you liked this blog entry by adding a comment.