Fixed bug in CreateFileMapping when name is not NULL.
[wine/multimedia.git] / windows / message.c
blob84e915182a335833935ebd884f2e9f8f37e0c077
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 "winerror.h"
15 #include "win.h"
16 #include "gdi.h"
17 #include "sysmetrics.h"
18 #include "heap.h"
19 #include "hook.h"
20 #include "input.h"
21 #include "spy.h"
22 #include "winpos.h"
23 #include "dde.h"
24 #include "queue.h"
25 #include "winproc.h"
26 #include "task.h"
27 #include "process.h"
28 #include "thread.h"
29 #include "options.h"
30 #include "struct32.h"
31 #include "debug.h"
33 #define WM_NCMOUSEFIRST WM_NCMOUSEMOVE
34 #define WM_NCMOUSELAST WM_NCMBUTTONDBLCLK
36 typedef enum { SYSQ_MSG_ABANDON, SYSQ_MSG_SKIP,
37 SYSQ_MSG_ACCEPT, SYSQ_MSG_CONTINUE } SYSQ_STATUS;
39 extern MESSAGEQUEUE *pCursorQueue; /* queue.c */
40 extern MESSAGEQUEUE *pActiveQueue;
42 DWORD MSG_WineStartTicks; /* Ticks at Wine startup */
44 static UINT32 doubleClickSpeed = 452;
45 static INT32 debugSMRL = 0; /* intertask SendMessage() recursion level */
47 /***********************************************************************
48 * MSG_CheckFilter
50 BOOL32 MSG_CheckFilter(WORD uMsg, DWORD filter)
52 if( filter )
53 return (uMsg >= LOWORD(filter) && uMsg <= HIWORD(filter));
54 return TRUE;
57 /***********************************************************************
58 * MSG_SendParentNotify
60 * Send a WM_PARENTNOTIFY to all ancestors of the given window, unless
61 * the window has the WS_EX_NOPARENTNOTIFY style.
63 static void MSG_SendParentNotify(WND* wndPtr, WORD event, WORD idChild, LPARAM lValue)
65 #define lppt ((LPPOINT16)&lValue)
67 /* pt has to be in the client coordinates of the parent window */
69 MapWindowPoints16( 0, wndPtr->hwndSelf, lppt, 1 );
70 while (wndPtr)
72 if (!(wndPtr->dwStyle & WS_CHILD) || (wndPtr->dwExStyle & WS_EX_NOPARENTNOTIFY)) break;
73 lppt->x += wndPtr->rectClient.left;
74 lppt->y += wndPtr->rectClient.top;
75 wndPtr = wndPtr->parent;
76 SendMessage32A( wndPtr->hwndSelf, WM_PARENTNOTIFY,
77 MAKEWPARAM( event, idChild ), lValue );
79 #undef lppt
83 /***********************************************************************
84 * MSG_TranslateMouseMsg
86 * Translate an mouse hardware event into a real mouse message.
87 * Return value indicates whether the translated message must be passed
88 * to the user, left in the queue, or skipped entirely (in this case
89 * HIWORD contains hit test code).
91 static DWORD MSG_TranslateMouseMsg( HWND16 hTopWnd, DWORD filter,
92 MSG16 *msg, BOOL32 remove, WND* pWndScope )
94 static DWORD dblclk_time_limit = 0;
95 static UINT16 clk_message = 0;
96 static HWND16 clk_hwnd = 0;
97 static POINT16 clk_pos = { 0, 0 };
99 WND *pWnd;
100 HWND16 hWnd;
101 INT16 ht, hittest, sendSC = 0;
102 UINT16 message = msg->message;
103 POINT16 screen_pt, pt;
104 HANDLE16 hQ = GetFastQueue();
105 MESSAGEQUEUE *queue = (MESSAGEQUEUE *)GlobalLock16(hQ);
106 BOOL32 eatMsg = FALSE;
107 BOOL32 mouseClick = ((message == WM_LBUTTONDOWN) ||
108 (message == WM_RBUTTONDOWN) ||
109 (message == WM_MBUTTONDOWN))?1:0;
110 SYSQ_STATUS ret = 0;
112 /* Find the window */
114 ht = hittest = HTCLIENT;
115 hWnd = GetCapture16();
116 if( !hWnd )
118 ht = hittest = WINPOS_WindowFromPoint( pWndScope, msg->pt, &pWnd );
119 if( !pWnd ) pWnd = WIN_GetDesktop();
120 hWnd = pWnd->hwndSelf;
121 sendSC = 1;
123 else
125 pWnd = WIN_FindWndPtr(hWnd);
126 ht = EVENT_GetCaptureInfo();
129 /* stop if not the right queue */
131 if (pWnd->hmemTaskQ != hQ)
133 /* Not for the current task */
134 if (queue) QUEUE_ClearWakeBit( queue, QS_MOUSE );
135 /* Wake up the other task */
136 queue = (MESSAGEQUEUE *)GlobalLock16( pWnd->hmemTaskQ );
137 if (queue) QUEUE_SetWakeBit( queue, QS_MOUSE );
138 return SYSQ_MSG_ABANDON;
141 /* check if hWnd is within hWndScope */
143 if( hTopWnd && hWnd != hTopWnd )
144 if( !IsChild16(hTopWnd, hWnd) ) return SYSQ_MSG_CONTINUE;
146 if( mouseClick )
148 /* translate double clicks -
149 * note that ...MOUSEMOVEs can slip in between
150 * ...BUTTONDOWN and ...BUTTONDBLCLK messages */
152 if( pWnd->class->style & CS_DBLCLKS || ht != HTCLIENT )
154 if ((message == clk_message) && (hWnd == clk_hwnd) &&
155 (msg->time - dblclk_time_limit < doubleClickSpeed) &&
156 (abs(msg->pt.x - clk_pos.x) < SYSMETRICS_CXDOUBLECLK/2) &&
157 (abs(msg->pt.y - clk_pos.y) < SYSMETRICS_CYDOUBLECLK/2))
159 message += (WM_LBUTTONDBLCLK - WM_LBUTTONDOWN);
160 mouseClick++; /* == 2 */
164 screen_pt = pt = msg->pt;
166 if (hittest != HTCLIENT)
168 message += ((INT16)WM_NCMOUSEMOVE - WM_MOUSEMOVE);
169 msg->wParam = hittest;
171 else ScreenToClient16( hWnd, &pt );
173 /* check message filter */
175 if (!MSG_CheckFilter(message, filter)) return SYSQ_MSG_CONTINUE;
177 pCursorQueue = queue;
179 /* call WH_MOUSE */
181 if (HOOK_IsHooked( WH_MOUSE ))
183 MOUSEHOOKSTRUCT16 *hook = SEGPTR_NEW(MOUSEHOOKSTRUCT16);
184 if( hook )
186 hook->pt = screen_pt;
187 hook->hwnd = hWnd;
188 hook->wHitTestCode = hittest;
189 hook->dwExtraInfo = 0;
190 ret = HOOK_CallHooks16( WH_MOUSE, remove ? HC_ACTION : HC_NOREMOVE,
191 message, (LPARAM)SEGPTR_GET(hook) );
192 SEGPTR_FREE(hook);
194 if( ret ) return MAKELONG((INT16)SYSQ_MSG_SKIP, hittest);
197 if ((hittest == HTERROR) || (hittest == HTNOWHERE))
198 eatMsg = sendSC = 1;
199 else if( remove && mouseClick )
201 HWND32 hwndTop = WIN_GetTopParent( hWnd );
203 if( mouseClick == 1 )
205 /* set conditions */
206 dblclk_time_limit = msg->time;
207 clk_message = msg->message;
208 clk_hwnd = hWnd;
209 clk_pos = screen_pt;
210 } else
211 /* got double click - zero them out */
212 dblclk_time_limit = clk_hwnd = 0;
214 if( sendSC )
216 /* Send the WM_PARENTNOTIFY,
217 * note that even for double/nonclient clicks
218 * notification message is still WM_L/M/RBUTTONDOWN.
221 MSG_SendParentNotify( pWnd, msg->message, 0, MAKELPARAM(screen_pt.x, screen_pt.y) );
223 /* Activate the window if needed */
225 if (hWnd != GetActiveWindow16() && hWnd != GetDesktopWindow16())
227 LONG ret = SendMessage16( hWnd, WM_MOUSEACTIVATE, hwndTop,
228 MAKELONG( hittest, message ) );
230 if ((ret == MA_ACTIVATEANDEAT) || (ret == MA_NOACTIVATEANDEAT))
231 eatMsg = TRUE;
233 if (((ret == MA_ACTIVATE) || (ret == MA_ACTIVATEANDEAT))
234 && hwndTop != GetActiveWindow16() )
235 if (!WINPOS_SetActiveWindow( hwndTop, TRUE , TRUE ))
236 eatMsg = TRUE;
239 } else sendSC = (remove && sendSC);
241 /* Send the WM_SETCURSOR message */
243 if (sendSC)
244 SendMessage16( hWnd, WM_SETCURSOR, (WPARAM16)hWnd,
245 MAKELONG( hittest, message ));
246 if (eatMsg) return MAKELONG( (UINT16)SYSQ_MSG_SKIP, hittest);
248 msg->hwnd = hWnd;
249 msg->message = message;
250 msg->lParam = MAKELONG( pt.x, pt.y );
251 return SYSQ_MSG_ACCEPT;
255 /***********************************************************************
256 * MSG_TranslateKbdMsg
258 * Translate an keyboard hardware event into a real message.
260 static DWORD MSG_TranslateKbdMsg( HWND16 hTopWnd, DWORD filter,
261 MSG16 *msg, BOOL32 remove )
263 WORD message = msg->message;
264 HWND16 hWnd = GetFocus16();
265 WND *pWnd;
267 /* Should check Ctrl-Esc and PrintScreen here */
269 if (!hWnd)
271 /* Send the message to the active window instead, */
272 /* translating messages to their WM_SYS equivalent */
274 hWnd = GetActiveWindow16();
276 if( message < WM_SYSKEYDOWN )
277 message += WM_SYSKEYDOWN - WM_KEYDOWN;
279 pWnd = WIN_FindWndPtr( hWnd );
280 if (pWnd && (pWnd->hmemTaskQ != GetFastQueue()))
282 /* Not for the current task */
283 MESSAGEQUEUE *queue = (MESSAGEQUEUE *)GlobalLock16( GetFastQueue() );
284 if (queue) QUEUE_ClearWakeBit( queue, QS_KEY );
285 /* Wake up the other task */
286 queue = (MESSAGEQUEUE *)GlobalLock16( pWnd->hmemTaskQ );
287 if (queue) QUEUE_SetWakeBit( queue, QS_KEY );
288 return SYSQ_MSG_ABANDON;
291 if (hTopWnd && hWnd != hTopWnd)
292 if (!IsChild16(hTopWnd, hWnd)) return SYSQ_MSG_CONTINUE;
293 if (!MSG_CheckFilter(message, filter)) return SYSQ_MSG_CONTINUE;
295 msg->hwnd = hWnd;
296 msg->message = message;
298 return (HOOK_CallHooks16( WH_KEYBOARD, remove ? HC_ACTION : HC_NOREMOVE,
299 msg->wParam, msg->lParam )
300 ? SYSQ_MSG_SKIP : SYSQ_MSG_ACCEPT);
304 /***********************************************************************
305 * MSG_JournalRecordMsg
307 * Build an EVENTMSG structure and call JOURNALRECORD hook
309 static void MSG_JournalRecordMsg( MSG16 *msg )
311 EVENTMSG16 *event = SEGPTR_NEW(EVENTMSG16);
312 if (!event) return;
313 event->message = msg->message;
314 event->time = msg->time;
315 if ((msg->message >= WM_KEYFIRST) && (msg->message <= WM_KEYLAST))
317 event->paramL = (msg->wParam & 0xFF) | (HIWORD(msg->lParam) << 8);
318 event->paramH = msg->lParam & 0x7FFF;
319 if (HIWORD(msg->lParam) & 0x0100)
320 event->paramH |= 0x8000; /* special_key - bit */
321 HOOK_CallHooks16( WH_JOURNALRECORD, HC_ACTION, 0,
322 (LPARAM)SEGPTR_GET(event) );
324 else if ((msg->message >= WM_MOUSEFIRST) && (msg->message <= WM_MOUSELAST))
326 event->paramL = LOWORD(msg->lParam); /* X pos */
327 event->paramH = HIWORD(msg->lParam); /* Y pos */
328 ClientToScreen16( msg->hwnd, (LPPOINT16)&event->paramL );
329 HOOK_CallHooks16( WH_JOURNALRECORD, HC_ACTION, 0,
330 (LPARAM)SEGPTR_GET(event) );
332 else if ((msg->message >= WM_NCMOUSEFIRST) &&
333 (msg->message <= WM_NCMOUSELAST))
335 event->paramL = LOWORD(msg->lParam); /* X pos */
336 event->paramH = HIWORD(msg->lParam); /* Y pos */
337 event->message += WM_MOUSEMOVE-WM_NCMOUSEMOVE;/* give no info about NC area */
338 HOOK_CallHooks16( WH_JOURNALRECORD, HC_ACTION, 0,
339 (LPARAM)SEGPTR_GET(event) );
341 SEGPTR_FREE(event);
344 /***********************************************************************
345 * MSG_JournalPlayBackMsg
347 * Get an EVENTMSG struct via call JOURNALPLAYBACK hook function
349 static int MSG_JournalPlayBackMsg(void)
351 EVENTMSG16 *tmpMsg;
352 long wtime,lParam;
353 WORD keyDown,i,wParam,result=0;
355 if ( HOOK_IsHooked( WH_JOURNALPLAYBACK ) )
357 tmpMsg = SEGPTR_NEW(EVENTMSG16);
358 wtime=HOOK_CallHooks16( WH_JOURNALPLAYBACK, HC_GETNEXT, 0,
359 (LPARAM)SEGPTR_GET(tmpMsg));
360 /* TRACE(msg,"Playback wait time =%ld\n",wtime); */
361 if (wtime<=0)
363 wtime=0;
364 if ((tmpMsg->message>= WM_KEYFIRST) && (tmpMsg->message <= WM_KEYLAST))
366 wParam=tmpMsg->paramL & 0xFF;
367 lParam=MAKELONG(tmpMsg->paramH&0x7ffff,tmpMsg->paramL>>8);
368 if (tmpMsg->message == WM_KEYDOWN || tmpMsg->message == WM_SYSKEYDOWN)
370 for (keyDown=i=0; i<256 && !keyDown; i++)
371 if (InputKeyStateTable[i] & 0x80)
372 keyDown++;
373 if (!keyDown)
374 lParam |= 0x40000000;
375 AsyncKeyStateTable[wParam]=InputKeyStateTable[wParam] |= 0x80;
377 else /* WM_KEYUP, WM_SYSKEYUP */
379 lParam |= 0xC0000000;
380 AsyncKeyStateTable[wParam]=InputKeyStateTable[wParam] &= ~0x80;
382 if (InputKeyStateTable[VK_MENU] & 0x80)
383 lParam |= 0x20000000;
384 if (tmpMsg->paramH & 0x8000) /*special_key bit*/
385 lParam |= 0x01000000;
386 hardware_event( tmpMsg->message, wParam, lParam,0, 0, tmpMsg->time, 0 );
388 else
390 if ((tmpMsg->message>= WM_MOUSEFIRST) && (tmpMsg->message <= WM_MOUSELAST))
392 switch (tmpMsg->message)
394 case WM_LBUTTONDOWN:
395 MouseButtonsStates[0]=AsyncMouseButtonsStates[0]=TRUE;break;
396 case WM_LBUTTONUP:
397 MouseButtonsStates[0]=AsyncMouseButtonsStates[0]=FALSE;break;
398 case WM_MBUTTONDOWN:
399 MouseButtonsStates[1]=AsyncMouseButtonsStates[1]=TRUE;break;
400 case WM_MBUTTONUP:
401 MouseButtonsStates[1]=AsyncMouseButtonsStates[1]=FALSE;break;
402 case WM_RBUTTONDOWN:
403 MouseButtonsStates[2]=AsyncMouseButtonsStates[2]=TRUE;break;
404 case WM_RBUTTONUP:
405 MouseButtonsStates[2]=AsyncMouseButtonsStates[2]=FALSE;break;
407 AsyncKeyStateTable[VK_LBUTTON]= InputKeyStateTable[VK_LBUTTON] = MouseButtonsStates[0] ? 0x80 : 0;
408 AsyncKeyStateTable[VK_MBUTTON]= InputKeyStateTable[VK_MBUTTON] = MouseButtonsStates[1] ? 0x80 : 0;
409 AsyncKeyStateTable[VK_RBUTTON]= InputKeyStateTable[VK_RBUTTON] = MouseButtonsStates[2] ? 0x80 : 0;
410 SetCursorPos32(tmpMsg->paramL,tmpMsg->paramH);
411 lParam=MAKELONG(tmpMsg->paramL,tmpMsg->paramH);
412 wParam=0;
413 if (MouseButtonsStates[0]) wParam |= MK_LBUTTON;
414 if (MouseButtonsStates[1]) wParam |= MK_MBUTTON;
415 if (MouseButtonsStates[2]) wParam |= MK_RBUTTON;
416 hardware_event( tmpMsg->message, wParam, lParam,
417 tmpMsg->paramL, tmpMsg->paramH, tmpMsg->time, 0 );
420 HOOK_CallHooks16( WH_JOURNALPLAYBACK, HC_SKIP, 0,
421 (LPARAM)SEGPTR_GET(tmpMsg));
423 else
425 if( tmpMsg->message == WM_QUEUESYNC )
426 if (HOOK_IsHooked( WH_CBT ))
427 HOOK_CallHooks16( WH_CBT, HCBT_QS, 0, 0L);
429 result= QS_MOUSE | QS_KEY; /* ? */
431 SEGPTR_FREE(tmpMsg);
433 return result;
436 /***********************************************************************
437 * MSG_PeekHardwareMsg
439 * Peek for a hardware message matching the hwnd and message filters.
441 static BOOL32 MSG_PeekHardwareMsg( MSG16 *msg, HWND16 hwnd, DWORD filter,
442 BOOL32 remove )
444 DWORD status = SYSQ_MSG_ACCEPT;
445 MESSAGEQUEUE *sysMsgQueue = QUEUE_GetSysQueue();
446 int i, kbd_msg, pos = sysMsgQueue->nextMessage;
448 /* FIXME: there has to be a better way to do this */
449 joySendMessages();
451 /* If the queue is empty, attempt to fill it */
452 if (!sysMsgQueue->msgCount && THREAD_IsWin16( THREAD_Current() )
453 && EVENT_Pending())
454 EVENT_WaitNetEvent( FALSE, FALSE );
456 for (i = kbd_msg = 0; i < sysMsgQueue->msgCount; i++, pos++)
458 if (pos >= sysMsgQueue->queueSize) pos = 0;
459 *msg = sysMsgQueue->messages[pos].msg;
461 /* Translate message */
463 if ((msg->message >= WM_MOUSEFIRST) && (msg->message <= WM_MOUSELAST))
465 HWND32 hWndScope = (HWND32)sysMsgQueue->messages[pos].extraInfo;
467 status = MSG_TranslateMouseMsg(hwnd, filter, msg, remove,
468 (Options.managed && IsWindow32(hWndScope) )
469 ? WIN_FindWndPtr(hWndScope) : WIN_GetDesktop() );
470 kbd_msg = 0;
472 else if ((msg->message >= WM_KEYFIRST) && (msg->message <= WM_KEYLAST))
474 status = MSG_TranslateKbdMsg(hwnd, filter, msg, remove);
475 kbd_msg = 1;
477 else /* Non-standard hardware event */
479 HARDWAREHOOKSTRUCT16 *hook;
480 if ((hook = SEGPTR_NEW(HARDWAREHOOKSTRUCT16)))
482 BOOL32 ret;
483 hook->hWnd = msg->hwnd;
484 hook->wMessage = msg->message;
485 hook->wParam = msg->wParam;
486 hook->lParam = msg->lParam;
487 ret = HOOK_CallHooks16( WH_HARDWARE,
488 remove ? HC_ACTION : HC_NOREMOVE,
489 0, (LPARAM)SEGPTR_GET(hook) );
490 SEGPTR_FREE(hook);
491 if (ret)
493 QUEUE_RemoveMsg( sysMsgQueue, pos );
494 continue;
496 status = SYSQ_MSG_ACCEPT;
500 switch (LOWORD(status))
502 case SYSQ_MSG_ACCEPT:
503 break;
505 case SYSQ_MSG_SKIP:
506 if (HOOK_IsHooked( WH_CBT ))
508 if( kbd_msg )
509 HOOK_CallHooks16( WH_CBT, HCBT_KEYSKIPPED,
510 msg->wParam, msg->lParam );
511 else
513 MOUSEHOOKSTRUCT16 *hook = SEGPTR_NEW(MOUSEHOOKSTRUCT16);
514 if (hook)
516 hook->pt = msg->pt;
517 hook->hwnd = msg->hwnd;
518 hook->wHitTestCode = HIWORD(status);
519 hook->dwExtraInfo = 0;
520 HOOK_CallHooks16( WH_CBT, HCBT_CLICKSKIPPED ,msg->message,
521 (LPARAM)SEGPTR_GET(hook) );
522 SEGPTR_FREE(hook);
527 if (remove)
528 QUEUE_RemoveMsg( sysMsgQueue, pos );
529 /* continue */
531 case SYSQ_MSG_CONTINUE:
532 continue;
534 case SYSQ_MSG_ABANDON:
535 return FALSE;
538 if (remove)
540 if (HOOK_IsHooked( WH_JOURNALRECORD )) MSG_JournalRecordMsg( msg );
541 QUEUE_RemoveMsg( sysMsgQueue, pos );
543 return TRUE;
545 return FALSE;
549 /**********************************************************************
550 * SetDoubleClickTime16 (USER.20)
552 void WINAPI SetDoubleClickTime16( UINT16 interval )
554 SetDoubleClickTime32( interval );
558 /**********************************************************************
559 * SetDoubleClickTime32 (USER32.480)
561 BOOL32 WINAPI SetDoubleClickTime32( UINT32 interval )
563 doubleClickSpeed = interval ? interval : 500;
564 return TRUE;
568 /**********************************************************************
569 * GetDoubleClickTime16 (USER.21)
571 UINT16 WINAPI GetDoubleClickTime16(void)
573 return doubleClickSpeed;
577 /**********************************************************************
578 * GetDoubleClickTime32 (USER32.239)
580 UINT32 WINAPI GetDoubleClickTime32(void)
582 return doubleClickSpeed;
586 /***********************************************************************
587 * MSG_SendMessage
589 * Implementation of an inter-task SendMessage.
591 static LRESULT MSG_SendMessage( HQUEUE16 hDestQueue, HWND16 hwnd, UINT16 msg,
592 WPARAM32 wParam, LPARAM lParam, WORD flags )
594 INT32 prevSMRL = debugSMRL;
595 QSMCTRL qCtrl = { 0, 1};
596 MESSAGEQUEUE *queue, *destQ;
598 if (!(queue = (MESSAGEQUEUE*)GlobalLock16( GetFastQueue() ))) return 0;
599 if (!(destQ = (MESSAGEQUEUE*)GlobalLock16( hDestQueue ))) return 0;
601 if (IsTaskLocked() || !IsWindow32(hwnd)) return 0;
603 debugSMRL+=4;
604 TRACE(sendmsg,"%*sSM: %s [%04x] (%04x -> %04x)\n",
605 prevSMRL, "", SPY_GetMsgName(msg), msg, queue->self, hDestQueue );
607 if( !(queue->wakeBits & QS_SMPARAMSFREE) )
609 TRACE(sendmsg,"\tIntertask SendMessage: sleeping since unreplied SendMessage pending\n");
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 = GetFastQueue();
623 QUEUE_ClearWakeBit( queue, 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 if (THREAD_IsWin16( THREAD_Current() )) DirectedYield( destQ->hTask );
639 QUEUE_WaitBits( QS_SMRESULT );
640 TRACE(sendmsg,"\tsm: have result!\n");
642 /* got something */
644 TRACE(sendmsg,"%*ssm: smResult = %08x\n", prevSMRL, "", (unsigned)queue->smResult );
646 if (queue->smResult) { /* FIXME, smResult should always be set */
647 queue->smResult->lResult = queue->SendMessageReturn;
648 queue->smResult->bPending = FALSE;
650 QUEUE_ClearWakeBit( queue, QS_SMRESULT );
652 if( queue->smResult != &qCtrl )
653 ERR(sendmsg, "%*ssm: weird scenes inside the goldmine!\n", prevSMRL, "");
655 queue->smResultInit = NULL;
657 TRACE(sendmsg,"%*sSM: [%04x] returning %08lx\n", prevSMRL, "", msg, qCtrl.lResult);
658 debugSMRL-=4;
660 return qCtrl.lResult;
664 /***********************************************************************
665 * ReplyMessage16 (USER.115)
667 void WINAPI ReplyMessage16( LRESULT result )
669 MESSAGEQUEUE *senderQ;
670 MESSAGEQUEUE *queue;
672 if (!(queue = (MESSAGEQUEUE*)GlobalLock16( GetFastQueue() ))) return;
674 TRACE(msg,"ReplyMessage, queue %04x\n", queue->self);
676 while( (senderQ = (MESSAGEQUEUE*)GlobalLock16( queue->InSendMessageHandle)))
678 TRACE(msg,"\trpm: replying to %04x (%04x -> %04x)\n",
679 queue->msg, queue->self, senderQ->self);
681 if( queue->wakeBits & QS_SENDMESSAGE )
683 QUEUE_ReceiveMessage( queue );
684 continue; /* ReceiveMessage() already called us */
687 if(!(senderQ->wakeBits & QS_SMRESULT) ) break;
688 if (THREAD_IsWin16(THREAD_Current())) OldYield();
690 if( !senderQ ) { TRACE(msg,"\trpm: done\n"); return; }
692 senderQ->SendMessageReturn = result;
693 TRACE(msg,"\trpm: smResult = %08x, result = %08lx\n",
694 (unsigned)queue->smResultCurrent, result );
696 senderQ->smResult = queue->smResultCurrent;
697 queue->InSendMessageHandle = 0;
699 QUEUE_SetWakeBit( senderQ, QS_SMRESULT );
700 if (THREAD_IsWin16(THREAD_Current())) DirectedYield( senderQ->hTask );
704 /***********************************************************************
705 * MSG_PeekMessage
707 static BOOL32 MSG_PeekMessage( LPMSG16 msg, HWND16 hwnd, WORD first, WORD last,
708 WORD flags, BOOL32 peek )
710 int pos, mask;
711 MESSAGEQUEUE *msgQueue;
712 HQUEUE16 hQueue;
714 #ifdef CONFIG_IPC
715 DDE_TestDDE(hwnd); /* do we have dde handling in the window ?*/
716 DDE_GetRemoteMessage();
717 #endif /* CONFIG_IPC */
719 mask = QS_POSTMESSAGE | QS_SENDMESSAGE; /* Always selected */
720 if (first || last)
722 if ((first <= WM_KEYLAST) && (last >= WM_KEYFIRST)) mask |= QS_KEY;
723 if ( ((first <= WM_MOUSELAST) && (last >= WM_MOUSEFIRST)) ||
724 ((first <= WM_NCMOUSELAST) && (last >= WM_NCMOUSEFIRST)) ) mask |= QS_MOUSE;
725 if ((first <= WM_TIMER) && (last >= WM_TIMER)) mask |= QS_TIMER;
726 if ((first <= WM_SYSTIMER) && (last >= WM_SYSTIMER)) mask |= QS_TIMER;
727 if ((first <= WM_PAINT) && (last >= WM_PAINT)) mask |= QS_PAINT;
729 else mask |= QS_MOUSE | QS_KEY | QS_TIMER | QS_PAINT;
731 if (IsTaskLocked()) flags |= PM_NOYIELD;
733 /* Never yield on Win32 threads */
734 if (!THREAD_IsWin16(THREAD_Current())) flags |= PM_NOYIELD;
736 while(1)
738 hQueue = GetFastQueue();
739 msgQueue = (MESSAGEQUEUE *)GlobalLock16( hQueue );
740 if (!msgQueue) return FALSE;
741 msgQueue->changeBits = 0;
743 /* First handle a message put by SendMessage() */
745 while (msgQueue->wakeBits & QS_SENDMESSAGE)
746 QUEUE_ReceiveMessage( msgQueue );
748 /* Now handle a WM_QUIT message */
750 if (msgQueue->wPostQMsg &&
751 (!first || WM_QUIT >= first) &&
752 (!last || WM_QUIT <= last) )
754 msg->hwnd = hwnd;
755 msg->message = WM_QUIT;
756 msg->wParam = msgQueue->wExitCode;
757 msg->lParam = 0;
758 if (flags & PM_REMOVE) msgQueue->wPostQMsg = 0;
759 break;
762 /* Now find a normal message */
764 if (((msgQueue->wakeBits & mask) & QS_POSTMESSAGE) &&
765 ((pos = QUEUE_FindMsg( msgQueue, hwnd, first, last )) != -1))
767 QMSG *qmsg = &msgQueue->messages[pos];
768 *msg = qmsg->msg;
769 msgQueue->GetMessageTimeVal = msg->time;
770 msgQueue->GetMessagePosVal = *(DWORD *)&msg->pt;
771 msgQueue->GetMessageExtraInfoVal = qmsg->extraInfo;
773 if (flags & PM_REMOVE) QUEUE_RemoveMsg( msgQueue, pos );
774 break;
777 msgQueue->changeBits |= MSG_JournalPlayBackMsg();
779 /* Now find a hardware event */
781 if (((msgQueue->wakeBits & mask) & (QS_MOUSE | QS_KEY)) &&
782 MSG_PeekHardwareMsg( msg, hwnd, MAKELONG(first,last), flags & PM_REMOVE ))
784 /* Got one */
785 msgQueue->GetMessageTimeVal = msg->time;
786 msgQueue->GetMessagePosVal = *(DWORD *)&msg->pt;
787 msgQueue->GetMessageExtraInfoVal = 0; /* Always 0 for now */
788 break;
791 /* Check again for SendMessage */
793 while (msgQueue->wakeBits & QS_SENDMESSAGE)
794 QUEUE_ReceiveMessage( msgQueue );
796 /* Now find a WM_PAINT message */
798 if ((msgQueue->wakeBits & mask) & QS_PAINT)
800 WND* wndPtr;
801 msg->hwnd = WIN_FindWinToRepaint( hwnd , hQueue );
802 msg->message = WM_PAINT;
803 msg->wParam = 0;
804 msg->lParam = 0;
806 if ((wndPtr = WIN_FindWndPtr(msg->hwnd)))
808 if( wndPtr->dwStyle & WS_MINIMIZE &&
809 wndPtr->class->hIcon )
811 msg->message = WM_PAINTICON;
812 msg->wParam = 1;
815 if( !hwnd || msg->hwnd == hwnd || IsChild16(hwnd,msg->hwnd) )
817 if( wndPtr->flags & WIN_INTERNAL_PAINT && !wndPtr->hrgnUpdate)
819 wndPtr->flags &= ~WIN_INTERNAL_PAINT;
820 QUEUE_DecPaintCount( hQueue );
822 break;
827 /* Check for timer messages, but yield first */
829 if (!(flags & PM_NOYIELD))
831 UserYield();
832 while (msgQueue->wakeBits & QS_SENDMESSAGE)
833 QUEUE_ReceiveMessage( msgQueue );
835 if ((msgQueue->wakeBits & mask) & QS_TIMER)
837 if (TIMER_GetTimerMsg(msg, hwnd, hQueue, flags & PM_REMOVE)) break;
840 if (peek)
842 if (!(flags & PM_NOYIELD)) UserYield();
843 return FALSE;
845 msgQueue->wakeMask = mask;
846 QUEUE_WaitBits( mask );
849 /* We got a message */
850 if (flags & PM_REMOVE)
852 WORD message = msg->message;
854 if (message == WM_KEYDOWN || message == WM_SYSKEYDOWN)
856 BYTE *p = &QueueKeyStateTable[msg->wParam & 0xff];
858 if (!(*p & 0x80))
859 *p ^= 0x01;
860 *p |= 0x80;
862 else if (message == WM_KEYUP || message == WM_SYSKEYUP)
863 QueueKeyStateTable[msg->wParam & 0xff] &= ~0x80;
865 if (peek) return TRUE;
866 else return (msg->message != WM_QUIT);
870 /***********************************************************************
871 * MSG_InternalGetMessage
873 * GetMessage() function for internal use. Behave like GetMessage(),
874 * but also call message filters and optionally send WM_ENTERIDLE messages.
875 * 'hwnd' must be the handle of the dialog or menu window.
876 * 'code' is the message filter value (MSGF_??? codes).
878 BOOL32 MSG_InternalGetMessage( MSG16 *msg, HWND32 hwnd, HWND32 hwndOwner,
879 WPARAM32 code, WORD flags, BOOL32 sendIdle )
881 for (;;)
883 if (sendIdle)
885 if (!MSG_PeekMessage( msg, 0, 0, 0, flags, TRUE ))
887 /* No message present -> send ENTERIDLE and wait */
888 if (IsWindow32(hwndOwner))
889 SendMessage16( hwndOwner, WM_ENTERIDLE,
890 code, (LPARAM)hwnd );
891 MSG_PeekMessage( msg, 0, 0, 0, flags, FALSE );
894 else /* Always wait for a message */
895 MSG_PeekMessage( msg, 0, 0, 0, flags, FALSE );
897 /* Call message filters */
899 if (HOOK_IsHooked( WH_SYSMSGFILTER ) || HOOK_IsHooked( WH_MSGFILTER ))
901 MSG16 *pmsg = SEGPTR_NEW(MSG16);
902 if (pmsg)
904 BOOL32 ret;
905 *pmsg = *msg;
906 ret = ((BOOL16)HOOK_CallHooks16( WH_SYSMSGFILTER, code, 0,
907 (LPARAM)SEGPTR_GET(pmsg) ) ||
908 (BOOL16)HOOK_CallHooks16( WH_MSGFILTER, code, 0,
909 (LPARAM)SEGPTR_GET(pmsg) ));
910 SEGPTR_FREE(pmsg);
911 if (ret)
913 /* Message filtered -> remove it from the queue */
914 /* if it's still there. */
915 if (!(flags & PM_REMOVE))
916 MSG_PeekMessage( msg, 0, 0, 0, PM_REMOVE, TRUE );
917 continue;
922 return (msg->message != WM_QUIT);
927 /***********************************************************************
928 * PeekMessage16 (USER.109)
930 BOOL16 WINAPI PeekMessage16( LPMSG16 msg, HWND16 hwnd, UINT16 first,
931 UINT16 last, UINT16 flags )
933 return MSG_PeekMessage( msg, hwnd, first, last, flags, TRUE );
936 /***********************************************************************
937 * PeekMessageA
939 BOOL32 WINAPI PeekMessage32A( LPMSG32 lpmsg, HWND32 hwnd,
940 UINT32 min,UINT32 max,UINT32 wRemoveMsg)
942 MSG16 msg;
943 BOOL32 ret;
944 ret=PeekMessage16(&msg,hwnd,min,max,wRemoveMsg);
945 /* FIXME: should translate the message to Win32 */
946 STRUCT32_MSG16to32(&msg,lpmsg);
947 return ret;
950 /***********************************************************************
951 * PeekMessageW Check queue for messages
953 * Checks for a message in the thread's queue, filtered as for
954 * GetMessage(). Returns immediately whether a message is available
955 * or not.
957 * Whether a retrieved message is removed from the queue is set by the
958 * _wRemoveMsg_ flags, which should be one of the following values:
960 * PM_NOREMOVE Do not remove the message from the queue.
962 * PM_REMOVE Remove the message from the queue.
964 * In addition, PM_NOYIELD may be combined into _wRemoveMsg_ to
965 * request that the system not yield control during PeekMessage();
966 * however applications may not rely on scheduling behavior.
968 * RETURNS
970 * Nonzero if a message is available and is retrieved, zero otherwise.
972 * CONFORMANCE
974 * ECMA-234, Win32
977 BOOL32 WINAPI PeekMessage32W(
978 LPMSG32 lpmsg, /* buffer to receive message */
979 HWND32 hwnd, /* restrict to messages for hwnd */
980 UINT32 min, /* minimum message to receive */
981 UINT32 max, /* maximum message to receive */
982 UINT32 wRemoveMsg /* removal flags */
984 /* FIXME: Should perform Unicode translation on specific messages */
985 return PeekMessage32A(lpmsg,hwnd,min,max,wRemoveMsg);
988 /***********************************************************************
989 * GetMessage16 (USER.108)
991 BOOL16 WINAPI GetMessage16( SEGPTR msg, HWND16 hwnd, UINT16 first, UINT16 last)
993 MSG16 *lpmsg = (MSG16 *)PTR_SEG_TO_LIN(msg);
994 MSG_PeekMessage( lpmsg,
995 hwnd, first, last, PM_REMOVE, FALSE );
997 TRACE(msg,"message %04x, hwnd %04x, filter(%04x - %04x)\n", lpmsg->message,
998 hwnd, first, last );
999 HOOK_CallHooks16( WH_GETMESSAGE, HC_ACTION, 0, (LPARAM)msg );
1000 return (lpmsg->message != WM_QUIT);
1003 /***********************************************************************
1004 * GetMessage32A (USER32.270)
1006 BOOL32 WINAPI GetMessage32A(MSG32* lpmsg,HWND32 hwnd,UINT32 min,UINT32 max)
1008 BOOL32 ret;
1009 MSG16 *msg = SEGPTR_NEW(MSG16);
1010 if (!msg) return 0;
1011 ret=GetMessage16(SEGPTR_GET(msg),(HWND16)hwnd,min,max);
1012 /* FIXME */
1013 STRUCT32_MSG16to32(msg,lpmsg);
1014 SEGPTR_FREE(msg);
1015 return ret;
1018 /***********************************************************************
1019 * GetMessage32W (USER32.274) Retrieve next message
1021 * GetMessage retrieves the next event from the calling thread's
1022 * queue and deposits it in *lpmsg.
1024 * If _hwnd_ is not NULL, only messages for window _hwnd_ and its
1025 * children as specified by IsChild() are retrieved. If _hwnd_ is NULL
1026 * all application messages are retrieved.
1028 * _min_ and _max_ specify the range of messages of interest. If
1029 * min==max==0, no filtering is performed. Useful examples are
1030 * WM_KEYFIRST and WM_KEYLAST to retrieve keyboard input, and
1031 * WM_MOUSEFIRST and WM_MOUSELAST to retrieve mouse input.
1033 * WM_PAINT messages are not removed from the queue; they remain until
1034 * processed. Other messages are removed from the queue.
1036 * RETURNS
1038 * -1 on error, 0 if message is WM_QUIT, nonzero otherwise.
1040 * CONFORMANCE
1042 * ECMA-234, Win32
1045 BOOL32 WINAPI GetMessage32W(
1046 MSG32* lpmsg, /* buffer to receive message */
1047 HWND32 hwnd, /* restrict to messages for hwnd */
1048 UINT32 min, /* minimum message to receive */
1049 UINT32 max /* maximum message to receive */
1051 BOOL32 ret;
1052 MSG16 *msg = SEGPTR_NEW(MSG16);
1053 if (!msg) return 0;
1054 ret=GetMessage16(SEGPTR_GET(msg),(HWND16)hwnd,min,max);
1055 /* FIXME */
1056 STRUCT32_MSG16to32(msg,lpmsg);
1057 SEGPTR_FREE(msg);
1058 return ret;
1062 /***********************************************************************
1063 * PostMessage16 (USER.110)
1065 BOOL16 WINAPI PostMessage16( HWND16 hwnd, UINT16 message, WPARAM16 wParam,
1066 LPARAM lParam )
1068 MSG16 msg;
1069 WND *wndPtr;
1071 msg.hwnd = hwnd;
1072 msg.message = message;
1073 msg.wParam = wParam;
1074 msg.lParam = lParam;
1075 msg.time = GetTickCount();
1076 msg.pt.x = 0;
1077 msg.pt.y = 0;
1079 #ifdef CONFIG_IPC
1080 if (DDE_PostMessage(&msg))
1081 return TRUE;
1082 #endif /* CONFIG_IPC */
1084 if (hwnd == HWND_BROADCAST)
1086 TRACE(msg,"HWND_BROADCAST !\n");
1087 for (wndPtr = WIN_GetDesktop()->child; wndPtr; wndPtr = wndPtr->next)
1089 if (wndPtr->dwStyle & WS_POPUP || wndPtr->dwStyle & WS_CAPTION)
1091 TRACE(msg,"BROADCAST Message to hWnd=%04x m=%04X w=%04X l=%08lX !\n",
1092 wndPtr->hwndSelf, message, wParam, lParam);
1093 PostMessage16( wndPtr->hwndSelf, message, wParam, lParam );
1096 TRACE(msg,"End of HWND_BROADCAST !\n");
1097 return TRUE;
1100 wndPtr = WIN_FindWndPtr( hwnd );
1101 if (!wndPtr || !wndPtr->hmemTaskQ) return FALSE;
1103 return QUEUE_AddMsg( wndPtr->hmemTaskQ, &msg, 0 );
1107 /***********************************************************************
1108 * PostMessage32A (USER32.419)
1110 BOOL32 WINAPI PostMessage32A( HWND32 hwnd, UINT32 message, WPARAM32 wParam,
1111 LPARAM lParam )
1113 /* FIXME */
1114 if (message&0xffff0000)
1115 FIXME(msg,"message is truncated from %d to %d\n", message, message&0xffff);
1116 if (wParam&0xffff0000)
1117 FIXME(msg,"wParam is truncated from %d to %d\n", wParam, wParam&0xffff);
1118 return PostMessage16( hwnd, message, wParam, lParam );
1122 /***********************************************************************
1123 * PostMessage32W (USER32.420)
1125 BOOL32 WINAPI PostMessage32W( HWND32 hwnd, UINT32 message, WPARAM32 wParam,
1126 LPARAM lParam )
1128 /* FIXME */
1129 if (message&0xffff0000)
1130 FIXME(msg,"message is truncated from %d to %d\n", message, message&0xffff);
1131 if (wParam&0xffff0000)
1132 FIXME(msg,"wParam is truncated from %d to %d\n", wParam, wParam&0xffff);
1133 return PostMessage16( hwnd, message, wParam, lParam );
1137 /***********************************************************************
1138 * PostAppMessage16 (USER.116)
1140 BOOL16 WINAPI PostAppMessage16( HTASK16 hTask, UINT16 message, WPARAM16 wParam,
1141 LPARAM lParam )
1143 MSG16 msg;
1145 if (GetTaskQueue(hTask) == 0) return FALSE;
1146 msg.hwnd = 0;
1147 msg.message = message;
1148 msg.wParam = wParam;
1149 msg.lParam = lParam;
1150 msg.time = GetTickCount();
1151 msg.pt.x = 0;
1152 msg.pt.y = 0;
1154 return QUEUE_AddMsg( GetTaskQueue(hTask), &msg, 0 );
1158 /***********************************************************************
1159 * SendMessage16 (USER.111)
1161 LRESULT WINAPI SendMessage16( HWND16 hwnd, UINT16 msg, WPARAM16 wParam,
1162 LPARAM lParam)
1164 WND * wndPtr;
1165 WND **list, **ppWnd;
1166 LRESULT ret;
1168 #ifdef CONFIG_IPC
1169 MSG16 DDE_msg = { hwnd, msg, wParam, lParam };
1170 if (DDE_SendMessage(&DDE_msg)) return TRUE;
1171 #endif /* CONFIG_IPC */
1173 if (hwnd == HWND_BROADCAST)
1175 if (!(list = WIN_BuildWinArray( WIN_GetDesktop(), 0, NULL )))
1176 return TRUE;
1177 TRACE(msg,"HWND_BROADCAST !\n");
1178 for (ppWnd = list; *ppWnd; ppWnd++)
1180 wndPtr = *ppWnd;
1181 if (!IsWindow32(wndPtr->hwndSelf)) continue;
1182 if (wndPtr->dwStyle & WS_POPUP || wndPtr->dwStyle & WS_CAPTION)
1184 TRACE(msg,"BROADCAST Message to hWnd=%04x m=%04X w=%04lX l=%08lX !\n",
1185 wndPtr->hwndSelf, msg, (DWORD)wParam, lParam);
1186 SendMessage16( wndPtr->hwndSelf, msg, wParam, lParam );
1189 HeapFree( SystemHeap, 0, list );
1190 TRACE(msg,"End of HWND_BROADCAST !\n");
1191 return TRUE;
1194 if (HOOK_IsHooked( WH_CALLWNDPROC ))
1196 LPCWPSTRUCT16 pmsg;
1198 if ((pmsg = SEGPTR_NEW(CWPSTRUCT16)))
1200 pmsg->hwnd = hwnd;
1201 pmsg->message= msg;
1202 pmsg->wParam = wParam;
1203 pmsg->lParam = lParam;
1204 HOOK_CallHooks16( WH_CALLWNDPROC, HC_ACTION, 1,
1205 (LPARAM)SEGPTR_GET(pmsg) );
1206 hwnd = pmsg->hwnd;
1207 msg = pmsg->message;
1208 wParam = pmsg->wParam;
1209 lParam = pmsg->lParam;
1210 SEGPTR_FREE( pmsg );
1214 if (!(wndPtr = WIN_FindWndPtr( hwnd )))
1216 WARN(msg, "invalid hwnd %04x\n", hwnd );
1217 return 0;
1219 if (QUEUE_IsExitingQueue(wndPtr->hmemTaskQ))
1220 return 0; /* Don't send anything if the task is dying */
1222 SPY_EnterMessage( SPY_SENDMESSAGE16, hwnd, msg, wParam, lParam );
1224 if (wndPtr->hmemTaskQ != GetFastQueue())
1225 ret = MSG_SendMessage( wndPtr->hmemTaskQ, hwnd, msg,
1226 wParam, lParam, 0 );
1227 else
1228 ret = CallWindowProc16( (WNDPROC16)wndPtr->winproc,
1229 hwnd, msg, wParam, lParam );
1231 SPY_ExitMessage( SPY_RESULT_OK16, hwnd, msg, ret );
1232 return ret;
1235 /************************************************************************
1236 * MSG_CallWndProcHook32
1238 static void MSG_CallWndProcHook32( LPMSG32 pmsg, BOOL32 bUnicode )
1240 CWPSTRUCT32 cwp;
1242 cwp.lParam = pmsg->lParam;
1243 cwp.wParam = pmsg->wParam;
1244 cwp.message = pmsg->message;
1245 cwp.hwnd = pmsg->hwnd;
1247 if (bUnicode) HOOK_CallHooks32W(WH_CALLWNDPROC, HC_ACTION, 1, (LPARAM)&cwp);
1248 else HOOK_CallHooks32A( WH_CALLWNDPROC, HC_ACTION, 1, (LPARAM)&cwp );
1250 pmsg->lParam = cwp.lParam;
1251 pmsg->wParam = cwp.wParam;
1252 pmsg->message = cwp.message;
1253 pmsg->hwnd = cwp.hwnd;
1256 /**********************************************************************
1257 * PostThreadMessage32A (USER32.422)
1259 * BUGS
1261 * Thread-local message queues are not supported.
1264 BOOL32 WINAPI PostThreadMessage32A(DWORD idThread , UINT32 message,
1265 WPARAM32 wParam, LPARAM lParam )
1267 THDB *thdb = THREAD_ID_TO_THDB(idThread);
1268 if (!thdb || !thdb->process) return FALSE;
1270 FIXME(sendmsg, "(...): Should use thread-local message queue!\n");
1271 return PostAppMessage16(thdb->process->task, message, wParam, lParam);
1274 /**********************************************************************
1275 * PostThreadMessage32W (USER32.423)
1277 * BUGS
1279 * Thread-local message queues are not supported.
1282 BOOL32 WINAPI PostThreadMessage32W(DWORD idThread , UINT32 message,
1283 WPARAM32 wParam, LPARAM lParam )
1285 THDB *thdb = THREAD_ID_TO_THDB(idThread);
1286 if (!thdb || !thdb->process) return FALSE;
1288 FIXME(sendmsg, "(...): Should use thread-local message queue!\n");
1289 return PostAppMessage16(thdb->process->task, message, wParam, lParam);
1292 /***********************************************************************
1293 * SendMessage32A (USER32.454)
1295 LRESULT WINAPI SendMessage32A( HWND32 hwnd, UINT32 msg, WPARAM32 wParam,
1296 LPARAM lParam )
1298 WND * wndPtr;
1299 WND **list, **ppWnd;
1300 LRESULT ret;
1302 if (hwnd == HWND_BROADCAST || hwnd == HWND_TOPMOST)
1304 if (!(list = WIN_BuildWinArray( WIN_GetDesktop(), 0, NULL )))
1305 return TRUE;
1306 for (ppWnd = list; *ppWnd; ppWnd++)
1308 wndPtr = *ppWnd;
1309 if (!IsWindow32(wndPtr->hwndSelf)) continue;
1310 if (wndPtr->dwStyle & WS_POPUP || wndPtr->dwStyle & WS_CAPTION)
1311 SendMessage32A( wndPtr->hwndSelf, msg, wParam, lParam );
1313 HeapFree( SystemHeap, 0, list );
1314 return TRUE;
1317 if (HOOK_IsHooked( WH_CALLWNDPROC ))
1318 MSG_CallWndProcHook32( (LPMSG32)&hwnd, FALSE);
1320 if (!(wndPtr = WIN_FindWndPtr( hwnd )))
1322 WARN(msg, "invalid hwnd %08x\n", hwnd );
1323 return 0;
1326 if (QUEUE_IsExitingQueue(wndPtr->hmemTaskQ))
1327 return 0; /* Don't send anything if the task is dying */
1329 SPY_EnterMessage( SPY_SENDMESSAGE32, hwnd, msg, wParam, lParam );
1331 if (wndPtr->hmemTaskQ != GetFastQueue())
1332 ret = MSG_SendMessage( wndPtr->hmemTaskQ, hwnd, msg, wParam, lParam,
1333 QUEUE_SM_WIN32 );
1334 else
1335 ret = CallWindowProc32A( (WNDPROC32)wndPtr->winproc,
1336 hwnd, msg, wParam, lParam );
1338 SPY_ExitMessage( SPY_RESULT_OK32, hwnd, msg, ret );
1339 return ret;
1343 /***********************************************************************
1344 * SendMessage32W (USER32.459) Send Window Message
1346 * Sends a message to the window procedure of the specified window.
1347 * SendMessage() will not return until the called window procedure
1348 * either returns or calls ReplyMessage().
1350 * Use PostMessage() to send message and return immediately. A window
1351 * procedure may use InSendMessage() to detect
1352 * SendMessage()-originated messages.
1354 * Applications which communicate via HWND_BROADCAST may use
1355 * RegisterWindowMessage() to obtain a unique message to avoid conflicts
1356 * with other applications.
1358 * CONFORMANCE
1360 * ECMA-234, Win32
1362 LRESULT WINAPI SendMessage32W(
1363 HWND32 hwnd, /* Window to send message to. If HWND_BROADCAST,
1364 the message will be sent to all top-level windows. */
1366 UINT32 msg, /* message */
1367 WPARAM32 wParam, /* message parameter */
1368 LPARAM lParam /* additional message parameter */
1370 WND * wndPtr;
1371 WND **list, **ppWnd;
1372 LRESULT ret;
1374 if (hwnd == HWND_BROADCAST || hwnd == HWND_TOPMOST)
1376 if (!(list = WIN_BuildWinArray( WIN_GetDesktop(), 0, NULL )))
1377 return TRUE;
1378 for (ppWnd = list; *ppWnd; ppWnd++)
1380 wndPtr = *ppWnd;
1381 if (!IsWindow32(wndPtr->hwndSelf)) continue;
1382 if (wndPtr->dwStyle & WS_POPUP || wndPtr->dwStyle & WS_CAPTION)
1383 SendMessage32W( wndPtr->hwndSelf, msg, wParam, lParam );
1385 HeapFree( SystemHeap, 0, list );
1386 return TRUE;
1389 if (HOOK_IsHooked( WH_CALLWNDPROC ))
1390 MSG_CallWndProcHook32( (LPMSG32)&hwnd, TRUE);
1392 if (!(wndPtr = WIN_FindWndPtr( hwnd )))
1394 WARN(msg, "invalid hwnd %08x\n", hwnd );
1395 return 0;
1397 if (QUEUE_IsExitingQueue(wndPtr->hmemTaskQ))
1398 return 0; /* Don't send anything if the task is dying */
1400 SPY_EnterMessage( SPY_SENDMESSAGE32, hwnd, msg, wParam, lParam );
1402 if (wndPtr->hmemTaskQ != GetFastQueue())
1403 ret = MSG_SendMessage( wndPtr->hmemTaskQ, hwnd, msg, wParam, lParam,
1404 QUEUE_SM_WIN32 | QUEUE_SM_UNICODE );
1405 else
1406 ret = CallWindowProc32W( (WNDPROC32)wndPtr->winproc,
1407 hwnd, msg, wParam, lParam );
1409 SPY_ExitMessage( SPY_RESULT_OK32, hwnd, msg, ret );
1410 return ret;
1414 /***********************************************************************
1415 * SendMessageTimeout16 (not a WINAPI)
1417 LRESULT WINAPI SendMessageTimeout16( HWND16 hwnd, UINT16 msg, WPARAM16 wParam,
1418 LPARAM lParam, UINT16 flags,
1419 UINT16 timeout, LPWORD resultp)
1421 FIXME(sendmsg, "(...): semistub\n");
1422 return SendMessage16 (hwnd, msg, wParam, lParam);
1426 /***********************************************************************
1427 * SendMessageTimeout32A (USER32.457)
1429 LRESULT WINAPI SendMessageTimeout32A( HWND32 hwnd, UINT32 msg, WPARAM32 wParam,
1430 LPARAM lParam, UINT32 flags,
1431 UINT32 timeout, LPDWORD resultp)
1433 FIXME(sendmsg, "(...): semistub\n");
1434 return SendMessage32A (hwnd, msg, wParam, lParam);
1438 /***********************************************************************
1439 * SendMessageTimeout32W (USER32.458)
1441 LRESULT WINAPI SendMessageTimeout32W( HWND32 hwnd, UINT32 msg, WPARAM32 wParam,
1442 LPARAM lParam, UINT32 flags,
1443 UINT32 timeout, LPDWORD resultp)
1445 FIXME(sendmsg, "(...): semistub\n");
1446 return SendMessage32W (hwnd, msg, wParam, lParam);
1450 /***********************************************************************
1451 * WaitMessage (USER.112) (USER32.578) Suspend thread pending messages
1453 * WaitMessage() suspends a thread until events appear in the thread's
1454 * queue.
1456 * BUGS
1458 * Is supposed to return BOOL under Win32.
1460 * Thread-local message queues are not supported.
1462 * CONFORMANCE
1464 * ECMA-234, Win32
1467 void WINAPI WaitMessage( void )
1469 QUEUE_WaitBits( QS_ALLINPUT );
1472 /***********************************************************************
1473 * MsgWaitForMultipleObjects (USER32.400)
1475 DWORD WINAPI MsgWaitForMultipleObjects( DWORD nCount, HANDLE32 *pHandles,
1476 BOOL32 fWaitAll, DWORD dwMilliseconds,
1477 DWORD dwWakeMask )
1479 DWORD i;
1480 HANDLE32 handles[MAXIMUM_WAIT_OBJECTS];
1482 TDB *currTask = (TDB *)GlobalLock16( GetCurrentTask() );
1483 HQUEUE16 hQueue = currTask? currTask->hQueue : 0;
1484 MESSAGEQUEUE *msgQueue = (MESSAGEQUEUE *)GlobalLock16( hQueue );
1485 if (!msgQueue) return WAIT_FAILED;
1487 if (nCount > MAXIMUM_WAIT_OBJECTS-1)
1489 SetLastError( ERROR_INVALID_PARAMETER );
1490 return WAIT_FAILED;
1493 msgQueue->changeBits = 0;
1494 msgQueue->wakeMask = dwWakeMask;
1496 /* Add the thread event to the handle list */
1497 for (i = 0; i < nCount; i++) handles[i] = pHandles[i];
1498 handles[nCount] = currTask->thdb->event;
1499 return WaitForMultipleObjects( nCount+1, handles, fWaitAll, dwMilliseconds );
1504 struct accent_char
1506 BYTE ac_accent;
1507 BYTE ac_char;
1508 BYTE ac_result;
1511 static const struct accent_char accent_chars[] =
1513 /* A good idea should be to read /usr/X11/lib/X11/locale/iso8859-x/Compose */
1514 {'`', 'A', '\300'}, {'`', 'a', '\340'},
1515 {'\'', 'A', '\301'}, {'\'', 'a', '\341'},
1516 {'^', 'A', '\302'}, {'^', 'a', '\342'},
1517 {'~', 'A', '\303'}, {'~', 'a', '\343'},
1518 {'"', 'A', '\304'}, {'"', 'a', '\344'},
1519 {'O', 'A', '\305'}, {'o', 'a', '\345'},
1520 {'0', 'A', '\305'}, {'0', 'a', '\345'},
1521 {'A', 'A', '\305'}, {'a', 'a', '\345'},
1522 {'A', 'E', '\306'}, {'a', 'e', '\346'},
1523 {',', 'C', '\307'}, {',', 'c', '\347'},
1524 {'`', 'E', '\310'}, {'`', 'e', '\350'},
1525 {'\'', 'E', '\311'}, {'\'', 'e', '\351'},
1526 {'^', 'E', '\312'}, {'^', 'e', '\352'},
1527 {'"', 'E', '\313'}, {'"', 'e', '\353'},
1528 {'`', 'I', '\314'}, {'`', 'i', '\354'},
1529 {'\'', 'I', '\315'}, {'\'', 'i', '\355'},
1530 {'^', 'I', '\316'}, {'^', 'i', '\356'},
1531 {'"', 'I', '\317'}, {'"', 'i', '\357'},
1532 {'-', 'D', '\320'}, {'-', 'd', '\360'},
1533 {'~', 'N', '\321'}, {'~', 'n', '\361'},
1534 {'`', 'O', '\322'}, {'`', 'o', '\362'},
1535 {'\'', 'O', '\323'}, {'\'', 'o', '\363'},
1536 {'^', 'O', '\324'}, {'^', 'o', '\364'},
1537 {'~', 'O', '\325'}, {'~', 'o', '\365'},
1538 {'"', 'O', '\326'}, {'"', 'o', '\366'},
1539 {'/', 'O', '\330'}, {'/', 'o', '\370'},
1540 {'`', 'U', '\331'}, {'`', 'u', '\371'},
1541 {'\'', 'U', '\332'}, {'\'', 'u', '\372'},
1542 {'^', 'U', '\333'}, {'^', 'u', '\373'},
1543 {'"', 'U', '\334'}, {'"', 'u', '\374'},
1544 {'\'', 'Y', '\335'}, {'\'', 'y', '\375'},
1545 {'T', 'H', '\336'}, {'t', 'h', '\376'},
1546 {'s', 's', '\337'}, {'"', 'y', '\377'},
1547 {'s', 'z', '\337'}, {'i', 'j', '\377'},
1548 /* iso-8859-2 uses this */
1549 {'<', 'L', '\245'}, {'<', 'l', '\265'}, /* caron */
1550 {'<', 'S', '\251'}, {'<', 's', '\271'},
1551 {'<', 'T', '\253'}, {'<', 't', '\273'},
1552 {'<', 'Z', '\256'}, {'<', 'z', '\276'},
1553 {'<', 'C', '\310'}, {'<', 'c', '\350'},
1554 {'<', 'E', '\314'}, {'<', 'e', '\354'},
1555 {'<', 'D', '\317'}, {'<', 'd', '\357'},
1556 {'<', 'N', '\322'}, {'<', 'n', '\362'},
1557 {'<', 'R', '\330'}, {'<', 'r', '\370'},
1558 {';', 'A', '\241'}, {';', 'a', '\261'}, /* ogonek */
1559 {';', 'E', '\312'}, {';', 'e', '\332'},
1560 {'\'', 'Z', '\254'}, {'\'', 'z', '\274'}, /* acute */
1561 {'\'', 'R', '\300'}, {'\'', 'r', '\340'},
1562 {'\'', 'L', '\305'}, {'\'', 'l', '\345'},
1563 {'\'', 'C', '\306'}, {'\'', 'c', '\346'},
1564 {'\'', 'N', '\321'}, {'\'', 'n', '\361'},
1565 /* collision whith S, from iso-8859-9 !!! */
1566 {',', 'S', '\252'}, {',', 's', '\272'}, /* cedilla */
1567 {',', 'T', '\336'}, {',', 't', '\376'},
1568 {'.', 'Z', '\257'}, {'.', 'z', '\277'}, /* dot above */
1569 {'/', 'L', '\243'}, {'/', 'l', '\263'}, /* slash */
1570 {'/', 'D', '\320'}, {'/', 'd', '\360'},
1571 {'(', 'A', '\303'}, {'(', 'a', '\343'}, /* breve */
1572 {'\275', 'O', '\325'}, {'\275', 'o', '\365'}, /* double acute */
1573 {'\275', 'U', '\334'}, {'\275', 'u', '\374'},
1574 {'0', 'U', '\332'}, {'0', 'u', '\372'}, /* ring above */
1575 /* iso-8859-3 uses this */
1576 {'/', 'H', '\241'}, {'/', 'h', '\261'}, /* slash */
1577 {'>', 'H', '\246'}, {'>', 'h', '\266'}, /* circumflex */
1578 {'>', 'J', '\254'}, {'>', 'j', '\274'},
1579 {'>', 'C', '\306'}, {'>', 'c', '\346'},
1580 {'>', 'G', '\330'}, {'>', 'g', '\370'},
1581 {'>', 'S', '\336'}, {'>', 's', '\376'},
1582 /* collision whith G( from iso-8859-9 !!! */
1583 {'(', 'G', '\253'}, {'(', 'g', '\273'}, /* breve */
1584 {'(', 'U', '\335'}, {'(', 'u', '\375'},
1585 /* collision whith I. from iso-8859-3 !!! */
1586 {'.', 'I', '\251'}, {'.', 'i', '\271'}, /* dot above */
1587 {'.', 'C', '\305'}, {'.', 'c', '\345'},
1588 {'.', 'G', '\325'}, {'.', 'g', '\365'},
1589 /* iso-8859-4 uses this */
1590 {',', 'R', '\243'}, {',', 'r', '\263'}, /* cedilla */
1591 {',', 'L', '\246'}, {',', 'l', '\266'},
1592 {',', 'G', '\253'}, {',', 'g', '\273'},
1593 {',', 'N', '\321'}, {',', 'n', '\361'},
1594 {',', 'K', '\323'}, {',', 'k', '\363'},
1595 {'~', 'I', '\245'}, {'~', 'i', '\265'}, /* tilde */
1596 {'-', 'E', '\252'}, {'-', 'e', '\272'}, /* macron */
1597 {'-', 'A', '\300'}, {'-', 'a', '\340'},
1598 {'-', 'I', '\317'}, {'-', 'i', '\357'},
1599 {'-', 'O', '\322'}, {'-', 'o', '\362'},
1600 {'-', 'U', '\336'}, {'-', 'u', '\376'},
1601 {'/', 'T', '\254'}, {'/', 't', '\274'}, /* slash */
1602 {'.', 'E', '\314'}, {'.', 'e', '\344'}, /* dot above */
1603 {';', 'I', '\307'}, {';', 'i', '\347'}, /* ogonek */
1604 {';', 'U', '\331'}, {';', 'u', '\371'},
1605 /* iso-8859-9 uses this */
1606 /* iso-8859-9 has really bad choosen G( S, and I. as they collide
1607 * whith the same letters on other iso-8859-x (that is they are on
1608 * different places :-( ), if you use turkish uncomment these and
1609 * comment out the lines in iso-8859-2 and iso-8859-3 sections
1610 * FIXME: should be dynamic according to chosen language
1611 * if/when Wine has turkish support.
1613 /* collision whith G( from iso-8859-3 !!! */
1614 /* {'(', 'G', '\320'}, {'(', 'g', '\360'}, */ /* breve */
1615 /* collision whith S, from iso-8859-2 !!! */
1616 /* {',', 'S', '\336'}, {',', 's', '\376'}, */ /* cedilla */
1617 /* collision whith I. from iso-8859-3 !!! */
1618 /* {'.', 'I', '\335'}, {'.', 'i', '\375'}, */ /* dot above */
1622 /***********************************************************************
1623 * MSG_DoTranslateMessage
1625 * Implementation of TranslateMessage.
1627 * TranslateMessage translates virtual-key messages into character-messages,
1628 * as follows :
1629 * WM_KEYDOWN/WM_KEYUP combinations produce a WM_CHAR or WM_DEADCHAR message.
1630 * ditto replacing WM_* with WM_SYS*
1631 * This produces WM_CHAR messages only for keys mapped to ASCII characters
1632 * by the keyboard driver.
1634 static BOOL32 MSG_DoTranslateMessage( UINT32 message, HWND32 hwnd,
1635 WPARAM32 wParam, LPARAM lParam )
1637 static int dead_char;
1638 BYTE wp[2];
1640 if (message != WM_MOUSEMOVE && message != WM_TIMER)
1641 TRACE(msg, "(%s, %04X, %08lX)\n",
1642 SPY_GetMsgName(message), wParam, lParam );
1643 if(message >= WM_KEYFIRST && message <= WM_KEYLAST)
1644 TRACE(key, "(%s, %04X, %08lX)\n",
1645 SPY_GetMsgName(message), wParam, lParam );
1647 if ((message != WM_KEYDOWN) && (message != WM_SYSKEYDOWN)) return FALSE;
1649 TRACE(key, "Translating key %04X, scancode %04X\n",
1650 wParam, HIWORD(lParam) );
1652 /* FIXME : should handle ToAscii yielding 2 */
1653 switch (ToAscii32(wParam, HIWORD(lParam),
1654 QueueKeyStateTable,(LPWORD)wp, 0))
1656 case 1 :
1657 message = (message == WM_KEYDOWN) ? WM_CHAR : WM_SYSCHAR;
1658 /* Should dead chars handling go in ToAscii ? */
1659 if (dead_char)
1661 int i;
1663 if (wp[0] == ' ') wp[0] = dead_char;
1664 if (dead_char == 0xa2) dead_char = '(';
1665 else if (dead_char == 0xa8) dead_char = '"';
1666 else if (dead_char == 0xb2) dead_char = ';';
1667 else if (dead_char == 0xb4) dead_char = '\'';
1668 else if (dead_char == 0xb7) dead_char = '<';
1669 else if (dead_char == 0xb8) dead_char = ',';
1670 else if (dead_char == 0xff) dead_char = '.';
1671 for (i = 0; i < sizeof(accent_chars)/sizeof(accent_chars[0]); i++)
1672 if ((accent_chars[i].ac_accent == dead_char) &&
1673 (accent_chars[i].ac_char == wp[0]))
1675 wp[0] = accent_chars[i].ac_result;
1676 break;
1678 dead_char = 0;
1680 TRACE(key, "1 -> PostMessage(%s)\n", SPY_GetMsgName(message));
1681 PostMessage16( hwnd, message, wp[0], lParam );
1682 return TRUE;
1684 case -1 :
1685 message = (message == WM_KEYDOWN) ? WM_DEADCHAR : WM_SYSDEADCHAR;
1686 dead_char = wp[0];
1687 TRACE(key, "-1 -> PostMessage(%s)\n",
1688 SPY_GetMsgName(message));
1689 PostMessage16( hwnd, message, wp[0], lParam );
1690 return TRUE;
1692 return FALSE;
1696 /***********************************************************************
1697 * TranslateMessage16 (USER.113)
1699 BOOL16 WINAPI TranslateMessage16( const MSG16 *msg )
1701 return MSG_DoTranslateMessage( msg->message, msg->hwnd,
1702 msg->wParam, msg->lParam );
1706 /***********************************************************************
1707 * TranslateMessage32 (USER32.556)
1709 BOOL32 WINAPI TranslateMessage32( const MSG32 *msg )
1711 return MSG_DoTranslateMessage( msg->message, msg->hwnd,
1712 msg->wParam, msg->lParam );
1716 /***********************************************************************
1717 * DispatchMessage16 (USER.114)
1719 LONG WINAPI DispatchMessage16( const MSG16* msg )
1721 WND * wndPtr;
1722 LONG retval;
1723 int painting;
1725 /* Process timer messages */
1726 if ((msg->message == WM_TIMER) || (msg->message == WM_SYSTIMER))
1728 if (msg->lParam)
1730 return CallWindowProc16( (WNDPROC16)msg->lParam, msg->hwnd,
1731 msg->message, msg->wParam, GetTickCount() );
1735 if (!msg->hwnd) return 0;
1736 if (!(wndPtr = WIN_FindWndPtr( msg->hwnd ))) return 0;
1737 if (!wndPtr->winproc) return 0;
1738 painting = (msg->message == WM_PAINT);
1739 if (painting) wndPtr->flags |= WIN_NEEDS_BEGINPAINT;
1741 SPY_EnterMessage( SPY_DISPATCHMESSAGE16, msg->hwnd, msg->message,
1742 msg->wParam, msg->lParam );
1743 retval = CallWindowProc16( (WNDPROC16)wndPtr->winproc,
1744 msg->hwnd, msg->message,
1745 msg->wParam, msg->lParam );
1746 SPY_ExitMessage( SPY_RESULT_OK16, msg->hwnd, msg->message, retval );
1748 if (painting && (wndPtr = WIN_FindWndPtr( msg->hwnd )) &&
1749 (wndPtr->flags & WIN_NEEDS_BEGINPAINT) && wndPtr->hrgnUpdate)
1751 ERR(msg, "BeginPaint not called on WM_PAINT for hwnd %04x!\n",
1752 msg->hwnd);
1753 wndPtr->flags &= ~WIN_NEEDS_BEGINPAINT;
1754 /* Validate the update region to avoid infinite WM_PAINT loop */
1755 ValidateRect32( msg->hwnd, NULL );
1757 return retval;
1761 /***********************************************************************
1762 * DispatchMessage32A (USER32.141)
1764 LONG WINAPI DispatchMessage32A( const MSG32* msg )
1766 WND * wndPtr;
1767 LONG retval;
1768 int painting;
1770 /* Process timer messages */
1771 if ((msg->message == WM_TIMER) || (msg->message == WM_SYSTIMER))
1773 if (msg->lParam)
1775 /* HOOK_CallHooks32A( WH_CALLWNDPROC, HC_ACTION, 0, FIXME ); */
1776 return CallWindowProc32A( (WNDPROC32)msg->lParam, msg->hwnd,
1777 msg->message, msg->wParam, GetTickCount() );
1781 if (!msg->hwnd) return 0;
1782 if (!(wndPtr = WIN_FindWndPtr( msg->hwnd ))) return 0;
1783 if (!wndPtr->winproc) return 0;
1784 painting = (msg->message == WM_PAINT);
1785 if (painting) wndPtr->flags |= WIN_NEEDS_BEGINPAINT;
1786 /* HOOK_CallHooks32A( WH_CALLWNDPROC, HC_ACTION, 0, FIXME ); */
1788 SPY_EnterMessage( SPY_DISPATCHMESSAGE32, msg->hwnd, msg->message,
1789 msg->wParam, msg->lParam );
1790 retval = CallWindowProc32A( (WNDPROC32)wndPtr->winproc,
1791 msg->hwnd, msg->message,
1792 msg->wParam, msg->lParam );
1793 SPY_ExitMessage( SPY_RESULT_OK32, msg->hwnd, msg->message, retval );
1795 if (painting && (wndPtr = WIN_FindWndPtr( msg->hwnd )) &&
1796 (wndPtr->flags & WIN_NEEDS_BEGINPAINT) && wndPtr->hrgnUpdate)
1798 ERR(msg, "BeginPaint not called on WM_PAINT for hwnd %04x!\n",
1799 msg->hwnd);
1800 wndPtr->flags &= ~WIN_NEEDS_BEGINPAINT;
1801 /* Validate the update region to avoid infinite WM_PAINT loop */
1802 ValidateRect32( msg->hwnd, NULL );
1804 return retval;
1808 /***********************************************************************
1809 * DispatchMessage32W (USER32.142) Process Message
1811 * Process the message specified in the structure *_msg_.
1813 * If the lpMsg parameter points to a WM_TIMER message and the
1814 * parameter of the WM_TIMER message is not NULL, the lParam parameter
1815 * points to the function that is called instead of the window
1816 * procedure.
1818 * The message must be valid.
1820 * RETURNS
1822 * DispatchMessage() returns the result of the window procedure invoked.
1824 * CONFORMANCE
1826 * ECMA-234, Win32
1829 LONG WINAPI DispatchMessage32W( const MSG32* msg )
1831 WND * wndPtr;
1832 LONG retval;
1833 int painting;
1835 /* Process timer messages */
1836 if ((msg->message == WM_TIMER) || (msg->message == WM_SYSTIMER))
1838 if (msg->lParam)
1840 /* HOOK_CallHooks32W( WH_CALLWNDPROC, HC_ACTION, 0, FIXME ); */
1841 return CallWindowProc32W( (WNDPROC32)msg->lParam, msg->hwnd,
1842 msg->message, msg->wParam, GetTickCount() );
1846 if (!msg->hwnd) return 0;
1847 if (!(wndPtr = WIN_FindWndPtr( msg->hwnd ))) return 0;
1848 if (!wndPtr->winproc) return 0;
1849 painting = (msg->message == WM_PAINT);
1850 if (painting) wndPtr->flags |= WIN_NEEDS_BEGINPAINT;
1851 /* HOOK_CallHooks32W( WH_CALLWNDPROC, HC_ACTION, 0, FIXME ); */
1853 SPY_EnterMessage( SPY_DISPATCHMESSAGE32, msg->hwnd, msg->message,
1854 msg->wParam, msg->lParam );
1855 retval = CallWindowProc32W( (WNDPROC32)wndPtr->winproc,
1856 msg->hwnd, msg->message,
1857 msg->wParam, msg->lParam );
1858 SPY_ExitMessage( SPY_RESULT_OK32, msg->hwnd, msg->message, retval );
1860 if (painting && (wndPtr = WIN_FindWndPtr( msg->hwnd )) &&
1861 (wndPtr->flags & WIN_NEEDS_BEGINPAINT) && wndPtr->hrgnUpdate)
1863 ERR(msg, "BeginPaint not called on WM_PAINT for hwnd %04x!\n",
1864 msg->hwnd);
1865 wndPtr->flags &= ~WIN_NEEDS_BEGINPAINT;
1866 /* Validate the update region to avoid infinite WM_PAINT loop */
1867 ValidateRect32( msg->hwnd, NULL );
1869 return retval;
1873 /***********************************************************************
1874 * RegisterWindowMessage16 (USER.118)
1876 WORD WINAPI RegisterWindowMessage16( SEGPTR str )
1878 TRACE(msg, "%08lx\n", (DWORD)str );
1879 return GlobalAddAtom16( str );
1883 /***********************************************************************
1884 * RegisterWindowMessage32A (USER32.437)
1886 WORD WINAPI RegisterWindowMessage32A( LPCSTR str )
1888 TRACE(msg, "%s\n", str );
1889 return GlobalAddAtom32A( str );
1893 /***********************************************************************
1894 * RegisterWindowMessage32W (USER32.438)
1896 WORD WINAPI RegisterWindowMessage32W( LPCWSTR str )
1898 TRACE(msg, "%p\n", str );
1899 return GlobalAddAtom32W( str );
1903 /***********************************************************************
1904 * GetTickCount (USER.13) (KERNEL32.299) System Time
1905 * Returns the number of milliseconds, modulo 2^32, since the start
1906 * of the current session.
1908 * CONFORMANCE
1910 * ECMA-234, Win32
1912 DWORD WINAPI GetTickCount(void)
1914 struct timeval t;
1915 gettimeofday( &t, NULL );
1916 /* make extremely compatible: granularity is 25 msec */
1917 return ((t.tv_sec * 1000) + (t.tv_usec / 25000) * 25) - MSG_WineStartTicks;
1921 /***********************************************************************
1922 * GetCurrentTime16 (USER.15)
1924 * (effectively identical to GetTickCount)
1926 DWORD WINAPI GetCurrentTime16(void)
1928 return GetTickCount();
1932 /***********************************************************************
1933 * InSendMessage16 (USER.192)
1935 BOOL16 WINAPI InSendMessage16(void)
1937 return InSendMessage32();
1941 /***********************************************************************
1942 * InSendMessage32 (USER32.320)
1944 BOOL32 WINAPI InSendMessage32(void)
1946 MESSAGEQUEUE *queue;
1948 if (!(queue = (MESSAGEQUEUE *)GlobalLock16( GetFastQueue() )))
1949 return 0;
1950 return (BOOL32)queue->InSendMessageHandle;
1953 /***********************************************************************
1954 * BroadcastSystemMessage (USER32.12)
1956 LONG WINAPI BroadcastSystemMessage(
1957 DWORD dwFlags,LPDWORD recipients,UINT32 uMessage,WPARAM32 wParam,
1958 LPARAM lParam
1960 FIXME(sendmsg,"(%08lx,%08lx,%08x,%08x,%08lx): stub!\n",
1961 dwFlags,*recipients,uMessage,wParam,lParam
1963 return 0;
1966 /***********************************************************************
1967 * SendNotifyMessageA (USER32.460)
1968 * FIXME
1969 * The message sended with PostMessage has to be put in the queue
1970 * with a higher priority as the other "Posted" messages.
1971 * QUEUE_AddMsg has to be modifyed.
1973 BOOL32 WINAPI SendNotifyMessage32A(HWND32 hwnd,UINT32 msg,WPARAM32 wParam,LPARAM lParam)
1974 { BOOL32 ret = TRUE;
1975 FIXME(msg,"(%04x,%08x,%08x,%08lx) not complete\n",
1976 hwnd, msg, wParam, lParam);
1978 if ( GetCurrentThreadId() == GetWindowThreadProcessId ( hwnd, NULL))
1979 { ret=SendMessage32A ( hwnd, msg, wParam, lParam );
1981 else
1982 { PostMessage32A ( hwnd, msg, wParam, lParam );
1984 return ret;
1987 /***********************************************************************
1988 * SendNotifyMessageW (USER32.461)
1989 * FIXME
1990 * The message sended with PostMessage has to be put in the queue
1991 * with a higher priority as the other "Posted" messages.
1992 * QUEUE_AddMsg has to be modifyed.
1994 BOOL32 WINAPI SendNotifyMessage32W(HWND32 hwnd,UINT32 msg,WPARAM32 wParam,LPARAM lParam)
1995 { BOOL32 ret = TRUE;
1996 FIXME(msg,"(%04x,%08x,%08x,%08lx) not complete\n",
1997 hwnd, msg, wParam, lParam);
1999 if ( GetCurrentThreadId() == GetWindowThreadProcessId ( hwnd, NULL))
2000 { ret=SendMessage32W ( hwnd, msg, wParam, lParam );
2002 else
2003 { PostMessage32W ( hwnd, msg, wParam, lParam );
2005 return ret;
2008 /***********************************************************************
2009 * SendMessageCallBack32A
2010 * FIXME: It's like PostMessage. The callback gets called when the message
2011 * is processed. We have to modify the message processing for a exact
2012 * implementation...
2014 BOOL32 WINAPI SendMessageCallBack32A(
2015 HWND32 hWnd,UINT32 Msg,WPARAM32 wParam,LPARAM lParam,
2016 FARPROC32 lpResultCallBack,DWORD dwData)
2018 FIXME(msg,"(0x%04x,0x%04x,0x%08x,0x%08lx,%p,0x%08lx),stub!\n",
2019 hWnd,Msg,wParam,lParam,lpResultCallBack,dwData);
2020 if ( hWnd == HWND_BROADCAST)
2021 { PostMessage32A( hWnd, Msg, wParam, lParam);
2022 FIXME(msg,"Broadcast: Callback will not be called!\n");
2023 return TRUE;
2025 (lpResultCallBack)( hWnd, Msg, dwData, SendMessage32A ( hWnd, Msg, wParam, lParam ));
2026 return TRUE;