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) | SET(SBM_GETSCROLLBARINFO),
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);
502 case SBM_GETSCROLLBARINFO:
504 const SCROLLBARINFO *info = (const SCROLLBARINFO *)lparam;
505 size_t size = min( info->cbSize, sizeof(SCROLLBARINFO) );
506 push_data( data, info, size );
514 if (wparam) size += sizeof(DWORD);
515 if (lparam) size += sizeof(DWORD);
520 case CB_GETDROPPEDCONTROLRECT:
524 push_data( data, (RECT *)lparam, sizeof(RECT) );
528 WORD *pw = (WORD *)lparam;
529 push_data( data, pw, sizeof(*pw) );
530 return *pw * sizeof(WCHAR);
534 if (wparam) push_data( data, (UINT *)lparam, sizeof(UINT) * wparam );
537 case CB_INSERTSTRING:
539 case CB_FINDSTRINGEXACT:
540 case CB_SELECTSTRING:
541 if (combobox_has_strings( hwnd )) push_string( data, (LPWSTR)lparam );
544 if (!combobox_has_strings( hwnd )) return sizeof(ULONG_PTR);
545 return (SendMessageW( hwnd, CB_GETLBTEXTLEN, wparam, 0 ) + 1) * sizeof(WCHAR);
547 case LB_INSERTSTRING:
549 case LB_FINDSTRINGEXACT:
550 case LB_SELECTSTRING:
551 if (listbox_has_strings( hwnd )) push_string( data, (LPWSTR)lparam );
554 if (!listbox_has_strings( hwnd )) return sizeof(ULONG_PTR);
555 return (SendMessageW( hwnd, LB_GETTEXTLEN, wparam, 0 ) + 1) * sizeof(WCHAR);
557 return wparam * sizeof(UINT);
559 push_data( data, (MDINEXTMENU *)lparam, sizeof(MDINEXTMENU) );
560 return sizeof(MDINEXTMENU);
563 push_data( data, (RECT *)lparam, sizeof(RECT) );
567 MDICREATESTRUCTW *cs = (MDICREATESTRUCTW *)lparam;
568 push_data( data, cs, sizeof(*cs) );
569 if (HIWORD(cs->szTitle)) push_string( data, cs->szTitle );
570 if (HIWORD(cs->szClass)) push_string( data, cs->szClass );
573 case WM_MDIGETACTIVE:
574 if (lparam) return sizeof(BOOL);
576 case WM_WINE_SETWINDOWPOS:
577 push_data( data, (WINDOWPOS *)lparam, sizeof(WINDOWPOS) );
579 case WM_WINE_KEYBOARD_LL_HOOK:
580 push_data( data, (KBDLLHOOKSTRUCT *)lparam, sizeof(KBDLLHOOKSTRUCT) );
582 case WM_WINE_MOUSE_LL_HOOK:
583 push_data( data, (MSLLHOOKSTRUCT *)lparam, sizeof(MSLLHOOKSTRUCT) );
586 /* these contain an HFONT */
589 /* these contain an HDC */
592 case WM_ICONERASEBKGND:
594 case WM_CTLCOLORMSGBOX:
595 case WM_CTLCOLOREDIT:
596 case WM_CTLCOLORLISTBOX:
599 case WM_CTLCOLORSCROLLBAR:
600 case WM_CTLCOLORSTATIC:
603 /* these contain an HGLOBAL */
604 case WM_PAINTCLIPBOARD:
605 case WM_SIZECLIPBOARD:
606 /* these contain HICON */
609 case WM_QUERYDRAGICON:
610 case WM_QUERYPARKICON:
611 /* these contain pointers */
613 case WM_QUERYDROPOBJECT:
617 case WM_DEVICECHANGE:
618 FIXME( "msg %x (%s) not supported yet\n", message, SPY_GetMsgName(message, hwnd) );
626 /***********************************************************************
629 * Unpack a message received from another process.
631 static BOOL unpack_message( HWND hwnd, UINT message, WPARAM *wparam, LPARAM *lparam,
632 void **buffer, size_t size )
641 CREATESTRUCTW *cs = *buffer;
642 WCHAR *str = (WCHAR *)(cs + 1);
643 if (size < sizeof(*cs)) return FALSE;
645 if (HIWORD(cs->lpszName))
647 if (!check_string( str, size )) return FALSE;
649 size -= (strlenW(str) + 1) * sizeof(WCHAR);
650 str += strlenW(str) + 1;
652 if (HIWORD(cs->lpszClass))
654 if (!check_string( str, size )) return FALSE;
660 case WM_ASKCBFORMATNAME:
661 if (!get_buffer_space( buffer, (*wparam * sizeof(WCHAR)) )) return FALSE;
663 case WM_WININICHANGE:
664 if (!*lparam) return TRUE;
667 case WM_DEVMODECHANGE:
672 if (!check_string( *buffer, size )) return FALSE;
674 case WM_GETMINMAXINFO:
675 minsize = sizeof(MINMAXINFO);
678 minsize = sizeof(DRAWITEMSTRUCT);
681 minsize = sizeof(MEASUREITEMSTRUCT);
684 minsize = sizeof(DELETEITEMSTRUCT);
687 minsize = sizeof(COMPAREITEMSTRUCT);
689 case WM_WINDOWPOSCHANGING:
690 case WM_WINDOWPOSCHANGED:
691 case WM_WINE_SETWINDOWPOS:
692 minsize = sizeof(WINDOWPOS);
696 COPYDATASTRUCT *cp = *buffer;
697 if (size < sizeof(*cp)) return FALSE;
700 minsize = sizeof(*cp) + cp->cbData;
706 /* WM_NOTIFY cannot be sent across processes (MSDN) */
709 minsize = sizeof(HELPINFO);
711 case WM_STYLECHANGING:
712 case WM_STYLECHANGED:
713 minsize = sizeof(STYLESTRUCT);
716 if (!*wparam) minsize = sizeof(RECT);
719 NCCALCSIZE_PARAMS *nc = *buffer;
720 if (size < sizeof(*nc) + sizeof(*nc->lppos)) return FALSE;
721 nc->lppos = (WINDOWPOS *)(nc + 1);
725 if (!*lparam) return TRUE;
726 minsize = sizeof(MSG);
728 case SBM_SETSCROLLINFO:
729 minsize = sizeof(SCROLLINFO);
731 case SBM_GETSCROLLINFO:
732 if (!get_buffer_space( buffer, sizeof(SCROLLINFO ))) return FALSE;
734 case SBM_GETSCROLLBARINFO:
735 if (!get_buffer_space( buffer, sizeof(SCROLLBARINFO ))) return FALSE;
740 if (*wparam || *lparam)
742 if (!get_buffer_space( buffer, 2*sizeof(DWORD) )) return FALSE;
743 if (*wparam) *wparam = (WPARAM)*buffer;
744 if (*lparam) *lparam = (LPARAM)((DWORD *)*buffer + 1);
749 case CB_GETDROPPEDCONTROLRECT:
750 if (!get_buffer_space( buffer, sizeof(RECT) )) return FALSE;
754 minsize = sizeof(RECT);
759 if (size < sizeof(WORD)) return FALSE;
760 len = *(WORD *)*buffer;
761 if (!get_buffer_space( buffer, (len + 1) * sizeof(WCHAR) )) return FALSE;
762 *lparam = (LPARAM)*buffer + sizeof(WORD); /* don't erase WORD at start of buffer */
767 if (!*wparam) return TRUE;
768 minsize = *wparam * sizeof(UINT);
771 case CB_INSERTSTRING:
773 case CB_FINDSTRINGEXACT:
774 case CB_SELECTSTRING:
776 case LB_INSERTSTRING:
778 case LB_FINDSTRINGEXACT:
779 case LB_SELECTSTRING:
780 if (!*buffer) return TRUE;
781 if (!check_string( *buffer, size )) return FALSE;
785 size = sizeof(ULONG_PTR);
786 if (combobox_has_strings( hwnd ))
787 size = (SendMessageW( hwnd, CB_GETLBTEXTLEN, *wparam, 0 ) + 1) * sizeof(WCHAR);
788 if (!get_buffer_space( buffer, size )) return FALSE;
793 size = sizeof(ULONG_PTR);
794 if (listbox_has_strings( hwnd ))
795 size = (SendMessageW( hwnd, LB_GETTEXTLEN, *wparam, 0 ) + 1) * sizeof(WCHAR);
796 if (!get_buffer_space( buffer, size )) return FALSE;
800 if (!get_buffer_space( buffer, *wparam * sizeof(UINT) )) return FALSE;
803 minsize = sizeof(MDINEXTMENU);
804 if (!get_buffer_space( buffer, sizeof(MDINEXTMENU) )) return FALSE;
808 minsize = sizeof(RECT);
809 if (!get_buffer_space( buffer, sizeof(RECT) )) return FALSE;
813 MDICREATESTRUCTW *cs = *buffer;
814 WCHAR *str = (WCHAR *)(cs + 1);
815 if (size < sizeof(*cs)) return FALSE;
817 if (HIWORD(cs->szTitle))
819 if (!check_string( str, size )) return FALSE;
821 size -= (strlenW(str) + 1) * sizeof(WCHAR);
822 str += strlenW(str) + 1;
824 if (HIWORD(cs->szClass))
826 if (!check_string( str, size )) return FALSE;
831 case WM_MDIGETACTIVE:
832 if (!*lparam) return TRUE;
833 if (!get_buffer_space( buffer, sizeof(BOOL) )) return FALSE;
835 case WM_WINE_KEYBOARD_LL_HOOK:
836 minsize = sizeof(KBDLLHOOKSTRUCT);
838 case WM_WINE_MOUSE_LL_HOOK:
839 minsize = sizeof(MSLLHOOKSTRUCT);
842 /* these contain an HFONT */
845 /* these contain an HDC */
848 case WM_ICONERASEBKGND:
850 case WM_CTLCOLORMSGBOX:
851 case WM_CTLCOLOREDIT:
852 case WM_CTLCOLORLISTBOX:
855 case WM_CTLCOLORSCROLLBAR:
856 case WM_CTLCOLORSTATIC:
859 /* these contain an HGLOBAL */
860 case WM_PAINTCLIPBOARD:
861 case WM_SIZECLIPBOARD:
862 /* these contain HICON */
865 case WM_QUERYDRAGICON:
866 case WM_QUERYPARKICON:
867 /* these contain pointers */
869 case WM_QUERYDROPOBJECT:
873 case WM_DEVICECHANGE:
874 FIXME( "msg %x (%s) not supported yet\n", message, SPY_GetMsgName(message, hwnd) );
878 return TRUE; /* message doesn't need any unpacking */
881 /* default exit for most messages: check minsize and store buffer in lparam */
882 if (size < minsize) return FALSE;
883 *lparam = (LPARAM)*buffer;
888 /***********************************************************************
891 * Pack a reply to a message for sending to another process.
893 static void pack_reply( HWND hwnd, UINT message, WPARAM wparam, LPARAM lparam,
894 LRESULT res, struct packed_message *data )
901 push_data( data, (CREATESTRUCTW *)lparam, sizeof(CREATESTRUCTW) );
906 push_data( data, (WCHAR *)lparam, (res + 1) * sizeof(WCHAR) );
908 case WM_GETMINMAXINFO:
909 push_data( data, (MINMAXINFO *)lparam, sizeof(MINMAXINFO) );
912 push_data( data, (MEASUREITEMSTRUCT *)lparam, sizeof(MEASUREITEMSTRUCT) );
914 case WM_WINDOWPOSCHANGING:
915 case WM_WINDOWPOSCHANGED:
916 push_data( data, (WINDOWPOS *)lparam, sizeof(WINDOWPOS) );
919 if (lparam) push_data( data, (MSG *)lparam, sizeof(MSG) );
921 case SBM_GETSCROLLINFO:
922 push_data( data, (SCROLLINFO *)lparam, sizeof(SCROLLINFO) );
926 case CB_GETDROPPEDCONTROLRECT:
929 push_data( data, (RECT *)lparam, sizeof(RECT) );
933 WORD *ptr = (WORD *)lparam;
934 push_data( data, ptr, ptr[-1] * sizeof(WCHAR) );
938 push_data( data, (UINT *)lparam, wparam * sizeof(UINT) );
940 case WM_MDIGETACTIVE:
941 if (lparam) push_data( data, (BOOL *)lparam, sizeof(BOOL) );
945 push_data( data, (RECT *)lparam, sizeof(RECT) );
948 NCCALCSIZE_PARAMS *nc = (NCCALCSIZE_PARAMS *)lparam;
949 push_data( data, nc, sizeof(*nc) );
950 push_data( data, nc->lppos, sizeof(*nc->lppos) );
956 if (wparam) push_data( data, (DWORD *)wparam, sizeof(DWORD) );
957 if (lparam) push_data( data, (DWORD *)lparam, sizeof(DWORD) );
960 push_data( data, (MDINEXTMENU *)lparam, sizeof(MDINEXTMENU) );
963 push_data( data, (MDICREATESTRUCTW *)lparam, sizeof(MDICREATESTRUCTW) );
965 case WM_ASKCBFORMATNAME:
966 push_data( data, (WCHAR *)lparam, (strlenW((WCHAR *)lparam) + 1) * sizeof(WCHAR) );
972 /***********************************************************************
975 * Unpack a message reply received from another process.
977 static void unpack_reply( HWND hwnd, UINT message, WPARAM wparam, LPARAM lparam,
978 void *buffer, size_t size )
985 CREATESTRUCTW *cs = (CREATESTRUCTW *)lparam;
986 LPCWSTR name = cs->lpszName, class = cs->lpszClass;
987 memcpy( cs, buffer, min( sizeof(*cs), size ));
988 cs->lpszName = name; /* restore the original pointers */
989 cs->lpszClass = class;
993 case WM_ASKCBFORMATNAME:
994 memcpy( (WCHAR *)lparam, buffer, min( wparam*sizeof(WCHAR), size ));
996 case WM_GETMINMAXINFO:
997 memcpy( (MINMAXINFO *)lparam, buffer, min( sizeof(MINMAXINFO), size ));
1000 memcpy( (MEASUREITEMSTRUCT *)lparam, buffer, min( sizeof(MEASUREITEMSTRUCT), size ));
1002 case WM_WINDOWPOSCHANGING:
1003 case WM_WINDOWPOSCHANGED:
1004 memcpy( (WINDOWPOS *)lparam, buffer, min( sizeof(WINDOWPOS), size ));
1007 if (lparam) memcpy( (MSG *)lparam, buffer, min( sizeof(MSG), size ));
1009 case SBM_GETSCROLLINFO:
1010 memcpy( (SCROLLINFO *)lparam, buffer, min( sizeof(SCROLLINFO), size ));
1012 case SBM_GETSCROLLBARINFO:
1013 memcpy( (SCROLLBARINFO *)lparam, buffer, min( sizeof(SCROLLBARINFO), size ));
1016 case CB_GETDROPPEDCONTROLRECT:
1017 case LB_GETITEMRECT:
1020 memcpy( (RECT *)lparam, buffer, min( sizeof(RECT), size ));
1023 size = min( size, (size_t)*(WORD *)lparam );
1024 memcpy( (WCHAR *)lparam, buffer, size );
1026 case LB_GETSELITEMS:
1027 memcpy( (UINT *)lparam, buffer, min( wparam*sizeof(UINT), size ));
1031 memcpy( (WCHAR *)lparam, buffer, size );
1034 memcpy( (MDINEXTMENU *)lparam, buffer, min( sizeof(MDINEXTMENU), size ));
1036 case WM_MDIGETACTIVE:
1037 if (lparam) memcpy( (BOOL *)lparam, buffer, min( sizeof(BOOL), size ));
1041 memcpy( (RECT *)lparam, buffer, min( sizeof(RECT), size ));
1044 NCCALCSIZE_PARAMS *nc = (NCCALCSIZE_PARAMS *)lparam;
1045 WINDOWPOS *wp = nc->lppos;
1046 memcpy( nc, buffer, min( sizeof(*nc), size ));
1047 if (size > sizeof(*nc))
1049 size -= sizeof(*nc);
1050 memcpy( wp, (NCCALCSIZE_PARAMS*)buffer + 1, min( sizeof(*wp), size ));
1052 nc->lppos = wp; /* restore the original pointer */
1060 memcpy( (DWORD *)wparam, buffer, min( sizeof(DWORD), size ));
1061 if (size <= sizeof(DWORD)) break;
1062 size -= sizeof(DWORD);
1063 buffer = (DWORD *)buffer + 1;
1065 if (lparam) memcpy( (DWORD *)lparam, buffer, min( sizeof(DWORD), size ));
1069 MDICREATESTRUCTW *cs = (MDICREATESTRUCTW *)lparam;
1070 LPCWSTR title = cs->szTitle, class = cs->szClass;
1071 memcpy( cs, buffer, min( sizeof(*cs), size ));
1072 cs->szTitle = title; /* restore the original pointers */
1073 cs->szClass = class;
1077 ERR( "should not happen: unexpected message %x\n", message );
1083 /***********************************************************************
1086 * Send a reply to a sent message.
1088 static void reply_message( struct received_message_info *info, LRESULT result, BOOL remove )
1090 struct packed_message data;
1091 int i, replied = info->flags & ISMEX_REPLIED;
1093 if (info->flags & ISMEX_NOTIFY) return; /* notify messages don't get replies */
1094 if (!remove && replied) return; /* replied already */
1097 info->flags |= ISMEX_REPLIED;
1099 if (info->type == MSG_OTHER_PROCESS && !replied)
1101 pack_reply( info->msg.hwnd, info->msg.message, info->msg.wParam,
1102 info->msg.lParam, result, &data );
1105 SERVER_START_REQ( reply_message )
1107 req->type = info->type;
1108 req->result = result;
1109 req->remove = remove;
1110 for (i = 0; i < data.count; i++) wine_server_add_data( req, data.data[i], data.size[i] );
1111 wine_server_call( req );
1117 /***********************************************************************
1118 * handle_internal_message
1120 * Handle an internal Wine message instead of calling the window proc.
1122 static LRESULT handle_internal_message( HWND hwnd, UINT msg, WPARAM wparam, LPARAM lparam )
1124 if (hwnd == GetDesktopWindow()) return 0;
1127 case WM_WINE_DESTROYWINDOW:
1128 return WIN_DestroyWindow( hwnd );
1129 case WM_WINE_SETWINDOWPOS:
1130 if (USER_Driver.pSetWindowPos)
1131 return USER_Driver.pSetWindowPos( (WINDOWPOS *)lparam );
1133 case WM_WINE_SHOWWINDOW:
1134 return ShowWindow( hwnd, wparam );
1135 case WM_WINE_SETPARENT:
1136 return (LRESULT)SetParent( hwnd, (HWND)wparam );
1137 case WM_WINE_SETWINDOWLONG:
1138 return (LRESULT)SetWindowLongW( hwnd, wparam, lparam );
1139 case WM_WINE_ENABLEWINDOW:
1140 return EnableWindow( hwnd, wparam );
1141 case WM_WINE_SETACTIVEWINDOW:
1142 return (LRESULT)SetActiveWindow( (HWND)wparam );
1143 case WM_WINE_KEYBOARD_LL_HOOK:
1144 return HOOK_CallHooks( WH_KEYBOARD_LL, HC_ACTION, wparam, lparam, TRUE );
1145 case WM_WINE_MOUSE_LL_HOOK:
1146 return HOOK_CallHooks( WH_MOUSE_LL, HC_ACTION, wparam, lparam, TRUE );
1148 FIXME( "unknown internal message %x\n", msg );
1153 /* since the WM_DDE_ACK response to a WM_DDE_EXECUTE message should contain the handle
1154 * to the memory handle, we keep track (in the server side) of all pairs of handle
1155 * used (the client passes its value and the content of the memory handle), and
1156 * the server stored both values (the client, and the local one, created after the
1157 * content). When a ACK message is generated, the list of pair is searched for a
1158 * matching pair, so that the client memory handle can be returned.
1161 HGLOBAL client_hMem;
1162 HGLOBAL server_hMem;
1165 static struct DDE_pair* dde_pairs;
1166 static int dde_num_alloc;
1167 static int dde_num_used;
1169 static CRITICAL_SECTION dde_crst;
1170 static CRITICAL_SECTION_DEBUG critsect_debug =
1173 { &critsect_debug.ProcessLocksList, &critsect_debug.ProcessLocksList },
1174 0, 0, { 0, (DWORD)(__FILE__ ": dde_crst") }
1176 static CRITICAL_SECTION dde_crst = { &critsect_debug, -1, 0, 0, 0, 0 };
1178 static BOOL dde_add_pair(HGLOBAL chm, HGLOBAL shm)
1183 EnterCriticalSection(&dde_crst);
1185 /* now remember the pair of hMem on both sides */
1186 if (dde_num_used == dde_num_alloc)
1188 struct DDE_pair* tmp;
1190 tmp = HeapReAlloc( GetProcessHeap(), 0, dde_pairs,
1191 (dde_num_alloc + GROWBY) * sizeof(struct DDE_pair));
1193 tmp = HeapAlloc( GetProcessHeap(), 0,
1194 (dde_num_alloc + GROWBY) * sizeof(struct DDE_pair));
1198 LeaveCriticalSection(&dde_crst);
1202 /* zero out newly allocated part */
1203 memset(&dde_pairs[dde_num_alloc], 0, GROWBY * sizeof(struct DDE_pair));
1204 dde_num_alloc += GROWBY;
1207 for (i = 0; i < dde_num_alloc; i++)
1209 if (dde_pairs[i].server_hMem == 0)
1211 dde_pairs[i].client_hMem = chm;
1212 dde_pairs[i].server_hMem = shm;
1217 LeaveCriticalSection(&dde_crst);
1221 static HGLOBAL dde_get_pair(HGLOBAL shm)
1226 EnterCriticalSection(&dde_crst);
1227 for (i = 0; i < dde_num_alloc; i++)
1229 if (dde_pairs[i].server_hMem == shm)
1231 /* free this pair */
1232 dde_pairs[i].server_hMem = 0;
1234 ret = dde_pairs[i].client_hMem;
1238 LeaveCriticalSection(&dde_crst);
1242 /***********************************************************************
1245 * Post a DDE message
1247 static BOOL post_dde_message( DWORD dest_tid, struct packed_message *data, const struct send_message_info *info )
1253 HGLOBAL hunlock = 0;
1257 if (!UnpackDDElParam( info->msg, info->lparam, &uiLo, &uiHi ))
1263 /* DDE messages which don't require packing are:
1272 /* uiHi should contain a hMem from WM_DDE_EXECUTE */
1273 HGLOBAL h = dde_get_pair( (HANDLE)uiHi );
1276 /* send back the value of h on the other side */
1277 push_data( data, &h, sizeof(HGLOBAL) );
1279 TRACE( "send dde-ack %x %08x => %08lx\n", uiLo, uiHi, (DWORD)h );
1284 /* uiHi should contain either an atom or 0 */
1285 TRACE( "send dde-ack %x atom=%x\n", uiLo, uiHi );
1286 lp = MAKELONG( uiLo, uiHi );
1295 size = GlobalSize( (HGLOBAL)uiLo ) ;
1296 if ((info->msg == WM_DDE_ADVISE && size < sizeof(DDEADVISE)) ||
1297 (info->msg == WM_DDE_DATA && size < sizeof(DDEDATA)) ||
1298 (info->msg == WM_DDE_POKE && size < sizeof(DDEPOKE))
1302 else if (info->msg != WM_DDE_DATA) return FALSE;
1307 if ((ptr = GlobalLock( (HGLOBAL)uiLo) ))
1309 DDEDATA *dde_data = (DDEDATA *)ptr;
1310 TRACE("unused %d, fResponse %d, fRelease %d, fDeferUpd %d, fAckReq %d, cfFormat %d\n",
1311 dde_data->unused, dde_data->fResponse, dde_data->fRelease,
1312 dde_data->reserved, dde_data->fAckReq, dde_data->cfFormat);
1313 push_data( data, ptr, size );
1314 hunlock = (HGLOBAL)uiLo;
1317 TRACE( "send ddepack %u %x\n", size, uiHi );
1319 case WM_DDE_EXECUTE:
1322 if ((ptr = GlobalLock( (HGLOBAL)info->lparam) ))
1324 push_data(data, ptr, GlobalSize( (HGLOBAL)info->lparam ));
1325 /* so that the other side can send it back on ACK */
1327 hunlock = (HGLOBAL)info->lparam;
1332 SERVER_START_REQ( send_message )
1335 req->type = info->type;
1337 req->win = info->hwnd;
1338 req->msg = info->msg;
1339 req->wparam = info->wparam;
1341 req->time = GetCurrentTime();
1343 for (i = 0; i < data->count; i++)
1344 wine_server_add_data( req, data->data[i], data->size[i] );
1345 if ((res = wine_server_call( req )))
1347 if (res == STATUS_INVALID_PARAMETER)
1348 /* FIXME: find a STATUS_ value for this one */
1349 SetLastError( ERROR_INVALID_THREAD_ID );
1351 SetLastError( RtlNtStatusToDosError(res) );
1354 FreeDDElParam(info->msg, info->lparam);
1357 if (hunlock) GlobalUnlock(hunlock);
1362 /***********************************************************************
1363 * unpack_dde_message
1365 * Unpack a posted DDE message received from another process.
1367 static BOOL unpack_dde_message( HWND hwnd, UINT message, WPARAM *wparam, LPARAM *lparam,
1368 void **buffer, size_t size )
1379 /* hMem is being passed */
1380 if (size != sizeof(HGLOBAL)) return FALSE;
1381 if (!buffer || !*buffer) return FALSE;
1383 memcpy( &hMem, *buffer, size );
1385 TRACE("recv dde-ack %x mem=%x[%lx]\n", uiLo, uiHi, GlobalSize( hMem ));
1389 uiLo = LOWORD( *lparam );
1390 uiHi = HIWORD( *lparam );
1391 TRACE("recv dde-ack %x atom=%x\n", uiLo, uiHi);
1393 *lparam = PackDDElParam( WM_DDE_ACK, uiLo, uiHi );
1398 if ((!buffer || !*buffer) && message != WM_DDE_DATA) return FALSE;
1400 TRACE( "recv ddepack %u %x\n", size, uiHi );
1403 hMem = GlobalAlloc( GMEM_MOVEABLE|GMEM_DDESHARE, size );
1404 if (hMem && (ptr = GlobalLock( hMem )))
1406 memcpy( ptr, *buffer, size );
1407 GlobalUnlock( hMem );
1413 *lparam = PackDDElParam( message, uiLo, uiHi );
1415 case WM_DDE_EXECUTE:
1418 if (!buffer || !*buffer) return FALSE;
1419 hMem = GlobalAlloc( GMEM_MOVEABLE|GMEM_DDESHARE, size );
1420 if (hMem && (ptr = GlobalLock( hMem )))
1422 memcpy( ptr, *buffer, size );
1423 GlobalUnlock( hMem );
1424 TRACE( "exec: pairing c=%08lx s=%08lx\n", *lparam, (DWORD)hMem );
1425 if (!dde_add_pair( (HGLOBAL)*lparam, hMem ))
1431 } else return FALSE;
1432 *lparam = (LPARAM)hMem;
1438 /***********************************************************************
1441 * Call a window procedure and the corresponding hooks.
1443 static LRESULT call_window_proc( HWND hwnd, UINT msg, WPARAM wparam, LPARAM lparam,
1444 BOOL unicode, BOOL same_thread )
1449 CWPRETSTRUCT cwpret;
1450 MESSAGEQUEUE *queue = QUEUE_Current();
1452 if (queue->recursion_count > MAX_SENDMSG_RECURSION) return 0;
1453 queue->recursion_count++;
1455 if (msg & 0x80000000)
1457 result = handle_internal_message( hwnd, msg, wparam, lparam );
1461 /* first the WH_CALLWNDPROC hook */
1462 hwnd = WIN_GetFullHandle( hwnd );
1463 cwp.lParam = lparam;
1464 cwp.wParam = wparam;
1467 HOOK_CallHooks( WH_CALLWNDPROC, HC_ACTION, same_thread, (LPARAM)&cwp, unicode );
1469 /* now call the window procedure */
1472 if (!(winproc = (WNDPROC)GetWindowLongPtrW( hwnd, GWLP_WNDPROC ))) goto done;
1473 result = CallWindowProcW( winproc, hwnd, msg, wparam, lparam );
1477 if (!(winproc = (WNDPROC)GetWindowLongPtrA( hwnd, GWLP_WNDPROC ))) goto done;
1478 result = CallWindowProcA( winproc, hwnd, msg, wparam, lparam );
1481 /* and finally the WH_CALLWNDPROCRET hook */
1482 cwpret.lResult = result;
1483 cwpret.lParam = lparam;
1484 cwpret.wParam = wparam;
1485 cwpret.message = msg;
1487 HOOK_CallHooks( WH_CALLWNDPROCRET, HC_ACTION, same_thread, (LPARAM)&cwpret, unicode );
1489 queue->recursion_count--;
1494 /***********************************************************************
1495 * process_hardware_message
1497 * Process a hardware message; return TRUE if message should be passed on to the app
1499 static BOOL process_hardware_message( MSG *msg, ULONG_PTR extra_info, HWND hwnd,
1500 UINT first, UINT last, BOOL remove )
1504 if (!MSG_process_raw_hardware_message( msg, extra_info, hwnd, first, last, remove ))
1507 ret = MSG_process_cooked_hardware_message( msg, extra_info, remove );
1509 /* tell the server we have passed it to the app
1510 * (even though we may end up dropping it later on)
1512 SERVER_START_REQ( reply_message )
1514 req->type = MSG_HARDWARE;
1516 req->remove = remove || !ret;
1517 wine_server_call( req );
1524 /***********************************************************************
1525 * call_sendmsg_callback
1527 * Call the callback function of SendMessageCallback.
1529 static inline void call_sendmsg_callback( SENDASYNCPROC callback, HWND hwnd, UINT msg,
1530 ULONG_PTR data, LRESULT result )
1532 if (TRACE_ON(relay))
1533 DPRINTF( "%04lx:Call message callback %p (hwnd=%p,msg=%s,data=%08lx,result=%08lx)\n",
1534 GetCurrentThreadId(), callback, hwnd, SPY_GetMsgName( msg, hwnd ),
1536 callback( hwnd, msg, data, result );
1537 if (TRACE_ON(relay))
1538 DPRINTF( "%04lx:Ret message callback %p (hwnd=%p,msg=%s,data=%08lx,result=%08lx)\n",
1539 GetCurrentThreadId(), callback, hwnd, SPY_GetMsgName( msg, hwnd ),
1544 /***********************************************************************
1547 * Peek for a message matching the given parameters. Return FALSE if none available.
1548 * All pending sent messages are processed before returning.
1550 BOOL MSG_peek_message( MSG *msg, HWND hwnd, UINT first, UINT last, int flags )
1553 ULONG_PTR extra_info = 0;
1554 MESSAGEQUEUE *queue = QUEUE_Current();
1555 struct received_message_info info, *old_info;
1557 if (!first && !last) last = ~0;
1562 void *buffer = NULL;
1563 size_t size = 0, buffer_size = 0;
1565 do /* loop while buffer is too small */
1567 if (buffer_size && !(buffer = HeapAlloc( GetProcessHeap(), 0, buffer_size )))
1569 SERVER_START_REQ( get_message )
1572 req->get_win = hwnd;
1573 req->get_first = first;
1574 req->get_last = last;
1575 if (buffer_size) wine_server_set_reply( req, buffer, buffer_size );
1576 if (!(res = wine_server_call( req )))
1578 size = wine_server_reply_size( reply );
1579 info.type = reply->type;
1580 info.msg.hwnd = reply->win;
1581 info.msg.message = reply->msg;
1582 info.msg.wParam = reply->wparam;
1583 info.msg.lParam = reply->lparam;
1584 info.msg.time = reply->time;
1585 info.msg.pt.x = reply->x;
1586 info.msg.pt.y = reply->y;
1587 extra_info = reply->info;
1591 HeapFree( GetProcessHeap(), 0, buffer );
1592 buffer_size = reply->total;
1596 } while (res == STATUS_BUFFER_OVERFLOW);
1598 if (res) return FALSE;
1600 TRACE( "got type %d msg %x (%s) hwnd %p wp %x lp %lx\n",
1601 info.type, info.msg.message, SPY_GetMsgName(info.msg.message, info.msg.hwnd),
1602 info.msg.hwnd, info.msg.wParam, info.msg.lParam );
1608 info.flags = ISMEX_SEND;
1611 info.flags = ISMEX_NOTIFY;
1614 info.flags = ISMEX_CALLBACK;
1616 case MSG_CALLBACK_RESULT:
1617 call_sendmsg_callback( (SENDASYNCPROC)info.msg.wParam, info.msg.hwnd,
1618 info.msg.message, extra_info, info.msg.lParam );
1620 case MSG_OTHER_PROCESS:
1621 info.flags = ISMEX_SEND;
1622 if (!unpack_message( info.msg.hwnd, info.msg.message, &info.msg.wParam,
1623 &info.msg.lParam, &buffer, size ))
1625 ERR( "invalid packed message %x (%s) hwnd %p wp %x lp %lx size %d\n",
1626 info.msg.message, SPY_GetMsgName(info.msg.message, info.msg.hwnd), info.msg.hwnd,
1627 info.msg.wParam, info.msg.lParam, size );
1629 reply_message( &info, 0, TRUE );
1634 if (!process_hardware_message( &info.msg, extra_info,
1635 hwnd, first, last, flags & GET_MSG_REMOVE ))
1637 TRACE("dropping msg %x\n", info.msg.message );
1638 goto next; /* ignore it */
1640 queue->GetMessagePosVal = MAKELONG( info.msg.pt.x, info.msg.pt.y );
1643 queue->GetMessageExtraInfoVal = extra_info;
1644 if (info.msg.message >= WM_DDE_FIRST && info.msg.message <= WM_DDE_LAST)
1646 if (!unpack_dde_message( info.msg.hwnd, info.msg.message, &info.msg.wParam,
1647 &info.msg.lParam, &buffer, size ))
1649 ERR( "invalid packed dde-message %x (%s) hwnd %p wp %x lp %lx size %d\n",
1650 info.msg.message, SPY_GetMsgName(info.msg.message, info.msg.hwnd),
1651 info.msg.hwnd, info.msg.wParam, info.msg.lParam, size );
1652 goto next; /* ignore it */
1656 HeapFree( GetProcessHeap(), 0, buffer );
1660 /* if we get here, we have a sent message; call the window procedure */
1661 old_info = queue->receive_info;
1662 queue->receive_info = &info;
1663 result = call_window_proc( info.msg.hwnd, info.msg.message, info.msg.wParam,
1664 info.msg.lParam, (info.type != MSG_ASCII), FALSE );
1665 reply_message( &info, result, TRUE );
1666 queue->receive_info = old_info;
1668 HeapFree( GetProcessHeap(), 0, buffer );
1673 /***********************************************************************
1674 * wait_message_reply
1676 * Wait until a sent message gets replied to.
1678 static void wait_message_reply( UINT flags )
1680 MESSAGEQUEUE *queue;
1682 if (!(queue = QUEUE_Current())) return;
1686 unsigned int wake_bits = 0, changed_bits = 0;
1689 SERVER_START_REQ( set_queue_mask )
1691 req->wake_mask = QS_SMRESULT | ((flags & SMTO_BLOCK) ? 0 : QS_SENDMESSAGE);
1692 req->changed_mask = req->wake_mask;
1694 if (!wine_server_call( req ))
1696 wake_bits = reply->wake_bits;
1697 changed_bits = reply->changed_bits;
1702 if (wake_bits & QS_SMRESULT) return; /* got a result */
1703 if (wake_bits & QS_SENDMESSAGE)
1705 /* Process the sent message immediately */
1707 MSG_peek_message( &msg, 0, 0, 0, GET_MSG_REMOVE | GET_MSG_SENT_ONLY );
1711 /* now wait for it */
1713 ReleaseThunkLock( &dwlc );
1715 if (USER_Driver.pMsgWaitForMultipleObjectsEx)
1716 res = USER_Driver.pMsgWaitForMultipleObjectsEx( 1, &queue->server_queue,
1719 res = WaitForSingleObject( queue->server_queue, INFINITE );
1721 if (dwlc) RestoreThunkLock( dwlc );
1725 /***********************************************************************
1726 * put_message_in_queue
1728 * Put a sent message into the destination queue.
1729 * For inter-process message, reply_size is set to expected size of reply data.
1731 static BOOL put_message_in_queue( DWORD dest_tid, const struct send_message_info *info,
1732 size_t *reply_size )
1734 struct packed_message data;
1736 int i, timeout = -1;
1738 if (info->type != MSG_NOTIFY &&
1739 info->type != MSG_CALLBACK &&
1740 info->type != MSG_POSTED &&
1741 info->timeout != INFINITE)
1742 timeout = info->timeout;
1745 if (info->type == MSG_OTHER_PROCESS)
1747 *reply_size = pack_message( info->hwnd, info->msg, info->wparam, info->lparam, &data );
1748 if (data.count == -1)
1750 WARN( "cannot pack message %x\n", info->msg );
1754 else if (info->type == MSG_POSTED && info->msg >= WM_DDE_FIRST && info->msg <= WM_DDE_LAST)
1756 return post_dde_message( dest_tid, &data, info );
1759 SERVER_START_REQ( send_message )
1762 req->type = info->type;
1764 req->win = info->hwnd;
1765 req->msg = info->msg;
1766 req->wparam = info->wparam;
1767 req->lparam = info->lparam;
1768 req->time = GetCurrentTime();
1769 req->timeout = timeout;
1771 if (info->type == MSG_CALLBACK)
1773 req->callback = info->callback;
1774 req->info = info->data;
1777 if (info->flags & SMTO_ABORTIFHUNG) req->flags |= SEND_MSG_ABORT_IF_HUNG;
1778 for (i = 0; i < data.count; i++) wine_server_add_data( req, data.data[i], data.size[i] );
1779 if ((res = wine_server_call( req )))
1781 if (res == STATUS_INVALID_PARAMETER)
1782 /* FIXME: find a STATUS_ value for this one */
1783 SetLastError( ERROR_INVALID_THREAD_ID );
1785 SetLastError( RtlNtStatusToDosError(res) );
1793 /***********************************************************************
1796 * Retrieve a message reply from the server.
1798 static LRESULT retrieve_reply( const struct send_message_info *info,
1799 size_t reply_size, LRESULT *result )
1802 void *reply_data = NULL;
1806 if (!(reply_data = HeapAlloc( GetProcessHeap(), 0, reply_size )))
1808 WARN( "no memory for reply %d bytes, will be truncated\n", reply_size );
1812 SERVER_START_REQ( get_message_reply )
1815 if (reply_size) wine_server_set_reply( req, reply_data, reply_size );
1816 if (!(status = wine_server_call( req ))) *result = reply->result;
1817 reply_size = wine_server_reply_size( reply );
1820 if (!status && reply_size)
1821 unpack_reply( info->hwnd, info->msg, info->wparam, info->lparam, reply_data, reply_size );
1823 HeapFree( GetProcessHeap(), 0, reply_data );
1825 TRACE( "hwnd %p msg %x (%s) wp %x lp %lx got reply %lx (err=%ld)\n",
1826 info->hwnd, info->msg, SPY_GetMsgName(info->msg, info->hwnd), info->wparam,
1827 info->lparam, *result, status );
1829 /* MSDN states that last error is 0 on timeout, but at least NT4 returns ERROR_TIMEOUT */
1830 if (status) SetLastError( RtlNtStatusToDosError(status) );
1835 /***********************************************************************
1836 * send_inter_thread_message
1838 static LRESULT send_inter_thread_message( DWORD dest_tid, const struct send_message_info *info,
1843 size_t reply_size = 0;
1845 TRACE( "hwnd %p msg %x (%s) wp %x lp %lx\n",
1846 info->hwnd, info->msg, SPY_GetMsgName(info->msg, info->hwnd), info->wparam, info->lparam );
1848 if (!put_message_in_queue( dest_tid, info, &reply_size )) return 0;
1850 /* there's no reply to wait for on notify/callback messages */
1851 if (info->type == MSG_NOTIFY || info->type == MSG_CALLBACK) return 1;
1853 locks = WIN_SuspendWndsLock();
1855 wait_message_reply( info->flags );
1856 ret = retrieve_reply( info, reply_size, res_ptr );
1858 WIN_RestoreWndsLock( locks );
1863 /***********************************************************************
1864 * MSG_SendInternalMessageTimeout
1866 * Same as SendMessageTimeoutW but sends the message to a specific thread
1867 * without requiring a window handle. Only works for internal Wine messages.
1869 LRESULT MSG_SendInternalMessageTimeout( DWORD dest_pid, DWORD dest_tid,
1870 UINT msg, WPARAM wparam, LPARAM lparam,
1871 UINT flags, UINT timeout, PDWORD_PTR res_ptr )
1873 struct send_message_info info;
1874 LRESULT ret, result;
1876 assert( msg & 0x80000000 ); /* must be an internal Wine message */
1878 info.type = MSG_UNICODE;
1881 info.wparam = wparam;
1882 info.lparam = lparam;
1884 info.timeout = timeout;
1886 if (USER_IsExitingThread( dest_tid )) return 0;
1888 if (dest_tid == GetCurrentThreadId())
1890 result = handle_internal_message( 0, msg, wparam, lparam );
1895 if (dest_pid != GetCurrentProcessId()) info.type = MSG_OTHER_PROCESS;
1896 ret = send_inter_thread_message( dest_tid, &info, &result );
1898 if (ret && res_ptr) *res_ptr = result;
1903 /***********************************************************************
1904 * SendMessageTimeoutW (USER32.@)
1906 LRESULT WINAPI SendMessageTimeoutW( HWND hwnd, UINT msg, WPARAM wparam, LPARAM lparam,
1907 UINT flags, UINT timeout, PDWORD_PTR res_ptr )
1909 struct send_message_info info;
1910 DWORD dest_tid, dest_pid;
1911 LRESULT ret, result;
1913 info.type = MSG_UNICODE;
1916 info.wparam = wparam;
1917 info.lparam = lparam;
1919 info.timeout = timeout;
1921 if (is_broadcast(hwnd))
1923 EnumWindows( broadcast_message_callback, (LPARAM)&info );
1924 if (res_ptr) *res_ptr = 1;
1928 if (!(dest_tid = GetWindowThreadProcessId( hwnd, &dest_pid ))) return 0;
1930 if (USER_IsExitingThread( dest_tid )) return 0;
1932 SPY_EnterMessage( SPY_SENDMESSAGE, hwnd, msg, wparam, lparam );
1934 if (dest_tid == GetCurrentThreadId())
1936 result = call_window_proc( hwnd, msg, wparam, lparam, TRUE, TRUE );
1941 if (dest_pid != GetCurrentProcessId()) info.type = MSG_OTHER_PROCESS;
1942 ret = send_inter_thread_message( dest_tid, &info, &result );
1945 SPY_ExitMessage( SPY_RESULT_OK, hwnd, msg, result, wparam, lparam );
1946 if (ret && res_ptr) *res_ptr = result;
1951 /***********************************************************************
1952 * SendMessageTimeoutA (USER32.@)
1954 LRESULT WINAPI SendMessageTimeoutA( HWND hwnd, UINT msg, WPARAM wparam, LPARAM lparam,
1955 UINT flags, UINT timeout, PDWORD_PTR res_ptr )
1957 struct send_message_info info;
1958 DWORD dest_tid, dest_pid;
1959 LRESULT ret, result;
1961 info.type = MSG_ASCII;
1964 info.wparam = wparam;
1965 info.lparam = lparam;
1967 info.timeout = timeout;
1969 if (is_broadcast(hwnd))
1971 EnumWindows( broadcast_message_callback, (LPARAM)&info );
1972 if (res_ptr) *res_ptr = 1;
1976 if (!(dest_tid = GetWindowThreadProcessId( hwnd, &dest_pid ))) return 0;
1978 if (USER_IsExitingThread( dest_tid )) return 0;
1980 SPY_EnterMessage( SPY_SENDMESSAGE, hwnd, msg, wparam, lparam );
1982 if (dest_tid == GetCurrentThreadId())
1984 result = call_window_proc( hwnd, msg, wparam, lparam, FALSE, TRUE );
1987 else if (dest_pid == GetCurrentProcessId())
1989 ret = send_inter_thread_message( dest_tid, &info, &result );
1993 /* inter-process message: need to map to Unicode */
1994 info.type = MSG_OTHER_PROCESS;
1995 if (is_unicode_message( info.msg ))
1997 if (WINPROC_MapMsg32ATo32W( info.hwnd, info.msg, &info.wparam, &info.lparam ) == -1)
1999 ret = send_inter_thread_message( dest_tid, &info, &result );
2000 result = WINPROC_UnmapMsg32ATo32W( info.hwnd, info.msg, info.wparam,
2001 info.lparam, result );
2003 else ret = send_inter_thread_message( dest_tid, &info, &result );
2005 SPY_ExitMessage( SPY_RESULT_OK, hwnd, msg, result, wparam, lparam );
2006 if (ret && res_ptr) *res_ptr = result;
2011 /***********************************************************************
2012 * SendMessageW (USER32.@)
2014 LRESULT WINAPI SendMessageW( HWND hwnd, UINT msg, WPARAM wparam, LPARAM lparam )
2017 SendMessageTimeoutW( hwnd, msg, wparam, lparam, SMTO_NORMAL, INFINITE, &res );
2022 /***********************************************************************
2023 * SendMessageA (USER32.@)
2025 LRESULT WINAPI SendMessageA( HWND hwnd, UINT msg, WPARAM wparam, LPARAM lparam )
2028 SendMessageTimeoutA( hwnd, msg, wparam, lparam, SMTO_NORMAL, INFINITE, &res );
2033 /***********************************************************************
2034 * SendNotifyMessageA (USER32.@)
2036 BOOL WINAPI SendNotifyMessageA( HWND hwnd, UINT msg, WPARAM wparam, LPARAM lparam )
2038 return SendNotifyMessageW( hwnd, msg, map_wparam_AtoW( msg, wparam ), lparam );
2042 /***********************************************************************
2043 * SendNotifyMessageW (USER32.@)
2045 BOOL WINAPI SendNotifyMessageW( HWND hwnd, UINT msg, WPARAM wparam, LPARAM lparam )
2047 struct send_message_info info;
2051 if (is_pointer_message(msg))
2053 SetLastError( ERROR_MESSAGE_SYNC_ONLY );
2057 info.type = MSG_NOTIFY;
2060 info.wparam = wparam;
2061 info.lparam = lparam;
2064 if (is_broadcast(hwnd))
2066 EnumWindows( broadcast_message_callback, (LPARAM)&info );
2070 if (!(dest_tid = GetWindowThreadProcessId( hwnd, NULL ))) return FALSE;
2072 if (USER_IsExitingThread( dest_tid )) return TRUE;
2074 if (dest_tid == GetCurrentThreadId())
2076 call_window_proc( hwnd, msg, wparam, lparam, TRUE, TRUE );
2079 return send_inter_thread_message( dest_tid, &info, &result );
2083 /***********************************************************************
2084 * SendMessageCallbackA (USER32.@)
2086 BOOL WINAPI SendMessageCallbackA( HWND hwnd, UINT msg, WPARAM wparam, LPARAM lparam,
2087 SENDASYNCPROC callback, ULONG_PTR data )
2089 return SendMessageCallbackW( hwnd, msg, map_wparam_AtoW( msg, wparam ),
2090 lparam, callback, data );
2094 /***********************************************************************
2095 * SendMessageCallbackW (USER32.@)
2097 BOOL WINAPI SendMessageCallbackW( HWND hwnd, UINT msg, WPARAM wparam, LPARAM lparam,
2098 SENDASYNCPROC callback, ULONG_PTR data )
2100 struct send_message_info info;
2104 if (is_pointer_message(msg))
2106 SetLastError( ERROR_MESSAGE_SYNC_ONLY );
2110 info.type = MSG_CALLBACK;
2113 info.wparam = wparam;
2114 info.lparam = lparam;
2115 info.callback = callback;
2119 if (is_broadcast(hwnd))
2121 EnumWindows( broadcast_message_callback, (LPARAM)&info );
2125 if (!(dest_tid = GetWindowThreadProcessId( hwnd, NULL ))) return FALSE;
2127 if (USER_IsExitingThread( dest_tid )) return TRUE;
2129 if (dest_tid == GetCurrentThreadId())
2131 result = call_window_proc( hwnd, msg, wparam, lparam, TRUE, TRUE );
2132 call_sendmsg_callback( callback, hwnd, msg, data, result );
2135 FIXME( "callback will not be called\n" );
2136 return send_inter_thread_message( dest_tid, &info, &result );
2140 /***********************************************************************
2141 * ReplyMessage (USER32.@)
2143 BOOL WINAPI ReplyMessage( LRESULT result )
2145 MESSAGEQUEUE *queue = QUEUE_Current();
2146 struct received_message_info *info = queue->receive_info;
2148 if (!info) return FALSE;
2149 reply_message( info, result, FALSE );
2154 /***********************************************************************
2155 * InSendMessage (USER32.@)
2157 BOOL WINAPI InSendMessage(void)
2159 return (InSendMessageEx(NULL) & (ISMEX_SEND|ISMEX_REPLIED)) == ISMEX_SEND;
2163 /***********************************************************************
2164 * InSendMessageEx (USER32.@)
2166 DWORD WINAPI InSendMessageEx( LPVOID reserved )
2168 MESSAGEQUEUE *queue = QUEUE_Current();
2169 struct received_message_info *info = queue->receive_info;
2171 if (info) return info->flags;
2172 return ISMEX_NOSEND;
2176 /***********************************************************************
2177 * PostMessageA (USER32.@)
2179 BOOL WINAPI PostMessageA( HWND hwnd, UINT msg, WPARAM wparam, LPARAM lparam )
2181 return PostMessageW( hwnd, msg, map_wparam_AtoW( msg, wparam ), lparam );
2185 /***********************************************************************
2186 * PostMessageW (USER32.@)
2188 BOOL WINAPI PostMessageW( HWND hwnd, UINT msg, WPARAM wparam, LPARAM lparam )
2190 struct send_message_info info;
2193 if (is_pointer_message( msg ))
2195 SetLastError( ERROR_MESSAGE_SYNC_ONLY );
2199 TRACE( "hwnd %p msg %x (%s) wp %x lp %lx\n",
2200 hwnd, msg, SPY_GetMsgName(msg, hwnd), wparam, lparam );
2202 info.type = MSG_POSTED;
2205 info.wparam = wparam;
2206 info.lparam = lparam;
2209 if (is_broadcast(hwnd))
2211 EnumWindows( broadcast_message_callback, (LPARAM)&info );
2215 if (!hwnd) return PostThreadMessageW( GetCurrentThreadId(), msg, wparam, lparam );
2217 if (!(dest_tid = GetWindowThreadProcessId( hwnd, NULL ))) return FALSE;
2219 if (USER_IsExitingThread( dest_tid )) return TRUE;
2221 return put_message_in_queue( dest_tid, &info, NULL );
2225 /**********************************************************************
2226 * PostThreadMessageA (USER32.@)
2228 BOOL WINAPI PostThreadMessageA( DWORD thread, UINT msg, WPARAM wparam, LPARAM lparam )
2230 return PostThreadMessageW( thread, msg, map_wparam_AtoW( msg, wparam ), lparam );
2234 /**********************************************************************
2235 * PostThreadMessageW (USER32.@)
2237 BOOL WINAPI PostThreadMessageW( DWORD thread, UINT msg, WPARAM wparam, LPARAM lparam )
2239 struct send_message_info info;
2241 if (is_pointer_message( msg ))
2243 SetLastError( ERROR_MESSAGE_SYNC_ONLY );
2246 if (USER_IsExitingThread( thread )) return TRUE;
2248 info.type = MSG_POSTED;
2251 info.wparam = wparam;
2252 info.lparam = lparam;
2254 return put_message_in_queue( thread, &info, NULL );
2258 /***********************************************************************
2259 * PostQuitMessage (USER32.@)
2261 void WINAPI PostQuitMessage( INT exitCode )
2263 PostThreadMessageW( GetCurrentThreadId(), WM_QUIT, exitCode, 0 );
2267 /***********************************************************************
2268 * PeekMessageW (USER32.@)
2270 BOOL WINAPI PeekMessageW( MSG *msg_out, HWND hwnd, UINT first, UINT last, UINT flags )
2272 MESSAGEQUEUE *queue;
2276 /* check for graphics events */
2277 if (USER_Driver.pMsgWaitForMultipleObjectsEx)
2278 USER_Driver.pMsgWaitForMultipleObjectsEx( 0, NULL, 0, 0, 0 );
2280 hwnd = WIN_GetFullHandle( hwnd );
2281 locks = WIN_SuspendWndsLock();
2283 if (!MSG_peek_message( &msg, hwnd, first, last,
2284 (flags & PM_REMOVE) ? GET_MSG_REMOVE : 0 ))
2286 if (!(flags & PM_NOYIELD))
2289 ReleaseThunkLock(&count);
2290 if (count) RestoreThunkLock(count);
2292 WIN_RestoreWndsLock( locks );
2296 WIN_RestoreWndsLock( locks );
2298 if (msg.message == WM_PAINT) /* clear internal paint flag */
2299 RedrawWindow( msg.hwnd, NULL, 0, RDW_NOINTERNALPAINT | RDW_NOCHILDREN );
2301 if ((queue = QUEUE_Current()))
2303 queue->GetMessageTimeVal = msg.time;
2304 msg.pt.x = LOWORD( queue->GetMessagePosVal );
2305 msg.pt.y = HIWORD( queue->GetMessagePosVal );
2308 HOOK_CallHooks( WH_GETMESSAGE, HC_ACTION, flags & PM_REMOVE, (LPARAM)&msg, TRUE );
2310 /* copy back our internal safe copy of message data to msg_out.
2311 * msg_out is a variable from the *program*, so it can't be used
2312 * internally as it can get "corrupted" by our use of SendMessage()
2313 * (back to the program) inside the message handling itself. */
2316 SetLastError( ERROR_NOACCESS );
2324 /***********************************************************************
2325 * PeekMessageA (USER32.@)
2327 BOOL WINAPI PeekMessageA( MSG *msg, HWND hwnd, UINT first, UINT last, UINT flags )
2329 BOOL ret = PeekMessageW( msg, hwnd, first, last, flags );
2330 if (ret) msg->wParam = map_wparam_WtoA( msg->message, msg->wParam );
2335 /***********************************************************************
2336 * GetMessageW (USER32.@)
2338 BOOL WINAPI GetMessageW( MSG *msg, HWND hwnd, UINT first, UINT last )
2340 MESSAGEQUEUE *queue = QUEUE_Current();
2343 mask = QS_POSTMESSAGE | QS_SENDMESSAGE; /* Always selected */
2346 if ((first <= WM_KEYLAST) && (last >= WM_KEYFIRST)) mask |= QS_KEY;
2347 if ( ((first <= WM_MOUSELAST) && (last >= WM_MOUSEFIRST)) ||
2348 ((first <= WM_NCMOUSELAST) && (last >= WM_NCMOUSEFIRST)) ) mask |= QS_MOUSE;
2349 if ((first <= WM_TIMER) && (last >= WM_TIMER)) mask |= QS_TIMER;
2350 if ((first <= WM_SYSTIMER) && (last >= WM_SYSTIMER)) mask |= QS_TIMER;
2351 if ((first <= WM_PAINT) && (last >= WM_PAINT)) mask |= QS_PAINT;
2353 else mask |= QS_MOUSE | QS_KEY | QS_TIMER | QS_PAINT;
2355 locks = WIN_SuspendWndsLock();
2357 while (!PeekMessageW( msg, hwnd, first, last, PM_REMOVE ))
2359 /* wait until one of the bits is set */
2360 unsigned int wake_bits = 0, changed_bits = 0;
2363 SERVER_START_REQ( set_queue_mask )
2365 req->wake_mask = QS_SENDMESSAGE;
2366 req->changed_mask = mask;
2368 if (!wine_server_call( req ))
2370 wake_bits = reply->wake_bits;
2371 changed_bits = reply->changed_bits;
2376 if (changed_bits & mask) continue;
2377 if (wake_bits & QS_SENDMESSAGE) continue;
2379 TRACE( "(%04x) mask=%08x, bits=%08x, changed=%08x, waiting\n",
2380 queue->self, mask, wake_bits, changed_bits );
2382 ReleaseThunkLock( &dwlc );
2383 if (USER_Driver.pMsgWaitForMultipleObjectsEx)
2384 USER_Driver.pMsgWaitForMultipleObjectsEx( 1, &queue->server_queue, INFINITE, 0, 0 );
2386 WaitForSingleObject( queue->server_queue, INFINITE );
2387 if (dwlc) RestoreThunkLock( dwlc );
2390 WIN_RestoreWndsLock( locks );
2392 return (msg->message != WM_QUIT);
2396 /***********************************************************************
2397 * GetMessageA (USER32.@)
2399 BOOL WINAPI GetMessageA( MSG *msg, HWND hwnd, UINT first, UINT last )
2401 GetMessageW( msg, hwnd, first, last );
2402 msg->wParam = map_wparam_WtoA( msg->message, msg->wParam );
2403 return (msg->message != WM_QUIT);
2407 /***********************************************************************
2408 * IsDialogMessage (USER32.@)
2409 * IsDialogMessageA (USER32.@)
2411 BOOL WINAPI IsDialogMessageA( HWND hwndDlg, LPMSG pmsg )
2414 msg.wParam = map_wparam_AtoW( msg.message, msg.wParam );
2415 return IsDialogMessageW( hwndDlg, &msg );
2419 /***********************************************************************
2420 * SetMessageQueue (USER32.@)
2422 BOOL WINAPI SetMessageQueue( INT size )
2424 /* now obsolete the message queue will be expanded dynamically as necessary */
2429 /***********************************************************************
2430 * MessageBeep (USER32.@)
2432 BOOL WINAPI MessageBeep( UINT i )
2435 SystemParametersInfoA( SPI_GETBEEP, 0, &active, FALSE );
2436 if (active && USER_Driver.pBeep) USER_Driver.pBeep();
2441 /***********************************************************************
2442 * SetTimer (USER32.@)
2444 UINT_PTR WINAPI SetTimer( HWND hwnd, UINT_PTR id, UINT timeout, TIMERPROC proc )
2447 WNDPROC winproc = 0;
2449 if (proc) winproc = WINPROC_AllocProc( (WNDPROC)proc, WIN_PROC_32A );
2451 SERVER_START_REQ( set_win_timer )
2454 req->msg = WM_TIMER;
2456 req->rate = max( timeout, SYS_TIMER_RATE );
2457 req->lparam = (unsigned int)winproc;
2458 if (!wine_server_call_err( req ))
2461 if (!ret) ret = TRUE;
2467 TRACE("Added %p %x %p timeout %d\n", hwnd, id, winproc, timeout );
2472 /***********************************************************************
2473 * SetSystemTimer (USER32.@)
2475 UINT_PTR WINAPI SetSystemTimer( HWND hwnd, UINT_PTR id, UINT timeout, TIMERPROC proc )
2478 WNDPROC winproc = 0;
2480 if (proc) winproc = WINPROC_AllocProc( (WNDPROC)proc, WIN_PROC_32A );
2482 SERVER_START_REQ( set_win_timer )
2485 req->msg = WM_SYSTIMER;
2487 req->rate = max( timeout, SYS_TIMER_RATE );
2488 req->lparam = (unsigned int)winproc;
2489 if (!wine_server_call_err( req ))
2492 if (!ret) ret = TRUE;
2498 TRACE("Added %p %x %p timeout %d\n", hwnd, id, winproc, timeout );
2503 /***********************************************************************
2504 * KillTimer (USER32.@)
2506 BOOL WINAPI KillTimer( HWND hwnd, UINT_PTR id )
2510 TRACE("%p %d\n", hwnd, id );
2512 SERVER_START_REQ( kill_win_timer )
2515 req->msg = WM_TIMER;
2517 ret = !wine_server_call_err( req );
2524 /***********************************************************************
2525 * KillSystemTimer (USER32.@)
2527 BOOL WINAPI KillSystemTimer( HWND hwnd, UINT_PTR id )
2531 TRACE("%p %d\n", hwnd, id );
2533 SERVER_START_REQ( kill_win_timer )
2536 req->msg = WM_SYSTIMER;
2538 ret = !wine_server_call_err( req );
2545 /**********************************************************************
2546 * AttachThreadInput (USER32.@)
2548 * Attaches the input processing mechanism of one thread to that of
2551 BOOL WINAPI AttachThreadInput( DWORD from, DWORD to, BOOL attach )
2555 SERVER_START_REQ( attach_thread_input )
2557 req->tid_from = from;
2559 req->attach = attach;
2560 ret = !wine_server_call_err( req );
2567 /**********************************************************************
2568 * GetGUIThreadInfo (USER32.@)
2570 BOOL WINAPI GetGUIThreadInfo( DWORD id, GUITHREADINFO *info )
2574 SERVER_START_REQ( get_thread_input )
2577 if ((ret = !wine_server_call_err( req )))
2580 info->hwndActive = reply->active;
2581 info->hwndFocus = reply->focus;
2582 info->hwndCapture = reply->capture;
2583 info->hwndMenuOwner = reply->menu_owner;
2584 info->hwndMoveSize = reply->move_size;
2585 info->hwndCaret = reply->caret;
2586 info->rcCaret.left = reply->rect.left;
2587 info->rcCaret.top = reply->rect.top;
2588 info->rcCaret.right = reply->rect.right;
2589 info->rcCaret.bottom = reply->rect.bottom;
2590 if (reply->menu_owner) info->flags |= GUI_INMENUMODE;
2591 if (reply->move_size) info->flags |= GUI_INMOVESIZE;
2592 if (reply->caret) info->flags |= GUI_CARETBLINKING;
2600 /**********************************************************************
2601 * GetKeyState (USER32.@)
2603 * An application calls the GetKeyState function in response to a
2604 * keyboard-input message. This function retrieves the state of the key
2605 * at the time the input message was generated.
2607 SHORT WINAPI GetKeyState(INT vkey)
2611 SERVER_START_REQ( get_key_state )
2613 req->tid = GetCurrentThreadId();
2615 if (!wine_server_call( req )) retval = (signed char)reply->state;
2618 TRACE("key (0x%x) -> %x\n", vkey, retval);
2623 /**********************************************************************
2624 * GetKeyboardState (USER32.@)
2626 BOOL WINAPI GetKeyboardState( LPBYTE state )
2630 TRACE("(%p)\n", state);
2632 memset( state, 0, 256 );
2633 SERVER_START_REQ( get_key_state )
2635 req->tid = GetCurrentThreadId();
2637 wine_server_set_reply( req, state, 256 );
2638 ret = !wine_server_call_err( req );
2645 /**********************************************************************
2646 * SetKeyboardState (USER32.@)
2648 BOOL WINAPI SetKeyboardState( LPBYTE state )
2652 TRACE("(%p)\n", state);
2654 SERVER_START_REQ( set_key_state )
2656 req->tid = GetCurrentThreadId();
2657 wine_server_add_data( req, state, 256 );
2658 ret = !wine_server_call_err( req );
2664 /******************************************************************
2665 * IsHungAppWindow (USER32.@)
2668 BOOL WINAPI IsHungAppWindow( HWND hWnd )
2671 return !SendMessageTimeoutA(hWnd, WM_NULL, 0, 0, SMTO_ABORTIFHUNG, 5000, &dwResult);
2674 /******************************************************************
2675 * GetLastInputInfo (USER32.@)
2677 BOOL WINAPI GetLastInputInfo(PLASTINPUTINFO plii)
2679 FIXME("%p\n", plii);