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.
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."
Related Call: SetParent
Category: Windows
Back to the index.