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
Type: HWND
A handle to the window.
lpdwProcessId
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.
HANDLE Phwd yuan71058 发表于 2013-5-7 11:22 static/image/common/back.gif
真的可以了 这是为什么呢 我怎么没明白呢
GetWindowThreadProcessId 的第二个参数是获取进程ID。而这个函数返回的却是创建这个窗口的线程ID,这两个概念不同。
你下面用OpenProcess打开进程,所需要的是进程ID,也就是 GetWindowThreadProcessId的第二参数返回的值。
你这样写:DWORD PID_=::GetWindowThreadProcessId (hwnd_,&PID_);
这个函数会先将 进程ID传给 PID_这个变量,然后会返回重新给这个变量赋值了线程ID,所以你拿到的是线程ID。 DWORD PID_=::GetWindowThreadProcessId (hwnd_,&PID_);
//改成
DWORD PID_= 0;
::GetWindowThreadProcessId (hwnd_,&PID_);
页:
[1]
2