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., 59 Temple Place, Suite 330, Boston, MA 02111-1307 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"
44 #include "wine/debug.h"
46 WINE_DEFAULT_DEBUG_CHANNEL(msg);
47 WINE_DECLARE_DEBUG_CHANNEL(relay);
48 WINE_DECLARE_DEBUG_CHANNEL(key);
50 #define WM_NCMOUSEFIRST WM_NCMOUSEMOVE
51 #define WM_NCMOUSELAST (WM_NCMOUSEFIRST+(WM_MOUSELAST-WM_MOUSEFIRST))
53 #define MAX_PACK_COUNT 4
54 #define MAX_SENDMSG_RECURSION 64
56 #define SYS_TIMER_RATE 55 /* min. timer rate in ms (actually 54.925)*/
58 /* description of the data fields that need to be packed along with a sent message */
62 const void *data[MAX_PACK_COUNT];
63 size_t size[MAX_PACK_COUNT];
66 /* info about the message currently being received by the current thread */
67 struct received_message_info
69 enum message_type type;
71 UINT flags; /* InSendMessageEx return flags */
72 HWINEVENTHOOK hook; /* winevent hook handle */
73 WINEVENTPROC hook_proc; /* winevent hook proc address */
76 /* structure to group all parameters for sent messages of the various kinds */
77 struct send_message_info
79 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 */
91 /* flag for messages that contain pointers */
92 /* 32 messages per entry, messages 0..31 map to bits 0..31 */
94 #define SET(msg) (1 << ((msg) & 31))
96 static const unsigned int message_pointer_flags[] =
99 SET(WM_CREATE) | SET(WM_SETTEXT) | SET(WM_GETTEXT) |
100 SET(WM_WININICHANGE) | SET(WM_DEVMODECHANGE),
102 SET(WM_GETMINMAXINFO) | SET(WM_DRAWITEM) | SET(WM_MEASUREITEM) | SET(WM_DELETEITEM) |
105 SET(WM_WINDOWPOSCHANGING) | SET(WM_WINDOWPOSCHANGED) | SET(WM_COPYDATA) |
106 SET(WM_NOTIFY) | SET(WM_HELP),
108 SET(WM_STYLECHANGING) | SET(WM_STYLECHANGED),
110 SET(WM_NCCREATE) | SET(WM_NCCALCSIZE) | SET(WM_GETDLGCODE),
112 SET(EM_GETSEL) | SET(EM_GETRECT) | SET(EM_SETRECT) | SET(EM_SETRECTNP),
114 SET(EM_REPLACESEL) | SET(EM_GETLINE) | SET(EM_SETTABSTOPS),
116 SET(SBM_GETRANGE) | SET(SBM_SETSCROLLINFO) | SET(SBM_GETSCROLLINFO) | SET(SBM_GETSCROLLBARINFO),
122 SET(CB_GETEDITSEL) | SET(CB_ADDSTRING) | SET(CB_DIR) | SET(CB_GETLBTEXT) |
123 SET(CB_INSERTSTRING) | SET(CB_FINDSTRING) | SET(CB_SELECTSTRING) |
124 SET(CB_GETDROPPEDCONTROLRECT) | SET(CB_FINDSTRINGEXACT),
128 SET(LB_ADDSTRING) | SET(LB_INSERTSTRING) | SET(LB_GETTEXT) | SET(LB_SELECTSTRING) |
129 SET(LB_DIR) | SET(LB_FINDSTRING) |
130 SET(LB_GETSELITEMS) | SET(LB_SETTABSTOPS) | SET(LB_ADDFILE) | SET(LB_GETITEMRECT),
132 SET(LB_FINDSTRINGEXACT),
138 SET(WM_NEXTMENU) | SET(WM_SIZING) | SET(WM_MOVING) | SET(WM_DEVICECHANGE),
140 SET(WM_MDICREATE) | SET(WM_MDIGETACTIVE) | SET(WM_DROPOBJECT) |
141 SET(WM_QUERYDROPOBJECT) | SET(WM_DRAGLOOP) | SET(WM_DRAGSELECT) | SET(WM_DRAGMOVE),
155 SET(WM_ASKCBFORMATNAME)
158 /* flags for messages that contain Unicode strings */
159 static const unsigned int message_unicode_flags[] =
162 SET(WM_CREATE) | SET(WM_SETTEXT) | SET(WM_GETTEXT) | SET(WM_GETTEXTLENGTH) |
163 SET(WM_WININICHANGE) | SET(WM_DEVMODECHANGE),
175 SET(EM_REPLACESEL) | SET(EM_GETLINE) | SET(EM_SETPASSWORDCHAR),
179 SET(WM_CHAR) | SET(WM_DEADCHAR) | SET(WM_SYSCHAR) | SET(WM_SYSDEADCHAR),
183 SET(CB_ADDSTRING) | SET(CB_DIR) | SET(CB_GETLBTEXT) | SET(CB_GETLBTEXTLEN) |
184 SET(CB_INSERTSTRING) | SET(CB_FINDSTRING) | SET(CB_SELECTSTRING) | SET(CB_FINDSTRINGEXACT),
188 SET(LB_ADDSTRING) | SET(LB_INSERTSTRING) | SET(LB_GETTEXT) | SET(LB_GETTEXTLEN) |
189 SET(LB_SELECTSTRING) | SET(LB_DIR) | SET(LB_FINDSTRING) | SET(LB_ADDFILE),
191 SET(LB_FINDSTRINGEXACT),
213 SET(WM_PAINTCLIPBOARD) | SET(WM_SIZECLIPBOARD) | SET(WM_ASKCBFORMATNAME)
216 /* check whether a given message type includes pointers */
217 inline static int is_pointer_message( UINT message )
219 if (message >= 8*sizeof(message_pointer_flags)) return FALSE;
220 return (message_pointer_flags[message / 32] & SET(message)) != 0;
223 /* check whether a given message type contains Unicode (or ASCII) chars */
224 inline static int is_unicode_message( UINT message )
226 if (message >= 8*sizeof(message_unicode_flags)) return FALSE;
227 return (message_unicode_flags[message / 32] & SET(message)) != 0;
232 /* add a data field to a packed message */
233 inline static void push_data( struct packed_message *data, const void *ptr, size_t size )
235 data->data[data->count] = ptr;
236 data->size[data->count] = size;
240 /* add a string to a packed message */
241 inline static void push_string( struct packed_message *data, LPCWSTR str )
243 push_data( data, str, (strlenW(str) + 1) * sizeof(WCHAR) );
246 /* retrieve a pointer to data from a packed message and increment the buffer pointer */
247 inline static void *get_data( void **buffer, size_t size )
250 *buffer = (char *)*buffer + size;
254 /* make sure that the buffer contains a valid null-terminated Unicode string */
255 inline static BOOL check_string( LPCWSTR str, size_t size )
257 for (size /= sizeof(WCHAR); size; size--, str++)
258 if (!*str) return TRUE;
262 /* make sure that there is space for 'size' bytes in buffer, growing it if needed */
263 inline static void *get_buffer_space( void **buffer, size_t size )
269 if (!(ret = HeapReAlloc( GetProcessHeap(), 0, *buffer, size )))
270 HeapFree( GetProcessHeap(), 0, *buffer );
272 else ret = HeapAlloc( GetProcessHeap(), 0, size );
278 /* retrieve a string pointer from packed data */
279 inline static LPWSTR get_string( void **buffer )
281 return get_data( buffer, (strlenW( (LPWSTR)*buffer ) + 1) * sizeof(WCHAR) );
284 /* check whether a combobox expects strings or ids in CB_ADDSTRING/CB_INSERTSTRING */
285 inline static BOOL combobox_has_strings( HWND hwnd )
287 DWORD style = GetWindowLongA( hwnd, GWL_STYLE );
288 return (!(style & (CBS_OWNERDRAWFIXED | CBS_OWNERDRAWVARIABLE)) || (style & CBS_HASSTRINGS));
291 /* check whether a listbox expects strings or ids in LB_ADDSTRING/LB_INSERTSTRING */
292 inline static BOOL listbox_has_strings( HWND hwnd )
294 DWORD style = GetWindowLongA( hwnd, GWL_STYLE );
295 return (!(style & (LBS_OWNERDRAWFIXED | LBS_OWNERDRAWVARIABLE)) || (style & LBS_HASSTRINGS));
298 /* check whether message is in the range of keyboard messages */
299 inline static BOOL is_keyboard_message( UINT message )
301 return (message >= WM_KEYFIRST && message <= WM_KEYLAST);
304 /* check whether message is in the range of mouse messages */
305 inline static BOOL is_mouse_message( UINT message )
307 return ((message >= WM_NCMOUSEFIRST && message <= WM_NCMOUSELAST) ||
308 (message >= WM_MOUSEFIRST && message <= WM_MOUSELAST));
311 /* check whether message matches the specified hwnd filter */
312 inline static BOOL check_hwnd_filter( const MSG *msg, HWND hwnd_filter )
314 if (!hwnd_filter) return TRUE;
315 return (msg->hwnd == hwnd_filter || IsChild( hwnd_filter, msg->hwnd ));
319 /***********************************************************************
320 * broadcast_message_callback
322 * Helper callback for broadcasting messages.
324 static BOOL CALLBACK broadcast_message_callback( HWND hwnd, LPARAM lparam )
326 struct send_message_info *info = (struct send_message_info *)lparam;
327 if (!(GetWindowLongW( hwnd, GWL_STYLE ) & (WS_POPUP|WS_CAPTION))) return TRUE;
331 SendMessageTimeoutW( hwnd, info->msg, info->wparam, info->lparam,
332 info->flags, info->timeout, NULL );
335 SendMessageTimeoutA( hwnd, info->msg, info->wparam, info->lparam,
336 info->flags, info->timeout, NULL );
339 SendNotifyMessageW( hwnd, info->msg, info->wparam, info->lparam );
342 SendMessageCallbackW( hwnd, info->msg, info->wparam, info->lparam,
343 info->callback, info->data );
346 PostMessageW( hwnd, info->msg, info->wparam, info->lparam );
349 ERR( "bad type %d\n", info->type );
356 /***********************************************************************
359 * Convert the wparam of an ASCII message to Unicode.
361 static WPARAM map_wparam_AtoW( UINT message, WPARAM wparam )
366 case EM_SETPASSWORDCHAR:
375 ch[0] = (wparam & 0xff);
376 ch[1] = (wparam >> 8);
377 MultiByteToWideChar(CP_ACP, 0, ch, 2, wch, 2);
378 wparam = MAKEWPARAM(wch[0], wch[1]);
385 ch[0] = (wparam >> 8);
386 ch[1] = (wparam & 0xff);
387 if (ch[0]) MultiByteToWideChar(CP_ACP, 0, ch, 2, &wch, 1);
388 else MultiByteToWideChar(CP_ACP, 0, &ch[1], 1, &wch, 1);
389 wparam = MAKEWPARAM( wch, HIWORD(wparam) );
397 /***********************************************************************
400 * Convert the wparam of a Unicode message to ASCII.
402 static WPARAM map_wparam_WtoA( UINT message, WPARAM wparam )
407 case EM_SETPASSWORDCHAR:
416 wch[0] = LOWORD(wparam);
417 wch[1] = HIWORD(wparam);
418 WideCharToMultiByte( CP_ACP, 0, wch, 2, (LPSTR)ch, 2, NULL, NULL );
419 wparam = MAKEWPARAM( ch[0] | (ch[1] << 8), 0 );
424 WCHAR wch = LOWORD(wparam);
427 if (WideCharToMultiByte( CP_ACP, 0, &wch, 1, (LPSTR)ch, 2, NULL, NULL ) == 2)
428 wparam = MAKEWPARAM( (ch[0] << 8) | ch[1], HIWORD(wparam) );
430 wparam = MAKEWPARAM( ch[0], HIWORD(wparam) );
438 /***********************************************************************
441 * Pack a message for sending to another process.
442 * Return the size of the data we expect in the message reply.
443 * Set data->count to -1 if there is an error.
445 static size_t pack_message( HWND hwnd, UINT message, WPARAM wparam, LPARAM lparam,
446 struct packed_message *data )
454 CREATESTRUCTW *cs = (CREATESTRUCTW *)lparam;
455 push_data( data, cs, sizeof(*cs) );
456 if (HIWORD(cs->lpszName)) push_string( data, cs->lpszName );
457 if (HIWORD(cs->lpszClass)) push_string( data, cs->lpszClass );
461 case WM_ASKCBFORMATNAME:
462 return wparam * sizeof(WCHAR);
463 case WM_WININICHANGE:
464 if (lparam) push_string(data, (LPWSTR)lparam );
467 case WM_DEVMODECHANGE:
472 push_string( data, (LPWSTR)lparam );
474 case WM_GETMINMAXINFO:
475 push_data( data, (MINMAXINFO *)lparam, sizeof(MINMAXINFO) );
476 return sizeof(MINMAXINFO);
478 push_data( data, (DRAWITEMSTRUCT *)lparam, sizeof(DRAWITEMSTRUCT) );
481 push_data( data, (MEASUREITEMSTRUCT *)lparam, sizeof(MEASUREITEMSTRUCT) );
482 return sizeof(MEASUREITEMSTRUCT);
484 push_data( data, (DELETEITEMSTRUCT *)lparam, sizeof(DELETEITEMSTRUCT) );
487 push_data( data, (COMPAREITEMSTRUCT *)lparam, sizeof(COMPAREITEMSTRUCT) );
489 case WM_WINDOWPOSCHANGING:
490 case WM_WINDOWPOSCHANGED:
491 push_data( data, (WINDOWPOS *)lparam, sizeof(WINDOWPOS) );
492 return sizeof(WINDOWPOS);
495 COPYDATASTRUCT *cp = (COPYDATASTRUCT *)lparam;
496 push_data( data, cp, sizeof(*cp) );
497 if (cp->lpData) push_data( data, cp->lpData, cp->cbData );
501 /* WM_NOTIFY cannot be sent across processes (MSDN) */
505 push_data( data, (HELPINFO *)lparam, sizeof(HELPINFO) );
507 case WM_STYLECHANGING:
508 case WM_STYLECHANGED:
509 push_data( data, (STYLESTRUCT *)lparam, sizeof(STYLESTRUCT) );
514 push_data( data, (RECT *)lparam, sizeof(RECT) );
519 NCCALCSIZE_PARAMS *nc = (NCCALCSIZE_PARAMS *)lparam;
520 push_data( data, nc, sizeof(*nc) );
521 push_data( data, nc->lppos, sizeof(*nc->lppos) );
522 return sizeof(*nc) + sizeof(*nc->lppos);
525 if (lparam) push_data( data, (MSG *)lparam, sizeof(MSG) );
527 case SBM_SETSCROLLINFO:
528 push_data( data, (SCROLLINFO *)lparam, sizeof(SCROLLINFO) );
530 case SBM_GETSCROLLINFO:
531 push_data( data, (SCROLLINFO *)lparam, sizeof(SCROLLINFO) );
532 return sizeof(SCROLLINFO);
533 case SBM_GETSCROLLBARINFO:
535 const SCROLLBARINFO *info = (const SCROLLBARINFO *)lparam;
536 size_t size = min( info->cbSize, sizeof(SCROLLBARINFO) );
537 push_data( data, info, size );
545 if (wparam) size += sizeof(DWORD);
546 if (lparam) size += sizeof(DWORD);
551 case CB_GETDROPPEDCONTROLRECT:
555 push_data( data, (RECT *)lparam, sizeof(RECT) );
559 WORD *pw = (WORD *)lparam;
560 push_data( data, pw, sizeof(*pw) );
561 return *pw * sizeof(WCHAR);
565 if (wparam) push_data( data, (UINT *)lparam, sizeof(UINT) * wparam );
568 case CB_INSERTSTRING:
570 case CB_FINDSTRINGEXACT:
571 case CB_SELECTSTRING:
572 if (combobox_has_strings( hwnd )) push_string( data, (LPWSTR)lparam );
575 if (!combobox_has_strings( hwnd )) return sizeof(ULONG_PTR);
576 return (SendMessageW( hwnd, CB_GETLBTEXTLEN, wparam, 0 ) + 1) * sizeof(WCHAR);
578 case LB_INSERTSTRING:
580 case LB_FINDSTRINGEXACT:
581 case LB_SELECTSTRING:
582 if (listbox_has_strings( hwnd )) push_string( data, (LPWSTR)lparam );
585 if (!listbox_has_strings( hwnd )) return sizeof(ULONG_PTR);
586 return (SendMessageW( hwnd, LB_GETTEXTLEN, wparam, 0 ) + 1) * sizeof(WCHAR);
588 return wparam * sizeof(UINT);
590 push_data( data, (MDINEXTMENU *)lparam, sizeof(MDINEXTMENU) );
591 return sizeof(MDINEXTMENU);
594 push_data( data, (RECT *)lparam, sizeof(RECT) );
598 MDICREATESTRUCTW *cs = (MDICREATESTRUCTW *)lparam;
599 push_data( data, cs, sizeof(*cs) );
600 if (HIWORD(cs->szTitle)) push_string( data, cs->szTitle );
601 if (HIWORD(cs->szClass)) push_string( data, cs->szClass );
604 case WM_MDIGETACTIVE:
605 if (lparam) return sizeof(BOOL);
607 case WM_DEVICECHANGE:
609 DEV_BROADCAST_HDR *header = (DEV_BROADCAST_HDR *)lparam;
610 push_data( data, header, header->dbch_size );
613 case WM_WINE_SETWINDOWPOS:
614 push_data( data, (WINDOWPOS *)lparam, sizeof(WINDOWPOS) );
616 case WM_WINE_KEYBOARD_LL_HOOK:
617 push_data( data, (KBDLLHOOKSTRUCT *)lparam, sizeof(KBDLLHOOKSTRUCT) );
619 case WM_WINE_MOUSE_LL_HOOK:
620 push_data( data, (MSLLHOOKSTRUCT *)lparam, sizeof(MSLLHOOKSTRUCT) );
623 if (!wparam) return 0;
626 /* these contain an HFONT */
629 /* these contain an HDC */
631 case WM_ICONERASEBKGND:
633 case WM_CTLCOLORMSGBOX:
634 case WM_CTLCOLOREDIT:
635 case WM_CTLCOLORLISTBOX:
638 case WM_CTLCOLORSCROLLBAR:
639 case WM_CTLCOLORSTATIC:
642 /* these contain an HGLOBAL */
643 case WM_PAINTCLIPBOARD:
644 case WM_SIZECLIPBOARD:
645 /* these contain HICON */
648 case WM_QUERYDRAGICON:
649 case WM_QUERYPARKICON:
650 /* these contain pointers */
652 case WM_QUERYDROPOBJECT:
656 FIXME( "msg %x (%s) not supported yet\n", message, SPY_GetMsgName(message, hwnd) );
664 /***********************************************************************
667 * Unpack a message received from another process.
669 static BOOL unpack_message( HWND hwnd, UINT message, WPARAM *wparam, LPARAM *lparam,
670 void **buffer, size_t size )
679 CREATESTRUCTW *cs = *buffer;
680 WCHAR *str = (WCHAR *)(cs + 1);
681 if (size < sizeof(*cs)) return FALSE;
683 if (HIWORD(cs->lpszName))
685 if (!check_string( str, size )) return FALSE;
687 size -= (strlenW(str) + 1) * sizeof(WCHAR);
688 str += strlenW(str) + 1;
690 if (HIWORD(cs->lpszClass))
692 if (!check_string( str, size )) return FALSE;
698 case WM_ASKCBFORMATNAME:
699 if (!get_buffer_space( buffer, (*wparam * sizeof(WCHAR)) )) return FALSE;
701 case WM_WININICHANGE:
702 if (!*lparam) return TRUE;
705 case WM_DEVMODECHANGE:
710 if (!check_string( *buffer, size )) return FALSE;
712 case WM_GETMINMAXINFO:
713 minsize = sizeof(MINMAXINFO);
716 minsize = sizeof(DRAWITEMSTRUCT);
719 minsize = sizeof(MEASUREITEMSTRUCT);
722 minsize = sizeof(DELETEITEMSTRUCT);
725 minsize = sizeof(COMPAREITEMSTRUCT);
727 case WM_WINDOWPOSCHANGING:
728 case WM_WINDOWPOSCHANGED:
729 case WM_WINE_SETWINDOWPOS:
730 minsize = sizeof(WINDOWPOS);
734 COPYDATASTRUCT *cp = *buffer;
735 if (size < sizeof(*cp)) return FALSE;
738 minsize = sizeof(*cp) + cp->cbData;
744 /* WM_NOTIFY cannot be sent across processes (MSDN) */
747 minsize = sizeof(HELPINFO);
749 case WM_STYLECHANGING:
750 case WM_STYLECHANGED:
751 minsize = sizeof(STYLESTRUCT);
754 if (!*wparam) minsize = sizeof(RECT);
757 NCCALCSIZE_PARAMS *nc = *buffer;
758 if (size < sizeof(*nc) + sizeof(*nc->lppos)) return FALSE;
759 nc->lppos = (WINDOWPOS *)(nc + 1);
763 if (!*lparam) return TRUE;
764 minsize = sizeof(MSG);
766 case SBM_SETSCROLLINFO:
767 minsize = sizeof(SCROLLINFO);
769 case SBM_GETSCROLLINFO:
770 if (!get_buffer_space( buffer, sizeof(SCROLLINFO ))) return FALSE;
772 case SBM_GETSCROLLBARINFO:
773 if (!get_buffer_space( buffer, sizeof(SCROLLBARINFO ))) return FALSE;
778 if (*wparam || *lparam)
780 if (!get_buffer_space( buffer, 2*sizeof(DWORD) )) return FALSE;
781 if (*wparam) *wparam = (WPARAM)*buffer;
782 if (*lparam) *lparam = (LPARAM)((DWORD *)*buffer + 1);
787 case CB_GETDROPPEDCONTROLRECT:
788 if (!get_buffer_space( buffer, sizeof(RECT) )) return FALSE;
792 minsize = sizeof(RECT);
797 if (size < sizeof(WORD)) return FALSE;
798 len = *(WORD *)*buffer;
799 if (!get_buffer_space( buffer, (len + 1) * sizeof(WCHAR) )) return FALSE;
800 *lparam = (LPARAM)*buffer + sizeof(WORD); /* don't erase WORD at start of buffer */
805 if (!*wparam) return TRUE;
806 minsize = *wparam * sizeof(UINT);
809 case CB_INSERTSTRING:
811 case CB_FINDSTRINGEXACT:
812 case CB_SELECTSTRING:
814 case LB_INSERTSTRING:
816 case LB_FINDSTRINGEXACT:
817 case LB_SELECTSTRING:
818 if (!*buffer) return TRUE;
819 if (!check_string( *buffer, size )) return FALSE;
823 size = sizeof(ULONG_PTR);
824 if (combobox_has_strings( hwnd ))
825 size = (SendMessageW( hwnd, CB_GETLBTEXTLEN, *wparam, 0 ) + 1) * sizeof(WCHAR);
826 if (!get_buffer_space( buffer, size )) return FALSE;
831 size = sizeof(ULONG_PTR);
832 if (listbox_has_strings( hwnd ))
833 size = (SendMessageW( hwnd, LB_GETTEXTLEN, *wparam, 0 ) + 1) * sizeof(WCHAR);
834 if (!get_buffer_space( buffer, size )) return FALSE;
838 if (!get_buffer_space( buffer, *wparam * sizeof(UINT) )) return FALSE;
841 minsize = sizeof(MDINEXTMENU);
842 if (!get_buffer_space( buffer, sizeof(MDINEXTMENU) )) return FALSE;
846 minsize = sizeof(RECT);
847 if (!get_buffer_space( buffer, sizeof(RECT) )) return FALSE;
851 MDICREATESTRUCTW *cs = *buffer;
852 WCHAR *str = (WCHAR *)(cs + 1);
853 if (size < sizeof(*cs)) return FALSE;
855 if (HIWORD(cs->szTitle))
857 if (!check_string( str, size )) return FALSE;
859 size -= (strlenW(str) + 1) * sizeof(WCHAR);
860 str += strlenW(str) + 1;
862 if (HIWORD(cs->szClass))
864 if (!check_string( str, size )) return FALSE;
869 case WM_MDIGETACTIVE:
870 if (!*lparam) return TRUE;
871 if (!get_buffer_space( buffer, sizeof(BOOL) )) return FALSE;
873 case WM_DEVICECHANGE:
874 minsize = sizeof(DEV_BROADCAST_HDR);
876 case WM_WINE_KEYBOARD_LL_HOOK:
877 minsize = sizeof(KBDLLHOOKSTRUCT);
879 case WM_WINE_MOUSE_LL_HOOK:
880 minsize = sizeof(MSLLHOOKSTRUCT);
883 if (!*wparam) return TRUE;
886 /* these contain an HFONT */
889 /* these contain an HDC */
891 case WM_ICONERASEBKGND:
893 case WM_CTLCOLORMSGBOX:
894 case WM_CTLCOLOREDIT:
895 case WM_CTLCOLORLISTBOX:
898 case WM_CTLCOLORSCROLLBAR:
899 case WM_CTLCOLORSTATIC:
902 /* these contain an HGLOBAL */
903 case WM_PAINTCLIPBOARD:
904 case WM_SIZECLIPBOARD:
905 /* these contain HICON */
908 case WM_QUERYDRAGICON:
909 case WM_QUERYPARKICON:
910 /* these contain pointers */
912 case WM_QUERYDROPOBJECT:
916 FIXME( "msg %x (%s) not supported yet\n", message, SPY_GetMsgName(message, hwnd) );
920 return TRUE; /* message doesn't need any unpacking */
923 /* default exit for most messages: check minsize and store buffer in lparam */
924 if (size < minsize) return FALSE;
925 *lparam = (LPARAM)*buffer;
930 /***********************************************************************
933 * Pack a reply to a message for sending to another process.
935 static void pack_reply( HWND hwnd, UINT message, WPARAM wparam, LPARAM lparam,
936 LRESULT res, struct packed_message *data )
943 push_data( data, (CREATESTRUCTW *)lparam, sizeof(CREATESTRUCTW) );
948 push_data( data, (WCHAR *)lparam, (res + 1) * sizeof(WCHAR) );
950 case WM_GETMINMAXINFO:
951 push_data( data, (MINMAXINFO *)lparam, sizeof(MINMAXINFO) );
954 push_data( data, (MEASUREITEMSTRUCT *)lparam, sizeof(MEASUREITEMSTRUCT) );
956 case WM_WINDOWPOSCHANGING:
957 case WM_WINDOWPOSCHANGED:
958 push_data( data, (WINDOWPOS *)lparam, sizeof(WINDOWPOS) );
961 if (lparam) push_data( data, (MSG *)lparam, sizeof(MSG) );
963 case SBM_GETSCROLLINFO:
964 push_data( data, (SCROLLINFO *)lparam, sizeof(SCROLLINFO) );
968 case CB_GETDROPPEDCONTROLRECT:
971 push_data( data, (RECT *)lparam, sizeof(RECT) );
975 WORD *ptr = (WORD *)lparam;
976 push_data( data, ptr, ptr[-1] * sizeof(WCHAR) );
980 push_data( data, (UINT *)lparam, wparam * sizeof(UINT) );
982 case WM_MDIGETACTIVE:
983 if (lparam) push_data( data, (BOOL *)lparam, sizeof(BOOL) );
987 push_data( data, (RECT *)lparam, sizeof(RECT) );
990 NCCALCSIZE_PARAMS *nc = (NCCALCSIZE_PARAMS *)lparam;
991 push_data( data, nc, sizeof(*nc) );
992 push_data( data, nc->lppos, sizeof(*nc->lppos) );
998 if (wparam) push_data( data, (DWORD *)wparam, sizeof(DWORD) );
999 if (lparam) push_data( data, (DWORD *)lparam, sizeof(DWORD) );
1002 push_data( data, (MDINEXTMENU *)lparam, sizeof(MDINEXTMENU) );
1005 push_data( data, (MDICREATESTRUCTW *)lparam, sizeof(MDICREATESTRUCTW) );
1007 case WM_ASKCBFORMATNAME:
1008 push_data( data, (WCHAR *)lparam, (strlenW((WCHAR *)lparam) + 1) * sizeof(WCHAR) );
1014 /***********************************************************************
1017 * Unpack a message reply received from another process.
1019 static void unpack_reply( HWND hwnd, UINT message, WPARAM wparam, LPARAM lparam,
1020 void *buffer, size_t size )
1027 CREATESTRUCTW *cs = (CREATESTRUCTW *)lparam;
1028 LPCWSTR name = cs->lpszName, class = cs->lpszClass;
1029 memcpy( cs, buffer, min( sizeof(*cs), size ));
1030 cs->lpszName = name; /* restore the original pointers */
1031 cs->lpszClass = class;
1035 case WM_ASKCBFORMATNAME:
1036 memcpy( (WCHAR *)lparam, buffer, min( wparam*sizeof(WCHAR), size ));
1038 case WM_GETMINMAXINFO:
1039 memcpy( (MINMAXINFO *)lparam, buffer, min( sizeof(MINMAXINFO), size ));
1041 case WM_MEASUREITEM:
1042 memcpy( (MEASUREITEMSTRUCT *)lparam, buffer, min( sizeof(MEASUREITEMSTRUCT), size ));
1044 case WM_WINDOWPOSCHANGING:
1045 case WM_WINDOWPOSCHANGED:
1046 memcpy( (WINDOWPOS *)lparam, buffer, min( sizeof(WINDOWPOS), size ));
1049 if (lparam) memcpy( (MSG *)lparam, buffer, min( sizeof(MSG), size ));
1051 case SBM_GETSCROLLINFO:
1052 memcpy( (SCROLLINFO *)lparam, buffer, min( sizeof(SCROLLINFO), size ));
1054 case SBM_GETSCROLLBARINFO:
1055 memcpy( (SCROLLBARINFO *)lparam, buffer, min( sizeof(SCROLLBARINFO), size ));
1058 case CB_GETDROPPEDCONTROLRECT:
1059 case LB_GETITEMRECT:
1062 memcpy( (RECT *)lparam, buffer, min( sizeof(RECT), size ));
1065 size = min( size, (size_t)*(WORD *)lparam );
1066 memcpy( (WCHAR *)lparam, buffer, size );
1068 case LB_GETSELITEMS:
1069 memcpy( (UINT *)lparam, buffer, min( wparam*sizeof(UINT), size ));
1073 memcpy( (WCHAR *)lparam, buffer, size );
1076 memcpy( (MDINEXTMENU *)lparam, buffer, min( sizeof(MDINEXTMENU), size ));
1078 case WM_MDIGETACTIVE:
1079 if (lparam) memcpy( (BOOL *)lparam, buffer, min( sizeof(BOOL), size ));
1083 memcpy( (RECT *)lparam, buffer, min( sizeof(RECT), size ));
1086 NCCALCSIZE_PARAMS *nc = (NCCALCSIZE_PARAMS *)lparam;
1087 WINDOWPOS *wp = nc->lppos;
1088 memcpy( nc, buffer, min( sizeof(*nc), size ));
1089 if (size > sizeof(*nc))
1091 size -= sizeof(*nc);
1092 memcpy( wp, (NCCALCSIZE_PARAMS*)buffer + 1, min( sizeof(*wp), size ));
1094 nc->lppos = wp; /* restore the original pointer */
1102 memcpy( (DWORD *)wparam, buffer, min( sizeof(DWORD), size ));
1103 if (size <= sizeof(DWORD)) break;
1104 size -= sizeof(DWORD);
1105 buffer = (DWORD *)buffer + 1;
1107 if (lparam) memcpy( (DWORD *)lparam, buffer, min( sizeof(DWORD), size ));
1111 MDICREATESTRUCTW *cs = (MDICREATESTRUCTW *)lparam;
1112 LPCWSTR title = cs->szTitle, class = cs->szClass;
1113 memcpy( cs, buffer, min( sizeof(*cs), size ));
1114 cs->szTitle = title; /* restore the original pointers */
1115 cs->szClass = class;
1119 ERR( "should not happen: unexpected message %x\n", message );
1125 /***********************************************************************
1128 * Send a reply to a sent message.
1130 static void reply_message( struct received_message_info *info, LRESULT result, BOOL remove )
1132 struct packed_message data;
1133 int i, replied = info->flags & ISMEX_REPLIED;
1135 if (info->flags & ISMEX_NOTIFY) return; /* notify messages don't get replies */
1136 if (!remove && replied) return; /* replied already */
1139 info->flags |= ISMEX_REPLIED;
1141 if (info->type == MSG_OTHER_PROCESS && !replied)
1143 pack_reply( info->msg.hwnd, info->msg.message, info->msg.wParam,
1144 info->msg.lParam, result, &data );
1147 SERVER_START_REQ( reply_message )
1149 req->result = result;
1150 req->remove = remove;
1151 for (i = 0; i < data.count; i++) wine_server_add_data( req, data.data[i], data.size[i] );
1152 wine_server_call( req );
1158 /***********************************************************************
1159 * handle_internal_message
1161 * Handle an internal Wine message instead of calling the window proc.
1163 static LRESULT handle_internal_message( HWND hwnd, UINT msg, WPARAM wparam, LPARAM lparam )
1167 case WM_WINE_DESTROYWINDOW:
1168 return WIN_DestroyWindow( hwnd );
1169 case WM_WINE_SETWINDOWPOS:
1170 if (hwnd == GetDesktopWindow()) return 0;
1171 return USER_Driver->pSetWindowPos( (WINDOWPOS *)lparam );
1172 case WM_WINE_SHOWWINDOW:
1173 if (hwnd == GetDesktopWindow()) return 0;
1174 return ShowWindow( hwnd, wparam );
1175 case WM_WINE_SETPARENT:
1176 if (hwnd == GetDesktopWindow()) return 0;
1177 return (LRESULT)SetParent( hwnd, (HWND)wparam );
1178 case WM_WINE_SETWINDOWLONG:
1179 return (LRESULT)SetWindowLongW( hwnd, wparam, lparam );
1180 case WM_WINE_ENABLEWINDOW:
1181 if (hwnd == GetDesktopWindow()) return 0;
1182 return EnableWindow( hwnd, wparam );
1183 case WM_WINE_SETACTIVEWINDOW:
1184 if (hwnd == GetDesktopWindow()) return 0;
1185 return (LRESULT)SetActiveWindow( (HWND)wparam );
1186 case WM_WINE_KEYBOARD_LL_HOOK:
1187 return HOOK_CallHooks( WH_KEYBOARD_LL, HC_ACTION, wparam, lparam, TRUE );
1188 case WM_WINE_MOUSE_LL_HOOK:
1189 return HOOK_CallHooks( WH_MOUSE_LL, HC_ACTION, wparam, lparam, TRUE );
1191 if (msg >= WM_WINE_FIRST_DRIVER_MSG && msg <= WM_WINE_LAST_DRIVER_MSG)
1192 return USER_Driver->pWindowMessage( hwnd, msg, wparam, lparam );
1193 FIXME( "unknown internal message %x\n", msg );
1198 /* since the WM_DDE_ACK response to a WM_DDE_EXECUTE message should contain the handle
1199 * to the memory handle, we keep track (in the server side) of all pairs of handle
1200 * used (the client passes its value and the content of the memory handle), and
1201 * the server stored both values (the client, and the local one, created after the
1202 * content). When a ACK message is generated, the list of pair is searched for a
1203 * matching pair, so that the client memory handle can be returned.
1206 HGLOBAL client_hMem;
1207 HGLOBAL server_hMem;
1210 static struct DDE_pair* dde_pairs;
1211 static int dde_num_alloc;
1212 static int dde_num_used;
1214 static CRITICAL_SECTION dde_crst;
1215 static CRITICAL_SECTION_DEBUG critsect_debug =
1218 { &critsect_debug.ProcessLocksList, &critsect_debug.ProcessLocksList },
1219 0, 0, { (DWORD_PTR)(__FILE__ ": dde_crst") }
1221 static CRITICAL_SECTION dde_crst = { &critsect_debug, -1, 0, 0, 0, 0 };
1223 static BOOL dde_add_pair(HGLOBAL chm, HGLOBAL shm)
1228 EnterCriticalSection(&dde_crst);
1230 /* now remember the pair of hMem on both sides */
1231 if (dde_num_used == dde_num_alloc)
1233 struct DDE_pair* tmp;
1235 tmp = HeapReAlloc( GetProcessHeap(), 0, dde_pairs,
1236 (dde_num_alloc + GROWBY) * sizeof(struct DDE_pair));
1238 tmp = HeapAlloc( GetProcessHeap(), 0,
1239 (dde_num_alloc + GROWBY) * sizeof(struct DDE_pair));
1243 LeaveCriticalSection(&dde_crst);
1247 /* zero out newly allocated part */
1248 memset(&dde_pairs[dde_num_alloc], 0, GROWBY * sizeof(struct DDE_pair));
1249 dde_num_alloc += GROWBY;
1252 for (i = 0; i < dde_num_alloc; i++)
1254 if (dde_pairs[i].server_hMem == 0)
1256 dde_pairs[i].client_hMem = chm;
1257 dde_pairs[i].server_hMem = shm;
1262 LeaveCriticalSection(&dde_crst);
1266 static HGLOBAL dde_get_pair(HGLOBAL shm)
1271 EnterCriticalSection(&dde_crst);
1272 for (i = 0; i < dde_num_alloc; i++)
1274 if (dde_pairs[i].server_hMem == shm)
1276 /* free this pair */
1277 dde_pairs[i].server_hMem = 0;
1279 ret = dde_pairs[i].client_hMem;
1283 LeaveCriticalSection(&dde_crst);
1287 /***********************************************************************
1290 * Post a DDE message
1292 static BOOL post_dde_message( DWORD dest_tid, struct packed_message *data, const struct send_message_info *info )
1296 UINT_PTR uiLo, uiHi;
1298 HGLOBAL hunlock = 0;
1302 if (!UnpackDDElParam( info->msg, info->lparam, &uiLo, &uiHi ))
1308 /* DDE messages which don't require packing are:
1317 /* uiHi should contain a hMem from WM_DDE_EXECUTE */
1318 HGLOBAL h = dde_get_pair( (HANDLE)uiHi );
1321 /* send back the value of h on the other side */
1322 push_data( data, &h, sizeof(HGLOBAL) );
1324 TRACE( "send dde-ack %x %08x => %p\n", uiLo, uiHi, h );
1329 /* uiHi should contain either an atom or 0 */
1330 TRACE( "send dde-ack %x atom=%x\n", uiLo, uiHi );
1331 lp = MAKELONG( uiLo, uiHi );
1340 size = GlobalSize( (HGLOBAL)uiLo ) ;
1341 if ((info->msg == WM_DDE_ADVISE && size < sizeof(DDEADVISE)) ||
1342 (info->msg == WM_DDE_DATA && size < sizeof(DDEDATA)) ||
1343 (info->msg == WM_DDE_POKE && size < sizeof(DDEPOKE))
1347 else if (info->msg != WM_DDE_DATA) return FALSE;
1352 if ((ptr = GlobalLock( (HGLOBAL)uiLo) ))
1354 DDEDATA *dde_data = (DDEDATA *)ptr;
1355 TRACE("unused %d, fResponse %d, fRelease %d, fDeferUpd %d, fAckReq %d, cfFormat %d\n",
1356 dde_data->unused, dde_data->fResponse, dde_data->fRelease,
1357 dde_data->reserved, dde_data->fAckReq, dde_data->cfFormat);
1358 push_data( data, ptr, size );
1359 hunlock = (HGLOBAL)uiLo;
1362 TRACE( "send ddepack %u %x\n", size, uiHi );
1364 case WM_DDE_EXECUTE:
1367 if ((ptr = GlobalLock( (HGLOBAL)info->lparam) ))
1369 push_data(data, ptr, GlobalSize( (HGLOBAL)info->lparam ));
1370 /* so that the other side can send it back on ACK */
1372 hunlock = (HGLOBAL)info->lparam;
1377 SERVER_START_REQ( send_message )
1380 req->type = info->type;
1382 req->win = info->hwnd;
1383 req->msg = info->msg;
1384 req->wparam = info->wparam;
1386 req->time = GetCurrentTime();
1388 for (i = 0; i < data->count; i++)
1389 wine_server_add_data( req, data->data[i], data->size[i] );
1390 if ((res = wine_server_call( req )))
1392 if (res == STATUS_INVALID_PARAMETER)
1393 /* FIXME: find a STATUS_ value for this one */
1394 SetLastError( ERROR_INVALID_THREAD_ID );
1396 SetLastError( RtlNtStatusToDosError(res) );
1399 FreeDDElParam(info->msg, info->lparam);
1402 if (hunlock) GlobalUnlock(hunlock);
1407 /***********************************************************************
1408 * unpack_dde_message
1410 * Unpack a posted DDE message received from another process.
1412 static BOOL unpack_dde_message( HWND hwnd, UINT message, WPARAM *wparam, LPARAM *lparam,
1413 void **buffer, size_t size )
1415 UINT_PTR uiLo, uiHi;
1424 /* hMem is being passed */
1425 if (size != sizeof(HGLOBAL)) return FALSE;
1426 if (!buffer || !*buffer) return FALSE;
1428 memcpy( &hMem, *buffer, size );
1429 uiHi = (UINT_PTR)hMem;
1430 TRACE("recv dde-ack %x mem=%x[%lx]\n", uiLo, uiHi, GlobalSize( hMem ));
1434 uiLo = LOWORD( *lparam );
1435 uiHi = HIWORD( *lparam );
1436 TRACE("recv dde-ack %x atom=%x\n", uiLo, uiHi);
1438 *lparam = PackDDElParam( WM_DDE_ACK, uiLo, uiHi );
1443 if ((!buffer || !*buffer) && message != WM_DDE_DATA) return FALSE;
1445 TRACE( "recv ddepack %u %x\n", size, uiHi );
1448 if (!(hMem = GlobalAlloc( GMEM_MOVEABLE|GMEM_DDESHARE, size )))
1450 if ((ptr = GlobalLock( hMem )))
1452 memcpy( ptr, *buffer, size );
1453 GlobalUnlock( hMem );
1461 uiLo = (UINT_PTR)hMem;
1463 *lparam = PackDDElParam( message, uiLo, uiHi );
1465 case WM_DDE_EXECUTE:
1468 if (!buffer || !*buffer) return FALSE;
1469 if (!(hMem = GlobalAlloc( GMEM_MOVEABLE|GMEM_DDESHARE, size ))) return FALSE;
1470 if ((ptr = GlobalLock( hMem )))
1472 memcpy( ptr, *buffer, size );
1473 GlobalUnlock( hMem );
1474 TRACE( "exec: pairing c=%08lx s=%08lx\n", *lparam, (DWORD)hMem );
1475 if (!dde_add_pair( (HGLOBAL)*lparam, hMem ))
1486 } else return FALSE;
1487 *lparam = (LPARAM)hMem;
1493 /***********************************************************************
1496 * Call a window procedure and the corresponding hooks.
1498 static LRESULT call_window_proc( HWND hwnd, UINT msg, WPARAM wparam, LPARAM lparam,
1499 BOOL unicode, BOOL same_thread )
1501 struct user_thread_info *thread_info = get_user_thread_info();
1505 CWPRETSTRUCT cwpret;
1507 if (thread_info->recursion_count > MAX_SENDMSG_RECURSION) return 0;
1508 thread_info->recursion_count++;
1510 if (msg & 0x80000000)
1512 result = handle_internal_message( hwnd, msg, wparam, lparam );
1516 /* first the WH_CALLWNDPROC hook */
1517 hwnd = WIN_GetFullHandle( hwnd );
1518 cwp.lParam = lparam;
1519 cwp.wParam = wparam;
1522 HOOK_CallHooks( WH_CALLWNDPROC, HC_ACTION, same_thread, (LPARAM)&cwp, unicode );
1524 /* now call the window procedure */
1527 if (!(winproc = (WNDPROC)GetWindowLongPtrW( hwnd, GWLP_WNDPROC ))) goto done;
1528 result = CallWindowProcW( winproc, hwnd, msg, wparam, lparam );
1532 if (!(winproc = (WNDPROC)GetWindowLongPtrA( hwnd, GWLP_WNDPROC ))) goto done;
1533 result = CallWindowProcA( winproc, hwnd, msg, wparam, lparam );
1536 /* and finally the WH_CALLWNDPROCRET hook */
1537 cwpret.lResult = result;
1538 cwpret.lParam = lparam;
1539 cwpret.wParam = wparam;
1540 cwpret.message = msg;
1542 HOOK_CallHooks( WH_CALLWNDPROCRET, HC_ACTION, same_thread, (LPARAM)&cwpret, unicode );
1544 thread_info->recursion_count--;
1549 /***********************************************************************
1550 * send_parent_notify
1552 * Send a WM_PARENTNOTIFY to all ancestors of the given window, unless
1553 * the window has the WS_EX_NOPARENTNOTIFY style.
1555 static void send_parent_notify( HWND hwnd, WORD event, WORD idChild, POINT pt )
1557 /* pt has to be in the client coordinates of the parent window */
1558 MapWindowPoints( 0, hwnd, &pt, 1 );
1563 if (!(GetWindowLongW( hwnd, GWL_STYLE ) & WS_CHILD)) break;
1564 if (GetWindowLongW( hwnd, GWL_EXSTYLE ) & WS_EX_NOPARENTNOTIFY) break;
1565 if (!(parent = GetParent(hwnd))) break;
1566 MapWindowPoints( hwnd, parent, &pt, 1 );
1568 SendMessageW( hwnd, WM_PARENTNOTIFY,
1569 MAKEWPARAM( event, idChild ), MAKELPARAM( pt.x, pt.y ) );
1574 /***********************************************************************
1575 * accept_hardware_message
1577 * Tell the server we have passed the message to the app
1578 * (even though we may end up dropping it later on)
1580 static void accept_hardware_message( UINT hw_id, BOOL remove, HWND new_hwnd )
1582 SERVER_START_REQ( accept_hardware_message )
1585 req->remove = remove;
1586 req->new_win = new_hwnd;
1587 if (wine_server_call( req ))
1588 FIXME("Failed to reply to MSG_HARDWARE message. Message may not be removed from queue.\n");
1594 /***********************************************************************
1595 * process_keyboard_message
1597 * returns TRUE if the contents of 'msg' should be passed to the application
1599 static BOOL process_keyboard_message( MSG *msg, UINT hw_id, HWND hwnd_filter,
1600 UINT first, UINT last, BOOL remove )
1604 /* FIXME: is this really the right place for this hook? */
1605 event.message = msg->message;
1606 event.hwnd = msg->hwnd;
1607 event.time = msg->time;
1608 event.paramL = (msg->wParam & 0xFF) | (HIWORD(msg->lParam) << 8);
1609 event.paramH = msg->lParam & 0x7FFF;
1610 if (HIWORD(msg->lParam) & 0x0100) event.paramH |= 0x8000; /* special_key - bit */
1611 HOOK_CallHooks( WH_JOURNALRECORD, HC_ACTION, 0, (LPARAM)&event, TRUE );
1613 /* check message filters */
1614 if (msg->message < first || msg->message > last) return FALSE;
1615 if (!check_hwnd_filter( msg, hwnd_filter )) return FALSE;
1619 /* Handle F1 key by sending out WM_HELP message */
1620 if ((msg->message == WM_KEYUP) &&
1621 (msg->wParam == VK_F1) &&
1622 (msg->hwnd != GetDesktopWindow()) &&
1623 !MENU_IsMenuActive())
1626 hi.cbSize = sizeof(HELPINFO);
1627 hi.iContextType = HELPINFO_WINDOW;
1628 hi.iCtrlId = GetWindowLongPtrA( msg->hwnd, GWLP_ID );
1629 hi.hItemHandle = msg->hwnd;
1630 hi.dwContextId = GetWindowContextHelpId( msg->hwnd );
1631 hi.MousePos = msg->pt;
1632 SendMessageW( msg->hwnd, WM_HELP, 0, (LPARAM)&hi );
1636 if (HOOK_CallHooks( WH_KEYBOARD, remove ? HC_ACTION : HC_NOREMOVE,
1637 LOWORD(msg->wParam), msg->lParam, TRUE ))
1639 /* skip this message */
1640 HOOK_CallHooks( WH_CBT, HCBT_KEYSKIPPED, LOWORD(msg->wParam), msg->lParam, TRUE );
1641 accept_hardware_message( hw_id, TRUE, 0 );
1644 accept_hardware_message( hw_id, remove, 0 );
1649 /***********************************************************************
1650 * process_mouse_message
1652 * returns TRUE if the contents of 'msg' should be passed to the application
1654 static BOOL process_mouse_message( MSG *msg, UINT hw_id, ULONG_PTR extra_info, HWND hwnd_filter,
1655 UINT first, UINT last, BOOL remove )
1664 MOUSEHOOKSTRUCT hook;
1667 /* find the window to dispatch this mouse message to */
1669 GetGUIThreadInfo( GetCurrentThreadId(), &info );
1670 if (info.hwndCapture)
1673 msg->hwnd = info.hwndCapture;
1677 msg->hwnd = WINPOS_WindowFromPoint( msg->hwnd, msg->pt, &hittest );
1680 if (!msg->hwnd || !WIN_IsCurrentThread( msg->hwnd ))
1682 accept_hardware_message( hw_id, TRUE, msg->hwnd );
1686 /* FIXME: is this really the right place for this hook? */
1687 event.message = msg->message;
1688 event.time = msg->time;
1689 event.hwnd = msg->hwnd;
1690 event.paramL = msg->pt.x;
1691 event.paramH = msg->pt.y;
1692 HOOK_CallHooks( WH_JOURNALRECORD, HC_ACTION, 0, (LPARAM)&event, TRUE );
1694 if (!check_hwnd_filter( msg, hwnd_filter )) return FALSE;
1697 message = msg->message;
1698 /* Note: windows has no concept of a non-client wheel message */
1699 if (message != WM_MOUSEWHEEL)
1701 if (hittest != HTCLIENT)
1703 message += WM_NCMOUSEMOVE - WM_MOUSEMOVE;
1704 msg->wParam = hittest;
1708 /* coordinates don't get translated while tracking a menu */
1709 /* FIXME: should differentiate popups and top-level menus */
1710 if (!(info.flags & GUI_INMENUMODE))
1711 ScreenToClient( msg->hwnd, &pt );
1714 msg->lParam = MAKELONG( pt.x, pt.y );
1716 /* translate double clicks */
1718 if ((msg->message == WM_LBUTTONDOWN) ||
1719 (msg->message == WM_RBUTTONDOWN) ||
1720 (msg->message == WM_MBUTTONDOWN) ||
1721 (msg->message == WM_XBUTTONDOWN))
1723 BOOL update = remove;
1725 /* translate double clicks -
1726 * note that ...MOUSEMOVEs can slip in between
1727 * ...BUTTONDOWN and ...BUTTONDBLCLK messages */
1729 if ((info.flags & (GUI_INMENUMODE|GUI_INMOVESIZE)) ||
1730 hittest != HTCLIENT ||
1731 (GetClassLongA( msg->hwnd, GCL_STYLE ) & CS_DBLCLKS))
1733 if ((msg->message == clk_msg.message) &&
1734 (msg->hwnd == clk_msg.hwnd) &&
1735 (msg->wParam == clk_msg.wParam) &&
1736 (msg->time - clk_msg.time < GetDoubleClickTime()) &&
1737 (abs(msg->pt.x - clk_msg.pt.x) < GetSystemMetrics(SM_CXDOUBLECLK)/2) &&
1738 (abs(msg->pt.y - clk_msg.pt.y) < GetSystemMetrics(SM_CYDOUBLECLK)/2))
1740 message += (WM_LBUTTONDBLCLK - WM_LBUTTONDOWN);
1743 clk_msg.message = 0; /* clear the double click conditions */
1748 if (message < first || message > last) return FALSE;
1749 /* update static double click conditions */
1750 if (update) clk_msg = *msg;
1754 if (message < first || message > last) return FALSE;
1757 /* message is accepted now (but may still get dropped) */
1760 hook.hwnd = msg->hwnd;
1761 hook.wHitTestCode = hittest;
1762 hook.dwExtraInfo = extra_info;
1763 if (HOOK_CallHooks( WH_MOUSE, remove ? HC_ACTION : HC_NOREMOVE,
1764 message, (LPARAM)&hook, TRUE ))
1767 hook.hwnd = msg->hwnd;
1768 hook.wHitTestCode = hittest;
1769 hook.dwExtraInfo = extra_info;
1770 HOOK_CallHooks( WH_CBT, HCBT_CLICKSKIPPED, message, (LPARAM)&hook, TRUE );
1771 accept_hardware_message( hw_id, TRUE, 0 );
1775 if ((hittest == HTERROR) || (hittest == HTNOWHERE))
1777 SendMessageW( msg->hwnd, WM_SETCURSOR, (WPARAM)msg->hwnd,
1778 MAKELONG( hittest, msg->message ));
1779 accept_hardware_message( hw_id, TRUE, 0 );
1783 accept_hardware_message( hw_id, remove, 0 );
1785 if (!remove || info.hwndCapture)
1787 msg->message = message;
1793 if ((msg->message == WM_LBUTTONDOWN) ||
1794 (msg->message == WM_RBUTTONDOWN) ||
1795 (msg->message == WM_MBUTTONDOWN) ||
1796 (msg->message == WM_XBUTTONDOWN))
1798 /* Send the WM_PARENTNOTIFY,
1799 * note that even for double/nonclient clicks
1800 * notification message is still WM_L/M/RBUTTONDOWN.
1802 send_parent_notify( msg->hwnd, msg->message, 0, msg->pt );
1804 /* Activate the window if needed */
1806 if (msg->hwnd != info.hwndActive)
1808 HWND hwndTop = msg->hwnd;
1811 if ((GetWindowLongW( hwndTop, GWL_STYLE ) & (WS_POPUP|WS_CHILD)) != WS_CHILD) break;
1812 hwndTop = GetParent( hwndTop );
1815 if (hwndTop && hwndTop != GetDesktopWindow())
1817 LONG ret = SendMessageW( msg->hwnd, WM_MOUSEACTIVATE, (WPARAM)hwndTop,
1818 MAKELONG( hittest, msg->message ) );
1821 case MA_NOACTIVATEANDEAT:
1826 case MA_ACTIVATEANDEAT:
1831 if (!FOCUS_MouseActivate( hwndTop )) eatMsg = TRUE;
1834 WARN( "unknown WM_MOUSEACTIVATE code %ld\n", ret );
1841 /* send the WM_SETCURSOR message */
1843 /* Windows sends the normal mouse message as the message parameter
1844 in the WM_SETCURSOR message even if it's non-client mouse message */
1845 SendMessageW( msg->hwnd, WM_SETCURSOR, (WPARAM)msg->hwnd, MAKELONG( hittest, msg->message ));
1847 msg->message = message;
1852 /***********************************************************************
1853 * process_hardware_message
1855 * Process a hardware message; return TRUE if message should be passed on to the app
1857 static BOOL process_hardware_message( MSG *msg, UINT hw_id, ULONG_PTR extra_info, HWND hwnd_filter,
1858 UINT first, UINT last, BOOL remove )
1860 if (is_keyboard_message( msg->message ))
1861 return process_keyboard_message( msg, hw_id, hwnd_filter, first, last, remove );
1863 if (is_mouse_message( msg->message ))
1864 return process_mouse_message( msg, hw_id, extra_info, hwnd_filter, first, last, remove );
1866 ERR( "unknown message type %x\n", msg->message );
1871 /***********************************************************************
1872 * call_sendmsg_callback
1874 * Call the callback function of SendMessageCallback.
1876 static inline void call_sendmsg_callback( SENDASYNCPROC callback, HWND hwnd, UINT msg,
1877 ULONG_PTR data, LRESULT result )
1879 if (TRACE_ON(relay))
1880 DPRINTF( "%04lx:Call message callback %p (hwnd=%p,msg=%s,data=%08lx,result=%08lx)\n",
1881 GetCurrentThreadId(), callback, hwnd, SPY_GetMsgName( msg, hwnd ),
1883 callback( hwnd, msg, data, result );
1884 if (TRACE_ON(relay))
1885 DPRINTF( "%04lx:Ret message callback %p (hwnd=%p,msg=%s,data=%08lx,result=%08lx)\n",
1886 GetCurrentThreadId(), callback, hwnd, SPY_GetMsgName( msg, hwnd ),
1891 /***********************************************************************
1894 * Retrieve the hook procedure real value for a module-relative proc
1896 static void *get_hook_proc( void *proc, const WCHAR *module )
1900 if (!(mod = GetModuleHandleW(module)))
1902 TRACE( "loading %s\n", debugstr_w(module) );
1903 /* FIXME: the library will never be freed */
1904 if (!(mod = LoadLibraryW(module))) return NULL;
1906 return (char *)mod + (ULONG_PTR)proc;
1910 /***********************************************************************
1913 * Peek for a message matching the given parameters. Return FALSE if none available.
1914 * All pending sent messages are processed before returning.
1916 static BOOL peek_message( MSG *msg, HWND hwnd, UINT first, UINT last, int flags )
1919 ULONG_PTR extra_info = 0;
1920 struct user_thread_info *thread_info = get_user_thread_info();
1921 struct received_message_info info, *old_info;
1922 unsigned int hw_id = 0; /* id of previous hardware message */
1924 if (!first && !last) last = ~0;
1929 void *buffer = NULL;
1930 size_t size = 0, buffer_size = 0;
1932 do /* loop while buffer is too small */
1934 if (buffer_size && !(buffer = HeapAlloc( GetProcessHeap(), 0, buffer_size )))
1936 SERVER_START_REQ( get_message )
1939 req->get_win = hwnd;
1940 req->get_first = first;
1941 req->get_last = last;
1943 if (buffer_size) wine_server_set_reply( req, buffer, buffer_size );
1944 if (!(res = wine_server_call( req )))
1946 size = wine_server_reply_size( reply );
1947 info.type = reply->type;
1948 info.msg.hwnd = reply->win;
1949 info.msg.message = reply->msg;
1950 info.msg.wParam = reply->wparam;
1951 info.msg.lParam = reply->lparam;
1952 info.msg.time = reply->time;
1953 info.msg.pt.x = reply->x;
1954 info.msg.pt.y = reply->y;
1955 info.hook = reply->hook;
1956 info.hook_proc = reply->hook_proc;
1957 hw_id = reply->hw_id;
1958 extra_info = reply->info;
1959 thread_info->active_hooks = reply->active_hooks;
1963 HeapFree( GetProcessHeap(), 0, buffer );
1964 buffer_size = reply->total;
1968 } while (res == STATUS_BUFFER_OVERFLOW);
1970 if (res) return FALSE;
1972 TRACE( "got type %d msg %x (%s) hwnd %p wp %x lp %lx\n",
1973 info.type, info.msg.message,
1974 (info.type == MSG_WINEVENT) ? "MSG_WINEVENT" : SPY_GetMsgName(info.msg.message, info.msg.hwnd),
1975 info.msg.hwnd, info.msg.wParam, info.msg.lParam );
1981 info.flags = ISMEX_SEND;
1984 info.flags = ISMEX_NOTIFY;
1987 info.flags = ISMEX_CALLBACK;
1989 case MSG_CALLBACK_RESULT:
1990 call_sendmsg_callback( (SENDASYNCPROC)info.msg.wParam, info.msg.hwnd,
1991 info.msg.message, extra_info, info.msg.lParam );
1996 WCHAR module[MAX_PATH];
1997 size = min( size, (MAX_PATH - 1) * sizeof(WCHAR) );
1998 memcpy( module, buffer, size );
1999 module[size / sizeof(WCHAR)] = 0;
2000 if (!(info.hook_proc = get_hook_proc( info.hook_proc, module )))
2002 ERR( "invalid winevent hook module name %s\n", debugstr_w(module) );
2006 if (TRACE_ON(relay))
2007 DPRINTF( "%04lx:Call winevent proc %p (hook=%p,event=%x,hwnd=%p,object_id=%x,child_id=%lx,tid=%04lx,time=%lx)\n",
2008 GetCurrentThreadId(), info.hook_proc,
2009 info.hook, info.msg.message, info.msg.hwnd, info.msg.wParam,
2010 info.msg.lParam, extra_info, info.msg.time);
2012 info.hook_proc( info.hook, info.msg.message, info.msg.hwnd, info.msg.wParam,
2013 info.msg.lParam, extra_info, info.msg.time );
2015 if (TRACE_ON(relay))
2016 DPRINTF( "%04lx:Ret winevent proc %p (hook=%p,event=%x,hwnd=%p,object_id=%x,child_id=%lx,tid=%04lx,time=%lx)\n",
2017 GetCurrentThreadId(), info.hook_proc,
2018 info.hook, info.msg.message, info.msg.hwnd, info.msg.wParam,
2019 info.msg.lParam, extra_info, info.msg.time);
2021 case MSG_OTHER_PROCESS:
2022 info.flags = ISMEX_SEND;
2023 if (!unpack_message( info.msg.hwnd, info.msg.message, &info.msg.wParam,
2024 &info.msg.lParam, &buffer, size ))
2026 ERR( "invalid packed message %x (%s) hwnd %p wp %x lp %lx size %d\n",
2027 info.msg.message, SPY_GetMsgName(info.msg.message, info.msg.hwnd), info.msg.hwnd,
2028 info.msg.wParam, info.msg.lParam, size );
2030 reply_message( &info, 0, TRUE );
2035 if (!process_hardware_message( &info.msg, hw_id, extra_info,
2036 hwnd, first, last, flags & GET_MSG_REMOVE ))
2038 TRACE("dropping msg %x\n", info.msg.message );
2039 goto next; /* ignore it */
2041 thread_info->GetMessagePosVal = MAKELONG( info.msg.pt.x, info.msg.pt.y );
2044 thread_info->GetMessageExtraInfoVal = extra_info;
2045 if (info.msg.message >= WM_DDE_FIRST && info.msg.message <= WM_DDE_LAST)
2047 if (!unpack_dde_message( info.msg.hwnd, info.msg.message, &info.msg.wParam,
2048 &info.msg.lParam, &buffer, size ))
2050 ERR( "invalid packed dde-message %x (%s) hwnd %p wp %x lp %lx size %d\n",
2051 info.msg.message, SPY_GetMsgName(info.msg.message, info.msg.hwnd),
2052 info.msg.hwnd, info.msg.wParam, info.msg.lParam, size );
2053 goto next; /* ignore it */
2057 HeapFree( GetProcessHeap(), 0, buffer );
2061 /* if we get here, we have a sent message; call the window procedure */
2062 old_info = thread_info->receive_info;
2063 thread_info->receive_info = &info;
2064 result = call_window_proc( info.msg.hwnd, info.msg.message, info.msg.wParam,
2065 info.msg.lParam, (info.type != MSG_ASCII), FALSE );
2066 reply_message( &info, result, TRUE );
2067 thread_info->receive_info = old_info;
2069 HeapFree( GetProcessHeap(), 0, buffer );
2074 /***********************************************************************
2075 * process_sent_messages
2077 * Process all pending sent messages.
2079 inline static void process_sent_messages(void)
2082 peek_message( &msg, 0, 0, 0, GET_MSG_REMOVE | GET_MSG_SENT_ONLY );
2086 /***********************************************************************
2087 * get_server_queue_handle
2089 * Get a handle to the server message queue for the current thread.
2091 static HANDLE get_server_queue_handle(void)
2093 struct user_thread_info *thread_info = get_user_thread_info();
2096 if (!(ret = thread_info->server_queue))
2098 SERVER_START_REQ( get_msg_queue )
2100 wine_server_call( req );
2101 ret = reply->handle;
2104 thread_info->server_queue = ret;
2105 if (!ret) ERR( "Cannot get server thread queue\n" );
2111 /***********************************************************************
2112 * wait_message_reply
2114 * Wait until a sent message gets replied to.
2116 static void wait_message_reply( UINT flags )
2118 HANDLE server_queue = get_server_queue_handle();
2122 unsigned int wake_bits = 0, changed_bits = 0;
2125 SERVER_START_REQ( set_queue_mask )
2127 req->wake_mask = QS_SMRESULT | ((flags & SMTO_BLOCK) ? 0 : QS_SENDMESSAGE);
2128 req->changed_mask = req->wake_mask;
2130 if (!wine_server_call( req ))
2132 wake_bits = reply->wake_bits;
2133 changed_bits = reply->changed_bits;
2138 if (wake_bits & QS_SMRESULT) return; /* got a result */
2139 if (wake_bits & QS_SENDMESSAGE)
2141 /* Process the sent message immediately */
2142 process_sent_messages();
2146 /* now wait for it */
2148 ReleaseThunkLock( &dwlc );
2149 res = USER_Driver->pMsgWaitForMultipleObjectsEx( 1, &server_queue,
2150 INFINITE, QS_ALLINPUT, 0 );
2151 if (dwlc) RestoreThunkLock( dwlc );
2155 /***********************************************************************
2156 * put_message_in_queue
2158 * Put a sent message into the destination queue.
2159 * For inter-process message, reply_size is set to expected size of reply data.
2161 static BOOL put_message_in_queue( DWORD dest_tid, const struct send_message_info *info,
2162 size_t *reply_size )
2164 struct packed_message data;
2168 /* Check for INFINITE timeout for compatibility with Win9x,
2169 * although Windows >= NT does not do so
2171 if (info->type != MSG_NOTIFY &&
2172 info->type != MSG_CALLBACK &&
2173 info->type != MSG_POSTED &&
2174 info->timeout != INFINITE)
2175 timeout = info->timeout;
2178 if (info->type == MSG_OTHER_PROCESS)
2180 *reply_size = pack_message( info->hwnd, info->msg, info->wparam, info->lparam, &data );
2181 if (data.count == -1)
2183 WARN( "cannot pack message %x\n", info->msg );
2187 else if (info->type == MSG_POSTED && info->msg >= WM_DDE_FIRST && info->msg <= WM_DDE_LAST)
2189 return post_dde_message( dest_tid, &data, info );
2192 SERVER_START_REQ( send_message )
2195 req->type = info->type;
2197 req->win = info->hwnd;
2198 req->msg = info->msg;
2199 req->wparam = info->wparam;
2200 req->lparam = info->lparam;
2201 req->time = GetCurrentTime();
2202 req->timeout = timeout;
2204 if (info->type == MSG_CALLBACK)
2206 req->callback = info->callback;
2207 req->info = info->data;
2210 if (info->flags & SMTO_ABORTIFHUNG) req->flags |= SEND_MSG_ABORT_IF_HUNG;
2211 for (i = 0; i < data.count; i++) wine_server_add_data( req, data.data[i], data.size[i] );
2212 if ((res = wine_server_call( req )))
2214 if (res == STATUS_INVALID_PARAMETER)
2215 /* FIXME: find a STATUS_ value for this one */
2216 SetLastError( ERROR_INVALID_THREAD_ID );
2218 SetLastError( RtlNtStatusToDosError(res) );
2226 /***********************************************************************
2229 * Retrieve a message reply from the server.
2231 static LRESULT retrieve_reply( const struct send_message_info *info,
2232 size_t reply_size, LRESULT *result )
2235 void *reply_data = NULL;
2239 if (!(reply_data = HeapAlloc( GetProcessHeap(), 0, reply_size )))
2241 WARN( "no memory for reply %d bytes, will be truncated\n", reply_size );
2245 SERVER_START_REQ( get_message_reply )
2248 if (reply_size) wine_server_set_reply( req, reply_data, reply_size );
2249 if (!(status = wine_server_call( req ))) *result = reply->result;
2250 reply_size = wine_server_reply_size( reply );
2253 if (!status && reply_size)
2254 unpack_reply( info->hwnd, info->msg, info->wparam, info->lparam, reply_data, reply_size );
2256 HeapFree( GetProcessHeap(), 0, reply_data );
2258 TRACE( "hwnd %p msg %x (%s) wp %x lp %lx got reply %lx (err=%ld)\n",
2259 info->hwnd, info->msg, SPY_GetMsgName(info->msg, info->hwnd), info->wparam,
2260 info->lparam, *result, status );
2262 /* MSDN states that last error is 0 on timeout, but at least NT4 returns ERROR_TIMEOUT */
2263 if (status) SetLastError( RtlNtStatusToDosError(status) );
2268 /***********************************************************************
2269 * send_inter_thread_message
2271 static LRESULT send_inter_thread_message( DWORD dest_tid, const struct send_message_info *info,
2274 size_t reply_size = 0;
2276 TRACE( "hwnd %p msg %x (%s) wp %x lp %lx\n",
2277 info->hwnd, info->msg, SPY_GetMsgName(info->msg, info->hwnd), info->wparam, info->lparam );
2279 USER_CheckNotLock();
2281 if (!put_message_in_queue( dest_tid, info, &reply_size )) return 0;
2283 /* there's no reply to wait for on notify/callback messages */
2284 if (info->type == MSG_NOTIFY || info->type == MSG_CALLBACK) return 1;
2286 wait_message_reply( info->flags );
2287 return retrieve_reply( info, reply_size, res_ptr );
2291 /***********************************************************************
2292 * MSG_SendInternalMessageTimeout
2294 * Same as SendMessageTimeoutW but sends the message to a specific thread
2295 * without requiring a window handle. Only works for internal Wine messages.
2297 LRESULT MSG_SendInternalMessageTimeout( DWORD dest_pid, DWORD dest_tid,
2298 UINT msg, WPARAM wparam, LPARAM lparam,
2299 UINT flags, UINT timeout, PDWORD_PTR res_ptr )
2301 struct send_message_info info;
2302 LRESULT ret, result;
2304 assert( msg & 0x80000000 ); /* must be an internal Wine message */
2306 info.type = MSG_UNICODE;
2309 info.wparam = wparam;
2310 info.lparam = lparam;
2312 info.timeout = timeout;
2314 if (USER_IsExitingThread( dest_tid )) return 0;
2316 if (dest_tid == GetCurrentThreadId())
2318 result = handle_internal_message( 0, msg, wparam, lparam );
2323 if (dest_pid != GetCurrentProcessId()) info.type = MSG_OTHER_PROCESS;
2324 ret = send_inter_thread_message( dest_tid, &info, &result );
2326 if (ret && res_ptr) *res_ptr = result;
2331 /***********************************************************************
2332 * SendMessageTimeoutW (USER32.@)
2334 LRESULT WINAPI SendMessageTimeoutW( HWND hwnd, UINT msg, WPARAM wparam, LPARAM lparam,
2335 UINT flags, UINT timeout, PDWORD_PTR res_ptr )
2337 struct send_message_info info;
2338 DWORD dest_tid, dest_pid;
2339 LRESULT ret, result;
2341 info.type = MSG_UNICODE;
2344 info.wparam = wparam;
2345 info.lparam = lparam;
2347 info.timeout = timeout;
2349 if (is_broadcast(hwnd))
2351 EnumWindows( broadcast_message_callback, (LPARAM)&info );
2352 if (res_ptr) *res_ptr = 1;
2356 if (!(dest_tid = GetWindowThreadProcessId( hwnd, &dest_pid ))) return 0;
2358 if (USER_IsExitingThread( dest_tid )) return 0;
2360 SPY_EnterMessage( SPY_SENDMESSAGE, hwnd, msg, wparam, lparam );
2362 if (dest_tid == GetCurrentThreadId())
2364 result = call_window_proc( hwnd, msg, wparam, lparam, TRUE, TRUE );
2369 if (dest_pid != GetCurrentProcessId()) info.type = MSG_OTHER_PROCESS;
2370 ret = send_inter_thread_message( dest_tid, &info, &result );
2373 SPY_ExitMessage( SPY_RESULT_OK, hwnd, msg, result, wparam, lparam );
2374 if (ret && res_ptr) *res_ptr = result;
2379 /***********************************************************************
2380 * SendMessageTimeoutA (USER32.@)
2382 LRESULT WINAPI SendMessageTimeoutA( HWND hwnd, UINT msg, WPARAM wparam, LPARAM lparam,
2383 UINT flags, UINT timeout, PDWORD_PTR res_ptr )
2385 struct send_message_info info;
2386 DWORD dest_tid, dest_pid;
2387 LRESULT ret, result;
2389 info.type = MSG_ASCII;
2392 info.wparam = wparam;
2393 info.lparam = lparam;
2395 info.timeout = timeout;
2397 if (is_broadcast(hwnd))
2399 EnumWindows( broadcast_message_callback, (LPARAM)&info );
2400 if (res_ptr) *res_ptr = 1;
2404 if (!(dest_tid = GetWindowThreadProcessId( hwnd, &dest_pid ))) return 0;
2406 if (USER_IsExitingThread( dest_tid )) return 0;
2408 SPY_EnterMessage( SPY_SENDMESSAGE, hwnd, msg, wparam, lparam );
2410 if (dest_tid == GetCurrentThreadId())
2412 result = call_window_proc( hwnd, msg, wparam, lparam, FALSE, TRUE );
2415 else if (dest_pid == GetCurrentProcessId())
2417 ret = send_inter_thread_message( dest_tid, &info, &result );
2421 /* inter-process message: need to map to Unicode */
2422 info.type = MSG_OTHER_PROCESS;
2423 if (is_unicode_message( info.msg ))
2425 if (WINPROC_MapMsg32ATo32W( info.hwnd, info.msg, &info.wparam, &info.lparam ) == -1)
2427 ret = send_inter_thread_message( dest_tid, &info, &result );
2428 result = WINPROC_UnmapMsg32ATo32W( info.hwnd, info.msg, info.wparam,
2429 info.lparam, result, NULL );
2431 else ret = send_inter_thread_message( dest_tid, &info, &result );
2433 SPY_ExitMessage( SPY_RESULT_OK, hwnd, msg, result, wparam, lparam );
2434 if (ret && res_ptr) *res_ptr = result;
2439 /***********************************************************************
2440 * SendMessageW (USER32.@)
2442 LRESULT WINAPI SendMessageW( HWND hwnd, UINT msg, WPARAM wparam, LPARAM lparam )
2445 SendMessageTimeoutW( hwnd, msg, wparam, lparam, SMTO_NORMAL, 0, &res );
2450 /***********************************************************************
2451 * SendMessageA (USER32.@)
2453 LRESULT WINAPI SendMessageA( HWND hwnd, UINT msg, WPARAM wparam, LPARAM lparam )
2456 SendMessageTimeoutA( hwnd, msg, wparam, lparam, SMTO_NORMAL, 0, &res );
2461 /***********************************************************************
2462 * SendNotifyMessageA (USER32.@)
2464 BOOL WINAPI SendNotifyMessageA( HWND hwnd, UINT msg, WPARAM wparam, LPARAM lparam )
2466 return SendNotifyMessageW( hwnd, msg, map_wparam_AtoW( msg, wparam ), lparam );
2470 /***********************************************************************
2471 * SendNotifyMessageW (USER32.@)
2473 BOOL WINAPI SendNotifyMessageW( HWND hwnd, UINT msg, WPARAM wparam, LPARAM lparam )
2475 struct send_message_info info;
2479 if (is_pointer_message(msg))
2481 SetLastError( ERROR_MESSAGE_SYNC_ONLY );
2485 info.type = MSG_NOTIFY;
2488 info.wparam = wparam;
2489 info.lparam = lparam;
2492 if (is_broadcast(hwnd))
2494 EnumWindows( broadcast_message_callback, (LPARAM)&info );
2498 if (!(dest_tid = GetWindowThreadProcessId( hwnd, NULL ))) return FALSE;
2500 if (USER_IsExitingThread( dest_tid )) return TRUE;
2502 if (dest_tid == GetCurrentThreadId())
2504 call_window_proc( hwnd, msg, wparam, lparam, TRUE, TRUE );
2507 return send_inter_thread_message( dest_tid, &info, &result );
2511 /***********************************************************************
2512 * SendMessageCallbackA (USER32.@)
2514 BOOL WINAPI SendMessageCallbackA( HWND hwnd, UINT msg, WPARAM wparam, LPARAM lparam,
2515 SENDASYNCPROC callback, ULONG_PTR data )
2517 return SendMessageCallbackW( hwnd, msg, map_wparam_AtoW( msg, wparam ),
2518 lparam, callback, data );
2522 /***********************************************************************
2523 * SendMessageCallbackW (USER32.@)
2525 BOOL WINAPI SendMessageCallbackW( HWND hwnd, UINT msg, WPARAM wparam, LPARAM lparam,
2526 SENDASYNCPROC callback, ULONG_PTR data )
2528 struct send_message_info info;
2532 if (is_pointer_message(msg))
2534 SetLastError( ERROR_MESSAGE_SYNC_ONLY );
2538 info.type = MSG_CALLBACK;
2541 info.wparam = wparam;
2542 info.lparam = lparam;
2543 info.callback = callback;
2547 if (is_broadcast(hwnd))
2549 EnumWindows( broadcast_message_callback, (LPARAM)&info );
2553 if (!(dest_tid = GetWindowThreadProcessId( hwnd, NULL ))) return FALSE;
2555 if (USER_IsExitingThread( dest_tid )) return TRUE;
2557 if (dest_tid == GetCurrentThreadId())
2559 result = call_window_proc( hwnd, msg, wparam, lparam, TRUE, TRUE );
2560 call_sendmsg_callback( callback, hwnd, msg, data, result );
2563 FIXME( "callback will not be called\n" );
2564 return send_inter_thread_message( dest_tid, &info, &result );
2568 /***********************************************************************
2569 * ReplyMessage (USER32.@)
2571 BOOL WINAPI ReplyMessage( LRESULT result )
2573 struct received_message_info *info = get_user_thread_info()->receive_info;
2575 if (!info) return FALSE;
2576 reply_message( info, result, FALSE );
2581 /***********************************************************************
2582 * InSendMessage (USER32.@)
2584 BOOL WINAPI InSendMessage(void)
2586 return (InSendMessageEx(NULL) & (ISMEX_SEND|ISMEX_REPLIED)) == ISMEX_SEND;
2590 /***********************************************************************
2591 * InSendMessageEx (USER32.@)
2593 DWORD WINAPI InSendMessageEx( LPVOID reserved )
2595 struct received_message_info *info = get_user_thread_info()->receive_info;
2597 if (info) return info->flags;
2598 return ISMEX_NOSEND;
2602 /***********************************************************************
2603 * PostMessageA (USER32.@)
2605 BOOL WINAPI PostMessageA( HWND hwnd, UINT msg, WPARAM wparam, LPARAM lparam )
2607 return PostMessageW( hwnd, msg, map_wparam_AtoW( msg, wparam ), lparam );
2611 /***********************************************************************
2612 * PostMessageW (USER32.@)
2614 BOOL WINAPI PostMessageW( HWND hwnd, UINT msg, WPARAM wparam, LPARAM lparam )
2616 struct send_message_info info;
2619 if (is_pointer_message( msg ))
2621 SetLastError( ERROR_MESSAGE_SYNC_ONLY );
2625 TRACE( "hwnd %p msg %x (%s) wp %x lp %lx\n",
2626 hwnd, msg, SPY_GetMsgName(msg, hwnd), wparam, lparam );
2628 info.type = MSG_POSTED;
2631 info.wparam = wparam;
2632 info.lparam = lparam;
2635 if (is_broadcast(hwnd))
2637 EnumWindows( broadcast_message_callback, (LPARAM)&info );
2641 if (!hwnd) return PostThreadMessageW( GetCurrentThreadId(), msg, wparam, lparam );
2643 if (!(dest_tid = GetWindowThreadProcessId( hwnd, NULL ))) return FALSE;
2645 if (USER_IsExitingThread( dest_tid )) return TRUE;
2647 return put_message_in_queue( dest_tid, &info, NULL );
2651 /**********************************************************************
2652 * PostThreadMessageA (USER32.@)
2654 BOOL WINAPI PostThreadMessageA( DWORD thread, UINT msg, WPARAM wparam, LPARAM lparam )
2656 return PostThreadMessageW( thread, msg, map_wparam_AtoW( msg, wparam ), lparam );
2660 /**********************************************************************
2661 * PostThreadMessageW (USER32.@)
2663 BOOL WINAPI PostThreadMessageW( DWORD thread, UINT msg, WPARAM wparam, LPARAM lparam )
2665 struct send_message_info info;
2667 if (is_pointer_message( msg ))
2669 SetLastError( ERROR_MESSAGE_SYNC_ONLY );
2672 if (USER_IsExitingThread( thread )) return TRUE;
2674 info.type = MSG_POSTED;
2677 info.wparam = wparam;
2678 info.lparam = lparam;
2680 return put_message_in_queue( thread, &info, NULL );
2684 /***********************************************************************
2685 * PostQuitMessage (USER32.@)
2687 * Posts a quit message to the current thread's message queue.
2690 * exit_code [I] Exit code to return from message loop.
2696 * This function is not the same as calling:
2697 *|PostThreadMessage(GetCurrentThreadId(), WM_QUIT, exit_code, 0);
2698 * It instead sets a flag in the message queue that signals it to generate
2699 * a WM_QUIT message when there are no other pending sent or posted messages
2702 void WINAPI PostQuitMessage( INT exit_code )
2704 SERVER_START_REQ( post_quit_message )
2706 req->exit_code = exit_code;
2707 wine_server_call( req );
2713 /***********************************************************************
2714 * PeekMessageW (USER32.@)
2716 BOOL WINAPI PeekMessageW( MSG *msg_out, HWND hwnd, UINT first, UINT last, UINT flags )
2718 struct user_thread_info *thread_info = get_user_thread_info();
2722 FIXME("PM_QS_xxxx flags (%04x) are not handled\n", flags >> 16);
2724 USER_CheckNotLock();
2726 /* check for graphics events */
2727 USER_Driver->pMsgWaitForMultipleObjectsEx( 0, NULL, 0, QS_ALLINPUT, 0 );
2729 hwnd = WIN_GetFullHandle( hwnd );
2733 if (!peek_message( &msg, hwnd, first, last, (flags & PM_REMOVE) ? GET_MSG_REMOVE : 0 ))
2735 if (!(flags & PM_NOYIELD))
2738 ReleaseThunkLock(&count);
2740 if (count) RestoreThunkLock(count);
2744 if (msg.message & 0x80000000)
2746 if (!(flags & PM_REMOVE))
2748 /* Have to remove the message explicitly.
2749 Do this before handling it, because the message handler may
2750 call PeekMessage again */
2751 peek_message( &msg, msg.hwnd, msg.message, msg.message, GET_MSG_REMOVE );
2753 handle_internal_message( msg.hwnd, msg.message, msg.wParam, msg.lParam );
2758 thread_info->GetMessageTimeVal = msg.time;
2759 msg.pt.x = LOWORD( thread_info->GetMessagePosVal );
2760 msg.pt.y = HIWORD( thread_info->GetMessagePosVal );
2762 HOOK_CallHooks( WH_GETMESSAGE, HC_ACTION, flags & PM_REMOVE, (LPARAM)&msg, TRUE );
2764 /* copy back our internal safe copy of message data to msg_out.
2765 * msg_out is a variable from the *program*, so it can't be used
2766 * internally as it can get "corrupted" by our use of SendMessage()
2767 * (back to the program) inside the message handling itself. */
2770 SetLastError( ERROR_NOACCESS );
2778 /***********************************************************************
2779 * PeekMessageA (USER32.@)
2781 BOOL WINAPI PeekMessageA( MSG *msg, HWND hwnd, UINT first, UINT last, UINT flags )
2783 BOOL ret = PeekMessageW( msg, hwnd, first, last, flags );
2784 if (ret) msg->wParam = map_wparam_WtoA( msg->message, msg->wParam );
2789 /***********************************************************************
2790 * GetMessageW (USER32.@)
2792 BOOL WINAPI GetMessageW( MSG *msg, HWND hwnd, UINT first, UINT last )
2794 HANDLE server_queue = get_server_queue_handle();
2795 int mask = QS_POSTMESSAGE | QS_SENDMESSAGE; /* Always selected */
2799 if ((first <= WM_KEYLAST) && (last >= WM_KEYFIRST)) mask |= QS_KEY;
2800 if ( ((first <= WM_MOUSELAST) && (last >= WM_MOUSEFIRST)) ||
2801 ((first <= WM_NCMOUSELAST) && (last >= WM_NCMOUSEFIRST)) ) mask |= QS_MOUSE;
2802 if ((first <= WM_TIMER) && (last >= WM_TIMER)) mask |= QS_TIMER;
2803 if ((first <= WM_SYSTIMER) && (last >= WM_SYSTIMER)) mask |= QS_TIMER;
2804 if ((first <= WM_PAINT) && (last >= WM_PAINT)) mask |= QS_PAINT;
2806 else mask |= QS_MOUSE | QS_KEY | QS_TIMER | QS_PAINT;
2808 while (!PeekMessageW( msg, hwnd, first, last, PM_REMOVE ))
2810 /* wait until one of the bits is set */
2811 unsigned int wake_bits = 0, changed_bits = 0;
2814 SERVER_START_REQ( set_queue_mask )
2816 req->wake_mask = QS_SENDMESSAGE;
2817 req->changed_mask = mask;
2819 if (!wine_server_call( req ))
2821 wake_bits = reply->wake_bits;
2822 changed_bits = reply->changed_bits;
2827 if (changed_bits & mask) continue;
2828 if (wake_bits & QS_SENDMESSAGE) continue;
2830 TRACE( "(%04lx) mask=%08x, bits=%08x, changed=%08x, waiting\n",
2831 GetCurrentThreadId(), mask, wake_bits, changed_bits );
2833 ReleaseThunkLock( &dwlc );
2834 USER_Driver->pMsgWaitForMultipleObjectsEx( 1, &server_queue, INFINITE, QS_ALLINPUT, 0 );
2835 if (dwlc) RestoreThunkLock( dwlc );
2838 return (msg->message != WM_QUIT);
2842 /***********************************************************************
2843 * GetMessageA (USER32.@)
2845 BOOL WINAPI GetMessageA( MSG *msg, HWND hwnd, UINT first, UINT last )
2847 GetMessageW( msg, hwnd, first, last );
2848 msg->wParam = map_wparam_WtoA( msg->message, msg->wParam );
2849 return (msg->message != WM_QUIT);
2853 /***********************************************************************
2854 * IsDialogMessageA (USER32.@)
2855 * IsDialogMessage (USER32.@)
2857 BOOL WINAPI IsDialogMessageA( HWND hwndDlg, LPMSG pmsg )
2860 msg.wParam = map_wparam_AtoW( msg.message, msg.wParam );
2861 return IsDialogMessageW( hwndDlg, &msg );
2865 /***********************************************************************
2866 * TranslateMessage (USER32.@)
2868 * Implementation of TranslateMessage.
2870 * TranslateMessage translates virtual-key messages into character-messages,
2872 * WM_KEYDOWN/WM_KEYUP combinations produce a WM_CHAR or WM_DEADCHAR message.
2873 * ditto replacing WM_* with WM_SYS*
2874 * This produces WM_CHAR messages only for keys mapped to ASCII characters
2875 * by the keyboard driver.
2877 * If the message is WM_KEYDOWN, WM_KEYUP, WM_SYSKEYDOWN, or WM_SYSKEYUP, the
2878 * return value is nonzero, regardless of the translation.
2881 BOOL WINAPI TranslateMessage( const MSG *msg )
2887 if (msg->message < WM_KEYFIRST || msg->message > WM_KEYLAST) return FALSE;
2888 if (msg->message != WM_KEYDOWN && msg->message != WM_SYSKEYDOWN) return TRUE;
2890 TRACE_(key)("Translating key %s (%04x), scancode %02x\n",
2891 SPY_GetVKeyName(msg->wParam), msg->wParam, LOBYTE(HIWORD(msg->lParam)));
2893 GetKeyboardState( state );
2894 /* FIXME : should handle ToUnicode yielding 2 */
2895 switch (ToUnicode(msg->wParam, HIWORD(msg->lParam), state, wp, 2, 0))
2898 message = (msg->message == WM_KEYDOWN) ? WM_CHAR : WM_SYSCHAR;
2899 TRACE_(key)("1 -> PostMessageW(%p,%s,%04x,%08lx)\n",
2900 msg->hwnd, SPY_GetMsgName(message, msg->hwnd), wp[0], msg->lParam);
2901 PostMessageW( msg->hwnd, message, wp[0], msg->lParam );
2905 message = (msg->message == WM_KEYDOWN) ? WM_DEADCHAR : WM_SYSDEADCHAR;
2906 TRACE_(key)("-1 -> PostMessageW(%p,%s,%04x,%08lx)\n",
2907 msg->hwnd, SPY_GetMsgName(message, msg->hwnd), wp[0], msg->lParam);
2908 PostMessageW( msg->hwnd, message, wp[0], msg->lParam );
2915 /***********************************************************************
2916 * DispatchMessageA (USER32.@)
2918 * See DispatchMessageW.
2920 LONG WINAPI DispatchMessageA( const MSG* msg )
2926 /* Process timer messages */
2927 if ((msg->message == WM_TIMER) || (msg->message == WM_SYSTIMER))
2929 if (msg->lParam) return CallWindowProcA( (WNDPROC)msg->lParam, msg->hwnd,
2930 msg->message, msg->wParam, GetTickCount() );
2933 if (!(wndPtr = WIN_GetPtr( msg->hwnd )))
2935 if (msg->hwnd) SetLastError( ERROR_INVALID_WINDOW_HANDLE );
2938 if (wndPtr == WND_OTHER_PROCESS || wndPtr == WND_DESKTOP)
2940 if (IsWindow( msg->hwnd )) SetLastError( ERROR_MESSAGE_SYNC_ONLY );
2941 else SetLastError( ERROR_INVALID_WINDOW_HANDLE );
2944 if (wndPtr->tid != GetCurrentThreadId())
2946 SetLastError( ERROR_MESSAGE_SYNC_ONLY );
2947 WIN_ReleasePtr( wndPtr );
2950 winproc = wndPtr->winproc;
2951 WIN_ReleasePtr( wndPtr );
2953 SPY_EnterMessage( SPY_DISPATCHMESSAGE, msg->hwnd, msg->message,
2954 msg->wParam, msg->lParam );
2955 retval = CallWindowProcA( winproc, msg->hwnd, msg->message,
2956 msg->wParam, msg->lParam );
2957 SPY_ExitMessage( SPY_RESULT_OK, msg->hwnd, msg->message, retval,
2958 msg->wParam, msg->lParam );
2960 if (msg->message == WM_PAINT)
2962 /* send a WM_NCPAINT and WM_ERASEBKGND if the non-client area is still invalid */
2963 HRGN hrgn = CreateRectRgn( 0, 0, 0, 0 );
2964 GetUpdateRgn( msg->hwnd, hrgn, TRUE );
2965 DeleteObject( hrgn );
2971 /***********************************************************************
2972 * DispatchMessageW (USER32.@) Process a message
2974 * Process the message specified in the structure *_msg_.
2976 * If the lpMsg parameter points to a WM_TIMER message and the
2977 * parameter of the WM_TIMER message is not NULL, the lParam parameter
2978 * points to the function that is called instead of the window
2981 * The message must be valid.
2985 * DispatchMessage() returns the result of the window procedure invoked.
2992 LONG WINAPI DispatchMessageW( const MSG* msg )
2998 /* Process timer messages */
2999 if ((msg->message == WM_TIMER) || (msg->message == WM_SYSTIMER))
3001 if (msg->lParam) return CallWindowProcW( (WNDPROC)msg->lParam, msg->hwnd,
3002 msg->message, msg->wParam, GetTickCount() );
3005 if (!(wndPtr = WIN_GetPtr( msg->hwnd )))
3007 if (msg->hwnd) SetLastError( ERROR_INVALID_WINDOW_HANDLE );
3010 if (wndPtr == WND_OTHER_PROCESS || wndPtr == WND_DESKTOP)
3012 if (IsWindow( msg->hwnd )) SetLastError( ERROR_MESSAGE_SYNC_ONLY );
3013 else SetLastError( ERROR_INVALID_WINDOW_HANDLE );
3016 if (wndPtr->tid != GetCurrentThreadId())
3018 SetLastError( ERROR_MESSAGE_SYNC_ONLY );
3019 WIN_ReleasePtr( wndPtr );
3022 winproc = wndPtr->winproc;
3023 WIN_ReleasePtr( wndPtr );
3025 SPY_EnterMessage( SPY_DISPATCHMESSAGE, msg->hwnd, msg->message,
3026 msg->wParam, msg->lParam );
3027 retval = CallWindowProcW( winproc, msg->hwnd, msg->message,
3028 msg->wParam, msg->lParam );
3029 SPY_ExitMessage( SPY_RESULT_OK, msg->hwnd, msg->message, retval,
3030 msg->wParam, msg->lParam );
3032 if (msg->message == WM_PAINT)
3034 /* send a WM_NCPAINT and WM_ERASEBKGND if the non-client area is still invalid */
3035 HRGN hrgn = CreateRectRgn( 0, 0, 0, 0 );
3036 GetUpdateRgn( msg->hwnd, hrgn, TRUE );
3037 DeleteObject( hrgn );
3043 /***********************************************************************
3044 * GetMessagePos (USER.119)
3045 * GetMessagePos (USER32.@)
3047 * The GetMessagePos() function returns a long value representing a
3048 * cursor position, in screen coordinates, when the last message
3049 * retrieved by the GetMessage() function occurs. The x-coordinate is
3050 * in the low-order word of the return value, the y-coordinate is in
3051 * the high-order word. The application can use the MAKEPOINT()
3052 * macro to obtain a POINT structure from the return value.
3054 * For the current cursor position, use GetCursorPos().
3058 * Cursor position of last message on success, zero on failure.
3065 DWORD WINAPI GetMessagePos(void)
3067 return get_user_thread_info()->GetMessagePosVal;
3071 /***********************************************************************
3072 * GetMessageTime (USER.120)
3073 * GetMessageTime (USER32.@)
3075 * GetMessageTime() returns the message time for the last message
3076 * retrieved by the function. The time is measured in milliseconds with
3077 * the same offset as GetTickCount().
3079 * Since the tick count wraps, this is only useful for moderately short
3080 * relative time comparisons.
3084 * Time of last message on success, zero on failure.
3086 LONG WINAPI GetMessageTime(void)
3088 return get_user_thread_info()->GetMessageTimeVal;
3092 /***********************************************************************
3093 * GetMessageExtraInfo (USER.288)
3094 * GetMessageExtraInfo (USER32.@)
3096 LPARAM WINAPI GetMessageExtraInfo(void)
3098 return get_user_thread_info()->GetMessageExtraInfoVal;
3102 /***********************************************************************
3103 * SetMessageExtraInfo (USER32.@)
3105 LPARAM WINAPI SetMessageExtraInfo(LPARAM lParam)
3107 struct user_thread_info *thread_info = get_user_thread_info();
3108 LONG old_value = thread_info->GetMessageExtraInfoVal;
3109 thread_info->GetMessageExtraInfoVal = lParam;
3114 /***********************************************************************
3115 * WaitMessage (USER.112) Suspend thread pending messages
3116 * WaitMessage (USER32.@) Suspend thread pending messages
3118 * WaitMessage() suspends a thread until events appear in the thread's
3121 BOOL WINAPI WaitMessage(void)
3123 return (MsgWaitForMultipleObjectsEx( 0, NULL, INFINITE, QS_ALLINPUT, 0 ) != WAIT_FAILED);
3127 /***********************************************************************
3128 * MsgWaitForMultipleObjectsEx (USER32.@)
3130 DWORD WINAPI MsgWaitForMultipleObjectsEx( DWORD count, CONST HANDLE *pHandles,
3131 DWORD timeout, DWORD mask, DWORD flags )
3133 HANDLE handles[MAXIMUM_WAIT_OBJECTS];
3136 if (count > MAXIMUM_WAIT_OBJECTS-1)
3138 SetLastError( ERROR_INVALID_PARAMETER );
3142 /* set the queue mask */
3143 SERVER_START_REQ( set_queue_mask )
3145 req->wake_mask = (flags & MWMO_INPUTAVAILABLE) ? mask : 0;
3146 req->changed_mask = mask;
3148 wine_server_call( req );
3152 /* Add the thread event to the handle list */
3153 for (i = 0; i < count; i++) handles[i] = pHandles[i];
3154 handles[count] = get_server_queue_handle();
3156 ReleaseThunkLock( &lock );
3157 ret = USER_Driver->pMsgWaitForMultipleObjectsEx( count+1, handles, timeout, mask, flags );
3158 if (ret == count+1) ret = count; /* pretend the msg queue is ready */
3159 if (lock) RestoreThunkLock( lock );
3164 /***********************************************************************
3165 * MsgWaitForMultipleObjects (USER32.@)
3167 DWORD WINAPI MsgWaitForMultipleObjects( DWORD count, CONST HANDLE *handles,
3168 BOOL wait_all, DWORD timeout, DWORD mask )
3170 return MsgWaitForMultipleObjectsEx( count, handles, timeout, mask,
3171 wait_all ? MWMO_WAITALL : 0 );
3175 /***********************************************************************
3176 * WaitForInputIdle (USER32.@)
3178 DWORD WINAPI WaitForInputIdle( HANDLE hProcess, DWORD dwTimeOut )
3180 DWORD start_time, elapsed, ret;
3181 HANDLE idle_event = (HANDLE)-1;
3183 SERVER_START_REQ( wait_input_idle )
3185 req->handle = hProcess;
3186 req->timeout = dwTimeOut;
3187 if (!(ret = wine_server_call_err( req ))) idle_event = reply->event;
3190 if (ret) return WAIT_FAILED; /* error */
3191 if (!idle_event) return 0; /* no event to wait on */
3193 start_time = GetTickCount();
3196 TRACE("waiting for %p\n", idle_event );
3199 ret = MsgWaitForMultipleObjects ( 1, &idle_event, FALSE, dwTimeOut - elapsed, QS_SENDMESSAGE );
3202 case WAIT_OBJECT_0+1:
3203 process_sent_messages();
3207 TRACE("timeout or error\n");
3210 TRACE("finished\n");
3213 if (dwTimeOut != INFINITE)
3215 elapsed = GetTickCount() - start_time;
3216 if (elapsed > dwTimeOut)
3222 return WAIT_TIMEOUT;
3226 /***********************************************************************
3227 * UserYield (USER.332)
3229 void WINAPI UserYield16(void)
3233 /* Handle sent messages */
3234 process_sent_messages();
3237 ReleaseThunkLock(&count);
3241 RestoreThunkLock(count);
3242 /* Handle sent messages again */
3243 process_sent_messages();
3248 /***********************************************************************
3249 * RegisterWindowMessageA (USER32.@)
3250 * RegisterWindowMessage (USER.118)
3252 UINT WINAPI RegisterWindowMessageA( LPCSTR str )
3254 UINT ret = GlobalAddAtomA(str);
3255 TRACE("%s, ret=%x\n", str, ret);
3260 /***********************************************************************
3261 * RegisterWindowMessageW (USER32.@)
3263 UINT WINAPI RegisterWindowMessageW( LPCWSTR str )
3265 UINT ret = GlobalAddAtomW(str);
3266 TRACE("%s ret=%x\n", debugstr_w(str), ret);
3271 /***********************************************************************
3272 * BroadcastSystemMessageA (USER32.@)
3273 * BroadcastSystemMessage (USER32.@)
3275 LONG WINAPI BroadcastSystemMessageA( DWORD flags, LPDWORD recipients, UINT msg, WPARAM wp, LPARAM lp )
3277 if ((*recipients & BSM_APPLICATIONS) || (*recipients == BSM_ALLCOMPONENTS))
3279 FIXME( "(%08lx,%08lx,%08x,%08x,%08lx): semi-stub!\n", flags, *recipients, msg, wp, lp );
3280 PostMessageA( HWND_BROADCAST, msg, wp, lp );
3285 FIXME( "(%08lx,%08lx,%08x,%08x,%08lx): stub!\n", flags, *recipients, msg, wp, lp);
3291 /***********************************************************************
3292 * BroadcastSystemMessageW (USER32.@)
3294 LONG WINAPI BroadcastSystemMessageW( DWORD flags, LPDWORD recipients, UINT msg, WPARAM wp, LPARAM lp )
3296 if ((*recipients & BSM_APPLICATIONS) || (*recipients == BSM_ALLCOMPONENTS))
3298 FIXME( "(%08lx,%08lx,%08x,%08x,%08lx): semi-stub!\n", flags, *recipients, msg, wp, lp );
3299 PostMessageW( HWND_BROADCAST, msg, wp, lp );
3304 FIXME( "(%08lx,%08lx,%08x,%08x,%08lx): stub!\n", flags, *recipients, msg, wp, lp );
3310 /***********************************************************************
3311 * SetMessageQueue (USER32.@)
3313 BOOL WINAPI SetMessageQueue( INT size )
3315 /* now obsolete the message queue will be expanded dynamically as necessary */
3320 /***********************************************************************
3321 * MessageBeep (USER32.@)
3323 BOOL WINAPI MessageBeep( UINT i )
3326 SystemParametersInfoA( SPI_GETBEEP, 0, &active, FALSE );
3327 if (active) USER_Driver->pBeep();
3332 /***********************************************************************
3333 * SetTimer (USER32.@)
3335 UINT_PTR WINAPI SetTimer( HWND hwnd, UINT_PTR id, UINT timeout, TIMERPROC proc )
3338 WNDPROC winproc = 0;
3340 if (proc) winproc = WINPROC_AllocProc( (WNDPROC)proc, WIN_PROC_32A );
3342 SERVER_START_REQ( set_win_timer )
3345 req->msg = WM_TIMER;
3347 req->rate = max( timeout, SYS_TIMER_RATE );
3348 req->lparam = (unsigned int)winproc;
3349 if (!wine_server_call_err( req ))
3352 if (!ret) ret = TRUE;
3358 TRACE("Added %p %x %p timeout %d\n", hwnd, id, winproc, timeout );
3363 /***********************************************************************
3364 * SetSystemTimer (USER32.@)
3366 UINT_PTR WINAPI SetSystemTimer( HWND hwnd, UINT_PTR id, UINT timeout, TIMERPROC proc )
3369 WNDPROC winproc = 0;
3371 if (proc) winproc = WINPROC_AllocProc( (WNDPROC)proc, WIN_PROC_32A );
3373 SERVER_START_REQ( set_win_timer )
3376 req->msg = WM_SYSTIMER;
3378 req->rate = max( timeout, SYS_TIMER_RATE );
3379 req->lparam = (unsigned int)winproc;
3380 if (!wine_server_call_err( req ))
3383 if (!ret) ret = TRUE;
3389 TRACE("Added %p %x %p timeout %d\n", hwnd, id, winproc, timeout );
3394 /***********************************************************************
3395 * KillTimer (USER32.@)
3397 BOOL WINAPI KillTimer( HWND hwnd, UINT_PTR id )
3401 TRACE("%p %d\n", hwnd, id );
3403 SERVER_START_REQ( kill_win_timer )
3406 req->msg = WM_TIMER;
3408 ret = !wine_server_call_err( req );
3415 /***********************************************************************
3416 * KillSystemTimer (USER32.@)
3418 BOOL WINAPI KillSystemTimer( HWND hwnd, UINT_PTR id )
3422 TRACE("%p %d\n", hwnd, id );
3424 SERVER_START_REQ( kill_win_timer )
3427 req->msg = WM_SYSTIMER;
3429 ret = !wine_server_call_err( req );
3436 /**********************************************************************
3437 * GetGUIThreadInfo (USER32.@)
3439 BOOL WINAPI GetGUIThreadInfo( DWORD id, GUITHREADINFO *info )
3443 SERVER_START_REQ( get_thread_input )
3446 if ((ret = !wine_server_call_err( req )))
3449 info->hwndActive = reply->active;
3450 info->hwndFocus = reply->focus;
3451 info->hwndCapture = reply->capture;
3452 info->hwndMenuOwner = reply->menu_owner;
3453 info->hwndMoveSize = reply->move_size;
3454 info->hwndCaret = reply->caret;
3455 info->rcCaret.left = reply->rect.left;
3456 info->rcCaret.top = reply->rect.top;
3457 info->rcCaret.right = reply->rect.right;
3458 info->rcCaret.bottom = reply->rect.bottom;
3459 if (reply->menu_owner) info->flags |= GUI_INMENUMODE;
3460 if (reply->move_size) info->flags |= GUI_INMOVESIZE;
3461 if (reply->caret) info->flags |= GUI_CARETBLINKING;
3469 /******************************************************************
3470 * IsHungAppWindow (USER32.@)
3473 BOOL WINAPI IsHungAppWindow( HWND hWnd )
3476 return !SendMessageTimeoutA(hWnd, WM_NULL, 0, 0, SMTO_ABORTIFHUNG, 5000, &dwResult);