user32: Avoid querying the server to determine whether the desktop window is a child window.

Huw Davies huw at codeweavers.com
Tue Jan 31 08:15:03 CST 2017


Signed-off-by: Huw Davies <huw at codeweavers.com>
---
 dlls/user32/win.c | 31 +++++++++++++++++++++++++++++--
 1 file changed, 29 insertions(+), 2 deletions(-)

diff --git a/dlls/user32/win.c b/dlls/user32/win.c
index a7be4a3..341769f 100644
--- a/dlls/user32/win.c
+++ b/dlls/user32/win.c
@@ -414,6 +414,33 @@ static HWND *list_window_parents( HWND hwnd )
     return NULL;
 }
 
+/*******************************************************************
+ *		is_child_win
+ *
+ * Helper to determine whether WS_CHILD is set.
+ * It avoids a server round trip for the desktop window.
+ */
+static BOOL is_child_win( HWND hwnd )
+{
+    WND *wndPtr = WIN_GetPtr( hwnd );
+    BOOL ret;
+
+    if (!wndPtr)
+    {
+        SetLastError( ERROR_INVALID_WINDOW_HANDLE );
+        return FALSE;
+    }
+
+    if (wndPtr == WND_OTHER_PROCESS)
+        return GetWindowLongW( hwnd, GWL_STYLE ) & WS_CHILD;
+
+    if (wndPtr == WND_DESKTOP)
+        return FALSE;
+
+    ret = wndPtr->dwStyle & WS_CHILD;
+    WIN_ReleasePtr( wndPtr );
+    return ret;
+}
 
 /*******************************************************************
  *           send_parent_notify
@@ -3092,7 +3119,7 @@ BOOL WINAPI IsChild( HWND parent, HWND child )
     int i;
     BOOL ret = FALSE;
 
-    if (!(GetWindowLongW( child, GWL_STYLE ) & WS_CHILD)) return FALSE;
+    if (!is_child_win( child )) return FALSE;
     if (!(list = list_window_parents( child ))) return FALSE;
     parent = WIN_GetFullHandle( parent );
     for (i = 0; list[i]; i++)
@@ -3102,7 +3129,7 @@ BOOL WINAPI IsChild( HWND parent, HWND child )
             ret = list[i] && list[i+1];
             break;
         }
-        if (!(GetWindowLongW( list[i], GWL_STYLE ) & WS_CHILD)) break;
+        if (!is_child_win( list[i] )) break;
     }
     HeapFree( GetProcessHeap(), 0, list );
     return ret;
-- 
2.10.2




More information about the wine-patches mailing list