From 515f998f0dfe19ef0a158d26cb61b58b9a0def7b Mon Sep 17 00:00:00 2001 From: Doug Lyons Date: Thu, 2 May 2024 03:43:41 -0500 Subject: [PATCH] [NTUSER] Fix co_IntSetParent when calling on itself (#6365) * Patch by @I_Kill_Bugs. * Provide explanation for change. CORE-9386 --- win32ss/user/ntuser/window.c | 40 ++++++++++++++++++------------------ 1 file changed, 20 insertions(+), 20 deletions(-) diff --git a/win32ss/user/ntuser/window.c b/win32ss/user/ntuser/window.c index ea1d33624c3..ea67f811073 100644 --- a/win32ss/user/ntuser/window.c +++ b/win32ss/user/ntuser/window.c @@ -1218,29 +1218,29 @@ co_IntSetParent(PWND Wnd, PWND WndNewParent) if (WndOldParent) UserReferenceObject(WndOldParent); /* Caller must deref */ - if (WndNewParent != WndOldParent) + /* Even if WndNewParent == WndOldParent continue because the + * child window (Wnd) should be moved to the top of the z-order */ + + /* Unlink the window from the siblings list */ + IntUnlinkWindow(Wnd); + Wnd->ExStyle2 &= ~WS_EX2_LINKED; + + /* Set the new parent */ + WndSetParent(Wnd, WndNewParent); + + if (Wnd->style & WS_CHILD && + Wnd->spwndOwner && + Wnd->spwndOwner->ExStyle & WS_EX_TOPMOST) { - /* Unlink the window from the siblings list */ - IntUnlinkWindow(Wnd); - Wnd->ExStyle2 &= ~WS_EX2_LINKED; - - /* Set the new parent */ - WndSetParent(Wnd, WndNewParent); - - if ( Wnd->style & WS_CHILD && - Wnd->spwndOwner && - Wnd->spwndOwner->ExStyle & WS_EX_TOPMOST ) - { - ERR("SetParent Top Most from Pop up!\n"); - Wnd->ExStyle |= WS_EX_TOPMOST; - } - - /* Link the window with its new siblings */ - IntLinkHwnd( Wnd, - ((0 == (Wnd->ExStyle & WS_EX_TOPMOST) && - UserIsDesktopWindow(WndNewParent) ) ? HWND_TOP : HWND_TOPMOST ) ); + ERR("SetParent Top Most from Pop up\n"); + Wnd->ExStyle |= WS_EX_TOPMOST; } + /* Link the window with its new siblings */ + IntLinkHwnd(Wnd, + ((0 == (Wnd->ExStyle & WS_EX_TOPMOST) && + UserIsDesktopWindow(WndNewParent)) ? HWND_TOP : HWND_TOPMOST)); + if ( WndNewParent == co_GetDesktopWindow(Wnd) && !(Wnd->style & WS_CLIPSIBLINGS) ) {