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;
85 UINT flags; /* flags for SendMessageTimeout */
86 UINT timeout; /* timeout for SendMessageTimeout */
87 SENDASYNCPROC callback; /* callback function for SendMessageCallback */
88 ULONG_PTR data; /* callback data */
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 inline static 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 inline static 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 inline static 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 inline static 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 inline static 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 inline static 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 inline static 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 /* retrieve a string pointer from packed data */
280 inline static LPWSTR get_string( void **buffer )
282 return get_data( buffer, (strlenW( (LPWSTR)*buffer ) + 1) * sizeof(WCHAR) );
285 /* check whether a combobox expects strings or ids in CB_ADDSTRING/CB_INSERTSTRING */
286 inline static BOOL combobox_has_strings( HWND hwnd )
288 DWORD style = GetWindowLongA( hwnd, GWL_STYLE );
289 return (!(style & (CBS_OWNERDRAWFIXED | CBS_OWNERDRAWVARIABLE)) || (style & CBS_HASSTRINGS));
292 /* check whether a listbox expects strings or ids in LB_ADDSTRING/LB_INSERTSTRING */
293 inline static BOOL listbox_has_strings( HWND hwnd )
295 DWORD style = GetWindowLongA( hwnd, GWL_STYLE );
296 return (!(style & (LBS_OWNERDRAWFIXED | LBS_OWNERDRAWVARIABLE)) || (style & LBS_HASSTRINGS));
299 /* check whether message is in the range of keyboard messages */
300 inline static BOOL is_keyboard_message( UINT message )
302 return (message >= WM_KEYFIRST && message <= WM_KEYLAST);
305 /* check whether message is in the range of mouse messages */
306 inline static BOOL is_mouse_message( UINT message )
308 return ((message >= WM_NCMOUSEFIRST && message <= WM_NCMOUSELAST) ||
309 (message >= WM_MOUSEFIRST && message <= WM_MOUSELAST));
312 /* check whether message matches the specified hwnd filter */
313 inline static BOOL check_hwnd_filter( const MSG *msg, HWND hwnd_filter )
315 if (!hwnd_filter) return TRUE;
316 return (msg->hwnd == hwnd_filter || IsChild( hwnd_filter, msg->hwnd ));
320 /***********************************************************************
321 * broadcast_message_callback
323 * Helper callback for broadcasting messages.
325 static BOOL CALLBACK broadcast_message_callback( HWND hwnd, LPARAM lparam )
327 struct send_message_info *info = (struct send_message_info *)lparam;
328 if (!(GetWindowLongW( hwnd, GWL_STYLE ) & (WS_POPUP|WS_CAPTION))) return TRUE;
332 SendMessageTimeoutW( hwnd, info->msg, info->wparam, info->lparam,
333 info->flags, info->timeout, NULL );
336 SendMessageTimeoutA( hwnd, info->msg, info->wparam, info->lparam,
337 info->flags, info->timeout, NULL );
340 SendNotifyMessageW( hwnd, info->msg, info->wparam, info->lparam );
343 SendMessageCallbackW( hwnd, info->msg, info->wparam, info->lparam,
344 info->callback, info->data );
347 PostMessageW( hwnd, info->msg, info->wparam, info->lparam );
350 ERR( "bad type %d\n", info->type );
357 /***********************************************************************
360 * Convert the wparam of an ASCII message to Unicode.
362 static WPARAM map_wparam_AtoW( UINT message, WPARAM wparam )
367 case EM_SETPASSWORDCHAR:
376 ch[0] = (wparam & 0xff);
377 ch[1] = (wparam >> 8);
378 MultiByteToWideChar(CP_ACP, 0, ch, 2, wch, 2);
379 wparam = MAKEWPARAM(wch[0], wch[1]);
386 ch[0] = (wparam >> 8);
387 ch[1] = (wparam & 0xff);
388 if (ch[0]) MultiByteToWideChar(CP_ACP, 0, ch, 2, &wch, 1);
389 else MultiByteToWideChar(CP_ACP, 0, &ch[1], 1, &wch, 1);
390 wparam = MAKEWPARAM( wch, HIWORD(wparam) );
398 /***********************************************************************
401 * Convert the wparam of a Unicode message to ASCII.
403 static WPARAM map_wparam_WtoA( UINT message, WPARAM wparam )
408 case EM_SETPASSWORDCHAR:
417 wch[0] = LOWORD(wparam);
418 wch[1] = HIWORD(wparam);
419 WideCharToMultiByte( CP_ACP, 0, wch, 2, (LPSTR)ch, 2, NULL, NULL );
420 wparam = MAKEWPARAM( ch[0] | (ch[1] << 8), 0 );
425 WCHAR wch = LOWORD(wparam);
428 if (WideCharToMultiByte( CP_ACP, 0, &wch, 1, (LPSTR)ch, 2, NULL, NULL ) == 2)
429 wparam = MAKEWPARAM( (ch[0] << 8) | ch[1], HIWORD(wparam) );
431 wparam = MAKEWPARAM( ch[0], HIWORD(wparam) );
439 /***********************************************************************
442 * Pack a message for sending to another process.
443 * Return the size of the data we expect in the message reply.
444 * Set data->count to -1 if there is an error.
446 static size_t pack_message( HWND hwnd, UINT message, WPARAM wparam, LPARAM lparam,
447 struct packed_message *data )
455 CREATESTRUCTW *cs = (CREATESTRUCTW *)lparam;
456 push_data( data, cs, sizeof(*cs) );
457 if (HIWORD(cs->lpszName)) push_string( data, cs->lpszName );
458 if (HIWORD(cs->lpszClass)) push_string( data, cs->lpszClass );
462 case WM_ASKCBFORMATNAME:
463 return wparam * sizeof(WCHAR);
464 case WM_WININICHANGE:
465 if (lparam) push_string(data, (LPWSTR)lparam );
468 case WM_DEVMODECHANGE:
473 push_string( data, (LPWSTR)lparam );
475 case WM_GETMINMAXINFO:
476 push_data( data, (MINMAXINFO *)lparam, sizeof(MINMAXINFO) );
477 return sizeof(MINMAXINFO);
479 push_data( data, (DRAWITEMSTRUCT *)lparam, sizeof(DRAWITEMSTRUCT) );
482 push_data( data, (MEASUREITEMSTRUCT *)lparam, sizeof(MEASUREITEMSTRUCT) );
483 return sizeof(MEASUREITEMSTRUCT);
485 push_data( data, (DELETEITEMSTRUCT *)lparam, sizeof(DELETEITEMSTRUCT) );
488 push_data( data, (COMPAREITEMSTRUCT *)lparam, sizeof(COMPAREITEMSTRUCT) );
490 case WM_WINDOWPOSCHANGING:
491 case WM_WINDOWPOSCHANGED:
492 push_data( data, (WINDOWPOS *)lparam, sizeof(WINDOWPOS) );
493 return sizeof(WINDOWPOS);
496 COPYDATASTRUCT *cp = (COPYDATASTRUCT *)lparam;
497 push_data( data, cp, sizeof(*cp) );
498 if (cp->lpData) push_data( data, cp->lpData, cp->cbData );
502 /* WM_NOTIFY cannot be sent across processes (MSDN) */
506 push_data( data, (HELPINFO *)lparam, sizeof(HELPINFO) );
508 case WM_STYLECHANGING:
509 case WM_STYLECHANGED:
510 push_data( data, (STYLESTRUCT *)lparam, sizeof(STYLESTRUCT) );
515 push_data( data, (RECT *)lparam, sizeof(RECT) );
520 NCCALCSIZE_PARAMS *nc = (NCCALCSIZE_PARAMS *)lparam;
521 push_data( data, nc, sizeof(*nc) );
522 push_data( data, nc->lppos, sizeof(*nc->lppos) );
523 return sizeof(*nc) + sizeof(*nc->lppos);
526 if (lparam) push_data( data, (MSG *)lparam, sizeof(MSG) );
528 case SBM_SETSCROLLINFO:
529 push_data( data, (SCROLLINFO *)lparam, sizeof(SCROLLINFO) );
531 case SBM_GETSCROLLINFO:
532 push_data( data, (SCROLLINFO *)lparam, sizeof(SCROLLINFO) );
533 return sizeof(SCROLLINFO);
534 case SBM_GETSCROLLBARINFO:
536 const SCROLLBARINFO *info = (const SCROLLBARINFO *)lparam;
537 size_t size = min( info->cbSize, sizeof(SCROLLBARINFO) );
538 push_data( data, info, size );
546 if (wparam) size += sizeof(DWORD);
547 if (lparam) size += sizeof(DWORD);
552 case CB_GETDROPPEDCONTROLRECT:
556 push_data( data, (RECT *)lparam, sizeof(RECT) );
560 WORD *pw = (WORD *)lparam;
561 push_data( data, pw, sizeof(*pw) );
562 return *pw * sizeof(WCHAR);
566 if (wparam) push_data( data, (UINT *)lparam, sizeof(UINT) * wparam );
569 case CB_INSERTSTRING:
571 case CB_FINDSTRINGEXACT:
572 case CB_SELECTSTRING:
573 if (combobox_has_strings( hwnd )) push_string( data, (LPWSTR)lparam );
576 if (!combobox_has_strings( hwnd )) return sizeof(ULONG_PTR);
577 return (SendMessageW( hwnd, CB_GETLBTEXTLEN, wparam, 0 ) + 1) * sizeof(WCHAR);
579 case LB_INSERTSTRING:
581 case LB_FINDSTRINGEXACT:
582 case LB_SELECTSTRING:
583 if (listbox_has_strings( hwnd )) push_string( data, (LPWSTR)lparam );
586 if (!listbox_has_strings( hwnd )) return sizeof(ULONG_PTR);
587 return (SendMessageW( hwnd, LB_GETTEXTLEN, wparam, 0 ) + 1) * sizeof(WCHAR);
589 return wparam * sizeof(UINT);
591 push_data( data, (MDINEXTMENU *)lparam, sizeof(MDINEXTMENU) );
592 return sizeof(MDINEXTMENU);
595 push_data( data, (RECT *)lparam, sizeof(RECT) );
599 MDICREATESTRUCTW *cs = (MDICREATESTRUCTW *)lparam;
600 push_data( data, cs, sizeof(*cs) );
601 if (HIWORD(cs->szTitle)) push_string( data, cs->szTitle );
602 if (HIWORD(cs->szClass)) push_string( data, cs->szClass );
605 case WM_MDIGETACTIVE:
606 if (lparam) return sizeof(BOOL);
608 case WM_DEVICECHANGE:
610 DEV_BROADCAST_HDR *header = (DEV_BROADCAST_HDR *)lparam;
611 push_data( data, header, header->dbch_size );
614 case WM_WINE_SETWINDOWPOS:
615 push_data( data, (WINDOWPOS *)lparam, sizeof(WINDOWPOS) );
617 case WM_WINE_KEYBOARD_LL_HOOK:
618 push_data( data, (KBDLLHOOKSTRUCT *)lparam, sizeof(KBDLLHOOKSTRUCT) );
620 case WM_WINE_MOUSE_LL_HOOK:
621 push_data( data, (MSLLHOOKSTRUCT *)lparam, sizeof(MSLLHOOKSTRUCT) );
624 if (wparam <= 1) return 0;
625 FIXME( "WM_NCPAINT hdc packing not supported yet\n" );
629 if (!wparam) return 0;
632 /* these contain an HFONT */
635 /* these contain an HDC */
637 case WM_ICONERASEBKGND:
638 case WM_CTLCOLORMSGBOX:
639 case WM_CTLCOLOREDIT:
640 case WM_CTLCOLORLISTBOX:
643 case WM_CTLCOLORSCROLLBAR:
644 case WM_CTLCOLORSTATIC:
647 /* these contain an HGLOBAL */
648 case WM_PAINTCLIPBOARD:
649 case WM_SIZECLIPBOARD:
650 /* these contain HICON */
653 case WM_QUERYDRAGICON:
654 case WM_QUERYPARKICON:
655 /* these contain pointers */
657 case WM_QUERYDROPOBJECT:
661 FIXME( "msg %x (%s) not supported yet\n", message, SPY_GetMsgName(message, hwnd) );
669 /***********************************************************************
672 * Unpack a message received from another process.
674 static BOOL unpack_message( HWND hwnd, UINT message, WPARAM *wparam, LPARAM *lparam,
675 void **buffer, size_t size )
684 CREATESTRUCTW *cs = *buffer;
685 WCHAR *str = (WCHAR *)(cs + 1);
686 if (size < sizeof(*cs)) return FALSE;
688 if (HIWORD(cs->lpszName))
690 if (!check_string( str, size )) return FALSE;
692 size -= (strlenW(str) + 1) * sizeof(WCHAR);
693 str += strlenW(str) + 1;
695 if (HIWORD(cs->lpszClass))
697 if (!check_string( str, size )) return FALSE;
703 case WM_ASKCBFORMATNAME:
704 if (!get_buffer_space( buffer, (*wparam * sizeof(WCHAR)) )) return FALSE;
706 case WM_WININICHANGE:
707 if (!*lparam) return TRUE;
710 case WM_DEVMODECHANGE:
715 if (!check_string( *buffer, size )) return FALSE;
717 case WM_GETMINMAXINFO:
718 minsize = sizeof(MINMAXINFO);
721 minsize = sizeof(DRAWITEMSTRUCT);
724 minsize = sizeof(MEASUREITEMSTRUCT);
727 minsize = sizeof(DELETEITEMSTRUCT);
730 minsize = sizeof(COMPAREITEMSTRUCT);
732 case WM_WINDOWPOSCHANGING:
733 case WM_WINDOWPOSCHANGED:
734 case WM_WINE_SETWINDOWPOS:
735 minsize = sizeof(WINDOWPOS);
739 COPYDATASTRUCT *cp = *buffer;
740 if (size < sizeof(*cp)) return FALSE;
743 minsize = sizeof(*cp) + cp->cbData;
749 /* WM_NOTIFY cannot be sent across processes (MSDN) */
752 minsize = sizeof(HELPINFO);
754 case WM_STYLECHANGING:
755 case WM_STYLECHANGED:
756 minsize = sizeof(STYLESTRUCT);
759 if (!*wparam) minsize = sizeof(RECT);
762 NCCALCSIZE_PARAMS *nc = *buffer;
763 if (size < sizeof(*nc) + sizeof(*nc->lppos)) return FALSE;
764 nc->lppos = (WINDOWPOS *)(nc + 1);
768 if (!*lparam) return TRUE;
769 minsize = sizeof(MSG);
771 case SBM_SETSCROLLINFO:
772 minsize = sizeof(SCROLLINFO);
774 case SBM_GETSCROLLINFO:
775 if (!get_buffer_space( buffer, sizeof(SCROLLINFO ))) return FALSE;
777 case SBM_GETSCROLLBARINFO:
778 if (!get_buffer_space( buffer, sizeof(SCROLLBARINFO ))) return FALSE;
783 if (*wparam || *lparam)
785 if (!get_buffer_space( buffer, 2*sizeof(DWORD) )) return FALSE;
786 if (*wparam) *wparam = (WPARAM)*buffer;
787 if (*lparam) *lparam = (LPARAM)((DWORD *)*buffer + 1);
792 case CB_GETDROPPEDCONTROLRECT:
793 if (!get_buffer_space( buffer, sizeof(RECT) )) return FALSE;
797 minsize = sizeof(RECT);
802 if (size < sizeof(WORD)) return FALSE;
803 len = *(WORD *)*buffer;
804 if (!get_buffer_space( buffer, (len + 1) * sizeof(WCHAR) )) return FALSE;
805 *lparam = (LPARAM)*buffer + sizeof(WORD); /* don't erase WORD at start of buffer */
810 if (!*wparam) return TRUE;
811 minsize = *wparam * sizeof(UINT);
814 case CB_INSERTSTRING:
816 case CB_FINDSTRINGEXACT:
817 case CB_SELECTSTRING:
819 case LB_INSERTSTRING:
821 case LB_FINDSTRINGEXACT:
822 case LB_SELECTSTRING:
823 if (!*buffer) return TRUE;
824 if (!check_string( *buffer, size )) return FALSE;
828 size = sizeof(ULONG_PTR);
829 if (combobox_has_strings( hwnd ))
830 size = (SendMessageW( hwnd, CB_GETLBTEXTLEN, *wparam, 0 ) + 1) * sizeof(WCHAR);
831 if (!get_buffer_space( buffer, size )) return FALSE;
836 size = sizeof(ULONG_PTR);
837 if (listbox_has_strings( hwnd ))
838 size = (SendMessageW( hwnd, LB_GETTEXTLEN, *wparam, 0 ) + 1) * sizeof(WCHAR);
839 if (!get_buffer_space( buffer, size )) return FALSE;
843 if (!get_buffer_space( buffer, *wparam * sizeof(UINT) )) return FALSE;
846 minsize = sizeof(MDINEXTMENU);
847 if (!get_buffer_space( buffer, sizeof(MDINEXTMENU) )) return FALSE;
851 minsize = sizeof(RECT);
852 if (!get_buffer_space( buffer, sizeof(RECT) )) return FALSE;
856 MDICREATESTRUCTW *cs = *buffer;
857 WCHAR *str = (WCHAR *)(cs + 1);
858 if (size < sizeof(*cs)) return FALSE;
860 if (HIWORD(cs->szTitle))
862 if (!check_string( str, size )) return FALSE;
864 size -= (strlenW(str) + 1) * sizeof(WCHAR);
865 str += strlenW(str) + 1;
867 if (HIWORD(cs->szClass))
869 if (!check_string( str, size )) return FALSE;
874 case WM_MDIGETACTIVE:
875 if (!*lparam) return TRUE;
876 if (!get_buffer_space( buffer, sizeof(BOOL) )) return FALSE;
878 case WM_DEVICECHANGE:
879 minsize = sizeof(DEV_BROADCAST_HDR);
881 case WM_WINE_KEYBOARD_LL_HOOK:
882 minsize = sizeof(KBDLLHOOKSTRUCT);
884 case WM_WINE_MOUSE_LL_HOOK:
885 minsize = sizeof(MSLLHOOKSTRUCT);
888 if (*wparam <= 1) return TRUE;
889 FIXME( "WM_NCPAINT hdc unpacking not supported\n" );
892 if (!*wparam) return TRUE;
895 /* these contain an HFONT */
898 /* these contain an HDC */
900 case WM_ICONERASEBKGND:
901 case WM_CTLCOLORMSGBOX:
902 case WM_CTLCOLOREDIT:
903 case WM_CTLCOLORLISTBOX:
906 case WM_CTLCOLORSCROLLBAR:
907 case WM_CTLCOLORSTATIC:
910 /* these contain an HGLOBAL */
911 case WM_PAINTCLIPBOARD:
912 case WM_SIZECLIPBOARD:
913 /* these contain HICON */
916 case WM_QUERYDRAGICON:
917 case WM_QUERYPARKICON:
918 /* these contain pointers */
920 case WM_QUERYDROPOBJECT:
924 FIXME( "msg %x (%s) not supported yet\n", message, SPY_GetMsgName(message, hwnd) );
928 return TRUE; /* message doesn't need any unpacking */
931 /* default exit for most messages: check minsize and store buffer in lparam */
932 if (size < minsize) return FALSE;
933 *lparam = (LPARAM)*buffer;
938 /***********************************************************************
941 * Pack a reply to a message for sending to another process.
943 static void pack_reply( HWND hwnd, UINT message, WPARAM wparam, LPARAM lparam,
944 LRESULT res, struct packed_message *data )
951 push_data( data, (CREATESTRUCTW *)lparam, sizeof(CREATESTRUCTW) );
956 push_data( data, (WCHAR *)lparam, (res + 1) * sizeof(WCHAR) );
958 case WM_GETMINMAXINFO:
959 push_data( data, (MINMAXINFO *)lparam, sizeof(MINMAXINFO) );
962 push_data( data, (MEASUREITEMSTRUCT *)lparam, sizeof(MEASUREITEMSTRUCT) );
964 case WM_WINDOWPOSCHANGING:
965 case WM_WINDOWPOSCHANGED:
966 push_data( data, (WINDOWPOS *)lparam, sizeof(WINDOWPOS) );
969 if (lparam) push_data( data, (MSG *)lparam, sizeof(MSG) );
971 case SBM_GETSCROLLINFO:
972 push_data( data, (SCROLLINFO *)lparam, sizeof(SCROLLINFO) );
976 case CB_GETDROPPEDCONTROLRECT:
979 push_data( data, (RECT *)lparam, sizeof(RECT) );
983 WORD *ptr = (WORD *)lparam;
984 push_data( data, ptr, ptr[-1] * sizeof(WCHAR) );
988 push_data( data, (UINT *)lparam, wparam * sizeof(UINT) );
990 case WM_MDIGETACTIVE:
991 if (lparam) push_data( data, (BOOL *)lparam, sizeof(BOOL) );
995 push_data( data, (RECT *)lparam, sizeof(RECT) );
998 NCCALCSIZE_PARAMS *nc = (NCCALCSIZE_PARAMS *)lparam;
999 push_data( data, nc, sizeof(*nc) );
1000 push_data( data, nc->lppos, sizeof(*nc->lppos) );
1006 if (wparam) push_data( data, (DWORD *)wparam, sizeof(DWORD) );
1007 if (lparam) push_data( data, (DWORD *)lparam, sizeof(DWORD) );
1010 push_data( data, (MDINEXTMENU *)lparam, sizeof(MDINEXTMENU) );
1013 push_data( data, (MDICREATESTRUCTW *)lparam, sizeof(MDICREATESTRUCTW) );
1015 case WM_ASKCBFORMATNAME:
1016 push_data( data, (WCHAR *)lparam, (strlenW((WCHAR *)lparam) + 1) * sizeof(WCHAR) );
1022 /***********************************************************************
1025 * Unpack a message reply received from another process.
1027 static void unpack_reply( HWND hwnd, UINT message, WPARAM wparam, LPARAM lparam,
1028 void *buffer, size_t size )
1035 CREATESTRUCTW *cs = (CREATESTRUCTW *)lparam;
1036 LPCWSTR name = cs->lpszName, class = cs->lpszClass;
1037 memcpy( cs, buffer, min( sizeof(*cs), size ));
1038 cs->lpszName = name; /* restore the original pointers */
1039 cs->lpszClass = class;
1043 case WM_ASKCBFORMATNAME:
1044 memcpy( (WCHAR *)lparam, buffer, min( wparam*sizeof(WCHAR), size ));
1046 case WM_GETMINMAXINFO:
1047 memcpy( (MINMAXINFO *)lparam, buffer, min( sizeof(MINMAXINFO), size ));
1049 case WM_MEASUREITEM:
1050 memcpy( (MEASUREITEMSTRUCT *)lparam, buffer, min( sizeof(MEASUREITEMSTRUCT), size ));
1052 case WM_WINDOWPOSCHANGING:
1053 case WM_WINDOWPOSCHANGED:
1054 memcpy( (WINDOWPOS *)lparam, buffer, min( sizeof(WINDOWPOS), size ));
1057 if (lparam) memcpy( (MSG *)lparam, buffer, min( sizeof(MSG), size ));
1059 case SBM_GETSCROLLINFO:
1060 memcpy( (SCROLLINFO *)lparam, buffer, min( sizeof(SCROLLINFO), size ));
1062 case SBM_GETSCROLLBARINFO:
1063 memcpy( (SCROLLBARINFO *)lparam, buffer, min( sizeof(SCROLLBARINFO), size ));
1066 case CB_GETDROPPEDCONTROLRECT:
1067 case LB_GETITEMRECT:
1070 memcpy( (RECT *)lparam, buffer, min( sizeof(RECT), size ));
1073 size = min( size, (size_t)*(WORD *)lparam );
1074 memcpy( (WCHAR *)lparam, buffer, size );
1076 case LB_GETSELITEMS:
1077 memcpy( (UINT *)lparam, buffer, min( wparam*sizeof(UINT), size ));
1081 memcpy( (WCHAR *)lparam, buffer, size );
1084 memcpy( (MDINEXTMENU *)lparam, buffer, min( sizeof(MDINEXTMENU), size ));
1086 case WM_MDIGETACTIVE:
1087 if (lparam) memcpy( (BOOL *)lparam, buffer, min( sizeof(BOOL), size ));
1091 memcpy( (RECT *)lparam, buffer, min( sizeof(RECT), size ));
1094 NCCALCSIZE_PARAMS *nc = (NCCALCSIZE_PARAMS *)lparam;
1095 WINDOWPOS *wp = nc->lppos;
1096 memcpy( nc, buffer, min( sizeof(*nc), size ));
1097 if (size > sizeof(*nc))
1099 size -= sizeof(*nc);
1100 memcpy( wp, (NCCALCSIZE_PARAMS*)buffer + 1, min( sizeof(*wp), size ));
1102 nc->lppos = wp; /* restore the original pointer */
1110 memcpy( (DWORD *)wparam, buffer, min( sizeof(DWORD), size ));
1111 if (size <= sizeof(DWORD)) break;
1112 size -= sizeof(DWORD);
1113 buffer = (DWORD *)buffer + 1;
1115 if (lparam) memcpy( (DWORD *)lparam, buffer, min( sizeof(DWORD), size ));
1119 MDICREATESTRUCTW *cs = (MDICREATESTRUCTW *)lparam;
1120 LPCWSTR title = cs->szTitle, class = cs->szClass;
1121 memcpy( cs, buffer, min( sizeof(*cs), size ));
1122 cs->szTitle = title; /* restore the original pointers */
1123 cs->szClass = class;
1127 ERR( "should not happen: unexpected message %x\n", message );
1133 /***********************************************************************
1136 * Send a reply to a sent message.
1138 static void reply_message( struct received_message_info *info, LRESULT result, BOOL remove )
1140 struct packed_message data;
1141 int i, replied = info->flags & ISMEX_REPLIED;
1143 if (info->flags & ISMEX_NOTIFY) return; /* notify messages don't get replies */
1144 if (!remove && replied) return; /* replied already */
1147 info->flags |= ISMEX_REPLIED;
1149 if (info->type == MSG_OTHER_PROCESS && !replied)
1151 pack_reply( info->msg.hwnd, info->msg.message, info->msg.wParam,
1152 info->msg.lParam, result, &data );
1155 SERVER_START_REQ( reply_message )
1157 req->result = result;
1158 req->remove = remove;
1159 for (i = 0; i < data.count; i++) wine_server_add_data( req, data.data[i], data.size[i] );
1160 wine_server_call( req );
1166 /***********************************************************************
1167 * handle_internal_message
1169 * Handle an internal Wine message instead of calling the window proc.
1171 static LRESULT handle_internal_message( HWND hwnd, UINT msg, WPARAM wparam, LPARAM lparam )
1175 case WM_WINE_DESTROYWINDOW:
1176 return WIN_DestroyWindow( hwnd );
1177 case WM_WINE_SETWINDOWPOS:
1178 if (hwnd == GetDesktopWindow()) return 0;
1179 return USER_Driver->pSetWindowPos( (WINDOWPOS *)lparam );
1180 case WM_WINE_SHOWWINDOW:
1181 if (hwnd == GetDesktopWindow()) return 0;
1182 return ShowWindow( hwnd, wparam );
1183 case WM_WINE_SETPARENT:
1184 if (hwnd == GetDesktopWindow()) return 0;
1185 return (LRESULT)SetParent( hwnd, (HWND)wparam );
1186 case WM_WINE_SETWINDOWLONG:
1187 return (LRESULT)SetWindowLongW( hwnd, wparam, lparam );
1188 case WM_WINE_ENABLEWINDOW:
1189 if (hwnd == GetDesktopWindow()) return 0;
1190 return EnableWindow( hwnd, wparam );
1191 case WM_WINE_SETACTIVEWINDOW:
1192 if (hwnd == GetDesktopWindow()) return 0;
1193 return (LRESULT)SetActiveWindow( (HWND)wparam );
1194 case WM_WINE_KEYBOARD_LL_HOOK:
1195 return HOOK_CallHooks( WH_KEYBOARD_LL, HC_ACTION, wparam, lparam, TRUE );
1196 case WM_WINE_MOUSE_LL_HOOK:
1197 return HOOK_CallHooks( WH_MOUSE_LL, HC_ACTION, wparam, lparam, TRUE );
1199 if (msg >= WM_WINE_FIRST_DRIVER_MSG && msg <= WM_WINE_LAST_DRIVER_MSG)
1200 return USER_Driver->pWindowMessage( hwnd, msg, wparam, lparam );
1201 FIXME( "unknown internal message %x\n", msg );
1206 /* since the WM_DDE_ACK response to a WM_DDE_EXECUTE message should contain the handle
1207 * to the memory handle, we keep track (in the server side) of all pairs of handle
1208 * used (the client passes its value and the content of the memory handle), and
1209 * the server stored both values (the client, and the local one, created after the
1210 * content). When a ACK message is generated, the list of pair is searched for a
1211 * matching pair, so that the client memory handle can be returned.
1214 HGLOBAL client_hMem;
1215 HGLOBAL server_hMem;
1218 static struct DDE_pair* dde_pairs;
1219 static int dde_num_alloc;
1220 static int dde_num_used;
1222 static CRITICAL_SECTION dde_crst;
1223 static CRITICAL_SECTION_DEBUG critsect_debug =
1226 { &critsect_debug.ProcessLocksList, &critsect_debug.ProcessLocksList },
1227 0, 0, { (DWORD_PTR)(__FILE__ ": dde_crst") }
1229 static CRITICAL_SECTION dde_crst = { &critsect_debug, -1, 0, 0, 0, 0 };
1231 static BOOL dde_add_pair(HGLOBAL chm, HGLOBAL shm)
1236 EnterCriticalSection(&dde_crst);
1238 /* now remember the pair of hMem on both sides */
1239 if (dde_num_used == dde_num_alloc)
1241 struct DDE_pair* tmp;
1243 tmp = HeapReAlloc( GetProcessHeap(), 0, dde_pairs,
1244 (dde_num_alloc + GROWBY) * sizeof(struct DDE_pair));
1246 tmp = HeapAlloc( GetProcessHeap(), 0,
1247 (dde_num_alloc + GROWBY) * sizeof(struct DDE_pair));
1251 LeaveCriticalSection(&dde_crst);
1255 /* zero out newly allocated part */
1256 memset(&dde_pairs[dde_num_alloc], 0, GROWBY * sizeof(struct DDE_pair));
1257 dde_num_alloc += GROWBY;
1260 for (i = 0; i < dde_num_alloc; i++)
1262 if (dde_pairs[i].server_hMem == 0)
1264 dde_pairs[i].client_hMem = chm;
1265 dde_pairs[i].server_hMem = shm;
1270 LeaveCriticalSection(&dde_crst);
1274 static HGLOBAL dde_get_pair(HGLOBAL shm)
1279 EnterCriticalSection(&dde_crst);
1280 for (i = 0; i < dde_num_alloc; i++)
1282 if (dde_pairs[i].server_hMem == shm)
1284 /* free this pair */
1285 dde_pairs[i].server_hMem = 0;
1287 ret = dde_pairs[i].client_hMem;
1291 LeaveCriticalSection(&dde_crst);
1295 /***********************************************************************
1298 * Post a DDE message
1300 static BOOL post_dde_message( struct packed_message *data, const struct send_message_info *info )
1304 UINT_PTR uiLo, uiHi;
1306 HGLOBAL hunlock = 0;
1310 if (!UnpackDDElParam( info->msg, info->lparam, &uiLo, &uiHi ))
1316 /* DDE messages which don't require packing are:
1325 /* uiHi should contain a hMem from WM_DDE_EXECUTE */
1326 HGLOBAL h = dde_get_pair( (HANDLE)uiHi );
1329 /* send back the value of h on the other side */
1330 push_data( data, &h, sizeof(HGLOBAL) );
1332 TRACE( "send dde-ack %x %08x => %p\n", uiLo, uiHi, h );
1337 /* uiHi should contain either an atom or 0 */
1338 TRACE( "send dde-ack %x atom=%x\n", uiLo, uiHi );
1339 lp = MAKELONG( uiLo, uiHi );
1348 size = GlobalSize( (HGLOBAL)uiLo ) ;
1349 if ((info->msg == WM_DDE_ADVISE && size < sizeof(DDEADVISE)) ||
1350 (info->msg == WM_DDE_DATA && size < sizeof(DDEDATA)) ||
1351 (info->msg == WM_DDE_POKE && size < sizeof(DDEPOKE))
1355 else if (info->msg != WM_DDE_DATA) return FALSE;
1360 if ((ptr = GlobalLock( (HGLOBAL)uiLo) ))
1362 DDEDATA *dde_data = (DDEDATA *)ptr;
1363 TRACE("unused %d, fResponse %d, fRelease %d, fDeferUpd %d, fAckReq %d, cfFormat %d\n",
1364 dde_data->unused, dde_data->fResponse, dde_data->fRelease,
1365 dde_data->reserved, dde_data->fAckReq, dde_data->cfFormat);
1366 push_data( data, ptr, size );
1367 hunlock = (HGLOBAL)uiLo;
1370 TRACE( "send ddepack %u %x\n", size, uiHi );
1372 case WM_DDE_EXECUTE:
1375 if ((ptr = GlobalLock( (HGLOBAL)info->lparam) ))
1377 push_data(data, ptr, GlobalSize( (HGLOBAL)info->lparam ));
1378 /* so that the other side can send it back on ACK */
1380 hunlock = (HGLOBAL)info->lparam;
1385 SERVER_START_REQ( send_message )
1387 req->id = info->dest_tid;
1388 req->type = info->type;
1390 req->win = info->hwnd;
1391 req->msg = info->msg;
1392 req->wparam = info->wparam;
1394 req->time = GetCurrentTime();
1396 for (i = 0; i < data->count; i++)
1397 wine_server_add_data( req, data->data[i], data->size[i] );
1398 if ((res = wine_server_call( req )))
1400 if (res == STATUS_INVALID_PARAMETER)
1401 /* FIXME: find a STATUS_ value for this one */
1402 SetLastError( ERROR_INVALID_THREAD_ID );
1404 SetLastError( RtlNtStatusToDosError(res) );
1407 FreeDDElParam(info->msg, info->lparam);
1410 if (hunlock) GlobalUnlock(hunlock);
1415 /***********************************************************************
1416 * unpack_dde_message
1418 * Unpack a posted DDE message received from another process.
1420 static BOOL unpack_dde_message( HWND hwnd, UINT message, WPARAM *wparam, LPARAM *lparam,
1421 void **buffer, size_t size )
1423 UINT_PTR uiLo, uiHi;
1432 /* hMem is being passed */
1433 if (size != sizeof(HGLOBAL)) return FALSE;
1434 if (!buffer || !*buffer) return FALSE;
1436 memcpy( &hMem, *buffer, size );
1437 uiHi = (UINT_PTR)hMem;
1438 TRACE("recv dde-ack %x mem=%x[%lx]\n", uiLo, uiHi, GlobalSize( hMem ));
1442 uiLo = LOWORD( *lparam );
1443 uiHi = HIWORD( *lparam );
1444 TRACE("recv dde-ack %x atom=%x\n", uiLo, uiHi);
1446 *lparam = PackDDElParam( WM_DDE_ACK, uiLo, uiHi );
1451 if ((!buffer || !*buffer) && message != WM_DDE_DATA) return FALSE;
1453 TRACE( "recv ddepack %u %x\n", size, uiHi );
1456 if (!(hMem = GlobalAlloc( GMEM_MOVEABLE|GMEM_DDESHARE, size )))
1458 if ((ptr = GlobalLock( hMem )))
1460 memcpy( ptr, *buffer, size );
1461 GlobalUnlock( hMem );
1469 uiLo = (UINT_PTR)hMem;
1471 *lparam = PackDDElParam( message, uiLo, uiHi );
1473 case WM_DDE_EXECUTE:
1476 if (!buffer || !*buffer) return FALSE;
1477 if (!(hMem = GlobalAlloc( GMEM_MOVEABLE|GMEM_DDESHARE, size ))) return FALSE;
1478 if ((ptr = GlobalLock( hMem )))
1480 memcpy( ptr, *buffer, size );
1481 GlobalUnlock( hMem );
1482 TRACE( "exec: pairing c=%08lx s=%08lx\n", *lparam, (DWORD)hMem );
1483 if (!dde_add_pair( (HGLOBAL)*lparam, hMem ))
1494 } else return FALSE;
1495 *lparam = (LPARAM)hMem;
1501 /***********************************************************************
1504 * Call a window procedure and the corresponding hooks.
1506 static LRESULT call_window_proc( HWND hwnd, UINT msg, WPARAM wparam, LPARAM lparam,
1507 BOOL unicode, BOOL same_thread )
1509 struct user_thread_info *thread_info = get_user_thread_info();
1513 CWPRETSTRUCT cwpret;
1515 if (thread_info->recursion_count > MAX_SENDMSG_RECURSION) return 0;
1516 thread_info->recursion_count++;
1518 if (msg & 0x80000000)
1520 result = handle_internal_message( hwnd, msg, wparam, lparam );
1524 /* first the WH_CALLWNDPROC hook */
1525 hwnd = WIN_GetFullHandle( hwnd );
1526 cwp.lParam = lparam;
1527 cwp.wParam = wparam;
1530 HOOK_CallHooks( WH_CALLWNDPROC, HC_ACTION, same_thread, (LPARAM)&cwp, unicode );
1532 /* now call the window procedure */
1535 if (!(winproc = (WNDPROC)GetWindowLongPtrW( hwnd, GWLP_WNDPROC ))) goto done;
1536 result = CallWindowProcW( winproc, hwnd, msg, wparam, lparam );
1540 if (!(winproc = (WNDPROC)GetWindowLongPtrA( hwnd, GWLP_WNDPROC ))) goto done;
1541 result = CallWindowProcA( winproc, hwnd, msg, wparam, lparam );
1544 /* and finally the WH_CALLWNDPROCRET hook */
1545 cwpret.lResult = result;
1546 cwpret.lParam = lparam;
1547 cwpret.wParam = wparam;
1548 cwpret.message = msg;
1550 HOOK_CallHooks( WH_CALLWNDPROCRET, HC_ACTION, same_thread, (LPARAM)&cwpret, unicode );
1552 thread_info->recursion_count--;
1557 /***********************************************************************
1558 * send_parent_notify
1560 * Send a WM_PARENTNOTIFY to all ancestors of the given window, unless
1561 * the window has the WS_EX_NOPARENTNOTIFY style.
1563 static void send_parent_notify( HWND hwnd, WORD event, WORD idChild, POINT pt )
1565 /* pt has to be in the client coordinates of the parent window */
1566 MapWindowPoints( 0, hwnd, &pt, 1 );
1571 if (!(GetWindowLongW( hwnd, GWL_STYLE ) & WS_CHILD)) break;
1572 if (GetWindowLongW( hwnd, GWL_EXSTYLE ) & WS_EX_NOPARENTNOTIFY) break;
1573 if (!(parent = GetParent(hwnd))) break;
1574 if (parent == GetDesktopWindow()) break;
1575 MapWindowPoints( hwnd, parent, &pt, 1 );
1577 SendMessageW( hwnd, WM_PARENTNOTIFY,
1578 MAKEWPARAM( event, idChild ), MAKELPARAM( pt.x, pt.y ) );
1583 /***********************************************************************
1584 * accept_hardware_message
1586 * Tell the server we have passed the message to the app
1587 * (even though we may end up dropping it later on)
1589 static void accept_hardware_message( UINT hw_id, BOOL remove, HWND new_hwnd )
1591 SERVER_START_REQ( accept_hardware_message )
1594 req->remove = remove;
1595 req->new_win = new_hwnd;
1596 if (wine_server_call( req ))
1597 FIXME("Failed to reply to MSG_HARDWARE message. Message may not be removed from queue.\n");
1603 /***********************************************************************
1604 * process_keyboard_message
1606 * returns TRUE if the contents of 'msg' should be passed to the application
1608 static BOOL process_keyboard_message( MSG *msg, UINT hw_id, HWND hwnd_filter,
1609 UINT first, UINT last, BOOL remove )
1613 /* FIXME: is this really the right place for this hook? */
1614 event.message = msg->message;
1615 event.hwnd = msg->hwnd;
1616 event.time = msg->time;
1617 event.paramL = (msg->wParam & 0xFF) | (HIWORD(msg->lParam) << 8);
1618 event.paramH = msg->lParam & 0x7FFF;
1619 if (HIWORD(msg->lParam) & 0x0100) event.paramH |= 0x8000; /* special_key - bit */
1620 HOOK_CallHooks( WH_JOURNALRECORD, HC_ACTION, 0, (LPARAM)&event, TRUE );
1622 /* check message filters */
1623 if (msg->message < first || msg->message > last) return FALSE;
1624 if (!check_hwnd_filter( msg, hwnd_filter )) return FALSE;
1628 /* Handle F1 key by sending out WM_HELP message */
1629 if ((msg->message == WM_KEYUP) &&
1630 (msg->wParam == VK_F1) &&
1631 (msg->hwnd != GetDesktopWindow()) &&
1632 !MENU_IsMenuActive())
1635 hi.cbSize = sizeof(HELPINFO);
1636 hi.iContextType = HELPINFO_WINDOW;
1637 hi.iCtrlId = GetWindowLongPtrA( msg->hwnd, GWLP_ID );
1638 hi.hItemHandle = msg->hwnd;
1639 hi.dwContextId = GetWindowContextHelpId( msg->hwnd );
1640 hi.MousePos = msg->pt;
1641 SendMessageW( msg->hwnd, WM_HELP, 0, (LPARAM)&hi );
1645 if (HOOK_CallHooks( WH_KEYBOARD, remove ? HC_ACTION : HC_NOREMOVE,
1646 LOWORD(msg->wParam), msg->lParam, TRUE ))
1648 /* skip this message */
1649 HOOK_CallHooks( WH_CBT, HCBT_KEYSKIPPED, LOWORD(msg->wParam), msg->lParam, TRUE );
1650 accept_hardware_message( hw_id, TRUE, 0 );
1653 accept_hardware_message( hw_id, remove, 0 );
1658 /***********************************************************************
1659 * process_mouse_message
1661 * returns TRUE if the contents of 'msg' should be passed to the application
1663 static BOOL process_mouse_message( MSG *msg, UINT hw_id, ULONG_PTR extra_info, HWND hwnd_filter,
1664 UINT first, UINT last, BOOL remove )
1673 MOUSEHOOKSTRUCT hook;
1676 /* find the window to dispatch this mouse message to */
1678 GetGUIThreadInfo( GetCurrentThreadId(), &info );
1679 if (info.hwndCapture)
1682 msg->hwnd = info.hwndCapture;
1686 msg->hwnd = WINPOS_WindowFromPoint( msg->hwnd, msg->pt, &hittest );
1689 if (!msg->hwnd || !WIN_IsCurrentThread( msg->hwnd ))
1691 accept_hardware_message( hw_id, TRUE, msg->hwnd );
1695 /* FIXME: is this really the right place for this hook? */
1696 event.message = msg->message;
1697 event.time = msg->time;
1698 event.hwnd = msg->hwnd;
1699 event.paramL = msg->pt.x;
1700 event.paramH = msg->pt.y;
1701 HOOK_CallHooks( WH_JOURNALRECORD, HC_ACTION, 0, (LPARAM)&event, TRUE );
1703 if (!check_hwnd_filter( msg, hwnd_filter )) return FALSE;
1706 message = msg->message;
1707 /* Note: windows has no concept of a non-client wheel message */
1708 if (message != WM_MOUSEWHEEL)
1710 if (hittest != HTCLIENT)
1712 message += WM_NCMOUSEMOVE - WM_MOUSEMOVE;
1713 msg->wParam = hittest;
1717 /* coordinates don't get translated while tracking a menu */
1718 /* FIXME: should differentiate popups and top-level menus */
1719 if (!(info.flags & GUI_INMENUMODE))
1720 ScreenToClient( msg->hwnd, &pt );
1723 msg->lParam = MAKELONG( pt.x, pt.y );
1725 /* translate double clicks */
1727 if ((msg->message == WM_LBUTTONDOWN) ||
1728 (msg->message == WM_RBUTTONDOWN) ||
1729 (msg->message == WM_MBUTTONDOWN) ||
1730 (msg->message == WM_XBUTTONDOWN))
1732 BOOL update = remove;
1734 /* translate double clicks -
1735 * note that ...MOUSEMOVEs can slip in between
1736 * ...BUTTONDOWN and ...BUTTONDBLCLK messages */
1738 if ((info.flags & (GUI_INMENUMODE|GUI_INMOVESIZE)) ||
1739 hittest != HTCLIENT ||
1740 (GetClassLongA( msg->hwnd, GCL_STYLE ) & CS_DBLCLKS))
1742 if ((msg->message == clk_msg.message) &&
1743 (msg->hwnd == clk_msg.hwnd) &&
1744 (msg->wParam == clk_msg.wParam) &&
1745 (msg->time - clk_msg.time < GetDoubleClickTime()) &&
1746 (abs(msg->pt.x - clk_msg.pt.x) < GetSystemMetrics(SM_CXDOUBLECLK)/2) &&
1747 (abs(msg->pt.y - clk_msg.pt.y) < GetSystemMetrics(SM_CYDOUBLECLK)/2))
1749 message += (WM_LBUTTONDBLCLK - WM_LBUTTONDOWN);
1752 clk_msg.message = 0; /* clear the double click conditions */
1757 if (message < first || message > last) return FALSE;
1758 /* update static double click conditions */
1759 if (update) clk_msg = *msg;
1763 if (message < first || message > last) return FALSE;
1766 /* message is accepted now (but may still get dropped) */
1769 hook.hwnd = msg->hwnd;
1770 hook.wHitTestCode = hittest;
1771 hook.dwExtraInfo = extra_info;
1772 if (HOOK_CallHooks( WH_MOUSE, remove ? HC_ACTION : HC_NOREMOVE,
1773 message, (LPARAM)&hook, TRUE ))
1776 hook.hwnd = msg->hwnd;
1777 hook.wHitTestCode = hittest;
1778 hook.dwExtraInfo = extra_info;
1779 HOOK_CallHooks( WH_CBT, HCBT_CLICKSKIPPED, message, (LPARAM)&hook, TRUE );
1780 accept_hardware_message( hw_id, TRUE, 0 );
1784 if ((hittest == HTERROR) || (hittest == HTNOWHERE))
1786 SendMessageW( msg->hwnd, WM_SETCURSOR, (WPARAM)msg->hwnd,
1787 MAKELONG( hittest, msg->message ));
1788 accept_hardware_message( hw_id, TRUE, 0 );
1792 accept_hardware_message( hw_id, remove, 0 );
1794 if (!remove || info.hwndCapture)
1796 msg->message = message;
1802 if ((msg->message == WM_LBUTTONDOWN) ||
1803 (msg->message == WM_RBUTTONDOWN) ||
1804 (msg->message == WM_MBUTTONDOWN) ||
1805 (msg->message == WM_XBUTTONDOWN))
1807 /* Send the WM_PARENTNOTIFY,
1808 * note that even for double/nonclient clicks
1809 * notification message is still WM_L/M/RBUTTONDOWN.
1811 send_parent_notify( msg->hwnd, msg->message, 0, msg->pt );
1813 /* Activate the window if needed */
1815 if (msg->hwnd != info.hwndActive)
1817 HWND hwndTop = msg->hwnd;
1820 if ((GetWindowLongW( hwndTop, GWL_STYLE ) & (WS_POPUP|WS_CHILD)) != WS_CHILD) break;
1821 hwndTop = GetParent( hwndTop );
1824 if (hwndTop && hwndTop != GetDesktopWindow())
1826 LONG ret = SendMessageW( msg->hwnd, WM_MOUSEACTIVATE, (WPARAM)hwndTop,
1827 MAKELONG( hittest, msg->message ) );
1830 case MA_NOACTIVATEANDEAT:
1835 case MA_ACTIVATEANDEAT:
1840 if (!FOCUS_MouseActivate( hwndTop )) eatMsg = TRUE;
1843 WARN( "unknown WM_MOUSEACTIVATE code %ld\n", ret );
1850 /* send the WM_SETCURSOR message */
1852 /* Windows sends the normal mouse message as the message parameter
1853 in the WM_SETCURSOR message even if it's non-client mouse message */
1854 SendMessageW( msg->hwnd, WM_SETCURSOR, (WPARAM)msg->hwnd, MAKELONG( hittest, msg->message ));
1856 msg->message = message;
1861 /***********************************************************************
1862 * process_hardware_message
1864 * Process a hardware message; return TRUE if message should be passed on to the app
1866 static BOOL process_hardware_message( MSG *msg, UINT hw_id, ULONG_PTR extra_info, HWND hwnd_filter,
1867 UINT first, UINT last, BOOL remove )
1869 if (is_keyboard_message( msg->message ))
1870 return process_keyboard_message( msg, hw_id, hwnd_filter, first, last, remove );
1872 if (is_mouse_message( msg->message ))
1873 return process_mouse_message( msg, hw_id, extra_info, hwnd_filter, first, last, remove );
1875 ERR( "unknown message type %x\n", msg->message );
1880 /***********************************************************************
1881 * call_sendmsg_callback
1883 * Call the callback function of SendMessageCallback.
1885 static inline void call_sendmsg_callback( SENDASYNCPROC callback, HWND hwnd, UINT msg,
1886 ULONG_PTR data, LRESULT result )
1888 if (TRACE_ON(relay))
1889 DPRINTF( "%04lx:Call message callback %p (hwnd=%p,msg=%s,data=%08lx,result=%08lx)\n",
1890 GetCurrentThreadId(), callback, hwnd, SPY_GetMsgName( msg, hwnd ),
1892 callback( hwnd, msg, data, result );
1893 if (TRACE_ON(relay))
1894 DPRINTF( "%04lx:Ret message callback %p (hwnd=%p,msg=%s,data=%08lx,result=%08lx)\n",
1895 GetCurrentThreadId(), callback, hwnd, SPY_GetMsgName( msg, hwnd ),
1900 /***********************************************************************
1903 * Retrieve the hook procedure real value for a module-relative proc
1905 static void *get_hook_proc( void *proc, const WCHAR *module )
1909 if (!(mod = GetModuleHandleW(module)))
1911 TRACE( "loading %s\n", debugstr_w(module) );
1912 /* FIXME: the library will never be freed */
1913 if (!(mod = LoadLibraryW(module))) return NULL;
1915 return (char *)mod + (ULONG_PTR)proc;
1919 /***********************************************************************
1922 * Peek for a message matching the given parameters. Return FALSE if none available.
1923 * All pending sent messages are processed before returning.
1925 static BOOL peek_message( MSG *msg, HWND hwnd, UINT first, UINT last, int flags )
1928 ULONG_PTR extra_info = 0;
1929 struct user_thread_info *thread_info = get_user_thread_info();
1930 struct received_message_info info, *old_info;
1931 unsigned int hw_id = 0; /* id of previous hardware message */
1933 if (!first && !last) last = ~0;
1938 void *buffer = NULL;
1939 size_t size = 0, buffer_size = 0;
1941 do /* loop while buffer is too small */
1943 if (buffer_size && !(buffer = HeapAlloc( GetProcessHeap(), 0, buffer_size )))
1945 SERVER_START_REQ( get_message )
1948 req->get_win = hwnd;
1949 req->get_first = first;
1950 req->get_last = last;
1952 if (buffer_size) wine_server_set_reply( req, buffer, buffer_size );
1953 if (!(res = wine_server_call( req )))
1955 size = wine_server_reply_size( reply );
1956 info.type = reply->type;
1957 info.msg.hwnd = reply->win;
1958 info.msg.message = reply->msg;
1959 info.msg.wParam = reply->wparam;
1960 info.msg.lParam = reply->lparam;
1961 info.msg.time = reply->time;
1962 info.msg.pt.x = reply->x;
1963 info.msg.pt.y = reply->y;
1964 info.hook = reply->hook;
1965 info.hook_proc = reply->hook_proc;
1966 hw_id = reply->hw_id;
1967 extra_info = reply->info;
1968 thread_info->active_hooks = reply->active_hooks;
1972 HeapFree( GetProcessHeap(), 0, buffer );
1973 buffer_size = reply->total;
1977 } while (res == STATUS_BUFFER_OVERFLOW);
1979 if (res) return FALSE;
1981 TRACE( "got type %d msg %x (%s) hwnd %p wp %x lp %lx\n",
1982 info.type, info.msg.message,
1983 (info.type == MSG_WINEVENT) ? "MSG_WINEVENT" : SPY_GetMsgName(info.msg.message, info.msg.hwnd),
1984 info.msg.hwnd, info.msg.wParam, info.msg.lParam );
1990 info.flags = ISMEX_SEND;
1993 info.flags = ISMEX_NOTIFY;
1996 info.flags = ISMEX_CALLBACK;
1998 case MSG_CALLBACK_RESULT:
1999 call_sendmsg_callback( (SENDASYNCPROC)info.msg.wParam, info.msg.hwnd,
2000 info.msg.message, extra_info, info.msg.lParam );
2005 WCHAR module[MAX_PATH];
2006 size = min( size, (MAX_PATH - 1) * sizeof(WCHAR) );
2007 memcpy( module, buffer, size );
2008 module[size / sizeof(WCHAR)] = 0;
2009 if (!(info.hook_proc = get_hook_proc( info.hook_proc, module )))
2011 ERR( "invalid winevent hook module name %s\n", debugstr_w(module) );
2015 if (TRACE_ON(relay))
2016 DPRINTF( "%04lx:Call 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 info.hook_proc( info.hook, info.msg.message, info.msg.hwnd, info.msg.wParam,
2022 info.msg.lParam, extra_info, info.msg.time );
2024 if (TRACE_ON(relay))
2025 DPRINTF( "%04lx:Ret winevent proc %p (hook=%p,event=%x,hwnd=%p,object_id=%x,child_id=%lx,tid=%04lx,time=%lx)\n",
2026 GetCurrentThreadId(), info.hook_proc,
2027 info.hook, info.msg.message, info.msg.hwnd, info.msg.wParam,
2028 info.msg.lParam, extra_info, info.msg.time);
2030 case MSG_OTHER_PROCESS:
2031 info.flags = ISMEX_SEND;
2032 if (!unpack_message( info.msg.hwnd, info.msg.message, &info.msg.wParam,
2033 &info.msg.lParam, &buffer, size ))
2035 ERR( "invalid packed message %x (%s) hwnd %p wp %x lp %lx size %d\n",
2036 info.msg.message, SPY_GetMsgName(info.msg.message, info.msg.hwnd), info.msg.hwnd,
2037 info.msg.wParam, info.msg.lParam, size );
2039 reply_message( &info, 0, TRUE );
2044 if (!process_hardware_message( &info.msg, hw_id, extra_info,
2045 hwnd, first, last, flags & GET_MSG_REMOVE ))
2047 TRACE("dropping msg %x\n", info.msg.message );
2048 goto next; /* ignore it */
2050 thread_info->GetMessagePosVal = MAKELONG( info.msg.pt.x, info.msg.pt.y );
2053 thread_info->GetMessageExtraInfoVal = extra_info;
2054 if (info.msg.message >= WM_DDE_FIRST && info.msg.message <= WM_DDE_LAST)
2056 if (!unpack_dde_message( info.msg.hwnd, info.msg.message, &info.msg.wParam,
2057 &info.msg.lParam, &buffer, size ))
2059 ERR( "invalid packed dde-message %x (%s) hwnd %p wp %x lp %lx size %d\n",
2060 info.msg.message, SPY_GetMsgName(info.msg.message, info.msg.hwnd),
2061 info.msg.hwnd, info.msg.wParam, info.msg.lParam, size );
2062 goto next; /* ignore it */
2066 HeapFree( GetProcessHeap(), 0, buffer );
2070 /* if we get here, we have a sent message; call the window procedure */
2071 old_info = thread_info->receive_info;
2072 thread_info->receive_info = &info;
2073 result = call_window_proc( info.msg.hwnd, info.msg.message, info.msg.wParam,
2074 info.msg.lParam, (info.type != MSG_ASCII), FALSE );
2075 reply_message( &info, result, TRUE );
2076 thread_info->receive_info = old_info;
2078 HeapFree( GetProcessHeap(), 0, buffer );
2083 /***********************************************************************
2084 * process_sent_messages
2086 * Process all pending sent messages.
2088 inline static void process_sent_messages(void)
2091 peek_message( &msg, 0, 0, 0, GET_MSG_REMOVE | GET_MSG_SENT_ONLY );
2095 /***********************************************************************
2096 * get_server_queue_handle
2098 * Get a handle to the server message queue for the current thread.
2100 static HANDLE get_server_queue_handle(void)
2102 struct user_thread_info *thread_info = get_user_thread_info();
2105 if (!(ret = thread_info->server_queue))
2107 SERVER_START_REQ( get_msg_queue )
2109 wine_server_call( req );
2110 ret = reply->handle;
2113 thread_info->server_queue = ret;
2114 if (!ret) ERR( "Cannot get server thread queue\n" );
2120 /***********************************************************************
2121 * wait_message_reply
2123 * Wait until a sent message gets replied to.
2125 static void wait_message_reply( UINT flags )
2127 HANDLE server_queue = get_server_queue_handle();
2131 unsigned int wake_bits = 0, changed_bits = 0;
2134 SERVER_START_REQ( set_queue_mask )
2136 req->wake_mask = QS_SMRESULT | ((flags & SMTO_BLOCK) ? 0 : QS_SENDMESSAGE);
2137 req->changed_mask = req->wake_mask;
2139 if (!wine_server_call( req ))
2141 wake_bits = reply->wake_bits;
2142 changed_bits = reply->changed_bits;
2147 if (wake_bits & QS_SMRESULT) return; /* got a result */
2148 if (wake_bits & QS_SENDMESSAGE)
2150 /* Process the sent message immediately */
2151 process_sent_messages();
2155 /* now wait for it */
2157 ReleaseThunkLock( &dwlc );
2158 res = USER_Driver->pMsgWaitForMultipleObjectsEx( 1, &server_queue,
2159 INFINITE, QS_SENDMESSAGE, 0 );
2160 if (dwlc) RestoreThunkLock( dwlc );
2164 /***********************************************************************
2165 * put_message_in_queue
2167 * Put a sent message into the destination queue.
2168 * For inter-process message, reply_size is set to expected size of reply data.
2170 static BOOL put_message_in_queue( const struct send_message_info *info, size_t *reply_size )
2172 struct packed_message data;
2176 /* Check for INFINITE timeout for compatibility with Win9x,
2177 * although Windows >= NT does not do so
2179 if (info->type != MSG_NOTIFY &&
2180 info->type != MSG_CALLBACK &&
2181 info->type != MSG_POSTED &&
2182 info->timeout != INFINITE)
2183 timeout = info->timeout;
2186 if (info->type == MSG_OTHER_PROCESS)
2188 *reply_size = pack_message( info->hwnd, info->msg, info->wparam, info->lparam, &data );
2189 if (data.count == -1)
2191 WARN( "cannot pack message %x\n", info->msg );
2195 else if (info->type == MSG_POSTED && info->msg >= WM_DDE_FIRST && info->msg <= WM_DDE_LAST)
2197 return post_dde_message( &data, info );
2200 SERVER_START_REQ( send_message )
2202 req->id = info->dest_tid;
2203 req->type = info->type;
2205 req->win = info->hwnd;
2206 req->msg = info->msg;
2207 req->wparam = info->wparam;
2208 req->lparam = info->lparam;
2209 req->time = GetCurrentTime();
2210 req->timeout = timeout;
2212 if (info->type == MSG_CALLBACK)
2214 req->callback = info->callback;
2215 req->info = info->data;
2218 if (info->flags & SMTO_ABORTIFHUNG) req->flags |= SEND_MSG_ABORT_IF_HUNG;
2219 for (i = 0; i < data.count; i++) wine_server_add_data( req, data.data[i], data.size[i] );
2220 if ((res = wine_server_call( req )))
2222 if (res == STATUS_INVALID_PARAMETER)
2223 /* FIXME: find a STATUS_ value for this one */
2224 SetLastError( ERROR_INVALID_THREAD_ID );
2226 SetLastError( RtlNtStatusToDosError(res) );
2234 /***********************************************************************
2237 * Retrieve a message reply from the server.
2239 static LRESULT retrieve_reply( const struct send_message_info *info,
2240 size_t reply_size, LRESULT *result )
2243 void *reply_data = NULL;
2247 if (!(reply_data = HeapAlloc( GetProcessHeap(), 0, reply_size )))
2249 WARN( "no memory for reply %d bytes, will be truncated\n", reply_size );
2253 SERVER_START_REQ( get_message_reply )
2256 if (reply_size) wine_server_set_reply( req, reply_data, reply_size );
2257 if (!(status = wine_server_call( req ))) *result = reply->result;
2258 reply_size = wine_server_reply_size( reply );
2261 if (!status && reply_size)
2262 unpack_reply( info->hwnd, info->msg, info->wparam, info->lparam, reply_data, reply_size );
2264 HeapFree( GetProcessHeap(), 0, reply_data );
2266 TRACE( "hwnd %p msg %x (%s) wp %x lp %lx got reply %lx (err=%ld)\n",
2267 info->hwnd, info->msg, SPY_GetMsgName(info->msg, info->hwnd), info->wparam,
2268 info->lparam, *result, status );
2270 /* MSDN states that last error is 0 on timeout, but at least NT4 returns ERROR_TIMEOUT */
2271 if (status) SetLastError( RtlNtStatusToDosError(status) );
2276 /***********************************************************************
2277 * send_inter_thread_message
2279 static LRESULT send_inter_thread_message( const struct send_message_info *info, LRESULT *res_ptr )
2281 size_t reply_size = 0;
2283 TRACE( "hwnd %p msg %x (%s) wp %x lp %lx\n",
2284 info->hwnd, info->msg, SPY_GetMsgName(info->msg, info->hwnd), info->wparam, info->lparam );
2286 USER_CheckNotLock();
2288 if (!put_message_in_queue( info, &reply_size )) return 0;
2290 /* there's no reply to wait for on notify/callback messages */
2291 if (info->type == MSG_NOTIFY || info->type == MSG_CALLBACK) return 1;
2293 wait_message_reply( info->flags );
2294 return retrieve_reply( info, reply_size, res_ptr );
2298 /***********************************************************************
2299 * MSG_SendInternalMessageTimeout
2301 * Same as SendMessageTimeoutW but sends the message to a specific thread
2302 * without requiring a window handle. Only works for internal Wine messages.
2304 LRESULT MSG_SendInternalMessageTimeout( DWORD dest_pid, DWORD dest_tid,
2305 UINT msg, WPARAM wparam, LPARAM lparam,
2306 UINT flags, UINT timeout, PDWORD_PTR res_ptr )
2308 struct send_message_info info;
2309 LRESULT ret, result;
2311 assert( msg & 0x80000000 ); /* must be an internal Wine message */
2313 info.type = MSG_UNICODE;
2314 info.dest_tid = dest_tid;
2317 info.wparam = wparam;
2318 info.lparam = lparam;
2320 info.timeout = timeout;
2322 if (USER_IsExitingThread( dest_tid )) return 0;
2324 if (dest_tid == GetCurrentThreadId())
2326 result = handle_internal_message( 0, msg, wparam, lparam );
2331 if (dest_pid != GetCurrentProcessId()) info.type = MSG_OTHER_PROCESS;
2332 ret = send_inter_thread_message( &info, &result );
2334 if (ret && res_ptr) *res_ptr = result;
2339 /***********************************************************************
2340 * SendMessageTimeoutW (USER32.@)
2342 LRESULT WINAPI SendMessageTimeoutW( HWND hwnd, UINT msg, WPARAM wparam, LPARAM lparam,
2343 UINT flags, UINT timeout, PDWORD_PTR res_ptr )
2345 struct send_message_info info;
2347 LRESULT ret, result;
2349 info.type = MSG_UNICODE;
2352 info.wparam = wparam;
2353 info.lparam = lparam;
2355 info.timeout = timeout;
2357 if (is_broadcast(hwnd))
2359 EnumWindows( broadcast_message_callback, (LPARAM)&info );
2360 if (res_ptr) *res_ptr = 1;
2364 if (!(info.dest_tid = GetWindowThreadProcessId( hwnd, &dest_pid ))) return 0;
2366 if (USER_IsExitingThread( info.dest_tid )) return 0;
2368 SPY_EnterMessage( SPY_SENDMESSAGE, hwnd, msg, wparam, lparam );
2370 if (info.dest_tid == GetCurrentThreadId())
2372 result = call_window_proc( hwnd, msg, wparam, lparam, TRUE, TRUE );
2377 if (dest_pid != GetCurrentProcessId()) info.type = MSG_OTHER_PROCESS;
2378 ret = send_inter_thread_message( &info, &result );
2381 SPY_ExitMessage( SPY_RESULT_OK, hwnd, msg, result, wparam, lparam );
2382 if (ret && res_ptr) *res_ptr = result;
2386 static LRESULT send_inter_thread_callback( HWND hwnd, UINT msg, WPARAM wp, LPARAM lp,
2387 LRESULT *result, void *arg )
2389 struct send_message_info *info = arg;
2394 return send_inter_thread_message( info, result );
2397 /***********************************************************************
2398 * SendMessageTimeoutA (USER32.@)
2400 LRESULT WINAPI SendMessageTimeoutA( HWND hwnd, UINT msg, WPARAM wparam, LPARAM lparam,
2401 UINT flags, UINT timeout, PDWORD_PTR res_ptr )
2403 struct send_message_info info;
2405 LRESULT ret, result;
2407 info.type = MSG_ASCII;
2410 info.wparam = wparam;
2411 info.lparam = lparam;
2413 info.timeout = timeout;
2415 if (is_broadcast(hwnd))
2417 EnumWindows( broadcast_message_callback, (LPARAM)&info );
2418 if (res_ptr) *res_ptr = 1;
2422 if (!(info.dest_tid = GetWindowThreadProcessId( hwnd, &dest_pid ))) return 0;
2424 if (USER_IsExitingThread( info.dest_tid )) return 0;
2426 SPY_EnterMessage( SPY_SENDMESSAGE, hwnd, msg, wparam, lparam );
2428 if (info.dest_tid == GetCurrentThreadId())
2430 result = call_window_proc( hwnd, msg, wparam, lparam, FALSE, TRUE );
2433 else if (dest_pid == GetCurrentProcessId())
2435 ret = send_inter_thread_message( &info, &result );
2439 /* inter-process message: need to map to Unicode */
2440 info.type = MSG_OTHER_PROCESS;
2441 if (is_unicode_message( info.msg ))
2442 ret = WINPROC_CallProcAtoW( send_inter_thread_callback, info.hwnd, info.msg,
2443 info.wparam, info.lparam, &result, &info );
2444 else ret = send_inter_thread_message( &info, &result );
2446 SPY_ExitMessage( SPY_RESULT_OK, hwnd, msg, result, wparam, lparam );
2447 if (ret && res_ptr) *res_ptr = result;
2452 /***********************************************************************
2453 * SendMessageW (USER32.@)
2455 LRESULT WINAPI SendMessageW( HWND hwnd, UINT msg, WPARAM wparam, LPARAM lparam )
2458 SendMessageTimeoutW( hwnd, msg, wparam, lparam, SMTO_NORMAL, 0, &res );
2463 /***********************************************************************
2464 * SendMessageA (USER32.@)
2466 LRESULT WINAPI SendMessageA( HWND hwnd, UINT msg, WPARAM wparam, LPARAM lparam )
2469 SendMessageTimeoutA( hwnd, msg, wparam, lparam, SMTO_NORMAL, 0, &res );
2474 /***********************************************************************
2475 * SendNotifyMessageA (USER32.@)
2477 BOOL WINAPI SendNotifyMessageA( HWND hwnd, UINT msg, WPARAM wparam, LPARAM lparam )
2479 return SendNotifyMessageW( hwnd, msg, map_wparam_AtoW( msg, wparam ), lparam );
2483 /***********************************************************************
2484 * SendNotifyMessageW (USER32.@)
2486 BOOL WINAPI SendNotifyMessageW( HWND hwnd, UINT msg, WPARAM wparam, LPARAM lparam )
2488 struct send_message_info info;
2491 if (is_pointer_message(msg))
2493 SetLastError( ERROR_MESSAGE_SYNC_ONLY );
2497 info.type = MSG_NOTIFY;
2500 info.wparam = wparam;
2501 info.lparam = lparam;
2504 if (is_broadcast(hwnd))
2506 EnumWindows( broadcast_message_callback, (LPARAM)&info );
2510 if (!(info.dest_tid = GetWindowThreadProcessId( hwnd, NULL ))) return FALSE;
2512 if (USER_IsExitingThread( info.dest_tid )) return TRUE;
2514 if (info.dest_tid == GetCurrentThreadId())
2516 call_window_proc( hwnd, msg, wparam, lparam, TRUE, TRUE );
2519 return send_inter_thread_message( &info, &result );
2523 /***********************************************************************
2524 * SendMessageCallbackA (USER32.@)
2526 BOOL WINAPI SendMessageCallbackA( HWND hwnd, UINT msg, WPARAM wparam, LPARAM lparam,
2527 SENDASYNCPROC callback, ULONG_PTR data )
2529 return SendMessageCallbackW( hwnd, msg, map_wparam_AtoW( msg, wparam ),
2530 lparam, callback, data );
2534 /***********************************************************************
2535 * SendMessageCallbackW (USER32.@)
2537 BOOL WINAPI SendMessageCallbackW( HWND hwnd, UINT msg, WPARAM wparam, LPARAM lparam,
2538 SENDASYNCPROC callback, ULONG_PTR data )
2540 struct send_message_info info;
2543 if (is_pointer_message(msg))
2545 SetLastError( ERROR_MESSAGE_SYNC_ONLY );
2549 info.type = MSG_CALLBACK;
2552 info.wparam = wparam;
2553 info.lparam = lparam;
2554 info.callback = callback;
2558 if (is_broadcast(hwnd))
2560 EnumWindows( broadcast_message_callback, (LPARAM)&info );
2564 if (!(info.dest_tid = GetWindowThreadProcessId( hwnd, NULL ))) return FALSE;
2566 if (USER_IsExitingThread( info.dest_tid )) return TRUE;
2568 if (info.dest_tid == GetCurrentThreadId())
2570 result = call_window_proc( hwnd, msg, wparam, lparam, TRUE, TRUE );
2571 call_sendmsg_callback( callback, hwnd, msg, data, result );
2574 FIXME( "callback will not be called\n" );
2575 return send_inter_thread_message( &info, &result );
2579 /***********************************************************************
2580 * ReplyMessage (USER32.@)
2582 BOOL WINAPI ReplyMessage( LRESULT result )
2584 struct received_message_info *info = get_user_thread_info()->receive_info;
2586 if (!info) return FALSE;
2587 reply_message( info, result, FALSE );
2592 /***********************************************************************
2593 * InSendMessage (USER32.@)
2595 BOOL WINAPI InSendMessage(void)
2597 return (InSendMessageEx(NULL) & (ISMEX_SEND|ISMEX_REPLIED)) == ISMEX_SEND;
2601 /***********************************************************************
2602 * InSendMessageEx (USER32.@)
2604 DWORD WINAPI InSendMessageEx( LPVOID reserved )
2606 struct received_message_info *info = get_user_thread_info()->receive_info;
2608 if (info) return info->flags;
2609 return ISMEX_NOSEND;
2613 /***********************************************************************
2614 * PostMessageA (USER32.@)
2616 BOOL WINAPI PostMessageA( HWND hwnd, UINT msg, WPARAM wparam, LPARAM lparam )
2618 return PostMessageW( hwnd, msg, map_wparam_AtoW( msg, wparam ), lparam );
2622 /***********************************************************************
2623 * PostMessageW (USER32.@)
2625 BOOL WINAPI PostMessageW( HWND hwnd, UINT msg, WPARAM wparam, LPARAM lparam )
2627 struct send_message_info info;
2629 if (is_pointer_message( msg ))
2631 SetLastError( ERROR_MESSAGE_SYNC_ONLY );
2635 TRACE( "hwnd %p msg %x (%s) wp %x lp %lx\n",
2636 hwnd, msg, SPY_GetMsgName(msg, hwnd), wparam, lparam );
2638 info.type = MSG_POSTED;
2641 info.wparam = wparam;
2642 info.lparam = lparam;
2645 if (is_broadcast(hwnd))
2647 EnumWindows( broadcast_message_callback, (LPARAM)&info );
2651 if (!hwnd) return PostThreadMessageW( GetCurrentThreadId(), msg, wparam, lparam );
2653 if (!(info.dest_tid = GetWindowThreadProcessId( hwnd, NULL ))) return FALSE;
2655 if (USER_IsExitingThread( info.dest_tid )) return TRUE;
2657 return put_message_in_queue( &info, NULL );
2661 /**********************************************************************
2662 * PostThreadMessageA (USER32.@)
2664 BOOL WINAPI PostThreadMessageA( DWORD thread, UINT msg, WPARAM wparam, LPARAM lparam )
2666 return PostThreadMessageW( thread, msg, map_wparam_AtoW( msg, wparam ), lparam );
2670 /**********************************************************************
2671 * PostThreadMessageW (USER32.@)
2673 BOOL WINAPI PostThreadMessageW( DWORD thread, UINT msg, WPARAM wparam, LPARAM lparam )
2675 struct send_message_info info;
2677 if (is_pointer_message( msg ))
2679 SetLastError( ERROR_MESSAGE_SYNC_ONLY );
2682 if (USER_IsExitingThread( thread )) return TRUE;
2684 info.type = MSG_POSTED;
2685 info.dest_tid = thread;
2688 info.wparam = wparam;
2689 info.lparam = lparam;
2691 return put_message_in_queue( &info, NULL );
2695 /***********************************************************************
2696 * PostQuitMessage (USER32.@)
2698 * Posts a quit message to the current thread's message queue.
2701 * exit_code [I] Exit code to return from message loop.
2707 * This function is not the same as calling:
2708 *|PostThreadMessage(GetCurrentThreadId(), WM_QUIT, exit_code, 0);
2709 * It instead sets a flag in the message queue that signals it to generate
2710 * a WM_QUIT message when there are no other pending sent or posted messages
2713 void WINAPI PostQuitMessage( INT exit_code )
2715 SERVER_START_REQ( post_quit_message )
2717 req->exit_code = exit_code;
2718 wine_server_call( req );
2724 /***********************************************************************
2725 * PeekMessageW (USER32.@)
2727 BOOL WINAPI PeekMessageW( MSG *msg_out, HWND hwnd, UINT first, UINT last, UINT flags )
2729 struct user_thread_info *thread_info = get_user_thread_info();
2733 FIXME("PM_QS_xxxx flags (%04x) are not handled\n", flags >> 16);
2735 USER_CheckNotLock();
2737 /* check for graphics events */
2738 USER_Driver->pMsgWaitForMultipleObjectsEx( 0, NULL, 0, QS_ALLINPUT, 0 );
2740 hwnd = WIN_GetFullHandle( hwnd );
2744 if (!peek_message( &msg, hwnd, first, last, (flags & PM_REMOVE) ? GET_MSG_REMOVE : 0 ))
2746 if (!(flags & PM_NOYIELD))
2749 ReleaseThunkLock(&count);
2751 if (count) RestoreThunkLock(count);
2755 if (msg.message & 0x80000000)
2757 if (!(flags & PM_REMOVE))
2759 /* Have to remove the message explicitly.
2760 Do this before handling it, because the message handler may
2761 call PeekMessage again */
2762 peek_message( &msg, msg.hwnd, msg.message, msg.message, GET_MSG_REMOVE );
2764 handle_internal_message( msg.hwnd, msg.message, msg.wParam, msg.lParam );
2769 thread_info->GetMessageTimeVal = msg.time;
2770 msg.pt.x = LOWORD( thread_info->GetMessagePosVal );
2771 msg.pt.y = HIWORD( thread_info->GetMessagePosVal );
2773 HOOK_CallHooks( WH_GETMESSAGE, HC_ACTION, flags & PM_REMOVE, (LPARAM)&msg, TRUE );
2775 /* copy back our internal safe copy of message data to msg_out.
2776 * msg_out is a variable from the *program*, so it can't be used
2777 * internally as it can get "corrupted" by our use of SendMessage()
2778 * (back to the program) inside the message handling itself. */
2781 SetLastError( ERROR_NOACCESS );
2789 /***********************************************************************
2790 * PeekMessageA (USER32.@)
2792 BOOL WINAPI PeekMessageA( MSG *msg, HWND hwnd, UINT first, UINT last, UINT flags )
2794 BOOL ret = PeekMessageW( msg, hwnd, first, last, flags );
2795 if (ret) msg->wParam = map_wparam_WtoA( msg->message, msg->wParam );
2800 /***********************************************************************
2801 * GetMessageW (USER32.@)
2803 BOOL WINAPI GetMessageW( MSG *msg, HWND hwnd, UINT first, UINT last )
2805 HANDLE server_queue = get_server_queue_handle();
2806 int mask = QS_POSTMESSAGE | QS_SENDMESSAGE; /* Always selected */
2810 if ((first <= WM_KEYLAST) && (last >= WM_KEYFIRST)) mask |= QS_KEY;
2811 if ( ((first <= WM_MOUSELAST) && (last >= WM_MOUSEFIRST)) ||
2812 ((first <= WM_NCMOUSELAST) && (last >= WM_NCMOUSEFIRST)) ) mask |= QS_MOUSE;
2813 if ((first <= WM_TIMER) && (last >= WM_TIMER)) mask |= QS_TIMER;
2814 if ((first <= WM_SYSTIMER) && (last >= WM_SYSTIMER)) mask |= QS_TIMER;
2815 if ((first <= WM_PAINT) && (last >= WM_PAINT)) mask |= QS_PAINT;
2817 else mask |= QS_MOUSE | QS_KEY | QS_TIMER | QS_PAINT;
2819 while (!PeekMessageW( msg, hwnd, first, last, PM_REMOVE ))
2821 /* wait until one of the bits is set */
2822 unsigned int wake_bits = 0, changed_bits = 0;
2825 SERVER_START_REQ( set_queue_mask )
2827 req->wake_mask = QS_SENDMESSAGE;
2828 req->changed_mask = mask;
2830 if (!wine_server_call( req ))
2832 wake_bits = reply->wake_bits;
2833 changed_bits = reply->changed_bits;
2838 if (changed_bits & mask) continue;
2839 if (wake_bits & QS_SENDMESSAGE) continue;
2841 TRACE( "(%04lx) mask=%08x, bits=%08x, changed=%08x, waiting\n",
2842 GetCurrentThreadId(), mask, wake_bits, changed_bits );
2844 ReleaseThunkLock( &dwlc );
2845 USER_Driver->pMsgWaitForMultipleObjectsEx( 1, &server_queue, INFINITE, QS_ALLINPUT, 0 );
2846 if (dwlc) RestoreThunkLock( dwlc );
2849 return (msg->message != WM_QUIT);
2853 /***********************************************************************
2854 * GetMessageA (USER32.@)
2856 BOOL WINAPI GetMessageA( MSG *msg, HWND hwnd, UINT first, UINT last )
2858 GetMessageW( msg, hwnd, first, last );
2859 msg->wParam = map_wparam_WtoA( msg->message, msg->wParam );
2860 return (msg->message != WM_QUIT);
2864 /***********************************************************************
2865 * IsDialogMessageA (USER32.@)
2866 * IsDialogMessage (USER32.@)
2868 BOOL WINAPI IsDialogMessageA( HWND hwndDlg, LPMSG pmsg )
2871 msg.wParam = map_wparam_AtoW( msg.message, msg.wParam );
2872 return IsDialogMessageW( hwndDlg, &msg );
2876 /***********************************************************************
2877 * TranslateMessage (USER32.@)
2879 * Implementation of TranslateMessage.
2881 * TranslateMessage translates virtual-key messages into character-messages,
2883 * WM_KEYDOWN/WM_KEYUP combinations produce a WM_CHAR or WM_DEADCHAR message.
2884 * ditto replacing WM_* with WM_SYS*
2885 * This produces WM_CHAR messages only for keys mapped to ASCII characters
2886 * by the keyboard driver.
2888 * If the message is WM_KEYDOWN, WM_KEYUP, WM_SYSKEYDOWN, or WM_SYSKEYUP, the
2889 * return value is nonzero, regardless of the translation.
2892 BOOL WINAPI TranslateMessage( const MSG *msg )
2898 if (msg->message < WM_KEYFIRST || msg->message > WM_KEYLAST) return FALSE;
2899 if (msg->message != WM_KEYDOWN && msg->message != WM_SYSKEYDOWN) return TRUE;
2901 TRACE_(key)("Translating key %s (%04x), scancode %02x\n",
2902 SPY_GetVKeyName(msg->wParam), msg->wParam, LOBYTE(HIWORD(msg->lParam)));
2904 GetKeyboardState( state );
2905 /* FIXME : should handle ToUnicode yielding 2 */
2906 switch (ToUnicode(msg->wParam, HIWORD(msg->lParam), state, wp, 2, 0))
2909 message = (msg->message == WM_KEYDOWN) ? WM_CHAR : WM_SYSCHAR;
2910 TRACE_(key)("1 -> PostMessageW(%p,%s,%04x,%08lx)\n",
2911 msg->hwnd, SPY_GetMsgName(message, msg->hwnd), wp[0], msg->lParam);
2912 PostMessageW( msg->hwnd, message, wp[0], msg->lParam );
2916 message = (msg->message == WM_KEYDOWN) ? WM_DEADCHAR : WM_SYSDEADCHAR;
2917 TRACE_(key)("-1 -> PostMessageW(%p,%s,%04x,%08lx)\n",
2918 msg->hwnd, SPY_GetMsgName(message, msg->hwnd), wp[0], msg->lParam);
2919 PostMessageW( msg->hwnd, message, wp[0], msg->lParam );
2926 /***********************************************************************
2927 * DispatchMessageA (USER32.@)
2929 * See DispatchMessageW.
2931 LONG WINAPI DispatchMessageA( const MSG* msg )
2937 /* Process timer messages */
2938 if ((msg->message == WM_TIMER) || (msg->message == WM_SYSTIMER))
2940 if (msg->lParam) return CallWindowProcA( (WNDPROC)msg->lParam, msg->hwnd,
2941 msg->message, msg->wParam, GetTickCount() );
2944 if (!(wndPtr = WIN_GetPtr( msg->hwnd )))
2946 if (msg->hwnd) SetLastError( ERROR_INVALID_WINDOW_HANDLE );
2949 if (wndPtr == WND_OTHER_PROCESS || wndPtr == WND_DESKTOP)
2951 if (IsWindow( msg->hwnd )) SetLastError( ERROR_MESSAGE_SYNC_ONLY );
2952 else SetLastError( ERROR_INVALID_WINDOW_HANDLE );
2955 if (wndPtr->tid != GetCurrentThreadId())
2957 SetLastError( ERROR_MESSAGE_SYNC_ONLY );
2958 WIN_ReleasePtr( wndPtr );
2961 winproc = wndPtr->winproc;
2962 WIN_ReleasePtr( wndPtr );
2964 SPY_EnterMessage( SPY_DISPATCHMESSAGE, msg->hwnd, msg->message,
2965 msg->wParam, msg->lParam );
2966 retval = CallWindowProcA( winproc, msg->hwnd, msg->message,
2967 msg->wParam, msg->lParam );
2968 SPY_ExitMessage( SPY_RESULT_OK, msg->hwnd, msg->message, retval,
2969 msg->wParam, msg->lParam );
2971 if (msg->message == WM_PAINT)
2973 /* send a WM_NCPAINT and WM_ERASEBKGND if the non-client area is still invalid */
2974 HRGN hrgn = CreateRectRgn( 0, 0, 0, 0 );
2975 GetUpdateRgn( msg->hwnd, hrgn, TRUE );
2976 DeleteObject( hrgn );
2982 /***********************************************************************
2983 * DispatchMessageW (USER32.@) Process a message
2985 * Process the message specified in the structure *_msg_.
2987 * If the lpMsg parameter points to a WM_TIMER message and the
2988 * parameter of the WM_TIMER message is not NULL, the lParam parameter
2989 * points to the function that is called instead of the window
2992 * The message must be valid.
2996 * DispatchMessage() returns the result of the window procedure invoked.
3003 LONG WINAPI DispatchMessageW( const MSG* msg )
3009 /* Process timer messages */
3010 if ((msg->message == WM_TIMER) || (msg->message == WM_SYSTIMER))
3012 if (msg->lParam) return CallWindowProcW( (WNDPROC)msg->lParam, msg->hwnd,
3013 msg->message, msg->wParam, GetTickCount() );
3016 if (!(wndPtr = WIN_GetPtr( msg->hwnd )))
3018 if (msg->hwnd) SetLastError( ERROR_INVALID_WINDOW_HANDLE );
3021 if (wndPtr == WND_OTHER_PROCESS || wndPtr == WND_DESKTOP)
3023 if (IsWindow( msg->hwnd )) SetLastError( ERROR_MESSAGE_SYNC_ONLY );
3024 else SetLastError( ERROR_INVALID_WINDOW_HANDLE );
3027 if (wndPtr->tid != GetCurrentThreadId())
3029 SetLastError( ERROR_MESSAGE_SYNC_ONLY );
3030 WIN_ReleasePtr( wndPtr );
3033 winproc = wndPtr->winproc;
3034 WIN_ReleasePtr( wndPtr );
3036 SPY_EnterMessage( SPY_DISPATCHMESSAGE, msg->hwnd, msg->message,
3037 msg->wParam, msg->lParam );
3038 retval = CallWindowProcW( winproc, msg->hwnd, msg->message,
3039 msg->wParam, msg->lParam );
3040 SPY_ExitMessage( SPY_RESULT_OK, msg->hwnd, msg->message, retval,
3041 msg->wParam, msg->lParam );
3043 if (msg->message == WM_PAINT)
3045 /* send a WM_NCPAINT and WM_ERASEBKGND if the non-client area is still invalid */
3046 HRGN hrgn = CreateRectRgn( 0, 0, 0, 0 );
3047 GetUpdateRgn( msg->hwnd, hrgn, TRUE );
3048 DeleteObject( hrgn );
3054 /***********************************************************************
3055 * GetMessagePos (USER.119)
3056 * GetMessagePos (USER32.@)
3058 * The GetMessagePos() function returns a long value representing a
3059 * cursor position, in screen coordinates, when the last message
3060 * retrieved by the GetMessage() function occurs. The x-coordinate is
3061 * in the low-order word of the return value, the y-coordinate is in
3062 * the high-order word. The application can use the MAKEPOINT()
3063 * macro to obtain a POINT structure from the return value.
3065 * For the current cursor position, use GetCursorPos().
3069 * Cursor position of last message on success, zero on failure.
3076 DWORD WINAPI GetMessagePos(void)
3078 return get_user_thread_info()->GetMessagePosVal;
3082 /***********************************************************************
3083 * GetMessageTime (USER.120)
3084 * GetMessageTime (USER32.@)
3086 * GetMessageTime() returns the message time for the last message
3087 * retrieved by the function. The time is measured in milliseconds with
3088 * the same offset as GetTickCount().
3090 * Since the tick count wraps, this is only useful for moderately short
3091 * relative time comparisons.
3095 * Time of last message on success, zero on failure.
3097 LONG WINAPI GetMessageTime(void)
3099 return get_user_thread_info()->GetMessageTimeVal;
3103 /***********************************************************************
3104 * GetMessageExtraInfo (USER.288)
3105 * GetMessageExtraInfo (USER32.@)
3107 LPARAM WINAPI GetMessageExtraInfo(void)
3109 return get_user_thread_info()->GetMessageExtraInfoVal;
3113 /***********************************************************************
3114 * SetMessageExtraInfo (USER32.@)
3116 LPARAM WINAPI SetMessageExtraInfo(LPARAM lParam)
3118 struct user_thread_info *thread_info = get_user_thread_info();
3119 LONG old_value = thread_info->GetMessageExtraInfoVal;
3120 thread_info->GetMessageExtraInfoVal = lParam;
3125 /***********************************************************************
3126 * WaitMessage (USER.112) Suspend thread pending messages
3127 * WaitMessage (USER32.@) Suspend thread pending messages
3129 * WaitMessage() suspends a thread until events appear in the thread's
3132 BOOL WINAPI WaitMessage(void)
3134 return (MsgWaitForMultipleObjectsEx( 0, NULL, INFINITE, QS_ALLINPUT, 0 ) != WAIT_FAILED);
3138 /***********************************************************************
3139 * MsgWaitForMultipleObjectsEx (USER32.@)
3141 DWORD WINAPI MsgWaitForMultipleObjectsEx( DWORD count, CONST HANDLE *pHandles,
3142 DWORD timeout, DWORD mask, DWORD flags )
3144 HANDLE handles[MAXIMUM_WAIT_OBJECTS];
3147 if (count > MAXIMUM_WAIT_OBJECTS-1)
3149 SetLastError( ERROR_INVALID_PARAMETER );
3153 /* set the queue mask */
3154 SERVER_START_REQ( set_queue_mask )
3156 req->wake_mask = (flags & MWMO_INPUTAVAILABLE) ? mask : 0;
3157 req->changed_mask = mask;
3159 wine_server_call( req );
3163 /* Add the thread event to the handle list */
3164 for (i = 0; i < count; i++) handles[i] = pHandles[i];
3165 handles[count] = get_server_queue_handle();
3167 ReleaseThunkLock( &lock );
3168 ret = USER_Driver->pMsgWaitForMultipleObjectsEx( count+1, handles, timeout, mask, flags );
3169 if (ret == count+1) ret = count; /* pretend the msg queue is ready */
3170 if (lock) RestoreThunkLock( lock );
3175 /***********************************************************************
3176 * MsgWaitForMultipleObjects (USER32.@)
3178 DWORD WINAPI MsgWaitForMultipleObjects( DWORD count, CONST HANDLE *handles,
3179 BOOL wait_all, DWORD timeout, DWORD mask )
3181 return MsgWaitForMultipleObjectsEx( count, handles, timeout, mask,
3182 wait_all ? MWMO_WAITALL : 0 );
3186 /***********************************************************************
3187 * WaitForInputIdle (USER32.@)
3189 DWORD WINAPI WaitForInputIdle( HANDLE hProcess, DWORD dwTimeOut )
3191 DWORD start_time, elapsed, ret;
3192 HANDLE idle_event = (HANDLE)-1;
3194 SERVER_START_REQ( wait_input_idle )
3196 req->handle = hProcess;
3197 req->timeout = dwTimeOut;
3198 if (!(ret = wine_server_call_err( req ))) idle_event = reply->event;
3201 if (ret) return WAIT_FAILED; /* error */
3202 if (!idle_event) return 0; /* no event to wait on */
3204 start_time = GetTickCount();
3207 TRACE("waiting for %p\n", idle_event );
3210 ret = MsgWaitForMultipleObjects ( 1, &idle_event, FALSE, dwTimeOut - elapsed, QS_SENDMESSAGE );
3213 case WAIT_OBJECT_0+1:
3214 process_sent_messages();
3218 TRACE("timeout or error\n");
3221 TRACE("finished\n");
3224 if (dwTimeOut != INFINITE)
3226 elapsed = GetTickCount() - start_time;
3227 if (elapsed > dwTimeOut)
3233 return WAIT_TIMEOUT;
3237 /***********************************************************************
3238 * UserYield (USER.332)
3240 void WINAPI UserYield16(void)
3244 /* Handle sent messages */
3245 process_sent_messages();
3248 ReleaseThunkLock(&count);
3252 RestoreThunkLock(count);
3253 /* Handle sent messages again */
3254 process_sent_messages();
3259 /***********************************************************************
3260 * RegisterWindowMessageA (USER32.@)
3261 * RegisterWindowMessage (USER.118)
3263 UINT WINAPI RegisterWindowMessageA( LPCSTR str )
3265 UINT ret = GlobalAddAtomA(str);
3266 TRACE("%s, ret=%x\n", str, ret);
3271 /***********************************************************************
3272 * RegisterWindowMessageW (USER32.@)
3274 UINT WINAPI RegisterWindowMessageW( LPCWSTR str )
3276 UINT ret = GlobalAddAtomW(str);
3277 TRACE("%s ret=%x\n", debugstr_w(str), ret);
3282 /***********************************************************************
3283 * BroadcastSystemMessageA (USER32.@)
3284 * BroadcastSystemMessage (USER32.@)
3286 LONG WINAPI BroadcastSystemMessageA( DWORD flags, LPDWORD recipients, UINT msg, WPARAM wp, LPARAM lp )
3288 if ((*recipients & BSM_APPLICATIONS) || (*recipients == BSM_ALLCOMPONENTS))
3290 FIXME( "(%08lx,%08lx,%08x,%08x,%08lx): semi-stub!\n", flags, *recipients, msg, wp, lp );
3291 PostMessageA( HWND_BROADCAST, msg, wp, lp );
3296 FIXME( "(%08lx,%08lx,%08x,%08x,%08lx): stub!\n", flags, *recipients, msg, wp, lp);
3302 /***********************************************************************
3303 * BroadcastSystemMessageW (USER32.@)
3305 LONG WINAPI BroadcastSystemMessageW( DWORD flags, LPDWORD recipients, UINT msg, WPARAM wp, LPARAM lp )
3307 if ((*recipients & BSM_APPLICATIONS) || (*recipients == BSM_ALLCOMPONENTS))
3309 FIXME( "(%08lx,%08lx,%08x,%08x,%08lx): semi-stub!\n", flags, *recipients, msg, wp, lp );
3310 PostMessageW( HWND_BROADCAST, msg, wp, lp );
3315 FIXME( "(%08lx,%08lx,%08x,%08x,%08lx): stub!\n", flags, *recipients, msg, wp, lp );
3321 /***********************************************************************
3322 * SetMessageQueue (USER32.@)
3324 BOOL WINAPI SetMessageQueue( INT size )
3326 /* now obsolete the message queue will be expanded dynamically as necessary */
3331 /***********************************************************************
3332 * MessageBeep (USER32.@)
3334 BOOL WINAPI MessageBeep( UINT i )
3337 SystemParametersInfoA( SPI_GETBEEP, 0, &active, FALSE );
3338 if (active) USER_Driver->pBeep();
3343 /***********************************************************************
3344 * SetTimer (USER32.@)
3346 UINT_PTR WINAPI SetTimer( HWND hwnd, UINT_PTR id, UINT timeout, TIMERPROC proc )
3349 WNDPROC winproc = 0;
3351 if (proc) winproc = WINPROC_AllocProc( (WNDPROC)proc, NULL );
3353 SERVER_START_REQ( set_win_timer )
3356 req->msg = WM_TIMER;
3358 req->rate = max( timeout, SYS_TIMER_RATE );
3359 req->lparam = (unsigned int)winproc;
3360 if (!wine_server_call_err( req ))
3363 if (!ret) ret = TRUE;
3369 TRACE("Added %p %x %p timeout %d\n", hwnd, id, winproc, timeout );
3374 /***********************************************************************
3375 * SetSystemTimer (USER32.@)
3377 UINT_PTR WINAPI SetSystemTimer( HWND hwnd, UINT_PTR id, UINT timeout, TIMERPROC proc )
3380 WNDPROC winproc = 0;
3382 if (proc) winproc = WINPROC_AllocProc( (WNDPROC)proc, NULL );
3384 SERVER_START_REQ( set_win_timer )
3387 req->msg = WM_SYSTIMER;
3389 req->rate = max( timeout, SYS_TIMER_RATE );
3390 req->lparam = (unsigned int)winproc;
3391 if (!wine_server_call_err( req ))
3394 if (!ret) ret = TRUE;
3400 TRACE("Added %p %x %p timeout %d\n", hwnd, id, winproc, timeout );
3405 /***********************************************************************
3406 * KillTimer (USER32.@)
3408 BOOL WINAPI KillTimer( HWND hwnd, UINT_PTR id )
3412 TRACE("%p %d\n", hwnd, id );
3414 SERVER_START_REQ( kill_win_timer )
3417 req->msg = WM_TIMER;
3419 ret = !wine_server_call_err( req );
3426 /***********************************************************************
3427 * KillSystemTimer (USER32.@)
3429 BOOL WINAPI KillSystemTimer( HWND hwnd, UINT_PTR id )
3433 TRACE("%p %d\n", hwnd, id );
3435 SERVER_START_REQ( kill_win_timer )
3438 req->msg = WM_SYSTIMER;
3440 ret = !wine_server_call_err( req );
3447 /**********************************************************************
3448 * GetGUIThreadInfo (USER32.@)
3450 BOOL WINAPI GetGUIThreadInfo( DWORD id, GUITHREADINFO *info )
3454 SERVER_START_REQ( get_thread_input )
3457 if ((ret = !wine_server_call_err( req )))
3460 info->hwndActive = reply->active;
3461 info->hwndFocus = reply->focus;
3462 info->hwndCapture = reply->capture;
3463 info->hwndMenuOwner = reply->menu_owner;
3464 info->hwndMoveSize = reply->move_size;
3465 info->hwndCaret = reply->caret;
3466 info->rcCaret.left = reply->rect.left;
3467 info->rcCaret.top = reply->rect.top;
3468 info->rcCaret.right = reply->rect.right;
3469 info->rcCaret.bottom = reply->rect.bottom;
3470 if (reply->menu_owner) info->flags |= GUI_INMENUMODE;
3471 if (reply->move_size) info->flags |= GUI_INMOVESIZE;
3472 if (reply->caret) info->flags |= GUI_CARETBLINKING;
3480 /******************************************************************
3481 * IsHungAppWindow (USER32.@)
3484 BOOL WINAPI IsHungAppWindow( HWND hWnd )
3487 return !SendMessageTimeoutA(hWnd, WM_NULL, 0, 0, SMTO_ABORTIFHUNG, 5000, &dwResult);