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"
43 #include "wine/debug.h"
45 WINE_DEFAULT_DEBUG_CHANNEL(msg);
46 WINE_DECLARE_DEBUG_CHANNEL(relay);
47 WINE_DECLARE_DEBUG_CHANNEL(key);
49 #define WM_NCMOUSEFIRST WM_NCMOUSEMOVE
50 #define WM_NCMOUSELAST WM_NCMBUTTONDBLCLK
52 #define MAX_PACK_COUNT 4
54 #define SYS_TIMER_RATE 55 /* min. timer rate in ms (actually 54.925)*/
56 /* description of the data fields that need to be packed along with a sent message */
60 const void *data[MAX_PACK_COUNT];
61 size_t size[MAX_PACK_COUNT];
64 /* info about the message currently being received by the current thread */
65 struct received_message_info
67 enum message_type type;
69 UINT flags; /* InSendMessageEx return flags */
70 HWINEVENTHOOK hook; /* winevent hook handle */
71 WINEVENTPROC hook_proc; /* winevent hook proc address */
74 /* structure to group all parameters for sent messages of the various kinds */
75 struct send_message_info
77 enum message_type type;
82 UINT flags; /* flags for SendMessageTimeout */
83 UINT timeout; /* timeout for SendMessageTimeout */
84 SENDASYNCPROC callback; /* callback function for SendMessageCallback */
85 ULONG_PTR data; /* callback data */
89 /* flag for messages that contain pointers */
90 /* 32 messages per entry, messages 0..31 map to bits 0..31 */
92 #define SET(msg) (1 << ((msg) & 31))
94 static const unsigned int message_pointer_flags[] =
97 SET(WM_CREATE) | SET(WM_SETTEXT) | SET(WM_GETTEXT) |
98 SET(WM_WININICHANGE) | SET(WM_DEVMODECHANGE),
100 SET(WM_GETMINMAXINFO) | SET(WM_DRAWITEM) | SET(WM_MEASUREITEM) | SET(WM_DELETEITEM) |
103 SET(WM_WINDOWPOSCHANGING) | SET(WM_WINDOWPOSCHANGED) | SET(WM_COPYDATA) |
104 SET(WM_NOTIFY) | SET(WM_HELP),
106 SET(WM_STYLECHANGING) | SET(WM_STYLECHANGED),
108 SET(WM_NCCREATE) | SET(WM_NCCALCSIZE) | SET(WM_GETDLGCODE),
110 SET(EM_GETSEL) | SET(EM_GETRECT) | SET(EM_SETRECT) | SET(EM_SETRECTNP),
112 SET(EM_REPLACESEL) | SET(EM_GETLINE) | SET(EM_SETTABSTOPS),
114 SET(SBM_GETRANGE) | SET(SBM_SETSCROLLINFO) | SET(SBM_GETSCROLLINFO) | SET(SBM_GETSCROLLBARINFO),
120 SET(CB_GETEDITSEL) | SET(CB_ADDSTRING) | SET(CB_DIR) | SET(CB_GETLBTEXT) |
121 SET(CB_INSERTSTRING) | SET(CB_FINDSTRING) | SET(CB_SELECTSTRING) |
122 SET(CB_GETDROPPEDCONTROLRECT) | SET(CB_FINDSTRINGEXACT),
126 SET(LB_ADDSTRING) | SET(LB_INSERTSTRING) | SET(LB_GETTEXT) | SET(LB_SELECTSTRING) |
127 SET(LB_DIR) | SET(LB_FINDSTRING) |
128 SET(LB_GETSELITEMS) | SET(LB_SETTABSTOPS) | SET(LB_ADDFILE) | SET(LB_GETITEMRECT),
130 SET(LB_FINDSTRINGEXACT),
136 SET(WM_NEXTMENU) | SET(WM_SIZING) | SET(WM_MOVING) | SET(WM_DEVICECHANGE),
138 SET(WM_MDICREATE) | SET(WM_MDIGETACTIVE) | SET(WM_DROPOBJECT) |
139 SET(WM_QUERYDROPOBJECT) | SET(WM_DRAGLOOP) | SET(WM_DRAGSELECT) | SET(WM_DRAGMOVE),
153 SET(WM_ASKCBFORMATNAME)
156 /* flags for messages that contain Unicode strings */
157 static const unsigned int message_unicode_flags[] =
160 SET(WM_CREATE) | SET(WM_SETTEXT) | SET(WM_GETTEXT) | SET(WM_GETTEXTLENGTH) |
161 SET(WM_WININICHANGE) | SET(WM_DEVMODECHANGE),
173 SET(EM_REPLACESEL) | SET(EM_GETLINE) | SET(EM_SETPASSWORDCHAR),
177 SET(WM_CHAR) | SET(WM_DEADCHAR) | SET(WM_SYSCHAR) | SET(WM_SYSDEADCHAR),
181 SET(CB_ADDSTRING) | SET(CB_DIR) | SET(CB_GETLBTEXT) | SET(CB_GETLBTEXTLEN) |
182 SET(CB_INSERTSTRING) | SET(CB_FINDSTRING) | SET(CB_SELECTSTRING) | SET(CB_FINDSTRINGEXACT),
186 SET(LB_ADDSTRING) | SET(LB_INSERTSTRING) | SET(LB_GETTEXT) | SET(LB_GETTEXTLEN) |
187 SET(LB_SELECTSTRING) | SET(LB_DIR) | SET(LB_FINDSTRING) | SET(LB_ADDFILE),
189 SET(LB_FINDSTRINGEXACT),
211 SET(WM_PAINTCLIPBOARD) | SET(WM_SIZECLIPBOARD) | SET(WM_ASKCBFORMATNAME)
214 /* check whether a given message type includes pointers */
215 inline static int is_pointer_message( UINT message )
217 if (message >= 8*sizeof(message_pointer_flags)) return FALSE;
218 return (message_pointer_flags[message / 32] & SET(message)) != 0;
221 /* check whether a given message type contains Unicode (or ASCII) chars */
222 inline static int is_unicode_message( UINT message )
224 if (message >= 8*sizeof(message_unicode_flags)) return FALSE;
225 return (message_unicode_flags[message / 32] & SET(message)) != 0;
230 /* add a data field to a packed message */
231 inline static void push_data( struct packed_message *data, const void *ptr, size_t size )
233 data->data[data->count] = ptr;
234 data->size[data->count] = size;
238 /* add a string to a packed message */
239 inline static void push_string( struct packed_message *data, LPCWSTR str )
241 push_data( data, str, (strlenW(str) + 1) * sizeof(WCHAR) );
244 /* retrieve a pointer to data from a packed message and increment the buffer pointer */
245 inline static void *get_data( void **buffer, size_t size )
248 *buffer = (char *)*buffer + size;
252 /* make sure that the buffer contains a valid null-terminated Unicode string */
253 inline static BOOL check_string( LPCWSTR str, size_t size )
255 for (size /= sizeof(WCHAR); size; size--, str++)
256 if (!*str) return TRUE;
260 /* make sure that there is space for 'size' bytes in buffer, growing it if needed */
261 inline static void *get_buffer_space( void **buffer, size_t size )
267 if (!(ret = HeapReAlloc( GetProcessHeap(), 0, *buffer, size )))
268 HeapFree( GetProcessHeap(), 0, *buffer );
270 else ret = HeapAlloc( GetProcessHeap(), 0, size );
276 /* retrieve a string pointer from packed data */
277 inline static LPWSTR get_string( void **buffer )
279 return get_data( buffer, (strlenW( (LPWSTR)*buffer ) + 1) * sizeof(WCHAR) );
282 /* check whether a combobox expects strings or ids in CB_ADDSTRING/CB_INSERTSTRING */
283 inline static BOOL combobox_has_strings( HWND hwnd )
285 DWORD style = GetWindowLongA( hwnd, GWL_STYLE );
286 return (!(style & (CBS_OWNERDRAWFIXED | CBS_OWNERDRAWVARIABLE)) || (style & CBS_HASSTRINGS));
289 /* check whether a listbox expects strings or ids in LB_ADDSTRING/LB_INSERTSTRING */
290 inline static BOOL listbox_has_strings( HWND hwnd )
292 DWORD style = GetWindowLongA( hwnd, GWL_STYLE );
293 return (!(style & (LBS_OWNERDRAWFIXED | LBS_OWNERDRAWVARIABLE)) || (style & LBS_HASSTRINGS));
296 /* check whether message is in the range of keyboard messages */
297 inline static BOOL is_keyboard_message( UINT message )
299 return (message >= WM_KEYFIRST && message <= WM_KEYLAST);
302 /* check whether message is in the range of mouse messages */
303 inline static BOOL is_mouse_message( UINT message )
305 return ((message >= WM_NCMOUSEFIRST && message <= WM_NCMOUSELAST) ||
306 (message >= WM_MOUSEFIRST && message <= WM_MOUSELAST));
309 /* check whether message matches the specified filter */
310 inline static BOOL check_message_filter( const MSG *msg, HWND hwnd, UINT first, UINT last )
312 if (hwnd && msg->hwnd != hwnd && !IsChild( hwnd, msg->hwnd )) return FALSE;
313 if (first || last) return (msg->message >= first && msg->message <= last);
318 /***********************************************************************
319 * broadcast_message_callback
321 * Helper callback for broadcasting messages.
323 static BOOL CALLBACK broadcast_message_callback( HWND hwnd, LPARAM lparam )
325 struct send_message_info *info = (struct send_message_info *)lparam;
326 if (!(GetWindowLongW( hwnd, GWL_STYLE ) & (WS_POPUP|WS_CAPTION))) return TRUE;
330 SendMessageTimeoutW( hwnd, info->msg, info->wparam, info->lparam,
331 info->flags, info->timeout, NULL );
334 SendMessageTimeoutA( hwnd, info->msg, info->wparam, info->lparam,
335 info->flags, info->timeout, NULL );
338 SendNotifyMessageW( hwnd, info->msg, info->wparam, info->lparam );
341 SendMessageCallbackW( hwnd, info->msg, info->wparam, info->lparam,
342 info->callback, info->data );
345 PostMessageW( hwnd, info->msg, info->wparam, info->lparam );
348 ERR( "bad type %d\n", info->type );
355 /***********************************************************************
358 * Convert the wparam of an ASCII message to Unicode.
360 static WPARAM map_wparam_AtoW( UINT message, WPARAM wparam )
365 case EM_SETPASSWORDCHAR:
372 char ch = LOWORD(wparam);
374 MultiByteToWideChar(CP_ACP, 0, &ch, 1, &wch, 1);
375 wparam = MAKEWPARAM( wch, HIWORD(wparam) );
382 ch[0] = (wparam >> 8);
383 ch[1] = (wparam & 0xff);
384 if (ch[0]) MultiByteToWideChar(CP_ACP, 0, ch, 2, &wch, 1);
385 else MultiByteToWideChar(CP_ACP, 0, &ch[1], 1, &wch, 1);
386 wparam = MAKEWPARAM( wch, HIWORD(wparam) );
394 /***********************************************************************
397 * Convert the wparam of a Unicode message to ASCII.
399 static WPARAM map_wparam_WtoA( UINT message, WPARAM wparam )
404 case EM_SETPASSWORDCHAR:
411 WCHAR wch = LOWORD(wparam);
413 WideCharToMultiByte( CP_ACP, 0, &wch, 1, &ch, 1, NULL, NULL );
414 wparam = MAKEWPARAM( ch, HIWORD(wparam) );
419 WCHAR wch = LOWORD(wparam);
422 if (WideCharToMultiByte( CP_ACP, 0, &wch, 1, ch, 2, NULL, NULL ) == 2)
423 wparam = MAKEWPARAM( (ch[0] << 8) | ch[1], HIWORD(wparam) );
425 wparam = MAKEWPARAM( ch[0], HIWORD(wparam) );
433 /***********************************************************************
436 * Pack a message for sending to another process.
437 * Return the size of the data we expect in the message reply.
438 * Set data->count to -1 if there is an error.
440 static size_t pack_message( HWND hwnd, UINT message, WPARAM wparam, LPARAM lparam,
441 struct packed_message *data )
449 CREATESTRUCTW *cs = (CREATESTRUCTW *)lparam;
450 push_data( data, cs, sizeof(*cs) );
451 if (HIWORD(cs->lpszName)) push_string( data, cs->lpszName );
452 if (HIWORD(cs->lpszClass)) push_string( data, cs->lpszClass );
456 case WM_ASKCBFORMATNAME:
457 return wparam * sizeof(WCHAR);
458 case WM_WININICHANGE:
459 if (lparam) push_string(data, (LPWSTR)lparam );
462 case WM_DEVMODECHANGE:
467 push_string( data, (LPWSTR)lparam );
469 case WM_GETMINMAXINFO:
470 push_data( data, (MINMAXINFO *)lparam, sizeof(MINMAXINFO) );
471 return sizeof(MINMAXINFO);
473 push_data( data, (DRAWITEMSTRUCT *)lparam, sizeof(DRAWITEMSTRUCT) );
476 push_data( data, (MEASUREITEMSTRUCT *)lparam, sizeof(MEASUREITEMSTRUCT) );
477 return sizeof(MEASUREITEMSTRUCT);
479 push_data( data, (DELETEITEMSTRUCT *)lparam, sizeof(DELETEITEMSTRUCT) );
482 push_data( data, (COMPAREITEMSTRUCT *)lparam, sizeof(COMPAREITEMSTRUCT) );
484 case WM_WINDOWPOSCHANGING:
485 case WM_WINDOWPOSCHANGED:
486 push_data( data, (WINDOWPOS *)lparam, sizeof(WINDOWPOS) );
487 return sizeof(WINDOWPOS);
490 COPYDATASTRUCT *cp = (COPYDATASTRUCT *)lparam;
491 push_data( data, cp, sizeof(*cp) );
492 if (cp->lpData) push_data( data, cp->lpData, cp->cbData );
496 /* WM_NOTIFY cannot be sent across processes (MSDN) */
500 push_data( data, (HELPINFO *)lparam, sizeof(HELPINFO) );
502 case WM_STYLECHANGING:
503 case WM_STYLECHANGED:
504 push_data( data, (STYLESTRUCT *)lparam, sizeof(STYLESTRUCT) );
509 push_data( data, (RECT *)lparam, sizeof(RECT) );
514 NCCALCSIZE_PARAMS *nc = (NCCALCSIZE_PARAMS *)lparam;
515 push_data( data, nc, sizeof(*nc) );
516 push_data( data, nc->lppos, sizeof(*nc->lppos) );
517 return sizeof(*nc) + sizeof(*nc->lppos);
520 if (lparam) push_data( data, (MSG *)lparam, sizeof(MSG) );
522 case SBM_SETSCROLLINFO:
523 push_data( data, (SCROLLINFO *)lparam, sizeof(SCROLLINFO) );
525 case SBM_GETSCROLLINFO:
526 push_data( data, (SCROLLINFO *)lparam, sizeof(SCROLLINFO) );
527 return sizeof(SCROLLINFO);
528 case SBM_GETSCROLLBARINFO:
530 const SCROLLBARINFO *info = (const SCROLLBARINFO *)lparam;
531 size_t size = min( info->cbSize, sizeof(SCROLLBARINFO) );
532 push_data( data, info, size );
540 if (wparam) size += sizeof(DWORD);
541 if (lparam) size += sizeof(DWORD);
546 case CB_GETDROPPEDCONTROLRECT:
550 push_data( data, (RECT *)lparam, sizeof(RECT) );
554 WORD *pw = (WORD *)lparam;
555 push_data( data, pw, sizeof(*pw) );
556 return *pw * sizeof(WCHAR);
560 if (wparam) push_data( data, (UINT *)lparam, sizeof(UINT) * wparam );
563 case CB_INSERTSTRING:
565 case CB_FINDSTRINGEXACT:
566 case CB_SELECTSTRING:
567 if (combobox_has_strings( hwnd )) push_string( data, (LPWSTR)lparam );
570 if (!combobox_has_strings( hwnd )) return sizeof(ULONG_PTR);
571 return (SendMessageW( hwnd, CB_GETLBTEXTLEN, wparam, 0 ) + 1) * sizeof(WCHAR);
573 case LB_INSERTSTRING:
575 case LB_FINDSTRINGEXACT:
576 case LB_SELECTSTRING:
577 if (listbox_has_strings( hwnd )) push_string( data, (LPWSTR)lparam );
580 if (!listbox_has_strings( hwnd )) return sizeof(ULONG_PTR);
581 return (SendMessageW( hwnd, LB_GETTEXTLEN, wparam, 0 ) + 1) * sizeof(WCHAR);
583 return wparam * sizeof(UINT);
585 push_data( data, (MDINEXTMENU *)lparam, sizeof(MDINEXTMENU) );
586 return sizeof(MDINEXTMENU);
589 push_data( data, (RECT *)lparam, sizeof(RECT) );
593 MDICREATESTRUCTW *cs = (MDICREATESTRUCTW *)lparam;
594 push_data( data, cs, sizeof(*cs) );
595 if (HIWORD(cs->szTitle)) push_string( data, cs->szTitle );
596 if (HIWORD(cs->szClass)) push_string( data, cs->szClass );
599 case WM_MDIGETACTIVE:
600 if (lparam) return sizeof(BOOL);
602 case WM_WINE_SETWINDOWPOS:
603 push_data( data, (WINDOWPOS *)lparam, sizeof(WINDOWPOS) );
605 case WM_WINE_KEYBOARD_LL_HOOK:
606 push_data( data, (KBDLLHOOKSTRUCT *)lparam, sizeof(KBDLLHOOKSTRUCT) );
608 case WM_WINE_MOUSE_LL_HOOK:
609 push_data( data, (MSLLHOOKSTRUCT *)lparam, sizeof(MSLLHOOKSTRUCT) );
612 if (!wparam) return 0;
615 /* these contain an HFONT */
618 /* these contain an HDC */
620 case WM_ICONERASEBKGND:
622 case WM_CTLCOLORMSGBOX:
623 case WM_CTLCOLOREDIT:
624 case WM_CTLCOLORLISTBOX:
627 case WM_CTLCOLORSCROLLBAR:
628 case WM_CTLCOLORSTATIC:
631 /* these contain an HGLOBAL */
632 case WM_PAINTCLIPBOARD:
633 case WM_SIZECLIPBOARD:
634 /* these contain HICON */
637 case WM_QUERYDRAGICON:
638 case WM_QUERYPARKICON:
639 /* these contain pointers */
641 case WM_QUERYDROPOBJECT:
645 case WM_DEVICECHANGE:
646 FIXME( "msg %x (%s) not supported yet\n", message, SPY_GetMsgName(message, hwnd) );
654 /***********************************************************************
657 * Unpack a message received from another process.
659 static BOOL unpack_message( HWND hwnd, UINT message, WPARAM *wparam, LPARAM *lparam,
660 void **buffer, size_t size )
669 CREATESTRUCTW *cs = *buffer;
670 WCHAR *str = (WCHAR *)(cs + 1);
671 if (size < sizeof(*cs)) return FALSE;
673 if (HIWORD(cs->lpszName))
675 if (!check_string( str, size )) return FALSE;
677 size -= (strlenW(str) + 1) * sizeof(WCHAR);
678 str += strlenW(str) + 1;
680 if (HIWORD(cs->lpszClass))
682 if (!check_string( str, size )) return FALSE;
688 case WM_ASKCBFORMATNAME:
689 if (!get_buffer_space( buffer, (*wparam * sizeof(WCHAR)) )) return FALSE;
691 case WM_WININICHANGE:
692 if (!*lparam) return TRUE;
695 case WM_DEVMODECHANGE:
700 if (!check_string( *buffer, size )) return FALSE;
702 case WM_GETMINMAXINFO:
703 minsize = sizeof(MINMAXINFO);
706 minsize = sizeof(DRAWITEMSTRUCT);
709 minsize = sizeof(MEASUREITEMSTRUCT);
712 minsize = sizeof(DELETEITEMSTRUCT);
715 minsize = sizeof(COMPAREITEMSTRUCT);
717 case WM_WINDOWPOSCHANGING:
718 case WM_WINDOWPOSCHANGED:
719 case WM_WINE_SETWINDOWPOS:
720 minsize = sizeof(WINDOWPOS);
724 COPYDATASTRUCT *cp = *buffer;
725 if (size < sizeof(*cp)) return FALSE;
728 minsize = sizeof(*cp) + cp->cbData;
734 /* WM_NOTIFY cannot be sent across processes (MSDN) */
737 minsize = sizeof(HELPINFO);
739 case WM_STYLECHANGING:
740 case WM_STYLECHANGED:
741 minsize = sizeof(STYLESTRUCT);
744 if (!*wparam) minsize = sizeof(RECT);
747 NCCALCSIZE_PARAMS *nc = *buffer;
748 if (size < sizeof(*nc) + sizeof(*nc->lppos)) return FALSE;
749 nc->lppos = (WINDOWPOS *)(nc + 1);
753 if (!*lparam) return TRUE;
754 minsize = sizeof(MSG);
756 case SBM_SETSCROLLINFO:
757 minsize = sizeof(SCROLLINFO);
759 case SBM_GETSCROLLINFO:
760 if (!get_buffer_space( buffer, sizeof(SCROLLINFO ))) return FALSE;
762 case SBM_GETSCROLLBARINFO:
763 if (!get_buffer_space( buffer, sizeof(SCROLLBARINFO ))) return FALSE;
768 if (*wparam || *lparam)
770 if (!get_buffer_space( buffer, 2*sizeof(DWORD) )) return FALSE;
771 if (*wparam) *wparam = (WPARAM)*buffer;
772 if (*lparam) *lparam = (LPARAM)((DWORD *)*buffer + 1);
777 case CB_GETDROPPEDCONTROLRECT:
778 if (!get_buffer_space( buffer, sizeof(RECT) )) return FALSE;
782 minsize = sizeof(RECT);
787 if (size < sizeof(WORD)) return FALSE;
788 len = *(WORD *)*buffer;
789 if (!get_buffer_space( buffer, (len + 1) * sizeof(WCHAR) )) return FALSE;
790 *lparam = (LPARAM)*buffer + sizeof(WORD); /* don't erase WORD at start of buffer */
795 if (!*wparam) return TRUE;
796 minsize = *wparam * sizeof(UINT);
799 case CB_INSERTSTRING:
801 case CB_FINDSTRINGEXACT:
802 case CB_SELECTSTRING:
804 case LB_INSERTSTRING:
806 case LB_FINDSTRINGEXACT:
807 case LB_SELECTSTRING:
808 if (!*buffer) return TRUE;
809 if (!check_string( *buffer, size )) return FALSE;
813 size = sizeof(ULONG_PTR);
814 if (combobox_has_strings( hwnd ))
815 size = (SendMessageW( hwnd, CB_GETLBTEXTLEN, *wparam, 0 ) + 1) * sizeof(WCHAR);
816 if (!get_buffer_space( buffer, size )) return FALSE;
821 size = sizeof(ULONG_PTR);
822 if (listbox_has_strings( hwnd ))
823 size = (SendMessageW( hwnd, LB_GETTEXTLEN, *wparam, 0 ) + 1) * sizeof(WCHAR);
824 if (!get_buffer_space( buffer, size )) return FALSE;
828 if (!get_buffer_space( buffer, *wparam * sizeof(UINT) )) return FALSE;
831 minsize = sizeof(MDINEXTMENU);
832 if (!get_buffer_space( buffer, sizeof(MDINEXTMENU) )) return FALSE;
836 minsize = sizeof(RECT);
837 if (!get_buffer_space( buffer, sizeof(RECT) )) return FALSE;
841 MDICREATESTRUCTW *cs = *buffer;
842 WCHAR *str = (WCHAR *)(cs + 1);
843 if (size < sizeof(*cs)) return FALSE;
845 if (HIWORD(cs->szTitle))
847 if (!check_string( str, size )) return FALSE;
849 size -= (strlenW(str) + 1) * sizeof(WCHAR);
850 str += strlenW(str) + 1;
852 if (HIWORD(cs->szClass))
854 if (!check_string( str, size )) return FALSE;
859 case WM_MDIGETACTIVE:
860 if (!*lparam) return TRUE;
861 if (!get_buffer_space( buffer, sizeof(BOOL) )) return FALSE;
863 case WM_WINE_KEYBOARD_LL_HOOK:
864 minsize = sizeof(KBDLLHOOKSTRUCT);
866 case WM_WINE_MOUSE_LL_HOOK:
867 minsize = sizeof(MSLLHOOKSTRUCT);
870 if (!*wparam) return TRUE;
873 /* these contain an HFONT */
876 /* these contain an HDC */
878 case WM_ICONERASEBKGND:
880 case WM_CTLCOLORMSGBOX:
881 case WM_CTLCOLOREDIT:
882 case WM_CTLCOLORLISTBOX:
885 case WM_CTLCOLORSCROLLBAR:
886 case WM_CTLCOLORSTATIC:
889 /* these contain an HGLOBAL */
890 case WM_PAINTCLIPBOARD:
891 case WM_SIZECLIPBOARD:
892 /* these contain HICON */
895 case WM_QUERYDRAGICON:
896 case WM_QUERYPARKICON:
897 /* these contain pointers */
899 case WM_QUERYDROPOBJECT:
903 case WM_DEVICECHANGE:
904 FIXME( "msg %x (%s) not supported yet\n", message, SPY_GetMsgName(message, hwnd) );
908 return TRUE; /* message doesn't need any unpacking */
911 /* default exit for most messages: check minsize and store buffer in lparam */
912 if (size < minsize) return FALSE;
913 *lparam = (LPARAM)*buffer;
918 /***********************************************************************
921 * Pack a reply to a message for sending to another process.
923 static void pack_reply( HWND hwnd, UINT message, WPARAM wparam, LPARAM lparam,
924 LRESULT res, struct packed_message *data )
931 push_data( data, (CREATESTRUCTW *)lparam, sizeof(CREATESTRUCTW) );
936 push_data( data, (WCHAR *)lparam, (res + 1) * sizeof(WCHAR) );
938 case WM_GETMINMAXINFO:
939 push_data( data, (MINMAXINFO *)lparam, sizeof(MINMAXINFO) );
942 push_data( data, (MEASUREITEMSTRUCT *)lparam, sizeof(MEASUREITEMSTRUCT) );
944 case WM_WINDOWPOSCHANGING:
945 case WM_WINDOWPOSCHANGED:
946 push_data( data, (WINDOWPOS *)lparam, sizeof(WINDOWPOS) );
949 if (lparam) push_data( data, (MSG *)lparam, sizeof(MSG) );
951 case SBM_GETSCROLLINFO:
952 push_data( data, (SCROLLINFO *)lparam, sizeof(SCROLLINFO) );
956 case CB_GETDROPPEDCONTROLRECT:
959 push_data( data, (RECT *)lparam, sizeof(RECT) );
963 WORD *ptr = (WORD *)lparam;
964 push_data( data, ptr, ptr[-1] * sizeof(WCHAR) );
968 push_data( data, (UINT *)lparam, wparam * sizeof(UINT) );
970 case WM_MDIGETACTIVE:
971 if (lparam) push_data( data, (BOOL *)lparam, sizeof(BOOL) );
975 push_data( data, (RECT *)lparam, sizeof(RECT) );
978 NCCALCSIZE_PARAMS *nc = (NCCALCSIZE_PARAMS *)lparam;
979 push_data( data, nc, sizeof(*nc) );
980 push_data( data, nc->lppos, sizeof(*nc->lppos) );
986 if (wparam) push_data( data, (DWORD *)wparam, sizeof(DWORD) );
987 if (lparam) push_data( data, (DWORD *)lparam, sizeof(DWORD) );
990 push_data( data, (MDINEXTMENU *)lparam, sizeof(MDINEXTMENU) );
993 push_data( data, (MDICREATESTRUCTW *)lparam, sizeof(MDICREATESTRUCTW) );
995 case WM_ASKCBFORMATNAME:
996 push_data( data, (WCHAR *)lparam, (strlenW((WCHAR *)lparam) + 1) * sizeof(WCHAR) );
1002 /***********************************************************************
1005 * Unpack a message reply received from another process.
1007 static void unpack_reply( HWND hwnd, UINT message, WPARAM wparam, LPARAM lparam,
1008 void *buffer, size_t size )
1015 CREATESTRUCTW *cs = (CREATESTRUCTW *)lparam;
1016 LPCWSTR name = cs->lpszName, class = cs->lpszClass;
1017 memcpy( cs, buffer, min( sizeof(*cs), size ));
1018 cs->lpszName = name; /* restore the original pointers */
1019 cs->lpszClass = class;
1023 case WM_ASKCBFORMATNAME:
1024 memcpy( (WCHAR *)lparam, buffer, min( wparam*sizeof(WCHAR), size ));
1026 case WM_GETMINMAXINFO:
1027 memcpy( (MINMAXINFO *)lparam, buffer, min( sizeof(MINMAXINFO), size ));
1029 case WM_MEASUREITEM:
1030 memcpy( (MEASUREITEMSTRUCT *)lparam, buffer, min( sizeof(MEASUREITEMSTRUCT), size ));
1032 case WM_WINDOWPOSCHANGING:
1033 case WM_WINDOWPOSCHANGED:
1034 memcpy( (WINDOWPOS *)lparam, buffer, min( sizeof(WINDOWPOS), size ));
1037 if (lparam) memcpy( (MSG *)lparam, buffer, min( sizeof(MSG), size ));
1039 case SBM_GETSCROLLINFO:
1040 memcpy( (SCROLLINFO *)lparam, buffer, min( sizeof(SCROLLINFO), size ));
1042 case SBM_GETSCROLLBARINFO:
1043 memcpy( (SCROLLBARINFO *)lparam, buffer, min( sizeof(SCROLLBARINFO), size ));
1046 case CB_GETDROPPEDCONTROLRECT:
1047 case LB_GETITEMRECT:
1050 memcpy( (RECT *)lparam, buffer, min( sizeof(RECT), size ));
1053 size = min( size, (size_t)*(WORD *)lparam );
1054 memcpy( (WCHAR *)lparam, buffer, size );
1056 case LB_GETSELITEMS:
1057 memcpy( (UINT *)lparam, buffer, min( wparam*sizeof(UINT), size ));
1061 memcpy( (WCHAR *)lparam, buffer, size );
1064 memcpy( (MDINEXTMENU *)lparam, buffer, min( sizeof(MDINEXTMENU), size ));
1066 case WM_MDIGETACTIVE:
1067 if (lparam) memcpy( (BOOL *)lparam, buffer, min( sizeof(BOOL), size ));
1071 memcpy( (RECT *)lparam, buffer, min( sizeof(RECT), size ));
1074 NCCALCSIZE_PARAMS *nc = (NCCALCSIZE_PARAMS *)lparam;
1075 WINDOWPOS *wp = nc->lppos;
1076 memcpy( nc, buffer, min( sizeof(*nc), size ));
1077 if (size > sizeof(*nc))
1079 size -= sizeof(*nc);
1080 memcpy( wp, (NCCALCSIZE_PARAMS*)buffer + 1, min( sizeof(*wp), size ));
1082 nc->lppos = wp; /* restore the original pointer */
1090 memcpy( (DWORD *)wparam, buffer, min( sizeof(DWORD), size ));
1091 if (size <= sizeof(DWORD)) break;
1092 size -= sizeof(DWORD);
1093 buffer = (DWORD *)buffer + 1;
1095 if (lparam) memcpy( (DWORD *)lparam, buffer, min( sizeof(DWORD), size ));
1099 MDICREATESTRUCTW *cs = (MDICREATESTRUCTW *)lparam;
1100 LPCWSTR title = cs->szTitle, class = cs->szClass;
1101 memcpy( cs, buffer, min( sizeof(*cs), size ));
1102 cs->szTitle = title; /* restore the original pointers */
1103 cs->szClass = class;
1107 ERR( "should not happen: unexpected message %x\n", message );
1113 /***********************************************************************
1116 * Send a reply to a sent message.
1118 static void reply_message( struct received_message_info *info, LRESULT result, BOOL remove )
1120 struct packed_message data;
1121 int i, replied = info->flags & ISMEX_REPLIED;
1123 if (info->flags & ISMEX_NOTIFY) return; /* notify messages don't get replies */
1124 if (!remove && replied) return; /* replied already */
1127 info->flags |= ISMEX_REPLIED;
1129 if (info->type == MSG_OTHER_PROCESS && !replied)
1131 pack_reply( info->msg.hwnd, info->msg.message, info->msg.wParam,
1132 info->msg.lParam, result, &data );
1135 SERVER_START_REQ( reply_message )
1137 req->type = info->type;
1138 req->result = result;
1139 req->remove = remove;
1140 for (i = 0; i < data.count; i++) wine_server_add_data( req, data.data[i], data.size[i] );
1141 wine_server_call( req );
1147 /***********************************************************************
1148 * handle_internal_message
1150 * Handle an internal Wine message instead of calling the window proc.
1152 static LRESULT handle_internal_message( HWND hwnd, UINT msg, WPARAM wparam, LPARAM lparam )
1154 if (hwnd == GetDesktopWindow()) return 0;
1157 case WM_WINE_DESTROYWINDOW:
1158 return WIN_DestroyWindow( hwnd );
1159 case WM_WINE_SETWINDOWPOS:
1160 if (USER_Driver.pSetWindowPos)
1161 return USER_Driver.pSetWindowPos( (WINDOWPOS *)lparam );
1163 case WM_WINE_SHOWWINDOW:
1164 return ShowWindow( hwnd, wparam );
1165 case WM_WINE_SETPARENT:
1166 return (LRESULT)SetParent( hwnd, (HWND)wparam );
1167 case WM_WINE_SETWINDOWLONG:
1168 return (LRESULT)SetWindowLongW( hwnd, wparam, lparam );
1169 case WM_WINE_ENABLEWINDOW:
1170 return EnableWindow( hwnd, wparam );
1171 case WM_WINE_SETACTIVEWINDOW:
1172 return (LRESULT)SetActiveWindow( (HWND)wparam );
1173 case WM_WINE_KEYBOARD_LL_HOOK:
1174 return HOOK_CallHooks( WH_KEYBOARD_LL, HC_ACTION, wparam, lparam, TRUE );
1175 case WM_WINE_MOUSE_LL_HOOK:
1176 return HOOK_CallHooks( WH_MOUSE_LL, HC_ACTION, wparam, lparam, TRUE );
1178 if (msg >= WM_WINE_FIRST_DRIVER_MSG && msg <= WM_WINE_LAST_DRIVER_MSG)
1180 if (!USER_Driver.pWindowMessage) return 0;
1181 return USER_Driver.pWindowMessage( hwnd, msg, wparam, lparam );
1183 FIXME( "unknown internal message %x\n", msg );
1188 /* since the WM_DDE_ACK response to a WM_DDE_EXECUTE message should contain the handle
1189 * to the memory handle, we keep track (in the server side) of all pairs of handle
1190 * used (the client passes its value and the content of the memory handle), and
1191 * the server stored both values (the client, and the local one, created after the
1192 * content). When a ACK message is generated, the list of pair is searched for a
1193 * matching pair, so that the client memory handle can be returned.
1196 HGLOBAL client_hMem;
1197 HGLOBAL server_hMem;
1200 static struct DDE_pair* dde_pairs;
1201 static int dde_num_alloc;
1202 static int dde_num_used;
1204 static CRITICAL_SECTION dde_crst;
1205 static CRITICAL_SECTION_DEBUG critsect_debug =
1208 { &critsect_debug.ProcessLocksList, &critsect_debug.ProcessLocksList },
1209 0, 0, { 0, (DWORD)(__FILE__ ": dde_crst") }
1211 static CRITICAL_SECTION dde_crst = { &critsect_debug, -1, 0, 0, 0, 0 };
1213 static BOOL dde_add_pair(HGLOBAL chm, HGLOBAL shm)
1218 EnterCriticalSection(&dde_crst);
1220 /* now remember the pair of hMem on both sides */
1221 if (dde_num_used == dde_num_alloc)
1223 struct DDE_pair* tmp;
1225 tmp = HeapReAlloc( GetProcessHeap(), 0, dde_pairs,
1226 (dde_num_alloc + GROWBY) * sizeof(struct DDE_pair));
1228 tmp = HeapAlloc( GetProcessHeap(), 0,
1229 (dde_num_alloc + GROWBY) * sizeof(struct DDE_pair));
1233 LeaveCriticalSection(&dde_crst);
1237 /* zero out newly allocated part */
1238 memset(&dde_pairs[dde_num_alloc], 0, GROWBY * sizeof(struct DDE_pair));
1239 dde_num_alloc += GROWBY;
1242 for (i = 0; i < dde_num_alloc; i++)
1244 if (dde_pairs[i].server_hMem == 0)
1246 dde_pairs[i].client_hMem = chm;
1247 dde_pairs[i].server_hMem = shm;
1252 LeaveCriticalSection(&dde_crst);
1256 static HGLOBAL dde_get_pair(HGLOBAL shm)
1261 EnterCriticalSection(&dde_crst);
1262 for (i = 0; i < dde_num_alloc; i++)
1264 if (dde_pairs[i].server_hMem == shm)
1266 /* free this pair */
1267 dde_pairs[i].server_hMem = 0;
1269 ret = dde_pairs[i].client_hMem;
1273 LeaveCriticalSection(&dde_crst);
1277 /***********************************************************************
1280 * Post a DDE message
1282 static BOOL post_dde_message( DWORD dest_tid, struct packed_message *data, const struct send_message_info *info )
1288 HGLOBAL hunlock = 0;
1292 if (!UnpackDDElParam( info->msg, info->lparam, &uiLo, &uiHi ))
1298 /* DDE messages which don't require packing are:
1307 /* uiHi should contain a hMem from WM_DDE_EXECUTE */
1308 HGLOBAL h = dde_get_pair( (HANDLE)uiHi );
1311 /* send back the value of h on the other side */
1312 push_data( data, &h, sizeof(HGLOBAL) );
1314 TRACE( "send dde-ack %x %08x => %08lx\n", uiLo, uiHi, (DWORD)h );
1319 /* uiHi should contain either an atom or 0 */
1320 TRACE( "send dde-ack %x atom=%x\n", uiLo, uiHi );
1321 lp = MAKELONG( uiLo, uiHi );
1330 size = GlobalSize( (HGLOBAL)uiLo ) ;
1331 if ((info->msg == WM_DDE_ADVISE && size < sizeof(DDEADVISE)) ||
1332 (info->msg == WM_DDE_DATA && size < sizeof(DDEDATA)) ||
1333 (info->msg == WM_DDE_POKE && size < sizeof(DDEPOKE))
1337 else if (info->msg != WM_DDE_DATA) return FALSE;
1342 if ((ptr = GlobalLock( (HGLOBAL)uiLo) ))
1344 DDEDATA *dde_data = (DDEDATA *)ptr;
1345 TRACE("unused %d, fResponse %d, fRelease %d, fDeferUpd %d, fAckReq %d, cfFormat %d\n",
1346 dde_data->unused, dde_data->fResponse, dde_data->fRelease,
1347 dde_data->reserved, dde_data->fAckReq, dde_data->cfFormat);
1348 push_data( data, ptr, size );
1349 hunlock = (HGLOBAL)uiLo;
1352 TRACE( "send ddepack %u %x\n", size, uiHi );
1354 case WM_DDE_EXECUTE:
1357 if ((ptr = GlobalLock( (HGLOBAL)info->lparam) ))
1359 push_data(data, ptr, GlobalSize( (HGLOBAL)info->lparam ));
1360 /* so that the other side can send it back on ACK */
1362 hunlock = (HGLOBAL)info->lparam;
1367 SERVER_START_REQ( send_message )
1370 req->type = info->type;
1372 req->win = info->hwnd;
1373 req->msg = info->msg;
1374 req->wparam = info->wparam;
1376 req->time = GetCurrentTime();
1378 for (i = 0; i < data->count; i++)
1379 wine_server_add_data( req, data->data[i], data->size[i] );
1380 if ((res = wine_server_call( req )))
1382 if (res == STATUS_INVALID_PARAMETER)
1383 /* FIXME: find a STATUS_ value for this one */
1384 SetLastError( ERROR_INVALID_THREAD_ID );
1386 SetLastError( RtlNtStatusToDosError(res) );
1389 FreeDDElParam(info->msg, info->lparam);
1392 if (hunlock) GlobalUnlock(hunlock);
1397 /***********************************************************************
1398 * unpack_dde_message
1400 * Unpack a posted DDE message received from another process.
1402 static BOOL unpack_dde_message( HWND hwnd, UINT message, WPARAM *wparam, LPARAM *lparam,
1403 void **buffer, size_t size )
1414 /* hMem is being passed */
1415 if (size != sizeof(HGLOBAL)) return FALSE;
1416 if (!buffer || !*buffer) return FALSE;
1418 memcpy( &hMem, *buffer, size );
1420 TRACE("recv dde-ack %x mem=%x[%lx]\n", uiLo, uiHi, GlobalSize( hMem ));
1424 uiLo = LOWORD( *lparam );
1425 uiHi = HIWORD( *lparam );
1426 TRACE("recv dde-ack %x atom=%x\n", uiLo, uiHi);
1428 *lparam = PackDDElParam( WM_DDE_ACK, uiLo, uiHi );
1433 if ((!buffer || !*buffer) && message != WM_DDE_DATA) return FALSE;
1435 TRACE( "recv ddepack %u %x\n", size, uiHi );
1438 if (!(hMem = GlobalAlloc( GMEM_MOVEABLE|GMEM_DDESHARE, size )))
1440 if ((ptr = GlobalLock( hMem )))
1442 memcpy( ptr, *buffer, size );
1443 GlobalUnlock( hMem );
1453 *lparam = PackDDElParam( message, uiLo, uiHi );
1455 case WM_DDE_EXECUTE:
1458 if (!buffer || !*buffer) return FALSE;
1459 if (!(hMem = GlobalAlloc( GMEM_MOVEABLE|GMEM_DDESHARE, size ))) return FALSE;
1460 if ((ptr = GlobalLock( hMem )))
1462 memcpy( ptr, *buffer, size );
1463 GlobalUnlock( hMem );
1464 TRACE( "exec: pairing c=%08lx s=%08lx\n", *lparam, (DWORD)hMem );
1465 if (!dde_add_pair( (HGLOBAL)*lparam, hMem ))
1476 } else return FALSE;
1477 *lparam = (LPARAM)hMem;
1483 /***********************************************************************
1486 * Call a window procedure and the corresponding hooks.
1488 static LRESULT call_window_proc( HWND hwnd, UINT msg, WPARAM wparam, LPARAM lparam,
1489 BOOL unicode, BOOL same_thread )
1494 CWPRETSTRUCT cwpret;
1495 MESSAGEQUEUE *queue = QUEUE_Current();
1497 if (queue->recursion_count > MAX_SENDMSG_RECURSION) return 0;
1498 queue->recursion_count++;
1500 if (msg & 0x80000000)
1502 result = handle_internal_message( hwnd, msg, wparam, lparam );
1506 /* first the WH_CALLWNDPROC hook */
1507 hwnd = WIN_GetFullHandle( hwnd );
1508 cwp.lParam = lparam;
1509 cwp.wParam = wparam;
1512 HOOK_CallHooks( WH_CALLWNDPROC, HC_ACTION, same_thread, (LPARAM)&cwp, unicode );
1514 /* now call the window procedure */
1517 if (!(winproc = (WNDPROC)GetWindowLongPtrW( hwnd, GWLP_WNDPROC ))) goto done;
1518 result = CallWindowProcW( winproc, hwnd, msg, wparam, lparam );
1522 if (!(winproc = (WNDPROC)GetWindowLongPtrA( hwnd, GWLP_WNDPROC ))) goto done;
1523 result = CallWindowProcA( winproc, hwnd, msg, wparam, lparam );
1526 /* and finally the WH_CALLWNDPROCRET hook */
1527 cwpret.lResult = result;
1528 cwpret.lParam = lparam;
1529 cwpret.wParam = wparam;
1530 cwpret.message = msg;
1532 HOOK_CallHooks( WH_CALLWNDPROCRET, HC_ACTION, same_thread, (LPARAM)&cwpret, unicode );
1534 queue->recursion_count--;
1539 /***********************************************************************
1540 * send_parent_notify
1542 * Send a WM_PARENTNOTIFY to all ancestors of the given window, unless
1543 * the window has the WS_EX_NOPARENTNOTIFY style.
1545 static void send_parent_notify( HWND hwnd, WORD event, WORD idChild, POINT pt )
1547 /* pt has to be in the client coordinates of the parent window */
1548 MapWindowPoints( 0, hwnd, &pt, 1 );
1553 if (!(GetWindowLongW( hwnd, GWL_STYLE ) & WS_CHILD)) break;
1554 if (GetWindowLongW( hwnd, GWL_EXSTYLE ) & WS_EX_NOPARENTNOTIFY) break;
1555 if (!(parent = GetParent(hwnd))) break;
1556 MapWindowPoints( hwnd, parent, &pt, 1 );
1558 SendMessageW( hwnd, WM_PARENTNOTIFY,
1559 MAKEWPARAM( event, idChild ), MAKELPARAM( pt.x, pt.y ) );
1564 /***********************************************************************
1565 * process_raw_keyboard_message
1567 * returns TRUE if the contents of 'msg' should be passed to the application
1569 static BOOL process_raw_keyboard_message( MSG *msg, HWND hwnd_filter, UINT first, UINT last )
1573 event.message = msg->message;
1574 event.hwnd = msg->hwnd;
1575 event.time = msg->time;
1576 event.paramL = (msg->wParam & 0xFF) | (HIWORD(msg->lParam) << 8);
1577 event.paramH = msg->lParam & 0x7FFF;
1578 if (HIWORD(msg->lParam) & 0x0100) event.paramH |= 0x8000; /* special_key - bit */
1579 HOOK_CallHooks( WH_JOURNALRECORD, HC_ACTION, 0, (LPARAM)&event, TRUE );
1580 return check_message_filter( msg, hwnd_filter, first, last );
1584 /***********************************************************************
1585 * process_cooked_keyboard_message
1587 * returns TRUE if the contents of 'msg' should be passed to the application
1589 static BOOL process_cooked_keyboard_message( MSG *msg, BOOL remove )
1593 /* Handle F1 key by sending out WM_HELP message */
1594 if ((msg->message == WM_KEYUP) &&
1595 (msg->wParam == VK_F1) &&
1596 (msg->hwnd != GetDesktopWindow()) &&
1597 !MENU_IsMenuActive())
1600 hi.cbSize = sizeof(HELPINFO);
1601 hi.iContextType = HELPINFO_WINDOW;
1602 hi.iCtrlId = GetWindowLongPtrA( msg->hwnd, GWLP_ID );
1603 hi.hItemHandle = msg->hwnd;
1604 hi.dwContextId = GetWindowContextHelpId( msg->hwnd );
1605 hi.MousePos = msg->pt;
1606 SendMessageW( msg->hwnd, WM_HELP, 0, (LPARAM)&hi );
1610 if (HOOK_CallHooks( WH_KEYBOARD, remove ? HC_ACTION : HC_NOREMOVE,
1611 LOWORD(msg->wParam), msg->lParam, TRUE ))
1613 /* skip this message */
1614 HOOK_CallHooks( WH_CBT, HCBT_KEYSKIPPED, LOWORD(msg->wParam), msg->lParam, TRUE );
1621 /***********************************************************************
1622 * process_raw_mouse_message
1624 static BOOL process_raw_mouse_message( MSG *msg, HWND hwnd_filter, UINT first,
1625 UINT last, BOOL remove )
1634 HWND hWndScope = msg->hwnd;
1636 /* find the window to dispatch this mouse message to */
1639 GetGUIThreadInfo( GetCurrentThreadId(), &info );
1640 if (!(msg->hwnd = info.hwndCapture))
1642 /* If no capture HWND, find window which contains the mouse position.
1643 * Also find the position of the cursor hot spot (hittest) */
1644 if (!IsWindow(hWndScope)) hWndScope = 0;
1645 if (!(msg->hwnd = WINPOS_WindowFromPoint( hWndScope, msg->pt, &hittest )))
1646 msg->hwnd = GetDesktopWindow();
1649 event.message = msg->message;
1650 event.time = msg->time;
1651 event.hwnd = msg->hwnd;
1652 event.paramL = msg->pt.x;
1653 event.paramH = msg->pt.y;
1654 HOOK_CallHooks( WH_JOURNALRECORD, HC_ACTION, 0, (LPARAM)&event, TRUE );
1658 if (msg->hwnd != hwnd_filter && !IsChild( hwnd_filter, msg->hwnd )) return FALSE;
1662 message = msg->message;
1663 /* Note: windows has no concept of a non-client wheel message */
1664 if (message != WM_MOUSEWHEEL)
1666 if (hittest != HTCLIENT)
1668 message += WM_NCMOUSEMOVE - WM_MOUSEMOVE;
1669 msg->wParam = hittest;
1673 /* coordinates don't get translated while tracking a menu */
1674 /* FIXME: should differentiate popups and top-level menus */
1675 if (!(info.flags & GUI_INMENUMODE))
1676 ScreenToClient( msg->hwnd, &pt );
1679 msg->lParam = MAKELONG( pt.x, pt.y );
1681 /* translate double clicks */
1683 if ((msg->message == WM_LBUTTONDOWN) ||
1684 (msg->message == WM_RBUTTONDOWN) ||
1685 (msg->message == WM_MBUTTONDOWN))
1687 /* translate double clicks -
1688 * note that ...MOUSEMOVEs can slip in between
1689 * ...BUTTONDOWN and ...BUTTONDBLCLK messages */
1691 if ((info.flags & (GUI_INMENUMODE|GUI_INMOVESIZE)) ||
1692 hittest != HTCLIENT ||
1693 (GetClassLongA( msg->hwnd, GCL_STYLE ) & CS_DBLCLKS))
1695 if ((msg->message == clk_msg.message) &&
1696 (msg->hwnd == clk_msg.hwnd) &&
1697 (msg->time - clk_msg.time < GetDoubleClickTime()) &&
1698 (abs(msg->pt.x - clk_msg.pt.x) < GetSystemMetrics(SM_CXDOUBLECLK)/2) &&
1699 (abs(msg->pt.y - clk_msg.pt.y) < GetSystemMetrics(SM_CYDOUBLECLK)/2))
1701 message += (WM_LBUTTONDBLCLK - WM_LBUTTONDOWN);
1702 msg->message = 0; /* to clear the double click conditions */
1707 if (message < first || message > last) remove = FALSE;
1709 /* update static double click conditions */
1710 if (remove) clk_msg = *msg;
1713 msg->message = message;
1714 if (first || last) return (message >= first && message <= last);
1719 /***********************************************************************
1720 * process_cooked_mouse_message
1722 * returns TRUE if the contents of 'msg' should be passed to the application
1724 static BOOL process_cooked_mouse_message( MSG *msg, ULONG_PTR extra_info, BOOL remove )
1726 MOUSEHOOKSTRUCT hook;
1727 INT hittest = HTCLIENT;
1728 UINT raw_message = msg->message;
1731 if (msg->message >= WM_NCMOUSEFIRST && msg->message <= WM_NCMOUSELAST)
1733 raw_message += WM_MOUSEFIRST - WM_NCMOUSEFIRST;
1734 hittest = msg->wParam;
1736 if (raw_message == WM_LBUTTONDBLCLK ||
1737 raw_message == WM_RBUTTONDBLCLK ||
1738 raw_message == WM_MBUTTONDBLCLK)
1740 raw_message += WM_LBUTTONDOWN - WM_LBUTTONDBLCLK;
1744 hook.hwnd = msg->hwnd;
1745 hook.wHitTestCode = hittest;
1746 hook.dwExtraInfo = extra_info;
1747 if (HOOK_CallHooks( WH_MOUSE, remove ? HC_ACTION : HC_NOREMOVE,
1748 msg->message, (LPARAM)&hook, TRUE ))
1751 hook.hwnd = msg->hwnd;
1752 hook.wHitTestCode = hittest;
1753 hook.dwExtraInfo = extra_info;
1754 HOOK_CallHooks( WH_CBT, HCBT_CLICKSKIPPED, msg->message, (LPARAM)&hook, TRUE );
1758 if ((hittest == HTERROR) || (hittest == HTNOWHERE))
1760 SendMessageW( msg->hwnd, WM_SETCURSOR, (WPARAM)msg->hwnd,
1761 MAKELONG( hittest, raw_message ));
1765 if (!remove || GetCapture()) return TRUE;
1769 if ((raw_message == WM_LBUTTONDOWN) ||
1770 (raw_message == WM_RBUTTONDOWN) ||
1771 (raw_message == WM_MBUTTONDOWN))
1773 /* Send the WM_PARENTNOTIFY,
1774 * note that even for double/nonclient clicks
1775 * notification message is still WM_L/M/RBUTTONDOWN.
1777 send_parent_notify( msg->hwnd, raw_message, 0, msg->pt );
1779 /* Activate the window if needed */
1781 if (msg->hwnd != GetActiveWindow())
1783 HWND hwndTop = msg->hwnd;
1786 if ((GetWindowLongW( hwndTop, GWL_STYLE ) & (WS_POPUP|WS_CHILD)) != WS_CHILD) break;
1787 hwndTop = GetParent( hwndTop );
1790 if (hwndTop && hwndTop != GetDesktopWindow())
1792 LONG ret = SendMessageW( msg->hwnd, WM_MOUSEACTIVATE, (WPARAM)hwndTop,
1793 MAKELONG( hittest, raw_message ) );
1796 case MA_NOACTIVATEANDEAT:
1801 case MA_ACTIVATEANDEAT:
1806 if (!FOCUS_MouseActivate( hwndTop )) eatMsg = TRUE;
1809 WARN( "unknown WM_MOUSEACTIVATE code %ld\n", ret );
1816 /* send the WM_SETCURSOR message */
1818 /* Windows sends the normal mouse message as the message parameter
1819 in the WM_SETCURSOR message even if it's non-client mouse message */
1820 SendMessageW( msg->hwnd, WM_SETCURSOR, (WPARAM)msg->hwnd,
1821 MAKELONG( hittest, raw_message ));
1827 /***********************************************************************
1828 * process_hardware_message
1830 * Process a hardware message; return TRUE if message should be passed on to the app
1832 static BOOL process_hardware_message( MSG *msg, ULONG_PTR extra_info, HWND hwnd,
1833 UINT first, UINT last, BOOL remove )
1837 if (is_keyboard_message( msg->message ))
1839 if (!process_raw_keyboard_message( msg, hwnd, first, last )) return FALSE;
1840 ret = process_cooked_keyboard_message( msg, remove );
1842 else if (is_mouse_message( msg->message ))
1844 if (!process_raw_mouse_message( msg, hwnd, first, last, remove )) return FALSE;
1845 ret = process_cooked_mouse_message( msg, extra_info, remove );
1849 ERR( "unknown message type %x\n", msg->message );
1853 /* tell the server we have passed it to the app
1854 * (even though we may end up dropping it later on)
1856 SERVER_START_REQ( reply_message )
1858 req->type = MSG_HARDWARE;
1860 req->remove = remove || !ret;
1861 if (wine_server_call( req ))
1862 FIXME("Failed to reply to MSG_HARDWARE message. Message may not be removed from queue.\n");
1869 /***********************************************************************
1870 * call_sendmsg_callback
1872 * Call the callback function of SendMessageCallback.
1874 static inline void call_sendmsg_callback( SENDASYNCPROC callback, HWND hwnd, UINT msg,
1875 ULONG_PTR data, LRESULT result )
1877 if (TRACE_ON(relay))
1878 DPRINTF( "%04lx:Call message callback %p (hwnd=%p,msg=%s,data=%08lx,result=%08lx)\n",
1879 GetCurrentThreadId(), callback, hwnd, SPY_GetMsgName( msg, hwnd ),
1881 callback( hwnd, msg, data, result );
1882 if (TRACE_ON(relay))
1883 DPRINTF( "%04lx:Ret message callback %p (hwnd=%p,msg=%s,data=%08lx,result=%08lx)\n",
1884 GetCurrentThreadId(), callback, hwnd, SPY_GetMsgName( msg, hwnd ),
1889 /***********************************************************************
1892 * Retrieve the hook procedure real value for a module-relative proc
1894 static void *get_hook_proc( void *proc, const WCHAR *module )
1898 if (!(mod = GetModuleHandleW(module)))
1900 TRACE( "loading %s\n", debugstr_w(module) );
1901 /* FIXME: the library will never be freed */
1902 if (!(mod = LoadLibraryW(module))) return NULL;
1904 return (char *)mod + (ULONG_PTR)proc;
1908 /***********************************************************************
1911 * Peek for a message matching the given parameters. Return FALSE if none available.
1912 * All pending sent messages are processed before returning.
1914 static BOOL peek_message( MSG *msg, HWND hwnd, UINT first, UINT last, int flags )
1917 ULONG_PTR extra_info = 0;
1918 MESSAGEQUEUE *queue = QUEUE_Current();
1919 struct received_message_info info, *old_info;
1920 int get_next_hw = 0; /* set when the previous message was a rejected hardware message */
1922 if (!first && !last) last = ~0;
1927 void *buffer = NULL;
1928 size_t size = 0, buffer_size = 0;
1930 do /* loop while buffer is too small */
1932 if (buffer_size && !(buffer = HeapAlloc( GetProcessHeap(), 0, buffer_size )))
1934 SERVER_START_REQ( get_message )
1937 req->get_win = hwnd;
1938 req->get_first = first;
1939 req->get_last = last;
1940 req->get_next_hw = get_next_hw;
1941 if (buffer_size) wine_server_set_reply( req, buffer, buffer_size );
1942 if (!(res = wine_server_call( req )))
1944 size = wine_server_reply_size( reply );
1945 info.type = reply->type;
1946 info.msg.hwnd = reply->win;
1947 info.msg.message = reply->msg;
1948 info.msg.wParam = reply->wparam;
1949 info.msg.lParam = reply->lparam;
1950 info.msg.time = reply->time;
1951 info.msg.pt.x = reply->x;
1952 info.msg.pt.y = reply->y;
1953 info.hook = reply->hook;
1954 info.hook_proc = reply->hook_proc;
1955 extra_info = reply->info;
1959 HeapFree( GetProcessHeap(), 0, buffer );
1960 buffer_size = reply->total;
1964 } while (res == STATUS_BUFFER_OVERFLOW);
1966 if (res) return FALSE;
1969 TRACE( "got type %d msg %x (%s) hwnd %p wp %x lp %lx\n",
1970 info.type, info.msg.message,
1971 (info.type == MSG_WINEVENT) ? "MSG_WINEVENT" : SPY_GetMsgName(info.msg.message, info.msg.hwnd),
1972 info.msg.hwnd, info.msg.wParam, info.msg.lParam );
1978 info.flags = ISMEX_SEND;
1981 info.flags = ISMEX_NOTIFY;
1984 info.flags = ISMEX_CALLBACK;
1986 case MSG_CALLBACK_RESULT:
1987 call_sendmsg_callback( (SENDASYNCPROC)info.msg.wParam, info.msg.hwnd,
1988 info.msg.message, extra_info, info.msg.lParam );
1993 WCHAR module[MAX_PATH];
1994 size = min( size, (MAX_PATH - 1) * sizeof(WCHAR) );
1995 memcpy( module, buffer, size );
1996 module[size / sizeof(WCHAR)] = 0;
1997 if (!(info.hook_proc = get_hook_proc( info.hook_proc, module )))
1999 ERR( "invalid winevent hook module name %s\n", debugstr_w(module) );
2003 if (TRACE_ON(relay))
2004 DPRINTF( "%04lx:Call winevent proc %p (hook=%p,event=%x,hwnd=%p,object_id=%x,child_id=%lx,tid=%04lx,time=%lx)\n",
2005 GetCurrentThreadId(), info.hook_proc,
2006 info.hook, info.msg.message, info.msg.hwnd, info.msg.wParam,
2007 info.msg.lParam, extra_info, info.msg.time);
2009 info.hook_proc( info.hook, info.msg.message, info.msg.hwnd, info.msg.wParam,
2010 info.msg.lParam, extra_info, info.msg.time );
2012 if (TRACE_ON(relay))
2013 DPRINTF( "%04lx:Ret winevent proc %p (hook=%p,event=%x,hwnd=%p,object_id=%x,child_id=%lx,tid=%04lx,time=%lx)\n",
2014 GetCurrentThreadId(), info.hook_proc,
2015 info.hook, info.msg.message, info.msg.hwnd, info.msg.wParam,
2016 info.msg.lParam, extra_info, info.msg.time);
2018 case MSG_OTHER_PROCESS:
2019 info.flags = ISMEX_SEND;
2020 if (!unpack_message( info.msg.hwnd, info.msg.message, &info.msg.wParam,
2021 &info.msg.lParam, &buffer, size ))
2023 ERR( "invalid packed message %x (%s) hwnd %p wp %x lp %lx size %d\n",
2024 info.msg.message, SPY_GetMsgName(info.msg.message, info.msg.hwnd), info.msg.hwnd,
2025 info.msg.wParam, info.msg.lParam, size );
2027 reply_message( &info, 0, TRUE );
2033 if (!process_hardware_message( &info.msg, extra_info,
2034 hwnd, first, last, flags & GET_MSG_REMOVE ))
2036 TRACE("dropping msg %x\n", info.msg.message );
2037 goto next; /* ignore it */
2039 queue->GetMessagePosVal = MAKELONG( info.msg.pt.x, info.msg.pt.y );
2042 queue->GetMessageExtraInfoVal = extra_info;
2043 if (info.msg.message >= WM_DDE_FIRST && info.msg.message <= WM_DDE_LAST)
2045 if (!unpack_dde_message( info.msg.hwnd, info.msg.message, &info.msg.wParam,
2046 &info.msg.lParam, &buffer, size ))
2048 ERR( "invalid packed dde-message %x (%s) hwnd %p wp %x lp %lx size %d\n",
2049 info.msg.message, SPY_GetMsgName(info.msg.message, info.msg.hwnd),
2050 info.msg.hwnd, info.msg.wParam, info.msg.lParam, size );
2051 goto next; /* ignore it */
2055 HeapFree( GetProcessHeap(), 0, buffer );
2059 /* if we get here, we have a sent message; call the window procedure */
2060 old_info = queue->receive_info;
2061 queue->receive_info = &info;
2062 result = call_window_proc( info.msg.hwnd, info.msg.message, info.msg.wParam,
2063 info.msg.lParam, (info.type != MSG_ASCII), FALSE );
2064 reply_message( &info, result, TRUE );
2065 queue->receive_info = old_info;
2067 HeapFree( GetProcessHeap(), 0, buffer );
2072 /***********************************************************************
2073 * process_sent_messages
2075 * Process all pending sent messages.
2077 inline static void process_sent_messages(void)
2080 peek_message( &msg, 0, 0, 0, GET_MSG_REMOVE | GET_MSG_SENT_ONLY );
2084 /***********************************************************************
2085 * wait_message_reply
2087 * Wait until a sent message gets replied to.
2089 static void wait_message_reply( UINT flags )
2091 MESSAGEQUEUE *queue;
2093 if (!(queue = QUEUE_Current())) return;
2097 unsigned int wake_bits = 0, changed_bits = 0;
2100 SERVER_START_REQ( set_queue_mask )
2102 req->wake_mask = QS_SMRESULT | ((flags & SMTO_BLOCK) ? 0 : QS_SENDMESSAGE);
2103 req->changed_mask = req->wake_mask;
2105 if (!wine_server_call( req ))
2107 wake_bits = reply->wake_bits;
2108 changed_bits = reply->changed_bits;
2113 if (wake_bits & QS_SMRESULT) return; /* got a result */
2114 if (wake_bits & QS_SENDMESSAGE)
2116 /* Process the sent message immediately */
2117 process_sent_messages();
2121 /* now wait for it */
2123 ReleaseThunkLock( &dwlc );
2125 if (USER_Driver.pMsgWaitForMultipleObjectsEx)
2126 res = USER_Driver.pMsgWaitForMultipleObjectsEx( 1, &queue->server_queue,
2127 INFINITE, QS_ALLINPUT, 0 );
2129 res = WaitForSingleObject( queue->server_queue, INFINITE );
2131 if (dwlc) RestoreThunkLock( dwlc );
2135 /***********************************************************************
2136 * put_message_in_queue
2138 * Put a sent message into the destination queue.
2139 * For inter-process message, reply_size is set to expected size of reply data.
2141 static BOOL put_message_in_queue( DWORD dest_tid, const struct send_message_info *info,
2142 size_t *reply_size )
2144 struct packed_message data;
2146 int i, timeout = -1;
2148 if (info->type != MSG_NOTIFY &&
2149 info->type != MSG_CALLBACK &&
2150 info->type != MSG_POSTED &&
2151 info->timeout != INFINITE)
2152 timeout = info->timeout;
2155 if (info->type == MSG_OTHER_PROCESS)
2157 *reply_size = pack_message( info->hwnd, info->msg, info->wparam, info->lparam, &data );
2158 if (data.count == -1)
2160 WARN( "cannot pack message %x\n", info->msg );
2164 else if (info->type == MSG_POSTED && info->msg >= WM_DDE_FIRST && info->msg <= WM_DDE_LAST)
2166 return post_dde_message( dest_tid, &data, info );
2169 SERVER_START_REQ( send_message )
2172 req->type = info->type;
2174 req->win = info->hwnd;
2175 req->msg = info->msg;
2176 req->wparam = info->wparam;
2177 req->lparam = info->lparam;
2178 req->time = GetCurrentTime();
2179 req->timeout = timeout;
2181 if (info->type == MSG_CALLBACK)
2183 req->callback = info->callback;
2184 req->info = info->data;
2187 if (info->flags & SMTO_ABORTIFHUNG) req->flags |= SEND_MSG_ABORT_IF_HUNG;
2188 for (i = 0; i < data.count; i++) wine_server_add_data( req, data.data[i], data.size[i] );
2189 if ((res = wine_server_call( req )))
2191 if (res == STATUS_INVALID_PARAMETER)
2192 /* FIXME: find a STATUS_ value for this one */
2193 SetLastError( ERROR_INVALID_THREAD_ID );
2195 SetLastError( RtlNtStatusToDosError(res) );
2203 /***********************************************************************
2206 * Retrieve a message reply from the server.
2208 static LRESULT retrieve_reply( const struct send_message_info *info,
2209 size_t reply_size, LRESULT *result )
2212 void *reply_data = NULL;
2216 if (!(reply_data = HeapAlloc( GetProcessHeap(), 0, reply_size )))
2218 WARN( "no memory for reply %d bytes, will be truncated\n", reply_size );
2222 SERVER_START_REQ( get_message_reply )
2225 if (reply_size) wine_server_set_reply( req, reply_data, reply_size );
2226 if (!(status = wine_server_call( req ))) *result = reply->result;
2227 reply_size = wine_server_reply_size( reply );
2230 if (!status && reply_size)
2231 unpack_reply( info->hwnd, info->msg, info->wparam, info->lparam, reply_data, reply_size );
2233 HeapFree( GetProcessHeap(), 0, reply_data );
2235 TRACE( "hwnd %p msg %x (%s) wp %x lp %lx got reply %lx (err=%ld)\n",
2236 info->hwnd, info->msg, SPY_GetMsgName(info->msg, info->hwnd), info->wparam,
2237 info->lparam, *result, status );
2239 /* MSDN states that last error is 0 on timeout, but at least NT4 returns ERROR_TIMEOUT */
2240 if (status) SetLastError( RtlNtStatusToDosError(status) );
2245 /***********************************************************************
2246 * send_inter_thread_message
2248 static LRESULT send_inter_thread_message( DWORD dest_tid, const struct send_message_info *info,
2253 size_t reply_size = 0;
2255 TRACE( "hwnd %p msg %x (%s) wp %x lp %lx\n",
2256 info->hwnd, info->msg, SPY_GetMsgName(info->msg, info->hwnd), info->wparam, info->lparam );
2258 if (!put_message_in_queue( dest_tid, info, &reply_size )) return 0;
2260 /* there's no reply to wait for on notify/callback messages */
2261 if (info->type == MSG_NOTIFY || info->type == MSG_CALLBACK) return 1;
2263 locks = WIN_SuspendWndsLock();
2265 wait_message_reply( info->flags );
2266 ret = retrieve_reply( info, reply_size, res_ptr );
2268 WIN_RestoreWndsLock( locks );
2273 /***********************************************************************
2274 * MSG_SendInternalMessageTimeout
2276 * Same as SendMessageTimeoutW but sends the message to a specific thread
2277 * without requiring a window handle. Only works for internal Wine messages.
2279 LRESULT MSG_SendInternalMessageTimeout( DWORD dest_pid, DWORD dest_tid,
2280 UINT msg, WPARAM wparam, LPARAM lparam,
2281 UINT flags, UINT timeout, PDWORD_PTR res_ptr )
2283 struct send_message_info info;
2284 LRESULT ret, result;
2286 assert( msg & 0x80000000 ); /* must be an internal Wine message */
2288 info.type = MSG_UNICODE;
2291 info.wparam = wparam;
2292 info.lparam = lparam;
2294 info.timeout = timeout;
2296 if (USER_IsExitingThread( dest_tid )) return 0;
2298 if (dest_tid == GetCurrentThreadId())
2300 result = handle_internal_message( 0, msg, wparam, lparam );
2305 if (dest_pid != GetCurrentProcessId()) info.type = MSG_OTHER_PROCESS;
2306 ret = send_inter_thread_message( dest_tid, &info, &result );
2308 if (ret && res_ptr) *res_ptr = result;
2313 /***********************************************************************
2314 * SendMessageTimeoutW (USER32.@)
2316 LRESULT WINAPI SendMessageTimeoutW( HWND hwnd, UINT msg, WPARAM wparam, LPARAM lparam,
2317 UINT flags, UINT timeout, PDWORD_PTR res_ptr )
2319 struct send_message_info info;
2320 DWORD dest_tid, dest_pid;
2321 LRESULT ret, result;
2323 info.type = MSG_UNICODE;
2326 info.wparam = wparam;
2327 info.lparam = lparam;
2329 info.timeout = timeout;
2331 if (is_broadcast(hwnd))
2333 EnumWindows( broadcast_message_callback, (LPARAM)&info );
2334 if (res_ptr) *res_ptr = 1;
2338 if (!(dest_tid = GetWindowThreadProcessId( hwnd, &dest_pid ))) return 0;
2340 if (USER_IsExitingThread( dest_tid )) return 0;
2342 SPY_EnterMessage( SPY_SENDMESSAGE, hwnd, msg, wparam, lparam );
2344 if (dest_tid == GetCurrentThreadId())
2346 result = call_window_proc( hwnd, msg, wparam, lparam, TRUE, TRUE );
2351 if (dest_pid != GetCurrentProcessId()) info.type = MSG_OTHER_PROCESS;
2352 ret = send_inter_thread_message( dest_tid, &info, &result );
2355 SPY_ExitMessage( SPY_RESULT_OK, hwnd, msg, result, wparam, lparam );
2356 if (ret && res_ptr) *res_ptr = result;
2361 /***********************************************************************
2362 * SendMessageTimeoutA (USER32.@)
2364 LRESULT WINAPI SendMessageTimeoutA( HWND hwnd, UINT msg, WPARAM wparam, LPARAM lparam,
2365 UINT flags, UINT timeout, PDWORD_PTR res_ptr )
2367 struct send_message_info info;
2368 DWORD dest_tid, dest_pid;
2369 LRESULT ret, result;
2371 info.type = MSG_ASCII;
2374 info.wparam = wparam;
2375 info.lparam = lparam;
2377 info.timeout = timeout;
2379 if (is_broadcast(hwnd))
2381 EnumWindows( broadcast_message_callback, (LPARAM)&info );
2382 if (res_ptr) *res_ptr = 1;
2386 if (!(dest_tid = GetWindowThreadProcessId( hwnd, &dest_pid ))) return 0;
2388 if (USER_IsExitingThread( dest_tid )) return 0;
2390 SPY_EnterMessage( SPY_SENDMESSAGE, hwnd, msg, wparam, lparam );
2392 if (dest_tid == GetCurrentThreadId())
2394 result = call_window_proc( hwnd, msg, wparam, lparam, FALSE, TRUE );
2397 else if (dest_pid == GetCurrentProcessId())
2399 ret = send_inter_thread_message( dest_tid, &info, &result );
2403 /* inter-process message: need to map to Unicode */
2404 info.type = MSG_OTHER_PROCESS;
2405 if (is_unicode_message( info.msg ))
2407 if (WINPROC_MapMsg32ATo32W( info.hwnd, info.msg, &info.wparam, &info.lparam ) == -1)
2409 ret = send_inter_thread_message( dest_tid, &info, &result );
2410 result = WINPROC_UnmapMsg32ATo32W( info.hwnd, info.msg, info.wparam,
2411 info.lparam, result );
2413 else ret = send_inter_thread_message( dest_tid, &info, &result );
2415 SPY_ExitMessage( SPY_RESULT_OK, hwnd, msg, result, wparam, lparam );
2416 if (ret && res_ptr) *res_ptr = result;
2421 /***********************************************************************
2422 * SendMessageW (USER32.@)
2424 LRESULT WINAPI SendMessageW( HWND hwnd, UINT msg, WPARAM wparam, LPARAM lparam )
2427 SendMessageTimeoutW( hwnd, msg, wparam, lparam, SMTO_NORMAL, INFINITE, &res );
2432 /***********************************************************************
2433 * SendMessageA (USER32.@)
2435 LRESULT WINAPI SendMessageA( HWND hwnd, UINT msg, WPARAM wparam, LPARAM lparam )
2438 SendMessageTimeoutA( hwnd, msg, wparam, lparam, SMTO_NORMAL, INFINITE, &res );
2443 /***********************************************************************
2444 * SendNotifyMessageA (USER32.@)
2446 BOOL WINAPI SendNotifyMessageA( HWND hwnd, UINT msg, WPARAM wparam, LPARAM lparam )
2448 return SendNotifyMessageW( hwnd, msg, map_wparam_AtoW( msg, wparam ), lparam );
2452 /***********************************************************************
2453 * SendNotifyMessageW (USER32.@)
2455 BOOL WINAPI SendNotifyMessageW( HWND hwnd, UINT msg, WPARAM wparam, LPARAM lparam )
2457 struct send_message_info info;
2461 if (is_pointer_message(msg))
2463 SetLastError( ERROR_MESSAGE_SYNC_ONLY );
2467 info.type = MSG_NOTIFY;
2470 info.wparam = wparam;
2471 info.lparam = lparam;
2474 if (is_broadcast(hwnd))
2476 EnumWindows( broadcast_message_callback, (LPARAM)&info );
2480 if (!(dest_tid = GetWindowThreadProcessId( hwnd, NULL ))) return FALSE;
2482 if (USER_IsExitingThread( dest_tid )) return TRUE;
2484 if (dest_tid == GetCurrentThreadId())
2486 call_window_proc( hwnd, msg, wparam, lparam, TRUE, TRUE );
2489 return send_inter_thread_message( dest_tid, &info, &result );
2493 /***********************************************************************
2494 * SendMessageCallbackA (USER32.@)
2496 BOOL WINAPI SendMessageCallbackA( HWND hwnd, UINT msg, WPARAM wparam, LPARAM lparam,
2497 SENDASYNCPROC callback, ULONG_PTR data )
2499 return SendMessageCallbackW( hwnd, msg, map_wparam_AtoW( msg, wparam ),
2500 lparam, callback, data );
2504 /***********************************************************************
2505 * SendMessageCallbackW (USER32.@)
2507 BOOL WINAPI SendMessageCallbackW( HWND hwnd, UINT msg, WPARAM wparam, LPARAM lparam,
2508 SENDASYNCPROC callback, ULONG_PTR data )
2510 struct send_message_info info;
2514 if (is_pointer_message(msg))
2516 SetLastError( ERROR_MESSAGE_SYNC_ONLY );
2520 info.type = MSG_CALLBACK;
2523 info.wparam = wparam;
2524 info.lparam = lparam;
2525 info.callback = callback;
2529 if (is_broadcast(hwnd))
2531 EnumWindows( broadcast_message_callback, (LPARAM)&info );
2535 if (!(dest_tid = GetWindowThreadProcessId( hwnd, NULL ))) return FALSE;
2537 if (USER_IsExitingThread( dest_tid )) return TRUE;
2539 if (dest_tid == GetCurrentThreadId())
2541 result = call_window_proc( hwnd, msg, wparam, lparam, TRUE, TRUE );
2542 call_sendmsg_callback( callback, hwnd, msg, data, result );
2545 FIXME( "callback will not be called\n" );
2546 return send_inter_thread_message( dest_tid, &info, &result );
2550 /***********************************************************************
2551 * ReplyMessage (USER32.@)
2553 BOOL WINAPI ReplyMessage( LRESULT result )
2555 MESSAGEQUEUE *queue = QUEUE_Current();
2556 struct received_message_info *info = queue->receive_info;
2558 if (!info) return FALSE;
2559 reply_message( info, result, FALSE );
2564 /***********************************************************************
2565 * InSendMessage (USER32.@)
2567 BOOL WINAPI InSendMessage(void)
2569 return (InSendMessageEx(NULL) & (ISMEX_SEND|ISMEX_REPLIED)) == ISMEX_SEND;
2573 /***********************************************************************
2574 * InSendMessageEx (USER32.@)
2576 DWORD WINAPI InSendMessageEx( LPVOID reserved )
2578 MESSAGEQUEUE *queue = QUEUE_Current();
2579 struct received_message_info *info = queue->receive_info;
2581 if (info) return info->flags;
2582 return ISMEX_NOSEND;
2586 /***********************************************************************
2587 * PostMessageA (USER32.@)
2589 BOOL WINAPI PostMessageA( HWND hwnd, UINT msg, WPARAM wparam, LPARAM lparam )
2591 return PostMessageW( hwnd, msg, map_wparam_AtoW( msg, wparam ), lparam );
2595 /***********************************************************************
2596 * PostMessageW (USER32.@)
2598 BOOL WINAPI PostMessageW( HWND hwnd, UINT msg, WPARAM wparam, LPARAM lparam )
2600 struct send_message_info info;
2603 if (is_pointer_message( msg ))
2605 SetLastError( ERROR_MESSAGE_SYNC_ONLY );
2609 TRACE( "hwnd %p msg %x (%s) wp %x lp %lx\n",
2610 hwnd, msg, SPY_GetMsgName(msg, hwnd), wparam, lparam );
2612 info.type = MSG_POSTED;
2615 info.wparam = wparam;
2616 info.lparam = lparam;
2619 if (is_broadcast(hwnd))
2621 EnumWindows( broadcast_message_callback, (LPARAM)&info );
2625 if (!hwnd) return PostThreadMessageW( GetCurrentThreadId(), msg, wparam, lparam );
2627 if (!(dest_tid = GetWindowThreadProcessId( hwnd, NULL ))) return FALSE;
2629 if (USER_IsExitingThread( dest_tid )) return TRUE;
2631 return put_message_in_queue( dest_tid, &info, NULL );
2635 /**********************************************************************
2636 * PostThreadMessageA (USER32.@)
2638 BOOL WINAPI PostThreadMessageA( DWORD thread, UINT msg, WPARAM wparam, LPARAM lparam )
2640 return PostThreadMessageW( thread, msg, map_wparam_AtoW( msg, wparam ), lparam );
2644 /**********************************************************************
2645 * PostThreadMessageW (USER32.@)
2647 BOOL WINAPI PostThreadMessageW( DWORD thread, UINT msg, WPARAM wparam, LPARAM lparam )
2649 struct send_message_info info;
2651 if (is_pointer_message( msg ))
2653 SetLastError( ERROR_MESSAGE_SYNC_ONLY );
2656 if (USER_IsExitingThread( thread )) return TRUE;
2658 info.type = MSG_POSTED;
2661 info.wparam = wparam;
2662 info.lparam = lparam;
2664 return put_message_in_queue( thread, &info, NULL );
2668 /***********************************************************************
2669 * PostQuitMessage (USER32.@)
2671 void WINAPI PostQuitMessage( INT exitCode )
2673 PostThreadMessageW( GetCurrentThreadId(), WM_QUIT, exitCode, 0 );
2677 /***********************************************************************
2678 * PeekMessageW (USER32.@)
2680 BOOL WINAPI PeekMessageW( MSG *msg_out, HWND hwnd, UINT first, UINT last, UINT flags )
2682 MESSAGEQUEUE *queue;
2686 /* check for graphics events */
2687 if (USER_Driver.pMsgWaitForMultipleObjectsEx)
2688 USER_Driver.pMsgWaitForMultipleObjectsEx( 0, NULL, 0, QS_ALLINPUT, 0 );
2690 hwnd = WIN_GetFullHandle( hwnd );
2691 locks = WIN_SuspendWndsLock();
2693 if (!peek_message( &msg, hwnd, first, last, (flags & PM_REMOVE) ? GET_MSG_REMOVE : 0 ))
2695 if (!(flags & PM_NOYIELD))
2698 ReleaseThunkLock(&count);
2699 if (count) RestoreThunkLock(count);
2701 WIN_RestoreWndsLock( locks );
2705 if ((queue = QUEUE_Current()))
2707 queue->GetMessageTimeVal = msg.time;
2708 msg.pt.x = LOWORD( queue->GetMessagePosVal );
2709 msg.pt.y = HIWORD( queue->GetMessagePosVal );
2712 HOOK_CallHooks( WH_GETMESSAGE, HC_ACTION, flags & PM_REMOVE, (LPARAM)&msg, TRUE );
2714 WIN_RestoreWndsLock( locks );
2716 /* copy back our internal safe copy of message data to msg_out.
2717 * msg_out is a variable from the *program*, so it can't be used
2718 * internally as it can get "corrupted" by our use of SendMessage()
2719 * (back to the program) inside the message handling itself. */
2722 SetLastError( ERROR_NOACCESS );
2730 /***********************************************************************
2731 * PeekMessageA (USER32.@)
2733 BOOL WINAPI PeekMessageA( MSG *msg, HWND hwnd, UINT first, UINT last, UINT flags )
2735 BOOL ret = PeekMessageW( msg, hwnd, first, last, flags );
2736 if (ret) msg->wParam = map_wparam_WtoA( msg->message, msg->wParam );
2741 /***********************************************************************
2742 * GetMessageW (USER32.@)
2744 BOOL WINAPI GetMessageW( MSG *msg, HWND hwnd, UINT first, UINT last )
2746 MESSAGEQUEUE *queue = QUEUE_Current();
2749 mask = QS_POSTMESSAGE | QS_SENDMESSAGE; /* Always selected */
2752 if ((first <= WM_KEYLAST) && (last >= WM_KEYFIRST)) mask |= QS_KEY;
2753 if ( ((first <= WM_MOUSELAST) && (last >= WM_MOUSEFIRST)) ||
2754 ((first <= WM_NCMOUSELAST) && (last >= WM_NCMOUSEFIRST)) ) mask |= QS_MOUSE;
2755 if ((first <= WM_TIMER) && (last >= WM_TIMER)) mask |= QS_TIMER;
2756 if ((first <= WM_SYSTIMER) && (last >= WM_SYSTIMER)) mask |= QS_TIMER;
2757 if ((first <= WM_PAINT) && (last >= WM_PAINT)) mask |= QS_PAINT;
2759 else mask |= QS_MOUSE | QS_KEY | QS_TIMER | QS_PAINT;
2761 locks = WIN_SuspendWndsLock();
2763 while (!PeekMessageW( msg, hwnd, first, last, PM_REMOVE ))
2765 /* wait until one of the bits is set */
2766 unsigned int wake_bits = 0, changed_bits = 0;
2769 SERVER_START_REQ( set_queue_mask )
2771 req->wake_mask = QS_SENDMESSAGE;
2772 req->changed_mask = mask;
2774 if (!wine_server_call( req ))
2776 wake_bits = reply->wake_bits;
2777 changed_bits = reply->changed_bits;
2782 if (changed_bits & mask) continue;
2783 if (wake_bits & QS_SENDMESSAGE) continue;
2785 TRACE( "(%04x) mask=%08x, bits=%08x, changed=%08x, waiting\n",
2786 queue->self, mask, wake_bits, changed_bits );
2788 ReleaseThunkLock( &dwlc );
2789 if (USER_Driver.pMsgWaitForMultipleObjectsEx)
2790 USER_Driver.pMsgWaitForMultipleObjectsEx( 1, &queue->server_queue, INFINITE,
2793 WaitForSingleObject( queue->server_queue, INFINITE );
2794 if (dwlc) RestoreThunkLock( dwlc );
2797 WIN_RestoreWndsLock( locks );
2799 return (msg->message != WM_QUIT);
2803 /***********************************************************************
2804 * GetMessageA (USER32.@)
2806 BOOL WINAPI GetMessageA( MSG *msg, HWND hwnd, UINT first, UINT last )
2808 GetMessageW( msg, hwnd, first, last );
2809 msg->wParam = map_wparam_WtoA( msg->message, msg->wParam );
2810 return (msg->message != WM_QUIT);
2814 /***********************************************************************
2815 * IsDialogMessage (USER32.@)
2816 * IsDialogMessageA (USER32.@)
2818 BOOL WINAPI IsDialogMessageA( HWND hwndDlg, LPMSG pmsg )
2821 msg.wParam = map_wparam_AtoW( msg.message, msg.wParam );
2822 return IsDialogMessageW( hwndDlg, &msg );
2826 /***********************************************************************
2827 * TranslateMessage (USER32.@)
2829 * Implementation of TranslateMessage.
2831 * TranslateMessage translates virtual-key messages into character-messages,
2833 * WM_KEYDOWN/WM_KEYUP combinations produce a WM_CHAR or WM_DEADCHAR message.
2834 * ditto replacing WM_* with WM_SYS*
2835 * This produces WM_CHAR messages only for keys mapped to ASCII characters
2836 * by the keyboard driver.
2838 * If the message is WM_KEYDOWN, WM_KEYUP, WM_SYSKEYDOWN, or WM_SYSKEYUP, the
2839 * return value is nonzero, regardless of the translation.
2842 BOOL WINAPI TranslateMessage( const MSG *msg )
2848 if (msg->message < WM_KEYFIRST || msg->message > WM_KEYLAST) return FALSE;
2849 if (msg->message != WM_KEYDOWN && msg->message != WM_SYSKEYDOWN) return TRUE;
2851 TRACE_(key)("Translating key %s (%04x), scancode %02x\n",
2852 SPY_GetVKeyName(msg->wParam), msg->wParam, LOBYTE(HIWORD(msg->lParam)));
2854 GetKeyboardState( state );
2855 /* FIXME : should handle ToUnicode yielding 2 */
2856 switch (ToUnicode(msg->wParam, HIWORD(msg->lParam), state, wp, 2, 0))
2859 message = (msg->message == WM_KEYDOWN) ? WM_CHAR : WM_SYSCHAR;
2860 TRACE_(key)("1 -> PostMessageW(%p,%s,%04x,%08lx)\n",
2861 msg->hwnd, SPY_GetMsgName(message, msg->hwnd), wp[0], msg->lParam);
2862 PostMessageW( msg->hwnd, message, wp[0], msg->lParam );
2866 message = (msg->message == WM_KEYDOWN) ? WM_DEADCHAR : WM_SYSDEADCHAR;
2867 TRACE_(key)("-1 -> PostMessageW(%p,%s,%04x,%08lx)\n",
2868 msg->hwnd, SPY_GetMsgName(message, msg->hwnd), wp[0], msg->lParam);
2869 PostMessageW( msg->hwnd, message, wp[0], msg->lParam );
2876 /***********************************************************************
2877 * DispatchMessageA (USER32.@)
2879 LONG WINAPI DispatchMessageA( const MSG* msg )
2885 /* Process timer messages */
2886 if ((msg->message == WM_TIMER) || (msg->message == WM_SYSTIMER))
2888 if (msg->lParam) return CallWindowProcA( (WNDPROC)msg->lParam, msg->hwnd,
2889 msg->message, msg->wParam, GetTickCount() );
2892 if (msg->message & 0x80000000)
2893 return handle_internal_message( msg->hwnd, msg->message, msg->wParam, msg->lParam );
2895 if (!(wndPtr = WIN_GetPtr( msg->hwnd )))
2897 if (msg->hwnd) SetLastError( ERROR_INVALID_WINDOW_HANDLE );
2900 if (wndPtr == WND_OTHER_PROCESS)
2902 if (IsWindow( msg->hwnd )) SetLastError( ERROR_MESSAGE_SYNC_ONLY );
2903 else SetLastError( ERROR_INVALID_WINDOW_HANDLE );
2906 if (wndPtr->tid != GetCurrentThreadId())
2908 SetLastError( ERROR_MESSAGE_SYNC_ONLY );
2909 WIN_ReleasePtr( wndPtr );
2912 winproc = wndPtr->winproc;
2913 WIN_ReleasePtr( wndPtr );
2915 SPY_EnterMessage( SPY_DISPATCHMESSAGE, msg->hwnd, msg->message,
2916 msg->wParam, msg->lParam );
2917 retval = CallWindowProcA( winproc, msg->hwnd, msg->message,
2918 msg->wParam, msg->lParam );
2919 SPY_ExitMessage( SPY_RESULT_OK, msg->hwnd, msg->message, retval,
2920 msg->wParam, msg->lParam );
2922 if (msg->message == WM_PAINT)
2924 /* send a WM_NCPAINT and WM_ERASEBKGND if the non-client area is still invalid */
2925 HRGN hrgn = CreateRectRgn( 0, 0, 0, 0 );
2926 GetUpdateRgn( msg->hwnd, hrgn, TRUE );
2927 DeleteObject( hrgn );
2933 /***********************************************************************
2934 * DispatchMessageW (USER32.@) Process a message
2936 * Process the message specified in the structure *_msg_.
2938 * If the lpMsg parameter points to a WM_TIMER message and the
2939 * parameter of the WM_TIMER message is not NULL, the lParam parameter
2940 * points to the function that is called instead of the window
2943 * The message must be valid.
2947 * DispatchMessage() returns the result of the window procedure invoked.
2954 LONG WINAPI DispatchMessageW( const MSG* msg )
2960 /* Process timer messages */
2961 if ((msg->message == WM_TIMER) || (msg->message == WM_SYSTIMER))
2963 if (msg->lParam) return CallWindowProcW( (WNDPROC)msg->lParam, msg->hwnd,
2964 msg->message, msg->wParam, GetTickCount() );
2967 if (msg->message & 0x80000000)
2968 return handle_internal_message( msg->hwnd, msg->message, msg->wParam, msg->lParam );
2970 if (!(wndPtr = WIN_GetPtr( msg->hwnd )))
2972 if (msg->hwnd) SetLastError( ERROR_INVALID_WINDOW_HANDLE );
2975 if (wndPtr == WND_OTHER_PROCESS)
2977 if (IsWindow( msg->hwnd )) SetLastError( ERROR_MESSAGE_SYNC_ONLY );
2978 else SetLastError( ERROR_INVALID_WINDOW_HANDLE );
2981 if (wndPtr->tid != GetCurrentThreadId())
2983 SetLastError( ERROR_MESSAGE_SYNC_ONLY );
2984 WIN_ReleasePtr( wndPtr );
2987 winproc = wndPtr->winproc;
2988 WIN_ReleasePtr( wndPtr );
2990 SPY_EnterMessage( SPY_DISPATCHMESSAGE, msg->hwnd, msg->message,
2991 msg->wParam, msg->lParam );
2992 retval = CallWindowProcW( winproc, msg->hwnd, msg->message,
2993 msg->wParam, msg->lParam );
2994 SPY_ExitMessage( SPY_RESULT_OK, msg->hwnd, msg->message, retval,
2995 msg->wParam, msg->lParam );
2997 if (msg->message == WM_PAINT)
2999 /* send a WM_NCPAINT and WM_ERASEBKGND if the non-client area is still invalid */
3000 HRGN hrgn = CreateRectRgn( 0, 0, 0, 0 );
3001 GetUpdateRgn( msg->hwnd, hrgn, TRUE );
3002 DeleteObject( hrgn );
3008 /***********************************************************************
3009 * WaitMessage (USER.112) Suspend thread pending messages
3010 * WaitMessage (USER32.@) Suspend thread pending messages
3012 * WaitMessage() suspends a thread until events appear in the thread's
3015 BOOL WINAPI WaitMessage(void)
3017 return (MsgWaitForMultipleObjectsEx( 0, NULL, INFINITE, QS_ALLINPUT, 0 ) != WAIT_FAILED);
3021 /***********************************************************************
3022 * MsgWaitForMultipleObjectsEx (USER32.@)
3024 DWORD WINAPI MsgWaitForMultipleObjectsEx( DWORD count, CONST HANDLE *pHandles,
3025 DWORD timeout, DWORD mask, DWORD flags )
3027 HANDLE handles[MAXIMUM_WAIT_OBJECTS];
3029 MESSAGEQUEUE *msgQueue;
3031 if (count > MAXIMUM_WAIT_OBJECTS-1)
3033 SetLastError( ERROR_INVALID_PARAMETER );
3037 if (!(msgQueue = QUEUE_Current())) return WAIT_FAILED;
3039 /* set the queue mask */
3040 SERVER_START_REQ( set_queue_mask )
3042 req->wake_mask = (flags & MWMO_INPUTAVAILABLE) ? mask : 0;
3043 req->changed_mask = mask;
3045 wine_server_call( req );
3049 /* Add the thread event to the handle list */
3050 for (i = 0; i < count; i++) handles[i] = pHandles[i];
3051 handles[count] = msgQueue->server_queue;
3053 ReleaseThunkLock( &lock );
3054 if (USER_Driver.pMsgWaitForMultipleObjectsEx)
3056 ret = USER_Driver.pMsgWaitForMultipleObjectsEx( count+1, handles, timeout, mask, flags );
3057 if (ret == count+1) ret = count; /* pretend the msg queue is ready */
3060 ret = WaitForMultipleObjectsEx( count+1, handles, flags & MWMO_WAITALL,
3061 timeout, flags & MWMO_ALERTABLE );
3062 if (lock) RestoreThunkLock( lock );
3067 /***********************************************************************
3068 * MsgWaitForMultipleObjects (USER32.@)
3070 DWORD WINAPI MsgWaitForMultipleObjects( DWORD count, CONST HANDLE *handles,
3071 BOOL wait_all, DWORD timeout, DWORD mask )
3073 return MsgWaitForMultipleObjectsEx( count, handles, timeout, mask,
3074 wait_all ? MWMO_WAITALL : 0 );
3078 /***********************************************************************
3079 * WaitForInputIdle (USER32.@)
3081 DWORD WINAPI WaitForInputIdle( HANDLE hProcess, DWORD dwTimeOut )
3083 DWORD start_time, elapsed, ret;
3084 HANDLE idle_event = (HANDLE)-1;
3086 SERVER_START_REQ( wait_input_idle )
3088 req->handle = hProcess;
3089 req->timeout = dwTimeOut;
3090 if (!(ret = wine_server_call_err( req ))) idle_event = reply->event;
3093 if (ret) return WAIT_FAILED; /* error */
3094 if (!idle_event) return 0; /* no event to wait on */
3096 start_time = GetTickCount();
3099 TRACE("waiting for %p\n", idle_event );
3102 ret = MsgWaitForMultipleObjects ( 1, &idle_event, FALSE, dwTimeOut - elapsed, QS_SENDMESSAGE );
3105 case WAIT_OBJECT_0+1:
3106 process_sent_messages();
3110 TRACE("timeout or error\n");
3113 TRACE("finished\n");
3116 if (dwTimeOut != INFINITE)
3118 elapsed = GetTickCount() - start_time;
3119 if (elapsed > dwTimeOut)
3125 return WAIT_TIMEOUT;
3129 /***********************************************************************
3130 * UserYield (USER.332)
3132 void WINAPI UserYield16(void)
3136 /* Handle sent messages */
3137 process_sent_messages();
3140 ReleaseThunkLock(&count);
3144 RestoreThunkLock(count);
3145 /* Handle sent messages again */
3146 process_sent_messages();
3151 /***********************************************************************
3152 * RegisterWindowMessage (USER.118)
3153 * RegisterWindowMessageA (USER32.@)
3155 WORD WINAPI RegisterWindowMessageA( LPCSTR str )
3157 TRACE("%s\n", str );
3158 return GlobalAddAtomA( str );
3162 /***********************************************************************
3163 * RegisterWindowMessageW (USER32.@)
3165 WORD WINAPI RegisterWindowMessageW( LPCWSTR str )
3167 TRACE("%p\n", str );
3168 return GlobalAddAtomW( str );
3172 /***********************************************************************
3173 * BroadcastSystemMessage (USER32.@)
3174 * BroadcastSystemMessageA (USER32.@)
3176 LONG WINAPI BroadcastSystemMessageA( DWORD flags, LPDWORD recipients, UINT msg, WPARAM wp, LPARAM lp )
3178 if ((*recipients & BSM_APPLICATIONS) || (*recipients == BSM_ALLCOMPONENTS))
3180 FIXME( "(%08lx,%08lx,%08x,%08x,%08lx): semi-stub!\n", flags, *recipients, msg, wp, lp );
3181 PostMessageA( HWND_BROADCAST, msg, wp, lp );
3186 FIXME( "(%08lx,%08lx,%08x,%08x,%08lx): stub!\n", flags, *recipients, msg, wp, lp);
3192 /***********************************************************************
3193 * BroadcastSystemMessageW (USER32.@)
3195 LONG WINAPI BroadcastSystemMessageW( DWORD flags, LPDWORD recipients, UINT msg, WPARAM wp, LPARAM lp )
3197 if ((*recipients & BSM_APPLICATIONS) || (*recipients == BSM_ALLCOMPONENTS))
3199 FIXME( "(%08lx,%08lx,%08x,%08x,%08lx): semi-stub!\n", flags, *recipients, msg, wp, lp );
3200 PostMessageW( HWND_BROADCAST, msg, wp, lp );
3205 FIXME( "(%08lx,%08lx,%08x,%08x,%08lx): stub!\n", flags, *recipients, msg, wp, lp );
3211 /***********************************************************************
3212 * SetMessageQueue (USER32.@)
3214 BOOL WINAPI SetMessageQueue( INT size )
3216 /* now obsolete the message queue will be expanded dynamically as necessary */
3221 /***********************************************************************
3222 * MessageBeep (USER32.@)
3224 BOOL WINAPI MessageBeep( UINT i )
3227 SystemParametersInfoA( SPI_GETBEEP, 0, &active, FALSE );
3228 if (active && USER_Driver.pBeep) USER_Driver.pBeep();
3233 /***********************************************************************
3234 * SetTimer (USER32.@)
3236 UINT_PTR WINAPI SetTimer( HWND hwnd, UINT_PTR id, UINT timeout, TIMERPROC proc )
3239 WNDPROC winproc = 0;
3241 if (proc) winproc = WINPROC_AllocProc( (WNDPROC)proc, WIN_PROC_32A );
3243 SERVER_START_REQ( set_win_timer )
3246 req->msg = WM_TIMER;
3248 req->rate = max( timeout, SYS_TIMER_RATE );
3249 req->lparam = (unsigned int)winproc;
3250 if (!wine_server_call_err( req ))
3253 if (!ret) ret = TRUE;
3259 TRACE("Added %p %x %p timeout %d\n", hwnd, id, winproc, timeout );
3264 /***********************************************************************
3265 * SetSystemTimer (USER32.@)
3267 UINT_PTR WINAPI SetSystemTimer( HWND hwnd, UINT_PTR id, UINT timeout, TIMERPROC proc )
3270 WNDPROC winproc = 0;
3272 if (proc) winproc = WINPROC_AllocProc( (WNDPROC)proc, WIN_PROC_32A );
3274 SERVER_START_REQ( set_win_timer )
3277 req->msg = WM_SYSTIMER;
3279 req->rate = max( timeout, SYS_TIMER_RATE );
3280 req->lparam = (unsigned int)winproc;
3281 if (!wine_server_call_err( req ))
3284 if (!ret) ret = TRUE;
3290 TRACE("Added %p %x %p timeout %d\n", hwnd, id, winproc, timeout );
3295 /***********************************************************************
3296 * KillTimer (USER32.@)
3298 BOOL WINAPI KillTimer( HWND hwnd, UINT_PTR id )
3302 TRACE("%p %d\n", hwnd, id );
3304 SERVER_START_REQ( kill_win_timer )
3307 req->msg = WM_TIMER;
3309 ret = !wine_server_call_err( req );
3316 /***********************************************************************
3317 * KillSystemTimer (USER32.@)
3319 BOOL WINAPI KillSystemTimer( HWND hwnd, UINT_PTR id )
3323 TRACE("%p %d\n", hwnd, id );
3325 SERVER_START_REQ( kill_win_timer )
3328 req->msg = WM_SYSTIMER;
3330 ret = !wine_server_call_err( req );
3337 /**********************************************************************
3338 * AttachThreadInput (USER32.@)
3340 * Attaches the input processing mechanism of one thread to that of
3343 BOOL WINAPI AttachThreadInput( DWORD from, DWORD to, BOOL attach )
3347 SERVER_START_REQ( attach_thread_input )
3349 req->tid_from = from;
3351 req->attach = attach;
3352 ret = !wine_server_call_err( req );
3359 /**********************************************************************
3360 * GetGUIThreadInfo (USER32.@)
3362 BOOL WINAPI GetGUIThreadInfo( DWORD id, GUITHREADINFO *info )
3366 SERVER_START_REQ( get_thread_input )
3369 if ((ret = !wine_server_call_err( req )))
3372 info->hwndActive = reply->active;
3373 info->hwndFocus = reply->focus;
3374 info->hwndCapture = reply->capture;
3375 info->hwndMenuOwner = reply->menu_owner;
3376 info->hwndMoveSize = reply->move_size;
3377 info->hwndCaret = reply->caret;
3378 info->rcCaret.left = reply->rect.left;
3379 info->rcCaret.top = reply->rect.top;
3380 info->rcCaret.right = reply->rect.right;
3381 info->rcCaret.bottom = reply->rect.bottom;
3382 if (reply->menu_owner) info->flags |= GUI_INMENUMODE;
3383 if (reply->move_size) info->flags |= GUI_INMOVESIZE;
3384 if (reply->caret) info->flags |= GUI_CARETBLINKING;
3392 /**********************************************************************
3393 * GetKeyState (USER32.@)
3395 * An application calls the GetKeyState function in response to a
3396 * keyboard-input message. This function retrieves the state of the key
3397 * at the time the input message was generated.
3399 SHORT WINAPI GetKeyState(INT vkey)
3403 SERVER_START_REQ( get_key_state )
3405 req->tid = GetCurrentThreadId();
3407 if (!wine_server_call( req )) retval = (signed char)reply->state;
3410 TRACE("key (0x%x) -> %x\n", vkey, retval);
3415 /**********************************************************************
3416 * GetKeyboardState (USER32.@)
3418 BOOL WINAPI GetKeyboardState( LPBYTE state )
3422 TRACE("(%p)\n", state);
3424 memset( state, 0, 256 );
3425 SERVER_START_REQ( get_key_state )
3427 req->tid = GetCurrentThreadId();
3429 wine_server_set_reply( req, state, 256 );
3430 ret = !wine_server_call_err( req );
3437 /**********************************************************************
3438 * SetKeyboardState (USER32.@)
3440 BOOL WINAPI SetKeyboardState( LPBYTE state )
3444 TRACE("(%p)\n", state);
3446 SERVER_START_REQ( set_key_state )
3448 req->tid = GetCurrentThreadId();
3449 wine_server_add_data( req, state, 256 );
3450 ret = !wine_server_call_err( req );
3456 /******************************************************************
3457 * IsHungAppWindow (USER32.@)
3460 BOOL WINAPI IsHungAppWindow( HWND hWnd )
3463 return !SendMessageTimeoutA(hWnd, WM_NULL, 0, 0, SMTO_ABORTIFHUNG, 5000, &dwResult);
3466 /******************************************************************
3467 * GetLastInputInfo (USER32.@)
3469 BOOL WINAPI GetLastInputInfo(PLASTINPUTINFO plii)
3471 FIXME("%p\n", plii);