HWND GetWindowHandleByPID(DWORD dwProcessID)

来源:互联网 发布:曲面电视的缺点 知乎 编辑:程序博客网 时间:2024/06/02 06:15
HWND GetWindowHandleByPID(DWORD dwProcessID)
{
    HWND h 
= GetTopWindow(0);
    
while ( h )
    {
        DWORD pid 
= 0;
        DWORD dwTheardId 
= GetWindowThreadProcessId( h,&pid);

        
if (dwTheardId != 0)
        {
            
if ( pid == dwProcessID/*your process id*/ )
            {
                
// here h is the handle to the window
                return h;
            }
        }

        h 
= GetNextWindow( h , GW_HWNDNEXT);
    }

    
return NULL;
}
原创粉丝点击