/*以下代码在win2k源码中寻找到的 位于win2k/privata/ntos/w32/ntoser/client/winmgrc.c Ln255*/
/***************************************************************************/
* GetWindowThreadProcessId
* Get's windows process and thread ids.
* 24-Jun-1991 ScottLu Created.
/***************************************************************************/
DWORD GetWindowThreadProcessId(
HWND hwnd,
LPDWORD lpdwProcessId)
{
PTHREADINFO ptiWindow;
DWORD dwThreadId;
if ((ptiWindow = PtiWindow(hwnd)) == NULL)
return 0;
/*
* For non-system threads get the info from the thread info structure
*/
if (ptiWindow == PtiCurrent()) {
if (lpdwProcessId != NULL)
*lpdwProcessId = HandleToUlong(NtCurrentTeb()->ClientId.UniqueProcess);
dwThreadId = HandleToUlong(NtCurrentTeb()->ClientId.UniqueThread);
} else {
/*
* Make this better later on.
*/
if (lpdwProcessId != NULL)
*lpdwProcessId = HandleToUlong(NtUserQueryWindow(hwnd, WindowProcess));
dwThreadId = HandleToUlong(NtUserQueryWindow(hwnd, WindowThread));
}
return dwThreadId;
}
/*
#define windowthread 0x1
#define windowprocess 0x0
*/
这段代码展示了在Windows 2000操作系统中,如何从窗口句柄获取对应的进程和线程ID。通过PTHREADINFO结构,检查是否为当前线程,并使用NtCurrentTeb()函数获取信息,或者对于非当前线程,使用NtUserQueryWindow()函数查询。
1万+

被折叠的 条评论
为什么被折叠?



