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"
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 /* description of the data fields that need to be packed along with a sent message */
55 const void *data[MAX_PACK_COUNT];
56 size_t size[MAX_PACK_COUNT];
59 /* info about the message currently being received by the current thread */
60 struct received_message_info
62 enum message_type type;
64 UINT flags; /* InSendMessageEx return flags */
67 /* structure to group all parameters for sent messages of the various kinds */
68 struct send_message_info
70 enum message_type type;
75 UINT flags; /* flags for SendMessageTimeout */
76 UINT timeout; /* timeout for SendMessageTimeout */
77 SENDASYNCPROC callback; /* callback function for SendMessageCallback */
78 ULONG_PTR data; /* callback data */
82 /* flag for messages that contain pointers */
83 /* 32 messages per entry, messages 0..31 map to bits 0..31 */
85 #define SET(msg) (1 << ((msg) & 31))
87 static const unsigned int message_pointer_flags[] =
90 SET(WM_CREATE) | SET(WM_SETTEXT) | SET(WM_GETTEXT) |
91 SET(WM_WININICHANGE) | SET(WM_DEVMODECHANGE),
93 SET(WM_GETMINMAXINFO) | SET(WM_DRAWITEM) | SET(WM_MEASUREITEM) | SET(WM_DELETEITEM) |
96 SET(WM_WINDOWPOSCHANGING) | SET(WM_WINDOWPOSCHANGED) | SET(WM_COPYDATA) |
97 SET(WM_NOTIFY) | SET(WM_HELP),
99 SET(WM_STYLECHANGING) | SET(WM_STYLECHANGED),
101 SET(WM_NCCREATE) | SET(WM_NCCALCSIZE) | SET(WM_GETDLGCODE),
103 SET(EM_GETSEL) | SET(EM_GETRECT) | SET(EM_SETRECT) | SET(EM_SETRECTNP),
105 SET(EM_REPLACESEL) | SET(EM_GETLINE) | SET(EM_SETTABSTOPS),
107 SET(SBM_GETRANGE) | SET(SBM_SETSCROLLINFO) | SET(SBM_GETSCROLLINFO),
113 SET(CB_GETEDITSEL) | SET(CB_ADDSTRING) | SET(CB_DIR) | SET(CB_GETLBTEXT) |
114 SET(CB_INSERTSTRING) | SET(CB_FINDSTRING) | SET(CB_SELECTSTRING) |
115 SET(CB_GETDROPPEDCONTROLRECT) | SET(CB_FINDSTRINGEXACT),
119 SET(LB_ADDSTRING) | SET(LB_INSERTSTRING) | SET(LB_GETTEXT) | SET(LB_SELECTSTRING) |
120 SET(LB_DIR) | SET(LB_FINDSTRING) |
121 SET(LB_GETSELITEMS) | SET(LB_SETTABSTOPS) | SET(LB_ADDFILE) | SET(LB_GETITEMRECT),
123 SET(LB_FINDSTRINGEXACT),
129 SET(WM_NEXTMENU) | SET(WM_SIZING) | SET(WM_MOVING) | SET(WM_DEVICECHANGE),
131 SET(WM_MDICREATE) | SET(WM_MDIGETACTIVE) | SET(WM_DROPOBJECT) |
132 SET(WM_QUERYDROPOBJECT) | SET(WM_DRAGLOOP) | SET(WM_DRAGSELECT) | SET(WM_DRAGMOVE),
146 SET(WM_ASKCBFORMATNAME)
149 /* flags for messages that contain Unicode strings */
150 static const unsigned int message_unicode_flags[] =
153 SET(WM_CREATE) | SET(WM_SETTEXT) | SET(WM_GETTEXT) | SET(WM_GETTEXTLENGTH) |
154 SET(WM_WININICHANGE) | SET(WM_DEVMODECHANGE),
166 SET(EM_REPLACESEL) | SET(EM_GETLINE) | SET(EM_SETPASSWORDCHAR),
170 SET(WM_CHAR) | SET(WM_DEADCHAR) | SET(WM_SYSCHAR) | SET(WM_SYSDEADCHAR),
174 SET(CB_ADDSTRING) | SET(CB_DIR) | SET(CB_GETLBTEXT) | SET(CB_GETLBTEXTLEN) |
175 SET(CB_INSERTSTRING) | SET(CB_FINDSTRING) | SET(CB_SELECTSTRING) | SET(CB_FINDSTRINGEXACT),
179 SET(LB_ADDSTRING) | SET(LB_INSERTSTRING) | SET(LB_GETTEXT) | SET(LB_GETTEXTLEN) |
180 SET(LB_SELECTSTRING) | SET(LB_DIR) | SET(LB_FINDSTRING) | SET(LB_ADDFILE),
182 SET(LB_FINDSTRINGEXACT),
204 SET(WM_PAINTCLIPBOARD) | SET(WM_SIZECLIPBOARD) | SET(WM_ASKCBFORMATNAME)
207 /* check whether a given message type includes pointers */
208 inline static int is_pointer_message( UINT message )
210 if (message >= 8*sizeof(message_pointer_flags)) return FALSE;
211 return (message_pointer_flags[message / 32] & SET(message)) != 0;
214 /* check whether a given message type contains Unicode (or ASCII) chars */
215 inline static int is_unicode_message( UINT message )
217 if (message >= 8*sizeof(message_unicode_flags)) return FALSE;
218 return (message_unicode_flags[message / 32] & SET(message)) != 0;
223 /* add a data field to a packed message */
224 inline static void push_data( struct packed_message *data, const void *ptr, size_t size )
226 data->data[data->count] = ptr;
227 data->size[data->count] = size;
231 /* add a string to a packed message */
232 inline static void push_string( struct packed_message *data, LPCWSTR str )
234 push_data( data, str, (strlenW(str) + 1) * sizeof(WCHAR) );
237 /* retrieve a pointer to data from a packed message and increment the buffer pointer */
238 inline static void *get_data( void **buffer, size_t size )
241 *buffer = (char *)*buffer + size;
245 /* make sure that the buffer contains a valid null-terminated Unicode string */
246 inline static BOOL check_string( LPCWSTR str, size_t size )
248 for (size /= sizeof(WCHAR); size; size--, str++)
249 if (!*str) return TRUE;
253 /* make sure that there is space for 'size' bytes in buffer, growing it if needed */
254 inline static void *get_buffer_space( void **buffer, size_t size )
260 if (!(ret = HeapReAlloc( GetProcessHeap(), 0, *buffer, size )))
261 HeapFree( GetProcessHeap(), 0, *buffer );
263 else ret = HeapAlloc( GetProcessHeap(), 0, size );
269 /* retrieve a string pointer from packed data */
270 inline static LPWSTR get_string( void **buffer )
272 return get_data( buffer, (strlenW( (LPWSTR)*buffer ) + 1) * sizeof(WCHAR) );
275 /* check whether a combobox expects strings or ids in CB_ADDSTRING/CB_INSERTSTRING */
276 inline static BOOL combobox_has_strings( HWND hwnd )
278 DWORD style = GetWindowLongA( hwnd, GWL_STYLE );
279 return (!(style & (CBS_OWNERDRAWFIXED | CBS_OWNERDRAWVARIABLE)) || (style & CBS_HASSTRINGS));
282 /* check whether a listbox expects strings or ids in LB_ADDSTRING/LB_INSERTSTRING */
283 inline static BOOL listbox_has_strings( HWND hwnd )
285 DWORD style = GetWindowLongA( hwnd, GWL_STYLE );
286 return (!(style & (LBS_OWNERDRAWFIXED | LBS_OWNERDRAWVARIABLE)) || (style & LBS_HASSTRINGS));
290 /***********************************************************************
291 * broadcast_message_callback
293 * Helper callback for broadcasting messages.
295 static BOOL CALLBACK broadcast_message_callback( HWND hwnd, LPARAM lparam )
297 struct send_message_info *info = (struct send_message_info *)lparam;
298 if (!(GetWindowLongW( hwnd, GWL_STYLE ) & (WS_POPUP|WS_CAPTION))) return TRUE;
302 SendMessageTimeoutW( hwnd, info->msg, info->wparam, info->lparam,
303 info->flags, info->timeout, NULL );
306 SendMessageTimeoutA( hwnd, info->msg, info->wparam, info->lparam,
307 info->flags, info->timeout, NULL );
310 SendNotifyMessageW( hwnd, info->msg, info->wparam, info->lparam );
313 SendMessageCallbackW( hwnd, info->msg, info->wparam, info->lparam,
314 info->callback, info->data );
317 PostMessageW( hwnd, info->msg, info->wparam, info->lparam );
320 ERR( "bad type %d\n", info->type );
327 /***********************************************************************
330 * Convert the wparam of an ASCII message to Unicode.
332 static WPARAM map_wparam_AtoW( UINT message, WPARAM wparam )
337 case EM_SETPASSWORDCHAR:
344 char ch = LOWORD(wparam);
346 MultiByteToWideChar(CP_ACP, 0, &ch, 1, &wch, 1);
347 wparam = MAKEWPARAM( wch, HIWORD(wparam) );
354 ch[0] = (wparam >> 8);
355 ch[1] = (wparam & 0xff);
356 if (ch[0]) MultiByteToWideChar(CP_ACP, 0, ch, 2, &wch, 1);
357 else MultiByteToWideChar(CP_ACP, 0, &ch[1], 1, &wch, 1);
358 wparam = MAKEWPARAM( wch, HIWORD(wparam) );
366 /***********************************************************************
369 * Convert the wparam of a Unicode message to ASCII.
371 static WPARAM map_wparam_WtoA( UINT message, WPARAM wparam )
376 case EM_SETPASSWORDCHAR:
383 WCHAR wch = LOWORD(wparam);
385 WideCharToMultiByte( CP_ACP, 0, &wch, 1, &ch, 1, NULL, NULL );
386 wparam = MAKEWPARAM( ch, HIWORD(wparam) );
391 WCHAR wch = LOWORD(wparam);
394 if (WideCharToMultiByte( CP_ACP, 0, &wch, 1, ch, 2, NULL, NULL ) == 2)
395 wparam = MAKEWPARAM( (ch[0] << 8) | ch[1], HIWORD(wparam) );
397 wparam = MAKEWPARAM( ch[0], HIWORD(wparam) );
405 /***********************************************************************
408 * Pack a message for sending to another process.
409 * Return the size of the data we expect in the message reply.
410 * Set data->count to -1 if there is an error.
412 static size_t pack_message( HWND hwnd, UINT message, WPARAM wparam, LPARAM lparam,
413 struct packed_message *data )
421 CREATESTRUCTW *cs = (CREATESTRUCTW *)lparam;
422 push_data( data, cs, sizeof(*cs) );
423 if (HIWORD(cs->lpszName)) push_string( data, cs->lpszName );
424 if (HIWORD(cs->lpszClass)) push_string( data, cs->lpszClass );
428 case WM_ASKCBFORMATNAME:
429 return wparam * sizeof(WCHAR);
430 case WM_WININICHANGE:
431 if (lparam) push_string(data, (LPWSTR)lparam );
434 case WM_DEVMODECHANGE:
439 push_string( data, (LPWSTR)lparam );
441 case WM_GETMINMAXINFO:
442 push_data( data, (MINMAXINFO *)lparam, sizeof(MINMAXINFO) );
443 return sizeof(MINMAXINFO);
445 push_data( data, (DRAWITEMSTRUCT *)lparam, sizeof(DRAWITEMSTRUCT) );
448 push_data( data, (MEASUREITEMSTRUCT *)lparam, sizeof(MEASUREITEMSTRUCT) );
449 return sizeof(MEASUREITEMSTRUCT);
451 push_data( data, (DELETEITEMSTRUCT *)lparam, sizeof(DELETEITEMSTRUCT) );
454 push_data( data, (COMPAREITEMSTRUCT *)lparam, sizeof(COMPAREITEMSTRUCT) );
456 case WM_WINDOWPOSCHANGING:
457 case WM_WINDOWPOSCHANGED:
458 push_data( data, (WINDOWPOS *)lparam, sizeof(WINDOWPOS) );
459 return sizeof(WINDOWPOS);
462 COPYDATASTRUCT *cp = (COPYDATASTRUCT *)lparam;
463 push_data( data, cp, sizeof(*cp) );
464 if (cp->lpData) push_data( data, cp->lpData, cp->cbData );
468 /* WM_NOTIFY cannot be sent across processes (MSDN) */
472 push_data( data, (HELPINFO *)lparam, sizeof(HELPINFO) );
474 case WM_STYLECHANGING:
475 case WM_STYLECHANGED:
476 push_data( data, (STYLESTRUCT *)lparam, sizeof(STYLESTRUCT) );
481 push_data( data, (RECT *)lparam, sizeof(RECT) );
486 NCCALCSIZE_PARAMS *nc = (NCCALCSIZE_PARAMS *)lparam;
487 push_data( data, nc, sizeof(*nc) );
488 push_data( data, nc->lppos, sizeof(*nc->lppos) );
489 return sizeof(*nc) + sizeof(*nc->lppos);
492 if (lparam) push_data( data, (MSG *)lparam, sizeof(MSG) );
494 case SBM_SETSCROLLINFO:
495 push_data( data, (SCROLLINFO *)lparam, sizeof(SCROLLINFO) );
497 case SBM_GETSCROLLINFO:
498 push_data( data, (SCROLLINFO *)lparam, sizeof(SCROLLINFO) );
499 return sizeof(SCROLLINFO);
505 if (wparam) size += sizeof(DWORD);
506 if (lparam) size += sizeof(DWORD);
511 case CB_GETDROPPEDCONTROLRECT:
515 push_data( data, (RECT *)lparam, sizeof(RECT) );
519 WORD *pw = (WORD *)lparam;
520 push_data( data, pw, sizeof(*pw) );
521 return *pw * sizeof(WCHAR);
525 if (wparam) push_data( data, (UINT *)lparam, sizeof(UINT) * wparam );
528 case CB_INSERTSTRING:
530 case CB_FINDSTRINGEXACT:
531 case CB_SELECTSTRING:
532 if (combobox_has_strings( hwnd )) push_string( data, (LPWSTR)lparam );
535 if (!combobox_has_strings( hwnd )) return sizeof(ULONG_PTR);
536 return (SendMessageW( hwnd, CB_GETLBTEXTLEN, wparam, 0 ) + 1) * sizeof(WCHAR);
538 case LB_INSERTSTRING:
540 case LB_FINDSTRINGEXACT:
541 case LB_SELECTSTRING:
542 if (listbox_has_strings( hwnd )) push_string( data, (LPWSTR)lparam );
545 if (!listbox_has_strings( hwnd )) return sizeof(ULONG_PTR);
546 return (SendMessageW( hwnd, LB_GETTEXTLEN, wparam, 0 ) + 1) * sizeof(WCHAR);
548 return wparam * sizeof(UINT);
550 push_data( data, (MDINEXTMENU *)lparam, sizeof(MDINEXTMENU) );
551 return sizeof(MDINEXTMENU);
554 push_data( data, (RECT *)lparam, sizeof(RECT) );
558 MDICREATESTRUCTW *cs = (MDICREATESTRUCTW *)lparam;
559 push_data( data, cs, sizeof(*cs) );
560 if (HIWORD(cs->szTitle)) push_string( data, cs->szTitle );
561 if (HIWORD(cs->szClass)) push_string( data, cs->szClass );
564 case WM_MDIGETACTIVE:
565 if (lparam) return sizeof(BOOL);
567 case WM_WINE_SETWINDOWPOS:
568 push_data( data, (WINDOWPOS *)lparam, sizeof(WINDOWPOS) );
570 case WM_WINE_KEYBOARD_LL_HOOK:
571 push_data( data, (KBDLLHOOKSTRUCT *)lparam, sizeof(KBDLLHOOKSTRUCT) );
573 case WM_WINE_MOUSE_LL_HOOK:
574 push_data( data, (MSLLHOOKSTRUCT *)lparam, sizeof(MSLLHOOKSTRUCT) );
577 /* these contain an HFONT */
580 /* these contain an HDC */
583 case WM_ICONERASEBKGND:
585 case WM_CTLCOLORMSGBOX:
586 case WM_CTLCOLOREDIT:
587 case WM_CTLCOLORLISTBOX:
590 case WM_CTLCOLORSCROLLBAR:
591 case WM_CTLCOLORSTATIC:
594 /* these contain an HGLOBAL */
595 case WM_PAINTCLIPBOARD:
596 case WM_SIZECLIPBOARD:
597 /* these contain HICON */
600 case WM_QUERYDRAGICON:
601 case WM_QUERYPARKICON:
602 /* these contain pointers */
604 case WM_QUERYDROPOBJECT:
608 case WM_DEVICECHANGE:
609 FIXME( "msg %x (%s) not supported yet\n", message, SPY_GetMsgName(message, hwnd) );
617 /***********************************************************************
620 * Unpack a message received from another process.
622 static BOOL unpack_message( HWND hwnd, UINT message, WPARAM *wparam, LPARAM *lparam,
623 void **buffer, size_t size )
632 CREATESTRUCTW *cs = *buffer;
633 WCHAR *str = (WCHAR *)(cs + 1);
634 if (size < sizeof(*cs)) return FALSE;
636 if (HIWORD(cs->lpszName))
638 if (!check_string( str, size )) return FALSE;
640 size -= (strlenW(str) + 1) * sizeof(WCHAR);
641 str += strlenW(str) + 1;
643 if (HIWORD(cs->lpszClass))
645 if (!check_string( str, size )) return FALSE;
651 case WM_ASKCBFORMATNAME:
652 if (!get_buffer_space( buffer, (*wparam * sizeof(WCHAR)) )) return FALSE;
654 case WM_WININICHANGE:
655 if (!*lparam) return TRUE;
658 case WM_DEVMODECHANGE:
663 if (!check_string( *buffer, size )) return FALSE;
665 case WM_GETMINMAXINFO:
666 minsize = sizeof(MINMAXINFO);
669 minsize = sizeof(DRAWITEMSTRUCT);
672 minsize = sizeof(MEASUREITEMSTRUCT);
675 minsize = sizeof(DELETEITEMSTRUCT);
678 minsize = sizeof(COMPAREITEMSTRUCT);
680 case WM_WINDOWPOSCHANGING:
681 case WM_WINDOWPOSCHANGED:
682 case WM_WINE_SETWINDOWPOS:
683 minsize = sizeof(WINDOWPOS);
687 COPYDATASTRUCT *cp = *buffer;
688 if (size < sizeof(*cp)) return FALSE;
691 minsize = sizeof(*cp) + cp->cbData;
697 /* WM_NOTIFY cannot be sent across processes (MSDN) */
700 minsize = sizeof(HELPINFO);
702 case WM_STYLECHANGING:
703 case WM_STYLECHANGED:
704 minsize = sizeof(STYLESTRUCT);
707 if (!*wparam) minsize = sizeof(RECT);
710 NCCALCSIZE_PARAMS *nc = *buffer;
711 if (size < sizeof(*nc) + sizeof(*nc->lppos)) return FALSE;
712 nc->lppos = (WINDOWPOS *)(nc + 1);
716 if (!*lparam) return TRUE;
717 minsize = sizeof(MSG);
719 case SBM_SETSCROLLINFO:
720 minsize = sizeof(SCROLLINFO);
722 case SBM_GETSCROLLINFO:
723 if (!get_buffer_space( buffer, sizeof(SCROLLINFO ))) return FALSE;
728 if (*wparam || *lparam)
730 if (!get_buffer_space( buffer, 2*sizeof(DWORD) )) return FALSE;
731 if (*wparam) *wparam = (WPARAM)*buffer;
732 if (*lparam) *lparam = (LPARAM)((DWORD *)*buffer + 1);
737 case CB_GETDROPPEDCONTROLRECT:
738 if (!get_buffer_space( buffer, sizeof(RECT) )) return FALSE;
742 minsize = sizeof(RECT);
747 if (size < sizeof(WORD)) return FALSE;
748 len = *(WORD *)*buffer;
749 if (!get_buffer_space( buffer, (len + 1) * sizeof(WCHAR) )) return FALSE;
750 *lparam = (LPARAM)*buffer + sizeof(WORD); /* don't erase WORD at start of buffer */
755 if (!*wparam) return TRUE;
756 minsize = *wparam * sizeof(UINT);
759 case CB_INSERTSTRING:
761 case CB_FINDSTRINGEXACT:
762 case CB_SELECTSTRING:
764 case LB_INSERTSTRING:
766 case LB_FINDSTRINGEXACT:
767 case LB_SELECTSTRING:
768 if (!*buffer) return TRUE;
769 if (!check_string( *buffer, size )) return FALSE;
773 size = sizeof(ULONG_PTR);
774 if (combobox_has_strings( hwnd ))
775 size = (SendMessageW( hwnd, CB_GETLBTEXTLEN, *wparam, 0 ) + 1) * sizeof(WCHAR);
776 if (!get_buffer_space( buffer, size )) return FALSE;
781 size = sizeof(ULONG_PTR);
782 if (listbox_has_strings( hwnd ))
783 size = (SendMessageW( hwnd, LB_GETTEXTLEN, *wparam, 0 ) + 1) * sizeof(WCHAR);
784 if (!get_buffer_space( buffer, size )) return FALSE;
788 if (!get_buffer_space( buffer, *wparam * sizeof(UINT) )) return FALSE;
791 minsize = sizeof(MDINEXTMENU);
792 if (!get_buffer_space( buffer, sizeof(MDINEXTMENU) )) return FALSE;
796 minsize = sizeof(RECT);
797 if (!get_buffer_space( buffer, sizeof(RECT) )) return FALSE;
801 MDICREATESTRUCTW *cs = *buffer;
802 WCHAR *str = (WCHAR *)(cs + 1);
803 if (size < sizeof(*cs)) return FALSE;
805 if (HIWORD(cs->szTitle))
807 if (!check_string( str, size )) return FALSE;
809 size -= (strlenW(str) + 1) * sizeof(WCHAR);
810 str += strlenW(str) + 1;
812 if (HIWORD(cs->szClass))
814 if (!check_string( str, size )) return FALSE;
819 case WM_MDIGETACTIVE:
820 if (!*lparam) return TRUE;
821 if (!get_buffer_space( buffer, sizeof(BOOL) )) return FALSE;
823 case WM_WINE_KEYBOARD_LL_HOOK:
824 minsize = sizeof(KBDLLHOOKSTRUCT);
826 case WM_WINE_MOUSE_LL_HOOK:
827 minsize = sizeof(MSLLHOOKSTRUCT);
830 /* these contain an HFONT */
833 /* these contain an HDC */
836 case WM_ICONERASEBKGND:
838 case WM_CTLCOLORMSGBOX:
839 case WM_CTLCOLOREDIT:
840 case WM_CTLCOLORLISTBOX:
843 case WM_CTLCOLORSCROLLBAR:
844 case WM_CTLCOLORSTATIC:
847 /* these contain an HGLOBAL */
848 case WM_PAINTCLIPBOARD:
849 case WM_SIZECLIPBOARD:
850 /* these contain HICON */
853 case WM_QUERYDRAGICON:
854 case WM_QUERYPARKICON:
855 /* these contain pointers */
857 case WM_QUERYDROPOBJECT:
861 case WM_DEVICECHANGE:
862 FIXME( "msg %x (%s) not supported yet\n", message, SPY_GetMsgName(message, hwnd) );
866 return TRUE; /* message doesn't need any unpacking */
869 /* default exit for most messages: check minsize and store buffer in lparam */
870 if (size < minsize) return FALSE;
871 *lparam = (LPARAM)*buffer;
876 /***********************************************************************
879 * Pack a reply to a message for sending to another process.
881 static void pack_reply( HWND hwnd, UINT message, WPARAM wparam, LPARAM lparam,
882 LRESULT res, struct packed_message *data )
889 push_data( data, (CREATESTRUCTW *)lparam, sizeof(CREATESTRUCTW) );
894 push_data( data, (WCHAR *)lparam, (res + 1) * sizeof(WCHAR) );
896 case WM_GETMINMAXINFO:
897 push_data( data, (MINMAXINFO *)lparam, sizeof(MINMAXINFO) );
900 push_data( data, (MEASUREITEMSTRUCT *)lparam, sizeof(MEASUREITEMSTRUCT) );
902 case WM_WINDOWPOSCHANGING:
903 case WM_WINDOWPOSCHANGED:
904 push_data( data, (WINDOWPOS *)lparam, sizeof(WINDOWPOS) );
907 if (lparam) push_data( data, (MSG *)lparam, sizeof(MSG) );
909 case SBM_GETSCROLLINFO:
910 push_data( data, (SCROLLINFO *)lparam, sizeof(SCROLLINFO) );
914 case CB_GETDROPPEDCONTROLRECT:
917 push_data( data, (RECT *)lparam, sizeof(RECT) );
921 WORD *ptr = (WORD *)lparam;
922 push_data( data, ptr, ptr[-1] * sizeof(WCHAR) );
926 push_data( data, (UINT *)lparam, wparam * sizeof(UINT) );
928 case WM_MDIGETACTIVE:
929 if (lparam) push_data( data, (BOOL *)lparam, sizeof(BOOL) );
933 push_data( data, (RECT *)lparam, sizeof(RECT) );
936 NCCALCSIZE_PARAMS *nc = (NCCALCSIZE_PARAMS *)lparam;
937 push_data( data, nc, sizeof(*nc) );
938 push_data( data, nc->lppos, sizeof(*nc->lppos) );
944 if (wparam) push_data( data, (DWORD *)wparam, sizeof(DWORD) );
945 if (lparam) push_data( data, (DWORD *)lparam, sizeof(DWORD) );
948 push_data( data, (MDINEXTMENU *)lparam, sizeof(MDINEXTMENU) );
951 push_data( data, (MDICREATESTRUCTW *)lparam, sizeof(MDICREATESTRUCTW) );
953 case WM_ASKCBFORMATNAME:
954 push_data( data, (WCHAR *)lparam, (strlenW((WCHAR *)lparam) + 1) * sizeof(WCHAR) );
960 /***********************************************************************
963 * Unpack a message reply received from another process.
965 static void unpack_reply( HWND hwnd, UINT message, WPARAM wparam, LPARAM lparam,
966 void *buffer, size_t size )
973 CREATESTRUCTW *cs = (CREATESTRUCTW *)lparam;
974 LPCWSTR name = cs->lpszName, class = cs->lpszClass;
975 memcpy( cs, buffer, min( sizeof(*cs), size ));
976 cs->lpszName = name; /* restore the original pointers */
977 cs->lpszClass = class;
981 case WM_ASKCBFORMATNAME:
982 memcpy( (WCHAR *)lparam, buffer, min( wparam*sizeof(WCHAR), size ));
984 case WM_GETMINMAXINFO:
985 memcpy( (MINMAXINFO *)lparam, buffer, min( sizeof(MINMAXINFO), size ));
988 memcpy( (MEASUREITEMSTRUCT *)lparam, buffer, min( sizeof(MEASUREITEMSTRUCT), size ));
990 case WM_WINDOWPOSCHANGING:
991 case WM_WINDOWPOSCHANGED:
992 memcpy( (WINDOWPOS *)lparam, buffer, min( sizeof(WINDOWPOS), size ));
995 if (lparam) memcpy( (MSG *)lparam, buffer, min( sizeof(MSG), size ));
997 case SBM_GETSCROLLINFO:
998 memcpy( (SCROLLINFO *)lparam, buffer, min( sizeof(SCROLLINFO), size ));
1001 case CB_GETDROPPEDCONTROLRECT:
1002 case LB_GETITEMRECT:
1005 memcpy( (RECT *)lparam, buffer, min( sizeof(RECT), size ));
1008 size = min( size, (size_t)*(WORD *)lparam );
1009 memcpy( (WCHAR *)lparam, buffer, size );
1011 case LB_GETSELITEMS:
1012 memcpy( (UINT *)lparam, buffer, min( wparam*sizeof(UINT), size ));
1016 memcpy( (WCHAR *)lparam, buffer, size );
1019 memcpy( (MDINEXTMENU *)lparam, buffer, min( sizeof(MDINEXTMENU), size ));
1021 case WM_MDIGETACTIVE:
1022 if (lparam) memcpy( (BOOL *)lparam, buffer, min( sizeof(BOOL), size ));
1026 memcpy( (RECT *)lparam, buffer, min( sizeof(RECT), size ));
1029 NCCALCSIZE_PARAMS *nc = (NCCALCSIZE_PARAMS *)lparam;
1030 WINDOWPOS *wp = nc->lppos;
1031 memcpy( nc, buffer, min( sizeof(*nc), size ));
1032 if (size > sizeof(*nc))
1034 size -= sizeof(*nc);
1035 memcpy( wp, (NCCALCSIZE_PARAMS*)buffer + 1, min( sizeof(*wp), size ));
1037 nc->lppos = wp; /* restore the original pointer */
1045 memcpy( (DWORD *)wparam, buffer, min( sizeof(DWORD), size ));
1046 if (size <= sizeof(DWORD)) break;
1047 size -= sizeof(DWORD);
1048 buffer = (DWORD *)buffer + 1;
1050 if (lparam) memcpy( (DWORD *)lparam, buffer, min( sizeof(DWORD), size ));
1054 MDICREATESTRUCTW *cs = (MDICREATESTRUCTW *)lparam;
1055 LPCWSTR title = cs->szTitle, class = cs->szClass;
1056 memcpy( cs, buffer, min( sizeof(*cs), size ));
1057 cs->szTitle = title; /* restore the original pointers */
1058 cs->szClass = class;
1062 ERR( "should not happen: unexpected message %x\n", message );
1068 /***********************************************************************
1071 * Send a reply to a sent message.
1073 static void reply_message( struct received_message_info *info, LRESULT result, BOOL remove )
1075 struct packed_message data;
1076 int i, replied = info->flags & ISMEX_REPLIED;
1078 if (info->flags & ISMEX_NOTIFY) return; /* notify messages don't get replies */
1079 if (!remove && replied) return; /* replied already */
1082 info->flags |= ISMEX_REPLIED;
1084 if (info->type == MSG_OTHER_PROCESS && !replied)
1086 pack_reply( info->msg.hwnd, info->msg.message, info->msg.wParam,
1087 info->msg.lParam, result, &data );
1090 SERVER_START_REQ( reply_message )
1092 req->type = info->type;
1093 req->result = result;
1094 req->remove = remove;
1095 for (i = 0; i < data.count; i++) wine_server_add_data( req, data.data[i], data.size[i] );
1096 wine_server_call( req );
1102 /***********************************************************************
1103 * handle_internal_message
1105 * Handle an internal Wine message instead of calling the window proc.
1107 static LRESULT handle_internal_message( HWND hwnd, UINT msg, WPARAM wparam, LPARAM lparam )
1109 if (hwnd == GetDesktopWindow()) return 0;
1112 case WM_WINE_DESTROYWINDOW:
1113 return WIN_DestroyWindow( hwnd );
1114 case WM_WINE_SETWINDOWPOS:
1115 return USER_Driver.pSetWindowPos( (WINDOWPOS *)lparam );
1116 case WM_WINE_SHOWWINDOW:
1117 return ShowWindow( hwnd, wparam );
1118 case WM_WINE_SETPARENT:
1119 return (LRESULT)SetParent( hwnd, (HWND)wparam );
1120 case WM_WINE_SETWINDOWLONG:
1121 return (LRESULT)SetWindowLongW( hwnd, wparam, lparam );
1122 case WM_WINE_ENABLEWINDOW:
1123 return EnableWindow( hwnd, wparam );
1124 case WM_WINE_SETACTIVEWINDOW:
1125 return (LRESULT)SetActiveWindow( (HWND)wparam );
1126 case WM_WINE_KEYBOARD_LL_HOOK:
1127 return HOOK_CallHooks( WH_KEYBOARD_LL, HC_ACTION, wparam, lparam, TRUE );
1128 case WM_WINE_MOUSE_LL_HOOK:
1129 return HOOK_CallHooks( WH_MOUSE_LL, HC_ACTION, wparam, lparam, TRUE );
1131 FIXME( "unknown internal message %x\n", msg );
1136 /* since the WM_DDE_ACK response to a WM_DDE_EXECUTE message should contain the handle
1137 * to the memory handle, we keep track (in the server side) of all pairs of handle
1138 * used (the client passes its value and the content of the memory handle), and
1139 * the server stored both values (the client, and the local one, created after the
1140 * content). When a ACK message is generated, the list of pair is searched for a
1141 * matching pair, so that the client memory handle can be returned.
1144 HGLOBAL client_hMem;
1145 HGLOBAL server_hMem;
1148 static struct DDE_pair* dde_pairs;
1149 static int dde_num_alloc;
1150 static int dde_num_used;
1152 static CRITICAL_SECTION dde_crst;
1153 static CRITICAL_SECTION_DEBUG critsect_debug =
1156 { &critsect_debug.ProcessLocksList, &critsect_debug.ProcessLocksList },
1157 0, 0, { 0, (DWORD)(__FILE__ ": dde_crst") }
1159 static CRITICAL_SECTION dde_crst = { &critsect_debug, -1, 0, 0, 0, 0 };
1161 static BOOL dde_add_pair(HGLOBAL chm, HGLOBAL shm)
1166 EnterCriticalSection(&dde_crst);
1168 /* now remember the pair of hMem on both sides */
1169 if (dde_num_used == dde_num_alloc)
1171 struct DDE_pair* tmp;
1173 tmp = HeapReAlloc( GetProcessHeap(), 0, dde_pairs,
1174 (dde_num_alloc + GROWBY) * sizeof(struct DDE_pair));
1176 tmp = HeapAlloc( GetProcessHeap(), 0,
1177 (dde_num_alloc + GROWBY) * sizeof(struct DDE_pair));
1181 LeaveCriticalSection(&dde_crst);
1185 /* zero out newly allocated part */
1186 memset(&dde_pairs[dde_num_alloc], 0, GROWBY * sizeof(struct DDE_pair));
1187 dde_num_alloc += GROWBY;
1190 for (i = 0; i < dde_num_alloc; i++)
1192 if (dde_pairs[i].server_hMem == 0)
1194 dde_pairs[i].client_hMem = chm;
1195 dde_pairs[i].server_hMem = shm;
1200 LeaveCriticalSection(&dde_crst);
1204 static HGLOBAL dde_get_pair(HGLOBAL shm)
1209 EnterCriticalSection(&dde_crst);
1210 for (i = 0; i < dde_num_alloc; i++)
1212 if (dde_pairs[i].server_hMem == shm)
1214 /* free this pair */
1215 dde_pairs[i].server_hMem = 0;
1217 ret = dde_pairs[i].client_hMem;
1221 LeaveCriticalSection(&dde_crst);
1225 /***********************************************************************
1228 * Post a DDE message
1230 static BOOL post_dde_message( DWORD dest_tid, struct packed_message *data, const struct send_message_info *info )
1236 HGLOBAL hunlock = 0;
1240 if (!UnpackDDElParam( info->msg, info->lparam, &uiLo, &uiHi ))
1246 /* DDE messages which don't require packing are:
1255 /* uiHi should contain a hMem from WM_DDE_EXECUTE */
1256 HGLOBAL h = dde_get_pair( (HANDLE)uiHi );
1259 /* send back the value of h on the other side */
1260 push_data( data, &h, sizeof(HGLOBAL) );
1262 TRACE( "send dde-ack %x %08x => %08lx\n", uiLo, uiHi, (DWORD)h );
1267 /* uiHi should contain either an atom or 0 */
1268 TRACE( "send dde-ack %x atom=%x\n", uiLo, uiHi );
1269 lp = MAKELONG( uiLo, uiHi );
1278 size = GlobalSize( (HGLOBAL)uiLo ) ;
1279 if ((info->msg == WM_DDE_ADVISE && size < sizeof(DDEADVISE)) ||
1280 (info->msg == WM_DDE_DATA && size < sizeof(DDEDATA)) ||
1281 (info->msg == WM_DDE_POKE && size < sizeof(DDEPOKE))
1285 else if (info->msg != WM_DDE_DATA) return FALSE;
1290 if ((ptr = GlobalLock( (HGLOBAL)uiLo) ))
1292 DDEDATA *dde_data = (DDEDATA *)ptr;
1293 TRACE("unused %d, fResponse %d, fRelease %d, fDeferUpd %d, fAckReq %d, cfFormat %d\n",
1294 dde_data->unused, dde_data->fResponse, dde_data->fRelease,
1295 dde_data->reserved, dde_data->fAckReq, dde_data->cfFormat);
1296 push_data( data, ptr, size );
1297 hunlock = (HGLOBAL)uiLo;
1300 TRACE( "send ddepack %u %x\n", size, uiHi );
1302 case WM_DDE_EXECUTE:
1305 if ((ptr = GlobalLock( (HGLOBAL)info->lparam) ))
1307 push_data(data, ptr, GlobalSize( (HGLOBAL)info->lparam ));
1308 /* so that the other side can send it back on ACK */
1310 hunlock = (HGLOBAL)info->lparam;
1315 SERVER_START_REQ( send_message )
1318 req->type = info->type;
1320 req->win = info->hwnd;
1321 req->msg = info->msg;
1322 req->wparam = info->wparam;
1324 req->time = GetCurrentTime();
1326 for (i = 0; i < data->count; i++)
1327 wine_server_add_data( req, data->data[i], data->size[i] );
1328 if ((res = wine_server_call( req )))
1330 if (res == STATUS_INVALID_PARAMETER)
1331 /* FIXME: find a STATUS_ value for this one */
1332 SetLastError( ERROR_INVALID_THREAD_ID );
1334 SetLastError( RtlNtStatusToDosError(res) );
1337 FreeDDElParam(info->msg, info->lparam);
1340 if (hunlock) GlobalUnlock(hunlock);
1345 /***********************************************************************
1346 * unpack_dde_message
1348 * Unpack a posted DDE message received from another process.
1350 static BOOL unpack_dde_message( HWND hwnd, UINT message, WPARAM *wparam, LPARAM *lparam,
1351 void **buffer, size_t size )
1362 /* hMem is being passed */
1363 if (size != sizeof(HGLOBAL)) return FALSE;
1364 if (!buffer || !*buffer) return FALSE;
1366 memcpy( &hMem, *buffer, size );
1368 TRACE("recv dde-ack %x mem=%x[%lx]\n", uiLo, uiHi, GlobalSize( hMem ));
1372 uiLo = LOWORD( *lparam );
1373 uiHi = HIWORD( *lparam );
1374 TRACE("recv dde-ack %x atom=%x\n", uiLo, uiHi);
1376 *lparam = PackDDElParam( WM_DDE_ACK, uiLo, uiHi );
1381 if ((!buffer || !*buffer) && message != WM_DDE_DATA) return FALSE;
1383 TRACE( "recv ddepack %u %x\n", size, uiHi );
1386 hMem = GlobalAlloc( GMEM_MOVEABLE|GMEM_DDESHARE, size );
1387 if (hMem && (ptr = GlobalLock( hMem )))
1389 memcpy( ptr, *buffer, size );
1390 GlobalUnlock( hMem );
1396 *lparam = PackDDElParam( message, uiLo, uiHi );
1398 case WM_DDE_EXECUTE:
1401 if (!buffer || !*buffer) return FALSE;
1402 hMem = GlobalAlloc( GMEM_MOVEABLE|GMEM_DDESHARE, size );
1403 if (hMem && (ptr = GlobalLock( hMem )))
1405 memcpy( ptr, *buffer, size );
1406 GlobalUnlock( hMem );
1407 TRACE( "exec: pairing c=%08lx s=%08lx\n", *lparam, (DWORD)hMem );
1408 if (!dde_add_pair( (HGLOBAL)*lparam, hMem ))
1414 } else return FALSE;
1415 *lparam = (LPARAM)hMem;
1421 /***********************************************************************
1424 * Call a window procedure and the corresponding hooks.
1426 static LRESULT call_window_proc( HWND hwnd, UINT msg, WPARAM wparam, LPARAM lparam,
1427 BOOL unicode, BOOL same_thread )
1432 CWPRETSTRUCT cwpret;
1433 MESSAGEQUEUE *queue = QUEUE_Current();
1435 if (queue->recursion_count > MAX_SENDMSG_RECURSION) return 0;
1436 queue->recursion_count++;
1438 if (msg & 0x80000000)
1440 result = handle_internal_message( hwnd, msg, wparam, lparam );
1444 /* first the WH_CALLWNDPROC hook */
1445 hwnd = WIN_GetFullHandle( hwnd );
1446 cwp.lParam = lparam;
1447 cwp.wParam = wparam;
1450 HOOK_CallHooks( WH_CALLWNDPROC, HC_ACTION, same_thread, (LPARAM)&cwp, unicode );
1452 /* now call the window procedure */
1455 if (!(winproc = (WNDPROC)GetWindowLongPtrW( hwnd, GWLP_WNDPROC ))) goto done;
1456 result = CallWindowProcW( winproc, hwnd, msg, wparam, lparam );
1460 if (!(winproc = (WNDPROC)GetWindowLongPtrA( hwnd, GWLP_WNDPROC ))) goto done;
1461 result = CallWindowProcA( winproc, hwnd, msg, wparam, lparam );
1464 /* and finally the WH_CALLWNDPROCRET hook */
1465 cwpret.lResult = result;
1466 cwpret.lParam = lparam;
1467 cwpret.wParam = wparam;
1468 cwpret.message = msg;
1470 HOOK_CallHooks( WH_CALLWNDPROCRET, HC_ACTION, same_thread, (LPARAM)&cwpret, unicode );
1472 queue->recursion_count--;
1477 /***********************************************************************
1478 * process_hardware_message
1480 * Process a hardware message; return TRUE if message should be passed on to the app
1482 static BOOL process_hardware_message( MSG *msg, ULONG_PTR extra_info, HWND hwnd,
1483 UINT first, UINT last, BOOL remove )
1487 if (!MSG_process_raw_hardware_message( msg, extra_info, hwnd, first, last, remove ))
1490 ret = MSG_process_cooked_hardware_message( msg, extra_info, remove );
1492 /* tell the server we have passed it to the app
1493 * (even though we may end up dropping it later on)
1495 SERVER_START_REQ( reply_message )
1497 req->type = MSG_HARDWARE;
1499 req->remove = remove || !ret;
1500 wine_server_call( req );
1507 /***********************************************************************
1508 * call_sendmsg_callback
1510 * Call the callback function of SendMessageCallback.
1512 static inline void call_sendmsg_callback( SENDASYNCPROC callback, HWND hwnd, UINT msg,
1513 ULONG_PTR data, LRESULT result )
1515 if (TRACE_ON(relay))
1516 DPRINTF( "%04lx:Call message callback %p (hwnd=%p,msg=%s,data=%08lx,result=%08lx)\n",
1517 GetCurrentThreadId(), callback, hwnd, SPY_GetMsgName( msg, hwnd ),
1519 callback( hwnd, msg, data, result );
1520 if (TRACE_ON(relay))
1521 DPRINTF( "%04lx:Ret message callback %p (hwnd=%p,msg=%s,data=%08lx,result=%08lx)\n",
1522 GetCurrentThreadId(), callback, hwnd, SPY_GetMsgName( msg, hwnd ),
1527 /***********************************************************************
1530 * Peek for a message matching the given parameters. Return FALSE if none available.
1531 * All pending sent messages are processed before returning.
1533 BOOL MSG_peek_message( MSG *msg, HWND hwnd, UINT first, UINT last, int flags )
1536 ULONG_PTR extra_info = 0;
1537 MESSAGEQUEUE *queue = QUEUE_Current();
1538 struct received_message_info info, *old_info;
1540 if (!first && !last) last = ~0;
1545 void *buffer = NULL;
1546 size_t size = 0, buffer_size = 0;
1548 do /* loop while buffer is too small */
1550 if (buffer_size && !(buffer = HeapAlloc( GetProcessHeap(), 0, buffer_size )))
1552 SERVER_START_REQ( get_message )
1555 req->get_win = hwnd;
1556 req->get_first = first;
1557 req->get_last = last;
1558 if (buffer_size) wine_server_set_reply( req, buffer, buffer_size );
1559 if (!(res = wine_server_call( req )))
1561 size = wine_server_reply_size( reply );
1562 info.type = reply->type;
1563 info.msg.hwnd = reply->win;
1564 info.msg.message = reply->msg;
1565 info.msg.wParam = reply->wparam;
1566 info.msg.lParam = reply->lparam;
1567 info.msg.time = reply->time;
1568 info.msg.pt.x = reply->x;
1569 info.msg.pt.y = reply->y;
1570 extra_info = reply->info;
1574 if (buffer) HeapFree( GetProcessHeap(), 0, buffer );
1575 buffer_size = reply->total;
1579 } while (res == STATUS_BUFFER_OVERFLOW);
1581 if (res) return FALSE;
1583 TRACE( "got type %d msg %x (%s) hwnd %p wp %x lp %lx\n",
1584 info.type, info.msg.message, SPY_GetMsgName(info.msg.message, info.msg.hwnd),
1585 info.msg.hwnd, info.msg.wParam, info.msg.lParam );
1591 info.flags = ISMEX_SEND;
1594 info.flags = ISMEX_NOTIFY;
1597 info.flags = ISMEX_CALLBACK;
1599 case MSG_CALLBACK_RESULT:
1600 call_sendmsg_callback( (SENDASYNCPROC)info.msg.wParam, info.msg.hwnd,
1601 info.msg.message, extra_info, info.msg.lParam );
1603 case MSG_OTHER_PROCESS:
1604 info.flags = ISMEX_SEND;
1605 if (!unpack_message( info.msg.hwnd, info.msg.message, &info.msg.wParam,
1606 &info.msg.lParam, &buffer, size ))
1608 ERR( "invalid packed message %x (%s) hwnd %p wp %x lp %lx size %d\n",
1609 info.msg.message, SPY_GetMsgName(info.msg.message, info.msg.hwnd), info.msg.hwnd,
1610 info.msg.wParam, info.msg.lParam, size );
1612 reply_message( &info, 0, TRUE );
1617 if (!process_hardware_message( &info.msg, extra_info,
1618 hwnd, first, last, flags & GET_MSG_REMOVE ))
1620 TRACE("dropping msg %x\n", info.msg.message );
1621 goto next; /* ignore it */
1623 queue->GetMessagePosVal = MAKELONG( info.msg.pt.x, info.msg.pt.y );
1626 queue->GetMessageExtraInfoVal = extra_info;
1627 if (info.msg.message >= WM_DDE_FIRST && info.msg.message <= WM_DDE_LAST)
1629 if (!unpack_dde_message( info.msg.hwnd, info.msg.message, &info.msg.wParam,
1630 &info.msg.lParam, &buffer, size ))
1632 ERR( "invalid packed dde-message %x (%s) hwnd %p wp %x lp %lx size %d\n",
1633 info.msg.message, SPY_GetMsgName(info.msg.message, info.msg.hwnd),
1634 info.msg.hwnd, info.msg.wParam, info.msg.lParam, size );
1635 goto next; /* ignore it */
1639 if (buffer) HeapFree( GetProcessHeap(), 0, buffer );
1643 /* if we get here, we have a sent message; call the window procedure */
1644 old_info = queue->receive_info;
1645 queue->receive_info = &info;
1646 result = call_window_proc( info.msg.hwnd, info.msg.message, info.msg.wParam,
1647 info.msg.lParam, (info.type != MSG_ASCII), FALSE );
1648 reply_message( &info, result, TRUE );
1649 queue->receive_info = old_info;
1651 if (buffer) HeapFree( GetProcessHeap(), 0, buffer );
1656 /***********************************************************************
1657 * wait_message_reply
1659 * Wait until a sent message gets replied to.
1661 static void wait_message_reply( UINT flags )
1663 MESSAGEQUEUE *queue;
1665 if (!(queue = QUEUE_Current())) return;
1669 unsigned int wake_bits = 0, changed_bits = 0;
1672 SERVER_START_REQ( set_queue_mask )
1674 req->wake_mask = QS_SMRESULT | ((flags & SMTO_BLOCK) ? 0 : QS_SENDMESSAGE);
1675 req->changed_mask = req->wake_mask;
1677 if (!wine_server_call( req ))
1679 wake_bits = reply->wake_bits;
1680 changed_bits = reply->changed_bits;
1685 if (wake_bits & QS_SMRESULT) return; /* got a result */
1686 if (wake_bits & QS_SENDMESSAGE)
1688 /* Process the sent message immediately */
1690 MSG_peek_message( &msg, 0, 0, 0, GET_MSG_REMOVE | GET_MSG_SENT_ONLY );
1694 /* now wait for it */
1696 ReleaseThunkLock( &dwlc );
1698 if (USER_Driver.pMsgWaitForMultipleObjectsEx)
1699 res = USER_Driver.pMsgWaitForMultipleObjectsEx( 1, &queue->server_queue,
1702 res = WaitForSingleObject( queue->server_queue, INFINITE );
1704 if (dwlc) RestoreThunkLock( dwlc );
1708 /***********************************************************************
1709 * put_message_in_queue
1711 * Put a sent message into the destination queue.
1712 * For inter-process message, reply_size is set to expected size of reply data.
1714 static BOOL put_message_in_queue( DWORD dest_tid, const struct send_message_info *info,
1715 size_t *reply_size )
1717 struct packed_message data;
1719 int i, timeout = -1;
1721 if (info->type != MSG_NOTIFY &&
1722 info->type != MSG_CALLBACK &&
1723 info->type != MSG_POSTED &&
1724 info->timeout != INFINITE)
1725 timeout = info->timeout;
1728 if (info->type == MSG_OTHER_PROCESS)
1730 *reply_size = pack_message( info->hwnd, info->msg, info->wparam, info->lparam, &data );
1731 if (data.count == -1)
1733 WARN( "cannot pack message %x\n", info->msg );
1737 else if (info->type == MSG_POSTED && info->msg >= WM_DDE_FIRST && info->msg <= WM_DDE_LAST)
1739 return post_dde_message( dest_tid, &data, info );
1742 SERVER_START_REQ( send_message )
1745 req->type = info->type;
1747 req->win = info->hwnd;
1748 req->msg = info->msg;
1749 req->wparam = info->wparam;
1750 req->lparam = info->lparam;
1751 req->time = GetCurrentTime();
1752 req->timeout = timeout;
1754 if (info->type == MSG_CALLBACK)
1756 req->callback = info->callback;
1757 req->info = info->data;
1760 if (info->flags & SMTO_ABORTIFHUNG) req->flags |= SEND_MSG_ABORT_IF_HUNG;
1761 for (i = 0; i < data.count; i++) wine_server_add_data( req, data.data[i], data.size[i] );
1762 if ((res = wine_server_call( req )))
1764 if (res == STATUS_INVALID_PARAMETER)
1765 /* FIXME: find a STATUS_ value for this one */
1766 SetLastError( ERROR_INVALID_THREAD_ID );
1768 SetLastError( RtlNtStatusToDosError(res) );
1776 /***********************************************************************
1779 * Retrieve a message reply from the server.
1781 static LRESULT retrieve_reply( const struct send_message_info *info,
1782 size_t reply_size, LRESULT *result )
1785 void *reply_data = NULL;
1789 if (!(reply_data = HeapAlloc( GetProcessHeap(), 0, reply_size )))
1791 WARN( "no memory for reply %d bytes, will be truncated\n", reply_size );
1795 SERVER_START_REQ( get_message_reply )
1798 if (reply_size) wine_server_set_reply( req, reply_data, reply_size );
1799 if (!(status = wine_server_call( req ))) *result = reply->result;
1800 reply_size = wine_server_reply_size( reply );
1803 if (!status && reply_size)
1804 unpack_reply( info->hwnd, info->msg, info->wparam, info->lparam, reply_data, reply_size );
1806 if (reply_data) HeapFree( GetProcessHeap(), 0, reply_data );
1808 TRACE( "hwnd %p msg %x (%s) wp %x lp %lx got reply %lx (err=%ld)\n",
1809 info->hwnd, info->msg, SPY_GetMsgName(info->msg, info->hwnd), info->wparam,
1810 info->lparam, *result, status );
1812 /* MSDN states that last error is 0 on timeout, but at least NT4 returns ERROR_TIMEOUT */
1813 if (status) SetLastError( RtlNtStatusToDosError(status) );
1818 /***********************************************************************
1819 * send_inter_thread_message
1821 static LRESULT send_inter_thread_message( DWORD dest_tid, const struct send_message_info *info,
1826 size_t reply_size = 0;
1828 TRACE( "hwnd %p msg %x (%s) wp %x lp %lx\n",
1829 info->hwnd, info->msg, SPY_GetMsgName(info->msg, info->hwnd), info->wparam, info->lparam );
1831 if (!put_message_in_queue( dest_tid, info, &reply_size )) return 0;
1833 /* there's no reply to wait for on notify/callback messages */
1834 if (info->type == MSG_NOTIFY || info->type == MSG_CALLBACK) return 1;
1836 locks = WIN_SuspendWndsLock();
1838 wait_message_reply( info->flags );
1839 ret = retrieve_reply( info, reply_size, res_ptr );
1841 WIN_RestoreWndsLock( locks );
1846 /***********************************************************************
1847 * MSG_SendInternalMessageTimeout
1849 * Same as SendMessageTimeoutW but sends the message to a specific thread
1850 * without requiring a window handle. Only works for internal Wine messages.
1852 LRESULT MSG_SendInternalMessageTimeout( DWORD dest_pid, DWORD dest_tid,
1853 UINT msg, WPARAM wparam, LPARAM lparam,
1854 UINT flags, UINT timeout, PDWORD_PTR res_ptr )
1856 struct send_message_info info;
1857 LRESULT ret, result;
1859 assert( msg & 0x80000000 ); /* must be an internal Wine message */
1861 info.type = MSG_UNICODE;
1864 info.wparam = wparam;
1865 info.lparam = lparam;
1867 info.timeout = timeout;
1869 if (USER_IsExitingThread( dest_tid )) return 0;
1871 if (dest_tid == GetCurrentThreadId())
1873 result = handle_internal_message( 0, msg, wparam, lparam );
1878 if (dest_pid != GetCurrentProcessId()) info.type = MSG_OTHER_PROCESS;
1879 ret = send_inter_thread_message( dest_tid, &info, &result );
1881 if (ret && res_ptr) *res_ptr = result;
1886 /***********************************************************************
1887 * SendMessageTimeoutW (USER32.@)
1889 LRESULT WINAPI SendMessageTimeoutW( HWND hwnd, UINT msg, WPARAM wparam, LPARAM lparam,
1890 UINT flags, UINT timeout, PDWORD_PTR res_ptr )
1892 struct send_message_info info;
1893 DWORD dest_tid, dest_pid;
1894 LRESULT ret, result;
1896 info.type = MSG_UNICODE;
1899 info.wparam = wparam;
1900 info.lparam = lparam;
1902 info.timeout = timeout;
1904 if (is_broadcast(hwnd))
1906 EnumWindows( broadcast_message_callback, (LPARAM)&info );
1907 if (res_ptr) *res_ptr = 1;
1911 if (!(dest_tid = GetWindowThreadProcessId( hwnd, &dest_pid ))) return 0;
1913 if (USER_IsExitingThread( dest_tid )) return 0;
1915 SPY_EnterMessage( SPY_SENDMESSAGE, hwnd, msg, wparam, lparam );
1917 if (dest_tid == GetCurrentThreadId())
1919 result = call_window_proc( hwnd, msg, wparam, lparam, TRUE, TRUE );
1924 if (dest_pid != GetCurrentProcessId()) info.type = MSG_OTHER_PROCESS;
1925 ret = send_inter_thread_message( dest_tid, &info, &result );
1928 SPY_ExitMessage( SPY_RESULT_OK, hwnd, msg, result, wparam, lparam );
1929 if (ret && res_ptr) *res_ptr = result;
1934 /***********************************************************************
1935 * SendMessageTimeoutA (USER32.@)
1937 LRESULT WINAPI SendMessageTimeoutA( HWND hwnd, UINT msg, WPARAM wparam, LPARAM lparam,
1938 UINT flags, UINT timeout, PDWORD_PTR res_ptr )
1940 struct send_message_info info;
1941 DWORD dest_tid, dest_pid;
1942 LRESULT ret, result;
1944 info.type = MSG_ASCII;
1947 info.wparam = wparam;
1948 info.lparam = lparam;
1950 info.timeout = timeout;
1952 if (is_broadcast(hwnd))
1954 EnumWindows( broadcast_message_callback, (LPARAM)&info );
1955 if (res_ptr) *res_ptr = 1;
1959 if (!(dest_tid = GetWindowThreadProcessId( hwnd, &dest_pid ))) return 0;
1961 if (USER_IsExitingThread( dest_tid )) return 0;
1963 SPY_EnterMessage( SPY_SENDMESSAGE, hwnd, msg, wparam, lparam );
1965 if (dest_tid == GetCurrentThreadId())
1967 result = call_window_proc( hwnd, msg, wparam, lparam, FALSE, TRUE );
1970 else if (dest_pid == GetCurrentProcessId())
1972 ret = send_inter_thread_message( dest_tid, &info, &result );
1976 /* inter-process message: need to map to Unicode */
1977 info.type = MSG_OTHER_PROCESS;
1978 if (is_unicode_message( info.msg ))
1980 if (WINPROC_MapMsg32ATo32W( info.hwnd, info.msg, &info.wparam, &info.lparam ) == -1)
1982 ret = send_inter_thread_message( dest_tid, &info, &result );
1983 result = WINPROC_UnmapMsg32ATo32W( info.hwnd, info.msg, info.wparam,
1984 info.lparam, result );
1986 else ret = send_inter_thread_message( dest_tid, &info, &result );
1988 SPY_ExitMessage( SPY_RESULT_OK, hwnd, msg, result, wparam, lparam );
1989 if (ret && res_ptr) *res_ptr = result;
1994 /***********************************************************************
1995 * SendMessageW (USER32.@)
1997 LRESULT WINAPI SendMessageW( HWND hwnd, UINT msg, WPARAM wparam, LPARAM lparam )
2000 SendMessageTimeoutW( hwnd, msg, wparam, lparam, SMTO_NORMAL, INFINITE, &res );
2005 /***********************************************************************
2006 * SendMessageA (USER32.@)
2008 LRESULT WINAPI SendMessageA( HWND hwnd, UINT msg, WPARAM wparam, LPARAM lparam )
2011 SendMessageTimeoutA( hwnd, msg, wparam, lparam, SMTO_NORMAL, INFINITE, &res );
2016 /***********************************************************************
2017 * SendNotifyMessageA (USER32.@)
2019 BOOL WINAPI SendNotifyMessageA( HWND hwnd, UINT msg, WPARAM wparam, LPARAM lparam )
2021 return SendNotifyMessageW( hwnd, msg, map_wparam_AtoW( msg, wparam ), lparam );
2025 /***********************************************************************
2026 * SendNotifyMessageW (USER32.@)
2028 BOOL WINAPI SendNotifyMessageW( HWND hwnd, UINT msg, WPARAM wparam, LPARAM lparam )
2030 struct send_message_info info;
2034 if (is_pointer_message(msg))
2036 SetLastError(ERROR_INVALID_PARAMETER);
2040 info.type = MSG_NOTIFY;
2043 info.wparam = wparam;
2044 info.lparam = lparam;
2047 if (is_broadcast(hwnd))
2049 EnumWindows( broadcast_message_callback, (LPARAM)&info );
2053 if (!(dest_tid = GetWindowThreadProcessId( hwnd, NULL ))) return FALSE;
2055 if (USER_IsExitingThread( dest_tid )) return TRUE;
2057 if (dest_tid == GetCurrentThreadId())
2059 call_window_proc( hwnd, msg, wparam, lparam, TRUE, TRUE );
2062 return send_inter_thread_message( dest_tid, &info, &result );
2066 /***********************************************************************
2067 * SendMessageCallbackA (USER32.@)
2069 BOOL WINAPI SendMessageCallbackA( HWND hwnd, UINT msg, WPARAM wparam, LPARAM lparam,
2070 SENDASYNCPROC callback, ULONG_PTR data )
2072 return SendMessageCallbackW( hwnd, msg, map_wparam_AtoW( msg, wparam ),
2073 lparam, callback, data );
2077 /***********************************************************************
2078 * SendMessageCallbackW (USER32.@)
2080 BOOL WINAPI SendMessageCallbackW( HWND hwnd, UINT msg, WPARAM wparam, LPARAM lparam,
2081 SENDASYNCPROC callback, ULONG_PTR data )
2083 struct send_message_info info;
2087 if (is_pointer_message(msg))
2089 SetLastError(ERROR_INVALID_PARAMETER);
2093 info.type = MSG_CALLBACK;
2096 info.wparam = wparam;
2097 info.lparam = lparam;
2098 info.callback = callback;
2102 if (is_broadcast(hwnd))
2104 EnumWindows( broadcast_message_callback, (LPARAM)&info );
2108 if (!(dest_tid = GetWindowThreadProcessId( hwnd, NULL ))) return FALSE;
2110 if (USER_IsExitingThread( dest_tid )) return TRUE;
2112 if (dest_tid == GetCurrentThreadId())
2114 result = call_window_proc( hwnd, msg, wparam, lparam, TRUE, TRUE );
2115 call_sendmsg_callback( callback, hwnd, msg, data, result );
2118 FIXME( "callback will not be called\n" );
2119 return send_inter_thread_message( dest_tid, &info, &result );
2123 /***********************************************************************
2124 * ReplyMessage (USER32.@)
2126 BOOL WINAPI ReplyMessage( LRESULT result )
2128 MESSAGEQUEUE *queue = QUEUE_Current();
2129 struct received_message_info *info = queue->receive_info;
2131 if (!info) return FALSE;
2132 reply_message( info, result, FALSE );
2137 /***********************************************************************
2138 * InSendMessage (USER32.@)
2140 BOOL WINAPI InSendMessage(void)
2142 return (InSendMessageEx(NULL) & (ISMEX_SEND|ISMEX_REPLIED)) == ISMEX_SEND;
2146 /***********************************************************************
2147 * InSendMessageEx (USER32.@)
2149 DWORD WINAPI InSendMessageEx( LPVOID reserved )
2151 MESSAGEQUEUE *queue = QUEUE_Current();
2152 struct received_message_info *info = queue->receive_info;
2154 if (info) return info->flags;
2155 return ISMEX_NOSEND;
2159 /***********************************************************************
2160 * PostMessageA (USER32.@)
2162 BOOL WINAPI PostMessageA( HWND hwnd, UINT msg, WPARAM wparam, LPARAM lparam )
2164 return PostMessageW( hwnd, msg, map_wparam_AtoW( msg, wparam ), lparam );
2168 /***********************************************************************
2169 * PostMessageW (USER32.@)
2171 BOOL WINAPI PostMessageW( HWND hwnd, UINT msg, WPARAM wparam, LPARAM lparam )
2173 struct send_message_info info;
2176 if (is_pointer_message( msg ))
2178 SetLastError( ERROR_INVALID_PARAMETER );
2182 TRACE( "hwnd %p msg %x (%s) wp %x lp %lx\n",
2183 hwnd, msg, SPY_GetMsgName(msg, hwnd), wparam, lparam );
2185 info.type = MSG_POSTED;
2188 info.wparam = wparam;
2189 info.lparam = lparam;
2192 if (is_broadcast(hwnd))
2194 EnumWindows( broadcast_message_callback, (LPARAM)&info );
2198 if (!hwnd) return PostThreadMessageW( GetCurrentThreadId(), msg, wparam, lparam );
2200 if (!(dest_tid = GetWindowThreadProcessId( hwnd, NULL ))) return FALSE;
2202 if (USER_IsExitingThread( dest_tid )) return TRUE;
2204 return put_message_in_queue( dest_tid, &info, NULL );
2208 /**********************************************************************
2209 * PostThreadMessageA (USER32.@)
2211 BOOL WINAPI PostThreadMessageA( DWORD thread, UINT msg, WPARAM wparam, LPARAM lparam )
2213 return PostThreadMessageW( thread, msg, map_wparam_AtoW( msg, wparam ), lparam );
2217 /**********************************************************************
2218 * PostThreadMessageW (USER32.@)
2220 BOOL WINAPI PostThreadMessageW( DWORD thread, UINT msg, WPARAM wparam, LPARAM lparam )
2222 struct send_message_info info;
2224 if (is_pointer_message( msg ))
2226 SetLastError( ERROR_INVALID_PARAMETER );
2229 if (USER_IsExitingThread( thread )) return TRUE;
2231 info.type = MSG_POSTED;
2234 info.wparam = wparam;
2235 info.lparam = lparam;
2237 return put_message_in_queue( thread, &info, NULL );
2241 /***********************************************************************
2242 * PostQuitMessage (USER32.@)
2244 void WINAPI PostQuitMessage( INT exitCode )
2246 PostThreadMessageW( GetCurrentThreadId(), WM_QUIT, exitCode, 0 );
2250 /***********************************************************************
2251 * PeekMessageW (USER32.@)
2253 BOOL WINAPI PeekMessageW( MSG *msg_out, HWND hwnd, UINT first, UINT last, UINT flags )
2255 MESSAGEQUEUE *queue;
2259 /* check for graphics events */
2260 if (USER_Driver.pMsgWaitForMultipleObjectsEx)
2261 USER_Driver.pMsgWaitForMultipleObjectsEx( 0, NULL, 0, 0, 0 );
2263 hwnd = WIN_GetFullHandle( hwnd );
2264 locks = WIN_SuspendWndsLock();
2266 if (!MSG_peek_message( &msg, hwnd, first, last,
2267 (flags & PM_REMOVE) ? GET_MSG_REMOVE : 0 ))
2269 if (!(flags & PM_NOYIELD))
2272 ReleaseThunkLock(&count);
2273 if (count) RestoreThunkLock(count);
2275 WIN_RestoreWndsLock( locks );
2279 WIN_RestoreWndsLock( locks );
2281 /* need to fill the window handle for WM_PAINT message */
2282 if (msg.message == WM_PAINT)
2284 if (IsIconic( msg.hwnd ) && GetClassLongW( msg.hwnd, GCL_HICON ))
2286 msg.message = WM_PAINTICON;
2289 /* clear internal paint flag */
2290 RedrawWindow( msg.hwnd, NULL, 0, RDW_NOINTERNALPAINT | RDW_NOCHILDREN );
2293 if ((queue = QUEUE_Current()))
2295 queue->GetMessageTimeVal = msg.time;
2296 msg.pt.x = LOWORD( queue->GetMessagePosVal );
2297 msg.pt.y = HIWORD( queue->GetMessagePosVal );
2300 HOOK_CallHooks( WH_GETMESSAGE, HC_ACTION, flags & PM_REMOVE, (LPARAM)&msg, TRUE );
2302 /* copy back our internal safe copy of message data to msg_out.
2303 * msg_out is a variable from the *program*, so it can't be used
2304 * internally as it can get "corrupted" by our use of SendMessage()
2305 * (back to the program) inside the message handling itself. */
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();
2428 /**********************************************************************
2429 * AttachThreadInput (USER32.@)
2431 * Attaches the input processing mechanism of one thread to that of
2434 BOOL WINAPI AttachThreadInput( DWORD from, DWORD to, BOOL attach )
2438 SERVER_START_REQ( attach_thread_input )
2440 req->tid_from = from;
2442 req->attach = attach;
2443 ret = !wine_server_call_err( req );
2450 /**********************************************************************
2451 * GetGUIThreadInfo (USER32.@)
2453 BOOL WINAPI GetGUIThreadInfo( DWORD id, GUITHREADINFO *info )
2457 SERVER_START_REQ( get_thread_input )
2460 if ((ret = !wine_server_call_err( req )))
2463 info->hwndActive = reply->active;
2464 info->hwndFocus = reply->focus;
2465 info->hwndCapture = reply->capture;
2466 info->hwndMenuOwner = reply->menu_owner;
2467 info->hwndMoveSize = reply->move_size;
2468 info->hwndCaret = reply->caret;
2469 info->rcCaret.left = reply->rect.left;
2470 info->rcCaret.top = reply->rect.top;
2471 info->rcCaret.right = reply->rect.right;
2472 info->rcCaret.bottom = reply->rect.bottom;
2473 if (reply->menu_owner) info->flags |= GUI_INMENUMODE;
2474 if (reply->move_size) info->flags |= GUI_INMOVESIZE;
2475 if (reply->caret) info->flags |= GUI_CARETBLINKING;
2483 /**********************************************************************
2484 * GetKeyState (USER32.@)
2486 * An application calls the GetKeyState function in response to a
2487 * keyboard-input message. This function retrieves the state of the key
2488 * at the time the input message was generated.
2490 SHORT WINAPI GetKeyState(INT vkey)
2494 SERVER_START_REQ( get_key_state )
2496 req->tid = GetCurrentThreadId();
2498 if (!wine_server_call( req )) retval = (signed char)reply->state;
2501 TRACE("key (0x%x) -> %x\n", vkey, retval);
2506 /**********************************************************************
2507 * GetKeyboardState (USER32.@)
2509 BOOL WINAPI GetKeyboardState( LPBYTE state )
2513 TRACE("(%p)\n", state);
2515 memset( state, 0, 256 );
2516 SERVER_START_REQ( get_key_state )
2518 req->tid = GetCurrentThreadId();
2520 wine_server_set_reply( req, state, 256 );
2521 ret = !wine_server_call_err( req );
2528 /**********************************************************************
2529 * SetKeyboardState (USER32.@)
2531 BOOL WINAPI SetKeyboardState( LPBYTE state )
2535 TRACE("(%p)\n", state);
2537 SERVER_START_REQ( set_key_state )
2539 req->tid = GetCurrentThreadId();
2540 wine_server_add_data( req, state, 256 );
2541 ret = !wine_server_call_err( req );
2547 /******************************************************************
2548 * IsHungAppWindow (USER32.@)
2551 BOOL WINAPI IsHungAppWindow( HWND hWnd )
2554 return !SendMessageTimeoutA(hWnd, WM_NULL, 0, 0, SMTO_ABORTIFHUNG, 5000, &dwResult);