From d13a44e4aa12fa5ad3498c39934e88a7dcd30916 Mon Sep 17 00:00:00 2001 From: Jacek Caban Date: Mon, 22 Feb 2016 12:54:59 +0100 Subject: [PATCH] user32: Don't use window's parent as an owner if WS_CHILD style is not set. Signed-off-by: Jacek Caban Signed-off-by: Alexandre Julliard --- dlls/user32/tests/win.c | 25 +++++++++++++++++++++++++ server/window.c | 3 ++- 2 files changed, 27 insertions(+), 1 deletion(-) diff --git a/dlls/user32/tests/win.c b/dlls/user32/tests/win.c index 71459e14f35..988aa6c157e 100644 --- a/dlls/user32/tests/win.c +++ b/dlls/user32/tests/win.c @@ -652,6 +652,31 @@ static void test_parent_owner(void) DestroyWindow( child ); DestroyWindow( test ); DestroyWindow( owner ); + + /* Test that owner window takes into account WS_CHILD flag even if parent is set by SetParent. */ + owner = create_tool_window( WS_VISIBLE | WS_OVERLAPPEDWINDOW, desktop ); + SetParent(owner, hwndMain); + check_parents( owner, hwndMain, hwndMain, NULL, NULL, hwndMain, owner ); + test = create_tool_window( WS_VISIBLE | WS_OVERLAPPEDWINDOW, owner ); + check_parents( test, desktop, owner, NULL, owner, test, test ); + DestroyWindow( owner ); + DestroyWindow( test ); + + owner = create_tool_window( WS_VISIBLE | WS_CHILD, desktop ); + SetParent(owner, hwndMain); + check_parents( owner, hwndMain, hwndMain, hwndMain, NULL, hwndMain, hwndMain ); + test = create_tool_window( WS_VISIBLE | WS_OVERLAPPEDWINDOW, owner ); + check_parents( test, desktop, hwndMain, NULL, hwndMain, test, test ); + DestroyWindow( owner ); + DestroyWindow( test ); + + owner = create_tool_window( WS_VISIBLE | WS_POPUP | WS_CHILD, desktop ); + SetParent(owner, hwndMain); + check_parents( owner, hwndMain, hwndMain, NULL, NULL, hwndMain, owner ); + test = create_tool_window( WS_VISIBLE | WS_OVERLAPPEDWINDOW, owner ); + check_parents( test, desktop, owner, NULL, owner, test, test ); + DestroyWindow( owner ); + DestroyWindow( test ); } static BOOL CALLBACK enum_proc( HWND hwnd, LPARAM lParam) diff --git a/server/window.c b/server/window.c index 93282115068..143b60cf33c 100644 --- a/server/window.c +++ b/server/window.c @@ -1901,7 +1901,8 @@ DECL_HANDLER(create_window) return; } else /* owner must be a top-level window */ - while (!is_desktop_window(owner->parent)) owner = owner->parent; + while ((owner->style & (WS_POPUP|WS_CHILD)) == WS_CHILD && !is_desktop_window(owner->parent)) + owner = owner->parent; } atom = cls_name.len ? find_global_atom( NULL, &cls_name ) : req->atom;