2 * Message queues related functions
4 * Copyright 1993, 1994 Alexandre Julliard
11 #include <sys/types.h>
13 #include "wine/winbase16.h"
14 #include "wine/winuser16.h"
17 #include "wine/server.h"
31 #include "debugtools.h"
33 DEFAULT_DEBUG_CHANNEL(msg
);
34 DECLARE_DEBUG_CHANNEL(key
);
36 #define WM_NCMOUSEFIRST WM_NCMOUSEMOVE
37 #define WM_NCMOUSELAST WM_NCMBUTTONDBLCLK
43 static UINT doubleClickSpeed
= 452;
45 static BOOL
MSG_ConvertMsg( MSG
*msg
, int srcType
, int dstType
);
49 /* flag for messages that contain pointers */
50 /* 16 messages per entry, messages 0..15 map to bits 0..15 */
52 #define SET(msg) (1 << ((msg) & 15))
54 static const unsigned short message_pointer_flags
[] =
57 SET(WM_CREATE
) | SET(WM_GETTEXT
) | SET(WM_SETTEXT
),
61 SET(WM_GETMINMAXINFO
) | SET(WM_DRAWITEM
) | SET(WM_MEASUREITEM
) | SET(WM_DELETEITEM
),
65 SET(WM_WINDOWPOSCHANGING
) | SET(WM_WINDOWPOSCHANGED
) | SET(WM_COPYDATA
) | SET(WM_NOTIFY
),
71 SET(WM_STYLECHANGING
) | SET(WM_STYLECHANGED
),
73 SET(WM_NCCREATE
) | SET(WM_NCCALCSIZE
) | SET(WM_GETDLGCODE
),
79 SET(EM_GETSEL
) | SET(EM_GETRECT
) | SET(EM_SETRECT
) | SET(EM_SETRECTNP
),
81 SET(EM_REPLACESEL
) | SET(EM_GETLINE
) | SET(EM_SETTABSTOPS
),
97 SET(CB_ADDSTRING
) | SET(CB_DIR
) | SET(CB_GETLBTEXT
) | SET(CB_INSERTSTRING
) |
98 SET(CB_FINDSTRING
) | SET(CB_SELECTSTRING
),
100 SET(CB_GETDROPPEDCONTROLRECT
) | SET(CB_FINDSTRINGEXACT
),
106 SET(LB_ADDSTRING
) | SET(LB_INSERTSTRING
) | SET(LB_GETTEXT
) | SET(LB_SELECTSTRING
) |
107 SET(LB_DIR
) | SET(LB_FINDSTRING
),
109 SET(LB_GETSELITEMS
) | SET(LB_SETTABSTOPS
) | SET(LB_ADDFILE
) | SET(LB_GETITEMRECT
),
111 SET(LB_FINDSTRINGEXACT
),
127 SET(WM_MDICREATE
) | SET(WM_MDIGETACTIVE
) | SET(WM_DROPOBJECT
) |
128 SET(WM_QUERYDROPOBJECT
) | SET(WM_DRAGSELECT
) | SET(WM_DRAGMOVE
)
133 /***********************************************************************
136 inline static int is_pointer_message( UINT message
)
138 if (message
>= 8*sizeof(message_pointer_flags
)) return FALSE
;
139 return (message_pointer_flags
[message
/ 16] & (1 << (message
& 15))) != 0;
143 /***********************************************************************
144 * is_keyboard_message
146 inline static BOOL
is_keyboard_message( UINT message
)
148 return (message
>= WM_KEYFIRST
&& message
<= WM_KEYLAST
);
152 /***********************************************************************
155 inline static BOOL
is_mouse_message( UINT message
)
157 return ((message
>= WM_NCMOUSEFIRST
&& message
<= WM_NCMOUSELAST
) ||
158 (message
>= WM_MOUSEFIRST
&& message
<= WM_MOUSELAST
));
162 /***********************************************************************
163 * check_message_filter
165 inline static BOOL
check_message_filter( const MSG
*msg
, HWND hwnd
, UINT first
, UINT last
)
169 if (msg
->hwnd
!= hwnd
&& !IsChild( hwnd
, msg
->hwnd
)) return FALSE
;
173 return (msg
->message
>= first
&& msg
->message
<= last
);
179 /***********************************************************************
182 * Convert the wparam of an ASCII message to Unicode.
184 static WPARAM
map_wparam_AtoW( UINT message
, WPARAM wparam
)
186 if (message
== WM_CHARTOITEM
||
187 message
== EM_SETPASSWORDCHAR
||
188 message
== WM_CHAR
||
189 message
== WM_DEADCHAR
||
190 message
== WM_SYSCHAR
||
191 message
== WM_SYSDEADCHAR
||
192 message
== WM_MENUCHAR
)
194 char ch
= LOWORD(wparam
);
196 MultiByteToWideChar(CP_ACP
, 0, &ch
, 1, &wch
, 1);
197 wparam
= MAKEWPARAM( wch
, HIWORD(wparam
) );
203 /***********************************************************************
206 * Convert the wparam of a Unicode message to ASCII.
208 static WPARAM
map_wparam_WtoA( UINT message
, WPARAM wparam
)
210 if (message
== WM_CHARTOITEM
||
211 message
== EM_SETPASSWORDCHAR
||
212 message
== WM_CHAR
||
213 message
== WM_DEADCHAR
||
214 message
== WM_SYSCHAR
||
215 message
== WM_SYSDEADCHAR
||
216 message
== WM_MENUCHAR
)
218 WCHAR wch
= LOWORD(wparam
);
220 WideCharToMultiByte( CP_ACP
, 0, &wch
, 1, &ch
, 1, NULL
, NULL
);
221 wparam
= MAKEWPARAM( ch
, HIWORD(wparam
) );
227 /***********************************************************************
228 * queue_hardware_message
230 * store a hardware message in the thread queue
232 static void queue_hardware_message( MSG
*msg
, ULONG_PTR extra_info
, enum message_kind kind
)
234 SERVER_START_REQ( send_message
)
237 req
->id
= (void *)GetWindowThreadProcessId( msg
->hwnd
, NULL
);
239 req
->win
= msg
->hwnd
;
240 req
->msg
= msg
->message
;
241 req
->wparam
= msg
->wParam
;
242 req
->lparam
= msg
->lParam
;
245 req
->time
= msg
->time
;
246 req
->info
= extra_info
;
253 /***********************************************************************
254 * MSG_SendParentNotify
256 * Send a WM_PARENTNOTIFY to all ancestors of the given window, unless
257 * the window has the WS_EX_NOPARENTNOTIFY style.
259 static void MSG_SendParentNotify( HWND hwnd
, WORD event
, WORD idChild
, POINT pt
)
261 WND
*tmpWnd
= WIN_FindWndPtr(hwnd
);
263 /* pt has to be in the client coordinates of the parent window */
264 MapWindowPoints( 0, tmpWnd
->hwndSelf
, &pt
, 1 );
267 if (!(tmpWnd
->dwStyle
& WS_CHILD
) || (tmpWnd
->dwExStyle
& WS_EX_NOPARENTNOTIFY
))
269 WIN_ReleaseWndPtr(tmpWnd
);
272 pt
.x
+= tmpWnd
->rectClient
.left
;
273 pt
.y
+= tmpWnd
->rectClient
.top
;
274 WIN_UpdateWndPtr(&tmpWnd
,tmpWnd
->parent
);
275 SendMessageA( tmpWnd
->hwndSelf
, WM_PARENTNOTIFY
,
276 MAKEWPARAM( event
, idChild
), MAKELPARAM( pt
.x
, pt
.y
) );
281 /***********************************************************************
282 * MSG_JournalPlayBackMsg
284 * Get an EVENTMSG struct via call JOURNALPLAYBACK hook function
286 static void MSG_JournalPlayBackMsg(void)
293 if (!HOOK_IsHooked( WH_JOURNALPLAYBACK
)) return;
295 wtime
=HOOK_CallHooksA( WH_JOURNALPLAYBACK
, HC_GETNEXT
, 0, (LPARAM
)&tmpMsg
);
296 /* TRACE(msg,"Playback wait time =%ld\n",wtime); */
300 msg
.message
= tmpMsg
.message
;
301 msg
.hwnd
= tmpMsg
.hwnd
;
302 msg
.time
= tmpMsg
.time
;
303 if ((tmpMsg
.message
>= WM_KEYFIRST
) && (tmpMsg
.message
<= WM_KEYLAST
))
305 msg
.wParam
= tmpMsg
.paramL
& 0xFF;
306 msg
.lParam
= MAKELONG(tmpMsg
.paramH
&0x7ffff,tmpMsg
.paramL
>>8);
307 if (tmpMsg
.message
== WM_KEYDOWN
|| tmpMsg
.message
== WM_SYSKEYDOWN
)
309 for (keyDown
=i
=0; i
<256 && !keyDown
; i
++)
310 if (InputKeyStateTable
[i
] & 0x80)
313 msg
.lParam
|= 0x40000000;
314 AsyncKeyStateTable
[msg
.wParam
]=InputKeyStateTable
[msg
.wParam
] |= 0x80;
316 else /* WM_KEYUP, WM_SYSKEYUP */
318 msg
.lParam
|= 0xC0000000;
319 AsyncKeyStateTable
[msg
.wParam
]=InputKeyStateTable
[msg
.wParam
] &= ~0x80;
321 if (InputKeyStateTable
[VK_MENU
] & 0x80)
322 msg
.lParam
|= 0x20000000;
323 if (tmpMsg
.paramH
& 0x8000) /*special_key bit*/
324 msg
.lParam
|= 0x01000000;
326 msg
.pt
.x
= msg
.pt
.y
= 0;
327 queue_hardware_message( &msg
, 0, RAW_HW_MESSAGE
);
329 else if ((tmpMsg
.message
>= WM_MOUSEFIRST
) && (tmpMsg
.message
<= WM_MOUSELAST
))
331 switch (tmpMsg
.message
)
334 MouseButtonsStates
[0]=AsyncMouseButtonsStates
[0]=TRUE
;break;
336 MouseButtonsStates
[0]=AsyncMouseButtonsStates
[0]=FALSE
;break;
338 MouseButtonsStates
[1]=AsyncMouseButtonsStates
[1]=TRUE
;break;
340 MouseButtonsStates
[1]=AsyncMouseButtonsStates
[1]=FALSE
;break;
342 MouseButtonsStates
[2]=AsyncMouseButtonsStates
[2]=TRUE
;break;
344 MouseButtonsStates
[2]=AsyncMouseButtonsStates
[2]=FALSE
;break;
346 AsyncKeyStateTable
[VK_LBUTTON
]= InputKeyStateTable
[VK_LBUTTON
] = MouseButtonsStates
[0] ? 0x80 : 0;
347 AsyncKeyStateTable
[VK_MBUTTON
]= InputKeyStateTable
[VK_MBUTTON
] = MouseButtonsStates
[1] ? 0x80 : 0;
348 AsyncKeyStateTable
[VK_RBUTTON
]= InputKeyStateTable
[VK_RBUTTON
] = MouseButtonsStates
[2] ? 0x80 : 0;
349 SetCursorPos(tmpMsg
.paramL
,tmpMsg
.paramH
);
350 msg
.lParam
=MAKELONG(tmpMsg
.paramL
,tmpMsg
.paramH
);
352 if (MouseButtonsStates
[0]) msg
.wParam
|= MK_LBUTTON
;
353 if (MouseButtonsStates
[1]) msg
.wParam
|= MK_MBUTTON
;
354 if (MouseButtonsStates
[2]) msg
.wParam
|= MK_RBUTTON
;
356 msg
.pt
.x
= tmpMsg
.paramL
;
357 msg
.pt
.y
= tmpMsg
.paramH
;
358 queue_hardware_message( &msg
, 0, RAW_HW_MESSAGE
);
360 HOOK_CallHooksA( WH_JOURNALPLAYBACK
, HC_SKIP
, 0, (LPARAM
)&tmpMsg
);
364 if( tmpMsg
.message
== WM_QUEUESYNC
)
365 if (HOOK_IsHooked( WH_CBT
))
366 HOOK_CallHooksA( WH_CBT
, HCBT_QS
, 0, 0L);
371 /***********************************************************************
372 * process_raw_keyboard_message
374 * returns TRUE if the contents of 'msg' should be passed to the application
376 static BOOL
process_raw_keyboard_message( MSG
*msg
, ULONG_PTR extra_info
)
378 if (!(msg
->hwnd
= GetFocus()))
380 /* Send the message to the active window instead, */
381 /* translating messages to their WM_SYS equivalent */
382 msg
->hwnd
= GetActiveWindow();
383 if (msg
->message
< WM_SYSKEYDOWN
) msg
->message
+= WM_SYSKEYDOWN
- WM_KEYDOWN
;
386 if (HOOK_IsHooked( WH_JOURNALRECORD
))
390 event
.message
= msg
->message
;
391 event
.hwnd
= msg
->hwnd
;
392 event
.time
= msg
->time
;
393 event
.paramL
= (msg
->wParam
& 0xFF) | (HIWORD(msg
->lParam
) << 8);
394 event
.paramH
= msg
->lParam
& 0x7FFF;
395 if (HIWORD(msg
->lParam
) & 0x0100) event
.paramH
|= 0x8000; /* special_key - bit */
396 HOOK_CallHooksA( WH_JOURNALRECORD
, HC_ACTION
, 0, (LPARAM
)&event
);
399 return (msg
->hwnd
!= 0);
403 /***********************************************************************
404 * process_cooked_keyboard_message
406 * returns TRUE if the contents of 'msg' should be passed to the application
408 static BOOL
process_cooked_keyboard_message( MSG
*msg
, BOOL remove
)
412 /* Handle F1 key by sending out WM_HELP message */
413 if ((msg
->message
== WM_KEYUP
) &&
414 (msg
->wParam
== VK_F1
) &&
415 (msg
->hwnd
!= GetDesktopWindow()) &&
416 !MENU_IsMenuActive())
419 hi
.cbSize
= sizeof(HELPINFO
);
420 hi
.iContextType
= HELPINFO_WINDOW
;
421 hi
.iCtrlId
= GetWindowLongA( msg
->hwnd
, GWL_ID
);
422 hi
.hItemHandle
= msg
->hwnd
;
423 hi
.dwContextId
= GetWindowContextHelpId( msg
->hwnd
);
424 hi
.MousePos
= msg
->pt
;
425 SendMessageA(msg
->hwnd
, WM_HELP
, 0, (LPARAM
)&hi
);
429 if (HOOK_CallHooksA( WH_KEYBOARD
, remove
? HC_ACTION
: HC_NOREMOVE
,
430 LOWORD(msg
->wParam
), msg
->lParam
))
432 /* skip this message */
433 HOOK_CallHooksA( WH_CBT
, HCBT_KEYSKIPPED
, LOWORD(msg
->wParam
), msg
->lParam
);
440 /***********************************************************************
441 * process_raw_mouse_message
443 * returns TRUE if the contents of 'msg' should be passed to the application
445 static BOOL
process_raw_mouse_message( MSG
*msg
, ULONG_PTR extra_info
)
452 /* find the window to dispatch this mouse message to */
455 if (!(msg
->hwnd
= PERQDATA_GetCaptureWnd( &ht
)))
457 /* If no capture HWND, find window which contains the mouse position.
458 * Also find the position of the cursor hot spot (hittest) */
459 HWND hWndScope
= (HWND
)extra_info
;
461 if (!IsWindow(hWndScope
)) hWndScope
= 0;
462 if (!(msg
->hwnd
= WINPOS_WindowFromPoint( hWndScope
, msg
->pt
, &hittest
)))
463 msg
->hwnd
= GetDesktopWindow();
467 if (HOOK_IsHooked( WH_JOURNALRECORD
))
470 event
.message
= msg
->message
;
471 event
.time
= msg
->time
;
472 event
.hwnd
= msg
->hwnd
;
473 event
.paramL
= msg
->pt
.x
;
474 event
.paramH
= msg
->pt
.y
;
475 HOOK_CallHooksA( WH_JOURNALRECORD
, HC_ACTION
, 0, (LPARAM
)&event
);
478 /* translate double clicks */
480 if ((msg
->message
== WM_LBUTTONDOWN
) ||
481 (msg
->message
== WM_RBUTTONDOWN
) ||
482 (msg
->message
== WM_MBUTTONDOWN
))
485 /* translate double clicks -
486 * note that ...MOUSEMOVEs can slip in between
487 * ...BUTTONDOWN and ...BUTTONDBLCLK messages */
489 if (GetClassLongA( msg
->hwnd
, GCL_STYLE
) & CS_DBLCLKS
|| ht
!= HTCLIENT
)
491 if ((msg
->message
== clk_msg
.message
) &&
492 (msg
->hwnd
== clk_msg
.hwnd
) &&
493 (msg
->time
- clk_msg
.time
< doubleClickSpeed
) &&
494 (abs(msg
->pt
.x
- clk_msg
.pt
.x
) < GetSystemMetrics(SM_CXDOUBLECLK
)/2) &&
495 (abs(msg
->pt
.y
- clk_msg
.pt
.y
) < GetSystemMetrics(SM_CYDOUBLECLK
)/2))
497 msg
->message
+= (WM_LBUTTONDBLCLK
- WM_LBUTTONDOWN
);
502 /* update static double click conditions */
503 if (update
) clk_msg
= *msg
;
507 /* Note: windows has no concept of a non-client wheel message */
508 if (hittest
!= HTCLIENT
&& msg
->message
!= WM_MOUSEWHEEL
)
510 msg
->message
+= WM_NCMOUSEMOVE
- WM_MOUSEMOVE
;
511 msg
->wParam
= hittest
;
513 else ScreenToClient( msg
->hwnd
, &pt
);
514 msg
->lParam
= MAKELONG( pt
.x
, pt
.y
);
519 /***********************************************************************
520 * process_cooked_mouse_message
522 * returns TRUE if the contents of 'msg' should be passed to the application
524 static BOOL
process_cooked_mouse_message( MSG
*msg
, BOOL remove
)
526 INT hittest
= HTCLIENT
;
527 UINT raw_message
= msg
->message
;
530 if (msg
->message
>= WM_NCMOUSEFIRST
&& msg
->message
<= WM_NCMOUSELAST
)
532 raw_message
+= WM_MOUSEFIRST
- WM_NCMOUSEFIRST
;
533 hittest
= msg
->wParam
;
535 if (raw_message
== WM_LBUTTONDBLCLK
||
536 raw_message
== WM_RBUTTONDBLCLK
||
537 raw_message
== WM_MBUTTONDBLCLK
)
539 raw_message
+= WM_LBUTTONDOWN
- WM_LBUTTONDBLCLK
;
542 if (HOOK_IsHooked( WH_MOUSE
))
544 MOUSEHOOKSTRUCT hook
;
546 hook
.hwnd
= msg
->hwnd
;
547 hook
.wHitTestCode
= hittest
;
548 hook
.dwExtraInfo
= 0;
549 if (HOOK_CallHooksA( WH_MOUSE
, remove
? HC_ACTION
: HC_NOREMOVE
,
550 msg
->message
, (LPARAM
)&hook
))
553 hook
.hwnd
= msg
->hwnd
;
554 hook
.wHitTestCode
= hittest
;
555 hook
.dwExtraInfo
= 0;
556 HOOK_CallHooksA( WH_CBT
, HCBT_CLICKSKIPPED
, msg
->message
, (LPARAM
)&hook
);
561 if ((hittest
== HTERROR
) || (hittest
== HTNOWHERE
))
563 SendMessageA( msg
->hwnd
, WM_SETCURSOR
, msg
->hwnd
, MAKELONG( hittest
, raw_message
));
567 if (!remove
|| GetCapture()) return TRUE
;
571 if ((raw_message
== WM_LBUTTONDOWN
) ||
572 (raw_message
== WM_RBUTTONDOWN
) ||
573 (raw_message
== WM_MBUTTONDOWN
))
575 HWND hwndTop
= WIN_GetTopParent( msg
->hwnd
);
577 /* Send the WM_PARENTNOTIFY,
578 * note that even for double/nonclient clicks
579 * notification message is still WM_L/M/RBUTTONDOWN.
581 MSG_SendParentNotify( msg
->hwnd
, raw_message
, 0, msg
->pt
);
583 /* Activate the window if needed */
585 if (msg
->hwnd
!= GetActiveWindow() && hwndTop
!= GetDesktopWindow())
587 LONG ret
= SendMessageA( msg
->hwnd
, WM_MOUSEACTIVATE
, hwndTop
,
588 MAKELONG( hittest
, raw_message
) );
592 case MA_NOACTIVATEANDEAT
:
597 case MA_ACTIVATEANDEAT
:
601 if (hwndTop
!= GetForegroundWindow() )
603 if (!WINPOS_SetActiveWindow( hwndTop
, TRUE
, TRUE
))
608 WARN( "unknown WM_MOUSEACTIVATE code %ld\n", ret
);
614 /* send the WM_SETCURSOR message */
616 /* Windows sends the normal mouse message as the message parameter
617 in the WM_SETCURSOR message even if it's non-client mouse message */
618 SendMessageA( msg
->hwnd
, WM_SETCURSOR
, msg
->hwnd
, MAKELONG( hittest
, raw_message
));
624 /***********************************************************************
625 * process_hardware_message
627 * returns TRUE if the contents of 'msg' should be passed to the application
629 static BOOL
process_raw_hardware_message( MSG
*msg
, ULONG_PTR extra_info
, HWND hwnd_filter
,
630 UINT first
, UINT last
, BOOL remove
)
632 if (is_keyboard_message( msg
->message
))
634 if (!process_raw_keyboard_message( msg
, extra_info
)) return FALSE
;
636 else if (is_mouse_message( msg
->message
))
638 if (!process_raw_mouse_message( msg
, extra_info
)) return FALSE
;
642 ERR( "unknown message type %x\n", msg
->message
);
646 /* check destination thread and filters */
647 if (!check_message_filter( msg
, hwnd_filter
, first
, last
) ||
648 GetWindowThreadProcessId( msg
->hwnd
, NULL
) != GetCurrentThreadId())
650 /* queue it for later, or for another thread */
651 queue_hardware_message( msg
, extra_info
, COOKED_HW_MESSAGE
);
655 /* save the message in the cooked queue if we didn't want to remove it */
656 if (!remove
) queue_hardware_message( msg
, extra_info
, COOKED_HW_MESSAGE
);
661 /***********************************************************************
662 * process_cooked_hardware_message
664 * returns TRUE if the contents of 'msg' should be passed to the application
666 static BOOL
process_cooked_hardware_message( MSG
*msg
, BOOL remove
)
668 if (is_keyboard_message( msg
->message
))
669 return process_cooked_keyboard_message( msg
, remove
);
671 if (is_mouse_message( msg
->message
))
672 return process_cooked_mouse_message( msg
, remove
);
674 ERR( "unknown message type %x\n", msg
->message
);
679 /***********************************************************************
680 * handle_sent_message
682 * Handle the reception of a sent message by calling the corresponding window proc
684 static void handle_sent_message( MSG
*msg
, int type
, ULONG_PTR extra_info
)
687 MESSAGEQUEUE
*queue
= QUEUE_Lock( GetFastQueue16() );
688 ULONG_PTR old_extra_info
= queue
->GetMessageExtraInfoVal
; /* save ExtraInfo */
689 WND
*wndPtr
= WIN_FindWndPtr( msg
->hwnd
);
691 TRACE( "got hwnd %x msg %x (%s) wp %x lp %lx\n",
692 msg
->hwnd
, msg
->message
, SPY_GetMsgName(msg
->message
),
693 msg
->wParam
, msg
->lParam
);
695 queue
->GetMessageExtraInfoVal
= extra_info
;
697 /* call the right version of CallWindowProcXX */
701 result
= CallWindowProc16( (WNDPROC16
)wndPtr
->winproc
,
703 (UINT16
) msg
->message
,
708 result
= CallWindowProcA( wndPtr
->winproc
, msg
->hwnd
, msg
->message
,
709 msg
->wParam
, msg
->lParam
);
712 result
= CallWindowProcW( wndPtr
->winproc
, msg
->hwnd
, msg
->message
,
713 msg
->wParam
, msg
->lParam
);
717 queue
->GetMessageExtraInfoVal
= old_extra_info
; /* Restore extra info */
718 WIN_ReleaseWndPtr(wndPtr
);
719 QUEUE_Unlock( queue
);
721 SERVER_START_REQ( reply_message
)
723 req
->result
= result
;
731 /***********************************************************************
732 * process_sent_messages
734 * Process all pending sent messages
736 static void process_sent_messages(void)
741 ULONG_PTR extra_info
;
745 SERVER_START_REQ( get_message
)
747 req
->flags
= GET_MSG_REMOVE
| GET_MSG_SENT_ONLY
;
751 if (!(res
= SERVER_CALL()))
755 msg
.message
= req
->msg
;
756 msg
.wParam
= req
->wparam
;
757 msg
.lParam
= req
->lparam
;
758 msg
.time
= req
->time
;
761 extra_info
= req
->info
;
767 handle_sent_message( &msg
, type
, extra_info
);
773 /***********************************************************************
776 * Peek for a message matching the given parameters. Return FALSE if none available.
778 static BOOL
peek_message( HWND hwnd
, UINT first
, UINT last
, int flags
, int type
,
779 MSG
*msg
, ULONG_PTR
*extra_info
)
782 enum message_kind kind
;
785 if (!first
&& !last
) last
= ~0;
789 SERVER_START_REQ( get_message
)
793 req
->get_first
= first
;
794 req
->get_last
= last
;
795 if ((ret
= !SERVER_CALL()))
798 msg_type
= req
->type
;
799 msg
->hwnd
= req
->win
;
800 msg
->message
= req
->msg
;
801 msg
->wParam
= req
->wparam
;
802 msg
->lParam
= req
->lparam
;
803 msg
->time
= req
->time
;
806 *extra_info
= req
->info
;
811 if (!ret
) return FALSE
;
816 handle_sent_message( msg
, msg_type
, *extra_info
);
819 /* try to convert message to requested type */
820 if (!MSG_ConvertMsg( msg
, msg_type
, type
))
822 ERR( "Message %s of wrong type contains pointer parameters. Skipped!\n",
823 SPY_GetMsgName(msg
->message
));
825 flags
|= GET_MSG_REMOVE_LAST
;
830 if (!process_raw_hardware_message( msg
, *extra_info
,
831 hwnd
, first
, last
, flags
& GET_MSG_REMOVE
))
834 case COOKED_HW_MESSAGE
:
835 if (!process_cooked_hardware_message( msg
, flags
& GET_MSG_REMOVE
))
837 flags
|= GET_MSG_REMOVE_LAST
;
843 /* now we got something */
844 TRACE( "got hwnd %x msg %x (%s) wp %x lp %lx\n",
845 msg
->hwnd
, msg
->message
, SPY_GetMsgName(msg
->message
),
846 msg
->wParam
, msg
->lParam
);
852 /***********************************************************************
855 * See "Windows Internals", p.447
858 * 0 if exit with timeout
861 static int wait_queue_bits( WORD bits
, DWORD timeout
)
866 TRACE_(msg
)("q %04x waiting for %04x\n", GetFastQueue16(), bits
);
868 hQueue
= GetFastQueue16();
869 if (!(queue
= QUEUE_Lock( hQueue
))) return 0;
873 unsigned int wake_bits
= 0, changed_bits
= 0;
876 SERVER_START_REQ( set_queue_mask
)
878 req
->wake_mask
= QS_SENDMESSAGE
;
879 req
->changed_mask
= bits
| QS_SENDMESSAGE
;
883 wake_bits
= req
->wake_bits
;
884 changed_bits
= req
->changed_bits
;
889 if (changed_bits
& bits
)
891 /* One of the bits is set; we can return */
892 QUEUE_Unlock( queue
);
895 if (wake_bits
& QS_SENDMESSAGE
)
897 /* Process the sent message immediately */
898 process_sent_messages();
899 continue; /* nested sm crux */
902 TRACE_(msg
)("(%04x) mask=%08x, bits=%08x, changed=%08x, waiting\n",
903 queue
->self
, bits
, wake_bits
, changed_bits
);
905 ReleaseThunkLock( &dwlc
);
906 if (dwlc
) TRACE_(msg
)("had win16 lock\n");
908 if (USER_Driver
.pMsgWaitForMultipleObjectsEx
)
909 USER_Driver
.pMsgWaitForMultipleObjectsEx( 1, &queue
->server_queue
, timeout
, 0, 0 );
911 WaitForSingleObject( queue
->server_queue
, timeout
);
912 if (dwlc
) RestoreThunkLock( dwlc
);
917 /**********************************************************************
918 * SetDoubleClickTime (USER.20)
920 void WINAPI
SetDoubleClickTime16( UINT16 interval
)
922 SetDoubleClickTime( interval
);
926 /**********************************************************************
927 * SetDoubleClickTime (USER32.@)
929 BOOL WINAPI
SetDoubleClickTime( UINT interval
)
931 doubleClickSpeed
= interval
? interval
: 500;
936 /**********************************************************************
937 * GetDoubleClickTime (USER.21)
939 UINT16 WINAPI
GetDoubleClickTime16(void)
941 return doubleClickSpeed
;
945 /**********************************************************************
946 * GetDoubleClickTime (USER32.@)
948 UINT WINAPI
GetDoubleClickTime(void)
950 return doubleClickSpeed
;
954 /***********************************************************************
955 * MSG_SendMessageInterThread
957 * Implementation of an inter-task SendMessage.
959 * 0 if error or timeout
962 static LRESULT
MSG_SendMessageInterThread( DWORD dest_tid
, HWND hwnd
, UINT msg
,
963 WPARAM wParam
, LPARAM lParam
,
964 DWORD timeout
, WORD type
,
971 TRACE( "hwnd %x msg %x (%s) wp %x lp %lx\n", hwnd
, msg
, SPY_GetMsgName(msg
), wParam
, lParam
);
973 SERVER_START_REQ( send_message
)
975 req
->kind
= SEND_MESSAGE
;
976 req
->id
= (void *)dest_tid
;
980 req
->wparam
= wParam
;
981 req
->lparam
= lParam
;
984 req
->time
= GetCurrentTime();
986 ret
= !SERVER_CALL_ERR();
991 iWndsLocks
= WIN_SuspendWndsLock();
993 /* wait for the result */
994 wait_queue_bits( QS_SMRESULT
, timeout
);
996 SERVER_START_REQ( get_message_reply
)
999 if ((ret
= !SERVER_CALL_ERR())) result
= req
->result
;
1003 TRACE( "hwnd %x msg %x (%s) wp %x lp %lx got reply %lx (err=%ld)\n",
1004 hwnd
, msg
, SPY_GetMsgName(msg
), wParam
, lParam
, result
, GetLastError() );
1006 if (!ret
&& (GetLastError() == ERROR_IO_PENDING
))
1008 if (timeout
== INFINITE
) ERR("no timeout but no result\n");
1009 SetLastError(0); /* timeout */
1012 if (pRes
) *pRes
= result
;
1014 WIN_RestoreWndsLock(iWndsLocks
);
1019 /***********************************************************************
1020 * ReplyMessage (USER.115)
1022 void WINAPI
ReplyMessage16( LRESULT result
)
1024 ReplyMessage( result
);
1027 /***********************************************************************
1028 * ReplyMessage (USER32.@)
1030 BOOL WINAPI
ReplyMessage( LRESULT result
)
1033 SERVER_START_REQ( reply_message
)
1035 req
->result
= result
;
1037 ret
= !SERVER_CALL_ERR();
1043 /***********************************************************************
1046 static BOOL
MSG_ConvertMsg( MSG
*msg
, int srcType
, int dstType
)
1048 if (srcType
== QMSG_WIN32A
|| dstType
== QMSG_WIN32A
)
1050 /* posted messages are always either Win16 or Unicode Win32,
1051 * QMSG_WIN32A is only for sent messages */
1052 ERR( "invalid type %d/%d\n", srcType
, dstType
);
1056 if (!srcType
|| srcType
== dstType
) return TRUE
;
1058 if (srcType
== QMSG_WIN16
)
1060 if (dstType
== QMSG_WIN32W
)
1062 switch ( WINPROC_MapMsg16To32W( msg
->hwnd
, msg
->message
, msg
->wParam
,
1063 &msg
->message
, &msg
->wParam
, &msg
->lParam
) )
1068 /* Pointer messages were mapped --> need to free allocated memory and fail */
1069 WINPROC_UnmapMsg16To32W( msg
->hwnd
, msg
->message
, msg
->wParam
, msg
->lParam
, 0 );
1075 else if (srcType
== QMSG_WIN32W
)
1077 if (dstType
== QMSG_WIN16
)
1082 mp16
.lParam
= msg
->lParam
;
1083 switch ( WINPROC_MapMsg32WTo16( msg
->hwnd
, msg
->message
, msg
->wParam
,
1084 &msg16
, &mp16
.wParam
, &mp16
.lParam
) )
1087 msg
->message
= msg16
;
1088 msg
->wParam
= mp16
.wParam
;
1089 msg
->lParam
= mp16
.lParam
;
1092 /* Pointer messages were mapped --> need to free allocated memory and fail */
1093 WINPROC_UnmapMsg32WTo16( msg
->hwnd
, msg
->message
, msg
->wParam
, msg
->lParam
, &mp16
);
1100 FIXME( "Invalid message type(s): %d / %d\n", srcType
, dstType
);
1105 /***********************************************************************
1108 static BOOL
MSG_PeekMessage( int type
, LPMSG msg_out
, HWND hwnd
,
1109 DWORD first
, DWORD last
, WORD flags
, BOOL peek
)
1111 int mask
, msg_flags
= 0;
1112 MESSAGEQUEUE
*msgQueue
;
1115 ULONG_PTR extra_info
;
1117 mask
= QS_POSTMESSAGE
| QS_SENDMESSAGE
; /* Always selected */
1120 if ((first
<= WM_KEYLAST
) && (last
>= WM_KEYFIRST
)) mask
|= QS_KEY
;
1121 if ( ((first
<= WM_MOUSELAST
) && (last
>= WM_MOUSEFIRST
)) ||
1122 ((first
<= WM_NCMOUSELAST
) && (last
>= WM_NCMOUSEFIRST
)) ) mask
|= QS_MOUSE
;
1123 if ((first
<= WM_TIMER
) && (last
>= WM_TIMER
)) mask
|= QS_TIMER
;
1124 if ((first
<= WM_SYSTIMER
) && (last
>= WM_SYSTIMER
)) mask
|= QS_TIMER
;
1125 if ((first
<= WM_PAINT
) && (last
>= WM_PAINT
)) mask
|= QS_PAINT
;
1127 else mask
|= QS_MOUSE
| QS_KEY
| QS_TIMER
| QS_PAINT
;
1129 if (IsTaskLocked16()) flags
|= PM_NOYIELD
;
1131 iWndsLocks
= WIN_SuspendWndsLock();
1133 /* check for graphics events */
1134 if (USER_Driver
.pMsgWaitForMultipleObjectsEx
)
1135 USER_Driver
.pMsgWaitForMultipleObjectsEx( 0, NULL
, 0, 0, 0 );
1137 if (flags
& PM_REMOVE
) msg_flags
|= GET_MSG_REMOVE
;
1141 if (peek_message( hwnd
, first
, last
, msg_flags
, type
, &msg
, &extra_info
))
1143 /* need to fill the window handle for WM_PAINT message */
1144 if (msg
.message
== WM_PAINT
)
1146 if ((msg
.hwnd
= WIN_FindWinToRepaint( hwnd
)))
1148 if (IsIconic( msg
.hwnd
) && GetClassLongA( msg
.hwnd
, GCL_HICON
))
1150 msg
.message
= WM_PAINTICON
;
1153 if( !hwnd
|| msg
.hwnd
== hwnd
|| IsChild(hwnd
,msg
.hwnd
) )
1155 /* clear internal paint flag */
1156 RedrawWindow( msg
.hwnd
, NULL
, 0,
1157 RDW_NOINTERNALPAINT
| RDW_NOCHILDREN
);
1165 /* FIXME: should be done before checking for hw events */
1166 MSG_JournalPlayBackMsg();
1171 if (!(flags
& PM_NOYIELD
)) UserYield16();
1173 WIN_RestoreWndsLock(iWndsLocks
);
1177 wait_queue_bits( mask
, INFINITE
);
1180 WIN_RestoreWndsLock(iWndsLocks
);
1182 if ((msgQueue
= QUEUE_Lock( GetFastQueue16() )))
1184 msgQueue
->GetMessageTimeVal
= msg
.time
;
1185 msgQueue
->GetMessagePosVal
= MAKELONG( msg
.pt
.x
, msg
.pt
.y
);
1186 msgQueue
->GetMessageExtraInfoVal
= extra_info
;
1187 QUEUE_Unlock( msgQueue
);
1190 /* We got a message */
1191 if (flags
& PM_REMOVE
)
1193 if (msg
.message
== WM_KEYDOWN
|| msg
.message
== WM_SYSKEYDOWN
)
1195 BYTE
*p
= &QueueKeyStateTable
[msg
.wParam
& 0xff];
1201 else if (msg
.message
== WM_KEYUP
|| msg
.message
== WM_SYSKEYUP
)
1202 QueueKeyStateTable
[msg
.wParam
& 0xff] &= ~0x80;
1205 /* copy back our internal safe copy of message data to msg_out.
1206 * msg_out is a variable from the *program*, so it can't be used
1207 * internally as it can get "corrupted" by our use of SendMessage()
1208 * (back to the program) inside the message handling itself. */
1214 return (msg
.message
!= WM_QUIT
);
1217 /***********************************************************************
1218 * MSG_InternalGetMessage
1220 * GetMessage() function for internal use. Behave like GetMessage(),
1221 * but also call message filters and optionally send WM_ENTERIDLE messages.
1222 * 'hwnd' must be the handle of the dialog or menu window.
1223 * 'code' is the message filter value (MSGF_??? codes).
1225 BOOL
MSG_InternalGetMessage( MSG
*msg
, HWND hwnd
, HWND hwndOwner
, UINT first
, UINT last
,
1226 WPARAM code
, WORD flags
, BOOL sendIdle
, BOOL
* idleSent
)
1232 if (!MSG_PeekMessage( QMSG_WIN32W
, msg
, 0, first
, last
, flags
, TRUE
))
1234 /* No message present -> send ENTERIDLE and wait */
1235 if (IsWindow(hwndOwner
))
1237 SendMessageA( hwndOwner
, WM_ENTERIDLE
,
1238 code
, (LPARAM
)hwnd
);
1243 MSG_PeekMessage( QMSG_WIN32W
, msg
, 0, first
, last
, flags
, FALSE
);
1246 else /* Always wait for a message */
1247 MSG_PeekMessage( QMSG_WIN32W
, msg
, 0, first
, last
, flags
, FALSE
);
1249 /* Call message filters */
1251 if (HOOK_IsHooked( WH_SYSMSGFILTER
) || HOOK_IsHooked( WH_MSGFILTER
))
1255 if (HOOK_CallHooksW( WH_SYSMSGFILTER
, code
, 0, (LPARAM
)&tmp_msg
) ||
1256 HOOK_CallHooksW( WH_MSGFILTER
, code
, 0, (LPARAM
)&tmp_msg
))
1258 /* Message filtered -> remove it from the queue if it's still there. */
1259 if (!(flags
& PM_REMOVE
))
1260 MSG_PeekMessage( QMSG_WIN32W
, msg
, 0, first
, last
, PM_REMOVE
, TRUE
);
1264 /* need to return an ASCII message (FIXME) */
1265 msg
->wParam
= map_wparam_WtoA( msg
->message
, msg
->wParam
);
1266 return (msg
->message
!= WM_QUIT
);
1271 /***********************************************************************
1272 * PeekMessage32 (USER.819)
1274 BOOL16 WINAPI
PeekMessage32_16( SEGPTR msg16_32
, HWND16 hwnd
,
1275 UINT16 first
, UINT16 last
, UINT16 flags
,
1276 BOOL16 wHaveParamHigh
)
1279 MSG32_16
*lpmsg16_32
= MapSL(msg16_32
);
1282 ret
= MSG_PeekMessage( QMSG_WIN16
, &msg
, hwnd
, first
, last
, flags
, TRUE
);
1284 lpmsg16_32
->msg
.hwnd
= msg
.hwnd
;
1285 lpmsg16_32
->msg
.message
= msg
.message
;
1286 lpmsg16_32
->msg
.wParam
= LOWORD(msg
.wParam
);
1287 lpmsg16_32
->msg
.lParam
= msg
.lParam
;
1288 lpmsg16_32
->msg
.time
= msg
.time
;
1289 lpmsg16_32
->msg
.pt
.x
= (INT16
)msg
.pt
.x
;
1290 lpmsg16_32
->msg
.pt
.y
= (INT16
)msg
.pt
.y
;
1292 if ( wHaveParamHigh
)
1293 lpmsg16_32
->wParamHigh
= HIWORD(msg
.wParam
);
1295 HOOK_CallHooks16( WH_GETMESSAGE
, HC_ACTION
, flags
& PM_REMOVE
, (LPARAM
)msg16_32
);
1299 /***********************************************************************
1300 * PeekMessage (USER.109)
1302 BOOL16 WINAPI
PeekMessage16( SEGPTR msg
, HWND16 hwnd
,
1303 UINT16 first
, UINT16 last
, UINT16 flags
)
1305 return PeekMessage32_16( msg
, hwnd
, first
, last
, flags
, FALSE
);
1308 /***********************************************************************
1309 * PeekMessageA (USER32.@)
1311 BOOL WINAPI
PeekMessageA( LPMSG lpmsg
, HWND hwnd
, UINT min
, UINT max
, UINT flags
)
1313 BOOL ret
= PeekMessageW( lpmsg
, hwnd
, min
, max
, flags
);
1314 if (ret
) lpmsg
->wParam
= map_wparam_WtoA( lpmsg
->message
, lpmsg
->wParam
);
1318 /***********************************************************************
1319 * PeekMessageW (USER32.@) Check queue for messages
1321 * Checks for a message in the thread's queue, filtered as for
1322 * GetMessage(). Returns immediately whether a message is available
1325 * Whether a retrieved message is removed from the queue is set by the
1326 * _wRemoveMsg_ flags, which should be one of the following values:
1328 * PM_NOREMOVE Do not remove the message from the queue.
1330 * PM_REMOVE Remove the message from the queue.
1332 * In addition, PM_NOYIELD may be combined into _wRemoveMsg_ to
1333 * request that the system not yield control during PeekMessage();
1334 * however applications may not rely on scheduling behavior.
1338 * Nonzero if a message is available and is retrieved, zero otherwise.
1345 BOOL WINAPI
PeekMessageW(
1346 LPMSG lpmsg
, /* [out] buffer to receive message */
1347 HWND hwnd
, /* [in] restrict to messages for hwnd */
1348 UINT min
, /* [in] minimum message to receive */
1349 UINT max
, /* [in] maximum message to receive */
1350 UINT wRemoveMsg
/* [in] removal flags */
1353 BOOL ret
= MSG_PeekMessage( QMSG_WIN32W
, lpmsg
, hwnd
, min
, max
, wRemoveMsg
, TRUE
);
1354 if (ret
) HOOK_CallHooksW( WH_GETMESSAGE
, HC_ACTION
,
1355 wRemoveMsg
& PM_REMOVE
, (LPARAM
)lpmsg
);
1360 /***********************************************************************
1361 * GetMessage32 (USER.820)
1363 BOOL16 WINAPI
GetMessage32_16( SEGPTR msg16_32
, HWND16 hWnd
, UINT16 first
,
1364 UINT16 last
, BOOL16 wHaveParamHigh
)
1366 MSG32_16
*lpmsg16_32
= MapSL(msg16_32
);
1369 MSG_PeekMessage( QMSG_WIN16
, &msg
, hWnd
, first
, last
, PM_REMOVE
, FALSE
);
1371 lpmsg16_32
->msg
.hwnd
= msg
.hwnd
;
1372 lpmsg16_32
->msg
.message
= msg
.message
;
1373 lpmsg16_32
->msg
.wParam
= LOWORD(msg
.wParam
);
1374 lpmsg16_32
->msg
.lParam
= msg
.lParam
;
1375 lpmsg16_32
->msg
.time
= msg
.time
;
1376 lpmsg16_32
->msg
.pt
.x
= (INT16
)msg
.pt
.x
;
1377 lpmsg16_32
->msg
.pt
.y
= (INT16
)msg
.pt
.y
;
1379 if ( wHaveParamHigh
)
1380 lpmsg16_32
->wParamHigh
= HIWORD(msg
.wParam
);
1382 TRACE( "message %04x, hwnd %04x, filter(%04x - %04x)\n",
1383 lpmsg16_32
->msg
.message
, hWnd
, first
, last
);
1385 HOOK_CallHooks16( WH_GETMESSAGE
, HC_ACTION
, PM_REMOVE
, (LPARAM
)msg16_32
);
1386 return lpmsg16_32
->msg
.message
!= WM_QUIT
;
1389 /***********************************************************************
1390 * GetMessage (USER.108)
1392 BOOL16 WINAPI
GetMessage16( SEGPTR msg
, HWND16 hwnd
, UINT16 first
, UINT16 last
)
1394 return GetMessage32_16( msg
, hwnd
, first
, last
, FALSE
);
1397 /***********************************************************************
1398 * GetMessageA (USER32.@)
1400 BOOL WINAPI
GetMessageA( MSG
*lpmsg
, HWND hwnd
, UINT min
, UINT max
)
1402 GetMessageW( lpmsg
, hwnd
, min
, max
);
1403 lpmsg
->wParam
= map_wparam_WtoA( lpmsg
->message
, lpmsg
->wParam
);
1404 return lpmsg
->message
!= WM_QUIT
;
1407 /***********************************************************************
1408 * GetMessageW (USER32.@) Retrieve next message
1410 * GetMessage retrieves the next event from the calling thread's
1411 * queue and deposits it in *lpmsg.
1413 * If _hwnd_ is not NULL, only messages for window _hwnd_ and its
1414 * children as specified by IsChild() are retrieved. If _hwnd_ is NULL
1415 * all application messages are retrieved.
1417 * _min_ and _max_ specify the range of messages of interest. If
1418 * min==max==0, no filtering is performed. Useful examples are
1419 * WM_KEYFIRST and WM_KEYLAST to retrieve keyboard input, and
1420 * WM_MOUSEFIRST and WM_MOUSELAST to retrieve mouse input.
1422 * WM_PAINT messages are not removed from the queue; they remain until
1423 * processed. Other messages are removed from the queue.
1427 * -1 on error, 0 if message is WM_QUIT, nonzero otherwise.
1434 BOOL WINAPI
GetMessageW(
1435 MSG
* lpmsg
, /* [out] buffer to receive message */
1436 HWND hwnd
, /* [in] restrict to messages for hwnd */
1437 UINT min
, /* [in] minimum message to receive */
1438 UINT max
/* [in] maximum message to receive */
1441 MSG_PeekMessage( QMSG_WIN32W
, lpmsg
, hwnd
, min
, max
, PM_REMOVE
, FALSE
);
1443 TRACE( "message %04x, hwnd %04x, filter(%04x - %04x)\n",
1444 lpmsg
->message
, hwnd
, min
, max
);
1446 HOOK_CallHooksW( WH_GETMESSAGE
, HC_ACTION
, PM_REMOVE
, (LPARAM
)lpmsg
);
1447 return lpmsg
->message
!= WM_QUIT
;
1450 /***********************************************************************
1453 static BOOL
MSG_PostToQueue( DWORD tid
, int type
, HWND hwnd
,
1454 UINT message
, WPARAM wParam
, LPARAM lParam
)
1458 TRACE( "posting %x %x (%s) %x %lx\n", hwnd
, message
, SPY_GetMsgName(message
), wParam
, lParam
);
1460 SERVER_START_REQ( send_message
)
1462 req
->kind
= POST_MESSAGE
;
1463 req
->id
= (void *)tid
;
1467 req
->wparam
= wParam
;
1468 req
->lparam
= lParam
;
1471 req
->time
= GetCurrentTime();
1473 res
= SERVER_CALL();
1479 if (res
== STATUS_INVALID_PARAMETER
)
1480 SetLastError( ERROR_INVALID_THREAD_ID
);
1482 SetLastError( RtlNtStatusToDosError(res
) );
1488 /***********************************************************************
1491 static BOOL
MSG_PostMessage( int type
, HWND hwnd
, UINT message
,
1492 WPARAM wParam
, LPARAM lParam
)
1496 if (hwnd
== HWND_BROADCAST
)
1498 WND
*pDesktop
= WIN_GetDesktop();
1499 TRACE("HWND_BROADCAST !\n");
1501 for (wndPtr
=WIN_LockWndPtr(pDesktop
->child
); wndPtr
; WIN_UpdateWndPtr(&wndPtr
,wndPtr
->next
))
1503 if (wndPtr
->dwStyle
& WS_POPUP
|| wndPtr
->dwStyle
& WS_CAPTION
)
1505 TRACE("BROADCAST Message to hWnd=%04x m=%04X w=%04X l=%08lX !\n",
1506 wndPtr
->hwndSelf
, message
, wParam
, lParam
);
1507 MSG_PostToQueue( GetWindowThreadProcessId( wndPtr
->hwndSelf
, NULL
), type
,
1508 wndPtr
->hwndSelf
, message
, wParam
, lParam
);
1511 WIN_ReleaseDesktop();
1512 TRACE("End of HWND_BROADCAST !\n");
1516 return MSG_PostToQueue( GetWindowThreadProcessId( hwnd
, NULL
),
1517 type
, hwnd
, message
, wParam
, lParam
);
1521 /***********************************************************************
1522 * PostMessage (USER.110)
1524 BOOL16 WINAPI
PostMessage16( HWND16 hwnd
, UINT16 message
, WPARAM16 wParam
,
1527 return (BOOL16
) MSG_PostMessage( QMSG_WIN16
, hwnd
, message
, wParam
, lParam
);
1530 /***********************************************************************
1531 * PostMessageA (USER32.@)
1533 BOOL WINAPI
PostMessageA( HWND hwnd
, UINT message
, WPARAM wParam
,
1536 return PostMessageW( hwnd
, message
, map_wparam_AtoW( message
, wParam
), lParam
);
1539 /***********************************************************************
1540 * PostMessageW (USER32.@)
1542 BOOL WINAPI
PostMessageW( HWND hwnd
, UINT message
, WPARAM wParam
,
1545 /* See thread on wine-devel around 6.2.2001. Basically posted messages
1546 * that are known to contain pointers are dropped by the Windows 32bit
1547 * PostMessage() with return FALSE; and invalid parameter last error.
1548 * (tested against NT4 by Gerard Patel)
1550 if (is_pointer_message(message
))
1552 SetLastError(ERROR_INVALID_PARAMETER
);
1555 return MSG_PostMessage( QMSG_WIN32W
, hwnd
, message
, wParam
, lParam
);
1558 /***********************************************************************
1559 * PostAppMessage (USER.116)
1560 * PostAppMessage16 (USER32.@)
1562 BOOL16 WINAPI
PostAppMessage16( HTASK16 hTask
, UINT16 message
,
1563 WPARAM16 wParam
, LPARAM lParam
)
1565 TDB
*pTask
= TASK_GetPtr( hTask
);
1566 if (!pTask
) return FALSE
;
1567 return MSG_PostToQueue( (DWORD
)pTask
->teb
->tid
, QMSG_WIN16
, 0, message
, wParam
, lParam
);
1570 /**********************************************************************
1571 * PostThreadMessageA (USER32.@)
1573 BOOL WINAPI
PostThreadMessageA( DWORD idThread
, UINT message
,
1574 WPARAM wParam
, LPARAM lParam
)
1576 return PostThreadMessageW( idThread
, message
, map_wparam_AtoW( message
, wParam
), lParam
);
1579 /**********************************************************************
1580 * PostThreadMessageW (USER32.@)
1582 BOOL WINAPI
PostThreadMessageW( DWORD idThread
, UINT message
,
1583 WPARAM wParam
, LPARAM lParam
)
1585 if (is_pointer_message( message
))
1587 SetLastError( ERROR_INVALID_PARAMETER
);
1590 return MSG_PostToQueue( idThread
, QMSG_WIN32W
, 0, message
, wParam
, lParam
);
1594 /************************************************************************
1595 * MSG_CallWndProcHook32
1597 static void MSG_CallWndProcHook( LPMSG pmsg
, BOOL bUnicode
)
1601 cwp
.lParam
= pmsg
->lParam
;
1602 cwp
.wParam
= pmsg
->wParam
;
1603 cwp
.message
= pmsg
->message
;
1604 cwp
.hwnd
= pmsg
->hwnd
;
1606 if (bUnicode
) HOOK_CallHooksW(WH_CALLWNDPROC
, HC_ACTION
, 1, (LPARAM
)&cwp
);
1607 else HOOK_CallHooksA( WH_CALLWNDPROC
, HC_ACTION
, 1, (LPARAM
)&cwp
);
1609 pmsg
->lParam
= cwp
.lParam
;
1610 pmsg
->wParam
= cwp
.wParam
;
1611 pmsg
->message
= cwp
.message
;
1612 pmsg
->hwnd
= cwp
.hwnd
;
1616 /***********************************************************************
1619 * return values: 0 if timeout occurs
1622 static LRESULT
MSG_SendMessage( HWND hwnd
, UINT msg
, WPARAM wParam
,
1623 LPARAM lParam
, DWORD timeout
, WORD type
,
1627 WND
**list
, **ppWnd
;
1632 if (pRes
) *pRes
= 0;
1634 if (hwnd
== HWND_BROADCAST
|| hwnd
== HWND_TOPMOST
)
1636 if (pRes
) *pRes
= 1;
1638 if (!(list
= WIN_BuildWinArray( WIN_GetDesktop(), 0, NULL
)))
1640 WIN_ReleaseDesktop();
1643 WIN_ReleaseDesktop();
1645 TRACE("HWND_BROADCAST !\n");
1646 for (ppWnd
= list
; *ppWnd
; ppWnd
++)
1648 WIN_UpdateWndPtr(&wndPtr
,*ppWnd
);
1649 if (!IsWindow(wndPtr
->hwndSelf
)) continue;
1650 if (wndPtr
->dwStyle
& WS_POPUP
|| wndPtr
->dwStyle
& WS_CAPTION
)
1652 TRACE("BROADCAST Message to hWnd=%04x m=%04X w=%04lX l=%08lX !\n",
1653 wndPtr
->hwndSelf
, msg
, (DWORD
)wParam
, lParam
);
1654 MSG_SendMessage( wndPtr
->hwndSelf
, msg
, wParam
, lParam
,
1655 timeout
, type
, pRes
);
1658 WIN_ReleaseWndPtr(wndPtr
);
1659 WIN_ReleaseWinArray(list
);
1660 TRACE("End of HWND_BROADCAST !\n");
1664 if (HOOK_IsHooked( WH_CALLWNDPROC
))
1672 if ((pmsg
= SEGPTR_NEW(CWPSTRUCT16
)))
1674 pmsg
->hwnd
= hwnd
& 0xffff;
1675 pmsg
->message
= msg
& 0xffff;
1676 pmsg
->wParam
= wParam
& 0xffff;
1677 pmsg
->lParam
= lParam
;
1678 HOOK_CallHooks16( WH_CALLWNDPROC
, HC_ACTION
, 1,
1679 (LPARAM
)SEGPTR_GET(pmsg
) );
1681 msg
= pmsg
->message
;
1682 wParam
= pmsg
->wParam
;
1683 lParam
= pmsg
->lParam
;
1684 SEGPTR_FREE( pmsg
);
1689 MSG_CallWndProcHook( (LPMSG
)&hwnd
, FALSE
);
1692 MSG_CallWndProcHook( (LPMSG
)&hwnd
, TRUE
);
1697 if (!(wndPtr
= WIN_FindWndPtr( hwnd
)))
1699 WARN("invalid hwnd %04x\n", hwnd
);
1702 if (QUEUE_IsExitingQueue(wndPtr
->hmemTaskQ
))
1704 WIN_ReleaseWndPtr( wndPtr
);
1705 return 0; /* Don't send anything if the task is dying */
1707 winproc
= (WNDPROC
)wndPtr
->winproc
;
1708 WIN_ReleaseWndPtr( wndPtr
);
1710 if (type
!= QMSG_WIN16
)
1711 SPY_EnterMessage( SPY_SENDMESSAGE
, hwnd
, msg
, wParam
, lParam
);
1713 SPY_EnterMessage( SPY_SENDMESSAGE16
, hwnd
, msg
, wParam
, lParam
);
1715 dest_tid
= GetWindowThreadProcessId( hwnd
, NULL
);
1716 if (dest_tid
&& dest_tid
!= GetCurrentThreadId())
1718 ret
= MSG_SendMessageInterThread( dest_tid
, hwnd
, msg
,
1719 wParam
, lParam
, timeout
, type
, pRes
);
1725 /* Call the right CallWindowProc flavor */
1729 res
= CallWindowProc16( (WNDPROC16
)winproc
, hwnd
, msg
, wParam
, lParam
);
1732 res
= CallWindowProcA( winproc
, hwnd
, msg
, wParam
, lParam
);
1735 res
= CallWindowProcW( winproc
, hwnd
, msg
, wParam
, lParam
);
1738 if (pRes
) *pRes
= res
;
1741 if (type
!= QMSG_WIN16
)
1742 SPY_ExitMessage( SPY_RESULT_OK
, hwnd
, msg
, pRes
?*pRes
:0, wParam
, lParam
);
1744 SPY_ExitMessage( SPY_RESULT_OK16
, hwnd
, msg
, pRes
?*pRes
:0, wParam
, lParam
);
1750 /***********************************************************************
1751 * SendMessage (USER.111)
1753 LRESULT WINAPI
SendMessage16( HWND16 hwnd
, UINT16 msg
, WPARAM16 wParam
,
1757 MSG_SendMessage(hwnd
, msg
, wParam
, lParam
, INFINITE
, QMSG_WIN16
, &res
);
1762 /***********************************************************************
1763 * SendMessageA (USER32.@)
1765 LRESULT WINAPI
SendMessageA( HWND hwnd
, UINT msg
, WPARAM wParam
,
1770 MSG_SendMessage(hwnd
, msg
, wParam
, lParam
, INFINITE
, QMSG_WIN32A
, &res
);
1776 /***********************************************************************
1777 * SendMessageW (USER32.@) Send Window Message
1779 * Sends a message to the window procedure of the specified window.
1780 * SendMessage() will not return until the called window procedure
1781 * either returns or calls ReplyMessage().
1783 * Use PostMessage() to send message and return immediately. A window
1784 * procedure may use InSendMessage() to detect
1785 * SendMessage()-originated messages.
1787 * Applications which communicate via HWND_BROADCAST may use
1788 * RegisterWindowMessage() to obtain a unique message to avoid conflicts
1789 * with other applications.
1795 LRESULT WINAPI
SendMessageW(
1796 HWND hwnd
, /* [in] Window to send message to. If HWND_BROADCAST,
1797 the message will be sent to all top-level windows. */
1799 UINT msg
, /* [in] message */
1800 WPARAM wParam
, /* [in] message parameter */
1801 LPARAM lParam
/* [in] additional message parameter */
1805 MSG_SendMessage(hwnd
, msg
, wParam
, lParam
, INFINITE
, QMSG_WIN32W
, &res
);
1811 /***********************************************************************
1812 * SendMessageTimeout (not a WINAPI)
1814 LRESULT WINAPI
SendMessageTimeout16( HWND16 hwnd
, UINT16 msg
, WPARAM16 wParam
,
1815 LPARAM lParam
, UINT16 flags
,
1816 UINT16 timeout
, LPWORD resultp
)
1821 /* FIXME: need support for SMTO_BLOCK */
1823 ret
= MSG_SendMessage(hwnd
, msg
, wParam
, lParam
, timeout
, QMSG_WIN16
, &msgRet
);
1824 if (resultp
) *resultp
= (WORD
) msgRet
;
1829 /***********************************************************************
1830 * SendMessageTimeoutA (USER32.@)
1832 LRESULT WINAPI
SendMessageTimeoutA( HWND hwnd
, UINT msg
, WPARAM wParam
,
1833 LPARAM lParam
, UINT flags
,
1834 UINT timeout
, LPDWORD resultp
)
1839 /* FIXME: need support for SMTO_BLOCK */
1841 ret
= MSG_SendMessage(hwnd
, msg
, wParam
, lParam
, timeout
, QMSG_WIN32A
, &msgRet
);
1843 if (resultp
) *resultp
= (DWORD
) msgRet
;
1848 /***********************************************************************
1849 * SendMessageTimeoutW (USER32.@)
1851 LRESULT WINAPI
SendMessageTimeoutW( HWND hwnd
, UINT msg
, WPARAM wParam
,
1852 LPARAM lParam
, UINT flags
,
1853 UINT timeout
, LPDWORD resultp
)
1858 /* FIXME: need support for SMTO_BLOCK */
1860 ret
= MSG_SendMessage(hwnd
, msg
, wParam
, lParam
, timeout
, QMSG_WIN32W
, &msgRet
);
1862 if (resultp
) *resultp
= (DWORD
) msgRet
;
1867 /***********************************************************************
1868 * SendNotifyMessageA (USER32.@)
1870 BOOL WINAPI
SendNotifyMessageA( HWND hwnd
, UINT msg
, WPARAM wParam
, LPARAM lParam
)
1872 return SendNotifyMessageW( hwnd
, msg
, map_wparam_AtoW( msg
, wParam
), lParam
);
1876 /***********************************************************************
1877 * SendNotifyMessageW (USER32.@)
1879 BOOL WINAPI
SendNotifyMessageW( HWND hwnd
, UINT msg
, WPARAM wParam
, LPARAM lParam
)
1881 if (is_pointer_message(msg
))
1883 SetLastError(ERROR_INVALID_PARAMETER
);
1886 return MSG_SendMessage( hwnd
, msg
, wParam
, lParam
, INFINITE
, QMSG_WIN32W
, NULL
);
1890 /***********************************************************************
1891 * SendMessageCallbackA (USER32.@)
1893 BOOL WINAPI
SendMessageCallbackA( HWND hwnd
, UINT msg
, WPARAM wParam
, LPARAM lParam
,
1894 SENDASYNCPROC callback
, ULONG_PTR data
)
1896 return SendMessageCallbackW( hwnd
, msg
, map_wparam_AtoW( msg
, wParam
),
1897 lParam
, callback
, data
);
1901 /***********************************************************************
1902 * SendMessageCallbackW (USER32.@)
1904 * FIXME: It's like PostMessage. The callback gets called when the message
1905 * is processed. We have to modify the message processing for an exact
1907 * The callback is only called when the thread that called us calls one of
1908 * Get/Peek/WaitMessage.
1910 BOOL WINAPI
SendMessageCallbackW( HWND hwnd
, UINT msg
, WPARAM wParam
, LPARAM lParam
,
1911 SENDASYNCPROC callback
, ULONG_PTR data
)
1915 if (is_pointer_message(msg
))
1917 SetLastError(ERROR_INVALID_PARAMETER
);
1920 FIXME( "(0x%04x,0x%04x,0x%08x,0x%08lx,%p,0x%08x),stub!\n",
1921 hwnd
, msg
, wParam
, lParam
, callback
, data
);
1923 if (hwnd
== HWND_BROADCAST
)
1925 PostMessageW( hwnd
, msg
, wParam
, lParam
);
1926 FIXME("Broadcast: Callback will not be called!\n");
1929 result
= SendMessageW( hwnd
, msg
, wParam
, lParam
);
1930 callback( hwnd
, msg
, data
, result
);
1935 /***********************************************************************
1936 * WaitMessage (USER.112) Suspend thread pending messages
1937 * WaitMessage (USER32.@) Suspend thread pending messages
1939 * WaitMessage() suspends a thread until events appear in the thread's
1942 BOOL WINAPI
WaitMessage(void)
1944 return (MsgWaitForMultipleObjectsEx( 0, NULL
, INFINITE
, QS_ALLINPUT
, 0 ) != WAIT_FAILED
);
1948 /***********************************************************************
1949 * MsgWaitForMultipleObjectsEx (USER32.@)
1951 DWORD WINAPI
MsgWaitForMultipleObjectsEx( DWORD count
, CONST HANDLE
*pHandles
,
1952 DWORD timeout
, DWORD mask
, DWORD flags
)
1954 HANDLE handles
[MAXIMUM_WAIT_OBJECTS
];
1956 HQUEUE16 hQueue
= GetFastQueue16();
1957 MESSAGEQUEUE
*msgQueue
;
1959 if (count
> MAXIMUM_WAIT_OBJECTS
-1)
1961 SetLastError( ERROR_INVALID_PARAMETER
);
1965 if (!(msgQueue
= QUEUE_Lock( hQueue
))) return WAIT_FAILED
;
1967 /* set the queue mask */
1968 SERVER_START_REQ( set_queue_mask
)
1970 req
->wake_mask
= (flags
& MWMO_INPUTAVAILABLE
) ? mask
: 0;
1971 req
->changed_mask
= mask
;
1977 /* Add the thread event to the handle list */
1978 for (i
= 0; i
< count
; i
++) handles
[i
] = pHandles
[i
];
1979 handles
[count
] = msgQueue
->server_queue
;
1982 if (USER_Driver
.pMsgWaitForMultipleObjectsEx
)
1984 ret
= USER_Driver
.pMsgWaitForMultipleObjectsEx( count
+1, handles
, timeout
, mask
, flags
);
1985 if (ret
== count
+1) ret
= count
; /* pretend the msg queue is ready */
1988 ret
= WaitForMultipleObjectsEx( count
+1, handles
, flags
& MWMO_WAITALL
,
1989 timeout
, flags
& MWMO_ALERTABLE
);
1990 QUEUE_Unlock( msgQueue
);
1995 /***********************************************************************
1996 * MsgWaitForMultipleObjects (USER32.@)
1998 DWORD WINAPI
MsgWaitForMultipleObjects( DWORD count
, CONST HANDLE
*handles
,
1999 BOOL wait_all
, DWORD timeout
, DWORD mask
)
2001 return MsgWaitForMultipleObjectsEx( count
, handles
, timeout
, mask
,
2002 wait_all
? MWMO_WAITALL
: 0 );
2006 /***********************************************************************
2007 * MsgWaitForMultipleObjects (USER.640)
2009 DWORD WINAPI
MsgWaitForMultipleObjects16( DWORD count
, CONST HANDLE
*handles
,
2010 BOOL wait_all
, DWORD timeout
, DWORD mask
)
2012 return MsgWaitForMultipleObjectsEx( count
, handles
, timeout
, mask
,
2013 wait_all
? MWMO_WAITALL
: 0 );
2017 /***********************************************************************
2018 * WaitForInputIdle (USER32.@)
2020 DWORD WINAPI
WaitForInputIdle( HANDLE hProcess
, DWORD dwTimeOut
)
2022 DWORD cur_time
, ret
;
2023 HANDLE idle_event
= -1;
2025 SERVER_START_REQ( wait_input_idle
)
2027 req
->handle
= hProcess
;
2028 req
->timeout
= dwTimeOut
;
2029 if (!(ret
= SERVER_CALL_ERR())) idle_event
= req
->event
;
2032 if (ret
) return 0xffffffff; /* error */
2033 if (!idle_event
) return 0; /* no event to wait on */
2035 cur_time
= GetTickCount();
2037 TRACE("waiting for %x\n", idle_event
);
2038 while ( dwTimeOut
> GetTickCount() - cur_time
|| dwTimeOut
== INFINITE
)
2040 ret
= MsgWaitForMultipleObjects ( 1, &idle_event
, FALSE
, dwTimeOut
, QS_SENDMESSAGE
);
2041 if ( ret
== ( WAIT_OBJECT_0
+ 1 ))
2043 process_sent_messages();
2046 if ( ret
== WAIT_TIMEOUT
|| ret
== 0xFFFFFFFF )
2048 TRACE("timeout or error\n");
2053 TRACE("finished\n");
2058 return WAIT_TIMEOUT
;
2062 /***********************************************************************
2063 * UserYield (USER.332)
2064 * UserYield16 (USER32.@)
2066 void WINAPI
UserYield16(void)
2068 /* Handle sent messages */
2069 process_sent_messages();
2074 /* Handle sent messages again */
2075 process_sent_messages();
2086 static const struct accent_char accent_chars
[] =
2088 /* A good idea should be to read /usr/X11/lib/X11/locale/iso8859-x/Compose */
2089 {'`', 'A', '\300'}, {'`', 'a', '\340'},
2090 {'\'', 'A', '\301'}, {'\'', 'a', '\341'},
2091 {'^', 'A', '\302'}, {'^', 'a', '\342'},
2092 {'~', 'A', '\303'}, {'~', 'a', '\343'},
2093 {'"', 'A', '\304'}, {'"', 'a', '\344'},
2094 {'O', 'A', '\305'}, {'o', 'a', '\345'},
2095 {'0', 'A', '\305'}, {'0', 'a', '\345'},
2096 {'A', 'A', '\305'}, {'a', 'a', '\345'},
2097 {'A', 'E', '\306'}, {'a', 'e', '\346'},
2098 {',', 'C', '\307'}, {',', 'c', '\347'},
2099 {'`', 'E', '\310'}, {'`', 'e', '\350'},
2100 {'\'', 'E', '\311'}, {'\'', 'e', '\351'},
2101 {'^', 'E', '\312'}, {'^', 'e', '\352'},
2102 {'"', 'E', '\313'}, {'"', 'e', '\353'},
2103 {'`', 'I', '\314'}, {'`', 'i', '\354'},
2104 {'\'', 'I', '\315'}, {'\'', 'i', '\355'},
2105 {'^', 'I', '\316'}, {'^', 'i', '\356'},
2106 {'"', 'I', '\317'}, {'"', 'i', '\357'},
2107 {'-', 'D', '\320'}, {'-', 'd', '\360'},
2108 {'~', 'N', '\321'}, {'~', 'n', '\361'},
2109 {'`', 'O', '\322'}, {'`', 'o', '\362'},
2110 {'\'', 'O', '\323'}, {'\'', 'o', '\363'},
2111 {'^', 'O', '\324'}, {'^', 'o', '\364'},
2112 {'~', 'O', '\325'}, {'~', 'o', '\365'},
2113 {'"', 'O', '\326'}, {'"', 'o', '\366'},
2114 {'/', 'O', '\330'}, {'/', 'o', '\370'},
2115 {'`', 'U', '\331'}, {'`', 'u', '\371'},
2116 {'\'', 'U', '\332'}, {'\'', 'u', '\372'},
2117 {'^', 'U', '\333'}, {'^', 'u', '\373'},
2118 {'"', 'U', '\334'}, {'"', 'u', '\374'},
2119 {'\'', 'Y', '\335'}, {'\'', 'y', '\375'},
2120 {'T', 'H', '\336'}, {'t', 'h', '\376'},
2121 {'s', 's', '\337'}, {'"', 'y', '\377'},
2122 {'s', 'z', '\337'}, {'i', 'j', '\377'},
2123 /* iso-8859-2 uses this */
2124 {'<', 'L', '\245'}, {'<', 'l', '\265'}, /* caron */
2125 {'<', 'S', '\251'}, {'<', 's', '\271'},
2126 {'<', 'T', '\253'}, {'<', 't', '\273'},
2127 {'<', 'Z', '\256'}, {'<', 'z', '\276'},
2128 {'<', 'C', '\310'}, {'<', 'c', '\350'},
2129 {'<', 'E', '\314'}, {'<', 'e', '\354'},
2130 {'<', 'D', '\317'}, {'<', 'd', '\357'},
2131 {'<', 'N', '\322'}, {'<', 'n', '\362'},
2132 {'<', 'R', '\330'}, {'<', 'r', '\370'},
2133 {';', 'A', '\241'}, {';', 'a', '\261'}, /* ogonek */
2134 {';', 'E', '\312'}, {';', 'e', '\332'},
2135 {'\'', 'Z', '\254'}, {'\'', 'z', '\274'}, /* acute */
2136 {'\'', 'R', '\300'}, {'\'', 'r', '\340'},
2137 {'\'', 'L', '\305'}, {'\'', 'l', '\345'},
2138 {'\'', 'C', '\306'}, {'\'', 'c', '\346'},
2139 {'\'', 'N', '\321'}, {'\'', 'n', '\361'},
2140 /* collision whith S, from iso-8859-9 !!! */
2141 {',', 'S', '\252'}, {',', 's', '\272'}, /* cedilla */
2142 {',', 'T', '\336'}, {',', 't', '\376'},
2143 {'.', 'Z', '\257'}, {'.', 'z', '\277'}, /* dot above */
2144 {'/', 'L', '\243'}, {'/', 'l', '\263'}, /* slash */
2145 {'/', 'D', '\320'}, {'/', 'd', '\360'},
2146 {'(', 'A', '\303'}, {'(', 'a', '\343'}, /* breve */
2147 {'\275', 'O', '\325'}, {'\275', 'o', '\365'}, /* double acute */
2148 {'\275', 'U', '\334'}, {'\275', 'u', '\374'},
2149 {'0', 'U', '\332'}, {'0', 'u', '\372'}, /* ring above */
2150 /* iso-8859-3 uses this */
2151 {'/', 'H', '\241'}, {'/', 'h', '\261'}, /* slash */
2152 {'>', 'H', '\246'}, {'>', 'h', '\266'}, /* circumflex */
2153 {'>', 'J', '\254'}, {'>', 'j', '\274'},
2154 {'>', 'C', '\306'}, {'>', 'c', '\346'},
2155 {'>', 'G', '\330'}, {'>', 'g', '\370'},
2156 {'>', 'S', '\336'}, {'>', 's', '\376'},
2157 /* collision whith G( from iso-8859-9 !!! */
2158 {'(', 'G', '\253'}, {'(', 'g', '\273'}, /* breve */
2159 {'(', 'U', '\335'}, {'(', 'u', '\375'},
2160 /* collision whith I. from iso-8859-3 !!! */
2161 {'.', 'I', '\251'}, {'.', 'i', '\271'}, /* dot above */
2162 {'.', 'C', '\305'}, {'.', 'c', '\345'},
2163 {'.', 'G', '\325'}, {'.', 'g', '\365'},
2164 /* iso-8859-4 uses this */
2165 {',', 'R', '\243'}, {',', 'r', '\263'}, /* cedilla */
2166 {',', 'L', '\246'}, {',', 'l', '\266'},
2167 {',', 'G', '\253'}, {',', 'g', '\273'},
2168 {',', 'N', '\321'}, {',', 'n', '\361'},
2169 {',', 'K', '\323'}, {',', 'k', '\363'},
2170 {'~', 'I', '\245'}, {'~', 'i', '\265'}, /* tilde */
2171 {'-', 'E', '\252'}, {'-', 'e', '\272'}, /* macron */
2172 {'-', 'A', '\300'}, {'-', 'a', '\340'},
2173 {'-', 'I', '\317'}, {'-', 'i', '\357'},
2174 {'-', 'O', '\322'}, {'-', 'o', '\362'},
2175 {'-', 'U', '\336'}, {'-', 'u', '\376'},
2176 {'/', 'T', '\254'}, {'/', 't', '\274'}, /* slash */
2177 {'.', 'E', '\314'}, {'.', 'e', '\344'}, /* dot above */
2178 {';', 'I', '\307'}, {';', 'i', '\347'}, /* ogonek */
2179 {';', 'U', '\331'}, {';', 'u', '\371'},
2180 /* iso-8859-9 uses this */
2181 /* iso-8859-9 has really bad choosen G( S, and I. as they collide
2182 * whith the same letters on other iso-8859-x (that is they are on
2183 * different places :-( ), if you use turkish uncomment these and
2184 * comment out the lines in iso-8859-2 and iso-8859-3 sections
2185 * FIXME: should be dynamic according to chosen language
2186 * if/when Wine has turkish support.
2188 /* collision whith G( from iso-8859-3 !!! */
2189 /* {'(', 'G', '\320'}, {'(', 'g', '\360'}, */ /* breve */
2190 /* collision whith S, from iso-8859-2 !!! */
2191 /* {',', 'S', '\336'}, {',', 's', '\376'}, */ /* cedilla */
2192 /* collision whith I. from iso-8859-3 !!! */
2193 /* {'.', 'I', '\335'}, {'.', 'i', '\375'}, */ /* dot above */
2197 /***********************************************************************
2198 * MSG_DoTranslateMessage
2200 * Implementation of TranslateMessage.
2202 * TranslateMessage translates virtual-key messages into character-messages,
2204 * WM_KEYDOWN/WM_KEYUP combinations produce a WM_CHAR or WM_DEADCHAR message.
2205 * ditto replacing WM_* with WM_SYS*
2206 * This produces WM_CHAR messages only for keys mapped to ASCII characters
2207 * by the keyboard driver.
2209 static BOOL
MSG_DoTranslateMessage( UINT message
, HWND hwnd
,
2210 WPARAM wParam
, LPARAM lParam
)
2212 static int dead_char
;
2215 if (message
!= WM_MOUSEMOVE
&& message
!= WM_TIMER
)
2216 TRACE("(%s, %04X, %08lX)\n",
2217 SPY_GetMsgName(message
), wParam
, lParam
);
2218 if(message
>= WM_KEYFIRST
&& message
<= WM_KEYLAST
)
2219 TRACE_(key
)("(%s, %04X, %08lX)\n",
2220 SPY_GetMsgName(message
), wParam
, lParam
);
2222 if ((message
!= WM_KEYDOWN
) && (message
!= WM_SYSKEYDOWN
)) return FALSE
;
2224 TRACE_(key
)("Translating key %s (%04x), scancode %02x\n",
2225 SPY_GetVKeyName(wParam
), wParam
, LOBYTE(HIWORD(lParam
)));
2227 /* FIXME : should handle ToUnicode yielding 2 */
2228 switch (ToUnicode(wParam
, HIWORD(lParam
), QueueKeyStateTable
, wp
, 2, 0))
2231 message
= (message
== WM_KEYDOWN
) ? WM_CHAR
: WM_SYSCHAR
;
2232 /* Should dead chars handling go in ToAscii ? */
2237 if (wp
[0] == ' ') wp
[0] = dead_char
;
2238 if (dead_char
== 0xa2) dead_char
= '(';
2239 else if (dead_char
== 0xa8) dead_char
= '"';
2240 else if (dead_char
== 0xb2) dead_char
= ';';
2241 else if (dead_char
== 0xb4) dead_char
= '\'';
2242 else if (dead_char
== 0xb7) dead_char
= '<';
2243 else if (dead_char
== 0xb8) dead_char
= ',';
2244 else if (dead_char
== 0xff) dead_char
= '.';
2245 for (i
= 0; i
< sizeof(accent_chars
)/sizeof(accent_chars
[0]); i
++)
2246 if ((accent_chars
[i
].ac_accent
== dead_char
) &&
2247 (accent_chars
[i
].ac_char
== wp
[0]))
2249 wp
[0] = accent_chars
[i
].ac_result
;
2254 TRACE_(key
)("1 -> PostMessage(%s)\n", SPY_GetMsgName(message
));
2255 PostMessageW( hwnd
, message
, wp
[0], lParam
);
2259 message
= (message
== WM_KEYDOWN
) ? WM_DEADCHAR
: WM_SYSDEADCHAR
;
2261 TRACE_(key
)("-1 -> PostMessage(%s)\n", SPY_GetMsgName(message
));
2262 PostMessageW( hwnd
, message
, wp
[0], lParam
);
2269 /***********************************************************************
2270 * TranslateMessage (USER.113)
2272 BOOL16 WINAPI
TranslateMessage16( const MSG16
*msg
)
2274 return MSG_DoTranslateMessage( msg
->message
, msg
->hwnd
,
2275 msg
->wParam
, msg
->lParam
);
2279 /***********************************************************************
2280 * TranslateMessage32 (USER.821)
2282 BOOL16 WINAPI
TranslateMessage32_16( const MSG32_16
*msg
, BOOL16 wHaveParamHigh
)
2287 wParam
= MAKELONG(msg
->msg
.wParam
, msg
->wParamHigh
);
2289 wParam
= (WPARAM
)msg
->msg
.wParam
;
2291 return MSG_DoTranslateMessage( msg
->msg
.message
, msg
->msg
.hwnd
,
2292 wParam
, msg
->msg
.lParam
);
2295 /***********************************************************************
2296 * TranslateMessage (USER32.@)
2298 BOOL WINAPI
TranslateMessage( const MSG
*msg
)
2300 return MSG_DoTranslateMessage( msg
->message
, msg
->hwnd
,
2301 msg
->wParam
, msg
->lParam
);
2305 /***********************************************************************
2306 * DispatchMessage (USER.114)
2308 LONG WINAPI
DispatchMessage16( const MSG16
* msg
)
2314 /* Process timer messages */
2315 if ((msg
->message
== WM_TIMER
) || (msg
->message
== WM_SYSTIMER
))
2319 /* before calling window proc, verify whether timer is still valid;
2320 there's a slim chance that the application kills the timer
2321 between GetMessage and DispatchMessage API calls */
2322 if (!TIMER_IsTimerValid(msg
->hwnd
, (UINT
) msg
->wParam
, (HWINDOWPROC
) msg
->lParam
))
2323 return 0; /* invalid winproc */
2325 return CallWindowProc16( (WNDPROC16
)msg
->lParam
, msg
->hwnd
,
2326 msg
->message
, msg
->wParam
, GetTickCount() );
2330 if (!msg
->hwnd
) return 0;
2331 if (!(wndPtr
= WIN_FindWndPtr( msg
->hwnd
))) return 0;
2332 if (!wndPtr
->winproc
)
2337 painting
= (msg
->message
== WM_PAINT
);
2338 if (painting
) wndPtr
->flags
|= WIN_NEEDS_BEGINPAINT
;
2340 SPY_EnterMessage( SPY_DISPATCHMESSAGE16
, msg
->hwnd
, msg
->message
,
2341 msg
->wParam
, msg
->lParam
);
2342 retval
= CallWindowProc16( (WNDPROC16
)wndPtr
->winproc
,
2343 msg
->hwnd
, msg
->message
,
2344 msg
->wParam
, msg
->lParam
);
2345 SPY_ExitMessage( SPY_RESULT_OK16
, msg
->hwnd
, msg
->message
, retval
,
2346 msg
->wParam
, msg
->lParam
);
2348 WIN_ReleaseWndPtr(wndPtr
);
2349 wndPtr
= WIN_FindWndPtr(msg
->hwnd
);
2350 if (painting
&& wndPtr
&&
2351 (wndPtr
->flags
& WIN_NEEDS_BEGINPAINT
) && wndPtr
->hrgnUpdate
)
2353 ERR("BeginPaint not called on WM_PAINT for hwnd %04x!\n",
2355 wndPtr
->flags
&= ~WIN_NEEDS_BEGINPAINT
;
2356 /* Validate the update region to avoid infinite WM_PAINT loop */
2357 RedrawWindow( wndPtr
->hwndSelf
, NULL
, 0,
2358 RDW_NOFRAME
| RDW_VALIDATE
| RDW_NOCHILDREN
| RDW_NOINTERNALPAINT
);
2361 WIN_ReleaseWndPtr(wndPtr
);
2366 /***********************************************************************
2367 * DispatchMessage32 (USER.822)
2369 LONG WINAPI
DispatchMessage32_16( const MSG32_16
* lpmsg16_32
, BOOL16 wHaveParamHigh
)
2371 if (wHaveParamHigh
== FALSE
)
2372 return DispatchMessage16(&(lpmsg16_32
->msg
));
2377 msg
.hwnd
= lpmsg16_32
->msg
.hwnd
;
2378 msg
.message
= lpmsg16_32
->msg
.message
;
2379 msg
.wParam
= MAKELONG(lpmsg16_32
->msg
.wParam
, lpmsg16_32
->wParamHigh
);
2380 msg
.lParam
= lpmsg16_32
->msg
.lParam
;
2381 msg
.time
= lpmsg16_32
->msg
.time
;
2382 msg
.pt
.x
= (INT
)lpmsg16_32
->msg
.pt
.x
;
2383 msg
.pt
.y
= (INT
)lpmsg16_32
->msg
.pt
.y
;
2384 return DispatchMessageA(&msg
);
2388 /***********************************************************************
2389 * DispatchMessageA (USER32.@)
2391 LONG WINAPI
DispatchMessageA( const MSG
* msg
)
2397 /* Process timer messages */
2398 if ((msg
->message
== WM_TIMER
) || (msg
->message
== WM_SYSTIMER
))
2402 /* HOOK_CallHooks32A( WH_CALLWNDPROC, HC_ACTION, 0, FIXME ); */
2404 /* before calling window proc, verify whether timer is still valid;
2405 there's a slim chance that the application kills the timer
2406 between GetMessage and DispatchMessage API calls */
2407 if (!TIMER_IsTimerValid(msg
->hwnd
, (UINT
) msg
->wParam
, (HWINDOWPROC
) msg
->lParam
))
2408 return 0; /* invalid winproc */
2410 return CallWindowProcA( (WNDPROC
)msg
->lParam
, msg
->hwnd
,
2411 msg
->message
, msg
->wParam
, GetTickCount() );
2415 if (!msg
->hwnd
) return 0;
2416 if (!(wndPtr
= WIN_FindWndPtr( msg
->hwnd
))) return 0;
2417 if (!wndPtr
->winproc
)
2422 painting
= (msg
->message
== WM_PAINT
);
2423 if (painting
) wndPtr
->flags
|= WIN_NEEDS_BEGINPAINT
;
2424 /* HOOK_CallHooks32A( WH_CALLWNDPROC, HC_ACTION, 0, FIXME ); */
2426 SPY_EnterMessage( SPY_DISPATCHMESSAGE
, msg
->hwnd
, msg
->message
,
2427 msg
->wParam
, msg
->lParam
);
2428 retval
= CallWindowProcA( (WNDPROC
)wndPtr
->winproc
,
2429 msg
->hwnd
, msg
->message
,
2430 msg
->wParam
, msg
->lParam
);
2431 SPY_ExitMessage( SPY_RESULT_OK
, msg
->hwnd
, msg
->message
, retval
,
2432 msg
->wParam
, msg
->lParam
);
2434 WIN_ReleaseWndPtr(wndPtr
);
2435 wndPtr
= WIN_FindWndPtr(msg
->hwnd
);
2437 if (painting
&& wndPtr
&&
2438 (wndPtr
->flags
& WIN_NEEDS_BEGINPAINT
) && wndPtr
->hrgnUpdate
)
2440 ERR("BeginPaint not called on WM_PAINT for hwnd %04x!\n",
2442 wndPtr
->flags
&= ~WIN_NEEDS_BEGINPAINT
;
2443 /* Validate the update region to avoid infinite WM_PAINT loop */
2444 RedrawWindow( wndPtr
->hwndSelf
, NULL
, 0,
2445 RDW_NOFRAME
| RDW_VALIDATE
| RDW_NOCHILDREN
| RDW_NOINTERNALPAINT
);
2448 WIN_ReleaseWndPtr(wndPtr
);
2453 /***********************************************************************
2454 * DispatchMessageW (USER32.@) Process Message
2456 * Process the message specified in the structure *_msg_.
2458 * If the lpMsg parameter points to a WM_TIMER message and the
2459 * parameter of the WM_TIMER message is not NULL, the lParam parameter
2460 * points to the function that is called instead of the window
2463 * The message must be valid.
2467 * DispatchMessage() returns the result of the window procedure invoked.
2474 LONG WINAPI
DispatchMessageW( const MSG
* msg
)
2480 /* Process timer messages */
2481 if ((msg
->message
== WM_TIMER
) || (msg
->message
== WM_SYSTIMER
))
2485 /* HOOK_CallHooks32W( WH_CALLWNDPROC, HC_ACTION, 0, FIXME ); */
2487 /* before calling window proc, verify whether timer is still valid;
2488 there's a slim chance that the application kills the timer
2489 between GetMessage and DispatchMessage API calls */
2490 if (!TIMER_IsTimerValid(msg
->hwnd
, (UINT
) msg
->wParam
, (HWINDOWPROC
) msg
->lParam
))
2491 return 0; /* invalid winproc */
2493 return CallWindowProcW( (WNDPROC
)msg
->lParam
, msg
->hwnd
,
2494 msg
->message
, msg
->wParam
, GetTickCount() );
2498 if (!msg
->hwnd
) return 0;
2499 if (!(wndPtr
= WIN_FindWndPtr( msg
->hwnd
))) return 0;
2500 if (!wndPtr
->winproc
)
2505 painting
= (msg
->message
== WM_PAINT
);
2506 if (painting
) wndPtr
->flags
|= WIN_NEEDS_BEGINPAINT
;
2507 /* HOOK_CallHooks32W( WH_CALLWNDPROC, HC_ACTION, 0, FIXME ); */
2509 SPY_EnterMessage( SPY_DISPATCHMESSAGE
, msg
->hwnd
, msg
->message
,
2510 msg
->wParam
, msg
->lParam
);
2511 retval
= CallWindowProcW( (WNDPROC
)wndPtr
->winproc
,
2512 msg
->hwnd
, msg
->message
,
2513 msg
->wParam
, msg
->lParam
);
2514 SPY_ExitMessage( SPY_RESULT_OK
, msg
->hwnd
, msg
->message
, retval
,
2515 msg
->wParam
, msg
->lParam
);
2517 WIN_ReleaseWndPtr(wndPtr
);
2518 wndPtr
= WIN_FindWndPtr(msg
->hwnd
);
2520 if (painting
&& wndPtr
&&
2521 (wndPtr
->flags
& WIN_NEEDS_BEGINPAINT
) && wndPtr
->hrgnUpdate
)
2523 ERR("BeginPaint not called on WM_PAINT for hwnd %04x!\n",
2525 wndPtr
->flags
&= ~WIN_NEEDS_BEGINPAINT
;
2526 /* Validate the update region to avoid infinite WM_PAINT loop */
2527 RedrawWindow( wndPtr
->hwndSelf
, NULL
, 0,
2528 RDW_NOFRAME
| RDW_VALIDATE
| RDW_NOCHILDREN
| RDW_NOINTERNALPAINT
);
2531 WIN_ReleaseWndPtr(wndPtr
);
2536 /***********************************************************************
2537 * RegisterWindowMessage (USER.118)
2538 * RegisterWindowMessageA (USER32.@)
2540 WORD WINAPI
RegisterWindowMessageA( LPCSTR str
)
2542 TRACE("%s\n", str
);
2543 return GlobalAddAtomA( str
);
2547 /***********************************************************************
2548 * RegisterWindowMessageW (USER32.@)
2550 WORD WINAPI
RegisterWindowMessageW( LPCWSTR str
)
2552 TRACE("%p\n", str
);
2553 return GlobalAddAtomW( str
);
2557 /***********************************************************************
2558 * InSendMessage (USER.192)
2560 BOOL16 WINAPI
InSendMessage16(void)
2562 return InSendMessage();
2566 /***********************************************************************
2567 * InSendMessage (USER32.@)
2569 BOOL WINAPI
InSendMessage(void)
2571 return (InSendMessageEx(NULL
) & (ISMEX_SEND
|ISMEX_REPLIED
)) == ISMEX_SEND
;
2575 /***********************************************************************
2576 * InSendMessageEx (USER32.@)
2578 DWORD WINAPI
InSendMessageEx( LPVOID reserved
)
2581 SERVER_START_REQ( in_send_message
)
2583 if (!SERVER_CALL_ERR()) ret
= req
->flags
;
2590 /***********************************************************************
2591 * BroadcastSystemMessage (USER32.@)
2593 LONG WINAPI
BroadcastSystemMessage(
2594 DWORD dwFlags
,LPDWORD recipients
,UINT uMessage
,WPARAM wParam
,
2597 FIXME("(%08lx,%08lx,%08x,%08x,%08lx): stub!\n",
2598 dwFlags
,*recipients
,uMessage
,wParam
,lParam