diff --git a/dlls/user32/tests/win.c b/dlls/user32/tests/win.c
index 700e60db17..572e39a372 100644
--- a/dlls/user32/tests/win.c
+++ b/dlls/user32/tests/win.c
@@ -3013,6 +3013,93 @@ static void test_popup_zorder(HWND hwnd_D, HWND hwnd_E, DWORD style)
     DestroyWindow(hwnd_F);
 }
 
+static void test_child_topmost_zorder(HWND hwnd_D)
+{
+    HWND hwnd_A, hwnd_B, hwnd_C;
+
+    BOOL is_wine = !strcmp(winetest_platform, "wine");
+
+    hwnd_C = CreateWindowExA(0, "MainWindowClass", NULL,
+                             WS_CHILD,
+                             100, 100, 100, 100,
+                             hwnd_D, 0, GetModuleHandleA(NULL), NULL);
+    check_z_order(hwnd_C, 0, 0, 0, FALSE);
+
+    hwnd_B = CreateWindowExA(0, "MainWindowClass", NULL,
+                             WS_CHILD,
+                             100, 100, 100, 100,
+                             hwnd_D, 0, GetModuleHandleA(NULL), NULL);
+    check_z_order(hwnd_C, hwnd_B, 0, 0, FALSE);
+    check_z_order(hwnd_B, 0, hwnd_C, 0, FALSE);
+
+    hwnd_A = CreateWindowExA(WS_EX_TOPMOST, "MainWindowClass", NULL,
+                             WS_CHILD,
+                             100, 100, 100, 100,
+                             hwnd_D, 0, GetModuleHandleA(NULL), NULL);
+    check_z_order(hwnd_C, hwnd_B, 0, 0, FALSE);
+    check_z_order(hwnd_B, hwnd_A, hwnd_C, 0, FALSE);
+todo_wine
+    check_z_order(hwnd_A, 0, hwnd_B, 0, TRUE);
+
+    SetWindowPos(hwnd_A, HWND_TOP, 0,0,0,0, SWP_NOSIZE|SWP_NOMOVE);
+    check_z_order(hwnd_C, hwnd_B, hwnd_A, 0, FALSE);
+    check_z_order(hwnd_B, 0, hwnd_C, 0, FALSE);
+todo_wine
+    check_z_order(hwnd_A, hwnd_C, 0, 0, TRUE);
+
+    SetWindowPos(hwnd_B, HWND_TOP, 0,0,0,0, SWP_NOSIZE|SWP_NOMOVE);
+    check_z_order(hwnd_C, 0, hwnd_A, 0, FALSE);
+    check_z_order(hwnd_B, hwnd_A, 0, 0, FALSE);
+todo_wine
+    check_z_order(hwnd_A, hwnd_C, hwnd_B, 0, TRUE);
+
+    SetWindowPos(hwnd_C, HWND_TOP, 0,0,0,0, SWP_NOSIZE|SWP_NOMOVE);
+    check_z_order(hwnd_C, hwnd_B, 0, 0, FALSE);
+    check_z_order(hwnd_B, hwnd_A, hwnd_C, 0, FALSE);
+todo_wine
+    check_z_order(hwnd_A, 0, hwnd_B, 0, TRUE);
+
+    SetWindowPos(hwnd_A, HWND_TOPMOST, 0,0,0,0, SWP_NOSIZE|SWP_NOMOVE);
+    check_z_order(hwnd_C, hwnd_B, 0, 0, FALSE);
+    check_z_order(hwnd_B, hwnd_A, hwnd_C, 0, FALSE);
+todo_wine
+    check_z_order(hwnd_A, 0, hwnd_B, 0, TRUE);
+
+    SetWindowPos(hwnd_B, HWND_TOPMOST, 0,0,0,0, SWP_NOSIZE|SWP_NOMOVE);
+    check_z_order(hwnd_C, hwnd_B, 0, 0, FALSE);
+    check_z_order(hwnd_B, hwnd_A, hwnd_C, 0, FALSE);
+todo_wine
+    check_z_order(hwnd_A, 0, hwnd_B, 0, TRUE);
+
+    SetWindowPos(hwnd_C, HWND_TOPMOST, 0,0,0,0, SWP_NOSIZE|SWP_NOMOVE);
+    check_z_order(hwnd_C, hwnd_B, 0, 0, FALSE);
+    check_z_order(hwnd_B, hwnd_A, hwnd_C, 0, FALSE);
+todo_wine
+    check_z_order(hwnd_A, 0, hwnd_B, 0, TRUE);
+
+    SetWindowPos(hwnd_A, HWND_TOP, 0,0,0,0, SWP_NOSIZE|SWP_NOMOVE);
+    check_z_order(hwnd_C, hwnd_B, hwnd_A, 0, FALSE);
+    check_z_order(hwnd_B, 0, hwnd_C, 0, FALSE);
+todo_wine
+    check_z_order(hwnd_A, hwnd_C, 0, 0, TRUE);
+
+    SetWindowPos(hwnd_B, HWND_TOP, 0,0,0,0, SWP_NOSIZE|SWP_NOMOVE);
+    check_z_order(hwnd_C, 0, hwnd_A, 0, FALSE);
+    check_z_order(hwnd_B, hwnd_A, 0, 0, FALSE);
+todo_wine
+    check_z_order(hwnd_A, hwnd_C, hwnd_B, 0, TRUE);
+
+    SetWindowPos(hwnd_C, HWND_TOP, 0,0,0,0, SWP_NOSIZE|SWP_NOMOVE);
+    check_z_order(hwnd_C, hwnd_B, 0, 0, FALSE);
+    check_z_order(hwnd_B, hwnd_A, hwnd_C, 0, FALSE);
+todo_wine
+    check_z_order(hwnd_A, 0, hwnd_B, 0, TRUE);
+
+    DestroyWindow(hwnd_A);
+    DestroyWindow(hwnd_B);
+    DestroyWindow(hwnd_C);
+}
+
 static void test_vis_rgn( HWND hwnd )
 {
     RECT win_rect, rgn_rect;
@@ -11971,6 +12058,7 @@ START_TEST(win)
     test_children_zorder(hwndMain);
     test_popup_zorder(hwndMain2, hwndMain, WS_POPUP);
     test_popup_zorder(hwndMain2, hwndMain, 0);
+    test_child_topmost_zorder(hwndMain);
     test_GetLastActivePopup();
     test_keyboard_input(hwndMain);
     test_mouse_input(hwndMain);
diff --git a/dlls/user32/winpos.c b/dlls/user32/winpos.c
index b92a20df18..9c8576e07b 100644
--- a/dlls/user32/winpos.c
+++ b/dlls/user32/winpos.c
@@ -1983,6 +1983,12 @@ static BOOL fixup_flags( WINDOWPOS *winpos, const RECT *old_window_rect, int par
         }
     }
 
+    if ((wndPtr->dwStyle & (WS_CHILD | WS_POPUP)) == WS_CHILD
+        && winpos->hwndInsertAfter == HWND_TOPMOST )
+    {
+        winpos->flags |= SWP_NOZORDER;
+    }
+
     /* Check hwndInsertAfter */
     if (winpos->flags & SWP_NOZORDER) goto done;
 
-- 
2.20.1

