Update the modemn status bit that indicates whether the RLSD line is
[wine.git] / windows / message.c
blob92189dae0c9986d00d99c6cfa95f868b0ec9d2f7
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 return PostMessage16( hwnd, message, wParam, lParam );
1121 /***********************************************************************
1122 * PostMessage32W (USER32.420)
1124 BOOL32 WINAPI PostMessage32W( HWND32 hwnd, UINT32 message, WPARAM32 wParam,
1125 LPARAM lParam )
1127 /* FIXME */
1128 return PostMessage16( hwnd, message, wParam, lParam );
1132 /***********************************************************************
1133 * PostAppMessage16 (USER.116)
1135 BOOL16 WINAPI PostAppMessage16( HTASK16 hTask, UINT16 message, WPARAM16 wParam,
1136 LPARAM lParam )
1138 MSG16 msg;
1140 if (GetTaskQueue(hTask) == 0) return FALSE;
1141 msg.hwnd = 0;
1142 msg.message = message;
1143 msg.wParam = wParam;
1144 msg.lParam = lParam;
1145 msg.time = GetTickCount();
1146 msg.pt.x = 0;
1147 msg.pt.y = 0;
1149 return QUEUE_AddMsg( GetTaskQueue(hTask), &msg, 0 );
1153 /***********************************************************************
1154 * SendMessage16 (USER.111)
1156 LRESULT WINAPI SendMessage16( HWND16 hwnd, UINT16 msg, WPARAM16 wParam,
1157 LPARAM lParam)
1159 WND * wndPtr;
1160 WND **list, **ppWnd;
1161 LRESULT ret;
1163 #ifdef CONFIG_IPC
1164 MSG16 DDE_msg = { hwnd, msg, wParam, lParam };
1165 if (DDE_SendMessage(&DDE_msg)) return TRUE;
1166 #endif /* CONFIG_IPC */
1168 if (hwnd == HWND_BROADCAST)
1170 if (!(list = WIN_BuildWinArray( WIN_GetDesktop(), 0, NULL )))
1171 return TRUE;
1172 TRACE(msg,"HWND_BROADCAST !\n");
1173 for (ppWnd = list; *ppWnd; ppWnd++)
1175 wndPtr = *ppWnd;
1176 if (!IsWindow32(wndPtr->hwndSelf)) continue;
1177 if (wndPtr->dwStyle & WS_POPUP || wndPtr->dwStyle & WS_CAPTION)
1179 TRACE(msg,"BROADCAST Message to hWnd=%04x m=%04X w=%04lX l=%08lX !\n",
1180 wndPtr->hwndSelf, msg, (DWORD)wParam, lParam);
1181 SendMessage16( wndPtr->hwndSelf, msg, wParam, lParam );
1184 HeapFree( SystemHeap, 0, list );
1185 TRACE(msg,"End of HWND_BROADCAST !\n");
1186 return TRUE;
1189 if (HOOK_IsHooked( WH_CALLWNDPROC ))
1191 LPCWPSTRUCT16 pmsg;
1193 if ((pmsg = SEGPTR_NEW(CWPSTRUCT16)))
1195 pmsg->hwnd = hwnd;
1196 pmsg->message= msg;
1197 pmsg->wParam = wParam;
1198 pmsg->lParam = lParam;
1199 HOOK_CallHooks16( WH_CALLWNDPROC, HC_ACTION, 1,
1200 (LPARAM)SEGPTR_GET(pmsg) );
1201 hwnd = pmsg->hwnd;
1202 msg = pmsg->message;
1203 wParam = pmsg->wParam;
1204 lParam = pmsg->lParam;
1205 SEGPTR_FREE( pmsg );
1209 if (!(wndPtr = WIN_FindWndPtr( hwnd )))
1211 WARN(msg, "invalid hwnd %04x\n", hwnd );
1212 return 0;
1214 if (QUEUE_IsExitingQueue(wndPtr->hmemTaskQ))
1215 return 0; /* Don't send anything if the task is dying */
1217 SPY_EnterMessage( SPY_SENDMESSAGE16, hwnd, msg, wParam, lParam );
1219 if (wndPtr->hmemTaskQ != GetTaskQueue(0))
1220 ret = MSG_SendMessage( wndPtr->hmemTaskQ, hwnd, msg,
1221 wParam, lParam, 0 );
1222 else
1223 ret = CallWindowProc16( (WNDPROC16)wndPtr->winproc,
1224 hwnd, msg, wParam, lParam );
1226 SPY_ExitMessage( SPY_RESULT_OK16, hwnd, msg, ret );
1227 return ret;
1230 /************************************************************************
1231 * MSG_CallWndProcHook32
1233 static void MSG_CallWndProcHook32( LPMSG32 pmsg, BOOL32 bUnicode )
1235 CWPSTRUCT32 cwp;
1237 cwp.lParam = pmsg->lParam;
1238 cwp.wParam = pmsg->wParam;
1239 cwp.message = pmsg->message;
1240 cwp.hwnd = pmsg->hwnd;
1242 if (bUnicode) HOOK_CallHooks32W(WH_CALLWNDPROC, HC_ACTION, 1, (LPARAM)&cwp);
1243 else HOOK_CallHooks32A( WH_CALLWNDPROC, HC_ACTION, 1, (LPARAM)&cwp );
1245 pmsg->lParam = cwp.lParam;
1246 pmsg->wParam = cwp.wParam;
1247 pmsg->message = cwp.message;
1248 pmsg->hwnd = cwp.hwnd;
1251 /**********************************************************************
1252 * PostThreadMessage32A (USER32.422)
1254 BOOL32 WINAPI PostThreadMessage32A(DWORD idThread , UINT32 message,
1255 WPARAM32 wParam, LPARAM lParam )
1257 THDB *thdb = THREAD_ID_TO_THDB(idThread);
1258 if (!thdb || !thdb->process) return FALSE;
1260 FIXME(sendmsg, "(...): Should use thread-local message queue!\n");
1261 return PostAppMessage16(thdb->process->task, message, wParam, lParam);
1264 /***********************************************************************
1265 * SendMessage32A (USER32.454)
1267 LRESULT WINAPI SendMessage32A( HWND32 hwnd, UINT32 msg, WPARAM32 wParam,
1268 LPARAM lParam )
1270 WND * wndPtr;
1271 WND **list, **ppWnd;
1272 LRESULT ret;
1274 if (hwnd == HWND_BROADCAST || hwnd == HWND_TOPMOST)
1276 if (!(list = WIN_BuildWinArray( WIN_GetDesktop(), 0, NULL )))
1277 return TRUE;
1278 for (ppWnd = list; *ppWnd; ppWnd++)
1280 wndPtr = *ppWnd;
1281 if (!IsWindow32(wndPtr->hwndSelf)) continue;
1282 if (wndPtr->dwStyle & WS_POPUP || wndPtr->dwStyle & WS_CAPTION)
1283 SendMessage32A( wndPtr->hwndSelf, msg, wParam, lParam );
1285 HeapFree( SystemHeap, 0, list );
1286 return TRUE;
1289 if (HOOK_IsHooked( WH_CALLWNDPROC ))
1290 MSG_CallWndProcHook32( (LPMSG32)&hwnd, FALSE);
1292 if (!(wndPtr = WIN_FindWndPtr( hwnd )))
1294 WARN(msg, "invalid hwnd %08x\n", hwnd );
1295 return 0;
1298 if (QUEUE_IsExitingQueue(wndPtr->hmemTaskQ))
1299 return 0; /* Don't send anything if the task is dying */
1301 SPY_EnterMessage( SPY_SENDMESSAGE32, hwnd, msg, wParam, lParam );
1303 if (wndPtr->hmemTaskQ != GetTaskQueue(0))
1304 ret = MSG_SendMessage( wndPtr->hmemTaskQ, hwnd, msg, wParam, lParam,
1305 QUEUE_SM_WIN32 );
1306 else
1307 ret = CallWindowProc32A( (WNDPROC32)wndPtr->winproc,
1308 hwnd, msg, wParam, lParam );
1310 SPY_ExitMessage( SPY_RESULT_OK32, hwnd, msg, ret );
1311 return ret;
1315 /***********************************************************************
1316 * SendMessage32W (USER32.459)
1318 LRESULT WINAPI SendMessage32W( HWND32 hwnd, UINT32 msg, WPARAM32 wParam,
1319 LPARAM lParam )
1321 WND * wndPtr;
1322 WND **list, **ppWnd;
1323 LRESULT ret;
1325 if (hwnd == HWND_BROADCAST || hwnd == HWND_TOPMOST)
1327 if (!(list = WIN_BuildWinArray( WIN_GetDesktop(), 0, NULL )))
1328 return TRUE;
1329 for (ppWnd = list; *ppWnd; ppWnd++)
1331 wndPtr = *ppWnd;
1332 if (!IsWindow32(wndPtr->hwndSelf)) continue;
1333 if (wndPtr->dwStyle & WS_POPUP || wndPtr->dwStyle & WS_CAPTION)
1334 SendMessage32W( wndPtr->hwndSelf, msg, wParam, lParam );
1336 HeapFree( SystemHeap, 0, list );
1337 return TRUE;
1340 if (HOOK_IsHooked( WH_CALLWNDPROC ))
1341 MSG_CallWndProcHook32( (LPMSG32)&hwnd, TRUE);
1343 if (!(wndPtr = WIN_FindWndPtr( hwnd )))
1345 WARN(msg, "invalid hwnd %08x\n", hwnd );
1346 return 0;
1348 if (QUEUE_IsExitingQueue(wndPtr->hmemTaskQ))
1349 return 0; /* Don't send anything if the task is dying */
1351 SPY_EnterMessage( SPY_SENDMESSAGE32, hwnd, msg, wParam, lParam );
1353 if (wndPtr->hmemTaskQ != GetTaskQueue(0))
1354 ret = MSG_SendMessage( wndPtr->hmemTaskQ, hwnd, msg, wParam, lParam,
1355 QUEUE_SM_WIN32 | QUEUE_SM_UNICODE );
1356 else
1357 ret = CallWindowProc32W( (WNDPROC32)wndPtr->winproc,
1358 hwnd, msg, wParam, lParam );
1360 SPY_ExitMessage( SPY_RESULT_OK32, hwnd, msg, ret );
1361 return ret;
1365 /***********************************************************************
1366 * SendMessageTimeout16 (not a WINAPI)
1368 LRESULT WINAPI SendMessageTimeout16( HWND16 hwnd, UINT16 msg, WPARAM16 wParam,
1369 LPARAM lParam, UINT16 flags,
1370 UINT16 timeout, LPWORD resultp)
1372 FIXME(sendmsg, "(...): semistub\n");
1373 return SendMessage16 (hwnd, msg, wParam, lParam);
1377 /***********************************************************************
1378 * SendMessageTimeout32A (USER32.457)
1380 LRESULT WINAPI SendMessageTimeout32A( HWND32 hwnd, UINT32 msg, WPARAM32 wParam,
1381 LPARAM lParam, UINT32 flags,
1382 UINT32 timeout, LPDWORD resultp)
1384 FIXME(sendmsg, "(...): semistub\n");
1385 return SendMessage32A (hwnd, msg, wParam, lParam);
1389 /***********************************************************************
1390 * SendMessageTimeout32W (USER32.458)
1392 LRESULT WINAPI SendMessageTimeout32W( HWND32 hwnd, UINT32 msg, WPARAM32 wParam,
1393 LPARAM lParam, UINT32 flags,
1394 UINT32 timeout, LPDWORD resultp)
1396 FIXME(sendmsg, "(...): semistub\n");
1397 return SendMessage32W (hwnd, msg, wParam, lParam);
1401 /***********************************************************************
1402 * WaitMessage (USER.112) (USER32.578) Suspend thread pending messages
1404 * WaitMessage() suspends a thread until events appear in the thread's
1405 * queue.
1407 * BUGS
1409 * Is supposed to return BOOL under Win32.
1411 * CONFORMANCE
1413 * ECMA-234, Win32
1416 void WINAPI WaitMessage( void )
1418 QUEUE_WaitBits( QS_ALLINPUT );
1421 /***********************************************************************
1422 * MsgWaitForMultipleObjects (USER32.400)
1424 DWORD WINAPI MsgWaitForMultipleObjects( DWORD nCount, HANDLE32 *pHandles,
1425 BOOL32 fWaitAll, DWORD dwMilliseconds,
1426 DWORD dwWakeMask )
1428 DWORD retv;
1430 TDB *currTask = (TDB *)GlobalLock16( GetCurrentTask() );
1431 HQUEUE16 hQueue = currTask? currTask->hQueue : 0;
1432 MESSAGEQUEUE *msgQueue = (MESSAGEQUEUE *)GlobalLock16( hQueue );
1433 if (!msgQueue) return 0xFFFFFFFF;
1435 msgQueue->changeBits = 0;
1436 msgQueue->wakeMask = dwWakeMask;
1438 retv = SYNC_DoWait( nCount, pHandles, fWaitAll, dwMilliseconds, FALSE, TRUE );
1440 return retv;
1445 struct accent_char
1447 BYTE ac_accent;
1448 BYTE ac_char;
1449 BYTE ac_result;
1452 static const struct accent_char accent_chars[] =
1454 /* A good idea should be to read /usr/X11/lib/X11/locale/iso8859-x/Compose */
1455 {'`', 'A', '\300'}, {'`', 'a', '\340'},
1456 {'\'', 'A', '\301'}, {'\'', 'a', '\341'},
1457 {'^', 'A', '\302'}, {'^', 'a', '\342'},
1458 {'~', 'A', '\303'}, {'~', 'a', '\343'},
1459 {'"', 'A', '\304'}, {'"', 'a', '\344'},
1460 {'O', 'A', '\305'}, {'o', 'a', '\345'},
1461 {'0', 'A', '\305'}, {'0', 'a', '\345'},
1462 {'A', 'A', '\305'}, {'a', 'a', '\345'},
1463 {'A', 'E', '\306'}, {'a', 'e', '\346'},
1464 {',', 'C', '\307'}, {',', 'c', '\347'},
1465 {'`', 'E', '\310'}, {'`', 'e', '\350'},
1466 {'\'', 'E', '\311'}, {'\'', 'e', '\351'},
1467 {'^', 'E', '\312'}, {'^', 'e', '\352'},
1468 {'"', 'E', '\313'}, {'"', 'e', '\353'},
1469 {'`', 'I', '\314'}, {'`', 'i', '\354'},
1470 {'\'', 'I', '\315'}, {'\'', 'i', '\355'},
1471 {'^', 'I', '\316'}, {'^', 'i', '\356'},
1472 {'"', 'I', '\317'}, {'"', 'i', '\357'},
1473 {'-', 'D', '\320'}, {'-', 'd', '\360'},
1474 {'~', 'N', '\321'}, {'~', 'n', '\361'},
1475 {'`', 'O', '\322'}, {'`', 'o', '\362'},
1476 {'\'', 'O', '\323'}, {'\'', 'o', '\363'},
1477 {'^', 'O', '\324'}, {'^', 'o', '\364'},
1478 {'~', 'O', '\325'}, {'~', 'o', '\365'},
1479 {'"', 'O', '\326'}, {'"', 'o', '\366'},
1480 {'/', 'O', '\330'}, {'/', 'o', '\370'},
1481 {'`', 'U', '\331'}, {'`', 'u', '\371'},
1482 {'\'', 'U', '\332'}, {'\'', 'u', '\372'},
1483 {'^', 'U', '\333'}, {'^', 'u', '\373'},
1484 {'"', 'U', '\334'}, {'"', 'u', '\374'},
1485 {'\'', 'Y', '\335'}, {'\'', 'y', '\375'},
1486 {'T', 'H', '\336'}, {'t', 'h', '\376'},
1487 {'s', 's', '\337'}, {'"', 'y', '\377'},
1488 {'s', 'z', '\337'}, {'i', 'j', '\377'},
1489 /* iso-8859-2 uses this */
1490 {'<', 'L', '\245'}, {'<', 'l', '\265'}, /* caron */
1491 {'<', 'S', '\251'}, {'<', 's', '\271'},
1492 {'<', 'T', '\253'}, {'<', 't', '\273'},
1493 {'<', 'Z', '\256'}, {'<', 'z', '\276'},
1494 {'<', 'C', '\310'}, {'<', 'c', '\350'},
1495 {'<', 'E', '\314'}, {'<', 'e', '\354'},
1496 {'<', 'D', '\317'}, {'<', 'd', '\357'},
1497 {'<', 'N', '\322'}, {'<', 'n', '\362'},
1498 {'<', 'R', '\330'}, {'<', 'r', '\370'},
1499 {';', 'A', '\241'}, {';', 'a', '\261'}, /* ogonek */
1500 {';', 'E', '\312'}, {';', 'e', '\332'},
1501 {'\'', 'Z', '\254'}, {'\'', 'z', '\274'}, /* acute */
1502 {'\'', 'R', '\300'}, {'\'', 'r', '\340'},
1503 {'\'', 'L', '\305'}, {'\'', 'l', '\345'},
1504 {'\'', 'C', '\306'}, {'\'', 'c', '\346'},
1505 {'\'', 'N', '\321'}, {'\'', 'n', '\361'},
1506 /* collision whith S, from iso-8859-9 !!! */
1507 {',', 'S', '\252'}, {',', 's', '\272'}, /* cedilla */
1508 {',', 'T', '\336'}, {',', 't', '\376'},
1509 {'.', 'Z', '\257'}, {'.', 'z', '\277'}, /* dot above */
1510 {'/', 'L', '\243'}, {'/', 'l', '\263'}, /* slash */
1511 {'/', 'D', '\320'}, {'/', 'd', '\360'},
1512 {'(', 'A', '\303'}, {'(', 'a', '\343'}, /* breve */
1513 {'\275', 'O', '\325'}, {'\275', 'o', '\365'}, /* double acute */
1514 {'\275', 'U', '\334'}, {'\275', 'u', '\374'},
1515 {'0', 'U', '\332'}, {'0', 'u', '\372'}, /* ring above */
1516 /* iso-8859-3 uses this */
1517 {'/', 'H', '\241'}, {'/', 'h', '\261'}, /* slash */
1518 {'>', 'H', '\246'}, {'>', 'h', '\266'}, /* circumflex */
1519 {'>', 'J', '\254'}, {'>', 'j', '\274'},
1520 {'>', 'C', '\306'}, {'>', 'c', '\346'},
1521 {'>', 'G', '\330'}, {'>', 'g', '\370'},
1522 {'>', 'S', '\336'}, {'>', 's', '\376'},
1523 /* collision whith G( from iso-8859-9 !!! */
1524 {'(', 'G', '\253'}, {'(', 'g', '\273'}, /* breve */
1525 {'(', 'U', '\335'}, {'(', 'u', '\375'},
1526 /* collision whith I. from iso-8859-3 !!! */
1527 {'.', 'I', '\251'}, {'.', 'i', '\271'}, /* dot above */
1528 {'.', 'C', '\305'}, {'.', 'c', '\345'},
1529 {'.', 'G', '\325'}, {'.', 'g', '\365'},
1530 /* iso-8859-4 uses this */
1531 {',', 'R', '\243'}, {',', 'r', '\263'}, /* cedilla */
1532 {',', 'L', '\246'}, {',', 'l', '\266'},
1533 {',', 'G', '\253'}, {',', 'g', '\273'},
1534 {',', 'N', '\321'}, {',', 'n', '\361'},
1535 {',', 'K', '\323'}, {',', 'k', '\363'},
1536 {'~', 'I', '\245'}, {'~', 'i', '\265'}, /* tilde */
1537 {'-', 'E', '\252'}, {'-', 'e', '\272'}, /* macron */
1538 {'-', 'A', '\300'}, {'-', 'a', '\340'},
1539 {'-', 'I', '\317'}, {'-', 'i', '\357'},
1540 {'-', 'O', '\322'}, {'-', 'o', '\362'},
1541 {'-', 'U', '\336'}, {'-', 'u', '\376'},
1542 {'/', 'T', '\254'}, {'/', 't', '\274'}, /* slash */
1543 {'.', 'E', '\314'}, {'.', 'e', '\344'}, /* dot above */
1544 {';', 'I', '\307'}, {';', 'i', '\347'}, /* ogonek */
1545 {';', 'U', '\331'}, {';', 'u', '\371'},
1546 /* iso-8859-9 uses this */
1547 /* iso-8859-9 has really bad choosen G( S, and I. as they collide
1548 * whith the same letters on other iso-8859-x (that is they are on
1549 * different places :-( ), if you use turkish uncomment these and
1550 * comment out the lines in iso-8859-2 and iso-8859-3 sections
1551 * FIXME: should be dynamic according to chosen language
1552 * if/when Wine has turkish support.
1554 /* collision whith G( from iso-8859-3 !!! */
1555 /* {'(', 'G', '\320'}, {'(', 'g', '\360'}, */ /* breve */
1556 /* collision whith S, from iso-8859-2 !!! */
1557 /* {',', 'S', '\336'}, {',', 's', '\376'}, */ /* cedilla */
1558 /* collision whith I. from iso-8859-3 !!! */
1559 /* {'.', 'I', '\335'}, {'.', 'i', '\375'}, */ /* dot above */
1563 /***********************************************************************
1564 * MSG_DoTranslateMessage
1566 * Implementation of TranslateMessage.
1568 * TranslateMessage translates virtual-key messages into character-messages,
1569 * as follows :
1570 * WM_KEYDOWN/WM_KEYUP combinations produce a WM_CHAR or WM_DEADCHAR message.
1571 * ditto replacing WM_* with WM_SYS*
1572 * This produces WM_CHAR messages only for keys mapped to ASCII characters
1573 * by the keyboard driver.
1575 static BOOL32 MSG_DoTranslateMessage( UINT32 message, HWND32 hwnd,
1576 WPARAM32 wParam, LPARAM lParam )
1578 static int dead_char;
1579 BYTE wp[2];
1581 if (message != WM_MOUSEMOVE && message != WM_TIMER)
1582 TRACE(msg, "(%s, %04X, %08lX)\n",
1583 SPY_GetMsgName(message), wParam, lParam );
1584 if(message >= WM_KEYFIRST && message <= WM_KEYLAST)
1585 TRACE(key, "(%s, %04X, %08lX)\n",
1586 SPY_GetMsgName(message), wParam, lParam );
1588 if ((message != WM_KEYDOWN) && (message != WM_SYSKEYDOWN)) return FALSE;
1590 TRACE(key, "Translating key %04X, scancode %04X\n",
1591 wParam, HIWORD(lParam) );
1593 /* FIXME : should handle ToAscii yielding 2 */
1594 switch (ToAscii32(wParam, HIWORD(lParam),
1595 QueueKeyStateTable,(LPWORD)wp, 0))
1597 case 1 :
1598 message = (message == WM_KEYDOWN) ? WM_CHAR : WM_SYSCHAR;
1599 /* Should dead chars handling go in ToAscii ? */
1600 if (dead_char)
1602 int i;
1604 if (wp[0] == ' ') wp[0] = dead_char;
1605 if (dead_char == 0xa2) dead_char = '(';
1606 else if (dead_char == 0xa8) dead_char = '"';
1607 else if (dead_char == 0xb2) dead_char = ';';
1608 else if (dead_char == 0xb4) dead_char = '\'';
1609 else if (dead_char == 0xb7) dead_char = '<';
1610 else if (dead_char == 0xb8) dead_char = ',';
1611 else if (dead_char == 0xff) dead_char = '.';
1612 for (i = 0; i < sizeof(accent_chars)/sizeof(accent_chars[0]); i++)
1613 if ((accent_chars[i].ac_accent == dead_char) &&
1614 (accent_chars[i].ac_char == wp[0]))
1616 wp[0] = accent_chars[i].ac_result;
1617 break;
1619 dead_char = 0;
1621 TRACE(key, "1 -> PostMessage(%s)\n", SPY_GetMsgName(message));
1622 PostMessage16( hwnd, message, wp[0], lParam );
1623 return TRUE;
1625 case -1 :
1626 message = (message == WM_KEYDOWN) ? WM_DEADCHAR : WM_SYSDEADCHAR;
1627 dead_char = wp[0];
1628 TRACE(key, "-1 -> PostMessage(%s)\n",
1629 SPY_GetMsgName(message));
1630 PostMessage16( hwnd, message, wp[0], lParam );
1631 return TRUE;
1633 return FALSE;
1637 /***********************************************************************
1638 * TranslateMessage16 (USER.113)
1640 BOOL16 WINAPI TranslateMessage16( const MSG16 *msg )
1642 return MSG_DoTranslateMessage( msg->message, msg->hwnd,
1643 msg->wParam, msg->lParam );
1647 /***********************************************************************
1648 * TranslateMessage32 (USER32.556)
1650 BOOL32 WINAPI TranslateMessage32( const MSG32 *msg )
1652 return MSG_DoTranslateMessage( msg->message, msg->hwnd,
1653 msg->wParam, msg->lParam );
1657 /***********************************************************************
1658 * DispatchMessage16 (USER.114)
1660 LONG WINAPI DispatchMessage16( const MSG16* msg )
1662 WND * wndPtr;
1663 LONG retval;
1664 int painting;
1666 /* Process timer messages */
1667 if ((msg->message == WM_TIMER) || (msg->message == WM_SYSTIMER))
1669 if (msg->lParam)
1671 return CallWindowProc16( (WNDPROC16)msg->lParam, msg->hwnd,
1672 msg->message, msg->wParam, GetTickCount() );
1676 if (!msg->hwnd) return 0;
1677 if (!(wndPtr = WIN_FindWndPtr( msg->hwnd ))) return 0;
1678 if (!wndPtr->winproc) return 0;
1679 painting = (msg->message == WM_PAINT);
1680 if (painting) wndPtr->flags |= WIN_NEEDS_BEGINPAINT;
1682 SPY_EnterMessage( SPY_DISPATCHMESSAGE16, msg->hwnd, msg->message,
1683 msg->wParam, msg->lParam );
1684 retval = CallWindowProc16( (WNDPROC16)wndPtr->winproc,
1685 msg->hwnd, msg->message,
1686 msg->wParam, msg->lParam );
1687 SPY_ExitMessage( SPY_RESULT_OK16, msg->hwnd, msg->message, retval );
1689 if (painting && (wndPtr = WIN_FindWndPtr( msg->hwnd )) &&
1690 (wndPtr->flags & WIN_NEEDS_BEGINPAINT) && wndPtr->hrgnUpdate)
1692 ERR(msg, "BeginPaint not called on WM_PAINT for hwnd %04x!\n",
1693 msg->hwnd);
1694 wndPtr->flags &= ~WIN_NEEDS_BEGINPAINT;
1695 /* Validate the update region to avoid infinite WM_PAINT loop */
1696 ValidateRect32( msg->hwnd, NULL );
1698 return retval;
1702 /***********************************************************************
1703 * DispatchMessage32A (USER32.141)
1705 LONG WINAPI DispatchMessage32A( const MSG32* msg )
1707 WND * wndPtr;
1708 LONG retval;
1709 int painting;
1711 /* Process timer messages */
1712 if ((msg->message == WM_TIMER) || (msg->message == WM_SYSTIMER))
1714 if (msg->lParam)
1716 /* HOOK_CallHooks32A( WH_CALLWNDPROC, HC_ACTION, 0, FIXME ); */
1717 return CallWindowProc32A( (WNDPROC32)msg->lParam, msg->hwnd,
1718 msg->message, msg->wParam, GetTickCount() );
1722 if (!msg->hwnd) return 0;
1723 if (!(wndPtr = WIN_FindWndPtr( msg->hwnd ))) return 0;
1724 if (!wndPtr->winproc) return 0;
1725 painting = (msg->message == WM_PAINT);
1726 if (painting) wndPtr->flags |= WIN_NEEDS_BEGINPAINT;
1727 /* HOOK_CallHooks32A( WH_CALLWNDPROC, HC_ACTION, 0, FIXME ); */
1729 SPY_EnterMessage( SPY_DISPATCHMESSAGE32, msg->hwnd, msg->message,
1730 msg->wParam, msg->lParam );
1731 retval = CallWindowProc32A( (WNDPROC32)wndPtr->winproc,
1732 msg->hwnd, msg->message,
1733 msg->wParam, msg->lParam );
1734 SPY_ExitMessage( SPY_RESULT_OK32, msg->hwnd, msg->message, retval );
1736 if (painting && (wndPtr = WIN_FindWndPtr( msg->hwnd )) &&
1737 (wndPtr->flags & WIN_NEEDS_BEGINPAINT) && wndPtr->hrgnUpdate)
1739 ERR(msg, "BeginPaint not called on WM_PAINT for hwnd %04x!\n",
1740 msg->hwnd);
1741 wndPtr->flags &= ~WIN_NEEDS_BEGINPAINT;
1742 /* Validate the update region to avoid infinite WM_PAINT loop */
1743 ValidateRect32( msg->hwnd, NULL );
1745 return retval;
1749 /***********************************************************************
1750 * DispatchMessage32W (USER32.142)
1752 * Process the message specified in the structure *_msg_.
1754 * If the lpMsg parameter points to a WM_TIMER message and the
1755 * parameter of the WM_TIMER message is not NULL, the lParam parameter
1756 * points to the function that is called instead of the window
1757 * procedure.
1759 * The message must be valid.
1761 * RETURNS
1763 * DispatchMessage() returns the result of the window procedure invoked.
1765 * CONFORMANCE
1767 * ECMA-234, Win32
1770 LONG WINAPI DispatchMessage32W( const MSG32* msg )
1772 WND * wndPtr;
1773 LONG retval;
1774 int painting;
1776 /* Process timer messages */
1777 if ((msg->message == WM_TIMER) || (msg->message == WM_SYSTIMER))
1779 if (msg->lParam)
1781 /* HOOK_CallHooks32W( WH_CALLWNDPROC, HC_ACTION, 0, FIXME ); */
1782 return CallWindowProc32W( (WNDPROC32)msg->lParam, msg->hwnd,
1783 msg->message, msg->wParam, GetTickCount() );
1787 if (!msg->hwnd) return 0;
1788 if (!(wndPtr = WIN_FindWndPtr( msg->hwnd ))) return 0;
1789 if (!wndPtr->winproc) return 0;
1790 painting = (msg->message == WM_PAINT);
1791 if (painting) wndPtr->flags |= WIN_NEEDS_BEGINPAINT;
1792 /* HOOK_CallHooks32W( WH_CALLWNDPROC, HC_ACTION, 0, FIXME ); */
1794 SPY_EnterMessage( SPY_DISPATCHMESSAGE32, msg->hwnd, msg->message,
1795 msg->wParam, msg->lParam );
1796 retval = CallWindowProc32W( (WNDPROC32)wndPtr->winproc,
1797 msg->hwnd, msg->message,
1798 msg->wParam, msg->lParam );
1799 SPY_ExitMessage( SPY_RESULT_OK32, msg->hwnd, msg->message, retval );
1801 if (painting && (wndPtr = WIN_FindWndPtr( msg->hwnd )) &&
1802 (wndPtr->flags & WIN_NEEDS_BEGINPAINT) && wndPtr->hrgnUpdate)
1804 ERR(msg, "BeginPaint not called on WM_PAINT for hwnd %04x!\n",
1805 msg->hwnd);
1806 wndPtr->flags &= ~WIN_NEEDS_BEGINPAINT;
1807 /* Validate the update region to avoid infinite WM_PAINT loop */
1808 ValidateRect32( msg->hwnd, NULL );
1810 return retval;
1814 /***********************************************************************
1815 * RegisterWindowMessage16 (USER.118)
1817 WORD WINAPI RegisterWindowMessage16( SEGPTR str )
1819 TRACE(msg, "%08lx\n", (DWORD)str );
1820 return GlobalAddAtom16( str );
1824 /***********************************************************************
1825 * RegisterWindowMessage32A (USER32.437)
1827 WORD WINAPI RegisterWindowMessage32A( LPCSTR str )
1829 TRACE(msg, "%s\n", str );
1830 return GlobalAddAtom32A( str );
1834 /***********************************************************************
1835 * RegisterWindowMessage32W (USER32.438)
1837 WORD WINAPI RegisterWindowMessage32W( LPCWSTR str )
1839 TRACE(msg, "%p\n", str );
1840 return GlobalAddAtom32W( str );
1844 /***********************************************************************
1845 * GetTickCount (USER.13) (KERNEL32.299)
1847 DWORD WINAPI GetTickCount(void)
1849 struct timeval t;
1850 gettimeofday( &t, NULL );
1851 return ((t.tv_sec * 1000) + (t.tv_usec / 1000)) - MSG_WineStartTicks;
1855 /***********************************************************************
1856 * GetCurrentTime16 (USER.15)
1858 * (effectively identical to GetTickCount)
1860 DWORD WINAPI GetCurrentTime16(void)
1862 return GetTickCount();
1866 /***********************************************************************
1867 * InSendMessage16 (USER.192)
1869 BOOL16 WINAPI InSendMessage16(void)
1871 return InSendMessage32();
1875 /***********************************************************************
1876 * InSendMessage32 (USER32.320)
1878 BOOL32 WINAPI InSendMessage32(void)
1880 MESSAGEQUEUE *queue;
1882 if (!(queue = (MESSAGEQUEUE *)GlobalLock16( GetTaskQueue(0) )))
1883 return 0;
1884 return (BOOL32)queue->InSendMessageHandle;
1887 /***********************************************************************
1888 * BroadcastSystemMessage (USER32.12)
1890 LONG WINAPI BroadcastSystemMessage(
1891 DWORD dwFlags,LPDWORD recipients,UINT32 uMessage,WPARAM32 wParam,
1892 LPARAM lParam
1894 FIXME(sendmsg,"(%08lx,%08lx,%08x,%08x,%08lx): stub!\n",
1895 dwFlags,*recipients,uMessage,wParam,lParam
1897 return 0;
1900 /***********************************************************************
1901 * SendNotifyMessageA (USER32.460)
1902 * FIXME
1903 * The message sended with PostMessage has to be put in the queue
1904 * with a higher priority as the other "Posted" messages.
1905 * QUEUE_AddMsg has to be modifyed.
1907 LONG WINAPI SendNotifyMessage32A(HWND32 hwnd,UINT32 msg,WPARAM32 wParam,LPARAM lParam)
1908 { BOOL32 ret = TRUE;
1909 FIXME(msg,"(%04x,%08x,%08x,%08lx) not complete\n",
1910 hwnd, msg, wParam, lParam);
1912 if ( GetCurrentThreadId() == GetWindowThreadProcessId ( hwnd, NULL))
1913 { ret=SendMessage32A ( hwnd, msg, wParam, lParam );
1915 else
1916 { PostMessage32A ( hwnd, msg, wParam, lParam );
1918 return ret;
1920 /***********************************************************************
1921 * SendMessageCallBack32A
1922 * FIXME: It's like PostMessage. The callback gets called when the message
1923 * is processed. We have to modify the message processing for a exact
1924 * implementation...
1926 BOOL32 WINAPI SendMessageCallBack32A(
1927 HWND32 hWnd,UINT32 Msg,WPARAM32 wParam,LPARAM lParam,
1928 FARPROC32 lpResultCallBack,DWORD dwData)
1930 FIXME(msg,"(0x%04x,0x%04x,0x%08x,0x%08lx,%p,0x%08lx),stub!\n",
1931 hWnd,Msg,wParam,lParam,lpResultCallBack,dwData);
1932 if ( hWnd == HWND_BROADCAST)
1933 { PostMessage32A( hWnd, Msg, wParam, lParam);
1934 FIXME(msg,"Broadcast: Callback will not be called!\n");
1935 return TRUE;
1937 (lpResultCallBack)( hWnd, Msg, dwData, SendMessage32A ( hWnd, Msg, wParam, lParam ));
1938 return TRUE;