2 * Window messaging support
4 * Copyright 2001 Alexandre Julliard
5 * Copyright 2008 Maarten Lankhorst
7 * This library is free software; you can redistribute it and/or
8 * modify it under the terms of the GNU Lesser General Public
9 * License as published by the Free Software Foundation; either
10 * version 2.1 of the License, or (at your option) any later version.
12 * This library is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
15 * Lesser General Public License for more details.
17 * You should have received a copy of the GNU Lesser General Public
18 * License along with this library; if not, write to the Free Software
19 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
23 #include "wine/port.h"
29 #define WIN32_NO_STATUS
40 #include "wine/unicode.h"
41 #include "wine/server.h"
42 #include "user_private.h"
45 #include "wine/debug.h"
47 WINE_DEFAULT_DEBUG_CHANNEL(msg);
48 WINE_DECLARE_DEBUG_CHANNEL(relay);
49 WINE_DECLARE_DEBUG_CHANNEL(key);
51 #define WM_NCMOUSEFIRST WM_NCMOUSEMOVE
52 #define WM_NCMOUSELAST (WM_NCMOUSEFIRST+(WM_MOUSELAST-WM_MOUSEFIRST))
54 #define MAX_PACK_COUNT 4
55 #define MAX_SENDMSG_RECURSION 64
57 #define SYS_TIMER_RATE 55 /* min. timer rate in ms (actually 54.925)*/
59 /* description of the data fields that need to be packed along with a sent message */
63 const void *data[MAX_PACK_COUNT];
64 size_t size[MAX_PACK_COUNT];
67 /* info about the message currently being received by the current thread */
68 struct received_message_info
70 enum message_type type;
72 UINT flags; /* InSendMessageEx return flags */
75 /* structure to group all parameters for sent messages of the various kinds */
76 struct send_message_info
78 enum message_type type;
84 UINT flags; /* flags for SendMessageTimeout */
85 UINT timeout; /* timeout for SendMessageTimeout */
86 SENDASYNCPROC callback; /* callback function for SendMessageCallback */
87 ULONG_PTR data; /* callback data */
88 enum wm_char_mapping wm_char;
92 /* flag for messages that contain pointers */
93 /* 32 messages per entry, messages 0..31 map to bits 0..31 */
95 #define SET(msg) (1 << ((msg) & 31))
97 static const unsigned int message_pointer_flags[] =
100 SET(WM_CREATE) | SET(WM_SETTEXT) | SET(WM_GETTEXT) |
101 SET(WM_WININICHANGE) | SET(WM_DEVMODECHANGE),
103 SET(WM_GETMINMAXINFO) | SET(WM_DRAWITEM) | SET(WM_MEASUREITEM) | SET(WM_DELETEITEM) |
106 SET(WM_WINDOWPOSCHANGING) | SET(WM_WINDOWPOSCHANGED) | SET(WM_COPYDATA) |
107 SET(WM_NOTIFY) | SET(WM_HELP),
109 SET(WM_STYLECHANGING) | SET(WM_STYLECHANGED),
111 SET(WM_NCCREATE) | SET(WM_NCCALCSIZE) | SET(WM_GETDLGCODE),
113 SET(EM_GETSEL) | SET(EM_GETRECT) | SET(EM_SETRECT) | SET(EM_SETRECTNP),
115 SET(EM_REPLACESEL) | SET(EM_GETLINE) | SET(EM_SETTABSTOPS),
117 SET(SBM_GETRANGE) | SET(SBM_SETSCROLLINFO) | SET(SBM_GETSCROLLINFO) | SET(SBM_GETSCROLLBARINFO),
123 SET(CB_GETEDITSEL) | SET(CB_ADDSTRING) | SET(CB_DIR) | SET(CB_GETLBTEXT) |
124 SET(CB_INSERTSTRING) | SET(CB_FINDSTRING) | SET(CB_SELECTSTRING) |
125 SET(CB_GETDROPPEDCONTROLRECT) | SET(CB_FINDSTRINGEXACT),
129 SET(LB_ADDSTRING) | SET(LB_INSERTSTRING) | SET(LB_GETTEXT) | SET(LB_SELECTSTRING) |
130 SET(LB_DIR) | SET(LB_FINDSTRING) |
131 SET(LB_GETSELITEMS) | SET(LB_SETTABSTOPS) | SET(LB_ADDFILE) | SET(LB_GETITEMRECT),
133 SET(LB_FINDSTRINGEXACT),
139 SET(WM_NEXTMENU) | SET(WM_SIZING) | SET(WM_MOVING) | SET(WM_DEVICECHANGE),
141 SET(WM_MDICREATE) | SET(WM_MDIGETACTIVE) | SET(WM_DROPOBJECT) |
142 SET(WM_QUERYDROPOBJECT) | SET(WM_DRAGLOOP) | SET(WM_DRAGSELECT) | SET(WM_DRAGMOVE),
156 SET(WM_ASKCBFORMATNAME)
159 /* flags for messages that contain Unicode strings */
160 static const unsigned int message_unicode_flags[] =
163 SET(WM_CREATE) | SET(WM_SETTEXT) | SET(WM_GETTEXT) | SET(WM_GETTEXTLENGTH) |
164 SET(WM_WININICHANGE) | SET(WM_DEVMODECHANGE),
176 SET(EM_REPLACESEL) | SET(EM_GETLINE) | SET(EM_SETPASSWORDCHAR),
180 SET(WM_CHAR) | SET(WM_DEADCHAR) | SET(WM_SYSCHAR) | SET(WM_SYSDEADCHAR),
184 SET(CB_ADDSTRING) | SET(CB_DIR) | SET(CB_GETLBTEXT) | SET(CB_GETLBTEXTLEN) |
185 SET(CB_INSERTSTRING) | SET(CB_FINDSTRING) | SET(CB_SELECTSTRING) | SET(CB_FINDSTRINGEXACT),
189 SET(LB_ADDSTRING) | SET(LB_INSERTSTRING) | SET(LB_GETTEXT) | SET(LB_GETTEXTLEN) |
190 SET(LB_SELECTSTRING) | SET(LB_DIR) | SET(LB_FINDSTRING) | SET(LB_ADDFILE),
192 SET(LB_FINDSTRINGEXACT),
214 SET(WM_PAINTCLIPBOARD) | SET(WM_SIZECLIPBOARD) | SET(WM_ASKCBFORMATNAME)
217 /* check whether a given message type includes pointers */
218 static inline int is_pointer_message( UINT message )
220 if (message >= 8*sizeof(message_pointer_flags)) return FALSE;
221 return (message_pointer_flags[message / 32] & SET(message)) != 0;
224 /* check whether a given message type contains Unicode (or ASCII) chars */
225 static inline int is_unicode_message( UINT message )
227 if (message >= 8*sizeof(message_unicode_flags)) return FALSE;
228 return (message_unicode_flags[message / 32] & SET(message)) != 0;
233 /* add a data field to a packed message */
234 static inline void push_data( struct packed_message *data, const void *ptr, size_t size )
236 data->data[data->count] = ptr;
237 data->size[data->count] = size;
241 /* add a string to a packed message */
242 static inline void push_string( struct packed_message *data, LPCWSTR str )
244 push_data( data, str, (strlenW(str) + 1) * sizeof(WCHAR) );
247 /* retrieve a pointer to data from a packed message and increment the buffer pointer */
248 static inline void *get_data( void **buffer, size_t size )
251 *buffer = (char *)*buffer + size;
255 /* make sure that the buffer contains a valid null-terminated Unicode string */
256 static inline BOOL check_string( LPCWSTR str, size_t size )
258 for (size /= sizeof(WCHAR); size; size--, str++)
259 if (!*str) return TRUE;
263 /* make sure that there is space for 'size' bytes in buffer, growing it if needed */
264 static inline void *get_buffer_space( void **buffer, size_t size )
270 if (!(ret = HeapReAlloc( GetProcessHeap(), 0, *buffer, size )))
271 HeapFree( GetProcessHeap(), 0, *buffer );
273 else ret = HeapAlloc( GetProcessHeap(), 0, size );
279 /* check whether a combobox expects strings or ids in CB_ADDSTRING/CB_INSERTSTRING */
280 static inline BOOL combobox_has_strings( HWND hwnd )
282 DWORD style = GetWindowLongA( hwnd, GWL_STYLE );
283 return (!(style & (CBS_OWNERDRAWFIXED | CBS_OWNERDRAWVARIABLE)) || (style & CBS_HASSTRINGS));
286 /* check whether a listbox expects strings or ids in LB_ADDSTRING/LB_INSERTSTRING */
287 static inline BOOL listbox_has_strings( HWND hwnd )
289 DWORD style = GetWindowLongA( hwnd, GWL_STYLE );
290 return (!(style & (LBS_OWNERDRAWFIXED | LBS_OWNERDRAWVARIABLE)) || (style & LBS_HASSTRINGS));
293 /* check whether message is in the range of keyboard messages */
294 static inline BOOL is_keyboard_message( UINT message )
296 return (message >= WM_KEYFIRST && message <= WM_KEYLAST);
299 /* check whether message is in the range of mouse messages */
300 static inline BOOL is_mouse_message( UINT message )
302 return ((message >= WM_NCMOUSEFIRST && message <= WM_NCMOUSELAST) ||
303 (message >= WM_MOUSEFIRST && message <= WM_MOUSELAST));
306 /* check whether message matches the specified hwnd filter */
307 static inline BOOL check_hwnd_filter( const MSG *msg, HWND hwnd_filter )
309 if (!hwnd_filter || hwnd_filter == GetDesktopWindow()) return TRUE;
310 return (msg->hwnd == hwnd_filter || IsChild( hwnd_filter, msg->hwnd ));
313 /* check for pending WM_CHAR message with DBCS trailing byte */
314 static inline BOOL get_pending_wmchar( MSG *msg, UINT first, UINT last, BOOL remove )
316 struct wm_char_mapping_data *data = get_user_thread_info()->wmchar_data;
318 if (!data || !data->get_msg.message) return FALSE;
319 if ((first || last) && (first > WM_CHAR || last < WM_CHAR)) return FALSE;
320 if (!msg) return FALSE;
321 *msg = data->get_msg;
322 if (remove) data->get_msg.message = 0;
326 /***********************************************************************
327 * broadcast_message_callback
329 * Helper callback for broadcasting messages.
331 static BOOL CALLBACK broadcast_message_callback( HWND hwnd, LPARAM lparam )
333 struct send_message_info *info = (struct send_message_info *)lparam;
334 if (!(GetWindowLongW( hwnd, GWL_STYLE ) & (WS_POPUP|WS_CAPTION))) return TRUE;
338 SendMessageTimeoutW( hwnd, info->msg, info->wparam, info->lparam,
339 info->flags, info->timeout, NULL );
342 SendMessageTimeoutA( hwnd, info->msg, info->wparam, info->lparam,
343 info->flags, info->timeout, NULL );
346 SendNotifyMessageW( hwnd, info->msg, info->wparam, info->lparam );
349 SendMessageCallbackW( hwnd, info->msg, info->wparam, info->lparam,
350 info->callback, info->data );
353 PostMessageW( hwnd, info->msg, info->wparam, info->lparam );
356 ERR( "bad type %d\n", info->type );
363 /***********************************************************************
366 * Convert the wparam of an ASCII message to Unicode.
368 BOOL map_wparam_AtoW( UINT message, WPARAM *wparam, enum wm_char_mapping mapping )
377 /* WM_CHAR is magic: a DBCS char can be sent/posted as two consecutive WM_CHAR
378 * messages, in which case the first char is stored, and the conversion
379 * to Unicode only takes place once the second char is sent/posted.
381 if (mapping != WMCHAR_MAP_NOMAPPING)
383 struct wm_char_mapping_data *data = get_user_thread_info()->wmchar_data;
384 BYTE low = LOBYTE(*wparam);
389 ch[1] = HIBYTE(*wparam);
390 RtlMultiByteToUnicodeN( wch, sizeof(wch), NULL, ch, 2 );
391 TRACE( "map %02x,%02x -> %04x mapping %u\n", (BYTE)ch[0], (BYTE)ch[1], wch[0], mapping );
392 if (data) data->lead_byte[mapping] = 0;
394 else if (data && data->lead_byte[mapping])
396 ch[0] = data->lead_byte[mapping];
398 RtlMultiByteToUnicodeN( wch, sizeof(wch), NULL, ch, 2 );
399 TRACE( "map stored %02x,%02x -> %04x mapping %u\n", (BYTE)ch[0], (BYTE)ch[1], wch[0], mapping );
400 data->lead_byte[mapping] = 0;
402 else if (!IsDBCSLeadByte( low ))
405 RtlMultiByteToUnicodeN( wch, sizeof(wch), NULL, ch, 1 );
406 TRACE( "map %02x -> %04x\n", (BYTE)ch[0], wch[0] );
407 if (data) data->lead_byte[mapping] = 0;
409 else /* store it and wait for trail byte */
413 if (!(data = HeapAlloc( GetProcessHeap(), HEAP_ZERO_MEMORY, sizeof(*data) )))
415 get_user_thread_info()->wmchar_data = data;
417 TRACE( "storing lead byte %02x mapping %u\n", low, mapping );
418 data->lead_byte[mapping] = low;
421 *wparam = MAKEWPARAM(wch[0], wch[1]);
424 /* else fall through */
426 case EM_SETPASSWORDCHAR:
431 ch[0] = LOBYTE(*wparam);
432 ch[1] = HIBYTE(*wparam);
433 RtlMultiByteToUnicodeN( wch, sizeof(wch), NULL, ch, 2 );
434 *wparam = MAKEWPARAM(wch[0], wch[1]);
437 ch[0] = HIBYTE(*wparam);
438 ch[1] = LOBYTE(*wparam);
439 if (ch[0]) RtlMultiByteToUnicodeN( wch, sizeof(wch[0]), NULL, ch, 2 );
440 else RtlMultiByteToUnicodeN( wch, sizeof(wch[0]), NULL, ch + 1, 1 );
441 *wparam = MAKEWPARAM(wch[0], HIWORD(*wparam));
448 /***********************************************************************
451 * Convert the wparam of a Unicode message to ASCII.
453 static void map_wparam_WtoA( MSG *msg, BOOL remove )
462 if (!HIWORD(msg->wParam))
464 wch[0] = LOWORD(msg->wParam);
466 RtlUnicodeToMultiByteN( (LPSTR)ch, 2, &len, wch, sizeof(wch[0]) );
467 if (len == 2) /* DBCS char */
469 struct wm_char_mapping_data *data = get_user_thread_info()->wmchar_data;
472 if (!(data = HeapAlloc( GetProcessHeap(), HEAP_ZERO_MEMORY, sizeof(*data) ))) return;
473 get_user_thread_info()->wmchar_data = data;
477 data->get_msg = *msg;
478 data->get_msg.wParam = ch[1];
484 /* else fall through */
486 case EM_SETPASSWORDCHAR:
491 wch[0] = LOWORD(msg->wParam);
492 wch[1] = HIWORD(msg->wParam);
494 RtlUnicodeToMultiByteN( (LPSTR)ch, 2, NULL, wch, sizeof(wch) );
495 msg->wParam = MAKEWPARAM( ch[0] | (ch[1] << 8), 0 );
498 wch[0] = LOWORD(msg->wParam);
500 RtlUnicodeToMultiByteN( (LPSTR)ch, 2, &len, wch, sizeof(wch[0]) );
502 msg->wParam = MAKEWPARAM( (ch[0] << 8) | ch[1], HIWORD(msg->wParam) );
504 msg->wParam = MAKEWPARAM( ch[0], HIWORD(msg->wParam) );
510 /***********************************************************************
513 * Pack a message for sending to another process.
514 * Return the size of the data we expect in the message reply.
515 * Set data->count to -1 if there is an error.
517 static size_t pack_message( HWND hwnd, UINT message, WPARAM wparam, LPARAM lparam,
518 struct packed_message *data )
526 CREATESTRUCTW *cs = (CREATESTRUCTW *)lparam;
527 push_data( data, cs, sizeof(*cs) );
528 if (HIWORD(cs->lpszName)) push_string( data, cs->lpszName );
529 if (HIWORD(cs->lpszClass)) push_string( data, cs->lpszClass );
533 case WM_ASKCBFORMATNAME:
534 return wparam * sizeof(WCHAR);
535 case WM_WININICHANGE:
536 if (lparam) push_string(data, (LPWSTR)lparam );
539 case WM_DEVMODECHANGE:
544 push_string( data, (LPWSTR)lparam );
546 case WM_GETMINMAXINFO:
547 push_data( data, (MINMAXINFO *)lparam, sizeof(MINMAXINFO) );
548 return sizeof(MINMAXINFO);
550 push_data( data, (DRAWITEMSTRUCT *)lparam, sizeof(DRAWITEMSTRUCT) );
553 push_data( data, (MEASUREITEMSTRUCT *)lparam, sizeof(MEASUREITEMSTRUCT) );
554 return sizeof(MEASUREITEMSTRUCT);
556 push_data( data, (DELETEITEMSTRUCT *)lparam, sizeof(DELETEITEMSTRUCT) );
559 push_data( data, (COMPAREITEMSTRUCT *)lparam, sizeof(COMPAREITEMSTRUCT) );
561 case WM_WINDOWPOSCHANGING:
562 case WM_WINDOWPOSCHANGED:
563 push_data( data, (WINDOWPOS *)lparam, sizeof(WINDOWPOS) );
564 return sizeof(WINDOWPOS);
567 COPYDATASTRUCT *cp = (COPYDATASTRUCT *)lparam;
568 push_data( data, cp, sizeof(*cp) );
569 if (cp->lpData) push_data( data, cp->lpData, cp->cbData );
573 /* WM_NOTIFY cannot be sent across processes (MSDN) */
577 push_data( data, (HELPINFO *)lparam, sizeof(HELPINFO) );
579 case WM_STYLECHANGING:
580 case WM_STYLECHANGED:
581 push_data( data, (STYLESTRUCT *)lparam, sizeof(STYLESTRUCT) );
586 push_data( data, (RECT *)lparam, sizeof(RECT) );
591 NCCALCSIZE_PARAMS *nc = (NCCALCSIZE_PARAMS *)lparam;
592 push_data( data, nc, sizeof(*nc) );
593 push_data( data, nc->lppos, sizeof(*nc->lppos) );
594 return sizeof(*nc) + sizeof(*nc->lppos);
597 if (lparam) push_data( data, (MSG *)lparam, sizeof(MSG) );
599 case SBM_SETSCROLLINFO:
600 push_data( data, (SCROLLINFO *)lparam, sizeof(SCROLLINFO) );
602 case SBM_GETSCROLLINFO:
603 push_data( data, (SCROLLINFO *)lparam, sizeof(SCROLLINFO) );
604 return sizeof(SCROLLINFO);
605 case SBM_GETSCROLLBARINFO:
607 const SCROLLBARINFO *info = (const SCROLLBARINFO *)lparam;
608 size_t size = min( info->cbSize, sizeof(SCROLLBARINFO) );
609 push_data( data, info, size );
617 if (wparam) size += sizeof(DWORD);
618 if (lparam) size += sizeof(DWORD);
623 case CB_GETDROPPEDCONTROLRECT:
627 push_data( data, (RECT *)lparam, sizeof(RECT) );
631 WORD *pw = (WORD *)lparam;
632 push_data( data, pw, sizeof(*pw) );
633 return *pw * sizeof(WCHAR);
637 if (wparam) push_data( data, (UINT *)lparam, sizeof(UINT) * wparam );
640 case CB_INSERTSTRING:
642 case CB_FINDSTRINGEXACT:
643 case CB_SELECTSTRING:
644 if (combobox_has_strings( hwnd )) push_string( data, (LPWSTR)lparam );
647 if (!combobox_has_strings( hwnd )) return sizeof(ULONG_PTR);
648 return (SendMessageW( hwnd, CB_GETLBTEXTLEN, wparam, 0 ) + 1) * sizeof(WCHAR);
650 case LB_INSERTSTRING:
652 case LB_FINDSTRINGEXACT:
653 case LB_SELECTSTRING:
654 if (listbox_has_strings( hwnd )) push_string( data, (LPWSTR)lparam );
657 if (!listbox_has_strings( hwnd )) return sizeof(ULONG_PTR);
658 return (SendMessageW( hwnd, LB_GETTEXTLEN, wparam, 0 ) + 1) * sizeof(WCHAR);
660 return wparam * sizeof(UINT);
662 push_data( data, (MDINEXTMENU *)lparam, sizeof(MDINEXTMENU) );
663 return sizeof(MDINEXTMENU);
666 push_data( data, (RECT *)lparam, sizeof(RECT) );
670 MDICREATESTRUCTW *cs = (MDICREATESTRUCTW *)lparam;
671 push_data( data, cs, sizeof(*cs) );
672 if (HIWORD(cs->szTitle)) push_string( data, cs->szTitle );
673 if (HIWORD(cs->szClass)) push_string( data, cs->szClass );
676 case WM_MDIGETACTIVE:
677 if (lparam) return sizeof(BOOL);
679 case WM_DEVICECHANGE:
681 DEV_BROADCAST_HDR *header = (DEV_BROADCAST_HDR *)lparam;
682 push_data( data, header, header->dbch_size );
685 case WM_WINE_SETWINDOWPOS:
686 push_data( data, (WINDOWPOS *)lparam, sizeof(WINDOWPOS) );
688 case WM_WINE_KEYBOARD_LL_HOOK:
690 struct hook_extra_info *h_extra = (struct hook_extra_info *)lparam;
691 push_data( data, h_extra, sizeof(*h_extra) );
692 push_data( data, (LPVOID)h_extra->lparam, sizeof(KBDLLHOOKSTRUCT) );
695 case WM_WINE_MOUSE_LL_HOOK:
697 struct hook_extra_info *h_extra = (struct hook_extra_info *)lparam;
698 push_data( data, h_extra, sizeof(*h_extra) );
699 push_data( data, (LPVOID)h_extra->lparam, sizeof(MSLLHOOKSTRUCT) );
703 if (wparam <= 1) return 0;
704 FIXME( "WM_NCPAINT hdc packing not supported yet\n" );
708 if (!wparam) return 0;
711 /* these contain an HFONT */
714 /* these contain an HDC */
716 case WM_ICONERASEBKGND:
717 case WM_CTLCOLORMSGBOX:
718 case WM_CTLCOLOREDIT:
719 case WM_CTLCOLORLISTBOX:
722 case WM_CTLCOLORSCROLLBAR:
723 case WM_CTLCOLORSTATIC:
726 /* these contain an HGLOBAL */
727 case WM_PAINTCLIPBOARD:
728 case WM_SIZECLIPBOARD:
729 /* these contain HICON */
732 case WM_QUERYDRAGICON:
733 case WM_QUERYPARKICON:
734 /* these contain pointers */
736 case WM_QUERYDROPOBJECT:
740 FIXME( "msg %x (%s) not supported yet\n", message, SPY_GetMsgName(message, hwnd) );
748 /***********************************************************************
751 * Unpack a message received from another process.
753 static BOOL unpack_message( HWND hwnd, UINT message, WPARAM *wparam, LPARAM *lparam,
754 void **buffer, size_t size )
763 CREATESTRUCTW *cs = *buffer;
764 WCHAR *str = (WCHAR *)(cs + 1);
765 if (size < sizeof(*cs)) return FALSE;
767 if (HIWORD(cs->lpszName))
769 if (!check_string( str, size )) return FALSE;
771 size -= (strlenW(str) + 1) * sizeof(WCHAR);
772 str += strlenW(str) + 1;
774 if (HIWORD(cs->lpszClass))
776 if (!check_string( str, size )) return FALSE;
782 case WM_ASKCBFORMATNAME:
783 if (!get_buffer_space( buffer, (*wparam * sizeof(WCHAR)) )) return FALSE;
785 case WM_WININICHANGE:
786 if (!*lparam) return TRUE;
789 case WM_DEVMODECHANGE:
794 if (!check_string( *buffer, size )) return FALSE;
796 case WM_GETMINMAXINFO:
797 minsize = sizeof(MINMAXINFO);
800 minsize = sizeof(DRAWITEMSTRUCT);
803 minsize = sizeof(MEASUREITEMSTRUCT);
806 minsize = sizeof(DELETEITEMSTRUCT);
809 minsize = sizeof(COMPAREITEMSTRUCT);
811 case WM_WINDOWPOSCHANGING:
812 case WM_WINDOWPOSCHANGED:
813 case WM_WINE_SETWINDOWPOS:
814 minsize = sizeof(WINDOWPOS);
818 COPYDATASTRUCT *cp = *buffer;
819 if (size < sizeof(*cp)) return FALSE;
822 minsize = sizeof(*cp) + cp->cbData;
828 /* WM_NOTIFY cannot be sent across processes (MSDN) */
831 minsize = sizeof(HELPINFO);
833 case WM_STYLECHANGING:
834 case WM_STYLECHANGED:
835 minsize = sizeof(STYLESTRUCT);
838 if (!*wparam) minsize = sizeof(RECT);
841 NCCALCSIZE_PARAMS *nc = *buffer;
842 if (size < sizeof(*nc) + sizeof(*nc->lppos)) return FALSE;
843 nc->lppos = (WINDOWPOS *)(nc + 1);
847 if (!*lparam) return TRUE;
848 minsize = sizeof(MSG);
850 case SBM_SETSCROLLINFO:
851 minsize = sizeof(SCROLLINFO);
853 case SBM_GETSCROLLINFO:
854 if (!get_buffer_space( buffer, sizeof(SCROLLINFO ))) return FALSE;
856 case SBM_GETSCROLLBARINFO:
857 if (!get_buffer_space( buffer, sizeof(SCROLLBARINFO ))) return FALSE;
862 if (*wparam || *lparam)
864 if (!get_buffer_space( buffer, 2*sizeof(DWORD) )) return FALSE;
865 if (*wparam) *wparam = (WPARAM)*buffer;
866 if (*lparam) *lparam = (LPARAM)((DWORD *)*buffer + 1);
871 case CB_GETDROPPEDCONTROLRECT:
872 if (!get_buffer_space( buffer, sizeof(RECT) )) return FALSE;
876 minsize = sizeof(RECT);
881 if (size < sizeof(WORD)) return FALSE;
882 len = *(WORD *)*buffer;
883 if (!get_buffer_space( buffer, (len + 1) * sizeof(WCHAR) )) return FALSE;
884 *lparam = (LPARAM)*buffer + sizeof(WORD); /* don't erase WORD at start of buffer */
889 if (!*wparam) return TRUE;
890 minsize = *wparam * sizeof(UINT);
893 case CB_INSERTSTRING:
895 case CB_FINDSTRINGEXACT:
896 case CB_SELECTSTRING:
898 case LB_INSERTSTRING:
900 case LB_FINDSTRINGEXACT:
901 case LB_SELECTSTRING:
902 if (!*buffer) return TRUE;
903 if (!check_string( *buffer, size )) return FALSE;
907 size = sizeof(ULONG_PTR);
908 if (combobox_has_strings( hwnd ))
909 size = (SendMessageW( hwnd, CB_GETLBTEXTLEN, *wparam, 0 ) + 1) * sizeof(WCHAR);
910 if (!get_buffer_space( buffer, size )) return FALSE;
915 size = sizeof(ULONG_PTR);
916 if (listbox_has_strings( hwnd ))
917 size = (SendMessageW( hwnd, LB_GETTEXTLEN, *wparam, 0 ) + 1) * sizeof(WCHAR);
918 if (!get_buffer_space( buffer, size )) return FALSE;
922 if (!get_buffer_space( buffer, *wparam * sizeof(UINT) )) return FALSE;
925 minsize = sizeof(MDINEXTMENU);
926 if (!get_buffer_space( buffer, sizeof(MDINEXTMENU) )) return FALSE;
930 minsize = sizeof(RECT);
931 if (!get_buffer_space( buffer, sizeof(RECT) )) return FALSE;
935 MDICREATESTRUCTW *cs = *buffer;
936 WCHAR *str = (WCHAR *)(cs + 1);
937 if (size < sizeof(*cs)) return FALSE;
939 if (HIWORD(cs->szTitle))
941 if (!check_string( str, size )) return FALSE;
943 size -= (strlenW(str) + 1) * sizeof(WCHAR);
944 str += strlenW(str) + 1;
946 if (HIWORD(cs->szClass))
948 if (!check_string( str, size )) return FALSE;
953 case WM_MDIGETACTIVE:
954 if (!*lparam) return TRUE;
955 if (!get_buffer_space( buffer, sizeof(BOOL) )) return FALSE;
957 case WM_DEVICECHANGE:
958 minsize = sizeof(DEV_BROADCAST_HDR);
960 case WM_WINE_KEYBOARD_LL_HOOK:
961 case WM_WINE_MOUSE_LL_HOOK:
963 struct hook_extra_info *h_extra = (struct hook_extra_info *)*buffer;
965 minsize = sizeof(struct hook_extra_info) +
966 (message == WM_WINE_KEYBOARD_LL_HOOK ? sizeof(KBDLLHOOKSTRUCT)
967 : sizeof(MSLLHOOKSTRUCT));
968 if (size < minsize) return FALSE;
969 h_extra->lparam = (LPARAM)(h_extra + 1);
973 if (*wparam <= 1) return TRUE;
974 FIXME( "WM_NCPAINT hdc unpacking not supported\n" );
977 if (!*wparam) return TRUE;
980 /* these contain an HFONT */
983 /* these contain an HDC */
985 case WM_ICONERASEBKGND:
986 case WM_CTLCOLORMSGBOX:
987 case WM_CTLCOLOREDIT:
988 case WM_CTLCOLORLISTBOX:
991 case WM_CTLCOLORSCROLLBAR:
992 case WM_CTLCOLORSTATIC:
995 /* these contain an HGLOBAL */
996 case WM_PAINTCLIPBOARD:
997 case WM_SIZECLIPBOARD:
998 /* these contain HICON */
1001 case WM_QUERYDRAGICON:
1002 case WM_QUERYPARKICON:
1003 /* these contain pointers */
1005 case WM_QUERYDROPOBJECT:
1009 FIXME( "msg %x (%s) not supported yet\n", message, SPY_GetMsgName(message, hwnd) );
1013 return TRUE; /* message doesn't need any unpacking */
1016 /* default exit for most messages: check minsize and store buffer in lparam */
1017 if (size < minsize) return FALSE;
1018 *lparam = (LPARAM)*buffer;
1023 /***********************************************************************
1026 * Pack a reply to a message for sending to another process.
1028 static void pack_reply( HWND hwnd, UINT message, WPARAM wparam, LPARAM lparam,
1029 LRESULT res, struct packed_message *data )
1036 push_data( data, (CREATESTRUCTW *)lparam, sizeof(CREATESTRUCTW) );
1041 push_data( data, (WCHAR *)lparam, (res + 1) * sizeof(WCHAR) );
1043 case WM_GETMINMAXINFO:
1044 push_data( data, (MINMAXINFO *)lparam, sizeof(MINMAXINFO) );
1046 case WM_MEASUREITEM:
1047 push_data( data, (MEASUREITEMSTRUCT *)lparam, sizeof(MEASUREITEMSTRUCT) );
1049 case WM_WINDOWPOSCHANGING:
1050 case WM_WINDOWPOSCHANGED:
1051 push_data( data, (WINDOWPOS *)lparam, sizeof(WINDOWPOS) );
1054 if (lparam) push_data( data, (MSG *)lparam, sizeof(MSG) );
1056 case SBM_GETSCROLLINFO:
1057 push_data( data, (SCROLLINFO *)lparam, sizeof(SCROLLINFO) );
1060 case LB_GETITEMRECT:
1061 case CB_GETDROPPEDCONTROLRECT:
1064 push_data( data, (RECT *)lparam, sizeof(RECT) );
1068 WORD *ptr = (WORD *)lparam;
1069 push_data( data, ptr, ptr[-1] * sizeof(WCHAR) );
1072 case LB_GETSELITEMS:
1073 push_data( data, (UINT *)lparam, wparam * sizeof(UINT) );
1075 case WM_MDIGETACTIVE:
1076 if (lparam) push_data( data, (BOOL *)lparam, sizeof(BOOL) );
1080 push_data( data, (RECT *)lparam, sizeof(RECT) );
1083 NCCALCSIZE_PARAMS *nc = (NCCALCSIZE_PARAMS *)lparam;
1084 push_data( data, nc, sizeof(*nc) );
1085 push_data( data, nc->lppos, sizeof(*nc->lppos) );
1091 if (wparam) push_data( data, (DWORD *)wparam, sizeof(DWORD) );
1092 if (lparam) push_data( data, (DWORD *)lparam, sizeof(DWORD) );
1095 push_data( data, (MDINEXTMENU *)lparam, sizeof(MDINEXTMENU) );
1098 push_data( data, (MDICREATESTRUCTW *)lparam, sizeof(MDICREATESTRUCTW) );
1100 case WM_ASKCBFORMATNAME:
1101 push_data( data, (WCHAR *)lparam, (strlenW((WCHAR *)lparam) + 1) * sizeof(WCHAR) );
1107 /***********************************************************************
1110 * Unpack a message reply received from another process.
1112 static void unpack_reply( HWND hwnd, UINT message, WPARAM wparam, LPARAM lparam,
1113 void *buffer, size_t size )
1120 CREATESTRUCTW *cs = (CREATESTRUCTW *)lparam;
1121 LPCWSTR name = cs->lpszName, class = cs->lpszClass;
1122 memcpy( cs, buffer, min( sizeof(*cs), size ));
1123 cs->lpszName = name; /* restore the original pointers */
1124 cs->lpszClass = class;
1128 case WM_ASKCBFORMATNAME:
1129 memcpy( (WCHAR *)lparam, buffer, min( wparam*sizeof(WCHAR), size ));
1131 case WM_GETMINMAXINFO:
1132 memcpy( (MINMAXINFO *)lparam, buffer, min( sizeof(MINMAXINFO), size ));
1134 case WM_MEASUREITEM:
1135 memcpy( (MEASUREITEMSTRUCT *)lparam, buffer, min( sizeof(MEASUREITEMSTRUCT), size ));
1137 case WM_WINDOWPOSCHANGING:
1138 case WM_WINDOWPOSCHANGED:
1139 memcpy( (WINDOWPOS *)lparam, buffer, min( sizeof(WINDOWPOS), size ));
1142 if (lparam) memcpy( (MSG *)lparam, buffer, min( sizeof(MSG), size ));
1144 case SBM_GETSCROLLINFO:
1145 memcpy( (SCROLLINFO *)lparam, buffer, min( sizeof(SCROLLINFO), size ));
1147 case SBM_GETSCROLLBARINFO:
1148 memcpy( (SCROLLBARINFO *)lparam, buffer, min( sizeof(SCROLLBARINFO), size ));
1151 case CB_GETDROPPEDCONTROLRECT:
1152 case LB_GETITEMRECT:
1155 memcpy( (RECT *)lparam, buffer, min( sizeof(RECT), size ));
1158 size = min( size, (size_t)*(WORD *)lparam );
1159 memcpy( (WCHAR *)lparam, buffer, size );
1161 case LB_GETSELITEMS:
1162 memcpy( (UINT *)lparam, buffer, min( wparam*sizeof(UINT), size ));
1166 memcpy( (WCHAR *)lparam, buffer, size );
1169 memcpy( (MDINEXTMENU *)lparam, buffer, min( sizeof(MDINEXTMENU), size ));
1171 case WM_MDIGETACTIVE:
1172 if (lparam) memcpy( (BOOL *)lparam, buffer, min( sizeof(BOOL), size ));
1176 memcpy( (RECT *)lparam, buffer, min( sizeof(RECT), size ));
1179 NCCALCSIZE_PARAMS *nc = (NCCALCSIZE_PARAMS *)lparam;
1180 WINDOWPOS *wp = nc->lppos;
1181 memcpy( nc, buffer, min( sizeof(*nc), size ));
1182 if (size > sizeof(*nc))
1184 size -= sizeof(*nc);
1185 memcpy( wp, (NCCALCSIZE_PARAMS*)buffer + 1, min( sizeof(*wp), size ));
1187 nc->lppos = wp; /* restore the original pointer */
1195 memcpy( (DWORD *)wparam, buffer, min( sizeof(DWORD), size ));
1196 if (size <= sizeof(DWORD)) break;
1197 size -= sizeof(DWORD);
1198 buffer = (DWORD *)buffer + 1;
1200 if (lparam) memcpy( (DWORD *)lparam, buffer, min( sizeof(DWORD), size ));
1204 MDICREATESTRUCTW *cs = (MDICREATESTRUCTW *)lparam;
1205 LPCWSTR title = cs->szTitle, class = cs->szClass;
1206 memcpy( cs, buffer, min( sizeof(*cs), size ));
1207 cs->szTitle = title; /* restore the original pointers */
1208 cs->szClass = class;
1212 ERR( "should not happen: unexpected message %x\n", message );
1218 /***********************************************************************
1221 * Send a reply to a sent message.
1223 static void reply_message( struct received_message_info *info, LRESULT result, BOOL remove )
1225 struct packed_message data;
1226 int i, replied = info->flags & ISMEX_REPLIED;
1228 if (info->flags & ISMEX_NOTIFY) return; /* notify messages don't get replies */
1229 if (!remove && replied) return; /* replied already */
1232 info->flags |= ISMEX_REPLIED;
1234 if (info->type == MSG_OTHER_PROCESS && !replied)
1236 pack_reply( info->msg.hwnd, info->msg.message, info->msg.wParam,
1237 info->msg.lParam, result, &data );
1240 SERVER_START_REQ( reply_message )
1242 req->result = result;
1243 req->remove = remove;
1244 for (i = 0; i < data.count; i++) wine_server_add_data( req, data.data[i], data.size[i] );
1245 wine_server_call( req );
1251 /***********************************************************************
1252 * handle_internal_message
1254 * Handle an internal Wine message instead of calling the window proc.
1256 static LRESULT handle_internal_message( HWND hwnd, UINT msg, WPARAM wparam, LPARAM lparam )
1260 case WM_WINE_DESTROYWINDOW:
1261 return WIN_DestroyWindow( hwnd );
1262 case WM_WINE_SETWINDOWPOS:
1263 if (hwnd == GetDesktopWindow()) return 0;
1264 return USER_SetWindowPos( (WINDOWPOS *)lparam );
1265 case WM_WINE_SHOWWINDOW:
1266 if (hwnd == GetDesktopWindow()) return 0;
1267 return ShowWindow( hwnd, wparam );
1268 case WM_WINE_SETPARENT:
1269 if (hwnd == GetDesktopWindow()) return 0;
1270 return (LRESULT)SetParent( hwnd, (HWND)wparam );
1271 case WM_WINE_SETWINDOWLONG:
1272 return WIN_SetWindowLong( hwnd, (short)LOWORD(wparam), HIWORD(wparam), lparam, TRUE );
1273 case WM_WINE_ENABLEWINDOW:
1274 if (hwnd == GetDesktopWindow()) return 0;
1275 return EnableWindow( hwnd, wparam );
1276 case WM_WINE_SETACTIVEWINDOW:
1277 if (hwnd == GetDesktopWindow()) return 0;
1278 return (LRESULT)SetActiveWindow( (HWND)wparam );
1279 case WM_WINE_KEYBOARD_LL_HOOK:
1280 case WM_WINE_MOUSE_LL_HOOK:
1282 struct hook_extra_info *h_extra = (struct hook_extra_info *)lparam;
1284 return call_current_hook( h_extra->handle, HC_ACTION, wparam, h_extra->lparam );
1287 if (msg >= WM_WINE_FIRST_DRIVER_MSG && msg <= WM_WINE_LAST_DRIVER_MSG)
1288 return USER_Driver->pWindowMessage( hwnd, msg, wparam, lparam );
1289 FIXME( "unknown internal message %x\n", msg );
1294 /* since the WM_DDE_ACK response to a WM_DDE_EXECUTE message should contain the handle
1295 * to the memory handle, we keep track (in the server side) of all pairs of handle
1296 * used (the client passes its value and the content of the memory handle), and
1297 * the server stored both values (the client, and the local one, created after the
1298 * content). When a ACK message is generated, the list of pair is searched for a
1299 * matching pair, so that the client memory handle can be returned.
1302 HGLOBAL client_hMem;
1303 HGLOBAL server_hMem;
1306 static struct DDE_pair* dde_pairs;
1307 static int dde_num_alloc;
1308 static int dde_num_used;
1310 static CRITICAL_SECTION dde_crst;
1311 static CRITICAL_SECTION_DEBUG critsect_debug =
1314 { &critsect_debug.ProcessLocksList, &critsect_debug.ProcessLocksList },
1315 0, 0, { (DWORD_PTR)(__FILE__ ": dde_crst") }
1317 static CRITICAL_SECTION dde_crst = { &critsect_debug, -1, 0, 0, 0, 0 };
1319 static BOOL dde_add_pair(HGLOBAL chm, HGLOBAL shm)
1324 EnterCriticalSection(&dde_crst);
1326 /* now remember the pair of hMem on both sides */
1327 if (dde_num_used == dde_num_alloc)
1329 struct DDE_pair* tmp;
1331 tmp = HeapReAlloc( GetProcessHeap(), 0, dde_pairs,
1332 (dde_num_alloc + GROWBY) * sizeof(struct DDE_pair));
1334 tmp = HeapAlloc( GetProcessHeap(), 0,
1335 (dde_num_alloc + GROWBY) * sizeof(struct DDE_pair));
1339 LeaveCriticalSection(&dde_crst);
1343 /* zero out newly allocated part */
1344 memset(&dde_pairs[dde_num_alloc], 0, GROWBY * sizeof(struct DDE_pair));
1345 dde_num_alloc += GROWBY;
1348 for (i = 0; i < dde_num_alloc; i++)
1350 if (dde_pairs[i].server_hMem == 0)
1352 dde_pairs[i].client_hMem = chm;
1353 dde_pairs[i].server_hMem = shm;
1358 LeaveCriticalSection(&dde_crst);
1362 static HGLOBAL dde_get_pair(HGLOBAL shm)
1367 EnterCriticalSection(&dde_crst);
1368 for (i = 0; i < dde_num_alloc; i++)
1370 if (dde_pairs[i].server_hMem == shm)
1372 /* free this pair */
1373 dde_pairs[i].server_hMem = 0;
1375 ret = dde_pairs[i].client_hMem;
1379 LeaveCriticalSection(&dde_crst);
1383 /***********************************************************************
1386 * Post a DDE message
1388 static BOOL post_dde_message( struct packed_message *data, const struct send_message_info *info )
1392 UINT_PTR uiLo, uiHi;
1394 HGLOBAL hunlock = 0;
1398 if (!UnpackDDElParam( info->msg, info->lparam, &uiLo, &uiHi ))
1404 /* DDE messages which don't require packing are:
1413 /* uiHi should contain a hMem from WM_DDE_EXECUTE */
1414 HGLOBAL h = dde_get_pair( (HANDLE)uiHi );
1417 /* send back the value of h on the other side */
1418 push_data( data, &h, sizeof(HGLOBAL) );
1420 TRACE( "send dde-ack %lx %08lx => %p\n", uiLo, uiHi, h );
1425 /* uiHi should contain either an atom or 0 */
1426 TRACE( "send dde-ack %lx atom=%lx\n", uiLo, uiHi );
1427 lp = MAKELONG( uiLo, uiHi );
1436 size = GlobalSize( (HGLOBAL)uiLo ) ;
1437 if ((info->msg == WM_DDE_ADVISE && size < sizeof(DDEADVISE)) ||
1438 (info->msg == WM_DDE_DATA && size < sizeof(DDEDATA)) ||
1439 (info->msg == WM_DDE_POKE && size < sizeof(DDEPOKE))
1443 else if (info->msg != WM_DDE_DATA) return FALSE;
1448 if ((ptr = GlobalLock( (HGLOBAL)uiLo) ))
1450 DDEDATA *dde_data = (DDEDATA *)ptr;
1451 TRACE("unused %d, fResponse %d, fRelease %d, fDeferUpd %d, fAckReq %d, cfFormat %d\n",
1452 dde_data->unused, dde_data->fResponse, dde_data->fRelease,
1453 dde_data->reserved, dde_data->fAckReq, dde_data->cfFormat);
1454 push_data( data, ptr, size );
1455 hunlock = (HGLOBAL)uiLo;
1458 TRACE( "send ddepack %u %lx\n", size, uiHi );
1460 case WM_DDE_EXECUTE:
1463 if ((ptr = GlobalLock( (HGLOBAL)info->lparam) ))
1465 push_data(data, ptr, GlobalSize( (HGLOBAL)info->lparam ));
1466 /* so that the other side can send it back on ACK */
1468 hunlock = (HGLOBAL)info->lparam;
1473 SERVER_START_REQ( send_message )
1475 req->id = info->dest_tid;
1476 req->type = info->type;
1478 req->win = info->hwnd;
1479 req->msg = info->msg;
1480 req->wparam = info->wparam;
1482 req->timeout = TIMEOUT_INFINITE;
1483 for (i = 0; i < data->count; i++)
1484 wine_server_add_data( req, data->data[i], data->size[i] );
1485 if ((res = wine_server_call( req )))
1487 if (res == STATUS_INVALID_PARAMETER)
1488 /* FIXME: find a STATUS_ value for this one */
1489 SetLastError( ERROR_INVALID_THREAD_ID );
1491 SetLastError( RtlNtStatusToDosError(res) );
1494 FreeDDElParam(info->msg, info->lparam);
1497 if (hunlock) GlobalUnlock(hunlock);
1502 /***********************************************************************
1503 * unpack_dde_message
1505 * Unpack a posted DDE message received from another process.
1507 static BOOL unpack_dde_message( HWND hwnd, UINT message, WPARAM *wparam, LPARAM *lparam,
1508 void **buffer, size_t size )
1510 UINT_PTR uiLo, uiHi;
1519 /* hMem is being passed */
1520 if (size != sizeof(HGLOBAL)) return FALSE;
1521 if (!buffer || !*buffer) return FALSE;
1523 memcpy( &hMem, *buffer, size );
1524 uiHi = (UINT_PTR)hMem;
1525 TRACE("recv dde-ack %lx mem=%lx[%lx]\n", uiLo, uiHi, GlobalSize( hMem ));
1529 uiLo = LOWORD( *lparam );
1530 uiHi = HIWORD( *lparam );
1531 TRACE("recv dde-ack %lx atom=%lx\n", uiLo, uiHi);
1533 *lparam = PackDDElParam( WM_DDE_ACK, uiLo, uiHi );
1538 if ((!buffer || !*buffer) && message != WM_DDE_DATA) return FALSE;
1542 if (!(hMem = GlobalAlloc( GMEM_MOVEABLE|GMEM_DDESHARE, size )))
1544 if ((ptr = GlobalLock( hMem )))
1546 memcpy( ptr, *buffer, size );
1547 GlobalUnlock( hMem );
1555 uiLo = (UINT_PTR)hMem;
1557 *lparam = PackDDElParam( message, uiLo, uiHi );
1559 case WM_DDE_EXECUTE:
1562 if (!buffer || !*buffer) return FALSE;
1563 if (!(hMem = GlobalAlloc( GMEM_MOVEABLE|GMEM_DDESHARE, size ))) return FALSE;
1564 if ((ptr = GlobalLock( hMem )))
1566 memcpy( ptr, *buffer, size );
1567 GlobalUnlock( hMem );
1568 TRACE( "exec: pairing c=%08lx s=%p\n", *lparam, hMem );
1569 if (!dde_add_pair( (HGLOBAL)*lparam, hMem ))
1580 } else return FALSE;
1581 *lparam = (LPARAM)hMem;
1587 /***********************************************************************
1590 * Call a window procedure and the corresponding hooks.
1592 static LRESULT call_window_proc( HWND hwnd, UINT msg, WPARAM wparam, LPARAM lparam,
1593 BOOL unicode, BOOL same_thread, enum wm_char_mapping mapping )
1595 struct user_thread_info *thread_info = get_user_thread_info();
1598 CWPRETSTRUCT cwpret;
1600 if (thread_info->recursion_count > MAX_SENDMSG_RECURSION) return 0;
1601 thread_info->recursion_count++;
1603 if (msg & 0x80000000)
1605 result = handle_internal_message( hwnd, msg, wparam, lparam );
1609 /* first the WH_CALLWNDPROC hook */
1610 hwnd = WIN_GetFullHandle( hwnd );
1611 cwp.lParam = lparam;
1612 cwp.wParam = wparam;
1615 HOOK_CallHooks( WH_CALLWNDPROC, HC_ACTION, same_thread, (LPARAM)&cwp, unicode );
1617 /* now call the window procedure */
1618 if (!WINPROC_call_window( hwnd, msg, wparam, lparam, &result, unicode, mapping )) goto done;
1620 /* and finally the WH_CALLWNDPROCRET hook */
1621 cwpret.lResult = result;
1622 cwpret.lParam = lparam;
1623 cwpret.wParam = wparam;
1624 cwpret.message = msg;
1626 HOOK_CallHooks( WH_CALLWNDPROCRET, HC_ACTION, same_thread, (LPARAM)&cwpret, unicode );
1628 thread_info->recursion_count--;
1633 /***********************************************************************
1634 * send_parent_notify
1636 * Send a WM_PARENTNOTIFY to all ancestors of the given window, unless
1637 * the window has the WS_EX_NOPARENTNOTIFY style.
1639 static void send_parent_notify( HWND hwnd, WORD event, WORD idChild, POINT pt )
1641 /* pt has to be in the client coordinates of the parent window */
1642 MapWindowPoints( 0, hwnd, &pt, 1 );
1647 if (!(GetWindowLongW( hwnd, GWL_STYLE ) & WS_CHILD)) break;
1648 if (GetWindowLongW( hwnd, GWL_EXSTYLE ) & WS_EX_NOPARENTNOTIFY) break;
1649 if (!(parent = GetParent(hwnd))) break;
1650 if (parent == GetDesktopWindow()) break;
1651 MapWindowPoints( hwnd, parent, &pt, 1 );
1653 SendMessageW( hwnd, WM_PARENTNOTIFY,
1654 MAKEWPARAM( event, idChild ), MAKELPARAM( pt.x, pt.y ) );
1659 /***********************************************************************
1660 * accept_hardware_message
1662 * Tell the server we have passed the message to the app
1663 * (even though we may end up dropping it later on)
1665 static void accept_hardware_message( UINT hw_id, BOOL remove, HWND new_hwnd )
1667 SERVER_START_REQ( accept_hardware_message )
1670 req->remove = remove;
1671 req->new_win = new_hwnd;
1672 if (wine_server_call( req ))
1673 FIXME("Failed to reply to MSG_HARDWARE message. Message may not be removed from queue.\n");
1679 /***********************************************************************
1680 * process_keyboard_message
1682 * returns TRUE if the contents of 'msg' should be passed to the application
1684 static BOOL process_keyboard_message( MSG *msg, UINT hw_id, HWND hwnd_filter,
1685 UINT first, UINT last, BOOL remove )
1689 if (msg->message == WM_KEYDOWN || msg->message == WM_SYSKEYDOWN ||
1690 msg->message == WM_KEYUP || msg->message == WM_SYSKEYUP)
1691 switch (msg->wParam)
1693 case VK_LSHIFT: case VK_RSHIFT:
1694 msg->wParam = VK_SHIFT;
1696 case VK_LCONTROL: case VK_RCONTROL:
1697 msg->wParam = VK_CONTROL;
1699 case VK_LMENU: case VK_RMENU:
1700 msg->wParam = VK_MENU;
1704 /* FIXME: is this really the right place for this hook? */
1705 event.message = msg->message;
1706 event.hwnd = msg->hwnd;
1707 event.time = msg->time;
1708 event.paramL = (msg->wParam & 0xFF) | (HIWORD(msg->lParam) << 8);
1709 event.paramH = msg->lParam & 0x7FFF;
1710 if (HIWORD(msg->lParam) & 0x0100) event.paramH |= 0x8000; /* special_key - bit */
1711 HOOK_CallHooks( WH_JOURNALRECORD, HC_ACTION, 0, (LPARAM)&event, TRUE );
1713 /* check message filters */
1714 if (msg->message < first || msg->message > last) return FALSE;
1715 if (!check_hwnd_filter( msg, hwnd_filter )) return FALSE;
1719 if((msg->message == WM_KEYDOWN) &&
1720 (msg->hwnd != GetDesktopWindow()))
1722 /* Handle F1 key by sending out WM_HELP message */
1723 if (msg->wParam == VK_F1)
1725 PostMessageW( msg->hwnd, WM_KEYF1, 0, 0 );
1727 else if(msg->wParam >= VK_BROWSER_BACK &&
1728 msg->wParam <= VK_LAUNCH_APP2)
1730 /* FIXME: Process keystate */
1731 SendMessageW(msg->hwnd, WM_APPCOMMAND, (WPARAM)msg->hwnd, MAKELPARAM(0, (FAPPCOMMAND_KEY | (msg->wParam - VK_BROWSER_BACK + 1))));
1734 else if (msg->message == WM_KEYUP)
1736 /* Handle VK_APPS key by posting a WM_CONTEXTMENU message */
1737 if (msg->wParam == VK_APPS && !MENU_IsMenuActive())
1738 PostMessageW(msg->hwnd, WM_CONTEXTMENU, (WPARAM)msg->hwnd, (LPARAM)-1);
1742 if (HOOK_CallHooks( WH_KEYBOARD, remove ? HC_ACTION : HC_NOREMOVE,
1743 LOWORD(msg->wParam), msg->lParam, TRUE ))
1745 /* skip this message */
1746 HOOK_CallHooks( WH_CBT, HCBT_KEYSKIPPED, LOWORD(msg->wParam), msg->lParam, TRUE );
1747 accept_hardware_message( hw_id, TRUE, 0 );
1750 accept_hardware_message( hw_id, remove, 0 );
1752 if ( msg->message == WM_KEYDOWN || msg->message == WM_KEYUP )
1753 if ( ImmProcessKey(msg->hwnd, GetKeyboardLayout(0), msg->wParam, msg->lParam, 0) )
1754 msg->wParam = VK_PROCESSKEY;
1760 /***********************************************************************
1761 * process_mouse_message
1763 * returns TRUE if the contents of 'msg' should be passed to the application
1765 static BOOL process_mouse_message( MSG *msg, UINT hw_id, ULONG_PTR extra_info, HWND hwnd_filter,
1766 UINT first, UINT last, BOOL remove )
1775 MOUSEHOOKSTRUCT hook;
1778 /* find the window to dispatch this mouse message to */
1780 GetGUIThreadInfo( GetCurrentThreadId(), &info );
1781 if (info.hwndCapture)
1784 msg->hwnd = info.hwndCapture;
1788 msg->hwnd = WINPOS_WindowFromPoint( msg->hwnd, msg->pt, &hittest );
1791 if (!msg->hwnd || !WIN_IsCurrentThread( msg->hwnd ))
1793 accept_hardware_message( hw_id, TRUE, msg->hwnd );
1797 /* FIXME: is this really the right place for this hook? */
1798 event.message = msg->message;
1799 event.time = msg->time;
1800 event.hwnd = msg->hwnd;
1801 event.paramL = msg->pt.x;
1802 event.paramH = msg->pt.y;
1803 HOOK_CallHooks( WH_JOURNALRECORD, HC_ACTION, 0, (LPARAM)&event, TRUE );
1805 if (!check_hwnd_filter( msg, hwnd_filter )) return FALSE;
1808 message = msg->message;
1809 /* Note: windows has no concept of a non-client wheel message */
1810 if (message != WM_MOUSEWHEEL)
1812 if (hittest != HTCLIENT)
1814 message += WM_NCMOUSEMOVE - WM_MOUSEMOVE;
1815 msg->wParam = hittest;
1819 /* coordinates don't get translated while tracking a menu */
1820 /* FIXME: should differentiate popups and top-level menus */
1821 if (!(info.flags & GUI_INMENUMODE))
1822 ScreenToClient( msg->hwnd, &pt );
1825 msg->lParam = MAKELONG( pt.x, pt.y );
1827 /* translate double clicks */
1829 if ((msg->message == WM_LBUTTONDOWN) ||
1830 (msg->message == WM_RBUTTONDOWN) ||
1831 (msg->message == WM_MBUTTONDOWN) ||
1832 (msg->message == WM_XBUTTONDOWN))
1834 BOOL update = remove;
1836 /* translate double clicks -
1837 * note that ...MOUSEMOVEs can slip in between
1838 * ...BUTTONDOWN and ...BUTTONDBLCLK messages */
1840 if ((info.flags & (GUI_INMENUMODE|GUI_INMOVESIZE)) ||
1841 hittest != HTCLIENT ||
1842 (GetClassLongA( msg->hwnd, GCL_STYLE ) & CS_DBLCLKS))
1844 if ((msg->message == clk_msg.message) &&
1845 (msg->hwnd == clk_msg.hwnd) &&
1846 (msg->wParam == clk_msg.wParam) &&
1847 (msg->time - clk_msg.time < GetDoubleClickTime()) &&
1848 (abs(msg->pt.x - clk_msg.pt.x) < GetSystemMetrics(SM_CXDOUBLECLK)/2) &&
1849 (abs(msg->pt.y - clk_msg.pt.y) < GetSystemMetrics(SM_CYDOUBLECLK)/2))
1851 message += (WM_LBUTTONDBLCLK - WM_LBUTTONDOWN);
1854 clk_msg.message = 0; /* clear the double click conditions */
1859 if (message < first || message > last) return FALSE;
1860 /* update static double click conditions */
1861 if (update) clk_msg = *msg;
1865 if (message < first || message > last) return FALSE;
1868 /* message is accepted now (but may still get dropped) */
1871 hook.hwnd = msg->hwnd;
1872 hook.wHitTestCode = hittest;
1873 hook.dwExtraInfo = extra_info;
1874 if (HOOK_CallHooks( WH_MOUSE, remove ? HC_ACTION : HC_NOREMOVE,
1875 message, (LPARAM)&hook, TRUE ))
1878 hook.hwnd = msg->hwnd;
1879 hook.wHitTestCode = hittest;
1880 hook.dwExtraInfo = extra_info;
1881 HOOK_CallHooks( WH_CBT, HCBT_CLICKSKIPPED, message, (LPARAM)&hook, TRUE );
1882 accept_hardware_message( hw_id, TRUE, 0 );
1886 if ((hittest == HTERROR) || (hittest == HTNOWHERE))
1888 SendMessageW( msg->hwnd, WM_SETCURSOR, (WPARAM)msg->hwnd,
1889 MAKELONG( hittest, msg->message ));
1890 accept_hardware_message( hw_id, TRUE, 0 );
1894 accept_hardware_message( hw_id, remove, 0 );
1896 if (!remove || info.hwndCapture)
1898 msg->message = message;
1904 if ((msg->message == WM_LBUTTONDOWN) ||
1905 (msg->message == WM_RBUTTONDOWN) ||
1906 (msg->message == WM_MBUTTONDOWN) ||
1907 (msg->message == WM_XBUTTONDOWN))
1909 /* Send the WM_PARENTNOTIFY,
1910 * note that even for double/nonclient clicks
1911 * notification message is still WM_L/M/RBUTTONDOWN.
1913 send_parent_notify( msg->hwnd, msg->message, 0, msg->pt );
1915 /* Activate the window if needed */
1917 if (msg->hwnd != info.hwndActive)
1919 HWND hwndTop = msg->hwnd;
1922 if ((GetWindowLongW( hwndTop, GWL_STYLE ) & (WS_POPUP|WS_CHILD)) != WS_CHILD) break;
1923 hwndTop = GetParent( hwndTop );
1926 if (hwndTop && hwndTop != GetDesktopWindow())
1928 LONG ret = SendMessageW( msg->hwnd, WM_MOUSEACTIVATE, (WPARAM)hwndTop,
1929 MAKELONG( hittest, msg->message ) );
1932 case MA_NOACTIVATEANDEAT:
1937 case MA_ACTIVATEANDEAT:
1942 if (!FOCUS_MouseActivate( hwndTop )) eatMsg = TRUE;
1945 WARN( "unknown WM_MOUSEACTIVATE code %d\n", ret );
1952 /* send the WM_SETCURSOR message */
1954 /* Windows sends the normal mouse message as the message parameter
1955 in the WM_SETCURSOR message even if it's non-client mouse message */
1956 SendMessageW( msg->hwnd, WM_SETCURSOR, (WPARAM)msg->hwnd, MAKELONG( hittest, msg->message ));
1958 msg->message = message;
1963 /***********************************************************************
1964 * process_hardware_message
1966 * Process a hardware message; return TRUE if message should be passed on to the app
1968 static BOOL process_hardware_message( MSG *msg, UINT hw_id, ULONG_PTR extra_info, HWND hwnd_filter,
1969 UINT first, UINT last, BOOL remove )
1971 if (is_keyboard_message( msg->message ))
1972 return process_keyboard_message( msg, hw_id, hwnd_filter, first, last, remove );
1974 if (is_mouse_message( msg->message ))
1975 return process_mouse_message( msg, hw_id, extra_info, hwnd_filter, first, last, remove );
1977 ERR( "unknown message type %x\n", msg->message );
1982 /***********************************************************************
1983 * call_sendmsg_callback
1985 * Call the callback function of SendMessageCallback.
1987 static inline void call_sendmsg_callback( SENDASYNCPROC callback, HWND hwnd, UINT msg,
1988 ULONG_PTR data, LRESULT result )
1990 if (!callback) return;
1992 if (TRACE_ON(relay))
1993 DPRINTF( "%04x:Call message callback %p (hwnd=%p,msg=%s,data=%08lx,result=%08lx)\n",
1994 GetCurrentThreadId(), callback, hwnd, SPY_GetMsgName( msg, hwnd ),
1996 callback( hwnd, msg, data, result );
1997 if (TRACE_ON(relay))
1998 DPRINTF( "%04x:Ret message callback %p (hwnd=%p,msg=%s,data=%08lx,result=%08lx)\n",
1999 GetCurrentThreadId(), callback, hwnd, SPY_GetMsgName( msg, hwnd ),
2004 /***********************************************************************
2007 * Peek for a message matching the given parameters. Return FALSE if none available.
2008 * All pending sent messages are processed before returning.
2010 static BOOL peek_message( MSG *msg, HWND hwnd, UINT first, UINT last, UINT flags )
2013 ULONG_PTR extra_info = 0;
2014 struct user_thread_info *thread_info = get_user_thread_info();
2015 struct received_message_info info, *old_info;
2016 unsigned int wake_mask, changed_mask = HIWORD(flags);
2017 unsigned int hw_id = 0; /* id of previous hardware message */
2019 if (!first && !last) last = ~0;
2020 if (!changed_mask) changed_mask = QS_ALLINPUT;
2021 wake_mask = changed_mask & (QS_SENDMESSAGE | QS_SMRESULT);
2026 void *buffer = NULL;
2027 size_t size = 0, buffer_size = 0;
2029 do /* loop while buffer is too small */
2031 if (buffer_size && !(buffer = HeapAlloc( GetProcessHeap(), 0, buffer_size )))
2033 SERVER_START_REQ( get_message )
2036 req->get_win = hwnd;
2037 req->get_first = first;
2038 req->get_last = last;
2040 req->wake_mask = wake_mask;
2041 req->changed_mask = changed_mask;
2042 if (buffer_size) wine_server_set_reply( req, buffer, buffer_size );
2043 if (!(res = wine_server_call( req )))
2045 size = wine_server_reply_size( reply );
2046 info.type = reply->type;
2047 info.msg.hwnd = reply->win;
2048 info.msg.message = reply->msg;
2049 info.msg.wParam = reply->wparam;
2050 info.msg.lParam = reply->lparam;
2051 info.msg.time = reply->time;
2052 info.msg.pt.x = reply->x;
2053 info.msg.pt.y = reply->y;
2054 hw_id = reply->hw_id;
2055 extra_info = reply->info;
2056 thread_info->active_hooks = reply->active_hooks;
2060 HeapFree( GetProcessHeap(), 0, buffer );
2061 buffer_size = reply->total;
2065 } while (res == STATUS_BUFFER_OVERFLOW);
2067 if (res) return FALSE;
2069 TRACE( "got type %d msg %x (%s) hwnd %p wp %lx lp %lx\n",
2070 info.type, info.msg.message,
2071 (info.type == MSG_WINEVENT) ? "MSG_WINEVENT" : SPY_GetMsgName(info.msg.message, info.msg.hwnd),
2072 info.msg.hwnd, info.msg.wParam, info.msg.lParam );
2078 info.flags = ISMEX_SEND;
2081 info.flags = ISMEX_NOTIFY;
2084 info.flags = ISMEX_CALLBACK;
2086 case MSG_CALLBACK_RESULT:
2087 if (size >= sizeof(struct callback_msg_data))
2089 const struct callback_msg_data *data = (const struct callback_msg_data *)buffer;
2090 call_sendmsg_callback( data->callback, info.msg.hwnd,
2091 info.msg.message, data->data, data->result );
2095 if (size >= sizeof(struct winevent_msg_data))
2097 WINEVENTPROC hook_proc;
2098 const struct winevent_msg_data *data = (const struct winevent_msg_data *)buffer;
2100 hook_proc = data->hook_proc;
2101 size -= sizeof(*data);
2104 WCHAR module[MAX_PATH];
2106 size = min( size, (MAX_PATH - 1) * sizeof(WCHAR) );
2107 memcpy( module, buffer, size );
2108 module[size / sizeof(WCHAR)] = 0;
2109 if (!(hook_proc = get_hook_proc( hook_proc, module )))
2111 ERR( "invalid winevent hook module name %s\n", debugstr_w(module) );
2116 if (TRACE_ON(relay))
2117 DPRINTF( "%04x:Call winevent proc %p (hook=%p,event=%x,hwnd=%p,object_id=%lx,child_id=%lx,tid=%04x,time=%x)\n",
2118 GetCurrentThreadId(), hook_proc,
2119 data->hook, info.msg.message, info.msg.hwnd, info.msg.wParam,
2120 info.msg.lParam, data->tid, info.msg.time);
2122 hook_proc( data->hook, info.msg.message, info.msg.hwnd, info.msg.wParam,
2123 info.msg.lParam, data->tid, info.msg.time );
2125 if (TRACE_ON(relay))
2126 DPRINTF( "%04x:Ret winevent proc %p (hook=%p,event=%x,hwnd=%p,object_id=%lx,child_id=%lx,tid=%04x,time=%x)\n",
2127 GetCurrentThreadId(), hook_proc,
2128 data->hook, info.msg.message, info.msg.hwnd, info.msg.wParam,
2129 info.msg.lParam, data->tid, info.msg.time);
2132 case MSG_OTHER_PROCESS:
2133 info.flags = ISMEX_SEND;
2134 if (!unpack_message( info.msg.hwnd, info.msg.message, &info.msg.wParam,
2135 &info.msg.lParam, &buffer, size ))
2138 reply_message( &info, 0, TRUE );
2143 if (!process_hardware_message( &info.msg, hw_id, extra_info,
2144 hwnd, first, last, flags & PM_REMOVE ))
2146 TRACE("dropping msg %x\n", info.msg.message );
2147 goto next; /* ignore it */
2149 thread_info->GetMessagePosVal = MAKELONG( info.msg.pt.x, info.msg.pt.y );
2152 thread_info->GetMessageExtraInfoVal = extra_info;
2153 if (info.msg.message >= WM_DDE_FIRST && info.msg.message <= WM_DDE_LAST)
2155 if (!unpack_dde_message( info.msg.hwnd, info.msg.message, &info.msg.wParam,
2156 &info.msg.lParam, &buffer, size ))
2157 goto next; /* ignore it */
2160 HeapFree( GetProcessHeap(), 0, buffer );
2164 /* if we get here, we have a sent message; call the window procedure */
2165 old_info = thread_info->receive_info;
2166 thread_info->receive_info = &info;
2167 result = call_window_proc( info.msg.hwnd, info.msg.message, info.msg.wParam,
2168 info.msg.lParam, (info.type != MSG_ASCII), FALSE,
2169 WMCHAR_MAP_RECVMESSAGE );
2170 reply_message( &info, result, TRUE );
2171 thread_info->receive_info = old_info;
2173 /* if some PM_QS* flags were specified, only handle sent messages from now on */
2174 if (HIWORD(flags)) flags = PM_QS_SENDMESSAGE | LOWORD(flags);
2176 HeapFree( GetProcessHeap(), 0, buffer );
2181 /***********************************************************************
2182 * process_sent_messages
2184 * Process all pending sent messages.
2186 static inline void process_sent_messages(void)
2189 peek_message( &msg, 0, 0, 0, PM_REMOVE | PM_QS_SENDMESSAGE );
2193 /***********************************************************************
2194 * get_server_queue_handle
2196 * Get a handle to the server message queue for the current thread.
2198 static HANDLE get_server_queue_handle(void)
2200 struct user_thread_info *thread_info = get_user_thread_info();
2203 if (!(ret = thread_info->server_queue))
2205 SERVER_START_REQ( get_msg_queue )
2207 wine_server_call( req );
2208 ret = reply->handle;
2211 thread_info->server_queue = ret;
2212 if (!ret) ERR( "Cannot get server thread queue\n" );
2218 /***********************************************************************
2219 * wait_message_reply
2221 * Wait until a sent message gets replied to.
2223 static void wait_message_reply( UINT flags )
2225 HANDLE server_queue = get_server_queue_handle();
2229 unsigned int wake_bits = 0, changed_bits = 0;
2232 SERVER_START_REQ( set_queue_mask )
2234 req->wake_mask = QS_SMRESULT | ((flags & SMTO_BLOCK) ? 0 : QS_SENDMESSAGE);
2235 req->changed_mask = req->wake_mask;
2237 if (!wine_server_call( req ))
2239 wake_bits = reply->wake_bits;
2240 changed_bits = reply->changed_bits;
2245 if (wake_bits & QS_SMRESULT) return; /* got a result */
2246 if (wake_bits & QS_SENDMESSAGE)
2248 /* Process the sent message immediately */
2249 process_sent_messages();
2253 /* now wait for it */
2255 ReleaseThunkLock( &dwlc );
2256 res = USER_Driver->pMsgWaitForMultipleObjectsEx( 1, &server_queue,
2257 INFINITE, QS_SENDMESSAGE, 0 );
2258 if (dwlc) RestoreThunkLock( dwlc );
2262 /***********************************************************************
2263 * put_message_in_queue
2265 * Put a sent message into the destination queue.
2266 * For inter-process message, reply_size is set to expected size of reply data.
2268 static BOOL put_message_in_queue( const struct send_message_info *info, size_t *reply_size )
2270 struct packed_message data;
2271 message_data_t msg_data;
2274 timeout_t timeout = TIMEOUT_INFINITE;
2276 /* Check for INFINITE timeout for compatibility with Win9x,
2277 * although Windows >= NT does not do so
2279 if (info->type != MSG_NOTIFY &&
2280 info->type != MSG_CALLBACK &&
2281 info->type != MSG_POSTED &&
2283 info->timeout != INFINITE)
2285 /* timeout is signed despite the prototype */
2286 timeout = (timeout_t)max( 0, (int)info->timeout ) * -10000;
2290 if (info->type == MSG_OTHER_PROCESS)
2292 *reply_size = pack_message( info->hwnd, info->msg, info->wparam, info->lparam, &data );
2293 if (data.count == -1)
2295 WARN( "cannot pack message %x\n", info->msg );
2299 else if (info->type == MSG_CALLBACK)
2301 msg_data.callback.callback = info->callback;
2302 msg_data.callback.data = info->data;
2303 msg_data.callback.result = 0;
2304 data.data[0] = &msg_data;
2305 data.size[0] = sizeof(msg_data.callback);
2308 else if (info->type == MSG_POSTED && info->msg >= WM_DDE_FIRST && info->msg <= WM_DDE_LAST)
2310 return post_dde_message( &data, info );
2313 SERVER_START_REQ( send_message )
2315 req->id = info->dest_tid;
2316 req->type = info->type;
2318 req->win = info->hwnd;
2319 req->msg = info->msg;
2320 req->wparam = info->wparam;
2321 req->lparam = info->lparam;
2322 req->timeout = timeout;
2324 if (info->flags & SMTO_ABORTIFHUNG) req->flags |= SEND_MSG_ABORT_IF_HUNG;
2325 for (i = 0; i < data.count; i++) wine_server_add_data( req, data.data[i], data.size[i] );
2326 if ((res = wine_server_call( req )))
2328 if (res == STATUS_INVALID_PARAMETER)
2329 /* FIXME: find a STATUS_ value for this one */
2330 SetLastError( ERROR_INVALID_THREAD_ID );
2332 SetLastError( RtlNtStatusToDosError(res) );
2340 /***********************************************************************
2343 * Retrieve a message reply from the server.
2345 static LRESULT retrieve_reply( const struct send_message_info *info,
2346 size_t reply_size, LRESULT *result )
2349 void *reply_data = NULL;
2353 if (!(reply_data = HeapAlloc( GetProcessHeap(), 0, reply_size )))
2355 WARN( "no memory for reply, will be truncated\n" );
2359 SERVER_START_REQ( get_message_reply )
2362 if (reply_size) wine_server_set_reply( req, reply_data, reply_size );
2363 if (!(status = wine_server_call( req ))) *result = reply->result;
2364 reply_size = wine_server_reply_size( reply );
2367 if (!status && reply_size)
2368 unpack_reply( info->hwnd, info->msg, info->wparam, info->lparam, reply_data, reply_size );
2370 HeapFree( GetProcessHeap(), 0, reply_data );
2372 TRACE( "hwnd %p msg %x (%s) wp %lx lp %lx got reply %lx (err=%d)\n",
2373 info->hwnd, info->msg, SPY_GetMsgName(info->msg, info->hwnd), info->wparam,
2374 info->lparam, *result, status );
2376 /* MSDN states that last error is 0 on timeout, but at least NT4 returns ERROR_TIMEOUT */
2377 if (status) SetLastError( RtlNtStatusToDosError(status) );
2382 /***********************************************************************
2383 * send_inter_thread_message
2385 static LRESULT send_inter_thread_message( const struct send_message_info *info, LRESULT *res_ptr )
2387 size_t reply_size = 0;
2389 TRACE( "hwnd %p msg %x (%s) wp %lx lp %lx\n",
2390 info->hwnd, info->msg, SPY_GetMsgName(info->msg, info->hwnd), info->wparam, info->lparam );
2392 USER_CheckNotLock();
2394 if (!put_message_in_queue( info, &reply_size )) return 0;
2396 /* there's no reply to wait for on notify/callback messages */
2397 if (info->type == MSG_NOTIFY || info->type == MSG_CALLBACK) return 1;
2399 wait_message_reply( info->flags );
2400 return retrieve_reply( info, reply_size, res_ptr );
2404 /***********************************************************************
2405 * send_inter_thread_callback
2407 static LRESULT send_inter_thread_callback( HWND hwnd, UINT msg, WPARAM wp, LPARAM lp,
2408 LRESULT *result, void *arg )
2410 struct send_message_info *info = arg;
2415 return send_inter_thread_message( info, result );
2419 /***********************************************************************
2422 * Backend implementation of the various SendMessage functions.
2424 static BOOL send_message( struct send_message_info *info, DWORD_PTR *res_ptr, BOOL unicode )
2430 if (is_broadcast(info->hwnd))
2432 EnumWindows( broadcast_message_callback, (LPARAM)info );
2433 if (res_ptr) *res_ptr = 1;
2437 if (!(info->dest_tid = GetWindowThreadProcessId( info->hwnd, &dest_pid ))) return FALSE;
2439 if (USER_IsExitingThread( info->dest_tid )) return FALSE;
2441 SPY_EnterMessage( SPY_SENDMESSAGE, info->hwnd, info->msg, info->wparam, info->lparam );
2443 if (info->dest_tid == GetCurrentThreadId())
2445 result = call_window_proc( info->hwnd, info->msg, info->wparam, info->lparam,
2446 unicode, TRUE, info->wm_char );
2447 if (info->type == MSG_CALLBACK)
2448 call_sendmsg_callback( info->callback, info->hwnd, info->msg, info->data, result );
2453 if (dest_pid != GetCurrentProcessId() && (info->type == MSG_ASCII || info->type == MSG_UNICODE))
2454 info->type = MSG_OTHER_PROCESS;
2456 /* MSG_ASCII can be sent unconverted except for WM_CHAR; everything else needs to be Unicode */
2457 if (!unicode && is_unicode_message( info->msg ) &&
2458 (info->type != MSG_ASCII || info->msg == WM_CHAR))
2459 ret = WINPROC_CallProcAtoW( send_inter_thread_callback, info->hwnd, info->msg,
2460 info->wparam, info->lparam, &result, info, info->wm_char );
2462 ret = send_inter_thread_message( info, &result );
2465 SPY_ExitMessage( SPY_RESULT_OK, info->hwnd, info->msg, result, info->wparam, info->lparam );
2466 if (ret && res_ptr) *res_ptr = result;
2471 /***********************************************************************
2472 * MSG_SendInternalMessageTimeout
2474 * Same as SendMessageTimeoutW but sends the message to a specific thread
2475 * without requiring a window handle. Only works for internal Wine messages.
2477 LRESULT MSG_SendInternalMessageTimeout( DWORD dest_pid, DWORD dest_tid,
2478 UINT msg, WPARAM wparam, LPARAM lparam,
2479 UINT flags, UINT timeout, PDWORD_PTR res_ptr )
2481 struct send_message_info info;
2482 LRESULT ret, result;
2484 assert( msg & 0x80000000 ); /* must be an internal Wine message */
2486 info.type = MSG_UNICODE;
2487 info.dest_tid = dest_tid;
2490 info.wparam = wparam;
2491 info.lparam = lparam;
2493 info.timeout = timeout;
2495 if (USER_IsExitingThread( dest_tid )) return 0;
2497 if (dest_tid == GetCurrentThreadId())
2499 result = handle_internal_message( 0, msg, wparam, lparam );
2504 if (dest_pid != GetCurrentProcessId()) info.type = MSG_OTHER_PROCESS;
2505 ret = send_inter_thread_message( &info, &result );
2507 if (ret && res_ptr) *res_ptr = result;
2512 /***********************************************************************
2513 * SendMessageTimeoutW (USER32.@)
2515 LRESULT WINAPI SendMessageTimeoutW( HWND hwnd, UINT msg, WPARAM wparam, LPARAM lparam,
2516 UINT flags, UINT timeout, PDWORD_PTR res_ptr )
2518 struct send_message_info info;
2520 info.type = MSG_UNICODE;
2523 info.wparam = wparam;
2524 info.lparam = lparam;
2526 info.timeout = timeout;
2528 return send_message( &info, res_ptr, TRUE );
2531 /***********************************************************************
2532 * SendMessageTimeoutA (USER32.@)
2534 LRESULT WINAPI SendMessageTimeoutA( HWND hwnd, UINT msg, WPARAM wparam, LPARAM lparam,
2535 UINT flags, UINT timeout, PDWORD_PTR res_ptr )
2537 struct send_message_info info;
2539 info.type = MSG_ASCII;
2542 info.wparam = wparam;
2543 info.lparam = lparam;
2545 info.timeout = timeout;
2546 info.wm_char = WMCHAR_MAP_SENDMESSAGETIMEOUT;
2548 return send_message( &info, res_ptr, FALSE );
2552 /***********************************************************************
2553 * SendMessageW (USER32.@)
2555 LRESULT WINAPI SendMessageW( HWND hwnd, UINT msg, WPARAM wparam, LPARAM lparam )
2558 struct send_message_info info;
2560 info.type = MSG_UNICODE;
2563 info.wparam = wparam;
2564 info.lparam = lparam;
2565 info.flags = SMTO_NORMAL;
2568 send_message( &info, &res, TRUE );
2573 /***********************************************************************
2574 * SendMessageA (USER32.@)
2576 LRESULT WINAPI SendMessageA( HWND hwnd, UINT msg, WPARAM wparam, LPARAM lparam )
2579 struct send_message_info info;
2581 info.type = MSG_ASCII;
2584 info.wparam = wparam;
2585 info.lparam = lparam;
2586 info.flags = SMTO_NORMAL;
2588 info.wm_char = WMCHAR_MAP_SENDMESSAGE;
2590 send_message( &info, &res, FALSE );
2595 /***********************************************************************
2596 * SendNotifyMessageA (USER32.@)
2598 BOOL WINAPI SendNotifyMessageA( HWND hwnd, UINT msg, WPARAM wparam, LPARAM lparam )
2600 struct send_message_info info;
2602 if (is_pointer_message(msg))
2604 SetLastError( ERROR_MESSAGE_SYNC_ONLY );
2608 info.type = MSG_NOTIFY;
2611 info.wparam = wparam;
2612 info.lparam = lparam;
2614 info.wm_char = WMCHAR_MAP_SENDMESSAGETIMEOUT;
2616 return send_message( &info, NULL, FALSE );
2620 /***********************************************************************
2621 * SendNotifyMessageW (USER32.@)
2623 BOOL WINAPI SendNotifyMessageW( HWND hwnd, UINT msg, WPARAM wparam, LPARAM lparam )
2625 struct send_message_info info;
2627 if (is_pointer_message(msg))
2629 SetLastError( ERROR_MESSAGE_SYNC_ONLY );
2633 info.type = MSG_NOTIFY;
2636 info.wparam = wparam;
2637 info.lparam = lparam;
2640 return send_message( &info, NULL, TRUE );
2644 /***********************************************************************
2645 * SendMessageCallbackA (USER32.@)
2647 BOOL WINAPI SendMessageCallbackA( HWND hwnd, UINT msg, WPARAM wparam, LPARAM lparam,
2648 SENDASYNCPROC callback, ULONG_PTR data )
2650 struct send_message_info info;
2652 if (is_pointer_message(msg))
2654 SetLastError( ERROR_MESSAGE_SYNC_ONLY );
2658 info.type = MSG_CALLBACK;
2661 info.wparam = wparam;
2662 info.lparam = lparam;
2663 info.callback = callback;
2666 info.wm_char = WMCHAR_MAP_SENDMESSAGETIMEOUT;
2668 return send_message( &info, NULL, FALSE );
2672 /***********************************************************************
2673 * SendMessageCallbackW (USER32.@)
2675 BOOL WINAPI SendMessageCallbackW( HWND hwnd, UINT msg, WPARAM wparam, LPARAM lparam,
2676 SENDASYNCPROC callback, ULONG_PTR data )
2678 struct send_message_info info;
2680 if (is_pointer_message(msg))
2682 SetLastError( ERROR_MESSAGE_SYNC_ONLY );
2686 info.type = MSG_CALLBACK;
2689 info.wparam = wparam;
2690 info.lparam = lparam;
2691 info.callback = callback;
2695 return send_message( &info, NULL, TRUE );
2699 /***********************************************************************
2700 * ReplyMessage (USER32.@)
2702 BOOL WINAPI ReplyMessage( LRESULT result )
2704 struct received_message_info *info = get_user_thread_info()->receive_info;
2706 if (!info) return FALSE;
2707 reply_message( info, result, FALSE );
2712 /***********************************************************************
2713 * InSendMessage (USER32.@)
2715 BOOL WINAPI InSendMessage(void)
2717 return (InSendMessageEx(NULL) & (ISMEX_SEND|ISMEX_REPLIED)) == ISMEX_SEND;
2721 /***********************************************************************
2722 * InSendMessageEx (USER32.@)
2724 DWORD WINAPI InSendMessageEx( LPVOID reserved )
2726 struct received_message_info *info = get_user_thread_info()->receive_info;
2728 if (info) return info->flags;
2729 return ISMEX_NOSEND;
2733 /***********************************************************************
2734 * PostMessageA (USER32.@)
2736 BOOL WINAPI PostMessageA( HWND hwnd, UINT msg, WPARAM wparam, LPARAM lparam )
2738 if (!map_wparam_AtoW( msg, &wparam, WMCHAR_MAP_POSTMESSAGE )) return TRUE;
2739 return PostMessageW( hwnd, msg, wparam, lparam );
2743 /***********************************************************************
2744 * PostMessageW (USER32.@)
2746 BOOL WINAPI PostMessageW( HWND hwnd, UINT msg, WPARAM wparam, LPARAM lparam )
2748 struct send_message_info info;
2750 if (is_pointer_message( msg ))
2752 SetLastError( ERROR_MESSAGE_SYNC_ONLY );
2756 TRACE( "hwnd %p msg %x (%s) wp %lx lp %lx\n",
2757 hwnd, msg, SPY_GetMsgName(msg, hwnd), wparam, lparam );
2759 info.type = MSG_POSTED;
2762 info.wparam = wparam;
2763 info.lparam = lparam;
2766 if (is_broadcast(hwnd))
2768 EnumWindows( broadcast_message_callback, (LPARAM)&info );
2772 if (!hwnd) return PostThreadMessageW( GetCurrentThreadId(), msg, wparam, lparam );
2774 if (!(info.dest_tid = GetWindowThreadProcessId( hwnd, NULL ))) return FALSE;
2776 if (USER_IsExitingThread( info.dest_tid )) return TRUE;
2778 return put_message_in_queue( &info, NULL );
2782 /**********************************************************************
2783 * PostThreadMessageA (USER32.@)
2785 BOOL WINAPI PostThreadMessageA( DWORD thread, UINT msg, WPARAM wparam, LPARAM lparam )
2787 if (!map_wparam_AtoW( msg, &wparam, WMCHAR_MAP_POSTMESSAGE )) return TRUE;
2788 return PostThreadMessageW( thread, msg, wparam, lparam );
2792 /**********************************************************************
2793 * PostThreadMessageW (USER32.@)
2795 BOOL WINAPI PostThreadMessageW( DWORD thread, UINT msg, WPARAM wparam, LPARAM lparam )
2797 struct send_message_info info;
2799 if (is_pointer_message( msg ))
2801 SetLastError( ERROR_MESSAGE_SYNC_ONLY );
2804 if (USER_IsExitingThread( thread )) return TRUE;
2806 info.type = MSG_POSTED;
2807 info.dest_tid = thread;
2810 info.wparam = wparam;
2811 info.lparam = lparam;
2813 return put_message_in_queue( &info, NULL );
2817 /***********************************************************************
2818 * PostQuitMessage (USER32.@)
2820 * Posts a quit message to the current thread's message queue.
2823 * exit_code [I] Exit code to return from message loop.
2829 * This function is not the same as calling:
2830 *|PostThreadMessage(GetCurrentThreadId(), WM_QUIT, exit_code, 0);
2831 * It instead sets a flag in the message queue that signals it to generate
2832 * a WM_QUIT message when there are no other pending sent or posted messages
2835 void WINAPI PostQuitMessage( INT exit_code )
2837 SERVER_START_REQ( post_quit_message )
2839 req->exit_code = exit_code;
2840 wine_server_call( req );
2846 /***********************************************************************
2847 * PeekMessageW (USER32.@)
2849 BOOL WINAPI PeekMessageW( MSG *msg_out, HWND hwnd, UINT first, UINT last, UINT flags )
2851 struct user_thread_info *thread_info = get_user_thread_info();
2854 USER_CheckNotLock();
2856 /* check for graphics events */
2857 USER_Driver->pMsgWaitForMultipleObjectsEx( 0, NULL, 0, QS_ALLINPUT, 0 );
2859 hwnd = WIN_GetFullHandle( hwnd );
2863 if (!peek_message( &msg, hwnd, first, last, flags ))
2865 if (!(flags & PM_NOYIELD))
2868 ReleaseThunkLock(&count);
2870 if (count) RestoreThunkLock(count);
2874 if (msg.message & 0x80000000)
2876 if (!(flags & PM_REMOVE))
2878 /* Have to remove the message explicitly.
2879 Do this before handling it, because the message handler may
2880 call PeekMessage again */
2881 peek_message( &msg, msg.hwnd, msg.message, msg.message, flags | PM_REMOVE );
2883 handle_internal_message( msg.hwnd, msg.message, msg.wParam, msg.lParam );
2888 thread_info->GetMessageTimeVal = msg.time;
2889 msg.pt.x = (short)LOWORD( thread_info->GetMessagePosVal );
2890 msg.pt.y = (short)HIWORD( thread_info->GetMessagePosVal );
2892 HOOK_CallHooks( WH_GETMESSAGE, HC_ACTION, flags & PM_REMOVE, (LPARAM)&msg, TRUE );
2894 /* copy back our internal safe copy of message data to msg_out.
2895 * msg_out is a variable from the *program*, so it can't be used
2896 * internally as it can get "corrupted" by our use of SendMessage()
2897 * (back to the program) inside the message handling itself. */
2900 SetLastError( ERROR_NOACCESS );
2908 /***********************************************************************
2909 * PeekMessageA (USER32.@)
2911 BOOL WINAPI PeekMessageA( MSG *msg, HWND hwnd, UINT first, UINT last, UINT flags )
2913 if (get_pending_wmchar( msg, first, last, (flags & PM_REMOVE) )) return TRUE;
2914 if (!PeekMessageW( msg, hwnd, first, last, flags )) return FALSE;
2915 map_wparam_WtoA( msg, (flags & PM_REMOVE) );
2920 /***********************************************************************
2921 * GetMessageW (USER32.@)
2923 BOOL WINAPI GetMessageW( MSG *msg, HWND hwnd, UINT first, UINT last )
2925 HANDLE server_queue = get_server_queue_handle();
2926 int mask = QS_POSTMESSAGE | QS_SENDMESSAGE; /* Always selected */
2930 if ((first <= WM_KEYLAST) && (last >= WM_KEYFIRST)) mask |= QS_KEY;
2931 if ( ((first <= WM_MOUSELAST) && (last >= WM_MOUSEFIRST)) ||
2932 ((first <= WM_NCMOUSELAST) && (last >= WM_NCMOUSEFIRST)) ) mask |= QS_MOUSE;
2933 if ((first <= WM_TIMER) && (last >= WM_TIMER)) mask |= QS_TIMER;
2934 if ((first <= WM_SYSTIMER) && (last >= WM_SYSTIMER)) mask |= QS_TIMER;
2935 if ((first <= WM_PAINT) && (last >= WM_PAINT)) mask |= QS_PAINT;
2937 else mask = QS_ALLINPUT;
2939 while (!PeekMessageW( msg, hwnd, first, last, PM_REMOVE | PM_NOYIELD | (mask << 16) ))
2943 ReleaseThunkLock( &dwlc );
2944 USER_Driver->pMsgWaitForMultipleObjectsEx( 1, &server_queue, INFINITE, mask, 0 );
2945 if (dwlc) RestoreThunkLock( dwlc );
2948 return (msg->message != WM_QUIT);
2952 /***********************************************************************
2953 * GetMessageA (USER32.@)
2955 BOOL WINAPI GetMessageA( MSG *msg, HWND hwnd, UINT first, UINT last )
2957 if (get_pending_wmchar( msg, first, last, TRUE )) return TRUE;
2958 GetMessageW( msg, hwnd, first, last );
2959 map_wparam_WtoA( msg, TRUE );
2960 return (msg->message != WM_QUIT);
2964 /***********************************************************************
2965 * IsDialogMessageA (USER32.@)
2966 * IsDialogMessage (USER32.@)
2968 BOOL WINAPI IsDialogMessageA( HWND hwndDlg, LPMSG pmsg )
2971 map_wparam_AtoW( msg.message, &msg.wParam, WMCHAR_MAP_NOMAPPING );
2972 return IsDialogMessageW( hwndDlg, &msg );
2976 /***********************************************************************
2977 * TranslateMessage (USER32.@)
2979 * Implementation of TranslateMessage.
2981 * TranslateMessage translates virtual-key messages into character-messages,
2983 * WM_KEYDOWN/WM_KEYUP combinations produce a WM_CHAR or WM_DEADCHAR message.
2984 * ditto replacing WM_* with WM_SYS*
2985 * This produces WM_CHAR messages only for keys mapped to ASCII characters
2986 * by the keyboard driver.
2988 * If the message is WM_KEYDOWN, WM_KEYUP, WM_SYSKEYDOWN, or WM_SYSKEYUP, the
2989 * return value is nonzero, regardless of the translation.
2992 BOOL WINAPI TranslateMessage( const MSG *msg )
2998 if (msg->message < WM_KEYFIRST || msg->message > WM_KEYLAST) return FALSE;
2999 if (msg->message != WM_KEYDOWN && msg->message != WM_SYSKEYDOWN) return TRUE;
3001 TRACE_(key)("Translating key %s (%04lx), scancode %02x\n",
3002 SPY_GetVKeyName(msg->wParam), msg->wParam, LOBYTE(HIWORD(msg->lParam)));
3004 if ( msg->wParam == VK_PROCESSKEY )
3005 return ImmTranslateMessage(msg->hwnd, msg->message, msg->wParam, msg->lParam);
3007 GetKeyboardState( state );
3008 /* FIXME : should handle ToUnicode yielding 2 */
3009 switch (ToUnicode(msg->wParam, HIWORD(msg->lParam), state, wp, 2, 0))
3012 message = (msg->message == WM_KEYDOWN) ? WM_CHAR : WM_SYSCHAR;
3013 TRACE_(key)("1 -> PostMessageW(%p,%s,%04x,%08lx)\n",
3014 msg->hwnd, SPY_GetMsgName(message, msg->hwnd), wp[0], msg->lParam);
3015 PostMessageW( msg->hwnd, message, wp[0], msg->lParam );
3019 message = (msg->message == WM_KEYDOWN) ? WM_DEADCHAR : WM_SYSDEADCHAR;
3020 TRACE_(key)("-1 -> PostMessageW(%p,%s,%04x,%08lx)\n",
3021 msg->hwnd, SPY_GetMsgName(message, msg->hwnd), wp[0], msg->lParam);
3022 PostMessageW( msg->hwnd, message, wp[0], msg->lParam );
3029 /***********************************************************************
3030 * DispatchMessageA (USER32.@)
3032 * See DispatchMessageW.
3034 LRESULT WINAPI DispatchMessageA( const MSG* msg )
3038 /* Process timer messages */
3039 if ((msg->message == WM_TIMER) || (msg->message == WM_SYSTIMER))
3041 if (msg->lParam) return CallWindowProcA( (WNDPROC)msg->lParam, msg->hwnd,
3042 msg->message, msg->wParam, GetTickCount() );
3044 if (!msg->hwnd) return 0;
3046 SPY_EnterMessage( SPY_DISPATCHMESSAGE, msg->hwnd, msg->message,
3047 msg->wParam, msg->lParam );
3049 if (!WINPROC_call_window( msg->hwnd, msg->message, msg->wParam, msg->lParam,
3050 &retval, FALSE, WMCHAR_MAP_DISPATCHMESSAGE ))
3052 if (!IsWindow( msg->hwnd )) SetLastError( ERROR_INVALID_WINDOW_HANDLE );
3053 else SetLastError( ERROR_MESSAGE_SYNC_ONLY );
3057 SPY_ExitMessage( SPY_RESULT_OK, msg->hwnd, msg->message, retval,
3058 msg->wParam, msg->lParam );
3060 if (msg->message == WM_PAINT)
3062 /* send a WM_NCPAINT and WM_ERASEBKGND if the non-client area is still invalid */
3063 HRGN hrgn = CreateRectRgn( 0, 0, 0, 0 );
3064 GetUpdateRgn( msg->hwnd, hrgn, TRUE );
3065 DeleteObject( hrgn );
3071 /***********************************************************************
3072 * DispatchMessageW (USER32.@) Process a message
3074 * Process the message specified in the structure *_msg_.
3076 * If the lpMsg parameter points to a WM_TIMER message and the
3077 * parameter of the WM_TIMER message is not NULL, the lParam parameter
3078 * points to the function that is called instead of the window
3081 * The message must be valid.
3085 * DispatchMessage() returns the result of the window procedure invoked.
3092 LRESULT WINAPI DispatchMessageW( const MSG* msg )
3096 /* Process timer messages */
3097 if ((msg->message == WM_TIMER) || (msg->message == WM_SYSTIMER))
3099 if (msg->lParam) return CallWindowProcW( (WNDPROC)msg->lParam, msg->hwnd,
3100 msg->message, msg->wParam, GetTickCount() );
3102 if (!msg->hwnd) return 0;
3104 SPY_EnterMessage( SPY_DISPATCHMESSAGE, msg->hwnd, msg->message,
3105 msg->wParam, msg->lParam );
3107 if (!WINPROC_call_window( msg->hwnd, msg->message, msg->wParam, msg->lParam,
3108 &retval, TRUE, WMCHAR_MAP_DISPATCHMESSAGE ))
3110 if (!IsWindow( msg->hwnd )) SetLastError( ERROR_INVALID_WINDOW_HANDLE );
3111 else SetLastError( ERROR_MESSAGE_SYNC_ONLY );
3115 SPY_ExitMessage( SPY_RESULT_OK, msg->hwnd, msg->message, retval,
3116 msg->wParam, msg->lParam );
3118 if (msg->message == WM_PAINT)
3120 /* send a WM_NCPAINT and WM_ERASEBKGND if the non-client area is still invalid */
3121 HRGN hrgn = CreateRectRgn( 0, 0, 0, 0 );
3122 GetUpdateRgn( msg->hwnd, hrgn, TRUE );
3123 DeleteObject( hrgn );
3129 /***********************************************************************
3130 * GetMessagePos (USER.119)
3131 * GetMessagePos (USER32.@)
3133 * The GetMessagePos() function returns a long value representing a
3134 * cursor position, in screen coordinates, when the last message
3135 * retrieved by the GetMessage() function occurs. The x-coordinate is
3136 * in the low-order word of the return value, the y-coordinate is in
3137 * the high-order word. The application can use the MAKEPOINT()
3138 * macro to obtain a POINT structure from the return value.
3140 * For the current cursor position, use GetCursorPos().
3144 * Cursor position of last message on success, zero on failure.
3151 DWORD WINAPI GetMessagePos(void)
3153 return get_user_thread_info()->GetMessagePosVal;
3157 /***********************************************************************
3158 * GetMessageTime (USER.120)
3159 * GetMessageTime (USER32.@)
3161 * GetMessageTime() returns the message time for the last message
3162 * retrieved by the function. The time is measured in milliseconds with
3163 * the same offset as GetTickCount().
3165 * Since the tick count wraps, this is only useful for moderately short
3166 * relative time comparisons.
3170 * Time of last message on success, zero on failure.
3172 LONG WINAPI GetMessageTime(void)
3174 return get_user_thread_info()->GetMessageTimeVal;
3178 /***********************************************************************
3179 * GetMessageExtraInfo (USER.288)
3180 * GetMessageExtraInfo (USER32.@)
3182 LPARAM WINAPI GetMessageExtraInfo(void)
3184 return get_user_thread_info()->GetMessageExtraInfoVal;
3188 /***********************************************************************
3189 * SetMessageExtraInfo (USER32.@)
3191 LPARAM WINAPI SetMessageExtraInfo(LPARAM lParam)
3193 struct user_thread_info *thread_info = get_user_thread_info();
3194 LONG old_value = thread_info->GetMessageExtraInfoVal;
3195 thread_info->GetMessageExtraInfoVal = lParam;
3200 /***********************************************************************
3201 * WaitMessage (USER.112) Suspend thread pending messages
3202 * WaitMessage (USER32.@) Suspend thread pending messages
3204 * WaitMessage() suspends a thread until events appear in the thread's
3207 BOOL WINAPI WaitMessage(void)
3209 return (MsgWaitForMultipleObjectsEx( 0, NULL, INFINITE, QS_ALLINPUT, 0 ) != WAIT_FAILED);
3213 /***********************************************************************
3214 * MsgWaitForMultipleObjectsEx (USER32.@)
3216 DWORD WINAPI MsgWaitForMultipleObjectsEx( DWORD count, CONST HANDLE *pHandles,
3217 DWORD timeout, DWORD mask, DWORD flags )
3219 HANDLE handles[MAXIMUM_WAIT_OBJECTS];
3222 if (count > MAXIMUM_WAIT_OBJECTS-1)
3224 SetLastError( ERROR_INVALID_PARAMETER );
3228 /* set the queue mask */
3229 SERVER_START_REQ( set_queue_mask )
3231 req->wake_mask = (flags & MWMO_INPUTAVAILABLE) ? mask : 0;
3232 req->changed_mask = mask;
3234 wine_server_call( req );
3238 /* add the queue to the handle list */
3239 for (i = 0; i < count; i++) handles[i] = pHandles[i];
3240 handles[count] = get_server_queue_handle();
3242 ReleaseThunkLock( &lock );
3243 ret = USER_Driver->pMsgWaitForMultipleObjectsEx( count+1, handles, timeout, mask, flags );
3244 if (lock) RestoreThunkLock( lock );
3249 /***********************************************************************
3250 * MsgWaitForMultipleObjects (USER32.@)
3252 DWORD WINAPI MsgWaitForMultipleObjects( DWORD count, CONST HANDLE *handles,
3253 BOOL wait_all, DWORD timeout, DWORD mask )
3255 return MsgWaitForMultipleObjectsEx( count, handles, timeout, mask,
3256 wait_all ? MWMO_WAITALL : 0 );
3260 /***********************************************************************
3261 * WaitForInputIdle (USER32.@)
3263 DWORD WINAPI WaitForInputIdle( HANDLE hProcess, DWORD dwTimeOut )
3265 DWORD start_time, elapsed, ret;
3268 handles[0] = hProcess;
3269 SERVER_START_REQ( get_process_idle_event )
3271 req->handle = hProcess;
3272 if (!(ret = wine_server_call_err( req ))) handles[1] = reply->event;
3275 if (ret) return WAIT_FAILED; /* error */
3276 if (!handles[1]) return 0; /* no event to wait on */
3278 start_time = GetTickCount();
3281 TRACE("waiting for %p\n", handles[1] );
3284 ret = MsgWaitForMultipleObjects ( 2, handles, FALSE, dwTimeOut - elapsed, QS_SENDMESSAGE );
3289 case WAIT_OBJECT_0+2:
3290 process_sent_messages();
3294 TRACE("timeout or error\n");
3297 TRACE("finished\n");
3300 if (dwTimeOut != INFINITE)
3302 elapsed = GetTickCount() - start_time;
3303 if (elapsed > dwTimeOut)
3309 return WAIT_TIMEOUT;
3313 /***********************************************************************
3314 * UserYield (USER.332)
3316 void WINAPI UserYield16(void)
3320 /* Handle sent messages */
3321 process_sent_messages();
3324 ReleaseThunkLock(&count);
3328 RestoreThunkLock(count);
3329 /* Handle sent messages again */
3330 process_sent_messages();
3335 /***********************************************************************
3336 * RegisterWindowMessageA (USER32.@)
3337 * RegisterWindowMessage (USER.118)
3339 UINT WINAPI RegisterWindowMessageA( LPCSTR str )
3341 UINT ret = GlobalAddAtomA(str);
3342 TRACE("%s, ret=%x\n", str, ret);
3347 /***********************************************************************
3348 * RegisterWindowMessageW (USER32.@)
3350 UINT WINAPI RegisterWindowMessageW( LPCWSTR str )
3352 UINT ret = GlobalAddAtomW(str);
3353 TRACE("%s ret=%x\n", debugstr_w(str), ret);
3357 typedef struct BroadcastParm
3368 static BOOL CALLBACK bcast_childwindow( HWND hw, LPARAM lp )
3370 BroadcastParm *parm = (BroadcastParm*)lp;
3371 DWORD_PTR retval = 0;
3374 if (parm->flags & BSF_IGNORECURRENTTASK && WIN_IsCurrentProcess(hw))
3376 TRACE("Not telling myself %p\n", hw);
3380 /* I don't know 100% for sure if this is what Windows does, but it fits the tests */
3381 if (parm->flags & BSF_QUERY)
3383 TRACE("Telling window %p using SendMessageTimeout\n", hw);
3385 /* Not tested for conflicting flags */
3386 if (parm->flags & BSF_FORCEIFHUNG || parm->flags & BSF_NOHANG)
3387 lresult = SendMessageTimeoutW( hw, parm->msg, parm->wp, parm->lp, SMTO_ABORTIFHUNG, 2000, &retval );
3388 else if (parm->flags & BSF_NOTIMEOUTIFNOTHUNG)
3389 lresult = SendMessageTimeoutW( hw, parm->msg, parm->wp, parm->lp, SMTO_NOTIMEOUTIFNOTHUNG, 2000, &retval );
3391 lresult = SendMessageTimeoutW( hw, parm->msg, parm->wp, parm->lp, SMTO_NORMAL, 2000, &retval );
3393 if (!lresult && GetLastError() == ERROR_TIMEOUT)
3395 WARN("Timed out!\n");
3396 if (!(parm->flags & BSF_FORCEIFHUNG))
3399 if (retval == BROADCAST_QUERY_DENY)
3408 else if (parm->flags & BSF_POSTMESSAGE)
3410 TRACE("Telling window %p using PostMessage\n", hw);
3411 PostMessageW( hw, parm->msg, parm->wp, parm->lp );
3415 TRACE("Telling window %p using SendNotifyMessage\n", hw);
3416 SendNotifyMessageW( hw, parm->msg, parm->wp, parm->lp );
3422 static BOOL CALLBACK bcast_desktop( LPWSTR desktop, LPARAM lp )
3426 BroadcastParm *parm = (BroadcastParm*)lp;
3428 TRACE("desktop: %s\n", debugstr_w( desktop ));
3430 hdesktop = open_winstation_desktop( parm->winsta, desktop, 0, FALSE, DESKTOP_ENUMERATE|DESKTOP_WRITEOBJECTS|STANDARD_RIGHTS_WRITE );
3433 FIXME("Could not open desktop %s\n", debugstr_w(desktop));
3437 ret = EnumDesktopWindows( hdesktop, bcast_childwindow, lp );
3438 CloseDesktop(hdesktop);
3439 TRACE("-->%d\n", ret);
3440 return parm->success;
3443 static BOOL CALLBACK bcast_winsta( LPWSTR winsta, LPARAM lp )
3446 HWINSTA hwinsta = OpenWindowStationW( winsta, FALSE, WINSTA_ENUMDESKTOPS );
3447 TRACE("hwinsta: %p/%s/%08x\n", hwinsta, debugstr_w( winsta ), GetLastError());
3450 ((BroadcastParm *)lp)->winsta = hwinsta;
3451 ret = EnumDesktopsW( hwinsta, bcast_desktop, lp );
3452 CloseWindowStation( hwinsta );
3453 TRACE("-->%d\n", ret);
3457 /***********************************************************************
3458 * BroadcastSystemMessageA (USER32.@)
3459 * BroadcastSystemMessage (USER32.@)
3461 LONG WINAPI BroadcastSystemMessageA( DWORD flags, LPDWORD recipients, UINT msg, WPARAM wp, LPARAM lp )
3463 return BroadcastSystemMessageExA( flags, recipients, msg, wp, lp, NULL );
3467 /***********************************************************************
3468 * BroadcastSystemMessageW (USER32.@)
3470 LONG WINAPI BroadcastSystemMessageW( DWORD flags, LPDWORD recipients, UINT msg, WPARAM wp, LPARAM lp )
3472 return BroadcastSystemMessageExW( flags, recipients, msg, wp, lp, NULL );
3475 /***********************************************************************
3476 * BroadcastSystemMessageExA (USER32.@)
3478 LONG WINAPI BroadcastSystemMessageExA( DWORD flags, LPDWORD recipients, UINT msg, WPARAM wp, LPARAM lp, PBSMINFO pinfo )
3480 map_wparam_AtoW( msg, &wp, WMCHAR_MAP_NOMAPPING );
3481 return BroadcastSystemMessageExW( flags, recipients, msg, wp, lp, NULL );
3485 /***********************************************************************
3486 * BroadcastSystemMessageExW (USER32.@)
3488 LONG WINAPI BroadcastSystemMessageExW( DWORD flags, LPDWORD recipients, UINT msg, WPARAM wp, LPARAM lp, PBSMINFO pinfo )
3491 DWORD recips = BSM_ALLCOMPONENTS;
3493 static const DWORD all_flags = ( BSF_QUERY | BSF_IGNORECURRENTTASK | BSF_FLUSHDISK | BSF_NOHANG
3494 | BSF_POSTMESSAGE | BSF_FORCEIFHUNG | BSF_NOTIMEOUTIFNOTHUNG
3495 | BSF_ALLOWSFW | BSF_SENDNOTIFYMESSAGE | BSF_RETURNHDESK | BSF_LUID );
3497 TRACE("Flags: %08x, recipients: %p(0x%x), msg: %04x, wparam: %08lx, lparam: %08lx\n", flags, recipients,
3498 (recipients ? *recipients : recips), msg, wp, lp);
3500 if (flags & ~all_flags)
3502 SetLastError(ERROR_INVALID_PARAMETER);
3507 recipients = &recips;
3509 if ( pinfo && flags & BSF_QUERY )
3510 FIXME("Not returning PBSMINFO information yet\n");
3513 parm.recipients = recipients;
3517 parm.success = TRUE;
3519 if (*recipients & BSM_ALLDESKTOPS || *recipients == BSM_ALLCOMPONENTS)
3520 ret = EnumWindowStationsW(bcast_winsta, (LONG_PTR)&parm);
3521 else if (*recipients & BSM_APPLICATIONS)
3523 EnumWindows(bcast_childwindow, (LONG_PTR)&parm);
3527 FIXME("Recipients %08x not supported!\n", *recipients);
3532 /***********************************************************************
3533 * SetMessageQueue (USER32.@)
3535 BOOL WINAPI SetMessageQueue( INT size )
3537 /* now obsolete the message queue will be expanded dynamically as necessary */
3542 /***********************************************************************
3543 * MessageBeep (USER32.@)
3545 BOOL WINAPI MessageBeep( UINT i )
3548 SystemParametersInfoA( SPI_GETBEEP, 0, &active, FALSE );
3549 if (active) USER_Driver->pBeep();
3554 /***********************************************************************
3555 * SetTimer (USER32.@)
3557 UINT_PTR WINAPI SetTimer( HWND hwnd, UINT_PTR id, UINT timeout, TIMERPROC proc )
3560 WNDPROC winproc = 0;
3562 if (proc) winproc = WINPROC_AllocProc( (WNDPROC)proc, NULL );
3564 SERVER_START_REQ( set_win_timer )
3567 req->msg = WM_TIMER;
3569 req->rate = max( timeout, SYS_TIMER_RATE );
3570 req->lparam = (unsigned long)winproc;
3571 if (!wine_server_call_err( req ))
3574 if (!ret) ret = TRUE;
3580 TRACE("Added %p %lx %p timeout %d\n", hwnd, id, winproc, timeout );
3585 /***********************************************************************
3586 * SetSystemTimer (USER32.@)
3588 UINT_PTR WINAPI SetSystemTimer( HWND hwnd, UINT_PTR id, UINT timeout, TIMERPROC proc )
3591 WNDPROC winproc = 0;
3593 if (proc) winproc = WINPROC_AllocProc( (WNDPROC)proc, NULL );
3595 SERVER_START_REQ( set_win_timer )
3598 req->msg = WM_SYSTIMER;
3600 req->rate = max( timeout, SYS_TIMER_RATE );
3601 req->lparam = (unsigned long)winproc;
3602 if (!wine_server_call_err( req ))
3605 if (!ret) ret = TRUE;
3611 TRACE("Added %p %lx %p timeout %d\n", hwnd, id, winproc, timeout );
3616 /***********************************************************************
3617 * KillTimer (USER32.@)
3619 BOOL WINAPI KillTimer( HWND hwnd, UINT_PTR id )
3623 SERVER_START_REQ( kill_win_timer )
3626 req->msg = WM_TIMER;
3628 ret = !wine_server_call_err( req );
3635 /***********************************************************************
3636 * KillSystemTimer (USER32.@)
3638 BOOL WINAPI KillSystemTimer( HWND hwnd, UINT_PTR id )
3642 SERVER_START_REQ( kill_win_timer )
3645 req->msg = WM_SYSTIMER;
3647 ret = !wine_server_call_err( req );
3654 /**********************************************************************
3655 * GetGUIThreadInfo (USER32.@)
3657 BOOL WINAPI GetGUIThreadInfo( DWORD id, GUITHREADINFO *info )
3661 SERVER_START_REQ( get_thread_input )
3664 if ((ret = !wine_server_call_err( req )))
3667 info->hwndActive = reply->active;
3668 info->hwndFocus = reply->focus;
3669 info->hwndCapture = reply->capture;
3670 info->hwndMenuOwner = reply->menu_owner;
3671 info->hwndMoveSize = reply->move_size;
3672 info->hwndCaret = reply->caret;
3673 info->rcCaret.left = reply->rect.left;
3674 info->rcCaret.top = reply->rect.top;
3675 info->rcCaret.right = reply->rect.right;
3676 info->rcCaret.bottom = reply->rect.bottom;
3677 if (reply->menu_owner) info->flags |= GUI_INMENUMODE;
3678 if (reply->move_size) info->flags |= GUI_INMOVESIZE;
3679 if (reply->caret) info->flags |= GUI_CARETBLINKING;
3687 /******************************************************************
3688 * IsHungAppWindow (USER32.@)
3691 BOOL WINAPI IsHungAppWindow( HWND hWnd )
3695 SERVER_START_REQ( is_window_hung )
3698 ret = !wine_server_call_err( req ) && reply->is_hung;