Handle to window handle

I tried using the method "capture all process identifiers listed on the desktop", however this does not work.

  • Is there a way to convert a handle to a window handle? -or-
  • Is there a way to take the process id and find out all the child windows created by the process?

I do not want to use FindWindowbecause of several process problems.

+4
source share
1 answer

You can call EnumWindows () to iterate over all the top-level windows on the screen, then use GetWindowThreadProcessId () to find out which of them belong to your process.

, - :

BOOL CALLBACK ForEachTopLevelWindow(HWND hwnd, LPARAM lp)
{
    DWORD processId;
    GetWindowThreadProcessId(hwnd, &processId);
    if (processId == (DWORD) lp) {
        // `hwnd` belongs to the target process.
    }
    return TRUE;
}

VOID LookupProcessWindows(DWORD processId)
{
    EnumWindows(ForEachTopLevelWindow, (LPARAM) processId);
}
+5

Source: https://habr.com/ru/post/1775962/


All Articles