GetDiskFreeSpaceEx32A can get null pointers and still not crash.
[wine/testsucceed.git] / windows / message.c
blob5b4586ca7eff16b5fab0129070b8f2c0e9ec268c
1 /*
2 * Message queues related functions
4 * Copyright 1993, 1994 Alexandre Julliard
5 */
7 #include <stdlib.h>
8 #include <string.h>
9 #include <ctype.h>
10 #include <sys/time.h>
11 #include <sys/types.h>
13 #include "message.h"
14 #include "winerror.h"
15 #include "win.h"
16 #include "gdi.h"
17 #include "sysmetrics.h"
18 #include "heap.h"
19 #include "hook.h"
20 #include "input.h"
21 #include "spy.h"
22 #include "winpos.h"
23 #include "dde.h"
24 #include "queue.h"
25 #include "winproc.h"
26 #include "task.h"
27 #include "process.h"
28 #include "thread.h"
29 #include "options.h"
30 #include "struct32.h"
31 #include "debug.h"
33 #define WM_NCMOUSEFIRST WM_NCMOUSEMOVE
34 #define WM_NCMOUSELAST WM_NCMBUTTONDBLCLK
36 typedef enum { SYSQ_MSG_ABANDON, SYSQ_MSG_SKIP,
37 SYSQ_MSG_ACCEPT, SYSQ_MSG_CONTINUE } SYSQ_STATUS;
39 extern HQUEUE16 hCursorQueue; /* queue.c */
41 DWORD MSG_WineStartTicks; /* Ticks at Wine startup */
43 static UINT32 doubleClickSpeed = 452;
44 static INT32 debugSMRL = 0; /* intertask SendMessage() recursion level */
46 /***********************************************************************
47 * MSG_CheckFilter
49 BOOL32 MSG_CheckFilter(WORD uMsg, DWORD filter)
51 if( filter )
52 return (uMsg >= LOWORD(filter) && uMsg <= HIWORD(filter));
53 return TRUE;
56 /***********************************************************************
57 * MSG_SendParentNotify
59 * Send a WM_PARENTNOTIFY to all ancestors of the given window, unless
60 * the window has the WS_EX_NOPARENTNOTIFY style.
62 static void MSG_SendParentNotify(WND* wndPtr, WORD event, WORD idChild, LPARAM lValue)
64 #define lppt ((LPPOINT16)&lValue)
66 /* pt has to be in the client coordinates of the parent window */
68 MapWindowPoints16( 0, wndPtr->hwndSelf, lppt, 1 );
69 while (wndPtr)
71 if (!(wndPtr->dwStyle & WS_CHILD) || (wndPtr->dwExStyle & WS_EX_NOPARENTNOTIFY)) break;
72 lppt->x += wndPtr->rectClient.left;
73 lppt->y += wndPtr->rectClient.top;
74 wndPtr = wndPtr->parent;
75 SendMessage32A( wndPtr->hwndSelf, WM_PARENTNOTIFY,
76 MAKEWPARAM( event, idChild ), lValue );
78 #undef lppt
82 /***********************************************************************
83 * MSG_TranslateMouseMsg
85 * Translate an mouse hardware event into a real mouse message.
86 * Return value indicates whether the translated message must be passed
87 * to the user, left in the queue, or skipped entirely (in this case
88 * HIWORD contains hit test code).
90 static DWORD MSG_TranslateMouseMsg( HWND16 hTopWnd, DWORD filter,
91 MSG16 *msg, BOOL32 remove, WND* pWndScope )
93 static DWORD dblclk_time_limit = 0;
94 static UINT16 clk_message = 0;
95 static HWND16 clk_hwnd = 0;
96 static POINT16 clk_pos = { 0, 0 };
98 WND *pWnd;
99 HWND16 hWnd;
100 INT16 ht, hittest, sendSC = 0;
101 UINT16 message = msg->message;
102 POINT16 screen_pt, pt;
103 HANDLE16 hQ = GetFastQueue();
104 MESSAGEQUEUE *queue = (MESSAGEQUEUE *)QUEUE_Lock(hQ);
105 BOOL32 eatMsg = FALSE;
106 BOOL32 mouseClick = ((message == WM_LBUTTONDOWN) ||
107 (message == WM_RBUTTONDOWN) ||
108 (message == WM_MBUTTONDOWN))?1:0;
109 SYSQ_STATUS ret = 0;
111 /* Find the window */
113 ht = hittest = HTCLIENT;
114 hWnd = GetCapture16();
115 if( !hWnd )
117 ht = hittest = WINPOS_WindowFromPoint( pWndScope, msg->pt, &pWnd );
118 if( !pWnd ) pWnd = WIN_GetDesktop();
119 hWnd = pWnd->hwndSelf;
120 sendSC = 1;
122 else
124 pWnd = WIN_FindWndPtr(hWnd);
125 ht = EVENT_GetCaptureInfo();
128 /* stop if not the right queue */
130 if (pWnd->hmemTaskQ != hQ)
132 /* Not for the current task */
133 if (queue) QUEUE_ClearWakeBit( queue, QS_MOUSE );
134 /* Wake up the other task */
135 QUEUE_Unlock( queue );
136 queue = (MESSAGEQUEUE *)QUEUE_Lock( pWnd->hmemTaskQ );
137 if (queue) QUEUE_SetWakeBit( queue, QS_MOUSE );
139 QUEUE_Unlock( queue );
140 return SYSQ_MSG_ABANDON;
143 /* check if hWnd is within hWndScope */
145 if( hTopWnd && hWnd != hTopWnd )
146 if( !IsChild16(hTopWnd, hWnd) )
148 QUEUE_Unlock( queue );
149 return SYSQ_MSG_CONTINUE;
152 if( mouseClick )
154 /* translate double clicks -
155 * note that ...MOUSEMOVEs can slip in between
156 * ...BUTTONDOWN and ...BUTTONDBLCLK messages */
158 if( pWnd->class->style & CS_DBLCLKS || ht != HTCLIENT )
160 if ((message == clk_message) && (hWnd == clk_hwnd) &&
161 (msg->time - dblclk_time_limit < doubleClickSpeed) &&
162 (abs(msg->pt.x - clk_pos.x) < SYSMETRICS_CXDOUBLECLK/2) &&
163 (abs(msg->pt.y - clk_pos.y) < SYSMETRICS_CYDOUBLECLK/2))
165 message += (WM_LBUTTONDBLCLK - WM_LBUTTONDOWN);
166 mouseClick++; /* == 2 */
170 screen_pt = pt = msg->pt;
172 if (hittest != HTCLIENT)
174 message += ((INT16)WM_NCMOUSEMOVE - WM_MOUSEMOVE);
175 msg->wParam = hittest;
177 else ScreenToClient16( hWnd, &pt );
179 /* check message filter */
181 if (!MSG_CheckFilter(message, filter))
183 QUEUE_Unlock(queue);
184 return SYSQ_MSG_CONTINUE;
187 hCursorQueue = queue->self;
188 QUEUE_Unlock(queue);
190 /* call WH_MOUSE */
192 if (HOOK_IsHooked( WH_MOUSE ))
194 MOUSEHOOKSTRUCT16 *hook = SEGPTR_NEW(MOUSEHOOKSTRUCT16);
195 if( hook )
197 hook->pt = screen_pt;
198 hook->hwnd = hWnd;
199 hook->wHitTestCode = hittest;
200 hook->dwExtraInfo = 0;
201 ret = HOOK_CallHooks16( WH_MOUSE, remove ? HC_ACTION : HC_NOREMOVE,
202 message, (LPARAM)SEGPTR_GET(hook) );
203 SEGPTR_FREE(hook);
205 if( ret ) return MAKELONG((INT16)SYSQ_MSG_SKIP, hittest);
208 if ((hittest == HTERROR) || (hittest == HTNOWHERE))
209 eatMsg = sendSC = 1;
210 else if( remove && mouseClick )
212 HWND32 hwndTop = WIN_GetTopParent( hWnd );
214 if( mouseClick == 1 )
216 /* set conditions */
217 dblclk_time_limit = msg->time;
218 clk_message = msg->message;
219 clk_hwnd = hWnd;
220 clk_pos = screen_pt;
221 } else
222 /* got double click - zero them out */
223 dblclk_time_limit = clk_hwnd = 0;
225 if( sendSC )
227 /* Send the WM_PARENTNOTIFY,
228 * note that even for double/nonclient clicks
229 * notification message is still WM_L/M/RBUTTONDOWN.
232 MSG_SendParentNotify( pWnd, msg->message, 0, MAKELPARAM(screen_pt.x, screen_pt.y) );
234 /* Activate the window if needed */
236 if (hWnd != GetActiveWindow16() && hWnd != GetDesktopWindow16())
238 LONG ret = SendMessage16( hWnd, WM_MOUSEACTIVATE, hwndTop,
239 MAKELONG( hittest, message ) );
241 if ((ret == MA_ACTIVATEANDEAT) || (ret == MA_NOACTIVATEANDEAT))
242 eatMsg = TRUE;
244 if (((ret == MA_ACTIVATE) || (ret == MA_ACTIVATEANDEAT))
245 && hwndTop != GetActiveWindow16() )
246 if (!WINPOS_SetActiveWindow( hwndTop, TRUE , TRUE ))
247 eatMsg = TRUE;
250 } else sendSC = (remove && sendSC);
252 /* Send the WM_SETCURSOR message */
254 if (sendSC)
255 SendMessage16( hWnd, WM_SETCURSOR, (WPARAM16)hWnd,
256 MAKELONG( hittest, message ));
257 if (eatMsg) return MAKELONG( (UINT16)SYSQ_MSG_SKIP, hittest);
259 msg->hwnd = hWnd;
260 msg->message = message;
261 msg->lParam = MAKELONG( pt.x, pt.y );
262 return SYSQ_MSG_ACCEPT;
266 /***********************************************************************
267 * MSG_TranslateKbdMsg
269 * Translate an keyboard hardware event into a real message.
271 static DWORD MSG_TranslateKbdMsg( HWND16 hTopWnd, DWORD filter,
272 MSG16 *msg, BOOL32 remove )
274 WORD message = msg->message;
275 HWND16 hWnd = GetFocus16();
276 WND *pWnd;
278 /* Should check Ctrl-Esc and PrintScreen here */
280 if (!hWnd)
282 /* Send the message to the active window instead, */
283 /* translating messages to their WM_SYS equivalent */
285 hWnd = GetActiveWindow16();
287 if( message < WM_SYSKEYDOWN )
288 message += WM_SYSKEYDOWN - WM_KEYDOWN;
290 pWnd = WIN_FindWndPtr( hWnd );
291 if (pWnd && (pWnd->hmemTaskQ != GetFastQueue()))
293 /* Not for the current task */
294 MESSAGEQUEUE *queue = (MESSAGEQUEUE *)QUEUE_Lock( GetFastQueue() );
295 if (queue) QUEUE_ClearWakeBit( queue, QS_KEY );
296 QUEUE_Unlock( queue );
298 /* Wake up the other task */
299 queue = (MESSAGEQUEUE *)QUEUE_Lock( pWnd->hmemTaskQ );
300 if (queue) QUEUE_SetWakeBit( queue, QS_KEY );
301 QUEUE_Unlock( queue );
302 return SYSQ_MSG_ABANDON;
305 if (hTopWnd && hWnd != hTopWnd)
306 if (!IsChild16(hTopWnd, hWnd)) return SYSQ_MSG_CONTINUE;
307 if (!MSG_CheckFilter(message, filter)) return SYSQ_MSG_CONTINUE;
309 msg->hwnd = hWnd;
310 msg->message = message;
312 return (HOOK_CallHooks16( WH_KEYBOARD, remove ? HC_ACTION : HC_NOREMOVE,
313 msg->wParam, msg->lParam )
314 ? SYSQ_MSG_SKIP : SYSQ_MSG_ACCEPT);
318 /***********************************************************************
319 * MSG_JournalRecordMsg
321 * Build an EVENTMSG structure and call JOURNALRECORD hook
323 static void MSG_JournalRecordMsg( MSG16 *msg )
325 EVENTMSG16 *event = SEGPTR_NEW(EVENTMSG16);
326 if (!event) return;
327 event->message = msg->message;
328 event->time = msg->time;
329 if ((msg->message >= WM_KEYFIRST) && (msg->message <= WM_KEYLAST))
331 event->paramL = (msg->wParam & 0xFF) | (HIWORD(msg->lParam) << 8);
332 event->paramH = msg->lParam & 0x7FFF;
333 if (HIWORD(msg->lParam) & 0x0100)
334 event->paramH |= 0x8000; /* special_key - bit */
335 HOOK_CallHooks16( WH_JOURNALRECORD, HC_ACTION, 0,
336 (LPARAM)SEGPTR_GET(event) );
338 else if ((msg->message >= WM_MOUSEFIRST) && (msg->message <= WM_MOUSELAST))
340 event->paramL = LOWORD(msg->lParam); /* X pos */
341 event->paramH = HIWORD(msg->lParam); /* Y pos */
342 ClientToScreen16( msg->hwnd, (LPPOINT16)&event->paramL );
343 HOOK_CallHooks16( WH_JOURNALRECORD, HC_ACTION, 0,
344 (LPARAM)SEGPTR_GET(event) );
346 else if ((msg->message >= WM_NCMOUSEFIRST) &&
347 (msg->message <= WM_NCMOUSELAST))
349 event->paramL = LOWORD(msg->lParam); /* X pos */
350 event->paramH = HIWORD(msg->lParam); /* Y pos */
351 event->message += WM_MOUSEMOVE-WM_NCMOUSEMOVE;/* give no info about NC area */
352 HOOK_CallHooks16( WH_JOURNALRECORD, HC_ACTION, 0,
353 (LPARAM)SEGPTR_GET(event) );
355 SEGPTR_FREE(event);
358 /***********************************************************************
359 * MSG_JournalPlayBackMsg
361 * Get an EVENTMSG struct via call JOURNALPLAYBACK hook function
363 static int MSG_JournalPlayBackMsg(void)
365 EVENTMSG16 *tmpMsg;
366 long wtime,lParam;
367 WORD keyDown,i,wParam,result=0;
369 if ( HOOK_IsHooked( WH_JOURNALPLAYBACK ) )
371 tmpMsg = SEGPTR_NEW(EVENTMSG16);
372 wtime=HOOK_CallHooks16( WH_JOURNALPLAYBACK, HC_GETNEXT, 0,
373 (LPARAM)SEGPTR_GET(tmpMsg));
374 /* TRACE(msg,"Playback wait time =%ld\n",wtime); */
375 if (wtime<=0)
377 wtime=0;
378 if ((tmpMsg->message>= WM_KEYFIRST) && (tmpMsg->message <= WM_KEYLAST))
380 wParam=tmpMsg->paramL & 0xFF;
381 lParam=MAKELONG(tmpMsg->paramH&0x7ffff,tmpMsg->paramL>>8);
382 if (tmpMsg->message == WM_KEYDOWN || tmpMsg->message == WM_SYSKEYDOWN)
384 for (keyDown=i=0; i<256 && !keyDown; i++)
385 if (InputKeyStateTable[i] & 0x80)
386 keyDown++;
387 if (!keyDown)
388 lParam |= 0x40000000;
389 AsyncKeyStateTable[wParam]=InputKeyStateTable[wParam] |= 0x80;
391 else /* WM_KEYUP, WM_SYSKEYUP */
393 lParam |= 0xC0000000;
394 AsyncKeyStateTable[wParam]=InputKeyStateTable[wParam] &= ~0x80;
396 if (InputKeyStateTable[VK_MENU] & 0x80)
397 lParam |= 0x20000000;
398 if (tmpMsg->paramH & 0x8000) /*special_key bit*/
399 lParam |= 0x01000000;
400 hardware_event( tmpMsg->message, wParam, lParam,0, 0, tmpMsg->time, 0 );
402 else
404 if ((tmpMsg->message>= WM_MOUSEFIRST) && (tmpMsg->message <= WM_MOUSELAST))
406 switch (tmpMsg->message)
408 case WM_LBUTTONDOWN:
409 MouseButtonsStates[0]=AsyncMouseButtonsStates[0]=TRUE;break;
410 case WM_LBUTTONUP:
411 MouseButtonsStates[0]=AsyncMouseButtonsStates[0]=FALSE;break;
412 case WM_MBUTTONDOWN:
413 MouseButtonsStates[1]=AsyncMouseButtonsStates[1]=TRUE;break;
414 case WM_MBUTTONUP:
415 MouseButtonsStates[1]=AsyncMouseButtonsStates[1]=FALSE;break;
416 case WM_RBUTTONDOWN:
417 MouseButtonsStates[2]=AsyncMouseButtonsStates[2]=TRUE;break;
418 case WM_RBUTTONUP:
419 MouseButtonsStates[2]=AsyncMouseButtonsStates[2]=FALSE;break;
421 AsyncKeyStateTable[VK_LBUTTON]= InputKeyStateTable[VK_LBUTTON] = MouseButtonsStates[0] ? 0x80 : 0;
422 AsyncKeyStateTable[VK_MBUTTON]= InputKeyStateTable[VK_MBUTTON] = MouseButtonsStates[1] ? 0x80 : 0;
423 AsyncKeyStateTable[VK_RBUTTON]= InputKeyStateTable[VK_RBUTTON] = MouseButtonsStates[2] ? 0x80 : 0;
424 SetCursorPos32(tmpMsg->paramL,tmpMsg->paramH);
425 lParam=MAKELONG(tmpMsg->paramL,tmpMsg->paramH);
426 wParam=0;
427 if (MouseButtonsStates[0]) wParam |= MK_LBUTTON;
428 if (MouseButtonsStates[1]) wParam |= MK_MBUTTON;
429 if (MouseButtonsStates[2]) wParam |= MK_RBUTTON;
430 hardware_event( tmpMsg->message, wParam, lParam,
431 tmpMsg->paramL, tmpMsg->paramH, tmpMsg->time, 0 );
434 HOOK_CallHooks16( WH_JOURNALPLAYBACK, HC_SKIP, 0,
435 (LPARAM)SEGPTR_GET(tmpMsg));
437 else
439 if( tmpMsg->message == WM_QUEUESYNC )
440 if (HOOK_IsHooked( WH_CBT ))
441 HOOK_CallHooks16( WH_CBT, HCBT_QS, 0, 0L);
443 result= QS_MOUSE | QS_KEY; /* ? */
445 SEGPTR_FREE(tmpMsg);
447 return result;
450 /***********************************************************************
451 * MSG_PeekHardwareMsg
453 * Peek for a hardware message matching the hwnd and message filters.
455 static BOOL32 MSG_PeekHardwareMsg( MSG16 *msg, HWND16 hwnd, DWORD filter,
456 BOOL32 remove )
458 /* FIXME: should deal with MSG32 instead of MSG16 */
460 DWORD status = SYSQ_MSG_ACCEPT;
461 MESSAGEQUEUE *sysMsgQueue = QUEUE_GetSysQueue();
462 int kbd_msg;
463 QMSG *nextqmsg, *qmsg = sysMsgQueue->firstMsg;
465 /* FIXME: there has to be a better way to do this */
466 joySendMessages();
468 /* If the queue is empty, attempt to fill it */
469 if (!sysMsgQueue->msgCount && THREAD_IsWin16( THREAD_Current() )
470 && EVENT_Pending())
471 EVENT_WaitNetEvent( FALSE, FALSE );
473 for ( kbd_msg = 0; qmsg; qmsg = nextqmsg)
476 /* FIXME: this line will be reenabled when msg will be a MSG32 */
477 /* *msg = qmsg->msg; */
478 STRUCT32_MSG32to16(&qmsg->msg, msg);
480 nextqmsg = qmsg->nextMsg;
482 /* Translate message */
484 if ((msg->message >= WM_MOUSEFIRST) && (msg->message <= WM_MOUSELAST))
486 HWND32 hWndScope = (HWND32)qmsg->extraInfo;
488 status = MSG_TranslateMouseMsg(hwnd, filter, msg, remove,
489 (Options.managed && IsWindow32(hWndScope) )
490 ? WIN_FindWndPtr(hWndScope) : WIN_GetDesktop() );
491 kbd_msg = 0;
493 else if ((msg->message >= WM_KEYFIRST) && (msg->message <= WM_KEYLAST))
495 status = MSG_TranslateKbdMsg(hwnd, filter, msg, remove);
496 kbd_msg = 1;
498 else /* Non-standard hardware event */
500 HARDWAREHOOKSTRUCT16 *hook;
501 if ((hook = SEGPTR_NEW(HARDWAREHOOKSTRUCT16)))
503 BOOL32 ret;
504 hook->hWnd = msg->hwnd;
505 hook->wMessage = msg->message;
506 hook->wParam = msg->wParam;
507 hook->lParam = msg->lParam;
508 ret = HOOK_CallHooks16( WH_HARDWARE,
509 remove ? HC_ACTION : HC_NOREMOVE,
510 0, (LPARAM)SEGPTR_GET(hook) );
511 SEGPTR_FREE(hook);
512 if (ret)
514 QUEUE_RemoveMsg( sysMsgQueue, qmsg );
515 continue;
517 status = SYSQ_MSG_ACCEPT;
521 switch (LOWORD(status))
523 case SYSQ_MSG_ACCEPT:
524 break;
526 case SYSQ_MSG_SKIP:
527 if (HOOK_IsHooked( WH_CBT ))
529 if( kbd_msg )
530 HOOK_CallHooks16( WH_CBT, HCBT_KEYSKIPPED,
531 msg->wParam, msg->lParam );
532 else
534 MOUSEHOOKSTRUCT16 *hook = SEGPTR_NEW(MOUSEHOOKSTRUCT16);
535 if (hook)
537 hook->pt = msg->pt;
538 hook->hwnd = msg->hwnd;
539 hook->wHitTestCode = HIWORD(status);
540 hook->dwExtraInfo = 0;
541 HOOK_CallHooks16( WH_CBT, HCBT_CLICKSKIPPED ,msg->message,
542 (LPARAM)SEGPTR_GET(hook) );
543 SEGPTR_FREE(hook);
548 if (remove)
549 QUEUE_RemoveMsg( sysMsgQueue, qmsg );
550 /* continue */
552 case SYSQ_MSG_CONTINUE:
553 continue;
555 case SYSQ_MSG_ABANDON:
556 return FALSE;
559 if (remove)
561 if (HOOK_IsHooked( WH_JOURNALRECORD )) MSG_JournalRecordMsg( msg );
562 QUEUE_RemoveMsg( sysMsgQueue, qmsg );
564 return TRUE;
566 return FALSE;
571 /**********************************************************************
572 * SetDoubleClickTime16 (USER.20)
574 void WINAPI SetDoubleClickTime16( UINT16 interval )
576 SetDoubleClickTime32( interval );
580 /**********************************************************************
581 * SetDoubleClickTime32 (USER32.480)
583 BOOL32 WINAPI SetDoubleClickTime32( UINT32 interval )
585 doubleClickSpeed = interval ? interval : 500;
586 return TRUE;
590 /**********************************************************************
591 * GetDoubleClickTime16 (USER.21)
593 UINT16 WINAPI GetDoubleClickTime16(void)
595 return doubleClickSpeed;
599 /**********************************************************************
600 * GetDoubleClickTime32 (USER32.239)
602 UINT32 WINAPI GetDoubleClickTime32(void)
604 return doubleClickSpeed;
608 /***********************************************************************
609 * MSG_SendMessage
611 * Implementation of an inter-task SendMessage.
613 static LRESULT MSG_SendMessage( HQUEUE16 hDestQueue, HWND16 hwnd, UINT16 msg,
614 WPARAM32 wParam, LPARAM lParam, WORD flags )
616 INT32 prevSMRL = debugSMRL;
617 QSMCTRL qCtrl = { 0, 1};
618 MESSAGEQUEUE *queue, *destQ;
620 if (IsTaskLocked() || !IsWindow32(hwnd))
621 return 0;
623 if (!(queue = (MESSAGEQUEUE*)QUEUE_Lock( GetFastQueue() ))) return 0;
625 if (!(destQ = (MESSAGEQUEUE*)QUEUE_Lock( hDestQueue )))
627 QUEUE_Unlock( queue );
628 return 0;
631 debugSMRL+=4;
632 TRACE(sendmsg,"%*sSM: %s [%04x] (%04x -> %04x)\n",
633 prevSMRL, "", SPY_GetMsgName(msg), msg, queue->self, hDestQueue );
635 if( !(queue->wakeBits & QS_SMPARAMSFREE) )
637 TRACE(sendmsg,"\tIntertask SendMessage: sleeping since unreplied SendMessage pending\n");
638 QUEUE_WaitBits( QS_SMPARAMSFREE );
641 /* resume sending */
642 queue->hWnd32 = hwnd;
643 queue->msg32 = msg;
644 queue->wParam32 = wParam;
645 queue->lParam = lParam;
646 queue->hPrevSendingTask = destQ->hSendingTask;
647 destQ->hSendingTask = GetFastQueue();
649 QUEUE_ClearWakeBit( queue, QS_SMPARAMSFREE );
650 queue->flags = (queue->flags & ~(QUEUE_SM_WIN32|QUEUE_SM_UNICODE)) | flags;
652 TRACE(sendmsg,"%*ssm: smResultInit = %08x\n", prevSMRL, "", (unsigned)&qCtrl);
654 queue->smResultInit = &qCtrl;
656 QUEUE_SetWakeBit( destQ, QS_SENDMESSAGE );
658 /* perform task switch and wait for the result */
660 while( qCtrl.bPending )
662 if (!(queue->wakeBits & QS_SMRESULT))
664 if (THREAD_IsWin16( THREAD_Current() ))
665 DirectedYield( destQ->thdb->teb.htask16 );
666 QUEUE_WaitBits( QS_SMRESULT );
667 TRACE(sendmsg,"\tsm: have result!\n");
669 /* got something */
671 TRACE(sendmsg,"%*ssm: smResult = %08x\n", prevSMRL, "", (unsigned)queue->smResult );
673 if (queue->smResult) { /* FIXME, smResult should always be set */
674 queue->smResult->lResult = queue->SendMessageReturn;
675 queue->smResult->bPending = FALSE;
677 QUEUE_ClearWakeBit( queue, QS_SMRESULT );
679 if( queue->smResult != &qCtrl )
680 ERR(sendmsg, "%*ssm: weird scenes inside the goldmine!\n", prevSMRL, "");
682 queue->smResultInit = NULL;
684 TRACE(sendmsg,"%*sSM: [%04x] returning %08lx\n", prevSMRL, "", msg, qCtrl.lResult);
685 debugSMRL-=4;
687 QUEUE_Unlock( queue );
688 QUEUE_Unlock( destQ );
690 return qCtrl.lResult;
694 /***********************************************************************
695 * ReplyMessage16 (USER.115)
697 void WINAPI ReplyMessage16( LRESULT result )
699 MESSAGEQUEUE *senderQ;
700 MESSAGEQUEUE *queue;
702 if (!(queue = (MESSAGEQUEUE*)QUEUE_Lock( GetFastQueue() ))) return;
704 TRACE(msg,"ReplyMessage, queue %04x\n", queue->self);
706 while( (senderQ = (MESSAGEQUEUE*)QUEUE_Lock( queue->InSendMessageHandle)))
708 TRACE(msg,"\trpm: replying to %08x (%04x -> %04x)\n",
709 queue->msg32, queue->self, senderQ->self);
711 if( queue->wakeBits & QS_SENDMESSAGE )
713 QUEUE_ReceiveMessage( queue );
714 QUEUE_Unlock( senderQ );
715 continue; /* ReceiveMessage() already called us */
718 if(!(senderQ->wakeBits & QS_SMRESULT) ) break;
719 if (THREAD_IsWin16(THREAD_Current())) OldYield();
721 QUEUE_Unlock( senderQ );
723 if( !senderQ )
725 TRACE(msg,"\trpm: done\n");
726 QUEUE_Unlock( queue );
727 return;
730 senderQ->SendMessageReturn = result;
731 TRACE(msg,"\trpm: smResult = %08x, result = %08lx\n",
732 (unsigned)queue->smResultCurrent, result );
734 senderQ->smResult = queue->smResultCurrent;
735 queue->InSendMessageHandle = 0;
737 QUEUE_SetWakeBit( senderQ, QS_SMRESULT );
738 if (THREAD_IsWin16( THREAD_Current() ))
739 DirectedYield( senderQ->thdb->teb.htask16 );
741 QUEUE_Unlock( senderQ );
742 QUEUE_Unlock( queue );
746 /***********************************************************************
747 * MSG_PeekMessage
749 static BOOL32 MSG_PeekMessage( LPMSG16 msg, HWND16 hwnd, WORD first, WORD last,
750 WORD flags, BOOL32 peek )
752 int mask;
753 MESSAGEQUEUE *msgQueue;
754 HQUEUE16 hQueue;
756 #ifdef CONFIG_IPC
757 DDE_TestDDE(hwnd); /* do we have dde handling in the window ?*/
758 DDE_GetRemoteMessage();
759 #endif /* CONFIG_IPC */
761 mask = QS_POSTMESSAGE | QS_SENDMESSAGE; /* Always selected */
762 if (first || last)
764 if ((first <= WM_KEYLAST) && (last >= WM_KEYFIRST)) mask |= QS_KEY;
765 if ( ((first <= WM_MOUSELAST) && (last >= WM_MOUSEFIRST)) ||
766 ((first <= WM_NCMOUSELAST) && (last >= WM_NCMOUSEFIRST)) ) mask |= QS_MOUSE;
767 if ((first <= WM_TIMER) && (last >= WM_TIMER)) mask |= QS_TIMER;
768 if ((first <= WM_SYSTIMER) && (last >= WM_SYSTIMER)) mask |= QS_TIMER;
769 if ((first <= WM_PAINT) && (last >= WM_PAINT)) mask |= QS_PAINT;
771 else mask |= QS_MOUSE | QS_KEY | QS_TIMER | QS_PAINT;
773 if (IsTaskLocked()) flags |= PM_NOYIELD;
775 /* Never yield on Win32 threads */
776 if (!THREAD_IsWin16(THREAD_Current())) flags |= PM_NOYIELD;
778 while(1)
780 QMSG *qmsg;
782 hQueue = GetFastQueue();
783 msgQueue = (MESSAGEQUEUE *)QUEUE_Lock( hQueue );
784 if (!msgQueue) return FALSE;
785 msgQueue->changeBits = 0;
787 /* First handle a message put by SendMessage() */
789 while (msgQueue->wakeBits & QS_SENDMESSAGE)
790 QUEUE_ReceiveMessage( msgQueue );
792 /* Now handle a WM_QUIT message */
794 if (msgQueue->wPostQMsg &&
795 (!first || WM_QUIT >= first) &&
796 (!last || WM_QUIT <= last) )
798 msg->hwnd = hwnd;
799 msg->message = WM_QUIT;
800 msg->wParam = msgQueue->wExitCode;
801 msg->lParam = 0;
802 if (flags & PM_REMOVE) msgQueue->wPostQMsg = 0;
803 break;
806 /* Now find a normal message */
808 if (((msgQueue->wakeBits & mask) & QS_POSTMESSAGE) &&
809 ((qmsg = QUEUE_FindMsg( msgQueue, hwnd, first, last )) != 0))
811 /* FIXME: this line will be reenabled when msg will be a MSG32 */
812 /* *msg = qmsg->msg; */
813 STRUCT32_MSG32to16(&qmsg->msg, msg);
815 msgQueue->GetMessageTimeVal = msg->time;
816 msgQueue->GetMessagePosVal = *(DWORD *)&msg->pt;
817 msgQueue->GetMessageExtraInfoVal = qmsg->extraInfo;
819 if (flags & PM_REMOVE) QUEUE_RemoveMsg( msgQueue, qmsg );
820 break;
823 msgQueue->changeBits |= MSG_JournalPlayBackMsg();
825 /* Now find a hardware event */
827 if (((msgQueue->wakeBits & mask) & (QS_MOUSE | QS_KEY)) &&
828 MSG_PeekHardwareMsg( msg, hwnd, MAKELONG(first,last), flags & PM_REMOVE ))
830 /* Got one */
831 msgQueue->GetMessageTimeVal = msg->time;
832 msgQueue->GetMessagePosVal = *(DWORD *)&msg->pt;
833 msgQueue->GetMessageExtraInfoVal = 0; /* Always 0 for now */
834 break;
837 /* Check again for SendMessage */
839 while (msgQueue->wakeBits & QS_SENDMESSAGE)
840 QUEUE_ReceiveMessage( msgQueue );
842 /* Now find a WM_PAINT message */
844 if ((msgQueue->wakeBits & mask) & QS_PAINT)
846 WND* wndPtr;
847 msg->hwnd = WIN_FindWinToRepaint( hwnd , hQueue );
848 msg->message = WM_PAINT;
849 msg->wParam = 0;
850 msg->lParam = 0;
852 if ((wndPtr = WIN_FindWndPtr(msg->hwnd)))
854 if( wndPtr->dwStyle & WS_MINIMIZE &&
855 wndPtr->class->hIcon )
857 msg->message = WM_PAINTICON;
858 msg->wParam = 1;
861 if( !hwnd || msg->hwnd == hwnd || IsChild16(hwnd,msg->hwnd) )
863 if( wndPtr->flags & WIN_INTERNAL_PAINT && !wndPtr->hrgnUpdate)
865 wndPtr->flags &= ~WIN_INTERNAL_PAINT;
866 QUEUE_DecPaintCount( hQueue );
868 break;
873 /* Check for timer messages, but yield first */
875 if (!(flags & PM_NOYIELD))
877 UserYield();
878 while (msgQueue->wakeBits & QS_SENDMESSAGE)
879 QUEUE_ReceiveMessage( msgQueue );
881 if ((msgQueue->wakeBits & mask) & QS_TIMER)
883 if (TIMER_GetTimerMsg(msg, hwnd, hQueue, flags & PM_REMOVE)) break;
886 if (peek)
888 if (!(flags & PM_NOYIELD)) UserYield();
890 QUEUE_Unlock( msgQueue );
891 return FALSE;
893 msgQueue->wakeMask = mask;
894 QUEUE_WaitBits( mask );
895 QUEUE_Unlock( msgQueue );
898 /* instead of unlocking queue for every break condition, all break
899 condition will fall here */
900 QUEUE_Unlock( msgQueue );
902 /* We got a message */
903 if (flags & PM_REMOVE)
905 WORD message = msg->message;
907 if (message == WM_KEYDOWN || message == WM_SYSKEYDOWN)
909 BYTE *p = &QueueKeyStateTable[msg->wParam & 0xff];
911 if (!(*p & 0x80))
912 *p ^= 0x01;
913 *p |= 0x80;
915 else if (message == WM_KEYUP || message == WM_SYSKEYUP)
916 QueueKeyStateTable[msg->wParam & 0xff] &= ~0x80;
918 if (peek) return TRUE;
919 else return (msg->message != WM_QUIT);
923 /***********************************************************************
924 * MSG_InternalGetMessage
926 * GetMessage() function for internal use. Behave like GetMessage(),
927 * but also call message filters and optionally send WM_ENTERIDLE messages.
928 * 'hwnd' must be the handle of the dialog or menu window.
929 * 'code' is the message filter value (MSGF_??? codes).
931 BOOL32 MSG_InternalGetMessage( MSG16 *msg, HWND32 hwnd, HWND32 hwndOwner,
932 WPARAM32 code, WORD flags, BOOL32 sendIdle )
934 for (;;)
936 if (sendIdle)
938 if (!MSG_PeekMessage( msg, 0, 0, 0, flags, TRUE ))
940 /* No message present -> send ENTERIDLE and wait */
941 if (IsWindow32(hwndOwner))
942 SendMessage16( hwndOwner, WM_ENTERIDLE,
943 code, (LPARAM)hwnd );
944 MSG_PeekMessage( msg, 0, 0, 0, flags, FALSE );
947 else /* Always wait for a message */
948 MSG_PeekMessage( msg, 0, 0, 0, flags, FALSE );
950 /* Call message filters */
952 if (HOOK_IsHooked( WH_SYSMSGFILTER ) || HOOK_IsHooked( WH_MSGFILTER ))
954 MSG16 *pmsg = SEGPTR_NEW(MSG16);
955 if (pmsg)
957 BOOL32 ret;
958 *pmsg = *msg;
959 ret = ((BOOL16)HOOK_CallHooks16( WH_SYSMSGFILTER, code, 0,
960 (LPARAM)SEGPTR_GET(pmsg) ) ||
961 (BOOL16)HOOK_CallHooks16( WH_MSGFILTER, code, 0,
962 (LPARAM)SEGPTR_GET(pmsg) ));
963 SEGPTR_FREE(pmsg);
964 if (ret)
966 /* Message filtered -> remove it from the queue */
967 /* if it's still there. */
968 if (!(flags & PM_REMOVE))
969 MSG_PeekMessage( msg, 0, 0, 0, PM_REMOVE, TRUE );
970 continue;
975 return (msg->message != WM_QUIT);
980 /***********************************************************************
981 * PeekMessage16 (USER.109)
983 BOOL16 WINAPI PeekMessage16( LPMSG16 msg, HWND16 hwnd, UINT16 first,
984 UINT16 last, UINT16 flags )
986 return MSG_PeekMessage( msg, hwnd, first, last, flags, TRUE );
989 /***********************************************************************
990 * WIN16_PeekMessage32 (USER.819)
992 BOOL16 WINAPI WIN16_PeekMessage32( LPMSG16_32 lpmsg16_32, HWND16 hwnd,
993 UINT16 first, UINT16 last, UINT16 flags, BOOL16 wHaveParamHigh )
995 if (wHaveParamHigh == FALSE)
997 lpmsg16_32->wParamHigh = 0;
998 return PeekMessage16(&(lpmsg16_32->msg), hwnd, first, last, flags);
1000 else
1002 MSG32 msg32;
1003 BOOL16 ret;
1005 ret = (BOOL16)PeekMessage32A(&msg32, (HWND32)hwnd,
1006 (UINT32)first, (UINT32)last, (UINT32)flags);
1007 lpmsg16_32->msg.hwnd = msg32.hwnd;
1008 lpmsg16_32->msg.message = msg32.message;
1009 lpmsg16_32->msg.wParam = LOWORD(msg32.wParam);
1010 lpmsg16_32->msg.lParam = msg32.lParam;
1011 lpmsg16_32->msg.time = msg32.time;
1012 lpmsg16_32->msg.pt.x = (INT16)msg32.pt.x;
1013 lpmsg16_32->msg.pt.y = (INT16)msg32.pt.y;
1014 lpmsg16_32->wParamHigh = HIWORD(msg32.wParam);
1015 return ret;
1020 /***********************************************************************
1021 * PeekMessageA
1023 BOOL32 WINAPI PeekMessage32A( LPMSG32 lpmsg, HWND32 hwnd,
1024 UINT32 min,UINT32 max,UINT32 wRemoveMsg)
1026 MSG16 msg;
1027 BOOL32 ret;
1028 ret=PeekMessage16(&msg,hwnd,min,max,wRemoveMsg);
1029 /* FIXME: should translate the message to Win32 */
1030 STRUCT32_MSG16to32(&msg,lpmsg);
1031 return ret;
1034 /***********************************************************************
1035 * PeekMessageW Check queue for messages
1037 * Checks for a message in the thread's queue, filtered as for
1038 * GetMessage(). Returns immediately whether a message is available
1039 * or not.
1041 * Whether a retrieved message is removed from the queue is set by the
1042 * _wRemoveMsg_ flags, which should be one of the following values:
1044 * PM_NOREMOVE Do not remove the message from the queue.
1046 * PM_REMOVE Remove the message from the queue.
1048 * In addition, PM_NOYIELD may be combined into _wRemoveMsg_ to
1049 * request that the system not yield control during PeekMessage();
1050 * however applications may not rely on scheduling behavior.
1052 * RETURNS
1054 * Nonzero if a message is available and is retrieved, zero otherwise.
1056 * CONFORMANCE
1058 * ECMA-234, Win32
1061 BOOL32 WINAPI PeekMessage32W(
1062 LPMSG32 lpmsg, /* buffer to receive message */
1063 HWND32 hwnd, /* restrict to messages for hwnd */
1064 UINT32 min, /* minimum message to receive */
1065 UINT32 max, /* maximum message to receive */
1066 UINT32 wRemoveMsg /* removal flags */
1068 /* FIXME: Should perform Unicode translation on specific messages */
1069 return PeekMessage32A(lpmsg,hwnd,min,max,wRemoveMsg);
1072 /***********************************************************************
1073 * GetMessage16 (USER.108)
1075 BOOL16 WINAPI GetMessage16( SEGPTR msg, HWND16 hwnd, UINT16 first, UINT16 last)
1077 MSG16 *lpmsg = (MSG16 *)PTR_SEG_TO_LIN(msg);
1078 MSG_PeekMessage( lpmsg,
1079 hwnd, first, last, PM_REMOVE, FALSE );
1081 TRACE(msg,"message %04x, hwnd %04x, filter(%04x - %04x)\n", lpmsg->message,
1082 hwnd, first, last );
1083 HOOK_CallHooks16( WH_GETMESSAGE, HC_ACTION, 0, (LPARAM)msg );
1084 return (lpmsg->message != WM_QUIT);
1087 /***********************************************************************
1088 * WIN16_GetMessage32 (USER.820)
1090 BOOL16 WINAPI WIN16_GetMessage32( SEGPTR msg16_32, HWND16 hWnd, UINT16 first,
1091 UINT16 last, BOOL16 wHaveParamHigh )
1093 MSG16_32 *lpmsg16_32 = (MSG16_32 *)PTR_SEG_TO_LIN(msg16_32);
1095 if (wHaveParamHigh == FALSE) /* normal GetMessage16 call */
1098 lpmsg16_32->wParamHigh = 0; /* you never know... */
1099 /* WARNING: msg16_32->msg has to be the first variable in the struct */
1100 return GetMessage16(msg16_32, hWnd, first, last);
1102 else
1104 MSG32 msg32;
1105 BOOL16 ret;
1107 ret = (BOOL16)GetMessage32A(&msg32, hWnd, first, last);
1108 lpmsg16_32->msg.hwnd = msg32.hwnd;
1109 lpmsg16_32->msg.message = msg32.message;
1110 lpmsg16_32->msg.wParam = LOWORD(msg32.wParam);
1111 lpmsg16_32->msg.lParam = msg32.lParam;
1112 lpmsg16_32->msg.time = msg32.time;
1113 lpmsg16_32->msg.pt.x = (INT16)msg32.pt.x;
1114 lpmsg16_32->msg.pt.y = (INT16)msg32.pt.y;
1115 lpmsg16_32->wParamHigh = HIWORD(msg32.wParam);
1116 return ret;
1120 /***********************************************************************
1121 * GetMessage32A (USER32.270)
1123 BOOL32 WINAPI GetMessage32A(MSG32* lpmsg,HWND32 hwnd,UINT32 min,UINT32 max)
1125 BOOL32 ret;
1126 MSG16 *msg = SEGPTR_NEW(MSG16);
1127 if (!msg) return 0;
1128 ret=GetMessage16(SEGPTR_GET(msg),(HWND16)hwnd,min,max);
1129 /* FIXME */
1130 STRUCT32_MSG16to32(msg,lpmsg);
1131 SEGPTR_FREE(msg);
1132 return ret;
1135 /***********************************************************************
1136 * GetMessage32W (USER32.274) Retrieve next message
1138 * GetMessage retrieves the next event from the calling thread's
1139 * queue and deposits it in *lpmsg.
1141 * If _hwnd_ is not NULL, only messages for window _hwnd_ and its
1142 * children as specified by IsChild() are retrieved. If _hwnd_ is NULL
1143 * all application messages are retrieved.
1145 * _min_ and _max_ specify the range of messages of interest. If
1146 * min==max==0, no filtering is performed. Useful examples are
1147 * WM_KEYFIRST and WM_KEYLAST to retrieve keyboard input, and
1148 * WM_MOUSEFIRST and WM_MOUSELAST to retrieve mouse input.
1150 * WM_PAINT messages are not removed from the queue; they remain until
1151 * processed. Other messages are removed from the queue.
1153 * RETURNS
1155 * -1 on error, 0 if message is WM_QUIT, nonzero otherwise.
1157 * CONFORMANCE
1159 * ECMA-234, Win32
1162 BOOL32 WINAPI GetMessage32W(
1163 MSG32* lpmsg, /* buffer to receive message */
1164 HWND32 hwnd, /* restrict to messages for hwnd */
1165 UINT32 min, /* minimum message to receive */
1166 UINT32 max /* maximum message to receive */
1168 BOOL32 ret;
1169 MSG16 *msg = SEGPTR_NEW(MSG16);
1170 if (!msg) return 0;
1171 ret=GetMessage16(SEGPTR_GET(msg),(HWND16)hwnd,min,max);
1172 /* FIXME */
1173 STRUCT32_MSG16to32(msg,lpmsg);
1174 SEGPTR_FREE(msg);
1175 return ret;
1179 /***********************************************************************
1180 * PostMessage16 (USER.110)
1182 BOOL16 WINAPI PostMessage16( HWND16 hwnd, UINT16 message, WPARAM16 wParam,
1183 LPARAM lParam )
1185 MSG32 msg;
1186 WND *wndPtr;
1188 msg.hwnd = hwnd;
1189 msg.message = message;
1190 msg.wParam = wParam;
1191 msg.lParam = lParam;
1192 msg.time = GetTickCount();
1193 msg.pt.x = 0;
1194 msg.pt.y = 0;
1196 #ifdef CONFIG_IPC
1197 if (DDE_PostMessage(&msg))
1198 return TRUE;
1199 #endif /* CONFIG_IPC */
1201 if (hwnd == HWND_BROADCAST)
1203 TRACE(msg,"HWND_BROADCAST !\n");
1204 for (wndPtr = WIN_GetDesktop()->child; wndPtr; wndPtr = wndPtr->next)
1206 if (wndPtr->dwStyle & WS_POPUP || wndPtr->dwStyle & WS_CAPTION)
1208 TRACE(msg,"BROADCAST Message to hWnd=%04x m=%04X w=%04X l=%08lX !\n",
1209 wndPtr->hwndSelf, message, wParam, lParam);
1210 PostMessage16( wndPtr->hwndSelf, message, wParam, lParam );
1213 TRACE(msg,"End of HWND_BROADCAST !\n");
1214 return TRUE;
1217 wndPtr = WIN_FindWndPtr( hwnd );
1218 if (!wndPtr || !wndPtr->hmemTaskQ) return FALSE;
1220 return QUEUE_AddMsg( wndPtr->hmemTaskQ, &msg, 0 );
1224 /***********************************************************************
1225 * PostMessage32A (USER32.419)
1227 BOOL32 WINAPI PostMessage32A( HWND32 hwnd, UINT32 message, WPARAM32 wParam,
1228 LPARAM lParam )
1230 /* FIXME */
1231 if (message&0xffff0000)
1232 FIXME(msg,"message is truncated from %d to %d\n", message, message&0xffff);
1233 if (wParam&0xffff0000)
1234 FIXME(msg,"wParam is truncated from %d to %d\n", wParam, wParam&0xffff);
1235 return PostMessage16( hwnd, message, wParam, lParam );
1239 /***********************************************************************
1240 * PostMessage32W (USER32.420)
1242 BOOL32 WINAPI PostMessage32W( HWND32 hwnd, UINT32 message, WPARAM32 wParam,
1243 LPARAM lParam )
1245 /* FIXME */
1246 if (message&0xffff0000)
1247 FIXME(msg,"message is truncated from %d to %d\n", message, message&0xffff);
1248 if (wParam&0xffff0000)
1249 FIXME(msg,"wParam is truncated from %d to %d\n", wParam, wParam&0xffff);
1250 return PostMessage16( hwnd, message, wParam, lParam );
1254 /***********************************************************************
1255 * PostAppMessage16 (USER.116)
1257 BOOL16 WINAPI PostAppMessage16( HTASK16 hTask, UINT16 message, WPARAM16 wParam,
1258 LPARAM lParam )
1260 MSG32 msg;
1262 if (GetTaskQueue(hTask) == 0) return FALSE;
1263 msg.hwnd = 0;
1264 msg.message = message;
1265 msg.wParam = wParam;
1266 msg.lParam = lParam;
1267 msg.time = GetTickCount();
1268 msg.pt.x = 0;
1269 msg.pt.y = 0;
1271 return QUEUE_AddMsg( GetTaskQueue(hTask), &msg, 0 );
1275 /***********************************************************************
1276 * SendMessage16 (USER.111)
1278 LRESULT WINAPI SendMessage16( HWND16 hwnd, UINT16 msg, WPARAM16 wParam,
1279 LPARAM lParam)
1281 WND * wndPtr;
1282 WND **list, **ppWnd;
1283 LRESULT ret;
1285 #ifdef CONFIG_IPC
1286 MSG16 DDE_msg = { hwnd, msg, wParam, lParam };
1287 if (DDE_SendMessage(&DDE_msg)) return TRUE;
1288 #endif /* CONFIG_IPC */
1290 if (hwnd == HWND_BROADCAST)
1292 if (!(list = WIN_BuildWinArray( WIN_GetDesktop(), 0, NULL )))
1293 return TRUE;
1294 TRACE(msg,"HWND_BROADCAST !\n");
1295 for (ppWnd = list; *ppWnd; ppWnd++)
1297 wndPtr = *ppWnd;
1298 if (!IsWindow32(wndPtr->hwndSelf)) continue;
1299 if (wndPtr->dwStyle & WS_POPUP || wndPtr->dwStyle & WS_CAPTION)
1301 TRACE(msg,"BROADCAST Message to hWnd=%04x m=%04X w=%04lX l=%08lX !\n",
1302 wndPtr->hwndSelf, msg, (DWORD)wParam, lParam);
1303 SendMessage16( wndPtr->hwndSelf, msg, wParam, lParam );
1306 HeapFree( SystemHeap, 0, list );
1307 TRACE(msg,"End of HWND_BROADCAST !\n");
1308 return TRUE;
1311 if (HOOK_IsHooked( WH_CALLWNDPROC ))
1313 LPCWPSTRUCT16 pmsg;
1315 if ((pmsg = SEGPTR_NEW(CWPSTRUCT16)))
1317 pmsg->hwnd = hwnd;
1318 pmsg->message= msg;
1319 pmsg->wParam = wParam;
1320 pmsg->lParam = lParam;
1321 HOOK_CallHooks16( WH_CALLWNDPROC, HC_ACTION, 1,
1322 (LPARAM)SEGPTR_GET(pmsg) );
1323 hwnd = pmsg->hwnd;
1324 msg = pmsg->message;
1325 wParam = pmsg->wParam;
1326 lParam = pmsg->lParam;
1327 SEGPTR_FREE( pmsg );
1331 if (!(wndPtr = WIN_FindWndPtr( hwnd )))
1333 WARN(msg, "invalid hwnd %04x\n", hwnd );
1334 return 0;
1336 if (QUEUE_IsExitingQueue(wndPtr->hmemTaskQ))
1337 return 0; /* Don't send anything if the task is dying */
1339 SPY_EnterMessage( SPY_SENDMESSAGE16, hwnd, msg, wParam, lParam );
1341 if (wndPtr->hmemTaskQ != GetFastQueue())
1342 ret = MSG_SendMessage( wndPtr->hmemTaskQ, hwnd, msg,
1343 wParam, lParam, 0 );
1344 else
1345 ret = CallWindowProc16( (WNDPROC16)wndPtr->winproc,
1346 hwnd, msg, wParam, lParam );
1348 SPY_ExitMessage( SPY_RESULT_OK16, hwnd, msg, ret );
1349 return ret;
1352 /************************************************************************
1353 * MSG_CallWndProcHook32
1355 static void MSG_CallWndProcHook32( LPMSG32 pmsg, BOOL32 bUnicode )
1357 CWPSTRUCT32 cwp;
1359 cwp.lParam = pmsg->lParam;
1360 cwp.wParam = pmsg->wParam;
1361 cwp.message = pmsg->message;
1362 cwp.hwnd = pmsg->hwnd;
1364 if (bUnicode) HOOK_CallHooks32W(WH_CALLWNDPROC, HC_ACTION, 1, (LPARAM)&cwp);
1365 else HOOK_CallHooks32A( WH_CALLWNDPROC, HC_ACTION, 1, (LPARAM)&cwp );
1367 pmsg->lParam = cwp.lParam;
1368 pmsg->wParam = cwp.wParam;
1369 pmsg->message = cwp.message;
1370 pmsg->hwnd = cwp.hwnd;
1373 /**********************************************************************
1374 * PostThreadMessage32A (USER32.422)
1376 * BUGS
1378 * Thread-local message queues are not supported.
1381 BOOL32 WINAPI PostThreadMessage32A(DWORD idThread , UINT32 message,
1382 WPARAM32 wParam, LPARAM lParam )
1384 THDB *thdb = THREAD_ID_TO_THDB(idThread);
1385 if (!thdb || !thdb->process) return FALSE;
1387 FIXME(sendmsg, "(...): Should use thread-local message queue!\n");
1388 return PostAppMessage16(thdb->process->task, message, wParam, lParam);
1391 /**********************************************************************
1392 * PostThreadMessage32W (USER32.423)
1394 * BUGS
1396 * Thread-local message queues are not supported.
1399 BOOL32 WINAPI PostThreadMessage32W(DWORD idThread , UINT32 message,
1400 WPARAM32 wParam, LPARAM lParam )
1402 THDB *thdb = THREAD_ID_TO_THDB(idThread);
1403 if (!thdb || !thdb->process) return FALSE;
1405 FIXME(sendmsg, "(...): Should use thread-local message queue!\n");
1406 return PostAppMessage16(thdb->process->task, message, wParam, lParam);
1409 /***********************************************************************
1410 * SendMessage32A (USER32.454)
1412 LRESULT WINAPI SendMessage32A( HWND32 hwnd, UINT32 msg, WPARAM32 wParam,
1413 LPARAM lParam )
1415 WND * wndPtr;
1416 WND **list, **ppWnd;
1417 LRESULT ret;
1419 if (hwnd == HWND_BROADCAST || hwnd == HWND_TOPMOST)
1421 if (!(list = WIN_BuildWinArray( WIN_GetDesktop(), 0, NULL )))
1422 return TRUE;
1423 for (ppWnd = list; *ppWnd; ppWnd++)
1425 wndPtr = *ppWnd;
1426 if (!IsWindow32(wndPtr->hwndSelf)) continue;
1427 if (wndPtr->dwStyle & WS_POPUP || wndPtr->dwStyle & WS_CAPTION)
1428 SendMessage32A( wndPtr->hwndSelf, msg, wParam, lParam );
1430 HeapFree( SystemHeap, 0, list );
1431 return TRUE;
1434 if (HOOK_IsHooked( WH_CALLWNDPROC ))
1435 MSG_CallWndProcHook32( (LPMSG32)&hwnd, FALSE);
1437 if (!(wndPtr = WIN_FindWndPtr( hwnd )))
1439 WARN(msg, "invalid hwnd %08x\n", hwnd );
1440 return 0;
1443 if (QUEUE_IsExitingQueue(wndPtr->hmemTaskQ))
1444 return 0; /* Don't send anything if the task is dying */
1446 SPY_EnterMessage( SPY_SENDMESSAGE32, hwnd, msg, wParam, lParam );
1448 if (wndPtr->hmemTaskQ != GetFastQueue())
1449 ret = MSG_SendMessage( wndPtr->hmemTaskQ, hwnd, msg, wParam, lParam,
1450 QUEUE_SM_WIN32 );
1451 else
1452 ret = CallWindowProc32A( (WNDPROC32)wndPtr->winproc,
1453 hwnd, msg, wParam, lParam );
1455 SPY_ExitMessage( SPY_RESULT_OK32, hwnd, msg, ret );
1456 return ret;
1460 /***********************************************************************
1461 * SendMessage32W (USER32.459) Send Window Message
1463 * Sends a message to the window procedure of the specified window.
1464 * SendMessage() will not return until the called window procedure
1465 * either returns or calls ReplyMessage().
1467 * Use PostMessage() to send message and return immediately. A window
1468 * procedure may use InSendMessage() to detect
1469 * SendMessage()-originated messages.
1471 * Applications which communicate via HWND_BROADCAST may use
1472 * RegisterWindowMessage() to obtain a unique message to avoid conflicts
1473 * with other applications.
1475 * CONFORMANCE
1477 * ECMA-234, Win32
1479 LRESULT WINAPI SendMessage32W(
1480 HWND32 hwnd, /* Window to send message to. If HWND_BROADCAST,
1481 the message will be sent to all top-level windows. */
1483 UINT32 msg, /* message */
1484 WPARAM32 wParam, /* message parameter */
1485 LPARAM lParam /* additional message parameter */
1487 WND * wndPtr;
1488 WND **list, **ppWnd;
1489 LRESULT ret;
1491 if (hwnd == HWND_BROADCAST || hwnd == HWND_TOPMOST)
1493 if (!(list = WIN_BuildWinArray( WIN_GetDesktop(), 0, NULL )))
1494 return TRUE;
1495 for (ppWnd = list; *ppWnd; ppWnd++)
1497 wndPtr = *ppWnd;
1498 if (!IsWindow32(wndPtr->hwndSelf)) continue;
1499 if (wndPtr->dwStyle & WS_POPUP || wndPtr->dwStyle & WS_CAPTION)
1500 SendMessage32W( wndPtr->hwndSelf, msg, wParam, lParam );
1502 HeapFree( SystemHeap, 0, list );
1503 return TRUE;
1506 if (HOOK_IsHooked( WH_CALLWNDPROC ))
1507 MSG_CallWndProcHook32( (LPMSG32)&hwnd, TRUE);
1509 if (!(wndPtr = WIN_FindWndPtr( hwnd )))
1511 WARN(msg, "invalid hwnd %08x\n", hwnd );
1512 return 0;
1514 if (QUEUE_IsExitingQueue(wndPtr->hmemTaskQ))
1515 return 0; /* Don't send anything if the task is dying */
1517 SPY_EnterMessage( SPY_SENDMESSAGE32, hwnd, msg, wParam, lParam );
1519 if (wndPtr->hmemTaskQ != GetFastQueue())
1520 ret = MSG_SendMessage( wndPtr->hmemTaskQ, hwnd, msg, wParam, lParam,
1521 QUEUE_SM_WIN32 | QUEUE_SM_UNICODE );
1522 else
1523 ret = CallWindowProc32W( (WNDPROC32)wndPtr->winproc,
1524 hwnd, msg, wParam, lParam );
1526 SPY_ExitMessage( SPY_RESULT_OK32, hwnd, msg, ret );
1527 return ret;
1531 /***********************************************************************
1532 * SendMessageTimeout16 (not a WINAPI)
1534 LRESULT WINAPI SendMessageTimeout16( HWND16 hwnd, UINT16 msg, WPARAM16 wParam,
1535 LPARAM lParam, UINT16 flags,
1536 UINT16 timeout, LPWORD resultp)
1538 FIXME(sendmsg, "(...): semistub\n");
1539 return SendMessage16 (hwnd, msg, wParam, lParam);
1543 /***********************************************************************
1544 * SendMessageTimeout32A (USER32.457)
1546 LRESULT WINAPI SendMessageTimeout32A( HWND32 hwnd, UINT32 msg, WPARAM32 wParam,
1547 LPARAM lParam, UINT32 flags,
1548 UINT32 timeout, LPDWORD resultp)
1550 FIXME(sendmsg, "(...): semistub\n");
1551 return SendMessage32A (hwnd, msg, wParam, lParam);
1555 /***********************************************************************
1556 * SendMessageTimeout32W (USER32.458)
1558 LRESULT WINAPI SendMessageTimeout32W( HWND32 hwnd, UINT32 msg, WPARAM32 wParam,
1559 LPARAM lParam, UINT32 flags,
1560 UINT32 timeout, LPDWORD resultp)
1562 FIXME(sendmsg, "(...): semistub\n");
1563 return SendMessage32W (hwnd, msg, wParam, lParam);
1567 /***********************************************************************
1568 * WaitMessage (USER.112) (USER32.578) Suspend thread pending messages
1570 * WaitMessage() suspends a thread until events appear in the thread's
1571 * queue.
1573 * BUGS
1575 * Is supposed to return BOOL under Win32.
1577 * Thread-local message queues are not supported.
1579 * CONFORMANCE
1581 * ECMA-234, Win32
1584 void WINAPI WaitMessage( void )
1586 QUEUE_WaitBits( QS_ALLINPUT );
1589 /***********************************************************************
1590 * MsgWaitForMultipleObjects (USER32.400)
1592 DWORD WINAPI MsgWaitForMultipleObjects( DWORD nCount, HANDLE32 *pHandles,
1593 BOOL32 fWaitAll, DWORD dwMilliseconds,
1594 DWORD dwWakeMask )
1596 DWORD i;
1597 HANDLE32 handles[MAXIMUM_WAIT_OBJECTS];
1599 TDB *currTask = (TDB *)GlobalLock16( GetCurrentTask() );
1600 HQUEUE16 hQueue = currTask? currTask->hQueue : 0;
1601 MESSAGEQUEUE *msgQueue = (MESSAGEQUEUE *)QUEUE_Lock( hQueue );
1602 if (!msgQueue) return WAIT_FAILED;
1604 if (nCount > MAXIMUM_WAIT_OBJECTS-1)
1606 SetLastError( ERROR_INVALID_PARAMETER );
1607 QUEUE_Unlock( msgQueue );
1608 return WAIT_FAILED;
1611 msgQueue->changeBits = 0;
1612 msgQueue->wakeMask = dwWakeMask;
1614 QUEUE_Unlock( msgQueue );
1616 /* Add the thread event to the handle list */
1617 for (i = 0; i < nCount; i++) handles[i] = pHandles[i];
1618 handles[nCount] = currTask->thdb->event;
1619 return WaitForMultipleObjects( nCount+1, handles, fWaitAll, dwMilliseconds );
1624 struct accent_char
1626 BYTE ac_accent;
1627 BYTE ac_char;
1628 BYTE ac_result;
1631 static const struct accent_char accent_chars[] =
1633 /* A good idea should be to read /usr/X11/lib/X11/locale/iso8859-x/Compose */
1634 {'`', 'A', '\300'}, {'`', 'a', '\340'},
1635 {'\'', 'A', '\301'}, {'\'', 'a', '\341'},
1636 {'^', 'A', '\302'}, {'^', 'a', '\342'},
1637 {'~', 'A', '\303'}, {'~', 'a', '\343'},
1638 {'"', 'A', '\304'}, {'"', 'a', '\344'},
1639 {'O', 'A', '\305'}, {'o', 'a', '\345'},
1640 {'0', 'A', '\305'}, {'0', 'a', '\345'},
1641 {'A', 'A', '\305'}, {'a', 'a', '\345'},
1642 {'A', 'E', '\306'}, {'a', 'e', '\346'},
1643 {',', 'C', '\307'}, {',', 'c', '\347'},
1644 {'`', 'E', '\310'}, {'`', 'e', '\350'},
1645 {'\'', 'E', '\311'}, {'\'', 'e', '\351'},
1646 {'^', 'E', '\312'}, {'^', 'e', '\352'},
1647 {'"', 'E', '\313'}, {'"', 'e', '\353'},
1648 {'`', 'I', '\314'}, {'`', 'i', '\354'},
1649 {'\'', 'I', '\315'}, {'\'', 'i', '\355'},
1650 {'^', 'I', '\316'}, {'^', 'i', '\356'},
1651 {'"', 'I', '\317'}, {'"', 'i', '\357'},
1652 {'-', 'D', '\320'}, {'-', 'd', '\360'},
1653 {'~', 'N', '\321'}, {'~', 'n', '\361'},
1654 {'`', 'O', '\322'}, {'`', 'o', '\362'},
1655 {'\'', 'O', '\323'}, {'\'', 'o', '\363'},
1656 {'^', 'O', '\324'}, {'^', 'o', '\364'},
1657 {'~', 'O', '\325'}, {'~', 'o', '\365'},
1658 {'"', 'O', '\326'}, {'"', 'o', '\366'},
1659 {'/', 'O', '\330'}, {'/', 'o', '\370'},
1660 {'`', 'U', '\331'}, {'`', 'u', '\371'},
1661 {'\'', 'U', '\332'}, {'\'', 'u', '\372'},
1662 {'^', 'U', '\333'}, {'^', 'u', '\373'},
1663 {'"', 'U', '\334'}, {'"', 'u', '\374'},
1664 {'\'', 'Y', '\335'}, {'\'', 'y', '\375'},
1665 {'T', 'H', '\336'}, {'t', 'h', '\376'},
1666 {'s', 's', '\337'}, {'"', 'y', '\377'},
1667 {'s', 'z', '\337'}, {'i', 'j', '\377'},
1668 /* iso-8859-2 uses this */
1669 {'<', 'L', '\245'}, {'<', 'l', '\265'}, /* caron */
1670 {'<', 'S', '\251'}, {'<', 's', '\271'},
1671 {'<', 'T', '\253'}, {'<', 't', '\273'},
1672 {'<', 'Z', '\256'}, {'<', 'z', '\276'},
1673 {'<', 'C', '\310'}, {'<', 'c', '\350'},
1674 {'<', 'E', '\314'}, {'<', 'e', '\354'},
1675 {'<', 'D', '\317'}, {'<', 'd', '\357'},
1676 {'<', 'N', '\322'}, {'<', 'n', '\362'},
1677 {'<', 'R', '\330'}, {'<', 'r', '\370'},
1678 {';', 'A', '\241'}, {';', 'a', '\261'}, /* ogonek */
1679 {';', 'E', '\312'}, {';', 'e', '\332'},
1680 {'\'', 'Z', '\254'}, {'\'', 'z', '\274'}, /* acute */
1681 {'\'', 'R', '\300'}, {'\'', 'r', '\340'},
1682 {'\'', 'L', '\305'}, {'\'', 'l', '\345'},
1683 {'\'', 'C', '\306'}, {'\'', 'c', '\346'},
1684 {'\'', 'N', '\321'}, {'\'', 'n', '\361'},
1685 /* collision whith S, from iso-8859-9 !!! */
1686 {',', 'S', '\252'}, {',', 's', '\272'}, /* cedilla */
1687 {',', 'T', '\336'}, {',', 't', '\376'},
1688 {'.', 'Z', '\257'}, {'.', 'z', '\277'}, /* dot above */
1689 {'/', 'L', '\243'}, {'/', 'l', '\263'}, /* slash */
1690 {'/', 'D', '\320'}, {'/', 'd', '\360'},
1691 {'(', 'A', '\303'}, {'(', 'a', '\343'}, /* breve */
1692 {'\275', 'O', '\325'}, {'\275', 'o', '\365'}, /* double acute */
1693 {'\275', 'U', '\334'}, {'\275', 'u', '\374'},
1694 {'0', 'U', '\332'}, {'0', 'u', '\372'}, /* ring above */
1695 /* iso-8859-3 uses this */
1696 {'/', 'H', '\241'}, {'/', 'h', '\261'}, /* slash */
1697 {'>', 'H', '\246'}, {'>', 'h', '\266'}, /* circumflex */
1698 {'>', 'J', '\254'}, {'>', 'j', '\274'},
1699 {'>', 'C', '\306'}, {'>', 'c', '\346'},
1700 {'>', 'G', '\330'}, {'>', 'g', '\370'},
1701 {'>', 'S', '\336'}, {'>', 's', '\376'},
1702 /* collision whith G( from iso-8859-9 !!! */
1703 {'(', 'G', '\253'}, {'(', 'g', '\273'}, /* breve */
1704 {'(', 'U', '\335'}, {'(', 'u', '\375'},
1705 /* collision whith I. from iso-8859-3 !!! */
1706 {'.', 'I', '\251'}, {'.', 'i', '\271'}, /* dot above */
1707 {'.', 'C', '\305'}, {'.', 'c', '\345'},
1708 {'.', 'G', '\325'}, {'.', 'g', '\365'},
1709 /* iso-8859-4 uses this */
1710 {',', 'R', '\243'}, {',', 'r', '\263'}, /* cedilla */
1711 {',', 'L', '\246'}, {',', 'l', '\266'},
1712 {',', 'G', '\253'}, {',', 'g', '\273'},
1713 {',', 'N', '\321'}, {',', 'n', '\361'},
1714 {',', 'K', '\323'}, {',', 'k', '\363'},
1715 {'~', 'I', '\245'}, {'~', 'i', '\265'}, /* tilde */
1716 {'-', 'E', '\252'}, {'-', 'e', '\272'}, /* macron */
1717 {'-', 'A', '\300'}, {'-', 'a', '\340'},
1718 {'-', 'I', '\317'}, {'-', 'i', '\357'},
1719 {'-', 'O', '\322'}, {'-', 'o', '\362'},
1720 {'-', 'U', '\336'}, {'-', 'u', '\376'},
1721 {'/', 'T', '\254'}, {'/', 't', '\274'}, /* slash */
1722 {'.', 'E', '\314'}, {'.', 'e', '\344'}, /* dot above */
1723 {';', 'I', '\307'}, {';', 'i', '\347'}, /* ogonek */
1724 {';', 'U', '\331'}, {';', 'u', '\371'},
1725 /* iso-8859-9 uses this */
1726 /* iso-8859-9 has really bad choosen G( S, and I. as they collide
1727 * whith the same letters on other iso-8859-x (that is they are on
1728 * different places :-( ), if you use turkish uncomment these and
1729 * comment out the lines in iso-8859-2 and iso-8859-3 sections
1730 * FIXME: should be dynamic according to chosen language
1731 * if/when Wine has turkish support.
1733 /* collision whith G( from iso-8859-3 !!! */
1734 /* {'(', 'G', '\320'}, {'(', 'g', '\360'}, */ /* breve */
1735 /* collision whith S, from iso-8859-2 !!! */
1736 /* {',', 'S', '\336'}, {',', 's', '\376'}, */ /* cedilla */
1737 /* collision whith I. from iso-8859-3 !!! */
1738 /* {'.', 'I', '\335'}, {'.', 'i', '\375'}, */ /* dot above */
1742 /***********************************************************************
1743 * MSG_DoTranslateMessage
1745 * Implementation of TranslateMessage.
1747 * TranslateMessage translates virtual-key messages into character-messages,
1748 * as follows :
1749 * WM_KEYDOWN/WM_KEYUP combinations produce a WM_CHAR or WM_DEADCHAR message.
1750 * ditto replacing WM_* with WM_SYS*
1751 * This produces WM_CHAR messages only for keys mapped to ASCII characters
1752 * by the keyboard driver.
1754 static BOOL32 MSG_DoTranslateMessage( UINT32 message, HWND32 hwnd,
1755 WPARAM32 wParam, LPARAM lParam )
1757 static int dead_char;
1758 BYTE wp[2];
1760 if (message != WM_MOUSEMOVE && message != WM_TIMER)
1761 TRACE(msg, "(%s, %04X, %08lX)\n",
1762 SPY_GetMsgName(message), wParam, lParam );
1763 if(message >= WM_KEYFIRST && message <= WM_KEYLAST)
1764 TRACE(key, "(%s, %04X, %08lX)\n",
1765 SPY_GetMsgName(message), wParam, lParam );
1767 if ((message != WM_KEYDOWN) && (message != WM_SYSKEYDOWN)) return FALSE;
1769 TRACE(key, "Translating key %04X, scancode %04X\n",
1770 wParam, HIWORD(lParam) );
1772 /* FIXME : should handle ToAscii yielding 2 */
1773 switch (ToAscii32(wParam, HIWORD(lParam),
1774 QueueKeyStateTable,(LPWORD)wp, 0))
1776 case 1 :
1777 message = (message == WM_KEYDOWN) ? WM_CHAR : WM_SYSCHAR;
1778 /* Should dead chars handling go in ToAscii ? */
1779 if (dead_char)
1781 int i;
1783 if (wp[0] == ' ') wp[0] = dead_char;
1784 if (dead_char == 0xa2) dead_char = '(';
1785 else if (dead_char == 0xa8) dead_char = '"';
1786 else if (dead_char == 0xb2) dead_char = ';';
1787 else if (dead_char == 0xb4) dead_char = '\'';
1788 else if (dead_char == 0xb7) dead_char = '<';
1789 else if (dead_char == 0xb8) dead_char = ',';
1790 else if (dead_char == 0xff) dead_char = '.';
1791 for (i = 0; i < sizeof(accent_chars)/sizeof(accent_chars[0]); i++)
1792 if ((accent_chars[i].ac_accent == dead_char) &&
1793 (accent_chars[i].ac_char == wp[0]))
1795 wp[0] = accent_chars[i].ac_result;
1796 break;
1798 dead_char = 0;
1800 TRACE(key, "1 -> PostMessage(%s)\n", SPY_GetMsgName(message));
1801 PostMessage16( hwnd, message, wp[0], lParam );
1802 return TRUE;
1804 case -1 :
1805 message = (message == WM_KEYDOWN) ? WM_DEADCHAR : WM_SYSDEADCHAR;
1806 dead_char = wp[0];
1807 TRACE(key, "-1 -> PostMessage(%s)\n",
1808 SPY_GetMsgName(message));
1809 PostMessage16( hwnd, message, wp[0], lParam );
1810 return TRUE;
1812 return FALSE;
1816 /***********************************************************************
1817 * TranslateMessage16 (USER.113)
1819 BOOL16 WINAPI TranslateMessage16( const MSG16 *msg )
1821 return MSG_DoTranslateMessage( msg->message, msg->hwnd,
1822 msg->wParam, msg->lParam );
1826 /***********************************************************************
1827 * WIN16_TranslateMessage32 (USER.821)
1829 BOOL16 WINAPI WIN16_TranslateMessage32( const MSG16_32 *msg, BOOL16 wHaveParamHigh )
1831 WPARAM32 wParam;
1833 if (wHaveParamHigh)
1834 wParam = MAKELONG(msg->msg.wParam, msg->wParamHigh);
1835 else
1836 wParam = (WPARAM32)msg->msg.wParam;
1838 return MSG_DoTranslateMessage( msg->msg.message, msg->msg.hwnd,
1839 wParam, msg->msg.lParam );
1842 /***********************************************************************
1843 * TranslateMessage32 (USER32.556)
1845 BOOL32 WINAPI TranslateMessage32( const MSG32 *msg )
1847 return MSG_DoTranslateMessage( msg->message, msg->hwnd,
1848 msg->wParam, msg->lParam );
1852 /***********************************************************************
1853 * DispatchMessage16 (USER.114)
1855 LONG WINAPI DispatchMessage16( const MSG16* msg )
1857 WND * wndPtr;
1858 LONG retval;
1859 int painting;
1861 /* Process timer messages */
1862 if ((msg->message == WM_TIMER) || (msg->message == WM_SYSTIMER))
1864 if (msg->lParam)
1866 return CallWindowProc16( (WNDPROC16)msg->lParam, msg->hwnd,
1867 msg->message, msg->wParam, GetTickCount() );
1871 if (!msg->hwnd) return 0;
1872 if (!(wndPtr = WIN_FindWndPtr( msg->hwnd ))) return 0;
1873 if (!wndPtr->winproc) return 0;
1874 painting = (msg->message == WM_PAINT);
1875 if (painting) wndPtr->flags |= WIN_NEEDS_BEGINPAINT;
1877 SPY_EnterMessage( SPY_DISPATCHMESSAGE16, msg->hwnd, msg->message,
1878 msg->wParam, msg->lParam );
1879 retval = CallWindowProc16( (WNDPROC16)wndPtr->winproc,
1880 msg->hwnd, msg->message,
1881 msg->wParam, msg->lParam );
1882 SPY_ExitMessage( SPY_RESULT_OK16, msg->hwnd, msg->message, retval );
1884 if (painting && (wndPtr = WIN_FindWndPtr( msg->hwnd )) &&
1885 (wndPtr->flags & WIN_NEEDS_BEGINPAINT) && wndPtr->hrgnUpdate)
1887 ERR(msg, "BeginPaint not called on WM_PAINT for hwnd %04x!\n",
1888 msg->hwnd);
1889 wndPtr->flags &= ~WIN_NEEDS_BEGINPAINT;
1890 /* Validate the update region to avoid infinite WM_PAINT loop */
1891 ValidateRect32( msg->hwnd, NULL );
1893 return retval;
1897 /***********************************************************************
1898 * WIN16_DispatchMessage32 (USER.822)
1900 LONG WINAPI WIN16_DispatchMessage32( const MSG16_32* lpmsg16_32, BOOL16 wHaveParamHigh )
1902 if (wHaveParamHigh == FALSE)
1903 return DispatchMessage16(&(lpmsg16_32->msg));
1904 else
1906 MSG32 msg;
1908 msg.hwnd = lpmsg16_32->msg.hwnd;
1909 msg.message = lpmsg16_32->msg.message;
1910 msg.wParam = MAKELONG(lpmsg16_32->msg.wParam, lpmsg16_32->wParamHigh);
1911 msg.lParam = lpmsg16_32->msg.lParam;
1912 msg.time = lpmsg16_32->msg.time;
1913 msg.pt.x = (INT32)lpmsg16_32->msg.pt.x;
1914 msg.pt.y = (INT32)lpmsg16_32->msg.pt.y;
1915 return DispatchMessage32A(&msg);
1919 /***********************************************************************
1920 * DispatchMessage32A (USER32.141)
1922 LONG WINAPI DispatchMessage32A( const MSG32* msg )
1924 WND * wndPtr;
1925 LONG retval;
1926 int painting;
1928 /* Process timer messages */
1929 if ((msg->message == WM_TIMER) || (msg->message == WM_SYSTIMER))
1931 if (msg->lParam)
1933 /* HOOK_CallHooks32A( WH_CALLWNDPROC, HC_ACTION, 0, FIXME ); */
1934 return CallWindowProc32A( (WNDPROC32)msg->lParam, msg->hwnd,
1935 msg->message, msg->wParam, GetTickCount() );
1939 if (!msg->hwnd) return 0;
1940 if (!(wndPtr = WIN_FindWndPtr( msg->hwnd ))) return 0;
1941 if (!wndPtr->winproc) return 0;
1942 painting = (msg->message == WM_PAINT);
1943 if (painting) wndPtr->flags |= WIN_NEEDS_BEGINPAINT;
1944 /* HOOK_CallHooks32A( WH_CALLWNDPROC, HC_ACTION, 0, FIXME ); */
1946 SPY_EnterMessage( SPY_DISPATCHMESSAGE32, msg->hwnd, msg->message,
1947 msg->wParam, msg->lParam );
1948 retval = CallWindowProc32A( (WNDPROC32)wndPtr->winproc,
1949 msg->hwnd, msg->message,
1950 msg->wParam, msg->lParam );
1951 SPY_ExitMessage( SPY_RESULT_OK32, msg->hwnd, msg->message, retval );
1953 if (painting && (wndPtr = WIN_FindWndPtr( msg->hwnd )) &&
1954 (wndPtr->flags & WIN_NEEDS_BEGINPAINT) && wndPtr->hrgnUpdate)
1956 ERR(msg, "BeginPaint not called on WM_PAINT for hwnd %04x!\n",
1957 msg->hwnd);
1958 wndPtr->flags &= ~WIN_NEEDS_BEGINPAINT;
1959 /* Validate the update region to avoid infinite WM_PAINT loop */
1960 ValidateRect32( msg->hwnd, NULL );
1962 return retval;
1966 /***********************************************************************
1967 * DispatchMessage32W (USER32.142) Process Message
1969 * Process the message specified in the structure *_msg_.
1971 * If the lpMsg parameter points to a WM_TIMER message and the
1972 * parameter of the WM_TIMER message is not NULL, the lParam parameter
1973 * points to the function that is called instead of the window
1974 * procedure.
1976 * The message must be valid.
1978 * RETURNS
1980 * DispatchMessage() returns the result of the window procedure invoked.
1982 * CONFORMANCE
1984 * ECMA-234, Win32
1987 LONG WINAPI DispatchMessage32W( const MSG32* msg )
1989 WND * wndPtr;
1990 LONG retval;
1991 int painting;
1993 /* Process timer messages */
1994 if ((msg->message == WM_TIMER) || (msg->message == WM_SYSTIMER))
1996 if (msg->lParam)
1998 /* HOOK_CallHooks32W( WH_CALLWNDPROC, HC_ACTION, 0, FIXME ); */
1999 return CallWindowProc32W( (WNDPROC32)msg->lParam, msg->hwnd,
2000 msg->message, msg->wParam, GetTickCount() );
2004 if (!msg->hwnd) return 0;
2005 if (!(wndPtr = WIN_FindWndPtr( msg->hwnd ))) return 0;
2006 if (!wndPtr->winproc) return 0;
2007 painting = (msg->message == WM_PAINT);
2008 if (painting) wndPtr->flags |= WIN_NEEDS_BEGINPAINT;
2009 /* HOOK_CallHooks32W( WH_CALLWNDPROC, HC_ACTION, 0, FIXME ); */
2011 SPY_EnterMessage( SPY_DISPATCHMESSAGE32, msg->hwnd, msg->message,
2012 msg->wParam, msg->lParam );
2013 retval = CallWindowProc32W( (WNDPROC32)wndPtr->winproc,
2014 msg->hwnd, msg->message,
2015 msg->wParam, msg->lParam );
2016 SPY_ExitMessage( SPY_RESULT_OK32, msg->hwnd, msg->message, retval );
2018 if (painting && (wndPtr = WIN_FindWndPtr( msg->hwnd )) &&
2019 (wndPtr->flags & WIN_NEEDS_BEGINPAINT) && wndPtr->hrgnUpdate)
2021 ERR(msg, "BeginPaint not called on WM_PAINT for hwnd %04x!\n",
2022 msg->hwnd);
2023 wndPtr->flags &= ~WIN_NEEDS_BEGINPAINT;
2024 /* Validate the update region to avoid infinite WM_PAINT loop */
2025 ValidateRect32( msg->hwnd, NULL );
2027 return retval;
2031 /***********************************************************************
2032 * RegisterWindowMessage16 (USER.118)
2034 WORD WINAPI RegisterWindowMessage16( SEGPTR str )
2036 TRACE(msg, "%08lx\n", (DWORD)str );
2037 return GlobalAddAtom16( str );
2041 /***********************************************************************
2042 * RegisterWindowMessage32A (USER32.437)
2044 WORD WINAPI RegisterWindowMessage32A( LPCSTR str )
2046 TRACE(msg, "%s\n", str );
2047 return GlobalAddAtom32A( str );
2051 /***********************************************************************
2052 * RegisterWindowMessage32W (USER32.438)
2054 WORD WINAPI RegisterWindowMessage32W( LPCWSTR str )
2056 TRACE(msg, "%p\n", str );
2057 return GlobalAddAtom32W( str );
2061 /***********************************************************************
2062 * GetTickCount (USER.13) (KERNEL32.299) System Time
2063 * Returns the number of milliseconds, modulo 2^32, since the start
2064 * of the current session.
2066 * CONFORMANCE
2068 * ECMA-234, Win32
2070 DWORD WINAPI GetTickCount(void)
2072 struct timeval t;
2073 gettimeofday( &t, NULL );
2074 /* make extremely compatible: granularity is 25 msec */
2075 return ((t.tv_sec * 1000) + (t.tv_usec / 25000) * 25) - MSG_WineStartTicks;
2079 /***********************************************************************
2080 * GetCurrentTime16 (USER.15)
2082 * (effectively identical to GetTickCount)
2084 DWORD WINAPI GetCurrentTime16(void)
2086 return GetTickCount();
2090 /***********************************************************************
2091 * InSendMessage16 (USER.192)
2093 BOOL16 WINAPI InSendMessage16(void)
2095 return InSendMessage32();
2099 /***********************************************************************
2100 * InSendMessage32 (USER32.320)
2102 BOOL32 WINAPI InSendMessage32(void)
2104 MESSAGEQUEUE *queue;
2105 BOOL32 ret;
2107 if (!(queue = (MESSAGEQUEUE *)QUEUE_Lock( GetFastQueue() )))
2108 return 0;
2109 ret = (BOOL32)queue->InSendMessageHandle;
2111 QUEUE_Unlock( queue );
2112 return ret;
2115 /***********************************************************************
2116 * BroadcastSystemMessage (USER32.12)
2118 LONG WINAPI BroadcastSystemMessage(
2119 DWORD dwFlags,LPDWORD recipients,UINT32 uMessage,WPARAM32 wParam,
2120 LPARAM lParam
2122 FIXME(sendmsg,"(%08lx,%08lx,%08x,%08x,%08lx): stub!\n",
2123 dwFlags,*recipients,uMessage,wParam,lParam
2125 return 0;
2128 /***********************************************************************
2129 * SendNotifyMessageA (USER32.460)
2130 * FIXME
2131 * The message sended with PostMessage has to be put in the queue
2132 * with a higher priority as the other "Posted" messages.
2133 * QUEUE_AddMsg has to be modifyed.
2135 BOOL32 WINAPI SendNotifyMessage32A(HWND32 hwnd,UINT32 msg,WPARAM32 wParam,LPARAM lParam)
2136 { BOOL32 ret = TRUE;
2137 FIXME(msg,"(%04x,%08x,%08x,%08lx) not complete\n",
2138 hwnd, msg, wParam, lParam);
2140 if ( GetCurrentThreadId() == GetWindowThreadProcessId ( hwnd, NULL))
2141 { ret=SendMessage32A ( hwnd, msg, wParam, lParam );
2143 else
2144 { PostMessage32A ( hwnd, msg, wParam, lParam );
2146 return ret;
2149 /***********************************************************************
2150 * SendNotifyMessageW (USER32.461)
2151 * FIXME
2152 * The message sended with PostMessage has to be put in the queue
2153 * with a higher priority as the other "Posted" messages.
2154 * QUEUE_AddMsg has to be modifyed.
2156 BOOL32 WINAPI SendNotifyMessage32W(HWND32 hwnd,UINT32 msg,WPARAM32 wParam,LPARAM lParam)
2157 { BOOL32 ret = TRUE;
2158 FIXME(msg,"(%04x,%08x,%08x,%08lx) not complete\n",
2159 hwnd, msg, wParam, lParam);
2161 if ( GetCurrentThreadId() == GetWindowThreadProcessId ( hwnd, NULL))
2162 { ret=SendMessage32W ( hwnd, msg, wParam, lParam );
2164 else
2165 { PostMessage32W ( hwnd, msg, wParam, lParam );
2167 return ret;
2170 /***********************************************************************
2171 * SendMessageCallBack32A
2172 * FIXME: It's like PostMessage. The callback gets called when the message
2173 * is processed. We have to modify the message processing for a exact
2174 * implementation...
2176 BOOL32 WINAPI SendMessageCallBack32A(
2177 HWND32 hWnd,UINT32 Msg,WPARAM32 wParam,LPARAM lParam,
2178 FARPROC32 lpResultCallBack,DWORD dwData)
2180 FIXME(msg,"(0x%04x,0x%04x,0x%08x,0x%08lx,%p,0x%08lx),stub!\n",
2181 hWnd,Msg,wParam,lParam,lpResultCallBack,dwData);
2182 if ( hWnd == HWND_BROADCAST)
2183 { PostMessage32A( hWnd, Msg, wParam, lParam);
2184 FIXME(msg,"Broadcast: Callback will not be called!\n");
2185 return TRUE;
2187 (lpResultCallBack)( hWnd, Msg, dwData, SendMessage32A ( hWnd, Msg, wParam, lParam ));
2188 return TRUE;