2 * Window messaging support
4 * Copyright 2001 Alexandre Julliard
6 * This library is free software; you can redistribute it and/or
7 * modify it under the terms of the GNU Lesser General Public
8 * License as published by the Free Software Foundation; either
9 * version 2.1 of the License, or (at your option) any later version.
11 * This library is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 * Lesser General Public License for more details.
16 * You should have received a copy of the GNU Lesser General Public
17 * License along with this library; if not, write to the Free Software
18 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
22 #include "wine/port.h"
35 #include "wine/unicode.h"
36 #include "wine/server.h"
38 #include "user_private.h"
41 #include "wine/debug.h"
43 WINE_DEFAULT_DEBUG_CHANNEL(msg);
44 WINE_DECLARE_DEBUG_CHANNEL(relay);
46 #define WM_NCMOUSEFIRST WM_NCMOUSEMOVE
47 #define WM_NCMOUSELAST WM_NCMBUTTONDBLCLK
49 #define MAX_PACK_COUNT 4
51 #define SYS_TIMER_RATE 55 /* min. timer rate in ms (actually 54.925)*/
53 /* description of the data fields that need to be packed along with a sent message */
57 const void *data[MAX_PACK_COUNT];
58 size_t size[MAX_PACK_COUNT];
61 /* info about the message currently being received by the current thread */
62 struct received_message_info
64 enum message_type type;
66 UINT flags; /* InSendMessageEx return flags */
67 HWINEVENTHOOK hook; /* winevent hook handle */
68 WINEVENTPROC hook_proc; /* winevent hook proc address */
71 /* structure to group all parameters for sent messages of the various kinds */
72 struct send_message_info
74 enum message_type type;
79 UINT flags; /* flags for SendMessageTimeout */
80 UINT timeout; /* timeout for SendMessageTimeout */
81 SENDASYNCPROC callback; /* callback function for SendMessageCallback */
82 ULONG_PTR data; /* callback data */
86 /* flag for messages that contain pointers */
87 /* 32 messages per entry, messages 0..31 map to bits 0..31 */
89 #define SET(msg) (1 << ((msg) & 31))
91 static const unsigned int message_pointer_flags[] =
94 SET(WM_CREATE) | SET(WM_SETTEXT) | SET(WM_GETTEXT) |
95 SET(WM_WININICHANGE) | SET(WM_DEVMODECHANGE),
97 SET(WM_GETMINMAXINFO) | SET(WM_DRAWITEM) | SET(WM_MEASUREITEM) | SET(WM_DELETEITEM) |
100 SET(WM_WINDOWPOSCHANGING) | SET(WM_WINDOWPOSCHANGED) | SET(WM_COPYDATA) |
101 SET(WM_NOTIFY) | SET(WM_HELP),
103 SET(WM_STYLECHANGING) | SET(WM_STYLECHANGED),
105 SET(WM_NCCREATE) | SET(WM_NCCALCSIZE) | SET(WM_GETDLGCODE),
107 SET(EM_GETSEL) | SET(EM_GETRECT) | SET(EM_SETRECT) | SET(EM_SETRECTNP),
109 SET(EM_REPLACESEL) | SET(EM_GETLINE) | SET(EM_SETTABSTOPS),
111 SET(SBM_GETRANGE) | SET(SBM_SETSCROLLINFO) | SET(SBM_GETSCROLLINFO) | SET(SBM_GETSCROLLBARINFO),
117 SET(CB_GETEDITSEL) | SET(CB_ADDSTRING) | SET(CB_DIR) | SET(CB_GETLBTEXT) |
118 SET(CB_INSERTSTRING) | SET(CB_FINDSTRING) | SET(CB_SELECTSTRING) |
119 SET(CB_GETDROPPEDCONTROLRECT) | SET(CB_FINDSTRINGEXACT),
123 SET(LB_ADDSTRING) | SET(LB_INSERTSTRING) | SET(LB_GETTEXT) | SET(LB_SELECTSTRING) |
124 SET(LB_DIR) | SET(LB_FINDSTRING) |
125 SET(LB_GETSELITEMS) | SET(LB_SETTABSTOPS) | SET(LB_ADDFILE) | SET(LB_GETITEMRECT),
127 SET(LB_FINDSTRINGEXACT),
133 SET(WM_NEXTMENU) | SET(WM_SIZING) | SET(WM_MOVING) | SET(WM_DEVICECHANGE),
135 SET(WM_MDICREATE) | SET(WM_MDIGETACTIVE) | SET(WM_DROPOBJECT) |
136 SET(WM_QUERYDROPOBJECT) | SET(WM_DRAGLOOP) | SET(WM_DRAGSELECT) | SET(WM_DRAGMOVE),
150 SET(WM_ASKCBFORMATNAME)
153 /* flags for messages that contain Unicode strings */
154 static const unsigned int message_unicode_flags[] =
157 SET(WM_CREATE) | SET(WM_SETTEXT) | SET(WM_GETTEXT) | SET(WM_GETTEXTLENGTH) |
158 SET(WM_WININICHANGE) | SET(WM_DEVMODECHANGE),
170 SET(EM_REPLACESEL) | SET(EM_GETLINE) | SET(EM_SETPASSWORDCHAR),
174 SET(WM_CHAR) | SET(WM_DEADCHAR) | SET(WM_SYSCHAR) | SET(WM_SYSDEADCHAR),
178 SET(CB_ADDSTRING) | SET(CB_DIR) | SET(CB_GETLBTEXT) | SET(CB_GETLBTEXTLEN) |
179 SET(CB_INSERTSTRING) | SET(CB_FINDSTRING) | SET(CB_SELECTSTRING) | SET(CB_FINDSTRINGEXACT),
183 SET(LB_ADDSTRING) | SET(LB_INSERTSTRING) | SET(LB_GETTEXT) | SET(LB_GETTEXTLEN) |
184 SET(LB_SELECTSTRING) | SET(LB_DIR) | SET(LB_FINDSTRING) | SET(LB_ADDFILE),
186 SET(LB_FINDSTRINGEXACT),
208 SET(WM_PAINTCLIPBOARD) | SET(WM_SIZECLIPBOARD) | SET(WM_ASKCBFORMATNAME)
211 /* check whether a given message type includes pointers */
212 inline static int is_pointer_message( UINT message )
214 if (message >= 8*sizeof(message_pointer_flags)) return FALSE;
215 return (message_pointer_flags[message / 32] & SET(message)) != 0;
218 /* check whether a given message type contains Unicode (or ASCII) chars */
219 inline static int is_unicode_message( UINT message )
221 if (message >= 8*sizeof(message_unicode_flags)) return FALSE;
222 return (message_unicode_flags[message / 32] & SET(message)) != 0;
227 /* add a data field to a packed message */
228 inline static void push_data( struct packed_message *data, const void *ptr, size_t size )
230 data->data[data->count] = ptr;
231 data->size[data->count] = size;
235 /* add a string to a packed message */
236 inline static void push_string( struct packed_message *data, LPCWSTR str )
238 push_data( data, str, (strlenW(str) + 1) * sizeof(WCHAR) );
241 /* retrieve a pointer to data from a packed message and increment the buffer pointer */
242 inline static void *get_data( void **buffer, size_t size )
245 *buffer = (char *)*buffer + size;
249 /* make sure that the buffer contains a valid null-terminated Unicode string */
250 inline static BOOL check_string( LPCWSTR str, size_t size )
252 for (size /= sizeof(WCHAR); size; size--, str++)
253 if (!*str) return TRUE;
257 /* make sure that there is space for 'size' bytes in buffer, growing it if needed */
258 inline static void *get_buffer_space( void **buffer, size_t size )
264 if (!(ret = HeapReAlloc( GetProcessHeap(), 0, *buffer, size )))
265 HeapFree( GetProcessHeap(), 0, *buffer );
267 else ret = HeapAlloc( GetProcessHeap(), 0, size );
273 /* retrieve a string pointer from packed data */
274 inline static LPWSTR get_string( void **buffer )
276 return get_data( buffer, (strlenW( (LPWSTR)*buffer ) + 1) * sizeof(WCHAR) );
279 /* check whether a combobox expects strings or ids in CB_ADDSTRING/CB_INSERTSTRING */
280 inline static BOOL combobox_has_strings( HWND hwnd )
282 DWORD style = GetWindowLongA( hwnd, GWL_STYLE );
283 return (!(style & (CBS_OWNERDRAWFIXED | CBS_OWNERDRAWVARIABLE)) || (style & CBS_HASSTRINGS));
286 /* check whether a listbox expects strings or ids in LB_ADDSTRING/LB_INSERTSTRING */
287 inline static BOOL listbox_has_strings( HWND hwnd )
289 DWORD style = GetWindowLongA( hwnd, GWL_STYLE );
290 return (!(style & (LBS_OWNERDRAWFIXED | LBS_OWNERDRAWVARIABLE)) || (style & LBS_HASSTRINGS));
294 /***********************************************************************
295 * broadcast_message_callback
297 * Helper callback for broadcasting messages.
299 static BOOL CALLBACK broadcast_message_callback( HWND hwnd, LPARAM lparam )
301 struct send_message_info *info = (struct send_message_info *)lparam;
302 if (!(GetWindowLongW( hwnd, GWL_STYLE ) & (WS_POPUP|WS_CAPTION))) return TRUE;
306 SendMessageTimeoutW( hwnd, info->msg, info->wparam, info->lparam,
307 info->flags, info->timeout, NULL );
310 SendMessageTimeoutA( hwnd, info->msg, info->wparam, info->lparam,
311 info->flags, info->timeout, NULL );
314 SendNotifyMessageW( hwnd, info->msg, info->wparam, info->lparam );
317 SendMessageCallbackW( hwnd, info->msg, info->wparam, info->lparam,
318 info->callback, info->data );
321 PostMessageW( hwnd, info->msg, info->wparam, info->lparam );
324 ERR( "bad type %d\n", info->type );
331 /***********************************************************************
334 * Convert the wparam of an ASCII message to Unicode.
336 static WPARAM map_wparam_AtoW( UINT message, WPARAM wparam )
341 case EM_SETPASSWORDCHAR:
348 char ch = LOWORD(wparam);
350 MultiByteToWideChar(CP_ACP, 0, &ch, 1, &wch, 1);
351 wparam = MAKEWPARAM( wch, HIWORD(wparam) );
358 ch[0] = (wparam >> 8);
359 ch[1] = (wparam & 0xff);
360 if (ch[0]) MultiByteToWideChar(CP_ACP, 0, ch, 2, &wch, 1);
361 else MultiByteToWideChar(CP_ACP, 0, &ch[1], 1, &wch, 1);
362 wparam = MAKEWPARAM( wch, HIWORD(wparam) );
370 /***********************************************************************
373 * Convert the wparam of a Unicode message to ASCII.
375 static WPARAM map_wparam_WtoA( UINT message, WPARAM wparam )
380 case EM_SETPASSWORDCHAR:
387 WCHAR wch = LOWORD(wparam);
389 WideCharToMultiByte( CP_ACP, 0, &wch, 1, &ch, 1, NULL, NULL );
390 wparam = MAKEWPARAM( ch, HIWORD(wparam) );
395 WCHAR wch = LOWORD(wparam);
398 if (WideCharToMultiByte( CP_ACP, 0, &wch, 1, ch, 2, NULL, NULL ) == 2)
399 wparam = MAKEWPARAM( (ch[0] << 8) | ch[1], HIWORD(wparam) );
401 wparam = MAKEWPARAM( ch[0], HIWORD(wparam) );
409 /***********************************************************************
412 * Pack a message for sending to another process.
413 * Return the size of the data we expect in the message reply.
414 * Set data->count to -1 if there is an error.
416 static size_t pack_message( HWND hwnd, UINT message, WPARAM wparam, LPARAM lparam,
417 struct packed_message *data )
425 CREATESTRUCTW *cs = (CREATESTRUCTW *)lparam;
426 push_data( data, cs, sizeof(*cs) );
427 if (HIWORD(cs->lpszName)) push_string( data, cs->lpszName );
428 if (HIWORD(cs->lpszClass)) push_string( data, cs->lpszClass );
432 case WM_ASKCBFORMATNAME:
433 return wparam * sizeof(WCHAR);
434 case WM_WININICHANGE:
435 if (lparam) push_string(data, (LPWSTR)lparam );
438 case WM_DEVMODECHANGE:
443 push_string( data, (LPWSTR)lparam );
445 case WM_GETMINMAXINFO:
446 push_data( data, (MINMAXINFO *)lparam, sizeof(MINMAXINFO) );
447 return sizeof(MINMAXINFO);
449 push_data( data, (DRAWITEMSTRUCT *)lparam, sizeof(DRAWITEMSTRUCT) );
452 push_data( data, (MEASUREITEMSTRUCT *)lparam, sizeof(MEASUREITEMSTRUCT) );
453 return sizeof(MEASUREITEMSTRUCT);
455 push_data( data, (DELETEITEMSTRUCT *)lparam, sizeof(DELETEITEMSTRUCT) );
458 push_data( data, (COMPAREITEMSTRUCT *)lparam, sizeof(COMPAREITEMSTRUCT) );
460 case WM_WINDOWPOSCHANGING:
461 case WM_WINDOWPOSCHANGED:
462 push_data( data, (WINDOWPOS *)lparam, sizeof(WINDOWPOS) );
463 return sizeof(WINDOWPOS);
466 COPYDATASTRUCT *cp = (COPYDATASTRUCT *)lparam;
467 push_data( data, cp, sizeof(*cp) );
468 if (cp->lpData) push_data( data, cp->lpData, cp->cbData );
472 /* WM_NOTIFY cannot be sent across processes (MSDN) */
476 push_data( data, (HELPINFO *)lparam, sizeof(HELPINFO) );
478 case WM_STYLECHANGING:
479 case WM_STYLECHANGED:
480 push_data( data, (STYLESTRUCT *)lparam, sizeof(STYLESTRUCT) );
485 push_data( data, (RECT *)lparam, sizeof(RECT) );
490 NCCALCSIZE_PARAMS *nc = (NCCALCSIZE_PARAMS *)lparam;
491 push_data( data, nc, sizeof(*nc) );
492 push_data( data, nc->lppos, sizeof(*nc->lppos) );
493 return sizeof(*nc) + sizeof(*nc->lppos);
496 if (lparam) push_data( data, (MSG *)lparam, sizeof(MSG) );
498 case SBM_SETSCROLLINFO:
499 push_data( data, (SCROLLINFO *)lparam, sizeof(SCROLLINFO) );
501 case SBM_GETSCROLLINFO:
502 push_data( data, (SCROLLINFO *)lparam, sizeof(SCROLLINFO) );
503 return sizeof(SCROLLINFO);
504 case SBM_GETSCROLLBARINFO:
506 const SCROLLBARINFO *info = (const SCROLLBARINFO *)lparam;
507 size_t size = min( info->cbSize, sizeof(SCROLLBARINFO) );
508 push_data( data, info, size );
516 if (wparam) size += sizeof(DWORD);
517 if (lparam) size += sizeof(DWORD);
522 case CB_GETDROPPEDCONTROLRECT:
526 push_data( data, (RECT *)lparam, sizeof(RECT) );
530 WORD *pw = (WORD *)lparam;
531 push_data( data, pw, sizeof(*pw) );
532 return *pw * sizeof(WCHAR);
536 if (wparam) push_data( data, (UINT *)lparam, sizeof(UINT) * wparam );
539 case CB_INSERTSTRING:
541 case CB_FINDSTRINGEXACT:
542 case CB_SELECTSTRING:
543 if (combobox_has_strings( hwnd )) push_string( data, (LPWSTR)lparam );
546 if (!combobox_has_strings( hwnd )) return sizeof(ULONG_PTR);
547 return (SendMessageW( hwnd, CB_GETLBTEXTLEN, wparam, 0 ) + 1) * sizeof(WCHAR);
549 case LB_INSERTSTRING:
551 case LB_FINDSTRINGEXACT:
552 case LB_SELECTSTRING:
553 if (listbox_has_strings( hwnd )) push_string( data, (LPWSTR)lparam );
556 if (!listbox_has_strings( hwnd )) return sizeof(ULONG_PTR);
557 return (SendMessageW( hwnd, LB_GETTEXTLEN, wparam, 0 ) + 1) * sizeof(WCHAR);
559 return wparam * sizeof(UINT);
561 push_data( data, (MDINEXTMENU *)lparam, sizeof(MDINEXTMENU) );
562 return sizeof(MDINEXTMENU);
565 push_data( data, (RECT *)lparam, sizeof(RECT) );
569 MDICREATESTRUCTW *cs = (MDICREATESTRUCTW *)lparam;
570 push_data( data, cs, sizeof(*cs) );
571 if (HIWORD(cs->szTitle)) push_string( data, cs->szTitle );
572 if (HIWORD(cs->szClass)) push_string( data, cs->szClass );
575 case WM_MDIGETACTIVE:
576 if (lparam) return sizeof(BOOL);
578 case WM_WINE_SETWINDOWPOS:
579 push_data( data, (WINDOWPOS *)lparam, sizeof(WINDOWPOS) );
581 case WM_WINE_KEYBOARD_LL_HOOK:
582 push_data( data, (KBDLLHOOKSTRUCT *)lparam, sizeof(KBDLLHOOKSTRUCT) );
584 case WM_WINE_MOUSE_LL_HOOK:
585 push_data( data, (MSLLHOOKSTRUCT *)lparam, sizeof(MSLLHOOKSTRUCT) );
588 if (!wparam) return 0;
591 /* these contain an HFONT */
594 /* these contain an HDC */
596 case WM_ICONERASEBKGND:
598 case WM_CTLCOLORMSGBOX:
599 case WM_CTLCOLOREDIT:
600 case WM_CTLCOLORLISTBOX:
603 case WM_CTLCOLORSCROLLBAR:
604 case WM_CTLCOLORSTATIC:
607 /* these contain an HGLOBAL */
608 case WM_PAINTCLIPBOARD:
609 case WM_SIZECLIPBOARD:
610 /* these contain HICON */
613 case WM_QUERYDRAGICON:
614 case WM_QUERYPARKICON:
615 /* these contain pointers */
617 case WM_QUERYDROPOBJECT:
621 case WM_DEVICECHANGE:
622 FIXME( "msg %x (%s) not supported yet\n", message, SPY_GetMsgName(message, hwnd) );
630 /***********************************************************************
633 * Unpack a message received from another process.
635 static BOOL unpack_message( HWND hwnd, UINT message, WPARAM *wparam, LPARAM *lparam,
636 void **buffer, size_t size )
645 CREATESTRUCTW *cs = *buffer;
646 WCHAR *str = (WCHAR *)(cs + 1);
647 if (size < sizeof(*cs)) return FALSE;
649 if (HIWORD(cs->lpszName))
651 if (!check_string( str, size )) return FALSE;
653 size -= (strlenW(str) + 1) * sizeof(WCHAR);
654 str += strlenW(str) + 1;
656 if (HIWORD(cs->lpszClass))
658 if (!check_string( str, size )) return FALSE;
664 case WM_ASKCBFORMATNAME:
665 if (!get_buffer_space( buffer, (*wparam * sizeof(WCHAR)) )) return FALSE;
667 case WM_WININICHANGE:
668 if (!*lparam) return TRUE;
671 case WM_DEVMODECHANGE:
676 if (!check_string( *buffer, size )) return FALSE;
678 case WM_GETMINMAXINFO:
679 minsize = sizeof(MINMAXINFO);
682 minsize = sizeof(DRAWITEMSTRUCT);
685 minsize = sizeof(MEASUREITEMSTRUCT);
688 minsize = sizeof(DELETEITEMSTRUCT);
691 minsize = sizeof(COMPAREITEMSTRUCT);
693 case WM_WINDOWPOSCHANGING:
694 case WM_WINDOWPOSCHANGED:
695 case WM_WINE_SETWINDOWPOS:
696 minsize = sizeof(WINDOWPOS);
700 COPYDATASTRUCT *cp = *buffer;
701 if (size < sizeof(*cp)) return FALSE;
704 minsize = sizeof(*cp) + cp->cbData;
710 /* WM_NOTIFY cannot be sent across processes (MSDN) */
713 minsize = sizeof(HELPINFO);
715 case WM_STYLECHANGING:
716 case WM_STYLECHANGED:
717 minsize = sizeof(STYLESTRUCT);
720 if (!*wparam) minsize = sizeof(RECT);
723 NCCALCSIZE_PARAMS *nc = *buffer;
724 if (size < sizeof(*nc) + sizeof(*nc->lppos)) return FALSE;
725 nc->lppos = (WINDOWPOS *)(nc + 1);
729 if (!*lparam) return TRUE;
730 minsize = sizeof(MSG);
732 case SBM_SETSCROLLINFO:
733 minsize = sizeof(SCROLLINFO);
735 case SBM_GETSCROLLINFO:
736 if (!get_buffer_space( buffer, sizeof(SCROLLINFO ))) return FALSE;
738 case SBM_GETSCROLLBARINFO:
739 if (!get_buffer_space( buffer, sizeof(SCROLLBARINFO ))) return FALSE;
744 if (*wparam || *lparam)
746 if (!get_buffer_space( buffer, 2*sizeof(DWORD) )) return FALSE;
747 if (*wparam) *wparam = (WPARAM)*buffer;
748 if (*lparam) *lparam = (LPARAM)((DWORD *)*buffer + 1);
753 case CB_GETDROPPEDCONTROLRECT:
754 if (!get_buffer_space( buffer, sizeof(RECT) )) return FALSE;
758 minsize = sizeof(RECT);
763 if (size < sizeof(WORD)) return FALSE;
764 len = *(WORD *)*buffer;
765 if (!get_buffer_space( buffer, (len + 1) * sizeof(WCHAR) )) return FALSE;
766 *lparam = (LPARAM)*buffer + sizeof(WORD); /* don't erase WORD at start of buffer */
771 if (!*wparam) return TRUE;
772 minsize = *wparam * sizeof(UINT);
775 case CB_INSERTSTRING:
777 case CB_FINDSTRINGEXACT:
778 case CB_SELECTSTRING:
780 case LB_INSERTSTRING:
782 case LB_FINDSTRINGEXACT:
783 case LB_SELECTSTRING:
784 if (!*buffer) return TRUE;
785 if (!check_string( *buffer, size )) return FALSE;
789 size = sizeof(ULONG_PTR);
790 if (combobox_has_strings( hwnd ))
791 size = (SendMessageW( hwnd, CB_GETLBTEXTLEN, *wparam, 0 ) + 1) * sizeof(WCHAR);
792 if (!get_buffer_space( buffer, size )) return FALSE;
797 size = sizeof(ULONG_PTR);
798 if (listbox_has_strings( hwnd ))
799 size = (SendMessageW( hwnd, LB_GETTEXTLEN, *wparam, 0 ) + 1) * sizeof(WCHAR);
800 if (!get_buffer_space( buffer, size )) return FALSE;
804 if (!get_buffer_space( buffer, *wparam * sizeof(UINT) )) return FALSE;
807 minsize = sizeof(MDINEXTMENU);
808 if (!get_buffer_space( buffer, sizeof(MDINEXTMENU) )) return FALSE;
812 minsize = sizeof(RECT);
813 if (!get_buffer_space( buffer, sizeof(RECT) )) return FALSE;
817 MDICREATESTRUCTW *cs = *buffer;
818 WCHAR *str = (WCHAR *)(cs + 1);
819 if (size < sizeof(*cs)) return FALSE;
821 if (HIWORD(cs->szTitle))
823 if (!check_string( str, size )) return FALSE;
825 size -= (strlenW(str) + 1) * sizeof(WCHAR);
826 str += strlenW(str) + 1;
828 if (HIWORD(cs->szClass))
830 if (!check_string( str, size )) return FALSE;
835 case WM_MDIGETACTIVE:
836 if (!*lparam) return TRUE;
837 if (!get_buffer_space( buffer, sizeof(BOOL) )) return FALSE;
839 case WM_WINE_KEYBOARD_LL_HOOK:
840 minsize = sizeof(KBDLLHOOKSTRUCT);
842 case WM_WINE_MOUSE_LL_HOOK:
843 minsize = sizeof(MSLLHOOKSTRUCT);
846 if (!*wparam) return TRUE;
849 /* these contain an HFONT */
852 /* these contain an HDC */
854 case WM_ICONERASEBKGND:
856 case WM_CTLCOLORMSGBOX:
857 case WM_CTLCOLOREDIT:
858 case WM_CTLCOLORLISTBOX:
861 case WM_CTLCOLORSCROLLBAR:
862 case WM_CTLCOLORSTATIC:
865 /* these contain an HGLOBAL */
866 case WM_PAINTCLIPBOARD:
867 case WM_SIZECLIPBOARD:
868 /* these contain HICON */
871 case WM_QUERYDRAGICON:
872 case WM_QUERYPARKICON:
873 /* these contain pointers */
875 case WM_QUERYDROPOBJECT:
879 case WM_DEVICECHANGE:
880 FIXME( "msg %x (%s) not supported yet\n", message, SPY_GetMsgName(message, hwnd) );
884 return TRUE; /* message doesn't need any unpacking */
887 /* default exit for most messages: check minsize and store buffer in lparam */
888 if (size < minsize) return FALSE;
889 *lparam = (LPARAM)*buffer;
894 /***********************************************************************
897 * Pack a reply to a message for sending to another process.
899 static void pack_reply( HWND hwnd, UINT message, WPARAM wparam, LPARAM lparam,
900 LRESULT res, struct packed_message *data )
907 push_data( data, (CREATESTRUCTW *)lparam, sizeof(CREATESTRUCTW) );
912 push_data( data, (WCHAR *)lparam, (res + 1) * sizeof(WCHAR) );
914 case WM_GETMINMAXINFO:
915 push_data( data, (MINMAXINFO *)lparam, sizeof(MINMAXINFO) );
918 push_data( data, (MEASUREITEMSTRUCT *)lparam, sizeof(MEASUREITEMSTRUCT) );
920 case WM_WINDOWPOSCHANGING:
921 case WM_WINDOWPOSCHANGED:
922 push_data( data, (WINDOWPOS *)lparam, sizeof(WINDOWPOS) );
925 if (lparam) push_data( data, (MSG *)lparam, sizeof(MSG) );
927 case SBM_GETSCROLLINFO:
928 push_data( data, (SCROLLINFO *)lparam, sizeof(SCROLLINFO) );
932 case CB_GETDROPPEDCONTROLRECT:
935 push_data( data, (RECT *)lparam, sizeof(RECT) );
939 WORD *ptr = (WORD *)lparam;
940 push_data( data, ptr, ptr[-1] * sizeof(WCHAR) );
944 push_data( data, (UINT *)lparam, wparam * sizeof(UINT) );
946 case WM_MDIGETACTIVE:
947 if (lparam) push_data( data, (BOOL *)lparam, sizeof(BOOL) );
951 push_data( data, (RECT *)lparam, sizeof(RECT) );
954 NCCALCSIZE_PARAMS *nc = (NCCALCSIZE_PARAMS *)lparam;
955 push_data( data, nc, sizeof(*nc) );
956 push_data( data, nc->lppos, sizeof(*nc->lppos) );
962 if (wparam) push_data( data, (DWORD *)wparam, sizeof(DWORD) );
963 if (lparam) push_data( data, (DWORD *)lparam, sizeof(DWORD) );
966 push_data( data, (MDINEXTMENU *)lparam, sizeof(MDINEXTMENU) );
969 push_data( data, (MDICREATESTRUCTW *)lparam, sizeof(MDICREATESTRUCTW) );
971 case WM_ASKCBFORMATNAME:
972 push_data( data, (WCHAR *)lparam, (strlenW((WCHAR *)lparam) + 1) * sizeof(WCHAR) );
978 /***********************************************************************
981 * Unpack a message reply received from another process.
983 static void unpack_reply( HWND hwnd, UINT message, WPARAM wparam, LPARAM lparam,
984 void *buffer, size_t size )
991 CREATESTRUCTW *cs = (CREATESTRUCTW *)lparam;
992 LPCWSTR name = cs->lpszName, class = cs->lpszClass;
993 memcpy( cs, buffer, min( sizeof(*cs), size ));
994 cs->lpszName = name; /* restore the original pointers */
995 cs->lpszClass = class;
999 case WM_ASKCBFORMATNAME:
1000 memcpy( (WCHAR *)lparam, buffer, min( wparam*sizeof(WCHAR), size ));
1002 case WM_GETMINMAXINFO:
1003 memcpy( (MINMAXINFO *)lparam, buffer, min( sizeof(MINMAXINFO), size ));
1005 case WM_MEASUREITEM:
1006 memcpy( (MEASUREITEMSTRUCT *)lparam, buffer, min( sizeof(MEASUREITEMSTRUCT), size ));
1008 case WM_WINDOWPOSCHANGING:
1009 case WM_WINDOWPOSCHANGED:
1010 memcpy( (WINDOWPOS *)lparam, buffer, min( sizeof(WINDOWPOS), size ));
1013 if (lparam) memcpy( (MSG *)lparam, buffer, min( sizeof(MSG), size ));
1015 case SBM_GETSCROLLINFO:
1016 memcpy( (SCROLLINFO *)lparam, buffer, min( sizeof(SCROLLINFO), size ));
1018 case SBM_GETSCROLLBARINFO:
1019 memcpy( (SCROLLBARINFO *)lparam, buffer, min( sizeof(SCROLLBARINFO), size ));
1022 case CB_GETDROPPEDCONTROLRECT:
1023 case LB_GETITEMRECT:
1026 memcpy( (RECT *)lparam, buffer, min( sizeof(RECT), size ));
1029 size = min( size, (size_t)*(WORD *)lparam );
1030 memcpy( (WCHAR *)lparam, buffer, size );
1032 case LB_GETSELITEMS:
1033 memcpy( (UINT *)lparam, buffer, min( wparam*sizeof(UINT), size ));
1037 memcpy( (WCHAR *)lparam, buffer, size );
1040 memcpy( (MDINEXTMENU *)lparam, buffer, min( sizeof(MDINEXTMENU), size ));
1042 case WM_MDIGETACTIVE:
1043 if (lparam) memcpy( (BOOL *)lparam, buffer, min( sizeof(BOOL), size ));
1047 memcpy( (RECT *)lparam, buffer, min( sizeof(RECT), size ));
1050 NCCALCSIZE_PARAMS *nc = (NCCALCSIZE_PARAMS *)lparam;
1051 WINDOWPOS *wp = nc->lppos;
1052 memcpy( nc, buffer, min( sizeof(*nc), size ));
1053 if (size > sizeof(*nc))
1055 size -= sizeof(*nc);
1056 memcpy( wp, (NCCALCSIZE_PARAMS*)buffer + 1, min( sizeof(*wp), size ));
1058 nc->lppos = wp; /* restore the original pointer */
1066 memcpy( (DWORD *)wparam, buffer, min( sizeof(DWORD), size ));
1067 if (size <= sizeof(DWORD)) break;
1068 size -= sizeof(DWORD);
1069 buffer = (DWORD *)buffer + 1;
1071 if (lparam) memcpy( (DWORD *)lparam, buffer, min( sizeof(DWORD), size ));
1075 MDICREATESTRUCTW *cs = (MDICREATESTRUCTW *)lparam;
1076 LPCWSTR title = cs->szTitle, class = cs->szClass;
1077 memcpy( cs, buffer, min( sizeof(*cs), size ));
1078 cs->szTitle = title; /* restore the original pointers */
1079 cs->szClass = class;
1083 ERR( "should not happen: unexpected message %x\n", message );
1089 /***********************************************************************
1092 * Send a reply to a sent message.
1094 static void reply_message( struct received_message_info *info, LRESULT result, BOOL remove )
1096 struct packed_message data;
1097 int i, replied = info->flags & ISMEX_REPLIED;
1099 if (info->flags & ISMEX_NOTIFY) return; /* notify messages don't get replies */
1100 if (!remove && replied) return; /* replied already */
1103 info->flags |= ISMEX_REPLIED;
1105 if (info->type == MSG_OTHER_PROCESS && !replied)
1107 pack_reply( info->msg.hwnd, info->msg.message, info->msg.wParam,
1108 info->msg.lParam, result, &data );
1111 SERVER_START_REQ( reply_message )
1113 req->type = info->type;
1114 req->result = result;
1115 req->remove = remove;
1116 for (i = 0; i < data.count; i++) wine_server_add_data( req, data.data[i], data.size[i] );
1117 wine_server_call( req );
1123 /***********************************************************************
1124 * handle_internal_message
1126 * Handle an internal Wine message instead of calling the window proc.
1128 static LRESULT handle_internal_message( HWND hwnd, UINT msg, WPARAM wparam, LPARAM lparam )
1130 if (hwnd == GetDesktopWindow()) return 0;
1133 case WM_WINE_DESTROYWINDOW:
1134 return WIN_DestroyWindow( hwnd );
1135 case WM_WINE_SETWINDOWPOS:
1136 if (USER_Driver.pSetWindowPos)
1137 return USER_Driver.pSetWindowPos( (WINDOWPOS *)lparam );
1139 case WM_WINE_SHOWWINDOW:
1140 return ShowWindow( hwnd, wparam );
1141 case WM_WINE_SETPARENT:
1142 return (LRESULT)SetParent( hwnd, (HWND)wparam );
1143 case WM_WINE_SETWINDOWLONG:
1144 return (LRESULT)SetWindowLongW( hwnd, wparam, lparam );
1145 case WM_WINE_ENABLEWINDOW:
1146 return EnableWindow( hwnd, wparam );
1147 case WM_WINE_SETACTIVEWINDOW:
1148 return (LRESULT)SetActiveWindow( (HWND)wparam );
1149 case WM_WINE_KEYBOARD_LL_HOOK:
1150 return HOOK_CallHooks( WH_KEYBOARD_LL, HC_ACTION, wparam, lparam, TRUE );
1151 case WM_WINE_MOUSE_LL_HOOK:
1152 return HOOK_CallHooks( WH_MOUSE_LL, HC_ACTION, wparam, lparam, TRUE );
1154 FIXME( "unknown internal message %x\n", msg );
1159 /* since the WM_DDE_ACK response to a WM_DDE_EXECUTE message should contain the handle
1160 * to the memory handle, we keep track (in the server side) of all pairs of handle
1161 * used (the client passes its value and the content of the memory handle), and
1162 * the server stored both values (the client, and the local one, created after the
1163 * content). When a ACK message is generated, the list of pair is searched for a
1164 * matching pair, so that the client memory handle can be returned.
1167 HGLOBAL client_hMem;
1168 HGLOBAL server_hMem;
1171 static struct DDE_pair* dde_pairs;
1172 static int dde_num_alloc;
1173 static int dde_num_used;
1175 static CRITICAL_SECTION dde_crst;
1176 static CRITICAL_SECTION_DEBUG critsect_debug =
1179 { &critsect_debug.ProcessLocksList, &critsect_debug.ProcessLocksList },
1180 0, 0, { 0, (DWORD)(__FILE__ ": dde_crst") }
1182 static CRITICAL_SECTION dde_crst = { &critsect_debug, -1, 0, 0, 0, 0 };
1184 static BOOL dde_add_pair(HGLOBAL chm, HGLOBAL shm)
1189 EnterCriticalSection(&dde_crst);
1191 /* now remember the pair of hMem on both sides */
1192 if (dde_num_used == dde_num_alloc)
1194 struct DDE_pair* tmp;
1196 tmp = HeapReAlloc( GetProcessHeap(), 0, dde_pairs,
1197 (dde_num_alloc + GROWBY) * sizeof(struct DDE_pair));
1199 tmp = HeapAlloc( GetProcessHeap(), 0,
1200 (dde_num_alloc + GROWBY) * sizeof(struct DDE_pair));
1204 LeaveCriticalSection(&dde_crst);
1208 /* zero out newly allocated part */
1209 memset(&dde_pairs[dde_num_alloc], 0, GROWBY * sizeof(struct DDE_pair));
1210 dde_num_alloc += GROWBY;
1213 for (i = 0; i < dde_num_alloc; i++)
1215 if (dde_pairs[i].server_hMem == 0)
1217 dde_pairs[i].client_hMem = chm;
1218 dde_pairs[i].server_hMem = shm;
1223 LeaveCriticalSection(&dde_crst);
1227 static HGLOBAL dde_get_pair(HGLOBAL shm)
1232 EnterCriticalSection(&dde_crst);
1233 for (i = 0; i < dde_num_alloc; i++)
1235 if (dde_pairs[i].server_hMem == shm)
1237 /* free this pair */
1238 dde_pairs[i].server_hMem = 0;
1240 ret = dde_pairs[i].client_hMem;
1244 LeaveCriticalSection(&dde_crst);
1248 /***********************************************************************
1251 * Post a DDE message
1253 static BOOL post_dde_message( DWORD dest_tid, struct packed_message *data, const struct send_message_info *info )
1259 HGLOBAL hunlock = 0;
1263 if (!UnpackDDElParam( info->msg, info->lparam, &uiLo, &uiHi ))
1269 /* DDE messages which don't require packing are:
1278 /* uiHi should contain a hMem from WM_DDE_EXECUTE */
1279 HGLOBAL h = dde_get_pair( (HANDLE)uiHi );
1282 /* send back the value of h on the other side */
1283 push_data( data, &h, sizeof(HGLOBAL) );
1285 TRACE( "send dde-ack %x %08x => %08lx\n", uiLo, uiHi, (DWORD)h );
1290 /* uiHi should contain either an atom or 0 */
1291 TRACE( "send dde-ack %x atom=%x\n", uiLo, uiHi );
1292 lp = MAKELONG( uiLo, uiHi );
1301 size = GlobalSize( (HGLOBAL)uiLo ) ;
1302 if ((info->msg == WM_DDE_ADVISE && size < sizeof(DDEADVISE)) ||
1303 (info->msg == WM_DDE_DATA && size < sizeof(DDEDATA)) ||
1304 (info->msg == WM_DDE_POKE && size < sizeof(DDEPOKE))
1308 else if (info->msg != WM_DDE_DATA) return FALSE;
1313 if ((ptr = GlobalLock( (HGLOBAL)uiLo) ))
1315 DDEDATA *dde_data = (DDEDATA *)ptr;
1316 TRACE("unused %d, fResponse %d, fRelease %d, fDeferUpd %d, fAckReq %d, cfFormat %d\n",
1317 dde_data->unused, dde_data->fResponse, dde_data->fRelease,
1318 dde_data->reserved, dde_data->fAckReq, dde_data->cfFormat);
1319 push_data( data, ptr, size );
1320 hunlock = (HGLOBAL)uiLo;
1323 TRACE( "send ddepack %u %x\n", size, uiHi );
1325 case WM_DDE_EXECUTE:
1328 if ((ptr = GlobalLock( (HGLOBAL)info->lparam) ))
1330 push_data(data, ptr, GlobalSize( (HGLOBAL)info->lparam ));
1331 /* so that the other side can send it back on ACK */
1333 hunlock = (HGLOBAL)info->lparam;
1338 SERVER_START_REQ( send_message )
1341 req->type = info->type;
1343 req->win = info->hwnd;
1344 req->msg = info->msg;
1345 req->wparam = info->wparam;
1347 req->time = GetCurrentTime();
1349 for (i = 0; i < data->count; i++)
1350 wine_server_add_data( req, data->data[i], data->size[i] );
1351 if ((res = wine_server_call( req )))
1353 if (res == STATUS_INVALID_PARAMETER)
1354 /* FIXME: find a STATUS_ value for this one */
1355 SetLastError( ERROR_INVALID_THREAD_ID );
1357 SetLastError( RtlNtStatusToDosError(res) );
1360 FreeDDElParam(info->msg, info->lparam);
1363 if (hunlock) GlobalUnlock(hunlock);
1368 /***********************************************************************
1369 * unpack_dde_message
1371 * Unpack a posted DDE message received from another process.
1373 static BOOL unpack_dde_message( HWND hwnd, UINT message, WPARAM *wparam, LPARAM *lparam,
1374 void **buffer, size_t size )
1385 /* hMem is being passed */
1386 if (size != sizeof(HGLOBAL)) return FALSE;
1387 if (!buffer || !*buffer) return FALSE;
1389 memcpy( &hMem, *buffer, size );
1391 TRACE("recv dde-ack %x mem=%x[%lx]\n", uiLo, uiHi, GlobalSize( hMem ));
1395 uiLo = LOWORD( *lparam );
1396 uiHi = HIWORD( *lparam );
1397 TRACE("recv dde-ack %x atom=%x\n", uiLo, uiHi);
1399 *lparam = PackDDElParam( WM_DDE_ACK, uiLo, uiHi );
1404 if ((!buffer || !*buffer) && message != WM_DDE_DATA) return FALSE;
1406 TRACE( "recv ddepack %u %x\n", size, uiHi );
1409 hMem = GlobalAlloc( GMEM_MOVEABLE|GMEM_DDESHARE, size );
1410 if (hMem && (ptr = GlobalLock( hMem )))
1412 memcpy( ptr, *buffer, size );
1413 GlobalUnlock( hMem );
1419 *lparam = PackDDElParam( message, uiLo, uiHi );
1421 case WM_DDE_EXECUTE:
1424 if (!buffer || !*buffer) return FALSE;
1425 hMem = GlobalAlloc( GMEM_MOVEABLE|GMEM_DDESHARE, size );
1426 if (hMem && (ptr = GlobalLock( hMem )))
1428 memcpy( ptr, *buffer, size );
1429 GlobalUnlock( hMem );
1430 TRACE( "exec: pairing c=%08lx s=%08lx\n", *lparam, (DWORD)hMem );
1431 if (!dde_add_pair( (HGLOBAL)*lparam, hMem ))
1437 } else return FALSE;
1438 *lparam = (LPARAM)hMem;
1444 /***********************************************************************
1447 * Call a window procedure and the corresponding hooks.
1449 static LRESULT call_window_proc( HWND hwnd, UINT msg, WPARAM wparam, LPARAM lparam,
1450 BOOL unicode, BOOL same_thread )
1455 CWPRETSTRUCT cwpret;
1456 MESSAGEQUEUE *queue = QUEUE_Current();
1458 if (queue->recursion_count > MAX_SENDMSG_RECURSION) return 0;
1459 queue->recursion_count++;
1461 if (msg & 0x80000000)
1463 result = handle_internal_message( hwnd, msg, wparam, lparam );
1467 /* first the WH_CALLWNDPROC hook */
1468 hwnd = WIN_GetFullHandle( hwnd );
1469 cwp.lParam = lparam;
1470 cwp.wParam = wparam;
1473 HOOK_CallHooks( WH_CALLWNDPROC, HC_ACTION, same_thread, (LPARAM)&cwp, unicode );
1475 /* now call the window procedure */
1478 if (!(winproc = (WNDPROC)GetWindowLongPtrW( hwnd, GWLP_WNDPROC ))) goto done;
1479 result = CallWindowProcW( winproc, hwnd, msg, wparam, lparam );
1483 if (!(winproc = (WNDPROC)GetWindowLongPtrA( hwnd, GWLP_WNDPROC ))) goto done;
1484 result = CallWindowProcA( winproc, hwnd, msg, wparam, lparam );
1487 /* and finally the WH_CALLWNDPROCRET hook */
1488 cwpret.lResult = result;
1489 cwpret.lParam = lparam;
1490 cwpret.wParam = wparam;
1491 cwpret.message = msg;
1493 HOOK_CallHooks( WH_CALLWNDPROCRET, HC_ACTION, same_thread, (LPARAM)&cwpret, unicode );
1495 queue->recursion_count--;
1500 /***********************************************************************
1501 * process_hardware_message
1503 * Process a hardware message; return TRUE if message should be passed on to the app
1505 static BOOL process_hardware_message( MSG *msg, ULONG_PTR extra_info, HWND hwnd,
1506 UINT first, UINT last, BOOL remove )
1510 if (!MSG_process_raw_hardware_message( msg, extra_info, hwnd, first, last, remove ))
1513 ret = MSG_process_cooked_hardware_message( msg, extra_info, remove );
1515 /* tell the server we have passed it to the app
1516 * (even though we may end up dropping it later on)
1518 SERVER_START_REQ( reply_message )
1520 req->type = MSG_HARDWARE;
1522 req->remove = remove || !ret;
1523 wine_server_call( req );
1530 /***********************************************************************
1531 * call_sendmsg_callback
1533 * Call the callback function of SendMessageCallback.
1535 static inline void call_sendmsg_callback( SENDASYNCPROC callback, HWND hwnd, UINT msg,
1536 ULONG_PTR data, LRESULT result )
1538 if (TRACE_ON(relay))
1539 DPRINTF( "%04lx:Call message callback %p (hwnd=%p,msg=%s,data=%08lx,result=%08lx)\n",
1540 GetCurrentThreadId(), callback, hwnd, SPY_GetMsgName( msg, hwnd ),
1542 callback( hwnd, msg, data, result );
1543 if (TRACE_ON(relay))
1544 DPRINTF( "%04lx:Ret message callback %p (hwnd=%p,msg=%s,data=%08lx,result=%08lx)\n",
1545 GetCurrentThreadId(), callback, hwnd, SPY_GetMsgName( msg, hwnd ),
1550 /***********************************************************************
1553 * Retrieve the hook procedure real value for a module-relative proc
1555 static void *get_hook_proc( void *proc, const WCHAR *module )
1559 if (!(mod = GetModuleHandleW(module)))
1561 TRACE( "loading %s\n", debugstr_w(module) );
1562 /* FIXME: the library will never be freed */
1563 if (!(mod = LoadLibraryW(module))) return NULL;
1565 return (char *)mod + (ULONG_PTR)proc;
1569 /***********************************************************************
1572 * Peek for a message matching the given parameters. Return FALSE if none available.
1573 * All pending sent messages are processed before returning.
1575 BOOL MSG_peek_message( MSG *msg, HWND hwnd, UINT first, UINT last, int flags )
1578 ULONG_PTR extra_info = 0;
1579 MESSAGEQUEUE *queue = QUEUE_Current();
1580 struct received_message_info info, *old_info;
1582 if (!first && !last) last = ~0;
1587 void *buffer = NULL;
1588 size_t size = 0, buffer_size = 0;
1590 do /* loop while buffer is too small */
1592 if (buffer_size && !(buffer = HeapAlloc( GetProcessHeap(), 0, buffer_size )))
1594 SERVER_START_REQ( get_message )
1597 req->get_win = hwnd;
1598 req->get_first = first;
1599 req->get_last = last;
1600 if (buffer_size) wine_server_set_reply( req, buffer, buffer_size );
1601 if (!(res = wine_server_call( req )))
1603 size = wine_server_reply_size( reply );
1604 info.type = reply->type;
1605 info.msg.hwnd = reply->win;
1606 info.msg.message = reply->msg;
1607 info.msg.wParam = reply->wparam;
1608 info.msg.lParam = reply->lparam;
1609 info.msg.time = reply->time;
1610 info.msg.pt.x = reply->x;
1611 info.msg.pt.y = reply->y;
1612 info.hook = reply->hook;
1613 info.hook_proc = reply->hook_proc;
1614 extra_info = reply->info;
1618 HeapFree( GetProcessHeap(), 0, buffer );
1619 buffer_size = reply->total;
1623 } while (res == STATUS_BUFFER_OVERFLOW);
1625 if (res) return FALSE;
1627 TRACE( "got type %d msg %x (%s) hwnd %p wp %x lp %lx\n",
1628 info.type, info.msg.message,
1629 (info.type == MSG_WINEVENT) ? "MSG_WINEVENT" : SPY_GetMsgName(info.msg.message, info.msg.hwnd),
1630 info.msg.hwnd, info.msg.wParam, info.msg.lParam );
1636 info.flags = ISMEX_SEND;
1639 info.flags = ISMEX_NOTIFY;
1642 info.flags = ISMEX_CALLBACK;
1644 case MSG_CALLBACK_RESULT:
1645 call_sendmsg_callback( (SENDASYNCPROC)info.msg.wParam, info.msg.hwnd,
1646 info.msg.message, extra_info, info.msg.lParam );
1651 WCHAR module[MAX_PATH];
1652 size = min( size, (MAX_PATH - 1) * sizeof(WCHAR) );
1653 memcpy( module, buffer, size );
1654 module[size / sizeof(WCHAR)] = 0;
1655 if (!(info.hook_proc = get_hook_proc( info.hook_proc, module )))
1657 ERR( "invalid winevent hook module name %s\n", debugstr_w(module) );
1661 if (TRACE_ON(relay))
1662 DPRINTF( "%04lx:Call winevent proc %p (hook=%p,event=%x,hwnd=%p,object_id=%x,child_id=%lx,tid=%04lx,time=%lx)\n",
1663 GetCurrentThreadId(), info.hook_proc,
1664 info.hook, info.msg.message, info.msg.hwnd, info.msg.wParam,
1665 info.msg.lParam, extra_info, info.msg.time);
1667 info.hook_proc( info.hook, info.msg.message, info.msg.hwnd, info.msg.wParam,
1668 info.msg.lParam, extra_info, info.msg.time );
1670 if (TRACE_ON(relay))
1671 DPRINTF( "%04lx:Ret winevent proc %p (hook=%p,event=%x,hwnd=%p,object_id=%x,child_id=%lx,tid=%04lx,time=%lx)\n",
1672 GetCurrentThreadId(), info.hook_proc,
1673 info.hook, info.msg.message, info.msg.hwnd, info.msg.wParam,
1674 info.msg.lParam, extra_info, info.msg.time);
1676 case MSG_OTHER_PROCESS:
1677 info.flags = ISMEX_SEND;
1678 if (!unpack_message( info.msg.hwnd, info.msg.message, &info.msg.wParam,
1679 &info.msg.lParam, &buffer, size ))
1681 ERR( "invalid packed message %x (%s) hwnd %p wp %x lp %lx size %d\n",
1682 info.msg.message, SPY_GetMsgName(info.msg.message, info.msg.hwnd), info.msg.hwnd,
1683 info.msg.wParam, info.msg.lParam, size );
1685 reply_message( &info, 0, TRUE );
1690 if (!process_hardware_message( &info.msg, extra_info,
1691 hwnd, first, last, flags & GET_MSG_REMOVE ))
1693 TRACE("dropping msg %x\n", info.msg.message );
1694 goto next; /* ignore it */
1696 queue->GetMessagePosVal = MAKELONG( info.msg.pt.x, info.msg.pt.y );
1699 queue->GetMessageExtraInfoVal = extra_info;
1700 if (info.msg.message >= WM_DDE_FIRST && info.msg.message <= WM_DDE_LAST)
1702 if (!unpack_dde_message( info.msg.hwnd, info.msg.message, &info.msg.wParam,
1703 &info.msg.lParam, &buffer, size ))
1705 ERR( "invalid packed dde-message %x (%s) hwnd %p wp %x lp %lx size %d\n",
1706 info.msg.message, SPY_GetMsgName(info.msg.message, info.msg.hwnd),
1707 info.msg.hwnd, info.msg.wParam, info.msg.lParam, size );
1708 goto next; /* ignore it */
1712 HeapFree( GetProcessHeap(), 0, buffer );
1716 /* if we get here, we have a sent message; call the window procedure */
1717 old_info = queue->receive_info;
1718 queue->receive_info = &info;
1719 result = call_window_proc( info.msg.hwnd, info.msg.message, info.msg.wParam,
1720 info.msg.lParam, (info.type != MSG_ASCII), FALSE );
1721 reply_message( &info, result, TRUE );
1722 queue->receive_info = old_info;
1724 HeapFree( GetProcessHeap(), 0, buffer );
1729 /***********************************************************************
1730 * wait_message_reply
1732 * Wait until a sent message gets replied to.
1734 static void wait_message_reply( UINT flags )
1736 MESSAGEQUEUE *queue;
1738 if (!(queue = QUEUE_Current())) return;
1742 unsigned int wake_bits = 0, changed_bits = 0;
1745 SERVER_START_REQ( set_queue_mask )
1747 req->wake_mask = QS_SMRESULT | ((flags & SMTO_BLOCK) ? 0 : QS_SENDMESSAGE);
1748 req->changed_mask = req->wake_mask;
1750 if (!wine_server_call( req ))
1752 wake_bits = reply->wake_bits;
1753 changed_bits = reply->changed_bits;
1758 if (wake_bits & QS_SMRESULT) return; /* got a result */
1759 if (wake_bits & QS_SENDMESSAGE)
1761 /* Process the sent message immediately */
1763 MSG_peek_message( &msg, 0, 0, 0, GET_MSG_REMOVE | GET_MSG_SENT_ONLY );
1767 /* now wait for it */
1769 ReleaseThunkLock( &dwlc );
1771 if (USER_Driver.pMsgWaitForMultipleObjectsEx)
1772 res = USER_Driver.pMsgWaitForMultipleObjectsEx( 1, &queue->server_queue,
1775 res = WaitForSingleObject( queue->server_queue, INFINITE );
1777 if (dwlc) RestoreThunkLock( dwlc );
1781 /***********************************************************************
1782 * put_message_in_queue
1784 * Put a sent message into the destination queue.
1785 * For inter-process message, reply_size is set to expected size of reply data.
1787 static BOOL put_message_in_queue( DWORD dest_tid, const struct send_message_info *info,
1788 size_t *reply_size )
1790 struct packed_message data;
1792 int i, timeout = -1;
1794 if (info->type != MSG_NOTIFY &&
1795 info->type != MSG_CALLBACK &&
1796 info->type != MSG_POSTED &&
1797 info->timeout != INFINITE)
1798 timeout = info->timeout;
1801 if (info->type == MSG_OTHER_PROCESS)
1803 *reply_size = pack_message( info->hwnd, info->msg, info->wparam, info->lparam, &data );
1804 if (data.count == -1)
1806 WARN( "cannot pack message %x\n", info->msg );
1810 else if (info->type == MSG_POSTED && info->msg >= WM_DDE_FIRST && info->msg <= WM_DDE_LAST)
1812 return post_dde_message( dest_tid, &data, info );
1815 SERVER_START_REQ( send_message )
1818 req->type = info->type;
1820 req->win = info->hwnd;
1821 req->msg = info->msg;
1822 req->wparam = info->wparam;
1823 req->lparam = info->lparam;
1824 req->time = GetCurrentTime();
1825 req->timeout = timeout;
1827 if (info->type == MSG_CALLBACK)
1829 req->callback = info->callback;
1830 req->info = info->data;
1833 if (info->flags & SMTO_ABORTIFHUNG) req->flags |= SEND_MSG_ABORT_IF_HUNG;
1834 for (i = 0; i < data.count; i++) wine_server_add_data( req, data.data[i], data.size[i] );
1835 if ((res = wine_server_call( req )))
1837 if (res == STATUS_INVALID_PARAMETER)
1838 /* FIXME: find a STATUS_ value for this one */
1839 SetLastError( ERROR_INVALID_THREAD_ID );
1841 SetLastError( RtlNtStatusToDosError(res) );
1849 /***********************************************************************
1852 * Retrieve a message reply from the server.
1854 static LRESULT retrieve_reply( const struct send_message_info *info,
1855 size_t reply_size, LRESULT *result )
1858 void *reply_data = NULL;
1862 if (!(reply_data = HeapAlloc( GetProcessHeap(), 0, reply_size )))
1864 WARN( "no memory for reply %d bytes, will be truncated\n", reply_size );
1868 SERVER_START_REQ( get_message_reply )
1871 if (reply_size) wine_server_set_reply( req, reply_data, reply_size );
1872 if (!(status = wine_server_call( req ))) *result = reply->result;
1873 reply_size = wine_server_reply_size( reply );
1876 if (!status && reply_size)
1877 unpack_reply( info->hwnd, info->msg, info->wparam, info->lparam, reply_data, reply_size );
1879 HeapFree( GetProcessHeap(), 0, reply_data );
1881 TRACE( "hwnd %p msg %x (%s) wp %x lp %lx got reply %lx (err=%ld)\n",
1882 info->hwnd, info->msg, SPY_GetMsgName(info->msg, info->hwnd), info->wparam,
1883 info->lparam, *result, status );
1885 /* MSDN states that last error is 0 on timeout, but at least NT4 returns ERROR_TIMEOUT */
1886 if (status) SetLastError( RtlNtStatusToDosError(status) );
1891 /***********************************************************************
1892 * send_inter_thread_message
1894 static LRESULT send_inter_thread_message( DWORD dest_tid, const struct send_message_info *info,
1899 size_t reply_size = 0;
1901 TRACE( "hwnd %p msg %x (%s) wp %x lp %lx\n",
1902 info->hwnd, info->msg, SPY_GetMsgName(info->msg, info->hwnd), info->wparam, info->lparam );
1904 if (!put_message_in_queue( dest_tid, info, &reply_size )) return 0;
1906 /* there's no reply to wait for on notify/callback messages */
1907 if (info->type == MSG_NOTIFY || info->type == MSG_CALLBACK) return 1;
1909 locks = WIN_SuspendWndsLock();
1911 wait_message_reply( info->flags );
1912 ret = retrieve_reply( info, reply_size, res_ptr );
1914 WIN_RestoreWndsLock( locks );
1919 /***********************************************************************
1920 * MSG_SendInternalMessageTimeout
1922 * Same as SendMessageTimeoutW but sends the message to a specific thread
1923 * without requiring a window handle. Only works for internal Wine messages.
1925 LRESULT MSG_SendInternalMessageTimeout( DWORD dest_pid, DWORD dest_tid,
1926 UINT msg, WPARAM wparam, LPARAM lparam,
1927 UINT flags, UINT timeout, PDWORD_PTR res_ptr )
1929 struct send_message_info info;
1930 LRESULT ret, result;
1932 assert( msg & 0x80000000 ); /* must be an internal Wine message */
1934 info.type = MSG_UNICODE;
1937 info.wparam = wparam;
1938 info.lparam = lparam;
1940 info.timeout = timeout;
1942 if (USER_IsExitingThread( dest_tid )) return 0;
1944 if (dest_tid == GetCurrentThreadId())
1946 result = handle_internal_message( 0, msg, wparam, lparam );
1951 if (dest_pid != GetCurrentProcessId()) info.type = MSG_OTHER_PROCESS;
1952 ret = send_inter_thread_message( dest_tid, &info, &result );
1954 if (ret && res_ptr) *res_ptr = result;
1959 /***********************************************************************
1960 * SendMessageTimeoutW (USER32.@)
1962 LRESULT WINAPI SendMessageTimeoutW( HWND hwnd, UINT msg, WPARAM wparam, LPARAM lparam,
1963 UINT flags, UINT timeout, PDWORD_PTR res_ptr )
1965 struct send_message_info info;
1966 DWORD dest_tid, dest_pid;
1967 LRESULT ret, result;
1969 info.type = MSG_UNICODE;
1972 info.wparam = wparam;
1973 info.lparam = lparam;
1975 info.timeout = timeout;
1977 if (is_broadcast(hwnd))
1979 EnumWindows( broadcast_message_callback, (LPARAM)&info );
1980 if (res_ptr) *res_ptr = 1;
1984 if (!(dest_tid = GetWindowThreadProcessId( hwnd, &dest_pid ))) return 0;
1986 if (USER_IsExitingThread( dest_tid )) return 0;
1988 SPY_EnterMessage( SPY_SENDMESSAGE, hwnd, msg, wparam, lparam );
1990 if (dest_tid == GetCurrentThreadId())
1992 result = call_window_proc( hwnd, msg, wparam, lparam, TRUE, TRUE );
1997 if (dest_pid != GetCurrentProcessId()) info.type = MSG_OTHER_PROCESS;
1998 ret = send_inter_thread_message( dest_tid, &info, &result );
2001 SPY_ExitMessage( SPY_RESULT_OK, hwnd, msg, result, wparam, lparam );
2002 if (ret && res_ptr) *res_ptr = result;
2007 /***********************************************************************
2008 * SendMessageTimeoutA (USER32.@)
2010 LRESULT WINAPI SendMessageTimeoutA( HWND hwnd, UINT msg, WPARAM wparam, LPARAM lparam,
2011 UINT flags, UINT timeout, PDWORD_PTR res_ptr )
2013 struct send_message_info info;
2014 DWORD dest_tid, dest_pid;
2015 LRESULT ret, result;
2017 info.type = MSG_ASCII;
2020 info.wparam = wparam;
2021 info.lparam = lparam;
2023 info.timeout = timeout;
2025 if (is_broadcast(hwnd))
2027 EnumWindows( broadcast_message_callback, (LPARAM)&info );
2028 if (res_ptr) *res_ptr = 1;
2032 if (!(dest_tid = GetWindowThreadProcessId( hwnd, &dest_pid ))) return 0;
2034 if (USER_IsExitingThread( dest_tid )) return 0;
2036 SPY_EnterMessage( SPY_SENDMESSAGE, hwnd, msg, wparam, lparam );
2038 if (dest_tid == GetCurrentThreadId())
2040 result = call_window_proc( hwnd, msg, wparam, lparam, FALSE, TRUE );
2043 else if (dest_pid == GetCurrentProcessId())
2045 ret = send_inter_thread_message( dest_tid, &info, &result );
2049 /* inter-process message: need to map to Unicode */
2050 info.type = MSG_OTHER_PROCESS;
2051 if (is_unicode_message( info.msg ))
2053 if (WINPROC_MapMsg32ATo32W( info.hwnd, info.msg, &info.wparam, &info.lparam ) == -1)
2055 ret = send_inter_thread_message( dest_tid, &info, &result );
2056 result = WINPROC_UnmapMsg32ATo32W( info.hwnd, info.msg, info.wparam,
2057 info.lparam, result );
2059 else ret = send_inter_thread_message( dest_tid, &info, &result );
2061 SPY_ExitMessage( SPY_RESULT_OK, hwnd, msg, result, wparam, lparam );
2062 if (ret && res_ptr) *res_ptr = result;
2067 /***********************************************************************
2068 * SendMessageW (USER32.@)
2070 LRESULT WINAPI SendMessageW( HWND hwnd, UINT msg, WPARAM wparam, LPARAM lparam )
2073 SendMessageTimeoutW( hwnd, msg, wparam, lparam, SMTO_NORMAL, INFINITE, &res );
2078 /***********************************************************************
2079 * SendMessageA (USER32.@)
2081 LRESULT WINAPI SendMessageA( HWND hwnd, UINT msg, WPARAM wparam, LPARAM lparam )
2084 SendMessageTimeoutA( hwnd, msg, wparam, lparam, SMTO_NORMAL, INFINITE, &res );
2089 /***********************************************************************
2090 * SendNotifyMessageA (USER32.@)
2092 BOOL WINAPI SendNotifyMessageA( HWND hwnd, UINT msg, WPARAM wparam, LPARAM lparam )
2094 return SendNotifyMessageW( hwnd, msg, map_wparam_AtoW( msg, wparam ), lparam );
2098 /***********************************************************************
2099 * SendNotifyMessageW (USER32.@)
2101 BOOL WINAPI SendNotifyMessageW( HWND hwnd, UINT msg, WPARAM wparam, LPARAM lparam )
2103 struct send_message_info info;
2107 if (is_pointer_message(msg))
2109 SetLastError( ERROR_MESSAGE_SYNC_ONLY );
2113 info.type = MSG_NOTIFY;
2116 info.wparam = wparam;
2117 info.lparam = lparam;
2120 if (is_broadcast(hwnd))
2122 EnumWindows( broadcast_message_callback, (LPARAM)&info );
2126 if (!(dest_tid = GetWindowThreadProcessId( hwnd, NULL ))) return FALSE;
2128 if (USER_IsExitingThread( dest_tid )) return TRUE;
2130 if (dest_tid == GetCurrentThreadId())
2132 call_window_proc( hwnd, msg, wparam, lparam, TRUE, TRUE );
2135 return send_inter_thread_message( dest_tid, &info, &result );
2139 /***********************************************************************
2140 * SendMessageCallbackA (USER32.@)
2142 BOOL WINAPI SendMessageCallbackA( HWND hwnd, UINT msg, WPARAM wparam, LPARAM lparam,
2143 SENDASYNCPROC callback, ULONG_PTR data )
2145 return SendMessageCallbackW( hwnd, msg, map_wparam_AtoW( msg, wparam ),
2146 lparam, callback, data );
2150 /***********************************************************************
2151 * SendMessageCallbackW (USER32.@)
2153 BOOL WINAPI SendMessageCallbackW( HWND hwnd, UINT msg, WPARAM wparam, LPARAM lparam,
2154 SENDASYNCPROC callback, ULONG_PTR data )
2156 struct send_message_info info;
2160 if (is_pointer_message(msg))
2162 SetLastError( ERROR_MESSAGE_SYNC_ONLY );
2166 info.type = MSG_CALLBACK;
2169 info.wparam = wparam;
2170 info.lparam = lparam;
2171 info.callback = callback;
2175 if (is_broadcast(hwnd))
2177 EnumWindows( broadcast_message_callback, (LPARAM)&info );
2181 if (!(dest_tid = GetWindowThreadProcessId( hwnd, NULL ))) return FALSE;
2183 if (USER_IsExitingThread( dest_tid )) return TRUE;
2185 if (dest_tid == GetCurrentThreadId())
2187 result = call_window_proc( hwnd, msg, wparam, lparam, TRUE, TRUE );
2188 call_sendmsg_callback( callback, hwnd, msg, data, result );
2191 FIXME( "callback will not be called\n" );
2192 return send_inter_thread_message( dest_tid, &info, &result );
2196 /***********************************************************************
2197 * ReplyMessage (USER32.@)
2199 BOOL WINAPI ReplyMessage( LRESULT result )
2201 MESSAGEQUEUE *queue = QUEUE_Current();
2202 struct received_message_info *info = queue->receive_info;
2204 if (!info) return FALSE;
2205 reply_message( info, result, FALSE );
2210 /***********************************************************************
2211 * InSendMessage (USER32.@)
2213 BOOL WINAPI InSendMessage(void)
2215 return (InSendMessageEx(NULL) & (ISMEX_SEND|ISMEX_REPLIED)) == ISMEX_SEND;
2219 /***********************************************************************
2220 * InSendMessageEx (USER32.@)
2222 DWORD WINAPI InSendMessageEx( LPVOID reserved )
2224 MESSAGEQUEUE *queue = QUEUE_Current();
2225 struct received_message_info *info = queue->receive_info;
2227 if (info) return info->flags;
2228 return ISMEX_NOSEND;
2232 /***********************************************************************
2233 * PostMessageA (USER32.@)
2235 BOOL WINAPI PostMessageA( HWND hwnd, UINT msg, WPARAM wparam, LPARAM lparam )
2237 return PostMessageW( hwnd, msg, map_wparam_AtoW( msg, wparam ), lparam );
2241 /***********************************************************************
2242 * PostMessageW (USER32.@)
2244 BOOL WINAPI PostMessageW( HWND hwnd, UINT msg, WPARAM wparam, LPARAM lparam )
2246 struct send_message_info info;
2249 if (is_pointer_message( msg ))
2251 SetLastError( ERROR_MESSAGE_SYNC_ONLY );
2255 TRACE( "hwnd %p msg %x (%s) wp %x lp %lx\n",
2256 hwnd, msg, SPY_GetMsgName(msg, hwnd), wparam, lparam );
2258 info.type = MSG_POSTED;
2261 info.wparam = wparam;
2262 info.lparam = lparam;
2265 if (is_broadcast(hwnd))
2267 EnumWindows( broadcast_message_callback, (LPARAM)&info );
2271 if (!hwnd) return PostThreadMessageW( GetCurrentThreadId(), msg, wparam, lparam );
2273 if (!(dest_tid = GetWindowThreadProcessId( hwnd, NULL ))) return FALSE;
2275 if (USER_IsExitingThread( dest_tid )) return TRUE;
2277 return put_message_in_queue( dest_tid, &info, NULL );
2281 /**********************************************************************
2282 * PostThreadMessageA (USER32.@)
2284 BOOL WINAPI PostThreadMessageA( DWORD thread, UINT msg, WPARAM wparam, LPARAM lparam )
2286 return PostThreadMessageW( thread, msg, map_wparam_AtoW( msg, wparam ), lparam );
2290 /**********************************************************************
2291 * PostThreadMessageW (USER32.@)
2293 BOOL WINAPI PostThreadMessageW( DWORD thread, UINT msg, WPARAM wparam, LPARAM lparam )
2295 struct send_message_info info;
2297 if (is_pointer_message( msg ))
2299 SetLastError( ERROR_MESSAGE_SYNC_ONLY );
2302 if (USER_IsExitingThread( thread )) return TRUE;
2304 info.type = MSG_POSTED;
2307 info.wparam = wparam;
2308 info.lparam = lparam;
2310 return put_message_in_queue( thread, &info, NULL );
2314 /***********************************************************************
2315 * PostQuitMessage (USER32.@)
2317 void WINAPI PostQuitMessage( INT exitCode )
2319 PostThreadMessageW( GetCurrentThreadId(), WM_QUIT, exitCode, 0 );
2323 /***********************************************************************
2324 * PeekMessageW (USER32.@)
2326 BOOL WINAPI PeekMessageW( MSG *msg_out, HWND hwnd, UINT first, UINT last, UINT flags )
2328 MESSAGEQUEUE *queue;
2332 /* check for graphics events */
2333 if (USER_Driver.pMsgWaitForMultipleObjectsEx)
2334 USER_Driver.pMsgWaitForMultipleObjectsEx( 0, NULL, 0, 0, 0 );
2336 hwnd = WIN_GetFullHandle( hwnd );
2337 locks = WIN_SuspendWndsLock();
2339 if (!MSG_peek_message( &msg, hwnd, first, last,
2340 (flags & PM_REMOVE) ? GET_MSG_REMOVE : 0 ))
2342 if (!(flags & PM_NOYIELD))
2345 ReleaseThunkLock(&count);
2346 if (count) RestoreThunkLock(count);
2348 WIN_RestoreWndsLock( locks );
2352 WIN_RestoreWndsLock( locks );
2354 if (msg.message == WM_PAINT) /* clear internal paint flag */
2355 RedrawWindow( msg.hwnd, NULL, 0, RDW_NOINTERNALPAINT | RDW_NOCHILDREN );
2357 if ((queue = QUEUE_Current()))
2359 queue->GetMessageTimeVal = msg.time;
2360 msg.pt.x = LOWORD( queue->GetMessagePosVal );
2361 msg.pt.y = HIWORD( queue->GetMessagePosVal );
2364 HOOK_CallHooks( WH_GETMESSAGE, HC_ACTION, flags & PM_REMOVE, (LPARAM)&msg, TRUE );
2366 /* copy back our internal safe copy of message data to msg_out.
2367 * msg_out is a variable from the *program*, so it can't be used
2368 * internally as it can get "corrupted" by our use of SendMessage()
2369 * (back to the program) inside the message handling itself. */
2372 SetLastError( ERROR_NOACCESS );
2380 /***********************************************************************
2381 * PeekMessageA (USER32.@)
2383 BOOL WINAPI PeekMessageA( MSG *msg, HWND hwnd, UINT first, UINT last, UINT flags )
2385 BOOL ret = PeekMessageW( msg, hwnd, first, last, flags );
2386 if (ret) msg->wParam = map_wparam_WtoA( msg->message, msg->wParam );
2391 /***********************************************************************
2392 * GetMessageW (USER32.@)
2394 BOOL WINAPI GetMessageW( MSG *msg, HWND hwnd, UINT first, UINT last )
2396 MESSAGEQUEUE *queue = QUEUE_Current();
2399 mask = QS_POSTMESSAGE | QS_SENDMESSAGE; /* Always selected */
2402 if ((first <= WM_KEYLAST) && (last >= WM_KEYFIRST)) mask |= QS_KEY;
2403 if ( ((first <= WM_MOUSELAST) && (last >= WM_MOUSEFIRST)) ||
2404 ((first <= WM_NCMOUSELAST) && (last >= WM_NCMOUSEFIRST)) ) mask |= QS_MOUSE;
2405 if ((first <= WM_TIMER) && (last >= WM_TIMER)) mask |= QS_TIMER;
2406 if ((first <= WM_SYSTIMER) && (last >= WM_SYSTIMER)) mask |= QS_TIMER;
2407 if ((first <= WM_PAINT) && (last >= WM_PAINT)) mask |= QS_PAINT;
2409 else mask |= QS_MOUSE | QS_KEY | QS_TIMER | QS_PAINT;
2411 locks = WIN_SuspendWndsLock();
2413 while (!PeekMessageW( msg, hwnd, first, last, PM_REMOVE ))
2415 /* wait until one of the bits is set */
2416 unsigned int wake_bits = 0, changed_bits = 0;
2419 SERVER_START_REQ( set_queue_mask )
2421 req->wake_mask = QS_SENDMESSAGE;
2422 req->changed_mask = mask;
2424 if (!wine_server_call( req ))
2426 wake_bits = reply->wake_bits;
2427 changed_bits = reply->changed_bits;
2432 if (changed_bits & mask) continue;
2433 if (wake_bits & QS_SENDMESSAGE) continue;
2435 TRACE( "(%04x) mask=%08x, bits=%08x, changed=%08x, waiting\n",
2436 queue->self, mask, wake_bits, changed_bits );
2438 ReleaseThunkLock( &dwlc );
2439 if (USER_Driver.pMsgWaitForMultipleObjectsEx)
2440 USER_Driver.pMsgWaitForMultipleObjectsEx( 1, &queue->server_queue, INFINITE, 0, 0 );
2442 WaitForSingleObject( queue->server_queue, INFINITE );
2443 if (dwlc) RestoreThunkLock( dwlc );
2446 WIN_RestoreWndsLock( locks );
2448 return (msg->message != WM_QUIT);
2452 /***********************************************************************
2453 * GetMessageA (USER32.@)
2455 BOOL WINAPI GetMessageA( MSG *msg, HWND hwnd, UINT first, UINT last )
2457 GetMessageW( msg, hwnd, first, last );
2458 msg->wParam = map_wparam_WtoA( msg->message, msg->wParam );
2459 return (msg->message != WM_QUIT);
2463 /***********************************************************************
2464 * IsDialogMessage (USER32.@)
2465 * IsDialogMessageA (USER32.@)
2467 BOOL WINAPI IsDialogMessageA( HWND hwndDlg, LPMSG pmsg )
2470 msg.wParam = map_wparam_AtoW( msg.message, msg.wParam );
2471 return IsDialogMessageW( hwndDlg, &msg );
2475 /***********************************************************************
2476 * SetMessageQueue (USER32.@)
2478 BOOL WINAPI SetMessageQueue( INT size )
2480 /* now obsolete the message queue will be expanded dynamically as necessary */
2485 /***********************************************************************
2486 * MessageBeep (USER32.@)
2488 BOOL WINAPI MessageBeep( UINT i )
2491 SystemParametersInfoA( SPI_GETBEEP, 0, &active, FALSE );
2492 if (active && USER_Driver.pBeep) USER_Driver.pBeep();
2497 /***********************************************************************
2498 * SetTimer (USER32.@)
2500 UINT_PTR WINAPI SetTimer( HWND hwnd, UINT_PTR id, UINT timeout, TIMERPROC proc )
2503 WNDPROC winproc = 0;
2505 if (proc) winproc = WINPROC_AllocProc( (WNDPROC)proc, WIN_PROC_32A );
2507 SERVER_START_REQ( set_win_timer )
2510 req->msg = WM_TIMER;
2512 req->rate = max( timeout, SYS_TIMER_RATE );
2513 req->lparam = (unsigned int)winproc;
2514 if (!wine_server_call_err( req ))
2517 if (!ret) ret = TRUE;
2523 TRACE("Added %p %x %p timeout %d\n", hwnd, id, winproc, timeout );
2528 /***********************************************************************
2529 * SetSystemTimer (USER32.@)
2531 UINT_PTR WINAPI SetSystemTimer( HWND hwnd, UINT_PTR id, UINT timeout, TIMERPROC proc )
2534 WNDPROC winproc = 0;
2536 if (proc) winproc = WINPROC_AllocProc( (WNDPROC)proc, WIN_PROC_32A );
2538 SERVER_START_REQ( set_win_timer )
2541 req->msg = WM_SYSTIMER;
2543 req->rate = max( timeout, SYS_TIMER_RATE );
2544 req->lparam = (unsigned int)winproc;
2545 if (!wine_server_call_err( req ))
2548 if (!ret) ret = TRUE;
2554 TRACE("Added %p %x %p timeout %d\n", hwnd, id, winproc, timeout );
2559 /***********************************************************************
2560 * KillTimer (USER32.@)
2562 BOOL WINAPI KillTimer( HWND hwnd, UINT_PTR id )
2566 TRACE("%p %d\n", hwnd, id );
2568 SERVER_START_REQ( kill_win_timer )
2571 req->msg = WM_TIMER;
2573 ret = !wine_server_call_err( req );
2580 /***********************************************************************
2581 * KillSystemTimer (USER32.@)
2583 BOOL WINAPI KillSystemTimer( HWND hwnd, UINT_PTR id )
2587 TRACE("%p %d\n", hwnd, id );
2589 SERVER_START_REQ( kill_win_timer )
2592 req->msg = WM_SYSTIMER;
2594 ret = !wine_server_call_err( req );
2601 /**********************************************************************
2602 * AttachThreadInput (USER32.@)
2604 * Attaches the input processing mechanism of one thread to that of
2607 BOOL WINAPI AttachThreadInput( DWORD from, DWORD to, BOOL attach )
2611 SERVER_START_REQ( attach_thread_input )
2613 req->tid_from = from;
2615 req->attach = attach;
2616 ret = !wine_server_call_err( req );
2623 /**********************************************************************
2624 * GetGUIThreadInfo (USER32.@)
2626 BOOL WINAPI GetGUIThreadInfo( DWORD id, GUITHREADINFO *info )
2630 SERVER_START_REQ( get_thread_input )
2633 if ((ret = !wine_server_call_err( req )))
2636 info->hwndActive = reply->active;
2637 info->hwndFocus = reply->focus;
2638 info->hwndCapture = reply->capture;
2639 info->hwndMenuOwner = reply->menu_owner;
2640 info->hwndMoveSize = reply->move_size;
2641 info->hwndCaret = reply->caret;
2642 info->rcCaret.left = reply->rect.left;
2643 info->rcCaret.top = reply->rect.top;
2644 info->rcCaret.right = reply->rect.right;
2645 info->rcCaret.bottom = reply->rect.bottom;
2646 if (reply->menu_owner) info->flags |= GUI_INMENUMODE;
2647 if (reply->move_size) info->flags |= GUI_INMOVESIZE;
2648 if (reply->caret) info->flags |= GUI_CARETBLINKING;
2656 /**********************************************************************
2657 * GetKeyState (USER32.@)
2659 * An application calls the GetKeyState function in response to a
2660 * keyboard-input message. This function retrieves the state of the key
2661 * at the time the input message was generated.
2663 SHORT WINAPI GetKeyState(INT vkey)
2667 SERVER_START_REQ( get_key_state )
2669 req->tid = GetCurrentThreadId();
2671 if (!wine_server_call( req )) retval = (signed char)reply->state;
2674 TRACE("key (0x%x) -> %x\n", vkey, retval);
2679 /**********************************************************************
2680 * GetKeyboardState (USER32.@)
2682 BOOL WINAPI GetKeyboardState( LPBYTE state )
2686 TRACE("(%p)\n", state);
2688 memset( state, 0, 256 );
2689 SERVER_START_REQ( get_key_state )
2691 req->tid = GetCurrentThreadId();
2693 wine_server_set_reply( req, state, 256 );
2694 ret = !wine_server_call_err( req );
2701 /**********************************************************************
2702 * SetKeyboardState (USER32.@)
2704 BOOL WINAPI SetKeyboardState( LPBYTE state )
2708 TRACE("(%p)\n", state);
2710 SERVER_START_REQ( set_key_state )
2712 req->tid = GetCurrentThreadId();
2713 wine_server_add_data( req, state, 256 );
2714 ret = !wine_server_call_err( req );
2720 /******************************************************************
2721 * IsHungAppWindow (USER32.@)
2724 BOOL WINAPI IsHungAppWindow( HWND hWnd )
2727 return !SendMessageTimeoutA(hWnd, WM_NULL, 0, 0, SMTO_ABORTIFHUNG, 5000, &dwResult);
2730 /******************************************************************
2731 * GetLastInputInfo (USER32.@)
2733 BOOL WINAPI GetLastInputInfo(PLASTINPUTINFO plii)
2735 FIXME("%p\n", plii);