[Win32k]
[reactos.git] / reactos / subsystems / win32 / win32k / ntuser / focus.c
index dd2fd4d..9989e88 100644 (file)
@@ -18,7 +18,7 @@
  *
  */
 
-#include <w32k.h>
+#include <win32k.h>
 
 #define NDEBUG
 #include <debug.h>
@@ -51,12 +51,14 @@ IntGetThreadFocusWindow(VOID)
 VOID FASTCALL
 co_IntSendDeactivateMessages(HWND hWndPrev, HWND hWnd)
 {
-   if (hWndPrev)
+    PWND WndPrev ;
+
+   if (hWndPrev && (WndPrev = UserGetWindowObject(hWndPrev)))
    {
-      co_IntPostOrSendMessage(hWndPrev, WM_NCACTIVATE, FALSE, 0);
-      co_IntPostOrSendMessage(hWndPrev, WM_ACTIVATE,
-                              MAKEWPARAM(WA_INACTIVE, UserGetWindowLong(hWndPrev, GWL_STYLE, FALSE) & WS_MINIMIZE),
-                              (LPARAM)hWnd);
+      co_IntSendMessageNoWait(hWndPrev, WM_NCACTIVATE, FALSE, 0);
+      co_IntSendMessageNoWait(hWndPrev, WM_ACTIVATE,
+                 MAKEWPARAM(WA_INACTIVE, WndPrev->style & WS_MINIMIZE),
+                 (LPARAM)hWnd);
    }
 }
 
@@ -64,7 +66,7 @@ VOID FASTCALL
 co_IntSendActivateMessages(HWND hWndPrev, HWND hWnd, BOOL MouseActivate)
 {
    USER_REFERENCE_ENTRY Ref, RefPrev;
-   PWINDOW_OBJECT Window, WindowPrev = NULL;
+   PWND Window, WindowPrev = NULL;
 
    if ((Window = UserGetWindowObject(hWnd)))
    { 
@@ -77,38 +79,44 @@ co_IntSendActivateMessages(HWND hWndPrev, HWND hWnd, BOOL MouseActivate)
       /* Send palette messages */
       if (co_IntPostOrSendMessage(hWnd, WM_QUERYNEWPALETTE, 0, 0))
       {
-         co_IntPostOrSendMessage(HWND_BROADCAST, WM_PALETTEISCHANGING,
-                                 (WPARAM)hWnd, 0);
+         UserSendNotifyMessage( HWND_BROADCAST,
+                                WM_PALETTEISCHANGING,
+                               (WPARAM)hWnd,
+                                0);
       }
 
-      if (UserGetWindow(hWnd, GW_HWNDPREV) != NULL)
+      if (Window->spwndPrev != NULL)
          co_WinPosSetWindowPos(Window, HWND_TOP, 0, 0, 0, 0,
                                SWP_NOSIZE | SWP_NOMOVE | SWP_NOACTIVATE | SWP_NOSENDCHANGING);
 
-      if (!IntGetOwner(Window) && !IntGetParent(Window))
+      if (!Window->spwndOwner && !IntGetParent(Window))
       {
          co_IntShellHookNotify(HSHELL_WINDOWACTIVATED, (LPARAM) hWnd);
       }
 
-      if (Window->Wnd)
+      if (Window)
       {  // Set last active for window and it's owner.
-         Window->Wnd->hWndLastActive = hWnd;
-         if (Window->Wnd->spwndOwner)
-            Window->Wnd->spwndOwner->hWndLastActive = hWnd;
-         Window->Wnd->state |= WNDS_ACTIVEFRAME;
+         Window->hWndLastActive = hWnd;
+         if (Window->spwndOwner)
+            Window->spwndOwner->hWndLastActive = hWnd;
+         Window->state |= WNDS_ACTIVEFRAME;
       }
 
-      if (WindowPrev && WindowPrev->Wnd)
-         WindowPrev->Wnd->state &= ~WNDS_ACTIVEFRAME;
+      if (WindowPrev)
+         WindowPrev->state &= ~WNDS_ACTIVEFRAME;
 
       if (Window && WindowPrev)
       {
-         PWINDOW_OBJECT cWindow;
+         PWND cWindow;
          HWND *List, *phWnd;
          HANDLE OldTID = IntGetWndThreadId(WindowPrev);
          HANDLE NewTID = IntGetWndThreadId(Window);
 
- DPRINT("SendActiveMessage Old -> %x, New -> %x\n", OldTID, NewTID);
+         DPRINT("SendActiveMessage Old -> %x, New -> %x\n", OldTID, NewTID);
+         if (Window->style & WS_MINIMIZE)
+         {
+            DPRINT("Widow was minimized\n");
+         }
 
          if (OldTID != NewTID)
          {
@@ -118,10 +126,11 @@ co_IntSendActivateMessages(HWND hWndPrev, HWND hWnd, BOOL MouseActivate)
                for (phWnd = List; *phWnd; ++phWnd)
                {
                   cWindow = UserGetWindowObject(*phWnd);
+
                   if (cWindow && (IntGetWndThreadId(cWindow) == OldTID))
                   {  // FALSE if the window is being deactivated,
                      // ThreadId that owns the window being activated.
-                    co_IntPostOrSendMessage(*phWnd, WM_ACTIVATEAPP, FALSE, (LPARAM)NewTID);
+                    co_IntSendMessageNoWait(*phWnd, WM_ACTIVATEAPP, FALSE, (LPARAM)NewTID);
                   }
                }
                for (phWnd = List; *phWnd; ++phWnd)
@@ -130,7 +139,7 @@ co_IntSendActivateMessages(HWND hWndPrev, HWND hWnd, BOOL MouseActivate)
                   if (cWindow && (IntGetWndThreadId(cWindow) == NewTID))
                   { // TRUE if the window is being activated,
                     // ThreadId that owns the window being deactivated.
-                    co_IntPostOrSendMessage(*phWnd, WM_ACTIVATEAPP, TRUE, (LPARAM)OldTID);
+                    co_IntSendMessageNoWait(*phWnd, WM_ACTIVATEAPP, TRUE, (LPARAM)OldTID);
                   }
                }
                ExFreePool(List);
@@ -142,12 +151,11 @@ co_IntSendActivateMessages(HWND hWndPrev, HWND hWnd, BOOL MouseActivate)
       UserDerefObjectCo(Window);
 
       /* FIXME: IntIsWindow */
-
-      co_IntPostOrSendMessage(hWnd, WM_NCACTIVATE, (WPARAM)(hWnd == UserGetForegroundWindow()), 0);
+      co_IntSendMessageNoWait(hWnd, WM_NCACTIVATE, (WPARAM)(hWnd == UserGetForegroundWindow()), 0);
       /* FIXME: WA_CLICKACTIVE */
-      co_IntPostOrSendMessage(hWnd, WM_ACTIVATE,
+      co_IntSendMessageNoWait(hWnd, WM_ACTIVATE,
                               MAKEWPARAM(MouseActivate ? WA_CLICKACTIVE : WA_ACTIVE,
-                                         UserGetWindowLong(hWnd, GWL_STYLE, FALSE) & WS_MINIMIZE),
+                              Window->style & WS_MINIMIZE),
                               (LPARAM)hWndPrev);
    }
 }
@@ -157,6 +165,7 @@ co_IntSendKillFocusMessages(HWND hWndPrev, HWND hWnd)
 {
    if (hWndPrev)
    {
+      IntNotifyWinEvent(EVENT_OBJECT_FOCUS, NULL, OBJID_CLIENT, CHILDID_SELF, 0);
       co_IntPostOrSendMessage(hWndPrev, WM_KILLFOCUS, (WPARAM)hWnd, 0);
    }
 }
@@ -166,25 +175,27 @@ co_IntSendSetFocusMessages(HWND hWndPrev, HWND hWnd)
 {
    if (hWnd)
    {
+      PWND pWnd = UserGetWindowObject(hWnd);
+      IntNotifyWinEvent(EVENT_OBJECT_FOCUS, pWnd, OBJID_CLIENT, CHILDID_SELF, 0);
       co_IntPostOrSendMessage(hWnd, WM_SETFOCUS, (WPARAM)hWndPrev, 0);
    }
 }
 
 HWND FASTCALL
-IntFindChildWindowToOwner(PWINDOW_OBJECT Root, PWINDOW_OBJECT Owner)
+IntFindChildWindowToOwner(PWND Root, PWND Owner)
 {
    HWND Ret;
-   PWINDOW_OBJECT Child, OwnerWnd;
+   PWND Child, OwnerWnd;
 
-   for(Child = Root->FirstChild; Child; Child = Child->NextSibling)
+   for(Child = Root->spwndChild; Child; Child = Child->spwndNext)
    {
-      OwnerWnd = UserGetWindowObject(Child->hOwner);
+       OwnerWnd = Child->spwndOwner;
       if(!OwnerWnd)
          continue;
 
       if(OwnerWnd == Owner)
       {
-         Ret = Child->hSelf;
+         Ret = Child->head.h;
          return Ret;
       }
    }
@@ -193,21 +204,18 @@ IntFindChildWindowToOwner(PWINDOW_OBJECT Root, PWINDOW_OBJECT Owner)
 }
 
 static BOOL FASTCALL
-co_IntSetForegroundAndFocusWindow(PWINDOW_OBJECT Window, PWINDOW_OBJECT FocusWindow, BOOL MouseActivate)
+co_IntSetForegroundAndFocusWindow(PWND Wnd, PWND FocusWindow, BOOL MouseActivate)
 {
-   HWND hWnd = Window->hSelf;
+   HWND hWnd = Wnd->head.h;
    HWND hWndPrev = NULL;
-   HWND hWndFocus = FocusWindow->hSelf;
+   HWND hWndFocus = FocusWindow->head.h;
    HWND hWndFocusPrev = NULL;
    PUSER_MESSAGE_QUEUE PrevForegroundQueue;
-   PWND Wnd;
 
-   ASSERT_REFS_CO(Window);
+   ASSERT_REFS_CO(Wnd);
 
    DPRINT("IntSetForegroundAndFocusWindow(%x, %x, %s)\n", hWnd, hWndFocus, MouseActivate ? "TRUE" : "FALSE");
 
-   Wnd = Window->Wnd;
-
    if ((Wnd->style & (WS_CHILD | WS_POPUP)) == WS_CHILD)
    {
       DPRINT("Failed - Child\n");
@@ -215,7 +223,7 @@ co_IntSetForegroundAndFocusWindow(PWINDOW_OBJECT Window, PWINDOW_OBJECT FocusWin
    }
 
    if (0 == (Wnd->style & WS_VISIBLE) &&
-       Window->OwnerThread->ThreadsProcess != CsrProcess)
+       Wnd->head.pti->pEThread->ThreadsProcess != CsrProcess)
    {
       DPRINT("Failed - Invisible\n");
       return FALSE;
@@ -225,6 +233,7 @@ co_IntSetForegroundAndFocusWindow(PWINDOW_OBJECT Window, PWINDOW_OBJECT FocusWin
    if (PrevForegroundQueue != 0)
    {
       hWndPrev = PrevForegroundQueue->ActiveWindow;
+      hWndFocusPrev = PrevForegroundQueue->FocusWindow;
    }
 
    if (hWndPrev == hWnd)
@@ -233,26 +242,25 @@ co_IntSetForegroundAndFocusWindow(PWINDOW_OBJECT Window, PWINDOW_OBJECT FocusWin
       return TRUE;
    }
 
-   hWndFocusPrev = (PrevForegroundQueue == FocusWindow->MessageQueue
-                    ? FocusWindow->MessageQueue->FocusWindow : NULL);
-
    /* FIXME: Call hooks. */
 
    co_IntSendDeactivateMessages(hWndPrev, hWnd);
    co_IntSendKillFocusMessages(hWndFocusPrev, hWndFocus);
 
-   IntSetFocusMessageQueue(Window->MessageQueue);
-   if (Window->MessageQueue)
+
+   IntSetFocusMessageQueue(Wnd->head.pti->MessageQueue);
+
+   if (Wnd->head.pti->MessageQueue)
    {
-      Window->MessageQueue->ActiveWindow = hWnd;
+      Wnd->head.pti->MessageQueue->ActiveWindow = hWnd;
    }
 
-   if (FocusWindow->MessageQueue)
+   if (FocusWindow->head.pti->MessageQueue)
    {
-      FocusWindow->MessageQueue->FocusWindow = hWndFocus;
+      FocusWindow->head.pti->MessageQueue->FocusWindow = hWndFocus;
    }
 
-   if (PrevForegroundQueue != Window->MessageQueue)
+   if (PrevForegroundQueue != Wnd->head.pti->MessageQueue)
    {
       /* FIXME: Send WM_ACTIVATEAPP to all thread windows. */
    }
@@ -264,7 +272,7 @@ co_IntSetForegroundAndFocusWindow(PWINDOW_OBJECT Window, PWINDOW_OBJECT FocusWin
 }
 
 BOOL FASTCALL
-co_IntSetForegroundWindow(PWINDOW_OBJECT Window)//FIXME: can Window be NULL??
+co_IntSetForegroundWindow(PWND Window)//FIXME: can Window be NULL??
 {
    /*if (Window)*/ ASSERT_REFS_CO(Window);
 
@@ -272,24 +280,22 @@ co_IntSetForegroundWindow(PWINDOW_OBJECT Window)//FIXME: can Window be NULL??
 }
 
 BOOL FASTCALL
-co_IntMouseActivateWindow(PWINDOW_OBJECT Window)
+co_IntMouseActivateWindow(PWND Wnd)
 {
    HWND Top;
-   PWINDOW_OBJECT TopWindow;
+   PWND TopWindow;
    USER_REFERENCE_ENTRY Ref;
-   PWND Wnd;
 
-   ASSERT_REFS_CO(Window);
+   ASSERT_REFS_CO(Wnd);
 
-   Wnd = Window->Wnd;
    if(Wnd->style & WS_DISABLED)
    {
       BOOL Ret;
-      PWINDOW_OBJECT TopWnd;
-      PWINDOW_OBJECT DesktopWindow = UserGetWindowObject(IntGetDesktopWindow());
+      PWND TopWnd;
+      PWND DesktopWindow = UserGetWindowObject(IntGetDesktopWindow());
       if(DesktopWindow)
       {
-         Top = IntFindChildWindowToOwner(DesktopWindow, Window);
+         Top = IntFindChildWindowToOwner(DesktopWindow, Wnd);
          if((TopWnd = UserGetWindowObject(Top)))
          {
             UserRefObjectCo(TopWnd, &Ref);
@@ -303,13 +309,13 @@ co_IntMouseActivateWindow(PWINDOW_OBJECT Window)
    }
 
 
-   TopWindow = UserGetAncestor(Window, GA_ROOT);
+   TopWindow = UserGetAncestor(Wnd, GA_ROOT);
    if (!TopWindow) return FALSE;
 
    /* TMN: Check return valud from this function? */
    UserRefObjectCo(TopWindow, &Ref);
 
-   co_IntSetForegroundAndFocusWindow(TopWindow, Window, TRUE);
+   co_IntSetForegroundAndFocusWindow(TopWindow, Wnd, TRUE);
 
    UserDerefObjectCo(TopWindow);
 
@@ -317,32 +323,30 @@ co_IntMouseActivateWindow(PWINDOW_OBJECT Window)
 }
 
 HWND FASTCALL
-co_IntSetActiveWindow(PWINDOW_OBJECT Window OPTIONAL)
+co_IntSetActiveWindow(PWND Wnd OPTIONAL)
 {
    PTHREADINFO pti;
    PUSER_MESSAGE_QUEUE ThreadQueue;
    HWND hWndPrev;
    HWND hWnd = 0;
-   PWND Wnd;
    CBTACTIVATESTRUCT cbt;
 
-   if (Window)
-      ASSERT_REFS_CO(Window);
+   if (Wnd)
+      ASSERT_REFS_CO(Wnd);
 
    pti = PsGetCurrentThreadWin32Thread();
    ThreadQueue = pti->MessageQueue;
    ASSERT(ThreadQueue != 0);
 
-   if (Window != 0)
+   if (Wnd != 0)
    {
-      Wnd = Window->Wnd;
       if ((!(Wnd->style & WS_VISIBLE) &&
-           Window->OwnerThread->ThreadsProcess != CsrProcess) ||
+           Wnd->head.pti->pEThread->ThreadsProcess != CsrProcess) ||
           (Wnd->style & (WS_POPUP | WS_CHILD)) == WS_CHILD)
       {
          return ThreadQueue ? 0 : ThreadQueue->ActiveWindow;
       }
-      hWnd = Window->hSelf;
+      hWnd = Wnd->head.h;
    }
 
    hWndPrev = ThreadQueue->ActiveWindow;
@@ -355,8 +359,10 @@ co_IntSetActiveWindow(PWINDOW_OBJECT Window OPTIONAL)
    cbt.fMouse     = FALSE;
    cbt.hWndActive = hWndPrev;
    if (co_HOOK_CallHooks( WH_CBT, HCBT_ACTIVATE, (WPARAM)hWnd, (LPARAM)&cbt))
+   {
+      DPRINT1("SetActiveWindow WH_CBT Call Hook return!\n");
       return 0;
-
+   }
    ThreadQueue->ActiveWindow = hWnd;
 
    co_IntSendDeactivateMessages(hWndPrev, hWnd);
@@ -369,7 +375,7 @@ co_IntSetActiveWindow(PWINDOW_OBJECT Window OPTIONAL)
 
 static
 HWND FASTCALL
-co_IntSetFocusWindow(PWINDOW_OBJECT Window OPTIONAL)
+co_IntSetFocusWindow(PWND Window OPTIONAL)
 {
    HWND hWndPrev = 0;
    PTHREADINFO pti;
@@ -386,25 +392,29 @@ co_IntSetFocusWindow(PWINDOW_OBJECT Window OPTIONAL)
 
    if (Window != 0)
    {
-      if (hWndPrev == Window->hSelf)
+      if (hWndPrev == Window->head.h)
       {
          return hWndPrev;
       }
 
-     if (co_HOOK_CallHooks( WH_CBT, HCBT_SETFOCUS, (WPARAM)Window->hSelf, (LPARAM)hWndPrev))
-        return 0;
-
-      ThreadQueue->FocusWindow = Window->hSelf;
+      if (co_HOOK_CallHooks( WH_CBT, HCBT_SETFOCUS, (WPARAM)Window->head.h, (LPARAM)hWndPrev))
+      {
+         DPRINT1("SetFocusWindow 1 WH_CBT Call Hook return!\n");
+         return 0;
+      }
+      ThreadQueue->FocusWindow = Window->head.h;
 
-      co_IntSendKillFocusMessages(hWndPrev, Window->hSelf);
-      co_IntSendSetFocusMessages(hWndPrev, Window->hSelf);
+      co_IntSendKillFocusMessages(hWndPrev, Window->head.h);
+      co_IntSendSetFocusMessages(hWndPrev, Window->head.h);
    }
    else
    {
       ThreadQueue->FocusWindow = 0;
-
-     if (co_HOOK_CallHooks( WH_CBT, HCBT_SETFOCUS, (WPARAM)0, (LPARAM)hWndPrev))
-        return 0;
+      if (co_HOOK_CallHooks( WH_CBT, HCBT_SETFOCUS, (WPARAM)0, (LPARAM)hWndPrev))
+      {
+         DPRINT1("SetFocusWindow 2 WH_CBT Call Hook return!\n");
+         return 0;
+      }
 
       co_IntSendKillFocusMessages(hWndPrev, 0);
    }
@@ -467,7 +477,7 @@ NtUserSetActiveWindow(HWND hWnd)
 
    if (hWnd)
    {
-      PWINDOW_OBJECT Window;
+      PWND Window;
       PTHREADINFO pti;
       PUSER_MESSAGE_QUEUE ThreadQueue;
       HWND hWndPrev;
@@ -480,9 +490,9 @@ NtUserSetActiveWindow(HWND hWnd)
       pti = PsGetCurrentThreadWin32Thread();
       ThreadQueue = pti->MessageQueue;
 
-      if (Window->MessageQueue != ThreadQueue)
+      if (Window->head.pti->MessageQueue != ThreadQueue)
       {
-         SetLastWin32Error(ERROR_INVALID_WINDOW_HANDLE);
+         EngSetLastError(ERROR_INVALID_WINDOW_HANDLE);
          RETURN( 0);
       }
 
@@ -524,45 +534,63 @@ CLEANUP:
    END_CLEANUP;
 }
 
-/*
- * @implemented
- */
-HWND APIENTRY
-NtUserSetCapture(HWND hWnd)
+
+HWND FASTCALL
+co_UserSetCapture(HWND hWnd)
 {
    PTHREADINFO pti;
    PUSER_MESSAGE_QUEUE ThreadQueue;
-   PWINDOW_OBJECT Window;
+   PWND Window, pWnd;
    HWND hWndPrev;
-   DECLARE_RETURN(HWND);
-
-   DPRINT("Enter NtUserSetCapture(%x)\n", hWnd);
-   UserEnterExclusive();
 
    pti = PsGetCurrentThreadWin32Thread();
    ThreadQueue = pti->MessageQueue;
 
-   if((Window = UserGetWindowObject(hWnd)))
+   if ((Window = UserGetWindowObject(hWnd)))
    {
-      if(Window->MessageQueue != ThreadQueue)
+      if (Window->head.pti->MessageQueue != ThreadQueue)
       {
-         RETURN(NULL);
+         return NULL;
       }
    }
 
    hWndPrev = MsqSetStateWindow(ThreadQueue, MSQ_STATE_CAPTURE, hWnd);
 
+   if (hWndPrev)
+   {
+      pWnd = UserGetWindowObject(hWndPrev);
+      if (pWnd)
+         IntNotifyWinEvent(EVENT_SYSTEM_CAPTUREEND, pWnd, OBJID_WINDOW, CHILDID_SELF, WEF_SETBYWNDPTI);
+   }
+
    /* also remove other windows if not capturing anymore */
-   if(hWnd == NULL)
+   if (hWnd == NULL)
    {
       MsqSetStateWindow(ThreadQueue, MSQ_STATE_MENUOWNER, NULL);
       MsqSetStateWindow(ThreadQueue, MSQ_STATE_MOVESIZE, NULL);
    }
 
+   if (Window)
+      IntNotifyWinEvent(EVENT_SYSTEM_CAPTURESTART, Window, OBJID_WINDOW, CHILDID_SELF, WEF_SETBYWNDPTI);
+
    co_IntPostOrSendMessage(hWndPrev, WM_CAPTURECHANGED, 0, (LPARAM)hWnd);
    ThreadQueue->CaptureWindow = hWnd;
 
-   RETURN( hWndPrev);
+   return hWndPrev;
+}
+
+/*
+ * @implemented
+ */
+HWND APIENTRY
+NtUserSetCapture(HWND hWnd)
+{
+   DECLARE_RETURN(HWND);
+
+   DPRINT("Enter NtUserSetCapture(%x)\n", hWnd);
+   UserEnterExclusive();
+
+   RETURN( co_UserSetCapture(hWnd));
 
 CLEANUP:
    DPRINT("Leave NtUserSetCapture, ret=%i\n",_ret_);
@@ -572,44 +600,42 @@ CLEANUP:
 
 
 
-HWND FASTCALL co_UserSetFocus(PWINDOW_OBJECT Window OPTIONAL)
+HWND FASTCALL co_UserSetFocus(PWND Wnd OPTIONAL)
 {
-   if (Window)
+   if (Wnd)
    {
       PTHREADINFO pti;
       PUSER_MESSAGE_QUEUE ThreadQueue;
       HWND hWndPrev;
-      PWINDOW_OBJECT TopWnd;
+      PWND TopWnd;
       USER_REFERENCE_ENTRY Ref;
-      PWND Wnd;
 
-      ASSERT_REFS_CO(Window);
+      ASSERT_REFS_CO(Wnd);
 
       pti = PsGetCurrentThreadWin32Thread();
       ThreadQueue = pti->MessageQueue;
 
-      Wnd = Window->Wnd;
       if (Wnd->style & (WS_MINIMIZE | WS_DISABLED))
       {
          return( (ThreadQueue ? ThreadQueue->FocusWindow : 0));
       }
 
-      if (Window->MessageQueue != ThreadQueue)
+      if (Wnd->head.pti->MessageQueue != ThreadQueue)
       {
-         SetLastWin32Error(ERROR_INVALID_WINDOW_HANDLE);
+         EngSetLastError(ERROR_INVALID_WINDOW_HANDLE);
          return( 0);
       }
 
-      TopWnd = UserGetAncestor(Window, GA_ROOT);
-      if (TopWnd && TopWnd->hSelf != UserGetActiveWindow())
+      TopWnd = UserGetAncestor(Wnd, GA_ROOT);
+      if (TopWnd && TopWnd->head.h != UserGetActiveWindow())
       {
-//         PWINDOW_OBJECT WndTops = UserGetWindowObject(hWndTop);
+//         PWND WndTops = UserGetWindowObject(hWndTop);
          UserRefObjectCo(TopWnd, &Ref);
          co_IntSetActiveWindow(TopWnd);
          UserDerefObjectCo(TopWnd);
       }
 
-      hWndPrev = co_IntSetFocusWindow(Window);
+      hWndPrev = co_IntSetFocusWindow(Wnd);
 
       return( hWndPrev);
    }
@@ -627,7 +653,7 @@ HWND FASTCALL co_UserSetFocus(PWINDOW_OBJECT Window OPTIONAL)
 HWND APIENTRY
 NtUserSetFocus(HWND hWnd)
 {
-   PWINDOW_OBJECT Window;
+   PWND Window;
    USER_REFERENCE_ENTRY Ref;
    DECLARE_RETURN(HWND);
    HWND ret;