win2k窗口句柄获得进程id

来源:互联网 发布:必应鸟淘客软件怎么样 编辑:程序博客网 时间:2024/05/15 05:43

/*以下代码在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
*/

 

原创粉丝点击