[Win32ss]
[reactos.git] / reactos / win32ss / user / ntuser / message.c
index f3c5c24..2151f0f 100644 (file)
@@ -116,7 +116,7 @@ typedef struct tagMSGMEMORY
 }
 MSGMEMORY, *PMSGMEMORY;
 
-static MSGMEMORY MsgMemory[] =
+static MSGMEMORY g_MsgMemory[] =
 {
     { WM_CREATE, MMS_SIZE_SPECIAL, MMS_FLAG_READWRITE },
     { WM_DDE_ACK, sizeof(KMDDELPARAM), MMS_FLAG_READ },
@@ -140,8 +140,8 @@ FindMsgMemory(UINT Msg)
     PMSGMEMORY MsgMemoryEntry;
 
     /* See if this message type is present in the table */
-    for (MsgMemoryEntry = MsgMemory;
-    MsgMemoryEntry < MsgMemory + sizeof(MsgMemory) / sizeof(MSGMEMORY);
+    for (MsgMemoryEntry = g_MsgMemory;
+    MsgMemoryEntry < g_MsgMemory + sizeof(g_MsgMemory) / sizeof(MSGMEMORY);
     MsgMemoryEntry++)
     {
         if (Msg == MsgMemoryEntry->Message)
@@ -223,6 +223,13 @@ MsgMemorySize(PMSGMEMORY MsgMemoryEntry, WPARAM wParam, LPARAM lParam)
     return Size;
 }
 
+UINT lParamMemorySize(UINT Msg, WPARAM wParam, LPARAM lParam)
+{
+    PMSGMEMORY MsgMemoryEntry = FindMsgMemory(Msg);
+    if(MsgMemoryEntry == NULL) return 0;
+    return MsgMemorySize(MsgMemoryEntry, wParam, lParam);
+}
+
 static NTSTATUS
 PackParam(LPARAM *lParamPacked, UINT Msg, WPARAM wParam, LPARAM lParam, BOOL NonPagedPoolNeeded)
 {
@@ -381,9 +388,9 @@ UnpackParam(LPARAM lParamPacked, UINT Msg, WPARAM wParam, LPARAM lParam, BOOL No
             return STATUS_INVALID_PARAMETER;
         }
 
-        if (MsgMemory->Flags == MMS_FLAG_READWRITE)
+        if (MsgMemoryEntry->Flags == MMS_FLAG_READWRITE)
         {
-            //RtlCopyMemory((PVOID)lParam, (PVOID)lParamPacked, MsgMemory->Size);
+            //RtlCopyMemory((PVOID)lParam, (PVOID)lParamPacked, MsgMemoryEntry->Size);
         }
         ExFreePool((PVOID) lParamPacked);
         return STATUS_SUCCESS;
@@ -501,7 +508,7 @@ IdlePing(VOID)
    ForegroundQueue = IntGetFocusMessageQueue();
 
    if (ForegroundQueue)
-      ptiForeground = ForegroundQueue->Thread->Tcb.Win32Thread;
+       ptiForeground = ForegroundQueue->ptiOwner;
 
    pti = PsGetCurrentThreadWin32Thread();
 
@@ -519,7 +526,7 @@ IdlePing(VOID)
       }
    }
 
-   TRACE("IdlePing ppi 0x%x\n",ppi);
+   TRACE("IdlePing ppi %p\n", ppi);
    if ( ppi && ppi->InputIdleEvent )
    {
       TRACE("InputIdleEvent\n");
@@ -532,7 +539,7 @@ IdlePong(VOID)
 {
    PPROCESSINFO ppi = PsGetCurrentProcessWin32Process();
 
-   TRACE("IdlePong ppi 0x%x\n",ppi);
+   TRACE("IdlePong ppi %p\n", ppi);
    if ( ppi && ppi->InputIdleEvent )
    {
       KeClearEvent(ppi->InputIdleEvent);
@@ -601,7 +608,7 @@ static LRESULT handle_internal_message( PWND pWnd, UINT msg, WPARAM wparam, LPAR
          pWnd == UserGetMessageWindow() )  // pWnd->fnid == FNID_MESSAGEWND
        return 0;
 
-    ERR("Internal Event Msg %p\n",msg);
+    TRACE("Internal Event Msg %u hWnd %p\n", msg, pWnd->head.h);
 
     switch(msg)
     {
@@ -625,7 +632,7 @@ static LRESULT handle_internal_message( PWND pWnd, UINT msg, WPARAM wparam, LPAR
        {
           PWND Window = (PWND)wparam;
           if (wparam) UserRefObjectCo(Window, &Ref);
-          lRes = (LRESULT)co_IntSetActiveWindow(Window,NULL,(BOOL)lparam,TRUE);
+          lRes = (LRESULT)co_IntSetActiveWindow(Window,NULL,(BOOL)lparam,TRUE,TRUE);
           if (wparam) UserDerefObjectCo(Window);
           return lRes;
        }
@@ -642,6 +649,7 @@ IntDispatchMessage(PMSG pMsg)
     PTHREADINFO pti;
     PWND Window = NULL;
     HRGN hrgn;
+    BOOL DoCallBack = TRUE;
 
     if (pMsg->hwnd)
     {
@@ -697,12 +705,30 @@ IntDispatchMessage(PMSG pMsg)
     if ( Window->state & WNDS_SERVERSIDEWINDOWPROC )
     {
        TRACE("Dispatch: Server Side Window Procedure\n");
+       switch(Window->fnid)
+       {
+          case FNID_DESKTOP:
+            DoCallBack = !DesktopWindowProc( Window,
+                                             pMsg->message,
+                                             pMsg->wParam,
+                                             pMsg->lParam,
+                                            &retval);
+            break;
+          case FNID_MESSAGEWND:
+            DoCallBack = !UserMessageWindowProc( Window,
+                                                 pMsg->message,
+                                                 pMsg->wParam,
+                                                 pMsg->lParam,
+                                                 &retval);
+            break;
+       }
     }
 
     /* Since we are doing a callback on the same thread right away, there is
        no need to copy the lparam to kernel mode and then back to usermode.
        We just pretend it isn't a pointer */
 
+    if (DoCallBack)
     retval = co_IntCallWindowProc( Window->lpfnWndProc,
                                    !Window->Unicode,
                                    pMsg->hwnd,
@@ -735,20 +761,16 @@ co_IntPeekMessage( PMSG Msg,
                    BOOL bGMSG )
 {
     PTHREADINFO pti;
-    //PCLIENTINFO pci;
     LARGE_INTEGER LargeTickCount;
-    PUSER_MESSAGE_QUEUE ThreadQueue;
     BOOL RemoveMessages;
     UINT ProcessMask;
     BOOL Hit = FALSE;
 
     pti = PsGetCurrentThreadWin32Thread();
-    ThreadQueue = pti->MessageQueue;
-    //pci = pti->pClientInfo;
 
     RemoveMessages = RemoveMsg & PM_REMOVE;
     ProcessMask = HIWORD(RemoveMsg);
-
+    
  /* Hint, "If wMsgFilterMin and wMsgFilterMax are both zero, PeekMessage returns
     all available messages (that is, no range filtering is performed)".        */
     if (!ProcessMask) ProcessMask = (QS_ALLPOSTMESSAGE|QS_ALLINPUT);
@@ -758,11 +780,11 @@ co_IntPeekMessage( PMSG Msg,
     do
     {
         KeQueryTickCount(&LargeTickCount);
-        ThreadQueue->LastMsgRead = LargeTickCount.u.LowPart;
+        pti->timeLast = LargeTickCount.u.LowPart;
         pti->pcti->tickLastMsgChecked = LargeTickCount.u.LowPart;
 
         /* Dispatch sent messages here. */
-        while ( co_MsqDispatchOneSentMessage(ThreadQueue) )
+        while ( co_MsqDispatchOneSentMessage(pti) )
         {
            /* if some PM_QS* flags were specified, only handle sent messages from now on */
            if (HIWORD(RemoveMsg) && !bGMSG) Hit = TRUE; // wine does this; ProcessMask = QS_SENDMESSAGE;
@@ -787,7 +809,7 @@ co_IntPeekMessage( PMSG Msg,
         /* Now check for normal messages. */
         if (( (ProcessMask & QS_POSTMESSAGE) ||
               (ProcessMask & QS_HOTKEY) ) &&
-            MsqPeekMessage( ThreadQueue,
+            MsqPeekMessage( pti,
                             RemoveMessages,
                             Window,
                             MsgFilterMin,
@@ -799,18 +821,18 @@ co_IntPeekMessage( PMSG Msg,
         }
 
         /* Now look for a quit message. */
-        if (ThreadQueue->QuitPosted)
+        if (pti->QuitPosted)
         {
             /* According to the PSDK, WM_QUIT messages are always returned, regardless
                of the filter specified */
             Msg->hwnd = NULL;
             Msg->message = WM_QUIT;
-            Msg->wParam = ThreadQueue->QuitExitCode;
+            Msg->wParam = pti->exitCode;
             Msg->lParam = 0;
             if (RemoveMessages)
             {
-                ThreadQueue->QuitPosted = FALSE;
-                ClearMsgBitsMask(ThreadQueue, QS_POSTMESSAGE);
+                pti->QuitPosted = FALSE;
+                ClearMsgBitsMask(pti, QS_POSTMESSAGE);
                 pti->pcti->fsWakeBits &= ~QS_ALLPOSTMESSAGE;
                 pti->pcti->fsChangeBits &= ~QS_ALLPOSTMESSAGE;
             }
@@ -819,7 +841,7 @@ co_IntPeekMessage( PMSG Msg,
 
         /* Check for hardware events. */
         if ((ProcessMask & QS_MOUSE) &&
-            co_MsqPeekMouseMove( ThreadQueue,
+            co_MsqPeekMouseMove( pti,
                                  RemoveMessages,
                                  Window,
                                  MsgFilterMin,
@@ -830,7 +852,7 @@ co_IntPeekMessage( PMSG Msg,
         }
 
         if ((ProcessMask & QS_INPUT) &&
-            co_MsqPeekHardwareMessage( ThreadQueue,
+            co_MsqPeekHardwareMessage( pti,
                                        RemoveMessages,
                                        Window,
                                        MsgFilterMin,
@@ -842,7 +864,7 @@ co_IntPeekMessage( PMSG Msg,
         }
 
         /* Check for sent messages again. */
-        while ( co_MsqDispatchOneSentMessage(ThreadQueue) )
+        while ( co_MsqDispatchOneSentMessage(pti) )
         {
            if (HIWORD(RemoveMsg) && !bGMSG) Hit = TRUE;
         }
@@ -883,12 +905,10 @@ co_IntWaitMessage( PWND Window,
                    UINT MsgFilterMax )
 {
     PTHREADINFO pti;
-    PUSER_MESSAGE_QUEUE ThreadQueue;
     NTSTATUS Status = STATUS_SUCCESS;
     MSG Msg;
 
     pti = PsGetCurrentThreadWin32Thread();
-    ThreadQueue = pti->MessageQueue;
 
     do
     {
@@ -903,7 +923,7 @@ co_IntWaitMessage( PWND Window,
         }
 
         /* Nothing found. Wait for new messages. */
-        Status = co_MsqWaitForNewMessages( ThreadQueue,
+        Status = co_MsqWaitForNewMessages( pti,
                                            Window,
                                            MsgFilterMin,
                                            MsgFilterMax);
@@ -998,7 +1018,7 @@ co_IntGetPeekMessage( PMSG pMsg,
 
         if ( bGMSG )
         {
-            Status = co_MsqWaitForNewMessages( pti->MessageQueue,
+            Status = co_MsqWaitForNewMessages( pti,
                                                Window,
                                                MsgFilterMin,
                                                MsgFilterMax);
@@ -1076,7 +1096,7 @@ UserPostThreadMessage( DWORD idThread,
 
         KeQueryTickCount(&LargeTickCount);
         Message.time = MsqCalculateMessageTime(&LargeTickCount);
-        MsqPostMessage(pThread->MessageQueue, &Message, FALSE, QS_POSTMESSAGE);
+        MsqPostMessage(pThread, &Message, FALSE, QS_POSTMESSAGE, 0);
         ObDereferenceObject( peThread );
         return TRUE;
     }
@@ -1175,30 +1195,31 @@ UserPostMessage( HWND Wnd,
         Window = UserGetWindowObject(Wnd);
         if ( !Window )
         {
+            ERR("UserPostMessage: Invalid handle 0x%p!\n",Wnd);
             return FALSE;
         }
 
         pti = Window->head.pti;
         if ( pti->TIF_flags & TIF_INCLEANUP )
         {
-            ERR("Attempted to post message to window 0x%x when the thread is in cleanup!\n", Wnd);
+            ERR("Attempted to post message to window %p when the thread is in cleanup!\n", Wnd);
             return FALSE;
         }
 
         if ( Window->state & WNDS_DESTROYED )
         {
-            ERR("Attempted to post message to window 0x%x that is being destroyed!\n", Wnd);
+            ERR("Attempted to post message to window %p that is being destroyed!\n", Wnd);
             /* FIXME: Last error code? */
             return FALSE;
         }
 
         if (WM_QUIT == Msg)
         {
-            MsqPostQuitMessage(Window->head.pti->MessageQueue, wParam);
+            MsqPostQuitMessage(Window->head.pti, wParam);
         }
         else
         {
-            MsqPostMessage(Window->head.pti->MessageQueue, &Message, FALSE, QS_POSTMESSAGE);
+            MsqPostMessage(Window->head.pti, &Message, FALSE, QS_POSTMESSAGE, 0);
         }
     }
     return TRUE;
@@ -1236,9 +1257,11 @@ co_IntSendMessageTimeoutSingle( HWND hWnd,
     ULONG_PTR Hi, Lo, Result = 0;
     DECLARE_RETURN(LRESULT);
     USER_REFERENCE_ENTRY Ref;
+    BOOL DoCallBack = TRUE;
 
     if (!(Window = UserGetWindowObject(hWnd)))
     {
+        TRACE("SendMessageTimeoutSingle: Invalid handle 0x%p!\n",hWnd);
         RETURN( FALSE);
     }
 
@@ -1247,7 +1270,7 @@ co_IntSendMessageTimeoutSingle( HWND hWnd,
     Win32Thread = PsGetCurrentThreadWin32Thread();
 
     if ( Win32Thread &&
-         Window->head.pti->MessageQueue == Win32Thread->MessageQueue)
+         Window->head.pti == Win32Thread)
     {
         if (Win32Thread->TIF_flags & TIF_INCLEANUP)
         {
@@ -1257,7 +1280,7 @@ co_IntSendMessageTimeoutSingle( HWND hWnd,
 
         if (Msg & 0x80000000)
         {
-           ERR("SMTS: Internal Message!\n");
+           TRACE("SMTS: Internal Message!\n");
            Result = (ULONG_PTR)handle_internal_message( Window, Msg, wParam, lParam );
            if (uResult) *uResult = Result;
            RETURN( TRUE);
@@ -1277,6 +1300,20 @@ co_IntSendMessageTimeoutSingle( HWND hWnd,
               RETURN( FALSE);
            }
            /* Return after server side call, IntCallWndProcRet will not be called. */
+           switch(Window->fnid)
+           {
+              case FNID_DESKTOP:
+                DoCallBack = !DesktopWindowProc(Window, Msg, wParam, lParam,(LRESULT*)&Result);
+                break;
+              case FNID_MESSAGEWND:
+                DoCallBack = !UserMessageWindowProc(Window, Msg, wParam, lParam,(LRESULT*)&Result);
+                break;
+           }
+           if (!DoCallBack)
+           {
+              if (uResult) *uResult = Result;
+              RETURN( TRUE);
+           }
         }
         /* See if this message type is present in the table */
         MsgMemoryEntry = FindMsgMemory(Msg);
@@ -1319,7 +1356,7 @@ co_IntSendMessageTimeoutSingle( HWND hWnd,
         RETURN( TRUE);
     }
 
-    if (uFlags & SMTO_ABORTIFHUNG && MsqIsHung(Window->head.pti->MessageQueue))
+    if (uFlags & SMTO_ABORTIFHUNG && MsqIsHung(Window->head.pti))
     {
         // FIXME: Set window hung and add to a list.
         /* FIXME: Set a LastError? */
@@ -1329,13 +1366,13 @@ co_IntSendMessageTimeoutSingle( HWND hWnd,
     if (Window->state & WNDS_DESTROYED)
     {
         /* FIXME: Last error? */
-        ERR("Attempted to send message to window 0x%x that is being destroyed!\n", hWnd);
+        ERR("Attempted to send message to window %p that is being destroyed!\n", hWnd);
         RETURN( FALSE);
     }
 
     do
     {
-        Status = co_MsqSendMessage( Window->head.pti->MessageQueue,
+        Status = co_MsqSendMessage( Window->head.pti,
                                     hWnd,
                                     Msg,
                                     wParam,
@@ -1347,7 +1384,7 @@ co_IntSendMessageTimeoutSingle( HWND hWnd,
     }
     while ((STATUS_TIMEOUT == Status) &&
            (uFlags & SMTO_NOTIMEOUTIFNOTHUNG) &&
-           !MsqIsHung(Window->head.pti->MessageQueue)); // FIXME: Set window hung and add to a list.
+           !MsqIsHung(Window->head.pti)); // FIXME: Set window hung and add to a list.
 
     if (STATUS_TIMEOUT == Status)
     {
@@ -1481,9 +1518,11 @@ co_IntSendMessageWithCallBack( HWND hWnd,
     DECLARE_RETURN(LRESULT);
     USER_REFERENCE_ENTRY Ref;
     PUSER_SENT_MESSAGE Message;
+    BOOL DoCallBack = TRUE;
 
     if (!(Window = UserGetWindowObject(hWnd)))
     {
+        TRACE("SendMessageWithCallBack: Invalid handle 0x%p!\n",hWnd);
         RETURN(FALSE);
     }
 
@@ -1492,21 +1531,24 @@ co_IntSendMessageWithCallBack( HWND hWnd,
     if (Window->state & WNDS_DESTROYED)
     {
         /* FIXME: last error? */
-        ERR("Attempted to send message to window 0x%x that is being destroyed!\n", hWnd);
+        ERR("Attempted to send message to window %p that is being destroyed!\n", hWnd);
         RETURN(FALSE);
     }
 
     Win32Thread = PsGetCurrentThreadWin32Thread();
 
-    if (Win32Thread == NULL)
+    if (Win32Thread == NULL ||
+        Win32Thread->TIF_flags & TIF_INCLEANUP)
     {
         RETURN(FALSE);
     }
 
     if (Msg & 0x80000000 &&
-        Window->head.pti->MessageQueue == Win32Thread->MessageQueue)
+        Window->head.pti == Win32Thread)
     {
-       ERR("SMWCB: Internal Message!\n");
+       if (Win32Thread->TIF_flags & TIF_INCLEANUP) RETURN( FALSE);
+
+       TRACE("SMWCB: Internal Message!\n");
        Result = (ULONG_PTR)handle_internal_message( Window, Msg, wParam, lParam );
        if (uResult) *uResult = Result;
        RETURN( TRUE);
@@ -1523,14 +1565,14 @@ co_IntSendMessageWithCallBack( HWND hWnd,
         lParamBufferSize = MsgMemorySize(MsgMemoryEntry, wParam, lParam);
     }
 
-    if (! NT_SUCCESS(PackParam(&lParamPacked, Msg, wParam, lParam, Window->head.pti->MessageQueue != Win32Thread->MessageQueue)))
+    if (! NT_SUCCESS(PackParam(&lParamPacked, Msg, wParam, lParam, Window->head.pti != Win32Thread)))
     {
         ERR("Failed to pack message parameters\n");
         RETURN( FALSE);
     }
 
     /* If it can be sent now, then send it. */
-    if (Window->head.pti->MessageQueue == Win32Thread->MessageQueue)
+    if (Window->head.pti == Win32Thread)
     {
         if (Win32Thread->TIF_flags & TIF_INCLEANUP)
         {
@@ -1544,8 +1586,18 @@ co_IntSendMessageWithCallBack( HWND hWnd,
         if ( Window->state & WNDS_SERVERSIDEWINDOWPROC )
         {
            TRACE("SMWCB: Server Side Window Procedure\n");
+           switch(Window->fnid)
+           {
+              case FNID_DESKTOP:
+                DoCallBack = !DesktopWindowProc(Window, Msg, wParam, lParamPacked, (LRESULT*)&Result);
+                break;
+              case FNID_MESSAGEWND:
+                DoCallBack = !UserMessageWindowProc(Window, Msg, wParam, lParam,(LRESULT*)&Result);
+                break;
+           }
         }
 
+        if (DoCallBack)
         Result = (ULONG_PTR)co_IntCallWindowProc( Window->lpfnWndProc,
                                                   !Window->Unicode,
                                                   hWnd,
@@ -1570,7 +1622,7 @@ co_IntSendMessageWithCallBack( HWND hWnd,
         }
     }
 
-    if (Window->head.pti->MessageQueue == Win32Thread->MessageQueue)
+    if (Window->head.pti == Win32Thread)
     {
         if (! NT_SUCCESS(UnpackParam(lParamPacked, Msg, wParam, lParam, FALSE)))
         {
@@ -1585,12 +1637,6 @@ co_IntSendMessageWithCallBack( HWND hWnd,
         RETURN( FALSE);
     }
 
-    IntReferenceMessageQueue(Window->head.pti->MessageQueue);
-    /* Take reference on this MessageQueue if its a callback. It will be released
-       when message is processed or removed from target hwnd MessageQueue */
-    if (CompletionCallback)
-       IntReferenceMessageQueue(Win32Thread->MessageQueue);
-
     Message->Msg.hwnd = hWnd;
     Message->Msg.message = Msg;
     Message->Msg.wParam = wParam;
@@ -1599,8 +1645,9 @@ co_IntSendMessageWithCallBack( HWND hWnd,
     Message->Result = 0;
     Message->lResult = 0;
     Message->QS_Flags = 0;
-    Message->SenderQueue = NULL; // mjmartin, you are right! This is null.
-    Message->CallBackSenderQueue = Win32Thread->MessageQueue;
+    Message->ptiReceiver = Window->head.pti;
+    Message->ptiSender = NULL; // mjmartin, you are right! This is null.
+    Message->ptiCallBackSender = Win32Thread;
     Message->DispatchingListEntry.Flink = NULL;
     Message->CompletionCallback = CompletionCallback;
     Message->CompletionCallbackContext = CompletionCallbackContext;
@@ -1608,9 +1655,11 @@ co_IntSendMessageWithCallBack( HWND hWnd,
     Message->HasPackedLParam = (lParamBufferSize > 0);
     Message->QS_Flags = QS_SENDMESSAGE;
 
-    InsertTailList(&Window->head.pti->MessageQueue->SentMessagesListHead, &Message->ListEntry);
-    MsqWakeQueue(Window->head.pti->MessageQueue, QS_SENDMESSAGE, TRUE);
-    IntDereferenceMessageQueue(Window->head.pti->MessageQueue);
+    if (Msg & 0x80000000) // Higher priority event message!
+       InsertHeadList(&Window->head.pti->SentMessagesListHead, &Message->ListEntry);
+    else
+       InsertTailList(&Window->head.pti->SentMessagesListHead, &Message->ListEntry);
+    MsqWakeQueue(Window->head.pti, QS_SENDMESSAGE, TRUE);
 
     RETURN(TRUE);
 
@@ -1642,6 +1691,7 @@ co_IntPostOrSendMessage( HWND hWnd,
 
     if(!(Window = UserGetWindowObject(hWnd)))
     {
+        TRACE("PostOrSendMessage: Invalid handle 0x%p!\n",hWnd);
         return 0;
     }
 
@@ -1790,11 +1840,9 @@ DWORD APIENTRY
 IntGetQueueStatus(DWORD Changes)
 {
     PTHREADINFO pti;
-    //PUSER_MESSAGE_QUEUE Queue;
     DWORD Result;
 
     pti = PsGetCurrentThreadWin32Thread();
-    //Queue = pti->MessageQueue;
 // wine:
     Changes &= (QS_ALLINPUT|QS_ALLPOSTMESSAGE|QS_SMRESULT);
 
@@ -1852,7 +1900,7 @@ NtUserDragDetect(
     ULONG wDragWidth, wDragHeight;
     DECLARE_RETURN(BOOL);
 
-    TRACE("Enter NtUserDragDetect(%x)\n", hWnd);
+    TRACE("Enter NtUserDragDetect(%p)\n", hWnd);
     UserEnterExclusive();
 
     wDragWidth = UserGetSystemMetrics(SM_CXDRAG);
@@ -2115,12 +2163,12 @@ NtUserDispatchMessage(PMSG UnsafeMsgInfo)
     return Res;
 }
 
-
 BOOL APIENTRY
 NtUserTranslateMessage(LPMSG lpMsg, UINT flags)
 {
     MSG SafeMsg;
     BOOL Ret;
+    PWND pWnd;
 
     _SEH2_TRY
     {
@@ -2135,14 +2183,23 @@ NtUserTranslateMessage(LPMSG lpMsg, UINT flags)
     _SEH2_END;
 
     UserEnterExclusive();
-
-    Ret = IntTranslateKbdMessage(&SafeMsg, flags);
-
+    pWnd = UserGetWindowObject(SafeMsg.hwnd);
+    if (pWnd) // Must have a window!
+    {
+       Ret = IntTranslateKbdMessage(&SafeMsg, flags);
+    }
+    else
+    {
+        TRACE("No Window for Translate. hwnd 0x%p Msg %u\n", SafeMsg.hwnd, SafeMsg.message);
+        Ret = FALSE;
+    }
     UserLeave();
 
     return Ret;
 }
 
+LRESULT APIENTRY ScrollBarWndProc(HWND Wnd, UINT Msg, WPARAM wParam, LPARAM lParam);
+
 BOOL APIENTRY
 NtUserMessageCall( HWND hWnd,
                    UINT Msg,
@@ -2163,20 +2220,30 @@ NtUserMessageCall( HWND hWnd,
     {
     case FNID_SCROLLBAR:
         {
-           switch(Msg)
+           lResult = ScrollBarWndProc(hWnd, Msg, wParam, lParam);
+           break;
+        }
+    case FNID_DESKTOP:
+        {
+           Window = UserGetWindowObject(hWnd);
+           if (Window)
            {
-               case WM_ENABLE:
-                  {
-                     Window = UserGetWindowObject(hWnd);
-                     if (Window->pSBInfo)
-                     {
-                        Window->pSBInfo->WSBflags = wParam ? ESB_ENABLE_BOTH : ESB_DISABLE_BOTH;
-                     }
-                  }
-                  break;
+              //ERR("FNID_DESKTOP IN\n");
+              Ret = DesktopWindowProc(Window, Msg, wParam, lParam, &lResult);
+              //ERR("FNID_DESKTOP OUT\n");
            }
            break;
         }
+
+   case FNID_MESSAGEWND:
+       {
+           Window = UserGetWindowObject(hWnd);
+           if (Window)
+           {
+                Ret = !UserMessageWindowProc(Window, Msg, wParam, lParam,&lResult);
+           }
+           break;
+       }
     case FNID_DEFWINDOWPROC:
         /* Validate input */
         if (hWnd)
@@ -2272,7 +2339,7 @@ NtUserMessageCall( HWND hWnd,
 
                            if ( parm.flags & BSF_IGNORECURRENTTASK )
                            {
-                              if ( pwnd->head.pti->MessageQueue == gptiCurrent->MessageQueue )
+                              if ( pwnd->head.pti == gptiCurrent )
                                  continue;
                            }
                            co_IntSendMessageTimeout( List[i],
@@ -2327,7 +2394,7 @@ NtUserMessageCall( HWND hWnd,
 
                            if ( parm.flags & BSF_IGNORECURRENTTASK )
                            {
-                              if ( pwnd->head.pti->MessageQueue == gptiCurrent->MessageQueue )
+                              if ( pwnd->head.pti == gptiCurrent )
                                  continue;
                            }
                            UserPostMessage(List[i], Msg, wParam, lParam);
@@ -2353,7 +2420,7 @@ NtUserMessageCall( HWND hWnd,
 
                            if ( parm.flags & BSF_IGNORECURRENTTASK )
                            {
-                              if ( pwnd->head.pti->MessageQueue == gptiCurrent->MessageQueue )
+                              if ( pwnd->head.pti == gptiCurrent )
                                  continue;
                            }
                            UserSendNotifyMessage(List[i], Msg, wParam, lParam);
@@ -2410,7 +2477,7 @@ NtUserMessageCall( HWND hWnd,
 
                         if ( parm.flags & BSF_IGNORECURRENTTASK )
                         {
-                           if ( pwnd->head.pti->MessageQueue == gptiCurrent->MessageQueue )
+                           if ( pwnd->head.pti == gptiCurrent )
                               continue;
                         }
                         co_IntSendMessageTimeout( List[i],
@@ -2464,7 +2531,7 @@ NtUserMessageCall( HWND hWnd,
 
                         if ( parm.flags & BSF_IGNORECURRENTTASK )
                         {
-                           if ( pwnd->head.pti->MessageQueue == gptiCurrent->MessageQueue )
+                           if ( pwnd->head.pti == gptiCurrent )
                               continue;
                         }
                         UserPostMessage(List[i], Msg, wParam, lParam);
@@ -2490,7 +2557,7 @@ NtUserMessageCall( HWND hWnd,
 
                         if ( parm.flags & BSF_IGNORECURRENTTASK )
                         {
-                           if ( pwnd->head.pti->MessageQueue == gptiCurrent->MessageQueue )
+                           if ( pwnd->head.pti == gptiCurrent )
                               continue;
                         }
                         UserSendNotifyMessage(List[i], Msg, wParam, lParam);
@@ -2624,13 +2691,15 @@ NtUserMessageCall( HWND hWnd,
                 CWP.message = Msg;
                 CWP.wParam  = wParam;
                 CWP.lParam  = lParam;
-                TRACE("WH_CALLWNDPROC: Hook %x NextHook %x\n", Hook, NextObj );
+                TRACE("WH_CALLWNDPROC: Hook %p NextHook %p\n", Hook, NextObj);
 
                 lResult = co_IntCallHookProc( Hook->HookId,
                                               HC_ACTION,
                                               ((ClientInfo->CI_flags & CI_CURTHPRHOOK) ? 1 : 0),
                                               (LPARAM)&CWP,
                                               Hook->Proc,
+                                              Hook->ihmod, 
+                                              Hook->offPfn,
                                               Hook->Ansi,
                                               &Hook->ModuleName);
             }
@@ -2648,6 +2717,8 @@ NtUserMessageCall( HWND hWnd,
                                               ((ClientInfo->CI_flags & CI_CURTHPRHOOK) ? 1 : 0),
                                               (LPARAM)&CWPR,
                                               Hook->Proc,
+                                              Hook->ihmod, 
+                                              Hook->offPfn,
                                               Hook->Ansi,
                                               &Hook->ModuleName);
             }
@@ -2660,6 +2731,8 @@ NtUserMessageCall( HWND hWnd,
     case FNID_DEFWINDOWPROC:
     case FNID_CALLWNDPROC:
     case FNID_CALLWNDPROCRET:
+    case FNID_SCROLLBAR:
+    case FNID_DESKTOP:
         if (ResultInfo)
         {
             _SEH2_TRY
@@ -2731,7 +2804,7 @@ NtUserWaitForInputIdle( IN HANDLE hProcess,
 
     Handles[0] = Process;
     Handles[1] = W32Process->InputIdleEvent;
-    Handles[2] = pti->MessageQueue->NewMessages; // pEventQueueServer; IntMsqSetWakeMask returns hEventQueueClient
+    Handles[2] = pti->pEventQueueServer; // IntMsqSetWakeMask returns hEventQueueClient
 
     if (!Handles[1])
     {
@@ -2750,7 +2823,7 @@ NtUserWaitForInputIdle( IN HANDLE hProcess,
        pti->pClientInfo->dwTIFlags = pti->TIF_flags;
     }
 
-    TRACE("WFII: ppi 0x%x\n",W32Process);
+    TRACE("WFII: ppi %p\n", W32Process);
     TRACE("WFII: waiting for %p\n", Handles[1] );
     do
     {