2 * Message queues related functions
4 * Copyright 1993, 1994 Alexandre Julliard
11 #include <sys/types.h>
13 #include "wine/winbase16.h"
18 #include "sysmetrics.h"
34 #define WM_NCMOUSEFIRST WM_NCMOUSEMOVE
35 #define WM_NCMOUSELAST WM_NCMBUTTONDBLCLK
38 typedef enum { SYSQ_MSG_ABANDON
, SYSQ_MSG_SKIP
,
39 SYSQ_MSG_ACCEPT
, SYSQ_MSG_CONTINUE
} SYSQ_STATUS
;
41 extern HQUEUE16 hCursorQueue
; /* queue.c */
43 DWORD MSG_WineStartTicks
; /* Ticks at Wine startup */
45 static UINT doubleClickSpeed
= 452;
48 /***********************************************************************
51 BOOL
MSG_CheckFilter(DWORD uMsg
, DWORD first
, DWORD last
)
54 return (uMsg
>= first
&& uMsg
<= last
);
58 /***********************************************************************
59 * MSG_SendParentNotify
61 * Send a WM_PARENTNOTIFY to all ancestors of the given window, unless
62 * the window has the WS_EX_NOPARENTNOTIFY style.
64 static void MSG_SendParentNotify(WND
* wndPtr
, WORD event
, WORD idChild
, LPARAM lValue
)
66 #define lppt ((LPPOINT16)&lValue)
68 /* pt has to be in the client coordinates of the parent window */
70 MapWindowPoints16( 0, wndPtr
->hwndSelf
, lppt
, 1 );
73 if (!(wndPtr
->dwStyle
& WS_CHILD
) || (wndPtr
->dwExStyle
& WS_EX_NOPARENTNOTIFY
)) break;
74 lppt
->x
+= wndPtr
->rectClient
.left
;
75 lppt
->y
+= wndPtr
->rectClient
.top
;
76 wndPtr
= wndPtr
->parent
;
77 SendMessageA( wndPtr
->hwndSelf
, WM_PARENTNOTIFY
,
78 MAKEWPARAM( event
, idChild
), lValue
);
84 /***********************************************************************
85 * MSG_TranslateMouseMsg
87 * Translate an mouse hardware event into a real mouse message.
88 * Return value indicates whether the translated message must be passed
89 * to the user, left in the queue, or skipped entirely (in this case
90 * HIWORD contains hit test code).
92 static DWORD
MSG_TranslateMouseMsg( HWND hTopWnd
, DWORD first
, DWORD last
,
93 MSG
*msg
, BOOL remove
, WND
* pWndScope
)
95 static DWORD dblclk_time_limit
= 0;
96 static UINT16 clk_message
= 0;
97 static HWND16 clk_hwnd
= 0;
98 static POINT16 clk_pos
= { 0, 0 };
102 INT16 ht
, hittest
, sendSC
= 0;
103 UINT message
= msg
->message
;
104 POINT16 screen_pt
, pt
;
105 HANDLE16 hQ
= GetFastQueue16();
106 MESSAGEQUEUE
*queue
= (MESSAGEQUEUE
*)QUEUE_Lock(hQ
);
108 BOOL mouseClick
= ((message
== WM_LBUTTONDOWN
) ||
109 (message
== WM_RBUTTONDOWN
) ||
110 (message
== WM_MBUTTONDOWN
))?1:0;
113 /* Find the window */
115 CONV_POINT32TO16( &msg
->pt
, &pt
);
117 ht
= hittest
= HTCLIENT
;
121 ht
= hittest
= WINPOS_WindowFromPoint( pWndScope
, pt
, &pWnd
);
122 if( !pWnd
) pWnd
= WIN_GetDesktop();
123 hWnd
= pWnd
->hwndSelf
;
128 pWnd
= WIN_FindWndPtr(hWnd
);
130 ht
= PERQDATA_GetCaptureInfo( queue
->pQData
);
133 /* stop if not the right queue */
135 if (pWnd
->hmemTaskQ
!= hQ
)
137 /* Not for the current task */
138 if (queue
) QUEUE_ClearWakeBit( queue
, QS_MOUSE
);
139 /* Wake up the other task */
140 QUEUE_Unlock( queue
);
141 queue
= (MESSAGEQUEUE
*)QUEUE_Lock( pWnd
->hmemTaskQ
);
142 if (queue
) QUEUE_SetWakeBit( queue
, QS_MOUSE
);
144 QUEUE_Unlock( queue
);
145 return SYSQ_MSG_ABANDON
;
148 /* check if hWnd is within hWndScope */
150 if( hTopWnd
&& hWnd
!= hTopWnd
)
151 if( !IsChild(hTopWnd
, hWnd
) )
153 QUEUE_Unlock( queue
);
154 return SYSQ_MSG_CONTINUE
;
159 /* translate double clicks -
160 * note that ...MOUSEMOVEs can slip in between
161 * ...BUTTONDOWN and ...BUTTONDBLCLK messages */
163 if( pWnd
->class->style
& CS_DBLCLKS
|| ht
!= HTCLIENT
)
165 if ((message
== clk_message
) && (hWnd
== clk_hwnd
) &&
166 (msg
->time
- dblclk_time_limit
< doubleClickSpeed
) &&
167 (abs(msg
->pt
.x
- clk_pos
.x
) < SYSMETRICS_CXDOUBLECLK
/2) &&
168 (abs(msg
->pt
.y
- clk_pos
.y
) < SYSMETRICS_CYDOUBLECLK
/2))
170 message
+= (WM_LBUTTONDBLCLK
- WM_LBUTTONDOWN
);
171 mouseClick
++; /* == 2 */
177 if (hittest
!= HTCLIENT
)
179 message
+= WM_NCMOUSEMOVE
- WM_MOUSEMOVE
;
180 msg
->wParam
= hittest
;
182 else ScreenToClient16( hWnd
, &pt
);
184 /* check message filter */
186 if (!MSG_CheckFilter(message
, first
, last
))
189 return SYSQ_MSG_CONTINUE
;
192 hCursorQueue
= queue
->self
;
197 if (HOOK_IsHooked( WH_MOUSE
))
199 MOUSEHOOKSTRUCT16
*hook
= SEGPTR_NEW(MOUSEHOOKSTRUCT16
);
202 hook
->pt
= screen_pt
;
204 hook
->wHitTestCode
= hittest
;
205 hook
->dwExtraInfo
= 0;
206 ret
= HOOK_CallHooks16( WH_MOUSE
, remove
? HC_ACTION
: HC_NOREMOVE
,
207 message
, (LPARAM
)SEGPTR_GET(hook
) );
210 if( ret
) return MAKELONG((INT16
)SYSQ_MSG_SKIP
, hittest
);
213 if ((hittest
== HTERROR
) || (hittest
== HTNOWHERE
))
215 else if( remove
&& mouseClick
)
217 HWND hwndTop
= WIN_GetTopParent( hWnd
);
219 if( mouseClick
== 1 )
222 dblclk_time_limit
= msg
->time
;
223 clk_message
= msg
->message
;
227 /* got double click - zero them out */
228 dblclk_time_limit
= clk_hwnd
= 0;
232 /* Send the WM_PARENTNOTIFY,
233 * note that even for double/nonclient clicks
234 * notification message is still WM_L/M/RBUTTONDOWN.
237 MSG_SendParentNotify( pWnd
, msg
->message
& 0xffff, 0, MAKELPARAM(screen_pt
.x
, screen_pt
.y
) );
239 /* Activate the window if needed */
241 if (hWnd
!= GetActiveWindow() && hWnd
!= GetDesktopWindow())
243 LONG ret
= SendMessageA( hWnd
, WM_MOUSEACTIVATE
, hwndTop
,
244 MAKELONG( hittest
, message
) );
246 if ((ret
== MA_ACTIVATEANDEAT
) || (ret
== MA_NOACTIVATEANDEAT
))
249 if (((ret
== MA_ACTIVATE
) || (ret
== MA_ACTIVATEANDEAT
))
250 && hwndTop
!= GetActiveWindow() )
251 if (!WINPOS_SetActiveWindow( hwndTop
, TRUE
, TRUE
))
255 } else sendSC
= (remove
&& sendSC
);
257 /* Send the WM_SETCURSOR message */
260 SendMessageA( hWnd
, WM_SETCURSOR
, hWnd
,
261 MAKELONG( hittest
, message
));
262 if (eatMsg
) return MAKELONG( (UINT16
)SYSQ_MSG_SKIP
, hittest
);
265 msg
->message
= message
;
266 msg
->lParam
= MAKELONG( pt
.x
, pt
.y
);
267 return SYSQ_MSG_ACCEPT
;
271 /***********************************************************************
272 * MSG_TranslateKbdMsg
274 * Translate an keyboard hardware event into a real message.
276 static DWORD
MSG_TranslateKbdMsg( HWND hTopWnd
, DWORD first
, DWORD last
,
277 MSG
*msg
, BOOL remove
)
279 WORD message
= msg
->message
;
280 HWND hWnd
= GetFocus();
283 /* Should check Ctrl-Esc and PrintScreen here */
287 /* Send the message to the active window instead, */
288 /* translating messages to their WM_SYS equivalent */
290 hWnd
= GetActiveWindow();
292 if( message
< WM_SYSKEYDOWN
)
293 message
+= WM_SYSKEYDOWN
- WM_KEYDOWN
;
295 pWnd
= WIN_FindWndPtr( hWnd
);
296 if (pWnd
&& (pWnd
->hmemTaskQ
!= GetFastQueue16()))
298 /* Not for the current task */
299 MESSAGEQUEUE
*queue
= (MESSAGEQUEUE
*)QUEUE_Lock( GetFastQueue16() );
300 if (queue
) QUEUE_ClearWakeBit( queue
, QS_KEY
);
301 QUEUE_Unlock( queue
);
303 /* Wake up the other task */
304 queue
= (MESSAGEQUEUE
*)QUEUE_Lock( pWnd
->hmemTaskQ
);
305 if (queue
) QUEUE_SetWakeBit( queue
, QS_KEY
);
306 QUEUE_Unlock( queue
);
307 return SYSQ_MSG_ABANDON
;
310 if (hTopWnd
&& hWnd
!= hTopWnd
)
311 if (!IsChild(hTopWnd
, hWnd
)) return SYSQ_MSG_CONTINUE
;
312 if (!MSG_CheckFilter(message
, first
, last
)) return SYSQ_MSG_CONTINUE
;
315 msg
->message
= message
;
317 return (HOOK_CallHooks16( WH_KEYBOARD
, remove
? HC_ACTION
: HC_NOREMOVE
,
318 LOWORD (msg
->wParam
), msg
->lParam
)
319 ? SYSQ_MSG_SKIP
: SYSQ_MSG_ACCEPT
);
323 /***********************************************************************
324 * MSG_JournalRecordMsg
326 * Build an EVENTMSG structure and call JOURNALRECORD hook
328 static void MSG_JournalRecordMsg( MSG
*msg
)
330 EVENTMSG
*event
= (EVENTMSG
*) HeapAlloc(SystemHeap
, 0, sizeof(EVENTMSG
));
332 event
->message
= msg
->message
;
333 event
->time
= msg
->time
;
334 if ((msg
->message
>= WM_KEYFIRST
) && (msg
->message
<= WM_KEYLAST
))
336 event
->paramL
= (msg
->wParam
& 0xFF) | (HIWORD(msg
->lParam
) << 8);
337 event
->paramH
= msg
->lParam
& 0x7FFF;
338 if (HIWORD(msg
->lParam
) & 0x0100)
339 event
->paramH
|= 0x8000; /* special_key - bit */
340 HOOK_CallHooksA( WH_JOURNALRECORD
, HC_ACTION
, 0, (LPARAM
)event
);
342 else if ((msg
->message
>= WM_MOUSEFIRST
) && (msg
->message
<= WM_MOUSELAST
))
344 event
->paramL
= LOWORD(msg
->lParam
); /* X pos */
345 event
->paramH
= HIWORD(msg
->lParam
); /* Y pos */
346 ClientToScreen16( msg
->hwnd
, (LPPOINT16
)&event
->paramL
);
347 HOOK_CallHooksA( WH_JOURNALRECORD
, HC_ACTION
, 0, (LPARAM
)event
);
349 else if ((msg
->message
>= WM_NCMOUSEFIRST
) &&
350 (msg
->message
<= WM_NCMOUSELAST
))
352 event
->paramL
= LOWORD(msg
->lParam
); /* X pos */
353 event
->paramH
= HIWORD(msg
->lParam
); /* Y pos */
354 event
->message
+= WM_MOUSEMOVE
-WM_NCMOUSEMOVE
;/* give no info about NC area */
355 HOOK_CallHooksA( WH_JOURNALRECORD
, HC_ACTION
, 0, (LPARAM
)event
);
358 HeapFree(SystemHeap
, 0, event
);
361 /***********************************************************************
362 * MSG_JournalPlayBackMsg
364 * Get an EVENTMSG struct via call JOURNALPLAYBACK hook function
366 static int MSG_JournalPlayBackMsg(void)
369 long wtime
,lParam
,wParam
;
370 WORD keyDown
,i
,result
=0;
372 if ( HOOK_IsHooked( WH_JOURNALPLAYBACK
) )
374 tmpMsg
= (EVENTMSG
*) HeapAlloc(SystemHeap
, 0, sizeof(EVENTMSG
));
375 if (!tmpMsg
) return result
;
377 wtime
=HOOK_CallHooksA( WH_JOURNALPLAYBACK
, HC_GETNEXT
, 0,
379 /* TRACE(msg,"Playback wait time =%ld\n",wtime); */
383 if ((tmpMsg
->message
>= WM_KEYFIRST
) && (tmpMsg
->message
<= WM_KEYLAST
))
385 wParam
=tmpMsg
->paramL
& 0xFF;
386 lParam
=MAKELONG(tmpMsg
->paramH
&0x7ffff,tmpMsg
->paramL
>>8);
387 if (tmpMsg
->message
== WM_KEYDOWN
|| tmpMsg
->message
== WM_SYSKEYDOWN
)
389 for (keyDown
=i
=0; i
<256 && !keyDown
; i
++)
390 if (InputKeyStateTable
[i
] & 0x80)
393 lParam
|= 0x40000000;
394 AsyncKeyStateTable
[wParam
]=InputKeyStateTable
[wParam
] |= 0x80;
396 else /* WM_KEYUP, WM_SYSKEYUP */
398 lParam
|= 0xC0000000;
399 AsyncKeyStateTable
[wParam
]=InputKeyStateTable
[wParam
] &= ~0x80;
401 if (InputKeyStateTable
[VK_MENU
] & 0x80)
402 lParam
|= 0x20000000;
403 if (tmpMsg
->paramH
& 0x8000) /*special_key bit*/
404 lParam
|= 0x01000000;
405 hardware_event( tmpMsg
->message
& 0xffff, LOWORD(wParam
), lParam
,
406 0, 0, tmpMsg
->time
, 0 );
410 if ((tmpMsg
->message
>= WM_MOUSEFIRST
) && (tmpMsg
->message
<= WM_MOUSELAST
))
412 switch (tmpMsg
->message
)
415 MouseButtonsStates
[0]=AsyncMouseButtonsStates
[0]=TRUE
;break;
417 MouseButtonsStates
[0]=AsyncMouseButtonsStates
[0]=FALSE
;break;
419 MouseButtonsStates
[1]=AsyncMouseButtonsStates
[1]=TRUE
;break;
421 MouseButtonsStates
[1]=AsyncMouseButtonsStates
[1]=FALSE
;break;
423 MouseButtonsStates
[2]=AsyncMouseButtonsStates
[2]=TRUE
;break;
425 MouseButtonsStates
[2]=AsyncMouseButtonsStates
[2]=FALSE
;break;
427 AsyncKeyStateTable
[VK_LBUTTON
]= InputKeyStateTable
[VK_LBUTTON
] = MouseButtonsStates
[0] ? 0x80 : 0;
428 AsyncKeyStateTable
[VK_MBUTTON
]= InputKeyStateTable
[VK_MBUTTON
] = MouseButtonsStates
[1] ? 0x80 : 0;
429 AsyncKeyStateTable
[VK_RBUTTON
]= InputKeyStateTable
[VK_RBUTTON
] = MouseButtonsStates
[2] ? 0x80 : 0;
430 SetCursorPos(tmpMsg
->paramL
,tmpMsg
->paramH
);
431 lParam
=MAKELONG(tmpMsg
->paramL
,tmpMsg
->paramH
);
433 if (MouseButtonsStates
[0]) wParam
|= MK_LBUTTON
;
434 if (MouseButtonsStates
[1]) wParam
|= MK_MBUTTON
;
435 if (MouseButtonsStates
[2]) wParam
|= MK_RBUTTON
;
436 hardware_event( tmpMsg
->message
& 0xffff, LOWORD (wParam
), lParam
,
437 tmpMsg
->paramL
, tmpMsg
->paramH
, tmpMsg
->time
, 0 );
440 HOOK_CallHooksA( WH_JOURNALPLAYBACK
, HC_SKIP
, 0,
446 if( tmpMsg
->message
== WM_QUEUESYNC
)
447 if (HOOK_IsHooked( WH_CBT
))
448 HOOK_CallHooksA( WH_CBT
, HCBT_QS
, 0, 0L);
450 result
= QS_MOUSE
| QS_KEY
; /* ? */
452 HeapFree(SystemHeap
, 0, tmpMsg
);
457 /***********************************************************************
458 * MSG_PeekHardwareMsg
460 * Peek for a hardware message matching the hwnd and message filters.
462 static BOOL
MSG_PeekHardwareMsg( MSG
*msg
, HWND hwnd
, DWORD first
, DWORD last
,
465 /* FIXME: should deal with MSG32 instead of MSG16 */
467 DWORD status
= SYSQ_MSG_ACCEPT
;
468 MESSAGEQUEUE
*sysMsgQueue
= QUEUE_GetSysQueue();
470 QMSG
*nextqmsg
, *qmsg
= 0;
472 /* FIXME: there has to be a better way to do this */
475 EnterCriticalSection(&sysMsgQueue
->cSection
);
477 qmsg
= sysMsgQueue
->firstMsg
;
479 /* If the queue is empty, attempt to fill it */
480 if (!sysMsgQueue
->msgCount
&& THREAD_IsWin16( THREAD_Current() )
482 EVENT_WaitNetEvent( FALSE
, FALSE
);
484 for ( kbd_msg
= 0; qmsg
; qmsg
= nextqmsg
)
489 nextqmsg
= qmsg
->nextMsg
;
491 /* Translate message */
493 if ((msg
->message
>= WM_MOUSEFIRST
) && (msg
->message
<= WM_MOUSELAST
))
495 HWND hWndScope
= (HWND
)qmsg
->extraInfo
;
497 status
= MSG_TranslateMouseMsg(hwnd
, first
, last
, msg
, remove
,
498 (Options
.managed
&& IsWindow(hWndScope
) )
499 ? WIN_FindWndPtr(hWndScope
) : WIN_GetDesktop() );
502 else if ((msg
->message
>= WM_KEYFIRST
) && (msg
->message
<= WM_KEYLAST
))
504 status
= MSG_TranslateKbdMsg(hwnd
, first
, last
, msg
, remove
);
507 else /* Non-standard hardware event */
509 HARDWAREHOOKSTRUCT16
*hook
;
510 if ((hook
= SEGPTR_NEW(HARDWAREHOOKSTRUCT16
)))
513 hook
->hWnd
= msg
->hwnd
;
514 hook
->wMessage
= msg
->message
& 0xffff;
515 hook
->wParam
= LOWORD (msg
->wParam
);
516 hook
->lParam
= msg
->lParam
;
517 ret
= HOOK_CallHooks16( WH_HARDWARE
,
518 remove
? HC_ACTION
: HC_NOREMOVE
,
519 0, (LPARAM
)SEGPTR_GET(hook
) );
523 QUEUE_RemoveMsg( sysMsgQueue
, qmsg
);
526 status
= SYSQ_MSG_ACCEPT
;
530 switch (LOWORD(status
))
532 case SYSQ_MSG_ACCEPT
:
536 if (HOOK_IsHooked( WH_CBT
))
539 HOOK_CallHooks16( WH_CBT
, HCBT_KEYSKIPPED
,
540 LOWORD (msg
->wParam
), msg
->lParam
);
543 MOUSEHOOKSTRUCT16
*hook
= SEGPTR_NEW(MOUSEHOOKSTRUCT16
);
546 CONV_POINT32TO16( &msg
->pt
,&hook
->pt
);
547 hook
->hwnd
= msg
->hwnd
;
548 hook
->wHitTestCode
= HIWORD(status
);
549 hook
->dwExtraInfo
= 0;
550 HOOK_CallHooks16( WH_CBT
, HCBT_CLICKSKIPPED
,msg
->message
& 0xffff,
551 (LPARAM
)SEGPTR_GET(hook
) );
558 QUEUE_RemoveMsg( sysMsgQueue
, qmsg
);
561 case SYSQ_MSG_CONTINUE
:
564 case SYSQ_MSG_ABANDON
:
565 LeaveCriticalSection(&sysMsgQueue
->cSection
);
571 if (HOOK_IsHooked( WH_JOURNALRECORD
)) MSG_JournalRecordMsg( msg
);
572 QUEUE_RemoveMsg( sysMsgQueue
, qmsg
);
574 LeaveCriticalSection(&sysMsgQueue
->cSection
);
577 LeaveCriticalSection(&sysMsgQueue
->cSection
);
582 /**********************************************************************
583 * SetDoubleClickTime16 (USER.20)
585 void WINAPI
SetDoubleClickTime16( UINT16 interval
)
587 SetDoubleClickTime( interval
);
591 /**********************************************************************
592 * SetDoubleClickTime32 (USER32.480)
594 BOOL WINAPI
SetDoubleClickTime( UINT interval
)
596 doubleClickSpeed
= interval
? interval
: 500;
601 /**********************************************************************
602 * GetDoubleClickTime16 (USER.21)
604 UINT16 WINAPI
GetDoubleClickTime16(void)
606 return doubleClickSpeed
;
610 /**********************************************************************
611 * GetDoubleClickTime32 (USER32.239)
613 UINT WINAPI
GetDoubleClickTime(void)
615 return doubleClickSpeed
;
619 /***********************************************************************
622 * Implementation of an inter-task SendMessage.
624 static LRESULT
MSG_SendMessage( HQUEUE16 hDestQueue
, HWND hwnd
, UINT msg
,
625 WPARAM wParam
, LPARAM lParam
, WORD flags
)
627 MESSAGEQUEUE
*queue
, *destQ
;
631 if (IsTaskLocked16() || !IsWindow(hwnd
))
634 /* create a SMSG structure to hold SendMessage() parameters */
635 if (! (smsg
= (SMSG
*) HeapAlloc( SystemHeap
, 0, sizeof(SMSG
) )) )
638 if (!(queue
= (MESSAGEQUEUE
*)QUEUE_Lock( GetFastQueue16() ))) return 0;
640 if (!(destQ
= (MESSAGEQUEUE
*)QUEUE_Lock( hDestQueue
)))
642 QUEUE_Unlock( queue
);
646 TRACE(sendmsg
,"SM: %s [%04x] (%04x -> %04x)\n",
647 SPY_GetMsgName(msg
), msg
, queue
->self
, hDestQueue
);
649 /* fill up SMSG structure */
652 smsg
->wParam
= wParam
;
653 smsg
->lParam
= lParam
;
656 smsg
->hSrcQueue
= GetFastQueue16();
657 smsg
->hDstQueue
= hDestQueue
;
660 /* add smsg struct in the processing SM list of the source queue */
661 QUEUE_AddSMSG(queue
, SM_PROCESSING_LIST
, smsg
);
663 /* add smsg struct in the pending list of the destination queue */
664 if (QUEUE_AddSMSG(destQ
, SM_PENDING_LIST
, smsg
) == FALSE
)
667 /* perform task switch and wait for the result */
668 while( (smsg
->flags
& SMSG_HAVE_RESULT
) == 0 )
670 /* force destination task to run next, if 16 bit threads */
671 if (THREAD_IsWin16(THREAD_Current()) && THREAD_IsWin16(destQ
->thdb
) )
672 DirectedYield16( destQ
->thdb
->teb
.htask16
);
674 QUEUE_WaitBits( QS_SMRESULT
);
676 if (! (smsg
->flags
& SMSG_HAVE_RESULT
) )
678 /* not supposed to happen */
679 ERR(sendmsg
, "SMSG_HAVE_RESULT not set: smsg->flags=%x\n", smsg
->flags
);
680 QUEUE_ClearWakeBit( queue
, QS_SMRESULT
);
684 lResult
= smsg
->lResult
;
685 TRACE(sendmsg
,"smResult = %08x\n", (unsigned)lResult
);
690 * Warning: This one looks like a hack but it has a very good reason
691 * for existing. It will become obsolete once an input task/thread is
694 * Normally, once a send message operation is complete, you want to
695 * clear the wake bit QS_SMRESULT for this queue. However, because of
696 * the way the 16 bit threads are scheduled, the EVENT_WaitNetEvent
697 * method might be sending messages using the same message queue as the
698 * one used for this send message. Since the recipient of that other
699 * send message is in another thread, it is totally possible that a
700 * send message operation that occured in time before this one
701 * has completed it's work before this one does.
702 * If we clear the wake bit without checking and that operation has
703 * completed, the send message operation waiting in the call stack
704 * of the current thread will wait forever.
706 EnterCriticalSection(&queue
->cSection
);
708 if ( (smsg
->nextProcessing
==0) ||
709 (( smsg
->nextProcessing
->flags
& SMSG_HAVE_RESULT
) == 0 ) )
710 QUEUE_ClearWakeBit( queue
, QS_SMRESULT
);
712 LeaveCriticalSection(&queue
->cSection
);
714 /* remove the smsg from the processingg list of the source queue */
715 QUEUE_RemoveSMSG( queue
, SM_PROCESSING_LIST
, smsg
);
717 /* Note: the destination thread is in charge of removing the smsg from
720 /* sender thread is in charge of releasing smsg if it's not an
722 if ( !(smsg
->flags
& SMSG_EARLY_REPLY
) )
724 HeapFree(SystemHeap
, 0, smsg
);
728 /* In the case of an early reply, sender thread will released the
729 smsg structure if the receiver thread is done (SMSG_RECEIVED set).
730 If the receiver thread isn't done, SMSG_RECEIVER_CLEANS_UP flag
731 is set, and it will be the receiver responsability to released
733 EnterCriticalSection( &queue
->cSection
);
735 if (smsg
->flags
& SMSG_RECEIVED
)
736 HeapFree(SystemHeap
, 0, smsg
);
738 smsg
->flags
|= SMSG_RECEIVER_CLEANS
;
740 LeaveCriticalSection( &queue
->cSection
);
743 QUEUE_Unlock( queue
);
744 QUEUE_Unlock( destQ
);
746 TRACE(sendmsg
,"done!\n");
751 /***********************************************************************
752 * ReplyMessage16 (USER.115)
754 void WINAPI
ReplyMessage16( LRESULT result
)
756 ReplyMessage( result
);
759 /***********************************************************************
760 * ReplyMessage (USER.115)
762 BOOL WINAPI
ReplyMessage( LRESULT result
)
764 MESSAGEQUEUE
*senderQ
= 0;
765 MESSAGEQUEUE
*queue
= 0;
769 if (!(queue
= (MESSAGEQUEUE
*)QUEUE_Lock( GetFastQueue16() ))) return FALSE
;
771 TRACE(sendmsg
,"ReplyMessage, queue %04x\n", queue
->self
);
773 while ((smsg
= queue
->smWaiting
) != 0)
775 /* if message has already been reply, continue the loop of receving
777 if ( smsg
->flags
& SMSG_ALREADY_REPLIED
)
778 goto ReplyMessageDone
;
780 senderQ
= (MESSAGEQUEUE
*)QUEUE_Lock( smsg
->hSrcQueue
);
782 goto ReplyMessageDone
;
784 /* if send message pending, processed it */
785 if( queue
->wakeBits
& QS_SENDMESSAGE
)
787 /* Note: QUEUE_ReceiveMessage() and ReplyMessage call each other */
788 QUEUE_ReceiveMessage( queue
);
789 QUEUE_Unlock( senderQ
);
790 continue; /* ReceiveMessage() already called us */
792 break; /* message to reply is in smsg */
796 goto ReplyMessageDone
;
798 smsg
->lResult
= result
;
799 smsg
->flags
|= SMSG_ALREADY_REPLIED
;
801 /* check if it's an early reply (called by the application) or
802 a regular reply (called by ReceiveMessage) */
803 if ( !(smsg
->flags
& SMSG_SENDING_REPLY
) )
804 smsg
->flags
|= SMSG_EARLY_REPLY
;
806 TRACE( sendmsg
,"\trpm: smResult = %08lx\n", (long) result
);
808 /* remove smsg from the waiting list, if it's not an early reply */
809 /* it is important to leave it in the waiting list if it's an early
810 reply, to be protected aginst multiple call to ReplyMessage() */
811 if ( !(smsg
->flags
& SMSG_EARLY_REPLY
) )
812 QUEUE_RemoveSMSG( queue
, SM_WAITING_LIST
, smsg
);
814 EnterCriticalSection(&senderQ
->cSection
);
816 smsg
->flags
|= SMSG_HAVE_RESULT
;
818 /* tell the sending task that its reply is ready */
819 QUEUE_SetWakeBit( senderQ
, QS_SMRESULT
);
821 LeaveCriticalSection(&senderQ
->cSection
);
823 /* switch directly to sending task (16 bit thread only) */
824 if ( THREAD_IsWin16( THREAD_Current() ) && THREAD_IsWin16( senderQ
->thdb
) )
825 DirectedYield16( senderQ
->thdb
->teb
.htask16
);
831 QUEUE_Unlock( senderQ
);
833 QUEUE_Unlock( queue
);
838 /***********************************************************************
841 static BOOL
MSG_PeekMessage( LPMSG msg
, HWND hwnd
, DWORD first
, DWORD last
,
842 WORD flags
, BOOL peek
)
845 MESSAGEQUEUE
*msgQueue
;
850 DDE_TestDDE(hwnd
); /* do we have dde handling in the window ?*/
851 DDE_GetRemoteMessage();
852 #endif /* CONFIG_IPC */
854 mask
= QS_POSTMESSAGE
| QS_SENDMESSAGE
; /* Always selected */
857 if ((first
<= WM_KEYLAST
) && (last
>= WM_KEYFIRST
)) mask
|= QS_KEY
;
858 if ( ((first
<= WM_MOUSELAST
) && (last
>= WM_MOUSEFIRST
)) ||
859 ((first
<= WM_NCMOUSELAST
) && (last
>= WM_NCMOUSEFIRST
)) ) mask
|= QS_MOUSE
;
860 if ((first
<= WM_TIMER
) && (last
>= WM_TIMER
)) mask
|= QS_TIMER
;
861 if ((first
<= WM_SYSTIMER
) && (last
>= WM_SYSTIMER
)) mask
|= QS_TIMER
;
862 if ((first
<= WM_PAINT
) && (last
>= WM_PAINT
)) mask
|= QS_PAINT
;
864 else mask
|= QS_MOUSE
| QS_KEY
| QS_TIMER
| QS_PAINT
;
866 if (IsTaskLocked16()) flags
|= PM_NOYIELD
;
868 /* Never yield on Win32 threads */
869 if (!THREAD_IsWin16(THREAD_Current())) flags
|= PM_NOYIELD
;
875 hQueue
= GetFastQueue16();
876 msgQueue
= (MESSAGEQUEUE
*)QUEUE_Lock( hQueue
);
877 if (!msgQueue
) return FALSE
;
878 msgQueue
->changeBits
= 0;
880 /* First handle a message put by SendMessage() */
882 while (msgQueue
->wakeBits
& QS_SENDMESSAGE
)
883 QUEUE_ReceiveMessage( msgQueue
);
885 /* Now handle a WM_QUIT message */
887 if (msgQueue
->wPostQMsg
&&
888 (!first
|| WM_QUIT
>= first
) &&
889 (!last
|| WM_QUIT
<= last
) )
892 msg
->message
= WM_QUIT
;
893 msg
->wParam
= msgQueue
->wExitCode
;
895 if (flags
& PM_REMOVE
) msgQueue
->wPostQMsg
= 0;
899 /* Now find a normal message */
901 if (((msgQueue
->wakeBits
& mask
) & QS_POSTMESSAGE
) &&
902 ((qmsg
= QUEUE_FindMsg( msgQueue
, hwnd
, first
, last
)) != 0))
906 msgQueue
->GetMessageTimeVal
= msg
->time
;
907 CONV_POINT32TO16(&msg
->pt
, &pt16
);
908 msgQueue
->GetMessagePosVal
= *(DWORD
*)&pt16
;
909 msgQueue
->GetMessageExtraInfoVal
= qmsg
->extraInfo
;
911 if (flags
& PM_REMOVE
) QUEUE_RemoveMsg( msgQueue
, qmsg
);
915 msgQueue
->changeBits
|= MSG_JournalPlayBackMsg();
917 /* Now find a hardware event */
919 if (((msgQueue
->wakeBits
& mask
) & (QS_MOUSE
| QS_KEY
)) &&
920 MSG_PeekHardwareMsg( msg
, hwnd
, first
, last
, flags
& PM_REMOVE
))
923 msgQueue
->GetMessageTimeVal
= msg
->time
;
924 CONV_POINT32TO16(&msg
->pt
, &pt16
);
925 msgQueue
->GetMessagePosVal
= *(DWORD
*)&pt16
;
926 msgQueue
->GetMessageExtraInfoVal
= 0; /* Always 0 for now */
930 /* Check again for SendMessage */
932 while (msgQueue
->wakeBits
& QS_SENDMESSAGE
)
933 QUEUE_ReceiveMessage( msgQueue
);
935 /* Now find a WM_PAINT message */
937 if ((msgQueue
->wakeBits
& mask
) & QS_PAINT
)
940 msg
->hwnd
= WIN_FindWinToRepaint( hwnd
, hQueue
);
941 msg
->message
= WM_PAINT
;
945 if ((wndPtr
= WIN_FindWndPtr(msg
->hwnd
)))
947 if( wndPtr
->dwStyle
& WS_MINIMIZE
&&
948 wndPtr
->class->hIcon
)
950 msg
->message
= WM_PAINTICON
;
954 if( !hwnd
|| msg
->hwnd
== hwnd
|| IsChild16(hwnd
,msg
->hwnd
) )
956 if( wndPtr
->flags
& WIN_INTERNAL_PAINT
&& !wndPtr
->hrgnUpdate
)
958 wndPtr
->flags
&= ~WIN_INTERNAL_PAINT
;
959 QUEUE_DecPaintCount( hQueue
);
966 /* Check for timer messages, but yield first */
968 if (!(flags
& PM_NOYIELD
))
971 while (msgQueue
->wakeBits
& QS_SENDMESSAGE
)
972 QUEUE_ReceiveMessage( msgQueue
);
974 if ((msgQueue
->wakeBits
& mask
) & QS_TIMER
)
976 if (TIMER_GetTimerMsg(msg
, hwnd
, hQueue
, flags
& PM_REMOVE
)) break;
981 if (!(flags
& PM_NOYIELD
)) UserYield16();
983 QUEUE_Unlock( msgQueue
);
986 msgQueue
->wakeMask
= mask
;
987 QUEUE_WaitBits( mask
);
988 QUEUE_Unlock( msgQueue
);
991 /* instead of unlocking queue for every break condition, all break
992 condition will fall here */
993 QUEUE_Unlock( msgQueue
);
995 /* We got a message */
996 if (flags
& PM_REMOVE
)
998 WORD message
= msg
->message
;
1000 if (message
== WM_KEYDOWN
|| message
== WM_SYSKEYDOWN
)
1002 BYTE
*p
= &QueueKeyStateTable
[msg
->wParam
& 0xff];
1008 else if (message
== WM_KEYUP
|| message
== WM_SYSKEYUP
)
1009 QueueKeyStateTable
[msg
->wParam
& 0xff] &= ~0x80;
1011 if (peek
) return TRUE
;
1012 else return (msg
->message
!= WM_QUIT
);
1015 /***********************************************************************
1016 * MSG_InternalGetMessage
1018 * GetMessage() function for internal use. Behave like GetMessage(),
1019 * but also call message filters and optionally send WM_ENTERIDLE messages.
1020 * 'hwnd' must be the handle of the dialog or menu window.
1021 * 'code' is the message filter value (MSGF_??? codes).
1023 BOOL
MSG_InternalGetMessage( MSG
*msg
, HWND hwnd
, HWND hwndOwner
,
1024 WPARAM code
, WORD flags
, BOOL sendIdle
)
1030 if (!MSG_PeekMessage( msg
, 0, 0, 0, flags
, TRUE
))
1032 /* No message present -> send ENTERIDLE and wait */
1033 if (IsWindow(hwndOwner
))
1034 SendMessageA( hwndOwner
, WM_ENTERIDLE
,
1035 code
, (LPARAM
)hwnd
);
1036 MSG_PeekMessage( msg
, 0, 0, 0, flags
, FALSE
);
1039 else /* Always wait for a message */
1040 MSG_PeekMessage( msg
, 0, 0, 0, flags
, FALSE
);
1042 /* Call message filters */
1044 if (HOOK_IsHooked( WH_SYSMSGFILTER
) || HOOK_IsHooked( WH_MSGFILTER
))
1046 MSG
*pmsg
= HeapAlloc( SystemHeap
, 0, sizeof(MSG
) );
1051 ret
= (HOOK_CallHooksA( WH_SYSMSGFILTER
, code
, 0,
1053 HOOK_CallHooksA( WH_MSGFILTER
, code
, 0,
1056 HeapFree( SystemHeap
, 0, pmsg
);
1059 /* Message filtered -> remove it from the queue */
1060 /* if it's still there. */
1061 if (!(flags
& PM_REMOVE
))
1062 MSG_PeekMessage( msg
, 0, 0, 0, PM_REMOVE
, TRUE
);
1068 return (msg
->message
!= WM_QUIT
);
1073 /***********************************************************************
1074 * PeekMessage16 (USER.109)
1076 BOOL16 WINAPI
PeekMessage16( LPMSG16 lpmsg
, HWND16 hwnd
, UINT16 first
,
1077 UINT16 last
, UINT16 flags
)
1081 ret
= PeekMessageA(&msg32
, hwnd
, first
, last
, flags
);
1082 STRUCT32_MSG32to16(&msg32
, lpmsg
);
1086 /***********************************************************************
1087 * WIN16_PeekMessage32 (USER.819)
1089 BOOL16 WINAPI
PeekMessage32_16( LPMSG16_32 lpmsg16_32
, HWND16 hwnd
,
1090 UINT16 first
, UINT16 last
, UINT16 flags
, BOOL16 wHaveParamHigh
)
1092 if (wHaveParamHigh
== FALSE
)
1094 lpmsg16_32
->wParamHigh
= 0;
1095 return PeekMessage16(&(lpmsg16_32
->msg
), hwnd
, first
, last
, flags
);
1102 ret
= (BOOL16
)PeekMessageA(&msg32
, (HWND
)hwnd
,
1103 (UINT
)first
, (UINT
)last
, (UINT
)flags
);
1104 lpmsg16_32
->msg
.hwnd
= msg32
.hwnd
;
1105 lpmsg16_32
->msg
.message
= msg32
.message
;
1106 lpmsg16_32
->msg
.wParam
= LOWORD(msg32
.wParam
);
1107 lpmsg16_32
->msg
.lParam
= msg32
.lParam
;
1108 lpmsg16_32
->msg
.time
= msg32
.time
;
1109 lpmsg16_32
->msg
.pt
.x
= (INT16
)msg32
.pt
.x
;
1110 lpmsg16_32
->msg
.pt
.y
= (INT16
)msg32
.pt
.y
;
1111 lpmsg16_32
->wParamHigh
= HIWORD(msg32
.wParam
);
1117 /***********************************************************************
1120 BOOL WINAPI
PeekMessageA( LPMSG lpmsg
, HWND hwnd
,
1121 UINT min
,UINT max
,UINT wRemoveMsg
)
1123 return MSG_PeekMessage( lpmsg
, hwnd
, min
, max
, wRemoveMsg
, TRUE
);
1126 /***********************************************************************
1127 * PeekMessageW Check queue for messages
1129 * Checks for a message in the thread's queue, filtered as for
1130 * GetMessage(). Returns immediately whether a message is available
1133 * Whether a retrieved message is removed from the queue is set by the
1134 * _wRemoveMsg_ flags, which should be one of the following values:
1136 * PM_NOREMOVE Do not remove the message from the queue.
1138 * PM_REMOVE Remove the message from the queue.
1140 * In addition, PM_NOYIELD may be combined into _wRemoveMsg_ to
1141 * request that the system not yield control during PeekMessage();
1142 * however applications may not rely on scheduling behavior.
1146 * Nonzero if a message is available and is retrieved, zero otherwise.
1153 BOOL WINAPI
PeekMessageW(
1154 LPMSG lpmsg
, /* buffer to receive message */
1155 HWND hwnd
, /* restrict to messages for hwnd */
1156 UINT min
, /* minimum message to receive */
1157 UINT max
, /* maximum message to receive */
1158 UINT wRemoveMsg
/* removal flags */
1160 /* FIXME: Should perform Unicode translation on specific messages */
1161 return PeekMessageA(lpmsg
,hwnd
,min
,max
,wRemoveMsg
);
1164 /***********************************************************************
1165 * GetMessage16 (USER.108)
1167 BOOL16 WINAPI
GetMessage16( SEGPTR msg
, HWND16 hwnd
, UINT16 first
, UINT16 last
)
1170 MSG16
*lpmsg
= (MSG16
*)PTR_SEG_TO_LIN(msg
);
1173 ret
= GetMessageA( &msg32
, hwnd
, first
, last
);
1175 STRUCT32_MSG32to16( &msg32
, lpmsg
);
1177 TRACE(msg
,"message %04x, hwnd %04x, filter(%04x - %04x)\n", lpmsg
->message
,
1178 hwnd
, first
, last
);
1183 /***********************************************************************
1184 * WIN16_GetMessage32 (USER.820)
1186 BOOL16 WINAPI
GetMessage32_16( SEGPTR msg16_32
, HWND16 hWnd
, UINT16 first
,
1187 UINT16 last
, BOOL16 wHaveParamHigh
)
1189 MSG32_16
*lpmsg16_32
= (MSG32_16
*)PTR_SEG_TO_LIN(msg16_32
);
1191 if (wHaveParamHigh
== FALSE
) /* normal GetMessage16 call */
1194 lpmsg16_32
->wParamHigh
= 0; /* you never know... */
1195 /* WARNING: msg16_32->msg has to be the first variable in the struct */
1196 return GetMessage16(msg16_32
, hWnd
, first
, last
);
1203 ret
= (BOOL16
)GetMessageA(&msg32
, hWnd
, first
, last
);
1204 lpmsg16_32
->msg
.hwnd
= msg32
.hwnd
;
1205 lpmsg16_32
->msg
.message
= msg32
.message
;
1206 lpmsg16_32
->msg
.wParam
= LOWORD(msg32
.wParam
);
1207 lpmsg16_32
->msg
.lParam
= msg32
.lParam
;
1208 lpmsg16_32
->msg
.time
= msg32
.time
;
1209 lpmsg16_32
->msg
.pt
.x
= (INT16
)msg32
.pt
.x
;
1210 lpmsg16_32
->msg
.pt
.y
= (INT16
)msg32
.pt
.y
;
1211 lpmsg16_32
->wParamHigh
= HIWORD(msg32
.wParam
);
1216 /***********************************************************************
1217 * GetMessage32A (USER32.270)
1219 BOOL WINAPI
GetMessageA(MSG
* lpmsg
,HWND hwnd
,UINT min
,UINT max
)
1221 MSG_PeekMessage( lpmsg
, hwnd
, min
, max
, PM_REMOVE
, FALSE
);
1223 TRACE(msg
,"message %04x, hwnd %04x, filter(%04x - %04x)\n", lpmsg
->message
,
1226 HOOK_CallHooksA( WH_GETMESSAGE
, HC_ACTION
, 0, (LPARAM
)lpmsg
);
1228 return (lpmsg
->message
!= WM_QUIT
);
1231 /***********************************************************************
1232 * GetMessage32W (USER32.274) Retrieve next message
1234 * GetMessage retrieves the next event from the calling thread's
1235 * queue and deposits it in *lpmsg.
1237 * If _hwnd_ is not NULL, only messages for window _hwnd_ and its
1238 * children as specified by IsChild() are retrieved. If _hwnd_ is NULL
1239 * all application messages are retrieved.
1241 * _min_ and _max_ specify the range of messages of interest. If
1242 * min==max==0, no filtering is performed. Useful examples are
1243 * WM_KEYFIRST and WM_KEYLAST to retrieve keyboard input, and
1244 * WM_MOUSEFIRST and WM_MOUSELAST to retrieve mouse input.
1246 * WM_PAINT messages are not removed from the queue; they remain until
1247 * processed. Other messages are removed from the queue.
1251 * -1 on error, 0 if message is WM_QUIT, nonzero otherwise.
1258 BOOL WINAPI
GetMessageW(
1259 MSG
* lpmsg
, /* buffer to receive message */
1260 HWND hwnd
, /* restrict to messages for hwnd */
1261 UINT min
, /* minimum message to receive */
1262 UINT max
/* maximum message to receive */
1265 return GetMessageA(lpmsg
, hwnd
, min
, max
);
1269 /***********************************************************************
1270 * PostMessage16 (USER.110)
1272 BOOL16 WINAPI
PostMessage16( HWND16 hwnd
, UINT16 message
, WPARAM16 wParam
,
1275 return (BOOL16
) PostMessageA( hwnd
, message
, wParam
, lParam
);
1279 /***********************************************************************
1280 * PostMessage32A (USER32.419)
1282 BOOL WINAPI
PostMessageA( HWND hwnd
, UINT message
, WPARAM wParam
,
1289 msg
.message
= message
;
1290 msg
.wParam
= wParam
;
1291 msg
.lParam
= lParam
;
1292 msg
.time
= GetTickCount();
1297 if (DDE_PostMessage(&msg
))
1299 #endif /* CONFIG_IPC */
1301 if (hwnd
== HWND_BROADCAST
)
1303 TRACE(msg
,"HWND_BROADCAST !\n");
1304 for (wndPtr
= WIN_GetDesktop()->child
; wndPtr
; wndPtr
= wndPtr
->next
)
1306 if (wndPtr
->dwStyle
& WS_POPUP
|| wndPtr
->dwStyle
& WS_CAPTION
)
1308 TRACE(msg
,"BROADCAST Message to hWnd=%04x m=%04X w=%04X l=%08lX !\n",
1309 wndPtr
->hwndSelf
, message
, wParam
, lParam
);
1310 PostMessageA( wndPtr
->hwndSelf
, message
, wParam
, lParam
);
1313 TRACE(msg
,"End of HWND_BROADCAST !\n");
1317 wndPtr
= WIN_FindWndPtr( hwnd
);
1318 if (!wndPtr
|| !wndPtr
->hmemTaskQ
) return FALSE
;
1320 return QUEUE_AddMsg( wndPtr
->hmemTaskQ
, &msg
, 0 );
1324 /***********************************************************************
1325 * PostMessage32W (USER32.420)
1327 BOOL WINAPI
PostMessageW( HWND hwnd
, UINT message
, WPARAM wParam
,
1331 return PostMessageA( hwnd
, message
, wParam
, lParam
);
1335 /***********************************************************************
1336 * PostAppMessage16 (USER.116)
1338 BOOL16 WINAPI
PostAppMessage16( HTASK16 hTask
, UINT16 message
, WPARAM16 wParam
,
1343 if (GetTaskQueue16(hTask
) == 0) return FALSE
;
1345 msg
.message
= message
;
1346 msg
.wParam
= wParam
;
1347 msg
.lParam
= lParam
;
1348 msg
.time
= GetTickCount();
1352 return QUEUE_AddMsg( GetTaskQueue16(hTask
), &msg
, 0 );
1356 /***********************************************************************
1357 * SendMessage16 (USER.111)
1359 LRESULT WINAPI
SendMessage16( HWND16 hwnd
, UINT16 msg
, WPARAM16 wParam
,
1363 WND
**list
, **ppWnd
;
1367 MSG16 DDE_msg
= { hwnd
, msg
, wParam
, lParam
};
1368 if (DDE_SendMessage(&DDE_msg
)) return TRUE
;
1369 #endif /* CONFIG_IPC */
1371 if (hwnd
== HWND_BROADCAST
)
1373 if (!(list
= WIN_BuildWinArray( WIN_GetDesktop(), 0, NULL
)))
1375 TRACE(msg
,"HWND_BROADCAST !\n");
1376 for (ppWnd
= list
; *ppWnd
; ppWnd
++)
1379 if (!IsWindow(wndPtr
->hwndSelf
)) continue;
1380 if (wndPtr
->dwStyle
& WS_POPUP
|| wndPtr
->dwStyle
& WS_CAPTION
)
1382 TRACE(msg
,"BROADCAST Message to hWnd=%04x m=%04X w=%04lX l=%08lX !\n",
1383 wndPtr
->hwndSelf
, msg
, (DWORD
)wParam
, lParam
);
1384 SendMessage16( wndPtr
->hwndSelf
, msg
, wParam
, lParam
);
1387 HeapFree( SystemHeap
, 0, list
);
1388 TRACE(msg
,"End of HWND_BROADCAST !\n");
1392 if (HOOK_IsHooked( WH_CALLWNDPROC
))
1396 if ((pmsg
= SEGPTR_NEW(CWPSTRUCT16
)))
1400 pmsg
->wParam
= wParam
;
1401 pmsg
->lParam
= lParam
;
1402 HOOK_CallHooks16( WH_CALLWNDPROC
, HC_ACTION
, 1,
1403 (LPARAM
)SEGPTR_GET(pmsg
) );
1405 msg
= pmsg
->message
;
1406 wParam
= pmsg
->wParam
;
1407 lParam
= pmsg
->lParam
;
1408 SEGPTR_FREE( pmsg
);
1412 if (!(wndPtr
= WIN_FindWndPtr( hwnd
)))
1414 WARN(msg
, "invalid hwnd %04x\n", hwnd
);
1417 if (QUEUE_IsExitingQueue(wndPtr
->hmemTaskQ
))
1418 return 0; /* Don't send anything if the task is dying */
1420 SPY_EnterMessage( SPY_SENDMESSAGE16
, hwnd
, msg
, wParam
, lParam
);
1422 if (wndPtr
->hmemTaskQ
!= GetFastQueue16())
1423 ret
= MSG_SendMessage( wndPtr
->hmemTaskQ
, hwnd
, msg
,
1424 wParam
, lParam
, 0 );
1426 ret
= CallWindowProc16( (WNDPROC16
)wndPtr
->winproc
,
1427 hwnd
, msg
, wParam
, lParam
);
1429 SPY_ExitMessage( SPY_RESULT_OK16
, hwnd
, msg
, ret
);
1433 /************************************************************************
1434 * MSG_CallWndProcHook32
1436 static void MSG_CallWndProcHook( LPMSG pmsg
, BOOL bUnicode
)
1440 cwp
.lParam
= pmsg
->lParam
;
1441 cwp
.wParam
= pmsg
->wParam
;
1442 cwp
.message
= pmsg
->message
;
1443 cwp
.hwnd
= pmsg
->hwnd
;
1445 if (bUnicode
) HOOK_CallHooksW(WH_CALLWNDPROC
, HC_ACTION
, 1, (LPARAM
)&cwp
);
1446 else HOOK_CallHooksA( WH_CALLWNDPROC
, HC_ACTION
, 1, (LPARAM
)&cwp
);
1448 pmsg
->lParam
= cwp
.lParam
;
1449 pmsg
->wParam
= cwp
.wParam
;
1450 pmsg
->message
= cwp
.message
;
1451 pmsg
->hwnd
= cwp
.hwnd
;
1454 /**********************************************************************
1455 * PostThreadMessage32A (USER32.422)
1459 * Thread-local message queues are not supported.
1462 BOOL WINAPI
PostThreadMessageA(DWORD idThread
, UINT message
,
1463 WPARAM wParam
, LPARAM lParam
)
1468 if ((hQueue
= GetThreadQueue16(idThread
)) == 0)
1472 msg
.message
= message
;
1473 msg
.wParam
= wParam
;
1474 msg
.lParam
= lParam
;
1475 msg
.time
= GetTickCount();
1479 return QUEUE_AddMsg( hQueue
, &msg
, 0 );
1482 /**********************************************************************
1483 * PostThreadMessage32W (USER32.423)
1487 * Thread-local message queues are not supported.
1490 BOOL WINAPI
PostThreadMessageW(DWORD idThread
, UINT message
,
1491 WPARAM wParam
, LPARAM lParam
)
1493 FIXME(sendmsg
, "(...): Should do unicode/ascii conversion!\n");
1494 return PostThreadMessageA(idThread
, message
, wParam
, lParam
);
1497 /***********************************************************************
1498 * SendMessage32A (USER32.454)
1500 LRESULT WINAPI
SendMessageA( HWND hwnd
, UINT msg
, WPARAM wParam
,
1504 WND
**list
, **ppWnd
;
1507 if (hwnd
== HWND_BROADCAST
|| hwnd
== HWND_TOPMOST
)
1509 if (!(list
= WIN_BuildWinArray( WIN_GetDesktop(), 0, NULL
)))
1511 for (ppWnd
= list
; *ppWnd
; ppWnd
++)
1514 if (!IsWindow(wndPtr
->hwndSelf
)) continue;
1515 if (wndPtr
->dwStyle
& WS_POPUP
|| wndPtr
->dwStyle
& WS_CAPTION
)
1516 SendMessageA( wndPtr
->hwndSelf
, msg
, wParam
, lParam
);
1518 HeapFree( SystemHeap
, 0, list
);
1522 if (HOOK_IsHooked( WH_CALLWNDPROC
))
1523 MSG_CallWndProcHook( (LPMSG
)&hwnd
, FALSE
);
1525 if (!(wndPtr
= WIN_FindWndPtr( hwnd
)))
1527 WARN(msg
, "invalid hwnd %08x\n", hwnd
);
1531 if (QUEUE_IsExitingQueue(wndPtr
->hmemTaskQ
))
1532 return 0; /* Don't send anything if the task is dying */
1534 SPY_EnterMessage( SPY_SENDMESSAGE
, hwnd
, msg
, wParam
, lParam
);
1536 if (wndPtr
->hmemTaskQ
!= GetFastQueue16())
1537 ret
= MSG_SendMessage( wndPtr
->hmemTaskQ
, hwnd
, msg
, wParam
, lParam
,
1540 ret
= CallWindowProcA( (WNDPROC
)wndPtr
->winproc
,
1541 hwnd
, msg
, wParam
, lParam
);
1543 SPY_ExitMessage( SPY_RESULT_OK
, hwnd
, msg
, ret
);
1548 /***********************************************************************
1549 * SendMessage32W (USER32.459) Send Window Message
1551 * Sends a message to the window procedure of the specified window.
1552 * SendMessage() will not return until the called window procedure
1553 * either returns or calls ReplyMessage().
1555 * Use PostMessage() to send message and return immediately. A window
1556 * procedure may use InSendMessage() to detect
1557 * SendMessage()-originated messages.
1559 * Applications which communicate via HWND_BROADCAST may use
1560 * RegisterWindowMessage() to obtain a unique message to avoid conflicts
1561 * with other applications.
1567 LRESULT WINAPI
SendMessageW(
1568 HWND hwnd
, /* Window to send message to. If HWND_BROADCAST,
1569 the message will be sent to all top-level windows. */
1571 UINT msg
, /* message */
1572 WPARAM wParam
, /* message parameter */
1573 LPARAM lParam
/* additional message parameter */
1576 WND
**list
, **ppWnd
;
1579 if (hwnd
== HWND_BROADCAST
|| hwnd
== HWND_TOPMOST
)
1581 if (!(list
= WIN_BuildWinArray( WIN_GetDesktop(), 0, NULL
)))
1583 for (ppWnd
= list
; *ppWnd
; ppWnd
++)
1586 if (!IsWindow(wndPtr
->hwndSelf
)) continue;
1587 if (wndPtr
->dwStyle
& WS_POPUP
|| wndPtr
->dwStyle
& WS_CAPTION
)
1588 SendMessageW( wndPtr
->hwndSelf
, msg
, wParam
, lParam
);
1590 HeapFree( SystemHeap
, 0, list
);
1594 if (HOOK_IsHooked( WH_CALLWNDPROC
))
1595 MSG_CallWndProcHook( (LPMSG
)&hwnd
, TRUE
);
1597 if (!(wndPtr
= WIN_FindWndPtr( hwnd
)))
1599 WARN(msg
, "invalid hwnd %08x\n", hwnd
);
1602 if (QUEUE_IsExitingQueue(wndPtr
->hmemTaskQ
))
1603 return 0; /* Don't send anything if the task is dying */
1605 SPY_EnterMessage( SPY_SENDMESSAGE
, hwnd
, msg
, wParam
, lParam
);
1607 if (wndPtr
->hmemTaskQ
!= GetFastQueue16())
1608 ret
= MSG_SendMessage( wndPtr
->hmemTaskQ
, hwnd
, msg
, wParam
, lParam
,
1609 SMSG_WIN32
| SMSG_UNICODE
);
1611 ret
= CallWindowProcW( (WNDPROC
)wndPtr
->winproc
,
1612 hwnd
, msg
, wParam
, lParam
);
1614 SPY_ExitMessage( SPY_RESULT_OK
, hwnd
, msg
, ret
);
1619 /***********************************************************************
1620 * SendMessageTimeout16 (not a WINAPI)
1622 LRESULT WINAPI
SendMessageTimeout16( HWND16 hwnd
, UINT16 msg
, WPARAM16 wParam
,
1623 LPARAM lParam
, UINT16 flags
,
1624 UINT16 timeout
, LPWORD resultp
)
1626 FIXME(sendmsg
, "(...): semistub\n");
1627 return SendMessage16 (hwnd
, msg
, wParam
, lParam
);
1631 /***********************************************************************
1632 * SendMessageTimeout32A (USER32.457)
1634 LRESULT WINAPI
SendMessageTimeoutA( HWND hwnd
, UINT msg
, WPARAM wParam
,
1635 LPARAM lParam
, UINT flags
,
1636 UINT timeout
, LPDWORD resultp
)
1638 FIXME(sendmsg
, "(...): semistub\n");
1639 return SendMessageA (hwnd
, msg
, wParam
, lParam
);
1643 /***********************************************************************
1644 * SendMessageTimeout32W (USER32.458)
1646 LRESULT WINAPI
SendMessageTimeoutW( HWND hwnd
, UINT msg
, WPARAM wParam
,
1647 LPARAM lParam
, UINT flags
,
1648 UINT timeout
, LPDWORD resultp
)
1650 FIXME(sendmsg
, "(...): semistub\n");
1651 return SendMessageW (hwnd
, msg
, wParam
, lParam
);
1655 /***********************************************************************
1656 * WaitMessage (USER.112) (USER32.578) Suspend thread pending messages
1658 * WaitMessage() suspends a thread until events appear in the thread's
1663 * Is supposed to return BOOL under Win32.
1665 * Thread-local message queues are not supported.
1672 void WINAPI
WaitMessage( void )
1674 QUEUE_WaitBits( QS_ALLINPUT
);
1677 /***********************************************************************
1678 * MsgWaitForMultipleObjects (USER32.400)
1680 DWORD WINAPI
MsgWaitForMultipleObjects( DWORD nCount
, HANDLE
*pHandles
,
1681 BOOL fWaitAll
, DWORD dwMilliseconds
,
1685 HANDLE handles
[MAXIMUM_WAIT_OBJECTS
];
1688 HQUEUE16 hQueue
= GetFastQueue16();
1689 MESSAGEQUEUE
*msgQueue
= (MESSAGEQUEUE
*)QUEUE_Lock( hQueue
);
1690 if (!msgQueue
) return WAIT_FAILED
;
1692 if (nCount
> MAXIMUM_WAIT_OBJECTS
-1)
1694 SetLastError( ERROR_INVALID_PARAMETER
);
1695 QUEUE_Unlock( msgQueue
);
1699 msgQueue
->changeBits
= 0;
1700 msgQueue
->wakeMask
= dwWakeMask
;
1702 if (THREAD_IsWin16(THREAD_Current()))
1705 * This is a temporary solution to a big problem.
1706 * You see, the main thread of all Win32 programs is created as a 16 bit
1707 * task. This means that if you want on an event using Win32 synchronization
1708 * methods, the 16 bit scheduler is stopped and things might just stop happening.
1709 * This implements a semi-busy loop that checks the handles to wait on and
1710 * also the message queue. When either one is ready, the wait function returns.
1712 * This will all go away when the real Win32 threads are implemented for all
1713 * the threads of an applications. Including the main thread.
1715 DWORD curTime
= GetCurrentTime();
1720 * Check the handles in the list.
1722 ret
= WaitForMultipleObjects(nCount
, pHandles
, fWaitAll
, 5L);
1725 * If the handles have been triggered, return.
1727 if (ret
!= WAIT_TIMEOUT
)
1731 * Then, let the 16 bit scheduler do it's thing.
1736 * If a message matching the wait mask has arrived, return.
1738 if (msgQueue
->changeBits
& dwWakeMask
)
1745 * And continue doing this until we hit the timeout.
1747 } while ((dwMilliseconds
== INFINITE
) || (GetCurrentTime()-curTime
< dwMilliseconds
) );
1751 /* Add the thread event to the handle list */
1752 for (i
= 0; i
< nCount
; i
++)
1753 handles
[i
] = pHandles
[i
];
1754 handles
[nCount
] = msgQueue
->hEvent
;
1756 ret
= WaitForMultipleObjects( nCount
+1, handles
, fWaitAll
, dwMilliseconds
);
1759 QUEUE_Unlock( msgQueue
);
1773 static const struct accent_char accent_chars
[] =
1775 /* A good idea should be to read /usr/X11/lib/X11/locale/iso8859-x/Compose */
1776 {'`', 'A', '\300'}, {'`', 'a', '\340'},
1777 {'\'', 'A', '\301'}, {'\'', 'a', '\341'},
1778 {'^', 'A', '\302'}, {'^', 'a', '\342'},
1779 {'~', 'A', '\303'}, {'~', 'a', '\343'},
1780 {'"', 'A', '\304'}, {'"', 'a', '\344'},
1781 {'O', 'A', '\305'}, {'o', 'a', '\345'},
1782 {'0', 'A', '\305'}, {'0', 'a', '\345'},
1783 {'A', 'A', '\305'}, {'a', 'a', '\345'},
1784 {'A', 'E', '\306'}, {'a', 'e', '\346'},
1785 {',', 'C', '\307'}, {',', 'c', '\347'},
1786 {'`', 'E', '\310'}, {'`', 'e', '\350'},
1787 {'\'', 'E', '\311'}, {'\'', 'e', '\351'},
1788 {'^', 'E', '\312'}, {'^', 'e', '\352'},
1789 {'"', 'E', '\313'}, {'"', 'e', '\353'},
1790 {'`', 'I', '\314'}, {'`', 'i', '\354'},
1791 {'\'', 'I', '\315'}, {'\'', 'i', '\355'},
1792 {'^', 'I', '\316'}, {'^', 'i', '\356'},
1793 {'"', 'I', '\317'}, {'"', 'i', '\357'},
1794 {'-', 'D', '\320'}, {'-', 'd', '\360'},
1795 {'~', 'N', '\321'}, {'~', 'n', '\361'},
1796 {'`', 'O', '\322'}, {'`', 'o', '\362'},
1797 {'\'', 'O', '\323'}, {'\'', 'o', '\363'},
1798 {'^', 'O', '\324'}, {'^', 'o', '\364'},
1799 {'~', 'O', '\325'}, {'~', 'o', '\365'},
1800 {'"', 'O', '\326'}, {'"', 'o', '\366'},
1801 {'/', 'O', '\330'}, {'/', 'o', '\370'},
1802 {'`', 'U', '\331'}, {'`', 'u', '\371'},
1803 {'\'', 'U', '\332'}, {'\'', 'u', '\372'},
1804 {'^', 'U', '\333'}, {'^', 'u', '\373'},
1805 {'"', 'U', '\334'}, {'"', 'u', '\374'},
1806 {'\'', 'Y', '\335'}, {'\'', 'y', '\375'},
1807 {'T', 'H', '\336'}, {'t', 'h', '\376'},
1808 {'s', 's', '\337'}, {'"', 'y', '\377'},
1809 {'s', 'z', '\337'}, {'i', 'j', '\377'},
1810 /* iso-8859-2 uses this */
1811 {'<', 'L', '\245'}, {'<', 'l', '\265'}, /* caron */
1812 {'<', 'S', '\251'}, {'<', 's', '\271'},
1813 {'<', 'T', '\253'}, {'<', 't', '\273'},
1814 {'<', 'Z', '\256'}, {'<', 'z', '\276'},
1815 {'<', 'C', '\310'}, {'<', 'c', '\350'},
1816 {'<', 'E', '\314'}, {'<', 'e', '\354'},
1817 {'<', 'D', '\317'}, {'<', 'd', '\357'},
1818 {'<', 'N', '\322'}, {'<', 'n', '\362'},
1819 {'<', 'R', '\330'}, {'<', 'r', '\370'},
1820 {';', 'A', '\241'}, {';', 'a', '\261'}, /* ogonek */
1821 {';', 'E', '\312'}, {';', 'e', '\332'},
1822 {'\'', 'Z', '\254'}, {'\'', 'z', '\274'}, /* acute */
1823 {'\'', 'R', '\300'}, {'\'', 'r', '\340'},
1824 {'\'', 'L', '\305'}, {'\'', 'l', '\345'},
1825 {'\'', 'C', '\306'}, {'\'', 'c', '\346'},
1826 {'\'', 'N', '\321'}, {'\'', 'n', '\361'},
1827 /* collision whith S, from iso-8859-9 !!! */
1828 {',', 'S', '\252'}, {',', 's', '\272'}, /* cedilla */
1829 {',', 'T', '\336'}, {',', 't', '\376'},
1830 {'.', 'Z', '\257'}, {'.', 'z', '\277'}, /* dot above */
1831 {'/', 'L', '\243'}, {'/', 'l', '\263'}, /* slash */
1832 {'/', 'D', '\320'}, {'/', 'd', '\360'},
1833 {'(', 'A', '\303'}, {'(', 'a', '\343'}, /* breve */
1834 {'\275', 'O', '\325'}, {'\275', 'o', '\365'}, /* double acute */
1835 {'\275', 'U', '\334'}, {'\275', 'u', '\374'},
1836 {'0', 'U', '\332'}, {'0', 'u', '\372'}, /* ring above */
1837 /* iso-8859-3 uses this */
1838 {'/', 'H', '\241'}, {'/', 'h', '\261'}, /* slash */
1839 {'>', 'H', '\246'}, {'>', 'h', '\266'}, /* circumflex */
1840 {'>', 'J', '\254'}, {'>', 'j', '\274'},
1841 {'>', 'C', '\306'}, {'>', 'c', '\346'},
1842 {'>', 'G', '\330'}, {'>', 'g', '\370'},
1843 {'>', 'S', '\336'}, {'>', 's', '\376'},
1844 /* collision whith G( from iso-8859-9 !!! */
1845 {'(', 'G', '\253'}, {'(', 'g', '\273'}, /* breve */
1846 {'(', 'U', '\335'}, {'(', 'u', '\375'},
1847 /* collision whith I. from iso-8859-3 !!! */
1848 {'.', 'I', '\251'}, {'.', 'i', '\271'}, /* dot above */
1849 {'.', 'C', '\305'}, {'.', 'c', '\345'},
1850 {'.', 'G', '\325'}, {'.', 'g', '\365'},
1851 /* iso-8859-4 uses this */
1852 {',', 'R', '\243'}, {',', 'r', '\263'}, /* cedilla */
1853 {',', 'L', '\246'}, {',', 'l', '\266'},
1854 {',', 'G', '\253'}, {',', 'g', '\273'},
1855 {',', 'N', '\321'}, {',', 'n', '\361'},
1856 {',', 'K', '\323'}, {',', 'k', '\363'},
1857 {'~', 'I', '\245'}, {'~', 'i', '\265'}, /* tilde */
1858 {'-', 'E', '\252'}, {'-', 'e', '\272'}, /* macron */
1859 {'-', 'A', '\300'}, {'-', 'a', '\340'},
1860 {'-', 'I', '\317'}, {'-', 'i', '\357'},
1861 {'-', 'O', '\322'}, {'-', 'o', '\362'},
1862 {'-', 'U', '\336'}, {'-', 'u', '\376'},
1863 {'/', 'T', '\254'}, {'/', 't', '\274'}, /* slash */
1864 {'.', 'E', '\314'}, {'.', 'e', '\344'}, /* dot above */
1865 {';', 'I', '\307'}, {';', 'i', '\347'}, /* ogonek */
1866 {';', 'U', '\331'}, {';', 'u', '\371'},
1867 /* iso-8859-9 uses this */
1868 /* iso-8859-9 has really bad choosen G( S, and I. as they collide
1869 * whith the same letters on other iso-8859-x (that is they are on
1870 * different places :-( ), if you use turkish uncomment these and
1871 * comment out the lines in iso-8859-2 and iso-8859-3 sections
1872 * FIXME: should be dynamic according to chosen language
1873 * if/when Wine has turkish support.
1875 /* collision whith G( from iso-8859-3 !!! */
1876 /* {'(', 'G', '\320'}, {'(', 'g', '\360'}, */ /* breve */
1877 /* collision whith S, from iso-8859-2 !!! */
1878 /* {',', 'S', '\336'}, {',', 's', '\376'}, */ /* cedilla */
1879 /* collision whith I. from iso-8859-3 !!! */
1880 /* {'.', 'I', '\335'}, {'.', 'i', '\375'}, */ /* dot above */
1884 /***********************************************************************
1885 * MSG_DoTranslateMessage
1887 * Implementation of TranslateMessage.
1889 * TranslateMessage translates virtual-key messages into character-messages,
1891 * WM_KEYDOWN/WM_KEYUP combinations produce a WM_CHAR or WM_DEADCHAR message.
1892 * ditto replacing WM_* with WM_SYS*
1893 * This produces WM_CHAR messages only for keys mapped to ASCII characters
1894 * by the keyboard driver.
1896 static BOOL
MSG_DoTranslateMessage( UINT message
, HWND hwnd
,
1897 WPARAM wParam
, LPARAM lParam
)
1899 static int dead_char
;
1902 if (message
!= WM_MOUSEMOVE
&& message
!= WM_TIMER
)
1903 TRACE(msg
, "(%s, %04X, %08lX)\n",
1904 SPY_GetMsgName(message
), wParam
, lParam
);
1905 if(message
>= WM_KEYFIRST
&& message
<= WM_KEYLAST
)
1906 TRACE(key
, "(%s, %04X, %08lX)\n",
1907 SPY_GetMsgName(message
), wParam
, lParam
);
1909 if ((message
!= WM_KEYDOWN
) && (message
!= WM_SYSKEYDOWN
)) return FALSE
;
1911 TRACE(key
, "Translating key %04X, scancode %04X\n",
1912 wParam
, HIWORD(lParam
) );
1914 /* FIXME : should handle ToAscii yielding 2 */
1915 switch (ToAscii(wParam
, HIWORD(lParam
),
1916 QueueKeyStateTable
,(LPWORD
)wp
, 0))
1919 message
= (message
== WM_KEYDOWN
) ? WM_CHAR
: WM_SYSCHAR
;
1920 /* Should dead chars handling go in ToAscii ? */
1925 if (wp
[0] == ' ') wp
[0] = dead_char
;
1926 if (dead_char
== 0xa2) dead_char
= '(';
1927 else if (dead_char
== 0xa8) dead_char
= '"';
1928 else if (dead_char
== 0xb2) dead_char
= ';';
1929 else if (dead_char
== 0xb4) dead_char
= '\'';
1930 else if (dead_char
== 0xb7) dead_char
= '<';
1931 else if (dead_char
== 0xb8) dead_char
= ',';
1932 else if (dead_char
== 0xff) dead_char
= '.';
1933 for (i
= 0; i
< sizeof(accent_chars
)/sizeof(accent_chars
[0]); i
++)
1934 if ((accent_chars
[i
].ac_accent
== dead_char
) &&
1935 (accent_chars
[i
].ac_char
== wp
[0]))
1937 wp
[0] = accent_chars
[i
].ac_result
;
1942 TRACE(key
, "1 -> PostMessage(%s)\n", SPY_GetMsgName(message
));
1943 PostMessage16( hwnd
, message
, wp
[0], lParam
);
1947 message
= (message
== WM_KEYDOWN
) ? WM_DEADCHAR
: WM_SYSDEADCHAR
;
1949 TRACE(key
, "-1 -> PostMessage(%s)\n",
1950 SPY_GetMsgName(message
));
1951 PostMessage16( hwnd
, message
, wp
[0], lParam
);
1958 /***********************************************************************
1959 * TranslateMessage16 (USER.113)
1961 BOOL16 WINAPI
TranslateMessage16( const MSG16
*msg
)
1963 return MSG_DoTranslateMessage( msg
->message
, msg
->hwnd
,
1964 msg
->wParam
, msg
->lParam
);
1968 /***********************************************************************
1969 * WIN16_TranslateMessage32 (USER.821)
1971 BOOL16 WINAPI
TranslateMessage32_16( const MSG32_16
*msg
, BOOL16 wHaveParamHigh
)
1976 wParam
= MAKELONG(msg
->msg
.wParam
, msg
->wParamHigh
);
1978 wParam
= (WPARAM
)msg
->msg
.wParam
;
1980 return MSG_DoTranslateMessage( msg
->msg
.message
, msg
->msg
.hwnd
,
1981 wParam
, msg
->msg
.lParam
);
1984 /***********************************************************************
1985 * TranslateMessage32 (USER32.556)
1987 BOOL WINAPI
TranslateMessage( const MSG
*msg
)
1989 return MSG_DoTranslateMessage( msg
->message
, msg
->hwnd
,
1990 msg
->wParam
, msg
->lParam
);
1994 /***********************************************************************
1995 * DispatchMessage16 (USER.114)
1997 LONG WINAPI
DispatchMessage16( const MSG16
* msg
)
2003 /* Process timer messages */
2004 if ((msg
->message
== WM_TIMER
) || (msg
->message
== WM_SYSTIMER
))
2008 return CallWindowProc16( (WNDPROC16
)msg
->lParam
, msg
->hwnd
,
2009 msg
->message
, msg
->wParam
, GetTickCount() );
2013 if (!msg
->hwnd
) return 0;
2014 if (!(wndPtr
= WIN_FindWndPtr( msg
->hwnd
))) return 0;
2015 if (!wndPtr
->winproc
) return 0;
2016 painting
= (msg
->message
== WM_PAINT
);
2017 if (painting
) wndPtr
->flags
|= WIN_NEEDS_BEGINPAINT
;
2019 SPY_EnterMessage( SPY_DISPATCHMESSAGE16
, msg
->hwnd
, msg
->message
,
2020 msg
->wParam
, msg
->lParam
);
2021 retval
= CallWindowProc16( (WNDPROC16
)wndPtr
->winproc
,
2022 msg
->hwnd
, msg
->message
,
2023 msg
->wParam
, msg
->lParam
);
2024 SPY_ExitMessage( SPY_RESULT_OK16
, msg
->hwnd
, msg
->message
, retval
);
2026 if (painting
&& (wndPtr
= WIN_FindWndPtr( msg
->hwnd
)) &&
2027 (wndPtr
->flags
& WIN_NEEDS_BEGINPAINT
) && wndPtr
->hrgnUpdate
)
2029 ERR(msg
, "BeginPaint not called on WM_PAINT for hwnd %04x!\n",
2031 wndPtr
->flags
&= ~WIN_NEEDS_BEGINPAINT
;
2032 /* Validate the update region to avoid infinite WM_PAINT loop */
2033 ValidateRect( msg
->hwnd
, NULL
);
2039 /***********************************************************************
2040 * WIN16_DispatchMessage32 (USER.822)
2042 LONG WINAPI
DispatchMessage32_16( const MSG32_16
* lpmsg16_32
, BOOL16 wHaveParamHigh
)
2044 if (wHaveParamHigh
== FALSE
)
2045 return DispatchMessage16(&(lpmsg16_32
->msg
));
2050 msg
.hwnd
= lpmsg16_32
->msg
.hwnd
;
2051 msg
.message
= lpmsg16_32
->msg
.message
;
2052 msg
.wParam
= MAKELONG(lpmsg16_32
->msg
.wParam
, lpmsg16_32
->wParamHigh
);
2053 msg
.lParam
= lpmsg16_32
->msg
.lParam
;
2054 msg
.time
= lpmsg16_32
->msg
.time
;
2055 msg
.pt
.x
= (INT
)lpmsg16_32
->msg
.pt
.x
;
2056 msg
.pt
.y
= (INT
)lpmsg16_32
->msg
.pt
.y
;
2057 return DispatchMessageA(&msg
);
2061 /***********************************************************************
2062 * DispatchMessage32A (USER32.141)
2064 LONG WINAPI
DispatchMessageA( const MSG
* msg
)
2070 /* Process timer messages */
2071 if ((msg
->message
== WM_TIMER
) || (msg
->message
== WM_SYSTIMER
))
2075 /* HOOK_CallHooks32A( WH_CALLWNDPROC, HC_ACTION, 0, FIXME ); */
2076 return CallWindowProcA( (WNDPROC
)msg
->lParam
, msg
->hwnd
,
2077 msg
->message
, msg
->wParam
, GetTickCount() );
2081 if (!msg
->hwnd
) return 0;
2082 if (!(wndPtr
= WIN_FindWndPtr( msg
->hwnd
))) return 0;
2083 if (!wndPtr
->winproc
) return 0;
2084 painting
= (msg
->message
== WM_PAINT
);
2085 if (painting
) wndPtr
->flags
|= WIN_NEEDS_BEGINPAINT
;
2086 /* HOOK_CallHooks32A( WH_CALLWNDPROC, HC_ACTION, 0, FIXME ); */
2088 SPY_EnterMessage( SPY_DISPATCHMESSAGE
, msg
->hwnd
, msg
->message
,
2089 msg
->wParam
, msg
->lParam
);
2090 retval
= CallWindowProcA( (WNDPROC
)wndPtr
->winproc
,
2091 msg
->hwnd
, msg
->message
,
2092 msg
->wParam
, msg
->lParam
);
2093 SPY_ExitMessage( SPY_RESULT_OK
, msg
->hwnd
, msg
->message
, retval
);
2095 if (painting
&& (wndPtr
= WIN_FindWndPtr( msg
->hwnd
)) &&
2096 (wndPtr
->flags
& WIN_NEEDS_BEGINPAINT
) && wndPtr
->hrgnUpdate
)
2098 ERR(msg
, "BeginPaint not called on WM_PAINT for hwnd %04x!\n",
2100 wndPtr
->flags
&= ~WIN_NEEDS_BEGINPAINT
;
2101 /* Validate the update region to avoid infinite WM_PAINT loop */
2102 ValidateRect( msg
->hwnd
, NULL
);
2108 /***********************************************************************
2109 * DispatchMessage32W (USER32.142) Process Message
2111 * Process the message specified in the structure *_msg_.
2113 * If the lpMsg parameter points to a WM_TIMER message and the
2114 * parameter of the WM_TIMER message is not NULL, the lParam parameter
2115 * points to the function that is called instead of the window
2118 * The message must be valid.
2122 * DispatchMessage() returns the result of the window procedure invoked.
2129 LONG WINAPI
DispatchMessageW( const MSG
* msg
)
2135 /* Process timer messages */
2136 if ((msg
->message
== WM_TIMER
) || (msg
->message
== WM_SYSTIMER
))
2140 /* HOOK_CallHooks32W( WH_CALLWNDPROC, HC_ACTION, 0, FIXME ); */
2141 return CallWindowProcW( (WNDPROC
)msg
->lParam
, msg
->hwnd
,
2142 msg
->message
, msg
->wParam
, GetTickCount() );
2146 if (!msg
->hwnd
) return 0;
2147 if (!(wndPtr
= WIN_FindWndPtr( msg
->hwnd
))) return 0;
2148 if (!wndPtr
->winproc
) return 0;
2149 painting
= (msg
->message
== WM_PAINT
);
2150 if (painting
) wndPtr
->flags
|= WIN_NEEDS_BEGINPAINT
;
2151 /* HOOK_CallHooks32W( WH_CALLWNDPROC, HC_ACTION, 0, FIXME ); */
2153 SPY_EnterMessage( SPY_DISPATCHMESSAGE
, msg
->hwnd
, msg
->message
,
2154 msg
->wParam
, msg
->lParam
);
2155 retval
= CallWindowProcW( (WNDPROC
)wndPtr
->winproc
,
2156 msg
->hwnd
, msg
->message
,
2157 msg
->wParam
, msg
->lParam
);
2158 SPY_ExitMessage( SPY_RESULT_OK
, msg
->hwnd
, msg
->message
, retval
);
2160 if (painting
&& (wndPtr
= WIN_FindWndPtr( msg
->hwnd
)) &&
2161 (wndPtr
->flags
& WIN_NEEDS_BEGINPAINT
) && wndPtr
->hrgnUpdate
)
2163 ERR(msg
, "BeginPaint not called on WM_PAINT for hwnd %04x!\n",
2165 wndPtr
->flags
&= ~WIN_NEEDS_BEGINPAINT
;
2166 /* Validate the update region to avoid infinite WM_PAINT loop */
2167 ValidateRect( msg
->hwnd
, NULL
);
2173 /***********************************************************************
2174 * RegisterWindowMessage16 (USER.118)
2176 WORD WINAPI
RegisterWindowMessage16( SEGPTR str
)
2178 TRACE(msg
, "%08lx\n", (DWORD
)str
);
2179 return GlobalAddAtom16( str
);
2183 /***********************************************************************
2184 * RegisterWindowMessage32A (USER32.437)
2186 WORD WINAPI
RegisterWindowMessageA( LPCSTR str
)
2188 TRACE(msg
, "%s\n", str
);
2189 return GlobalAddAtomA( str
);
2193 /***********************************************************************
2194 * RegisterWindowMessage32W (USER32.438)
2196 WORD WINAPI
RegisterWindowMessageW( LPCWSTR str
)
2198 TRACE(msg
, "%p\n", str
);
2199 return GlobalAddAtomW( str
);
2203 /***********************************************************************
2204 * GetTickCount (USER.13) (KERNEL32.299) System Time
2205 * Returns the number of milliseconds, modulo 2^32, since the start
2206 * of the current session.
2212 DWORD WINAPI
GetTickCount(void)
2215 gettimeofday( &t
, NULL
);
2216 /* make extremely compatible: granularity is 25 msec */
2217 return ((t
.tv_sec
* 1000) + (t
.tv_usec
/ 25000) * 25) - MSG_WineStartTicks
;
2221 /***********************************************************************
2222 * GetCurrentTime16 (USER.15)
2224 * (effectively identical to GetTickCount)
2226 DWORD WINAPI
GetCurrentTime16(void)
2228 return GetTickCount();
2232 /***********************************************************************
2233 * InSendMessage16 (USER.192)
2235 BOOL16 WINAPI
InSendMessage16(void)
2237 return InSendMessage();
2241 /***********************************************************************
2242 * InSendMessage32 (USER32.320)
2244 BOOL WINAPI
InSendMessage(void)
2246 MESSAGEQUEUE
*queue
;
2249 if (!(queue
= (MESSAGEQUEUE
*)QUEUE_Lock( GetFastQueue16() )))
2251 ret
= (BOOL
)queue
->smWaiting
;
2253 QUEUE_Unlock( queue
);
2257 /***********************************************************************
2258 * BroadcastSystemMessage (USER32.12)
2260 LONG WINAPI
BroadcastSystemMessage(
2261 DWORD dwFlags
,LPDWORD recipients
,UINT uMessage
,WPARAM wParam
,
2264 FIXME(sendmsg
,"(%08lx,%08lx,%08x,%08x,%08lx): stub!\n",
2265 dwFlags
,*recipients
,uMessage
,wParam
,lParam
2270 /***********************************************************************
2271 * SendNotifyMessageA (USER32.460)
2273 * The message sended with PostMessage has to be put in the queue
2274 * with a higher priority as the other "Posted" messages.
2275 * QUEUE_AddMsg has to be modifyed.
2277 BOOL WINAPI
SendNotifyMessageA(HWND hwnd
,UINT msg
,WPARAM wParam
,LPARAM lParam
)
2279 FIXME(msg
,"(%04x,%08x,%08x,%08lx) not complete\n",
2280 hwnd
, msg
, wParam
, lParam
);
2282 if ( GetCurrentThreadId() == GetWindowThreadProcessId ( hwnd
, NULL
))
2283 { ret
=SendMessageA ( hwnd
, msg
, wParam
, lParam
);
2286 { PostMessageA ( hwnd
, msg
, wParam
, lParam
);
2291 /***********************************************************************
2292 * SendNotifyMessageW (USER32.461)
2294 * The message sended with PostMessage has to be put in the queue
2295 * with a higher priority as the other "Posted" messages.
2296 * QUEUE_AddMsg has to be modifyed.
2298 BOOL WINAPI
SendNotifyMessageW(HWND hwnd
,UINT msg
,WPARAM wParam
,LPARAM lParam
)
2300 FIXME(msg
,"(%04x,%08x,%08x,%08lx) not complete\n",
2301 hwnd
, msg
, wParam
, lParam
);
2303 if ( GetCurrentThreadId() == GetWindowThreadProcessId ( hwnd
, NULL
))
2304 { ret
=SendMessageW ( hwnd
, msg
, wParam
, lParam
);
2307 { PostMessageW ( hwnd
, msg
, wParam
, lParam
);
2312 /***********************************************************************
2313 * SendMessageCallBack32A
2314 * FIXME: It's like PostMessage. The callback gets called when the message
2315 * is processed. We have to modify the message processing for a exact
2318 BOOL WINAPI
SendMessageCallBackA(
2319 HWND hWnd
,UINT Msg
,WPARAM wParam
,LPARAM lParam
,
2320 FARPROC lpResultCallBack
,DWORD dwData
)
2322 FIXME(msg
,"(0x%04x,0x%04x,0x%08x,0x%08lx,%p,0x%08lx),stub!\n",
2323 hWnd
,Msg
,wParam
,lParam
,lpResultCallBack
,dwData
);
2324 if ( hWnd
== HWND_BROADCAST
)
2325 { PostMessageA( hWnd
, Msg
, wParam
, lParam
);
2326 FIXME(msg
,"Broadcast: Callback will not be called!\n");
2329 (lpResultCallBack
)( hWnd
, Msg
, dwData
, SendMessageA ( hWnd
, Msg
, wParam
, lParam
));