2 * Window messaging support
4 * Copyright 2001 Alexandre Julliard
6 * This library is free software; you can redistribute it and/or
7 * modify it under the terms of the GNU Lesser General Public
8 * License as published by the Free Software Foundation; either
9 * version 2.1 of the License, or (at your option) any later version.
11 * This library is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 * Lesser General Public License for more details.
16 * You should have received a copy of the GNU Lesser General Public
17 * License along with this library; if not, write to the Free Software
18 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
22 #include "wine/port.h"
28 #define WIN32_NO_STATUS
37 #include "wine/unicode.h"
38 #include "wine/server.h"
39 #include "user_private.h"
42 #include "wine/debug.h"
44 WINE_DEFAULT_DEBUG_CHANNEL(msg);
45 WINE_DECLARE_DEBUG_CHANNEL(relay);
46 WINE_DECLARE_DEBUG_CHANNEL(key);
48 #define WM_NCMOUSEFIRST WM_NCMOUSEMOVE
49 #define WM_NCMOUSELAST (WM_NCMOUSEFIRST+(WM_MOUSELAST-WM_MOUSEFIRST))
51 #define MAX_PACK_COUNT 4
52 #define MAX_SENDMSG_RECURSION 64
54 #define SYS_TIMER_RATE 55 /* min. timer rate in ms (actually 54.925)*/
56 /* description of the data fields that need to be packed along with a sent message */
60 const void *data[MAX_PACK_COUNT];
61 size_t size[MAX_PACK_COUNT];
64 /* info about the message currently being received by the current thread */
65 struct received_message_info
67 enum message_type type;
69 UINT flags; /* InSendMessageEx return flags */
72 /* structure to group all parameters for sent messages of the various kinds */
73 struct send_message_info
75 enum message_type type;
81 UINT flags; /* flags for SendMessageTimeout */
82 UINT timeout; /* timeout for SendMessageTimeout */
83 SENDASYNCPROC callback; /* callback function for SendMessageCallback */
84 ULONG_PTR data; /* callback data */
85 enum wm_char_mapping wm_char;
89 /* flag for messages that contain pointers */
90 /* 32 messages per entry, messages 0..31 map to bits 0..31 */
92 #define SET(msg) (1 << ((msg) & 31))
94 static const unsigned int message_pointer_flags[] =
97 SET(WM_CREATE) | SET(WM_SETTEXT) | SET(WM_GETTEXT) |
98 SET(WM_WININICHANGE) | SET(WM_DEVMODECHANGE),
100 SET(WM_GETMINMAXINFO) | SET(WM_DRAWITEM) | SET(WM_MEASUREITEM) | SET(WM_DELETEITEM) |
103 SET(WM_WINDOWPOSCHANGING) | SET(WM_WINDOWPOSCHANGED) | SET(WM_COPYDATA) |
104 SET(WM_NOTIFY) | SET(WM_HELP),
106 SET(WM_STYLECHANGING) | SET(WM_STYLECHANGED),
108 SET(WM_NCCREATE) | SET(WM_NCCALCSIZE) | SET(WM_GETDLGCODE),
110 SET(EM_GETSEL) | SET(EM_GETRECT) | SET(EM_SETRECT) | SET(EM_SETRECTNP),
112 SET(EM_REPLACESEL) | SET(EM_GETLINE) | SET(EM_SETTABSTOPS),
114 SET(SBM_GETRANGE) | SET(SBM_SETSCROLLINFO) | SET(SBM_GETSCROLLINFO) | SET(SBM_GETSCROLLBARINFO),
120 SET(CB_GETEDITSEL) | SET(CB_ADDSTRING) | SET(CB_DIR) | SET(CB_GETLBTEXT) |
121 SET(CB_INSERTSTRING) | SET(CB_FINDSTRING) | SET(CB_SELECTSTRING) |
122 SET(CB_GETDROPPEDCONTROLRECT) | SET(CB_FINDSTRINGEXACT),
126 SET(LB_ADDSTRING) | SET(LB_INSERTSTRING) | SET(LB_GETTEXT) | SET(LB_SELECTSTRING) |
127 SET(LB_DIR) | SET(LB_FINDSTRING) |
128 SET(LB_GETSELITEMS) | SET(LB_SETTABSTOPS) | SET(LB_ADDFILE) | SET(LB_GETITEMRECT),
130 SET(LB_FINDSTRINGEXACT),
136 SET(WM_NEXTMENU) | SET(WM_SIZING) | SET(WM_MOVING) | SET(WM_DEVICECHANGE),
138 SET(WM_MDICREATE) | SET(WM_MDIGETACTIVE) | SET(WM_DROPOBJECT) |
139 SET(WM_QUERYDROPOBJECT) | SET(WM_DRAGLOOP) | SET(WM_DRAGSELECT) | SET(WM_DRAGMOVE),
153 SET(WM_ASKCBFORMATNAME)
156 /* flags for messages that contain Unicode strings */
157 static const unsigned int message_unicode_flags[] =
160 SET(WM_CREATE) | SET(WM_SETTEXT) | SET(WM_GETTEXT) | SET(WM_GETTEXTLENGTH) |
161 SET(WM_WININICHANGE) | SET(WM_DEVMODECHANGE),
173 SET(EM_REPLACESEL) | SET(EM_GETLINE) | SET(EM_SETPASSWORDCHAR),
177 SET(WM_CHAR) | SET(WM_DEADCHAR) | SET(WM_SYSCHAR) | SET(WM_SYSDEADCHAR),
181 SET(CB_ADDSTRING) | SET(CB_DIR) | SET(CB_GETLBTEXT) | SET(CB_GETLBTEXTLEN) |
182 SET(CB_INSERTSTRING) | SET(CB_FINDSTRING) | SET(CB_SELECTSTRING) | SET(CB_FINDSTRINGEXACT),
186 SET(LB_ADDSTRING) | SET(LB_INSERTSTRING) | SET(LB_GETTEXT) | SET(LB_GETTEXTLEN) |
187 SET(LB_SELECTSTRING) | SET(LB_DIR) | SET(LB_FINDSTRING) | SET(LB_ADDFILE),
189 SET(LB_FINDSTRINGEXACT),
211 SET(WM_PAINTCLIPBOARD) | SET(WM_SIZECLIPBOARD) | SET(WM_ASKCBFORMATNAME)
214 /* check whether a given message type includes pointers */
215 static inline int is_pointer_message( UINT message )
217 if (message >= 8*sizeof(message_pointer_flags)) return FALSE;
218 return (message_pointer_flags[message / 32] & SET(message)) != 0;
221 /* check whether a given message type contains Unicode (or ASCII) chars */
222 static inline int is_unicode_message( UINT message )
224 if (message >= 8*sizeof(message_unicode_flags)) return FALSE;
225 return (message_unicode_flags[message / 32] & SET(message)) != 0;
230 /* add a data field to a packed message */
231 static inline void push_data( struct packed_message *data, const void *ptr, size_t size )
233 data->data[data->count] = ptr;
234 data->size[data->count] = size;
238 /* add a string to a packed message */
239 static inline void push_string( struct packed_message *data, LPCWSTR str )
241 push_data( data, str, (strlenW(str) + 1) * sizeof(WCHAR) );
244 /* retrieve a pointer to data from a packed message and increment the buffer pointer */
245 static inline void *get_data( void **buffer, size_t size )
248 *buffer = (char *)*buffer + size;
252 /* make sure that the buffer contains a valid null-terminated Unicode string */
253 static inline BOOL check_string( LPCWSTR str, size_t size )
255 for (size /= sizeof(WCHAR); size; size--, str++)
256 if (!*str) return TRUE;
260 /* make sure that there is space for 'size' bytes in buffer, growing it if needed */
261 static inline void *get_buffer_space( void **buffer, size_t size )
267 if (!(ret = HeapReAlloc( GetProcessHeap(), 0, *buffer, size )))
268 HeapFree( GetProcessHeap(), 0, *buffer );
270 else ret = HeapAlloc( GetProcessHeap(), 0, size );
276 /* check whether a combobox expects strings or ids in CB_ADDSTRING/CB_INSERTSTRING */
277 static inline BOOL combobox_has_strings( HWND hwnd )
279 DWORD style = GetWindowLongA( hwnd, GWL_STYLE );
280 return (!(style & (CBS_OWNERDRAWFIXED | CBS_OWNERDRAWVARIABLE)) || (style & CBS_HASSTRINGS));
283 /* check whether a listbox expects strings or ids in LB_ADDSTRING/LB_INSERTSTRING */
284 static inline BOOL listbox_has_strings( HWND hwnd )
286 DWORD style = GetWindowLongA( hwnd, GWL_STYLE );
287 return (!(style & (LBS_OWNERDRAWFIXED | LBS_OWNERDRAWVARIABLE)) || (style & LBS_HASSTRINGS));
290 /* check whether message is in the range of keyboard messages */
291 static inline BOOL is_keyboard_message( UINT message )
293 return (message >= WM_KEYFIRST && message <= WM_KEYLAST);
296 /* check whether message is in the range of mouse messages */
297 static inline BOOL is_mouse_message( UINT message )
299 return ((message >= WM_NCMOUSEFIRST && message <= WM_NCMOUSELAST) ||
300 (message >= WM_MOUSEFIRST && message <= WM_MOUSELAST));
303 /* check whether message matches the specified hwnd filter */
304 static inline BOOL check_hwnd_filter( const MSG *msg, HWND hwnd_filter )
306 if (!hwnd_filter || hwnd_filter == GetDesktopWindow()) return TRUE;
307 return (msg->hwnd == hwnd_filter || IsChild( hwnd_filter, msg->hwnd ));
310 /* check for pending WM_CHAR message with DBCS trailing byte */
311 static inline BOOL get_pending_wmchar( MSG *msg, UINT first, UINT last, BOOL remove )
313 struct wm_char_mapping_data *data = get_user_thread_info()->wmchar_data;
315 if (!data || !data->get_msg.message) return FALSE;
316 if ((first || last) && (first > WM_CHAR || last < WM_CHAR)) return FALSE;
317 if (!msg) return FALSE;
318 *msg = data->get_msg;
319 if (remove) data->get_msg.message = 0;
323 /***********************************************************************
324 * broadcast_message_callback
326 * Helper callback for broadcasting messages.
328 static BOOL CALLBACK broadcast_message_callback( HWND hwnd, LPARAM lparam )
330 struct send_message_info *info = (struct send_message_info *)lparam;
331 if (!(GetWindowLongW( hwnd, GWL_STYLE ) & (WS_POPUP|WS_CAPTION))) return TRUE;
335 SendMessageTimeoutW( hwnd, info->msg, info->wparam, info->lparam,
336 info->flags, info->timeout, NULL );
339 SendMessageTimeoutA( hwnd, info->msg, info->wparam, info->lparam,
340 info->flags, info->timeout, NULL );
343 SendNotifyMessageW( hwnd, info->msg, info->wparam, info->lparam );
346 SendMessageCallbackW( hwnd, info->msg, info->wparam, info->lparam,
347 info->callback, info->data );
350 PostMessageW( hwnd, info->msg, info->wparam, info->lparam );
353 ERR( "bad type %d\n", info->type );
360 /***********************************************************************
363 * Convert the wparam of an ASCII message to Unicode.
365 BOOL map_wparam_AtoW( UINT message, WPARAM *wparam, enum wm_char_mapping mapping )
374 /* WM_CHAR is magic: a DBCS char can be sent/posted as two consecutive WM_CHAR
375 * messages, in which case the first char is stored, and the conversion
376 * to Unicode only takes place once the second char is sent/posted.
378 if (mapping != WMCHAR_MAP_NOMAPPING)
380 struct wm_char_mapping_data *data = get_user_thread_info()->wmchar_data;
381 BYTE low = LOBYTE(*wparam);
386 ch[1] = HIBYTE(*wparam);
387 RtlMultiByteToUnicodeN( wch, sizeof(wch), NULL, ch, 2 );
388 TRACE( "map %02x,%02x -> %04x mapping %u\n", (BYTE)ch[0], (BYTE)ch[1], wch[0], mapping );
389 if (data) data->lead_byte[mapping] = 0;
391 else if (data && data->lead_byte[mapping])
393 ch[0] = data->lead_byte[mapping];
395 RtlMultiByteToUnicodeN( wch, sizeof(wch), NULL, ch, 2 );
396 TRACE( "map stored %02x,%02x -> %04x mapping %u\n", (BYTE)ch[0], (BYTE)ch[1], wch[0], mapping );
397 data->lead_byte[mapping] = 0;
399 else if (!IsDBCSLeadByte( low ))
402 RtlMultiByteToUnicodeN( wch, sizeof(wch), NULL, ch, 1 );
403 TRACE( "map %02x -> %04x\n", (BYTE)ch[0], wch[0] );
404 if (data) data->lead_byte[mapping] = 0;
406 else /* store it and wait for trail byte */
410 if (!(data = HeapAlloc( GetProcessHeap(), HEAP_ZERO_MEMORY, sizeof(*data) )))
412 get_user_thread_info()->wmchar_data = data;
414 TRACE( "storing lead byte %02x mapping %u\n", low, mapping );
415 data->lead_byte[mapping] = low;
418 *wparam = MAKEWPARAM(wch[0], wch[1]);
421 /* else fall through */
423 case EM_SETPASSWORDCHAR:
428 ch[0] = LOBYTE(*wparam);
429 ch[1] = HIBYTE(*wparam);
430 RtlMultiByteToUnicodeN( wch, sizeof(wch), NULL, ch, 2 );
431 *wparam = MAKEWPARAM(wch[0], wch[1]);
434 ch[0] = HIBYTE(*wparam);
435 ch[1] = LOBYTE(*wparam);
436 if (ch[0]) RtlMultiByteToUnicodeN( wch, sizeof(wch[0]), NULL, ch, 2 );
437 else RtlMultiByteToUnicodeN( wch, sizeof(wch[0]), NULL, ch + 1, 1 );
438 *wparam = MAKEWPARAM(wch[0], HIWORD(*wparam));
445 /***********************************************************************
448 * Convert the wparam of a Unicode message to ASCII.
450 static void map_wparam_WtoA( MSG *msg, BOOL remove )
459 if (!HIWORD(msg->wParam))
461 wch[0] = LOWORD(msg->wParam);
463 RtlUnicodeToMultiByteN( (LPSTR)ch, 2, &len, wch, sizeof(wch[0]) );
464 if (len == 2) /* DBCS char */
466 struct wm_char_mapping_data *data = get_user_thread_info()->wmchar_data;
469 if (!(data = HeapAlloc( GetProcessHeap(), HEAP_ZERO_MEMORY, sizeof(*data) ))) return;
470 get_user_thread_info()->wmchar_data = data;
474 data->get_msg = *msg;
475 data->get_msg.wParam = ch[1];
481 /* else fall through */
483 case EM_SETPASSWORDCHAR:
488 wch[0] = LOWORD(msg->wParam);
489 wch[1] = HIWORD(msg->wParam);
491 RtlUnicodeToMultiByteN( (LPSTR)ch, 2, NULL, wch, sizeof(wch) );
492 msg->wParam = MAKEWPARAM( ch[0] | (ch[1] << 8), 0 );
495 wch[0] = LOWORD(msg->wParam);
497 RtlUnicodeToMultiByteN( (LPSTR)ch, 2, &len, wch, sizeof(wch[0]) );
499 msg->wParam = MAKEWPARAM( (ch[0] << 8) | ch[1], HIWORD(msg->wParam) );
501 msg->wParam = MAKEWPARAM( ch[0], HIWORD(msg->wParam) );
507 /***********************************************************************
510 * Pack a message for sending to another process.
511 * Return the size of the data we expect in the message reply.
512 * Set data->count to -1 if there is an error.
514 static size_t pack_message( HWND hwnd, UINT message, WPARAM wparam, LPARAM lparam,
515 struct packed_message *data )
523 CREATESTRUCTW *cs = (CREATESTRUCTW *)lparam;
524 push_data( data, cs, sizeof(*cs) );
525 if (HIWORD(cs->lpszName)) push_string( data, cs->lpszName );
526 if (HIWORD(cs->lpszClass)) push_string( data, cs->lpszClass );
530 case WM_ASKCBFORMATNAME:
531 return wparam * sizeof(WCHAR);
532 case WM_WININICHANGE:
533 if (lparam) push_string(data, (LPWSTR)lparam );
536 case WM_DEVMODECHANGE:
541 push_string( data, (LPWSTR)lparam );
543 case WM_GETMINMAXINFO:
544 push_data( data, (MINMAXINFO *)lparam, sizeof(MINMAXINFO) );
545 return sizeof(MINMAXINFO);
547 push_data( data, (DRAWITEMSTRUCT *)lparam, sizeof(DRAWITEMSTRUCT) );
550 push_data( data, (MEASUREITEMSTRUCT *)lparam, sizeof(MEASUREITEMSTRUCT) );
551 return sizeof(MEASUREITEMSTRUCT);
553 push_data( data, (DELETEITEMSTRUCT *)lparam, sizeof(DELETEITEMSTRUCT) );
556 push_data( data, (COMPAREITEMSTRUCT *)lparam, sizeof(COMPAREITEMSTRUCT) );
558 case WM_WINDOWPOSCHANGING:
559 case WM_WINDOWPOSCHANGED:
560 push_data( data, (WINDOWPOS *)lparam, sizeof(WINDOWPOS) );
561 return sizeof(WINDOWPOS);
564 COPYDATASTRUCT *cp = (COPYDATASTRUCT *)lparam;
565 push_data( data, cp, sizeof(*cp) );
566 if (cp->lpData) push_data( data, cp->lpData, cp->cbData );
570 /* WM_NOTIFY cannot be sent across processes (MSDN) */
574 push_data( data, (HELPINFO *)lparam, sizeof(HELPINFO) );
576 case WM_STYLECHANGING:
577 case WM_STYLECHANGED:
578 push_data( data, (STYLESTRUCT *)lparam, sizeof(STYLESTRUCT) );
583 push_data( data, (RECT *)lparam, sizeof(RECT) );
588 NCCALCSIZE_PARAMS *nc = (NCCALCSIZE_PARAMS *)lparam;
589 push_data( data, nc, sizeof(*nc) );
590 push_data( data, nc->lppos, sizeof(*nc->lppos) );
591 return sizeof(*nc) + sizeof(*nc->lppos);
594 if (lparam) push_data( data, (MSG *)lparam, sizeof(MSG) );
596 case SBM_SETSCROLLINFO:
597 push_data( data, (SCROLLINFO *)lparam, sizeof(SCROLLINFO) );
599 case SBM_GETSCROLLINFO:
600 push_data( data, (SCROLLINFO *)lparam, sizeof(SCROLLINFO) );
601 return sizeof(SCROLLINFO);
602 case SBM_GETSCROLLBARINFO:
604 const SCROLLBARINFO *info = (const SCROLLBARINFO *)lparam;
605 size_t size = min( info->cbSize, sizeof(SCROLLBARINFO) );
606 push_data( data, info, size );
614 if (wparam) size += sizeof(DWORD);
615 if (lparam) size += sizeof(DWORD);
620 case CB_GETDROPPEDCONTROLRECT:
624 push_data( data, (RECT *)lparam, sizeof(RECT) );
628 WORD *pw = (WORD *)lparam;
629 push_data( data, pw, sizeof(*pw) );
630 return *pw * sizeof(WCHAR);
634 if (wparam) push_data( data, (UINT *)lparam, sizeof(UINT) * wparam );
637 case CB_INSERTSTRING:
639 case CB_FINDSTRINGEXACT:
640 case CB_SELECTSTRING:
641 if (combobox_has_strings( hwnd )) push_string( data, (LPWSTR)lparam );
644 if (!combobox_has_strings( hwnd )) return sizeof(ULONG_PTR);
645 return (SendMessageW( hwnd, CB_GETLBTEXTLEN, wparam, 0 ) + 1) * sizeof(WCHAR);
647 case LB_INSERTSTRING:
649 case LB_FINDSTRINGEXACT:
650 case LB_SELECTSTRING:
651 if (listbox_has_strings( hwnd )) push_string( data, (LPWSTR)lparam );
654 if (!listbox_has_strings( hwnd )) return sizeof(ULONG_PTR);
655 return (SendMessageW( hwnd, LB_GETTEXTLEN, wparam, 0 ) + 1) * sizeof(WCHAR);
657 return wparam * sizeof(UINT);
659 push_data( data, (MDINEXTMENU *)lparam, sizeof(MDINEXTMENU) );
660 return sizeof(MDINEXTMENU);
663 push_data( data, (RECT *)lparam, sizeof(RECT) );
667 MDICREATESTRUCTW *cs = (MDICREATESTRUCTW *)lparam;
668 push_data( data, cs, sizeof(*cs) );
669 if (HIWORD(cs->szTitle)) push_string( data, cs->szTitle );
670 if (HIWORD(cs->szClass)) push_string( data, cs->szClass );
673 case WM_MDIGETACTIVE:
674 if (lparam) return sizeof(BOOL);
676 case WM_DEVICECHANGE:
678 DEV_BROADCAST_HDR *header = (DEV_BROADCAST_HDR *)lparam;
679 push_data( data, header, header->dbch_size );
682 case WM_WINE_SETWINDOWPOS:
683 push_data( data, (WINDOWPOS *)lparam, sizeof(WINDOWPOS) );
685 case WM_WINE_KEYBOARD_LL_HOOK:
687 struct hook_extra_info *h_extra = (struct hook_extra_info *)lparam;
688 push_data( data, h_extra, sizeof(*h_extra) );
689 push_data( data, (LPVOID)h_extra->lparam, sizeof(KBDLLHOOKSTRUCT) );
692 case WM_WINE_MOUSE_LL_HOOK:
694 struct hook_extra_info *h_extra = (struct hook_extra_info *)lparam;
695 push_data( data, h_extra, sizeof(*h_extra) );
696 push_data( data, (LPVOID)h_extra->lparam, sizeof(MSLLHOOKSTRUCT) );
700 if (wparam <= 1) return 0;
701 FIXME( "WM_NCPAINT hdc packing not supported yet\n" );
705 if (!wparam) return 0;
708 /* these contain an HFONT */
711 /* these contain an HDC */
713 case WM_ICONERASEBKGND:
714 case WM_CTLCOLORMSGBOX:
715 case WM_CTLCOLOREDIT:
716 case WM_CTLCOLORLISTBOX:
719 case WM_CTLCOLORSCROLLBAR:
720 case WM_CTLCOLORSTATIC:
723 /* these contain an HGLOBAL */
724 case WM_PAINTCLIPBOARD:
725 case WM_SIZECLIPBOARD:
726 /* these contain HICON */
729 case WM_QUERYDRAGICON:
730 case WM_QUERYPARKICON:
731 /* these contain pointers */
733 case WM_QUERYDROPOBJECT:
737 FIXME( "msg %x (%s) not supported yet\n", message, SPY_GetMsgName(message, hwnd) );
745 /***********************************************************************
748 * Unpack a message received from another process.
750 static BOOL unpack_message( HWND hwnd, UINT message, WPARAM *wparam, LPARAM *lparam,
751 void **buffer, size_t size )
760 CREATESTRUCTW *cs = *buffer;
761 WCHAR *str = (WCHAR *)(cs + 1);
762 if (size < sizeof(*cs)) return FALSE;
764 if (HIWORD(cs->lpszName))
766 if (!check_string( str, size )) return FALSE;
768 size -= (strlenW(str) + 1) * sizeof(WCHAR);
769 str += strlenW(str) + 1;
771 if (HIWORD(cs->lpszClass))
773 if (!check_string( str, size )) return FALSE;
779 case WM_ASKCBFORMATNAME:
780 if (!get_buffer_space( buffer, (*wparam * sizeof(WCHAR)) )) return FALSE;
782 case WM_WININICHANGE:
783 if (!*lparam) return TRUE;
786 case WM_DEVMODECHANGE:
791 if (!check_string( *buffer, size )) return FALSE;
793 case WM_GETMINMAXINFO:
794 minsize = sizeof(MINMAXINFO);
797 minsize = sizeof(DRAWITEMSTRUCT);
800 minsize = sizeof(MEASUREITEMSTRUCT);
803 minsize = sizeof(DELETEITEMSTRUCT);
806 minsize = sizeof(COMPAREITEMSTRUCT);
808 case WM_WINDOWPOSCHANGING:
809 case WM_WINDOWPOSCHANGED:
810 case WM_WINE_SETWINDOWPOS:
811 minsize = sizeof(WINDOWPOS);
815 COPYDATASTRUCT *cp = *buffer;
816 if (size < sizeof(*cp)) return FALSE;
819 minsize = sizeof(*cp) + cp->cbData;
825 /* WM_NOTIFY cannot be sent across processes (MSDN) */
828 minsize = sizeof(HELPINFO);
830 case WM_STYLECHANGING:
831 case WM_STYLECHANGED:
832 minsize = sizeof(STYLESTRUCT);
835 if (!*wparam) minsize = sizeof(RECT);
838 NCCALCSIZE_PARAMS *nc = *buffer;
839 if (size < sizeof(*nc) + sizeof(*nc->lppos)) return FALSE;
840 nc->lppos = (WINDOWPOS *)(nc + 1);
844 if (!*lparam) return TRUE;
845 minsize = sizeof(MSG);
847 case SBM_SETSCROLLINFO:
848 minsize = sizeof(SCROLLINFO);
850 case SBM_GETSCROLLINFO:
851 if (!get_buffer_space( buffer, sizeof(SCROLLINFO ))) return FALSE;
853 case SBM_GETSCROLLBARINFO:
854 if (!get_buffer_space( buffer, sizeof(SCROLLBARINFO ))) return FALSE;
859 if (*wparam || *lparam)
861 if (!get_buffer_space( buffer, 2*sizeof(DWORD) )) return FALSE;
862 if (*wparam) *wparam = (WPARAM)*buffer;
863 if (*lparam) *lparam = (LPARAM)((DWORD *)*buffer + 1);
868 case CB_GETDROPPEDCONTROLRECT:
869 if (!get_buffer_space( buffer, sizeof(RECT) )) return FALSE;
873 minsize = sizeof(RECT);
878 if (size < sizeof(WORD)) return FALSE;
879 len = *(WORD *)*buffer;
880 if (!get_buffer_space( buffer, (len + 1) * sizeof(WCHAR) )) return FALSE;
881 *lparam = (LPARAM)*buffer + sizeof(WORD); /* don't erase WORD at start of buffer */
886 if (!*wparam) return TRUE;
887 minsize = *wparam * sizeof(UINT);
890 case CB_INSERTSTRING:
892 case CB_FINDSTRINGEXACT:
893 case CB_SELECTSTRING:
895 case LB_INSERTSTRING:
897 case LB_FINDSTRINGEXACT:
898 case LB_SELECTSTRING:
899 if (!*buffer) return TRUE;
900 if (!check_string( *buffer, size )) return FALSE;
904 size = sizeof(ULONG_PTR);
905 if (combobox_has_strings( hwnd ))
906 size = (SendMessageW( hwnd, CB_GETLBTEXTLEN, *wparam, 0 ) + 1) * sizeof(WCHAR);
907 if (!get_buffer_space( buffer, size )) return FALSE;
912 size = sizeof(ULONG_PTR);
913 if (listbox_has_strings( hwnd ))
914 size = (SendMessageW( hwnd, LB_GETTEXTLEN, *wparam, 0 ) + 1) * sizeof(WCHAR);
915 if (!get_buffer_space( buffer, size )) return FALSE;
919 if (!get_buffer_space( buffer, *wparam * sizeof(UINT) )) return FALSE;
922 minsize = sizeof(MDINEXTMENU);
923 if (!get_buffer_space( buffer, sizeof(MDINEXTMENU) )) return FALSE;
927 minsize = sizeof(RECT);
928 if (!get_buffer_space( buffer, sizeof(RECT) )) return FALSE;
932 MDICREATESTRUCTW *cs = *buffer;
933 WCHAR *str = (WCHAR *)(cs + 1);
934 if (size < sizeof(*cs)) return FALSE;
936 if (HIWORD(cs->szTitle))
938 if (!check_string( str, size )) return FALSE;
940 size -= (strlenW(str) + 1) * sizeof(WCHAR);
941 str += strlenW(str) + 1;
943 if (HIWORD(cs->szClass))
945 if (!check_string( str, size )) return FALSE;
950 case WM_MDIGETACTIVE:
951 if (!*lparam) return TRUE;
952 if (!get_buffer_space( buffer, sizeof(BOOL) )) return FALSE;
954 case WM_DEVICECHANGE:
955 minsize = sizeof(DEV_BROADCAST_HDR);
957 case WM_WINE_KEYBOARD_LL_HOOK:
958 case WM_WINE_MOUSE_LL_HOOK:
960 struct hook_extra_info *h_extra = (struct hook_extra_info *)*buffer;
962 minsize = sizeof(struct hook_extra_info) +
963 (message == WM_WINE_KEYBOARD_LL_HOOK ? sizeof(KBDLLHOOKSTRUCT)
964 : sizeof(MSLLHOOKSTRUCT));
965 if (size < minsize) return FALSE;
966 h_extra->lparam = (LPARAM)(h_extra + 1);
970 if (*wparam <= 1) return TRUE;
971 FIXME( "WM_NCPAINT hdc unpacking not supported\n" );
974 if (!*wparam) return TRUE;
977 /* these contain an HFONT */
980 /* these contain an HDC */
982 case WM_ICONERASEBKGND:
983 case WM_CTLCOLORMSGBOX:
984 case WM_CTLCOLOREDIT:
985 case WM_CTLCOLORLISTBOX:
988 case WM_CTLCOLORSCROLLBAR:
989 case WM_CTLCOLORSTATIC:
992 /* these contain an HGLOBAL */
993 case WM_PAINTCLIPBOARD:
994 case WM_SIZECLIPBOARD:
995 /* these contain HICON */
998 case WM_QUERYDRAGICON:
999 case WM_QUERYPARKICON:
1000 /* these contain pointers */
1002 case WM_QUERYDROPOBJECT:
1006 FIXME( "msg %x (%s) not supported yet\n", message, SPY_GetMsgName(message, hwnd) );
1010 return TRUE; /* message doesn't need any unpacking */
1013 /* default exit for most messages: check minsize and store buffer in lparam */
1014 if (size < minsize) return FALSE;
1015 *lparam = (LPARAM)*buffer;
1020 /***********************************************************************
1023 * Pack a reply to a message for sending to another process.
1025 static void pack_reply( HWND hwnd, UINT message, WPARAM wparam, LPARAM lparam,
1026 LRESULT res, struct packed_message *data )
1033 push_data( data, (CREATESTRUCTW *)lparam, sizeof(CREATESTRUCTW) );
1038 push_data( data, (WCHAR *)lparam, (res + 1) * sizeof(WCHAR) );
1040 case WM_GETMINMAXINFO:
1041 push_data( data, (MINMAXINFO *)lparam, sizeof(MINMAXINFO) );
1043 case WM_MEASUREITEM:
1044 push_data( data, (MEASUREITEMSTRUCT *)lparam, sizeof(MEASUREITEMSTRUCT) );
1046 case WM_WINDOWPOSCHANGING:
1047 case WM_WINDOWPOSCHANGED:
1048 push_data( data, (WINDOWPOS *)lparam, sizeof(WINDOWPOS) );
1051 if (lparam) push_data( data, (MSG *)lparam, sizeof(MSG) );
1053 case SBM_GETSCROLLINFO:
1054 push_data( data, (SCROLLINFO *)lparam, sizeof(SCROLLINFO) );
1057 case LB_GETITEMRECT:
1058 case CB_GETDROPPEDCONTROLRECT:
1061 push_data( data, (RECT *)lparam, sizeof(RECT) );
1065 WORD *ptr = (WORD *)lparam;
1066 push_data( data, ptr, ptr[-1] * sizeof(WCHAR) );
1069 case LB_GETSELITEMS:
1070 push_data( data, (UINT *)lparam, wparam * sizeof(UINT) );
1072 case WM_MDIGETACTIVE:
1073 if (lparam) push_data( data, (BOOL *)lparam, sizeof(BOOL) );
1077 push_data( data, (RECT *)lparam, sizeof(RECT) );
1080 NCCALCSIZE_PARAMS *nc = (NCCALCSIZE_PARAMS *)lparam;
1081 push_data( data, nc, sizeof(*nc) );
1082 push_data( data, nc->lppos, sizeof(*nc->lppos) );
1088 if (wparam) push_data( data, (DWORD *)wparam, sizeof(DWORD) );
1089 if (lparam) push_data( data, (DWORD *)lparam, sizeof(DWORD) );
1092 push_data( data, (MDINEXTMENU *)lparam, sizeof(MDINEXTMENU) );
1095 push_data( data, (MDICREATESTRUCTW *)lparam, sizeof(MDICREATESTRUCTW) );
1097 case WM_ASKCBFORMATNAME:
1098 push_data( data, (WCHAR *)lparam, (strlenW((WCHAR *)lparam) + 1) * sizeof(WCHAR) );
1104 /***********************************************************************
1107 * Unpack a message reply received from another process.
1109 static void unpack_reply( HWND hwnd, UINT message, WPARAM wparam, LPARAM lparam,
1110 void *buffer, size_t size )
1117 CREATESTRUCTW *cs = (CREATESTRUCTW *)lparam;
1118 LPCWSTR name = cs->lpszName, class = cs->lpszClass;
1119 memcpy( cs, buffer, min( sizeof(*cs), size ));
1120 cs->lpszName = name; /* restore the original pointers */
1121 cs->lpszClass = class;
1125 case WM_ASKCBFORMATNAME:
1126 memcpy( (WCHAR *)lparam, buffer, min( wparam*sizeof(WCHAR), size ));
1128 case WM_GETMINMAXINFO:
1129 memcpy( (MINMAXINFO *)lparam, buffer, min( sizeof(MINMAXINFO), size ));
1131 case WM_MEASUREITEM:
1132 memcpy( (MEASUREITEMSTRUCT *)lparam, buffer, min( sizeof(MEASUREITEMSTRUCT), size ));
1134 case WM_WINDOWPOSCHANGING:
1135 case WM_WINDOWPOSCHANGED:
1136 memcpy( (WINDOWPOS *)lparam, buffer, min( sizeof(WINDOWPOS), size ));
1139 if (lparam) memcpy( (MSG *)lparam, buffer, min( sizeof(MSG), size ));
1141 case SBM_GETSCROLLINFO:
1142 memcpy( (SCROLLINFO *)lparam, buffer, min( sizeof(SCROLLINFO), size ));
1144 case SBM_GETSCROLLBARINFO:
1145 memcpy( (SCROLLBARINFO *)lparam, buffer, min( sizeof(SCROLLBARINFO), size ));
1148 case CB_GETDROPPEDCONTROLRECT:
1149 case LB_GETITEMRECT:
1152 memcpy( (RECT *)lparam, buffer, min( sizeof(RECT), size ));
1155 size = min( size, (size_t)*(WORD *)lparam );
1156 memcpy( (WCHAR *)lparam, buffer, size );
1158 case LB_GETSELITEMS:
1159 memcpy( (UINT *)lparam, buffer, min( wparam*sizeof(UINT), size ));
1163 memcpy( (WCHAR *)lparam, buffer, size );
1166 memcpy( (MDINEXTMENU *)lparam, buffer, min( sizeof(MDINEXTMENU), size ));
1168 case WM_MDIGETACTIVE:
1169 if (lparam) memcpy( (BOOL *)lparam, buffer, min( sizeof(BOOL), size ));
1173 memcpy( (RECT *)lparam, buffer, min( sizeof(RECT), size ));
1176 NCCALCSIZE_PARAMS *nc = (NCCALCSIZE_PARAMS *)lparam;
1177 WINDOWPOS *wp = nc->lppos;
1178 memcpy( nc, buffer, min( sizeof(*nc), size ));
1179 if (size > sizeof(*nc))
1181 size -= sizeof(*nc);
1182 memcpy( wp, (NCCALCSIZE_PARAMS*)buffer + 1, min( sizeof(*wp), size ));
1184 nc->lppos = wp; /* restore the original pointer */
1192 memcpy( (DWORD *)wparam, buffer, min( sizeof(DWORD), size ));
1193 if (size <= sizeof(DWORD)) break;
1194 size -= sizeof(DWORD);
1195 buffer = (DWORD *)buffer + 1;
1197 if (lparam) memcpy( (DWORD *)lparam, buffer, min( sizeof(DWORD), size ));
1201 MDICREATESTRUCTW *cs = (MDICREATESTRUCTW *)lparam;
1202 LPCWSTR title = cs->szTitle, class = cs->szClass;
1203 memcpy( cs, buffer, min( sizeof(*cs), size ));
1204 cs->szTitle = title; /* restore the original pointers */
1205 cs->szClass = class;
1209 ERR( "should not happen: unexpected message %x\n", message );
1215 /***********************************************************************
1218 * Send a reply to a sent message.
1220 static void reply_message( struct received_message_info *info, LRESULT result, BOOL remove )
1222 struct packed_message data;
1223 int i, replied = info->flags & ISMEX_REPLIED;
1225 if (info->flags & ISMEX_NOTIFY) return; /* notify messages don't get replies */
1226 if (!remove && replied) return; /* replied already */
1229 info->flags |= ISMEX_REPLIED;
1231 if (info->type == MSG_OTHER_PROCESS && !replied)
1233 pack_reply( info->msg.hwnd, info->msg.message, info->msg.wParam,
1234 info->msg.lParam, result, &data );
1237 SERVER_START_REQ( reply_message )
1239 req->result = result;
1240 req->remove = remove;
1241 for (i = 0; i < data.count; i++) wine_server_add_data( req, data.data[i], data.size[i] );
1242 wine_server_call( req );
1248 /***********************************************************************
1249 * handle_internal_message
1251 * Handle an internal Wine message instead of calling the window proc.
1253 static LRESULT handle_internal_message( HWND hwnd, UINT msg, WPARAM wparam, LPARAM lparam )
1257 case WM_WINE_DESTROYWINDOW:
1258 return WIN_DestroyWindow( hwnd );
1259 case WM_WINE_SETWINDOWPOS:
1260 if (hwnd == GetDesktopWindow()) return 0;
1261 return USER_SetWindowPos( (WINDOWPOS *)lparam );
1262 case WM_WINE_SHOWWINDOW:
1263 if (hwnd == GetDesktopWindow()) return 0;
1264 return ShowWindow( hwnd, wparam );
1265 case WM_WINE_SETPARENT:
1266 if (hwnd == GetDesktopWindow()) return 0;
1267 return (LRESULT)SetParent( hwnd, (HWND)wparam );
1268 case WM_WINE_SETWINDOWLONG:
1269 return WIN_SetWindowLong( hwnd, (short)LOWORD(wparam), HIWORD(wparam), lparam, TRUE );
1270 case WM_WINE_ENABLEWINDOW:
1271 if (hwnd == GetDesktopWindow()) return 0;
1272 return EnableWindow( hwnd, wparam );
1273 case WM_WINE_SETACTIVEWINDOW:
1274 if (hwnd == GetDesktopWindow()) return 0;
1275 return (LRESULT)SetActiveWindow( (HWND)wparam );
1276 case WM_WINE_KEYBOARD_LL_HOOK:
1277 case WM_WINE_MOUSE_LL_HOOK:
1279 struct hook_extra_info *h_extra = (struct hook_extra_info *)lparam;
1281 return call_current_hook( h_extra->handle, HC_ACTION, wparam, h_extra->lparam );
1284 if (msg >= WM_WINE_FIRST_DRIVER_MSG && msg <= WM_WINE_LAST_DRIVER_MSG)
1285 return USER_Driver->pWindowMessage( hwnd, msg, wparam, lparam );
1286 FIXME( "unknown internal message %x\n", msg );
1291 /* since the WM_DDE_ACK response to a WM_DDE_EXECUTE message should contain the handle
1292 * to the memory handle, we keep track (in the server side) of all pairs of handle
1293 * used (the client passes its value and the content of the memory handle), and
1294 * the server stored both values (the client, and the local one, created after the
1295 * content). When a ACK message is generated, the list of pair is searched for a
1296 * matching pair, so that the client memory handle can be returned.
1299 HGLOBAL client_hMem;
1300 HGLOBAL server_hMem;
1303 static struct DDE_pair* dde_pairs;
1304 static int dde_num_alloc;
1305 static int dde_num_used;
1307 static CRITICAL_SECTION dde_crst;
1308 static CRITICAL_SECTION_DEBUG critsect_debug =
1311 { &critsect_debug.ProcessLocksList, &critsect_debug.ProcessLocksList },
1312 0, 0, { (DWORD_PTR)(__FILE__ ": dde_crst") }
1314 static CRITICAL_SECTION dde_crst = { &critsect_debug, -1, 0, 0, 0, 0 };
1316 static BOOL dde_add_pair(HGLOBAL chm, HGLOBAL shm)
1321 EnterCriticalSection(&dde_crst);
1323 /* now remember the pair of hMem on both sides */
1324 if (dde_num_used == dde_num_alloc)
1326 struct DDE_pair* tmp;
1328 tmp = HeapReAlloc( GetProcessHeap(), 0, dde_pairs,
1329 (dde_num_alloc + GROWBY) * sizeof(struct DDE_pair));
1331 tmp = HeapAlloc( GetProcessHeap(), 0,
1332 (dde_num_alloc + GROWBY) * sizeof(struct DDE_pair));
1336 LeaveCriticalSection(&dde_crst);
1340 /* zero out newly allocated part */
1341 memset(&dde_pairs[dde_num_alloc], 0, GROWBY * sizeof(struct DDE_pair));
1342 dde_num_alloc += GROWBY;
1345 for (i = 0; i < dde_num_alloc; i++)
1347 if (dde_pairs[i].server_hMem == 0)
1349 dde_pairs[i].client_hMem = chm;
1350 dde_pairs[i].server_hMem = shm;
1355 LeaveCriticalSection(&dde_crst);
1359 static HGLOBAL dde_get_pair(HGLOBAL shm)
1364 EnterCriticalSection(&dde_crst);
1365 for (i = 0; i < dde_num_alloc; i++)
1367 if (dde_pairs[i].server_hMem == shm)
1369 /* free this pair */
1370 dde_pairs[i].server_hMem = 0;
1372 ret = dde_pairs[i].client_hMem;
1376 LeaveCriticalSection(&dde_crst);
1380 /***********************************************************************
1383 * Post a DDE message
1385 static BOOL post_dde_message( struct packed_message *data, const struct send_message_info *info )
1389 UINT_PTR uiLo, uiHi;
1391 HGLOBAL hunlock = 0;
1395 if (!UnpackDDElParam( info->msg, info->lparam, &uiLo, &uiHi ))
1401 /* DDE messages which don't require packing are:
1410 /* uiHi should contain a hMem from WM_DDE_EXECUTE */
1411 HGLOBAL h = dde_get_pair( (HANDLE)uiHi );
1414 /* send back the value of h on the other side */
1415 push_data( data, &h, sizeof(HGLOBAL) );
1417 TRACE( "send dde-ack %lx %08lx => %p\n", uiLo, uiHi, h );
1422 /* uiHi should contain either an atom or 0 */
1423 TRACE( "send dde-ack %lx atom=%lx\n", uiLo, uiHi );
1424 lp = MAKELONG( uiLo, uiHi );
1433 size = GlobalSize( (HGLOBAL)uiLo ) ;
1434 if ((info->msg == WM_DDE_ADVISE && size < sizeof(DDEADVISE)) ||
1435 (info->msg == WM_DDE_DATA && size < sizeof(DDEDATA)) ||
1436 (info->msg == WM_DDE_POKE && size < sizeof(DDEPOKE))
1440 else if (info->msg != WM_DDE_DATA) return FALSE;
1445 if ((ptr = GlobalLock( (HGLOBAL)uiLo) ))
1447 DDEDATA *dde_data = (DDEDATA *)ptr;
1448 TRACE("unused %d, fResponse %d, fRelease %d, fDeferUpd %d, fAckReq %d, cfFormat %d\n",
1449 dde_data->unused, dde_data->fResponse, dde_data->fRelease,
1450 dde_data->reserved, dde_data->fAckReq, dde_data->cfFormat);
1451 push_data( data, ptr, size );
1452 hunlock = (HGLOBAL)uiLo;
1455 TRACE( "send ddepack %u %lx\n", size, uiHi );
1457 case WM_DDE_EXECUTE:
1460 if ((ptr = GlobalLock( (HGLOBAL)info->lparam) ))
1462 push_data(data, ptr, GlobalSize( (HGLOBAL)info->lparam ));
1463 /* so that the other side can send it back on ACK */
1465 hunlock = (HGLOBAL)info->lparam;
1470 SERVER_START_REQ( send_message )
1472 req->id = info->dest_tid;
1473 req->type = info->type;
1475 req->win = info->hwnd;
1476 req->msg = info->msg;
1477 req->wparam = info->wparam;
1479 req->timeout = TIMEOUT_INFINITE;
1480 for (i = 0; i < data->count; i++)
1481 wine_server_add_data( req, data->data[i], data->size[i] );
1482 if ((res = wine_server_call( req )))
1484 if (res == STATUS_INVALID_PARAMETER)
1485 /* FIXME: find a STATUS_ value for this one */
1486 SetLastError( ERROR_INVALID_THREAD_ID );
1488 SetLastError( RtlNtStatusToDosError(res) );
1491 FreeDDElParam(info->msg, info->lparam);
1494 if (hunlock) GlobalUnlock(hunlock);
1499 /***********************************************************************
1500 * unpack_dde_message
1502 * Unpack a posted DDE message received from another process.
1504 static BOOL unpack_dde_message( HWND hwnd, UINT message, WPARAM *wparam, LPARAM *lparam,
1505 void **buffer, size_t size )
1507 UINT_PTR uiLo, uiHi;
1516 /* hMem is being passed */
1517 if (size != sizeof(HGLOBAL)) return FALSE;
1518 if (!buffer || !*buffer) return FALSE;
1520 memcpy( &hMem, *buffer, size );
1521 uiHi = (UINT_PTR)hMem;
1522 TRACE("recv dde-ack %lx mem=%lx[%lx]\n", uiLo, uiHi, GlobalSize( hMem ));
1526 uiLo = LOWORD( *lparam );
1527 uiHi = HIWORD( *lparam );
1528 TRACE("recv dde-ack %lx atom=%lx\n", uiLo, uiHi);
1530 *lparam = PackDDElParam( WM_DDE_ACK, uiLo, uiHi );
1535 if ((!buffer || !*buffer) && message != WM_DDE_DATA) return FALSE;
1539 if (!(hMem = GlobalAlloc( GMEM_MOVEABLE|GMEM_DDESHARE, size )))
1541 if ((ptr = GlobalLock( hMem )))
1543 memcpy( ptr, *buffer, size );
1544 GlobalUnlock( hMem );
1552 uiLo = (UINT_PTR)hMem;
1554 *lparam = PackDDElParam( message, uiLo, uiHi );
1556 case WM_DDE_EXECUTE:
1559 if (!buffer || !*buffer) return FALSE;
1560 if (!(hMem = GlobalAlloc( GMEM_MOVEABLE|GMEM_DDESHARE, size ))) return FALSE;
1561 if ((ptr = GlobalLock( hMem )))
1563 memcpy( ptr, *buffer, size );
1564 GlobalUnlock( hMem );
1565 TRACE( "exec: pairing c=%08lx s=%p\n", *lparam, hMem );
1566 if (!dde_add_pair( (HGLOBAL)*lparam, hMem ))
1577 } else return FALSE;
1578 *lparam = (LPARAM)hMem;
1584 /***********************************************************************
1587 * Call a window procedure and the corresponding hooks.
1589 static LRESULT call_window_proc( HWND hwnd, UINT msg, WPARAM wparam, LPARAM lparam,
1590 BOOL unicode, BOOL same_thread, enum wm_char_mapping mapping )
1592 struct user_thread_info *thread_info = get_user_thread_info();
1595 CWPRETSTRUCT cwpret;
1597 if (thread_info->recursion_count > MAX_SENDMSG_RECURSION) return 0;
1598 thread_info->recursion_count++;
1600 if (msg & 0x80000000)
1602 result = handle_internal_message( hwnd, msg, wparam, lparam );
1606 /* first the WH_CALLWNDPROC hook */
1607 hwnd = WIN_GetFullHandle( hwnd );
1608 cwp.lParam = lparam;
1609 cwp.wParam = wparam;
1612 HOOK_CallHooks( WH_CALLWNDPROC, HC_ACTION, same_thread, (LPARAM)&cwp, unicode );
1614 /* now call the window procedure */
1615 if (!WINPROC_call_window( hwnd, msg, wparam, lparam, &result, unicode, mapping )) goto done;
1617 /* and finally the WH_CALLWNDPROCRET hook */
1618 cwpret.lResult = result;
1619 cwpret.lParam = lparam;
1620 cwpret.wParam = wparam;
1621 cwpret.message = msg;
1623 HOOK_CallHooks( WH_CALLWNDPROCRET, HC_ACTION, same_thread, (LPARAM)&cwpret, unicode );
1625 thread_info->recursion_count--;
1630 /***********************************************************************
1631 * send_parent_notify
1633 * Send a WM_PARENTNOTIFY to all ancestors of the given window, unless
1634 * the window has the WS_EX_NOPARENTNOTIFY style.
1636 static void send_parent_notify( HWND hwnd, WORD event, WORD idChild, POINT pt )
1638 /* pt has to be in the client coordinates of the parent window */
1639 MapWindowPoints( 0, hwnd, &pt, 1 );
1644 if (!(GetWindowLongW( hwnd, GWL_STYLE ) & WS_CHILD)) break;
1645 if (GetWindowLongW( hwnd, GWL_EXSTYLE ) & WS_EX_NOPARENTNOTIFY) break;
1646 if (!(parent = GetParent(hwnd))) break;
1647 if (parent == GetDesktopWindow()) break;
1648 MapWindowPoints( hwnd, parent, &pt, 1 );
1650 SendMessageW( hwnd, WM_PARENTNOTIFY,
1651 MAKEWPARAM( event, idChild ), MAKELPARAM( pt.x, pt.y ) );
1656 /***********************************************************************
1657 * accept_hardware_message
1659 * Tell the server we have passed the message to the app
1660 * (even though we may end up dropping it later on)
1662 static void accept_hardware_message( UINT hw_id, BOOL remove, HWND new_hwnd )
1664 SERVER_START_REQ( accept_hardware_message )
1667 req->remove = remove;
1668 req->new_win = new_hwnd;
1669 if (wine_server_call( req ))
1670 FIXME("Failed to reply to MSG_HARDWARE message. Message may not be removed from queue.\n");
1676 /***********************************************************************
1677 * process_keyboard_message
1679 * returns TRUE if the contents of 'msg' should be passed to the application
1681 static BOOL process_keyboard_message( MSG *msg, UINT hw_id, HWND hwnd_filter,
1682 UINT first, UINT last, BOOL remove )
1686 /* FIXME: is this really the right place for this hook? */
1687 event.message = msg->message;
1688 event.hwnd = msg->hwnd;
1689 event.time = msg->time;
1690 event.paramL = (msg->wParam & 0xFF) | (HIWORD(msg->lParam) << 8);
1691 event.paramH = msg->lParam & 0x7FFF;
1692 if (HIWORD(msg->lParam) & 0x0100) event.paramH |= 0x8000; /* special_key - bit */
1693 HOOK_CallHooks( WH_JOURNALRECORD, HC_ACTION, 0, (LPARAM)&event, TRUE );
1695 /* check message filters */
1696 if (msg->message < first || msg->message > last) return FALSE;
1697 if (!check_hwnd_filter( msg, hwnd_filter )) return FALSE;
1701 if((msg->message == WM_KEYDOWN) &&
1702 (msg->hwnd != GetDesktopWindow()))
1704 /* Handle F1 key by sending out WM_HELP message */
1705 if (msg->wParam == VK_F1)
1707 PostMessageW( msg->hwnd, WM_KEYF1, 0, 0 );
1709 else if(msg->wParam >= VK_BROWSER_BACK &&
1710 msg->wParam <= VK_LAUNCH_APP2)
1712 /* FIXME: Process keystate */
1713 SendMessageW(msg->hwnd, WM_APPCOMMAND, (WPARAM)msg->hwnd, MAKELPARAM(0, (FAPPCOMMAND_KEY | (msg->wParam - VK_BROWSER_BACK + 1))));
1716 else if (msg->message == WM_KEYUP)
1718 /* Handle VK_APPS key by posting a WM_CONTEXTMENU message */
1719 if (msg->wParam == VK_APPS && !MENU_IsMenuActive())
1720 PostMessageW(msg->hwnd, WM_CONTEXTMENU, (WPARAM)msg->hwnd, (LPARAM)-1);
1724 if (HOOK_CallHooks( WH_KEYBOARD, remove ? HC_ACTION : HC_NOREMOVE,
1725 LOWORD(msg->wParam), msg->lParam, TRUE ))
1727 /* skip this message */
1728 HOOK_CallHooks( WH_CBT, HCBT_KEYSKIPPED, LOWORD(msg->wParam), msg->lParam, TRUE );
1729 accept_hardware_message( hw_id, TRUE, 0 );
1732 accept_hardware_message( hw_id, remove, 0 );
1737 /***********************************************************************
1738 * process_mouse_message
1740 * returns TRUE if the contents of 'msg' should be passed to the application
1742 static BOOL process_mouse_message( MSG *msg, UINT hw_id, ULONG_PTR extra_info, HWND hwnd_filter,
1743 UINT first, UINT last, BOOL remove )
1752 MOUSEHOOKSTRUCT hook;
1755 /* find the window to dispatch this mouse message to */
1757 GetGUIThreadInfo( GetCurrentThreadId(), &info );
1758 if (info.hwndCapture)
1761 msg->hwnd = info.hwndCapture;
1765 msg->hwnd = WINPOS_WindowFromPoint( msg->hwnd, msg->pt, &hittest );
1768 if (!msg->hwnd || !WIN_IsCurrentThread( msg->hwnd ))
1770 accept_hardware_message( hw_id, TRUE, msg->hwnd );
1774 /* FIXME: is this really the right place for this hook? */
1775 event.message = msg->message;
1776 event.time = msg->time;
1777 event.hwnd = msg->hwnd;
1778 event.paramL = msg->pt.x;
1779 event.paramH = msg->pt.y;
1780 HOOK_CallHooks( WH_JOURNALRECORD, HC_ACTION, 0, (LPARAM)&event, TRUE );
1782 if (!check_hwnd_filter( msg, hwnd_filter )) return FALSE;
1785 message = msg->message;
1786 /* Note: windows has no concept of a non-client wheel message */
1787 if (message != WM_MOUSEWHEEL)
1789 if (hittest != HTCLIENT)
1791 message += WM_NCMOUSEMOVE - WM_MOUSEMOVE;
1792 msg->wParam = hittest;
1796 /* coordinates don't get translated while tracking a menu */
1797 /* FIXME: should differentiate popups and top-level menus */
1798 if (!(info.flags & GUI_INMENUMODE))
1799 ScreenToClient( msg->hwnd, &pt );
1802 msg->lParam = MAKELONG( pt.x, pt.y );
1804 /* translate double clicks */
1806 if ((msg->message == WM_LBUTTONDOWN) ||
1807 (msg->message == WM_RBUTTONDOWN) ||
1808 (msg->message == WM_MBUTTONDOWN) ||
1809 (msg->message == WM_XBUTTONDOWN))
1811 BOOL update = remove;
1813 /* translate double clicks -
1814 * note that ...MOUSEMOVEs can slip in between
1815 * ...BUTTONDOWN and ...BUTTONDBLCLK messages */
1817 if ((info.flags & (GUI_INMENUMODE|GUI_INMOVESIZE)) ||
1818 hittest != HTCLIENT ||
1819 (GetClassLongA( msg->hwnd, GCL_STYLE ) & CS_DBLCLKS))
1821 if ((msg->message == clk_msg.message) &&
1822 (msg->hwnd == clk_msg.hwnd) &&
1823 (msg->wParam == clk_msg.wParam) &&
1824 (msg->time - clk_msg.time < GetDoubleClickTime()) &&
1825 (abs(msg->pt.x - clk_msg.pt.x) < GetSystemMetrics(SM_CXDOUBLECLK)/2) &&
1826 (abs(msg->pt.y - clk_msg.pt.y) < GetSystemMetrics(SM_CYDOUBLECLK)/2))
1828 message += (WM_LBUTTONDBLCLK - WM_LBUTTONDOWN);
1831 clk_msg.message = 0; /* clear the double click conditions */
1836 if (message < first || message > last) return FALSE;
1837 /* update static double click conditions */
1838 if (update) clk_msg = *msg;
1842 if (message < first || message > last) return FALSE;
1845 /* message is accepted now (but may still get dropped) */
1848 hook.hwnd = msg->hwnd;
1849 hook.wHitTestCode = hittest;
1850 hook.dwExtraInfo = extra_info;
1851 if (HOOK_CallHooks( WH_MOUSE, remove ? HC_ACTION : HC_NOREMOVE,
1852 message, (LPARAM)&hook, TRUE ))
1855 hook.hwnd = msg->hwnd;
1856 hook.wHitTestCode = hittest;
1857 hook.dwExtraInfo = extra_info;
1858 HOOK_CallHooks( WH_CBT, HCBT_CLICKSKIPPED, message, (LPARAM)&hook, TRUE );
1859 accept_hardware_message( hw_id, TRUE, 0 );
1863 if ((hittest == HTERROR) || (hittest == HTNOWHERE))
1865 SendMessageW( msg->hwnd, WM_SETCURSOR, (WPARAM)msg->hwnd,
1866 MAKELONG( hittest, msg->message ));
1867 accept_hardware_message( hw_id, TRUE, 0 );
1871 accept_hardware_message( hw_id, remove, 0 );
1873 if (!remove || info.hwndCapture)
1875 msg->message = message;
1881 if ((msg->message == WM_LBUTTONDOWN) ||
1882 (msg->message == WM_RBUTTONDOWN) ||
1883 (msg->message == WM_MBUTTONDOWN) ||
1884 (msg->message == WM_XBUTTONDOWN))
1886 /* Send the WM_PARENTNOTIFY,
1887 * note that even for double/nonclient clicks
1888 * notification message is still WM_L/M/RBUTTONDOWN.
1890 send_parent_notify( msg->hwnd, msg->message, 0, msg->pt );
1892 /* Activate the window if needed */
1894 if (msg->hwnd != info.hwndActive)
1896 HWND hwndTop = msg->hwnd;
1899 if ((GetWindowLongW( hwndTop, GWL_STYLE ) & (WS_POPUP|WS_CHILD)) != WS_CHILD) break;
1900 hwndTop = GetParent( hwndTop );
1903 if (hwndTop && hwndTop != GetDesktopWindow())
1905 LONG ret = SendMessageW( msg->hwnd, WM_MOUSEACTIVATE, (WPARAM)hwndTop,
1906 MAKELONG( hittest, msg->message ) );
1909 case MA_NOACTIVATEANDEAT:
1914 case MA_ACTIVATEANDEAT:
1919 if (!FOCUS_MouseActivate( hwndTop )) eatMsg = TRUE;
1922 WARN( "unknown WM_MOUSEACTIVATE code %d\n", ret );
1929 /* send the WM_SETCURSOR message */
1931 /* Windows sends the normal mouse message as the message parameter
1932 in the WM_SETCURSOR message even if it's non-client mouse message */
1933 SendMessageW( msg->hwnd, WM_SETCURSOR, (WPARAM)msg->hwnd, MAKELONG( hittest, msg->message ));
1935 msg->message = message;
1940 /***********************************************************************
1941 * process_hardware_message
1943 * Process a hardware message; return TRUE if message should be passed on to the app
1945 static BOOL process_hardware_message( MSG *msg, UINT hw_id, ULONG_PTR extra_info, HWND hwnd_filter,
1946 UINT first, UINT last, BOOL remove )
1948 if (is_keyboard_message( msg->message ))
1949 return process_keyboard_message( msg, hw_id, hwnd_filter, first, last, remove );
1951 if (is_mouse_message( msg->message ))
1952 return process_mouse_message( msg, hw_id, extra_info, hwnd_filter, first, last, remove );
1954 ERR( "unknown message type %x\n", msg->message );
1959 /***********************************************************************
1960 * call_sendmsg_callback
1962 * Call the callback function of SendMessageCallback.
1964 static inline void call_sendmsg_callback( SENDASYNCPROC callback, HWND hwnd, UINT msg,
1965 ULONG_PTR data, LRESULT result )
1967 if (!callback) return;
1969 if (TRACE_ON(relay))
1970 DPRINTF( "%04x:Call message callback %p (hwnd=%p,msg=%s,data=%08lx,result=%08lx)\n",
1971 GetCurrentThreadId(), callback, hwnd, SPY_GetMsgName( msg, hwnd ),
1973 callback( hwnd, msg, data, result );
1974 if (TRACE_ON(relay))
1975 DPRINTF( "%04x:Ret message callback %p (hwnd=%p,msg=%s,data=%08lx,result=%08lx)\n",
1976 GetCurrentThreadId(), callback, hwnd, SPY_GetMsgName( msg, hwnd ),
1981 /***********************************************************************
1984 * Peek for a message matching the given parameters. Return FALSE if none available.
1985 * All pending sent messages are processed before returning.
1987 static BOOL peek_message( MSG *msg, HWND hwnd, UINT first, UINT last, UINT flags )
1990 ULONG_PTR extra_info = 0;
1991 struct user_thread_info *thread_info = get_user_thread_info();
1992 struct received_message_info info, *old_info;
1993 unsigned int wake_mask, changed_mask = HIWORD(flags);
1994 unsigned int hw_id = 0; /* id of previous hardware message */
1996 if (!first && !last) last = ~0;
1997 if (!changed_mask) changed_mask = QS_ALLINPUT;
1998 wake_mask = changed_mask & (QS_SENDMESSAGE | QS_SMRESULT);
2003 void *buffer = NULL;
2004 size_t size = 0, buffer_size = 0;
2006 do /* loop while buffer is too small */
2008 if (buffer_size && !(buffer = HeapAlloc( GetProcessHeap(), 0, buffer_size )))
2010 SERVER_START_REQ( get_message )
2013 req->get_win = hwnd;
2014 req->get_first = first;
2015 req->get_last = last;
2017 req->wake_mask = wake_mask;
2018 req->changed_mask = changed_mask;
2019 if (buffer_size) wine_server_set_reply( req, buffer, buffer_size );
2020 if (!(res = wine_server_call( req )))
2022 size = wine_server_reply_size( reply );
2023 info.type = reply->type;
2024 info.msg.hwnd = reply->win;
2025 info.msg.message = reply->msg;
2026 info.msg.wParam = reply->wparam;
2027 info.msg.lParam = reply->lparam;
2028 info.msg.time = reply->time;
2029 info.msg.pt.x = reply->x;
2030 info.msg.pt.y = reply->y;
2031 hw_id = reply->hw_id;
2032 extra_info = reply->info;
2033 thread_info->active_hooks = reply->active_hooks;
2037 HeapFree( GetProcessHeap(), 0, buffer );
2038 buffer_size = reply->total;
2042 } while (res == STATUS_BUFFER_OVERFLOW);
2044 if (res) return FALSE;
2046 TRACE( "got type %d msg %x (%s) hwnd %p wp %lx lp %lx\n",
2047 info.type, info.msg.message,
2048 (info.type == MSG_WINEVENT) ? "MSG_WINEVENT" : SPY_GetMsgName(info.msg.message, info.msg.hwnd),
2049 info.msg.hwnd, info.msg.wParam, info.msg.lParam );
2055 info.flags = ISMEX_SEND;
2058 info.flags = ISMEX_NOTIFY;
2061 info.flags = ISMEX_CALLBACK;
2063 case MSG_CALLBACK_RESULT:
2064 if (size >= sizeof(struct callback_msg_data))
2066 const struct callback_msg_data *data = (const struct callback_msg_data *)buffer;
2067 call_sendmsg_callback( data->callback, info.msg.hwnd,
2068 info.msg.message, data->data, data->result );
2072 if (size >= sizeof(struct winevent_msg_data))
2074 WINEVENTPROC hook_proc;
2075 const struct winevent_msg_data *data = (const struct winevent_msg_data *)buffer;
2077 hook_proc = data->hook_proc;
2078 size -= sizeof(*data);
2081 WCHAR module[MAX_PATH];
2083 size = min( size, (MAX_PATH - 1) * sizeof(WCHAR) );
2084 memcpy( module, buffer, size );
2085 module[size / sizeof(WCHAR)] = 0;
2086 if (!(hook_proc = get_hook_proc( hook_proc, module )))
2088 ERR( "invalid winevent hook module name %s\n", debugstr_w(module) );
2093 if (TRACE_ON(relay))
2094 DPRINTF( "%04x:Call winevent proc %p (hook=%p,event=%x,hwnd=%p,object_id=%lx,child_id=%lx,tid=%04x,time=%x)\n",
2095 GetCurrentThreadId(), hook_proc,
2096 data->hook, info.msg.message, info.msg.hwnd, info.msg.wParam,
2097 info.msg.lParam, data->tid, info.msg.time);
2099 hook_proc( data->hook, info.msg.message, info.msg.hwnd, info.msg.wParam,
2100 info.msg.lParam, data->tid, info.msg.time );
2102 if (TRACE_ON(relay))
2103 DPRINTF( "%04x:Ret winevent proc %p (hook=%p,event=%x,hwnd=%p,object_id=%lx,child_id=%lx,tid=%04x,time=%x)\n",
2104 GetCurrentThreadId(), hook_proc,
2105 data->hook, info.msg.message, info.msg.hwnd, info.msg.wParam,
2106 info.msg.lParam, data->tid, info.msg.time);
2109 case MSG_OTHER_PROCESS:
2110 info.flags = ISMEX_SEND;
2111 if (!unpack_message( info.msg.hwnd, info.msg.message, &info.msg.wParam,
2112 &info.msg.lParam, &buffer, size ))
2115 reply_message( &info, 0, TRUE );
2120 if (!process_hardware_message( &info.msg, hw_id, extra_info,
2121 hwnd, first, last, flags & PM_REMOVE ))
2123 TRACE("dropping msg %x\n", info.msg.message );
2124 goto next; /* ignore it */
2126 thread_info->GetMessagePosVal = MAKELONG( info.msg.pt.x, info.msg.pt.y );
2129 thread_info->GetMessageExtraInfoVal = extra_info;
2130 if (info.msg.message >= WM_DDE_FIRST && info.msg.message <= WM_DDE_LAST)
2132 if (!unpack_dde_message( info.msg.hwnd, info.msg.message, &info.msg.wParam,
2133 &info.msg.lParam, &buffer, size ))
2134 goto next; /* ignore it */
2137 HeapFree( GetProcessHeap(), 0, buffer );
2141 /* if we get here, we have a sent message; call the window procedure */
2142 old_info = thread_info->receive_info;
2143 thread_info->receive_info = &info;
2144 result = call_window_proc( info.msg.hwnd, info.msg.message, info.msg.wParam,
2145 info.msg.lParam, (info.type != MSG_ASCII), FALSE,
2146 WMCHAR_MAP_RECVMESSAGE );
2147 reply_message( &info, result, TRUE );
2148 thread_info->receive_info = old_info;
2150 /* if some PM_QS* flags were specified, only handle sent messages from now on */
2151 if (HIWORD(flags)) flags = PM_QS_SENDMESSAGE | LOWORD(flags);
2153 HeapFree( GetProcessHeap(), 0, buffer );
2158 /***********************************************************************
2159 * process_sent_messages
2161 * Process all pending sent messages.
2163 static inline void process_sent_messages(void)
2166 peek_message( &msg, 0, 0, 0, PM_REMOVE | PM_QS_SENDMESSAGE );
2170 /***********************************************************************
2171 * get_server_queue_handle
2173 * Get a handle to the server message queue for the current thread.
2175 static HANDLE get_server_queue_handle(void)
2177 struct user_thread_info *thread_info = get_user_thread_info();
2180 if (!(ret = thread_info->server_queue))
2182 SERVER_START_REQ( get_msg_queue )
2184 wine_server_call( req );
2185 ret = reply->handle;
2188 thread_info->server_queue = ret;
2189 if (!ret) ERR( "Cannot get server thread queue\n" );
2195 /***********************************************************************
2196 * wait_message_reply
2198 * Wait until a sent message gets replied to.
2200 static void wait_message_reply( UINT flags )
2202 HANDLE server_queue = get_server_queue_handle();
2206 unsigned int wake_bits = 0, changed_bits = 0;
2209 SERVER_START_REQ( set_queue_mask )
2211 req->wake_mask = QS_SMRESULT | ((flags & SMTO_BLOCK) ? 0 : QS_SENDMESSAGE);
2212 req->changed_mask = req->wake_mask;
2214 if (!wine_server_call( req ))
2216 wake_bits = reply->wake_bits;
2217 changed_bits = reply->changed_bits;
2222 if (wake_bits & QS_SMRESULT) return; /* got a result */
2223 if (wake_bits & QS_SENDMESSAGE)
2225 /* Process the sent message immediately */
2226 process_sent_messages();
2230 /* now wait for it */
2232 ReleaseThunkLock( &dwlc );
2233 res = USER_Driver->pMsgWaitForMultipleObjectsEx( 1, &server_queue,
2234 INFINITE, QS_SENDMESSAGE, 0 );
2235 if (dwlc) RestoreThunkLock( dwlc );
2239 /***********************************************************************
2240 * put_message_in_queue
2242 * Put a sent message into the destination queue.
2243 * For inter-process message, reply_size is set to expected size of reply data.
2245 static BOOL put_message_in_queue( const struct send_message_info *info, size_t *reply_size )
2247 struct packed_message data;
2248 message_data_t msg_data;
2251 timeout_t timeout = TIMEOUT_INFINITE;
2253 /* Check for INFINITE timeout for compatibility with Win9x,
2254 * although Windows >= NT does not do so
2256 if (info->type != MSG_NOTIFY &&
2257 info->type != MSG_CALLBACK &&
2258 info->type != MSG_POSTED &&
2260 info->timeout != INFINITE)
2262 /* timeout is signed despite the prototype */
2263 timeout = (timeout_t)max( 0, (int)info->timeout ) * -10000;
2267 if (info->type == MSG_OTHER_PROCESS)
2269 *reply_size = pack_message( info->hwnd, info->msg, info->wparam, info->lparam, &data );
2270 if (data.count == -1)
2272 WARN( "cannot pack message %x\n", info->msg );
2276 else if (info->type == MSG_CALLBACK)
2278 msg_data.callback.callback = info->callback;
2279 msg_data.callback.data = info->data;
2280 msg_data.callback.result = 0;
2281 data.data[0] = &msg_data;
2282 data.size[0] = sizeof(msg_data.callback);
2285 else if (info->type == MSG_POSTED && info->msg >= WM_DDE_FIRST && info->msg <= WM_DDE_LAST)
2287 return post_dde_message( &data, info );
2290 SERVER_START_REQ( send_message )
2292 req->id = info->dest_tid;
2293 req->type = info->type;
2295 req->win = info->hwnd;
2296 req->msg = info->msg;
2297 req->wparam = info->wparam;
2298 req->lparam = info->lparam;
2299 req->timeout = timeout;
2301 if (info->flags & SMTO_ABORTIFHUNG) req->flags |= SEND_MSG_ABORT_IF_HUNG;
2302 for (i = 0; i < data.count; i++) wine_server_add_data( req, data.data[i], data.size[i] );
2303 if ((res = wine_server_call( req )))
2305 if (res == STATUS_INVALID_PARAMETER)
2306 /* FIXME: find a STATUS_ value for this one */
2307 SetLastError( ERROR_INVALID_THREAD_ID );
2309 SetLastError( RtlNtStatusToDosError(res) );
2317 /***********************************************************************
2320 * Retrieve a message reply from the server.
2322 static LRESULT retrieve_reply( const struct send_message_info *info,
2323 size_t reply_size, LRESULT *result )
2326 void *reply_data = NULL;
2330 if (!(reply_data = HeapAlloc( GetProcessHeap(), 0, reply_size )))
2332 WARN( "no memory for reply, will be truncated\n" );
2336 SERVER_START_REQ( get_message_reply )
2339 if (reply_size) wine_server_set_reply( req, reply_data, reply_size );
2340 if (!(status = wine_server_call( req ))) *result = reply->result;
2341 reply_size = wine_server_reply_size( reply );
2344 if (!status && reply_size)
2345 unpack_reply( info->hwnd, info->msg, info->wparam, info->lparam, reply_data, reply_size );
2347 HeapFree( GetProcessHeap(), 0, reply_data );
2349 TRACE( "hwnd %p msg %x (%s) wp %lx lp %lx got reply %lx (err=%d)\n",
2350 info->hwnd, info->msg, SPY_GetMsgName(info->msg, info->hwnd), info->wparam,
2351 info->lparam, *result, status );
2353 /* MSDN states that last error is 0 on timeout, but at least NT4 returns ERROR_TIMEOUT */
2354 if (status) SetLastError( RtlNtStatusToDosError(status) );
2359 /***********************************************************************
2360 * send_inter_thread_message
2362 static LRESULT send_inter_thread_message( const struct send_message_info *info, LRESULT *res_ptr )
2364 size_t reply_size = 0;
2366 TRACE( "hwnd %p msg %x (%s) wp %lx lp %lx\n",
2367 info->hwnd, info->msg, SPY_GetMsgName(info->msg, info->hwnd), info->wparam, info->lparam );
2369 USER_CheckNotLock();
2371 if (!put_message_in_queue( info, &reply_size )) return 0;
2373 /* there's no reply to wait for on notify/callback messages */
2374 if (info->type == MSG_NOTIFY || info->type == MSG_CALLBACK) return 1;
2376 wait_message_reply( info->flags );
2377 return retrieve_reply( info, reply_size, res_ptr );
2381 /***********************************************************************
2382 * send_inter_thread_callback
2384 static LRESULT send_inter_thread_callback( HWND hwnd, UINT msg, WPARAM wp, LPARAM lp,
2385 LRESULT *result, void *arg )
2387 struct send_message_info *info = arg;
2392 return send_inter_thread_message( info, result );
2396 /***********************************************************************
2399 * Backend implementation of the various SendMessage functions.
2401 static BOOL send_message( struct send_message_info *info, DWORD_PTR *res_ptr, BOOL unicode )
2407 if (is_broadcast(info->hwnd))
2409 EnumWindows( broadcast_message_callback, (LPARAM)info );
2410 if (res_ptr) *res_ptr = 1;
2414 if (!(info->dest_tid = GetWindowThreadProcessId( info->hwnd, &dest_pid ))) return FALSE;
2416 if (USER_IsExitingThread( info->dest_tid )) return FALSE;
2418 SPY_EnterMessage( SPY_SENDMESSAGE, info->hwnd, info->msg, info->wparam, info->lparam );
2420 if (info->dest_tid == GetCurrentThreadId())
2422 result = call_window_proc( info->hwnd, info->msg, info->wparam, info->lparam,
2423 unicode, TRUE, info->wm_char );
2424 if (info->type == MSG_CALLBACK)
2425 call_sendmsg_callback( info->callback, info->hwnd, info->msg, info->data, result );
2430 if (dest_pid != GetCurrentProcessId() && (info->type == MSG_ASCII || info->type == MSG_UNICODE))
2431 info->type = MSG_OTHER_PROCESS;
2433 /* MSG_ASCII can be sent unconverted except for WM_CHAR; everything else needs to be Unicode */
2434 if (!unicode && is_unicode_message( info->msg ) &&
2435 (info->type != MSG_ASCII || info->msg == WM_CHAR))
2436 ret = WINPROC_CallProcAtoW( send_inter_thread_callback, info->hwnd, info->msg,
2437 info->wparam, info->lparam, &result, info, info->wm_char );
2439 ret = send_inter_thread_message( info, &result );
2442 SPY_ExitMessage( SPY_RESULT_OK, info->hwnd, info->msg, result, info->wparam, info->lparam );
2443 if (ret && res_ptr) *res_ptr = result;
2448 /***********************************************************************
2449 * MSG_SendInternalMessageTimeout
2451 * Same as SendMessageTimeoutW but sends the message to a specific thread
2452 * without requiring a window handle. Only works for internal Wine messages.
2454 LRESULT MSG_SendInternalMessageTimeout( DWORD dest_pid, DWORD dest_tid,
2455 UINT msg, WPARAM wparam, LPARAM lparam,
2456 UINT flags, UINT timeout, PDWORD_PTR res_ptr )
2458 struct send_message_info info;
2459 LRESULT ret, result;
2461 assert( msg & 0x80000000 ); /* must be an internal Wine message */
2463 info.type = MSG_UNICODE;
2464 info.dest_tid = dest_tid;
2467 info.wparam = wparam;
2468 info.lparam = lparam;
2470 info.timeout = timeout;
2472 if (USER_IsExitingThread( dest_tid )) return 0;
2474 if (dest_tid == GetCurrentThreadId())
2476 result = handle_internal_message( 0, msg, wparam, lparam );
2481 if (dest_pid != GetCurrentProcessId()) info.type = MSG_OTHER_PROCESS;
2482 ret = send_inter_thread_message( &info, &result );
2484 if (ret && res_ptr) *res_ptr = result;
2489 /***********************************************************************
2490 * SendMessageTimeoutW (USER32.@)
2492 LRESULT WINAPI SendMessageTimeoutW( HWND hwnd, UINT msg, WPARAM wparam, LPARAM lparam,
2493 UINT flags, UINT timeout, PDWORD_PTR res_ptr )
2495 struct send_message_info info;
2497 info.type = MSG_UNICODE;
2500 info.wparam = wparam;
2501 info.lparam = lparam;
2503 info.timeout = timeout;
2505 return send_message( &info, res_ptr, TRUE );
2508 /***********************************************************************
2509 * SendMessageTimeoutA (USER32.@)
2511 LRESULT WINAPI SendMessageTimeoutA( HWND hwnd, UINT msg, WPARAM wparam, LPARAM lparam,
2512 UINT flags, UINT timeout, PDWORD_PTR res_ptr )
2514 struct send_message_info info;
2516 info.type = MSG_ASCII;
2519 info.wparam = wparam;
2520 info.lparam = lparam;
2522 info.timeout = timeout;
2523 info.wm_char = WMCHAR_MAP_SENDMESSAGETIMEOUT;
2525 return send_message( &info, res_ptr, FALSE );
2529 /***********************************************************************
2530 * SendMessageW (USER32.@)
2532 LRESULT WINAPI SendMessageW( HWND hwnd, UINT msg, WPARAM wparam, LPARAM lparam )
2535 struct send_message_info info;
2537 info.type = MSG_UNICODE;
2540 info.wparam = wparam;
2541 info.lparam = lparam;
2542 info.flags = SMTO_NORMAL;
2545 send_message( &info, &res, TRUE );
2550 /***********************************************************************
2551 * SendMessageA (USER32.@)
2553 LRESULT WINAPI SendMessageA( HWND hwnd, UINT msg, WPARAM wparam, LPARAM lparam )
2556 struct send_message_info info;
2558 info.type = MSG_ASCII;
2561 info.wparam = wparam;
2562 info.lparam = lparam;
2563 info.flags = SMTO_NORMAL;
2565 info.wm_char = WMCHAR_MAP_SENDMESSAGE;
2567 send_message( &info, &res, FALSE );
2572 /***********************************************************************
2573 * SendNotifyMessageA (USER32.@)
2575 BOOL WINAPI SendNotifyMessageA( HWND hwnd, UINT msg, WPARAM wparam, LPARAM lparam )
2577 struct send_message_info info;
2579 if (is_pointer_message(msg))
2581 SetLastError( ERROR_MESSAGE_SYNC_ONLY );
2585 info.type = MSG_NOTIFY;
2588 info.wparam = wparam;
2589 info.lparam = lparam;
2591 info.wm_char = WMCHAR_MAP_SENDMESSAGETIMEOUT;
2593 return send_message( &info, NULL, FALSE );
2597 /***********************************************************************
2598 * SendNotifyMessageW (USER32.@)
2600 BOOL WINAPI SendNotifyMessageW( HWND hwnd, UINT msg, WPARAM wparam, LPARAM lparam )
2602 struct send_message_info info;
2604 if (is_pointer_message(msg))
2606 SetLastError( ERROR_MESSAGE_SYNC_ONLY );
2610 info.type = MSG_NOTIFY;
2613 info.wparam = wparam;
2614 info.lparam = lparam;
2617 return send_message( &info, NULL, TRUE );
2621 /***********************************************************************
2622 * SendMessageCallbackA (USER32.@)
2624 BOOL WINAPI SendMessageCallbackA( HWND hwnd, UINT msg, WPARAM wparam, LPARAM lparam,
2625 SENDASYNCPROC callback, ULONG_PTR data )
2627 struct send_message_info info;
2629 if (is_pointer_message(msg))
2631 SetLastError( ERROR_MESSAGE_SYNC_ONLY );
2635 info.type = MSG_CALLBACK;
2638 info.wparam = wparam;
2639 info.lparam = lparam;
2640 info.callback = callback;
2643 info.wm_char = WMCHAR_MAP_SENDMESSAGETIMEOUT;
2645 return send_message( &info, NULL, FALSE );
2649 /***********************************************************************
2650 * SendMessageCallbackW (USER32.@)
2652 BOOL WINAPI SendMessageCallbackW( HWND hwnd, UINT msg, WPARAM wparam, LPARAM lparam,
2653 SENDASYNCPROC callback, ULONG_PTR data )
2655 struct send_message_info info;
2657 if (is_pointer_message(msg))
2659 SetLastError( ERROR_MESSAGE_SYNC_ONLY );
2663 info.type = MSG_CALLBACK;
2666 info.wparam = wparam;
2667 info.lparam = lparam;
2668 info.callback = callback;
2672 return send_message( &info, NULL, TRUE );
2676 /***********************************************************************
2677 * ReplyMessage (USER32.@)
2679 BOOL WINAPI ReplyMessage( LRESULT result )
2681 struct received_message_info *info = get_user_thread_info()->receive_info;
2683 if (!info) return FALSE;
2684 reply_message( info, result, FALSE );
2689 /***********************************************************************
2690 * InSendMessage (USER32.@)
2692 BOOL WINAPI InSendMessage(void)
2694 return (InSendMessageEx(NULL) & (ISMEX_SEND|ISMEX_REPLIED)) == ISMEX_SEND;
2698 /***********************************************************************
2699 * InSendMessageEx (USER32.@)
2701 DWORD WINAPI InSendMessageEx( LPVOID reserved )
2703 struct received_message_info *info = get_user_thread_info()->receive_info;
2705 if (info) return info->flags;
2706 return ISMEX_NOSEND;
2710 /***********************************************************************
2711 * PostMessageA (USER32.@)
2713 BOOL WINAPI PostMessageA( HWND hwnd, UINT msg, WPARAM wparam, LPARAM lparam )
2715 if (!map_wparam_AtoW( msg, &wparam, WMCHAR_MAP_POSTMESSAGE )) return TRUE;
2716 return PostMessageW( hwnd, msg, wparam, lparam );
2720 /***********************************************************************
2721 * PostMessageW (USER32.@)
2723 BOOL WINAPI PostMessageW( HWND hwnd, UINT msg, WPARAM wparam, LPARAM lparam )
2725 struct send_message_info info;
2727 if (is_pointer_message( msg ))
2729 SetLastError( ERROR_MESSAGE_SYNC_ONLY );
2733 TRACE( "hwnd %p msg %x (%s) wp %lx lp %lx\n",
2734 hwnd, msg, SPY_GetMsgName(msg, hwnd), wparam, lparam );
2736 info.type = MSG_POSTED;
2739 info.wparam = wparam;
2740 info.lparam = lparam;
2743 if (is_broadcast(hwnd))
2745 EnumWindows( broadcast_message_callback, (LPARAM)&info );
2749 if (!hwnd) return PostThreadMessageW( GetCurrentThreadId(), msg, wparam, lparam );
2751 if (!(info.dest_tid = GetWindowThreadProcessId( hwnd, NULL ))) return FALSE;
2753 if (USER_IsExitingThread( info.dest_tid )) return TRUE;
2755 return put_message_in_queue( &info, NULL );
2759 /**********************************************************************
2760 * PostThreadMessageA (USER32.@)
2762 BOOL WINAPI PostThreadMessageA( DWORD thread, UINT msg, WPARAM wparam, LPARAM lparam )
2764 if (!map_wparam_AtoW( msg, &wparam, WMCHAR_MAP_POSTMESSAGE )) return TRUE;
2765 return PostThreadMessageW( thread, msg, wparam, lparam );
2769 /**********************************************************************
2770 * PostThreadMessageW (USER32.@)
2772 BOOL WINAPI PostThreadMessageW( DWORD thread, UINT msg, WPARAM wparam, LPARAM lparam )
2774 struct send_message_info info;
2776 if (is_pointer_message( msg ))
2778 SetLastError( ERROR_MESSAGE_SYNC_ONLY );
2781 if (USER_IsExitingThread( thread )) return TRUE;
2783 info.type = MSG_POSTED;
2784 info.dest_tid = thread;
2787 info.wparam = wparam;
2788 info.lparam = lparam;
2790 return put_message_in_queue( &info, NULL );
2794 /***********************************************************************
2795 * PostQuitMessage (USER32.@)
2797 * Posts a quit message to the current thread's message queue.
2800 * exit_code [I] Exit code to return from message loop.
2806 * This function is not the same as calling:
2807 *|PostThreadMessage(GetCurrentThreadId(), WM_QUIT, exit_code, 0);
2808 * It instead sets a flag in the message queue that signals it to generate
2809 * a WM_QUIT message when there are no other pending sent or posted messages
2812 void WINAPI PostQuitMessage( INT exit_code )
2814 SERVER_START_REQ( post_quit_message )
2816 req->exit_code = exit_code;
2817 wine_server_call( req );
2823 /***********************************************************************
2824 * PeekMessageW (USER32.@)
2826 BOOL WINAPI PeekMessageW( MSG *msg_out, HWND hwnd, UINT first, UINT last, UINT flags )
2828 struct user_thread_info *thread_info = get_user_thread_info();
2831 USER_CheckNotLock();
2833 /* check for graphics events */
2834 USER_Driver->pMsgWaitForMultipleObjectsEx( 0, NULL, 0, QS_ALLINPUT, 0 );
2836 hwnd = WIN_GetFullHandle( hwnd );
2840 if (!peek_message( &msg, hwnd, first, last, flags ))
2842 if (!(flags & PM_NOYIELD))
2845 ReleaseThunkLock(&count);
2847 if (count) RestoreThunkLock(count);
2851 if (msg.message & 0x80000000)
2853 if (!(flags & PM_REMOVE))
2855 /* Have to remove the message explicitly.
2856 Do this before handling it, because the message handler may
2857 call PeekMessage again */
2858 peek_message( &msg, msg.hwnd, msg.message, msg.message, flags | PM_REMOVE );
2860 handle_internal_message( msg.hwnd, msg.message, msg.wParam, msg.lParam );
2865 thread_info->GetMessageTimeVal = msg.time;
2866 msg.pt.x = (short)LOWORD( thread_info->GetMessagePosVal );
2867 msg.pt.y = (short)HIWORD( thread_info->GetMessagePosVal );
2869 HOOK_CallHooks( WH_GETMESSAGE, HC_ACTION, flags & PM_REMOVE, (LPARAM)&msg, TRUE );
2871 /* copy back our internal safe copy of message data to msg_out.
2872 * msg_out is a variable from the *program*, so it can't be used
2873 * internally as it can get "corrupted" by our use of SendMessage()
2874 * (back to the program) inside the message handling itself. */
2877 SetLastError( ERROR_NOACCESS );
2885 /***********************************************************************
2886 * PeekMessageA (USER32.@)
2888 BOOL WINAPI PeekMessageA( MSG *msg, HWND hwnd, UINT first, UINT last, UINT flags )
2890 if (get_pending_wmchar( msg, first, last, (flags & PM_REMOVE) )) return TRUE;
2891 if (!PeekMessageW( msg, hwnd, first, last, flags )) return FALSE;
2892 map_wparam_WtoA( msg, (flags & PM_REMOVE) );
2897 /***********************************************************************
2898 * GetMessageW (USER32.@)
2900 BOOL WINAPI GetMessageW( MSG *msg, HWND hwnd, UINT first, UINT last )
2902 HANDLE server_queue = get_server_queue_handle();
2903 int mask = QS_POSTMESSAGE | QS_SENDMESSAGE; /* Always selected */
2907 if ((first <= WM_KEYLAST) && (last >= WM_KEYFIRST)) mask |= QS_KEY;
2908 if ( ((first <= WM_MOUSELAST) && (last >= WM_MOUSEFIRST)) ||
2909 ((first <= WM_NCMOUSELAST) && (last >= WM_NCMOUSEFIRST)) ) mask |= QS_MOUSE;
2910 if ((first <= WM_TIMER) && (last >= WM_TIMER)) mask |= QS_TIMER;
2911 if ((first <= WM_SYSTIMER) && (last >= WM_SYSTIMER)) mask |= QS_TIMER;
2912 if ((first <= WM_PAINT) && (last >= WM_PAINT)) mask |= QS_PAINT;
2914 else mask = QS_ALLINPUT;
2916 while (!PeekMessageW( msg, hwnd, first, last, PM_REMOVE | PM_NOYIELD | (mask << 16) ))
2920 ReleaseThunkLock( &dwlc );
2921 USER_Driver->pMsgWaitForMultipleObjectsEx( 1, &server_queue, INFINITE, mask, 0 );
2922 if (dwlc) RestoreThunkLock( dwlc );
2925 return (msg->message != WM_QUIT);
2929 /***********************************************************************
2930 * GetMessageA (USER32.@)
2932 BOOL WINAPI GetMessageA( MSG *msg, HWND hwnd, UINT first, UINT last )
2934 if (get_pending_wmchar( msg, first, last, TRUE )) return TRUE;
2935 GetMessageW( msg, hwnd, first, last );
2936 map_wparam_WtoA( msg, TRUE );
2937 return (msg->message != WM_QUIT);
2941 /***********************************************************************
2942 * IsDialogMessageA (USER32.@)
2943 * IsDialogMessage (USER32.@)
2945 BOOL WINAPI IsDialogMessageA( HWND hwndDlg, LPMSG pmsg )
2948 map_wparam_AtoW( msg.message, &msg.wParam, WMCHAR_MAP_NOMAPPING );
2949 return IsDialogMessageW( hwndDlg, &msg );
2953 /***********************************************************************
2954 * TranslateMessage (USER32.@)
2956 * Implementation of TranslateMessage.
2958 * TranslateMessage translates virtual-key messages into character-messages,
2960 * WM_KEYDOWN/WM_KEYUP combinations produce a WM_CHAR or WM_DEADCHAR message.
2961 * ditto replacing WM_* with WM_SYS*
2962 * This produces WM_CHAR messages only for keys mapped to ASCII characters
2963 * by the keyboard driver.
2965 * If the message is WM_KEYDOWN, WM_KEYUP, WM_SYSKEYDOWN, or WM_SYSKEYUP, the
2966 * return value is nonzero, regardless of the translation.
2969 BOOL WINAPI TranslateMessage( const MSG *msg )
2975 if (msg->message < WM_KEYFIRST || msg->message > WM_KEYLAST) return FALSE;
2976 if (msg->message != WM_KEYDOWN && msg->message != WM_SYSKEYDOWN) return TRUE;
2978 TRACE_(key)("Translating key %s (%04lx), scancode %02x\n",
2979 SPY_GetVKeyName(msg->wParam), msg->wParam, LOBYTE(HIWORD(msg->lParam)));
2981 GetKeyboardState( state );
2982 /* FIXME : should handle ToUnicode yielding 2 */
2983 switch (ToUnicode(msg->wParam, HIWORD(msg->lParam), state, wp, 2, 0))
2986 message = (msg->message == WM_KEYDOWN) ? WM_CHAR : WM_SYSCHAR;
2987 TRACE_(key)("1 -> PostMessageW(%p,%s,%04x,%08lx)\n",
2988 msg->hwnd, SPY_GetMsgName(message, msg->hwnd), wp[0], msg->lParam);
2989 PostMessageW( msg->hwnd, message, wp[0], msg->lParam );
2993 message = (msg->message == WM_KEYDOWN) ? WM_DEADCHAR : WM_SYSDEADCHAR;
2994 TRACE_(key)("-1 -> PostMessageW(%p,%s,%04x,%08lx)\n",
2995 msg->hwnd, SPY_GetMsgName(message, msg->hwnd), wp[0], msg->lParam);
2996 PostMessageW( msg->hwnd, message, wp[0], msg->lParam );
3003 /***********************************************************************
3004 * DispatchMessageA (USER32.@)
3006 * See DispatchMessageW.
3008 LRESULT WINAPI DispatchMessageA( const MSG* msg )
3012 /* Process timer messages */
3013 if ((msg->message == WM_TIMER) || (msg->message == WM_SYSTIMER))
3015 if (msg->lParam) return CallWindowProcA( (WNDPROC)msg->lParam, msg->hwnd,
3016 msg->message, msg->wParam, GetTickCount() );
3018 if (!msg->hwnd) return 0;
3020 SPY_EnterMessage( SPY_DISPATCHMESSAGE, msg->hwnd, msg->message,
3021 msg->wParam, msg->lParam );
3023 if (!WINPROC_call_window( msg->hwnd, msg->message, msg->wParam, msg->lParam,
3024 &retval, FALSE, WMCHAR_MAP_DISPATCHMESSAGE ))
3026 if (!IsWindow( msg->hwnd )) SetLastError( ERROR_INVALID_WINDOW_HANDLE );
3027 else SetLastError( ERROR_MESSAGE_SYNC_ONLY );
3031 SPY_ExitMessage( SPY_RESULT_OK, msg->hwnd, msg->message, retval,
3032 msg->wParam, msg->lParam );
3034 if (msg->message == WM_PAINT)
3036 /* send a WM_NCPAINT and WM_ERASEBKGND if the non-client area is still invalid */
3037 HRGN hrgn = CreateRectRgn( 0, 0, 0, 0 );
3038 GetUpdateRgn( msg->hwnd, hrgn, TRUE );
3039 DeleteObject( hrgn );
3045 /***********************************************************************
3046 * DispatchMessageW (USER32.@) Process a message
3048 * Process the message specified in the structure *_msg_.
3050 * If the lpMsg parameter points to a WM_TIMER message and the
3051 * parameter of the WM_TIMER message is not NULL, the lParam parameter
3052 * points to the function that is called instead of the window
3055 * The message must be valid.
3059 * DispatchMessage() returns the result of the window procedure invoked.
3066 LRESULT WINAPI DispatchMessageW( const MSG* msg )
3070 /* Process timer messages */
3071 if ((msg->message == WM_TIMER) || (msg->message == WM_SYSTIMER))
3073 if (msg->lParam) return CallWindowProcW( (WNDPROC)msg->lParam, msg->hwnd,
3074 msg->message, msg->wParam, GetTickCount() );
3076 if (!msg->hwnd) return 0;
3078 SPY_EnterMessage( SPY_DISPATCHMESSAGE, msg->hwnd, msg->message,
3079 msg->wParam, msg->lParam );
3081 if (!WINPROC_call_window( msg->hwnd, msg->message, msg->wParam, msg->lParam,
3082 &retval, TRUE, WMCHAR_MAP_DISPATCHMESSAGE ))
3084 if (!IsWindow( msg->hwnd )) SetLastError( ERROR_INVALID_WINDOW_HANDLE );
3085 else SetLastError( ERROR_MESSAGE_SYNC_ONLY );
3089 SPY_ExitMessage( SPY_RESULT_OK, msg->hwnd, msg->message, retval,
3090 msg->wParam, msg->lParam );
3092 if (msg->message == WM_PAINT)
3094 /* send a WM_NCPAINT and WM_ERASEBKGND if the non-client area is still invalid */
3095 HRGN hrgn = CreateRectRgn( 0, 0, 0, 0 );
3096 GetUpdateRgn( msg->hwnd, hrgn, TRUE );
3097 DeleteObject( hrgn );
3103 /***********************************************************************
3104 * GetMessagePos (USER.119)
3105 * GetMessagePos (USER32.@)
3107 * The GetMessagePos() function returns a long value representing a
3108 * cursor position, in screen coordinates, when the last message
3109 * retrieved by the GetMessage() function occurs. The x-coordinate is
3110 * in the low-order word of the return value, the y-coordinate is in
3111 * the high-order word. The application can use the MAKEPOINT()
3112 * macro to obtain a POINT structure from the return value.
3114 * For the current cursor position, use GetCursorPos().
3118 * Cursor position of last message on success, zero on failure.
3125 DWORD WINAPI GetMessagePos(void)
3127 return get_user_thread_info()->GetMessagePosVal;
3131 /***********************************************************************
3132 * GetMessageTime (USER.120)
3133 * GetMessageTime (USER32.@)
3135 * GetMessageTime() returns the message time for the last message
3136 * retrieved by the function. The time is measured in milliseconds with
3137 * the same offset as GetTickCount().
3139 * Since the tick count wraps, this is only useful for moderately short
3140 * relative time comparisons.
3144 * Time of last message on success, zero on failure.
3146 LONG WINAPI GetMessageTime(void)
3148 return get_user_thread_info()->GetMessageTimeVal;
3152 /***********************************************************************
3153 * GetMessageExtraInfo (USER.288)
3154 * GetMessageExtraInfo (USER32.@)
3156 LPARAM WINAPI GetMessageExtraInfo(void)
3158 return get_user_thread_info()->GetMessageExtraInfoVal;
3162 /***********************************************************************
3163 * SetMessageExtraInfo (USER32.@)
3165 LPARAM WINAPI SetMessageExtraInfo(LPARAM lParam)
3167 struct user_thread_info *thread_info = get_user_thread_info();
3168 LONG old_value = thread_info->GetMessageExtraInfoVal;
3169 thread_info->GetMessageExtraInfoVal = lParam;
3174 /***********************************************************************
3175 * WaitMessage (USER.112) Suspend thread pending messages
3176 * WaitMessage (USER32.@) Suspend thread pending messages
3178 * WaitMessage() suspends a thread until events appear in the thread's
3181 BOOL WINAPI WaitMessage(void)
3183 return (MsgWaitForMultipleObjectsEx( 0, NULL, INFINITE, QS_ALLINPUT, 0 ) != WAIT_FAILED);
3187 /***********************************************************************
3188 * MsgWaitForMultipleObjectsEx (USER32.@)
3190 DWORD WINAPI MsgWaitForMultipleObjectsEx( DWORD count, CONST HANDLE *pHandles,
3191 DWORD timeout, DWORD mask, DWORD flags )
3193 HANDLE handles[MAXIMUM_WAIT_OBJECTS];
3196 if (count > MAXIMUM_WAIT_OBJECTS-1)
3198 SetLastError( ERROR_INVALID_PARAMETER );
3202 /* set the queue mask */
3203 SERVER_START_REQ( set_queue_mask )
3205 req->wake_mask = (flags & MWMO_INPUTAVAILABLE) ? mask : 0;
3206 req->changed_mask = mask;
3208 wine_server_call( req );
3212 /* add the queue to the handle list */
3213 for (i = 0; i < count; i++) handles[i] = pHandles[i];
3214 handles[count] = get_server_queue_handle();
3216 ReleaseThunkLock( &lock );
3217 ret = USER_Driver->pMsgWaitForMultipleObjectsEx( count+1, handles, timeout, mask, flags );
3218 if (lock) RestoreThunkLock( lock );
3223 /***********************************************************************
3224 * MsgWaitForMultipleObjects (USER32.@)
3226 DWORD WINAPI MsgWaitForMultipleObjects( DWORD count, CONST HANDLE *handles,
3227 BOOL wait_all, DWORD timeout, DWORD mask )
3229 return MsgWaitForMultipleObjectsEx( count, handles, timeout, mask,
3230 wait_all ? MWMO_WAITALL : 0 );
3234 /***********************************************************************
3235 * WaitForInputIdle (USER32.@)
3237 DWORD WINAPI WaitForInputIdle( HANDLE hProcess, DWORD dwTimeOut )
3239 DWORD start_time, elapsed, ret;
3242 handles[0] = hProcess;
3243 SERVER_START_REQ( get_process_idle_event )
3245 req->handle = hProcess;
3246 if (!(ret = wine_server_call_err( req ))) handles[1] = reply->event;
3249 if (ret) return WAIT_FAILED; /* error */
3250 if (!handles[1]) return 0; /* no event to wait on */
3252 start_time = GetTickCount();
3255 TRACE("waiting for %p\n", handles[1] );
3258 ret = MsgWaitForMultipleObjects ( 2, handles, FALSE, dwTimeOut - elapsed, QS_SENDMESSAGE );
3263 case WAIT_OBJECT_0+2:
3264 process_sent_messages();
3268 TRACE("timeout or error\n");
3271 TRACE("finished\n");
3274 if (dwTimeOut != INFINITE)
3276 elapsed = GetTickCount() - start_time;
3277 if (elapsed > dwTimeOut)
3283 return WAIT_TIMEOUT;
3287 /***********************************************************************
3288 * UserYield (USER.332)
3290 void WINAPI UserYield16(void)
3294 /* Handle sent messages */
3295 process_sent_messages();
3298 ReleaseThunkLock(&count);
3302 RestoreThunkLock(count);
3303 /* Handle sent messages again */
3304 process_sent_messages();
3309 /***********************************************************************
3310 * RegisterWindowMessageA (USER32.@)
3311 * RegisterWindowMessage (USER.118)
3313 UINT WINAPI RegisterWindowMessageA( LPCSTR str )
3315 UINT ret = GlobalAddAtomA(str);
3316 TRACE("%s, ret=%x\n", str, ret);
3321 /***********************************************************************
3322 * RegisterWindowMessageW (USER32.@)
3324 UINT WINAPI RegisterWindowMessageW( LPCWSTR str )
3326 UINT ret = GlobalAddAtomW(str);
3327 TRACE("%s ret=%x\n", debugstr_w(str), ret);
3332 /***********************************************************************
3333 * BroadcastSystemMessageA (USER32.@)
3334 * BroadcastSystemMessage (USER32.@)
3336 LONG WINAPI BroadcastSystemMessageA( DWORD flags, LPDWORD recipients, UINT msg, WPARAM wp, LPARAM lp )
3338 if ((*recipients & BSM_APPLICATIONS) || (*recipients == BSM_ALLCOMPONENTS))
3340 FIXME( "(%08x,%08x,%08x,%08lx,%08lx): semi-stub!\n", flags, *recipients, msg, wp, lp );
3341 PostMessageA( HWND_BROADCAST, msg, wp, lp );
3346 FIXME( "(%08x,%08x,%08x,%08lx,%08lx): stub!\n", flags, *recipients, msg, wp, lp);
3352 /***********************************************************************
3353 * BroadcastSystemMessageW (USER32.@)
3355 LONG WINAPI BroadcastSystemMessageW( DWORD flags, LPDWORD recipients, UINT msg, WPARAM wp, LPARAM lp )
3357 if ((*recipients & BSM_APPLICATIONS) || (*recipients == BSM_ALLCOMPONENTS))
3359 FIXME( "(%08x,%08x,%08x,%08lx,%08lx): semi-stub!\n", flags, *recipients, msg, wp, lp );
3360 PostMessageW( HWND_BROADCAST, msg, wp, lp );
3365 FIXME( "(%08x,%08x,%08x,%08lx,%08lx): stub!\n", flags, *recipients, msg, wp, lp );
3371 /***********************************************************************
3372 * SetMessageQueue (USER32.@)
3374 BOOL WINAPI SetMessageQueue( INT size )
3376 /* now obsolete the message queue will be expanded dynamically as necessary */
3381 /***********************************************************************
3382 * MessageBeep (USER32.@)
3384 BOOL WINAPI MessageBeep( UINT i )
3387 SystemParametersInfoA( SPI_GETBEEP, 0, &active, FALSE );
3388 if (active) USER_Driver->pBeep();
3393 /***********************************************************************
3394 * SetTimer (USER32.@)
3396 UINT_PTR WINAPI SetTimer( HWND hwnd, UINT_PTR id, UINT timeout, TIMERPROC proc )
3399 WNDPROC winproc = 0;
3401 if (proc) winproc = WINPROC_AllocProc( (WNDPROC)proc, NULL );
3403 SERVER_START_REQ( set_win_timer )
3406 req->msg = WM_TIMER;
3408 req->rate = max( timeout, SYS_TIMER_RATE );
3409 req->lparam = (unsigned long)winproc;
3410 if (!wine_server_call_err( req ))
3413 if (!ret) ret = TRUE;
3419 TRACE("Added %p %lx %p timeout %d\n", hwnd, id, winproc, timeout );
3424 /***********************************************************************
3425 * SetSystemTimer (USER32.@)
3427 UINT_PTR WINAPI SetSystemTimer( HWND hwnd, UINT_PTR id, UINT timeout, TIMERPROC proc )
3430 WNDPROC winproc = 0;
3432 if (proc) winproc = WINPROC_AllocProc( (WNDPROC)proc, NULL );
3434 SERVER_START_REQ( set_win_timer )
3437 req->msg = WM_SYSTIMER;
3439 req->rate = max( timeout, SYS_TIMER_RATE );
3440 req->lparam = (unsigned long)winproc;
3441 if (!wine_server_call_err( req ))
3444 if (!ret) ret = TRUE;
3450 TRACE("Added %p %lx %p timeout %d\n", hwnd, id, winproc, timeout );
3455 /***********************************************************************
3456 * KillTimer (USER32.@)
3458 BOOL WINAPI KillTimer( HWND hwnd, UINT_PTR id )
3462 SERVER_START_REQ( kill_win_timer )
3465 req->msg = WM_TIMER;
3467 ret = !wine_server_call_err( req );
3474 /***********************************************************************
3475 * KillSystemTimer (USER32.@)
3477 BOOL WINAPI KillSystemTimer( HWND hwnd, UINT_PTR id )
3481 SERVER_START_REQ( kill_win_timer )
3484 req->msg = WM_SYSTIMER;
3486 ret = !wine_server_call_err( req );
3493 /**********************************************************************
3494 * GetGUIThreadInfo (USER32.@)
3496 BOOL WINAPI GetGUIThreadInfo( DWORD id, GUITHREADINFO *info )
3500 SERVER_START_REQ( get_thread_input )
3503 if ((ret = !wine_server_call_err( req )))
3506 info->hwndActive = reply->active;
3507 info->hwndFocus = reply->focus;
3508 info->hwndCapture = reply->capture;
3509 info->hwndMenuOwner = reply->menu_owner;
3510 info->hwndMoveSize = reply->move_size;
3511 info->hwndCaret = reply->caret;
3512 info->rcCaret.left = reply->rect.left;
3513 info->rcCaret.top = reply->rect.top;
3514 info->rcCaret.right = reply->rect.right;
3515 info->rcCaret.bottom = reply->rect.bottom;
3516 if (reply->menu_owner) info->flags |= GUI_INMENUMODE;
3517 if (reply->move_size) info->flags |= GUI_INMOVESIZE;
3518 if (reply->caret) info->flags |= GUI_CARETBLINKING;
3526 /******************************************************************
3527 * IsHungAppWindow (USER32.@)
3530 BOOL WINAPI IsHungAppWindow( HWND hWnd )
3534 SERVER_START_REQ( is_window_hung )
3537 ret = !wine_server_call_err( req ) && reply->is_hung;