-sync user32_winetest with wine 1.1.32
[reactos.git] / rostests / winetests / user32 / win.c
index d45eba3..0bd6fbf 100644 (file)
@@ -569,6 +569,60 @@ static void test_parent_owner(void)
     DestroyWindow( owner );
 }
 
+static BOOL CALLBACK enum_proc( HWND hwnd, LPARAM lParam)
+{
+    (*(LPINT)lParam)++;
+    if (*(LPINT)lParam > 2) return FALSE;
+    return TRUE;
+}
+static DWORD CALLBACK enum_thread( void *arg )
+{
+    INT count;
+    HWND hwnd[3];
+    BOOL ret;
+    MSG msg;
+
+    PeekMessage( &msg, 0, 0, 0, PM_NOREMOVE );  /* make sure we have a message queue */
+
+    count = 0;
+    ret = EnumThreadWindows( GetCurrentThreadId(), enum_proc, (LPARAM)&count );
+    ok( ret, "EnumThreadWindows should have returned TRUE\n" );
+    ok( count == 0, "count should be 0 got %d\n", count );
+
+    hwnd[0] = CreateWindowExA(0, "ToolWindowClass", "Tool window 1", WS_POPUP,
+                              0, 0, 100, 100, 0, 0, 0, NULL );
+    count = 0;
+    ret = EnumThreadWindows( GetCurrentThreadId(), enum_proc, (LPARAM)&count );
+    ok( ret, "EnumThreadWindows should have returned TRUE\n" );
+    if (count != 2)  /* Vista gives us two windows for the price of one */
+    {
+        ok( count == 1, "count should be 1 got %d\n", count );
+        hwnd[2] = CreateWindowExA(0, "ToolWindowClass", "Tool window 2", WS_POPUP,
+                                  0, 0, 100, 100, 0, 0, 0, NULL );
+    }
+    else hwnd[2] = 0;
+
+    hwnd[1] = CreateWindowExA(0, "ToolWindowClass", "Tool window 3", WS_POPUP,
+                              0, 0, 100, 100, 0, 0, 0, NULL );
+    count = 0;
+    ret = EnumThreadWindows( GetCurrentThreadId(), enum_proc, (LPARAM)&count );
+    ok( !ret, "EnumThreadWindows should have returned FALSE\n" );
+    ok( count == 3, "count should be 3 got %d\n", count );
+
+    if (hwnd[2]) DestroyWindow(hwnd[2]);
+    DestroyWindow(hwnd[1]);
+    DestroyWindow(hwnd[0]);
+    return 0;
+}
+
+/* test EnumThreadWindows in a separate thread */
+static void test_enum_thread_windows(void)
+{
+    DWORD id;
+    HANDLE handle = CreateThread( NULL, 0, enum_thread, 0, 0, &id );
+    ok( !WaitForSingleObject( handle, 10000 ), "wait failed\n" );
+    CloseHandle( handle );
+}
 
 static LRESULT WINAPI main_window_procA(HWND hwnd, UINT msg, WPARAM wparam, LPARAM lparam)
 {
@@ -3218,6 +3272,59 @@ static void test_window_styles(void)
     check_window_style(0, WS_EX_APPWINDOW, WS_CLIPSIBLINGS|WS_CAPTION, WS_EX_APPWINDOW|WS_EX_WINDOWEDGE);
 }
 
+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);
+}
+
 static void test_scrollvalidate( HWND parent)
 {
     HDC hdc;
@@ -4859,6 +4966,75 @@ static void test_Expose(void)
     DestroyWindow(mw);
 }
 
+static LRESULT CALLBACK TestNCRedraw_WndProc(HWND hwnd, UINT msg, WPARAM wParam, LPARAM lParam)
+{
+    static UINT ncredrawflags;
+    PAINTSTRUCT ps;
+
+    switch(msg)
+    {
+    case WM_CREATE:
+        ncredrawflags = *(UINT *) (((CREATESTRUCT *)lParam)->lpCreateParams);
+        return 0;
+    case WM_NCPAINT:
+        RedrawWindow(hwnd, NULL, NULL, ncredrawflags);
+        break;
+    case WM_PAINT:
+        BeginPaint(hwnd, &ps);
+        EndPaint(hwnd, &ps);
+        return 0;
+    }
+    return DefWindowProc(hwnd, msg, wParam, lParam);
+}
+
+static void run_NCRedrawLoop(UINT flags)
+{
+    HWND hwnd;
+    MSG msg;
+
+    UINT loopcount = 0;
+
+    hwnd = CreateWindowA("TestNCRedrawClass", "MainWindow",
+                         WS_OVERLAPPEDWINDOW, 0, 0, 200, 100,
+                         NULL, NULL, 0, &flags);
+    ShowWindow(hwnd, SW_SHOW);
+    UpdateWindow(hwnd);
+    while(PeekMessage(&msg, hwnd, 0, 0, PM_REMOVE) != 0)
+    {
+        if (msg.message == WM_PAINT) loopcount++;
+        if (loopcount >= 100) break;
+        TranslateMessage(&msg);
+        DispatchMessage(&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
+        ok(loopcount < 100, "Detected infinite WM_PAINT loop (%x).\n", flags);
+    DestroyWindow(hwnd);
+}
+
+static void test_NCRedraw(void)
+{
+    WNDCLASSA wndclass;
+
+    wndclass.lpszClassName = "TestNCRedrawClass";
+    wndclass.style = CS_HREDRAW | CS_VREDRAW;
+    wndclass.lpfnWndProc = TestNCRedraw_WndProc;
+    wndclass.cbClsExtra = 0;
+    wndclass.cbWndExtra = 0;
+    wndclass.hInstance = 0;
+    wndclass.hIcon = LoadIcon(NULL, IDI_APPLICATION);
+    wndclass.hCursor = LoadCursor(NULL, IDC_ARROW);
+    wndclass.hbrBackground = GetStockObject(WHITE_BRUSH);
+    wndclass.lpszMenuName = NULL;
+
+    RegisterClassA(&wndclass);
+
+    run_NCRedrawLoop(RDW_INVALIDATE | RDW_FRAME);
+    run_NCRedrawLoop(RDW_INVALIDATE);
+}
+
 static void test_GetWindowModuleFileName(void)
 {
     HWND hwnd;
@@ -5640,6 +5816,7 @@ START_TEST(win)
     test_CreateWindow();
     test_parent_owner();
     test_SetParent();
+    test_enum_thread_windows();
 
     test_mdi();
     test_icons();
@@ -5647,6 +5824,7 @@ START_TEST(win)
     test_SetMenu(hwndMain);
     test_SetFocus(hwndMain);
     test_SetActiveWindow(hwndMain);
+    test_NCRedraw();
 
     test_children_zorder(hwndMain);
     test_popup_zorder(hwndMain2, hwndMain);
@@ -5654,6 +5832,7 @@ START_TEST(win)
     test_mouse_input(hwndMain);
     test_validatergn(hwndMain);
     test_nccalcscroll( hwndMain);
+    test_scrollwindow( hwndMain);
     test_scrollvalidate( hwndMain);
     test_scrolldc( hwndMain);
     test_scroll();