GetParent Function

Declare Function GetParent Lib "user32.dll" (ByVal hwnd As Long) As Long

Platforms: Win 32s, Win 95/98, Win NT

GetParent returns the handle of the parent window of another window. For example, the parent of a button would normally be the form window it is in. If successful, the function returns a handle to the parent window. If it fails (for example, trying to find the parent of a non-window), it returns 0.

hwnd
The handle of the window to find the parent of.

Example:

' Figure out which frame, Frame1 or Frame2, the button Command1
' is located on -- it is considered the child of the frame it is in
Dim parenthwnd As Long  ' button's parent window

parenthwnd = GetParent(Command1.hWnd)  ' get the button's parent window
If parenthwnd = Frame1.hWnd Then Debug.Print "The button is inside Frame 1."
If parenthwnd = Frame2.hWnd Then Debug.Print "The button is inside Frame 2."

See Also: SetParent
Category: Windows

Go back to the alphabetical Function listing.
Go back to the Reference section index.


This page is copyright © 2000 Paul Kuliniewicz. Copyright Information.
Go back to the Windows API Guide home page.
E-mail: vbapi@vbapi.com Send Encrypted E-Mail
This page is at http://www.vbapi.com/ref/g/getparent.html