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
);
689 QUEUE_ClearWakeBit( queue
, QS_SMRESULT
);
691 /* remove the smsg from the processingg list of the source queue */
692 QUEUE_RemoveSMSG( queue
, SM_PROCESSING_LIST
, smsg
);
694 /* Note: the destination thread is in charge of removing the smsg from
697 /* sender thread is in charge of releasing smsg if it's not an
699 if ( !(smsg
->flags
& SMSG_EARLY_REPLY
) )
701 HeapFree(SystemHeap
, 0, smsg
);
705 /* In the case of an early reply, sender thread will released the
706 smsg structure if the receiver thread is done (SMSG_RECEIVED set).
707 If the receiver thread isn't done, SMSG_RECEIVER_CLEANS_UP flag
708 is set, and it will be the receiver responsability to released
710 EnterCriticalSection( &queue
->cSection
);
712 if (smsg
->flags
& SMSG_RECEIVED
)
713 HeapFree(SystemHeap
, 0, smsg
);
715 smsg
->flags
|= SMSG_RECEIVER_CLEANS
;
717 LeaveCriticalSection( &queue
->cSection
);
720 QUEUE_Unlock( queue
);
721 QUEUE_Unlock( destQ
);
723 TRACE(sendmsg
,"done!\n");
728 /***********************************************************************
729 * ReplyMessage16 (USER.115)
731 void WINAPI
ReplyMessage16( LRESULT result
)
733 ReplyMessage( result
);
736 /***********************************************************************
737 * ReplyMessage (USER.115)
739 BOOL WINAPI
ReplyMessage( LRESULT result
)
741 MESSAGEQUEUE
*senderQ
= 0;
742 MESSAGEQUEUE
*queue
= 0;
746 if (!(queue
= (MESSAGEQUEUE
*)QUEUE_Lock( GetFastQueue16() ))) return FALSE
;
748 TRACE(sendmsg
,"ReplyMessage, queue %04x\n", queue
->self
);
750 while ((smsg
= queue
->smWaiting
) != 0)
752 /* if message has already been reply, continue the loop of receving
754 if ( smsg
->flags
& SMSG_ALREADY_REPLIED
)
755 goto ReplyMessageDone
;
757 senderQ
= (MESSAGEQUEUE
*)QUEUE_Lock( smsg
->hSrcQueue
);
759 goto ReplyMessageDone
;
761 /* if send message pending, processed it */
762 if( queue
->wakeBits
& QS_SENDMESSAGE
)
764 /* Note: QUEUE_ReceiveMessage() and ReplyMessage call each other */
765 QUEUE_ReceiveMessage( queue
);
766 QUEUE_Unlock( senderQ
);
767 continue; /* ReceiveMessage() already called us */
769 break; /* message to reply is in smsg */
773 goto ReplyMessageDone
;
775 smsg
->lResult
= result
;
776 smsg
->flags
|= SMSG_ALREADY_REPLIED
| SMSG_HAVE_RESULT
;
778 /* check if it's an early reply (called by the application) or
779 a regular reply (called by ReceiveMessage) */
780 if ( !(smsg
->flags
& SMSG_SENDING_REPLY
) )
781 smsg
->flags
|= SMSG_EARLY_REPLY
;
783 TRACE( sendmsg
,"\trpm: smResult = %08lx\n", (long) result
);
785 /* remove smsg from the waiting list, if it's not an early reply */
786 /* it is important to leave it in the waiting list if it's an early
787 reply, to be protected aginst multiple call to ReplyMessage() */
788 if ( !(smsg
->flags
& SMSG_EARLY_REPLY
) )
789 QUEUE_RemoveSMSG( queue
, SM_WAITING_LIST
, smsg
);
791 /* tell the sending task that its reply is ready */
792 QUEUE_SetWakeBit( senderQ
, QS_SMRESULT
);
794 /* switch directly to sending task (16 bit thread only) */
795 if (THREAD_IsWin16( THREAD_Current() ))
796 DirectedYield16( senderQ
->thdb
->teb
.htask16
);
802 QUEUE_Unlock( senderQ
);
804 QUEUE_Unlock( queue
);
809 /***********************************************************************
812 static BOOL
MSG_PeekMessage( LPMSG msg
, HWND hwnd
, DWORD first
, DWORD last
,
813 WORD flags
, BOOL peek
)
816 MESSAGEQUEUE
*msgQueue
;
821 DDE_TestDDE(hwnd
); /* do we have dde handling in the window ?*/
822 DDE_GetRemoteMessage();
823 #endif /* CONFIG_IPC */
825 mask
= QS_POSTMESSAGE
| QS_SENDMESSAGE
; /* Always selected */
828 if ((first
<= WM_KEYLAST
) && (last
>= WM_KEYFIRST
)) mask
|= QS_KEY
;
829 if ( ((first
<= WM_MOUSELAST
) && (last
>= WM_MOUSEFIRST
)) ||
830 ((first
<= WM_NCMOUSELAST
) && (last
>= WM_NCMOUSEFIRST
)) ) mask
|= QS_MOUSE
;
831 if ((first
<= WM_TIMER
) && (last
>= WM_TIMER
)) mask
|= QS_TIMER
;
832 if ((first
<= WM_SYSTIMER
) && (last
>= WM_SYSTIMER
)) mask
|= QS_TIMER
;
833 if ((first
<= WM_PAINT
) && (last
>= WM_PAINT
)) mask
|= QS_PAINT
;
835 else mask
|= QS_MOUSE
| QS_KEY
| QS_TIMER
| QS_PAINT
;
837 if (IsTaskLocked16()) flags
|= PM_NOYIELD
;
839 /* Never yield on Win32 threads */
840 if (!THREAD_IsWin16(THREAD_Current())) flags
|= PM_NOYIELD
;
846 hQueue
= GetFastQueue16();
847 msgQueue
= (MESSAGEQUEUE
*)QUEUE_Lock( hQueue
);
848 if (!msgQueue
) return FALSE
;
849 msgQueue
->changeBits
= 0;
851 /* First handle a message put by SendMessage() */
853 while (msgQueue
->wakeBits
& QS_SENDMESSAGE
)
854 QUEUE_ReceiveMessage( msgQueue
);
856 /* Now handle a WM_QUIT message */
858 if (msgQueue
->wPostQMsg
&&
859 (!first
|| WM_QUIT
>= first
) &&
860 (!last
|| WM_QUIT
<= last
) )
863 msg
->message
= WM_QUIT
;
864 msg
->wParam
= msgQueue
->wExitCode
;
866 if (flags
& PM_REMOVE
) msgQueue
->wPostQMsg
= 0;
870 /* Now find a normal message */
872 if (((msgQueue
->wakeBits
& mask
) & QS_POSTMESSAGE
) &&
873 ((qmsg
= QUEUE_FindMsg( msgQueue
, hwnd
, first
, last
)) != 0))
877 msgQueue
->GetMessageTimeVal
= msg
->time
;
878 CONV_POINT32TO16(&msg
->pt
, &pt16
);
879 msgQueue
->GetMessagePosVal
= *(DWORD
*)&pt16
;
880 msgQueue
->GetMessageExtraInfoVal
= qmsg
->extraInfo
;
882 if (flags
& PM_REMOVE
) QUEUE_RemoveMsg( msgQueue
, qmsg
);
886 msgQueue
->changeBits
|= MSG_JournalPlayBackMsg();
888 /* Now find a hardware event */
890 if (((msgQueue
->wakeBits
& mask
) & (QS_MOUSE
| QS_KEY
)) &&
891 MSG_PeekHardwareMsg( msg
, hwnd
, first
, last
, flags
& PM_REMOVE
))
894 msgQueue
->GetMessageTimeVal
= msg
->time
;
895 CONV_POINT32TO16(&msg
->pt
, &pt16
);
896 msgQueue
->GetMessagePosVal
= *(DWORD
*)&pt16
;
897 msgQueue
->GetMessageExtraInfoVal
= 0; /* Always 0 for now */
901 /* Check again for SendMessage */
903 while (msgQueue
->wakeBits
& QS_SENDMESSAGE
)
904 QUEUE_ReceiveMessage( msgQueue
);
906 /* Now find a WM_PAINT message */
908 if ((msgQueue
->wakeBits
& mask
) & QS_PAINT
)
911 msg
->hwnd
= WIN_FindWinToRepaint( hwnd
, hQueue
);
912 msg
->message
= WM_PAINT
;
916 if ((wndPtr
= WIN_FindWndPtr(msg
->hwnd
)))
918 if( wndPtr
->dwStyle
& WS_MINIMIZE
&&
919 wndPtr
->class->hIcon
)
921 msg
->message
= WM_PAINTICON
;
925 if( !hwnd
|| msg
->hwnd
== hwnd
|| IsChild16(hwnd
,msg
->hwnd
) )
927 if( wndPtr
->flags
& WIN_INTERNAL_PAINT
&& !wndPtr
->hrgnUpdate
)
929 wndPtr
->flags
&= ~WIN_INTERNAL_PAINT
;
930 QUEUE_DecPaintCount( hQueue
);
937 /* Check for timer messages, but yield first */
939 if (!(flags
& PM_NOYIELD
))
942 while (msgQueue
->wakeBits
& QS_SENDMESSAGE
)
943 QUEUE_ReceiveMessage( msgQueue
);
945 if ((msgQueue
->wakeBits
& mask
) & QS_TIMER
)
947 if (TIMER_GetTimerMsg(msg
, hwnd
, hQueue
, flags
& PM_REMOVE
)) break;
952 if (!(flags
& PM_NOYIELD
)) UserYield16();
954 QUEUE_Unlock( msgQueue
);
957 msgQueue
->wakeMask
= mask
;
958 QUEUE_WaitBits( mask
);
959 QUEUE_Unlock( msgQueue
);
962 /* instead of unlocking queue for every break condition, all break
963 condition will fall here */
964 QUEUE_Unlock( msgQueue
);
966 /* We got a message */
967 if (flags
& PM_REMOVE
)
969 WORD message
= msg
->message
;
971 if (message
== WM_KEYDOWN
|| message
== WM_SYSKEYDOWN
)
973 BYTE
*p
= &QueueKeyStateTable
[msg
->wParam
& 0xff];
979 else if (message
== WM_KEYUP
|| message
== WM_SYSKEYUP
)
980 QueueKeyStateTable
[msg
->wParam
& 0xff] &= ~0x80;
982 if (peek
) return TRUE
;
983 else return (msg
->message
!= WM_QUIT
);
986 /***********************************************************************
987 * MSG_InternalGetMessage
989 * GetMessage() function for internal use. Behave like GetMessage(),
990 * but also call message filters and optionally send WM_ENTERIDLE messages.
991 * 'hwnd' must be the handle of the dialog or menu window.
992 * 'code' is the message filter value (MSGF_??? codes).
994 BOOL
MSG_InternalGetMessage( MSG
*msg
, HWND hwnd
, HWND hwndOwner
,
995 WPARAM code
, WORD flags
, BOOL sendIdle
)
1001 if (!MSG_PeekMessage( msg
, 0, 0, 0, flags
, TRUE
))
1003 /* No message present -> send ENTERIDLE and wait */
1004 if (IsWindow(hwndOwner
))
1005 SendMessageA( hwndOwner
, WM_ENTERIDLE
,
1006 code
, (LPARAM
)hwnd
);
1007 MSG_PeekMessage( msg
, 0, 0, 0, flags
, FALSE
);
1010 else /* Always wait for a message */
1011 MSG_PeekMessage( msg
, 0, 0, 0, flags
, FALSE
);
1013 /* Call message filters */
1015 if (HOOK_IsHooked( WH_SYSMSGFILTER
) || HOOK_IsHooked( WH_MSGFILTER
))
1017 MSG
*pmsg
= HeapAlloc( SystemHeap
, 0, sizeof(MSG
) );
1022 ret
= (HOOK_CallHooksA( WH_SYSMSGFILTER
, code
, 0,
1024 HOOK_CallHooksA( WH_MSGFILTER
, code
, 0,
1027 HeapFree( SystemHeap
, 0, pmsg
);
1030 /* Message filtered -> remove it from the queue */
1031 /* if it's still there. */
1032 if (!(flags
& PM_REMOVE
))
1033 MSG_PeekMessage( msg
, 0, 0, 0, PM_REMOVE
, TRUE
);
1039 return (msg
->message
!= WM_QUIT
);
1044 /***********************************************************************
1045 * PeekMessage16 (USER.109)
1047 BOOL16 WINAPI
PeekMessage16( LPMSG16 lpmsg
, HWND16 hwnd
, UINT16 first
,
1048 UINT16 last
, UINT16 flags
)
1052 ret
= PeekMessageA(&msg32
, hwnd
, first
, last
, flags
);
1053 STRUCT32_MSG32to16(&msg32
, lpmsg
);
1057 /***********************************************************************
1058 * WIN16_PeekMessage32 (USER.819)
1060 BOOL16 WINAPI
PeekMessage32_16( LPMSG16_32 lpmsg16_32
, HWND16 hwnd
,
1061 UINT16 first
, UINT16 last
, UINT16 flags
, BOOL16 wHaveParamHigh
)
1063 if (wHaveParamHigh
== FALSE
)
1065 lpmsg16_32
->wParamHigh
= 0;
1066 return PeekMessage16(&(lpmsg16_32
->msg
), hwnd
, first
, last
, flags
);
1073 ret
= (BOOL16
)PeekMessageA(&msg32
, (HWND
)hwnd
,
1074 (UINT
)first
, (UINT
)last
, (UINT
)flags
);
1075 lpmsg16_32
->msg
.hwnd
= msg32
.hwnd
;
1076 lpmsg16_32
->msg
.message
= msg32
.message
;
1077 lpmsg16_32
->msg
.wParam
= LOWORD(msg32
.wParam
);
1078 lpmsg16_32
->msg
.lParam
= msg32
.lParam
;
1079 lpmsg16_32
->msg
.time
= msg32
.time
;
1080 lpmsg16_32
->msg
.pt
.x
= (INT16
)msg32
.pt
.x
;
1081 lpmsg16_32
->msg
.pt
.y
= (INT16
)msg32
.pt
.y
;
1082 lpmsg16_32
->wParamHigh
= HIWORD(msg32
.wParam
);
1088 /***********************************************************************
1091 BOOL WINAPI
PeekMessageA( LPMSG lpmsg
, HWND hwnd
,
1092 UINT min
,UINT max
,UINT wRemoveMsg
)
1094 return MSG_PeekMessage( lpmsg
, hwnd
, min
, max
, wRemoveMsg
, TRUE
);
1097 /***********************************************************************
1098 * PeekMessageW Check queue for messages
1100 * Checks for a message in the thread's queue, filtered as for
1101 * GetMessage(). Returns immediately whether a message is available
1104 * Whether a retrieved message is removed from the queue is set by the
1105 * _wRemoveMsg_ flags, which should be one of the following values:
1107 * PM_NOREMOVE Do not remove the message from the queue.
1109 * PM_REMOVE Remove the message from the queue.
1111 * In addition, PM_NOYIELD may be combined into _wRemoveMsg_ to
1112 * request that the system not yield control during PeekMessage();
1113 * however applications may not rely on scheduling behavior.
1117 * Nonzero if a message is available and is retrieved, zero otherwise.
1124 BOOL WINAPI
PeekMessageW(
1125 LPMSG lpmsg
, /* buffer to receive message */
1126 HWND hwnd
, /* restrict to messages for hwnd */
1127 UINT min
, /* minimum message to receive */
1128 UINT max
, /* maximum message to receive */
1129 UINT wRemoveMsg
/* removal flags */
1131 /* FIXME: Should perform Unicode translation on specific messages */
1132 return PeekMessageA(lpmsg
,hwnd
,min
,max
,wRemoveMsg
);
1135 /***********************************************************************
1136 * GetMessage16 (USER.108)
1138 BOOL16 WINAPI
GetMessage16( SEGPTR msg
, HWND16 hwnd
, UINT16 first
, UINT16 last
)
1141 MSG16
*lpmsg
= (MSG16
*)PTR_SEG_TO_LIN(msg
);
1144 ret
= GetMessageA( &msg32
, hwnd
, first
, last
);
1146 STRUCT32_MSG32to16( &msg32
, lpmsg
);
1148 TRACE(msg
,"message %04x, hwnd %04x, filter(%04x - %04x)\n", lpmsg
->message
,
1149 hwnd
, first
, last
);
1154 /***********************************************************************
1155 * WIN16_GetMessage32 (USER.820)
1157 BOOL16 WINAPI
GetMessage32_16( SEGPTR msg16_32
, HWND16 hWnd
, UINT16 first
,
1158 UINT16 last
, BOOL16 wHaveParamHigh
)
1160 MSG32_16
*lpmsg16_32
= (MSG32_16
*)PTR_SEG_TO_LIN(msg16_32
);
1162 if (wHaveParamHigh
== FALSE
) /* normal GetMessage16 call */
1165 lpmsg16_32
->wParamHigh
= 0; /* you never know... */
1166 /* WARNING: msg16_32->msg has to be the first variable in the struct */
1167 return GetMessage16(msg16_32
, hWnd
, first
, last
);
1174 ret
= (BOOL16
)GetMessageA(&msg32
, hWnd
, first
, last
);
1175 lpmsg16_32
->msg
.hwnd
= msg32
.hwnd
;
1176 lpmsg16_32
->msg
.message
= msg32
.message
;
1177 lpmsg16_32
->msg
.wParam
= LOWORD(msg32
.wParam
);
1178 lpmsg16_32
->msg
.lParam
= msg32
.lParam
;
1179 lpmsg16_32
->msg
.time
= msg32
.time
;
1180 lpmsg16_32
->msg
.pt
.x
= (INT16
)msg32
.pt
.x
;
1181 lpmsg16_32
->msg
.pt
.y
= (INT16
)msg32
.pt
.y
;
1182 lpmsg16_32
->wParamHigh
= HIWORD(msg32
.wParam
);
1187 /***********************************************************************
1188 * GetMessage32A (USER32.270)
1190 BOOL WINAPI
GetMessageA(MSG
* lpmsg
,HWND hwnd
,UINT min
,UINT max
)
1192 MSG_PeekMessage( lpmsg
, hwnd
, min
, max
, PM_REMOVE
, FALSE
);
1194 TRACE(msg
,"message %04x, hwnd %04x, filter(%04x - %04x)\n", lpmsg
->message
,
1197 HOOK_CallHooksA( WH_GETMESSAGE
, HC_ACTION
, 0, (LPARAM
)lpmsg
);
1199 return (lpmsg
->message
!= WM_QUIT
);
1202 /***********************************************************************
1203 * GetMessage32W (USER32.274) Retrieve next message
1205 * GetMessage retrieves the next event from the calling thread's
1206 * queue and deposits it in *lpmsg.
1208 * If _hwnd_ is not NULL, only messages for window _hwnd_ and its
1209 * children as specified by IsChild() are retrieved. If _hwnd_ is NULL
1210 * all application messages are retrieved.
1212 * _min_ and _max_ specify the range of messages of interest. If
1213 * min==max==0, no filtering is performed. Useful examples are
1214 * WM_KEYFIRST and WM_KEYLAST to retrieve keyboard input, and
1215 * WM_MOUSEFIRST and WM_MOUSELAST to retrieve mouse input.
1217 * WM_PAINT messages are not removed from the queue; they remain until
1218 * processed. Other messages are removed from the queue.
1222 * -1 on error, 0 if message is WM_QUIT, nonzero otherwise.
1229 BOOL WINAPI
GetMessageW(
1230 MSG
* lpmsg
, /* buffer to receive message */
1231 HWND hwnd
, /* restrict to messages for hwnd */
1232 UINT min
, /* minimum message to receive */
1233 UINT max
/* maximum message to receive */
1236 return GetMessageA(lpmsg
, hwnd
, min
, max
);
1240 /***********************************************************************
1241 * PostMessage16 (USER.110)
1243 BOOL16 WINAPI
PostMessage16( HWND16 hwnd
, UINT16 message
, WPARAM16 wParam
,
1246 return (BOOL16
) PostMessageA( hwnd
, message
, wParam
, lParam
);
1250 /***********************************************************************
1251 * PostMessage32A (USER32.419)
1253 BOOL WINAPI
PostMessageA( HWND hwnd
, UINT message
, WPARAM wParam
,
1260 msg
.message
= message
;
1261 msg
.wParam
= wParam
;
1262 msg
.lParam
= lParam
;
1263 msg
.time
= GetTickCount();
1268 if (DDE_PostMessage(&msg
))
1270 #endif /* CONFIG_IPC */
1272 if (hwnd
== HWND_BROADCAST
)
1274 TRACE(msg
,"HWND_BROADCAST !\n");
1275 for (wndPtr
= WIN_GetDesktop()->child
; wndPtr
; wndPtr
= wndPtr
->next
)
1277 if (wndPtr
->dwStyle
& WS_POPUP
|| wndPtr
->dwStyle
& WS_CAPTION
)
1279 TRACE(msg
,"BROADCAST Message to hWnd=%04x m=%04X w=%04X l=%08lX !\n",
1280 wndPtr
->hwndSelf
, message
, wParam
, lParam
);
1281 PostMessageA( wndPtr
->hwndSelf
, message
, wParam
, lParam
);
1284 TRACE(msg
,"End of HWND_BROADCAST !\n");
1288 wndPtr
= WIN_FindWndPtr( hwnd
);
1289 if (!wndPtr
|| !wndPtr
->hmemTaskQ
) return FALSE
;
1291 return QUEUE_AddMsg( wndPtr
->hmemTaskQ
, &msg
, 0 );
1295 /***********************************************************************
1296 * PostMessage32W (USER32.420)
1298 BOOL WINAPI
PostMessageW( HWND hwnd
, UINT message
, WPARAM wParam
,
1302 return PostMessageA( hwnd
, message
, wParam
, lParam
);
1306 /***********************************************************************
1307 * PostAppMessage16 (USER.116)
1309 BOOL16 WINAPI
PostAppMessage16( HTASK16 hTask
, UINT16 message
, WPARAM16 wParam
,
1314 if (GetTaskQueue16(hTask
) == 0) return FALSE
;
1316 msg
.message
= message
;
1317 msg
.wParam
= wParam
;
1318 msg
.lParam
= lParam
;
1319 msg
.time
= GetTickCount();
1323 return QUEUE_AddMsg( GetTaskQueue16(hTask
), &msg
, 0 );
1327 /***********************************************************************
1328 * SendMessage16 (USER.111)
1330 LRESULT WINAPI
SendMessage16( HWND16 hwnd
, UINT16 msg
, WPARAM16 wParam
,
1334 WND
**list
, **ppWnd
;
1338 MSG16 DDE_msg
= { hwnd
, msg
, wParam
, lParam
};
1339 if (DDE_SendMessage(&DDE_msg
)) return TRUE
;
1340 #endif /* CONFIG_IPC */
1342 if (hwnd
== HWND_BROADCAST
)
1344 if (!(list
= WIN_BuildWinArray( WIN_GetDesktop(), 0, NULL
)))
1346 TRACE(msg
,"HWND_BROADCAST !\n");
1347 for (ppWnd
= list
; *ppWnd
; ppWnd
++)
1350 if (!IsWindow(wndPtr
->hwndSelf
)) continue;
1351 if (wndPtr
->dwStyle
& WS_POPUP
|| wndPtr
->dwStyle
& WS_CAPTION
)
1353 TRACE(msg
,"BROADCAST Message to hWnd=%04x m=%04X w=%04lX l=%08lX !\n",
1354 wndPtr
->hwndSelf
, msg
, (DWORD
)wParam
, lParam
);
1355 SendMessage16( wndPtr
->hwndSelf
, msg
, wParam
, lParam
);
1358 HeapFree( SystemHeap
, 0, list
);
1359 TRACE(msg
,"End of HWND_BROADCAST !\n");
1363 if (HOOK_IsHooked( WH_CALLWNDPROC
))
1367 if ((pmsg
= SEGPTR_NEW(CWPSTRUCT16
)))
1371 pmsg
->wParam
= wParam
;
1372 pmsg
->lParam
= lParam
;
1373 HOOK_CallHooks16( WH_CALLWNDPROC
, HC_ACTION
, 1,
1374 (LPARAM
)SEGPTR_GET(pmsg
) );
1376 msg
= pmsg
->message
;
1377 wParam
= pmsg
->wParam
;
1378 lParam
= pmsg
->lParam
;
1379 SEGPTR_FREE( pmsg
);
1383 if (!(wndPtr
= WIN_FindWndPtr( hwnd
)))
1385 WARN(msg
, "invalid hwnd %04x\n", hwnd
);
1388 if (QUEUE_IsExitingQueue(wndPtr
->hmemTaskQ
))
1389 return 0; /* Don't send anything if the task is dying */
1391 SPY_EnterMessage( SPY_SENDMESSAGE16
, hwnd
, msg
, wParam
, lParam
);
1393 if (wndPtr
->hmemTaskQ
!= GetFastQueue16())
1394 ret
= MSG_SendMessage( wndPtr
->hmemTaskQ
, hwnd
, msg
,
1395 wParam
, lParam
, 0 );
1397 ret
= CallWindowProc16( (WNDPROC16
)wndPtr
->winproc
,
1398 hwnd
, msg
, wParam
, lParam
);
1400 SPY_ExitMessage( SPY_RESULT_OK16
, hwnd
, msg
, ret
);
1404 /************************************************************************
1405 * MSG_CallWndProcHook32
1407 static void MSG_CallWndProcHook( LPMSG pmsg
, BOOL bUnicode
)
1411 cwp
.lParam
= pmsg
->lParam
;
1412 cwp
.wParam
= pmsg
->wParam
;
1413 cwp
.message
= pmsg
->message
;
1414 cwp
.hwnd
= pmsg
->hwnd
;
1416 if (bUnicode
) HOOK_CallHooksW(WH_CALLWNDPROC
, HC_ACTION
, 1, (LPARAM
)&cwp
);
1417 else HOOK_CallHooksA( WH_CALLWNDPROC
, HC_ACTION
, 1, (LPARAM
)&cwp
);
1419 pmsg
->lParam
= cwp
.lParam
;
1420 pmsg
->wParam
= cwp
.wParam
;
1421 pmsg
->message
= cwp
.message
;
1422 pmsg
->hwnd
= cwp
.hwnd
;
1425 /**********************************************************************
1426 * PostThreadMessage32A (USER32.422)
1430 * Thread-local message queues are not supported.
1433 BOOL WINAPI
PostThreadMessageA(DWORD idThread
, UINT message
,
1434 WPARAM wParam
, LPARAM lParam
)
1439 if ((hQueue
= GetThreadQueue16(idThread
)) == 0)
1443 msg
.message
= message
;
1444 msg
.wParam
= wParam
;
1445 msg
.lParam
= lParam
;
1446 msg
.time
= GetTickCount();
1450 return QUEUE_AddMsg( hQueue
, &msg
, 0 );
1453 /**********************************************************************
1454 * PostThreadMessage32W (USER32.423)
1458 * Thread-local message queues are not supported.
1461 BOOL WINAPI
PostThreadMessageW(DWORD idThread
, UINT message
,
1462 WPARAM wParam
, LPARAM lParam
)
1464 FIXME(sendmsg
, "(...): Should do unicode/ascii conversion!\n");
1465 return PostThreadMessageA(idThread
, message
, wParam
, lParam
);
1468 /***********************************************************************
1469 * SendMessage32A (USER32.454)
1471 LRESULT WINAPI
SendMessageA( HWND hwnd
, UINT msg
, WPARAM wParam
,
1475 WND
**list
, **ppWnd
;
1478 if (hwnd
== HWND_BROADCAST
|| hwnd
== HWND_TOPMOST
)
1480 if (!(list
= WIN_BuildWinArray( WIN_GetDesktop(), 0, NULL
)))
1482 for (ppWnd
= list
; *ppWnd
; ppWnd
++)
1485 if (!IsWindow(wndPtr
->hwndSelf
)) continue;
1486 if (wndPtr
->dwStyle
& WS_POPUP
|| wndPtr
->dwStyle
& WS_CAPTION
)
1487 SendMessageA( wndPtr
->hwndSelf
, msg
, wParam
, lParam
);
1489 HeapFree( SystemHeap
, 0, list
);
1493 if (HOOK_IsHooked( WH_CALLWNDPROC
))
1494 MSG_CallWndProcHook( (LPMSG
)&hwnd
, FALSE
);
1496 if (!(wndPtr
= WIN_FindWndPtr( hwnd
)))
1498 WARN(msg
, "invalid hwnd %08x\n", hwnd
);
1502 if (QUEUE_IsExitingQueue(wndPtr
->hmemTaskQ
))
1503 return 0; /* Don't send anything if the task is dying */
1505 SPY_EnterMessage( SPY_SENDMESSAGE
, hwnd
, msg
, wParam
, lParam
);
1507 if (wndPtr
->hmemTaskQ
!= GetFastQueue16())
1508 ret
= MSG_SendMessage( wndPtr
->hmemTaskQ
, hwnd
, msg
, wParam
, lParam
,
1511 ret
= CallWindowProcA( (WNDPROC
)wndPtr
->winproc
,
1512 hwnd
, msg
, wParam
, lParam
);
1514 SPY_ExitMessage( SPY_RESULT_OK
, hwnd
, msg
, ret
);
1519 /***********************************************************************
1520 * SendMessage32W (USER32.459) Send Window Message
1522 * Sends a message to the window procedure of the specified window.
1523 * SendMessage() will not return until the called window procedure
1524 * either returns or calls ReplyMessage().
1526 * Use PostMessage() to send message and return immediately. A window
1527 * procedure may use InSendMessage() to detect
1528 * SendMessage()-originated messages.
1530 * Applications which communicate via HWND_BROADCAST may use
1531 * RegisterWindowMessage() to obtain a unique message to avoid conflicts
1532 * with other applications.
1538 LRESULT WINAPI
SendMessageW(
1539 HWND hwnd
, /* Window to send message to. If HWND_BROADCAST,
1540 the message will be sent to all top-level windows. */
1542 UINT msg
, /* message */
1543 WPARAM wParam
, /* message parameter */
1544 LPARAM lParam
/* additional message parameter */
1547 WND
**list
, **ppWnd
;
1550 if (hwnd
== HWND_BROADCAST
|| hwnd
== HWND_TOPMOST
)
1552 if (!(list
= WIN_BuildWinArray( WIN_GetDesktop(), 0, NULL
)))
1554 for (ppWnd
= list
; *ppWnd
; ppWnd
++)
1557 if (!IsWindow(wndPtr
->hwndSelf
)) continue;
1558 if (wndPtr
->dwStyle
& WS_POPUP
|| wndPtr
->dwStyle
& WS_CAPTION
)
1559 SendMessageW( wndPtr
->hwndSelf
, msg
, wParam
, lParam
);
1561 HeapFree( SystemHeap
, 0, list
);
1565 if (HOOK_IsHooked( WH_CALLWNDPROC
))
1566 MSG_CallWndProcHook( (LPMSG
)&hwnd
, TRUE
);
1568 if (!(wndPtr
= WIN_FindWndPtr( hwnd
)))
1570 WARN(msg
, "invalid hwnd %08x\n", hwnd
);
1573 if (QUEUE_IsExitingQueue(wndPtr
->hmemTaskQ
))
1574 return 0; /* Don't send anything if the task is dying */
1576 SPY_EnterMessage( SPY_SENDMESSAGE
, hwnd
, msg
, wParam
, lParam
);
1578 if (wndPtr
->hmemTaskQ
!= GetFastQueue16())
1579 ret
= MSG_SendMessage( wndPtr
->hmemTaskQ
, hwnd
, msg
, wParam
, lParam
,
1580 SMSG_WIN32
| SMSG_UNICODE
);
1582 ret
= CallWindowProcW( (WNDPROC
)wndPtr
->winproc
,
1583 hwnd
, msg
, wParam
, lParam
);
1585 SPY_ExitMessage( SPY_RESULT_OK
, hwnd
, msg
, ret
);
1590 /***********************************************************************
1591 * SendMessageTimeout16 (not a WINAPI)
1593 LRESULT WINAPI
SendMessageTimeout16( HWND16 hwnd
, UINT16 msg
, WPARAM16 wParam
,
1594 LPARAM lParam
, UINT16 flags
,
1595 UINT16 timeout
, LPWORD resultp
)
1597 FIXME(sendmsg
, "(...): semistub\n");
1598 return SendMessage16 (hwnd
, msg
, wParam
, lParam
);
1602 /***********************************************************************
1603 * SendMessageTimeout32A (USER32.457)
1605 LRESULT WINAPI
SendMessageTimeoutA( HWND hwnd
, UINT msg
, WPARAM wParam
,
1606 LPARAM lParam
, UINT flags
,
1607 UINT timeout
, LPDWORD resultp
)
1609 FIXME(sendmsg
, "(...): semistub\n");
1610 return SendMessageA (hwnd
, msg
, wParam
, lParam
);
1614 /***********************************************************************
1615 * SendMessageTimeout32W (USER32.458)
1617 LRESULT WINAPI
SendMessageTimeoutW( HWND hwnd
, UINT msg
, WPARAM wParam
,
1618 LPARAM lParam
, UINT flags
,
1619 UINT timeout
, LPDWORD resultp
)
1621 FIXME(sendmsg
, "(...): semistub\n");
1622 return SendMessageW (hwnd
, msg
, wParam
, lParam
);
1626 /***********************************************************************
1627 * WaitMessage (USER.112) (USER32.578) Suspend thread pending messages
1629 * WaitMessage() suspends a thread until events appear in the thread's
1634 * Is supposed to return BOOL under Win32.
1636 * Thread-local message queues are not supported.
1643 void WINAPI
WaitMessage( void )
1645 QUEUE_WaitBits( QS_ALLINPUT
);
1648 /***********************************************************************
1649 * MsgWaitForMultipleObjects (USER32.400)
1651 DWORD WINAPI
MsgWaitForMultipleObjects( DWORD nCount
, HANDLE
*pHandles
,
1652 BOOL fWaitAll
, DWORD dwMilliseconds
,
1656 HANDLE handles
[MAXIMUM_WAIT_OBJECTS
];
1659 HQUEUE16 hQueue
= GetFastQueue16();
1660 MESSAGEQUEUE
*msgQueue
= (MESSAGEQUEUE
*)QUEUE_Lock( hQueue
);
1661 if (!msgQueue
) return WAIT_FAILED
;
1663 if (nCount
> MAXIMUM_WAIT_OBJECTS
-1)
1665 SetLastError( ERROR_INVALID_PARAMETER
);
1666 QUEUE_Unlock( msgQueue
);
1670 msgQueue
->changeBits
= 0;
1671 msgQueue
->wakeMask
= dwWakeMask
;
1673 if (THREAD_IsWin16(THREAD_Current()))
1676 * This is a temporary solution to a big problem.
1677 * You see, the main thread of all Win32 programs is created as a 16 bit
1678 * task. This means that if you want on an event using Win32 synchronization
1679 * methods, the 16 bit scheduler is stopped and things might just stop happening.
1680 * This implements a semi-busy loop that checks the handles to wait on and
1681 * also the message queue. When either one is ready, the wait function returns.
1683 * This will all go away when the real Win32 threads are implemented for all
1684 * the threads of an applications. Including the main thread.
1686 DWORD curTime
= GetCurrentTime();
1691 * Check the handles in the list.
1693 ret
= WaitForMultipleObjects(nCount
, pHandles
, fWaitAll
, 5L);
1696 * If the handles have been triggered, return.
1698 if (ret
!= WAIT_TIMEOUT
)
1702 * Then, let the 16 bit scheduler do it's thing.
1707 * If a message matching the wait mask has arrived, return.
1709 if (msgQueue
->changeBits
& dwWakeMask
)
1716 * And continue doing this until we hit the timeout.
1718 } while ((dwMilliseconds
== INFINITE
) || (GetCurrentTime()-curTime
< dwMilliseconds
) );
1722 /* Add the thread event to the handle list */
1723 for (i
= 0; i
< nCount
; i
++)
1724 handles
[i
] = pHandles
[i
];
1725 handles
[nCount
] = msgQueue
->hEvent
;
1727 ret
= WaitForMultipleObjects( nCount
+1, handles
, fWaitAll
, dwMilliseconds
);
1730 QUEUE_Unlock( msgQueue
);
1744 static const struct accent_char accent_chars
[] =
1746 /* A good idea should be to read /usr/X11/lib/X11/locale/iso8859-x/Compose */
1747 {'`', 'A', '\300'}, {'`', 'a', '\340'},
1748 {'\'', 'A', '\301'}, {'\'', 'a', '\341'},
1749 {'^', 'A', '\302'}, {'^', 'a', '\342'},
1750 {'~', 'A', '\303'}, {'~', 'a', '\343'},
1751 {'"', 'A', '\304'}, {'"', 'a', '\344'},
1752 {'O', 'A', '\305'}, {'o', 'a', '\345'},
1753 {'0', 'A', '\305'}, {'0', 'a', '\345'},
1754 {'A', 'A', '\305'}, {'a', 'a', '\345'},
1755 {'A', 'E', '\306'}, {'a', 'e', '\346'},
1756 {',', 'C', '\307'}, {',', 'c', '\347'},
1757 {'`', 'E', '\310'}, {'`', 'e', '\350'},
1758 {'\'', 'E', '\311'}, {'\'', 'e', '\351'},
1759 {'^', 'E', '\312'}, {'^', 'e', '\352'},
1760 {'"', 'E', '\313'}, {'"', 'e', '\353'},
1761 {'`', 'I', '\314'}, {'`', 'i', '\354'},
1762 {'\'', 'I', '\315'}, {'\'', 'i', '\355'},
1763 {'^', 'I', '\316'}, {'^', 'i', '\356'},
1764 {'"', 'I', '\317'}, {'"', 'i', '\357'},
1765 {'-', 'D', '\320'}, {'-', 'd', '\360'},
1766 {'~', 'N', '\321'}, {'~', 'n', '\361'},
1767 {'`', 'O', '\322'}, {'`', 'o', '\362'},
1768 {'\'', 'O', '\323'}, {'\'', 'o', '\363'},
1769 {'^', 'O', '\324'}, {'^', 'o', '\364'},
1770 {'~', 'O', '\325'}, {'~', 'o', '\365'},
1771 {'"', 'O', '\326'}, {'"', 'o', '\366'},
1772 {'/', 'O', '\330'}, {'/', 'o', '\370'},
1773 {'`', 'U', '\331'}, {'`', 'u', '\371'},
1774 {'\'', 'U', '\332'}, {'\'', 'u', '\372'},
1775 {'^', 'U', '\333'}, {'^', 'u', '\373'},
1776 {'"', 'U', '\334'}, {'"', 'u', '\374'},
1777 {'\'', 'Y', '\335'}, {'\'', 'y', '\375'},
1778 {'T', 'H', '\336'}, {'t', 'h', '\376'},
1779 {'s', 's', '\337'}, {'"', 'y', '\377'},
1780 {'s', 'z', '\337'}, {'i', 'j', '\377'},
1781 /* iso-8859-2 uses this */
1782 {'<', 'L', '\245'}, {'<', 'l', '\265'}, /* caron */
1783 {'<', 'S', '\251'}, {'<', 's', '\271'},
1784 {'<', 'T', '\253'}, {'<', 't', '\273'},
1785 {'<', 'Z', '\256'}, {'<', 'z', '\276'},
1786 {'<', 'C', '\310'}, {'<', 'c', '\350'},
1787 {'<', 'E', '\314'}, {'<', 'e', '\354'},
1788 {'<', 'D', '\317'}, {'<', 'd', '\357'},
1789 {'<', 'N', '\322'}, {'<', 'n', '\362'},
1790 {'<', 'R', '\330'}, {'<', 'r', '\370'},
1791 {';', 'A', '\241'}, {';', 'a', '\261'}, /* ogonek */
1792 {';', 'E', '\312'}, {';', 'e', '\332'},
1793 {'\'', 'Z', '\254'}, {'\'', 'z', '\274'}, /* acute */
1794 {'\'', 'R', '\300'}, {'\'', 'r', '\340'},
1795 {'\'', 'L', '\305'}, {'\'', 'l', '\345'},
1796 {'\'', 'C', '\306'}, {'\'', 'c', '\346'},
1797 {'\'', 'N', '\321'}, {'\'', 'n', '\361'},
1798 /* collision whith S, from iso-8859-9 !!! */
1799 {',', 'S', '\252'}, {',', 's', '\272'}, /* cedilla */
1800 {',', 'T', '\336'}, {',', 't', '\376'},
1801 {'.', 'Z', '\257'}, {'.', 'z', '\277'}, /* dot above */
1802 {'/', 'L', '\243'}, {'/', 'l', '\263'}, /* slash */
1803 {'/', 'D', '\320'}, {'/', 'd', '\360'},
1804 {'(', 'A', '\303'}, {'(', 'a', '\343'}, /* breve */
1805 {'\275', 'O', '\325'}, {'\275', 'o', '\365'}, /* double acute */
1806 {'\275', 'U', '\334'}, {'\275', 'u', '\374'},
1807 {'0', 'U', '\332'}, {'0', 'u', '\372'}, /* ring above */
1808 /* iso-8859-3 uses this */
1809 {'/', 'H', '\241'}, {'/', 'h', '\261'}, /* slash */
1810 {'>', 'H', '\246'}, {'>', 'h', '\266'}, /* circumflex */
1811 {'>', 'J', '\254'}, {'>', 'j', '\274'},
1812 {'>', 'C', '\306'}, {'>', 'c', '\346'},
1813 {'>', 'G', '\330'}, {'>', 'g', '\370'},
1814 {'>', 'S', '\336'}, {'>', 's', '\376'},
1815 /* collision whith G( from iso-8859-9 !!! */
1816 {'(', 'G', '\253'}, {'(', 'g', '\273'}, /* breve */
1817 {'(', 'U', '\335'}, {'(', 'u', '\375'},
1818 /* collision whith I. from iso-8859-3 !!! */
1819 {'.', 'I', '\251'}, {'.', 'i', '\271'}, /* dot above */
1820 {'.', 'C', '\305'}, {'.', 'c', '\345'},
1821 {'.', 'G', '\325'}, {'.', 'g', '\365'},
1822 /* iso-8859-4 uses this */
1823 {',', 'R', '\243'}, {',', 'r', '\263'}, /* cedilla */
1824 {',', 'L', '\246'}, {',', 'l', '\266'},
1825 {',', 'G', '\253'}, {',', 'g', '\273'},
1826 {',', 'N', '\321'}, {',', 'n', '\361'},
1827 {',', 'K', '\323'}, {',', 'k', '\363'},
1828 {'~', 'I', '\245'}, {'~', 'i', '\265'}, /* tilde */
1829 {'-', 'E', '\252'}, {'-', 'e', '\272'}, /* macron */
1830 {'-', 'A', '\300'}, {'-', 'a', '\340'},
1831 {'-', 'I', '\317'}, {'-', 'i', '\357'},
1832 {'-', 'O', '\322'}, {'-', 'o', '\362'},
1833 {'-', 'U', '\336'}, {'-', 'u', '\376'},
1834 {'/', 'T', '\254'}, {'/', 't', '\274'}, /* slash */
1835 {'.', 'E', '\314'}, {'.', 'e', '\344'}, /* dot above */
1836 {';', 'I', '\307'}, {';', 'i', '\347'}, /* ogonek */
1837 {';', 'U', '\331'}, {';', 'u', '\371'},
1838 /* iso-8859-9 uses this */
1839 /* iso-8859-9 has really bad choosen G( S, and I. as they collide
1840 * whith the same letters on other iso-8859-x (that is they are on
1841 * different places :-( ), if you use turkish uncomment these and
1842 * comment out the lines in iso-8859-2 and iso-8859-3 sections
1843 * FIXME: should be dynamic according to chosen language
1844 * if/when Wine has turkish support.
1846 /* collision whith G( from iso-8859-3 !!! */
1847 /* {'(', 'G', '\320'}, {'(', 'g', '\360'}, */ /* breve */
1848 /* collision whith S, from iso-8859-2 !!! */
1849 /* {',', 'S', '\336'}, {',', 's', '\376'}, */ /* cedilla */
1850 /* collision whith I. from iso-8859-3 !!! */
1851 /* {'.', 'I', '\335'}, {'.', 'i', '\375'}, */ /* dot above */
1855 /***********************************************************************
1856 * MSG_DoTranslateMessage
1858 * Implementation of TranslateMessage.
1860 * TranslateMessage translates virtual-key messages into character-messages,
1862 * WM_KEYDOWN/WM_KEYUP combinations produce a WM_CHAR or WM_DEADCHAR message.
1863 * ditto replacing WM_* with WM_SYS*
1864 * This produces WM_CHAR messages only for keys mapped to ASCII characters
1865 * by the keyboard driver.
1867 static BOOL
MSG_DoTranslateMessage( UINT message
, HWND hwnd
,
1868 WPARAM wParam
, LPARAM lParam
)
1870 static int dead_char
;
1873 if (message
!= WM_MOUSEMOVE
&& message
!= WM_TIMER
)
1874 TRACE(msg
, "(%s, %04X, %08lX)\n",
1875 SPY_GetMsgName(message
), wParam
, lParam
);
1876 if(message
>= WM_KEYFIRST
&& message
<= WM_KEYLAST
)
1877 TRACE(key
, "(%s, %04X, %08lX)\n",
1878 SPY_GetMsgName(message
), wParam
, lParam
);
1880 if ((message
!= WM_KEYDOWN
) && (message
!= WM_SYSKEYDOWN
)) return FALSE
;
1882 TRACE(key
, "Translating key %04X, scancode %04X\n",
1883 wParam
, HIWORD(lParam
) );
1885 /* FIXME : should handle ToAscii yielding 2 */
1886 switch (ToAscii(wParam
, HIWORD(lParam
),
1887 QueueKeyStateTable
,(LPWORD
)wp
, 0))
1890 message
= (message
== WM_KEYDOWN
) ? WM_CHAR
: WM_SYSCHAR
;
1891 /* Should dead chars handling go in ToAscii ? */
1896 if (wp
[0] == ' ') wp
[0] = dead_char
;
1897 if (dead_char
== 0xa2) dead_char
= '(';
1898 else if (dead_char
== 0xa8) dead_char
= '"';
1899 else if (dead_char
== 0xb2) dead_char
= ';';
1900 else if (dead_char
== 0xb4) dead_char
= '\'';
1901 else if (dead_char
== 0xb7) dead_char
= '<';
1902 else if (dead_char
== 0xb8) dead_char
= ',';
1903 else if (dead_char
== 0xff) dead_char
= '.';
1904 for (i
= 0; i
< sizeof(accent_chars
)/sizeof(accent_chars
[0]); i
++)
1905 if ((accent_chars
[i
].ac_accent
== dead_char
) &&
1906 (accent_chars
[i
].ac_char
== wp
[0]))
1908 wp
[0] = accent_chars
[i
].ac_result
;
1913 TRACE(key
, "1 -> PostMessage(%s)\n", SPY_GetMsgName(message
));
1914 PostMessage16( hwnd
, message
, wp
[0], lParam
);
1918 message
= (message
== WM_KEYDOWN
) ? WM_DEADCHAR
: WM_SYSDEADCHAR
;
1920 TRACE(key
, "-1 -> PostMessage(%s)\n",
1921 SPY_GetMsgName(message
));
1922 PostMessage16( hwnd
, message
, wp
[0], lParam
);
1929 /***********************************************************************
1930 * TranslateMessage16 (USER.113)
1932 BOOL16 WINAPI
TranslateMessage16( const MSG16
*msg
)
1934 return MSG_DoTranslateMessage( msg
->message
, msg
->hwnd
,
1935 msg
->wParam
, msg
->lParam
);
1939 /***********************************************************************
1940 * WIN16_TranslateMessage32 (USER.821)
1942 BOOL16 WINAPI
TranslateMessage32_16( const MSG32_16
*msg
, BOOL16 wHaveParamHigh
)
1947 wParam
= MAKELONG(msg
->msg
.wParam
, msg
->wParamHigh
);
1949 wParam
= (WPARAM
)msg
->msg
.wParam
;
1951 return MSG_DoTranslateMessage( msg
->msg
.message
, msg
->msg
.hwnd
,
1952 wParam
, msg
->msg
.lParam
);
1955 /***********************************************************************
1956 * TranslateMessage32 (USER32.556)
1958 BOOL WINAPI
TranslateMessage( const MSG
*msg
)
1960 return MSG_DoTranslateMessage( msg
->message
, msg
->hwnd
,
1961 msg
->wParam
, msg
->lParam
);
1965 /***********************************************************************
1966 * DispatchMessage16 (USER.114)
1968 LONG WINAPI
DispatchMessage16( const MSG16
* msg
)
1974 /* Process timer messages */
1975 if ((msg
->message
== WM_TIMER
) || (msg
->message
== WM_SYSTIMER
))
1979 return CallWindowProc16( (WNDPROC16
)msg
->lParam
, msg
->hwnd
,
1980 msg
->message
, msg
->wParam
, GetTickCount() );
1984 if (!msg
->hwnd
) return 0;
1985 if (!(wndPtr
= WIN_FindWndPtr( msg
->hwnd
))) return 0;
1986 if (!wndPtr
->winproc
) return 0;
1987 painting
= (msg
->message
== WM_PAINT
);
1988 if (painting
) wndPtr
->flags
|= WIN_NEEDS_BEGINPAINT
;
1990 SPY_EnterMessage( SPY_DISPATCHMESSAGE16
, msg
->hwnd
, msg
->message
,
1991 msg
->wParam
, msg
->lParam
);
1992 retval
= CallWindowProc16( (WNDPROC16
)wndPtr
->winproc
,
1993 msg
->hwnd
, msg
->message
,
1994 msg
->wParam
, msg
->lParam
);
1995 SPY_ExitMessage( SPY_RESULT_OK16
, msg
->hwnd
, msg
->message
, retval
);
1997 if (painting
&& (wndPtr
= WIN_FindWndPtr( msg
->hwnd
)) &&
1998 (wndPtr
->flags
& WIN_NEEDS_BEGINPAINT
) && wndPtr
->hrgnUpdate
)
2000 ERR(msg
, "BeginPaint not called on WM_PAINT for hwnd %04x!\n",
2002 wndPtr
->flags
&= ~WIN_NEEDS_BEGINPAINT
;
2003 /* Validate the update region to avoid infinite WM_PAINT loop */
2004 ValidateRect( msg
->hwnd
, NULL
);
2010 /***********************************************************************
2011 * WIN16_DispatchMessage32 (USER.822)
2013 LONG WINAPI
DispatchMessage32_16( const MSG32_16
* lpmsg16_32
, BOOL16 wHaveParamHigh
)
2015 if (wHaveParamHigh
== FALSE
)
2016 return DispatchMessage16(&(lpmsg16_32
->msg
));
2021 msg
.hwnd
= lpmsg16_32
->msg
.hwnd
;
2022 msg
.message
= lpmsg16_32
->msg
.message
;
2023 msg
.wParam
= MAKELONG(lpmsg16_32
->msg
.wParam
, lpmsg16_32
->wParamHigh
);
2024 msg
.lParam
= lpmsg16_32
->msg
.lParam
;
2025 msg
.time
= lpmsg16_32
->msg
.time
;
2026 msg
.pt
.x
= (INT
)lpmsg16_32
->msg
.pt
.x
;
2027 msg
.pt
.y
= (INT
)lpmsg16_32
->msg
.pt
.y
;
2028 return DispatchMessageA(&msg
);
2032 /***********************************************************************
2033 * DispatchMessage32A (USER32.141)
2035 LONG WINAPI
DispatchMessageA( const MSG
* msg
)
2041 /* Process timer messages */
2042 if ((msg
->message
== WM_TIMER
) || (msg
->message
== WM_SYSTIMER
))
2046 /* HOOK_CallHooks32A( WH_CALLWNDPROC, HC_ACTION, 0, FIXME ); */
2047 return CallWindowProcA( (WNDPROC
)msg
->lParam
, msg
->hwnd
,
2048 msg
->message
, msg
->wParam
, GetTickCount() );
2052 if (!msg
->hwnd
) return 0;
2053 if (!(wndPtr
= WIN_FindWndPtr( msg
->hwnd
))) return 0;
2054 if (!wndPtr
->winproc
) return 0;
2055 painting
= (msg
->message
== WM_PAINT
);
2056 if (painting
) wndPtr
->flags
|= WIN_NEEDS_BEGINPAINT
;
2057 /* HOOK_CallHooks32A( WH_CALLWNDPROC, HC_ACTION, 0, FIXME ); */
2059 SPY_EnterMessage( SPY_DISPATCHMESSAGE
, msg
->hwnd
, msg
->message
,
2060 msg
->wParam
, msg
->lParam
);
2061 retval
= CallWindowProcA( (WNDPROC
)wndPtr
->winproc
,
2062 msg
->hwnd
, msg
->message
,
2063 msg
->wParam
, msg
->lParam
);
2064 SPY_ExitMessage( SPY_RESULT_OK
, msg
->hwnd
, msg
->message
, retval
);
2066 if (painting
&& (wndPtr
= WIN_FindWndPtr( msg
->hwnd
)) &&
2067 (wndPtr
->flags
& WIN_NEEDS_BEGINPAINT
) && wndPtr
->hrgnUpdate
)
2069 ERR(msg
, "BeginPaint not called on WM_PAINT for hwnd %04x!\n",
2071 wndPtr
->flags
&= ~WIN_NEEDS_BEGINPAINT
;
2072 /* Validate the update region to avoid infinite WM_PAINT loop */
2073 ValidateRect( msg
->hwnd
, NULL
);
2079 /***********************************************************************
2080 * DispatchMessage32W (USER32.142) Process Message
2082 * Process the message specified in the structure *_msg_.
2084 * If the lpMsg parameter points to a WM_TIMER message and the
2085 * parameter of the WM_TIMER message is not NULL, the lParam parameter
2086 * points to the function that is called instead of the window
2089 * The message must be valid.
2093 * DispatchMessage() returns the result of the window procedure invoked.
2100 LONG WINAPI
DispatchMessageW( const MSG
* msg
)
2106 /* Process timer messages */
2107 if ((msg
->message
== WM_TIMER
) || (msg
->message
== WM_SYSTIMER
))
2111 /* HOOK_CallHooks32W( WH_CALLWNDPROC, HC_ACTION, 0, FIXME ); */
2112 return CallWindowProcW( (WNDPROC
)msg
->lParam
, msg
->hwnd
,
2113 msg
->message
, msg
->wParam
, GetTickCount() );
2117 if (!msg
->hwnd
) return 0;
2118 if (!(wndPtr
= WIN_FindWndPtr( msg
->hwnd
))) return 0;
2119 if (!wndPtr
->winproc
) return 0;
2120 painting
= (msg
->message
== WM_PAINT
);
2121 if (painting
) wndPtr
->flags
|= WIN_NEEDS_BEGINPAINT
;
2122 /* HOOK_CallHooks32W( WH_CALLWNDPROC, HC_ACTION, 0, FIXME ); */
2124 SPY_EnterMessage( SPY_DISPATCHMESSAGE
, msg
->hwnd
, msg
->message
,
2125 msg
->wParam
, msg
->lParam
);
2126 retval
= CallWindowProcW( (WNDPROC
)wndPtr
->winproc
,
2127 msg
->hwnd
, msg
->message
,
2128 msg
->wParam
, msg
->lParam
);
2129 SPY_ExitMessage( SPY_RESULT_OK
, msg
->hwnd
, msg
->message
, retval
);
2131 if (painting
&& (wndPtr
= WIN_FindWndPtr( msg
->hwnd
)) &&
2132 (wndPtr
->flags
& WIN_NEEDS_BEGINPAINT
) && wndPtr
->hrgnUpdate
)
2134 ERR(msg
, "BeginPaint not called on WM_PAINT for hwnd %04x!\n",
2136 wndPtr
->flags
&= ~WIN_NEEDS_BEGINPAINT
;
2137 /* Validate the update region to avoid infinite WM_PAINT loop */
2138 ValidateRect( msg
->hwnd
, NULL
);
2144 /***********************************************************************
2145 * RegisterWindowMessage16 (USER.118)
2147 WORD WINAPI
RegisterWindowMessage16( SEGPTR str
)
2149 TRACE(msg
, "%08lx\n", (DWORD
)str
);
2150 return GlobalAddAtom16( str
);
2154 /***********************************************************************
2155 * RegisterWindowMessage32A (USER32.437)
2157 WORD WINAPI
RegisterWindowMessageA( LPCSTR str
)
2159 TRACE(msg
, "%s\n", str
);
2160 return GlobalAddAtomA( str
);
2164 /***********************************************************************
2165 * RegisterWindowMessage32W (USER32.438)
2167 WORD WINAPI
RegisterWindowMessageW( LPCWSTR str
)
2169 TRACE(msg
, "%p\n", str
);
2170 return GlobalAddAtomW( str
);
2174 /***********************************************************************
2175 * GetTickCount (USER.13) (KERNEL32.299) System Time
2176 * Returns the number of milliseconds, modulo 2^32, since the start
2177 * of the current session.
2183 DWORD WINAPI
GetTickCount(void)
2186 gettimeofday( &t
, NULL
);
2187 /* make extremely compatible: granularity is 25 msec */
2188 return ((t
.tv_sec
* 1000) + (t
.tv_usec
/ 25000) * 25) - MSG_WineStartTicks
;
2192 /***********************************************************************
2193 * GetCurrentTime16 (USER.15)
2195 * (effectively identical to GetTickCount)
2197 DWORD WINAPI
GetCurrentTime16(void)
2199 return GetTickCount();
2203 /***********************************************************************
2204 * InSendMessage16 (USER.192)
2206 BOOL16 WINAPI
InSendMessage16(void)
2208 return InSendMessage();
2212 /***********************************************************************
2213 * InSendMessage32 (USER32.320)
2215 BOOL WINAPI
InSendMessage(void)
2217 MESSAGEQUEUE
*queue
;
2220 if (!(queue
= (MESSAGEQUEUE
*)QUEUE_Lock( GetFastQueue16() )))
2222 ret
= (BOOL
)queue
->smWaiting
;
2224 QUEUE_Unlock( queue
);
2228 /***********************************************************************
2229 * BroadcastSystemMessage (USER32.12)
2231 LONG WINAPI
BroadcastSystemMessage(
2232 DWORD dwFlags
,LPDWORD recipients
,UINT uMessage
,WPARAM wParam
,
2235 FIXME(sendmsg
,"(%08lx,%08lx,%08x,%08x,%08lx): stub!\n",
2236 dwFlags
,*recipients
,uMessage
,wParam
,lParam
2241 /***********************************************************************
2242 * SendNotifyMessageA (USER32.460)
2244 * The message sended with PostMessage has to be put in the queue
2245 * with a higher priority as the other "Posted" messages.
2246 * QUEUE_AddMsg has to be modifyed.
2248 BOOL WINAPI
SendNotifyMessageA(HWND hwnd
,UINT msg
,WPARAM wParam
,LPARAM lParam
)
2250 FIXME(msg
,"(%04x,%08x,%08x,%08lx) not complete\n",
2251 hwnd
, msg
, wParam
, lParam
);
2253 if ( GetCurrentThreadId() == GetWindowThreadProcessId ( hwnd
, NULL
))
2254 { ret
=SendMessageA ( hwnd
, msg
, wParam
, lParam
);
2257 { PostMessageA ( hwnd
, msg
, wParam
, lParam
);
2262 /***********************************************************************
2263 * SendNotifyMessageW (USER32.461)
2265 * The message sended with PostMessage has to be put in the queue
2266 * with a higher priority as the other "Posted" messages.
2267 * QUEUE_AddMsg has to be modifyed.
2269 BOOL WINAPI
SendNotifyMessageW(HWND hwnd
,UINT msg
,WPARAM wParam
,LPARAM lParam
)
2271 FIXME(msg
,"(%04x,%08x,%08x,%08lx) not complete\n",
2272 hwnd
, msg
, wParam
, lParam
);
2274 if ( GetCurrentThreadId() == GetWindowThreadProcessId ( hwnd
, NULL
))
2275 { ret
=SendMessageW ( hwnd
, msg
, wParam
, lParam
);
2278 { PostMessageW ( hwnd
, msg
, wParam
, lParam
);
2283 /***********************************************************************
2284 * SendMessageCallBack32A
2285 * FIXME: It's like PostMessage. The callback gets called when the message
2286 * is processed. We have to modify the message processing for a exact
2289 BOOL WINAPI
SendMessageCallBackA(
2290 HWND hWnd
,UINT Msg
,WPARAM wParam
,LPARAM lParam
,
2291 FARPROC lpResultCallBack
,DWORD dwData
)
2293 FIXME(msg
,"(0x%04x,0x%04x,0x%08x,0x%08lx,%p,0x%08lx),stub!\n",
2294 hWnd
,Msg
,wParam
,lParam
,lpResultCallBack
,dwData
);
2295 if ( hWnd
== HWND_BROADCAST
)
2296 { PostMessageA( hWnd
, Msg
, wParam
, lParam
);
2297 FIXME(msg
,"Broadcast: Callback will not be called!\n");
2300 (lpResultCallBack
)( hWnd
, Msg
, dwData
, SendMessageA ( hWnd
, Msg
, wParam
, lParam
));