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"
35 #include "wine/unicode.h"
36 #include "wine/server.h"
38 #include "user_private.h"
41 #include "wine/debug.h"
43 WINE_DEFAULT_DEBUG_CHANNEL(msg);
44 WINE_DECLARE_DEBUG_CHANNEL(relay);
46 #define WM_NCMOUSEFIRST WM_NCMOUSEMOVE
47 #define WM_NCMOUSELAST WM_NCMBUTTONDBLCLK
49 #define MAX_PACK_COUNT 4
51 #define SYS_TIMER_RATE 55 /* min. timer rate in ms (actually 54.925)*/
53 /* description of the data fields that need to be packed along with a sent message */
57 const void *data[MAX_PACK_COUNT];
58 size_t size[MAX_PACK_COUNT];
61 /* info about the message currently being received by the current thread */
62 struct received_message_info
64 enum message_type type;
66 UINT flags; /* InSendMessageEx return flags */
67 HWINEVENTHOOK hook; /* winevent hook handle */
68 WINEVENTPROC hook_proc; /* winevent hook proc address */
71 /* structure to group all parameters for sent messages of the various kinds */
72 struct send_message_info
74 enum message_type type;
79 UINT flags; /* flags for SendMessageTimeout */
80 UINT timeout; /* timeout for SendMessageTimeout */
81 SENDASYNCPROC callback; /* callback function for SendMessageCallback */
82 ULONG_PTR data; /* callback data */
86 /* flag for messages that contain pointers */
87 /* 32 messages per entry, messages 0..31 map to bits 0..31 */
89 #define SET(msg) (1 << ((msg) & 31))
91 static const unsigned int message_pointer_flags[] =
94 SET(WM_CREATE) | SET(WM_SETTEXT) | SET(WM_GETTEXT) |
95 SET(WM_WININICHANGE) | SET(WM_DEVMODECHANGE),
97 SET(WM_GETMINMAXINFO) | SET(WM_DRAWITEM) | SET(WM_MEASUREITEM) | SET(WM_DELETEITEM) |
100 SET(WM_WINDOWPOSCHANGING) | SET(WM_WINDOWPOSCHANGED) | SET(WM_COPYDATA) |
101 SET(WM_NOTIFY) | SET(WM_HELP),
103 SET(WM_STYLECHANGING) | SET(WM_STYLECHANGED),
105 SET(WM_NCCREATE) | SET(WM_NCCALCSIZE) | SET(WM_GETDLGCODE),
107 SET(EM_GETSEL) | SET(EM_GETRECT) | SET(EM_SETRECT) | SET(EM_SETRECTNP),
109 SET(EM_REPLACESEL) | SET(EM_GETLINE) | SET(EM_SETTABSTOPS),
111 SET(SBM_GETRANGE) | SET(SBM_SETSCROLLINFO) | SET(SBM_GETSCROLLINFO) | SET(SBM_GETSCROLLBARINFO),
117 SET(CB_GETEDITSEL) | SET(CB_ADDSTRING) | SET(CB_DIR) | SET(CB_GETLBTEXT) |
118 SET(CB_INSERTSTRING) | SET(CB_FINDSTRING) | SET(CB_SELECTSTRING) |
119 SET(CB_GETDROPPEDCONTROLRECT) | SET(CB_FINDSTRINGEXACT),
123 SET(LB_ADDSTRING) | SET(LB_INSERTSTRING) | SET(LB_GETTEXT) | SET(LB_SELECTSTRING) |
124 SET(LB_DIR) | SET(LB_FINDSTRING) |
125 SET(LB_GETSELITEMS) | SET(LB_SETTABSTOPS) | SET(LB_ADDFILE) | SET(LB_GETITEMRECT),
127 SET(LB_FINDSTRINGEXACT),
133 SET(WM_NEXTMENU) | SET(WM_SIZING) | SET(WM_MOVING) | SET(WM_DEVICECHANGE),
135 SET(WM_MDICREATE) | SET(WM_MDIGETACTIVE) | SET(WM_DROPOBJECT) |
136 SET(WM_QUERYDROPOBJECT) | SET(WM_DRAGLOOP) | SET(WM_DRAGSELECT) | SET(WM_DRAGMOVE),
150 SET(WM_ASKCBFORMATNAME)
153 /* flags for messages that contain Unicode strings */
154 static const unsigned int message_unicode_flags[] =
157 SET(WM_CREATE) | SET(WM_SETTEXT) | SET(WM_GETTEXT) | SET(WM_GETTEXTLENGTH) |
158 SET(WM_WININICHANGE) | SET(WM_DEVMODECHANGE),
170 SET(EM_REPLACESEL) | SET(EM_GETLINE) | SET(EM_SETPASSWORDCHAR),
174 SET(WM_CHAR) | SET(WM_DEADCHAR) | SET(WM_SYSCHAR) | SET(WM_SYSDEADCHAR),
178 SET(CB_ADDSTRING) | SET(CB_DIR) | SET(CB_GETLBTEXT) | SET(CB_GETLBTEXTLEN) |
179 SET(CB_INSERTSTRING) | SET(CB_FINDSTRING) | SET(CB_SELECTSTRING) | SET(CB_FINDSTRINGEXACT),
183 SET(LB_ADDSTRING) | SET(LB_INSERTSTRING) | SET(LB_GETTEXT) | SET(LB_GETTEXTLEN) |
184 SET(LB_SELECTSTRING) | SET(LB_DIR) | SET(LB_FINDSTRING) | SET(LB_ADDFILE),
186 SET(LB_FINDSTRINGEXACT),
208 SET(WM_PAINTCLIPBOARD) | SET(WM_SIZECLIPBOARD) | SET(WM_ASKCBFORMATNAME)
211 /* check whether a given message type includes pointers */
212 inline static int is_pointer_message( UINT message )
214 if (message >= 8*sizeof(message_pointer_flags)) return FALSE;
215 return (message_pointer_flags[message / 32] & SET(message)) != 0;
218 /* check whether a given message type contains Unicode (or ASCII) chars */
219 inline static int is_unicode_message( UINT message )
221 if (message >= 8*sizeof(message_unicode_flags)) return FALSE;
222 return (message_unicode_flags[message / 32] & SET(message)) != 0;
227 /* add a data field to a packed message */
228 inline static void push_data( struct packed_message *data, const void *ptr, size_t size )
230 data->data[data->count] = ptr;
231 data->size[data->count] = size;
235 /* add a string to a packed message */
236 inline static void push_string( struct packed_message *data, LPCWSTR str )
238 push_data( data, str, (strlenW(str) + 1) * sizeof(WCHAR) );
241 /* retrieve a pointer to data from a packed message and increment the buffer pointer */
242 inline static void *get_data( void **buffer, size_t size )
245 *buffer = (char *)*buffer + size;
249 /* make sure that the buffer contains a valid null-terminated Unicode string */
250 inline static BOOL check_string( LPCWSTR str, size_t size )
252 for (size /= sizeof(WCHAR); size; size--, str++)
253 if (!*str) return TRUE;
257 /* make sure that there is space for 'size' bytes in buffer, growing it if needed */
258 inline static void *get_buffer_space( void **buffer, size_t size )
264 if (!(ret = HeapReAlloc( GetProcessHeap(), 0, *buffer, size )))
265 HeapFree( GetProcessHeap(), 0, *buffer );
267 else ret = HeapAlloc( GetProcessHeap(), 0, size );
273 /* retrieve a string pointer from packed data */
274 inline static LPWSTR get_string( void **buffer )
276 return get_data( buffer, (strlenW( (LPWSTR)*buffer ) + 1) * sizeof(WCHAR) );
279 /* check whether a combobox expects strings or ids in CB_ADDSTRING/CB_INSERTSTRING */
280 inline static BOOL combobox_has_strings( HWND hwnd )
282 DWORD style = GetWindowLongA( hwnd, GWL_STYLE );
283 return (!(style & (CBS_OWNERDRAWFIXED | CBS_OWNERDRAWVARIABLE)) || (style & CBS_HASSTRINGS));
286 /* check whether a listbox expects strings or ids in LB_ADDSTRING/LB_INSERTSTRING */
287 inline static BOOL listbox_has_strings( HWND hwnd )
289 DWORD style = GetWindowLongA( hwnd, GWL_STYLE );
290 return (!(style & (LBS_OWNERDRAWFIXED | LBS_OWNERDRAWVARIABLE)) || (style & LBS_HASSTRINGS));
294 /***********************************************************************
295 * broadcast_message_callback
297 * Helper callback for broadcasting messages.
299 static BOOL CALLBACK broadcast_message_callback( HWND hwnd, LPARAM lparam )
301 struct send_message_info *info = (struct send_message_info *)lparam;
302 if (!(GetWindowLongW( hwnd, GWL_STYLE ) & (WS_POPUP|WS_CAPTION))) return TRUE;
306 SendMessageTimeoutW( hwnd, info->msg, info->wparam, info->lparam,
307 info->flags, info->timeout, NULL );
310 SendMessageTimeoutA( hwnd, info->msg, info->wparam, info->lparam,
311 info->flags, info->timeout, NULL );
314 SendNotifyMessageW( hwnd, info->msg, info->wparam, info->lparam );
317 SendMessageCallbackW( hwnd, info->msg, info->wparam, info->lparam,
318 info->callback, info->data );
321 PostMessageW( hwnd, info->msg, info->wparam, info->lparam );
324 ERR( "bad type %d\n", info->type );
331 /***********************************************************************
334 * Convert the wparam of an ASCII message to Unicode.
336 static WPARAM map_wparam_AtoW( UINT message, WPARAM wparam )
341 case EM_SETPASSWORDCHAR:
348 char ch = LOWORD(wparam);
350 MultiByteToWideChar(CP_ACP, 0, &ch, 1, &wch, 1);
351 wparam = MAKEWPARAM( wch, HIWORD(wparam) );
358 ch[0] = (wparam >> 8);
359 ch[1] = (wparam & 0xff);
360 if (ch[0]) MultiByteToWideChar(CP_ACP, 0, ch, 2, &wch, 1);
361 else MultiByteToWideChar(CP_ACP, 0, &ch[1], 1, &wch, 1);
362 wparam = MAKEWPARAM( wch, HIWORD(wparam) );
370 /***********************************************************************
373 * Convert the wparam of a Unicode message to ASCII.
375 static WPARAM map_wparam_WtoA( UINT message, WPARAM wparam )
380 case EM_SETPASSWORDCHAR:
387 WCHAR wch = LOWORD(wparam);
389 WideCharToMultiByte( CP_ACP, 0, &wch, 1, &ch, 1, NULL, NULL );
390 wparam = MAKEWPARAM( ch, HIWORD(wparam) );
395 WCHAR wch = LOWORD(wparam);
398 if (WideCharToMultiByte( CP_ACP, 0, &wch, 1, ch, 2, NULL, NULL ) == 2)
399 wparam = MAKEWPARAM( (ch[0] << 8) | ch[1], HIWORD(wparam) );
401 wparam = MAKEWPARAM( ch[0], HIWORD(wparam) );
409 /***********************************************************************
412 * Pack a message for sending to another process.
413 * Return the size of the data we expect in the message reply.
414 * Set data->count to -1 if there is an error.
416 static size_t pack_message( HWND hwnd, UINT message, WPARAM wparam, LPARAM lparam,
417 struct packed_message *data )
425 CREATESTRUCTW *cs = (CREATESTRUCTW *)lparam;
426 push_data( data, cs, sizeof(*cs) );
427 if (HIWORD(cs->lpszName)) push_string( data, cs->lpszName );
428 if (HIWORD(cs->lpszClass)) push_string( data, cs->lpszClass );
432 case WM_ASKCBFORMATNAME:
433 return wparam * sizeof(WCHAR);
434 case WM_WININICHANGE:
435 if (lparam) push_string(data, (LPWSTR)lparam );
438 case WM_DEVMODECHANGE:
443 push_string( data, (LPWSTR)lparam );
445 case WM_GETMINMAXINFO:
446 push_data( data, (MINMAXINFO *)lparam, sizeof(MINMAXINFO) );
447 return sizeof(MINMAXINFO);
449 push_data( data, (DRAWITEMSTRUCT *)lparam, sizeof(DRAWITEMSTRUCT) );
452 push_data( data, (MEASUREITEMSTRUCT *)lparam, sizeof(MEASUREITEMSTRUCT) );
453 return sizeof(MEASUREITEMSTRUCT);
455 push_data( data, (DELETEITEMSTRUCT *)lparam, sizeof(DELETEITEMSTRUCT) );
458 push_data( data, (COMPAREITEMSTRUCT *)lparam, sizeof(COMPAREITEMSTRUCT) );
460 case WM_WINDOWPOSCHANGING:
461 case WM_WINDOWPOSCHANGED:
462 push_data( data, (WINDOWPOS *)lparam, sizeof(WINDOWPOS) );
463 return sizeof(WINDOWPOS);
466 COPYDATASTRUCT *cp = (COPYDATASTRUCT *)lparam;
467 push_data( data, cp, sizeof(*cp) );
468 if (cp->lpData) push_data( data, cp->lpData, cp->cbData );
472 /* WM_NOTIFY cannot be sent across processes (MSDN) */
476 push_data( data, (HELPINFO *)lparam, sizeof(HELPINFO) );
478 case WM_STYLECHANGING:
479 case WM_STYLECHANGED:
480 push_data( data, (STYLESTRUCT *)lparam, sizeof(STYLESTRUCT) );
485 push_data( data, (RECT *)lparam, sizeof(RECT) );
490 NCCALCSIZE_PARAMS *nc = (NCCALCSIZE_PARAMS *)lparam;
491 push_data( data, nc, sizeof(*nc) );
492 push_data( data, nc->lppos, sizeof(*nc->lppos) );
493 return sizeof(*nc) + sizeof(*nc->lppos);
496 if (lparam) push_data( data, (MSG *)lparam, sizeof(MSG) );
498 case SBM_SETSCROLLINFO:
499 push_data( data, (SCROLLINFO *)lparam, sizeof(SCROLLINFO) );
501 case SBM_GETSCROLLINFO:
502 push_data( data, (SCROLLINFO *)lparam, sizeof(SCROLLINFO) );
503 return sizeof(SCROLLINFO);
504 case SBM_GETSCROLLBARINFO:
506 const SCROLLBARINFO *info = (const SCROLLBARINFO *)lparam;
507 size_t size = min( info->cbSize, sizeof(SCROLLBARINFO) );
508 push_data( data, info, size );
516 if (wparam) size += sizeof(DWORD);
517 if (lparam) size += sizeof(DWORD);
522 case CB_GETDROPPEDCONTROLRECT:
526 push_data( data, (RECT *)lparam, sizeof(RECT) );
530 WORD *pw = (WORD *)lparam;
531 push_data( data, pw, sizeof(*pw) );
532 return *pw * sizeof(WCHAR);
536 if (wparam) push_data( data, (UINT *)lparam, sizeof(UINT) * wparam );
539 case CB_INSERTSTRING:
541 case CB_FINDSTRINGEXACT:
542 case CB_SELECTSTRING:
543 if (combobox_has_strings( hwnd )) push_string( data, (LPWSTR)lparam );
546 if (!combobox_has_strings( hwnd )) return sizeof(ULONG_PTR);
547 return (SendMessageW( hwnd, CB_GETLBTEXTLEN, wparam, 0 ) + 1) * sizeof(WCHAR);
549 case LB_INSERTSTRING:
551 case LB_FINDSTRINGEXACT:
552 case LB_SELECTSTRING:
553 if (listbox_has_strings( hwnd )) push_string( data, (LPWSTR)lparam );
556 if (!listbox_has_strings( hwnd )) return sizeof(ULONG_PTR);
557 return (SendMessageW( hwnd, LB_GETTEXTLEN, wparam, 0 ) + 1) * sizeof(WCHAR);
559 return wparam * sizeof(UINT);
561 push_data( data, (MDINEXTMENU *)lparam, sizeof(MDINEXTMENU) );
562 return sizeof(MDINEXTMENU);
565 push_data( data, (RECT *)lparam, sizeof(RECT) );
569 MDICREATESTRUCTW *cs = (MDICREATESTRUCTW *)lparam;
570 push_data( data, cs, sizeof(*cs) );
571 if (HIWORD(cs->szTitle)) push_string( data, cs->szTitle );
572 if (HIWORD(cs->szClass)) push_string( data, cs->szClass );
575 case WM_MDIGETACTIVE:
576 if (lparam) return sizeof(BOOL);
578 case WM_WINE_SETWINDOWPOS:
579 push_data( data, (WINDOWPOS *)lparam, sizeof(WINDOWPOS) );
581 case WM_WINE_KEYBOARD_LL_HOOK:
582 push_data( data, (KBDLLHOOKSTRUCT *)lparam, sizeof(KBDLLHOOKSTRUCT) );
584 case WM_WINE_MOUSE_LL_HOOK:
585 push_data( data, (MSLLHOOKSTRUCT *)lparam, sizeof(MSLLHOOKSTRUCT) );
588 /* these contain an HFONT */
591 /* these contain an HDC */
594 case WM_ICONERASEBKGND:
596 case WM_CTLCOLORMSGBOX:
597 case WM_CTLCOLOREDIT:
598 case WM_CTLCOLORLISTBOX:
601 case WM_CTLCOLORSCROLLBAR:
602 case WM_CTLCOLORSTATIC:
605 /* these contain an HGLOBAL */
606 case WM_PAINTCLIPBOARD:
607 case WM_SIZECLIPBOARD:
608 /* these contain HICON */
611 case WM_QUERYDRAGICON:
612 case WM_QUERYPARKICON:
613 /* these contain pointers */
615 case WM_QUERYDROPOBJECT:
619 case WM_DEVICECHANGE:
620 FIXME( "msg %x (%s) not supported yet\n", message, SPY_GetMsgName(message, hwnd) );
628 /***********************************************************************
631 * Unpack a message received from another process.
633 static BOOL unpack_message( HWND hwnd, UINT message, WPARAM *wparam, LPARAM *lparam,
634 void **buffer, size_t size )
643 CREATESTRUCTW *cs = *buffer;
644 WCHAR *str = (WCHAR *)(cs + 1);
645 if (size < sizeof(*cs)) return FALSE;
647 if (HIWORD(cs->lpszName))
649 if (!check_string( str, size )) return FALSE;
651 size -= (strlenW(str) + 1) * sizeof(WCHAR);
652 str += strlenW(str) + 1;
654 if (HIWORD(cs->lpszClass))
656 if (!check_string( str, size )) return FALSE;
662 case WM_ASKCBFORMATNAME:
663 if (!get_buffer_space( buffer, (*wparam * sizeof(WCHAR)) )) return FALSE;
665 case WM_WININICHANGE:
666 if (!*lparam) return TRUE;
669 case WM_DEVMODECHANGE:
674 if (!check_string( *buffer, size )) return FALSE;
676 case WM_GETMINMAXINFO:
677 minsize = sizeof(MINMAXINFO);
680 minsize = sizeof(DRAWITEMSTRUCT);
683 minsize = sizeof(MEASUREITEMSTRUCT);
686 minsize = sizeof(DELETEITEMSTRUCT);
689 minsize = sizeof(COMPAREITEMSTRUCT);
691 case WM_WINDOWPOSCHANGING:
692 case WM_WINDOWPOSCHANGED:
693 case WM_WINE_SETWINDOWPOS:
694 minsize = sizeof(WINDOWPOS);
698 COPYDATASTRUCT *cp = *buffer;
699 if (size < sizeof(*cp)) return FALSE;
702 minsize = sizeof(*cp) + cp->cbData;
708 /* WM_NOTIFY cannot be sent across processes (MSDN) */
711 minsize = sizeof(HELPINFO);
713 case WM_STYLECHANGING:
714 case WM_STYLECHANGED:
715 minsize = sizeof(STYLESTRUCT);
718 if (!*wparam) minsize = sizeof(RECT);
721 NCCALCSIZE_PARAMS *nc = *buffer;
722 if (size < sizeof(*nc) + sizeof(*nc->lppos)) return FALSE;
723 nc->lppos = (WINDOWPOS *)(nc + 1);
727 if (!*lparam) return TRUE;
728 minsize = sizeof(MSG);
730 case SBM_SETSCROLLINFO:
731 minsize = sizeof(SCROLLINFO);
733 case SBM_GETSCROLLINFO:
734 if (!get_buffer_space( buffer, sizeof(SCROLLINFO ))) return FALSE;
736 case SBM_GETSCROLLBARINFO:
737 if (!get_buffer_space( buffer, sizeof(SCROLLBARINFO ))) return FALSE;
742 if (*wparam || *lparam)
744 if (!get_buffer_space( buffer, 2*sizeof(DWORD) )) return FALSE;
745 if (*wparam) *wparam = (WPARAM)*buffer;
746 if (*lparam) *lparam = (LPARAM)((DWORD *)*buffer + 1);
751 case CB_GETDROPPEDCONTROLRECT:
752 if (!get_buffer_space( buffer, sizeof(RECT) )) return FALSE;
756 minsize = sizeof(RECT);
761 if (size < sizeof(WORD)) return FALSE;
762 len = *(WORD *)*buffer;
763 if (!get_buffer_space( buffer, (len + 1) * sizeof(WCHAR) )) return FALSE;
764 *lparam = (LPARAM)*buffer + sizeof(WORD); /* don't erase WORD at start of buffer */
769 if (!*wparam) return TRUE;
770 minsize = *wparam * sizeof(UINT);
773 case CB_INSERTSTRING:
775 case CB_FINDSTRINGEXACT:
776 case CB_SELECTSTRING:
778 case LB_INSERTSTRING:
780 case LB_FINDSTRINGEXACT:
781 case LB_SELECTSTRING:
782 if (!*buffer) return TRUE;
783 if (!check_string( *buffer, size )) return FALSE;
787 size = sizeof(ULONG_PTR);
788 if (combobox_has_strings( hwnd ))
789 size = (SendMessageW( hwnd, CB_GETLBTEXTLEN, *wparam, 0 ) + 1) * sizeof(WCHAR);
790 if (!get_buffer_space( buffer, size )) return FALSE;
795 size = sizeof(ULONG_PTR);
796 if (listbox_has_strings( hwnd ))
797 size = (SendMessageW( hwnd, LB_GETTEXTLEN, *wparam, 0 ) + 1) * sizeof(WCHAR);
798 if (!get_buffer_space( buffer, size )) return FALSE;
802 if (!get_buffer_space( buffer, *wparam * sizeof(UINT) )) return FALSE;
805 minsize = sizeof(MDINEXTMENU);
806 if (!get_buffer_space( buffer, sizeof(MDINEXTMENU) )) return FALSE;
810 minsize = sizeof(RECT);
811 if (!get_buffer_space( buffer, sizeof(RECT) )) return FALSE;
815 MDICREATESTRUCTW *cs = *buffer;
816 WCHAR *str = (WCHAR *)(cs + 1);
817 if (size < sizeof(*cs)) return FALSE;
819 if (HIWORD(cs->szTitle))
821 if (!check_string( str, size )) return FALSE;
823 size -= (strlenW(str) + 1) * sizeof(WCHAR);
824 str += strlenW(str) + 1;
826 if (HIWORD(cs->szClass))
828 if (!check_string( str, size )) return FALSE;
833 case WM_MDIGETACTIVE:
834 if (!*lparam) return TRUE;
835 if (!get_buffer_space( buffer, sizeof(BOOL) )) return FALSE;
837 case WM_WINE_KEYBOARD_LL_HOOK:
838 minsize = sizeof(KBDLLHOOKSTRUCT);
840 case WM_WINE_MOUSE_LL_HOOK:
841 minsize = sizeof(MSLLHOOKSTRUCT);
844 /* these contain an HFONT */
847 /* these contain an HDC */
850 case WM_ICONERASEBKGND:
852 case WM_CTLCOLORMSGBOX:
853 case WM_CTLCOLOREDIT:
854 case WM_CTLCOLORLISTBOX:
857 case WM_CTLCOLORSCROLLBAR:
858 case WM_CTLCOLORSTATIC:
861 /* these contain an HGLOBAL */
862 case WM_PAINTCLIPBOARD:
863 case WM_SIZECLIPBOARD:
864 /* these contain HICON */
867 case WM_QUERYDRAGICON:
868 case WM_QUERYPARKICON:
869 /* these contain pointers */
871 case WM_QUERYDROPOBJECT:
875 case WM_DEVICECHANGE:
876 FIXME( "msg %x (%s) not supported yet\n", message, SPY_GetMsgName(message, hwnd) );
880 return TRUE; /* message doesn't need any unpacking */
883 /* default exit for most messages: check minsize and store buffer in lparam */
884 if (size < minsize) return FALSE;
885 *lparam = (LPARAM)*buffer;
890 /***********************************************************************
893 * Pack a reply to a message for sending to another process.
895 static void pack_reply( HWND hwnd, UINT message, WPARAM wparam, LPARAM lparam,
896 LRESULT res, struct packed_message *data )
903 push_data( data, (CREATESTRUCTW *)lparam, sizeof(CREATESTRUCTW) );
908 push_data( data, (WCHAR *)lparam, (res + 1) * sizeof(WCHAR) );
910 case WM_GETMINMAXINFO:
911 push_data( data, (MINMAXINFO *)lparam, sizeof(MINMAXINFO) );
914 push_data( data, (MEASUREITEMSTRUCT *)lparam, sizeof(MEASUREITEMSTRUCT) );
916 case WM_WINDOWPOSCHANGING:
917 case WM_WINDOWPOSCHANGED:
918 push_data( data, (WINDOWPOS *)lparam, sizeof(WINDOWPOS) );
921 if (lparam) push_data( data, (MSG *)lparam, sizeof(MSG) );
923 case SBM_GETSCROLLINFO:
924 push_data( data, (SCROLLINFO *)lparam, sizeof(SCROLLINFO) );
928 case CB_GETDROPPEDCONTROLRECT:
931 push_data( data, (RECT *)lparam, sizeof(RECT) );
935 WORD *ptr = (WORD *)lparam;
936 push_data( data, ptr, ptr[-1] * sizeof(WCHAR) );
940 push_data( data, (UINT *)lparam, wparam * sizeof(UINT) );
942 case WM_MDIGETACTIVE:
943 if (lparam) push_data( data, (BOOL *)lparam, sizeof(BOOL) );
947 push_data( data, (RECT *)lparam, sizeof(RECT) );
950 NCCALCSIZE_PARAMS *nc = (NCCALCSIZE_PARAMS *)lparam;
951 push_data( data, nc, sizeof(*nc) );
952 push_data( data, nc->lppos, sizeof(*nc->lppos) );
958 if (wparam) push_data( data, (DWORD *)wparam, sizeof(DWORD) );
959 if (lparam) push_data( data, (DWORD *)lparam, sizeof(DWORD) );
962 push_data( data, (MDINEXTMENU *)lparam, sizeof(MDINEXTMENU) );
965 push_data( data, (MDICREATESTRUCTW *)lparam, sizeof(MDICREATESTRUCTW) );
967 case WM_ASKCBFORMATNAME:
968 push_data( data, (WCHAR *)lparam, (strlenW((WCHAR *)lparam) + 1) * sizeof(WCHAR) );
974 /***********************************************************************
977 * Unpack a message reply received from another process.
979 static void unpack_reply( HWND hwnd, UINT message, WPARAM wparam, LPARAM lparam,
980 void *buffer, size_t size )
987 CREATESTRUCTW *cs = (CREATESTRUCTW *)lparam;
988 LPCWSTR name = cs->lpszName, class = cs->lpszClass;
989 memcpy( cs, buffer, min( sizeof(*cs), size ));
990 cs->lpszName = name; /* restore the original pointers */
991 cs->lpszClass = class;
995 case WM_ASKCBFORMATNAME:
996 memcpy( (WCHAR *)lparam, buffer, min( wparam*sizeof(WCHAR), size ));
998 case WM_GETMINMAXINFO:
999 memcpy( (MINMAXINFO *)lparam, buffer, min( sizeof(MINMAXINFO), size ));
1001 case WM_MEASUREITEM:
1002 memcpy( (MEASUREITEMSTRUCT *)lparam, buffer, min( sizeof(MEASUREITEMSTRUCT), size ));
1004 case WM_WINDOWPOSCHANGING:
1005 case WM_WINDOWPOSCHANGED:
1006 memcpy( (WINDOWPOS *)lparam, buffer, min( sizeof(WINDOWPOS), size ));
1009 if (lparam) memcpy( (MSG *)lparam, buffer, min( sizeof(MSG), size ));
1011 case SBM_GETSCROLLINFO:
1012 memcpy( (SCROLLINFO *)lparam, buffer, min( sizeof(SCROLLINFO), size ));
1014 case SBM_GETSCROLLBARINFO:
1015 memcpy( (SCROLLBARINFO *)lparam, buffer, min( sizeof(SCROLLBARINFO), size ));
1018 case CB_GETDROPPEDCONTROLRECT:
1019 case LB_GETITEMRECT:
1022 memcpy( (RECT *)lparam, buffer, min( sizeof(RECT), size ));
1025 size = min( size, (size_t)*(WORD *)lparam );
1026 memcpy( (WCHAR *)lparam, buffer, size );
1028 case LB_GETSELITEMS:
1029 memcpy( (UINT *)lparam, buffer, min( wparam*sizeof(UINT), size ));
1033 memcpy( (WCHAR *)lparam, buffer, size );
1036 memcpy( (MDINEXTMENU *)lparam, buffer, min( sizeof(MDINEXTMENU), size ));
1038 case WM_MDIGETACTIVE:
1039 if (lparam) memcpy( (BOOL *)lparam, buffer, min( sizeof(BOOL), size ));
1043 memcpy( (RECT *)lparam, buffer, min( sizeof(RECT), size ));
1046 NCCALCSIZE_PARAMS *nc = (NCCALCSIZE_PARAMS *)lparam;
1047 WINDOWPOS *wp = nc->lppos;
1048 memcpy( nc, buffer, min( sizeof(*nc), size ));
1049 if (size > sizeof(*nc))
1051 size -= sizeof(*nc);
1052 memcpy( wp, (NCCALCSIZE_PARAMS*)buffer + 1, min( sizeof(*wp), size ));
1054 nc->lppos = wp; /* restore the original pointer */
1062 memcpy( (DWORD *)wparam, buffer, min( sizeof(DWORD), size ));
1063 if (size <= sizeof(DWORD)) break;
1064 size -= sizeof(DWORD);
1065 buffer = (DWORD *)buffer + 1;
1067 if (lparam) memcpy( (DWORD *)lparam, buffer, min( sizeof(DWORD), size ));
1071 MDICREATESTRUCTW *cs = (MDICREATESTRUCTW *)lparam;
1072 LPCWSTR title = cs->szTitle, class = cs->szClass;
1073 memcpy( cs, buffer, min( sizeof(*cs), size ));
1074 cs->szTitle = title; /* restore the original pointers */
1075 cs->szClass = class;
1079 ERR( "should not happen: unexpected message %x\n", message );
1085 /***********************************************************************
1088 * Send a reply to a sent message.
1090 static void reply_message( struct received_message_info *info, LRESULT result, BOOL remove )
1092 struct packed_message data;
1093 int i, replied = info->flags & ISMEX_REPLIED;
1095 if (info->flags & ISMEX_NOTIFY) return; /* notify messages don't get replies */
1096 if (!remove && replied) return; /* replied already */
1099 info->flags |= ISMEX_REPLIED;
1101 if (info->type == MSG_OTHER_PROCESS && !replied)
1103 pack_reply( info->msg.hwnd, info->msg.message, info->msg.wParam,
1104 info->msg.lParam, result, &data );
1107 SERVER_START_REQ( reply_message )
1109 req->type = info->type;
1110 req->result = result;
1111 req->remove = remove;
1112 for (i = 0; i < data.count; i++) wine_server_add_data( req, data.data[i], data.size[i] );
1113 wine_server_call( req );
1119 /***********************************************************************
1120 * handle_internal_message
1122 * Handle an internal Wine message instead of calling the window proc.
1124 static LRESULT handle_internal_message( HWND hwnd, UINT msg, WPARAM wparam, LPARAM lparam )
1126 if (hwnd == GetDesktopWindow()) return 0;
1129 case WM_WINE_DESTROYWINDOW:
1130 return WIN_DestroyWindow( hwnd );
1131 case WM_WINE_SETWINDOWPOS:
1132 if (USER_Driver.pSetWindowPos)
1133 return USER_Driver.pSetWindowPos( (WINDOWPOS *)lparam );
1135 case WM_WINE_SHOWWINDOW:
1136 return ShowWindow( hwnd, wparam );
1137 case WM_WINE_SETPARENT:
1138 return (LRESULT)SetParent( hwnd, (HWND)wparam );
1139 case WM_WINE_SETWINDOWLONG:
1140 return (LRESULT)SetWindowLongW( hwnd, wparam, lparam );
1141 case WM_WINE_ENABLEWINDOW:
1142 return EnableWindow( hwnd, wparam );
1143 case WM_WINE_SETACTIVEWINDOW:
1144 return (LRESULT)SetActiveWindow( (HWND)wparam );
1145 case WM_WINE_KEYBOARD_LL_HOOK:
1146 return HOOK_CallHooks( WH_KEYBOARD_LL, HC_ACTION, wparam, lparam, TRUE );
1147 case WM_WINE_MOUSE_LL_HOOK:
1148 return HOOK_CallHooks( WH_MOUSE_LL, HC_ACTION, wparam, lparam, TRUE );
1150 FIXME( "unknown internal message %x\n", msg );
1155 /* since the WM_DDE_ACK response to a WM_DDE_EXECUTE message should contain the handle
1156 * to the memory handle, we keep track (in the server side) of all pairs of handle
1157 * used (the client passes its value and the content of the memory handle), and
1158 * the server stored both values (the client, and the local one, created after the
1159 * content). When a ACK message is generated, the list of pair is searched for a
1160 * matching pair, so that the client memory handle can be returned.
1163 HGLOBAL client_hMem;
1164 HGLOBAL server_hMem;
1167 static struct DDE_pair* dde_pairs;
1168 static int dde_num_alloc;
1169 static int dde_num_used;
1171 static CRITICAL_SECTION dde_crst;
1172 static CRITICAL_SECTION_DEBUG critsect_debug =
1175 { &critsect_debug.ProcessLocksList, &critsect_debug.ProcessLocksList },
1176 0, 0, { 0, (DWORD)(__FILE__ ": dde_crst") }
1178 static CRITICAL_SECTION dde_crst = { &critsect_debug, -1, 0, 0, 0, 0 };
1180 static BOOL dde_add_pair(HGLOBAL chm, HGLOBAL shm)
1185 EnterCriticalSection(&dde_crst);
1187 /* now remember the pair of hMem on both sides */
1188 if (dde_num_used == dde_num_alloc)
1190 struct DDE_pair* tmp;
1192 tmp = HeapReAlloc( GetProcessHeap(), 0, dde_pairs,
1193 (dde_num_alloc + GROWBY) * sizeof(struct DDE_pair));
1195 tmp = HeapAlloc( GetProcessHeap(), 0,
1196 (dde_num_alloc + GROWBY) * sizeof(struct DDE_pair));
1200 LeaveCriticalSection(&dde_crst);
1204 /* zero out newly allocated part */
1205 memset(&dde_pairs[dde_num_alloc], 0, GROWBY * sizeof(struct DDE_pair));
1206 dde_num_alloc += GROWBY;
1209 for (i = 0; i < dde_num_alloc; i++)
1211 if (dde_pairs[i].server_hMem == 0)
1213 dde_pairs[i].client_hMem = chm;
1214 dde_pairs[i].server_hMem = shm;
1219 LeaveCriticalSection(&dde_crst);
1223 static HGLOBAL dde_get_pair(HGLOBAL shm)
1228 EnterCriticalSection(&dde_crst);
1229 for (i = 0; i < dde_num_alloc; i++)
1231 if (dde_pairs[i].server_hMem == shm)
1233 /* free this pair */
1234 dde_pairs[i].server_hMem = 0;
1236 ret = dde_pairs[i].client_hMem;
1240 LeaveCriticalSection(&dde_crst);
1244 /***********************************************************************
1247 * Post a DDE message
1249 static BOOL post_dde_message( DWORD dest_tid, struct packed_message *data, const struct send_message_info *info )
1255 HGLOBAL hunlock = 0;
1259 if (!UnpackDDElParam( info->msg, info->lparam, &uiLo, &uiHi ))
1265 /* DDE messages which don't require packing are:
1274 /* uiHi should contain a hMem from WM_DDE_EXECUTE */
1275 HGLOBAL h = dde_get_pair( (HANDLE)uiHi );
1278 /* send back the value of h on the other side */
1279 push_data( data, &h, sizeof(HGLOBAL) );
1281 TRACE( "send dde-ack %x %08x => %08lx\n", uiLo, uiHi, (DWORD)h );
1286 /* uiHi should contain either an atom or 0 */
1287 TRACE( "send dde-ack %x atom=%x\n", uiLo, uiHi );
1288 lp = MAKELONG( uiLo, uiHi );
1297 size = GlobalSize( (HGLOBAL)uiLo ) ;
1298 if ((info->msg == WM_DDE_ADVISE && size < sizeof(DDEADVISE)) ||
1299 (info->msg == WM_DDE_DATA && size < sizeof(DDEDATA)) ||
1300 (info->msg == WM_DDE_POKE && size < sizeof(DDEPOKE))
1304 else if (info->msg != WM_DDE_DATA) return FALSE;
1309 if ((ptr = GlobalLock( (HGLOBAL)uiLo) ))
1311 DDEDATA *dde_data = (DDEDATA *)ptr;
1312 TRACE("unused %d, fResponse %d, fRelease %d, fDeferUpd %d, fAckReq %d, cfFormat %d\n",
1313 dde_data->unused, dde_data->fResponse, dde_data->fRelease,
1314 dde_data->reserved, dde_data->fAckReq, dde_data->cfFormat);
1315 push_data( data, ptr, size );
1316 hunlock = (HGLOBAL)uiLo;
1319 TRACE( "send ddepack %u %x\n", size, uiHi );
1321 case WM_DDE_EXECUTE:
1324 if ((ptr = GlobalLock( (HGLOBAL)info->lparam) ))
1326 push_data(data, ptr, GlobalSize( (HGLOBAL)info->lparam ));
1327 /* so that the other side can send it back on ACK */
1329 hunlock = (HGLOBAL)info->lparam;
1334 SERVER_START_REQ( send_message )
1337 req->type = info->type;
1339 req->win = info->hwnd;
1340 req->msg = info->msg;
1341 req->wparam = info->wparam;
1343 req->time = GetCurrentTime();
1345 for (i = 0; i < data->count; i++)
1346 wine_server_add_data( req, data->data[i], data->size[i] );
1347 if ((res = wine_server_call( req )))
1349 if (res == STATUS_INVALID_PARAMETER)
1350 /* FIXME: find a STATUS_ value for this one */
1351 SetLastError( ERROR_INVALID_THREAD_ID );
1353 SetLastError( RtlNtStatusToDosError(res) );
1356 FreeDDElParam(info->msg, info->lparam);
1359 if (hunlock) GlobalUnlock(hunlock);
1364 /***********************************************************************
1365 * unpack_dde_message
1367 * Unpack a posted DDE message received from another process.
1369 static BOOL unpack_dde_message( HWND hwnd, UINT message, WPARAM *wparam, LPARAM *lparam,
1370 void **buffer, size_t size )
1381 /* hMem is being passed */
1382 if (size != sizeof(HGLOBAL)) return FALSE;
1383 if (!buffer || !*buffer) return FALSE;
1385 memcpy( &hMem, *buffer, size );
1387 TRACE("recv dde-ack %x mem=%x[%lx]\n", uiLo, uiHi, GlobalSize( hMem ));
1391 uiLo = LOWORD( *lparam );
1392 uiHi = HIWORD( *lparam );
1393 TRACE("recv dde-ack %x atom=%x\n", uiLo, uiHi);
1395 *lparam = PackDDElParam( WM_DDE_ACK, uiLo, uiHi );
1400 if ((!buffer || !*buffer) && message != WM_DDE_DATA) return FALSE;
1402 TRACE( "recv ddepack %u %x\n", size, uiHi );
1405 hMem = GlobalAlloc( GMEM_MOVEABLE|GMEM_DDESHARE, size );
1406 if (hMem && (ptr = GlobalLock( hMem )))
1408 memcpy( ptr, *buffer, size );
1409 GlobalUnlock( hMem );
1415 *lparam = PackDDElParam( message, uiLo, uiHi );
1417 case WM_DDE_EXECUTE:
1420 if (!buffer || !*buffer) return FALSE;
1421 hMem = GlobalAlloc( GMEM_MOVEABLE|GMEM_DDESHARE, size );
1422 if (hMem && (ptr = GlobalLock( hMem )))
1424 memcpy( ptr, *buffer, size );
1425 GlobalUnlock( hMem );
1426 TRACE( "exec: pairing c=%08lx s=%08lx\n", *lparam, (DWORD)hMem );
1427 if (!dde_add_pair( (HGLOBAL)*lparam, hMem ))
1433 } else return FALSE;
1434 *lparam = (LPARAM)hMem;
1440 /***********************************************************************
1443 * Call a window procedure and the corresponding hooks.
1445 static LRESULT call_window_proc( HWND hwnd, UINT msg, WPARAM wparam, LPARAM lparam,
1446 BOOL unicode, BOOL same_thread )
1451 CWPRETSTRUCT cwpret;
1452 MESSAGEQUEUE *queue = QUEUE_Current();
1454 if (queue->recursion_count > MAX_SENDMSG_RECURSION) return 0;
1455 queue->recursion_count++;
1457 if (msg & 0x80000000)
1459 result = handle_internal_message( hwnd, msg, wparam, lparam );
1463 /* first the WH_CALLWNDPROC hook */
1464 hwnd = WIN_GetFullHandle( hwnd );
1465 cwp.lParam = lparam;
1466 cwp.wParam = wparam;
1469 HOOK_CallHooks( WH_CALLWNDPROC, HC_ACTION, same_thread, (LPARAM)&cwp, unicode );
1471 /* now call the window procedure */
1474 if (!(winproc = (WNDPROC)GetWindowLongPtrW( hwnd, GWLP_WNDPROC ))) goto done;
1475 result = CallWindowProcW( winproc, hwnd, msg, wparam, lparam );
1479 if (!(winproc = (WNDPROC)GetWindowLongPtrA( hwnd, GWLP_WNDPROC ))) goto done;
1480 result = CallWindowProcA( winproc, hwnd, msg, wparam, lparam );
1483 /* and finally the WH_CALLWNDPROCRET hook */
1484 cwpret.lResult = result;
1485 cwpret.lParam = lparam;
1486 cwpret.wParam = wparam;
1487 cwpret.message = msg;
1489 HOOK_CallHooks( WH_CALLWNDPROCRET, HC_ACTION, same_thread, (LPARAM)&cwpret, unicode );
1491 queue->recursion_count--;
1496 /***********************************************************************
1497 * process_hardware_message
1499 * Process a hardware message; return TRUE if message should be passed on to the app
1501 static BOOL process_hardware_message( MSG *msg, ULONG_PTR extra_info, HWND hwnd,
1502 UINT first, UINT last, BOOL remove )
1506 if (!MSG_process_raw_hardware_message( msg, extra_info, hwnd, first, last, remove ))
1509 ret = MSG_process_cooked_hardware_message( msg, extra_info, remove );
1511 /* tell the server we have passed it to the app
1512 * (even though we may end up dropping it later on)
1514 SERVER_START_REQ( reply_message )
1516 req->type = MSG_HARDWARE;
1518 req->remove = remove || !ret;
1519 wine_server_call( req );
1526 /***********************************************************************
1527 * call_sendmsg_callback
1529 * Call the callback function of SendMessageCallback.
1531 static inline void call_sendmsg_callback( SENDASYNCPROC callback, HWND hwnd, UINT msg,
1532 ULONG_PTR data, LRESULT result )
1534 if (TRACE_ON(relay))
1535 DPRINTF( "%04lx:Call message callback %p (hwnd=%p,msg=%s,data=%08lx,result=%08lx)\n",
1536 GetCurrentThreadId(), callback, hwnd, SPY_GetMsgName( msg, hwnd ),
1538 callback( hwnd, msg, data, result );
1539 if (TRACE_ON(relay))
1540 DPRINTF( "%04lx:Ret message callback %p (hwnd=%p,msg=%s,data=%08lx,result=%08lx)\n",
1541 GetCurrentThreadId(), callback, hwnd, SPY_GetMsgName( msg, hwnd ),
1546 /***********************************************************************
1549 * Retrieve the hook procedure real value for a module-relative proc
1551 static void *get_hook_proc( void *proc, const WCHAR *module )
1555 if (!(mod = GetModuleHandleW(module)))
1557 TRACE( "loading %s\n", debugstr_w(module) );
1558 /* FIXME: the library will never be freed */
1559 if (!(mod = LoadLibraryW(module))) return NULL;
1561 return (char *)mod + (ULONG_PTR)proc;
1565 /***********************************************************************
1568 * Peek for a message matching the given parameters. Return FALSE if none available.
1569 * All pending sent messages are processed before returning.
1571 BOOL MSG_peek_message( MSG *msg, HWND hwnd, UINT first, UINT last, int flags )
1574 ULONG_PTR extra_info = 0;
1575 MESSAGEQUEUE *queue = QUEUE_Current();
1576 struct received_message_info info, *old_info;
1578 if (!first && !last) last = ~0;
1583 void *buffer = NULL;
1584 size_t size = 0, buffer_size = 0;
1586 do /* loop while buffer is too small */
1588 if (buffer_size && !(buffer = HeapAlloc( GetProcessHeap(), 0, buffer_size )))
1590 SERVER_START_REQ( get_message )
1593 req->get_win = hwnd;
1594 req->get_first = first;
1595 req->get_last = last;
1596 if (buffer_size) wine_server_set_reply( req, buffer, buffer_size );
1597 if (!(res = wine_server_call( req )))
1599 size = wine_server_reply_size( reply );
1600 info.type = reply->type;
1601 info.msg.hwnd = reply->win;
1602 info.msg.message = reply->msg;
1603 info.msg.wParam = reply->wparam;
1604 info.msg.lParam = reply->lparam;
1605 info.msg.time = reply->time;
1606 info.msg.pt.x = reply->x;
1607 info.msg.pt.y = reply->y;
1608 info.hook = reply->hook;
1609 info.hook_proc = reply->hook_proc;
1610 extra_info = reply->info;
1614 HeapFree( GetProcessHeap(), 0, buffer );
1615 buffer_size = reply->total;
1619 } while (res == STATUS_BUFFER_OVERFLOW);
1621 if (res) return FALSE;
1623 TRACE( "got type %d msg %x (%s) hwnd %p wp %x lp %lx\n",
1624 info.type, info.msg.message,
1625 (info.type == MSG_WINEVENT) ? "MSG_WINEVENT" : SPY_GetMsgName(info.msg.message, info.msg.hwnd),
1626 info.msg.hwnd, info.msg.wParam, info.msg.lParam );
1632 info.flags = ISMEX_SEND;
1635 info.flags = ISMEX_NOTIFY;
1638 info.flags = ISMEX_CALLBACK;
1640 case MSG_CALLBACK_RESULT:
1641 call_sendmsg_callback( (SENDASYNCPROC)info.msg.wParam, info.msg.hwnd,
1642 info.msg.message, extra_info, info.msg.lParam );
1647 WCHAR module[MAX_PATH];
1648 size = min( size, (MAX_PATH - 1) * sizeof(WCHAR) );
1649 memcpy( module, buffer, size );
1650 module[size / sizeof(WCHAR)] = 0;
1651 if (!(info.hook_proc = get_hook_proc( info.hook_proc, module )))
1653 ERR( "invalid winevent hook module name %s\n", debugstr_w(module) );
1657 if (TRACE_ON(relay))
1658 DPRINTF( "%04lx:Call winevent proc %p (hook=%p,event=%x,hwnd=%p,object_id=%x,child_id=%lx,tid=%04lx,time=%lx)\n",
1659 GetCurrentThreadId(), info.hook_proc,
1660 info.hook, info.msg.message, info.msg.hwnd, info.msg.wParam,
1661 info.msg.lParam, extra_info, info.msg.time);
1663 info.hook_proc( info.hook, info.msg.message, info.msg.hwnd, info.msg.wParam,
1664 info.msg.lParam, extra_info, info.msg.time );
1666 if (TRACE_ON(relay))
1667 DPRINTF( "%04lx:Ret winevent proc %p (hook=%p,event=%x,hwnd=%p,object_id=%x,child_id=%lx,tid=%04lx,time=%lx)\n",
1668 GetCurrentThreadId(), info.hook_proc,
1669 info.hook, info.msg.message, info.msg.hwnd, info.msg.wParam,
1670 info.msg.lParam, extra_info, info.msg.time);
1672 case MSG_OTHER_PROCESS:
1673 info.flags = ISMEX_SEND;
1674 if (!unpack_message( info.msg.hwnd, info.msg.message, &info.msg.wParam,
1675 &info.msg.lParam, &buffer, size ))
1677 ERR( "invalid packed message %x (%s) hwnd %p wp %x lp %lx size %d\n",
1678 info.msg.message, SPY_GetMsgName(info.msg.message, info.msg.hwnd), info.msg.hwnd,
1679 info.msg.wParam, info.msg.lParam, size );
1681 reply_message( &info, 0, TRUE );
1686 if (!process_hardware_message( &info.msg, extra_info,
1687 hwnd, first, last, flags & GET_MSG_REMOVE ))
1689 TRACE("dropping msg %x\n", info.msg.message );
1690 goto next; /* ignore it */
1692 queue->GetMessagePosVal = MAKELONG( info.msg.pt.x, info.msg.pt.y );
1695 queue->GetMessageExtraInfoVal = extra_info;
1696 if (info.msg.message >= WM_DDE_FIRST && info.msg.message <= WM_DDE_LAST)
1698 if (!unpack_dde_message( info.msg.hwnd, info.msg.message, &info.msg.wParam,
1699 &info.msg.lParam, &buffer, size ))
1701 ERR( "invalid packed dde-message %x (%s) hwnd %p wp %x lp %lx size %d\n",
1702 info.msg.message, SPY_GetMsgName(info.msg.message, info.msg.hwnd),
1703 info.msg.hwnd, info.msg.wParam, info.msg.lParam, size );
1704 goto next; /* ignore it */
1708 HeapFree( GetProcessHeap(), 0, buffer );
1712 /* if we get here, we have a sent message; call the window procedure */
1713 old_info = queue->receive_info;
1714 queue->receive_info = &info;
1715 result = call_window_proc( info.msg.hwnd, info.msg.message, info.msg.wParam,
1716 info.msg.lParam, (info.type != MSG_ASCII), FALSE );
1717 reply_message( &info, result, TRUE );
1718 queue->receive_info = old_info;
1720 HeapFree( GetProcessHeap(), 0, buffer );
1725 /***********************************************************************
1726 * wait_message_reply
1728 * Wait until a sent message gets replied to.
1730 static void wait_message_reply( UINT flags )
1732 MESSAGEQUEUE *queue;
1734 if (!(queue = QUEUE_Current())) return;
1738 unsigned int wake_bits = 0, changed_bits = 0;
1741 SERVER_START_REQ( set_queue_mask )
1743 req->wake_mask = QS_SMRESULT | ((flags & SMTO_BLOCK) ? 0 : QS_SENDMESSAGE);
1744 req->changed_mask = req->wake_mask;
1746 if (!wine_server_call( req ))
1748 wake_bits = reply->wake_bits;
1749 changed_bits = reply->changed_bits;
1754 if (wake_bits & QS_SMRESULT) return; /* got a result */
1755 if (wake_bits & QS_SENDMESSAGE)
1757 /* Process the sent message immediately */
1759 MSG_peek_message( &msg, 0, 0, 0, GET_MSG_REMOVE | GET_MSG_SENT_ONLY );
1763 /* now wait for it */
1765 ReleaseThunkLock( &dwlc );
1767 if (USER_Driver.pMsgWaitForMultipleObjectsEx)
1768 res = USER_Driver.pMsgWaitForMultipleObjectsEx( 1, &queue->server_queue,
1771 res = WaitForSingleObject( queue->server_queue, INFINITE );
1773 if (dwlc) RestoreThunkLock( dwlc );
1777 /***********************************************************************
1778 * put_message_in_queue
1780 * Put a sent message into the destination queue.
1781 * For inter-process message, reply_size is set to expected size of reply data.
1783 static BOOL put_message_in_queue( DWORD dest_tid, const struct send_message_info *info,
1784 size_t *reply_size )
1786 struct packed_message data;
1788 int i, timeout = -1;
1790 if (info->type != MSG_NOTIFY &&
1791 info->type != MSG_CALLBACK &&
1792 info->type != MSG_POSTED &&
1793 info->timeout != INFINITE)
1794 timeout = info->timeout;
1797 if (info->type == MSG_OTHER_PROCESS)
1799 *reply_size = pack_message( info->hwnd, info->msg, info->wparam, info->lparam, &data );
1800 if (data.count == -1)
1802 WARN( "cannot pack message %x\n", info->msg );
1806 else if (info->type == MSG_POSTED && info->msg >= WM_DDE_FIRST && info->msg <= WM_DDE_LAST)
1808 return post_dde_message( dest_tid, &data, info );
1811 SERVER_START_REQ( send_message )
1814 req->type = info->type;
1816 req->win = info->hwnd;
1817 req->msg = info->msg;
1818 req->wparam = info->wparam;
1819 req->lparam = info->lparam;
1820 req->time = GetCurrentTime();
1821 req->timeout = timeout;
1823 if (info->type == MSG_CALLBACK)
1825 req->callback = info->callback;
1826 req->info = info->data;
1829 if (info->flags & SMTO_ABORTIFHUNG) req->flags |= SEND_MSG_ABORT_IF_HUNG;
1830 for (i = 0; i < data.count; i++) wine_server_add_data( req, data.data[i], data.size[i] );
1831 if ((res = wine_server_call( req )))
1833 if (res == STATUS_INVALID_PARAMETER)
1834 /* FIXME: find a STATUS_ value for this one */
1835 SetLastError( ERROR_INVALID_THREAD_ID );
1837 SetLastError( RtlNtStatusToDosError(res) );
1845 /***********************************************************************
1848 * Retrieve a message reply from the server.
1850 static LRESULT retrieve_reply( const struct send_message_info *info,
1851 size_t reply_size, LRESULT *result )
1854 void *reply_data = NULL;
1858 if (!(reply_data = HeapAlloc( GetProcessHeap(), 0, reply_size )))
1860 WARN( "no memory for reply %d bytes, will be truncated\n", reply_size );
1864 SERVER_START_REQ( get_message_reply )
1867 if (reply_size) wine_server_set_reply( req, reply_data, reply_size );
1868 if (!(status = wine_server_call( req ))) *result = reply->result;
1869 reply_size = wine_server_reply_size( reply );
1872 if (!status && reply_size)
1873 unpack_reply( info->hwnd, info->msg, info->wparam, info->lparam, reply_data, reply_size );
1875 HeapFree( GetProcessHeap(), 0, reply_data );
1877 TRACE( "hwnd %p msg %x (%s) wp %x lp %lx got reply %lx (err=%ld)\n",
1878 info->hwnd, info->msg, SPY_GetMsgName(info->msg, info->hwnd), info->wparam,
1879 info->lparam, *result, status );
1881 /* MSDN states that last error is 0 on timeout, but at least NT4 returns ERROR_TIMEOUT */
1882 if (status) SetLastError( RtlNtStatusToDosError(status) );
1887 /***********************************************************************
1888 * send_inter_thread_message
1890 static LRESULT send_inter_thread_message( DWORD dest_tid, const struct send_message_info *info,
1895 size_t reply_size = 0;
1897 TRACE( "hwnd %p msg %x (%s) wp %x lp %lx\n",
1898 info->hwnd, info->msg, SPY_GetMsgName(info->msg, info->hwnd), info->wparam, info->lparam );
1900 if (!put_message_in_queue( dest_tid, info, &reply_size )) return 0;
1902 /* there's no reply to wait for on notify/callback messages */
1903 if (info->type == MSG_NOTIFY || info->type == MSG_CALLBACK) return 1;
1905 locks = WIN_SuspendWndsLock();
1907 wait_message_reply( info->flags );
1908 ret = retrieve_reply( info, reply_size, res_ptr );
1910 WIN_RestoreWndsLock( locks );
1915 /***********************************************************************
1916 * MSG_SendInternalMessageTimeout
1918 * Same as SendMessageTimeoutW but sends the message to a specific thread
1919 * without requiring a window handle. Only works for internal Wine messages.
1921 LRESULT MSG_SendInternalMessageTimeout( DWORD dest_pid, DWORD dest_tid,
1922 UINT msg, WPARAM wparam, LPARAM lparam,
1923 UINT flags, UINT timeout, PDWORD_PTR res_ptr )
1925 struct send_message_info info;
1926 LRESULT ret, result;
1928 assert( msg & 0x80000000 ); /* must be an internal Wine message */
1930 info.type = MSG_UNICODE;
1933 info.wparam = wparam;
1934 info.lparam = lparam;
1936 info.timeout = timeout;
1938 if (USER_IsExitingThread( dest_tid )) return 0;
1940 if (dest_tid == GetCurrentThreadId())
1942 result = handle_internal_message( 0, msg, wparam, lparam );
1947 if (dest_pid != GetCurrentProcessId()) info.type = MSG_OTHER_PROCESS;
1948 ret = send_inter_thread_message( dest_tid, &info, &result );
1950 if (ret && res_ptr) *res_ptr = result;
1955 /***********************************************************************
1956 * SendMessageTimeoutW (USER32.@)
1958 LRESULT WINAPI SendMessageTimeoutW( HWND hwnd, UINT msg, WPARAM wparam, LPARAM lparam,
1959 UINT flags, UINT timeout, PDWORD_PTR res_ptr )
1961 struct send_message_info info;
1962 DWORD dest_tid, dest_pid;
1963 LRESULT ret, result;
1965 info.type = MSG_UNICODE;
1968 info.wparam = wparam;
1969 info.lparam = lparam;
1971 info.timeout = timeout;
1973 if (is_broadcast(hwnd))
1975 EnumWindows( broadcast_message_callback, (LPARAM)&info );
1976 if (res_ptr) *res_ptr = 1;
1980 if (!(dest_tid = GetWindowThreadProcessId( hwnd, &dest_pid ))) return 0;
1982 if (USER_IsExitingThread( dest_tid )) return 0;
1984 SPY_EnterMessage( SPY_SENDMESSAGE, hwnd, msg, wparam, lparam );
1986 if (dest_tid == GetCurrentThreadId())
1988 result = call_window_proc( hwnd, msg, wparam, lparam, TRUE, TRUE );
1993 if (dest_pid != GetCurrentProcessId()) info.type = MSG_OTHER_PROCESS;
1994 ret = send_inter_thread_message( dest_tid, &info, &result );
1997 SPY_ExitMessage( SPY_RESULT_OK, hwnd, msg, result, wparam, lparam );
1998 if (ret && res_ptr) *res_ptr = result;
2003 /***********************************************************************
2004 * SendMessageTimeoutA (USER32.@)
2006 LRESULT WINAPI SendMessageTimeoutA( HWND hwnd, UINT msg, WPARAM wparam, LPARAM lparam,
2007 UINT flags, UINT timeout, PDWORD_PTR res_ptr )
2009 struct send_message_info info;
2010 DWORD dest_tid, dest_pid;
2011 LRESULT ret, result;
2013 info.type = MSG_ASCII;
2016 info.wparam = wparam;
2017 info.lparam = lparam;
2019 info.timeout = timeout;
2021 if (is_broadcast(hwnd))
2023 EnumWindows( broadcast_message_callback, (LPARAM)&info );
2024 if (res_ptr) *res_ptr = 1;
2028 if (!(dest_tid = GetWindowThreadProcessId( hwnd, &dest_pid ))) return 0;
2030 if (USER_IsExitingThread( dest_tid )) return 0;
2032 SPY_EnterMessage( SPY_SENDMESSAGE, hwnd, msg, wparam, lparam );
2034 if (dest_tid == GetCurrentThreadId())
2036 result = call_window_proc( hwnd, msg, wparam, lparam, FALSE, TRUE );
2039 else if (dest_pid == GetCurrentProcessId())
2041 ret = send_inter_thread_message( dest_tid, &info, &result );
2045 /* inter-process message: need to map to Unicode */
2046 info.type = MSG_OTHER_PROCESS;
2047 if (is_unicode_message( info.msg ))
2049 if (WINPROC_MapMsg32ATo32W( info.hwnd, info.msg, &info.wparam, &info.lparam ) == -1)
2051 ret = send_inter_thread_message( dest_tid, &info, &result );
2052 result = WINPROC_UnmapMsg32ATo32W( info.hwnd, info.msg, info.wparam,
2053 info.lparam, result );
2055 else ret = send_inter_thread_message( dest_tid, &info, &result );
2057 SPY_ExitMessage( SPY_RESULT_OK, hwnd, msg, result, wparam, lparam );
2058 if (ret && res_ptr) *res_ptr = result;
2063 /***********************************************************************
2064 * SendMessageW (USER32.@)
2066 LRESULT WINAPI SendMessageW( HWND hwnd, UINT msg, WPARAM wparam, LPARAM lparam )
2069 SendMessageTimeoutW( hwnd, msg, wparam, lparam, SMTO_NORMAL, INFINITE, &res );
2074 /***********************************************************************
2075 * SendMessageA (USER32.@)
2077 LRESULT WINAPI SendMessageA( HWND hwnd, UINT msg, WPARAM wparam, LPARAM lparam )
2080 SendMessageTimeoutA( hwnd, msg, wparam, lparam, SMTO_NORMAL, INFINITE, &res );
2085 /***********************************************************************
2086 * SendNotifyMessageA (USER32.@)
2088 BOOL WINAPI SendNotifyMessageA( HWND hwnd, UINT msg, WPARAM wparam, LPARAM lparam )
2090 return SendNotifyMessageW( hwnd, msg, map_wparam_AtoW( msg, wparam ), lparam );
2094 /***********************************************************************
2095 * SendNotifyMessageW (USER32.@)
2097 BOOL WINAPI SendNotifyMessageW( HWND hwnd, UINT msg, WPARAM wparam, LPARAM lparam )
2099 struct send_message_info info;
2103 if (is_pointer_message(msg))
2105 SetLastError( ERROR_MESSAGE_SYNC_ONLY );
2109 info.type = MSG_NOTIFY;
2112 info.wparam = wparam;
2113 info.lparam = lparam;
2116 if (is_broadcast(hwnd))
2118 EnumWindows( broadcast_message_callback, (LPARAM)&info );
2122 if (!(dest_tid = GetWindowThreadProcessId( hwnd, NULL ))) return FALSE;
2124 if (USER_IsExitingThread( dest_tid )) return TRUE;
2126 if (dest_tid == GetCurrentThreadId())
2128 call_window_proc( hwnd, msg, wparam, lparam, TRUE, TRUE );
2131 return send_inter_thread_message( dest_tid, &info, &result );
2135 /***********************************************************************
2136 * SendMessageCallbackA (USER32.@)
2138 BOOL WINAPI SendMessageCallbackA( HWND hwnd, UINT msg, WPARAM wparam, LPARAM lparam,
2139 SENDASYNCPROC callback, ULONG_PTR data )
2141 return SendMessageCallbackW( hwnd, msg, map_wparam_AtoW( msg, wparam ),
2142 lparam, callback, data );
2146 /***********************************************************************
2147 * SendMessageCallbackW (USER32.@)
2149 BOOL WINAPI SendMessageCallbackW( HWND hwnd, UINT msg, WPARAM wparam, LPARAM lparam,
2150 SENDASYNCPROC callback, ULONG_PTR data )
2152 struct send_message_info info;
2156 if (is_pointer_message(msg))
2158 SetLastError( ERROR_MESSAGE_SYNC_ONLY );
2162 info.type = MSG_CALLBACK;
2165 info.wparam = wparam;
2166 info.lparam = lparam;
2167 info.callback = callback;
2171 if (is_broadcast(hwnd))
2173 EnumWindows( broadcast_message_callback, (LPARAM)&info );
2177 if (!(dest_tid = GetWindowThreadProcessId( hwnd, NULL ))) return FALSE;
2179 if (USER_IsExitingThread( dest_tid )) return TRUE;
2181 if (dest_tid == GetCurrentThreadId())
2183 result = call_window_proc( hwnd, msg, wparam, lparam, TRUE, TRUE );
2184 call_sendmsg_callback( callback, hwnd, msg, data, result );
2187 FIXME( "callback will not be called\n" );
2188 return send_inter_thread_message( dest_tid, &info, &result );
2192 /***********************************************************************
2193 * ReplyMessage (USER32.@)
2195 BOOL WINAPI ReplyMessage( LRESULT result )
2197 MESSAGEQUEUE *queue = QUEUE_Current();
2198 struct received_message_info *info = queue->receive_info;
2200 if (!info) return FALSE;
2201 reply_message( info, result, FALSE );
2206 /***********************************************************************
2207 * InSendMessage (USER32.@)
2209 BOOL WINAPI InSendMessage(void)
2211 return (InSendMessageEx(NULL) & (ISMEX_SEND|ISMEX_REPLIED)) == ISMEX_SEND;
2215 /***********************************************************************
2216 * InSendMessageEx (USER32.@)
2218 DWORD WINAPI InSendMessageEx( LPVOID reserved )
2220 MESSAGEQUEUE *queue = QUEUE_Current();
2221 struct received_message_info *info = queue->receive_info;
2223 if (info) return info->flags;
2224 return ISMEX_NOSEND;
2228 /***********************************************************************
2229 * PostMessageA (USER32.@)
2231 BOOL WINAPI PostMessageA( HWND hwnd, UINT msg, WPARAM wparam, LPARAM lparam )
2233 return PostMessageW( hwnd, msg, map_wparam_AtoW( msg, wparam ), lparam );
2237 /***********************************************************************
2238 * PostMessageW (USER32.@)
2240 BOOL WINAPI PostMessageW( HWND hwnd, UINT msg, WPARAM wparam, LPARAM lparam )
2242 struct send_message_info info;
2245 if (is_pointer_message( msg ))
2247 SetLastError( ERROR_MESSAGE_SYNC_ONLY );
2251 TRACE( "hwnd %p msg %x (%s) wp %x lp %lx\n",
2252 hwnd, msg, SPY_GetMsgName(msg, hwnd), wparam, lparam );
2254 info.type = MSG_POSTED;
2257 info.wparam = wparam;
2258 info.lparam = lparam;
2261 if (is_broadcast(hwnd))
2263 EnumWindows( broadcast_message_callback, (LPARAM)&info );
2267 if (!hwnd) return PostThreadMessageW( GetCurrentThreadId(), msg, wparam, lparam );
2269 if (!(dest_tid = GetWindowThreadProcessId( hwnd, NULL ))) return FALSE;
2271 if (USER_IsExitingThread( dest_tid )) return TRUE;
2273 return put_message_in_queue( dest_tid, &info, NULL );
2277 /**********************************************************************
2278 * PostThreadMessageA (USER32.@)
2280 BOOL WINAPI PostThreadMessageA( DWORD thread, UINT msg, WPARAM wparam, LPARAM lparam )
2282 return PostThreadMessageW( thread, msg, map_wparam_AtoW( msg, wparam ), lparam );
2286 /**********************************************************************
2287 * PostThreadMessageW (USER32.@)
2289 BOOL WINAPI PostThreadMessageW( DWORD thread, UINT msg, WPARAM wparam, LPARAM lparam )
2291 struct send_message_info info;
2293 if (is_pointer_message( msg ))
2295 SetLastError( ERROR_MESSAGE_SYNC_ONLY );
2298 if (USER_IsExitingThread( thread )) return TRUE;
2300 info.type = MSG_POSTED;
2303 info.wparam = wparam;
2304 info.lparam = lparam;
2306 return put_message_in_queue( thread, &info, NULL );
2310 /***********************************************************************
2311 * PostQuitMessage (USER32.@)
2313 void WINAPI PostQuitMessage( INT exitCode )
2315 PostThreadMessageW( GetCurrentThreadId(), WM_QUIT, exitCode, 0 );
2319 /***********************************************************************
2320 * PeekMessageW (USER32.@)
2322 BOOL WINAPI PeekMessageW( MSG *msg_out, HWND hwnd, UINT first, UINT last, UINT flags )
2324 MESSAGEQUEUE *queue;
2328 /* check for graphics events */
2329 if (USER_Driver.pMsgWaitForMultipleObjectsEx)
2330 USER_Driver.pMsgWaitForMultipleObjectsEx( 0, NULL, 0, 0, 0 );
2332 hwnd = WIN_GetFullHandle( hwnd );
2333 locks = WIN_SuspendWndsLock();
2335 if (!MSG_peek_message( &msg, hwnd, first, last,
2336 (flags & PM_REMOVE) ? GET_MSG_REMOVE : 0 ))
2338 if (!(flags & PM_NOYIELD))
2341 ReleaseThunkLock(&count);
2342 if (count) RestoreThunkLock(count);
2344 WIN_RestoreWndsLock( locks );
2348 WIN_RestoreWndsLock( locks );
2350 if (msg.message == WM_PAINT) /* clear internal paint flag */
2351 RedrawWindow( msg.hwnd, NULL, 0, RDW_NOINTERNALPAINT | RDW_NOCHILDREN );
2353 if ((queue = QUEUE_Current()))
2355 queue->GetMessageTimeVal = msg.time;
2356 msg.pt.x = LOWORD( queue->GetMessagePosVal );
2357 msg.pt.y = HIWORD( queue->GetMessagePosVal );
2360 HOOK_CallHooks( WH_GETMESSAGE, HC_ACTION, flags & PM_REMOVE, (LPARAM)&msg, TRUE );
2362 /* copy back our internal safe copy of message data to msg_out.
2363 * msg_out is a variable from the *program*, so it can't be used
2364 * internally as it can get "corrupted" by our use of SendMessage()
2365 * (back to the program) inside the message handling itself. */
2368 SetLastError( ERROR_NOACCESS );
2376 /***********************************************************************
2377 * PeekMessageA (USER32.@)
2379 BOOL WINAPI PeekMessageA( MSG *msg, HWND hwnd, UINT first, UINT last, UINT flags )
2381 BOOL ret = PeekMessageW( msg, hwnd, first, last, flags );
2382 if (ret) msg->wParam = map_wparam_WtoA( msg->message, msg->wParam );
2387 /***********************************************************************
2388 * GetMessageW (USER32.@)
2390 BOOL WINAPI GetMessageW( MSG *msg, HWND hwnd, UINT first, UINT last )
2392 MESSAGEQUEUE *queue = QUEUE_Current();
2395 mask = QS_POSTMESSAGE | QS_SENDMESSAGE; /* Always selected */
2398 if ((first <= WM_KEYLAST) && (last >= WM_KEYFIRST)) mask |= QS_KEY;
2399 if ( ((first <= WM_MOUSELAST) && (last >= WM_MOUSEFIRST)) ||
2400 ((first <= WM_NCMOUSELAST) && (last >= WM_NCMOUSEFIRST)) ) mask |= QS_MOUSE;
2401 if ((first <= WM_TIMER) && (last >= WM_TIMER)) mask |= QS_TIMER;
2402 if ((first <= WM_SYSTIMER) && (last >= WM_SYSTIMER)) mask |= QS_TIMER;
2403 if ((first <= WM_PAINT) && (last >= WM_PAINT)) mask |= QS_PAINT;
2405 else mask |= QS_MOUSE | QS_KEY | QS_TIMER | QS_PAINT;
2407 locks = WIN_SuspendWndsLock();
2409 while (!PeekMessageW( msg, hwnd, first, last, PM_REMOVE ))
2411 /* wait until one of the bits is set */
2412 unsigned int wake_bits = 0, changed_bits = 0;
2415 SERVER_START_REQ( set_queue_mask )
2417 req->wake_mask = QS_SENDMESSAGE;
2418 req->changed_mask = mask;
2420 if (!wine_server_call( req ))
2422 wake_bits = reply->wake_bits;
2423 changed_bits = reply->changed_bits;
2428 if (changed_bits & mask) continue;
2429 if (wake_bits & QS_SENDMESSAGE) continue;
2431 TRACE( "(%04x) mask=%08x, bits=%08x, changed=%08x, waiting\n",
2432 queue->self, mask, wake_bits, changed_bits );
2434 ReleaseThunkLock( &dwlc );
2435 if (USER_Driver.pMsgWaitForMultipleObjectsEx)
2436 USER_Driver.pMsgWaitForMultipleObjectsEx( 1, &queue->server_queue, INFINITE, 0, 0 );
2438 WaitForSingleObject( queue->server_queue, INFINITE );
2439 if (dwlc) RestoreThunkLock( dwlc );
2442 WIN_RestoreWndsLock( locks );
2444 return (msg->message != WM_QUIT);
2448 /***********************************************************************
2449 * GetMessageA (USER32.@)
2451 BOOL WINAPI GetMessageA( MSG *msg, HWND hwnd, UINT first, UINT last )
2453 GetMessageW( msg, hwnd, first, last );
2454 msg->wParam = map_wparam_WtoA( msg->message, msg->wParam );
2455 return (msg->message != WM_QUIT);
2459 /***********************************************************************
2460 * IsDialogMessage (USER32.@)
2461 * IsDialogMessageA (USER32.@)
2463 BOOL WINAPI IsDialogMessageA( HWND hwndDlg, LPMSG pmsg )
2466 msg.wParam = map_wparam_AtoW( msg.message, msg.wParam );
2467 return IsDialogMessageW( hwndDlg, &msg );
2471 /***********************************************************************
2472 * SetMessageQueue (USER32.@)
2474 BOOL WINAPI SetMessageQueue( INT size )
2476 /* now obsolete the message queue will be expanded dynamically as necessary */
2481 /***********************************************************************
2482 * MessageBeep (USER32.@)
2484 BOOL WINAPI MessageBeep( UINT i )
2487 SystemParametersInfoA( SPI_GETBEEP, 0, &active, FALSE );
2488 if (active && USER_Driver.pBeep) USER_Driver.pBeep();
2493 /***********************************************************************
2494 * SetTimer (USER32.@)
2496 UINT_PTR WINAPI SetTimer( HWND hwnd, UINT_PTR id, UINT timeout, TIMERPROC proc )
2499 WNDPROC winproc = 0;
2501 if (proc) winproc = WINPROC_AllocProc( (WNDPROC)proc, WIN_PROC_32A );
2503 SERVER_START_REQ( set_win_timer )
2506 req->msg = WM_TIMER;
2508 req->rate = max( timeout, SYS_TIMER_RATE );
2509 req->lparam = (unsigned int)winproc;
2510 if (!wine_server_call_err( req ))
2513 if (!ret) ret = TRUE;
2519 TRACE("Added %p %x %p timeout %d\n", hwnd, id, winproc, timeout );
2524 /***********************************************************************
2525 * SetSystemTimer (USER32.@)
2527 UINT_PTR WINAPI SetSystemTimer( HWND hwnd, UINT_PTR id, UINT timeout, TIMERPROC proc )
2530 WNDPROC winproc = 0;
2532 if (proc) winproc = WINPROC_AllocProc( (WNDPROC)proc, WIN_PROC_32A );
2534 SERVER_START_REQ( set_win_timer )
2537 req->msg = WM_SYSTIMER;
2539 req->rate = max( timeout, SYS_TIMER_RATE );
2540 req->lparam = (unsigned int)winproc;
2541 if (!wine_server_call_err( req ))
2544 if (!ret) ret = TRUE;
2550 TRACE("Added %p %x %p timeout %d\n", hwnd, id, winproc, timeout );
2555 /***********************************************************************
2556 * KillTimer (USER32.@)
2558 BOOL WINAPI KillTimer( HWND hwnd, UINT_PTR id )
2562 TRACE("%p %d\n", hwnd, id );
2564 SERVER_START_REQ( kill_win_timer )
2567 req->msg = WM_TIMER;
2569 ret = !wine_server_call_err( req );
2576 /***********************************************************************
2577 * KillSystemTimer (USER32.@)
2579 BOOL WINAPI KillSystemTimer( HWND hwnd, UINT_PTR id )
2583 TRACE("%p %d\n", hwnd, id );
2585 SERVER_START_REQ( kill_win_timer )
2588 req->msg = WM_SYSTIMER;
2590 ret = !wine_server_call_err( req );
2597 /**********************************************************************
2598 * AttachThreadInput (USER32.@)
2600 * Attaches the input processing mechanism of one thread to that of
2603 BOOL WINAPI AttachThreadInput( DWORD from, DWORD to, BOOL attach )
2607 SERVER_START_REQ( attach_thread_input )
2609 req->tid_from = from;
2611 req->attach = attach;
2612 ret = !wine_server_call_err( req );
2619 /**********************************************************************
2620 * GetGUIThreadInfo (USER32.@)
2622 BOOL WINAPI GetGUIThreadInfo( DWORD id, GUITHREADINFO *info )
2626 SERVER_START_REQ( get_thread_input )
2629 if ((ret = !wine_server_call_err( req )))
2632 info->hwndActive = reply->active;
2633 info->hwndFocus = reply->focus;
2634 info->hwndCapture = reply->capture;
2635 info->hwndMenuOwner = reply->menu_owner;
2636 info->hwndMoveSize = reply->move_size;
2637 info->hwndCaret = reply->caret;
2638 info->rcCaret.left = reply->rect.left;
2639 info->rcCaret.top = reply->rect.top;
2640 info->rcCaret.right = reply->rect.right;
2641 info->rcCaret.bottom = reply->rect.bottom;
2642 if (reply->menu_owner) info->flags |= GUI_INMENUMODE;
2643 if (reply->move_size) info->flags |= GUI_INMOVESIZE;
2644 if (reply->caret) info->flags |= GUI_CARETBLINKING;
2652 /**********************************************************************
2653 * GetKeyState (USER32.@)
2655 * An application calls the GetKeyState function in response to a
2656 * keyboard-input message. This function retrieves the state of the key
2657 * at the time the input message was generated.
2659 SHORT WINAPI GetKeyState(INT vkey)
2663 SERVER_START_REQ( get_key_state )
2665 req->tid = GetCurrentThreadId();
2667 if (!wine_server_call( req )) retval = (signed char)reply->state;
2670 TRACE("key (0x%x) -> %x\n", vkey, retval);
2675 /**********************************************************************
2676 * GetKeyboardState (USER32.@)
2678 BOOL WINAPI GetKeyboardState( LPBYTE state )
2682 TRACE("(%p)\n", state);
2684 memset( state, 0, 256 );
2685 SERVER_START_REQ( get_key_state )
2687 req->tid = GetCurrentThreadId();
2689 wine_server_set_reply( req, state, 256 );
2690 ret = !wine_server_call_err( req );
2697 /**********************************************************************
2698 * SetKeyboardState (USER32.@)
2700 BOOL WINAPI SetKeyboardState( LPBYTE state )
2704 TRACE("(%p)\n", state);
2706 SERVER_START_REQ( set_key_state )
2708 req->tid = GetCurrentThreadId();
2709 wine_server_add_data( req, state, 256 );
2710 ret = !wine_server_call_err( req );
2716 /******************************************************************
2717 * IsHungAppWindow (USER32.@)
2720 BOOL WINAPI IsHungAppWindow( HWND hWnd )
2723 return !SendMessageTimeoutA(hWnd, WM_NULL, 0, 0, SMTO_ABORTIFHUNG, 5000, &dwResult);
2726 /******************************************************************
2727 * GetLastInputInfo (USER32.@)
2729 BOOL WINAPI GetLastInputInfo(PLASTINPUTINFO plii)
2731 FIXME("%p\n", plii);