SetParent Function

Declare Function SetParent Lib "user32.dll" (ByVal hWndChild As Long, ByVal hWndNewParent As Long) As Long

Platforms

Description & Usage

SetParent moves a window from having one parent window to another. If needed, the window itself moves so it can be "inside" its new parent. The child window can also become independent by making it a child of the desktop.

Return Value

If an error occured, the function returns 0 (use GetLastError to get the error code). If successful, the function returns a handle to the child window's former parent window.

Visual Basic-Specific Issues

None.

Parameters

hWndChild
The handle of the window to change the parent of.
hWndNewParent
The handle of the window to become the new parent of the child window. To make the desktop the parent, pass 0 for this parameter.

Example

' This code is licensed according to the terms and conditions listed here.

' Move button Command1, which is a child window, from its old
' parent window of Form1 to its new parent window of Form2.
Dim oldhwnd As Long  ' receives handle of button's former parent

oldhwnd = SetParent(Command1.hWnd, Form2.hWnd)  ' button is now in window Form2.

See Also

IsChild, GetParent

Category

Windows

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


Last Modified: August 1, 1999
This page is copyright © 1999 Paul Kuliniewicz. Copyright Information Revised October 29, 2000
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/s/setparent.html