Added stubs for Process32First/Process32Next.
[wine/multimedia.git] / windows / message.c
blob06c78197231febaa4abdd55dd9243f4b723f08b9
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 "keyboard.h"
20 #include "spy.h"
21 #include "winpos.h"
22 #include "atom.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 = GetTaskQueue(0);
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 != GetTaskQueue(0)))
282 /* Not for the current task */
283 MESSAGEQUEUE *queue = (MESSAGEQUEUE *)GlobalLock16( GetTaskQueue(0) );
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 && TSXPending(display))
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 ))
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);
525 if (remove)
526 QUEUE_RemoveMsg( sysMsgQueue, pos );
527 /* continue */
529 case SYSQ_MSG_CONTINUE:
530 continue;
532 case SYSQ_MSG_ABANDON:
533 return FALSE;
536 if (remove)
538 if (HOOK_IsHooked( WH_JOURNALRECORD )) MSG_JournalRecordMsg( msg );
539 QUEUE_RemoveMsg( sysMsgQueue, pos );
541 return TRUE;
543 return FALSE;
547 /**********************************************************************
548 * SetDoubleClickTime16 (USER.20)
550 void WINAPI SetDoubleClickTime16( UINT16 interval )
552 SetDoubleClickTime32( interval );
556 /**********************************************************************
557 * SetDoubleClickTime32 (USER32.480)
559 BOOL32 WINAPI SetDoubleClickTime32( UINT32 interval )
561 doubleClickSpeed = interval ? interval : 500;
562 return TRUE;
566 /**********************************************************************
567 * GetDoubleClickTime16 (USER.21)
569 UINT16 WINAPI GetDoubleClickTime16(void)
571 return doubleClickSpeed;
575 /**********************************************************************
576 * GetDoubleClickTime32 (USER32.239)
578 UINT32 WINAPI GetDoubleClickTime32(void)
580 return doubleClickSpeed;
584 /***********************************************************************
585 * MSG_SendMessage
587 * Implementation of an inter-task SendMessage.
589 static LRESULT MSG_SendMessage( HQUEUE16 hDestQueue, HWND16 hwnd, UINT16 msg,
590 WPARAM32 wParam, LPARAM lParam, WORD flags )
592 INT32 prevSMRL = debugSMRL;
593 QSMCTRL qCtrl = { 0, 1};
594 MESSAGEQUEUE *queue, *destQ;
596 if (!(queue = (MESSAGEQUEUE*)GlobalLock16( GetTaskQueue(0) ))) return 0;
597 if (!(destQ = (MESSAGEQUEUE*)GlobalLock16( hDestQueue ))) return 0;
599 if (IsTaskLocked() || !IsWindow32(hwnd)) return 0;
601 debugSMRL+=4;
602 TRACE(sendmsg,"%*sSM: %s [%04x] (%04x -> %04x)\n",
603 prevSMRL, "", SPY_GetMsgName(msg), msg, queue->self, hDestQueue );
605 if( !(queue->wakeBits & QS_SMPARAMSFREE) )
607 TRACE(sendmsg,"\tIntertask SendMessage: sleeping since unreplied SendMessage pending\n");
608 queue->changeBits &= ~QS_SMPARAMSFREE;
609 QUEUE_WaitBits( QS_SMPARAMSFREE );
612 /* resume sending */
614 queue->hWnd = hwnd;
615 queue->msg = msg;
616 queue->wParam = LOWORD(wParam);
617 queue->wParamHigh = HIWORD(wParam);
618 queue->lParam = lParam;
619 queue->hPrevSendingTask = destQ->hSendingTask;
620 destQ->hSendingTask = GetTaskQueue(0);
622 queue->wakeBits &= ~QS_SMPARAMSFREE;
623 queue->flags = (queue->flags & ~(QUEUE_SM_WIN32|QUEUE_SM_UNICODE)) | flags;
625 TRACE(sendmsg,"%*ssm: smResultInit = %08x\n", prevSMRL, "", (unsigned)&qCtrl);
627 queue->smResultInit = &qCtrl;
629 QUEUE_SetWakeBit( destQ, QS_SENDMESSAGE );
631 /* perform task switch and wait for the result */
633 while( qCtrl.bPending )
635 if (!(queue->wakeBits & QS_SMRESULT))
637 queue->changeBits &= ~QS_SMRESULT;
638 if (THREAD_IsWin16( THREAD_Current() ))
639 DirectedYield( destQ->hTask );
640 else
641 QUEUE_Signal( destQ->hTask );
642 QUEUE_WaitBits( QS_SMRESULT );
643 TRACE(sendmsg,"\tsm: have result!\n");
645 /* got something */
647 TRACE(sendmsg,"%*ssm: smResult = %08x\n", prevSMRL, "", (unsigned)queue->smResult );
649 if (queue->smResult) { /* FIXME, smResult should always be set */
650 queue->smResult->lResult = queue->SendMessageReturn;
651 queue->smResult->bPending = FALSE;
653 queue->wakeBits &= ~QS_SMRESULT;
655 if( queue->smResult != &qCtrl )
656 ERR(sendmsg, "%*ssm: weird scenes inside the goldmine!\n", prevSMRL, "");
658 queue->smResultInit = NULL;
660 TRACE(sendmsg,"%*sSM: [%04x] returning %08lx\n", prevSMRL, "", msg, qCtrl.lResult);
661 debugSMRL-=4;
663 return qCtrl.lResult;
667 /***********************************************************************
668 * ReplyMessage16 (USER.115)
670 void WINAPI ReplyMessage16( LRESULT result )
672 MESSAGEQUEUE *senderQ;
673 MESSAGEQUEUE *queue;
675 if (!(queue = (MESSAGEQUEUE*)GlobalLock16( GetTaskQueue(0) ))) return;
677 TRACE(msg,"ReplyMessage, queue %04x\n", queue->self);
679 while( (senderQ = (MESSAGEQUEUE*)GlobalLock16( queue->InSendMessageHandle)))
681 TRACE(msg,"\trpm: replying to %04x (%04x -> %04x)\n",
682 queue->msg, queue->self, senderQ->self);
684 if( queue->wakeBits & QS_SENDMESSAGE )
686 QUEUE_ReceiveMessage( queue );
687 continue; /* ReceiveMessage() already called us */
690 if(!(senderQ->wakeBits & QS_SMRESULT) ) break;
691 if (THREAD_IsWin16(THREAD_Current())) OldYield();
693 if( !senderQ ) { TRACE(msg,"\trpm: done\n"); return; }
695 senderQ->SendMessageReturn = result;
696 TRACE(msg,"\trpm: smResult = %08x, result = %08lx\n",
697 (unsigned)queue->smResultCurrent, result );
699 senderQ->smResult = queue->smResultCurrent;
700 queue->InSendMessageHandle = 0;
702 QUEUE_SetWakeBit( senderQ, QS_SMRESULT );
703 if (THREAD_IsWin16(THREAD_Current())) DirectedYield( queue->hSendingTask );
707 /***********************************************************************
708 * MSG_PeekMessage
710 static BOOL32 MSG_PeekMessage( LPMSG16 msg, HWND16 hwnd, WORD first, WORD last,
711 WORD flags, BOOL32 peek )
713 int pos, mask;
714 MESSAGEQUEUE *msgQueue;
715 HQUEUE16 hQueue;
717 #ifdef CONFIG_IPC
718 DDE_TestDDE(hwnd); /* do we have dde handling in the window ?*/
719 DDE_GetRemoteMessage();
720 #endif /* CONFIG_IPC */
722 mask = QS_POSTMESSAGE | QS_SENDMESSAGE; /* Always selected */
723 if (first || last)
725 if ((first <= WM_KEYLAST) && (last >= WM_KEYFIRST)) mask |= QS_KEY;
726 if ( ((first <= WM_MOUSELAST) && (last >= WM_MOUSEFIRST)) ||
727 ((first <= WM_NCMOUSELAST) && (last >= WM_NCMOUSEFIRST)) ) mask |= QS_MOUSE;
728 if ((first <= WM_TIMER) && (last >= WM_TIMER)) mask |= QS_TIMER;
729 if ((first <= WM_SYSTIMER) && (last >= WM_SYSTIMER)) mask |= QS_TIMER;
730 if ((first <= WM_PAINT) && (last >= WM_PAINT)) mask |= QS_PAINT;
732 else mask |= QS_MOUSE | QS_KEY | QS_TIMER | QS_PAINT;
734 if (IsTaskLocked()) flags |= PM_NOYIELD;
736 /* Never yield on Win32 threads */
737 if (!THREAD_IsWin16(THREAD_Current())) flags |= PM_NOYIELD;
739 while(1)
741 hQueue = GetTaskQueue(0);
742 msgQueue = (MESSAGEQUEUE *)GlobalLock16( hQueue );
743 if (!msgQueue) return FALSE;
744 msgQueue->changeBits = 0;
746 /* First handle a message put by SendMessage() */
748 while (msgQueue->wakeBits & QS_SENDMESSAGE)
749 QUEUE_ReceiveMessage( msgQueue );
751 /* Now handle a WM_QUIT message */
753 if (msgQueue->wPostQMsg &&
754 (!first || WM_QUIT >= first) &&
755 (!last || WM_QUIT <= last) )
757 msg->hwnd = hwnd;
758 msg->message = WM_QUIT;
759 msg->wParam = msgQueue->wExitCode;
760 msg->lParam = 0;
761 if (flags & PM_REMOVE) msgQueue->wPostQMsg = 0;
762 break;
765 /* Now find a normal message */
767 if (((msgQueue->wakeBits & mask) & QS_POSTMESSAGE) &&
768 ((pos = QUEUE_FindMsg( msgQueue, hwnd, first, last )) != -1))
770 QMSG *qmsg = &msgQueue->messages[pos];
771 *msg = qmsg->msg;
772 msgQueue->GetMessageTimeVal = msg->time;
773 msgQueue->GetMessagePosVal = *(DWORD *)&msg->pt;
774 msgQueue->GetMessageExtraInfoVal = qmsg->extraInfo;
776 if (flags & PM_REMOVE) QUEUE_RemoveMsg( msgQueue, pos );
777 break;
780 msgQueue->changeBits |= MSG_JournalPlayBackMsg();
782 /* Now find a hardware event */
784 if (((msgQueue->wakeBits & mask) & (QS_MOUSE | QS_KEY)) &&
785 MSG_PeekHardwareMsg( msg, hwnd, MAKELONG(first,last), flags & PM_REMOVE ))
787 /* Got one */
788 msgQueue->GetMessageTimeVal = msg->time;
789 msgQueue->GetMessagePosVal = *(DWORD *)&msg->pt;
790 msgQueue->GetMessageExtraInfoVal = 0; /* Always 0 for now */
791 break;
794 /* Check again for SendMessage */
796 while (msgQueue->wakeBits & QS_SENDMESSAGE)
797 QUEUE_ReceiveMessage( msgQueue );
799 /* Now find a WM_PAINT message */
801 if ((msgQueue->wakeBits & mask) & QS_PAINT)
803 WND* wndPtr;
804 msg->hwnd = WIN_FindWinToRepaint( hwnd , hQueue );
805 msg->message = WM_PAINT;
806 msg->wParam = 0;
807 msg->lParam = 0;
809 if ((wndPtr = WIN_FindWndPtr(msg->hwnd)))
811 if( wndPtr->dwStyle & WS_MINIMIZE &&
812 wndPtr->class->hIcon )
814 msg->message = WM_PAINTICON;
815 msg->wParam = 1;
818 if( !hwnd || msg->hwnd == hwnd || IsChild16(hwnd,msg->hwnd) )
820 if( wndPtr->flags & WIN_INTERNAL_PAINT && !wndPtr->hrgnUpdate)
822 wndPtr->flags &= ~WIN_INTERNAL_PAINT;
823 QUEUE_DecPaintCount( hQueue );
825 break;
830 /* Check for timer messages, but yield first */
832 if (!(flags & PM_NOYIELD))
834 UserYield();
835 while (msgQueue->wakeBits & QS_SENDMESSAGE)
836 QUEUE_ReceiveMessage( msgQueue );
838 if ((msgQueue->wakeBits & mask) & QS_TIMER)
840 if (TIMER_GetTimerMsg(msg, hwnd, hQueue, flags & PM_REMOVE)) break;
843 if (peek)
845 if (!(flags & PM_NOYIELD)) UserYield();
846 return FALSE;
848 msgQueue->wakeMask = mask;
849 QUEUE_WaitBits( mask );
852 /* We got a message */
853 if (flags & PM_REMOVE)
855 WORD message = msg->message;
857 if (message == WM_KEYDOWN || message == WM_SYSKEYDOWN)
859 BYTE *p = &QueueKeyStateTable[msg->wParam & 0xff];
861 if (!(*p & 0x80))
862 *p ^= 0x01;
863 *p |= 0x80;
865 else if (message == WM_KEYUP || message == WM_SYSKEYUP)
866 QueueKeyStateTable[msg->wParam & 0xff] &= ~0x80;
868 if (peek) return TRUE;
869 else return (msg->message != WM_QUIT);
873 /***********************************************************************
874 * MSG_InternalGetMessage
876 * GetMessage() function for internal use. Behave like GetMessage(),
877 * but also call message filters and optionally send WM_ENTERIDLE messages.
878 * 'hwnd' must be the handle of the dialog or menu window.
879 * 'code' is the message filter value (MSGF_??? codes).
881 BOOL32 MSG_InternalGetMessage( MSG16 *msg, HWND32 hwnd, HWND32 hwndOwner,
882 WPARAM32 code, WORD flags, BOOL32 sendIdle )
884 for (;;)
886 if (sendIdle)
888 if (!MSG_PeekMessage( msg, 0, 0, 0, flags, TRUE ))
890 /* No message present -> send ENTERIDLE and wait */
891 if (IsWindow32(hwndOwner))
892 SendMessage16( hwndOwner, WM_ENTERIDLE,
893 code, (LPARAM)hwnd );
894 MSG_PeekMessage( msg, 0, 0, 0, flags, FALSE );
897 else /* Always wait for a message */
898 MSG_PeekMessage( msg, 0, 0, 0, flags, FALSE );
900 /* Call message filters */
902 if (HOOK_IsHooked( WH_SYSMSGFILTER ) || HOOK_IsHooked( WH_MSGFILTER ))
904 MSG16 *pmsg = SEGPTR_NEW(MSG16);
905 if (pmsg)
907 BOOL32 ret;
908 *pmsg = *msg;
909 ret = ((BOOL16)HOOK_CallHooks16( WH_SYSMSGFILTER, code, 0,
910 (LPARAM)SEGPTR_GET(pmsg) ) ||
911 (BOOL16)HOOK_CallHooks16( WH_MSGFILTER, code, 0,
912 (LPARAM)SEGPTR_GET(pmsg) ));
913 SEGPTR_FREE(pmsg);
914 if (ret)
916 /* Message filtered -> remove it from the queue */
917 /* if it's still there. */
918 if (!(flags & PM_REMOVE))
919 MSG_PeekMessage( msg, 0, 0, 0, PM_REMOVE, TRUE );
920 continue;
925 return (msg->message != WM_QUIT);
930 /***********************************************************************
931 * PeekMessage16 (USER.109)
933 BOOL16 WINAPI PeekMessage16( LPMSG16 msg, HWND16 hwnd, UINT16 first,
934 UINT16 last, UINT16 flags )
936 return MSG_PeekMessage( msg, hwnd, first, last, flags, TRUE );
939 /***********************************************************************
940 * PeekMessageA
942 BOOL32 WINAPI PeekMessage32A( LPMSG32 lpmsg, HWND32 hwnd,
943 UINT32 min,UINT32 max,UINT32 wRemoveMsg)
945 MSG16 msg;
946 BOOL32 ret;
947 ret=PeekMessage16(&msg,hwnd,min,max,wRemoveMsg);
948 /* FIXME: should translate the message to Win32 */
949 STRUCT32_MSG16to32(&msg,lpmsg);
950 return ret;
953 /***********************************************************************
954 * PeekMessageW Check queue for messages
956 * Checks for a message in the thread's queue, filtered as for
957 * GetMessage(). Returns immediately whether a message is available
958 * or not.
960 * Whether a retrieved message is removed from the queue is set by the
961 * _wRemoveMsg_ flags, which should be one of the following values:
963 * PM_NOREMOVE Do not remove the message from the queue.
965 * PM_REMOVE Remove the message from the queue.
967 * In addition, PM_NOYIELD may be combined into _wRemoveMsg_ to
968 * request that the system not yield control during PeekMessage();
969 * however applications may not rely on scheduling behavior.
971 * RETURNS
973 * Nonzero if a message is available and is retrieved, zero otherwise.
975 * CONFORMANCE
977 * ECMA-234, Win32
980 BOOL32 WINAPI PeekMessage32W(
981 LPMSG32 lpmsg, /* buffer to receive message */
982 HWND32 hwnd, /* restrict to messages for hwnd */
983 UINT32 min, /* minimum message to receive */
984 UINT32 max, /* maximum message to receive */
985 UINT32 wRemoveMsg /* removal flags */
987 /* FIXME: Should perform Unicode translation on specific messages */
988 return PeekMessage32A(lpmsg,hwnd,min,max,wRemoveMsg);
991 /***********************************************************************
992 * GetMessage16 (USER.108)
994 BOOL16 WINAPI GetMessage16( SEGPTR msg, HWND16 hwnd, UINT16 first, UINT16 last)
996 MSG16 *lpmsg = (MSG16 *)PTR_SEG_TO_LIN(msg);
997 MSG_PeekMessage( lpmsg,
998 hwnd, first, last, PM_REMOVE, FALSE );
1000 TRACE(msg,"message %04x, hwnd %04x, filter(%04x - %04x)\n", lpmsg->message,
1001 hwnd, first, last );
1002 HOOK_CallHooks16( WH_GETMESSAGE, HC_ACTION, 0, (LPARAM)msg );
1003 return (lpmsg->message != WM_QUIT);
1006 /***********************************************************************
1007 * GetMessage32A (USER32.270)
1009 BOOL32 WINAPI GetMessage32A(MSG32* lpmsg,HWND32 hwnd,UINT32 min,UINT32 max)
1011 BOOL32 ret;
1012 MSG16 *msg = SEGPTR_NEW(MSG16);
1013 if (!msg) return 0;
1014 ret=GetMessage16(SEGPTR_GET(msg),(HWND16)hwnd,min,max);
1015 /* FIXME */
1016 STRUCT32_MSG16to32(msg,lpmsg);
1017 SEGPTR_FREE(msg);
1018 return ret;
1021 /***********************************************************************
1022 * GetMessage32W (USER32.274) Retrieve next message
1024 * GetMessage retrieves the next event from the calling thread's
1025 * queue and deposits it in *lpmsg.
1027 * If _hwnd_ is not NULL, only messages for window _hwnd_ and its
1028 * children as specified by IsChild() are retrieved. If _hwnd_ is NULL
1029 * all application messages are retrieved.
1031 * _min_ and _max_ specify the range of messages of interest. If
1032 * min==max==0, no filtering is performed. Useful examples are
1033 * WM_KEYFIRST and WM_KEYLAST to retrieve keyboard input, and
1034 * WM_MOUSEFIRST and WM_MOUSELAST to retrieve mouse input.
1036 * WM_PAINT messages are not removed from the queue; they remain until
1037 * processed. Other messages are removed from the queue.
1039 * RETURNS
1041 * -1 on error, 0 if message is WM_QUIT, nonzero otherwise.
1043 * CONFORMANCE
1045 * ECMA-234, Win32
1048 BOOL32 WINAPI GetMessage32W(
1049 MSG32* lpmsg, /* buffer to receive message */
1050 HWND32 hwnd, /* restrict to messages for hwnd */
1051 UINT32 min, /* minimum message to receive */
1052 UINT32 max /* maximum message to receive */
1054 BOOL32 ret;
1055 MSG16 *msg = SEGPTR_NEW(MSG16);
1056 if (!msg) return 0;
1057 ret=GetMessage16(SEGPTR_GET(msg),(HWND16)hwnd,min,max);
1058 /* FIXME */
1059 STRUCT32_MSG16to32(msg,lpmsg);
1060 SEGPTR_FREE(msg);
1061 return ret;
1065 /***********************************************************************
1066 * PostMessage16 (USER.110)
1068 BOOL16 WINAPI PostMessage16( HWND16 hwnd, UINT16 message, WPARAM16 wParam,
1069 LPARAM lParam )
1071 MSG16 msg;
1072 WND *wndPtr;
1074 msg.hwnd = hwnd;
1075 msg.message = message;
1076 msg.wParam = wParam;
1077 msg.lParam = lParam;
1078 msg.time = GetTickCount();
1079 msg.pt.x = 0;
1080 msg.pt.y = 0;
1082 #ifdef CONFIG_IPC
1083 if (DDE_PostMessage(&msg))
1084 return TRUE;
1085 #endif /* CONFIG_IPC */
1087 if (hwnd == HWND_BROADCAST)
1089 TRACE(msg,"HWND_BROADCAST !\n");
1090 for (wndPtr = WIN_GetDesktop()->child; wndPtr; wndPtr = wndPtr->next)
1092 if (wndPtr->dwStyle & WS_POPUP || wndPtr->dwStyle & WS_CAPTION)
1094 TRACE(msg,"BROADCAST Message to hWnd=%04x m=%04X w=%04X l=%08lX !\n",
1095 wndPtr->hwndSelf, message, wParam, lParam);
1096 PostMessage16( wndPtr->hwndSelf, message, wParam, lParam );
1099 TRACE(msg,"End of HWND_BROADCAST !\n");
1100 return TRUE;
1103 wndPtr = WIN_FindWndPtr( hwnd );
1104 if (!wndPtr || !wndPtr->hmemTaskQ) return FALSE;
1106 return QUEUE_AddMsg( wndPtr->hmemTaskQ, &msg, 0 );
1110 /***********************************************************************
1111 * PostMessage32A (USER32.419)
1113 BOOL32 WINAPI PostMessage32A( HWND32 hwnd, UINT32 message, WPARAM32 wParam,
1114 LPARAM lParam )
1116 /* FIXME */
1117 if (message&0xffff0000)
1118 FIXME(msg,"message is truncated from %d to %d\n", message, message&0xffff);
1119 if (wParam&0xffff0000)
1120 FIXME(msg,"wParam is truncated from %d to %d\n", wParam, wParam&0xffff);
1121 return PostMessage16( hwnd, message, wParam, lParam );
1125 /***********************************************************************
1126 * PostMessage32W (USER32.420)
1128 BOOL32 WINAPI PostMessage32W( HWND32 hwnd, UINT32 message, WPARAM32 wParam,
1129 LPARAM lParam )
1131 /* FIXME */
1132 if (message&0xffff0000)
1133 FIXME(msg,"message is truncated from %d to %d\n", message, message&0xffff);
1134 if (wParam&0xffff0000)
1135 FIXME(msg,"wParam is truncated from %d to %d\n", wParam, wParam&0xffff);
1136 return PostMessage16( hwnd, message, wParam, lParam );
1140 /***********************************************************************
1141 * PostAppMessage16 (USER.116)
1143 BOOL16 WINAPI PostAppMessage16( HTASK16 hTask, UINT16 message, WPARAM16 wParam,
1144 LPARAM lParam )
1146 MSG16 msg;
1148 if (GetTaskQueue(hTask) == 0) return FALSE;
1149 msg.hwnd = 0;
1150 msg.message = message;
1151 msg.wParam = wParam;
1152 msg.lParam = lParam;
1153 msg.time = GetTickCount();
1154 msg.pt.x = 0;
1155 msg.pt.y = 0;
1157 return QUEUE_AddMsg( GetTaskQueue(hTask), &msg, 0 );
1161 /***********************************************************************
1162 * SendMessage16 (USER.111)
1164 LRESULT WINAPI SendMessage16( HWND16 hwnd, UINT16 msg, WPARAM16 wParam,
1165 LPARAM lParam)
1167 WND * wndPtr;
1168 WND **list, **ppWnd;
1169 LRESULT ret;
1171 #ifdef CONFIG_IPC
1172 MSG16 DDE_msg = { hwnd, msg, wParam, lParam };
1173 if (DDE_SendMessage(&DDE_msg)) return TRUE;
1174 #endif /* CONFIG_IPC */
1176 if (hwnd == HWND_BROADCAST)
1178 if (!(list = WIN_BuildWinArray( WIN_GetDesktop(), 0, NULL )))
1179 return TRUE;
1180 TRACE(msg,"HWND_BROADCAST !\n");
1181 for (ppWnd = list; *ppWnd; ppWnd++)
1183 wndPtr = *ppWnd;
1184 if (!IsWindow32(wndPtr->hwndSelf)) continue;
1185 if (wndPtr->dwStyle & WS_POPUP || wndPtr->dwStyle & WS_CAPTION)
1187 TRACE(msg,"BROADCAST Message to hWnd=%04x m=%04X w=%04lX l=%08lX !\n",
1188 wndPtr->hwndSelf, msg, (DWORD)wParam, lParam);
1189 SendMessage16( wndPtr->hwndSelf, msg, wParam, lParam );
1192 HeapFree( SystemHeap, 0, list );
1193 TRACE(msg,"End of HWND_BROADCAST !\n");
1194 return TRUE;
1197 if (HOOK_IsHooked( WH_CALLWNDPROC ))
1199 LPCWPSTRUCT16 pmsg;
1201 if ((pmsg = SEGPTR_NEW(CWPSTRUCT16)))
1203 pmsg->hwnd = hwnd;
1204 pmsg->message= msg;
1205 pmsg->wParam = wParam;
1206 pmsg->lParam = lParam;
1207 HOOK_CallHooks16( WH_CALLWNDPROC, HC_ACTION, 1,
1208 (LPARAM)SEGPTR_GET(pmsg) );
1209 hwnd = pmsg->hwnd;
1210 msg = pmsg->message;
1211 wParam = pmsg->wParam;
1212 lParam = pmsg->lParam;
1213 SEGPTR_FREE( pmsg );
1217 if (!(wndPtr = WIN_FindWndPtr( hwnd )))
1219 WARN(msg, "invalid hwnd %04x\n", hwnd );
1220 return 0;
1222 if (QUEUE_IsExitingQueue(wndPtr->hmemTaskQ))
1223 return 0; /* Don't send anything if the task is dying */
1225 SPY_EnterMessage( SPY_SENDMESSAGE16, hwnd, msg, wParam, lParam );
1227 if (wndPtr->hmemTaskQ != GetTaskQueue(0))
1228 ret = MSG_SendMessage( wndPtr->hmemTaskQ, hwnd, msg,
1229 wParam, lParam, 0 );
1230 else
1231 ret = CallWindowProc16( (WNDPROC16)wndPtr->winproc,
1232 hwnd, msg, wParam, lParam );
1234 SPY_ExitMessage( SPY_RESULT_OK16, hwnd, msg, ret );
1235 return ret;
1238 /************************************************************************
1239 * MSG_CallWndProcHook32
1241 static void MSG_CallWndProcHook32( LPMSG32 pmsg, BOOL32 bUnicode )
1243 CWPSTRUCT32 cwp;
1245 cwp.lParam = pmsg->lParam;
1246 cwp.wParam = pmsg->wParam;
1247 cwp.message = pmsg->message;
1248 cwp.hwnd = pmsg->hwnd;
1250 if (bUnicode) HOOK_CallHooks32W(WH_CALLWNDPROC, HC_ACTION, 1, (LPARAM)&cwp);
1251 else HOOK_CallHooks32A( WH_CALLWNDPROC, HC_ACTION, 1, (LPARAM)&cwp );
1253 pmsg->lParam = cwp.lParam;
1254 pmsg->wParam = cwp.wParam;
1255 pmsg->message = cwp.message;
1256 pmsg->hwnd = cwp.hwnd;
1259 /**********************************************************************
1260 * PostThreadMessage32A (USER32.422)
1262 * BUGS
1264 * Thread-local message queues are not supported.
1267 BOOL32 WINAPI PostThreadMessage32A(DWORD idThread , UINT32 message,
1268 WPARAM32 wParam, LPARAM lParam )
1270 THDB *thdb = THREAD_ID_TO_THDB(idThread);
1271 if (!thdb || !thdb->process) return FALSE;
1273 FIXME(sendmsg, "(...): Should use thread-local message queue!\n");
1274 return PostAppMessage16(thdb->process->task, message, wParam, lParam);
1277 /***********************************************************************
1278 * SendMessage32A (USER32.454)
1280 LRESULT WINAPI SendMessage32A( HWND32 hwnd, UINT32 msg, WPARAM32 wParam,
1281 LPARAM lParam )
1283 WND * wndPtr;
1284 WND **list, **ppWnd;
1285 LRESULT ret;
1287 if (hwnd == HWND_BROADCAST || hwnd == HWND_TOPMOST)
1289 if (!(list = WIN_BuildWinArray( WIN_GetDesktop(), 0, NULL )))
1290 return TRUE;
1291 for (ppWnd = list; *ppWnd; ppWnd++)
1293 wndPtr = *ppWnd;
1294 if (!IsWindow32(wndPtr->hwndSelf)) continue;
1295 if (wndPtr->dwStyle & WS_POPUP || wndPtr->dwStyle & WS_CAPTION)
1296 SendMessage32A( wndPtr->hwndSelf, msg, wParam, lParam );
1298 HeapFree( SystemHeap, 0, list );
1299 return TRUE;
1302 if (HOOK_IsHooked( WH_CALLWNDPROC ))
1303 MSG_CallWndProcHook32( (LPMSG32)&hwnd, FALSE);
1305 if (!(wndPtr = WIN_FindWndPtr( hwnd )))
1307 WARN(msg, "invalid hwnd %08x\n", hwnd );
1308 return 0;
1311 if (QUEUE_IsExitingQueue(wndPtr->hmemTaskQ))
1312 return 0; /* Don't send anything if the task is dying */
1314 SPY_EnterMessage( SPY_SENDMESSAGE32, hwnd, msg, wParam, lParam );
1316 if (wndPtr->hmemTaskQ != GetTaskQueue(0))
1317 ret = MSG_SendMessage( wndPtr->hmemTaskQ, hwnd, msg, wParam, lParam,
1318 QUEUE_SM_WIN32 );
1319 else
1320 ret = CallWindowProc32A( (WNDPROC32)wndPtr->winproc,
1321 hwnd, msg, wParam, lParam );
1323 SPY_ExitMessage( SPY_RESULT_OK32, hwnd, msg, ret );
1324 return ret;
1328 /***********************************************************************
1329 * SendMessage32W (USER32.459) Send Window Message
1331 * Sends a message to the window procedure of the specified window.
1332 * SendMessage() will not return until the called window procedure
1333 * either returns or calls ReplyMessage().
1335 * Use PostMessage() to send message and return immediately. A window
1336 * procedure may use InSendMessage() to detect
1337 * SendMessage()-originated messages.
1339 * Applications which communicate via HWND_BROADCAST may use
1340 * RegisterWindowMessage() to obtain a unique message to avoid conflicts
1341 * with other applications.
1343 * CONFORMANCE
1345 * ECMA-234, Win32
1347 LRESULT WINAPI SendMessage32W(
1348 HWND32 hwnd, /* Window to send message to. If HWND_BROADCAST,
1349 the message will be sent to all top-level windows. */
1351 UINT32 msg, /* message */
1352 WPARAM32 wParam, /* message parameter */
1353 LPARAM lParam /* additional message parameter */
1355 WND * wndPtr;
1356 WND **list, **ppWnd;
1357 LRESULT ret;
1359 if (hwnd == HWND_BROADCAST || hwnd == HWND_TOPMOST)
1361 if (!(list = WIN_BuildWinArray( WIN_GetDesktop(), 0, NULL )))
1362 return TRUE;
1363 for (ppWnd = list; *ppWnd; ppWnd++)
1365 wndPtr = *ppWnd;
1366 if (!IsWindow32(wndPtr->hwndSelf)) continue;
1367 if (wndPtr->dwStyle & WS_POPUP || wndPtr->dwStyle & WS_CAPTION)
1368 SendMessage32W( wndPtr->hwndSelf, msg, wParam, lParam );
1370 HeapFree( SystemHeap, 0, list );
1371 return TRUE;
1374 if (HOOK_IsHooked( WH_CALLWNDPROC ))
1375 MSG_CallWndProcHook32( (LPMSG32)&hwnd, TRUE);
1377 if (!(wndPtr = WIN_FindWndPtr( hwnd )))
1379 WARN(msg, "invalid hwnd %08x\n", hwnd );
1380 return 0;
1382 if (QUEUE_IsExitingQueue(wndPtr->hmemTaskQ))
1383 return 0; /* Don't send anything if the task is dying */
1385 SPY_EnterMessage( SPY_SENDMESSAGE32, hwnd, msg, wParam, lParam );
1387 if (wndPtr->hmemTaskQ != GetTaskQueue(0))
1388 ret = MSG_SendMessage( wndPtr->hmemTaskQ, hwnd, msg, wParam, lParam,
1389 QUEUE_SM_WIN32 | QUEUE_SM_UNICODE );
1390 else
1391 ret = CallWindowProc32W( (WNDPROC32)wndPtr->winproc,
1392 hwnd, msg, wParam, lParam );
1394 SPY_ExitMessage( SPY_RESULT_OK32, hwnd, msg, ret );
1395 return ret;
1399 /***********************************************************************
1400 * SendMessageTimeout16 (not a WINAPI)
1402 LRESULT WINAPI SendMessageTimeout16( HWND16 hwnd, UINT16 msg, WPARAM16 wParam,
1403 LPARAM lParam, UINT16 flags,
1404 UINT16 timeout, LPWORD resultp)
1406 FIXME(sendmsg, "(...): semistub\n");
1407 return SendMessage16 (hwnd, msg, wParam, lParam);
1411 /***********************************************************************
1412 * SendMessageTimeout32A (USER32.457)
1414 LRESULT WINAPI SendMessageTimeout32A( HWND32 hwnd, UINT32 msg, WPARAM32 wParam,
1415 LPARAM lParam, UINT32 flags,
1416 UINT32 timeout, LPDWORD resultp)
1418 FIXME(sendmsg, "(...): semistub\n");
1419 return SendMessage32A (hwnd, msg, wParam, lParam);
1423 /***********************************************************************
1424 * SendMessageTimeout32W (USER32.458)
1426 LRESULT WINAPI SendMessageTimeout32W( HWND32 hwnd, UINT32 msg, WPARAM32 wParam,
1427 LPARAM lParam, UINT32 flags,
1428 UINT32 timeout, LPDWORD resultp)
1430 FIXME(sendmsg, "(...): semistub\n");
1431 return SendMessage32W (hwnd, msg, wParam, lParam);
1435 /***********************************************************************
1436 * WaitMessage (USER.112) (USER32.578) Suspend thread pending messages
1438 * WaitMessage() suspends a thread until events appear in the thread's
1439 * queue.
1441 * BUGS
1443 * Is supposed to return BOOL under Win32.
1445 * Thread-local message queues are not supported.
1447 * CONFORMANCE
1449 * ECMA-234, Win32
1452 void WINAPI WaitMessage( void )
1454 QUEUE_WaitBits( QS_ALLINPUT );
1457 /***********************************************************************
1458 * MsgWaitForMultipleObjects (USER32.400)
1460 DWORD WINAPI MsgWaitForMultipleObjects( DWORD nCount, HANDLE32 *pHandles,
1461 BOOL32 fWaitAll, DWORD dwMilliseconds,
1462 DWORD dwWakeMask )
1464 DWORD retv;
1466 TDB *currTask = (TDB *)GlobalLock16( GetCurrentTask() );
1467 HQUEUE16 hQueue = currTask? currTask->hQueue : 0;
1468 MESSAGEQUEUE *msgQueue = (MESSAGEQUEUE *)GlobalLock16( hQueue );
1469 if (!msgQueue) return 0xFFFFFFFF;
1471 msgQueue->changeBits = 0;
1472 msgQueue->wakeMask = dwWakeMask;
1474 retv = SYNC_DoWait( nCount, pHandles, fWaitAll, dwMilliseconds, FALSE, TRUE );
1476 return retv;
1481 struct accent_char
1483 BYTE ac_accent;
1484 BYTE ac_char;
1485 BYTE ac_result;
1488 static const struct accent_char accent_chars[] =
1490 /* A good idea should be to read /usr/X11/lib/X11/locale/iso8859-x/Compose */
1491 {'`', 'A', '\300'}, {'`', 'a', '\340'},
1492 {'\'', 'A', '\301'}, {'\'', 'a', '\341'},
1493 {'^', 'A', '\302'}, {'^', 'a', '\342'},
1494 {'~', 'A', '\303'}, {'~', 'a', '\343'},
1495 {'"', 'A', '\304'}, {'"', 'a', '\344'},
1496 {'O', 'A', '\305'}, {'o', 'a', '\345'},
1497 {'0', 'A', '\305'}, {'0', 'a', '\345'},
1498 {'A', 'A', '\305'}, {'a', 'a', '\345'},
1499 {'A', 'E', '\306'}, {'a', 'e', '\346'},
1500 {',', 'C', '\307'}, {',', 'c', '\347'},
1501 {'`', 'E', '\310'}, {'`', 'e', '\350'},
1502 {'\'', 'E', '\311'}, {'\'', 'e', '\351'},
1503 {'^', 'E', '\312'}, {'^', 'e', '\352'},
1504 {'"', 'E', '\313'}, {'"', 'e', '\353'},
1505 {'`', 'I', '\314'}, {'`', 'i', '\354'},
1506 {'\'', 'I', '\315'}, {'\'', 'i', '\355'},
1507 {'^', 'I', '\316'}, {'^', 'i', '\356'},
1508 {'"', 'I', '\317'}, {'"', 'i', '\357'},
1509 {'-', 'D', '\320'}, {'-', 'd', '\360'},
1510 {'~', 'N', '\321'}, {'~', 'n', '\361'},
1511 {'`', 'O', '\322'}, {'`', 'o', '\362'},
1512 {'\'', 'O', '\323'}, {'\'', 'o', '\363'},
1513 {'^', 'O', '\324'}, {'^', 'o', '\364'},
1514 {'~', 'O', '\325'}, {'~', 'o', '\365'},
1515 {'"', 'O', '\326'}, {'"', 'o', '\366'},
1516 {'/', 'O', '\330'}, {'/', 'o', '\370'},
1517 {'`', 'U', '\331'}, {'`', 'u', '\371'},
1518 {'\'', 'U', '\332'}, {'\'', 'u', '\372'},
1519 {'^', 'U', '\333'}, {'^', 'u', '\373'},
1520 {'"', 'U', '\334'}, {'"', 'u', '\374'},
1521 {'\'', 'Y', '\335'}, {'\'', 'y', '\375'},
1522 {'T', 'H', '\336'}, {'t', 'h', '\376'},
1523 {'s', 's', '\337'}, {'"', 'y', '\377'},
1524 {'s', 'z', '\337'}, {'i', 'j', '\377'},
1525 /* iso-8859-2 uses this */
1526 {'<', 'L', '\245'}, {'<', 'l', '\265'}, /* caron */
1527 {'<', 'S', '\251'}, {'<', 's', '\271'},
1528 {'<', 'T', '\253'}, {'<', 't', '\273'},
1529 {'<', 'Z', '\256'}, {'<', 'z', '\276'},
1530 {'<', 'C', '\310'}, {'<', 'c', '\350'},
1531 {'<', 'E', '\314'}, {'<', 'e', '\354'},
1532 {'<', 'D', '\317'}, {'<', 'd', '\357'},
1533 {'<', 'N', '\322'}, {'<', 'n', '\362'},
1534 {'<', 'R', '\330'}, {'<', 'r', '\370'},
1535 {';', 'A', '\241'}, {';', 'a', '\261'}, /* ogonek */
1536 {';', 'E', '\312'}, {';', 'e', '\332'},
1537 {'\'', 'Z', '\254'}, {'\'', 'z', '\274'}, /* acute */
1538 {'\'', 'R', '\300'}, {'\'', 'r', '\340'},
1539 {'\'', 'L', '\305'}, {'\'', 'l', '\345'},
1540 {'\'', 'C', '\306'}, {'\'', 'c', '\346'},
1541 {'\'', 'N', '\321'}, {'\'', 'n', '\361'},
1542 /* collision whith S, from iso-8859-9 !!! */
1543 {',', 'S', '\252'}, {',', 's', '\272'}, /* cedilla */
1544 {',', 'T', '\336'}, {',', 't', '\376'},
1545 {'.', 'Z', '\257'}, {'.', 'z', '\277'}, /* dot above */
1546 {'/', 'L', '\243'}, {'/', 'l', '\263'}, /* slash */
1547 {'/', 'D', '\320'}, {'/', 'd', '\360'},
1548 {'(', 'A', '\303'}, {'(', 'a', '\343'}, /* breve */
1549 {'\275', 'O', '\325'}, {'\275', 'o', '\365'}, /* double acute */
1550 {'\275', 'U', '\334'}, {'\275', 'u', '\374'},
1551 {'0', 'U', '\332'}, {'0', 'u', '\372'}, /* ring above */
1552 /* iso-8859-3 uses this */
1553 {'/', 'H', '\241'}, {'/', 'h', '\261'}, /* slash */
1554 {'>', 'H', '\246'}, {'>', 'h', '\266'}, /* circumflex */
1555 {'>', 'J', '\254'}, {'>', 'j', '\274'},
1556 {'>', 'C', '\306'}, {'>', 'c', '\346'},
1557 {'>', 'G', '\330'}, {'>', 'g', '\370'},
1558 {'>', 'S', '\336'}, {'>', 's', '\376'},
1559 /* collision whith G( from iso-8859-9 !!! */
1560 {'(', 'G', '\253'}, {'(', 'g', '\273'}, /* breve */
1561 {'(', 'U', '\335'}, {'(', 'u', '\375'},
1562 /* collision whith I. from iso-8859-3 !!! */
1563 {'.', 'I', '\251'}, {'.', 'i', '\271'}, /* dot above */
1564 {'.', 'C', '\305'}, {'.', 'c', '\345'},
1565 {'.', 'G', '\325'}, {'.', 'g', '\365'},
1566 /* iso-8859-4 uses this */
1567 {',', 'R', '\243'}, {',', 'r', '\263'}, /* cedilla */
1568 {',', 'L', '\246'}, {',', 'l', '\266'},
1569 {',', 'G', '\253'}, {',', 'g', '\273'},
1570 {',', 'N', '\321'}, {',', 'n', '\361'},
1571 {',', 'K', '\323'}, {',', 'k', '\363'},
1572 {'~', 'I', '\245'}, {'~', 'i', '\265'}, /* tilde */
1573 {'-', 'E', '\252'}, {'-', 'e', '\272'}, /* macron */
1574 {'-', 'A', '\300'}, {'-', 'a', '\340'},
1575 {'-', 'I', '\317'}, {'-', 'i', '\357'},
1576 {'-', 'O', '\322'}, {'-', 'o', '\362'},
1577 {'-', 'U', '\336'}, {'-', 'u', '\376'},
1578 {'/', 'T', '\254'}, {'/', 't', '\274'}, /* slash */
1579 {'.', 'E', '\314'}, {'.', 'e', '\344'}, /* dot above */
1580 {';', 'I', '\307'}, {';', 'i', '\347'}, /* ogonek */
1581 {';', 'U', '\331'}, {';', 'u', '\371'},
1582 /* iso-8859-9 uses this */
1583 /* iso-8859-9 has really bad choosen G( S, and I. as they collide
1584 * whith the same letters on other iso-8859-x (that is they are on
1585 * different places :-( ), if you use turkish uncomment these and
1586 * comment out the lines in iso-8859-2 and iso-8859-3 sections
1587 * FIXME: should be dynamic according to chosen language
1588 * if/when Wine has turkish support.
1590 /* collision whith G( from iso-8859-3 !!! */
1591 /* {'(', 'G', '\320'}, {'(', 'g', '\360'}, */ /* breve */
1592 /* collision whith S, from iso-8859-2 !!! */
1593 /* {',', 'S', '\336'}, {',', 's', '\376'}, */ /* cedilla */
1594 /* collision whith I. from iso-8859-3 !!! */
1595 /* {'.', 'I', '\335'}, {'.', 'i', '\375'}, */ /* dot above */
1599 /***********************************************************************
1600 * MSG_DoTranslateMessage
1602 * Implementation of TranslateMessage.
1604 * TranslateMessage translates virtual-key messages into character-messages,
1605 * as follows :
1606 * WM_KEYDOWN/WM_KEYUP combinations produce a WM_CHAR or WM_DEADCHAR message.
1607 * ditto replacing WM_* with WM_SYS*
1608 * This produces WM_CHAR messages only for keys mapped to ASCII characters
1609 * by the keyboard driver.
1611 static BOOL32 MSG_DoTranslateMessage( UINT32 message, HWND32 hwnd,
1612 WPARAM32 wParam, LPARAM lParam )
1614 static int dead_char;
1615 BYTE wp[2];
1617 if (message != WM_MOUSEMOVE && message != WM_TIMER)
1618 TRACE(msg, "(%s, %04X, %08lX)\n",
1619 SPY_GetMsgName(message), wParam, lParam );
1620 if(message >= WM_KEYFIRST && message <= WM_KEYLAST)
1621 TRACE(key, "(%s, %04X, %08lX)\n",
1622 SPY_GetMsgName(message), wParam, lParam );
1624 if ((message != WM_KEYDOWN) && (message != WM_SYSKEYDOWN)) return FALSE;
1626 TRACE(key, "Translating key %04X, scancode %04X\n",
1627 wParam, HIWORD(lParam) );
1629 /* FIXME : should handle ToAscii yielding 2 */
1630 switch (ToAscii32(wParam, HIWORD(lParam),
1631 QueueKeyStateTable,(LPWORD)wp, 0))
1633 case 1 :
1634 message = (message == WM_KEYDOWN) ? WM_CHAR : WM_SYSCHAR;
1635 /* Should dead chars handling go in ToAscii ? */
1636 if (dead_char)
1638 int i;
1640 if (wp[0] == ' ') wp[0] = dead_char;
1641 if (dead_char == 0xa2) dead_char = '(';
1642 else if (dead_char == 0xa8) dead_char = '"';
1643 else if (dead_char == 0xb2) dead_char = ';';
1644 else if (dead_char == 0xb4) dead_char = '\'';
1645 else if (dead_char == 0xb7) dead_char = '<';
1646 else if (dead_char == 0xb8) dead_char = ',';
1647 else if (dead_char == 0xff) dead_char = '.';
1648 for (i = 0; i < sizeof(accent_chars)/sizeof(accent_chars[0]); i++)
1649 if ((accent_chars[i].ac_accent == dead_char) &&
1650 (accent_chars[i].ac_char == wp[0]))
1652 wp[0] = accent_chars[i].ac_result;
1653 break;
1655 dead_char = 0;
1657 TRACE(key, "1 -> PostMessage(%s)\n", SPY_GetMsgName(message));
1658 PostMessage16( hwnd, message, wp[0], lParam );
1659 return TRUE;
1661 case -1 :
1662 message = (message == WM_KEYDOWN) ? WM_DEADCHAR : WM_SYSDEADCHAR;
1663 dead_char = wp[0];
1664 TRACE(key, "-1 -> PostMessage(%s)\n",
1665 SPY_GetMsgName(message));
1666 PostMessage16( hwnd, message, wp[0], lParam );
1667 return TRUE;
1669 return FALSE;
1673 /***********************************************************************
1674 * TranslateMessage16 (USER.113)
1676 BOOL16 WINAPI TranslateMessage16( const MSG16 *msg )
1678 return MSG_DoTranslateMessage( msg->message, msg->hwnd,
1679 msg->wParam, msg->lParam );
1683 /***********************************************************************
1684 * TranslateMessage32 (USER32.556)
1686 BOOL32 WINAPI TranslateMessage32( const MSG32 *msg )
1688 return MSG_DoTranslateMessage( msg->message, msg->hwnd,
1689 msg->wParam, msg->lParam );
1693 /***********************************************************************
1694 * DispatchMessage16 (USER.114)
1696 LONG WINAPI DispatchMessage16( const MSG16* msg )
1698 WND * wndPtr;
1699 LONG retval;
1700 int painting;
1702 /* Process timer messages */
1703 if ((msg->message == WM_TIMER) || (msg->message == WM_SYSTIMER))
1705 if (msg->lParam)
1707 return CallWindowProc16( (WNDPROC16)msg->lParam, msg->hwnd,
1708 msg->message, msg->wParam, GetTickCount() );
1712 if (!msg->hwnd) return 0;
1713 if (!(wndPtr = WIN_FindWndPtr( msg->hwnd ))) return 0;
1714 if (!wndPtr->winproc) return 0;
1715 painting = (msg->message == WM_PAINT);
1716 if (painting) wndPtr->flags |= WIN_NEEDS_BEGINPAINT;
1718 SPY_EnterMessage( SPY_DISPATCHMESSAGE16, msg->hwnd, msg->message,
1719 msg->wParam, msg->lParam );
1720 retval = CallWindowProc16( (WNDPROC16)wndPtr->winproc,
1721 msg->hwnd, msg->message,
1722 msg->wParam, msg->lParam );
1723 SPY_ExitMessage( SPY_RESULT_OK16, msg->hwnd, msg->message, retval );
1725 if (painting && (wndPtr = WIN_FindWndPtr( msg->hwnd )) &&
1726 (wndPtr->flags & WIN_NEEDS_BEGINPAINT) && wndPtr->hrgnUpdate)
1728 ERR(msg, "BeginPaint not called on WM_PAINT for hwnd %04x!\n",
1729 msg->hwnd);
1730 wndPtr->flags &= ~WIN_NEEDS_BEGINPAINT;
1731 /* Validate the update region to avoid infinite WM_PAINT loop */
1732 ValidateRect32( msg->hwnd, NULL );
1734 return retval;
1738 /***********************************************************************
1739 * DispatchMessage32A (USER32.141)
1741 LONG WINAPI DispatchMessage32A( const MSG32* msg )
1743 WND * wndPtr;
1744 LONG retval;
1745 int painting;
1747 /* Process timer messages */
1748 if ((msg->message == WM_TIMER) || (msg->message == WM_SYSTIMER))
1750 if (msg->lParam)
1752 /* HOOK_CallHooks32A( WH_CALLWNDPROC, HC_ACTION, 0, FIXME ); */
1753 return CallWindowProc32A( (WNDPROC32)msg->lParam, msg->hwnd,
1754 msg->message, msg->wParam, GetTickCount() );
1758 if (!msg->hwnd) return 0;
1759 if (!(wndPtr = WIN_FindWndPtr( msg->hwnd ))) return 0;
1760 if (!wndPtr->winproc) return 0;
1761 painting = (msg->message == WM_PAINT);
1762 if (painting) wndPtr->flags |= WIN_NEEDS_BEGINPAINT;
1763 /* HOOK_CallHooks32A( WH_CALLWNDPROC, HC_ACTION, 0, FIXME ); */
1765 SPY_EnterMessage( SPY_DISPATCHMESSAGE32, msg->hwnd, msg->message,
1766 msg->wParam, msg->lParam );
1767 retval = CallWindowProc32A( (WNDPROC32)wndPtr->winproc,
1768 msg->hwnd, msg->message,
1769 msg->wParam, msg->lParam );
1770 SPY_ExitMessage( SPY_RESULT_OK32, msg->hwnd, msg->message, retval );
1772 if (painting && (wndPtr = WIN_FindWndPtr( msg->hwnd )) &&
1773 (wndPtr->flags & WIN_NEEDS_BEGINPAINT) && wndPtr->hrgnUpdate)
1775 ERR(msg, "BeginPaint not called on WM_PAINT for hwnd %04x!\n",
1776 msg->hwnd);
1777 wndPtr->flags &= ~WIN_NEEDS_BEGINPAINT;
1778 /* Validate the update region to avoid infinite WM_PAINT loop */
1779 ValidateRect32( msg->hwnd, NULL );
1781 return retval;
1785 /***********************************************************************
1786 * DispatchMessage32W (USER32.142) Process Message
1788 * Process the message specified in the structure *_msg_.
1790 * If the lpMsg parameter points to a WM_TIMER message and the
1791 * parameter of the WM_TIMER message is not NULL, the lParam parameter
1792 * points to the function that is called instead of the window
1793 * procedure.
1795 * The message must be valid.
1797 * RETURNS
1799 * DispatchMessage() returns the result of the window procedure invoked.
1801 * CONFORMANCE
1803 * ECMA-234, Win32
1806 LONG WINAPI DispatchMessage32W( const MSG32* msg )
1808 WND * wndPtr;
1809 LONG retval;
1810 int painting;
1812 /* Process timer messages */
1813 if ((msg->message == WM_TIMER) || (msg->message == WM_SYSTIMER))
1815 if (msg->lParam)
1817 /* HOOK_CallHooks32W( WH_CALLWNDPROC, HC_ACTION, 0, FIXME ); */
1818 return CallWindowProc32W( (WNDPROC32)msg->lParam, msg->hwnd,
1819 msg->message, msg->wParam, GetTickCount() );
1823 if (!msg->hwnd) return 0;
1824 if (!(wndPtr = WIN_FindWndPtr( msg->hwnd ))) return 0;
1825 if (!wndPtr->winproc) return 0;
1826 painting = (msg->message == WM_PAINT);
1827 if (painting) wndPtr->flags |= WIN_NEEDS_BEGINPAINT;
1828 /* HOOK_CallHooks32W( WH_CALLWNDPROC, HC_ACTION, 0, FIXME ); */
1830 SPY_EnterMessage( SPY_DISPATCHMESSAGE32, msg->hwnd, msg->message,
1831 msg->wParam, msg->lParam );
1832 retval = CallWindowProc32W( (WNDPROC32)wndPtr->winproc,
1833 msg->hwnd, msg->message,
1834 msg->wParam, msg->lParam );
1835 SPY_ExitMessage( SPY_RESULT_OK32, msg->hwnd, msg->message, retval );
1837 if (painting && (wndPtr = WIN_FindWndPtr( msg->hwnd )) &&
1838 (wndPtr->flags & WIN_NEEDS_BEGINPAINT) && wndPtr->hrgnUpdate)
1840 ERR(msg, "BeginPaint not called on WM_PAINT for hwnd %04x!\n",
1841 msg->hwnd);
1842 wndPtr->flags &= ~WIN_NEEDS_BEGINPAINT;
1843 /* Validate the update region to avoid infinite WM_PAINT loop */
1844 ValidateRect32( msg->hwnd, NULL );
1846 return retval;
1850 /***********************************************************************
1851 * RegisterWindowMessage16 (USER.118)
1853 WORD WINAPI RegisterWindowMessage16( SEGPTR str )
1855 TRACE(msg, "%08lx\n", (DWORD)str );
1856 return GlobalAddAtom16( str );
1860 /***********************************************************************
1861 * RegisterWindowMessage32A (USER32.437)
1863 WORD WINAPI RegisterWindowMessage32A( LPCSTR str )
1865 TRACE(msg, "%s\n", str );
1866 return GlobalAddAtom32A( str );
1870 /***********************************************************************
1871 * RegisterWindowMessage32W (USER32.438)
1873 WORD WINAPI RegisterWindowMessage32W( LPCWSTR str )
1875 TRACE(msg, "%p\n", str );
1876 return GlobalAddAtom32W( str );
1880 /***********************************************************************
1881 * GetTickCount (USER.13) (KERNEL32.299) System Time
1882 * Returns the number of milliseconds, modulo 2^32, since the start
1883 * of the current session.
1885 * CONFORMANCE
1887 * ECMA-234, Win32
1889 DWORD WINAPI GetTickCount(void)
1891 struct timeval t;
1892 gettimeofday( &t, NULL );
1893 /* make extremely compatible: granularity is 25 msec */
1894 return ((t.tv_sec * 1000) + (t.tv_usec / 25000) * 25) - MSG_WineStartTicks;
1898 /***********************************************************************
1899 * GetCurrentTime16 (USER.15)
1901 * (effectively identical to GetTickCount)
1903 DWORD WINAPI GetCurrentTime16(void)
1905 return GetTickCount();
1909 /***********************************************************************
1910 * InSendMessage16 (USER.192)
1912 BOOL16 WINAPI InSendMessage16(void)
1914 return InSendMessage32();
1918 /***********************************************************************
1919 * InSendMessage32 (USER32.320)
1921 BOOL32 WINAPI InSendMessage32(void)
1923 MESSAGEQUEUE *queue;
1925 if (!(queue = (MESSAGEQUEUE *)GlobalLock16( GetTaskQueue(0) )))
1926 return 0;
1927 return (BOOL32)queue->InSendMessageHandle;
1930 /***********************************************************************
1931 * BroadcastSystemMessage (USER32.12)
1933 LONG WINAPI BroadcastSystemMessage(
1934 DWORD dwFlags,LPDWORD recipients,UINT32 uMessage,WPARAM32 wParam,
1935 LPARAM lParam
1937 FIXME(sendmsg,"(%08lx,%08lx,%08x,%08x,%08lx): stub!\n",
1938 dwFlags,*recipients,uMessage,wParam,lParam
1940 return 0;
1943 /***********************************************************************
1944 * SendNotifyMessageA (USER32.460)
1945 * FIXME
1946 * The message sended with PostMessage has to be put in the queue
1947 * with a higher priority as the other "Posted" messages.
1948 * QUEUE_AddMsg has to be modifyed.
1950 LONG WINAPI SendNotifyMessage32A(HWND32 hwnd,UINT32 msg,WPARAM32 wParam,LPARAM lParam)
1951 { BOOL32 ret = TRUE;
1952 FIXME(msg,"(%04x,%08x,%08x,%08lx) not complete\n",
1953 hwnd, msg, wParam, lParam);
1955 if ( GetCurrentThreadId() == GetWindowThreadProcessId ( hwnd, NULL))
1956 { ret=SendMessage32A ( hwnd, msg, wParam, lParam );
1958 else
1959 { PostMessage32A ( hwnd, msg, wParam, lParam );
1961 return ret;
1963 /***********************************************************************
1964 * SendMessageCallBack32A
1965 * FIXME: It's like PostMessage. The callback gets called when the message
1966 * is processed. We have to modify the message processing for a exact
1967 * implementation...
1969 BOOL32 WINAPI SendMessageCallBack32A(
1970 HWND32 hWnd,UINT32 Msg,WPARAM32 wParam,LPARAM lParam,
1971 FARPROC32 lpResultCallBack,DWORD dwData)
1973 FIXME(msg,"(0x%04x,0x%04x,0x%08x,0x%08lx,%p,0x%08lx),stub!\n",
1974 hWnd,Msg,wParam,lParam,lpResultCallBack,dwData);
1975 if ( hWnd == HWND_BROADCAST)
1976 { PostMessage32A( hWnd, Msg, wParam, lParam);
1977 FIXME(msg,"Broadcast: Callback will not be called!\n");
1978 return TRUE;
1980 (lpResultCallBack)( hWnd, Msg, dwData, SendMessage32A ( hWnd, Msg, wParam, lParam ));
1981 return TRUE;