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 &&
1706 !MENU_IsMenuActive())
1709 hi.cbSize = sizeof(HELPINFO);
1710 hi.iContextType = HELPINFO_WINDOW;
1711 hi.iCtrlId = GetWindowLongPtrA( msg->hwnd, GWLP_ID );
1712 hi.hItemHandle = msg->hwnd;
1713 hi.dwContextId = GetWindowContextHelpId( msg->hwnd );
1714 hi.MousePos = msg->pt;
1715 SendMessageW( msg->hwnd, WM_HELP, 0, (LPARAM)&hi );
1717 else if(msg->wParam >= VK_BROWSER_BACK &&
1718 msg->wParam <= VK_LAUNCH_APP2)
1720 /* FIXME: Process keystate */
1721 SendMessageW(msg->hwnd, WM_APPCOMMAND, (WPARAM)msg->hwnd, MAKELPARAM(0, (FAPPCOMMAND_KEY | (msg->wParam - VK_BROWSER_BACK + 1))));
1724 else if (msg->message == WM_KEYUP)
1726 /* Handle VK_APPS key by posting a WM_CONTEXTMENU message */
1727 if (msg->wParam == VK_APPS && !MENU_IsMenuActive())
1728 PostMessageW(msg->hwnd, WM_CONTEXTMENU, (WPARAM)msg->hwnd, (LPARAM)-1);
1732 if (HOOK_CallHooks( WH_KEYBOARD, remove ? HC_ACTION : HC_NOREMOVE,
1733 LOWORD(msg->wParam), msg->lParam, TRUE ))
1735 /* skip this message */
1736 HOOK_CallHooks( WH_CBT, HCBT_KEYSKIPPED, LOWORD(msg->wParam), msg->lParam, TRUE );
1737 accept_hardware_message( hw_id, TRUE, 0 );
1740 accept_hardware_message( hw_id, remove, 0 );
1745 /***********************************************************************
1746 * process_mouse_message
1748 * returns TRUE if the contents of 'msg' should be passed to the application
1750 static BOOL process_mouse_message( MSG *msg, UINT hw_id, ULONG_PTR extra_info, HWND hwnd_filter,
1751 UINT first, UINT last, BOOL remove )
1760 MOUSEHOOKSTRUCT hook;
1763 /* find the window to dispatch this mouse message to */
1765 GetGUIThreadInfo( GetCurrentThreadId(), &info );
1766 if (info.hwndCapture)
1769 msg->hwnd = info.hwndCapture;
1773 msg->hwnd = WINPOS_WindowFromPoint( msg->hwnd, msg->pt, &hittest );
1776 if (!msg->hwnd || !WIN_IsCurrentThread( msg->hwnd ))
1778 accept_hardware_message( hw_id, TRUE, msg->hwnd );
1782 /* FIXME: is this really the right place for this hook? */
1783 event.message = msg->message;
1784 event.time = msg->time;
1785 event.hwnd = msg->hwnd;
1786 event.paramL = msg->pt.x;
1787 event.paramH = msg->pt.y;
1788 HOOK_CallHooks( WH_JOURNALRECORD, HC_ACTION, 0, (LPARAM)&event, TRUE );
1790 if (!check_hwnd_filter( msg, hwnd_filter )) return FALSE;
1793 message = msg->message;
1794 /* Note: windows has no concept of a non-client wheel message */
1795 if (message != WM_MOUSEWHEEL)
1797 if (hittest != HTCLIENT)
1799 message += WM_NCMOUSEMOVE - WM_MOUSEMOVE;
1800 msg->wParam = hittest;
1804 /* coordinates don't get translated while tracking a menu */
1805 /* FIXME: should differentiate popups and top-level menus */
1806 if (!(info.flags & GUI_INMENUMODE))
1807 ScreenToClient( msg->hwnd, &pt );
1810 msg->lParam = MAKELONG( pt.x, pt.y );
1812 /* translate double clicks */
1814 if ((msg->message == WM_LBUTTONDOWN) ||
1815 (msg->message == WM_RBUTTONDOWN) ||
1816 (msg->message == WM_MBUTTONDOWN) ||
1817 (msg->message == WM_XBUTTONDOWN))
1819 BOOL update = remove;
1821 /* translate double clicks -
1822 * note that ...MOUSEMOVEs can slip in between
1823 * ...BUTTONDOWN and ...BUTTONDBLCLK messages */
1825 if ((info.flags & (GUI_INMENUMODE|GUI_INMOVESIZE)) ||
1826 hittest != HTCLIENT ||
1827 (GetClassLongA( msg->hwnd, GCL_STYLE ) & CS_DBLCLKS))
1829 if ((msg->message == clk_msg.message) &&
1830 (msg->hwnd == clk_msg.hwnd) &&
1831 (msg->wParam == clk_msg.wParam) &&
1832 (msg->time - clk_msg.time < GetDoubleClickTime()) &&
1833 (abs(msg->pt.x - clk_msg.pt.x) < GetSystemMetrics(SM_CXDOUBLECLK)/2) &&
1834 (abs(msg->pt.y - clk_msg.pt.y) < GetSystemMetrics(SM_CYDOUBLECLK)/2))
1836 message += (WM_LBUTTONDBLCLK - WM_LBUTTONDOWN);
1839 clk_msg.message = 0; /* clear the double click conditions */
1844 if (message < first || message > last) return FALSE;
1845 /* update static double click conditions */
1846 if (update) clk_msg = *msg;
1850 if (message < first || message > last) return FALSE;
1853 /* message is accepted now (but may still get dropped) */
1856 hook.hwnd = msg->hwnd;
1857 hook.wHitTestCode = hittest;
1858 hook.dwExtraInfo = extra_info;
1859 if (HOOK_CallHooks( WH_MOUSE, remove ? HC_ACTION : HC_NOREMOVE,
1860 message, (LPARAM)&hook, TRUE ))
1863 hook.hwnd = msg->hwnd;
1864 hook.wHitTestCode = hittest;
1865 hook.dwExtraInfo = extra_info;
1866 HOOK_CallHooks( WH_CBT, HCBT_CLICKSKIPPED, message, (LPARAM)&hook, TRUE );
1867 accept_hardware_message( hw_id, TRUE, 0 );
1871 if ((hittest == HTERROR) || (hittest == HTNOWHERE))
1873 SendMessageW( msg->hwnd, WM_SETCURSOR, (WPARAM)msg->hwnd,
1874 MAKELONG( hittest, msg->message ));
1875 accept_hardware_message( hw_id, TRUE, 0 );
1879 accept_hardware_message( hw_id, remove, 0 );
1881 if (!remove || info.hwndCapture)
1883 msg->message = message;
1889 if ((msg->message == WM_LBUTTONDOWN) ||
1890 (msg->message == WM_RBUTTONDOWN) ||
1891 (msg->message == WM_MBUTTONDOWN) ||
1892 (msg->message == WM_XBUTTONDOWN))
1894 /* Send the WM_PARENTNOTIFY,
1895 * note that even for double/nonclient clicks
1896 * notification message is still WM_L/M/RBUTTONDOWN.
1898 send_parent_notify( msg->hwnd, msg->message, 0, msg->pt );
1900 /* Activate the window if needed */
1902 if (msg->hwnd != info.hwndActive)
1904 HWND hwndTop = msg->hwnd;
1907 if ((GetWindowLongW( hwndTop, GWL_STYLE ) & (WS_POPUP|WS_CHILD)) != WS_CHILD) break;
1908 hwndTop = GetParent( hwndTop );
1911 if (hwndTop && hwndTop != GetDesktopWindow())
1913 LONG ret = SendMessageW( msg->hwnd, WM_MOUSEACTIVATE, (WPARAM)hwndTop,
1914 MAKELONG( hittest, msg->message ) );
1917 case MA_NOACTIVATEANDEAT:
1922 case MA_ACTIVATEANDEAT:
1927 if (!FOCUS_MouseActivate( hwndTop )) eatMsg = TRUE;
1930 WARN( "unknown WM_MOUSEACTIVATE code %d\n", ret );
1937 /* send the WM_SETCURSOR message */
1939 /* Windows sends the normal mouse message as the message parameter
1940 in the WM_SETCURSOR message even if it's non-client mouse message */
1941 SendMessageW( msg->hwnd, WM_SETCURSOR, (WPARAM)msg->hwnd, MAKELONG( hittest, msg->message ));
1943 msg->message = message;
1948 /***********************************************************************
1949 * process_hardware_message
1951 * Process a hardware message; return TRUE if message should be passed on to the app
1953 static BOOL process_hardware_message( MSG *msg, UINT hw_id, ULONG_PTR extra_info, HWND hwnd_filter,
1954 UINT first, UINT last, BOOL remove )
1956 if (is_keyboard_message( msg->message ))
1957 return process_keyboard_message( msg, hw_id, hwnd_filter, first, last, remove );
1959 if (is_mouse_message( msg->message ))
1960 return process_mouse_message( msg, hw_id, extra_info, hwnd_filter, first, last, remove );
1962 ERR( "unknown message type %x\n", msg->message );
1967 /***********************************************************************
1968 * call_sendmsg_callback
1970 * Call the callback function of SendMessageCallback.
1972 static inline void call_sendmsg_callback( SENDASYNCPROC callback, HWND hwnd, UINT msg,
1973 ULONG_PTR data, LRESULT result )
1975 if (!callback) return;
1977 if (TRACE_ON(relay))
1978 DPRINTF( "%04x:Call message callback %p (hwnd=%p,msg=%s,data=%08lx,result=%08lx)\n",
1979 GetCurrentThreadId(), callback, hwnd, SPY_GetMsgName( msg, hwnd ),
1981 callback( hwnd, msg, data, result );
1982 if (TRACE_ON(relay))
1983 DPRINTF( "%04x:Ret message callback %p (hwnd=%p,msg=%s,data=%08lx,result=%08lx)\n",
1984 GetCurrentThreadId(), callback, hwnd, SPY_GetMsgName( msg, hwnd ),
1989 /***********************************************************************
1992 * Peek for a message matching the given parameters. Return FALSE if none available.
1993 * All pending sent messages are processed before returning.
1995 static BOOL peek_message( MSG *msg, HWND hwnd, UINT first, UINT last, UINT flags )
1998 ULONG_PTR extra_info = 0;
1999 struct user_thread_info *thread_info = get_user_thread_info();
2000 struct received_message_info info, *old_info;
2001 unsigned int wake_mask, changed_mask = HIWORD(flags);
2002 unsigned int hw_id = 0; /* id of previous hardware message */
2004 if (!first && !last) last = ~0;
2005 if (!changed_mask) changed_mask = QS_ALLINPUT;
2006 wake_mask = changed_mask & (QS_SENDMESSAGE | QS_SMRESULT);
2011 void *buffer = NULL;
2012 size_t size = 0, buffer_size = 0;
2014 do /* loop while buffer is too small */
2016 if (buffer_size && !(buffer = HeapAlloc( GetProcessHeap(), 0, buffer_size )))
2018 SERVER_START_REQ( get_message )
2021 req->get_win = hwnd;
2022 req->get_first = first;
2023 req->get_last = last;
2025 req->wake_mask = wake_mask;
2026 req->changed_mask = changed_mask;
2027 if (buffer_size) wine_server_set_reply( req, buffer, buffer_size );
2028 if (!(res = wine_server_call( req )))
2030 size = wine_server_reply_size( reply );
2031 info.type = reply->type;
2032 info.msg.hwnd = reply->win;
2033 info.msg.message = reply->msg;
2034 info.msg.wParam = reply->wparam;
2035 info.msg.lParam = reply->lparam;
2036 info.msg.time = reply->time;
2037 info.msg.pt.x = reply->x;
2038 info.msg.pt.y = reply->y;
2039 hw_id = reply->hw_id;
2040 extra_info = reply->info;
2041 thread_info->active_hooks = reply->active_hooks;
2045 HeapFree( GetProcessHeap(), 0, buffer );
2046 buffer_size = reply->total;
2050 } while (res == STATUS_BUFFER_OVERFLOW);
2052 if (res) return FALSE;
2054 TRACE( "got type %d msg %x (%s) hwnd %p wp %lx lp %lx\n",
2055 info.type, info.msg.message,
2056 (info.type == MSG_WINEVENT) ? "MSG_WINEVENT" : SPY_GetMsgName(info.msg.message, info.msg.hwnd),
2057 info.msg.hwnd, info.msg.wParam, info.msg.lParam );
2063 info.flags = ISMEX_SEND;
2066 info.flags = ISMEX_NOTIFY;
2069 info.flags = ISMEX_CALLBACK;
2071 case MSG_CALLBACK_RESULT:
2072 if (size >= sizeof(struct callback_msg_data))
2074 const struct callback_msg_data *data = (const struct callback_msg_data *)buffer;
2075 call_sendmsg_callback( data->callback, info.msg.hwnd,
2076 info.msg.message, data->data, data->result );
2080 if (size >= sizeof(struct winevent_msg_data))
2082 WINEVENTPROC hook_proc;
2083 const struct winevent_msg_data *data = (const struct winevent_msg_data *)buffer;
2085 hook_proc = data->hook_proc;
2086 size -= sizeof(*data);
2089 WCHAR module[MAX_PATH];
2091 size = min( size, (MAX_PATH - 1) * sizeof(WCHAR) );
2092 memcpy( module, buffer, size );
2093 module[size / sizeof(WCHAR)] = 0;
2094 if (!(hook_proc = get_hook_proc( hook_proc, module )))
2096 ERR( "invalid winevent hook module name %s\n", debugstr_w(module) );
2101 if (TRACE_ON(relay))
2102 DPRINTF( "%04x:Call winevent proc %p (hook=%p,event=%x,hwnd=%p,object_id=%lx,child_id=%lx,tid=%04x,time=%x)\n",
2103 GetCurrentThreadId(), hook_proc,
2104 data->hook, info.msg.message, info.msg.hwnd, info.msg.wParam,
2105 info.msg.lParam, data->tid, info.msg.time);
2107 hook_proc( data->hook, info.msg.message, info.msg.hwnd, info.msg.wParam,
2108 info.msg.lParam, data->tid, info.msg.time );
2110 if (TRACE_ON(relay))
2111 DPRINTF( "%04x:Ret winevent proc %p (hook=%p,event=%x,hwnd=%p,object_id=%lx,child_id=%lx,tid=%04x,time=%x)\n",
2112 GetCurrentThreadId(), hook_proc,
2113 data->hook, info.msg.message, info.msg.hwnd, info.msg.wParam,
2114 info.msg.lParam, data->tid, info.msg.time);
2117 case MSG_OTHER_PROCESS:
2118 info.flags = ISMEX_SEND;
2119 if (!unpack_message( info.msg.hwnd, info.msg.message, &info.msg.wParam,
2120 &info.msg.lParam, &buffer, size ))
2123 reply_message( &info, 0, TRUE );
2128 if (!process_hardware_message( &info.msg, hw_id, extra_info,
2129 hwnd, first, last, flags & PM_REMOVE ))
2131 TRACE("dropping msg %x\n", info.msg.message );
2132 goto next; /* ignore it */
2134 thread_info->GetMessagePosVal = MAKELONG( info.msg.pt.x, info.msg.pt.y );
2137 thread_info->GetMessageExtraInfoVal = extra_info;
2138 if (info.msg.message >= WM_DDE_FIRST && info.msg.message <= WM_DDE_LAST)
2140 if (!unpack_dde_message( info.msg.hwnd, info.msg.message, &info.msg.wParam,
2141 &info.msg.lParam, &buffer, size ))
2142 goto next; /* ignore it */
2145 HeapFree( GetProcessHeap(), 0, buffer );
2149 /* if we get here, we have a sent message; call the window procedure */
2150 old_info = thread_info->receive_info;
2151 thread_info->receive_info = &info;
2152 result = call_window_proc( info.msg.hwnd, info.msg.message, info.msg.wParam,
2153 info.msg.lParam, (info.type != MSG_ASCII), FALSE,
2154 WMCHAR_MAP_RECVMESSAGE );
2155 reply_message( &info, result, TRUE );
2156 thread_info->receive_info = old_info;
2158 /* if some PM_QS* flags were specified, only handle sent messages from now on */
2159 if (HIWORD(flags)) flags = PM_QS_SENDMESSAGE | LOWORD(flags);
2161 HeapFree( GetProcessHeap(), 0, buffer );
2166 /***********************************************************************
2167 * process_sent_messages
2169 * Process all pending sent messages.
2171 static inline void process_sent_messages(void)
2174 peek_message( &msg, 0, 0, 0, PM_REMOVE | PM_QS_SENDMESSAGE );
2178 /***********************************************************************
2179 * get_server_queue_handle
2181 * Get a handle to the server message queue for the current thread.
2183 static HANDLE get_server_queue_handle(void)
2185 struct user_thread_info *thread_info = get_user_thread_info();
2188 if (!(ret = thread_info->server_queue))
2190 SERVER_START_REQ( get_msg_queue )
2192 wine_server_call( req );
2193 ret = reply->handle;
2196 thread_info->server_queue = ret;
2197 if (!ret) ERR( "Cannot get server thread queue\n" );
2203 /***********************************************************************
2204 * wait_message_reply
2206 * Wait until a sent message gets replied to.
2208 static void wait_message_reply( UINT flags )
2210 HANDLE server_queue = get_server_queue_handle();
2214 unsigned int wake_bits = 0, changed_bits = 0;
2217 SERVER_START_REQ( set_queue_mask )
2219 req->wake_mask = QS_SMRESULT | ((flags & SMTO_BLOCK) ? 0 : QS_SENDMESSAGE);
2220 req->changed_mask = req->wake_mask;
2222 if (!wine_server_call( req ))
2224 wake_bits = reply->wake_bits;
2225 changed_bits = reply->changed_bits;
2230 if (wake_bits & QS_SMRESULT) return; /* got a result */
2231 if (wake_bits & QS_SENDMESSAGE)
2233 /* Process the sent message immediately */
2234 process_sent_messages();
2238 /* now wait for it */
2240 ReleaseThunkLock( &dwlc );
2241 res = USER_Driver->pMsgWaitForMultipleObjectsEx( 1, &server_queue,
2242 INFINITE, QS_SENDMESSAGE, 0 );
2243 if (dwlc) RestoreThunkLock( dwlc );
2247 /***********************************************************************
2248 * put_message_in_queue
2250 * Put a sent message into the destination queue.
2251 * For inter-process message, reply_size is set to expected size of reply data.
2253 static BOOL put_message_in_queue( const struct send_message_info *info, size_t *reply_size )
2255 struct packed_message data;
2256 message_data_t msg_data;
2259 timeout_t timeout = TIMEOUT_INFINITE;
2261 /* Check for INFINITE timeout for compatibility with Win9x,
2262 * although Windows >= NT does not do so
2264 if (info->type != MSG_NOTIFY &&
2265 info->type != MSG_CALLBACK &&
2266 info->type != MSG_POSTED &&
2268 info->timeout != INFINITE)
2270 /* timeout is signed despite the prototype */
2271 timeout = (timeout_t)max( 0, (int)info->timeout ) * -10000;
2275 if (info->type == MSG_OTHER_PROCESS)
2277 *reply_size = pack_message( info->hwnd, info->msg, info->wparam, info->lparam, &data );
2278 if (data.count == -1)
2280 WARN( "cannot pack message %x\n", info->msg );
2284 else if (info->type == MSG_CALLBACK)
2286 msg_data.callback.callback = info->callback;
2287 msg_data.callback.data = info->data;
2288 msg_data.callback.result = 0;
2289 data.data[0] = &msg_data;
2290 data.size[0] = sizeof(msg_data.callback);
2293 else if (info->type == MSG_POSTED && info->msg >= WM_DDE_FIRST && info->msg <= WM_DDE_LAST)
2295 return post_dde_message( &data, info );
2298 SERVER_START_REQ( send_message )
2300 req->id = info->dest_tid;
2301 req->type = info->type;
2303 req->win = info->hwnd;
2304 req->msg = info->msg;
2305 req->wparam = info->wparam;
2306 req->lparam = info->lparam;
2307 req->timeout = timeout;
2309 if (info->flags & SMTO_ABORTIFHUNG) req->flags |= SEND_MSG_ABORT_IF_HUNG;
2310 for (i = 0; i < data.count; i++) wine_server_add_data( req, data.data[i], data.size[i] );
2311 if ((res = wine_server_call( req )))
2313 if (res == STATUS_INVALID_PARAMETER)
2314 /* FIXME: find a STATUS_ value for this one */
2315 SetLastError( ERROR_INVALID_THREAD_ID );
2317 SetLastError( RtlNtStatusToDosError(res) );
2325 /***********************************************************************
2328 * Retrieve a message reply from the server.
2330 static LRESULT retrieve_reply( const struct send_message_info *info,
2331 size_t reply_size, LRESULT *result )
2334 void *reply_data = NULL;
2338 if (!(reply_data = HeapAlloc( GetProcessHeap(), 0, reply_size )))
2340 WARN( "no memory for reply, will be truncated\n" );
2344 SERVER_START_REQ( get_message_reply )
2347 if (reply_size) wine_server_set_reply( req, reply_data, reply_size );
2348 if (!(status = wine_server_call( req ))) *result = reply->result;
2349 reply_size = wine_server_reply_size( reply );
2352 if (!status && reply_size)
2353 unpack_reply( info->hwnd, info->msg, info->wparam, info->lparam, reply_data, reply_size );
2355 HeapFree( GetProcessHeap(), 0, reply_data );
2357 TRACE( "hwnd %p msg %x (%s) wp %lx lp %lx got reply %lx (err=%d)\n",
2358 info->hwnd, info->msg, SPY_GetMsgName(info->msg, info->hwnd), info->wparam,
2359 info->lparam, *result, status );
2361 /* MSDN states that last error is 0 on timeout, but at least NT4 returns ERROR_TIMEOUT */
2362 if (status) SetLastError( RtlNtStatusToDosError(status) );
2367 /***********************************************************************
2368 * send_inter_thread_message
2370 static LRESULT send_inter_thread_message( const struct send_message_info *info, LRESULT *res_ptr )
2372 size_t reply_size = 0;
2374 TRACE( "hwnd %p msg %x (%s) wp %lx lp %lx\n",
2375 info->hwnd, info->msg, SPY_GetMsgName(info->msg, info->hwnd), info->wparam, info->lparam );
2377 USER_CheckNotLock();
2379 if (!put_message_in_queue( info, &reply_size )) return 0;
2381 /* there's no reply to wait for on notify/callback messages */
2382 if (info->type == MSG_NOTIFY || info->type == MSG_CALLBACK) return 1;
2384 wait_message_reply( info->flags );
2385 return retrieve_reply( info, reply_size, res_ptr );
2389 /***********************************************************************
2390 * send_inter_thread_callback
2392 static LRESULT send_inter_thread_callback( HWND hwnd, UINT msg, WPARAM wp, LPARAM lp,
2393 LRESULT *result, void *arg )
2395 struct send_message_info *info = arg;
2400 return send_inter_thread_message( info, result );
2404 /***********************************************************************
2407 * Backend implementation of the various SendMessage functions.
2409 static BOOL send_message( struct send_message_info *info, DWORD_PTR *res_ptr, BOOL unicode )
2415 if (is_broadcast(info->hwnd))
2417 EnumWindows( broadcast_message_callback, (LPARAM)info );
2418 if (res_ptr) *res_ptr = 1;
2422 if (!(info->dest_tid = GetWindowThreadProcessId( info->hwnd, &dest_pid ))) return FALSE;
2424 if (USER_IsExitingThread( info->dest_tid )) return FALSE;
2426 SPY_EnterMessage( SPY_SENDMESSAGE, info->hwnd, info->msg, info->wparam, info->lparam );
2428 if (info->dest_tid == GetCurrentThreadId())
2430 result = call_window_proc( info->hwnd, info->msg, info->wparam, info->lparam,
2431 unicode, TRUE, info->wm_char );
2432 if (info->type == MSG_CALLBACK)
2433 call_sendmsg_callback( info->callback, info->hwnd, info->msg, info->data, result );
2438 if (dest_pid != GetCurrentProcessId() && (info->type == MSG_ASCII || info->type == MSG_UNICODE))
2439 info->type = MSG_OTHER_PROCESS;
2441 /* MSG_ASCII can be sent unconverted except for WM_CHAR; everything else needs to be Unicode */
2442 if (!unicode && is_unicode_message( info->msg ) &&
2443 (info->type != MSG_ASCII || info->msg == WM_CHAR))
2444 ret = WINPROC_CallProcAtoW( send_inter_thread_callback, info->hwnd, info->msg,
2445 info->wparam, info->lparam, &result, info, info->wm_char );
2447 ret = send_inter_thread_message( info, &result );
2450 SPY_ExitMessage( SPY_RESULT_OK, info->hwnd, info->msg, result, info->wparam, info->lparam );
2451 if (ret && res_ptr) *res_ptr = result;
2456 /***********************************************************************
2457 * MSG_SendInternalMessageTimeout
2459 * Same as SendMessageTimeoutW but sends the message to a specific thread
2460 * without requiring a window handle. Only works for internal Wine messages.
2462 LRESULT MSG_SendInternalMessageTimeout( DWORD dest_pid, DWORD dest_tid,
2463 UINT msg, WPARAM wparam, LPARAM lparam,
2464 UINT flags, UINT timeout, PDWORD_PTR res_ptr )
2466 struct send_message_info info;
2467 LRESULT ret, result;
2469 assert( msg & 0x80000000 ); /* must be an internal Wine message */
2471 info.type = MSG_UNICODE;
2472 info.dest_tid = dest_tid;
2475 info.wparam = wparam;
2476 info.lparam = lparam;
2478 info.timeout = timeout;
2480 if (USER_IsExitingThread( dest_tid )) return 0;
2482 if (dest_tid == GetCurrentThreadId())
2484 result = handle_internal_message( 0, msg, wparam, lparam );
2489 if (dest_pid != GetCurrentProcessId()) info.type = MSG_OTHER_PROCESS;
2490 ret = send_inter_thread_message( &info, &result );
2492 if (ret && res_ptr) *res_ptr = result;
2497 /***********************************************************************
2498 * SendMessageTimeoutW (USER32.@)
2500 LRESULT WINAPI SendMessageTimeoutW( HWND hwnd, UINT msg, WPARAM wparam, LPARAM lparam,
2501 UINT flags, UINT timeout, PDWORD_PTR res_ptr )
2503 struct send_message_info info;
2505 info.type = MSG_UNICODE;
2508 info.wparam = wparam;
2509 info.lparam = lparam;
2511 info.timeout = timeout;
2513 return send_message( &info, res_ptr, TRUE );
2516 /***********************************************************************
2517 * SendMessageTimeoutA (USER32.@)
2519 LRESULT WINAPI SendMessageTimeoutA( HWND hwnd, UINT msg, WPARAM wparam, LPARAM lparam,
2520 UINT flags, UINT timeout, PDWORD_PTR res_ptr )
2522 struct send_message_info info;
2524 info.type = MSG_ASCII;
2527 info.wparam = wparam;
2528 info.lparam = lparam;
2530 info.timeout = timeout;
2531 info.wm_char = WMCHAR_MAP_SENDMESSAGETIMEOUT;
2533 return send_message( &info, res_ptr, FALSE );
2537 /***********************************************************************
2538 * SendMessageW (USER32.@)
2540 LRESULT WINAPI SendMessageW( HWND hwnd, UINT msg, WPARAM wparam, LPARAM lparam )
2543 struct send_message_info info;
2545 info.type = MSG_UNICODE;
2548 info.wparam = wparam;
2549 info.lparam = lparam;
2550 info.flags = SMTO_NORMAL;
2553 send_message( &info, &res, TRUE );
2558 /***********************************************************************
2559 * SendMessageA (USER32.@)
2561 LRESULT WINAPI SendMessageA( HWND hwnd, UINT msg, WPARAM wparam, LPARAM lparam )
2564 struct send_message_info info;
2566 info.type = MSG_ASCII;
2569 info.wparam = wparam;
2570 info.lparam = lparam;
2571 info.flags = SMTO_NORMAL;
2573 info.wm_char = WMCHAR_MAP_SENDMESSAGE;
2575 send_message( &info, &res, FALSE );
2580 /***********************************************************************
2581 * SendNotifyMessageA (USER32.@)
2583 BOOL WINAPI SendNotifyMessageA( HWND hwnd, UINT msg, WPARAM wparam, LPARAM lparam )
2585 struct send_message_info info;
2587 if (is_pointer_message(msg))
2589 SetLastError( ERROR_MESSAGE_SYNC_ONLY );
2593 info.type = MSG_NOTIFY;
2596 info.wparam = wparam;
2597 info.lparam = lparam;
2599 info.wm_char = WMCHAR_MAP_SENDMESSAGETIMEOUT;
2601 return send_message( &info, NULL, FALSE );
2605 /***********************************************************************
2606 * SendNotifyMessageW (USER32.@)
2608 BOOL WINAPI SendNotifyMessageW( HWND hwnd, UINT msg, WPARAM wparam, LPARAM lparam )
2610 struct send_message_info info;
2612 if (is_pointer_message(msg))
2614 SetLastError( ERROR_MESSAGE_SYNC_ONLY );
2618 info.type = MSG_NOTIFY;
2621 info.wparam = wparam;
2622 info.lparam = lparam;
2625 return send_message( &info, NULL, TRUE );
2629 /***********************************************************************
2630 * SendMessageCallbackA (USER32.@)
2632 BOOL WINAPI SendMessageCallbackA( HWND hwnd, UINT msg, WPARAM wparam, LPARAM lparam,
2633 SENDASYNCPROC callback, ULONG_PTR data )
2635 struct send_message_info info;
2637 if (is_pointer_message(msg))
2639 SetLastError( ERROR_MESSAGE_SYNC_ONLY );
2643 info.type = MSG_CALLBACK;
2646 info.wparam = wparam;
2647 info.lparam = lparam;
2648 info.callback = callback;
2651 info.wm_char = WMCHAR_MAP_SENDMESSAGETIMEOUT;
2653 return send_message( &info, NULL, FALSE );
2657 /***********************************************************************
2658 * SendMessageCallbackW (USER32.@)
2660 BOOL WINAPI SendMessageCallbackW( HWND hwnd, UINT msg, WPARAM wparam, LPARAM lparam,
2661 SENDASYNCPROC callback, ULONG_PTR data )
2663 struct send_message_info info;
2665 if (is_pointer_message(msg))
2667 SetLastError( ERROR_MESSAGE_SYNC_ONLY );
2671 info.type = MSG_CALLBACK;
2674 info.wparam = wparam;
2675 info.lparam = lparam;
2676 info.callback = callback;
2680 return send_message( &info, NULL, TRUE );
2684 /***********************************************************************
2685 * ReplyMessage (USER32.@)
2687 BOOL WINAPI ReplyMessage( LRESULT result )
2689 struct received_message_info *info = get_user_thread_info()->receive_info;
2691 if (!info) return FALSE;
2692 reply_message( info, result, FALSE );
2697 /***********************************************************************
2698 * InSendMessage (USER32.@)
2700 BOOL WINAPI InSendMessage(void)
2702 return (InSendMessageEx(NULL) & (ISMEX_SEND|ISMEX_REPLIED)) == ISMEX_SEND;
2706 /***********************************************************************
2707 * InSendMessageEx (USER32.@)
2709 DWORD WINAPI InSendMessageEx( LPVOID reserved )
2711 struct received_message_info *info = get_user_thread_info()->receive_info;
2713 if (info) return info->flags;
2714 return ISMEX_NOSEND;
2718 /***********************************************************************
2719 * PostMessageA (USER32.@)
2721 BOOL WINAPI PostMessageA( HWND hwnd, UINT msg, WPARAM wparam, LPARAM lparam )
2723 if (!map_wparam_AtoW( msg, &wparam, WMCHAR_MAP_POSTMESSAGE )) return TRUE;
2724 return PostMessageW( hwnd, msg, wparam, lparam );
2728 /***********************************************************************
2729 * PostMessageW (USER32.@)
2731 BOOL WINAPI PostMessageW( HWND hwnd, UINT msg, WPARAM wparam, LPARAM lparam )
2733 struct send_message_info info;
2735 if (is_pointer_message( msg ))
2737 SetLastError( ERROR_MESSAGE_SYNC_ONLY );
2741 TRACE( "hwnd %p msg %x (%s) wp %lx lp %lx\n",
2742 hwnd, msg, SPY_GetMsgName(msg, hwnd), wparam, lparam );
2744 info.type = MSG_POSTED;
2747 info.wparam = wparam;
2748 info.lparam = lparam;
2751 if (is_broadcast(hwnd))
2753 EnumWindows( broadcast_message_callback, (LPARAM)&info );
2757 if (!hwnd) return PostThreadMessageW( GetCurrentThreadId(), msg, wparam, lparam );
2759 if (!(info.dest_tid = GetWindowThreadProcessId( hwnd, NULL ))) return FALSE;
2761 if (USER_IsExitingThread( info.dest_tid )) return TRUE;
2763 return put_message_in_queue( &info, NULL );
2767 /**********************************************************************
2768 * PostThreadMessageA (USER32.@)
2770 BOOL WINAPI PostThreadMessageA( DWORD thread, UINT msg, WPARAM wparam, LPARAM lparam )
2772 if (!map_wparam_AtoW( msg, &wparam, WMCHAR_MAP_POSTMESSAGE )) return TRUE;
2773 return PostThreadMessageW( thread, msg, wparam, lparam );
2777 /**********************************************************************
2778 * PostThreadMessageW (USER32.@)
2780 BOOL WINAPI PostThreadMessageW( DWORD thread, UINT msg, WPARAM wparam, LPARAM lparam )
2782 struct send_message_info info;
2784 if (is_pointer_message( msg ))
2786 SetLastError( ERROR_MESSAGE_SYNC_ONLY );
2789 if (USER_IsExitingThread( thread )) return TRUE;
2791 info.type = MSG_POSTED;
2792 info.dest_tid = thread;
2795 info.wparam = wparam;
2796 info.lparam = lparam;
2798 return put_message_in_queue( &info, NULL );
2802 /***********************************************************************
2803 * PostQuitMessage (USER32.@)
2805 * Posts a quit message to the current thread's message queue.
2808 * exit_code [I] Exit code to return from message loop.
2814 * This function is not the same as calling:
2815 *|PostThreadMessage(GetCurrentThreadId(), WM_QUIT, exit_code, 0);
2816 * It instead sets a flag in the message queue that signals it to generate
2817 * a WM_QUIT message when there are no other pending sent or posted messages
2820 void WINAPI PostQuitMessage( INT exit_code )
2822 SERVER_START_REQ( post_quit_message )
2824 req->exit_code = exit_code;
2825 wine_server_call( req );
2831 /***********************************************************************
2832 * PeekMessageW (USER32.@)
2834 BOOL WINAPI PeekMessageW( MSG *msg_out, HWND hwnd, UINT first, UINT last, UINT flags )
2836 struct user_thread_info *thread_info = get_user_thread_info();
2839 USER_CheckNotLock();
2841 /* check for graphics events */
2842 USER_Driver->pMsgWaitForMultipleObjectsEx( 0, NULL, 0, QS_ALLINPUT, 0 );
2844 hwnd = WIN_GetFullHandle( hwnd );
2848 if (!peek_message( &msg, hwnd, first, last, flags ))
2850 if (!(flags & PM_NOYIELD))
2853 ReleaseThunkLock(&count);
2855 if (count) RestoreThunkLock(count);
2859 if (msg.message & 0x80000000)
2861 if (!(flags & PM_REMOVE))
2863 /* Have to remove the message explicitly.
2864 Do this before handling it, because the message handler may
2865 call PeekMessage again */
2866 peek_message( &msg, msg.hwnd, msg.message, msg.message, flags | PM_REMOVE );
2868 handle_internal_message( msg.hwnd, msg.message, msg.wParam, msg.lParam );
2873 thread_info->GetMessageTimeVal = msg.time;
2874 msg.pt.x = (short)LOWORD( thread_info->GetMessagePosVal );
2875 msg.pt.y = (short)HIWORD( thread_info->GetMessagePosVal );
2877 HOOK_CallHooks( WH_GETMESSAGE, HC_ACTION, flags & PM_REMOVE, (LPARAM)&msg, TRUE );
2879 /* copy back our internal safe copy of message data to msg_out.
2880 * msg_out is a variable from the *program*, so it can't be used
2881 * internally as it can get "corrupted" by our use of SendMessage()
2882 * (back to the program) inside the message handling itself. */
2885 SetLastError( ERROR_NOACCESS );
2893 /***********************************************************************
2894 * PeekMessageA (USER32.@)
2896 BOOL WINAPI PeekMessageA( MSG *msg, HWND hwnd, UINT first, UINT last, UINT flags )
2898 if (get_pending_wmchar( msg, first, last, (flags & PM_REMOVE) )) return TRUE;
2899 if (!PeekMessageW( msg, hwnd, first, last, flags )) return FALSE;
2900 map_wparam_WtoA( msg, (flags & PM_REMOVE) );
2905 /***********************************************************************
2906 * GetMessageW (USER32.@)
2908 BOOL WINAPI GetMessageW( MSG *msg, HWND hwnd, UINT first, UINT last )
2910 HANDLE server_queue = get_server_queue_handle();
2911 int mask = QS_POSTMESSAGE | QS_SENDMESSAGE; /* Always selected */
2915 if ((first <= WM_KEYLAST) && (last >= WM_KEYFIRST)) mask |= QS_KEY;
2916 if ( ((first <= WM_MOUSELAST) && (last >= WM_MOUSEFIRST)) ||
2917 ((first <= WM_NCMOUSELAST) && (last >= WM_NCMOUSEFIRST)) ) mask |= QS_MOUSE;
2918 if ((first <= WM_TIMER) && (last >= WM_TIMER)) mask |= QS_TIMER;
2919 if ((first <= WM_SYSTIMER) && (last >= WM_SYSTIMER)) mask |= QS_TIMER;
2920 if ((first <= WM_PAINT) && (last >= WM_PAINT)) mask |= QS_PAINT;
2922 else mask = QS_ALLINPUT;
2924 while (!PeekMessageW( msg, hwnd, first, last, PM_REMOVE | PM_NOYIELD | (mask << 16) ))
2928 ReleaseThunkLock( &dwlc );
2929 USER_Driver->pMsgWaitForMultipleObjectsEx( 1, &server_queue, INFINITE, mask, 0 );
2930 if (dwlc) RestoreThunkLock( dwlc );
2933 return (msg->message != WM_QUIT);
2937 /***********************************************************************
2938 * GetMessageA (USER32.@)
2940 BOOL WINAPI GetMessageA( MSG *msg, HWND hwnd, UINT first, UINT last )
2942 if (get_pending_wmchar( msg, first, last, TRUE )) return TRUE;
2943 GetMessageW( msg, hwnd, first, last );
2944 map_wparam_WtoA( msg, TRUE );
2945 return (msg->message != WM_QUIT);
2949 /***********************************************************************
2950 * IsDialogMessageA (USER32.@)
2951 * IsDialogMessage (USER32.@)
2953 BOOL WINAPI IsDialogMessageA( HWND hwndDlg, LPMSG pmsg )
2956 map_wparam_AtoW( msg.message, &msg.wParam, WMCHAR_MAP_NOMAPPING );
2957 return IsDialogMessageW( hwndDlg, &msg );
2961 /***********************************************************************
2962 * TranslateMessage (USER32.@)
2964 * Implementation of TranslateMessage.
2966 * TranslateMessage translates virtual-key messages into character-messages,
2968 * WM_KEYDOWN/WM_KEYUP combinations produce a WM_CHAR or WM_DEADCHAR message.
2969 * ditto replacing WM_* with WM_SYS*
2970 * This produces WM_CHAR messages only for keys mapped to ASCII characters
2971 * by the keyboard driver.
2973 * If the message is WM_KEYDOWN, WM_KEYUP, WM_SYSKEYDOWN, or WM_SYSKEYUP, the
2974 * return value is nonzero, regardless of the translation.
2977 BOOL WINAPI TranslateMessage( const MSG *msg )
2983 if (msg->message < WM_KEYFIRST || msg->message > WM_KEYLAST) return FALSE;
2984 if (msg->message != WM_KEYDOWN && msg->message != WM_SYSKEYDOWN) return TRUE;
2986 TRACE_(key)("Translating key %s (%04lx), scancode %02x\n",
2987 SPY_GetVKeyName(msg->wParam), msg->wParam, LOBYTE(HIWORD(msg->lParam)));
2989 GetKeyboardState( state );
2990 /* FIXME : should handle ToUnicode yielding 2 */
2991 switch (ToUnicode(msg->wParam, HIWORD(msg->lParam), state, wp, 2, 0))
2994 message = (msg->message == WM_KEYDOWN) ? WM_CHAR : WM_SYSCHAR;
2995 TRACE_(key)("1 -> PostMessageW(%p,%s,%04x,%08lx)\n",
2996 msg->hwnd, SPY_GetMsgName(message, msg->hwnd), wp[0], msg->lParam);
2997 PostMessageW( msg->hwnd, message, wp[0], msg->lParam );
3001 message = (msg->message == WM_KEYDOWN) ? WM_DEADCHAR : WM_SYSDEADCHAR;
3002 TRACE_(key)("-1 -> PostMessageW(%p,%s,%04x,%08lx)\n",
3003 msg->hwnd, SPY_GetMsgName(message, msg->hwnd), wp[0], msg->lParam);
3004 PostMessageW( msg->hwnd, message, wp[0], msg->lParam );
3011 /***********************************************************************
3012 * DispatchMessageA (USER32.@)
3014 * See DispatchMessageW.
3016 LRESULT WINAPI DispatchMessageA( const MSG* msg )
3020 /* Process timer messages */
3021 if ((msg->message == WM_TIMER) || (msg->message == WM_SYSTIMER))
3023 if (msg->lParam) return CallWindowProcA( (WNDPROC)msg->lParam, msg->hwnd,
3024 msg->message, msg->wParam, GetTickCount() );
3026 if (!msg->hwnd) return 0;
3028 SPY_EnterMessage( SPY_DISPATCHMESSAGE, msg->hwnd, msg->message,
3029 msg->wParam, msg->lParam );
3031 if (!WINPROC_call_window( msg->hwnd, msg->message, msg->wParam, msg->lParam,
3032 &retval, FALSE, WMCHAR_MAP_DISPATCHMESSAGE ))
3034 if (!IsWindow( msg->hwnd )) SetLastError( ERROR_INVALID_WINDOW_HANDLE );
3035 else SetLastError( ERROR_MESSAGE_SYNC_ONLY );
3039 SPY_ExitMessage( SPY_RESULT_OK, msg->hwnd, msg->message, retval,
3040 msg->wParam, msg->lParam );
3042 if (msg->message == WM_PAINT)
3044 /* send a WM_NCPAINT and WM_ERASEBKGND if the non-client area is still invalid */
3045 HRGN hrgn = CreateRectRgn( 0, 0, 0, 0 );
3046 GetUpdateRgn( msg->hwnd, hrgn, TRUE );
3047 DeleteObject( hrgn );
3053 /***********************************************************************
3054 * DispatchMessageW (USER32.@) Process a message
3056 * Process the message specified in the structure *_msg_.
3058 * If the lpMsg parameter points to a WM_TIMER message and the
3059 * parameter of the WM_TIMER message is not NULL, the lParam parameter
3060 * points to the function that is called instead of the window
3063 * The message must be valid.
3067 * DispatchMessage() returns the result of the window procedure invoked.
3074 LRESULT WINAPI DispatchMessageW( const MSG* msg )
3078 /* Process timer messages */
3079 if ((msg->message == WM_TIMER) || (msg->message == WM_SYSTIMER))
3081 if (msg->lParam) return CallWindowProcW( (WNDPROC)msg->lParam, msg->hwnd,
3082 msg->message, msg->wParam, GetTickCount() );
3084 if (!msg->hwnd) return 0;
3086 SPY_EnterMessage( SPY_DISPATCHMESSAGE, msg->hwnd, msg->message,
3087 msg->wParam, msg->lParam );
3089 if (!WINPROC_call_window( msg->hwnd, msg->message, msg->wParam, msg->lParam,
3090 &retval, TRUE, WMCHAR_MAP_DISPATCHMESSAGE ))
3092 if (!IsWindow( msg->hwnd )) SetLastError( ERROR_INVALID_WINDOW_HANDLE );
3093 else SetLastError( ERROR_MESSAGE_SYNC_ONLY );
3097 SPY_ExitMessage( SPY_RESULT_OK, msg->hwnd, msg->message, retval,
3098 msg->wParam, msg->lParam );
3100 if (msg->message == WM_PAINT)
3102 /* send a WM_NCPAINT and WM_ERASEBKGND if the non-client area is still invalid */
3103 HRGN hrgn = CreateRectRgn( 0, 0, 0, 0 );
3104 GetUpdateRgn( msg->hwnd, hrgn, TRUE );
3105 DeleteObject( hrgn );
3111 /***********************************************************************
3112 * GetMessagePos (USER.119)
3113 * GetMessagePos (USER32.@)
3115 * The GetMessagePos() function returns a long value representing a
3116 * cursor position, in screen coordinates, when the last message
3117 * retrieved by the GetMessage() function occurs. The x-coordinate is
3118 * in the low-order word of the return value, the y-coordinate is in
3119 * the high-order word. The application can use the MAKEPOINT()
3120 * macro to obtain a POINT structure from the return value.
3122 * For the current cursor position, use GetCursorPos().
3126 * Cursor position of last message on success, zero on failure.
3133 DWORD WINAPI GetMessagePos(void)
3135 return get_user_thread_info()->GetMessagePosVal;
3139 /***********************************************************************
3140 * GetMessageTime (USER.120)
3141 * GetMessageTime (USER32.@)
3143 * GetMessageTime() returns the message time for the last message
3144 * retrieved by the function. The time is measured in milliseconds with
3145 * the same offset as GetTickCount().
3147 * Since the tick count wraps, this is only useful for moderately short
3148 * relative time comparisons.
3152 * Time of last message on success, zero on failure.
3154 LONG WINAPI GetMessageTime(void)
3156 return get_user_thread_info()->GetMessageTimeVal;
3160 /***********************************************************************
3161 * GetMessageExtraInfo (USER.288)
3162 * GetMessageExtraInfo (USER32.@)
3164 LPARAM WINAPI GetMessageExtraInfo(void)
3166 return get_user_thread_info()->GetMessageExtraInfoVal;
3170 /***********************************************************************
3171 * SetMessageExtraInfo (USER32.@)
3173 LPARAM WINAPI SetMessageExtraInfo(LPARAM lParam)
3175 struct user_thread_info *thread_info = get_user_thread_info();
3176 LONG old_value = thread_info->GetMessageExtraInfoVal;
3177 thread_info->GetMessageExtraInfoVal = lParam;
3182 /***********************************************************************
3183 * WaitMessage (USER.112) Suspend thread pending messages
3184 * WaitMessage (USER32.@) Suspend thread pending messages
3186 * WaitMessage() suspends a thread until events appear in the thread's
3189 BOOL WINAPI WaitMessage(void)
3191 return (MsgWaitForMultipleObjectsEx( 0, NULL, INFINITE, QS_ALLINPUT, 0 ) != WAIT_FAILED);
3195 /***********************************************************************
3196 * MsgWaitForMultipleObjectsEx (USER32.@)
3198 DWORD WINAPI MsgWaitForMultipleObjectsEx( DWORD count, CONST HANDLE *pHandles,
3199 DWORD timeout, DWORD mask, DWORD flags )
3201 HANDLE handles[MAXIMUM_WAIT_OBJECTS];
3204 if (count > MAXIMUM_WAIT_OBJECTS-1)
3206 SetLastError( ERROR_INVALID_PARAMETER );
3210 /* set the queue mask */
3211 SERVER_START_REQ( set_queue_mask )
3213 req->wake_mask = (flags & MWMO_INPUTAVAILABLE) ? mask : 0;
3214 req->changed_mask = mask;
3216 wine_server_call( req );
3220 /* add the queue to the handle list */
3221 for (i = 0; i < count; i++) handles[i] = pHandles[i];
3222 handles[count] = get_server_queue_handle();
3224 ReleaseThunkLock( &lock );
3225 ret = USER_Driver->pMsgWaitForMultipleObjectsEx( count+1, handles, timeout, mask, flags );
3226 if (lock) RestoreThunkLock( lock );
3231 /***********************************************************************
3232 * MsgWaitForMultipleObjects (USER32.@)
3234 DWORD WINAPI MsgWaitForMultipleObjects( DWORD count, CONST HANDLE *handles,
3235 BOOL wait_all, DWORD timeout, DWORD mask )
3237 return MsgWaitForMultipleObjectsEx( count, handles, timeout, mask,
3238 wait_all ? MWMO_WAITALL : 0 );
3242 /***********************************************************************
3243 * WaitForInputIdle (USER32.@)
3245 DWORD WINAPI WaitForInputIdle( HANDLE hProcess, DWORD dwTimeOut )
3247 DWORD start_time, elapsed, ret;
3250 handles[0] = hProcess;
3251 SERVER_START_REQ( get_process_idle_event )
3253 req->handle = hProcess;
3254 if (!(ret = wine_server_call_err( req ))) handles[1] = reply->event;
3257 if (ret) return WAIT_FAILED; /* error */
3258 if (!handles[1]) return 0; /* no event to wait on */
3260 start_time = GetTickCount();
3263 TRACE("waiting for %p\n", handles[1] );
3266 ret = MsgWaitForMultipleObjects ( 2, handles, FALSE, dwTimeOut - elapsed, QS_SENDMESSAGE );
3271 case WAIT_OBJECT_0+2:
3272 process_sent_messages();
3276 TRACE("timeout or error\n");
3279 TRACE("finished\n");
3282 if (dwTimeOut != INFINITE)
3284 elapsed = GetTickCount() - start_time;
3285 if (elapsed > dwTimeOut)
3291 return WAIT_TIMEOUT;
3295 /***********************************************************************
3296 * UserYield (USER.332)
3298 void WINAPI UserYield16(void)
3302 /* Handle sent messages */
3303 process_sent_messages();
3306 ReleaseThunkLock(&count);
3310 RestoreThunkLock(count);
3311 /* Handle sent messages again */
3312 process_sent_messages();
3317 /***********************************************************************
3318 * RegisterWindowMessageA (USER32.@)
3319 * RegisterWindowMessage (USER.118)
3321 UINT WINAPI RegisterWindowMessageA( LPCSTR str )
3323 UINT ret = GlobalAddAtomA(str);
3324 TRACE("%s, ret=%x\n", str, ret);
3329 /***********************************************************************
3330 * RegisterWindowMessageW (USER32.@)
3332 UINT WINAPI RegisterWindowMessageW( LPCWSTR str )
3334 UINT ret = GlobalAddAtomW(str);
3335 TRACE("%s ret=%x\n", debugstr_w(str), ret);
3340 /***********************************************************************
3341 * BroadcastSystemMessageA (USER32.@)
3342 * BroadcastSystemMessage (USER32.@)
3344 LONG WINAPI BroadcastSystemMessageA( DWORD flags, LPDWORD recipients, UINT msg, WPARAM wp, LPARAM lp )
3346 if ((*recipients & BSM_APPLICATIONS) || (*recipients == BSM_ALLCOMPONENTS))
3348 FIXME( "(%08x,%08x,%08x,%08lx,%08lx): semi-stub!\n", flags, *recipients, msg, wp, lp );
3349 PostMessageA( HWND_BROADCAST, msg, wp, lp );
3354 FIXME( "(%08x,%08x,%08x,%08lx,%08lx): stub!\n", flags, *recipients, msg, wp, lp);
3360 /***********************************************************************
3361 * BroadcastSystemMessageW (USER32.@)
3363 LONG WINAPI BroadcastSystemMessageW( DWORD flags, LPDWORD recipients, UINT msg, WPARAM wp, LPARAM lp )
3365 if ((*recipients & BSM_APPLICATIONS) || (*recipients == BSM_ALLCOMPONENTS))
3367 FIXME( "(%08x,%08x,%08x,%08lx,%08lx): semi-stub!\n", flags, *recipients, msg, wp, lp );
3368 PostMessageW( HWND_BROADCAST, msg, wp, lp );
3373 FIXME( "(%08x,%08x,%08x,%08lx,%08lx): stub!\n", flags, *recipients, msg, wp, lp );
3379 /***********************************************************************
3380 * SetMessageQueue (USER32.@)
3382 BOOL WINAPI SetMessageQueue( INT size )
3384 /* now obsolete the message queue will be expanded dynamically as necessary */
3389 /***********************************************************************
3390 * MessageBeep (USER32.@)
3392 BOOL WINAPI MessageBeep( UINT i )
3395 SystemParametersInfoA( SPI_GETBEEP, 0, &active, FALSE );
3396 if (active) USER_Driver->pBeep();
3401 /***********************************************************************
3402 * SetTimer (USER32.@)
3404 UINT_PTR WINAPI SetTimer( HWND hwnd, UINT_PTR id, UINT timeout, TIMERPROC proc )
3407 WNDPROC winproc = 0;
3409 if (proc) winproc = WINPROC_AllocProc( (WNDPROC)proc, NULL );
3411 SERVER_START_REQ( set_win_timer )
3414 req->msg = WM_TIMER;
3416 req->rate = max( timeout, SYS_TIMER_RATE );
3417 req->lparam = (unsigned long)winproc;
3418 if (!wine_server_call_err( req ))
3421 if (!ret) ret = TRUE;
3427 TRACE("Added %p %lx %p timeout %d\n", hwnd, id, winproc, timeout );
3432 /***********************************************************************
3433 * SetSystemTimer (USER32.@)
3435 UINT_PTR WINAPI SetSystemTimer( HWND hwnd, UINT_PTR id, UINT timeout, TIMERPROC proc )
3438 WNDPROC winproc = 0;
3440 if (proc) winproc = WINPROC_AllocProc( (WNDPROC)proc, NULL );
3442 SERVER_START_REQ( set_win_timer )
3445 req->msg = WM_SYSTIMER;
3447 req->rate = max( timeout, SYS_TIMER_RATE );
3448 req->lparam = (unsigned long)winproc;
3449 if (!wine_server_call_err( req ))
3452 if (!ret) ret = TRUE;
3458 TRACE("Added %p %lx %p timeout %d\n", hwnd, id, winproc, timeout );
3463 /***********************************************************************
3464 * KillTimer (USER32.@)
3466 BOOL WINAPI KillTimer( HWND hwnd, UINT_PTR id )
3470 SERVER_START_REQ( kill_win_timer )
3473 req->msg = WM_TIMER;
3475 ret = !wine_server_call_err( req );
3482 /***********************************************************************
3483 * KillSystemTimer (USER32.@)
3485 BOOL WINAPI KillSystemTimer( HWND hwnd, UINT_PTR id )
3489 SERVER_START_REQ( kill_win_timer )
3492 req->msg = WM_SYSTIMER;
3494 ret = !wine_server_call_err( req );
3501 /**********************************************************************
3502 * GetGUIThreadInfo (USER32.@)
3504 BOOL WINAPI GetGUIThreadInfo( DWORD id, GUITHREADINFO *info )
3508 SERVER_START_REQ( get_thread_input )
3511 if ((ret = !wine_server_call_err( req )))
3514 info->hwndActive = reply->active;
3515 info->hwndFocus = reply->focus;
3516 info->hwndCapture = reply->capture;
3517 info->hwndMenuOwner = reply->menu_owner;
3518 info->hwndMoveSize = reply->move_size;
3519 info->hwndCaret = reply->caret;
3520 info->rcCaret.left = reply->rect.left;
3521 info->rcCaret.top = reply->rect.top;
3522 info->rcCaret.right = reply->rect.right;
3523 info->rcCaret.bottom = reply->rect.bottom;
3524 if (reply->menu_owner) info->flags |= GUI_INMENUMODE;
3525 if (reply->move_size) info->flags |= GUI_INMOVESIZE;
3526 if (reply->caret) info->flags |= GUI_CARETBLINKING;
3534 /******************************************************************
3535 * IsHungAppWindow (USER32.@)
3538 BOOL WINAPI IsHungAppWindow( HWND hWnd )
3542 SERVER_START_REQ( is_window_hung )
3545 ret = !wine_server_call_err( req ) && reply->is_hung;