Yet another small self-loader fix.
[wine/multimedia.git] / windows / queue.c
blob8ab1c80bd92035837e43eb3f04a89ec94e61df18
1 /*
2 * Message queues related functions
4 * Copyright 1993, 1994 Alexandre Julliard
5 */
7 #include <stdlib.h>
8 #include <signal.h>
9 #include "miscemu.h"
10 #include "module.h"
11 #include "queue.h"
12 #include "task.h"
13 #include "win.h"
14 #include "clipboard.h"
15 #include "hook.h"
16 #include "heap.h"
17 #include "thread.h"
18 #include "process.h"
19 #include "debug.h"
21 #define MAX_QUEUE_SIZE 120 /* Max. size of a message queue */
23 static HQUEUE16 hFirstQueue = 0;
24 static HQUEUE16 hExitingQueue = 0;
25 static HQUEUE16 hmemSysMsgQueue = 0;
26 static MESSAGEQUEUE *sysMsgQueue = NULL;
28 static MESSAGEQUEUE *pMouseQueue = NULL; /* Queue for last mouse message */
29 static MESSAGEQUEUE *pKbdQueue = NULL; /* Queue for last kbd message */
31 MESSAGEQUEUE *pCursorQueue = NULL;
32 MESSAGEQUEUE *pActiveQueue = NULL;
34 /***********************************************************************
35 * QUEUE_DumpQueue
37 void QUEUE_DumpQueue( HQUEUE16 hQueue )
39 MESSAGEQUEUE *pq;
41 if (!(pq = (MESSAGEQUEUE*) GlobalLock16( hQueue )) ||
42 GlobalSize16(hQueue) < sizeof(MESSAGEQUEUE)+pq->queueSize*sizeof(QMSG))
44 WARN(msg, "%04x is not a queue handle\n", hQueue );
45 return;
48 DUMP( "next: %12.4x Intertask SendMessage:\n"
49 "hTask: %11.4x ----------------------\n"
50 "msgSize: %9.4x hWnd: %10.4x\n"
51 "msgCount: %8.4x msg: %11.4x\n"
52 "msgNext: %9.4x wParam: %8.4x\n"
53 "msgFree: %9.4x lParam: %8.8x\n"
54 "qSize: %11.4x lRet: %10.8x\n"
55 "wWinVer: %9.4x ISMH: %10.4x\n"
56 "paints: %10.4x hSendTask: %5.4x\n"
57 "timers: %10.4x hPrevSend: %5.4x\n"
58 "wakeBits: %8.4x\n"
59 "wakeMask: %8.4x\n"
60 "hCurHook: %8.4x\n",
61 pq->next, pq->hTask, pq->msgSize, pq->hWnd,
62 pq->msgCount, pq->msg, pq->nextMessage, pq->wParam,
63 pq->nextFreeMessage, (unsigned)pq->lParam, pq->queueSize,
64 (unsigned)pq->SendMessageReturn, pq->wWinVersion, pq->InSendMessageHandle,
65 pq->wPaintCount, pq->hSendingTask, pq->wTimerCount,
66 pq->hPrevSendingTask, pq->wakeBits, pq->wakeMask, pq->hCurHook);
70 /***********************************************************************
71 * QUEUE_WalkQueues
73 void QUEUE_WalkQueues(void)
75 char module[10];
76 HQUEUE16 hQueue = hFirstQueue;
78 DUMP( "Queue Size Msgs Task\n" );
79 while (hQueue)
81 MESSAGEQUEUE *queue = (MESSAGEQUEUE *)GlobalLock16( hQueue );
82 if (!queue)
84 WARN( msg, "Bad queue handle %04x\n", hQueue );
85 return;
87 if (!GetModuleName( queue->hTask, module, sizeof(module )))
88 strcpy( module, "???" );
89 DUMP( "%04x %5d %4d %04x %s\n", hQueue, queue->msgSize,
90 queue->msgCount, queue->hTask, module );
91 hQueue = queue->next;
93 DUMP( "\n" );
97 /***********************************************************************
98 * QUEUE_IsExitingQueue
100 BOOL32 QUEUE_IsExitingQueue( HQUEUE16 hQueue )
102 return (hExitingQueue && (hQueue == hExitingQueue));
106 /***********************************************************************
107 * QUEUE_SetExitingQueue
109 void QUEUE_SetExitingQueue( HQUEUE16 hQueue )
111 hExitingQueue = hQueue;
115 /***********************************************************************
116 * QUEUE_CreateMsgQueue
118 * Creates a message queue. Doesn't link it into queue list!
120 static HQUEUE16 QUEUE_CreateMsgQueue( int size )
122 HQUEUE16 hQueue;
123 MESSAGEQUEUE * msgQueue;
124 int queueSize;
125 TDB *pTask = (TDB *)GlobalLock16( GetCurrentTask() );
127 TRACE(msg,"Creating message queue...\n");
129 queueSize = sizeof(MESSAGEQUEUE) + size * sizeof(QMSG);
130 if (!(hQueue = GlobalAlloc16( GMEM_FIXED | GMEM_ZEROINIT, queueSize )))
131 return 0;
132 msgQueue = (MESSAGEQUEUE *) GlobalLock16( hQueue );
133 msgQueue->self = hQueue;
134 msgQueue->msgSize = sizeof(QMSG);
135 msgQueue->queueSize = size;
136 msgQueue->wakeBits = msgQueue->changeBits = QS_SMPARAMSFREE;
137 msgQueue->wWinVersion = pTask ? pTask->version : 0;
138 GlobalUnlock16( hQueue );
139 return hQueue;
143 /***********************************************************************
144 * QUEUE_DeleteMsgQueue
146 * Unlinks and deletes a message queue.
148 * Note: We need to mask asynchronous events to make sure PostMessage works
149 * even in the signal handler.
151 BOOL32 QUEUE_DeleteMsgQueue( HQUEUE16 hQueue )
153 MESSAGEQUEUE * msgQueue = (MESSAGEQUEUE*)GlobalLock16(hQueue);
154 HQUEUE16 senderQ;
155 HQUEUE16 *pPrev;
157 TRACE(msg,"Deleting message queue %04x\n", hQueue);
159 if (!hQueue || !msgQueue)
161 WARN(msg, "invalid argument.\n");
162 return 0;
164 if( pCursorQueue == msgQueue ) pCursorQueue = NULL;
165 if( pActiveQueue == msgQueue ) pActiveQueue = NULL;
167 /* flush sent messages */
168 senderQ = msgQueue->hSendingTask;
169 while( senderQ )
171 MESSAGEQUEUE* sq = (MESSAGEQUEUE*)GlobalLock16(senderQ);
172 if( !sq ) break;
173 sq->SendMessageReturn = 0L;
174 QUEUE_SetWakeBit( sq, QS_SMRESULT );
175 senderQ = sq->hPrevSendingTask;
178 SIGNAL_MaskAsyncEvents( TRUE );
180 pPrev = &hFirstQueue;
181 while (*pPrev && (*pPrev != hQueue))
183 MESSAGEQUEUE *msgQ = (MESSAGEQUEUE*)GlobalLock16(*pPrev);
184 pPrev = &msgQ->next;
186 if (*pPrev) *pPrev = msgQueue->next;
187 msgQueue->self = 0;
189 SIGNAL_MaskAsyncEvents( FALSE );
191 GlobalFree16( hQueue );
192 return 1;
196 /***********************************************************************
197 * QUEUE_CreateSysMsgQueue
199 * Create the system message queue, and set the double-click speed.
200 * Must be called only once.
202 BOOL32 QUEUE_CreateSysMsgQueue( int size )
204 if (size > MAX_QUEUE_SIZE) size = MAX_QUEUE_SIZE;
205 else if (size <= 0) size = 1;
206 if (!(hmemSysMsgQueue = QUEUE_CreateMsgQueue( size ))) return FALSE;
207 sysMsgQueue = (MESSAGEQUEUE *) GlobalLock16( hmemSysMsgQueue );
208 return TRUE;
212 /***********************************************************************
213 * QUEUE_GetSysQueue
215 MESSAGEQUEUE *QUEUE_GetSysQueue(void)
217 return sysMsgQueue;
220 /***********************************************************************
221 * QUEUE_Signal
223 void QUEUE_Signal( HTASK16 hTask )
225 PDB32 *pdb;
226 THREAD_ENTRY *entry;
227 int wakeup = FALSE;
229 TDB *pTask = (TDB *)GlobalLock16( hTask );
230 if ( !pTask ) return;
232 TRACE(msg, "calling SYNC_MsgWakeUp\n");
234 /* Wake up thread waiting for message */
235 /* NOTE: This should really wake up *the* thread that owns
236 the queue. Since we dont't have thread-local message
237 queues yet, we wake up all waiting threads ... */
238 SYSTEM_LOCK();
239 pdb = pTask->thdb->process;
240 entry = pdb? pdb->thread_list->next : NULL;
242 if (entry)
243 for (;;)
245 if (entry->thread->wait_struct.wait_msg)
247 SYNC_MsgWakeUp( entry->thread );
248 wakeup = TRUE;
250 if (entry == pdb->thread_list) break;
251 entry = entry->next;
253 SYSTEM_UNLOCK();
255 if ( !wakeup && THREAD_IsWin16( THREAD_Current() ) )
256 PostEvent( hTask );
259 /***********************************************************************
260 * QUEUE_Wait
262 void QUEUE_Wait( void )
264 if ( THREAD_IsWin16( THREAD_Current() ) )
265 WaitEvent( 0 );
266 else
268 TRACE(msg, "current task is 32-bit, calling SYNC_DoWait\n");
269 SYNC_DoWait( 0, NULL, FALSE, INFINITE32, FALSE, TRUE );
274 /***********************************************************************
275 * QUEUE_SetWakeBit
277 * See "Windows Internals", p.449
279 void QUEUE_SetWakeBit( MESSAGEQUEUE *queue, WORD bit )
281 TRACE(msg,"queue = %04x (wm=%04x), bit = %04x\n",
282 queue->self, queue->wakeMask, bit );
284 if (bit & QS_MOUSE) pMouseQueue = queue;
285 if (bit & QS_KEY) pKbdQueue = queue;
286 queue->changeBits |= bit;
287 queue->wakeBits |= bit;
288 if (queue->wakeMask & bit)
290 queue->wakeMask = 0;
291 QUEUE_Signal( queue->hTask );
296 /***********************************************************************
297 * QUEUE_ClearWakeBit
299 void QUEUE_ClearWakeBit( MESSAGEQUEUE *queue, WORD bit )
301 queue->changeBits &= ~bit;
302 queue->wakeBits &= ~bit;
306 /***********************************************************************
307 * QUEUE_WaitBits
309 * See "Windows Internals", p.447
311 void QUEUE_WaitBits( WORD bits )
313 MESSAGEQUEUE *queue;
315 TRACE(msg,"q %04x waiting for %04x\n", GetTaskQueue(0), bits);
317 for (;;)
319 if (!(queue = (MESSAGEQUEUE *)GlobalLock16( GetTaskQueue(0) ))) return;
321 if (queue->changeBits & bits)
323 /* One of the bits is set; we can return */
324 queue->wakeMask = 0;
325 return;
327 if (queue->wakeBits & QS_SENDMESSAGE)
329 /* Process the sent message immediately */
331 queue->wakeMask = 0;
332 QUEUE_ReceiveMessage( queue );
333 continue; /* nested sm crux */
336 queue->wakeMask = bits | QS_SENDMESSAGE;
337 if(queue->changeBits & bits) continue;
339 TRACE(msg,"%04x) wakeMask is %04x, waiting\n", queue->self, queue->wakeMask);
341 QUEUE_Wait();
346 /***********************************************************************
347 * QUEUE_ReceiveMessage
349 * This routine is called when a sent message is waiting for the queue.
351 void QUEUE_ReceiveMessage( MESSAGEQUEUE *queue )
353 MESSAGEQUEUE *senderQ = NULL;
354 HQUEUE16 prevSender = 0;
355 QSMCTRL* prevCtrlPtr = NULL;
356 LRESULT result = 0;
358 TRACE(msg, "ReceiveMessage, queue %04x\n", queue->self );
359 if (!(queue->wakeBits & QS_SENDMESSAGE) ||
360 !(senderQ = (MESSAGEQUEUE*)GlobalLock16( queue->hSendingTask)))
361 { TRACE(msg,"\trcm: nothing to do\n"); return; }
363 if( !senderQ->hPrevSendingTask )
365 queue->wakeBits &= ~QS_SENDMESSAGE; /* no more sent messages */
366 queue->changeBits &= ~QS_SENDMESSAGE;
369 /* Save current state on stack */
370 prevSender = queue->InSendMessageHandle;
371 prevCtrlPtr = queue->smResultCurrent;
373 /* Remove sending queue from the list */
374 queue->InSendMessageHandle = queue->hSendingTask;
375 queue->smResultCurrent = senderQ->smResultInit;
376 queue->hSendingTask = senderQ->hPrevSendingTask;
378 TRACE(msg, "\trcm: smResultCurrent = %08x, prevCtrl = %08x\n",
379 (unsigned)queue->smResultCurrent, (unsigned)prevCtrlPtr );
380 QUEUE_SetWakeBit( senderQ, QS_SMPARAMSFREE );
382 TRACE(msg, "\trcm: calling wndproc - %04x %04x %04x%04x %08x\n",
383 senderQ->hWnd, senderQ->msg, senderQ->wParamHigh,
384 senderQ->wParam, (unsigned)senderQ->lParam );
386 if (IsWindow32( senderQ->hWnd ))
388 WND *wndPtr = WIN_FindWndPtr( senderQ->hWnd );
389 DWORD extraInfo = queue->GetMessageExtraInfoVal;
390 queue->GetMessageExtraInfoVal = senderQ->GetMessageExtraInfoVal;
392 if (senderQ->flags & QUEUE_SM_WIN32)
394 WPARAM32 wParam = MAKELONG( senderQ->wParam, senderQ->wParamHigh );
395 TRACE(msg, "\trcm: msg is Win32\n" );
396 if (senderQ->flags & QUEUE_SM_UNICODE)
397 result = CallWindowProc32W( wndPtr->winproc,
398 senderQ->hWnd, senderQ->msg,
399 wParam, senderQ->lParam );
400 else
401 result = CallWindowProc32A( wndPtr->winproc,
402 senderQ->hWnd, senderQ->msg,
403 wParam, senderQ->lParam );
405 else /* Win16 message */
406 result = CallWindowProc16( (WNDPROC16)wndPtr->winproc,
407 senderQ->hWnd, senderQ->msg,
408 senderQ->wParam, senderQ->lParam );
410 queue->GetMessageExtraInfoVal = extraInfo; /* Restore extra info */
411 TRACE(msg,"\trcm: result = %08x\n", (unsigned)result );
413 else WARN(msg, "\trcm: bad hWnd\n");
415 /* Return the result to the sender task */
416 ReplyMessage16( result );
418 queue->InSendMessageHandle = prevSender;
419 queue->smResultCurrent = prevCtrlPtr;
421 TRACE(msg,"done!\n");
424 /***********************************************************************
425 * QUEUE_FlushMessage
427 * Try to reply to all pending sent messages on exit.
429 void QUEUE_FlushMessages( HQUEUE16 hQueue )
431 MESSAGEQUEUE *queue = (MESSAGEQUEUE*)GlobalLock16( hQueue );
433 if( queue )
435 MESSAGEQUEUE *senderQ = (MESSAGEQUEUE*)GlobalLock16( queue->hSendingTask);
436 QSMCTRL* CtrlPtr = queue->smResultCurrent;
438 while( senderQ )
440 if( !(queue->hSendingTask = senderQ->hPrevSendingTask) )
441 queue->wakeBits &= ~QS_SENDMESSAGE;
442 QUEUE_SetWakeBit( senderQ, QS_SMPARAMSFREE );
444 queue->smResultCurrent = CtrlPtr;
445 while( senderQ->wakeBits & QS_SMRESULT ) OldYield();
447 senderQ->SendMessageReturn = 0;
448 senderQ->smResult = queue->smResultCurrent;
449 QUEUE_SetWakeBit( senderQ, QS_SMRESULT);
451 if( (senderQ = (MESSAGEQUEUE*)GlobalLock16( queue->hSendingTask)) )
452 CtrlPtr = senderQ->smResultInit;
454 queue->InSendMessageHandle = 0;
458 /***********************************************************************
459 * QUEUE_AddMsg
461 * Add a message to the queue. Return FALSE if queue is full.
463 BOOL32 QUEUE_AddMsg( HQUEUE16 hQueue, MSG16 * msg, DWORD extraInfo )
465 int pos;
466 MESSAGEQUEUE *msgQueue;
468 SIGNAL_MaskAsyncEvents( TRUE );
470 if (!(msgQueue = (MESSAGEQUEUE *)GlobalLock16( hQueue ))) return FALSE;
471 pos = msgQueue->nextFreeMessage;
473 /* Check if queue is full */
474 if ((pos == msgQueue->nextMessage) && (msgQueue->msgCount > 0))
476 SIGNAL_MaskAsyncEvents( FALSE );
477 WARN( msg,"Queue is full!\n" );
478 return FALSE;
481 /* Store message */
482 msgQueue->messages[pos].msg = *msg;
483 msgQueue->messages[pos].extraInfo = extraInfo;
484 if (pos < msgQueue->queueSize-1) pos++;
485 else pos = 0;
486 msgQueue->nextFreeMessage = pos;
487 msgQueue->msgCount++;
489 SIGNAL_MaskAsyncEvents( FALSE );
491 QUEUE_SetWakeBit( msgQueue, QS_POSTMESSAGE );
492 return TRUE;
496 /***********************************************************************
497 * QUEUE_FindMsg
499 * Find a message matching the given parameters. Return -1 if none available.
501 int QUEUE_FindMsg( MESSAGEQUEUE * msgQueue, HWND32 hwnd, int first, int last )
503 int i, pos = msgQueue->nextMessage;
505 TRACE(msg,"hwnd=%04x pos=%d\n", hwnd, pos );
507 if (!msgQueue->msgCount) return -1;
508 if (!hwnd && !first && !last) return pos;
510 for (i = 0; i < msgQueue->msgCount; i++)
512 MSG16 * msg = &msgQueue->messages[pos].msg;
514 if (!hwnd || (msg->hwnd == hwnd))
516 if (!first && !last) return pos;
517 if ((msg->message >= first) && (msg->message <= last)) return pos;
519 if (pos < msgQueue->queueSize-1) pos++;
520 else pos = 0;
522 return -1;
526 /***********************************************************************
527 * QUEUE_RemoveMsg
529 * Remove a message from the queue (pos must be a valid position).
531 void QUEUE_RemoveMsg( MESSAGEQUEUE * msgQueue, int pos )
533 SIGNAL_MaskAsyncEvents( TRUE );
535 if (pos >= msgQueue->nextMessage)
537 for ( ; pos > msgQueue->nextMessage; pos--)
538 msgQueue->messages[pos] = msgQueue->messages[pos-1];
539 msgQueue->nextMessage++;
540 if (msgQueue->nextMessage >= msgQueue->queueSize)
541 msgQueue->nextMessage = 0;
543 else
545 for ( ; pos < msgQueue->nextFreeMessage; pos++)
546 msgQueue->messages[pos] = msgQueue->messages[pos+1];
547 if (msgQueue->nextFreeMessage) msgQueue->nextFreeMessage--;
548 else msgQueue->nextFreeMessage = msgQueue->queueSize-1;
550 msgQueue->msgCount--;
551 if (!msgQueue->msgCount) msgQueue->wakeBits &= ~QS_POSTMESSAGE;
553 SIGNAL_MaskAsyncEvents( FALSE );
557 /***********************************************************************
558 * QUEUE_WakeSomeone
560 * Wake a queue upon reception of a hardware event.
562 static void QUEUE_WakeSomeone( UINT32 message )
564 WND* wndPtr = NULL;
565 WORD wakeBit;
566 HWND32 hwnd;
567 MESSAGEQUEUE *queue = pCursorQueue;
569 if( (message >= WM_KEYFIRST) && (message <= WM_KEYLAST) )
571 wakeBit = QS_KEY;
572 if( pActiveQueue ) queue = pActiveQueue;
574 else
576 wakeBit = (message == WM_MOUSEMOVE) ? QS_MOUSEMOVE : QS_MOUSEBUTTON;
577 if( (hwnd = GetCapture32()) )
578 if( (wndPtr = WIN_FindWndPtr( hwnd )) )
579 queue = (MESSAGEQUEUE *)GlobalLock16( wndPtr->hmemTaskQ );
582 if( (hwnd = GetSysModalWindow16()) )
583 if( (wndPtr = WIN_FindWndPtr( hwnd )) )
584 queue = (MESSAGEQUEUE *)GlobalLock16( wndPtr->hmemTaskQ );
586 if( !queue )
588 queue = GlobalLock16( hFirstQueue );
589 while( queue )
591 if (queue->wakeMask & wakeBit) break;
592 queue = GlobalLock16( queue->next );
594 if( !queue )
596 WARN(msg, "couldn't find queue\n");
597 return;
601 QUEUE_SetWakeBit( queue, wakeBit );
605 /***********************************************************************
606 * hardware_event
608 * Add an event to the system message queue.
609 * Note: the position is relative to the desktop window.
611 void hardware_event( WORD message, WORD wParam, LONG lParam,
612 int xPos, int yPos, DWORD time, DWORD extraInfo )
614 MSG16 *msg;
615 int pos;
617 if (!sysMsgQueue) return;
618 pos = sysMsgQueue->nextFreeMessage;
620 /* Merge with previous event if possible */
622 if ((message == WM_MOUSEMOVE) && sysMsgQueue->msgCount)
624 if (pos > 0) pos--;
625 else pos = sysMsgQueue->queueSize - 1;
626 msg = &sysMsgQueue->messages[pos].msg;
627 if ((msg->message == message) && (msg->wParam == wParam))
628 sysMsgQueue->msgCount--; /* Merge events */
629 else
630 pos = sysMsgQueue->nextFreeMessage; /* Don't merge */
633 /* Check if queue is full */
635 if ((pos == sysMsgQueue->nextMessage) && sysMsgQueue->msgCount)
637 /* Queue is full, beep (but not on every mouse motion...) */
638 if (message != WM_MOUSEMOVE) MessageBeep32(0);
639 return;
642 /* Store message */
644 msg = &sysMsgQueue->messages[pos].msg;
645 msg->hwnd = 0;
646 msg->message = message;
647 msg->wParam = wParam;
648 msg->lParam = lParam;
649 msg->time = time;
650 msg->pt.x = xPos & 0xffff;
651 msg->pt.y = yPos & 0xffff;
652 sysMsgQueue->messages[pos].extraInfo = extraInfo;
653 if (pos < sysMsgQueue->queueSize - 1) pos++;
654 else pos = 0;
655 sysMsgQueue->nextFreeMessage = pos;
656 sysMsgQueue->msgCount++;
657 QUEUE_WakeSomeone( message );
661 /***********************************************************************
662 * QUEUE_GetQueueTask
664 HTASK16 QUEUE_GetQueueTask( HQUEUE16 hQueue )
666 MESSAGEQUEUE *queue = GlobalLock16( hQueue );
667 return (queue) ? queue->hTask : 0 ;
671 /***********************************************************************
672 * QUEUE_IncPaintCount
674 void QUEUE_IncPaintCount( HQUEUE16 hQueue )
676 MESSAGEQUEUE *queue;
678 if (!(queue = (MESSAGEQUEUE *)GlobalLock16( hQueue ))) return;
679 queue->wPaintCount++;
680 QUEUE_SetWakeBit( queue, QS_PAINT );
684 /***********************************************************************
685 * QUEUE_DecPaintCount
687 void QUEUE_DecPaintCount( HQUEUE16 hQueue )
689 MESSAGEQUEUE *queue;
691 if (!(queue = (MESSAGEQUEUE *)GlobalLock16( hQueue ))) return;
692 queue->wPaintCount--;
693 if (!queue->wPaintCount) queue->wakeBits &= ~QS_PAINT;
697 /***********************************************************************
698 * QUEUE_IncTimerCount
700 void QUEUE_IncTimerCount( HQUEUE16 hQueue )
702 MESSAGEQUEUE *queue;
704 if (!(queue = (MESSAGEQUEUE *)GlobalLock16( hQueue ))) return;
705 queue->wTimerCount++;
706 QUEUE_SetWakeBit( queue, QS_TIMER );
710 /***********************************************************************
711 * QUEUE_DecTimerCount
713 void QUEUE_DecTimerCount( HQUEUE16 hQueue )
715 MESSAGEQUEUE *queue;
717 if (!(queue = (MESSAGEQUEUE *)GlobalLock16( hQueue ))) return;
718 queue->wTimerCount--;
719 if (!queue->wTimerCount) queue->wakeBits &= ~QS_TIMER;
723 /***********************************************************************
724 * PostQuitMessage16 (USER.6)
726 void WINAPI PostQuitMessage16( INT16 exitCode )
728 PostQuitMessage32( exitCode );
732 /***********************************************************************
733 * PostQuitMessage32 (USER32.421)
735 void WINAPI PostQuitMessage32( INT32 exitCode )
737 MESSAGEQUEUE *queue;
739 if (!(queue = (MESSAGEQUEUE *)GlobalLock16( GetTaskQueue(0) ))) return;
740 queue->wPostQMsg = TRUE;
741 queue->wExitCode = (WORD)exitCode;
745 /***********************************************************************
746 * GetWindowTask16 (USER.224)
748 HTASK16 WINAPI GetWindowTask16( HWND16 hwnd )
750 WND *wndPtr = WIN_FindWndPtr( hwnd );
752 if (!wndPtr) return 0;
753 return QUEUE_GetQueueTask( wndPtr->hmemTaskQ );
756 /***********************************************************************
757 * GetWindowThreadProcessId (USER32.313)
759 DWORD WINAPI GetWindowThreadProcessId( HWND32 hwnd, LPDWORD process )
761 HTASK16 htask;
762 TDB *tdb;
764 WND *wndPtr = WIN_FindWndPtr( hwnd );
766 if (!wndPtr) return 0;
767 htask=QUEUE_GetQueueTask( wndPtr->hmemTaskQ );
768 tdb = (TDB*)GlobalLock16(htask);
769 if (!tdb || !tdb->thdb) return 0;
770 if (process) *process = PDB_TO_PROCESS_ID( tdb->thdb->process );
771 return THDB_TO_THREAD_ID( tdb->thdb );
775 /***********************************************************************
776 * SetMessageQueue16 (USER.266)
778 BOOL16 WINAPI SetMessageQueue16( INT16 size )
780 return SetMessageQueue32( size );
784 /***********************************************************************
785 * SetMessageQueue32 (USER32.494)
787 BOOL32 WINAPI SetMessageQueue32( INT32 size )
789 HQUEUE16 hQueue, hNewQueue;
790 MESSAGEQUEUE *queuePtr;
792 TRACE(msg,"task %04x size %i\n", GetCurrentTask(), size);
794 if ((size > MAX_QUEUE_SIZE) || (size <= 0)) return TRUE;
796 if( !(hNewQueue = QUEUE_CreateMsgQueue( size )))
798 WARN(msg, "failed!\n");
799 return FALSE;
801 queuePtr = (MESSAGEQUEUE *)GlobalLock16( hNewQueue );
803 SIGNAL_MaskAsyncEvents( TRUE );
805 /* Copy data and free the old message queue */
806 if ((hQueue = GetTaskQueue(0)) != 0)
808 MESSAGEQUEUE *oldQ = (MESSAGEQUEUE *)GlobalLock16( hQueue );
809 memcpy( &queuePtr->wParamHigh, &oldQ->wParamHigh,
810 (int)oldQ->messages - (int)(&oldQ->wParamHigh) );
811 HOOK_ResetQueueHooks( hNewQueue );
812 if( WIN_GetDesktop()->hmemTaskQ == hQueue )
813 WIN_GetDesktop()->hmemTaskQ = hNewQueue;
814 WIN_ResetQueueWindows( WIN_GetDesktop(), hQueue, hNewQueue );
815 CLIPBOARD_ResetLock( hQueue, hNewQueue );
816 QUEUE_DeleteMsgQueue( hQueue );
819 /* Link new queue into list */
820 queuePtr->hTask = GetCurrentTask();
821 queuePtr->next = hFirstQueue;
822 hFirstQueue = hNewQueue;
824 if( !queuePtr->next ) pCursorQueue = queuePtr;
825 SetTaskQueue( 0, hNewQueue );
827 SIGNAL_MaskAsyncEvents( FALSE );
828 return TRUE;
832 /***********************************************************************
833 * GetQueueStatus16 (USER.334)
835 DWORD WINAPI GetQueueStatus16( UINT16 flags )
837 MESSAGEQUEUE *queue;
838 DWORD ret;
840 if (!(queue = (MESSAGEQUEUE *)GlobalLock16( GetTaskQueue(0) ))) return 0;
841 ret = MAKELONG( queue->changeBits, queue->wakeBits );
842 queue->changeBits = 0;
843 return ret & MAKELONG( flags, flags );
846 /***********************************************************************
847 * GetQueueStatus32 (USER32.283)
849 DWORD WINAPI GetQueueStatus32( UINT32 flags )
851 MESSAGEQUEUE *queue;
852 DWORD ret;
854 if (!(queue = (MESSAGEQUEUE *)GlobalLock16( GetTaskQueue(0) ))) return 0;
855 ret = MAKELONG( queue->changeBits, queue->wakeBits );
856 queue->changeBits = 0;
857 return ret & MAKELONG( flags, flags );
861 /***********************************************************************
862 * GetInputState16 (USER.335)
864 BOOL16 WINAPI GetInputState16(void)
866 return GetInputState32();
869 /***********************************************************************
870 * WaitForInputIdle (USER32.577)
872 DWORD WINAPI WaitForInputIdle (HANDLE32 hProcess, DWORD dwTimeOut)
874 FIXME (msg, "(hProcess=%d, dwTimeOut=%ld): stub\n", hProcess, dwTimeOut);
876 return WAIT_TIMEOUT;
880 /***********************************************************************
881 * GetInputState32 (USER32.244)
883 BOOL32 WINAPI GetInputState32(void)
885 MESSAGEQUEUE *queue;
887 if (!(queue = (MESSAGEQUEUE *)GlobalLock16( GetTaskQueue(0) )))
888 return FALSE;
889 return queue->wakeBits & (QS_KEY | QS_MOUSEBUTTON);
893 /***********************************************************************
894 * GetMessagePos (USER.119) (USER32.272)
896 DWORD WINAPI GetMessagePos(void)
898 MESSAGEQUEUE *queue;
900 if (!(queue = (MESSAGEQUEUE *)GlobalLock16( GetTaskQueue(0) ))) return 0;
901 return queue->GetMessagePosVal;
905 /***********************************************************************
906 * GetMessageTime (USER.120) (USER32.273)
908 LONG WINAPI GetMessageTime(void)
910 MESSAGEQUEUE *queue;
912 if (!(queue = (MESSAGEQUEUE *)GlobalLock16( GetTaskQueue(0) ))) return 0;
913 return queue->GetMessageTimeVal;
917 /***********************************************************************
918 * GetMessageExtraInfo (USER.288) (USER32.271)
920 LONG WINAPI GetMessageExtraInfo(void)
922 MESSAGEQUEUE *queue;
924 if (!(queue = (MESSAGEQUEUE *)GlobalLock16( GetTaskQueue(0) ))) return 0;
925 return queue->GetMessageExtraInfoVal;