- Minor API files fixes
[wine/multimedia.git] / windows / message.c
blob6c20ccc854b8e2d30a7aa938061bb424a08bbcd0
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 = (EVENTMSG *) HeapAlloc(SystemHeap, 0, sizeof(EVENTMSG));
458 if (!event) return;
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 );
488 HeapFree(SystemHeap, 0, event);
491 /***********************************************************************
492 * MSG_JournalPlayBackMsg
494 * Get an EVENTMSG struct via call JOURNALPLAYBACK hook function
496 static int MSG_JournalPlayBackMsg(void)
498 EVENTMSG *tmpMsg;
499 long wtime,lParam,wParam;
500 WORD keyDown,i,result=0;
502 if ( HOOK_IsHooked( WH_JOURNALPLAYBACK ) )
504 tmpMsg = (EVENTMSG *) HeapAlloc(SystemHeap, 0, sizeof(EVENTMSG));
505 if (!tmpMsg) return result;
507 wtime=HOOK_CallHooksA( WH_JOURNALPLAYBACK, HC_GETNEXT, 0,
508 (LPARAM) tmpMsg );
509 /* TRACE(msg,"Playback wait time =%ld\n",wtime); */
510 if (wtime<=0)
512 wtime=0;
513 if ((tmpMsg->message >= WM_KEYFIRST) && (tmpMsg->message <= WM_KEYLAST))
515 wParam=tmpMsg->paramL & 0xFF;
516 lParam=MAKELONG(tmpMsg->paramH&0x7ffff,tmpMsg->paramL>>8);
517 if (tmpMsg->message == WM_KEYDOWN || tmpMsg->message == WM_SYSKEYDOWN)
519 for (keyDown=i=0; i<256 && !keyDown; i++)
520 if (InputKeyStateTable[i] & 0x80)
521 keyDown++;
522 if (!keyDown)
523 lParam |= 0x40000000;
524 AsyncKeyStateTable[wParam]=InputKeyStateTable[wParam] |= 0x80;
526 else /* WM_KEYUP, WM_SYSKEYUP */
528 lParam |= 0xC0000000;
529 AsyncKeyStateTable[wParam]=InputKeyStateTable[wParam] &= ~0x80;
531 if (InputKeyStateTable[VK_MENU] & 0x80)
532 lParam |= 0x20000000;
533 if (tmpMsg->paramH & 0x8000) /*special_key bit*/
534 lParam |= 0x01000000;
535 hardware_event( tmpMsg->message & 0xffff, LOWORD(wParam), lParam,
536 0, 0, tmpMsg->time, 0 );
538 else
540 if ((tmpMsg->message>= WM_MOUSEFIRST) && (tmpMsg->message <= WM_MOUSELAST))
542 switch (tmpMsg->message)
544 case WM_LBUTTONDOWN:
545 MouseButtonsStates[0]=AsyncMouseButtonsStates[0]=TRUE;break;
546 case WM_LBUTTONUP:
547 MouseButtonsStates[0]=AsyncMouseButtonsStates[0]=FALSE;break;
548 case WM_MBUTTONDOWN:
549 MouseButtonsStates[1]=AsyncMouseButtonsStates[1]=TRUE;break;
550 case WM_MBUTTONUP:
551 MouseButtonsStates[1]=AsyncMouseButtonsStates[1]=FALSE;break;
552 case WM_RBUTTONDOWN:
553 MouseButtonsStates[2]=AsyncMouseButtonsStates[2]=TRUE;break;
554 case WM_RBUTTONUP:
555 MouseButtonsStates[2]=AsyncMouseButtonsStates[2]=FALSE;break;
557 AsyncKeyStateTable[VK_LBUTTON]= InputKeyStateTable[VK_LBUTTON] = MouseButtonsStates[0] ? 0x80 : 0;
558 AsyncKeyStateTable[VK_MBUTTON]= InputKeyStateTable[VK_MBUTTON] = MouseButtonsStates[1] ? 0x80 : 0;
559 AsyncKeyStateTable[VK_RBUTTON]= InputKeyStateTable[VK_RBUTTON] = MouseButtonsStates[2] ? 0x80 : 0;
560 SetCursorPos(tmpMsg->paramL,tmpMsg->paramH);
561 lParam=MAKELONG(tmpMsg->paramL,tmpMsg->paramH);
562 wParam=0;
563 if (MouseButtonsStates[0]) wParam |= MK_LBUTTON;
564 if (MouseButtonsStates[1]) wParam |= MK_MBUTTON;
565 if (MouseButtonsStates[2]) wParam |= MK_RBUTTON;
566 hardware_event( tmpMsg->message & 0xffff, LOWORD (wParam), lParam,
567 tmpMsg->paramL, tmpMsg->paramH, tmpMsg->time, 0 );
570 HOOK_CallHooksA( WH_JOURNALPLAYBACK, HC_SKIP, 0,
571 (LPARAM) tmpMsg);
573 else
576 if( tmpMsg->message == WM_QUEUESYNC )
577 if (HOOK_IsHooked( WH_CBT ))
578 HOOK_CallHooksA( WH_CBT, HCBT_QS, 0, 0L);
580 result= QS_MOUSE | QS_KEY; /* ? */
582 HeapFree(SystemHeap, 0, tmpMsg);
584 return result;
587 /***********************************************************************
588 * MSG_PeekHardwareMsg
590 * Peek for a hardware message matching the hwnd and message filters.
592 static BOOL MSG_PeekHardwareMsg( MSG *msg, HWND hwnd, DWORD first, DWORD last,
593 BOOL remove )
595 DWORD status = SYSQ_MSG_ACCEPT;
596 MESSAGEQUEUE *sysMsgQueue = QUEUE_GetSysQueue();
597 enum { MOUSE_MSG = 0, KEYBOARD_MSG, HARDWARE_MSG } msgType;
598 QMSG *nextqmsg, *qmsg = 0;
599 BOOL bRet = FALSE;
601 EnterCriticalSection(&sysMsgQueue->cSection);
603 /* Loop through the Q and translate the message we wish to process
604 * while we own the lock. Based on the translation status (abandon/cont/accept)
605 * we then process the message accordingly
608 for ( qmsg = sysMsgQueue->firstMsg; qmsg; qmsg = nextqmsg )
610 INT16 hittest;
611 POINT16 screen_pt;
612 BOOL mouseClick;
614 *msg = qmsg->msg;
616 nextqmsg = qmsg->nextMsg;
618 /* Translate message */
620 if ((msg->message >= WM_MOUSEFIRST) && (msg->message <= WM_MOUSELAST))
622 HWND hWndScope = (HWND)qmsg->extraInfo;
623 WND *tmpWnd = (Options.managed && IsWindow(hWndScope) )
624 ? WIN_FindWndPtr(hWndScope) : WIN_GetDesktop();
626 status = MSG_TranslateMouseMsg(hwnd, first, last, msg, remove, tmpWnd,
627 &hittest, &screen_pt, &mouseClick );
628 msgType = MOUSE_MSG;
630 WIN_ReleaseWndPtr(tmpWnd);
633 else if ((msg->message >= WM_KEYFIRST) && (msg->message <= WM_KEYLAST))
635 status = MSG_TranslateKbdMsg(hwnd, first, last, msg, remove);
636 msgType = KEYBOARD_MSG;
638 else /* Non-standard hardware event */
640 HARDWAREHOOKSTRUCT16 *hook;
641 msgType = HARDWARE_MSG;
642 if ((hook = SEGPTR_NEW(HARDWAREHOOKSTRUCT16)))
644 BOOL ret;
645 hook->hWnd = msg->hwnd;
646 hook->wMessage = msg->message & 0xffff;
647 hook->wParam = LOWORD (msg->wParam);
648 hook->lParam = msg->lParam;
649 ret = HOOK_CallHooks16( WH_HARDWARE,
650 remove ? HC_ACTION : HC_NOREMOVE,
651 0, (LPARAM)SEGPTR_GET(hook) );
652 SEGPTR_FREE(hook);
653 if (ret)
655 QUEUE_RemoveMsg( sysMsgQueue, qmsg );
656 continue;
658 status = SYSQ_MSG_ACCEPT;
663 switch (LOWORD(status))
665 case SYSQ_MSG_ACCEPT:
667 /* Remove the message from the system msg Q while it is still locked,
668 * before accepting it */
669 if (remove)
671 if (HOOK_IsHooked( WH_JOURNALRECORD )) MSG_JournalRecordMsg( msg );
672 QUEUE_RemoveMsg( sysMsgQueue, qmsg );
674 /* Now actually process the message, after we unlock the system msg Q.
675 * We should not hold on to the crst since SendMessage calls during processing
676 * will potentially cause callbacks to PeekMessage from the application.
677 * If we're holding the crst and QUEUE_WaitBits is called with a
678 * QS_SENDMESSAGE mask we will deadlock in hardware_event() when a
679 * message is being posted to the Q.
681 LeaveCriticalSection(&sysMsgQueue->cSection);
682 if( msgType == KEYBOARD_MSG )
683 status = MSG_ProcessKbdMsg( msg, remove );
684 else if ( msgType == MOUSE_MSG )
685 status = MSG_ProcessMouseMsg( msg, remove, hittest, screen_pt, mouseClick );
687 /* Reclaim the sys msg Q crst */
688 EnterCriticalSection(&sysMsgQueue->cSection);
690 /* Pass the translated message to the user if it was accepted */
691 if (status == SYSQ_MSG_ACCEPT)
692 break;
694 /* If not accepted, fall through into the SYSQ_MSG_SKIP case */
697 case SYSQ_MSG_SKIP:
698 if (HOOK_IsHooked( WH_CBT ))
700 if( msgType == KEYBOARD_MSG )
701 HOOK_CallHooks16( WH_CBT, HCBT_KEYSKIPPED,
702 LOWORD (msg->wParam), msg->lParam );
703 else if ( msgType == MOUSE_MSG )
705 MOUSEHOOKSTRUCT16 *hook = SEGPTR_NEW(MOUSEHOOKSTRUCT16);
706 if (hook)
708 CONV_POINT32TO16( &msg->pt,&hook->pt );
709 hook->hwnd = msg->hwnd;
710 hook->wHitTestCode = HIWORD(status);
711 hook->dwExtraInfo = 0;
712 HOOK_CallHooks16( WH_CBT, HCBT_CLICKSKIPPED ,msg->message & 0xffff,
713 (LPARAM)SEGPTR_GET(hook) );
714 SEGPTR_FREE(hook);
719 /* If the message was removed earlier set up nextqmsg so that we start
720 * at the top of the queue again. We need to do this since our next pointer
721 * could be invalid due to us unlocking the system message Q to process the message.
722 * If not removed just refresh nextqmsg to point to the next msg.
724 if (remove)
725 nextqmsg = sysMsgQueue->firstMsg;
726 else
727 nextqmsg = qmsg->nextMsg;
729 continue;
731 case SYSQ_MSG_CONTINUE:
732 continue;
734 case SYSQ_MSG_ABANDON:
735 bRet = FALSE;
736 goto END;
739 bRet = TRUE;
740 goto END;
743 END:
744 LeaveCriticalSection(&sysMsgQueue->cSection);
745 return bRet;
749 /**********************************************************************
750 * SetDoubleClickTime (USER.20)
752 void WINAPI SetDoubleClickTime16( UINT16 interval )
754 SetDoubleClickTime( interval );
758 /**********************************************************************
759 * SetDoubleClickTime (USER32.@)
761 BOOL WINAPI SetDoubleClickTime( UINT interval )
763 doubleClickSpeed = interval ? interval : 500;
764 return TRUE;
768 /**********************************************************************
769 * GetDoubleClickTime (USER.21)
771 UINT16 WINAPI GetDoubleClickTime16(void)
773 return doubleClickSpeed;
777 /**********************************************************************
778 * GetDoubleClickTime (USER32.@)
780 UINT WINAPI GetDoubleClickTime(void)
782 return doubleClickSpeed;
786 /***********************************************************************
787 * MSG_SendMessageInterThread
789 * Implementation of an inter-task SendMessage.
790 * Return values:
791 * 0 if error or timeout
792 * 1 if successful
794 static LRESULT MSG_SendMessageInterThread( HQUEUE16 hDestQueue,
795 HWND hwnd, UINT msg,
796 WPARAM wParam, LPARAM lParam,
797 DWORD timeout, WORD flags,
798 LRESULT *pRes)
800 MESSAGEQUEUE *queue, *destQ;
801 SMSG *smsg;
802 LRESULT retVal = 1;
803 int iWndsLocks;
805 if (pRes) *pRes = 0;
807 if (IsTaskLocked16() || !IsWindow(hwnd))
808 return 0;
810 /* create a SMSG structure to hold SendMessage() parameters */
811 if (! (smsg = (SMSG *) HeapAlloc( SystemHeap, 0, sizeof(SMSG) )) )
812 return 0;
813 if (!(queue = QUEUE_Lock( GetFastQueue16() ))) return 0;
815 if (!(destQ = QUEUE_Lock( hDestQueue )))
817 QUEUE_Unlock( queue );
818 return 0;
821 TRACE_(sendmsg)("SM: %s [%04x] (%04x -> %04x)\n",
822 SPY_GetMsgName(msg), msg, queue->self, hDestQueue );
824 /* fill up SMSG structure */
825 smsg->hWnd = hwnd;
826 smsg->msg = msg;
827 smsg->wParam = wParam;
828 smsg->lParam = lParam;
830 smsg->lResult = 0;
831 smsg->hSrcQueue = pRes ? GetFastQueue16() : 0;
832 smsg->hDstQueue = hDestQueue;
833 smsg->flags = flags;
835 if (pRes) {
836 /* add smsg struct in the processing SM list of the source queue */
837 QUEUE_AddSMSG(queue, SM_PROCESSING_LIST, smsg);
838 } else {
839 /* this is a notification message, we don't need a reply */
840 smsg->flags |= SMSG_ALREADY_REPLIED | SMSG_RECEIVER_CLEANS;
843 /* add smsg struct in the pending list of the destination queue */
844 if (QUEUE_AddSMSG(destQ, SM_PENDING_LIST, smsg) == FALSE)
846 retVal = 0;
847 goto CLEANUP;
850 if (!pRes) goto CLEANUP; /* don't need a reply */
852 iWndsLocks = WIN_SuspendWndsLock();
854 /* force destination task to run next, if 16 bit threads */
855 if ( THREAD_IsWin16(NtCurrentTeb()) && THREAD_IsWin16(destQ->teb) )
856 DirectedYield16( destQ->teb->htask16 );
858 /* wait for the result, note that 16-bit apps almost always get out of
859 * DirectedYield() with SMSG_HAVE_RESULT flag already set */
861 while ( TRUE )
864 * The sequence is crucial to avoid deadlock situations:
865 * - first, we clear the QS_SMRESULT bit
866 * - then, we check the SMSG_HAVE_RESULT bit
867 * - only if this isn't set, we enter the wait state.
869 * As the receiver first sets the SMSG_HAVE_RESULT and then wakes us,
870 * we are guaranteed that -should we now clear the QS_SMRESULT that
871 * was signalled already by the receiver- we will not start waiting.
874 if ( smsg->flags & SMSG_HAVE_RESULT )
876 got:
877 *pRes = smsg->lResult;
878 TRACE_(sendmsg)("smResult = %08x\n", (unsigned)*pRes );
879 break;
882 QUEUE_ClearWakeBit( queue, QS_SMRESULT );
884 if ( smsg->flags & SMSG_HAVE_RESULT )
885 goto got;
887 if( QUEUE_WaitBits( QS_SMRESULT, timeout ) == 0 )
889 /* return with timeout */
890 SetLastError( 0 );
891 retVal = 0;
892 break;
895 WIN_RestoreWndsLock(iWndsLocks);
897 /* remove the smsg from the processing list of the source queue */
898 QUEUE_RemoveSMSG( queue, SM_PROCESSING_LIST, smsg );
900 /* Note: the destination thread is in charge of removing the smsg from
901 the pending list */
903 /* In the case of an early reply (or a timeout), sender thread will
904 released the smsg structure if the receiver thread is done
905 (SMSG_RECEIVED set). If the receiver thread isn't done,
906 SMSG_RECEIVER_CLEANS_UP flag is set, and it will be the receiver
907 responsibility to release smsg */
908 EnterCriticalSection( &queue->cSection );
910 if (smsg->flags & SMSG_RECEIVED)
911 HeapFree(SystemHeap, 0, smsg);
912 else
913 smsg->flags |= SMSG_RECEIVER_CLEANS;
915 LeaveCriticalSection( &queue->cSection );
918 CLEANUP:
919 QUEUE_Unlock( queue );
920 QUEUE_Unlock( destQ );
922 TRACE_(sendmsg)("done!\n");
923 return retVal;
927 /***********************************************************************
928 * ReplyMessage (USER.115)
930 void WINAPI ReplyMessage16( LRESULT result )
932 ReplyMessage( result );
935 /***********************************************************************
936 * ReplyMessage (USER32.@)
938 BOOL WINAPI ReplyMessage( LRESULT result )
940 MESSAGEQUEUE *senderQ = 0;
941 MESSAGEQUEUE *queue = 0;
942 SMSG *smsg;
943 BOOL ret = FALSE;
945 if (!(queue = QUEUE_Lock( GetFastQueue16() )))
946 return FALSE;
948 TRACE_(sendmsg)("ReplyMessage, queue %04x\n", queue->self);
951 if ( !(smsg = queue->smWaiting)
952 || !( (senderQ = QUEUE_Lock( smsg->hSrcQueue ))
953 || (smsg->flags & SMSG_ALREADY_REPLIED)) )
954 goto ReplyMessageEnd;
956 if ( !(smsg->flags & SMSG_ALREADY_REPLIED) )
958 /* This is the first reply, so pass result to sender */
960 TRACE_(sendmsg)("\trpm: smResult = %08lx\n", (long) result );
962 EnterCriticalSection(&senderQ->cSection);
964 smsg->lResult = result;
965 smsg->flags |= SMSG_ALREADY_REPLIED;
967 /* check if it's an early reply (called by the application) or
968 a regular reply (called by ReceiveMessage) */
969 if ( !(smsg->flags & SMSG_SENDING_REPLY) )
970 smsg->flags |= SMSG_EARLY_REPLY;
972 smsg->flags |= SMSG_HAVE_RESULT;
974 LeaveCriticalSection(&senderQ->cSection);
976 /* tell the sending task that its reply is ready */
977 QUEUE_SetWakeBit( senderQ, QS_SMRESULT );
979 /* switch directly to sending task (16 bit thread only) */
980 if ( THREAD_IsWin16( NtCurrentTeb() ) && THREAD_IsWin16( senderQ->teb ) )
981 DirectedYield16( senderQ->teb->htask16 );
983 ret = TRUE;
986 if (smsg->flags & SMSG_SENDING_REPLY)
988 /* remove msg from the waiting list, since this is the last
989 ReplyMessage */
990 QUEUE_RemoveSMSG( queue, SM_WAITING_LIST, smsg );
992 if (senderQ) EnterCriticalSection(&senderQ->cSection);
994 /* tell the sender we're all done with smsg structure */
995 smsg->flags |= SMSG_RECEIVED;
997 /* sender will set SMSG_RECEIVER_CLEANS_UP if it wants the
998 receiver to clean up smsg, it could only happen when there is
999 an early reply or a timeout */
1000 if ( smsg->flags & SMSG_RECEIVER_CLEANS )
1002 TRACE_(sendmsg)("Receiver cleans up!\n" );
1003 HeapFree( SystemHeap, 0, smsg );
1006 if (senderQ) LeaveCriticalSection(&senderQ->cSection);
1009 ReplyMessageEnd:
1010 if ( senderQ )
1011 QUEUE_Unlock( senderQ );
1012 if ( queue )
1013 QUEUE_Unlock( queue );
1015 return ret;
1018 /***********************************************************************
1019 * MSG_ConvertMsg
1021 static BOOL MSG_ConvertMsg( MSG *msg, int srcType, int dstType )
1023 UINT16 msg16;
1024 MSGPARAM16 mp16;
1026 switch ( MAKELONG( srcType, dstType ) )
1028 case MAKELONG( QMSG_WIN16, QMSG_WIN16 ):
1029 case MAKELONG( QMSG_WIN32A, QMSG_WIN32A ):
1030 case MAKELONG( QMSG_WIN32W, QMSG_WIN32W ):
1031 return TRUE;
1033 case MAKELONG( QMSG_WIN16, QMSG_WIN32A ):
1034 switch ( WINPROC_MapMsg16To32A( msg->message, msg->wParam,
1035 &msg->message, &msg->wParam, &msg->lParam ) )
1037 case 0:
1038 return TRUE;
1039 case 1:
1040 /* Pointer messages were mapped --> need to free allocated memory and fail */
1041 WINPROC_UnmapMsg16To32A( msg->hwnd, msg->message, msg->wParam, msg->lParam, 0 );
1042 default:
1043 return FALSE;
1046 case MAKELONG( QMSG_WIN16, QMSG_WIN32W ):
1047 switch ( WINPROC_MapMsg16To32W( msg->hwnd, msg->message, msg->wParam,
1048 &msg->message, &msg->wParam, &msg->lParam ) )
1050 case 0:
1051 return TRUE;
1052 case 1:
1053 /* Pointer messages were mapped --> need to free allocated memory and fail */
1054 WINPROC_UnmapMsg16To32W( msg->hwnd, msg->message, msg->wParam, msg->lParam, 0 );
1055 default:
1056 return FALSE;
1059 case MAKELONG( QMSG_WIN32A, QMSG_WIN16 ):
1060 mp16.lParam = msg->lParam;
1061 switch ( WINPROC_MapMsg32ATo16( msg->hwnd, msg->message, msg->wParam,
1062 &msg16, &mp16.wParam, &mp16.lParam ) )
1064 case 0:
1065 msg->message = msg16;
1066 msg->wParam = mp16.wParam;
1067 msg->lParam = mp16.lParam;
1068 return TRUE;
1069 case 1:
1070 /* Pointer messages were mapped --> need to free allocated memory and fail */
1071 WINPROC_UnmapMsg32ATo16( msg->hwnd, msg->message, msg->wParam, msg->lParam, &mp16 );
1072 default:
1073 return FALSE;
1076 case MAKELONG( QMSG_WIN32W, QMSG_WIN16 ):
1077 mp16.lParam = msg->lParam;
1078 switch ( WINPROC_MapMsg32WTo16( msg->hwnd, msg->message, msg->wParam,
1079 &msg16, &mp16.wParam, &mp16.lParam ) )
1081 case 0:
1082 msg->message = msg16;
1083 msg->wParam = mp16.wParam;
1084 msg->lParam = mp16.lParam;
1085 return TRUE;
1086 case 1:
1087 /* Pointer messages were mapped --> need to free allocated memory and fail */
1088 WINPROC_UnmapMsg32WTo16( msg->hwnd, msg->message, msg->wParam, msg->lParam, &mp16 );
1089 default:
1090 return FALSE;
1093 case MAKELONG( QMSG_WIN32A, QMSG_WIN32W ):
1094 switch ( WINPROC_MapMsg32ATo32W( 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_UnmapMsg32ATo32W( msg->hwnd, msg->message, msg->wParam, msg->lParam );
1101 default:
1102 return FALSE;
1105 case MAKELONG( QMSG_WIN32W, QMSG_WIN32A ):
1106 switch ( WINPROC_MapMsg32WTo32A( msg->hwnd, msg->message, &msg->wParam, &msg->lParam ) )
1108 case 0:
1109 return TRUE;
1110 case 1:
1111 /* Pointer messages were mapped --> need to free allocated memory and fail */
1112 WINPROC_UnmapMsg32WTo32A( msg->hwnd, msg->message, msg->wParam, msg->lParam );
1113 default:
1114 return FALSE;
1117 default:
1118 FIXME( "Invalid message type(s): %d / %d\n", srcType, dstType );
1119 return FALSE;
1123 /***********************************************************************
1124 * MSG_PeekMessage
1126 static BOOL MSG_PeekMessage( int type, LPMSG msg_out, HWND hwnd,
1127 DWORD first, DWORD last, WORD flags, BOOL peek )
1129 int changeBits, mask;
1130 MESSAGEQUEUE *msgQueue;
1131 HQUEUE16 hQueue;
1132 int iWndsLocks;
1133 MSG msg;
1135 mask = QS_POSTMESSAGE | QS_SENDMESSAGE; /* Always selected */
1136 if (first || last)
1138 if ((first <= WM_KEYLAST) && (last >= WM_KEYFIRST)) mask |= QS_KEY;
1139 if ( ((first <= WM_MOUSELAST) && (last >= WM_MOUSEFIRST)) ||
1140 ((first <= WM_NCMOUSELAST) && (last >= WM_NCMOUSEFIRST)) ) mask |= QS_MOUSE;
1141 if ((first <= WM_TIMER) && (last >= WM_TIMER)) mask |= QS_TIMER;
1142 if ((first <= WM_SYSTIMER) && (last >= WM_SYSTIMER)) mask |= QS_TIMER;
1143 if ((first <= WM_PAINT) && (last >= WM_PAINT)) mask |= QS_PAINT;
1145 else mask |= QS_MOUSE | QS_KEY | QS_TIMER | QS_PAINT;
1147 if (IsTaskLocked16()) flags |= PM_NOYIELD;
1149 /* Never yield on Win32 threads */
1150 if (!THREAD_IsWin16(NtCurrentTeb())) flags |= PM_NOYIELD;
1152 iWndsLocks = WIN_SuspendWndsLock();
1154 while(1)
1156 QMSG *qmsg;
1158 hQueue = GetFastQueue16();
1159 msgQueue = QUEUE_Lock( hQueue );
1160 if (!msgQueue)
1162 WIN_RestoreWndsLock(iWndsLocks);
1163 return FALSE;
1166 EnterCriticalSection( &msgQueue->cSection );
1167 msgQueue->changeBits = 0;
1168 LeaveCriticalSection( &msgQueue->cSection );
1170 /* First handle a message put by SendMessage() */
1172 while ( QUEUE_ReceiveMessage( msgQueue ) )
1175 /* Now handle a WM_QUIT message */
1177 EnterCriticalSection( &msgQueue->cSection );
1178 if (msgQueue->wPostQMsg &&
1179 (!first || WM_QUIT >= first) &&
1180 (!last || WM_QUIT <= last) )
1182 msg.hwnd = hwnd;
1183 msg.message = WM_QUIT;
1184 msg.wParam = msgQueue->wExitCode;
1185 msg.lParam = 0;
1186 if (flags & PM_REMOVE) msgQueue->wPostQMsg = 0;
1187 LeaveCriticalSection( &msgQueue->cSection );
1188 break;
1190 LeaveCriticalSection( &msgQueue->cSection );
1192 /* Now find a normal message */
1194 retry:
1195 if ((QUEUE_TestWakeBit(msgQueue, mask & QS_POSTMESSAGE)) &&
1196 ((qmsg = QUEUE_FindMsg( msgQueue, hwnd, first, last )) != 0))
1198 /* Try to convert message to requested type */
1199 MSG tmpMsg = qmsg->msg;
1200 if ( !MSG_ConvertMsg( &tmpMsg, qmsg->type, type ) )
1202 ERR( "Message %s of wrong type contains pointer parameters. Skipped!\n",
1203 SPY_GetMsgName(tmpMsg.message));
1204 QUEUE_RemoveMsg( msgQueue, qmsg );
1205 goto retry;
1208 msg = tmpMsg;
1209 msgQueue->GetMessageTimeVal = msg.time;
1210 msgQueue->GetMessagePosVal = MAKELONG( (INT16)msg.pt.x, (INT16)msg.pt.y );
1211 msgQueue->GetMessageExtraInfoVal = qmsg->extraInfo;
1213 if (flags & PM_REMOVE) QUEUE_RemoveMsg( msgQueue, qmsg );
1214 break;
1217 changeBits = MSG_JournalPlayBackMsg();
1218 EnterCriticalSection( &msgQueue->cSection );
1219 msgQueue->changeBits |= changeBits;
1220 LeaveCriticalSection( &msgQueue->cSection );
1222 /* Now find a hardware event */
1224 if (MSG_PeekHardwareMsg( &msg, hwnd, first, last, flags & PM_REMOVE ))
1226 /* Got one */
1227 msgQueue->GetMessageTimeVal = msg.time;
1228 msgQueue->GetMessagePosVal = MAKELONG( (INT16)msg.pt.x, (INT16)msg.pt.y );
1229 msgQueue->GetMessageExtraInfoVal = 0; /* Always 0 for now */
1230 break;
1233 /* Check again for SendMessage */
1235 while ( QUEUE_ReceiveMessage( msgQueue ) )
1238 /* Now find a WM_PAINT message */
1240 if (QUEUE_TestWakeBit(msgQueue, mask & QS_PAINT))
1242 WND* wndPtr;
1243 msg.hwnd = WIN_FindWinToRepaint( hwnd , hQueue );
1244 msg.message = WM_PAINT;
1245 msg.wParam = 0;
1246 msg.lParam = 0;
1248 if ((wndPtr = WIN_FindWndPtr(msg.hwnd)))
1250 if( wndPtr->dwStyle & WS_MINIMIZE &&
1251 (HICON) GetClassLongA(wndPtr->hwndSelf, GCL_HICON) )
1253 msg.message = WM_PAINTICON;
1254 msg.wParam = 1;
1257 if( !hwnd || msg.hwnd == hwnd || IsChild16(hwnd,msg.hwnd) )
1259 if( wndPtr->flags & WIN_INTERNAL_PAINT && !wndPtr->hrgnUpdate)
1261 wndPtr->flags &= ~WIN_INTERNAL_PAINT;
1262 QUEUE_DecPaintCount( hQueue );
1264 WIN_ReleaseWndPtr(wndPtr);
1265 break;
1267 WIN_ReleaseWndPtr(wndPtr);
1271 /* Check for timer messages, but yield first */
1273 if (!(flags & PM_NOYIELD))
1275 UserYield16();
1276 while ( QUEUE_ReceiveMessage( msgQueue ) )
1280 if (QUEUE_TestWakeBit(msgQueue, mask & QS_TIMER))
1282 if (TIMER_GetTimerMsg(&msg, hwnd, hQueue, flags & PM_REMOVE)) break;
1285 if (peek)
1287 if (!(flags & PM_NOYIELD)) UserYield16();
1289 QUEUE_Unlock( msgQueue );
1290 WIN_RestoreWndsLock(iWndsLocks);
1291 return FALSE;
1294 QUEUE_WaitBits( mask, INFINITE );
1295 QUEUE_Unlock( msgQueue );
1298 WIN_RestoreWndsLock(iWndsLocks);
1300 /* instead of unlocking queue for every break condition, all break
1301 condition will fall here */
1302 QUEUE_Unlock( msgQueue );
1304 /* We got a message */
1305 if (flags & PM_REMOVE)
1307 WORD message = msg.message;
1309 if (message == WM_KEYDOWN || message == WM_SYSKEYDOWN)
1311 BYTE *p = &QueueKeyStateTable[msg.wParam & 0xff];
1313 if (!(*p & 0x80))
1314 *p ^= 0x01;
1315 *p |= 0x80;
1317 else if (message == WM_KEYUP || message == WM_SYSKEYUP)
1318 QueueKeyStateTable[msg.wParam & 0xff] &= ~0x80;
1321 /* copy back our internal safe copy of message data to msg_out.
1322 * msg_out is a variable from the *program*, so it can't be used
1323 * internally as it can get "corrupted" by our use of SendMessage()
1324 * (back to the program) inside the message handling itself. */
1325 *msg_out = msg;
1326 if (peek)
1327 return TRUE;
1329 else
1330 return (msg.message != WM_QUIT);
1333 /***********************************************************************
1334 * MSG_InternalGetMessage
1336 * GetMessage() function for internal use. Behave like GetMessage(),
1337 * but also call message filters and optionally send WM_ENTERIDLE messages.
1338 * 'hwnd' must be the handle of the dialog or menu window.
1339 * 'code' is the message filter value (MSGF_??? codes).
1341 BOOL MSG_InternalGetMessage( int type, MSG *msg, HWND hwnd, HWND hwndOwner,
1342 WPARAM code, WORD flags, BOOL sendIdle, BOOL* idleSent )
1344 for (;;)
1346 if (sendIdle)
1348 if (!MSG_PeekMessage( type, msg, 0, 0, 0, flags, TRUE ))
1350 /* No message present -> send ENTERIDLE and wait */
1351 if (IsWindow(hwndOwner))
1353 SendMessageA( hwndOwner, WM_ENTERIDLE,
1354 code, (LPARAM)hwnd );
1356 if (idleSent!=NULL)
1357 *idleSent=TRUE;
1359 MSG_PeekMessage( type, msg, 0, 0, 0, flags, FALSE );
1362 else /* Always wait for a message */
1363 MSG_PeekMessage( type, msg, 0, 0, 0, flags, FALSE );
1365 /* Call message filters */
1367 if (HOOK_IsHooked( WH_SYSMSGFILTER ) || HOOK_IsHooked( WH_MSGFILTER ))
1369 MSG *pmsg = HeapAlloc( SystemHeap, 0, sizeof(MSG) );
1370 if (pmsg)
1372 BOOL ret;
1373 *pmsg = *msg;
1374 ret = (HOOK_CallHooksA( WH_SYSMSGFILTER, code, 0,
1375 (LPARAM) pmsg ) ||
1376 HOOK_CallHooksA( WH_MSGFILTER, code, 0,
1377 (LPARAM) pmsg ));
1379 HeapFree( SystemHeap, 0, pmsg );
1380 if (ret)
1382 /* Message filtered -> remove it from the queue */
1383 /* if it's still there. */
1384 if (!(flags & PM_REMOVE))
1385 MSG_PeekMessage( type, msg, 0, 0, 0, PM_REMOVE, TRUE );
1386 continue;
1391 return (msg->message != WM_QUIT);
1396 /***********************************************************************
1397 * PeekMessage32 (USER.819)
1399 BOOL16 WINAPI PeekMessage32_16( SEGPTR msg16_32, HWND16 hwnd,
1400 UINT16 first, UINT16 last, UINT16 flags,
1401 BOOL16 wHaveParamHigh )
1403 BOOL ret;
1404 MSG32_16 *lpmsg16_32 = MapSL(msg16_32);
1405 MSG msg;
1407 ret = MSG_PeekMessage( QMSG_WIN16, &msg, hwnd, first, last, flags, TRUE );
1409 lpmsg16_32->msg.hwnd = msg.hwnd;
1410 lpmsg16_32->msg.message = msg.message;
1411 lpmsg16_32->msg.wParam = LOWORD(msg.wParam);
1412 lpmsg16_32->msg.lParam = msg.lParam;
1413 lpmsg16_32->msg.time = msg.time;
1414 lpmsg16_32->msg.pt.x = (INT16)msg.pt.x;
1415 lpmsg16_32->msg.pt.y = (INT16)msg.pt.y;
1417 if ( wHaveParamHigh )
1418 lpmsg16_32->wParamHigh = HIWORD(msg.wParam);
1420 HOOK_CallHooks16( WH_GETMESSAGE, HC_ACTION, flags & PM_REMOVE, (LPARAM)msg16_32 );
1421 return ret;
1424 /***********************************************************************
1425 * PeekMessage (USER.109)
1427 BOOL16 WINAPI PeekMessage16( SEGPTR msg, HWND16 hwnd,
1428 UINT16 first, UINT16 last, UINT16 flags )
1430 return PeekMessage32_16( msg, hwnd, first, last, flags, FALSE );
1433 /***********************************************************************
1434 * PeekMessageA (USER32.@)
1436 BOOL WINAPI PeekMessageA( LPMSG lpmsg, HWND hwnd,
1437 UINT min, UINT max, UINT wRemoveMsg)
1439 BOOL ret = MSG_PeekMessage( QMSG_WIN32A, lpmsg, hwnd, min, max, wRemoveMsg, TRUE );
1441 TRACE( "peekmessage %04x, hwnd %04x, filter(%04x - %04x)\n",
1442 lpmsg->message, hwnd, min, max );
1444 if (ret) HOOK_CallHooksA( WH_GETMESSAGE, HC_ACTION,
1445 wRemoveMsg & PM_REMOVE, (LPARAM)lpmsg );
1446 return ret;
1449 /***********************************************************************
1450 * PeekMessageW (USER32.@) Check queue for messages
1452 * Checks for a message in the thread's queue, filtered as for
1453 * GetMessage(). Returns immediately whether a message is available
1454 * or not.
1456 * Whether a retrieved message is removed from the queue is set by the
1457 * _wRemoveMsg_ flags, which should be one of the following values:
1459 * PM_NOREMOVE Do not remove the message from the queue.
1461 * PM_REMOVE Remove the message from the queue.
1463 * In addition, PM_NOYIELD may be combined into _wRemoveMsg_ to
1464 * request that the system not yield control during PeekMessage();
1465 * however applications may not rely on scheduling behavior.
1467 * RETURNS
1469 * Nonzero if a message is available and is retrieved, zero otherwise.
1471 * CONFORMANCE
1473 * ECMA-234, Win32
1476 BOOL WINAPI PeekMessageW(
1477 LPMSG lpmsg, /* [out] buffer to receive message */
1478 HWND hwnd, /* [in] restrict to messages for hwnd */
1479 UINT min, /* [in] minimum message to receive */
1480 UINT max, /* [in] maximum message to receive */
1481 UINT wRemoveMsg /* [in] removal flags */
1484 BOOL ret = MSG_PeekMessage( QMSG_WIN32W, lpmsg, hwnd, min, max, wRemoveMsg, TRUE );
1485 if (ret) HOOK_CallHooksW( WH_GETMESSAGE, HC_ACTION,
1486 wRemoveMsg & PM_REMOVE, (LPARAM)lpmsg );
1487 return ret;
1491 /***********************************************************************
1492 * GetMessage32 (USER.820)
1494 BOOL16 WINAPI GetMessage32_16( SEGPTR msg16_32, HWND16 hWnd, UINT16 first,
1495 UINT16 last, BOOL16 wHaveParamHigh )
1497 MSG32_16 *lpmsg16_32 = MapSL(msg16_32);
1498 MSG msg;
1500 MSG_PeekMessage( QMSG_WIN16, &msg, hWnd, first, last, PM_REMOVE, FALSE );
1502 lpmsg16_32->msg.hwnd = msg.hwnd;
1503 lpmsg16_32->msg.message = msg.message;
1504 lpmsg16_32->msg.wParam = LOWORD(msg.wParam);
1505 lpmsg16_32->msg.lParam = msg.lParam;
1506 lpmsg16_32->msg.time = msg.time;
1507 lpmsg16_32->msg.pt.x = (INT16)msg.pt.x;
1508 lpmsg16_32->msg.pt.y = (INT16)msg.pt.y;
1510 if ( wHaveParamHigh )
1511 lpmsg16_32->wParamHigh = HIWORD(msg.wParam);
1513 TRACE( "message %04x, hwnd %04x, filter(%04x - %04x)\n",
1514 lpmsg16_32->msg.message, hWnd, first, last );
1516 HOOK_CallHooks16( WH_GETMESSAGE, HC_ACTION, PM_REMOVE, (LPARAM)msg16_32 );
1517 return lpmsg16_32->msg.message != WM_QUIT;
1520 /***********************************************************************
1521 * GetMessage (USER.108)
1523 BOOL16 WINAPI GetMessage16( SEGPTR msg, HWND16 hwnd, UINT16 first, UINT16 last)
1525 return GetMessage32_16( msg, hwnd, first, last, FALSE );
1528 /***********************************************************************
1529 * GetMessageA (USER32.@)
1531 BOOL WINAPI GetMessageA( MSG *lpmsg, HWND hwnd, UINT min, UINT max )
1533 MSG_PeekMessage( QMSG_WIN32A, lpmsg, hwnd, min, max, PM_REMOVE, FALSE );
1535 TRACE( "message %04x, hwnd %04x, filter(%04x - %04x)\n",
1536 lpmsg->message, hwnd, min, max );
1538 HOOK_CallHooksA( WH_GETMESSAGE, HC_ACTION, PM_REMOVE, (LPARAM)lpmsg );
1539 return lpmsg->message != WM_QUIT;
1542 /***********************************************************************
1543 * GetMessageW (USER32.@) Retrieve next message
1545 * GetMessage retrieves the next event from the calling thread's
1546 * queue and deposits it in *lpmsg.
1548 * If _hwnd_ is not NULL, only messages for window _hwnd_ and its
1549 * children as specified by IsChild() are retrieved. If _hwnd_ is NULL
1550 * all application messages are retrieved.
1552 * _min_ and _max_ specify the range of messages of interest. If
1553 * min==max==0, no filtering is performed. Useful examples are
1554 * WM_KEYFIRST and WM_KEYLAST to retrieve keyboard input, and
1555 * WM_MOUSEFIRST and WM_MOUSELAST to retrieve mouse input.
1557 * WM_PAINT messages are not removed from the queue; they remain until
1558 * processed. Other messages are removed from the queue.
1560 * RETURNS
1562 * -1 on error, 0 if message is WM_QUIT, nonzero otherwise.
1564 * CONFORMANCE
1566 * ECMA-234, Win32
1569 BOOL WINAPI GetMessageW(
1570 MSG* lpmsg, /* [out] buffer to receive message */
1571 HWND hwnd, /* [in] restrict to messages for hwnd */
1572 UINT min, /* [in] minimum message to receive */
1573 UINT max /* [in] maximum message to receive */
1576 MSG_PeekMessage( QMSG_WIN32W, lpmsg, hwnd, min, max, PM_REMOVE, FALSE );
1578 TRACE( "message %04x, hwnd %04x, filter(%04x - %04x)\n",
1579 lpmsg->message, hwnd, min, max );
1581 HOOK_CallHooksW( WH_GETMESSAGE, HC_ACTION, PM_REMOVE, (LPARAM)lpmsg );
1582 return lpmsg->message != WM_QUIT;
1585 /***********************************************************************
1586 * MSG_PostToQueue
1588 static BOOL MSG_PostToQueue( HQUEUE16 hQueue, int type, HWND hwnd,
1589 UINT message, WPARAM wParam, LPARAM lParam )
1591 MSG msg;
1593 if ( !hQueue ) return FALSE;
1595 msg.hwnd = hwnd;
1596 msg.message = message;
1597 msg.wParam = wParam;
1598 msg.lParam = lParam;
1599 msg.time = GetTickCount();
1600 GetCursorPos(&msg.pt);
1602 return QUEUE_AddMsg( hQueue, type, &msg, 0 );
1605 /***********************************************************************
1606 * MSG_IsPointerMessage
1608 * Check whether this message (may) contain pointers.
1609 * Those messages may not be PostMessage()d or GetMessage()d, but are dropped.
1611 * FIXME: list of pointer messages might be incomplete.
1613 * (We could do a generic !IsBadWritePtr() check, but this would cause too
1614 * much slow down I think. MM20010206)
1616 static BOOL MSG_IsPointerMessage(UINT message, WPARAM wParam, LPARAM lParam) {
1617 switch (message) {
1618 case WM_CREATE:
1619 case WM_NCCREATE:
1620 case WM_COMPAREITEM:
1621 case WM_DELETEITEM:
1622 case WM_MEASUREITEM:
1623 case WM_DRAWITEM:
1624 case WM_GETMINMAXINFO:
1625 case WM_GETTEXT:
1626 case WM_SETTEXT:
1627 case WM_MDICREATE:
1628 case WM_MDIGETACTIVE:
1629 case WM_NCCALCSIZE:
1630 case WM_WINDOWPOSCHANGING:
1631 case WM_WINDOWPOSCHANGED:
1632 case WM_NOTIFY:
1633 case WM_GETDLGCODE:
1634 case WM_WININICHANGE:
1635 case WM_HELP:
1636 case WM_COPYDATA:
1637 case WM_STYLECHANGING:
1638 case WM_STYLECHANGED:
1639 case WM_DROPOBJECT:
1640 case WM_DRAGMOVE:
1641 case WM_DRAGSELECT:
1642 case WM_QUERYDROPOBJECT:
1644 case CB_DIR:
1645 case CB_ADDSTRING:
1646 case CB_INSERTSTRING:
1647 case CB_FINDSTRING:
1648 case CB_FINDSTRINGEXACT:
1649 case CB_SELECTSTRING:
1650 case CB_GETLBTEXT:
1651 case CB_GETDROPPEDCONTROLRECT:
1653 case LB_DIR:
1654 case LB_ADDFILE:
1655 case LB_ADDSTRING:
1656 case LB_INSERTSTRING:
1657 case LB_GETTEXT:
1658 case LB_GETITEMRECT:
1659 case LB_FINDSTRING:
1660 case LB_FINDSTRINGEXACT:
1661 case LB_SELECTSTRING:
1662 case LB_GETSELITEMS:
1663 case LB_SETTABSTOPS:
1665 case EM_REPLACESEL:
1666 case EM_GETSEL:
1667 case EM_GETRECT:
1668 case EM_SETRECT:
1669 case EM_SETRECTNP:
1670 case EM_GETLINE:
1671 case EM_SETTABSTOPS:
1672 return TRUE;
1673 default:
1674 return FALSE;
1678 /***********************************************************************
1679 * MSG_PostMessage
1681 static BOOL MSG_PostMessage( int type, HWND hwnd, UINT message,
1682 WPARAM wParam, LPARAM lParam )
1684 HQUEUE16 hQueue;
1685 WND *wndPtr;
1687 /* See thread on wine-devel around 6.2.2001. Basically posted messages
1688 * that are known to contain pointers are dropped by the Windows 32bit
1689 * PostMessage() with return FALSE; and invalid parameter last error.
1690 * (tested against NT4 by Gerard Patel)
1691 * 16 bit does not care, so we don't either.
1693 if ( (type!=QMSG_WIN16) && MSG_IsPointerMessage(message,wParam,lParam)) {
1694 FIXME("Ignoring posted pointer message 0x%04x to hwnd 0x%04x.\n",
1695 message,hwnd
1697 SetLastError(ERROR_INVALID_PARAMETER);
1698 return FALSE;
1701 if (hwnd == HWND_BROADCAST)
1703 WND *pDesktop = WIN_GetDesktop();
1704 TRACE("HWND_BROADCAST !\n");
1706 for (wndPtr=WIN_LockWndPtr(pDesktop->child); wndPtr; WIN_UpdateWndPtr(&wndPtr,wndPtr->next))
1708 if (wndPtr->dwStyle & WS_POPUP || wndPtr->dwStyle & WS_CAPTION)
1710 TRACE("BROADCAST Message to hWnd=%04x m=%04X w=%04X l=%08lX !\n",
1711 wndPtr->hwndSelf, message, wParam, lParam);
1712 MSG_PostToQueue( wndPtr->hmemTaskQ, type,
1713 wndPtr->hwndSelf, message, wParam, lParam );
1716 WIN_ReleaseDesktop();
1717 TRACE("End of HWND_BROADCAST !\n");
1718 return TRUE;
1721 wndPtr = WIN_FindWndPtr( hwnd );
1722 hQueue = wndPtr? wndPtr->hmemTaskQ : 0;
1723 WIN_ReleaseWndPtr(wndPtr);
1725 return MSG_PostToQueue( hQueue, type, hwnd, message, wParam, lParam );
1728 /***********************************************************************
1729 * PostMessage (USER.110)
1731 BOOL16 WINAPI PostMessage16( HWND16 hwnd, UINT16 message, WPARAM16 wParam,
1732 LPARAM lParam )
1734 return (BOOL16) MSG_PostMessage( QMSG_WIN16, hwnd, message, wParam, lParam );
1737 /***********************************************************************
1738 * PostMessageA (USER32.@)
1740 BOOL WINAPI PostMessageA( HWND hwnd, UINT message, WPARAM wParam,
1741 LPARAM lParam )
1743 return MSG_PostMessage( QMSG_WIN32A, hwnd, message, wParam, lParam );
1746 /***********************************************************************
1747 * PostMessageW (USER32.@)
1749 BOOL WINAPI PostMessageW( HWND hwnd, UINT message, WPARAM wParam,
1750 LPARAM lParam )
1752 return MSG_PostMessage( QMSG_WIN32W, hwnd, message, wParam, lParam );
1755 /***********************************************************************
1756 * PostAppMessage (USER.116)
1757 * PostAppMessage16 (USER32.@)
1759 BOOL16 WINAPI PostAppMessage16( HTASK16 hTask, UINT16 message,
1760 WPARAM16 wParam, LPARAM lParam )
1762 return MSG_PostToQueue( GetTaskQueue16(hTask), QMSG_WIN16,
1763 0, message, wParam, lParam );
1766 /**********************************************************************
1767 * PostThreadMessageA (USER32.@)
1769 BOOL WINAPI PostThreadMessageA( DWORD idThread, UINT message,
1770 WPARAM wParam, LPARAM lParam )
1772 return MSG_PostToQueue( GetThreadQueue16(idThread), QMSG_WIN32A,
1773 0, message, wParam, lParam );
1776 /**********************************************************************
1777 * PostThreadMessageW (USER32.@)
1779 BOOL WINAPI PostThreadMessageW( DWORD idThread, UINT message,
1780 WPARAM wParam, LPARAM lParam )
1782 return MSG_PostToQueue( GetThreadQueue16(idThread), QMSG_WIN32W,
1783 0, message, wParam, lParam );
1787 /************************************************************************
1788 * MSG_CallWndProcHook32
1790 static void MSG_CallWndProcHook( LPMSG pmsg, BOOL bUnicode )
1792 CWPSTRUCT cwp;
1794 cwp.lParam = pmsg->lParam;
1795 cwp.wParam = pmsg->wParam;
1796 cwp.message = pmsg->message;
1797 cwp.hwnd = pmsg->hwnd;
1799 if (bUnicode) HOOK_CallHooksW(WH_CALLWNDPROC, HC_ACTION, 1, (LPARAM)&cwp);
1800 else HOOK_CallHooksA( WH_CALLWNDPROC, HC_ACTION, 1, (LPARAM)&cwp );
1802 pmsg->lParam = cwp.lParam;
1803 pmsg->wParam = cwp.wParam;
1804 pmsg->message = cwp.message;
1805 pmsg->hwnd = cwp.hwnd;
1809 /***********************************************************************
1810 * MSG_SendMessage
1812 * return values: 0 if timeout occurs
1813 * 1 otherwise
1815 static LRESULT MSG_SendMessage( HWND hwnd, UINT msg, WPARAM wParam,
1816 LPARAM lParam, DWORD timeout, WORD flags,
1817 LRESULT *pRes)
1819 WND * wndPtr = 0;
1820 WND **list, **ppWnd;
1821 LRESULT ret = 1;
1823 if (pRes) *pRes = 0;
1825 if (hwnd == HWND_BROADCAST|| hwnd == HWND_TOPMOST)
1827 if (pRes) *pRes = 1;
1829 if (!(list = WIN_BuildWinArray( WIN_GetDesktop(), 0, NULL )))
1831 WIN_ReleaseDesktop();
1832 return 1;
1834 WIN_ReleaseDesktop();
1836 TRACE("HWND_BROADCAST !\n");
1837 for (ppWnd = list; *ppWnd; ppWnd++)
1839 WIN_UpdateWndPtr(&wndPtr,*ppWnd);
1840 if (!IsWindow(wndPtr->hwndSelf)) continue;
1841 if (wndPtr->dwStyle & WS_POPUP || wndPtr->dwStyle & WS_CAPTION)
1843 TRACE("BROADCAST Message to hWnd=%04x m=%04X w=%04lX l=%08lX !\n",
1844 wndPtr->hwndSelf, msg, (DWORD)wParam, lParam);
1845 MSG_SendMessage( wndPtr->hwndSelf, msg, wParam, lParam,
1846 timeout, flags, pRes);
1849 WIN_ReleaseWndPtr(wndPtr);
1850 WIN_ReleaseWinArray(list);
1851 TRACE("End of HWND_BROADCAST !\n");
1852 return 1;
1855 if (HOOK_IsHooked( WH_CALLWNDPROC ))
1857 if (flags & SMSG_UNICODE)
1858 MSG_CallWndProcHook( (LPMSG)&hwnd, TRUE);
1859 else if (flags & SMSG_WIN32)
1860 MSG_CallWndProcHook( (LPMSG)&hwnd, FALSE);
1861 else
1863 LPCWPSTRUCT16 pmsg;
1865 if ((pmsg = SEGPTR_NEW(CWPSTRUCT16)))
1867 pmsg->hwnd = hwnd & 0xffff;
1868 pmsg->message= msg & 0xffff;
1869 pmsg->wParam = wParam & 0xffff;
1870 pmsg->lParam = lParam;
1871 HOOK_CallHooks16( WH_CALLWNDPROC, HC_ACTION, 1,
1872 (LPARAM)SEGPTR_GET(pmsg) );
1873 hwnd = pmsg->hwnd;
1874 msg = pmsg->message;
1875 wParam = pmsg->wParam;
1876 lParam = pmsg->lParam;
1877 SEGPTR_FREE( pmsg );
1882 if (!(wndPtr = WIN_FindWndPtr( hwnd )))
1884 WARN("invalid hwnd %04x\n", hwnd );
1885 return 0;
1887 if (QUEUE_IsExitingQueue(wndPtr->hmemTaskQ))
1889 ret = 0; /* Don't send anything if the task is dying */
1890 goto END;
1892 if (flags & SMSG_WIN32)
1893 SPY_EnterMessage( SPY_SENDMESSAGE, hwnd, msg, wParam, lParam );
1894 else
1895 SPY_EnterMessage( SPY_SENDMESSAGE16, hwnd, msg, wParam, lParam );
1897 if (wndPtr->hmemTaskQ != GetFastQueue16())
1898 ret = MSG_SendMessageInterThread( wndPtr->hmemTaskQ, hwnd, msg,
1899 wParam, lParam, timeout, flags, pRes );
1900 else
1902 LRESULT res;
1904 /* Call the right CallWindowProc flavor */
1905 if (flags & SMSG_UNICODE)
1906 res = CallWindowProcW( (WNDPROC)wndPtr->winproc,
1907 hwnd, msg, wParam, lParam );
1908 else if (flags & SMSG_WIN32)
1909 res = CallWindowProcA( (WNDPROC)wndPtr->winproc,
1910 hwnd, msg, wParam, lParam );
1911 else
1912 res = CallWindowProc16( (WNDPROC16)wndPtr->winproc,
1913 (HWND16) hwnd, (UINT16) msg,
1914 (WPARAM16) wParam, lParam );
1915 if (pRes) *pRes = res;
1918 if (flags & SMSG_WIN32)
1919 SPY_ExitMessage( SPY_RESULT_OK, hwnd, msg, pRes?*pRes:0, wParam, lParam );
1920 else
1921 SPY_ExitMessage( SPY_RESULT_OK16, hwnd, msg, pRes?*pRes:0, wParam, lParam );
1922 END:
1923 WIN_ReleaseWndPtr(wndPtr);
1924 return ret;
1928 /***********************************************************************
1929 * SendMessage (USER.111)
1931 LRESULT WINAPI SendMessage16( HWND16 hwnd, UINT16 msg, WPARAM16 wParam,
1932 LPARAM lParam)
1934 LRESULT res;
1935 MSG_SendMessage(hwnd, msg, wParam, lParam, INFINITE, 0, &res);
1936 return res;
1940 /***********************************************************************
1941 * SendMessageA (USER32.@)
1943 LRESULT WINAPI SendMessageA( HWND hwnd, UINT msg, WPARAM wParam,
1944 LPARAM lParam )
1946 LRESULT res;
1948 MSG_SendMessage(hwnd, msg, wParam, lParam, INFINITE,
1949 SMSG_WIN32, &res);
1951 return res;
1955 /***********************************************************************
1956 * SendMessageW (USER32.@) Send Window Message
1958 * Sends a message to the window procedure of the specified window.
1959 * SendMessage() will not return until the called window procedure
1960 * either returns or calls ReplyMessage().
1962 * Use PostMessage() to send message and return immediately. A window
1963 * procedure may use InSendMessage() to detect
1964 * SendMessage()-originated messages.
1966 * Applications which communicate via HWND_BROADCAST may use
1967 * RegisterWindowMessage() to obtain a unique message to avoid conflicts
1968 * with other applications.
1970 * CONFORMANCE
1972 * ECMA-234, Win32
1974 LRESULT WINAPI SendMessageW(
1975 HWND hwnd, /* [in] Window to send message to. If HWND_BROADCAST,
1976 the message will be sent to all top-level windows. */
1978 UINT msg, /* [in] message */
1979 WPARAM wParam, /* [in] message parameter */
1980 LPARAM lParam /* [in] additional message parameter */
1982 LRESULT res;
1984 MSG_SendMessage(hwnd, msg, wParam, lParam, INFINITE,
1985 SMSG_WIN32 | SMSG_UNICODE, &res);
1987 return res;
1991 /***********************************************************************
1992 * SendMessageTimeout (not a WINAPI)
1994 LRESULT WINAPI SendMessageTimeout16( HWND16 hwnd, UINT16 msg, WPARAM16 wParam,
1995 LPARAM lParam, UINT16 flags,
1996 UINT16 timeout, LPWORD resultp)
1998 LRESULT ret;
1999 LRESULT msgRet;
2001 /* FIXME: need support for SMTO_BLOCK */
2003 ret = MSG_SendMessage(hwnd, msg, wParam, lParam, timeout, 0, &msgRet);
2004 if (resultp) *resultp = (WORD) msgRet;
2005 return ret;
2009 /***********************************************************************
2010 * SendMessageTimeoutA (USER32.@)
2012 LRESULT WINAPI SendMessageTimeoutA( HWND hwnd, UINT msg, WPARAM wParam,
2013 LPARAM lParam, UINT flags,
2014 UINT timeout, LPDWORD resultp)
2016 LRESULT ret;
2017 LRESULT msgRet;
2019 /* FIXME: need support for SMTO_BLOCK */
2021 ret = MSG_SendMessage(hwnd, msg, wParam, lParam, timeout, SMSG_WIN32,
2022 &msgRet);
2024 if (resultp) *resultp = (DWORD) msgRet;
2025 return ret;
2029 /***********************************************************************
2030 * SendMessageTimeoutW (USER32.@)
2032 LRESULT WINAPI SendMessageTimeoutW( HWND hwnd, UINT msg, WPARAM wParam,
2033 LPARAM lParam, UINT flags,
2034 UINT timeout, LPDWORD resultp)
2036 LRESULT ret;
2037 LRESULT msgRet;
2039 /* FIXME: need support for SMTO_BLOCK */
2041 ret = MSG_SendMessage(hwnd, msg, wParam, lParam, timeout,
2042 SMSG_WIN32 | SMSG_UNICODE, &msgRet);
2044 if (resultp) *resultp = (DWORD) msgRet;
2045 return ret;
2049 /***********************************************************************
2050 * WaitMessage (USER.112) (USER32.@) Suspend thread pending messages
2052 * WaitMessage() suspends a thread until events appear in the thread's
2053 * queue.
2055 * BUGS
2057 * Is supposed to return BOOL under Win32.
2059 * Thread-local message queues are not supported.
2061 * CONFORMANCE
2063 * ECMA-234, Win32
2066 void WINAPI WaitMessage( void )
2068 QUEUE_WaitBits( QS_ALLINPUT, INFINITE );
2071 /***********************************************************************
2072 * MsgWaitForMultipleObjects (USER32.@)
2074 DWORD WINAPI MsgWaitForMultipleObjects( DWORD nCount, HANDLE *pHandles,
2075 BOOL fWaitAll, DWORD dwMilliseconds,
2076 DWORD dwWakeMask )
2078 DWORD i;
2079 HANDLE handles[MAXIMUM_WAIT_OBJECTS];
2080 DWORD ret;
2082 HQUEUE16 hQueue = GetFastQueue16();
2083 MESSAGEQUEUE *msgQueue = QUEUE_Lock( hQueue );
2084 if (!msgQueue) return WAIT_FAILED;
2086 if (nCount > MAXIMUM_WAIT_OBJECTS-1)
2088 SetLastError( ERROR_INVALID_PARAMETER );
2089 QUEUE_Unlock( msgQueue );
2090 return WAIT_FAILED;
2093 EnterCriticalSection( &msgQueue->cSection );
2094 msgQueue->changeBits = 0;
2095 msgQueue->wakeMask = dwWakeMask;
2096 LeaveCriticalSection( &msgQueue->cSection );
2098 if (THREAD_IsWin16(NtCurrentTeb()))
2101 * This is a temporary solution to a big problem.
2102 * You see, the main thread of all Win32 programs is created as a 16 bit
2103 * task. This means that if you wait on an event using Win32 synchronization
2104 * methods, the 16 bit scheduler is stopped and things might just stop happening.
2105 * This implements a semi-busy loop that checks the handles to wait on and
2106 * also the message queue. When either one is ready, the wait function returns.
2108 * This will all go away when the real Win32 threads are implemented for all
2109 * the threads of an applications. Including the main thread.
2111 DWORD curTime = GetCurrentTime();
2116 * Check the handles in the list.
2118 ret = WaitForMultipleObjects(nCount, pHandles, fWaitAll, 5L);
2121 * If the handles have been triggered, return.
2123 if (ret != WAIT_TIMEOUT)
2124 break;
2127 * Then, let the 16 bit scheduler do it's thing.
2129 K32WOWYield16();
2132 * If a message matching the wait mask has arrived, return.
2134 EnterCriticalSection( &msgQueue->cSection );
2135 if (msgQueue->changeBits & dwWakeMask)
2137 LeaveCriticalSection( &msgQueue->cSection );
2138 ret = nCount;
2139 break;
2141 LeaveCriticalSection( &msgQueue->cSection );
2144 * And continue doing this until we hit the timeout.
2146 } while ((dwMilliseconds == INFINITE) || (GetCurrentTime()-curTime < dwMilliseconds) );
2148 else
2150 /* Add the thread event to the handle list */
2151 for (i = 0; i < nCount; i++)
2152 handles[i] = pHandles[i];
2153 handles[nCount] = msgQueue->server_queue;
2154 ret = WaitForMultipleObjects( nCount+1, handles, fWaitAll, dwMilliseconds );
2156 QUEUE_Unlock( msgQueue );
2157 return ret;
2160 /***********************************************************************
2161 * MsgWaitForMultipleObjects (USER.640)
2163 DWORD WINAPI MsgWaitForMultipleObjects16( DWORD nCount, HANDLE *pHandles,
2164 BOOL fWaitAll, DWORD dwMilliseconds,
2165 DWORD dwWakeMask )
2167 TRACE("(%lu,%p,%u,%lu,0x%lx)\n",
2168 nCount, pHandles, fWaitAll, dwMilliseconds, dwWakeMask);
2169 return MsgWaitForMultipleObjects(nCount, pHandles, fWaitAll, dwMilliseconds, dwWakeMask);
2172 struct accent_char
2174 BYTE ac_accent;
2175 BYTE ac_char;
2176 BYTE ac_result;
2179 static const struct accent_char accent_chars[] =
2181 /* A good idea should be to read /usr/X11/lib/X11/locale/iso8859-x/Compose */
2182 {'`', 'A', '\300'}, {'`', 'a', '\340'},
2183 {'\'', 'A', '\301'}, {'\'', 'a', '\341'},
2184 {'^', 'A', '\302'}, {'^', 'a', '\342'},
2185 {'~', 'A', '\303'}, {'~', 'a', '\343'},
2186 {'"', 'A', '\304'}, {'"', 'a', '\344'},
2187 {'O', 'A', '\305'}, {'o', 'a', '\345'},
2188 {'0', 'A', '\305'}, {'0', 'a', '\345'},
2189 {'A', 'A', '\305'}, {'a', 'a', '\345'},
2190 {'A', 'E', '\306'}, {'a', 'e', '\346'},
2191 {',', 'C', '\307'}, {',', 'c', '\347'},
2192 {'`', 'E', '\310'}, {'`', 'e', '\350'},
2193 {'\'', 'E', '\311'}, {'\'', 'e', '\351'},
2194 {'^', 'E', '\312'}, {'^', 'e', '\352'},
2195 {'"', 'E', '\313'}, {'"', 'e', '\353'},
2196 {'`', 'I', '\314'}, {'`', 'i', '\354'},
2197 {'\'', 'I', '\315'}, {'\'', 'i', '\355'},
2198 {'^', 'I', '\316'}, {'^', 'i', '\356'},
2199 {'"', 'I', '\317'}, {'"', 'i', '\357'},
2200 {'-', 'D', '\320'}, {'-', 'd', '\360'},
2201 {'~', 'N', '\321'}, {'~', 'n', '\361'},
2202 {'`', 'O', '\322'}, {'`', 'o', '\362'},
2203 {'\'', 'O', '\323'}, {'\'', 'o', '\363'},
2204 {'^', 'O', '\324'}, {'^', 'o', '\364'},
2205 {'~', 'O', '\325'}, {'~', 'o', '\365'},
2206 {'"', 'O', '\326'}, {'"', 'o', '\366'},
2207 {'/', 'O', '\330'}, {'/', 'o', '\370'},
2208 {'`', 'U', '\331'}, {'`', 'u', '\371'},
2209 {'\'', 'U', '\332'}, {'\'', 'u', '\372'},
2210 {'^', 'U', '\333'}, {'^', 'u', '\373'},
2211 {'"', 'U', '\334'}, {'"', 'u', '\374'},
2212 {'\'', 'Y', '\335'}, {'\'', 'y', '\375'},
2213 {'T', 'H', '\336'}, {'t', 'h', '\376'},
2214 {'s', 's', '\337'}, {'"', 'y', '\377'},
2215 {'s', 'z', '\337'}, {'i', 'j', '\377'},
2216 /* iso-8859-2 uses this */
2217 {'<', 'L', '\245'}, {'<', 'l', '\265'}, /* caron */
2218 {'<', 'S', '\251'}, {'<', 's', '\271'},
2219 {'<', 'T', '\253'}, {'<', 't', '\273'},
2220 {'<', 'Z', '\256'}, {'<', 'z', '\276'},
2221 {'<', 'C', '\310'}, {'<', 'c', '\350'},
2222 {'<', 'E', '\314'}, {'<', 'e', '\354'},
2223 {'<', 'D', '\317'}, {'<', 'd', '\357'},
2224 {'<', 'N', '\322'}, {'<', 'n', '\362'},
2225 {'<', 'R', '\330'}, {'<', 'r', '\370'},
2226 {';', 'A', '\241'}, {';', 'a', '\261'}, /* ogonek */
2227 {';', 'E', '\312'}, {';', 'e', '\332'},
2228 {'\'', 'Z', '\254'}, {'\'', 'z', '\274'}, /* acute */
2229 {'\'', 'R', '\300'}, {'\'', 'r', '\340'},
2230 {'\'', 'L', '\305'}, {'\'', 'l', '\345'},
2231 {'\'', 'C', '\306'}, {'\'', 'c', '\346'},
2232 {'\'', 'N', '\321'}, {'\'', 'n', '\361'},
2233 /* collision whith S, from iso-8859-9 !!! */
2234 {',', 'S', '\252'}, {',', 's', '\272'}, /* cedilla */
2235 {',', 'T', '\336'}, {',', 't', '\376'},
2236 {'.', 'Z', '\257'}, {'.', 'z', '\277'}, /* dot above */
2237 {'/', 'L', '\243'}, {'/', 'l', '\263'}, /* slash */
2238 {'/', 'D', '\320'}, {'/', 'd', '\360'},
2239 {'(', 'A', '\303'}, {'(', 'a', '\343'}, /* breve */
2240 {'\275', 'O', '\325'}, {'\275', 'o', '\365'}, /* double acute */
2241 {'\275', 'U', '\334'}, {'\275', 'u', '\374'},
2242 {'0', 'U', '\332'}, {'0', 'u', '\372'}, /* ring above */
2243 /* iso-8859-3 uses this */
2244 {'/', 'H', '\241'}, {'/', 'h', '\261'}, /* slash */
2245 {'>', 'H', '\246'}, {'>', 'h', '\266'}, /* circumflex */
2246 {'>', 'J', '\254'}, {'>', 'j', '\274'},
2247 {'>', 'C', '\306'}, {'>', 'c', '\346'},
2248 {'>', 'G', '\330'}, {'>', 'g', '\370'},
2249 {'>', 'S', '\336'}, {'>', 's', '\376'},
2250 /* collision whith G( from iso-8859-9 !!! */
2251 {'(', 'G', '\253'}, {'(', 'g', '\273'}, /* breve */
2252 {'(', 'U', '\335'}, {'(', 'u', '\375'},
2253 /* collision whith I. from iso-8859-3 !!! */
2254 {'.', 'I', '\251'}, {'.', 'i', '\271'}, /* dot above */
2255 {'.', 'C', '\305'}, {'.', 'c', '\345'},
2256 {'.', 'G', '\325'}, {'.', 'g', '\365'},
2257 /* iso-8859-4 uses this */
2258 {',', 'R', '\243'}, {',', 'r', '\263'}, /* cedilla */
2259 {',', 'L', '\246'}, {',', 'l', '\266'},
2260 {',', 'G', '\253'}, {',', 'g', '\273'},
2261 {',', 'N', '\321'}, {',', 'n', '\361'},
2262 {',', 'K', '\323'}, {',', 'k', '\363'},
2263 {'~', 'I', '\245'}, {'~', 'i', '\265'}, /* tilde */
2264 {'-', 'E', '\252'}, {'-', 'e', '\272'}, /* macron */
2265 {'-', 'A', '\300'}, {'-', 'a', '\340'},
2266 {'-', 'I', '\317'}, {'-', 'i', '\357'},
2267 {'-', 'O', '\322'}, {'-', 'o', '\362'},
2268 {'-', 'U', '\336'}, {'-', 'u', '\376'},
2269 {'/', 'T', '\254'}, {'/', 't', '\274'}, /* slash */
2270 {'.', 'E', '\314'}, {'.', 'e', '\344'}, /* dot above */
2271 {';', 'I', '\307'}, {';', 'i', '\347'}, /* ogonek */
2272 {';', 'U', '\331'}, {';', 'u', '\371'},
2273 /* iso-8859-9 uses this */
2274 /* iso-8859-9 has really bad choosen G( S, and I. as they collide
2275 * whith the same letters on other iso-8859-x (that is they are on
2276 * different places :-( ), if you use turkish uncomment these and
2277 * comment out the lines in iso-8859-2 and iso-8859-3 sections
2278 * FIXME: should be dynamic according to chosen language
2279 * if/when Wine has turkish support.
2281 /* collision whith G( from iso-8859-3 !!! */
2282 /* {'(', 'G', '\320'}, {'(', 'g', '\360'}, */ /* breve */
2283 /* collision whith S, from iso-8859-2 !!! */
2284 /* {',', 'S', '\336'}, {',', 's', '\376'}, */ /* cedilla */
2285 /* collision whith I. from iso-8859-3 !!! */
2286 /* {'.', 'I', '\335'}, {'.', 'i', '\375'}, */ /* dot above */
2290 /***********************************************************************
2291 * MSG_DoTranslateMessage
2293 * Implementation of TranslateMessage.
2295 * TranslateMessage translates virtual-key messages into character-messages,
2296 * as follows :
2297 * WM_KEYDOWN/WM_KEYUP combinations produce a WM_CHAR or WM_DEADCHAR message.
2298 * ditto replacing WM_* with WM_SYS*
2299 * This produces WM_CHAR messages only for keys mapped to ASCII characters
2300 * by the keyboard driver.
2302 static BOOL MSG_DoTranslateMessage( UINT message, HWND hwnd,
2303 WPARAM wParam, LPARAM lParam )
2305 static int dead_char;
2306 WCHAR wp[2];
2308 if (message != WM_MOUSEMOVE && message != WM_TIMER)
2309 TRACE("(%s, %04X, %08lX)\n",
2310 SPY_GetMsgName(message), wParam, lParam );
2311 if(message >= WM_KEYFIRST && message <= WM_KEYLAST)
2312 TRACE_(key)("(%s, %04X, %08lX)\n",
2313 SPY_GetMsgName(message), wParam, lParam );
2315 if ((message != WM_KEYDOWN) && (message != WM_SYSKEYDOWN)) return FALSE;
2317 TRACE_(key)("Translating key %s (%04x), scancode %02x\n",
2318 SPY_GetVKeyName(wParam), wParam, LOBYTE(HIWORD(lParam)));
2320 /* FIXME : should handle ToUnicode yielding 2 */
2321 switch (ToUnicode(wParam, HIWORD(lParam), QueueKeyStateTable, wp, 2, 0))
2323 case 1:
2324 message = (message == WM_KEYDOWN) ? WM_CHAR : WM_SYSCHAR;
2325 /* Should dead chars handling go in ToAscii ? */
2326 if (dead_char)
2328 int i;
2330 if (wp[0] == ' ') wp[0] = dead_char;
2331 if (dead_char == 0xa2) dead_char = '(';
2332 else if (dead_char == 0xa8) dead_char = '"';
2333 else if (dead_char == 0xb2) dead_char = ';';
2334 else if (dead_char == 0xb4) dead_char = '\'';
2335 else if (dead_char == 0xb7) dead_char = '<';
2336 else if (dead_char == 0xb8) dead_char = ',';
2337 else if (dead_char == 0xff) dead_char = '.';
2338 for (i = 0; i < sizeof(accent_chars)/sizeof(accent_chars[0]); i++)
2339 if ((accent_chars[i].ac_accent == dead_char) &&
2340 (accent_chars[i].ac_char == wp[0]))
2342 wp[0] = accent_chars[i].ac_result;
2343 break;
2345 dead_char = 0;
2347 TRACE_(key)("1 -> PostMessage(%s)\n", SPY_GetMsgName(message));
2348 PostMessageW( hwnd, message, wp[0], lParam );
2349 return TRUE;
2351 case -1:
2352 message = (message == WM_KEYDOWN) ? WM_DEADCHAR : WM_SYSDEADCHAR;
2353 dead_char = wp[0];
2354 TRACE_(key)("-1 -> PostMessage(%s)\n", SPY_GetMsgName(message));
2355 PostMessageW( hwnd, message, wp[0], lParam );
2356 return TRUE;
2358 return FALSE;
2362 /***********************************************************************
2363 * TranslateMessage (USER.113)
2365 BOOL16 WINAPI TranslateMessage16( const MSG16 *msg )
2367 return MSG_DoTranslateMessage( msg->message, msg->hwnd,
2368 msg->wParam, msg->lParam );
2372 /***********************************************************************
2373 * TranslateMessage32 (USER.821)
2375 BOOL16 WINAPI TranslateMessage32_16( const MSG32_16 *msg, BOOL16 wHaveParamHigh )
2377 WPARAM wParam;
2379 if (wHaveParamHigh)
2380 wParam = MAKELONG(msg->msg.wParam, msg->wParamHigh);
2381 else
2382 wParam = (WPARAM)msg->msg.wParam;
2384 return MSG_DoTranslateMessage( msg->msg.message, msg->msg.hwnd,
2385 wParam, msg->msg.lParam );
2388 /***********************************************************************
2389 * TranslateMessage (USER32.@)
2391 BOOL WINAPI TranslateMessage( const MSG *msg )
2393 return MSG_DoTranslateMessage( msg->message, msg->hwnd,
2394 msg->wParam, msg->lParam );
2398 /***********************************************************************
2399 * DispatchMessage (USER.114)
2401 LONG WINAPI DispatchMessage16( const MSG16* msg )
2403 WND * wndPtr;
2404 LONG retval;
2405 int painting;
2407 /* Process timer messages */
2408 if ((msg->message == WM_TIMER) || (msg->message == WM_SYSTIMER))
2410 if (msg->lParam)
2412 /* before calling window proc, verify whether timer is still valid;
2413 there's a slim chance that the application kills the timer
2414 between GetMessage and DispatchMessage API calls */
2415 if (!TIMER_IsTimerValid(msg->hwnd, (UINT) msg->wParam, (HWINDOWPROC) msg->lParam))
2416 return 0; /* invalid winproc */
2418 return CallWindowProc16( (WNDPROC16)msg->lParam, msg->hwnd,
2419 msg->message, msg->wParam, GetTickCount() );
2423 if (!msg->hwnd) return 0;
2424 if (!(wndPtr = WIN_FindWndPtr( msg->hwnd ))) return 0;
2425 if (!wndPtr->winproc)
2427 retval = 0;
2428 goto END;
2430 painting = (msg->message == WM_PAINT);
2431 if (painting) wndPtr->flags |= WIN_NEEDS_BEGINPAINT;
2433 SPY_EnterMessage( SPY_DISPATCHMESSAGE16, msg->hwnd, msg->message,
2434 msg->wParam, msg->lParam );
2435 retval = CallWindowProc16( (WNDPROC16)wndPtr->winproc,
2436 msg->hwnd, msg->message,
2437 msg->wParam, msg->lParam );
2438 SPY_ExitMessage( SPY_RESULT_OK16, msg->hwnd, msg->message, retval,
2439 msg->wParam, msg->lParam );
2441 WIN_ReleaseWndPtr(wndPtr);
2442 wndPtr = WIN_FindWndPtr(msg->hwnd);
2443 if (painting && wndPtr &&
2444 (wndPtr->flags & WIN_NEEDS_BEGINPAINT) && wndPtr->hrgnUpdate)
2446 ERR("BeginPaint not called on WM_PAINT for hwnd %04x!\n",
2447 msg->hwnd);
2448 wndPtr->flags &= ~WIN_NEEDS_BEGINPAINT;
2449 /* Validate the update region to avoid infinite WM_PAINT loop */
2450 ValidateRect( msg->hwnd, NULL );
2452 END:
2453 WIN_ReleaseWndPtr(wndPtr);
2454 return retval;
2458 /***********************************************************************
2459 * DispatchMessage32 (USER.822)
2461 LONG WINAPI DispatchMessage32_16( const MSG32_16* lpmsg16_32, BOOL16 wHaveParamHigh )
2463 if (wHaveParamHigh == FALSE)
2464 return DispatchMessage16(&(lpmsg16_32->msg));
2465 else
2467 MSG msg;
2469 msg.hwnd = lpmsg16_32->msg.hwnd;
2470 msg.message = lpmsg16_32->msg.message;
2471 msg.wParam = MAKELONG(lpmsg16_32->msg.wParam, lpmsg16_32->wParamHigh);
2472 msg.lParam = lpmsg16_32->msg.lParam;
2473 msg.time = lpmsg16_32->msg.time;
2474 msg.pt.x = (INT)lpmsg16_32->msg.pt.x;
2475 msg.pt.y = (INT)lpmsg16_32->msg.pt.y;
2476 return DispatchMessageA(&msg);
2480 /***********************************************************************
2481 * DispatchMessageA (USER32.@)
2483 LONG WINAPI DispatchMessageA( const MSG* msg )
2485 WND * wndPtr;
2486 LONG retval;
2487 int painting;
2489 /* Process timer messages */
2490 if ((msg->message == WM_TIMER) || (msg->message == WM_SYSTIMER))
2492 if (msg->lParam)
2494 /* HOOK_CallHooks32A( WH_CALLWNDPROC, HC_ACTION, 0, FIXME ); */
2496 /* before calling window proc, verify whether timer is still valid;
2497 there's a slim chance that the application kills the timer
2498 between GetMessage and DispatchMessage API calls */
2499 if (!TIMER_IsTimerValid(msg->hwnd, (UINT) msg->wParam, (HWINDOWPROC) msg->lParam))
2500 return 0; /* invalid winproc */
2502 return CallWindowProcA( (WNDPROC)msg->lParam, msg->hwnd,
2503 msg->message, msg->wParam, GetTickCount() );
2507 if (!msg->hwnd) return 0;
2508 if (!(wndPtr = WIN_FindWndPtr( msg->hwnd ))) return 0;
2509 if (!wndPtr->winproc)
2511 retval = 0;
2512 goto END;
2514 painting = (msg->message == WM_PAINT);
2515 if (painting) wndPtr->flags |= WIN_NEEDS_BEGINPAINT;
2516 /* HOOK_CallHooks32A( WH_CALLWNDPROC, HC_ACTION, 0, FIXME ); */
2518 SPY_EnterMessage( SPY_DISPATCHMESSAGE, msg->hwnd, msg->message,
2519 msg->wParam, msg->lParam );
2520 retval = CallWindowProcA( (WNDPROC)wndPtr->winproc,
2521 msg->hwnd, msg->message,
2522 msg->wParam, msg->lParam );
2523 SPY_ExitMessage( SPY_RESULT_OK, msg->hwnd, msg->message, retval,
2524 msg->wParam, msg->lParam );
2526 WIN_ReleaseWndPtr(wndPtr);
2527 wndPtr = WIN_FindWndPtr(msg->hwnd);
2529 if (painting && wndPtr &&
2530 (wndPtr->flags & WIN_NEEDS_BEGINPAINT) && wndPtr->hrgnUpdate)
2532 ERR("BeginPaint not called on WM_PAINT for hwnd %04x!\n",
2533 msg->hwnd);
2534 wndPtr->flags &= ~WIN_NEEDS_BEGINPAINT;
2535 /* Validate the update region to avoid infinite WM_PAINT loop */
2536 PAINT_RedrawWindow( wndPtr->hwndSelf, NULL, 0,
2537 RDW_FRAME | RDW_VALIDATE | RDW_NOCHILDREN | RDW_NOINTERNALPAINT, 0 );
2539 END:
2540 WIN_ReleaseWndPtr(wndPtr);
2541 return retval;
2545 /***********************************************************************
2546 * DispatchMessageW (USER32.@) Process Message
2548 * Process the message specified in the structure *_msg_.
2550 * If the lpMsg parameter points to a WM_TIMER message and the
2551 * parameter of the WM_TIMER message is not NULL, the lParam parameter
2552 * points to the function that is called instead of the window
2553 * procedure.
2555 * The message must be valid.
2557 * RETURNS
2559 * DispatchMessage() returns the result of the window procedure invoked.
2561 * CONFORMANCE
2563 * ECMA-234, Win32
2566 LONG WINAPI DispatchMessageW( const MSG* msg )
2568 WND * wndPtr;
2569 LONG retval;
2570 int painting;
2572 /* Process timer messages */
2573 if ((msg->message == WM_TIMER) || (msg->message == WM_SYSTIMER))
2575 if (msg->lParam)
2577 /* HOOK_CallHooks32W( WH_CALLWNDPROC, HC_ACTION, 0, FIXME ); */
2579 /* before calling window proc, verify whether timer is still valid;
2580 there's a slim chance that the application kills the timer
2581 between GetMessage and DispatchMessage API calls */
2582 if (!TIMER_IsTimerValid(msg->hwnd, (UINT) msg->wParam, (HWINDOWPROC) msg->lParam))
2583 return 0; /* invalid winproc */
2585 return CallWindowProcW( (WNDPROC)msg->lParam, msg->hwnd,
2586 msg->message, msg->wParam, GetTickCount() );
2590 if (!msg->hwnd) return 0;
2591 if (!(wndPtr = WIN_FindWndPtr( msg->hwnd ))) return 0;
2592 if (!wndPtr->winproc)
2594 retval = 0;
2595 goto END;
2597 painting = (msg->message == WM_PAINT);
2598 if (painting) wndPtr->flags |= WIN_NEEDS_BEGINPAINT;
2599 /* HOOK_CallHooks32W( WH_CALLWNDPROC, HC_ACTION, 0, FIXME ); */
2601 SPY_EnterMessage( SPY_DISPATCHMESSAGE, msg->hwnd, msg->message,
2602 msg->wParam, msg->lParam );
2603 retval = CallWindowProcW( (WNDPROC)wndPtr->winproc,
2604 msg->hwnd, msg->message,
2605 msg->wParam, msg->lParam );
2606 SPY_ExitMessage( SPY_RESULT_OK, msg->hwnd, msg->message, retval,
2607 msg->wParam, msg->lParam );
2609 WIN_ReleaseWndPtr(wndPtr);
2610 wndPtr = WIN_FindWndPtr(msg->hwnd);
2612 if (painting && wndPtr &&
2613 (wndPtr->flags & WIN_NEEDS_BEGINPAINT) && wndPtr->hrgnUpdate)
2615 ERR("BeginPaint not called on WM_PAINT for hwnd %04x!\n",
2616 msg->hwnd);
2617 wndPtr->flags &= ~WIN_NEEDS_BEGINPAINT;
2618 /* Validate the update region to avoid infinite WM_PAINT loop */
2619 ValidateRect( msg->hwnd, NULL );
2621 END:
2622 WIN_ReleaseWndPtr(wndPtr);
2623 return retval;
2627 /***********************************************************************
2628 * RegisterWindowMessage (USER.118)
2629 * RegisterWindowMessageA (USER32.@)
2631 WORD WINAPI RegisterWindowMessageA( LPCSTR str )
2633 TRACE("%s\n", str );
2634 return GlobalAddAtomA( str );
2638 /***********************************************************************
2639 * RegisterWindowMessageW (USER32.@)
2641 WORD WINAPI RegisterWindowMessageW( LPCWSTR str )
2643 TRACE("%p\n", str );
2644 return GlobalAddAtomW( str );
2648 /***********************************************************************
2649 * GetCurrentTime (USER.15)
2651 * (effectively identical to GetTickCount)
2653 DWORD WINAPI GetCurrentTime16(void)
2655 return GetTickCount();
2659 /***********************************************************************
2660 * InSendMessage (USER.192)
2662 BOOL16 WINAPI InSendMessage16(void)
2664 return InSendMessage();
2668 /***********************************************************************
2669 * InSendMessage (USER32.@)
2671 BOOL WINAPI InSendMessage(void)
2673 MESSAGEQUEUE *queue;
2674 BOOL ret;
2676 if (!(queue = QUEUE_Lock( GetFastQueue16() )))
2677 return 0;
2678 ret = (BOOL)queue->smWaiting;
2680 QUEUE_Unlock( queue );
2681 return ret;
2684 /***********************************************************************
2685 * BroadcastSystemMessage (USER32.@)
2687 LONG WINAPI BroadcastSystemMessage(
2688 DWORD dwFlags,LPDWORD recipients,UINT uMessage,WPARAM wParam,
2689 LPARAM lParam
2691 FIXME_(sendmsg)("(%08lx,%08lx,%08x,%08x,%08lx): stub!\n",
2692 dwFlags,*recipients,uMessage,wParam,lParam
2694 return 0;
2697 /***********************************************************************
2698 * SendNotifyMessageA (USER32.@)
2700 BOOL WINAPI SendNotifyMessageA(HWND hwnd,UINT msg,WPARAM wParam,LPARAM lParam)
2702 return MSG_SendMessage(hwnd, msg, wParam, lParam, INFINITE,
2703 SMSG_WIN32, NULL);
2706 /***********************************************************************
2707 * SendNotifyMessageW (USER32.@)
2709 BOOL WINAPI SendNotifyMessageW(HWND hwnd,UINT msg,WPARAM wParam,LPARAM lParam)
2711 return MSG_SendMessage(hwnd, msg, wParam, lParam, INFINITE,
2712 SMSG_WIN32 | SMSG_UNICODE, NULL);
2715 /***********************************************************************
2716 * SendMessageCallbackA (USER32.@)
2717 * FIXME: It's like PostMessage. The callback gets called when the message
2718 * is processed. We have to modify the message processing for an exact
2719 * implementation...
2720 * The callback is only called when the thread that called us calls one of
2721 * Get/Peek/WaitMessage.
2723 BOOL WINAPI SendMessageCallbackA(
2724 HWND hWnd,UINT Msg,WPARAM wParam,LPARAM lParam,
2725 FARPROC lpResultCallBack,DWORD dwData)
2727 FIXME("(0x%04x,0x%04x,0x%08x,0x%08lx,%p,0x%08lx),stub!\n",
2728 hWnd,Msg,wParam,lParam,lpResultCallBack,dwData);
2729 if ( hWnd == HWND_BROADCAST)
2730 { PostMessageA( hWnd, Msg, wParam, lParam);
2731 FIXME("Broadcast: Callback will not be called!\n");
2732 return TRUE;
2734 (lpResultCallBack)( hWnd, Msg, dwData, SendMessageA ( hWnd, Msg, wParam, lParam ));
2735 return TRUE;
2737 /***********************************************************************
2738 * SendMessageCallbackW (USER32.@)
2739 * FIXME: see SendMessageCallbackA.
2741 BOOL WINAPI SendMessageCallbackW(
2742 HWND hWnd,UINT Msg,WPARAM wParam,LPARAM lParam,
2743 FARPROC lpResultCallBack,DWORD dwData)
2745 FIXME("(0x%04x,0x%04x,0x%08x,0x%08lx,%p,0x%08lx),stub!\n",
2746 hWnd,Msg,wParam,lParam,lpResultCallBack,dwData);
2747 if ( hWnd == HWND_BROADCAST)
2748 { PostMessageW( hWnd, Msg, wParam, lParam);
2749 FIXME("Broadcast: Callback will not be called!\n");
2750 return TRUE;
2752 (lpResultCallBack)( hWnd, Msg, dwData, SendMessageA ( hWnd, Msg, wParam, lParam ));
2753 return TRUE;