SetParent

The SetParent function changes the parent window of the specified child window.

HWND SetParent(
  HWND hWndChild,      // handle to window whose parent is changing
  HWND hWndNewParent   // handle to new parent window
);
 

Parameters

hWndChild
Handle to the child window.
hWndNewParent
Handle to the new parent window. If this parameter is NULL, the desktop window becomes the new parent window.

Windows NT 5.0 and later: If this parameter is HWND_MESSAGE, the child window becomes a message-only window.

Return Values

If the function succeeds, the return value is a handle to the previous parent window.

If the function fails, the return value is NULL. To get extended error information, call GetLastError.

Remarks

An application can use the SetParent function to set the parent window of a pop-up, overlapped, or child window. The new parent window and the child window must belong to the same application.

If the window identified by the hWndChild parameter is visible, the system performs the appropriate redrawing and repainting.

For compatibility reasons, SetParent does not modify the WS_CHILD or WS_POPUP window styles of the window whose parent is being changed. Therefore, if hWndNewParent is NULL, you should also clear the WS_CHILD bit and set the WS_POPUP style after calling SetParent. Conversely, if hWndNewParent is not NULL and the window was previously a child of the desktop, you should clear the WS_POPUP style and set the WS_CHILD style before calling SetParent.

QuickInfo

  Windows NT: Requires version 3.1 or later.
  Windows: Requires Windows 95 or later.
  Windows CE: Requires version 1.0 or later.
  Header: Declared in winuser.h.
  Import Library: Use user32.lib.

See Also

Windows Overview, Window Functions, GetParent