diff --git a/dlls/user32/tests/win.c b/dlls/user32/tests/win.c index 615cb2a076..d524bccf49 100644 --- a/dlls/user32/tests/win.c +++ b/dlls/user32/tests/win.c @@ -445,6 +445,12 @@ static void test_parent_owner(void) ret = SetParent( test, child ); ok( ret == desktop, "SetParent return value %p expected %p\n", ret, desktop ); check_parents( test, child, child, 0, 0, hwndMain, test ); + + ShowWindow( test, SW_SHOW ); + ret = SetParent( test, test ); + ok( ret == NULL, "SetParent return value %p expected %p\n", ret, NULL ); + ok( GetWindowLongA( test, GWL_STYLE ) & WS_VISIBLE, "window is not visible after SetParent\n" ); + check_parents( test, child, child, 0, 0, hwndMain, test ); DestroyWindow( test ); /* owned popup */ diff --git a/dlls/user32/win.c b/dlls/user32/win.c index 9a19b2ade4..adf74d099a 100644 --- a/dlls/user32/win.c +++ b/dlls/user32/win.c @@ -2701,6 +2701,12 @@ HWND WINAPI SetParent( HWND hwnd, HWND parent ) if (!(full_handle = WIN_IsCurrentThread( hwnd ))) return (HWND)SendMessageW( hwnd, WM_WINE_SETPARENT, (WPARAM)parent, 0 ); + if (full_handle == parent) + { + SetLastError( ERROR_INVALID_PARAMETER ); + return 0; + } + /* Windows hides the window first, then shows it again * including the WM_SHOWWINDOW messages and all */ was_visible = ShowWindow( hwnd, SW_HIDE );