2 * Message queues related functions
4 * Copyright 1993, 1994 Alexandre Julliard
11 #include <sys/types.h>
13 #include "wine/winbase16.h"
30 #include "debugtools.h"
32 DECLARE_DEBUG_CHANNEL(key)
33 DECLARE_DEBUG_CHANNEL(msg)
34 DECLARE_DEBUG_CHANNEL(sendmsg)
36 #define WM_NCMOUSEFIRST WM_NCMOUSEMOVE
37 #define WM_NCMOUSELAST WM_NCMBUTTONDBLCLK
40 typedef enum { SYSQ_MSG_ABANDON, SYSQ_MSG_SKIP,
41 SYSQ_MSG_ACCEPT, SYSQ_MSG_CONTINUE } SYSQ_STATUS;
43 extern HQUEUE16 hCursorQueue; /* queue.c */
45 DWORD MSG_WineStartTicks; /* Ticks at Wine startup */
47 static UINT doubleClickSpeed = 452;
49 /***********************************************************************
52 BOOL MSG_CheckFilter(DWORD uMsg, DWORD first, DWORD last)
55 return (uMsg >= first && uMsg <= last);
59 /***********************************************************************
60 * MSG_SendParentNotify
62 * Send a WM_PARENTNOTIFY to all ancestors of the given window, unless
63 * the window has the WS_EX_NOPARENTNOTIFY style.
65 static void MSG_SendParentNotify(WND* wndPtr, WORD event, WORD idChild, LPARAM lValue)
67 #define lppt ((LPPOINT16)&lValue)
69 /* pt has to be in the client coordinates of the parent window */
70 WND *tmpWnd = WIN_LockWndPtr(wndPtr);
72 MapWindowPoints16( 0, tmpWnd->hwndSelf, lppt, 1 );
75 if (!(tmpWnd->dwStyle & WS_CHILD) || (tmpWnd->dwExStyle & WS_EX_NOPARENTNOTIFY))
77 WIN_ReleaseWndPtr(tmpWnd);
80 lppt->x += tmpWnd->rectClient.left;
81 lppt->y += tmpWnd->rectClient.top;
82 WIN_UpdateWndPtr(&tmpWnd,tmpWnd->parent);
83 SendMessageA( tmpWnd->hwndSelf, WM_PARENTNOTIFY,
84 MAKEWPARAM( event, idChild ), lValue );
91 /***********************************************************************
92 * MSG_TranslateMouseMsg
94 * Translate an mouse hardware event into a real mouse message.
98 * SYSQ_MSG_ABANDON - abandon the peek message loop
99 * SYSQ_MSG_CONTINUE - leave the message in the queue and
100 * continue with the translation loop
101 * SYSQ_MSG_ACCEPT - proceed to process the translated message
103 static DWORD MSG_TranslateMouseMsg( HWND hTopWnd, DWORD first, DWORD last,
104 MSG *msg, BOOL remove, WND* pWndScope,
105 INT16 *pHitTest, POINT16 *pScreen_pt, BOOL *pmouseClick )
107 static DWORD dblclk_time_limit = 0;
108 static UINT16 clk_message = 0;
109 static HWND16 clk_hwnd = 0;
110 static POINT16 clk_pos = { 0, 0 };
115 UINT message = msg->message;
116 POINT16 screen_pt, pt;
117 HANDLE16 hQ = GetFastQueue16();
118 MESSAGEQUEUE *queue = (MESSAGEQUEUE *)QUEUE_Lock(hQ);
119 BOOL mouseClick = ((message == WM_LBUTTONDOWN) ||
120 (message == WM_RBUTTONDOWN) ||
121 (message == WM_MBUTTONDOWN))?1:0;
124 /* Find the window to dispatch this mouse message to */
126 CONV_POINT32TO16( &msg->pt, &pt );
130 /* If no capture HWND, find window which contains the mouse position.
131 * Also find the position of the cursor hot spot (hittest) */
134 ht = hittest = WINPOS_WindowFromPoint( pWndScope, pt, &pWnd );
135 if( !pWnd ) pWnd = WIN_GetDesktop();
136 else WIN_LockWndPtr(pWnd);
137 hWnd = pWnd->hwndSelf;
141 ht = hittest = HTCLIENT;
142 pWnd = WIN_FindWndPtr(hWnd);
144 ht = PERQDATA_GetCaptureInfo( queue->pQData );
147 /* Save hittest for return */
150 /* stop if not the right queue */
152 if (pWnd->hmemTaskQ != hQ)
154 /* Not for the current task */
155 if (queue) QUEUE_ClearWakeBit( queue, QS_MOUSE );
156 /* Wake up the other task */
157 QUEUE_Unlock( queue );
158 queue = (MESSAGEQUEUE *)QUEUE_Lock( pWnd->hmemTaskQ );
159 if (queue) QUEUE_SetWakeBit( queue, QS_MOUSE );
161 QUEUE_Unlock( queue );
162 retvalue = SYSQ_MSG_ABANDON;
166 /* check if hWnd is within hWndScope */
168 if( hTopWnd && hWnd != hTopWnd )
169 if( !IsChild(hTopWnd, hWnd) )
171 QUEUE_Unlock( queue );
172 retvalue = SYSQ_MSG_CONTINUE;
176 /* Was it a mouse click message */
179 /* translate double clicks -
180 * note that ...MOUSEMOVEs can slip in between
181 * ...BUTTONDOWN and ...BUTTONDBLCLK messages */
183 if(GetClassLongA(hWnd, GCL_STYLE) & CS_DBLCLKS || ht != HTCLIENT )
185 if ((message == clk_message) && (hWnd == clk_hwnd) &&
186 (msg->time - dblclk_time_limit < doubleClickSpeed) &&
187 (abs(msg->pt.x - clk_pos.x) < GetSystemMetrics(SM_CXDOUBLECLK)/2) &&
188 (abs(msg->pt.y - clk_pos.y) < GetSystemMetrics(SM_CYDOUBLECLK)/2))
190 message += (WM_LBUTTONDBLCLK - WM_LBUTTONDOWN);
191 mouseClick++; /* == 2 */
195 /* save mouse position */
199 if (hittest != HTCLIENT)
201 message += WM_NCMOUSEMOVE - WM_MOUSEMOVE;
202 msg->wParam = hittest;
205 ScreenToClient16( hWnd, &pt );
207 /* check message filter */
209 if (!MSG_CheckFilter(message, first, last))
212 retvalue = SYSQ_MSG_CONTINUE;
216 /* Update global hCursorQueue */
217 hCursorQueue = queue->self;
219 /* Update static double click conditions */
220 if( remove && mouseClick )
222 if( mouseClick == 1 )
225 dblclk_time_limit = msg->time;
226 clk_message = msg->message;
230 /* got double click - zero them out */
231 dblclk_time_limit = clk_hwnd = 0;
236 /* Update message params */
238 msg->message = message;
239 msg->lParam = MAKELONG( pt.x, pt.y );
240 retvalue = SYSQ_MSG_ACCEPT;
243 WIN_ReleaseWndPtr(pWnd);
245 /* Return mouseclick flag */
246 *pmouseClick = mouseClick;
252 /***********************************************************************
253 * MSG_ProcessMouseMsg
255 * Processes a translated mouse hardware event.
256 * The passed in msg structure should contain the updated hWnd,
257 * lParam, wParam and message fields from MSG_TranslateMouseMsg.
261 * SYSQ_MSG_SKIP - Message should be skipped entirely (in this case
262 * HIWORD contains hit test code). Continue translating..
263 * SYSQ_MSG_ACCEPT - the translated message must be passed to the user
264 * MSG_PeekHardwareMsg should return TRUE.
266 static DWORD MSG_ProcessMouseMsg( MSG *msg, BOOL remove, INT16 hittest,
267 POINT16 screen_pt, BOOL mouseClick )
270 HWND hWnd = msg->hwnd;
271 INT16 sendSC = (GetCapture() == 0);
272 UINT message = msg->message;
276 pWnd = WIN_FindWndPtr(hWnd);
280 if (HOOK_IsHooked( WH_MOUSE ))
283 MOUSEHOOKSTRUCT16 *hook = SEGPTR_NEW(MOUSEHOOKSTRUCT16);
286 hook->pt = screen_pt;
288 hook->wHitTestCode = hittest;
289 hook->dwExtraInfo = 0;
290 ret = HOOK_CallHooks16( WH_MOUSE, remove ? HC_ACTION : HC_NOREMOVE,
291 message, (LPARAM)SEGPTR_GET(hook) );
296 retvalue = MAKELONG((INT16)SYSQ_MSG_SKIP, hittest);
302 if ((hittest == HTERROR) || (hittest == HTNOWHERE))
304 else if( remove && mouseClick )
306 HWND hwndTop = WIN_GetTopParent( hWnd );
310 /* Send the WM_PARENTNOTIFY,
311 * note that even for double/nonclient clicks
312 * notification message is still WM_L/M/RBUTTONDOWN.
315 MSG_SendParentNotify( pWnd, msg->message & 0xffff, 0, MAKELPARAM(screen_pt.x, screen_pt.y) );
317 /* Activate the window if needed */
319 if (hWnd != GetActiveWindow() && hWnd != GetDesktopWindow())
321 LONG ret = SendMessageA( hWnd, WM_MOUSEACTIVATE, hwndTop,
322 MAKELONG( hittest, message ) );
324 if ((ret == MA_ACTIVATEANDEAT) || (ret == MA_NOACTIVATEANDEAT))
327 if (((ret == MA_ACTIVATE) || (ret == MA_ACTIVATEANDEAT))
328 && hwndTop != GetActiveWindow() )
329 if (!WINPOS_SetActiveWindow( hwndTop, TRUE , TRUE ))
333 } else sendSC = (remove && sendSC);
335 /* Send the WM_SETCURSOR message */
338 SendMessageA( hWnd, WM_SETCURSOR, hWnd,
339 MAKELONG( hittest, message ));
342 retvalue = MAKELONG( (UINT16)SYSQ_MSG_SKIP, hittest);
346 retvalue = SYSQ_MSG_ACCEPT;
348 WIN_ReleaseWndPtr(pWnd);
354 /***********************************************************************
355 * MSG_TranslateKbdMsg
357 * Translate an keyboard hardware event into a real message.
359 static DWORD MSG_TranslateKbdMsg( HWND hTopWnd, DWORD first, DWORD last,
360 MSG *msg, BOOL remove )
362 WORD message = msg->message;
363 HWND hWnd = GetFocus();
366 /* Should check Ctrl-Esc and PrintScreen here */
370 /* Send the message to the active window instead, */
371 /* translating messages to their WM_SYS equivalent */
373 hWnd = GetActiveWindow();
375 if( message < WM_SYSKEYDOWN )
376 message += WM_SYSKEYDOWN - WM_KEYDOWN;
378 pWnd = WIN_FindWndPtr( hWnd );
379 if (pWnd && (pWnd->hmemTaskQ != GetFastQueue16()))
381 /* Not for the current task */
382 MESSAGEQUEUE *queue = (MESSAGEQUEUE *)QUEUE_Lock( GetFastQueue16() );
383 if (queue) QUEUE_ClearWakeBit( queue, QS_KEY );
384 QUEUE_Unlock( queue );
386 /* Wake up the other task */
387 queue = (MESSAGEQUEUE *)QUEUE_Lock( pWnd->hmemTaskQ );
388 if (queue) QUEUE_SetWakeBit( queue, QS_KEY );
389 QUEUE_Unlock( queue );
390 WIN_ReleaseWndPtr(pWnd);
391 return SYSQ_MSG_ABANDON;
393 WIN_ReleaseWndPtr(pWnd);
395 if (hTopWnd && hWnd != hTopWnd)
396 if (!IsChild(hTopWnd, hWnd)) return SYSQ_MSG_CONTINUE;
397 if (!MSG_CheckFilter(message, first, last)) return SYSQ_MSG_CONTINUE;
400 msg->message = message;
402 return SYSQ_MSG_ACCEPT;
406 /***********************************************************************
409 * Processes a translated keyboard message
411 static DWORD MSG_ProcessKbdMsg( MSG *msg, BOOL remove )
413 return (HOOK_CallHooks16( WH_KEYBOARD, remove ? HC_ACTION : HC_NOREMOVE,
414 LOWORD (msg->wParam), msg->lParam )
415 ? SYSQ_MSG_SKIP : SYSQ_MSG_ACCEPT);
419 /***********************************************************************
420 * MSG_JournalRecordMsg
422 * Build an EVENTMSG structure and call JOURNALRECORD hook
424 static void MSG_JournalRecordMsg( MSG *msg )
426 EVENTMSG *event = (EVENTMSG *) HeapAlloc(SystemHeap, 0, sizeof(EVENTMSG));
428 event->message = msg->message;
429 event->time = msg->time;
430 if ((msg->message >= WM_KEYFIRST) && (msg->message <= WM_KEYLAST))
432 event->paramL = (msg->wParam & 0xFF) | (HIWORD(msg->lParam) << 8);
433 event->paramH = msg->lParam & 0x7FFF;
434 if (HIWORD(msg->lParam) & 0x0100)
435 event->paramH |= 0x8000; /* special_key - bit */
436 HOOK_CallHooksA( WH_JOURNALRECORD, HC_ACTION, 0, (LPARAM)event );
438 else if ((msg->message >= WM_MOUSEFIRST) && (msg->message <= WM_MOUSELAST))
440 event->paramL = LOWORD(msg->lParam); /* X pos */
441 event->paramH = HIWORD(msg->lParam); /* Y pos */
442 ClientToScreen16( msg->hwnd, (LPPOINT16)&event->paramL );
443 HOOK_CallHooksA( WH_JOURNALRECORD, HC_ACTION, 0, (LPARAM)event );
445 else if ((msg->message >= WM_NCMOUSEFIRST) &&
446 (msg->message <= WM_NCMOUSELAST))
448 event->paramL = LOWORD(msg->lParam); /* X pos */
449 event->paramH = HIWORD(msg->lParam); /* Y pos */
450 event->message += WM_MOUSEMOVE-WM_NCMOUSEMOVE;/* give no info about NC area */
451 HOOK_CallHooksA( WH_JOURNALRECORD, HC_ACTION, 0, (LPARAM)event );
454 HeapFree(SystemHeap, 0, event);
457 /***********************************************************************
458 * MSG_JournalPlayBackMsg
460 * Get an EVENTMSG struct via call JOURNALPLAYBACK hook function
462 static int MSG_JournalPlayBackMsg(void)
465 long wtime,lParam,wParam;
466 WORD keyDown,i,result=0;
468 if ( HOOK_IsHooked( WH_JOURNALPLAYBACK ) )
470 tmpMsg = (EVENTMSG *) HeapAlloc(SystemHeap, 0, sizeof(EVENTMSG));
471 if (!tmpMsg) return result;
473 wtime=HOOK_CallHooksA( WH_JOURNALPLAYBACK, HC_GETNEXT, 0,
475 /* TRACE(msg,"Playback wait time =%ld\n",wtime); */
479 if ((tmpMsg->message>= WM_KEYFIRST) && (tmpMsg->message <= WM_KEYLAST))
481 wParam=tmpMsg->paramL & 0xFF;
482 lParam=MAKELONG(tmpMsg->paramH&0x7ffff,tmpMsg->paramL>>8);
483 if (tmpMsg->message == WM_KEYDOWN || tmpMsg->message == WM_SYSKEYDOWN)
485 for (keyDown=i=0; i<256 && !keyDown; i++)
486 if (InputKeyStateTable[i] & 0x80)
489 lParam |= 0x40000000;
490 AsyncKeyStateTable[wParam]=InputKeyStateTable[wParam] |= 0x80;
492 else /* WM_KEYUP, WM_SYSKEYUP */
494 lParam |= 0xC0000000;
495 AsyncKeyStateTable[wParam]=InputKeyStateTable[wParam] &= ~0x80;
497 if (InputKeyStateTable[VK_MENU] & 0x80)
498 lParam |= 0x20000000;
499 if (tmpMsg->paramH & 0x8000) /*special_key bit*/
500 lParam |= 0x01000000;
501 hardware_event( tmpMsg->message & 0xffff, LOWORD(wParam), lParam,
502 0, 0, tmpMsg->time, 0 );
506 if ((tmpMsg->message>= WM_MOUSEFIRST) && (tmpMsg->message <= WM_MOUSELAST))
508 switch (tmpMsg->message)
511 MouseButtonsStates[0]=AsyncMouseButtonsStates[0]=TRUE;break;
513 MouseButtonsStates[0]=AsyncMouseButtonsStates[0]=FALSE;break;
515 MouseButtonsStates[1]=AsyncMouseButtonsStates[1]=TRUE;break;
517 MouseButtonsStates[1]=AsyncMouseButtonsStates[1]=FALSE;break;
519 MouseButtonsStates[2]=AsyncMouseButtonsStates[2]=TRUE;break;
521 MouseButtonsStates[2]=AsyncMouseButtonsStates[2]=FALSE;break;
523 AsyncKeyStateTable[VK_LBUTTON]= InputKeyStateTable[VK_LBUTTON] = MouseButtonsStates[0] ? 0x80 : 0;
524 AsyncKeyStateTable[VK_MBUTTON]= InputKeyStateTable[VK_MBUTTON] = MouseButtonsStates[1] ? 0x80 : 0;
525 AsyncKeyStateTable[VK_RBUTTON]= InputKeyStateTable[VK_RBUTTON] = MouseButtonsStates[2] ? 0x80 : 0;
526 SetCursorPos(tmpMsg->paramL,tmpMsg->paramH);
527 lParam=MAKELONG(tmpMsg->paramL,tmpMsg->paramH);
529 if (MouseButtonsStates[0]) wParam |= MK_LBUTTON;
530 if (MouseButtonsStates[1]) wParam |= MK_MBUTTON;
531 if (MouseButtonsStates[2]) wParam |= MK_RBUTTON;
532 hardware_event( tmpMsg->message & 0xffff, LOWORD (wParam), lParam,
533 tmpMsg->paramL, tmpMsg->paramH, tmpMsg->time, 0 );
536 HOOK_CallHooksA( WH_JOURNALPLAYBACK, HC_SKIP, 0,
542 if( tmpMsg->message == WM_QUEUESYNC )
543 if (HOOK_IsHooked( WH_CBT ))
544 HOOK_CallHooksA( WH_CBT, HCBT_QS, 0, 0L);
546 result= QS_MOUSE | QS_KEY; /* ? */
548 HeapFree(SystemHeap, 0, tmpMsg);
553 /***********************************************************************
554 * MSG_PeekHardwareMsg
556 * Peek for a hardware message matching the hwnd and message filters.
558 static BOOL MSG_PeekHardwareMsg( MSG *msg, HWND hwnd, DWORD first, DWORD last,
561 /* FIXME: should deal with MSG32 instead of MSG16 */
563 DWORD status = SYSQ_MSG_ACCEPT;
564 MESSAGEQUEUE *sysMsgQueue = QUEUE_GetSysQueue();
565 enum { MOUSE_MSG = 0, KEYBOARD_MSG, HARDWARE_MSG } msgType;
566 QMSG *nextqmsg, *qmsg = 0;
569 /* FIXME: there has to be a better way to do this */
572 EnterCriticalSection(&sysMsgQueue->cSection);
574 /* Loop through the Q and translate the message we wish to process
575 * while we own the lock. Based on the translation status (abandon/cont/accept)
576 * we then process the message accordingly
579 for ( qmsg = sysMsgQueue->firstMsg; qmsg; qmsg = nextqmsg )
587 nextqmsg = qmsg->nextMsg;
589 /* Translate message */
591 if ((msg->message >= WM_MOUSEFIRST) && (msg->message <= WM_MOUSELAST))
593 HWND hWndScope = (HWND)qmsg->extraInfo;
594 WND *tmpWnd = (Options.managed && IsWindow(hWndScope) )
595 ? WIN_FindWndPtr(hWndScope) : WIN_GetDesktop();
597 status = MSG_TranslateMouseMsg(hwnd, first, last, msg, remove, tmpWnd,
598 &hittest, &screen_pt, &mouseClick );
601 WIN_ReleaseWndPtr(tmpWnd);
604 else if ((msg->message >= WM_KEYFIRST) && (msg->message <= WM_KEYLAST))
606 status = MSG_TranslateKbdMsg(hwnd, first, last, msg, remove);
607 msgType = KEYBOARD_MSG;
609 else /* Non-standard hardware event */
611 HARDWAREHOOKSTRUCT16 *hook;
612 msgType = HARDWARE_MSG;
613 if ((hook = SEGPTR_NEW(HARDWAREHOOKSTRUCT16)))
616 hook->hWnd = msg->hwnd;
617 hook->wMessage = msg->message & 0xffff;
618 hook->wParam = LOWORD (msg->wParam);
619 hook->lParam = msg->lParam;
620 ret = HOOK_CallHooks16( WH_HARDWARE,
621 remove ? HC_ACTION : HC_NOREMOVE,
622 0, (LPARAM)SEGPTR_GET(hook) );
626 QUEUE_RemoveMsg( sysMsgQueue, qmsg );
629 status = SYSQ_MSG_ACCEPT;
634 switch (LOWORD(status))
636 case SYSQ_MSG_ACCEPT:
638 /* Remove the message from the system msg Q while it is still locked,
639 * before accepting it */
642 if (HOOK_IsHooked( WH_JOURNALRECORD )) MSG_JournalRecordMsg( msg );
643 QUEUE_RemoveMsg( sysMsgQueue, qmsg );
645 /* Now actually process the message, after we unlock the system msg Q.
646 * We should not hold on to the crst since SendMessage calls during processing
647 * will potentially cause callbacks to PeekMessage from the application.
648 * If we're holding the crst and QUEUE_WaitBits is called with a
649 * QS_SENDMESSAGE mask we will deadlock in hardware_event() when a
650 * message is being posted to the Q.
652 LeaveCriticalSection(&sysMsgQueue->cSection);
653 if( msgType == KEYBOARD_MSG )
654 status = MSG_ProcessKbdMsg( msg, remove );
655 else if ( msgType == MOUSE_MSG )
656 status = MSG_ProcessMouseMsg( msg, remove, hittest, screen_pt, mouseClick );
658 /* Reclaim the sys msg Q crst */
659 EnterCriticalSection(&sysMsgQueue->cSection);
661 /* Pass the translated message to the user if it was accepted */
662 if (status == SYSQ_MSG_ACCEPT)
665 /* If not accepted, fall through into the SYSQ_MSG_SKIP case */
669 if (HOOK_IsHooked( WH_CBT ))
671 if( msgType == KEYBOARD_MSG )
672 HOOK_CallHooks16( WH_CBT, HCBT_KEYSKIPPED,
673 LOWORD (msg->wParam), msg->lParam );
674 else if ( msgType == MOUSE_MSG )
676 MOUSEHOOKSTRUCT16 *hook = SEGPTR_NEW(MOUSEHOOKSTRUCT16);
679 CONV_POINT32TO16( &msg->pt,&hook->pt );
680 hook->hwnd = msg->hwnd;
681 hook->wHitTestCode = HIWORD(status);
682 hook->dwExtraInfo = 0;
683 HOOK_CallHooks16( WH_CBT, HCBT_CLICKSKIPPED ,msg->message & 0xffff,
684 (LPARAM)SEGPTR_GET(hook) );
690 /* If the message was removed earlier set up nextqmsg so that we start
691 * at the top of the queue again. We need to do this since our next pointer
692 * could be invalid due to us unlocking the system message Q to process the message.
693 * If not removed just refresh nextqmsg to point to the next msg.
696 nextqmsg = sysMsgQueue->firstMsg;
698 nextqmsg = qmsg->nextMsg;
702 case SYSQ_MSG_CONTINUE:
705 case SYSQ_MSG_ABANDON:
715 LeaveCriticalSection(&sysMsgQueue->cSection);
720 /**********************************************************************
721 * SetDoubleClickTime16 (USER.20)
723 void WINAPI SetDoubleClickTime16( UINT16 interval )
725 SetDoubleClickTime( interval );
729 /**********************************************************************
730 * SetDoubleClickTime32 (USER32.480)
732 BOOL WINAPI SetDoubleClickTime( UINT interval )
734 doubleClickSpeed = interval ? interval : 500;
739 /**********************************************************************
740 * GetDoubleClickTime16 (USER.21)
742 UINT16 WINAPI GetDoubleClickTime16(void)
744 return doubleClickSpeed;
748 /**********************************************************************
749 * GetDoubleClickTime32 (USER32.239)
751 UINT WINAPI GetDoubleClickTime(void)
753 return doubleClickSpeed;
757 /***********************************************************************
758 * MSG_SendMessageInterThread
760 * Implementation of an inter-task SendMessage.
762 * 0 if error or timeout
765 static LRESULT MSG_SendMessageInterThread( HQUEUE16 hDestQueue,
767 WPARAM wParam, LPARAM lParam,
768 DWORD timeout, WORD flags,
771 MESSAGEQUEUE *queue, *destQ;
778 if (IsTaskLocked16() || !IsWindow(hwnd))
781 /* create a SMSG structure to hold SendMessage() parameters */
782 if (! (smsg = (SMSG *) HeapAlloc( SystemHeap, 0, sizeof(SMSG) )) )
784 if (!(queue = (MESSAGEQUEUE*)QUEUE_Lock( GetFastQueue16() ))) return 0;
786 if (!(destQ = (MESSAGEQUEUE*)QUEUE_Lock( hDestQueue )))
788 QUEUE_Unlock( queue );
792 TRACE_(sendmsg)("SM: %s [%04x] (%04x -> %04x)\n",
793 SPY_GetMsgName(msg), msg, queue->self, hDestQueue );
795 /* fill up SMSG structure */
798 smsg->wParam = wParam;
799 smsg->lParam = lParam;
802 smsg->hSrcQueue = GetFastQueue16();
803 smsg->hDstQueue = hDestQueue;
806 /* add smsg struct in the processing SM list of the source queue */
807 QUEUE_AddSMSG(queue, SM_PROCESSING_LIST, smsg);
809 /* add smsg struct in the pending list of the destination queue */
810 if (QUEUE_AddSMSG(destQ, SM_PENDING_LIST, smsg) == FALSE)
813 iWndsLocks = WIN_SuspendWndsLock();
815 /* force destination task to run next, if 16 bit threads */
816 if ( THREAD_IsWin16(THREAD_Current()) && THREAD_IsWin16(destQ->thdb) )
817 DirectedYield16( destQ->thdb->teb.htask16 );
819 /* wait for the result, note that 16-bit apps almost always get out of
820 * DirectedYield() with SMSG_HAVE_RESULT flag already set */
825 * The sequence is crucial to avoid deadlock situations:
826 * - first, we clear the QS_SMRESULT bit
827 * - then, we check the SMSG_HAVE_RESULT bit
828 * - only if this isn't set, we enter the wait state.
830 * As the receiver first sets the SMSG_HAVE_RESULT and then wakes us,
831 * we are guaranteed that -should we now clear the QS_SMRESULT that
832 * was signalled already by the receiver- we will not start waiting.
835 if ( smsg->flags & SMSG_HAVE_RESULT )
838 *pRes = smsg->lResult;
839 TRACE_(sendmsg)("smResult = %08x\n", (unsigned)*pRes );
843 QUEUE_ClearWakeBit( queue, QS_SMRESULT );
845 if ( smsg->flags & SMSG_HAVE_RESULT )
848 if( QUEUE_WaitBits( QS_SMRESULT, timeout ) == 0 )
850 /* return with timeout */
856 WIN_RestoreWndsLock(iWndsLocks);
858 /* remove the smsg from the processingg list of the source queue */
859 QUEUE_RemoveSMSG( queue, SM_PROCESSING_LIST, smsg );
861 /* Note: the destination thread is in charge of removing the smsg from
864 /* In the case of an early reply (or a timeout), sender thread will
865 released the smsg structure if the receiver thread is done
866 (SMSG_RECEIVED set). If the receiver thread isn't done,
867 SMSG_RECEIVER_CLEANS_UP flag is set, and it will be the receiver
868 responsability to released smsg */
869 EnterCriticalSection( &queue->cSection );
871 if (smsg->flags & SMSG_RECEIVED)
872 HeapFree(SystemHeap, 0, smsg);
874 smsg->flags |= SMSG_RECEIVER_CLEANS;
876 LeaveCriticalSection( &queue->cSection );
879 QUEUE_Unlock( queue );
880 QUEUE_Unlock( destQ );
882 TRACE_(sendmsg)("done!\n");
887 /***********************************************************************
888 * ReplyMessage16 (USER.115)
890 void WINAPI ReplyMessage16( LRESULT result )
892 ReplyMessage( result );
895 /***********************************************************************
896 * ReplyMessage (USER.115)
898 BOOL WINAPI ReplyMessage( LRESULT result )
900 MESSAGEQUEUE *senderQ = 0;
901 MESSAGEQUEUE *queue = 0;
905 if (!(queue = (MESSAGEQUEUE*)QUEUE_Lock( GetFastQueue16() )))
908 TRACE_(sendmsg)("ReplyMessage, queue %04x\n", queue->self);
911 if ( !(smsg = queue->smWaiting)
912 || !(senderQ = QUEUE_Lock( smsg->hSrcQueue )) )
913 goto ReplyMessageEnd;
915 if ( !(smsg->flags & SMSG_ALREADY_REPLIED) )
917 /* This is the first reply, so pass result to sender */
919 TRACE_(sendmsg)("\trpm: smResult = %08lx\n", (long) result );
921 EnterCriticalSection(&senderQ->cSection);
923 smsg->lResult = result;
924 smsg->flags |= SMSG_ALREADY_REPLIED;
926 /* check if it's an early reply (called by the application) or
927 a regular reply (called by ReceiveMessage) */
928 if ( !(smsg->flags & SMSG_SENDING_REPLY) )
929 smsg->flags |= SMSG_EARLY_REPLY;
931 smsg->flags |= SMSG_HAVE_RESULT;
933 LeaveCriticalSection(&senderQ->cSection);
935 /* tell the sending task that its reply is ready */
936 QUEUE_SetWakeBit( senderQ, QS_SMRESULT );
938 /* switch directly to sending task (16 bit thread only) */
939 if ( THREAD_IsWin16( THREAD_Current() ) && THREAD_IsWin16( senderQ->thdb ) )
940 DirectedYield16( senderQ->thdb->teb.htask16 );
945 if (smsg->flags & SMSG_SENDING_REPLY)
947 /* remove msg from the waiting list, since this is the last
949 QUEUE_RemoveSMSG( queue, SM_WAITING_LIST, smsg );
951 EnterCriticalSection(&senderQ->cSection);
953 /* tell the sender we're all done with smsg structure */
954 smsg->flags |= SMSG_RECEIVED;
956 /* sender will set SMSG_RECEIVER_CLEANS_UP if it wants the
957 receiver to clean up smsg, it could only happens when there is
958 an early reply or a timeout */
959 if ( smsg->flags & SMSG_RECEIVER_CLEANS )
961 TRACE_(sendmsg)("Receiver cleans up!\n" );
962 HeapFree( SystemHeap, 0, smsg );
965 LeaveCriticalSection(&senderQ->cSection);
970 QUEUE_Unlock( senderQ );
972 QUEUE_Unlock( queue );
977 /***********************************************************************
980 static BOOL MSG_PeekMessage( LPMSG msg, HWND hwnd, DWORD first, DWORD last,
981 WORD flags, BOOL peek )
984 MESSAGEQUEUE *msgQueue;
990 DDE_TestDDE(hwnd); /* do we have dde handling in the window ?*/
991 DDE_GetRemoteMessage();
992 #endif /* CONFIG_IPC */
994 mask = QS_POSTMESSAGE | QS_SENDMESSAGE; /* Always selected */
997 if ((first <= WM_KEYLAST) && (last >= WM_KEYFIRST)) mask |= QS_KEY;
998 if ( ((first <= WM_MOUSELAST) && (last >= WM_MOUSEFIRST)) ||
999 ((first <= WM_NCMOUSELAST) && (last >= WM_NCMOUSEFIRST)) ) mask |= QS_MOUSE;
1000 if ((first <= WM_TIMER) && (last >= WM_TIMER)) mask |= QS_TIMER;
1001 if ((first <= WM_SYSTIMER) && (last >= WM_SYSTIMER)) mask |= QS_TIMER;
1002 if ((first <= WM_PAINT) && (last >= WM_PAINT)) mask |= QS_PAINT;
1004 else mask |= QS_MOUSE | QS_KEY | QS_TIMER | QS_PAINT;
1006 if (IsTaskLocked16()) flags |= PM_NOYIELD;
1008 /* Never yield on Win32 threads */
1009 if (!THREAD_IsWin16(THREAD_Current())) flags |= PM_NOYIELD;
1011 iWndsLocks = WIN_SuspendWndsLock();
1017 hQueue = GetFastQueue16();
1018 msgQueue = (MESSAGEQUEUE *)QUEUE_Lock( hQueue );
1021 WIN_RestoreWndsLock(iWndsLocks);
1024 msgQueue->changeBits = 0;
1026 /* First handle a message put by SendMessage() */
1028 while (msgQueue->wakeBits & QS_SENDMESSAGE)
1029 QUEUE_ReceiveMessage( msgQueue );
1031 /* Now handle a WM_QUIT message */
1033 if (msgQueue->wPostQMsg &&
1034 (!first || WM_QUIT >= first) &&
1035 (!last || WM_QUIT <= last) )
1038 msg->message = WM_QUIT;
1039 msg->wParam = msgQueue->wExitCode;
1041 if (flags & PM_REMOVE) msgQueue->wPostQMsg = 0;
1045 /* Now find a normal message */
1047 if (((msgQueue->wakeBits & mask) & QS_POSTMESSAGE) &&
1048 ((qmsg = QUEUE_FindMsg( msgQueue, hwnd, first, last )) != 0))
1052 msgQueue->GetMessageTimeVal = msg->time;
1053 CONV_POINT32TO16(&msg->pt, &pt16);
1054 msgQueue->GetMessagePosVal = *(DWORD *)&pt16;
1055 msgQueue->GetMessageExtraInfoVal = qmsg->extraInfo;
1057 if (flags & PM_REMOVE) QUEUE_RemoveMsg( msgQueue, qmsg );
1061 msgQueue->changeBits |= MSG_JournalPlayBackMsg();
1063 /* Now find a hardware event */
1065 if (((msgQueue->wakeBits & mask) & (QS_MOUSE | QS_KEY)) &&
1066 MSG_PeekHardwareMsg( msg, hwnd, first, last, flags & PM_REMOVE ))
1069 msgQueue->GetMessageTimeVal = msg->time;
1070 CONV_POINT32TO16(&msg->pt, &pt16);
1071 msgQueue->GetMessagePosVal = *(DWORD *)&pt16;
1072 msgQueue->GetMessageExtraInfoVal = 0; /* Always 0 for now */
1076 /* Check again for SendMessage */
1078 while (msgQueue->wakeBits & QS_SENDMESSAGE)
1079 QUEUE_ReceiveMessage( msgQueue );
1081 /* Now find a WM_PAINT message */
1083 if ((msgQueue->wakeBits & mask) & QS_PAINT)
1086 msg->hwnd = WIN_FindWinToRepaint( hwnd , hQueue );
1087 msg->message = WM_PAINT;
1091 if ((wndPtr = WIN_FindWndPtr(msg->hwnd)))
1093 if( wndPtr->dwStyle & WS_MINIMIZE &&
1094 (HICON) GetClassLongA(wndPtr->hwndSelf, GCL_HICON) )
1096 msg->message = WM_PAINTICON;
1100 if( !hwnd || msg->hwnd == hwnd || IsChild16(hwnd,msg->hwnd) )
1102 if( wndPtr->flags & WIN_INTERNAL_PAINT && !wndPtr->hrgnUpdate)
1104 wndPtr->flags &= ~WIN_INTERNAL_PAINT;
1105 QUEUE_DecPaintCount( hQueue );
1107 WIN_ReleaseWndPtr(wndPtr);
1110 WIN_ReleaseWndPtr(wndPtr);
1114 /* Check for timer messages, but yield first */
1116 if (!(flags & PM_NOYIELD))
1119 while (msgQueue->wakeBits & QS_SENDMESSAGE)
1120 QUEUE_ReceiveMessage( msgQueue );
1122 if ((msgQueue->wakeBits & mask) & QS_TIMER)
1124 if (TIMER_GetTimerMsg(msg, hwnd, hQueue, flags & PM_REMOVE)) break;
1129 if (!(flags & PM_NOYIELD)) UserYield16();
1131 QUEUE_Unlock( msgQueue );
1132 WIN_RestoreWndsLock(iWndsLocks);
1135 msgQueue->wakeMask = mask;
1136 QUEUE_WaitBits( mask, INFINITE );
1137 QUEUE_Unlock( msgQueue );
1140 WIN_RestoreWndsLock(iWndsLocks);
1142 /* instead of unlocking queue for every break condition, all break
1143 condition will fall here */
1144 QUEUE_Unlock( msgQueue );
1146 /* We got a message */
1147 if (flags & PM_REMOVE)
1149 WORD message = msg->message;
1151 if (message == WM_KEYDOWN || message == WM_SYSKEYDOWN)
1153 BYTE *p = &QueueKeyStateTable[msg->wParam & 0xff];
1159 else if (message == WM_KEYUP || message == WM_SYSKEYUP)
1160 QueueKeyStateTable[msg->wParam & 0xff] &= ~0x80;
1167 return (msg->message != WM_QUIT);
1170 /***********************************************************************
1171 * MSG_InternalGetMessage
1173 * GetMessage() function for internal use. Behave like GetMessage(),
1174 * but also call message filters and optionally send WM_ENTERIDLE messages.
1175 * 'hwnd' must be the handle of the dialog or menu window.
1176 * 'code' is the message filter value (MSGF_??? codes).
1178 BOOL MSG_InternalGetMessage( MSG *msg, HWND hwnd, HWND hwndOwner,
1179 WPARAM code, WORD flags, BOOL sendIdle )
1185 if (!MSG_PeekMessage( msg, 0, 0, 0, flags, TRUE ))
1187 /* No message present -> send ENTERIDLE and wait */
1188 if (IsWindow(hwndOwner))
1189 SendMessageA( hwndOwner, WM_ENTERIDLE,
1190 code, (LPARAM)hwnd );
1191 MSG_PeekMessage( msg, 0, 0, 0, flags, FALSE );
1194 else /* Always wait for a message */
1195 MSG_PeekMessage( msg, 0, 0, 0, flags, FALSE );
1197 /* Call message filters */
1199 if (HOOK_IsHooked( WH_SYSMSGFILTER ) || HOOK_IsHooked( WH_MSGFILTER ))
1201 MSG *pmsg = HeapAlloc( SystemHeap, 0, sizeof(MSG) );
1206 ret = (HOOK_CallHooksA( WH_SYSMSGFILTER, code, 0,
1208 HOOK_CallHooksA( WH_MSGFILTER, code, 0,
1211 HeapFree( SystemHeap, 0, pmsg );
1214 /* Message filtered -> remove it from the queue */
1215 /* if it's still there. */
1216 if (!(flags & PM_REMOVE))
1217 MSG_PeekMessage( msg, 0, 0, 0, PM_REMOVE, TRUE );
1223 return (msg->message != WM_QUIT);
1228 /***********************************************************************
1229 * PeekMessage16 (USER.109)
1231 BOOL16 WINAPI PeekMessage16( LPMSG16 lpmsg, HWND16 hwnd, UINT16 first,
1232 UINT16 last, UINT16 flags )
1236 ret = PeekMessageA(&msg32, hwnd, first, last, flags);
1237 STRUCT32_MSG32to16(&msg32, lpmsg);
1241 /***********************************************************************
1242 * WIN16_PeekMessage32 (USER.819)
1244 BOOL16 WINAPI PeekMessage32_16( LPMSG16_32 lpmsg16_32, HWND16 hwnd,
1245 UINT16 first, UINT16 last, UINT16 flags, BOOL16 wHaveParamHigh )
1247 if (wHaveParamHigh == FALSE)
1249 lpmsg16_32->wParamHigh = 0;
1250 return PeekMessage16(&(lpmsg16_32->msg), hwnd, first, last, flags);
1257 ret = (BOOL16)PeekMessageA(&msg32, (HWND)hwnd,
1258 (UINT)first, (UINT)last, (UINT)flags);
1259 lpmsg16_32->msg.hwnd = msg32.hwnd;
1260 lpmsg16_32->msg.message = msg32.message;
1261 lpmsg16_32->msg.wParam = LOWORD(msg32.wParam);
1262 lpmsg16_32->msg.lParam = msg32.lParam;
1263 lpmsg16_32->msg.time = msg32.time;
1264 lpmsg16_32->msg.pt.x = (INT16)msg32.pt.x;
1265 lpmsg16_32->msg.pt.y = (INT16)msg32.pt.y;
1266 lpmsg16_32->wParamHigh = HIWORD(msg32.wParam);
1272 /***********************************************************************
1275 BOOL WINAPI PeekMessageA( LPMSG lpmsg, HWND hwnd,
1276 UINT min,UINT max,UINT wRemoveMsg)
1278 return MSG_PeekMessage( lpmsg, hwnd, min, max, wRemoveMsg, TRUE );
1281 /***********************************************************************
1282 * PeekMessageW Check queue for messages
1284 * Checks for a message in the thread's queue, filtered as for
1285 * GetMessage(). Returns immediately whether a message is available
1288 * Whether a retrieved message is removed from the queue is set by the
1289 * _wRemoveMsg_ flags, which should be one of the following values:
1291 * PM_NOREMOVE Do not remove the message from the queue.
1293 * PM_REMOVE Remove the message from the queue.
1295 * In addition, PM_NOYIELD may be combined into _wRemoveMsg_ to
1296 * request that the system not yield control during PeekMessage();
1297 * however applications may not rely on scheduling behavior.
1301 * Nonzero if a message is available and is retrieved, zero otherwise.
1308 BOOL WINAPI PeekMessageW(
1309 LPMSG lpmsg, /* buffer to receive message */
1310 HWND hwnd, /* restrict to messages for hwnd */
1311 UINT min, /* minimum message to receive */
1312 UINT max, /* maximum message to receive */
1313 UINT wRemoveMsg /* removal flags */
1316 BOOL bRet = PeekMessageA(lpmsg,hwnd,min,max,wRemoveMsg);
1318 FIXME_(sendmsg)("(%s) unicode<->ascii\n", SPY_GetMsgName(lpmsg->message));
1322 /***********************************************************************
1323 * GetMessage16 (USER.108)
1325 BOOL16 WINAPI GetMessage16( SEGPTR msg, HWND16 hwnd, UINT16 first, UINT16 last)
1328 MSG16 *lpmsg = (MSG16 *)PTR_SEG_TO_LIN(msg);
1331 ret = GetMessageA( &msg32, hwnd, first, last );
1333 STRUCT32_MSG32to16( &msg32, lpmsg );
1335 TRACE_(msg)("message %04x, hwnd %04x, filter(%04x - %04x)\n", lpmsg->message,
1336 hwnd, first, last );
1341 /***********************************************************************
1342 * WIN16_GetMessage32 (USER.820)
1344 BOOL16 WINAPI GetMessage32_16( SEGPTR msg16_32, HWND16 hWnd, UINT16 first,
1345 UINT16 last, BOOL16 wHaveParamHigh )
1347 MSG32_16 *lpmsg16_32 = (MSG32_16 *)PTR_SEG_TO_LIN(msg16_32);
1349 if (wHaveParamHigh == FALSE) /* normal GetMessage16 call */
1352 lpmsg16_32->wParamHigh = 0; /* you never know... */
1353 /* WARNING: msg16_32->msg has to be the first variable in the struct */
1354 return GetMessage16(msg16_32, hWnd, first, last);
1361 ret = (BOOL16)GetMessageA(&msg32, hWnd, first, last);
1362 lpmsg16_32->msg.hwnd = msg32.hwnd;
1363 lpmsg16_32->msg.message = msg32.message;
1364 lpmsg16_32->msg.wParam = LOWORD(msg32.wParam);
1365 lpmsg16_32->msg.lParam = msg32.lParam;
1366 lpmsg16_32->msg.time = msg32.time;
1367 lpmsg16_32->msg.pt.x = (INT16)msg32.pt.x;
1368 lpmsg16_32->msg.pt.y = (INT16)msg32.pt.y;
1369 lpmsg16_32->wParamHigh = HIWORD(msg32.wParam);
1374 /***********************************************************************
1375 * GetMessage32A (USER32.270)
1377 BOOL WINAPI GetMessageA(MSG* lpmsg,HWND hwnd,UINT min,UINT max)
1379 MSG_PeekMessage( lpmsg, hwnd, min, max, PM_REMOVE, FALSE );
1381 TRACE_(msg)("message %04x, hwnd %04x, filter(%04x - %04x)\n", lpmsg->message,
1384 HOOK_CallHooksA( WH_GETMESSAGE, HC_ACTION, 0, (LPARAM)lpmsg );
1386 return (lpmsg->message != WM_QUIT);
1389 /***********************************************************************
1390 * GetMessage32W (USER32.274) Retrieve next message
1392 * GetMessage retrieves the next event from the calling thread's
1393 * queue and deposits it in *lpmsg.
1395 * If _hwnd_ is not NULL, only messages for window _hwnd_ and its
1396 * children as specified by IsChild() are retrieved. If _hwnd_ is NULL
1397 * all application messages are retrieved.
1399 * _min_ and _max_ specify the range of messages of interest. If
1400 * min==max==0, no filtering is performed. Useful examples are
1401 * WM_KEYFIRST and WM_KEYLAST to retrieve keyboard input, and
1402 * WM_MOUSEFIRST and WM_MOUSELAST to retrieve mouse input.
1404 * WM_PAINT messages are not removed from the queue; they remain until
1405 * processed. Other messages are removed from the queue.
1409 * -1 on error, 0 if message is WM_QUIT, nonzero otherwise.
1416 BOOL WINAPI GetMessageW(
1417 MSG* lpmsg, /* buffer to receive message */
1418 HWND hwnd, /* restrict to messages for hwnd */
1419 UINT min, /* minimum message to receive */
1420 UINT max /* maximum message to receive */
1423 BOOL bRet = GetMessageA(lpmsg, hwnd, min, max);
1425 FIXME_(sendmsg)("(%s) unicode<->ascii\n", SPY_GetMsgName(lpmsg->message));
1431 /***********************************************************************
1432 * PostMessage16 (USER.110)
1434 BOOL16 WINAPI PostMessage16( HWND16 hwnd, UINT16 message, WPARAM16 wParam,
1437 return (BOOL16) PostMessageA( hwnd, message, wParam, lParam );
1441 /***********************************************************************
1442 * PostMessage32A (USER32.419)
1444 BOOL WINAPI PostMessageA( HWND hwnd, UINT message, WPARAM wParam,
1452 msg.message = message;
1453 msg.wParam = wParam;
1454 msg.lParam = lParam;
1455 msg.time = GetTickCount();
1460 if (DDE_PostMessage(&msg))
1462 #endif /* CONFIG_IPC */
1464 if (hwnd == HWND_BROADCAST)
1466 WND *pDesktop = WIN_GetDesktop();
1467 TRACE_(msg)("HWND_BROADCAST !\n");
1469 for (wndPtr=WIN_LockWndPtr(pDesktop->child); wndPtr; WIN_UpdateWndPtr(&wndPtr,wndPtr->next))
1471 if (wndPtr->dwStyle & WS_POPUP || wndPtr->dwStyle & WS_CAPTION)
1473 TRACE_(msg)("BROADCAST Message to hWnd=%04x m=%04X w=%04X l=%08lX !\n",
1474 wndPtr->hwndSelf, message, wParam, lParam);
1475 PostMessageA( wndPtr->hwndSelf, message, wParam, lParam );
1478 WIN_ReleaseDesktop();
1479 TRACE_(msg)("End of HWND_BROADCAST !\n");
1483 wndPtr = WIN_FindWndPtr( hwnd );
1484 if (!wndPtr || !wndPtr->hmemTaskQ)
1490 retvalue = QUEUE_AddMsg( wndPtr->hmemTaskQ, &msg, 0 );
1492 WIN_ReleaseWndPtr(wndPtr);
1497 /***********************************************************************
1498 * PostMessage32W (USER32.420)
1500 BOOL WINAPI PostMessageW( HWND hwnd, UINT message, WPARAM wParam,
1503 FIXME_(sendmsg)("(%s) unicode<->ascii\n", SPY_GetMsgName(message));
1504 return PostMessageA( hwnd, message, wParam, lParam );
1508 /***********************************************************************
1509 * PostAppMessage16 (USER.116)
1511 BOOL16 WINAPI PostAppMessage16( HTASK16 hTask, UINT16 message, WPARAM16 wParam,
1516 if (GetTaskQueue16(hTask) == 0) return FALSE;
1518 msg.message = message;
1519 msg.wParam = wParam;
1520 msg.lParam = lParam;
1521 msg.time = GetTickCount();
1525 return QUEUE_AddMsg( GetTaskQueue16(hTask), &msg, 0 );
1528 /************************************************************************
1529 * MSG_CallWndProcHook32
1531 static void MSG_CallWndProcHook( LPMSG pmsg, BOOL bUnicode )
1535 cwp.lParam = pmsg->lParam;
1536 cwp.wParam = pmsg->wParam;
1537 cwp.message = pmsg->message;
1538 cwp.hwnd = pmsg->hwnd;
1540 if (bUnicode) HOOK_CallHooksW(WH_CALLWNDPROC, HC_ACTION, 1, (LPARAM)&cwp);
1541 else HOOK_CallHooksA( WH_CALLWNDPROC, HC_ACTION, 1, (LPARAM)&cwp );
1543 pmsg->lParam = cwp.lParam;
1544 pmsg->wParam = cwp.wParam;
1545 pmsg->message = cwp.message;
1546 pmsg->hwnd = cwp.hwnd;
1550 /***********************************************************************
1553 * return values: 0 if timeout occurs
1556 LRESULT MSG_SendMessage( HWND hwnd, UINT msg, WPARAM wParam,
1557 LPARAM lParam, DWORD timeout, WORD flags,
1561 WND **list, **ppWnd;
1566 if (hwnd == HWND_BROADCAST|| hwnd == HWND_TOPMOST)
1570 if (!(list = WIN_BuildWinArray( WIN_GetDesktop(), 0, NULL )))
1572 WIN_ReleaseDesktop();
1575 WIN_ReleaseDesktop();
1577 TRACE_(msg)("HWND_BROADCAST !\n");
1578 for (ppWnd = list; *ppWnd; ppWnd++)
1580 WIN_UpdateWndPtr(&wndPtr,*ppWnd);
1581 if (!IsWindow(wndPtr->hwndSelf)) continue;
1582 if (wndPtr->dwStyle & WS_POPUP || wndPtr->dwStyle & WS_CAPTION)
1584 TRACE_(msg)("BROADCAST Message to hWnd=%04x m=%04X w=%04lX l=%08lX !\n",
1585 wndPtr->hwndSelf, msg, (DWORD)wParam, lParam);
1586 MSG_SendMessage( wndPtr->hwndSelf, msg, wParam, lParam,
1587 timeout, flags, pRes);
1590 WIN_ReleaseWndPtr(wndPtr);
1591 WIN_ReleaseWinArray(list);
1592 TRACE_(msg)("End of HWND_BROADCAST !\n");
1596 if (HOOK_IsHooked( WH_CALLWNDPROC ))
1598 if (flags & SMSG_UNICODE)
1599 MSG_CallWndProcHook( (LPMSG)&hwnd, TRUE);
1600 else if (flags & SMSG_WIN32)
1601 MSG_CallWndProcHook( (LPMSG)&hwnd, FALSE);
1606 if ((pmsg = SEGPTR_NEW(CWPSTRUCT16)))
1608 pmsg->hwnd = hwnd & 0xffff;
1609 pmsg->message= msg & 0xffff;
1610 pmsg->wParam = wParam & 0xffff;
1611 pmsg->lParam = lParam;
1612 HOOK_CallHooks16( WH_CALLWNDPROC, HC_ACTION, 1,
1613 (LPARAM)SEGPTR_GET(pmsg) );
1615 msg = pmsg->message;
1616 wParam = pmsg->wParam;
1617 lParam = pmsg->lParam;
1618 SEGPTR_FREE( pmsg );
1623 if (!(wndPtr = WIN_FindWndPtr( hwnd )))
1625 WARN_(msg)("invalid hwnd %04x\n", hwnd );
1628 if (QUEUE_IsExitingQueue(wndPtr->hmemTaskQ))
1630 ret = 0; /* Don't send anything if the task is dying */
1633 if (flags & SMSG_WIN32)
1634 SPY_EnterMessage( SPY_SENDMESSAGE, hwnd, msg, wParam, lParam );
1636 SPY_EnterMessage( SPY_SENDMESSAGE16, hwnd, msg, wParam, lParam );
1638 if (wndPtr->hmemTaskQ != GetFastQueue16())
1639 ret = MSG_SendMessageInterThread( wndPtr->hmemTaskQ, hwnd, msg,
1640 wParam, lParam, timeout, flags, pRes );
1643 /* Call the right CallWindowProc flavor */
1644 if (flags & SMSG_UNICODE)
1645 *pRes = CallWindowProcW( (WNDPROC)wndPtr->winproc,
1646 hwnd, msg, wParam, lParam );
1647 else if (flags & SMSG_WIN32)
1648 *pRes = CallWindowProcA( (WNDPROC)wndPtr->winproc,
1649 hwnd, msg, wParam, lParam );
1651 *pRes = CallWindowProc16( (WNDPROC16)wndPtr->winproc,
1652 (HWND16) hwnd, (UINT16) msg,
1653 (WPARAM16) wParam, lParam );
1656 if (flags & SMSG_WIN32)
1657 SPY_ExitMessage( SPY_RESULT_OK, hwnd, msg, ret );
1659 SPY_ExitMessage( SPY_RESULT_OK16, hwnd, msg, ret );
1661 WIN_ReleaseWndPtr(wndPtr);
1666 /***********************************************************************
1667 * SendMessage16 (USER.111)
1669 LRESULT WINAPI SendMessage16( HWND16 hwnd, UINT16 msg, WPARAM16 wParam,
1674 MSG16 DDE_msg = { hwnd, msg, wParam, lParam };
1675 if (DDE_SendMessage(&DDE_msg)) return TRUE;
1676 #endif /* CONFIG_IPC */
1678 MSG_SendMessage(hwnd, msg, wParam, lParam, INFINITE, 0, &res);
1685 /**********************************************************************
1686 * PostThreadMessage32A (USER32.422)
1690 * Thread-local message queues are not supported.
1693 BOOL WINAPI PostThreadMessageA(DWORD idThread , UINT message,
1694 WPARAM wParam, LPARAM lParam )
1699 if ((hQueue = GetThreadQueue16(idThread)) == 0)
1703 msg.message = message;
1704 msg.wParam = wParam;
1705 msg.lParam = lParam;
1706 msg.time = GetTickCount();
1710 return QUEUE_AddMsg( hQueue, &msg, 0 );
1713 /**********************************************************************
1714 * PostThreadMessage32W (USER32.423)
1718 * Thread-local message queues are not supported.
1721 BOOL WINAPI PostThreadMessageW(DWORD idThread , UINT message,
1722 WPARAM wParam, LPARAM lParam )
1724 FIXME_(sendmsg)("(%s) unicode<->ascii\n",SPY_GetMsgName(message));
1725 return PostThreadMessageA(idThread, message, wParam, lParam);
1728 /***********************************************************************
1729 * SendMessage32A (USER32.454)
1731 LRESULT WINAPI SendMessageA( HWND hwnd, UINT msg, WPARAM wParam,
1736 MSG_SendMessage(hwnd, msg, wParam, lParam, INFINITE,
1743 /***********************************************************************
1744 * SendMessage32W (USER32.459) Send Window Message
1746 * Sends a message to the window procedure of the specified window.
1747 * SendMessage() will not return until the called window procedure
1748 * either returns or calls ReplyMessage().
1750 * Use PostMessage() to send message and return immediately. A window
1751 * procedure may use InSendMessage() to detect
1752 * SendMessage()-originated messages.
1754 * Applications which communicate via HWND_BROADCAST may use
1755 * RegisterWindowMessage() to obtain a unique message to avoid conflicts
1756 * with other applications.
1762 LRESULT WINAPI SendMessageW(
1763 HWND hwnd, /* Window to send message to. If HWND_BROADCAST,
1764 the message will be sent to all top-level windows. */
1766 UINT msg, /* message */
1767 WPARAM wParam, /* message parameter */
1768 LPARAM lParam /* additional message parameter */
1772 MSG_SendMessage(hwnd, msg, wParam, lParam, INFINITE,
1773 SMSG_WIN32 | SMSG_UNICODE, &res);
1779 /***********************************************************************
1780 * SendMessageTimeout16 (not a WINAPI)
1782 LRESULT WINAPI SendMessageTimeout16( HWND16 hwnd, UINT16 msg, WPARAM16 wParam,
1783 LPARAM lParam, UINT16 flags,
1784 UINT16 timeout, LPWORD resultp)
1789 /* FIXME: need support for SMTO_BLOCK */
1791 ret = MSG_SendMessage(hwnd, msg, wParam, lParam, timeout, 0, &msgRet);
1792 *resultp = (WORD) msgRet;
1797 /***********************************************************************
1798 * SendMessageTimeoutA (USER32.457)
1800 LRESULT WINAPI SendMessageTimeoutA( HWND hwnd, UINT msg, WPARAM wParam,
1801 LPARAM lParam, UINT flags,
1802 UINT timeout, LPDWORD resultp)
1807 /* FIXME: need support for SMTO_BLOCK */
1809 ret = MSG_SendMessage(hwnd, msg, wParam, lParam, timeout, SMSG_WIN32,
1812 *resultp = (DWORD) msgRet;
1817 /***********************************************************************
1818 * SendMessageTimeoutW (USER32.458)
1820 LRESULT WINAPI SendMessageTimeoutW( HWND hwnd, UINT msg, WPARAM wParam,
1821 LPARAM lParam, UINT flags,
1822 UINT timeout, LPDWORD resultp)
1827 /* FIXME: need support for SMTO_BLOCK */
1829 ret = MSG_SendMessage(hwnd, msg, wParam, lParam, timeout,
1830 SMSG_WIN32 | SMSG_UNICODE, &msgRet);
1832 *resultp = (DWORD) msgRet;
1837 /***********************************************************************
1838 * WaitMessage (USER.112) (USER32.578) Suspend thread pending messages
1840 * WaitMessage() suspends a thread until events appear in the thread's
1845 * Is supposed to return BOOL under Win32.
1847 * Thread-local message queues are not supported.
1854 void WINAPI WaitMessage( void )
1856 QUEUE_WaitBits( QS_ALLINPUT, INFINITE );
1859 /***********************************************************************
1860 * MsgWaitForMultipleObjects (USER32.400)
1862 DWORD WINAPI MsgWaitForMultipleObjects( DWORD nCount, HANDLE *pHandles,
1863 BOOL fWaitAll, DWORD dwMilliseconds,
1867 HANDLE handles[MAXIMUM_WAIT_OBJECTS];
1870 HQUEUE16 hQueue = GetFastQueue16();
1871 MESSAGEQUEUE *msgQueue = (MESSAGEQUEUE *)QUEUE_Lock( hQueue );
1872 if (!msgQueue) return WAIT_FAILED;
1874 if (nCount > MAXIMUM_WAIT_OBJECTS-1)
1876 SetLastError( ERROR_INVALID_PARAMETER );
1877 QUEUE_Unlock( msgQueue );
1881 msgQueue->changeBits = 0;
1882 msgQueue->wakeMask = dwWakeMask;
1884 if (THREAD_IsWin16(THREAD_Current()))
1887 * This is a temporary solution to a big problem.
1888 * You see, the main thread of all Win32 programs is created as a 16 bit
1889 * task. This means that if you want on an event using Win32 synchronization
1890 * methods, the 16 bit scheduler is stopped and things might just stop happening.
1891 * This implements a semi-busy loop that checks the handles to wait on and
1892 * also the message queue. When either one is ready, the wait function returns.
1894 * This will all go away when the real Win32 threads are implemented for all
1895 * the threads of an applications. Including the main thread.
1897 DWORD curTime = GetCurrentTime();
1902 * Check the handles in the list.
1904 ret = WaitForMultipleObjects(nCount, pHandles, fWaitAll, 5L);
1907 * If the handles have been triggered, return.
1909 if (ret != WAIT_TIMEOUT)
1913 * Then, let the 16 bit scheduler do it's thing.
1918 * If a message matching the wait mask has arrived, return.
1920 if (msgQueue->changeBits & dwWakeMask)
1927 * And continue doing this until we hit the timeout.
1929 } while ((dwMilliseconds == INFINITE) || (GetCurrentTime()-curTime < dwMilliseconds) );
1933 /* Add the thread event to the handle list */
1934 for (i = 0; i < nCount; i++)
1935 handles[i] = pHandles[i];
1936 handles[nCount] = msgQueue->hEvent;
1938 ret = WaitForMultipleObjects( nCount+1, handles, fWaitAll, dwMilliseconds );
1941 QUEUE_Unlock( msgQueue );
1955 static const struct accent_char accent_chars[] =
1957 /* A good idea should be to read /usr/X11/lib/X11/locale/iso8859-x/Compose */
1958 {'`', 'A', '\300'}, {'`', 'a', '\340'},
1959 {'\'', 'A', '\301'}, {'\'', 'a', '\341'},
1960 {'^', 'A', '\302'}, {'^', 'a', '\342'},
1961 {'~', 'A', '\303'}, {'~', 'a', '\343'},
1962 {'"', 'A', '\304'}, {'"', 'a', '\344'},
1963 {'O', 'A', '\305'}, {'o', 'a', '\345'},
1964 {'0', 'A', '\305'}, {'0', 'a', '\345'},
1965 {'A', 'A', '\305'}, {'a', 'a', '\345'},
1966 {'A', 'E', '\306'}, {'a', 'e', '\346'},
1967 {',', 'C', '\307'}, {',', 'c', '\347'},
1968 {'`', 'E', '\310'}, {'`', 'e', '\350'},
1969 {'\'', 'E', '\311'}, {'\'', 'e', '\351'},
1970 {'^', 'E', '\312'}, {'^', 'e', '\352'},
1971 {'"', 'E', '\313'}, {'"', 'e', '\353'},
1972 {'`', 'I', '\314'}, {'`', 'i', '\354'},
1973 {'\'', 'I', '\315'}, {'\'', 'i', '\355'},
1974 {'^', 'I', '\316'}, {'^', 'i', '\356'},
1975 {'"', 'I', '\317'}, {'"', 'i', '\357'},
1976 {'-', 'D', '\320'}, {'-', 'd', '\360'},
1977 {'~', 'N', '\321'}, {'~', 'n', '\361'},
1978 {'`', 'O', '\322'}, {'`', 'o', '\362'},
1979 {'\'', 'O', '\323'}, {'\'', 'o', '\363'},
1980 {'^', 'O', '\324'}, {'^', 'o', '\364'},
1981 {'~', 'O', '\325'}, {'~', 'o', '\365'},
1982 {'"', 'O', '\326'}, {'"', 'o', '\366'},
1983 {'/', 'O', '\330'}, {'/', 'o', '\370'},
1984 {'`', 'U', '\331'}, {'`', 'u', '\371'},
1985 {'\'', 'U', '\332'}, {'\'', 'u', '\372'},
1986 {'^', 'U', '\333'}, {'^', 'u', '\373'},
1987 {'"', 'U', '\334'}, {'"', 'u', '\374'},
1988 {'\'', 'Y', '\335'}, {'\'', 'y', '\375'},
1989 {'T', 'H', '\336'}, {'t', 'h', '\376'},
1990 {'s', 's', '\337'}, {'"', 'y', '\377'},
1991 {'s', 'z', '\337'}, {'i', 'j', '\377'},
1992 /* iso-8859-2 uses this */
1993 {'<', 'L', '\245'}, {'<', 'l', '\265'}, /* caron */
1994 {'<', 'S', '\251'}, {'<', 's', '\271'},
1995 {'<', 'T', '\253'}, {'<', 't', '\273'},
1996 {'<', 'Z', '\256'}, {'<', 'z', '\276'},
1997 {'<', 'C', '\310'}, {'<', 'c', '\350'},
1998 {'<', 'E', '\314'}, {'<', 'e', '\354'},
1999 {'<', 'D', '\317'}, {'<', 'd', '\357'},
2000 {'<', 'N', '\322'}, {'<', 'n', '\362'},
2001 {'<', 'R', '\330'}, {'<', 'r', '\370'},
2002 {';', 'A', '\241'}, {';', 'a', '\261'}, /* ogonek */
2003 {';', 'E', '\312'}, {';', 'e', '\332'},
2004 {'\'', 'Z', '\254'}, {'\'', 'z', '\274'}, /* acute */
2005 {'\'', 'R', '\300'}, {'\'', 'r', '\340'},
2006 {'\'', 'L', '\305'}, {'\'', 'l', '\345'},
2007 {'\'', 'C', '\306'}, {'\'', 'c', '\346'},
2008 {'\'', 'N', '\321'}, {'\'', 'n', '\361'},
2009 /* collision whith S, from iso-8859-9 !!! */
2010 {',', 'S', '\252'}, {',', 's', '\272'}, /* cedilla */
2011 {',', 'T', '\336'}, {',', 't', '\376'},
2012 {'.', 'Z', '\257'}, {'.', 'z', '\277'}, /* dot above */
2013 {'/', 'L', '\243'}, {'/', 'l', '\263'}, /* slash */
2014 {'/', 'D', '\320'}, {'/', 'd', '\360'},
2015 {'(', 'A', '\303'}, {'(', 'a', '\343'}, /* breve */
2016 {'\275', 'O', '\325'}, {'\275', 'o', '\365'}, /* double acute */
2017 {'\275', 'U', '\334'}, {'\275', 'u', '\374'},
2018 {'0', 'U', '\332'}, {'0', 'u', '\372'}, /* ring above */
2019 /* iso-8859-3 uses this */
2020 {'/', 'H', '\241'}, {'/', 'h', '\261'}, /* slash */
2021 {'>', 'H', '\246'}, {'>', 'h', '\266'}, /* circumflex */
2022 {'>', 'J', '\254'}, {'>', 'j', '\274'},
2023 {'>', 'C', '\306'}, {'>', 'c', '\346'},
2024 {'>', 'G', '\330'}, {'>', 'g', '\370'},
2025 {'>', 'S', '\336'}, {'>', 's', '\376'},
2026 /* collision whith G( from iso-8859-9 !!! */
2027 {'(', 'G', '\253'}, {'(', 'g', '\273'}, /* breve */
2028 {'(', 'U', '\335'}, {'(', 'u', '\375'},
2029 /* collision whith I. from iso-8859-3 !!! */
2030 {'.', 'I', '\251'}, {'.', 'i', '\271'}, /* dot above */
2031 {'.', 'C', '\305'}, {'.', 'c', '\345'},
2032 {'.', 'G', '\325'}, {'.', 'g', '\365'},
2033 /* iso-8859-4 uses this */
2034 {',', 'R', '\243'}, {',', 'r', '\263'}, /* cedilla */
2035 {',', 'L', '\246'}, {',', 'l', '\266'},
2036 {',', 'G', '\253'}, {',', 'g', '\273'},
2037 {',', 'N', '\321'}, {',', 'n', '\361'},
2038 {',', 'K', '\323'}, {',', 'k', '\363'},
2039 {'~', 'I', '\245'}, {'~', 'i', '\265'}, /* tilde */
2040 {'-', 'E', '\252'}, {'-', 'e', '\272'}, /* macron */
2041 {'-', 'A', '\300'}, {'-', 'a', '\340'},
2042 {'-', 'I', '\317'}, {'-', 'i', '\357'},
2043 {'-', 'O', '\322'}, {'-', 'o', '\362'},
2044 {'-', 'U', '\336'}, {'-', 'u', '\376'},
2045 {'/', 'T', '\254'}, {'/', 't', '\274'}, /* slash */
2046 {'.', 'E', '\314'}, {'.', 'e', '\344'}, /* dot above */
2047 {';', 'I', '\307'}, {';', 'i', '\347'}, /* ogonek */
2048 {';', 'U', '\331'}, {';', 'u', '\371'},
2049 /* iso-8859-9 uses this */
2050 /* iso-8859-9 has really bad choosen G( S, and I. as they collide
2051 * whith the same letters on other iso-8859-x (that is they are on
2052 * different places :-( ), if you use turkish uncomment these and
2053 * comment out the lines in iso-8859-2 and iso-8859-3 sections
2054 * FIXME: should be dynamic according to chosen language
2055 * if/when Wine has turkish support.
2057 /* collision whith G( from iso-8859-3 !!! */
2058 /* {'(', 'G', '\320'}, {'(', 'g', '\360'}, */ /* breve */
2059 /* collision whith S, from iso-8859-2 !!! */
2060 /* {',', 'S', '\336'}, {',', 's', '\376'}, */ /* cedilla */
2061 /* collision whith I. from iso-8859-3 !!! */
2062 /* {'.', 'I', '\335'}, {'.', 'i', '\375'}, */ /* dot above */
2066 /***********************************************************************
2067 * MSG_DoTranslateMessage
2069 * Implementation of TranslateMessage.
2071 * TranslateMessage translates virtual-key messages into character-messages,
2073 * WM_KEYDOWN/WM_KEYUP combinations produce a WM_CHAR or WM_DEADCHAR message.
2074 * ditto replacing WM_* with WM_SYS*
2075 * This produces WM_CHAR messages only for keys mapped to ASCII characters
2076 * by the keyboard driver.
2078 static BOOL MSG_DoTranslateMessage( UINT message, HWND hwnd,
2079 WPARAM wParam, LPARAM lParam )
2081 static int dead_char;
2084 if (message != WM_MOUSEMOVE && message != WM_TIMER)
2085 TRACE_(msg)("(%s, %04X, %08lX)\n",
2086 SPY_GetMsgName(message), wParam, lParam );
2087 if(message >= WM_KEYFIRST && message <= WM_KEYLAST)
2088 TRACE_(key)("(%s, %04X, %08lX)\n",
2089 SPY_GetMsgName(message), wParam, lParam );
2091 if ((message != WM_KEYDOWN) && (message != WM_SYSKEYDOWN)) return FALSE;
2093 TRACE_(key)("Translating key %04X, scancode %04X\n",
2094 wParam, HIWORD(lParam) );
2096 /* FIXME : should handle ToAscii yielding 2 */
2097 switch (ToAscii(wParam, HIWORD(lParam),
2098 QueueKeyStateTable,(LPWORD)wp, 0))
2101 message = (message == WM_KEYDOWN) ? WM_CHAR : WM_SYSCHAR;
2102 /* Should dead chars handling go in ToAscii ? */
2107 if (wp[0] == ' ') wp[0] = dead_char;
2108 if (dead_char == 0xa2) dead_char = '(';
2109 else if (dead_char == 0xa8) dead_char = '"';
2110 else if (dead_char == 0xb2) dead_char = ';';
2111 else if (dead_char == 0xb4) dead_char = '\'';
2112 else if (dead_char == 0xb7) dead_char = '<';
2113 else if (dead_char == 0xb8) dead_char = ',';
2114 else if (dead_char == 0xff) dead_char = '.';
2115 for (i = 0; i < sizeof(accent_chars)/sizeof(accent_chars[0]); i++)
2116 if ((accent_chars[i].ac_accent == dead_char) &&
2117 (accent_chars[i].ac_char == wp[0]))
2119 wp[0] = accent_chars[i].ac_result;
2124 TRACE_(key)("1 -> PostMessage(%s)\n", SPY_GetMsgName(message));
2125 PostMessage16( hwnd, message, wp[0], lParam );
2129 message = (message == WM_KEYDOWN) ? WM_DEADCHAR : WM_SYSDEADCHAR;
2131 TRACE_(key)("-1 -> PostMessage(%s)\n",
2132 SPY_GetMsgName(message));
2133 PostMessage16( hwnd, message, wp[0], lParam );
2140 /***********************************************************************
2141 * TranslateMessage16 (USER.113)
2143 BOOL16 WINAPI TranslateMessage16( const MSG16 *msg )
2145 return MSG_DoTranslateMessage( msg->message, msg->hwnd,
2146 msg->wParam, msg->lParam );
2150 /***********************************************************************
2151 * WIN16_TranslateMessage32 (USER.821)
2153 BOOL16 WINAPI TranslateMessage32_16( const MSG32_16 *msg, BOOL16 wHaveParamHigh )
2158 wParam = MAKELONG(msg->msg.wParam, msg->wParamHigh);
2160 wParam = (WPARAM)msg->msg.wParam;
2162 return MSG_DoTranslateMessage( msg->msg.message, msg->msg.hwnd,
2163 wParam, msg->msg.lParam );
2166 /***********************************************************************
2167 * TranslateMessage32 (USER32.556)
2169 BOOL WINAPI TranslateMessage( const MSG *msg )
2171 return MSG_DoTranslateMessage( msg->message, msg->hwnd,
2172 msg->wParam, msg->lParam );
2176 /***********************************************************************
2177 * DispatchMessage16 (USER.114)
2179 LONG WINAPI DispatchMessage16( const MSG16* msg )
2185 /* Process timer messages */
2186 if ((msg->message == WM_TIMER) || (msg->message == WM_SYSTIMER))
2190 return CallWindowProc16( (WNDPROC16)msg->lParam, msg->hwnd,
2191 msg->message, msg->wParam, GetTickCount() );
2195 if (!msg->hwnd) return 0;
2196 if (!(wndPtr = WIN_FindWndPtr( msg->hwnd ))) return 0;
2197 if (!wndPtr->winproc)
2202 painting = (msg->message == WM_PAINT);
2203 if (painting) wndPtr->flags |= WIN_NEEDS_BEGINPAINT;
2205 SPY_EnterMessage( SPY_DISPATCHMESSAGE16, msg->hwnd, msg->message,
2206 msg->wParam, msg->lParam );
2207 retval = CallWindowProc16( (WNDPROC16)wndPtr->winproc,
2208 msg->hwnd, msg->message,
2209 msg->wParam, msg->lParam );
2210 SPY_ExitMessage( SPY_RESULT_OK16, msg->hwnd, msg->message, retval );
2212 WIN_ReleaseWndPtr(wndPtr);
2213 wndPtr = WIN_FindWndPtr(msg->hwnd);
2214 if (painting && wndPtr &&
2215 (wndPtr->flags & WIN_NEEDS_BEGINPAINT) && wndPtr->hrgnUpdate)
2217 ERR_(msg)("BeginPaint not called on WM_PAINT for hwnd %04x!\n",
2219 wndPtr->flags &= ~WIN_NEEDS_BEGINPAINT;
2220 /* Validate the update region to avoid infinite WM_PAINT loop */
2221 ValidateRect( msg->hwnd, NULL );
2224 WIN_ReleaseWndPtr(wndPtr);
2229 /***********************************************************************
2230 * WIN16_DispatchMessage32 (USER.822)
2232 LONG WINAPI DispatchMessage32_16( const MSG32_16* lpmsg16_32, BOOL16 wHaveParamHigh )
2234 if (wHaveParamHigh == FALSE)
2235 return DispatchMessage16(&(lpmsg16_32->msg));
2240 msg.hwnd = lpmsg16_32->msg.hwnd;
2241 msg.message = lpmsg16_32->msg.message;
2242 msg.wParam = MAKELONG(lpmsg16_32->msg.wParam, lpmsg16_32->wParamHigh);
2243 msg.lParam = lpmsg16_32->msg.lParam;
2244 msg.time = lpmsg16_32->msg.time;
2245 msg.pt.x = (INT)lpmsg16_32->msg.pt.x;
2246 msg.pt.y = (INT)lpmsg16_32->msg.pt.y;
2247 return DispatchMessageA(&msg);
2251 /***********************************************************************
2252 * DispatchMessage32A (USER32.141)
2254 LONG WINAPI DispatchMessageA( const MSG* msg )
2260 /* Process timer messages */
2261 if ((msg->message == WM_TIMER) || (msg->message == WM_SYSTIMER))
2265 /* HOOK_CallHooks32A( WH_CALLWNDPROC, HC_ACTION, 0, FIXME ); */
2266 return CallWindowProcA( (WNDPROC)msg->lParam, msg->hwnd,
2267 msg->message, msg->wParam, GetTickCount() );
2271 if (!msg->hwnd) return 0;
2272 if (!(wndPtr = WIN_FindWndPtr( msg->hwnd ))) return 0;
2273 if (!wndPtr->winproc)
2278 painting = (msg->message == WM_PAINT);
2279 if (painting) wndPtr->flags |= WIN_NEEDS_BEGINPAINT;
2280 /* HOOK_CallHooks32A( WH_CALLWNDPROC, HC_ACTION, 0, FIXME ); */
2282 SPY_EnterMessage( SPY_DISPATCHMESSAGE, msg->hwnd, msg->message,
2283 msg->wParam, msg->lParam );
2284 retval = CallWindowProcA( (WNDPROC)wndPtr->winproc,
2285 msg->hwnd, msg->message,
2286 msg->wParam, msg->lParam );
2287 SPY_ExitMessage( SPY_RESULT_OK, msg->hwnd, msg->message, retval );
2289 WIN_ReleaseWndPtr(wndPtr);
2290 wndPtr = WIN_FindWndPtr(msg->hwnd);
2292 if (painting && wndPtr &&
2293 (wndPtr->flags & WIN_NEEDS_BEGINPAINT) && wndPtr->hrgnUpdate)
2295 ERR_(msg)("BeginPaint not called on WM_PAINT for hwnd %04x!\n",
2297 wndPtr->flags &= ~WIN_NEEDS_BEGINPAINT;
2298 /* Validate the update region to avoid infinite WM_PAINT loop */
2299 ValidateRect( msg->hwnd, NULL );
2302 WIN_ReleaseWndPtr(wndPtr);
2307 /***********************************************************************
2308 * DispatchMessage32W (USER32.142) Process Message
2310 * Process the message specified in the structure *_msg_.
2312 * If the lpMsg parameter points to a WM_TIMER message and the
2313 * parameter of the WM_TIMER message is not NULL, the lParam parameter
2314 * points to the function that is called instead of the window
2317 * The message must be valid.
2321 * DispatchMessage() returns the result of the window procedure invoked.
2328 LONG WINAPI DispatchMessageW( const MSG* msg )
2334 /* Process timer messages */
2335 if ((msg->message == WM_TIMER) || (msg->message == WM_SYSTIMER))
2339 /* HOOK_CallHooks32W( WH_CALLWNDPROC, HC_ACTION, 0, FIXME ); */
2340 return CallWindowProcW( (WNDPROC)msg->lParam, msg->hwnd,
2341 msg->message, msg->wParam, GetTickCount() );
2345 if (!msg->hwnd) return 0;
2346 if (!(wndPtr = WIN_FindWndPtr( msg->hwnd ))) return 0;
2347 if (!wndPtr->winproc)
2352 painting = (msg->message == WM_PAINT);
2353 if (painting) wndPtr->flags |= WIN_NEEDS_BEGINPAINT;
2354 /* HOOK_CallHooks32W( WH_CALLWNDPROC, HC_ACTION, 0, FIXME ); */
2356 SPY_EnterMessage( SPY_DISPATCHMESSAGE, msg->hwnd, msg->message,
2357 msg->wParam, msg->lParam );
2358 retval = CallWindowProcW( (WNDPROC)wndPtr->winproc,
2359 msg->hwnd, msg->message,
2360 msg->wParam, msg->lParam );
2361 SPY_ExitMessage( SPY_RESULT_OK, msg->hwnd, msg->message, retval );
2363 WIN_ReleaseWndPtr(wndPtr);
2364 wndPtr = WIN_FindWndPtr(msg->hwnd);
2366 if (painting && wndPtr &&
2367 (wndPtr->flags & WIN_NEEDS_BEGINPAINT) && wndPtr->hrgnUpdate)
2369 ERR_(msg)("BeginPaint not called on WM_PAINT for hwnd %04x!\n",
2371 wndPtr->flags &= ~WIN_NEEDS_BEGINPAINT;
2372 /* Validate the update region to avoid infinite WM_PAINT loop */
2373 ValidateRect( msg->hwnd, NULL );
2376 WIN_ReleaseWndPtr(wndPtr);
2381 /***********************************************************************
2382 * RegisterWindowMessage16 (USER.118)
2384 WORD WINAPI RegisterWindowMessage16( SEGPTR str )
2386 TRACE_(msg)("%08lx\n", (DWORD)str );
2387 return GlobalAddAtom16( str );
2391 /***********************************************************************
2392 * RegisterWindowMessage32A (USER32.437)
2394 WORD WINAPI RegisterWindowMessageA( LPCSTR str )
2396 TRACE_(msg)("%s\n", str );
2397 return GlobalAddAtomA( str );
2401 /***********************************************************************
2402 * RegisterWindowMessage32W (USER32.438)
2404 WORD WINAPI RegisterWindowMessageW( LPCWSTR str )
2406 TRACE_(msg)("%p\n", str );
2407 return GlobalAddAtomW( str );
2411 /***********************************************************************
2412 * GetTickCount (USER.13) (KERNEL32.299) System Time
2413 * Returns the number of milliseconds, modulo 2^32, since the start
2414 * of the current session.
2420 DWORD WINAPI GetTickCount(void)
2423 gettimeofday( &t, NULL );
2424 /* make extremely compatible: granularity is 25 msec */
2425 return ((t.tv_sec * 1000) + (t.tv_usec / 25000) * 25) - MSG_WineStartTicks;
2429 /***********************************************************************
2430 * GetCurrentTime16 (USER.15)
2432 * (effectively identical to GetTickCount)
2434 DWORD WINAPI GetCurrentTime16(void)
2436 return GetTickCount();
2440 /***********************************************************************
2441 * InSendMessage16 (USER.192)
2443 BOOL16 WINAPI InSendMessage16(void)
2445 return InSendMessage();
2449 /***********************************************************************
2450 * InSendMessage32 (USER32.320)
2452 BOOL WINAPI InSendMessage(void)
2454 MESSAGEQUEUE *queue;
2457 if (!(queue = (MESSAGEQUEUE *)QUEUE_Lock( GetFastQueue16() )))
2459 ret = (BOOL)queue->smWaiting;
2461 QUEUE_Unlock( queue );
2465 /***********************************************************************
2466 * BroadcastSystemMessage (USER32.12)
2468 LONG WINAPI BroadcastSystemMessage(
2469 DWORD dwFlags,LPDWORD recipients,UINT uMessage,WPARAM wParam,
2472 FIXME_(sendmsg)("(%08lx,%08lx,%08x,%08x,%08lx): stub!\n",
2473 dwFlags,*recipients,uMessage,wParam,lParam
2478 /***********************************************************************
2479 * SendNotifyMessageA (USER32.460)
2481 * The message sended with PostMessage has to be put in the queue
2482 * with a higher priority as the other "Posted" messages.
2483 * QUEUE_AddMsg has to be modifyed.
2485 BOOL WINAPI SendNotifyMessageA(HWND hwnd,UINT msg,WPARAM wParam,LPARAM lParam)
2487 FIXME_(msg)("(%04x,%08x,%08x,%08lx) not complete\n",
2488 hwnd, msg, wParam, lParam);
2490 if ( GetCurrentThreadId() == GetWindowThreadProcessId ( hwnd, NULL))
2491 { ret=SendMessageA ( hwnd, msg, wParam, lParam );
2494 { PostMessageA ( hwnd, msg, wParam, lParam );
2499 /***********************************************************************
2500 * SendNotifyMessageW (USER32.461)
2502 * The message sended with PostMessage has to be put in the queue
2503 * with a higher priority as the other "Posted" messages.
2504 * QUEUE_AddMsg has to be modifyed.
2506 BOOL WINAPI SendNotifyMessageW(HWND hwnd,UINT msg,WPARAM wParam,LPARAM lParam)
2508 FIXME_(msg)("(%04x,%08x,%08x,%08lx) not complete\n",
2509 hwnd, msg, wParam, lParam);
2511 if ( GetCurrentThreadId() == GetWindowThreadProcessId ( hwnd, NULL))
2512 { ret=SendMessageW ( hwnd, msg, wParam, lParam );
2515 { PostMessageW ( hwnd, msg, wParam, lParam );
2520 /***********************************************************************
2521 * SendMessageCallback32A
2522 * FIXME: It's like PostMessage. The callback gets called when the message
2523 * is processed. We have to modify the message processing for a exact
2526 BOOL WINAPI SendMessageCallbackA(
2527 HWND hWnd,UINT Msg,WPARAM wParam,LPARAM lParam,
2528 FARPROC lpResultCallBack,DWORD dwData)
2530 FIXME_(msg)("(0x%04x,0x%04x,0x%08x,0x%08lx,%p,0x%08lx),stub!\n",
2531 hWnd,Msg,wParam,lParam,lpResultCallBack,dwData);
2532 if ( hWnd == HWND_BROADCAST)
2533 { PostMessageA( hWnd, Msg, wParam, lParam);
2534 FIXME_(msg)("Broadcast: Callback will not be called!\n");
2537 (lpResultCallBack)( hWnd, Msg, dwData, SendMessageA ( hWnd, Msg, wParam, lParam ));
2540 /***********************************************************************
2541 * SendMessageCallback32W
2542 * FIXME: It's like PostMessage. The callback gets called when the message
2543 * is processed. We have to modify the message processing for a exact
2546 BOOL WINAPI SendMessageCallbackW(
2547 HWND hWnd,UINT Msg,WPARAM wParam,LPARAM lParam,
2548 FARPROC lpResultCallBack,DWORD dwData)
2550 FIXME_(msg)("(0x%04x,0x%04x,0x%08x,0x%08lx,%p,0x%08lx),stub!\n",
2551 hWnd,Msg,wParam,lParam,lpResultCallBack,dwData);
2552 if ( hWnd == HWND_BROADCAST)
2553 { PostMessageW( hWnd, Msg, wParam, lParam);
2554 FIXME_(msg)("Broadcast: Callback will not be called!\n");
2557 (lpResultCallBack)( hWnd, Msg, dwData, SendMessageA ( hWnd, Msg, wParam, lParam ));