Fixes for C++ Winelib compilation.
[wine.git] / windows / message.c
blobf3b0c96f64b0cbdd78ff94cd5c5191b4e6c513a7
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 "message.h"
14 #include "win.h"
15 #include "gdi.h"
16 #include "sysmetrics.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 "thread.h"
28 #include "options.h"
29 #include "struct32.h"
30 #include "debug.h"
32 #define WM_NCMOUSEFIRST WM_NCMOUSEMOVE
33 #define WM_NCMOUSELAST WM_NCMBUTTONDBLCLK
35 typedef enum { SYSQ_MSG_ABANDON, SYSQ_MSG_SKIP,
36 SYSQ_MSG_ACCEPT, SYSQ_MSG_CONTINUE } SYSQ_STATUS;
38 extern MESSAGEQUEUE *pCursorQueue; /* queue.c */
39 extern MESSAGEQUEUE *pActiveQueue;
41 DWORD MSG_WineStartTicks; /* Ticks at Wine startup */
43 static UINT32 doubleClickSpeed = 452;
44 static INT32 debugSMRL = 0; /* intertask SendMessage() recursion level */
46 /***********************************************************************
47 * MSG_CheckFilter
49 BOOL32 MSG_CheckFilter(WORD uMsg, DWORD filter)
51 if( filter )
52 return (uMsg >= LOWORD(filter) && uMsg <= HIWORD(filter));
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 #define lppt ((LPPOINT16)&lValue)
66 /* pt has to be in the client coordinates of the parent window */
68 MapWindowPoints16( 0, wndPtr->hwndSelf, lppt, 1 );
69 while (wndPtr)
71 if (!(wndPtr->dwStyle & WS_CHILD) || (wndPtr->dwExStyle & WS_EX_NOPARENTNOTIFY)) break;
72 lppt->x += wndPtr->rectClient.left;
73 lppt->y += wndPtr->rectClient.top;
74 wndPtr = wndPtr->parent;
75 SendMessage32A( wndPtr->hwndSelf, WM_PARENTNOTIFY,
76 MAKEWPARAM( event, idChild ), lValue );
78 #undef lppt
82 /***********************************************************************
83 * MSG_TranslateMouseMsg
85 * Translate an mouse hardware event into a real mouse message.
86 * Return value indicates whether the translated message must be passed
87 * to the user, left in the queue, or skipped entirely (in this case
88 * HIWORD contains hit test code).
90 static DWORD MSG_TranslateMouseMsg( HWND16 hTopWnd, DWORD filter,
91 MSG16 *msg, BOOL32 remove, WND* pWndScope )
93 static DWORD dblclk_time_limit = 0;
94 static UINT16 clk_message = 0;
95 static HWND16 clk_hwnd = 0;
96 static POINT16 clk_pos = { 0, 0 };
98 WND *pWnd;
99 HWND16 hWnd;
100 INT16 ht, hittest, sendSC = 0;
101 UINT16 message = msg->message;
102 POINT16 screen_pt, pt;
103 HANDLE16 hQ = GetTaskQueue(0);
104 MESSAGEQUEUE *queue = (MESSAGEQUEUE *)GlobalLock16(hQ);
105 BOOL32 eatMsg = FALSE;
106 BOOL32 mouseClick = ((message == WM_LBUTTONDOWN) ||
107 (message == WM_RBUTTONDOWN) ||
108 (message == WM_MBUTTONDOWN))?1:0;
109 SYSQ_STATUS ret = 0;
111 /* Find the window */
113 ht = hittest = HTCLIENT;
114 hWnd = GetCapture16();
115 if( !hWnd )
117 ht = hittest = WINPOS_WindowFromPoint( pWndScope, msg->pt, &pWnd );
118 if( !pWnd ) pWnd = WIN_GetDesktop();
119 hWnd = pWnd->hwndSelf;
120 sendSC = 1;
122 else
124 pWnd = WIN_FindWndPtr(hWnd);
125 ht = EVENT_GetCaptureInfo();
128 /* stop if not the right queue */
130 if (pWnd->hmemTaskQ != hQ)
132 /* Not for the current task */
133 if (queue) QUEUE_ClearWakeBit( queue, QS_MOUSE );
134 /* Wake up the other task */
135 queue = (MESSAGEQUEUE *)GlobalLock16( pWnd->hmemTaskQ );
136 if (queue) QUEUE_SetWakeBit( queue, QS_MOUSE );
137 return SYSQ_MSG_ABANDON;
140 /* check if hWnd is within hWndScope */
142 if( hTopWnd && hWnd != hTopWnd )
143 if( !IsChild16(hTopWnd, hWnd) ) return SYSQ_MSG_CONTINUE;
145 if( mouseClick )
147 /* translate double clicks -
148 * note that ...MOUSEMOVEs can slip in between
149 * ...BUTTONDOWN and ...BUTTONDBLCLK messages */
151 if( pWnd->class->style & CS_DBLCLKS || ht != HTCLIENT )
153 if ((message == clk_message) && (hWnd == clk_hwnd) &&
154 (msg->time - dblclk_time_limit < doubleClickSpeed) &&
155 (abs(msg->pt.x - clk_pos.x) < SYSMETRICS_CXDOUBLECLK/2) &&
156 (abs(msg->pt.y - clk_pos.y) < SYSMETRICS_CYDOUBLECLK/2))
158 message += (WM_LBUTTONDBLCLK - WM_LBUTTONDOWN);
159 mouseClick++; /* == 2 */
163 screen_pt = pt = msg->pt;
165 if (hittest != HTCLIENT)
167 message += ((INT16)WM_NCMOUSEMOVE - WM_MOUSEMOVE);
168 msg->wParam = hittest;
170 else ScreenToClient16( hWnd, &pt );
172 /* check message filter */
174 if (!MSG_CheckFilter(message, filter)) return SYSQ_MSG_CONTINUE;
176 pCursorQueue = queue;
178 /* call WH_MOUSE */
180 if (HOOK_IsHooked( WH_MOUSE ))
182 MOUSEHOOKSTRUCT16 *hook = SEGPTR_NEW(MOUSEHOOKSTRUCT16);
183 if( hook )
185 hook->pt = screen_pt;
186 hook->hwnd = hWnd;
187 hook->wHitTestCode = hittest;
188 hook->dwExtraInfo = 0;
189 ret = HOOK_CallHooks16( WH_MOUSE, remove ? HC_ACTION : HC_NOREMOVE,
190 message, (LPARAM)SEGPTR_GET(hook) );
191 SEGPTR_FREE(hook);
193 if( ret ) return MAKELONG((INT16)SYSQ_MSG_SKIP, hittest);
196 if ((hittest == HTERROR) || (hittest == HTNOWHERE))
197 eatMsg = sendSC = 1;
198 else if( remove && mouseClick )
200 HWND32 hwndTop = WIN_GetTopParent( hWnd );
202 if( mouseClick == 1 )
204 /* set conditions */
205 dblclk_time_limit = msg->time;
206 clk_message = msg->message;
207 clk_hwnd = hWnd;
208 clk_pos = screen_pt;
209 } else
210 /* got double click - zero them out */
211 dblclk_time_limit = clk_hwnd = 0;
213 if( sendSC )
215 /* Send the WM_PARENTNOTIFY,
216 * note that even for double/nonclient clicks
217 * notification message is still WM_L/M/RBUTTONDOWN.
220 MSG_SendParentNotify( pWnd, msg->message, 0, MAKELPARAM(screen_pt.x, screen_pt.y) );
222 /* Activate the window if needed */
224 if (hWnd != GetActiveWindow16() && hWnd != GetDesktopWindow16())
226 LONG ret = SendMessage16( hWnd, WM_MOUSEACTIVATE, hwndTop,
227 MAKELONG( hittest, message ) );
229 if ((ret == MA_ACTIVATEANDEAT) || (ret == MA_NOACTIVATEANDEAT))
230 eatMsg = TRUE;
232 if (((ret == MA_ACTIVATE) || (ret == MA_ACTIVATEANDEAT))
233 && hwndTop != GetActiveWindow16() )
234 if (!WINPOS_SetActiveWindow( hwndTop, TRUE , TRUE ))
235 eatMsg = TRUE;
238 } else sendSC = (remove && sendSC);
240 /* Send the WM_SETCURSOR message */
242 if (sendSC)
243 SendMessage16( hWnd, WM_SETCURSOR, (WPARAM16)hWnd,
244 MAKELONG( hittest, message ));
245 if (eatMsg) return MAKELONG( (UINT16)SYSQ_MSG_SKIP, hittest);
247 msg->hwnd = hWnd;
248 msg->message = message;
249 msg->lParam = MAKELONG( pt.x, pt.y );
250 return SYSQ_MSG_ACCEPT;
254 /***********************************************************************
255 * MSG_TranslateKbdMsg
257 * Translate an keyboard hardware event into a real message.
259 static DWORD MSG_TranslateKbdMsg( HWND16 hTopWnd, DWORD filter,
260 MSG16 *msg, BOOL32 remove )
262 WORD message = msg->message;
263 HWND16 hWnd = GetFocus16();
264 WND *pWnd;
266 /* Should check Ctrl-Esc and PrintScreen here */
268 if (!hWnd)
270 /* Send the message to the active window instead, */
271 /* translating messages to their WM_SYS equivalent */
273 hWnd = GetActiveWindow16();
275 if( message < WM_SYSKEYDOWN )
276 message += WM_SYSKEYDOWN - WM_KEYDOWN;
278 pWnd = WIN_FindWndPtr( hWnd );
279 if (pWnd && (pWnd->hmemTaskQ != GetTaskQueue(0)))
281 /* Not for the current task */
282 MESSAGEQUEUE *queue = (MESSAGEQUEUE *)GlobalLock16( GetTaskQueue(0) );
283 if (queue) QUEUE_ClearWakeBit( queue, QS_KEY );
284 /* Wake up the other task */
285 queue = (MESSAGEQUEUE *)GlobalLock16( pWnd->hmemTaskQ );
286 if (queue) QUEUE_SetWakeBit( queue, QS_KEY );
287 return SYSQ_MSG_ABANDON;
290 if (hTopWnd && hWnd != hTopWnd)
291 if (!IsChild16(hTopWnd, hWnd)) return SYSQ_MSG_CONTINUE;
292 if (!MSG_CheckFilter(message, filter)) return SYSQ_MSG_CONTINUE;
294 msg->hwnd = hWnd;
295 msg->message = message;
297 return (HOOK_CallHooks16( WH_KEYBOARD, remove ? HC_ACTION : HC_NOREMOVE,
298 msg->wParam, msg->lParam )
299 ? SYSQ_MSG_SKIP : SYSQ_MSG_ACCEPT);
303 /***********************************************************************
304 * MSG_JournalRecordMsg
306 * Build an EVENTMSG structure and call JOURNALRECORD hook
308 static void MSG_JournalRecordMsg( MSG16 *msg )
310 EVENTMSG16 *event = SEGPTR_NEW(EVENTMSG16);
311 if (!event) return;
312 event->message = msg->message;
313 event->time = msg->time;
314 if ((msg->message >= WM_KEYFIRST) && (msg->message <= WM_KEYLAST))
316 event->paramL = (msg->wParam & 0xFF) | (HIWORD(msg->lParam) << 8);
317 event->paramH = msg->lParam & 0x7FFF;
318 if (HIWORD(msg->lParam) & 0x0100)
319 event->paramH |= 0x8000; /* special_key - bit */
320 HOOK_CallHooks16( WH_JOURNALRECORD, HC_ACTION, 0,
321 (LPARAM)SEGPTR_GET(event) );
323 else if ((msg->message >= WM_MOUSEFIRST) && (msg->message <= WM_MOUSELAST))
325 event->paramL = LOWORD(msg->lParam); /* X pos */
326 event->paramH = HIWORD(msg->lParam); /* Y pos */
327 ClientToScreen16( msg->hwnd, (LPPOINT16)&event->paramL );
328 HOOK_CallHooks16( WH_JOURNALRECORD, HC_ACTION, 0,
329 (LPARAM)SEGPTR_GET(event) );
331 else if ((msg->message >= WM_NCMOUSEFIRST) &&
332 (msg->message <= WM_NCMOUSELAST))
334 event->paramL = LOWORD(msg->lParam); /* X pos */
335 event->paramH = HIWORD(msg->lParam); /* Y pos */
336 event->message += WM_MOUSEMOVE-WM_NCMOUSEMOVE;/* give no info about NC area */
337 HOOK_CallHooks16( WH_JOURNALRECORD, HC_ACTION, 0,
338 (LPARAM)SEGPTR_GET(event) );
340 SEGPTR_FREE(event);
343 /***********************************************************************
344 * MSG_JournalPlayBackMsg
346 * Get an EVENTMSG struct via call JOURNALPLAYBACK hook function
348 static int MSG_JournalPlayBackMsg(void)
350 EVENTMSG16 *tmpMsg;
351 long wtime,lParam;
352 WORD keyDown,i,wParam,result=0;
354 if ( HOOK_IsHooked( WH_JOURNALPLAYBACK ) )
356 tmpMsg = SEGPTR_NEW(EVENTMSG16);
357 wtime=HOOK_CallHooks16( WH_JOURNALPLAYBACK, HC_GETNEXT, 0,
358 (LPARAM)SEGPTR_GET(tmpMsg));
359 /* TRACE(msg,"Playback wait time =%ld\n",wtime); */
360 if (wtime<=0)
362 wtime=0;
363 if ((tmpMsg->message>= WM_KEYFIRST) && (tmpMsg->message <= WM_KEYLAST))
365 wParam=tmpMsg->paramL & 0xFF;
366 lParam=MAKELONG(tmpMsg->paramH&0x7ffff,tmpMsg->paramL>>8);
367 if (tmpMsg->message == WM_KEYDOWN || tmpMsg->message == WM_SYSKEYDOWN)
369 for (keyDown=i=0; i<256 && !keyDown; i++)
370 if (InputKeyStateTable[i] & 0x80)
371 keyDown++;
372 if (!keyDown)
373 lParam |= 0x40000000;
374 AsyncKeyStateTable[wParam]=InputKeyStateTable[wParam] |= 0x80;
376 else /* WM_KEYUP, WM_SYSKEYUP */
378 lParam |= 0xC0000000;
379 AsyncKeyStateTable[wParam]=InputKeyStateTable[wParam] &= ~0x80;
381 if (InputKeyStateTable[VK_MENU] & 0x80)
382 lParam |= 0x20000000;
383 if (tmpMsg->paramH & 0x8000) /*special_key bit*/
384 lParam |= 0x01000000;
385 hardware_event( tmpMsg->message, wParam, lParam,0, 0, tmpMsg->time, 0 );
387 else
389 if ((tmpMsg->message>= WM_MOUSEFIRST) && (tmpMsg->message <= WM_MOUSELAST))
391 switch (tmpMsg->message)
393 case WM_LBUTTONDOWN:
394 MouseButtonsStates[0]=AsyncMouseButtonsStates[0]=TRUE;break;
395 case WM_LBUTTONUP:
396 MouseButtonsStates[0]=AsyncMouseButtonsStates[0]=FALSE;break;
397 case WM_MBUTTONDOWN:
398 MouseButtonsStates[1]=AsyncMouseButtonsStates[1]=TRUE;break;
399 case WM_MBUTTONUP:
400 MouseButtonsStates[1]=AsyncMouseButtonsStates[1]=FALSE;break;
401 case WM_RBUTTONDOWN:
402 MouseButtonsStates[2]=AsyncMouseButtonsStates[2]=TRUE;break;
403 case WM_RBUTTONUP:
404 MouseButtonsStates[2]=AsyncMouseButtonsStates[2]=FALSE;break;
406 AsyncKeyStateTable[VK_LBUTTON]= InputKeyStateTable[VK_LBUTTON] = MouseButtonsStates[0] ? 0x80 : 0;
407 AsyncKeyStateTable[VK_MBUTTON]= InputKeyStateTable[VK_MBUTTON] = MouseButtonsStates[1] ? 0x80 : 0;
408 AsyncKeyStateTable[VK_RBUTTON]= InputKeyStateTable[VK_RBUTTON] = MouseButtonsStates[2] ? 0x80 : 0;
409 SetCursorPos32(tmpMsg->paramL,tmpMsg->paramH);
410 lParam=MAKELONG(tmpMsg->paramL,tmpMsg->paramH);
411 wParam=0;
412 if (MouseButtonsStates[0]) wParam |= MK_LBUTTON;
413 if (MouseButtonsStates[1]) wParam |= MK_MBUTTON;
414 if (MouseButtonsStates[2]) wParam |= MK_RBUTTON;
415 hardware_event( tmpMsg->message, wParam, lParam,
416 tmpMsg->paramL, tmpMsg->paramH, tmpMsg->time, 0 );
419 HOOK_CallHooks16( WH_JOURNALPLAYBACK, HC_SKIP, 0,
420 (LPARAM)SEGPTR_GET(tmpMsg));
422 else
424 if( tmpMsg->message == WM_QUEUESYNC )
425 if (HOOK_IsHooked( WH_CBT ))
426 HOOK_CallHooks16( WH_CBT, HCBT_QS, 0, 0L);
428 result= QS_MOUSE | QS_KEY; /* ? */
430 SEGPTR_FREE(tmpMsg);
432 return result;
435 /***********************************************************************
436 * MSG_PeekHardwareMsg
438 * Peek for a hardware message matching the hwnd and message filters.
440 static BOOL32 MSG_PeekHardwareMsg( MSG16 *msg, HWND16 hwnd, DWORD filter,
441 BOOL32 remove )
443 DWORD status = SYSQ_MSG_ACCEPT;
444 MESSAGEQUEUE *sysMsgQueue = QUEUE_GetSysQueue();
445 int i, kbd_msg, pos = sysMsgQueue->nextMessage;
447 /* FIXME: there has to be a better way to do this */
448 joySendMessages();
450 /* If the queue is empty, attempt to fill it */
451 if (!sysMsgQueue->msgCount && THREAD_IsWin16( THREAD_Current() )
452 && TSXPending(display))
453 EVENT_WaitNetEvent( FALSE, FALSE );
455 for (i = kbd_msg = 0; i < sysMsgQueue->msgCount; i++, pos++)
457 if (pos >= sysMsgQueue->queueSize) pos = 0;
458 *msg = sysMsgQueue->messages[pos].msg;
460 /* Translate message */
462 if ((msg->message >= WM_MOUSEFIRST) && (msg->message <= WM_MOUSELAST))
464 HWND32 hWndScope = (HWND32)sysMsgQueue->messages[pos].extraInfo;
466 status = MSG_TranslateMouseMsg(hwnd, filter, msg, remove,
467 (Options.managed && IsWindow32(hWndScope) )
468 ? WIN_FindWndPtr(hWndScope) : WIN_GetDesktop() );
469 kbd_msg = 0;
471 else if ((msg->message >= WM_KEYFIRST) && (msg->message <= WM_KEYLAST))
473 status = MSG_TranslateKbdMsg(hwnd, filter, msg, remove);
474 kbd_msg = 1;
476 else /* Non-standard hardware event */
478 HARDWAREHOOKSTRUCT16 *hook;
479 if ((hook = SEGPTR_NEW(HARDWAREHOOKSTRUCT16)))
481 BOOL32 ret;
482 hook->hWnd = msg->hwnd;
483 hook->wMessage = msg->message;
484 hook->wParam = msg->wParam;
485 hook->lParam = msg->lParam;
486 ret = HOOK_CallHooks16( WH_HARDWARE,
487 remove ? HC_ACTION : HC_NOREMOVE,
488 0, (LPARAM)SEGPTR_GET(hook) );
489 SEGPTR_FREE(hook);
490 if (ret)
492 QUEUE_RemoveMsg( sysMsgQueue, pos );
493 continue;
495 status = SYSQ_MSG_ACCEPT;
499 switch (LOWORD(status))
501 case SYSQ_MSG_ACCEPT:
502 break;
504 case SYSQ_MSG_SKIP:
505 if (HOOK_IsHooked( WH_CBT ))
507 if( kbd_msg )
508 HOOK_CallHooks16( WH_CBT, HCBT_KEYSKIPPED,
509 msg->wParam, msg->lParam );
510 else
512 MOUSEHOOKSTRUCT16 *hook = SEGPTR_NEW(MOUSEHOOKSTRUCT16);
513 if (hook)
515 hook->pt = msg->pt;
516 hook->hwnd = msg->hwnd;
517 hook->wHitTestCode = HIWORD(status);
518 hook->dwExtraInfo = 0;
519 HOOK_CallHooks16( WH_CBT, HCBT_CLICKSKIPPED ,msg->message,
520 (LPARAM)SEGPTR_GET(hook) );
521 SEGPTR_FREE(hook);
526 if (remove)
527 QUEUE_RemoveMsg( sysMsgQueue, pos );
528 /* continue */
530 case SYSQ_MSG_CONTINUE:
531 continue;
533 case SYSQ_MSG_ABANDON:
534 return FALSE;
537 if (remove)
539 if (HOOK_IsHooked( WH_JOURNALRECORD )) MSG_JournalRecordMsg( msg );
540 QUEUE_RemoveMsg( sysMsgQueue, pos );
542 return TRUE;
544 return FALSE;
548 /**********************************************************************
549 * SetDoubleClickTime16 (USER.20)
551 void WINAPI SetDoubleClickTime16( UINT16 interval )
553 SetDoubleClickTime32( interval );
557 /**********************************************************************
558 * SetDoubleClickTime32 (USER32.480)
560 BOOL32 WINAPI SetDoubleClickTime32( UINT32 interval )
562 doubleClickSpeed = interval ? interval : 500;
563 return TRUE;
567 /**********************************************************************
568 * GetDoubleClickTime16 (USER.21)
570 UINT16 WINAPI GetDoubleClickTime16(void)
572 return doubleClickSpeed;
576 /**********************************************************************
577 * GetDoubleClickTime32 (USER32.239)
579 UINT32 WINAPI GetDoubleClickTime32(void)
581 return doubleClickSpeed;
585 /***********************************************************************
586 * MSG_SendMessage
588 * Implementation of an inter-task SendMessage.
590 static LRESULT MSG_SendMessage( HQUEUE16 hDestQueue, HWND16 hwnd, UINT16 msg,
591 WPARAM32 wParam, LPARAM lParam, WORD flags )
593 INT32 prevSMRL = debugSMRL;
594 QSMCTRL qCtrl = { 0, 1};
595 MESSAGEQUEUE *queue, *destQ;
597 if (!(queue = (MESSAGEQUEUE*)GlobalLock16( GetTaskQueue(0) ))) return 0;
598 if (!(destQ = (MESSAGEQUEUE*)GlobalLock16( hDestQueue ))) return 0;
600 if (IsTaskLocked() || !IsWindow32(hwnd)) return 0;
602 debugSMRL+=4;
603 TRACE(sendmsg,"%*sSM: %s [%04x] (%04x -> %04x)\n",
604 prevSMRL, "", SPY_GetMsgName(msg), msg, queue->self, hDestQueue );
606 if( !(queue->wakeBits & QS_SMPARAMSFREE) )
608 TRACE(sendmsg,"\tIntertask SendMessage: sleeping since unreplied SendMessage pending\n");
609 queue->changeBits &= ~QS_SMPARAMSFREE;
610 QUEUE_WaitBits( QS_SMPARAMSFREE );
613 /* resume sending */
615 queue->hWnd = hwnd;
616 queue->msg = msg;
617 queue->wParam = LOWORD(wParam);
618 queue->wParamHigh = HIWORD(wParam);
619 queue->lParam = lParam;
620 queue->hPrevSendingTask = destQ->hSendingTask;
621 destQ->hSendingTask = GetTaskQueue(0);
623 queue->wakeBits &= ~QS_SMPARAMSFREE;
624 queue->flags = (queue->flags & ~(QUEUE_SM_WIN32|QUEUE_SM_UNICODE)) | flags;
626 TRACE(sendmsg,"%*ssm: smResultInit = %08x\n", prevSMRL, "", (unsigned)&qCtrl);
628 queue->smResultInit = &qCtrl;
630 QUEUE_SetWakeBit( destQ, QS_SENDMESSAGE );
632 /* perform task switch and wait for the result */
634 while( qCtrl.bPending )
636 if (!(queue->wakeBits & QS_SMRESULT))
638 queue->changeBits &= ~QS_SMRESULT;
639 if (THREAD_IsWin16( THREAD_Current() ))
640 DirectedYield( destQ->hTask );
641 else
642 QUEUE_Signal( destQ->hTask );
643 QUEUE_WaitBits( QS_SMRESULT );
644 TRACE(sendmsg,"\tsm: have result!\n");
646 /* got something */
648 TRACE(sendmsg,"%*ssm: smResult = %08x\n", prevSMRL, "", (unsigned)queue->smResult );
650 if (queue->smResult) { /* FIXME, smResult should always be set */
651 queue->smResult->lResult = queue->SendMessageReturn;
652 queue->smResult->bPending = FALSE;
654 queue->wakeBits &= ~QS_SMRESULT;
656 if( queue->smResult != &qCtrl )
657 ERR(sendmsg, "%*ssm: weird scenes inside the goldmine!\n", prevSMRL, "");
659 queue->smResultInit = NULL;
661 TRACE(sendmsg,"%*sSM: [%04x] returning %08lx\n", prevSMRL, "", msg, qCtrl.lResult);
662 debugSMRL-=4;
664 return qCtrl.lResult;
668 /***********************************************************************
669 * ReplyMessage16 (USER.115)
671 void WINAPI ReplyMessage16( LRESULT result )
673 MESSAGEQUEUE *senderQ;
674 MESSAGEQUEUE *queue;
676 if (!(queue = (MESSAGEQUEUE*)GlobalLock16( GetTaskQueue(0) ))) return;
678 TRACE(msg,"ReplyMessage, queue %04x\n", queue->self);
680 while( (senderQ = (MESSAGEQUEUE*)GlobalLock16( queue->InSendMessageHandle)))
682 TRACE(msg,"\trpm: replying to %04x (%04x -> %04x)\n",
683 queue->msg, queue->self, senderQ->self);
685 if( queue->wakeBits & QS_SENDMESSAGE )
687 QUEUE_ReceiveMessage( queue );
688 continue; /* ReceiveMessage() already called us */
691 if(!(senderQ->wakeBits & QS_SMRESULT) ) break;
692 if (THREAD_IsWin16(THREAD_Current())) OldYield();
694 if( !senderQ ) { TRACE(msg,"\trpm: done\n"); return; }
696 senderQ->SendMessageReturn = result;
697 TRACE(msg,"\trpm: smResult = %08x, result = %08lx\n",
698 (unsigned)queue->smResultCurrent, result );
700 senderQ->smResult = queue->smResultCurrent;
701 queue->InSendMessageHandle = 0;
703 QUEUE_SetWakeBit( senderQ, QS_SMRESULT );
704 if (THREAD_IsWin16(THREAD_Current())) DirectedYield( queue->hSendingTask );
708 /***********************************************************************
709 * MSG_PeekMessage
711 static BOOL32 MSG_PeekMessage( LPMSG16 msg, HWND16 hwnd, WORD first, WORD last,
712 WORD flags, BOOL32 peek )
714 int pos, mask;
715 MESSAGEQUEUE *msgQueue;
716 HQUEUE16 hQueue;
718 #ifdef CONFIG_IPC
719 DDE_TestDDE(hwnd); /* do we have dde handling in the window ?*/
720 DDE_GetRemoteMessage();
721 #endif /* CONFIG_IPC */
723 mask = QS_POSTMESSAGE | QS_SENDMESSAGE; /* Always selected */
724 if (first || last)
726 if ((first <= WM_KEYLAST) && (last >= WM_KEYFIRST)) mask |= QS_KEY;
727 if ( ((first <= WM_MOUSELAST) && (last >= WM_MOUSEFIRST)) ||
728 ((first <= WM_NCMOUSELAST) && (last >= WM_NCMOUSEFIRST)) ) mask |= QS_MOUSE;
729 if ((first <= WM_TIMER) && (last >= WM_TIMER)) mask |= QS_TIMER;
730 if ((first <= WM_SYSTIMER) && (last >= WM_SYSTIMER)) mask |= QS_TIMER;
731 if ((first <= WM_PAINT) && (last >= WM_PAINT)) mask |= QS_PAINT;
733 else mask |= QS_MOUSE | QS_KEY | QS_TIMER | QS_PAINT;
735 if (IsTaskLocked()) flags |= PM_NOYIELD;
737 /* Never yield on Win32 threads */
738 if (!THREAD_IsWin16(THREAD_Current())) flags |= PM_NOYIELD;
740 while(1)
742 hQueue = GetTaskQueue(0);
743 msgQueue = (MESSAGEQUEUE *)GlobalLock16( hQueue );
744 if (!msgQueue) return FALSE;
745 msgQueue->changeBits = 0;
747 /* First handle a message put by SendMessage() */
749 while (msgQueue->wakeBits & QS_SENDMESSAGE)
750 QUEUE_ReceiveMessage( msgQueue );
752 /* Now handle a WM_QUIT message */
754 if (msgQueue->wPostQMsg &&
755 (!first || WM_QUIT >= first) &&
756 (!last || WM_QUIT <= last) )
758 msg->hwnd = hwnd;
759 msg->message = WM_QUIT;
760 msg->wParam = msgQueue->wExitCode;
761 msg->lParam = 0;
762 if (flags & PM_REMOVE) msgQueue->wPostQMsg = 0;
763 break;
766 /* Now find a normal message */
768 if (((msgQueue->wakeBits & mask) & QS_POSTMESSAGE) &&
769 ((pos = QUEUE_FindMsg( msgQueue, hwnd, first, last )) != -1))
771 QMSG *qmsg = &msgQueue->messages[pos];
772 *msg = qmsg->msg;
773 msgQueue->GetMessageTimeVal = msg->time;
774 msgQueue->GetMessagePosVal = *(DWORD *)&msg->pt;
775 msgQueue->GetMessageExtraInfoVal = qmsg->extraInfo;
777 if (flags & PM_REMOVE) QUEUE_RemoveMsg( msgQueue, pos );
778 break;
781 msgQueue->changeBits |= MSG_JournalPlayBackMsg();
783 /* Now find a hardware event */
785 if (((msgQueue->wakeBits & mask) & (QS_MOUSE | QS_KEY)) &&
786 MSG_PeekHardwareMsg( msg, hwnd, MAKELONG(first,last), flags & PM_REMOVE ))
788 /* Got one */
789 msgQueue->GetMessageTimeVal = msg->time;
790 msgQueue->GetMessagePosVal = *(DWORD *)&msg->pt;
791 msgQueue->GetMessageExtraInfoVal = 0; /* Always 0 for now */
792 break;
795 /* Check again for SendMessage */
797 while (msgQueue->wakeBits & QS_SENDMESSAGE)
798 QUEUE_ReceiveMessage( msgQueue );
800 /* Now find a WM_PAINT message */
802 if ((msgQueue->wakeBits & mask) & QS_PAINT)
804 WND* wndPtr;
805 msg->hwnd = WIN_FindWinToRepaint( hwnd , hQueue );
806 msg->message = WM_PAINT;
807 msg->wParam = 0;
808 msg->lParam = 0;
810 if ((wndPtr = WIN_FindWndPtr(msg->hwnd)))
812 if( wndPtr->dwStyle & WS_MINIMIZE &&
813 wndPtr->class->hIcon )
815 msg->message = WM_PAINTICON;
816 msg->wParam = 1;
819 if( !hwnd || msg->hwnd == hwnd || IsChild16(hwnd,msg->hwnd) )
821 if( wndPtr->flags & WIN_INTERNAL_PAINT && !wndPtr->hrgnUpdate)
823 wndPtr->flags &= ~WIN_INTERNAL_PAINT;
824 QUEUE_DecPaintCount( hQueue );
826 break;
831 /* Check for timer messages, but yield first */
833 if (!(flags & PM_NOYIELD))
835 UserYield();
836 while (msgQueue->wakeBits & QS_SENDMESSAGE)
837 QUEUE_ReceiveMessage( msgQueue );
839 if ((msgQueue->wakeBits & mask) & QS_TIMER)
841 if (TIMER_GetTimerMsg(msg, hwnd, hQueue, flags & PM_REMOVE)) break;
844 if (peek)
846 if (!(flags & PM_NOYIELD)) UserYield();
847 return FALSE;
849 msgQueue->wakeMask = mask;
850 QUEUE_WaitBits( mask );
853 /* We got a message */
854 if (flags & PM_REMOVE)
856 WORD message = msg->message;
858 if (message == WM_KEYDOWN || message == WM_SYSKEYDOWN)
860 BYTE *p = &QueueKeyStateTable[msg->wParam & 0xff];
862 if (!(*p & 0x80))
863 *p ^= 0x01;
864 *p |= 0x80;
866 else if (message == WM_KEYUP || message == WM_SYSKEYUP)
867 QueueKeyStateTable[msg->wParam & 0xff] &= ~0x80;
869 if (peek) return TRUE;
870 else return (msg->message != WM_QUIT);
874 /***********************************************************************
875 * MSG_InternalGetMessage
877 * GetMessage() function for internal use. Behave like GetMessage(),
878 * but also call message filters and optionally send WM_ENTERIDLE messages.
879 * 'hwnd' must be the handle of the dialog or menu window.
880 * 'code' is the message filter value (MSGF_??? codes).
882 BOOL32 MSG_InternalGetMessage( MSG16 *msg, HWND32 hwnd, HWND32 hwndOwner,
883 WPARAM32 code, WORD flags, BOOL32 sendIdle )
885 for (;;)
887 if (sendIdle)
889 if (!MSG_PeekMessage( msg, 0, 0, 0, flags, TRUE ))
891 /* No message present -> send ENTERIDLE and wait */
892 if (IsWindow32(hwndOwner))
893 SendMessage16( hwndOwner, WM_ENTERIDLE,
894 code, (LPARAM)hwnd );
895 MSG_PeekMessage( msg, 0, 0, 0, flags, FALSE );
898 else /* Always wait for a message */
899 MSG_PeekMessage( msg, 0, 0, 0, flags, FALSE );
901 /* Call message filters */
903 if (HOOK_IsHooked( WH_SYSMSGFILTER ) || HOOK_IsHooked( WH_MSGFILTER ))
905 MSG16 *pmsg = SEGPTR_NEW(MSG16);
906 if (pmsg)
908 BOOL32 ret;
909 *pmsg = *msg;
910 ret = ((BOOL16)HOOK_CallHooks16( WH_SYSMSGFILTER, code, 0,
911 (LPARAM)SEGPTR_GET(pmsg) ) ||
912 (BOOL16)HOOK_CallHooks16( WH_MSGFILTER, code, 0,
913 (LPARAM)SEGPTR_GET(pmsg) ));
914 SEGPTR_FREE(pmsg);
915 if (ret)
917 /* Message filtered -> remove it from the queue */
918 /* if it's still there. */
919 if (!(flags & PM_REMOVE))
920 MSG_PeekMessage( msg, 0, 0, 0, PM_REMOVE, TRUE );
921 continue;
926 return (msg->message != WM_QUIT);
931 /***********************************************************************
932 * PeekMessage16 (USER.109)
934 BOOL16 WINAPI PeekMessage16( LPMSG16 msg, HWND16 hwnd, UINT16 first,
935 UINT16 last, UINT16 flags )
937 return MSG_PeekMessage( msg, hwnd, first, last, flags, TRUE );
940 /***********************************************************************
941 * PeekMessageA
943 BOOL32 WINAPI PeekMessage32A( LPMSG32 lpmsg, HWND32 hwnd,
944 UINT32 min,UINT32 max,UINT32 wRemoveMsg)
946 MSG16 msg;
947 BOOL32 ret;
948 ret=PeekMessage16(&msg,hwnd,min,max,wRemoveMsg);
949 /* FIXME: should translate the message to Win32 */
950 STRUCT32_MSG16to32(&msg,lpmsg);
951 return ret;
954 /***********************************************************************
955 * PeekMessageW Check queue for messages
957 * Checks for a message in the thread's queue, filtered as for
958 * GetMessage(). Returns immediately whether a message is available
959 * or not.
961 * Whether a retrieved message is removed from the queue is set by the
962 * _wRemoveMsg_ flags, which should be one of the following values:
964 * PM_NOREMOVE Do not remove the message from the queue.
966 * PM_REMOVE Remove the message from the queue.
968 * In addition, PM_NOYIELD may be combined into _wRemoveMsg_ to
969 * request that the system not yield control during PeekMessage();
970 * however applications may not rely on scheduling behavior.
972 * RETURNS
974 * Nonzero if a message is available and is retrieved, zero otherwise.
976 * CONFORMANCE
978 * ECMA-234, Win32
981 BOOL32 WINAPI PeekMessage32W(
982 LPMSG32 lpmsg, /* buffer to receive message */
983 HWND32 hwnd, /* restrict to messages for hwnd */
984 UINT32 min, /* minimum message to receive */
985 UINT32 max, /* maximum message to receive */
986 UINT32 wRemoveMsg /* removal flags */
988 /* FIXME: Should perform Unicode translation on specific messages */
989 return PeekMessage32A(lpmsg,hwnd,min,max,wRemoveMsg);
992 /***********************************************************************
993 * GetMessage16 (USER.108)
995 BOOL16 WINAPI GetMessage16( SEGPTR msg, HWND16 hwnd, UINT16 first, UINT16 last)
997 MSG16 *lpmsg = (MSG16 *)PTR_SEG_TO_LIN(msg);
998 MSG_PeekMessage( lpmsg,
999 hwnd, first, last, PM_REMOVE, FALSE );
1001 TRACE(msg,"message %04x, hwnd %04x, filter(%04x - %04x)\n", lpmsg->message,
1002 hwnd, first, last );
1003 HOOK_CallHooks16( WH_GETMESSAGE, HC_ACTION, 0, (LPARAM)msg );
1004 return (lpmsg->message != WM_QUIT);
1007 /***********************************************************************
1008 * GetMessage32A (USER32.270)
1010 BOOL32 WINAPI GetMessage32A(MSG32* lpmsg,HWND32 hwnd,UINT32 min,UINT32 max)
1012 BOOL32 ret;
1013 MSG16 *msg = SEGPTR_NEW(MSG16);
1014 if (!msg) return 0;
1015 ret=GetMessage16(SEGPTR_GET(msg),(HWND16)hwnd,min,max);
1016 /* FIXME */
1017 STRUCT32_MSG16to32(msg,lpmsg);
1018 SEGPTR_FREE(msg);
1019 return ret;
1022 /***********************************************************************
1023 * GetMessage32W (USER32.274) Retrieve next message
1025 * GetMessage retrieves the next event from the calling thread's
1026 * queue and deposits it in *lpmsg.
1028 * If _hwnd_ is not NULL, only messages for window _hwnd_ and its
1029 * children as specified by IsChild() are retrieved. If _hwnd_ is NULL
1030 * all application messages are retrieved.
1032 * _min_ and _max_ specify the range of messages of interest. If
1033 * min==max==0, no filtering is performed. Useful examples are
1034 * WM_KEYFIRST and WM_KEYLAST to retrieve keyboard input, and
1035 * WM_MOUSEFIRST and WM_MOUSELAST to retrieve mouse input.
1037 * WM_PAINT messages are not removed from the queue; they remain until
1038 * processed. Other messages are removed from the queue.
1040 * RETURNS
1042 * -1 on error, 0 if message is WM_QUIT, nonzero otherwise.
1044 * CONFORMANCE
1046 * ECMA-234, Win32
1049 BOOL32 WINAPI GetMessage32W(
1050 MSG32* lpmsg, /* buffer to receive message */
1051 HWND32 hwnd, /* restrict to messages for hwnd */
1052 UINT32 min, /* minimum message to receive */
1053 UINT32 max /* maximum message to receive */
1055 BOOL32 ret;
1056 MSG16 *msg = SEGPTR_NEW(MSG16);
1057 if (!msg) return 0;
1058 ret=GetMessage16(SEGPTR_GET(msg),(HWND16)hwnd,min,max);
1059 /* FIXME */
1060 STRUCT32_MSG16to32(msg,lpmsg);
1061 SEGPTR_FREE(msg);
1062 return ret;
1066 /***********************************************************************
1067 * PostMessage16 (USER.110)
1069 BOOL16 WINAPI PostMessage16( HWND16 hwnd, UINT16 message, WPARAM16 wParam,
1070 LPARAM lParam )
1072 MSG16 msg;
1073 WND *wndPtr;
1075 msg.hwnd = hwnd;
1076 msg.message = message;
1077 msg.wParam = wParam;
1078 msg.lParam = lParam;
1079 msg.time = GetTickCount();
1080 msg.pt.x = 0;
1081 msg.pt.y = 0;
1083 #ifdef CONFIG_IPC
1084 if (DDE_PostMessage(&msg))
1085 return TRUE;
1086 #endif /* CONFIG_IPC */
1088 if (hwnd == HWND_BROADCAST)
1090 TRACE(msg,"HWND_BROADCAST !\n");
1091 for (wndPtr = WIN_GetDesktop()->child; wndPtr; wndPtr = wndPtr->next)
1093 if (wndPtr->dwStyle & WS_POPUP || wndPtr->dwStyle & WS_CAPTION)
1095 TRACE(msg,"BROADCAST Message to hWnd=%04x m=%04X w=%04X l=%08lX !\n",
1096 wndPtr->hwndSelf, message, wParam, lParam);
1097 PostMessage16( wndPtr->hwndSelf, message, wParam, lParam );
1100 TRACE(msg,"End of HWND_BROADCAST !\n");
1101 return TRUE;
1104 wndPtr = WIN_FindWndPtr( hwnd );
1105 if (!wndPtr || !wndPtr->hmemTaskQ) return FALSE;
1107 return QUEUE_AddMsg( wndPtr->hmemTaskQ, &msg, 0 );
1111 /***********************************************************************
1112 * PostMessage32A (USER32.419)
1114 BOOL32 WINAPI PostMessage32A( HWND32 hwnd, UINT32 message, WPARAM32 wParam,
1115 LPARAM lParam )
1117 /* FIXME */
1118 if (message&0xffff0000)
1119 FIXME(msg,"message is truncated from %d to %d\n", message, message&0xffff);
1120 if (wParam&0xffff0000)
1121 FIXME(msg,"wParam is truncated from %d to %d\n", wParam, wParam&0xffff);
1122 return PostMessage16( hwnd, message, wParam, lParam );
1126 /***********************************************************************
1127 * PostMessage32W (USER32.420)
1129 BOOL32 WINAPI PostMessage32W( HWND32 hwnd, UINT32 message, WPARAM32 wParam,
1130 LPARAM lParam )
1132 /* FIXME */
1133 if (message&0xffff0000)
1134 FIXME(msg,"message is truncated from %d to %d\n", message, message&0xffff);
1135 if (wParam&0xffff0000)
1136 FIXME(msg,"wParam is truncated from %d to %d\n", wParam, wParam&0xffff);
1137 return PostMessage16( hwnd, message, wParam, lParam );
1141 /***********************************************************************
1142 * PostAppMessage16 (USER.116)
1144 BOOL16 WINAPI PostAppMessage16( HTASK16 hTask, UINT16 message, WPARAM16 wParam,
1145 LPARAM lParam )
1147 MSG16 msg;
1149 if (GetTaskQueue(hTask) == 0) return FALSE;
1150 msg.hwnd = 0;
1151 msg.message = message;
1152 msg.wParam = wParam;
1153 msg.lParam = lParam;
1154 msg.time = GetTickCount();
1155 msg.pt.x = 0;
1156 msg.pt.y = 0;
1158 return QUEUE_AddMsg( GetTaskQueue(hTask), &msg, 0 );
1162 /***********************************************************************
1163 * SendMessage16 (USER.111)
1165 LRESULT WINAPI SendMessage16( HWND16 hwnd, UINT16 msg, WPARAM16 wParam,
1166 LPARAM lParam)
1168 WND * wndPtr;
1169 WND **list, **ppWnd;
1170 LRESULT ret;
1172 #ifdef CONFIG_IPC
1173 MSG16 DDE_msg = { hwnd, msg, wParam, lParam };
1174 if (DDE_SendMessage(&DDE_msg)) return TRUE;
1175 #endif /* CONFIG_IPC */
1177 if (hwnd == HWND_BROADCAST)
1179 if (!(list = WIN_BuildWinArray( WIN_GetDesktop(), 0, NULL )))
1180 return TRUE;
1181 TRACE(msg,"HWND_BROADCAST !\n");
1182 for (ppWnd = list; *ppWnd; ppWnd++)
1184 wndPtr = *ppWnd;
1185 if (!IsWindow32(wndPtr->hwndSelf)) continue;
1186 if (wndPtr->dwStyle & WS_POPUP || wndPtr->dwStyle & WS_CAPTION)
1188 TRACE(msg,"BROADCAST Message to hWnd=%04x m=%04X w=%04lX l=%08lX !\n",
1189 wndPtr->hwndSelf, msg, (DWORD)wParam, lParam);
1190 SendMessage16( wndPtr->hwndSelf, msg, wParam, lParam );
1193 HeapFree( SystemHeap, 0, list );
1194 TRACE(msg,"End of HWND_BROADCAST !\n");
1195 return TRUE;
1198 if (HOOK_IsHooked( WH_CALLWNDPROC ))
1200 LPCWPSTRUCT16 pmsg;
1202 if ((pmsg = SEGPTR_NEW(CWPSTRUCT16)))
1204 pmsg->hwnd = hwnd;
1205 pmsg->message= msg;
1206 pmsg->wParam = wParam;
1207 pmsg->lParam = lParam;
1208 HOOK_CallHooks16( WH_CALLWNDPROC, HC_ACTION, 1,
1209 (LPARAM)SEGPTR_GET(pmsg) );
1210 hwnd = pmsg->hwnd;
1211 msg = pmsg->message;
1212 wParam = pmsg->wParam;
1213 lParam = pmsg->lParam;
1214 SEGPTR_FREE( pmsg );
1218 if (!(wndPtr = WIN_FindWndPtr( hwnd )))
1220 WARN(msg, "invalid hwnd %04x\n", hwnd );
1221 return 0;
1223 if (QUEUE_IsExitingQueue(wndPtr->hmemTaskQ))
1224 return 0; /* Don't send anything if the task is dying */
1226 SPY_EnterMessage( SPY_SENDMESSAGE16, hwnd, msg, wParam, lParam );
1228 if (wndPtr->hmemTaskQ != GetTaskQueue(0))
1229 ret = MSG_SendMessage( wndPtr->hmemTaskQ, hwnd, msg,
1230 wParam, lParam, 0 );
1231 else
1232 ret = CallWindowProc16( (WNDPROC16)wndPtr->winproc,
1233 hwnd, msg, wParam, lParam );
1235 SPY_ExitMessage( SPY_RESULT_OK16, hwnd, msg, ret );
1236 return ret;
1239 /************************************************************************
1240 * MSG_CallWndProcHook32
1242 static void MSG_CallWndProcHook32( LPMSG32 pmsg, BOOL32 bUnicode )
1244 CWPSTRUCT32 cwp;
1246 cwp.lParam = pmsg->lParam;
1247 cwp.wParam = pmsg->wParam;
1248 cwp.message = pmsg->message;
1249 cwp.hwnd = pmsg->hwnd;
1251 if (bUnicode) HOOK_CallHooks32W(WH_CALLWNDPROC, HC_ACTION, 1, (LPARAM)&cwp);
1252 else HOOK_CallHooks32A( WH_CALLWNDPROC, HC_ACTION, 1, (LPARAM)&cwp );
1254 pmsg->lParam = cwp.lParam;
1255 pmsg->wParam = cwp.wParam;
1256 pmsg->message = cwp.message;
1257 pmsg->hwnd = cwp.hwnd;
1260 /**********************************************************************
1261 * PostThreadMessage32A (USER32.422)
1263 * BUGS
1265 * Thread-local message queues are not supported.
1268 BOOL32 WINAPI PostThreadMessage32A(DWORD idThread , UINT32 message,
1269 WPARAM32 wParam, LPARAM lParam )
1271 THDB *thdb = THREAD_ID_TO_THDB(idThread);
1272 if (!thdb || !thdb->process) return FALSE;
1274 FIXME(sendmsg, "(...): Should use thread-local message queue!\n");
1275 return PostAppMessage16(thdb->process->task, message, wParam, lParam);
1278 /**********************************************************************
1279 * PostThreadMessage32W (USER32.423)
1281 * BUGS
1283 * Thread-local message queues are not supported.
1286 BOOL32 WINAPI PostThreadMessage32W(DWORD idThread , UINT32 message,
1287 WPARAM32 wParam, LPARAM lParam )
1289 THDB *thdb = THREAD_ID_TO_THDB(idThread);
1290 if (!thdb || !thdb->process) return FALSE;
1292 FIXME(sendmsg, "(...): Should use thread-local message queue!\n");
1293 return PostAppMessage16(thdb->process->task, message, wParam, lParam);
1296 /***********************************************************************
1297 * SendMessage32A (USER32.454)
1299 LRESULT WINAPI SendMessage32A( HWND32 hwnd, UINT32 msg, WPARAM32 wParam,
1300 LPARAM lParam )
1302 WND * wndPtr;
1303 WND **list, **ppWnd;
1304 LRESULT ret;
1306 if (hwnd == HWND_BROADCAST || hwnd == HWND_TOPMOST)
1308 if (!(list = WIN_BuildWinArray( WIN_GetDesktop(), 0, NULL )))
1309 return TRUE;
1310 for (ppWnd = list; *ppWnd; ppWnd++)
1312 wndPtr = *ppWnd;
1313 if (!IsWindow32(wndPtr->hwndSelf)) continue;
1314 if (wndPtr->dwStyle & WS_POPUP || wndPtr->dwStyle & WS_CAPTION)
1315 SendMessage32A( wndPtr->hwndSelf, msg, wParam, lParam );
1317 HeapFree( SystemHeap, 0, list );
1318 return TRUE;
1321 if (HOOK_IsHooked( WH_CALLWNDPROC ))
1322 MSG_CallWndProcHook32( (LPMSG32)&hwnd, FALSE);
1324 if (!(wndPtr = WIN_FindWndPtr( hwnd )))
1326 WARN(msg, "invalid hwnd %08x\n", hwnd );
1327 return 0;
1330 if (QUEUE_IsExitingQueue(wndPtr->hmemTaskQ))
1331 return 0; /* Don't send anything if the task is dying */
1333 SPY_EnterMessage( SPY_SENDMESSAGE32, hwnd, msg, wParam, lParam );
1335 if (wndPtr->hmemTaskQ != GetTaskQueue(0))
1336 ret = MSG_SendMessage( wndPtr->hmemTaskQ, hwnd, msg, wParam, lParam,
1337 QUEUE_SM_WIN32 );
1338 else
1339 ret = CallWindowProc32A( (WNDPROC32)wndPtr->winproc,
1340 hwnd, msg, wParam, lParam );
1342 SPY_ExitMessage( SPY_RESULT_OK32, hwnd, msg, ret );
1343 return ret;
1347 /***********************************************************************
1348 * SendMessage32W (USER32.459) Send Window Message
1350 * Sends a message to the window procedure of the specified window.
1351 * SendMessage() will not return until the called window procedure
1352 * either returns or calls ReplyMessage().
1354 * Use PostMessage() to send message and return immediately. A window
1355 * procedure may use InSendMessage() to detect
1356 * SendMessage()-originated messages.
1358 * Applications which communicate via HWND_BROADCAST may use
1359 * RegisterWindowMessage() to obtain a unique message to avoid conflicts
1360 * with other applications.
1362 * CONFORMANCE
1364 * ECMA-234, Win32
1366 LRESULT WINAPI SendMessage32W(
1367 HWND32 hwnd, /* Window to send message to. If HWND_BROADCAST,
1368 the message will be sent to all top-level windows. */
1370 UINT32 msg, /* message */
1371 WPARAM32 wParam, /* message parameter */
1372 LPARAM lParam /* additional message parameter */
1374 WND * wndPtr;
1375 WND **list, **ppWnd;
1376 LRESULT ret;
1378 if (hwnd == HWND_BROADCAST || hwnd == HWND_TOPMOST)
1380 if (!(list = WIN_BuildWinArray( WIN_GetDesktop(), 0, NULL )))
1381 return TRUE;
1382 for (ppWnd = list; *ppWnd; ppWnd++)
1384 wndPtr = *ppWnd;
1385 if (!IsWindow32(wndPtr->hwndSelf)) continue;
1386 if (wndPtr->dwStyle & WS_POPUP || wndPtr->dwStyle & WS_CAPTION)
1387 SendMessage32W( wndPtr->hwndSelf, msg, wParam, lParam );
1389 HeapFree( SystemHeap, 0, list );
1390 return TRUE;
1393 if (HOOK_IsHooked( WH_CALLWNDPROC ))
1394 MSG_CallWndProcHook32( (LPMSG32)&hwnd, TRUE);
1396 if (!(wndPtr = WIN_FindWndPtr( hwnd )))
1398 WARN(msg, "invalid hwnd %08x\n", hwnd );
1399 return 0;
1401 if (QUEUE_IsExitingQueue(wndPtr->hmemTaskQ))
1402 return 0; /* Don't send anything if the task is dying */
1404 SPY_EnterMessage( SPY_SENDMESSAGE32, hwnd, msg, wParam, lParam );
1406 if (wndPtr->hmemTaskQ != GetTaskQueue(0))
1407 ret = MSG_SendMessage( wndPtr->hmemTaskQ, hwnd, msg, wParam, lParam,
1408 QUEUE_SM_WIN32 | QUEUE_SM_UNICODE );
1409 else
1410 ret = CallWindowProc32W( (WNDPROC32)wndPtr->winproc,
1411 hwnd, msg, wParam, lParam );
1413 SPY_ExitMessage( SPY_RESULT_OK32, hwnd, msg, ret );
1414 return ret;
1418 /***********************************************************************
1419 * SendMessageTimeout16 (not a WINAPI)
1421 LRESULT WINAPI SendMessageTimeout16( HWND16 hwnd, UINT16 msg, WPARAM16 wParam,
1422 LPARAM lParam, UINT16 flags,
1423 UINT16 timeout, LPWORD resultp)
1425 FIXME(sendmsg, "(...): semistub\n");
1426 return SendMessage16 (hwnd, msg, wParam, lParam);
1430 /***********************************************************************
1431 * SendMessageTimeout32A (USER32.457)
1433 LRESULT WINAPI SendMessageTimeout32A( HWND32 hwnd, UINT32 msg, WPARAM32 wParam,
1434 LPARAM lParam, UINT32 flags,
1435 UINT32 timeout, LPDWORD resultp)
1437 FIXME(sendmsg, "(...): semistub\n");
1438 return SendMessage32A (hwnd, msg, wParam, lParam);
1442 /***********************************************************************
1443 * SendMessageTimeout32W (USER32.458)
1445 LRESULT WINAPI SendMessageTimeout32W( HWND32 hwnd, UINT32 msg, WPARAM32 wParam,
1446 LPARAM lParam, UINT32 flags,
1447 UINT32 timeout, LPDWORD resultp)
1449 FIXME(sendmsg, "(...): semistub\n");
1450 return SendMessage32W (hwnd, msg, wParam, lParam);
1454 /***********************************************************************
1455 * WaitMessage (USER.112) (USER32.578) Suspend thread pending messages
1457 * WaitMessage() suspends a thread until events appear in the thread's
1458 * queue.
1460 * BUGS
1462 * Is supposed to return BOOL under Win32.
1464 * Thread-local message queues are not supported.
1466 * CONFORMANCE
1468 * ECMA-234, Win32
1471 void WINAPI WaitMessage( void )
1473 QUEUE_WaitBits( QS_ALLINPUT );
1476 /***********************************************************************
1477 * MsgWaitForMultipleObjects (USER32.400)
1479 DWORD WINAPI MsgWaitForMultipleObjects( DWORD nCount, HANDLE32 *pHandles,
1480 BOOL32 fWaitAll, DWORD dwMilliseconds,
1481 DWORD dwWakeMask )
1483 DWORD retv;
1485 TDB *currTask = (TDB *)GlobalLock16( GetCurrentTask() );
1486 HQUEUE16 hQueue = currTask? currTask->hQueue : 0;
1487 MESSAGEQUEUE *msgQueue = (MESSAGEQUEUE *)GlobalLock16( hQueue );
1488 if (!msgQueue) return 0xFFFFFFFF;
1490 msgQueue->changeBits = 0;
1491 msgQueue->wakeMask = dwWakeMask;
1493 retv = SYNC_DoWait( nCount, pHandles, fWaitAll, dwMilliseconds, FALSE, TRUE );
1495 return retv;
1500 struct accent_char
1502 BYTE ac_accent;
1503 BYTE ac_char;
1504 BYTE ac_result;
1507 static const struct accent_char accent_chars[] =
1509 /* A good idea should be to read /usr/X11/lib/X11/locale/iso8859-x/Compose */
1510 {'`', 'A', '\300'}, {'`', 'a', '\340'},
1511 {'\'', 'A', '\301'}, {'\'', 'a', '\341'},
1512 {'^', 'A', '\302'}, {'^', 'a', '\342'},
1513 {'~', 'A', '\303'}, {'~', 'a', '\343'},
1514 {'"', 'A', '\304'}, {'"', 'a', '\344'},
1515 {'O', 'A', '\305'}, {'o', 'a', '\345'},
1516 {'0', 'A', '\305'}, {'0', 'a', '\345'},
1517 {'A', 'A', '\305'}, {'a', 'a', '\345'},
1518 {'A', 'E', '\306'}, {'a', 'e', '\346'},
1519 {',', 'C', '\307'}, {',', 'c', '\347'},
1520 {'`', 'E', '\310'}, {'`', 'e', '\350'},
1521 {'\'', 'E', '\311'}, {'\'', 'e', '\351'},
1522 {'^', 'E', '\312'}, {'^', 'e', '\352'},
1523 {'"', 'E', '\313'}, {'"', 'e', '\353'},
1524 {'`', 'I', '\314'}, {'`', 'i', '\354'},
1525 {'\'', 'I', '\315'}, {'\'', 'i', '\355'},
1526 {'^', 'I', '\316'}, {'^', 'i', '\356'},
1527 {'"', 'I', '\317'}, {'"', 'i', '\357'},
1528 {'-', 'D', '\320'}, {'-', 'd', '\360'},
1529 {'~', 'N', '\321'}, {'~', 'n', '\361'},
1530 {'`', 'O', '\322'}, {'`', 'o', '\362'},
1531 {'\'', 'O', '\323'}, {'\'', 'o', '\363'},
1532 {'^', 'O', '\324'}, {'^', 'o', '\364'},
1533 {'~', 'O', '\325'}, {'~', 'o', '\365'},
1534 {'"', 'O', '\326'}, {'"', 'o', '\366'},
1535 {'/', 'O', '\330'}, {'/', 'o', '\370'},
1536 {'`', 'U', '\331'}, {'`', 'u', '\371'},
1537 {'\'', 'U', '\332'}, {'\'', 'u', '\372'},
1538 {'^', 'U', '\333'}, {'^', 'u', '\373'},
1539 {'"', 'U', '\334'}, {'"', 'u', '\374'},
1540 {'\'', 'Y', '\335'}, {'\'', 'y', '\375'},
1541 {'T', 'H', '\336'}, {'t', 'h', '\376'},
1542 {'s', 's', '\337'}, {'"', 'y', '\377'},
1543 {'s', 'z', '\337'}, {'i', 'j', '\377'},
1544 /* iso-8859-2 uses this */
1545 {'<', 'L', '\245'}, {'<', 'l', '\265'}, /* caron */
1546 {'<', 'S', '\251'}, {'<', 's', '\271'},
1547 {'<', 'T', '\253'}, {'<', 't', '\273'},
1548 {'<', 'Z', '\256'}, {'<', 'z', '\276'},
1549 {'<', 'C', '\310'}, {'<', 'c', '\350'},
1550 {'<', 'E', '\314'}, {'<', 'e', '\354'},
1551 {'<', 'D', '\317'}, {'<', 'd', '\357'},
1552 {'<', 'N', '\322'}, {'<', 'n', '\362'},
1553 {'<', 'R', '\330'}, {'<', 'r', '\370'},
1554 {';', 'A', '\241'}, {';', 'a', '\261'}, /* ogonek */
1555 {';', 'E', '\312'}, {';', 'e', '\332'},
1556 {'\'', 'Z', '\254'}, {'\'', 'z', '\274'}, /* acute */
1557 {'\'', 'R', '\300'}, {'\'', 'r', '\340'},
1558 {'\'', 'L', '\305'}, {'\'', 'l', '\345'},
1559 {'\'', 'C', '\306'}, {'\'', 'c', '\346'},
1560 {'\'', 'N', '\321'}, {'\'', 'n', '\361'},
1561 /* collision whith S, from iso-8859-9 !!! */
1562 {',', 'S', '\252'}, {',', 's', '\272'}, /* cedilla */
1563 {',', 'T', '\336'}, {',', 't', '\376'},
1564 {'.', 'Z', '\257'}, {'.', 'z', '\277'}, /* dot above */
1565 {'/', 'L', '\243'}, {'/', 'l', '\263'}, /* slash */
1566 {'/', 'D', '\320'}, {'/', 'd', '\360'},
1567 {'(', 'A', '\303'}, {'(', 'a', '\343'}, /* breve */
1568 {'\275', 'O', '\325'}, {'\275', 'o', '\365'}, /* double acute */
1569 {'\275', 'U', '\334'}, {'\275', 'u', '\374'},
1570 {'0', 'U', '\332'}, {'0', 'u', '\372'}, /* ring above */
1571 /* iso-8859-3 uses this */
1572 {'/', 'H', '\241'}, {'/', 'h', '\261'}, /* slash */
1573 {'>', 'H', '\246'}, {'>', 'h', '\266'}, /* circumflex */
1574 {'>', 'J', '\254'}, {'>', 'j', '\274'},
1575 {'>', 'C', '\306'}, {'>', 'c', '\346'},
1576 {'>', 'G', '\330'}, {'>', 'g', '\370'},
1577 {'>', 'S', '\336'}, {'>', 's', '\376'},
1578 /* collision whith G( from iso-8859-9 !!! */
1579 {'(', 'G', '\253'}, {'(', 'g', '\273'}, /* breve */
1580 {'(', 'U', '\335'}, {'(', 'u', '\375'},
1581 /* collision whith I. from iso-8859-3 !!! */
1582 {'.', 'I', '\251'}, {'.', 'i', '\271'}, /* dot above */
1583 {'.', 'C', '\305'}, {'.', 'c', '\345'},
1584 {'.', 'G', '\325'}, {'.', 'g', '\365'},
1585 /* iso-8859-4 uses this */
1586 {',', 'R', '\243'}, {',', 'r', '\263'}, /* cedilla */
1587 {',', 'L', '\246'}, {',', 'l', '\266'},
1588 {',', 'G', '\253'}, {',', 'g', '\273'},
1589 {',', 'N', '\321'}, {',', 'n', '\361'},
1590 {',', 'K', '\323'}, {',', 'k', '\363'},
1591 {'~', 'I', '\245'}, {'~', 'i', '\265'}, /* tilde */
1592 {'-', 'E', '\252'}, {'-', 'e', '\272'}, /* macron */
1593 {'-', 'A', '\300'}, {'-', 'a', '\340'},
1594 {'-', 'I', '\317'}, {'-', 'i', '\357'},
1595 {'-', 'O', '\322'}, {'-', 'o', '\362'},
1596 {'-', 'U', '\336'}, {'-', 'u', '\376'},
1597 {'/', 'T', '\254'}, {'/', 't', '\274'}, /* slash */
1598 {'.', 'E', '\314'}, {'.', 'e', '\344'}, /* dot above */
1599 {';', 'I', '\307'}, {';', 'i', '\347'}, /* ogonek */
1600 {';', 'U', '\331'}, {';', 'u', '\371'},
1601 /* iso-8859-9 uses this */
1602 /* iso-8859-9 has really bad choosen G( S, and I. as they collide
1603 * whith the same letters on other iso-8859-x (that is they are on
1604 * different places :-( ), if you use turkish uncomment these and
1605 * comment out the lines in iso-8859-2 and iso-8859-3 sections
1606 * FIXME: should be dynamic according to chosen language
1607 * if/when Wine has turkish support.
1609 /* collision whith G( from iso-8859-3 !!! */
1610 /* {'(', 'G', '\320'}, {'(', 'g', '\360'}, */ /* breve */
1611 /* collision whith S, from iso-8859-2 !!! */
1612 /* {',', 'S', '\336'}, {',', 's', '\376'}, */ /* cedilla */
1613 /* collision whith I. from iso-8859-3 !!! */
1614 /* {'.', 'I', '\335'}, {'.', 'i', '\375'}, */ /* dot above */
1618 /***********************************************************************
1619 * MSG_DoTranslateMessage
1621 * Implementation of TranslateMessage.
1623 * TranslateMessage translates virtual-key messages into character-messages,
1624 * as follows :
1625 * WM_KEYDOWN/WM_KEYUP combinations produce a WM_CHAR or WM_DEADCHAR message.
1626 * ditto replacing WM_* with WM_SYS*
1627 * This produces WM_CHAR messages only for keys mapped to ASCII characters
1628 * by the keyboard driver.
1630 static BOOL32 MSG_DoTranslateMessage( UINT32 message, HWND32 hwnd,
1631 WPARAM32 wParam, LPARAM lParam )
1633 static int dead_char;
1634 BYTE wp[2];
1636 if (message != WM_MOUSEMOVE && message != WM_TIMER)
1637 TRACE(msg, "(%s, %04X, %08lX)\n",
1638 SPY_GetMsgName(message), wParam, lParam );
1639 if(message >= WM_KEYFIRST && message <= WM_KEYLAST)
1640 TRACE(key, "(%s, %04X, %08lX)\n",
1641 SPY_GetMsgName(message), wParam, lParam );
1643 if ((message != WM_KEYDOWN) && (message != WM_SYSKEYDOWN)) return FALSE;
1645 TRACE(key, "Translating key %04X, scancode %04X\n",
1646 wParam, HIWORD(lParam) );
1648 /* FIXME : should handle ToAscii yielding 2 */
1649 switch (ToAscii32(wParam, HIWORD(lParam),
1650 QueueKeyStateTable,(LPWORD)wp, 0))
1652 case 1 :
1653 message = (message == WM_KEYDOWN) ? WM_CHAR : WM_SYSCHAR;
1654 /* Should dead chars handling go in ToAscii ? */
1655 if (dead_char)
1657 int i;
1659 if (wp[0] == ' ') wp[0] = dead_char;
1660 if (dead_char == 0xa2) dead_char = '(';
1661 else if (dead_char == 0xa8) dead_char = '"';
1662 else if (dead_char == 0xb2) dead_char = ';';
1663 else if (dead_char == 0xb4) dead_char = '\'';
1664 else if (dead_char == 0xb7) dead_char = '<';
1665 else if (dead_char == 0xb8) dead_char = ',';
1666 else if (dead_char == 0xff) dead_char = '.';
1667 for (i = 0; i < sizeof(accent_chars)/sizeof(accent_chars[0]); i++)
1668 if ((accent_chars[i].ac_accent == dead_char) &&
1669 (accent_chars[i].ac_char == wp[0]))
1671 wp[0] = accent_chars[i].ac_result;
1672 break;
1674 dead_char = 0;
1676 TRACE(key, "1 -> PostMessage(%s)\n", SPY_GetMsgName(message));
1677 PostMessage16( hwnd, message, wp[0], lParam );
1678 return TRUE;
1680 case -1 :
1681 message = (message == WM_KEYDOWN) ? WM_DEADCHAR : WM_SYSDEADCHAR;
1682 dead_char = wp[0];
1683 TRACE(key, "-1 -> PostMessage(%s)\n",
1684 SPY_GetMsgName(message));
1685 PostMessage16( hwnd, message, wp[0], lParam );
1686 return TRUE;
1688 return FALSE;
1692 /***********************************************************************
1693 * TranslateMessage16 (USER.113)
1695 BOOL16 WINAPI TranslateMessage16( const MSG16 *msg )
1697 return MSG_DoTranslateMessage( msg->message, msg->hwnd,
1698 msg->wParam, msg->lParam );
1702 /***********************************************************************
1703 * TranslateMessage32 (USER32.556)
1705 BOOL32 WINAPI TranslateMessage32( const MSG32 *msg )
1707 return MSG_DoTranslateMessage( msg->message, msg->hwnd,
1708 msg->wParam, msg->lParam );
1712 /***********************************************************************
1713 * DispatchMessage16 (USER.114)
1715 LONG WINAPI DispatchMessage16( const MSG16* msg )
1717 WND * wndPtr;
1718 LONG retval;
1719 int painting;
1721 /* Process timer messages */
1722 if ((msg->message == WM_TIMER) || (msg->message == WM_SYSTIMER))
1724 if (msg->lParam)
1726 return CallWindowProc16( (WNDPROC16)msg->lParam, msg->hwnd,
1727 msg->message, msg->wParam, GetTickCount() );
1731 if (!msg->hwnd) return 0;
1732 if (!(wndPtr = WIN_FindWndPtr( msg->hwnd ))) return 0;
1733 if (!wndPtr->winproc) return 0;
1734 painting = (msg->message == WM_PAINT);
1735 if (painting) wndPtr->flags |= WIN_NEEDS_BEGINPAINT;
1737 SPY_EnterMessage( SPY_DISPATCHMESSAGE16, msg->hwnd, msg->message,
1738 msg->wParam, msg->lParam );
1739 retval = CallWindowProc16( (WNDPROC16)wndPtr->winproc,
1740 msg->hwnd, msg->message,
1741 msg->wParam, msg->lParam );
1742 SPY_ExitMessage( SPY_RESULT_OK16, msg->hwnd, msg->message, retval );
1744 if (painting && (wndPtr = WIN_FindWndPtr( msg->hwnd )) &&
1745 (wndPtr->flags & WIN_NEEDS_BEGINPAINT) && wndPtr->hrgnUpdate)
1747 ERR(msg, "BeginPaint not called on WM_PAINT for hwnd %04x!\n",
1748 msg->hwnd);
1749 wndPtr->flags &= ~WIN_NEEDS_BEGINPAINT;
1750 /* Validate the update region to avoid infinite WM_PAINT loop */
1751 ValidateRect32( msg->hwnd, NULL );
1753 return retval;
1757 /***********************************************************************
1758 * DispatchMessage32A (USER32.141)
1760 LONG WINAPI DispatchMessage32A( const MSG32* msg )
1762 WND * wndPtr;
1763 LONG retval;
1764 int painting;
1766 /* Process timer messages */
1767 if ((msg->message == WM_TIMER) || (msg->message == WM_SYSTIMER))
1769 if (msg->lParam)
1771 /* HOOK_CallHooks32A( WH_CALLWNDPROC, HC_ACTION, 0, FIXME ); */
1772 return CallWindowProc32A( (WNDPROC32)msg->lParam, msg->hwnd,
1773 msg->message, msg->wParam, GetTickCount() );
1777 if (!msg->hwnd) return 0;
1778 if (!(wndPtr = WIN_FindWndPtr( msg->hwnd ))) return 0;
1779 if (!wndPtr->winproc) return 0;
1780 painting = (msg->message == WM_PAINT);
1781 if (painting) wndPtr->flags |= WIN_NEEDS_BEGINPAINT;
1782 /* HOOK_CallHooks32A( WH_CALLWNDPROC, HC_ACTION, 0, FIXME ); */
1784 SPY_EnterMessage( SPY_DISPATCHMESSAGE32, msg->hwnd, msg->message,
1785 msg->wParam, msg->lParam );
1786 retval = CallWindowProc32A( (WNDPROC32)wndPtr->winproc,
1787 msg->hwnd, msg->message,
1788 msg->wParam, msg->lParam );
1789 SPY_ExitMessage( SPY_RESULT_OK32, msg->hwnd, msg->message, retval );
1791 if (painting && (wndPtr = WIN_FindWndPtr( msg->hwnd )) &&
1792 (wndPtr->flags & WIN_NEEDS_BEGINPAINT) && wndPtr->hrgnUpdate)
1794 ERR(msg, "BeginPaint not called on WM_PAINT for hwnd %04x!\n",
1795 msg->hwnd);
1796 wndPtr->flags &= ~WIN_NEEDS_BEGINPAINT;
1797 /* Validate the update region to avoid infinite WM_PAINT loop */
1798 ValidateRect32( msg->hwnd, NULL );
1800 return retval;
1804 /***********************************************************************
1805 * DispatchMessage32W (USER32.142) Process Message
1807 * Process the message specified in the structure *_msg_.
1809 * If the lpMsg parameter points to a WM_TIMER message and the
1810 * parameter of the WM_TIMER message is not NULL, the lParam parameter
1811 * points to the function that is called instead of the window
1812 * procedure.
1814 * The message must be valid.
1816 * RETURNS
1818 * DispatchMessage() returns the result of the window procedure invoked.
1820 * CONFORMANCE
1822 * ECMA-234, Win32
1825 LONG WINAPI DispatchMessage32W( const MSG32* msg )
1827 WND * wndPtr;
1828 LONG retval;
1829 int painting;
1831 /* Process timer messages */
1832 if ((msg->message == WM_TIMER) || (msg->message == WM_SYSTIMER))
1834 if (msg->lParam)
1836 /* HOOK_CallHooks32W( WH_CALLWNDPROC, HC_ACTION, 0, FIXME ); */
1837 return CallWindowProc32W( (WNDPROC32)msg->lParam, msg->hwnd,
1838 msg->message, msg->wParam, GetTickCount() );
1842 if (!msg->hwnd) return 0;
1843 if (!(wndPtr = WIN_FindWndPtr( msg->hwnd ))) return 0;
1844 if (!wndPtr->winproc) return 0;
1845 painting = (msg->message == WM_PAINT);
1846 if (painting) wndPtr->flags |= WIN_NEEDS_BEGINPAINT;
1847 /* HOOK_CallHooks32W( WH_CALLWNDPROC, HC_ACTION, 0, FIXME ); */
1849 SPY_EnterMessage( SPY_DISPATCHMESSAGE32, msg->hwnd, msg->message,
1850 msg->wParam, msg->lParam );
1851 retval = CallWindowProc32W( (WNDPROC32)wndPtr->winproc,
1852 msg->hwnd, msg->message,
1853 msg->wParam, msg->lParam );
1854 SPY_ExitMessage( SPY_RESULT_OK32, msg->hwnd, msg->message, retval );
1856 if (painting && (wndPtr = WIN_FindWndPtr( msg->hwnd )) &&
1857 (wndPtr->flags & WIN_NEEDS_BEGINPAINT) && wndPtr->hrgnUpdate)
1859 ERR(msg, "BeginPaint not called on WM_PAINT for hwnd %04x!\n",
1860 msg->hwnd);
1861 wndPtr->flags &= ~WIN_NEEDS_BEGINPAINT;
1862 /* Validate the update region to avoid infinite WM_PAINT loop */
1863 ValidateRect32( msg->hwnd, NULL );
1865 return retval;
1869 /***********************************************************************
1870 * RegisterWindowMessage16 (USER.118)
1872 WORD WINAPI RegisterWindowMessage16( SEGPTR str )
1874 TRACE(msg, "%08lx\n", (DWORD)str );
1875 return GlobalAddAtom16( str );
1879 /***********************************************************************
1880 * RegisterWindowMessage32A (USER32.437)
1882 WORD WINAPI RegisterWindowMessage32A( LPCSTR str )
1884 TRACE(msg, "%s\n", str );
1885 return GlobalAddAtom32A( str );
1889 /***********************************************************************
1890 * RegisterWindowMessage32W (USER32.438)
1892 WORD WINAPI RegisterWindowMessage32W( LPCWSTR str )
1894 TRACE(msg, "%p\n", str );
1895 return GlobalAddAtom32W( str );
1899 /***********************************************************************
1900 * GetTickCount (USER.13) (KERNEL32.299) System Time
1901 * Returns the number of milliseconds, modulo 2^32, since the start
1902 * of the current session.
1904 * CONFORMANCE
1906 * ECMA-234, Win32
1908 DWORD WINAPI GetTickCount(void)
1910 struct timeval t;
1911 gettimeofday( &t, NULL );
1912 /* make extremely compatible: granularity is 25 msec */
1913 return ((t.tv_sec * 1000) + (t.tv_usec / 25000) * 25) - MSG_WineStartTicks;
1917 /***********************************************************************
1918 * GetCurrentTime16 (USER.15)
1920 * (effectively identical to GetTickCount)
1922 DWORD WINAPI GetCurrentTime16(void)
1924 return GetTickCount();
1928 /***********************************************************************
1929 * InSendMessage16 (USER.192)
1931 BOOL16 WINAPI InSendMessage16(void)
1933 return InSendMessage32();
1937 /***********************************************************************
1938 * InSendMessage32 (USER32.320)
1940 BOOL32 WINAPI InSendMessage32(void)
1942 MESSAGEQUEUE *queue;
1944 if (!(queue = (MESSAGEQUEUE *)GlobalLock16( GetTaskQueue(0) )))
1945 return 0;
1946 return (BOOL32)queue->InSendMessageHandle;
1949 /***********************************************************************
1950 * BroadcastSystemMessage (USER32.12)
1952 LONG WINAPI BroadcastSystemMessage(
1953 DWORD dwFlags,LPDWORD recipients,UINT32 uMessage,WPARAM32 wParam,
1954 LPARAM lParam
1956 FIXME(sendmsg,"(%08lx,%08lx,%08x,%08x,%08lx): stub!\n",
1957 dwFlags,*recipients,uMessage,wParam,lParam
1959 return 0;
1962 /***********************************************************************
1963 * SendNotifyMessageA (USER32.460)
1964 * FIXME
1965 * The message sended with PostMessage has to be put in the queue
1966 * with a higher priority as the other "Posted" messages.
1967 * QUEUE_AddMsg has to be modifyed.
1969 LONG WINAPI SendNotifyMessage32A(HWND32 hwnd,UINT32 msg,WPARAM32 wParam,LPARAM lParam)
1970 { BOOL32 ret = TRUE;
1971 FIXME(msg,"(%04x,%08x,%08x,%08lx) not complete\n",
1972 hwnd, msg, wParam, lParam);
1974 if ( GetCurrentThreadId() == GetWindowThreadProcessId ( hwnd, NULL))
1975 { ret=SendMessage32A ( hwnd, msg, wParam, lParam );
1977 else
1978 { PostMessage32A ( hwnd, msg, wParam, lParam );
1980 return ret;
1982 /***********************************************************************
1983 * SendMessageCallBack32A
1984 * FIXME: It's like PostMessage. The callback gets called when the message
1985 * is processed. We have to modify the message processing for a exact
1986 * implementation...
1988 BOOL32 WINAPI SendMessageCallBack32A(
1989 HWND32 hWnd,UINT32 Msg,WPARAM32 wParam,LPARAM lParam,
1990 FARPROC32 lpResultCallBack,DWORD dwData)
1992 FIXME(msg,"(0x%04x,0x%04x,0x%08x,0x%08lx,%p,0x%08lx),stub!\n",
1993 hWnd,Msg,wParam,lParam,lpResultCallBack,dwData);
1994 if ( hWnd == HWND_BROADCAST)
1995 { PostMessage32A( hWnd, Msg, wParam, lParam);
1996 FIXME(msg,"Broadcast: Callback will not be called!\n");
1997 return TRUE;
1999 (lpResultCallBack)( hWnd, Msg, dwData, SendMessage32A ( hWnd, Msg, wParam, lParam ));
2000 return TRUE;