Authors: Chris Morgan <cmorgan@wpi.edu>, James Abbatiello <abbeyj@wpi.edu>
[wine/multimedia.git] / windows / message.c
blob090730eea2fe0d7c9679a2fa1cbdde40457b6d36
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 "task.h"
26 #include "process.h"
27 #include "selectors.h"
28 #include "thread.h"
29 #include "options.h"
30 #include "menu.h"
31 #include "struct32.h"
32 #include "debugtools.h"
34 DEFAULT_DEBUG_CHANNEL(msg)
35 DECLARE_DEBUG_CHANNEL(key)
36 DECLARE_DEBUG_CHANNEL(sendmsg)
38 #define WM_NCMOUSEFIRST WM_NCMOUSEMOVE
39 #define WM_NCMOUSELAST WM_NCMBUTTONDBLCLK
42 typedef enum { SYSQ_MSG_ABANDON, SYSQ_MSG_SKIP,
43 SYSQ_MSG_ACCEPT, SYSQ_MSG_CONTINUE } SYSQ_STATUS;
45 extern HQUEUE16 hCursorQueue; /* queue.c */
47 DWORD MSG_WineStartTicks; /* Ticks at Wine startup */
49 static UINT doubleClickSpeed = 452;
51 /***********************************************************************
52 * MSG_CheckFilter
54 static BOOL MSG_CheckFilter(DWORD uMsg, DWORD first, DWORD last)
56 if( first || last )
57 return (uMsg >= first && uMsg <= last);
58 return TRUE;
61 /***********************************************************************
62 * MSG_SendParentNotify
64 * Send a WM_PARENTNOTIFY to all ancestors of the given window, unless
65 * the window has the WS_EX_NOPARENTNOTIFY style.
67 static void MSG_SendParentNotify(WND* wndPtr, WORD event, WORD idChild, LPARAM lValue)
69 #define lppt ((LPPOINT16)&lValue)
71 /* pt has to be in the client coordinates of the parent window */
72 WND *tmpWnd = WIN_LockWndPtr(wndPtr);
74 MapWindowPoints16( 0, tmpWnd->hwndSelf, lppt, 1 );
75 while (tmpWnd)
77 if (!(tmpWnd->dwStyle & WS_CHILD) || (tmpWnd->dwExStyle & WS_EX_NOPARENTNOTIFY))
79 WIN_ReleaseWndPtr(tmpWnd);
80 break;
82 lppt->x += tmpWnd->rectClient.left;
83 lppt->y += tmpWnd->rectClient.top;
84 WIN_UpdateWndPtr(&tmpWnd,tmpWnd->parent);
85 SendMessageA( tmpWnd->hwndSelf, WM_PARENTNOTIFY,
86 MAKEWPARAM( event, idChild ), lValue );
89 #undef lppt
93 /***********************************************************************
94 * MSG_TranslateMouseMsg
96 * Translate an mouse hardware event into a real mouse message.
98 * Returns:
100 * SYSQ_MSG_ABANDON - abandon the peek message loop
101 * SYSQ_MSG_CONTINUE - leave the message in the queue and
102 * continue with the translation loop
103 * SYSQ_MSG_ACCEPT - proceed to process the translated message
105 static DWORD MSG_TranslateMouseMsg( HWND hTopWnd, DWORD first, DWORD last,
106 MSG *msg, BOOL remove, WND* pWndScope,
107 INT16 *pHitTest, POINT16 *pScreen_pt, BOOL *pmouseClick )
109 static DWORD dblclk_time_limit = 0;
110 static UINT16 clk_message = 0;
111 static HWND16 clk_hwnd = 0;
112 static POINT16 clk_pos = { 0, 0 };
114 WND *pWnd;
115 HWND hWnd;
116 INT16 ht, hittest;
117 UINT message = msg->message;
118 POINT16 screen_pt, pt;
119 HANDLE16 hQ = GetFastQueue16();
120 MESSAGEQUEUE *queue = (MESSAGEQUEUE *)QUEUE_Lock(hQ);
121 BOOL mouseClick = ((message == WM_LBUTTONDOWN) ||
122 (message == WM_RBUTTONDOWN) ||
123 (message == WM_MBUTTONDOWN))?1:0;
124 DWORD retvalue;
126 /* Find the window to dispatch this mouse message to */
128 CONV_POINT32TO16( &msg->pt, &pt );
130 hWnd = GetCapture();
132 /* If no capture HWND, find window which contains the mouse position.
133 * Also find the position of the cursor hot spot (hittest) */
134 if( !hWnd )
136 ht = hittest = WINPOS_WindowFromPoint( pWndScope, pt, &pWnd );
137 if( !pWnd ) pWnd = WIN_GetDesktop();
138 else WIN_LockWndPtr(pWnd);
139 hWnd = pWnd->hwndSelf;
141 else
143 ht = hittest = HTCLIENT;
144 pWnd = WIN_FindWndPtr(hWnd);
145 if (queue)
146 ht = PERQDATA_GetCaptureInfo( queue->pQData );
149 /* Save hittest for return */
150 *pHitTest = hittest;
152 /* stop if not the right queue */
154 if (pWnd->hmemTaskQ != hQ)
156 /* Not for the current task */
157 if (queue) QUEUE_ClearWakeBit( queue, QS_MOUSE );
158 /* Wake up the other task */
159 QUEUE_Unlock( queue );
160 queue = (MESSAGEQUEUE *)QUEUE_Lock( pWnd->hmemTaskQ );
161 if (queue) QUEUE_SetWakeBit( queue, QS_MOUSE );
163 QUEUE_Unlock( queue );
164 retvalue = SYSQ_MSG_ABANDON;
165 goto END;
168 /* check if hWnd is within hWndScope */
170 if( hTopWnd && hWnd != hTopWnd )
171 if( !IsChild(hTopWnd, hWnd) )
173 QUEUE_Unlock( queue );
174 retvalue = SYSQ_MSG_CONTINUE;
175 goto END;
178 /* Was it a mouse click message */
179 if( mouseClick )
181 /* translate double clicks -
182 * note that ...MOUSEMOVEs can slip in between
183 * ...BUTTONDOWN and ...BUTTONDBLCLK messages */
185 if(GetClassLongA(hWnd, GCL_STYLE) & CS_DBLCLKS || ht != HTCLIENT )
187 if ((message == clk_message) && (hWnd == clk_hwnd) &&
188 (msg->time - dblclk_time_limit < doubleClickSpeed) &&
189 (abs(msg->pt.x - clk_pos.x) < GetSystemMetrics(SM_CXDOUBLECLK)/2) &&
190 (abs(msg->pt.y - clk_pos.y) < GetSystemMetrics(SM_CYDOUBLECLK)/2))
192 message += (WM_LBUTTONDBLCLK - WM_LBUTTONDOWN);
193 mouseClick++; /* == 2 */
197 /* save mouse position */
198 screen_pt = pt;
199 *pScreen_pt = pt;
201 if (hittest != HTCLIENT)
203 message += WM_NCMOUSEMOVE - WM_MOUSEMOVE;
204 msg->wParam = hittest;
206 else
207 ScreenToClient16( hWnd, &pt );
209 /* check message filter */
211 if (!MSG_CheckFilter(message, first, last))
213 QUEUE_Unlock(queue);
214 retvalue = SYSQ_MSG_CONTINUE;
215 goto END;
218 /* Update global hCursorQueue */
219 hCursorQueue = queue->self;
221 /* Update static double click conditions */
222 if( remove && mouseClick )
224 if( mouseClick == 1 )
226 /* set conditions */
227 dblclk_time_limit = msg->time;
228 clk_message = msg->message;
229 clk_hwnd = hWnd;
230 clk_pos = screen_pt;
231 } else
232 /* got double click - zero them out */
233 dblclk_time_limit = clk_hwnd = 0;
236 QUEUE_Unlock(queue);
238 /* Update message params */
239 msg->hwnd = hWnd;
240 msg->message = message;
241 msg->lParam = MAKELONG( pt.x, pt.y );
242 retvalue = SYSQ_MSG_ACCEPT;
244 END:
245 WIN_ReleaseWndPtr(pWnd);
247 /* Return mouseclick flag */
248 *pmouseClick = mouseClick;
250 return retvalue;
254 /***********************************************************************
255 * MSG_ProcessMouseMsg
257 * Processes a translated mouse hardware event.
258 * The passed in msg structure should contain the updated hWnd,
259 * lParam, wParam and message fields from MSG_TranslateMouseMsg.
261 * Returns:
263 * SYSQ_MSG_SKIP - Message should be skipped entirely (in this case
264 * HIWORD contains hit test code). Continue translating..
265 * SYSQ_MSG_ACCEPT - the translated message must be passed to the user
266 * MSG_PeekHardwareMsg should return TRUE.
268 static DWORD MSG_ProcessMouseMsg( MSG *msg, BOOL remove, INT16 hittest,
269 POINT16 screen_pt, BOOL mouseClick )
271 WND *pWnd;
272 HWND hWnd = msg->hwnd;
273 INT16 sendSC = (GetCapture() == 0);
274 UINT message = msg->message;
275 BOOL eatMsg = FALSE;
276 DWORD retvalue;
278 pWnd = WIN_FindWndPtr(hWnd);
280 /* call WH_MOUSE */
282 if (HOOK_IsHooked( WH_MOUSE ))
284 SYSQ_STATUS ret = 0;
285 MOUSEHOOKSTRUCT16 *hook = SEGPTR_NEW(MOUSEHOOKSTRUCT16);
286 if( hook )
288 hook->pt = screen_pt;
289 hook->hwnd = hWnd;
290 hook->wHitTestCode = hittest;
291 hook->dwExtraInfo = 0;
292 ret = HOOK_CallHooks16( WH_MOUSE, remove ? HC_ACTION : HC_NOREMOVE,
293 message, (LPARAM)SEGPTR_GET(hook) );
294 SEGPTR_FREE(hook);
296 if( ret )
298 retvalue = MAKELONG((INT16)SYSQ_MSG_SKIP, hittest);
299 goto END;
304 if ((hittest == HTERROR) || (hittest == HTNOWHERE))
305 eatMsg = sendSC = 1;
306 else if( remove && mouseClick )
308 HWND hwndTop = WIN_GetTopParent( hWnd );
310 if( sendSC )
312 /* Send the WM_PARENTNOTIFY,
313 * note that even for double/nonclient clicks
314 * notification message is still WM_L/M/RBUTTONDOWN.
317 MSG_SendParentNotify( pWnd, msg->message & 0xffff, 0, MAKELPARAM(screen_pt.x, screen_pt.y) );
319 /* Activate the window if needed */
321 if (hWnd != GetActiveWindow() && hWnd != GetDesktopWindow())
323 LONG ret = SendMessageA( hWnd, WM_MOUSEACTIVATE, hwndTop,
324 MAKELONG( hittest, message ) );
326 if ((ret == MA_ACTIVATEANDEAT) || (ret == MA_NOACTIVATEANDEAT))
327 eatMsg = TRUE;
329 if (((ret == MA_ACTIVATE) || (ret == MA_ACTIVATEANDEAT))
330 && hwndTop != GetForegroundWindow() )
332 if (!WINPOS_SetActiveWindow( hwndTop, TRUE , TRUE ))
333 eatMsg = TRUE;
337 } else sendSC = (remove && sendSC);
339 /* Send the WM_SETCURSOR message */
341 if (sendSC)
343 UINT uSCMessage = message;
345 /* Windows sends the normal mouse message as the message parameter
346 in the WM_SETCURSOR message even if it's non-client mouse message */
348 if (uSCMessage >= WM_NCMOUSEFIRST && uSCMessage <= WM_NCMOUSELAST)
349 uSCMessage += WM_MOUSEFIRST - WM_NCMOUSEFIRST;
350 SendMessageA( hWnd, WM_SETCURSOR, hWnd,
351 MAKELONG( hittest, uSCMessage));
353 if (eatMsg)
355 retvalue = MAKELONG( (UINT16)SYSQ_MSG_SKIP, hittest);
356 goto END;
359 retvalue = SYSQ_MSG_ACCEPT;
360 END:
361 WIN_ReleaseWndPtr(pWnd);
363 return retvalue;
367 /***********************************************************************
368 * MSG_TranslateKbdMsg
370 * Translate an keyboard hardware event into a real message.
372 static DWORD MSG_TranslateKbdMsg( HWND hTopWnd, DWORD first, DWORD last,
373 MSG *msg, BOOL remove )
375 WORD message = msg->message;
376 HWND hWnd = GetFocus();
377 WND *pWnd;
379 /* Should check Ctrl-Esc and PrintScreen here */
381 if (!hWnd)
383 /* Send the message to the active window instead, */
384 /* translating messages to their WM_SYS equivalent */
386 hWnd = GetActiveWindow();
388 if( message < WM_SYSKEYDOWN )
389 message += WM_SYSKEYDOWN - WM_KEYDOWN;
391 pWnd = WIN_FindWndPtr( hWnd );
392 if (pWnd && (pWnd->hmemTaskQ != GetFastQueue16()))
394 /* Not for the current task */
395 MESSAGEQUEUE *queue = (MESSAGEQUEUE *)QUEUE_Lock( GetFastQueue16() );
396 if (queue) QUEUE_ClearWakeBit( queue, QS_KEY );
397 QUEUE_Unlock( queue );
399 /* Wake up the other task */
400 queue = (MESSAGEQUEUE *)QUEUE_Lock( pWnd->hmemTaskQ );
401 if (queue) QUEUE_SetWakeBit( queue, QS_KEY );
402 QUEUE_Unlock( queue );
403 WIN_ReleaseWndPtr(pWnd);
404 return SYSQ_MSG_ABANDON;
406 WIN_ReleaseWndPtr(pWnd);
408 if (hTopWnd && hWnd != hTopWnd)
409 if (!IsChild(hTopWnd, hWnd)) return SYSQ_MSG_CONTINUE;
410 if (!MSG_CheckFilter(message, first, last)) return SYSQ_MSG_CONTINUE;
412 msg->hwnd = hWnd;
413 msg->message = message;
415 return SYSQ_MSG_ACCEPT;
419 /***********************************************************************
420 * MSG_ProcessKbdMsg
422 * Processes a translated keyboard message
424 static DWORD MSG_ProcessKbdMsg( MSG *msg, BOOL remove )
426 /* Handle F1 key by sending out WM_HELP message */
427 if ((msg->message == WM_KEYUP) &&
428 (msg->wParam == VK_F1) &&
429 remove &&
430 (msg->hwnd != GetDesktopWindow()) &&
431 !MENU_IsMenuActive())
433 HELPINFO hi;
434 WND *pWnd = WIN_FindWndPtr(msg->hwnd);
436 if (NULL != pWnd)
438 hi.cbSize = sizeof(HELPINFO);
439 hi.iContextType = HELPINFO_WINDOW;
440 hi.iCtrlId = pWnd->wIDmenu;
441 hi.hItemHandle = msg->hwnd;
442 hi.dwContextId = pWnd->helpContext;
443 hi.MousePos = msg->pt;
444 SendMessageA(msg->hwnd, WM_HELP, 0, (LPARAM)&hi);
446 WIN_ReleaseWndPtr(pWnd);
449 return (HOOK_CallHooks16( WH_KEYBOARD, remove ? HC_ACTION : HC_NOREMOVE,
450 LOWORD (msg->wParam), msg->lParam )
451 ? SYSQ_MSG_SKIP : SYSQ_MSG_ACCEPT);
455 /***********************************************************************
456 * MSG_JournalRecordMsg
458 * Build an EVENTMSG structure and call JOURNALRECORD hook
460 static void MSG_JournalRecordMsg( MSG *msg )
462 EVENTMSG *event = (EVENTMSG *) HeapAlloc(SystemHeap, 0, sizeof(EVENTMSG));
463 if (!event) return;
464 event->message = msg->message;
465 event->time = msg->time;
466 if ((msg->message >= WM_KEYFIRST) && (msg->message <= WM_KEYLAST))
468 event->paramL = (msg->wParam & 0xFF) | (HIWORD(msg->lParam) << 8);
469 event->paramH = msg->lParam & 0x7FFF;
470 if (HIWORD(msg->lParam) & 0x0100)
471 event->paramH |= 0x8000; /* special_key - bit */
472 HOOK_CallHooksA( WH_JOURNALRECORD, HC_ACTION, 0, (LPARAM)event );
474 else if ((msg->message >= WM_MOUSEFIRST) && (msg->message <= WM_MOUSELAST))
476 event->paramL = LOWORD(msg->lParam); /* X pos */
477 event->paramH = HIWORD(msg->lParam); /* Y pos */
478 ClientToScreen16( msg->hwnd, (LPPOINT16)&event->paramL );
479 HOOK_CallHooksA( WH_JOURNALRECORD, HC_ACTION, 0, (LPARAM)event );
481 else if ((msg->message >= WM_NCMOUSEFIRST) &&
482 (msg->message <= WM_NCMOUSELAST))
484 event->paramL = LOWORD(msg->lParam); /* X pos */
485 event->paramH = HIWORD(msg->lParam); /* Y pos */
486 event->message += WM_MOUSEMOVE-WM_NCMOUSEMOVE;/* give no info about NC area */
487 HOOK_CallHooksA( WH_JOURNALRECORD, HC_ACTION, 0, (LPARAM)event );
490 HeapFree(SystemHeap, 0, event);
493 /***********************************************************************
494 * MSG_JournalPlayBackMsg
496 * Get an EVENTMSG struct via call JOURNALPLAYBACK hook function
498 static int MSG_JournalPlayBackMsg(void)
500 EVENTMSG *tmpMsg;
501 long wtime,lParam,wParam;
502 WORD keyDown,i,result=0;
504 if ( HOOK_IsHooked( WH_JOURNALPLAYBACK ) )
506 tmpMsg = (EVENTMSG *) HeapAlloc(SystemHeap, 0, sizeof(EVENTMSG));
507 if (!tmpMsg) return result;
509 wtime=HOOK_CallHooksA( WH_JOURNALPLAYBACK, HC_GETNEXT, 0,
510 (LPARAM) tmpMsg );
511 /* TRACE(msg,"Playback wait time =%ld\n",wtime); */
512 if (wtime<=0)
514 wtime=0;
515 if ((tmpMsg->message>= WM_KEYFIRST) && (tmpMsg->message <= WM_KEYLAST))
517 wParam=tmpMsg->paramL & 0xFF;
518 lParam=MAKELONG(tmpMsg->paramH&0x7ffff,tmpMsg->paramL>>8);
519 if (tmpMsg->message == WM_KEYDOWN || tmpMsg->message == WM_SYSKEYDOWN)
521 for (keyDown=i=0; i<256 && !keyDown; i++)
522 if (InputKeyStateTable[i] & 0x80)
523 keyDown++;
524 if (!keyDown)
525 lParam |= 0x40000000;
526 AsyncKeyStateTable[wParam]=InputKeyStateTable[wParam] |= 0x80;
528 else /* WM_KEYUP, WM_SYSKEYUP */
530 lParam |= 0xC0000000;
531 AsyncKeyStateTable[wParam]=InputKeyStateTable[wParam] &= ~0x80;
533 if (InputKeyStateTable[VK_MENU] & 0x80)
534 lParam |= 0x20000000;
535 if (tmpMsg->paramH & 0x8000) /*special_key bit*/
536 lParam |= 0x01000000;
537 hardware_event( tmpMsg->message & 0xffff, LOWORD(wParam), lParam,
538 0, 0, tmpMsg->time, 0 );
540 else
542 if ((tmpMsg->message>= WM_MOUSEFIRST) && (tmpMsg->message <= WM_MOUSELAST))
544 switch (tmpMsg->message)
546 case WM_LBUTTONDOWN:
547 MouseButtonsStates[0]=AsyncMouseButtonsStates[0]=TRUE;break;
548 case WM_LBUTTONUP:
549 MouseButtonsStates[0]=AsyncMouseButtonsStates[0]=FALSE;break;
550 case WM_MBUTTONDOWN:
551 MouseButtonsStates[1]=AsyncMouseButtonsStates[1]=TRUE;break;
552 case WM_MBUTTONUP:
553 MouseButtonsStates[1]=AsyncMouseButtonsStates[1]=FALSE;break;
554 case WM_RBUTTONDOWN:
555 MouseButtonsStates[2]=AsyncMouseButtonsStates[2]=TRUE;break;
556 case WM_RBUTTONUP:
557 MouseButtonsStates[2]=AsyncMouseButtonsStates[2]=FALSE;break;
559 AsyncKeyStateTable[VK_LBUTTON]= InputKeyStateTable[VK_LBUTTON] = MouseButtonsStates[0] ? 0x80 : 0;
560 AsyncKeyStateTable[VK_MBUTTON]= InputKeyStateTable[VK_MBUTTON] = MouseButtonsStates[1] ? 0x80 : 0;
561 AsyncKeyStateTable[VK_RBUTTON]= InputKeyStateTable[VK_RBUTTON] = MouseButtonsStates[2] ? 0x80 : 0;
562 SetCursorPos(tmpMsg->paramL,tmpMsg->paramH);
563 lParam=MAKELONG(tmpMsg->paramL,tmpMsg->paramH);
564 wParam=0;
565 if (MouseButtonsStates[0]) wParam |= MK_LBUTTON;
566 if (MouseButtonsStates[1]) wParam |= MK_MBUTTON;
567 if (MouseButtonsStates[2]) wParam |= MK_RBUTTON;
568 hardware_event( tmpMsg->message & 0xffff, LOWORD (wParam), lParam,
569 tmpMsg->paramL, tmpMsg->paramH, tmpMsg->time, 0 );
572 HOOK_CallHooksA( WH_JOURNALPLAYBACK, HC_SKIP, 0,
573 (LPARAM) tmpMsg);
575 else
578 if( tmpMsg->message == WM_QUEUESYNC )
579 if (HOOK_IsHooked( WH_CBT ))
580 HOOK_CallHooksA( WH_CBT, HCBT_QS, 0, 0L);
582 result= QS_MOUSE | QS_KEY; /* ? */
584 HeapFree(SystemHeap, 0, tmpMsg);
586 return result;
589 /***********************************************************************
590 * MSG_PeekHardwareMsg
592 * Peek for a hardware message matching the hwnd and message filters.
594 static BOOL MSG_PeekHardwareMsg( MSG *msg, HWND hwnd, DWORD first, DWORD last,
595 BOOL remove )
597 /* FIXME: should deal with MSG32 instead of MSG16 */
599 DWORD status = SYSQ_MSG_ACCEPT;
600 MESSAGEQUEUE *sysMsgQueue = QUEUE_GetSysQueue();
601 enum { MOUSE_MSG = 0, KEYBOARD_MSG, HARDWARE_MSG } msgType;
602 QMSG *nextqmsg, *qmsg = 0;
603 BOOL bRet = FALSE;
605 EnterCriticalSection(&sysMsgQueue->cSection);
607 /* Loop through the Q and translate the message we wish to process
608 * while we own the lock. Based on the translation status (abandon/cont/accept)
609 * we then process the message accordingly
612 for ( qmsg = sysMsgQueue->firstMsg; qmsg; qmsg = nextqmsg )
614 INT16 hittest;
615 POINT16 screen_pt;
616 BOOL mouseClick;
618 *msg = qmsg->msg;
620 nextqmsg = qmsg->nextMsg;
622 /* Translate message */
624 if ((msg->message >= WM_MOUSEFIRST) && (msg->message <= WM_MOUSELAST))
626 HWND hWndScope = (HWND)qmsg->extraInfo;
627 WND *tmpWnd = (Options.managed && IsWindow(hWndScope) )
628 ? WIN_FindWndPtr(hWndScope) : WIN_GetDesktop();
630 status = MSG_TranslateMouseMsg(hwnd, first, last, msg, remove, tmpWnd,
631 &hittest, &screen_pt, &mouseClick );
632 msgType = MOUSE_MSG;
634 WIN_ReleaseWndPtr(tmpWnd);
637 else if ((msg->message >= WM_KEYFIRST) && (msg->message <= WM_KEYLAST))
639 status = MSG_TranslateKbdMsg(hwnd, first, last, msg, remove);
640 msgType = KEYBOARD_MSG;
642 else /* Non-standard hardware event */
644 HARDWAREHOOKSTRUCT16 *hook;
645 msgType = HARDWARE_MSG;
646 if ((hook = SEGPTR_NEW(HARDWAREHOOKSTRUCT16)))
648 BOOL ret;
649 hook->hWnd = msg->hwnd;
650 hook->wMessage = msg->message & 0xffff;
651 hook->wParam = LOWORD (msg->wParam);
652 hook->lParam = msg->lParam;
653 ret = HOOK_CallHooks16( WH_HARDWARE,
654 remove ? HC_ACTION : HC_NOREMOVE,
655 0, (LPARAM)SEGPTR_GET(hook) );
656 SEGPTR_FREE(hook);
657 if (ret)
659 QUEUE_RemoveMsg( sysMsgQueue, qmsg );
660 continue;
662 status = SYSQ_MSG_ACCEPT;
667 switch (LOWORD(status))
669 case SYSQ_MSG_ACCEPT:
671 /* Remove the message from the system msg Q while it is still locked,
672 * before accepting it */
673 if (remove)
675 if (HOOK_IsHooked( WH_JOURNALRECORD )) MSG_JournalRecordMsg( msg );
676 QUEUE_RemoveMsg( sysMsgQueue, qmsg );
678 /* Now actually process the message, after we unlock the system msg Q.
679 * We should not hold on to the crst since SendMessage calls during processing
680 * will potentially cause callbacks to PeekMessage from the application.
681 * If we're holding the crst and QUEUE_WaitBits is called with a
682 * QS_SENDMESSAGE mask we will deadlock in hardware_event() when a
683 * message is being posted to the Q.
685 LeaveCriticalSection(&sysMsgQueue->cSection);
686 if( msgType == KEYBOARD_MSG )
687 status = MSG_ProcessKbdMsg( msg, remove );
688 else if ( msgType == MOUSE_MSG )
689 status = MSG_ProcessMouseMsg( msg, remove, hittest, screen_pt, mouseClick );
691 /* Reclaim the sys msg Q crst */
692 EnterCriticalSection(&sysMsgQueue->cSection);
694 /* Pass the translated message to the user if it was accepted */
695 if (status == SYSQ_MSG_ACCEPT)
696 break;
698 /* If not accepted, fall through into the SYSQ_MSG_SKIP case */
701 case SYSQ_MSG_SKIP:
702 if (HOOK_IsHooked( WH_CBT ))
704 if( msgType == KEYBOARD_MSG )
705 HOOK_CallHooks16( WH_CBT, HCBT_KEYSKIPPED,
706 LOWORD (msg->wParam), msg->lParam );
707 else if ( msgType == MOUSE_MSG )
709 MOUSEHOOKSTRUCT16 *hook = SEGPTR_NEW(MOUSEHOOKSTRUCT16);
710 if (hook)
712 CONV_POINT32TO16( &msg->pt,&hook->pt );
713 hook->hwnd = msg->hwnd;
714 hook->wHitTestCode = HIWORD(status);
715 hook->dwExtraInfo = 0;
716 HOOK_CallHooks16( WH_CBT, HCBT_CLICKSKIPPED ,msg->message & 0xffff,
717 (LPARAM)SEGPTR_GET(hook) );
718 SEGPTR_FREE(hook);
723 /* If the message was removed earlier set up nextqmsg so that we start
724 * at the top of the queue again. We need to do this since our next pointer
725 * could be invalid due to us unlocking the system message Q to process the message.
726 * If not removed just refresh nextqmsg to point to the next msg.
728 if (remove)
729 nextqmsg = sysMsgQueue->firstMsg;
730 else
731 nextqmsg = qmsg->nextMsg;
733 continue;
735 case SYSQ_MSG_CONTINUE:
736 continue;
738 case SYSQ_MSG_ABANDON:
739 bRet = FALSE;
740 goto END;
743 bRet = TRUE;
744 goto END;
747 END:
748 LeaveCriticalSection(&sysMsgQueue->cSection);
749 return bRet;
753 /**********************************************************************
754 * SetDoubleClickTime16 (USER.20)
756 void WINAPI SetDoubleClickTime16( UINT16 interval )
758 SetDoubleClickTime( interval );
762 /**********************************************************************
763 * SetDoubleClickTime (USER32.480)
765 BOOL WINAPI SetDoubleClickTime( UINT interval )
767 doubleClickSpeed = interval ? interval : 500;
768 return TRUE;
772 /**********************************************************************
773 * GetDoubleClickTime16 (USER.21)
775 UINT16 WINAPI GetDoubleClickTime16(void)
777 return doubleClickSpeed;
781 /**********************************************************************
782 * GetDoubleClickTime (USER32.239)
784 UINT WINAPI GetDoubleClickTime(void)
786 return doubleClickSpeed;
790 /***********************************************************************
791 * MSG_SendMessageInterThread
793 * Implementation of an inter-task SendMessage.
794 * Return values:
795 * 0 if error or timeout
796 * 1 if successflul
798 static LRESULT MSG_SendMessageInterThread( HQUEUE16 hDestQueue,
799 HWND hwnd, UINT msg,
800 WPARAM wParam, LPARAM lParam,
801 DWORD timeout, WORD flags,
802 LRESULT *pRes)
804 MESSAGEQUEUE *queue, *destQ;
805 SMSG *smsg;
806 LRESULT retVal = 1;
807 int iWndsLocks;
809 *pRes = 0;
811 if (IsTaskLocked16() || !IsWindow(hwnd))
812 return 0;
814 /* create a SMSG structure to hold SendMessage() parameters */
815 if (! (smsg = (SMSG *) HeapAlloc( SystemHeap, 0, sizeof(SMSG) )) )
816 return 0;
817 if (!(queue = (MESSAGEQUEUE*)QUEUE_Lock( GetFastQueue16() ))) return 0;
819 if (!(destQ = (MESSAGEQUEUE*)QUEUE_Lock( hDestQueue )))
821 QUEUE_Unlock( queue );
822 return 0;
825 TRACE_(sendmsg)("SM: %s [%04x] (%04x -> %04x)\n",
826 SPY_GetMsgName(msg), msg, queue->self, hDestQueue );
828 /* fill up SMSG structure */
829 smsg->hWnd = hwnd;
830 smsg->msg = msg;
831 smsg->wParam = wParam;
832 smsg->lParam = lParam;
834 smsg->lResult = 0;
835 smsg->hSrcQueue = GetFastQueue16();
836 smsg->hDstQueue = hDestQueue;
837 smsg->flags = flags;
839 /* add smsg struct in the processing SM list of the source queue */
840 QUEUE_AddSMSG(queue, SM_PROCESSING_LIST, smsg);
842 /* add smsg struct in the pending list of the destination queue */
843 if (QUEUE_AddSMSG(destQ, SM_PENDING_LIST, smsg) == FALSE)
844 return 0;
846 iWndsLocks = WIN_SuspendWndsLock();
848 /* force destination task to run next, if 16 bit threads */
849 if ( THREAD_IsWin16(NtCurrentTeb()) && THREAD_IsWin16(destQ->teb) )
850 DirectedYield16( destQ->teb->htask16 );
852 /* wait for the result, note that 16-bit apps almost always get out of
853 * DirectedYield() with SMSG_HAVE_RESULT flag already set */
855 while ( TRUE )
858 * The sequence is crucial to avoid deadlock situations:
859 * - first, we clear the QS_SMRESULT bit
860 * - then, we check the SMSG_HAVE_RESULT bit
861 * - only if this isn't set, we enter the wait state.
863 * As the receiver first sets the SMSG_HAVE_RESULT and then wakes us,
864 * we are guaranteed that -should we now clear the QS_SMRESULT that
865 * was signalled already by the receiver- we will not start waiting.
868 if ( smsg->flags & SMSG_HAVE_RESULT )
870 got:
871 *pRes = smsg->lResult;
872 TRACE_(sendmsg)("smResult = %08x\n", (unsigned)*pRes );
873 break;
876 QUEUE_ClearWakeBit( queue, QS_SMRESULT );
878 if ( smsg->flags & SMSG_HAVE_RESULT )
879 goto got;
881 if( QUEUE_WaitBits( QS_SMRESULT, timeout ) == 0 )
883 /* return with timeout */
884 SetLastError( 0 );
885 retVal = 0;
886 break;
889 WIN_RestoreWndsLock(iWndsLocks);
891 /* remove the smsg from the processingg list of the source queue */
892 QUEUE_RemoveSMSG( queue, SM_PROCESSING_LIST, smsg );
894 /* Note: the destination thread is in charge of removing the smsg from
895 the pending list */
897 /* In the case of an early reply (or a timeout), sender thread will
898 released the smsg structure if the receiver thread is done
899 (SMSG_RECEIVED set). If the receiver thread isn't done,
900 SMSG_RECEIVER_CLEANS_UP flag is set, and it will be the receiver
901 responsability to released smsg */
902 EnterCriticalSection( &queue->cSection );
904 if (smsg->flags & SMSG_RECEIVED)
905 HeapFree(SystemHeap, 0, smsg);
906 else
907 smsg->flags |= SMSG_RECEIVER_CLEANS;
909 LeaveCriticalSection( &queue->cSection );
912 QUEUE_Unlock( queue );
913 QUEUE_Unlock( destQ );
915 TRACE_(sendmsg)("done!\n");
916 return retVal;
920 /***********************************************************************
921 * ReplyMessage16 (USER.115)
923 void WINAPI ReplyMessage16( LRESULT result )
925 ReplyMessage( result );
928 /***********************************************************************
929 * ReplyMessage (USER.115)
931 BOOL WINAPI ReplyMessage( LRESULT result )
933 MESSAGEQUEUE *senderQ = 0;
934 MESSAGEQUEUE *queue = 0;
935 SMSG *smsg;
936 BOOL ret = FALSE;
938 if (!(queue = (MESSAGEQUEUE*)QUEUE_Lock( GetFastQueue16() )))
939 return FALSE;
941 TRACE_(sendmsg)("ReplyMessage, queue %04x\n", queue->self);
944 if ( !(smsg = queue->smWaiting)
945 || !(senderQ = QUEUE_Lock( smsg->hSrcQueue )) )
946 goto ReplyMessageEnd;
948 if ( !(smsg->flags & SMSG_ALREADY_REPLIED) )
950 /* This is the first reply, so pass result to sender */
952 TRACE_(sendmsg)("\trpm: smResult = %08lx\n", (long) result );
954 EnterCriticalSection(&senderQ->cSection);
956 smsg->lResult = result;
957 smsg->flags |= SMSG_ALREADY_REPLIED;
959 /* check if it's an early reply (called by the application) or
960 a regular reply (called by ReceiveMessage) */
961 if ( !(smsg->flags & SMSG_SENDING_REPLY) )
962 smsg->flags |= SMSG_EARLY_REPLY;
964 smsg->flags |= SMSG_HAVE_RESULT;
966 LeaveCriticalSection(&senderQ->cSection);
968 /* tell the sending task that its reply is ready */
969 QUEUE_SetWakeBit( senderQ, QS_SMRESULT );
971 /* switch directly to sending task (16 bit thread only) */
972 if ( THREAD_IsWin16( NtCurrentTeb() ) && THREAD_IsWin16( senderQ->teb ) )
973 DirectedYield16( senderQ->teb->htask16 );
975 ret = TRUE;
978 if (smsg->flags & SMSG_SENDING_REPLY)
980 /* remove msg from the waiting list, since this is the last
981 ReplyMessage */
982 QUEUE_RemoveSMSG( queue, SM_WAITING_LIST, smsg );
984 EnterCriticalSection(&senderQ->cSection);
986 /* tell the sender we're all done with smsg structure */
987 smsg->flags |= SMSG_RECEIVED;
989 /* sender will set SMSG_RECEIVER_CLEANS_UP if it wants the
990 receiver to clean up smsg, it could only happens when there is
991 an early reply or a timeout */
992 if ( smsg->flags & SMSG_RECEIVER_CLEANS )
994 TRACE_(sendmsg)("Receiver cleans up!\n" );
995 HeapFree( SystemHeap, 0, smsg );
998 LeaveCriticalSection(&senderQ->cSection);
1001 ReplyMessageEnd:
1002 if ( senderQ )
1003 QUEUE_Unlock( senderQ );
1004 if ( queue )
1005 QUEUE_Unlock( queue );
1007 return ret;
1010 /***********************************************************************
1011 * MSG_ConvertMsg
1013 static BOOL MSG_ConvertMsg( MSG *msg, int srcType, int dstType )
1015 UINT16 msg16;
1016 MSGPARAM16 mp16;
1018 switch ( MAKELONG( srcType, dstType ) )
1020 case MAKELONG( QMSG_WIN16, QMSG_WIN16 ):
1021 case MAKELONG( QMSG_WIN32A, QMSG_WIN32A ):
1022 case MAKELONG( QMSG_WIN32W, QMSG_WIN32W ):
1023 return TRUE;
1025 case MAKELONG( QMSG_WIN16, QMSG_WIN32A ):
1026 switch ( WINPROC_MapMsg16To32A( msg->message, msg->wParam,
1027 &msg->message, &msg->wParam, &msg->lParam ) )
1029 case 0:
1030 return TRUE;
1031 case 1:
1032 /* Pointer messages were mapped --> need to free allocated memory and fail */
1033 WINPROC_UnmapMsg16To32A( msg->hwnd, msg->message, msg->wParam, msg->lParam, 0 );
1034 default:
1035 return FALSE;
1038 case MAKELONG( QMSG_WIN16, QMSG_WIN32W ):
1039 switch ( WINPROC_MapMsg16To32W( msg->hwnd, msg->message, msg->wParam,
1040 &msg->message, &msg->wParam, &msg->lParam ) )
1042 case 0:
1043 return TRUE;
1044 case 1:
1045 /* Pointer messages were mapped --> need to free allocated memory and fail */
1046 WINPROC_UnmapMsg16To32W( msg->hwnd, msg->message, msg->wParam, msg->lParam, 0 );
1047 default:
1048 return FALSE;
1051 case MAKELONG( QMSG_WIN32A, QMSG_WIN16 ):
1052 mp16.lParam = msg->lParam;
1053 switch ( WINPROC_MapMsg32ATo16( msg->hwnd, msg->message, msg->wParam,
1054 &msg16, &mp16.wParam, &mp16.lParam ) )
1056 case 0:
1057 msg->message = msg16;
1058 msg->wParam = mp16.wParam;
1059 msg->lParam = mp16.lParam;
1060 return TRUE;
1061 case 1:
1062 /* Pointer messages were mapped --> need to free allocated memory and fail */
1063 WINPROC_UnmapMsg32ATo16( msg->hwnd, msg->message, msg->wParam, msg->lParam, &mp16 );
1064 default:
1065 return FALSE;
1068 case MAKELONG( QMSG_WIN32W, QMSG_WIN16 ):
1069 mp16.lParam = msg->lParam;
1070 switch ( WINPROC_MapMsg32WTo16( msg->hwnd, msg->message, msg->wParam,
1071 &msg16, &mp16.wParam, &mp16.lParam ) )
1073 case 0:
1074 msg->message = msg16;
1075 msg->wParam = mp16.wParam;
1076 msg->lParam = mp16.lParam;
1077 return TRUE;
1078 case 1:
1079 /* Pointer messages were mapped --> need to free allocated memory and fail */
1080 WINPROC_UnmapMsg32WTo16( msg->hwnd, msg->message, msg->wParam, msg->lParam, &mp16 );
1081 default:
1082 return FALSE;
1085 case MAKELONG( QMSG_WIN32A, QMSG_WIN32W ):
1086 switch ( WINPROC_MapMsg32ATo32W( msg->hwnd, msg->message, msg->wParam, &msg->lParam ) )
1088 case 0:
1089 return TRUE;
1090 case 1:
1091 /* Pointer messages were mapped --> need to free allocated memory and fail */
1092 WINPROC_UnmapMsg32ATo32W( msg->hwnd, msg->message, msg->wParam, msg->lParam );
1093 default:
1094 return FALSE;
1097 case MAKELONG( QMSG_WIN32W, QMSG_WIN32A ):
1098 switch ( WINPROC_MapMsg32WTo32A( msg->hwnd, msg->message, msg->wParam, &msg->lParam ) )
1100 case 0:
1101 return TRUE;
1102 case 1:
1103 /* Pointer messages were mapped --> need to free allocated memory and fail */
1104 WINPROC_UnmapMsg32WTo32A( msg->hwnd, msg->message, msg->wParam, msg->lParam );
1105 default:
1106 return FALSE;
1109 default:
1110 FIXME( "Invalid message type(s): %d / %d\n", srcType, dstType );
1111 return FALSE;
1115 /***********************************************************************
1116 * MSG_PeekMessage
1118 static BOOL MSG_PeekMessage( int type, LPMSG msg, HWND hwnd,
1119 DWORD first, DWORD last, WORD flags, BOOL peek )
1121 int mask;
1122 MESSAGEQUEUE *msgQueue;
1123 HQUEUE16 hQueue;
1124 POINT16 pt16;
1125 int iWndsLocks;
1127 mask = QS_POSTMESSAGE | QS_SENDMESSAGE; /* Always selected */
1128 if (first || last)
1130 if ((first <= WM_KEYLAST) && (last >= WM_KEYFIRST)) mask |= QS_KEY;
1131 if ( ((first <= WM_MOUSELAST) && (last >= WM_MOUSEFIRST)) ||
1132 ((first <= WM_NCMOUSELAST) && (last >= WM_NCMOUSEFIRST)) ) mask |= QS_MOUSE;
1133 if ((first <= WM_TIMER) && (last >= WM_TIMER)) mask |= QS_TIMER;
1134 if ((first <= WM_SYSTIMER) && (last >= WM_SYSTIMER)) mask |= QS_TIMER;
1135 if ((first <= WM_PAINT) && (last >= WM_PAINT)) mask |= QS_PAINT;
1137 else mask |= QS_MOUSE | QS_KEY | QS_TIMER | QS_PAINT;
1139 if (IsTaskLocked16()) flags |= PM_NOYIELD;
1141 /* Never yield on Win32 threads */
1142 if (!THREAD_IsWin16(NtCurrentTeb())) flags |= PM_NOYIELD;
1144 iWndsLocks = WIN_SuspendWndsLock();
1146 while(1)
1148 QMSG *qmsg;
1150 hQueue = GetFastQueue16();
1151 msgQueue = (MESSAGEQUEUE *)QUEUE_Lock( hQueue );
1152 if (!msgQueue)
1154 WIN_RestoreWndsLock(iWndsLocks);
1155 return FALSE;
1157 msgQueue->changeBits = 0;
1159 /* First handle a message put by SendMessage() */
1161 while (msgQueue->wakeBits & QS_SENDMESSAGE)
1162 QUEUE_ReceiveMessage( msgQueue );
1164 /* Now handle a WM_QUIT message */
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 break;
1178 /* Now find a normal message */
1180 retry:
1181 if (((msgQueue->wakeBits & mask) & QS_POSTMESSAGE) &&
1182 ((qmsg = QUEUE_FindMsg( msgQueue, hwnd, first, last )) != 0))
1184 /* Try to convert message to requested type */
1185 MSG tmpMsg = qmsg->msg;
1186 if ( !MSG_ConvertMsg( &tmpMsg, qmsg->type, type ) )
1188 ERR( "Message of wrong type contains pointer parameters. Skipped!\n ");
1189 QUEUE_RemoveMsg( msgQueue, qmsg );
1190 goto retry;
1193 *msg = tmpMsg;
1194 msgQueue->GetMessageTimeVal = msg->time;
1195 CONV_POINT32TO16(&msg->pt, &pt16);
1196 msgQueue->GetMessagePosVal = *(DWORD *)&pt16;
1197 msgQueue->GetMessageExtraInfoVal = qmsg->extraInfo;
1199 if (flags & PM_REMOVE) QUEUE_RemoveMsg( msgQueue, qmsg );
1200 break;
1203 msgQueue->changeBits |= MSG_JournalPlayBackMsg();
1205 /* Now find a hardware event */
1207 if (((msgQueue->wakeBits & mask) & (QS_MOUSE | QS_KEY)) &&
1208 MSG_PeekHardwareMsg( msg, hwnd, first, last, flags & PM_REMOVE ))
1210 /* Got one */
1211 msgQueue->GetMessageTimeVal = msg->time;
1212 CONV_POINT32TO16(&msg->pt, &pt16);
1213 msgQueue->GetMessagePosVal = *(DWORD *)&pt16;
1214 msgQueue->GetMessageExtraInfoVal = 0; /* Always 0 for now */
1215 break;
1218 /* Check again for SendMessage */
1220 while (msgQueue->wakeBits & QS_SENDMESSAGE)
1221 QUEUE_ReceiveMessage( msgQueue );
1223 /* Now find a WM_PAINT message */
1225 if ((msgQueue->wakeBits & mask) & QS_PAINT)
1227 WND* wndPtr;
1228 msg->hwnd = WIN_FindWinToRepaint( hwnd , hQueue );
1229 msg->message = WM_PAINT;
1230 msg->wParam = 0;
1231 msg->lParam = 0;
1233 if ((wndPtr = WIN_FindWndPtr(msg->hwnd)))
1235 if( wndPtr->dwStyle & WS_MINIMIZE &&
1236 (HICON) GetClassLongA(wndPtr->hwndSelf, GCL_HICON) )
1238 msg->message = WM_PAINTICON;
1239 msg->wParam = 1;
1242 if( !hwnd || msg->hwnd == hwnd || IsChild16(hwnd,msg->hwnd) )
1244 if( wndPtr->flags & WIN_INTERNAL_PAINT && !wndPtr->hrgnUpdate)
1246 wndPtr->flags &= ~WIN_INTERNAL_PAINT;
1247 QUEUE_DecPaintCount( hQueue );
1249 WIN_ReleaseWndPtr(wndPtr);
1250 break;
1252 WIN_ReleaseWndPtr(wndPtr);
1256 /* Check for timer messages, but yield first */
1258 if (!(flags & PM_NOYIELD))
1260 UserYield16();
1261 while (msgQueue->wakeBits & QS_SENDMESSAGE)
1262 QUEUE_ReceiveMessage( msgQueue );
1264 if ((msgQueue->wakeBits & mask) & QS_TIMER)
1266 if (TIMER_GetTimerMsg(msg, hwnd, hQueue, flags & PM_REMOVE)) break;
1269 if (peek)
1271 if (!(flags & PM_NOYIELD)) UserYield16();
1273 QUEUE_Unlock( msgQueue );
1274 WIN_RestoreWndsLock(iWndsLocks);
1275 return FALSE;
1277 msgQueue->wakeMask = mask;
1278 QUEUE_WaitBits( mask, INFINITE );
1279 QUEUE_Unlock( msgQueue );
1282 WIN_RestoreWndsLock(iWndsLocks);
1284 /* instead of unlocking queue for every break condition, all break
1285 condition will fall here */
1286 QUEUE_Unlock( msgQueue );
1288 /* We got a message */
1289 if (flags & PM_REMOVE)
1291 WORD message = msg->message;
1293 if (message == WM_KEYDOWN || message == WM_SYSKEYDOWN)
1295 BYTE *p = &QueueKeyStateTable[msg->wParam & 0xff];
1297 if (!(*p & 0x80))
1298 *p ^= 0x01;
1299 *p |= 0x80;
1301 else if (message == WM_KEYUP || message == WM_SYSKEYUP)
1302 QueueKeyStateTable[msg->wParam & 0xff] &= ~0x80;
1305 if (peek)
1306 return TRUE;
1308 else
1309 return (msg->message != WM_QUIT);
1312 /***********************************************************************
1313 * MSG_InternalGetMessage
1315 * GetMessage() function for internal use. Behave like GetMessage(),
1316 * but also call message filters and optionally send WM_ENTERIDLE messages.
1317 * 'hwnd' must be the handle of the dialog or menu window.
1318 * 'code' is the message filter value (MSGF_??? codes).
1320 BOOL MSG_InternalGetMessage( int type, MSG *msg, HWND hwnd, HWND hwndOwner,
1321 WPARAM code, WORD flags, BOOL sendIdle, BOOL* idleSent )
1323 for (;;)
1325 if (sendIdle)
1327 if (!MSG_PeekMessage( type, msg, 0, 0, 0, flags, TRUE ))
1329 /* No message present -> send ENTERIDLE and wait */
1330 if (IsWindow(hwndOwner))
1332 SendMessageA( hwndOwner, WM_ENTERIDLE,
1333 code, (LPARAM)hwnd );
1335 if (idleSent!=NULL)
1336 *idleSent=TRUE;
1338 MSG_PeekMessage( type, msg, 0, 0, 0, flags, FALSE );
1341 else /* Always wait for a message */
1342 MSG_PeekMessage( type, msg, 0, 0, 0, flags, FALSE );
1344 /* Call message filters */
1346 if (HOOK_IsHooked( WH_SYSMSGFILTER ) || HOOK_IsHooked( WH_MSGFILTER ))
1348 MSG *pmsg = HeapAlloc( SystemHeap, 0, sizeof(MSG) );
1349 if (pmsg)
1351 BOOL ret;
1352 *pmsg = *msg;
1353 ret = (HOOK_CallHooksA( WH_SYSMSGFILTER, code, 0,
1354 (LPARAM) pmsg ) ||
1355 HOOK_CallHooksA( WH_MSGFILTER, code, 0,
1356 (LPARAM) pmsg ));
1358 HeapFree( SystemHeap, 0, pmsg );
1359 if (ret)
1361 /* Message filtered -> remove it from the queue */
1362 /* if it's still there. */
1363 if (!(flags & PM_REMOVE))
1364 MSG_PeekMessage( type, msg, 0, 0, 0, PM_REMOVE, TRUE );
1365 continue;
1370 return (msg->message != WM_QUIT);
1375 /***********************************************************************
1376 * PeekMessage32_16 (USER.819)
1378 BOOL16 WINAPI PeekMessage32_16( LPMSG16_32 lpmsg16_32, HWND16 hwnd,
1379 UINT16 first, UINT16 last, UINT16 flags,
1380 BOOL16 wHaveParamHigh )
1382 BOOL ret;
1383 MSG msg;
1385 ret = MSG_PeekMessage( QMSG_WIN16, &msg, hwnd, first, last, flags, TRUE );
1387 lpmsg16_32->msg.hwnd = msg.hwnd;
1388 lpmsg16_32->msg.message = msg.message;
1389 lpmsg16_32->msg.wParam = LOWORD(msg.wParam);
1390 lpmsg16_32->msg.lParam = msg.lParam;
1391 lpmsg16_32->msg.time = msg.time;
1392 lpmsg16_32->msg.pt.x = (INT16)msg.pt.x;
1393 lpmsg16_32->msg.pt.y = (INT16)msg.pt.y;
1395 if ( wHaveParamHigh )
1396 lpmsg16_32->wParamHigh = HIWORD(msg.wParam);
1398 return ret;
1401 /***********************************************************************
1402 * PeekMessage16 (USER.109)
1404 BOOL16 WINAPI PeekMessage16( LPMSG16 lpmsg, HWND16 hwnd,
1405 UINT16 first, UINT16 last, UINT16 flags )
1407 return PeekMessage32_16( (LPMSG16_32)lpmsg, hwnd, first, last, flags, FALSE );
1410 /***********************************************************************
1411 * PeekMessageA
1413 BOOL WINAPI PeekMessageA( LPMSG lpmsg, HWND hwnd,
1414 UINT min, UINT max, UINT wRemoveMsg)
1416 return MSG_PeekMessage( QMSG_WIN32A, lpmsg, hwnd, min, max, wRemoveMsg, TRUE );
1419 /***********************************************************************
1420 * PeekMessageW Check queue for messages
1422 * Checks for a message in the thread's queue, filtered as for
1423 * GetMessage(). Returns immediately whether a message is available
1424 * or not.
1426 * Whether a retrieved message is removed from the queue is set by the
1427 * _wRemoveMsg_ flags, which should be one of the following values:
1429 * PM_NOREMOVE Do not remove the message from the queue.
1431 * PM_REMOVE Remove the message from the queue.
1433 * In addition, PM_NOYIELD may be combined into _wRemoveMsg_ to
1434 * request that the system not yield control during PeekMessage();
1435 * however applications may not rely on scheduling behavior.
1437 * RETURNS
1439 * Nonzero if a message is available and is retrieved, zero otherwise.
1441 * CONFORMANCE
1443 * ECMA-234, Win32
1446 BOOL WINAPI PeekMessageW(
1447 LPMSG lpmsg, /* buffer to receive message */
1448 HWND hwnd, /* restrict to messages for hwnd */
1449 UINT min, /* minimum message to receive */
1450 UINT max, /* maximum message to receive */
1451 UINT wRemoveMsg /* removal flags */
1454 return MSG_PeekMessage( QMSG_WIN32W, lpmsg, hwnd, min, max, wRemoveMsg, TRUE );
1458 /***********************************************************************
1459 * GetMessage32_16 (USER.820)
1461 BOOL16 WINAPI GetMessage32_16( SEGPTR msg16_32, HWND16 hWnd, UINT16 first,
1462 UINT16 last, BOOL16 wHaveParamHigh )
1464 MSG32_16 *lpmsg16_32 = (MSG32_16 *)PTR_SEG_TO_LIN(msg16_32);
1465 MSG msg;
1467 MSG_PeekMessage( QMSG_WIN16, &msg, hWnd, first, last, PM_REMOVE, FALSE );
1469 lpmsg16_32->msg.hwnd = msg.hwnd;
1470 lpmsg16_32->msg.message = msg.message;
1471 lpmsg16_32->msg.wParam = LOWORD(msg.wParam);
1472 lpmsg16_32->msg.lParam = msg.lParam;
1473 lpmsg16_32->msg.time = msg.time;
1474 lpmsg16_32->msg.pt.x = (INT16)msg.pt.x;
1475 lpmsg16_32->msg.pt.y = (INT16)msg.pt.y;
1477 if ( wHaveParamHigh )
1478 lpmsg16_32->wParamHigh = HIWORD(msg.wParam);
1480 TRACE( "message %04x, hwnd %04x, filter(%04x - %04x)\n",
1481 lpmsg16_32->msg.message, hWnd, first, last );
1483 HOOK_CallHooks16( WH_GETMESSAGE, HC_ACTION, 0, (LPARAM)msg16_32 );
1484 return lpmsg16_32->msg.message != WM_QUIT;
1487 /***********************************************************************
1488 * GetMessage16 (USER.108)
1490 BOOL16 WINAPI GetMessage16( SEGPTR msg, HWND16 hwnd, UINT16 first, UINT16 last)
1492 return GetMessage32_16( msg, hwnd, first, last, FALSE );
1495 /***********************************************************************
1496 * GetMessageA (USER32.270)
1498 BOOL WINAPI GetMessageA( MSG *lpmsg, HWND hwnd, UINT min, UINT max )
1500 MSG_PeekMessage( QMSG_WIN32A, lpmsg, hwnd, min, max, PM_REMOVE, FALSE );
1502 TRACE( "message %04x, hwnd %04x, filter(%04x - %04x)\n",
1503 lpmsg->message, hwnd, min, max );
1505 HOOK_CallHooksA( WH_GETMESSAGE, HC_ACTION, 0, (LPARAM)lpmsg );
1506 return lpmsg->message != WM_QUIT;
1509 /***********************************************************************
1510 * GetMessageW (USER32.274) Retrieve next message
1512 * GetMessage retrieves the next event from the calling thread's
1513 * queue and deposits it in *lpmsg.
1515 * If _hwnd_ is not NULL, only messages for window _hwnd_ and its
1516 * children as specified by IsChild() are retrieved. If _hwnd_ is NULL
1517 * all application messages are retrieved.
1519 * _min_ and _max_ specify the range of messages of interest. If
1520 * min==max==0, no filtering is performed. Useful examples are
1521 * WM_KEYFIRST and WM_KEYLAST to retrieve keyboard input, and
1522 * WM_MOUSEFIRST and WM_MOUSELAST to retrieve mouse input.
1524 * WM_PAINT messages are not removed from the queue; they remain until
1525 * processed. Other messages are removed from the queue.
1527 * RETURNS
1529 * -1 on error, 0 if message is WM_QUIT, nonzero otherwise.
1531 * CONFORMANCE
1533 * ECMA-234, Win32
1536 BOOL WINAPI GetMessageW(
1537 MSG* lpmsg, /* buffer to receive message */
1538 HWND hwnd, /* restrict to messages for hwnd */
1539 UINT min, /* minimum message to receive */
1540 UINT max /* maximum message to receive */
1543 MSG_PeekMessage( QMSG_WIN32W, lpmsg, hwnd, min, max, PM_REMOVE, FALSE );
1545 TRACE( "message %04x, hwnd %04x, filter(%04x - %04x)\n",
1546 lpmsg->message, hwnd, min, max );
1548 HOOK_CallHooksW( WH_GETMESSAGE, HC_ACTION, 0, (LPARAM)lpmsg );
1549 return lpmsg->message != WM_QUIT;
1552 /***********************************************************************
1553 * MSG_PostToQueue
1555 static BOOL MSG_PostToQueue( HQUEUE16 hQueue, int type, HWND hwnd,
1556 UINT message, WPARAM wParam, LPARAM lParam )
1558 MSG msg;
1560 if ( !hQueue ) return FALSE;
1562 msg.hwnd = hwnd;
1563 msg.message = message;
1564 msg.wParam = wParam;
1565 msg.lParam = lParam;
1566 msg.time = GetTickCount();
1567 msg.pt.x = 0;
1568 msg.pt.y = 0;
1570 return QUEUE_AddMsg( hQueue, type, &msg, 0 );
1573 /***********************************************************************
1574 * MSG_PostMessage
1576 static BOOL MSG_PostMessage( int type, HWND hwnd, UINT message,
1577 WPARAM wParam, LPARAM lParam )
1579 HQUEUE16 hQueue;
1580 WND *wndPtr;
1582 if (hwnd == HWND_BROADCAST)
1584 WND *pDesktop = WIN_GetDesktop();
1585 TRACE("HWND_BROADCAST !\n");
1587 for (wndPtr=WIN_LockWndPtr(pDesktop->child); wndPtr; WIN_UpdateWndPtr(&wndPtr,wndPtr->next))
1589 if (wndPtr->dwStyle & WS_POPUP || wndPtr->dwStyle & WS_CAPTION)
1591 TRACE("BROADCAST Message to hWnd=%04x m=%04X w=%04X l=%08lX !\n",
1592 wndPtr->hwndSelf, message, wParam, lParam);
1593 MSG_PostToQueue( wndPtr->hmemTaskQ, type,
1594 wndPtr->hwndSelf, message, wParam, lParam );
1597 WIN_ReleaseDesktop();
1598 TRACE("End of HWND_BROADCAST !\n");
1599 return TRUE;
1602 wndPtr = WIN_FindWndPtr( hwnd );
1603 hQueue = wndPtr? wndPtr->hmemTaskQ : 0;
1604 WIN_ReleaseWndPtr(wndPtr);
1606 return MSG_PostToQueue( hQueue, type, hwnd, message, wParam, lParam );
1609 /***********************************************************************
1610 * PostMessage16 (USER.110)
1612 BOOL16 WINAPI PostMessage16( HWND16 hwnd, UINT16 message, WPARAM16 wParam,
1613 LPARAM lParam )
1615 return (BOOL16) MSG_PostMessage( QMSG_WIN16, hwnd, message, wParam, lParam );
1618 /***********************************************************************
1619 * PostMessageA (USER32.419)
1621 BOOL WINAPI PostMessageA( HWND hwnd, UINT message, WPARAM wParam,
1622 LPARAM lParam )
1624 return MSG_PostMessage( QMSG_WIN32A, hwnd, message, wParam, lParam );
1627 /***********************************************************************
1628 * PostMessageW (USER32.420)
1630 BOOL WINAPI PostMessageW( HWND hwnd, UINT message, WPARAM wParam,
1631 LPARAM lParam )
1633 return MSG_PostMessage( QMSG_WIN32W, hwnd, message, wParam, lParam );
1636 /***********************************************************************
1637 * PostAppMessage16 (USER.116)
1639 BOOL16 WINAPI PostAppMessage16( HTASK16 hTask, UINT16 message,
1640 WPARAM16 wParam, LPARAM lParam )
1642 return MSG_PostToQueue( GetTaskQueue16(hTask), QMSG_WIN16,
1643 0, message, wParam, lParam );
1646 /**********************************************************************
1647 * PostThreadMessageA (USER32.422)
1649 BOOL WINAPI PostThreadMessageA( DWORD idThread, UINT message,
1650 WPARAM wParam, LPARAM lParam )
1652 return MSG_PostToQueue( GetThreadQueue16(idThread), QMSG_WIN32A,
1653 0, message, wParam, lParam );
1656 /**********************************************************************
1657 * PostThreadMessageW (USER32.423)
1659 BOOL WINAPI PostThreadMessageW( DWORD idThread, UINT message,
1660 WPARAM wParam, LPARAM lParam )
1662 return MSG_PostToQueue( GetThreadQueue16(idThread), QMSG_WIN32W,
1663 0, message, wParam, lParam );
1667 /************************************************************************
1668 * MSG_CallWndProcHook32
1670 static void MSG_CallWndProcHook( LPMSG pmsg, BOOL bUnicode )
1672 CWPSTRUCT cwp;
1674 cwp.lParam = pmsg->lParam;
1675 cwp.wParam = pmsg->wParam;
1676 cwp.message = pmsg->message;
1677 cwp.hwnd = pmsg->hwnd;
1679 if (bUnicode) HOOK_CallHooksW(WH_CALLWNDPROC, HC_ACTION, 1, (LPARAM)&cwp);
1680 else HOOK_CallHooksA( WH_CALLWNDPROC, HC_ACTION, 1, (LPARAM)&cwp );
1682 pmsg->lParam = cwp.lParam;
1683 pmsg->wParam = cwp.wParam;
1684 pmsg->message = cwp.message;
1685 pmsg->hwnd = cwp.hwnd;
1689 /***********************************************************************
1690 * MSG_SendMessage
1692 * return values: 0 if timeout occurs
1693 * 1 otherwise
1695 static LRESULT MSG_SendMessage( HWND hwnd, UINT msg, WPARAM wParam,
1696 LPARAM lParam, DWORD timeout, WORD flags,
1697 LRESULT *pRes)
1699 WND * wndPtr = 0;
1700 WND **list, **ppWnd;
1701 LRESULT ret = 1;
1703 *pRes = 0;
1705 if (hwnd == HWND_BROADCAST|| hwnd == HWND_TOPMOST)
1707 *pRes = 1;
1709 if (!(list = WIN_BuildWinArray( WIN_GetDesktop(), 0, NULL )))
1711 WIN_ReleaseDesktop();
1712 return 1;
1714 WIN_ReleaseDesktop();
1716 TRACE("HWND_BROADCAST !\n");
1717 for (ppWnd = list; *ppWnd; ppWnd++)
1719 WIN_UpdateWndPtr(&wndPtr,*ppWnd);
1720 if (!IsWindow(wndPtr->hwndSelf)) continue;
1721 if (wndPtr->dwStyle & WS_POPUP || wndPtr->dwStyle & WS_CAPTION)
1723 TRACE("BROADCAST Message to hWnd=%04x m=%04X w=%04lX l=%08lX !\n",
1724 wndPtr->hwndSelf, msg, (DWORD)wParam, lParam);
1725 MSG_SendMessage( wndPtr->hwndSelf, msg, wParam, lParam,
1726 timeout, flags, pRes);
1729 WIN_ReleaseWndPtr(wndPtr);
1730 WIN_ReleaseWinArray(list);
1731 TRACE("End of HWND_BROADCAST !\n");
1732 return 1;
1735 if (HOOK_IsHooked( WH_CALLWNDPROC ))
1737 if (flags & SMSG_UNICODE)
1738 MSG_CallWndProcHook( (LPMSG)&hwnd, TRUE);
1739 else if (flags & SMSG_WIN32)
1740 MSG_CallWndProcHook( (LPMSG)&hwnd, FALSE);
1741 else
1743 LPCWPSTRUCT16 pmsg;
1745 if ((pmsg = SEGPTR_NEW(CWPSTRUCT16)))
1747 pmsg->hwnd = hwnd & 0xffff;
1748 pmsg->message= msg & 0xffff;
1749 pmsg->wParam = wParam & 0xffff;
1750 pmsg->lParam = lParam;
1751 HOOK_CallHooks16( WH_CALLWNDPROC, HC_ACTION, 1,
1752 (LPARAM)SEGPTR_GET(pmsg) );
1753 hwnd = pmsg->hwnd;
1754 msg = pmsg->message;
1755 wParam = pmsg->wParam;
1756 lParam = pmsg->lParam;
1757 SEGPTR_FREE( pmsg );
1762 if (!(wndPtr = WIN_FindWndPtr( hwnd )))
1764 WARN("invalid hwnd %04x\n", hwnd );
1765 return 0;
1767 if (QUEUE_IsExitingQueue(wndPtr->hmemTaskQ))
1769 ret = 0; /* Don't send anything if the task is dying */
1770 goto END;
1772 if (flags & SMSG_WIN32)
1773 SPY_EnterMessage( SPY_SENDMESSAGE, hwnd, msg, wParam, lParam );
1774 else
1775 SPY_EnterMessage( SPY_SENDMESSAGE16, hwnd, msg, wParam, lParam );
1777 if (wndPtr->hmemTaskQ != GetFastQueue16())
1778 ret = MSG_SendMessageInterThread( wndPtr->hmemTaskQ, hwnd, msg,
1779 wParam, lParam, timeout, flags, pRes );
1780 else
1782 /* Call the right CallWindowProc flavor */
1783 if (flags & SMSG_UNICODE)
1784 *pRes = CallWindowProcW( (WNDPROC)wndPtr->winproc,
1785 hwnd, msg, wParam, lParam );
1786 else if (flags & SMSG_WIN32)
1787 *pRes = CallWindowProcA( (WNDPROC)wndPtr->winproc,
1788 hwnd, msg, wParam, lParam );
1789 else
1790 *pRes = CallWindowProc16( (WNDPROC16)wndPtr->winproc,
1791 (HWND16) hwnd, (UINT16) msg,
1792 (WPARAM16) wParam, lParam );
1795 if (flags & SMSG_WIN32)
1796 SPY_ExitMessage( SPY_RESULT_OK, hwnd, msg, *pRes );
1797 else
1798 SPY_ExitMessage( SPY_RESULT_OK16, hwnd, msg, *pRes );
1799 END:
1800 WIN_ReleaseWndPtr(wndPtr);
1801 return ret;
1805 /***********************************************************************
1806 * SendMessage16 (USER.111)
1808 LRESULT WINAPI SendMessage16( HWND16 hwnd, UINT16 msg, WPARAM16 wParam,
1809 LPARAM lParam)
1811 LRESULT res;
1812 MSG_SendMessage(hwnd, msg, wParam, lParam, INFINITE, 0, &res);
1813 return res;
1817 /***********************************************************************
1818 * SendMessageA (USER32.454)
1820 LRESULT WINAPI SendMessageA( HWND hwnd, UINT msg, WPARAM wParam,
1821 LPARAM lParam )
1823 LRESULT res;
1825 MSG_SendMessage(hwnd, msg, wParam, lParam, INFINITE,
1826 SMSG_WIN32, &res);
1828 return res;
1832 /***********************************************************************
1833 * SendMessageW (USER32.459) Send Window Message
1835 * Sends a message to the window procedure of the specified window.
1836 * SendMessage() will not return until the called window procedure
1837 * either returns or calls ReplyMessage().
1839 * Use PostMessage() to send message and return immediately. A window
1840 * procedure may use InSendMessage() to detect
1841 * SendMessage()-originated messages.
1843 * Applications which communicate via HWND_BROADCAST may use
1844 * RegisterWindowMessage() to obtain a unique message to avoid conflicts
1845 * with other applications.
1847 * CONFORMANCE
1849 * ECMA-234, Win32
1851 LRESULT WINAPI SendMessageW(
1852 HWND hwnd, /* Window to send message to. If HWND_BROADCAST,
1853 the message will be sent to all top-level windows. */
1855 UINT msg, /* message */
1856 WPARAM wParam, /* message parameter */
1857 LPARAM lParam /* additional message parameter */
1859 LRESULT res;
1861 MSG_SendMessage(hwnd, msg, wParam, lParam, INFINITE,
1862 SMSG_WIN32 | SMSG_UNICODE, &res);
1864 return res;
1868 /***********************************************************************
1869 * SendMessageTimeout16 (not a WINAPI)
1871 LRESULT WINAPI SendMessageTimeout16( HWND16 hwnd, UINT16 msg, WPARAM16 wParam,
1872 LPARAM lParam, UINT16 flags,
1873 UINT16 timeout, LPWORD resultp)
1875 LRESULT ret;
1876 LRESULT msgRet;
1878 /* FIXME: need support for SMTO_BLOCK */
1880 ret = MSG_SendMessage(hwnd, msg, wParam, lParam, timeout, 0, &msgRet);
1881 if (resultp) *resultp = (WORD) msgRet;
1882 return ret;
1886 /***********************************************************************
1887 * SendMessageTimeoutA (USER32.457)
1889 LRESULT WINAPI SendMessageTimeoutA( HWND hwnd, UINT msg, WPARAM wParam,
1890 LPARAM lParam, UINT flags,
1891 UINT timeout, LPDWORD resultp)
1893 LRESULT ret;
1894 LRESULT msgRet;
1896 /* FIXME: need support for SMTO_BLOCK */
1898 ret = MSG_SendMessage(hwnd, msg, wParam, lParam, timeout, SMSG_WIN32,
1899 &msgRet);
1901 if (resultp) *resultp = (DWORD) msgRet;
1902 return ret;
1906 /***********************************************************************
1907 * SendMessageTimeoutW (USER32.458)
1909 LRESULT WINAPI SendMessageTimeoutW( HWND hwnd, UINT msg, WPARAM wParam,
1910 LPARAM lParam, UINT flags,
1911 UINT timeout, LPDWORD resultp)
1913 LRESULT ret;
1914 LRESULT msgRet;
1916 /* FIXME: need support for SMTO_BLOCK */
1918 ret = MSG_SendMessage(hwnd, msg, wParam, lParam, timeout,
1919 SMSG_WIN32 | SMSG_UNICODE, &msgRet);
1921 if (resultp) *resultp = (DWORD) msgRet;
1922 return ret;
1926 /***********************************************************************
1927 * WaitMessage (USER.112) (USER32.578) Suspend thread pending messages
1929 * WaitMessage() suspends a thread until events appear in the thread's
1930 * queue.
1932 * BUGS
1934 * Is supposed to return BOOL under Win32.
1936 * Thread-local message queues are not supported.
1938 * CONFORMANCE
1940 * ECMA-234, Win32
1943 void WINAPI WaitMessage( void )
1945 QUEUE_WaitBits( QS_ALLINPUT, INFINITE );
1948 /***********************************************************************
1949 * MsgWaitForMultipleObjects (USER32.400)
1951 DWORD WINAPI MsgWaitForMultipleObjects( DWORD nCount, HANDLE *pHandles,
1952 BOOL fWaitAll, DWORD dwMilliseconds,
1953 DWORD dwWakeMask )
1955 DWORD i;
1956 HANDLE handles[MAXIMUM_WAIT_OBJECTS];
1957 DWORD ret;
1958 PDB * pdb = PROCESS_Current();
1960 HQUEUE16 hQueue = GetFastQueue16();
1961 MESSAGEQUEUE *msgQueue = (MESSAGEQUEUE *)QUEUE_Lock( hQueue );
1962 if (!msgQueue) return WAIT_FAILED;
1964 if (nCount > MAXIMUM_WAIT_OBJECTS-1)
1966 SetLastError( ERROR_INVALID_PARAMETER );
1967 QUEUE_Unlock( msgQueue );
1968 return WAIT_FAILED;
1971 msgQueue->changeBits = 0;
1972 msgQueue->wakeMask = dwWakeMask;
1974 if (THREAD_IsWin16(NtCurrentTeb()))
1977 * This is a temporary solution to a big problem.
1978 * You see, the main thread of all Win32 programs is created as a 16 bit
1979 * task. This means that if you want on an event using Win32 synchronization
1980 * methods, the 16 bit scheduler is stopped and things might just stop happening.
1981 * This implements a semi-busy loop that checks the handles to wait on and
1982 * also the message queue. When either one is ready, the wait function returns.
1984 * This will all go away when the real Win32 threads are implemented for all
1985 * the threads of an applications. Including the main thread.
1987 DWORD curTime = GetCurrentTime();
1992 * Check the handles in the list.
1994 SetEvent ( pdb->idle_event );
1995 ret = WaitForMultipleObjects(nCount, pHandles, fWaitAll, 5L);
1998 * If the handles have been triggered, return.
2000 if (ret != WAIT_TIMEOUT)
2001 break;
2004 * Then, let the 16 bit scheduler do it's thing.
2006 Yield16();
2009 * If a message matching the wait mask has arrived, return.
2011 if (msgQueue->changeBits & dwWakeMask)
2013 ret = nCount;
2014 break;
2018 * And continue doing this until we hit the timeout.
2020 } while ((dwMilliseconds == INFINITE) || (GetCurrentTime()-curTime < dwMilliseconds) );
2022 else
2024 /* Add the thread event to the handle list */
2025 for (i = 0; i < nCount; i++)
2026 handles[i] = pHandles[i];
2027 handles[nCount] = msgQueue->hEvent;
2029 if ( pdb->main_queue == INVALID_HANDLE_VALUE16 ) pdb->main_queue = hQueue;
2030 if ( pdb->main_queue == hQueue ) SetEvent ( pdb->idle_event );
2031 ret = WaitForMultipleObjects( nCount+1, handles, fWaitAll, dwMilliseconds );
2032 if ( pdb->main_queue == hQueue ) ResetEvent ( pdb->idle_event );
2036 QUEUE_Unlock( msgQueue );
2038 return ret;
2043 struct accent_char
2045 BYTE ac_accent;
2046 BYTE ac_char;
2047 BYTE ac_result;
2050 static const struct accent_char accent_chars[] =
2052 /* A good idea should be to read /usr/X11/lib/X11/locale/iso8859-x/Compose */
2053 {'`', 'A', '\300'}, {'`', 'a', '\340'},
2054 {'\'', 'A', '\301'}, {'\'', 'a', '\341'},
2055 {'^', 'A', '\302'}, {'^', 'a', '\342'},
2056 {'~', 'A', '\303'}, {'~', 'a', '\343'},
2057 {'"', 'A', '\304'}, {'"', 'a', '\344'},
2058 {'O', 'A', '\305'}, {'o', 'a', '\345'},
2059 {'0', 'A', '\305'}, {'0', 'a', '\345'},
2060 {'A', 'A', '\305'}, {'a', 'a', '\345'},
2061 {'A', 'E', '\306'}, {'a', 'e', '\346'},
2062 {',', 'C', '\307'}, {',', 'c', '\347'},
2063 {'`', 'E', '\310'}, {'`', 'e', '\350'},
2064 {'\'', 'E', '\311'}, {'\'', 'e', '\351'},
2065 {'^', 'E', '\312'}, {'^', 'e', '\352'},
2066 {'"', 'E', '\313'}, {'"', 'e', '\353'},
2067 {'`', 'I', '\314'}, {'`', 'i', '\354'},
2068 {'\'', 'I', '\315'}, {'\'', 'i', '\355'},
2069 {'^', 'I', '\316'}, {'^', 'i', '\356'},
2070 {'"', 'I', '\317'}, {'"', 'i', '\357'},
2071 {'-', 'D', '\320'}, {'-', 'd', '\360'},
2072 {'~', 'N', '\321'}, {'~', 'n', '\361'},
2073 {'`', 'O', '\322'}, {'`', 'o', '\362'},
2074 {'\'', 'O', '\323'}, {'\'', 'o', '\363'},
2075 {'^', 'O', '\324'}, {'^', 'o', '\364'},
2076 {'~', 'O', '\325'}, {'~', 'o', '\365'},
2077 {'"', 'O', '\326'}, {'"', 'o', '\366'},
2078 {'/', 'O', '\330'}, {'/', 'o', '\370'},
2079 {'`', 'U', '\331'}, {'`', 'u', '\371'},
2080 {'\'', 'U', '\332'}, {'\'', 'u', '\372'},
2081 {'^', 'U', '\333'}, {'^', 'u', '\373'},
2082 {'"', 'U', '\334'}, {'"', 'u', '\374'},
2083 {'\'', 'Y', '\335'}, {'\'', 'y', '\375'},
2084 {'T', 'H', '\336'}, {'t', 'h', '\376'},
2085 {'s', 's', '\337'}, {'"', 'y', '\377'},
2086 {'s', 'z', '\337'}, {'i', 'j', '\377'},
2087 /* iso-8859-2 uses this */
2088 {'<', 'L', '\245'}, {'<', 'l', '\265'}, /* caron */
2089 {'<', 'S', '\251'}, {'<', 's', '\271'},
2090 {'<', 'T', '\253'}, {'<', 't', '\273'},
2091 {'<', 'Z', '\256'}, {'<', 'z', '\276'},
2092 {'<', 'C', '\310'}, {'<', 'c', '\350'},
2093 {'<', 'E', '\314'}, {'<', 'e', '\354'},
2094 {'<', 'D', '\317'}, {'<', 'd', '\357'},
2095 {'<', 'N', '\322'}, {'<', 'n', '\362'},
2096 {'<', 'R', '\330'}, {'<', 'r', '\370'},
2097 {';', 'A', '\241'}, {';', 'a', '\261'}, /* ogonek */
2098 {';', 'E', '\312'}, {';', 'e', '\332'},
2099 {'\'', 'Z', '\254'}, {'\'', 'z', '\274'}, /* acute */
2100 {'\'', 'R', '\300'}, {'\'', 'r', '\340'},
2101 {'\'', 'L', '\305'}, {'\'', 'l', '\345'},
2102 {'\'', 'C', '\306'}, {'\'', 'c', '\346'},
2103 {'\'', 'N', '\321'}, {'\'', 'n', '\361'},
2104 /* collision whith S, from iso-8859-9 !!! */
2105 {',', 'S', '\252'}, {',', 's', '\272'}, /* cedilla */
2106 {',', 'T', '\336'}, {',', 't', '\376'},
2107 {'.', 'Z', '\257'}, {'.', 'z', '\277'}, /* dot above */
2108 {'/', 'L', '\243'}, {'/', 'l', '\263'}, /* slash */
2109 {'/', 'D', '\320'}, {'/', 'd', '\360'},
2110 {'(', 'A', '\303'}, {'(', 'a', '\343'}, /* breve */
2111 {'\275', 'O', '\325'}, {'\275', 'o', '\365'}, /* double acute */
2112 {'\275', 'U', '\334'}, {'\275', 'u', '\374'},
2113 {'0', 'U', '\332'}, {'0', 'u', '\372'}, /* ring above */
2114 /* iso-8859-3 uses this */
2115 {'/', 'H', '\241'}, {'/', 'h', '\261'}, /* slash */
2116 {'>', 'H', '\246'}, {'>', 'h', '\266'}, /* circumflex */
2117 {'>', 'J', '\254'}, {'>', 'j', '\274'},
2118 {'>', 'C', '\306'}, {'>', 'c', '\346'},
2119 {'>', 'G', '\330'}, {'>', 'g', '\370'},
2120 {'>', 'S', '\336'}, {'>', 's', '\376'},
2121 /* collision whith G( from iso-8859-9 !!! */
2122 {'(', 'G', '\253'}, {'(', 'g', '\273'}, /* breve */
2123 {'(', 'U', '\335'}, {'(', 'u', '\375'},
2124 /* collision whith I. from iso-8859-3 !!! */
2125 {'.', 'I', '\251'}, {'.', 'i', '\271'}, /* dot above */
2126 {'.', 'C', '\305'}, {'.', 'c', '\345'},
2127 {'.', 'G', '\325'}, {'.', 'g', '\365'},
2128 /* iso-8859-4 uses this */
2129 {',', 'R', '\243'}, {',', 'r', '\263'}, /* cedilla */
2130 {',', 'L', '\246'}, {',', 'l', '\266'},
2131 {',', 'G', '\253'}, {',', 'g', '\273'},
2132 {',', 'N', '\321'}, {',', 'n', '\361'},
2133 {',', 'K', '\323'}, {',', 'k', '\363'},
2134 {'~', 'I', '\245'}, {'~', 'i', '\265'}, /* tilde */
2135 {'-', 'E', '\252'}, {'-', 'e', '\272'}, /* macron */
2136 {'-', 'A', '\300'}, {'-', 'a', '\340'},
2137 {'-', 'I', '\317'}, {'-', 'i', '\357'},
2138 {'-', 'O', '\322'}, {'-', 'o', '\362'},
2139 {'-', 'U', '\336'}, {'-', 'u', '\376'},
2140 {'/', 'T', '\254'}, {'/', 't', '\274'}, /* slash */
2141 {'.', 'E', '\314'}, {'.', 'e', '\344'}, /* dot above */
2142 {';', 'I', '\307'}, {';', 'i', '\347'}, /* ogonek */
2143 {';', 'U', '\331'}, {';', 'u', '\371'},
2144 /* iso-8859-9 uses this */
2145 /* iso-8859-9 has really bad choosen G( S, and I. as they collide
2146 * whith the same letters on other iso-8859-x (that is they are on
2147 * different places :-( ), if you use turkish uncomment these and
2148 * comment out the lines in iso-8859-2 and iso-8859-3 sections
2149 * FIXME: should be dynamic according to chosen language
2150 * if/when Wine has turkish support.
2152 /* collision whith G( from iso-8859-3 !!! */
2153 /* {'(', 'G', '\320'}, {'(', 'g', '\360'}, */ /* breve */
2154 /* collision whith S, from iso-8859-2 !!! */
2155 /* {',', 'S', '\336'}, {',', 's', '\376'}, */ /* cedilla */
2156 /* collision whith I. from iso-8859-3 !!! */
2157 /* {'.', 'I', '\335'}, {'.', 'i', '\375'}, */ /* dot above */
2161 /***********************************************************************
2162 * MSG_DoTranslateMessage
2164 * Implementation of TranslateMessage.
2166 * TranslateMessage translates virtual-key messages into character-messages,
2167 * as follows :
2168 * WM_KEYDOWN/WM_KEYUP combinations produce a WM_CHAR or WM_DEADCHAR message.
2169 * ditto replacing WM_* with WM_SYS*
2170 * This produces WM_CHAR messages only for keys mapped to ASCII characters
2171 * by the keyboard driver.
2173 static BOOL MSG_DoTranslateMessage( UINT message, HWND hwnd,
2174 WPARAM wParam, LPARAM lParam )
2176 static int dead_char;
2177 BYTE wp[2];
2179 if (message != WM_MOUSEMOVE && message != WM_TIMER)
2180 TRACE("(%s, %04X, %08lX)\n",
2181 SPY_GetMsgName(message), wParam, lParam );
2182 if(message >= WM_KEYFIRST && message <= WM_KEYLAST)
2183 TRACE_(key)("(%s, %04X, %08lX)\n",
2184 SPY_GetMsgName(message), wParam, lParam );
2186 if ((message != WM_KEYDOWN) && (message != WM_SYSKEYDOWN)) return FALSE;
2188 TRACE_(key)("Translating key %04X, scancode %04X\n",
2189 wParam, HIWORD(lParam) );
2191 /* FIXME : should handle ToAscii yielding 2 */
2192 switch (ToAscii(wParam, HIWORD(lParam),
2193 QueueKeyStateTable,(LPWORD)wp, 0))
2195 case 1 :
2196 message = (message == WM_KEYDOWN) ? WM_CHAR : WM_SYSCHAR;
2197 /* Should dead chars handling go in ToAscii ? */
2198 if (dead_char)
2200 int i;
2202 if (wp[0] == ' ') wp[0] = dead_char;
2203 if (dead_char == 0xa2) dead_char = '(';
2204 else if (dead_char == 0xa8) dead_char = '"';
2205 else if (dead_char == 0xb2) dead_char = ';';
2206 else if (dead_char == 0xb4) dead_char = '\'';
2207 else if (dead_char == 0xb7) dead_char = '<';
2208 else if (dead_char == 0xb8) dead_char = ',';
2209 else if (dead_char == 0xff) dead_char = '.';
2210 for (i = 0; i < sizeof(accent_chars)/sizeof(accent_chars[0]); i++)
2211 if ((accent_chars[i].ac_accent == dead_char) &&
2212 (accent_chars[i].ac_char == wp[0]))
2214 wp[0] = accent_chars[i].ac_result;
2215 break;
2217 dead_char = 0;
2219 TRACE_(key)("1 -> PostMessage(%s)\n", SPY_GetMsgName(message));
2220 PostMessage16( hwnd, message, wp[0], lParam );
2221 return TRUE;
2223 case -1 :
2224 message = (message == WM_KEYDOWN) ? WM_DEADCHAR : WM_SYSDEADCHAR;
2225 dead_char = wp[0];
2226 TRACE_(key)("-1 -> PostMessage(%s)\n",
2227 SPY_GetMsgName(message));
2228 PostMessage16( hwnd, message, wp[0], lParam );
2229 return TRUE;
2231 return FALSE;
2235 /***********************************************************************
2236 * TranslateMessage16 (USER.113)
2238 BOOL16 WINAPI TranslateMessage16( const MSG16 *msg )
2240 return MSG_DoTranslateMessage( msg->message, msg->hwnd,
2241 msg->wParam, msg->lParam );
2245 /***********************************************************************
2246 * TranslateMessage32 (USER.821)
2248 BOOL16 WINAPI TranslateMessage32_16( const MSG32_16 *msg, BOOL16 wHaveParamHigh )
2250 WPARAM wParam;
2252 if (wHaveParamHigh)
2253 wParam = MAKELONG(msg->msg.wParam, msg->wParamHigh);
2254 else
2255 wParam = (WPARAM)msg->msg.wParam;
2257 return MSG_DoTranslateMessage( msg->msg.message, msg->msg.hwnd,
2258 wParam, msg->msg.lParam );
2261 /***********************************************************************
2262 * TranslateMessage (USER32.556)
2264 BOOL WINAPI TranslateMessage( const MSG *msg )
2266 return MSG_DoTranslateMessage( msg->message, msg->hwnd,
2267 msg->wParam, msg->lParam );
2271 /***********************************************************************
2272 * DispatchMessage16 (USER.114)
2274 LONG WINAPI DispatchMessage16( const MSG16* msg )
2276 WND * wndPtr;
2277 LONG retval;
2278 int painting;
2280 /* Process timer messages */
2281 if ((msg->message == WM_TIMER) || (msg->message == WM_SYSTIMER))
2283 if (msg->lParam)
2285 return CallWindowProc16( (WNDPROC16)msg->lParam, msg->hwnd,
2286 msg->message, msg->wParam, GetTickCount() );
2290 if (!msg->hwnd) return 0;
2291 if (!(wndPtr = WIN_FindWndPtr( msg->hwnd ))) return 0;
2292 if (!wndPtr->winproc)
2294 retval = 0;
2295 goto END;
2297 painting = (msg->message == WM_PAINT);
2298 if (painting) wndPtr->flags |= WIN_NEEDS_BEGINPAINT;
2300 SPY_EnterMessage( SPY_DISPATCHMESSAGE16, msg->hwnd, msg->message,
2301 msg->wParam, msg->lParam );
2302 retval = CallWindowProc16( (WNDPROC16)wndPtr->winproc,
2303 msg->hwnd, msg->message,
2304 msg->wParam, msg->lParam );
2305 SPY_ExitMessage( SPY_RESULT_OK16, msg->hwnd, msg->message, retval );
2307 WIN_ReleaseWndPtr(wndPtr);
2308 wndPtr = WIN_FindWndPtr(msg->hwnd);
2309 if (painting && wndPtr &&
2310 (wndPtr->flags & WIN_NEEDS_BEGINPAINT) && wndPtr->hrgnUpdate)
2312 ERR("BeginPaint not called on WM_PAINT for hwnd %04x!\n",
2313 msg->hwnd);
2314 wndPtr->flags &= ~WIN_NEEDS_BEGINPAINT;
2315 /* Validate the update region to avoid infinite WM_PAINT loop */
2316 ValidateRect( msg->hwnd, NULL );
2318 END:
2319 WIN_ReleaseWndPtr(wndPtr);
2320 return retval;
2324 /***********************************************************************
2325 * DispatchMessage32 (USER.822)
2327 LONG WINAPI DispatchMessage32_16( const MSG32_16* lpmsg16_32, BOOL16 wHaveParamHigh )
2329 if (wHaveParamHigh == FALSE)
2330 return DispatchMessage16(&(lpmsg16_32->msg));
2331 else
2333 MSG msg;
2335 msg.hwnd = lpmsg16_32->msg.hwnd;
2336 msg.message = lpmsg16_32->msg.message;
2337 msg.wParam = MAKELONG(lpmsg16_32->msg.wParam, lpmsg16_32->wParamHigh);
2338 msg.lParam = lpmsg16_32->msg.lParam;
2339 msg.time = lpmsg16_32->msg.time;
2340 msg.pt.x = (INT)lpmsg16_32->msg.pt.x;
2341 msg.pt.y = (INT)lpmsg16_32->msg.pt.y;
2342 return DispatchMessageA(&msg);
2346 /***********************************************************************
2347 * DispatchMessageA (USER32.141)
2349 LONG WINAPI DispatchMessageA( const MSG* msg )
2351 WND * wndPtr;
2352 LONG retval;
2353 int painting;
2355 /* Process timer messages */
2356 if ((msg->message == WM_TIMER) || (msg->message == WM_SYSTIMER))
2358 if (msg->lParam)
2360 /* HOOK_CallHooks32A( WH_CALLWNDPROC, HC_ACTION, 0, FIXME ); */
2361 return CallWindowProcA( (WNDPROC)msg->lParam, msg->hwnd,
2362 msg->message, msg->wParam, GetTickCount() );
2366 if (!msg->hwnd) return 0;
2367 if (!(wndPtr = WIN_FindWndPtr( msg->hwnd ))) return 0;
2368 if (!wndPtr->winproc)
2370 retval = 0;
2371 goto END;
2373 painting = (msg->message == WM_PAINT);
2374 if (painting) wndPtr->flags |= WIN_NEEDS_BEGINPAINT;
2375 /* HOOK_CallHooks32A( WH_CALLWNDPROC, HC_ACTION, 0, FIXME ); */
2377 SPY_EnterMessage( SPY_DISPATCHMESSAGE, msg->hwnd, msg->message,
2378 msg->wParam, msg->lParam );
2379 retval = CallWindowProcA( (WNDPROC)wndPtr->winproc,
2380 msg->hwnd, msg->message,
2381 msg->wParam, msg->lParam );
2382 SPY_ExitMessage( SPY_RESULT_OK, msg->hwnd, msg->message, retval );
2384 WIN_ReleaseWndPtr(wndPtr);
2385 wndPtr = WIN_FindWndPtr(msg->hwnd);
2387 if (painting && wndPtr &&
2388 (wndPtr->flags & WIN_NEEDS_BEGINPAINT) && wndPtr->hrgnUpdate)
2390 ERR("BeginPaint not called on WM_PAINT for hwnd %04x!\n",
2391 msg->hwnd);
2392 wndPtr->flags &= ~WIN_NEEDS_BEGINPAINT;
2393 /* Validate the update region to avoid infinite WM_PAINT loop */
2394 ValidateRect( msg->hwnd, NULL );
2396 END:
2397 WIN_ReleaseWndPtr(wndPtr);
2398 return retval;
2402 /***********************************************************************
2403 * DispatchMessageW (USER32.142) Process Message
2405 * Process the message specified in the structure *_msg_.
2407 * If the lpMsg parameter points to a WM_TIMER message and the
2408 * parameter of the WM_TIMER message is not NULL, the lParam parameter
2409 * points to the function that is called instead of the window
2410 * procedure.
2412 * The message must be valid.
2414 * RETURNS
2416 * DispatchMessage() returns the result of the window procedure invoked.
2418 * CONFORMANCE
2420 * ECMA-234, Win32
2423 LONG WINAPI DispatchMessageW( const MSG* msg )
2425 WND * wndPtr;
2426 LONG retval;
2427 int painting;
2429 /* Process timer messages */
2430 if ((msg->message == WM_TIMER) || (msg->message == WM_SYSTIMER))
2432 if (msg->lParam)
2434 /* HOOK_CallHooks32W( WH_CALLWNDPROC, HC_ACTION, 0, FIXME ); */
2435 return CallWindowProcW( (WNDPROC)msg->lParam, msg->hwnd,
2436 msg->message, msg->wParam, GetTickCount() );
2440 if (!msg->hwnd) return 0;
2441 if (!(wndPtr = WIN_FindWndPtr( msg->hwnd ))) return 0;
2442 if (!wndPtr->winproc)
2444 retval = 0;
2445 goto END;
2447 painting = (msg->message == WM_PAINT);
2448 if (painting) wndPtr->flags |= WIN_NEEDS_BEGINPAINT;
2449 /* HOOK_CallHooks32W( WH_CALLWNDPROC, HC_ACTION, 0, FIXME ); */
2451 SPY_EnterMessage( SPY_DISPATCHMESSAGE, msg->hwnd, msg->message,
2452 msg->wParam, msg->lParam );
2453 retval = CallWindowProcW( (WNDPROC)wndPtr->winproc,
2454 msg->hwnd, msg->message,
2455 msg->wParam, msg->lParam );
2456 SPY_ExitMessage( SPY_RESULT_OK, msg->hwnd, msg->message, retval );
2458 WIN_ReleaseWndPtr(wndPtr);
2459 wndPtr = WIN_FindWndPtr(msg->hwnd);
2461 if (painting && wndPtr &&
2462 (wndPtr->flags & WIN_NEEDS_BEGINPAINT) && wndPtr->hrgnUpdate)
2464 ERR("BeginPaint not called on WM_PAINT for hwnd %04x!\n",
2465 msg->hwnd);
2466 wndPtr->flags &= ~WIN_NEEDS_BEGINPAINT;
2467 /* Validate the update region to avoid infinite WM_PAINT loop */
2468 ValidateRect( msg->hwnd, NULL );
2470 END:
2471 WIN_ReleaseWndPtr(wndPtr);
2472 return retval;
2476 /***********************************************************************
2477 * RegisterWindowMessageA (USER.118) (USER32.437)
2479 WORD WINAPI RegisterWindowMessageA( LPCSTR str )
2481 TRACE("%s\n", str );
2482 return GlobalAddAtomA( str );
2486 /***********************************************************************
2487 * RegisterWindowMessageW (USER32.438)
2489 WORD WINAPI RegisterWindowMessageW( LPCWSTR str )
2491 TRACE("%p\n", str );
2492 return GlobalAddAtomW( str );
2496 /***********************************************************************
2497 * GetCurrentTime16 (USER.15)
2499 * (effectively identical to GetTickCount)
2501 DWORD WINAPI GetCurrentTime16(void)
2503 return GetTickCount();
2507 /***********************************************************************
2508 * InSendMessage16 (USER.192)
2510 BOOL16 WINAPI InSendMessage16(void)
2512 return InSendMessage();
2516 /***********************************************************************
2517 * InSendMessage (USER32.320)
2519 BOOL WINAPI InSendMessage(void)
2521 MESSAGEQUEUE *queue;
2522 BOOL ret;
2524 if (!(queue = (MESSAGEQUEUE *)QUEUE_Lock( GetFastQueue16() )))
2525 return 0;
2526 ret = (BOOL)queue->smWaiting;
2528 QUEUE_Unlock( queue );
2529 return ret;
2532 /***********************************************************************
2533 * BroadcastSystemMessage (USER32.12)
2535 LONG WINAPI BroadcastSystemMessage(
2536 DWORD dwFlags,LPDWORD recipients,UINT uMessage,WPARAM wParam,
2537 LPARAM lParam
2539 FIXME_(sendmsg)("(%08lx,%08lx,%08x,%08x,%08lx): stub!\n",
2540 dwFlags,*recipients,uMessage,wParam,lParam
2542 return 0;
2545 /***********************************************************************
2546 * SendNotifyMessageA (USER32.460)
2547 * FIXME
2548 * The message sended with PostMessage has to be put in the queue
2549 * with a higher priority as the other "Posted" messages.
2550 * QUEUE_AddMsg has to be modifyed.
2552 BOOL WINAPI SendNotifyMessageA(HWND hwnd,UINT msg,WPARAM wParam,LPARAM lParam)
2553 { BOOL ret = TRUE;
2554 FIXME("(%04x,%08x,%08x,%08lx) not complete\n",
2555 hwnd, msg, wParam, lParam);
2557 if ( GetCurrentThreadId() == GetWindowThreadProcessId ( hwnd, NULL))
2558 { ret=SendMessageA ( hwnd, msg, wParam, lParam );
2560 else
2561 { PostMessageA ( hwnd, msg, wParam, lParam );
2563 return ret;
2566 /***********************************************************************
2567 * SendNotifyMessageW (USER32.461)
2568 * FIXME
2569 * The message sended with PostMessage has to be put in the queue
2570 * with a higher priority as the other "Posted" messages.
2571 * QUEUE_AddMsg has to be modifyed.
2573 BOOL WINAPI SendNotifyMessageW(HWND hwnd,UINT msg,WPARAM wParam,LPARAM lParam)
2574 { BOOL ret = TRUE;
2575 FIXME("(%04x,%08x,%08x,%08lx) not complete\n",
2576 hwnd, msg, wParam, lParam);
2578 if ( GetCurrentThreadId() == GetWindowThreadProcessId ( hwnd, NULL))
2579 { ret=SendMessageW ( hwnd, msg, wParam, lParam );
2581 else
2582 { PostMessageW ( hwnd, msg, wParam, lParam );
2584 return ret;
2587 /***********************************************************************
2588 * SendMessageCallbackA
2589 * FIXME: It's like PostMessage. The callback gets called when the message
2590 * is processed. We have to modify the message processing for a exact
2591 * implementation...
2593 BOOL WINAPI SendMessageCallbackA(
2594 HWND hWnd,UINT Msg,WPARAM wParam,LPARAM lParam,
2595 FARPROC lpResultCallBack,DWORD dwData)
2597 FIXME("(0x%04x,0x%04x,0x%08x,0x%08lx,%p,0x%08lx),stub!\n",
2598 hWnd,Msg,wParam,lParam,lpResultCallBack,dwData);
2599 if ( hWnd == HWND_BROADCAST)
2600 { PostMessageA( hWnd, Msg, wParam, lParam);
2601 FIXME("Broadcast: Callback will not be called!\n");
2602 return TRUE;
2604 (lpResultCallBack)( hWnd, Msg, dwData, SendMessageA ( hWnd, Msg, wParam, lParam ));
2605 return TRUE;
2607 /***********************************************************************
2608 * SendMessageCallbackW
2609 * FIXME: It's like PostMessage. The callback gets called when the message
2610 * is processed. We have to modify the message processing for a exact
2611 * implementation...
2613 BOOL WINAPI SendMessageCallbackW(
2614 HWND hWnd,UINT Msg,WPARAM wParam,LPARAM lParam,
2615 FARPROC lpResultCallBack,DWORD dwData)
2617 FIXME("(0x%04x,0x%04x,0x%08x,0x%08lx,%p,0x%08lx),stub!\n",
2618 hWnd,Msg,wParam,lParam,lpResultCallBack,dwData);
2619 if ( hWnd == HWND_BROADCAST)
2620 { PostMessageW( hWnd, Msg, wParam, lParam);
2621 FIXME("Broadcast: Callback will not be called!\n");
2622 return TRUE;
2624 (lpResultCallBack)( hWnd, Msg, dwData, SendMessageA ( hWnd, Msg, wParam, lParam ));
2625 return TRUE;