GetWindowThreadProcessId

  DWORD GetWindowThreadProcessId(hwnd, lpdwProcessId)    
  HWND hwnd;    
  LPDWORD lpdwProcessId;    

This function lets you obtain identifiers for the thread and process that created a window.

Parameters

hwnd

Identifies the window of interest.

lpdwProcessId

Points to a DWORD where the function will store the process id of the process that created the window hwnd.

Return Value

The return value is the thread id of the thread that created the window hwnd. If lpdwProcessId is not NULL, the function puts the process id of the process that created hwnd into the DWORD lpdwProcessId points to.

Comments

Windows 3 used the API function GetWindowTask to obtain an hTask task handle for the task that created a window. New Windows 32 applications should use GetWindowThreadProcessId instead of GetWindowTask.

GetWindowTask is now obsolete. For compatibility, it is macroed on top of GetWindowThreadProcessId as follows:

#define GetWindowTask(hwnd)\

((HANDLE)GetWindowThreadProcessId(hwnd, NULL))

Since GetWindowTask returned a handle in Win3, the macro casts the GetWindowThreadProcessId return value to a HANDLE. This handle is really the thread id of the thread that created hwnd.