5 out of 22 rated this helpful - Rate this topic

GetWindowThreadProcessId function

Applies to: desktop apps only

Retrieves the identifier of the thread that created the specified window and, optionally, the identifier of the process that created the window.

Syntax

DWORD WINAPI GetWindowThreadProcessId(
  __in       HWND hWnd,
  __out_opt  LPDWORD lpdwProcessId
);

Parameters

hWnd [in]

Type: HWND

A handle to the window.

lpdwProcessId [out, optional]

Type: LPDWORD

A pointer to a variable that receives the process identifier. If this parameter is not NULL, GetWindowThreadProcessId copies the identifier of the process to the variable; otherwise, it does not.

Return value

Type:

Type: DWORD

The return value is the identifier of the thread that created the window.

Requirements

Minimum supported client

Windows 2000 Professional

Minimum supported server

Windows 2000 Server

Header

Winuser.h (include Windows.h)

Library

User32.lib

DLL

User32.dll

See also

Windows Overview

 

 

Send comments about this topic to Microsoft

Build date: 2/3/2012

Did you find this helpful?
(1500 characters remaining)
Community Content Add
Annotations FAQ
error condition
what is the return value if there was an error?

[tfl - 06 04 12] Hi - and thanks for your post. Community content is not the appropriate place for technical support queries. Instead, you should visit the MSDN Forums at http://forums.microsoft.com/MSDN, where such posts are welcomed and where you stand a much better chance of getting your query resolved. Sorry if that's not the answer you wanted to hear.
Get owner process
To find the path to the process that created the window see the implementation of GetWindowProcessImage here:
http://www.asyncop.com/MTnPDirEnum.aspx?treeviewPath=%5bo%5d+Open-Source%5cWinModules%5cInfrastructure%5cSystemAPI.cpp
GetWindowThreadProcessId behavior if hWnd is invalid
GetWindowThreadProcessId returns 0 and the variable pointed to by lpdwProcessId
is not modifed if the handle hWnd is not valid. GetLastError() returns 87 (ERROR_INVALID_PARAMETER).