Click to Rate and Give Feedback
MSDN
MSDN Library
User Interface
Windowing
Windows
Functions
GetParent Function
GetParent Function

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

Parameters

hWnd
[in] Handle to the window whose parent window handle is to be retrieved.

Return Value

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, the return value is a handle to the owner window. If the window is a top-level unowned window or if the function fails, the return value is NULL. To get extended error information, call GetLastError. For example, this would determine, when the function returns NULL, if the function failed or the window was a top-level window.

Remarks

Note that, despite its name, this function can return an owner window instead of a parent window. To obtain the parent window and not the owner, use GetLastError with the GA_PARENT flag.

Example

For an example, see Initializing a Dialog Box.

Function Information

Minimum DLL Versionuser32.dll
HeaderDeclared in Winuser.h, include Windows.h
Import libraryUser32.lib
Minimum operating systems Windows 95, Windows NT 3.1

See Also

Tags What's this?: getparent (x) parent-window (x) Add a tag
Community Content What is Community Content?
Add new contentRSS Annotations
Possible VB9 declaration Đonny ... Noelle Mallory - MSFT | Edit
This is not phishing, this is art!
Read more here what this is about.
| Show History
Friend Declare Function GetParent Lib "user32.dll" (ByVal hwnd As Int32) As Int32
Tags What's this?: Add a tag
Flag as ContentBug
vb.net syntax dmex | Edit
This is not phishing, this is art!
Read more here what this is about.
| Show History
<DllImport("user32.dll", CharSet:=CharSet.Auto, ExactSpelling:=True)> _
Public Shared Function GetParent(ByVal hWnd As IntPtr) As IntPtr End Function
Tags What's this?: Add a tag
Flag as ContentBug
C# syntax dmex | Edit
This is not phishing, this is art!
Read more here what this is about.
| Show History
[DllImport("user32.dll", CharSet = CharSet.Auto, ExactSpelling = true)]
public static extern IntPtr GetParent(IntPtr hWnd);
Tags What's this?: c# (x) Add a tag
Flag as ContentBug
fix for "Remarks" Yuriy Chumak | Edit
This is not phishing, this is art!
Read more here what this is about.
| Show History
Remarks
Note that, despite its name, this function can return an owner window instead of a parent window. To obtain the parent window and not the owner, use GetAncestor with the GA_PARENT flag.
Tags What's this?: fix (x) Add a tag
Flag as ContentBug
Processing
© 2009 Microsoft Corporation. All rights reserved. Terms of Use | Trademarks | Privacy Statement | Site Feedback
Page view tracker