2 * Window messaging support
4 * Copyright 2001 Alexandre Julliard
6 * This library is free software; you can redistribute it and/or
7 * modify it under the terms of the GNU Lesser General Public
8 * License as published by the Free Software Foundation; either
9 * version 2.1 of the License, or (at your option) any later version.
11 * This library is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 * Lesser General Public License for more details.
16 * You should have received a copy of the GNU Lesser General Public
17 * License along with this library; if not, write to the Free Software
18 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
22 #include "wine/port.h"
28 #define WIN32_NO_STATUS
37 #include "wine/unicode.h"
38 #include "wine/server.h"
39 #include "user_private.h"
43 #include "wine/debug.h"
45 WINE_DEFAULT_DEBUG_CHANNEL(msg);
46 WINE_DECLARE_DEBUG_CHANNEL(relay);
47 WINE_DECLARE_DEBUG_CHANNEL(key);
49 #define WM_NCMOUSEFIRST WM_NCMOUSEMOVE
50 #define WM_NCMOUSELAST (WM_NCMOUSEFIRST+(WM_MOUSELAST-WM_MOUSEFIRST))
52 #define MAX_PACK_COUNT 4
53 #define MAX_SENDMSG_RECURSION 64
55 #define SYS_TIMER_RATE 55 /* min. timer rate in ms (actually 54.925)*/
57 /* description of the data fields that need to be packed along with a sent message */
61 const void *data[MAX_PACK_COUNT];
62 size_t size[MAX_PACK_COUNT];
65 /* info about the message currently being received by the current thread */
66 struct received_message_info
68 enum message_type type;
70 UINT flags; /* InSendMessageEx return flags */
71 HWINEVENTHOOK hook; /* winevent hook handle */
72 WINEVENTPROC hook_proc; /* winevent hook proc address */
75 /* structure to group all parameters for sent messages of the various kinds */
76 struct send_message_info
78 enum message_type type;
84 UINT flags; /* flags for SendMessageTimeout */
85 UINT timeout; /* timeout for SendMessageTimeout */
86 SENDASYNCPROC callback; /* callback function for SendMessageCallback */
87 ULONG_PTR data; /* callback data */
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 <= 1) return 0;
624 FIXME( "WM_NCPAINT hdc packing not supported yet\n" );
628 if (!wparam) return 0;
631 /* these contain an HFONT */
634 /* these contain an HDC */
636 case WM_ICONERASEBKGND:
637 case WM_CTLCOLORMSGBOX:
638 case WM_CTLCOLOREDIT:
639 case WM_CTLCOLORLISTBOX:
642 case WM_CTLCOLORSCROLLBAR:
643 case WM_CTLCOLORSTATIC:
646 /* these contain an HGLOBAL */
647 case WM_PAINTCLIPBOARD:
648 case WM_SIZECLIPBOARD:
649 /* these contain HICON */
652 case WM_QUERYDRAGICON:
653 case WM_QUERYPARKICON:
654 /* these contain pointers */
656 case WM_QUERYDROPOBJECT:
660 FIXME( "msg %x (%s) not supported yet\n", message, SPY_GetMsgName(message, hwnd) );
668 /***********************************************************************
671 * Unpack a message received from another process.
673 static BOOL unpack_message( HWND hwnd, UINT message, WPARAM *wparam, LPARAM *lparam,
674 void **buffer, size_t size )
683 CREATESTRUCTW *cs = *buffer;
684 WCHAR *str = (WCHAR *)(cs + 1);
685 if (size < sizeof(*cs)) return FALSE;
687 if (HIWORD(cs->lpszName))
689 if (!check_string( str, size )) return FALSE;
691 size -= (strlenW(str) + 1) * sizeof(WCHAR);
692 str += strlenW(str) + 1;
694 if (HIWORD(cs->lpszClass))
696 if (!check_string( str, size )) return FALSE;
702 case WM_ASKCBFORMATNAME:
703 if (!get_buffer_space( buffer, (*wparam * sizeof(WCHAR)) )) return FALSE;
705 case WM_WININICHANGE:
706 if (!*lparam) return TRUE;
709 case WM_DEVMODECHANGE:
714 if (!check_string( *buffer, size )) return FALSE;
716 case WM_GETMINMAXINFO:
717 minsize = sizeof(MINMAXINFO);
720 minsize = sizeof(DRAWITEMSTRUCT);
723 minsize = sizeof(MEASUREITEMSTRUCT);
726 minsize = sizeof(DELETEITEMSTRUCT);
729 minsize = sizeof(COMPAREITEMSTRUCT);
731 case WM_WINDOWPOSCHANGING:
732 case WM_WINDOWPOSCHANGED:
733 case WM_WINE_SETWINDOWPOS:
734 minsize = sizeof(WINDOWPOS);
738 COPYDATASTRUCT *cp = *buffer;
739 if (size < sizeof(*cp)) return FALSE;
742 minsize = sizeof(*cp) + cp->cbData;
748 /* WM_NOTIFY cannot be sent across processes (MSDN) */
751 minsize = sizeof(HELPINFO);
753 case WM_STYLECHANGING:
754 case WM_STYLECHANGED:
755 minsize = sizeof(STYLESTRUCT);
758 if (!*wparam) minsize = sizeof(RECT);
761 NCCALCSIZE_PARAMS *nc = *buffer;
762 if (size < sizeof(*nc) + sizeof(*nc->lppos)) return FALSE;
763 nc->lppos = (WINDOWPOS *)(nc + 1);
767 if (!*lparam) return TRUE;
768 minsize = sizeof(MSG);
770 case SBM_SETSCROLLINFO:
771 minsize = sizeof(SCROLLINFO);
773 case SBM_GETSCROLLINFO:
774 if (!get_buffer_space( buffer, sizeof(SCROLLINFO ))) return FALSE;
776 case SBM_GETSCROLLBARINFO:
777 if (!get_buffer_space( buffer, sizeof(SCROLLBARINFO ))) return FALSE;
782 if (*wparam || *lparam)
784 if (!get_buffer_space( buffer, 2*sizeof(DWORD) )) return FALSE;
785 if (*wparam) *wparam = (WPARAM)*buffer;
786 if (*lparam) *lparam = (LPARAM)((DWORD *)*buffer + 1);
791 case CB_GETDROPPEDCONTROLRECT:
792 if (!get_buffer_space( buffer, sizeof(RECT) )) return FALSE;
796 minsize = sizeof(RECT);
801 if (size < sizeof(WORD)) return FALSE;
802 len = *(WORD *)*buffer;
803 if (!get_buffer_space( buffer, (len + 1) * sizeof(WCHAR) )) return FALSE;
804 *lparam = (LPARAM)*buffer + sizeof(WORD); /* don't erase WORD at start of buffer */
809 if (!*wparam) return TRUE;
810 minsize = *wparam * sizeof(UINT);
813 case CB_INSERTSTRING:
815 case CB_FINDSTRINGEXACT:
816 case CB_SELECTSTRING:
818 case LB_INSERTSTRING:
820 case LB_FINDSTRINGEXACT:
821 case LB_SELECTSTRING:
822 if (!*buffer) return TRUE;
823 if (!check_string( *buffer, size )) return FALSE;
827 size = sizeof(ULONG_PTR);
828 if (combobox_has_strings( hwnd ))
829 size = (SendMessageW( hwnd, CB_GETLBTEXTLEN, *wparam, 0 ) + 1) * sizeof(WCHAR);
830 if (!get_buffer_space( buffer, size )) return FALSE;
835 size = sizeof(ULONG_PTR);
836 if (listbox_has_strings( hwnd ))
837 size = (SendMessageW( hwnd, LB_GETTEXTLEN, *wparam, 0 ) + 1) * sizeof(WCHAR);
838 if (!get_buffer_space( buffer, size )) return FALSE;
842 if (!get_buffer_space( buffer, *wparam * sizeof(UINT) )) return FALSE;
845 minsize = sizeof(MDINEXTMENU);
846 if (!get_buffer_space( buffer, sizeof(MDINEXTMENU) )) return FALSE;
850 minsize = sizeof(RECT);
851 if (!get_buffer_space( buffer, sizeof(RECT) )) return FALSE;
855 MDICREATESTRUCTW *cs = *buffer;
856 WCHAR *str = (WCHAR *)(cs + 1);
857 if (size < sizeof(*cs)) return FALSE;
859 if (HIWORD(cs->szTitle))
861 if (!check_string( str, size )) return FALSE;
863 size -= (strlenW(str) + 1) * sizeof(WCHAR);
864 str += strlenW(str) + 1;
866 if (HIWORD(cs->szClass))
868 if (!check_string( str, size )) return FALSE;
873 case WM_MDIGETACTIVE:
874 if (!*lparam) return TRUE;
875 if (!get_buffer_space( buffer, sizeof(BOOL) )) return FALSE;
877 case WM_DEVICECHANGE:
878 minsize = sizeof(DEV_BROADCAST_HDR);
880 case WM_WINE_KEYBOARD_LL_HOOK:
881 minsize = sizeof(KBDLLHOOKSTRUCT);
883 case WM_WINE_MOUSE_LL_HOOK:
884 minsize = sizeof(MSLLHOOKSTRUCT);
887 if (*wparam <= 1) return TRUE;
888 FIXME( "WM_NCPAINT hdc unpacking not supported\n" );
891 if (!*wparam) return TRUE;
894 /* these contain an HFONT */
897 /* these contain an HDC */
899 case WM_ICONERASEBKGND:
900 case WM_CTLCOLORMSGBOX:
901 case WM_CTLCOLOREDIT:
902 case WM_CTLCOLORLISTBOX:
905 case WM_CTLCOLORSCROLLBAR:
906 case WM_CTLCOLORSTATIC:
909 /* these contain an HGLOBAL */
910 case WM_PAINTCLIPBOARD:
911 case WM_SIZECLIPBOARD:
912 /* these contain HICON */
915 case WM_QUERYDRAGICON:
916 case WM_QUERYPARKICON:
917 /* these contain pointers */
919 case WM_QUERYDROPOBJECT:
923 FIXME( "msg %x (%s) not supported yet\n", message, SPY_GetMsgName(message, hwnd) );
927 return TRUE; /* message doesn't need any unpacking */
930 /* default exit for most messages: check minsize and store buffer in lparam */
931 if (size < minsize) return FALSE;
932 *lparam = (LPARAM)*buffer;
937 /***********************************************************************
940 * Pack a reply to a message for sending to another process.
942 static void pack_reply( HWND hwnd, UINT message, WPARAM wparam, LPARAM lparam,
943 LRESULT res, struct packed_message *data )
950 push_data( data, (CREATESTRUCTW *)lparam, sizeof(CREATESTRUCTW) );
955 push_data( data, (WCHAR *)lparam, (res + 1) * sizeof(WCHAR) );
957 case WM_GETMINMAXINFO:
958 push_data( data, (MINMAXINFO *)lparam, sizeof(MINMAXINFO) );
961 push_data( data, (MEASUREITEMSTRUCT *)lparam, sizeof(MEASUREITEMSTRUCT) );
963 case WM_WINDOWPOSCHANGING:
964 case WM_WINDOWPOSCHANGED:
965 push_data( data, (WINDOWPOS *)lparam, sizeof(WINDOWPOS) );
968 if (lparam) push_data( data, (MSG *)lparam, sizeof(MSG) );
970 case SBM_GETSCROLLINFO:
971 push_data( data, (SCROLLINFO *)lparam, sizeof(SCROLLINFO) );
975 case CB_GETDROPPEDCONTROLRECT:
978 push_data( data, (RECT *)lparam, sizeof(RECT) );
982 WORD *ptr = (WORD *)lparam;
983 push_data( data, ptr, ptr[-1] * sizeof(WCHAR) );
987 push_data( data, (UINT *)lparam, wparam * sizeof(UINT) );
989 case WM_MDIGETACTIVE:
990 if (lparam) push_data( data, (BOOL *)lparam, sizeof(BOOL) );
994 push_data( data, (RECT *)lparam, sizeof(RECT) );
997 NCCALCSIZE_PARAMS *nc = (NCCALCSIZE_PARAMS *)lparam;
998 push_data( data, nc, sizeof(*nc) );
999 push_data( data, nc->lppos, sizeof(*nc->lppos) );
1005 if (wparam) push_data( data, (DWORD *)wparam, sizeof(DWORD) );
1006 if (lparam) push_data( data, (DWORD *)lparam, sizeof(DWORD) );
1009 push_data( data, (MDINEXTMENU *)lparam, sizeof(MDINEXTMENU) );
1012 push_data( data, (MDICREATESTRUCTW *)lparam, sizeof(MDICREATESTRUCTW) );
1014 case WM_ASKCBFORMATNAME:
1015 push_data( data, (WCHAR *)lparam, (strlenW((WCHAR *)lparam) + 1) * sizeof(WCHAR) );
1021 /***********************************************************************
1024 * Unpack a message reply received from another process.
1026 static void unpack_reply( HWND hwnd, UINT message, WPARAM wparam, LPARAM lparam,
1027 void *buffer, size_t size )
1034 CREATESTRUCTW *cs = (CREATESTRUCTW *)lparam;
1035 LPCWSTR name = cs->lpszName, class = cs->lpszClass;
1036 memcpy( cs, buffer, min( sizeof(*cs), size ));
1037 cs->lpszName = name; /* restore the original pointers */
1038 cs->lpszClass = class;
1042 case WM_ASKCBFORMATNAME:
1043 memcpy( (WCHAR *)lparam, buffer, min( wparam*sizeof(WCHAR), size ));
1045 case WM_GETMINMAXINFO:
1046 memcpy( (MINMAXINFO *)lparam, buffer, min( sizeof(MINMAXINFO), size ));
1048 case WM_MEASUREITEM:
1049 memcpy( (MEASUREITEMSTRUCT *)lparam, buffer, min( sizeof(MEASUREITEMSTRUCT), size ));
1051 case WM_WINDOWPOSCHANGING:
1052 case WM_WINDOWPOSCHANGED:
1053 memcpy( (WINDOWPOS *)lparam, buffer, min( sizeof(WINDOWPOS), size ));
1056 if (lparam) memcpy( (MSG *)lparam, buffer, min( sizeof(MSG), size ));
1058 case SBM_GETSCROLLINFO:
1059 memcpy( (SCROLLINFO *)lparam, buffer, min( sizeof(SCROLLINFO), size ));
1061 case SBM_GETSCROLLBARINFO:
1062 memcpy( (SCROLLBARINFO *)lparam, buffer, min( sizeof(SCROLLBARINFO), size ));
1065 case CB_GETDROPPEDCONTROLRECT:
1066 case LB_GETITEMRECT:
1069 memcpy( (RECT *)lparam, buffer, min( sizeof(RECT), size ));
1072 size = min( size, (size_t)*(WORD *)lparam );
1073 memcpy( (WCHAR *)lparam, buffer, size );
1075 case LB_GETSELITEMS:
1076 memcpy( (UINT *)lparam, buffer, min( wparam*sizeof(UINT), size ));
1080 memcpy( (WCHAR *)lparam, buffer, size );
1083 memcpy( (MDINEXTMENU *)lparam, buffer, min( sizeof(MDINEXTMENU), size ));
1085 case WM_MDIGETACTIVE:
1086 if (lparam) memcpy( (BOOL *)lparam, buffer, min( sizeof(BOOL), size ));
1090 memcpy( (RECT *)lparam, buffer, min( sizeof(RECT), size ));
1093 NCCALCSIZE_PARAMS *nc = (NCCALCSIZE_PARAMS *)lparam;
1094 WINDOWPOS *wp = nc->lppos;
1095 memcpy( nc, buffer, min( sizeof(*nc), size ));
1096 if (size > sizeof(*nc))
1098 size -= sizeof(*nc);
1099 memcpy( wp, (NCCALCSIZE_PARAMS*)buffer + 1, min( sizeof(*wp), size ));
1101 nc->lppos = wp; /* restore the original pointer */
1109 memcpy( (DWORD *)wparam, buffer, min( sizeof(DWORD), size ));
1110 if (size <= sizeof(DWORD)) break;
1111 size -= sizeof(DWORD);
1112 buffer = (DWORD *)buffer + 1;
1114 if (lparam) memcpy( (DWORD *)lparam, buffer, min( sizeof(DWORD), size ));
1118 MDICREATESTRUCTW *cs = (MDICREATESTRUCTW *)lparam;
1119 LPCWSTR title = cs->szTitle, class = cs->szClass;
1120 memcpy( cs, buffer, min( sizeof(*cs), size ));
1121 cs->szTitle = title; /* restore the original pointers */
1122 cs->szClass = class;
1126 ERR( "should not happen: unexpected message %x\n", message );
1132 /***********************************************************************
1135 * Send a reply to a sent message.
1137 static void reply_message( struct received_message_info *info, LRESULT result, BOOL remove )
1139 struct packed_message data;
1140 int i, replied = info->flags & ISMEX_REPLIED;
1142 if (info->flags & ISMEX_NOTIFY) return; /* notify messages don't get replies */
1143 if (!remove && replied) return; /* replied already */
1146 info->flags |= ISMEX_REPLIED;
1148 if (info->type == MSG_OTHER_PROCESS && !replied)
1150 pack_reply( info->msg.hwnd, info->msg.message, info->msg.wParam,
1151 info->msg.lParam, result, &data );
1154 SERVER_START_REQ( reply_message )
1156 req->result = result;
1157 req->remove = remove;
1158 for (i = 0; i < data.count; i++) wine_server_add_data( req, data.data[i], data.size[i] );
1159 wine_server_call( req );
1165 /***********************************************************************
1166 * handle_internal_message
1168 * Handle an internal Wine message instead of calling the window proc.
1170 static LRESULT handle_internal_message( HWND hwnd, UINT msg, WPARAM wparam, LPARAM lparam )
1174 case WM_WINE_DESTROYWINDOW:
1175 return WIN_DestroyWindow( hwnd );
1176 case WM_WINE_SETWINDOWPOS:
1177 if (hwnd == GetDesktopWindow()) return 0;
1178 return USER_Driver->pSetWindowPos( (WINDOWPOS *)lparam );
1179 case WM_WINE_SHOWWINDOW:
1180 if (hwnd == GetDesktopWindow()) return 0;
1181 return ShowWindow( hwnd, wparam );
1182 case WM_WINE_SETPARENT:
1183 if (hwnd == GetDesktopWindow()) return 0;
1184 return (LRESULT)SetParent( hwnd, (HWND)wparam );
1185 case WM_WINE_SETWINDOWLONG:
1186 return WIN_SetWindowLong( hwnd, (short)LOWORD(wparam), HIWORD(wparam), lparam, TRUE );
1187 case WM_WINE_ENABLEWINDOW:
1188 if (hwnd == GetDesktopWindow()) return 0;
1189 return EnableWindow( hwnd, wparam );
1190 case WM_WINE_SETACTIVEWINDOW:
1191 if (hwnd == GetDesktopWindow()) return 0;
1192 return (LRESULT)SetActiveWindow( (HWND)wparam );
1193 case WM_WINE_KEYBOARD_LL_HOOK:
1194 return HOOK_CallHooks( WH_KEYBOARD_LL, HC_ACTION, wparam, lparam, TRUE );
1195 case WM_WINE_MOUSE_LL_HOOK:
1196 return HOOK_CallHooks( WH_MOUSE_LL, HC_ACTION, wparam, lparam, TRUE );
1198 if (msg >= WM_WINE_FIRST_DRIVER_MSG && msg <= WM_WINE_LAST_DRIVER_MSG)
1199 return USER_Driver->pWindowMessage( hwnd, msg, wparam, lparam );
1200 FIXME( "unknown internal message %x\n", msg );
1205 /* since the WM_DDE_ACK response to a WM_DDE_EXECUTE message should contain the handle
1206 * to the memory handle, we keep track (in the server side) of all pairs of handle
1207 * used (the client passes its value and the content of the memory handle), and
1208 * the server stored both values (the client, and the local one, created after the
1209 * content). When a ACK message is generated, the list of pair is searched for a
1210 * matching pair, so that the client memory handle can be returned.
1213 HGLOBAL client_hMem;
1214 HGLOBAL server_hMem;
1217 static struct DDE_pair* dde_pairs;
1218 static int dde_num_alloc;
1219 static int dde_num_used;
1221 static CRITICAL_SECTION dde_crst;
1222 static CRITICAL_SECTION_DEBUG critsect_debug =
1225 { &critsect_debug.ProcessLocksList, &critsect_debug.ProcessLocksList },
1226 0, 0, { (DWORD_PTR)(__FILE__ ": dde_crst") }
1228 static CRITICAL_SECTION dde_crst = { &critsect_debug, -1, 0, 0, 0, 0 };
1230 static BOOL dde_add_pair(HGLOBAL chm, HGLOBAL shm)
1235 EnterCriticalSection(&dde_crst);
1237 /* now remember the pair of hMem on both sides */
1238 if (dde_num_used == dde_num_alloc)
1240 struct DDE_pair* tmp;
1242 tmp = HeapReAlloc( GetProcessHeap(), 0, dde_pairs,
1243 (dde_num_alloc + GROWBY) * sizeof(struct DDE_pair));
1245 tmp = HeapAlloc( GetProcessHeap(), 0,
1246 (dde_num_alloc + GROWBY) * sizeof(struct DDE_pair));
1250 LeaveCriticalSection(&dde_crst);
1254 /* zero out newly allocated part */
1255 memset(&dde_pairs[dde_num_alloc], 0, GROWBY * sizeof(struct DDE_pair));
1256 dde_num_alloc += GROWBY;
1259 for (i = 0; i < dde_num_alloc; i++)
1261 if (dde_pairs[i].server_hMem == 0)
1263 dde_pairs[i].client_hMem = chm;
1264 dde_pairs[i].server_hMem = shm;
1269 LeaveCriticalSection(&dde_crst);
1273 static HGLOBAL dde_get_pair(HGLOBAL shm)
1278 EnterCriticalSection(&dde_crst);
1279 for (i = 0; i < dde_num_alloc; i++)
1281 if (dde_pairs[i].server_hMem == shm)
1283 /* free this pair */
1284 dde_pairs[i].server_hMem = 0;
1286 ret = dde_pairs[i].client_hMem;
1290 LeaveCriticalSection(&dde_crst);
1294 /***********************************************************************
1297 * Post a DDE message
1299 static BOOL post_dde_message( struct packed_message *data, const struct send_message_info *info )
1303 UINT_PTR uiLo, uiHi;
1305 HGLOBAL hunlock = 0;
1309 if (!UnpackDDElParam( info->msg, info->lparam, &uiLo, &uiHi ))
1315 /* DDE messages which don't require packing are:
1324 /* uiHi should contain a hMem from WM_DDE_EXECUTE */
1325 HGLOBAL h = dde_get_pair( (HANDLE)uiHi );
1328 /* send back the value of h on the other side */
1329 push_data( data, &h, sizeof(HGLOBAL) );
1331 TRACE( "send dde-ack %x %08x => %p\n", uiLo, uiHi, h );
1336 /* uiHi should contain either an atom or 0 */
1337 TRACE( "send dde-ack %x atom=%x\n", uiLo, uiHi );
1338 lp = MAKELONG( uiLo, uiHi );
1347 size = GlobalSize( (HGLOBAL)uiLo ) ;
1348 if ((info->msg == WM_DDE_ADVISE && size < sizeof(DDEADVISE)) ||
1349 (info->msg == WM_DDE_DATA && size < sizeof(DDEDATA)) ||
1350 (info->msg == WM_DDE_POKE && size < sizeof(DDEPOKE))
1354 else if (info->msg != WM_DDE_DATA) return FALSE;
1359 if ((ptr = GlobalLock( (HGLOBAL)uiLo) ))
1361 DDEDATA *dde_data = (DDEDATA *)ptr;
1362 TRACE("unused %d, fResponse %d, fRelease %d, fDeferUpd %d, fAckReq %d, cfFormat %d\n",
1363 dde_data->unused, dde_data->fResponse, dde_data->fRelease,
1364 dde_data->reserved, dde_data->fAckReq, dde_data->cfFormat);
1365 push_data( data, ptr, size );
1366 hunlock = (HGLOBAL)uiLo;
1369 TRACE( "send ddepack %u %x\n", size, uiHi );
1371 case WM_DDE_EXECUTE:
1374 if ((ptr = GlobalLock( (HGLOBAL)info->lparam) ))
1376 push_data(data, ptr, GlobalSize( (HGLOBAL)info->lparam ));
1377 /* so that the other side can send it back on ACK */
1379 hunlock = (HGLOBAL)info->lparam;
1384 SERVER_START_REQ( send_message )
1386 req->id = info->dest_tid;
1387 req->type = info->type;
1389 req->win = info->hwnd;
1390 req->msg = info->msg;
1391 req->wparam = info->wparam;
1394 for (i = 0; i < data->count; i++)
1395 wine_server_add_data( req, data->data[i], data->size[i] );
1396 if ((res = wine_server_call( req )))
1398 if (res == STATUS_INVALID_PARAMETER)
1399 /* FIXME: find a STATUS_ value for this one */
1400 SetLastError( ERROR_INVALID_THREAD_ID );
1402 SetLastError( RtlNtStatusToDosError(res) );
1405 FreeDDElParam(info->msg, info->lparam);
1408 if (hunlock) GlobalUnlock(hunlock);
1413 /***********************************************************************
1414 * unpack_dde_message
1416 * Unpack a posted DDE message received from another process.
1418 static BOOL unpack_dde_message( HWND hwnd, UINT message, WPARAM *wparam, LPARAM *lparam,
1419 void **buffer, size_t size )
1421 UINT_PTR uiLo, uiHi;
1430 /* hMem is being passed */
1431 if (size != sizeof(HGLOBAL)) return FALSE;
1432 if (!buffer || !*buffer) return FALSE;
1434 memcpy( &hMem, *buffer, size );
1435 uiHi = (UINT_PTR)hMem;
1436 TRACE("recv dde-ack %x mem=%x[%lx]\n", uiLo, uiHi, GlobalSize( hMem ));
1440 uiLo = LOWORD( *lparam );
1441 uiHi = HIWORD( *lparam );
1442 TRACE("recv dde-ack %x atom=%x\n", uiLo, uiHi);
1444 *lparam = PackDDElParam( WM_DDE_ACK, uiLo, uiHi );
1449 if ((!buffer || !*buffer) && message != WM_DDE_DATA) return FALSE;
1453 if (!(hMem = GlobalAlloc( GMEM_MOVEABLE|GMEM_DDESHARE, size )))
1455 if ((ptr = GlobalLock( hMem )))
1457 memcpy( ptr, *buffer, size );
1458 GlobalUnlock( hMem );
1466 uiLo = (UINT_PTR)hMem;
1468 *lparam = PackDDElParam( message, uiLo, uiHi );
1470 case WM_DDE_EXECUTE:
1473 if (!buffer || !*buffer) return FALSE;
1474 if (!(hMem = GlobalAlloc( GMEM_MOVEABLE|GMEM_DDESHARE, size ))) return FALSE;
1475 if ((ptr = GlobalLock( hMem )))
1477 memcpy( ptr, *buffer, size );
1478 GlobalUnlock( hMem );
1479 TRACE( "exec: pairing c=%08lx s=%08lx\n", *lparam, (DWORD)hMem );
1480 if (!dde_add_pair( (HGLOBAL)*lparam, hMem ))
1491 } else return FALSE;
1492 *lparam = (LPARAM)hMem;
1498 /***********************************************************************
1501 * Call a window procedure and the corresponding hooks.
1503 static LRESULT call_window_proc( HWND hwnd, UINT msg, WPARAM wparam, LPARAM lparam,
1504 BOOL unicode, BOOL same_thread )
1506 struct user_thread_info *thread_info = get_user_thread_info();
1510 CWPRETSTRUCT cwpret;
1512 if (thread_info->recursion_count > MAX_SENDMSG_RECURSION) return 0;
1513 thread_info->recursion_count++;
1515 if (msg & 0x80000000)
1517 result = handle_internal_message( hwnd, msg, wparam, lparam );
1521 /* first the WH_CALLWNDPROC hook */
1522 hwnd = WIN_GetFullHandle( hwnd );
1523 cwp.lParam = lparam;
1524 cwp.wParam = wparam;
1527 HOOK_CallHooks( WH_CALLWNDPROC, HC_ACTION, same_thread, (LPARAM)&cwp, unicode );
1529 /* now call the window procedure */
1532 if (!(winproc = (WNDPROC)GetWindowLongPtrW( hwnd, GWLP_WNDPROC ))) goto done;
1533 result = CallWindowProcW( winproc, hwnd, msg, wparam, lparam );
1537 if (!(winproc = (WNDPROC)GetWindowLongPtrA( hwnd, GWLP_WNDPROC ))) goto done;
1538 result = CallWindowProcA( winproc, hwnd, msg, wparam, lparam );
1541 /* and finally the WH_CALLWNDPROCRET hook */
1542 cwpret.lResult = result;
1543 cwpret.lParam = lparam;
1544 cwpret.wParam = wparam;
1545 cwpret.message = msg;
1547 HOOK_CallHooks( WH_CALLWNDPROCRET, HC_ACTION, same_thread, (LPARAM)&cwpret, unicode );
1549 thread_info->recursion_count--;
1554 /***********************************************************************
1555 * send_parent_notify
1557 * Send a WM_PARENTNOTIFY to all ancestors of the given window, unless
1558 * the window has the WS_EX_NOPARENTNOTIFY style.
1560 static void send_parent_notify( HWND hwnd, WORD event, WORD idChild, POINT pt )
1562 /* pt has to be in the client coordinates of the parent window */
1563 MapWindowPoints( 0, hwnd, &pt, 1 );
1568 if (!(GetWindowLongW( hwnd, GWL_STYLE ) & WS_CHILD)) break;
1569 if (GetWindowLongW( hwnd, GWL_EXSTYLE ) & WS_EX_NOPARENTNOTIFY) break;
1570 if (!(parent = GetParent(hwnd))) break;
1571 if (parent == GetDesktopWindow()) break;
1572 MapWindowPoints( hwnd, parent, &pt, 1 );
1574 SendMessageW( hwnd, WM_PARENTNOTIFY,
1575 MAKEWPARAM( event, idChild ), MAKELPARAM( pt.x, pt.y ) );
1580 /***********************************************************************
1581 * accept_hardware_message
1583 * Tell the server we have passed the message to the app
1584 * (even though we may end up dropping it later on)
1586 static void accept_hardware_message( UINT hw_id, BOOL remove, HWND new_hwnd )
1588 SERVER_START_REQ( accept_hardware_message )
1591 req->remove = remove;
1592 req->new_win = new_hwnd;
1593 if (wine_server_call( req ))
1594 FIXME("Failed to reply to MSG_HARDWARE message. Message may not be removed from queue.\n");
1600 /***********************************************************************
1601 * process_keyboard_message
1603 * returns TRUE if the contents of 'msg' should be passed to the application
1605 static BOOL process_keyboard_message( MSG *msg, UINT hw_id, HWND hwnd_filter,
1606 UINT first, UINT last, BOOL remove )
1610 /* FIXME: is this really the right place for this hook? */
1611 event.message = msg->message;
1612 event.hwnd = msg->hwnd;
1613 event.time = msg->time;
1614 event.paramL = (msg->wParam & 0xFF) | (HIWORD(msg->lParam) << 8);
1615 event.paramH = msg->lParam & 0x7FFF;
1616 if (HIWORD(msg->lParam) & 0x0100) event.paramH |= 0x8000; /* special_key - bit */
1617 HOOK_CallHooks( WH_JOURNALRECORD, HC_ACTION, 0, (LPARAM)&event, TRUE );
1619 /* check message filters */
1620 if (msg->message < first || msg->message > last) return FALSE;
1621 if (!check_hwnd_filter( msg, hwnd_filter )) return FALSE;
1625 /* Handle F1 key by sending out WM_HELP message */
1626 if ((msg->message == WM_KEYUP) &&
1627 (msg->wParam == VK_F1) &&
1628 (msg->hwnd != GetDesktopWindow()) &&
1629 !MENU_IsMenuActive())
1632 hi.cbSize = sizeof(HELPINFO);
1633 hi.iContextType = HELPINFO_WINDOW;
1634 hi.iCtrlId = GetWindowLongPtrA( msg->hwnd, GWLP_ID );
1635 hi.hItemHandle = msg->hwnd;
1636 hi.dwContextId = GetWindowContextHelpId( msg->hwnd );
1637 hi.MousePos = msg->pt;
1638 SendMessageW( msg->hwnd, WM_HELP, 0, (LPARAM)&hi );
1642 if (HOOK_CallHooks( WH_KEYBOARD, remove ? HC_ACTION : HC_NOREMOVE,
1643 LOWORD(msg->wParam), msg->lParam, TRUE ))
1645 /* skip this message */
1646 HOOK_CallHooks( WH_CBT, HCBT_KEYSKIPPED, LOWORD(msg->wParam), msg->lParam, TRUE );
1647 accept_hardware_message( hw_id, TRUE, 0 );
1650 accept_hardware_message( hw_id, remove, 0 );
1655 /***********************************************************************
1656 * process_mouse_message
1658 * returns TRUE if the contents of 'msg' should be passed to the application
1660 static BOOL process_mouse_message( MSG *msg, UINT hw_id, ULONG_PTR extra_info, HWND hwnd_filter,
1661 UINT first, UINT last, BOOL remove )
1670 MOUSEHOOKSTRUCT hook;
1673 /* find the window to dispatch this mouse message to */
1675 GetGUIThreadInfo( GetCurrentThreadId(), &info );
1676 if (info.hwndCapture)
1679 msg->hwnd = info.hwndCapture;
1683 msg->hwnd = WINPOS_WindowFromPoint( msg->hwnd, msg->pt, &hittest );
1686 if (!msg->hwnd || !WIN_IsCurrentThread( msg->hwnd ))
1688 accept_hardware_message( hw_id, TRUE, msg->hwnd );
1692 /* FIXME: is this really the right place for this hook? */
1693 event.message = msg->message;
1694 event.time = msg->time;
1695 event.hwnd = msg->hwnd;
1696 event.paramL = msg->pt.x;
1697 event.paramH = msg->pt.y;
1698 HOOK_CallHooks( WH_JOURNALRECORD, HC_ACTION, 0, (LPARAM)&event, TRUE );
1700 if (!check_hwnd_filter( msg, hwnd_filter )) return FALSE;
1703 message = msg->message;
1704 /* Note: windows has no concept of a non-client wheel message */
1705 if (message != WM_MOUSEWHEEL)
1707 if (hittest != HTCLIENT)
1709 message += WM_NCMOUSEMOVE - WM_MOUSEMOVE;
1710 msg->wParam = hittest;
1714 /* coordinates don't get translated while tracking a menu */
1715 /* FIXME: should differentiate popups and top-level menus */
1716 if (!(info.flags & GUI_INMENUMODE))
1717 ScreenToClient( msg->hwnd, &pt );
1720 msg->lParam = MAKELONG( pt.x, pt.y );
1722 /* translate double clicks */
1724 if ((msg->message == WM_LBUTTONDOWN) ||
1725 (msg->message == WM_RBUTTONDOWN) ||
1726 (msg->message == WM_MBUTTONDOWN) ||
1727 (msg->message == WM_XBUTTONDOWN))
1729 BOOL update = remove;
1731 /* translate double clicks -
1732 * note that ...MOUSEMOVEs can slip in between
1733 * ...BUTTONDOWN and ...BUTTONDBLCLK messages */
1735 if ((info.flags & (GUI_INMENUMODE|GUI_INMOVESIZE)) ||
1736 hittest != HTCLIENT ||
1737 (GetClassLongA( msg->hwnd, GCL_STYLE ) & CS_DBLCLKS))
1739 if ((msg->message == clk_msg.message) &&
1740 (msg->hwnd == clk_msg.hwnd) &&
1741 (msg->wParam == clk_msg.wParam) &&
1742 (msg->time - clk_msg.time < GetDoubleClickTime()) &&
1743 (abs(msg->pt.x - clk_msg.pt.x) < GetSystemMetrics(SM_CXDOUBLECLK)/2) &&
1744 (abs(msg->pt.y - clk_msg.pt.y) < GetSystemMetrics(SM_CYDOUBLECLK)/2))
1746 message += (WM_LBUTTONDBLCLK - WM_LBUTTONDOWN);
1749 clk_msg.message = 0; /* clear the double click conditions */
1754 if (message < first || message > last) return FALSE;
1755 /* update static double click conditions */
1756 if (update) clk_msg = *msg;
1760 if (message < first || message > last) return FALSE;
1763 /* message is accepted now (but may still get dropped) */
1766 hook.hwnd = msg->hwnd;
1767 hook.wHitTestCode = hittest;
1768 hook.dwExtraInfo = extra_info;
1769 if (HOOK_CallHooks( WH_MOUSE, remove ? HC_ACTION : HC_NOREMOVE,
1770 message, (LPARAM)&hook, TRUE ))
1773 hook.hwnd = msg->hwnd;
1774 hook.wHitTestCode = hittest;
1775 hook.dwExtraInfo = extra_info;
1776 HOOK_CallHooks( WH_CBT, HCBT_CLICKSKIPPED, message, (LPARAM)&hook, TRUE );
1777 accept_hardware_message( hw_id, TRUE, 0 );
1781 if ((hittest == HTERROR) || (hittest == HTNOWHERE))
1783 SendMessageW( msg->hwnd, WM_SETCURSOR, (WPARAM)msg->hwnd,
1784 MAKELONG( hittest, msg->message ));
1785 accept_hardware_message( hw_id, TRUE, 0 );
1789 accept_hardware_message( hw_id, remove, 0 );
1791 if (!remove || info.hwndCapture)
1793 msg->message = message;
1799 if ((msg->message == WM_LBUTTONDOWN) ||
1800 (msg->message == WM_RBUTTONDOWN) ||
1801 (msg->message == WM_MBUTTONDOWN) ||
1802 (msg->message == WM_XBUTTONDOWN))
1804 /* Send the WM_PARENTNOTIFY,
1805 * note that even for double/nonclient clicks
1806 * notification message is still WM_L/M/RBUTTONDOWN.
1808 send_parent_notify( msg->hwnd, msg->message, 0, msg->pt );
1810 /* Activate the window if needed */
1812 if (msg->hwnd != info.hwndActive)
1814 HWND hwndTop = msg->hwnd;
1817 if ((GetWindowLongW( hwndTop, GWL_STYLE ) & (WS_POPUP|WS_CHILD)) != WS_CHILD) break;
1818 hwndTop = GetParent( hwndTop );
1821 if (hwndTop && hwndTop != GetDesktopWindow())
1823 LONG ret = SendMessageW( msg->hwnd, WM_MOUSEACTIVATE, (WPARAM)hwndTop,
1824 MAKELONG( hittest, msg->message ) );
1827 case MA_NOACTIVATEANDEAT:
1832 case MA_ACTIVATEANDEAT:
1837 if (!FOCUS_MouseActivate( hwndTop )) eatMsg = TRUE;
1840 WARN( "unknown WM_MOUSEACTIVATE code %ld\n", ret );
1847 /* send the WM_SETCURSOR message */
1849 /* Windows sends the normal mouse message as the message parameter
1850 in the WM_SETCURSOR message even if it's non-client mouse message */
1851 SendMessageW( msg->hwnd, WM_SETCURSOR, (WPARAM)msg->hwnd, MAKELONG( hittest, msg->message ));
1853 msg->message = message;
1858 /***********************************************************************
1859 * process_hardware_message
1861 * Process a hardware message; return TRUE if message should be passed on to the app
1863 static BOOL process_hardware_message( MSG *msg, UINT hw_id, ULONG_PTR extra_info, HWND hwnd_filter,
1864 UINT first, UINT last, BOOL remove )
1866 if (is_keyboard_message( msg->message ))
1867 return process_keyboard_message( msg, hw_id, hwnd_filter, first, last, remove );
1869 if (is_mouse_message( msg->message ))
1870 return process_mouse_message( msg, hw_id, extra_info, hwnd_filter, first, last, remove );
1872 ERR( "unknown message type %x\n", msg->message );
1877 /***********************************************************************
1878 * call_sendmsg_callback
1880 * Call the callback function of SendMessageCallback.
1882 static inline void call_sendmsg_callback( SENDASYNCPROC callback, HWND hwnd, UINT msg,
1883 ULONG_PTR data, LRESULT result )
1885 if (TRACE_ON(relay))
1886 DPRINTF( "%04lx:Call message callback %p (hwnd=%p,msg=%s,data=%08lx,result=%08lx)\n",
1887 GetCurrentThreadId(), callback, hwnd, SPY_GetMsgName( msg, hwnd ),
1889 callback( hwnd, msg, data, result );
1890 if (TRACE_ON(relay))
1891 DPRINTF( "%04lx:Ret message callback %p (hwnd=%p,msg=%s,data=%08lx,result=%08lx)\n",
1892 GetCurrentThreadId(), callback, hwnd, SPY_GetMsgName( msg, hwnd ),
1897 /***********************************************************************
1900 * Retrieve the hook procedure real value for a module-relative proc
1902 static void *get_hook_proc( void *proc, const WCHAR *module )
1906 if (!(mod = GetModuleHandleW(module)))
1908 TRACE( "loading %s\n", debugstr_w(module) );
1909 /* FIXME: the library will never be freed */
1910 if (!(mod = LoadLibraryW(module))) return NULL;
1912 return (char *)mod + (ULONG_PTR)proc;
1916 /***********************************************************************
1919 * Peek for a message matching the given parameters. Return FALSE if none available.
1920 * All pending sent messages are processed before returning.
1922 static BOOL peek_message( MSG *msg, HWND hwnd, UINT first, UINT last, int flags )
1925 ULONG_PTR extra_info = 0;
1926 struct user_thread_info *thread_info = get_user_thread_info();
1927 struct received_message_info info, *old_info;
1928 unsigned int hw_id = 0; /* id of previous hardware message */
1930 if (!first && !last) last = ~0;
1935 void *buffer = NULL;
1936 size_t size = 0, buffer_size = 0;
1938 do /* loop while buffer is too small */
1940 if (buffer_size && !(buffer = HeapAlloc( GetProcessHeap(), 0, buffer_size )))
1942 SERVER_START_REQ( get_message )
1945 req->get_win = hwnd;
1946 req->get_first = first;
1947 req->get_last = last;
1949 if (buffer_size) wine_server_set_reply( req, buffer, buffer_size );
1950 if (!(res = wine_server_call( req )))
1952 size = wine_server_reply_size( reply );
1953 info.type = reply->type;
1954 info.msg.hwnd = reply->win;
1955 info.msg.message = reply->msg;
1956 info.msg.wParam = reply->wparam;
1957 info.msg.lParam = reply->lparam;
1958 info.msg.time = reply->time;
1959 info.msg.pt.x = reply->x;
1960 info.msg.pt.y = reply->y;
1961 info.hook = reply->hook;
1962 info.hook_proc = reply->hook_proc;
1963 hw_id = reply->hw_id;
1964 extra_info = reply->info;
1965 thread_info->active_hooks = reply->active_hooks;
1969 HeapFree( GetProcessHeap(), 0, buffer );
1970 buffer_size = reply->total;
1974 } while (res == STATUS_BUFFER_OVERFLOW);
1976 if (res) return FALSE;
1978 TRACE( "got type %d msg %x (%s) hwnd %p wp %x lp %lx\n",
1979 info.type, info.msg.message,
1980 (info.type == MSG_WINEVENT) ? "MSG_WINEVENT" : SPY_GetMsgName(info.msg.message, info.msg.hwnd),
1981 info.msg.hwnd, info.msg.wParam, info.msg.lParam );
1987 info.flags = ISMEX_SEND;
1990 info.flags = ISMEX_NOTIFY;
1993 info.flags = ISMEX_CALLBACK;
1995 case MSG_CALLBACK_RESULT:
1996 call_sendmsg_callback( (SENDASYNCPROC)info.msg.wParam, info.msg.hwnd,
1997 info.msg.message, extra_info, info.msg.lParam );
2002 WCHAR module[MAX_PATH];
2003 size = min( size, (MAX_PATH - 1) * sizeof(WCHAR) );
2004 memcpy( module, buffer, size );
2005 module[size / sizeof(WCHAR)] = 0;
2006 if (!(info.hook_proc = get_hook_proc( info.hook_proc, module )))
2008 ERR( "invalid winevent hook module name %s\n", debugstr_w(module) );
2012 if (TRACE_ON(relay))
2013 DPRINTF( "%04lx:Call winevent proc %p (hook=%p,event=%x,hwnd=%p,object_id=%x,child_id=%lx,tid=%04lx,time=%lx)\n",
2014 GetCurrentThreadId(), info.hook_proc,
2015 info.hook, info.msg.message, info.msg.hwnd, info.msg.wParam,
2016 info.msg.lParam, extra_info, info.msg.time);
2018 info.hook_proc( info.hook, info.msg.message, info.msg.hwnd, info.msg.wParam,
2019 info.msg.lParam, extra_info, info.msg.time );
2021 if (TRACE_ON(relay))
2022 DPRINTF( "%04lx:Ret winevent proc %p (hook=%p,event=%x,hwnd=%p,object_id=%x,child_id=%lx,tid=%04lx,time=%lx)\n",
2023 GetCurrentThreadId(), info.hook_proc,
2024 info.hook, info.msg.message, info.msg.hwnd, info.msg.wParam,
2025 info.msg.lParam, extra_info, info.msg.time);
2027 case MSG_OTHER_PROCESS:
2028 info.flags = ISMEX_SEND;
2029 if (!unpack_message( info.msg.hwnd, info.msg.message, &info.msg.wParam,
2030 &info.msg.lParam, &buffer, size ))
2033 reply_message( &info, 0, TRUE );
2038 if (!process_hardware_message( &info.msg, hw_id, extra_info,
2039 hwnd, first, last, flags & GET_MSG_REMOVE ))
2041 TRACE("dropping msg %x\n", info.msg.message );
2042 goto next; /* ignore it */
2044 thread_info->GetMessagePosVal = MAKELONG( info.msg.pt.x, info.msg.pt.y );
2047 thread_info->GetMessageExtraInfoVal = extra_info;
2048 if (info.msg.message >= WM_DDE_FIRST && info.msg.message <= WM_DDE_LAST)
2050 if (!unpack_dde_message( info.msg.hwnd, info.msg.message, &info.msg.wParam,
2051 &info.msg.lParam, &buffer, size ))
2052 goto next; /* ignore it */
2055 HeapFree( GetProcessHeap(), 0, buffer );
2059 /* if we get here, we have a sent message; call the window procedure */
2060 old_info = thread_info->receive_info;
2061 thread_info->receive_info = &info;
2062 result = call_window_proc( info.msg.hwnd, info.msg.message, info.msg.wParam,
2063 info.msg.lParam, (info.type != MSG_ASCII), FALSE );
2064 reply_message( &info, result, TRUE );
2065 thread_info->receive_info = old_info;
2067 HeapFree( GetProcessHeap(), 0, buffer );
2072 /***********************************************************************
2073 * process_sent_messages
2075 * Process all pending sent messages.
2077 inline static void process_sent_messages(void)
2080 peek_message( &msg, 0, 0, 0, GET_MSG_REMOVE | GET_MSG_SENT_ONLY );
2084 /***********************************************************************
2085 * get_server_queue_handle
2087 * Get a handle to the server message queue for the current thread.
2089 static HANDLE get_server_queue_handle(void)
2091 struct user_thread_info *thread_info = get_user_thread_info();
2094 if (!(ret = thread_info->server_queue))
2096 SERVER_START_REQ( get_msg_queue )
2098 wine_server_call( req );
2099 ret = reply->handle;
2102 thread_info->server_queue = ret;
2103 if (!ret) ERR( "Cannot get server thread queue\n" );
2109 /***********************************************************************
2110 * wait_message_reply
2112 * Wait until a sent message gets replied to.
2114 static void wait_message_reply( UINT flags )
2116 HANDLE server_queue = get_server_queue_handle();
2120 unsigned int wake_bits = 0, changed_bits = 0;
2123 SERVER_START_REQ( set_queue_mask )
2125 req->wake_mask = QS_SMRESULT | ((flags & SMTO_BLOCK) ? 0 : QS_SENDMESSAGE);
2126 req->changed_mask = req->wake_mask;
2128 if (!wine_server_call( req ))
2130 wake_bits = reply->wake_bits;
2131 changed_bits = reply->changed_bits;
2136 if (wake_bits & QS_SMRESULT) return; /* got a result */
2137 if (wake_bits & QS_SENDMESSAGE)
2139 /* Process the sent message immediately */
2140 process_sent_messages();
2144 /* now wait for it */
2146 ReleaseThunkLock( &dwlc );
2147 res = USER_Driver->pMsgWaitForMultipleObjectsEx( 1, &server_queue,
2148 INFINITE, QS_SENDMESSAGE, 0 );
2149 if (dwlc) RestoreThunkLock( dwlc );
2153 /***********************************************************************
2154 * put_message_in_queue
2156 * Put a sent message into the destination queue.
2157 * For inter-process message, reply_size is set to expected size of reply data.
2159 static BOOL put_message_in_queue( const struct send_message_info *info, size_t *reply_size )
2161 struct packed_message data;
2165 /* Check for INFINITE timeout for compatibility with Win9x,
2166 * although Windows >= NT does not do so
2168 if (info->type != MSG_NOTIFY &&
2169 info->type != MSG_CALLBACK &&
2170 info->type != MSG_POSTED &&
2171 info->timeout != INFINITE)
2172 timeout = info->timeout;
2175 if (info->type == MSG_OTHER_PROCESS)
2177 *reply_size = pack_message( info->hwnd, info->msg, info->wparam, info->lparam, &data );
2178 if (data.count == -1)
2180 WARN( "cannot pack message %x\n", info->msg );
2184 else if (info->type == MSG_POSTED && info->msg >= WM_DDE_FIRST && info->msg <= WM_DDE_LAST)
2186 return post_dde_message( &data, info );
2189 SERVER_START_REQ( send_message )
2191 req->id = info->dest_tid;
2192 req->type = info->type;
2194 req->win = info->hwnd;
2195 req->msg = info->msg;
2196 req->wparam = info->wparam;
2197 req->lparam = info->lparam;
2198 req->timeout = timeout;
2200 if (info->type == MSG_CALLBACK)
2202 req->callback = info->callback;
2203 req->info = info->data;
2206 if (info->flags & SMTO_ABORTIFHUNG) req->flags |= SEND_MSG_ABORT_IF_HUNG;
2207 for (i = 0; i < data.count; i++) wine_server_add_data( req, data.data[i], data.size[i] );
2208 if ((res = wine_server_call( req )))
2210 if (res == STATUS_INVALID_PARAMETER)
2211 /* FIXME: find a STATUS_ value for this one */
2212 SetLastError( ERROR_INVALID_THREAD_ID );
2214 SetLastError( RtlNtStatusToDosError(res) );
2222 /***********************************************************************
2225 * Retrieve a message reply from the server.
2227 static LRESULT retrieve_reply( const struct send_message_info *info,
2228 size_t reply_size, LRESULT *result )
2231 void *reply_data = NULL;
2235 if (!(reply_data = HeapAlloc( GetProcessHeap(), 0, reply_size )))
2237 WARN( "no memory for reply, will be truncated\n" );
2241 SERVER_START_REQ( get_message_reply )
2244 if (reply_size) wine_server_set_reply( req, reply_data, reply_size );
2245 if (!(status = wine_server_call( req ))) *result = reply->result;
2246 reply_size = wine_server_reply_size( reply );
2249 if (!status && reply_size)
2250 unpack_reply( info->hwnd, info->msg, info->wparam, info->lparam, reply_data, reply_size );
2252 HeapFree( GetProcessHeap(), 0, reply_data );
2254 TRACE( "hwnd %p msg %x (%s) wp %x lp %lx got reply %lx (err=%ld)\n",
2255 info->hwnd, info->msg, SPY_GetMsgName(info->msg, info->hwnd), info->wparam,
2256 info->lparam, *result, status );
2258 /* MSDN states that last error is 0 on timeout, but at least NT4 returns ERROR_TIMEOUT */
2259 if (status) SetLastError( RtlNtStatusToDosError(status) );
2264 /***********************************************************************
2265 * send_inter_thread_message
2267 static LRESULT send_inter_thread_message( const struct send_message_info *info, LRESULT *res_ptr )
2269 size_t reply_size = 0;
2271 TRACE( "hwnd %p msg %x (%s) wp %x lp %lx\n",
2272 info->hwnd, info->msg, SPY_GetMsgName(info->msg, info->hwnd), info->wparam, info->lparam );
2274 USER_CheckNotLock();
2276 if (!put_message_in_queue( info, &reply_size )) return 0;
2278 /* there's no reply to wait for on notify/callback messages */
2279 if (info->type == MSG_NOTIFY || info->type == MSG_CALLBACK) return 1;
2281 wait_message_reply( info->flags );
2282 return retrieve_reply( info, reply_size, res_ptr );
2286 /***********************************************************************
2287 * MSG_SendInternalMessageTimeout
2289 * Same as SendMessageTimeoutW but sends the message to a specific thread
2290 * without requiring a window handle. Only works for internal Wine messages.
2292 LRESULT MSG_SendInternalMessageTimeout( DWORD dest_pid, DWORD dest_tid,
2293 UINT msg, WPARAM wparam, LPARAM lparam,
2294 UINT flags, UINT timeout, PDWORD_PTR res_ptr )
2296 struct send_message_info info;
2297 LRESULT ret, result;
2299 assert( msg & 0x80000000 ); /* must be an internal Wine message */
2301 info.type = MSG_UNICODE;
2302 info.dest_tid = dest_tid;
2305 info.wparam = wparam;
2306 info.lparam = lparam;
2308 info.timeout = timeout;
2310 if (USER_IsExitingThread( dest_tid )) return 0;
2312 if (dest_tid == GetCurrentThreadId())
2314 result = handle_internal_message( 0, msg, wparam, lparam );
2319 if (dest_pid != GetCurrentProcessId()) info.type = MSG_OTHER_PROCESS;
2320 ret = send_inter_thread_message( &info, &result );
2322 if (ret && res_ptr) *res_ptr = result;
2327 /***********************************************************************
2328 * SendMessageTimeoutW (USER32.@)
2330 LRESULT WINAPI SendMessageTimeoutW( HWND hwnd, UINT msg, WPARAM wparam, LPARAM lparam,
2331 UINT flags, UINT timeout, PDWORD_PTR res_ptr )
2333 struct send_message_info info;
2335 LRESULT ret, result;
2337 info.type = MSG_UNICODE;
2340 info.wparam = wparam;
2341 info.lparam = lparam;
2343 info.timeout = timeout;
2345 if (is_broadcast(hwnd))
2347 EnumWindows( broadcast_message_callback, (LPARAM)&info );
2348 if (res_ptr) *res_ptr = 1;
2352 if (!(info.dest_tid = GetWindowThreadProcessId( hwnd, &dest_pid ))) return 0;
2354 if (USER_IsExitingThread( info.dest_tid )) return 0;
2356 SPY_EnterMessage( SPY_SENDMESSAGE, hwnd, msg, wparam, lparam );
2358 if (info.dest_tid == GetCurrentThreadId())
2360 result = call_window_proc( hwnd, msg, wparam, lparam, TRUE, TRUE );
2365 if (dest_pid != GetCurrentProcessId()) info.type = MSG_OTHER_PROCESS;
2366 ret = send_inter_thread_message( &info, &result );
2369 SPY_ExitMessage( SPY_RESULT_OK, hwnd, msg, result, wparam, lparam );
2370 if (ret && res_ptr) *res_ptr = result;
2374 static LRESULT send_inter_thread_callback( HWND hwnd, UINT msg, WPARAM wp, LPARAM lp,
2375 LRESULT *result, void *arg )
2377 struct send_message_info *info = arg;
2382 return send_inter_thread_message( info, result );
2385 /***********************************************************************
2386 * SendMessageTimeoutA (USER32.@)
2388 LRESULT WINAPI SendMessageTimeoutA( HWND hwnd, UINT msg, WPARAM wparam, LPARAM lparam,
2389 UINT flags, UINT timeout, PDWORD_PTR res_ptr )
2391 struct send_message_info info;
2393 LRESULT ret, result;
2395 info.type = MSG_ASCII;
2398 info.wparam = wparam;
2399 info.lparam = lparam;
2401 info.timeout = timeout;
2403 if (is_broadcast(hwnd))
2405 EnumWindows( broadcast_message_callback, (LPARAM)&info );
2406 if (res_ptr) *res_ptr = 1;
2410 if (!(info.dest_tid = GetWindowThreadProcessId( hwnd, &dest_pid ))) return 0;
2412 if (USER_IsExitingThread( info.dest_tid )) return 0;
2414 SPY_EnterMessage( SPY_SENDMESSAGE, hwnd, msg, wparam, lparam );
2416 if (info.dest_tid == GetCurrentThreadId())
2418 result = call_window_proc( hwnd, msg, wparam, lparam, FALSE, TRUE );
2421 else if (dest_pid == GetCurrentProcessId())
2423 ret = send_inter_thread_message( &info, &result );
2427 /* inter-process message: need to map to Unicode */
2428 info.type = MSG_OTHER_PROCESS;
2429 if (is_unicode_message( info.msg ))
2430 ret = WINPROC_CallProcAtoW( send_inter_thread_callback, info.hwnd, info.msg,
2431 info.wparam, info.lparam, &result, &info );
2432 else ret = send_inter_thread_message( &info, &result );
2434 SPY_ExitMessage( SPY_RESULT_OK, hwnd, msg, result, wparam, lparam );
2435 if (ret && res_ptr) *res_ptr = result;
2440 /***********************************************************************
2441 * SendMessageW (USER32.@)
2443 LRESULT WINAPI SendMessageW( HWND hwnd, UINT msg, WPARAM wparam, LPARAM lparam )
2446 SendMessageTimeoutW( hwnd, msg, wparam, lparam, SMTO_NORMAL, 0, &res );
2451 /***********************************************************************
2452 * SendMessageA (USER32.@)
2454 LRESULT WINAPI SendMessageA( HWND hwnd, UINT msg, WPARAM wparam, LPARAM lparam )
2457 SendMessageTimeoutA( hwnd, msg, wparam, lparam, SMTO_NORMAL, 0, &res );
2462 /***********************************************************************
2463 * SendNotifyMessageA (USER32.@)
2465 BOOL WINAPI SendNotifyMessageA( HWND hwnd, UINT msg, WPARAM wparam, LPARAM lparam )
2467 return SendNotifyMessageW( hwnd, msg, map_wparam_AtoW( msg, wparam ), lparam );
2471 /***********************************************************************
2472 * SendNotifyMessageW (USER32.@)
2474 BOOL WINAPI SendNotifyMessageW( HWND hwnd, UINT msg, WPARAM wparam, LPARAM lparam )
2476 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 (!(info.dest_tid = GetWindowThreadProcessId( hwnd, NULL ))) return FALSE;
2500 if (USER_IsExitingThread( info.dest_tid )) return TRUE;
2502 if (info.dest_tid == GetCurrentThreadId())
2504 call_window_proc( hwnd, msg, wparam, lparam, TRUE, TRUE );
2507 return send_inter_thread_message( &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;
2531 if (is_pointer_message(msg))
2533 SetLastError( ERROR_MESSAGE_SYNC_ONLY );
2537 info.type = MSG_CALLBACK;
2540 info.wparam = wparam;
2541 info.lparam = lparam;
2542 info.callback = callback;
2546 if (is_broadcast(hwnd))
2548 EnumWindows( broadcast_message_callback, (LPARAM)&info );
2552 if (!(info.dest_tid = GetWindowThreadProcessId( hwnd, NULL ))) return FALSE;
2554 if (USER_IsExitingThread( info.dest_tid )) return TRUE;
2556 if (info.dest_tid == GetCurrentThreadId())
2558 result = call_window_proc( hwnd, msg, wparam, lparam, TRUE, TRUE );
2559 call_sendmsg_callback( callback, hwnd, msg, data, result );
2562 FIXME( "callback will not be called\n" );
2563 return send_inter_thread_message( &info, &result );
2567 /***********************************************************************
2568 * ReplyMessage (USER32.@)
2570 BOOL WINAPI ReplyMessage( LRESULT result )
2572 struct received_message_info *info = get_user_thread_info()->receive_info;
2574 if (!info) return FALSE;
2575 reply_message( info, result, FALSE );
2580 /***********************************************************************
2581 * InSendMessage (USER32.@)
2583 BOOL WINAPI InSendMessage(void)
2585 return (InSendMessageEx(NULL) & (ISMEX_SEND|ISMEX_REPLIED)) == ISMEX_SEND;
2589 /***********************************************************************
2590 * InSendMessageEx (USER32.@)
2592 DWORD WINAPI InSendMessageEx( LPVOID reserved )
2594 struct received_message_info *info = get_user_thread_info()->receive_info;
2596 if (info) return info->flags;
2597 return ISMEX_NOSEND;
2601 /***********************************************************************
2602 * PostMessageA (USER32.@)
2604 BOOL WINAPI PostMessageA( HWND hwnd, UINT msg, WPARAM wparam, LPARAM lparam )
2606 return PostMessageW( hwnd, msg, map_wparam_AtoW( msg, wparam ), lparam );
2610 /***********************************************************************
2611 * PostMessageW (USER32.@)
2613 BOOL WINAPI PostMessageW( HWND hwnd, UINT msg, WPARAM wparam, LPARAM lparam )
2615 struct send_message_info info;
2617 if (is_pointer_message( msg ))
2619 SetLastError( ERROR_MESSAGE_SYNC_ONLY );
2623 TRACE( "hwnd %p msg %x (%s) wp %x lp %lx\n",
2624 hwnd, msg, SPY_GetMsgName(msg, hwnd), wparam, lparam );
2626 info.type = MSG_POSTED;
2629 info.wparam = wparam;
2630 info.lparam = lparam;
2633 if (is_broadcast(hwnd))
2635 EnumWindows( broadcast_message_callback, (LPARAM)&info );
2639 if (!hwnd) return PostThreadMessageW( GetCurrentThreadId(), msg, wparam, lparam );
2641 if (!(info.dest_tid = GetWindowThreadProcessId( hwnd, NULL ))) return FALSE;
2643 if (USER_IsExitingThread( info.dest_tid )) return TRUE;
2645 return put_message_in_queue( &info, NULL );
2649 /**********************************************************************
2650 * PostThreadMessageA (USER32.@)
2652 BOOL WINAPI PostThreadMessageA( DWORD thread, UINT msg, WPARAM wparam, LPARAM lparam )
2654 return PostThreadMessageW( thread, msg, map_wparam_AtoW( msg, wparam ), lparam );
2658 /**********************************************************************
2659 * PostThreadMessageW (USER32.@)
2661 BOOL WINAPI PostThreadMessageW( DWORD thread, UINT msg, WPARAM wparam, LPARAM lparam )
2663 struct send_message_info info;
2665 if (is_pointer_message( msg ))
2667 SetLastError( ERROR_MESSAGE_SYNC_ONLY );
2670 if (USER_IsExitingThread( thread )) return TRUE;
2672 info.type = MSG_POSTED;
2673 info.dest_tid = thread;
2676 info.wparam = wparam;
2677 info.lparam = lparam;
2679 return put_message_in_queue( &info, NULL );
2683 /***********************************************************************
2684 * PostQuitMessage (USER32.@)
2686 * Posts a quit message to the current thread's message queue.
2689 * exit_code [I] Exit code to return from message loop.
2695 * This function is not the same as calling:
2696 *|PostThreadMessage(GetCurrentThreadId(), WM_QUIT, exit_code, 0);
2697 * It instead sets a flag in the message queue that signals it to generate
2698 * a WM_QUIT message when there are no other pending sent or posted messages
2701 void WINAPI PostQuitMessage( INT exit_code )
2703 SERVER_START_REQ( post_quit_message )
2705 req->exit_code = exit_code;
2706 wine_server_call( req );
2712 /***********************************************************************
2713 * PeekMessageW (USER32.@)
2715 BOOL WINAPI PeekMessageW( MSG *msg_out, HWND hwnd, UINT first, UINT last, UINT flags )
2717 struct user_thread_info *thread_info = get_user_thread_info();
2721 FIXME("PM_QS_xxxx flags (%04x) are not handled\n", flags >> 16);
2723 USER_CheckNotLock();
2725 /* check for graphics events */
2726 USER_Driver->pMsgWaitForMultipleObjectsEx( 0, NULL, 0, QS_ALLINPUT, 0 );
2728 hwnd = WIN_GetFullHandle( hwnd );
2732 if (!peek_message( &msg, hwnd, first, last, (flags & PM_REMOVE) ? GET_MSG_REMOVE : 0 ))
2734 if (!(flags & PM_NOYIELD))
2737 ReleaseThunkLock(&count);
2739 if (count) RestoreThunkLock(count);
2743 if (msg.message & 0x80000000)
2745 if (!(flags & PM_REMOVE))
2747 /* Have to remove the message explicitly.
2748 Do this before handling it, because the message handler may
2749 call PeekMessage again */
2750 peek_message( &msg, msg.hwnd, msg.message, msg.message, GET_MSG_REMOVE );
2752 handle_internal_message( msg.hwnd, msg.message, msg.wParam, msg.lParam );
2757 thread_info->GetMessageTimeVal = msg.time;
2758 msg.pt.x = LOWORD( thread_info->GetMessagePosVal );
2759 msg.pt.y = HIWORD( thread_info->GetMessagePosVal );
2761 HOOK_CallHooks( WH_GETMESSAGE, HC_ACTION, flags & PM_REMOVE, (LPARAM)&msg, TRUE );
2763 /* copy back our internal safe copy of message data to msg_out.
2764 * msg_out is a variable from the *program*, so it can't be used
2765 * internally as it can get "corrupted" by our use of SendMessage()
2766 * (back to the program) inside the message handling itself. */
2769 SetLastError( ERROR_NOACCESS );
2777 /***********************************************************************
2778 * PeekMessageA (USER32.@)
2780 BOOL WINAPI PeekMessageA( MSG *msg, HWND hwnd, UINT first, UINT last, UINT flags )
2782 BOOL ret = PeekMessageW( msg, hwnd, first, last, flags );
2783 if (ret) msg->wParam = map_wparam_WtoA( msg->message, msg->wParam );
2788 /***********************************************************************
2789 * GetMessageW (USER32.@)
2791 BOOL WINAPI GetMessageW( MSG *msg, HWND hwnd, UINT first, UINT last )
2793 HANDLE server_queue = get_server_queue_handle();
2794 int mask = QS_POSTMESSAGE | QS_SENDMESSAGE; /* Always selected */
2798 if ((first <= WM_KEYLAST) && (last >= WM_KEYFIRST)) mask |= QS_KEY;
2799 if ( ((first <= WM_MOUSELAST) && (last >= WM_MOUSEFIRST)) ||
2800 ((first <= WM_NCMOUSELAST) && (last >= WM_NCMOUSEFIRST)) ) mask |= QS_MOUSE;
2801 if ((first <= WM_TIMER) && (last >= WM_TIMER)) mask |= QS_TIMER;
2802 if ((first <= WM_SYSTIMER) && (last >= WM_SYSTIMER)) mask |= QS_TIMER;
2803 if ((first <= WM_PAINT) && (last >= WM_PAINT)) mask |= QS_PAINT;
2805 else mask |= QS_MOUSE | QS_KEY | QS_TIMER | QS_PAINT;
2807 while (!PeekMessageW( msg, hwnd, first, last, PM_REMOVE ))
2809 /* wait until one of the bits is set */
2810 unsigned int wake_bits = 0, changed_bits = 0;
2813 SERVER_START_REQ( set_queue_mask )
2815 req->wake_mask = QS_SENDMESSAGE;
2816 req->changed_mask = mask;
2818 if (!wine_server_call( req ))
2820 wake_bits = reply->wake_bits;
2821 changed_bits = reply->changed_bits;
2826 if (changed_bits & mask) continue;
2827 if (wake_bits & QS_SENDMESSAGE) continue;
2829 TRACE( "(%04lx) mask=%08x, bits=%08x, changed=%08x, waiting\n",
2830 GetCurrentThreadId(), mask, wake_bits, changed_bits );
2832 ReleaseThunkLock( &dwlc );
2833 USER_Driver->pMsgWaitForMultipleObjectsEx( 1, &server_queue, INFINITE, QS_ALLINPUT, 0 );
2834 if (dwlc) RestoreThunkLock( dwlc );
2837 return (msg->message != WM_QUIT);
2841 /***********************************************************************
2842 * GetMessageA (USER32.@)
2844 BOOL WINAPI GetMessageA( MSG *msg, HWND hwnd, UINT first, UINT last )
2846 GetMessageW( msg, hwnd, first, last );
2847 msg->wParam = map_wparam_WtoA( msg->message, msg->wParam );
2848 return (msg->message != WM_QUIT);
2852 /***********************************************************************
2853 * IsDialogMessageA (USER32.@)
2854 * IsDialogMessage (USER32.@)
2856 BOOL WINAPI IsDialogMessageA( HWND hwndDlg, LPMSG pmsg )
2859 msg.wParam = map_wparam_AtoW( msg.message, msg.wParam );
2860 return IsDialogMessageW( hwndDlg, &msg );
2864 /***********************************************************************
2865 * TranslateMessage (USER32.@)
2867 * Implementation of TranslateMessage.
2869 * TranslateMessage translates virtual-key messages into character-messages,
2871 * WM_KEYDOWN/WM_KEYUP combinations produce a WM_CHAR or WM_DEADCHAR message.
2872 * ditto replacing WM_* with WM_SYS*
2873 * This produces WM_CHAR messages only for keys mapped to ASCII characters
2874 * by the keyboard driver.
2876 * If the message is WM_KEYDOWN, WM_KEYUP, WM_SYSKEYDOWN, or WM_SYSKEYUP, the
2877 * return value is nonzero, regardless of the translation.
2880 BOOL WINAPI TranslateMessage( const MSG *msg )
2886 if (msg->message < WM_KEYFIRST || msg->message > WM_KEYLAST) return FALSE;
2887 if (msg->message != WM_KEYDOWN && msg->message != WM_SYSKEYDOWN) return TRUE;
2889 TRACE_(key)("Translating key %s (%04x), scancode %02x\n",
2890 SPY_GetVKeyName(msg->wParam), msg->wParam, LOBYTE(HIWORD(msg->lParam)));
2892 GetKeyboardState( state );
2893 /* FIXME : should handle ToUnicode yielding 2 */
2894 switch (ToUnicode(msg->wParam, HIWORD(msg->lParam), state, wp, 2, 0))
2897 message = (msg->message == WM_KEYDOWN) ? WM_CHAR : WM_SYSCHAR;
2898 TRACE_(key)("1 -> PostMessageW(%p,%s,%04x,%08lx)\n",
2899 msg->hwnd, SPY_GetMsgName(message, msg->hwnd), wp[0], msg->lParam);
2900 PostMessageW( msg->hwnd, message, wp[0], msg->lParam );
2904 message = (msg->message == WM_KEYDOWN) ? WM_DEADCHAR : WM_SYSDEADCHAR;
2905 TRACE_(key)("-1 -> PostMessageW(%p,%s,%04x,%08lx)\n",
2906 msg->hwnd, SPY_GetMsgName(message, msg->hwnd), wp[0], msg->lParam);
2907 PostMessageW( msg->hwnd, message, wp[0], msg->lParam );
2914 /***********************************************************************
2915 * DispatchMessageA (USER32.@)
2917 * See DispatchMessageW.
2919 LONG WINAPI DispatchMessageA( const MSG* msg )
2925 /* Process timer messages */
2926 if ((msg->message == WM_TIMER) || (msg->message == WM_SYSTIMER))
2928 if (msg->lParam) return CallWindowProcA( (WNDPROC)msg->lParam, msg->hwnd,
2929 msg->message, msg->wParam, GetTickCount() );
2932 if (!(wndPtr = WIN_GetPtr( msg->hwnd )))
2934 if (msg->hwnd) SetLastError( ERROR_INVALID_WINDOW_HANDLE );
2937 if (wndPtr == WND_OTHER_PROCESS || wndPtr == WND_DESKTOP)
2939 if (IsWindow( msg->hwnd )) SetLastError( ERROR_MESSAGE_SYNC_ONLY );
2940 else SetLastError( ERROR_INVALID_WINDOW_HANDLE );
2943 if (wndPtr->tid != GetCurrentThreadId())
2945 SetLastError( ERROR_MESSAGE_SYNC_ONLY );
2946 WIN_ReleasePtr( wndPtr );
2949 winproc = wndPtr->winproc;
2950 WIN_ReleasePtr( wndPtr );
2952 SPY_EnterMessage( SPY_DISPATCHMESSAGE, msg->hwnd, msg->message,
2953 msg->wParam, msg->lParam );
2954 retval = CallWindowProcA( winproc, msg->hwnd, msg->message,
2955 msg->wParam, msg->lParam );
2956 SPY_ExitMessage( SPY_RESULT_OK, msg->hwnd, msg->message, retval,
2957 msg->wParam, msg->lParam );
2959 if (msg->message == WM_PAINT)
2961 /* send a WM_NCPAINT and WM_ERASEBKGND if the non-client area is still invalid */
2962 HRGN hrgn = CreateRectRgn( 0, 0, 0, 0 );
2963 GetUpdateRgn( msg->hwnd, hrgn, TRUE );
2964 DeleteObject( hrgn );
2970 /***********************************************************************
2971 * DispatchMessageW (USER32.@) Process a message
2973 * Process the message specified in the structure *_msg_.
2975 * If the lpMsg parameter points to a WM_TIMER message and the
2976 * parameter of the WM_TIMER message is not NULL, the lParam parameter
2977 * points to the function that is called instead of the window
2980 * The message must be valid.
2984 * DispatchMessage() returns the result of the window procedure invoked.
2991 LONG WINAPI DispatchMessageW( const MSG* msg )
2997 /* Process timer messages */
2998 if ((msg->message == WM_TIMER) || (msg->message == WM_SYSTIMER))
3000 if (msg->lParam) return CallWindowProcW( (WNDPROC)msg->lParam, msg->hwnd,
3001 msg->message, msg->wParam, GetTickCount() );
3004 if (!(wndPtr = WIN_GetPtr( msg->hwnd )))
3006 if (msg->hwnd) SetLastError( ERROR_INVALID_WINDOW_HANDLE );
3009 if (wndPtr == WND_OTHER_PROCESS || wndPtr == WND_DESKTOP)
3011 if (IsWindow( msg->hwnd )) SetLastError( ERROR_MESSAGE_SYNC_ONLY );
3012 else SetLastError( ERROR_INVALID_WINDOW_HANDLE );
3015 if (wndPtr->tid != GetCurrentThreadId())
3017 SetLastError( ERROR_MESSAGE_SYNC_ONLY );
3018 WIN_ReleasePtr( wndPtr );
3021 winproc = wndPtr->winproc;
3022 WIN_ReleasePtr( wndPtr );
3024 SPY_EnterMessage( SPY_DISPATCHMESSAGE, msg->hwnd, msg->message,
3025 msg->wParam, msg->lParam );
3026 retval = CallWindowProcW( winproc, msg->hwnd, msg->message,
3027 msg->wParam, msg->lParam );
3028 SPY_ExitMessage( SPY_RESULT_OK, msg->hwnd, msg->message, retval,
3029 msg->wParam, msg->lParam );
3031 if (msg->message == WM_PAINT)
3033 /* send a WM_NCPAINT and WM_ERASEBKGND if the non-client area is still invalid */
3034 HRGN hrgn = CreateRectRgn( 0, 0, 0, 0 );
3035 GetUpdateRgn( msg->hwnd, hrgn, TRUE );
3036 DeleteObject( hrgn );
3042 /***********************************************************************
3043 * GetMessagePos (USER.119)
3044 * GetMessagePos (USER32.@)
3046 * The GetMessagePos() function returns a long value representing a
3047 * cursor position, in screen coordinates, when the last message
3048 * retrieved by the GetMessage() function occurs. The x-coordinate is
3049 * in the low-order word of the return value, the y-coordinate is in
3050 * the high-order word. The application can use the MAKEPOINT()
3051 * macro to obtain a POINT structure from the return value.
3053 * For the current cursor position, use GetCursorPos().
3057 * Cursor position of last message on success, zero on failure.
3064 DWORD WINAPI GetMessagePos(void)
3066 return get_user_thread_info()->GetMessagePosVal;
3070 /***********************************************************************
3071 * GetMessageTime (USER.120)
3072 * GetMessageTime (USER32.@)
3074 * GetMessageTime() returns the message time for the last message
3075 * retrieved by the function. The time is measured in milliseconds with
3076 * the same offset as GetTickCount().
3078 * Since the tick count wraps, this is only useful for moderately short
3079 * relative time comparisons.
3083 * Time of last message on success, zero on failure.
3085 LONG WINAPI GetMessageTime(void)
3087 return get_user_thread_info()->GetMessageTimeVal;
3091 /***********************************************************************
3092 * GetMessageExtraInfo (USER.288)
3093 * GetMessageExtraInfo (USER32.@)
3095 LPARAM WINAPI GetMessageExtraInfo(void)
3097 return get_user_thread_info()->GetMessageExtraInfoVal;
3101 /***********************************************************************
3102 * SetMessageExtraInfo (USER32.@)
3104 LPARAM WINAPI SetMessageExtraInfo(LPARAM lParam)
3106 struct user_thread_info *thread_info = get_user_thread_info();
3107 LONG old_value = thread_info->GetMessageExtraInfoVal;
3108 thread_info->GetMessageExtraInfoVal = lParam;
3113 /***********************************************************************
3114 * WaitMessage (USER.112) Suspend thread pending messages
3115 * WaitMessage (USER32.@) Suspend thread pending messages
3117 * WaitMessage() suspends a thread until events appear in the thread's
3120 BOOL WINAPI WaitMessage(void)
3122 return (MsgWaitForMultipleObjectsEx( 0, NULL, INFINITE, QS_ALLINPUT, 0 ) != WAIT_FAILED);
3126 /***********************************************************************
3127 * MsgWaitForMultipleObjectsEx (USER32.@)
3129 DWORD WINAPI MsgWaitForMultipleObjectsEx( DWORD count, CONST HANDLE *pHandles,
3130 DWORD timeout, DWORD mask, DWORD flags )
3132 HANDLE handles[MAXIMUM_WAIT_OBJECTS];
3135 if (count > MAXIMUM_WAIT_OBJECTS-1)
3137 SetLastError( ERROR_INVALID_PARAMETER );
3141 /* set the queue mask */
3142 SERVER_START_REQ( set_queue_mask )
3144 req->wake_mask = (flags & MWMO_INPUTAVAILABLE) ? mask : 0;
3145 req->changed_mask = mask;
3147 wine_server_call( req );
3151 /* Add the thread event to the handle list */
3152 for (i = 0; i < count; i++) handles[i] = pHandles[i];
3153 handles[count] = get_server_queue_handle();
3155 ReleaseThunkLock( &lock );
3156 ret = USER_Driver->pMsgWaitForMultipleObjectsEx( count+1, handles, timeout, mask, flags );
3157 if (ret == count+1) ret = count; /* pretend the msg queue is ready */
3158 if (lock) RestoreThunkLock( lock );
3163 /***********************************************************************
3164 * MsgWaitForMultipleObjects (USER32.@)
3166 DWORD WINAPI MsgWaitForMultipleObjects( DWORD count, CONST HANDLE *handles,
3167 BOOL wait_all, DWORD timeout, DWORD mask )
3169 return MsgWaitForMultipleObjectsEx( count, handles, timeout, mask,
3170 wait_all ? MWMO_WAITALL : 0 );
3174 /***********************************************************************
3175 * WaitForInputIdle (USER32.@)
3177 DWORD WINAPI WaitForInputIdle( HANDLE hProcess, DWORD dwTimeOut )
3179 DWORD start_time, elapsed, ret;
3182 handles[0] = hProcess;
3183 SERVER_START_REQ( get_process_idle_event )
3185 req->handle = hProcess;
3186 if (!(ret = wine_server_call_err( req ))) handles[1] = reply->event;
3189 if (ret) return WAIT_FAILED; /* error */
3190 if (!handles[1]) return 0; /* no event to wait on */
3192 start_time = GetTickCount();
3195 TRACE("waiting for %p\n", handles[1] );
3198 ret = MsgWaitForMultipleObjects ( 2, handles, FALSE, dwTimeOut - elapsed, QS_SENDMESSAGE );
3203 case WAIT_OBJECT_0+2:
3204 process_sent_messages();
3208 TRACE("timeout or error\n");
3211 TRACE("finished\n");
3214 if (dwTimeOut != INFINITE)
3216 elapsed = GetTickCount() - start_time;
3217 if (elapsed > dwTimeOut)
3223 return WAIT_TIMEOUT;
3227 /***********************************************************************
3228 * UserYield (USER.332)
3230 void WINAPI UserYield16(void)
3234 /* Handle sent messages */
3235 process_sent_messages();
3238 ReleaseThunkLock(&count);
3242 RestoreThunkLock(count);
3243 /* Handle sent messages again */
3244 process_sent_messages();
3249 /***********************************************************************
3250 * RegisterWindowMessageA (USER32.@)
3251 * RegisterWindowMessage (USER.118)
3253 UINT WINAPI RegisterWindowMessageA( LPCSTR str )
3255 UINT ret = GlobalAddAtomA(str);
3256 TRACE("%s, ret=%x\n", str, ret);
3261 /***********************************************************************
3262 * RegisterWindowMessageW (USER32.@)
3264 UINT WINAPI RegisterWindowMessageW( LPCWSTR str )
3266 UINT ret = GlobalAddAtomW(str);
3267 TRACE("%s ret=%x\n", debugstr_w(str), ret);
3272 /***********************************************************************
3273 * BroadcastSystemMessageA (USER32.@)
3274 * BroadcastSystemMessage (USER32.@)
3276 LONG WINAPI BroadcastSystemMessageA( DWORD flags, LPDWORD recipients, UINT msg, WPARAM wp, LPARAM lp )
3278 if ((*recipients & BSM_APPLICATIONS) || (*recipients == BSM_ALLCOMPONENTS))
3280 FIXME( "(%08lx,%08lx,%08x,%08x,%08lx): semi-stub!\n", flags, *recipients, msg, wp, lp );
3281 PostMessageA( HWND_BROADCAST, msg, wp, lp );
3286 FIXME( "(%08lx,%08lx,%08x,%08x,%08lx): stub!\n", flags, *recipients, msg, wp, lp);
3292 /***********************************************************************
3293 * BroadcastSystemMessageW (USER32.@)
3295 LONG WINAPI BroadcastSystemMessageW( DWORD flags, LPDWORD recipients, UINT msg, WPARAM wp, LPARAM lp )
3297 if ((*recipients & BSM_APPLICATIONS) || (*recipients == BSM_ALLCOMPONENTS))
3299 FIXME( "(%08lx,%08lx,%08x,%08x,%08lx): semi-stub!\n", flags, *recipients, msg, wp, lp );
3300 PostMessageW( HWND_BROADCAST, msg, wp, lp );
3305 FIXME( "(%08lx,%08lx,%08x,%08x,%08lx): stub!\n", flags, *recipients, msg, wp, lp );
3311 /***********************************************************************
3312 * SetMessageQueue (USER32.@)
3314 BOOL WINAPI SetMessageQueue( INT size )
3316 /* now obsolete the message queue will be expanded dynamically as necessary */
3321 /***********************************************************************
3322 * MessageBeep (USER32.@)
3324 BOOL WINAPI MessageBeep( UINT i )
3327 SystemParametersInfoA( SPI_GETBEEP, 0, &active, FALSE );
3328 if (active) USER_Driver->pBeep();
3333 /***********************************************************************
3334 * SetTimer (USER32.@)
3336 UINT_PTR WINAPI SetTimer( HWND hwnd, UINT_PTR id, UINT timeout, TIMERPROC proc )
3339 WNDPROC winproc = 0;
3341 if (proc) winproc = WINPROC_AllocProc( (WNDPROC)proc, NULL );
3343 SERVER_START_REQ( set_win_timer )
3346 req->msg = WM_TIMER;
3348 req->rate = max( timeout, SYS_TIMER_RATE );
3349 req->lparam = (unsigned long)winproc;
3350 if (!wine_server_call_err( req ))
3353 if (!ret) ret = TRUE;
3359 TRACE("Added %p %x %p timeout %d\n", hwnd, id, winproc, timeout );
3364 /***********************************************************************
3365 * SetSystemTimer (USER32.@)
3367 UINT_PTR WINAPI SetSystemTimer( HWND hwnd, UINT_PTR id, UINT timeout, TIMERPROC proc )
3370 WNDPROC winproc = 0;
3372 if (proc) winproc = WINPROC_AllocProc( (WNDPROC)proc, NULL );
3374 SERVER_START_REQ( set_win_timer )
3377 req->msg = WM_SYSTIMER;
3379 req->rate = max( timeout, SYS_TIMER_RATE );
3380 req->lparam = (unsigned long)winproc;
3381 if (!wine_server_call_err( req ))
3384 if (!ret) ret = TRUE;
3390 TRACE("Added %p %x %p timeout %d\n", hwnd, id, winproc, timeout );
3395 /***********************************************************************
3396 * KillTimer (USER32.@)
3398 BOOL WINAPI KillTimer( HWND hwnd, UINT_PTR id )
3402 TRACE("%p %d\n", hwnd, id );
3404 SERVER_START_REQ( kill_win_timer )
3407 req->msg = WM_TIMER;
3409 ret = !wine_server_call_err( req );
3416 /***********************************************************************
3417 * KillSystemTimer (USER32.@)
3419 BOOL WINAPI KillSystemTimer( HWND hwnd, UINT_PTR id )
3423 TRACE("%p %d\n", hwnd, id );
3425 SERVER_START_REQ( kill_win_timer )
3428 req->msg = WM_SYSTIMER;
3430 ret = !wine_server_call_err( req );
3437 /**********************************************************************
3438 * GetGUIThreadInfo (USER32.@)
3440 BOOL WINAPI GetGUIThreadInfo( DWORD id, GUITHREADINFO *info )
3444 SERVER_START_REQ( get_thread_input )
3447 if ((ret = !wine_server_call_err( req )))
3450 info->hwndActive = reply->active;
3451 info->hwndFocus = reply->focus;
3452 info->hwndCapture = reply->capture;
3453 info->hwndMenuOwner = reply->menu_owner;
3454 info->hwndMoveSize = reply->move_size;
3455 info->hwndCaret = reply->caret;
3456 info->rcCaret.left = reply->rect.left;
3457 info->rcCaret.top = reply->rect.top;
3458 info->rcCaret.right = reply->rect.right;
3459 info->rcCaret.bottom = reply->rect.bottom;
3460 if (reply->menu_owner) info->flags |= GUI_INMENUMODE;
3461 if (reply->move_size) info->flags |= GUI_INMOVESIZE;
3462 if (reply->caret) info->flags |= GUI_CARETBLINKING;
3470 /******************************************************************
3471 * IsHungAppWindow (USER32.@)
3474 BOOL WINAPI IsHungAppWindow( HWND hWnd )
3477 return !SendMessageTimeoutA(hWnd, WM_NULL, 0, 0, SMTO_ABORTIFHUNG, 5000, &dwResult);