lygstate
lygstate

Reputation: 562

Win32/Qt - Can one Enumerate all the toplevel windows belonging to the calling process?

I want to detect all the top-level windows in order to send messages to it's Descendants. How can I do that? The following code seems to not be detecting Qt top level window, I don't know why.

static BOOL CALLBACK EnumWindowsProc(_In_ HWND hwnd, _In_ LPARAM lParam) {
  WORD far wndProcessID;

  WORD currentProcessID = GetCurrentProcessId();
  std::vector<HWND> *topWindowList = (std::vector<HWND> *)lParam;
  if (topWindowList != NULL &&
      GetWindowThreadProcessId(hwnd, NULL) == currentProcessID) {
    printf("Found a top level window");
    fflush(stdout);
    topWindowList->push_back(hwnd);
  }
  return TRUE;
}

void enumAllDesktopChildWindow() {
  std::vector<HWND> topWindowList;
  EnumChildWindows(GetDesktopWindow(), EnumWindowsProc, LPARAM(&topWindowList));
}

Upvotes: 2

Views: 1376

Answers (1)

manuell
manuell

Reputation: 7620

First, the GetWindowThreadProcessId API returns a Thread ID (TID) not a Process ID (PID)

Second, if you want to enumerate all top-level Windows, you should use EnumWindows, not EnumChildWindows. If you want to use EnumChildWindows, pass NULL as the first parameter.

Upvotes: 3

Related Questions