Avoid using GetFastQueue16 from USER.

diff --git a/dlls/x11drv/desktop.c b/dlls/x11drv/desktop.c
index ff57b37..aaa0f7b 100644
--- a/dlls/x11drv/desktop.c
+++ b/dlls/x11drv/desktop.c
@@ -9,6 +9,7 @@
 
 #include "ts_xlib.h"
 
+#include "wine/winuser16.h"
 #include "win.h"
 #include "x11drv.h"
 #include "debugtools.h"
@@ -54,7 +55,7 @@
 
     /* patch the desktop window queue to point to our queue */
     win = WIN_FindWndPtr( hwnd );
-    win->hmemTaskQ = GetFastQueue16();
+    win->hmemTaskQ = InitThreadInput16( 0, 0 );
     X11DRV_register_window( display, hwnd, win->pDriverData );
     WIN_ReleaseWndPtr( win );
 
diff --git a/include/queue.h b/include/queue.h
index f57d180..b43eb16 100644
--- a/include/queue.h
+++ b/include/queue.h
@@ -63,14 +63,13 @@
 HWND PERQDATA_SetCaptureWnd( HWND hWndCapture, INT hittest );
 
 /* Message queue management methods */
+extern MESSAGEQUEUE *QUEUE_Current(void);
 extern MESSAGEQUEUE *QUEUE_Lock( HQUEUE16 hQueue );
 extern void QUEUE_Unlock( MESSAGEQUEUE *queue );
 extern BOOL QUEUE_IsExitingQueue( HQUEUE16 hQueue );
 extern void QUEUE_SetExitingQueue( HQUEUE16 hQueue );
-extern BOOL QUEUE_DeleteMsgQueue( HQUEUE16 hQueue );
+extern void QUEUE_DeleteMsgQueue(void);
 extern HTASK16 QUEUE_GetQueueTask( HQUEUE16 hQueue );
 extern void QUEUE_CleanupWindow( HWND hwnd );
 
-extern HQUEUE16 WINAPI InitThreadInput16( WORD unknown, WORD flags );
-
 #endif  /* __WINE_QUEUE_H */
diff --git a/include/wine/winuser16.h b/include/wine/winuser16.h
index 2829c1c..7fe3745 100644
--- a/include/wine/winuser16.h
+++ b/include/wine/winuser16.h
@@ -783,6 +783,7 @@
 BOOL16      WINAPI HiliteMenuItem16(HWND16,HMENU16,UINT16,UINT16);
 DWORD       WINAPI IconSize16(void);
 void        WINAPI InflateRect16(LPRECT16,INT16,INT16);
+HQUEUE16    WINAPI InitThreadInput16(WORD,WORD);
 BOOL16      WINAPI InSendMessage16(void);
 BOOL16      WINAPI InsertMenu16(HMENU16,UINT16,UINT16,UINT16,SEGPTR);
 BOOL16      WINAPI InsertMenuItem16(HMENU16,UINT16,BOOL16,const MENUITEMINFO16*);
diff --git a/windows/clipboard.c b/windows/clipboard.c
index af2f798..99901af 100644
--- a/windows/clipboard.c
+++ b/windows/clipboard.c
@@ -131,7 +131,7 @@
        * clipboard in order to update data in response to this message.
        */
 #if 0
-      MESSAGEQUEUE *queue = QUEUE_Lock( GetFastQueue16() );
+      MESSAGEQUEUE *queue = QUEUE_Current();
       
       if ( queue
            && queue->smWaiting
@@ -139,8 +139,6 @@
            && queue->smWaiting->hSrcQueue
          )
   	bIsLocked = FALSE;
-        
-      QUEUE_Unlock( queue );
 #else
       /* FIXME: queue check no longer possible */
       bIsLocked = FALSE;
diff --git a/windows/focus.c b/windows/focus.c
index 9a32fcc..4820429 100644
--- a/windows/focus.c
+++ b/windows/focus.c
@@ -64,7 +64,7 @@
     BOOL16 bRet = 0;
 
     /* Get the messageQ for the current thread */
-    if (!(pCurMsgQ = (MESSAGEQUEUE *)QUEUE_Lock( GetFastQueue16() )))
+    if (!(pCurMsgQ = QUEUE_Current()))
     {
         WARN("\tCurrent message queue not found. Exiting!\n" );
         goto CLEANUP;
@@ -149,8 +149,6 @@
     /* Unlock the queues before returning */
     if ( pMsgQ )
         QUEUE_Unlock( pMsgQ );
-    if ( pCurMsgQ )
-        QUEUE_Unlock( pCurMsgQ );
 
     WIN_ReleaseWndPtr(wndPtr);
     return bRet ? hWndFocus : 0;
@@ -172,19 +170,14 @@
 HWND WINAPI GetFocus(void)
 {
     MESSAGEQUEUE *pCurMsgQ = 0;
-    HWND hwndFocus = 0;
 
     /* Get the messageQ for the current thread */
-    if (!(pCurMsgQ = (MESSAGEQUEUE *)QUEUE_Lock( GetFastQueue16() )))
+    if (!(pCurMsgQ = QUEUE_Current()))
     {
         WARN("\tCurrent message queue not found. Exiting!\n" );
         return 0;
     }
 
     /* Get the current focus from the perQ data of the current message Q */
-    hwndFocus = PERQDATA_GetFocusWnd( pCurMsgQ->pQData );
-
-    QUEUE_Unlock( pCurMsgQ );
-
-    return hwndFocus;
+    return PERQDATA_GetFocusWnd( pCurMsgQ->pQData );
 }
diff --git a/windows/hook.c b/windows/hook.c
index ce2441b..d0cb579 100644
--- a/windows/hook.c
+++ b/windows/hook.c
@@ -835,16 +835,14 @@
  *
  * Get the first hook for a given type.
  */
-static HANDLE16 HOOK_GetHook( INT16 id, HQUEUE16 hQueue )
+static HANDLE16 HOOK_GetHook( INT16 id )
 {
     MESSAGEQUEUE *queue;
     HANDLE16 hook = 0;
 
-    if ((queue = (MESSAGEQUEUE *)QUEUE_Lock( hQueue )) != NULL)
+    if ((queue = QUEUE_Current()) != NULL)
         hook = queue->hooks[id - WH_MINHOOK];
     if (!hook) hook = HOOK_systemHooks[id - WH_MINHOOK];
-
-    QUEUE_Unlock( queue );
     return hook;
 }
 
@@ -870,7 +868,7 @@
                   id, (UINT)proc, hModule, dwThreadId );
 
     /* Create task queue if none present */
-    GetFastQueue16();
+    InitThreadInput16( 0, 0 );
 
     if (id == WH_JOURNALPLAYBACK) EnableHardwareInput16(FALSE);
 
@@ -1018,7 +1016,7 @@
 
     /* Now call it */
 
-    if (!(queue = (MESSAGEQUEUE *)QUEUE_Lock( GetFastQueue16() ))) return 0;
+    if (!(queue = QUEUE_Current())) return 0;
     prevHook = queue->hCurHook;
     queue->hCurHook = hook;
     data->flags |= HOOK_INUSE;
@@ -1047,8 +1045,6 @@
     data->flags &= ~HOOK_INUSE;
     queue->hCurHook = prevHook;
 
-    QUEUE_Unlock( queue );
-
     if (UnMapFunc)
       UnMapFunc( data->id, code, wParamOrig, lParamOrig, wParam, lParam );
 
@@ -1068,10 +1064,7 @@
  */
 BOOL HOOK_IsHooked( INT16 id )
 {
-    /* Hmmm. Use GetThreadQueue(0) instead of GetFastQueue() here to 
-       avoid queue being created if someone wants to merely check ... */
-
-    return HOOK_GetHook( id, GetThreadQueue16(0) ) != 0;
+    return HOOK_GetHook( id ) != 0;
 }
 
 
@@ -1085,7 +1078,7 @@
 {
     HANDLE16 hook; 
 
-    if (!(hook = HOOK_GetHook( id, GetFastQueue16() ))) return 0;
+    if (!(hook = HOOK_GetHook( id ))) return 0;
     if (!(hook = HOOK_FindValidHook(hook))) return 0;
     return HOOK_CallHook( hook, HOOK_WIN16, code, wParam, lParam );
 }
@@ -1100,7 +1093,7 @@
 {
     HANDLE16 hook; 
 
-    if (!(hook = HOOK_GetHook( id, GetFastQueue16() ))) return 0;
+    if (!(hook = HOOK_GetHook( id ))) return 0;
     if (!(hook = HOOK_FindValidHook(hook))) return 0;
     return HOOK_CallHook( hook, HOOK_WIN32A, code, wParam, lParam );
 }
@@ -1115,7 +1108,7 @@
 {
     HANDLE16 hook; 
 
-    if (!(hook = HOOK_GetHook( id, GetFastQueue16() ))) return 0;
+    if (!(hook = HOOK_GetHook( id ))) return 0;
     if (!(hook = HOOK_FindValidHook(hook))) return 0;
     return HOOK_CallHook( hook, HOOK_WIN32W, code, wParam,
 			  lParam );
@@ -1123,35 +1116,6 @@
 
 
 /***********************************************************************
- *           HOOK_ResetQueueHooks
- */
-void HOOK_ResetQueueHooks( HQUEUE16 hQueue )
-{
-    MESSAGEQUEUE *queue;
-
-    if ((queue = (MESSAGEQUEUE *)QUEUE_Lock( hQueue )) != NULL)
-    {
-	HOOKDATA*	data;
-	HHOOK		hook;
-	int		id;
-	for( id = WH_MINHOOK; id <= WH_MAXHOOK; id++ )
-	{
-	    hook = queue->hooks[id - WH_MINHOOK];
-	    while( hook )
-	    {
-	        if( (data = (HOOKDATA *)USER_HEAP_LIN_ADDR(hook)) )
-	        {
-		  data->ownerQueue = hQueue;
-		  hook = data->next;
-		} else break;
-	    }
-	}
-
-        QUEUE_Unlock( queue );
-    }
-}
-
-/***********************************************************************
  *	     HOOK_FreeModuleHooks
  */
 void HOOK_FreeModuleHooks( HMODULE16 hModule )
@@ -1183,9 +1147,9 @@
 /***********************************************************************
  *	     HOOK_FreeQueueHooks
  */
-void HOOK_FreeQueueHooks( HQUEUE16 hQueue )
+void HOOK_FreeQueueHooks(void)
 {
-  /* remove all hooks registered by this queue */
+  /* remove all hooks registered by the current queue */
 
   HOOKDATA*	hptr = NULL;
   HHOOK 	hook, next;
@@ -1193,13 +1157,13 @@
 
   for( id = WH_MINHOOK; id <= WH_MAXHOOK; id++ )
     {
-       hook = HOOK_GetHook( id, hQueue );
+       hook = HOOK_GetHook( id );
        while( hook )
 	{
 	  next = HOOK_GetNextHook(hook);
 
 	  hptr = (HOOKDATA *)USER_HEAP_LIN_ADDR(hook);
-	  if( hptr && hptr->ownerQueue == hQueue )
+	  if( hptr && hptr->ownerQueue )
 	    {
 	      hptr->flags &= HOOK_MAPTYPE;
 	      HOOK_RemoveHook(hook);
@@ -1287,7 +1251,7 @@
  */
 BOOL WINAPI UnhookWindowsHook( INT id, HOOKPROC proc )
 {
-    HANDLE16 hook = HOOK_GetHook( id, GetFastQueue16() );
+    HANDLE16 hook = HOOK_GetHook( id );
 
     TRACE("%d %08lx\n", id, (DWORD)proc );
 
@@ -1373,12 +1337,9 @@
     /* Note: the *hhook parameter is never used, since we rely on the
      * current hook value from the task queue to find the next hook. */
     MESSAGEQUEUE *queue;
-    LRESULT ret;
 
-    if (!(queue = (MESSAGEQUEUE *)QUEUE_Lock( GetFastQueue16() ))) return 0;
-    ret = CallNextHookEx16( queue->hCurHook, code, wParam, lParam );
-    QUEUE_Unlock( queue );
-    return ret;
+    if (!(queue = QUEUE_Current())) return 0;
+    return CallNextHookEx16( queue->hCurHook, code, wParam, lParam );
 }
 
 
diff --git a/windows/input.c b/windows/input.c
index b30b9f6..62c7518 100644
--- a/windows/input.c
+++ b/windows/input.c
@@ -499,7 +499,7 @@
     }
 
     /* Get the messageQ for the current thread */
-    if (!(pCurMsgQ = (MESSAGEQUEUE *)QUEUE_Lock( GetFastQueue16() )))
+    if (!(pCurMsgQ = QUEUE_Current()))
     {
         WARN_(win)("\tCurrent message queue not found. Exiting!\n" );
         goto CLEANUP;
@@ -533,9 +533,7 @@
     /* Unlock the queues before returning */
     if ( pMsgQ )
         QUEUE_Unlock( pMsgQ );
-    if ( pCurMsgQ )
-        QUEUE_Unlock( pCurMsgQ );
-    
+
     WIN_ReleaseWndPtr(wndPtr);
     return capturePrev;
 }
diff --git a/windows/message.c b/windows/message.c
index 47d410d..7658e52 100644
--- a/windows/message.c
+++ b/windows/message.c
@@ -684,7 +684,7 @@
 static void handle_sent_message( MSG *msg, int type, ULONG_PTR extra_info )
 {
     LRESULT result = 0;
-    MESSAGEQUEUE *queue = QUEUE_Lock( GetFastQueue16() );
+    MESSAGEQUEUE *queue = QUEUE_Current();
     ULONG_PTR old_extra_info = queue->GetMessageExtraInfoVal; /* save ExtraInfo */
     WND *wndPtr = WIN_FindWndPtr( msg->hwnd );
 
@@ -716,7 +716,6 @@
 
     queue->GetMessageExtraInfoVal = old_extra_info;  /* Restore extra info */
     WIN_ReleaseWndPtr(wndPtr);
-    QUEUE_Unlock( queue );
 
     SERVER_START_REQ( reply_message )
     {
@@ -861,12 +860,10 @@
 static int wait_queue_bits( WORD bits, DWORD timeout )
 {
     MESSAGEQUEUE *queue;
-    HQUEUE16 hQueue;
 
-    TRACE_(msg)("q %04x waiting for %04x\n", GetFastQueue16(), bits);
+    if (!(queue = QUEUE_Current())) return 0;
 
-    hQueue = GetFastQueue16();
-    if (!(queue = QUEUE_Lock( hQueue ))) return 0;
+    TRACE("q %04x waiting for %04x\n", queue->self, bits);
 
     for (;;)
     {
@@ -889,7 +886,6 @@
         if (changed_bits & bits)
         {
             /* One of the bits is set; we can return */
-            QUEUE_Unlock( queue );
             return 1;
         }
         if (wake_bits & QS_SENDMESSAGE)
@@ -1179,12 +1175,11 @@
 
     WIN_RestoreWndsLock(iWndsLocks);
 
-    if ((msgQueue = QUEUE_Lock( GetFastQueue16() )))
+    if ((msgQueue = QUEUE_Current()))
     {
         msgQueue->GetMessageTimeVal      = msg.time;
         msgQueue->GetMessagePosVal       = MAKELONG( msg.pt.x, msg.pt.y );
         msgQueue->GetMessageExtraInfoVal = extra_info;
-        QUEUE_Unlock( msgQueue );
     }
 
       /* We got a message */
@@ -1953,7 +1948,6 @@
 {
     HANDLE handles[MAXIMUM_WAIT_OBJECTS];
     DWORD i, ret;
-    HQUEUE16 hQueue = GetFastQueue16();
     MESSAGEQUEUE *msgQueue;
 
     if (count > MAXIMUM_WAIT_OBJECTS-1)
@@ -1962,7 +1956,7 @@
         return WAIT_FAILED;
     }
 
-    if (!(msgQueue = QUEUE_Lock( hQueue ))) return WAIT_FAILED;
+    if (!(msgQueue = QUEUE_Current())) return WAIT_FAILED;
 
     /* set the queue mask */
     SERVER_START_REQ( set_queue_mask )
@@ -1987,7 +1981,6 @@
     else
         ret = WaitForMultipleObjectsEx( count+1, handles, flags & MWMO_WAITALL,
                                         timeout, flags & MWMO_ALERTABLE );
-    QUEUE_Unlock( msgQueue );
     return ret;
 }
 
diff --git a/windows/queue.c b/windows/queue.c
index d68d402..4f9fd73 100644
--- a/windows/queue.c
+++ b/windows/queue.c
@@ -214,15 +214,13 @@
     PERQUEUEDATA *pQData;
     HWND hWndCapture;
 
-    if (!(queue = QUEUE_Lock( GetFastQueue16() ))) return 0;
+    if (!(queue = QUEUE_Current())) return 0;
     pQData = queue->pQData;
 
     EnterCriticalSection( &pQData->cSection );
     hWndCapture = pQData->hWndCapture;
     *hittest = pQData->nCaptureHT;
     LeaveCriticalSection( &pQData->cSection );
-
-    QUEUE_Unlock( queue );
     return hWndCapture;
 }
 
@@ -238,7 +236,7 @@
     PERQUEUEDATA *pQData;
     HWND hWndCapturePrv;
 
-    if (!(queue = QUEUE_Lock( GetFastQueue16() ))) return 0;
+    if (!(queue = QUEUE_Current())) return 0;
     pQData = queue->pQData;
 
     EnterCriticalSection( &pQData->cSection );
@@ -246,8 +244,6 @@
     pQData->hWndCapture = hWndCapture;
     pQData->nCaptureHT = hittest;
     LeaveCriticalSection( &pQData->cSection );
-
-    QUEUE_Unlock( queue );
     return hWndCapturePrv;
 }
 
@@ -280,6 +276,31 @@
 
 
 /***********************************************************************
+ *	     QUEUE_Current
+ *
+ * Get the current thread queue, creating it if required.
+ * QUEUE_Unlock is not needed since the queue can only be deleted by
+ * the current thread anyway.
+ */
+MESSAGEQUEUE *QUEUE_Current(void)
+{
+    MESSAGEQUEUE *queue;
+    HQUEUE16 hQueue;
+
+    if (!(hQueue = GetThreadQueue16(0)))
+    {
+        if (!(hQueue = InitThreadInput16( 0, 0 ))) return NULL;
+    }
+
+    if ((queue = GlobalLock16( hQueue )))
+    {
+        if (queue->magic != QUEUE_MAGIC) queue = NULL;
+    }
+    return queue;
+}
+
+
+/***********************************************************************
  *	     QUEUE_Unlock
  *
  * Use with QUEUE_Lock to get a thread safe access to message queue
@@ -378,16 +399,19 @@
  * Note: We need to mask asynchronous events to make sure PostMessage works
  * even in the signal handler.
  */
-BOOL QUEUE_DeleteMsgQueue( HQUEUE16 hQueue )
+void QUEUE_DeleteMsgQueue(void)
 {
-    MESSAGEQUEUE * msgQueue = QUEUE_Lock(hQueue);
+    HQUEUE16 hQueue = GetThreadQueue16(0);
+    MESSAGEQUEUE * msgQueue;
 
-    TRACE_(msg)("(): Deleting message queue %04x\n", hQueue);
+    if (!hQueue) return;  /* thread doesn't have a queue */
 
-    if (!hQueue || !msgQueue)
+    TRACE("(): Deleting message queue %04x\n", hQueue);
+
+    if (!(msgQueue = QUEUE_Lock(hQueue)))
     {
-	ERR_(msg)("invalid argument.\n");
-	return 0;
+        ERR("invalid thread queue\n");
+        return;
     }
 
     msgQueue->magic = 0;
@@ -407,12 +431,11 @@
     msgQueue->self = 0;
 
     HeapUnlock( GetProcessHeap() );
+    SetThreadQueue16( 0, 0 );
 
     /* free up resource used by MESSAGEQUEUE structure */
     msgQueue->lockCount--;
     QUEUE_Unlock( msgQueue );
-    
-    return 1;
 }
 
 
@@ -534,10 +557,6 @@
 {
     /* now obsolete the message queue will be expanded dynamically
      as necessary */
-
-    /* access the queue to create it if it's not existing */
-    GetFastQueue16();
-
     return TRUE;
 }
 
@@ -546,16 +565,9 @@
  */
 HQUEUE16 WINAPI InitThreadInput16( WORD unknown, WORD flags )
 {
-    HQUEUE16 hQueue;
     MESSAGEQUEUE *queuePtr;
+    HQUEUE16 hQueue = NtCurrentTeb()->queue;
 
-    TEB *teb = NtCurrentTeb();
-
-    if (!teb)
-        return 0;
-
-    hQueue = teb->queue;
-    
     if ( !hQueue )
     {
         /* Create thread message queue */
@@ -571,7 +583,7 @@
 
         HeapLock( GetProcessHeap() );  /* FIXME: a bit overkill */
         SetThreadQueue16( 0, hQueue );
-        teb->queue = hQueue;
+        NtCurrentTeb()->queue = hQueue;
         HeapUnlock( GetProcessHeap() );
         
         QUEUE_Unlock( queuePtr );
@@ -656,13 +668,9 @@
 DWORD WINAPI GetMessagePos(void)
 {
     MESSAGEQUEUE *queue;
-    DWORD ret;
 
-    if (!(queue = QUEUE_Lock( GetFastQueue16() ))) return 0;
-    ret = queue->GetMessagePosVal;
-    QUEUE_Unlock( queue );
-
-    return ret;
+    if (!(queue = QUEUE_Current())) return 0;
+    return queue->GetMessagePosVal;
 }
 
 
@@ -689,13 +697,9 @@
 LONG WINAPI GetMessageTime(void)
 {
     MESSAGEQUEUE *queue;
-    LONG ret;
 
-    if (!(queue = QUEUE_Lock( GetFastQueue16() ))) return 0;
-    ret = queue->GetMessageTimeVal;
-    QUEUE_Unlock( queue );
-    
-    return ret;
+    if (!(queue = QUEUE_Current())) return 0;
+    return queue->GetMessageTimeVal;
 }
 
 
@@ -706,13 +710,9 @@
 LONG WINAPI GetMessageExtraInfo(void)
 {
     MESSAGEQUEUE *queue;
-    LONG ret;
 
-    if (!(queue = QUEUE_Lock( GetFastQueue16() ))) return 0;
-    ret = queue->GetMessageExtraInfoVal;
-    QUEUE_Unlock( queue );
-
-    return ret;
+    if (!(queue = QUEUE_Current())) return 0;
+    return queue->GetMessageExtraInfoVal;
 }
 
 
diff --git a/windows/timer.c b/windows/timer.c
index 47b3a67..9163dff 100644
--- a/windows/timer.c
+++ b/windows/timer.c
@@ -160,7 +160,7 @@
       /* Add the timer */
 
     pTimer->hwnd    = hwnd;
-    pTimer->hq      = GetFastQueue16();
+    pTimer->hq      = InitThreadInput16( 0, 0 );
     pTimer->msg     = sys ? WM_SYSTIMER : WM_TIMER;
     pTimer->id      = id;
     pTimer->timeout = timeout;
diff --git a/windows/user.c b/windows/user.c
index 88ee059..3a28b5f 100644
--- a/windows/user.c
+++ b/windows/user.c
@@ -83,7 +83,7 @@
     INT_SetPMHandler( 0, INT_GetPMHandler( 0xff ) );
 
     /* Create task message queue */
-    if ( !GetFastQueue16() ) return 0;
+    if ( !InitThreadInput16( 0, 0 ) ) return 0;
 
     return 1;
 }
diff --git a/windows/win.c b/windows/win.c
index 9d38ce1..e97fe4f 100644
--- a/windows/win.c
+++ b/windows/win.c
@@ -769,7 +769,7 @@
     wndPtr->hwndSelf       = hwnd;
     wndPtr->hInstance      = cs->hInstance;
     wndPtr->text           = NULL;
-    wndPtr->hmemTaskQ      = GetFastQueue16();
+    wndPtr->hmemTaskQ      = InitThreadInput16( 0, 0 );
     wndPtr->hrgnUpdate     = 0;
     wndPtr->hrgnWnd        = 0;
     wndPtr->hwndLastActive = hwnd;
diff --git a/windows/winpos.c b/windows/winpos.c
index 41aeeb6..8b36e61 100644
--- a/windows/winpos.c
+++ b/windows/winpos.c
@@ -772,20 +772,16 @@
 HWND WINAPI GetActiveWindow(void)
 {
     MESSAGEQUEUE *pCurMsgQ = 0;
-    HWND hwndActive = 0;
 
     /* Get the messageQ for the current thread */
-    if (!(pCurMsgQ = (MESSAGEQUEUE *)QUEUE_Lock( GetFastQueue16() )))
+    if (!(pCurMsgQ = QUEUE_Current()))
 {
         WARN("\tCurrent message queue not found. Exiting!\n" );
         return 0;
     }
 
     /* Return the current active window from the perQ data of the current message Q */
-    hwndActive = PERQDATA_GetActiveWnd( pCurMsgQ->pQData );
-
-    QUEUE_Unlock( pCurMsgQ );
-    return hwndActive;
+    return PERQDATA_GetActiveWnd( pCurMsgQ->pQData );
 }
 
 
@@ -825,7 +821,7 @@
     }
 
     /* Get the messageQ for the current thread */
-    if (!(pCurMsgQ = (MESSAGEQUEUE *)QUEUE_Lock( GetFastQueue16() )))
+    if (!(pCurMsgQ = QUEUE_Current()))
     {
         WARN("\tCurrent message queue not found. Exiting!\n" );
         goto CLEANUP;
@@ -855,8 +851,6 @@
     /* Unlock the queues before returning */
     if ( pMsgQ )
         QUEUE_Unlock( pMsgQ );
-    if ( pCurMsgQ )
-        QUEUE_Unlock( pCurMsgQ );
     
 end:
     WIN_ReleaseWndPtr(wndPtr);