[win32k]
[reactos.git] / reactos / subsystems / win32 / win32k / ntuser / msgqueue.c
index d12b9c0..77d1ef4 100644 (file)
  *  along with this program; if not, write to the Free Software
  *  Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
  */
-/* $Id$
- *
+/*
  * COPYRIGHT:        See COPYING in the top level directory
  * PROJECT:          ReactOS kernel
  * PURPOSE:          Message queues
- * FILE:             subsys/win32k/ntuser/msgqueue.c
+ * FILE:             subsystems/win32/win32k/ntuser/msgqueue.c
  * PROGRAMER:        Casper S. Hornstrup (chorns@users.sourceforge.net)
  * REVISION HISTORY:
  *       06-06-2001  CSH  Created
@@ -72,7 +71,7 @@ IdlePing(VOID)
 {
   HWND hWnd;
   PWINDOW_OBJECT Window;
-  PW32PROCESS W32d = PsGetCurrentProcessWin32Process();
+  PPROCESSINFO W32d = PsGetCurrentProcessWin32Process();
 
   hWnd = UserGetForegroundWindow();
 
@@ -80,7 +79,7 @@ IdlePing(VOID)
 
   if (Window && Window->ti)
   {
-     if (Window->ti->Hooks & HOOKID_TO_FLAG(WH_FOREGROUNDIDLE))
+     if (Window->ti->fsHooks & HOOKID_TO_FLAG(WH_FOREGROUNDIDLE))
      {
         co_HOOK_CallHooks(WH_FOREGROUNDIDLE,HC_ACTION,0,0);
      }
@@ -119,6 +118,7 @@ IntMsqClearWakeMask(VOID)
       return FALSE;
 
    MessageQueue = Win32Thread->MessageQueue;
+// HACK!!!!!!! Newbies that wrote this should hold your head down in shame! (jt)
    MessageQueue->WakeMask = ~0;
 
    return TRUE;
@@ -295,13 +295,13 @@ MsqIsDblClk(LPMSG Msg, BOOL Remove)
    return Res;
 }
 
-BOOL static STDCALL
-co_MsqTranslateMouseMessage(PUSER_MESSAGE_QUEUE MessageQueue, HWND hWnd, UINT FilterLow, UINT FilterHigh,
+static BOOL APIENTRY
+co_MsqTranslateMouseMessage(PUSER_MESSAGE_QUEUE MessageQueue, PWINDOW_OBJECT Window, UINT FilterLow, UINT FilterHigh,
                             PUSER_MESSAGE Message, BOOL Remove, PBOOL Freed,
                             PWINDOW_OBJECT ScopeWin, PPOINT ScreenPoint, BOOL FromGlobalQueue, PLIST_ENTRY *Next)
 {
    USHORT Msg = Message->Msg.message;
-   PWINDOW_OBJECT Window = NULL;
+   PWINDOW_OBJECT CaptureWindow = NULL;
    HWND hCaptureWin;
 
    ASSERT_REFS_CO(ScopeWin);
@@ -315,18 +315,18 @@ co_MsqTranslateMouseMessage(PUSER_MESSAGE_QUEUE MessageQueue, HWND hWnd, UINT Fi
    hCaptureWin = IntGetCaptureWindow();
    if (hCaptureWin == NULL)
    {
-      if(Msg == WM_MOUSEWHEEL)
+      if (Msg == WM_MOUSEWHEEL)
       {
-         Window = UserGetWindowObject(IntGetFocusWindow());
-         if (Window) UserReferenceObject(Window);
+         CaptureWindow = UserGetWindowObject(IntGetFocusWindow());
+         if (CaptureWindow) UserReferenceObject(CaptureWindow);
       }
       else
       {
-         co_WinPosWindowFromPoint(ScopeWin, NULL, &Message->Msg.pt, &Window);
-         if(Window == NULL)
+         co_WinPosWindowFromPoint(ScopeWin, NULL, &Message->Msg.pt, &CaptureWindow);
+         if(CaptureWindow == NULL)
          {
-            Window = ScopeWin;
-            if (Window) UserReferenceObject(Window);
+            CaptureWindow = ScopeWin;
+            if (CaptureWindow) UserReferenceObject(CaptureWindow);
          }
          else
          {
@@ -339,13 +339,13 @@ co_MsqTranslateMouseMessage(PUSER_MESSAGE_QUEUE MessageQueue, HWND hWnd, UINT Fi
    {
       /* FIXME - window messages should go to the right window if no buttons are
                  pressed */
-      Window = UserGetWindowObject(hCaptureWin);
-      if (Window) UserReferenceObject(Window);
+      CaptureWindow = UserGetWindowObject(hCaptureWin);
+      if (CaptureWindow) UserReferenceObject(CaptureWindow);
    }
 
 
 
-   if (Window == NULL)
+   if (CaptureWindow == NULL)
    {
       if(!FromGlobalQueue)
       {
@@ -361,7 +361,7 @@ co_MsqTranslateMouseMessage(PUSER_MESSAGE_QUEUE MessageQueue, HWND hWnd, UINT Fi
       return(FALSE);
    }
 
-   if (Window->MessageQueue != MessageQueue)
+   if (CaptureWindow->MessageQueue != MessageQueue)
    {
       if (! FromGlobalQueue)
       {
@@ -384,37 +384,37 @@ co_MsqTranslateMouseMessage(PUSER_MESSAGE_QUEUE MessageQueue, HWND hWnd, UINT Fi
 
       /* lock the destination message queue, so we don't get in trouble with other
          threads, messing with it at the same time */
-      IntLockHardwareMessageQueue(Window->MessageQueue);
-      InsertTailList(&Window->MessageQueue->HardwareMessagesListHead,
+      IntLockHardwareMessageQueue(CaptureWindow->MessageQueue);
+      InsertTailList(&CaptureWindow->MessageQueue->HardwareMessagesListHead,
                      &Message->ListEntry);
       if(Message->Msg.message == WM_MOUSEMOVE)
       {
-         if(Window->MessageQueue->MouseMoveMsg)
+         if(CaptureWindow->MessageQueue->MouseMoveMsg)
          {
             /* remove the old WM_MOUSEMOVE message, we're processing a more recent
                one */
-            RemoveEntryList(&Window->MessageQueue->MouseMoveMsg->ListEntry);
-            ExFreePool(Window->MessageQueue->MouseMoveMsg);
+            RemoveEntryList(&CaptureWindow->MessageQueue->MouseMoveMsg->ListEntry);
+            ExFreePool(CaptureWindow->MessageQueue->MouseMoveMsg);
          }
          /* save the pointer to the WM_MOUSEMOVE message in the new queue */
-         Window->MessageQueue->MouseMoveMsg = Message;
+         CaptureWindow->MessageQueue->MouseMoveMsg = Message;
 
-         Window->MessageQueue->QueueBits |= QS_MOUSEMOVE;
-         Window->MessageQueue->ChangedBits |= QS_MOUSEMOVE;
-         if (Window->MessageQueue->WakeMask & QS_MOUSEMOVE)
-            KeSetEvent(Window->MessageQueue->NewMessages, IO_NO_INCREMENT, FALSE);
+         CaptureWindow->MessageQueue->QueueBits |= QS_MOUSEMOVE;
+         CaptureWindow->MessageQueue->ChangedBits |= QS_MOUSEMOVE;
+         if (CaptureWindow->MessageQueue->WakeMask & QS_MOUSEMOVE)
+            KeSetEvent(CaptureWindow->MessageQueue->NewMessages, IO_NO_INCREMENT, FALSE);
       }
       else
       {
-         Window->MessageQueue->QueueBits |= QS_MOUSEBUTTON;
-         Window->MessageQueue->ChangedBits |= QS_MOUSEBUTTON;
-         if (Window->MessageQueue->WakeMask & QS_MOUSEBUTTON)
-            KeSetEvent(Window->MessageQueue->NewMessages, IO_NO_INCREMENT, FALSE);
+         CaptureWindow->MessageQueue->QueueBits |= QS_MOUSEBUTTON;
+         CaptureWindow->MessageQueue->ChangedBits |= QS_MOUSEBUTTON;
+         if (CaptureWindow->MessageQueue->WakeMask & QS_MOUSEBUTTON)
+            KeSetEvent(CaptureWindow->MessageQueue->NewMessages, IO_NO_INCREMENT, FALSE);
       }
-      IntUnLockHardwareMessageQueue(Window->MessageQueue);
+      IntUnLockHardwareMessageQueue(CaptureWindow->MessageQueue);
 
       *Freed = FALSE;
-      UserDereferenceObject(Window);
+      UserDereferenceObject(CaptureWindow);
       return(FALSE);
    }
 
@@ -422,7 +422,7 @@ co_MsqTranslateMouseMessage(PUSER_MESSAGE_QUEUE MessageQueue, HWND hWnd, UINT Fi
 
    *ScreenPoint = Message->Msg.pt;
 
-   if((hWnd != NULL && Window->hSelf != hWnd) ||
+   if((Window != NULL && (int)Window != 1 && CaptureWindow->hSelf != Window->hSelf) ||
          ((FilterLow != 0 || FilterHigh != 0) && (Msg < FilterLow || Msg > FilterHigh)))
    {
       /* Reject the message because it doesn't match the filter */
@@ -432,21 +432,21 @@ co_MsqTranslateMouseMessage(PUSER_MESSAGE_QUEUE MessageQueue, HWND hWnd, UINT Fi
          /* Lock the message queue so no other thread can mess with it.
             Our own message queue is not locked while fetching from the global
             queue, so we have to make sure nothing interferes! */
-         IntLockHardwareMessageQueue(Window->MessageQueue);
+         IntLockHardwareMessageQueue(CaptureWindow->MessageQueue);
          /* if we're from the global queue, we need to add our message to our
             private queue so we don't loose it! */
-         InsertTailList(&Window->MessageQueue->HardwareMessagesListHead,
+         InsertTailList(&CaptureWindow->MessageQueue->HardwareMessagesListHead,
                         &Message->ListEntry);
       }
 
       if (Message->Msg.message == WM_MOUSEMOVE)
       {
-         if(Window->MessageQueue->MouseMoveMsg &&
-               (Window->MessageQueue->MouseMoveMsg != Message))
+         if(CaptureWindow->MessageQueue->MouseMoveMsg &&
+               (CaptureWindow->MessageQueue->MouseMoveMsg != Message))
          {
             /* delete the old message */
-            RemoveEntryList(&Window->MessageQueue->MouseMoveMsg->ListEntry);
-            ExFreePool(Window->MessageQueue->MouseMoveMsg);
+            RemoveEntryList(&CaptureWindow->MessageQueue->MouseMoveMsg->ListEntry);
+            ExFreePool(CaptureWindow->MessageQueue->MouseMoveMsg);
             if (!FromGlobalQueue)
             {
                // We might have deleted the next one in our queue, so fix next
@@ -455,20 +455,20 @@ co_MsqTranslateMouseMessage(PUSER_MESSAGE_QUEUE MessageQueue, HWND hWnd, UINT Fi
          }
          /* always save a pointer to this WM_MOUSEMOVE message here because we're
             sure that the message is in the private queue */
-         Window->MessageQueue->MouseMoveMsg = Message;
+         CaptureWindow->MessageQueue->MouseMoveMsg = Message;
       }
       if(FromGlobalQueue)
       {
-         IntUnLockHardwareMessageQueue(Window->MessageQueue);
+         IntUnLockHardwareMessageQueue(CaptureWindow->MessageQueue);
       }
 
-      UserDereferenceObject(Window);
+      UserDereferenceObject(CaptureWindow);
       *Freed = FALSE;
       return(FALSE);
    }
 
    /* FIXME - only assign if removing? */
-   Message->Msg.hwnd = Window->hSelf;
+   Message->Msg.hwnd = CaptureWindow->hSelf;
    Message->Msg.message = Msg;
    Message->Msg.lParam = MAKELONG(Message->Msg.pt.x, Message->Msg.pt.y);
 
@@ -482,32 +482,32 @@ co_MsqTranslateMouseMessage(PUSER_MESSAGE_QUEUE MessageQueue, HWND hWnd, UINT Fi
          /* Lock the message queue so no other thread can mess with it.
             Our own message queue is not locked while fetching from the global
             queue, so we have to make sure nothing interferes! */
-         IntLockHardwareMessageQueue(Window->MessageQueue);
-         if(Window->MessageQueue->MouseMoveMsg)
+         IntLockHardwareMessageQueue(CaptureWindow->MessageQueue);
+         if(CaptureWindow->MessageQueue->MouseMoveMsg)
          {
             /* delete the WM_(NC)MOUSEMOVE message in the private queue, we're dealing
                with one that's been sent later */
-            RemoveEntryList(&Window->MessageQueue->MouseMoveMsg->ListEntry);
-            ExFreePool(Window->MessageQueue->MouseMoveMsg);
+            RemoveEntryList(&CaptureWindow->MessageQueue->MouseMoveMsg->ListEntry);
+            ExFreePool(CaptureWindow->MessageQueue->MouseMoveMsg);
             /* our message is not in the private queue so we can remove the pointer
                instead of setting it to the current message we're processing */
-            Window->MessageQueue->MouseMoveMsg = NULL;
+            CaptureWindow->MessageQueue->MouseMoveMsg = NULL;
          }
-         IntUnLockHardwareMessageQueue(Window->MessageQueue);
+         IntUnLockHardwareMessageQueue(CaptureWindow->MessageQueue);
       }
-      else if(Window->MessageQueue->MouseMoveMsg == Message)
+      else if (CaptureWindow->MessageQueue->MouseMoveMsg == Message)
       {
-         Window->MessageQueue->MouseMoveMsg = NULL;
+         CaptureWindow->MessageQueue->MouseMoveMsg = NULL;
       }
    }
 
-   UserDereferenceObject(Window);
+   UserDereferenceObject(CaptureWindow);
    *Freed = FALSE;
    return(TRUE);
 }
 
-BOOL STDCALL
-co_MsqPeekHardwareMessage(PUSER_MESSAGE_QUEUE MessageQueue, HWND hWnd,
+BOOL APIENTRY
+co_MsqPeekHardwareMessage(PUSER_MESSAGE_QUEUE MessageQueue, PWINDOW_OBJECT Window,
                           UINT FilterLow, UINT FilterHigh, BOOL Remove,
                           PUSER_MESSAGE* Message)
 {
@@ -534,11 +534,6 @@ co_MsqPeekHardwareMessage(PUSER_MESSAGE_QUEUE MessageQueue, HWND hWnd,
                                             UserMode, FALSE, NULL, NULL);
 
       UserEnterCo();
-
-      while (co_MsqDispatchOneSentMessage(MessageQueue))
-      {
-         ;
-      }
    }
    while (NT_SUCCESS(WaitStatus) && STATUS_WAIT_0 != WaitStatus);
 
@@ -547,7 +542,7 @@ co_MsqPeekHardwareMessage(PUSER_MESSAGE_QUEUE MessageQueue, HWND hWnd,
    if (DesktopWindow)
    {
        UserRefObjectCo(DesktopWindow, &Ref);//can DesktopWindow be NULL?
-       Desk = DesktopWindow->ti->Desktop;
+       Desk = DesktopWindow->ti->pDeskInfo;
    }
 
    /* Process messages in the message queue itself. */
@@ -563,7 +558,7 @@ co_MsqPeekHardwareMessage(PUSER_MESSAGE_QUEUE MessageQueue, HWND hWnd,
       {
 
 
-         Accept = co_MsqTranslateMouseMessage(MessageQueue, hWnd, FilterLow, FilterHigh,
+         Accept = co_MsqTranslateMouseMessage(MessageQueue, Window, FilterLow, FilterHigh,
                                               Current, Remove, &Freed,
                                               DesktopWindow, &ScreenPoint, FALSE, &CurrentEntry);
          if (Accept)
@@ -663,7 +658,7 @@ co_MsqPeekHardwareMessage(PUSER_MESSAGE_QUEUE MessageQueue, HWND hWnd,
       {
          const ULONG ActiveStamp = HardwareMessageQueueStamp;
          /* Translate the message. */
-         Accept = co_MsqTranslateMouseMessage(MessageQueue, hWnd, FilterLow, FilterHigh,
+         Accept = co_MsqTranslateMouseMessage(MessageQueue, Window, FilterLow, FilterHigh,
                                               Current, Remove, &Freed,
                                               DesktopWindow, &ScreenPoint, TRUE, NULL);
          if (Accept)
@@ -739,12 +734,18 @@ co_MsqPostKeyboardMessage(UINT uMsg, WPARAM wParam, LPARAM lParam)
    LARGE_INTEGER LargeTickCount;
    KBDLLHOOKSTRUCT KbdHookData;
    EVENTMSG Event;
+   BOOLEAN Entered = FALSE;
 
    DPRINT("MsqPostKeyboardMessage(uMsg 0x%x, wParam 0x%x, lParam 0x%x)\n",
           uMsg, wParam, lParam);
 
    // Condition may arise when calling MsqPostMessage and waiting for an event.
-   if (!UserIsEntered()) UserEnterExclusive(); // Fixme: Not sure ATM if this thread is locked.
+   if (!UserIsEntered())
+   {
+         // Fixme: Not sure ATM if this thread is locked.
+         UserEnterExclusive();
+         Entered = TRUE;
+   }
 
    FocusMessageQueue = IntGetFocusMessageQueue();
 
@@ -782,12 +783,14 @@ co_MsqPostKeyboardMessage(UINT uMsg, WPARAM wParam, LPARAM lParam)
    {
       DPRINT("Kbd msg %d wParam %d lParam 0x%08x dropped by WH_KEYBOARD_LL hook\n",
              Msg.message, Msg.wParam, Msg.lParam);
+      if (Entered) UserLeave();
       return;
    }
 
    if (FocusMessageQueue == NULL)
    {
          DPRINT("No focus message queue\n");
+         if (Entered) UserLeave();
          return;
    }
 
@@ -806,7 +809,9 @@ co_MsqPostKeyboardMessage(UINT uMsg, WPARAM wParam, LPARAM lParam)
    {
          DPRINT("Invalid focus window handle\n");
    }
-   if (UserIsEntered()) UserLeave();
+
+   if (Entered) UserLeave();
+   return;
 }
 
 VOID FASTCALL
@@ -942,8 +947,8 @@ co_MsqDispatchOneSentMessage(PUSER_MESSAGE_QUEUE MessageQueue)
    {
       Result = co_EVENT_CallEvents( Message->Msg.message,
                                     Message->Msg.hwnd,
-                             (LONG) Message->Msg.wParam,
-                             (LONG) Message->Msg.lParam);                                  
+                                    Message->Msg.wParam,
+                                    Message->Msg.lParam);                                  
    }
    else
    {
@@ -1010,7 +1015,7 @@ Notified:
    return(TRUE);
 }
 
-VOID STDCALL
+VOID APIENTRY
 MsqRemoveWindowMessagesFromQueue(PVOID pWindow)
 {
    PUSER_SENT_MESSAGE SentMessage;
@@ -1312,11 +1317,11 @@ MsqPostQuitMessage(PUSER_MESSAGE_QUEUE MessageQueue, ULONG ExitCode)
       KeSetEvent(MessageQueue->NewMessages, IO_NO_INCREMENT, FALSE);
 }
 
-BOOLEAN STDCALL
+BOOLEAN APIENTRY
 co_MsqFindMessage(IN PUSER_MESSAGE_QUEUE MessageQueue,
                   IN BOOLEAN Hardware,
                   IN BOOLEAN Remove,
-                  IN HWND Wnd,
+                  IN PWINDOW_OBJECT Window,
                   IN UINT MsgFilterLow,
                   IN UINT MsgFilterHigh,
                   OUT PUSER_MESSAGE* Message)
@@ -1327,7 +1332,7 @@ co_MsqFindMessage(IN PUSER_MESSAGE_QUEUE MessageQueue,
 
    if (Hardware)
    {
-      return(co_MsqPeekHardwareMessage(MessageQueue, Wnd,
+      return(co_MsqPeekHardwareMessage(MessageQueue, Window,
                                        MsgFilterLow, MsgFilterHigh,
                                        Remove, Message));
    }
@@ -1338,7 +1343,7 @@ co_MsqFindMessage(IN PUSER_MESSAGE_QUEUE MessageQueue,
    {
       CurrentMessage = CONTAINING_RECORD(CurrentEntry, USER_MESSAGE,
                                          ListEntry);
-      if ((Wnd == 0 || Wnd == CurrentMessage->Msg.hwnd) &&
+      if ((!Window || (int)Window == 1 || Window->hSelf == CurrentMessage->Msg.hwnd) &&
             ((MsgFilterLow == 0 && MsgFilterHigh == 0) ||
              (MsgFilterLow <= CurrentMessage->Msg.message &&
               MsgFilterHigh >= CurrentMessage->Msg.message)))
@@ -1358,7 +1363,7 @@ co_MsqFindMessage(IN PUSER_MESSAGE_QUEUE MessageQueue,
 }
 
 NTSTATUS FASTCALL
-co_MsqWaitForNewMessages(PUSER_MESSAGE_QUEUE MessageQueue, HWND WndFilter,
+co_MsqWaitForNewMessages(PUSER_MESSAGE_QUEUE MessageQueue, PWINDOW_OBJECT WndFilter,
                          UINT MsgFilterMin, UINT MsgFilterMax)
 {
    PVOID WaitObjects[2] = {MessageQueue->NewMessages, &HardwareMessageEvent};
@@ -1423,6 +1428,7 @@ MsqInitializeMessageQueue(struct _ETHREAD *Thread, PUSER_MESSAGE_QUEUE MessageQu
    MessageQueue->LastMsgRead = LargeTickCount.u.LowPart;
    MessageQueue->FocusWindow = NULL;
    MessageQueue->PaintCount = 0;
+// HACK!!!!!!! Newbies that wrote this should hold your head down in shame! (jt)
    MessageQueue->WakeMask = ~0;
    MessageQueue->NewMessagesHandle = NULL;
 
@@ -1550,7 +1556,7 @@ MsqCreateMessageQueue(struct _ETHREAD *Thread)
 {
    PUSER_MESSAGE_QUEUE MessageQueue;
 
-   MessageQueue = (PUSER_MESSAGE_QUEUE)ExAllocatePoolWithTag(PagedPool,
+   MessageQueue = (PUSER_MESSAGE_QUEUE)ExAllocatePoolWithTag(NonPagedPool,
                   sizeof(USER_MESSAGE_QUEUE) + sizeof(THRDCARETINFO),
                   TAG_MSGQ);
 
@@ -1822,7 +1828,7 @@ MsqKillTimer(PUSER_MESSAGE_QUEUE MessageQueue, HWND Wnd,
 
 BOOLEAN FASTCALL
 MsqGetTimerMessage(PUSER_MESSAGE_QUEUE MessageQueue,
-                   HWND WndFilter, UINT MsgFilterMin, UINT MsgFilterMax,
+                   PWINDOW_OBJECT WindowFilter, UINT MsgFilterMin, UINT MsgFilterMax,
                    MSG *Msg, BOOLEAN Restart)
 {
    PTIMER_ENTRY Timer;
@@ -1846,7 +1852,7 @@ MsqGetTimerMessage(PUSER_MESSAGE_QUEUE MessageQueue,
       DPRINT("Checking timer %p wnd %x expiry %I64d\n", Timer, Timer->Wnd,
              Timer->ExpiryTime.QuadPart);
       EnumEntry = EnumEntry->Flink;
-      if ((NULL == WndFilter || Timer->Wnd == WndFilter) &&
+      if ((NULL == WindowFilter || Timer->Wnd == WindowFilter->hSelf) &&
             ((MsgFilterMin == 0 && MsgFilterMax == 0) ||
              (MsgFilterMin <= Timer->Msg &&
               Timer->Msg <= MsgFilterMax)))
@@ -1866,7 +1872,7 @@ MsqGetTimerMessage(PUSER_MESSAGE_QUEUE MessageQueue,
       else
       {
          DPRINT("timer %p (wnd %x msg %d) failed filter wnd %x msgmin %d msgmax %d\n",
-                Timer, Timer->Wnd, Timer->Msg, WndFilter, MsgFilterMin, MsgFilterMax);
+                Timer, Timer->Wnd, Timer->Msg, WindowFilter->hSelf, MsgFilterMin, MsgFilterMax);
       }
    }
 
@@ -1936,7 +1942,7 @@ MsqRemoveTimersWindow(PUSER_MESSAGE_QUEUE MessageQueue, HWND Wnd)
 
 BOOLEAN FASTCALL
 MsqGetFirstTimerExpiry(PUSER_MESSAGE_QUEUE MessageQueue,
-                       HWND WndFilter, UINT MsgFilterMin, UINT MsgFilterMax,
+                       PWINDOW_OBJECT WndFilter, UINT MsgFilterMin, UINT MsgFilterMax,
                        PLARGE_INTEGER FirstTimerExpiry)
 {
    PTIMER_ENTRY Timer;
@@ -1951,7 +1957,7 @@ MsqGetFirstTimerExpiry(PUSER_MESSAGE_QUEUE MessageQueue,
       Timer = CONTAINING_RECORD(MessageQueue->TimerListHead.Flink,
                                 TIMER_ENTRY, ListEntry);
       EnumEntry = EnumEntry->Flink;
-      if ((NULL == WndFilter || Timer->Wnd == WndFilter) &&
+      if ((NULL == WndFilter || (int)WndFilter == 1 || Timer->Wnd == WndFilter->hSelf) &&
             ((MsgFilterMin == 0 && MsgFilterMax == 0) ||
              (MsgFilterMin <= Timer->Msg &&
               Timer->Msg <= MsgFilterMax)))