[1/2] user32: SetParent() should use ShowWindow() to make a reparented window visible and move a window to new position.

Dmitry Timoshkov dmitry at baikal.ru
Fri Mar 23 03:57:28 CDT 2012


SetParent() tests confirm that.

These 2 patches is the first step in fixing a fundamental SetParent() bug.
Currently window coordiantes are internally stored relative to parent, and
are not updated by SetParent(), so while a window is not actually moved by
SetParent(), GetWindowRect() returns coordinates like the window has been
moved to the new position.

This is a resend of an old 3/3 series, but without the final patch which
was incomplete.
---
 dlls/user32/win.c |   11 +++++++----
 1 file changed, 7 insertions(+), 4 deletions(-)

diff --git a/dlls/user32/win.c b/dlls/user32/win.c
index 3e7d9b1..1cad8aa 100644
--- a/dlls/user32/win.c
+++ b/dlls/user32/win.c
@@ -2787,6 +2787,7 @@ HWND WINAPI SetParent( HWND hwnd, HWND parent )
     HWND old_parent = 0;
     BOOL was_visible;
     WND *wndPtr;
+    POINT pt;
     BOOL ret;
 
     if (is_broadcast(hwnd) || is_broadcast(parent))
@@ -2828,6 +2829,9 @@ HWND WINAPI SetParent( HWND hwnd, HWND parent )
     wndPtr = WIN_GetPtr( hwnd );
     if (!wndPtr || wndPtr == WND_OTHER_PROCESS || wndPtr == WND_DESKTOP) return 0;
 
+    pt.x = wndPtr->rectWindow.left;
+    pt.y = wndPtr->rectWindow.top;
+
     SERVER_START_REQ( set_parent )
     {
         req->handle = wine_server_user_handle( hwnd );
@@ -2849,10 +2853,9 @@ HWND WINAPI SetParent( HWND hwnd, HWND parent )
        in the x-order and send the expected WM_WINDOWPOSCHANGING and
        WM_WINDOWPOSCHANGED notification messages.
     */
-    SetWindowPos( hwnd, HWND_TOP, 0, 0, 0, 0,
-                  SWP_NOACTIVATE | SWP_NOMOVE | SWP_NOSIZE | (was_visible ? SWP_SHOWWINDOW : 0) );
-    /* FIXME: a WM_MOVE is also generated (in the DefWindowProc handler
-     * for WM_WINDOWPOSCHANGED) in Windows, should probably remove SWP_NOMOVE */
+    SetWindowPos( hwnd, HWND_TOP, pt.x, pt.y, 0, 0, SWP_NOSIZE );
+
+    if (was_visible) ShowWindow( hwnd, SW_SHOW );
 
     return old_parent;
 }
-- 
1.7.9.4




More information about the wine-patches mailing list