2 * Window messaging support
4 * Copyright 2001 Alexandre Julliard
5 * Copyright 2008 Maarten Lankhorst
7 * This library is free software; you can redistribute it and/or
8 * modify it under the terms of the GNU Lesser General Public
9 * License as published by the Free Software Foundation; either
10 * version 2.1 of the License, or (at your option) any later version.
12 * This library is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
15 * Lesser General Public License for more details.
17 * You should have received a copy of the GNU Lesser General Public
18 * License along with this library; if not, write to the Free Software
19 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
23 #include "wine/port.h"
29 #define WIN32_NO_STATUS
40 #include "wine/unicode.h"
41 #include "wine/server.h"
42 #include "user_private.h"
45 #include "wine/debug.h"
46 #include "wine/exception.h"
48 WINE_DEFAULT_DEBUG_CHANNEL(msg);
49 WINE_DECLARE_DEBUG_CHANNEL(relay);
50 WINE_DECLARE_DEBUG_CHANNEL(key);
52 #define WM_NCMOUSEFIRST WM_NCMOUSEMOVE
53 #define WM_NCMOUSELAST (WM_NCMOUSEFIRST+(WM_MOUSELAST-WM_MOUSEFIRST))
55 #define MAX_PACK_COUNT 4
57 #define SYS_TIMER_RATE 55 /* min. timer rate in ms (actually 54.925)*/
59 /* the various structures that can be sent in messages, in platform-independent layout */
60 struct packed_CREATESTRUCTW
62 ULONGLONG lpCreateParams;
66 user_handle_t hwndParent;
79 struct packed_DRAWITEMSTRUCT
86 user_handle_t hwndItem;
94 struct packed_MEASUREITEMSTRUCT
104 struct packed_DELETEITEMSTRUCT
109 user_handle_t hwndItem;
114 struct packed_COMPAREITEMSTRUCT
118 user_handle_t hwndItem;
128 struct packed_WINDOWPOS
132 user_handle_t hwndInsertAfter;
142 struct packed_COPYDATASTRUCT
149 struct packed_HELPINFO
154 user_handle_t hItemHandle;
156 ULONGLONG dwContextId;
160 struct packed_NCCALCSIZE_PARAMS
166 user_handle_t hwndInsertAfter;
188 struct packed_MDINEXTMENU
190 user_handle_t hmenuIn;
192 user_handle_t hmenuNext;
194 user_handle_t hwndNext;
198 struct packed_MDICREATESTRUCTW
211 struct packed_hook_extra_info
213 user_handle_t handle;
218 /* the structures are unpacked on top of the packed ones, so make sure they fit */
219 C_ASSERT( sizeof(struct packed_CREATESTRUCTW) >= sizeof(CREATESTRUCTW) );
220 C_ASSERT( sizeof(struct packed_DRAWITEMSTRUCT) >= sizeof(DRAWITEMSTRUCT) );
221 C_ASSERT( sizeof(struct packed_MEASUREITEMSTRUCT) >= sizeof(MEASUREITEMSTRUCT) );
222 C_ASSERT( sizeof(struct packed_DELETEITEMSTRUCT) >= sizeof(DELETEITEMSTRUCT) );
223 C_ASSERT( sizeof(struct packed_COMPAREITEMSTRUCT) >= sizeof(COMPAREITEMSTRUCT) );
224 C_ASSERT( sizeof(struct packed_WINDOWPOS) >= sizeof(WINDOWPOS) );
225 C_ASSERT( sizeof(struct packed_COPYDATASTRUCT) >= sizeof(COPYDATASTRUCT) );
226 C_ASSERT( sizeof(struct packed_HELPINFO) >= sizeof(HELPINFO) );
227 C_ASSERT( sizeof(struct packed_NCCALCSIZE_PARAMS) >= sizeof(NCCALCSIZE_PARAMS) + sizeof(WINDOWPOS) );
228 C_ASSERT( sizeof(struct packed_MSG) >= sizeof(MSG) );
229 C_ASSERT( sizeof(struct packed_MDINEXTMENU) >= sizeof(MDINEXTMENU) );
230 C_ASSERT( sizeof(struct packed_MDICREATESTRUCTW) >= sizeof(MDICREATESTRUCTW) );
231 C_ASSERT( sizeof(struct packed_hook_extra_info) >= sizeof(struct hook_extra_info) );
235 struct packed_CREATESTRUCTW cs;
236 struct packed_DRAWITEMSTRUCT dis;
237 struct packed_MEASUREITEMSTRUCT mis;
238 struct packed_DELETEITEMSTRUCT dls;
239 struct packed_COMPAREITEMSTRUCT cis;
240 struct packed_WINDOWPOS wp;
241 struct packed_COPYDATASTRUCT cds;
242 struct packed_HELPINFO hi;
243 struct packed_NCCALCSIZE_PARAMS ncp;
244 struct packed_MSG msg;
245 struct packed_MDINEXTMENU mnm;
246 struct packed_MDICREATESTRUCTW mcs;
247 struct packed_hook_extra_info hook;
250 /* description of the data fields that need to be packed along with a sent message */
251 struct packed_message
253 union packed_structs ps;
255 const void *data[MAX_PACK_COUNT];
256 size_t size[MAX_PACK_COUNT];
259 /* info about the message currently being received by the current thread */
260 struct received_message_info
262 enum message_type type;
264 UINT flags; /* InSendMessageEx return flags */
267 /* structure to group all parameters for sent messages of the various kinds */
268 struct send_message_info
270 enum message_type type;
276 UINT flags; /* flags for SendMessageTimeout */
277 UINT timeout; /* timeout for SendMessageTimeout */
278 SENDASYNCPROC callback; /* callback function for SendMessageCallback */
279 ULONG_PTR data; /* callback data */
280 enum wm_char_mapping wm_char;
284 /* Message class descriptor */
285 static const WCHAR messageW[] = {'M','e','s','s','a','g','e',0};
287 const struct builtin_class_descr MESSAGE_builtin_class =
291 WINPROC_MESSAGE, /* proc */
293 IDC_ARROW, /* cursor */
299 /* flag for messages that contain pointers */
300 /* 32 messages per entry, messages 0..31 map to bits 0..31 */
302 #define SET(msg) (1 << ((msg) & 31))
304 static const unsigned int message_pointer_flags[] =
307 SET(WM_CREATE) | SET(WM_SETTEXT) | SET(WM_GETTEXT) |
308 SET(WM_WININICHANGE) | SET(WM_DEVMODECHANGE),
310 SET(WM_GETMINMAXINFO) | SET(WM_DRAWITEM) | SET(WM_MEASUREITEM) | SET(WM_DELETEITEM) |
313 SET(WM_WINDOWPOSCHANGING) | SET(WM_WINDOWPOSCHANGED) | SET(WM_COPYDATA) |
314 SET(WM_NOTIFY) | SET(WM_HELP),
316 SET(WM_STYLECHANGING) | SET(WM_STYLECHANGED),
318 SET(WM_NCCREATE) | SET(WM_NCCALCSIZE) | SET(WM_GETDLGCODE),
320 SET(EM_GETSEL) | SET(EM_GETRECT) | SET(EM_SETRECT) | SET(EM_SETRECTNP),
322 SET(EM_REPLACESEL) | SET(EM_GETLINE) | SET(EM_SETTABSTOPS),
324 SET(SBM_GETRANGE) | SET(SBM_SETSCROLLINFO) | SET(SBM_GETSCROLLINFO) | SET(SBM_GETSCROLLBARINFO),
330 SET(CB_GETEDITSEL) | SET(CB_ADDSTRING) | SET(CB_DIR) | SET(CB_GETLBTEXT) |
331 SET(CB_INSERTSTRING) | SET(CB_FINDSTRING) | SET(CB_SELECTSTRING) |
332 SET(CB_GETDROPPEDCONTROLRECT) | SET(CB_FINDSTRINGEXACT),
336 SET(LB_ADDSTRING) | SET(LB_INSERTSTRING) | SET(LB_GETTEXT) | SET(LB_SELECTSTRING) |
337 SET(LB_DIR) | SET(LB_FINDSTRING) |
338 SET(LB_GETSELITEMS) | SET(LB_SETTABSTOPS) | SET(LB_ADDFILE) | SET(LB_GETITEMRECT),
340 SET(LB_FINDSTRINGEXACT),
346 SET(WM_NEXTMENU) | SET(WM_SIZING) | SET(WM_MOVING) | SET(WM_DEVICECHANGE),
348 SET(WM_MDICREATE) | SET(WM_MDIGETACTIVE) | SET(WM_DROPOBJECT) |
349 SET(WM_QUERYDROPOBJECT) | SET(WM_DRAGLOOP) | SET(WM_DRAGSELECT) | SET(WM_DRAGMOVE),
363 SET(WM_ASKCBFORMATNAME)
366 /* flags for messages that contain Unicode strings */
367 static const unsigned int message_unicode_flags[] =
370 SET(WM_CREATE) | SET(WM_SETTEXT) | SET(WM_GETTEXT) | SET(WM_GETTEXTLENGTH) |
371 SET(WM_WININICHANGE) | SET(WM_DEVMODECHANGE),
383 SET(EM_REPLACESEL) | SET(EM_GETLINE) | SET(EM_SETPASSWORDCHAR),
387 SET(WM_CHAR) | SET(WM_DEADCHAR) | SET(WM_SYSCHAR) | SET(WM_SYSDEADCHAR),
391 SET(CB_ADDSTRING) | SET(CB_DIR) | SET(CB_GETLBTEXT) | SET(CB_GETLBTEXTLEN) |
392 SET(CB_INSERTSTRING) | SET(CB_FINDSTRING) | SET(CB_SELECTSTRING) | SET(CB_FINDSTRINGEXACT),
396 SET(LB_ADDSTRING) | SET(LB_INSERTSTRING) | SET(LB_GETTEXT) | SET(LB_GETTEXTLEN) |
397 SET(LB_SELECTSTRING) | SET(LB_DIR) | SET(LB_FINDSTRING) | SET(LB_ADDFILE),
399 SET(LB_FINDSTRINGEXACT),
421 SET(WM_PAINTCLIPBOARD) | SET(WM_SIZECLIPBOARD) | SET(WM_ASKCBFORMATNAME)
424 /* check whether a given message type includes pointers */
425 static inline int is_pointer_message( UINT message )
427 if (message >= 8*sizeof(message_pointer_flags)) return FALSE;
428 return (message_pointer_flags[message / 32] & SET(message)) != 0;
431 /* check whether a given message type contains Unicode (or ASCII) chars */
432 static inline int is_unicode_message( UINT message )
434 if (message >= 8*sizeof(message_unicode_flags)) return FALSE;
435 return (message_unicode_flags[message / 32] & SET(message)) != 0;
440 /* add a data field to a packed message */
441 static inline void push_data( struct packed_message *data, const void *ptr, size_t size )
443 data->data[data->count] = ptr;
444 data->size[data->count] = size;
448 /* add a string to a packed message */
449 static inline void push_string( struct packed_message *data, LPCWSTR str )
451 push_data( data, str, (strlenW(str) + 1) * sizeof(WCHAR) );
454 /* make sure that the buffer contains a valid null-terminated Unicode string */
455 static inline BOOL check_string( LPCWSTR str, size_t size )
457 for (size /= sizeof(WCHAR); size; size--, str++)
458 if (!*str) return TRUE;
462 /* pack a pointer into a 32/64 portable format */
463 static inline ULONGLONG pack_ptr( const void *ptr )
465 return (ULONG_PTR)ptr;
468 /* unpack a potentially 64-bit pointer, returning 0 when truncated */
469 static inline void *unpack_ptr( ULONGLONG ptr64 )
471 if ((ULONG_PTR)ptr64 != ptr64) return 0;
472 return (void *)(ULONG_PTR)ptr64;
475 /* make sure that there is space for 'size' bytes in buffer, growing it if needed */
476 static inline void *get_buffer_space( void **buffer, size_t size )
482 if (!(ret = HeapReAlloc( GetProcessHeap(), 0, *buffer, size )))
483 HeapFree( GetProcessHeap(), 0, *buffer );
485 else ret = HeapAlloc( GetProcessHeap(), 0, size );
491 /* check whether a combobox expects strings or ids in CB_ADDSTRING/CB_INSERTSTRING */
492 static inline BOOL combobox_has_strings( HWND hwnd )
494 DWORD style = GetWindowLongA( hwnd, GWL_STYLE );
495 return (!(style & (CBS_OWNERDRAWFIXED | CBS_OWNERDRAWVARIABLE)) || (style & CBS_HASSTRINGS));
498 /* check whether a listbox expects strings or ids in LB_ADDSTRING/LB_INSERTSTRING */
499 static inline BOOL listbox_has_strings( HWND hwnd )
501 DWORD style = GetWindowLongA( hwnd, GWL_STYLE );
502 return (!(style & (LBS_OWNERDRAWFIXED | LBS_OWNERDRAWVARIABLE)) || (style & LBS_HASSTRINGS));
505 /* check whether message is in the range of keyboard messages */
506 static inline BOOL is_keyboard_message( UINT message )
508 return (message >= WM_KEYFIRST && message <= WM_KEYLAST);
511 /* check whether message is in the range of mouse messages */
512 static inline BOOL is_mouse_message( UINT message )
514 return ((message >= WM_NCMOUSEFIRST && message <= WM_NCMOUSELAST) ||
515 (message >= WM_MOUSEFIRST && message <= WM_MOUSELAST));
518 /* check whether message matches the specified hwnd filter */
519 static inline BOOL check_hwnd_filter( const MSG *msg, HWND hwnd_filter )
521 if (!hwnd_filter || hwnd_filter == GetDesktopWindow()) return TRUE;
522 return (msg->hwnd == hwnd_filter || IsChild( hwnd_filter, msg->hwnd ));
525 /* check for pending WM_CHAR message with DBCS trailing byte */
526 static inline BOOL get_pending_wmchar( MSG *msg, UINT first, UINT last, BOOL remove )
528 struct wm_char_mapping_data *data = get_user_thread_info()->wmchar_data;
530 if (!data || !data->get_msg.message) return FALSE;
531 if ((first || last) && (first > WM_CHAR || last < WM_CHAR)) return FALSE;
532 if (!msg) return FALSE;
533 *msg = data->get_msg;
534 if (remove) data->get_msg.message = 0;
539 /***********************************************************************
542 * Window procedure for "Message" windows (HWND_MESSAGE parent).
544 LRESULT WINAPI MessageWndProc( HWND hwnd, UINT message, WPARAM wParam, LPARAM lParam )
546 if (message == WM_NCCREATE) return TRUE;
547 return 0; /* all other messages are ignored */
551 /***********************************************************************
552 * broadcast_message_callback
554 * Helper callback for broadcasting messages.
556 static BOOL CALLBACK broadcast_message_callback( HWND hwnd, LPARAM lparam )
558 struct send_message_info *info = (struct send_message_info *)lparam;
559 if (!(GetWindowLongW( hwnd, GWL_STYLE ) & (WS_POPUP|WS_CAPTION))) return TRUE;
563 SendMessageTimeoutW( hwnd, info->msg, info->wparam, info->lparam,
564 info->flags, info->timeout, NULL );
567 SendMessageTimeoutA( hwnd, info->msg, info->wparam, info->lparam,
568 info->flags, info->timeout, NULL );
571 SendNotifyMessageW( hwnd, info->msg, info->wparam, info->lparam );
574 SendMessageCallbackW( hwnd, info->msg, info->wparam, info->lparam,
575 info->callback, info->data );
578 PostMessageW( hwnd, info->msg, info->wparam, info->lparam );
581 ERR( "bad type %d\n", info->type );
588 /***********************************************************************
591 * Convert the wparam of an ASCII message to Unicode.
593 BOOL map_wparam_AtoW( UINT message, WPARAM *wparam, enum wm_char_mapping mapping )
602 /* WM_CHAR is magic: a DBCS char can be sent/posted as two consecutive WM_CHAR
603 * messages, in which case the first char is stored, and the conversion
604 * to Unicode only takes place once the second char is sent/posted.
606 if (mapping != WMCHAR_MAP_NOMAPPING)
608 struct wm_char_mapping_data *data = get_user_thread_info()->wmchar_data;
609 BYTE low = LOBYTE(*wparam);
614 ch[1] = HIBYTE(*wparam);
615 RtlMultiByteToUnicodeN( wch, sizeof(wch), NULL, ch, 2 );
616 TRACE( "map %02x,%02x -> %04x mapping %u\n", (BYTE)ch[0], (BYTE)ch[1], wch[0], mapping );
617 if (data) data->lead_byte[mapping] = 0;
619 else if (data && data->lead_byte[mapping])
621 ch[0] = data->lead_byte[mapping];
623 RtlMultiByteToUnicodeN( wch, sizeof(wch), NULL, ch, 2 );
624 TRACE( "map stored %02x,%02x -> %04x mapping %u\n", (BYTE)ch[0], (BYTE)ch[1], wch[0], mapping );
625 data->lead_byte[mapping] = 0;
627 else if (!IsDBCSLeadByte( low ))
630 RtlMultiByteToUnicodeN( wch, sizeof(wch), NULL, ch, 1 );
631 TRACE( "map %02x -> %04x\n", (BYTE)ch[0], wch[0] );
632 if (data) data->lead_byte[mapping] = 0;
634 else /* store it and wait for trail byte */
638 if (!(data = HeapAlloc( GetProcessHeap(), HEAP_ZERO_MEMORY, sizeof(*data) )))
640 get_user_thread_info()->wmchar_data = data;
642 TRACE( "storing lead byte %02x mapping %u\n", low, mapping );
643 data->lead_byte[mapping] = low;
646 *wparam = MAKEWPARAM(wch[0], wch[1]);
649 /* else fall through */
651 case EM_SETPASSWORDCHAR:
656 ch[0] = LOBYTE(*wparam);
657 ch[1] = HIBYTE(*wparam);
658 RtlMultiByteToUnicodeN( wch, sizeof(wch), NULL, ch, 2 );
659 *wparam = MAKEWPARAM(wch[0], wch[1]);
662 ch[0] = HIBYTE(*wparam);
663 ch[1] = LOBYTE(*wparam);
664 if (ch[0]) RtlMultiByteToUnicodeN( wch, sizeof(wch[0]), NULL, ch, 2 );
665 else RtlMultiByteToUnicodeN( wch, sizeof(wch[0]), NULL, ch + 1, 1 );
666 *wparam = MAKEWPARAM(wch[0], HIWORD(*wparam));
673 /***********************************************************************
676 * Convert the wparam of a Unicode message to ASCII.
678 static void map_wparam_WtoA( MSG *msg, BOOL remove )
687 if (!HIWORD(msg->wParam))
689 wch[0] = LOWORD(msg->wParam);
691 RtlUnicodeToMultiByteN( (LPSTR)ch, 2, &len, wch, sizeof(wch[0]) );
692 if (len == 2) /* DBCS char */
694 struct wm_char_mapping_data *data = get_user_thread_info()->wmchar_data;
697 if (!(data = HeapAlloc( GetProcessHeap(), HEAP_ZERO_MEMORY, sizeof(*data) ))) return;
698 get_user_thread_info()->wmchar_data = data;
702 data->get_msg = *msg;
703 data->get_msg.wParam = ch[1];
709 /* else fall through */
711 case EM_SETPASSWORDCHAR:
716 wch[0] = LOWORD(msg->wParam);
717 wch[1] = HIWORD(msg->wParam);
719 RtlUnicodeToMultiByteN( (LPSTR)ch, 2, NULL, wch, sizeof(wch) );
720 msg->wParam = MAKEWPARAM( ch[0] | (ch[1] << 8), 0 );
723 wch[0] = LOWORD(msg->wParam);
725 RtlUnicodeToMultiByteN( (LPSTR)ch, 2, &len, wch, sizeof(wch[0]) );
727 msg->wParam = MAKEWPARAM( (ch[0] << 8) | ch[1], HIWORD(msg->wParam) );
729 msg->wParam = MAKEWPARAM( ch[0], HIWORD(msg->wParam) );
735 /***********************************************************************
738 * Pack a message for sending to another process.
739 * Return the size of the data we expect in the message reply.
740 * Set data->count to -1 if there is an error.
742 static size_t pack_message( HWND hwnd, UINT message, WPARAM wparam, LPARAM lparam,
743 struct packed_message *data )
751 CREATESTRUCTW *cs = (CREATESTRUCTW *)lparam;
752 data->ps.cs.lpCreateParams = pack_ptr( cs->lpCreateParams );
753 data->ps.cs.hInstance = pack_ptr( cs->hInstance );
754 data->ps.cs.hMenu = wine_server_user_handle( cs->hMenu );
755 data->ps.cs.hwndParent = wine_server_user_handle( cs->hwndParent );
756 data->ps.cs.cy = cs->cy;
757 data->ps.cs.cx = cs->cx;
758 data->ps.cs.y = cs->y;
759 data->ps.cs.x = cs->x;
760 data->ps.cs.style = cs->style;
761 data->ps.cs.dwExStyle = cs->dwExStyle;
762 data->ps.cs.lpszName = pack_ptr( cs->lpszName );
763 data->ps.cs.lpszClass = pack_ptr( cs->lpszClass );
764 push_data( data, &data->ps.cs, sizeof(data->ps.cs) );
765 if (!IS_INTRESOURCE(cs->lpszName)) push_string( data, cs->lpszName );
766 if (!IS_INTRESOURCE(cs->lpszClass)) push_string( data, cs->lpszClass );
767 return sizeof(data->ps.cs);
770 case WM_ASKCBFORMATNAME:
771 return wparam * sizeof(WCHAR);
772 case WM_WININICHANGE:
773 if (lparam) push_string(data, (LPWSTR)lparam );
776 case WM_DEVMODECHANGE:
781 push_string( data, (LPWSTR)lparam );
783 case WM_GETMINMAXINFO:
784 push_data( data, (MINMAXINFO *)lparam, sizeof(MINMAXINFO) );
785 return sizeof(MINMAXINFO);
788 DRAWITEMSTRUCT *dis = (DRAWITEMSTRUCT *)lparam;
789 data->ps.dis.CtlType = dis->CtlType;
790 data->ps.dis.CtlID = dis->CtlID;
791 data->ps.dis.itemID = dis->itemID;
792 data->ps.dis.itemAction = dis->itemAction;
793 data->ps.dis.itemState = dis->itemState;
794 data->ps.dis.hwndItem = wine_server_user_handle( dis->hwndItem );
795 data->ps.dis.hDC = wine_server_user_handle( dis->hDC ); /* FIXME */
796 data->ps.dis.rcItem = dis->rcItem;
797 data->ps.dis.itemData = dis->itemData;
798 push_data( data, &data->ps.dis, sizeof(data->ps.dis) );
803 MEASUREITEMSTRUCT *mis = (MEASUREITEMSTRUCT *)lparam;
804 data->ps.mis.CtlType = mis->CtlType;
805 data->ps.mis.CtlID = mis->CtlID;
806 data->ps.mis.itemID = mis->itemID;
807 data->ps.mis.itemWidth = mis->itemWidth;
808 data->ps.mis.itemHeight = mis->itemHeight;
809 data->ps.mis.itemData = mis->itemData;
810 push_data( data, &data->ps.mis, sizeof(data->ps.mis) );
811 return sizeof(data->ps.mis);
815 DELETEITEMSTRUCT *dls = (DELETEITEMSTRUCT *)lparam;
816 data->ps.dls.CtlType = dls->CtlType;
817 data->ps.dls.CtlID = dls->CtlID;
818 data->ps.dls.itemID = dls->itemID;
819 data->ps.dls.hwndItem = wine_server_user_handle( dls->hwndItem );
820 data->ps.dls.itemData = dls->itemData;
821 push_data( data, &data->ps.dls, sizeof(data->ps.dls) );
826 COMPAREITEMSTRUCT *cis = (COMPAREITEMSTRUCT *)lparam;
827 data->ps.cis.CtlType = cis->CtlType;
828 data->ps.cis.CtlID = cis->CtlID;
829 data->ps.cis.hwndItem = wine_server_user_handle( cis->hwndItem );
830 data->ps.cis.itemID1 = cis->itemID1;
831 data->ps.cis.itemData1 = cis->itemData1;
832 data->ps.cis.itemID2 = cis->itemID2;
833 data->ps.cis.itemData2 = cis->itemData2;
834 data->ps.cis.dwLocaleId = cis->dwLocaleId;
835 push_data( data, &data->ps.cis, sizeof(data->ps.cis) );
838 case WM_WINE_SETWINDOWPOS:
839 case WM_WINDOWPOSCHANGING:
840 case WM_WINDOWPOSCHANGED:
842 WINDOWPOS *wp = (WINDOWPOS *)lparam;
843 data->ps.wp.hwnd = wine_server_user_handle( wp->hwnd );
844 data->ps.wp.hwndInsertAfter = wine_server_user_handle( wp->hwndInsertAfter );
845 data->ps.wp.x = wp->x;
846 data->ps.wp.y = wp->y;
847 data->ps.wp.cx = wp->cx;
848 data->ps.wp.cy = wp->cy;
849 data->ps.wp.flags = wp->flags;
850 push_data( data, &data->ps.wp, sizeof(data->ps.wp) );
851 return sizeof(data->ps.wp);
855 COPYDATASTRUCT *cds = (COPYDATASTRUCT *)lparam;
856 data->ps.cds.cbData = cds->cbData;
857 data->ps.cds.dwData = cds->dwData;
858 data->ps.cds.lpData = pack_ptr( cds->lpData );
859 push_data( data, &data->ps.cds, sizeof(data->ps.cds) );
860 if (cds->lpData) push_data( data, cds->lpData, cds->cbData );
864 /* WM_NOTIFY cannot be sent across processes (MSDN) */
869 HELPINFO *hi = (HELPINFO *)lparam;
870 data->ps.hi.iContextType = hi->iContextType;
871 data->ps.hi.iCtrlId = hi->iCtrlId;
872 data->ps.hi.hItemHandle = wine_server_user_handle( hi->hItemHandle );
873 data->ps.hi.dwContextId = hi->dwContextId;
874 data->ps.hi.MousePos = hi->MousePos;
875 push_data( data, &data->ps.hi, sizeof(data->ps.hi) );
878 case WM_STYLECHANGING:
879 case WM_STYLECHANGED:
880 push_data( data, (STYLESTRUCT *)lparam, sizeof(STYLESTRUCT) );
885 push_data( data, (RECT *)lparam, sizeof(RECT) );
890 NCCALCSIZE_PARAMS *ncp = (NCCALCSIZE_PARAMS *)lparam;
891 data->ps.ncp.rgrc[0] = ncp->rgrc[0];
892 data->ps.ncp.rgrc[1] = ncp->rgrc[1];
893 data->ps.ncp.rgrc[2] = ncp->rgrc[2];
894 data->ps.ncp.hwnd = wine_server_user_handle( ncp->lppos->hwnd );
895 data->ps.ncp.hwndInsertAfter = wine_server_user_handle( ncp->lppos->hwndInsertAfter );
896 data->ps.ncp.x = ncp->lppos->x;
897 data->ps.ncp.y = ncp->lppos->y;
898 data->ps.ncp.cx = ncp->lppos->cx;
899 data->ps.ncp.cy = ncp->lppos->cy;
900 data->ps.ncp.flags = ncp->lppos->flags;
901 push_data( data, &data->ps.ncp, sizeof(data->ps.ncp) );
902 return sizeof(data->ps.ncp);
907 MSG *msg = (MSG *)lparam;
908 data->ps.msg.hwnd = wine_server_user_handle( msg->hwnd );
909 data->ps.msg.message = msg->message;
910 data->ps.msg.wParam = msg->wParam;
911 data->ps.msg.lParam = msg->lParam;
912 data->ps.msg.time = msg->time;
913 data->ps.msg.pt = msg->pt;
914 push_data( data, &data->ps.msg, sizeof(data->ps.msg) );
915 return sizeof(data->ps.msg);
918 case SBM_SETSCROLLINFO:
919 push_data( data, (SCROLLINFO *)lparam, sizeof(SCROLLINFO) );
921 case SBM_GETSCROLLINFO:
922 push_data( data, (SCROLLINFO *)lparam, sizeof(SCROLLINFO) );
923 return sizeof(SCROLLINFO);
924 case SBM_GETSCROLLBARINFO:
926 const SCROLLBARINFO *info = (const SCROLLBARINFO *)lparam;
927 size_t size = min( info->cbSize, sizeof(SCROLLBARINFO) );
928 push_data( data, info, size );
936 if (wparam) size += sizeof(DWORD);
937 if (lparam) size += sizeof(DWORD);
942 case CB_GETDROPPEDCONTROLRECT:
946 push_data( data, (RECT *)lparam, sizeof(RECT) );
950 WORD *pw = (WORD *)lparam;
951 push_data( data, pw, sizeof(*pw) );
952 return *pw * sizeof(WCHAR);
956 if (wparam) push_data( data, (UINT *)lparam, sizeof(UINT) * wparam );
959 case CB_INSERTSTRING:
961 case CB_FINDSTRINGEXACT:
962 case CB_SELECTSTRING:
963 if (combobox_has_strings( hwnd )) push_string( data, (LPWSTR)lparam );
966 if (!combobox_has_strings( hwnd )) return sizeof(ULONG_PTR);
967 return (SendMessageW( hwnd, CB_GETLBTEXTLEN, wparam, 0 ) + 1) * sizeof(WCHAR);
969 case LB_INSERTSTRING:
971 case LB_FINDSTRINGEXACT:
972 case LB_SELECTSTRING:
973 if (listbox_has_strings( hwnd )) push_string( data, (LPWSTR)lparam );
976 if (!listbox_has_strings( hwnd )) return sizeof(ULONG_PTR);
977 return (SendMessageW( hwnd, LB_GETTEXTLEN, wparam, 0 ) + 1) * sizeof(WCHAR);
979 return wparam * sizeof(UINT);
982 MDINEXTMENU *mnm = (MDINEXTMENU *)lparam;
983 data->ps.mnm.hmenuIn = wine_server_user_handle( mnm->hmenuIn );
984 data->ps.mnm.hmenuNext = wine_server_user_handle( mnm->hmenuNext );
985 data->ps.mnm.hwndNext = wine_server_user_handle( mnm->hwndNext );
986 push_data( data, &data->ps.mnm, sizeof(data->ps.mnm) );
987 return sizeof(data->ps.mnm);
991 push_data( data, (RECT *)lparam, sizeof(RECT) );
995 MDICREATESTRUCTW *mcs = (MDICREATESTRUCTW *)lparam;
996 data->ps.mcs.szClass = pack_ptr( mcs->szClass );
997 data->ps.mcs.szTitle = pack_ptr( mcs->szTitle );
998 data->ps.mcs.hOwner = pack_ptr( mcs->hOwner );
999 data->ps.mcs.x = mcs->x;
1000 data->ps.mcs.y = mcs->y;
1001 data->ps.mcs.cx = mcs->cx;
1002 data->ps.mcs.cy = mcs->cy;
1003 data->ps.mcs.style = mcs->style;
1004 data->ps.mcs.lParam = mcs->lParam;
1005 push_data( data, &data->ps.mcs, sizeof(data->ps.mcs) );
1006 if (!IS_INTRESOURCE(mcs->szClass)) push_string( data, mcs->szClass );
1007 if (!IS_INTRESOURCE(mcs->szTitle)) push_string( data, mcs->szTitle );
1008 return sizeof(data->ps.mcs);
1010 case WM_MDIGETACTIVE:
1011 if (lparam) return sizeof(BOOL);
1013 case WM_DEVICECHANGE:
1015 DEV_BROADCAST_HDR *header = (DEV_BROADCAST_HDR *)lparam;
1016 push_data( data, header, header->dbch_size );
1019 case WM_WINE_KEYBOARD_LL_HOOK:
1021 struct hook_extra_info *h_extra = (struct hook_extra_info *)lparam;
1022 data->ps.hook.handle = wine_server_user_handle( h_extra->handle );
1023 push_data( data, &data->ps.hook, sizeof(data->ps.hook) );
1024 push_data( data, (LPVOID)h_extra->lparam, sizeof(KBDLLHOOKSTRUCT) );
1027 case WM_WINE_MOUSE_LL_HOOK:
1029 struct hook_extra_info *h_extra = (struct hook_extra_info *)lparam;
1030 data->ps.hook.handle = wine_server_user_handle( h_extra->handle );
1031 push_data( data, &data->ps.hook, sizeof(data->ps.hook) );
1032 push_data( data, (LPVOID)h_extra->lparam, sizeof(MSLLHOOKSTRUCT) );
1036 if (wparam <= 1) return 0;
1037 FIXME( "WM_NCPAINT hdc packing not supported yet\n" );
1041 if (!wparam) return 0;
1044 /* these contain an HFONT */
1047 /* these contain an HDC */
1049 case WM_ICONERASEBKGND:
1050 case WM_CTLCOLORMSGBOX:
1051 case WM_CTLCOLOREDIT:
1052 case WM_CTLCOLORLISTBOX:
1053 case WM_CTLCOLORBTN:
1054 case WM_CTLCOLORDLG:
1055 case WM_CTLCOLORSCROLLBAR:
1056 case WM_CTLCOLORSTATIC:
1058 case WM_PRINTCLIENT:
1059 /* these contain an HGLOBAL */
1060 case WM_PAINTCLIPBOARD:
1061 case WM_SIZECLIPBOARD:
1062 /* these contain HICON */
1065 case WM_QUERYDRAGICON:
1066 case WM_QUERYPARKICON:
1067 /* these contain pointers */
1069 case WM_QUERYDROPOBJECT:
1073 FIXME( "msg %x (%s) not supported yet\n", message, SPY_GetMsgName(message, hwnd) );
1081 /***********************************************************************
1084 * Unpack a message received from another process.
1086 static BOOL unpack_message( HWND hwnd, UINT message, WPARAM *wparam, LPARAM *lparam,
1087 void **buffer, size_t size )
1090 union packed_structs *ps = *buffer;
1098 WCHAR *str = (WCHAR *)(&ps->cs + 1);
1099 if (size < sizeof(ps->cs)) return FALSE;
1100 size -= sizeof(ps->cs);
1101 cs.lpCreateParams = unpack_ptr( ps->cs.lpCreateParams );
1102 cs.hInstance = unpack_ptr( ps->cs.hInstance );
1103 cs.hMenu = wine_server_ptr_handle( ps->cs.hMenu );
1104 cs.hwndParent = wine_server_ptr_handle( ps->cs.hwndParent );
1109 cs.style = ps->cs.style;
1110 cs.dwExStyle = ps->cs.dwExStyle;
1111 cs.lpszName = unpack_ptr( ps->cs.lpszName );
1112 cs.lpszClass = unpack_ptr( ps->cs.lpszClass );
1113 if (ps->cs.lpszName >> 16)
1115 if (!check_string( str, size )) return FALSE;
1117 size -= (strlenW(str) + 1) * sizeof(WCHAR);
1118 str += strlenW(str) + 1;
1120 if (ps->cs.lpszClass >> 16)
1122 if (!check_string( str, size )) return FALSE;
1125 memcpy( &ps->cs, &cs, sizeof(cs) );
1129 case WM_ASKCBFORMATNAME:
1130 if (!get_buffer_space( buffer, (*wparam * sizeof(WCHAR)) )) return FALSE;
1132 case WM_WININICHANGE:
1133 if (!*lparam) return TRUE;
1136 case WM_DEVMODECHANGE:
1141 if (!check_string( *buffer, size )) return FALSE;
1143 case WM_GETMINMAXINFO:
1144 minsize = sizeof(MINMAXINFO);
1149 if (size < sizeof(ps->dis)) return FALSE;
1150 dis.CtlType = ps->dis.CtlType;
1151 dis.CtlID = ps->dis.CtlID;
1152 dis.itemID = ps->dis.itemID;
1153 dis.itemAction = ps->dis.itemAction;
1154 dis.itemState = ps->dis.itemState;
1155 dis.hwndItem = wine_server_ptr_handle( ps->dis.hwndItem );
1156 dis.hDC = wine_server_ptr_handle( ps->dis.hDC );
1157 dis.rcItem = ps->dis.rcItem;
1158 dis.itemData = (ULONG_PTR)unpack_ptr( ps->dis.itemData );
1159 memcpy( &ps->dis, &dis, sizeof(dis) );
1162 case WM_MEASUREITEM:
1164 MEASUREITEMSTRUCT mis;
1165 if (size < sizeof(ps->mis)) return FALSE;
1166 mis.CtlType = ps->mis.CtlType;
1167 mis.CtlID = ps->mis.CtlID;
1168 mis.itemID = ps->mis.itemID;
1169 mis.itemWidth = ps->mis.itemWidth;
1170 mis.itemHeight = ps->mis.itemHeight;
1171 mis.itemData = (ULONG_PTR)unpack_ptr( ps->mis.itemData );
1172 memcpy( &ps->mis, &mis, sizeof(mis) );
1177 DELETEITEMSTRUCT dls;
1178 if (size < sizeof(ps->dls)) return FALSE;
1179 dls.CtlType = ps->dls.CtlType;
1180 dls.CtlID = ps->dls.CtlID;
1181 dls.itemID = ps->dls.itemID;
1182 dls.hwndItem = wine_server_ptr_handle( ps->dls.hwndItem );
1183 dls.itemData = (ULONG_PTR)unpack_ptr( ps->dls.itemData );
1184 memcpy( &ps->dls, &dls, sizeof(dls) );
1187 case WM_COMPAREITEM:
1189 COMPAREITEMSTRUCT cis;
1190 if (size < sizeof(ps->cis)) return FALSE;
1191 cis.CtlType = ps->cis.CtlType;
1192 cis.CtlID = ps->cis.CtlID;
1193 cis.hwndItem = wine_server_ptr_handle( ps->cis.hwndItem );
1194 cis.itemID1 = ps->cis.itemID1;
1195 cis.itemData1 = (ULONG_PTR)unpack_ptr( ps->cis.itemData1 );
1196 cis.itemID2 = ps->cis.itemID2;
1197 cis.itemData2 = (ULONG_PTR)unpack_ptr( ps->cis.itemData2 );
1198 cis.dwLocaleId = ps->cis.dwLocaleId;
1199 memcpy( &ps->cis, &cis, sizeof(cis) );
1202 case WM_WINDOWPOSCHANGING:
1203 case WM_WINDOWPOSCHANGED:
1204 case WM_WINE_SETWINDOWPOS:
1207 if (size < sizeof(ps->wp)) return FALSE;
1208 wp.hwnd = wine_server_ptr_handle( ps->wp.hwnd );
1209 wp.hwndInsertAfter = wine_server_ptr_handle( ps->wp.hwndInsertAfter );
1214 wp.flags = ps->wp.flags;
1215 memcpy( &ps->wp, &wp, sizeof(wp) );
1221 if (size < sizeof(ps->cds)) return FALSE;
1222 cds.dwData = (ULONG_PTR)unpack_ptr( ps->cds.dwData );
1225 cds.cbData = ps->cds.cbData;
1226 cds.lpData = &ps->cds + 1;
1227 minsize = sizeof(ps->cds) + cds.cbData;
1234 memcpy( &ps->cds, &cds, sizeof(cds) );
1238 /* WM_NOTIFY cannot be sent across processes (MSDN) */
1243 if (size < sizeof(ps->hi)) return FALSE;
1244 hi.cbSize = sizeof(hi);
1245 hi.iContextType = ps->hi.iContextType;
1246 hi.iCtrlId = ps->hi.iCtrlId;
1247 hi.hItemHandle = wine_server_ptr_handle( ps->hi.hItemHandle );
1248 hi.dwContextId = (ULONG_PTR)unpack_ptr( ps->hi.dwContextId );
1249 hi.MousePos = ps->hi.MousePos;
1250 memcpy( &ps->hi, &hi, sizeof(hi) );
1253 case WM_STYLECHANGING:
1254 case WM_STYLECHANGED:
1255 minsize = sizeof(STYLESTRUCT);
1258 if (!*wparam) minsize = sizeof(RECT);
1261 NCCALCSIZE_PARAMS ncp;
1263 if (size < sizeof(ps->ncp)) return FALSE;
1264 ncp.rgrc[0] = ps->ncp.rgrc[0];
1265 ncp.rgrc[1] = ps->ncp.rgrc[1];
1266 ncp.rgrc[2] = ps->ncp.rgrc[2];
1267 wp.hwnd = wine_server_ptr_handle( ps->ncp.hwnd );
1268 wp.hwndInsertAfter = wine_server_ptr_handle( ps->ncp.hwndInsertAfter );
1273 wp.flags = ps->ncp.flags;
1274 ncp.lppos = (WINDOWPOS *)((NCCALCSIZE_PARAMS *)&ps->ncp + 1);
1275 memcpy( &ps->ncp, &ncp, sizeof(ncp) );
1283 if (size < sizeof(ps->msg)) return FALSE;
1284 msg.hwnd = wine_server_ptr_handle( ps->msg.hwnd );
1285 msg.message = ps->msg.message;
1286 msg.wParam = (ULONG_PTR)unpack_ptr( ps->msg.wParam );
1287 msg.lParam = (ULONG_PTR)unpack_ptr( ps->msg.lParam );
1288 msg.time = ps->msg.time;
1289 msg.pt = ps->msg.pt;
1290 memcpy( &ps->msg, &msg, sizeof(msg) );
1294 case SBM_SETSCROLLINFO:
1295 minsize = sizeof(SCROLLINFO);
1297 case SBM_GETSCROLLINFO:
1298 if (!get_buffer_space( buffer, sizeof(SCROLLINFO ))) return FALSE;
1300 case SBM_GETSCROLLBARINFO:
1301 if (!get_buffer_space( buffer, sizeof(SCROLLBARINFO ))) return FALSE;
1306 if (*wparam || *lparam)
1308 if (!get_buffer_space( buffer, 2*sizeof(DWORD) )) return FALSE;
1309 if (*wparam) *wparam = (WPARAM)*buffer;
1310 if (*lparam) *lparam = (LPARAM)((DWORD *)*buffer + 1);
1314 case LB_GETITEMRECT:
1315 case CB_GETDROPPEDCONTROLRECT:
1316 if (!get_buffer_space( buffer, sizeof(RECT) )) return FALSE;
1320 minsize = sizeof(RECT);
1325 if (size < sizeof(WORD)) return FALSE;
1326 len = *(WORD *)*buffer;
1327 if (!get_buffer_space( buffer, (len + 1) * sizeof(WCHAR) )) return FALSE;
1328 *lparam = (LPARAM)*buffer + sizeof(WORD); /* don't erase WORD at start of buffer */
1331 case EM_SETTABSTOPS:
1332 case LB_SETTABSTOPS:
1333 if (!*wparam) return TRUE;
1334 minsize = *wparam * sizeof(UINT);
1337 case CB_INSERTSTRING:
1339 case CB_FINDSTRINGEXACT:
1340 case CB_SELECTSTRING:
1342 case LB_INSERTSTRING:
1344 case LB_FINDSTRINGEXACT:
1345 case LB_SELECTSTRING:
1346 if (!*buffer) return TRUE;
1347 if (!check_string( *buffer, size )) return FALSE;
1351 size = sizeof(ULONG_PTR);
1352 if (combobox_has_strings( hwnd ))
1353 size = (SendMessageW( hwnd, CB_GETLBTEXTLEN, *wparam, 0 ) + 1) * sizeof(WCHAR);
1354 if (!get_buffer_space( buffer, size )) return FALSE;
1359 size = sizeof(ULONG_PTR);
1360 if (listbox_has_strings( hwnd ))
1361 size = (SendMessageW( hwnd, LB_GETTEXTLEN, *wparam, 0 ) + 1) * sizeof(WCHAR);
1362 if (!get_buffer_space( buffer, size )) return FALSE;
1365 case LB_GETSELITEMS:
1366 if (!get_buffer_space( buffer, *wparam * sizeof(UINT) )) return FALSE;
1371 if (size < sizeof(ps->mnm)) return FALSE;
1372 mnm.hmenuIn = wine_server_ptr_handle( ps->mnm.hmenuIn );
1373 mnm.hmenuNext = wine_server_ptr_handle( ps->mnm.hmenuNext );
1374 mnm.hwndNext = wine_server_ptr_handle( ps->mnm.hwndNext );
1375 memcpy( &ps->mnm, &mnm, sizeof(mnm) );
1380 minsize = sizeof(RECT);
1381 if (!get_buffer_space( buffer, sizeof(RECT) )) return FALSE;
1385 MDICREATESTRUCTW mcs;
1386 WCHAR *str = (WCHAR *)(&ps->mcs + 1);
1387 if (size < sizeof(ps->mcs)) return FALSE;
1388 size -= sizeof(ps->mcs);
1390 mcs.szClass = unpack_ptr( ps->mcs.szClass );
1391 mcs.szTitle = unpack_ptr( ps->mcs.szTitle );
1392 mcs.hOwner = unpack_ptr( ps->mcs.hOwner );
1395 mcs.cx = ps->mcs.cx;
1396 mcs.cy = ps->mcs.cy;
1397 mcs.style = ps->mcs.style;
1398 mcs.lParam = (LPARAM)unpack_ptr( ps->mcs.lParam );
1399 if (ps->mcs.szClass >> 16)
1401 if (!check_string( str, size )) return FALSE;
1403 size -= (strlenW(str) + 1) * sizeof(WCHAR);
1404 str += strlenW(str) + 1;
1406 if (ps->mcs.szTitle >> 16)
1408 if (!check_string( str, size )) return FALSE;
1411 memcpy( &ps->mcs, &mcs, sizeof(mcs) );
1414 case WM_MDIGETACTIVE:
1415 if (!*lparam) return TRUE;
1416 if (!get_buffer_space( buffer, sizeof(BOOL) )) return FALSE;
1418 case WM_DEVICECHANGE:
1419 minsize = sizeof(DEV_BROADCAST_HDR);
1421 case WM_WINE_KEYBOARD_LL_HOOK:
1422 case WM_WINE_MOUSE_LL_HOOK:
1424 struct hook_extra_info h_extra;
1425 minsize = sizeof(ps->hook) +
1426 (message == WM_WINE_KEYBOARD_LL_HOOK ? sizeof(KBDLLHOOKSTRUCT)
1427 : sizeof(MSLLHOOKSTRUCT));
1428 if (size < minsize) return FALSE;
1429 h_extra.handle = wine_server_ptr_handle( ps->hook.handle );
1430 h_extra.lparam = (LPARAM)(&ps->hook + 1);
1431 memcpy( &ps->hook, &h_extra, sizeof(h_extra) );
1435 if (*wparam <= 1) return TRUE;
1436 FIXME( "WM_NCPAINT hdc unpacking not supported\n" );
1439 if (!*wparam) return TRUE;
1442 /* these contain an HFONT */
1445 /* these contain an HDC */
1447 case WM_ICONERASEBKGND:
1448 case WM_CTLCOLORMSGBOX:
1449 case WM_CTLCOLOREDIT:
1450 case WM_CTLCOLORLISTBOX:
1451 case WM_CTLCOLORBTN:
1452 case WM_CTLCOLORDLG:
1453 case WM_CTLCOLORSCROLLBAR:
1454 case WM_CTLCOLORSTATIC:
1456 case WM_PRINTCLIENT:
1457 /* these contain an HGLOBAL */
1458 case WM_PAINTCLIPBOARD:
1459 case WM_SIZECLIPBOARD:
1460 /* these contain HICON */
1463 case WM_QUERYDRAGICON:
1464 case WM_QUERYPARKICON:
1465 /* these contain pointers */
1467 case WM_QUERYDROPOBJECT:
1471 FIXME( "msg %x (%s) not supported yet\n", message, SPY_GetMsgName(message, hwnd) );
1475 return TRUE; /* message doesn't need any unpacking */
1478 /* default exit for most messages: check minsize and store buffer in lparam */
1479 if (size < minsize) return FALSE;
1480 *lparam = (LPARAM)*buffer;
1485 /***********************************************************************
1488 * Pack a reply to a message for sending to another process.
1490 static void pack_reply( HWND hwnd, UINT message, WPARAM wparam, LPARAM lparam,
1491 LRESULT res, struct packed_message *data )
1499 CREATESTRUCTW *cs = (CREATESTRUCTW *)lparam;
1500 data->ps.cs.lpCreateParams = (ULONG_PTR)cs->lpCreateParams;
1501 data->ps.cs.hInstance = (ULONG_PTR)cs->hInstance;
1502 data->ps.cs.hMenu = wine_server_user_handle( cs->hMenu );
1503 data->ps.cs.hwndParent = wine_server_user_handle( cs->hwndParent );
1504 data->ps.cs.cy = cs->cy;
1505 data->ps.cs.cx = cs->cx;
1506 data->ps.cs.y = cs->y;
1507 data->ps.cs.x = cs->x;
1508 data->ps.cs.style = cs->style;
1509 data->ps.cs.dwExStyle = cs->dwExStyle;
1510 data->ps.cs.lpszName = (ULONG_PTR)cs->lpszName;
1511 data->ps.cs.lpszClass = (ULONG_PTR)cs->lpszClass;
1512 push_data( data, &data->ps.cs, sizeof(data->ps.cs) );
1518 push_data( data, (WCHAR *)lparam, (res + 1) * sizeof(WCHAR) );
1520 case WM_GETMINMAXINFO:
1521 push_data( data, (MINMAXINFO *)lparam, sizeof(MINMAXINFO) );
1523 case WM_MEASUREITEM:
1525 MEASUREITEMSTRUCT *mis = (MEASUREITEMSTRUCT *)lparam;
1526 data->ps.mis.CtlType = mis->CtlType;
1527 data->ps.mis.CtlID = mis->CtlID;
1528 data->ps.mis.itemID = mis->itemID;
1529 data->ps.mis.itemWidth = mis->itemWidth;
1530 data->ps.mis.itemHeight = mis->itemHeight;
1531 data->ps.mis.itemData = mis->itemData;
1532 push_data( data, &data->ps.mis, sizeof(data->ps.mis) );
1535 case WM_WINDOWPOSCHANGING:
1536 case WM_WINDOWPOSCHANGED:
1538 WINDOWPOS *wp = (WINDOWPOS *)lparam;
1539 data->ps.wp.hwnd = wine_server_user_handle( wp->hwnd );
1540 data->ps.wp.hwndInsertAfter = wine_server_user_handle( wp->hwndInsertAfter );
1541 data->ps.wp.x = wp->x;
1542 data->ps.wp.y = wp->y;
1543 data->ps.wp.cx = wp->cx;
1544 data->ps.wp.cy = wp->cy;
1545 data->ps.wp.flags = wp->flags;
1546 push_data( data, &data->ps.wp, sizeof(data->ps.wp) );
1552 MSG *msg = (MSG *)lparam;
1553 data->ps.msg.hwnd = wine_server_user_handle( msg->hwnd );
1554 data->ps.msg.message = msg->message;
1555 data->ps.msg.wParam = msg->wParam;
1556 data->ps.msg.lParam = msg->lParam;
1557 data->ps.msg.time = msg->time;
1558 data->ps.msg.pt = msg->pt;
1559 push_data( data, &data->ps.msg, sizeof(data->ps.msg) );
1562 case SBM_GETSCROLLINFO:
1563 push_data( data, (SCROLLINFO *)lparam, sizeof(SCROLLINFO) );
1566 case LB_GETITEMRECT:
1567 case CB_GETDROPPEDCONTROLRECT:
1570 push_data( data, (RECT *)lparam, sizeof(RECT) );
1574 WORD *ptr = (WORD *)lparam;
1575 push_data( data, ptr, ptr[-1] * sizeof(WCHAR) );
1578 case LB_GETSELITEMS:
1579 push_data( data, (UINT *)lparam, wparam * sizeof(UINT) );
1581 case WM_MDIGETACTIVE:
1582 if (lparam) push_data( data, (BOOL *)lparam, sizeof(BOOL) );
1586 push_data( data, (RECT *)lparam, sizeof(RECT) );
1589 NCCALCSIZE_PARAMS *ncp = (NCCALCSIZE_PARAMS *)lparam;
1590 data->ps.ncp.rgrc[0] = ncp->rgrc[0];
1591 data->ps.ncp.rgrc[1] = ncp->rgrc[1];
1592 data->ps.ncp.rgrc[2] = ncp->rgrc[2];
1593 data->ps.ncp.hwnd = wine_server_user_handle( ncp->lppos->hwnd );
1594 data->ps.ncp.hwndInsertAfter = wine_server_user_handle( ncp->lppos->hwndInsertAfter );
1595 data->ps.ncp.x = ncp->lppos->x;
1596 data->ps.ncp.y = ncp->lppos->y;
1597 data->ps.ncp.cx = ncp->lppos->cx;
1598 data->ps.ncp.cy = ncp->lppos->cy;
1599 data->ps.ncp.flags = ncp->lppos->flags;
1600 push_data( data, &data->ps.ncp, sizeof(data->ps.ncp) );
1606 if (wparam) push_data( data, (DWORD *)wparam, sizeof(DWORD) );
1607 if (lparam) push_data( data, (DWORD *)lparam, sizeof(DWORD) );
1611 MDINEXTMENU *mnm = (MDINEXTMENU *)lparam;
1612 data->ps.mnm.hmenuIn = wine_server_user_handle( mnm->hmenuIn );
1613 data->ps.mnm.hmenuNext = wine_server_user_handle( mnm->hmenuNext );
1614 data->ps.mnm.hwndNext = wine_server_user_handle( mnm->hwndNext );
1615 push_data( data, &data->ps.mnm, sizeof(data->ps.mnm) );
1620 MDICREATESTRUCTW *mcs = (MDICREATESTRUCTW *)lparam;
1621 data->ps.mcs.szClass = pack_ptr( mcs->szClass );
1622 data->ps.mcs.szTitle = pack_ptr( mcs->szTitle );
1623 data->ps.mcs.hOwner = pack_ptr( mcs->hOwner );
1624 data->ps.mcs.x = mcs->x;
1625 data->ps.mcs.y = mcs->y;
1626 data->ps.mcs.cx = mcs->cx;
1627 data->ps.mcs.cy = mcs->cy;
1628 data->ps.mcs.style = mcs->style;
1629 data->ps.mcs.lParam = mcs->lParam;
1630 push_data( data, &data->ps.mcs, sizeof(data->ps.mcs) );
1633 case WM_ASKCBFORMATNAME:
1634 push_data( data, (WCHAR *)lparam, (strlenW((WCHAR *)lparam) + 1) * sizeof(WCHAR) );
1640 /***********************************************************************
1643 * Unpack a message reply received from another process.
1645 static void unpack_reply( HWND hwnd, UINT message, WPARAM wparam, LPARAM lparam,
1646 void *buffer, size_t size )
1648 union packed_structs *ps = buffer;
1654 if (size >= sizeof(ps->cs))
1656 CREATESTRUCTW *cs = (CREATESTRUCTW *)lparam;
1657 cs->lpCreateParams = unpack_ptr( ps->cs.lpCreateParams );
1658 cs->hInstance = unpack_ptr( ps->cs.hInstance );
1659 cs->hMenu = wine_server_ptr_handle( ps->cs.hMenu );
1660 cs->hwndParent = wine_server_ptr_handle( ps->cs.hwndParent );
1665 cs->style = ps->cs.style;
1666 cs->dwExStyle = ps->cs.dwExStyle;
1667 /* don't allow changing name and class pointers */
1671 case WM_ASKCBFORMATNAME:
1672 memcpy( (WCHAR *)lparam, buffer, min( wparam*sizeof(WCHAR), size ));
1674 case WM_GETMINMAXINFO:
1675 memcpy( (MINMAXINFO *)lparam, buffer, min( sizeof(MINMAXINFO), size ));
1677 case WM_MEASUREITEM:
1678 if (size >= sizeof(ps->mis))
1680 MEASUREITEMSTRUCT *mis = (MEASUREITEMSTRUCT *)lparam;
1681 mis->CtlType = ps->mis.CtlType;
1682 mis->CtlID = ps->mis.CtlID;
1683 mis->itemID = ps->mis.itemID;
1684 mis->itemWidth = ps->mis.itemWidth;
1685 mis->itemHeight = ps->mis.itemHeight;
1686 mis->itemData = (ULONG_PTR)unpack_ptr( ps->mis.itemData );
1689 case WM_WINDOWPOSCHANGING:
1690 case WM_WINDOWPOSCHANGED:
1691 if (size >= sizeof(ps->wp))
1693 WINDOWPOS *wp = (WINDOWPOS *)lparam;
1694 wp->hwnd = wine_server_ptr_handle( ps->wp.hwnd );
1695 wp->hwndInsertAfter = wine_server_ptr_handle( ps->wp.hwndInsertAfter );
1700 wp->flags = ps->wp.flags;
1704 if (lparam && size >= sizeof(ps->msg))
1706 MSG *msg = (MSG *)lparam;
1707 msg->hwnd = wine_server_ptr_handle( ps->msg.hwnd );
1708 msg->message = ps->msg.message;
1709 msg->wParam = (ULONG_PTR)unpack_ptr( ps->msg.wParam );
1710 msg->lParam = (ULONG_PTR)unpack_ptr( ps->msg.lParam );
1711 msg->time = ps->msg.time;
1712 msg->pt = ps->msg.pt;
1715 case SBM_GETSCROLLINFO:
1716 memcpy( (SCROLLINFO *)lparam, buffer, min( sizeof(SCROLLINFO), size ));
1718 case SBM_GETSCROLLBARINFO:
1719 memcpy( (SCROLLBARINFO *)lparam, buffer, min( sizeof(SCROLLBARINFO), size ));
1722 case CB_GETDROPPEDCONTROLRECT:
1723 case LB_GETITEMRECT:
1726 memcpy( (RECT *)lparam, buffer, min( sizeof(RECT), size ));
1729 size = min( size, (size_t)*(WORD *)lparam );
1730 memcpy( (WCHAR *)lparam, buffer, size );
1732 case LB_GETSELITEMS:
1733 memcpy( (UINT *)lparam, buffer, min( wparam*sizeof(UINT), size ));
1737 memcpy( (WCHAR *)lparam, buffer, size );
1740 if (size >= sizeof(ps->mnm))
1742 MDINEXTMENU *mnm = (MDINEXTMENU *)lparam;
1743 mnm->hmenuIn = wine_server_ptr_handle( ps->mnm.hmenuIn );
1744 mnm->hmenuNext = wine_server_ptr_handle( ps->mnm.hmenuNext );
1745 mnm->hwndNext = wine_server_ptr_handle( ps->mnm.hwndNext );
1748 case WM_MDIGETACTIVE:
1749 if (lparam) memcpy( (BOOL *)lparam, buffer, min( sizeof(BOOL), size ));
1753 memcpy( (RECT *)lparam, buffer, min( sizeof(RECT), size ));
1754 else if (size >= sizeof(ps->ncp))
1756 NCCALCSIZE_PARAMS *ncp = (NCCALCSIZE_PARAMS *)lparam;
1757 ncp->rgrc[0] = ps->ncp.rgrc[0];
1758 ncp->rgrc[1] = ps->ncp.rgrc[1];
1759 ncp->rgrc[2] = ps->ncp.rgrc[2];
1760 ncp->lppos->hwnd = wine_server_ptr_handle( ps->ncp.hwnd );
1761 ncp->lppos->hwndInsertAfter = wine_server_ptr_handle( ps->ncp.hwndInsertAfter );
1762 ncp->lppos->x = ps->ncp.x;
1763 ncp->lppos->y = ps->ncp.y;
1764 ncp->lppos->cx = ps->ncp.cx;
1765 ncp->lppos->cy = ps->ncp.cy;
1766 ncp->lppos->flags = ps->ncp.flags;
1774 memcpy( (DWORD *)wparam, buffer, min( sizeof(DWORD), size ));
1775 if (size <= sizeof(DWORD)) break;
1776 size -= sizeof(DWORD);
1777 buffer = (DWORD *)buffer + 1;
1779 if (lparam) memcpy( (DWORD *)lparam, buffer, min( sizeof(DWORD), size ));
1782 if (size >= sizeof(ps->mcs))
1784 MDICREATESTRUCTW *mcs = (MDICREATESTRUCTW *)lparam;
1785 mcs->hOwner = unpack_ptr( ps->mcs.hOwner );
1788 mcs->cx = ps->mcs.cx;
1789 mcs->cy = ps->mcs.cy;
1790 mcs->style = ps->mcs.style;
1791 mcs->lParam = (LPARAM)unpack_ptr( ps->mcs.lParam );
1792 /* don't allow changing class and title pointers */
1796 ERR( "should not happen: unexpected message %x\n", message );
1802 /***********************************************************************
1805 * Send a reply to a sent message.
1807 static void reply_message( struct received_message_info *info, LRESULT result, BOOL remove )
1809 struct packed_message data;
1810 int i, replied = info->flags & ISMEX_REPLIED;
1812 if (info->flags & ISMEX_NOTIFY) return; /* notify messages don't get replies */
1813 if (!remove && replied) return; /* replied already */
1815 memset( &data, 0, sizeof(data) );
1816 info->flags |= ISMEX_REPLIED;
1818 if (info->type == MSG_OTHER_PROCESS && !replied)
1820 pack_reply( info->msg.hwnd, info->msg.message, info->msg.wParam,
1821 info->msg.lParam, result, &data );
1824 SERVER_START_REQ( reply_message )
1826 req->result = result;
1827 req->remove = remove;
1828 for (i = 0; i < data.count; i++) wine_server_add_data( req, data.data[i], data.size[i] );
1829 wine_server_call( req );
1835 /***********************************************************************
1836 * handle_internal_message
1838 * Handle an internal Wine message instead of calling the window proc.
1840 static LRESULT handle_internal_message( HWND hwnd, UINT msg, WPARAM wparam, LPARAM lparam )
1844 case WM_WINE_DESTROYWINDOW:
1845 return WIN_DestroyWindow( hwnd );
1846 case WM_WINE_SETWINDOWPOS:
1847 if (is_desktop_window( hwnd )) return 0;
1848 return USER_SetWindowPos( (WINDOWPOS *)lparam );
1849 case WM_WINE_SHOWWINDOW:
1850 if (is_desktop_window( hwnd )) return 0;
1851 return ShowWindow( hwnd, wparam );
1852 case WM_WINE_SETPARENT:
1853 if (is_desktop_window( hwnd )) return 0;
1854 return (LRESULT)SetParent( hwnd, (HWND)wparam );
1855 case WM_WINE_SETWINDOWLONG:
1856 return WIN_SetWindowLong( hwnd, (short)LOWORD(wparam), HIWORD(wparam), lparam, TRUE );
1857 case WM_WINE_ENABLEWINDOW:
1858 if (is_desktop_window( hwnd )) return 0;
1859 return EnableWindow( hwnd, wparam );
1860 case WM_WINE_SETACTIVEWINDOW:
1861 if (is_desktop_window( hwnd )) return 0;
1862 return (LRESULT)SetActiveWindow( (HWND)wparam );
1863 case WM_WINE_KEYBOARD_LL_HOOK:
1864 case WM_WINE_MOUSE_LL_HOOK:
1866 struct hook_extra_info *h_extra = (struct hook_extra_info *)lparam;
1868 return call_current_hook( h_extra->handle, HC_ACTION, wparam, h_extra->lparam );
1871 if (msg >= WM_WINE_FIRST_DRIVER_MSG && msg <= WM_WINE_LAST_DRIVER_MSG)
1872 return USER_Driver->pWindowMessage( hwnd, msg, wparam, lparam );
1873 FIXME( "unknown internal message %x\n", msg );
1878 /* since the WM_DDE_ACK response to a WM_DDE_EXECUTE message should contain the handle
1879 * to the memory handle, we keep track (in the server side) of all pairs of handle
1880 * used (the client passes its value and the content of the memory handle), and
1881 * the server stored both values (the client, and the local one, created after the
1882 * content). When a ACK message is generated, the list of pair is searched for a
1883 * matching pair, so that the client memory handle can be returned.
1886 HGLOBAL client_hMem;
1887 HGLOBAL server_hMem;
1890 static struct DDE_pair* dde_pairs;
1891 static int dde_num_alloc;
1892 static int dde_num_used;
1894 static CRITICAL_SECTION dde_crst;
1895 static CRITICAL_SECTION_DEBUG critsect_debug =
1898 { &critsect_debug.ProcessLocksList, &critsect_debug.ProcessLocksList },
1899 0, 0, { (DWORD_PTR)(__FILE__ ": dde_crst") }
1901 static CRITICAL_SECTION dde_crst = { &critsect_debug, -1, 0, 0, 0, 0 };
1903 static BOOL dde_add_pair(HGLOBAL chm, HGLOBAL shm)
1908 EnterCriticalSection(&dde_crst);
1910 /* now remember the pair of hMem on both sides */
1911 if (dde_num_used == dde_num_alloc)
1913 struct DDE_pair* tmp;
1915 tmp = HeapReAlloc( GetProcessHeap(), 0, dde_pairs,
1916 (dde_num_alloc + GROWBY) * sizeof(struct DDE_pair));
1918 tmp = HeapAlloc( GetProcessHeap(), 0,
1919 (dde_num_alloc + GROWBY) * sizeof(struct DDE_pair));
1923 LeaveCriticalSection(&dde_crst);
1927 /* zero out newly allocated part */
1928 memset(&dde_pairs[dde_num_alloc], 0, GROWBY * sizeof(struct DDE_pair));
1929 dde_num_alloc += GROWBY;
1932 for (i = 0; i < dde_num_alloc; i++)
1934 if (dde_pairs[i].server_hMem == 0)
1936 dde_pairs[i].client_hMem = chm;
1937 dde_pairs[i].server_hMem = shm;
1942 LeaveCriticalSection(&dde_crst);
1946 static HGLOBAL dde_get_pair(HGLOBAL shm)
1951 EnterCriticalSection(&dde_crst);
1952 for (i = 0; i < dde_num_alloc; i++)
1954 if (dde_pairs[i].server_hMem == shm)
1956 /* free this pair */
1957 dde_pairs[i].server_hMem = 0;
1959 ret = dde_pairs[i].client_hMem;
1963 LeaveCriticalSection(&dde_crst);
1967 /***********************************************************************
1970 * Post a DDE message
1972 static BOOL post_dde_message( struct packed_message *data, const struct send_message_info *info )
1976 UINT_PTR uiLo, uiHi;
1978 HGLOBAL hunlock = 0;
1982 if (!UnpackDDElParam( info->msg, info->lparam, &uiLo, &uiHi ))
1988 /* DDE messages which don't require packing are:
1997 /* uiHi should contain a hMem from WM_DDE_EXECUTE */
1998 HGLOBAL h = dde_get_pair( (HANDLE)uiHi );
2001 ULONGLONG hpack = pack_ptr( h );
2002 /* send back the value of h on the other side */
2003 push_data( data, &hpack, sizeof(hpack) );
2005 TRACE( "send dde-ack %lx %08lx => %p\n", uiLo, uiHi, h );
2010 /* uiHi should contain either an atom or 0 */
2011 TRACE( "send dde-ack %lx atom=%lx\n", uiLo, uiHi );
2012 lp = MAKELONG( uiLo, uiHi );
2021 size = GlobalSize( (HGLOBAL)uiLo ) ;
2022 if ((info->msg == WM_DDE_ADVISE && size < sizeof(DDEADVISE)) ||
2023 (info->msg == WM_DDE_DATA && size < FIELD_OFFSET(DDEDATA, Value)) ||
2024 (info->msg == WM_DDE_POKE && size < FIELD_OFFSET(DDEPOKE, Value))
2028 else if (info->msg != WM_DDE_DATA) return FALSE;
2033 if ((ptr = GlobalLock( (HGLOBAL)uiLo) ))
2035 DDEDATA *dde_data = ptr;
2036 TRACE("unused %d, fResponse %d, fRelease %d, fDeferUpd %d, fAckReq %d, cfFormat %d\n",
2037 dde_data->unused, dde_data->fResponse, dde_data->fRelease,
2038 dde_data->reserved, dde_data->fAckReq, dde_data->cfFormat);
2039 push_data( data, ptr, size );
2040 hunlock = (HGLOBAL)uiLo;
2043 TRACE( "send ddepack %u %lx\n", size, uiHi );
2045 case WM_DDE_EXECUTE:
2048 if ((ptr = GlobalLock( (HGLOBAL)info->lparam) ))
2050 push_data(data, ptr, GlobalSize( (HGLOBAL)info->lparam ));
2051 /* so that the other side can send it back on ACK */
2053 hunlock = (HGLOBAL)info->lparam;
2058 SERVER_START_REQ( send_message )
2060 req->id = info->dest_tid;
2061 req->type = info->type;
2063 req->win = wine_server_user_handle( info->hwnd );
2064 req->msg = info->msg;
2065 req->wparam = info->wparam;
2067 req->timeout = TIMEOUT_INFINITE;
2068 for (i = 0; i < data->count; i++)
2069 wine_server_add_data( req, data->data[i], data->size[i] );
2070 if ((res = wine_server_call( req )))
2072 if (res == STATUS_INVALID_PARAMETER)
2073 /* FIXME: find a STATUS_ value for this one */
2074 SetLastError( ERROR_INVALID_THREAD_ID );
2076 SetLastError( RtlNtStatusToDosError(res) );
2079 FreeDDElParam(info->msg, info->lparam);
2082 if (hunlock) GlobalUnlock(hunlock);
2087 /***********************************************************************
2088 * unpack_dde_message
2090 * Unpack a posted DDE message received from another process.
2092 static BOOL unpack_dde_message( HWND hwnd, UINT message, WPARAM *wparam, LPARAM *lparam,
2093 void **buffer, size_t size )
2095 UINT_PTR uiLo, uiHi;
2105 /* hMem is being passed */
2106 if (size != sizeof(hpack)) return FALSE;
2107 if (!buffer || !*buffer) return FALSE;
2109 memcpy( &hpack, *buffer, size );
2110 hMem = unpack_ptr( hpack );
2111 uiHi = (UINT_PTR)hMem;
2112 TRACE("recv dde-ack %lx mem=%lx[%lx]\n", uiLo, uiHi, GlobalSize( hMem ));
2116 uiLo = LOWORD( *lparam );
2117 uiHi = HIWORD( *lparam );
2118 TRACE("recv dde-ack %lx atom=%lx\n", uiLo, uiHi);
2120 *lparam = PackDDElParam( WM_DDE_ACK, uiLo, uiHi );
2125 if ((!buffer || !*buffer) && message != WM_DDE_DATA) return FALSE;
2129 if (!(hMem = GlobalAlloc( GMEM_MOVEABLE|GMEM_DDESHARE, size )))
2131 if ((ptr = GlobalLock( hMem )))
2133 memcpy( ptr, *buffer, size );
2134 GlobalUnlock( hMem );
2142 uiLo = (UINT_PTR)hMem;
2144 *lparam = PackDDElParam( message, uiLo, uiHi );
2146 case WM_DDE_EXECUTE:
2149 if (!buffer || !*buffer) return FALSE;
2150 if (!(hMem = GlobalAlloc( GMEM_MOVEABLE|GMEM_DDESHARE, size ))) return FALSE;
2151 if ((ptr = GlobalLock( hMem )))
2153 memcpy( ptr, *buffer, size );
2154 GlobalUnlock( hMem );
2155 TRACE( "exec: pairing c=%08lx s=%p\n", *lparam, hMem );
2156 if (!dde_add_pair( (HGLOBAL)*lparam, hMem ))
2167 } else return FALSE;
2168 *lparam = (LPARAM)hMem;
2174 /***********************************************************************
2177 * Call a window procedure and the corresponding hooks.
2179 static LRESULT call_window_proc( HWND hwnd, UINT msg, WPARAM wparam, LPARAM lparam,
2180 BOOL unicode, BOOL same_thread, enum wm_char_mapping mapping )
2184 CWPRETSTRUCT cwpret;
2186 if (msg & 0x80000000)
2188 result = handle_internal_message( hwnd, msg, wparam, lparam );
2192 /* first the WH_CALLWNDPROC hook */
2193 hwnd = WIN_GetFullHandle( hwnd );
2194 cwp.lParam = lparam;
2195 cwp.wParam = wparam;
2198 HOOK_CallHooks( WH_CALLWNDPROC, HC_ACTION, same_thread, (LPARAM)&cwp, unicode );
2200 /* now call the window procedure */
2201 if (!WINPROC_call_window( hwnd, msg, wparam, lparam, &result, unicode, mapping )) goto done;
2203 /* and finally the WH_CALLWNDPROCRET hook */
2204 cwpret.lResult = result;
2205 cwpret.lParam = lparam;
2206 cwpret.wParam = wparam;
2207 cwpret.message = msg;
2209 HOOK_CallHooks( WH_CALLWNDPROCRET, HC_ACTION, same_thread, (LPARAM)&cwpret, unicode );
2215 /***********************************************************************
2216 * send_parent_notify
2218 * Send a WM_PARENTNOTIFY to all ancestors of the given window, unless
2219 * the window has the WS_EX_NOPARENTNOTIFY style.
2221 static void send_parent_notify( HWND hwnd, WORD event, WORD idChild, POINT pt )
2223 /* pt has to be in the client coordinates of the parent window */
2224 MapWindowPoints( 0, hwnd, &pt, 1 );
2229 if (!(GetWindowLongW( hwnd, GWL_STYLE ) & WS_CHILD)) break;
2230 if (GetWindowLongW( hwnd, GWL_EXSTYLE ) & WS_EX_NOPARENTNOTIFY) break;
2231 if (!(parent = GetParent(hwnd))) break;
2232 if (parent == GetDesktopWindow()) break;
2233 MapWindowPoints( hwnd, parent, &pt, 1 );
2235 SendMessageW( hwnd, WM_PARENTNOTIFY,
2236 MAKEWPARAM( event, idChild ), MAKELPARAM( pt.x, pt.y ) );
2241 /***********************************************************************
2242 * accept_hardware_message
2244 * Tell the server we have passed the message to the app
2245 * (even though we may end up dropping it later on)
2247 static void accept_hardware_message( UINT hw_id, BOOL remove, HWND new_hwnd )
2249 SERVER_START_REQ( accept_hardware_message )
2252 req->remove = remove;
2253 req->new_win = wine_server_user_handle( new_hwnd );
2254 if (wine_server_call( req ))
2255 FIXME("Failed to reply to MSG_HARDWARE message. Message may not be removed from queue.\n");
2261 /***********************************************************************
2262 * process_keyboard_message
2264 * returns TRUE if the contents of 'msg' should be passed to the application
2266 static BOOL process_keyboard_message( MSG *msg, UINT hw_id, HWND hwnd_filter,
2267 UINT first, UINT last, BOOL remove )
2271 if (msg->message == WM_KEYDOWN || msg->message == WM_SYSKEYDOWN ||
2272 msg->message == WM_KEYUP || msg->message == WM_SYSKEYUP)
2273 switch (msg->wParam)
2275 case VK_LSHIFT: case VK_RSHIFT:
2276 msg->wParam = VK_SHIFT;
2278 case VK_LCONTROL: case VK_RCONTROL:
2279 msg->wParam = VK_CONTROL;
2281 case VK_LMENU: case VK_RMENU:
2282 msg->wParam = VK_MENU;
2286 /* FIXME: is this really the right place for this hook? */
2287 event.message = msg->message;
2288 event.hwnd = msg->hwnd;
2289 event.time = msg->time;
2290 event.paramL = (msg->wParam & 0xFF) | (HIWORD(msg->lParam) << 8);
2291 event.paramH = msg->lParam & 0x7FFF;
2292 if (HIWORD(msg->lParam) & 0x0100) event.paramH |= 0x8000; /* special_key - bit */
2293 HOOK_CallHooks( WH_JOURNALRECORD, HC_ACTION, 0, (LPARAM)&event, TRUE );
2295 /* check message filters */
2296 if (msg->message < first || msg->message > last) return FALSE;
2297 if (!check_hwnd_filter( msg, hwnd_filter )) return FALSE;
2301 if((msg->message == WM_KEYDOWN) &&
2302 (msg->hwnd != GetDesktopWindow()))
2304 /* Handle F1 key by sending out WM_HELP message */
2305 if (msg->wParam == VK_F1)
2307 PostMessageW( msg->hwnd, WM_KEYF1, 0, 0 );
2309 else if(msg->wParam >= VK_BROWSER_BACK &&
2310 msg->wParam <= VK_LAUNCH_APP2)
2312 /* FIXME: Process keystate */
2313 SendMessageW(msg->hwnd, WM_APPCOMMAND, (WPARAM)msg->hwnd, MAKELPARAM(0, (FAPPCOMMAND_KEY | (msg->wParam - VK_BROWSER_BACK + 1))));
2316 else if (msg->message == WM_KEYUP)
2318 /* Handle VK_APPS key by posting a WM_CONTEXTMENU message */
2319 if (msg->wParam == VK_APPS && !MENU_IsMenuActive())
2320 PostMessageW(msg->hwnd, WM_CONTEXTMENU, (WPARAM)msg->hwnd, -1);
2324 if (HOOK_CallHooks( WH_KEYBOARD, remove ? HC_ACTION : HC_NOREMOVE,
2325 LOWORD(msg->wParam), msg->lParam, TRUE ))
2327 /* skip this message */
2328 HOOK_CallHooks( WH_CBT, HCBT_KEYSKIPPED, LOWORD(msg->wParam), msg->lParam, TRUE );
2329 accept_hardware_message( hw_id, TRUE, 0 );
2332 accept_hardware_message( hw_id, remove, 0 );
2334 if ( msg->message == WM_KEYDOWN || msg->message == WM_KEYUP )
2335 if ( ImmProcessKey(msg->hwnd, GetKeyboardLayout(0), msg->wParam, msg->lParam, 0) )
2336 msg->wParam = VK_PROCESSKEY;
2342 /***********************************************************************
2343 * process_mouse_message
2345 * returns TRUE if the contents of 'msg' should be passed to the application
2347 static BOOL process_mouse_message( MSG *msg, UINT hw_id, ULONG_PTR extra_info, HWND hwnd_filter,
2348 UINT first, UINT last, BOOL remove )
2357 MOUSEHOOKSTRUCT hook;
2360 /* find the window to dispatch this mouse message to */
2362 GetGUIThreadInfo( GetCurrentThreadId(), &info );
2363 if (info.hwndCapture)
2366 msg->hwnd = info.hwndCapture;
2370 msg->hwnd = WINPOS_WindowFromPoint( msg->hwnd, msg->pt, &hittest );
2373 if (!msg->hwnd || !WIN_IsCurrentThread( msg->hwnd ))
2375 accept_hardware_message( hw_id, TRUE, msg->hwnd );
2379 /* FIXME: is this really the right place for this hook? */
2380 event.message = msg->message;
2381 event.time = msg->time;
2382 event.hwnd = msg->hwnd;
2383 event.paramL = msg->pt.x;
2384 event.paramH = msg->pt.y;
2385 HOOK_CallHooks( WH_JOURNALRECORD, HC_ACTION, 0, (LPARAM)&event, TRUE );
2387 if (!check_hwnd_filter( msg, hwnd_filter )) return FALSE;
2390 message = msg->message;
2391 /* Note: windows has no concept of a non-client wheel message */
2392 if (message != WM_MOUSEWHEEL)
2394 if (hittest != HTCLIENT)
2396 message += WM_NCMOUSEMOVE - WM_MOUSEMOVE;
2397 msg->wParam = hittest;
2401 /* coordinates don't get translated while tracking a menu */
2402 /* FIXME: should differentiate popups and top-level menus */
2403 if (!(info.flags & GUI_INMENUMODE))
2404 ScreenToClient( msg->hwnd, &pt );
2407 msg->lParam = MAKELONG( pt.x, pt.y );
2409 /* translate double clicks */
2411 if ((msg->message == WM_LBUTTONDOWN) ||
2412 (msg->message == WM_RBUTTONDOWN) ||
2413 (msg->message == WM_MBUTTONDOWN) ||
2414 (msg->message == WM_XBUTTONDOWN))
2416 BOOL update = remove;
2418 /* translate double clicks -
2419 * note that ...MOUSEMOVEs can slip in between
2420 * ...BUTTONDOWN and ...BUTTONDBLCLK messages */
2422 if ((info.flags & (GUI_INMENUMODE|GUI_INMOVESIZE)) ||
2423 hittest != HTCLIENT ||
2424 (GetClassLongA( msg->hwnd, GCL_STYLE ) & CS_DBLCLKS))
2426 if ((msg->message == clk_msg.message) &&
2427 (msg->hwnd == clk_msg.hwnd) &&
2428 (msg->wParam == clk_msg.wParam) &&
2429 (msg->time - clk_msg.time < GetDoubleClickTime()) &&
2430 (abs(msg->pt.x - clk_msg.pt.x) < GetSystemMetrics(SM_CXDOUBLECLK)/2) &&
2431 (abs(msg->pt.y - clk_msg.pt.y) < GetSystemMetrics(SM_CYDOUBLECLK)/2))
2433 message += (WM_LBUTTONDBLCLK - WM_LBUTTONDOWN);
2436 clk_msg.message = 0; /* clear the double click conditions */
2441 if (message < first || message > last) return FALSE;
2442 /* update static double click conditions */
2443 if (update) clk_msg = *msg;
2447 if (message < first || message > last) return FALSE;
2450 /* message is accepted now (but may still get dropped) */
2453 hook.hwnd = msg->hwnd;
2454 hook.wHitTestCode = hittest;
2455 hook.dwExtraInfo = extra_info;
2456 if (HOOK_CallHooks( WH_MOUSE, remove ? HC_ACTION : HC_NOREMOVE,
2457 message, (LPARAM)&hook, TRUE ))
2460 hook.hwnd = msg->hwnd;
2461 hook.wHitTestCode = hittest;
2462 hook.dwExtraInfo = extra_info;
2463 HOOK_CallHooks( WH_CBT, HCBT_CLICKSKIPPED, message, (LPARAM)&hook, TRUE );
2464 accept_hardware_message( hw_id, TRUE, 0 );
2468 if ((hittest == HTERROR) || (hittest == HTNOWHERE))
2470 SendMessageW( msg->hwnd, WM_SETCURSOR, (WPARAM)msg->hwnd,
2471 MAKELONG( hittest, msg->message ));
2472 accept_hardware_message( hw_id, TRUE, 0 );
2476 accept_hardware_message( hw_id, remove, 0 );
2478 if (!remove || info.hwndCapture)
2480 msg->message = message;
2486 if ((msg->message == WM_LBUTTONDOWN) ||
2487 (msg->message == WM_RBUTTONDOWN) ||
2488 (msg->message == WM_MBUTTONDOWN) ||
2489 (msg->message == WM_XBUTTONDOWN))
2491 /* Send the WM_PARENTNOTIFY,
2492 * note that even for double/nonclient clicks
2493 * notification message is still WM_L/M/RBUTTONDOWN.
2495 send_parent_notify( msg->hwnd, msg->message, 0, msg->pt );
2497 /* Activate the window if needed */
2499 if (msg->hwnd != info.hwndActive)
2501 HWND hwndTop = msg->hwnd;
2504 if ((GetWindowLongW( hwndTop, GWL_STYLE ) & (WS_POPUP|WS_CHILD)) != WS_CHILD) break;
2505 hwndTop = GetParent( hwndTop );
2508 if (hwndTop && hwndTop != GetDesktopWindow())
2510 LONG ret = SendMessageW( msg->hwnd, WM_MOUSEACTIVATE, (WPARAM)hwndTop,
2511 MAKELONG( hittest, msg->message ) );
2514 case MA_NOACTIVATEANDEAT:
2519 case MA_ACTIVATEANDEAT:
2524 if (!FOCUS_MouseActivate( hwndTop )) eatMsg = TRUE;
2527 WARN( "unknown WM_MOUSEACTIVATE code %d\n", ret );
2534 /* send the WM_SETCURSOR message */
2536 /* Windows sends the normal mouse message as the message parameter
2537 in the WM_SETCURSOR message even if it's non-client mouse message */
2538 SendMessageW( msg->hwnd, WM_SETCURSOR, (WPARAM)msg->hwnd, MAKELONG( hittest, msg->message ));
2540 msg->message = message;
2545 /***********************************************************************
2546 * process_hardware_message
2548 * Process a hardware message; return TRUE if message should be passed on to the app
2550 static BOOL process_hardware_message( MSG *msg, UINT hw_id, ULONG_PTR extra_info, HWND hwnd_filter,
2551 UINT first, UINT last, BOOL remove )
2553 if (is_keyboard_message( msg->message ))
2554 return process_keyboard_message( msg, hw_id, hwnd_filter, first, last, remove );
2556 if (is_mouse_message( msg->message ))
2557 return process_mouse_message( msg, hw_id, extra_info, hwnd_filter, first, last, remove );
2559 ERR( "unknown message type %x\n", msg->message );
2564 /***********************************************************************
2565 * call_sendmsg_callback
2567 * Call the callback function of SendMessageCallback.
2569 static inline void call_sendmsg_callback( SENDASYNCPROC callback, HWND hwnd, UINT msg,
2570 ULONG_PTR data, LRESULT result )
2572 if (!callback) return;
2574 if (TRACE_ON(relay))
2575 DPRINTF( "%04x:Call message callback %p (hwnd=%p,msg=%s,data=%08lx,result=%08lx)\n",
2576 GetCurrentThreadId(), callback, hwnd, SPY_GetMsgName( msg, hwnd ),
2578 callback( hwnd, msg, data, result );
2579 if (TRACE_ON(relay))
2580 DPRINTF( "%04x:Ret message callback %p (hwnd=%p,msg=%s,data=%08lx,result=%08lx)\n",
2581 GetCurrentThreadId(), callback, hwnd, SPY_GetMsgName( msg, hwnd ),
2586 /***********************************************************************
2589 * Peek for a message matching the given parameters. Return FALSE if none available.
2590 * All pending sent messages are processed before returning.
2592 static BOOL peek_message( MSG *msg, HWND hwnd, UINT first, UINT last, UINT flags, UINT changed_mask )
2595 struct user_thread_info *thread_info = get_user_thread_info();
2596 struct received_message_info info, *old_info;
2597 unsigned int hw_id = 0; /* id of previous hardware message */
2599 size_t buffer_size = 256;
2601 if (!(buffer = HeapAlloc( GetProcessHeap(), 0, buffer_size ))) return FALSE;
2603 if (!first && !last) last = ~0;
2604 if (hwnd == HWND_BROADCAST) hwnd = HWND_TOPMOST;
2610 const message_data_t *msg_data = buffer;
2612 SERVER_START_REQ( get_message )
2615 req->get_win = wine_server_user_handle( hwnd );
2616 req->get_first = first;
2617 req->get_last = last;
2619 req->wake_mask = changed_mask & (QS_SENDMESSAGE | QS_SMRESULT);
2620 req->changed_mask = changed_mask;
2621 wine_server_set_reply( req, buffer, buffer_size );
2622 if (!(res = wine_server_call( req )))
2624 size = wine_server_reply_size( reply );
2625 info.type = reply->type;
2626 info.msg.hwnd = wine_server_ptr_handle( reply->win );
2627 info.msg.message = reply->msg;
2628 info.msg.wParam = reply->wparam;
2629 info.msg.lParam = reply->lparam;
2630 info.msg.time = reply->time;
2634 thread_info->active_hooks = reply->active_hooks;
2636 else buffer_size = reply->total;
2642 HeapFree( GetProcessHeap(), 0, buffer );
2643 if (res != STATUS_BUFFER_OVERFLOW) return FALSE;
2644 if (!(buffer = HeapAlloc( GetProcessHeap(), 0, buffer_size ))) return FALSE;
2648 TRACE( "got type %d msg %x (%s) hwnd %p wp %lx lp %lx\n",
2649 info.type, info.msg.message,
2650 (info.type == MSG_WINEVENT) ? "MSG_WINEVENT" : SPY_GetMsgName(info.msg.message, info.msg.hwnd),
2651 info.msg.hwnd, info.msg.wParam, info.msg.lParam );
2657 info.flags = ISMEX_SEND;
2660 info.flags = ISMEX_NOTIFY;
2663 info.flags = ISMEX_CALLBACK;
2665 case MSG_CALLBACK_RESULT:
2666 if (size >= sizeof(msg_data->callback))
2667 call_sendmsg_callback( wine_server_get_ptr(msg_data->callback.callback),
2668 info.msg.hwnd, info.msg.message,
2669 msg_data->callback.data, msg_data->callback.result );
2672 if (size >= sizeof(msg_data->winevent))
2674 WINEVENTPROC hook_proc;
2676 hook_proc = wine_server_get_ptr( msg_data->winevent.hook_proc );
2677 size -= sizeof(msg_data->winevent);
2680 WCHAR module[MAX_PATH];
2682 size = min( size, (MAX_PATH - 1) * sizeof(WCHAR) );
2683 memcpy( module, &msg_data->winevent + 1, size );
2684 module[size / sizeof(WCHAR)] = 0;
2685 if (!(hook_proc = get_hook_proc( hook_proc, module )))
2687 ERR( "invalid winevent hook module name %s\n", debugstr_w(module) );
2692 if (TRACE_ON(relay))
2693 DPRINTF( "%04x:Call winevent proc %p (hook=%04x,event=%x,hwnd=%p,object_id=%lx,child_id=%lx,tid=%04x,time=%x)\n",
2694 GetCurrentThreadId(), hook_proc,
2695 msg_data->winevent.hook, info.msg.message, info.msg.hwnd, info.msg.wParam,
2696 info.msg.lParam, msg_data->winevent.tid, info.msg.time);
2698 hook_proc( wine_server_ptr_handle( msg_data->winevent.hook ), info.msg.message,
2699 info.msg.hwnd, info.msg.wParam, info.msg.lParam,
2700 msg_data->winevent.tid, info.msg.time );
2702 if (TRACE_ON(relay))
2703 DPRINTF( "%04x:Ret winevent proc %p (hook=%04x,event=%x,hwnd=%p,object_id=%lx,child_id=%lx,tid=%04x,time=%x)\n",
2704 GetCurrentThreadId(), hook_proc,
2705 msg_data->winevent.hook, info.msg.message, info.msg.hwnd, info.msg.wParam,
2706 info.msg.lParam, msg_data->winevent.tid, info.msg.time);
2709 case MSG_OTHER_PROCESS:
2710 info.flags = ISMEX_SEND;
2711 if (!unpack_message( info.msg.hwnd, info.msg.message, &info.msg.wParam,
2712 &info.msg.lParam, &buffer, size ))
2715 reply_message( &info, 0, TRUE );
2720 if (size >= sizeof(msg_data->hardware))
2722 info.msg.pt.x = msg_data->hardware.x;
2723 info.msg.pt.y = msg_data->hardware.y;
2724 hw_id = msg_data->hardware.hw_id;
2725 if (!process_hardware_message( &info.msg, hw_id, msg_data->hardware.info,
2726 hwnd, first, last, flags & PM_REMOVE ))
2728 TRACE("dropping msg %x\n", info.msg.message );
2729 continue; /* ignore it */
2732 thread_info->GetMessagePosVal = MAKELONG( info.msg.pt.x, info.msg.pt.y );
2733 thread_info->GetMessageTimeVal = info.msg.time;
2734 thread_info->GetMessageExtraInfoVal = msg_data->hardware.info;
2735 HeapFree( GetProcessHeap(), 0, buffer );
2736 HOOK_CallHooks( WH_GETMESSAGE, HC_ACTION, flags & PM_REMOVE, (LPARAM)msg, TRUE );
2741 if (info.msg.message & 0x80000000) /* internal message */
2743 if (flags & PM_REMOVE)
2745 handle_internal_message( info.msg.hwnd, info.msg.message,
2746 info.msg.wParam, info.msg.lParam );
2747 /* if this is a nested call return right away */
2748 if (first == info.msg.message && last == info.msg.message) return FALSE;
2751 peek_message( msg, info.msg.hwnd, info.msg.message,
2752 info.msg.message, flags | PM_REMOVE, changed_mask );
2755 if (info.msg.message >= WM_DDE_FIRST && info.msg.message <= WM_DDE_LAST)
2757 if (!unpack_dde_message( info.msg.hwnd, info.msg.message, &info.msg.wParam,
2758 &info.msg.lParam, &buffer, size ))
2759 continue; /* ignore it */
2762 msg->pt.x = (short)LOWORD( thread_info->GetMessagePosVal );
2763 msg->pt.y = (short)HIWORD( thread_info->GetMessagePosVal );
2764 thread_info->GetMessageTimeVal = info.msg.time;
2765 thread_info->GetMessageExtraInfoVal = 0;
2766 HeapFree( GetProcessHeap(), 0, buffer );
2767 HOOK_CallHooks( WH_GETMESSAGE, HC_ACTION, flags & PM_REMOVE, (LPARAM)msg, TRUE );
2771 /* if we get here, we have a sent message; call the window procedure */
2772 old_info = thread_info->receive_info;
2773 thread_info->receive_info = &info;
2774 result = call_window_proc( info.msg.hwnd, info.msg.message, info.msg.wParam,
2775 info.msg.lParam, (info.type != MSG_ASCII), FALSE,
2776 WMCHAR_MAP_RECVMESSAGE );
2777 reply_message( &info, result, TRUE );
2778 thread_info->receive_info = old_info;
2780 /* if some PM_QS* flags were specified, only handle sent messages from now on */
2781 if (HIWORD(flags) && !changed_mask) flags = PM_QS_SENDMESSAGE | LOWORD(flags);
2786 /***********************************************************************
2787 * process_sent_messages
2789 * Process all pending sent messages.
2791 static inline void process_sent_messages(void)
2794 peek_message( &msg, 0, 0, 0, PM_REMOVE | PM_QS_SENDMESSAGE, 0 );
2798 /***********************************************************************
2799 * get_server_queue_handle
2801 * Get a handle to the server message queue for the current thread.
2803 static HANDLE get_server_queue_handle(void)
2805 struct user_thread_info *thread_info = get_user_thread_info();
2808 if (!(ret = thread_info->server_queue))
2810 SERVER_START_REQ( get_msg_queue )
2812 wine_server_call( req );
2813 ret = wine_server_ptr_handle( reply->handle );
2816 thread_info->server_queue = ret;
2817 if (!ret) ERR( "Cannot get server thread queue\n" );
2823 /***********************************************************************
2824 * wait_message_reply
2826 * Wait until a sent message gets replied to.
2828 static void wait_message_reply( UINT flags )
2830 HANDLE server_queue = get_server_queue_handle();
2834 unsigned int wake_bits = 0;
2836 SERVER_START_REQ( set_queue_mask )
2838 req->wake_mask = QS_SMRESULT | ((flags & SMTO_BLOCK) ? 0 : QS_SENDMESSAGE);
2839 req->changed_mask = req->wake_mask;
2841 if (!wine_server_call( req ))
2842 wake_bits = reply->wake_bits;
2846 if (wake_bits & QS_SMRESULT) return; /* got a result */
2847 if (wake_bits & QS_SENDMESSAGE)
2849 /* Process the sent message immediately */
2850 process_sent_messages();
2854 wow_handlers.wait_message( 1, &server_queue, INFINITE, QS_SENDMESSAGE, 0 );
2858 /***********************************************************************
2859 * put_message_in_queue
2861 * Put a sent message into the destination queue.
2862 * For inter-process message, reply_size is set to expected size of reply data.
2864 static BOOL put_message_in_queue( const struct send_message_info *info, size_t *reply_size )
2866 struct packed_message data;
2867 message_data_t msg_data;
2870 timeout_t timeout = TIMEOUT_INFINITE;
2872 /* Check for INFINITE timeout for compatibility with Win9x,
2873 * although Windows >= NT does not do so
2875 if (info->type != MSG_NOTIFY &&
2876 info->type != MSG_CALLBACK &&
2877 info->type != MSG_POSTED &&
2879 info->timeout != INFINITE)
2881 /* timeout is signed despite the prototype */
2882 timeout = (timeout_t)max( 0, (int)info->timeout ) * -10000;
2885 memset( &data, 0, sizeof(data) );
2886 if (info->type == MSG_OTHER_PROCESS)
2888 *reply_size = pack_message( info->hwnd, info->msg, info->wparam, info->lparam, &data );
2889 if (data.count == -1)
2891 WARN( "cannot pack message %x\n", info->msg );
2895 else if (info->type == MSG_CALLBACK)
2897 msg_data.callback.callback = wine_server_client_ptr( info->callback );
2898 msg_data.callback.data = info->data;
2899 msg_data.callback.result = 0;
2900 data.data[0] = &msg_data;
2901 data.size[0] = sizeof(msg_data.callback);
2904 else if (info->type == MSG_POSTED && info->msg >= WM_DDE_FIRST && info->msg <= WM_DDE_LAST)
2906 return post_dde_message( &data, info );
2909 SERVER_START_REQ( send_message )
2911 req->id = info->dest_tid;
2912 req->type = info->type;
2914 req->win = wine_server_user_handle( info->hwnd );
2915 req->msg = info->msg;
2916 req->wparam = info->wparam;
2917 req->lparam = info->lparam;
2918 req->timeout = timeout;
2920 if (info->flags & SMTO_ABORTIFHUNG) req->flags |= SEND_MSG_ABORT_IF_HUNG;
2921 for (i = 0; i < data.count; i++) wine_server_add_data( req, data.data[i], data.size[i] );
2922 if ((res = wine_server_call( req )))
2924 if (res == STATUS_INVALID_PARAMETER)
2925 /* FIXME: find a STATUS_ value for this one */
2926 SetLastError( ERROR_INVALID_THREAD_ID );
2928 SetLastError( RtlNtStatusToDosError(res) );
2936 /***********************************************************************
2939 * Retrieve a message reply from the server.
2941 static LRESULT retrieve_reply( const struct send_message_info *info,
2942 size_t reply_size, LRESULT *result )
2945 void *reply_data = NULL;
2949 if (!(reply_data = HeapAlloc( GetProcessHeap(), 0, reply_size )))
2951 WARN( "no memory for reply, will be truncated\n" );
2955 SERVER_START_REQ( get_message_reply )
2958 if (reply_size) wine_server_set_reply( req, reply_data, reply_size );
2959 if (!(status = wine_server_call( req ))) *result = reply->result;
2960 reply_size = wine_server_reply_size( reply );
2963 if (!status && reply_size)
2964 unpack_reply( info->hwnd, info->msg, info->wparam, info->lparam, reply_data, reply_size );
2966 HeapFree( GetProcessHeap(), 0, reply_data );
2968 TRACE( "hwnd %p msg %x (%s) wp %lx lp %lx got reply %lx (err=%d)\n",
2969 info->hwnd, info->msg, SPY_GetMsgName(info->msg, info->hwnd), info->wparam,
2970 info->lparam, *result, status );
2972 /* MSDN states that last error is 0 on timeout, but at least NT4 returns ERROR_TIMEOUT */
2973 if (status) SetLastError( RtlNtStatusToDosError(status) );
2978 /***********************************************************************
2979 * send_inter_thread_message
2981 static LRESULT send_inter_thread_message( const struct send_message_info *info, LRESULT *res_ptr )
2983 size_t reply_size = 0;
2985 TRACE( "hwnd %p msg %x (%s) wp %lx lp %lx\n",
2986 info->hwnd, info->msg, SPY_GetMsgName(info->msg, info->hwnd), info->wparam, info->lparam );
2988 USER_CheckNotLock();
2990 if (!put_message_in_queue( info, &reply_size )) return 0;
2992 /* there's no reply to wait for on notify/callback messages */
2993 if (info->type == MSG_NOTIFY || info->type == MSG_CALLBACK) return 1;
2995 wait_message_reply( info->flags );
2996 return retrieve_reply( info, reply_size, res_ptr );
3000 /***********************************************************************
3001 * send_inter_thread_callback
3003 static LRESULT send_inter_thread_callback( HWND hwnd, UINT msg, WPARAM wp, LPARAM lp,
3004 LRESULT *result, void *arg )
3006 struct send_message_info *info = arg;
3011 return send_inter_thread_message( info, result );
3015 /***********************************************************************
3018 * Backend implementation of the various SendMessage functions.
3020 static BOOL send_message( struct send_message_info *info, DWORD_PTR *res_ptr, BOOL unicode )
3026 if (is_broadcast(info->hwnd))
3028 EnumWindows( broadcast_message_callback, (LPARAM)info );
3029 if (res_ptr) *res_ptr = 1;
3033 if (!(info->dest_tid = GetWindowThreadProcessId( info->hwnd, &dest_pid ))) return FALSE;
3035 if (USER_IsExitingThread( info->dest_tid )) return FALSE;
3037 SPY_EnterMessage( SPY_SENDMESSAGE, info->hwnd, info->msg, info->wparam, info->lparam );
3039 if (info->dest_tid == GetCurrentThreadId())
3041 result = call_window_proc( info->hwnd, info->msg, info->wparam, info->lparam,
3042 unicode, TRUE, info->wm_char );
3043 if (info->type == MSG_CALLBACK)
3044 call_sendmsg_callback( info->callback, info->hwnd, info->msg, info->data, result );
3049 if (dest_pid != GetCurrentProcessId() && (info->type == MSG_ASCII || info->type == MSG_UNICODE))
3050 info->type = MSG_OTHER_PROCESS;
3052 /* MSG_ASCII can be sent unconverted except for WM_CHAR; everything else needs to be Unicode */
3053 if (!unicode && is_unicode_message( info->msg ) &&
3054 (info->type != MSG_ASCII || info->msg == WM_CHAR))
3055 ret = WINPROC_CallProcAtoW( send_inter_thread_callback, info->hwnd, info->msg,
3056 info->wparam, info->lparam, &result, info, info->wm_char );
3058 ret = send_inter_thread_message( info, &result );
3061 SPY_ExitMessage( SPY_RESULT_OK, info->hwnd, info->msg, result, info->wparam, info->lparam );
3062 if (ret && res_ptr) *res_ptr = result;
3067 /***********************************************************************
3068 * MSG_SendInternalMessageTimeout
3070 * Same as SendMessageTimeoutW but sends the message to a specific thread
3071 * without requiring a window handle. Only works for internal Wine messages.
3073 LRESULT MSG_SendInternalMessageTimeout( DWORD dest_pid, DWORD dest_tid,
3074 UINT msg, WPARAM wparam, LPARAM lparam,
3075 UINT flags, UINT timeout, PDWORD_PTR res_ptr )
3077 struct send_message_info info;
3078 LRESULT ret, result;
3080 assert( msg & 0x80000000 ); /* must be an internal Wine message */
3082 info.type = MSG_UNICODE;
3083 info.dest_tid = dest_tid;
3086 info.wparam = wparam;
3087 info.lparam = lparam;
3089 info.timeout = timeout;
3091 if (USER_IsExitingThread( dest_tid )) return 0;
3093 if (dest_tid == GetCurrentThreadId())
3095 result = handle_internal_message( 0, msg, wparam, lparam );
3100 if (dest_pid != GetCurrentProcessId()) info.type = MSG_OTHER_PROCESS;
3101 ret = send_inter_thread_message( &info, &result );
3103 if (ret && res_ptr) *res_ptr = result;
3108 /***********************************************************************
3109 * SendMessageTimeoutW (USER32.@)
3111 LRESULT WINAPI SendMessageTimeoutW( HWND hwnd, UINT msg, WPARAM wparam, LPARAM lparam,
3112 UINT flags, UINT timeout, PDWORD_PTR res_ptr )
3114 struct send_message_info info;
3116 info.type = MSG_UNICODE;
3119 info.wparam = wparam;
3120 info.lparam = lparam;
3122 info.timeout = timeout;
3124 return send_message( &info, res_ptr, TRUE );
3127 /***********************************************************************
3128 * SendMessageTimeoutA (USER32.@)
3130 LRESULT WINAPI SendMessageTimeoutA( HWND hwnd, UINT msg, WPARAM wparam, LPARAM lparam,
3131 UINT flags, UINT timeout, PDWORD_PTR res_ptr )
3133 struct send_message_info info;
3135 info.type = MSG_ASCII;
3138 info.wparam = wparam;
3139 info.lparam = lparam;
3141 info.timeout = timeout;
3142 info.wm_char = WMCHAR_MAP_SENDMESSAGETIMEOUT;
3144 return send_message( &info, res_ptr, FALSE );
3148 /***********************************************************************
3149 * SendMessageW (USER32.@)
3151 LRESULT WINAPI SendMessageW( HWND hwnd, UINT msg, WPARAM wparam, LPARAM lparam )
3154 struct send_message_info info;
3156 info.type = MSG_UNICODE;
3159 info.wparam = wparam;
3160 info.lparam = lparam;
3161 info.flags = SMTO_NORMAL;
3164 send_message( &info, &res, TRUE );
3169 /***********************************************************************
3170 * SendMessageA (USER32.@)
3172 LRESULT WINAPI SendMessageA( HWND hwnd, UINT msg, WPARAM wparam, LPARAM lparam )
3175 struct send_message_info info;
3177 info.type = MSG_ASCII;
3180 info.wparam = wparam;
3181 info.lparam = lparam;
3182 info.flags = SMTO_NORMAL;
3184 info.wm_char = WMCHAR_MAP_SENDMESSAGE;
3186 send_message( &info, &res, FALSE );
3191 /***********************************************************************
3192 * SendNotifyMessageA (USER32.@)
3194 BOOL WINAPI SendNotifyMessageA( HWND hwnd, UINT msg, WPARAM wparam, LPARAM lparam )
3196 struct send_message_info info;
3198 if (is_pointer_message(msg))
3200 SetLastError( ERROR_MESSAGE_SYNC_ONLY );
3204 info.type = MSG_NOTIFY;
3207 info.wparam = wparam;
3208 info.lparam = lparam;
3210 info.wm_char = WMCHAR_MAP_SENDMESSAGETIMEOUT;
3212 return send_message( &info, NULL, FALSE );
3216 /***********************************************************************
3217 * SendNotifyMessageW (USER32.@)
3219 BOOL WINAPI SendNotifyMessageW( HWND hwnd, UINT msg, WPARAM wparam, LPARAM lparam )
3221 struct send_message_info info;
3223 if (is_pointer_message(msg))
3225 SetLastError( ERROR_MESSAGE_SYNC_ONLY );
3229 info.type = MSG_NOTIFY;
3232 info.wparam = wparam;
3233 info.lparam = lparam;
3236 return send_message( &info, NULL, TRUE );
3240 /***********************************************************************
3241 * SendMessageCallbackA (USER32.@)
3243 BOOL WINAPI SendMessageCallbackA( HWND hwnd, UINT msg, WPARAM wparam, LPARAM lparam,
3244 SENDASYNCPROC callback, ULONG_PTR data )
3246 struct send_message_info info;
3248 if (is_pointer_message(msg))
3250 SetLastError( ERROR_MESSAGE_SYNC_ONLY );
3254 info.type = MSG_CALLBACK;
3257 info.wparam = wparam;
3258 info.lparam = lparam;
3259 info.callback = callback;
3262 info.wm_char = WMCHAR_MAP_SENDMESSAGETIMEOUT;
3264 return send_message( &info, NULL, FALSE );
3268 /***********************************************************************
3269 * SendMessageCallbackW (USER32.@)
3271 BOOL WINAPI SendMessageCallbackW( HWND hwnd, UINT msg, WPARAM wparam, LPARAM lparam,
3272 SENDASYNCPROC callback, ULONG_PTR data )
3274 struct send_message_info info;
3276 if (is_pointer_message(msg))
3278 SetLastError( ERROR_MESSAGE_SYNC_ONLY );
3282 info.type = MSG_CALLBACK;
3285 info.wparam = wparam;
3286 info.lparam = lparam;
3287 info.callback = callback;
3291 return send_message( &info, NULL, TRUE );
3295 /***********************************************************************
3296 * ReplyMessage (USER32.@)
3298 BOOL WINAPI ReplyMessage( LRESULT result )
3300 struct received_message_info *info = get_user_thread_info()->receive_info;
3302 if (!info) return FALSE;
3303 reply_message( info, result, FALSE );
3308 /***********************************************************************
3309 * InSendMessage (USER32.@)
3311 BOOL WINAPI InSendMessage(void)
3313 return (InSendMessageEx(NULL) & (ISMEX_SEND|ISMEX_REPLIED)) == ISMEX_SEND;
3317 /***********************************************************************
3318 * InSendMessageEx (USER32.@)
3320 DWORD WINAPI InSendMessageEx( LPVOID reserved )
3322 struct received_message_info *info = get_user_thread_info()->receive_info;
3324 if (info) return info->flags;
3325 return ISMEX_NOSEND;
3329 /***********************************************************************
3330 * PostMessageA (USER32.@)
3332 BOOL WINAPI PostMessageA( HWND hwnd, UINT msg, WPARAM wparam, LPARAM lparam )
3334 if (!map_wparam_AtoW( msg, &wparam, WMCHAR_MAP_POSTMESSAGE )) return TRUE;
3335 return PostMessageW( hwnd, msg, wparam, lparam );
3339 /***********************************************************************
3340 * PostMessageW (USER32.@)
3342 BOOL WINAPI PostMessageW( HWND hwnd, UINT msg, WPARAM wparam, LPARAM lparam )
3344 struct send_message_info info;
3346 if (is_pointer_message( msg ))
3348 SetLastError( ERROR_MESSAGE_SYNC_ONLY );
3352 TRACE( "hwnd %p msg %x (%s) wp %lx lp %lx\n",
3353 hwnd, msg, SPY_GetMsgName(msg, hwnd), wparam, lparam );
3355 info.type = MSG_POSTED;
3358 info.wparam = wparam;
3359 info.lparam = lparam;
3362 if (is_broadcast(hwnd))
3364 EnumWindows( broadcast_message_callback, (LPARAM)&info );
3368 if (!hwnd) return PostThreadMessageW( GetCurrentThreadId(), msg, wparam, lparam );
3370 if (!(info.dest_tid = GetWindowThreadProcessId( hwnd, NULL ))) return FALSE;
3372 if (USER_IsExitingThread( info.dest_tid )) return TRUE;
3374 return put_message_in_queue( &info, NULL );
3378 /**********************************************************************
3379 * PostThreadMessageA (USER32.@)
3381 BOOL WINAPI PostThreadMessageA( DWORD thread, UINT msg, WPARAM wparam, LPARAM lparam )
3383 if (!map_wparam_AtoW( msg, &wparam, WMCHAR_MAP_POSTMESSAGE )) return TRUE;
3384 return PostThreadMessageW( thread, msg, wparam, lparam );
3388 /**********************************************************************
3389 * PostThreadMessageW (USER32.@)
3391 BOOL WINAPI PostThreadMessageW( DWORD thread, UINT msg, WPARAM wparam, LPARAM lparam )
3393 struct send_message_info info;
3395 if (is_pointer_message( msg ))
3397 SetLastError( ERROR_MESSAGE_SYNC_ONLY );
3400 if (USER_IsExitingThread( thread )) return TRUE;
3402 info.type = MSG_POSTED;
3403 info.dest_tid = thread;
3406 info.wparam = wparam;
3407 info.lparam = lparam;
3409 return put_message_in_queue( &info, NULL );
3413 /***********************************************************************
3414 * PostQuitMessage (USER32.@)
3416 * Posts a quit message to the current thread's message queue.
3419 * exit_code [I] Exit code to return from message loop.
3425 * This function is not the same as calling:
3426 *|PostThreadMessage(GetCurrentThreadId(), WM_QUIT, exit_code, 0);
3427 * It instead sets a flag in the message queue that signals it to generate
3428 * a WM_QUIT message when there are no other pending sent or posted messages
3431 void WINAPI PostQuitMessage( INT exit_code )
3433 SERVER_START_REQ( post_quit_message )
3435 req->exit_code = exit_code;
3436 wine_server_call( req );
3442 /***********************************************************************
3443 * PeekMessageW (USER32.@)
3445 BOOL WINAPI DECLSPEC_HOTPATCH PeekMessageW( MSG *msg_out, HWND hwnd, UINT first, UINT last, UINT flags )
3449 USER_CheckNotLock();
3451 /* check for graphics events */
3452 USER_Driver->pMsgWaitForMultipleObjectsEx( 0, NULL, 0, QS_ALLINPUT, 0 );
3454 if (!peek_message( &msg, hwnd, first, last, flags, 0 ))
3456 if (!(flags & PM_NOYIELD)) wow_handlers.wait_message( 0, NULL, 0, 0, 0 );
3460 /* copy back our internal safe copy of message data to msg_out.
3461 * msg_out is a variable from the *program*, so it can't be used
3462 * internally as it can get "corrupted" by our use of SendMessage()
3463 * (back to the program) inside the message handling itself. */
3466 SetLastError( ERROR_NOACCESS );
3474 /***********************************************************************
3475 * PeekMessageA (USER32.@)
3477 BOOL WINAPI DECLSPEC_HOTPATCH PeekMessageA( MSG *msg, HWND hwnd, UINT first, UINT last, UINT flags )
3479 if (get_pending_wmchar( msg, first, last, (flags & PM_REMOVE) )) return TRUE;
3480 if (!PeekMessageW( msg, hwnd, first, last, flags )) return FALSE;
3481 map_wparam_WtoA( msg, (flags & PM_REMOVE) );
3486 /***********************************************************************
3487 * GetMessageW (USER32.@)
3489 BOOL WINAPI DECLSPEC_HOTPATCH GetMessageW( MSG *msg, HWND hwnd, UINT first, UINT last )
3491 HANDLE server_queue = get_server_queue_handle();
3492 unsigned int mask = QS_POSTMESSAGE | QS_SENDMESSAGE; /* Always selected */
3494 USER_CheckNotLock();
3496 /* check for graphics events */
3497 USER_Driver->pMsgWaitForMultipleObjectsEx( 0, NULL, 0, QS_ALLINPUT, 0 );
3501 if ((first <= WM_KEYLAST) && (last >= WM_KEYFIRST)) mask |= QS_KEY;
3502 if ( ((first <= WM_MOUSELAST) && (last >= WM_MOUSEFIRST)) ||
3503 ((first <= WM_NCMOUSELAST) && (last >= WM_NCMOUSEFIRST)) ) mask |= QS_MOUSE;
3504 if ((first <= WM_TIMER) && (last >= WM_TIMER)) mask |= QS_TIMER;
3505 if ((first <= WM_SYSTIMER) && (last >= WM_SYSTIMER)) mask |= QS_TIMER;
3506 if ((first <= WM_PAINT) && (last >= WM_PAINT)) mask |= QS_PAINT;
3508 else mask = QS_ALLINPUT;
3510 while (!peek_message( msg, hwnd, first, last, PM_REMOVE | (mask << 16), mask ))
3512 wow_handlers.wait_message( 1, &server_queue, INFINITE, mask, 0 );
3515 return (msg->message != WM_QUIT);
3519 /***********************************************************************
3520 * GetMessageA (USER32.@)
3522 BOOL WINAPI DECLSPEC_HOTPATCH GetMessageA( MSG *msg, HWND hwnd, UINT first, UINT last )
3524 if (get_pending_wmchar( msg, first, last, TRUE )) return TRUE;
3525 GetMessageW( msg, hwnd, first, last );
3526 map_wparam_WtoA( msg, TRUE );
3527 return (msg->message != WM_QUIT);
3531 /***********************************************************************
3532 * IsDialogMessageA (USER32.@)
3533 * IsDialogMessage (USER32.@)
3535 BOOL WINAPI IsDialogMessageA( HWND hwndDlg, LPMSG pmsg )
3538 map_wparam_AtoW( msg.message, &msg.wParam, WMCHAR_MAP_NOMAPPING );
3539 return IsDialogMessageW( hwndDlg, &msg );
3543 /***********************************************************************
3544 * TranslateMessage (USER32.@)
3546 * Implementation of TranslateMessage.
3548 * TranslateMessage translates virtual-key messages into character-messages,
3550 * WM_KEYDOWN/WM_KEYUP combinations produce a WM_CHAR or WM_DEADCHAR message.
3551 * ditto replacing WM_* with WM_SYS*
3552 * This produces WM_CHAR messages only for keys mapped to ASCII characters
3553 * by the keyboard driver.
3555 * If the message is WM_KEYDOWN, WM_KEYUP, WM_SYSKEYDOWN, or WM_SYSKEYUP, the
3556 * return value is nonzero, regardless of the translation.
3559 BOOL WINAPI TranslateMessage( const MSG *msg )
3565 if (msg->message < WM_KEYFIRST || msg->message > WM_KEYLAST) return FALSE;
3566 if (msg->message != WM_KEYDOWN && msg->message != WM_SYSKEYDOWN) return TRUE;
3568 TRACE_(key)("Translating key %s (%04lX), scancode %04x\n",
3569 SPY_GetVKeyName(msg->wParam), msg->wParam, HIWORD(msg->lParam));
3571 switch (msg->wParam)
3574 message = (msg->message == WM_KEYDOWN) ? WM_CHAR : WM_SYSCHAR;
3575 TRACE_(key)("PostMessageW(%p,%s,%04x,%08x)\n",
3576 msg->hwnd, SPY_GetMsgName(message, msg->hwnd), HIWORD(msg->lParam), LOWORD(msg->lParam));
3577 PostMessageW( msg->hwnd, message, HIWORD(msg->lParam), LOWORD(msg->lParam));
3581 return ImmTranslateMessage(msg->hwnd, msg->message, msg->wParam, msg->lParam);
3584 GetKeyboardState( state );
3585 /* FIXME : should handle ToUnicode yielding 2 */
3586 switch (ToUnicode(msg->wParam, HIWORD(msg->lParam), state, wp, 2, 0))
3589 message = (msg->message == WM_KEYDOWN) ? WM_CHAR : WM_SYSCHAR;
3590 TRACE_(key)("1 -> PostMessageW(%p,%s,%04x,%08lx)\n",
3591 msg->hwnd, SPY_GetMsgName(message, msg->hwnd), wp[0], msg->lParam);
3592 PostMessageW( msg->hwnd, message, wp[0], msg->lParam );
3596 message = (msg->message == WM_KEYDOWN) ? WM_DEADCHAR : WM_SYSDEADCHAR;
3597 TRACE_(key)("-1 -> PostMessageW(%p,%s,%04x,%08lx)\n",
3598 msg->hwnd, SPY_GetMsgName(message, msg->hwnd), wp[0], msg->lParam);
3599 PostMessageW( msg->hwnd, message, wp[0], msg->lParam );
3606 /***********************************************************************
3607 * DispatchMessageA (USER32.@)
3609 * See DispatchMessageW.
3611 LRESULT WINAPI DECLSPEC_HOTPATCH DispatchMessageA( const MSG* msg )
3615 /* Process timer messages */
3616 if ((msg->message == WM_TIMER) || (msg->message == WM_SYSTIMER))
3622 retval = CallWindowProcA( (WNDPROC)msg->lParam, msg->hwnd,
3623 msg->message, msg->wParam, GetTickCount() );
3633 if (!msg->hwnd) return 0;
3635 SPY_EnterMessage( SPY_DISPATCHMESSAGE, msg->hwnd, msg->message,
3636 msg->wParam, msg->lParam );
3638 if (!WINPROC_call_window( msg->hwnd, msg->message, msg->wParam, msg->lParam,
3639 &retval, FALSE, WMCHAR_MAP_DISPATCHMESSAGE ))
3641 if (!IsWindow( msg->hwnd )) SetLastError( ERROR_INVALID_WINDOW_HANDLE );
3642 else SetLastError( ERROR_MESSAGE_SYNC_ONLY );
3646 SPY_ExitMessage( SPY_RESULT_OK, msg->hwnd, msg->message, retval,
3647 msg->wParam, msg->lParam );
3649 if (msg->message == WM_PAINT)
3651 /* send a WM_NCPAINT and WM_ERASEBKGND if the non-client area is still invalid */
3652 HRGN hrgn = CreateRectRgn( 0, 0, 0, 0 );
3653 GetUpdateRgn( msg->hwnd, hrgn, TRUE );
3654 DeleteObject( hrgn );
3660 /***********************************************************************
3661 * DispatchMessageW (USER32.@) Process a message
3663 * Process the message specified in the structure *_msg_.
3665 * If the lpMsg parameter points to a WM_TIMER message and the
3666 * parameter of the WM_TIMER message is not NULL, the lParam parameter
3667 * points to the function that is called instead of the window
3668 * procedure. The function stored in lParam (timer callback) is protected
3669 * from causing page-faults.
3671 * The message must be valid.
3675 * DispatchMessage() returns the result of the window procedure invoked.
3682 LRESULT WINAPI DECLSPEC_HOTPATCH DispatchMessageW( const MSG* msg )
3686 /* Process timer messages */
3687 if ((msg->message == WM_TIMER) || (msg->message == WM_SYSTIMER))
3693 retval = CallWindowProcW( (WNDPROC)msg->lParam, msg->hwnd,
3694 msg->message, msg->wParam, GetTickCount() );
3704 if (!msg->hwnd) return 0;
3706 SPY_EnterMessage( SPY_DISPATCHMESSAGE, msg->hwnd, msg->message,
3707 msg->wParam, msg->lParam );
3709 if (!WINPROC_call_window( msg->hwnd, msg->message, msg->wParam, msg->lParam,
3710 &retval, TRUE, WMCHAR_MAP_DISPATCHMESSAGE ))
3712 if (!IsWindow( msg->hwnd )) SetLastError( ERROR_INVALID_WINDOW_HANDLE );
3713 else SetLastError( ERROR_MESSAGE_SYNC_ONLY );
3717 SPY_ExitMessage( SPY_RESULT_OK, msg->hwnd, msg->message, retval,
3718 msg->wParam, msg->lParam );
3720 if (msg->message == WM_PAINT)
3722 /* send a WM_NCPAINT and WM_ERASEBKGND if the non-client area is still invalid */
3723 HRGN hrgn = CreateRectRgn( 0, 0, 0, 0 );
3724 GetUpdateRgn( msg->hwnd, hrgn, TRUE );
3725 DeleteObject( hrgn );
3731 /***********************************************************************
3732 * GetMessagePos (USER.119)
3733 * GetMessagePos (USER32.@)
3735 * The GetMessagePos() function returns a long value representing a
3736 * cursor position, in screen coordinates, when the last message
3737 * retrieved by the GetMessage() function occurs. The x-coordinate is
3738 * in the low-order word of the return value, the y-coordinate is in
3739 * the high-order word. The application can use the MAKEPOINT()
3740 * macro to obtain a POINT structure from the return value.
3742 * For the current cursor position, use GetCursorPos().
3746 * Cursor position of last message on success, zero on failure.
3753 DWORD WINAPI GetMessagePos(void)
3755 return get_user_thread_info()->GetMessagePosVal;
3759 /***********************************************************************
3760 * GetMessageTime (USER.120)
3761 * GetMessageTime (USER32.@)
3763 * GetMessageTime() returns the message time for the last message
3764 * retrieved by the function. The time is measured in milliseconds with
3765 * the same offset as GetTickCount().
3767 * Since the tick count wraps, this is only useful for moderately short
3768 * relative time comparisons.
3772 * Time of last message on success, zero on failure.
3774 LONG WINAPI GetMessageTime(void)
3776 return get_user_thread_info()->GetMessageTimeVal;
3780 /***********************************************************************
3781 * GetMessageExtraInfo (USER.288)
3782 * GetMessageExtraInfo (USER32.@)
3784 LPARAM WINAPI GetMessageExtraInfo(void)
3786 return get_user_thread_info()->GetMessageExtraInfoVal;
3790 /***********************************************************************
3791 * SetMessageExtraInfo (USER32.@)
3793 LPARAM WINAPI SetMessageExtraInfo(LPARAM lParam)
3795 struct user_thread_info *thread_info = get_user_thread_info();
3796 LONG old_value = thread_info->GetMessageExtraInfoVal;
3797 thread_info->GetMessageExtraInfoVal = lParam;
3802 /***********************************************************************
3803 * WaitMessage (USER.112) Suspend thread pending messages
3804 * WaitMessage (USER32.@) Suspend thread pending messages
3806 * WaitMessage() suspends a thread until events appear in the thread's
3809 BOOL WINAPI WaitMessage(void)
3811 return (MsgWaitForMultipleObjectsEx( 0, NULL, INFINITE, QS_ALLINPUT, 0 ) != WAIT_FAILED);
3815 /***********************************************************************
3816 * MsgWaitForMultipleObjectsEx (USER32.@)
3818 DWORD WINAPI MsgWaitForMultipleObjectsEx( DWORD count, CONST HANDLE *pHandles,
3819 DWORD timeout, DWORD mask, DWORD flags )
3821 HANDLE handles[MAXIMUM_WAIT_OBJECTS];
3824 if (count > MAXIMUM_WAIT_OBJECTS-1)
3826 SetLastError( ERROR_INVALID_PARAMETER );
3830 /* set the queue mask */
3831 SERVER_START_REQ( set_queue_mask )
3833 req->wake_mask = (flags & MWMO_INPUTAVAILABLE) ? mask : 0;
3834 req->changed_mask = mask;
3836 wine_server_call( req );
3840 /* add the queue to the handle list */
3841 for (i = 0; i < count; i++) handles[i] = pHandles[i];
3842 handles[count] = get_server_queue_handle();
3844 return wow_handlers.wait_message( count+1, handles, timeout, mask, flags );
3848 /***********************************************************************
3849 * MsgWaitForMultipleObjects (USER32.@)
3851 DWORD WINAPI MsgWaitForMultipleObjects( DWORD count, CONST HANDLE *handles,
3852 BOOL wait_all, DWORD timeout, DWORD mask )
3854 return MsgWaitForMultipleObjectsEx( count, handles, timeout, mask,
3855 wait_all ? MWMO_WAITALL : 0 );
3859 /***********************************************************************
3860 * WaitForInputIdle (USER32.@)
3862 DWORD WINAPI WaitForInputIdle( HANDLE hProcess, DWORD dwTimeOut )
3864 DWORD start_time, elapsed, ret;
3867 handles[0] = hProcess;
3868 SERVER_START_REQ( get_process_idle_event )
3870 req->handle = wine_server_obj_handle( hProcess );
3871 wine_server_call_err( req );
3872 handles[1] = wine_server_ptr_handle( reply->event );
3875 if (!handles[1]) return WAIT_FAILED; /* no event to wait on */
3877 start_time = GetTickCount();
3880 TRACE("waiting for %p\n", handles[1] );
3883 ret = MsgWaitForMultipleObjects ( 2, handles, FALSE, dwTimeOut - elapsed, QS_SENDMESSAGE );
3888 case WAIT_OBJECT_0+2:
3889 process_sent_messages();
3893 TRACE("timeout or error\n");
3896 TRACE("finished\n");
3899 if (dwTimeOut != INFINITE)
3901 elapsed = GetTickCount() - start_time;
3902 if (elapsed > dwTimeOut)
3908 return WAIT_TIMEOUT;
3912 /***********************************************************************
3913 * RegisterWindowMessageA (USER32.@)
3914 * RegisterWindowMessage (USER.118)
3916 UINT WINAPI RegisterWindowMessageA( LPCSTR str )
3918 UINT ret = GlobalAddAtomA(str);
3919 TRACE("%s, ret=%x\n", str, ret);
3924 /***********************************************************************
3925 * RegisterWindowMessageW (USER32.@)
3927 UINT WINAPI RegisterWindowMessageW( LPCWSTR str )
3929 UINT ret = GlobalAddAtomW(str);
3930 TRACE("%s ret=%x\n", debugstr_w(str), ret);
3934 typedef struct BroadcastParm
3945 static BOOL CALLBACK bcast_childwindow( HWND hw, LPARAM lp )
3947 BroadcastParm *parm = (BroadcastParm*)lp;
3948 DWORD_PTR retval = 0;
3951 if (parm->flags & BSF_IGNORECURRENTTASK && WIN_IsCurrentProcess(hw))
3953 TRACE("Not telling myself %p\n", hw);
3957 /* I don't know 100% for sure if this is what Windows does, but it fits the tests */
3958 if (parm->flags & BSF_QUERY)
3960 TRACE("Telling window %p using SendMessageTimeout\n", hw);
3962 /* Not tested for conflicting flags */
3963 if (parm->flags & BSF_FORCEIFHUNG || parm->flags & BSF_NOHANG)
3964 lresult = SendMessageTimeoutW( hw, parm->msg, parm->wp, parm->lp, SMTO_ABORTIFHUNG, 2000, &retval );
3965 else if (parm->flags & BSF_NOTIMEOUTIFNOTHUNG)
3966 lresult = SendMessageTimeoutW( hw, parm->msg, parm->wp, parm->lp, SMTO_NOTIMEOUTIFNOTHUNG, 2000, &retval );
3968 lresult = SendMessageTimeoutW( hw, parm->msg, parm->wp, parm->lp, SMTO_NORMAL, 2000, &retval );
3970 if (!lresult && GetLastError() == ERROR_TIMEOUT)
3972 WARN("Timed out!\n");
3973 if (!(parm->flags & BSF_FORCEIFHUNG))
3976 if (retval == BROADCAST_QUERY_DENY)
3985 else if (parm->flags & BSF_POSTMESSAGE)
3987 TRACE("Telling window %p using PostMessage\n", hw);
3988 PostMessageW( hw, parm->msg, parm->wp, parm->lp );
3992 TRACE("Telling window %p using SendNotifyMessage\n", hw);
3993 SendNotifyMessageW( hw, parm->msg, parm->wp, parm->lp );
3999 static BOOL CALLBACK bcast_desktop( LPWSTR desktop, LPARAM lp )
4003 BroadcastParm *parm = (BroadcastParm*)lp;
4005 TRACE("desktop: %s\n", debugstr_w( desktop ));
4007 hdesktop = open_winstation_desktop( parm->winsta, desktop, 0, FALSE, DESKTOP_ENUMERATE|DESKTOP_WRITEOBJECTS|STANDARD_RIGHTS_WRITE );
4010 FIXME("Could not open desktop %s\n", debugstr_w(desktop));
4014 ret = EnumDesktopWindows( hdesktop, bcast_childwindow, lp );
4015 CloseDesktop(hdesktop);
4016 TRACE("-->%d\n", ret);
4017 return parm->success;
4020 static BOOL CALLBACK bcast_winsta( LPWSTR winsta, LPARAM lp )
4023 HWINSTA hwinsta = OpenWindowStationW( winsta, FALSE, WINSTA_ENUMDESKTOPS );
4024 TRACE("hwinsta: %p/%s/%08x\n", hwinsta, debugstr_w( winsta ), GetLastError());
4027 ((BroadcastParm *)lp)->winsta = hwinsta;
4028 ret = EnumDesktopsW( hwinsta, bcast_desktop, lp );
4029 CloseWindowStation( hwinsta );
4030 TRACE("-->%d\n", ret);
4034 /***********************************************************************
4035 * BroadcastSystemMessageA (USER32.@)
4036 * BroadcastSystemMessage (USER32.@)
4038 LONG WINAPI BroadcastSystemMessageA( DWORD flags, LPDWORD recipients, UINT msg, WPARAM wp, LPARAM lp )
4040 return BroadcastSystemMessageExA( flags, recipients, msg, wp, lp, NULL );
4044 /***********************************************************************
4045 * BroadcastSystemMessageW (USER32.@)
4047 LONG WINAPI BroadcastSystemMessageW( DWORD flags, LPDWORD recipients, UINT msg, WPARAM wp, LPARAM lp )
4049 return BroadcastSystemMessageExW( flags, recipients, msg, wp, lp, NULL );
4052 /***********************************************************************
4053 * BroadcastSystemMessageExA (USER32.@)
4055 LONG WINAPI BroadcastSystemMessageExA( DWORD flags, LPDWORD recipients, UINT msg, WPARAM wp, LPARAM lp, PBSMINFO pinfo )
4057 map_wparam_AtoW( msg, &wp, WMCHAR_MAP_NOMAPPING );
4058 return BroadcastSystemMessageExW( flags, recipients, msg, wp, lp, NULL );
4062 /***********************************************************************
4063 * BroadcastSystemMessageExW (USER32.@)
4065 LONG WINAPI BroadcastSystemMessageExW( DWORD flags, LPDWORD recipients, UINT msg, WPARAM wp, LPARAM lp, PBSMINFO pinfo )
4068 DWORD recips = BSM_ALLCOMPONENTS;
4070 static const DWORD all_flags = ( BSF_QUERY | BSF_IGNORECURRENTTASK | BSF_FLUSHDISK | BSF_NOHANG
4071 | BSF_POSTMESSAGE | BSF_FORCEIFHUNG | BSF_NOTIMEOUTIFNOTHUNG
4072 | BSF_ALLOWSFW | BSF_SENDNOTIFYMESSAGE | BSF_RETURNHDESK | BSF_LUID );
4074 TRACE("Flags: %08x, recipients: %p(0x%x), msg: %04x, wparam: %08lx, lparam: %08lx\n", flags, recipients,
4075 (recipients ? *recipients : recips), msg, wp, lp);
4077 if (flags & ~all_flags)
4079 SetLastError(ERROR_INVALID_PARAMETER);
4084 recipients = &recips;
4086 if ( pinfo && flags & BSF_QUERY )
4087 FIXME("Not returning PBSMINFO information yet\n");
4090 parm.recipients = recipients;
4094 parm.success = TRUE;
4096 if (*recipients & BSM_ALLDESKTOPS || *recipients == BSM_ALLCOMPONENTS)
4097 ret = EnumWindowStationsW(bcast_winsta, (LONG_PTR)&parm);
4098 else if (*recipients & BSM_APPLICATIONS)
4100 EnumWindows(bcast_childwindow, (LONG_PTR)&parm);
4104 FIXME("Recipients %08x not supported!\n", *recipients);
4109 /***********************************************************************
4110 * SetMessageQueue (USER32.@)
4112 BOOL WINAPI SetMessageQueue( INT size )
4114 /* now obsolete the message queue will be expanded dynamically as necessary */
4119 /***********************************************************************
4120 * MessageBeep (USER32.@)
4122 BOOL WINAPI MessageBeep( UINT i )
4125 SystemParametersInfoA( SPI_GETBEEP, 0, &active, FALSE );
4126 if (active) USER_Driver->pBeep();
4131 /***********************************************************************
4132 * SetTimer (USER32.@)
4134 UINT_PTR WINAPI SetTimer( HWND hwnd, UINT_PTR id, UINT timeout, TIMERPROC proc )
4137 WNDPROC winproc = 0;
4139 if (proc) winproc = WINPROC_AllocProc( (WNDPROC)proc, FALSE );
4141 SERVER_START_REQ( set_win_timer )
4143 req->win = wine_server_user_handle( hwnd );
4144 req->msg = WM_TIMER;
4146 req->rate = max( timeout, SYS_TIMER_RATE );
4147 req->lparam = (ULONG_PTR)winproc;
4148 if (!wine_server_call_err( req ))
4151 if (!ret) ret = TRUE;
4157 TRACE("Added %p %lx %p timeout %d\n", hwnd, id, winproc, timeout );
4162 /***********************************************************************
4163 * SetSystemTimer (USER32.@)
4165 UINT_PTR WINAPI SetSystemTimer( HWND hwnd, UINT_PTR id, UINT timeout, TIMERPROC proc )
4168 WNDPROC winproc = 0;
4170 if (proc) winproc = WINPROC_AllocProc( (WNDPROC)proc, FALSE );
4172 SERVER_START_REQ( set_win_timer )
4174 req->win = wine_server_user_handle( hwnd );
4175 req->msg = WM_SYSTIMER;
4177 req->rate = max( timeout, SYS_TIMER_RATE );
4178 req->lparam = (ULONG_PTR)winproc;
4179 if (!wine_server_call_err( req ))
4182 if (!ret) ret = TRUE;
4188 TRACE("Added %p %lx %p timeout %d\n", hwnd, id, winproc, timeout );
4193 /***********************************************************************
4194 * KillTimer (USER32.@)
4196 BOOL WINAPI KillTimer( HWND hwnd, UINT_PTR id )
4200 SERVER_START_REQ( kill_win_timer )
4202 req->win = wine_server_user_handle( hwnd );
4203 req->msg = WM_TIMER;
4205 ret = !wine_server_call_err( req );
4212 /***********************************************************************
4213 * KillSystemTimer (USER32.@)
4215 BOOL WINAPI KillSystemTimer( HWND hwnd, UINT_PTR id )
4219 SERVER_START_REQ( kill_win_timer )
4221 req->win = wine_server_user_handle( hwnd );
4222 req->msg = WM_SYSTIMER;
4224 ret = !wine_server_call_err( req );
4231 /**********************************************************************
4232 * GetGUIThreadInfo (USER32.@)
4234 BOOL WINAPI GetGUIThreadInfo( DWORD id, GUITHREADINFO *info )
4238 SERVER_START_REQ( get_thread_input )
4241 if ((ret = !wine_server_call_err( req )))
4244 info->hwndActive = wine_server_ptr_handle( reply->active );
4245 info->hwndFocus = wine_server_ptr_handle( reply->focus );
4246 info->hwndCapture = wine_server_ptr_handle( reply->capture );
4247 info->hwndMenuOwner = wine_server_ptr_handle( reply->menu_owner );
4248 info->hwndMoveSize = wine_server_ptr_handle( reply->move_size );
4249 info->hwndCaret = wine_server_ptr_handle( reply->caret );
4250 info->rcCaret.left = reply->rect.left;
4251 info->rcCaret.top = reply->rect.top;
4252 info->rcCaret.right = reply->rect.right;
4253 info->rcCaret.bottom = reply->rect.bottom;
4254 if (reply->menu_owner) info->flags |= GUI_INMENUMODE;
4255 if (reply->move_size) info->flags |= GUI_INMOVESIZE;
4256 if (reply->caret) info->flags |= GUI_CARETBLINKING;
4264 /******************************************************************
4265 * IsHungAppWindow (USER32.@)
4268 BOOL WINAPI IsHungAppWindow( HWND hWnd )
4272 SERVER_START_REQ( is_window_hung )
4274 req->win = wine_server_user_handle( hWnd );
4275 ret = !wine_server_call_err( req ) && reply->is_hung;
4281 /******************************************************************
4282 * ChangeWindowMessageFilter (USER32.@)
4284 BOOL WINAPI ChangeWindowMessageFilter( UINT message, DWORD flag )
4286 FIXME( "%x %08x\n", message, flag );