Commit in reactos/subsys/win32k on MAIN
include/cursoricon.h+3-11.6 -> 1.7
       /prop.h+61.6 -> 1.7
       /window.h+6-81.50 -> 1.51
       /winpos.h+1-11.11 -> 1.12
misc/object.c+1-41.10 -> 1.11
ntuser/msgqueue.c+24-81.72 -> 1.73
      /vis.c+5-61.20 -> 1.21
      /window.c+111-371.193 -> 1.194
      /winpos.c+56-511.100 -> 1.101
objects/cursoricon.c+1-71.48 -> 1.49
+214-123
10 modified files
fixed crashes that could be caused by the thread cleanup routine when destroying windows from different threads

reactos/subsys/win32k/include
cursoricon.h 1.6 -> 1.7
diff -u -r1.6 -r1.7
--- cursoricon.h	24 Feb 2004 13:27:02 -0000	1.6
+++ cursoricon.h	26 Feb 2004 22:23:54 -0000	1.7
@@ -19,10 +19,12 @@
 HCURSOR FASTCALL IntSetCursor(PWINSTATION_OBJECT WinStaObject, PCURICON_OBJECT NewCursor, BOOL ForceChange);
 BOOL FASTCALL IntSetupCurIconHandles(PWINSTATION_OBJECT WinStaObject);
 PCURICON_OBJECT FASTCALL IntGetCurIconObject(PWINSTATION_OBJECT WinStaObject, HANDLE Handle);
-VOID FASTCALL IntReleaseCurIconObject(PCURICON_OBJECT Object);
 PCURICON_OBJECT FASTCALL IntCreateCurIconHandle(PWINSTATION_OBJECT WinStaObject);
 VOID FASTCALL IntCleanupCurIcons(struct _EPROCESS *Process, PW32PROCESS Win32Process);
 
+#define IntReleaseCurIconObject(CurIconObj) \
+  ObmDereferenceObject(CurIconObj)
+
 #define IntLockProcessCursorIcons(W32Process) \
   ExAcquireFastMutex(&W32Process->CursorIconListLock)
 

reactos/subsys/win32k/include
prop.h 1.6 -> 1.7
diff -u -r1.6 -r1.7
--- prop.h	24 Feb 2004 13:27:02 -0000	1.6
+++ prop.h	26 Feb 2004 22:23:54 -0000	1.7
@@ -8,6 +8,12 @@
   ATOM Atom;
 } PROPERTY, *PPROPERTY;
 
+BOOL FASTCALL
+IntSetProp(PWINDOW_OBJECT Wnd, ATOM Atom, HANDLE Data);
+
+PPROPERTY FASTCALL
+IntGetProp(PWINDOW_OBJECT WindowObject, ATOM Atom);
+
 #define IntLockWindowProperties(Window) \
   ExAcquireFastMutex(&Window->PropListLock)
 

reactos/subsys/win32k/include
window.h 1.50 -> 1.51
diff -u -r1.50 -r1.51
--- window.h	24 Feb 2004 13:27:02 -0000	1.50
+++ window.h	26 Feb 2004 22:23:54 -0000	1.51
@@ -72,9 +72,9 @@
   struct _WINDOW_OBJECT* PrevSibling;
   /* Entry in the list of thread windows. */
   LIST_ENTRY ThreadListEntry;
-  /* Pointer to the parent window. */
+  /* Handle to the parent window. */
   HANDLE Parent;
-  /* Pointer to the owner window. */
+  /* Handle to the owner window. */
   HANDLE Owner;
   /* DC Entries (DCE) */
   PDCE Dce;
@@ -93,6 +93,7 @@
   PETHREAD OwnerThread;
   HWND hWndLastPopup; /* handle to last active popup window (wine doesn't use pointer, for unk. reason)*/
   PINTERNALPOS InternalPos;
+  ULONG Status;
 } WINDOW_OBJECT; /* PWINDOW_OBJECT already declared at top of file */
 
 /* Window flags. */
@@ -102,6 +103,9 @@
 #define WINDOWOBJECT_NEED_INTERNALPAINT   (0x00000008)
 #define WINDOWOBJECT_RESTOREMAX           (0x00000020)
 
+#define WINDOWSTATUS_DESTROYING         (0x1)
+#define WINDOWSTATUS_DESTROYED          (0x2)
+
 #define IntIsDesktopWindow(WndObj) \
   (WndObj->Parent == NULL)
 
@@ -167,12 +171,6 @@
 BOOL FASTCALL
 IntIsChildWindow (HWND Parent, HWND Child);
 
-BOOL FASTCALL
-IntSetProp(PWINDOW_OBJECT Wnd, ATOM Atom, HANDLE Data);
-
-PPROPERTY FASTCALL
-IntGetProp(PWINDOW_OBJECT WindowObject, ATOM Atom);
-
 VOID FASTCALL
 IntUnlinkWindow(PWINDOW_OBJECT Wnd);
 

reactos/subsys/win32k/include
winpos.h 1.11 -> 1.12
diff -u -r1.11 -r1.12
--- winpos.h	24 Feb 2004 15:56:52 -0000	1.11
+++ winpos.h	26 Feb 2004 22:23:54 -0000	1.12
@@ -20,7 +20,7 @@
 BOOLEAN FASTCALL
 WinPosShowWindow(HWND Wnd, INT Cmd);
 USHORT FASTCALL
-WinPosWindowFromPoint(PWINDOW_OBJECT ScopeWin, BOOL SendProcHitTests, POINT *WinPoint, 
+WinPosWindowFromPoint(PWINDOW_OBJECT ScopeWin, BOOL SendHitTestMessage, POINT *WinPoint, 
 		      PWINDOW_OBJECT* Window);
 VOID FASTCALL WinPosActivateOtherWindow(PWINDOW_OBJECT Window);
 

reactos/subsys/win32k/misc
object.c 1.10 -> 1.11
diff -u -r1.10 -r1.11
--- object.c	24 Feb 2004 13:27:03 -0000	1.10
+++ object.c	26 Feb 2004 22:23:54 -0000	1.11
@@ -16,7 +16,7 @@
  *  along with this program; if not, write to the Free Software
  *  Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
  */
-/* $Id: object.c,v 1.10 2004/02/24 13:27:03 weiden Exp $
+/* $Id: object.c,v 1.11 2004/02/26 22:23:54 weiden Exp $
  *
  * COPYRIGHT:      See COPYING in the top level directory
  * PROJECT:        ReactOS kernel
@@ -31,7 +31,6 @@
 
 #include <ddk/ntddk.h>
 #include <include/object.h>
-#include <include/window.h>
 
 #define NDEBUG
 #include <debug.h>
@@ -289,7 +288,6 @@
   ObjectHeader = BODY_TO_HEADER(ObjectBody);
   
   ObjectHeader->RefCount--;
-  
   ObmpPerformRetentionChecks(ObjectHeader);
 }
 
@@ -312,7 +310,6 @@
     {
       return STATUS_INVALID_PARAMETER;
     }
-  
   ObjectHeader->RefCount++;
   
   return STATUS_SUCCESS;

reactos/subsys/win32k/ntuser
msgqueue.c 1.72 -> 1.73
diff -u -r1.72 -r1.73
--- msgqueue.c	24 Feb 2004 15:56:52 -0000	1.72
+++ msgqueue.c	26 Feb 2004 22:23:54 -0000	1.73
@@ -16,7 +16,7 @@
  *  along with this program; if not, write to the Free Software
  *  Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
  */
-/* $Id: msgqueue.c,v 1.72 2004/02/24 15:56:52 weiden Exp $
+/* $Id: msgqueue.c,v 1.73 2004/02/26 22:23:54 weiden Exp $
  *
  * COPYRIGHT:        See COPYING in the top level directory
  * PROJECT:          ReactOS kernel
@@ -255,7 +255,12 @@
       Msg == WM_RBUTTONDOWN ||
       Msg == WM_XBUTTONDOWN)
   {
-    USHORT Hit = WinPosWindowFromPoint(ScopeWin, FALSE, &Message->Msg.pt, &Window);
+    *HitTest = WinPosWindowFromPoint(ScopeWin, !FromGlobalQueue, &Message->Msg.pt, &Window);
+    if(Window && FromGlobalQueue && (PsGetWin32Thread()->MessageQueue == Window->MessageQueue))
+    {
+      *HitTest = IntSendMessage(Window->Self, WM_NCHITTEST, 0, 
+                                MAKELONG(Message->Msg.pt.x, Message->Msg.pt.y));
+    }
     /*
     **Make sure that we have a window that is not already in focus
     */
@@ -263,9 +268,9 @@
     {
       if(Window->Self != IntGetFocusWindow())
       {
-        SpareLParam = MAKELONG(Hit, Msg);
+        SpareLParam = MAKELONG(*HitTest, Msg);
         
-        if(Hit != (USHORT)HTTRANSPARENT)
+        if(*HitTest != (USHORT)HTTRANSPARENT)
         {
           Result = IntSendMessage(Window->Self, WM_MOUSEACTIVATE, (WPARAM)NtUserGetParent(Window->Self), (LPARAM)SpareLParam);
           
@@ -297,7 +302,6 @@
           return(FALSE);
         }
       }
-      IntReleaseWindowObject(Window);
     }
 
   }
@@ -309,20 +313,32 @@
     if(Msg == WM_MOUSEWHEEL)
     {
       *HitTest = HTCLIENT;
+      if(Window)
+        IntReleaseWindowObject(Window);
       Window = IntGetWindowObject(IntGetFocusWindow());
     }
     else
     {
-      *HitTest = WinPosWindowFromPoint(ScopeWin, FALSE, &Message->Msg.pt, &Window);
       if(!Window)
       {
-        /* change the cursor on desktop background */
-        IntLoadDefaultCursors(TRUE);
+        *HitTest = WinPosWindowFromPoint(ScopeWin, !FromGlobalQueue, &Message->Msg.pt, &Window);
+        if(Window && FromGlobalQueue && (PsGetWin32Thread()->MessageQueue == Window->MessageQueue))
+        {
+          *HitTest = IntSendMessage(Window->Self, WM_NCHITTEST, 0, 
+                                    MAKELONG(Message->Msg.pt.x, Message->Msg.pt.y));
+        }
+        if(!Window)
+        {
+          /* change the cursor on desktop background */
+          IntLoadDefaultCursors(TRUE);
+        }
       }
     }
   }
   else
   {
+    if(Window)
+      IntReleaseWindowObject(Window);
     Window = IntGetWindowObject(CaptureWin);
     *HitTest = HTCLIENT;
   }

reactos/subsys/win32k/ntuser
vis.c 1.20 -> 1.21
diff -u -r1.20 -r1.21
--- vis.c	24 Feb 2004 01:30:57 -0000	1.20
+++ vis.c	26 Feb 2004 22:23:54 -0000	1.21
@@ -16,7 +16,7 @@
  *  along with this program; if not, write to the Free Software
  *  Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
  *
- * $Id: vis.c,v 1.20 2004/02/24 01:30:57 weiden Exp $
+ * $Id: vis.c,v 1.21 2004/02/26 22:23:54 weiden Exp $
  *
  * COPYRIGHT:        See COPYING in the top level directory
  * PROJECT:          ReactOS kernel
@@ -144,12 +144,11 @@
       NtGdiOffsetRgn(Temp,
                      Window->WindowRect.left - Parent->ClientRect.left,
                      Window->WindowRect.top - Parent->ClientRect.top);
-   }
-   IntRedrawWindow(Parent, NULL, Temp,
-                   RDW_FRAME | RDW_ERASE | RDW_INVALIDATE | 
-                   RDW_ALLCHILDREN);
-   if(Parent)
+     IntRedrawWindow(Parent, NULL, Temp,
+                     RDW_FRAME | RDW_ERASE | RDW_INVALIDATE | 
+                     RDW_ALLCHILDREN);
      IntReleaseWindowObject(Parent);
+   }
    NtGdiDeleteObject(Temp);
 }
 

reactos/subsys/win32k/ntuser
window.c 1.193 -> 1.194
diff -u -r1.193 -r1.194
--- window.c	24 Feb 2004 15:56:52 -0000	1.193
+++ window.c	26 Feb 2004 22:23:54 -0000	1.194
@@ -16,7 +16,7 @@
  *  along with this program; if not, write to the Free Software
  *  Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
  */
-/* $Id: window.c,v 1.193 2004/02/24 15:56:52 weiden Exp $
+/* $Id: window.c,v 1.194 2004/02/26 22:23:54 weiden Exp $
  *
  * COPYRIGHT:        See COPYING in the top level directory
  * PROJECT:          ReactOS kernel
@@ -289,11 +289,25 @@
   HWND *ChildHandle;
   PWINDOW_OBJECT Child;
   PMENU_OBJECT Menu;
+  BOOL BelongsToThreadData;
   
-  if (! IntWndBelongsToThread(Window, ThreadData))
-    {
-      return 0;
-    }
+  ASSERT(Window);
+  
+  IntLockThreadWindows(Window->OwnerThread->Win32Thread);
+  if(Window->Status & WINDOWSTATUS_DESTROYING)
+  {
+    IntUnLockThreadWindows(Window->OwnerThread->Win32Thread);
+    DPRINT("Tried to call IntDestroyWindow() twice\n");
+    return 0;
+  }
+  Window->Status |= WINDOWSTATUS_DESTROYING;
+  /* remove the window already at this point from the thread window list so we
+     don't get into trouble when destroying the thread windows while we're still
+     in IntDestroyWindow() */
+  RemoveEntryList(&Window->ThreadListEntry);
+  IntUnLockThreadWindows(Window->OwnerThread->Win32Thread);
+  
+  BelongsToThreadData = IntWndBelongsToThread(Window, ThreadData);
   
   if(SendMessages)
   {
@@ -309,15 +323,13 @@
         {
           if ((Child = IntGetWindowObject(*ChildHandle)))
             {
-              if(IntWndBelongsToThread(Child, ThreadData))
-              {
-                IntDestroyWindow(Child, ProcessData, ThreadData, SendMessages);
-              }
-              else
+              if(!IntWndBelongsToThread(Child, ThreadData))
               {
+                /* send WM_DESTROY messages to windows not belonging to the same thread */
                 IntSendDestroyMsg(Child->Self);
-                IntDestroyWindow(Child, ProcessData, Child->OwnerThread->Win32Thread, FALSE);
               }
+              else
+                IntDestroyWindow(Child, ProcessData, ThreadData, SendMessages);
               IntReleaseWindowObject(Child);
             }
         }
@@ -329,7 +341,7 @@
       /*
        * Clear the update region to make sure no WM_PAINT messages will be
        * generated for this window while processing the WM_NCDESTROY.
-       */
+       */ 
       IntRedrawWindow(Window, NULL, 0,
                       RDW_VALIDATE | RDW_NOFRAME | RDW_NOERASE |
                       RDW_NOINTERNALPAINT | RDW_NOCHILDREN);
@@ -337,7 +349,8 @@
       /*
        * Send the WM_NCDESTROY to the window being destroyed.
        */
-      IntSendMessage(Window->Self, WM_NCDESTROY, 0, 0);
+      if(BelongsToThreadData)
+        IntSendMessage(Window->Self, WM_NCDESTROY, 0, 0);
     }
 
   /* reset shell window handles */
@@ -349,7 +362,7 @@
     if (Window->Self == ProcessData->WindowStation->ShellListView)
       ProcessData->WindowStation->ShellListView = NULL;
   }
-
+  
   /* Unregister hot keys */
   UnregisterWindowHotKeys (Window);
 
@@ -389,17 +402,22 @@
 #endif
   
   IntUnlinkWindow(Window);
-
-  IntLockThreadWindows(ThreadData);
-  RemoveEntryList(&Window->ThreadListEntry);
-  IntUnLockThreadWindows(ThreadData);
+  
+  IntReferenceWindowObject(Window);
+  ObmCloseHandle(ProcessData->WindowStation->HandleTable, Window->Self);
   
   IntDestroyScrollBar(Window, SB_VERT);
   IntDestroyScrollBar(Window, SB_HORZ);
   
+  IntLockThreadWindows(Window->OwnerThread->Win32Thread);
+  Window->Status |= WINDOWSTATUS_DESTROYED;
+  /* don't remove the WINDOWSTATUS_DESTROYING bit */
+  IntUnLockThreadWindows(Window->OwnerThread->Win32Thread);
+  
   ObmDereferenceObject(Window->Class);
   Window->Class = NULL;
-  ObmCloseHandle(ProcessData->WindowStation->HandleTable, Window->Self);
+  
+  IntReleaseWindowObject(Window);
 
   return 0;
 }
@@ -475,30 +493,57 @@
 VOID FASTCALL
 DestroyThreadWindows(struct _ETHREAD *Thread)
 {
-  PLIST_ENTRY LastHead;
+  PLIST_ENTRY Current;
   PW32PROCESS Win32Process;
   PW32THREAD Win32Thread;
   PWINDOW_OBJECT Window;
+  HWND *List, *phWnd;
+  ULONG Cnt = 0;
 
   Win32Thread = Thread->Win32Thread;
   Win32Process = Thread->ThreadsProcess->Win32Process;
+  
   IntLockThreadWindows(Win32Thread);
-  LastHead = NULL;
-  while (Win32Thread->WindowListHead.Flink != &(Win32Thread->WindowListHead) &&
-         Win32Thread->WindowListHead.Flink != LastHead)
+  Current = Win32Thread->WindowListHead.Flink;
+  while (Current != &(Win32Thread->WindowListHead))
+  {
+    Cnt++;
+    Current = Current->Flink;
+  }
+  
+  if(Cnt > 0)
+  {
+    List = ExAllocatePool(PagedPool, (Cnt + 1) * sizeof(HANDLE));
+    if(!List)
     {
-      LastHead = Win32Thread->WindowListHead.Flink;
-      Window = CONTAINING_RECORD(Win32Thread->WindowListHead.Flink, WINDOW_OBJECT, ThreadListEntry);
+      DPRINT("Not enough memory to allocate window handle list\n");
       IntUnLockThreadWindows(Win32Thread);
-      WinPosShowWindow(Window->Self, SW_HIDE);
-      IntDestroyWindow(Window, Win32Process, Win32Thread, FALSE);
-      IntLockThreadWindows(Win32Thread);
+      return;
     }
-  if (Win32Thread->WindowListHead.Flink == LastHead)
+    phWnd = List;
+    Current = Win32Thread->WindowListHead.Flink;
+    while (Current != &(Win32Thread->WindowListHead))
+    {
+      Window = CONTAINING_RECORD(Current, WINDOW_OBJECT, ThreadListEntry);
+      *phWnd = Window->Self;
+      phWnd++;
+      Current = Current->Flink;
+    }
+    IntUnLockThreadWindows(Win32Thread);
+    *phWnd = NULL;
+    
+    for(phWnd = List; *phWnd; phWnd++)
     {
-      /* Window at head of list was not removed, should never happen, infinite loop */
-      KEBUGCHECK(0);
+      if((Window = IntGetWindowObject(*phWnd)))
+      {
+        IntDestroyWindow(Window, Win32Process, Win32Thread, FALSE);
+        IntReleaseWindowObject(Window);
+      }
     }
+    ExFreePool(List);
+    return;
+  }
+  
   IntUnLockThreadWindows(Win32Thread);
 }
 
@@ -655,11 +700,23 @@
 BOOL FASTCALL
 IntIsChildWindow(HWND Parent, HWND Child)
 {
-  PWINDOW_OBJECT BaseWindow = IntGetWindowObject(Child);
-  PWINDOW_OBJECT Window = BaseWindow;
+  PWINDOW_OBJECT Window;
+  PWINDOW_OBJECT BaseWindow;
   
-  while (Window != NULL && Window->Style & WS_CHILD)
+  if(!(BaseWindow = IntGetWindowObject(Child)))
   {
+    return FALSE;
+  }
+  
+  Window = BaseWindow;
+  while (Window)
+  {
+    if(!(Window->Style & WS_CHILD))
+    {
+      if(Window != BaseWindow)
+        IntReleaseWindowObject(Window);
+      break;
+    }
     if (Window->Self == Parent)
     {
       if(Window != BaseWindow)
@@ -1512,8 +1569,15 @@
       /* link the window into the parent's child list */
       if ((dwStyle & (WS_CHILD|WS_MAXIMIZE)) == WS_CHILD)
         {
+          PWINDOW_OBJECT PrevSibling;
+          IntLockRelatives(ParentWindow);
+          if((PrevSibling = ParentWindow->LastChild))
+            IntReferenceWindowObject(PrevSibling);
+          IntUnLockRelatives(ParentWindow);
           /* link window as bottom sibling */
-          IntLinkWindow(WindowObject, ParentWindow, ParentWindow->LastChild /*prev sibling*/);
+          IntLinkWindow(WindowObject, ParentWindow, PrevSibling /*prev sibling*/);
+          if(PrevSibling)
+            IntReleaseWindowObject(PrevSibling);
         }
       else
         {
@@ -1711,7 +1775,7 @@
     {
     return TRUE;
     }
-
+  
   /* Recursively destroy owned windows */
   if (! isChild)
     {
@@ -1734,11 +1798,19 @@
 		    {
 		      continue;
 		    }
+		  if(Child->Self == Wnd)
+		  {
+		    IntReleaseWindowObject(Child);
+		    continue;
+		  }
+		  IntLockRelatives(Child);
 		  if (Child->Parent != Window->Self)
 		    {
+		      IntUnLockRelatives(Child);
 		      IntReleaseWindowObject(Child);
 		      continue;
 		    }
+		  IntUnLockRelatives(Child);
 		  if (IntWndBelongsToThread(Child, PsGetWin32Thread()))
 		    {
 		      IntReleaseWindowObject(Child);
@@ -1746,10 +1818,12 @@
 		      GotOne = TRUE;		      
 		      continue;
 		    }
+		  IntLockRelatives(Child);
 		  if (Child->Owner != NULL)
 		    {
 		      Child->Owner = NULL;
 		    }
+		  IntUnLockRelatives(Child);
 		  IntReleaseWindowObject(Child);
 		}
 	      ExFreePool(Children);
@@ -1760,7 +1834,7 @@
 	    }
 	}
     }
-
+  
   if (!IntIsWindow(Wnd))
     {
       return TRUE;

reactos/subsys/win32k/ntuser
winpos.c 1.100 -> 1.101
diff -u -r1.100 -r1.101
--- winpos.c	24 Feb 2004 15:56:53 -0000	1.100
+++ winpos.c	26 Feb 2004 22:23:55 -0000	1.101
@@ -16,7 +16,7 @@
  *  along with this program; if not, write to the Free Software
  *  Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
  */
-/* $Id: winpos.c,v 1.100 2004/02/24 15:56:53 weiden Exp $
+/* $Id: winpos.c,v 1.101 2004/02/26 22:23:55 weiden Exp $
  *
  * COPYRIGHT:        See COPYING in the top level directory
  * PROJECT:          ReactOS kernel
@@ -82,7 +82,7 @@
 {
   PWINDOW_OBJECT WindowObject;
   
-  WindowObject = IntGetWindowObject(hWnd);
+  WindowObject = IntGetWindowObject((hWnd ? hWnd : IntGetDesktopWindow()));
   if (WindowObject == NULL)
     {
       Point->x = Point->y = 0;
@@ -102,8 +102,20 @@
   POINT pt;
   NTSTATUS Status;
   
+  if(!Point)
+  {
+    SetLastWin32Error(ERROR_INVALID_PARAMETER);
+    return FALSE;
+  }
+  
   Ret = IntGetClientOrigin(hWnd, &pt);
   
+  if(!Ret)
+  {
+    SetLastWin32Error(ERROR_INVALID_WINDOW_HANDLE);
+    return FALSE;
+  }
+  
   Status = MmCopyToCaller(Point, &pt, sizeof(POINT));
   if(!NT_SUCCESS(Status))
   {
@@ -122,45 +134,48 @@
 VOID FASTCALL
 WinPosActivateOtherWindow(PWINDOW_OBJECT Window)
 {
-  PWINDOW_OBJECT Child, Wnd = Window;
-  HWND *List, *phWnd;
-
+  PWINDOW_OBJECT Wnd, Old;
+  
   if (!Window || IntIsDesktopWindow(Window))
   {
     IntSetFocusMessageQueue(NULL);
     return;
   }
-
+  Wnd = Window;
   for(;;)
   {
+    HWND *List, *phWnd;
+    
+    Old = Wnd;
     Wnd = IntGetParentObject(Wnd);
-    if(!Wnd)
+    if(Old != Window)
     {
-      IntSetFocusMessageQueue(NULL);
-      return;
+      IntReleaseWindowObject(Old);
     }
-    if(IntIsDesktopWindow(Wnd))
+    if(!Wnd)
     {
-      IntReleaseWindowObject(Wnd);
       IntSetFocusMessageQueue(NULL);
       return;
     }
-    if((List = IntWinListChildren(Window)))
+    
+    if((List = IntWinListChildren(Wnd)))
     {
-      for(phWnd = List; *phWnd; ++phWnd)
+      for(phWnd = List; *phWnd; phWnd++)
       {
-        if(*phWnd == Window->Self)
+        PWINDOW_OBJECT Child;
+        
+        if((*phWnd) == Window->Self)
         {
           continue;
         }
         
-        Child = IntGetWindowObject(*phWnd);
-        if(Child)
+        if((Child = IntGetWindowObject(*phWnd)))
         {
           if(IntSetForegroundWindow(Child))
           {
-            IntReleaseWindowObject(Child);
             ExFreePool(List);
+            IntReleaseWindowObject(Wnd);
+            IntReleaseWindowObject(Child);
             return;
           }
           IntReleaseWindowObject(Child);
@@ -169,6 +184,7 @@
       ExFreePool(List);
     }
   }
+  IntReleaseWindowObject(Wnd);
 }
 
 VOID STATIC FASTCALL
@@ -1276,8 +1292,8 @@
   return(WasVisible);
 }
 
-BOOL STATIC FASTCALL
-WinPosSearchChildren(PWINDOW_OBJECT ScopeWin, BOOL SendProcHitTests, POINT *Point,
+VOID STATIC FASTCALL
+WinPosSearchChildren(PWINDOW_OBJECT ScopeWin, BOOL SendHitTestMessage, POINT *Point,
 		     PWINDOW_OBJECT* Window, USHORT *HitTest)
 {
   PWINDOW_OBJECT Current;
@@ -1293,29 +1309,27 @@
       }
       
       if (Current->Style & WS_VISIBLE &&
-	      ((!(Current->Style & WS_DISABLED)) ||
-	       (Current->Style & (WS_CHILD | WS_POPUP)) != WS_CHILD) &&
-	      (Point->x >= Current->WindowRect.left &&
+	  (!(Current->Style & WS_DISABLED) || (Current->Style & (WS_CHILD | WS_POPUP)) != WS_CHILD) &&
+	  (Point->x >= Current->WindowRect.left &&
            Point->x < Current->WindowRect.right &&
            Point->y >= Current->WindowRect.top &&
            Point->y < Current->WindowRect.bottom))
            /* FIXME - check if Point is in window region */
 	  {
-	    if(*Window)
-	    {
-	      IntReleaseWindowObject(*Window);
-	    }
-	    *Window = Current;
+	if(*Window)
+	{
+	  IntReleaseWindowObject(*Window);
+	}
+	*Window = Current;
 	    
         if(Current->Style & WS_DISABLED)
         {
           *HitTest = HTERROR;
-	      ExFreePool(List);
-          return TRUE;
+	  ExFreePool(List);
+          return;
         }
         
-        if((SendProcHitTests && 
-            (Current->OwnerThread->ThreadsProcess == PsGetCurrentProcess())) ||
+        if(SendHitTestMessage &&
            (Current->MessageQueue == PsGetWin32Thread()->MessageQueue))
         {
           *HitTest = IntSendMessage(Current->Self, WM_NCHITTEST, 0,
@@ -1335,31 +1349,22 @@
            Point->y >= Current->ClientRect.top &&
            Point->y < Current->ClientRect.bottom)
         {
-          USHORT ChildHitTest;
-          if(WinPosSearchChildren(Current, SendProcHitTests, Point, Window, &ChildHitTest))
-          {
-            *HitTest = ChildHitTest;
-            ExFreePool(List);
-            return TRUE;
-          }
+          WinPosSearchChildren(Current, SendHitTestMessage, Point, Window, HitTest);
+          ExFreePool(List);
+          return;
         }
         
         ExFreePool(List);
-        return TRUE;
+        return;
       }
       IntReleaseWindowObject(Current);
     }
     ExFreePool(List);
   }
-  
-  if((*Window) == NULL)
-    HitTest = HTNOWHERE;
-  
-  return FALSE;
 }
 
 USHORT FASTCALL
-WinPosWindowFromPoint(PWINDOW_OBJECT ScopeWin, BOOL SendProcHitTests, POINT *WinPoint, 
+WinPosWindowFromPoint(PWINDOW_OBJECT ScopeWin, BOOL SendHitTestMessage, POINT *WinPoint, 
 		      PWINDOW_OBJECT* Window)
 {
   HWND DesktopWindowHandle;
@@ -1382,19 +1387,19 @@
 
   /* Translate the point to the space of the scope window. */
   DesktopWindowHandle = IntGetDesktopWindow();
-  if((DesktopWindow = IntGetWindowObject(DesktopWindowHandle)))
+  if((DesktopWindowHandle != ScopeWin->Self) &&
+     (DesktopWindow = IntGetWindowObject(DesktopWindowHandle)))
   {
     Point.x += ScopeWin->ClientRect.left - DesktopWindow->ClientRect.left;
     Point.y += ScopeWin->ClientRect.top - DesktopWindow->ClientRect.top;
     IntReleaseWindowObject(DesktopWindow);
   }
   
-  if(WinPosSearchChildren(ScopeWin, SendProcHitTests, &Point, Window, &HitTest))
-  {
-    return HitTest;
-  }
+  HitTest = HTNOWHERE;
+  
+  WinPosSearchChildren(ScopeWin, SendHitTestMessage, &Point, Window, &HitTest);
 
-  return HTNOWHERE;
+  return ((*Window) ? HitTest : HTNOWHERE);
 }
 
 BOOL

reactos/subsys/win32k/objects
cursoricon.c 1.48 -> 1.49
diff -u -r1.48 -r1.49
--- cursoricon.c	24 Feb 2004 13:27:03 -0000	1.48
+++ cursoricon.c	26 Feb 2004 22:23:55 -0000	1.49
@@ -16,7 +16,7 @@
  *  along with this program; if not, write to the Free Software
  *  Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
  */
-/* $Id: cursoricon.c,v 1.48 2004/02/24 13:27:03 weiden Exp $ */
+/* $Id: cursoricon.c,v 1.49 2004/02/26 22:23:55 weiden Exp $ */
 
 #undef WIN32_LEAN_AND_MEAN
 
@@ -61,12 +61,6 @@
   return Object;
 }
 
-VOID FASTCALL
-IntReleaseCurIconObject(PCURICON_OBJECT Object)
-{
-  ObmDereferenceObject(Object);
-}
-
 HBITMAP FASTCALL
 IntCopyBitmap(HBITMAP bmp)
 {
CVSspam 0.2.8