GetParent function (winuser.h)

Retrieves a handle to the specified window's parent or owner.

To retrieve a handle to a specified ancestor, use the GetAncestor function.

Syntax

HWND GetParent(
  [in] HWND hWnd
);

Parameters

[in] hWnd

Type: HWND

A handle to the window whose parent window handle is to be retrieved.

Return value

Type: HWND

If the window is a child window, the return value is a handle to the parent window. If the window is a top-level window with the WS_POPUP style, the return value is a handle to the owner window.

If the function fails, the return value is NULL. To get extended error information, call GetLastError.

This function typically fails for one of the following reasons:

  • The window is a top-level window that is unowned or does not have the WS_POPUP style.
  • The owner window has WS_POPUP style.

Remarks

To obtain a window's owner window, instead of using GetParent, use GetWindow with the GW_OWNER flag. To obtain the parent window and not the owner, instead of using GetParent, use GetAncestor with the GA_PARENT flag.

Examples

For an example, see Initializing a Dialog Box.

Requirements

Requirement Value
Minimum supported client Windows 2000 Professional [desktop apps only]
Minimum supported server Windows 2000 Server [desktop apps only]
Target Platform Windows
Header winuser.h (include Windows.h)
Library User32.lib
DLL User32.dll
API set ext-ms-win-ntuser-window-l1-1-0 (introduced in Windows 8)

See also

Conceptual

GetAncestor

GetWindow

Reference

SetParent

Windows

Windows Styles