2 * Message queues related functions
4 * Copyright 1993, 1994 Alexandre Julliard
14 #include "clipboard.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 /***********************************************************************
37 void QUEUE_DumpQueue( HQUEUE16 hQueue
)
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
);
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"
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 /***********************************************************************
73 void QUEUE_WalkQueues(void)
76 HQUEUE16 hQueue
= hFirstQueue
;
78 DUMP( "Queue Size Msgs Task\n" );
81 MESSAGEQUEUE
*queue
= (MESSAGEQUEUE
*)GlobalLock16( hQueue
);
84 WARN( msg
, "Bad queue handle %04x\n", hQueue
);
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
);
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
)
123 MESSAGEQUEUE
* msgQueue
;
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
)))
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
);
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
);
157 TRACE(msg
,"Deleting message queue %04x\n", hQueue
);
159 if (!hQueue
|| !msgQueue
)
161 WARN(msg
, "invalid argument.\n");
164 if( pCursorQueue
== msgQueue
) pCursorQueue
= NULL
;
165 if( pActiveQueue
== msgQueue
) pActiveQueue
= NULL
;
167 /* flush sent messages */
168 senderQ
= msgQueue
->hSendingTask
;
171 MESSAGEQUEUE
* sq
= (MESSAGEQUEUE
*)GlobalLock16(senderQ
);
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
);
186 if (*pPrev
) *pPrev
= msgQueue
->next
;
189 SIGNAL_MaskAsyncEvents( FALSE
);
191 GlobalFree16( hQueue
);
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
);
212 /***********************************************************************
215 MESSAGEQUEUE
*QUEUE_GetSysQueue(void)
220 /***********************************************************************
223 void QUEUE_Signal( HTASK16 hTask
)
228 TDB
*pTask
= (TDB
*)GlobalLock16( hTask
);
229 if ( !pTask
) return;
231 /* Wake up thread waiting for message */
232 SetEvent( pTask
->thdb
->event
);
237 /***********************************************************************
240 static void QUEUE_Wait( DWORD wait_mask
)
242 if ( THREAD_IsWin16( THREAD_Current() ) )
246 TRACE(msg
, "current task is 32-bit, calling SYNC_DoWait\n");
247 MsgWaitForMultipleObjects( 0, NULL
, FALSE
, INFINITE32
, wait_mask
);
252 /***********************************************************************
255 * See "Windows Internals", p.449
257 void QUEUE_SetWakeBit( MESSAGEQUEUE
*queue
, WORD bit
)
259 TRACE(msg
,"queue = %04x (wm=%04x), bit = %04x\n",
260 queue
->self
, queue
->wakeMask
, bit
);
262 if (bit
& QS_MOUSE
) pMouseQueue
= queue
;
263 if (bit
& QS_KEY
) pKbdQueue
= queue
;
264 queue
->changeBits
|= bit
;
265 queue
->wakeBits
|= bit
;
266 if (queue
->wakeMask
& bit
)
269 QUEUE_Signal( queue
->hTask
);
274 /***********************************************************************
277 void QUEUE_ClearWakeBit( MESSAGEQUEUE
*queue
, WORD bit
)
279 queue
->changeBits
&= ~bit
;
280 queue
->wakeBits
&= ~bit
;
284 /***********************************************************************
287 * See "Windows Internals", p.447
289 void QUEUE_WaitBits( WORD bits
)
293 TRACE(msg
,"q %04x waiting for %04x\n", GetFastQueue(), bits
);
297 if (!(queue
= (MESSAGEQUEUE
*)GlobalLock16( GetFastQueue() ))) return;
299 if (queue
->changeBits
& bits
)
301 /* One of the bits is set; we can return */
305 if (queue
->wakeBits
& QS_SENDMESSAGE
)
307 /* Process the sent message immediately */
310 QUEUE_ReceiveMessage( queue
);
311 continue; /* nested sm crux */
314 queue
->wakeMask
= bits
| QS_SENDMESSAGE
;
315 if(queue
->changeBits
& bits
) continue;
317 TRACE(msg
,"%04x) wakeMask is %04x, waiting\n", queue
->self
, queue
->wakeMask
);
319 QUEUE_Wait( queue
->wakeMask
);
324 /***********************************************************************
325 * QUEUE_ReceiveMessage
327 * This routine is called when a sent message is waiting for the queue.
329 void QUEUE_ReceiveMessage( MESSAGEQUEUE
*queue
)
331 MESSAGEQUEUE
*senderQ
= NULL
;
332 HQUEUE16 prevSender
= 0;
333 QSMCTRL
* prevCtrlPtr
= NULL
;
336 TRACE(msg
, "ReceiveMessage, queue %04x\n", queue
->self
);
337 if (!(queue
->wakeBits
& QS_SENDMESSAGE
) ||
338 !(senderQ
= (MESSAGEQUEUE
*)GlobalLock16( queue
->hSendingTask
)))
339 { TRACE(msg
,"\trcm: nothing to do\n"); return; }
341 if( !senderQ
->hPrevSendingTask
)
342 QUEUE_ClearWakeBit( queue
, QS_SENDMESSAGE
); /* no more sent messages */
344 /* Save current state on stack */
345 prevSender
= queue
->InSendMessageHandle
;
346 prevCtrlPtr
= queue
->smResultCurrent
;
348 /* Remove sending queue from the list */
349 queue
->InSendMessageHandle
= queue
->hSendingTask
;
350 queue
->smResultCurrent
= senderQ
->smResultInit
;
351 queue
->hSendingTask
= senderQ
->hPrevSendingTask
;
353 TRACE(msg
, "\trcm: smResultCurrent = %08x, prevCtrl = %08x\n",
354 (unsigned)queue
->smResultCurrent
, (unsigned)prevCtrlPtr
);
355 QUEUE_SetWakeBit( senderQ
, QS_SMPARAMSFREE
);
357 TRACE(msg
, "\trcm: calling wndproc - %04x %04x %04x%04x %08x\n",
358 senderQ
->hWnd
, senderQ
->msg
, senderQ
->wParamHigh
,
359 senderQ
->wParam
, (unsigned)senderQ
->lParam
);
361 if (IsWindow32( senderQ
->hWnd
))
363 WND
*wndPtr
= WIN_FindWndPtr( senderQ
->hWnd
);
364 DWORD extraInfo
= queue
->GetMessageExtraInfoVal
;
365 queue
->GetMessageExtraInfoVal
= senderQ
->GetMessageExtraInfoVal
;
367 if (senderQ
->flags
& QUEUE_SM_WIN32
)
369 WPARAM32 wParam
= MAKELONG( senderQ
->wParam
, senderQ
->wParamHigh
);
370 TRACE(msg
, "\trcm: msg is Win32\n" );
371 if (senderQ
->flags
& QUEUE_SM_UNICODE
)
372 result
= CallWindowProc32W( wndPtr
->winproc
,
373 senderQ
->hWnd
, senderQ
->msg
,
374 wParam
, senderQ
->lParam
);
376 result
= CallWindowProc32A( wndPtr
->winproc
,
377 senderQ
->hWnd
, senderQ
->msg
,
378 wParam
, senderQ
->lParam
);
380 else /* Win16 message */
381 result
= CallWindowProc16( (WNDPROC16
)wndPtr
->winproc
,
382 senderQ
->hWnd
, senderQ
->msg
,
383 senderQ
->wParam
, senderQ
->lParam
);
385 queue
->GetMessageExtraInfoVal
= extraInfo
; /* Restore extra info */
386 TRACE(msg
,"\trcm: result = %08x\n", (unsigned)result
);
388 else WARN(msg
, "\trcm: bad hWnd\n");
390 /* Return the result to the sender task */
391 ReplyMessage16( result
);
393 queue
->InSendMessageHandle
= prevSender
;
394 queue
->smResultCurrent
= prevCtrlPtr
;
396 TRACE(msg
,"done!\n");
399 /***********************************************************************
402 * Try to reply to all pending sent messages on exit.
404 void QUEUE_FlushMessages( HQUEUE16 hQueue
)
406 MESSAGEQUEUE
*queue
= (MESSAGEQUEUE
*)GlobalLock16( hQueue
);
410 MESSAGEQUEUE
*senderQ
= (MESSAGEQUEUE
*)GlobalLock16( queue
->hSendingTask
);
411 QSMCTRL
* CtrlPtr
= queue
->smResultCurrent
;
413 TRACE(msg
,"Flushing queue %04x:\n", hQueue
);
418 CtrlPtr
= senderQ
->smResultInit
;
420 TRACE(msg
,"\tfrom queue %04x, smResult %08x\n", queue
->hSendingTask
, (unsigned)CtrlPtr
);
422 if( !(queue
->hSendingTask
= senderQ
->hPrevSendingTask
) )
423 QUEUE_ClearWakeBit( queue
, QS_SENDMESSAGE
);
425 QUEUE_SetWakeBit( senderQ
, QS_SMPARAMSFREE
);
427 queue
->smResultCurrent
= CtrlPtr
;
428 while( senderQ
->wakeBits
& QS_SMRESULT
) OldYield();
430 senderQ
->SendMessageReturn
= 0;
431 senderQ
->smResult
= queue
->smResultCurrent
;
432 QUEUE_SetWakeBit( senderQ
, QS_SMRESULT
);
434 senderQ
= (MESSAGEQUEUE
*)GlobalLock16( queue
->hSendingTask
);
437 queue
->InSendMessageHandle
= 0;
441 /***********************************************************************
444 * Add a message to the queue. Return FALSE if queue is full.
446 BOOL32
QUEUE_AddMsg( HQUEUE16 hQueue
, MSG16
* msg
, DWORD extraInfo
)
449 MESSAGEQUEUE
*msgQueue
;
451 SIGNAL_MaskAsyncEvents( TRUE
);
453 if (!(msgQueue
= (MESSAGEQUEUE
*)GlobalLock16( hQueue
))) return FALSE
;
454 pos
= msgQueue
->nextFreeMessage
;
456 /* Check if queue is full */
457 if ((pos
== msgQueue
->nextMessage
) && (msgQueue
->msgCount
> 0))
459 SIGNAL_MaskAsyncEvents( FALSE
);
460 WARN( msg
,"Queue is full!\n" );
465 msgQueue
->messages
[pos
].msg
= *msg
;
466 msgQueue
->messages
[pos
].extraInfo
= extraInfo
;
467 if (pos
< msgQueue
->queueSize
-1) pos
++;
469 msgQueue
->nextFreeMessage
= pos
;
470 msgQueue
->msgCount
++;
472 SIGNAL_MaskAsyncEvents( FALSE
);
474 QUEUE_SetWakeBit( msgQueue
, QS_POSTMESSAGE
);
479 /***********************************************************************
482 * Find a message matching the given parameters. Return -1 if none available.
484 int QUEUE_FindMsg( MESSAGEQUEUE
* msgQueue
, HWND32 hwnd
, int first
, int last
)
486 int i
, pos
= msgQueue
->nextMessage
;
488 TRACE(msg
,"hwnd=%04x pos=%d\n", hwnd
, pos
);
490 if (!msgQueue
->msgCount
) return -1;
491 if (!hwnd
&& !first
&& !last
) return pos
;
493 for (i
= 0; i
< msgQueue
->msgCount
; i
++)
495 MSG16
* msg
= &msgQueue
->messages
[pos
].msg
;
497 if (!hwnd
|| (msg
->hwnd
== hwnd
))
499 if (!first
&& !last
) return pos
;
500 if ((msg
->message
>= first
) && (msg
->message
<= last
)) return pos
;
502 if (pos
< msgQueue
->queueSize
-1) pos
++;
509 /***********************************************************************
512 * Remove a message from the queue (pos must be a valid position).
514 void QUEUE_RemoveMsg( MESSAGEQUEUE
* msgQueue
, int pos
)
516 SIGNAL_MaskAsyncEvents( TRUE
);
518 if (pos
>= msgQueue
->nextMessage
)
520 for ( ; pos
> msgQueue
->nextMessage
; pos
--)
521 msgQueue
->messages
[pos
] = msgQueue
->messages
[pos
-1];
522 msgQueue
->nextMessage
++;
523 if (msgQueue
->nextMessage
>= msgQueue
->queueSize
)
524 msgQueue
->nextMessage
= 0;
528 for ( ; pos
< msgQueue
->nextFreeMessage
; pos
++)
529 msgQueue
->messages
[pos
] = msgQueue
->messages
[pos
+1];
530 if (msgQueue
->nextFreeMessage
) msgQueue
->nextFreeMessage
--;
531 else msgQueue
->nextFreeMessage
= msgQueue
->queueSize
-1;
533 msgQueue
->msgCount
--;
534 if (!msgQueue
->msgCount
) msgQueue
->wakeBits
&= ~QS_POSTMESSAGE
;
536 SIGNAL_MaskAsyncEvents( FALSE
);
540 /***********************************************************************
543 * Wake a queue upon reception of a hardware event.
545 static void QUEUE_WakeSomeone( UINT32 message
)
550 MESSAGEQUEUE
*queue
= pCursorQueue
;
552 if( (message
>= WM_KEYFIRST
) && (message
<= WM_KEYLAST
) )
555 if( pActiveQueue
) queue
= pActiveQueue
;
559 wakeBit
= (message
== WM_MOUSEMOVE
) ? QS_MOUSEMOVE
: QS_MOUSEBUTTON
;
560 if( (hwnd
= GetCapture32()) )
561 if( (wndPtr
= WIN_FindWndPtr( hwnd
)) )
562 queue
= (MESSAGEQUEUE
*)GlobalLock16( wndPtr
->hmemTaskQ
);
565 if( (hwnd
= GetSysModalWindow16()) )
566 if( (wndPtr
= WIN_FindWndPtr( hwnd
)) )
567 queue
= (MESSAGEQUEUE
*)GlobalLock16( wndPtr
->hmemTaskQ
);
571 queue
= GlobalLock16( hFirstQueue
);
574 if (queue
->wakeMask
& wakeBit
) break;
575 queue
= GlobalLock16( queue
->next
);
579 WARN(msg
, "couldn't find queue\n");
584 QUEUE_SetWakeBit( queue
, wakeBit
);
588 /***********************************************************************
591 * Add an event to the system message queue.
592 * Note: the position is relative to the desktop window.
594 void hardware_event( WORD message
, WORD wParam
, LONG lParam
,
595 int xPos
, int yPos
, DWORD time
, DWORD extraInfo
)
600 if (!sysMsgQueue
) return;
601 pos
= sysMsgQueue
->nextFreeMessage
;
603 /* Merge with previous event if possible */
605 if ((message
== WM_MOUSEMOVE
) && sysMsgQueue
->msgCount
)
608 else pos
= sysMsgQueue
->queueSize
- 1;
609 msg
= &sysMsgQueue
->messages
[pos
].msg
;
610 if ((msg
->message
== message
) && (msg
->wParam
== wParam
))
611 sysMsgQueue
->msgCount
--; /* Merge events */
613 pos
= sysMsgQueue
->nextFreeMessage
; /* Don't merge */
616 /* Check if queue is full */
618 if ((pos
== sysMsgQueue
->nextMessage
) && sysMsgQueue
->msgCount
)
620 /* Queue is full, beep (but not on every mouse motion...) */
621 if (message
!= WM_MOUSEMOVE
) MessageBeep32(0);
627 msg
= &sysMsgQueue
->messages
[pos
].msg
;
629 msg
->message
= message
;
630 msg
->wParam
= wParam
;
631 msg
->lParam
= lParam
;
633 msg
->pt
.x
= xPos
& 0xffff;
634 msg
->pt
.y
= yPos
& 0xffff;
635 sysMsgQueue
->messages
[pos
].extraInfo
= extraInfo
;
636 if (pos
< sysMsgQueue
->queueSize
- 1) pos
++;
638 sysMsgQueue
->nextFreeMessage
= pos
;
639 sysMsgQueue
->msgCount
++;
640 QUEUE_WakeSomeone( message
);
644 /***********************************************************************
647 HTASK16
QUEUE_GetQueueTask( HQUEUE16 hQueue
)
649 MESSAGEQUEUE
*queue
= GlobalLock16( hQueue
);
650 return (queue
) ? queue
->hTask
: 0 ;
654 /***********************************************************************
655 * QUEUE_IncPaintCount
657 void QUEUE_IncPaintCount( HQUEUE16 hQueue
)
661 if (!(queue
= (MESSAGEQUEUE
*)GlobalLock16( hQueue
))) return;
662 queue
->wPaintCount
++;
663 QUEUE_SetWakeBit( queue
, QS_PAINT
);
667 /***********************************************************************
668 * QUEUE_DecPaintCount
670 void QUEUE_DecPaintCount( HQUEUE16 hQueue
)
674 if (!(queue
= (MESSAGEQUEUE
*)GlobalLock16( hQueue
))) return;
675 queue
->wPaintCount
--;
676 if (!queue
->wPaintCount
) queue
->wakeBits
&= ~QS_PAINT
;
680 /***********************************************************************
681 * QUEUE_IncTimerCount
683 void QUEUE_IncTimerCount( HQUEUE16 hQueue
)
687 if (!(queue
= (MESSAGEQUEUE
*)GlobalLock16( hQueue
))) return;
688 queue
->wTimerCount
++;
689 QUEUE_SetWakeBit( queue
, QS_TIMER
);
693 /***********************************************************************
694 * QUEUE_DecTimerCount
696 void QUEUE_DecTimerCount( HQUEUE16 hQueue
)
700 if (!(queue
= (MESSAGEQUEUE
*)GlobalLock16( hQueue
))) return;
701 queue
->wTimerCount
--;
702 if (!queue
->wTimerCount
) queue
->wakeBits
&= ~QS_TIMER
;
706 /***********************************************************************
707 * PostQuitMessage16 (USER.6)
709 void WINAPI
PostQuitMessage16( INT16 exitCode
)
711 PostQuitMessage32( exitCode
);
715 /***********************************************************************
716 * PostQuitMessage32 (USER32.421)
718 * PostQuitMessage() posts a message to the system requesting an
719 * application to terminate execution. As a result of this function,
720 * the WM_QUIT message is posted to the application, and
721 * PostQuitMessage() returns immediately. The exitCode parameter
722 * specifies an application-defined exit code, which appears in the
723 * _wParam_ parameter of the WM_QUIT message posted to the application.
729 void WINAPI
PostQuitMessage32( INT32 exitCode
)
733 if (!(queue
= (MESSAGEQUEUE
*)GlobalLock16( GetFastQueue() ))) return;
734 queue
->wPostQMsg
= TRUE
;
735 queue
->wExitCode
= (WORD
)exitCode
;
739 /***********************************************************************
740 * GetWindowTask16 (USER.224)
742 HTASK16 WINAPI
GetWindowTask16( HWND16 hwnd
)
744 WND
*wndPtr
= WIN_FindWndPtr( hwnd
);
746 if (!wndPtr
) return 0;
747 return QUEUE_GetQueueTask( wndPtr
->hmemTaskQ
);
750 /***********************************************************************
751 * GetWindowThreadProcessId (USER32.313)
753 DWORD WINAPI
GetWindowThreadProcessId( HWND32 hwnd
, LPDWORD process
)
758 WND
*wndPtr
= WIN_FindWndPtr( hwnd
);
760 if (!wndPtr
) return 0;
761 htask
=QUEUE_GetQueueTask( wndPtr
->hmemTaskQ
);
762 tdb
= (TDB
*)GlobalLock16(htask
);
763 if (!tdb
|| !tdb
->thdb
) return 0;
764 if (process
) *process
= PDB_TO_PROCESS_ID( tdb
->thdb
->process
);
765 return THDB_TO_THREAD_ID( tdb
->thdb
);
769 /***********************************************************************
770 * SetMessageQueue16 (USER.266)
772 BOOL16 WINAPI
SetMessageQueue16( INT16 size
)
774 return SetMessageQueue32( size
);
778 /***********************************************************************
779 * SetMessageQueue32 (USER32.494)
781 BOOL32 WINAPI
SetMessageQueue32( INT32 size
)
783 HQUEUE16 hQueue
, hNewQueue
;
784 MESSAGEQUEUE
*queuePtr
;
786 TRACE(msg
,"task %04x size %i\n", GetCurrentTask(), size
);
788 if ((size
> MAX_QUEUE_SIZE
) || (size
<= 0)) return FALSE
;
790 if( !(hNewQueue
= QUEUE_CreateMsgQueue( size
)))
792 WARN(msg
, "failed!\n");
795 queuePtr
= (MESSAGEQUEUE
*)GlobalLock16( hNewQueue
);
797 SIGNAL_MaskAsyncEvents( TRUE
);
799 /* Copy data and free the old message queue */
800 if ((hQueue
= GetThreadQueue(0)) != 0)
802 MESSAGEQUEUE
*oldQ
= (MESSAGEQUEUE
*)GlobalLock16( hQueue
);
803 memcpy( &queuePtr
->wParamHigh
, &oldQ
->wParamHigh
,
804 (int)oldQ
->messages
- (int)(&oldQ
->wParamHigh
) );
805 HOOK_ResetQueueHooks( hNewQueue
);
806 if( WIN_GetDesktop()->hmemTaskQ
== hQueue
)
807 WIN_GetDesktop()->hmemTaskQ
= hNewQueue
;
808 WIN_ResetQueueWindows( WIN_GetDesktop(), hQueue
, hNewQueue
);
809 CLIPBOARD_ResetLock( hQueue
, hNewQueue
);
810 QUEUE_DeleteMsgQueue( hQueue
);
813 /* Link new queue into list */
814 queuePtr
->hTask
= GetCurrentTask();
815 queuePtr
->next
= hFirstQueue
;
816 hFirstQueue
= hNewQueue
;
818 if( !queuePtr
->next
) pCursorQueue
= queuePtr
;
819 SetThreadQueue( 0, hNewQueue
);
821 SIGNAL_MaskAsyncEvents( FALSE
);
825 /***********************************************************************
826 * InitThreadInput (USER.409)
828 HQUEUE16 WINAPI
InitThreadInput( WORD unknown
, WORD flags
)
830 HQUEUE16 hQueue
= GetTaskQueue( 0 );
832 FIXME( msg
, "(%04X,%04X): should create thread-local message queue!\n",
835 SetFastQueue( 0, hQueue
);
839 /***********************************************************************
840 * GetQueueStatus16 (USER.334)
842 DWORD WINAPI
GetQueueStatus16( UINT16 flags
)
847 if (!(queue
= (MESSAGEQUEUE
*)GlobalLock16( GetFastQueue() ))) return 0;
848 ret
= MAKELONG( queue
->changeBits
, queue
->wakeBits
);
849 queue
->changeBits
= 0;
850 return ret
& MAKELONG( flags
, flags
);
853 /***********************************************************************
854 * GetQueueStatus32 (USER32.283)
856 DWORD WINAPI
GetQueueStatus32( UINT32 flags
)
861 if (!(queue
= (MESSAGEQUEUE
*)GlobalLock16( GetFastQueue() ))) return 0;
862 ret
= MAKELONG( queue
->changeBits
, queue
->wakeBits
);
863 queue
->changeBits
= 0;
864 return ret
& MAKELONG( flags
, flags
);
868 /***********************************************************************
869 * GetInputState16 (USER.335)
871 BOOL16 WINAPI
GetInputState16(void)
873 return GetInputState32();
876 /***********************************************************************
877 * WaitForInputIdle (USER32.577)
879 DWORD WINAPI
WaitForInputIdle (HANDLE32 hProcess
, DWORD dwTimeOut
)
881 FIXME (msg
, "(hProcess=%d, dwTimeOut=%ld): stub\n", hProcess
, dwTimeOut
);
887 /***********************************************************************
888 * GetInputState32 (USER32.244)
890 BOOL32 WINAPI
GetInputState32(void)
894 if (!(queue
= (MESSAGEQUEUE
*)GlobalLock16( GetFastQueue() )))
896 return queue
->wakeBits
& (QS_KEY
| QS_MOUSEBUTTON
);
899 /***********************************************************************
900 * UserYield (USER.332)
902 void WINAPI
UserYield(void)
904 TDB
*pCurTask
= (TDB
*)GlobalLock16( GetCurrentTask() );
905 MESSAGEQUEUE
*queue
= (MESSAGEQUEUE
*)GlobalLock16( pCurTask
->hQueue
);
907 if ( !THREAD_IsWin16( THREAD_Current() ) )
909 FIXME(task
, "called for Win32 thread (%04x)!\n", THREAD_Current()->teb_sel
);
913 /* Handle sent messages */
914 while (queue
&& (queue
->wakeBits
& QS_SENDMESSAGE
))
915 QUEUE_ReceiveMessage( queue
);
919 queue
= (MESSAGEQUEUE
*)GlobalLock16( pCurTask
->hQueue
);
920 while (queue
&& (queue
->wakeBits
& QS_SENDMESSAGE
))
921 QUEUE_ReceiveMessage( queue
);
924 /***********************************************************************
925 * GetMessagePos (USER.119) (USER32.272)
927 * The GetMessagePos() function returns a long value representing a
928 * cursor position, in screen coordinates, when the last message
929 * retrieved by the GetMessage() function occurs. The x-coordinate is
930 * in the low-order word of the return value, the y-coordinate is in
931 * the high-order word. The application can use the MAKEPOINT()
932 * macro to obtain a POINT structure from the return value.
934 * For the current cursor position, use GetCursorPos().
938 * Cursor position of last message on success, zero on failure.
945 DWORD WINAPI
GetMessagePos(void)
949 if (!(queue
= (MESSAGEQUEUE
*)GlobalLock16( GetFastQueue() ))) return 0;
950 return queue
->GetMessagePosVal
;
954 /***********************************************************************
955 * GetMessageTime (USER.120) (USER32.273)
957 * GetMessageTime() returns the message time for the last message
958 * retrieved by the function. The time is measured in milliseconds with
959 * the same offset as GetTickCount().
961 * Since the tick count wraps, this is only useful for moderately short
962 * relative time comparisons.
966 * Time of last message on success, zero on failure.
973 LONG WINAPI
GetMessageTime(void)
977 if (!(queue
= (MESSAGEQUEUE
*)GlobalLock16( GetFastQueue() ))) return 0;
978 return queue
->GetMessageTimeVal
;
982 /***********************************************************************
983 * GetMessageExtraInfo (USER.288) (USER32.271)
985 LONG WINAPI
GetMessageExtraInfo(void)
989 if (!(queue
= (MESSAGEQUEUE
*)GlobalLock16( GetFastQueue() ))) return 0;
990 return queue
->GetMessageExtraInfoVal
;