Use poll() on the client-side during server waits to implement
[wine.git] / windows / message.c
blob7c36e5125b9ad1f608b1c9890047c856e298d543
1 /*
2 * Message queues related functions
4 * Copyright 1993, 1994 Alexandre Julliard
5 */
7 #include <stdlib.h>
8 #include <string.h>
9 #include <ctype.h>
10 #include <sys/time.h>
11 #include <sys/types.h>
13 #include "wine/winbase16.h"
14 #include "message.h"
15 #include "winerror.h"
16 #include "win.h"
17 #include "heap.h"
18 #include "hook.h"
19 #include "input.h"
20 #include "spy.h"
21 #include "winpos.h"
22 #include "dde.h"
23 #include "queue.h"
24 #include "winproc.h"
25 #include "thread.h"
26 #include "options.h"
27 #include "controls.h"
28 #include "struct32.h"
29 #include "debugtools.h"
31 DEFAULT_DEBUG_CHANNEL(msg);
32 DECLARE_DEBUG_CHANNEL(key);
33 DECLARE_DEBUG_CHANNEL(sendmsg);
35 #define WM_NCMOUSEFIRST WM_NCMOUSEMOVE
36 #define WM_NCMOUSELAST WM_NCMBUTTONDBLCLK
39 typedef enum { SYSQ_MSG_ABANDON, SYSQ_MSG_SKIP,
40 SYSQ_MSG_ACCEPT, SYSQ_MSG_CONTINUE } SYSQ_STATUS;
42 extern HQUEUE16 hCursorQueue; /* queue.c */
44 static UINT doubleClickSpeed = 452;
46 /***********************************************************************
47 * MSG_CheckFilter
49 static BOOL MSG_CheckFilter(DWORD uMsg, DWORD first, DWORD last)
51 if( first || last )
52 return (uMsg >= first && uMsg <= last);
53 return TRUE;
56 /***********************************************************************
57 * MSG_SendParentNotify
59 * Send a WM_PARENTNOTIFY to all ancestors of the given window, unless
60 * the window has the WS_EX_NOPARENTNOTIFY style.
62 static void MSG_SendParentNotify(WND* wndPtr, WORD event, WORD idChild, LPARAM lValue)
64 POINT pt;
66 /* pt has to be in the client coordinates of the parent window */
67 WND *tmpWnd = WIN_LockWndPtr(wndPtr);
69 pt.x = SLOWORD(lValue);
70 pt.y = SHIWORD(lValue);
71 MapWindowPoints( 0, tmpWnd->hwndSelf, &pt, 1 );
72 while (tmpWnd)
74 if (!(tmpWnd->dwStyle & WS_CHILD) || (tmpWnd->dwExStyle & WS_EX_NOPARENTNOTIFY))
76 WIN_ReleaseWndPtr(tmpWnd);
77 break;
79 pt.x += tmpWnd->rectClient.left;
80 pt.y += tmpWnd->rectClient.top;
81 WIN_UpdateWndPtr(&tmpWnd,tmpWnd->parent);
82 SendMessageA( tmpWnd->hwndSelf, WM_PARENTNOTIFY,
83 MAKEWPARAM( event, idChild ),
84 MAKELONG( pt.x, pt.y ) );
89 /***********************************************************************
90 * MSG_TranslateMouseMsg
92 * Translate a mouse hardware event into a real mouse message.
94 * Returns:
96 * SYSQ_MSG_ABANDON - abandon the peek message loop
97 * SYSQ_MSG_CONTINUE - leave the message in the queue and
98 * continue with the translation loop
99 * SYSQ_MSG_ACCEPT - proceed to process the translated message
101 static DWORD MSG_TranslateMouseMsg( HWND hTopWnd, DWORD first, DWORD last,
102 MSG *msg, BOOL remove, WND* pWndScope,
103 INT16 *pHitTest, POINT16 *pScreen_pt, BOOL *pmouseClick )
105 static DWORD dblclk_time_limit = 0;
106 static UINT16 clk_message = 0;
107 static HWND16 clk_hwnd = 0;
108 static POINT16 clk_pos = { 0, 0 };
110 WND *pWnd;
111 HWND hWnd;
112 INT16 ht, hittest;
113 UINT message = msg->message;
114 POINT16 screen_pt, pt;
115 HANDLE16 hQ = GetFastQueue16();
116 MESSAGEQUEUE *queue = QUEUE_Lock(hQ);
117 BOOL mouseClick = ((message == WM_LBUTTONDOWN) ||
118 (message == WM_RBUTTONDOWN) ||
119 (message == WM_MBUTTONDOWN))?1:0;
120 DWORD retvalue;
122 /* Find the window to dispatch this mouse message to */
124 CONV_POINT32TO16( &msg->pt, &pt );
126 hWnd = GetCapture();
128 /* If no capture HWND, find window which contains the mouse position.
129 * Also find the position of the cursor hot spot (hittest) */
130 if( !hWnd )
132 ht = hittest = WINPOS_WindowFromPoint( pWndScope, pt, &pWnd );
133 if( !pWnd ) pWnd = WIN_GetDesktop();
134 else WIN_LockWndPtr(pWnd);
135 hWnd = pWnd->hwndSelf;
137 else
139 ht = hittest = HTCLIENT;
140 pWnd = WIN_FindWndPtr(hWnd);
141 if (queue)
142 ht = PERQDATA_GetCaptureInfo( queue->pQData );
145 /* Save hittest for return */
146 *pHitTest = hittest;
148 /* stop if not the right queue */
150 if (pWnd->hmemTaskQ != hQ)
152 /* Not for the current task */
153 if (queue) QUEUE_ClearWakeBit( queue, QS_MOUSE );
154 /* Wake up the other task */
155 QUEUE_Unlock( queue );
156 queue = QUEUE_Lock( pWnd->hmemTaskQ );
157 if (queue) QUEUE_SetWakeBit( queue, QS_MOUSE );
159 QUEUE_Unlock( queue );
160 retvalue = SYSQ_MSG_ABANDON;
161 goto END;
164 /* check if hWnd is within hWndScope */
166 if( hTopWnd && hWnd != hTopWnd )
167 if( !IsChild(hTopWnd, hWnd) )
169 QUEUE_Unlock( queue );
170 retvalue = SYSQ_MSG_CONTINUE;
171 goto END;
174 /* Was it a mouse click message */
175 if( mouseClick )
177 /* translate double clicks -
178 * note that ...MOUSEMOVEs can slip in between
179 * ...BUTTONDOWN and ...BUTTONDBLCLK messages */
181 if(GetClassLongA(hWnd, GCL_STYLE) & CS_DBLCLKS || ht != HTCLIENT )
183 if ((message == clk_message) && (hWnd == clk_hwnd) &&
184 (msg->time - dblclk_time_limit < doubleClickSpeed) &&
185 (abs(msg->pt.x - clk_pos.x) < GetSystemMetrics(SM_CXDOUBLECLK)/2) &&
186 (abs(msg->pt.y - clk_pos.y) < GetSystemMetrics(SM_CYDOUBLECLK)/2))
188 message += (WM_LBUTTONDBLCLK - WM_LBUTTONDOWN);
189 mouseClick++; /* == 2 */
193 /* save mouse position */
194 screen_pt = pt;
195 *pScreen_pt = pt;
197 if (hittest != HTCLIENT)
199 message += WM_NCMOUSEMOVE - WM_MOUSEMOVE;
200 msg->wParam = hittest;
202 else
203 ScreenToClient16( hWnd, &pt );
205 /* check message filter */
207 if (!MSG_CheckFilter(message, first, last))
209 QUEUE_Unlock(queue);
210 retvalue = SYSQ_MSG_CONTINUE;
211 goto END;
214 /* Update global hCursorQueue */
215 hCursorQueue = queue->self;
217 /* Update static double click conditions */
218 if( remove && mouseClick )
220 if( mouseClick == 1 )
222 /* set conditions */
223 dblclk_time_limit = msg->time;
224 clk_message = msg->message;
225 clk_hwnd = hWnd;
226 clk_pos = screen_pt;
227 } else
228 /* got double click - zero them out */
229 dblclk_time_limit = clk_hwnd = 0;
232 QUEUE_Unlock(queue);
234 /* Update message params */
235 msg->hwnd = hWnd;
236 msg->message = message;
237 msg->lParam = MAKELONG( pt.x, pt.y );
238 retvalue = SYSQ_MSG_ACCEPT;
240 END:
241 WIN_ReleaseWndPtr(pWnd);
243 /* Return mouseclick flag */
244 *pmouseClick = mouseClick;
246 return retvalue;
250 /***********************************************************************
251 * MSG_ProcessMouseMsg
253 * Processes a translated mouse hardware event.
254 * The passed in msg structure should contain the updated hWnd,
255 * lParam, wParam and message fields from MSG_TranslateMouseMsg.
257 * Returns:
259 * SYSQ_MSG_SKIP - Message should be skipped entirely (in this case
260 * HIWORD contains hit test code). Continue translating..
261 * SYSQ_MSG_ACCEPT - the translated message must be passed to the user
262 * MSG_PeekHardwareMsg should return TRUE.
264 static DWORD MSG_ProcessMouseMsg( MSG *msg, BOOL remove, INT16 hittest,
265 POINT16 screen_pt, BOOL mouseClick )
267 WND *pWnd;
268 HWND hWnd = msg->hwnd;
269 INT16 sendSC = (GetCapture() == 0);
270 UINT message = msg->message;
271 BOOL eatMsg = FALSE;
272 DWORD retvalue;
274 pWnd = WIN_FindWndPtr(hWnd);
276 /* call WH_MOUSE */
278 if (HOOK_IsHooked( WH_MOUSE ))
280 SYSQ_STATUS ret = 0;
281 MOUSEHOOKSTRUCT16 *hook = SEGPTR_NEW(MOUSEHOOKSTRUCT16);
282 if( hook )
284 hook->pt = screen_pt;
285 hook->hwnd = hWnd;
286 hook->wHitTestCode = hittest;
287 hook->dwExtraInfo = 0;
288 ret = HOOK_CallHooks16( WH_MOUSE, remove ? HC_ACTION : HC_NOREMOVE,
289 message, (LPARAM)SEGPTR_GET(hook) );
290 SEGPTR_FREE(hook);
292 if( ret )
294 retvalue = MAKELONG((INT16)SYSQ_MSG_SKIP, hittest);
295 goto END;
299 if (message >= WM_NCMOUSEFIRST && message <= WM_NCMOUSELAST)
300 message += WM_MOUSEFIRST - WM_NCMOUSEFIRST;
302 if ((hittest == HTERROR) || (hittest == HTNOWHERE))
303 eatMsg = sendSC = 1;
304 else if( remove && mouseClick )
306 HWND hwndTop = WIN_GetTopParent( hWnd );
308 if( sendSC )
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, message, 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))
325 eatMsg = TRUE;
327 if (((ret == MA_ACTIVATE) || (ret == MA_ACTIVATEANDEAT))
328 && hwndTop != GetForegroundWindow() )
330 if (!WINPOS_SetActiveWindow( hwndTop, TRUE , TRUE ))
331 eatMsg = TRUE;
335 } else sendSC = (remove && sendSC);
337 /* Send the WM_SETCURSOR message */
339 if (sendSC)
341 /* Windows sends the normal mouse message as the message parameter
342 in the WM_SETCURSOR message even if it's non-client mouse message */
343 SendMessageA( hWnd, WM_SETCURSOR, hWnd,
344 MAKELONG( hittest, message ));
346 if (eatMsg)
348 retvalue = MAKELONG( (UINT16)SYSQ_MSG_SKIP, hittest);
349 goto END;
352 retvalue = SYSQ_MSG_ACCEPT;
353 END:
354 WIN_ReleaseWndPtr(pWnd);
356 return retvalue;
360 /***********************************************************************
361 * MSG_TranslateKbdMsg
363 * Translate a keyboard hardware event into a real message.
365 static DWORD MSG_TranslateKbdMsg( HWND hTopWnd, DWORD first, DWORD last,
366 MSG *msg, BOOL remove )
368 WORD message = msg->message;
369 HWND hWnd = GetFocus();
370 WND *pWnd;
372 /* Should check Ctrl-Esc and PrintScreen here */
374 if (!hWnd)
376 /* Send the message to the active window instead, */
377 /* translating messages to their WM_SYS equivalent */
379 hWnd = GetActiveWindow();
381 if( message < WM_SYSKEYDOWN )
382 message += WM_SYSKEYDOWN - WM_KEYDOWN;
384 if ( !hWnd ) return SYSQ_MSG_ABANDON;
385 pWnd = WIN_FindWndPtr( hWnd );
387 if (pWnd && (pWnd->hmemTaskQ != GetFastQueue16()))
389 /* Not for the current task */
390 MESSAGEQUEUE *queue = QUEUE_Lock( GetFastQueue16() );
391 if (queue) QUEUE_ClearWakeBit( queue, QS_KEY );
392 QUEUE_Unlock( queue );
394 /* Wake up the other task */
395 queue = QUEUE_Lock( pWnd->hmemTaskQ );
396 if (queue) QUEUE_SetWakeBit( queue, QS_KEY );
397 QUEUE_Unlock( queue );
398 WIN_ReleaseWndPtr(pWnd);
399 return SYSQ_MSG_ABANDON;
401 WIN_ReleaseWndPtr(pWnd);
403 if (hTopWnd && hWnd != hTopWnd)
404 if (!IsChild(hTopWnd, hWnd)) return SYSQ_MSG_CONTINUE;
405 if (!MSG_CheckFilter(message, first, last)) return SYSQ_MSG_CONTINUE;
407 msg->hwnd = hWnd;
408 msg->message = message;
410 return SYSQ_MSG_ACCEPT;
414 /***********************************************************************
415 * MSG_ProcessKbdMsg
417 * Processes a translated keyboard message
419 static DWORD MSG_ProcessKbdMsg( MSG *msg, BOOL remove )
421 /* Handle F1 key by sending out WM_HELP message */
422 if ((msg->message == WM_KEYUP) &&
423 (msg->wParam == VK_F1) &&
424 remove &&
425 (msg->hwnd != GetDesktopWindow()) &&
426 !MENU_IsMenuActive())
428 HELPINFO hi;
429 WND *pWnd = WIN_FindWndPtr(msg->hwnd);
431 if (NULL != pWnd)
433 hi.cbSize = sizeof(HELPINFO);
434 hi.iContextType = HELPINFO_WINDOW;
435 hi.iCtrlId = pWnd->wIDmenu;
436 hi.hItemHandle = msg->hwnd;
437 hi.dwContextId = pWnd->helpContext;
438 hi.MousePos = msg->pt;
439 SendMessageA(msg->hwnd, WM_HELP, 0, (LPARAM)&hi);
441 WIN_ReleaseWndPtr(pWnd);
444 return (HOOK_CallHooks16( WH_KEYBOARD, remove ? HC_ACTION : HC_NOREMOVE,
445 LOWORD (msg->wParam), msg->lParam )
446 ? SYSQ_MSG_SKIP : SYSQ_MSG_ACCEPT);
450 /***********************************************************************
451 * MSG_JournalRecordMsg
453 * Build an EVENTMSG structure and call JOURNALRECORD hook
455 static void MSG_JournalRecordMsg( MSG *msg )
457 EVENTMSG event;
459 event.message = msg->message;
460 event.time = msg->time;
461 if ((msg->message >= WM_KEYFIRST) && (msg->message <= WM_KEYLAST))
463 event.paramL = (msg->wParam & 0xFF) | (HIWORD(msg->lParam) << 8);
464 event.paramH = msg->lParam & 0x7FFF;
465 if (HIWORD(msg->lParam) & 0x0100)
466 event.paramH |= 0x8000; /* special_key - bit */
467 HOOK_CallHooksA( WH_JOURNALRECORD, HC_ACTION, 0, (LPARAM)&event );
469 else if ((msg->message >= WM_MOUSEFIRST) && (msg->message <= WM_MOUSELAST))
471 POINT pt;
472 pt.x = SLOWORD(msg->lParam);
473 pt.y = SHIWORD(msg->lParam);
474 ClientToScreen( msg->hwnd, &pt );
475 event.paramL = pt.x;
476 event.paramH = pt.y;
477 HOOK_CallHooksA( WH_JOURNALRECORD, HC_ACTION, 0, (LPARAM)&event );
479 else if ((msg->message >= WM_NCMOUSEFIRST) &&
480 (msg->message <= WM_NCMOUSELAST))
482 event.paramL = LOWORD(msg->lParam); /* X pos */
483 event.paramH = HIWORD(msg->lParam); /* Y pos */
484 event.message += WM_MOUSEMOVE-WM_NCMOUSEMOVE;/* give no info about NC area */
485 HOOK_CallHooksA( WH_JOURNALRECORD, HC_ACTION, 0, (LPARAM)&event );
489 /***********************************************************************
490 * MSG_JournalPlayBackMsg
492 * Get an EVENTMSG struct via call JOURNALPLAYBACK hook function
494 static int MSG_JournalPlayBackMsg(void)
496 EVENTMSG tmpMsg;
497 LPARAM lParam;
498 WPARAM wParam;
499 LRESULT wtime;
500 int keyDown,i;
502 if (!HOOK_IsHooked( WH_JOURNALPLAYBACK )) return 0;
504 wtime=HOOK_CallHooksA( WH_JOURNALPLAYBACK, HC_GETNEXT, 0, (LPARAM)&tmpMsg );
505 /* TRACE(msg,"Playback wait time =%ld\n",wtime); */
506 if (wtime<=0)
508 wtime=0;
509 if ((tmpMsg.message >= WM_KEYFIRST) && (tmpMsg.message <= WM_KEYLAST))
511 wParam=tmpMsg.paramL & 0xFF;
512 lParam=MAKELONG(tmpMsg.paramH&0x7ffff,tmpMsg.paramL>>8);
513 if (tmpMsg.message == WM_KEYDOWN || tmpMsg.message == WM_SYSKEYDOWN)
515 for (keyDown=i=0; i<256 && !keyDown; i++)
516 if (InputKeyStateTable[i] & 0x80)
517 keyDown++;
518 if (!keyDown)
519 lParam |= 0x40000000;
520 AsyncKeyStateTable[wParam]=InputKeyStateTable[wParam] |= 0x80;
522 else /* WM_KEYUP, WM_SYSKEYUP */
524 lParam |= 0xC0000000;
525 AsyncKeyStateTable[wParam]=InputKeyStateTable[wParam] &= ~0x80;
527 if (InputKeyStateTable[VK_MENU] & 0x80)
528 lParam |= 0x20000000;
529 if (tmpMsg.paramH & 0x8000) /*special_key bit*/
530 lParam |= 0x01000000;
531 hardware_event( tmpMsg.message, wParam, lParam, 0, 0, tmpMsg.time, 0 );
533 else if ((tmpMsg.message>= WM_MOUSEFIRST) && (tmpMsg.message <= WM_MOUSELAST))
535 switch (tmpMsg.message)
537 case WM_LBUTTONDOWN:
538 MouseButtonsStates[0]=AsyncMouseButtonsStates[0]=TRUE;break;
539 case WM_LBUTTONUP:
540 MouseButtonsStates[0]=AsyncMouseButtonsStates[0]=FALSE;break;
541 case WM_MBUTTONDOWN:
542 MouseButtonsStates[1]=AsyncMouseButtonsStates[1]=TRUE;break;
543 case WM_MBUTTONUP:
544 MouseButtonsStates[1]=AsyncMouseButtonsStates[1]=FALSE;break;
545 case WM_RBUTTONDOWN:
546 MouseButtonsStates[2]=AsyncMouseButtonsStates[2]=TRUE;break;
547 case WM_RBUTTONUP:
548 MouseButtonsStates[2]=AsyncMouseButtonsStates[2]=FALSE;break;
550 AsyncKeyStateTable[VK_LBUTTON]= InputKeyStateTable[VK_LBUTTON] = MouseButtonsStates[0] ? 0x80 : 0;
551 AsyncKeyStateTable[VK_MBUTTON]= InputKeyStateTable[VK_MBUTTON] = MouseButtonsStates[1] ? 0x80 : 0;
552 AsyncKeyStateTable[VK_RBUTTON]= InputKeyStateTable[VK_RBUTTON] = MouseButtonsStates[2] ? 0x80 : 0;
553 SetCursorPos(tmpMsg.paramL,tmpMsg.paramH);
554 lParam=MAKELONG(tmpMsg.paramL,tmpMsg.paramH);
555 wParam=0;
556 if (MouseButtonsStates[0]) wParam |= MK_LBUTTON;
557 if (MouseButtonsStates[1]) wParam |= MK_MBUTTON;
558 if (MouseButtonsStates[2]) wParam |= MK_RBUTTON;
559 hardware_event( tmpMsg.message, wParam, lParam,
560 tmpMsg.paramL, tmpMsg.paramH, tmpMsg.time, 0 );
562 HOOK_CallHooksA( WH_JOURNALPLAYBACK, HC_SKIP, 0, (LPARAM)&tmpMsg);
563 return 0;
565 else
567 if( tmpMsg.message == WM_QUEUESYNC )
568 if (HOOK_IsHooked( WH_CBT ))
569 HOOK_CallHooksA( WH_CBT, HCBT_QS, 0, 0L);
571 return QS_MOUSE | QS_KEY; /* ? */
575 /***********************************************************************
576 * MSG_PeekHardwareMsg
578 * Peek for a hardware message matching the hwnd and message filters.
580 static BOOL MSG_PeekHardwareMsg( MSG *msg, HWND hwnd, DWORD first, DWORD last,
581 BOOL remove )
583 DWORD status = SYSQ_MSG_ACCEPT;
584 MESSAGEQUEUE *sysMsgQueue = QUEUE_GetSysQueue();
585 enum { MOUSE_MSG = 0, KEYBOARD_MSG, HARDWARE_MSG } msgType;
586 QMSG *nextqmsg, *qmsg = 0;
587 BOOL bRet = FALSE;
589 EnterCriticalSection(&sysMsgQueue->cSection);
591 /* Loop through the Q and translate the message we wish to process
592 * while we own the lock. Based on the translation status (abandon/cont/accept)
593 * we then process the message accordingly
596 for ( qmsg = sysMsgQueue->firstMsg; qmsg; qmsg = nextqmsg )
598 INT16 hittest;
599 POINT16 screen_pt;
600 BOOL mouseClick;
602 *msg = qmsg->msg;
604 nextqmsg = qmsg->nextMsg;
606 /* Translate message */
608 if ((msg->message >= WM_MOUSEFIRST) && (msg->message <= WM_MOUSELAST))
610 HWND hWndScope = (HWND)qmsg->extraInfo;
611 WND *tmpWnd = (Options.managed && IsWindow(hWndScope) )
612 ? WIN_FindWndPtr(hWndScope) : WIN_GetDesktop();
614 status = MSG_TranslateMouseMsg(hwnd, first, last, msg, remove, tmpWnd,
615 &hittest, &screen_pt, &mouseClick );
616 msgType = MOUSE_MSG;
618 WIN_ReleaseWndPtr(tmpWnd);
621 else if ((msg->message >= WM_KEYFIRST) && (msg->message <= WM_KEYLAST))
623 status = MSG_TranslateKbdMsg(hwnd, first, last, msg, remove);
624 msgType = KEYBOARD_MSG;
626 else /* Non-standard hardware event */
628 HARDWAREHOOKSTRUCT16 *hook;
629 msgType = HARDWARE_MSG;
630 if ((hook = SEGPTR_NEW(HARDWAREHOOKSTRUCT16)))
632 BOOL ret;
633 hook->hWnd = msg->hwnd;
634 hook->wMessage = msg->message & 0xffff;
635 hook->wParam = LOWORD (msg->wParam);
636 hook->lParam = msg->lParam;
637 ret = HOOK_CallHooks16( WH_HARDWARE,
638 remove ? HC_ACTION : HC_NOREMOVE,
639 0, (LPARAM)SEGPTR_GET(hook) );
640 SEGPTR_FREE(hook);
641 if (ret)
643 QUEUE_RemoveMsg( sysMsgQueue, qmsg );
644 continue;
646 status = SYSQ_MSG_ACCEPT;
651 switch (LOWORD(status))
653 case SYSQ_MSG_ACCEPT:
655 /* Remove the message from the system msg Q while it is still locked,
656 * before accepting it */
657 if (remove)
659 if (HOOK_IsHooked( WH_JOURNALRECORD )) MSG_JournalRecordMsg( msg );
660 QUEUE_RemoveMsg( sysMsgQueue, qmsg );
662 /* Now actually process the message, after we unlock the system msg Q.
663 * We should not hold on to the crst since SendMessage calls during processing
664 * will potentially cause callbacks to PeekMessage from the application.
665 * If we're holding the crst and QUEUE_WaitBits is called with a
666 * QS_SENDMESSAGE mask we will deadlock in hardware_event() when a
667 * message is being posted to the Q.
669 LeaveCriticalSection(&sysMsgQueue->cSection);
670 if( msgType == KEYBOARD_MSG )
671 status = MSG_ProcessKbdMsg( msg, remove );
672 else if ( msgType == MOUSE_MSG )
673 status = MSG_ProcessMouseMsg( msg, remove, hittest, screen_pt, mouseClick );
675 /* Reclaim the sys msg Q crst */
676 EnterCriticalSection(&sysMsgQueue->cSection);
678 /* Pass the translated message to the user if it was accepted */
679 if (status == SYSQ_MSG_ACCEPT)
680 break;
682 /* If not accepted, fall through into the SYSQ_MSG_SKIP case */
685 case SYSQ_MSG_SKIP:
686 if (HOOK_IsHooked( WH_CBT ))
688 if( msgType == KEYBOARD_MSG )
689 HOOK_CallHooks16( WH_CBT, HCBT_KEYSKIPPED,
690 LOWORD (msg->wParam), msg->lParam );
691 else if ( msgType == MOUSE_MSG )
693 MOUSEHOOKSTRUCT16 *hook = SEGPTR_NEW(MOUSEHOOKSTRUCT16);
694 if (hook)
696 CONV_POINT32TO16( &msg->pt,&hook->pt );
697 hook->hwnd = msg->hwnd;
698 hook->wHitTestCode = HIWORD(status);
699 hook->dwExtraInfo = 0;
700 HOOK_CallHooks16( WH_CBT, HCBT_CLICKSKIPPED ,msg->message & 0xffff,
701 (LPARAM)SEGPTR_GET(hook) );
702 SEGPTR_FREE(hook);
707 /* If the message was removed earlier set up nextqmsg so that we start
708 * at the top of the queue again. We need to do this since our next pointer
709 * could be invalid due to us unlocking the system message Q to process the message.
710 * If not removed just refresh nextqmsg to point to the next msg.
712 if (remove)
713 nextqmsg = sysMsgQueue->firstMsg;
714 else
715 nextqmsg = qmsg->nextMsg;
717 continue;
719 case SYSQ_MSG_CONTINUE:
720 continue;
722 case SYSQ_MSG_ABANDON:
723 bRet = FALSE;
724 goto END;
727 bRet = TRUE;
728 goto END;
731 END:
732 LeaveCriticalSection(&sysMsgQueue->cSection);
733 return bRet;
737 /**********************************************************************
738 * SetDoubleClickTime (USER.20)
740 void WINAPI SetDoubleClickTime16( UINT16 interval )
742 SetDoubleClickTime( interval );
746 /**********************************************************************
747 * SetDoubleClickTime (USER32.@)
749 BOOL WINAPI SetDoubleClickTime( UINT interval )
751 doubleClickSpeed = interval ? interval : 500;
752 return TRUE;
756 /**********************************************************************
757 * GetDoubleClickTime (USER.21)
759 UINT16 WINAPI GetDoubleClickTime16(void)
761 return doubleClickSpeed;
765 /**********************************************************************
766 * GetDoubleClickTime (USER32.@)
768 UINT WINAPI GetDoubleClickTime(void)
770 return doubleClickSpeed;
774 /***********************************************************************
775 * MSG_SendMessageInterThread
777 * Implementation of an inter-task SendMessage.
778 * Return values:
779 * 0 if error or timeout
780 * 1 if successful
782 static LRESULT MSG_SendMessageInterThread( HQUEUE16 hDestQueue,
783 HWND hwnd, UINT msg,
784 WPARAM wParam, LPARAM lParam,
785 DWORD timeout, WORD flags,
786 LRESULT *pRes)
788 MESSAGEQUEUE *queue, *destQ;
789 SMSG *smsg;
790 LRESULT retVal = 1;
791 int iWndsLocks;
793 if (pRes) *pRes = 0;
795 if (IsTaskLocked16() || !IsWindow(hwnd))
796 return 0;
798 /* create a SMSG structure to hold SendMessage() parameters */
799 if (! (smsg = (SMSG *) HeapAlloc( GetProcessHeap(), 0, sizeof(SMSG) )) )
800 return 0;
801 if (!(queue = QUEUE_Lock( GetFastQueue16() ))) return 0;
803 if (!(destQ = QUEUE_Lock( hDestQueue )))
805 QUEUE_Unlock( queue );
806 return 0;
809 TRACE_(sendmsg)("SM: %s [%04x] (%04x -> %04x)\n",
810 SPY_GetMsgName(msg), msg, queue->self, hDestQueue );
812 /* fill up SMSG structure */
813 smsg->hWnd = hwnd;
814 smsg->msg = msg;
815 smsg->wParam = wParam;
816 smsg->lParam = lParam;
818 smsg->lResult = 0;
819 smsg->hSrcQueue = pRes ? GetFastQueue16() : 0;
820 smsg->hDstQueue = hDestQueue;
821 smsg->flags = flags;
823 if (pRes) {
824 /* add smsg struct in the processing SM list of the source queue */
825 QUEUE_AddSMSG(queue, SM_PROCESSING_LIST, smsg);
826 } else {
827 /* this is a notification message, we don't need a reply */
828 smsg->flags |= SMSG_ALREADY_REPLIED | SMSG_RECEIVER_CLEANS;
831 /* add smsg struct in the pending list of the destination queue */
832 if (QUEUE_AddSMSG(destQ, SM_PENDING_LIST, smsg) == FALSE)
834 retVal = 0;
835 goto CLEANUP;
838 if (!pRes) goto CLEANUP; /* don't need a reply */
840 iWndsLocks = WIN_SuspendWndsLock();
842 /* force destination task to run next, if 16 bit threads */
843 if ( THREAD_IsWin16(NtCurrentTeb()) && THREAD_IsWin16(destQ->teb) )
844 DirectedYield16( destQ->teb->htask16 );
846 /* wait for the result, note that 16-bit apps almost always get out of
847 * DirectedYield() with SMSG_HAVE_RESULT flag already set */
849 while ( TRUE )
852 * The sequence is crucial to avoid deadlock situations:
853 * - first, we clear the QS_SMRESULT bit
854 * - then, we check the SMSG_HAVE_RESULT bit
855 * - only if this isn't set, we enter the wait state.
857 * As the receiver first sets the SMSG_HAVE_RESULT and then wakes us,
858 * we are guaranteed that -should we now clear the QS_SMRESULT that
859 * was signalled already by the receiver- we will not start waiting.
862 if ( smsg->flags & SMSG_HAVE_RESULT )
864 got:
865 *pRes = smsg->lResult;
866 TRACE_(sendmsg)("smResult = %08x\n", (unsigned)*pRes );
867 break;
870 QUEUE_ClearWakeBit( queue, QS_SMRESULT );
872 if ( smsg->flags & SMSG_HAVE_RESULT )
873 goto got;
875 if( QUEUE_WaitBits( QS_SMRESULT, timeout ) == 0 )
877 /* return with timeout */
878 SetLastError( 0 );
879 retVal = 0;
880 break;
883 WIN_RestoreWndsLock(iWndsLocks);
885 /* remove the smsg from the processing list of the source queue */
886 QUEUE_RemoveSMSG( queue, SM_PROCESSING_LIST, smsg );
888 /* Note: the destination thread is in charge of removing the smsg from
889 the pending list */
891 /* In the case of an early reply (or a timeout), sender thread will
892 released the smsg structure if the receiver thread is done
893 (SMSG_RECEIVED set). If the receiver thread isn't done,
894 SMSG_RECEIVER_CLEANS_UP flag is set, and it will be the receiver
895 responsibility to release smsg */
896 EnterCriticalSection( &queue->cSection );
898 if (smsg->flags & SMSG_RECEIVED)
899 HeapFree(GetProcessHeap(), 0, smsg);
900 else
901 smsg->flags |= SMSG_RECEIVER_CLEANS;
903 LeaveCriticalSection( &queue->cSection );
906 CLEANUP:
907 QUEUE_Unlock( queue );
908 QUEUE_Unlock( destQ );
910 TRACE_(sendmsg)("done!\n");
911 return retVal;
915 /***********************************************************************
916 * ReplyMessage (USER.115)
918 void WINAPI ReplyMessage16( LRESULT result )
920 ReplyMessage( result );
923 /***********************************************************************
924 * ReplyMessage (USER32.@)
926 BOOL WINAPI ReplyMessage( LRESULT result )
928 MESSAGEQUEUE *senderQ = 0;
929 MESSAGEQUEUE *queue = 0;
930 SMSG *smsg;
931 BOOL ret = FALSE;
933 if (!(queue = QUEUE_Lock( GetFastQueue16() )))
934 return FALSE;
936 TRACE_(sendmsg)("ReplyMessage, queue %04x\n", queue->self);
939 if ( !(smsg = queue->smWaiting)
940 || !( (senderQ = QUEUE_Lock( smsg->hSrcQueue ))
941 || (smsg->flags & SMSG_ALREADY_REPLIED)) )
942 goto ReplyMessageEnd;
944 if ( !(smsg->flags & SMSG_ALREADY_REPLIED) )
946 /* This is the first reply, so pass result to sender */
948 TRACE_(sendmsg)("\trpm: smResult = %08lx\n", (long) result );
950 EnterCriticalSection(&senderQ->cSection);
952 smsg->lResult = result;
953 smsg->flags |= SMSG_ALREADY_REPLIED;
955 /* check if it's an early reply (called by the application) or
956 a regular reply (called by ReceiveMessage) */
957 if ( !(smsg->flags & SMSG_SENDING_REPLY) )
958 smsg->flags |= SMSG_EARLY_REPLY;
960 smsg->flags |= SMSG_HAVE_RESULT;
962 LeaveCriticalSection(&senderQ->cSection);
964 /* tell the sending task that its reply is ready */
965 QUEUE_SetWakeBit( senderQ, QS_SMRESULT );
967 /* switch directly to sending task (16 bit thread only) */
968 if ( THREAD_IsWin16( NtCurrentTeb() ) && THREAD_IsWin16( senderQ->teb ) )
969 DirectedYield16( senderQ->teb->htask16 );
971 ret = TRUE;
974 if (smsg->flags & SMSG_SENDING_REPLY)
976 /* remove msg from the waiting list, since this is the last
977 ReplyMessage */
978 QUEUE_RemoveSMSG( queue, SM_WAITING_LIST, smsg );
980 if (senderQ) EnterCriticalSection(&senderQ->cSection);
982 /* tell the sender we're all done with smsg structure */
983 smsg->flags |= SMSG_RECEIVED;
985 /* sender will set SMSG_RECEIVER_CLEANS_UP if it wants the
986 receiver to clean up smsg, it could only happen when there is
987 an early reply or a timeout */
988 if ( smsg->flags & SMSG_RECEIVER_CLEANS )
990 TRACE_(sendmsg)("Receiver cleans up!\n" );
991 HeapFree( GetProcessHeap(), 0, smsg );
994 if (senderQ) LeaveCriticalSection(&senderQ->cSection);
997 ReplyMessageEnd:
998 if ( senderQ )
999 QUEUE_Unlock( senderQ );
1000 if ( queue )
1001 QUEUE_Unlock( queue );
1003 return ret;
1006 /***********************************************************************
1007 * MSG_ConvertMsg
1009 static BOOL MSG_ConvertMsg( MSG *msg, int srcType, int dstType )
1011 UINT16 msg16;
1012 MSGPARAM16 mp16;
1014 switch ( MAKELONG( srcType, dstType ) )
1016 case MAKELONG( QMSG_WIN16, QMSG_WIN16 ):
1017 case MAKELONG( QMSG_WIN32A, QMSG_WIN32A ):
1018 case MAKELONG( QMSG_WIN32W, QMSG_WIN32W ):
1019 return TRUE;
1021 case MAKELONG( QMSG_WIN16, QMSG_WIN32A ):
1022 switch ( WINPROC_MapMsg16To32A( msg->message, msg->wParam,
1023 &msg->message, &msg->wParam, &msg->lParam ) )
1025 case 0:
1026 return TRUE;
1027 case 1:
1028 /* Pointer messages were mapped --> need to free allocated memory and fail */
1029 WINPROC_UnmapMsg16To32A( msg->hwnd, msg->message, msg->wParam, msg->lParam, 0 );
1030 default:
1031 return FALSE;
1034 case MAKELONG( QMSG_WIN16, QMSG_WIN32W ):
1035 switch ( WINPROC_MapMsg16To32W( msg->hwnd, msg->message, msg->wParam,
1036 &msg->message, &msg->wParam, &msg->lParam ) )
1038 case 0:
1039 return TRUE;
1040 case 1:
1041 /* Pointer messages were mapped --> need to free allocated memory and fail */
1042 WINPROC_UnmapMsg16To32W( msg->hwnd, msg->message, msg->wParam, msg->lParam, 0 );
1043 default:
1044 return FALSE;
1047 case MAKELONG( QMSG_WIN32A, QMSG_WIN16 ):
1048 mp16.lParam = msg->lParam;
1049 switch ( WINPROC_MapMsg32ATo16( msg->hwnd, msg->message, msg->wParam,
1050 &msg16, &mp16.wParam, &mp16.lParam ) )
1052 case 0:
1053 msg->message = msg16;
1054 msg->wParam = mp16.wParam;
1055 msg->lParam = mp16.lParam;
1056 return TRUE;
1057 case 1:
1058 /* Pointer messages were mapped --> need to free allocated memory and fail */
1059 WINPROC_UnmapMsg32ATo16( msg->hwnd, msg->message, msg->wParam, msg->lParam, &mp16 );
1060 default:
1061 return FALSE;
1064 case MAKELONG( QMSG_WIN32W, QMSG_WIN16 ):
1065 mp16.lParam = msg->lParam;
1066 switch ( WINPROC_MapMsg32WTo16( msg->hwnd, msg->message, msg->wParam,
1067 &msg16, &mp16.wParam, &mp16.lParam ) )
1069 case 0:
1070 msg->message = msg16;
1071 msg->wParam = mp16.wParam;
1072 msg->lParam = mp16.lParam;
1073 return TRUE;
1074 case 1:
1075 /* Pointer messages were mapped --> need to free allocated memory and fail */
1076 WINPROC_UnmapMsg32WTo16( msg->hwnd, msg->message, msg->wParam, msg->lParam, &mp16 );
1077 default:
1078 return FALSE;
1081 case MAKELONG( QMSG_WIN32A, QMSG_WIN32W ):
1082 switch ( WINPROC_MapMsg32ATo32W( msg->hwnd, msg->message, &msg->wParam, &msg->lParam ) )
1084 case 0:
1085 return TRUE;
1086 case 1:
1087 /* Pointer messages were mapped --> need to free allocated memory and fail */
1088 WINPROC_UnmapMsg32ATo32W( msg->hwnd, msg->message, msg->wParam, msg->lParam );
1089 default:
1090 return FALSE;
1093 case MAKELONG( QMSG_WIN32W, QMSG_WIN32A ):
1094 switch ( WINPROC_MapMsg32WTo32A( msg->hwnd, msg->message, &msg->wParam, &msg->lParam ) )
1096 case 0:
1097 return TRUE;
1098 case 1:
1099 /* Pointer messages were mapped --> need to free allocated memory and fail */
1100 WINPROC_UnmapMsg32WTo32A( msg->hwnd, msg->message, msg->wParam, msg->lParam );
1101 default:
1102 return FALSE;
1105 default:
1106 FIXME( "Invalid message type(s): %d / %d\n", srcType, dstType );
1107 return FALSE;
1111 /***********************************************************************
1112 * MSG_PeekMessage
1114 static BOOL MSG_PeekMessage( int type, LPMSG msg_out, HWND hwnd,
1115 DWORD first, DWORD last, WORD flags, BOOL peek )
1117 int changeBits, mask;
1118 MESSAGEQUEUE *msgQueue;
1119 HQUEUE16 hQueue;
1120 int iWndsLocks;
1121 MSG msg;
1123 mask = QS_POSTMESSAGE | QS_SENDMESSAGE; /* Always selected */
1124 if (first || last)
1126 if ((first <= WM_KEYLAST) && (last >= WM_KEYFIRST)) mask |= QS_KEY;
1127 if ( ((first <= WM_MOUSELAST) && (last >= WM_MOUSEFIRST)) ||
1128 ((first <= WM_NCMOUSELAST) && (last >= WM_NCMOUSEFIRST)) ) mask |= QS_MOUSE;
1129 if ((first <= WM_TIMER) && (last >= WM_TIMER)) mask |= QS_TIMER;
1130 if ((first <= WM_SYSTIMER) && (last >= WM_SYSTIMER)) mask |= QS_TIMER;
1131 if ((first <= WM_PAINT) && (last >= WM_PAINT)) mask |= QS_PAINT;
1133 else mask |= QS_MOUSE | QS_KEY | QS_TIMER | QS_PAINT;
1135 if (IsTaskLocked16()) flags |= PM_NOYIELD;
1137 /* Never yield on Win32 threads */
1138 if (!THREAD_IsWin16(NtCurrentTeb())) flags |= PM_NOYIELD;
1140 iWndsLocks = WIN_SuspendWndsLock();
1142 while(1)
1144 QMSG *qmsg;
1146 hQueue = GetFastQueue16();
1147 msgQueue = QUEUE_Lock( hQueue );
1148 if (!msgQueue)
1150 WIN_RestoreWndsLock(iWndsLocks);
1151 return FALSE;
1154 EnterCriticalSection( &msgQueue->cSection );
1155 msgQueue->changeBits = 0;
1156 LeaveCriticalSection( &msgQueue->cSection );
1158 /* First handle a message put by SendMessage() */
1160 while ( QUEUE_ReceiveMessage( msgQueue ) )
1163 /* Now handle a WM_QUIT message */
1165 EnterCriticalSection( &msgQueue->cSection );
1166 if (msgQueue->wPostQMsg &&
1167 (!first || WM_QUIT >= first) &&
1168 (!last || WM_QUIT <= last) )
1170 msg.hwnd = hwnd;
1171 msg.message = WM_QUIT;
1172 msg.wParam = msgQueue->wExitCode;
1173 msg.lParam = 0;
1174 if (flags & PM_REMOVE) msgQueue->wPostQMsg = 0;
1175 LeaveCriticalSection( &msgQueue->cSection );
1176 break;
1178 LeaveCriticalSection( &msgQueue->cSection );
1180 /* Now find a normal message */
1182 retry:
1183 if ((QUEUE_TestWakeBit(msgQueue, mask & QS_POSTMESSAGE)) &&
1184 ((qmsg = QUEUE_FindMsg( msgQueue, hwnd, first, last )) != 0))
1186 /* Try to convert message to requested type */
1187 MSG tmpMsg = qmsg->msg;
1188 if ( !MSG_ConvertMsg( &tmpMsg, qmsg->type, type ) )
1190 ERR( "Message %s of wrong type contains pointer parameters. Skipped!\n",
1191 SPY_GetMsgName(tmpMsg.message));
1192 QUEUE_RemoveMsg( msgQueue, qmsg );
1193 goto retry;
1196 msg = tmpMsg;
1197 msgQueue->GetMessageTimeVal = msg.time;
1198 msgQueue->GetMessagePosVal = MAKELONG( (INT16)msg.pt.x, (INT16)msg.pt.y );
1199 msgQueue->GetMessageExtraInfoVal = qmsg->extraInfo;
1201 if (flags & PM_REMOVE) QUEUE_RemoveMsg( msgQueue, qmsg );
1202 break;
1205 changeBits = MSG_JournalPlayBackMsg();
1206 EnterCriticalSection( &msgQueue->cSection );
1207 msgQueue->changeBits |= changeBits;
1208 LeaveCriticalSection( &msgQueue->cSection );
1210 /* Now find a hardware event */
1212 if (MSG_PeekHardwareMsg( &msg, hwnd, first, last, flags & PM_REMOVE ))
1214 /* Got one */
1215 msgQueue->GetMessageTimeVal = msg.time;
1216 msgQueue->GetMessagePosVal = MAKELONG( (INT16)msg.pt.x, (INT16)msg.pt.y );
1217 msgQueue->GetMessageExtraInfoVal = 0; /* Always 0 for now */
1218 break;
1221 /* Check again for SendMessage */
1223 while ( QUEUE_ReceiveMessage( msgQueue ) )
1226 /* Now find a WM_PAINT message */
1228 if (QUEUE_TestWakeBit(msgQueue, mask & QS_PAINT))
1230 WND* wndPtr;
1231 msg.hwnd = WIN_FindWinToRepaint( hwnd , hQueue );
1232 msg.message = WM_PAINT;
1233 msg.wParam = 0;
1234 msg.lParam = 0;
1236 if ((wndPtr = WIN_FindWndPtr(msg.hwnd)))
1238 if( wndPtr->dwStyle & WS_MINIMIZE &&
1239 (HICON) GetClassLongA(wndPtr->hwndSelf, GCL_HICON) )
1241 msg.message = WM_PAINTICON;
1242 msg.wParam = 1;
1245 if( !hwnd || msg.hwnd == hwnd || IsChild16(hwnd,msg.hwnd) )
1247 if( wndPtr->flags & WIN_INTERNAL_PAINT && !wndPtr->hrgnUpdate)
1249 wndPtr->flags &= ~WIN_INTERNAL_PAINT;
1250 QUEUE_DecPaintCount( hQueue );
1252 WIN_ReleaseWndPtr(wndPtr);
1253 break;
1255 WIN_ReleaseWndPtr(wndPtr);
1259 /* Check for timer messages, but yield first */
1261 if (!(flags & PM_NOYIELD))
1263 UserYield16();
1264 while ( QUEUE_ReceiveMessage( msgQueue ) )
1268 if (QUEUE_TestWakeBit(msgQueue, mask & QS_TIMER))
1270 if (TIMER_GetTimerMsg(&msg, hwnd, hQueue, flags & PM_REMOVE)) break;
1273 if (peek)
1275 if (!(flags & PM_NOYIELD)) UserYield16();
1277 QUEUE_Unlock( msgQueue );
1278 WIN_RestoreWndsLock(iWndsLocks);
1279 return FALSE;
1282 QUEUE_WaitBits( mask, INFINITE );
1283 QUEUE_Unlock( msgQueue );
1286 WIN_RestoreWndsLock(iWndsLocks);
1288 /* instead of unlocking queue for every break condition, all break
1289 condition will fall here */
1290 QUEUE_Unlock( msgQueue );
1292 /* We got a message */
1293 if (flags & PM_REMOVE)
1295 WORD message = msg.message;
1297 if (message == WM_KEYDOWN || message == WM_SYSKEYDOWN)
1299 BYTE *p = &QueueKeyStateTable[msg.wParam & 0xff];
1301 if (!(*p & 0x80))
1302 *p ^= 0x01;
1303 *p |= 0x80;
1305 else if (message == WM_KEYUP || message == WM_SYSKEYUP)
1306 QueueKeyStateTable[msg.wParam & 0xff] &= ~0x80;
1309 /* copy back our internal safe copy of message data to msg_out.
1310 * msg_out is a variable from the *program*, so it can't be used
1311 * internally as it can get "corrupted" by our use of SendMessage()
1312 * (back to the program) inside the message handling itself. */
1313 *msg_out = msg;
1314 if (peek)
1315 return TRUE;
1317 else
1318 return (msg.message != WM_QUIT);
1321 /***********************************************************************
1322 * MSG_InternalGetMessage
1324 * GetMessage() function for internal use. Behave like GetMessage(),
1325 * but also call message filters and optionally send WM_ENTERIDLE messages.
1326 * 'hwnd' must be the handle of the dialog or menu window.
1327 * 'code' is the message filter value (MSGF_??? codes).
1329 BOOL MSG_InternalGetMessage( int type, MSG *msg, HWND hwnd, HWND hwndOwner,
1330 WPARAM code, WORD flags, BOOL sendIdle, BOOL* idleSent )
1332 for (;;)
1334 if (sendIdle)
1336 if (!MSG_PeekMessage( type, msg, 0, 0, 0, flags, TRUE ))
1338 /* No message present -> send ENTERIDLE and wait */
1339 if (IsWindow(hwndOwner))
1341 SendMessageA( hwndOwner, WM_ENTERIDLE,
1342 code, (LPARAM)hwnd );
1344 if (idleSent!=NULL)
1345 *idleSent=TRUE;
1347 MSG_PeekMessage( type, msg, 0, 0, 0, flags, FALSE );
1350 else /* Always wait for a message */
1351 MSG_PeekMessage( type, msg, 0, 0, 0, flags, FALSE );
1353 /* Call message filters */
1355 if (HOOK_IsHooked( WH_SYSMSGFILTER ) || HOOK_IsHooked( WH_MSGFILTER ))
1357 MSG *pmsg = HeapAlloc( GetProcessHeap(), 0, sizeof(MSG) );
1358 if (pmsg)
1360 BOOL ret;
1361 *pmsg = *msg;
1362 ret = (HOOK_CallHooksA( WH_SYSMSGFILTER, code, 0,
1363 (LPARAM) pmsg ) ||
1364 HOOK_CallHooksA( WH_MSGFILTER, code, 0,
1365 (LPARAM) pmsg ));
1367 HeapFree( GetProcessHeap(), 0, pmsg );
1368 if (ret)
1370 /* Message filtered -> remove it from the queue */
1371 /* if it's still there. */
1372 if (!(flags & PM_REMOVE))
1373 MSG_PeekMessage( type, msg, 0, 0, 0, PM_REMOVE, TRUE );
1374 continue;
1379 return (msg->message != WM_QUIT);
1384 /***********************************************************************
1385 * PeekMessage32 (USER.819)
1387 BOOL16 WINAPI PeekMessage32_16( SEGPTR msg16_32, HWND16 hwnd,
1388 UINT16 first, UINT16 last, UINT16 flags,
1389 BOOL16 wHaveParamHigh )
1391 BOOL ret;
1392 MSG32_16 *lpmsg16_32 = MapSL(msg16_32);
1393 MSG msg;
1395 ret = MSG_PeekMessage( QMSG_WIN16, &msg, hwnd, first, last, flags, TRUE );
1397 lpmsg16_32->msg.hwnd = msg.hwnd;
1398 lpmsg16_32->msg.message = msg.message;
1399 lpmsg16_32->msg.wParam = LOWORD(msg.wParam);
1400 lpmsg16_32->msg.lParam = msg.lParam;
1401 lpmsg16_32->msg.time = msg.time;
1402 lpmsg16_32->msg.pt.x = (INT16)msg.pt.x;
1403 lpmsg16_32->msg.pt.y = (INT16)msg.pt.y;
1405 if ( wHaveParamHigh )
1406 lpmsg16_32->wParamHigh = HIWORD(msg.wParam);
1408 HOOK_CallHooks16( WH_GETMESSAGE, HC_ACTION, flags & PM_REMOVE, (LPARAM)msg16_32 );
1409 return ret;
1412 /***********************************************************************
1413 * PeekMessage (USER.109)
1415 BOOL16 WINAPI PeekMessage16( SEGPTR msg, HWND16 hwnd,
1416 UINT16 first, UINT16 last, UINT16 flags )
1418 return PeekMessage32_16( msg, hwnd, first, last, flags, FALSE );
1421 /***********************************************************************
1422 * PeekMessageA (USER32.@)
1424 BOOL WINAPI PeekMessageA( LPMSG lpmsg, HWND hwnd,
1425 UINT min, UINT max, UINT wRemoveMsg)
1427 BOOL ret = MSG_PeekMessage( QMSG_WIN32A, lpmsg, hwnd, min, max, wRemoveMsg, TRUE );
1429 TRACE( "peekmessage %04x, hwnd %04x, filter(%04x - %04x)\n",
1430 lpmsg->message, hwnd, min, max );
1432 if (ret) HOOK_CallHooksA( WH_GETMESSAGE, HC_ACTION,
1433 wRemoveMsg & PM_REMOVE, (LPARAM)lpmsg );
1434 return ret;
1437 /***********************************************************************
1438 * PeekMessageW (USER32.@) Check queue for messages
1440 * Checks for a message in the thread's queue, filtered as for
1441 * GetMessage(). Returns immediately whether a message is available
1442 * or not.
1444 * Whether a retrieved message is removed from the queue is set by the
1445 * _wRemoveMsg_ flags, which should be one of the following values:
1447 * PM_NOREMOVE Do not remove the message from the queue.
1449 * PM_REMOVE Remove the message from the queue.
1451 * In addition, PM_NOYIELD may be combined into _wRemoveMsg_ to
1452 * request that the system not yield control during PeekMessage();
1453 * however applications may not rely on scheduling behavior.
1455 * RETURNS
1457 * Nonzero if a message is available and is retrieved, zero otherwise.
1459 * CONFORMANCE
1461 * ECMA-234, Win32
1464 BOOL WINAPI PeekMessageW(
1465 LPMSG lpmsg, /* [out] buffer to receive message */
1466 HWND hwnd, /* [in] restrict to messages for hwnd */
1467 UINT min, /* [in] minimum message to receive */
1468 UINT max, /* [in] maximum message to receive */
1469 UINT wRemoveMsg /* [in] removal flags */
1472 BOOL ret = MSG_PeekMessage( QMSG_WIN32W, lpmsg, hwnd, min, max, wRemoveMsg, TRUE );
1473 if (ret) HOOK_CallHooksW( WH_GETMESSAGE, HC_ACTION,
1474 wRemoveMsg & PM_REMOVE, (LPARAM)lpmsg );
1475 return ret;
1479 /***********************************************************************
1480 * GetMessage32 (USER.820)
1482 BOOL16 WINAPI GetMessage32_16( SEGPTR msg16_32, HWND16 hWnd, UINT16 first,
1483 UINT16 last, BOOL16 wHaveParamHigh )
1485 MSG32_16 *lpmsg16_32 = MapSL(msg16_32);
1486 MSG msg;
1488 MSG_PeekMessage( QMSG_WIN16, &msg, hWnd, first, last, PM_REMOVE, FALSE );
1490 lpmsg16_32->msg.hwnd = msg.hwnd;
1491 lpmsg16_32->msg.message = msg.message;
1492 lpmsg16_32->msg.wParam = LOWORD(msg.wParam);
1493 lpmsg16_32->msg.lParam = msg.lParam;
1494 lpmsg16_32->msg.time = msg.time;
1495 lpmsg16_32->msg.pt.x = (INT16)msg.pt.x;
1496 lpmsg16_32->msg.pt.y = (INT16)msg.pt.y;
1498 if ( wHaveParamHigh )
1499 lpmsg16_32->wParamHigh = HIWORD(msg.wParam);
1501 TRACE( "message %04x, hwnd %04x, filter(%04x - %04x)\n",
1502 lpmsg16_32->msg.message, hWnd, first, last );
1504 HOOK_CallHooks16( WH_GETMESSAGE, HC_ACTION, PM_REMOVE, (LPARAM)msg16_32 );
1505 return lpmsg16_32->msg.message != WM_QUIT;
1508 /***********************************************************************
1509 * GetMessage (USER.108)
1511 BOOL16 WINAPI GetMessage16( SEGPTR msg, HWND16 hwnd, UINT16 first, UINT16 last)
1513 return GetMessage32_16( msg, hwnd, first, last, FALSE );
1516 /***********************************************************************
1517 * GetMessageA (USER32.@)
1519 BOOL WINAPI GetMessageA( MSG *lpmsg, HWND hwnd, UINT min, UINT max )
1521 MSG_PeekMessage( QMSG_WIN32A, lpmsg, hwnd, min, max, PM_REMOVE, FALSE );
1523 TRACE( "message %04x, hwnd %04x, filter(%04x - %04x)\n",
1524 lpmsg->message, hwnd, min, max );
1526 HOOK_CallHooksA( WH_GETMESSAGE, HC_ACTION, PM_REMOVE, (LPARAM)lpmsg );
1527 return lpmsg->message != WM_QUIT;
1530 /***********************************************************************
1531 * GetMessageW (USER32.@) Retrieve next message
1533 * GetMessage retrieves the next event from the calling thread's
1534 * queue and deposits it in *lpmsg.
1536 * If _hwnd_ is not NULL, only messages for window _hwnd_ and its
1537 * children as specified by IsChild() are retrieved. If _hwnd_ is NULL
1538 * all application messages are retrieved.
1540 * _min_ and _max_ specify the range of messages of interest. If
1541 * min==max==0, no filtering is performed. Useful examples are
1542 * WM_KEYFIRST and WM_KEYLAST to retrieve keyboard input, and
1543 * WM_MOUSEFIRST and WM_MOUSELAST to retrieve mouse input.
1545 * WM_PAINT messages are not removed from the queue; they remain until
1546 * processed. Other messages are removed from the queue.
1548 * RETURNS
1550 * -1 on error, 0 if message is WM_QUIT, nonzero otherwise.
1552 * CONFORMANCE
1554 * ECMA-234, Win32
1557 BOOL WINAPI GetMessageW(
1558 MSG* lpmsg, /* [out] buffer to receive message */
1559 HWND hwnd, /* [in] restrict to messages for hwnd */
1560 UINT min, /* [in] minimum message to receive */
1561 UINT max /* [in] maximum message to receive */
1564 MSG_PeekMessage( QMSG_WIN32W, lpmsg, hwnd, min, max, PM_REMOVE, FALSE );
1566 TRACE( "message %04x, hwnd %04x, filter(%04x - %04x)\n",
1567 lpmsg->message, hwnd, min, max );
1569 HOOK_CallHooksW( WH_GETMESSAGE, HC_ACTION, PM_REMOVE, (LPARAM)lpmsg );
1570 return lpmsg->message != WM_QUIT;
1573 /***********************************************************************
1574 * MSG_PostToQueue
1576 static BOOL MSG_PostToQueue( HQUEUE16 hQueue, int type, HWND hwnd,
1577 UINT message, WPARAM wParam, LPARAM lParam )
1579 MSG msg;
1581 if ( !hQueue ) return FALSE;
1583 msg.hwnd = hwnd;
1584 msg.message = message;
1585 msg.wParam = wParam;
1586 msg.lParam = lParam;
1587 msg.time = GetTickCount();
1588 GetCursorPos(&msg.pt);
1590 return QUEUE_AddMsg( hQueue, type, &msg, 0 );
1593 /***********************************************************************
1594 * MSG_IsPointerMessage
1596 * Check whether this message (may) contain pointers.
1597 * Those messages may not be PostMessage()d or GetMessage()d, but are dropped.
1599 * FIXME: list of pointer messages might be incomplete.
1601 * (We could do a generic !IsBadWritePtr() check, but this would cause too
1602 * much slow down I think. MM20010206)
1604 static BOOL MSG_IsPointerMessage(UINT message, WPARAM wParam, LPARAM lParam) {
1605 switch (message) {
1606 case WM_CREATE:
1607 case WM_NCCREATE:
1608 case WM_COMPAREITEM:
1609 case WM_DELETEITEM:
1610 case WM_MEASUREITEM:
1611 case WM_DRAWITEM:
1612 case WM_GETMINMAXINFO:
1613 case WM_GETTEXT:
1614 case WM_SETTEXT:
1615 case WM_MDICREATE:
1616 case WM_MDIGETACTIVE:
1617 case WM_NCCALCSIZE:
1618 case WM_WINDOWPOSCHANGING:
1619 case WM_WINDOWPOSCHANGED:
1620 case WM_NOTIFY:
1621 case WM_GETDLGCODE:
1622 case WM_WININICHANGE:
1623 case WM_HELP:
1624 case WM_COPYDATA:
1625 case WM_STYLECHANGING:
1626 case WM_STYLECHANGED:
1627 case WM_DROPOBJECT:
1628 case WM_DRAGMOVE:
1629 case WM_DRAGSELECT:
1630 case WM_QUERYDROPOBJECT:
1632 case CB_DIR:
1633 case CB_ADDSTRING:
1634 case CB_INSERTSTRING:
1635 case CB_FINDSTRING:
1636 case CB_FINDSTRINGEXACT:
1637 case CB_SELECTSTRING:
1638 case CB_GETLBTEXT:
1639 case CB_GETDROPPEDCONTROLRECT:
1641 case LB_DIR:
1642 case LB_ADDFILE:
1643 case LB_ADDSTRING:
1644 case LB_INSERTSTRING:
1645 case LB_GETTEXT:
1646 case LB_GETITEMRECT:
1647 case LB_FINDSTRING:
1648 case LB_FINDSTRINGEXACT:
1649 case LB_SELECTSTRING:
1650 case LB_GETSELITEMS:
1651 case LB_SETTABSTOPS:
1653 case EM_REPLACESEL:
1654 case EM_GETSEL:
1655 case EM_GETRECT:
1656 case EM_SETRECT:
1657 case EM_SETRECTNP:
1658 case EM_GETLINE:
1659 case EM_SETTABSTOPS:
1660 return TRUE;
1661 default:
1662 return FALSE;
1666 /***********************************************************************
1667 * MSG_PostMessage
1669 static BOOL MSG_PostMessage( int type, HWND hwnd, UINT message,
1670 WPARAM wParam, LPARAM lParam )
1672 HQUEUE16 hQueue;
1673 WND *wndPtr;
1675 /* See thread on wine-devel around 6.2.2001. Basically posted messages
1676 * that are known to contain pointers are dropped by the Windows 32bit
1677 * PostMessage() with return FALSE; and invalid parameter last error.
1678 * (tested against NT4 by Gerard Patel)
1679 * 16 bit does not care, so we don't either.
1681 if ( (type!=QMSG_WIN16) && MSG_IsPointerMessage(message,wParam,lParam)) {
1682 FIXME("Ignoring posted pointer message 0x%04x to hwnd 0x%04x.\n",
1683 message,hwnd
1685 SetLastError(ERROR_INVALID_PARAMETER);
1686 return FALSE;
1689 if (hwnd == HWND_BROADCAST)
1691 WND *pDesktop = WIN_GetDesktop();
1692 TRACE("HWND_BROADCAST !\n");
1694 for (wndPtr=WIN_LockWndPtr(pDesktop->child); wndPtr; WIN_UpdateWndPtr(&wndPtr,wndPtr->next))
1696 if (wndPtr->dwStyle & WS_POPUP || wndPtr->dwStyle & WS_CAPTION)
1698 TRACE("BROADCAST Message to hWnd=%04x m=%04X w=%04X l=%08lX !\n",
1699 wndPtr->hwndSelf, message, wParam, lParam);
1700 MSG_PostToQueue( wndPtr->hmemTaskQ, type,
1701 wndPtr->hwndSelf, message, wParam, lParam );
1704 WIN_ReleaseDesktop();
1705 TRACE("End of HWND_BROADCAST !\n");
1706 return TRUE;
1709 wndPtr = WIN_FindWndPtr( hwnd );
1710 hQueue = wndPtr? wndPtr->hmemTaskQ : 0;
1711 WIN_ReleaseWndPtr(wndPtr);
1713 return MSG_PostToQueue( hQueue, type, hwnd, message, wParam, lParam );
1716 /***********************************************************************
1717 * PostMessage (USER.110)
1719 BOOL16 WINAPI PostMessage16( HWND16 hwnd, UINT16 message, WPARAM16 wParam,
1720 LPARAM lParam )
1722 return (BOOL16) MSG_PostMessage( QMSG_WIN16, hwnd, message, wParam, lParam );
1725 /***********************************************************************
1726 * PostMessageA (USER32.@)
1728 BOOL WINAPI PostMessageA( HWND hwnd, UINT message, WPARAM wParam,
1729 LPARAM lParam )
1731 return MSG_PostMessage( QMSG_WIN32A, hwnd, message, wParam, lParam );
1734 /***********************************************************************
1735 * PostMessageW (USER32.@)
1737 BOOL WINAPI PostMessageW( HWND hwnd, UINT message, WPARAM wParam,
1738 LPARAM lParam )
1740 return MSG_PostMessage( QMSG_WIN32W, hwnd, message, wParam, lParam );
1743 /***********************************************************************
1744 * PostAppMessage (USER.116)
1745 * PostAppMessage16 (USER32.@)
1747 BOOL16 WINAPI PostAppMessage16( HTASK16 hTask, UINT16 message,
1748 WPARAM16 wParam, LPARAM lParam )
1750 return MSG_PostToQueue( GetTaskQueue16(hTask), QMSG_WIN16,
1751 0, message, wParam, lParam );
1754 /**********************************************************************
1755 * PostThreadMessageA (USER32.@)
1757 BOOL WINAPI PostThreadMessageA( DWORD idThread, UINT message,
1758 WPARAM wParam, LPARAM lParam )
1760 return MSG_PostToQueue( GetThreadQueue16(idThread), QMSG_WIN32A,
1761 0, message, wParam, lParam );
1764 /**********************************************************************
1765 * PostThreadMessageW (USER32.@)
1767 BOOL WINAPI PostThreadMessageW( DWORD idThread, UINT message,
1768 WPARAM wParam, LPARAM lParam )
1770 return MSG_PostToQueue( GetThreadQueue16(idThread), QMSG_WIN32W,
1771 0, message, wParam, lParam );
1775 /************************************************************************
1776 * MSG_CallWndProcHook32
1778 static void MSG_CallWndProcHook( LPMSG pmsg, BOOL bUnicode )
1780 CWPSTRUCT cwp;
1782 cwp.lParam = pmsg->lParam;
1783 cwp.wParam = pmsg->wParam;
1784 cwp.message = pmsg->message;
1785 cwp.hwnd = pmsg->hwnd;
1787 if (bUnicode) HOOK_CallHooksW(WH_CALLWNDPROC, HC_ACTION, 1, (LPARAM)&cwp);
1788 else HOOK_CallHooksA( WH_CALLWNDPROC, HC_ACTION, 1, (LPARAM)&cwp );
1790 pmsg->lParam = cwp.lParam;
1791 pmsg->wParam = cwp.wParam;
1792 pmsg->message = cwp.message;
1793 pmsg->hwnd = cwp.hwnd;
1797 /***********************************************************************
1798 * MSG_SendMessage
1800 * return values: 0 if timeout occurs
1801 * 1 otherwise
1803 static LRESULT MSG_SendMessage( HWND hwnd, UINT msg, WPARAM wParam,
1804 LPARAM lParam, DWORD timeout, WORD flags,
1805 LRESULT *pRes)
1807 WND * wndPtr = 0;
1808 WND **list, **ppWnd;
1809 LRESULT ret = 1;
1811 if (pRes) *pRes = 0;
1813 if (hwnd == HWND_BROADCAST|| hwnd == HWND_TOPMOST)
1815 if (pRes) *pRes = 1;
1817 if (!(list = WIN_BuildWinArray( WIN_GetDesktop(), 0, NULL )))
1819 WIN_ReleaseDesktop();
1820 return 1;
1822 WIN_ReleaseDesktop();
1824 TRACE("HWND_BROADCAST !\n");
1825 for (ppWnd = list; *ppWnd; ppWnd++)
1827 WIN_UpdateWndPtr(&wndPtr,*ppWnd);
1828 if (!IsWindow(wndPtr->hwndSelf)) continue;
1829 if (wndPtr->dwStyle & WS_POPUP || wndPtr->dwStyle & WS_CAPTION)
1831 TRACE("BROADCAST Message to hWnd=%04x m=%04X w=%04lX l=%08lX !\n",
1832 wndPtr->hwndSelf, msg, (DWORD)wParam, lParam);
1833 MSG_SendMessage( wndPtr->hwndSelf, msg, wParam, lParam,
1834 timeout, flags, pRes);
1837 WIN_ReleaseWndPtr(wndPtr);
1838 WIN_ReleaseWinArray(list);
1839 TRACE("End of HWND_BROADCAST !\n");
1840 return 1;
1843 if (HOOK_IsHooked( WH_CALLWNDPROC ))
1845 if (flags & SMSG_UNICODE)
1846 MSG_CallWndProcHook( (LPMSG)&hwnd, TRUE);
1847 else if (flags & SMSG_WIN32)
1848 MSG_CallWndProcHook( (LPMSG)&hwnd, FALSE);
1849 else
1851 LPCWPSTRUCT16 pmsg;
1853 if ((pmsg = SEGPTR_NEW(CWPSTRUCT16)))
1855 pmsg->hwnd = hwnd & 0xffff;
1856 pmsg->message= msg & 0xffff;
1857 pmsg->wParam = wParam & 0xffff;
1858 pmsg->lParam = lParam;
1859 HOOK_CallHooks16( WH_CALLWNDPROC, HC_ACTION, 1,
1860 (LPARAM)SEGPTR_GET(pmsg) );
1861 hwnd = pmsg->hwnd;
1862 msg = pmsg->message;
1863 wParam = pmsg->wParam;
1864 lParam = pmsg->lParam;
1865 SEGPTR_FREE( pmsg );
1870 if (!(wndPtr = WIN_FindWndPtr( hwnd )))
1872 WARN("invalid hwnd %04x\n", hwnd );
1873 return 0;
1875 if (QUEUE_IsExitingQueue(wndPtr->hmemTaskQ))
1877 ret = 0; /* Don't send anything if the task is dying */
1878 goto END;
1880 if (flags & SMSG_WIN32)
1881 SPY_EnterMessage( SPY_SENDMESSAGE, hwnd, msg, wParam, lParam );
1882 else
1883 SPY_EnterMessage( SPY_SENDMESSAGE16, hwnd, msg, wParam, lParam );
1885 if (wndPtr->hmemTaskQ != GetFastQueue16())
1886 ret = MSG_SendMessageInterThread( wndPtr->hmemTaskQ, hwnd, msg,
1887 wParam, lParam, timeout, flags, pRes );
1888 else
1890 LRESULT res;
1892 /* Call the right CallWindowProc flavor */
1893 if (flags & SMSG_UNICODE)
1894 res = CallWindowProcW( (WNDPROC)wndPtr->winproc,
1895 hwnd, msg, wParam, lParam );
1896 else if (flags & SMSG_WIN32)
1897 res = CallWindowProcA( (WNDPROC)wndPtr->winproc,
1898 hwnd, msg, wParam, lParam );
1899 else
1900 res = CallWindowProc16( (WNDPROC16)wndPtr->winproc,
1901 (HWND16) hwnd, (UINT16) msg,
1902 (WPARAM16) wParam, lParam );
1903 if (pRes) *pRes = res;
1906 if (flags & SMSG_WIN32)
1907 SPY_ExitMessage( SPY_RESULT_OK, hwnd, msg, pRes?*pRes:0, wParam, lParam );
1908 else
1909 SPY_ExitMessage( SPY_RESULT_OK16, hwnd, msg, pRes?*pRes:0, wParam, lParam );
1910 END:
1911 WIN_ReleaseWndPtr(wndPtr);
1912 return ret;
1916 /***********************************************************************
1917 * SendMessage (USER.111)
1919 LRESULT WINAPI SendMessage16( HWND16 hwnd, UINT16 msg, WPARAM16 wParam,
1920 LPARAM lParam)
1922 LRESULT res;
1923 MSG_SendMessage(hwnd, msg, wParam, lParam, INFINITE, 0, &res);
1924 return res;
1928 /***********************************************************************
1929 * SendMessageA (USER32.@)
1931 LRESULT WINAPI SendMessageA( HWND hwnd, UINT msg, WPARAM wParam,
1932 LPARAM lParam )
1934 LRESULT res;
1936 MSG_SendMessage(hwnd, msg, wParam, lParam, INFINITE,
1937 SMSG_WIN32, &res);
1939 return res;
1943 /***********************************************************************
1944 * SendMessageW (USER32.@) Send Window Message
1946 * Sends a message to the window procedure of the specified window.
1947 * SendMessage() will not return until the called window procedure
1948 * either returns or calls ReplyMessage().
1950 * Use PostMessage() to send message and return immediately. A window
1951 * procedure may use InSendMessage() to detect
1952 * SendMessage()-originated messages.
1954 * Applications which communicate via HWND_BROADCAST may use
1955 * RegisterWindowMessage() to obtain a unique message to avoid conflicts
1956 * with other applications.
1958 * CONFORMANCE
1960 * ECMA-234, Win32
1962 LRESULT WINAPI SendMessageW(
1963 HWND hwnd, /* [in] Window to send message to. If HWND_BROADCAST,
1964 the message will be sent to all top-level windows. */
1966 UINT msg, /* [in] message */
1967 WPARAM wParam, /* [in] message parameter */
1968 LPARAM lParam /* [in] additional message parameter */
1970 LRESULT res;
1972 MSG_SendMessage(hwnd, msg, wParam, lParam, INFINITE,
1973 SMSG_WIN32 | SMSG_UNICODE, &res);
1975 return res;
1979 /***********************************************************************
1980 * SendMessageTimeout (not a WINAPI)
1982 LRESULT WINAPI SendMessageTimeout16( HWND16 hwnd, UINT16 msg, WPARAM16 wParam,
1983 LPARAM lParam, UINT16 flags,
1984 UINT16 timeout, LPWORD resultp)
1986 LRESULT ret;
1987 LRESULT msgRet;
1989 /* FIXME: need support for SMTO_BLOCK */
1991 ret = MSG_SendMessage(hwnd, msg, wParam, lParam, timeout, 0, &msgRet);
1992 if (resultp) *resultp = (WORD) msgRet;
1993 return ret;
1997 /***********************************************************************
1998 * SendMessageTimeoutA (USER32.@)
2000 LRESULT WINAPI SendMessageTimeoutA( HWND hwnd, UINT msg, WPARAM wParam,
2001 LPARAM lParam, UINT flags,
2002 UINT timeout, LPDWORD resultp)
2004 LRESULT ret;
2005 LRESULT msgRet;
2007 /* FIXME: need support for SMTO_BLOCK */
2009 ret = MSG_SendMessage(hwnd, msg, wParam, lParam, timeout, SMSG_WIN32,
2010 &msgRet);
2012 if (resultp) *resultp = (DWORD) msgRet;
2013 return ret;
2017 /***********************************************************************
2018 * SendMessageTimeoutW (USER32.@)
2020 LRESULT WINAPI SendMessageTimeoutW( HWND hwnd, UINT msg, WPARAM wParam,
2021 LPARAM lParam, UINT flags,
2022 UINT timeout, LPDWORD resultp)
2024 LRESULT ret;
2025 LRESULT msgRet;
2027 /* FIXME: need support for SMTO_BLOCK */
2029 ret = MSG_SendMessage(hwnd, msg, wParam, lParam, timeout,
2030 SMSG_WIN32 | SMSG_UNICODE, &msgRet);
2032 if (resultp) *resultp = (DWORD) msgRet;
2033 return ret;
2037 /***********************************************************************
2038 * WaitMessage (USER.112) (USER32.@) Suspend thread pending messages
2040 * WaitMessage() suspends a thread until events appear in the thread's
2041 * queue.
2043 * BUGS
2045 * Is supposed to return BOOL under Win32.
2047 * Thread-local message queues are not supported.
2049 * CONFORMANCE
2051 * ECMA-234, Win32
2054 void WINAPI WaitMessage( void )
2056 QUEUE_WaitBits( QS_ALLINPUT, INFINITE );
2059 /***********************************************************************
2060 * MsgWaitForMultipleObjects (USER32.@)
2062 DWORD WINAPI MsgWaitForMultipleObjects( DWORD nCount, HANDLE *pHandles,
2063 BOOL fWaitAll, DWORD dwMilliseconds,
2064 DWORD dwWakeMask )
2066 DWORD i;
2067 HANDLE handles[MAXIMUM_WAIT_OBJECTS];
2068 DWORD ret;
2070 HQUEUE16 hQueue = GetFastQueue16();
2071 MESSAGEQUEUE *msgQueue = QUEUE_Lock( hQueue );
2072 if (!msgQueue) return WAIT_FAILED;
2074 if (nCount > MAXIMUM_WAIT_OBJECTS-1)
2076 SetLastError( ERROR_INVALID_PARAMETER );
2077 QUEUE_Unlock( msgQueue );
2078 return WAIT_FAILED;
2081 EnterCriticalSection( &msgQueue->cSection );
2082 msgQueue->changeBits = 0;
2083 msgQueue->wakeMask = dwWakeMask;
2084 LeaveCriticalSection( &msgQueue->cSection );
2086 if (THREAD_IsWin16(NtCurrentTeb()))
2089 * This is a temporary solution to a big problem.
2090 * You see, the main thread of all Win32 programs is created as a 16 bit
2091 * task. This means that if you wait on an event using Win32 synchronization
2092 * methods, the 16 bit scheduler is stopped and things might just stop happening.
2093 * This implements a semi-busy loop that checks the handles to wait on and
2094 * also the message queue. When either one is ready, the wait function returns.
2096 * This will all go away when the real Win32 threads are implemented for all
2097 * the threads of an applications. Including the main thread.
2099 DWORD curTime = GetCurrentTime();
2104 * Check the handles in the list.
2106 ret = WaitForMultipleObjects(nCount, pHandles, fWaitAll, 5L);
2109 * If the handles have been triggered, return.
2111 if (ret != WAIT_TIMEOUT)
2112 break;
2115 * Then, let the 16 bit scheduler do it's thing.
2117 K32WOWYield16();
2120 * If a message matching the wait mask has arrived, return.
2122 EnterCriticalSection( &msgQueue->cSection );
2123 if (msgQueue->changeBits & dwWakeMask)
2125 LeaveCriticalSection( &msgQueue->cSection );
2126 ret = nCount;
2127 break;
2129 LeaveCriticalSection( &msgQueue->cSection );
2132 * And continue doing this until we hit the timeout.
2134 } while ((dwMilliseconds == INFINITE) || (GetCurrentTime()-curTime < dwMilliseconds) );
2136 else
2138 /* Add the thread event to the handle list */
2139 for (i = 0; i < nCount; i++)
2140 handles[i] = pHandles[i];
2141 handles[nCount] = msgQueue->server_queue;
2142 ret = WaitForMultipleObjects( nCount+1, handles, fWaitAll, dwMilliseconds );
2144 QUEUE_Unlock( msgQueue );
2145 return ret;
2148 /***********************************************************************
2149 * MsgWaitForMultipleObjects (USER.640)
2151 DWORD WINAPI MsgWaitForMultipleObjects16( DWORD nCount, HANDLE *pHandles,
2152 BOOL fWaitAll, DWORD dwMilliseconds,
2153 DWORD dwWakeMask )
2155 TRACE("(%lu,%p,%u,%lu,0x%lx)\n",
2156 nCount, pHandles, fWaitAll, dwMilliseconds, dwWakeMask);
2157 return MsgWaitForMultipleObjects(nCount, pHandles, fWaitAll, dwMilliseconds, dwWakeMask);
2160 struct accent_char
2162 BYTE ac_accent;
2163 BYTE ac_char;
2164 BYTE ac_result;
2167 static const struct accent_char accent_chars[] =
2169 /* A good idea should be to read /usr/X11/lib/X11/locale/iso8859-x/Compose */
2170 {'`', 'A', '\300'}, {'`', 'a', '\340'},
2171 {'\'', 'A', '\301'}, {'\'', 'a', '\341'},
2172 {'^', 'A', '\302'}, {'^', 'a', '\342'},
2173 {'~', 'A', '\303'}, {'~', 'a', '\343'},
2174 {'"', 'A', '\304'}, {'"', 'a', '\344'},
2175 {'O', 'A', '\305'}, {'o', 'a', '\345'},
2176 {'0', 'A', '\305'}, {'0', 'a', '\345'},
2177 {'A', 'A', '\305'}, {'a', 'a', '\345'},
2178 {'A', 'E', '\306'}, {'a', 'e', '\346'},
2179 {',', 'C', '\307'}, {',', 'c', '\347'},
2180 {'`', 'E', '\310'}, {'`', 'e', '\350'},
2181 {'\'', 'E', '\311'}, {'\'', 'e', '\351'},
2182 {'^', 'E', '\312'}, {'^', 'e', '\352'},
2183 {'"', 'E', '\313'}, {'"', 'e', '\353'},
2184 {'`', 'I', '\314'}, {'`', 'i', '\354'},
2185 {'\'', 'I', '\315'}, {'\'', 'i', '\355'},
2186 {'^', 'I', '\316'}, {'^', 'i', '\356'},
2187 {'"', 'I', '\317'}, {'"', 'i', '\357'},
2188 {'-', 'D', '\320'}, {'-', 'd', '\360'},
2189 {'~', 'N', '\321'}, {'~', 'n', '\361'},
2190 {'`', 'O', '\322'}, {'`', 'o', '\362'},
2191 {'\'', 'O', '\323'}, {'\'', 'o', '\363'},
2192 {'^', 'O', '\324'}, {'^', 'o', '\364'},
2193 {'~', 'O', '\325'}, {'~', 'o', '\365'},
2194 {'"', 'O', '\326'}, {'"', 'o', '\366'},
2195 {'/', 'O', '\330'}, {'/', 'o', '\370'},
2196 {'`', 'U', '\331'}, {'`', 'u', '\371'},
2197 {'\'', 'U', '\332'}, {'\'', 'u', '\372'},
2198 {'^', 'U', '\333'}, {'^', 'u', '\373'},
2199 {'"', 'U', '\334'}, {'"', 'u', '\374'},
2200 {'\'', 'Y', '\335'}, {'\'', 'y', '\375'},
2201 {'T', 'H', '\336'}, {'t', 'h', '\376'},
2202 {'s', 's', '\337'}, {'"', 'y', '\377'},
2203 {'s', 'z', '\337'}, {'i', 'j', '\377'},
2204 /* iso-8859-2 uses this */
2205 {'<', 'L', '\245'}, {'<', 'l', '\265'}, /* caron */
2206 {'<', 'S', '\251'}, {'<', 's', '\271'},
2207 {'<', 'T', '\253'}, {'<', 't', '\273'},
2208 {'<', 'Z', '\256'}, {'<', 'z', '\276'},
2209 {'<', 'C', '\310'}, {'<', 'c', '\350'},
2210 {'<', 'E', '\314'}, {'<', 'e', '\354'},
2211 {'<', 'D', '\317'}, {'<', 'd', '\357'},
2212 {'<', 'N', '\322'}, {'<', 'n', '\362'},
2213 {'<', 'R', '\330'}, {'<', 'r', '\370'},
2214 {';', 'A', '\241'}, {';', 'a', '\261'}, /* ogonek */
2215 {';', 'E', '\312'}, {';', 'e', '\332'},
2216 {'\'', 'Z', '\254'}, {'\'', 'z', '\274'}, /* acute */
2217 {'\'', 'R', '\300'}, {'\'', 'r', '\340'},
2218 {'\'', 'L', '\305'}, {'\'', 'l', '\345'},
2219 {'\'', 'C', '\306'}, {'\'', 'c', '\346'},
2220 {'\'', 'N', '\321'}, {'\'', 'n', '\361'},
2221 /* collision whith S, from iso-8859-9 !!! */
2222 {',', 'S', '\252'}, {',', 's', '\272'}, /* cedilla */
2223 {',', 'T', '\336'}, {',', 't', '\376'},
2224 {'.', 'Z', '\257'}, {'.', 'z', '\277'}, /* dot above */
2225 {'/', 'L', '\243'}, {'/', 'l', '\263'}, /* slash */
2226 {'/', 'D', '\320'}, {'/', 'd', '\360'},
2227 {'(', 'A', '\303'}, {'(', 'a', '\343'}, /* breve */
2228 {'\275', 'O', '\325'}, {'\275', 'o', '\365'}, /* double acute */
2229 {'\275', 'U', '\334'}, {'\275', 'u', '\374'},
2230 {'0', 'U', '\332'}, {'0', 'u', '\372'}, /* ring above */
2231 /* iso-8859-3 uses this */
2232 {'/', 'H', '\241'}, {'/', 'h', '\261'}, /* slash */
2233 {'>', 'H', '\246'}, {'>', 'h', '\266'}, /* circumflex */
2234 {'>', 'J', '\254'}, {'>', 'j', '\274'},
2235 {'>', 'C', '\306'}, {'>', 'c', '\346'},
2236 {'>', 'G', '\330'}, {'>', 'g', '\370'},
2237 {'>', 'S', '\336'}, {'>', 's', '\376'},
2238 /* collision whith G( from iso-8859-9 !!! */
2239 {'(', 'G', '\253'}, {'(', 'g', '\273'}, /* breve */
2240 {'(', 'U', '\335'}, {'(', 'u', '\375'},
2241 /* collision whith I. from iso-8859-3 !!! */
2242 {'.', 'I', '\251'}, {'.', 'i', '\271'}, /* dot above */
2243 {'.', 'C', '\305'}, {'.', 'c', '\345'},
2244 {'.', 'G', '\325'}, {'.', 'g', '\365'},
2245 /* iso-8859-4 uses this */
2246 {',', 'R', '\243'}, {',', 'r', '\263'}, /* cedilla */
2247 {',', 'L', '\246'}, {',', 'l', '\266'},
2248 {',', 'G', '\253'}, {',', 'g', '\273'},
2249 {',', 'N', '\321'}, {',', 'n', '\361'},
2250 {',', 'K', '\323'}, {',', 'k', '\363'},
2251 {'~', 'I', '\245'}, {'~', 'i', '\265'}, /* tilde */
2252 {'-', 'E', '\252'}, {'-', 'e', '\272'}, /* macron */
2253 {'-', 'A', '\300'}, {'-', 'a', '\340'},
2254 {'-', 'I', '\317'}, {'-', 'i', '\357'},
2255 {'-', 'O', '\322'}, {'-', 'o', '\362'},
2256 {'-', 'U', '\336'}, {'-', 'u', '\376'},
2257 {'/', 'T', '\254'}, {'/', 't', '\274'}, /* slash */
2258 {'.', 'E', '\314'}, {'.', 'e', '\344'}, /* dot above */
2259 {';', 'I', '\307'}, {';', 'i', '\347'}, /* ogonek */
2260 {';', 'U', '\331'}, {';', 'u', '\371'},
2261 /* iso-8859-9 uses this */
2262 /* iso-8859-9 has really bad choosen G( S, and I. as they collide
2263 * whith the same letters on other iso-8859-x (that is they are on
2264 * different places :-( ), if you use turkish uncomment these and
2265 * comment out the lines in iso-8859-2 and iso-8859-3 sections
2266 * FIXME: should be dynamic according to chosen language
2267 * if/when Wine has turkish support.
2269 /* collision whith G( from iso-8859-3 !!! */
2270 /* {'(', 'G', '\320'}, {'(', 'g', '\360'}, */ /* breve */
2271 /* collision whith S, from iso-8859-2 !!! */
2272 /* {',', 'S', '\336'}, {',', 's', '\376'}, */ /* cedilla */
2273 /* collision whith I. from iso-8859-3 !!! */
2274 /* {'.', 'I', '\335'}, {'.', 'i', '\375'}, */ /* dot above */
2278 /***********************************************************************
2279 * MSG_DoTranslateMessage
2281 * Implementation of TranslateMessage.
2283 * TranslateMessage translates virtual-key messages into character-messages,
2284 * as follows :
2285 * WM_KEYDOWN/WM_KEYUP combinations produce a WM_CHAR or WM_DEADCHAR message.
2286 * ditto replacing WM_* with WM_SYS*
2287 * This produces WM_CHAR messages only for keys mapped to ASCII characters
2288 * by the keyboard driver.
2290 static BOOL MSG_DoTranslateMessage( UINT message, HWND hwnd,
2291 WPARAM wParam, LPARAM lParam )
2293 static int dead_char;
2294 WCHAR wp[2];
2296 if (message != WM_MOUSEMOVE && message != WM_TIMER)
2297 TRACE("(%s, %04X, %08lX)\n",
2298 SPY_GetMsgName(message), wParam, lParam );
2299 if(message >= WM_KEYFIRST && message <= WM_KEYLAST)
2300 TRACE_(key)("(%s, %04X, %08lX)\n",
2301 SPY_GetMsgName(message), wParam, lParam );
2303 if ((message != WM_KEYDOWN) && (message != WM_SYSKEYDOWN)) return FALSE;
2305 TRACE_(key)("Translating key %s (%04x), scancode %02x\n",
2306 SPY_GetVKeyName(wParam), wParam, LOBYTE(HIWORD(lParam)));
2308 /* FIXME : should handle ToUnicode yielding 2 */
2309 switch (ToUnicode(wParam, HIWORD(lParam), QueueKeyStateTable, wp, 2, 0))
2311 case 1:
2312 message = (message == WM_KEYDOWN) ? WM_CHAR : WM_SYSCHAR;
2313 /* Should dead chars handling go in ToAscii ? */
2314 if (dead_char)
2316 int i;
2318 if (wp[0] == ' ') wp[0] = dead_char;
2319 if (dead_char == 0xa2) dead_char = '(';
2320 else if (dead_char == 0xa8) dead_char = '"';
2321 else if (dead_char == 0xb2) dead_char = ';';
2322 else if (dead_char == 0xb4) dead_char = '\'';
2323 else if (dead_char == 0xb7) dead_char = '<';
2324 else if (dead_char == 0xb8) dead_char = ',';
2325 else if (dead_char == 0xff) dead_char = '.';
2326 for (i = 0; i < sizeof(accent_chars)/sizeof(accent_chars[0]); i++)
2327 if ((accent_chars[i].ac_accent == dead_char) &&
2328 (accent_chars[i].ac_char == wp[0]))
2330 wp[0] = accent_chars[i].ac_result;
2331 break;
2333 dead_char = 0;
2335 TRACE_(key)("1 -> PostMessage(%s)\n", SPY_GetMsgName(message));
2336 PostMessageW( hwnd, message, wp[0], lParam );
2337 return TRUE;
2339 case -1:
2340 message = (message == WM_KEYDOWN) ? WM_DEADCHAR : WM_SYSDEADCHAR;
2341 dead_char = wp[0];
2342 TRACE_(key)("-1 -> PostMessage(%s)\n", SPY_GetMsgName(message));
2343 PostMessageW( hwnd, message, wp[0], lParam );
2344 return TRUE;
2346 return FALSE;
2350 /***********************************************************************
2351 * TranslateMessage (USER.113)
2353 BOOL16 WINAPI TranslateMessage16( const MSG16 *msg )
2355 return MSG_DoTranslateMessage( msg->message, msg->hwnd,
2356 msg->wParam, msg->lParam );
2360 /***********************************************************************
2361 * TranslateMessage32 (USER.821)
2363 BOOL16 WINAPI TranslateMessage32_16( const MSG32_16 *msg, BOOL16 wHaveParamHigh )
2365 WPARAM wParam;
2367 if (wHaveParamHigh)
2368 wParam = MAKELONG(msg->msg.wParam, msg->wParamHigh);
2369 else
2370 wParam = (WPARAM)msg->msg.wParam;
2372 return MSG_DoTranslateMessage( msg->msg.message, msg->msg.hwnd,
2373 wParam, msg->msg.lParam );
2376 /***********************************************************************
2377 * TranslateMessage (USER32.@)
2379 BOOL WINAPI TranslateMessage( const MSG *msg )
2381 return MSG_DoTranslateMessage( msg->message, msg->hwnd,
2382 msg->wParam, msg->lParam );
2386 /***********************************************************************
2387 * DispatchMessage (USER.114)
2389 LONG WINAPI DispatchMessage16( const MSG16* msg )
2391 WND * wndPtr;
2392 LONG retval;
2393 int painting;
2395 /* Process timer messages */
2396 if ((msg->message == WM_TIMER) || (msg->message == WM_SYSTIMER))
2398 if (msg->lParam)
2400 /* before calling window proc, verify whether timer is still valid;
2401 there's a slim chance that the application kills the timer
2402 between GetMessage and DispatchMessage API calls */
2403 if (!TIMER_IsTimerValid(msg->hwnd, (UINT) msg->wParam, (HWINDOWPROC) msg->lParam))
2404 return 0; /* invalid winproc */
2406 return CallWindowProc16( (WNDPROC16)msg->lParam, msg->hwnd,
2407 msg->message, msg->wParam, GetTickCount() );
2411 if (!msg->hwnd) return 0;
2412 if (!(wndPtr = WIN_FindWndPtr( msg->hwnd ))) return 0;
2413 if (!wndPtr->winproc)
2415 retval = 0;
2416 goto END;
2418 painting = (msg->message == WM_PAINT);
2419 if (painting) wndPtr->flags |= WIN_NEEDS_BEGINPAINT;
2421 SPY_EnterMessage( SPY_DISPATCHMESSAGE16, msg->hwnd, msg->message,
2422 msg->wParam, msg->lParam );
2423 retval = CallWindowProc16( (WNDPROC16)wndPtr->winproc,
2424 msg->hwnd, msg->message,
2425 msg->wParam, msg->lParam );
2426 SPY_ExitMessage( SPY_RESULT_OK16, msg->hwnd, msg->message, retval,
2427 msg->wParam, msg->lParam );
2429 WIN_ReleaseWndPtr(wndPtr);
2430 wndPtr = WIN_FindWndPtr(msg->hwnd);
2431 if (painting && wndPtr &&
2432 (wndPtr->flags & WIN_NEEDS_BEGINPAINT) && wndPtr->hrgnUpdate)
2434 ERR("BeginPaint not called on WM_PAINT for hwnd %04x!\n",
2435 msg->hwnd);
2436 wndPtr->flags &= ~WIN_NEEDS_BEGINPAINT;
2437 /* Validate the update region to avoid infinite WM_PAINT loop */
2438 ValidateRect( msg->hwnd, NULL );
2440 END:
2441 WIN_ReleaseWndPtr(wndPtr);
2442 return retval;
2446 /***********************************************************************
2447 * DispatchMessage32 (USER.822)
2449 LONG WINAPI DispatchMessage32_16( const MSG32_16* lpmsg16_32, BOOL16 wHaveParamHigh )
2451 if (wHaveParamHigh == FALSE)
2452 return DispatchMessage16(&(lpmsg16_32->msg));
2453 else
2455 MSG msg;
2457 msg.hwnd = lpmsg16_32->msg.hwnd;
2458 msg.message = lpmsg16_32->msg.message;
2459 msg.wParam = MAKELONG(lpmsg16_32->msg.wParam, lpmsg16_32->wParamHigh);
2460 msg.lParam = lpmsg16_32->msg.lParam;
2461 msg.time = lpmsg16_32->msg.time;
2462 msg.pt.x = (INT)lpmsg16_32->msg.pt.x;
2463 msg.pt.y = (INT)lpmsg16_32->msg.pt.y;
2464 return DispatchMessageA(&msg);
2468 /***********************************************************************
2469 * DispatchMessageA (USER32.@)
2471 LONG WINAPI DispatchMessageA( const MSG* msg )
2473 WND * wndPtr;
2474 LONG retval;
2475 int painting;
2477 /* Process timer messages */
2478 if ((msg->message == WM_TIMER) || (msg->message == WM_SYSTIMER))
2480 if (msg->lParam)
2482 /* HOOK_CallHooks32A( WH_CALLWNDPROC, HC_ACTION, 0, FIXME ); */
2484 /* before calling window proc, verify whether timer is still valid;
2485 there's a slim chance that the application kills the timer
2486 between GetMessage and DispatchMessage API calls */
2487 if (!TIMER_IsTimerValid(msg->hwnd, (UINT) msg->wParam, (HWINDOWPROC) msg->lParam))
2488 return 0; /* invalid winproc */
2490 return CallWindowProcA( (WNDPROC)msg->lParam, msg->hwnd,
2491 msg->message, msg->wParam, GetTickCount() );
2495 if (!msg->hwnd) return 0;
2496 if (!(wndPtr = WIN_FindWndPtr( msg->hwnd ))) return 0;
2497 if (!wndPtr->winproc)
2499 retval = 0;
2500 goto END;
2502 painting = (msg->message == WM_PAINT);
2503 if (painting) wndPtr->flags |= WIN_NEEDS_BEGINPAINT;
2504 /* HOOK_CallHooks32A( WH_CALLWNDPROC, HC_ACTION, 0, FIXME ); */
2506 SPY_EnterMessage( SPY_DISPATCHMESSAGE, msg->hwnd, msg->message,
2507 msg->wParam, msg->lParam );
2508 retval = CallWindowProcA( (WNDPROC)wndPtr->winproc,
2509 msg->hwnd, msg->message,
2510 msg->wParam, msg->lParam );
2511 SPY_ExitMessage( SPY_RESULT_OK, msg->hwnd, msg->message, retval,
2512 msg->wParam, msg->lParam );
2514 WIN_ReleaseWndPtr(wndPtr);
2515 wndPtr = WIN_FindWndPtr(msg->hwnd);
2517 if (painting && wndPtr &&
2518 (wndPtr->flags & WIN_NEEDS_BEGINPAINT) && wndPtr->hrgnUpdate)
2520 ERR("BeginPaint not called on WM_PAINT for hwnd %04x!\n",
2521 msg->hwnd);
2522 wndPtr->flags &= ~WIN_NEEDS_BEGINPAINT;
2523 /* Validate the update region to avoid infinite WM_PAINT loop */
2524 PAINT_RedrawWindow( wndPtr->hwndSelf, NULL, 0,
2525 RDW_FRAME | RDW_VALIDATE | RDW_NOCHILDREN | RDW_NOINTERNALPAINT, 0 );
2527 END:
2528 WIN_ReleaseWndPtr(wndPtr);
2529 return retval;
2533 /***********************************************************************
2534 * DispatchMessageW (USER32.@) Process Message
2536 * Process the message specified in the structure *_msg_.
2538 * If the lpMsg parameter points to a WM_TIMER message and the
2539 * parameter of the WM_TIMER message is not NULL, the lParam parameter
2540 * points to the function that is called instead of the window
2541 * procedure.
2543 * The message must be valid.
2545 * RETURNS
2547 * DispatchMessage() returns the result of the window procedure invoked.
2549 * CONFORMANCE
2551 * ECMA-234, Win32
2554 LONG WINAPI DispatchMessageW( const MSG* msg )
2556 WND * wndPtr;
2557 LONG retval;
2558 int painting;
2560 /* Process timer messages */
2561 if ((msg->message == WM_TIMER) || (msg->message == WM_SYSTIMER))
2563 if (msg->lParam)
2565 /* HOOK_CallHooks32W( WH_CALLWNDPROC, HC_ACTION, 0, FIXME ); */
2567 /* before calling window proc, verify whether timer is still valid;
2568 there's a slim chance that the application kills the timer
2569 between GetMessage and DispatchMessage API calls */
2570 if (!TIMER_IsTimerValid(msg->hwnd, (UINT) msg->wParam, (HWINDOWPROC) msg->lParam))
2571 return 0; /* invalid winproc */
2573 return CallWindowProcW( (WNDPROC)msg->lParam, msg->hwnd,
2574 msg->message, msg->wParam, GetTickCount() );
2578 if (!msg->hwnd) return 0;
2579 if (!(wndPtr = WIN_FindWndPtr( msg->hwnd ))) return 0;
2580 if (!wndPtr->winproc)
2582 retval = 0;
2583 goto END;
2585 painting = (msg->message == WM_PAINT);
2586 if (painting) wndPtr->flags |= WIN_NEEDS_BEGINPAINT;
2587 /* HOOK_CallHooks32W( WH_CALLWNDPROC, HC_ACTION, 0, FIXME ); */
2589 SPY_EnterMessage( SPY_DISPATCHMESSAGE, msg->hwnd, msg->message,
2590 msg->wParam, msg->lParam );
2591 retval = CallWindowProcW( (WNDPROC)wndPtr->winproc,
2592 msg->hwnd, msg->message,
2593 msg->wParam, msg->lParam );
2594 SPY_ExitMessage( SPY_RESULT_OK, msg->hwnd, msg->message, retval,
2595 msg->wParam, msg->lParam );
2597 WIN_ReleaseWndPtr(wndPtr);
2598 wndPtr = WIN_FindWndPtr(msg->hwnd);
2600 if (painting && wndPtr &&
2601 (wndPtr->flags & WIN_NEEDS_BEGINPAINT) && wndPtr->hrgnUpdate)
2603 ERR("BeginPaint not called on WM_PAINT for hwnd %04x!\n",
2604 msg->hwnd);
2605 wndPtr->flags &= ~WIN_NEEDS_BEGINPAINT;
2606 /* Validate the update region to avoid infinite WM_PAINT loop */
2607 ValidateRect( msg->hwnd, NULL );
2609 END:
2610 WIN_ReleaseWndPtr(wndPtr);
2611 return retval;
2615 /***********************************************************************
2616 * RegisterWindowMessage (USER.118)
2617 * RegisterWindowMessageA (USER32.@)
2619 WORD WINAPI RegisterWindowMessageA( LPCSTR str )
2621 TRACE("%s\n", str );
2622 return GlobalAddAtomA( str );
2626 /***********************************************************************
2627 * RegisterWindowMessageW (USER32.@)
2629 WORD WINAPI RegisterWindowMessageW( LPCWSTR str )
2631 TRACE("%p\n", str );
2632 return GlobalAddAtomW( str );
2636 /***********************************************************************
2637 * GetCurrentTime (USER.15)
2639 * (effectively identical to GetTickCount)
2641 DWORD WINAPI GetCurrentTime16(void)
2643 return GetTickCount();
2647 /***********************************************************************
2648 * InSendMessage (USER.192)
2650 BOOL16 WINAPI InSendMessage16(void)
2652 return InSendMessage();
2656 /***********************************************************************
2657 * InSendMessage (USER32.@)
2659 BOOL WINAPI InSendMessage(void)
2661 MESSAGEQUEUE *queue;
2662 BOOL ret;
2664 if (!(queue = QUEUE_Lock( GetFastQueue16() )))
2665 return 0;
2666 ret = (BOOL)queue->smWaiting;
2668 QUEUE_Unlock( queue );
2669 return ret;
2672 /***********************************************************************
2673 * BroadcastSystemMessage (USER32.@)
2675 LONG WINAPI BroadcastSystemMessage(
2676 DWORD dwFlags,LPDWORD recipients,UINT uMessage,WPARAM wParam,
2677 LPARAM lParam
2679 FIXME_(sendmsg)("(%08lx,%08lx,%08x,%08x,%08lx): stub!\n",
2680 dwFlags,*recipients,uMessage,wParam,lParam
2682 return 0;
2685 /***********************************************************************
2686 * SendNotifyMessageA (USER32.@)
2688 BOOL WINAPI SendNotifyMessageA(HWND hwnd,UINT msg,WPARAM wParam,LPARAM lParam)
2690 return MSG_SendMessage(hwnd, msg, wParam, lParam, INFINITE,
2691 SMSG_WIN32, NULL);
2694 /***********************************************************************
2695 * SendNotifyMessageW (USER32.@)
2697 BOOL WINAPI SendNotifyMessageW(HWND hwnd,UINT msg,WPARAM wParam,LPARAM lParam)
2699 return MSG_SendMessage(hwnd, msg, wParam, lParam, INFINITE,
2700 SMSG_WIN32 | SMSG_UNICODE, NULL);
2703 /***********************************************************************
2704 * SendMessageCallbackA (USER32.@)
2705 * FIXME: It's like PostMessage. The callback gets called when the message
2706 * is processed. We have to modify the message processing for an exact
2707 * implementation...
2708 * The callback is only called when the thread that called us calls one of
2709 * Get/Peek/WaitMessage.
2711 BOOL WINAPI SendMessageCallbackA(
2712 HWND hWnd,UINT Msg,WPARAM wParam,LPARAM lParam,
2713 FARPROC lpResultCallBack,DWORD dwData)
2715 FIXME("(0x%04x,0x%04x,0x%08x,0x%08lx,%p,0x%08lx),stub!\n",
2716 hWnd,Msg,wParam,lParam,lpResultCallBack,dwData);
2717 if ( hWnd == HWND_BROADCAST)
2718 { PostMessageA( hWnd, Msg, wParam, lParam);
2719 FIXME("Broadcast: Callback will not be called!\n");
2720 return TRUE;
2722 (lpResultCallBack)( hWnd, Msg, dwData, SendMessageA ( hWnd, Msg, wParam, lParam ));
2723 return TRUE;
2725 /***********************************************************************
2726 * SendMessageCallbackW (USER32.@)
2727 * FIXME: see SendMessageCallbackA.
2729 BOOL WINAPI SendMessageCallbackW(
2730 HWND hWnd,UINT Msg,WPARAM wParam,LPARAM lParam,
2731 FARPROC lpResultCallBack,DWORD dwData)
2733 FIXME("(0x%04x,0x%04x,0x%08x,0x%08lx,%p,0x%08lx),stub!\n",
2734 hWnd,Msg,wParam,lParam,lpResultCallBack,dwData);
2735 if ( hWnd == HWND_BROADCAST)
2736 { PostMessageW( hWnd, Msg, wParam, lParam);
2737 FIXME("Broadcast: Callback will not be called!\n");
2738 return TRUE;
2740 (lpResultCallBack)( hWnd, Msg, dwData, SendMessageA ( hWnd, Msg, wParam, lParam ));
2741 return TRUE;