2 * Message queues related functions
4 * Copyright 1993, 1994 Alexandre Julliard
11 #include <sys/types.h>
13 #include "wine/winbase16.h"
17 #include "sysmetrics.h"
33 #define WM_NCMOUSEFIRST WM_NCMOUSEMOVE
34 #define WM_NCMOUSELAST WM_NCMBUTTONDBLCLK
37 typedef enum { SYSQ_MSG_ABANDON
, SYSQ_MSG_SKIP
,
38 SYSQ_MSG_ACCEPT
, SYSQ_MSG_CONTINUE
} SYSQ_STATUS
;
40 extern HQUEUE16 hCursorQueue
; /* queue.c */
42 DWORD MSG_WineStartTicks
; /* Ticks at Wine startup */
44 static UINT doubleClickSpeed
= 452;
46 /***********************************************************************
49 BOOL
MSG_CheckFilter(DWORD uMsg
, DWORD first
, DWORD last
)
52 return (uMsg
>= first
&& uMsg
<= last
);
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 */
67 WND
*tmpWnd
= WIN_LockWndPtr(wndPtr
);
69 MapWindowPoints16( 0, tmpWnd
->hwndSelf
, lppt
, 1 );
72 if (!(tmpWnd
->dwStyle
& WS_CHILD
) || (tmpWnd
->dwExStyle
& WS_EX_NOPARENTNOTIFY
))
74 WIN_ReleaseWndPtr(tmpWnd
);
77 lppt
->x
+= tmpWnd
->rectClient
.left
;
78 lppt
->y
+= tmpWnd
->rectClient
.top
;
79 WIN_UpdateWndPtr(&tmpWnd
,tmpWnd
->parent
);
80 SendMessageA( tmpWnd
->hwndSelf
, WM_PARENTNOTIFY
,
81 MAKEWPARAM( event
, idChild
), lValue
);
88 /***********************************************************************
89 * MSG_TranslateMouseMsg
91 * Translate an mouse hardware event into a real mouse message.
92 * Return value indicates whether the translated message must be passed
93 * to the user, left in the queue, or skipped entirely (in this case
94 * HIWORD contains hit test code).
96 static DWORD
MSG_TranslateMouseMsg( HWND hTopWnd
, DWORD first
, DWORD last
,
97 MSG
*msg
, BOOL remove
, WND
* pWndScope
)
99 static DWORD dblclk_time_limit
= 0;
100 static UINT16 clk_message
= 0;
101 static HWND16 clk_hwnd
= 0;
102 static POINT16 clk_pos
= { 0, 0 };
106 INT16 ht
, hittest
, sendSC
= 0;
107 UINT message
= msg
->message
;
108 POINT16 screen_pt
, pt
;
109 HANDLE16 hQ
= GetFastQueue16();
110 MESSAGEQUEUE
*queue
= (MESSAGEQUEUE
*)QUEUE_Lock(hQ
);
112 BOOL mouseClick
= ((message
== WM_LBUTTONDOWN
) ||
113 (message
== WM_RBUTTONDOWN
) ||
114 (message
== WM_MBUTTONDOWN
))?1:0;
118 /* Find the window */
120 CONV_POINT32TO16( &msg
->pt
, &pt
);
122 ht
= hittest
= HTCLIENT
;
126 ht
= hittest
= WINPOS_WindowFromPoint( pWndScope
, pt
, &pWnd
);
127 if( !pWnd
) pWnd
= WIN_GetDesktop();
128 else WIN_LockWndPtr(pWnd
);
129 hWnd
= pWnd
->hwndSelf
;
134 pWnd
= WIN_FindWndPtr(hWnd
);
136 ht
= PERQDATA_GetCaptureInfo( queue
->pQData
);
139 /* stop if not the right queue */
141 if (pWnd
->hmemTaskQ
!= hQ
)
143 /* Not for the current task */
144 if (queue
) QUEUE_ClearWakeBit( queue
, QS_MOUSE
);
145 /* Wake up the other task */
146 QUEUE_Unlock( queue
);
147 queue
= (MESSAGEQUEUE
*)QUEUE_Lock( pWnd
->hmemTaskQ
);
148 if (queue
) QUEUE_SetWakeBit( queue
, QS_MOUSE
);
150 QUEUE_Unlock( queue
);
151 retvalue
= SYSQ_MSG_ABANDON
;
155 /* check if hWnd is within hWndScope */
157 if( hTopWnd
&& hWnd
!= hTopWnd
)
158 if( !IsChild(hTopWnd
, hWnd
) )
160 QUEUE_Unlock( queue
);
161 retvalue
= SYSQ_MSG_CONTINUE
;
167 /* translate double clicks -
168 * note that ...MOUSEMOVEs can slip in between
169 * ...BUTTONDOWN and ...BUTTONDBLCLK messages */
171 if( pWnd
->class->style
& CS_DBLCLKS
|| ht
!= HTCLIENT
)
173 if ((message
== clk_message
) && (hWnd
== clk_hwnd
) &&
174 (msg
->time
- dblclk_time_limit
< doubleClickSpeed
) &&
175 (abs(msg
->pt
.x
- clk_pos
.x
) < SYSMETRICS_CXDOUBLECLK
/2) &&
176 (abs(msg
->pt
.y
- clk_pos
.y
) < SYSMETRICS_CYDOUBLECLK
/2))
178 message
+= (WM_LBUTTONDBLCLK
- WM_LBUTTONDOWN
);
179 mouseClick
++; /* == 2 */
185 if (hittest
!= HTCLIENT
)
187 message
+= WM_NCMOUSEMOVE
- WM_MOUSEMOVE
;
188 msg
->wParam
= hittest
;
190 else ScreenToClient16( hWnd
, &pt
);
192 /* check message filter */
194 if (!MSG_CheckFilter(message
, first
, last
))
197 retvalue
= SYSQ_MSG_CONTINUE
;
201 hCursorQueue
= queue
->self
;
207 if (HOOK_IsHooked( WH_MOUSE
))
209 MOUSEHOOKSTRUCT16
*hook
= SEGPTR_NEW(MOUSEHOOKSTRUCT16
);
212 hook
->pt
= screen_pt
;
214 hook
->wHitTestCode
= hittest
;
215 hook
->dwExtraInfo
= 0;
216 ret
= HOOK_CallHooks16( WH_MOUSE
, remove
? HC_ACTION
: HC_NOREMOVE
,
217 message
, (LPARAM
)SEGPTR_GET(hook
) );
222 retvalue
= MAKELONG((INT16
)SYSQ_MSG_SKIP
, hittest
);
229 if ((hittest
== HTERROR
) || (hittest
== HTNOWHERE
))
231 else if( remove
&& mouseClick
)
233 HWND hwndTop
= WIN_GetTopParent( hWnd
);
235 if( mouseClick
== 1 )
238 dblclk_time_limit
= msg
->time
;
239 clk_message
= msg
->message
;
243 /* got double click - zero them out */
244 dblclk_time_limit
= clk_hwnd
= 0;
248 /* Send the WM_PARENTNOTIFY,
249 * note that even for double/nonclient clicks
250 * notification message is still WM_L/M/RBUTTONDOWN.
253 MSG_SendParentNotify( pWnd
, msg
->message
& 0xffff, 0, MAKELPARAM(screen_pt
.x
, screen_pt
.y
) );
255 /* Activate the window if needed */
257 if (hWnd
!= GetActiveWindow() && hWnd
!= GetDesktopWindow())
259 LONG ret
= SendMessageA( hWnd
, WM_MOUSEACTIVATE
, hwndTop
,
260 MAKELONG( hittest
, message
) );
262 if ((ret
== MA_ACTIVATEANDEAT
) || (ret
== MA_NOACTIVATEANDEAT
))
265 if (((ret
== MA_ACTIVATE
) || (ret
== MA_ACTIVATEANDEAT
))
266 && hwndTop
!= GetActiveWindow() )
267 if (!WINPOS_SetActiveWindow( hwndTop
, TRUE
, TRUE
))
271 } else sendSC
= (remove
&& sendSC
);
273 /* Send the WM_SETCURSOR message */
276 SendMessageA( hWnd
, WM_SETCURSOR
, hWnd
,
277 MAKELONG( hittest
, message
));
280 retvalue
= MAKELONG( (UINT16
)SYSQ_MSG_SKIP
, hittest
);
285 msg
->message
= message
;
286 msg
->lParam
= MAKELONG( pt
.x
, pt
.y
);
287 retvalue
= SYSQ_MSG_ACCEPT
;
289 WIN_ReleaseWndPtr(pWnd
);
295 /***********************************************************************
296 * MSG_TranslateKbdMsg
298 * Translate an keyboard hardware event into a real message.
300 static DWORD
MSG_TranslateKbdMsg( HWND hTopWnd
, DWORD first
, DWORD last
,
301 MSG
*msg
, BOOL remove
)
303 WORD message
= msg
->message
;
304 HWND hWnd
= GetFocus();
307 /* Should check Ctrl-Esc and PrintScreen here */
311 /* Send the message to the active window instead, */
312 /* translating messages to their WM_SYS equivalent */
314 hWnd
= GetActiveWindow();
316 if( message
< WM_SYSKEYDOWN
)
317 message
+= WM_SYSKEYDOWN
- WM_KEYDOWN
;
319 pWnd
= WIN_FindWndPtr( hWnd
);
320 if (pWnd
&& (pWnd
->hmemTaskQ
!= GetFastQueue16()))
322 /* Not for the current task */
323 MESSAGEQUEUE
*queue
= (MESSAGEQUEUE
*)QUEUE_Lock( GetFastQueue16() );
324 if (queue
) QUEUE_ClearWakeBit( queue
, QS_KEY
);
325 QUEUE_Unlock( queue
);
327 /* Wake up the other task */
328 queue
= (MESSAGEQUEUE
*)QUEUE_Lock( pWnd
->hmemTaskQ
);
329 if (queue
) QUEUE_SetWakeBit( queue
, QS_KEY
);
330 QUEUE_Unlock( queue
);
331 WIN_ReleaseWndPtr(pWnd
);
332 return SYSQ_MSG_ABANDON
;
334 WIN_ReleaseWndPtr(pWnd
);
336 if (hTopWnd
&& hWnd
!= hTopWnd
)
337 if (!IsChild(hTopWnd
, hWnd
)) return SYSQ_MSG_CONTINUE
;
338 if (!MSG_CheckFilter(message
, first
, last
)) return SYSQ_MSG_CONTINUE
;
341 msg
->message
= message
;
343 return (HOOK_CallHooks16( WH_KEYBOARD
, remove
? HC_ACTION
: HC_NOREMOVE
,
344 LOWORD (msg
->wParam
), msg
->lParam
)
345 ? SYSQ_MSG_SKIP
: SYSQ_MSG_ACCEPT
);
349 /***********************************************************************
350 * MSG_JournalRecordMsg
352 * Build an EVENTMSG structure and call JOURNALRECORD hook
354 static void MSG_JournalRecordMsg( MSG
*msg
)
356 EVENTMSG
*event
= (EVENTMSG
*) HeapAlloc(SystemHeap
, 0, sizeof(EVENTMSG
));
358 event
->message
= msg
->message
;
359 event
->time
= msg
->time
;
360 if ((msg
->message
>= WM_KEYFIRST
) && (msg
->message
<= WM_KEYLAST
))
362 event
->paramL
= (msg
->wParam
& 0xFF) | (HIWORD(msg
->lParam
) << 8);
363 event
->paramH
= msg
->lParam
& 0x7FFF;
364 if (HIWORD(msg
->lParam
) & 0x0100)
365 event
->paramH
|= 0x8000; /* special_key - bit */
366 HOOK_CallHooksA( WH_JOURNALRECORD
, HC_ACTION
, 0, (LPARAM
)event
);
368 else if ((msg
->message
>= WM_MOUSEFIRST
) && (msg
->message
<= WM_MOUSELAST
))
370 event
->paramL
= LOWORD(msg
->lParam
); /* X pos */
371 event
->paramH
= HIWORD(msg
->lParam
); /* Y pos */
372 ClientToScreen16( msg
->hwnd
, (LPPOINT16
)&event
->paramL
);
373 HOOK_CallHooksA( WH_JOURNALRECORD
, HC_ACTION
, 0, (LPARAM
)event
);
375 else if ((msg
->message
>= WM_NCMOUSEFIRST
) &&
376 (msg
->message
<= WM_NCMOUSELAST
))
378 event
->paramL
= LOWORD(msg
->lParam
); /* X pos */
379 event
->paramH
= HIWORD(msg
->lParam
); /* Y pos */
380 event
->message
+= WM_MOUSEMOVE
-WM_NCMOUSEMOVE
;/* give no info about NC area */
381 HOOK_CallHooksA( WH_JOURNALRECORD
, HC_ACTION
, 0, (LPARAM
)event
);
384 HeapFree(SystemHeap
, 0, event
);
387 /***********************************************************************
388 * MSG_JournalPlayBackMsg
390 * Get an EVENTMSG struct via call JOURNALPLAYBACK hook function
392 static int MSG_JournalPlayBackMsg(void)
395 long wtime
,lParam
,wParam
;
396 WORD keyDown
,i
,result
=0;
398 if ( HOOK_IsHooked( WH_JOURNALPLAYBACK
) )
400 tmpMsg
= (EVENTMSG
*) HeapAlloc(SystemHeap
, 0, sizeof(EVENTMSG
));
401 if (!tmpMsg
) return result
;
403 wtime
=HOOK_CallHooksA( WH_JOURNALPLAYBACK
, HC_GETNEXT
, 0,
405 /* TRACE(msg,"Playback wait time =%ld\n",wtime); */
409 if ((tmpMsg
->message
>= WM_KEYFIRST
) && (tmpMsg
->message
<= WM_KEYLAST
))
411 wParam
=tmpMsg
->paramL
& 0xFF;
412 lParam
=MAKELONG(tmpMsg
->paramH
&0x7ffff,tmpMsg
->paramL
>>8);
413 if (tmpMsg
->message
== WM_KEYDOWN
|| tmpMsg
->message
== WM_SYSKEYDOWN
)
415 for (keyDown
=i
=0; i
<256 && !keyDown
; i
++)
416 if (InputKeyStateTable
[i
] & 0x80)
419 lParam
|= 0x40000000;
420 AsyncKeyStateTable
[wParam
]=InputKeyStateTable
[wParam
] |= 0x80;
422 else /* WM_KEYUP, WM_SYSKEYUP */
424 lParam
|= 0xC0000000;
425 AsyncKeyStateTable
[wParam
]=InputKeyStateTable
[wParam
] &= ~0x80;
427 if (InputKeyStateTable
[VK_MENU
] & 0x80)
428 lParam
|= 0x20000000;
429 if (tmpMsg
->paramH
& 0x8000) /*special_key bit*/
430 lParam
|= 0x01000000;
431 hardware_event( tmpMsg
->message
& 0xffff, LOWORD(wParam
), lParam
,
432 0, 0, tmpMsg
->time
, 0 );
436 if ((tmpMsg
->message
>= WM_MOUSEFIRST
) && (tmpMsg
->message
<= WM_MOUSELAST
))
438 switch (tmpMsg
->message
)
441 MouseButtonsStates
[0]=AsyncMouseButtonsStates
[0]=TRUE
;break;
443 MouseButtonsStates
[0]=AsyncMouseButtonsStates
[0]=FALSE
;break;
445 MouseButtonsStates
[1]=AsyncMouseButtonsStates
[1]=TRUE
;break;
447 MouseButtonsStates
[1]=AsyncMouseButtonsStates
[1]=FALSE
;break;
449 MouseButtonsStates
[2]=AsyncMouseButtonsStates
[2]=TRUE
;break;
451 MouseButtonsStates
[2]=AsyncMouseButtonsStates
[2]=FALSE
;break;
453 AsyncKeyStateTable
[VK_LBUTTON
]= InputKeyStateTable
[VK_LBUTTON
] = MouseButtonsStates
[0] ? 0x80 : 0;
454 AsyncKeyStateTable
[VK_MBUTTON
]= InputKeyStateTable
[VK_MBUTTON
] = MouseButtonsStates
[1] ? 0x80 : 0;
455 AsyncKeyStateTable
[VK_RBUTTON
]= InputKeyStateTable
[VK_RBUTTON
] = MouseButtonsStates
[2] ? 0x80 : 0;
456 SetCursorPos(tmpMsg
->paramL
,tmpMsg
->paramH
);
457 lParam
=MAKELONG(tmpMsg
->paramL
,tmpMsg
->paramH
);
459 if (MouseButtonsStates
[0]) wParam
|= MK_LBUTTON
;
460 if (MouseButtonsStates
[1]) wParam
|= MK_MBUTTON
;
461 if (MouseButtonsStates
[2]) wParam
|= MK_RBUTTON
;
462 hardware_event( tmpMsg
->message
& 0xffff, LOWORD (wParam
), lParam
,
463 tmpMsg
->paramL
, tmpMsg
->paramH
, tmpMsg
->time
, 0 );
466 HOOK_CallHooksA( WH_JOURNALPLAYBACK
, HC_SKIP
, 0,
472 if( tmpMsg
->message
== WM_QUEUESYNC
)
473 if (HOOK_IsHooked( WH_CBT
))
474 HOOK_CallHooksA( WH_CBT
, HCBT_QS
, 0, 0L);
476 result
= QS_MOUSE
| QS_KEY
; /* ? */
478 HeapFree(SystemHeap
, 0, tmpMsg
);
483 /***********************************************************************
484 * MSG_PeekHardwareMsg
486 * Peek for a hardware message matching the hwnd and message filters.
488 static BOOL
MSG_PeekHardwareMsg( MSG
*msg
, HWND hwnd
, DWORD first
, DWORD last
,
491 /* FIXME: should deal with MSG32 instead of MSG16 */
493 DWORD status
= SYSQ_MSG_ACCEPT
;
494 MESSAGEQUEUE
*sysMsgQueue
= QUEUE_GetSysQueue();
496 QMSG
*nextqmsg
, *qmsg
= 0;
498 /* FIXME: there has to be a better way to do this */
501 EnterCriticalSection(&sysMsgQueue
->cSection
);
503 qmsg
= sysMsgQueue
->firstMsg
;
505 /* If the queue is empty, attempt to fill it */
506 if (!sysMsgQueue
->msgCount
&& THREAD_IsWin16( THREAD_Current() )
509 LeaveCriticalSection(&sysMsgQueue
->cSection
);
510 EVENT_WaitNetEvent( FALSE
, TRUE
);
511 EnterCriticalSection(&sysMsgQueue
->cSection
);
514 for ( kbd_msg
= 0; qmsg
; qmsg
= nextqmsg
)
519 nextqmsg
= qmsg
->nextMsg
;
521 /* Translate message */
523 if ((msg
->message
>= WM_MOUSEFIRST
) && (msg
->message
<= WM_MOUSELAST
))
526 HWND hWndScope
= (HWND
)qmsg
->extraInfo
;
527 WND
*tmpWnd
= (Options
.managed
&& IsWindow(hWndScope
) )
528 ? WIN_FindWndPtr(hWndScope
) : WIN_GetDesktop();
530 status
= MSG_TranslateMouseMsg(hwnd
, first
, last
, msg
, remove
,tmpWnd
);
533 WIN_ReleaseWndPtr(tmpWnd
);
536 else if ((msg
->message
>= WM_KEYFIRST
) && (msg
->message
<= WM_KEYLAST
))
538 status
= MSG_TranslateKbdMsg(hwnd
, first
, last
, msg
, remove
);
541 else /* Non-standard hardware event */
543 HARDWAREHOOKSTRUCT16
*hook
;
544 if ((hook
= SEGPTR_NEW(HARDWAREHOOKSTRUCT16
)))
547 hook
->hWnd
= msg
->hwnd
;
548 hook
->wMessage
= msg
->message
& 0xffff;
549 hook
->wParam
= LOWORD (msg
->wParam
);
550 hook
->lParam
= msg
->lParam
;
551 ret
= HOOK_CallHooks16( WH_HARDWARE
,
552 remove
? HC_ACTION
: HC_NOREMOVE
,
553 0, (LPARAM
)SEGPTR_GET(hook
) );
557 QUEUE_RemoveMsg( sysMsgQueue
, qmsg
);
560 status
= SYSQ_MSG_ACCEPT
;
564 switch (LOWORD(status
))
566 case SYSQ_MSG_ACCEPT
:
570 if (HOOK_IsHooked( WH_CBT
))
573 HOOK_CallHooks16( WH_CBT
, HCBT_KEYSKIPPED
,
574 LOWORD (msg
->wParam
), msg
->lParam
);
577 MOUSEHOOKSTRUCT16
*hook
= SEGPTR_NEW(MOUSEHOOKSTRUCT16
);
580 CONV_POINT32TO16( &msg
->pt
,&hook
->pt
);
581 hook
->hwnd
= msg
->hwnd
;
582 hook
->wHitTestCode
= HIWORD(status
);
583 hook
->dwExtraInfo
= 0;
584 HOOK_CallHooks16( WH_CBT
, HCBT_CLICKSKIPPED
,msg
->message
& 0xffff,
585 (LPARAM
)SEGPTR_GET(hook
) );
592 QUEUE_RemoveMsg( sysMsgQueue
, qmsg
);
595 case SYSQ_MSG_CONTINUE
:
598 case SYSQ_MSG_ABANDON
:
599 LeaveCriticalSection(&sysMsgQueue
->cSection
);
605 if (HOOK_IsHooked( WH_JOURNALRECORD
)) MSG_JournalRecordMsg( msg
);
606 QUEUE_RemoveMsg( sysMsgQueue
, qmsg
);
608 LeaveCriticalSection(&sysMsgQueue
->cSection
);
611 LeaveCriticalSection(&sysMsgQueue
->cSection
);
616 /**********************************************************************
617 * SetDoubleClickTime16 (USER.20)
619 void WINAPI
SetDoubleClickTime16( UINT16 interval
)
621 SetDoubleClickTime( interval
);
625 /**********************************************************************
626 * SetDoubleClickTime32 (USER32.480)
628 BOOL WINAPI
SetDoubleClickTime( UINT interval
)
630 doubleClickSpeed
= interval
? interval
: 500;
635 /**********************************************************************
636 * GetDoubleClickTime16 (USER.21)
638 UINT16 WINAPI
GetDoubleClickTime16(void)
640 return doubleClickSpeed
;
644 /**********************************************************************
645 * GetDoubleClickTime32 (USER32.239)
647 UINT WINAPI
GetDoubleClickTime(void)
649 return doubleClickSpeed
;
653 /***********************************************************************
654 * MSG_SendMessageInterThread
656 * Implementation of an inter-task SendMessage.
658 * 0 if error or timeout
661 static LRESULT
MSG_SendMessageInterThread( HQUEUE16 hDestQueue
,
663 WPARAM wParam
, LPARAM lParam
,
664 DWORD timeout
, WORD flags
,
667 MESSAGEQUEUE
*queue
, *destQ
;
674 if (IsTaskLocked16() || !IsWindow(hwnd
))
677 /* create a SMSG structure to hold SendMessage() parameters */
678 if (! (smsg
= (SMSG
*) HeapAlloc( SystemHeap
, 0, sizeof(SMSG
) )) )
680 if (!(queue
= (MESSAGEQUEUE
*)QUEUE_Lock( GetFastQueue16() ))) return 0;
682 if (!(destQ
= (MESSAGEQUEUE
*)QUEUE_Lock( hDestQueue
)))
684 QUEUE_Unlock( queue
);
688 TRACE(sendmsg
,"SM: %s [%04x] (%04x -> %04x)\n",
689 SPY_GetMsgName(msg
), msg
, queue
->self
, hDestQueue
);
691 /* fill up SMSG structure */
694 smsg
->wParam
= wParam
;
695 smsg
->lParam
= lParam
;
698 smsg
->hSrcQueue
= GetFastQueue16();
699 smsg
->hDstQueue
= hDestQueue
;
702 /* add smsg struct in the processing SM list of the source queue */
703 QUEUE_AddSMSG(queue
, SM_PROCESSING_LIST
, smsg
);
705 /* add smsg struct in the pending list of the destination queue */
706 if (QUEUE_AddSMSG(destQ
, SM_PENDING_LIST
, smsg
) == FALSE
)
709 iWndsLocks
= WIN_SuspendWndsLock();
711 /* force destination task to run next, if 16 bit threads */
712 if ( THREAD_IsWin16(THREAD_Current()) && THREAD_IsWin16(destQ
->thdb
) )
713 DirectedYield16( destQ
->thdb
->teb
.htask16
);
715 /* wait for the result, note that 16-bit apps almost always get out of
716 * DirectedYield() with SMSG_HAVE_RESULT flag already set */
721 * The sequence is crucial to avoid deadlock situations:
722 * - first, we clear the QS_SMRESULT bit
723 * - then, we check the SMSG_HAVE_RESULT bit
724 * - only if this isn't set, we enter the wait state.
726 * As the receiver first sets the SMSG_HAVE_RESULT and then wakes us,
727 * we are guaranteed that -should we now clear the QS_SMRESULT that
728 * was signalled already by the receiver- we will not start waiting.
731 if ( smsg
->flags
& SMSG_HAVE_RESULT
)
734 *pRes
= smsg
->lResult
;
735 TRACE(sendmsg
,"smResult = %08x\n", (unsigned)*pRes
);
739 QUEUE_ClearWakeBit( queue
, QS_SMRESULT
);
741 if ( smsg
->flags
& SMSG_HAVE_RESULT
)
744 if( QUEUE_WaitBits( QS_SMRESULT
, timeout
) == 0 )
746 /* return with timeout */
752 WIN_RestoreWndsLock(iWndsLocks
);
754 /* remove the smsg from the processingg list of the source queue */
755 QUEUE_RemoveSMSG( queue
, SM_PROCESSING_LIST
, smsg
);
757 /* Note: the destination thread is in charge of removing the smsg from
760 /* In the case of an early reply (or a timeout), sender thread will
761 released the smsg structure if the receiver thread is done
762 (SMSG_RECEIVED set). If the receiver thread isn't done,
763 SMSG_RECEIVER_CLEANS_UP flag is set, and it will be the receiver
764 responsability to released smsg */
765 EnterCriticalSection( &queue
->cSection
);
767 if (smsg
->flags
& SMSG_RECEIVED
)
768 HeapFree(SystemHeap
, 0, smsg
);
770 smsg
->flags
|= SMSG_RECEIVER_CLEANS
;
772 LeaveCriticalSection( &queue
->cSection
);
775 QUEUE_Unlock( queue
);
776 QUEUE_Unlock( destQ
);
778 TRACE(sendmsg
,"done!\n");
783 /***********************************************************************
784 * ReplyMessage16 (USER.115)
786 void WINAPI
ReplyMessage16( LRESULT result
)
788 ReplyMessage( result
);
791 /***********************************************************************
792 * ReplyMessage (USER.115)
794 BOOL WINAPI
ReplyMessage( LRESULT result
)
796 MESSAGEQUEUE
*senderQ
= 0;
797 MESSAGEQUEUE
*queue
= 0;
801 if (!(queue
= (MESSAGEQUEUE
*)QUEUE_Lock( GetFastQueue16() )))
804 TRACE(sendmsg
,"ReplyMessage, queue %04x\n", queue
->self
);
807 if ( !(smsg
= queue
->smWaiting
)
808 || !(senderQ
= QUEUE_Lock( smsg
->hSrcQueue
)) )
809 goto ReplyMessageEnd
;
811 if ( !(smsg
->flags
& SMSG_ALREADY_REPLIED
) )
813 /* This is the first reply, so pass result to sender */
815 TRACE( sendmsg
,"\trpm: smResult = %08lx\n", (long) result
);
817 EnterCriticalSection(&senderQ
->cSection
);
819 smsg
->lResult
= result
;
820 smsg
->flags
|= SMSG_ALREADY_REPLIED
;
822 /* check if it's an early reply (called by the application) or
823 a regular reply (called by ReceiveMessage) */
824 if ( !(smsg
->flags
& SMSG_SENDING_REPLY
) )
825 smsg
->flags
|= SMSG_EARLY_REPLY
;
827 smsg
->flags
|= SMSG_HAVE_RESULT
;
829 LeaveCriticalSection(&senderQ
->cSection
);
831 /* tell the sending task that its reply is ready */
832 QUEUE_SetWakeBit( senderQ
, QS_SMRESULT
);
834 /* switch directly to sending task (16 bit thread only) */
835 if ( THREAD_IsWin16( THREAD_Current() ) && THREAD_IsWin16( senderQ
->thdb
) )
836 DirectedYield16( senderQ
->thdb
->teb
.htask16
);
841 if (smsg
->flags
& SMSG_SENDING_REPLY
)
843 /* remove msg from the waiting list, since this is the last
845 QUEUE_RemoveSMSG( queue
, SM_WAITING_LIST
, smsg
);
847 EnterCriticalSection(&senderQ
->cSection
);
849 /* tell the sender we're all done with smsg structure */
850 smsg
->flags
|= SMSG_RECEIVED
;
852 /* sender will set SMSG_RECEIVER_CLEANS_UP if it wants the
853 receiver to clean up smsg, it could only happens when there is
854 an early reply or a timeout */
855 if ( smsg
->flags
& SMSG_RECEIVER_CLEANS
)
857 TRACE( sendmsg
,"Receiver cleans up!\n" );
858 HeapFree( SystemHeap
, 0, smsg
);
861 LeaveCriticalSection(&senderQ
->cSection
);
866 QUEUE_Unlock( senderQ
);
868 QUEUE_Unlock( queue
);
873 /***********************************************************************
876 static BOOL
MSG_PeekMessage( LPMSG msg
, HWND hwnd
, DWORD first
, DWORD last
,
877 WORD flags
, BOOL peek
)
880 MESSAGEQUEUE
*msgQueue
;
886 DDE_TestDDE(hwnd
); /* do we have dde handling in the window ?*/
887 DDE_GetRemoteMessage();
888 #endif /* CONFIG_IPC */
890 mask
= QS_POSTMESSAGE
| QS_SENDMESSAGE
; /* Always selected */
893 if ((first
<= WM_KEYLAST
) && (last
>= WM_KEYFIRST
)) mask
|= QS_KEY
;
894 if ( ((first
<= WM_MOUSELAST
) && (last
>= WM_MOUSEFIRST
)) ||
895 ((first
<= WM_NCMOUSELAST
) && (last
>= WM_NCMOUSEFIRST
)) ) mask
|= QS_MOUSE
;
896 if ((first
<= WM_TIMER
) && (last
>= WM_TIMER
)) mask
|= QS_TIMER
;
897 if ((first
<= WM_SYSTIMER
) && (last
>= WM_SYSTIMER
)) mask
|= QS_TIMER
;
898 if ((first
<= WM_PAINT
) && (last
>= WM_PAINT
)) mask
|= QS_PAINT
;
900 else mask
|= QS_MOUSE
| QS_KEY
| QS_TIMER
| QS_PAINT
;
902 if (IsTaskLocked16()) flags
|= PM_NOYIELD
;
904 /* Never yield on Win32 threads */
905 if (!THREAD_IsWin16(THREAD_Current())) flags
|= PM_NOYIELD
;
907 iWndsLocks
= WIN_SuspendWndsLock();
913 hQueue
= GetFastQueue16();
914 msgQueue
= (MESSAGEQUEUE
*)QUEUE_Lock( hQueue
);
917 WIN_RestoreWndsLock(iWndsLocks
);
920 msgQueue
->changeBits
= 0;
922 /* First handle a message put by SendMessage() */
924 while (msgQueue
->wakeBits
& QS_SENDMESSAGE
)
925 QUEUE_ReceiveMessage( msgQueue
);
927 /* Now handle a WM_QUIT message */
929 if (msgQueue
->wPostQMsg
&&
930 (!first
|| WM_QUIT
>= first
) &&
931 (!last
|| WM_QUIT
<= last
) )
934 msg
->message
= WM_QUIT
;
935 msg
->wParam
= msgQueue
->wExitCode
;
937 if (flags
& PM_REMOVE
) msgQueue
->wPostQMsg
= 0;
941 /* Now find a normal message */
943 if (((msgQueue
->wakeBits
& mask
) & QS_POSTMESSAGE
) &&
944 ((qmsg
= QUEUE_FindMsg( msgQueue
, hwnd
, first
, last
)) != 0))
948 msgQueue
->GetMessageTimeVal
= msg
->time
;
949 CONV_POINT32TO16(&msg
->pt
, &pt16
);
950 msgQueue
->GetMessagePosVal
= *(DWORD
*)&pt16
;
951 msgQueue
->GetMessageExtraInfoVal
= qmsg
->extraInfo
;
953 if (flags
& PM_REMOVE
) QUEUE_RemoveMsg( msgQueue
, qmsg
);
957 msgQueue
->changeBits
|= MSG_JournalPlayBackMsg();
959 /* Now find a hardware event */
961 if (((msgQueue
->wakeBits
& mask
) & (QS_MOUSE
| QS_KEY
)) &&
962 MSG_PeekHardwareMsg( msg
, hwnd
, first
, last
, flags
& PM_REMOVE
))
965 msgQueue
->GetMessageTimeVal
= msg
->time
;
966 CONV_POINT32TO16(&msg
->pt
, &pt16
);
967 msgQueue
->GetMessagePosVal
= *(DWORD
*)&pt16
;
968 msgQueue
->GetMessageExtraInfoVal
= 0; /* Always 0 for now */
972 /* Check again for SendMessage */
974 while (msgQueue
->wakeBits
& QS_SENDMESSAGE
)
975 QUEUE_ReceiveMessage( msgQueue
);
977 /* Now find a WM_PAINT message */
979 if ((msgQueue
->wakeBits
& mask
) & QS_PAINT
)
982 msg
->hwnd
= WIN_FindWinToRepaint( hwnd
, hQueue
);
983 msg
->message
= WM_PAINT
;
987 if ((wndPtr
= WIN_FindWndPtr(msg
->hwnd
)))
989 if( wndPtr
->dwStyle
& WS_MINIMIZE
&&
990 wndPtr
->class->hIcon
)
992 msg
->message
= WM_PAINTICON
;
996 if( !hwnd
|| msg
->hwnd
== hwnd
|| IsChild16(hwnd
,msg
->hwnd
) )
998 if( wndPtr
->flags
& WIN_INTERNAL_PAINT
&& !wndPtr
->hrgnUpdate
)
1000 wndPtr
->flags
&= ~WIN_INTERNAL_PAINT
;
1001 QUEUE_DecPaintCount( hQueue
);
1003 WIN_ReleaseWndPtr(wndPtr
);
1006 WIN_ReleaseWndPtr(wndPtr
);
1010 /* Check for timer messages, but yield first */
1012 if (!(flags
& PM_NOYIELD
))
1015 while (msgQueue
->wakeBits
& QS_SENDMESSAGE
)
1016 QUEUE_ReceiveMessage( msgQueue
);
1018 if ((msgQueue
->wakeBits
& mask
) & QS_TIMER
)
1020 if (TIMER_GetTimerMsg(msg
, hwnd
, hQueue
, flags
& PM_REMOVE
)) break;
1025 if (!(flags
& PM_NOYIELD
)) UserYield16();
1027 QUEUE_Unlock( msgQueue
);
1028 WIN_RestoreWndsLock(iWndsLocks
);
1031 msgQueue
->wakeMask
= mask
;
1032 QUEUE_WaitBits( mask
, INFINITE
);
1033 QUEUE_Unlock( msgQueue
);
1036 WIN_RestoreWndsLock(iWndsLocks
);
1038 /* instead of unlocking queue for every break condition, all break
1039 condition will fall here */
1040 QUEUE_Unlock( msgQueue
);
1042 /* We got a message */
1043 if (flags
& PM_REMOVE
)
1045 WORD message
= msg
->message
;
1047 if (message
== WM_KEYDOWN
|| message
== WM_SYSKEYDOWN
)
1049 BYTE
*p
= &QueueKeyStateTable
[msg
->wParam
& 0xff];
1055 else if (message
== WM_KEYUP
|| message
== WM_SYSKEYUP
)
1056 QueueKeyStateTable
[msg
->wParam
& 0xff] &= ~0x80;
1063 return (msg
->message
!= WM_QUIT
);
1066 /***********************************************************************
1067 * MSG_InternalGetMessage
1069 * GetMessage() function for internal use. Behave like GetMessage(),
1070 * but also call message filters and optionally send WM_ENTERIDLE messages.
1071 * 'hwnd' must be the handle of the dialog or menu window.
1072 * 'code' is the message filter value (MSGF_??? codes).
1074 BOOL
MSG_InternalGetMessage( MSG
*msg
, HWND hwnd
, HWND hwndOwner
,
1075 WPARAM code
, WORD flags
, BOOL sendIdle
)
1081 if (!MSG_PeekMessage( msg
, 0, 0, 0, flags
, TRUE
))
1083 /* No message present -> send ENTERIDLE and wait */
1084 if (IsWindow(hwndOwner
))
1085 SendMessageA( hwndOwner
, WM_ENTERIDLE
,
1086 code
, (LPARAM
)hwnd
);
1087 MSG_PeekMessage( msg
, 0, 0, 0, flags
, FALSE
);
1090 else /* Always wait for a message */
1091 MSG_PeekMessage( msg
, 0, 0, 0, flags
, FALSE
);
1093 /* Call message filters */
1095 if (HOOK_IsHooked( WH_SYSMSGFILTER
) || HOOK_IsHooked( WH_MSGFILTER
))
1097 MSG
*pmsg
= HeapAlloc( SystemHeap
, 0, sizeof(MSG
) );
1102 ret
= (HOOK_CallHooksA( WH_SYSMSGFILTER
, code
, 0,
1104 HOOK_CallHooksA( WH_MSGFILTER
, code
, 0,
1107 HeapFree( SystemHeap
, 0, pmsg
);
1110 /* Message filtered -> remove it from the queue */
1111 /* if it's still there. */
1112 if (!(flags
& PM_REMOVE
))
1113 MSG_PeekMessage( msg
, 0, 0, 0, PM_REMOVE
, TRUE
);
1119 return (msg
->message
!= WM_QUIT
);
1124 /***********************************************************************
1125 * PeekMessage16 (USER.109)
1127 BOOL16 WINAPI
PeekMessage16( LPMSG16 lpmsg
, HWND16 hwnd
, UINT16 first
,
1128 UINT16 last
, UINT16 flags
)
1132 ret
= PeekMessageA(&msg32
, hwnd
, first
, last
, flags
);
1133 STRUCT32_MSG32to16(&msg32
, lpmsg
);
1137 /***********************************************************************
1138 * WIN16_PeekMessage32 (USER.819)
1140 BOOL16 WINAPI
PeekMessage32_16( LPMSG16_32 lpmsg16_32
, HWND16 hwnd
,
1141 UINT16 first
, UINT16 last
, UINT16 flags
, BOOL16 wHaveParamHigh
)
1143 if (wHaveParamHigh
== FALSE
)
1145 lpmsg16_32
->wParamHigh
= 0;
1146 return PeekMessage16(&(lpmsg16_32
->msg
), hwnd
, first
, last
, flags
);
1153 ret
= (BOOL16
)PeekMessageA(&msg32
, (HWND
)hwnd
,
1154 (UINT
)first
, (UINT
)last
, (UINT
)flags
);
1155 lpmsg16_32
->msg
.hwnd
= msg32
.hwnd
;
1156 lpmsg16_32
->msg
.message
= msg32
.message
;
1157 lpmsg16_32
->msg
.wParam
= LOWORD(msg32
.wParam
);
1158 lpmsg16_32
->msg
.lParam
= msg32
.lParam
;
1159 lpmsg16_32
->msg
.time
= msg32
.time
;
1160 lpmsg16_32
->msg
.pt
.x
= (INT16
)msg32
.pt
.x
;
1161 lpmsg16_32
->msg
.pt
.y
= (INT16
)msg32
.pt
.y
;
1162 lpmsg16_32
->wParamHigh
= HIWORD(msg32
.wParam
);
1168 /***********************************************************************
1171 BOOL WINAPI
PeekMessageA( LPMSG lpmsg
, HWND hwnd
,
1172 UINT min
,UINT max
,UINT wRemoveMsg
)
1174 return MSG_PeekMessage( lpmsg
, hwnd
, min
, max
, wRemoveMsg
, TRUE
);
1177 /***********************************************************************
1178 * PeekMessageW Check queue for messages
1180 * Checks for a message in the thread's queue, filtered as for
1181 * GetMessage(). Returns immediately whether a message is available
1184 * Whether a retrieved message is removed from the queue is set by the
1185 * _wRemoveMsg_ flags, which should be one of the following values:
1187 * PM_NOREMOVE Do not remove the message from the queue.
1189 * PM_REMOVE Remove the message from the queue.
1191 * In addition, PM_NOYIELD may be combined into _wRemoveMsg_ to
1192 * request that the system not yield control during PeekMessage();
1193 * however applications may not rely on scheduling behavior.
1197 * Nonzero if a message is available and is retrieved, zero otherwise.
1204 BOOL WINAPI
PeekMessageW(
1205 LPMSG lpmsg
, /* buffer to receive message */
1206 HWND hwnd
, /* restrict to messages for hwnd */
1207 UINT min
, /* minimum message to receive */
1208 UINT max
, /* maximum message to receive */
1209 UINT wRemoveMsg
/* removal flags */
1211 /* FIXME: Should perform Unicode translation on specific messages */
1212 return PeekMessageA(lpmsg
,hwnd
,min
,max
,wRemoveMsg
);
1215 /***********************************************************************
1216 * GetMessage16 (USER.108)
1218 BOOL16 WINAPI
GetMessage16( SEGPTR msg
, HWND16 hwnd
, UINT16 first
, UINT16 last
)
1221 MSG16
*lpmsg
= (MSG16
*)PTR_SEG_TO_LIN(msg
);
1224 ret
= GetMessageA( &msg32
, hwnd
, first
, last
);
1226 STRUCT32_MSG32to16( &msg32
, lpmsg
);
1228 TRACE(msg
,"message %04x, hwnd %04x, filter(%04x - %04x)\n", lpmsg
->message
,
1229 hwnd
, first
, last
);
1234 /***********************************************************************
1235 * WIN16_GetMessage32 (USER.820)
1237 BOOL16 WINAPI
GetMessage32_16( SEGPTR msg16_32
, HWND16 hWnd
, UINT16 first
,
1238 UINT16 last
, BOOL16 wHaveParamHigh
)
1240 MSG32_16
*lpmsg16_32
= (MSG32_16
*)PTR_SEG_TO_LIN(msg16_32
);
1242 if (wHaveParamHigh
== FALSE
) /* normal GetMessage16 call */
1245 lpmsg16_32
->wParamHigh
= 0; /* you never know... */
1246 /* WARNING: msg16_32->msg has to be the first variable in the struct */
1247 return GetMessage16(msg16_32
, hWnd
, first
, last
);
1254 ret
= (BOOL16
)GetMessageA(&msg32
, hWnd
, first
, last
);
1255 lpmsg16_32
->msg
.hwnd
= msg32
.hwnd
;
1256 lpmsg16_32
->msg
.message
= msg32
.message
;
1257 lpmsg16_32
->msg
.wParam
= LOWORD(msg32
.wParam
);
1258 lpmsg16_32
->msg
.lParam
= msg32
.lParam
;
1259 lpmsg16_32
->msg
.time
= msg32
.time
;
1260 lpmsg16_32
->msg
.pt
.x
= (INT16
)msg32
.pt
.x
;
1261 lpmsg16_32
->msg
.pt
.y
= (INT16
)msg32
.pt
.y
;
1262 lpmsg16_32
->wParamHigh
= HIWORD(msg32
.wParam
);
1267 /***********************************************************************
1268 * GetMessage32A (USER32.270)
1270 BOOL WINAPI
GetMessageA(MSG
* lpmsg
,HWND hwnd
,UINT min
,UINT max
)
1272 MSG_PeekMessage( lpmsg
, hwnd
, min
, max
, PM_REMOVE
, FALSE
);
1274 TRACE(msg
,"message %04x, hwnd %04x, filter(%04x - %04x)\n", lpmsg
->message
,
1277 HOOK_CallHooksA( WH_GETMESSAGE
, HC_ACTION
, 0, (LPARAM
)lpmsg
);
1279 return (lpmsg
->message
!= WM_QUIT
);
1282 /***********************************************************************
1283 * GetMessage32W (USER32.274) Retrieve next message
1285 * GetMessage retrieves the next event from the calling thread's
1286 * queue and deposits it in *lpmsg.
1288 * If _hwnd_ is not NULL, only messages for window _hwnd_ and its
1289 * children as specified by IsChild() are retrieved. If _hwnd_ is NULL
1290 * all application messages are retrieved.
1292 * _min_ and _max_ specify the range of messages of interest. If
1293 * min==max==0, no filtering is performed. Useful examples are
1294 * WM_KEYFIRST and WM_KEYLAST to retrieve keyboard input, and
1295 * WM_MOUSEFIRST and WM_MOUSELAST to retrieve mouse input.
1297 * WM_PAINT messages are not removed from the queue; they remain until
1298 * processed. Other messages are removed from the queue.
1302 * -1 on error, 0 if message is WM_QUIT, nonzero otherwise.
1309 BOOL WINAPI
GetMessageW(
1310 MSG
* lpmsg
, /* buffer to receive message */
1311 HWND hwnd
, /* restrict to messages for hwnd */
1312 UINT min
, /* minimum message to receive */
1313 UINT max
/* maximum message to receive */
1316 return GetMessageA(lpmsg
, hwnd
, min
, max
);
1320 /***********************************************************************
1321 * PostMessage16 (USER.110)
1323 BOOL16 WINAPI
PostMessage16( HWND16 hwnd
, UINT16 message
, WPARAM16 wParam
,
1326 return (BOOL16
) PostMessageA( hwnd
, message
, wParam
, lParam
);
1330 /***********************************************************************
1331 * PostMessage32A (USER32.419)
1333 BOOL WINAPI
PostMessageA( HWND hwnd
, UINT message
, WPARAM wParam
,
1341 msg
.message
= message
;
1342 msg
.wParam
= wParam
;
1343 msg
.lParam
= lParam
;
1344 msg
.time
= GetTickCount();
1349 if (DDE_PostMessage(&msg
))
1351 #endif /* CONFIG_IPC */
1353 if (hwnd
== HWND_BROADCAST
)
1355 WND
*pDesktop
= WIN_GetDesktop();
1356 TRACE(msg
,"HWND_BROADCAST !\n");
1358 for (wndPtr
=WIN_LockWndPtr(pDesktop
->child
); wndPtr
; WIN_UpdateWndPtr(&wndPtr
,wndPtr
->next
))
1360 if (wndPtr
->dwStyle
& WS_POPUP
|| wndPtr
->dwStyle
& WS_CAPTION
)
1362 TRACE(msg
,"BROADCAST Message to hWnd=%04x m=%04X w=%04X l=%08lX !\n",
1363 wndPtr
->hwndSelf
, message
, wParam
, lParam
);
1364 PostMessageA( wndPtr
->hwndSelf
, message
, wParam
, lParam
);
1367 WIN_ReleaseDesktop();
1368 TRACE(msg
,"End of HWND_BROADCAST !\n");
1372 wndPtr
= WIN_FindWndPtr( hwnd
);
1373 if (!wndPtr
|| !wndPtr
->hmemTaskQ
)
1379 retvalue
= QUEUE_AddMsg( wndPtr
->hmemTaskQ
, &msg
, 0 );
1381 WIN_ReleaseWndPtr(wndPtr
);
1386 /***********************************************************************
1387 * PostMessage32W (USER32.420)
1389 BOOL WINAPI
PostMessageW( HWND hwnd
, UINT message
, WPARAM wParam
,
1393 return PostMessageA( hwnd
, message
, wParam
, lParam
);
1397 /***********************************************************************
1398 * PostAppMessage16 (USER.116)
1400 BOOL16 WINAPI
PostAppMessage16( HTASK16 hTask
, UINT16 message
, WPARAM16 wParam
,
1405 if (GetTaskQueue16(hTask
) == 0) return FALSE
;
1407 msg
.message
= message
;
1408 msg
.wParam
= wParam
;
1409 msg
.lParam
= lParam
;
1410 msg
.time
= GetTickCount();
1414 return QUEUE_AddMsg( GetTaskQueue16(hTask
), &msg
, 0 );
1417 /************************************************************************
1418 * MSG_CallWndProcHook32
1420 static void MSG_CallWndProcHook( LPMSG pmsg
, BOOL bUnicode
)
1424 cwp
.lParam
= pmsg
->lParam
;
1425 cwp
.wParam
= pmsg
->wParam
;
1426 cwp
.message
= pmsg
->message
;
1427 cwp
.hwnd
= pmsg
->hwnd
;
1429 if (bUnicode
) HOOK_CallHooksW(WH_CALLWNDPROC
, HC_ACTION
, 1, (LPARAM
)&cwp
);
1430 else HOOK_CallHooksA( WH_CALLWNDPROC
, HC_ACTION
, 1, (LPARAM
)&cwp
);
1432 pmsg
->lParam
= cwp
.lParam
;
1433 pmsg
->wParam
= cwp
.wParam
;
1434 pmsg
->message
= cwp
.message
;
1435 pmsg
->hwnd
= cwp
.hwnd
;
1439 /***********************************************************************
1442 * return values: 0 if timeout occurs
1445 LRESULT
MSG_SendMessage( HWND hwnd
, UINT msg
, WPARAM wParam
,
1446 LPARAM lParam
, DWORD timeout
, WORD flags
,
1450 WND
**list
, **ppWnd
;
1455 if (hwnd
== HWND_BROADCAST
)
1459 if (!(list
= WIN_BuildWinArray( WIN_GetDesktop(), 0, NULL
)))
1461 WIN_ReleaseDesktop();
1464 WIN_ReleaseDesktop();
1466 TRACE(msg
,"HWND_BROADCAST !\n");
1467 for (ppWnd
= list
; *ppWnd
; ppWnd
++)
1469 WIN_UpdateWndPtr(&wndPtr
,*ppWnd
);
1470 if (!IsWindow(wndPtr
->hwndSelf
)) continue;
1471 if (wndPtr
->dwStyle
& WS_POPUP
|| wndPtr
->dwStyle
& WS_CAPTION
)
1473 TRACE(msg
,"BROADCAST Message to hWnd=%04x m=%04X w=%04lX l=%08lX !\n",
1474 wndPtr
->hwndSelf
, msg
, (DWORD
)wParam
, lParam
);
1475 MSG_SendMessage( wndPtr
->hwndSelf
, msg
, wParam
, lParam
,
1476 timeout
, flags
, pRes
);
1479 WIN_ReleaseWndPtr(wndPtr
);
1480 WIN_ReleaseWinArray(list
);
1481 TRACE(msg
,"End of HWND_BROADCAST !\n");
1485 if (HOOK_IsHooked( WH_CALLWNDPROC
))
1487 if (flags
& SMSG_UNICODE
)
1488 MSG_CallWndProcHook( (LPMSG
)&hwnd
, TRUE
);
1489 else if (flags
& SMSG_WIN32
)
1490 MSG_CallWndProcHook( (LPMSG
)&hwnd
, FALSE
);
1495 if ((pmsg
= SEGPTR_NEW(CWPSTRUCT16
)))
1497 pmsg
->hwnd
= hwnd
& 0xffff;
1498 pmsg
->message
= msg
& 0xffff;
1499 pmsg
->wParam
= wParam
& 0xffff;
1500 pmsg
->lParam
= lParam
;
1501 HOOK_CallHooks16( WH_CALLWNDPROC
, HC_ACTION
, 1,
1502 (LPARAM
)SEGPTR_GET(pmsg
) );
1504 msg
= pmsg
->message
;
1505 wParam
= pmsg
->wParam
;
1506 lParam
= pmsg
->lParam
;
1507 SEGPTR_FREE( pmsg
);
1512 if (!(wndPtr
= WIN_FindWndPtr( hwnd
)))
1514 WARN(msg
, "invalid hwnd %04x\n", hwnd
);
1517 if (QUEUE_IsExitingQueue(wndPtr
->hmemTaskQ
))
1519 ret
= 0; /* Don't send anything if the task is dying */
1522 if (flags
& SMSG_WIN32
)
1523 SPY_EnterMessage( SPY_SENDMESSAGE
, hwnd
, msg
, wParam
, lParam
);
1525 SPY_EnterMessage( SPY_SENDMESSAGE16
, hwnd
, msg
, wParam
, lParam
);
1527 if (wndPtr
->hmemTaskQ
!= GetFastQueue16())
1528 ret
= MSG_SendMessageInterThread( wndPtr
->hmemTaskQ
, hwnd
, msg
,
1529 wParam
, lParam
, timeout
, flags
, pRes
);
1532 /* Call the right CallWindowProc flavor */
1533 if (flags
& SMSG_UNICODE
)
1534 *pRes
= CallWindowProcW( (WNDPROC
)wndPtr
->winproc
,
1535 hwnd
, msg
, wParam
, lParam
);
1536 else if (flags
& SMSG_WIN32
)
1537 *pRes
= CallWindowProcA( (WNDPROC
)wndPtr
->winproc
,
1538 hwnd
, msg
, wParam
, lParam
);
1540 *pRes
= CallWindowProc16( (WNDPROC16
)wndPtr
->winproc
,
1541 (HWND16
) hwnd
, (UINT16
) msg
,
1542 (WPARAM16
) wParam
, lParam
);
1545 if (flags
& SMSG_WIN32
)
1546 SPY_ExitMessage( SPY_RESULT_OK
, hwnd
, msg
, ret
);
1548 SPY_ExitMessage( SPY_RESULT_OK16
, hwnd
, msg
, ret
);
1550 WIN_ReleaseWndPtr(wndPtr
);
1555 /***********************************************************************
1556 * SendMessage16 (USER.111)
1558 LRESULT WINAPI
SendMessage16( HWND16 hwnd
, UINT16 msg
, WPARAM16 wParam
,
1563 MSG16 DDE_msg
= { hwnd
, msg
, wParam
, lParam
};
1564 if (DDE_SendMessage(&DDE_msg
)) return TRUE
;
1565 #endif /* CONFIG_IPC */
1567 MSG_SendMessage(hwnd
, msg
, wParam
, lParam
, INFINITE
, 0, &res
);
1574 /**********************************************************************
1575 * PostThreadMessage32A (USER32.422)
1579 * Thread-local message queues are not supported.
1582 BOOL WINAPI
PostThreadMessageA(DWORD idThread
, UINT message
,
1583 WPARAM wParam
, LPARAM lParam
)
1588 if ((hQueue
= GetThreadQueue16(idThread
)) == 0)
1592 msg
.message
= message
;
1593 msg
.wParam
= wParam
;
1594 msg
.lParam
= lParam
;
1595 msg
.time
= GetTickCount();
1599 return QUEUE_AddMsg( hQueue
, &msg
, 0 );
1602 /**********************************************************************
1603 * PostThreadMessage32W (USER32.423)
1607 * Thread-local message queues are not supported.
1610 BOOL WINAPI
PostThreadMessageW(DWORD idThread
, UINT message
,
1611 WPARAM wParam
, LPARAM lParam
)
1613 FIXME(sendmsg
, "(...): Should do unicode/ascii conversion!\n");
1614 return PostThreadMessageA(idThread
, message
, wParam
, lParam
);
1617 /***********************************************************************
1618 * SendMessage32A (USER32.454)
1620 LRESULT WINAPI
SendMessageA( HWND hwnd
, UINT msg
, WPARAM wParam
,
1625 MSG_SendMessage(hwnd
, msg
, wParam
, lParam
, INFINITE
,
1632 /***********************************************************************
1633 * SendMessage32W (USER32.459) Send Window Message
1635 * Sends a message to the window procedure of the specified window.
1636 * SendMessage() will not return until the called window procedure
1637 * either returns or calls ReplyMessage().
1639 * Use PostMessage() to send message and return immediately. A window
1640 * procedure may use InSendMessage() to detect
1641 * SendMessage()-originated messages.
1643 * Applications which communicate via HWND_BROADCAST may use
1644 * RegisterWindowMessage() to obtain a unique message to avoid conflicts
1645 * with other applications.
1651 LRESULT WINAPI
SendMessageW(
1652 HWND hwnd
, /* Window to send message to. If HWND_BROADCAST,
1653 the message will be sent to all top-level windows. */
1655 UINT msg
, /* message */
1656 WPARAM wParam
, /* message parameter */
1657 LPARAM lParam
/* additional message parameter */
1661 MSG_SendMessage(hwnd
, msg
, wParam
, lParam
, INFINITE
,
1662 SMSG_WIN32
| SMSG_UNICODE
, &res
);
1668 /***********************************************************************
1669 * SendMessageTimeout16 (not a WINAPI)
1671 LRESULT WINAPI
SendMessageTimeout16( HWND16 hwnd
, UINT16 msg
, WPARAM16 wParam
,
1672 LPARAM lParam
, UINT16 flags
,
1673 UINT16 timeout
, LPWORD resultp
)
1678 /* FIXME: need support for SMTO_BLOCK */
1680 ret
= MSG_SendMessage(hwnd
, msg
, wParam
, lParam
, timeout
, 0, &msgRet
);
1681 *resultp
= (WORD
) msgRet
;
1686 /***********************************************************************
1687 * SendMessageTimeoutA (USER32.457)
1689 LRESULT WINAPI
SendMessageTimeoutA( HWND hwnd
, UINT msg
, WPARAM wParam
,
1690 LPARAM lParam
, UINT flags
,
1691 UINT timeout
, LPDWORD resultp
)
1696 /* FIXME: need support for SMTO_BLOCK */
1698 ret
= MSG_SendMessage(hwnd
, msg
, wParam
, lParam
, timeout
, SMSG_WIN32
,
1701 *resultp
= (DWORD
) msgRet
;
1706 /***********************************************************************
1707 * SendMessageTimeoutW (USER32.458)
1709 LRESULT WINAPI
SendMessageTimeoutW( HWND hwnd
, UINT msg
, WPARAM wParam
,
1710 LPARAM lParam
, UINT flags
,
1711 UINT timeout
, LPDWORD resultp
)
1716 /* FIXME: need support for SMTO_BLOCK */
1718 ret
= MSG_SendMessage(hwnd
, msg
, wParam
, lParam
, timeout
,
1719 SMSG_WIN32
| SMSG_UNICODE
, &msgRet
);
1721 *resultp
= (DWORD
) msgRet
;
1726 /***********************************************************************
1727 * WaitMessage (USER.112) (USER32.578) Suspend thread pending messages
1729 * WaitMessage() suspends a thread until events appear in the thread's
1734 * Is supposed to return BOOL under Win32.
1736 * Thread-local message queues are not supported.
1743 void WINAPI
WaitMessage( void )
1745 QUEUE_WaitBits( QS_ALLINPUT
, INFINITE
);
1748 /***********************************************************************
1749 * MsgWaitForMultipleObjects (USER32.400)
1751 DWORD WINAPI
MsgWaitForMultipleObjects( DWORD nCount
, HANDLE
*pHandles
,
1752 BOOL fWaitAll
, DWORD dwMilliseconds
,
1756 HANDLE handles
[MAXIMUM_WAIT_OBJECTS
];
1759 HQUEUE16 hQueue
= GetFastQueue16();
1760 MESSAGEQUEUE
*msgQueue
= (MESSAGEQUEUE
*)QUEUE_Lock( hQueue
);
1761 if (!msgQueue
) return WAIT_FAILED
;
1763 if (nCount
> MAXIMUM_WAIT_OBJECTS
-1)
1765 SetLastError( ERROR_INVALID_PARAMETER
);
1766 QUEUE_Unlock( msgQueue
);
1770 msgQueue
->changeBits
= 0;
1771 msgQueue
->wakeMask
= dwWakeMask
;
1773 if (THREAD_IsWin16(THREAD_Current()))
1776 * This is a temporary solution to a big problem.
1777 * You see, the main thread of all Win32 programs is created as a 16 bit
1778 * task. This means that if you want on an event using Win32 synchronization
1779 * methods, the 16 bit scheduler is stopped and things might just stop happening.
1780 * This implements a semi-busy loop that checks the handles to wait on and
1781 * also the message queue. When either one is ready, the wait function returns.
1783 * This will all go away when the real Win32 threads are implemented for all
1784 * the threads of an applications. Including the main thread.
1786 DWORD curTime
= GetCurrentTime();
1791 * Check the handles in the list.
1793 ret
= WaitForMultipleObjects(nCount
, pHandles
, fWaitAll
, 5L);
1796 * If the handles have been triggered, return.
1798 if (ret
!= WAIT_TIMEOUT
)
1802 * Then, let the 16 bit scheduler do it's thing.
1807 * If a message matching the wait mask has arrived, return.
1809 if (msgQueue
->changeBits
& dwWakeMask
)
1816 * And continue doing this until we hit the timeout.
1818 } while ((dwMilliseconds
== INFINITE
) || (GetCurrentTime()-curTime
< dwMilliseconds
) );
1822 /* Add the thread event to the handle list */
1823 for (i
= 0; i
< nCount
; i
++)
1824 handles
[i
] = pHandles
[i
];
1825 handles
[nCount
] = msgQueue
->hEvent
;
1829 ret
= WaitForMultipleObjects( nCount
+1, handles
, fWaitAll
, dwMilliseconds
);
1832 QUEUE_Unlock( msgQueue
);
1846 static const struct accent_char accent_chars
[] =
1848 /* A good idea should be to read /usr/X11/lib/X11/locale/iso8859-x/Compose */
1849 {'`', 'A', '\300'}, {'`', 'a', '\340'},
1850 {'\'', 'A', '\301'}, {'\'', 'a', '\341'},
1851 {'^', 'A', '\302'}, {'^', 'a', '\342'},
1852 {'~', 'A', '\303'}, {'~', 'a', '\343'},
1853 {'"', 'A', '\304'}, {'"', 'a', '\344'},
1854 {'O', 'A', '\305'}, {'o', 'a', '\345'},
1855 {'0', 'A', '\305'}, {'0', 'a', '\345'},
1856 {'A', 'A', '\305'}, {'a', 'a', '\345'},
1857 {'A', 'E', '\306'}, {'a', 'e', '\346'},
1858 {',', 'C', '\307'}, {',', 'c', '\347'},
1859 {'`', 'E', '\310'}, {'`', 'e', '\350'},
1860 {'\'', 'E', '\311'}, {'\'', 'e', '\351'},
1861 {'^', 'E', '\312'}, {'^', 'e', '\352'},
1862 {'"', 'E', '\313'}, {'"', 'e', '\353'},
1863 {'`', 'I', '\314'}, {'`', 'i', '\354'},
1864 {'\'', 'I', '\315'}, {'\'', 'i', '\355'},
1865 {'^', 'I', '\316'}, {'^', 'i', '\356'},
1866 {'"', 'I', '\317'}, {'"', 'i', '\357'},
1867 {'-', 'D', '\320'}, {'-', 'd', '\360'},
1868 {'~', 'N', '\321'}, {'~', 'n', '\361'},
1869 {'`', 'O', '\322'}, {'`', 'o', '\362'},
1870 {'\'', 'O', '\323'}, {'\'', 'o', '\363'},
1871 {'^', 'O', '\324'}, {'^', 'o', '\364'},
1872 {'~', 'O', '\325'}, {'~', 'o', '\365'},
1873 {'"', 'O', '\326'}, {'"', 'o', '\366'},
1874 {'/', 'O', '\330'}, {'/', 'o', '\370'},
1875 {'`', 'U', '\331'}, {'`', 'u', '\371'},
1876 {'\'', 'U', '\332'}, {'\'', 'u', '\372'},
1877 {'^', 'U', '\333'}, {'^', 'u', '\373'},
1878 {'"', 'U', '\334'}, {'"', 'u', '\374'},
1879 {'\'', 'Y', '\335'}, {'\'', 'y', '\375'},
1880 {'T', 'H', '\336'}, {'t', 'h', '\376'},
1881 {'s', 's', '\337'}, {'"', 'y', '\377'},
1882 {'s', 'z', '\337'}, {'i', 'j', '\377'},
1883 /* iso-8859-2 uses this */
1884 {'<', 'L', '\245'}, {'<', 'l', '\265'}, /* caron */
1885 {'<', 'S', '\251'}, {'<', 's', '\271'},
1886 {'<', 'T', '\253'}, {'<', 't', '\273'},
1887 {'<', 'Z', '\256'}, {'<', 'z', '\276'},
1888 {'<', 'C', '\310'}, {'<', 'c', '\350'},
1889 {'<', 'E', '\314'}, {'<', 'e', '\354'},
1890 {'<', 'D', '\317'}, {'<', 'd', '\357'},
1891 {'<', 'N', '\322'}, {'<', 'n', '\362'},
1892 {'<', 'R', '\330'}, {'<', 'r', '\370'},
1893 {';', 'A', '\241'}, {';', 'a', '\261'}, /* ogonek */
1894 {';', 'E', '\312'}, {';', 'e', '\332'},
1895 {'\'', 'Z', '\254'}, {'\'', 'z', '\274'}, /* acute */
1896 {'\'', 'R', '\300'}, {'\'', 'r', '\340'},
1897 {'\'', 'L', '\305'}, {'\'', 'l', '\345'},
1898 {'\'', 'C', '\306'}, {'\'', 'c', '\346'},
1899 {'\'', 'N', '\321'}, {'\'', 'n', '\361'},
1900 /* collision whith S, from iso-8859-9 !!! */
1901 {',', 'S', '\252'}, {',', 's', '\272'}, /* cedilla */
1902 {',', 'T', '\336'}, {',', 't', '\376'},
1903 {'.', 'Z', '\257'}, {'.', 'z', '\277'}, /* dot above */
1904 {'/', 'L', '\243'}, {'/', 'l', '\263'}, /* slash */
1905 {'/', 'D', '\320'}, {'/', 'd', '\360'},
1906 {'(', 'A', '\303'}, {'(', 'a', '\343'}, /* breve */
1907 {'\275', 'O', '\325'}, {'\275', 'o', '\365'}, /* double acute */
1908 {'\275', 'U', '\334'}, {'\275', 'u', '\374'},
1909 {'0', 'U', '\332'}, {'0', 'u', '\372'}, /* ring above */
1910 /* iso-8859-3 uses this */
1911 {'/', 'H', '\241'}, {'/', 'h', '\261'}, /* slash */
1912 {'>', 'H', '\246'}, {'>', 'h', '\266'}, /* circumflex */
1913 {'>', 'J', '\254'}, {'>', 'j', '\274'},
1914 {'>', 'C', '\306'}, {'>', 'c', '\346'},
1915 {'>', 'G', '\330'}, {'>', 'g', '\370'},
1916 {'>', 'S', '\336'}, {'>', 's', '\376'},
1917 /* collision whith G( from iso-8859-9 !!! */
1918 {'(', 'G', '\253'}, {'(', 'g', '\273'}, /* breve */
1919 {'(', 'U', '\335'}, {'(', 'u', '\375'},
1920 /* collision whith I. from iso-8859-3 !!! */
1921 {'.', 'I', '\251'}, {'.', 'i', '\271'}, /* dot above */
1922 {'.', 'C', '\305'}, {'.', 'c', '\345'},
1923 {'.', 'G', '\325'}, {'.', 'g', '\365'},
1924 /* iso-8859-4 uses this */
1925 {',', 'R', '\243'}, {',', 'r', '\263'}, /* cedilla */
1926 {',', 'L', '\246'}, {',', 'l', '\266'},
1927 {',', 'G', '\253'}, {',', 'g', '\273'},
1928 {',', 'N', '\321'}, {',', 'n', '\361'},
1929 {',', 'K', '\323'}, {',', 'k', '\363'},
1930 {'~', 'I', '\245'}, {'~', 'i', '\265'}, /* tilde */
1931 {'-', 'E', '\252'}, {'-', 'e', '\272'}, /* macron */
1932 {'-', 'A', '\300'}, {'-', 'a', '\340'},
1933 {'-', 'I', '\317'}, {'-', 'i', '\357'},
1934 {'-', 'O', '\322'}, {'-', 'o', '\362'},
1935 {'-', 'U', '\336'}, {'-', 'u', '\376'},
1936 {'/', 'T', '\254'}, {'/', 't', '\274'}, /* slash */
1937 {'.', 'E', '\314'}, {'.', 'e', '\344'}, /* dot above */
1938 {';', 'I', '\307'}, {';', 'i', '\347'}, /* ogonek */
1939 {';', 'U', '\331'}, {';', 'u', '\371'},
1940 /* iso-8859-9 uses this */
1941 /* iso-8859-9 has really bad choosen G( S, and I. as they collide
1942 * whith the same letters on other iso-8859-x (that is they are on
1943 * different places :-( ), if you use turkish uncomment these and
1944 * comment out the lines in iso-8859-2 and iso-8859-3 sections
1945 * FIXME: should be dynamic according to chosen language
1946 * if/when Wine has turkish support.
1948 /* collision whith G( from iso-8859-3 !!! */
1949 /* {'(', 'G', '\320'}, {'(', 'g', '\360'}, */ /* breve */
1950 /* collision whith S, from iso-8859-2 !!! */
1951 /* {',', 'S', '\336'}, {',', 's', '\376'}, */ /* cedilla */
1952 /* collision whith I. from iso-8859-3 !!! */
1953 /* {'.', 'I', '\335'}, {'.', 'i', '\375'}, */ /* dot above */
1957 /***********************************************************************
1958 * MSG_DoTranslateMessage
1960 * Implementation of TranslateMessage.
1962 * TranslateMessage translates virtual-key messages into character-messages,
1964 * WM_KEYDOWN/WM_KEYUP combinations produce a WM_CHAR or WM_DEADCHAR message.
1965 * ditto replacing WM_* with WM_SYS*
1966 * This produces WM_CHAR messages only for keys mapped to ASCII characters
1967 * by the keyboard driver.
1969 static BOOL
MSG_DoTranslateMessage( UINT message
, HWND hwnd
,
1970 WPARAM wParam
, LPARAM lParam
)
1972 static int dead_char
;
1975 if (message
!= WM_MOUSEMOVE
&& message
!= WM_TIMER
)
1976 TRACE(msg
, "(%s, %04X, %08lX)\n",
1977 SPY_GetMsgName(message
), wParam
, lParam
);
1978 if(message
>= WM_KEYFIRST
&& message
<= WM_KEYLAST
)
1979 TRACE(key
, "(%s, %04X, %08lX)\n",
1980 SPY_GetMsgName(message
), wParam
, lParam
);
1982 if ((message
!= WM_KEYDOWN
) && (message
!= WM_SYSKEYDOWN
)) return FALSE
;
1984 TRACE(key
, "Translating key %04X, scancode %04X\n",
1985 wParam
, HIWORD(lParam
) );
1987 /* FIXME : should handle ToAscii yielding 2 */
1988 switch (ToAscii(wParam
, HIWORD(lParam
),
1989 QueueKeyStateTable
,(LPWORD
)wp
, 0))
1992 message
= (message
== WM_KEYDOWN
) ? WM_CHAR
: WM_SYSCHAR
;
1993 /* Should dead chars handling go in ToAscii ? */
1998 if (wp
[0] == ' ') wp
[0] = dead_char
;
1999 if (dead_char
== 0xa2) dead_char
= '(';
2000 else if (dead_char
== 0xa8) dead_char
= '"';
2001 else if (dead_char
== 0xb2) dead_char
= ';';
2002 else if (dead_char
== 0xb4) dead_char
= '\'';
2003 else if (dead_char
== 0xb7) dead_char
= '<';
2004 else if (dead_char
== 0xb8) dead_char
= ',';
2005 else if (dead_char
== 0xff) dead_char
= '.';
2006 for (i
= 0; i
< sizeof(accent_chars
)/sizeof(accent_chars
[0]); i
++)
2007 if ((accent_chars
[i
].ac_accent
== dead_char
) &&
2008 (accent_chars
[i
].ac_char
== wp
[0]))
2010 wp
[0] = accent_chars
[i
].ac_result
;
2015 TRACE(key
, "1 -> PostMessage(%s)\n", SPY_GetMsgName(message
));
2016 PostMessage16( hwnd
, message
, wp
[0], lParam
);
2020 message
= (message
== WM_KEYDOWN
) ? WM_DEADCHAR
: WM_SYSDEADCHAR
;
2022 TRACE(key
, "-1 -> PostMessage(%s)\n",
2023 SPY_GetMsgName(message
));
2024 PostMessage16( hwnd
, message
, wp
[0], lParam
);
2031 /***********************************************************************
2032 * TranslateMessage16 (USER.113)
2034 BOOL16 WINAPI
TranslateMessage16( const MSG16
*msg
)
2036 return MSG_DoTranslateMessage( msg
->message
, msg
->hwnd
,
2037 msg
->wParam
, msg
->lParam
);
2041 /***********************************************************************
2042 * WIN16_TranslateMessage32 (USER.821)
2044 BOOL16 WINAPI
TranslateMessage32_16( const MSG32_16
*msg
, BOOL16 wHaveParamHigh
)
2049 wParam
= MAKELONG(msg
->msg
.wParam
, msg
->wParamHigh
);
2051 wParam
= (WPARAM
)msg
->msg
.wParam
;
2053 return MSG_DoTranslateMessage( msg
->msg
.message
, msg
->msg
.hwnd
,
2054 wParam
, msg
->msg
.lParam
);
2057 /***********************************************************************
2058 * TranslateMessage32 (USER32.556)
2060 BOOL WINAPI
TranslateMessage( const MSG
*msg
)
2062 return MSG_DoTranslateMessage( msg
->message
, msg
->hwnd
,
2063 msg
->wParam
, msg
->lParam
);
2067 /***********************************************************************
2068 * DispatchMessage16 (USER.114)
2070 LONG WINAPI
DispatchMessage16( const MSG16
* msg
)
2076 /* Process timer messages */
2077 if ((msg
->message
== WM_TIMER
) || (msg
->message
== WM_SYSTIMER
))
2081 return CallWindowProc16( (WNDPROC16
)msg
->lParam
, msg
->hwnd
,
2082 msg
->message
, msg
->wParam
, GetTickCount() );
2086 if (!msg
->hwnd
) return 0;
2087 if (!(wndPtr
= WIN_FindWndPtr( msg
->hwnd
))) return 0;
2088 if (!wndPtr
->winproc
)
2093 painting
= (msg
->message
== WM_PAINT
);
2094 if (painting
) wndPtr
->flags
|= WIN_NEEDS_BEGINPAINT
;
2096 SPY_EnterMessage( SPY_DISPATCHMESSAGE16
, msg
->hwnd
, msg
->message
,
2097 msg
->wParam
, msg
->lParam
);
2098 retval
= CallWindowProc16( (WNDPROC16
)wndPtr
->winproc
,
2099 msg
->hwnd
, msg
->message
,
2100 msg
->wParam
, msg
->lParam
);
2101 SPY_ExitMessage( SPY_RESULT_OK16
, msg
->hwnd
, msg
->message
, retval
);
2103 WIN_ReleaseWndPtr(wndPtr
);
2104 wndPtr
= WIN_FindWndPtr(msg
->hwnd
);
2105 if (painting
&& wndPtr
&&
2106 (wndPtr
->flags
& WIN_NEEDS_BEGINPAINT
) && wndPtr
->hrgnUpdate
)
2108 ERR(msg
, "BeginPaint not called on WM_PAINT for hwnd %04x!\n",
2110 wndPtr
->flags
&= ~WIN_NEEDS_BEGINPAINT
;
2111 /* Validate the update region to avoid infinite WM_PAINT loop */
2112 ValidateRect( msg
->hwnd
, NULL
);
2115 WIN_ReleaseWndPtr(wndPtr
);
2120 /***********************************************************************
2121 * WIN16_DispatchMessage32 (USER.822)
2123 LONG WINAPI
DispatchMessage32_16( const MSG32_16
* lpmsg16_32
, BOOL16 wHaveParamHigh
)
2125 if (wHaveParamHigh
== FALSE
)
2126 return DispatchMessage16(&(lpmsg16_32
->msg
));
2131 msg
.hwnd
= lpmsg16_32
->msg
.hwnd
;
2132 msg
.message
= lpmsg16_32
->msg
.message
;
2133 msg
.wParam
= MAKELONG(lpmsg16_32
->msg
.wParam
, lpmsg16_32
->wParamHigh
);
2134 msg
.lParam
= lpmsg16_32
->msg
.lParam
;
2135 msg
.time
= lpmsg16_32
->msg
.time
;
2136 msg
.pt
.x
= (INT
)lpmsg16_32
->msg
.pt
.x
;
2137 msg
.pt
.y
= (INT
)lpmsg16_32
->msg
.pt
.y
;
2138 return DispatchMessageA(&msg
);
2142 /***********************************************************************
2143 * DispatchMessage32A (USER32.141)
2145 LONG WINAPI
DispatchMessageA( const MSG
* msg
)
2151 /* Process timer messages */
2152 if ((msg
->message
== WM_TIMER
) || (msg
->message
== WM_SYSTIMER
))
2156 /* HOOK_CallHooks32A( WH_CALLWNDPROC, HC_ACTION, 0, FIXME ); */
2157 return CallWindowProcA( (WNDPROC
)msg
->lParam
, msg
->hwnd
,
2158 msg
->message
, msg
->wParam
, GetTickCount() );
2162 if (!msg
->hwnd
) return 0;
2163 if (!(wndPtr
= WIN_FindWndPtr( msg
->hwnd
))) return 0;
2164 if (!wndPtr
->winproc
)
2169 painting
= (msg
->message
== WM_PAINT
);
2170 if (painting
) wndPtr
->flags
|= WIN_NEEDS_BEGINPAINT
;
2171 /* HOOK_CallHooks32A( WH_CALLWNDPROC, HC_ACTION, 0, FIXME ); */
2173 SPY_EnterMessage( SPY_DISPATCHMESSAGE
, msg
->hwnd
, msg
->message
,
2174 msg
->wParam
, msg
->lParam
);
2175 retval
= CallWindowProcA( (WNDPROC
)wndPtr
->winproc
,
2176 msg
->hwnd
, msg
->message
,
2177 msg
->wParam
, msg
->lParam
);
2178 SPY_ExitMessage( SPY_RESULT_OK
, msg
->hwnd
, msg
->message
, retval
);
2180 WIN_ReleaseWndPtr(wndPtr
);
2181 wndPtr
= WIN_FindWndPtr(msg
->hwnd
);
2183 if (painting
&& wndPtr
&&
2184 (wndPtr
->flags
& WIN_NEEDS_BEGINPAINT
) && wndPtr
->hrgnUpdate
)
2186 ERR(msg
, "BeginPaint not called on WM_PAINT for hwnd %04x!\n",
2188 wndPtr
->flags
&= ~WIN_NEEDS_BEGINPAINT
;
2189 /* Validate the update region to avoid infinite WM_PAINT loop */
2190 ValidateRect( msg
->hwnd
, NULL
);
2193 WIN_ReleaseWndPtr(wndPtr
);
2198 /***********************************************************************
2199 * DispatchMessage32W (USER32.142) Process Message
2201 * Process the message specified in the structure *_msg_.
2203 * If the lpMsg parameter points to a WM_TIMER message and the
2204 * parameter of the WM_TIMER message is not NULL, the lParam parameter
2205 * points to the function that is called instead of the window
2208 * The message must be valid.
2212 * DispatchMessage() returns the result of the window procedure invoked.
2219 LONG WINAPI
DispatchMessageW( const MSG
* msg
)
2225 /* Process timer messages */
2226 if ((msg
->message
== WM_TIMER
) || (msg
->message
== WM_SYSTIMER
))
2230 /* HOOK_CallHooks32W( WH_CALLWNDPROC, HC_ACTION, 0, FIXME ); */
2231 return CallWindowProcW( (WNDPROC
)msg
->lParam
, msg
->hwnd
,
2232 msg
->message
, msg
->wParam
, GetTickCount() );
2236 if (!msg
->hwnd
) return 0;
2237 if (!(wndPtr
= WIN_FindWndPtr( msg
->hwnd
))) return 0;
2238 if (!wndPtr
->winproc
)
2243 painting
= (msg
->message
== WM_PAINT
);
2244 if (painting
) wndPtr
->flags
|= WIN_NEEDS_BEGINPAINT
;
2245 /* HOOK_CallHooks32W( WH_CALLWNDPROC, HC_ACTION, 0, FIXME ); */
2247 SPY_EnterMessage( SPY_DISPATCHMESSAGE
, msg
->hwnd
, msg
->message
,
2248 msg
->wParam
, msg
->lParam
);
2249 retval
= CallWindowProcW( (WNDPROC
)wndPtr
->winproc
,
2250 msg
->hwnd
, msg
->message
,
2251 msg
->wParam
, msg
->lParam
);
2252 SPY_ExitMessage( SPY_RESULT_OK
, msg
->hwnd
, msg
->message
, retval
);
2254 WIN_ReleaseWndPtr(wndPtr
);
2255 wndPtr
= WIN_FindWndPtr(msg
->hwnd
);
2257 if (painting
&& wndPtr
&&
2258 (wndPtr
->flags
& WIN_NEEDS_BEGINPAINT
) && wndPtr
->hrgnUpdate
)
2260 ERR(msg
, "BeginPaint not called on WM_PAINT for hwnd %04x!\n",
2262 wndPtr
->flags
&= ~WIN_NEEDS_BEGINPAINT
;
2263 /* Validate the update region to avoid infinite WM_PAINT loop */
2264 ValidateRect( msg
->hwnd
, NULL
);
2267 WIN_ReleaseWndPtr(wndPtr
);
2272 /***********************************************************************
2273 * RegisterWindowMessage16 (USER.118)
2275 WORD WINAPI
RegisterWindowMessage16( SEGPTR str
)
2277 TRACE(msg
, "%08lx\n", (DWORD
)str
);
2278 return GlobalAddAtom16( str
);
2282 /***********************************************************************
2283 * RegisterWindowMessage32A (USER32.437)
2285 WORD WINAPI
RegisterWindowMessageA( LPCSTR str
)
2287 TRACE(msg
, "%s\n", str
);
2288 return GlobalAddAtomA( str
);
2292 /***********************************************************************
2293 * RegisterWindowMessage32W (USER32.438)
2295 WORD WINAPI
RegisterWindowMessageW( LPCWSTR str
)
2297 TRACE(msg
, "%p\n", str
);
2298 return GlobalAddAtomW( str
);
2302 /***********************************************************************
2303 * GetTickCount (USER.13) (KERNEL32.299) System Time
2304 * Returns the number of milliseconds, modulo 2^32, since the start
2305 * of the current session.
2311 DWORD WINAPI
GetTickCount(void)
2314 gettimeofday( &t
, NULL
);
2315 /* make extremely compatible: granularity is 25 msec */
2316 return ((t
.tv_sec
* 1000) + (t
.tv_usec
/ 25000) * 25) - MSG_WineStartTicks
;
2320 /***********************************************************************
2321 * GetCurrentTime16 (USER.15)
2323 * (effectively identical to GetTickCount)
2325 DWORD WINAPI
GetCurrentTime16(void)
2327 return GetTickCount();
2331 /***********************************************************************
2332 * InSendMessage16 (USER.192)
2334 BOOL16 WINAPI
InSendMessage16(void)
2336 return InSendMessage();
2340 /***********************************************************************
2341 * InSendMessage32 (USER32.320)
2343 BOOL WINAPI
InSendMessage(void)
2345 MESSAGEQUEUE
*queue
;
2348 if (!(queue
= (MESSAGEQUEUE
*)QUEUE_Lock( GetFastQueue16() )))
2350 ret
= (BOOL
)queue
->smWaiting
;
2352 QUEUE_Unlock( queue
);
2356 /***********************************************************************
2357 * BroadcastSystemMessage (USER32.12)
2359 LONG WINAPI
BroadcastSystemMessage(
2360 DWORD dwFlags
,LPDWORD recipients
,UINT uMessage
,WPARAM wParam
,
2363 FIXME(sendmsg
,"(%08lx,%08lx,%08x,%08x,%08lx): stub!\n",
2364 dwFlags
,*recipients
,uMessage
,wParam
,lParam
2369 /***********************************************************************
2370 * SendNotifyMessageA (USER32.460)
2372 * The message sended with PostMessage has to be put in the queue
2373 * with a higher priority as the other "Posted" messages.
2374 * QUEUE_AddMsg has to be modifyed.
2376 BOOL WINAPI
SendNotifyMessageA(HWND hwnd
,UINT msg
,WPARAM wParam
,LPARAM lParam
)
2378 FIXME(msg
,"(%04x,%08x,%08x,%08lx) not complete\n",
2379 hwnd
, msg
, wParam
, lParam
);
2381 if ( GetCurrentThreadId() == GetWindowThreadProcessId ( hwnd
, NULL
))
2382 { ret
=SendMessageA ( hwnd
, msg
, wParam
, lParam
);
2385 { PostMessageA ( hwnd
, msg
, wParam
, lParam
);
2390 /***********************************************************************
2391 * SendNotifyMessageW (USER32.461)
2393 * The message sended with PostMessage has to be put in the queue
2394 * with a higher priority as the other "Posted" messages.
2395 * QUEUE_AddMsg has to be modifyed.
2397 BOOL WINAPI
SendNotifyMessageW(HWND hwnd
,UINT msg
,WPARAM wParam
,LPARAM lParam
)
2399 FIXME(msg
,"(%04x,%08x,%08x,%08lx) not complete\n",
2400 hwnd
, msg
, wParam
, lParam
);
2402 if ( GetCurrentThreadId() == GetWindowThreadProcessId ( hwnd
, NULL
))
2403 { ret
=SendMessageW ( hwnd
, msg
, wParam
, lParam
);
2406 { PostMessageW ( hwnd
, msg
, wParam
, lParam
);
2411 /***********************************************************************
2412 * SendMessageCallBack32A
2413 * FIXME: It's like PostMessage. The callback gets called when the message
2414 * is processed. We have to modify the message processing for a exact
2417 BOOL WINAPI
SendMessageCallBackA(
2418 HWND hWnd
,UINT Msg
,WPARAM wParam
,LPARAM lParam
,
2419 FARPROC lpResultCallBack
,DWORD dwData
)
2421 FIXME(msg
,"(0x%04x,0x%04x,0x%08x,0x%08lx,%p,0x%08lx),stub!\n",
2422 hWnd
,Msg
,wParam
,lParam
,lpResultCallBack
,dwData
);
2423 if ( hWnd
== HWND_BROADCAST
)
2424 { PostMessageA( hWnd
, Msg
, wParam
, lParam
);
2425 FIXME(msg
,"Broadcast: Callback will not be called!\n");
2428 (lpResultCallBack
)( hWnd
, Msg
, dwData
, SendMessageA ( hWnd
, Msg
, wParam
, lParam
));