GetAncestor 行为异常 [英] GetAncestor behaving weirdlly

查看:37
本文介绍了GetAncestor 行为异常的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

HWND hwnd; 
HWND hParent;
HWND hwnd;

hwnd = GetForegroundWindow();
hParent = GetAncestor(hwnd, GA_PARENT);
hTop = GetAncestor(hwnd, GA_ROOT);

hParent 是桌面句柄,hTop 与 hwnd 相同,而不是返回父级和顶级窗口.这是为什么?

hParent is the Desktop handle and hTop is same as hwnd, instead of returning parent and top-level window. Why is that?

推荐答案

hParent 是桌面句柄

hParent is the Desktop handle

从这个结果来看,hwnd 是一个顶级窗口.

From this result, the hwnd is a top-level window.

另一方面,顶级窗口没有父窗口.它的父级是空.

A top-level window, on the other hand, has no parent. Its parent is NULL.

从这个角度来看,根窗口是它自己,因为它没有父窗口.所以 hTop 与 hwnd 相同" 是预期的.

From this point of view, the root window is itself since it has no parent. So "hTop is same as hwnd" is expected.

参考"桌面窗口有什么特别之处?"和 "一个窗口可以有父级或所有者,但不能同时有两者".

Refer to "What's so special about the desktop window?" and "A window can have a parent or an owner but not both".

考虑这种情况:窗口A有一个子窗口B,B有一个子窗口C.此时:

Consider this situation: Window A has a child window B, B has a child window C. At this time:

// hWindowC is HWND of window C; hWindowB is HWND of window B; hWindowA is HWND of window A
hWindowB = GetAncestor(hWindowC, GA_PARENT);
hWindowA= GetAncestor(hWindowC, GA_ROOT);

这篇关于GetAncestor 行为异常的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆