- Unixware (Solaris) linker typo fixed
[wine.git] / windows / queue.c
blob3b88261e8b24c28702c7b967c313d1ee758fe775
1 /* * Message queues related functions
3 * Copyright 1993, 1994 Alexandre Julliard
4 */
6 #include <string.h>
7 #include <signal.h>
8 #include <assert.h>
9 #include "wine/winbase16.h"
10 #include "wine/winuser16.h"
11 #include "miscemu.h"
12 #include "syslevel.h"
13 #include "module.h"
14 #include "queue.h"
15 #include "task.h"
16 #include "win.h"
17 #include "clipboard.h"
18 #include "hook.h"
19 #include "heap.h"
20 #include "thread.h"
21 #include "process.h"
22 #include "debugtools.h"
23 #include "spy.h"
25 DECLARE_DEBUG_CHANNEL(msg)
26 DECLARE_DEBUG_CHANNEL(sendmsg)
28 #define MAX_QUEUE_SIZE 120 /* Max. size of a message queue */
30 static HQUEUE16 hFirstQueue = 0;
31 static HQUEUE16 hExitingQueue = 0;
32 static HQUEUE16 hmemSysMsgQueue = 0;
33 static MESSAGEQUEUE *sysMsgQueue = NULL;
34 static PERQUEUEDATA *pQDataWin16 = NULL; /* Global perQData for Win16 tasks */
36 static MESSAGEQUEUE *pMouseQueue = NULL; /* Queue for last mouse message */
37 static MESSAGEQUEUE *pKbdQueue = NULL; /* Queue for last kbd message */
39 HQUEUE16 hCursorQueue = 0;
40 HQUEUE16 hActiveQueue = 0;
43 /***********************************************************************
44 * PERQDATA_CreateInstance
46 * Creates an instance of a reference counted PERQUEUEDATA element
47 * for the message queue. perQData is stored globally for 16 bit tasks.
49 * Note: We don't implement perQdata exactly the same way Windows does.
50 * Each perQData element is reference counted since it may be potentially
51 * shared by multiple message Queues (via AttachThreadInput).
52 * We only store the current values for Active, Capture and focus windows
53 * currently.
55 PERQUEUEDATA * PERQDATA_CreateInstance( )
57 PERQUEUEDATA *pQData;
59 BOOL16 bIsWin16 = 0;
61 TRACE_(msg)("()\n");
63 /* Share a single instance of perQData for all 16 bit tasks */
64 if ( ( bIsWin16 = THREAD_IsWin16( NtCurrentTeb() ) ) )
66 /* If previously allocated, just bump up ref count */
67 if ( pQDataWin16 )
69 PERQDATA_Addref( pQDataWin16 );
70 return pQDataWin16;
74 /* Allocate PERQUEUEDATA from the system heap */
75 if (!( pQData = (PERQUEUEDATA *) HeapAlloc( SystemHeap, 0,
76 sizeof(PERQUEUEDATA) ) ))
77 return 0;
79 /* Initialize */
80 pQData->hWndCapture = pQData->hWndFocus = pQData->hWndActive = 0;
81 pQData->ulRefCount = 1;
82 pQData->nCaptureHT = HTCLIENT;
84 /* Note: We have an independent critical section for the per queue data
85 * since this may be shared by different threads. see AttachThreadInput()
87 InitializeCriticalSection( &pQData->cSection );
88 /* FIXME: not all per queue data critical sections should be global */
89 MakeCriticalSectionGlobal( &pQData->cSection );
91 /* Save perQData globally for 16 bit tasks */
92 if ( bIsWin16 )
93 pQDataWin16 = pQData;
95 return pQData;
99 /***********************************************************************
100 * PERQDATA_Addref
102 * Increment reference count for the PERQUEUEDATA instance
103 * Returns reference count for debugging purposes
105 ULONG PERQDATA_Addref( PERQUEUEDATA *pQData )
107 assert(pQData != 0 );
108 TRACE_(msg)("(): current refcount %lu ...\n", pQData->ulRefCount);
110 EnterCriticalSection( &pQData->cSection );
111 ++pQData->ulRefCount;
112 LeaveCriticalSection( &pQData->cSection );
114 return pQData->ulRefCount;
118 /***********************************************************************
119 * PERQDATA_Release
121 * Release a reference to a PERQUEUEDATA instance.
122 * Destroy the instance if no more references exist
123 * Returns reference count for debugging purposes
125 ULONG PERQDATA_Release( PERQUEUEDATA *pQData )
127 assert(pQData != 0 );
128 TRACE_(msg)("(): current refcount %lu ...\n",
129 (LONG)pQData->ulRefCount );
131 EnterCriticalSection( &pQData->cSection );
132 if ( --pQData->ulRefCount == 0 )
134 LeaveCriticalSection( &pQData->cSection );
135 DeleteCriticalSection( &pQData->cSection );
137 TRACE_(msg)("(): deleting PERQUEUEDATA instance ...\n" );
139 /* Deleting our global 16 bit perQData? */
140 if ( pQData == pQDataWin16 )
141 pQDataWin16 = 0;
143 /* Free the PERQUEUEDATA instance */
144 HeapFree( SystemHeap, 0, pQData );
146 return 0;
148 LeaveCriticalSection( &pQData->cSection );
150 return pQData->ulRefCount;
154 /***********************************************************************
155 * PERQDATA_GetFocusWnd
157 * Get the focus hwnd member in a threadsafe manner
159 HWND PERQDATA_GetFocusWnd( PERQUEUEDATA *pQData )
161 HWND hWndFocus;
162 assert(pQData != 0 );
164 EnterCriticalSection( &pQData->cSection );
165 hWndFocus = pQData->hWndFocus;
166 LeaveCriticalSection( &pQData->cSection );
168 return hWndFocus;
172 /***********************************************************************
173 * PERQDATA_SetFocusWnd
175 * Set the focus hwnd member in a threadsafe manner
177 HWND PERQDATA_SetFocusWnd( PERQUEUEDATA *pQData, HWND hWndFocus )
179 HWND hWndFocusPrv;
180 assert(pQData != 0 );
182 EnterCriticalSection( &pQData->cSection );
183 hWndFocusPrv = pQData->hWndFocus;
184 pQData->hWndFocus = hWndFocus;
185 LeaveCriticalSection( &pQData->cSection );
187 return hWndFocusPrv;
191 /***********************************************************************
192 * PERQDATA_GetActiveWnd
194 * Get the active hwnd member in a threadsafe manner
196 HWND PERQDATA_GetActiveWnd( PERQUEUEDATA *pQData )
198 HWND hWndActive;
199 assert(pQData != 0 );
201 EnterCriticalSection( &pQData->cSection );
202 hWndActive = pQData->hWndActive;
203 LeaveCriticalSection( &pQData->cSection );
205 return hWndActive;
209 /***********************************************************************
210 * PERQDATA_SetActiveWnd
212 * Set the active focus hwnd member in a threadsafe manner
214 HWND PERQDATA_SetActiveWnd( PERQUEUEDATA *pQData, HWND hWndActive )
216 HWND hWndActivePrv;
217 assert(pQData != 0 );
219 EnterCriticalSection( &pQData->cSection );
220 hWndActivePrv = pQData->hWndActive;
221 pQData->hWndActive = hWndActive;
222 LeaveCriticalSection( &pQData->cSection );
224 return hWndActivePrv;
228 /***********************************************************************
229 * PERQDATA_GetCaptureWnd
231 * Get the capture hwnd member in a threadsafe manner
233 HWND PERQDATA_GetCaptureWnd( PERQUEUEDATA *pQData )
235 HWND hWndCapture;
236 assert(pQData != 0 );
238 EnterCriticalSection( &pQData->cSection );
239 hWndCapture = pQData->hWndCapture;
240 LeaveCriticalSection( &pQData->cSection );
242 return hWndCapture;
246 /***********************************************************************
247 * PERQDATA_SetCaptureWnd
249 * Set the capture hwnd member in a threadsafe manner
251 HWND PERQDATA_SetCaptureWnd( PERQUEUEDATA *pQData, HWND hWndCapture )
253 HWND hWndCapturePrv;
254 assert(pQData != 0 );
256 EnterCriticalSection( &pQData->cSection );
257 hWndCapturePrv = pQData->hWndCapture;
258 pQData->hWndCapture = hWndCapture;
259 LeaveCriticalSection( &pQData->cSection );
261 return hWndCapturePrv;
265 /***********************************************************************
266 * PERQDATA_GetCaptureInfo
268 * Get the capture info member in a threadsafe manner
270 INT16 PERQDATA_GetCaptureInfo( PERQUEUEDATA *pQData )
272 INT16 nCaptureHT;
273 assert(pQData != 0 );
275 EnterCriticalSection( &pQData->cSection );
276 nCaptureHT = pQData->nCaptureHT;
277 LeaveCriticalSection( &pQData->cSection );
279 return nCaptureHT;
283 /***********************************************************************
284 * PERQDATA_SetCaptureInfo
286 * Set the capture info member in a threadsafe manner
288 INT16 PERQDATA_SetCaptureInfo( PERQUEUEDATA *pQData, INT16 nCaptureHT )
290 INT16 nCaptureHTPrv;
291 assert(pQData != 0 );
293 EnterCriticalSection( &pQData->cSection );
294 nCaptureHTPrv = pQData->nCaptureHT;
295 pQData->nCaptureHT = nCaptureHT;
296 LeaveCriticalSection( &pQData->cSection );
298 return nCaptureHTPrv;
302 /***********************************************************************
303 * QUEUE_Lock
305 * Function for getting a 32 bit pointer on queue strcture. For thread
306 * safeness programmers should use this function instead of GlobalLock to
307 * retrieve a pointer on the structure. QUEUE_Unlock should also be called
308 * when access to the queue structure is not required anymore.
310 MESSAGEQUEUE *QUEUE_Lock( HQUEUE16 hQueue )
312 MESSAGEQUEUE *queue;
314 HeapLock( SystemHeap ); /* FIXME: a bit overkill */
315 queue = GlobalLock16( hQueue );
316 if ( !queue || (queue->magic != QUEUE_MAGIC) )
318 HeapUnlock( SystemHeap );
319 return NULL;
322 queue->lockCount++;
323 HeapUnlock( SystemHeap );
324 return queue;
328 /***********************************************************************
329 * QUEUE_Unlock
331 * Use with QUEUE_Lock to get a thread safe access to message queue
332 * structure
334 void QUEUE_Unlock( MESSAGEQUEUE *queue )
336 if (queue)
338 HeapLock( SystemHeap ); /* FIXME: a bit overkill */
340 if ( --queue->lockCount == 0 )
342 DeleteCriticalSection ( &queue->cSection );
343 if (queue->hEvent)
344 CloseHandle( queue->hEvent );
345 GlobalFree16( queue->self );
348 HeapUnlock( SystemHeap );
353 /***********************************************************************
354 * QUEUE_DumpQueue
356 void QUEUE_DumpQueue( HQUEUE16 hQueue )
358 MESSAGEQUEUE *pq;
360 if (!(pq = (MESSAGEQUEUE*) QUEUE_Lock( hQueue )) )
362 WARN_(msg)("%04x is not a queue handle\n", hQueue );
363 return;
366 DPRINTF( "next: %12.4x Intertask SendMessage:\n"
367 "thread: %10p ----------------------\n"
368 "firstMsg: %8p smWaiting: %10p\n"
369 "lastMsg: %8p smPending: %10p\n"
370 "msgCount: %8.4x smProcessing: %10p\n"
371 "lockCount: %7.4x\n"
372 "wWinVer: %9.4x\n"
373 "paints: %10.4x\n"
374 "timers: %10.4x\n"
375 "wakeBits: %8.4x\n"
376 "wakeMask: %8.4x\n"
377 "hCurHook: %8.4x\n",
378 pq->next, pq->teb, pq->firstMsg, pq->smWaiting, pq->lastMsg,
379 pq->smPending, pq->msgCount, pq->smProcessing,
380 (unsigned)pq->lockCount, pq->wWinVersion,
381 pq->wPaintCount, pq->wTimerCount,
382 pq->wakeBits, pq->wakeMask, pq->hCurHook);
384 QUEUE_Unlock( pq );
388 /***********************************************************************
389 * QUEUE_WalkQueues
391 void QUEUE_WalkQueues(void)
393 char module[10];
394 HQUEUE16 hQueue = hFirstQueue;
396 DPRINTF( "Queue Msgs Thread Task Module\n" );
397 while (hQueue)
399 MESSAGEQUEUE *queue = (MESSAGEQUEUE *)QUEUE_Lock( hQueue );
400 if (!queue)
402 WARN_(msg)("Bad queue handle %04x\n", hQueue );
403 return;
405 if (!GetModuleName16( queue->teb->process->task, module, sizeof(module )))
406 strcpy( module, "???" );
407 DPRINTF( "%04x %4d %p %04x %s\n", hQueue,queue->msgCount,
408 queue->teb, queue->teb->process->task, module );
409 hQueue = queue->next;
410 QUEUE_Unlock( queue );
412 DPRINTF( "\n" );
416 /***********************************************************************
417 * QUEUE_IsExitingQueue
419 BOOL QUEUE_IsExitingQueue( HQUEUE16 hQueue )
421 return (hExitingQueue && (hQueue == hExitingQueue));
425 /***********************************************************************
426 * QUEUE_SetExitingQueue
428 void QUEUE_SetExitingQueue( HQUEUE16 hQueue )
430 hExitingQueue = hQueue;
434 /***********************************************************************
435 * QUEUE_CreateMsgQueue
437 * Creates a message queue. Doesn't link it into queue list!
439 static HQUEUE16 QUEUE_CreateMsgQueue( BOOL16 bCreatePerQData )
441 HQUEUE16 hQueue;
442 MESSAGEQUEUE * msgQueue;
443 TDB *pTask = (TDB *)GlobalLock16( GetCurrentTask() );
445 TRACE_(msg)("(): Creating message queue...\n");
447 if (!(hQueue = GlobalAlloc16( GMEM_FIXED | GMEM_ZEROINIT,
448 sizeof(MESSAGEQUEUE) )))
449 return 0;
451 msgQueue = (MESSAGEQUEUE *) GlobalLock16( hQueue );
452 if ( !msgQueue )
453 return 0;
455 msgQueue->self = hQueue;
456 msgQueue->wakeBits = msgQueue->changeBits = 0;
457 msgQueue->wWinVersion = pTask ? pTask->version : 0;
459 InitializeCriticalSection( &msgQueue->cSection );
460 MakeCriticalSectionGlobal( &msgQueue->cSection );
462 /* Create an Event object for waiting on message, used by win32 thread
463 only */
464 if ( !THREAD_IsWin16( NtCurrentTeb() ) )
466 msgQueue->hEvent = CreateEventA( NULL, FALSE, FALSE, NULL);
468 if (msgQueue->hEvent == 0)
470 WARN_(msg)("CreateEventA is not able to create an event object");
471 return 0;
473 msgQueue->hEvent = ConvertToGlobalHandle( msgQueue->hEvent );
475 else
476 msgQueue->hEvent = 0;
478 msgQueue->lockCount = 1;
479 msgQueue->magic = QUEUE_MAGIC;
481 /* Create and initialize our per queue data */
482 msgQueue->pQData = bCreatePerQData ? PERQDATA_CreateInstance() : NULL;
484 return hQueue;
488 /***********************************************************************
489 * QUEUE_FlushMessage
491 * Try to reply to all pending sent messages on exit.
493 static void QUEUE_FlushMessages( MESSAGEQUEUE *queue )
495 SMSG *smsg;
496 MESSAGEQUEUE *senderQ = 0;
498 if( queue )
500 EnterCriticalSection( &queue->cSection );
502 /* empty the list of pending SendMessage waiting to be received */
503 while (queue->smPending)
505 smsg = QUEUE_RemoveSMSG( queue, SM_PENDING_LIST, 0);
507 senderQ = (MESSAGEQUEUE*)QUEUE_Lock( smsg->hSrcQueue );
508 if ( !senderQ )
509 continue;
511 /* return 0, to unblock other thread */
512 smsg->lResult = 0;
513 smsg->flags |= SMSG_HAVE_RESULT;
514 QUEUE_SetWakeBit( senderQ, QS_SMRESULT);
516 QUEUE_Unlock( senderQ );
519 QUEUE_ClearWakeBit( queue, QS_SENDMESSAGE );
521 LeaveCriticalSection( &queue->cSection );
526 /***********************************************************************
527 * QUEUE_DeleteMsgQueue
529 * Unlinks and deletes a message queue.
531 * Note: We need to mask asynchronous events to make sure PostMessage works
532 * even in the signal handler.
534 BOOL QUEUE_DeleteMsgQueue( HQUEUE16 hQueue )
536 MESSAGEQUEUE * msgQueue = (MESSAGEQUEUE*)QUEUE_Lock(hQueue);
537 HQUEUE16 *pPrev;
539 TRACE_(msg)("(): Deleting message queue %04x\n", hQueue);
541 if (!hQueue || !msgQueue)
543 WARN_(msg)("invalid argument.\n");
544 return 0;
547 msgQueue->magic = 0;
549 if( hCursorQueue == hQueue ) hCursorQueue = 0;
550 if( hActiveQueue == hQueue ) hActiveQueue = 0;
552 /* flush sent messages */
553 QUEUE_FlushMessages( msgQueue );
555 HeapLock( SystemHeap ); /* FIXME: a bit overkill */
557 /* Release per queue data if present */
558 if ( msgQueue->pQData )
560 PERQDATA_Release( msgQueue->pQData );
561 msgQueue->pQData = 0;
564 /* remove the message queue from the global link list */
565 pPrev = &hFirstQueue;
566 while (*pPrev && (*pPrev != hQueue))
568 MESSAGEQUEUE *msgQ = (MESSAGEQUEUE*)GlobalLock16(*pPrev);
570 /* sanity check */
571 if ( !msgQ || (msgQ->magic != QUEUE_MAGIC) )
573 /* HQUEUE link list is corrupted, try to exit gracefully */
574 WARN_(msg)("HQUEUE link list corrupted!\n");
575 pPrev = 0;
576 break;
578 pPrev = &msgQ->next;
580 if (pPrev && *pPrev) *pPrev = msgQueue->next;
581 msgQueue->self = 0;
583 HeapUnlock( SystemHeap );
585 /* free up resource used by MESSAGEQUEUE strcture */
586 msgQueue->lockCount--;
587 QUEUE_Unlock( msgQueue );
589 return 1;
593 /***********************************************************************
594 * QUEUE_CreateSysMsgQueue
596 * Create the system message queue, and set the double-click speed.
597 * Must be called only once.
599 BOOL QUEUE_CreateSysMsgQueue( int size )
601 /* Note: We dont need perQ data for the system message queue */
602 if (!(hmemSysMsgQueue = QUEUE_CreateMsgQueue( FALSE )))
603 return FALSE;
605 sysMsgQueue = (MESSAGEQUEUE *) GlobalLock16( hmemSysMsgQueue );
606 return TRUE;
610 /***********************************************************************
611 * QUEUE_GetSysQueue
613 MESSAGEQUEUE *QUEUE_GetSysQueue(void)
615 return sysMsgQueue;
619 /***********************************************************************
620 * QUEUE_SetWakeBit
622 * See "Windows Internals", p.449
624 void QUEUE_SetWakeBit( MESSAGEQUEUE *queue, WORD bit )
626 TRACE_(msg)("queue = %04x (wm=%04x), bit = %04x\n",
627 queue->self, queue->wakeMask, bit );
629 if (bit & QS_MOUSE) pMouseQueue = queue;
630 if (bit & QS_KEY) pKbdQueue = queue;
631 queue->changeBits |= bit;
632 queue->wakeBits |= bit;
633 if (queue->wakeMask & bit)
635 queue->wakeMask = 0;
637 /* Wake up thread waiting for message */
638 if ( THREAD_IsWin16( queue->teb ) )
640 int iWndsLock = WIN_SuspendWndsLock();
641 PostEvent16( queue->teb->process->task );
642 WIN_RestoreWndsLock( iWndsLock );
644 else
646 SetEvent( queue->hEvent );
652 /***********************************************************************
653 * QUEUE_ClearWakeBit
655 void QUEUE_ClearWakeBit( MESSAGEQUEUE *queue, WORD bit )
657 queue->changeBits &= ~bit;
658 queue->wakeBits &= ~bit;
662 /***********************************************************************
663 * QUEUE_WaitBits
665 * See "Windows Internals", p.447
667 * return values:
668 * 0 if exit with timeout
669 * 1 otherwise
671 int QUEUE_WaitBits( WORD bits, DWORD timeout )
673 MESSAGEQUEUE *queue;
674 DWORD curTime = 0;
675 HQUEUE16 hQueue;
676 PDB * pdb;
678 TRACE_(msg)("q %04x waiting for %04x\n", GetFastQueue16(), bits);
680 if ( THREAD_IsWin16( NtCurrentTeb() ) && (timeout != INFINITE) )
681 curTime = GetTickCount();
683 hQueue = GetFastQueue16();
684 if (!(queue = (MESSAGEQUEUE *)QUEUE_Lock( hQueue ))) return 0;
686 pdb = PROCESS_Current();
688 for (;;)
690 if (queue->changeBits & bits)
692 /* One of the bits is set; we can return */
693 queue->wakeMask = 0;
694 QUEUE_Unlock( queue );
695 return 1;
697 if (queue->wakeBits & QS_SENDMESSAGE)
699 /* Process the sent message immediately */
701 queue->wakeMask = 0;
702 QUEUE_ReceiveMessage( queue );
703 continue; /* nested sm crux */
706 queue->wakeMask = bits | QS_SENDMESSAGE;
707 if(queue->changeBits & bits)
709 continue;
712 TRACE_(msg)("%04x) wakeMask is %04x, waiting\n", queue->self, queue->wakeMask);
714 if ( !THREAD_IsWin16( NtCurrentTeb() ) )
716 BOOL bHasWin16Lock;
717 DWORD dwlc;
719 if ( (bHasWin16Lock = _ConfirmWin16Lock()) )
721 TRACE_(msg)("bHasWin16Lock=TRUE\n");
722 ReleaseThunkLock( &dwlc );
726 if ( pdb->main_queue == INVALID_HANDLE_VALUE16 )
728 pdb->main_queue = hQueue;
730 if ( pdb->main_queue == hQueue )
732 SetEvent ( pdb->idle_event );
735 WaitForSingleObject( queue->hEvent, timeout );
737 if ( pdb->main_queue == hQueue )
739 ResetEvent ( pdb->idle_event );
742 if ( bHasWin16Lock )
744 RestoreThunkLock( dwlc );
747 else
749 SetEvent ( pdb->idle_event );
751 if ( timeout == INFINITE )
752 WaitEvent16( 0 ); /* win 16 thread, use WaitEvent */
753 else
755 /* check for timeout, then give control to other tasks */
756 if (GetTickCount() - curTime > timeout)
759 QUEUE_Unlock( queue );
760 return 0; /* exit with timeout */
762 Yield16();
769 /***********************************************************************
770 * QUEUE_AddSMSG
772 * This routine is called when a SMSG need to be added to one of the three
773 * SM list. (SM_PROCESSING_LIST, SM_PENDING_LIST, SM_WAITING_LIST)
775 BOOL QUEUE_AddSMSG( MESSAGEQUEUE *queue, int list, SMSG *smsg )
777 TRACE_(sendmsg)("queue=%x, list=%d, smsg=%p msg=%s\n", queue->self, list,
778 smsg, SPY_GetMsgName(smsg->msg));
780 switch (list)
782 case SM_PROCESSING_LIST:
783 /* don't need to be thread safe, only accessed by the
784 thread associated with the sender queue */
785 smsg->nextProcessing = queue->smProcessing;
786 queue->smProcessing = smsg;
787 break;
789 case SM_WAITING_LIST:
790 /* don't need to be thread safe, only accessed by the
791 thread associated with the receiver queue */
792 smsg->nextWaiting = queue->smWaiting;
793 queue->smWaiting = smsg;
794 break;
796 case SM_PENDING_LIST:
798 /* make it thread safe, could be accessed by the sender and
799 receiver thread */
800 SMSG **prev;
802 EnterCriticalSection( &queue->cSection );
803 smsg->nextPending = NULL;
804 prev = &queue->smPending;
805 while ( *prev )
806 prev = &(*prev)->nextPending;
807 *prev = smsg;
808 LeaveCriticalSection( &queue->cSection );
810 QUEUE_SetWakeBit( queue, QS_SENDMESSAGE );
811 break;
814 default:
815 WARN_(sendmsg)("Invalid list: %d", list);
816 break;
819 return TRUE;
823 /***********************************************************************
824 * QUEUE_RemoveSMSG
826 * This routine is called when a SMSG need to be remove from one of the three
827 * SM list. (SM_PROCESSING_LIST, SM_PENDING_LIST, SM_WAITING_LIST)
828 * If smsg == 0, remove the first smsg from the specified list
830 SMSG *QUEUE_RemoveSMSG( MESSAGEQUEUE *queue, int list, SMSG *smsg )
833 switch (list)
835 case SM_PROCESSING_LIST:
836 /* don't need to be thread safe, only accessed by the
837 thread associated with the sender queue */
839 /* if smsg is equal to null, it means the first in the list */
840 if (!smsg)
841 smsg = queue->smProcessing;
843 TRACE_(sendmsg)("queue=%x, list=%d, smsg=%p msg=%s\n", queue->self, list,
844 smsg, SPY_GetMsgName(smsg->msg));
845 /* In fact SM_PROCESSING_LIST is a stack, and smsg
846 should be always at the top of the list */
847 if ( (smsg != queue->smProcessing) || !queue->smProcessing )
849 ERR_(sendmsg)("smsg not at the top of Processing list, smsg=0x%p queue=0x%p", smsg, queue);
850 return 0;
852 else
854 queue->smProcessing = smsg->nextProcessing;
855 smsg->nextProcessing = 0;
857 return smsg;
859 case SM_WAITING_LIST:
860 /* don't need to be thread safe, only accessed by the
861 thread associated with the receiver queue */
863 /* if smsg is equal to null, it means the first in the list */
864 if (!smsg)
865 smsg = queue->smWaiting;
867 TRACE_(sendmsg)("queue=%x, list=%d, smsg=%p msg=%s\n", queue->self, list,
868 smsg, SPY_GetMsgName(smsg->msg));
869 /* In fact SM_WAITING_LIST is a stack, and smsg
870 should be always at the top of the list */
871 if ( (smsg != queue->smWaiting) || !queue->smWaiting )
873 ERR_(sendmsg)("smsg not at the top of Waiting list, smsg=0x%p queue=0x%p", smsg, queue);
874 return 0;
876 else
878 queue->smWaiting = smsg->nextWaiting;
879 smsg->nextWaiting = 0;
881 return smsg;
883 case SM_PENDING_LIST:
884 /* make it thread safe, could be accessed by the sender and
885 receiver thread */
886 EnterCriticalSection( &queue->cSection );
888 if (!smsg || !queue->smPending)
889 smsg = queue->smPending;
890 else
892 ERR_(sendmsg)("should always remove the top one in Pending list, smsg=0x%p queue=0x%p", smsg, queue);
893 LeaveCriticalSection( &queue->cSection );
894 return 0;
897 TRACE_(sendmsg)("queue=%x, list=%d, smsg=%p msg=%s\n", queue->self, list,
898 smsg, SPY_GetMsgName(smsg->msg));
900 queue->smPending = smsg->nextPending;
901 smsg->nextPending = 0;
903 /* if no more SMSG in Pending list, clear QS_SENDMESSAGE flag */
904 if (!queue->smPending)
905 QUEUE_ClearWakeBit( queue, QS_SENDMESSAGE );
907 LeaveCriticalSection( &queue->cSection );
908 return smsg;
910 default:
911 WARN_(sendmsg)("Invalid list: %d", list);
912 break;
915 return 0;
919 /***********************************************************************
920 * QUEUE_ReceiveMessage
922 * This routine is called when a sent message is waiting for the queue.
924 void QUEUE_ReceiveMessage( MESSAGEQUEUE *queue )
926 LRESULT result = 0;
927 SMSG *smsg;
928 MESSAGEQUEUE *senderQ;
930 TRACE_(sendmsg)("queue %04x\n", queue->self );
932 if ( !(queue->wakeBits & QS_SENDMESSAGE) && queue->smPending )
934 TRACE_(sendmsg)("\trcm: nothing to do\n");
935 return;
938 /* remove smsg on the top of the pending list and put it in the processing list */
939 smsg = QUEUE_RemoveSMSG(queue, SM_PENDING_LIST, 0);
940 QUEUE_AddSMSG(queue, SM_WAITING_LIST, smsg);
942 TRACE_(sendmsg)("RM: %s [%04x] (%04x -> %04x)\n",
943 SPY_GetMsgName(smsg->msg), smsg->msg, smsg->hSrcQueue, smsg->hDstQueue );
945 if (IsWindow( smsg->hWnd ))
947 WND *wndPtr = WIN_FindWndPtr( smsg->hWnd );
948 DWORD extraInfo = queue->GetMessageExtraInfoVal; /* save ExtraInfo */
950 /* use sender queue extra info value while calling the window proc */
951 senderQ = (MESSAGEQUEUE*)QUEUE_Lock( smsg->hSrcQueue );
952 if (senderQ)
954 queue->GetMessageExtraInfoVal = senderQ->GetMessageExtraInfoVal;
955 QUEUE_Unlock( senderQ );
958 /* call the right version of CallWindowProcXX */
959 if (smsg->flags & SMSG_WIN32)
961 TRACE_(sendmsg)("\trcm: msg is Win32\n" );
962 if (smsg->flags & SMSG_UNICODE)
963 result = CallWindowProcW( wndPtr->winproc,
964 smsg->hWnd, smsg->msg,
965 smsg->wParam, smsg->lParam );
966 else
967 result = CallWindowProcA( wndPtr->winproc,
968 smsg->hWnd, smsg->msg,
969 smsg->wParam, smsg->lParam );
971 else /* Win16 message */
972 result = CallWindowProc16( (WNDPROC16)wndPtr->winproc,
973 (HWND16) smsg->hWnd,
974 (UINT16) smsg->msg,
975 LOWORD (smsg->wParam),
976 smsg->lParam );
978 queue->GetMessageExtraInfoVal = extraInfo; /* Restore extra info */
979 WIN_ReleaseWndPtr(wndPtr);
980 TRACE_(sendmsg)("result = %08x\n", (unsigned)result );
982 else WARN_(sendmsg)("\trcm: bad hWnd\n");
985 /* set SMSG_SENDING_REPLY flag to tell ReplyMessage16, it's not
986 an early reply */
987 smsg->flags |= SMSG_SENDING_REPLY;
988 ReplyMessage( result );
990 TRACE_(sendmsg)("done! \n" );
995 /***********************************************************************
996 * QUEUE_AddMsg
998 * Add a message to the queue. Return FALSE if queue is full.
1000 BOOL QUEUE_AddMsg( HQUEUE16 hQueue, int type, MSG *msg, DWORD extraInfo )
1002 MESSAGEQUEUE *msgQueue;
1003 QMSG *qmsg;
1006 if (!(msgQueue = (MESSAGEQUEUE *)QUEUE_Lock( hQueue ))) return FALSE;
1008 /* allocate new message in global heap for now */
1009 if (!(qmsg = (QMSG *) HeapAlloc( SystemHeap, 0, sizeof(QMSG) ) ))
1011 QUEUE_Unlock( msgQueue );
1012 return 0;
1015 EnterCriticalSection( &msgQueue->cSection );
1017 /* Store message */
1018 qmsg->type = type;
1019 qmsg->msg = *msg;
1020 qmsg->extraInfo = extraInfo;
1022 /* insert the message in the link list */
1023 qmsg->nextMsg = 0;
1024 qmsg->prevMsg = msgQueue->lastMsg;
1026 if (msgQueue->lastMsg)
1027 msgQueue->lastMsg->nextMsg = qmsg;
1029 /* update first and last anchor in message queue */
1030 msgQueue->lastMsg = qmsg;
1031 if (!msgQueue->firstMsg)
1032 msgQueue->firstMsg = qmsg;
1034 msgQueue->msgCount++;
1036 LeaveCriticalSection( &msgQueue->cSection );
1038 QUEUE_SetWakeBit( msgQueue, QS_POSTMESSAGE );
1039 QUEUE_Unlock( msgQueue );
1041 return TRUE;
1046 /***********************************************************************
1047 * QUEUE_FindMsg
1049 * Find a message matching the given parameters. Return -1 if none available.
1051 QMSG* QUEUE_FindMsg( MESSAGEQUEUE * msgQueue, HWND hwnd, int first, int last )
1053 QMSG* qmsg;
1055 EnterCriticalSection( &msgQueue->cSection );
1057 if (!msgQueue->msgCount)
1058 qmsg = 0;
1059 else if (!hwnd && !first && !last)
1060 qmsg = msgQueue->firstMsg;
1061 else
1063 /* look in linked list for message matching first and last criteria */
1064 for (qmsg = msgQueue->firstMsg; qmsg; qmsg = qmsg->nextMsg)
1066 MSG *msg = &(qmsg->msg);
1068 if (!hwnd || (msg->hwnd == hwnd))
1070 if (!first && !last)
1071 break; /* found it */
1073 if ((msg->message >= first) && (!last || (msg->message <= last)))
1074 break; /* found it */
1079 LeaveCriticalSection( &msgQueue->cSection );
1081 return qmsg;
1086 /***********************************************************************
1087 * QUEUE_RemoveMsg
1089 * Remove a message from the queue (pos must be a valid position).
1091 void QUEUE_RemoveMsg( MESSAGEQUEUE * msgQueue, QMSG *qmsg )
1093 EnterCriticalSection( &msgQueue->cSection );
1095 /* set the linked list */
1096 if (qmsg->prevMsg)
1097 qmsg->prevMsg->nextMsg = qmsg->nextMsg;
1099 if (qmsg->nextMsg)
1100 qmsg->nextMsg->prevMsg = qmsg->prevMsg;
1102 if (msgQueue->firstMsg == qmsg)
1103 msgQueue->firstMsg = qmsg->nextMsg;
1105 if (msgQueue->lastMsg == qmsg)
1106 msgQueue->lastMsg = qmsg->prevMsg;
1108 /* deallocate the memory for the message */
1109 HeapFree( SystemHeap, 0, qmsg );
1111 msgQueue->msgCount--;
1112 if (!msgQueue->msgCount) msgQueue->wakeBits &= ~QS_POSTMESSAGE;
1114 LeaveCriticalSection( &msgQueue->cSection );
1118 /***********************************************************************
1119 * QUEUE_WakeSomeone
1121 * Wake a queue upon reception of a hardware event.
1123 static void QUEUE_WakeSomeone( UINT message )
1125 WND* wndPtr = NULL;
1126 WORD wakeBit;
1127 HWND hwnd;
1128 HQUEUE16 hQueue = 0;
1129 MESSAGEQUEUE *queue = NULL;
1131 if (hCursorQueue)
1132 hQueue = hCursorQueue;
1134 if( (message >= WM_KEYFIRST) && (message <= WM_KEYLAST) )
1136 wakeBit = QS_KEY;
1137 if( hActiveQueue )
1138 hQueue = hActiveQueue;
1140 else
1142 wakeBit = (message == WM_MOUSEMOVE) ? QS_MOUSEMOVE : QS_MOUSEBUTTON;
1143 if( (hwnd = GetCapture()) )
1144 if( (wndPtr = WIN_FindWndPtr( hwnd )) )
1146 hQueue = wndPtr->hmemTaskQ;
1147 WIN_ReleaseWndPtr(wndPtr);
1151 if( (hwnd = GetSysModalWindow16()) )
1153 if( (wndPtr = WIN_FindWndPtr( hwnd )) )
1155 hQueue = wndPtr->hmemTaskQ;
1156 WIN_ReleaseWndPtr(wndPtr);
1160 if (hQueue)
1161 queue = QUEUE_Lock( hQueue );
1163 if( !queue )
1165 queue = QUEUE_Lock( hFirstQueue );
1166 while( queue )
1168 if (queue->wakeMask & wakeBit) break;
1170 QUEUE_Unlock(queue);
1171 queue = QUEUE_Lock( queue->next );
1173 if( !queue )
1175 WARN_(msg)("couldn't find queue\n");
1176 return;
1180 QUEUE_SetWakeBit( queue, wakeBit );
1182 QUEUE_Unlock( queue );
1186 /***********************************************************************
1187 * hardware_event
1189 * Add an event to the system message queue.
1190 * Note: the position is relative to the desktop window.
1192 void hardware_event( UINT message, WPARAM wParam, LPARAM lParam,
1193 int xPos, int yPos, DWORD time, DWORD extraInfo )
1195 MSG *msg;
1196 QMSG *qmsg;
1197 int mergeMsg = 0;
1199 if (!sysMsgQueue) return;
1201 EnterCriticalSection( &sysMsgQueue->cSection );
1203 /* Merge with previous event if possible */
1204 qmsg = sysMsgQueue->lastMsg;
1206 if ((message == WM_MOUSEMOVE) && sysMsgQueue->lastMsg)
1208 msg = &(sysMsgQueue->lastMsg->msg);
1210 if ((msg->message == message) && (msg->wParam == wParam))
1212 /* Merge events */
1213 qmsg = sysMsgQueue->lastMsg;
1214 mergeMsg = 1;
1218 if (!mergeMsg)
1220 /* Should I limit the number of message in
1221 the system message queue??? */
1223 /* Don't merge allocate a new msg in the global heap */
1225 if (!(qmsg = (QMSG *) HeapAlloc( SystemHeap, 0, sizeof(QMSG) ) ))
1227 LeaveCriticalSection( &sysMsgQueue->cSection );
1228 return;
1231 /* put message at the end of the linked list */
1232 qmsg->nextMsg = 0;
1233 qmsg->prevMsg = sysMsgQueue->lastMsg;
1235 if (sysMsgQueue->lastMsg)
1236 sysMsgQueue->lastMsg->nextMsg = qmsg;
1238 /* set last and first anchor index in system message queue */
1239 sysMsgQueue->lastMsg = qmsg;
1240 if (!sysMsgQueue->firstMsg)
1241 sysMsgQueue->firstMsg = qmsg;
1243 sysMsgQueue->msgCount++;
1246 /* Store message */
1247 msg = &(qmsg->msg);
1248 msg->hwnd = 0;
1249 msg->message = message;
1250 msg->wParam = wParam;
1251 msg->lParam = lParam;
1252 msg->time = time;
1253 msg->pt.x = xPos;
1254 msg->pt.y = yPos;
1255 qmsg->extraInfo = extraInfo;
1256 qmsg->type = QMSG_HARDWARE;
1258 LeaveCriticalSection( &sysMsgQueue->cSection );
1260 QUEUE_WakeSomeone( message );
1264 /***********************************************************************
1265 * QUEUE_GetQueueTask
1267 HTASK16 QUEUE_GetQueueTask( HQUEUE16 hQueue )
1269 HTASK16 hTask = 0;
1271 MESSAGEQUEUE *queue = QUEUE_Lock( hQueue );
1273 if (queue)
1275 hTask = queue->teb->process->task;
1276 QUEUE_Unlock( queue );
1279 return hTask;
1284 /***********************************************************************
1285 * QUEUE_IncPaintCount
1287 void QUEUE_IncPaintCount( HQUEUE16 hQueue )
1289 MESSAGEQUEUE *queue;
1291 if (!(queue = (MESSAGEQUEUE *)QUEUE_Lock( hQueue ))) return;
1292 queue->wPaintCount++;
1293 QUEUE_SetWakeBit( queue, QS_PAINT );
1294 QUEUE_Unlock( queue );
1298 /***********************************************************************
1299 * QUEUE_DecPaintCount
1301 void QUEUE_DecPaintCount( HQUEUE16 hQueue )
1303 MESSAGEQUEUE *queue;
1305 if (!(queue = (MESSAGEQUEUE *)QUEUE_Lock( hQueue ))) return;
1306 queue->wPaintCount--;
1307 if (!queue->wPaintCount) queue->wakeBits &= ~QS_PAINT;
1308 QUEUE_Unlock( queue );
1312 /***********************************************************************
1313 * QUEUE_IncTimerCount
1315 void QUEUE_IncTimerCount( HQUEUE16 hQueue )
1317 MESSAGEQUEUE *queue;
1319 if (!(queue = (MESSAGEQUEUE *)QUEUE_Lock( hQueue ))) return;
1320 queue->wTimerCount++;
1321 QUEUE_SetWakeBit( queue, QS_TIMER );
1322 QUEUE_Unlock( queue );
1326 /***********************************************************************
1327 * QUEUE_DecTimerCount
1329 void QUEUE_DecTimerCount( HQUEUE16 hQueue )
1331 MESSAGEQUEUE *queue;
1333 if (!(queue = (MESSAGEQUEUE *)QUEUE_Lock( hQueue ))) return;
1334 queue->wTimerCount--;
1335 if (!queue->wTimerCount) queue->wakeBits &= ~QS_TIMER;
1336 QUEUE_Unlock( queue );
1340 /***********************************************************************
1341 * PostQuitMessage16 (USER.6)
1343 void WINAPI PostQuitMessage16( INT16 exitCode )
1345 PostQuitMessage( exitCode );
1349 /***********************************************************************
1350 * PostQuitMessage32 (USER32.421)
1352 * PostQuitMessage() posts a message to the system requesting an
1353 * application to terminate execution. As a result of this function,
1354 * the WM_QUIT message is posted to the application, and
1355 * PostQuitMessage() returns immediately. The exitCode parameter
1356 * specifies an application-defined exit code, which appears in the
1357 * _wParam_ parameter of the WM_QUIT message posted to the application.
1359 * CONFORMANCE
1361 * ECMA-234, Win32
1363 void WINAPI PostQuitMessage( INT exitCode )
1365 MESSAGEQUEUE *queue;
1367 if (!(queue = (MESSAGEQUEUE *)QUEUE_Lock( GetFastQueue16() ))) return;
1368 queue->wPostQMsg = TRUE;
1369 queue->wExitCode = (WORD)exitCode;
1370 QUEUE_Unlock( queue );
1374 /***********************************************************************
1375 * GetWindowTask16 (USER.224)
1377 HTASK16 WINAPI GetWindowTask16( HWND16 hwnd )
1379 HTASK16 retvalue;
1380 WND *wndPtr = WIN_FindWndPtr( hwnd );
1382 if (!wndPtr) return 0;
1383 retvalue = QUEUE_GetQueueTask( wndPtr->hmemTaskQ );
1384 WIN_ReleaseWndPtr(wndPtr);
1385 return retvalue;
1388 /***********************************************************************
1389 * GetWindowThreadProcessId (USER32.313)
1391 DWORD WINAPI GetWindowThreadProcessId( HWND hwnd, LPDWORD process )
1393 DWORD retvalue;
1394 MESSAGEQUEUE *queue;
1396 WND *wndPtr = WIN_FindWndPtr( hwnd );
1397 if (!wndPtr) return 0;
1399 queue = QUEUE_Lock( wndPtr->hmemTaskQ );
1400 WIN_ReleaseWndPtr(wndPtr);
1402 if (!queue) return 0;
1404 if ( process ) *process = (DWORD)queue->teb->process->server_pid;
1405 retvalue = (DWORD)queue->teb->tid;
1407 QUEUE_Unlock( queue );
1408 return retvalue;
1412 /***********************************************************************
1413 * SetMessageQueue16 (USER.266)
1415 BOOL16 WINAPI SetMessageQueue16( INT16 size )
1417 return SetMessageQueue( size );
1421 /***********************************************************************
1422 * SetMessageQueue (USER32.494)
1424 BOOL WINAPI SetMessageQueue( INT size )
1426 /* now obsolete the message queue will be expanded dynamically
1427 as necessary */
1429 /* access the queue to create it if it's not existing */
1430 GetFastQueue16();
1432 return TRUE;
1435 /***********************************************************************
1436 * InitThreadInput16 (USER.409)
1438 HQUEUE16 WINAPI InitThreadInput16( WORD unknown, WORD flags )
1440 HQUEUE16 hQueue;
1441 MESSAGEQUEUE *queuePtr;
1443 TEB *teb = NtCurrentTeb();
1445 if (!teb)
1446 return 0;
1448 hQueue = teb->queue;
1450 if ( !hQueue )
1452 /* Create thread message queue */
1453 if( !(hQueue = QUEUE_CreateMsgQueue( TRUE )))
1455 WARN_(msg)("failed!\n");
1456 return FALSE;
1459 /* Link new queue into list */
1460 queuePtr = (MESSAGEQUEUE *)QUEUE_Lock( hQueue );
1461 queuePtr->teb = NtCurrentTeb();
1463 HeapLock( SystemHeap ); /* FIXME: a bit overkill */
1464 SetThreadQueue16( 0, hQueue );
1465 teb->queue = hQueue;
1467 queuePtr->next = hFirstQueue;
1468 hFirstQueue = hQueue;
1469 HeapUnlock( SystemHeap );
1471 QUEUE_Unlock( queuePtr );
1474 return hQueue;
1477 /***********************************************************************
1478 * GetQueueStatus16 (USER.334)
1480 DWORD WINAPI GetQueueStatus16( UINT16 flags )
1482 MESSAGEQUEUE *queue;
1483 DWORD ret;
1485 if (!(queue = (MESSAGEQUEUE *)QUEUE_Lock( GetFastQueue16() ))) return 0;
1486 ret = MAKELONG( queue->changeBits, queue->wakeBits );
1487 queue->changeBits = 0;
1488 QUEUE_Unlock( queue );
1490 return ret & MAKELONG( flags, flags );
1493 /***********************************************************************
1494 * GetQueueStatus32 (USER32.283)
1496 DWORD WINAPI GetQueueStatus( UINT flags )
1498 MESSAGEQUEUE *queue;
1499 DWORD ret;
1501 if (!(queue = (MESSAGEQUEUE *)QUEUE_Lock( GetFastQueue16() ))) return 0;
1502 ret = MAKELONG( queue->changeBits, queue->wakeBits );
1503 queue->changeBits = 0;
1504 QUEUE_Unlock( queue );
1506 return ret & MAKELONG( flags, flags );
1510 /***********************************************************************
1511 * GetInputState16 (USER.335)
1513 BOOL16 WINAPI GetInputState16(void)
1515 return GetInputState();
1518 /***********************************************************************
1519 * WaitForInputIdle (USER32.577)
1521 DWORD WINAPI WaitForInputIdle (HANDLE hProcess, DWORD dwTimeOut)
1523 PDB * pdb;
1524 DWORD cur_time, ret, pid = MapProcessHandle ( hProcess );
1526 /* Check whether the calling process is a command line application */
1527 if (!THREAD_IsWin16(NtCurrentTeb() ) &&
1528 (PROCESS_Current()->flags & PDB32_CONSOLE_PROC))
1530 TRACE_(msg)("not a win32 GUI application!\n" );
1531 return 0;
1534 pdb = PROCESS_IdToPDB( pid );
1536 /* check whether we are waiting for a win32 process or the win16 subsystem */
1537 if ( pdb->flags & PDB32_WIN16_PROC ) {
1538 if ( THREAD_IsWin16(NtCurrentTeb()) ) return 0;
1540 else { /* target is win32 */
1541 if ( pdb->flags & PDB32_CONSOLE_PROC ) return 0;
1542 if ( GetFastQueue16() == pdb->main_queue ) return 0;
1545 cur_time = GetTickCount();
1547 TRACE_(msg)("waiting for %x\n", pdb->idle_event );
1548 while ( dwTimeOut > GetTickCount() - cur_time || dwTimeOut == INFINITE ) {
1550 ret = MsgWaitForMultipleObjects ( 1, &pdb->idle_event, FALSE, dwTimeOut, QS_SENDMESSAGE );
1551 if ( ret == ( WAIT_OBJECT_0 + 1 )) {
1552 MESSAGEQUEUE * queue;
1553 if (!(queue = (MESSAGEQUEUE *)QUEUE_Lock( GetFastQueue16() ))) return 0xFFFFFFFF;
1554 QUEUE_ReceiveMessage ( queue );
1555 QUEUE_Unlock ( queue );
1556 continue;
1558 if ( ret == WAIT_TIMEOUT || ret == 0xFFFFFFFF ) {
1559 TRACE_(msg)("timeout or error\n");
1560 return ret;
1562 else {
1563 TRACE_(msg)("finished\n");
1564 return 0;
1568 return WAIT_TIMEOUT;
1571 /***********************************************************************
1572 * GetInputState32 (USER32.244)
1574 BOOL WINAPI GetInputState(void)
1576 MESSAGEQUEUE *queue;
1577 BOOL ret;
1579 if (!(queue = (MESSAGEQUEUE *)QUEUE_Lock( GetFastQueue16() )))
1580 return FALSE;
1581 ret = queue->wakeBits & (QS_KEY | QS_MOUSEBUTTON);
1582 QUEUE_Unlock( queue );
1584 return ret;
1587 /***********************************************************************
1588 * UserYield (USER.332)
1590 void WINAPI UserYield16(void)
1592 MESSAGEQUEUE *queue;
1594 /* Handle sent messages */
1595 queue = (MESSAGEQUEUE *)QUEUE_Lock( GetFastQueue16() );
1597 while (queue && (queue->wakeBits & QS_SENDMESSAGE))
1598 QUEUE_ReceiveMessage( queue );
1600 QUEUE_Unlock( queue );
1602 /* Yield */
1603 if ( THREAD_IsWin16( NtCurrentTeb() ) )
1604 OldYield16();
1605 else
1606 WIN32_OldYield16();
1608 /* Handle sent messages again */
1609 queue = (MESSAGEQUEUE *)QUEUE_Lock( GetFastQueue16() );
1611 while (queue && (queue->wakeBits & QS_SENDMESSAGE))
1612 QUEUE_ReceiveMessage( queue );
1614 QUEUE_Unlock( queue );
1617 /***********************************************************************
1618 * GetMessagePos (USER.119) (USER32.272)
1620 * The GetMessagePos() function returns a long value representing a
1621 * cursor position, in screen coordinates, when the last message
1622 * retrieved by the GetMessage() function occurs. The x-coordinate is
1623 * in the low-order word of the return value, the y-coordinate is in
1624 * the high-order word. The application can use the MAKEPOINT()
1625 * macro to obtain a POINT structure from the return value.
1627 * For the current cursor position, use GetCursorPos().
1629 * RETURNS
1631 * Cursor position of last message on success, zero on failure.
1633 * CONFORMANCE
1635 * ECMA-234, Win32
1638 DWORD WINAPI GetMessagePos(void)
1640 MESSAGEQUEUE *queue;
1641 DWORD ret;
1643 if (!(queue = (MESSAGEQUEUE *)QUEUE_Lock( GetFastQueue16() ))) return 0;
1644 ret = queue->GetMessagePosVal;
1645 QUEUE_Unlock( queue );
1647 return ret;
1651 /***********************************************************************
1652 * GetMessageTime (USER.120) (USER32.273)
1654 * GetMessageTime() returns the message time for the last message
1655 * retrieved by the function. The time is measured in milliseconds with
1656 * the same offset as GetTickCount().
1658 * Since the tick count wraps, this is only useful for moderately short
1659 * relative time comparisons.
1661 * RETURNS
1663 * Time of last message on success, zero on failure.
1665 * CONFORMANCE
1667 * ECMA-234, Win32
1670 LONG WINAPI GetMessageTime(void)
1672 MESSAGEQUEUE *queue;
1673 LONG ret;
1675 if (!(queue = (MESSAGEQUEUE *)QUEUE_Lock( GetFastQueue16() ))) return 0;
1676 ret = queue->GetMessageTimeVal;
1677 QUEUE_Unlock( queue );
1679 return ret;
1683 /***********************************************************************
1684 * GetMessageExtraInfo (USER.288) (USER32.271)
1686 LONG WINAPI GetMessageExtraInfo(void)
1688 MESSAGEQUEUE *queue;
1689 LONG ret;
1691 if (!(queue = (MESSAGEQUEUE *)QUEUE_Lock( GetFastQueue16() ))) return 0;
1692 ret = queue->GetMessageExtraInfoVal;
1693 QUEUE_Unlock( queue );
1695 return ret;