The following code locates the handles of all windows per a given PID.
#include <vector>
#include <Windows.h>
void GetAllWindowsFromProcessID(DWORD dwProcessID, std::vector<HWND>& vhWnds)
{
HWND hCurWnd = NULL;
do
{
hCurWnd = FindWindowEx(NULL, hCurWnd, NULL, NULL);
if (hCurWnd != NULL)
{
DWORD curProcessID = 0;
GetWindowThreadProcessId(hCurWnd, &curProcessID);
if (curProcessID == dwProcessID)
{
vhWnds.push_back(hCurWnd);
wprintf(L"Found hWnd %d\n", (int)hCurWnd);
}
}
} while (hCurWnd != NULL);
}