Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/jsp/3.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Windows 如何获取父窗口&x27;的孙子,或孙子';儿子_Windows_Winapi_Handle_Childwindow - Fatal编程技术网

Windows 如何获取父窗口&x27;的孙子,或孙子';儿子

Windows 如何获取父窗口&x27;的孙子,或孙子';儿子,windows,winapi,handle,childwindow,Windows,Winapi,Handle,Childwindow,我有一个名为example file的主窗口类,每个文件窗口都有几个子窗口,例如页面,每个页面都有几个子窗口,例如文本框等。 如何从文本框的句柄或文本框的子窗口之一获取文件句柄。 有一个函数GetParent(),但它返回一级以上的父级,我正在寻找这样一个返回顶级窗口的函数。 我编写了执行操作的代码,如下所示,但我的问题是win32中是否有系统函数 HWND GetTopLevelWindow(HWND hChild) { HWND topParent = 0; HWND h1

我有一个名为example file的主窗口类,每个文件窗口都有几个子窗口,例如页面,每个页面都有几个子窗口,例如文本框等。
如何从文本框的句柄或文本框的子窗口之一获取文件句柄。
有一个函数
GetParent()
,但它返回一级以上的父级,我正在寻找这样一个返回顶级窗口的函数。
我编写了执行操作的代码,如下所示,但我的问题是win32中是否有系统函数

HWND GetTopLevelWindow(HWND hChild)
{
    HWND topParent = 0;
    HWND h1 = hChild;
    HWND h2;

    while(topParent == 0)
    {
        h2 = GetParent(h1);
        if(h2 == 0)
            topParent = h1;
        else
            h1 = h2;
    }
    return topParent;
}
您需要使用,参数为
GA_ROOT
。比如说

HWND topParent = GetAncestor(hChild, GA_ROOT);

可能是
get祖先(GA_ROOT)
或某种变体?是的,这应该是一个答案<代码>获取祖先(hWndChild,GA_ROOT)