通过进程ID获取hwnd C++

2022-01-04 00:00:00 get pid c++ hwnd

如果我知道进程 ID,如何获取应用程序的 HWND?任何人都可以张贴样品吗?我正在使用 MSV C++ 2010.我找到了 Process::MainWindowHandle 但我不知道如何使用它.

How can I get the HWND of application, if I know the process ID? Anyone could post a sample please? I'm using MSV C++ 2010. I found Process::MainWindowHandle but I don't know how to use it.

推荐答案

HWND g_HWND=NULL;
BOOL CALLBACK EnumWindowsProcMy(HWND hwnd,LPARAM lParam)
{
    DWORD lpdwProcessId;
    GetWindowThreadProcessId(hwnd,&lpdwProcessId);
    if(lpdwProcessId==lParam)
    {
        g_HWND=hwnd;
        return FALSE;
    }
    return TRUE;
}
EnumWindows(EnumWindowsProcMy,m_ProcessId);

相关文章