Thanks to Michael Haephrati , I slightly corrected your code for modern Qt C ++ 11:
#include <iostream> #include "windows.h" #include "tlhelp32.h" #include "tchar.h" #include "vector" #include "string" using namespace std; void GetAllWindowsFromProcessID(DWORD dwProcessID, std::vector <HWND> &vhWnds) { // find all hWnds (vhWnds) associated with a process id (dwProcessID) HWND hCurWnd = nullptr; do { hCurWnd = FindWindowEx(nullptr, hCurWnd, nullptr, nullptr); DWORD checkProcessID = 0; GetWindowThreadProcessId(hCurWnd, &checkProcessID); if (checkProcessID == dwProcessID) { vhWnds.push_back(hCurWnd); // add the found hCurWnd to the vector //wprintf(L"Found hWnd %d\n", hCurWnd); } } while (hCurWnd != nullptr); }
rsarov
source share