1 out of 5 rated this helpful - Rate this topic

GetAncestor function

Applies to: desktop apps only

Retrieves the handle to the ancestor of the specified window.

Syntax

HWND WINAPI GetAncestor(
  __in  HWND hwnd,
  __in  UINT gaFlags
);

Parameters

hwnd [in]

Type: HWND

A handle to the window whose ancestor is to be retrieved. If this parameter is the desktop window, the function returns NULL.

gaFlags [in]

Type: UINT

The ancestor to be retrieved. This parameter can be one of the following values.

ValueMeaning
GA_PARENT
1

Retrieves the parent window. This does not include the owner, as it does with the GetParent function.

GA_ROOT
2

Retrieves the root window by walking the chain of parent windows.

GA_ROOTOWNER
3

Retrieves the owned root window by walking the chain of parent and owner windows returned by GetParent.

 

Return value

Type:

Type: HWND

The return value is the handle to the ancestor window.

Requirements

Minimum supported client

Windows 2000 Professional

Minimum supported server

Windows 2000 Server

Header

Winuser.h (include Windows.h)

Library

User32.lib

DLL

User32.dll

See also

Reference
GetParent
Conceptual
Windows

 

 

Send comments about this topic to Microsoft

Build date: 2/3/2012

Did you find this helpful?
(1500 characters remaining)
Community Content Add
Annotations FAQ
Litteral mistake
In "Parameters" paragraph:
"GA_ROOTOWNER
Retrieves the owned root window by walking the chain of parent and owner windows returned by GetParent."
"owned" should be "owning".
C# syntax
[DllImport("user32.dll", CharSet=CharSet.Auto, ExactSpelling=true)]
public static extern IntPtr GetAncestor(IntPtr hWnd, int flags);
vb.net syntax
<DllImport("user32.dll", CharSet:=CharSet.Auto, ExactSpelling:=True)> _
Public Shared Function GetAncestor(ByVal hWnd As IntPtr, ByVal flags As Integer) As IntPtr End Function