user32: FindWindow() should treat an empty title same way as NULL. (Resend)

Dmitry Timoshkov dmitry at codeweavers.com
Tue Oct 19 00:22:53 CDT 2010


This version of the patch adds its own tests, and doesn't rely on
"Shell_TrayWnd" being captionless.
---
 dlls/user32/tests/win.c |   24 +++++++++++++++++++++---
 dlls/user32/win.c       |    9 ++++++++-
 2 files changed, 29 insertions(+), 4 deletions(-)

diff --git a/dlls/user32/tests/win.c b/dlls/user32/tests/win.c
index 0acd704..80aad49 100644
--- a/dlls/user32/tests/win.c
+++ b/dlls/user32/tests/win.c
@@ -6239,15 +6239,31 @@ static void test_rtl_layout(void)
 
 static void test_FindWindowEx(void)
 {
-    HWND found;
+    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 );
     ok( found == NULL, "expected a NULL hwnd\n" );
     found = FindWindowExA( 0, 0, "MainWindowClass", NULL );
-    ok( found != NULL, "found is NULL, expected a valid hwnd\n" );
+    ok( found == hwnd, "found is %p, expected a valid hwnd\n", found );
+
+    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 );
+    ok( found == hwnd, "found is %p, expected a valid hwnd\n", found );
+    found = FindWindowExA( 0, 0, "MainWindowClass", NULL );
+    ok( found == hwnd, "found is %p, expected a valid hwnd\n", found );
+
+    DestroyWindow( hwnd );
+
     /* test behaviour with a window title that is an empty character */
     found = FindWindowExA( 0, 0, "Shell_TrayWnd", title );
 todo_wine
@@ -6307,6 +6323,9 @@ START_TEST(win)
     hhook = SetWindowsHookExA(WH_CBT, cbt_hook_proc, 0, GetCurrentThreadId());
     if (!hhook) win_skip( "Cannot set CBT hook, skipping some tests\n" );
 
+    /* make sure that FindWindow tests are executed first */
+    test_FindWindowEx();
+
     hwndMain = CreateWindowExA(/*WS_EX_TOOLWINDOW*/ 0, "MainWindowClass", "Main window",
                                WS_CAPTION | WS_SYSMENU | WS_MINIMIZEBOX |
                                WS_MAXIMIZEBOX | WS_POPUP,
@@ -6374,7 +6393,6 @@ START_TEST(win)
     test_Expose();
     test_layered_window();
 
-    test_FindWindowEx();
     test_SetForegroundWindow(hwndMain);
     test_shell_window();
     test_handles( hwndMain );
diff --git a/dlls/user32/win.c b/dlls/user32/win.c
index 1b67329..f9b6be2 100644
--- a/dlls/user32/win.c
+++ b/dlls/user32/win.c
@@ -1767,7 +1767,14 @@ HWND WINAPI FindWindowExW( HWND parent, HWND child, LPCWSTR className, LPCWSTR t
     {
         while (list[i])
         {
-            if (GetWindowTextW( list[i], buffer, len + 1 ) && !strcmpiW( buffer, title )) break;
+            if (GetWindowTextW( list[i], buffer, len + 1 ))
+            {
+                if (!strcmpiW( buffer, title )) break;
+            }
+            else
+            {
+                if (!title[0]) break;
+            }
             i++;
         }
     }
-- 
1.7.0.6




More information about the wine-patches mailing list