如何从子窗口句柄获取主窗口句柄

时间:2020-11-05 19:45:20

标签: c++ winapi

我想从前景窗口获取主窗口的句柄。

hWnd = GetForegroundWindow();

hwndOwner = GetWindow(hWnd, GW_OWNER);
hwndParent = GetParent(hWnd);

hwndOwnerhwndParent只是前景窗口上方的一层。如何在不递归调用上述函数的情况下获取主窗口句柄?

1 个答案:

答案 0 :(得分:0)

将GetAncestor与GA_ROOT标志一起使用: GetAncestor(hwndChild,GA_ROOT);

请注意,我不确定GA_ROOT和GA_ROOTOWNER之间的区别。