[USER32_WINETEST] Sync with Wine Staging 1.9.11 Part 4. CORE-11368
[reactos.git] / rostests / winetests / user32 / win.c
index 0dc610f..74c9ec8 100644 (file)
 #define SPI_GETDESKWALLPAPER 0x0073
 #endif
 
+#ifndef WM_SYSTIMER
+#define WM_SYSTIMER 0x0118
+#endif
+
 #define LONG_PTR INT_PTR
 #define ULONG_PTR UINT_PTR
 
@@ -57,15 +61,19 @@ static int  (WINAPI *pGetWindowRgnBox)(HWND,LPRECT);
 static BOOL (WINAPI *pGetGUIThreadInfo)(DWORD, GUITHREADINFO*);
 static BOOL (WINAPI *pGetProcessDefaultLayout)( DWORD *layout );
 static BOOL (WINAPI *pSetProcessDefaultLayout)( DWORD layout );
+static BOOL (WINAPI *pFlashWindow)( HWND hwnd, BOOL bInvert );
 static BOOL (WINAPI *pFlashWindowEx)( PFLASHWINFO pfwi );
 static DWORD (WINAPI *pSetLayout)(HDC hdc, DWORD layout);
 static DWORD (WINAPI *pGetLayout)(HDC hdc);
 static BOOL (WINAPI *pMirrorRgn)(HWND hwnd, HRGN hrgn);
 
 static BOOL test_lbuttondown_flag;
+static DWORD num_gettext_msgs;
+static DWORD num_settext_msgs;
 static HWND hwndMessage;
 static HWND hwndMain, hwndMain2;
 static HHOOK hhook;
+static BOOL app_activated, app_deactivated;
 
 static const char* szAWRClass = "Winsize";
 static HMENU hmenu;
@@ -97,12 +105,28 @@ static void flush_events( BOOL remove_messages )
     {
         if (MsgWaitForMultipleObjects( 0, NULL, FALSE, min_timeout, QS_ALLINPUT ) == WAIT_TIMEOUT) break;
         if (remove_messages)
-            while (PeekMessage( &msg, 0, 0, 0, PM_REMOVE )) DispatchMessage( &msg );
+            while (PeekMessageA( &msg, 0, 0, 0, PM_REMOVE )) DispatchMessageA( &msg );
         diff = time - GetTickCount();
         min_timeout = 50;
     }
 }
 
+static BOOL wait_for_event(HANDLE event, int timeout)
+{
+    DWORD end_time = GetTickCount() + timeout;
+    MSG msg;
+
+    do {
+        if(MsgWaitForMultipleObjects(1, &event, FALSE, timeout, QS_ALLINPUT) == WAIT_OBJECT_0)
+            return TRUE;
+        while(PeekMessageA(&msg, 0, 0, 0, PM_REMOVE))
+            DispatchMessageA(&msg);
+        timeout = end_time - GetTickCount();
+    }while(timeout > 0);
+
+    return FALSE;
+}
+
 /* check the values returned by the various parent/owner functions on a given window */
 static void check_parents( HWND hwnd, HWND ga_parent, HWND gwl_parent, HWND get_parent,
                            HWND gw_owner, HWND ga_root, HWND ga_root_owner )
@@ -163,6 +187,8 @@ static BOOL ignore_message( UINT message )
     return (message >= 0xc000 ||
             message == WM_GETICON ||
             message == WM_GETOBJECT ||
+            message == WM_TIMER ||
+            message == WM_SYSTIMER ||
             message == WM_TIMECHANGE ||
             message == WM_DEVICECHANGE);
 }
@@ -626,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)
@@ -657,7 +708,7 @@ static DWORD CALLBACK enum_thread( void *arg )
             "wrong error %u\n", GetLastError() );
     }
 
-    PeekMessage( &msg, 0, 0, 0, PM_NOREMOVE );  /* make sure we have a message queue */
+    PeekMessageA( &msg, 0, 0, 0, PM_NOREMOVE );  /* make sure we have a message queue */
 
     count = 0;
     ret = EnumThreadWindows( GetCurrentThreadId(), enum_proc, (LPARAM)&count );
@@ -699,25 +750,25 @@ static void test_enum_thread_windows(void)
     CloseHandle( handle );
 }
 
+static struct wm_gettext_override_data
+{
+    BOOL   enabled; /* when 1 bypasses default procedure */
+    char  *buff;    /* expected text buffer pointer */
+    WCHAR *buffW;   /* same, for W test */
+} g_wm_gettext_override;
+
 static LRESULT WINAPI main_window_procA(HWND hwnd, UINT msg, WPARAM wparam, LPARAM lparam)
 {
     switch (msg)
     {
        case WM_GETMINMAXINFO:
        {
-           MINMAXINFO* minmax = (MINMAXINFO *)lparam;
-
-           trace("WM_GETMINMAXINFO: hwnd %p, %08lx, %08lx\n", hwnd, wparam, lparam);
-            dump_minmax_info( minmax );
            SetWindowLongPtrA(hwnd, GWLP_USERDATA, 0x20031021);
            break;
        }
        case WM_WINDOWPOSCHANGING:
        {
            WINDOWPOS *winpos = (WINDOWPOS *)lparam;
-           trace("main: WM_WINDOWPOSCHANGING %p after %p, x %d, y %d, cx %d, cy %d flags %08x\n",
-                  winpos->hwnd, winpos->hwndInsertAfter,
-                  winpos->x, winpos->y, winpos->cx, winpos->cy, winpos->flags);
            if (!(winpos->flags & SWP_NOMOVE))
            {
                ok(winpos->x >= -32768 && winpos->x <= 32767, "bad winpos->x %d\n", winpos->x);
@@ -739,9 +790,6 @@ static LRESULT WINAPI main_window_procA(HWND hwnd, UINT msg, WPARAM wparam, LPAR
        {
             RECT rc1, rc2;
            WINDOWPOS *winpos = (WINDOWPOS *)lparam;
-           trace("main: WM_WINDOWPOSCHANGED %p after %p, x %d, y %d, cx %d, cy %d flags %08x\n",
-                  winpos->hwnd, winpos->hwndInsertAfter,
-                  winpos->x, winpos->y, winpos->cx, winpos->cy, winpos->flags);
            ok(winpos->x >= -32768 && winpos->x <= 32767, "bad winpos->x %d\n", winpos->x);
            ok(winpos->y >= -32768 && winpos->y <= 32767, "bad winpos->y %d\n", winpos->y);
 
@@ -775,10 +823,6 @@ static LRESULT WINAPI main_window_procA(HWND hwnd, UINT msg, WPARAM wparam, LPAR
            BOOL got_getminmaxinfo = GetWindowLongPtrA(hwnd, GWLP_USERDATA) == 0x20031021;
            CREATESTRUCTA *cs = (CREATESTRUCTA *)lparam;
 
-            trace("WM_NCCREATE: hwnd %p, parent %p, style %08x\n", hwnd, cs->hwndParent, cs->style);
-           if (got_getminmaxinfo)
-               trace("%p got WM_GETMINMAXINFO\n", hwnd);
-
            if ((cs->style & WS_THICKFRAME) || !(cs->style & (WS_POPUP | WS_CHILD)))
                ok(got_getminmaxinfo, "main: WM_GETMINMAXINFO should have been received before WM_NCCREATE\n");
            else
@@ -792,6 +836,42 @@ static LRESULT WINAPI main_window_procA(HWND hwnd, UINT msg, WPARAM wparam, LPAR
                 flush_events( FALSE );
             }
             break;
+        case WM_GETTEXT:
+            num_gettext_msgs++;
+            if (g_wm_gettext_override.enabled)
+            {
+                char *text = (char*)lparam;
+                ok(g_wm_gettext_override.buff == text, "expected buffer %p, got %p\n", g_wm_gettext_override.buff, text);
+                ok(*text == 0, "expected empty string buffer %x\n", *text);
+                return 0;
+            }
+            break;
+        case WM_SETTEXT:
+            num_settext_msgs++;
+            break;
+        case WM_ACTIVATEAPP:
+            if (wparam) app_activated = TRUE;
+            else app_deactivated = TRUE;
+            break;
+    }
+
+    return DefWindowProcA(hwnd, msg, wparam, lparam);
+}
+
+static LRESULT WINAPI main_window_procW(HWND hwnd, UINT msg, WPARAM wparam, LPARAM lparam)
+{
+    switch (msg)
+    {
+        case WM_GETTEXT:
+            num_gettext_msgs++;
+            if (g_wm_gettext_override.enabled)
+            {
+                WCHAR *text = (WCHAR*)lparam;
+                ok(g_wm_gettext_override.buffW == text, "expected buffer %p, got %p\n", g_wm_gettext_override.buffW, text);
+                ok(*text == 0, "expected empty string buffer %x\n", *text);
+                return 0;
+            }
+            break;
     }
 
     return DefWindowProcA(hwnd, msg, wparam, lparam);
@@ -803,10 +883,6 @@ static LRESULT WINAPI tool_window_procA(HWND hwnd, UINT msg, WPARAM wparam, LPAR
     {
        case WM_GETMINMAXINFO:
        {
-           MINMAXINFO* minmax = (MINMAXINFO *)lparam;
-
-           trace("hwnd %p, WM_GETMINMAXINFO, %08lx, %08lx\n", hwnd, wparam, lparam);
-            dump_minmax_info( minmax );
            SetWindowLongPtrA(hwnd, GWLP_USERDATA, 0x20031021);
            break;
        }
@@ -815,10 +891,6 @@ static LRESULT WINAPI tool_window_procA(HWND hwnd, UINT msg, WPARAM wparam, LPAR
            BOOL got_getminmaxinfo = GetWindowLongPtrA(hwnd, GWLP_USERDATA) == 0x20031021;
            CREATESTRUCTA *cs = (CREATESTRUCTA *)lparam;
 
-            trace("WM_NCCREATE: hwnd %p, parent %p, style %08x\n", hwnd, cs->hwndParent, cs->style);
-           if (got_getminmaxinfo)
-               trace("%p got WM_GETMINMAXINFO\n", hwnd);
-
            if ((cs->style & WS_THICKFRAME) || !(cs->style & (WS_POPUP | WS_CHILD)))
                ok(got_getminmaxinfo, "tool: WM_GETMINMAXINFO should have been received before WM_NCCREATE\n");
            else
@@ -830,8 +902,11 @@ static LRESULT WINAPI tool_window_procA(HWND hwnd, UINT msg, WPARAM wparam, LPAR
     return DefWindowProcA(hwnd, msg, wparam, lparam);
 }
 
+static const WCHAR mainclassW[] = {'M','a','i','n','W','i','n','d','o','w','C','l','a','s','s','W',0};
+
 static BOOL RegisterWindowClasses(void)
 {
+    WNDCLASSW clsW;
     WNDCLASSA cls;
 
     cls.style = CS_DBLCLKS;
@@ -840,20 +915,33 @@ static BOOL RegisterWindowClasses(void)
     cls.cbWndExtra = 0;
     cls.hInstance = GetModuleHandleA(0);
     cls.hIcon = 0;
-    cls.hCursor = LoadCursorA(0, IDC_ARROW);
+    cls.hCursor = LoadCursorA(0, (LPCSTR)IDC_ARROW);
     cls.hbrBackground = GetStockObject(WHITE_BRUSH);
     cls.lpszMenuName = NULL;
     cls.lpszClassName = "MainWindowClass";
 
     if(!RegisterClassA(&cls)) return FALSE;
 
+    clsW.style = CS_DBLCLKS;
+    clsW.lpfnWndProc = main_window_procW;
+    clsW.cbClsExtra = 0;
+    clsW.cbWndExtra = 0;
+    clsW.hInstance = GetModuleHandleA(0);
+    clsW.hIcon = 0;
+    clsW.hCursor = LoadCursorA(0, (LPCSTR)IDC_ARROW);
+    clsW.hbrBackground = GetStockObject(WHITE_BRUSH);
+    clsW.lpszMenuName = NULL;
+    clsW.lpszClassName = mainclassW;
+
+    if(!RegisterClassW(&clsW)) return FALSE;
+
     cls.style = 0;
     cls.lpfnWndProc = tool_window_procA;
     cls.cbClsExtra = 0;
     cls.cbWndExtra = 0;
     cls.hInstance = GetModuleHandleA(0);
     cls.hIcon = 0;
-    cls.hCursor = LoadCursorA(0, IDC_ARROW);
+    cls.hCursor = LoadCursorA(0, (LPCSTR)IDC_ARROW);
     cls.hbrBackground = GetStockObject(WHITE_BRUSH);
     cls.lpszMenuName = NULL;
     cls.lpszClassName = "ToolWindowClass";
@@ -895,14 +983,15 @@ static void verify_window_info(const char *hook, HWND hwnd, const WINDOWINFO *in
     /* win2k and XP return broken border info in GetWindowInfo most of
      * the time, so there is no point in testing it.
      */
-#if 0
+if (0)
+{
     UINT border;
     ok(info->cxWindowBorders == (unsigned)(rcClient.left - rcWindow.left),
        "wrong cxWindowBorders %d != %d\n", info->cxWindowBorders, rcClient.left - rcWindow.left);
     border = min(rcWindow.bottom - rcClient.bottom, rcClient.top - rcWindow.top);
     ok(info->cyWindowBorders == border,
        "wrong cyWindowBorders %d != %d\n", info->cyWindowBorders, border);
-#endif
+}
     ok(info->atomWindowType == GetClassLongA(hwnd, GCW_ATOM), "wrong atomWindowType for %p in hook %s\n",
        hwnd, hook);
     ok(info->wCreatorVersion == 0x0400 /* NT4, Win2000, XP, Win2003 */ ||
@@ -925,6 +1014,52 @@ static void FixedAdjustWindowRectEx(RECT* rc, LONG style, BOOL menu, LONG exstyl
        rc->bottom += GetSystemMetrics(SM_CYHSCROLL);
 }
 
+/* reimplement it to check that the Wine algorithm gives the correct result */
+static void wine_AdjustWindowRectEx( RECT *rect, LONG style, BOOL menu, LONG exStyle )
+{
+    int adjust;
+
+    if ((exStyle & (WS_EX_STATICEDGE|WS_EX_DLGMODALFRAME)) ==
+        WS_EX_STATICEDGE)
+    {
+        adjust = 1; /* for the outer frame always present */
+    }
+    else
+    {
+        adjust = 0;
+        if ((exStyle & WS_EX_DLGMODALFRAME) ||
+            (style & (WS_THICKFRAME|WS_DLGFRAME))) adjust = 2; /* outer */
+    }
+    if (style & WS_THICKFRAME)
+        adjust += GetSystemMetrics(SM_CXFRAME) - GetSystemMetrics(SM_CXDLGFRAME); /* The resize border */
+    if ((style & (WS_BORDER|WS_DLGFRAME)) ||
+        (exStyle & WS_EX_DLGMODALFRAME))
+        adjust++; /* The other border */
+
+    InflateRect (rect, adjust, adjust);
+
+    if ((style & WS_CAPTION) == WS_CAPTION)
+    {
+        if (exStyle & WS_EX_TOOLWINDOW)
+            rect->top -= GetSystemMetrics(SM_CYSMCAPTION);
+        else
+            rect->top -= GetSystemMetrics(SM_CYCAPTION);
+    }
+    if (menu) rect->top -= GetSystemMetrics(SM_CYMENU);
+
+    if (exStyle & WS_EX_CLIENTEDGE)
+        InflateRect(rect, GetSystemMetrics(SM_CXEDGE), GetSystemMetrics(SM_CYEDGE));
+
+    if (style & WS_VSCROLL)
+    {
+        if((exStyle & WS_EX_LEFTSCROLLBAR) != 0)
+            rect->left  -= GetSystemMetrics(SM_CXVSCROLL);
+        else
+            rect->right += GetSystemMetrics(SM_CXVSCROLL);
+    }
+    if (style & WS_HSCROLL) rect->bottom += GetSystemMetrics(SM_CYHSCROLL);
+}
+
 static void test_nonclient_area(HWND hwnd)
 {
     DWORD style, exstyle;
@@ -952,6 +1087,14 @@ static void test_nonclient_area(HWND hwnd)
        style, exstyle, menu, rc_window.left, rc_window.top, rc_window.right, rc_window.bottom,
        rc.left, rc.top, rc.right, rc.bottom);
 
+    CopyRect(&rc, &rc_client);
+    MapWindowPoints(hwnd, 0, (LPPOINT)&rc, 2);
+    wine_AdjustWindowRectEx(&rc, style, menu, exstyle);
+    ok(EqualRect(&rc, &rc_window),
+       "window rect does not match: style:exstyle=0x%08x:0x%08x, menu=%d, win=(%d,%d)-(%d,%d), calc=(%d,%d)-(%d,%d)\n",
+       style, exstyle, menu, rc_window.left, rc_window.top, rc_window.right, rc_window.bottom,
+       rc.left, rc.top, rc.right, rc.bottom);
+
 
     CopyRect(&rc, &rc_window);
     DefWindowProcA(hwnd, WM_NCCALCSIZE, 0, (LPARAM)&rc);
@@ -1116,7 +1259,7 @@ static void test_shell_window(void)
     }
 
     shellWindow = GetShellWindow();
-    hinst = GetModuleHandle(0);
+    hinst = GetModuleHandleA(NULL);
     hUser32 = GetModuleHandleA("user32");
 
     SetShellWindow = (void *)GetProcAddress(hUser32, "SetShellWindow");
@@ -1151,7 +1294,7 @@ static void test_shell_window(void)
         CloseHandle(hProcess);
     }
 
-    hwnd1 = CreateWindowEx(0, TEXT("#32770"), TEXT("TEST1"), WS_OVERLAPPEDWINDOW/*|WS_VISIBLE*/, 100, 100, 300, 200, 0, 0, hinst, 0);
+    hwnd1 = CreateWindowExA(0, "#32770", "TEST1", WS_OVERLAPPEDWINDOW/*|WS_VISIBLE*/, 100, 100, 300, 200, 0, 0, hinst, 0);
     trace("created window 1: %p\n", hwnd1);
 
     ret = SetShellWindow(hwnd1);
@@ -1172,22 +1315,22 @@ static void test_shell_window(void)
     /* passes on Win XP, but not on Win98
     ok(!ret, "third call to SetShellWindow(hwnd1)\n"); */
 
-    SetWindowLong(hwnd1, GWL_EXSTYLE, GetWindowLong(hwnd1,GWL_EXSTYLE)|WS_EX_TOPMOST);
-    ret = (GetWindowLong(hwnd1,GWL_EXSTYLE) & WS_EX_TOPMOST) != 0;
+    SetWindowLongA(hwnd1, GWL_EXSTYLE, GetWindowLongA(hwnd1,GWL_EXSTYLE)|WS_EX_TOPMOST);
+    ret = (GetWindowLongA(hwnd1,GWL_EXSTYLE) & WS_EX_TOPMOST) != 0;
     ok(!ret, "SetWindowExStyle(hwnd1, WS_EX_TOPMOST)\n");
 
     ret = DestroyWindow(hwnd1);
     ok(ret, "DestroyWindow(hwnd1)\n");
 
-    hwnd2 = CreateWindowEx(WS_EX_TOPMOST, TEXT("#32770"), TEXT("TEST2"), WS_OVERLAPPEDWINDOW/*|WS_VISIBLE*/, 150, 250, 300, 200, 0, 0, hinst, 0);
+    hwnd2 = CreateWindowExA(WS_EX_TOPMOST, "#32770", "TEST2", WS_OVERLAPPEDWINDOW/*|WS_VISIBLE*/, 150, 250, 300, 200, 0, 0, hinst, 0);
     trace("created window 2: %p\n", hwnd2);
     ret = SetShellWindow(hwnd2);
     ok(!ret, "SetShellWindow(hwnd2) with WS_EX_TOPMOST\n");
 
-    hwnd3 = CreateWindowEx(0, TEXT("#32770"), TEXT("TEST3"), WS_OVERLAPPEDWINDOW/*|WS_VISIBLE*/, 200, 400, 300, 200, 0, 0, hinst, 0);
+    hwnd3 = CreateWindowExA(0, "#32770", "TEST3", WS_OVERLAPPEDWINDOW/*|WS_VISIBLE*/, 200, 400, 300, 200, 0, 0, hinst, 0);
     trace("created window 3: %p\n", hwnd3);
 
-    hwnd4 = CreateWindowEx(0, TEXT("#32770"), TEXT("TEST4"), WS_OVERLAPPEDWINDOW/*|WS_VISIBLE*/, 250, 500, 300, 200, 0, 0, hinst, 0);
+    hwnd4 = CreateWindowExA(0, "#32770", "TEST4", WS_OVERLAPPEDWINDOW/*|WS_VISIBLE*/, 250, 500, 300, 200, 0, 0, hinst, 0);
     trace("created window 4: %p\n", hwnd4);
 
     nextWnd = GetWindow(hwnd4, GW_HWNDNEXT);
@@ -1212,7 +1355,7 @@ static void test_shell_window(void)
     shellWindow = GetShellWindow();
     ok(shellWindow==hwnd4, "wrong shell window: %p - expected hwnd4\n", shellWindow);
 
-    hwnd5 = CreateWindowEx(0, TEXT("#32770"), TEXT("TEST5"), WS_OVERLAPPEDWINDOW/*|WS_VISIBLE*/, 300, 600, 300, 200, 0, 0, hinst, 0);
+    hwnd5 = CreateWindowExA(0, "#32770", "TEST5", WS_OVERLAPPEDWINDOW/*|WS_VISIBLE*/, 300, 600, 300, 200, 0, 0, hinst, 0);
     trace("created window 5: %p\n", hwnd5);
     ret = SetWindowPos(hwnd4, hwnd5, 0, 0, 0, 0, SWP_NOSIZE|SWP_NOMOVE);
     ok(ret, "SetWindowPos(hwnd4, hwnd5)\n");
@@ -1237,7 +1380,7 @@ static char mdi_lParam_test_message[] = "just a test string";
 static void test_MDI_create(HWND parent, HWND mdi_client, INT_PTR first_id)
 {
     MDICREATESTRUCTA mdi_cs;
-    HWND mdi_child;
+    HWND mdi_child, hwnd, exp_hwnd;
     INT_PTR id;
     static const WCHAR classW[] = {'M','D','I','_','c','h','i','l','d','_','C','l','a','s','s','_','1',0};
     static const WCHAR titleW[] = {'M','D','I',' ','c','h','i','l','d',0};
@@ -1245,7 +1388,7 @@ static void test_MDI_create(HWND parent, HWND mdi_client, INT_PTR first_id)
 
     mdi_cs.szClass = "MDI_child_Class_1";
     mdi_cs.szTitle = "MDI child";
-    mdi_cs.hOwner = GetModuleHandle(0);
+    mdi_cs.hOwner = GetModuleHandleA(NULL);
     mdi_cs.x = CW_USEDEFAULT;
     mdi_cs.y = CW_USEDEFAULT;
     mdi_cs.cx = CW_USEDEFAULT;
@@ -1256,6 +1399,9 @@ static void test_MDI_create(HWND parent, HWND mdi_client, INT_PTR first_id)
     ok(mdi_child != 0, "MDI child creation failed\n");
     id = GetWindowLongPtrA(mdi_child, GWLP_ID);
     ok(id == first_id, "wrong child id %ld\n", id);
+    hwnd = (HWND)SendMessageA(mdi_client, WM_MDIGETACTIVE, 0, 0);
+    exp_hwnd = (GetWindowLongW(mdi_child, GWL_STYLE) & WS_VISIBLE) ? mdi_child : 0;
+    ok(hwnd == exp_hwnd, "WM_MDIGETACTIVE should return %p, got %p\n", exp_hwnd, hwnd);
     SendMessageA(mdi_client, WM_MDIDESTROY, (WPARAM)mdi_child, 0);
     ok(!IsWindow(mdi_child), "WM_MDIDESTROY failed\n");
 
@@ -1264,6 +1410,8 @@ static void test_MDI_create(HWND parent, HWND mdi_client, INT_PTR first_id)
     ok(mdi_child != 0, "MDI child creation failed\n");
     id = GetWindowLongPtrA(mdi_child, GWLP_ID);
     ok(id == first_id, "wrong child id %ld\n", id);
+    hwnd = (HWND)SendMessageA(mdi_client, WM_MDIGETACTIVE, 0, 0);
+    ok(!hwnd, "WM_MDIGETACTIVE should return 0, got %p\n", hwnd);
     SendMessageA(mdi_client, WM_MDIDESTROY, (WPARAM)mdi_child, 0);
     ok(!IsWindow(mdi_child), "WM_MDIDESTROY failed\n");
 
@@ -1278,6 +1426,8 @@ static void test_MDI_create(HWND parent, HWND mdi_client, INT_PTR first_id)
         ok(mdi_child != 0, "MDI child creation failed\n");
         id = GetWindowLongPtrA(mdi_child, GWLP_ID);
         ok(id == first_id, "wrong child id %ld\n", id);
+        hwnd = (HWND)SendMessageA(mdi_client, WM_MDIGETACTIVE, 0, 0);
+        ok(!hwnd, "WM_MDIGETACTIVE should return 0, got %p\n", hwnd);
         SendMessageA(mdi_client, WM_MDIDESTROY, (WPARAM)mdi_child, 0);
         ok(!IsWindow(mdi_child), "WM_MDIDESTROY failed\n");
     }
@@ -1300,6 +1450,9 @@ static void test_MDI_create(HWND parent, HWND mdi_client, INT_PTR first_id)
     {
         id = GetWindowLongPtrA(mdi_child, GWLP_ID);
         ok(id == first_id, "wrong child id %ld\n", id);
+        hwnd = (HWND)SendMessageA(mdi_client, WM_MDIGETACTIVE, 0, 0);
+        exp_hwnd = (GetWindowLongW(mdi_child, GWL_STYLE) & WS_VISIBLE) ? mdi_child : 0;
+        ok(hwnd == exp_hwnd, "WM_MDIGETACTIVE should return %p, got %p\n", exp_hwnd, hwnd);
         SendMessageA(mdi_client, WM_MDIDESTROY, (WPARAM)mdi_child, 0);
         ok(!IsWindow(mdi_child), "WM_MDIDESTROY failed\n");
     }
@@ -1308,11 +1461,14 @@ static void test_MDI_create(HWND parent, HWND mdi_client, INT_PTR first_id)
                                  0,
                                  CW_USEDEFAULT, CW_USEDEFAULT,
                                  CW_USEDEFAULT, CW_USEDEFAULT,
-                                 mdi_client, GetModuleHandle(0),
+                                 mdi_client, GetModuleHandleA(NULL),
                                  (LPARAM)mdi_lParam_test_message);
     ok(mdi_child != 0, "MDI child creation failed\n");
     id = GetWindowLongPtrA(mdi_child, GWLP_ID);
     ok(id == first_id, "wrong child id %ld\n", id);
+    hwnd = (HWND)SendMessageA(mdi_client, WM_MDIGETACTIVE, 0, 0);
+    exp_hwnd = (GetWindowLongW(mdi_child, GWL_STYLE) & WS_VISIBLE) ? mdi_child : 0;
+    ok(hwnd == exp_hwnd, "WM_MDIGETACTIVE should return %p, got %p\n", exp_hwnd, hwnd);
     SendMessageA(mdi_client, WM_MDIDESTROY, (WPARAM)mdi_child, 0);
     ok(!IsWindow(mdi_child), "WM_MDIDESTROY failed\n");
 
@@ -1320,11 +1476,13 @@ static void test_MDI_create(HWND parent, HWND mdi_client, INT_PTR first_id)
                                  0x7fffffff, /* without WS_POPUP */
                                  CW_USEDEFAULT, CW_USEDEFAULT,
                                  CW_USEDEFAULT, CW_USEDEFAULT,
-                                 mdi_client, GetModuleHandle(0),
+                                 mdi_client, GetModuleHandleA(NULL),
                                  (LPARAM)mdi_lParam_test_message);
     ok(mdi_child != 0, "MDI child creation failed\n");
     id = GetWindowLongPtrA(mdi_child, GWLP_ID);
     ok(id == first_id, "wrong child id %ld\n", id);
+    hwnd = (HWND)SendMessageA(mdi_client, WM_MDIGETACTIVE, 0, 0);
+    ok(!hwnd, "WM_MDIGETACTIVE should return 0, got %p\n", hwnd);
     SendMessageA(mdi_client, WM_MDIDESTROY, (WPARAM)mdi_child, 0);
     ok(!IsWindow(mdi_child), "WM_MDIDESTROY failed\n");
 
@@ -1332,7 +1490,7 @@ static void test_MDI_create(HWND parent, HWND mdi_client, INT_PTR first_id)
                                  0xffffffff, /* with WS_POPUP */
                                  CW_USEDEFAULT, CW_USEDEFAULT,
                                  CW_USEDEFAULT, CW_USEDEFAULT,
-                                 mdi_client, GetModuleHandle(0),
+                                 mdi_client, GetModuleHandleA(NULL),
                                  (LPARAM)mdi_lParam_test_message);
     if (GetWindowLongA(mdi_client, GWL_STYLE) & MDIS_ALLCHILDSTYLES)
     {
@@ -1343,6 +1501,8 @@ static void test_MDI_create(HWND parent, HWND mdi_client, INT_PTR first_id)
         ok(mdi_child != 0, "MDI child creation failed\n");
         id = GetWindowLongPtrA(mdi_child, GWLP_ID);
         ok(id == first_id, "wrong child id %ld\n", id);
+        hwnd = (HWND)SendMessageA(mdi_client, WM_MDIGETACTIVE, 0, 0);
+        ok(!hwnd, "WM_MDIGETACTIVE should return 0, got %p\n", hwnd);
         SendMessageA(mdi_client, WM_MDIDESTROY, (WPARAM)mdi_child, 0);
         ok(!IsWindow(mdi_child), "WM_MDIDESTROY failed\n");
     }
@@ -1353,7 +1513,7 @@ static void test_MDI_create(HWND parent, HWND mdi_client, INT_PTR first_id)
                                  0,
                                  CW_USEDEFAULT, CW_USEDEFAULT,
                                  CW_USEDEFAULT, CW_USEDEFAULT,
-                                 mdi_client, GetModuleHandle(0),
+                                 mdi_client, GetModuleHandleA(NULL),
                                  (LPARAM)mdi_lParam_test_message);
     if (!mdi_child)
     {
@@ -1366,6 +1526,9 @@ static void test_MDI_create(HWND parent, HWND mdi_client, INT_PTR first_id)
     {
         id = GetWindowLongPtrA(mdi_child, GWLP_ID);
         ok(id == first_id, "wrong child id %ld\n", id);
+        hwnd = (HWND)SendMessageA(mdi_client, WM_MDIGETACTIVE, 0, 0);
+        exp_hwnd = (GetWindowLongW(mdi_child, GWL_STYLE) & WS_VISIBLE) ? mdi_child : 0;
+        ok(hwnd == exp_hwnd, "WM_MDIGETACTIVE should return %p, got %p\n", exp_hwnd, hwnd);
         SendMessageA(mdi_client, WM_MDIDESTROY, (WPARAM)mdi_child, 0);
         ok(!IsWindow(mdi_child), "WM_MDIDESTROY failed\n");
     }
@@ -1374,11 +1537,14 @@ static void test_MDI_create(HWND parent, HWND mdi_client, INT_PTR first_id)
                                 0,
                                 CW_USEDEFAULT, CW_USEDEFAULT,
                                 CW_USEDEFAULT, CW_USEDEFAULT,
-                                mdi_client, 0, GetModuleHandle(0),
+                                mdi_client, 0, GetModuleHandleA(NULL),
                                 mdi_lParam_test_message);
     ok(mdi_child != 0, "MDI child creation failed\n");
     id = GetWindowLongPtrA(mdi_child, GWLP_ID);
     ok(id == first_id, "wrong child id %ld\n", id);
+    hwnd = (HWND)SendMessageA(mdi_client, WM_MDIGETACTIVE, 0, 0);
+    exp_hwnd = (GetWindowLongW(mdi_child, GWL_STYLE) & WS_VISIBLE) ? mdi_child : 0;
+    ok(hwnd == exp_hwnd, "WM_MDIGETACTIVE should return %p, got %p\n", exp_hwnd, hwnd);
     SendMessageA(mdi_client, WM_MDIDESTROY, (WPARAM)mdi_child, 0);
     ok(!IsWindow(mdi_child), "WM_MDIDESTROY failed\n");
 
@@ -1386,11 +1552,13 @@ static void test_MDI_create(HWND parent, HWND mdi_client, INT_PTR first_id)
                                 0x7fffffff, /* without WS_POPUP */
                                 CW_USEDEFAULT, CW_USEDEFAULT,
                                 CW_USEDEFAULT, CW_USEDEFAULT,
-                                mdi_client, 0, GetModuleHandle(0),
+                                mdi_client, 0, GetModuleHandleA(NULL),
                                 mdi_lParam_test_message);
     ok(mdi_child != 0, "MDI child creation failed\n");
     id = GetWindowLongPtrA(mdi_child, GWLP_ID);
     ok(id == first_id, "wrong child id %ld\n", id);
+    hwnd = (HWND)SendMessageA(mdi_client, WM_MDIGETACTIVE, 0, 0);
+    ok(!hwnd, "WM_MDIGETACTIVE should return 0, got %p\n", hwnd);
     SendMessageA(mdi_client, WM_MDIDESTROY, (WPARAM)mdi_child, 0);
     ok(!IsWindow(mdi_child), "WM_MDIDESTROY failed\n");
 
@@ -1398,7 +1566,7 @@ static void test_MDI_create(HWND parent, HWND mdi_client, INT_PTR first_id)
                                 0xffffffff, /* with WS_POPUP */
                                 CW_USEDEFAULT, CW_USEDEFAULT,
                                 CW_USEDEFAULT, CW_USEDEFAULT,
-                                mdi_client, 0, GetModuleHandle(0),
+                                mdi_client, 0, GetModuleHandleA(NULL),
                                 mdi_lParam_test_message);
     if (GetWindowLongA(mdi_client, GWL_STYLE) & MDIS_ALLCHILDSTYLES)
     {
@@ -1409,6 +1577,8 @@ static void test_MDI_create(HWND parent, HWND mdi_client, INT_PTR first_id)
         ok(mdi_child != 0, "MDI child creation failed\n");
         id = GetWindowLongPtrA(mdi_child, GWLP_ID);
         ok(id == first_id, "wrong child id %ld\n", id);
+        hwnd = (HWND)SendMessageA(mdi_client, WM_MDIGETACTIVE, 0, 0);
+        ok(!hwnd, "WM_MDIGETACTIVE should return 0, got %p\n", hwnd);
         SendMessageA(mdi_client, WM_MDIDESTROY, (WPARAM)mdi_child, 0);
         ok(!IsWindow(mdi_child), "WM_MDIDESTROY failed\n");
     }
@@ -1419,7 +1589,7 @@ static void test_MDI_create(HWND parent, HWND mdi_client, INT_PTR first_id)
                                 0,
                                 CW_USEDEFAULT, CW_USEDEFAULT,
                                 CW_USEDEFAULT, CW_USEDEFAULT,
-                                mdi_client, 0, GetModuleHandle(0),
+                                mdi_client, 0, GetModuleHandleA(NULL),
                                 mdi_lParam_test_message);
     if (!mdi_child)
     {
@@ -1432,6 +1602,9 @@ static void test_MDI_create(HWND parent, HWND mdi_client, INT_PTR first_id)
     {
         id = GetWindowLongPtrA(mdi_child, GWLP_ID);
         ok(id == first_id, "wrong child id %ld\n", id);
+        hwnd = (HWND)SendMessageA(mdi_client, WM_MDIGETACTIVE, 0, 0);
+        exp_hwnd = (GetWindowLongW(mdi_child, GWL_STYLE) & WS_VISIBLE) ? mdi_child : 0;
+        ok(hwnd == exp_hwnd, "WM_MDIGETACTIVE should return %p, got %p\n", exp_hwnd, hwnd);
         SendMessageA(mdi_client, WM_MDIDESTROY, (WPARAM)mdi_child, 0);
         ok(!IsWindow(mdi_child), "WM_MDIDESTROY failed\n");
     }
@@ -1443,7 +1616,7 @@ static void test_MDI_create(HWND parent, HWND mdi_client, INT_PTR first_id)
                                 WS_CHILD,
                                 CW_USEDEFAULT, CW_USEDEFAULT,
                                 CW_USEDEFAULT, CW_USEDEFAULT,
-                                parent, 0, GetModuleHandle(0),
+                                parent, 0, GetModuleHandleA(NULL),
                                 mdi_lParam_test_message);
         ok(!mdi_child, "WS_EX_MDICHILD with a not MDIClient parent should fail\n");
     }
@@ -1452,22 +1625,26 @@ static void test_MDI_create(HWND parent, HWND mdi_client, INT_PTR first_id)
                                 WS_CHILD, /* without WS_POPUP */
                                 CW_USEDEFAULT, CW_USEDEFAULT,
                                 CW_USEDEFAULT, CW_USEDEFAULT,
-                                mdi_client, 0, GetModuleHandle(0),
+                                mdi_client, 0, GetModuleHandleA(NULL),
                                 mdi_lParam_test_message);
     ok(mdi_child != 0, "MDI child creation failed\n");
     id = GetWindowLongPtrA(mdi_child, GWLP_ID);
     ok(id == 0, "wrong child id %ld\n", id);
+    hwnd = (HWND)SendMessageA(mdi_client, WM_MDIGETACTIVE, 0, 0);
+    ok(!hwnd, "WM_MDIGETACTIVE should return 0, got %p\n", hwnd);
     DestroyWindow(mdi_child);
 
     mdi_child = CreateWindowExA(0, "MDI_child_Class_2", "MDI child",
                                 WS_CHILD | WS_POPUP, /* with WS_POPUP */
                                 CW_USEDEFAULT, CW_USEDEFAULT,
                                 CW_USEDEFAULT, CW_USEDEFAULT,
-                                mdi_client, 0, GetModuleHandle(0),
+                                mdi_client, 0, GetModuleHandleA(NULL),
                                 mdi_lParam_test_message);
     ok(mdi_child != 0, "MDI child creation failed\n");
     id = GetWindowLongPtrA(mdi_child, GWLP_ID);
     ok(id == 0, "wrong child id %ld\n", id);
+    hwnd = (HWND)SendMessageA(mdi_client, WM_MDIGETACTIVE, 0, 0);
+    ok(!hwnd, "WM_MDIGETACTIVE should return 0, got %p\n", hwnd);
     DestroyWindow(mdi_child);
 
     /* maximized child */
@@ -1475,11 +1652,13 @@ static void test_MDI_create(HWND parent, HWND mdi_client, INT_PTR first_id)
                                 WS_CHILD | WS_MAXIMIZE,
                                 CW_USEDEFAULT, CW_USEDEFAULT,
                                 CW_USEDEFAULT, CW_USEDEFAULT,
-                                mdi_client, 0, GetModuleHandle(0),
+                                mdi_client, 0, GetModuleHandleA(NULL),
                                 mdi_lParam_test_message);
     ok(mdi_child != 0, "MDI child creation failed\n");
     id = GetWindowLongPtrA(mdi_child, GWLP_ID);
     ok(id == 0, "wrong child id %ld\n", id);
+    hwnd = (HWND)SendMessageA(mdi_client, WM_MDIGETACTIVE, 0, 0);
+    ok(!hwnd, "WM_MDIGETACTIVE should return 0, got %p\n", hwnd);
     DestroyWindow(mdi_child);
 
     trace("Creating maximized child with a caption\n");
@@ -1487,11 +1666,13 @@ static void test_MDI_create(HWND parent, HWND mdi_client, INT_PTR first_id)
                                 WS_CHILD | WS_MAXIMIZE | WS_CAPTION,
                                 CW_USEDEFAULT, CW_USEDEFAULT,
                                 CW_USEDEFAULT, CW_USEDEFAULT,
-                                mdi_client, 0, GetModuleHandle(0),
+                                mdi_client, 0, GetModuleHandleA(NULL),
                                 mdi_lParam_test_message);
     ok(mdi_child != 0, "MDI child creation failed\n");
     id = GetWindowLongPtrA(mdi_child, GWLP_ID);
     ok(id == 0, "wrong child id %ld\n", id);
+    hwnd = (HWND)SendMessageA(mdi_client, WM_MDIGETACTIVE, 0, 0);
+    ok(!hwnd, "WM_MDIGETACTIVE should return 0, got %p\n", hwnd);
     DestroyWindow(mdi_child);
 
     trace("Creating maximized child with a caption and a thick frame\n");
@@ -1499,11 +1680,13 @@ static void test_MDI_create(HWND parent, HWND mdi_client, INT_PTR first_id)
                                 WS_CHILD | WS_MAXIMIZE | WS_CAPTION | WS_THICKFRAME,
                                 CW_USEDEFAULT, CW_USEDEFAULT,
                                 CW_USEDEFAULT, CW_USEDEFAULT,
-                                mdi_client, 0, GetModuleHandle(0),
+                                mdi_client, 0, GetModuleHandleA(NULL),
                                 mdi_lParam_test_message);
     ok(mdi_child != 0, "MDI child creation failed\n");
     id = GetWindowLongPtrA(mdi_child, GWLP_ID);
     ok(id == 0, "wrong child id %ld\n", id);
+    hwnd = (HWND)SendMessageA(mdi_client, WM_MDIGETACTIVE, 0, 0);
+    ok(!hwnd, "WM_MDIGETACTIVE should return 0, got %p\n", hwnd);
     DestroyWindow(mdi_child);
 }
 
@@ -1543,7 +1726,7 @@ static void test_MDI_child_stack(HWND mdi_client)
             child_4, child_3, child_2, child_1);
 
     trace("Activate child next to %p\n", child_3);
-    SendMessage(mdi_client, WM_MDINEXT, (WPARAM)child_3, 0);
+    SendMessageA(mdi_client, WM_MDINEXT, (WPARAM)child_3, 0);
 
     stack[0] = (HWND)SendMessageA(mdi_client, WM_MDIGETACTIVE, 0, 0);
     stack[1] = GetWindow(stack[0], GW_HWNDNEXT);
@@ -1555,7 +1738,7 @@ static void test_MDI_child_stack(HWND mdi_client)
             child_2, child_4, child_1, child_3, stack[0], stack[1], stack[2], stack[3]);
 
     trace("Activate child previous to %p\n", child_1);
-    SendMessage(mdi_client, WM_MDINEXT, (WPARAM)child_1, 1);
+    SendMessageA(mdi_client, WM_MDINEXT, (WPARAM)child_1, 1);
 
     stack[0] = (HWND)SendMessageA(mdi_client, WM_MDIGETACTIVE, 0, 0);
     stack[1] = GetWindow(stack[0], GW_HWNDNEXT);
@@ -1664,12 +1847,7 @@ static LRESULT WINAPI mdi_child_wnd_proc_1(HWND hwnd, UINT msg, WPARAM wparam, L
             style = GetWindowLongA(hwnd, GWL_STYLE);
             exstyle = GetWindowLongA(hwnd, GWL_EXSTYLE);
 
-            GetWindowRect(client, &rc);
-            trace("MDI client %p window size = (%d x %d)\n", client, rc.right-rc.left, rc.bottom-rc.top);
             GetClientRect(client, &rc);
-            trace("MDI client %p client size = (%d x %d)\n", client, rc.right, rc.bottom);
-            trace("screen size: %d x %d\n", GetSystemMetrics(SM_CXSCREEN),
-                                            GetSystemMetrics(SM_CYSCREEN));
 
             GetClientRect(client, &rc);
             if ((style & WS_CAPTION) == WS_CAPTION)
@@ -1821,51 +1999,7 @@ static LRESULT WINAPI mdi_main_wnd_procA(HWND hwnd, UINT msg, WPARAM wparam, LPA
     switch (msg)
     {
         case WM_CREATE:
-        {
-            CLIENTCREATESTRUCT client_cs;
-            RECT rc;
-
-            GetClientRect(hwnd, &rc);
-
-            client_cs.hWindowMenu = 0;
-            client_cs.idFirstChild = 1;
-
-            /* MDIClient without MDIS_ALLCHILDSTYLES */
-            mdi_client = CreateWindowExA(0, "mdiclient",
-                                         NULL,
-                                         WS_CHILD /*| WS_VISIBLE*/,
-                                          /* tests depend on a not zero MDIClient size */
-                                         0, 0, rc.right, rc.bottom,
-                                         hwnd, 0, GetModuleHandle(0),
-                                         &client_cs);
-            assert(mdi_client);
-            test_MDI_create(hwnd, mdi_client, client_cs.idFirstChild);
-            DestroyWindow(mdi_client);
-
-            /* MDIClient with MDIS_ALLCHILDSTYLES */
-            mdi_client = CreateWindowExA(0, "mdiclient",
-                                         NULL,
-                                         WS_CHILD | MDIS_ALLCHILDSTYLES /*| WS_VISIBLE*/,
-                                          /* tests depend on a not zero MDIClient size */
-                                         0, 0, rc.right, rc.bottom,
-                                         hwnd, 0, GetModuleHandle(0),
-                                         &client_cs);
-            assert(mdi_client);
-            test_MDI_create(hwnd, mdi_client, client_cs.idFirstChild);
-            DestroyWindow(mdi_client);
-
-            /* Test child window stack management */
-            mdi_client = CreateWindowExA(0, "mdiclient",
-                                         NULL,
-                                         WS_CHILD,
-                                         0, 0, rc.right, rc.bottom,
-                                         hwnd, 0, GetModuleHandle(0),
-                                         &client_cs);
-            assert(mdi_client);
-            test_MDI_child_stack(mdi_client);
-            DestroyWindow(mdi_client);
-            break;
-        }
+            return 1;
 
         case WM_WINDOWPOSCHANGED:
         {
@@ -1926,7 +2060,7 @@ static BOOL mdi_RegisterWindowClasses(void)
     cls.cbWndExtra = 0;
     cls.hInstance = GetModuleHandleA(0);
     cls.hIcon = 0;
-    cls.hCursor = LoadCursorA(0, IDC_ARROW);
+    cls.hCursor = LoadCursorA(0, (LPCSTR)IDC_ARROW);
     cls.hbrBackground = GetStockObject(WHITE_BRUSH);
     cls.lpszMenuName = NULL;
     cls.lpszClassName = "MDI_parent_Class";
@@ -1945,8 +2079,12 @@ static BOOL mdi_RegisterWindowClasses(void)
 
 static void test_mdi(void)
 {
-    HWND mdi_hwndMain;
-    /*MSG msg;*/
+    static const DWORD style[] = { 0, WS_HSCROLL, WS_VSCROLL, WS_HSCROLL | WS_VSCROLL };
+    HWND mdi_hwndMain, mdi_client;
+    CLIENTCREATESTRUCT client_cs;
+    RECT rc;
+    DWORD i;
+    MSG msg;
 
     if (!mdi_RegisterWindowClasses()) assert(0);
 
@@ -1955,8 +2093,180 @@ static void test_mdi(void)
                                    WS_MAXIMIZEBOX /*| WS_VISIBLE*/,
                                    100, 100, CW_USEDEFAULT, CW_USEDEFAULT,
                                    GetDesktopWindow(), 0,
-                                   GetModuleHandle(0), NULL);
+                                   GetModuleHandleA(NULL), NULL);
     assert(mdi_hwndMain);
+
+    GetClientRect(mdi_hwndMain, &rc);
+
+    client_cs.hWindowMenu = 0;
+    client_cs.idFirstChild = 1;
+
+    for (i = 0; i < sizeof(style)/sizeof(style[0]); i++)
+    {
+        HWND mdi_child;
+        SCROLLINFO si;
+        BOOL ret, gotit;
+
+        mdi_client = CreateWindowExA(0, "mdiclient", NULL,
+                                 WS_CHILD | style[i],
+                                 0, 0, rc.right, rc.bottom,
+                                 mdi_hwndMain, 0, 0, &client_cs);
+        ok(mdi_client != 0, "MDI client creation failed\n");
+
+        mdi_child = CreateWindowExA(WS_EX_MDICHILD, "MDI_child_Class_1", "MDI child",
+                                0,
+                                CW_USEDEFAULT, CW_USEDEFAULT,
+                                CW_USEDEFAULT, CW_USEDEFAULT,
+                                mdi_client, 0, 0,
+                                mdi_lParam_test_message);
+        ok(mdi_child != 0, "MDI child creation failed\n");
+
+        si.cbSize = sizeof(si);
+        si.fMask = SIF_ALL;
+        ret = GetScrollInfo(mdi_client, SB_HORZ, &si);
+        if (style[i] & (WS_HSCROLL | WS_VSCROLL))
+        {
+            ok(ret, "style %#x: GetScrollInfo(SB_HORZ) failed\n", style[i]);
+            ok(si.nPage == 0, "expected 0\n");
+            ok(si.nPos == 0, "expected 0\n");
+            ok(si.nTrackPos == 0, "expected 0\n");
+            ok(si.nMin == 0, "expected 0\n");
+            ok(si.nMax == 100, "expected 100\n");
+        }
+        else
+            ok(!ret, "style %#x: GetScrollInfo(SB_HORZ) should fail\n", style[i]);
+
+        ret = GetScrollInfo(mdi_client, SB_VERT, &si);
+        if (style[i] & (WS_HSCROLL | WS_VSCROLL))
+        {
+            ok(ret, "style %#x: GetScrollInfo(SB_VERT) failed\n", style[i]);
+            ok(si.nPage == 0, "expected 0\n");
+            ok(si.nPos == 0, "expected 0\n");
+            ok(si.nTrackPos == 0, "expected 0\n");
+            ok(si.nMin == 0, "expected 0\n");
+            ok(si.nMax == 100, "expected 100\n");
+        }
+        else
+            ok(!ret, "style %#x: GetScrollInfo(SB_VERT) should fail\n", style[i]);
+
+        SetWindowPos(mdi_child, 0, -100, -100, 0, 0, SWP_NOZORDER | SWP_NOACTIVATE | SWP_NOSIZE);
+
+        si.cbSize = sizeof(si);
+        si.fMask = SIF_ALL;
+        ret = GetScrollInfo(mdi_client, SB_HORZ, &si);
+        if (style[i] & (WS_HSCROLL | WS_VSCROLL))
+        {
+            ok(ret, "style %#x: GetScrollInfo(SB_HORZ) failed\n", style[i]);
+            ok(si.nPage == 0, "expected 0\n");
+            ok(si.nPos == 0, "expected 0\n");
+            ok(si.nTrackPos == 0, "expected 0\n");
+            ok(si.nMin == 0, "expected 0\n");
+            ok(si.nMax == 100, "expected 100\n");
+        }
+        else
+            ok(!ret, "style %#x: GetScrollInfo(SB_HORZ) should fail\n", style[i]);
+
+        ret = GetScrollInfo(mdi_client, SB_VERT, &si);
+        if (style[i] & (WS_HSCROLL | WS_VSCROLL))
+        {
+            ok(ret, "style %#x: GetScrollInfo(SB_VERT) failed\n", style[i]);
+            ok(si.nPage == 0, "expected 0\n");
+            ok(si.nPos == 0, "expected 0\n");
+            ok(si.nTrackPos == 0, "expected 0\n");
+            ok(si.nMin == 0, "expected 0\n");
+            ok(si.nMax == 100, "expected 100\n");
+        }
+        else
+            ok(!ret, "style %#x: GetScrollInfo(SB_VERT) should fail\n", style[i]);
+
+        gotit = FALSE;
+        while (PeekMessageA(&msg, 0, 0, 0, PM_REMOVE))
+        {
+            if (msg.message == WM_MOUSEMOVE || msg.message == WM_PAINT)
+            {
+                DispatchMessageA(&msg);
+                continue;
+            }
+
+            if (msg.message == 0x003f) /* WM_MDICALCCHILDSCROLL ??? */
+            {
+                ok(msg.hwnd == mdi_client, "message 0x003f should be posted to mdiclient\n");
+                gotit = TRUE;
+            }
+            else
+                ok(msg.hwnd != mdi_client, "message %04x should not be posted to mdiclient\n", msg.message);
+            DispatchMessageA(&msg);
+        }
+        ok(gotit, "message 0x003f should appear after SetWindowPos\n");
+
+        si.cbSize = sizeof(si);
+        si.fMask = SIF_ALL;
+        ret = GetScrollInfo(mdi_client, SB_HORZ, &si);
+        if (style[i] & (WS_HSCROLL | WS_VSCROLL))
+        {
+            ok(ret, "style %#x: GetScrollInfo(SB_HORZ) failed\n", style[i]);
+todo_wine
+            ok(si.nPage != 0, "expected !0\n");
+            ok(si.nPos == 0, "expected 0\n");
+            ok(si.nTrackPos == 0, "expected 0\n");
+            ok(si.nMin != 0, "expected !0\n");
+            ok(si.nMax != 100, "expected !100\n");
+        }
+        else
+            ok(!ret, "style %#x: GetScrollInfo(SB_HORZ) should fail\n", style[i]);
+
+        ret = GetScrollInfo(mdi_client, SB_VERT, &si);
+        if (style[i] & (WS_HSCROLL | WS_VSCROLL))
+        {
+            ok(ret, "style %#x: GetScrollInfo(SB_VERT) failed\n", style[i]);
+todo_wine
+            ok(si.nPage != 0, "expected !0\n");
+            ok(si.nPos == 0, "expected 0\n");
+            ok(si.nTrackPos == 0, "expected 0\n");
+            ok(si.nMin != 0, "expected !0\n");
+            ok(si.nMax != 100, "expected !100\n");
+        }
+        else
+            ok(!ret, "style %#x: GetScrollInfo(SB_VERT) should fail\n", style[i]);
+
+        DestroyWindow(mdi_child);
+        DestroyWindow(mdi_client);
+    }
+
+    /* MDIClient without MDIS_ALLCHILDSTYLES */
+    mdi_client = CreateWindowExA(0, "mdiclient",
+                                 NULL,
+                                 WS_CHILD /*| WS_VISIBLE*/,
+                                  /* tests depend on a not zero MDIClient size */
+                                 0, 0, rc.right, rc.bottom,
+                                 mdi_hwndMain, 0, GetModuleHandleA(NULL),
+                                 &client_cs);
+    assert(mdi_client);
+    test_MDI_create(mdi_hwndMain, mdi_client, client_cs.idFirstChild);
+    DestroyWindow(mdi_client);
+
+    /* MDIClient with MDIS_ALLCHILDSTYLES */
+    mdi_client = CreateWindowExA(0, "mdiclient",
+                                 NULL,
+                                 WS_CHILD | MDIS_ALLCHILDSTYLES /*| WS_VISIBLE*/,
+                                  /* tests depend on a not zero MDIClient size */
+                                 0, 0, rc.right, rc.bottom,
+                                 mdi_hwndMain, 0, GetModuleHandleA(NULL),
+                                 &client_cs);
+    assert(mdi_client);
+    test_MDI_create(mdi_hwndMain, mdi_client, client_cs.idFirstChild);
+    DestroyWindow(mdi_client);
+
+    /* Test child window stack management */
+    mdi_client = CreateWindowExA(0, "mdiclient",
+                                 NULL,
+                                 WS_CHILD,
+                                 0, 0, rc.right, rc.bottom,
+                                 mdi_hwndMain, 0, GetModuleHandleA(NULL),
+                                 &client_cs);
+    assert(mdi_client);
+    test_MDI_child_stack(mdi_client);
+    DestroyWindow(mdi_client);
 /*
     while(GetMessage(&msg, 0, 0, 0))
     {
@@ -1971,9 +2281,9 @@ static void test_icons(void)
 {
     WNDCLASSEXA cls;
     HWND hwnd;
-    HICON icon = LoadIconA(0, IDI_APPLICATION);
-    HICON icon2 = LoadIconA(0, IDI_QUESTION);
-    HICON small_icon = LoadImageA(0, IDI_APPLICATION, IMAGE_ICON,
+    HICON icon = LoadIconA(0, (LPCSTR)IDI_APPLICATION);
+    HICON icon2 = LoadIconA(0, (LPCSTR)IDI_QUESTION);
+    HICON small_icon = LoadImageA(0, (LPCSTR)IDI_APPLICATION, IMAGE_ICON,
                                   GetSystemMetrics(SM_CXSMICON), GetSystemMetrics(SM_CYSMICON), LR_SHARED );
     HICON res;
 
@@ -1983,9 +2293,9 @@ static void test_icons(void)
     cls.cbClsExtra = 0;
     cls.cbWndExtra = 0;
     cls.hInstance = 0;
-    cls.hIcon = LoadIconA(0, IDI_HAND);
+    cls.hIcon = LoadIconA(0, (LPCSTR)IDI_HAND);
     cls.hIconSm = small_icon;
-    cls.hCursor = LoadCursorA(0, IDC_ARROW);
+    cls.hCursor = LoadCursorA(0, (LPCSTR)IDC_ARROW);
     cls.hbrBackground = GetStockObject(WHITE_BRUSH);
     cls.lpszMenuName = NULL;
     cls.lpszClassName = "IconWindowClass";
@@ -2009,23 +2319,20 @@ static void test_icons(void)
 
     res = (HICON)SendMessageA( hwnd, WM_GETICON, ICON_SMALL, 0 );
     ok( res == 0, "wrong small icon %p/0\n", res );
-    /* this test is XP specific */
-    /*res = (HICON)SendMessageA( hwnd, WM_GETICON, ICON_SMALL2, 0 );
-    ok( res != 0, "wrong small icon %p\n", res );*/
+    res = (HICON)SendMessageA( hwnd, WM_GETICON, ICON_SMALL2, 0 );
+    ok( (res && res != small_icon && res != icon2) || broken(!res), "wrong small2 icon %p\n", res );
     res = (HICON)SendMessageA( hwnd, WM_SETICON, ICON_SMALL, (LPARAM)icon );
     ok( res == 0, "wrong previous small icon %p/0\n", res );
     res = (HICON)SendMessageA( hwnd, WM_GETICON, ICON_SMALL, 0 );
     ok( res == icon, "wrong small icon after set %p/%p\n", res, icon );
-    /* this test is XP specific */
-    /*res = (HICON)SendMessageA( hwnd, WM_GETICON, ICON_SMALL2, 0 );
-    ok( res == icon, "wrong small icon after set %p/%p\n", res, icon );*/
+    res = (HICON)SendMessageA( hwnd, WM_GETICON, ICON_SMALL2, 0 );
+    ok( res == icon || broken(!res), "wrong small2 icon after set %p/%p\n", res, icon );
     res = (HICON)SendMessageA( hwnd, WM_SETICON, ICON_SMALL, (LPARAM)small_icon );
     ok( res == icon, "wrong previous small icon %p/%p\n", res, icon );
     res = (HICON)SendMessageA( hwnd, WM_GETICON, ICON_SMALL, 0 );
     ok( res == small_icon, "wrong small icon after set %p/%p\n", res, small_icon );
-    /* this test is XP specific */
-    /*res = (HICON)SendMessageA( hwnd, WM_GETICON, ICON_SMALL2, 0 );
-    ok( res == small_icon, "wrong small icon after set %p/%p\n", res, small_icon );*/
+    res = (HICON)SendMessageA( hwnd, WM_GETICON, ICON_SMALL2, 0 );
+    ok( res == small_icon || broken(!res), "wrong small2 icon after set %p/%p\n", res, small_icon );
 
     /* make sure the big icon hasn't changed */
     res = (HICON)SendMessageA( hwnd, WM_GETICON, ICON_BIG, 0 );
@@ -2044,7 +2351,7 @@ static LRESULT WINAPI nccalcsize_proc(HWND hwnd, UINT msg, WPARAM wparam, LPARAM
         else InflateRect( rect, -10, -10 );
         return 0;
     }
-    return DefWindowProc( hwnd, msg, wparam, lparam );
+    return DefWindowProcA( hwnd, msg, wparam, lparam );
 }
 
 static void test_SetWindowPos(HWND hwnd, HWND hwnd2)
@@ -2068,7 +2375,7 @@ static void test_SetWindowPos(HWND hwnd, HWND hwnd2)
 
     GetWindowRect(hwnd, &orig_win_rc);
 
-    old_proc = SetWindowLongPtr( hwnd, GWLP_WNDPROC, (ULONG_PTR)nccalcsize_proc );
+    old_proc = SetWindowLongPtrA( hwnd, GWLP_WNDPROC, (ULONG_PTR)nccalcsize_proc );
     ret = SetWindowPos(hwnd, 0, 100, 100, 0, 0, SWP_NOZORDER|SWP_FRAMECHANGED);
     ok(ret, "Got %d\n", ret);
     GetWindowRect( hwnd, &rect );
@@ -2092,7 +2399,7 @@ static void test_SetWindowPos(HWND hwnd, HWND hwnd2)
     ret = SetWindowPos(hwnd, 0, orig_win_rc.left, orig_win_rc.top,
                       orig_win_rc.right, orig_win_rc.bottom, 0);
     ok(ret, "Got %d\n", ret);
-    SetWindowLongPtr( hwnd, GWLP_WNDPROC, old_proc );
+    SetWindowLongPtrA( hwnd, GWLP_WNDPROC, old_proc );
 
     /* Win9x truncates coordinates to 16-bit irrespectively */
     if (!is_win9x)
@@ -2112,16 +2419,16 @@ static void test_SetWindowPos(HWND hwnd, HWND hwnd2)
                        orig_win_rc.right, orig_win_rc.bottom, 0);
     ok(ret, "Got %d\n", ret);
 
-    ok(!(GetWindowLong(hwnd, GWL_EXSTYLE) & WS_EX_TOPMOST), "WS_EX_TOPMOST should not be set\n");
+    ok(!(GetWindowLongA(hwnd, GWL_EXSTYLE) & WS_EX_TOPMOST), "WS_EX_TOPMOST should not be set\n");
     ret = SetWindowPos(hwnd, HWND_TOPMOST, 0, 0, 0, 0, SWP_NOSIZE|SWP_NOMOVE);
     ok(ret, "Got %d\n", ret);
-    ok(GetWindowLong(hwnd, GWL_EXSTYLE) & WS_EX_TOPMOST, "WS_EX_TOPMOST should be set\n");
+    ok(GetWindowLongA(hwnd, GWL_EXSTYLE) & WS_EX_TOPMOST, "WS_EX_TOPMOST should be set\n");
     ret = SetWindowPos(hwnd, HWND_TOP, 0, 0, 0, 0, SWP_NOSIZE|SWP_NOMOVE);
     ok(ret, "Got %d\n", ret);
-    ok(GetWindowLong(hwnd, GWL_EXSTYLE) & WS_EX_TOPMOST, "WS_EX_TOPMOST should be set\n");
+    ok(GetWindowLongA(hwnd, GWL_EXSTYLE) & WS_EX_TOPMOST, "WS_EX_TOPMOST should be set\n");
     ret = SetWindowPos(hwnd, HWND_NOTOPMOST, 0, 0, 0, 0, SWP_NOSIZE|SWP_NOMOVE);
     ok(ret, "Got %d\n", ret);
-    ok(!(GetWindowLong(hwnd, GWL_EXSTYLE) & WS_EX_TOPMOST), "WS_EX_TOPMOST should not be set\n");
+    ok(!(GetWindowLongA(hwnd, GWL_EXSTYLE) & WS_EX_TOPMOST), "WS_EX_TOPMOST should not be set\n");
 
     hwnd_desktop = GetDesktopWindow();
     ok(!!hwnd_desktop, "Failed to get hwnd_desktop window (%d).\n", GetLastError());
@@ -2322,15 +2629,15 @@ static void test_SetMenu(HWND parent)
     ret = GetMenu(child);
     ok(ret == (HMENU)10, "unexpected menu id %p\n", ret);
 
-    style = GetWindowLong(child, GWL_STYLE);
-    SetWindowLong(child, GWL_STYLE, style | WS_POPUP);
+    style = GetWindowLongA(child, GWL_STYLE);
+    SetWindowLongA(child, GWL_STYLE, style | WS_POPUP);
     ok(SetMenu(child, hMenu), "SetMenu on a popup child window should not fail\n");
     ok(SetMenu(child, 0), "SetMenu on a popup child window should not fail\n");
-    SetWindowLong(child, GWL_STYLE, style);
+    SetWindowLongA(child, GWL_STYLE, style);
 
-    SetWindowLong(child, GWL_STYLE, style | WS_OVERLAPPED);
-    ok(!SetMenu(child, hMenu), "SetMenu on a overlapped child window should fail\n");
-    SetWindowLong(child, GWL_STYLE, style);
+    SetWindowLongA(child, GWL_STYLE, style | WS_OVERLAPPED);
+    ok(!SetMenu(child, hMenu), "SetMenu on an overlapped child window should fail\n");
+    SetWindowLongA(child, GWL_STYLE, style);
 
     DestroyWindow(child);
     DestroyMenu(hMenu);
@@ -2350,7 +2657,7 @@ static void test_window_tree(HWND parent, const DWORD *style, const int *order,
     {
         if (style[i] & DS_CONTROL)
         {
-            child[i] = CreateWindowExA(0, MAKEINTATOM(32770), "", style[i] & ~WS_VISIBLE,
+            child[i] = CreateWindowExA(0, (LPCSTR)MAKEINTATOM(32770), "", style[i] & ~WS_VISIBLE,
                                        0,0,0,0, parent, (HMENU)i, 0, NULL);
             if (style[i] & WS_VISIBLE)
                 ShowWindow(child[i], SW_SHOW);
@@ -2428,7 +2735,7 @@ static void check_z_order_debug(HWND hwnd, HWND next, HWND prev, HWND owner,
     /* skip foreign windows */
     while (test && test != next &&
            (GetWindowThreadProcessId(test, NULL) != our_pid ||
-            UlongToHandle(GetWindowLongPtr(test, GWLP_HINSTANCE)) != GetModuleHandle(0) ||
+            UlongToHandle(GetWindowLongPtrA(test, GWLP_HINSTANCE)) != GetModuleHandleA(NULL) ||
             GetWindow(test, GW_OWNER) == next))
     {
         /*trace("skipping next %p (%p)\n", test, UlongToHandle(GetWindowLongPtr(test, GWLP_HINSTANCE)));*/
@@ -2440,7 +2747,7 @@ static void check_z_order_debug(HWND hwnd, HWND next, HWND prev, HWND owner,
     /* skip foreign windows */
     while (test && test != prev &&
            (GetWindowThreadProcessId(test, NULL) != our_pid ||
-            UlongToHandle(GetWindowLongPtr(test, GWLP_HINSTANCE)) != GetModuleHandle(0) ||
+            UlongToHandle(GetWindowLongPtrA(test, GWLP_HINSTANCE)) != GetModuleHandleA(NULL) ||
             GetWindow(test, GW_OWNER) == hwnd))
     {
         /*trace("skipping prev %p (%p)\n", test, UlongToHandle(GetWindowLongPtr(test, GWLP_HINSTANCE)));*/
@@ -2451,7 +2758,7 @@ static void check_z_order_debug(HWND hwnd, HWND next, HWND prev, HWND owner,
     test = GetWindow(hwnd, GW_OWNER);
     ok_(file, line)(owner == test, "%p: expected owner %p, got %p\n", hwnd, owner, test);
 
-    ex_style = GetWindowLong(hwnd, GWL_EXSTYLE);
+    ex_style = GetWindowLongA(hwnd, GWL_EXSTYLE);
     ok_(file, line)(!(ex_style & WS_EX_TOPMOST) == !topmost, "%p: expected %stopmost\n",
                     hwnd, topmost ? "" : "NOT ");
 }
@@ -2467,10 +2774,10 @@ static void test_popup_zorder(HWND hwnd_D, HWND hwnd_E, DWORD style)
     check_z_order(hwnd_D, hwnd_E, 0, 0, FALSE);
     check_z_order(hwnd_E, 0, hwnd_D, 0, FALSE);
 
-    hwnd_F = CreateWindowEx(0, "MainWindowClass", "Owner window",
+    hwnd_F = CreateWindowExA(0, "MainWindowClass", "Owner window",
                             WS_OVERLAPPED | WS_CAPTION,
                             100, 100, 100, 100,
-                            0, 0, GetModuleHandle(0), NULL);
+                            0, 0, GetModuleHandleA(NULL), NULL);
     trace("hwnd_F %p\n", hwnd_F);
     check_z_order(hwnd_F, hwnd_D, 0, 0, FALSE);
 
@@ -2479,20 +2786,20 @@ static void test_popup_zorder(HWND hwnd_D, HWND hwnd_E, DWORD style)
     check_z_order(hwnd_E, hwnd_F, hwnd_D, 0, FALSE);
     check_z_order(hwnd_D, hwnd_E, 0, 0, FALSE);
 
-    hwnd_C = CreateWindowEx(0, "MainWindowClass", NULL,
+    hwnd_C = CreateWindowExA(0, "MainWindowClass", NULL,
                             style,
                             100, 100, 100, 100,
-                            hwnd_F, 0, GetModuleHandle(0), NULL);
+                            hwnd_F, 0, GetModuleHandleA(NULL), NULL);
     trace("hwnd_C %p\n", hwnd_C);
     check_z_order(hwnd_F, 0, hwnd_E, 0, FALSE);
     check_z_order(hwnd_E, hwnd_F, hwnd_D, 0, FALSE);
     check_z_order(hwnd_D, hwnd_E, hwnd_C, 0, FALSE);
     check_z_order(hwnd_C, hwnd_D, 0, hwnd_F, FALSE);
 
-    hwnd_B = CreateWindowEx(WS_EX_TOPMOST, "MainWindowClass", NULL,
+    hwnd_B = CreateWindowExA(WS_EX_TOPMOST, "MainWindowClass", NULL,
                             style,
                             100, 100, 100, 100,
-                            hwnd_F, 0, GetModuleHandle(0), NULL);
+                            hwnd_F, 0, GetModuleHandleA(NULL), NULL);
     trace("hwnd_B %p\n", hwnd_B);
     check_z_order(hwnd_F, 0, hwnd_E, 0, FALSE);
     check_z_order(hwnd_E, hwnd_F, hwnd_D, 0, FALSE);
@@ -2500,10 +2807,10 @@ static void test_popup_zorder(HWND hwnd_D, HWND hwnd_E, DWORD style)
     check_z_order(hwnd_C, hwnd_D, hwnd_B, hwnd_F, FALSE);
     check_z_order(hwnd_B, hwnd_C, 0, hwnd_F, TRUE);
 
-    hwnd_A = CreateWindowEx(WS_EX_TOPMOST, "MainWindowClass", NULL,
+    hwnd_A = CreateWindowExA(WS_EX_TOPMOST, "MainWindowClass", NULL,
                             style,
                             100, 100, 100, 100,
-                            0, 0, GetModuleHandle(0), NULL);
+                            0, 0, GetModuleHandleA(NULL), NULL);
     trace("hwnd_A %p\n", hwnd_A);
     check_z_order(hwnd_F, 0, hwnd_E, 0, FALSE);
     check_z_order(hwnd_E, hwnd_F, hwnd_D, 0, FALSE);
@@ -2536,10 +2843,10 @@ static void test_popup_zorder(HWND hwnd_D, HWND hwnd_E, DWORD style)
 
     /* make hwnd_C owned by a topmost window */
     DestroyWindow( hwnd_C );
-    hwnd_C = CreateWindowEx(0, "MainWindowClass", NULL,
+    hwnd_C = CreateWindowExA(0, "MainWindowClass", NULL,
                             style,
                             100, 100, 100, 100,
-                            hwnd_A, 0, GetModuleHandle(0), NULL);
+                            hwnd_A, 0, GetModuleHandleA(NULL), NULL);
     trace("hwnd_C %p\n", hwnd_C);
     check_z_order(hwnd_E, 0, hwnd_D, 0, FALSE);
     check_z_order(hwnd_D, hwnd_E, hwnd_F, 0, FALSE);
@@ -2593,7 +2900,7 @@ static LRESULT WINAPI set_focus_on_activate_proc(HWND hwnd, UINT msg, WPARAM wp,
         ok(GetFocus() == child, "Focus should be on child %p\n", child);
         return 0;
     }
-    return DefWindowProc(hwnd, msg, wp, lp);
+    return DefWindowProcA(hwnd, msg, wp, lp);
 }
 
 static void test_SetFocus(HWND hwnd)
@@ -2607,22 +2914,22 @@ static void test_SetFocus(HWND hwnd)
     SetFocus(0);
     SetFocus(hwnd);
     ok( GetFocus() == hwnd, "Failed to set focus to visible window %p\n", hwnd );
-    ok( GetWindowLong(hwnd,GWL_STYLE) & WS_VISIBLE, "Window %p not visible\n", hwnd );
+    ok( GetWindowLongA(hwnd,GWL_STYLE) & WS_VISIBLE, "Window %p not visible\n", hwnd );
     ShowWindow(hwnd, SW_HIDE);
     SetFocus(0);
     SetFocus(hwnd);
     ok( GetFocus() == hwnd, "Failed to set focus to invisible window %p\n", hwnd );
-    ok( !(GetWindowLong(hwnd,GWL_STYLE) & WS_VISIBLE), "Window %p still visible\n", hwnd );
+    ok( !(GetWindowLongA(hwnd,GWL_STYLE) & WS_VISIBLE), "Window %p still visible\n", hwnd );
     child = CreateWindowExA(0, "static", NULL, WS_CHILD, 0, 0, 0, 0, hwnd, 0, 0, NULL);
     assert(child);
     SetFocus(child);
     ok( GetFocus() == child, "Failed to set focus to invisible child %p\n", child );
-    ok( !(GetWindowLong(child,GWL_STYLE) & WS_VISIBLE), "Child %p is visible\n", child );
+    ok( !(GetWindowLongA(child,GWL_STYLE) & WS_VISIBLE), "Child %p is visible\n", child );
     ShowWindow(child, SW_SHOW);
-    ok( GetWindowLong(child,GWL_STYLE) & WS_VISIBLE, "Child %p is not visible\n", child );
+    ok( GetWindowLongA(child,GWL_STYLE) & WS_VISIBLE, "Child %p is not visible\n", child );
     ok( GetFocus() == child, "Focus no longer on child %p\n", child );
     ShowWindow(child, SW_HIDE);
-    ok( !(GetWindowLong(child,GWL_STYLE) & WS_VISIBLE), "Child %p is visible\n", child );
+    ok( !(GetWindowLongA(child,GWL_STYLE) & WS_VISIBLE), "Child %p is visible\n", child );
     ok( GetFocus() == hwnd, "Focus should be on parent %p, not %p\n", hwnd, GetFocus() );
     ShowWindow(child, SW_SHOW);
     child2 = CreateWindowExA(0, "static", NULL, WS_CHILD, 0, 0, 0, 0, child, 0, 0, NULL);
@@ -2630,7 +2937,7 @@ static void test_SetFocus(HWND hwnd)
     ShowWindow(child2, SW_SHOW);
     SetFocus(child2);
     ShowWindow(child, SW_HIDE);
-    ok( !(GetWindowLong(child,GWL_STYLE) & WS_VISIBLE), "Child %p is visible\n", child );
+    ok( !(GetWindowLongA(child,GWL_STYLE) & WS_VISIBLE), "Child %p is visible\n", child );
     ok( GetFocus() == child2, "Focus should be on %p, not %p\n", child2, GetFocus() );
     ShowWindow(child, SW_SHOW);
     SetFocus(child);
@@ -2668,12 +2975,12 @@ todo_wine
     ok( GetFocus() != child, "Focus should not be on child %p\n", child );
 todo_wine
     ok( GetFocus() != hwnd, "Focus should not be on parent %p\n", hwnd );
-    old_wnd_proc = (WNDPROC)SetWindowLongPtr(hwnd, GWLP_WNDPROC, (LONG_PTR)set_focus_on_activate_proc);
+    old_wnd_proc = (WNDPROC)SetWindowLongPtrA(hwnd, GWLP_WNDPROC, (LONG_PTR)set_focus_on_activate_proc);
     ShowWindow(hwnd, SW_RESTORE);
     ok( GetActiveWindow() == hwnd, "parent window %p should be active\n", hwnd);
 todo_wine
     ok( GetFocus() == child, "Focus should be on child %p, not %p\n", child, GetFocus() );
-    SetWindowLongPtr(hwnd, GWLP_WNDPROC, (LONG_PTR)old_wnd_proc);
+    SetWindowLongPtrA(hwnd, GWLP_WNDPROC, (LONG_PTR)old_wnd_proc);
 
     SetFocus( hwnd );
     SetParent( child, GetDesktopWindow());
@@ -2793,6 +3100,7 @@ static void test_SetForegroundWindow(HWND hwnd)
     BOOL ret;
     HWND hwnd2;
     MSG msg;
+    LONG style;
 
     flush_events( TRUE );
     ShowWindow(hwnd, SW_HIDE);
@@ -2870,9 +3178,9 @@ static void test_SetForegroundWindow(HWND hwnd)
     hwnd2 = CreateWindowA("static", NULL, WS_POPUP | WS_VISIBLE, 0, 0, 0, 0, 0, 0, 0, 0);
     check_wnd_state(hwnd2, hwnd2, hwnd2, 0);
 
-    thread_params.window_created = CreateEvent(NULL, FALSE, FALSE, NULL);
+    thread_params.window_created = CreateEventW(NULL, FALSE, FALSE, NULL);
     ok(!!thread_params.window_created, "CreateEvent failed, last error %#x.\n", GetLastError());
-    thread_params.test_finished = CreateEvent(NULL, FALSE, FALSE, NULL);
+    thread_params.test_finished = CreateEventW(NULL, FALSE, FALSE, NULL);
     ok(!!thread_params.test_finished, "CreateEvent failed, last error %#x.\n", GetLastError());
     thread = CreateThread(NULL, 0, create_window_thread, &thread_params, 0, &tid);
     ok(!!thread, "Failed to create thread, last error %#x.\n", GetLastError());
@@ -2883,11 +3191,24 @@ static void test_SetForegroundWindow(HWND hwnd)
     SetForegroundWindow(hwnd2);
     check_wnd_state(hwnd2, hwnd2, hwnd2, 0);
 
-    while (PeekMessage(&msg, 0, 0, 0, PM_REMOVE)) DispatchMessage(&msg);
+    while (PeekMessageA(&msg, 0, 0, 0, PM_REMOVE)) DispatchMessageA(&msg);
     if (0) check_wnd_state(hwnd2, hwnd2, hwnd2, 0);
     todo_wine ok(GetActiveWindow() == hwnd2, "Expected active window %p, got %p.\n", hwnd2, GetActiveWindow());
     todo_wine ok(GetFocus() == hwnd2, "Expected focus window %p, got %p.\n", hwnd2, GetFocus());
 
+    SetForegroundWindow(hwnd);
+    check_wnd_state(hwnd, hwnd, hwnd, 0);
+    style = GetWindowLongA(hwnd2, GWL_STYLE) | WS_CHILD;
+    ok(SetWindowLongA(hwnd2, GWL_STYLE, style), "SetWindowLong failed\n");
+    ok(SetForegroundWindow(hwnd2), "SetForegroundWindow failed\n");
+    check_wnd_state(hwnd2, hwnd2, hwnd2, 0);
+
+    SetForegroundWindow(hwnd);
+    check_wnd_state(hwnd, hwnd, hwnd, 0);
+    ok(SetWindowLongA(hwnd2, GWL_STYLE, style & (~WS_POPUP)), "SetWindowLong failed\n");
+    ok(!SetForegroundWindow(hwnd2), "SetForegroundWindow failed\n");
+    check_wnd_state(hwnd, hwnd, hwnd, 0);
+
     SetEvent(thread_params.test_finished);
     WaitForSingleObject(thread, INFINITE);
     CloseHandle(thread_params.test_finished);
@@ -2935,7 +3256,7 @@ static LRESULT WINAPI button_hook_proc(HWND button, UINT msg, WPARAM wparam, LPA
        /* button wnd proc should release capture on WM_KILLFOCUS if it does
         * match internal button state.
         */
-       SendMessage(button, WM_KILLFOCUS, 0, 0);
+       SendMessageA(button, WM_KILLFOCUS, 0, 0);
        check_wnd_state(button, button, button, 0);
 
        ShowWindow(hwnd, SW_SHOW);
@@ -3001,7 +3322,7 @@ static void test_capture_2(void)
     /* button wnd proc should ignore WM_KILLFOCUS if it doesn't match
      * internal button state.
      */
-    SendMessage(button, WM_KILLFOCUS, 0, 0);
+    SendMessageA(button, WM_KILLFOCUS, 0, 0);
     check_wnd_state(button, button, button, button);
 
     hwnd = CreateWindowExA(0, "static", NULL, WS_POPUP, 0, 0, 10, 10, 0, 0, 0, NULL);
@@ -3083,6 +3404,9 @@ static LRESULT CALLBACK test_capture_4_proc(HWND hWnd, UINT msg, WPARAM wParam,
             }
             cap_wnd = GetCapture();
 
+            ok(cap_wnd == (HWND)lParam, "capture window %p does not match lparam %lx\n", cap_wnd, lParam);
+            todo_wine ok(cap_wnd == hWnd, "capture window %p does not match hwnd %p\n", cap_wnd, hWnd);
+
             /* check that re-setting the capture for the menu fails */
             set_cap_wnd = SetCapture(cap_wnd);
             ok(!set_cap_wnd || broken(set_cap_wnd == cap_wnd), /* nt4 */
@@ -3144,8 +3468,8 @@ static void test_capture_4(void)
     wclass.style         = CS_HREDRAW | CS_VREDRAW;
     wclass.lpfnWndProc   = test_capture_4_proc;
     wclass.hInstance     = hInstance;
-    wclass.hIcon         = LoadIconA( 0, IDI_APPLICATION );
-    wclass.hCursor       = LoadCursorA( NULL, IDC_ARROW );
+    wclass.hIcon         = LoadIconA( 0, (LPCSTR)IDI_APPLICATION );
+    wclass.hCursor       = LoadCursorA( 0, (LPCSTR)IDC_ARROW );
     wclass.hbrBackground = (HBRUSH)( COLOR_WINDOW + 1 );
     wclass.lpszMenuName  = 0;
     wclass.cbClsExtra    = 0;
@@ -3188,7 +3512,7 @@ static BOOL peek_message( MSG *msg )
     do
     {
         ret = PeekMessageA(msg, 0, 0, 0, PM_REMOVE);
-    } while (ret && (msg->message == WM_TIMER || ignore_message(msg->message)));
+    } while (ret && ignore_message(msg->message));
     return ret;
 }
 
@@ -3277,7 +3601,7 @@ static BOOL wait_for_message( MSG *msg )
         ret = peek_message(msg);
         if (ret)
         {
-            if (msg->message == WM_PAINT) DispatchMessage(msg);
+            if (msg->message == WM_PAINT) DispatchMessageA(msg);
             else break;
         }
         else if (MsgWaitForMultipleObjects( 0, NULL, FALSE, 100, QS_ALLINPUT ) == WAIT_TIMEOUT) break;
@@ -3352,10 +3676,10 @@ static void test_mouse_input(HWND hwnd)
     /* FIXME: SetCursorPos in Wine generates additional WM_MOUSEMOVE message */
     while (PeekMessageA(&msg, 0, 0, 0, PM_REMOVE))
     {
-        if (msg.message == WM_TIMER || ignore_message(msg.message)) continue;
+        if (ignore_message(msg.message)) continue;
         ok(msg.hwnd == popup && msg.message == WM_MOUSEMOVE,
            "hwnd %p message %04x\n", msg.hwnd, msg.message);
-        DispatchMessage(&msg);
+        DispatchMessageA(&msg);
     }
     ret = peek_message(&msg);
     ok( !ret, "message %04x available\n", msg.message);
@@ -3570,7 +3894,7 @@ static void test_nccalcscroll(HWND parent)
             0, rc1.left, rc1.top, rc1.right, rc1.bottom);
 
     /* same test, but with client edge: not enough width */
-    SetWindowLong( hwnd, GWL_EXSTYLE, WS_EX_CLIENTEDGE | GetWindowLong( hwnd, GWL_EXSTYLE));
+    SetWindowLongA( hwnd, GWL_EXSTYLE, WS_EX_CLIENTEDGE | GetWindowLongA( hwnd, GWL_EXSTYLE));
     nccalchelper( hwnd, sbwidth, 100, &rc1);
     ok( rc1.right - rc1.left == sbwidth - 2 * GetSystemMetrics(SM_CXEDGE),
             "Width should be %d size is %d,%d - %d,%d\n",
@@ -3674,6 +3998,19 @@ static void test_SetParent(void)
     ok(SetParent(sibling, parent) != 0, "SetParent should not fail\n");
     ok(GetMenu(sibling) == hMenu, "SetParent should not remove menu\n");
 
+    ok(SetParent(parent, desktop) != 0, "SetParent should not fail\n");
+    ok(SetParent(child4, child3) != 0, "SetParent should not fail\n");
+    ok(SetParent(child3, child2) != 0, "SetParent should not fail\n");
+    ok(SetParent(child2, child1) != 0, "SetParent should not fail\n");
+    ok(!IsChild(child3, child4), "wrong parent/child %p/%p\n", child3, child4);
+    SetWindowLongW(child4, GWL_STYLE, WS_CHILD);
+    ok(IsChild(child3, child4), "wrong parent/child %p/%p\n", child3, child4);
+    ok(IsChild(child2, child4), "wrong parent/child %p/%p\n", child2, child4);
+    ok(!IsChild(child1, child4), "wrong parent/child %p/%p\n", child1, child4);
+    SetWindowLongW(child2, GWL_STYLE, WS_CHILD);
+    ok(IsChild(child1, child4), "wrong parent/child %p/%p\n", child1, child4);
+    ok(IsChild(parent, child4), "wrong parent/child %p/%p\n", parent, child4);
+
     ok(DestroyWindow(parent), "DestroyWindow() failed\n");
 
     ok(!IsWindow(parent), "parent still exists\n");
@@ -3706,21 +4043,39 @@ static void test_SetParent(void)
     ret = SetParent(popup, child1);
     ok(ret == desktop, "expected %p, got %p\n", desktop, ret);
     check_parents(popup, child1, child1, 0, 0, parent, popup);
-todo_wine
     check_active_state(popup, 0, popup);
 
+    SetActiveWindow(parent);
+    SetFocus(popup);
+    check_active_state(popup, 0, popup);
+
+    EnableWindow(child1, FALSE);
+    check_active_state(popup, 0, popup);
+    SetFocus(parent);
+    check_active_state(parent, 0, parent);
+    SetFocus(popup);
+    check_active_state(popup, 0, popup);
+    EnableWindow(child1, TRUE);
+
+    ShowWindow(child1, SW_MINIMIZE);
+    SetFocus(parent);
+    check_active_state(parent, 0, parent);
+    SetFocus(popup);
+    check_active_state(popup, 0, popup);
+    ShowWindow(child1, SW_HIDE);
+
     SetActiveWindow(parent);
     SetFocus(parent);
     check_active_state(parent, 0, parent);
 
     bret = SetForegroundWindow(popup);
-todo_wine {
-    ok(bret || broken(!bret), "SetForegroundWindow() failed\n");
-    if (!bret)
-        check_active_state(popup, 0, popup);
-    else
-        check_active_state(popup, popup, popup);
-    }
+    ok(bret, "SetForegroundWindow() failed\n");
+    check_active_state(popup, popup, popup);
+
+    ShowWindow(parent, SW_SHOW);
+    SetActiveWindow(popup);
+    ok(DestroyWindow(popup), "DestroyWindow() failed\n");
+    check_active_state(parent, parent, parent);
 
     ok(DestroyWindow(parent), "DestroyWindow() failed\n");
 
@@ -3731,14 +4086,14 @@ todo_wine {
 
 static LRESULT WINAPI StyleCheckProc(HWND hwnd, UINT msg, WPARAM wparam, LPARAM lparam)
 {
-    LPCREATESTRUCT lpcs;
+    LPCREATESTRUCTA lpcs;
     LPSTYLESTRUCT lpss;
 
     switch (msg)
     {
     case WM_NCCREATE:
     case WM_CREATE:
-        lpcs = (LPCREATESTRUCT)lparam;
+        lpcs = (LPCREATESTRUCTA)lparam;
         lpss = lpcs->lpCreateParams;
         if (lpss)
         {
@@ -3751,7 +4106,7 @@ static LRESULT WINAPI StyleCheckProc(HWND hwnd, UINT msg, WPARAM wparam, LPARAM
 
             ok((lpss->styleOld & ~WS_EX_WINDOWEDGE) == (lpcs->dwExStyle & ~WS_EX_WINDOWEDGE),
                 "Ex style (0x%08x) should match what the caller passed to CreateWindowEx (0x%08x)\n",
-                (lpss->styleOld & ~WS_EX_WINDOWEDGE), (lpcs->dwExStyle & ~WS_EX_WINDOWEDGE));
+                lpss->styleOld, lpcs->dwExStyle);
 
             ok(lpss->styleNew == lpcs->style,
                 "Style (0x%08x) should match what the caller passed to CreateWindowEx (0x%08x)\n",
@@ -3759,28 +4114,28 @@ static LRESULT WINAPI StyleCheckProc(HWND hwnd, UINT msg, WPARAM wparam, LPARAM
         }
         break;
     }
-    return DefWindowProc(hwnd, msg, wparam, lparam);
+    return DefWindowProcA(hwnd, msg, wparam, lparam);
 }
 
 static ATOM atomStyleCheckClass;
 
 static void register_style_check_class(void)
 {
-    WNDCLASS wc =
+    WNDCLASSA wc =
     {
         0,
         StyleCheckProc,
         0,
         0,
-        GetModuleHandle(NULL),
+        GetModuleHandleA(NULL),
         NULL,
-        LoadCursor(NULL, IDC_ARROW),
+        LoadCursorA(0, (LPCSTR)IDC_ARROW),
         (HBRUSH)(COLOR_BTNFACE+1),
         NULL,
-        TEXT("WineStyleCheck"),
+        "WineStyleCheck",
     };
-    
-    atomStyleCheckClass = RegisterClass(&wc);
+
+    atomStyleCheckClass = RegisterClassA(&wc);
     assert(atomStyleCheckClass);
 }
 
@@ -3797,25 +4152,25 @@ static void check_window_style(DWORD dwStyleIn, DWORD dwExStyleIn, DWORD dwStyle
 
     if (dwStyleIn & WS_CHILD)
     {
-        hwndParent = CreateWindowEx(0, MAKEINTATOM(atomStyleCheckClass), NULL,
+        hwndParent = CreateWindowExA(0, (LPCSTR)MAKEINTATOM(atomStyleCheckClass), NULL,
             WS_OVERLAPPEDWINDOW, 0, 0, 0, 0, NULL, NULL, NULL, NULL);
     }
 
-    hwnd = CreateWindowEx(dwExStyleIn, MAKEINTATOM(atomStyleCheckClass), NULL,
+    hwnd = CreateWindowExA(dwExStyleIn, (LPCSTR)MAKEINTATOM(atomStyleCheckClass), NULL,
                     dwStyleIn, 0, 0, 0, 0, hwndParent, NULL, NULL, &ss);
     assert(hwnd);
 
     flush_events( TRUE );
 
-    dwActualStyle = GetWindowLong(hwnd, GWL_STYLE);
-    dwActualExStyle = GetWindowLong(hwnd, GWL_EXSTYLE);
+    dwActualStyle = GetWindowLongA(hwnd, GWL_STYLE);
+    dwActualExStyle = GetWindowLongA(hwnd, GWL_EXSTYLE);
     ok(dwActualStyle == dwStyleOut, "expected style %#x, got %#x\n", dwStyleOut, dwActualStyle);
     ok(dwActualExStyle == dwExStyleOut, "expected ex_style %#x, got %#x\n", dwExStyleOut, dwActualExStyle);
 
     /* try setting the styles explicitly */
-    SetWindowLong( hwnd, GWL_EXSTYLE, dwExStyleIn );
-    dwActualStyle = GetWindowLong(hwnd, GWL_STYLE);
-    dwActualExStyle = GetWindowLong(hwnd, GWL_EXSTYLE);
+    SetWindowLongA( hwnd, GWL_EXSTYLE, dwExStyleIn );
+    dwActualStyle = GetWindowLongA(hwnd, GWL_STYLE);
+    dwActualExStyle = GetWindowLongA(hwnd, GWL_EXSTYLE);
     /* WS_EX_WINDOWEDGE can't always be changed */
     if (dwExStyleIn & WS_EX_DLGMODALFRAME)
         dwExStyleOut = dwExStyleIn | WS_EX_WINDOWEDGE;
@@ -3826,9 +4181,9 @@ static void check_window_style(DWORD dwStyleIn, DWORD dwExStyleIn, DWORD dwStyle
     ok(dwActualStyle == dwStyleOut, "expected style %#x, got %#x\n", dwStyleOut, dwActualStyle);
     ok(dwActualExStyle == dwExStyleOut, "expected ex_style %#x, got %#x\n", dwExStyleOut, dwActualExStyle);
 
-    SetWindowLong( hwnd, GWL_STYLE, dwStyleIn );
-    dwActualStyle = GetWindowLong(hwnd, GWL_STYLE);
-    dwActualExStyle = GetWindowLong(hwnd, GWL_EXSTYLE);
+    SetWindowLongA( hwnd, GWL_STYLE, dwStyleIn );
+    dwActualStyle = GetWindowLongA(hwnd, GWL_STYLE);
+    dwActualExStyle = GetWindowLongA(hwnd, GWL_EXSTYLE);
     /* WS_CLIPSIBLINGS can't be reset on top-level windows */
     if ((dwStyleIn & (WS_CHILD|WS_POPUP)) == WS_CHILD) dwStyleOut = dwStyleIn;
     else dwStyleOut = dwStyleIn | WS_CLIPSIBLINGS;
@@ -3841,10 +4196,8 @@ static void check_window_style(DWORD dwStyleIn, DWORD dwExStyleIn, DWORD dwStyle
         dwExStyleOut = dwExStyleIn & ~WS_EX_WINDOWEDGE;
     ok(dwActualStyle == dwStyleOut, "expected style %#x, got %#x\n", dwStyleOut, dwActualStyle);
     /* FIXME: Remove the condition below once Wine is fixed */
-    if (dwActualExStyle != dwExStyleOut)
-    todo_wine ok(dwActualExStyle == dwExStyleOut, "expected ex_style %#x, got %#x\n", dwExStyleOut, dwActualExStyle);
-    else
-    ok(dwActualExStyle == dwExStyleOut, "expected ex_style %#x, got %#x\n", dwExStyleOut, dwActualExStyle);
+    todo_wine_if (dwActualExStyle != dwExStyleOut)
+        ok(dwActualExStyle == dwExStyleOut, "expected ex_style %#x, got %#x\n", dwExStyleOut, dwActualExStyle);
 
     DestroyWindow(hwnd);
     if (hwndParent) DestroyWindow(hwndParent);
@@ -3903,6 +4256,74 @@ static INT_PTR WINAPI empty_dlg_proc(HWND hwnd, UINT msg, WPARAM wparam, LPARAM
     return 0;
 }
 
+static INT_PTR WINAPI empty_dlg_proc3(HWND hwnd, UINT msg, WPARAM wparam, LPARAM lparam)
+{
+    if (msg == WM_INITDIALOG)
+        EndDialog(hwnd, 0);
+
+    return 0;
+}
+
+struct dialog_param
+{
+    HWND parent, grand_parent;
+    DLGTEMPLATE *dlg_data;
+};
+
+static INT_PTR WINAPI empty_dlg_proc2(HWND hwnd, UINT msg, WPARAM wparam, LPARAM lparam)
+{
+    if (msg == WM_INITDIALOG)
+    {
+        DWORD style = GetWindowLongA(hwnd, GWL_STYLE);
+        struct dialog_param *param = (struct dialog_param *)lparam;
+        BOOL parent_is_child;
+        HWND disabled_hwnd;
+
+        parent_is_child = (GetWindowLongA(param->parent, GWL_STYLE) & (WS_POPUP | WS_CHILD)) == WS_CHILD;
+
+        ok(IsWindowEnabled(hwnd), "wrong state for %p\n", hwnd);
+        if (parent_is_child)
+        {
+            ok(IsWindowEnabled(param->parent), "wrong state for %08x\n", style);
+            disabled_hwnd = param->grand_parent;
+        }
+        else
+        {
+            ok(!IsWindowEnabled(param->parent), "wrong state for %08x\n", style);
+            disabled_hwnd = param->parent;
+        }
+
+        if (param->grand_parent)
+        {
+            if (parent_is_child)
+                ok(!IsWindowEnabled(param->grand_parent), "wrong state for %08x\n", style);
+            else
+                ok(IsWindowEnabled(param->grand_parent), "wrong state for %08x\n", style);
+        }
+
+        DialogBoxIndirectParamA(GetModuleHandleA(NULL), param->dlg_data, disabled_hwnd, empty_dlg_proc3, 0);
+        ok(IsWindowEnabled(disabled_hwnd), "wrong state for %08x\n", style);
+
+        ok(IsWindowEnabled(hwnd), "wrong state for %p\n", hwnd);
+        ok(IsWindowEnabled(param->parent), "wrong state for %p\n", param->parent);
+        if (param->grand_parent)
+            ok(IsWindowEnabled(param->grand_parent), "wrong state for %p (%08x)\n", param->grand_parent, style);
+
+        DialogBoxIndirectParamA(GetModuleHandleA(NULL), param->dlg_data, hwnd, empty_dlg_proc3, 0);
+        ok(IsWindowEnabled(hwnd), "wrong state for %p\n", hwnd);
+        ok(IsWindowEnabled(param->parent), "wrong state for %p\n", param->parent);
+        if (param->grand_parent)
+            ok(IsWindowEnabled(param->grand_parent), "wrong state for %p (%08x)\n", param->grand_parent, style);
+
+        param->dlg_data->style |= WS_CHILD;
+        DialogBoxIndirectParamA(GetModuleHandleA(NULL), param->dlg_data, hwnd, empty_dlg_proc3, 0);
+        ok(IsWindowEnabled(hwnd), "wrong state for %p (%08x)\n", hwnd, style);
+
+        EndDialog(hwnd, 0);
+    }
+    return 0;
+}
+
 static void check_dialog_style(DWORD style_in, DWORD ex_style_in, DWORD style_out, DWORD ex_style_out)
 {
     struct
@@ -3914,11 +4335,19 @@ static void check_dialog_style(DWORD style_in, DWORD ex_style_in, DWORD style_ou
         WCHAR caption[1];
     } dlg_data;
     DWORD style, ex_style;
-    HWND hwnd, parent = 0;
+    HWND hwnd, grand_parent = 0, parent = 0;
+    struct dialog_param param;
 
     if (style_in & WS_CHILD)
-        parent = CreateWindowEx(0, "static", NULL, WS_OVERLAPPEDWINDOW,
+    {
+        grand_parent = CreateWindowExA(0, "static", NULL, WS_OVERLAPPEDWINDOW,
                                 0, 0, 0, 0, NULL, NULL, NULL, NULL);
+        ok(grand_parent != 0, "grand_parent creation failed\n");
+    }
+
+    parent = CreateWindowExA(0, "static", NULL, style_in,
+                             0, 0, 0, 0, grand_parent, NULL, NULL, NULL);
+    ok(parent != 0, "parent creation failed, style %#x\n", style_in);
 
     dlg_data.dt.style = style_in;
     dlg_data.dt.dwExtendedStyle = ex_style_in;
@@ -3932,21 +4361,23 @@ static void check_dialog_style(DWORD style_in, DWORD ex_style_in, DWORD style_ou
     dlg_data.class_atom = 0;
     dlg_data.caption[0] = 0;
 
-    hwnd = CreateDialogIndirectParam(GetModuleHandle(0), &dlg_data.dt, parent, empty_dlg_proc, 0);
+    hwnd = CreateDialogIndirectParamA(GetModuleHandleA(NULL), &dlg_data.dt, parent, empty_dlg_proc, 0);
     ok(hwnd != 0, "dialog creation failed, style %#x, exstyle %#x\n", style_in, ex_style_in);
 
     flush_events( TRUE );
 
-    style = GetWindowLong(hwnd, GWL_STYLE);
-    ex_style = GetWindowLong(hwnd, GWL_EXSTYLE);
-    ok(style == (style_out | DS_3DLOOK), "expected style %#x, got %#x\n", style_out | DS_3DLOOK, style);
+    style = GetWindowLongA(hwnd, GWL_STYLE);
+    ex_style = GetWindowLongA(hwnd, GWL_EXSTYLE);
+    ok(style == (style_out | DS_3DLOOK), "got %#x\n", style);
     ok(ex_style == ex_style_out, "expected ex_style %#x, got %#x\n", ex_style_out, ex_style);
 
+    ok(IsWindowEnabled(parent), "wrong parent state (dialog style %#x)\n", style_in);
+
     /* try setting the styles explicitly */
-    SetWindowLong(hwnd, GWL_EXSTYLE, ex_style_in);
-    style = GetWindowLong(hwnd, GWL_STYLE);
-    ex_style = GetWindowLong(hwnd, GWL_EXSTYLE);
-    ok(style == (style_out | DS_3DLOOK), "expected style %#x, got %#x\n", style_out|DS_3DLOOK, style);
+    SetWindowLongA(hwnd, GWL_EXSTYLE, ex_style_in);
+    style = GetWindowLongA(hwnd, GWL_STYLE);
+    ex_style = GetWindowLongA(hwnd, GWL_EXSTYLE);
+    ok(style == (style_out | DS_3DLOOK), "got %#x\n", style);
     /* WS_EX_WINDOWEDGE can't always be changed */
     if (ex_style_in & WS_EX_DLGMODALFRAME)
         ex_style_out = ex_style_in | WS_EX_WINDOWEDGE;
@@ -3956,9 +4387,9 @@ static void check_dialog_style(DWORD style_in, DWORD ex_style_in, DWORD style_ou
         ex_style_out = ex_style_in & ~WS_EX_WINDOWEDGE;
     ok(ex_style == ex_style_out, "expected ex_style %#x, got %#x\n", ex_style_out, ex_style);
 
-    SetWindowLong(hwnd, GWL_STYLE, style_in);
-    style = GetWindowLong(hwnd, GWL_STYLE);
-    ex_style = GetWindowLong(hwnd, GWL_EXSTYLE);
+    SetWindowLongA(hwnd, GWL_STYLE, style_in);
+    style = GetWindowLongA(hwnd, GWL_STYLE);
+    ex_style = GetWindowLongA(hwnd, GWL_EXSTYLE);
     /* WS_CLIPSIBLINGS can't be reset on top-level windows */
     if ((style_in & (WS_CHILD | WS_POPUP)) == WS_CHILD) style_out = style_in;
     else style_out = style_in | WS_CLIPSIBLINGS;
@@ -3971,13 +4402,22 @@ static void check_dialog_style(DWORD style_in, DWORD ex_style_in, DWORD style_ou
     else
         ex_style_out = ex_style_in & ~WS_EX_WINDOWEDGE;
     /* FIXME: Remove the condition below once Wine is fixed */
-    if (ex_style != ex_style_out)
-    todo_wine ok(ex_style == ex_style_out, "expected ex_style %#x, got %#x\n", ex_style_out, ex_style);
-    else
-    ok(ex_style == ex_style_out, "expected ex_style %#x, got %#x\n", ex_style_out, ex_style);
+    todo_wine_if (ex_style != ex_style_out)
+        ok(ex_style == ex_style_out, "expected ex_style %#x, got %#x\n", ex_style_out, ex_style);
 
     DestroyWindow(hwnd);
+
+    param.parent = parent;
+    param.grand_parent = grand_parent;
+    param.dlg_data = &dlg_data.dt;
+    DialogBoxIndirectParamA(GetModuleHandleA(NULL), &dlg_data.dt, parent, empty_dlg_proc2, (LPARAM)&param);
+
+    ok(IsWindowEnabled(parent), "wrong parent state (dialog style %#x)\n", style_in);
+    if (grand_parent)
+        ok(IsWindowEnabled(grand_parent), "wrong grand parent state (dialog style %#x)\n", style_in);
+
     DestroyWindow(parent);
+    DestroyWindow(grand_parent);
 }
 
 static void test_dialog_styles(void)
@@ -4067,54 +4507,281 @@ static void test_dialog_styles(void)
     }
 }
 
-static void test_scrollwindow( HWND hwnd)
+struct dlg_parent_param
 {
-    HDC hdc;
-    RECT rc, rc2, rc3;
-    COLORREF colr;
+    HWND ga_parent;
+    HWND gwl_parent;
+    HWND get_parent;
+    HWND owner;
+    HWND root;
+    HWND ga_root_owner;
+};
 
-    ShowWindow( hwnd, SW_SHOW);
-    UpdateWindow( hwnd);
-    flush_events( TRUE );
-    GetClientRect( hwnd, &rc);
-    hdc = GetDC( hwnd);
-    /* test ScrollWindow(Ex) with no clip rectangle */
-    /* paint the lower half of the window black */
-    rc2 = rc;
-    rc2.top = ( rc2.top + rc2.bottom) / 2;
-    FillRect( hdc, &rc2, GetStockObject(BLACK_BRUSH));
-    /* paint the upper half of the window white */
-    rc2.bottom = rc2.top;
-    rc2.top =0;
-    FillRect( hdc, &rc2, GetStockObject(WHITE_BRUSH));
-    /* scroll lower half up */
-    rc2 = rc;
-    rc2.top = ( rc2.top + rc2.bottom) / 2;
-    ScrollWindowEx( hwnd, 0, - rc2.top, &rc2, NULL, NULL, NULL, SW_ERASE);
-    flush_events(FALSE);
-    /* expected: black should have scrolled to the upper half */
-    colr = GetPixel( hdc, (rc2.left+rc2.right)/ 2,  rc2.bottom / 4 );
-    ok ( colr == 0, "pixel should be black, color is %08x\n", colr);
-    /* Repeat that test of ScrollWindow(Ex) now with clip rectangle */
-    /* paint the lower half of the window black */
-    rc2 = rc;
-    rc2.top = ( rc2.top + rc2.bottom) / 2;
-    FillRect( hdc, &rc2, GetStockObject(BLACK_BRUSH));
-    /* paint the upper half of the window white */
-    rc2.bottom = rc2.top;
-    rc2.top =0;
-    FillRect( hdc, &rc2, GetStockObject(WHITE_BRUSH));
-    /* scroll lower half up */
-    rc2 = rc;
-    rc2.top = ( rc2.top + rc2.bottom) / 2;
-    rc3 = rc;
-    rc3.left = rc3.right / 4;
-    rc3.right -= rc3.right / 4;
-    ScrollWindowEx( hwnd, 0, - rc2.top, &rc2, &rc3, NULL, NULL, SW_ERASE);
-    flush_events(FALSE);
-    /* expected: black should have scrolled to the upper half */
-    colr = GetPixel( hdc, (rc2.left+rc2.right)/ 2,  rc2.bottom / 4 );
-    ok ( colr == 0, "pixel should be black, color is %08x\n", colr);
+static INT_PTR WINAPI parent_dlg_proc(HWND hwnd, UINT msg, WPARAM wparam, LPARAM lparam)
+{
+    if (msg == WM_INITDIALOG) {
+        struct dlg_parent_param *param = (void*)lparam;
+        check_parents(hwnd, param->ga_parent, param->gwl_parent, param->get_parent, param->owner,
+                      param->root ? param->root : hwnd, param->ga_root_owner ? param->ga_root_owner : hwnd);
+
+        ok(!IsWindowEnabled(param->gwl_parent), "parent is not disabled\n");
+        EndDialog(hwnd, 2);
+        ok(IsWindowEnabled(param->gwl_parent), "parent is not enabled\n");
+    }
+
+    return 0;
+}
+
+static INT_PTR WINAPI reparent_dlg_proc(HWND hwnd, UINT msg, WPARAM wparam, LPARAM lparam)
+{
+    if (msg == WM_INITDIALOG) {
+        ok(!IsWindowEnabled(GetParent(hwnd)), "parent is not disabled\n");
+        SetParent(hwnd, (HWND)lparam);
+    }
+
+    return 0;
+}
+
+static INT_PTR WINAPI reparent_owned_dlg_proc(HWND hwnd, UINT msg, WPARAM wparam, LPARAM lparam)
+{
+    if (msg == WM_INITDIALOG) {
+        HWND new_parent = (HWND)lparam;
+        HWND owner = GetWindow(hwnd, GW_OWNER);
+        ok(!IsWindowEnabled(owner), "owner is not disabled\n");
+        SetWindowLongA(hwnd, GWL_STYLE, GetWindowLongA(hwnd, GWL_STYLE) | WS_CHILD);
+        SetParent(hwnd, new_parent);
+        ok(GetParent(hwnd) == new_parent, "GetParent(hwnd) = %p, expected %p\n", GetParent(hwnd), new_parent);
+        PostMessageA(hwnd, WM_QUIT, 0, 0);
+    }
+
+    return 0;
+}
+
+static LRESULT WINAPI reparent_dialog_owner_proc(HWND hwnd, UINT msg, WPARAM wparam, LPARAM lparam)
+{
+    if (msg == WM_ENTERIDLE) {
+        HWND dialog = (HWND)lparam;
+        HWND owner = GetParent(dialog);
+        /* EndDialog will enable owner */
+        EnableWindow(owner, FALSE);
+        EndDialog(dialog, 2);
+        ok(IsWindowEnabled(owner), "owner is not enabled\n");
+        /* ...but it won't be enabled on dialog exit */
+        EnableWindow(owner, FALSE);
+    }
+    return DefWindowProcA( hwnd, msg, wparam, lparam );
+}
+
+static LRESULT WINAPI post_quit_dialog_owner_proc(HWND hwnd, UINT msg, WPARAM wparam, LPARAM lparam)
+{
+    if (msg == WM_ENTERIDLE) {
+        HWND dialog = (HWND)lparam;
+        PostMessageA(dialog, WM_QUIT, 0, 0);
+    }
+    return DefWindowProcA( hwnd, msg, wparam, lparam );
+}
+
+static LRESULT WINAPI destroy_dialog_owner_proc(HWND hwnd, UINT msg, WPARAM wparam, LPARAM lparam)
+{
+    if (msg == WM_ENTERIDLE) {
+        HWND dialog = (HWND)lparam;
+        DestroyWindow(dialog);
+    }
+    return DefWindowProcA( hwnd, msg, wparam, lparam );
+}
+
+static void test_dialog_parent(void)
+{
+    HWND dialog, parent, child, child2, other, desktop = GetDesktopWindow();
+    struct dlg_parent_param param;
+    INT_PTR ret;
+    struct
+    {
+        DLGTEMPLATE dt;
+        WORD menu_name;
+        WORD class_id;
+        WORD class_atom;
+        WCHAR caption[1];
+    } dlg_data;
+
+    dlg_data.dt.dwExtendedStyle = 0;
+    dlg_data.dt.cdit = 0;
+    dlg_data.dt.x = 0;
+    dlg_data.dt.y = 0;
+    dlg_data.dt.cx = 100;
+    dlg_data.dt.cy = 100;
+    dlg_data.menu_name = 0;
+    dlg_data.class_id = 0;
+    dlg_data.class_atom = 0;
+    dlg_data.caption[0] = 0;
+
+    parent = CreateWindowExA(0, "static", NULL, WS_OVERLAPPEDWINDOW, 0, 0, 0, 0, NULL, NULL, NULL, NULL);
+    /* Create a child without WS_CHILD flag. It's a valid owner window. */
+    child = CreateWindowExA(0, "static", NULL, WS_OVERLAPPEDWINDOW, 0, 0, 0, 0, NULL, NULL, NULL, NULL);
+    SetParent(child, parent);
+    /* Regular child. If passed as an owner, its parent will be true owner window. */
+    child2 = CreateWindowExA(0, "static", NULL, WS_CHILD, 0, 0, 0, 0, child, NULL, NULL, NULL);
+
+    trace("parent %p child %p child2 %p desktop %p\n", parent, child, child2, desktop);
+
+    /* When dialog is created with WS_CHILD style, its parent depends on function used to create it. */
+    dlg_data.dt.style = WS_CHILD;
+
+    /* CreateDialogIndirectParam uses passed parent as dialog parent. */
+    dialog = CreateDialogIndirectParamA(GetModuleHandleA(NULL), &dlg_data.dt, child2, empty_dlg_proc, 0);
+    ok(dialog != 0, "dialog creation failed\n");
+    check_parents(dialog, child2, child2, child2, NULL, parent, child);
+
+    ok(IsWindowEnabled(child2), "child2 is disabled\n");
+    EnableWindow(child2, FALSE);
+    EndDialog(dialog, 0);
+    ok(IsWindowEnabled(child2), "child2 is not enabled\n");
+    DestroyWindow(dialog);
+
+    /* DialogBoxIndirectParam uses the first parent of passed owner that's not a child window as dialog
+     * parent (like in case of dialog with owner). */
+    param.ga_parent = param.gwl_parent = param.get_parent = child;
+    param.owner = NULL;
+    param.root = parent;
+    param.ga_root_owner = child;
+    ret = DialogBoxIndirectParamA(GetModuleHandleA(NULL), &dlg_data.dt, child2, parent_dlg_proc, (LPARAM)&param);
+    ok(ret == 2, "DialogBoxIndirectParam returned %ld\n", ret);
+
+    /* Dialogs without WS_CHILD behave as expected, they use passed owner just like CreateWindow does. */
+    dlg_data.dt.style = WS_OVERLAPPEDWINDOW;
+
+    dialog = CreateDialogIndirectParamA(GetModuleHandleA(NULL), &dlg_data.dt, child2, empty_dlg_proc, 0);
+    ok(dialog != 0, "dialog creation failed\n");
+    check_parents(dialog, desktop, child, NULL, child, dialog, dialog);
+
+    ok(IsWindowEnabled(child), "child is disabled\n");
+    EnableWindow(child, FALSE);
+    EndDialog(dialog, 0);
+    ok(IsWindowEnabled(child), "child is not enabled\n");
+    DestroyWindow(dialog);
+
+    param.ga_parent = desktop;
+    param.gwl_parent = child;
+    param.get_parent = NULL;
+    param.owner = child;
+    param.root = param.ga_root_owner = NULL;
+    ret = DialogBoxIndirectParamA(GetModuleHandleA(NULL), &dlg_data.dt, child2, parent_dlg_proc, (LPARAM)&param);
+    ok(ret == 2, "DialogBoxIndirectParam returned %ld\n", ret);
+
+    other = CreateWindowExA(0, "static", NULL, WS_OVERLAPPEDWINDOW, 0, 0, 0, 0, NULL, NULL, NULL, NULL);
+    SetWindowLongPtrA(child, GWLP_WNDPROC, (ULONG_PTR)reparent_dialog_owner_proc);
+
+    /* When dialog is created with WS_CHILD|WS_POPUP style, we have an owner. */
+    dlg_data.dt.style = WS_CHILD|WS_POPUP;
+
+    dialog = CreateDialogIndirectParamA(GetModuleHandleA(NULL), &dlg_data.dt, child2, empty_dlg_proc, 0);
+    ok(dialog != 0, "dialog creation failed\n");
+    check_parents(dialog, desktop, child, child, child, dialog, child);
+
+    ok(IsWindowEnabled(child), "child is disabled\n");
+    EnableWindow(child, FALSE);
+    EndDialog(dialog, 0);
+    ok(IsWindowEnabled(child), "child is not enabled\n");
+    DestroyWindow(dialog);
+
+    param.ga_parent = desktop;
+    param.gwl_parent = param.get_parent = child;
+    param.owner = child;
+    param.root = NULL;
+    param.ga_root_owner = child;
+    ret = DialogBoxIndirectParamA(GetModuleHandleA(NULL), &dlg_data.dt, child2, parent_dlg_proc, (LPARAM)&param);
+    ok(ret == 2, "DialogBoxIndirectParam returned %ld\n", ret);
+
+    /* If we change parent in WM_INITDIALOG for WS_CHILD dialog WM_ENTERIDLE is still sent to the original
+     * parent. EndDialog will enable the new parent. */
+    EnableWindow(child, TRUE);
+    EnableWindow(other, FALSE);
+    dlg_data.dt.style = WS_CHILD;
+    ret = DialogBoxIndirectParamA(GetModuleHandleA(NULL), &dlg_data.dt, child2, reparent_dlg_proc, (LPARAM)other);
+    ok(ret == 2, "DialogBoxIndirectParam returned %ld\n", ret);
+    ok(!IsWindowEnabled(other), "other is not disabled\n");
+    ok(!IsWindowEnabled(child), "child is not disabled\n");
+    ok(IsWindowEnabled(child2), "child2 is not enabled\n");
+    EnableWindow(child, TRUE);
+
+    /* If we change parent and style in WM_INITDIALOG for dialog with an owner to make it true child
+     * (thus GetParent() will return the new parent instead of an owner), WM_ENTERIDLE is still sent
+     * to the original parent. EndDialog will enable the new parent. */
+    EnableWindow(other, FALSE);
+    dlg_data.dt.style = WS_OVERLAPPED;
+    ret = DialogBoxIndirectParamA(GetModuleHandleA(NULL), &dlg_data.dt, child2, reparent_owned_dlg_proc, (LPARAM)other);
+    ok(ret == 1, "DialogBoxIndirectParam returned %ld\n", ret);
+    ok(!IsWindowEnabled(other), "other is not disabled\n");
+    ok(!IsWindowEnabled(child), "child is not disabled\n");
+    ok(IsWindowEnabled(child2), "child2 is not enabled\n");
+    EnableWindow(child, TRUE);
+    EnableWindow(other, TRUE);
+
+    /* Quit dialog message loop by sending WM_QUIT message. Dialog owner is not enabled. */
+    SetWindowLongPtrA(child, GWLP_WNDPROC, (ULONG_PTR)post_quit_dialog_owner_proc);
+    ret = DialogBoxIndirectParamA(GetModuleHandleA(NULL), &dlg_data.dt, other, empty_dlg_proc, 0);
+    ok(ret == 1, "DialogBoxIndirectParam returned %ld\n", ret);
+    ok(!IsWindowEnabled(other), "other is enabled\n");
+    EnableWindow(other, TRUE);
+
+    /* Quit dialog message loop by destroying the window. Dialog owner is not enabled. */
+    SetWindowLongPtrA(child, GWLP_WNDPROC, (ULONG_PTR)destroy_dialog_owner_proc);
+    ret = DialogBoxIndirectParamA(GetModuleHandleA(NULL), &dlg_data.dt, other, empty_dlg_proc, 0);
+    ok(ret == 1, "DialogBoxIndirectParam returned %ld\n", ret);
+    ok(!IsWindowEnabled(other), "other is enabled\n");
+    EnableWindow(other, TRUE);
+
+    DestroyWindow(parent);
+}
+
+static void test_scrollwindow( HWND hwnd)
+{
+    HDC hdc;
+    RECT rc, rc2, rc3;
+    COLORREF colr;
+
+    ShowWindow( hwnd, SW_SHOW);
+    UpdateWindow( hwnd);
+    flush_events( TRUE );
+    GetClientRect( hwnd, &rc);
+    hdc = GetDC( hwnd);
+    /* test ScrollWindow(Ex) with no clip rectangle */
+    /* paint the lower half of the window black */
+    rc2 = rc;
+    rc2.top = ( rc2.top + rc2.bottom) / 2;
+    FillRect( hdc, &rc2, GetStockObject(BLACK_BRUSH));
+    /* paint the upper half of the window white */
+    rc2.bottom = rc2.top;
+    rc2.top =0;
+    FillRect( hdc, &rc2, GetStockObject(WHITE_BRUSH));
+    /* scroll lower half up */
+    rc2 = rc;
+    rc2.top = ( rc2.top + rc2.bottom) / 2;
+    ScrollWindowEx( hwnd, 0, - rc2.top, &rc2, NULL, NULL, NULL, SW_ERASE);
+    flush_events(FALSE);
+    /* expected: black should have scrolled to the upper half */
+    colr = GetPixel( hdc, (rc2.left+rc2.right)/ 2,  rc2.bottom / 4 );
+    ok ( colr == 0, "pixel should be black, color is %08x\n", colr);
+    /* Repeat that test of ScrollWindow(Ex) now with clip rectangle */
+    /* paint the lower half of the window black */
+    rc2 = rc;
+    rc2.top = ( rc2.top + rc2.bottom) / 2;
+    FillRect( hdc, &rc2, GetStockObject(BLACK_BRUSH));
+    /* paint the upper half of the window white */
+    rc2.bottom = rc2.top;
+    rc2.top =0;
+    FillRect( hdc, &rc2, GetStockObject(WHITE_BRUSH));
+    /* scroll lower half up */
+    rc2 = rc;
+    rc2.top = ( rc2.top + rc2.bottom) / 2;
+    rc3 = rc;
+    rc3.left = rc3.right / 4;
+    rc3.right -= rc3.right / 4;
+    ScrollWindowEx( hwnd, 0, - rc2.top, &rc2, &rc3, NULL, NULL, SW_ERASE);
+    flush_events(FALSE);
+    /* expected: black should have scrolled to the upper half */
+    colr = GetPixel( hdc, (rc2.left+rc2.right)/ 2,  rc2.bottom / 4 );
+    ok ( colr == 0, "pixel should be black, color is %08x\n", colr);
 
     /* clean up */
     ReleaseDC( hwnd, hdc);
@@ -4147,7 +4814,7 @@ static void test_scrollvalidate( HWND parent)
     SetRectRgn( clipping, 10, 10, 90, 90);
     hdc = GetDC( hwnd1);
     /* for a visual touch */
-    TextOut( hdc, 0,10, "0123456789", 10);
+    TextOutA( hdc, 0,10, "0123456789", 10);
     ScrollDC( hdc, -10, -5, &rc, &cliprc, hrgn, &rcu);
     if (winetest_debug > 0) dump_region(hrgn);
     /* create a region with what is expected */
@@ -4174,11 +4841,25 @@ static void test_scrollvalidate( HWND parent)
             rcu.left,rcu.top,rcu.right,rcu.bottom);
     ReleaseDC( hwnd1, hdc);
 
-    /* test scrolling a window with an update region */
+    /* test scrolling a rect by more than its size */
     DestroyWindow( hwnd2);
     ValidateRect( hwnd1, NULL);
     SetRect( &rc, 40,40, 50,50);
     InvalidateRect( hwnd1, &rc, 1);
+    ScrollWindowEx( hwnd1, -20, 0, &rc, NULL, hrgn, &rcu,
+      SW_SCROLLCHILDREN | SW_INVALIDATE);
+    if (winetest_debug > 0) dump_region(hrgn);
+    SetRectRgn( exprgn, 20, 40, 30, 50);
+    SetRectRgn( tmprgn, 40, 40, 50, 50);
+    CombineRgn( exprgn, exprgn, tmprgn, RGN_OR);
+    ok( EqualRgn( exprgn, hrgn), "wrong update region\n");
+    ok( rcu.left == 20 && rcu.top == 40 && rcu.right == 50 && rcu.bottom == 50,
+        "unexpected update rect: %d,%d - %d,%d\n", rcu.left,rcu.top,rcu.right,rcu.bottom);
+
+    /* test scrolling a window with an update region */
+    ValidateRect( hwnd1, NULL);
+    SetRect( &rc, 40,40, 50,50);
+    InvalidateRect( hwnd1, &rc, 1);
     GetClientRect( hwnd1, &rc);
     cliprc=rc;
     ScrollWindowEx( hwnd1, -10, 0, &rc, &cliprc, hrgn, &rcu,
@@ -4205,12 +4886,12 @@ static void test_scrollvalidate( HWND parent)
     hwnd2 = CreateWindowExA(0, "static", NULL,
             WS_CHILD| WS_VISIBLE | WS_BORDER ,
             50, 50, 100, 100, hwnd1, 0, 0, NULL);
-    SetWindowLong( hwnd1, GWL_STYLE, GetWindowLong( hwnd1, GWL_STYLE) & ~WS_CLIPSIBLINGS);
+    SetWindowLongA( hwnd1, GWL_STYLE, GetWindowLongA( hwnd1, GWL_STYLE) & ~WS_CLIPSIBLINGS);
     GetClientRect( hwnd1, &rc);
     cliprc=rc;
 
     /* WS_CLIPCHILDREN and SW_SCROLLCHILDREN */
-    SetWindowLong( hwnd1, GWL_STYLE, GetWindowLong( hwnd1, GWL_STYLE) | WS_CLIPCHILDREN );
+    SetWindowLongA( hwnd1, GWL_STYLE, GetWindowLongA( hwnd1, GWL_STYLE) | WS_CLIPCHILDREN );
     ValidateRect( hwnd1, NULL);
     ValidateRect( hwnd2, NULL);
     ScrollWindowEx( hwnd1, -10, -10, &rc, &cliprc, hrgn, &rcu,
@@ -4222,7 +4903,7 @@ static void test_scrollvalidate( HWND parent)
     ok( EqualRgn( exprgn, hrgn), "wrong update region\n");
 
     /* SW_SCROLLCHILDREN */
-    SetWindowLong( hwnd1, GWL_STYLE, GetWindowLong( hwnd1, GWL_STYLE) & ~WS_CLIPCHILDREN );
+    SetWindowLongA( hwnd1, GWL_STYLE, GetWindowLongA( hwnd1, GWL_STYLE) & ~WS_CLIPCHILDREN );
     ValidateRect( hwnd1, NULL);
     ValidateRect( hwnd2, NULL);
     ScrollWindowEx( hwnd1, -10, -10, &rc, &cliprc, hrgn, &rcu, SW_SCROLLCHILDREN | SW_INVALIDATE);
@@ -4231,7 +4912,7 @@ static void test_scrollvalidate( HWND parent)
     ok( EqualRgn( exprgn, hrgn), "wrong update region\n");
 
     /* no SW_SCROLLCHILDREN */
-    SetWindowLong( hwnd1, GWL_STYLE, GetWindowLong( hwnd1, GWL_STYLE) & ~WS_CLIPCHILDREN );
+    SetWindowLongA( hwnd1, GWL_STYLE, GetWindowLongA( hwnd1, GWL_STYLE) & ~WS_CLIPCHILDREN );
     ValidateRect( hwnd1, NULL);
     ValidateRect( hwnd2, NULL);
     ScrollWindowEx( hwnd1, -10, -10, &rc, &cliprc, hrgn, &rcu, SW_INVALIDATE);
@@ -4240,7 +4921,7 @@ static void test_scrollvalidate( HWND parent)
     ok( EqualRgn( exprgn, hrgn), "wrong update region\n");
 
     /* WS_CLIPCHILDREN and no SW_SCROLLCHILDREN */
-    SetWindowLong( hwnd1, GWL_STYLE, GetWindowLong( hwnd1, GWL_STYLE) | WS_CLIPCHILDREN );
+    SetWindowLongA( hwnd1, GWL_STYLE, GetWindowLongA( hwnd1, GWL_STYLE) | WS_CLIPCHILDREN );
     ValidateRect( hwnd1, NULL);
     ValidateRect( hwnd2, NULL);
     ScrollWindowEx( hwnd1, -10, -10, &rc, &cliprc, hrgn, &rcu, SW_INVALIDATE);
@@ -4386,7 +5067,7 @@ static void test_params(void)
     if (pGetMonitorInfoA)
     {
         SetLastError(0xdeadbeef);
-        rc = GetWindowText(hwndMain2, NULL, 1024);
+        rc = GetWindowTextA(hwndMain2, NULL, 1024);
         ok( rc==0, "GetWindowText: rc=%d err=%d\n",rc,GetLastError());
     }
     else
@@ -4396,7 +5077,7 @@ static void test_params(void)
     }
 
     SetLastError(0xdeadbeef);
-    hwnd=CreateWindow("LISTBOX", "TestList",
+    hwnd=CreateWindowA("LISTBOX", "TestList",
                       (LBS_STANDARD & ~LBS_SORT),
                       0, 0, 100, 100,
                       NULL, (HMENU)1, NULL, 0);
@@ -4413,7 +5094,7 @@ static void test_AWRwindow(LPCSTR class, LONG style, LONG exStyle, BOOL menu)
 {
     HWND hwnd = 0;
 
-    hwnd = CreateWindowEx(exStyle, class, class, style,
+    hwnd = CreateWindowExA(exStyle, class, class, style,
                          110, 100,
                          225, 200,
                          0,
@@ -4433,20 +5114,20 @@ static void test_AWRwindow(LPCSTR class, LONG style, LONG exStyle, BOOL menu)
 
 static BOOL AWR_init(void)
 {
-    WNDCLASS class;
+    WNDCLASSA class;
 
     class.style         = CS_HREDRAW | CS_VREDRAW;
     class.lpfnWndProc     = DefWindowProcA;
     class.cbClsExtra    = 0;
     class.cbWndExtra    = 0;
     class.hInstance     = 0;
-    class.hIcon         = LoadIcon (0, IDI_APPLICATION);
-    class.hCursor       = LoadCursor (0, IDC_ARROW);
+    class.hIcon         = LoadIconA(0, (LPCSTR)IDI_APPLICATION);
+    class.hCursor       = LoadCursorA(0, (LPCSTR)IDC_ARROW);
     class.hbrBackground = 0;
     class.lpszMenuName  = 0;
     class.lpszClassName = szAWRClass;
-    
-    if (!RegisterClass (&class)) {
+
+    if (!RegisterClassA(&class)) {
        ok(FALSE, "RegisterClass failed\n");
        return FALSE;
     }
@@ -4455,34 +5136,24 @@ static BOOL AWR_init(void)
     if (!hmenu)
        return FALSE;
     ok(hmenu != 0, "Failed to create menu\n");
-    ok(AppendMenu(hmenu, MF_STRING, 1, "Test!"), "Failed to create menu item\n");
-    
+    ok(AppendMenuA(hmenu, MF_STRING, 1, "Test!"), "Failed to create menu item\n");
+
     return TRUE;
 }
 
 
 static void test_AWR_window_size(BOOL menu)
 {
-    LONG styles[] = {
-       WS_POPUP,
-       WS_MAXIMIZE, WS_BORDER, WS_DLGFRAME, 
-       WS_SYSMENU, 
-       WS_THICKFRAME,
-       WS_MINIMIZEBOX, WS_MAXIMIZEBOX,
-       WS_HSCROLL, WS_VSCROLL
+    static const DWORD styles[] = {
+        WS_POPUP, WS_MAXIMIZE, WS_BORDER, WS_DLGFRAME, WS_CAPTION, WS_SYSMENU,
+        WS_THICKFRAME, WS_MINIMIZEBOX, WS_MAXIMIZEBOX, WS_HSCROLL, WS_VSCROLL
     };
-    LONG exStyles[] = {
-       WS_EX_CLIENTEDGE,
-       WS_EX_TOOLWINDOW, WS_EX_WINDOWEDGE,
-       WS_EX_APPWINDOW,
-#if 0
-       /* These styles have problems on (at least) WinXP (SP2) and Wine */
-       WS_EX_DLGMODALFRAME, 
-       WS_EX_STATICEDGE, 
-#endif
+    static const DWORD exStyles[] = {
+       WS_EX_CLIENTEDGE, WS_EX_TOOLWINDOW, WS_EX_WINDOWEDGE, WS_EX_APPWINDOW,
+       WS_EX_DLGMODALFRAME, WS_EX_DLGMODALFRAME | WS_EX_STATICEDGE
     };
 
-    int i;    
+    unsigned int i;
 
     /* A exhaustive check of all the styles takes too long
      * so just do a (hopefully representative) sample
@@ -4494,6 +5165,33 @@ static void test_AWR_window_size(BOOL menu)
         test_AWRwindow(szAWRClass, WS_THICKFRAME, exStyles[i], menu);
     }
 }
+
+static void test_AWR_flags(void)
+{
+    static const DWORD styles[] = { WS_POPUP, WS_BORDER, WS_DLGFRAME, WS_THICKFRAME };
+    static const DWORD exStyles[] = { WS_EX_CLIENTEDGE, WS_EX_TOOLWINDOW, WS_EX_WINDOWEDGE,
+                                      WS_EX_APPWINDOW, WS_EX_DLGMODALFRAME, WS_EX_STATICEDGE };
+
+    DWORD i, j, k, style, exstyle;
+    RECT rect, rect2;
+
+    for (i = 0; i < (1 << COUNTOF(styles)); i++)
+    {
+        for (k = style = 0; k < COUNTOF(styles); k++) if (i & (1 << k)) style |= styles[k];
+
+        for (j = 0; j < (1 << COUNTOF(exStyles)); j++)
+        {
+            for (k = exstyle = 0; k < COUNTOF(exStyles); k++) if (j & (1 << k)) exstyle |= exStyles[k];
+            SetRect( &rect, 100, 100, 200, 200 );
+            rect2 = rect;
+            AdjustWindowRectEx( &rect, style, FALSE, exstyle );
+            wine_AdjustWindowRectEx( &rect2, style, FALSE, exstyle );
+            ok( EqualRect( &rect, &rect2 ), "rects do not match: win %d,%d-%d,%d wine %d,%d-%d,%d\n",
+                rect.left, rect.top, rect.right, rect.bottom,
+                rect2.left, rect2.top, rect2.right, rect2.bottom );
+        }
+    }
+}
 #undef COUNTOF
 
 #define SHOWSYSMETRIC(SM) trace(#SM "=%d\n", GetSystemMetrics(SM))
@@ -4519,6 +5217,7 @@ static void test_AdjustWindowRect(void)
 
     test_AWR_window_size(FALSE);
     test_AWR_window_size(TRUE);
+    test_AWR_flags();
 
     DestroyMenu(hmenu);
 }
@@ -4543,7 +5242,7 @@ static LRESULT WINAPI redraw_window_procA(HWND hwnd, UINT msg, WPARAM wparam, LP
         }
         return 0;
     }
-    return DefWindowProc(hwnd, msg, wparam, lparam);
+    return DefWindowProcA(hwnd, msg, wparam, lparam);
 }
 
 /* Ensure we exit from RedrawNow regardless of invalidated area */
@@ -4558,7 +5257,7 @@ static void test_redrawnow(void)
    cls.cbWndExtra = 0;
    cls.hInstance = GetModuleHandleA(0);
    cls.hIcon = 0;
-   cls.hCursor = LoadCursorA(0, IDC_ARROW);
+   cls.hCursor = LoadCursorA(0, (LPCSTR)IDC_ARROW);
    cls.hbrBackground = GetStockObject(WHITE_BRUSH);
    cls.lpszMenuName = NULL;
    cls.lpszClassName = "RedrawWindowClass";
@@ -4622,7 +5321,7 @@ static LRESULT WINAPI parentdc_window_procA(HWND hwnd, UINT msg, WPARAM wparam,
         EndPaint(hwnd, &ps);
         return 0;
     }
-    return DefWindowProc(hwnd, msg, wparam, lparam);
+    return DefWindowProcA(hwnd, msg, wparam, lparam);
 }
 
 static void zero_parentdc_stat(struct parentdc_stat *t)
@@ -4645,8 +5344,8 @@ static void zero_parentdc_test(struct parentdc_test *t)
       t.w.r.f, got.w.r.f)
 
 #define parentdc_todo_field_ok(t, w, r, f, got) \
-  if (t.w##_todo.r.f) todo_wine { parentdc_field_ok(t, w, r, f, got); } \
-  else parentdc_field_ok(t, w, r, f, got)
+  todo_wine_if (t.w##_todo.r.f) \
+      parentdc_field_ok(t, w, r, f, got);
 
 #define parentdc_rect_ok(t, w, r, got) \
   parentdc_todo_field_ok(t, w, r, left, got); \
@@ -4729,7 +5428,7 @@ static void test_csparentdc(void)
    clsMain.cbWndExtra = 0;
    clsMain.hInstance = GetModuleHandleA(0);
    clsMain.hIcon = 0;
-   clsMain.hCursor = LoadCursorA(0, IDC_ARROW);
+   clsMain.hCursor = LoadCursorA(0, (LPCSTR)IDC_ARROW);
    clsMain.hbrBackground = GetStockObject(WHITE_BRUSH);
    clsMain.lpszMenuName = NULL;
    clsMain.lpszClassName = "ParentDcMainWindowClass";
@@ -4745,7 +5444,7 @@ static void test_csparentdc(void)
    cls.cbWndExtra = 0;
    cls.hInstance = GetModuleHandleA(0);
    cls.hIcon = 0;
-   cls.hCursor = LoadCursorA(0, IDC_ARROW);
+   cls.hCursor = LoadCursorA(0, (LPCSTR)IDC_ARROW);
    cls.hbrBackground = GetStockObject(WHITE_BRUSH);
    cls.lpszMenuName = NULL;
    cls.lpszClassName = "ParentDcWindowClass";
@@ -4837,6 +5536,7 @@ static void test_IsWindowUnicode(void)
     WNDCLASSA classA;
     WNDCLASSW classW;
     HWND hwnd;
+    ATOM atom;
 
     memset(&classW, 0, sizeof(classW));
     classW.hInstance = GetModuleHandleA(0);
@@ -4848,7 +5548,8 @@ static void test_IsWindowUnicode(void)
     classA.hInstance = GetModuleHandleA(0);
     classA.lpfnWndProc = def_window_procA;
     classA.lpszClassName = ansi_class_nameA;
-    assert(RegisterClassA(&classA));
+    atom = RegisterClassA(&classA);
+    assert(atom);
 
     /* unicode class: window proc */
     hwnd = CreateWindowExW(0, unicode_class_nameW, NULL, WS_POPUP,
@@ -4950,11 +5651,11 @@ static LRESULT CALLBACK minmax_wnd_proc(HWND hwnd, UINT msg, WPARAM wp, LPARAM l
     MINMAXINFO *minmax;
 
     if (msg != WM_GETMINMAXINFO)
-        return DefWindowProc(hwnd, msg, wp, lp);
+        return DefWindowProcA(hwnd, msg, wp, lp);
 
     minmax = (MINMAXINFO *)lp;
 
-    if ((GetWindowLong(hwnd, GWL_STYLE) & WS_CHILD))
+    if ((GetWindowLongA(hwnd, GWL_STYLE) & WS_CHILD))
     {
         minmax->ptReserved.x = 0;
         minmax->ptReserved.y = 0;
@@ -4968,7 +5669,7 @@ static LRESULT CALLBACK minmax_wnd_proc(HWND hwnd, UINT msg, WPARAM wp, LPARAM l
         minmax->ptMinTrackSize.y = 100;
     }
     else
-        DefWindowProc(hwnd, msg, wp, lp);
+        DefWindowProcA(hwnd, msg, wp, lp);
     return 1;
 }
 
@@ -4985,7 +5686,7 @@ static LRESULT CALLBACK winsizes_wnd_proc(HWND hwnd, UINT msg, WPARAM wp, LPARAM
         GetWindowRect( hwnd, &rect );
         ok( !rect.left && !rect.top && !rect.right && !rect.bottom,
             "wrong rect %d,%d-%d,%d\n", rect.left, rect.top, rect.right, rect.bottom );
-        return DefWindowProc(hwnd, msg, wp, lp);
+        return DefWindowProcA(hwnd, msg, wp, lp);
     }
     case WM_NCCREATE:
     case WM_CREATE:
@@ -5010,7 +5711,7 @@ static LRESULT CALLBACK winsizes_wnd_proc(HWND hwnd, UINT msg, WPARAM wp, LPARAM
             "wrong rect %d,%d-%d,%d / %d,%d-%d,%d\n",
             rect.left, rect.top, rect.right, rect.bottom,
             expected_rect.left, expected_rect.top, expected_rect.right, expected_rect.bottom );
-        return DefWindowProc(hwnd, msg, wp, lp);
+        return DefWindowProcA(hwnd, msg, wp, lp);
     }
     case WM_NCCALCSIZE:
     {
@@ -5019,16 +5720,16 @@ static LRESULT CALLBACK winsizes_wnd_proc(HWND hwnd, UINT msg, WPARAM wp, LPARAM
         ok( !memcmp( &rect, r, sizeof(rect) ),
             "passed rect %d,%d-%d,%d doesn't match window rect %d,%d-%d,%d\n",
             r->left, r->top, r->right, r->bottom, rect.left, rect.top, rect.right, rect.bottom );
-        return DefWindowProc(hwnd, msg, wp, lp);
+        return DefWindowProcA(hwnd, msg, wp, lp);
     }
     default:
-        return DefWindowProc(hwnd, msg, wp, lp);
+        return DefWindowProcA(hwnd, msg, wp, lp);
     }
 }
 
 static void test_CreateWindow(void)
 {
-    WNDCLASS cls;
+    WNDCLASSA cls;
     HWND hwnd, parent;
     HMENU hmenu;
     RECT rc, rc_minmax;
@@ -5041,10 +5742,10 @@ static void test_CreateWindow(void)
     ok(res, "GetMenu error %d\n", GetLastError())
 
 #define expect_style(window, style)\
-    ok((ULONG)GetWindowLong(window, GWL_STYLE) == (style), "expected style %x != %x\n", (LONG)(style), GetWindowLong(window, GWL_STYLE))
+    ok((ULONG)GetWindowLongA(window, GWL_STYLE) == (style), "expected style %x != %x\n", (LONG)(style), GetWindowLongA(window, GWL_STYLE))
 
 #define expect_ex_style(window, ex_style)\
-    ok((ULONG)GetWindowLong(window, GWL_EXSTYLE) == (ex_style), "expected ex_style %x != %x\n", (LONG)(ex_style), GetWindowLong(window, GWL_EXSTYLE))
+    ok((ULONG)GetWindowLongA(window, GWL_EXSTYLE) == (ex_style), "expected ex_style %x != %x\n", (LONG)(ex_style), GetWindowLongA(window, GWL_EXSTYLE))
 
 #define expect_gle_broken_9x(gle)\
     ok(GetLastError() == gle ||\
@@ -5062,7 +5763,7 @@ static void test_CreateWindow(void)
 
     /* WS_CHILD */
     SetLastError(0xdeadbeef);
-    hwnd = CreateWindowEx(WS_EX_APPWINDOW, "static", NULL, WS_CHILD,
+    hwnd = CreateWindowExA(WS_EX_APPWINDOW, "static", NULL, WS_CHILD,
                            0, 0, 100, 100, parent, (HMENU)1, 0, NULL);
     ok(hwnd != 0, "CreateWindowEx error %d\n", GetLastError());
     expect_menu(hwnd, 1);
@@ -5071,7 +5772,7 @@ static void test_CreateWindow(void)
     DestroyWindow(hwnd);
 
     SetLastError(0xdeadbeef);
-    hwnd = CreateWindowEx(WS_EX_APPWINDOW, "static", NULL, WS_CHILD | WS_CAPTION,
+    hwnd = CreateWindowExA(WS_EX_APPWINDOW, "static", NULL, WS_CHILD | WS_CAPTION,
                            0, 0, 100, 100, parent, (HMENU)1, 0, NULL);
     ok(hwnd != 0, "CreateWindowEx error %d\n", GetLastError());
     expect_menu(hwnd, 1);
@@ -5080,7 +5781,7 @@ static void test_CreateWindow(void)
     DestroyWindow(hwnd);
 
     SetLastError(0xdeadbeef);
-    hwnd = CreateWindowEx(0, "static", NULL, WS_CHILD,
+    hwnd = CreateWindowExA(0, "static", NULL, WS_CHILD,
                            0, 0, 100, 100, parent, (HMENU)1, 0, NULL);
     ok(hwnd != 0, "CreateWindowEx error %d\n", GetLastError());
     expect_menu(hwnd, 1);
@@ -5089,7 +5790,7 @@ static void test_CreateWindow(void)
     DestroyWindow(hwnd);
 
     SetLastError(0xdeadbeef);
-    hwnd = CreateWindowEx(0, "static", NULL, WS_CHILD | WS_CAPTION,
+    hwnd = CreateWindowExA(0, "static", NULL, WS_CHILD | WS_CAPTION,
                            0, 0, 100, 100, parent, (HMENU)1, 0, NULL);
     ok(hwnd != 0, "CreateWindowEx error %d\n", GetLastError());
     expect_menu(hwnd, 1);
@@ -5099,7 +5800,7 @@ static void test_CreateWindow(void)
 
     /* WS_POPUP */
     SetLastError(0xdeadbeef);
-    hwnd = CreateWindowEx(WS_EX_APPWINDOW, "static", NULL, WS_POPUP,
+    hwnd = CreateWindowExA(WS_EX_APPWINDOW, "static", NULL, WS_POPUP,
                            0, 0, 100, 100, parent, hmenu, 0, NULL);
     ok(hwnd != 0, "CreateWindowEx error %d\n", GetLastError());
     expect_menu(hwnd, hmenu);
@@ -5113,7 +5814,7 @@ static void test_CreateWindow(void)
     hmenu = CreateMenu();
     assert(hmenu != 0);
     SetLastError(0xdeadbeef);
-    hwnd = CreateWindowEx(WS_EX_APPWINDOW, "static", NULL, WS_POPUP | WS_CAPTION,
+    hwnd = CreateWindowExA(WS_EX_APPWINDOW, "static", NULL, WS_POPUP | WS_CAPTION,
                            0, 0, 100, 100, parent, hmenu, 0, NULL);
     ok(hwnd != 0, "CreateWindowEx error %d\n", GetLastError());
     expect_menu(hwnd, hmenu);
@@ -5127,7 +5828,7 @@ static void test_CreateWindow(void)
     hmenu = CreateMenu();
     assert(hmenu != 0);
     SetLastError(0xdeadbeef);
-    hwnd = CreateWindowEx(0, "static", NULL, WS_POPUP,
+    hwnd = CreateWindowExA(0, "static", NULL, WS_POPUP,
                            0, 0, 100, 100, parent, hmenu, 0, NULL);
     ok(hwnd != 0, "CreateWindowEx error %d\n", GetLastError());
     expect_menu(hwnd, hmenu);
@@ -5141,7 +5842,7 @@ static void test_CreateWindow(void)
     hmenu = CreateMenu();
     assert(hmenu != 0);
     SetLastError(0xdeadbeef);
-    hwnd = CreateWindowEx(0, "static", NULL, WS_POPUP | WS_CAPTION,
+    hwnd = CreateWindowExA(0, "static", NULL, WS_POPUP | WS_CAPTION,
                            0, 0, 100, 100, parent, hmenu, 0, NULL);
     ok(hwnd != 0, "CreateWindowEx error %d\n", GetLastError());
     expect_menu(hwnd, hmenu);
@@ -5154,7 +5855,7 @@ static void test_CreateWindow(void)
 
     /* WS_CHILD | WS_POPUP */
     SetLastError(0xdeadbeef);
-    hwnd = CreateWindowEx(WS_EX_APPWINDOW, "static", NULL, WS_CHILD | WS_POPUP,
+    hwnd = CreateWindowExA(WS_EX_APPWINDOW, "static", NULL, WS_CHILD | WS_POPUP,
                            0, 0, 100, 100, parent, (HMENU)1, 0, NULL);
     ok(!hwnd || broken(hwnd != 0 /* Win9x */), "CreateWindowEx should fail\n");
     expect_gle_broken_9x(ERROR_INVALID_MENU_HANDLE);
@@ -5164,7 +5865,7 @@ static void test_CreateWindow(void)
     hmenu = CreateMenu();
     assert(hmenu != 0);
     SetLastError(0xdeadbeef);
-    hwnd = CreateWindowEx(WS_EX_APPWINDOW, "static", NULL, WS_CHILD | WS_POPUP,
+    hwnd = CreateWindowExA(WS_EX_APPWINDOW, "static", NULL, WS_CHILD | WS_POPUP,
                            0, 0, 100, 100, parent, hmenu, 0, NULL);
     ok(hwnd != 0, "CreateWindowEx error %d\n", GetLastError());
     expect_menu(hwnd, hmenu);
@@ -5176,7 +5877,7 @@ static void test_CreateWindow(void)
     expect_gle_broken_9x(ERROR_INVALID_MENU_HANDLE);
 
     SetLastError(0xdeadbeef);
-    hwnd = CreateWindowEx(WS_EX_APPWINDOW, "static", NULL, WS_CHILD | WS_POPUP | WS_CAPTION,
+    hwnd = CreateWindowExA(WS_EX_APPWINDOW, "static", NULL, WS_CHILD | WS_POPUP | WS_CAPTION,
                            0, 0, 100, 100, parent, (HMENU)1, 0, NULL);
     ok(!hwnd || broken(hwnd != 0 /* Win9x */), "CreateWindowEx should fail\n");
     expect_gle_broken_9x(ERROR_INVALID_MENU_HANDLE);
@@ -5186,7 +5887,7 @@ static void test_CreateWindow(void)
     hmenu = CreateMenu();
     assert(hmenu != 0);
     SetLastError(0xdeadbeef);
-    hwnd = CreateWindowEx(WS_EX_APPWINDOW, "static", NULL, WS_CHILD | WS_POPUP | WS_CAPTION,
+    hwnd = CreateWindowExA(WS_EX_APPWINDOW, "static", NULL, WS_CHILD | WS_POPUP | WS_CAPTION,
                            0, 0, 100, 100, parent, hmenu, 0, NULL);
     ok(hwnd != 0, "CreateWindowEx error %d\n", GetLastError());
     expect_menu(hwnd, hmenu);
@@ -5198,7 +5899,7 @@ static void test_CreateWindow(void)
     expect_gle_broken_9x(ERROR_INVALID_MENU_HANDLE);
 
     SetLastError(0xdeadbeef);
-    hwnd = CreateWindowEx(0, "static", NULL, WS_CHILD | WS_POPUP,
+    hwnd = CreateWindowExA(0, "static", NULL, WS_CHILD | WS_POPUP,
                            0, 0, 100, 100, parent, (HMENU)1, 0, NULL);
     ok(!hwnd || broken(hwnd != 0 /* Win9x */), "CreateWindowEx should fail\n");
     expect_gle_broken_9x(ERROR_INVALID_MENU_HANDLE);
@@ -5208,7 +5909,7 @@ static void test_CreateWindow(void)
     hmenu = CreateMenu();
     assert(hmenu != 0);
     SetLastError(0xdeadbeef);
-    hwnd = CreateWindowEx(0, "static", NULL, WS_CHILD | WS_POPUP,
+    hwnd = CreateWindowExA(0, "static", NULL, WS_CHILD | WS_POPUP,
                            0, 0, 100, 100, parent, hmenu, 0, NULL);
     ok(hwnd != 0, "CreateWindowEx error %d\n", GetLastError());
     expect_menu(hwnd, hmenu);
@@ -5220,7 +5921,7 @@ static void test_CreateWindow(void)
     expect_gle_broken_9x(ERROR_INVALID_MENU_HANDLE);
 
     SetLastError(0xdeadbeef);
-    hwnd = CreateWindowEx(0, "static", NULL, WS_CHILD | WS_POPUP | WS_CAPTION,
+    hwnd = CreateWindowExA(0, "static", NULL, WS_CHILD | WS_POPUP | WS_CAPTION,
                            0, 0, 100, 100, parent, (HMENU)1, 0, NULL);
     ok(!hwnd || broken(hwnd != 0 /* Win9x */), "CreateWindowEx should fail\n");
     expect_gle_broken_9x(ERROR_INVALID_MENU_HANDLE);
@@ -5230,7 +5931,7 @@ static void test_CreateWindow(void)
     hmenu = CreateMenu();
     assert(hmenu != 0);
     SetLastError(0xdeadbeef);
-    hwnd = CreateWindowEx(0, "static", NULL, WS_CHILD | WS_POPUP | WS_CAPTION,
+    hwnd = CreateWindowExA(0, "static", NULL, WS_CHILD | WS_POPUP | WS_CAPTION,
                            0, 0, 100, 100, parent, hmenu, 0, NULL);
     ok(hwnd != 0, "CreateWindowEx error %d\n", GetLastError());
     expect_menu(hwnd, hmenu);
@@ -5246,16 +5947,16 @@ static void test_CreateWindow(void)
     cls.lpfnWndProc = minmax_wnd_proc;
     cls.cbClsExtra = 0;
     cls.cbWndExtra = 0;
-    cls.hInstance = GetModuleHandle(0);
+    cls.hInstance = GetModuleHandleA(NULL);
     cls.hIcon = 0;
-    cls.hCursor = LoadCursorA(0, IDC_ARROW);
+    cls.hCursor = LoadCursorA(0, (LPCSTR)IDC_ARROW);
     cls.hbrBackground = GetStockObject(WHITE_BRUSH);
     cls.lpszMenuName = NULL;
     cls.lpszClassName = "MinMax_WndClass";
-    RegisterClass(&cls);
+    RegisterClassA(&cls);
 
     SetLastError(0xdeadbeef);
-    parent = CreateWindowEx(0, "MinMax_WndClass", NULL, WS_CAPTION | WS_SYSMENU | WS_THICKFRAME,
+    parent = CreateWindowExA(0, "MinMax_WndClass", NULL, WS_CAPTION | WS_SYSMENU | WS_THICKFRAME,
                            0, 0, 100, 100, 0, 0, 0, NULL);
     ok(parent != 0, "CreateWindowEx error %d\n", GetLastError());
     expect_menu(parent, 0);
@@ -5263,7 +5964,7 @@ static void test_CreateWindow(void)
     expect_ex_style(parent, WS_EX_WINDOWEDGE);
 
     memset(&minmax, 0, sizeof(minmax));
-    SendMessage(parent, WM_GETMINMAXINFO, 0, (LPARAM)&minmax);
+    SendMessageA(parent, WM_GETMINMAXINFO, 0, (LPARAM)&minmax);
     SetRect(&rc_minmax, 0, 0, minmax.ptMaxSize.x, minmax.ptMaxSize.y);
     ok(IsRectEmpty(&rc_minmax), "ptMaxSize is not empty\n");
     SetRect(&rc_minmax, 0, 0, minmax.ptMaxTrackSize.x, minmax.ptMaxTrackSize.y);
@@ -5278,7 +5979,7 @@ static void test_CreateWindow(void)
     trace("creating child with rect (%d,%d-%d,%d)\n", rc.left, rc.top, rc.right, rc.bottom);
 
     SetLastError(0xdeadbeef);
-    hwnd = CreateWindowEx(0, "MinMax_WndClass", NULL, WS_CHILD | WS_CAPTION | WS_SYSMENU | WS_THICKFRAME,
+    hwnd = CreateWindowExA(0, "MinMax_WndClass", NULL, WS_CHILD | WS_CAPTION | WS_SYSMENU | WS_THICKFRAME,
                           rc.left, rc.top, rc.right - rc.left, rc.bottom - rc.top,
                           parent, (HMENU)1, 0, NULL);
     ok(hwnd != 0, "CreateWindowEx error %d\n", GetLastError());
@@ -5287,7 +5988,7 @@ static void test_CreateWindow(void)
     expect_ex_style(hwnd, WS_EX_WINDOWEDGE);
 
     memset(&minmax, 0, sizeof(minmax));
-    SendMessage(hwnd, WM_GETMINMAXINFO, 0, (LPARAM)&minmax);
+    SendMessageA(hwnd, WM_GETMINMAXINFO, 0, (LPARAM)&minmax);
     SetRect(&rc_minmax, 0, 0, minmax.ptMaxTrackSize.x, minmax.ptMaxTrackSize.y);
 
     GetWindowRect(hwnd, &rc);
@@ -5299,7 +6000,7 @@ static void test_CreateWindow(void)
 
     cls.lpfnWndProc = winsizes_wnd_proc;
     cls.lpszClassName = "Sizes_WndClass";
-    RegisterClass(&cls);
+    RegisterClassA(&cls);
 
     expected_cx = expected_cy = 200000;
     SetRect( &expected_rect, 0, 0, 200000, 200000 );
@@ -5314,7 +6015,7 @@ static void test_CreateWindow(void)
     DestroyWindow(hwnd);
 
     expected_cx = expected_cy = -10;
-    SetRect( &expected_rect, 0, 0, 0, 0 );
+    SetRectEmpty(&expected_rect);
     SetRect( &broken_rect, 0, 0, -10, -10 );
     hwnd = CreateWindowExA(0, "Sizes_WndClass", NULL, WS_CHILD, -20, -20, -10, -10, parent, 0, 0, NULL);
     ok( hwnd != 0, "creation failed err %u\n", GetLastError());
@@ -5324,7 +6025,7 @@ static void test_CreateWindow(void)
     DestroyWindow(hwnd);
 
     expected_cx = expected_cy = -200000;
-    SetRect( &expected_rect, 0, 0, 0, 0 );
+    SetRectEmpty(&expected_rect);
     SetRect( &broken_rect, 0, 0, -200000, -200000 );
     hwnd = CreateWindowExA(0, "Sizes_WndClass", NULL, WS_CHILD, -300000, -300000, -200000, -200000, parent, 0, 0, NULL);
     ok( hwnd != 0, "creation failed err %u\n", GetLastError());
@@ -5335,7 +6036,7 @@ static void test_CreateWindow(void)
 
     /* we need a parent at 0,0 so that child coordinates match */
     DestroyWindow(parent);
-    parent = CreateWindowEx(0, "MinMax_WndClass", NULL, WS_POPUP, 0, 0, 100, 100, 0, 0, 0, NULL);
+    parent = CreateWindowExA(0, "MinMax_WndClass", NULL, WS_POPUP, 0, 0, 100, 100, 0, 0, 0, NULL);
     ok(parent != 0, "CreateWindowEx error %d\n", GetLastError());
 
     expected_cx = 100;
@@ -5382,7 +6083,7 @@ static void test_CreateWindow(void)
             ReleaseDC( parent, hdc );
             DestroyWindow( parent );
             SetLastError( 0xdeadbeef );
-            parent = CreateWindowEx(WS_EX_APPWINDOW | WS_EX_LAYOUTRTL, "static", NULL, WS_POPUP,
+            parent = CreateWindowExA(WS_EX_APPWINDOW | WS_EX_LAYOUTRTL, "static", NULL, WS_POPUP,
                                     0, 0, 100, 100, 0, 0, 0, NULL);
             ok( parent != 0, "creation failed err %u\n", GetLastError());
             expect_ex_style( parent, WS_EX_APPWINDOW | WS_EX_LAYOUTRTL );
@@ -5423,12 +6124,12 @@ static void test_CreateWindow(void)
                 res = pGetProcessDefaultLayout( &layout );
                 ok( res, "GetProcessDefaultLayout failed err %u\n", GetLastError ());
                 ok( layout == LAYOUT_RTL, "GetProcessDefaultLayout wrong layout %x\n", layout );
-                hwnd = CreateWindowEx(WS_EX_APPWINDOW, "static", NULL, WS_POPUP,
+                hwnd = CreateWindowExA(WS_EX_APPWINDOW, "static", NULL, WS_POPUP,
                                       0, 0, 100, 100, 0, 0, 0, NULL);
                 ok( hwnd != 0, "creation failed err %u\n", GetLastError());
                 expect_ex_style( hwnd, WS_EX_APPWINDOW | WS_EX_LAYOUTRTL );
                 DestroyWindow( hwnd );
-                hwnd = CreateWindowEx(WS_EX_APPWINDOW, "static", NULL, WS_POPUP,
+                hwnd = CreateWindowExA(WS_EX_APPWINDOW, "static", NULL, WS_POPUP,
                                       0, 0, 100, 100, parent, 0, 0, NULL);
                 ok( hwnd != 0, "creation failed err %u\n", GetLastError());
                 expect_ex_style( hwnd, WS_EX_APPWINDOW );
@@ -5443,8 +6144,8 @@ static void test_CreateWindow(void)
 
     DestroyWindow(parent);
 
-    UnregisterClass("MinMax_WndClass", GetModuleHandle(0));
-    UnregisterClass("Sizes_WndClass", GetModuleHandle(0));
+    UnregisterClassA("MinMax_WndClass", GetModuleHandleA(NULL));
+    UnregisterClassA("Sizes_WndClass", GetModuleHandleA(NULL));
 
 #undef expect_gle_broken_9x
 #undef expect_menu
@@ -5468,23 +6169,23 @@ static void test_SetWindowLong(void)
     WNDPROC old_window_procW;
 
     SetLastError(0xdeadbeef);
-    retval = SetWindowLongPtr(NULL, GWLP_WNDPROC, 0);
+    retval = SetWindowLongPtrA(NULL, GWLP_WNDPROC, 0);
     ok(!retval, "SetWindowLongPtr on invalid window handle should have returned 0 instead of 0x%lx\n", retval);
     ok(check_error(GetLastError(), ERROR_INVALID_WINDOW_HANDLE),
         "SetWindowLongPtr should have set error to ERROR_INVALID_WINDOW_HANDLE instead of %d\n", GetLastError());
 
     SetLastError(0xdeadbeef);
-    retval = SetWindowLongPtr(hwndMain, 0xdeadbeef, 0);
+    retval = SetWindowLongPtrA(hwndMain, 0xdeadbeef, 0);
     ok(!retval, "SetWindowLongPtr on invalid index should have returned 0 instead of 0x%lx\n", retval);
     ok(check_error(GetLastError(), ERROR_INVALID_INDEX),
         "SetWindowLongPtr should have set error to ERROR_INVALID_INDEX instead of %d\n", GetLastError());
 
     SetLastError(0xdeadbeef);
-    retval = SetWindowLongPtr(hwndMain, GWLP_WNDPROC, 0);
+    retval = SetWindowLongPtrA(hwndMain, GWLP_WNDPROC, 0);
     ok((WNDPROC)retval == main_window_procA || broken(!retval), /* win9x */
         "SetWindowLongPtr on invalid window proc should have returned address of main_window_procA instead of 0x%lx\n", retval);
     ok(GetLastError() == 0xdeadbeef, "SetWindowLongPtr shouldn't have set the last error, instead of setting it to %d\n", GetLastError());
-    retval = GetWindowLongPtr(hwndMain, GWLP_WNDPROC);
+    retval = GetWindowLongPtrA(hwndMain, GWLP_WNDPROC);
     ok((WNDPROC)retval == main_window_procA,
         "SetWindowLongPtr on invalid window proc shouldn't have changed the value returned by GetWindowLongPtr, instead of changing it to 0x%lx\n", retval);
     ok(!IsWindowUnicode(hwndMain), "hwndMain shouldn't be Unicode\n");
@@ -5501,7 +6202,7 @@ static void test_SetWindowLong(void)
         ok(IsWindowUnicode(hwndMain), "hwndMain should now be Unicode\n");
 
         /* set it back to ANSI */
-        SetWindowLongPtr(hwndMain, GWLP_WNDPROC, 0);
+        SetWindowLongPtrA(hwndMain, GWLP_WNDPROC, 0);
     }
 }
 
@@ -5514,7 +6215,7 @@ static void test_ShowWindow(void)
 
     SetRect(&rcMain, 120, 120, 210, 210);
 
-    hwnd = CreateWindowEx(0, "MainWindowClass", NULL,
+    hwnd = CreateWindowExA(0, "MainWindowClass", NULL,
                           WS_CAPTION | WS_SYSMENU | WS_MINIMIZEBOX |
                           WS_MAXIMIZEBOX | WS_POPUP,
                           rcMain.left, rcMain.top,
@@ -5522,7 +6223,7 @@ static void test_ShowWindow(void)
                           0, 0, 0, NULL);
     assert(hwnd);
 
-    style = GetWindowLong(hwnd, GWL_STYLE);
+    style = GetWindowLongA(hwnd, GWL_STYLE);
     ok(!(style & WS_DISABLED), "window should not be disabled\n");
     ok(!(style & WS_VISIBLE), "window should not be visible\n");
     ok(!(style & WS_MINIMIZE), "window should not be minimized\n");
@@ -5534,7 +6235,7 @@ static void test_ShowWindow(void)
 
     ret = ShowWindow(hwnd, SW_SHOW);
     ok(!ret, "not expected ret: %lu\n", ret);
-    style = GetWindowLong(hwnd, GWL_STYLE);
+    style = GetWindowLongA(hwnd, GWL_STYLE);
     ok(!(style & WS_DISABLED), "window should not be disabled\n");
     ok(style & WS_VISIBLE, "window should be visible\n");
     ok(!(style & WS_MINIMIZE), "window should not be minimized\n");
@@ -5546,7 +6247,7 @@ static void test_ShowWindow(void)
 
     ret = ShowWindow(hwnd, SW_MINIMIZE);
     ok(ret, "not expected ret: %lu\n", ret);
-    style = GetWindowLong(hwnd, GWL_STYLE);
+    style = GetWindowLongA(hwnd, GWL_STYLE);
     ok(!(style & WS_DISABLED), "window should not be disabled\n");
     ok(style & WS_VISIBLE, "window should be visible\n");
     ok(style & WS_MINIMIZE, "window should be minimized\n");
@@ -5564,7 +6265,7 @@ static void test_ShowWindow(void)
 
     ShowWindow(hwnd, SW_RESTORE);
     ok(ret, "not expected ret: %lu\n", ret);
-    style = GetWindowLong(hwnd, GWL_STYLE);
+    style = GetWindowLongA(hwnd, GWL_STYLE);
     ok(!(style & WS_DISABLED), "window should not be disabled\n");
     ok(style & WS_VISIBLE, "window should be visible\n");
     ok(!(style & WS_MINIMIZE), "window should not be minimized\n");
@@ -5576,12 +6277,12 @@ static void test_ShowWindow(void)
 
     ret = EnableWindow(hwnd, FALSE);
     ok(!ret, "not expected ret: %lu\n", ret);
-    style = GetWindowLong(hwnd, GWL_STYLE);
+    style = GetWindowLongA(hwnd, GWL_STYLE);
     ok(style & WS_DISABLED, "window should be disabled\n");
 
-    ret = DefWindowProc(hwnd, WM_SYSCOMMAND, SC_MINIMIZE, 0);
+    ret = DefWindowProcA(hwnd, WM_SYSCOMMAND, SC_MINIMIZE, 0);
     ok(!ret, "not expected ret: %lu\n", ret);
-    style = GetWindowLong(hwnd, GWL_STYLE);
+    style = GetWindowLongA(hwnd, GWL_STYLE);
     ok(style & WS_DISABLED, "window should be disabled\n");
     ok(style & WS_VISIBLE, "window should be visible\n");
     ok(!(style & WS_MINIMIZE), "window should not be minimized\n");
@@ -5591,9 +6292,9 @@ static void test_ShowWindow(void)
        rcMain.left, rcMain.top, rcMain.right, rcMain.bottom,
        rc.left, rc.top, rc.right, rc.bottom);
 
-    ret = DefWindowProc(hwnd, WM_SYSCOMMAND, SC_MAXIMIZE, 0);
+    ret = DefWindowProcA(hwnd, WM_SYSCOMMAND, SC_MAXIMIZE, 0);
     ok(!ret, "not expected ret: %lu\n", ret);
-    style = GetWindowLong(hwnd, GWL_STYLE);
+    style = GetWindowLongA(hwnd, GWL_STYLE);
     ok(style & WS_DISABLED, "window should be disabled\n");
     ok(style & WS_VISIBLE, "window should be visible\n");
     ok(!(style & WS_MINIMIZE), "window should not be minimized\n");
@@ -5605,7 +6306,7 @@ static void test_ShowWindow(void)
 
     ret = ShowWindow(hwnd, SW_MINIMIZE);
     ok(ret, "not expected ret: %lu\n", ret);
-    style = GetWindowLong(hwnd, GWL_STYLE);
+    style = GetWindowLongA(hwnd, GWL_STYLE);
     ok(style & WS_DISABLED, "window should be disabled\n");
     ok(style & WS_VISIBLE, "window should be visible\n");
     ok(style & WS_MINIMIZE, "window should be minimized\n");
@@ -5613,9 +6314,9 @@ static void test_ShowWindow(void)
     GetWindowRect(hwnd, &rc);
     ok(!EqualRect(&rcMain, &rc), "rects shouldn't match\n");
 
-    ret = DefWindowProc(hwnd, WM_SYSCOMMAND, SC_RESTORE, 0);
+    ret = DefWindowProcA(hwnd, WM_SYSCOMMAND, SC_RESTORE, 0);
     ok(!ret, "not expected ret: %lu\n", ret);
-    style = GetWindowLong(hwnd, GWL_STYLE);
+    style = GetWindowLongA(hwnd, GWL_STYLE);
     ok(style & WS_DISABLED, "window should be disabled\n");
     ok(style & WS_VISIBLE, "window should be visible\n");
     ok(style & WS_MINIMIZE, "window should be minimized\n");
@@ -5625,7 +6326,7 @@ static void test_ShowWindow(void)
 
     ret = ShowWindow(hwnd, SW_RESTORE);
     ok(ret, "not expected ret: %lu\n", ret);
-    style = GetWindowLong(hwnd, GWL_STYLE);
+    style = GetWindowLongA(hwnd, GWL_STYLE);
     ok(style & WS_DISABLED, "window should be disabled\n");
     ok(style & WS_VISIBLE, "window should be visible\n");
     ok(!(style & WS_MINIMIZE), "window should not be minimized\n");
@@ -5635,49 +6336,221 @@ static void test_ShowWindow(void)
        rcMain.left, rcMain.top, rcMain.right, rcMain.bottom,
        rc.left, rc.top, rc.right, rc.bottom);
 
-    ret = DefWindowProc(hwnd, WM_SYSCOMMAND, SC_CLOSE, 0);
+    ret = DefWindowProcA(hwnd, WM_SYSCOMMAND, SC_CLOSE, 0);
     ok(!ret, "not expected ret: %lu\n", ret);
     ok(IsWindow(hwnd), "window should exist\n");
 
     ret = EnableWindow(hwnd, TRUE);
     ok(ret, "not expected ret: %lu\n", ret);
 
-    ret = DefWindowProc(hwnd, WM_SYSCOMMAND, SC_CLOSE, 0);
+    ret = DefWindowProcA(hwnd, WM_SYSCOMMAND, SC_CLOSE, 0);
     ok(!ret, "not expected ret: %lu\n", ret);
     ok(!IsWindow(hwnd), "window should not exist\n");
 }
 
+static DWORD CALLBACK gettext_msg_thread( LPVOID arg )
+{
+    HWND hwnd = arg;
+    char buf[32];
+    INT buf_len;
+
+    /* test GetWindowTextA */
+    num_gettext_msgs = 0;
+    memset( buf, 0, sizeof(buf) );
+    buf_len = GetWindowTextA( hwnd, buf, sizeof(buf) );
+    ok( buf_len != 0, "expected a nonempty window text\n" );
+    ok( !strcmp(buf, "another_caption"), "got wrong window text '%s'\n", buf );
+    ok( num_gettext_msgs == 1, "got %u WM_GETTEXT messages\n", num_gettext_msgs );
+
+    return 0;
+}
+
+static DWORD CALLBACK settext_msg_thread( LPVOID arg )
+{
+    HWND hwnd = arg;
+    BOOL success;
+
+    /* test SetWindowTextA */
+    num_settext_msgs = 0;
+    success = SetWindowTextA( hwnd, "thread_caption" );
+    ok( success, "SetWindowTextA failed\n" );
+    ok( num_settext_msgs == 1, "got %u WM_SETTEXT messages\n", num_settext_msgs );
+
+    return 0;
+}
+
 static void test_gettext(void)
 {
-    WNDCLASS cls;
-    LPCSTR clsname = "gettexttest";
-    HWND hwnd;
+    DWORD tid, num_msgs;
+    WCHAR bufW[32];
+    HANDLE thread;
+    BOOL success;
+    char buf[32];
+    INT buf_len;
+    HWND hwnd, hwnd2;
     LRESULT r;
+    MSG msg;
 
-    memset( &cls, 0, sizeof cls );
-    cls.lpfnWndProc = DefWindowProc;
-    cls.lpszClassName = clsname;
-    cls.hInstance = GetModuleHandle(NULL);
+    hwnd = CreateWindowExA( 0, "MainWindowClass", "caption", WS_POPUP, 0, 0, 0, 0, 0, 0, 0, NULL );
+    ok( hwnd != 0, "CreateWindowExA error %d\n", GetLastError() );
 
-    if (!RegisterClass( &cls )) return;
+    /* test GetWindowTextA */
+    num_gettext_msgs = 0;
+    memset( buf, 0, sizeof(buf) );
+    buf_len = GetWindowTextA( hwnd, buf, sizeof(buf) );
+    ok( buf_len != 0, "expected a nonempty window text\n" );
+    ok( !strcmp(buf, "caption"), "got wrong window text '%s'\n", buf );
+    ok( num_gettext_msgs == 1, "got %u WM_GETTEXT messages\n", num_gettext_msgs );
+
+    /* other process window */
+    strcpy( buf, "a" );
+    buf_len = GetWindowTextA( GetDesktopWindow(), buf, sizeof(buf) );
+    ok( buf_len == 0, "expected a nonempty window text\n" );
+    ok( *buf == 0, "got wrong window text '%s'\n", buf );
+
+    strcpy( buf, "blah" );
+    buf_len = GetWindowTextA( GetDesktopWindow(), buf, 0 );
+    ok( buf_len == 0, "expected a nonempty window text\n" );
+    ok( !strcmp(buf, "blah"), "got wrong window text '%s'\n", buf );
+
+    bufW[0] = 0xcc;
+    buf_len = GetWindowTextW( GetDesktopWindow(), bufW, 0 );
+    ok( buf_len == 0, "expected a nonempty window text\n" );
+    ok( bufW[0] == 0xcc, "got %x\n", bufW[0] );
+
+    g_wm_gettext_override.enabled = TRUE;
+
+    num_gettext_msgs = 0;
+    memset( buf, 0xcc, sizeof(buf) );
+    g_wm_gettext_override.buff = buf;
+    buf_len = GetWindowTextA( hwnd, buf, sizeof(buf) );
+    ok( buf_len == 0, "got %d\n", buf_len );
+    ok( *buf == 0, "got %x\n", *buf );
+    ok( num_gettext_msgs == 1, "got %u WM_GETTEXT messages\n", num_gettext_msgs );
+
+    num_gettext_msgs = 0;
+    strcpy( buf, "blah" );
+    g_wm_gettext_override.buff = buf;
+    buf_len = GetWindowTextA( hwnd, buf, 0 );
+    ok( buf_len == 0, "got %d\n", buf_len );
+    ok( !strcmp(buf, "blah"), "got %s\n", buf );
+    ok( num_gettext_msgs == 0, "got %u WM_GETTEXT messages\n", num_gettext_msgs );
+
+    g_wm_gettext_override.enabled = FALSE;
+
+    /* same for W window */
+    hwnd2 = CreateWindowExW( 0, mainclassW, NULL, WS_POPUP, 0, 0, 0, 0, 0, 0, 0, NULL );
+    ok( hwnd2 != 0, "CreateWindowExA error %d\n", GetLastError() );
+
+    g_wm_gettext_override.enabled = TRUE;
+
+    num_gettext_msgs = 0;
+    memset( bufW, 0xcc, sizeof(bufW) );
+    g_wm_gettext_override.buffW = bufW;
+    buf_len = GetWindowTextW( hwnd2, bufW, sizeof(bufW)/sizeof(WCHAR) );
+    ok( buf_len == 0, "got %d\n", buf_len );
+    ok( *bufW == 0, "got %x\n", *bufW );
+    ok( num_gettext_msgs == 1, "got %u WM_GETTEXT messages\n", num_gettext_msgs );
+
+    num_gettext_msgs = 0;
+    memset( bufW, 0xcc, sizeof(bufW) );
+    g_wm_gettext_override.buffW = bufW;
+    buf_len = GetWindowTextW( hwnd2, bufW, 0 );
+    ok( buf_len == 0, "got %d\n", buf_len );
+    ok( *bufW == 0xcccc, "got %x\n", *bufW );
+    ok( num_gettext_msgs == 0, "got %u WM_GETTEXT messages\n", num_gettext_msgs );
+
+    g_wm_gettext_override.enabled = FALSE;
+
+    DestroyWindow( hwnd2 );
+
+    /* test WM_GETTEXT */
+    num_gettext_msgs = 0;
+    memset( buf, 0, sizeof(buf) );
+    r = SendMessageA( hwnd, WM_GETTEXT, sizeof(buf), (LONG_PTR)buf );
+    ok( r != 0, "expected a nonempty window text\n" );
+    ok( !strcmp(buf, "caption"), "got wrong window text '%s'\n", buf );
+    ok( num_gettext_msgs == 1, "got %u WM_GETTEXT messages\n", num_gettext_msgs );
+
+    /* test SetWindowTextA */
+    num_settext_msgs = 0;
+    success = SetWindowTextA( hwnd, "new_caption" );
+    ok( success, "SetWindowTextA failed\n" );
+    ok( num_settext_msgs == 1, "got %u WM_SETTEXT messages\n", num_settext_msgs );
+
+    num_gettext_msgs = 0;
+    memset( buf, 0, sizeof(buf) );
+    buf_len = GetWindowTextA( hwnd, buf, sizeof(buf) );
+    ok( buf_len != 0, "expected a nonempty window text\n" );
+    ok( !strcmp(buf, "new_caption"), "got wrong window text '%s'\n", buf );
+    ok( num_gettext_msgs == 1, "got %u WM_GETTEXT messages\n", num_gettext_msgs );
+
+    /* test WM_SETTEXT */
+    num_settext_msgs = 0;
+    r = SendMessageA( hwnd, WM_SETTEXT, 0, (ULONG_PTR)"another_caption" );
+    ok( r != 0, "WM_SETTEXT failed\n" );
+    ok( num_settext_msgs == 1, "got %u WM_SETTEXT messages\n", num_settext_msgs );
+
+    num_gettext_msgs = 0;
+    memset( buf, 0, sizeof(buf) );
+    buf_len = GetWindowTextA( hwnd, buf, sizeof(buf) );
+    ok( buf_len != 0, "expected a nonempty window text\n" );
+    ok( !strcmp(buf, "another_caption"), "got wrong window text '%s'\n", buf );
+    ok( num_gettext_msgs == 1, "got %u WM_GETTEXT messages\n", num_gettext_msgs );
+
+    while (PeekMessageA( &msg, 0, 0, 0, PM_REMOVE | PM_QS_SENDMESSAGE ))
+        DispatchMessageA( &msg );
+
+    /* test interthread GetWindowTextA */
+    num_msgs = 0;
+    thread = CreateThread( NULL, 0, gettext_msg_thread, hwnd, 0, &tid );
+    ok(thread != NULL, "CreateThread failed, error %d\n", GetLastError());
+    while (MsgWaitForMultipleObjects( 1, &thread, FALSE, INFINITE, QS_SENDMESSAGE ) != WAIT_OBJECT_0)
+    {
+        while (PeekMessageA( &msg, 0, 0, 0, PM_REMOVE | PM_QS_SENDMESSAGE ))
+            DispatchMessageA( &msg );
+        num_msgs++;
+    }
+    CloseHandle( thread );
+    ok( num_msgs >= 1, "got %u wakeups from MsgWaitForMultipleObjects\n", num_msgs );
+
+    /* test interthread SetWindowText */
+    num_msgs = 0;
+    thread = CreateThread( NULL, 0, settext_msg_thread, hwnd, 0, &tid );
+    ok(thread != NULL, "CreateThread failed, error %d\n", GetLastError());
+    while (MsgWaitForMultipleObjects( 1, &thread, FALSE, INFINITE, QS_SENDMESSAGE ) != WAIT_OBJECT_0)
+    {
+        while (PeekMessageA( &msg, 0, 0, 0, PM_REMOVE | PM_QS_SENDMESSAGE ))
+            DispatchMessageA( &msg );
+        num_msgs++;
+    }
+    CloseHandle( thread );
+    ok( num_msgs >= 1, "got %u wakeups from MsgWaitForMultipleObjects\n", num_msgs );
 
-    hwnd = CreateWindow( clsname, "test text", WS_OVERLAPPED, 0, 0, 10, 10, 0, NULL, NULL, NULL);
-    ok( hwnd != NULL, "window was null\n");
+    num_gettext_msgs = 0;
+    memset( buf, 0, sizeof(buf) );
+    buf_len = GetWindowTextA( hwnd, buf, sizeof(buf) );
+    ok( buf_len != 0, "expected a nonempty window text\n" );
+    ok( !strcmp(buf, "thread_caption"), "got wrong window text '%s'\n", buf );
+    ok( num_gettext_msgs == 1, "got %u WM_GETTEXT messages\n", num_gettext_msgs );
 
-    r = SendMessage( hwnd, WM_GETTEXT, 0x10, 0x1000);
+    /* seems to crash on every modern Windows version */
+    if (0)
+    {
+    r = SendMessageA( hwnd, WM_GETTEXT, 0x10, 0x1000);
     ok( r == 0, "settext should return zero\n");
 
-    r = SendMessage( hwnd, WM_GETTEXT, 0x10000, 0);
+    r = SendMessageA( hwnd, WM_GETTEXT, 0x10000, 0);
     ok( r == 0, "settext should return zero (%ld)\n", r);
 
-    r = SendMessage( hwnd, WM_GETTEXT, 0xff000000, 0x1000);
+    r = SendMessageA( hwnd, WM_GETTEXT, 0xff000000, 0x1000);
     ok( r == 0, "settext should return zero (%ld)\n", r);
 
-    r = SendMessage( hwnd, WM_GETTEXT, 0x1000, 0xff000000);
+    r = SendMessageA( hwnd, WM_GETTEXT, 0x1000, 0xff000000);
     ok( r == 0, "settext should return zero (%ld)\n", r);
+    }
 
     DestroyWindow(hwnd);
-    UnregisterClass( clsname, NULL );
 }
 
 
@@ -5704,7 +6577,7 @@ static void test_GetUpdateRect(void)
     flush_events( TRUE );
 
     ShowWindow(hchild, SW_HIDE);
-    SetRect(&rc2, 0, 0, 0, 0);
+    SetRectEmpty(&rc2);
     ret = GetUpdateRect(hgrandparent, &rc1, FALSE);
     ok(!ret, "GetUpdateRect returned not empty region\n");
     ok(EqualRect(&rc1, &rc2), "rects do not match (%d,%d,%d,%d) / (%d,%d,%d,%d)\n",
@@ -5720,14 +6593,14 @@ static void test_GetUpdateRect(void)
 
     parent_wm_paint = FALSE;
     grandparent_wm_paint = FALSE;
-    while (PeekMessage(&msg, 0, 0, 0, PM_REMOVE))
+    while (PeekMessageA(&msg, 0, 0, 0, PM_REMOVE))
     {
         if (msg.message == WM_PAINT)
         {
             if (msg.hwnd == hgrandparent) grandparent_wm_paint = TRUE;
             if (msg.hwnd == hparent) parent_wm_paint = TRUE;
         }
-        DispatchMessage(&msg);
+        DispatchMessageA(&msg);
     }
     ok(parent_wm_paint, "WM_PAINT should have been received in parent\n");
     ok(!grandparent_wm_paint, "WM_PAINT should NOT have been received in grandparent\n");
@@ -5740,7 +6613,7 @@ static void test_GetUpdateRect(void)
     cls.cbWndExtra = 0;
     cls.hInstance = GetModuleHandleA(0);
     cls.hIcon = 0;
-    cls.hCursor = LoadCursorA(0, IDC_ARROW);
+    cls.hCursor = LoadCursorA(0, (LPCSTR)IDC_ARROW);
     cls.hbrBackground = GetStockObject(WHITE_BRUSH);
     cls.lpszMenuName = NULL;
     cls.lpszClassName = classNameA;
@@ -5768,7 +6641,7 @@ static void test_GetUpdateRect(void)
 
     ShowWindow(hchild, SW_HIDE);
 
-    SetRect(&rc2, 0, 0, 0, 0);
+    SetRectEmpty(&rc2);
     ret = GetUpdateRect(hgrandparent, &rc1, FALSE);
     ok(!ret, "GetUpdateRect returned not empty region\n");
     ok(EqualRect(&rc1, &rc2), "rects do not match (%d,%d,%d,%d) / (%d,%d,%d,%d)\n",
@@ -5784,14 +6657,14 @@ static void test_GetUpdateRect(void)
 
     parent_wm_paint = FALSE;
     grandparent_wm_paint = FALSE;
-    while (PeekMessage(&msg, 0, 0, 0, PM_REMOVE))
+    while (PeekMessageA(&msg, 0, 0, 0, PM_REMOVE))
     {
         if (msg.message == WM_PAINT)
         {
             if (msg.hwnd == hgrandparent) grandparent_wm_paint = TRUE;
             if (msg.hwnd == hparent) parent_wm_paint = TRUE;
         }
-        DispatchMessage(&msg);
+        DispatchMessageA(&msg);
     }
     ok(parent_wm_paint, "WM_PAINT should have been received in parent\n");
     ok(!grandparent_wm_paint, "WM_PAINT should NOT have been received in grandparent\n");
@@ -5830,7 +6703,7 @@ static LRESULT CALLBACK TestExposedRegion_WndProc(HWND hwnd, UINT msg, WPARAM wP
 
         return 1;
     }
-    return DefWindowProc(hwnd, msg, wParam, lParam);
+    return DefWindowProcA(hwnd, msg, wParam, lParam);
 }
 
 static void test_Expose(void)
@@ -5859,7 +6732,7 @@ static LRESULT CALLBACK TestNCRedraw_WndProc(HWND hwnd, UINT msg, WPARAM wParam,
     switch(msg)
     {
     case WM_CREATE:
-        ncredrawflags = *(UINT *) (((CREATESTRUCT *)lParam)->lpCreateParams);
+        ncredrawflags = *(UINT *) (((CREATESTRUCTA *)lParam)->lpCreateParams);
         return 0;
     case WM_NCPAINT:
         RedrawWindow(hwnd, NULL, NULL, ncredrawflags);
@@ -5869,7 +6742,7 @@ static LRESULT CALLBACK TestNCRedraw_WndProc(HWND hwnd, UINT msg, WPARAM wParam,
         EndPaint(hwnd, &ps);
         return 0;
     }
-    return DefWindowProc(hwnd, msg, wParam, lParam);
+    return DefWindowProcA(hwnd, msg, wParam, lParam);
 }
 
 static void run_NCRedrawLoop(UINT flags)
@@ -5885,17 +6758,15 @@ static void run_NCRedrawLoop(UINT flags)
     ShowWindow(hwnd, SW_SHOW);
     UpdateWindow(hwnd);
     flush_events( FALSE );
-    while(PeekMessage(&msg, hwnd, 0, 0, PM_REMOVE) != 0)
+    while (PeekMessageA(&msg, hwnd, 0, 0, PM_REMOVE))
     {
         if (msg.message == WM_PAINT) loopcount++;
         if (loopcount >= 100) break;
         TranslateMessage(&msg);
-        DispatchMessage(&msg);
+        DispatchMessageA(&msg);
         MsgWaitForMultipleObjects(0, NULL, FALSE, 100, QS_ALLINPUT);
     }
-    if (flags == (RDW_INVALIDATE | RDW_FRAME))
-        todo_wine ok(loopcount < 100, "Detected infinite WM_PAINT loop (%x).\n", flags);
-    else
+    todo_wine_if (flags == (RDW_INVALIDATE | RDW_FRAME))
         ok(loopcount < 100, "Detected infinite WM_PAINT loop (%x).\n", flags);
     DestroyWindow(hwnd);
 }
@@ -5910,8 +6781,8 @@ static void test_NCRedraw(void)
     wndclass.cbClsExtra = 0;
     wndclass.cbWndExtra = 0;
     wndclass.hInstance = 0;
-    wndclass.hIcon = LoadIcon(NULL, IDI_APPLICATION);
-    wndclass.hCursor = LoadCursor(NULL, IDC_ARROW);
+    wndclass.hIcon = LoadIconA(0, (LPCSTR)IDI_APPLICATION);
+    wndclass.hCursor = LoadCursorA(0, (LPCSTR)IDC_ARROW);
     wndclass.hbrBackground = GetStockObject(WHITE_BRUSH);
     wndclass.lpszMenuName = NULL;
 
@@ -5937,12 +6808,12 @@ static void test_GetWindowModuleFileName(void)
     hwnd = CreateWindowExA(0, "static", NULL, WS_POPUP, 0,0,0,0, 0, 0, 0, NULL);
     assert(hwnd);
 
-    hinst = (HINSTANCE)GetWindowLongPtr(hwnd, GWLP_HINSTANCE);
-    ok(hinst == 0 || broken(hinst == GetModuleHandle(0)), /* win9x */ "expected 0, got %p\n", hinst);
+    hinst = (HINSTANCE)GetWindowLongPtrA(hwnd, GWLP_HINSTANCE);
+    ok(hinst == 0 || broken(hinst == GetModuleHandleA(NULL)), /* win9x */ "expected 0, got %p\n", hinst);
 
     buf1[0] = 0;
     SetLastError(0xdeadbeef);
-    ret1 = GetModuleFileName(hinst, buf1, sizeof(buf1));
+    ret1 = GetModuleFileNameA(hinst, buf1, sizeof(buf1));
     ok(ret1, "GetModuleFileName error %u\n", GetLastError());
 
     buf2[0] = 0;
@@ -5956,10 +6827,10 @@ static void test_GetWindowModuleFileName(void)
         ok(ret1 == ret2 || broken(ret2 == ret1 + 1), /* win98 */ "%u != %u\n", ret1, ret2);
         ok(!strcmp(buf1, buf2), "%s != %s\n", buf1, buf2);
     }
-    hinst = GetModuleHandle(0);
+    hinst = GetModuleHandleA(NULL);
 
     SetLastError(0xdeadbeef);
-    ret2 = GetModuleFileName(hinst, buf2, ret1 - 2);
+    ret2 = GetModuleFileNameA(hinst, buf2, ret1 - 2);
     ok(ret2 == ret1 - 2 || broken(ret2 == ret1 - 3), /* win98 */
        "expected %u, got %u\n", ret1 - 2, ret2);
     ok(GetLastError() == 0xdeadbeef /* XP */ ||
@@ -5967,7 +6838,7 @@ static void test_GetWindowModuleFileName(void)
        "expected 0xdeadbeef or ERROR_INSUFFICIENT_BUFFER, got %u\n", GetLastError());
 
     SetLastError(0xdeadbeef);
-    ret2 = GetModuleFileName(hinst, buf2, 0);
+    ret2 = GetModuleFileNameA(hinst, buf2, 0);
     ok(!ret2, "GetModuleFileName should return 0\n");
     ok(GetLastError() == 0xdeadbeef /* XP */ ||
        GetLastError() == ERROR_INSUFFICIENT_BUFFER, /* win2k3, vista */
@@ -5998,7 +6869,7 @@ static void test_GetWindowModuleFileName(void)
     ok(GetLastError() == ERROR_INVALID_WINDOW_HANDLE || broken(GetLastError() == 0xdeadbeef), /* win9x */
        "expected ERROR_INVALID_WINDOW_HANDLE, got %u\n", GetLastError());
 
-    hwnd = FindWindow("Shell_TrayWnd", NULL);
+    hwnd = FindWindowA("Shell_TrayWnd", NULL);
     ok(IsWindow(hwnd) || broken(!hwnd), "got invalid tray window %p\n", hwnd);
     SetLastError(0xdeadbeef);
     ret1 = pGetWindowModuleFileNameA(hwnd, buf1, sizeof(buf1));
@@ -6006,7 +6877,7 @@ static void test_GetWindowModuleFileName(void)
 
     if (!ret1)  /* inter-process GetWindowModuleFileName works on win9x, so don't test the desktop there */
     {
-        ret1 = GetModuleFileName(0, buf1, sizeof(buf1));
+        ret1 = GetModuleFileNameA(0, buf1, sizeof(buf1));
         hwnd = GetDesktopWindow();
         ok(IsWindow(hwnd), "got invalid desktop window %p\n", hwnd);
         SetLastError(0xdeadbeef);
@@ -6052,7 +6923,7 @@ static void test_hwnd_message(void)
             "parent shouldn't have parent %p\n", pGetAncestor(parent, GA_PARENT) );
         trace("parent %p root %p desktop %p\n", parent, root, desktop);
         if (!GetClassNameA( parent, buffer, sizeof(buffer) )) buffer[0] = 0;
-        ok( !lstrcmpi( buffer, "Message" ), "wrong parent class '%s'\n", buffer );
+        ok( !lstrcmpiA( buffer, "Message" ), "wrong parent class '%s'\n", buffer );
         GetWindowRect( parent, &rect );
         ok( rect.left == 0 && rect.right == 100 && rect.top == 0 && rect.bottom == 100,
             "wrong parent rect %d,%d-%d,%d\n", rect.left, rect.top, rect.right, rect.bottom );
@@ -6120,7 +6991,7 @@ static void test_layered_window(void)
     ok( !ret, "GetLayeredWindowAttributes should fail on non-layered window\n" );
     ret = pSetLayeredWindowAttributes( hwnd, 0, 0, LWA_ALPHA );
     ok( !ret, "SetLayeredWindowAttributes should fail on non-layered window\n" );
-    SetWindowLong( hwnd, GWL_EXSTYLE, GetWindowLong(hwnd, GWL_EXSTYLE) | WS_EX_LAYERED );
+    SetWindowLongA( hwnd, GWL_EXSTYLE, GetWindowLongA(hwnd, GWL_EXSTYLE) | WS_EX_LAYERED );
     ret = pGetLayeredWindowAttributes( hwnd, &key, &alpha, &flags );
     ok( !ret, "GetLayeredWindowAttributes should fail on layered but not initialized window\n" );
     ret = pUpdateLayeredWindow( hwnd, 0, NULL, &sz, hdc, &pt, 0, NULL, ULW_OPAQUE );
@@ -6140,13 +7011,13 @@ static void test_layered_window(void)
     ok( GetLastError() == ERROR_INVALID_PARAMETER, "expected ERROR_INVALID_PARAMETER, got %u\n", GetLastError() );
 
     /* clearing WS_EX_LAYERED resets attributes */
-    SetWindowLong( hwnd, GWL_EXSTYLE, GetWindowLong(hwnd, GWL_EXSTYLE) & ~WS_EX_LAYERED );
+    SetWindowLongA( hwnd, GWL_EXSTYLE, GetWindowLongA(hwnd, GWL_EXSTYLE) & ~WS_EX_LAYERED );
     SetLastError( 0xdeadbeef );
     ret = pUpdateLayeredWindow( hwnd, 0, NULL, &sz, hdc, &pt, 0, NULL, ULW_OPAQUE );
     ok( !ret, "UpdateLayeredWindow should fail on non-layered window\n" );
     ret = pGetLayeredWindowAttributes( hwnd, &key, &alpha, &flags );
     ok( !ret, "GetLayeredWindowAttributes should fail on no longer layered window\n" );
-    SetWindowLong( hwnd, GWL_EXSTYLE, GetWindowLong(hwnd, GWL_EXSTYLE) | WS_EX_LAYERED );
+    SetWindowLongA( hwnd, GWL_EXSTYLE, GetWindowLongA(hwnd, GWL_EXSTYLE) | WS_EX_LAYERED );
     ret = pGetLayeredWindowAttributes( hwnd, &key, &alpha, &flags );
     ok( !ret, "GetLayeredWindowAttributes should fail on layered but not initialized window\n" );
     ret = pUpdateLayeredWindow( hwnd, 0, NULL, &sz, hdc, &pt, 0, NULL, ULW_OPAQUE );
@@ -6170,10 +7041,12 @@ static void test_layered_window(void)
         ret = pUpdateLayeredWindowIndirect( hwnd, &info );
         ok( ret, "UpdateLayeredWindowIndirect should succeed on layered window\n" );
         sz.cx--;
+        SetLastError(0);
         ret = pUpdateLayeredWindowIndirect( hwnd, &info );
         ok( !ret, "UpdateLayeredWindowIndirect should fail\n" );
-        ok( GetLastError() == ERROR_INCORRECT_SIZE || broken(GetLastError() == ERROR_MR_MID_NOT_FOUND),
-            "wrong error %u\n", GetLastError() );
+        /* particular error code differs from version to version, could be ERROR_INCORRECT_SIZE,
+           ERROR_MR_MID_NOT_FOUND or ERROR_GEN_FAILURE (Win8/Win10) */
+        ok( GetLastError() != 0, "wrong error %u\n", GetLastError() );
         info.dwFlags  = ULW_OPAQUE;
         ret = pUpdateLayeredWindowIndirect( hwnd, &info );
         ok( ret, "UpdateLayeredWindowIndirect should succeed on layered window\n" );
@@ -6225,8 +7098,8 @@ static void test_layered_window(void)
     ok( flags == 0, "wrong flags %x\n", flags );
 
     /* default alpha and color key is 0 */
-    SetWindowLong( hwnd, GWL_EXSTYLE, GetWindowLong(hwnd, GWL_EXSTYLE) & ~WS_EX_LAYERED );
-    SetWindowLong( hwnd, GWL_EXSTYLE, GetWindowLong(hwnd, GWL_EXSTYLE) | WS_EX_LAYERED );
+    SetWindowLongA( hwnd, GWL_EXSTYLE, GetWindowLongA(hwnd, GWL_EXSTYLE) & ~WS_EX_LAYERED );
+    SetWindowLongA( hwnd, GWL_EXSTYLE, GetWindowLongA(hwnd, GWL_EXSTYLE) | WS_EX_LAYERED );
     ret = pSetLayeredWindowAttributes( hwnd, 0x222222, 55, 0 );
     ok( ret, "SetLayeredWindowAttributes should succeed on layered window\n" );
     ret = pGetLayeredWindowAttributes( hwnd, &key, &alpha, &flags );
@@ -6249,7 +7122,6 @@ static LRESULT CALLBACK fullscreen_wnd_proc(HWND hwnd, UINT msg, WPARAM wp, LPAR
         case WM_NCCREATE:
         {
             CREATESTRUCTA *cs = (CREATESTRUCTA *)lp;
-            trace("WM_NCCREATE: rect %d,%d-%d,%d\n", cs->x, cs->y, cs->cx, cs->cy);
             ok(cs->x == mi.rcMonitor.left && cs->y == mi.rcMonitor.top &&
                cs->cx == mi.rcMonitor.right && cs->cy == mi.rcMonitor.bottom,
                "expected %d,%d-%d,%d, got %d,%d-%d,%d\n",
@@ -6260,7 +7132,6 @@ static LRESULT CALLBACK fullscreen_wnd_proc(HWND hwnd, UINT msg, WPARAM wp, LPAR
         case WM_GETMINMAXINFO:
         {
             MINMAXINFO *minmax = (MINMAXINFO *)lp;
-            dump_minmax_info(minmax);
             ok(minmax->ptMaxPosition.x <= mi.rcMonitor.left, "%d <= %d\n", minmax->ptMaxPosition.x, mi.rcMonitor.left);
             ok(minmax->ptMaxPosition.y <= mi.rcMonitor.top, "%d <= %d\n", minmax->ptMaxPosition.y, mi.rcMonitor.top);
             ok(minmax->ptMaxSize.x >= mi.rcMonitor.right, "%d >= %d\n", minmax->ptMaxSize.x, mi.rcMonitor.right);
@@ -6268,7 +7139,7 @@ static LRESULT CALLBACK fullscreen_wnd_proc(HWND hwnd, UINT msg, WPARAM wp, LPAR
             break;
         }
     }
-    return DefWindowProc(hwnd, msg, wp, lp);
+    return DefWindowProcA(hwnd, msg, wp, lp);
 }
 
 static void test_fullscreen(void)
@@ -6279,7 +7150,7 @@ static void test_fullscreen(void)
     static const DWORD t_ex_style[] = {
         0, WS_EX_APPWINDOW, WS_EX_TOOLWINDOW
     };
-    WNDCLASS cls;
+    WNDCLASSA cls;
     HWND hwnd;
     int i, j;
     POINT pt;
@@ -6310,13 +7181,13 @@ static void test_fullscreen(void)
     cls.lpfnWndProc = fullscreen_wnd_proc;
     cls.cbClsExtra = 0;
     cls.cbWndExtra = 0;
-    cls.hInstance = GetModuleHandle(0);
+    cls.hInstance = GetModuleHandleA(NULL);
     cls.hIcon = 0;
-    cls.hCursor = LoadCursorA(0, IDC_ARROW);
+    cls.hCursor = LoadCursorA(0, (LPCSTR)IDC_ARROW);
     cls.hbrBackground = GetStockObject(WHITE_BRUSH);
     cls.lpszMenuName = NULL;
     cls.lpszClassName = "fullscreen_class";
-    RegisterClass(&cls);
+    RegisterClassA(&cls);
 
     for (i = 0; i < sizeof(t_style)/sizeof(t_style[0]); i++)
     {
@@ -6334,7 +7205,7 @@ static void test_fullscreen(void)
 
             hwnd = CreateWindowExA(ex_style, "fullscreen_class", NULL, style,
                                    mi.rcMonitor.left, mi.rcMonitor.top, mi.rcMonitor.right, mi.rcMonitor.bottom,
-                                   GetDesktopWindow(), 0, GetModuleHandle(0), NULL);
+                                   GetDesktopWindow(), 0, GetModuleHandleA(NULL), NULL);
             ok(hwnd != 0, "%d: CreateWindowExA(%#x/%#x) failed\n", i, ex_style, style);
             GetWindowRect(hwnd, &rc);
             trace("%#x/%#x: window rect %d,%d-%d,%d\n", ex_style, style, rc.left, rc.top, rc.right, rc.bottom);
@@ -6346,7 +7217,7 @@ static void test_fullscreen(void)
             style = t_style[i] | WS_MAXIMIZE;
             hwnd = CreateWindowExA(ex_style, "fullscreen_class", NULL, style,
                                    mi.rcMonitor.left, mi.rcMonitor.top, mi.rcMonitor.right, mi.rcMonitor.bottom,
-                                   GetDesktopWindow(), 0, GetModuleHandle(0), NULL);
+                                   GetDesktopWindow(), 0, GetModuleHandleA(NULL), NULL);
             ok(hwnd != 0, "%d: CreateWindowExA(%#x/%#x) failed\n", i, ex_style, style);
             GetWindowRect(hwnd, &rc);
             trace("%#x/%#x: window rect %d,%d-%d,%d\n", ex_style, style, rc.left, rc.top, rc.right, rc.bottom);
@@ -6358,7 +7229,7 @@ static void test_fullscreen(void)
             style = t_style[i] | WS_MAXIMIZE | WS_CAPTION;
             hwnd = CreateWindowExA(ex_style, "fullscreen_class", NULL, style,
                                    mi.rcMonitor.left, mi.rcMonitor.top, mi.rcMonitor.right, mi.rcMonitor.bottom,
-                                   GetDesktopWindow(), 0, GetModuleHandle(0), NULL);
+                                   GetDesktopWindow(), 0, GetModuleHandleA(NULL), NULL);
             ok(hwnd != 0, "%d: CreateWindowExA(%#x/%#x) failed\n", i, ex_style, style);
             GetWindowRect(hwnd, &rc);
             trace("%#x/%#x: window rect %d,%d-%d,%d\n", ex_style, style, rc.left, rc.top, rc.right, rc.bottom);
@@ -6370,7 +7241,7 @@ static void test_fullscreen(void)
             style = t_style[i] | WS_CAPTION | WS_MAXIMIZEBOX;
             hwnd = CreateWindowExA(ex_style, "fullscreen_class", NULL, style,
                                    mi.rcMonitor.left, mi.rcMonitor.top, mi.rcMonitor.right, mi.rcMonitor.bottom,
-                                   GetDesktopWindow(), 0, GetModuleHandle(0), NULL);
+                                   GetDesktopWindow(), 0, GetModuleHandleA(NULL), NULL);
             ok(hwnd != 0, "%d: CreateWindowExA(%#x/%#x) failed\n", i, ex_style, style);
             GetWindowRect(hwnd, &rc);
             trace("%#x/%#x: window rect %d,%d-%d,%d\n", ex_style, style, rc.left, rc.top, rc.right, rc.bottom);
@@ -6382,24 +7253,24 @@ static void test_fullscreen(void)
             style = t_style[i] | WS_MAXIMIZE | WS_CAPTION | WS_MAXIMIZEBOX;
             hwnd = CreateWindowExA(ex_style, "fullscreen_class", NULL, style,
                                    mi.rcMonitor.left, mi.rcMonitor.top, mi.rcMonitor.right, mi.rcMonitor.bottom,
-                                   GetDesktopWindow(), 0, GetModuleHandle(0), NULL);
+                                   GetDesktopWindow(), 0, GetModuleHandleA(NULL), NULL);
             ok(hwnd != 0, "%d: CreateWindowExA(%#x/%#x) failed\n", i, ex_style, style);
             GetWindowRect(hwnd, &rc);
             trace("%#x/%#x: window rect %d,%d-%d,%d\n", ex_style, style, rc.left, rc.top, rc.right, rc.bottom);
             /* Windows makes a maximized window slightly larger (to hide the borders?) */
             fixup = min(abs(rc.left), abs(rc.top));
             InflateRect(&rc, -fixup, -fixup);
-            ok(rc.left >= mi.rcWork.left && rc.top <= mi.rcWork.top &&
-               rc.right <= mi.rcWork.right && rc.bottom <= mi.rcWork.bottom,
+            ok(rc.left >= mi.rcMonitor.left && rc.top >= mi.rcMonitor.top &&
+               rc.right <= mi.rcMonitor.right && rc.bottom <= mi.rcMonitor.bottom,
                "%#x/%#x: window rect %d,%d-%d,%d must be in %d,%d-%d,%d\n",
                ex_style, style, rc.left, rc.top, rc.right, rc.bottom,
-               mi.rcWork.left, mi.rcWork.top, mi.rcWork.right, mi.rcWork.bottom);
+               mi.rcMonitor.left, mi.rcMonitor.top, mi.rcMonitor.right, mi.rcMonitor.bottom);
             DestroyWindow(hwnd);
 
             style = t_style[i] | WS_MAXIMIZE | WS_MAXIMIZEBOX;
             hwnd = CreateWindowExA(ex_style, "fullscreen_class", NULL, style,
                                    mi.rcMonitor.left, mi.rcMonitor.top, mi.rcMonitor.right, mi.rcMonitor.bottom,
-                                   GetDesktopWindow(), 0, GetModuleHandle(0), NULL);
+                                   GetDesktopWindow(), 0, GetModuleHandleA(NULL), NULL);
             ok(hwnd != 0, "%d: CreateWindowExA(%#x/%#x) failed\n", i, ex_style, style);
             GetWindowRect(hwnd, &rc);
             trace("%#x/%#x: window rect %d,%d-%d,%d\n", ex_style, style, rc.left, rc.top, rc.right, rc.bottom);
@@ -6411,14 +7282,14 @@ static void test_fullscreen(void)
                    rc.right >= mi.rcMonitor.right && rc.bottom >= mi.rcMonitor.bottom,
                    "%#x/%#x: window rect %d,%d-%d,%d\n", ex_style, style, rc.left, rc.top, rc.right, rc.bottom);
             else
-                ok(rc.left >= mi.rcWork.left && rc.top <= mi.rcWork.top &&
-                   rc.right <= mi.rcWork.right && rc.bottom <= mi.rcWork.bottom,
+                ok(rc.left >= mi.rcMonitor.left && rc.top >= mi.rcMonitor.top &&
+                   rc.right <= mi.rcMonitor.right && rc.bottom <= mi.rcMonitor.bottom,
                    "%#x/%#x: window rect %d,%d-%d,%d\n", ex_style, style, rc.left, rc.top, rc.right, rc.bottom);
             DestroyWindow(hwnd);
         }
     }
 
-    UnregisterClass("fullscreen_class", GetModuleHandle(0));
+    UnregisterClassA("fullscreen_class", GetModuleHandleA(NULL));
 }
 
 static BOOL test_thick_child_got_minmax;
@@ -6529,7 +7400,7 @@ static void test_thick_child_size(HWND parentWindow)
     LONG expectedWidth;
     LONG expectedHeight;
     WNDCLASSA cls;
-    LPCTSTR className = "THICK_CHILD_CLASS";
+    static const char className[] = "THICK_CHILD_CLASS";
     int i;
     LONG adjustedStyle;
     static const LONG styles[NUMBER_OF_THICK_CHILD_TESTS] = {
@@ -6594,7 +7465,7 @@ static void test_thick_child_size(HWND parentWindow)
     cls.cbWndExtra = 0;
     cls.hInstance = GetModuleHandleA(0);
     cls.hIcon = 0;
-    cls.hCursor = LoadCursorA(0, IDC_ARROW);
+    cls.hCursor = LoadCursorA(0, (LPCSTR)IDC_ARROW);
     cls.hbrBackground = GetStockObject(WHITE_BRUSH);
     cls.lpszMenuName = NULL;
     cls.lpszClassName = className;
@@ -6610,7 +7481,7 @@ static void test_thick_child_size(HWND parentWindow)
         test_thick_child_got_minmax = FALSE;
 
         SetLastError(0xdeadbeef);
-        childWindow = CreateWindowEx( exStyles[i], className, "", styles[i],  0, 0, 0, 0, parentWindow, 0,  GetModuleHandleA(0),  NULL );
+        childWindow = CreateWindowExA( exStyles[i], className, "", styles[i],  0, 0, 0, 0, parentWindow, 0,  GetModuleHandleA(0),  NULL );
         ok(childWindow != NULL, "Failed to create child window, error: %u\n", GetLastError());
 
         ok(test_thick_child_got_minmax, "Got no WM_GETMINMAXINFO\n");
@@ -6647,7 +7518,7 @@ static void test_thick_child_size(HWND parentWindow)
         success = DestroyWindow(childWindow);
         ok(success,"DestroyWindow call failed, error: %u\n", GetLastError());
     }
-    ok(UnregisterClass(className, GetModuleHandleA(0)),"UnregisterClass call failed\n");
+    ok(UnregisterClassA(className, GetModuleHandleA(NULL)),"UnregisterClass call failed\n");
 }
 
 static void test_handles( HWND full_hwnd )
@@ -6719,7 +7590,7 @@ static void test_winregion(void)
         ok( ret == ERROR, "Expected ERROR, got %d\n", ret);
         ok( GetLastError() == 0xdeadbeef, "Expected , got %d\n", GetLastError());
 
-        r.left = r.top = r.right = r.bottom = 0;
+        SetRectEmpty(&r);
         ret = pGetWindowRgnBox(hwnd, &r);
         ok( ret == SIMPLEREGION, "Expected SIMPLEREGION, got %d\n", ret);
         ok( r.left == 2 && r.top == 3 && r.right == 10 && r.bottom == 15,
@@ -6730,10 +7601,10 @@ static void test_winregion(void)
             hrgn = CreateRectRgn(2, 3, 10, 15);
             ret = pMirrorRgn( hwnd, hrgn );
             ok( ret == TRUE, "MirrorRgn failed %u\n", ret );
-            r.left = r.top = r.right = r.bottom = 0;
+            SetRectEmpty(&r);
             GetWindowRect( hwnd, &r );
             width = r.right - r.left;
-            r.left = r.top = r.right = r.bottom = 0;
+            SetRectEmpty(&r);
             ret = GetRgnBox( hrgn, &r );
             ok( ret == SIMPLEREGION, "GetRgnBox failed %u\n", ret );
             ok( r.left == width - 10 && r.top == 3 && r.right == width - 2 && r.bottom == 15,
@@ -6802,6 +7673,33 @@ static void test_rtl_layout(void)
     DestroyWindow( parent );
 }
 
+static void test_FlashWindow(void)
+{
+    HWND hwnd;
+    BOOL ret;
+    if (!pFlashWindow)
+    {
+        win_skip( "FlashWindow not supported\n" );
+        return;
+    }
+
+    hwnd = CreateWindowExA( 0, "MainWindowClass", "FlashWindow", WS_POPUP,
+                            0, 0, 0, 0, 0, 0, 0, NULL );
+    ok( hwnd != 0, "CreateWindowExA error %d\n", GetLastError() );
+
+    SetLastError( 0xdeadbeef );
+    ret = pFlashWindow( NULL, TRUE );
+    ok( !ret && GetLastError() == ERROR_INVALID_PARAMETER,
+        "FlashWindow returned with %d\n", GetLastError() );
+
+    DestroyWindow( hwnd );
+
+    SetLastError( 0xdeadbeef );
+    ret = pFlashWindow( hwnd, TRUE );
+    ok( !ret && GetLastError() == ERROR_INVALID_PARAMETER,
+        "FlashWindow returned with %d\n", GetLastError() );
+}
+
 static void test_FlashWindowEx(void)
 {
     HWND hwnd;
@@ -6825,13 +7723,13 @@ static void test_FlashWindowEx(void)
     finfo.hwnd = NULL;
     SetLastError(0xdeadbeef);
     ret = pFlashWindowEx(&finfo);
-    todo_wine ok(!ret && GetLastError() == ERROR_INVALID_PARAMETER,
-                 "FlashWindowEx returned with %d\n", GetLastError());
+    ok(!ret && GetLastError() == ERROR_INVALID_PARAMETER,
+       "FlashWindowEx returned with %d\n", GetLastError());
 
     finfo.hwnd = hwnd;
     SetLastError(0xdeadbeef);
     ret = pFlashWindowEx(NULL);
-    todo_wine ok(!ret && GetLastError() == ERROR_NOACCESS,
+    ok(!ret && GetLastError() == ERROR_NOACCESS,
        "FlashWindowEx returned with %d\n", GetLastError());
 
     SetLastError(0xdeadbeef);
@@ -6841,13 +7739,13 @@ static void test_FlashWindowEx(void)
     finfo.cbSize = sizeof(FLASHWINFO) - 1;
     SetLastError(0xdeadbeef);
     ret = pFlashWindowEx(&finfo);
-    todo_wine ok(!ret && GetLastError()==ERROR_INVALID_PARAMETER,
+    ok(!ret && GetLastError() == ERROR_INVALID_PARAMETER,
        "FlashWindowEx succeeded\n");
 
     finfo.cbSize = sizeof(FLASHWINFO) + 1;
     SetLastError(0xdeadbeef);
     ret = pFlashWindowEx(&finfo);
-    todo_wine ok(!ret && GetLastError()==ERROR_INVALID_PARAMETER,
+    ok(!ret && GetLastError() == ERROR_INVALID_PARAMETER,
        "FlashWindowEx succeeded\n");
     finfo.cbSize = sizeof(FLASHWINFO);
 
@@ -6855,7 +7753,7 @@ static void test_FlashWindowEx(void)
 
     SetLastError(0xdeadbeef);
     ret = pFlashWindowEx(&finfo);
-    todo_wine ok(!ret && GetLastError() == ERROR_INVALID_PARAMETER,
+    ok(!ret && GetLastError() == ERROR_INVALID_PARAMETER,
        "FlashWindowEx returned with %d\n", GetLastError());
 
     ok(finfo.cbSize == sizeof(FLASHWINFO), "FlashWindowEx modified cdSize to %x\n", finfo.cbSize);
@@ -6871,7 +7769,7 @@ static void test_FlashWindowEx(void)
 
     SetLastError(0xdeadbeef);
     ret = pFlashWindowEx(NULL);
-    todo_wine ok(!ret && GetLastError() == ERROR_NOACCESS,
+    ok(!ret && GetLastError() == ERROR_NOACCESS,
        "FlashWindowEx returned with %d\n", GetLastError());
 
     SetLastError(0xdeadbeef);
@@ -6886,7 +7784,6 @@ static void test_FlashWindowEx(void)
     finfo.dwFlags = FLASHW_STOP;
     SetLastError(0xdeadbeef);
     ret = pFlashWindowEx(&finfo);
-todo_wine
     ok(prev != ret, "previous window state should be different\n");
 
     DestroyWindow( hwnd );
@@ -6895,32 +7792,44 @@ todo_wine
 static void test_FindWindowEx(void)
 {
     HWND hwnd, found;
-    CHAR title[1];
 
     hwnd = CreateWindowExA( 0, "MainWindowClass", "caption", WS_POPUP, 0,0,0,0, 0, 0, 0, NULL );
     ok( hwnd != 0, "CreateWindowExA error %d\n", GetLastError() );
 
-    title[0] = 0;
-
-    found = FindWindowExA( 0, 0, "MainWindowClass", title );
+    num_gettext_msgs = 0;
+    found = FindWindowExA( 0, 0, "MainWindowClass", "" );
     ok( found == NULL, "expected a NULL hwnd\n" );
+    ok( num_gettext_msgs == 0, "got %u WM_GETTEXT messages\n", num_gettext_msgs );
+
+    num_gettext_msgs = 0;
     found = FindWindowExA( 0, 0, "MainWindowClass", NULL );
     ok( found == hwnd, "found is %p, expected a valid hwnd\n", found );
+    ok( num_gettext_msgs == 0, "got %u WM_GETTEXT messages\n", num_gettext_msgs );
+
+    num_gettext_msgs = 0;
+    found = FindWindowExA( 0, 0, "MainWindowClass", "caption" );
+    ok( found == hwnd, "found is %p, expected a valid hwnd\n", found );
+    ok( num_gettext_msgs == 0, "got %u WM_GETTEXT messages\n", num_gettext_msgs );
 
     DestroyWindow( hwnd );
 
     hwnd = CreateWindowExA( 0, "MainWindowClass", NULL, WS_POPUP, 0,0,0,0, 0, 0, 0, NULL );
     ok( hwnd != 0, "CreateWindowExA error %d\n", GetLastError() );
 
-    found = FindWindowExA( 0, 0, "MainWindowClass", title );
+    num_gettext_msgs = 0;
+    found = FindWindowExA( 0, 0, "MainWindowClass", "" );
     ok( found == hwnd, "found is %p, expected a valid hwnd\n", found );
+    ok( num_gettext_msgs == 0, "got %u WM_GETTEXT messages\n", num_gettext_msgs );
+
+    num_gettext_msgs = 0;
     found = FindWindowExA( 0, 0, "MainWindowClass", NULL );
     ok( found == hwnd, "found is %p, expected a valid hwnd\n", found );
+    ok( num_gettext_msgs == 0, "got %u WM_GETTEXT messages\n", num_gettext_msgs );
 
     DestroyWindow( hwnd );
 
     /* test behaviour with a window title that is an empty character */
-    found = FindWindowExA( 0, 0, "Shell_TrayWnd", title );
+    found = FindWindowExA( 0, 0, "Shell_TrayWnd", "" );
     ok( found != NULL, "found is NULL, expected a valid hwnd\n" );
     found = FindWindowExA( 0, 0, "Shell_TrayWnd", NULL );
     ok( found != NULL, "found is NULL, expected a valid hwnd\n" );
@@ -6933,15 +7842,15 @@ static void test_GetLastActivePopup(void)
     hwndOwner = CreateWindowExA(0, "MainWindowClass", NULL,
                                 WS_VISIBLE | WS_POPUPWINDOW,
                                 100, 100, 200, 200,
-                                NULL, 0, GetModuleHandle(0), NULL);
+                                NULL, 0, GetModuleHandleA(NULL), NULL);
     hwndPopup1 = CreateWindowExA(0, "MainWindowClass", NULL,
                                  WS_VISIBLE | WS_POPUPWINDOW,
                                  100, 100, 200, 200,
-                                 hwndOwner, 0, GetModuleHandle(0), NULL);
+                                 hwndOwner, 0, GetModuleHandleA(NULL), NULL);
     hwndPopup2 = CreateWindowExA(0, "MainWindowClass", NULL,
                                  WS_VISIBLE | WS_POPUPWINDOW,
                                  100, 100, 200, 200,
-                                 hwndPopup1, 0, GetModuleHandle(0), NULL);
+                                 hwndPopup1, 0, GetModuleHandleA(NULL), NULL);
     ok( GetLastActivePopup(hwndOwner) == hwndPopup2, "wrong last active popup\n" );
     DestroyWindow( hwndPopup2 );
     DestroyWindow( hwndPopup1 );
@@ -6951,12 +7860,12 @@ static void test_GetLastActivePopup(void)
 static LRESULT WINAPI my_httrasparent_proc(HWND hwnd, UINT msg, WPARAM wp, LPARAM lp)
 {
     if (msg == WM_NCHITTEST) return HTTRANSPARENT;
-    return DefWindowProc(hwnd, msg, wp, lp);
+    return DefWindowProcA(hwnd, msg, wp, lp);
 }
 
 static LRESULT WINAPI my_window_proc(HWND hwnd, UINT msg, WPARAM wp, LPARAM lp)
 {
-    return DefWindowProc(hwnd, msg, wp, lp);
+    return DefWindowProcA(hwnd, msg, wp, lp);
 }
 
 static void create_window_tree(HWND parent, HWND *window, int size)
@@ -6970,76 +7879,76 @@ static void create_window_tree(HWND parent, HWND *window, int size)
     for (i = 0; i < sizeof(style)/sizeof(style[0]); i++)
     {
         assert(pos < size);
-        window[pos] = CreateWindowEx(0, "my_window", NULL, style[i] | WS_CHILD,
+        window[pos] = CreateWindowExA(0, "my_window", NULL, style[i] | WS_CHILD,
                                      0, 0, 100, 100, parent, 0, 0, NULL);
         ok(window[pos] != 0, "CreateWindowEx failed\n");
         pos++;
         assert(pos < size);
-        window[pos] = CreateWindowEx(WS_EX_TRANSPARENT, "my_window", NULL, style[i] | WS_CHILD,
+        window[pos] = CreateWindowExA(WS_EX_TRANSPARENT, "my_window", NULL, style[i] | WS_CHILD,
                                      0, 0, 100, 100, parent, 0, 0, NULL);
         ok(window[pos] != 0, "CreateWindowEx failed\n");
         pos++;
 
         assert(pos < size);
-        window[pos] = CreateWindowEx(0, "my_httrasparent", NULL, style[i] | WS_CHILD,
+        window[pos] = CreateWindowExA(0, "my_httrasparent", NULL, style[i] | WS_CHILD,
                                      0, 0, 100, 100, parent, 0, 0, NULL);
         ok(window[pos] != 0, "CreateWindowEx failed\n");
         pos++;
         assert(pos < size);
-        window[pos] = CreateWindowEx(WS_EX_TRANSPARENT, "my_httrasparent", NULL, style[i] | WS_CHILD,
+        window[pos] = CreateWindowExA(WS_EX_TRANSPARENT, "my_httrasparent", NULL, style[i] | WS_CHILD,
                                      0, 0, 100, 100, parent, 0, 0, NULL);
         ok(window[pos] != 0, "CreateWindowEx failed\n");
         pos++;
 
         assert(pos < size);
-        window[pos] = CreateWindowEx(0, "my_button", NULL, style[i] | WS_CHILD | BS_GROUPBOX,
+        window[pos] = CreateWindowExA(0, "my_button", NULL, style[i] | WS_CHILD | BS_GROUPBOX,
                                      0, 0, 100, 100, parent, 0, 0, NULL);
         ok(window[pos] != 0, "CreateWindowEx failed\n");
         pos++;
         assert(pos < size);
-        window[pos] = CreateWindowEx(WS_EX_TRANSPARENT, "my_button", NULL, style[i] | WS_CHILD | BS_GROUPBOX,
+        window[pos] = CreateWindowExA(WS_EX_TRANSPARENT, "my_button", NULL, style[i] | WS_CHILD | BS_GROUPBOX,
                                      0, 0, 100, 100, parent, 0, 0, NULL);
         ok(window[pos] != 0, "CreateWindowEx failed\n");
         pos++;
         assert(pos < size);
-        window[pos] = CreateWindowEx(0, "my_button", NULL, style[i] | WS_CHILD | BS_PUSHBUTTON,
+        window[pos] = CreateWindowExA(0, "my_button", NULL, style[i] | WS_CHILD | BS_PUSHBUTTON,
                                      0, 0, 100, 100, parent, 0, 0, NULL);
         ok(window[pos] != 0, "CreateWindowEx failed\n");
         pos++;
         assert(pos < size);
-        window[pos] = CreateWindowEx(WS_EX_TRANSPARENT, "my_button", NULL, style[i] | WS_CHILD | BS_PUSHBUTTON,
+        window[pos] = CreateWindowExA(WS_EX_TRANSPARENT, "my_button", NULL, style[i] | WS_CHILD | BS_PUSHBUTTON,
                                      0, 0, 100, 100, parent, 0, 0, NULL);
         ok(window[pos] != 0, "CreateWindowEx failed\n");
         pos++;
 
         assert(pos < size);
-        window[pos] = CreateWindowEx(0, "Button", NULL, style[i] | WS_CHILD | BS_GROUPBOX,
+        window[pos] = CreateWindowExA(0, "Button", NULL, style[i] | WS_CHILD | BS_GROUPBOX,
                                      0, 0, 100, 100, parent, 0, 0, NULL);
         ok(window[pos] != 0, "CreateWindowEx failed\n");
         pos++;
         assert(pos < size);
-        window[pos] = CreateWindowEx(WS_EX_TRANSPARENT, "Button", NULL, style[i] | WS_CHILD | BS_GROUPBOX,
+        window[pos] = CreateWindowExA(WS_EX_TRANSPARENT, "Button", NULL, style[i] | WS_CHILD | BS_GROUPBOX,
                                      0, 0, 100, 100, parent, 0, 0, NULL);
         ok(window[pos] != 0, "CreateWindowEx failed\n");
         pos++;
         assert(pos < size);
-        window[pos] = CreateWindowEx(0, "Button", NULL, style[i] | WS_CHILD | BS_PUSHBUTTON,
+        window[pos] = CreateWindowExA(0, "Button", NULL, style[i] | WS_CHILD | BS_PUSHBUTTON,
                                      0, 0, 100, 100, parent, 0, 0, NULL);
         ok(window[pos] != 0, "CreateWindowEx failed\n");
         pos++;
         assert(pos < size);
-        window[pos] = CreateWindowEx(WS_EX_TRANSPARENT, "Button", NULL, style[i] | WS_CHILD | BS_PUSHBUTTON,
+        window[pos] = CreateWindowExA(WS_EX_TRANSPARENT, "Button", NULL, style[i] | WS_CHILD | BS_PUSHBUTTON,
                                      0, 0, 100, 100, parent, 0, 0, NULL);
         ok(window[pos] != 0, "CreateWindowEx failed\n");
         pos++;
 
         assert(pos < size);
-        window[pos] = CreateWindowEx(0, "Static", NULL, style[i] | WS_CHILD,
+        window[pos] = CreateWindowExA(0, "Static", NULL, style[i] | WS_CHILD,
                                      0, 0, 100, 100, parent, 0, 0, NULL);
         ok(window[pos] != 0, "CreateWindowEx failed\n");
         pos++;
         assert(pos < size);
-        window[pos] = CreateWindowEx(WS_EX_TRANSPARENT, "Static", NULL, style[i] | WS_CHILD,
+        window[pos] = CreateWindowExA(WS_EX_TRANSPARENT, "Static", NULL, style[i] | WS_CHILD,
                                      0, 0, 100, 100, parent, 0, 0, NULL);
         ok(window[pos] != 0, "CreateWindowEx failed\n");
         pos++;
@@ -7049,22 +7958,22 @@ static void create_window_tree(HWND parent, HWND *window, int size)
 struct window_attributes
 {
     char class_name[128];
-    int is_visible, is_enabled, is_groupbox, is_httransparent, is_extransparent;
+    BOOL is_visible, is_enabled, is_groupbox, is_httransparent, is_extransparent;
 };
 
 static void get_window_attributes(HWND hwnd, struct window_attributes *attrs)
 {
     DWORD style, ex_style, hittest;
 
-    style = GetWindowLong(hwnd, GWL_STYLE);
-    ex_style = GetWindowLong(hwnd, GWL_EXSTYLE);
+    style = GetWindowLongA(hwnd, GWL_STYLE);
+    ex_style = GetWindowLongA(hwnd, GWL_EXSTYLE);
     attrs->class_name[0] = 0;
-    GetClassName(hwnd, attrs->class_name, sizeof(attrs->class_name));
-    hittest = SendMessage(hwnd, WM_NCHITTEST, 0, 0);
+    GetClassNameA(hwnd, attrs->class_name, sizeof(attrs->class_name));
+    hittest = SendMessageA(hwnd, WM_NCHITTEST, 0, 0);
 
     attrs->is_visible = (style & WS_VISIBLE) != 0;
     attrs->is_enabled = (style & WS_DISABLED) == 0;
-    attrs->is_groupbox = !lstrcmpi(attrs->class_name, "Button") && (style & BS_TYPEMASK) == BS_GROUPBOX;
+    attrs->is_groupbox = !lstrcmpiA(attrs->class_name, "Button") && (style & BS_TYPEMASK) == BS_GROUPBOX;
     attrs->is_httransparent = hittest == HTTRANSPARENT;
     attrs->is_extransparent = (ex_style & WS_EX_TRANSPARENT) != 0;
 }
@@ -7093,26 +8002,26 @@ static void test_child_window_from_point(void)
     int found_invisible, found_disabled, found_groupbox, found_httransparent, found_extransparent;
     int ret, i;
 
-    ret = GetClassInfo(0, "Button", &cls);
+    ret = GetClassInfoA(0, "Button", &cls);
     ok(ret, "GetClassInfo(Button) failed\n");
     cls.lpszClassName = "my_button";
-    ret = RegisterClass(&cls);
+    ret = RegisterClassA(&cls);
     ok(ret, "RegisterClass(my_button) failed\n");
 
     cls.lpszClassName = "my_httrasparent";
     cls.lpfnWndProc = my_httrasparent_proc;
-    ret = RegisterClass(&cls);
+    ret = RegisterClassA(&cls);
     ok(ret, "RegisterClass(my_httrasparent) failed\n");
 
     cls.lpszClassName = "my_window";
     cls.lpfnWndProc = my_window_proc;
-    ret = RegisterClass(&cls);
+    ret = RegisterClassA(&cls);
     ok(ret, "RegisterClass(my_window) failed\n");
 
-    parent = CreateWindowEx(0, "MainWindowClass", NULL,
+    parent = CreateWindowExA(0, "MainWindowClass", NULL,
                             WS_CAPTION | WS_SYSMENU | WS_MINIMIZEBOX | WS_MAXIMIZEBOX | WS_POPUP | WS_VISIBLE,
                             100, 100, 200, 200,
-                            0, 0, GetModuleHandle(0), NULL);
+                            0, 0, GetModuleHandleA(NULL), NULL);
     ok(parent != 0, "CreateWindowEx failed\n");
     trace("parent %p\n", parent);
 
@@ -7134,9 +8043,7 @@ static void test_child_window_from_point(void)
         ok(hwnd != 0, "RealChildWindowFromPoint failed\n");
         ret = window_to_index(hwnd, window, sizeof(window)/sizeof(window[0]));
         /* FIXME: remove once Wine is fixed */
-        if (ret != real_child_pos[i])
-            todo_wine ok(ret == real_child_pos[i] || broken(ret == real_child_pos_nt4[i]), "expected %d, got %d\n", real_child_pos[i], ret);
-        else
+        todo_wine_if (ret != real_child_pos[i])
             ok(ret == real_child_pos[i] || broken(ret == real_child_pos_nt4[i]), "expected %d, got %d\n", real_child_pos[i], ret);
 
         get_window_attributes(hwnd, &attrs);
@@ -7172,14 +8079,175 @@ todo_wine
 todo_wine
     ok(found_extransparent, "found %d extransparent windows\n", found_extransparent);
 
-    ret = UnregisterClass("my_button", cls.hInstance);
+    ret = UnregisterClassA("my_button", cls.hInstance);
     ok(ret, "UnregisterClass(my_button) failed\n");
-    ret = UnregisterClass("my_httrasparent", cls.hInstance);
+    ret = UnregisterClassA("my_httrasparent", cls.hInstance);
     ok(ret, "UnregisterClass(my_httrasparent) failed\n");
-    ret = UnregisterClass("my_window", cls.hInstance);
+    ret = UnregisterClassA("my_window", cls.hInstance);
     ok(ret, "UnregisterClass(my_window) failed\n");
 }
 
+static void simulate_click(int x, int y)
+{
+    INPUT input[2];
+    UINT events_no;
+
+    SetCursorPos(x, y);
+    memset(input, 0, sizeof(input));
+    input[0].type = INPUT_MOUSE;
+    U(input[0]).mi.dx = x;
+    U(input[0]).mi.dy = y;
+    U(input[0]).mi.dwFlags = MOUSEEVENTF_LEFTDOWN;
+    input[1].type = INPUT_MOUSE;
+    U(input[1]).mi.dx = x;
+    U(input[1]).mi.dy = y;
+    U(input[1]).mi.dwFlags = MOUSEEVENTF_LEFTUP;
+    events_no = SendInput(2, input, sizeof(input[0]));
+    ok(events_no == 2, "SendInput returned %d\n", events_no);
+}
+
+static WNDPROC def_static_proc;
+static BOOL got_hittest;
+static LRESULT WINAPI static_hook_proc(HWND hwnd, UINT msg, WPARAM wp, LPARAM lp)
+{
+    if(msg == WM_NCHITTEST)
+        got_hittest = TRUE;
+    if(msg == WM_LBUTTONDOWN)
+        ok(0, "unexpected call\n");
+
+    return def_static_proc(hwnd, msg, wp, lp);
+}
+
+static void window_from_point_proc(HWND parent)
+{
+    HANDLE start_event, end_event;
+    HANDLE win, child_static, child_button;
+    BOOL got_click;
+    DWORD ret;
+    POINT pt;
+    MSG msg;
+
+    start_event = OpenEventA(EVENT_ALL_ACCESS, FALSE, "test_wfp_start");
+    ok(start_event != 0, "OpenEvent failed\n");
+    end_event = OpenEventA(EVENT_ALL_ACCESS, FALSE, "test_wfp_end");
+    ok(end_event != 0, "OpenEvent failed\n");
+
+    child_static = CreateWindowExA(0, "static", "static", WS_CHILD | WS_VISIBLE,
+            0, 0, 100, 100, parent, 0, NULL, NULL);
+    ok(child_static != 0, "CreateWindowEx failed\n");
+    pt.x = pt.y = 150;
+    win = WindowFromPoint(pt);
+    ok(win == parent, "WindowFromPoint returned %p, expected %p\n", win, parent);
+
+    child_button = CreateWindowExA(0, "button", "button", WS_CHILD | WS_VISIBLE,
+            100, 0, 100, 100, parent, 0, NULL, NULL);
+    ok(child_button != 0, "CreateWindowEx failed\n");
+    pt.x = 250;
+    win = WindowFromPoint(pt);
+    ok(win == child_button, "WindowFromPoint returned %p, expected %p\n", win, child_button);
+
+    /* without this window simulate click test keeps sending WM_NCHITTEST
+     * message to child_static in an infinite loop */
+    win = CreateWindowExA(0, "button", "button", WS_CHILD | WS_VISIBLE,
+            0, 0, 100, 100, parent, 0, NULL, NULL);
+    ok(win != 0, "CreateWindowEx failed\n");
+    def_static_proc = (void*)SetWindowLongPtrA(child_static,
+            GWLP_WNDPROC, (LONG_PTR)static_hook_proc);
+    flush_events(TRUE);
+    SetEvent(start_event);
+
+    got_hittest = FALSE;
+    got_click = FALSE;
+    while(!got_click && wait_for_message(&msg)) {
+        if(msg.message == WM_LBUTTONUP) {
+            ok(msg.hwnd == win, "msg.hwnd = %p, expected %p\n", msg.hwnd, win);
+            got_click = TRUE;
+        }
+        DispatchMessageA(&msg);
+    }
+    ok(got_hittest, "transparent window didn't get WM_NCHITTEST message\n");
+    ok(got_click, "button under static window didn't get WM_LBUTTONUP\n");
+
+    ret = WaitForSingleObject(end_event, 5000);
+    ok(ret == WAIT_OBJECT_0, "WaitForSingleObject returned %x\n", ret);
+
+    CloseHandle(start_event);
+    CloseHandle(end_event);
+}
+
+static void test_window_from_point(const char *argv0)
+{
+    HWND hwnd, child, win;
+    POINT pt;
+    PROCESS_INFORMATION info;
+    STARTUPINFOA startup;
+    char cmd[MAX_PATH];
+    HANDLE start_event, end_event;
+
+    hwnd = CreateWindowExA(0, "MainWindowClass", NULL, WS_POPUP | WS_VISIBLE,
+            100, 100, 200, 100, 0, 0, NULL, NULL);
+    ok(hwnd != 0, "CreateWindowEx failed\n");
+
+    pt.x = pt.y = 150;
+    win = WindowFromPoint(pt);
+    pt.x = 250;
+    if(win == hwnd)
+        win = WindowFromPoint(pt);
+    if(win != hwnd) {
+        skip("there's another window covering test window\n");
+        DestroyWindow(hwnd);
+        return;
+    }
+
+    child = CreateWindowExA(0, "static", "static", WS_CHILD | WS_VISIBLE,
+            0, 0, 100, 100, hwnd, 0, NULL, NULL);
+    ok(child != 0, "CreateWindowEx failed\n");
+    pt.x = pt.y = 150;
+    win = WindowFromPoint(pt);
+    ok(win == hwnd, "WindowFromPoint returned %p, expected %p\n", win, hwnd);
+    DestroyWindow(child);
+
+    child = CreateWindowExA(0, "button", "button", WS_CHILD | WS_VISIBLE,
+                0, 0, 100, 100, hwnd, 0, NULL, NULL);
+    ok(child != 0, "CreateWindowEx failed\n");
+    win = WindowFromPoint(pt);
+    ok(win == child, "WindowFromPoint returned %p, expected %p\n", win, child);
+    DestroyWindow(child);
+
+    start_event = CreateEventA(NULL, FALSE, FALSE, "test_wfp_start");
+    ok(start_event != 0, "CreateEvent failed\n");
+    end_event = CreateEventA(NULL, FALSE, FALSE, "test_wfp_end");
+    ok(start_event != 0, "CreateEvent failed\n");
+
+    sprintf(cmd, "%s win create_children %p\n", argv0, hwnd);
+    memset(&startup, 0, sizeof(startup));
+    startup.cb = sizeof(startup);
+    ok(CreateProcessA(NULL, cmd, NULL, NULL, FALSE, 0, NULL, NULL,
+                &startup, &info), "CreateProcess failed.\n");
+    ok(wait_for_event(start_event, 1000), "didn't get start_event\n");
+
+    child = GetWindow(hwnd, GW_CHILD);
+    win = WindowFromPoint(pt);
+    ok(win == child, "WindowFromPoint returned %p, expected %p\n", win, child);
+
+    simulate_click(150, 150);
+    flush_events(TRUE);
+
+    child = GetWindow(child, GW_HWNDNEXT);
+    pt.x = 250;
+    win = WindowFromPoint(pt);
+    ok(win == child, "WindowFromPoint returned %p, expected %p\n", win, child);
+
+    SetEvent(end_event);
+    winetest_wait_child_process(info.hProcess);
+    CloseHandle(start_event);
+    CloseHandle(end_event);
+    CloseHandle(info.hProcess);
+    CloseHandle(info.hThread);
+
+    DestroyWindow(hwnd);
+}
+
 static void test_map_points(void)
 {
     BOOL ret;
@@ -7194,11 +8262,11 @@ static void test_map_points(void)
     RECT client_rect;
 
     /* Create test windows */
-    wnd = CreateWindow("static", "test1", WS_POPUP, pos.x, pos.y, width, height, NULL, NULL, NULL, NULL);
+    wnd = CreateWindowA("static", "test1", WS_POPUP, pos.x, pos.y, width, height, NULL, NULL, NULL, NULL);
     ok(wnd != NULL, "Failed %p\n", wnd);
-    wnd0 = CreateWindow("static", "test2", WS_POPUP, 0, 0, width, height, NULL, NULL, NULL, NULL);
+    wnd0 = CreateWindowA("static", "test2", WS_POPUP, 0, 0, width, height, NULL, NULL, NULL, NULL);
     ok(wnd0 != NULL, "Failed %p\n", wnd);
-    dwnd = CreateWindow("static", "test3", 0, 200, 300, 150, 150, NULL, NULL, NULL, NULL);
+    dwnd = CreateWindowA("static", "test3", 0, 200, 300, 150, 150, NULL, NULL, NULL, NULL);
     DestroyWindow(dwnd);
     ok(dwnd != NULL, "Failed %p\n", dwnd);
 
@@ -7469,8 +8537,658 @@ todo_wine
     DestroyWindow(parent);
 }
 
+static void test_window_without_child_style(void)
+{
+    HWND hwnd;
+
+    hwnd = CreateWindowExA(0, "edit", NULL, WS_VISIBLE|WS_CHILD,
+            0, 0, 50, 50, hwndMain, NULL, 0, NULL);
+    ok(hwnd != NULL, "CreateWindow failed\n");
+
+    ok(SetWindowLongA(hwnd, GWL_STYLE, GetWindowLongA(hwnd, GWL_STYLE) & (~WS_CHILD)),
+            "can't remove WS_CHILD style\n");
+
+    SetActiveWindow(hwndMain);
+    PostMessageW(hwnd, WM_LBUTTONUP, 0, 0);
+    SendMessageW(hwnd, WM_NCLBUTTONDOWN, HTCAPTION, 0);
+    check_active_state(hwnd, hwnd, hwnd);
+    flush_events(TRUE);
+
+    DestroyWindow(hwnd);
+}
+
+
+struct smresult_thread_data
+{
+    HWND main_hwnd;
+    HWND thread_hwnd;
+    HANDLE thread_started;
+    HANDLE thread_got_wm_app;
+    HANDLE main_in_wm_app_1;
+    HANDLE thread_replied;
+};
+
+
+static LRESULT WINAPI smresult_wndproc(HWND hwnd, UINT msg, WPARAM wparam, LPARAM lparam)
+{
+    switch (msg)
+    {
+    case WM_APP:
+    {
+        struct smresult_thread_data *data = (struct smresult_thread_data*)lparam;
+
+        ok(hwnd == data->thread_hwnd, "unexpected hwnd %p\n", hwnd);
+
+        SendNotifyMessageA(data->main_hwnd, WM_APP+1, 0, lparam);
+
+        /* Don't return until the main thread is processing our sent message. */
+        ok(WaitForSingleObject(data->main_in_wm_app_1, INFINITE) == WAIT_OBJECT_0, "WaitForSingleObject failed\n");
+
+        /* Break the PeekMessage loop so we can notify the main thread after we return. */
+        SetEvent(data->thread_got_wm_app);
+
+        return 0x240408ea;
+    }
+    case WM_APP+1:
+    {
+        struct smresult_thread_data *data = (struct smresult_thread_data*)lparam;
+        LRESULT res;
+
+        ok(hwnd == data->main_hwnd, "unexpected hwnd %p\n", hwnd);
+
+        /* Ask the thread to reply to our WM_APP message. */
+        SetEvent(data->main_in_wm_app_1);
+
+        /* Wait until the thread has sent a reply. */
+        ok(WaitForSingleObject(data->thread_replied, INFINITE) == WAIT_OBJECT_0, "WaitForSingleObject failed\n");
+
+        /* Send another message while we have a reply queued for the current one. */
+        res = SendMessageA(data->thread_hwnd, WM_APP+2, 0, lparam);
+        ok(res == 0x449b0190, "unexpected result %lx\n", res);
+
+        return 0;
+    }
+    case WM_APP+2:
+    {
+        struct smresult_thread_data *data = (struct smresult_thread_data*)lparam;
+
+        ok(hwnd == data->thread_hwnd, "unexpected hwnd %p\n", hwnd);
+
+        /* Don't return until we know the main thread is processing sent messages. */
+        SendMessageA(data->main_hwnd, WM_NULL, 0, 0);
+
+        return 0x449b0190;
+    }
+    case WM_CLOSE:
+        PostQuitMessage(0);
+        break;
+    }
+    return DefWindowProcA(hwnd, msg, wparam, lparam);
+}
+
+static DWORD WINAPI smresult_thread_proc(void *param)
+{
+    MSG msg;
+    struct smresult_thread_data *data = param;
+
+    data->thread_hwnd = CreateWindowExA(0, "SmresultClass", "window caption text", WS_OVERLAPPEDWINDOW,
+                                      100, 100, 200, 200, 0, 0, 0, NULL);
+    ok(data->thread_hwnd != 0, "Failed to create overlapped window\n");
+
+    SetEvent(data->thread_started);
+
+    /* Loop until we've processed WM_APP. */
+    while (WaitForSingleObject(data->thread_got_wm_app, 0) != WAIT_OBJECT_0)
+    {
+        if (PeekMessageA(&msg, 0, 0, 0, PM_REMOVE))
+        {
+            TranslateMessage(&msg);
+            DispatchMessageA(&msg);
+        }
+        else
+        {
+            MsgWaitForMultipleObjects(1, &data->thread_got_wm_app, FALSE, INFINITE, QS_SENDMESSAGE);
+        }
+    }
+
+    /* Notify the main thread that we replied to its WM_APP message. */
+    SetEvent(data->thread_replied);
+
+    while (GetMessageA(&msg, 0, 0, 0))
+    {
+        TranslateMessage(&msg);
+        DispatchMessageA(&msg);
+    }
+
+    return 0;
+}
+
+static void test_smresult(void)
+{
+    WNDCLASSA cls;
+    HANDLE hThread;
+    DWORD tid;
+    struct smresult_thread_data data;
+    BOOL ret;
+    LRESULT res;
+
+    cls.style = CS_DBLCLKS;
+    cls.lpfnWndProc = smresult_wndproc;
+    cls.cbClsExtra = 0;
+    cls.cbWndExtra = 0;
+    cls.hInstance = GetModuleHandleA(0);
+    cls.hIcon = 0;
+    cls.hCursor = LoadCursorA(0, (LPCSTR)IDC_ARROW);
+    cls.hbrBackground = GetStockObject(WHITE_BRUSH);
+    cls.lpszMenuName = NULL;
+    cls.lpszClassName = "SmresultClass";
+
+    ret = RegisterClassA(&cls);
+    ok(ret, "RegisterClassA failed\n");
+
+    data.thread_started = CreateEventA(NULL, TRUE, FALSE, NULL);
+    ok(data.thread_started != NULL, "CreateEventA failed\n");
+
+    data.thread_got_wm_app = CreateEventA(NULL, TRUE, FALSE, NULL);
+    ok(data.thread_got_wm_app != NULL, "CreateEventA failed\n");
+
+    data.main_in_wm_app_1 = CreateEventA(NULL, TRUE, FALSE, NULL);
+    ok(data.main_in_wm_app_1 != NULL, "CreateEventA failed\n");
+
+    data.thread_replied = CreateEventA(NULL, TRUE, FALSE, NULL);
+    ok(data.thread_replied != NULL, "CreateEventA failed\n");
+
+    data.main_hwnd = CreateWindowExA(0, "SmresultClass", "window caption text", WS_OVERLAPPEDWINDOW,
+                                      100, 100, 200, 200, 0, 0, 0, NULL);
+
+    hThread = CreateThread(NULL, 0, smresult_thread_proc, &data, 0, &tid);
+    ok(hThread != NULL, "CreateThread failed, error %d\n", GetLastError());
+
+    ok(WaitForSingleObject(data.thread_started, INFINITE) == WAIT_OBJECT_0, "WaitForSingleObject failed\n");
+
+    res = SendMessageA(data.thread_hwnd, WM_APP, 0, (LPARAM)&data);
+    ok(res == 0x240408ea, "unexpected result %lx\n", res);
+
+    SendMessageA(data.thread_hwnd, WM_CLOSE, 0, 0);
+
+    DestroyWindow(data.main_hwnd);
+
+    ok(WaitForSingleObject(hThread, INFINITE) == WAIT_OBJECT_0, "WaitForSingleObject failed\n");
+
+    CloseHandle(data.thread_started);
+    CloseHandle(data.thread_got_wm_app);
+    CloseHandle(data.main_in_wm_app_1);
+    CloseHandle(data.thread_replied);
+}
+
+static void test_GetMessagePos(void)
+{
+    HWND button;
+    DWORD pos;
+    MSG msg;
+
+    button = CreateWindowExA(0, "button", "button", WS_VISIBLE,
+            100, 100, 100, 100, 0, 0, 0, NULL);
+    ok(button != 0, "CreateWindowExA failed\n");
+
+    SetCursorPos(120, 140);
+    flush_events(TRUE);
+    pos = GetMessagePos();
+    ok(pos == MAKELONG(120, 140), "pos = %08x\n", pos);
+
+    SetCursorPos(340, 320);
+    pos = GetMessagePos();
+    ok(pos == MAKELONG(120, 140), "pos = %08x\n", pos);
+
+    SendMessageW(button, WM_APP, 0, 0);
+    pos = GetMessagePos();
+    ok(pos == MAKELONG(120, 140), "pos = %08x\n", pos);
+
+    PostMessageA(button, WM_APP, 0, 0);
+    GetMessageA(&msg, button, 0, 0);
+    ok(msg.message == WM_APP, "msg.message = %x\n", msg.message);
+    pos = GetMessagePos();
+    ok(pos == MAKELONG(340, 320), "pos = %08x\n", pos);
+
+    PostMessageA(button, WM_APP, 0, 0);
+    SetCursorPos(350, 330);
+    GetMessageA(&msg, button, 0, 0);
+    ok(msg.message == WM_APP, "msg.message = %x\n", msg.message);
+    pos = GetMessagePos();
+    ok(pos == MAKELONG(340, 320), "pos = %08x\n", pos);
+
+    PostMessageA(button, WM_APP, 0, 0);
+    SetCursorPos(320, 340);
+    PostMessageA(button, WM_APP+1, 0, 0);
+    pos = GetMessagePos();
+    ok(pos == MAKELONG(340, 320), "pos = %08x\n", pos);
+    GetMessageA(&msg, button, 0, 0);
+    ok(msg.message == WM_APP, "msg.message = %x\n", msg.message);
+    pos = GetMessagePos();
+    ok(pos == MAKELONG(350, 330), "pos = %08x\n", pos);
+    GetMessageA(&msg, button, 0, 0);
+    ok(msg.message == WM_APP+1, "msg.message = %x\n", msg.message);
+    pos = GetMessagePos();
+    ok(pos == MAKELONG(320, 340), "pos = %08x\n", pos);
+
+    SetTimer(button, 1, 250, NULL);
+    SetCursorPos(330, 350);
+    GetMessageA(&msg, button, 0, 0);
+    while (msg.message == WM_PAINT)
+    {
+        UpdateWindow( button );
+        GetMessageA(&msg, button, 0, 0);
+    }
+    ok(msg.message == WM_TIMER, "msg.message = %x\n", msg.message);
+    pos = GetMessagePos();
+    ok(pos == MAKELONG(330, 350), "pos = %08x\n", pos);
+    KillTimer(button, 1);
+
+    DestroyWindow(button);
+}
+
+#define SET_FOREGROUND_STEAL_1          0x01
+#define SET_FOREGROUND_SET_1            0x02
+#define SET_FOREGROUND_STEAL_2          0x04
+#define SET_FOREGROUND_SET_2            0x08
+#define SET_FOREGROUND_INJECT           0x10
+
+struct set_foreground_thread_params
+{
+    UINT msg_quit, msg_command;
+    HWND window1, window2, thread_window;
+    HANDLE command_executed;
+};
+
+static DWORD WINAPI set_foreground_thread(void *params)
+{
+    struct set_foreground_thread_params *p = params;
+    MSG msg;
+
+    p->thread_window = CreateWindowExA(0, "static", "thread window", WS_OVERLAPPEDWINDOW | WS_VISIBLE,
+            0, 0, 10, 10, 0, 0, 0, NULL);
+    SetEvent(p->command_executed);
+
+    while(GetMessageA(&msg, 0, 0, 0))
+    {
+        if (msg.message == p->msg_quit)
+            break;
+
+        if (msg.message == p->msg_command)
+        {
+            if (msg.wParam & SET_FOREGROUND_STEAL_1)
+            {
+                SetForegroundWindow(p->thread_window);
+                check_wnd_state(p->thread_window, p->thread_window, p->thread_window, 0);
+            }
+            if (msg.wParam & SET_FOREGROUND_INJECT)
+            {
+                SendNotifyMessageA(p->window1, WM_ACTIVATEAPP, 0, 0);
+            }
+            if (msg.wParam & SET_FOREGROUND_SET_1)
+            {
+                SetForegroundWindow(p->window1);
+                check_wnd_state(0, p->window1, 0, 0);
+            }
+            if (msg.wParam & SET_FOREGROUND_STEAL_2)
+            {
+                SetForegroundWindow(p->thread_window);
+                check_wnd_state(p->thread_window, p->thread_window, p->thread_window, 0);
+            }
+            if (msg.wParam & SET_FOREGROUND_SET_2)
+            {
+                SetForegroundWindow(p->window2);
+                check_wnd_state(0, p->window2, 0, 0);
+            }
+
+            SetEvent(p->command_executed);
+            continue;
+        }
+
+        TranslateMessage(&msg);
+        DispatchMessageA(&msg);
+    }
+
+    DestroyWindow(p->thread_window);
+    return 0;
+}
+
+static void test_activateapp(HWND window1)
+{
+    HWND window2, test_window;
+    HANDLE thread;
+    struct set_foreground_thread_params thread_params;
+    DWORD tid;
+    MSG msg;
+
+    window2 = CreateWindowExA(0, "static", "window 2", WS_OVERLAPPEDWINDOW | WS_VISIBLE,
+            300, 0, 10, 10, 0, 0, 0, NULL);
+    thread_params.msg_quit = WM_USER;
+    thread_params.msg_command = WM_USER + 1;
+    thread_params.window1 = window1;
+    thread_params.window2 = window2;
+    thread_params.command_executed = CreateEventW(NULL, FALSE, FALSE, NULL);
+
+    thread = CreateThread(NULL, 0, set_foreground_thread, &thread_params, 0, &tid);
+    WaitForSingleObject(thread_params.command_executed, INFINITE);
+
+    SetForegroundWindow(window1);
+    check_wnd_state(window1, window1, window1, 0);
+    while (PeekMessageA(&msg, 0, 0, 0, PM_REMOVE)) DispatchMessageA(&msg);
+
+    /* Steal foreground: WM_ACTIVATEAPP(0) is delivered. */
+    app_activated = app_deactivated = FALSE;
+    PostThreadMessageA(tid, thread_params.msg_command, SET_FOREGROUND_STEAL_1, 0);
+    WaitForSingleObject(thread_params.command_executed, INFINITE);
+    test_window = GetForegroundWindow();
+    ok(test_window == thread_params.thread_window, "Expected foreground window %p, got %p\n",
+            thread_params.thread_window, test_window);
+    /* Active and Focus window are sometimes 0 on KDE. Ignore them.
+     * check_wnd_state(window1, thread_params.thread_window, window1, 0); */
+    ok(!app_activated, "Received WM_ACTIVATEAPP(1), did not expect it.\n");
+    ok(!app_deactivated, "Received WM_ACTIVATEAPP(0), did not expect it.\n");
+    while (PeekMessageA(&msg, 0, 0, 0, PM_REMOVE)) DispatchMessageA(&msg);
+    check_wnd_state(0, thread_params.thread_window, 0, 0);
+    test_window = GetForegroundWindow();
+    ok(test_window == thread_params.thread_window, "Expected foreground window %p, got %p\n",
+            thread_params.thread_window, test_window);
+    ok(!app_activated, "Received WM_ACTIVATEAPP(1), did not expect it.\n");
+    /* This message is reliable on Windows and inside a virtual desktop.
+     * It is unreliable on KDE (50/50) and never arrives on FVWM.
+     * ok(app_deactivated, "Expected WM_ACTIVATEAPP(0), did not receive it.\n"); */
+
+    /* Set foreground: WM_ACTIVATEAPP (1) is delivered. */
+    app_activated = app_deactivated = FALSE;
+    PostThreadMessageA(tid, thread_params.msg_command, SET_FOREGROUND_SET_1, 0);
+    WaitForSingleObject(thread_params.command_executed, INFINITE);
+    check_wnd_state(0, 0, 0, 0);
+    test_window = GetForegroundWindow();
+    ok(!test_window, "Expected foreground window 0, got %p\n", test_window);
+    ok(!app_activated, "Received WM_ACTIVATEAPP(!= 0), did not expect it.\n");
+    ok(!app_deactivated, "Received WM_ACTIVATEAPP(0), did not expect it.\n");
+    while (PeekMessageA(&msg, 0, 0, 0, PM_REMOVE)) DispatchMessageA(&msg);
+    check_wnd_state(window1, window1, window1, 0);
+    test_window = GetForegroundWindow();
+    ok(test_window == window1, "Expected foreground window %p, got %p\n",
+            window1, test_window);
+    ok(app_activated, "Expected WM_ACTIVATEAPP(1), did not receive it.\n");
+    ok(!app_deactivated, "Received WM_ACTIVATEAPP(0), did not expect it.\n");
+
+    /* Steal foreground then set it back: No messages are delivered. */
+    app_activated = app_deactivated = FALSE;
+    PostThreadMessageA(tid, thread_params.msg_command, SET_FOREGROUND_STEAL_1 | SET_FOREGROUND_SET_1, 0);
+    WaitForSingleObject(thread_params.command_executed, INFINITE);
+    test_window = GetForegroundWindow();
+    ok(test_window == window1, "Expected foreground window %p, got %p\n",
+            window1, test_window);
+    check_wnd_state(window1, window1, window1, 0);
+    ok(!app_activated, "Received WM_ACTIVATEAPP(1), did not expect it.\n");
+    ok(!app_deactivated, "Received WM_ACTIVATEAPP(0), did not expect it.\n");
+    while (PeekMessageA(&msg, 0, 0, 0, PM_REMOVE)) DispatchMessageA(&msg);
+    test_window = GetForegroundWindow();
+    ok(test_window == window1, "Expected foreground window %p, got %p\n",
+            window1, test_window);
+    check_wnd_state(window1, window1, window1, 0);
+    ok(!app_activated, "Received WM_ACTIVATEAPP(1), did not expect it.\n");
+    ok(!app_deactivated, "Received WM_ACTIVATEAPP(0), did not expect it.\n");
+
+    /* This is not implemented with a plain WM_ACTIVATEAPP filter. */
+    app_activated = app_deactivated = FALSE;
+    PostThreadMessageA(tid, thread_params.msg_command, SET_FOREGROUND_STEAL_1
+            | SET_FOREGROUND_INJECT | SET_FOREGROUND_SET_1, 0);
+    WaitForSingleObject(thread_params.command_executed, INFINITE);
+    test_window = GetForegroundWindow();
+    ok(test_window == window1, "Expected foreground window %p, got %p\n",
+            window1, test_window);
+    check_wnd_state(window1, window1, window1, 0);
+    ok(!app_activated, "Received WM_ACTIVATEAPP(1), did not expect it.\n");
+    ok(!app_deactivated, "Received WM_ACTIVATEAPP(0), did not expect it.\n");
+    while (PeekMessageA(&msg, 0, 0, 0, PM_REMOVE)) DispatchMessageA(&msg);
+    test_window = GetForegroundWindow();
+    ok(test_window == window1, "Expected foreground window %p, got %p\n",
+            window1, test_window);
+    check_wnd_state(window1, window1, window1, 0);
+    ok(!app_activated, "Received WM_ACTIVATEAPP(1), did not expect it.\n");
+    ok(app_deactivated, "Expected WM_ACTIVATEAPP(0), did not receive it.\n");
+
+    SetForegroundWindow(thread_params.thread_window);
+
+    /* Set foreground then remove: Both messages are delivered. */
+    app_activated = app_deactivated = FALSE;
+    PostThreadMessageA(tid, thread_params.msg_command, SET_FOREGROUND_SET_1 | SET_FOREGROUND_STEAL_2, 0);
+    WaitForSingleObject(thread_params.command_executed, INFINITE);
+    test_window = GetForegroundWindow();
+    ok(test_window == thread_params.thread_window, "Expected foreground window %p, got %p\n",
+            thread_params.thread_window, test_window);
+    check_wnd_state(0, thread_params.thread_window, 0, 0);
+    ok(!app_activated, "Received WM_ACTIVATEAPP(1), did not expect it.\n");
+    ok(!app_deactivated, "Received WM_ACTIVATEAPP(0), did not expect it.\n");
+    while (PeekMessageA(&msg, 0, 0, 0, PM_REMOVE)) DispatchMessageA(&msg);
+    test_window = GetForegroundWindow();
+    ok(test_window == thread_params.thread_window, "Expected foreground window %p, got %p\n",
+            thread_params.thread_window, test_window);
+    /* Active and focus are window1 on wine because the internal WM_WINE_SETACTIVEWINDOW(0)
+     * message is never generated. GetCapture() returns 0 though, so we'd get a test success
+     * in todo_wine in the line below.
+     * todo_wine check_wnd_state(0, thread_params.thread_window, 0, 0); */
+    ok(app_activated, "Expected WM_ACTIVATEAPP(1), did not receive it.\n");
+    todo_wine ok(app_deactivated, "Expected WM_ACTIVATEAPP(0), did not receive it.\n");
+
+    SetForegroundWindow(window1);
+    test_window = GetForegroundWindow();
+    ok(test_window == window1, "Expected foreground window %p, got %p\n",
+            window1, test_window);
+    check_wnd_state(window1, window1, window1, 0);
+
+    /* Switch to a different window from the same thread? No messages. */
+    app_activated = app_deactivated = FALSE;
+    PostThreadMessageA(tid, thread_params.msg_command, SET_FOREGROUND_STEAL_1 | SET_FOREGROUND_SET_2, 0);
+    WaitForSingleObject(thread_params.command_executed, INFINITE);
+    test_window = GetForegroundWindow();
+    ok(test_window == window1, "Expected foreground window %p, got %p\n",
+            window1, test_window);
+    check_wnd_state(window1, window1, window1, 0);
+    ok(!app_activated, "Received WM_ACTIVATEAPP(1), did not expect it.\n");
+    ok(!app_deactivated, "Received WM_ACTIVATEAPP(0), did not expect it.\n");
+    while (PeekMessageA(&msg, 0, 0, 0, PM_REMOVE)) DispatchMessageA(&msg);
+    test_window = GetForegroundWindow();
+    ok(test_window == window2, "Expected foreground window %p, got %p\n",
+            window2, test_window);
+    check_wnd_state(window2, window2, window2, 0);
+    ok(!app_activated, "Received WM_ACTIVATEAPP(1), did not expect it.\n");
+    ok(!app_deactivated, "Received WM_ACTIVATEAPP(0), did not expect it.\n");
+
+    PostThreadMessageA(tid, thread_params.msg_quit, 0, 0);
+    WaitForSingleObject(thread, INFINITE);
+
+    CloseHandle(thread_params.command_executed);
+    DestroyWindow(window2);
+}
+
+static LRESULT WINAPI winproc(HWND hwnd, UINT msg, WPARAM wparam, LPARAM lparam)
+{
+    if(!hwnd) {
+        int *count = (int*)lparam;
+        (*count)++;
+    }
+    return 0;
+}
+
+static LRESULT WINAPI winproc_convA(HWND hwnd, UINT msg, WPARAM wparam, LPARAM lparam)
+{
+    if(msg == WM_SETTEXT)
+    {
+        const char *text = (const char*)lparam;
+
+        ok(!wparam, "wparam = %08lx\n", wparam);
+        ok(!strcmp(text, "text"), "WM_SETTEXT lparam = %s\n", text);
+        return 1;
+    }
+    return 0;
+}
+
+static const WCHAR textW[] = {'t','e','x','t',0};
+static LRESULT WINAPI winproc_convW(HWND hwnd, UINT msg, WPARAM wparam, LPARAM lparam)
+{
+    if(msg == WM_SETTEXT)
+    {
+        const WCHAR *text = (const WCHAR*)lparam;
+
+        ok(!wparam, "wparam = %08lx\n", wparam);
+        ok(!lstrcmpW(text, textW), "WM_SETTEXT lparam = %s\n", wine_dbgstr_w(text));
+        return 1;
+    }
+    return 0;
+}
+
+static void test_winproc_handles(const char *argv0)
+{
+    static const WCHAR winproc_testW[] = {'w','i','n','p','r','o','c','_','t','e','s','t',0};
+
+    HINSTANCE hinst = GetModuleHandleA(NULL);
+    WNDCLASSA wnd_classA;
+    WNDCLASSW wnd_classW;
+    int count, ret;
+    PROCESS_INFORMATION info;
+    STARTUPINFOA startup;
+    char cmd[MAX_PATH];
+
+    memset(&wnd_classA, 0, sizeof(wnd_classA));
+    wnd_classA.lpszClassName = "winproc_test";
+    wnd_classA.lpfnWndProc = winproc;
+    ret = RegisterClassA(&wnd_classA);
+    ok(ret, "RegisterClass failed with error %d\n", GetLastError());
+
+    ret = GetClassInfoW(hinst, winproc_testW, &wnd_classW);
+    ok(ret, "GetClassInfoW failed with error %d\n", GetLastError());
+    ok(wnd_classA.lpfnWndProc != wnd_classW.lpfnWndProc,
+            "winproc pointers should not be identical\n");
+
+    count = 0;
+    CallWindowProcA(wnd_classW.lpfnWndProc, 0, 0, 0, (LPARAM)&count);
+    ok(count == 1, "winproc should be called once (%d)\n", count);
+    count = 0;
+    CallWindowProcW(wnd_classW.lpfnWndProc, 0, 0, 0, (LPARAM)&count);
+    ok(count == 1, "winproc should be called once (%d)\n", count);
+
+    ret = UnregisterClassW(winproc_testW, hinst);
+    ok(ret, "UnregisterClass failed with error %d\n", GetLastError());
+
+    /* crashes on 64-bit windows because lpfnWndProc handle is already freed */
+    if (sizeof(void*) == 4)
+    {
+        count = 0;
+        CallWindowProcA(wnd_classW.lpfnWndProc, 0, 0, 0, (LPARAM)&count);
+        todo_wine ok(!count, "winproc should not be called (%d)\n", count);
+        CallWindowProcW(wnd_classW.lpfnWndProc, 0, 0, 0, (LPARAM)&count);
+        todo_wine ok(!count, "winproc should not be called (%d)\n", count);
+    }
+
+    sprintf(cmd, "%s win winproc_limit", argv0);
+    memset(&startup, 0, sizeof(startup));
+    startup.cb = sizeof(startup);
+    ok(CreateProcessA(NULL, cmd, NULL, NULL, FALSE, 0, NULL, NULL,
+                &startup, &info), "CreateProcess failed.\n");
+    winetest_wait_child_process(info.hProcess);
+    CloseHandle(info.hProcess);
+    CloseHandle(info.hThread);
+}
+
+static void test_winproc_limit(void)
+{
+    WNDPROC winproc_handle;
+    LONG_PTR ret;
+    HWND hwnd;
+    int i;
+
+    hwnd = CreateWindowExA(0, "static", "test", WS_POPUP, 0, 0, 0, 0, 0, 0, 0, 0);
+    ok(hwnd != 0, "CreateWindowEx failed\n");
+
+    ok(SetWindowLongPtrA(hwnd, GWLP_WNDPROC, (LONG_PTR)winproc),
+            "SetWindowLongPtr failed\n");
+    winproc_handle = (WNDPROC)GetWindowLongPtrW(hwnd, GWLP_WNDPROC);
+    ok(winproc_handle != winproc, "winproc pointers should not be identical\n");
+
+    /* run out of winproc slots */
+    for(i = 2; i<0xffff; i++)
+    {
+        ok(SetWindowLongPtrA(hwnd, GWLP_WNDPROC, i), "SetWindowLongPtr failed (%d)\n", i);
+        if(GetWindowLongPtrW(hwnd, GWLP_WNDPROC) == i)
+            break;
+    }
+    ok(i != 0xffff, "unable to run out of winproc slots\n");
+
+    ret = SetWindowLongPtrA(hwnd, GWLP_WNDPROC, (LONG_PTR)winproc_convA);
+    ok(ret, "SetWindowLongPtr failed with error %d\n", GetLastError());
+    ok(SendMessageA(hwnd, WM_SETTEXT, 0, (LPARAM)"text"), "WM_SETTEXT failed\n");
+    ok(SendMessageW(hwnd, WM_SETTEXT, 0, (LPARAM)textW), "WM_SETTEXT with conversion failed\n");
+
+    ret = SetWindowLongPtrW(hwnd, GWLP_WNDPROC, (LONG_PTR)winproc_convW);
+    ok(ret, "SetWindowLongPtr failed with error %d\n", GetLastError());
+    ok(SendMessageA(hwnd, WM_SETTEXT, 0, (LPARAM)"text"), "WM_SETTEXT failed\n");
+    ok(SendMessageW(hwnd, WM_SETTEXT, 0, (LPARAM)textW), "WM_SETTEXT with conversion failed\n");
+
+    /* Show that there's no message conversion when CallWindowProc is used */
+    ok(CallWindowProcA(winproc_convW, hwnd, WM_SETTEXT, 0, (LPARAM)textW) == 1,
+            "winproc_convW returned error\n");
+    ok(CallWindowProcW(winproc_convW, hwnd, WM_SETTEXT, 0, (LPARAM)textW) == 1,
+            "winproc_convW returned error\n");
+
+    i = 0;
+    CallWindowProcA(winproc_handle, 0, 0, 0, (LPARAM)&i);
+    ok(i == 1, "winproc should be called once (%d)\n", i);
+    i = 0;
+    CallWindowProcW(winproc_handle, 0, 0, 0, (LPARAM)&i);
+    ok(i == 1, "winproc should be called once (%d)\n", i);
+
+    DestroyWindow(hwnd);
+
+    i = 0;
+    CallWindowProcA(winproc_handle, 0, 0, 0, (LPARAM)&i);
+    ok(i == 1, "winproc should be called once (%d)\n", i);
+    i = 0;
+    CallWindowProcW(winproc_handle, 0, 0, 0, (LPARAM)&i);
+    ok(i == 1, "winproc should be called once (%d)\n", i);
+}
+
+static void test_deferwindowpos(void)
+{
+    HDWP hdwp, hdwp2;
+    BOOL ret;
+
+    hdwp = BeginDeferWindowPos(0);
+    ok(hdwp != NULL, "got %p\n", hdwp);
+
+    ret = EndDeferWindowPos(NULL);
+    ok(!ret, "got %d\n", ret);
+
+    hdwp2 = DeferWindowPos(NULL, NULL, NULL, 0, 0, 10, 10, 0);
+todo_wine
+    ok(hdwp2 == NULL && ((GetLastError() == ERROR_INVALID_DWP_HANDLE) ||
+        broken(GetLastError() == ERROR_INVALID_WINDOW_HANDLE) /* before win8 */), "got %p, error %d\n", hdwp2, GetLastError());
+
+    hdwp2 = DeferWindowPos((HDWP)0xdead, GetDesktopWindow(), NULL, 0, 0, 10, 10, 0);
+todo_wine
+    ok(hdwp2 == NULL && ((GetLastError() == ERROR_INVALID_DWP_HANDLE) ||
+        broken(GetLastError() == ERROR_INVALID_WINDOW_HANDLE) /* before win8 */), "got %p, error %d\n", hdwp2, GetLastError());
+
+    hdwp2 = DeferWindowPos(hdwp, NULL, NULL, 0, 0, 10, 10, 0);
+    ok(hdwp2 == NULL && GetLastError() == ERROR_INVALID_WINDOW_HANDLE, "got %p, error %d\n", hdwp2, GetLastError());
+
+    hdwp2 = DeferWindowPos(hdwp, GetDesktopWindow(), NULL, 0, 0, 10, 10, 0);
+    ok(hdwp2 == NULL && GetLastError() == ERROR_INVALID_WINDOW_HANDLE, "got %p, error %d\n", hdwp2, GetLastError());
+
+    hdwp2 = DeferWindowPos(hdwp, (HWND)0xdead, NULL, 0, 0, 10, 10, 0);
+    ok(hdwp2 == NULL && GetLastError() == ERROR_INVALID_WINDOW_HANDLE, "got %p, error %d\n", hdwp2, GetLastError());
+
+    ret = EndDeferWindowPos(hdwp);
+    ok(ret, "got %d\n", ret);
+}
+
 START_TEST(win)
 {
+    char **argv;
+    int argc = winetest_get_mainargs( &argv );
     HMODULE user32 = GetModuleHandleA( "user32.dll" );
     HMODULE gdi32 = GetModuleHandleA("gdi32.dll");
     pGetAncestor = (void *)GetProcAddress( user32, "GetAncestor" );
@@ -7486,13 +9204,42 @@ START_TEST(win)
     pGetGUIThreadInfo = (void *)GetProcAddress( user32, "GetGUIThreadInfo" );
     pGetProcessDefaultLayout = (void *)GetProcAddress( user32, "GetProcessDefaultLayout" );
     pSetProcessDefaultLayout = (void *)GetProcAddress( user32, "SetProcessDefaultLayout" );
+    pFlashWindow = (void *)GetProcAddress( user32, "FlashWindow" );
     pFlashWindowEx = (void *)GetProcAddress( user32, "FlashWindowEx" );
     pGetLayout = (void *)GetProcAddress( gdi32, "GetLayout" );
     pSetLayout = (void *)GetProcAddress( gdi32, "SetLayout" );
     pMirrorRgn = (void *)GetProcAddress( gdi32, "MirrorRgn" );
 
+    if (argc==4 && !strcmp(argv[2], "create_children"))
+    {
+        HWND hwnd;
+
+        sscanf(argv[3], "%p", &hwnd);
+        window_from_point_proc(hwnd);
+        return;
+    }
+
+    if (argc==3 && !strcmp(argv[2], "winproc_limit"))
+    {
+        test_winproc_limit();
+        return;
+    }
+
     if (!RegisterWindowClasses()) assert(0);
 
+    hwndMain = CreateWindowExA(/*WS_EX_TOOLWINDOW*/ 0, "MainWindowClass", "Main window",
+                               WS_CAPTION | WS_SYSMENU | WS_MINIMIZEBOX |
+                               WS_MAXIMIZEBOX | WS_POPUP | WS_VISIBLE,
+                               100, 100, 200, 200,
+                               0, 0, GetModuleHandleA(NULL), NULL);
+    assert( hwndMain );
+
+    if(!SetForegroundWindow(hwndMain)) {
+        /* workaround for foreground lock timeout */
+        simulate_click(101, 101);
+        ok(SetForegroundWindow(hwndMain), "SetForegroundWindow failed\n");
+    }
+
     SetLastError(0xdeafbeef);
     GetWindowLongPtrW(GetDesktopWindow(), GWLP_WNDPROC);
     is_win9x = (GetLastError() == ERROR_CALL_NOT_IMPLEMENTED);
@@ -7504,23 +9251,18 @@ START_TEST(win)
     test_FindWindowEx();
     test_SetParent();
 
-    hwndMain = CreateWindowExA(/*WS_EX_TOOLWINDOW*/ 0, "MainWindowClass", "Main window",
-                               WS_CAPTION | WS_SYSMENU | WS_MINIMIZEBOX |
-                               WS_MAXIMIZEBOX | WS_POPUP,
-                               100, 100, 200, 200,
-                               0, 0, GetModuleHandle(0), NULL);
     hwndMain2 = CreateWindowExA(/*WS_EX_TOOLWINDOW*/ 0, "MainWindowClass", "Main window 2",
                                 WS_CAPTION | WS_SYSMENU | WS_MINIMIZEBOX |
                                 WS_MAXIMIZEBOX | WS_POPUP,
                                 100, 100, 200, 200,
-                                0, 0, GetModuleHandle(0), NULL);
-    assert( hwndMain );
+                                0, 0, GetModuleHandleA(NULL), NULL);
     assert( hwndMain2 );
 
     our_pid = GetWindowThreadProcessId(hwndMain, NULL);
 
     /* Add the tests below this line */
     test_child_window_from_point();
+    test_window_from_point(argv[0]);
     test_thick_child_size(hwndMain);
     test_fullscreen();
     test_hwnd_message();
@@ -7532,6 +9274,7 @@ START_TEST(win)
     test_capture_3(hwndMain, hwndMain2);
     test_capture_4();
     test_rtl_layout();
+    test_FlashWindow();
     test_FlashWindowEx();
 
     test_CreateWindow();
@@ -7564,24 +9307,32 @@ START_TEST(win)
     test_AdjustWindowRect();
     test_window_styles();
     test_dialog_styles();
+    test_dialog_parent();
     test_redrawnow();
     test_csparentdc();
     test_SetWindowLong();
     test_ShowWindow();
-    if (0) test_gettext(); /* crashes on NT4 */
+    test_gettext();
     test_GetUpdateRect();
     test_Expose();
     test_layered_window();
 
     test_SetForegroundWindow(hwndMain);
-    if(!winetest_interactive)
-       skip("bug ROSTESTS-23: skipping test_shell_window, it crashes ros/win7 explorer\n");
-    else
-       test_shell_window();
+    test_shell_window();
     test_handles( hwndMain );
     test_winregion();
     test_map_points();
     test_update_region();
+    test_window_without_child_style();
+    test_smresult();
+    test_GetMessagePos();
+
+    if (!winetest_interactive)
+        skip("ROSTESTS-208: Skipping test_activateapp(hwndMain).\n");
+    else
+        test_activateapp(hwndMain);
+    test_winproc_handles(argv[0]);
+    test_deferwindowpos();
 
     /* add the tests above this line */
     if (hhook) UnhookWindowsHookEx(hhook);