Export (0) Print
Expand All
Expand Minimize

GetParent function

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 WINAPI GetParent(
  _In_  HWND hWnd
);

Parameters

hWnd [in]

Type: HWND

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

Return value

Type:

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

Minimum supported client

Windows 2000 Professional [desktop apps only]

Minimum supported server

Windows 2000 Server [desktop apps only]

Header

Winuser.h (include Windows.h)

Library

User32.lib

DLL

User32.dll

See also

Reference
GetAncestor
GetWindow
SetParent
Windows Styles
Conceptual
Windows

 

 

Community Additions

ADD
Show:
© 2014 Microsoft