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 DECLARE_DEBUG_CHANNEL(key
)
34 DECLARE_DEBUG_CHANNEL(msg
)
35 DECLARE_DEBUG_CHANNEL(sendmsg
)
37 #define WM_NCMOUSEFIRST WM_NCMOUSEMOVE
38 #define WM_NCMOUSELAST WM_NCMBUTTONDBLCLK
41 typedef enum { SYSQ_MSG_ABANDON
, SYSQ_MSG_SKIP
,
42 SYSQ_MSG_ACCEPT
, SYSQ_MSG_CONTINUE
} SYSQ_STATUS
;
44 extern HQUEUE16 hCursorQueue
; /* queue.c */
46 DWORD MSG_WineStartTicks
; /* Ticks at Wine startup */
48 static UINT doubleClickSpeed
= 452;
50 /***********************************************************************
53 BOOL
MSG_CheckFilter(DWORD uMsg
, DWORD first
, DWORD last
)
56 return (uMsg
>= first
&& uMsg
<= last
);
60 /***********************************************************************
61 * MSG_SendParentNotify
63 * Send a WM_PARENTNOTIFY to all ancestors of the given window, unless
64 * the window has the WS_EX_NOPARENTNOTIFY style.
66 static void MSG_SendParentNotify(WND
* wndPtr
, WORD event
, WORD idChild
, LPARAM lValue
)
68 #define lppt ((LPPOINT16)&lValue)
70 /* pt has to be in the client coordinates of the parent window */
71 WND
*tmpWnd
= WIN_LockWndPtr(wndPtr
);
73 MapWindowPoints16( 0, tmpWnd
->hwndSelf
, lppt
, 1 );
76 if (!(tmpWnd
->dwStyle
& WS_CHILD
) || (tmpWnd
->dwExStyle
& WS_EX_NOPARENTNOTIFY
))
78 WIN_ReleaseWndPtr(tmpWnd
);
81 lppt
->x
+= tmpWnd
->rectClient
.left
;
82 lppt
->y
+= tmpWnd
->rectClient
.top
;
83 WIN_UpdateWndPtr(&tmpWnd
,tmpWnd
->parent
);
84 SendMessageA( tmpWnd
->hwndSelf
, WM_PARENTNOTIFY
,
85 MAKEWPARAM( event
, idChild
), lValue
);
92 /***********************************************************************
93 * MSG_TranslateMouseMsg
95 * Translate an mouse hardware event into a real mouse message.
96 * Return value indicates whether the translated message must be passed
97 * to the user, left in the queue, or skipped entirely (in this case
98 * HIWORD contains hit test code).
100 static DWORD
MSG_TranslateMouseMsg( HWND hTopWnd
, DWORD first
, DWORD last
,
101 MSG
*msg
, BOOL remove
, WND
* pWndScope
)
103 static DWORD dblclk_time_limit
= 0;
104 static UINT16 clk_message
= 0;
105 static HWND16 clk_hwnd
= 0;
106 static POINT16 clk_pos
= { 0, 0 };
110 INT16 ht
, hittest
, sendSC
= 0;
111 UINT message
= msg
->message
;
112 POINT16 screen_pt
, pt
;
113 HANDLE16 hQ
= GetFastQueue16();
114 MESSAGEQUEUE
*queue
= (MESSAGEQUEUE
*)QUEUE_Lock(hQ
);
116 BOOL mouseClick
= ((message
== WM_LBUTTONDOWN
) ||
117 (message
== WM_RBUTTONDOWN
) ||
118 (message
== WM_MBUTTONDOWN
))?1:0;
122 /* Find the window */
124 CONV_POINT32TO16( &msg
->pt
, &pt
);
126 ht
= hittest
= HTCLIENT
;
130 ht
= hittest
= WINPOS_WindowFromPoint( pWndScope
, pt
, &pWnd
);
131 if( !pWnd
) pWnd
= WIN_GetDesktop();
132 else WIN_LockWndPtr(pWnd
);
133 hWnd
= pWnd
->hwndSelf
;
138 pWnd
= WIN_FindWndPtr(hWnd
);
140 ht
= PERQDATA_GetCaptureInfo( queue
->pQData
);
143 /* stop if not the right queue */
145 if (pWnd
->hmemTaskQ
!= hQ
)
147 /* Not for the current task */
148 if (queue
) QUEUE_ClearWakeBit( queue
, QS_MOUSE
);
149 /* Wake up the other task */
150 QUEUE_Unlock( queue
);
151 queue
= (MESSAGEQUEUE
*)QUEUE_Lock( pWnd
->hmemTaskQ
);
152 if (queue
) QUEUE_SetWakeBit( queue
, QS_MOUSE
);
154 QUEUE_Unlock( queue
);
155 retvalue
= SYSQ_MSG_ABANDON
;
159 /* check if hWnd is within hWndScope */
161 if( hTopWnd
&& hWnd
!= hTopWnd
)
162 if( !IsChild(hTopWnd
, hWnd
) )
164 QUEUE_Unlock( queue
);
165 retvalue
= SYSQ_MSG_CONTINUE
;
171 /* translate double clicks -
172 * note that ...MOUSEMOVEs can slip in between
173 * ...BUTTONDOWN and ...BUTTONDBLCLK messages */
175 if( pWnd
->class->style
& CS_DBLCLKS
|| ht
!= HTCLIENT
)
177 if ((message
== clk_message
) && (hWnd
== clk_hwnd
) &&
178 (msg
->time
- dblclk_time_limit
< doubleClickSpeed
) &&
179 (abs(msg
->pt
.x
- clk_pos
.x
) < SYSMETRICS_CXDOUBLECLK
/2) &&
180 (abs(msg
->pt
.y
- clk_pos
.y
) < SYSMETRICS_CYDOUBLECLK
/2))
182 message
+= (WM_LBUTTONDBLCLK
- WM_LBUTTONDOWN
);
183 mouseClick
++; /* == 2 */
189 if (hittest
!= HTCLIENT
)
191 message
+= WM_NCMOUSEMOVE
- WM_MOUSEMOVE
;
192 msg
->wParam
= hittest
;
194 else ScreenToClient16( hWnd
, &pt
);
196 /* check message filter */
198 if (!MSG_CheckFilter(message
, first
, last
))
201 retvalue
= SYSQ_MSG_CONTINUE
;
205 hCursorQueue
= queue
->self
;
211 if (HOOK_IsHooked( WH_MOUSE
))
213 MOUSEHOOKSTRUCT16
*hook
= SEGPTR_NEW(MOUSEHOOKSTRUCT16
);
216 hook
->pt
= screen_pt
;
218 hook
->wHitTestCode
= hittest
;
219 hook
->dwExtraInfo
= 0;
220 ret
= HOOK_CallHooks16( WH_MOUSE
, remove
? HC_ACTION
: HC_NOREMOVE
,
221 message
, (LPARAM
)SEGPTR_GET(hook
) );
226 retvalue
= MAKELONG((INT16
)SYSQ_MSG_SKIP
, hittest
);
233 if ((hittest
== HTERROR
) || (hittest
== HTNOWHERE
))
235 else if( remove
&& mouseClick
)
237 HWND hwndTop
= WIN_GetTopParent( hWnd
);
239 if( mouseClick
== 1 )
242 dblclk_time_limit
= msg
->time
;
243 clk_message
= msg
->message
;
247 /* got double click - zero them out */
248 dblclk_time_limit
= clk_hwnd
= 0;
252 /* Send the WM_PARENTNOTIFY,
253 * note that even for double/nonclient clicks
254 * notification message is still WM_L/M/RBUTTONDOWN.
257 MSG_SendParentNotify( pWnd
, msg
->message
& 0xffff, 0, MAKELPARAM(screen_pt
.x
, screen_pt
.y
) );
259 /* Activate the window if needed */
261 if (hWnd
!= GetActiveWindow() && hWnd
!= GetDesktopWindow())
263 LONG ret
= SendMessageA( hWnd
, WM_MOUSEACTIVATE
, hwndTop
,
264 MAKELONG( hittest
, message
) );
266 if ((ret
== MA_ACTIVATEANDEAT
) || (ret
== MA_NOACTIVATEANDEAT
))
269 if (((ret
== MA_ACTIVATE
) || (ret
== MA_ACTIVATEANDEAT
))
270 && hwndTop
!= GetActiveWindow() )
271 if (!WINPOS_SetActiveWindow( hwndTop
, TRUE
, TRUE
))
275 } else sendSC
= (remove
&& sendSC
);
277 /* Send the WM_SETCURSOR message */
280 SendMessageA( hWnd
, WM_SETCURSOR
, hWnd
,
281 MAKELONG( hittest
, message
));
284 retvalue
= MAKELONG( (UINT16
)SYSQ_MSG_SKIP
, hittest
);
289 msg
->message
= message
;
290 msg
->lParam
= MAKELONG( pt
.x
, pt
.y
);
291 retvalue
= SYSQ_MSG_ACCEPT
;
293 WIN_ReleaseWndPtr(pWnd
);
299 /***********************************************************************
300 * MSG_TranslateKbdMsg
302 * Translate an keyboard hardware event into a real message.
304 static DWORD
MSG_TranslateKbdMsg( HWND hTopWnd
, DWORD first
, DWORD last
,
305 MSG
*msg
, BOOL remove
)
307 WORD message
= msg
->message
;
308 HWND hWnd
= GetFocus();
311 /* Should check Ctrl-Esc and PrintScreen here */
315 /* Send the message to the active window instead, */
316 /* translating messages to their WM_SYS equivalent */
318 hWnd
= GetActiveWindow();
320 if( message
< WM_SYSKEYDOWN
)
321 message
+= WM_SYSKEYDOWN
- WM_KEYDOWN
;
323 pWnd
= WIN_FindWndPtr( hWnd
);
324 if (pWnd
&& (pWnd
->hmemTaskQ
!= GetFastQueue16()))
326 /* Not for the current task */
327 MESSAGEQUEUE
*queue
= (MESSAGEQUEUE
*)QUEUE_Lock( GetFastQueue16() );
328 if (queue
) QUEUE_ClearWakeBit( queue
, QS_KEY
);
329 QUEUE_Unlock( queue
);
331 /* Wake up the other task */
332 queue
= (MESSAGEQUEUE
*)QUEUE_Lock( pWnd
->hmemTaskQ
);
333 if (queue
) QUEUE_SetWakeBit( queue
, QS_KEY
);
334 QUEUE_Unlock( queue
);
335 WIN_ReleaseWndPtr(pWnd
);
336 return SYSQ_MSG_ABANDON
;
338 WIN_ReleaseWndPtr(pWnd
);
340 if (hTopWnd
&& hWnd
!= hTopWnd
)
341 if (!IsChild(hTopWnd
, hWnd
)) return SYSQ_MSG_CONTINUE
;
342 if (!MSG_CheckFilter(message
, first
, last
)) return SYSQ_MSG_CONTINUE
;
345 msg
->message
= message
;
347 return (HOOK_CallHooks16( WH_KEYBOARD
, remove
? HC_ACTION
: HC_NOREMOVE
,
348 LOWORD (msg
->wParam
), msg
->lParam
)
349 ? SYSQ_MSG_SKIP
: SYSQ_MSG_ACCEPT
);
353 /***********************************************************************
354 * MSG_JournalRecordMsg
356 * Build an EVENTMSG structure and call JOURNALRECORD hook
358 static void MSG_JournalRecordMsg( MSG
*msg
)
360 EVENTMSG
*event
= (EVENTMSG
*) HeapAlloc(SystemHeap
, 0, sizeof(EVENTMSG
));
362 event
->message
= msg
->message
;
363 event
->time
= msg
->time
;
364 if ((msg
->message
>= WM_KEYFIRST
) && (msg
->message
<= WM_KEYLAST
))
366 event
->paramL
= (msg
->wParam
& 0xFF) | (HIWORD(msg
->lParam
) << 8);
367 event
->paramH
= msg
->lParam
& 0x7FFF;
368 if (HIWORD(msg
->lParam
) & 0x0100)
369 event
->paramH
|= 0x8000; /* special_key - bit */
370 HOOK_CallHooksA( WH_JOURNALRECORD
, HC_ACTION
, 0, (LPARAM
)event
);
372 else if ((msg
->message
>= WM_MOUSEFIRST
) && (msg
->message
<= WM_MOUSELAST
))
374 event
->paramL
= LOWORD(msg
->lParam
); /* X pos */
375 event
->paramH
= HIWORD(msg
->lParam
); /* Y pos */
376 ClientToScreen16( msg
->hwnd
, (LPPOINT16
)&event
->paramL
);
377 HOOK_CallHooksA( WH_JOURNALRECORD
, HC_ACTION
, 0, (LPARAM
)event
);
379 else if ((msg
->message
>= WM_NCMOUSEFIRST
) &&
380 (msg
->message
<= WM_NCMOUSELAST
))
382 event
->paramL
= LOWORD(msg
->lParam
); /* X pos */
383 event
->paramH
= HIWORD(msg
->lParam
); /* Y pos */
384 event
->message
+= WM_MOUSEMOVE
-WM_NCMOUSEMOVE
;/* give no info about NC area */
385 HOOK_CallHooksA( WH_JOURNALRECORD
, HC_ACTION
, 0, (LPARAM
)event
);
388 HeapFree(SystemHeap
, 0, event
);
391 /***********************************************************************
392 * MSG_JournalPlayBackMsg
394 * Get an EVENTMSG struct via call JOURNALPLAYBACK hook function
396 static int MSG_JournalPlayBackMsg(void)
399 long wtime
,lParam
,wParam
;
400 WORD keyDown
,i
,result
=0;
402 if ( HOOK_IsHooked( WH_JOURNALPLAYBACK
) )
404 tmpMsg
= (EVENTMSG
*) HeapAlloc(SystemHeap
, 0, sizeof(EVENTMSG
));
405 if (!tmpMsg
) return result
;
407 wtime
=HOOK_CallHooksA( WH_JOURNALPLAYBACK
, HC_GETNEXT
, 0,
409 /* TRACE(msg,"Playback wait time =%ld\n",wtime); */
413 if ((tmpMsg
->message
>= WM_KEYFIRST
) && (tmpMsg
->message
<= WM_KEYLAST
))
415 wParam
=tmpMsg
->paramL
& 0xFF;
416 lParam
=MAKELONG(tmpMsg
->paramH
&0x7ffff,tmpMsg
->paramL
>>8);
417 if (tmpMsg
->message
== WM_KEYDOWN
|| tmpMsg
->message
== WM_SYSKEYDOWN
)
419 for (keyDown
=i
=0; i
<256 && !keyDown
; i
++)
420 if (InputKeyStateTable
[i
] & 0x80)
423 lParam
|= 0x40000000;
424 AsyncKeyStateTable
[wParam
]=InputKeyStateTable
[wParam
] |= 0x80;
426 else /* WM_KEYUP, WM_SYSKEYUP */
428 lParam
|= 0xC0000000;
429 AsyncKeyStateTable
[wParam
]=InputKeyStateTable
[wParam
] &= ~0x80;
431 if (InputKeyStateTable
[VK_MENU
] & 0x80)
432 lParam
|= 0x20000000;
433 if (tmpMsg
->paramH
& 0x8000) /*special_key bit*/
434 lParam
|= 0x01000000;
435 hardware_event( tmpMsg
->message
& 0xffff, LOWORD(wParam
), lParam
,
436 0, 0, tmpMsg
->time
, 0 );
440 if ((tmpMsg
->message
>= WM_MOUSEFIRST
) && (tmpMsg
->message
<= WM_MOUSELAST
))
442 switch (tmpMsg
->message
)
445 MouseButtonsStates
[0]=AsyncMouseButtonsStates
[0]=TRUE
;break;
447 MouseButtonsStates
[0]=AsyncMouseButtonsStates
[0]=FALSE
;break;
449 MouseButtonsStates
[1]=AsyncMouseButtonsStates
[1]=TRUE
;break;
451 MouseButtonsStates
[1]=AsyncMouseButtonsStates
[1]=FALSE
;break;
453 MouseButtonsStates
[2]=AsyncMouseButtonsStates
[2]=TRUE
;break;
455 MouseButtonsStates
[2]=AsyncMouseButtonsStates
[2]=FALSE
;break;
457 AsyncKeyStateTable
[VK_LBUTTON
]= InputKeyStateTable
[VK_LBUTTON
] = MouseButtonsStates
[0] ? 0x80 : 0;
458 AsyncKeyStateTable
[VK_MBUTTON
]= InputKeyStateTable
[VK_MBUTTON
] = MouseButtonsStates
[1] ? 0x80 : 0;
459 AsyncKeyStateTable
[VK_RBUTTON
]= InputKeyStateTable
[VK_RBUTTON
] = MouseButtonsStates
[2] ? 0x80 : 0;
460 SetCursorPos(tmpMsg
->paramL
,tmpMsg
->paramH
);
461 lParam
=MAKELONG(tmpMsg
->paramL
,tmpMsg
->paramH
);
463 if (MouseButtonsStates
[0]) wParam
|= MK_LBUTTON
;
464 if (MouseButtonsStates
[1]) wParam
|= MK_MBUTTON
;
465 if (MouseButtonsStates
[2]) wParam
|= MK_RBUTTON
;
466 hardware_event( tmpMsg
->message
& 0xffff, LOWORD (wParam
), lParam
,
467 tmpMsg
->paramL
, tmpMsg
->paramH
, tmpMsg
->time
, 0 );
470 HOOK_CallHooksA( WH_JOURNALPLAYBACK
, HC_SKIP
, 0,
476 if( tmpMsg
->message
== WM_QUEUESYNC
)
477 if (HOOK_IsHooked( WH_CBT
))
478 HOOK_CallHooksA( WH_CBT
, HCBT_QS
, 0, 0L);
480 result
= QS_MOUSE
| QS_KEY
; /* ? */
482 HeapFree(SystemHeap
, 0, tmpMsg
);
487 /***********************************************************************
488 * MSG_PeekHardwareMsg
490 * Peek for a hardware message matching the hwnd and message filters.
492 static BOOL
MSG_PeekHardwareMsg( MSG
*msg
, HWND hwnd
, DWORD first
, DWORD last
,
495 /* FIXME: should deal with MSG32 instead of MSG16 */
497 DWORD status
= SYSQ_MSG_ACCEPT
;
498 MESSAGEQUEUE
*sysMsgQueue
= QUEUE_GetSysQueue();
500 QMSG
*nextqmsg
, *qmsg
= 0;
502 /* FIXME: there has to be a better way to do this */
505 EnterCriticalSection(&sysMsgQueue
->cSection
);
507 qmsg
= sysMsgQueue
->firstMsg
;
509 /* If the queue is empty, attempt to fill it */
510 if (!sysMsgQueue
->msgCount
&& THREAD_IsWin16( THREAD_Current() )
513 LeaveCriticalSection(&sysMsgQueue
->cSection
);
514 EVENT_WaitNetEvent( FALSE
, TRUE
);
515 EnterCriticalSection(&sysMsgQueue
->cSection
);
518 for ( kbd_msg
= 0; qmsg
; qmsg
= nextqmsg
)
523 nextqmsg
= qmsg
->nextMsg
;
525 /* Translate message */
527 if ((msg
->message
>= WM_MOUSEFIRST
) && (msg
->message
<= WM_MOUSELAST
))
530 HWND hWndScope
= (HWND
)qmsg
->extraInfo
;
531 WND
*tmpWnd
= (Options
.managed
&& IsWindow(hWndScope
) )
532 ? WIN_FindWndPtr(hWndScope
) : WIN_GetDesktop();
534 status
= MSG_TranslateMouseMsg(hwnd
, first
, last
, msg
, remove
,tmpWnd
);
537 WIN_ReleaseWndPtr(tmpWnd
);
540 else if ((msg
->message
>= WM_KEYFIRST
) && (msg
->message
<= WM_KEYLAST
))
542 status
= MSG_TranslateKbdMsg(hwnd
, first
, last
, msg
, remove
);
545 else /* Non-standard hardware event */
547 HARDWAREHOOKSTRUCT16
*hook
;
548 if ((hook
= SEGPTR_NEW(HARDWAREHOOKSTRUCT16
)))
551 hook
->hWnd
= msg
->hwnd
;
552 hook
->wMessage
= msg
->message
& 0xffff;
553 hook
->wParam
= LOWORD (msg
->wParam
);
554 hook
->lParam
= msg
->lParam
;
555 ret
= HOOK_CallHooks16( WH_HARDWARE
,
556 remove
? HC_ACTION
: HC_NOREMOVE
,
557 0, (LPARAM
)SEGPTR_GET(hook
) );
561 QUEUE_RemoveMsg( sysMsgQueue
, qmsg
);
564 status
= SYSQ_MSG_ACCEPT
;
568 switch (LOWORD(status
))
570 case SYSQ_MSG_ACCEPT
:
574 if (HOOK_IsHooked( WH_CBT
))
577 HOOK_CallHooks16( WH_CBT
, HCBT_KEYSKIPPED
,
578 LOWORD (msg
->wParam
), msg
->lParam
);
581 MOUSEHOOKSTRUCT16
*hook
= SEGPTR_NEW(MOUSEHOOKSTRUCT16
);
584 CONV_POINT32TO16( &msg
->pt
,&hook
->pt
);
585 hook
->hwnd
= msg
->hwnd
;
586 hook
->wHitTestCode
= HIWORD(status
);
587 hook
->dwExtraInfo
= 0;
588 HOOK_CallHooks16( WH_CBT
, HCBT_CLICKSKIPPED
,msg
->message
& 0xffff,
589 (LPARAM
)SEGPTR_GET(hook
) );
596 QUEUE_RemoveMsg( sysMsgQueue
, qmsg
);
599 case SYSQ_MSG_CONTINUE
:
602 case SYSQ_MSG_ABANDON
:
603 LeaveCriticalSection(&sysMsgQueue
->cSection
);
609 if (HOOK_IsHooked( WH_JOURNALRECORD
)) MSG_JournalRecordMsg( msg
);
610 QUEUE_RemoveMsg( sysMsgQueue
, qmsg
);
612 LeaveCriticalSection(&sysMsgQueue
->cSection
);
615 LeaveCriticalSection(&sysMsgQueue
->cSection
);
620 /**********************************************************************
621 * SetDoubleClickTime16 (USER.20)
623 void WINAPI
SetDoubleClickTime16( UINT16 interval
)
625 SetDoubleClickTime( interval
);
629 /**********************************************************************
630 * SetDoubleClickTime32 (USER32.480)
632 BOOL WINAPI
SetDoubleClickTime( UINT interval
)
634 doubleClickSpeed
= interval
? interval
: 500;
639 /**********************************************************************
640 * GetDoubleClickTime16 (USER.21)
642 UINT16 WINAPI
GetDoubleClickTime16(void)
644 return doubleClickSpeed
;
648 /**********************************************************************
649 * GetDoubleClickTime32 (USER32.239)
651 UINT WINAPI
GetDoubleClickTime(void)
653 return doubleClickSpeed
;
657 /***********************************************************************
658 * MSG_SendMessageInterThread
660 * Implementation of an inter-task SendMessage.
662 * 0 if error or timeout
665 static LRESULT
MSG_SendMessageInterThread( HQUEUE16 hDestQueue
,
667 WPARAM wParam
, LPARAM lParam
,
668 DWORD timeout
, WORD flags
,
671 MESSAGEQUEUE
*queue
, *destQ
;
678 if (IsTaskLocked16() || !IsWindow(hwnd
))
681 /* create a SMSG structure to hold SendMessage() parameters */
682 if (! (smsg
= (SMSG
*) HeapAlloc( SystemHeap
, 0, sizeof(SMSG
) )) )
684 if (!(queue
= (MESSAGEQUEUE
*)QUEUE_Lock( GetFastQueue16() ))) return 0;
686 if (!(destQ
= (MESSAGEQUEUE
*)QUEUE_Lock( hDestQueue
)))
688 QUEUE_Unlock( queue
);
692 TRACE(sendmsg
,"SM: %s [%04x] (%04x -> %04x)\n",
693 SPY_GetMsgName(msg
), msg
, queue
->self
, hDestQueue
);
695 /* fill up SMSG structure */
698 smsg
->wParam
= wParam
;
699 smsg
->lParam
= lParam
;
702 smsg
->hSrcQueue
= GetFastQueue16();
703 smsg
->hDstQueue
= hDestQueue
;
706 /* add smsg struct in the processing SM list of the source queue */
707 QUEUE_AddSMSG(queue
, SM_PROCESSING_LIST
, smsg
);
709 /* add smsg struct in the pending list of the destination queue */
710 if (QUEUE_AddSMSG(destQ
, SM_PENDING_LIST
, smsg
) == FALSE
)
713 iWndsLocks
= WIN_SuspendWndsLock();
715 /* force destination task to run next, if 16 bit threads */
716 if ( THREAD_IsWin16(THREAD_Current()) && THREAD_IsWin16(destQ
->thdb
) )
717 DirectedYield16( destQ
->thdb
->teb
.htask16
);
719 /* wait for the result, note that 16-bit apps almost always get out of
720 * DirectedYield() with SMSG_HAVE_RESULT flag already set */
725 * The sequence is crucial to avoid deadlock situations:
726 * - first, we clear the QS_SMRESULT bit
727 * - then, we check the SMSG_HAVE_RESULT bit
728 * - only if this isn't set, we enter the wait state.
730 * As the receiver first sets the SMSG_HAVE_RESULT and then wakes us,
731 * we are guaranteed that -should we now clear the QS_SMRESULT that
732 * was signalled already by the receiver- we will not start waiting.
735 if ( smsg
->flags
& SMSG_HAVE_RESULT
)
738 *pRes
= smsg
->lResult
;
739 TRACE(sendmsg
,"smResult = %08x\n", (unsigned)*pRes
);
743 QUEUE_ClearWakeBit( queue
, QS_SMRESULT
);
745 if ( smsg
->flags
& SMSG_HAVE_RESULT
)
748 if( QUEUE_WaitBits( QS_SMRESULT
, timeout
) == 0 )
750 /* return with timeout */
756 WIN_RestoreWndsLock(iWndsLocks
);
758 /* remove the smsg from the processingg list of the source queue */
759 QUEUE_RemoveSMSG( queue
, SM_PROCESSING_LIST
, smsg
);
761 /* Note: the destination thread is in charge of removing the smsg from
764 /* In the case of an early reply (or a timeout), sender thread will
765 released the smsg structure if the receiver thread is done
766 (SMSG_RECEIVED set). If the receiver thread isn't done,
767 SMSG_RECEIVER_CLEANS_UP flag is set, and it will be the receiver
768 responsability to released smsg */
769 EnterCriticalSection( &queue
->cSection
);
771 if (smsg
->flags
& SMSG_RECEIVED
)
772 HeapFree(SystemHeap
, 0, smsg
);
774 smsg
->flags
|= SMSG_RECEIVER_CLEANS
;
776 LeaveCriticalSection( &queue
->cSection
);
779 QUEUE_Unlock( queue
);
780 QUEUE_Unlock( destQ
);
782 TRACE(sendmsg
,"done!\n");
787 /***********************************************************************
788 * ReplyMessage16 (USER.115)
790 void WINAPI
ReplyMessage16( LRESULT result
)
792 ReplyMessage( result
);
795 /***********************************************************************
796 * ReplyMessage (USER.115)
798 BOOL WINAPI
ReplyMessage( LRESULT result
)
800 MESSAGEQUEUE
*senderQ
= 0;
801 MESSAGEQUEUE
*queue
= 0;
805 if (!(queue
= (MESSAGEQUEUE
*)QUEUE_Lock( GetFastQueue16() )))
808 TRACE(sendmsg
,"ReplyMessage, queue %04x\n", queue
->self
);
811 if ( !(smsg
= queue
->smWaiting
)
812 || !(senderQ
= QUEUE_Lock( smsg
->hSrcQueue
)) )
813 goto ReplyMessageEnd
;
815 if ( !(smsg
->flags
& SMSG_ALREADY_REPLIED
) )
817 /* This is the first reply, so pass result to sender */
819 TRACE( sendmsg
,"\trpm: smResult = %08lx\n", (long) result
);
821 EnterCriticalSection(&senderQ
->cSection
);
823 smsg
->lResult
= result
;
824 smsg
->flags
|= SMSG_ALREADY_REPLIED
;
826 /* check if it's an early reply (called by the application) or
827 a regular reply (called by ReceiveMessage) */
828 if ( !(smsg
->flags
& SMSG_SENDING_REPLY
) )
829 smsg
->flags
|= SMSG_EARLY_REPLY
;
831 smsg
->flags
|= SMSG_HAVE_RESULT
;
833 LeaveCriticalSection(&senderQ
->cSection
);
835 /* tell the sending task that its reply is ready */
836 QUEUE_SetWakeBit( senderQ
, QS_SMRESULT
);
838 /* switch directly to sending task (16 bit thread only) */
839 if ( THREAD_IsWin16( THREAD_Current() ) && THREAD_IsWin16( senderQ
->thdb
) )
840 DirectedYield16( senderQ
->thdb
->teb
.htask16
);
845 if (smsg
->flags
& SMSG_SENDING_REPLY
)
847 /* remove msg from the waiting list, since this is the last
849 QUEUE_RemoveSMSG( queue
, SM_WAITING_LIST
, smsg
);
851 EnterCriticalSection(&senderQ
->cSection
);
853 /* tell the sender we're all done with smsg structure */
854 smsg
->flags
|= SMSG_RECEIVED
;
856 /* sender will set SMSG_RECEIVER_CLEANS_UP if it wants the
857 receiver to clean up smsg, it could only happens when there is
858 an early reply or a timeout */
859 if ( smsg
->flags
& SMSG_RECEIVER_CLEANS
)
861 TRACE( sendmsg
,"Receiver cleans up!\n" );
862 HeapFree( SystemHeap
, 0, smsg
);
865 LeaveCriticalSection(&senderQ
->cSection
);
870 QUEUE_Unlock( senderQ
);
872 QUEUE_Unlock( queue
);
877 /***********************************************************************
880 static BOOL
MSG_PeekMessage( LPMSG msg
, HWND hwnd
, DWORD first
, DWORD last
,
881 WORD flags
, BOOL peek
)
884 MESSAGEQUEUE
*msgQueue
;
890 DDE_TestDDE(hwnd
); /* do we have dde handling in the window ?*/
891 DDE_GetRemoteMessage();
892 #endif /* CONFIG_IPC */
894 mask
= QS_POSTMESSAGE
| QS_SENDMESSAGE
; /* Always selected */
897 if ((first
<= WM_KEYLAST
) && (last
>= WM_KEYFIRST
)) mask
|= QS_KEY
;
898 if ( ((first
<= WM_MOUSELAST
) && (last
>= WM_MOUSEFIRST
)) ||
899 ((first
<= WM_NCMOUSELAST
) && (last
>= WM_NCMOUSEFIRST
)) ) mask
|= QS_MOUSE
;
900 if ((first
<= WM_TIMER
) && (last
>= WM_TIMER
)) mask
|= QS_TIMER
;
901 if ((first
<= WM_SYSTIMER
) && (last
>= WM_SYSTIMER
)) mask
|= QS_TIMER
;
902 if ((first
<= WM_PAINT
) && (last
>= WM_PAINT
)) mask
|= QS_PAINT
;
904 else mask
|= QS_MOUSE
| QS_KEY
| QS_TIMER
| QS_PAINT
;
906 if (IsTaskLocked16()) flags
|= PM_NOYIELD
;
908 /* Never yield on Win32 threads */
909 if (!THREAD_IsWin16(THREAD_Current())) flags
|= PM_NOYIELD
;
911 iWndsLocks
= WIN_SuspendWndsLock();
917 hQueue
= GetFastQueue16();
918 msgQueue
= (MESSAGEQUEUE
*)QUEUE_Lock( hQueue
);
921 WIN_RestoreWndsLock(iWndsLocks
);
924 msgQueue
->changeBits
= 0;
926 /* First handle a message put by SendMessage() */
928 while (msgQueue
->wakeBits
& QS_SENDMESSAGE
)
929 QUEUE_ReceiveMessage( msgQueue
);
931 /* Now handle a WM_QUIT message */
933 if (msgQueue
->wPostQMsg
&&
934 (!first
|| WM_QUIT
>= first
) &&
935 (!last
|| WM_QUIT
<= last
) )
938 msg
->message
= WM_QUIT
;
939 msg
->wParam
= msgQueue
->wExitCode
;
941 if (flags
& PM_REMOVE
) msgQueue
->wPostQMsg
= 0;
945 /* Now find a normal message */
947 if (((msgQueue
->wakeBits
& mask
) & QS_POSTMESSAGE
) &&
948 ((qmsg
= QUEUE_FindMsg( msgQueue
, hwnd
, first
, last
)) != 0))
952 msgQueue
->GetMessageTimeVal
= msg
->time
;
953 CONV_POINT32TO16(&msg
->pt
, &pt16
);
954 msgQueue
->GetMessagePosVal
= *(DWORD
*)&pt16
;
955 msgQueue
->GetMessageExtraInfoVal
= qmsg
->extraInfo
;
957 if (flags
& PM_REMOVE
) QUEUE_RemoveMsg( msgQueue
, qmsg
);
961 msgQueue
->changeBits
|= MSG_JournalPlayBackMsg();
963 /* Now find a hardware event */
965 if (((msgQueue
->wakeBits
& mask
) & (QS_MOUSE
| QS_KEY
)) &&
966 MSG_PeekHardwareMsg( msg
, hwnd
, first
, last
, flags
& PM_REMOVE
))
969 msgQueue
->GetMessageTimeVal
= msg
->time
;
970 CONV_POINT32TO16(&msg
->pt
, &pt16
);
971 msgQueue
->GetMessagePosVal
= *(DWORD
*)&pt16
;
972 msgQueue
->GetMessageExtraInfoVal
= 0; /* Always 0 for now */
976 /* Check again for SendMessage */
978 while (msgQueue
->wakeBits
& QS_SENDMESSAGE
)
979 QUEUE_ReceiveMessage( msgQueue
);
981 /* Now find a WM_PAINT message */
983 if ((msgQueue
->wakeBits
& mask
) & QS_PAINT
)
986 msg
->hwnd
= WIN_FindWinToRepaint( hwnd
, hQueue
);
987 msg
->message
= WM_PAINT
;
991 if ((wndPtr
= WIN_FindWndPtr(msg
->hwnd
)))
993 if( wndPtr
->dwStyle
& WS_MINIMIZE
&&
994 wndPtr
->class->hIcon
)
996 msg
->message
= WM_PAINTICON
;
1000 if( !hwnd
|| msg
->hwnd
== hwnd
|| IsChild16(hwnd
,msg
->hwnd
) )
1002 if( wndPtr
->flags
& WIN_INTERNAL_PAINT
&& !wndPtr
->hrgnUpdate
)
1004 wndPtr
->flags
&= ~WIN_INTERNAL_PAINT
;
1005 QUEUE_DecPaintCount( hQueue
);
1007 WIN_ReleaseWndPtr(wndPtr
);
1010 WIN_ReleaseWndPtr(wndPtr
);
1014 /* Check for timer messages, but yield first */
1016 if (!(flags
& PM_NOYIELD
))
1019 while (msgQueue
->wakeBits
& QS_SENDMESSAGE
)
1020 QUEUE_ReceiveMessage( msgQueue
);
1022 if ((msgQueue
->wakeBits
& mask
) & QS_TIMER
)
1024 if (TIMER_GetTimerMsg(msg
, hwnd
, hQueue
, flags
& PM_REMOVE
)) break;
1029 if (!(flags
& PM_NOYIELD
)) UserYield16();
1031 QUEUE_Unlock( msgQueue
);
1032 WIN_RestoreWndsLock(iWndsLocks
);
1035 msgQueue
->wakeMask
= mask
;
1036 QUEUE_WaitBits( mask
, INFINITE
);
1037 QUEUE_Unlock( msgQueue
);
1040 WIN_RestoreWndsLock(iWndsLocks
);
1042 /* instead of unlocking queue for every break condition, all break
1043 condition will fall here */
1044 QUEUE_Unlock( msgQueue
);
1046 /* We got a message */
1047 if (flags
& PM_REMOVE
)
1049 WORD message
= msg
->message
;
1051 if (message
== WM_KEYDOWN
|| message
== WM_SYSKEYDOWN
)
1053 BYTE
*p
= &QueueKeyStateTable
[msg
->wParam
& 0xff];
1059 else if (message
== WM_KEYUP
|| message
== WM_SYSKEYUP
)
1060 QueueKeyStateTable
[msg
->wParam
& 0xff] &= ~0x80;
1067 return (msg
->message
!= WM_QUIT
);
1070 /***********************************************************************
1071 * MSG_InternalGetMessage
1073 * GetMessage() function for internal use. Behave like GetMessage(),
1074 * but also call message filters and optionally send WM_ENTERIDLE messages.
1075 * 'hwnd' must be the handle of the dialog or menu window.
1076 * 'code' is the message filter value (MSGF_??? codes).
1078 BOOL
MSG_InternalGetMessage( MSG
*msg
, HWND hwnd
, HWND hwndOwner
,
1079 WPARAM code
, WORD flags
, BOOL sendIdle
)
1085 if (!MSG_PeekMessage( msg
, 0, 0, 0, flags
, TRUE
))
1087 /* No message present -> send ENTERIDLE and wait */
1088 if (IsWindow(hwndOwner
))
1089 SendMessageA( hwndOwner
, WM_ENTERIDLE
,
1090 code
, (LPARAM
)hwnd
);
1091 MSG_PeekMessage( msg
, 0, 0, 0, flags
, FALSE
);
1094 else /* Always wait for a message */
1095 MSG_PeekMessage( msg
, 0, 0, 0, flags
, FALSE
);
1097 /* Call message filters */
1099 if (HOOK_IsHooked( WH_SYSMSGFILTER
) || HOOK_IsHooked( WH_MSGFILTER
))
1101 MSG
*pmsg
= HeapAlloc( SystemHeap
, 0, sizeof(MSG
) );
1106 ret
= (HOOK_CallHooksA( WH_SYSMSGFILTER
, code
, 0,
1108 HOOK_CallHooksA( WH_MSGFILTER
, code
, 0,
1111 HeapFree( SystemHeap
, 0, pmsg
);
1114 /* Message filtered -> remove it from the queue */
1115 /* if it's still there. */
1116 if (!(flags
& PM_REMOVE
))
1117 MSG_PeekMessage( msg
, 0, 0, 0, PM_REMOVE
, TRUE
);
1123 return (msg
->message
!= WM_QUIT
);
1128 /***********************************************************************
1129 * PeekMessage16 (USER.109)
1131 BOOL16 WINAPI
PeekMessage16( LPMSG16 lpmsg
, HWND16 hwnd
, UINT16 first
,
1132 UINT16 last
, UINT16 flags
)
1136 ret
= PeekMessageA(&msg32
, hwnd
, first
, last
, flags
);
1137 STRUCT32_MSG32to16(&msg32
, lpmsg
);
1141 /***********************************************************************
1142 * WIN16_PeekMessage32 (USER.819)
1144 BOOL16 WINAPI
PeekMessage32_16( LPMSG16_32 lpmsg16_32
, HWND16 hwnd
,
1145 UINT16 first
, UINT16 last
, UINT16 flags
, BOOL16 wHaveParamHigh
)
1147 if (wHaveParamHigh
== FALSE
)
1149 lpmsg16_32
->wParamHigh
= 0;
1150 return PeekMessage16(&(lpmsg16_32
->msg
), hwnd
, first
, last
, flags
);
1157 ret
= (BOOL16
)PeekMessageA(&msg32
, (HWND
)hwnd
,
1158 (UINT
)first
, (UINT
)last
, (UINT
)flags
);
1159 lpmsg16_32
->msg
.hwnd
= msg32
.hwnd
;
1160 lpmsg16_32
->msg
.message
= msg32
.message
;
1161 lpmsg16_32
->msg
.wParam
= LOWORD(msg32
.wParam
);
1162 lpmsg16_32
->msg
.lParam
= msg32
.lParam
;
1163 lpmsg16_32
->msg
.time
= msg32
.time
;
1164 lpmsg16_32
->msg
.pt
.x
= (INT16
)msg32
.pt
.x
;
1165 lpmsg16_32
->msg
.pt
.y
= (INT16
)msg32
.pt
.y
;
1166 lpmsg16_32
->wParamHigh
= HIWORD(msg32
.wParam
);
1172 /***********************************************************************
1175 BOOL WINAPI
PeekMessageA( LPMSG lpmsg
, HWND hwnd
,
1176 UINT min
,UINT max
,UINT wRemoveMsg
)
1178 return MSG_PeekMessage( lpmsg
, hwnd
, min
, max
, wRemoveMsg
, TRUE
);
1181 /***********************************************************************
1182 * PeekMessageW Check queue for messages
1184 * Checks for a message in the thread's queue, filtered as for
1185 * GetMessage(). Returns immediately whether a message is available
1188 * Whether a retrieved message is removed from the queue is set by the
1189 * _wRemoveMsg_ flags, which should be one of the following values:
1191 * PM_NOREMOVE Do not remove the message from the queue.
1193 * PM_REMOVE Remove the message from the queue.
1195 * In addition, PM_NOYIELD may be combined into _wRemoveMsg_ to
1196 * request that the system not yield control during PeekMessage();
1197 * however applications may not rely on scheduling behavior.
1201 * Nonzero if a message is available and is retrieved, zero otherwise.
1208 BOOL WINAPI
PeekMessageW(
1209 LPMSG lpmsg
, /* buffer to receive message */
1210 HWND hwnd
, /* restrict to messages for hwnd */
1211 UINT min
, /* minimum message to receive */
1212 UINT max
, /* maximum message to receive */
1213 UINT wRemoveMsg
/* removal flags */
1215 /* FIXME: Should perform Unicode translation on specific messages */
1216 return PeekMessageA(lpmsg
,hwnd
,min
,max
,wRemoveMsg
);
1219 /***********************************************************************
1220 * GetMessage16 (USER.108)
1222 BOOL16 WINAPI
GetMessage16( SEGPTR msg
, HWND16 hwnd
, UINT16 first
, UINT16 last
)
1225 MSG16
*lpmsg
= (MSG16
*)PTR_SEG_TO_LIN(msg
);
1228 ret
= GetMessageA( &msg32
, hwnd
, first
, last
);
1230 STRUCT32_MSG32to16( &msg32
, lpmsg
);
1232 TRACE(msg
,"message %04x, hwnd %04x, filter(%04x - %04x)\n", lpmsg
->message
,
1233 hwnd
, first
, last
);
1238 /***********************************************************************
1239 * WIN16_GetMessage32 (USER.820)
1241 BOOL16 WINAPI
GetMessage32_16( SEGPTR msg16_32
, HWND16 hWnd
, UINT16 first
,
1242 UINT16 last
, BOOL16 wHaveParamHigh
)
1244 MSG32_16
*lpmsg16_32
= (MSG32_16
*)PTR_SEG_TO_LIN(msg16_32
);
1246 if (wHaveParamHigh
== FALSE
) /* normal GetMessage16 call */
1249 lpmsg16_32
->wParamHigh
= 0; /* you never know... */
1250 /* WARNING: msg16_32->msg has to be the first variable in the struct */
1251 return GetMessage16(msg16_32
, hWnd
, first
, last
);
1258 ret
= (BOOL16
)GetMessageA(&msg32
, hWnd
, first
, last
);
1259 lpmsg16_32
->msg
.hwnd
= msg32
.hwnd
;
1260 lpmsg16_32
->msg
.message
= msg32
.message
;
1261 lpmsg16_32
->msg
.wParam
= LOWORD(msg32
.wParam
);
1262 lpmsg16_32
->msg
.lParam
= msg32
.lParam
;
1263 lpmsg16_32
->msg
.time
= msg32
.time
;
1264 lpmsg16_32
->msg
.pt
.x
= (INT16
)msg32
.pt
.x
;
1265 lpmsg16_32
->msg
.pt
.y
= (INT16
)msg32
.pt
.y
;
1266 lpmsg16_32
->wParamHigh
= HIWORD(msg32
.wParam
);
1271 /***********************************************************************
1272 * GetMessage32A (USER32.270)
1274 BOOL WINAPI
GetMessageA(MSG
* lpmsg
,HWND hwnd
,UINT min
,UINT max
)
1276 MSG_PeekMessage( lpmsg
, hwnd
, min
, max
, PM_REMOVE
, FALSE
);
1278 TRACE(msg
,"message %04x, hwnd %04x, filter(%04x - %04x)\n", lpmsg
->message
,
1281 HOOK_CallHooksA( WH_GETMESSAGE
, HC_ACTION
, 0, (LPARAM
)lpmsg
);
1283 return (lpmsg
->message
!= WM_QUIT
);
1286 /***********************************************************************
1287 * GetMessage32W (USER32.274) Retrieve next message
1289 * GetMessage retrieves the next event from the calling thread's
1290 * queue and deposits it in *lpmsg.
1292 * If _hwnd_ is not NULL, only messages for window _hwnd_ and its
1293 * children as specified by IsChild() are retrieved. If _hwnd_ is NULL
1294 * all application messages are retrieved.
1296 * _min_ and _max_ specify the range of messages of interest. If
1297 * min==max==0, no filtering is performed. Useful examples are
1298 * WM_KEYFIRST and WM_KEYLAST to retrieve keyboard input, and
1299 * WM_MOUSEFIRST and WM_MOUSELAST to retrieve mouse input.
1301 * WM_PAINT messages are not removed from the queue; they remain until
1302 * processed. Other messages are removed from the queue.
1306 * -1 on error, 0 if message is WM_QUIT, nonzero otherwise.
1313 BOOL WINAPI
GetMessageW(
1314 MSG
* lpmsg
, /* buffer to receive message */
1315 HWND hwnd
, /* restrict to messages for hwnd */
1316 UINT min
, /* minimum message to receive */
1317 UINT max
/* maximum message to receive */
1320 return GetMessageA(lpmsg
, hwnd
, min
, max
);
1324 /***********************************************************************
1325 * PostMessage16 (USER.110)
1327 BOOL16 WINAPI
PostMessage16( HWND16 hwnd
, UINT16 message
, WPARAM16 wParam
,
1330 return (BOOL16
) PostMessageA( hwnd
, message
, wParam
, lParam
);
1334 /***********************************************************************
1335 * PostMessage32A (USER32.419)
1337 BOOL WINAPI
PostMessageA( HWND hwnd
, UINT message
, WPARAM wParam
,
1345 msg
.message
= message
;
1346 msg
.wParam
= wParam
;
1347 msg
.lParam
= lParam
;
1348 msg
.time
= GetTickCount();
1353 if (DDE_PostMessage(&msg
))
1355 #endif /* CONFIG_IPC */
1357 if (hwnd
== HWND_BROADCAST
)
1359 WND
*pDesktop
= WIN_GetDesktop();
1360 TRACE(msg
,"HWND_BROADCAST !\n");
1362 for (wndPtr
=WIN_LockWndPtr(pDesktop
->child
); wndPtr
; WIN_UpdateWndPtr(&wndPtr
,wndPtr
->next
))
1364 if (wndPtr
->dwStyle
& WS_POPUP
|| wndPtr
->dwStyle
& WS_CAPTION
)
1366 TRACE(msg
,"BROADCAST Message to hWnd=%04x m=%04X w=%04X l=%08lX !\n",
1367 wndPtr
->hwndSelf
, message
, wParam
, lParam
);
1368 PostMessageA( wndPtr
->hwndSelf
, message
, wParam
, lParam
);
1371 WIN_ReleaseDesktop();
1372 TRACE(msg
,"End of HWND_BROADCAST !\n");
1376 wndPtr
= WIN_FindWndPtr( hwnd
);
1377 if (!wndPtr
|| !wndPtr
->hmemTaskQ
)
1383 retvalue
= QUEUE_AddMsg( wndPtr
->hmemTaskQ
, &msg
, 0 );
1385 WIN_ReleaseWndPtr(wndPtr
);
1390 /***********************************************************************
1391 * PostMessage32W (USER32.420)
1393 BOOL WINAPI
PostMessageW( HWND hwnd
, UINT message
, WPARAM wParam
,
1397 return PostMessageA( hwnd
, message
, wParam
, lParam
);
1401 /***********************************************************************
1402 * PostAppMessage16 (USER.116)
1404 BOOL16 WINAPI
PostAppMessage16( HTASK16 hTask
, UINT16 message
, WPARAM16 wParam
,
1409 if (GetTaskQueue16(hTask
) == 0) return FALSE
;
1411 msg
.message
= message
;
1412 msg
.wParam
= wParam
;
1413 msg
.lParam
= lParam
;
1414 msg
.time
= GetTickCount();
1418 return QUEUE_AddMsg( GetTaskQueue16(hTask
), &msg
, 0 );
1421 /************************************************************************
1422 * MSG_CallWndProcHook32
1424 static void MSG_CallWndProcHook( LPMSG pmsg
, BOOL bUnicode
)
1428 cwp
.lParam
= pmsg
->lParam
;
1429 cwp
.wParam
= pmsg
->wParam
;
1430 cwp
.message
= pmsg
->message
;
1431 cwp
.hwnd
= pmsg
->hwnd
;
1433 if (bUnicode
) HOOK_CallHooksW(WH_CALLWNDPROC
, HC_ACTION
, 1, (LPARAM
)&cwp
);
1434 else HOOK_CallHooksA( WH_CALLWNDPROC
, HC_ACTION
, 1, (LPARAM
)&cwp
);
1436 pmsg
->lParam
= cwp
.lParam
;
1437 pmsg
->wParam
= cwp
.wParam
;
1438 pmsg
->message
= cwp
.message
;
1439 pmsg
->hwnd
= cwp
.hwnd
;
1443 /***********************************************************************
1446 * return values: 0 if timeout occurs
1449 LRESULT
MSG_SendMessage( HWND hwnd
, UINT msg
, WPARAM wParam
,
1450 LPARAM lParam
, DWORD timeout
, WORD flags
,
1454 WND
**list
, **ppWnd
;
1459 if (hwnd
== HWND_BROADCAST
)
1463 if (!(list
= WIN_BuildWinArray( WIN_GetDesktop(), 0, NULL
)))
1465 WIN_ReleaseDesktop();
1468 WIN_ReleaseDesktop();
1470 TRACE(msg
,"HWND_BROADCAST !\n");
1471 for (ppWnd
= list
; *ppWnd
; ppWnd
++)
1473 WIN_UpdateWndPtr(&wndPtr
,*ppWnd
);
1474 if (!IsWindow(wndPtr
->hwndSelf
)) continue;
1475 if (wndPtr
->dwStyle
& WS_POPUP
|| wndPtr
->dwStyle
& WS_CAPTION
)
1477 TRACE(msg
,"BROADCAST Message to hWnd=%04x m=%04X w=%04lX l=%08lX !\n",
1478 wndPtr
->hwndSelf
, msg
, (DWORD
)wParam
, lParam
);
1479 MSG_SendMessage( wndPtr
->hwndSelf
, msg
, wParam
, lParam
,
1480 timeout
, flags
, pRes
);
1483 WIN_ReleaseWndPtr(wndPtr
);
1484 WIN_ReleaseWinArray(list
);
1485 TRACE(msg
,"End of HWND_BROADCAST !\n");
1489 if (HOOK_IsHooked( WH_CALLWNDPROC
))
1491 if (flags
& SMSG_UNICODE
)
1492 MSG_CallWndProcHook( (LPMSG
)&hwnd
, TRUE
);
1493 else if (flags
& SMSG_WIN32
)
1494 MSG_CallWndProcHook( (LPMSG
)&hwnd
, FALSE
);
1499 if ((pmsg
= SEGPTR_NEW(CWPSTRUCT16
)))
1501 pmsg
->hwnd
= hwnd
& 0xffff;
1502 pmsg
->message
= msg
& 0xffff;
1503 pmsg
->wParam
= wParam
& 0xffff;
1504 pmsg
->lParam
= lParam
;
1505 HOOK_CallHooks16( WH_CALLWNDPROC
, HC_ACTION
, 1,
1506 (LPARAM
)SEGPTR_GET(pmsg
) );
1508 msg
= pmsg
->message
;
1509 wParam
= pmsg
->wParam
;
1510 lParam
= pmsg
->lParam
;
1511 SEGPTR_FREE( pmsg
);
1516 if (!(wndPtr
= WIN_FindWndPtr( hwnd
)))
1518 WARN(msg
, "invalid hwnd %04x\n", hwnd
);
1521 if (QUEUE_IsExitingQueue(wndPtr
->hmemTaskQ
))
1523 ret
= 0; /* Don't send anything if the task is dying */
1526 if (flags
& SMSG_WIN32
)
1527 SPY_EnterMessage( SPY_SENDMESSAGE
, hwnd
, msg
, wParam
, lParam
);
1529 SPY_EnterMessage( SPY_SENDMESSAGE16
, hwnd
, msg
, wParam
, lParam
);
1531 if (wndPtr
->hmemTaskQ
!= GetFastQueue16())
1532 ret
= MSG_SendMessageInterThread( wndPtr
->hmemTaskQ
, hwnd
, msg
,
1533 wParam
, lParam
, timeout
, flags
, pRes
);
1536 /* Call the right CallWindowProc flavor */
1537 if (flags
& SMSG_UNICODE
)
1538 *pRes
= CallWindowProcW( (WNDPROC
)wndPtr
->winproc
,
1539 hwnd
, msg
, wParam
, lParam
);
1540 else if (flags
& SMSG_WIN32
)
1541 *pRes
= CallWindowProcA( (WNDPROC
)wndPtr
->winproc
,
1542 hwnd
, msg
, wParam
, lParam
);
1544 *pRes
= CallWindowProc16( (WNDPROC16
)wndPtr
->winproc
,
1545 (HWND16
) hwnd
, (UINT16
) msg
,
1546 (WPARAM16
) wParam
, lParam
);
1549 if (flags
& SMSG_WIN32
)
1550 SPY_ExitMessage( SPY_RESULT_OK
, hwnd
, msg
, ret
);
1552 SPY_ExitMessage( SPY_RESULT_OK16
, hwnd
, msg
, ret
);
1554 WIN_ReleaseWndPtr(wndPtr
);
1559 /***********************************************************************
1560 * SendMessage16 (USER.111)
1562 LRESULT WINAPI
SendMessage16( HWND16 hwnd
, UINT16 msg
, WPARAM16 wParam
,
1567 MSG16 DDE_msg
= { hwnd
, msg
, wParam
, lParam
};
1568 if (DDE_SendMessage(&DDE_msg
)) return TRUE
;
1569 #endif /* CONFIG_IPC */
1571 MSG_SendMessage(hwnd
, msg
, wParam
, lParam
, INFINITE
, 0, &res
);
1578 /**********************************************************************
1579 * PostThreadMessage32A (USER32.422)
1583 * Thread-local message queues are not supported.
1586 BOOL WINAPI
PostThreadMessageA(DWORD idThread
, UINT message
,
1587 WPARAM wParam
, LPARAM lParam
)
1592 if ((hQueue
= GetThreadQueue16(idThread
)) == 0)
1596 msg
.message
= message
;
1597 msg
.wParam
= wParam
;
1598 msg
.lParam
= lParam
;
1599 msg
.time
= GetTickCount();
1603 return QUEUE_AddMsg( hQueue
, &msg
, 0 );
1606 /**********************************************************************
1607 * PostThreadMessage32W (USER32.423)
1611 * Thread-local message queues are not supported.
1614 BOOL WINAPI
PostThreadMessageW(DWORD idThread
, UINT message
,
1615 WPARAM wParam
, LPARAM lParam
)
1617 FIXME(sendmsg
, "(...): Should do unicode/ascii conversion!\n");
1618 return PostThreadMessageA(idThread
, message
, wParam
, lParam
);
1621 /***********************************************************************
1622 * SendMessage32A (USER32.454)
1624 LRESULT WINAPI
SendMessageA( HWND hwnd
, UINT msg
, WPARAM wParam
,
1629 MSG_SendMessage(hwnd
, msg
, wParam
, lParam
, INFINITE
,
1636 /***********************************************************************
1637 * SendMessage32W (USER32.459) Send Window Message
1639 * Sends a message to the window procedure of the specified window.
1640 * SendMessage() will not return until the called window procedure
1641 * either returns or calls ReplyMessage().
1643 * Use PostMessage() to send message and return immediately. A window
1644 * procedure may use InSendMessage() to detect
1645 * SendMessage()-originated messages.
1647 * Applications which communicate via HWND_BROADCAST may use
1648 * RegisterWindowMessage() to obtain a unique message to avoid conflicts
1649 * with other applications.
1655 LRESULT WINAPI
SendMessageW(
1656 HWND hwnd
, /* Window to send message to. If HWND_BROADCAST,
1657 the message will be sent to all top-level windows. */
1659 UINT msg
, /* message */
1660 WPARAM wParam
, /* message parameter */
1661 LPARAM lParam
/* additional message parameter */
1665 MSG_SendMessage(hwnd
, msg
, wParam
, lParam
, INFINITE
,
1666 SMSG_WIN32
| SMSG_UNICODE
, &res
);
1672 /***********************************************************************
1673 * SendMessageTimeout16 (not a WINAPI)
1675 LRESULT WINAPI
SendMessageTimeout16( HWND16 hwnd
, UINT16 msg
, WPARAM16 wParam
,
1676 LPARAM lParam
, UINT16 flags
,
1677 UINT16 timeout
, LPWORD resultp
)
1682 /* FIXME: need support for SMTO_BLOCK */
1684 ret
= MSG_SendMessage(hwnd
, msg
, wParam
, lParam
, timeout
, 0, &msgRet
);
1685 *resultp
= (WORD
) msgRet
;
1690 /***********************************************************************
1691 * SendMessageTimeoutA (USER32.457)
1693 LRESULT WINAPI
SendMessageTimeoutA( HWND hwnd
, UINT msg
, WPARAM wParam
,
1694 LPARAM lParam
, UINT flags
,
1695 UINT timeout
, LPDWORD resultp
)
1700 /* FIXME: need support for SMTO_BLOCK */
1702 ret
= MSG_SendMessage(hwnd
, msg
, wParam
, lParam
, timeout
, SMSG_WIN32
,
1705 *resultp
= (DWORD
) msgRet
;
1710 /***********************************************************************
1711 * SendMessageTimeoutW (USER32.458)
1713 LRESULT WINAPI
SendMessageTimeoutW( HWND hwnd
, UINT msg
, WPARAM wParam
,
1714 LPARAM lParam
, UINT flags
,
1715 UINT timeout
, LPDWORD resultp
)
1720 /* FIXME: need support for SMTO_BLOCK */
1722 ret
= MSG_SendMessage(hwnd
, msg
, wParam
, lParam
, timeout
,
1723 SMSG_WIN32
| SMSG_UNICODE
, &msgRet
);
1725 *resultp
= (DWORD
) msgRet
;
1730 /***********************************************************************
1731 * WaitMessage (USER.112) (USER32.578) Suspend thread pending messages
1733 * WaitMessage() suspends a thread until events appear in the thread's
1738 * Is supposed to return BOOL under Win32.
1740 * Thread-local message queues are not supported.
1747 void WINAPI
WaitMessage( void )
1749 QUEUE_WaitBits( QS_ALLINPUT
, INFINITE
);
1752 /***********************************************************************
1753 * MsgWaitForMultipleObjects (USER32.400)
1755 DWORD WINAPI
MsgWaitForMultipleObjects( DWORD nCount
, HANDLE
*pHandles
,
1756 BOOL fWaitAll
, DWORD dwMilliseconds
,
1760 HANDLE handles
[MAXIMUM_WAIT_OBJECTS
];
1763 HQUEUE16 hQueue
= GetFastQueue16();
1764 MESSAGEQUEUE
*msgQueue
= (MESSAGEQUEUE
*)QUEUE_Lock( hQueue
);
1765 if (!msgQueue
) return WAIT_FAILED
;
1767 if (nCount
> MAXIMUM_WAIT_OBJECTS
-1)
1769 SetLastError( ERROR_INVALID_PARAMETER
);
1770 QUEUE_Unlock( msgQueue
);
1774 msgQueue
->changeBits
= 0;
1775 msgQueue
->wakeMask
= dwWakeMask
;
1777 if (THREAD_IsWin16(THREAD_Current()))
1780 * This is a temporary solution to a big problem.
1781 * You see, the main thread of all Win32 programs is created as a 16 bit
1782 * task. This means that if you want on an event using Win32 synchronization
1783 * methods, the 16 bit scheduler is stopped and things might just stop happening.
1784 * This implements a semi-busy loop that checks the handles to wait on and
1785 * also the message queue. When either one is ready, the wait function returns.
1787 * This will all go away when the real Win32 threads are implemented for all
1788 * the threads of an applications. Including the main thread.
1790 DWORD curTime
= GetCurrentTime();
1795 * Check the handles in the list.
1797 ret
= WaitForMultipleObjects(nCount
, pHandles
, fWaitAll
, 5L);
1800 * If the handles have been triggered, return.
1802 if (ret
!= WAIT_TIMEOUT
)
1806 * Then, let the 16 bit scheduler do it's thing.
1811 * If a message matching the wait mask has arrived, return.
1813 if (msgQueue
->changeBits
& dwWakeMask
)
1820 * And continue doing this until we hit the timeout.
1822 } while ((dwMilliseconds
== INFINITE
) || (GetCurrentTime()-curTime
< dwMilliseconds
) );
1826 /* Add the thread event to the handle list */
1827 for (i
= 0; i
< nCount
; i
++)
1828 handles
[i
] = pHandles
[i
];
1829 handles
[nCount
] = msgQueue
->hEvent
;
1833 ret
= WaitForMultipleObjects( nCount
+1, handles
, fWaitAll
, dwMilliseconds
);
1836 QUEUE_Unlock( msgQueue
);
1850 static const struct accent_char accent_chars
[] =
1852 /* A good idea should be to read /usr/X11/lib/X11/locale/iso8859-x/Compose */
1853 {'`', 'A', '\300'}, {'`', 'a', '\340'},
1854 {'\'', 'A', '\301'}, {'\'', 'a', '\341'},
1855 {'^', 'A', '\302'}, {'^', 'a', '\342'},
1856 {'~', 'A', '\303'}, {'~', 'a', '\343'},
1857 {'"', 'A', '\304'}, {'"', 'a', '\344'},
1858 {'O', 'A', '\305'}, {'o', 'a', '\345'},
1859 {'0', 'A', '\305'}, {'0', 'a', '\345'},
1860 {'A', 'A', '\305'}, {'a', 'a', '\345'},
1861 {'A', 'E', '\306'}, {'a', 'e', '\346'},
1862 {',', 'C', '\307'}, {',', 'c', '\347'},
1863 {'`', 'E', '\310'}, {'`', 'e', '\350'},
1864 {'\'', 'E', '\311'}, {'\'', 'e', '\351'},
1865 {'^', 'E', '\312'}, {'^', 'e', '\352'},
1866 {'"', 'E', '\313'}, {'"', 'e', '\353'},
1867 {'`', 'I', '\314'}, {'`', 'i', '\354'},
1868 {'\'', 'I', '\315'}, {'\'', 'i', '\355'},
1869 {'^', 'I', '\316'}, {'^', 'i', '\356'},
1870 {'"', 'I', '\317'}, {'"', 'i', '\357'},
1871 {'-', 'D', '\320'}, {'-', 'd', '\360'},
1872 {'~', 'N', '\321'}, {'~', 'n', '\361'},
1873 {'`', 'O', '\322'}, {'`', 'o', '\362'},
1874 {'\'', 'O', '\323'}, {'\'', 'o', '\363'},
1875 {'^', 'O', '\324'}, {'^', 'o', '\364'},
1876 {'~', 'O', '\325'}, {'~', 'o', '\365'},
1877 {'"', 'O', '\326'}, {'"', 'o', '\366'},
1878 {'/', 'O', '\330'}, {'/', 'o', '\370'},
1879 {'`', 'U', '\331'}, {'`', 'u', '\371'},
1880 {'\'', 'U', '\332'}, {'\'', 'u', '\372'},
1881 {'^', 'U', '\333'}, {'^', 'u', '\373'},
1882 {'"', 'U', '\334'}, {'"', 'u', '\374'},
1883 {'\'', 'Y', '\335'}, {'\'', 'y', '\375'},
1884 {'T', 'H', '\336'}, {'t', 'h', '\376'},
1885 {'s', 's', '\337'}, {'"', 'y', '\377'},
1886 {'s', 'z', '\337'}, {'i', 'j', '\377'},
1887 /* iso-8859-2 uses this */
1888 {'<', 'L', '\245'}, {'<', 'l', '\265'}, /* caron */
1889 {'<', 'S', '\251'}, {'<', 's', '\271'},
1890 {'<', 'T', '\253'}, {'<', 't', '\273'},
1891 {'<', 'Z', '\256'}, {'<', 'z', '\276'},
1892 {'<', 'C', '\310'}, {'<', 'c', '\350'},
1893 {'<', 'E', '\314'}, {'<', 'e', '\354'},
1894 {'<', 'D', '\317'}, {'<', 'd', '\357'},
1895 {'<', 'N', '\322'}, {'<', 'n', '\362'},
1896 {'<', 'R', '\330'}, {'<', 'r', '\370'},
1897 {';', 'A', '\241'}, {';', 'a', '\261'}, /* ogonek */
1898 {';', 'E', '\312'}, {';', 'e', '\332'},
1899 {'\'', 'Z', '\254'}, {'\'', 'z', '\274'}, /* acute */
1900 {'\'', 'R', '\300'}, {'\'', 'r', '\340'},
1901 {'\'', 'L', '\305'}, {'\'', 'l', '\345'},
1902 {'\'', 'C', '\306'}, {'\'', 'c', '\346'},
1903 {'\'', 'N', '\321'}, {'\'', 'n', '\361'},
1904 /* collision whith S, from iso-8859-9 !!! */
1905 {',', 'S', '\252'}, {',', 's', '\272'}, /* cedilla */
1906 {',', 'T', '\336'}, {',', 't', '\376'},
1907 {'.', 'Z', '\257'}, {'.', 'z', '\277'}, /* dot above */
1908 {'/', 'L', '\243'}, {'/', 'l', '\263'}, /* slash */
1909 {'/', 'D', '\320'}, {'/', 'd', '\360'},
1910 {'(', 'A', '\303'}, {'(', 'a', '\343'}, /* breve */
1911 {'\275', 'O', '\325'}, {'\275', 'o', '\365'}, /* double acute */
1912 {'\275', 'U', '\334'}, {'\275', 'u', '\374'},
1913 {'0', 'U', '\332'}, {'0', 'u', '\372'}, /* ring above */
1914 /* iso-8859-3 uses this */
1915 {'/', 'H', '\241'}, {'/', 'h', '\261'}, /* slash */
1916 {'>', 'H', '\246'}, {'>', 'h', '\266'}, /* circumflex */
1917 {'>', 'J', '\254'}, {'>', 'j', '\274'},
1918 {'>', 'C', '\306'}, {'>', 'c', '\346'},
1919 {'>', 'G', '\330'}, {'>', 'g', '\370'},
1920 {'>', 'S', '\336'}, {'>', 's', '\376'},
1921 /* collision whith G( from iso-8859-9 !!! */
1922 {'(', 'G', '\253'}, {'(', 'g', '\273'}, /* breve */
1923 {'(', 'U', '\335'}, {'(', 'u', '\375'},
1924 /* collision whith I. from iso-8859-3 !!! */
1925 {'.', 'I', '\251'}, {'.', 'i', '\271'}, /* dot above */
1926 {'.', 'C', '\305'}, {'.', 'c', '\345'},
1927 {'.', 'G', '\325'}, {'.', 'g', '\365'},
1928 /* iso-8859-4 uses this */
1929 {',', 'R', '\243'}, {',', 'r', '\263'}, /* cedilla */
1930 {',', 'L', '\246'}, {',', 'l', '\266'},
1931 {',', 'G', '\253'}, {',', 'g', '\273'},
1932 {',', 'N', '\321'}, {',', 'n', '\361'},
1933 {',', 'K', '\323'}, {',', 'k', '\363'},
1934 {'~', 'I', '\245'}, {'~', 'i', '\265'}, /* tilde */
1935 {'-', 'E', '\252'}, {'-', 'e', '\272'}, /* macron */
1936 {'-', 'A', '\300'}, {'-', 'a', '\340'},
1937 {'-', 'I', '\317'}, {'-', 'i', '\357'},
1938 {'-', 'O', '\322'}, {'-', 'o', '\362'},
1939 {'-', 'U', '\336'}, {'-', 'u', '\376'},
1940 {'/', 'T', '\254'}, {'/', 't', '\274'}, /* slash */
1941 {'.', 'E', '\314'}, {'.', 'e', '\344'}, /* dot above */
1942 {';', 'I', '\307'}, {';', 'i', '\347'}, /* ogonek */
1943 {';', 'U', '\331'}, {';', 'u', '\371'},
1944 /* iso-8859-9 uses this */
1945 /* iso-8859-9 has really bad choosen G( S, and I. as they collide
1946 * whith the same letters on other iso-8859-x (that is they are on
1947 * different places :-( ), if you use turkish uncomment these and
1948 * comment out the lines in iso-8859-2 and iso-8859-3 sections
1949 * FIXME: should be dynamic according to chosen language
1950 * if/when Wine has turkish support.
1952 /* collision whith G( from iso-8859-3 !!! */
1953 /* {'(', 'G', '\320'}, {'(', 'g', '\360'}, */ /* breve */
1954 /* collision whith S, from iso-8859-2 !!! */
1955 /* {',', 'S', '\336'}, {',', 's', '\376'}, */ /* cedilla */
1956 /* collision whith I. from iso-8859-3 !!! */
1957 /* {'.', 'I', '\335'}, {'.', 'i', '\375'}, */ /* dot above */
1961 /***********************************************************************
1962 * MSG_DoTranslateMessage
1964 * Implementation of TranslateMessage.
1966 * TranslateMessage translates virtual-key messages into character-messages,
1968 * WM_KEYDOWN/WM_KEYUP combinations produce a WM_CHAR or WM_DEADCHAR message.
1969 * ditto replacing WM_* with WM_SYS*
1970 * This produces WM_CHAR messages only for keys mapped to ASCII characters
1971 * by the keyboard driver.
1973 static BOOL
MSG_DoTranslateMessage( UINT message
, HWND hwnd
,
1974 WPARAM wParam
, LPARAM lParam
)
1976 static int dead_char
;
1979 if (message
!= WM_MOUSEMOVE
&& message
!= WM_TIMER
)
1980 TRACE(msg
, "(%s, %04X, %08lX)\n",
1981 SPY_GetMsgName(message
), wParam
, lParam
);
1982 if(message
>= WM_KEYFIRST
&& message
<= WM_KEYLAST
)
1983 TRACE(key
, "(%s, %04X, %08lX)\n",
1984 SPY_GetMsgName(message
), wParam
, lParam
);
1986 if ((message
!= WM_KEYDOWN
) && (message
!= WM_SYSKEYDOWN
)) return FALSE
;
1988 TRACE(key
, "Translating key %04X, scancode %04X\n",
1989 wParam
, HIWORD(lParam
) );
1991 /* FIXME : should handle ToAscii yielding 2 */
1992 switch (ToAscii(wParam
, HIWORD(lParam
),
1993 QueueKeyStateTable
,(LPWORD
)wp
, 0))
1996 message
= (message
== WM_KEYDOWN
) ? WM_CHAR
: WM_SYSCHAR
;
1997 /* Should dead chars handling go in ToAscii ? */
2002 if (wp
[0] == ' ') wp
[0] = dead_char
;
2003 if (dead_char
== 0xa2) dead_char
= '(';
2004 else if (dead_char
== 0xa8) dead_char
= '"';
2005 else if (dead_char
== 0xb2) dead_char
= ';';
2006 else if (dead_char
== 0xb4) dead_char
= '\'';
2007 else if (dead_char
== 0xb7) dead_char
= '<';
2008 else if (dead_char
== 0xb8) dead_char
= ',';
2009 else if (dead_char
== 0xff) dead_char
= '.';
2010 for (i
= 0; i
< sizeof(accent_chars
)/sizeof(accent_chars
[0]); i
++)
2011 if ((accent_chars
[i
].ac_accent
== dead_char
) &&
2012 (accent_chars
[i
].ac_char
== wp
[0]))
2014 wp
[0] = accent_chars
[i
].ac_result
;
2019 TRACE(key
, "1 -> PostMessage(%s)\n", SPY_GetMsgName(message
));
2020 PostMessage16( hwnd
, message
, wp
[0], lParam
);
2024 message
= (message
== WM_KEYDOWN
) ? WM_DEADCHAR
: WM_SYSDEADCHAR
;
2026 TRACE(key
, "-1 -> PostMessage(%s)\n",
2027 SPY_GetMsgName(message
));
2028 PostMessage16( hwnd
, message
, wp
[0], lParam
);
2035 /***********************************************************************
2036 * TranslateMessage16 (USER.113)
2038 BOOL16 WINAPI
TranslateMessage16( const MSG16
*msg
)
2040 return MSG_DoTranslateMessage( msg
->message
, msg
->hwnd
,
2041 msg
->wParam
, msg
->lParam
);
2045 /***********************************************************************
2046 * WIN16_TranslateMessage32 (USER.821)
2048 BOOL16 WINAPI
TranslateMessage32_16( const MSG32_16
*msg
, BOOL16 wHaveParamHigh
)
2053 wParam
= MAKELONG(msg
->msg
.wParam
, msg
->wParamHigh
);
2055 wParam
= (WPARAM
)msg
->msg
.wParam
;
2057 return MSG_DoTranslateMessage( msg
->msg
.message
, msg
->msg
.hwnd
,
2058 wParam
, msg
->msg
.lParam
);
2061 /***********************************************************************
2062 * TranslateMessage32 (USER32.556)
2064 BOOL WINAPI
TranslateMessage( const MSG
*msg
)
2066 return MSG_DoTranslateMessage( msg
->message
, msg
->hwnd
,
2067 msg
->wParam
, msg
->lParam
);
2071 /***********************************************************************
2072 * DispatchMessage16 (USER.114)
2074 LONG WINAPI
DispatchMessage16( const MSG16
* msg
)
2080 /* Process timer messages */
2081 if ((msg
->message
== WM_TIMER
) || (msg
->message
== WM_SYSTIMER
))
2085 return CallWindowProc16( (WNDPROC16
)msg
->lParam
, msg
->hwnd
,
2086 msg
->message
, msg
->wParam
, GetTickCount() );
2090 if (!msg
->hwnd
) return 0;
2091 if (!(wndPtr
= WIN_FindWndPtr( msg
->hwnd
))) return 0;
2092 if (!wndPtr
->winproc
)
2097 painting
= (msg
->message
== WM_PAINT
);
2098 if (painting
) wndPtr
->flags
|= WIN_NEEDS_BEGINPAINT
;
2100 SPY_EnterMessage( SPY_DISPATCHMESSAGE16
, msg
->hwnd
, msg
->message
,
2101 msg
->wParam
, msg
->lParam
);
2102 retval
= CallWindowProc16( (WNDPROC16
)wndPtr
->winproc
,
2103 msg
->hwnd
, msg
->message
,
2104 msg
->wParam
, msg
->lParam
);
2105 SPY_ExitMessage( SPY_RESULT_OK16
, msg
->hwnd
, msg
->message
, retval
);
2107 WIN_ReleaseWndPtr(wndPtr
);
2108 wndPtr
= WIN_FindWndPtr(msg
->hwnd
);
2109 if (painting
&& wndPtr
&&
2110 (wndPtr
->flags
& WIN_NEEDS_BEGINPAINT
) && wndPtr
->hrgnUpdate
)
2112 ERR(msg
, "BeginPaint not called on WM_PAINT for hwnd %04x!\n",
2114 wndPtr
->flags
&= ~WIN_NEEDS_BEGINPAINT
;
2115 /* Validate the update region to avoid infinite WM_PAINT loop */
2116 ValidateRect( msg
->hwnd
, NULL
);
2119 WIN_ReleaseWndPtr(wndPtr
);
2124 /***********************************************************************
2125 * WIN16_DispatchMessage32 (USER.822)
2127 LONG WINAPI
DispatchMessage32_16( const MSG32_16
* lpmsg16_32
, BOOL16 wHaveParamHigh
)
2129 if (wHaveParamHigh
== FALSE
)
2130 return DispatchMessage16(&(lpmsg16_32
->msg
));
2135 msg
.hwnd
= lpmsg16_32
->msg
.hwnd
;
2136 msg
.message
= lpmsg16_32
->msg
.message
;
2137 msg
.wParam
= MAKELONG(lpmsg16_32
->msg
.wParam
, lpmsg16_32
->wParamHigh
);
2138 msg
.lParam
= lpmsg16_32
->msg
.lParam
;
2139 msg
.time
= lpmsg16_32
->msg
.time
;
2140 msg
.pt
.x
= (INT
)lpmsg16_32
->msg
.pt
.x
;
2141 msg
.pt
.y
= (INT
)lpmsg16_32
->msg
.pt
.y
;
2142 return DispatchMessageA(&msg
);
2146 /***********************************************************************
2147 * DispatchMessage32A (USER32.141)
2149 LONG WINAPI
DispatchMessageA( const MSG
* msg
)
2155 /* Process timer messages */
2156 if ((msg
->message
== WM_TIMER
) || (msg
->message
== WM_SYSTIMER
))
2160 /* HOOK_CallHooks32A( WH_CALLWNDPROC, HC_ACTION, 0, FIXME ); */
2161 return CallWindowProcA( (WNDPROC
)msg
->lParam
, msg
->hwnd
,
2162 msg
->message
, msg
->wParam
, GetTickCount() );
2166 if (!msg
->hwnd
) return 0;
2167 if (!(wndPtr
= WIN_FindWndPtr( msg
->hwnd
))) return 0;
2168 if (!wndPtr
->winproc
)
2173 painting
= (msg
->message
== WM_PAINT
);
2174 if (painting
) wndPtr
->flags
|= WIN_NEEDS_BEGINPAINT
;
2175 /* HOOK_CallHooks32A( WH_CALLWNDPROC, HC_ACTION, 0, FIXME ); */
2177 SPY_EnterMessage( SPY_DISPATCHMESSAGE
, msg
->hwnd
, msg
->message
,
2178 msg
->wParam
, msg
->lParam
);
2179 retval
= CallWindowProcA( (WNDPROC
)wndPtr
->winproc
,
2180 msg
->hwnd
, msg
->message
,
2181 msg
->wParam
, msg
->lParam
);
2182 SPY_ExitMessage( SPY_RESULT_OK
, msg
->hwnd
, msg
->message
, retval
);
2184 WIN_ReleaseWndPtr(wndPtr
);
2185 wndPtr
= WIN_FindWndPtr(msg
->hwnd
);
2187 if (painting
&& wndPtr
&&
2188 (wndPtr
->flags
& WIN_NEEDS_BEGINPAINT
) && wndPtr
->hrgnUpdate
)
2190 ERR(msg
, "BeginPaint not called on WM_PAINT for hwnd %04x!\n",
2192 wndPtr
->flags
&= ~WIN_NEEDS_BEGINPAINT
;
2193 /* Validate the update region to avoid infinite WM_PAINT loop */
2194 ValidateRect( msg
->hwnd
, NULL
);
2197 WIN_ReleaseWndPtr(wndPtr
);
2202 /***********************************************************************
2203 * DispatchMessage32W (USER32.142) Process Message
2205 * Process the message specified in the structure *_msg_.
2207 * If the lpMsg parameter points to a WM_TIMER message and the
2208 * parameter of the WM_TIMER message is not NULL, the lParam parameter
2209 * points to the function that is called instead of the window
2212 * The message must be valid.
2216 * DispatchMessage() returns the result of the window procedure invoked.
2223 LONG WINAPI
DispatchMessageW( const MSG
* msg
)
2229 /* Process timer messages */
2230 if ((msg
->message
== WM_TIMER
) || (msg
->message
== WM_SYSTIMER
))
2234 /* HOOK_CallHooks32W( WH_CALLWNDPROC, HC_ACTION, 0, FIXME ); */
2235 return CallWindowProcW( (WNDPROC
)msg
->lParam
, msg
->hwnd
,
2236 msg
->message
, msg
->wParam
, GetTickCount() );
2240 if (!msg
->hwnd
) return 0;
2241 if (!(wndPtr
= WIN_FindWndPtr( msg
->hwnd
))) return 0;
2242 if (!wndPtr
->winproc
)
2247 painting
= (msg
->message
== WM_PAINT
);
2248 if (painting
) wndPtr
->flags
|= WIN_NEEDS_BEGINPAINT
;
2249 /* HOOK_CallHooks32W( WH_CALLWNDPROC, HC_ACTION, 0, FIXME ); */
2251 SPY_EnterMessage( SPY_DISPATCHMESSAGE
, msg
->hwnd
, msg
->message
,
2252 msg
->wParam
, msg
->lParam
);
2253 retval
= CallWindowProcW( (WNDPROC
)wndPtr
->winproc
,
2254 msg
->hwnd
, msg
->message
,
2255 msg
->wParam
, msg
->lParam
);
2256 SPY_ExitMessage( SPY_RESULT_OK
, msg
->hwnd
, msg
->message
, retval
);
2258 WIN_ReleaseWndPtr(wndPtr
);
2259 wndPtr
= WIN_FindWndPtr(msg
->hwnd
);
2261 if (painting
&& wndPtr
&&
2262 (wndPtr
->flags
& WIN_NEEDS_BEGINPAINT
) && wndPtr
->hrgnUpdate
)
2264 ERR(msg
, "BeginPaint not called on WM_PAINT for hwnd %04x!\n",
2266 wndPtr
->flags
&= ~WIN_NEEDS_BEGINPAINT
;
2267 /* Validate the update region to avoid infinite WM_PAINT loop */
2268 ValidateRect( msg
->hwnd
, NULL
);
2271 WIN_ReleaseWndPtr(wndPtr
);
2276 /***********************************************************************
2277 * RegisterWindowMessage16 (USER.118)
2279 WORD WINAPI
RegisterWindowMessage16( SEGPTR str
)
2281 TRACE(msg
, "%08lx\n", (DWORD
)str
);
2282 return GlobalAddAtom16( str
);
2286 /***********************************************************************
2287 * RegisterWindowMessage32A (USER32.437)
2289 WORD WINAPI
RegisterWindowMessageA( LPCSTR str
)
2291 TRACE(msg
, "%s\n", str
);
2292 return GlobalAddAtomA( str
);
2296 /***********************************************************************
2297 * RegisterWindowMessage32W (USER32.438)
2299 WORD WINAPI
RegisterWindowMessageW( LPCWSTR str
)
2301 TRACE(msg
, "%p\n", str
);
2302 return GlobalAddAtomW( str
);
2306 /***********************************************************************
2307 * GetTickCount (USER.13) (KERNEL32.299) System Time
2308 * Returns the number of milliseconds, modulo 2^32, since the start
2309 * of the current session.
2315 DWORD WINAPI
GetTickCount(void)
2318 gettimeofday( &t
, NULL
);
2319 /* make extremely compatible: granularity is 25 msec */
2320 return ((t
.tv_sec
* 1000) + (t
.tv_usec
/ 25000) * 25) - MSG_WineStartTicks
;
2324 /***********************************************************************
2325 * GetCurrentTime16 (USER.15)
2327 * (effectively identical to GetTickCount)
2329 DWORD WINAPI
GetCurrentTime16(void)
2331 return GetTickCount();
2335 /***********************************************************************
2336 * InSendMessage16 (USER.192)
2338 BOOL16 WINAPI
InSendMessage16(void)
2340 return InSendMessage();
2344 /***********************************************************************
2345 * InSendMessage32 (USER32.320)
2347 BOOL WINAPI
InSendMessage(void)
2349 MESSAGEQUEUE
*queue
;
2352 if (!(queue
= (MESSAGEQUEUE
*)QUEUE_Lock( GetFastQueue16() )))
2354 ret
= (BOOL
)queue
->smWaiting
;
2356 QUEUE_Unlock( queue
);
2360 /***********************************************************************
2361 * BroadcastSystemMessage (USER32.12)
2363 LONG WINAPI
BroadcastSystemMessage(
2364 DWORD dwFlags
,LPDWORD recipients
,UINT uMessage
,WPARAM wParam
,
2367 FIXME(sendmsg
,"(%08lx,%08lx,%08x,%08x,%08lx): stub!\n",
2368 dwFlags
,*recipients
,uMessage
,wParam
,lParam
2373 /***********************************************************************
2374 * SendNotifyMessageA (USER32.460)
2376 * The message sended with PostMessage has to be put in the queue
2377 * with a higher priority as the other "Posted" messages.
2378 * QUEUE_AddMsg has to be modifyed.
2380 BOOL WINAPI
SendNotifyMessageA(HWND hwnd
,UINT msg
,WPARAM wParam
,LPARAM lParam
)
2382 FIXME(msg
,"(%04x,%08x,%08x,%08lx) not complete\n",
2383 hwnd
, msg
, wParam
, lParam
);
2385 if ( GetCurrentThreadId() == GetWindowThreadProcessId ( hwnd
, NULL
))
2386 { ret
=SendMessageA ( hwnd
, msg
, wParam
, lParam
);
2389 { PostMessageA ( hwnd
, msg
, wParam
, lParam
);
2394 /***********************************************************************
2395 * SendNotifyMessageW (USER32.461)
2397 * The message sended with PostMessage has to be put in the queue
2398 * with a higher priority as the other "Posted" messages.
2399 * QUEUE_AddMsg has to be modifyed.
2401 BOOL WINAPI
SendNotifyMessageW(HWND hwnd
,UINT msg
,WPARAM wParam
,LPARAM lParam
)
2403 FIXME(msg
,"(%04x,%08x,%08x,%08lx) not complete\n",
2404 hwnd
, msg
, wParam
, lParam
);
2406 if ( GetCurrentThreadId() == GetWindowThreadProcessId ( hwnd
, NULL
))
2407 { ret
=SendMessageW ( hwnd
, msg
, wParam
, lParam
);
2410 { PostMessageW ( hwnd
, msg
, wParam
, lParam
);
2415 /***********************************************************************
2416 * SendMessageCallBack32A
2417 * FIXME: It's like PostMessage. The callback gets called when the message
2418 * is processed. We have to modify the message processing for a exact
2421 BOOL WINAPI
SendMessageCallBackA(
2422 HWND hWnd
,UINT Msg
,WPARAM wParam
,LPARAM lParam
,
2423 FARPROC lpResultCallBack
,DWORD dwData
)
2425 FIXME(msg
,"(0x%04x,0x%04x,0x%08x,0x%08lx,%p,0x%08lx),stub!\n",
2426 hWnd
,Msg
,wParam
,lParam
,lpResultCallBack
,dwData
);
2427 if ( hWnd
== HWND_BROADCAST
)
2428 { PostMessageA( hWnd
, Msg
, wParam
, lParam
);
2429 FIXME(msg
,"Broadcast: Callback will not be called!\n");
2432 (lpResultCallBack
)( hWnd
, Msg
, dwData
, SendMessageA ( hWnd
, Msg
, wParam
, lParam
));