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
)
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 ... */
239 pdb
= pTask
->thdb
->process
;
240 entry
= pdb
? pdb
->thread_list
->next
: NULL
;
245 if (entry
->thread
->wait_struct
.wait_msg
)
247 SYNC_MsgWakeUp( entry
->thread
);
250 if (entry
== pdb
->thread_list
) break;
259 /***********************************************************************
262 void QUEUE_Wait( void )
264 if ( THREAD_IsWin16( THREAD_Current() ) )
268 TRACE(msg
, "current task is 32-bit, calling SYNC_DoWait\n");
269 SYNC_DoWait( 0, NULL
, FALSE
, INFINITE32
, FALSE
, TRUE
);
274 /***********************************************************************
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
)
291 QUEUE_Signal( queue
->hTask
);
296 /***********************************************************************
299 void QUEUE_ClearWakeBit( MESSAGEQUEUE
*queue
, WORD bit
)
301 queue
->changeBits
&= ~bit
;
302 queue
->wakeBits
&= ~bit
;
306 /***********************************************************************
309 * See "Windows Internals", p.447
311 void QUEUE_WaitBits( WORD bits
)
315 TRACE(msg
,"q %04x waiting for %04x\n", GetFastQueue(), bits
);
319 if (!(queue
= (MESSAGEQUEUE
*)GlobalLock16( GetFastQueue() ))) return;
321 if (queue
->changeBits
& bits
)
323 /* One of the bits is set; we can return */
327 if (queue
->wakeBits
& QS_SENDMESSAGE
)
329 /* Process the sent message immediately */
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
);
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
;
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
)
364 QUEUE_ClearWakeBit( queue
, QS_SENDMESSAGE
); /* no more sent messages */
366 /* Save current state on stack */
367 prevSender
= queue
->InSendMessageHandle
;
368 prevCtrlPtr
= queue
->smResultCurrent
;
370 /* Remove sending queue from the list */
371 queue
->InSendMessageHandle
= queue
->hSendingTask
;
372 queue
->smResultCurrent
= senderQ
->smResultInit
;
373 queue
->hSendingTask
= senderQ
->hPrevSendingTask
;
375 TRACE(msg
, "\trcm: smResultCurrent = %08x, prevCtrl = %08x\n",
376 (unsigned)queue
->smResultCurrent
, (unsigned)prevCtrlPtr
);
377 QUEUE_SetWakeBit( senderQ
, QS_SMPARAMSFREE
);
379 TRACE(msg
, "\trcm: calling wndproc - %04x %04x %04x%04x %08x\n",
380 senderQ
->hWnd
, senderQ
->msg
, senderQ
->wParamHigh
,
381 senderQ
->wParam
, (unsigned)senderQ
->lParam
);
383 if (IsWindow32( senderQ
->hWnd
))
385 WND
*wndPtr
= WIN_FindWndPtr( senderQ
->hWnd
);
386 DWORD extraInfo
= queue
->GetMessageExtraInfoVal
;
387 queue
->GetMessageExtraInfoVal
= senderQ
->GetMessageExtraInfoVal
;
389 if (senderQ
->flags
& QUEUE_SM_WIN32
)
391 WPARAM32 wParam
= MAKELONG( senderQ
->wParam
, senderQ
->wParamHigh
);
392 TRACE(msg
, "\trcm: msg is Win32\n" );
393 if (senderQ
->flags
& QUEUE_SM_UNICODE
)
394 result
= CallWindowProc32W( wndPtr
->winproc
,
395 senderQ
->hWnd
, senderQ
->msg
,
396 wParam
, senderQ
->lParam
);
398 result
= CallWindowProc32A( wndPtr
->winproc
,
399 senderQ
->hWnd
, senderQ
->msg
,
400 wParam
, senderQ
->lParam
);
402 else /* Win16 message */
403 result
= CallWindowProc16( (WNDPROC16
)wndPtr
->winproc
,
404 senderQ
->hWnd
, senderQ
->msg
,
405 senderQ
->wParam
, senderQ
->lParam
);
407 queue
->GetMessageExtraInfoVal
= extraInfo
; /* Restore extra info */
408 TRACE(msg
,"\trcm: result = %08x\n", (unsigned)result
);
410 else WARN(msg
, "\trcm: bad hWnd\n");
412 /* Return the result to the sender task */
413 ReplyMessage16( result
);
415 queue
->InSendMessageHandle
= prevSender
;
416 queue
->smResultCurrent
= prevCtrlPtr
;
418 TRACE(msg
,"done!\n");
421 /***********************************************************************
424 * Try to reply to all pending sent messages on exit.
426 void QUEUE_FlushMessages( HQUEUE16 hQueue
)
428 MESSAGEQUEUE
*queue
= (MESSAGEQUEUE
*)GlobalLock16( hQueue
);
432 MESSAGEQUEUE
*senderQ
= (MESSAGEQUEUE
*)GlobalLock16( queue
->hSendingTask
);
433 QSMCTRL
* CtrlPtr
= queue
->smResultCurrent
;
435 TRACE(msg
,"Flushing queue %04x:\n", hQueue
);
440 CtrlPtr
= senderQ
->smResultInit
;
442 TRACE(msg
,"\tfrom queue %04x, smResult %08x\n", queue
->hSendingTask
, (unsigned)CtrlPtr
);
444 if( !(queue
->hSendingTask
= senderQ
->hPrevSendingTask
) )
445 QUEUE_ClearWakeBit( queue
, QS_SENDMESSAGE
);
447 QUEUE_SetWakeBit( senderQ
, QS_SMPARAMSFREE
);
449 queue
->smResultCurrent
= CtrlPtr
;
450 while( senderQ
->wakeBits
& QS_SMRESULT
) OldYield();
452 senderQ
->SendMessageReturn
= 0;
453 senderQ
->smResult
= queue
->smResultCurrent
;
454 QUEUE_SetWakeBit( senderQ
, QS_SMRESULT
);
456 senderQ
= (MESSAGEQUEUE
*)GlobalLock16( queue
->hSendingTask
);
459 queue
->InSendMessageHandle
= 0;
463 /***********************************************************************
466 * Add a message to the queue. Return FALSE if queue is full.
468 BOOL32
QUEUE_AddMsg( HQUEUE16 hQueue
, MSG16
* msg
, DWORD extraInfo
)
471 MESSAGEQUEUE
*msgQueue
;
473 SIGNAL_MaskAsyncEvents( TRUE
);
475 if (!(msgQueue
= (MESSAGEQUEUE
*)GlobalLock16( hQueue
))) return FALSE
;
476 pos
= msgQueue
->nextFreeMessage
;
478 /* Check if queue is full */
479 if ((pos
== msgQueue
->nextMessage
) && (msgQueue
->msgCount
> 0))
481 SIGNAL_MaskAsyncEvents( FALSE
);
482 WARN( msg
,"Queue is full!\n" );
487 msgQueue
->messages
[pos
].msg
= *msg
;
488 msgQueue
->messages
[pos
].extraInfo
= extraInfo
;
489 if (pos
< msgQueue
->queueSize
-1) pos
++;
491 msgQueue
->nextFreeMessage
= pos
;
492 msgQueue
->msgCount
++;
494 SIGNAL_MaskAsyncEvents( FALSE
);
496 QUEUE_SetWakeBit( msgQueue
, QS_POSTMESSAGE
);
501 /***********************************************************************
504 * Find a message matching the given parameters. Return -1 if none available.
506 int QUEUE_FindMsg( MESSAGEQUEUE
* msgQueue
, HWND32 hwnd
, int first
, int last
)
508 int i
, pos
= msgQueue
->nextMessage
;
510 TRACE(msg
,"hwnd=%04x pos=%d\n", hwnd
, pos
);
512 if (!msgQueue
->msgCount
) return -1;
513 if (!hwnd
&& !first
&& !last
) return pos
;
515 for (i
= 0; i
< msgQueue
->msgCount
; i
++)
517 MSG16
* msg
= &msgQueue
->messages
[pos
].msg
;
519 if (!hwnd
|| (msg
->hwnd
== hwnd
))
521 if (!first
&& !last
) return pos
;
522 if ((msg
->message
>= first
) && (msg
->message
<= last
)) return pos
;
524 if (pos
< msgQueue
->queueSize
-1) pos
++;
531 /***********************************************************************
534 * Remove a message from the queue (pos must be a valid position).
536 void QUEUE_RemoveMsg( MESSAGEQUEUE
* msgQueue
, int pos
)
538 SIGNAL_MaskAsyncEvents( TRUE
);
540 if (pos
>= msgQueue
->nextMessage
)
542 for ( ; pos
> msgQueue
->nextMessage
; pos
--)
543 msgQueue
->messages
[pos
] = msgQueue
->messages
[pos
-1];
544 msgQueue
->nextMessage
++;
545 if (msgQueue
->nextMessage
>= msgQueue
->queueSize
)
546 msgQueue
->nextMessage
= 0;
550 for ( ; pos
< msgQueue
->nextFreeMessage
; pos
++)
551 msgQueue
->messages
[pos
] = msgQueue
->messages
[pos
+1];
552 if (msgQueue
->nextFreeMessage
) msgQueue
->nextFreeMessage
--;
553 else msgQueue
->nextFreeMessage
= msgQueue
->queueSize
-1;
555 msgQueue
->msgCount
--;
556 if (!msgQueue
->msgCount
) msgQueue
->wakeBits
&= ~QS_POSTMESSAGE
;
558 SIGNAL_MaskAsyncEvents( FALSE
);
562 /***********************************************************************
565 * Wake a queue upon reception of a hardware event.
567 static void QUEUE_WakeSomeone( UINT32 message
)
572 MESSAGEQUEUE
*queue
= pCursorQueue
;
574 if( (message
>= WM_KEYFIRST
) && (message
<= WM_KEYLAST
) )
577 if( pActiveQueue
) queue
= pActiveQueue
;
581 wakeBit
= (message
== WM_MOUSEMOVE
) ? QS_MOUSEMOVE
: QS_MOUSEBUTTON
;
582 if( (hwnd
= GetCapture32()) )
583 if( (wndPtr
= WIN_FindWndPtr( hwnd
)) )
584 queue
= (MESSAGEQUEUE
*)GlobalLock16( wndPtr
->hmemTaskQ
);
587 if( (hwnd
= GetSysModalWindow16()) )
588 if( (wndPtr
= WIN_FindWndPtr( hwnd
)) )
589 queue
= (MESSAGEQUEUE
*)GlobalLock16( wndPtr
->hmemTaskQ
);
593 queue
= GlobalLock16( hFirstQueue
);
596 if (queue
->wakeMask
& wakeBit
) break;
597 queue
= GlobalLock16( queue
->next
);
601 WARN(msg
, "couldn't find queue\n");
606 QUEUE_SetWakeBit( queue
, wakeBit
);
610 /***********************************************************************
613 * Add an event to the system message queue.
614 * Note: the position is relative to the desktop window.
616 void hardware_event( WORD message
, WORD wParam
, LONG lParam
,
617 int xPos
, int yPos
, DWORD time
, DWORD extraInfo
)
622 if (!sysMsgQueue
) return;
623 pos
= sysMsgQueue
->nextFreeMessage
;
625 /* Merge with previous event if possible */
627 if ((message
== WM_MOUSEMOVE
) && sysMsgQueue
->msgCount
)
630 else pos
= sysMsgQueue
->queueSize
- 1;
631 msg
= &sysMsgQueue
->messages
[pos
].msg
;
632 if ((msg
->message
== message
) && (msg
->wParam
== wParam
))
633 sysMsgQueue
->msgCount
--; /* Merge events */
635 pos
= sysMsgQueue
->nextFreeMessage
; /* Don't merge */
638 /* Check if queue is full */
640 if ((pos
== sysMsgQueue
->nextMessage
) && sysMsgQueue
->msgCount
)
642 /* Queue is full, beep (but not on every mouse motion...) */
643 if (message
!= WM_MOUSEMOVE
) MessageBeep32(0);
649 msg
= &sysMsgQueue
->messages
[pos
].msg
;
651 msg
->message
= message
;
652 msg
->wParam
= wParam
;
653 msg
->lParam
= lParam
;
655 msg
->pt
.x
= xPos
& 0xffff;
656 msg
->pt
.y
= yPos
& 0xffff;
657 sysMsgQueue
->messages
[pos
].extraInfo
= extraInfo
;
658 if (pos
< sysMsgQueue
->queueSize
- 1) pos
++;
660 sysMsgQueue
->nextFreeMessage
= pos
;
661 sysMsgQueue
->msgCount
++;
662 QUEUE_WakeSomeone( message
);
666 /***********************************************************************
669 HTASK16
QUEUE_GetQueueTask( HQUEUE16 hQueue
)
671 MESSAGEQUEUE
*queue
= GlobalLock16( hQueue
);
672 return (queue
) ? queue
->hTask
: 0 ;
676 /***********************************************************************
677 * QUEUE_IncPaintCount
679 void QUEUE_IncPaintCount( HQUEUE16 hQueue
)
683 if (!(queue
= (MESSAGEQUEUE
*)GlobalLock16( hQueue
))) return;
684 queue
->wPaintCount
++;
685 QUEUE_SetWakeBit( queue
, QS_PAINT
);
689 /***********************************************************************
690 * QUEUE_DecPaintCount
692 void QUEUE_DecPaintCount( HQUEUE16 hQueue
)
696 if (!(queue
= (MESSAGEQUEUE
*)GlobalLock16( hQueue
))) return;
697 queue
->wPaintCount
--;
698 if (!queue
->wPaintCount
) queue
->wakeBits
&= ~QS_PAINT
;
702 /***********************************************************************
703 * QUEUE_IncTimerCount
705 void QUEUE_IncTimerCount( HQUEUE16 hQueue
)
709 if (!(queue
= (MESSAGEQUEUE
*)GlobalLock16( hQueue
))) return;
710 queue
->wTimerCount
++;
711 QUEUE_SetWakeBit( queue
, QS_TIMER
);
715 /***********************************************************************
716 * QUEUE_DecTimerCount
718 void QUEUE_DecTimerCount( HQUEUE16 hQueue
)
722 if (!(queue
= (MESSAGEQUEUE
*)GlobalLock16( hQueue
))) return;
723 queue
->wTimerCount
--;
724 if (!queue
->wTimerCount
) queue
->wakeBits
&= ~QS_TIMER
;
728 /***********************************************************************
729 * PostQuitMessage16 (USER.6)
731 void WINAPI
PostQuitMessage16( INT16 exitCode
)
733 PostQuitMessage32( exitCode
);
737 /***********************************************************************
738 * PostQuitMessage32 (USER32.421)
740 * PostQuitMessage() posts a message to the system requesting an
741 * application to terminate execution. As a result of this function,
742 * the WM_QUIT message is posted to the application, and
743 * PostQuitMessage() returns immediately. The exitCode parameter
744 * specifies an application-defined exit code, which appears in the
745 * _wParam_ parameter of the WM_QUIT message posted to the application.
751 void WINAPI
PostQuitMessage32( INT32 exitCode
)
755 if (!(queue
= (MESSAGEQUEUE
*)GlobalLock16( GetFastQueue() ))) return;
756 queue
->wPostQMsg
= TRUE
;
757 queue
->wExitCode
= (WORD
)exitCode
;
761 /***********************************************************************
762 * GetWindowTask16 (USER.224)
764 HTASK16 WINAPI
GetWindowTask16( HWND16 hwnd
)
766 WND
*wndPtr
= WIN_FindWndPtr( hwnd
);
768 if (!wndPtr
) return 0;
769 return QUEUE_GetQueueTask( wndPtr
->hmemTaskQ
);
772 /***********************************************************************
773 * GetWindowThreadProcessId (USER32.313)
775 DWORD WINAPI
GetWindowThreadProcessId( HWND32 hwnd
, LPDWORD process
)
780 WND
*wndPtr
= WIN_FindWndPtr( hwnd
);
782 if (!wndPtr
) return 0;
783 htask
=QUEUE_GetQueueTask( wndPtr
->hmemTaskQ
);
784 tdb
= (TDB
*)GlobalLock16(htask
);
785 if (!tdb
|| !tdb
->thdb
) return 0;
786 if (process
) *process
= PDB_TO_PROCESS_ID( tdb
->thdb
->process
);
787 return THDB_TO_THREAD_ID( tdb
->thdb
);
791 /***********************************************************************
792 * SetMessageQueue16 (USER.266)
794 BOOL16 WINAPI
SetMessageQueue16( INT16 size
)
796 return SetMessageQueue32( size
);
800 /***********************************************************************
801 * SetMessageQueue32 (USER32.494)
803 BOOL32 WINAPI
SetMessageQueue32( INT32 size
)
805 HQUEUE16 hQueue
, hNewQueue
;
806 MESSAGEQUEUE
*queuePtr
;
808 TRACE(msg
,"task %04x size %i\n", GetCurrentTask(), size
);
810 if ((size
> MAX_QUEUE_SIZE
) || (size
<= 0)) return FALSE
;
812 if( !(hNewQueue
= QUEUE_CreateMsgQueue( size
)))
814 WARN(msg
, "failed!\n");
817 queuePtr
= (MESSAGEQUEUE
*)GlobalLock16( hNewQueue
);
819 SIGNAL_MaskAsyncEvents( TRUE
);
821 /* Copy data and free the old message queue */
822 if ((hQueue
= GetThreadQueue(0)) != 0)
824 MESSAGEQUEUE
*oldQ
= (MESSAGEQUEUE
*)GlobalLock16( hQueue
);
825 memcpy( &queuePtr
->wParamHigh
, &oldQ
->wParamHigh
,
826 (int)oldQ
->messages
- (int)(&oldQ
->wParamHigh
) );
827 HOOK_ResetQueueHooks( hNewQueue
);
828 if( WIN_GetDesktop()->hmemTaskQ
== hQueue
)
829 WIN_GetDesktop()->hmemTaskQ
= hNewQueue
;
830 WIN_ResetQueueWindows( WIN_GetDesktop(), hQueue
, hNewQueue
);
831 CLIPBOARD_ResetLock( hQueue
, hNewQueue
);
832 QUEUE_DeleteMsgQueue( hQueue
);
835 /* Link new queue into list */
836 queuePtr
->hTask
= GetCurrentTask();
837 queuePtr
->next
= hFirstQueue
;
838 hFirstQueue
= hNewQueue
;
840 if( !queuePtr
->next
) pCursorQueue
= queuePtr
;
841 SetThreadQueue( 0, hNewQueue
);
843 SIGNAL_MaskAsyncEvents( FALSE
);
847 /***********************************************************************
848 * InitThreadInput (USER.409)
850 HQUEUE16 WINAPI
InitThreadInput( WORD unknown
, WORD flags
)
852 HQUEUE16 hQueue
= GetTaskQueue( 0 );
854 FIXME( msg
, "(%04X,%04X): should create thread-local message queue!\n",
857 SetFastQueue( 0, hQueue
);
861 /***********************************************************************
862 * GetQueueStatus16 (USER.334)
864 DWORD WINAPI
GetQueueStatus16( UINT16 flags
)
869 if (!(queue
= (MESSAGEQUEUE
*)GlobalLock16( GetFastQueue() ))) return 0;
870 ret
= MAKELONG( queue
->changeBits
, queue
->wakeBits
);
871 queue
->changeBits
= 0;
872 return ret
& MAKELONG( flags
, flags
);
875 /***********************************************************************
876 * GetQueueStatus32 (USER32.283)
878 DWORD WINAPI
GetQueueStatus32( UINT32 flags
)
883 if (!(queue
= (MESSAGEQUEUE
*)GlobalLock16( GetFastQueue() ))) return 0;
884 ret
= MAKELONG( queue
->changeBits
, queue
->wakeBits
);
885 queue
->changeBits
= 0;
886 return ret
& MAKELONG( flags
, flags
);
890 /***********************************************************************
891 * GetInputState16 (USER.335)
893 BOOL16 WINAPI
GetInputState16(void)
895 return GetInputState32();
898 /***********************************************************************
899 * WaitForInputIdle (USER32.577)
901 DWORD WINAPI
WaitForInputIdle (HANDLE32 hProcess
, DWORD dwTimeOut
)
903 FIXME (msg
, "(hProcess=%d, dwTimeOut=%ld): stub\n", hProcess
, dwTimeOut
);
909 /***********************************************************************
910 * GetInputState32 (USER32.244)
912 BOOL32 WINAPI
GetInputState32(void)
916 if (!(queue
= (MESSAGEQUEUE
*)GlobalLock16( GetFastQueue() )))
918 return queue
->wakeBits
& (QS_KEY
| QS_MOUSEBUTTON
);
921 /***********************************************************************
922 * UserYield (USER.332)
924 void WINAPI
UserYield(void)
926 TDB
*pCurTask
= (TDB
*)GlobalLock16( GetCurrentTask() );
927 MESSAGEQUEUE
*queue
= (MESSAGEQUEUE
*)GlobalLock16( pCurTask
->hQueue
);
929 if ( !THREAD_IsWin16( THREAD_Current() ) )
931 FIXME(task
, "called for Win32 thread (%04x)!\n", THREAD_Current()->teb_sel
);
935 /* Handle sent messages */
936 while (queue
&& (queue
->wakeBits
& QS_SENDMESSAGE
))
937 QUEUE_ReceiveMessage( queue
);
941 queue
= (MESSAGEQUEUE
*)GlobalLock16( pCurTask
->hQueue
);
942 while (queue
&& (queue
->wakeBits
& QS_SENDMESSAGE
))
943 QUEUE_ReceiveMessage( queue
);
946 /***********************************************************************
947 * GetMessagePos (USER.119) (USER32.272)
949 * The GetMessagePos() function returns a long value representing a
950 * cursor position, in screen coordinates, when the last message
951 * retrieved by the GetMessage() function occurs. The x-coordinate is
952 * in the low-order word of the return value, the y-coordinate is in
953 * the high-order word. The application can use the MAKEPOINT()
954 * macro to obtain a POINT structure from the return value.
956 * For the current cursor position, use GetCursorPos().
960 * Cursor position of last message on success, zero on failure.
967 DWORD WINAPI
GetMessagePos(void)
971 if (!(queue
= (MESSAGEQUEUE
*)GlobalLock16( GetFastQueue() ))) return 0;
972 return queue
->GetMessagePosVal
;
976 /***********************************************************************
977 * GetMessageTime (USER.120) (USER32.273)
979 * GetMessageTime() returns the message time for the last message
980 * retrieved by the function. The time is measured in milliseconds with
981 * the same offset as GetTickCount().
983 * Since the tick count wraps, this is only useful for moderately short
984 * relative time comparisons.
988 * Time of last message on success, zero on failure.
995 LONG WINAPI
GetMessageTime(void)
999 if (!(queue
= (MESSAGEQUEUE
*)GlobalLock16( GetFastQueue() ))) return 0;
1000 return queue
->GetMessageTimeVal
;
1004 /***********************************************************************
1005 * GetMessageExtraInfo (USER.288) (USER32.271)
1007 LONG WINAPI
GetMessageExtraInfo(void)
1009 MESSAGEQUEUE
*queue
;
1011 if (!(queue
= (MESSAGEQUEUE
*)GlobalLock16( GetFastQueue() ))) return 0;
1012 return queue
->GetMessageExtraInfoVal
;