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

' 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.

Related Functions

IsChild, GetParent

Category

Windows

Back to the index.


Last Modified: August 1, 1999
This page is copyright © 1999 Paul Kuliniewicz. Copyright Information

Go to Paul Kuliniewicz's Home Page.
E-mail: rogue953@hotmail.com
This page is at http://skyscraper.fortunecity.com/transmission/45/api/s/setparent.html