2 * Message queues related functions
4 * Copyright 1993, 1994 Alexandre Julliard
11 #include <sys/types.h>
13 #include "wine/winbase16.h"
18 #include "sysmetrics.h"
34 #define WM_NCMOUSEFIRST WM_NCMOUSEMOVE
35 #define WM_NCMOUSELAST WM_NCMBUTTONDBLCLK
38 typedef enum { SYSQ_MSG_ABANDON, SYSQ_MSG_SKIP,
39 SYSQ_MSG_ACCEPT, SYSQ_MSG_CONTINUE } SYSQ_STATUS;
41 extern HQUEUE16 hCursorQueue; /* queue.c */
43 DWORD MSG_WineStartTicks; /* Ticks at Wine startup */
45 static UINT doubleClickSpeed = 452;
47 /***********************************************************************
50 BOOL MSG_CheckFilter(DWORD uMsg, DWORD first, DWORD last)
53 return (uMsg >= first && uMsg <= last);
57 /***********************************************************************
58 * MSG_SendParentNotify
60 * Send a WM_PARENTNOTIFY to all ancestors of the given window, unless
61 * the window has the WS_EX_NOPARENTNOTIFY style.
63 static void MSG_SendParentNotify(WND* wndPtr, WORD event, WORD idChild, LPARAM lValue)
65 #define lppt ((LPPOINT16)&lValue)
67 /* pt has to be in the client coordinates of the parent window */
69 MapWindowPoints16( 0, wndPtr->hwndSelf, lppt, 1 );
72 if (!(wndPtr->dwStyle & WS_CHILD) || (wndPtr->dwExStyle & WS_EX_NOPARENTNOTIFY)) break;
73 lppt->x += wndPtr->rectClient.left;
74 lppt->y += wndPtr->rectClient.top;
75 wndPtr = wndPtr->parent;
76 SendMessageA( wndPtr->hwndSelf, WM_PARENTNOTIFY,
77 MAKEWPARAM( event, idChild ), lValue );
83 /***********************************************************************
84 * MSG_TranslateMouseMsg
86 * Translate an mouse hardware event into a real mouse message.
87 * Return value indicates whether the translated message must be passed
88 * to the user, left in the queue, or skipped entirely (in this case
89 * HIWORD contains hit test code).
91 static DWORD MSG_TranslateMouseMsg( HWND hTopWnd, DWORD first, DWORD last,
92 MSG *msg, BOOL remove, WND* pWndScope )
94 static DWORD dblclk_time_limit = 0;
95 static UINT16 clk_message = 0;
96 static HWND16 clk_hwnd = 0;
97 static POINT16 clk_pos = { 0, 0 };
101 INT16 ht, hittest, sendSC = 0;
102 UINT message = msg->message;
103 POINT16 screen_pt, pt;
104 HANDLE16 hQ = GetFastQueue16();
105 MESSAGEQUEUE *queue = (MESSAGEQUEUE *)QUEUE_Lock(hQ);
107 BOOL mouseClick = ((message == WM_LBUTTONDOWN) ||
108 (message == WM_RBUTTONDOWN) ||
109 (message == WM_MBUTTONDOWN))?1:0;
112 /* Find the window */
114 CONV_POINT32TO16( &msg->pt, &pt );
116 ht = hittest = HTCLIENT;
120 ht = hittest = WINPOS_WindowFromPoint( pWndScope, pt, &pWnd );
121 if( !pWnd ) pWnd = WIN_GetDesktop();
122 hWnd = pWnd->hwndSelf;
127 pWnd = WIN_FindWndPtr(hWnd);
129 ht = PERQDATA_GetCaptureInfo( queue->pQData );
132 /* stop if not the right queue */
134 if (pWnd->hmemTaskQ != hQ)
136 /* Not for the current task */
137 if (queue) QUEUE_ClearWakeBit( queue, QS_MOUSE );
138 /* Wake up the other task */
139 QUEUE_Unlock( queue );
140 queue = (MESSAGEQUEUE *)QUEUE_Lock( pWnd->hmemTaskQ );
141 if (queue) QUEUE_SetWakeBit( queue, QS_MOUSE );
143 QUEUE_Unlock( queue );
144 return SYSQ_MSG_ABANDON;
147 /* check if hWnd is within hWndScope */
149 if( hTopWnd && hWnd != hTopWnd )
150 if( !IsChild(hTopWnd, hWnd) )
152 QUEUE_Unlock( queue );
153 return SYSQ_MSG_CONTINUE;
158 /* translate double clicks -
159 * note that ...MOUSEMOVEs can slip in between
160 * ...BUTTONDOWN and ...BUTTONDBLCLK messages */
162 if( pWnd->class->style & CS_DBLCLKS || ht != HTCLIENT )
164 if ((message == clk_message) && (hWnd == clk_hwnd) &&
165 (msg->time - dblclk_time_limit < doubleClickSpeed) &&
166 (abs(msg->pt.x - clk_pos.x) < SYSMETRICS_CXDOUBLECLK/2) &&
167 (abs(msg->pt.y - clk_pos.y) < SYSMETRICS_CYDOUBLECLK/2))
169 message += (WM_LBUTTONDBLCLK - WM_LBUTTONDOWN);
170 mouseClick++; /* == 2 */
176 if (hittest != HTCLIENT)
178 message += WM_NCMOUSEMOVE - WM_MOUSEMOVE;
179 msg->wParam = hittest;
181 else ScreenToClient16( hWnd, &pt );
183 /* check message filter */
185 if (!MSG_CheckFilter(message, first, last))
188 return SYSQ_MSG_CONTINUE;
191 hCursorQueue = queue->self;
196 if (HOOK_IsHooked( WH_MOUSE ))
198 MOUSEHOOKSTRUCT16 *hook = SEGPTR_NEW(MOUSEHOOKSTRUCT16);
201 hook->pt = screen_pt;
203 hook->wHitTestCode = hittest;
204 hook->dwExtraInfo = 0;
205 ret = HOOK_CallHooks16( WH_MOUSE, remove ? HC_ACTION : HC_NOREMOVE,
206 message, (LPARAM)SEGPTR_GET(hook) );
209 if( ret ) return MAKELONG((INT16)SYSQ_MSG_SKIP, hittest);
212 if ((hittest == HTERROR) || (hittest == HTNOWHERE))
214 else if( remove && mouseClick )
216 HWND hwndTop = WIN_GetTopParent( hWnd );
218 if( mouseClick == 1 )
221 dblclk_time_limit = msg->time;
222 clk_message = msg->message;
226 /* got double click - zero them out */
227 dblclk_time_limit = clk_hwnd = 0;
231 /* Send the WM_PARENTNOTIFY,
232 * note that even for double/nonclient clicks
233 * notification message is still WM_L/M/RBUTTONDOWN.
236 MSG_SendParentNotify( pWnd, msg->message & 0xffff, 0, MAKELPARAM(screen_pt.x, screen_pt.y) );
238 /* Activate the window if needed */
240 if (hWnd != GetActiveWindow() && hWnd != GetDesktopWindow())
242 LONG ret = SendMessageA( hWnd, WM_MOUSEACTIVATE, hwndTop,
243 MAKELONG( hittest, message ) );
245 if ((ret == MA_ACTIVATEANDEAT) || (ret == MA_NOACTIVATEANDEAT))
248 if (((ret == MA_ACTIVATE) || (ret == MA_ACTIVATEANDEAT))
249 && hwndTop != GetActiveWindow() )
250 if (!WINPOS_SetActiveWindow( hwndTop, TRUE , TRUE ))
254 } else sendSC = (remove && sendSC);
256 /* Send the WM_SETCURSOR message */
259 SendMessageA( hWnd, WM_SETCURSOR, hWnd,
260 MAKELONG( hittest, message ));
261 if (eatMsg) return MAKELONG( (UINT16)SYSQ_MSG_SKIP, hittest);
264 msg->message = message;
265 msg->lParam = MAKELONG( pt.x, pt.y );
266 return SYSQ_MSG_ACCEPT;
270 /***********************************************************************
271 * MSG_TranslateKbdMsg
273 * Translate an keyboard hardware event into a real message.
275 static DWORD MSG_TranslateKbdMsg( HWND hTopWnd, DWORD first, DWORD last,
276 MSG *msg, BOOL remove )
278 WORD message = msg->message;
279 HWND hWnd = GetFocus();
282 /* Should check Ctrl-Esc and PrintScreen here */
286 /* Send the message to the active window instead, */
287 /* translating messages to their WM_SYS equivalent */
289 hWnd = GetActiveWindow();
291 if( message < WM_SYSKEYDOWN )
292 message += WM_SYSKEYDOWN - WM_KEYDOWN;
294 pWnd = WIN_FindWndPtr( hWnd );
295 if (pWnd && (pWnd->hmemTaskQ != GetFastQueue16()))
297 /* Not for the current task */
298 MESSAGEQUEUE *queue = (MESSAGEQUEUE *)QUEUE_Lock( GetFastQueue16() );
299 if (queue) QUEUE_ClearWakeBit( queue, QS_KEY );
300 QUEUE_Unlock( queue );
302 /* Wake up the other task */
303 queue = (MESSAGEQUEUE *)QUEUE_Lock( pWnd->hmemTaskQ );
304 if (queue) QUEUE_SetWakeBit( queue, QS_KEY );
305 QUEUE_Unlock( queue );
306 return SYSQ_MSG_ABANDON;
309 if (hTopWnd && hWnd != hTopWnd)
310 if (!IsChild(hTopWnd, hWnd)) return SYSQ_MSG_CONTINUE;
311 if (!MSG_CheckFilter(message, first, last)) return SYSQ_MSG_CONTINUE;
314 msg->message = message;
316 return (HOOK_CallHooks16( WH_KEYBOARD, remove ? HC_ACTION : HC_NOREMOVE,
317 LOWORD (msg->wParam), msg->lParam )
318 ? SYSQ_MSG_SKIP : SYSQ_MSG_ACCEPT);
322 /***********************************************************************
323 * MSG_JournalRecordMsg
325 * Build an EVENTMSG structure and call JOURNALRECORD hook
327 static void MSG_JournalRecordMsg( MSG *msg )
329 EVENTMSG *event = (EVENTMSG *) HeapAlloc(SystemHeap, 0, sizeof(EVENTMSG));
331 event->message = msg->message;
332 event->time = msg->time;
333 if ((msg->message >= WM_KEYFIRST) && (msg->message <= WM_KEYLAST))
335 event->paramL = (msg->wParam & 0xFF) | (HIWORD(msg->lParam) << 8);
336 event->paramH = msg->lParam & 0x7FFF;
337 if (HIWORD(msg->lParam) & 0x0100)
338 event->paramH |= 0x8000; /* special_key - bit */
339 HOOK_CallHooksA( WH_JOURNALRECORD, HC_ACTION, 0, (LPARAM)event );
341 else if ((msg->message >= WM_MOUSEFIRST) && (msg->message <= WM_MOUSELAST))
343 event->paramL = LOWORD(msg->lParam); /* X pos */
344 event->paramH = HIWORD(msg->lParam); /* Y pos */
345 ClientToScreen16( msg->hwnd, (LPPOINT16)&event->paramL );
346 HOOK_CallHooksA( WH_JOURNALRECORD, HC_ACTION, 0, (LPARAM)event );
348 else if ((msg->message >= WM_NCMOUSEFIRST) &&
349 (msg->message <= WM_NCMOUSELAST))
351 event->paramL = LOWORD(msg->lParam); /* X pos */
352 event->paramH = HIWORD(msg->lParam); /* Y pos */
353 event->message += WM_MOUSEMOVE-WM_NCMOUSEMOVE;/* give no info about NC area */
354 HOOK_CallHooksA( WH_JOURNALRECORD, HC_ACTION, 0, (LPARAM)event );
357 HeapFree(SystemHeap, 0, event);
360 /***********************************************************************
361 * MSG_JournalPlayBackMsg
363 * Get an EVENTMSG struct via call JOURNALPLAYBACK hook function
365 static int MSG_JournalPlayBackMsg(void)
368 long wtime,lParam,wParam;
369 WORD keyDown,i,result=0;
371 if ( HOOK_IsHooked( WH_JOURNALPLAYBACK ) )
373 tmpMsg = (EVENTMSG *) HeapAlloc(SystemHeap, 0, sizeof(EVENTMSG));
374 if (!tmpMsg) return result;
376 wtime=HOOK_CallHooksA( WH_JOURNALPLAYBACK, HC_GETNEXT, 0,
378 /* TRACE(msg,"Playback wait time =%ld\n",wtime); */
382 if ((tmpMsg->message>= WM_KEYFIRST) && (tmpMsg->message <= WM_KEYLAST))
384 wParam=tmpMsg->paramL & 0xFF;
385 lParam=MAKELONG(tmpMsg->paramH&0x7ffff,tmpMsg->paramL>>8);
386 if (tmpMsg->message == WM_KEYDOWN || tmpMsg->message == WM_SYSKEYDOWN)
388 for (keyDown=i=0; i<256 && !keyDown; i++)
389 if (InputKeyStateTable[i] & 0x80)
392 lParam |= 0x40000000;
393 AsyncKeyStateTable[wParam]=InputKeyStateTable[wParam] |= 0x80;
395 else /* WM_KEYUP, WM_SYSKEYUP */
397 lParam |= 0xC0000000;
398 AsyncKeyStateTable[wParam]=InputKeyStateTable[wParam] &= ~0x80;
400 if (InputKeyStateTable[VK_MENU] & 0x80)
401 lParam |= 0x20000000;
402 if (tmpMsg->paramH & 0x8000) /*special_key bit*/
403 lParam |= 0x01000000;
404 hardware_event( tmpMsg->message & 0xffff, LOWORD(wParam), lParam,
405 0, 0, tmpMsg->time, 0 );
409 if ((tmpMsg->message>= WM_MOUSEFIRST) && (tmpMsg->message <= WM_MOUSELAST))
411 switch (tmpMsg->message)
414 MouseButtonsStates[0]=AsyncMouseButtonsStates[0]=TRUE;break;
416 MouseButtonsStates[0]=AsyncMouseButtonsStates[0]=FALSE;break;
418 MouseButtonsStates[1]=AsyncMouseButtonsStates[1]=TRUE;break;
420 MouseButtonsStates[1]=AsyncMouseButtonsStates[1]=FALSE;break;
422 MouseButtonsStates[2]=AsyncMouseButtonsStates[2]=TRUE;break;
424 MouseButtonsStates[2]=AsyncMouseButtonsStates[2]=FALSE;break;
426 AsyncKeyStateTable[VK_LBUTTON]= InputKeyStateTable[VK_LBUTTON] = MouseButtonsStates[0] ? 0x80 : 0;
427 AsyncKeyStateTable[VK_MBUTTON]= InputKeyStateTable[VK_MBUTTON] = MouseButtonsStates[1] ? 0x80 : 0;
428 AsyncKeyStateTable[VK_RBUTTON]= InputKeyStateTable[VK_RBUTTON] = MouseButtonsStates[2] ? 0x80 : 0;
429 SetCursorPos(tmpMsg->paramL,tmpMsg->paramH);
430 lParam=MAKELONG(tmpMsg->paramL,tmpMsg->paramH);
432 if (MouseButtonsStates[0]) wParam |= MK_LBUTTON;
433 if (MouseButtonsStates[1]) wParam |= MK_MBUTTON;
434 if (MouseButtonsStates[2]) wParam |= MK_RBUTTON;
435 hardware_event( tmpMsg->message & 0xffff, LOWORD (wParam), lParam,
436 tmpMsg->paramL, tmpMsg->paramH, tmpMsg->time, 0 );
439 HOOK_CallHooksA( WH_JOURNALPLAYBACK, HC_SKIP, 0,
445 if( tmpMsg->message == WM_QUEUESYNC )
446 if (HOOK_IsHooked( WH_CBT ))
447 HOOK_CallHooksA( WH_CBT, HCBT_QS, 0, 0L);
449 result= QS_MOUSE | QS_KEY; /* ? */
451 HeapFree(SystemHeap, 0, tmpMsg);
456 /***********************************************************************
457 * MSG_PeekHardwareMsg
459 * Peek for a hardware message matching the hwnd and message filters.
461 static BOOL MSG_PeekHardwareMsg( MSG *msg, HWND hwnd, DWORD first, DWORD last,
464 /* FIXME: should deal with MSG32 instead of MSG16 */
466 DWORD status = SYSQ_MSG_ACCEPT;
467 MESSAGEQUEUE *sysMsgQueue = QUEUE_GetSysQueue();
469 QMSG *nextqmsg, *qmsg = 0;
471 /* FIXME: there has to be a better way to do this */
474 EnterCriticalSection(&sysMsgQueue->cSection);
476 qmsg = sysMsgQueue->firstMsg;
478 /* If the queue is empty, attempt to fill it */
479 if (!sysMsgQueue->msgCount && THREAD_IsWin16( THREAD_Current() )
481 EVENT_WaitNetEvent( FALSE, FALSE );
483 for ( kbd_msg = 0; qmsg; qmsg = nextqmsg)
488 nextqmsg = qmsg->nextMsg;
490 /* Translate message */
492 if ((msg->message >= WM_MOUSEFIRST) && (msg->message <= WM_MOUSELAST))
494 HWND hWndScope = (HWND)qmsg->extraInfo;
496 status = MSG_TranslateMouseMsg(hwnd, first, last, msg, remove,
497 (Options.managed && IsWindow(hWndScope) )
498 ? WIN_FindWndPtr(hWndScope) : WIN_GetDesktop() );
501 else if ((msg->message >= WM_KEYFIRST) && (msg->message <= WM_KEYLAST))
503 status = MSG_TranslateKbdMsg(hwnd, first, last, msg, remove);
506 else /* Non-standard hardware event */
508 HARDWAREHOOKSTRUCT16 *hook;
509 if ((hook = SEGPTR_NEW(HARDWAREHOOKSTRUCT16)))
512 hook->hWnd = msg->hwnd;
513 hook->wMessage = msg->message & 0xffff;
514 hook->wParam = LOWORD (msg->wParam);
515 hook->lParam = msg->lParam;
516 ret = HOOK_CallHooks16( WH_HARDWARE,
517 remove ? HC_ACTION : HC_NOREMOVE,
518 0, (LPARAM)SEGPTR_GET(hook) );
522 QUEUE_RemoveMsg( sysMsgQueue, qmsg );
525 status = SYSQ_MSG_ACCEPT;
529 switch (LOWORD(status))
531 case SYSQ_MSG_ACCEPT:
535 if (HOOK_IsHooked( WH_CBT ))
538 HOOK_CallHooks16( WH_CBT, HCBT_KEYSKIPPED,
539 LOWORD (msg->wParam), msg->lParam );
542 MOUSEHOOKSTRUCT16 *hook = SEGPTR_NEW(MOUSEHOOKSTRUCT16);
545 CONV_POINT32TO16( &msg->pt,&hook->pt );
546 hook->hwnd = msg->hwnd;
547 hook->wHitTestCode = HIWORD(status);
548 hook->dwExtraInfo = 0;
549 HOOK_CallHooks16( WH_CBT, HCBT_CLICKSKIPPED ,msg->message & 0xffff,
550 (LPARAM)SEGPTR_GET(hook) );
557 QUEUE_RemoveMsg( sysMsgQueue, qmsg );
560 case SYSQ_MSG_CONTINUE:
563 case SYSQ_MSG_ABANDON:
564 LeaveCriticalSection(&sysMsgQueue->cSection);
570 if (HOOK_IsHooked( WH_JOURNALRECORD )) MSG_JournalRecordMsg( msg );
571 QUEUE_RemoveMsg( sysMsgQueue, qmsg );
573 LeaveCriticalSection(&sysMsgQueue->cSection);
576 LeaveCriticalSection(&sysMsgQueue->cSection);
581 /**********************************************************************
582 * SetDoubleClickTime16 (USER.20)
584 void WINAPI SetDoubleClickTime16( UINT16 interval )
586 SetDoubleClickTime( interval );
590 /**********************************************************************
591 * SetDoubleClickTime32 (USER32.480)
593 BOOL WINAPI SetDoubleClickTime( UINT interval )
595 doubleClickSpeed = interval ? interval : 500;
600 /**********************************************************************
601 * GetDoubleClickTime16 (USER.21)
603 UINT16 WINAPI GetDoubleClickTime16(void)
605 return doubleClickSpeed;
609 /**********************************************************************
610 * GetDoubleClickTime32 (USER32.239)
612 UINT WINAPI GetDoubleClickTime(void)
614 return doubleClickSpeed;
618 /***********************************************************************
619 * MSG_SendMessageInterThread
621 * Implementation of an inter-task SendMessage.
623 * 0 if error or timeout
626 static LRESULT MSG_SendMessageInterThread( HQUEUE16 hDestQueue,
628 WPARAM wParam, LPARAM lParam,
629 DWORD timeout, WORD flags,
632 MESSAGEQUEUE *queue, *destQ;
638 if (IsTaskLocked16() || !IsWindow(hwnd))
641 /* create a SMSG structure to hold SendMessage() parameters */
642 if (! (smsg = (SMSG *) HeapAlloc( SystemHeap, 0, sizeof(SMSG) )) )
644 if (!(queue = (MESSAGEQUEUE*)QUEUE_Lock( GetFastQueue16() ))) return 0;
646 if (!(destQ = (MESSAGEQUEUE*)QUEUE_Lock( hDestQueue )))
648 QUEUE_Unlock( queue );
652 TRACE(sendmsg,"SM: %s [%04x] (%04x -> %04x)\n",
653 SPY_GetMsgName(msg), msg, queue->self, hDestQueue );
655 /* fill up SMSG structure */
658 smsg->wParam = wParam;
659 smsg->lParam = lParam;
662 smsg->hSrcQueue = GetFastQueue16();
663 smsg->hDstQueue = hDestQueue;
666 /* add smsg struct in the processing SM list of the source queue */
667 QUEUE_AddSMSG(queue, SM_PROCESSING_LIST, smsg);
669 /* add smsg struct in the pending list of the destination queue */
670 if (QUEUE_AddSMSG(destQ, SM_PENDING_LIST, smsg) == FALSE)
673 /* force destination task to run next, if 16 bit threads */
674 if ( THREAD_IsWin16(THREAD_Current()) && THREAD_IsWin16(destQ->thdb) )
675 DirectedYield16( destQ->thdb->teb.htask16 );
677 /* wait for the result */
678 while ( !(smsg->flags & SMSG_HAVE_RESULT) )
681 * The sequence is crucial to avoid deadlock situations:
682 * - first, we clear the QS_SMRESULT bit
683 * - then, we check the SMSG_HAVE_RESULT bit
684 * - only if this isn't set, we enter the wait state.
686 * As the receiver first sets the SMSG_HAVE_RESULT and then wakes us,
687 * we are guaranteed that -should we now clear the QS_SMRESULT that
688 * was signalled already by the receiver- we will not start waiting.
690 QUEUE_ClearWakeBit( queue, QS_SMRESULT );
692 if ( !(smsg->flags & SMSG_HAVE_RESULT)
693 && QUEUE_WaitBits( QS_SMRESULT, timeout ) == 0 )
695 /* return with timeout */
701 if ( smsg->flags & SMSG_HAVE_RESULT )
703 *pRes = smsg->lResult;
704 TRACE(sendmsg,"smResult = %08x\n", (unsigned)*pRes );
708 /* remove the smsg from the processingg list of the source queue */
709 QUEUE_RemoveSMSG( queue, SM_PROCESSING_LIST, smsg );
711 /* Note: the destination thread is in charge of removing the smsg from
714 /* In the case of an early reply (or a timeout), sender thread will
715 released the smsg structure if the receiver thread is done
716 (SMSG_RECEIVED set). If the receiver thread isn't done,
717 SMSG_RECEIVER_CLEANS_UP flag is set, and it will be the receiver
718 responsability to released smsg */
719 EnterCriticalSection( &queue->cSection );
721 if (smsg->flags & SMSG_RECEIVED)
722 HeapFree(SystemHeap, 0, smsg);
724 smsg->flags |= SMSG_RECEIVER_CLEANS;
726 LeaveCriticalSection( &queue->cSection );
729 QUEUE_Unlock( queue );
730 QUEUE_Unlock( destQ );
732 TRACE(sendmsg,"done!\n");
737 /***********************************************************************
738 * ReplyMessage16 (USER.115)
740 void WINAPI ReplyMessage16( LRESULT result )
742 ReplyMessage( result );
745 /***********************************************************************
746 * ReplyMessage (USER.115)
748 BOOL WINAPI ReplyMessage( LRESULT result )
750 MESSAGEQUEUE *senderQ = 0;
751 MESSAGEQUEUE *queue = 0;
755 if (!(queue = (MESSAGEQUEUE*)QUEUE_Lock( GetFastQueue16() ))) return FALSE;
757 TRACE(sendmsg,"ReplyMessage, queue %04x\n", queue->self);
759 if ( !(smsg = queue->smWaiting)
760 || !(senderQ = QUEUE_Lock( smsg->hSrcQueue )) )
761 goto ReplyMessageEnd;
763 if ( !(smsg->flags & SMSG_ALREADY_REPLIED) )
765 /* This is the first reply, so pass result to sender */
767 TRACE( sendmsg,"\trpm: smResult = %08lx\n", (long) result );
769 EnterCriticalSection(&senderQ->cSection);
771 smsg->lResult = result;
772 smsg->flags |= SMSG_ALREADY_REPLIED;
774 /* check if it's an early reply (called by the application) or
775 a regular reply (called by ReceiveMessage) */
776 if ( !(smsg->flags & SMSG_SENDING_REPLY) )
777 smsg->flags |= SMSG_EARLY_REPLY;
779 smsg->flags |= SMSG_HAVE_RESULT;
781 LeaveCriticalSection(&senderQ->cSection);
783 /* tell the sending task that its reply is ready */
784 QUEUE_SetWakeBit( senderQ, QS_SMRESULT );
786 /* switch directly to sending task (16 bit thread only) */
787 if ( THREAD_IsWin16( THREAD_Current() ) && THREAD_IsWin16( senderQ->thdb ) )
788 DirectedYield16( senderQ->thdb->teb.htask16 );
793 if (smsg->flags & SMSG_SENDING_REPLY)
795 /* remove msg from the waiting list, since this is the last
797 QUEUE_RemoveSMSG( queue, SM_WAITING_LIST, smsg );
799 EnterCriticalSection(&senderQ->cSection);
801 /* tell the sender we're all done with smsg structure */
802 smsg->flags |= SMSG_RECEIVED;
804 /* sender will set SMSG_RECEIVER_CLEANS_UP if it wants the
805 receiver to clean up smsg, it could only happens when there is
806 an early reply or a timeout */
807 if ( smsg->flags & SMSG_RECEIVER_CLEANS )
809 TRACE( sendmsg,"Receiver cleans up!\n" );
810 HeapFree( SystemHeap, 0, smsg );
813 LeaveCriticalSection(&senderQ->cSection);
818 QUEUE_Unlock( senderQ );
820 QUEUE_Unlock( queue );
825 /***********************************************************************
828 static BOOL MSG_PeekMessage( LPMSG msg, HWND hwnd, DWORD first, DWORD last,
829 WORD flags, BOOL peek )
832 MESSAGEQUEUE *msgQueue;
837 DDE_TestDDE(hwnd); /* do we have dde handling in the window ?*/
838 DDE_GetRemoteMessage();
839 #endif /* CONFIG_IPC */
841 mask = QS_POSTMESSAGE | QS_SENDMESSAGE; /* Always selected */
844 if ((first <= WM_KEYLAST) && (last >= WM_KEYFIRST)) mask |= QS_KEY;
845 if ( ((first <= WM_MOUSELAST) && (last >= WM_MOUSEFIRST)) ||
846 ((first <= WM_NCMOUSELAST) && (last >= WM_NCMOUSEFIRST)) ) mask |= QS_MOUSE;
847 if ((first <= WM_TIMER) && (last >= WM_TIMER)) mask |= QS_TIMER;
848 if ((first <= WM_SYSTIMER) && (last >= WM_SYSTIMER)) mask |= QS_TIMER;
849 if ((first <= WM_PAINT) && (last >= WM_PAINT)) mask |= QS_PAINT;
851 else mask |= QS_MOUSE | QS_KEY | QS_TIMER | QS_PAINT;
853 if (IsTaskLocked16()) flags |= PM_NOYIELD;
855 /* Never yield on Win32 threads */
856 if (!THREAD_IsWin16(THREAD_Current())) flags |= PM_NOYIELD;
862 hQueue = GetFastQueue16();
863 msgQueue = (MESSAGEQUEUE *)QUEUE_Lock( hQueue );
864 if (!msgQueue) return FALSE;
865 msgQueue->changeBits = 0;
867 /* First handle a message put by SendMessage() */
869 while (msgQueue->wakeBits & QS_SENDMESSAGE)
870 QUEUE_ReceiveMessage( msgQueue );
872 /* Now handle a WM_QUIT message */
874 if (msgQueue->wPostQMsg &&
875 (!first || WM_QUIT >= first) &&
876 (!last || WM_QUIT <= last) )
879 msg->message = WM_QUIT;
880 msg->wParam = msgQueue->wExitCode;
882 if (flags & PM_REMOVE) msgQueue->wPostQMsg = 0;
886 /* Now find a normal message */
888 if (((msgQueue->wakeBits & mask) & QS_POSTMESSAGE) &&
889 ((qmsg = QUEUE_FindMsg( msgQueue, hwnd, first, last )) != 0))
893 msgQueue->GetMessageTimeVal = msg->time;
894 CONV_POINT32TO16(&msg->pt, &pt16);
895 msgQueue->GetMessagePosVal = *(DWORD *)&pt16;
896 msgQueue->GetMessageExtraInfoVal = qmsg->extraInfo;
898 if (flags & PM_REMOVE) QUEUE_RemoveMsg( msgQueue, qmsg );
902 msgQueue->changeBits |= MSG_JournalPlayBackMsg();
904 /* Now find a hardware event */
906 if (((msgQueue->wakeBits & mask) & (QS_MOUSE | QS_KEY)) &&
907 MSG_PeekHardwareMsg( msg, hwnd, first, last, flags & PM_REMOVE ))
910 msgQueue->GetMessageTimeVal = msg->time;
911 CONV_POINT32TO16(&msg->pt, &pt16);
912 msgQueue->GetMessagePosVal = *(DWORD *)&pt16;
913 msgQueue->GetMessageExtraInfoVal = 0; /* Always 0 for now */
917 /* Check again for SendMessage */
919 while (msgQueue->wakeBits & QS_SENDMESSAGE)
920 QUEUE_ReceiveMessage( msgQueue );
922 /* Now find a WM_PAINT message */
924 if ((msgQueue->wakeBits & mask) & QS_PAINT)
927 msg->hwnd = WIN_FindWinToRepaint( hwnd , hQueue );
928 msg->message = WM_PAINT;
932 if ((wndPtr = WIN_FindWndPtr(msg->hwnd)))
934 if( wndPtr->dwStyle & WS_MINIMIZE &&
935 wndPtr->class->hIcon )
937 msg->message = WM_PAINTICON;
941 if( !hwnd || msg->hwnd == hwnd || IsChild16(hwnd,msg->hwnd) )
943 if( wndPtr->flags & WIN_INTERNAL_PAINT && !wndPtr->hrgnUpdate)
945 wndPtr->flags &= ~WIN_INTERNAL_PAINT;
946 QUEUE_DecPaintCount( hQueue );
953 /* Check for timer messages, but yield first */
955 if (!(flags & PM_NOYIELD))
958 while (msgQueue->wakeBits & QS_SENDMESSAGE)
959 QUEUE_ReceiveMessage( msgQueue );
961 if ((msgQueue->wakeBits & mask) & QS_TIMER)
963 if (TIMER_GetTimerMsg(msg, hwnd, hQueue, flags & PM_REMOVE)) break;
968 if (!(flags & PM_NOYIELD)) UserYield16();
970 QUEUE_Unlock( msgQueue );
973 msgQueue->wakeMask = mask;
974 QUEUE_WaitBits( mask, INFINITE );
975 QUEUE_Unlock( msgQueue );
978 /* instead of unlocking queue for every break condition, all break
979 condition will fall here */
980 QUEUE_Unlock( msgQueue );
982 /* We got a message */
983 if (flags & PM_REMOVE)
985 WORD message = msg->message;
987 if (message == WM_KEYDOWN || message == WM_SYSKEYDOWN)
989 BYTE *p = &QueueKeyStateTable[msg->wParam & 0xff];
995 else if (message == WM_KEYUP || message == WM_SYSKEYUP)
996 QueueKeyStateTable[msg->wParam & 0xff] &= ~0x80;
998 if (peek) return TRUE;
999 else return (msg->message != WM_QUIT);
1002 /***********************************************************************
1003 * MSG_InternalGetMessage
1005 * GetMessage() function for internal use. Behave like GetMessage(),
1006 * but also call message filters and optionally send WM_ENTERIDLE messages.
1007 * 'hwnd' must be the handle of the dialog or menu window.
1008 * 'code' is the message filter value (MSGF_??? codes).
1010 BOOL MSG_InternalGetMessage( MSG *msg, HWND hwnd, HWND hwndOwner,
1011 WPARAM code, WORD flags, BOOL sendIdle )
1017 if (!MSG_PeekMessage( msg, 0, 0, 0, flags, TRUE ))
1019 /* No message present -> send ENTERIDLE and wait */
1020 if (IsWindow(hwndOwner))
1021 SendMessageA( hwndOwner, WM_ENTERIDLE,
1022 code, (LPARAM)hwnd );
1023 MSG_PeekMessage( msg, 0, 0, 0, flags, FALSE );
1026 else /* Always wait for a message */
1027 MSG_PeekMessage( msg, 0, 0, 0, flags, FALSE );
1029 /* Call message filters */
1031 if (HOOK_IsHooked( WH_SYSMSGFILTER ) || HOOK_IsHooked( WH_MSGFILTER ))
1033 MSG *pmsg = HeapAlloc( SystemHeap, 0, sizeof(MSG) );
1038 ret = (HOOK_CallHooksA( WH_SYSMSGFILTER, code, 0,
1040 HOOK_CallHooksA( WH_MSGFILTER, code, 0,
1043 HeapFree( SystemHeap, 0, pmsg );
1046 /* Message filtered -> remove it from the queue */
1047 /* if it's still there. */
1048 if (!(flags & PM_REMOVE))
1049 MSG_PeekMessage( msg, 0, 0, 0, PM_REMOVE, TRUE );
1055 return (msg->message != WM_QUIT);
1060 /***********************************************************************
1061 * PeekMessage16 (USER.109)
1063 BOOL16 WINAPI PeekMessage16( LPMSG16 lpmsg, HWND16 hwnd, UINT16 first,
1064 UINT16 last, UINT16 flags )
1068 ret = PeekMessageA(&msg32, hwnd, first, last, flags);
1069 STRUCT32_MSG32to16(&msg32, lpmsg);
1073 /***********************************************************************
1074 * WIN16_PeekMessage32 (USER.819)
1076 BOOL16 WINAPI PeekMessage32_16( LPMSG16_32 lpmsg16_32, HWND16 hwnd,
1077 UINT16 first, UINT16 last, UINT16 flags, BOOL16 wHaveParamHigh )
1079 if (wHaveParamHigh == FALSE)
1081 lpmsg16_32->wParamHigh = 0;
1082 return PeekMessage16(&(lpmsg16_32->msg), hwnd, first, last, flags);
1089 ret = (BOOL16)PeekMessageA(&msg32, (HWND)hwnd,
1090 (UINT)first, (UINT)last, (UINT)flags);
1091 lpmsg16_32->msg.hwnd = msg32.hwnd;
1092 lpmsg16_32->msg.message = msg32.message;
1093 lpmsg16_32->msg.wParam = LOWORD(msg32.wParam);
1094 lpmsg16_32->msg.lParam = msg32.lParam;
1095 lpmsg16_32->msg.time = msg32.time;
1096 lpmsg16_32->msg.pt.x = (INT16)msg32.pt.x;
1097 lpmsg16_32->msg.pt.y = (INT16)msg32.pt.y;
1098 lpmsg16_32->wParamHigh = HIWORD(msg32.wParam);
1104 /***********************************************************************
1107 BOOL WINAPI PeekMessageA( LPMSG lpmsg, HWND hwnd,
1108 UINT min,UINT max,UINT wRemoveMsg)
1110 return MSG_PeekMessage( lpmsg, hwnd, min, max, wRemoveMsg, TRUE );
1113 /***********************************************************************
1114 * PeekMessageW Check queue for messages
1116 * Checks for a message in the thread's queue, filtered as for
1117 * GetMessage(). Returns immediately whether a message is available
1120 * Whether a retrieved message is removed from the queue is set by the
1121 * _wRemoveMsg_ flags, which should be one of the following values:
1123 * PM_NOREMOVE Do not remove the message from the queue.
1125 * PM_REMOVE Remove the message from the queue.
1127 * In addition, PM_NOYIELD may be combined into _wRemoveMsg_ to
1128 * request that the system not yield control during PeekMessage();
1129 * however applications may not rely on scheduling behavior.
1133 * Nonzero if a message is available and is retrieved, zero otherwise.
1140 BOOL WINAPI PeekMessageW(
1141 LPMSG lpmsg, /* buffer to receive message */
1142 HWND hwnd, /* restrict to messages for hwnd */
1143 UINT min, /* minimum message to receive */
1144 UINT max, /* maximum message to receive */
1145 UINT wRemoveMsg /* removal flags */
1147 /* FIXME: Should perform Unicode translation on specific messages */
1148 return PeekMessageA(lpmsg,hwnd,min,max,wRemoveMsg);
1151 /***********************************************************************
1152 * GetMessage16 (USER.108)
1154 BOOL16 WINAPI GetMessage16( SEGPTR msg, HWND16 hwnd, UINT16 first, UINT16 last)
1157 MSG16 *lpmsg = (MSG16 *)PTR_SEG_TO_LIN(msg);
1160 ret = GetMessageA( &msg32, hwnd, first, last );
1162 STRUCT32_MSG32to16( &msg32, lpmsg );
1164 TRACE(msg,"message %04x, hwnd %04x, filter(%04x - %04x)\n", lpmsg->message,
1165 hwnd, first, last );
1170 /***********************************************************************
1171 * WIN16_GetMessage32 (USER.820)
1173 BOOL16 WINAPI GetMessage32_16( SEGPTR msg16_32, HWND16 hWnd, UINT16 first,
1174 UINT16 last, BOOL16 wHaveParamHigh )
1176 MSG32_16 *lpmsg16_32 = (MSG32_16 *)PTR_SEG_TO_LIN(msg16_32);
1178 if (wHaveParamHigh == FALSE) /* normal GetMessage16 call */
1181 lpmsg16_32->wParamHigh = 0; /* you never know... */
1182 /* WARNING: msg16_32->msg has to be the first variable in the struct */
1183 return GetMessage16(msg16_32, hWnd, first, last);
1190 ret = (BOOL16)GetMessageA(&msg32, hWnd, first, last);
1191 lpmsg16_32->msg.hwnd = msg32.hwnd;
1192 lpmsg16_32->msg.message = msg32.message;
1193 lpmsg16_32->msg.wParam = LOWORD(msg32.wParam);
1194 lpmsg16_32->msg.lParam = msg32.lParam;
1195 lpmsg16_32->msg.time = msg32.time;
1196 lpmsg16_32->msg.pt.x = (INT16)msg32.pt.x;
1197 lpmsg16_32->msg.pt.y = (INT16)msg32.pt.y;
1198 lpmsg16_32->wParamHigh = HIWORD(msg32.wParam);
1203 /***********************************************************************
1204 * GetMessage32A (USER32.270)
1206 BOOL WINAPI GetMessageA(MSG* lpmsg,HWND hwnd,UINT min,UINT max)
1208 MSG_PeekMessage( lpmsg, hwnd, min, max, PM_REMOVE, FALSE );
1210 TRACE(msg,"message %04x, hwnd %04x, filter(%04x - %04x)\n", lpmsg->message,
1213 HOOK_CallHooksA( WH_GETMESSAGE, HC_ACTION, 0, (LPARAM)lpmsg );
1215 return (lpmsg->message != WM_QUIT);
1218 /***********************************************************************
1219 * GetMessage32W (USER32.274) Retrieve next message
1221 * GetMessage retrieves the next event from the calling thread's
1222 * queue and deposits it in *lpmsg.
1224 * If _hwnd_ is not NULL, only messages for window _hwnd_ and its
1225 * children as specified by IsChild() are retrieved. If _hwnd_ is NULL
1226 * all application messages are retrieved.
1228 * _min_ and _max_ specify the range of messages of interest. If
1229 * min==max==0, no filtering is performed. Useful examples are
1230 * WM_KEYFIRST and WM_KEYLAST to retrieve keyboard input, and
1231 * WM_MOUSEFIRST and WM_MOUSELAST to retrieve mouse input.
1233 * WM_PAINT messages are not removed from the queue; they remain until
1234 * processed. Other messages are removed from the queue.
1238 * -1 on error, 0 if message is WM_QUIT, nonzero otherwise.
1245 BOOL WINAPI GetMessageW(
1246 MSG* lpmsg, /* buffer to receive message */
1247 HWND hwnd, /* restrict to messages for hwnd */
1248 UINT min, /* minimum message to receive */
1249 UINT max /* maximum message to receive */
1252 return GetMessageA(lpmsg, hwnd, min, max);
1256 /***********************************************************************
1257 * PostMessage16 (USER.110)
1259 BOOL16 WINAPI PostMessage16( HWND16 hwnd, UINT16 message, WPARAM16 wParam,
1262 return (BOOL16) PostMessageA( hwnd, message, wParam, lParam );
1266 /***********************************************************************
1267 * PostMessage32A (USER32.419)
1269 BOOL WINAPI PostMessageA( HWND hwnd, UINT message, WPARAM wParam,
1276 msg.message = message;
1277 msg.wParam = wParam;
1278 msg.lParam = lParam;
1279 msg.time = GetTickCount();
1284 if (DDE_PostMessage(&msg))
1286 #endif /* CONFIG_IPC */
1288 if (hwnd == HWND_BROADCAST)
1290 TRACE(msg,"HWND_BROADCAST !\n");
1291 for (wndPtr = WIN_GetDesktop()->child; wndPtr; wndPtr = wndPtr->next)
1293 if (wndPtr->dwStyle & WS_POPUP || wndPtr->dwStyle & WS_CAPTION)
1295 TRACE(msg,"BROADCAST Message to hWnd=%04x m=%04X w=%04X l=%08lX !\n",
1296 wndPtr->hwndSelf, message, wParam, lParam);
1297 PostMessageA( wndPtr->hwndSelf, message, wParam, lParam );
1300 TRACE(msg,"End of HWND_BROADCAST !\n");
1304 wndPtr = WIN_FindWndPtr( hwnd );
1305 if (!wndPtr || !wndPtr->hmemTaskQ) return FALSE;
1307 return QUEUE_AddMsg( wndPtr->hmemTaskQ, &msg, 0 );
1311 /***********************************************************************
1312 * PostMessage32W (USER32.420)
1314 BOOL WINAPI PostMessageW( HWND hwnd, UINT message, WPARAM wParam,
1318 return PostMessageA( hwnd, message, wParam, lParam );
1322 /***********************************************************************
1323 * PostAppMessage16 (USER.116)
1325 BOOL16 WINAPI PostAppMessage16( HTASK16 hTask, UINT16 message, WPARAM16 wParam,
1330 if (GetTaskQueue16(hTask) == 0) return FALSE;
1332 msg.message = message;
1333 msg.wParam = wParam;
1334 msg.lParam = lParam;
1335 msg.time = GetTickCount();
1339 return QUEUE_AddMsg( GetTaskQueue16(hTask), &msg, 0 );
1342 /************************************************************************
1343 * MSG_CallWndProcHook32
1345 static void MSG_CallWndProcHook( LPMSG pmsg, BOOL bUnicode )
1349 cwp.lParam = pmsg->lParam;
1350 cwp.wParam = pmsg->wParam;
1351 cwp.message = pmsg->message;
1352 cwp.hwnd = pmsg->hwnd;
1354 if (bUnicode) HOOK_CallHooksW(WH_CALLWNDPROC, HC_ACTION, 1, (LPARAM)&cwp);
1355 else HOOK_CallHooksA( WH_CALLWNDPROC, HC_ACTION, 1, (LPARAM)&cwp );
1357 pmsg->lParam = cwp.lParam;
1358 pmsg->wParam = cwp.wParam;
1359 pmsg->message = cwp.message;
1360 pmsg->hwnd = cwp.hwnd;
1364 /***********************************************************************
1367 * return values: 0 if timeout occurs
1370 LRESULT MSG_SendMessage( HWND hwnd, UINT msg, WPARAM wParam,
1371 LPARAM lParam, DWORD timeout, WORD flags,
1375 WND **list, **ppWnd;
1380 if (hwnd == HWND_BROADCAST)
1384 if (!(list = WIN_BuildWinArray( WIN_GetDesktop(), 0, NULL )))
1386 TRACE(msg,"HWND_BROADCAST !\n");
1387 for (ppWnd = list; *ppWnd; ppWnd++)
1390 if (!IsWindow(wndPtr->hwndSelf)) continue;
1391 if (wndPtr->dwStyle & WS_POPUP || wndPtr->dwStyle & WS_CAPTION)
1393 TRACE(msg,"BROADCAST Message to hWnd=%04x m=%04X w=%04lX l=%08lX !\n",
1394 wndPtr->hwndSelf, msg, (DWORD)wParam, lParam);
1395 MSG_SendMessage( wndPtr->hwndSelf, msg, wParam, lParam,
1396 timeout, flags, pRes);
1399 HeapFree( SystemHeap, 0, list );
1400 TRACE(msg,"End of HWND_BROADCAST !\n");
1404 if (HOOK_IsHooked( WH_CALLWNDPROC ))
1406 if (flags & SMSG_UNICODE)
1407 MSG_CallWndProcHook( (LPMSG)&hwnd, TRUE);
1408 else if (flags & SMSG_WIN32)
1409 MSG_CallWndProcHook( (LPMSG)&hwnd, FALSE);
1414 if ((pmsg = SEGPTR_NEW(CWPSTRUCT16)))
1416 pmsg->hwnd = hwnd & 0xffff;
1417 pmsg->message= msg & 0xffff;
1418 pmsg->wParam = wParam & 0xffff;
1419 pmsg->lParam = lParam;
1420 HOOK_CallHooks16( WH_CALLWNDPROC, HC_ACTION, 1,
1421 (LPARAM)SEGPTR_GET(pmsg) );
1423 msg = pmsg->message;
1424 wParam = pmsg->wParam;
1425 lParam = pmsg->lParam;
1426 SEGPTR_FREE( pmsg );
1431 if (!(wndPtr = WIN_FindWndPtr( hwnd )))
1433 WARN(msg, "invalid hwnd %04x\n", hwnd );
1436 if (QUEUE_IsExitingQueue(wndPtr->hmemTaskQ))
1437 return 0; /* Don't send anything if the task is dying */
1439 if (flags & SMSG_WIN32)
1440 SPY_EnterMessage( SPY_SENDMESSAGE, hwnd, msg, wParam, lParam );
1442 SPY_EnterMessage( SPY_SENDMESSAGE16, hwnd, msg, wParam, lParam );
1444 if (wndPtr->hmemTaskQ != GetFastQueue16())
1445 ret = MSG_SendMessageInterThread( wndPtr->hmemTaskQ, hwnd, msg,
1446 wParam, lParam, timeout, flags, pRes );
1449 /* Call the right CallWindowProc flavor */
1450 if (flags & SMSG_UNICODE)
1451 *pRes = CallWindowProcW( (WNDPROC)wndPtr->winproc,
1452 hwnd, msg, wParam, lParam );
1453 else if (flags & SMSG_WIN32)
1454 *pRes = CallWindowProcA( (WNDPROC)wndPtr->winproc,
1455 hwnd, msg, wParam, lParam );
1457 *pRes = CallWindowProc16( (WNDPROC16)wndPtr->winproc,
1458 (HWND16) hwnd, (UINT16) msg,
1459 (WPARAM16) wParam, lParam );
1462 if (flags & SMSG_WIN32)
1463 SPY_ExitMessage( SPY_RESULT_OK, hwnd, msg, ret );
1465 SPY_ExitMessage( SPY_RESULT_OK16, hwnd, msg, ret );
1471 /***********************************************************************
1472 * SendMessage16 (USER.111)
1474 LRESULT WINAPI SendMessage16( HWND16 hwnd, UINT16 msg, WPARAM16 wParam,
1479 MSG16 DDE_msg = { hwnd, msg, wParam, lParam };
1480 if (DDE_SendMessage(&DDE_msg)) return TRUE;
1481 #endif /* CONFIG_IPC */
1483 MSG_SendMessage(hwnd, msg, wParam, lParam, INFINITE, 0, &res);
1490 /**********************************************************************
1491 * PostThreadMessage32A (USER32.422)
1495 * Thread-local message queues are not supported.
1498 BOOL WINAPI PostThreadMessageA(DWORD idThread , UINT message,
1499 WPARAM wParam, LPARAM lParam )
1504 if ((hQueue = GetThreadQueue16(idThread)) == 0)
1508 msg.message = message;
1509 msg.wParam = wParam;
1510 msg.lParam = lParam;
1511 msg.time = GetTickCount();
1515 return QUEUE_AddMsg( hQueue, &msg, 0 );
1518 /**********************************************************************
1519 * PostThreadMessage32W (USER32.423)
1523 * Thread-local message queues are not supported.
1526 BOOL WINAPI PostThreadMessageW(DWORD idThread , UINT message,
1527 WPARAM wParam, LPARAM lParam )
1529 FIXME(sendmsg, "(...): Should do unicode/ascii conversion!\n");
1530 return PostThreadMessageA(idThread, message, wParam, lParam);
1533 /***********************************************************************
1534 * SendMessage32A (USER32.454)
1536 LRESULT WINAPI SendMessageA( HWND hwnd, UINT msg, WPARAM wParam,
1541 MSG_SendMessage(hwnd, msg, wParam, lParam, INFINITE,
1548 /***********************************************************************
1549 * SendMessage32W (USER32.459) Send Window Message
1551 * Sends a message to the window procedure of the specified window.
1552 * SendMessage() will not return until the called window procedure
1553 * either returns or calls ReplyMessage().
1555 * Use PostMessage() to send message and return immediately. A window
1556 * procedure may use InSendMessage() to detect
1557 * SendMessage()-originated messages.
1559 * Applications which communicate via HWND_BROADCAST may use
1560 * RegisterWindowMessage() to obtain a unique message to avoid conflicts
1561 * with other applications.
1567 LRESULT WINAPI SendMessageW(
1568 HWND hwnd, /* Window to send message to. If HWND_BROADCAST,
1569 the message will be sent to all top-level windows. */
1571 UINT msg, /* message */
1572 WPARAM wParam, /* message parameter */
1573 LPARAM lParam /* additional message parameter */
1577 MSG_SendMessage(hwnd, msg, wParam, lParam, INFINITE,
1578 SMSG_WIN32 | SMSG_UNICODE, &res);
1584 /***********************************************************************
1585 * SendMessageTimeout16 (not a WINAPI)
1587 LRESULT WINAPI SendMessageTimeout16( HWND16 hwnd, UINT16 msg, WPARAM16 wParam,
1588 LPARAM lParam, UINT16 flags,
1589 UINT16 timeout, LPWORD resultp)
1594 /* FIXME: need support for SMTO_BLOCK */
1596 ret = MSG_SendMessage(hwnd, msg, wParam, lParam, timeout, 0, &msgRet);
1597 *resultp = (WORD) msgRet;
1602 /***********************************************************************
1603 * SendMessageTimeoutA (USER32.457)
1605 LRESULT WINAPI SendMessageTimeoutA( HWND hwnd, UINT msg, WPARAM wParam,
1606 LPARAM lParam, UINT flags,
1607 UINT timeout, LPDWORD resultp)
1612 /* FIXME: need support for SMTO_BLOCK */
1614 ret = MSG_SendMessage(hwnd, msg, wParam, lParam, timeout, SMSG_WIN32,
1617 *resultp = (DWORD) msgRet;
1622 /***********************************************************************
1623 * SendMessageTimeoutW (USER32.458)
1625 LRESULT WINAPI SendMessageTimeoutW( HWND hwnd, UINT msg, WPARAM wParam,
1626 LPARAM lParam, UINT flags,
1627 UINT timeout, LPDWORD resultp)
1632 /* FIXME: need support for SMTO_BLOCK */
1634 ret = MSG_SendMessage(hwnd, msg, wParam, lParam, timeout,
1635 SMSG_WIN32 | SMSG_UNICODE, &msgRet);
1637 *resultp = (DWORD) msgRet;
1642 /***********************************************************************
1643 * WaitMessage (USER.112) (USER32.578) Suspend thread pending messages
1645 * WaitMessage() suspends a thread until events appear in the thread's
1650 * Is supposed to return BOOL under Win32.
1652 * Thread-local message queues are not supported.
1659 void WINAPI WaitMessage( void )
1661 QUEUE_WaitBits( QS_ALLINPUT, INFINITE );
1664 /***********************************************************************
1665 * MsgWaitForMultipleObjects (USER32.400)
1667 DWORD WINAPI MsgWaitForMultipleObjects( DWORD nCount, HANDLE *pHandles,
1668 BOOL fWaitAll, DWORD dwMilliseconds,
1672 HANDLE handles[MAXIMUM_WAIT_OBJECTS];
1675 HQUEUE16 hQueue = GetFastQueue16();
1676 MESSAGEQUEUE *msgQueue = (MESSAGEQUEUE *)QUEUE_Lock( hQueue );
1677 if (!msgQueue) return WAIT_FAILED;
1679 if (nCount > MAXIMUM_WAIT_OBJECTS-1)
1681 SetLastError( ERROR_INVALID_PARAMETER );
1682 QUEUE_Unlock( msgQueue );
1686 msgQueue->changeBits = 0;
1687 msgQueue->wakeMask = dwWakeMask;
1689 if (THREAD_IsWin16(THREAD_Current()))
1692 * This is a temporary solution to a big problem.
1693 * You see, the main thread of all Win32 programs is created as a 16 bit
1694 * task. This means that if you want on an event using Win32 synchronization
1695 * methods, the 16 bit scheduler is stopped and things might just stop happening.
1696 * This implements a semi-busy loop that checks the handles to wait on and
1697 * also the message queue. When either one is ready, the wait function returns.
1699 * This will all go away when the real Win32 threads are implemented for all
1700 * the threads of an applications. Including the main thread.
1702 DWORD curTime = GetCurrentTime();
1707 * Check the handles in the list.
1709 ret = WaitForMultipleObjects(nCount, pHandles, fWaitAll, 5L);
1712 * If the handles have been triggered, return.
1714 if (ret != WAIT_TIMEOUT)
1718 * Then, let the 16 bit scheduler do it's thing.
1723 * If a message matching the wait mask has arrived, return.
1725 if (msgQueue->changeBits & dwWakeMask)
1732 * And continue doing this until we hit the timeout.
1734 } while ((dwMilliseconds == INFINITE) || (GetCurrentTime()-curTime < dwMilliseconds) );
1738 /* Add the thread event to the handle list */
1739 for (i = 0; i < nCount; i++)
1740 handles[i] = pHandles[i];
1741 handles[nCount] = msgQueue->hEvent;
1743 ret = WaitForMultipleObjects( nCount+1, handles, fWaitAll, dwMilliseconds );
1746 QUEUE_Unlock( msgQueue );
1760 static const struct accent_char accent_chars[] =
1762 /* A good idea should be to read /usr/X11/lib/X11/locale/iso8859-x/Compose */
1763 {'`', 'A', '\300'}, {'`', 'a', '\340'},
1764 {'\'', 'A', '\301'}, {'\'', 'a', '\341'},
1765 {'^', 'A', '\302'}, {'^', 'a', '\342'},
1766 {'~', 'A', '\303'}, {'~', 'a', '\343'},
1767 {'"', 'A', '\304'}, {'"', 'a', '\344'},
1768 {'O', 'A', '\305'}, {'o', 'a', '\345'},
1769 {'0', 'A', '\305'}, {'0', 'a', '\345'},
1770 {'A', 'A', '\305'}, {'a', 'a', '\345'},
1771 {'A', 'E', '\306'}, {'a', 'e', '\346'},
1772 {',', 'C', '\307'}, {',', 'c', '\347'},
1773 {'`', 'E', '\310'}, {'`', 'e', '\350'},
1774 {'\'', 'E', '\311'}, {'\'', 'e', '\351'},
1775 {'^', 'E', '\312'}, {'^', 'e', '\352'},
1776 {'"', 'E', '\313'}, {'"', 'e', '\353'},
1777 {'`', 'I', '\314'}, {'`', 'i', '\354'},
1778 {'\'', 'I', '\315'}, {'\'', 'i', '\355'},
1779 {'^', 'I', '\316'}, {'^', 'i', '\356'},
1780 {'"', 'I', '\317'}, {'"', 'i', '\357'},
1781 {'-', 'D', '\320'}, {'-', 'd', '\360'},
1782 {'~', 'N', '\321'}, {'~', 'n', '\361'},
1783 {'`', 'O', '\322'}, {'`', 'o', '\362'},
1784 {'\'', 'O', '\323'}, {'\'', 'o', '\363'},
1785 {'^', 'O', '\324'}, {'^', 'o', '\364'},
1786 {'~', 'O', '\325'}, {'~', 'o', '\365'},
1787 {'"', 'O', '\326'}, {'"', 'o', '\366'},
1788 {'/', 'O', '\330'}, {'/', 'o', '\370'},
1789 {'`', 'U', '\331'}, {'`', 'u', '\371'},
1790 {'\'', 'U', '\332'}, {'\'', 'u', '\372'},
1791 {'^', 'U', '\333'}, {'^', 'u', '\373'},
1792 {'"', 'U', '\334'}, {'"', 'u', '\374'},
1793 {'\'', 'Y', '\335'}, {'\'', 'y', '\375'},
1794 {'T', 'H', '\336'}, {'t', 'h', '\376'},
1795 {'s', 's', '\337'}, {'"', 'y', '\377'},
1796 {'s', 'z', '\337'}, {'i', 'j', '\377'},
1797 /* iso-8859-2 uses this */
1798 {'<', 'L', '\245'}, {'<', 'l', '\265'}, /* caron */
1799 {'<', 'S', '\251'}, {'<', 's', '\271'},
1800 {'<', 'T', '\253'}, {'<', 't', '\273'},
1801 {'<', 'Z', '\256'}, {'<', 'z', '\276'},
1802 {'<', 'C', '\310'}, {'<', 'c', '\350'},
1803 {'<', 'E', '\314'}, {'<', 'e', '\354'},
1804 {'<', 'D', '\317'}, {'<', 'd', '\357'},
1805 {'<', 'N', '\322'}, {'<', 'n', '\362'},
1806 {'<', 'R', '\330'}, {'<', 'r', '\370'},
1807 {';', 'A', '\241'}, {';', 'a', '\261'}, /* ogonek */
1808 {';', 'E', '\312'}, {';', 'e', '\332'},
1809 {'\'', 'Z', '\254'}, {'\'', 'z', '\274'}, /* acute */
1810 {'\'', 'R', '\300'}, {'\'', 'r', '\340'},
1811 {'\'', 'L', '\305'}, {'\'', 'l', '\345'},
1812 {'\'', 'C', '\306'}, {'\'', 'c', '\346'},
1813 {'\'', 'N', '\321'}, {'\'', 'n', '\361'},
1814 /* collision whith S, from iso-8859-9 !!! */
1815 {',', 'S', '\252'}, {',', 's', '\272'}, /* cedilla */
1816 {',', 'T', '\336'}, {',', 't', '\376'},
1817 {'.', 'Z', '\257'}, {'.', 'z', '\277'}, /* dot above */
1818 {'/', 'L', '\243'}, {'/', 'l', '\263'}, /* slash */
1819 {'/', 'D', '\320'}, {'/', 'd', '\360'},
1820 {'(', 'A', '\303'}, {'(', 'a', '\343'}, /* breve */
1821 {'\275', 'O', '\325'}, {'\275', 'o', '\365'}, /* double acute */
1822 {'\275', 'U', '\334'}, {'\275', 'u', '\374'},
1823 {'0', 'U', '\332'}, {'0', 'u', '\372'}, /* ring above */
1824 /* iso-8859-3 uses this */
1825 {'/', 'H', '\241'}, {'/', 'h', '\261'}, /* slash */
1826 {'>', 'H', '\246'}, {'>', 'h', '\266'}, /* circumflex */
1827 {'>', 'J', '\254'}, {'>', 'j', '\274'},
1828 {'>', 'C', '\306'}, {'>', 'c', '\346'},
1829 {'>', 'G', '\330'}, {'>', 'g', '\370'},
1830 {'>', 'S', '\336'}, {'>', 's', '\376'},
1831 /* collision whith G( from iso-8859-9 !!! */
1832 {'(', 'G', '\253'}, {'(', 'g', '\273'}, /* breve */
1833 {'(', 'U', '\335'}, {'(', 'u', '\375'},
1834 /* collision whith I. from iso-8859-3 !!! */
1835 {'.', 'I', '\251'}, {'.', 'i', '\271'}, /* dot above */
1836 {'.', 'C', '\305'}, {'.', 'c', '\345'},
1837 {'.', 'G', '\325'}, {'.', 'g', '\365'},
1838 /* iso-8859-4 uses this */
1839 {',', 'R', '\243'}, {',', 'r', '\263'}, /* cedilla */
1840 {',', 'L', '\246'}, {',', 'l', '\266'},
1841 {',', 'G', '\253'}, {',', 'g', '\273'},
1842 {',', 'N', '\321'}, {',', 'n', '\361'},
1843 {',', 'K', '\323'}, {',', 'k', '\363'},
1844 {'~', 'I', '\245'}, {'~', 'i', '\265'}, /* tilde */
1845 {'-', 'E', '\252'}, {'-', 'e', '\272'}, /* macron */
1846 {'-', 'A', '\300'}, {'-', 'a', '\340'},
1847 {'-', 'I', '\317'}, {'-', 'i', '\357'},
1848 {'-', 'O', '\322'}, {'-', 'o', '\362'},
1849 {'-', 'U', '\336'}, {'-', 'u', '\376'},
1850 {'/', 'T', '\254'}, {'/', 't', '\274'}, /* slash */
1851 {'.', 'E', '\314'}, {'.', 'e', '\344'}, /* dot above */
1852 {';', 'I', '\307'}, {';', 'i', '\347'}, /* ogonek */
1853 {';', 'U', '\331'}, {';', 'u', '\371'},
1854 /* iso-8859-9 uses this */
1855 /* iso-8859-9 has really bad choosen G( S, and I. as they collide
1856 * whith the same letters on other iso-8859-x (that is they are on
1857 * different places :-( ), if you use turkish uncomment these and
1858 * comment out the lines in iso-8859-2 and iso-8859-3 sections
1859 * FIXME: should be dynamic according to chosen language
1860 * if/when Wine has turkish support.
1862 /* collision whith G( from iso-8859-3 !!! */
1863 /* {'(', 'G', '\320'}, {'(', 'g', '\360'}, */ /* breve */
1864 /* collision whith S, from iso-8859-2 !!! */
1865 /* {',', 'S', '\336'}, {',', 's', '\376'}, */ /* cedilla */
1866 /* collision whith I. from iso-8859-3 !!! */
1867 /* {'.', 'I', '\335'}, {'.', 'i', '\375'}, */ /* dot above */
1871 /***********************************************************************
1872 * MSG_DoTranslateMessage
1874 * Implementation of TranslateMessage.
1876 * TranslateMessage translates virtual-key messages into character-messages,
1878 * WM_KEYDOWN/WM_KEYUP combinations produce a WM_CHAR or WM_DEADCHAR message.
1879 * ditto replacing WM_* with WM_SYS*
1880 * This produces WM_CHAR messages only for keys mapped to ASCII characters
1881 * by the keyboard driver.
1883 static BOOL MSG_DoTranslateMessage( UINT message, HWND hwnd,
1884 WPARAM wParam, LPARAM lParam )
1886 static int dead_char;
1889 if (message != WM_MOUSEMOVE && message != WM_TIMER)
1890 TRACE(msg, "(%s, %04X, %08lX)\n",
1891 SPY_GetMsgName(message), wParam, lParam );
1892 if(message >= WM_KEYFIRST && message <= WM_KEYLAST)
1893 TRACE(key, "(%s, %04X, %08lX)\n",
1894 SPY_GetMsgName(message), wParam, lParam );
1896 if ((message != WM_KEYDOWN) && (message != WM_SYSKEYDOWN)) return FALSE;
1898 TRACE(key, "Translating key %04X, scancode %04X\n",
1899 wParam, HIWORD(lParam) );
1901 /* FIXME : should handle ToAscii yielding 2 */
1902 switch (ToAscii(wParam, HIWORD(lParam),
1903 QueueKeyStateTable,(LPWORD)wp, 0))
1906 message = (message == WM_KEYDOWN) ? WM_CHAR : WM_SYSCHAR;
1907 /* Should dead chars handling go in ToAscii ? */
1912 if (wp[0] == ' ') wp[0] = dead_char;
1913 if (dead_char == 0xa2) dead_char = '(';
1914 else if (dead_char == 0xa8) dead_char = '"';
1915 else if (dead_char == 0xb2) dead_char = ';';
1916 else if (dead_char == 0xb4) dead_char = '\'';
1917 else if (dead_char == 0xb7) dead_char = '<';
1918 else if (dead_char == 0xb8) dead_char = ',';
1919 else if (dead_char == 0xff) dead_char = '.';
1920 for (i = 0; i < sizeof(accent_chars)/sizeof(accent_chars[0]); i++)
1921 if ((accent_chars[i].ac_accent == dead_char) &&
1922 (accent_chars[i].ac_char == wp[0]))
1924 wp[0] = accent_chars[i].ac_result;
1929 TRACE(key, "1 -> PostMessage(%s)\n", SPY_GetMsgName(message));
1930 PostMessage16( hwnd, message, wp[0], lParam );
1934 message = (message == WM_KEYDOWN) ? WM_DEADCHAR : WM_SYSDEADCHAR;
1936 TRACE(key, "-1 -> PostMessage(%s)\n",
1937 SPY_GetMsgName(message));
1938 PostMessage16( hwnd, message, wp[0], lParam );
1945 /***********************************************************************
1946 * TranslateMessage16 (USER.113)
1948 BOOL16 WINAPI TranslateMessage16( const MSG16 *msg )
1950 return MSG_DoTranslateMessage( msg->message, msg->hwnd,
1951 msg->wParam, msg->lParam );
1955 /***********************************************************************
1956 * WIN16_TranslateMessage32 (USER.821)
1958 BOOL16 WINAPI TranslateMessage32_16( const MSG32_16 *msg, BOOL16 wHaveParamHigh )
1963 wParam = MAKELONG(msg->msg.wParam, msg->wParamHigh);
1965 wParam = (WPARAM)msg->msg.wParam;
1967 return MSG_DoTranslateMessage( msg->msg.message, msg->msg.hwnd,
1968 wParam, msg->msg.lParam );
1971 /***********************************************************************
1972 * TranslateMessage32 (USER32.556)
1974 BOOL WINAPI TranslateMessage( const MSG *msg )
1976 return MSG_DoTranslateMessage( msg->message, msg->hwnd,
1977 msg->wParam, msg->lParam );
1981 /***********************************************************************
1982 * DispatchMessage16 (USER.114)
1984 LONG WINAPI DispatchMessage16( const MSG16* msg )
1990 /* Process timer messages */
1991 if ((msg->message == WM_TIMER) || (msg->message == WM_SYSTIMER))
1995 return CallWindowProc16( (WNDPROC16)msg->lParam, msg->hwnd,
1996 msg->message, msg->wParam, GetTickCount() );
2000 if (!msg->hwnd) return 0;
2001 if (!(wndPtr = WIN_FindWndPtr( msg->hwnd ))) return 0;
2002 if (!wndPtr->winproc) return 0;
2003 painting = (msg->message == WM_PAINT);
2004 if (painting) wndPtr->flags |= WIN_NEEDS_BEGINPAINT;
2006 SPY_EnterMessage( SPY_DISPATCHMESSAGE16, msg->hwnd, msg->message,
2007 msg->wParam, msg->lParam );
2008 retval = CallWindowProc16( (WNDPROC16)wndPtr->winproc,
2009 msg->hwnd, msg->message,
2010 msg->wParam, msg->lParam );
2011 SPY_ExitMessage( SPY_RESULT_OK16, msg->hwnd, msg->message, retval );
2013 if (painting && (wndPtr = WIN_FindWndPtr( msg->hwnd )) &&
2014 (wndPtr->flags & WIN_NEEDS_BEGINPAINT) && wndPtr->hrgnUpdate)
2016 ERR(msg, "BeginPaint not called on WM_PAINT for hwnd %04x!\n",
2018 wndPtr->flags &= ~WIN_NEEDS_BEGINPAINT;
2019 /* Validate the update region to avoid infinite WM_PAINT loop */
2020 ValidateRect( msg->hwnd, NULL );
2026 /***********************************************************************
2027 * WIN16_DispatchMessage32 (USER.822)
2029 LONG WINAPI DispatchMessage32_16( const MSG32_16* lpmsg16_32, BOOL16 wHaveParamHigh )
2031 if (wHaveParamHigh == FALSE)
2032 return DispatchMessage16(&(lpmsg16_32->msg));
2037 msg.hwnd = lpmsg16_32->msg.hwnd;
2038 msg.message = lpmsg16_32->msg.message;
2039 msg.wParam = MAKELONG(lpmsg16_32->msg.wParam, lpmsg16_32->wParamHigh);
2040 msg.lParam = lpmsg16_32->msg.lParam;
2041 msg.time = lpmsg16_32->msg.time;
2042 msg.pt.x = (INT)lpmsg16_32->msg.pt.x;
2043 msg.pt.y = (INT)lpmsg16_32->msg.pt.y;
2044 return DispatchMessageA(&msg);
2048 /***********************************************************************
2049 * DispatchMessage32A (USER32.141)
2051 LONG WINAPI DispatchMessageA( const MSG* msg )
2057 /* Process timer messages */
2058 if ((msg->message == WM_TIMER) || (msg->message == WM_SYSTIMER))
2062 /* HOOK_CallHooks32A( WH_CALLWNDPROC, HC_ACTION, 0, FIXME ); */
2063 return CallWindowProcA( (WNDPROC)msg->lParam, msg->hwnd,
2064 msg->message, msg->wParam, GetTickCount() );
2068 if (!msg->hwnd) return 0;
2069 if (!(wndPtr = WIN_FindWndPtr( msg->hwnd ))) return 0;
2070 if (!wndPtr->winproc) return 0;
2071 painting = (msg->message == WM_PAINT);
2072 if (painting) wndPtr->flags |= WIN_NEEDS_BEGINPAINT;
2073 /* HOOK_CallHooks32A( WH_CALLWNDPROC, HC_ACTION, 0, FIXME ); */
2075 SPY_EnterMessage( SPY_DISPATCHMESSAGE, msg->hwnd, msg->message,
2076 msg->wParam, msg->lParam );
2077 retval = CallWindowProcA( (WNDPROC)wndPtr->winproc,
2078 msg->hwnd, msg->message,
2079 msg->wParam, msg->lParam );
2080 SPY_ExitMessage( SPY_RESULT_OK, msg->hwnd, msg->message, retval );
2082 if (painting && (wndPtr = WIN_FindWndPtr( msg->hwnd )) &&
2083 (wndPtr->flags & WIN_NEEDS_BEGINPAINT) && wndPtr->hrgnUpdate)
2085 ERR(msg, "BeginPaint not called on WM_PAINT for hwnd %04x!\n",
2087 wndPtr->flags &= ~WIN_NEEDS_BEGINPAINT;
2088 /* Validate the update region to avoid infinite WM_PAINT loop */
2089 ValidateRect( msg->hwnd, NULL );
2095 /***********************************************************************
2096 * DispatchMessage32W (USER32.142) Process Message
2098 * Process the message specified in the structure *_msg_.
2100 * If the lpMsg parameter points to a WM_TIMER message and the
2101 * parameter of the WM_TIMER message is not NULL, the lParam parameter
2102 * points to the function that is called instead of the window
2105 * The message must be valid.
2109 * DispatchMessage() returns the result of the window procedure invoked.
2116 LONG WINAPI DispatchMessageW( const MSG* msg )
2122 /* Process timer messages */
2123 if ((msg->message == WM_TIMER) || (msg->message == WM_SYSTIMER))
2127 /* HOOK_CallHooks32W( WH_CALLWNDPROC, HC_ACTION, 0, FIXME ); */
2128 return CallWindowProcW( (WNDPROC)msg->lParam, msg->hwnd,
2129 msg->message, msg->wParam, GetTickCount() );
2133 if (!msg->hwnd) return 0;
2134 if (!(wndPtr = WIN_FindWndPtr( msg->hwnd ))) return 0;
2135 if (!wndPtr->winproc) return 0;
2136 painting = (msg->message == WM_PAINT);
2137 if (painting) wndPtr->flags |= WIN_NEEDS_BEGINPAINT;
2138 /* HOOK_CallHooks32W( WH_CALLWNDPROC, HC_ACTION, 0, FIXME ); */
2140 SPY_EnterMessage( SPY_DISPATCHMESSAGE, msg->hwnd, msg->message,
2141 msg->wParam, msg->lParam );
2142 retval = CallWindowProcW( (WNDPROC)wndPtr->winproc,
2143 msg->hwnd, msg->message,
2144 msg->wParam, msg->lParam );
2145 SPY_ExitMessage( SPY_RESULT_OK, msg->hwnd, msg->message, retval );
2147 if (painting && (wndPtr = WIN_FindWndPtr( msg->hwnd )) &&
2148 (wndPtr->flags & WIN_NEEDS_BEGINPAINT) && wndPtr->hrgnUpdate)
2150 ERR(msg, "BeginPaint not called on WM_PAINT for hwnd %04x!\n",
2152 wndPtr->flags &= ~WIN_NEEDS_BEGINPAINT;
2153 /* Validate the update region to avoid infinite WM_PAINT loop */
2154 ValidateRect( msg->hwnd, NULL );
2160 /***********************************************************************
2161 * RegisterWindowMessage16 (USER.118)
2163 WORD WINAPI RegisterWindowMessage16( SEGPTR str )
2165 TRACE(msg, "%08lx\n", (DWORD)str );
2166 return GlobalAddAtom16( str );
2170 /***********************************************************************
2171 * RegisterWindowMessage32A (USER32.437)
2173 WORD WINAPI RegisterWindowMessageA( LPCSTR str )
2175 TRACE(msg, "%s\n", str );
2176 return GlobalAddAtomA( str );
2180 /***********************************************************************
2181 * RegisterWindowMessage32W (USER32.438)
2183 WORD WINAPI RegisterWindowMessageW( LPCWSTR str )
2185 TRACE(msg, "%p\n", str );
2186 return GlobalAddAtomW( str );
2190 /***********************************************************************
2191 * GetTickCount (USER.13) (KERNEL32.299) System Time
2192 * Returns the number of milliseconds, modulo 2^32, since the start
2193 * of the current session.
2199 DWORD WINAPI GetTickCount(void)
2202 gettimeofday( &t, NULL );
2203 /* make extremely compatible: granularity is 25 msec */
2204 return ((t.tv_sec * 1000) + (t.tv_usec / 25000) * 25) - MSG_WineStartTicks;
2208 /***********************************************************************
2209 * GetCurrentTime16 (USER.15)
2211 * (effectively identical to GetTickCount)
2213 DWORD WINAPI GetCurrentTime16(void)
2215 return GetTickCount();
2219 /***********************************************************************
2220 * InSendMessage16 (USER.192)
2222 BOOL16 WINAPI InSendMessage16(void)
2224 return InSendMessage();
2228 /***********************************************************************
2229 * InSendMessage32 (USER32.320)
2231 BOOL WINAPI InSendMessage(void)
2233 MESSAGEQUEUE *queue;
2236 if (!(queue = (MESSAGEQUEUE *)QUEUE_Lock( GetFastQueue16() )))
2238 ret = (BOOL)queue->smWaiting;
2240 QUEUE_Unlock( queue );
2244 /***********************************************************************
2245 * BroadcastSystemMessage (USER32.12)
2247 LONG WINAPI BroadcastSystemMessage(
2248 DWORD dwFlags,LPDWORD recipients,UINT uMessage,WPARAM wParam,
2251 FIXME(sendmsg,"(%08lx,%08lx,%08x,%08x,%08lx): stub!\n",
2252 dwFlags,*recipients,uMessage,wParam,lParam
2257 /***********************************************************************
2258 * SendNotifyMessageA (USER32.460)
2260 * The message sended with PostMessage has to be put in the queue
2261 * with a higher priority as the other "Posted" messages.
2262 * QUEUE_AddMsg has to be modifyed.
2264 BOOL WINAPI SendNotifyMessageA(HWND hwnd,UINT msg,WPARAM wParam,LPARAM lParam)
2266 FIXME(msg,"(%04x,%08x,%08x,%08lx) not complete\n",
2267 hwnd, msg, wParam, lParam);
2269 if ( GetCurrentThreadId() == GetWindowThreadProcessId ( hwnd, NULL))
2270 { ret=SendMessageA ( hwnd, msg, wParam, lParam );
2273 { PostMessageA ( hwnd, msg, wParam, lParam );
2278 /***********************************************************************
2279 * SendNotifyMessageW (USER32.461)
2281 * The message sended with PostMessage has to be put in the queue
2282 * with a higher priority as the other "Posted" messages.
2283 * QUEUE_AddMsg has to be modifyed.
2285 BOOL WINAPI SendNotifyMessageW(HWND hwnd,UINT msg,WPARAM wParam,LPARAM lParam)
2287 FIXME(msg,"(%04x,%08x,%08x,%08lx) not complete\n",
2288 hwnd, msg, wParam, lParam);
2290 if ( GetCurrentThreadId() == GetWindowThreadProcessId ( hwnd, NULL))
2291 { ret=SendMessageW ( hwnd, msg, wParam, lParam );
2294 { PostMessageW ( hwnd, msg, wParam, lParam );
2299 /***********************************************************************
2300 * SendMessageCallBack32A
2301 * FIXME: It's like PostMessage. The callback gets called when the message
2302 * is processed. We have to modify the message processing for a exact
2305 BOOL WINAPI SendMessageCallBackA(
2306 HWND hWnd,UINT Msg,WPARAM wParam,LPARAM lParam,
2307 FARPROC lpResultCallBack,DWORD dwData)
2309 FIXME(msg,"(0x%04x,0x%04x,0x%08x,0x%08lx,%p,0x%08lx),stub!\n",
2310 hWnd,Msg,wParam,lParam,lpResultCallBack,dwData);
2311 if ( hWnd == HWND_BROADCAST)
2312 { PostMessageA( hWnd, Msg, wParam, lParam);
2313 FIXME(msg,"Broadcast: Callback will not be called!\n");
2316 (lpResultCallBack)( hWnd, Msg, dwData, SendMessageA ( hWnd, Msg, wParam, lParam ));