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 */
69 /* structure to group all parameters for sent messages of the various kinds */
70 struct send_message_info
72 enum message_type type;
77 UINT flags; /* flags for SendMessageTimeout */
78 UINT timeout; /* timeout for SendMessageTimeout */
79 SENDASYNCPROC callback; /* callback function for SendMessageCallback */
80 ULONG_PTR data; /* callback data */
84 /* flag for messages that contain pointers */
85 /* 32 messages per entry, messages 0..31 map to bits 0..31 */
87 #define SET(msg) (1 << ((msg) & 31))
89 static const unsigned int message_pointer_flags[] =
92 SET(WM_CREATE) | SET(WM_SETTEXT) | SET(WM_GETTEXT) |
93 SET(WM_WININICHANGE) | SET(WM_DEVMODECHANGE),
95 SET(WM_GETMINMAXINFO) | SET(WM_DRAWITEM) | SET(WM_MEASUREITEM) | SET(WM_DELETEITEM) |
98 SET(WM_WINDOWPOSCHANGING) | SET(WM_WINDOWPOSCHANGED) | SET(WM_COPYDATA) |
99 SET(WM_NOTIFY) | SET(WM_HELP),
101 SET(WM_STYLECHANGING) | SET(WM_STYLECHANGED),
103 SET(WM_NCCREATE) | SET(WM_NCCALCSIZE) | SET(WM_GETDLGCODE),
105 SET(EM_GETSEL) | SET(EM_GETRECT) | SET(EM_SETRECT) | SET(EM_SETRECTNP),
107 SET(EM_REPLACESEL) | SET(EM_GETLINE) | SET(EM_SETTABSTOPS),
109 SET(SBM_GETRANGE) | SET(SBM_SETSCROLLINFO) | SET(SBM_GETSCROLLINFO),
115 SET(CB_GETEDITSEL) | SET(CB_ADDSTRING) | SET(CB_DIR) | SET(CB_GETLBTEXT) |
116 SET(CB_INSERTSTRING) | SET(CB_FINDSTRING) | SET(CB_SELECTSTRING) |
117 SET(CB_GETDROPPEDCONTROLRECT) | SET(CB_FINDSTRINGEXACT),
121 SET(LB_ADDSTRING) | SET(LB_INSERTSTRING) | SET(LB_GETTEXT) | SET(LB_SELECTSTRING) |
122 SET(LB_DIR) | SET(LB_FINDSTRING) |
123 SET(LB_GETSELITEMS) | SET(LB_SETTABSTOPS) | SET(LB_ADDFILE) | SET(LB_GETITEMRECT),
125 SET(LB_FINDSTRINGEXACT),
131 SET(WM_NEXTMENU) | SET(WM_SIZING) | SET(WM_MOVING) | SET(WM_DEVICECHANGE),
133 SET(WM_MDICREATE) | SET(WM_MDIGETACTIVE) | SET(WM_DROPOBJECT) |
134 SET(WM_QUERYDROPOBJECT) | SET(WM_DRAGLOOP) | SET(WM_DRAGSELECT) | SET(WM_DRAGMOVE),
148 SET(WM_ASKCBFORMATNAME)
151 /* flags for messages that contain Unicode strings */
152 static const unsigned int message_unicode_flags[] =
155 SET(WM_CREATE) | SET(WM_SETTEXT) | SET(WM_GETTEXT) | SET(WM_GETTEXTLENGTH) |
156 SET(WM_WININICHANGE) | SET(WM_DEVMODECHANGE),
168 SET(EM_REPLACESEL) | SET(EM_GETLINE) | SET(EM_SETPASSWORDCHAR),
172 SET(WM_CHAR) | SET(WM_DEADCHAR) | SET(WM_SYSCHAR) | SET(WM_SYSDEADCHAR),
176 SET(CB_ADDSTRING) | SET(CB_DIR) | SET(CB_GETLBTEXT) | SET(CB_GETLBTEXTLEN) |
177 SET(CB_INSERTSTRING) | SET(CB_FINDSTRING) | SET(CB_SELECTSTRING) | SET(CB_FINDSTRINGEXACT),
181 SET(LB_ADDSTRING) | SET(LB_INSERTSTRING) | SET(LB_GETTEXT) | SET(LB_GETTEXTLEN) |
182 SET(LB_SELECTSTRING) | SET(LB_DIR) | SET(LB_FINDSTRING) | SET(LB_ADDFILE),
184 SET(LB_FINDSTRINGEXACT),
206 SET(WM_PAINTCLIPBOARD) | SET(WM_SIZECLIPBOARD) | SET(WM_ASKCBFORMATNAME)
209 /* check whether a given message type includes pointers */
210 inline static int is_pointer_message( UINT message )
212 if (message >= 8*sizeof(message_pointer_flags)) return FALSE;
213 return (message_pointer_flags[message / 32] & SET(message)) != 0;
216 /* check whether a given message type contains Unicode (or ASCII) chars */
217 inline static int is_unicode_message( UINT message )
219 if (message >= 8*sizeof(message_unicode_flags)) return FALSE;
220 return (message_unicode_flags[message / 32] & SET(message)) != 0;
225 /* add a data field to a packed message */
226 inline static void push_data( struct packed_message *data, const void *ptr, size_t size )
228 data->data[data->count] = ptr;
229 data->size[data->count] = size;
233 /* add a string to a packed message */
234 inline static void push_string( struct packed_message *data, LPCWSTR str )
236 push_data( data, str, (strlenW(str) + 1) * sizeof(WCHAR) );
239 /* retrieve a pointer to data from a packed message and increment the buffer pointer */
240 inline static void *get_data( void **buffer, size_t size )
243 *buffer = (char *)*buffer + size;
247 /* make sure that the buffer contains a valid null-terminated Unicode string */
248 inline static BOOL check_string( LPCWSTR str, size_t size )
250 for (size /= sizeof(WCHAR); size; size--, str++)
251 if (!*str) return TRUE;
255 /* make sure that there is space for 'size' bytes in buffer, growing it if needed */
256 inline static void *get_buffer_space( void **buffer, size_t size )
262 if (!(ret = HeapReAlloc( GetProcessHeap(), 0, *buffer, size )))
263 HeapFree( GetProcessHeap(), 0, *buffer );
265 else ret = HeapAlloc( GetProcessHeap(), 0, size );
271 /* retrieve a string pointer from packed data */
272 inline static LPWSTR get_string( void **buffer )
274 return get_data( buffer, (strlenW( (LPWSTR)*buffer ) + 1) * sizeof(WCHAR) );
277 /* check whether a combobox expects strings or ids in CB_ADDSTRING/CB_INSERTSTRING */
278 inline static BOOL combobox_has_strings( HWND hwnd )
280 DWORD style = GetWindowLongA( hwnd, GWL_STYLE );
281 return (!(style & (CBS_OWNERDRAWFIXED | CBS_OWNERDRAWVARIABLE)) || (style & CBS_HASSTRINGS));
284 /* check whether a listbox expects strings or ids in LB_ADDSTRING/LB_INSERTSTRING */
285 inline static BOOL listbox_has_strings( HWND hwnd )
287 DWORD style = GetWindowLongA( hwnd, GWL_STYLE );
288 return (!(style & (LBS_OWNERDRAWFIXED | LBS_OWNERDRAWVARIABLE)) || (style & LBS_HASSTRINGS));
292 /***********************************************************************
293 * broadcast_message_callback
295 * Helper callback for broadcasting messages.
297 static BOOL CALLBACK broadcast_message_callback( HWND hwnd, LPARAM lparam )
299 struct send_message_info *info = (struct send_message_info *)lparam;
300 if (!(GetWindowLongW( hwnd, GWL_STYLE ) & (WS_POPUP|WS_CAPTION))) return TRUE;
304 SendMessageTimeoutW( hwnd, info->msg, info->wparam, info->lparam,
305 info->flags, info->timeout, NULL );
308 SendMessageTimeoutA( hwnd, info->msg, info->wparam, info->lparam,
309 info->flags, info->timeout, NULL );
312 SendNotifyMessageW( hwnd, info->msg, info->wparam, info->lparam );
315 SendMessageCallbackW( hwnd, info->msg, info->wparam, info->lparam,
316 info->callback, info->data );
319 PostMessageW( hwnd, info->msg, info->wparam, info->lparam );
322 ERR( "bad type %d\n", info->type );
329 /***********************************************************************
332 * Convert the wparam of an ASCII message to Unicode.
334 static WPARAM map_wparam_AtoW( UINT message, WPARAM wparam )
339 case EM_SETPASSWORDCHAR:
346 char ch = LOWORD(wparam);
348 MultiByteToWideChar(CP_ACP, 0, &ch, 1, &wch, 1);
349 wparam = MAKEWPARAM( wch, HIWORD(wparam) );
356 ch[0] = (wparam >> 8);
357 ch[1] = (wparam & 0xff);
358 if (ch[0]) MultiByteToWideChar(CP_ACP, 0, ch, 2, &wch, 1);
359 else MultiByteToWideChar(CP_ACP, 0, &ch[1], 1, &wch, 1);
360 wparam = MAKEWPARAM( wch, HIWORD(wparam) );
368 /***********************************************************************
371 * Convert the wparam of a Unicode message to ASCII.
373 static WPARAM map_wparam_WtoA( UINT message, WPARAM wparam )
378 case EM_SETPASSWORDCHAR:
385 WCHAR wch = LOWORD(wparam);
387 WideCharToMultiByte( CP_ACP, 0, &wch, 1, &ch, 1, NULL, NULL );
388 wparam = MAKEWPARAM( ch, HIWORD(wparam) );
393 WCHAR wch = LOWORD(wparam);
396 if (WideCharToMultiByte( CP_ACP, 0, &wch, 1, ch, 2, NULL, NULL ) == 2)
397 wparam = MAKEWPARAM( (ch[0] << 8) | ch[1], HIWORD(wparam) );
399 wparam = MAKEWPARAM( ch[0], HIWORD(wparam) );
407 /***********************************************************************
410 * Pack a message for sending to another process.
411 * Return the size of the data we expect in the message reply.
412 * Set data->count to -1 if there is an error.
414 static size_t pack_message( HWND hwnd, UINT message, WPARAM wparam, LPARAM lparam,
415 struct packed_message *data )
423 CREATESTRUCTW *cs = (CREATESTRUCTW *)lparam;
424 push_data( data, cs, sizeof(*cs) );
425 if (HIWORD(cs->lpszName)) push_string( data, cs->lpszName );
426 if (HIWORD(cs->lpszClass)) push_string( data, cs->lpszClass );
430 case WM_ASKCBFORMATNAME:
431 return wparam * sizeof(WCHAR);
432 case WM_WININICHANGE:
433 if (lparam) push_string(data, (LPWSTR)lparam );
436 case WM_DEVMODECHANGE:
441 push_string( data, (LPWSTR)lparam );
443 case WM_GETMINMAXINFO:
444 push_data( data, (MINMAXINFO *)lparam, sizeof(MINMAXINFO) );
445 return sizeof(MINMAXINFO);
447 push_data( data, (DRAWITEMSTRUCT *)lparam, sizeof(DRAWITEMSTRUCT) );
450 push_data( data, (MEASUREITEMSTRUCT *)lparam, sizeof(MEASUREITEMSTRUCT) );
451 return sizeof(MEASUREITEMSTRUCT);
453 push_data( data, (DELETEITEMSTRUCT *)lparam, sizeof(DELETEITEMSTRUCT) );
456 push_data( data, (COMPAREITEMSTRUCT *)lparam, sizeof(COMPAREITEMSTRUCT) );
458 case WM_WINDOWPOSCHANGING:
459 case WM_WINDOWPOSCHANGED:
460 push_data( data, (WINDOWPOS *)lparam, sizeof(WINDOWPOS) );
461 return sizeof(WINDOWPOS);
464 COPYDATASTRUCT *cp = (COPYDATASTRUCT *)lparam;
465 push_data( data, cp, sizeof(*cp) );
466 if (cp->lpData) push_data( data, cp->lpData, cp->cbData );
470 /* WM_NOTIFY cannot be sent across processes (MSDN) */
474 push_data( data, (HELPINFO *)lparam, sizeof(HELPINFO) );
476 case WM_STYLECHANGING:
477 case WM_STYLECHANGED:
478 push_data( data, (STYLESTRUCT *)lparam, sizeof(STYLESTRUCT) );
483 push_data( data, (RECT *)lparam, sizeof(RECT) );
488 NCCALCSIZE_PARAMS *nc = (NCCALCSIZE_PARAMS *)lparam;
489 push_data( data, nc, sizeof(*nc) );
490 push_data( data, nc->lppos, sizeof(*nc->lppos) );
491 return sizeof(*nc) + sizeof(*nc->lppos);
494 if (lparam) push_data( data, (MSG *)lparam, sizeof(MSG) );
496 case SBM_SETSCROLLINFO:
497 push_data( data, (SCROLLINFO *)lparam, sizeof(SCROLLINFO) );
499 case SBM_GETSCROLLINFO:
500 push_data( data, (SCROLLINFO *)lparam, sizeof(SCROLLINFO) );
501 return sizeof(SCROLLINFO);
507 if (wparam) size += sizeof(DWORD);
508 if (lparam) size += sizeof(DWORD);
513 case CB_GETDROPPEDCONTROLRECT:
517 push_data( data, (RECT *)lparam, sizeof(RECT) );
521 WORD *pw = (WORD *)lparam;
522 push_data( data, pw, sizeof(*pw) );
523 return *pw * sizeof(WCHAR);
527 if (wparam) push_data( data, (UINT *)lparam, sizeof(UINT) * wparam );
530 case CB_INSERTSTRING:
532 case CB_FINDSTRINGEXACT:
533 case CB_SELECTSTRING:
534 if (combobox_has_strings( hwnd )) push_string( data, (LPWSTR)lparam );
537 if (!combobox_has_strings( hwnd )) return sizeof(ULONG_PTR);
538 return (SendMessageW( hwnd, CB_GETLBTEXTLEN, wparam, 0 ) + 1) * sizeof(WCHAR);
540 case LB_INSERTSTRING:
542 case LB_FINDSTRINGEXACT:
543 case LB_SELECTSTRING:
544 if (listbox_has_strings( hwnd )) push_string( data, (LPWSTR)lparam );
547 if (!listbox_has_strings( hwnd )) return sizeof(ULONG_PTR);
548 return (SendMessageW( hwnd, LB_GETTEXTLEN, wparam, 0 ) + 1) * sizeof(WCHAR);
550 return wparam * sizeof(UINT);
552 push_data( data, (MDINEXTMENU *)lparam, sizeof(MDINEXTMENU) );
553 return sizeof(MDINEXTMENU);
556 push_data( data, (RECT *)lparam, sizeof(RECT) );
560 MDICREATESTRUCTW *cs = (MDICREATESTRUCTW *)lparam;
561 push_data( data, cs, sizeof(*cs) );
562 if (HIWORD(cs->szTitle)) push_string( data, cs->szTitle );
563 if (HIWORD(cs->szClass)) push_string( data, cs->szClass );
566 case WM_MDIGETACTIVE:
567 if (lparam) return sizeof(BOOL);
569 case WM_WINE_SETWINDOWPOS:
570 push_data( data, (WINDOWPOS *)lparam, sizeof(WINDOWPOS) );
572 case WM_WINE_KEYBOARD_LL_HOOK:
573 push_data( data, (KBDLLHOOKSTRUCT *)lparam, sizeof(KBDLLHOOKSTRUCT) );
575 case WM_WINE_MOUSE_LL_HOOK:
576 push_data( data, (MSLLHOOKSTRUCT *)lparam, sizeof(MSLLHOOKSTRUCT) );
579 /* these contain an HFONT */
582 /* these contain an HDC */
585 case WM_ICONERASEBKGND:
587 case WM_CTLCOLORMSGBOX:
588 case WM_CTLCOLOREDIT:
589 case WM_CTLCOLORLISTBOX:
592 case WM_CTLCOLORSCROLLBAR:
593 case WM_CTLCOLORSTATIC:
596 /* these contain an HGLOBAL */
597 case WM_PAINTCLIPBOARD:
598 case WM_SIZECLIPBOARD:
599 /* these contain HICON */
602 case WM_QUERYDRAGICON:
603 case WM_QUERYPARKICON:
604 /* these contain pointers */
606 case WM_QUERYDROPOBJECT:
610 case WM_DEVICECHANGE:
611 FIXME( "msg %x (%s) not supported yet\n", message, SPY_GetMsgName(message, hwnd) );
619 /***********************************************************************
622 * Unpack a message received from another process.
624 static BOOL unpack_message( HWND hwnd, UINT message, WPARAM *wparam, LPARAM *lparam,
625 void **buffer, size_t size )
634 CREATESTRUCTW *cs = *buffer;
635 WCHAR *str = (WCHAR *)(cs + 1);
636 if (size < sizeof(*cs)) return FALSE;
638 if (HIWORD(cs->lpszName))
640 if (!check_string( str, size )) return FALSE;
642 size -= (strlenW(str) + 1) * sizeof(WCHAR);
643 str += strlenW(str) + 1;
645 if (HIWORD(cs->lpszClass))
647 if (!check_string( str, size )) return FALSE;
653 case WM_ASKCBFORMATNAME:
654 if (!get_buffer_space( buffer, (*wparam * sizeof(WCHAR)) )) return FALSE;
656 case WM_WININICHANGE:
657 if (!*lparam) return TRUE;
660 case WM_DEVMODECHANGE:
665 if (!check_string( *buffer, size )) return FALSE;
667 case WM_GETMINMAXINFO:
668 minsize = sizeof(MINMAXINFO);
671 minsize = sizeof(DRAWITEMSTRUCT);
674 minsize = sizeof(MEASUREITEMSTRUCT);
677 minsize = sizeof(DELETEITEMSTRUCT);
680 minsize = sizeof(COMPAREITEMSTRUCT);
682 case WM_WINDOWPOSCHANGING:
683 case WM_WINDOWPOSCHANGED:
684 case WM_WINE_SETWINDOWPOS:
685 minsize = sizeof(WINDOWPOS);
689 COPYDATASTRUCT *cp = *buffer;
690 if (size < sizeof(*cp)) return FALSE;
693 minsize = sizeof(*cp) + cp->cbData;
699 /* WM_NOTIFY cannot be sent across processes (MSDN) */
702 minsize = sizeof(HELPINFO);
704 case WM_STYLECHANGING:
705 case WM_STYLECHANGED:
706 minsize = sizeof(STYLESTRUCT);
709 if (!*wparam) minsize = sizeof(RECT);
712 NCCALCSIZE_PARAMS *nc = *buffer;
713 if (size < sizeof(*nc) + sizeof(*nc->lppos)) return FALSE;
714 nc->lppos = (WINDOWPOS *)(nc + 1);
718 if (!*lparam) return TRUE;
719 minsize = sizeof(MSG);
721 case SBM_SETSCROLLINFO:
722 minsize = sizeof(SCROLLINFO);
724 case SBM_GETSCROLLINFO:
725 if (!get_buffer_space( buffer, sizeof(SCROLLINFO ))) return FALSE;
730 if (*wparam || *lparam)
732 if (!get_buffer_space( buffer, 2*sizeof(DWORD) )) return FALSE;
733 if (*wparam) *wparam = (WPARAM)*buffer;
734 if (*lparam) *lparam = (LPARAM)((DWORD *)*buffer + 1);
739 case CB_GETDROPPEDCONTROLRECT:
740 if (!get_buffer_space( buffer, sizeof(RECT) )) return FALSE;
744 minsize = sizeof(RECT);
749 if (size < sizeof(WORD)) return FALSE;
750 len = *(WORD *)*buffer;
751 if (!get_buffer_space( buffer, (len + 1) * sizeof(WCHAR) )) return FALSE;
752 *lparam = (LPARAM)*buffer + sizeof(WORD); /* don't erase WORD at start of buffer */
757 if (!*wparam) return TRUE;
758 minsize = *wparam * sizeof(UINT);
761 case CB_INSERTSTRING:
763 case CB_FINDSTRINGEXACT:
764 case CB_SELECTSTRING:
766 case LB_INSERTSTRING:
768 case LB_FINDSTRINGEXACT:
769 case LB_SELECTSTRING:
770 if (!*buffer) return TRUE;
771 if (!check_string( *buffer, size )) return FALSE;
775 size = sizeof(ULONG_PTR);
776 if (combobox_has_strings( hwnd ))
777 size = (SendMessageW( hwnd, CB_GETLBTEXTLEN, *wparam, 0 ) + 1) * sizeof(WCHAR);
778 if (!get_buffer_space( buffer, size )) return FALSE;
783 size = sizeof(ULONG_PTR);
784 if (listbox_has_strings( hwnd ))
785 size = (SendMessageW( hwnd, LB_GETTEXTLEN, *wparam, 0 ) + 1) * sizeof(WCHAR);
786 if (!get_buffer_space( buffer, size )) return FALSE;
790 if (!get_buffer_space( buffer, *wparam * sizeof(UINT) )) return FALSE;
793 minsize = sizeof(MDINEXTMENU);
794 if (!get_buffer_space( buffer, sizeof(MDINEXTMENU) )) return FALSE;
798 minsize = sizeof(RECT);
799 if (!get_buffer_space( buffer, sizeof(RECT) )) return FALSE;
803 MDICREATESTRUCTW *cs = *buffer;
804 WCHAR *str = (WCHAR *)(cs + 1);
805 if (size < sizeof(*cs)) return FALSE;
807 if (HIWORD(cs->szTitle))
809 if (!check_string( str, size )) return FALSE;
811 size -= (strlenW(str) + 1) * sizeof(WCHAR);
812 str += strlenW(str) + 1;
814 if (HIWORD(cs->szClass))
816 if (!check_string( str, size )) return FALSE;
821 case WM_MDIGETACTIVE:
822 if (!*lparam) return TRUE;
823 if (!get_buffer_space( buffer, sizeof(BOOL) )) return FALSE;
825 case WM_WINE_KEYBOARD_LL_HOOK:
826 minsize = sizeof(KBDLLHOOKSTRUCT);
828 case WM_WINE_MOUSE_LL_HOOK:
829 minsize = sizeof(MSLLHOOKSTRUCT);
832 /* these contain an HFONT */
835 /* these contain an HDC */
838 case WM_ICONERASEBKGND:
840 case WM_CTLCOLORMSGBOX:
841 case WM_CTLCOLOREDIT:
842 case WM_CTLCOLORLISTBOX:
845 case WM_CTLCOLORSCROLLBAR:
846 case WM_CTLCOLORSTATIC:
849 /* these contain an HGLOBAL */
850 case WM_PAINTCLIPBOARD:
851 case WM_SIZECLIPBOARD:
852 /* these contain HICON */
855 case WM_QUERYDRAGICON:
856 case WM_QUERYPARKICON:
857 /* these contain pointers */
859 case WM_QUERYDROPOBJECT:
863 case WM_DEVICECHANGE:
864 FIXME( "msg %x (%s) not supported yet\n", message, SPY_GetMsgName(message, hwnd) );
868 return TRUE; /* message doesn't need any unpacking */
871 /* default exit for most messages: check minsize and store buffer in lparam */
872 if (size < minsize) return FALSE;
873 *lparam = (LPARAM)*buffer;
878 /***********************************************************************
881 * Pack a reply to a message for sending to another process.
883 static void pack_reply( HWND hwnd, UINT message, WPARAM wparam, LPARAM lparam,
884 LRESULT res, struct packed_message *data )
891 push_data( data, (CREATESTRUCTW *)lparam, sizeof(CREATESTRUCTW) );
896 push_data( data, (WCHAR *)lparam, (res + 1) * sizeof(WCHAR) );
898 case WM_GETMINMAXINFO:
899 push_data( data, (MINMAXINFO *)lparam, sizeof(MINMAXINFO) );
902 push_data( data, (MEASUREITEMSTRUCT *)lparam, sizeof(MEASUREITEMSTRUCT) );
904 case WM_WINDOWPOSCHANGING:
905 case WM_WINDOWPOSCHANGED:
906 push_data( data, (WINDOWPOS *)lparam, sizeof(WINDOWPOS) );
909 if (lparam) push_data( data, (MSG *)lparam, sizeof(MSG) );
911 case SBM_GETSCROLLINFO:
912 push_data( data, (SCROLLINFO *)lparam, sizeof(SCROLLINFO) );
916 case CB_GETDROPPEDCONTROLRECT:
919 push_data( data, (RECT *)lparam, sizeof(RECT) );
923 WORD *ptr = (WORD *)lparam;
924 push_data( data, ptr, ptr[-1] * sizeof(WCHAR) );
928 push_data( data, (UINT *)lparam, wparam * sizeof(UINT) );
930 case WM_MDIGETACTIVE:
931 if (lparam) push_data( data, (BOOL *)lparam, sizeof(BOOL) );
935 push_data( data, (RECT *)lparam, sizeof(RECT) );
938 NCCALCSIZE_PARAMS *nc = (NCCALCSIZE_PARAMS *)lparam;
939 push_data( data, nc, sizeof(*nc) );
940 push_data( data, nc->lppos, sizeof(*nc->lppos) );
946 if (wparam) push_data( data, (DWORD *)wparam, sizeof(DWORD) );
947 if (lparam) push_data( data, (DWORD *)lparam, sizeof(DWORD) );
950 push_data( data, (MDINEXTMENU *)lparam, sizeof(MDINEXTMENU) );
953 push_data( data, (MDICREATESTRUCTW *)lparam, sizeof(MDICREATESTRUCTW) );
955 case WM_ASKCBFORMATNAME:
956 push_data( data, (WCHAR *)lparam, (strlenW((WCHAR *)lparam) + 1) * sizeof(WCHAR) );
962 /***********************************************************************
965 * Unpack a message reply received from another process.
967 static void unpack_reply( HWND hwnd, UINT message, WPARAM wparam, LPARAM lparam,
968 void *buffer, size_t size )
975 CREATESTRUCTW *cs = (CREATESTRUCTW *)lparam;
976 LPCWSTR name = cs->lpszName, class = cs->lpszClass;
977 memcpy( cs, buffer, min( sizeof(*cs), size ));
978 cs->lpszName = name; /* restore the original pointers */
979 cs->lpszClass = class;
983 case WM_ASKCBFORMATNAME:
984 memcpy( (WCHAR *)lparam, buffer, min( wparam*sizeof(WCHAR), size ));
986 case WM_GETMINMAXINFO:
987 memcpy( (MINMAXINFO *)lparam, buffer, min( sizeof(MINMAXINFO), size ));
990 memcpy( (MEASUREITEMSTRUCT *)lparam, buffer, min( sizeof(MEASUREITEMSTRUCT), size ));
992 case WM_WINDOWPOSCHANGING:
993 case WM_WINDOWPOSCHANGED:
994 memcpy( (WINDOWPOS *)lparam, buffer, min( sizeof(WINDOWPOS), size ));
997 if (lparam) memcpy( (MSG *)lparam, buffer, min( sizeof(MSG), size ));
999 case SBM_GETSCROLLINFO:
1000 memcpy( (SCROLLINFO *)lparam, buffer, min( sizeof(SCROLLINFO), size ));
1003 case CB_GETDROPPEDCONTROLRECT:
1004 case LB_GETITEMRECT:
1007 memcpy( (RECT *)lparam, buffer, min( sizeof(RECT), size ));
1010 size = min( size, (size_t)*(WORD *)lparam );
1011 memcpy( (WCHAR *)lparam, buffer, size );
1013 case LB_GETSELITEMS:
1014 memcpy( (UINT *)lparam, buffer, min( wparam*sizeof(UINT), size ));
1018 memcpy( (WCHAR *)lparam, buffer, size );
1021 memcpy( (MDINEXTMENU *)lparam, buffer, min( sizeof(MDINEXTMENU), size ));
1023 case WM_MDIGETACTIVE:
1024 if (lparam) memcpy( (BOOL *)lparam, buffer, min( sizeof(BOOL), size ));
1028 memcpy( (RECT *)lparam, buffer, min( sizeof(RECT), size ));
1031 NCCALCSIZE_PARAMS *nc = (NCCALCSIZE_PARAMS *)lparam;
1032 WINDOWPOS *wp = nc->lppos;
1033 memcpy( nc, buffer, min( sizeof(*nc), size ));
1034 if (size > sizeof(*nc))
1036 size -= sizeof(*nc);
1037 memcpy( wp, (NCCALCSIZE_PARAMS*)buffer + 1, min( sizeof(*wp), size ));
1039 nc->lppos = wp; /* restore the original pointer */
1047 memcpy( (DWORD *)wparam, buffer, min( sizeof(DWORD), size ));
1048 if (size <= sizeof(DWORD)) break;
1049 size -= sizeof(DWORD);
1050 buffer = (DWORD *)buffer + 1;
1052 if (lparam) memcpy( (DWORD *)lparam, buffer, min( sizeof(DWORD), size ));
1056 MDICREATESTRUCTW *cs = (MDICREATESTRUCTW *)lparam;
1057 LPCWSTR title = cs->szTitle, class = cs->szClass;
1058 memcpy( cs, buffer, min( sizeof(*cs), size ));
1059 cs->szTitle = title; /* restore the original pointers */
1060 cs->szClass = class;
1064 ERR( "should not happen: unexpected message %x\n", message );
1070 /***********************************************************************
1073 * Send a reply to a sent message.
1075 static void reply_message( struct received_message_info *info, LRESULT result, BOOL remove )
1077 struct packed_message data;
1078 int i, replied = info->flags & ISMEX_REPLIED;
1080 if (info->flags & ISMEX_NOTIFY) return; /* notify messages don't get replies */
1081 if (!remove && replied) return; /* replied already */
1084 info->flags |= ISMEX_REPLIED;
1086 if (info->type == MSG_OTHER_PROCESS && !replied)
1088 pack_reply( info->msg.hwnd, info->msg.message, info->msg.wParam,
1089 info->msg.lParam, result, &data );
1092 SERVER_START_REQ( reply_message )
1094 req->type = info->type;
1095 req->result = result;
1096 req->remove = remove;
1097 for (i = 0; i < data.count; i++) wine_server_add_data( req, data.data[i], data.size[i] );
1098 wine_server_call( req );
1104 /***********************************************************************
1105 * handle_internal_message
1107 * Handle an internal Wine message instead of calling the window proc.
1109 static LRESULT handle_internal_message( HWND hwnd, UINT msg, WPARAM wparam, LPARAM lparam )
1111 if (hwnd == GetDesktopWindow()) return 0;
1114 case WM_WINE_DESTROYWINDOW:
1115 return WIN_DestroyWindow( hwnd );
1116 case WM_WINE_SETWINDOWPOS:
1117 if (USER_Driver.pSetWindowPos)
1118 return USER_Driver.pSetWindowPos( (WINDOWPOS *)lparam );
1120 case WM_WINE_SHOWWINDOW:
1121 return ShowWindow( hwnd, wparam );
1122 case WM_WINE_SETPARENT:
1123 return (LRESULT)SetParent( hwnd, (HWND)wparam );
1124 case WM_WINE_SETWINDOWLONG:
1125 return (LRESULT)SetWindowLongW( hwnd, wparam, lparam );
1126 case WM_WINE_ENABLEWINDOW:
1127 return EnableWindow( hwnd, wparam );
1128 case WM_WINE_SETACTIVEWINDOW:
1129 return (LRESULT)SetActiveWindow( (HWND)wparam );
1130 case WM_WINE_KEYBOARD_LL_HOOK:
1131 return HOOK_CallHooks( WH_KEYBOARD_LL, HC_ACTION, wparam, lparam, TRUE );
1132 case WM_WINE_MOUSE_LL_HOOK:
1133 return HOOK_CallHooks( WH_MOUSE_LL, HC_ACTION, wparam, lparam, TRUE );
1135 FIXME( "unknown internal message %x\n", msg );
1140 /* since the WM_DDE_ACK response to a WM_DDE_EXECUTE message should contain the handle
1141 * to the memory handle, we keep track (in the server side) of all pairs of handle
1142 * used (the client passes its value and the content of the memory handle), and
1143 * the server stored both values (the client, and the local one, created after the
1144 * content). When a ACK message is generated, the list of pair is searched for a
1145 * matching pair, so that the client memory handle can be returned.
1148 HGLOBAL client_hMem;
1149 HGLOBAL server_hMem;
1152 static struct DDE_pair* dde_pairs;
1153 static int dde_num_alloc;
1154 static int dde_num_used;
1156 static CRITICAL_SECTION dde_crst;
1157 static CRITICAL_SECTION_DEBUG critsect_debug =
1160 { &critsect_debug.ProcessLocksList, &critsect_debug.ProcessLocksList },
1161 0, 0, { 0, (DWORD)(__FILE__ ": dde_crst") }
1163 static CRITICAL_SECTION dde_crst = { &critsect_debug, -1, 0, 0, 0, 0 };
1165 static BOOL dde_add_pair(HGLOBAL chm, HGLOBAL shm)
1170 EnterCriticalSection(&dde_crst);
1172 /* now remember the pair of hMem on both sides */
1173 if (dde_num_used == dde_num_alloc)
1175 struct DDE_pair* tmp;
1177 tmp = HeapReAlloc( GetProcessHeap(), 0, dde_pairs,
1178 (dde_num_alloc + GROWBY) * sizeof(struct DDE_pair));
1180 tmp = HeapAlloc( GetProcessHeap(), 0,
1181 (dde_num_alloc + GROWBY) * sizeof(struct DDE_pair));
1185 LeaveCriticalSection(&dde_crst);
1189 /* zero out newly allocated part */
1190 memset(&dde_pairs[dde_num_alloc], 0, GROWBY * sizeof(struct DDE_pair));
1191 dde_num_alloc += GROWBY;
1194 for (i = 0; i < dde_num_alloc; i++)
1196 if (dde_pairs[i].server_hMem == 0)
1198 dde_pairs[i].client_hMem = chm;
1199 dde_pairs[i].server_hMem = shm;
1204 LeaveCriticalSection(&dde_crst);
1208 static HGLOBAL dde_get_pair(HGLOBAL shm)
1213 EnterCriticalSection(&dde_crst);
1214 for (i = 0; i < dde_num_alloc; i++)
1216 if (dde_pairs[i].server_hMem == shm)
1218 /* free this pair */
1219 dde_pairs[i].server_hMem = 0;
1221 ret = dde_pairs[i].client_hMem;
1225 LeaveCriticalSection(&dde_crst);
1229 /***********************************************************************
1232 * Post a DDE message
1234 static BOOL post_dde_message( DWORD dest_tid, struct packed_message *data, const struct send_message_info *info )
1240 HGLOBAL hunlock = 0;
1244 if (!UnpackDDElParam( info->msg, info->lparam, &uiLo, &uiHi ))
1250 /* DDE messages which don't require packing are:
1259 /* uiHi should contain a hMem from WM_DDE_EXECUTE */
1260 HGLOBAL h = dde_get_pair( (HANDLE)uiHi );
1263 /* send back the value of h on the other side */
1264 push_data( data, &h, sizeof(HGLOBAL) );
1266 TRACE( "send dde-ack %x %08x => %08lx\n", uiLo, uiHi, (DWORD)h );
1271 /* uiHi should contain either an atom or 0 */
1272 TRACE( "send dde-ack %x atom=%x\n", uiLo, uiHi );
1273 lp = MAKELONG( uiLo, uiHi );
1282 size = GlobalSize( (HGLOBAL)uiLo ) ;
1283 if ((info->msg == WM_DDE_ADVISE && size < sizeof(DDEADVISE)) ||
1284 (info->msg == WM_DDE_DATA && size < sizeof(DDEDATA)) ||
1285 (info->msg == WM_DDE_POKE && size < sizeof(DDEPOKE))
1289 else if (info->msg != WM_DDE_DATA) return FALSE;
1294 if ((ptr = GlobalLock( (HGLOBAL)uiLo) ))
1296 DDEDATA *dde_data = (DDEDATA *)ptr;
1297 TRACE("unused %d, fResponse %d, fRelease %d, fDeferUpd %d, fAckReq %d, cfFormat %d\n",
1298 dde_data->unused, dde_data->fResponse, dde_data->fRelease,
1299 dde_data->reserved, dde_data->fAckReq, dde_data->cfFormat);
1300 push_data( data, ptr, size );
1301 hunlock = (HGLOBAL)uiLo;
1304 TRACE( "send ddepack %u %x\n", size, uiHi );
1306 case WM_DDE_EXECUTE:
1309 if ((ptr = GlobalLock( (HGLOBAL)info->lparam) ))
1311 push_data(data, ptr, GlobalSize( (HGLOBAL)info->lparam ));
1312 /* so that the other side can send it back on ACK */
1314 hunlock = (HGLOBAL)info->lparam;
1319 SERVER_START_REQ( send_message )
1322 req->type = info->type;
1324 req->win = info->hwnd;
1325 req->msg = info->msg;
1326 req->wparam = info->wparam;
1328 req->time = GetCurrentTime();
1330 for (i = 0; i < data->count; i++)
1331 wine_server_add_data( req, data->data[i], data->size[i] );
1332 if ((res = wine_server_call( req )))
1334 if (res == STATUS_INVALID_PARAMETER)
1335 /* FIXME: find a STATUS_ value for this one */
1336 SetLastError( ERROR_INVALID_THREAD_ID );
1338 SetLastError( RtlNtStatusToDosError(res) );
1341 FreeDDElParam(info->msg, info->lparam);
1344 if (hunlock) GlobalUnlock(hunlock);
1349 /***********************************************************************
1350 * unpack_dde_message
1352 * Unpack a posted DDE message received from another process.
1354 static BOOL unpack_dde_message( HWND hwnd, UINT message, WPARAM *wparam, LPARAM *lparam,
1355 void **buffer, size_t size )
1366 /* hMem is being passed */
1367 if (size != sizeof(HGLOBAL)) return FALSE;
1368 if (!buffer || !*buffer) return FALSE;
1370 memcpy( &hMem, *buffer, size );
1372 TRACE("recv dde-ack %x mem=%x[%lx]\n", uiLo, uiHi, GlobalSize( hMem ));
1376 uiLo = LOWORD( *lparam );
1377 uiHi = HIWORD( *lparam );
1378 TRACE("recv dde-ack %x atom=%x\n", uiLo, uiHi);
1380 *lparam = PackDDElParam( WM_DDE_ACK, uiLo, uiHi );
1385 if ((!buffer || !*buffer) && message != WM_DDE_DATA) return FALSE;
1387 TRACE( "recv ddepack %u %x\n", size, uiHi );
1390 hMem = GlobalAlloc( GMEM_MOVEABLE|GMEM_DDESHARE, size );
1391 if (hMem && (ptr = GlobalLock( hMem )))
1393 memcpy( ptr, *buffer, size );
1394 GlobalUnlock( hMem );
1400 *lparam = PackDDElParam( message, uiLo, uiHi );
1402 case WM_DDE_EXECUTE:
1405 if (!buffer || !*buffer) return FALSE;
1406 hMem = GlobalAlloc( GMEM_MOVEABLE|GMEM_DDESHARE, size );
1407 if (hMem && (ptr = GlobalLock( hMem )))
1409 memcpy( ptr, *buffer, size );
1410 GlobalUnlock( hMem );
1411 TRACE( "exec: pairing c=%08lx s=%08lx\n", *lparam, (DWORD)hMem );
1412 if (!dde_add_pair( (HGLOBAL)*lparam, hMem ))
1418 } else return FALSE;
1419 *lparam = (LPARAM)hMem;
1425 /***********************************************************************
1428 * Call a window procedure and the corresponding hooks.
1430 static LRESULT call_window_proc( HWND hwnd, UINT msg, WPARAM wparam, LPARAM lparam,
1431 BOOL unicode, BOOL same_thread )
1436 CWPRETSTRUCT cwpret;
1437 MESSAGEQUEUE *queue = QUEUE_Current();
1439 if (queue->recursion_count > MAX_SENDMSG_RECURSION) return 0;
1440 queue->recursion_count++;
1442 if (msg & 0x80000000)
1444 result = handle_internal_message( hwnd, msg, wparam, lparam );
1448 /* first the WH_CALLWNDPROC hook */
1449 hwnd = WIN_GetFullHandle( hwnd );
1450 cwp.lParam = lparam;
1451 cwp.wParam = wparam;
1454 HOOK_CallHooks( WH_CALLWNDPROC, HC_ACTION, same_thread, (LPARAM)&cwp, unicode );
1456 /* now call the window procedure */
1459 if (!(winproc = (WNDPROC)GetWindowLongPtrW( hwnd, GWLP_WNDPROC ))) goto done;
1460 result = CallWindowProcW( winproc, hwnd, msg, wparam, lparam );
1464 if (!(winproc = (WNDPROC)GetWindowLongPtrA( hwnd, GWLP_WNDPROC ))) goto done;
1465 result = CallWindowProcA( winproc, hwnd, msg, wparam, lparam );
1468 /* and finally the WH_CALLWNDPROCRET hook */
1469 cwpret.lResult = result;
1470 cwpret.lParam = lparam;
1471 cwpret.wParam = wparam;
1472 cwpret.message = msg;
1474 HOOK_CallHooks( WH_CALLWNDPROCRET, HC_ACTION, same_thread, (LPARAM)&cwpret, unicode );
1476 queue->recursion_count--;
1481 /***********************************************************************
1482 * process_hardware_message
1484 * Process a hardware message; return TRUE if message should be passed on to the app
1486 static BOOL process_hardware_message( MSG *msg, ULONG_PTR extra_info, HWND hwnd,
1487 UINT first, UINT last, BOOL remove )
1491 if (!MSG_process_raw_hardware_message( msg, extra_info, hwnd, first, last, remove ))
1494 ret = MSG_process_cooked_hardware_message( msg, extra_info, remove );
1496 /* tell the server we have passed it to the app
1497 * (even though we may end up dropping it later on)
1499 SERVER_START_REQ( reply_message )
1501 req->type = MSG_HARDWARE;
1503 req->remove = remove || !ret;
1504 wine_server_call( req );
1511 /***********************************************************************
1512 * call_sendmsg_callback
1514 * Call the callback function of SendMessageCallback.
1516 static inline void call_sendmsg_callback( SENDASYNCPROC callback, HWND hwnd, UINT msg,
1517 ULONG_PTR data, LRESULT result )
1519 if (TRACE_ON(relay))
1520 DPRINTF( "%04lx:Call message callback %p (hwnd=%p,msg=%s,data=%08lx,result=%08lx)\n",
1521 GetCurrentThreadId(), callback, hwnd, SPY_GetMsgName( msg, hwnd ),
1523 callback( hwnd, msg, data, result );
1524 if (TRACE_ON(relay))
1525 DPRINTF( "%04lx:Ret message callback %p (hwnd=%p,msg=%s,data=%08lx,result=%08lx)\n",
1526 GetCurrentThreadId(), callback, hwnd, SPY_GetMsgName( msg, hwnd ),
1531 /***********************************************************************
1534 * Peek for a message matching the given parameters. Return FALSE if none available.
1535 * All pending sent messages are processed before returning.
1537 BOOL MSG_peek_message( MSG *msg, HWND hwnd, UINT first, UINT last, int flags )
1540 ULONG_PTR extra_info = 0;
1541 MESSAGEQUEUE *queue = QUEUE_Current();
1542 struct received_message_info info, *old_info;
1544 if (!first && !last) last = ~0;
1549 void *buffer = NULL;
1550 size_t size = 0, buffer_size = 0;
1552 do /* loop while buffer is too small */
1554 if (buffer_size && !(buffer = HeapAlloc( GetProcessHeap(), 0, buffer_size )))
1556 SERVER_START_REQ( get_message )
1559 req->get_win = hwnd;
1560 req->get_first = first;
1561 req->get_last = last;
1562 if (buffer_size) wine_server_set_reply( req, buffer, buffer_size );
1563 if (!(res = wine_server_call( req )))
1565 size = wine_server_reply_size( reply );
1566 info.type = reply->type;
1567 info.msg.hwnd = reply->win;
1568 info.msg.message = reply->msg;
1569 info.msg.wParam = reply->wparam;
1570 info.msg.lParam = reply->lparam;
1571 info.msg.time = reply->time;
1572 info.msg.pt.x = reply->x;
1573 info.msg.pt.y = reply->y;
1574 extra_info = reply->info;
1578 HeapFree( GetProcessHeap(), 0, buffer );
1579 buffer_size = reply->total;
1583 } while (res == STATUS_BUFFER_OVERFLOW);
1585 if (res) return FALSE;
1587 TRACE( "got type %d msg %x (%s) hwnd %p wp %x lp %lx\n",
1588 info.type, info.msg.message, SPY_GetMsgName(info.msg.message, info.msg.hwnd),
1589 info.msg.hwnd, info.msg.wParam, info.msg.lParam );
1595 info.flags = ISMEX_SEND;
1598 info.flags = ISMEX_NOTIFY;
1601 info.flags = ISMEX_CALLBACK;
1603 case MSG_CALLBACK_RESULT:
1604 call_sendmsg_callback( (SENDASYNCPROC)info.msg.wParam, info.msg.hwnd,
1605 info.msg.message, extra_info, info.msg.lParam );
1607 case MSG_OTHER_PROCESS:
1608 info.flags = ISMEX_SEND;
1609 if (!unpack_message( info.msg.hwnd, info.msg.message, &info.msg.wParam,
1610 &info.msg.lParam, &buffer, size ))
1612 ERR( "invalid packed message %x (%s) hwnd %p wp %x lp %lx size %d\n",
1613 info.msg.message, SPY_GetMsgName(info.msg.message, info.msg.hwnd), info.msg.hwnd,
1614 info.msg.wParam, info.msg.lParam, size );
1616 reply_message( &info, 0, TRUE );
1621 if (!process_hardware_message( &info.msg, extra_info,
1622 hwnd, first, last, flags & GET_MSG_REMOVE ))
1624 TRACE("dropping msg %x\n", info.msg.message );
1625 goto next; /* ignore it */
1627 queue->GetMessagePosVal = MAKELONG( info.msg.pt.x, info.msg.pt.y );
1630 queue->GetMessageExtraInfoVal = extra_info;
1631 if (info.msg.message >= WM_DDE_FIRST && info.msg.message <= WM_DDE_LAST)
1633 if (!unpack_dde_message( info.msg.hwnd, info.msg.message, &info.msg.wParam,
1634 &info.msg.lParam, &buffer, size ))
1636 ERR( "invalid packed dde-message %x (%s) hwnd %p wp %x lp %lx size %d\n",
1637 info.msg.message, SPY_GetMsgName(info.msg.message, info.msg.hwnd),
1638 info.msg.hwnd, info.msg.wParam, info.msg.lParam, size );
1639 goto next; /* ignore it */
1643 HeapFree( GetProcessHeap(), 0, buffer );
1647 /* if we get here, we have a sent message; call the window procedure */
1648 old_info = queue->receive_info;
1649 queue->receive_info = &info;
1650 result = call_window_proc( info.msg.hwnd, info.msg.message, info.msg.wParam,
1651 info.msg.lParam, (info.type != MSG_ASCII), FALSE );
1652 reply_message( &info, result, TRUE );
1653 queue->receive_info = old_info;
1655 HeapFree( GetProcessHeap(), 0, buffer );
1660 /***********************************************************************
1661 * wait_message_reply
1663 * Wait until a sent message gets replied to.
1665 static void wait_message_reply( UINT flags )
1667 MESSAGEQUEUE *queue;
1669 if (!(queue = QUEUE_Current())) return;
1673 unsigned int wake_bits = 0, changed_bits = 0;
1676 SERVER_START_REQ( set_queue_mask )
1678 req->wake_mask = QS_SMRESULT | ((flags & SMTO_BLOCK) ? 0 : QS_SENDMESSAGE);
1679 req->changed_mask = req->wake_mask;
1681 if (!wine_server_call( req ))
1683 wake_bits = reply->wake_bits;
1684 changed_bits = reply->changed_bits;
1689 if (wake_bits & QS_SMRESULT) return; /* got a result */
1690 if (wake_bits & QS_SENDMESSAGE)
1692 /* Process the sent message immediately */
1694 MSG_peek_message( &msg, 0, 0, 0, GET_MSG_REMOVE | GET_MSG_SENT_ONLY );
1698 /* now wait for it */
1700 ReleaseThunkLock( &dwlc );
1702 if (USER_Driver.pMsgWaitForMultipleObjectsEx)
1703 res = USER_Driver.pMsgWaitForMultipleObjectsEx( 1, &queue->server_queue,
1706 res = WaitForSingleObject( queue->server_queue, INFINITE );
1708 if (dwlc) RestoreThunkLock( dwlc );
1712 /***********************************************************************
1713 * put_message_in_queue
1715 * Put a sent message into the destination queue.
1716 * For inter-process message, reply_size is set to expected size of reply data.
1718 static BOOL put_message_in_queue( DWORD dest_tid, const struct send_message_info *info,
1719 size_t *reply_size )
1721 struct packed_message data;
1723 int i, timeout = -1;
1725 if (info->type != MSG_NOTIFY &&
1726 info->type != MSG_CALLBACK &&
1727 info->type != MSG_POSTED &&
1728 info->timeout != INFINITE)
1729 timeout = info->timeout;
1732 if (info->type == MSG_OTHER_PROCESS)
1734 *reply_size = pack_message( info->hwnd, info->msg, info->wparam, info->lparam, &data );
1735 if (data.count == -1)
1737 WARN( "cannot pack message %x\n", info->msg );
1741 else if (info->type == MSG_POSTED && info->msg >= WM_DDE_FIRST && info->msg <= WM_DDE_LAST)
1743 return post_dde_message( dest_tid, &data, info );
1746 SERVER_START_REQ( send_message )
1749 req->type = info->type;
1751 req->win = info->hwnd;
1752 req->msg = info->msg;
1753 req->wparam = info->wparam;
1754 req->lparam = info->lparam;
1755 req->time = GetCurrentTime();
1756 req->timeout = timeout;
1758 if (info->type == MSG_CALLBACK)
1760 req->callback = info->callback;
1761 req->info = info->data;
1764 if (info->flags & SMTO_ABORTIFHUNG) req->flags |= SEND_MSG_ABORT_IF_HUNG;
1765 for (i = 0; i < data.count; i++) wine_server_add_data( req, data.data[i], data.size[i] );
1766 if ((res = wine_server_call( req )))
1768 if (res == STATUS_INVALID_PARAMETER)
1769 /* FIXME: find a STATUS_ value for this one */
1770 SetLastError( ERROR_INVALID_THREAD_ID );
1772 SetLastError( RtlNtStatusToDosError(res) );
1780 /***********************************************************************
1783 * Retrieve a message reply from the server.
1785 static LRESULT retrieve_reply( const struct send_message_info *info,
1786 size_t reply_size, LRESULT *result )
1789 void *reply_data = NULL;
1793 if (!(reply_data = HeapAlloc( GetProcessHeap(), 0, reply_size )))
1795 WARN( "no memory for reply %d bytes, will be truncated\n", reply_size );
1799 SERVER_START_REQ( get_message_reply )
1802 if (reply_size) wine_server_set_reply( req, reply_data, reply_size );
1803 if (!(status = wine_server_call( req ))) *result = reply->result;
1804 reply_size = wine_server_reply_size( reply );
1807 if (!status && reply_size)
1808 unpack_reply( info->hwnd, info->msg, info->wparam, info->lparam, reply_data, reply_size );
1810 HeapFree( GetProcessHeap(), 0, reply_data );
1812 TRACE( "hwnd %p msg %x (%s) wp %x lp %lx got reply %lx (err=%ld)\n",
1813 info->hwnd, info->msg, SPY_GetMsgName(info->msg, info->hwnd), info->wparam,
1814 info->lparam, *result, status );
1816 /* MSDN states that last error is 0 on timeout, but at least NT4 returns ERROR_TIMEOUT */
1817 if (status) SetLastError( RtlNtStatusToDosError(status) );
1822 /***********************************************************************
1823 * send_inter_thread_message
1825 static LRESULT send_inter_thread_message( DWORD dest_tid, const struct send_message_info *info,
1830 size_t reply_size = 0;
1832 TRACE( "hwnd %p msg %x (%s) wp %x lp %lx\n",
1833 info->hwnd, info->msg, SPY_GetMsgName(info->msg, info->hwnd), info->wparam, info->lparam );
1835 if (!put_message_in_queue( dest_tid, info, &reply_size )) return 0;
1837 /* there's no reply to wait for on notify/callback messages */
1838 if (info->type == MSG_NOTIFY || info->type == MSG_CALLBACK) return 1;
1840 locks = WIN_SuspendWndsLock();
1842 wait_message_reply( info->flags );
1843 ret = retrieve_reply( info, reply_size, res_ptr );
1845 WIN_RestoreWndsLock( locks );
1850 /***********************************************************************
1851 * MSG_SendInternalMessageTimeout
1853 * Same as SendMessageTimeoutW but sends the message to a specific thread
1854 * without requiring a window handle. Only works for internal Wine messages.
1856 LRESULT MSG_SendInternalMessageTimeout( DWORD dest_pid, DWORD dest_tid,
1857 UINT msg, WPARAM wparam, LPARAM lparam,
1858 UINT flags, UINT timeout, PDWORD_PTR res_ptr )
1860 struct send_message_info info;
1861 LRESULT ret, result;
1863 assert( msg & 0x80000000 ); /* must be an internal Wine message */
1865 info.type = MSG_UNICODE;
1868 info.wparam = wparam;
1869 info.lparam = lparam;
1871 info.timeout = timeout;
1873 if (USER_IsExitingThread( dest_tid )) return 0;
1875 if (dest_tid == GetCurrentThreadId())
1877 result = handle_internal_message( 0, msg, wparam, lparam );
1882 if (dest_pid != GetCurrentProcessId()) info.type = MSG_OTHER_PROCESS;
1883 ret = send_inter_thread_message( dest_tid, &info, &result );
1885 if (ret && res_ptr) *res_ptr = result;
1890 /***********************************************************************
1891 * SendMessageTimeoutW (USER32.@)
1893 LRESULT WINAPI SendMessageTimeoutW( HWND hwnd, UINT msg, WPARAM wparam, LPARAM lparam,
1894 UINT flags, UINT timeout, PDWORD_PTR res_ptr )
1896 struct send_message_info info;
1897 DWORD dest_tid, dest_pid;
1898 LRESULT ret, result;
1900 info.type = MSG_UNICODE;
1903 info.wparam = wparam;
1904 info.lparam = lparam;
1906 info.timeout = timeout;
1908 if (is_broadcast(hwnd))
1910 EnumWindows( broadcast_message_callback, (LPARAM)&info );
1911 if (res_ptr) *res_ptr = 1;
1915 if (!(dest_tid = GetWindowThreadProcessId( hwnd, &dest_pid ))) return 0;
1917 if (USER_IsExitingThread( dest_tid )) return 0;
1919 SPY_EnterMessage( SPY_SENDMESSAGE, hwnd, msg, wparam, lparam );
1921 if (dest_tid == GetCurrentThreadId())
1923 result = call_window_proc( hwnd, msg, wparam, lparam, TRUE, TRUE );
1928 if (dest_pid != GetCurrentProcessId()) info.type = MSG_OTHER_PROCESS;
1929 ret = send_inter_thread_message( dest_tid, &info, &result );
1932 SPY_ExitMessage( SPY_RESULT_OK, hwnd, msg, result, wparam, lparam );
1933 if (ret && res_ptr) *res_ptr = result;
1938 /***********************************************************************
1939 * SendMessageTimeoutA (USER32.@)
1941 LRESULT WINAPI SendMessageTimeoutA( HWND hwnd, UINT msg, WPARAM wparam, LPARAM lparam,
1942 UINT flags, UINT timeout, PDWORD_PTR res_ptr )
1944 struct send_message_info info;
1945 DWORD dest_tid, dest_pid;
1946 LRESULT ret, result;
1948 info.type = MSG_ASCII;
1951 info.wparam = wparam;
1952 info.lparam = lparam;
1954 info.timeout = timeout;
1956 if (is_broadcast(hwnd))
1958 EnumWindows( broadcast_message_callback, (LPARAM)&info );
1959 if (res_ptr) *res_ptr = 1;
1963 if (!(dest_tid = GetWindowThreadProcessId( hwnd, &dest_pid ))) return 0;
1965 if (USER_IsExitingThread( dest_tid )) return 0;
1967 SPY_EnterMessage( SPY_SENDMESSAGE, hwnd, msg, wparam, lparam );
1969 if (dest_tid == GetCurrentThreadId())
1971 result = call_window_proc( hwnd, msg, wparam, lparam, FALSE, TRUE );
1974 else if (dest_pid == GetCurrentProcessId())
1976 ret = send_inter_thread_message( dest_tid, &info, &result );
1980 /* inter-process message: need to map to Unicode */
1981 info.type = MSG_OTHER_PROCESS;
1982 if (is_unicode_message( info.msg ))
1984 if (WINPROC_MapMsg32ATo32W( info.hwnd, info.msg, &info.wparam, &info.lparam ) == -1)
1986 ret = send_inter_thread_message( dest_tid, &info, &result );
1987 result = WINPROC_UnmapMsg32ATo32W( info.hwnd, info.msg, info.wparam,
1988 info.lparam, result );
1990 else ret = send_inter_thread_message( dest_tid, &info, &result );
1992 SPY_ExitMessage( SPY_RESULT_OK, hwnd, msg, result, wparam, lparam );
1993 if (ret && res_ptr) *res_ptr = result;
1998 /***********************************************************************
1999 * SendMessageW (USER32.@)
2001 LRESULT WINAPI SendMessageW( HWND hwnd, UINT msg, WPARAM wparam, LPARAM lparam )
2004 SendMessageTimeoutW( hwnd, msg, wparam, lparam, SMTO_NORMAL, INFINITE, &res );
2009 /***********************************************************************
2010 * SendMessageA (USER32.@)
2012 LRESULT WINAPI SendMessageA( HWND hwnd, UINT msg, WPARAM wparam, LPARAM lparam )
2015 SendMessageTimeoutA( hwnd, msg, wparam, lparam, SMTO_NORMAL, INFINITE, &res );
2020 /***********************************************************************
2021 * SendNotifyMessageA (USER32.@)
2023 BOOL WINAPI SendNotifyMessageA( HWND hwnd, UINT msg, WPARAM wparam, LPARAM lparam )
2025 return SendNotifyMessageW( hwnd, msg, map_wparam_AtoW( msg, wparam ), lparam );
2029 /***********************************************************************
2030 * SendNotifyMessageW (USER32.@)
2032 BOOL WINAPI SendNotifyMessageW( HWND hwnd, UINT msg, WPARAM wparam, LPARAM lparam )
2034 struct send_message_info info;
2038 if (is_pointer_message(msg))
2040 SetLastError( ERROR_MESSAGE_SYNC_ONLY );
2044 info.type = MSG_NOTIFY;
2047 info.wparam = wparam;
2048 info.lparam = lparam;
2051 if (is_broadcast(hwnd))
2053 EnumWindows( broadcast_message_callback, (LPARAM)&info );
2057 if (!(dest_tid = GetWindowThreadProcessId( hwnd, NULL ))) return FALSE;
2059 if (USER_IsExitingThread( dest_tid )) return TRUE;
2061 if (dest_tid == GetCurrentThreadId())
2063 call_window_proc( hwnd, msg, wparam, lparam, TRUE, TRUE );
2066 return send_inter_thread_message( dest_tid, &info, &result );
2070 /***********************************************************************
2071 * SendMessageCallbackA (USER32.@)
2073 BOOL WINAPI SendMessageCallbackA( HWND hwnd, UINT msg, WPARAM wparam, LPARAM lparam,
2074 SENDASYNCPROC callback, ULONG_PTR data )
2076 return SendMessageCallbackW( hwnd, msg, map_wparam_AtoW( msg, wparam ),
2077 lparam, callback, data );
2081 /***********************************************************************
2082 * SendMessageCallbackW (USER32.@)
2084 BOOL WINAPI SendMessageCallbackW( HWND hwnd, UINT msg, WPARAM wparam, LPARAM lparam,
2085 SENDASYNCPROC callback, ULONG_PTR data )
2087 struct send_message_info info;
2091 if (is_pointer_message(msg))
2093 SetLastError( ERROR_MESSAGE_SYNC_ONLY );
2097 info.type = MSG_CALLBACK;
2100 info.wparam = wparam;
2101 info.lparam = lparam;
2102 info.callback = callback;
2106 if (is_broadcast(hwnd))
2108 EnumWindows( broadcast_message_callback, (LPARAM)&info );
2112 if (!(dest_tid = GetWindowThreadProcessId( hwnd, NULL ))) return FALSE;
2114 if (USER_IsExitingThread( dest_tid )) return TRUE;
2116 if (dest_tid == GetCurrentThreadId())
2118 result = call_window_proc( hwnd, msg, wparam, lparam, TRUE, TRUE );
2119 call_sendmsg_callback( callback, hwnd, msg, data, result );
2122 FIXME( "callback will not be called\n" );
2123 return send_inter_thread_message( dest_tid, &info, &result );
2127 /***********************************************************************
2128 * ReplyMessage (USER32.@)
2130 BOOL WINAPI ReplyMessage( LRESULT result )
2132 MESSAGEQUEUE *queue = QUEUE_Current();
2133 struct received_message_info *info = queue->receive_info;
2135 if (!info) return FALSE;
2136 reply_message( info, result, FALSE );
2141 /***********************************************************************
2142 * InSendMessage (USER32.@)
2144 BOOL WINAPI InSendMessage(void)
2146 return (InSendMessageEx(NULL) & (ISMEX_SEND|ISMEX_REPLIED)) == ISMEX_SEND;
2150 /***********************************************************************
2151 * InSendMessageEx (USER32.@)
2153 DWORD WINAPI InSendMessageEx( LPVOID reserved )
2155 MESSAGEQUEUE *queue = QUEUE_Current();
2156 struct received_message_info *info = queue->receive_info;
2158 if (info) return info->flags;
2159 return ISMEX_NOSEND;
2163 /***********************************************************************
2164 * PostMessageA (USER32.@)
2166 BOOL WINAPI PostMessageA( HWND hwnd, UINT msg, WPARAM wparam, LPARAM lparam )
2168 return PostMessageW( hwnd, msg, map_wparam_AtoW( msg, wparam ), lparam );
2172 /***********************************************************************
2173 * PostMessageW (USER32.@)
2175 BOOL WINAPI PostMessageW( HWND hwnd, UINT msg, WPARAM wparam, LPARAM lparam )
2177 struct send_message_info info;
2180 if (is_pointer_message( msg ))
2182 SetLastError( ERROR_MESSAGE_SYNC_ONLY );
2186 TRACE( "hwnd %p msg %x (%s) wp %x lp %lx\n",
2187 hwnd, msg, SPY_GetMsgName(msg, hwnd), wparam, lparam );
2189 info.type = MSG_POSTED;
2192 info.wparam = wparam;
2193 info.lparam = lparam;
2196 if (is_broadcast(hwnd))
2198 EnumWindows( broadcast_message_callback, (LPARAM)&info );
2202 if (!hwnd) return PostThreadMessageW( GetCurrentThreadId(), msg, wparam, lparam );
2204 if (!(dest_tid = GetWindowThreadProcessId( hwnd, NULL ))) return FALSE;
2206 if (USER_IsExitingThread( dest_tid )) return TRUE;
2208 return put_message_in_queue( dest_tid, &info, NULL );
2212 /**********************************************************************
2213 * PostThreadMessageA (USER32.@)
2215 BOOL WINAPI PostThreadMessageA( DWORD thread, UINT msg, WPARAM wparam, LPARAM lparam )
2217 return PostThreadMessageW( thread, msg, map_wparam_AtoW( msg, wparam ), lparam );
2221 /**********************************************************************
2222 * PostThreadMessageW (USER32.@)
2224 BOOL WINAPI PostThreadMessageW( DWORD thread, UINT msg, WPARAM wparam, LPARAM lparam )
2226 struct send_message_info info;
2228 if (is_pointer_message( msg ))
2230 SetLastError( ERROR_MESSAGE_SYNC_ONLY );
2233 if (USER_IsExitingThread( thread )) return TRUE;
2235 info.type = MSG_POSTED;
2238 info.wparam = wparam;
2239 info.lparam = lparam;
2241 return put_message_in_queue( thread, &info, NULL );
2245 /***********************************************************************
2246 * PostQuitMessage (USER32.@)
2248 void WINAPI PostQuitMessage( INT exitCode )
2250 PostThreadMessageW( GetCurrentThreadId(), WM_QUIT, exitCode, 0 );
2254 /***********************************************************************
2255 * PeekMessageW (USER32.@)
2257 BOOL WINAPI PeekMessageW( MSG *msg_out, HWND hwnd, UINT first, UINT last, UINT flags )
2259 MESSAGEQUEUE *queue;
2263 /* check for graphics events */
2264 if (USER_Driver.pMsgWaitForMultipleObjectsEx)
2265 USER_Driver.pMsgWaitForMultipleObjectsEx( 0, NULL, 0, 0, 0 );
2267 hwnd = WIN_GetFullHandle( hwnd );
2268 locks = WIN_SuspendWndsLock();
2270 if (!MSG_peek_message( &msg, hwnd, first, last,
2271 (flags & PM_REMOVE) ? GET_MSG_REMOVE : 0 ))
2273 if (!(flags & PM_NOYIELD))
2276 ReleaseThunkLock(&count);
2277 if (count) RestoreThunkLock(count);
2279 WIN_RestoreWndsLock( locks );
2283 WIN_RestoreWndsLock( locks );
2285 if (msg.message == WM_PAINT) /* clear internal paint flag */
2286 RedrawWindow( msg.hwnd, NULL, 0, RDW_NOINTERNALPAINT | RDW_NOCHILDREN );
2288 if ((queue = QUEUE_Current()))
2290 queue->GetMessageTimeVal = msg.time;
2291 msg.pt.x = LOWORD( queue->GetMessagePosVal );
2292 msg.pt.y = HIWORD( queue->GetMessagePosVal );
2295 HOOK_CallHooks( WH_GETMESSAGE, HC_ACTION, flags & PM_REMOVE, (LPARAM)&msg, TRUE );
2297 /* copy back our internal safe copy of message data to msg_out.
2298 * msg_out is a variable from the *program*, so it can't be used
2299 * internally as it can get "corrupted" by our use of SendMessage()
2300 * (back to the program) inside the message handling itself. */
2303 SetLastError( ERROR_NOACCESS );
2311 /***********************************************************************
2312 * PeekMessageA (USER32.@)
2314 BOOL WINAPI PeekMessageA( MSG *msg, HWND hwnd, UINT first, UINT last, UINT flags )
2316 BOOL ret = PeekMessageW( msg, hwnd, first, last, flags );
2317 if (ret) msg->wParam = map_wparam_WtoA( msg->message, msg->wParam );
2322 /***********************************************************************
2323 * GetMessageW (USER32.@)
2325 BOOL WINAPI GetMessageW( MSG *msg, HWND hwnd, UINT first, UINT last )
2327 MESSAGEQUEUE *queue = QUEUE_Current();
2330 mask = QS_POSTMESSAGE | QS_SENDMESSAGE; /* Always selected */
2333 if ((first <= WM_KEYLAST) && (last >= WM_KEYFIRST)) mask |= QS_KEY;
2334 if ( ((first <= WM_MOUSELAST) && (last >= WM_MOUSEFIRST)) ||
2335 ((first <= WM_NCMOUSELAST) && (last >= WM_NCMOUSEFIRST)) ) mask |= QS_MOUSE;
2336 if ((first <= WM_TIMER) && (last >= WM_TIMER)) mask |= QS_TIMER;
2337 if ((first <= WM_SYSTIMER) && (last >= WM_SYSTIMER)) mask |= QS_TIMER;
2338 if ((first <= WM_PAINT) && (last >= WM_PAINT)) mask |= QS_PAINT;
2340 else mask |= QS_MOUSE | QS_KEY | QS_TIMER | QS_PAINT;
2342 locks = WIN_SuspendWndsLock();
2344 while (!PeekMessageW( msg, hwnd, first, last, PM_REMOVE ))
2346 /* wait until one of the bits is set */
2347 unsigned int wake_bits = 0, changed_bits = 0;
2350 SERVER_START_REQ( set_queue_mask )
2352 req->wake_mask = QS_SENDMESSAGE;
2353 req->changed_mask = mask;
2355 if (!wine_server_call( req ))
2357 wake_bits = reply->wake_bits;
2358 changed_bits = reply->changed_bits;
2363 if (changed_bits & mask) continue;
2364 if (wake_bits & QS_SENDMESSAGE) continue;
2366 TRACE( "(%04x) mask=%08x, bits=%08x, changed=%08x, waiting\n",
2367 queue->self, mask, wake_bits, changed_bits );
2369 ReleaseThunkLock( &dwlc );
2370 if (USER_Driver.pMsgWaitForMultipleObjectsEx)
2371 USER_Driver.pMsgWaitForMultipleObjectsEx( 1, &queue->server_queue, INFINITE, 0, 0 );
2373 WaitForSingleObject( queue->server_queue, INFINITE );
2374 if (dwlc) RestoreThunkLock( dwlc );
2377 WIN_RestoreWndsLock( locks );
2379 return (msg->message != WM_QUIT);
2383 /***********************************************************************
2384 * GetMessageA (USER32.@)
2386 BOOL WINAPI GetMessageA( MSG *msg, HWND hwnd, UINT first, UINT last )
2388 GetMessageW( msg, hwnd, first, last );
2389 msg->wParam = map_wparam_WtoA( msg->message, msg->wParam );
2390 return (msg->message != WM_QUIT);
2394 /***********************************************************************
2395 * IsDialogMessage (USER32.@)
2396 * IsDialogMessageA (USER32.@)
2398 BOOL WINAPI IsDialogMessageA( HWND hwndDlg, LPMSG pmsg )
2401 msg.wParam = map_wparam_AtoW( msg.message, msg.wParam );
2402 return IsDialogMessageW( hwndDlg, &msg );
2406 /***********************************************************************
2407 * SetMessageQueue (USER32.@)
2409 BOOL WINAPI SetMessageQueue( INT size )
2411 /* now obsolete the message queue will be expanded dynamically as necessary */
2416 /***********************************************************************
2417 * MessageBeep (USER32.@)
2419 BOOL WINAPI MessageBeep( UINT i )
2422 SystemParametersInfoA( SPI_GETBEEP, 0, &active, FALSE );
2423 if (active && USER_Driver.pBeep) USER_Driver.pBeep();
2428 /***********************************************************************
2429 * SetTimer (USER32.@)
2431 UINT_PTR WINAPI SetTimer( HWND hwnd, UINT_PTR id, UINT timeout, TIMERPROC proc )
2434 WNDPROC winproc = 0;
2436 if (proc) winproc = WINPROC_AllocProc( (WNDPROC)proc, WIN_PROC_32A );
2438 SERVER_START_REQ( set_win_timer )
2441 req->msg = WM_TIMER;
2443 req->rate = max( timeout, SYS_TIMER_RATE );
2444 req->lparam = (unsigned int)winproc;
2445 if (!wine_server_call_err( req ))
2448 if (!ret) ret = TRUE;
2454 TRACE("Added %p %x %p timeout %d\n", hwnd, id, winproc, timeout );
2459 /***********************************************************************
2460 * SetSystemTimer (USER32.@)
2462 UINT_PTR WINAPI SetSystemTimer( HWND hwnd, UINT_PTR id, UINT timeout, TIMERPROC proc )
2465 WNDPROC winproc = 0;
2467 if (proc) winproc = WINPROC_AllocProc( (WNDPROC)proc, WIN_PROC_32A );
2469 SERVER_START_REQ( set_win_timer )
2472 req->msg = WM_SYSTIMER;
2474 req->rate = max( timeout, SYS_TIMER_RATE );
2475 req->lparam = (unsigned int)winproc;
2476 if (!wine_server_call_err( req ))
2479 if (!ret) ret = TRUE;
2485 TRACE("Added %p %x %p timeout %d\n", hwnd, id, winproc, timeout );
2490 /***********************************************************************
2491 * KillTimer (USER32.@)
2493 BOOL WINAPI KillTimer( HWND hwnd, UINT_PTR id )
2497 TRACE("%p %d\n", hwnd, id );
2499 SERVER_START_REQ( kill_win_timer )
2502 req->msg = WM_TIMER;
2504 ret = !wine_server_call_err( req );
2511 /***********************************************************************
2512 * KillSystemTimer (USER32.@)
2514 BOOL WINAPI KillSystemTimer( HWND hwnd, UINT_PTR id )
2518 TRACE("%p %d\n", hwnd, id );
2520 SERVER_START_REQ( kill_win_timer )
2523 req->msg = WM_SYSTIMER;
2525 ret = !wine_server_call_err( req );
2532 /**********************************************************************
2533 * AttachThreadInput (USER32.@)
2535 * Attaches the input processing mechanism of one thread to that of
2538 BOOL WINAPI AttachThreadInput( DWORD from, DWORD to, BOOL attach )
2542 SERVER_START_REQ( attach_thread_input )
2544 req->tid_from = from;
2546 req->attach = attach;
2547 ret = !wine_server_call_err( req );
2554 /**********************************************************************
2555 * GetGUIThreadInfo (USER32.@)
2557 BOOL WINAPI GetGUIThreadInfo( DWORD id, GUITHREADINFO *info )
2561 SERVER_START_REQ( get_thread_input )
2564 if ((ret = !wine_server_call_err( req )))
2567 info->hwndActive = reply->active;
2568 info->hwndFocus = reply->focus;
2569 info->hwndCapture = reply->capture;
2570 info->hwndMenuOwner = reply->menu_owner;
2571 info->hwndMoveSize = reply->move_size;
2572 info->hwndCaret = reply->caret;
2573 info->rcCaret.left = reply->rect.left;
2574 info->rcCaret.top = reply->rect.top;
2575 info->rcCaret.right = reply->rect.right;
2576 info->rcCaret.bottom = reply->rect.bottom;
2577 if (reply->menu_owner) info->flags |= GUI_INMENUMODE;
2578 if (reply->move_size) info->flags |= GUI_INMOVESIZE;
2579 if (reply->caret) info->flags |= GUI_CARETBLINKING;
2587 /**********************************************************************
2588 * GetKeyState (USER32.@)
2590 * An application calls the GetKeyState function in response to a
2591 * keyboard-input message. This function retrieves the state of the key
2592 * at the time the input message was generated.
2594 SHORT WINAPI GetKeyState(INT vkey)
2598 SERVER_START_REQ( get_key_state )
2600 req->tid = GetCurrentThreadId();
2602 if (!wine_server_call( req )) retval = (signed char)reply->state;
2605 TRACE("key (0x%x) -> %x\n", vkey, retval);
2610 /**********************************************************************
2611 * GetKeyboardState (USER32.@)
2613 BOOL WINAPI GetKeyboardState( LPBYTE state )
2617 TRACE("(%p)\n", state);
2619 memset( state, 0, 256 );
2620 SERVER_START_REQ( get_key_state )
2622 req->tid = GetCurrentThreadId();
2624 wine_server_set_reply( req, state, 256 );
2625 ret = !wine_server_call_err( req );
2632 /**********************************************************************
2633 * SetKeyboardState (USER32.@)
2635 BOOL WINAPI SetKeyboardState( LPBYTE state )
2639 TRACE("(%p)\n", state);
2641 SERVER_START_REQ( set_key_state )
2643 req->tid = GetCurrentThreadId();
2644 wine_server_add_data( req, state, 256 );
2645 ret = !wine_server_call_err( req );
2651 /******************************************************************
2652 * IsHungAppWindow (USER32.@)
2655 BOOL WINAPI IsHungAppWindow( HWND hWnd )
2658 return !SendMessageTimeoutA(hWnd, WM_NULL, 0, 0, SMTO_ABORTIFHUNG, 5000, &dwResult);
2661 /******************************************************************
2662 * GetLastInputInfo (USER32.@)
2664 BOOL WINAPI GetLastInputInfo(PLASTINPUTINFO plii)
2666 FIXME("%p\n", plii);