I have a main window class, called for example file, and each file window, has several child windows, for example pages, and each page has several child windows, for example text boxes, etc, etc..
How can I get handle of the file, from handle of the text box, or one of the text box's child windows.
There is a function GetParent(), but it returns the parent one level up, and I am looking for such a function that returns the top level window.
I wrote my code that performs the action, as follows, but my question if there is a system function in 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;
}
有帮助吗?

解决方案

You need to use GetAncestor, with an argument of GA_ROOT. For example

HWND topParent = GetAncestor(hChild, GA_ROOT);
许可以下: CC-BY-SA归因
不隶属于 StackOverflow
scroll top