FindWindow should not match against partial names

Mike Hearn mike at theoretic.com
Sat Dec 27 05:56:49 CST 2003


Currently FindWindow("one") will match against "one two", because
GetWindowText will truncate it to the length of the text to match
against.

Mike Hearn <mike at theoretic.com>
In WIN_FindWindow, use the result of GetWindowTextLength to allocate the
buffer instead of using the length of the text to match against.
Prevents a particular type of false match.


Index: windows/win.c
===================================================================
RCS file: /home/wine/wine/windows/win.c,v
retrieving revision 1.230
diff -u -r1.230 win.c
--- windows/win.c       11 Dec 2003 05:34:53 -0000      1.230
+++ windows/win.c       27 Dec 2003 11:41:38 -0000
@@ -1515,14 +1515,8 @@
     HWND *list = NULL;
     HWND retvalue = 0;
     int i = 0, len = 0;
-    WCHAR *buffer = NULL;
  
     if (!parent) parent = GetDesktopWindow();
-    if (title)
-    {
-        len = strlenW(title) + 1;  /* one extra char to check for chars beyond the end */
-        if (!(buffer = HeapAlloc( GetProcessHeap(), 0, (len + 1) * sizeof(WCHAR) ))) return 0;
-    }
  
     if (!(list = list_window_children( parent, className, 0 ))) goto done;
  
@@ -1538,15 +1532,21 @@
     {
         while (list[i])
         {
-            if (GetWindowTextW( list[i], buffer, len ) && !strcmpiW( buffer, title )) break;
-            i++;
+            int len = GetWindowTextLengthW( list[i] ) + 1; /* one extra char to check for chars beyond the end */
+            WCHAR *buffer = HeapAlloc( GetProcessHeap(), 0, (len + 1) * sizeof(WCHAR) );
+
+            int matched = (GetWindowTextW( list[i], buffer, len ) && !strcmpiW( buffer, title ));
+
+            HeapFree( GetProcessHeap(), 0, buffer );
+
+            if (matched) break;
+            i++;
         }
     }
     retvalue = list[i];
  
  done:
     if (list) HeapFree( GetProcessHeap(), 0, list );
-    if (buffer) HeapFree( GetProcessHeap(), 0, buffer );
     return retvalue;
 }
  







More information about the wine-patches mailing list