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"
28 #define NONAMELESSUNION
29 #define NONAMELESSSTRUCT
31 #define WIN32_NO_STATUS
42 #include "wine/unicode.h"
43 #include "wine/server.h"
44 #include "user_private.h"
47 #include "wine/debug.h"
48 #include "wine/exception.h"
50 WINE_DEFAULT_DEBUG_CHANNEL(msg);
51 WINE_DECLARE_DEBUG_CHANNEL(relay);
52 WINE_DECLARE_DEBUG_CHANNEL(key);
54 #define WM_NCMOUSEFIRST WM_NCMOUSEMOVE
55 #define WM_NCMOUSELAST (WM_NCMOUSEFIRST+(WM_MOUSELAST-WM_MOUSEFIRST))
57 #define MAX_PACK_COUNT 4
59 #define SYS_TIMER_RATE 55 /* min. timer rate in ms (actually 54.925)*/
61 /* the various structures that can be sent in messages, in platform-independent layout */
62 struct packed_CREATESTRUCTW
64 ULONGLONG lpCreateParams;
68 user_handle_t hwndParent;
81 struct packed_DRAWITEMSTRUCT
88 user_handle_t hwndItem;
96 struct packed_MEASUREITEMSTRUCT
106 struct packed_DELETEITEMSTRUCT
111 user_handle_t hwndItem;
116 struct packed_COMPAREITEMSTRUCT
120 user_handle_t hwndItem;
130 struct packed_WINDOWPOS
134 user_handle_t hwndInsertAfter;
144 struct packed_COPYDATASTRUCT
151 struct packed_HELPINFO
156 user_handle_t hItemHandle;
158 ULONGLONG dwContextId;
162 struct packed_NCCALCSIZE_PARAMS
168 user_handle_t hwndInsertAfter;
190 struct packed_MDINEXTMENU
192 user_handle_t hmenuIn;
194 user_handle_t hmenuNext;
196 user_handle_t hwndNext;
200 struct packed_MDICREATESTRUCTW
213 struct packed_hook_extra_info
215 user_handle_t handle;
220 /* the structures are unpacked on top of the packed ones, so make sure they fit */
221 C_ASSERT( sizeof(struct packed_CREATESTRUCTW) >= sizeof(CREATESTRUCTW) );
222 C_ASSERT( sizeof(struct packed_DRAWITEMSTRUCT) >= sizeof(DRAWITEMSTRUCT) );
223 C_ASSERT( sizeof(struct packed_MEASUREITEMSTRUCT) >= sizeof(MEASUREITEMSTRUCT) );
224 C_ASSERT( sizeof(struct packed_DELETEITEMSTRUCT) >= sizeof(DELETEITEMSTRUCT) );
225 C_ASSERT( sizeof(struct packed_COMPAREITEMSTRUCT) >= sizeof(COMPAREITEMSTRUCT) );
226 C_ASSERT( sizeof(struct packed_WINDOWPOS) >= sizeof(WINDOWPOS) );
227 C_ASSERT( sizeof(struct packed_COPYDATASTRUCT) >= sizeof(COPYDATASTRUCT) );
228 C_ASSERT( sizeof(struct packed_HELPINFO) >= sizeof(HELPINFO) );
229 C_ASSERT( sizeof(struct packed_NCCALCSIZE_PARAMS) >= sizeof(NCCALCSIZE_PARAMS) + sizeof(WINDOWPOS) );
230 C_ASSERT( sizeof(struct packed_MSG) >= sizeof(MSG) );
231 C_ASSERT( sizeof(struct packed_MDINEXTMENU) >= sizeof(MDINEXTMENU) );
232 C_ASSERT( sizeof(struct packed_MDICREATESTRUCTW) >= sizeof(MDICREATESTRUCTW) );
233 C_ASSERT( sizeof(struct packed_hook_extra_info) >= sizeof(struct hook_extra_info) );
237 struct packed_CREATESTRUCTW cs;
238 struct packed_DRAWITEMSTRUCT dis;
239 struct packed_MEASUREITEMSTRUCT mis;
240 struct packed_DELETEITEMSTRUCT dls;
241 struct packed_COMPAREITEMSTRUCT cis;
242 struct packed_WINDOWPOS wp;
243 struct packed_COPYDATASTRUCT cds;
244 struct packed_HELPINFO hi;
245 struct packed_NCCALCSIZE_PARAMS ncp;
246 struct packed_MSG msg;
247 struct packed_MDINEXTMENU mnm;
248 struct packed_MDICREATESTRUCTW mcs;
249 struct packed_hook_extra_info hook;
252 /* description of the data fields that need to be packed along with a sent message */
253 struct packed_message
255 union packed_structs ps;
257 const void *data[MAX_PACK_COUNT];
258 size_t size[MAX_PACK_COUNT];
261 /* info about the message currently being received by the current thread */
262 struct received_message_info
264 enum message_type type;
266 UINT flags; /* InSendMessageEx return flags */
269 /* structure to group all parameters for sent messages of the various kinds */
270 struct send_message_info
272 enum message_type type;
278 UINT flags; /* flags for SendMessageTimeout */
279 UINT timeout; /* timeout for SendMessageTimeout */
280 SENDASYNCPROC callback; /* callback function for SendMessageCallback */
281 ULONG_PTR data; /* callback data */
282 enum wm_char_mapping wm_char;
286 /* Message class descriptor */
287 static const WCHAR messageW[] = {'M','e','s','s','a','g','e',0};
289 const struct builtin_class_descr MESSAGE_builtin_class =
293 WINPROC_MESSAGE, /* proc */
295 IDC_ARROW, /* cursor */
301 /* flag for messages that contain pointers */
302 /* 32 messages per entry, messages 0..31 map to bits 0..31 */
304 #define SET(msg) (1 << ((msg) & 31))
306 static const unsigned int message_pointer_flags[] =
309 SET(WM_CREATE) | SET(WM_SETTEXT) | SET(WM_GETTEXT) |
310 SET(WM_WININICHANGE) | SET(WM_DEVMODECHANGE),
312 SET(WM_GETMINMAXINFO) | SET(WM_DRAWITEM) | SET(WM_MEASUREITEM) | SET(WM_DELETEITEM) |
315 SET(WM_WINDOWPOSCHANGING) | SET(WM_WINDOWPOSCHANGED) | SET(WM_COPYDATA) |
316 SET(WM_NOTIFY) | SET(WM_HELP),
318 SET(WM_STYLECHANGING) | SET(WM_STYLECHANGED),
320 SET(WM_NCCREATE) | SET(WM_NCCALCSIZE) | SET(WM_GETDLGCODE),
322 SET(EM_GETSEL) | SET(EM_GETRECT) | SET(EM_SETRECT) | SET(EM_SETRECTNP),
324 SET(EM_REPLACESEL) | SET(EM_GETLINE) | SET(EM_SETTABSTOPS),
326 SET(SBM_GETRANGE) | SET(SBM_SETSCROLLINFO) | SET(SBM_GETSCROLLINFO) | SET(SBM_GETSCROLLBARINFO),
332 SET(CB_GETEDITSEL) | SET(CB_ADDSTRING) | SET(CB_DIR) | SET(CB_GETLBTEXT) |
333 SET(CB_INSERTSTRING) | SET(CB_FINDSTRING) | SET(CB_SELECTSTRING) |
334 SET(CB_GETDROPPEDCONTROLRECT) | SET(CB_FINDSTRINGEXACT),
338 SET(LB_ADDSTRING) | SET(LB_INSERTSTRING) | SET(LB_GETTEXT) | SET(LB_SELECTSTRING) |
339 SET(LB_DIR) | SET(LB_FINDSTRING) |
340 SET(LB_GETSELITEMS) | SET(LB_SETTABSTOPS) | SET(LB_ADDFILE) | SET(LB_GETITEMRECT),
342 SET(LB_FINDSTRINGEXACT),
348 SET(WM_NEXTMENU) | SET(WM_SIZING) | SET(WM_MOVING) | SET(WM_DEVICECHANGE),
350 SET(WM_MDICREATE) | SET(WM_MDIGETACTIVE) | SET(WM_DROPOBJECT) |
351 SET(WM_QUERYDROPOBJECT) | SET(WM_DRAGLOOP) | SET(WM_DRAGSELECT) | SET(WM_DRAGMOVE),
365 SET(WM_ASKCBFORMATNAME)
368 /* flags for messages that contain Unicode strings */
369 static const unsigned int message_unicode_flags[] =
372 SET(WM_CREATE) | SET(WM_SETTEXT) | SET(WM_GETTEXT) | SET(WM_GETTEXTLENGTH) |
373 SET(WM_WININICHANGE) | SET(WM_DEVMODECHANGE),
385 SET(EM_REPLACESEL) | SET(EM_GETLINE) | SET(EM_SETPASSWORDCHAR),
389 SET(WM_CHAR) | SET(WM_DEADCHAR) | SET(WM_SYSCHAR) | SET(WM_SYSDEADCHAR),
393 SET(CB_ADDSTRING) | SET(CB_DIR) | SET(CB_GETLBTEXT) | SET(CB_GETLBTEXTLEN) |
394 SET(CB_INSERTSTRING) | SET(CB_FINDSTRING) | SET(CB_SELECTSTRING) | SET(CB_FINDSTRINGEXACT),
398 SET(LB_ADDSTRING) | SET(LB_INSERTSTRING) | SET(LB_GETTEXT) | SET(LB_GETTEXTLEN) |
399 SET(LB_SELECTSTRING) | SET(LB_DIR) | SET(LB_FINDSTRING) | SET(LB_ADDFILE),
401 SET(LB_FINDSTRINGEXACT),
423 SET(WM_PAINTCLIPBOARD) | SET(WM_SIZECLIPBOARD) | SET(WM_ASKCBFORMATNAME)
426 /* check whether a given message type includes pointers */
427 static inline int is_pointer_message( UINT message )
429 if (message >= 8*sizeof(message_pointer_flags)) return FALSE;
430 return (message_pointer_flags[message / 32] & SET(message)) != 0;
433 /* check whether a given message type contains Unicode (or ASCII) chars */
434 static inline int is_unicode_message( UINT message )
436 if (message >= 8*sizeof(message_unicode_flags)) return FALSE;
437 return (message_unicode_flags[message / 32] & SET(message)) != 0;
442 /* add a data field to a packed message */
443 static inline void push_data( struct packed_message *data, const void *ptr, size_t size )
445 data->data[data->count] = ptr;
446 data->size[data->count] = size;
450 /* add a string to a packed message */
451 static inline void push_string( struct packed_message *data, LPCWSTR str )
453 push_data( data, str, (strlenW(str) + 1) * sizeof(WCHAR) );
456 /* make sure that the buffer contains a valid null-terminated Unicode string */
457 static inline BOOL check_string( LPCWSTR str, size_t size )
459 for (size /= sizeof(WCHAR); size; size--, str++)
460 if (!*str) return TRUE;
464 /* pack a pointer into a 32/64 portable format */
465 static inline ULONGLONG pack_ptr( const void *ptr )
467 return (ULONG_PTR)ptr;
470 /* unpack a potentially 64-bit pointer, returning 0 when truncated */
471 static inline void *unpack_ptr( ULONGLONG ptr64 )
473 if ((ULONG_PTR)ptr64 != ptr64) return 0;
474 return (void *)(ULONG_PTR)ptr64;
477 /* make sure that there is space for 'size' bytes in buffer, growing it if needed */
478 static inline void *get_buffer_space( void **buffer, size_t size )
484 if (!(ret = HeapReAlloc( GetProcessHeap(), 0, *buffer, size )))
485 HeapFree( GetProcessHeap(), 0, *buffer );
487 else ret = HeapAlloc( GetProcessHeap(), 0, size );
493 /* check whether a combobox expects strings or ids in CB_ADDSTRING/CB_INSERTSTRING */
494 static inline BOOL combobox_has_strings( HWND hwnd )
496 DWORD style = GetWindowLongA( hwnd, GWL_STYLE );
497 return (!(style & (CBS_OWNERDRAWFIXED | CBS_OWNERDRAWVARIABLE)) || (style & CBS_HASSTRINGS));
500 /* check whether a listbox expects strings or ids in LB_ADDSTRING/LB_INSERTSTRING */
501 static inline BOOL listbox_has_strings( HWND hwnd )
503 DWORD style = GetWindowLongA( hwnd, GWL_STYLE );
504 return (!(style & (LBS_OWNERDRAWFIXED | LBS_OWNERDRAWVARIABLE)) || (style & LBS_HASSTRINGS));
507 /* check whether message is in the range of keyboard messages */
508 static inline BOOL is_keyboard_message( UINT message )
510 return (message >= WM_KEYFIRST && message <= WM_KEYLAST);
513 /* check whether message is in the range of mouse messages */
514 static inline BOOL is_mouse_message( UINT message )
516 return ((message >= WM_NCMOUSEFIRST && message <= WM_NCMOUSELAST) ||
517 (message >= WM_MOUSEFIRST && message <= WM_MOUSELAST));
520 /* check whether message matches the specified hwnd filter */
521 static inline BOOL check_hwnd_filter( const MSG *msg, HWND hwnd_filter )
523 if (!hwnd_filter || hwnd_filter == GetDesktopWindow()) return TRUE;
524 return (msg->hwnd == hwnd_filter || IsChild( hwnd_filter, msg->hwnd ));
527 /* check for pending WM_CHAR message with DBCS trailing byte */
528 static inline BOOL get_pending_wmchar( MSG *msg, UINT first, UINT last, BOOL remove )
530 struct wm_char_mapping_data *data = get_user_thread_info()->wmchar_data;
532 if (!data || !data->get_msg.message) return FALSE;
533 if ((first || last) && (first > WM_CHAR || last < WM_CHAR)) return FALSE;
534 if (!msg) return FALSE;
535 *msg = data->get_msg;
536 if (remove) data->get_msg.message = 0;
541 /***********************************************************************
544 * Window procedure for "Message" windows (HWND_MESSAGE parent).
546 LRESULT WINAPI MessageWndProc( HWND hwnd, UINT message, WPARAM wParam, LPARAM lParam )
548 if (message == WM_NCCREATE) return TRUE;
549 return 0; /* all other messages are ignored */
553 /***********************************************************************
554 * broadcast_message_callback
556 * Helper callback for broadcasting messages.
558 static BOOL CALLBACK broadcast_message_callback( HWND hwnd, LPARAM lparam )
560 struct send_message_info *info = (struct send_message_info *)lparam;
561 if (!(GetWindowLongW( hwnd, GWL_STYLE ) & (WS_POPUP|WS_CAPTION))) return TRUE;
565 SendMessageTimeoutW( hwnd, info->msg, info->wparam, info->lparam,
566 info->flags, info->timeout, NULL );
569 SendMessageTimeoutA( hwnd, info->msg, info->wparam, info->lparam,
570 info->flags, info->timeout, NULL );
573 SendNotifyMessageW( hwnd, info->msg, info->wparam, info->lparam );
576 SendMessageCallbackW( hwnd, info->msg, info->wparam, info->lparam,
577 info->callback, info->data );
580 PostMessageW( hwnd, info->msg, info->wparam, info->lparam );
583 ERR( "bad type %d\n", info->type );
590 /***********************************************************************
593 * Convert the wparam of an ASCII message to Unicode.
595 BOOL map_wparam_AtoW( UINT message, WPARAM *wparam, enum wm_char_mapping mapping )
604 /* WM_CHAR is magic: a DBCS char can be sent/posted as two consecutive WM_CHAR
605 * messages, in which case the first char is stored, and the conversion
606 * to Unicode only takes place once the second char is sent/posted.
608 if (mapping != WMCHAR_MAP_NOMAPPING)
610 struct wm_char_mapping_data *data = get_user_thread_info()->wmchar_data;
611 BYTE low = LOBYTE(*wparam);
616 ch[1] = HIBYTE(*wparam);
617 RtlMultiByteToUnicodeN( wch, sizeof(wch), NULL, ch, 2 );
618 TRACE( "map %02x,%02x -> %04x mapping %u\n", (BYTE)ch[0], (BYTE)ch[1], wch[0], mapping );
619 if (data) data->lead_byte[mapping] = 0;
621 else if (data && data->lead_byte[mapping])
623 ch[0] = data->lead_byte[mapping];
625 RtlMultiByteToUnicodeN( wch, sizeof(wch), NULL, ch, 2 );
626 TRACE( "map stored %02x,%02x -> %04x mapping %u\n", (BYTE)ch[0], (BYTE)ch[1], wch[0], mapping );
627 data->lead_byte[mapping] = 0;
629 else if (!IsDBCSLeadByte( low ))
632 RtlMultiByteToUnicodeN( wch, sizeof(wch), NULL, ch, 1 );
633 TRACE( "map %02x -> %04x\n", (BYTE)ch[0], wch[0] );
634 if (data) data->lead_byte[mapping] = 0;
636 else /* store it and wait for trail byte */
640 if (!(data = HeapAlloc( GetProcessHeap(), HEAP_ZERO_MEMORY, sizeof(*data) )))
642 get_user_thread_info()->wmchar_data = data;
644 TRACE( "storing lead byte %02x mapping %u\n", low, mapping );
645 data->lead_byte[mapping] = low;
648 *wparam = MAKEWPARAM(wch[0], wch[1]);
651 /* else fall through */
653 case EM_SETPASSWORDCHAR:
658 ch[0] = LOBYTE(*wparam);
659 ch[1] = HIBYTE(*wparam);
660 RtlMultiByteToUnicodeN( wch, sizeof(wch), NULL, ch, 2 );
661 *wparam = MAKEWPARAM(wch[0], wch[1]);
664 ch[0] = HIBYTE(*wparam);
665 ch[1] = LOBYTE(*wparam);
666 if (ch[0]) RtlMultiByteToUnicodeN( wch, sizeof(wch[0]), NULL, ch, 2 );
667 else RtlMultiByteToUnicodeN( wch, sizeof(wch[0]), NULL, ch + 1, 1 );
668 *wparam = MAKEWPARAM(wch[0], HIWORD(*wparam));
675 /***********************************************************************
678 * Convert the wparam of a Unicode message to ASCII.
680 static void map_wparam_WtoA( MSG *msg, BOOL remove )
689 if (!HIWORD(msg->wParam))
691 wch[0] = LOWORD(msg->wParam);
693 RtlUnicodeToMultiByteN( (LPSTR)ch, 2, &len, wch, sizeof(wch[0]) );
694 if (len == 2) /* DBCS char */
696 struct wm_char_mapping_data *data = get_user_thread_info()->wmchar_data;
699 if (!(data = HeapAlloc( GetProcessHeap(), HEAP_ZERO_MEMORY, sizeof(*data) ))) return;
700 get_user_thread_info()->wmchar_data = data;
704 data->get_msg = *msg;
705 data->get_msg.wParam = ch[1];
711 /* else fall through */
713 case EM_SETPASSWORDCHAR:
718 wch[0] = LOWORD(msg->wParam);
719 wch[1] = HIWORD(msg->wParam);
721 RtlUnicodeToMultiByteN( (LPSTR)ch, 2, NULL, wch, sizeof(wch) );
722 msg->wParam = MAKEWPARAM( ch[0] | (ch[1] << 8), 0 );
725 wch[0] = LOWORD(msg->wParam);
727 RtlUnicodeToMultiByteN( (LPSTR)ch, 2, &len, wch, sizeof(wch[0]) );
729 msg->wParam = MAKEWPARAM( (ch[0] << 8) | ch[1], HIWORD(msg->wParam) );
731 msg->wParam = MAKEWPARAM( ch[0], HIWORD(msg->wParam) );
737 /***********************************************************************
740 * Pack a message for sending to another process.
741 * Return the size of the data we expect in the message reply.
742 * Set data->count to -1 if there is an error.
744 static size_t pack_message( HWND hwnd, UINT message, WPARAM wparam, LPARAM lparam,
745 struct packed_message *data )
753 CREATESTRUCTW *cs = (CREATESTRUCTW *)lparam;
754 data->ps.cs.lpCreateParams = pack_ptr( cs->lpCreateParams );
755 data->ps.cs.hInstance = pack_ptr( cs->hInstance );
756 data->ps.cs.hMenu = wine_server_user_handle( cs->hMenu );
757 data->ps.cs.hwndParent = wine_server_user_handle( cs->hwndParent );
758 data->ps.cs.cy = cs->cy;
759 data->ps.cs.cx = cs->cx;
760 data->ps.cs.y = cs->y;
761 data->ps.cs.x = cs->x;
762 data->ps.cs.style = cs->style;
763 data->ps.cs.dwExStyle = cs->dwExStyle;
764 data->ps.cs.lpszName = pack_ptr( cs->lpszName );
765 data->ps.cs.lpszClass = pack_ptr( cs->lpszClass );
766 push_data( data, &data->ps.cs, sizeof(data->ps.cs) );
767 if (!IS_INTRESOURCE(cs->lpszName)) push_string( data, cs->lpszName );
768 if (!IS_INTRESOURCE(cs->lpszClass)) push_string( data, cs->lpszClass );
769 return sizeof(data->ps.cs);
772 case WM_ASKCBFORMATNAME:
773 return wparam * sizeof(WCHAR);
774 case WM_WININICHANGE:
775 if (lparam) push_string(data, (LPWSTR)lparam );
778 case WM_DEVMODECHANGE:
783 push_string( data, (LPWSTR)lparam );
785 case WM_GETMINMAXINFO:
786 push_data( data, (MINMAXINFO *)lparam, sizeof(MINMAXINFO) );
787 return sizeof(MINMAXINFO);
790 DRAWITEMSTRUCT *dis = (DRAWITEMSTRUCT *)lparam;
791 data->ps.dis.CtlType = dis->CtlType;
792 data->ps.dis.CtlID = dis->CtlID;
793 data->ps.dis.itemID = dis->itemID;
794 data->ps.dis.itemAction = dis->itemAction;
795 data->ps.dis.itemState = dis->itemState;
796 data->ps.dis.hwndItem = wine_server_user_handle( dis->hwndItem );
797 data->ps.dis.hDC = wine_server_user_handle( dis->hDC ); /* FIXME */
798 data->ps.dis.rcItem = dis->rcItem;
799 data->ps.dis.itemData = dis->itemData;
800 push_data( data, &data->ps.dis, sizeof(data->ps.dis) );
805 MEASUREITEMSTRUCT *mis = (MEASUREITEMSTRUCT *)lparam;
806 data->ps.mis.CtlType = mis->CtlType;
807 data->ps.mis.CtlID = mis->CtlID;
808 data->ps.mis.itemID = mis->itemID;
809 data->ps.mis.itemWidth = mis->itemWidth;
810 data->ps.mis.itemHeight = mis->itemHeight;
811 data->ps.mis.itemData = mis->itemData;
812 push_data( data, &data->ps.mis, sizeof(data->ps.mis) );
813 return sizeof(data->ps.mis);
817 DELETEITEMSTRUCT *dls = (DELETEITEMSTRUCT *)lparam;
818 data->ps.dls.CtlType = dls->CtlType;
819 data->ps.dls.CtlID = dls->CtlID;
820 data->ps.dls.itemID = dls->itemID;
821 data->ps.dls.hwndItem = wine_server_user_handle( dls->hwndItem );
822 data->ps.dls.itemData = dls->itemData;
823 push_data( data, &data->ps.dls, sizeof(data->ps.dls) );
828 COMPAREITEMSTRUCT *cis = (COMPAREITEMSTRUCT *)lparam;
829 data->ps.cis.CtlType = cis->CtlType;
830 data->ps.cis.CtlID = cis->CtlID;
831 data->ps.cis.hwndItem = wine_server_user_handle( cis->hwndItem );
832 data->ps.cis.itemID1 = cis->itemID1;
833 data->ps.cis.itemData1 = cis->itemData1;
834 data->ps.cis.itemID2 = cis->itemID2;
835 data->ps.cis.itemData2 = cis->itemData2;
836 data->ps.cis.dwLocaleId = cis->dwLocaleId;
837 push_data( data, &data->ps.cis, sizeof(data->ps.cis) );
840 case WM_WINE_SETWINDOWPOS:
841 case WM_WINDOWPOSCHANGING:
842 case WM_WINDOWPOSCHANGED:
844 WINDOWPOS *wp = (WINDOWPOS *)lparam;
845 data->ps.wp.hwnd = wine_server_user_handle( wp->hwnd );
846 data->ps.wp.hwndInsertAfter = wine_server_user_handle( wp->hwndInsertAfter );
847 data->ps.wp.x = wp->x;
848 data->ps.wp.y = wp->y;
849 data->ps.wp.cx = wp->cx;
850 data->ps.wp.cy = wp->cy;
851 data->ps.wp.flags = wp->flags;
852 push_data( data, &data->ps.wp, sizeof(data->ps.wp) );
853 return sizeof(data->ps.wp);
857 COPYDATASTRUCT *cds = (COPYDATASTRUCT *)lparam;
858 data->ps.cds.cbData = cds->cbData;
859 data->ps.cds.dwData = cds->dwData;
860 data->ps.cds.lpData = pack_ptr( cds->lpData );
861 push_data( data, &data->ps.cds, sizeof(data->ps.cds) );
862 if (cds->lpData) push_data( data, cds->lpData, cds->cbData );
866 /* WM_NOTIFY cannot be sent across processes (MSDN) */
871 HELPINFO *hi = (HELPINFO *)lparam;
872 data->ps.hi.iContextType = hi->iContextType;
873 data->ps.hi.iCtrlId = hi->iCtrlId;
874 data->ps.hi.hItemHandle = wine_server_user_handle( hi->hItemHandle );
875 data->ps.hi.dwContextId = hi->dwContextId;
876 data->ps.hi.MousePos = hi->MousePos;
877 push_data( data, &data->ps.hi, sizeof(data->ps.hi) );
880 case WM_STYLECHANGING:
881 case WM_STYLECHANGED:
882 push_data( data, (STYLESTRUCT *)lparam, sizeof(STYLESTRUCT) );
887 push_data( data, (RECT *)lparam, sizeof(RECT) );
892 NCCALCSIZE_PARAMS *ncp = (NCCALCSIZE_PARAMS *)lparam;
893 data->ps.ncp.rgrc[0] = ncp->rgrc[0];
894 data->ps.ncp.rgrc[1] = ncp->rgrc[1];
895 data->ps.ncp.rgrc[2] = ncp->rgrc[2];
896 data->ps.ncp.hwnd = wine_server_user_handle( ncp->lppos->hwnd );
897 data->ps.ncp.hwndInsertAfter = wine_server_user_handle( ncp->lppos->hwndInsertAfter );
898 data->ps.ncp.x = ncp->lppos->x;
899 data->ps.ncp.y = ncp->lppos->y;
900 data->ps.ncp.cx = ncp->lppos->cx;
901 data->ps.ncp.cy = ncp->lppos->cy;
902 data->ps.ncp.flags = ncp->lppos->flags;
903 push_data( data, &data->ps.ncp, sizeof(data->ps.ncp) );
904 return sizeof(data->ps.ncp);
909 MSG *msg = (MSG *)lparam;
910 data->ps.msg.hwnd = wine_server_user_handle( msg->hwnd );
911 data->ps.msg.message = msg->message;
912 data->ps.msg.wParam = msg->wParam;
913 data->ps.msg.lParam = msg->lParam;
914 data->ps.msg.time = msg->time;
915 data->ps.msg.pt = msg->pt;
916 push_data( data, &data->ps.msg, sizeof(data->ps.msg) );
917 return sizeof(data->ps.msg);
920 case SBM_SETSCROLLINFO:
921 push_data( data, (SCROLLINFO *)lparam, sizeof(SCROLLINFO) );
923 case SBM_GETSCROLLINFO:
924 push_data( data, (SCROLLINFO *)lparam, sizeof(SCROLLINFO) );
925 return sizeof(SCROLLINFO);
926 case SBM_GETSCROLLBARINFO:
928 const SCROLLBARINFO *info = (const SCROLLBARINFO *)lparam;
929 size_t size = min( info->cbSize, sizeof(SCROLLBARINFO) );
930 push_data( data, info, size );
938 if (wparam) size += sizeof(DWORD);
939 if (lparam) size += sizeof(DWORD);
944 case CB_GETDROPPEDCONTROLRECT:
948 push_data( data, (RECT *)lparam, sizeof(RECT) );
952 WORD *pw = (WORD *)lparam;
953 push_data( data, pw, sizeof(*pw) );
954 return *pw * sizeof(WCHAR);
958 if (wparam) push_data( data, (UINT *)lparam, sizeof(UINT) * wparam );
961 case CB_INSERTSTRING:
963 case CB_FINDSTRINGEXACT:
964 case CB_SELECTSTRING:
965 if (combobox_has_strings( hwnd )) push_string( data, (LPWSTR)lparam );
968 if (!combobox_has_strings( hwnd )) return sizeof(ULONG_PTR);
969 return (SendMessageW( hwnd, CB_GETLBTEXTLEN, wparam, 0 ) + 1) * sizeof(WCHAR);
971 case LB_INSERTSTRING:
973 case LB_FINDSTRINGEXACT:
974 case LB_SELECTSTRING:
975 if (listbox_has_strings( hwnd )) push_string( data, (LPWSTR)lparam );
978 if (!listbox_has_strings( hwnd )) return sizeof(ULONG_PTR);
979 return (SendMessageW( hwnd, LB_GETTEXTLEN, wparam, 0 ) + 1) * sizeof(WCHAR);
981 return wparam * sizeof(UINT);
984 MDINEXTMENU *mnm = (MDINEXTMENU *)lparam;
985 data->ps.mnm.hmenuIn = wine_server_user_handle( mnm->hmenuIn );
986 data->ps.mnm.hmenuNext = wine_server_user_handle( mnm->hmenuNext );
987 data->ps.mnm.hwndNext = wine_server_user_handle( mnm->hwndNext );
988 push_data( data, &data->ps.mnm, sizeof(data->ps.mnm) );
989 return sizeof(data->ps.mnm);
993 push_data( data, (RECT *)lparam, sizeof(RECT) );
997 MDICREATESTRUCTW *mcs = (MDICREATESTRUCTW *)lparam;
998 data->ps.mcs.szClass = pack_ptr( mcs->szClass );
999 data->ps.mcs.szTitle = pack_ptr( mcs->szTitle );
1000 data->ps.mcs.hOwner = pack_ptr( mcs->hOwner );
1001 data->ps.mcs.x = mcs->x;
1002 data->ps.mcs.y = mcs->y;
1003 data->ps.mcs.cx = mcs->cx;
1004 data->ps.mcs.cy = mcs->cy;
1005 data->ps.mcs.style = mcs->style;
1006 data->ps.mcs.lParam = mcs->lParam;
1007 push_data( data, &data->ps.mcs, sizeof(data->ps.mcs) );
1008 if (!IS_INTRESOURCE(mcs->szClass)) push_string( data, mcs->szClass );
1009 if (!IS_INTRESOURCE(mcs->szTitle)) push_string( data, mcs->szTitle );
1010 return sizeof(data->ps.mcs);
1012 case WM_MDIGETACTIVE:
1013 if (lparam) return sizeof(BOOL);
1015 case WM_DEVICECHANGE:
1017 DEV_BROADCAST_HDR *header = (DEV_BROADCAST_HDR *)lparam;
1018 push_data( data, header, header->dbch_size );
1021 case WM_WINE_KEYBOARD_LL_HOOK:
1023 struct hook_extra_info *h_extra = (struct hook_extra_info *)lparam;
1024 data->ps.hook.handle = wine_server_user_handle( h_extra->handle );
1025 push_data( data, &data->ps.hook, sizeof(data->ps.hook) );
1026 push_data( data, (LPVOID)h_extra->lparam, sizeof(KBDLLHOOKSTRUCT) );
1029 case WM_WINE_MOUSE_LL_HOOK:
1031 struct hook_extra_info *h_extra = (struct hook_extra_info *)lparam;
1032 data->ps.hook.handle = wine_server_user_handle( h_extra->handle );
1033 push_data( data, &data->ps.hook, sizeof(data->ps.hook) );
1034 push_data( data, (LPVOID)h_extra->lparam, sizeof(MSLLHOOKSTRUCT) );
1038 if (wparam <= 1) return 0;
1039 FIXME( "WM_NCPAINT hdc packing not supported yet\n" );
1043 if (!wparam) return 0;
1046 /* these contain an HFONT */
1049 /* these contain an HDC */
1051 case WM_ICONERASEBKGND:
1052 case WM_CTLCOLORMSGBOX:
1053 case WM_CTLCOLOREDIT:
1054 case WM_CTLCOLORLISTBOX:
1055 case WM_CTLCOLORBTN:
1056 case WM_CTLCOLORDLG:
1057 case WM_CTLCOLORSCROLLBAR:
1058 case WM_CTLCOLORSTATIC:
1060 case WM_PRINTCLIENT:
1061 /* these contain an HGLOBAL */
1062 case WM_PAINTCLIPBOARD:
1063 case WM_SIZECLIPBOARD:
1064 /* these contain HICON */
1067 case WM_QUERYDRAGICON:
1068 case WM_QUERYPARKICON:
1069 /* these contain pointers */
1071 case WM_QUERYDROPOBJECT:
1075 FIXME( "msg %x (%s) not supported yet\n", message, SPY_GetMsgName(message, hwnd) );
1083 /***********************************************************************
1086 * Unpack a message received from another process.
1088 static BOOL unpack_message( HWND hwnd, UINT message, WPARAM *wparam, LPARAM *lparam,
1089 void **buffer, size_t size )
1092 union packed_structs *ps = *buffer;
1100 WCHAR *str = (WCHAR *)(&ps->cs + 1);
1101 if (size < sizeof(ps->cs)) return FALSE;
1102 size -= sizeof(ps->cs);
1103 cs.lpCreateParams = unpack_ptr( ps->cs.lpCreateParams );
1104 cs.hInstance = unpack_ptr( ps->cs.hInstance );
1105 cs.hMenu = wine_server_ptr_handle( ps->cs.hMenu );
1106 cs.hwndParent = wine_server_ptr_handle( ps->cs.hwndParent );
1111 cs.style = ps->cs.style;
1112 cs.dwExStyle = ps->cs.dwExStyle;
1113 cs.lpszName = unpack_ptr( ps->cs.lpszName );
1114 cs.lpszClass = unpack_ptr( ps->cs.lpszClass );
1115 if (ps->cs.lpszName >> 16)
1117 if (!check_string( str, size )) return FALSE;
1119 size -= (strlenW(str) + 1) * sizeof(WCHAR);
1120 str += strlenW(str) + 1;
1122 if (ps->cs.lpszClass >> 16)
1124 if (!check_string( str, size )) return FALSE;
1127 memcpy( &ps->cs, &cs, sizeof(cs) );
1131 case WM_ASKCBFORMATNAME:
1132 if (!get_buffer_space( buffer, (*wparam * sizeof(WCHAR)) )) return FALSE;
1134 case WM_WININICHANGE:
1135 if (!*lparam) return TRUE;
1138 case WM_DEVMODECHANGE:
1143 if (!check_string( *buffer, size )) return FALSE;
1145 case WM_GETMINMAXINFO:
1146 minsize = sizeof(MINMAXINFO);
1151 if (size < sizeof(ps->dis)) return FALSE;
1152 dis.CtlType = ps->dis.CtlType;
1153 dis.CtlID = ps->dis.CtlID;
1154 dis.itemID = ps->dis.itemID;
1155 dis.itemAction = ps->dis.itemAction;
1156 dis.itemState = ps->dis.itemState;
1157 dis.hwndItem = wine_server_ptr_handle( ps->dis.hwndItem );
1158 dis.hDC = wine_server_ptr_handle( ps->dis.hDC );
1159 dis.rcItem = ps->dis.rcItem;
1160 dis.itemData = (ULONG_PTR)unpack_ptr( ps->dis.itemData );
1161 memcpy( &ps->dis, &dis, sizeof(dis) );
1164 case WM_MEASUREITEM:
1166 MEASUREITEMSTRUCT mis;
1167 if (size < sizeof(ps->mis)) return FALSE;
1168 mis.CtlType = ps->mis.CtlType;
1169 mis.CtlID = ps->mis.CtlID;
1170 mis.itemID = ps->mis.itemID;
1171 mis.itemWidth = ps->mis.itemWidth;
1172 mis.itemHeight = ps->mis.itemHeight;
1173 mis.itemData = (ULONG_PTR)unpack_ptr( ps->mis.itemData );
1174 memcpy( &ps->mis, &mis, sizeof(mis) );
1179 DELETEITEMSTRUCT dls;
1180 if (size < sizeof(ps->dls)) return FALSE;
1181 dls.CtlType = ps->dls.CtlType;
1182 dls.CtlID = ps->dls.CtlID;
1183 dls.itemID = ps->dls.itemID;
1184 dls.hwndItem = wine_server_ptr_handle( ps->dls.hwndItem );
1185 dls.itemData = (ULONG_PTR)unpack_ptr( ps->dls.itemData );
1186 memcpy( &ps->dls, &dls, sizeof(dls) );
1189 case WM_COMPAREITEM:
1191 COMPAREITEMSTRUCT cis;
1192 if (size < sizeof(ps->cis)) return FALSE;
1193 cis.CtlType = ps->cis.CtlType;
1194 cis.CtlID = ps->cis.CtlID;
1195 cis.hwndItem = wine_server_ptr_handle( ps->cis.hwndItem );
1196 cis.itemID1 = ps->cis.itemID1;
1197 cis.itemData1 = (ULONG_PTR)unpack_ptr( ps->cis.itemData1 );
1198 cis.itemID2 = ps->cis.itemID2;
1199 cis.itemData2 = (ULONG_PTR)unpack_ptr( ps->cis.itemData2 );
1200 cis.dwLocaleId = ps->cis.dwLocaleId;
1201 memcpy( &ps->cis, &cis, sizeof(cis) );
1204 case WM_WINDOWPOSCHANGING:
1205 case WM_WINDOWPOSCHANGED:
1206 case WM_WINE_SETWINDOWPOS:
1209 if (size < sizeof(ps->wp)) return FALSE;
1210 wp.hwnd = wine_server_ptr_handle( ps->wp.hwnd );
1211 wp.hwndInsertAfter = wine_server_ptr_handle( ps->wp.hwndInsertAfter );
1216 wp.flags = ps->wp.flags;
1217 memcpy( &ps->wp, &wp, sizeof(wp) );
1223 if (size < sizeof(ps->cds)) return FALSE;
1224 cds.dwData = (ULONG_PTR)unpack_ptr( ps->cds.dwData );
1227 cds.cbData = ps->cds.cbData;
1228 cds.lpData = &ps->cds + 1;
1229 minsize = sizeof(ps->cds) + cds.cbData;
1236 memcpy( &ps->cds, &cds, sizeof(cds) );
1240 /* WM_NOTIFY cannot be sent across processes (MSDN) */
1245 if (size < sizeof(ps->hi)) return FALSE;
1246 hi.cbSize = sizeof(hi);
1247 hi.iContextType = ps->hi.iContextType;
1248 hi.iCtrlId = ps->hi.iCtrlId;
1249 hi.hItemHandle = wine_server_ptr_handle( ps->hi.hItemHandle );
1250 hi.dwContextId = (ULONG_PTR)unpack_ptr( ps->hi.dwContextId );
1251 hi.MousePos = ps->hi.MousePos;
1252 memcpy( &ps->hi, &hi, sizeof(hi) );
1255 case WM_STYLECHANGING:
1256 case WM_STYLECHANGED:
1257 minsize = sizeof(STYLESTRUCT);
1260 if (!*wparam) minsize = sizeof(RECT);
1263 NCCALCSIZE_PARAMS ncp;
1265 if (size < sizeof(ps->ncp)) return FALSE;
1266 ncp.rgrc[0] = ps->ncp.rgrc[0];
1267 ncp.rgrc[1] = ps->ncp.rgrc[1];
1268 ncp.rgrc[2] = ps->ncp.rgrc[2];
1269 wp.hwnd = wine_server_ptr_handle( ps->ncp.hwnd );
1270 wp.hwndInsertAfter = wine_server_ptr_handle( ps->ncp.hwndInsertAfter );
1275 wp.flags = ps->ncp.flags;
1276 ncp.lppos = (WINDOWPOS *)((NCCALCSIZE_PARAMS *)&ps->ncp + 1);
1277 memcpy( &ps->ncp, &ncp, sizeof(ncp) );
1285 if (size < sizeof(ps->msg)) return FALSE;
1286 msg.hwnd = wine_server_ptr_handle( ps->msg.hwnd );
1287 msg.message = ps->msg.message;
1288 msg.wParam = (ULONG_PTR)unpack_ptr( ps->msg.wParam );
1289 msg.lParam = (ULONG_PTR)unpack_ptr( ps->msg.lParam );
1290 msg.time = ps->msg.time;
1291 msg.pt = ps->msg.pt;
1292 memcpy( &ps->msg, &msg, sizeof(msg) );
1296 case SBM_SETSCROLLINFO:
1297 minsize = sizeof(SCROLLINFO);
1299 case SBM_GETSCROLLINFO:
1300 if (!get_buffer_space( buffer, sizeof(SCROLLINFO ))) return FALSE;
1302 case SBM_GETSCROLLBARINFO:
1303 if (!get_buffer_space( buffer, sizeof(SCROLLBARINFO ))) return FALSE;
1308 if (*wparam || *lparam)
1310 if (!get_buffer_space( buffer, 2*sizeof(DWORD) )) return FALSE;
1311 if (*wparam) *wparam = (WPARAM)*buffer;
1312 if (*lparam) *lparam = (LPARAM)((DWORD *)*buffer + 1);
1316 case LB_GETITEMRECT:
1317 case CB_GETDROPPEDCONTROLRECT:
1318 if (!get_buffer_space( buffer, sizeof(RECT) )) return FALSE;
1322 minsize = sizeof(RECT);
1327 if (size < sizeof(WORD)) return FALSE;
1328 len = *(WORD *)*buffer;
1329 if (!get_buffer_space( buffer, (len + 1) * sizeof(WCHAR) )) return FALSE;
1330 *lparam = (LPARAM)*buffer + sizeof(WORD); /* don't erase WORD at start of buffer */
1333 case EM_SETTABSTOPS:
1334 case LB_SETTABSTOPS:
1335 if (!*wparam) return TRUE;
1336 minsize = *wparam * sizeof(UINT);
1339 case CB_INSERTSTRING:
1341 case CB_FINDSTRINGEXACT:
1342 case CB_SELECTSTRING:
1344 case LB_INSERTSTRING:
1346 case LB_FINDSTRINGEXACT:
1347 case LB_SELECTSTRING:
1348 if (!*buffer) return TRUE;
1349 if (!check_string( *buffer, size )) return FALSE;
1353 size = sizeof(ULONG_PTR);
1354 if (combobox_has_strings( hwnd ))
1355 size = (SendMessageW( hwnd, CB_GETLBTEXTLEN, *wparam, 0 ) + 1) * sizeof(WCHAR);
1356 if (!get_buffer_space( buffer, size )) return FALSE;
1361 size = sizeof(ULONG_PTR);
1362 if (listbox_has_strings( hwnd ))
1363 size = (SendMessageW( hwnd, LB_GETTEXTLEN, *wparam, 0 ) + 1) * sizeof(WCHAR);
1364 if (!get_buffer_space( buffer, size )) return FALSE;
1367 case LB_GETSELITEMS:
1368 if (!get_buffer_space( buffer, *wparam * sizeof(UINT) )) return FALSE;
1373 if (size < sizeof(ps->mnm)) return FALSE;
1374 mnm.hmenuIn = wine_server_ptr_handle( ps->mnm.hmenuIn );
1375 mnm.hmenuNext = wine_server_ptr_handle( ps->mnm.hmenuNext );
1376 mnm.hwndNext = wine_server_ptr_handle( ps->mnm.hwndNext );
1377 memcpy( &ps->mnm, &mnm, sizeof(mnm) );
1382 minsize = sizeof(RECT);
1383 if (!get_buffer_space( buffer, sizeof(RECT) )) return FALSE;
1387 MDICREATESTRUCTW mcs;
1388 WCHAR *str = (WCHAR *)(&ps->mcs + 1);
1389 if (size < sizeof(ps->mcs)) return FALSE;
1390 size -= sizeof(ps->mcs);
1392 mcs.szClass = unpack_ptr( ps->mcs.szClass );
1393 mcs.szTitle = unpack_ptr( ps->mcs.szTitle );
1394 mcs.hOwner = unpack_ptr( ps->mcs.hOwner );
1397 mcs.cx = ps->mcs.cx;
1398 mcs.cy = ps->mcs.cy;
1399 mcs.style = ps->mcs.style;
1400 mcs.lParam = (LPARAM)unpack_ptr( ps->mcs.lParam );
1401 if (ps->mcs.szClass >> 16)
1403 if (!check_string( str, size )) return FALSE;
1405 size -= (strlenW(str) + 1) * sizeof(WCHAR);
1406 str += strlenW(str) + 1;
1408 if (ps->mcs.szTitle >> 16)
1410 if (!check_string( str, size )) return FALSE;
1413 memcpy( &ps->mcs, &mcs, sizeof(mcs) );
1416 case WM_MDIGETACTIVE:
1417 if (!*lparam) return TRUE;
1418 if (!get_buffer_space( buffer, sizeof(BOOL) )) return FALSE;
1420 case WM_DEVICECHANGE:
1421 minsize = sizeof(DEV_BROADCAST_HDR);
1423 case WM_WINE_KEYBOARD_LL_HOOK:
1424 case WM_WINE_MOUSE_LL_HOOK:
1426 struct hook_extra_info h_extra;
1427 minsize = sizeof(ps->hook) +
1428 (message == WM_WINE_KEYBOARD_LL_HOOK ? sizeof(KBDLLHOOKSTRUCT)
1429 : sizeof(MSLLHOOKSTRUCT));
1430 if (size < minsize) return FALSE;
1431 h_extra.handle = wine_server_ptr_handle( ps->hook.handle );
1432 h_extra.lparam = (LPARAM)(&ps->hook + 1);
1433 memcpy( &ps->hook, &h_extra, sizeof(h_extra) );
1437 if (*wparam <= 1) return TRUE;
1438 FIXME( "WM_NCPAINT hdc unpacking not supported\n" );
1441 if (!*wparam) return TRUE;
1444 /* these contain an HFONT */
1447 /* these contain an HDC */
1449 case WM_ICONERASEBKGND:
1450 case WM_CTLCOLORMSGBOX:
1451 case WM_CTLCOLOREDIT:
1452 case WM_CTLCOLORLISTBOX:
1453 case WM_CTLCOLORBTN:
1454 case WM_CTLCOLORDLG:
1455 case WM_CTLCOLORSCROLLBAR:
1456 case WM_CTLCOLORSTATIC:
1458 case WM_PRINTCLIENT:
1459 /* these contain an HGLOBAL */
1460 case WM_PAINTCLIPBOARD:
1461 case WM_SIZECLIPBOARD:
1462 /* these contain HICON */
1465 case WM_QUERYDRAGICON:
1466 case WM_QUERYPARKICON:
1467 /* these contain pointers */
1469 case WM_QUERYDROPOBJECT:
1473 FIXME( "msg %x (%s) not supported yet\n", message, SPY_GetMsgName(message, hwnd) );
1477 return TRUE; /* message doesn't need any unpacking */
1480 /* default exit for most messages: check minsize and store buffer in lparam */
1481 if (size < minsize) return FALSE;
1482 *lparam = (LPARAM)*buffer;
1487 /***********************************************************************
1490 * Pack a reply to a message for sending to another process.
1492 static void pack_reply( HWND hwnd, UINT message, WPARAM wparam, LPARAM lparam,
1493 LRESULT res, struct packed_message *data )
1501 CREATESTRUCTW *cs = (CREATESTRUCTW *)lparam;
1502 data->ps.cs.lpCreateParams = (ULONG_PTR)cs->lpCreateParams;
1503 data->ps.cs.hInstance = (ULONG_PTR)cs->hInstance;
1504 data->ps.cs.hMenu = wine_server_user_handle( cs->hMenu );
1505 data->ps.cs.hwndParent = wine_server_user_handle( cs->hwndParent );
1506 data->ps.cs.cy = cs->cy;
1507 data->ps.cs.cx = cs->cx;
1508 data->ps.cs.y = cs->y;
1509 data->ps.cs.x = cs->x;
1510 data->ps.cs.style = cs->style;
1511 data->ps.cs.dwExStyle = cs->dwExStyle;
1512 data->ps.cs.lpszName = (ULONG_PTR)cs->lpszName;
1513 data->ps.cs.lpszClass = (ULONG_PTR)cs->lpszClass;
1514 push_data( data, &data->ps.cs, sizeof(data->ps.cs) );
1520 push_data( data, (WCHAR *)lparam, (res + 1) * sizeof(WCHAR) );
1522 case WM_GETMINMAXINFO:
1523 push_data( data, (MINMAXINFO *)lparam, sizeof(MINMAXINFO) );
1525 case WM_MEASUREITEM:
1527 MEASUREITEMSTRUCT *mis = (MEASUREITEMSTRUCT *)lparam;
1528 data->ps.mis.CtlType = mis->CtlType;
1529 data->ps.mis.CtlID = mis->CtlID;
1530 data->ps.mis.itemID = mis->itemID;
1531 data->ps.mis.itemWidth = mis->itemWidth;
1532 data->ps.mis.itemHeight = mis->itemHeight;
1533 data->ps.mis.itemData = mis->itemData;
1534 push_data( data, &data->ps.mis, sizeof(data->ps.mis) );
1537 case WM_WINDOWPOSCHANGING:
1538 case WM_WINDOWPOSCHANGED:
1540 WINDOWPOS *wp = (WINDOWPOS *)lparam;
1541 data->ps.wp.hwnd = wine_server_user_handle( wp->hwnd );
1542 data->ps.wp.hwndInsertAfter = wine_server_user_handle( wp->hwndInsertAfter );
1543 data->ps.wp.x = wp->x;
1544 data->ps.wp.y = wp->y;
1545 data->ps.wp.cx = wp->cx;
1546 data->ps.wp.cy = wp->cy;
1547 data->ps.wp.flags = wp->flags;
1548 push_data( data, &data->ps.wp, sizeof(data->ps.wp) );
1554 MSG *msg = (MSG *)lparam;
1555 data->ps.msg.hwnd = wine_server_user_handle( msg->hwnd );
1556 data->ps.msg.message = msg->message;
1557 data->ps.msg.wParam = msg->wParam;
1558 data->ps.msg.lParam = msg->lParam;
1559 data->ps.msg.time = msg->time;
1560 data->ps.msg.pt = msg->pt;
1561 push_data( data, &data->ps.msg, sizeof(data->ps.msg) );
1564 case SBM_GETSCROLLINFO:
1565 push_data( data, (SCROLLINFO *)lparam, sizeof(SCROLLINFO) );
1568 case LB_GETITEMRECT:
1569 case CB_GETDROPPEDCONTROLRECT:
1572 push_data( data, (RECT *)lparam, sizeof(RECT) );
1576 WORD *ptr = (WORD *)lparam;
1577 push_data( data, ptr, ptr[-1] * sizeof(WCHAR) );
1580 case LB_GETSELITEMS:
1581 push_data( data, (UINT *)lparam, wparam * sizeof(UINT) );
1583 case WM_MDIGETACTIVE:
1584 if (lparam) push_data( data, (BOOL *)lparam, sizeof(BOOL) );
1588 push_data( data, (RECT *)lparam, sizeof(RECT) );
1591 NCCALCSIZE_PARAMS *ncp = (NCCALCSIZE_PARAMS *)lparam;
1592 data->ps.ncp.rgrc[0] = ncp->rgrc[0];
1593 data->ps.ncp.rgrc[1] = ncp->rgrc[1];
1594 data->ps.ncp.rgrc[2] = ncp->rgrc[2];
1595 data->ps.ncp.hwnd = wine_server_user_handle( ncp->lppos->hwnd );
1596 data->ps.ncp.hwndInsertAfter = wine_server_user_handle( ncp->lppos->hwndInsertAfter );
1597 data->ps.ncp.x = ncp->lppos->x;
1598 data->ps.ncp.y = ncp->lppos->y;
1599 data->ps.ncp.cx = ncp->lppos->cx;
1600 data->ps.ncp.cy = ncp->lppos->cy;
1601 data->ps.ncp.flags = ncp->lppos->flags;
1602 push_data( data, &data->ps.ncp, sizeof(data->ps.ncp) );
1608 if (wparam) push_data( data, (DWORD *)wparam, sizeof(DWORD) );
1609 if (lparam) push_data( data, (DWORD *)lparam, sizeof(DWORD) );
1613 MDINEXTMENU *mnm = (MDINEXTMENU *)lparam;
1614 data->ps.mnm.hmenuIn = wine_server_user_handle( mnm->hmenuIn );
1615 data->ps.mnm.hmenuNext = wine_server_user_handle( mnm->hmenuNext );
1616 data->ps.mnm.hwndNext = wine_server_user_handle( mnm->hwndNext );
1617 push_data( data, &data->ps.mnm, sizeof(data->ps.mnm) );
1622 MDICREATESTRUCTW *mcs = (MDICREATESTRUCTW *)lparam;
1623 data->ps.mcs.szClass = pack_ptr( mcs->szClass );
1624 data->ps.mcs.szTitle = pack_ptr( mcs->szTitle );
1625 data->ps.mcs.hOwner = pack_ptr( mcs->hOwner );
1626 data->ps.mcs.x = mcs->x;
1627 data->ps.mcs.y = mcs->y;
1628 data->ps.mcs.cx = mcs->cx;
1629 data->ps.mcs.cy = mcs->cy;
1630 data->ps.mcs.style = mcs->style;
1631 data->ps.mcs.lParam = mcs->lParam;
1632 push_data( data, &data->ps.mcs, sizeof(data->ps.mcs) );
1635 case WM_ASKCBFORMATNAME:
1636 push_data( data, (WCHAR *)lparam, (strlenW((WCHAR *)lparam) + 1) * sizeof(WCHAR) );
1642 /***********************************************************************
1645 * Unpack a message reply received from another process.
1647 static void unpack_reply( HWND hwnd, UINT message, WPARAM wparam, LPARAM lparam,
1648 void *buffer, size_t size )
1650 union packed_structs *ps = buffer;
1656 if (size >= sizeof(ps->cs))
1658 CREATESTRUCTW *cs = (CREATESTRUCTW *)lparam;
1659 cs->lpCreateParams = unpack_ptr( ps->cs.lpCreateParams );
1660 cs->hInstance = unpack_ptr( ps->cs.hInstance );
1661 cs->hMenu = wine_server_ptr_handle( ps->cs.hMenu );
1662 cs->hwndParent = wine_server_ptr_handle( ps->cs.hwndParent );
1667 cs->style = ps->cs.style;
1668 cs->dwExStyle = ps->cs.dwExStyle;
1669 /* don't allow changing name and class pointers */
1673 case WM_ASKCBFORMATNAME:
1674 memcpy( (WCHAR *)lparam, buffer, min( wparam*sizeof(WCHAR), size ));
1676 case WM_GETMINMAXINFO:
1677 memcpy( (MINMAXINFO *)lparam, buffer, min( sizeof(MINMAXINFO), size ));
1679 case WM_MEASUREITEM:
1680 if (size >= sizeof(ps->mis))
1682 MEASUREITEMSTRUCT *mis = (MEASUREITEMSTRUCT *)lparam;
1683 mis->CtlType = ps->mis.CtlType;
1684 mis->CtlID = ps->mis.CtlID;
1685 mis->itemID = ps->mis.itemID;
1686 mis->itemWidth = ps->mis.itemWidth;
1687 mis->itemHeight = ps->mis.itemHeight;
1688 mis->itemData = (ULONG_PTR)unpack_ptr( ps->mis.itemData );
1691 case WM_WINDOWPOSCHANGING:
1692 case WM_WINDOWPOSCHANGED:
1693 if (size >= sizeof(ps->wp))
1695 WINDOWPOS *wp = (WINDOWPOS *)lparam;
1696 wp->hwnd = wine_server_ptr_handle( ps->wp.hwnd );
1697 wp->hwndInsertAfter = wine_server_ptr_handle( ps->wp.hwndInsertAfter );
1702 wp->flags = ps->wp.flags;
1706 if (lparam && size >= sizeof(ps->msg))
1708 MSG *msg = (MSG *)lparam;
1709 msg->hwnd = wine_server_ptr_handle( ps->msg.hwnd );
1710 msg->message = ps->msg.message;
1711 msg->wParam = (ULONG_PTR)unpack_ptr( ps->msg.wParam );
1712 msg->lParam = (ULONG_PTR)unpack_ptr( ps->msg.lParam );
1713 msg->time = ps->msg.time;
1714 msg->pt = ps->msg.pt;
1717 case SBM_GETSCROLLINFO:
1718 memcpy( (SCROLLINFO *)lparam, buffer, min( sizeof(SCROLLINFO), size ));
1720 case SBM_GETSCROLLBARINFO:
1721 memcpy( (SCROLLBARINFO *)lparam, buffer, min( sizeof(SCROLLBARINFO), size ));
1724 case CB_GETDROPPEDCONTROLRECT:
1725 case LB_GETITEMRECT:
1728 memcpy( (RECT *)lparam, buffer, min( sizeof(RECT), size ));
1731 size = min( size, (size_t)*(WORD *)lparam );
1732 memcpy( (WCHAR *)lparam, buffer, size );
1734 case LB_GETSELITEMS:
1735 memcpy( (UINT *)lparam, buffer, min( wparam*sizeof(UINT), size ));
1739 memcpy( (WCHAR *)lparam, buffer, size );
1742 if (size >= sizeof(ps->mnm))
1744 MDINEXTMENU *mnm = (MDINEXTMENU *)lparam;
1745 mnm->hmenuIn = wine_server_ptr_handle( ps->mnm.hmenuIn );
1746 mnm->hmenuNext = wine_server_ptr_handle( ps->mnm.hmenuNext );
1747 mnm->hwndNext = wine_server_ptr_handle( ps->mnm.hwndNext );
1750 case WM_MDIGETACTIVE:
1751 if (lparam) memcpy( (BOOL *)lparam, buffer, min( sizeof(BOOL), size ));
1755 memcpy( (RECT *)lparam, buffer, min( sizeof(RECT), size ));
1756 else if (size >= sizeof(ps->ncp))
1758 NCCALCSIZE_PARAMS *ncp = (NCCALCSIZE_PARAMS *)lparam;
1759 ncp->rgrc[0] = ps->ncp.rgrc[0];
1760 ncp->rgrc[1] = ps->ncp.rgrc[1];
1761 ncp->rgrc[2] = ps->ncp.rgrc[2];
1762 ncp->lppos->hwnd = wine_server_ptr_handle( ps->ncp.hwnd );
1763 ncp->lppos->hwndInsertAfter = wine_server_ptr_handle( ps->ncp.hwndInsertAfter );
1764 ncp->lppos->x = ps->ncp.x;
1765 ncp->lppos->y = ps->ncp.y;
1766 ncp->lppos->cx = ps->ncp.cx;
1767 ncp->lppos->cy = ps->ncp.cy;
1768 ncp->lppos->flags = ps->ncp.flags;
1776 memcpy( (DWORD *)wparam, buffer, min( sizeof(DWORD), size ));
1777 if (size <= sizeof(DWORD)) break;
1778 size -= sizeof(DWORD);
1779 buffer = (DWORD *)buffer + 1;
1781 if (lparam) memcpy( (DWORD *)lparam, buffer, min( sizeof(DWORD), size ));
1784 if (size >= sizeof(ps->mcs))
1786 MDICREATESTRUCTW *mcs = (MDICREATESTRUCTW *)lparam;
1787 mcs->hOwner = unpack_ptr( ps->mcs.hOwner );
1790 mcs->cx = ps->mcs.cx;
1791 mcs->cy = ps->mcs.cy;
1792 mcs->style = ps->mcs.style;
1793 mcs->lParam = (LPARAM)unpack_ptr( ps->mcs.lParam );
1794 /* don't allow changing class and title pointers */
1798 ERR( "should not happen: unexpected message %x\n", message );
1804 /***********************************************************************
1807 * Send a reply to a sent message.
1809 static void reply_message( struct received_message_info *info, LRESULT result, BOOL remove )
1811 struct packed_message data;
1812 int i, replied = info->flags & ISMEX_REPLIED;
1814 if (info->flags & ISMEX_NOTIFY) return; /* notify messages don't get replies */
1815 if (!remove && replied) return; /* replied already */
1817 memset( &data, 0, sizeof(data) );
1818 info->flags |= ISMEX_REPLIED;
1820 if (info->type == MSG_OTHER_PROCESS && !replied)
1822 pack_reply( info->msg.hwnd, info->msg.message, info->msg.wParam,
1823 info->msg.lParam, result, &data );
1826 SERVER_START_REQ( reply_message )
1828 req->result = result;
1829 req->remove = remove;
1830 for (i = 0; i < data.count; i++) wine_server_add_data( req, data.data[i], data.size[i] );
1831 wine_server_call( req );
1837 /***********************************************************************
1838 * handle_internal_message
1840 * Handle an internal Wine message instead of calling the window proc.
1842 static LRESULT handle_internal_message( HWND hwnd, UINT msg, WPARAM wparam, LPARAM lparam )
1846 case WM_WINE_DESTROYWINDOW:
1847 return WIN_DestroyWindow( hwnd );
1848 case WM_WINE_SETWINDOWPOS:
1849 if (is_desktop_window( hwnd )) return 0;
1850 return USER_SetWindowPos( (WINDOWPOS *)lparam );
1851 case WM_WINE_SHOWWINDOW:
1852 if (is_desktop_window( hwnd )) return 0;
1853 return ShowWindow( hwnd, wparam );
1854 case WM_WINE_SETPARENT:
1855 if (is_desktop_window( hwnd )) return 0;
1856 return (LRESULT)SetParent( hwnd, (HWND)wparam );
1857 case WM_WINE_SETWINDOWLONG:
1858 return WIN_SetWindowLong( hwnd, (short)LOWORD(wparam), HIWORD(wparam), lparam, TRUE );
1859 case WM_WINE_ENABLEWINDOW:
1860 if (is_desktop_window( hwnd )) return 0;
1861 return EnableWindow( hwnd, wparam );
1862 case WM_WINE_SETACTIVEWINDOW:
1863 if (is_desktop_window( hwnd )) return 0;
1864 return (LRESULT)SetActiveWindow( (HWND)wparam );
1865 case WM_WINE_KEYBOARD_LL_HOOK:
1866 case WM_WINE_MOUSE_LL_HOOK:
1868 struct hook_extra_info *h_extra = (struct hook_extra_info *)lparam;
1870 return call_current_hook( h_extra->handle, HC_ACTION, wparam, h_extra->lparam );
1872 case WM_WINE_CLIPCURSOR:
1875 GetClipCursor( &rect );
1876 return USER_Driver->pClipCursor( &rect );
1879 if (msg >= WM_WINE_FIRST_DRIVER_MSG && msg <= WM_WINE_LAST_DRIVER_MSG)
1880 return USER_Driver->pWindowMessage( hwnd, msg, wparam, lparam );
1881 FIXME( "unknown internal message %x\n", msg );
1886 /* since the WM_DDE_ACK response to a WM_DDE_EXECUTE message should contain the handle
1887 * to the memory handle, we keep track (in the server side) of all pairs of handle
1888 * used (the client passes its value and the content of the memory handle), and
1889 * the server stored both values (the client, and the local one, created after the
1890 * content). When a ACK message is generated, the list of pair is searched for a
1891 * matching pair, so that the client memory handle can be returned.
1894 HGLOBAL client_hMem;
1895 HGLOBAL server_hMem;
1898 static struct DDE_pair* dde_pairs;
1899 static int dde_num_alloc;
1900 static int dde_num_used;
1902 static CRITICAL_SECTION dde_crst;
1903 static CRITICAL_SECTION_DEBUG critsect_debug =
1906 { &critsect_debug.ProcessLocksList, &critsect_debug.ProcessLocksList },
1907 0, 0, { (DWORD_PTR)(__FILE__ ": dde_crst") }
1909 static CRITICAL_SECTION dde_crst = { &critsect_debug, -1, 0, 0, 0, 0 };
1911 static BOOL dde_add_pair(HGLOBAL chm, HGLOBAL shm)
1916 EnterCriticalSection(&dde_crst);
1918 /* now remember the pair of hMem on both sides */
1919 if (dde_num_used == dde_num_alloc)
1921 struct DDE_pair* tmp;
1923 tmp = HeapReAlloc( GetProcessHeap(), 0, dde_pairs,
1924 (dde_num_alloc + GROWBY) * sizeof(struct DDE_pair));
1926 tmp = HeapAlloc( GetProcessHeap(), 0,
1927 (dde_num_alloc + GROWBY) * sizeof(struct DDE_pair));
1931 LeaveCriticalSection(&dde_crst);
1935 /* zero out newly allocated part */
1936 memset(&dde_pairs[dde_num_alloc], 0, GROWBY * sizeof(struct DDE_pair));
1937 dde_num_alloc += GROWBY;
1940 for (i = 0; i < dde_num_alloc; i++)
1942 if (dde_pairs[i].server_hMem == 0)
1944 dde_pairs[i].client_hMem = chm;
1945 dde_pairs[i].server_hMem = shm;
1950 LeaveCriticalSection(&dde_crst);
1954 static HGLOBAL dde_get_pair(HGLOBAL shm)
1959 EnterCriticalSection(&dde_crst);
1960 for (i = 0; i < dde_num_alloc; i++)
1962 if (dde_pairs[i].server_hMem == shm)
1964 /* free this pair */
1965 dde_pairs[i].server_hMem = 0;
1967 ret = dde_pairs[i].client_hMem;
1971 LeaveCriticalSection(&dde_crst);
1975 /***********************************************************************
1978 * Post a DDE message
1980 static BOOL post_dde_message( struct packed_message *data, const struct send_message_info *info )
1984 UINT_PTR uiLo, uiHi;
1986 HGLOBAL hunlock = 0;
1990 if (!UnpackDDElParam( info->msg, info->lparam, &uiLo, &uiHi ))
1996 /* DDE messages which don't require packing are:
2005 /* uiHi should contain a hMem from WM_DDE_EXECUTE */
2006 HGLOBAL h = dde_get_pair( (HANDLE)uiHi );
2009 ULONGLONG hpack = pack_ptr( h );
2010 /* send back the value of h on the other side */
2011 push_data( data, &hpack, sizeof(hpack) );
2013 TRACE( "send dde-ack %lx %08lx => %p\n", uiLo, uiHi, h );
2018 /* uiHi should contain either an atom or 0 */
2019 TRACE( "send dde-ack %lx atom=%lx\n", uiLo, uiHi );
2020 lp = MAKELONG( uiLo, uiHi );
2029 size = GlobalSize( (HGLOBAL)uiLo ) ;
2030 if ((info->msg == WM_DDE_ADVISE && size < sizeof(DDEADVISE)) ||
2031 (info->msg == WM_DDE_DATA && size < FIELD_OFFSET(DDEDATA, Value)) ||
2032 (info->msg == WM_DDE_POKE && size < FIELD_OFFSET(DDEPOKE, Value))
2036 else if (info->msg != WM_DDE_DATA) return FALSE;
2041 if ((ptr = GlobalLock( (HGLOBAL)uiLo) ))
2043 DDEDATA *dde_data = ptr;
2044 TRACE("unused %d, fResponse %d, fRelease %d, fDeferUpd %d, fAckReq %d, cfFormat %d\n",
2045 dde_data->unused, dde_data->fResponse, dde_data->fRelease,
2046 dde_data->reserved, dde_data->fAckReq, dde_data->cfFormat);
2047 push_data( data, ptr, size );
2048 hunlock = (HGLOBAL)uiLo;
2051 TRACE( "send ddepack %u %lx\n", size, uiHi );
2053 case WM_DDE_EXECUTE:
2056 if ((ptr = GlobalLock( (HGLOBAL)info->lparam) ))
2058 push_data(data, ptr, GlobalSize( (HGLOBAL)info->lparam ));
2059 /* so that the other side can send it back on ACK */
2061 hunlock = (HGLOBAL)info->lparam;
2066 SERVER_START_REQ( send_message )
2068 req->id = info->dest_tid;
2069 req->type = info->type;
2071 req->win = wine_server_user_handle( info->hwnd );
2072 req->msg = info->msg;
2073 req->wparam = info->wparam;
2075 req->timeout = TIMEOUT_INFINITE;
2076 for (i = 0; i < data->count; i++)
2077 wine_server_add_data( req, data->data[i], data->size[i] );
2078 if ((res = wine_server_call( req )))
2080 if (res == STATUS_INVALID_PARAMETER)
2081 /* FIXME: find a STATUS_ value for this one */
2082 SetLastError( ERROR_INVALID_THREAD_ID );
2084 SetLastError( RtlNtStatusToDosError(res) );
2087 FreeDDElParam(info->msg, info->lparam);
2090 if (hunlock) GlobalUnlock(hunlock);
2095 /***********************************************************************
2096 * unpack_dde_message
2098 * Unpack a posted DDE message received from another process.
2100 static BOOL unpack_dde_message( HWND hwnd, UINT message, WPARAM *wparam, LPARAM *lparam,
2101 void **buffer, size_t size )
2103 UINT_PTR uiLo, uiHi;
2113 /* hMem is being passed */
2114 if (size != sizeof(hpack)) return FALSE;
2115 if (!buffer || !*buffer) return FALSE;
2117 memcpy( &hpack, *buffer, size );
2118 hMem = unpack_ptr( hpack );
2119 uiHi = (UINT_PTR)hMem;
2120 TRACE("recv dde-ack %lx mem=%lx[%lx]\n", uiLo, uiHi, GlobalSize( hMem ));
2124 uiLo = LOWORD( *lparam );
2125 uiHi = HIWORD( *lparam );
2126 TRACE("recv dde-ack %lx atom=%lx\n", uiLo, uiHi);
2128 *lparam = PackDDElParam( WM_DDE_ACK, uiLo, uiHi );
2133 if ((!buffer || !*buffer) && message != WM_DDE_DATA) return FALSE;
2137 if (!(hMem = GlobalAlloc( GMEM_MOVEABLE|GMEM_DDESHARE, size )))
2139 if ((ptr = GlobalLock( hMem )))
2141 memcpy( ptr, *buffer, size );
2142 GlobalUnlock( hMem );
2150 uiLo = (UINT_PTR)hMem;
2152 *lparam = PackDDElParam( message, uiLo, uiHi );
2154 case WM_DDE_EXECUTE:
2157 if (!buffer || !*buffer) return FALSE;
2158 if (!(hMem = GlobalAlloc( GMEM_MOVEABLE|GMEM_DDESHARE, size ))) return FALSE;
2159 if ((ptr = GlobalLock( hMem )))
2161 memcpy( ptr, *buffer, size );
2162 GlobalUnlock( hMem );
2163 TRACE( "exec: pairing c=%08lx s=%p\n", *lparam, hMem );
2164 if (!dde_add_pair( (HGLOBAL)*lparam, hMem ))
2175 } else return FALSE;
2176 *lparam = (LPARAM)hMem;
2182 /***********************************************************************
2185 * Call a window procedure and the corresponding hooks.
2187 static LRESULT call_window_proc( HWND hwnd, UINT msg, WPARAM wparam, LPARAM lparam,
2188 BOOL unicode, BOOL same_thread, enum wm_char_mapping mapping )
2192 CWPRETSTRUCT cwpret;
2194 if (msg & 0x80000000)
2196 result = handle_internal_message( hwnd, msg, wparam, lparam );
2200 /* first the WH_CALLWNDPROC hook */
2201 hwnd = WIN_GetFullHandle( hwnd );
2202 cwp.lParam = lparam;
2203 cwp.wParam = wparam;
2206 HOOK_CallHooks( WH_CALLWNDPROC, HC_ACTION, same_thread, (LPARAM)&cwp, unicode );
2208 /* now call the window procedure */
2209 if (!WINPROC_call_window( hwnd, msg, wparam, lparam, &result, unicode, mapping )) goto done;
2211 /* and finally the WH_CALLWNDPROCRET hook */
2212 cwpret.lResult = result;
2213 cwpret.lParam = lparam;
2214 cwpret.wParam = wparam;
2215 cwpret.message = msg;
2217 HOOK_CallHooks( WH_CALLWNDPROCRET, HC_ACTION, same_thread, (LPARAM)&cwpret, unicode );
2223 /***********************************************************************
2224 * send_parent_notify
2226 * Send a WM_PARENTNOTIFY to all ancestors of the given window, unless
2227 * the window has the WS_EX_NOPARENTNOTIFY style.
2229 static void send_parent_notify( HWND hwnd, WORD event, WORD idChild, POINT pt )
2231 /* pt has to be in the client coordinates of the parent window */
2232 MapWindowPoints( 0, hwnd, &pt, 1 );
2237 if (!(GetWindowLongW( hwnd, GWL_STYLE ) & WS_CHILD)) break;
2238 if (GetWindowLongW( hwnd, GWL_EXSTYLE ) & WS_EX_NOPARENTNOTIFY) break;
2239 if (!(parent = GetParent(hwnd))) break;
2240 if (parent == GetDesktopWindow()) break;
2241 MapWindowPoints( hwnd, parent, &pt, 1 );
2243 SendMessageW( hwnd, WM_PARENTNOTIFY,
2244 MAKEWPARAM( event, idChild ), MAKELPARAM( pt.x, pt.y ) );
2249 /***********************************************************************
2250 * accept_hardware_message
2252 * Tell the server we have passed the message to the app
2253 * (even though we may end up dropping it later on)
2255 static void accept_hardware_message( UINT hw_id, BOOL remove, HWND new_hwnd )
2257 SERVER_START_REQ( accept_hardware_message )
2260 req->remove = remove;
2261 req->new_win = wine_server_user_handle( new_hwnd );
2262 if (wine_server_call( req ))
2263 FIXME("Failed to reply to MSG_HARDWARE message. Message may not be removed from queue.\n");
2269 /***********************************************************************
2270 * process_keyboard_message
2272 * returns TRUE if the contents of 'msg' should be passed to the application
2274 static BOOL process_keyboard_message( MSG *msg, UINT hw_id, HWND hwnd_filter,
2275 UINT first, UINT last, BOOL remove )
2279 if (msg->message == WM_KEYDOWN || msg->message == WM_SYSKEYDOWN ||
2280 msg->message == WM_KEYUP || msg->message == WM_SYSKEYUP)
2281 switch (msg->wParam)
2283 case VK_LSHIFT: case VK_RSHIFT:
2284 msg->wParam = VK_SHIFT;
2286 case VK_LCONTROL: case VK_RCONTROL:
2287 msg->wParam = VK_CONTROL;
2289 case VK_LMENU: case VK_RMENU:
2290 msg->wParam = VK_MENU;
2294 /* FIXME: is this really the right place for this hook? */
2295 event.message = msg->message;
2296 event.hwnd = msg->hwnd;
2297 event.time = msg->time;
2298 event.paramL = (msg->wParam & 0xFF) | (HIWORD(msg->lParam) << 8);
2299 event.paramH = msg->lParam & 0x7FFF;
2300 if (HIWORD(msg->lParam) & 0x0100) event.paramH |= 0x8000; /* special_key - bit */
2301 HOOK_CallHooks( WH_JOURNALRECORD, HC_ACTION, 0, (LPARAM)&event, TRUE );
2303 /* check message filters */
2304 if (msg->message < first || msg->message > last) return FALSE;
2305 if (!check_hwnd_filter( msg, hwnd_filter )) return FALSE;
2309 if((msg->message == WM_KEYDOWN) &&
2310 (msg->hwnd != GetDesktopWindow()))
2312 /* Handle F1 key by sending out WM_HELP message */
2313 if (msg->wParam == VK_F1)
2315 PostMessageW( msg->hwnd, WM_KEYF1, 0, 0 );
2317 else if(msg->wParam >= VK_BROWSER_BACK &&
2318 msg->wParam <= VK_LAUNCH_APP2)
2320 /* FIXME: Process keystate */
2321 SendMessageW(msg->hwnd, WM_APPCOMMAND, (WPARAM)msg->hwnd, MAKELPARAM(0, (FAPPCOMMAND_KEY | (msg->wParam - VK_BROWSER_BACK + 1))));
2324 else if (msg->message == WM_KEYUP)
2326 /* Handle VK_APPS key by posting a WM_CONTEXTMENU message */
2327 if (msg->wParam == VK_APPS && !MENU_IsMenuActive())
2328 PostMessageW(msg->hwnd, WM_CONTEXTMENU, (WPARAM)msg->hwnd, -1);
2332 if (HOOK_CallHooks( WH_KEYBOARD, remove ? HC_ACTION : HC_NOREMOVE,
2333 LOWORD(msg->wParam), msg->lParam, TRUE ))
2335 /* skip this message */
2336 HOOK_CallHooks( WH_CBT, HCBT_KEYSKIPPED, LOWORD(msg->wParam), msg->lParam, TRUE );
2337 accept_hardware_message( hw_id, TRUE, 0 );
2340 accept_hardware_message( hw_id, remove, 0 );
2342 if ( msg->message == WM_KEYDOWN || msg->message == WM_KEYUP )
2343 if ( ImmProcessKey(msg->hwnd, GetKeyboardLayout(0), msg->wParam, msg->lParam, 0) )
2344 msg->wParam = VK_PROCESSKEY;
2350 /***********************************************************************
2351 * process_mouse_message
2353 * returns TRUE if the contents of 'msg' should be passed to the application
2355 static BOOL process_mouse_message( MSG *msg, UINT hw_id, ULONG_PTR extra_info, HWND hwnd_filter,
2356 UINT first, UINT last, BOOL remove )
2365 MOUSEHOOKSTRUCT hook;
2368 /* find the window to dispatch this mouse message to */
2370 info.cbSize = sizeof(info);
2371 GetGUIThreadInfo( GetCurrentThreadId(), &info );
2372 if (info.hwndCapture)
2375 msg->hwnd = info.hwndCapture;
2379 msg->hwnd = WINPOS_WindowFromPoint( msg->hwnd, msg->pt, &hittest );
2382 if (!msg->hwnd || !WIN_IsCurrentThread( msg->hwnd ))
2384 accept_hardware_message( hw_id, TRUE, msg->hwnd );
2388 /* FIXME: is this really the right place for this hook? */
2389 event.message = msg->message;
2390 event.time = msg->time;
2391 event.hwnd = msg->hwnd;
2392 event.paramL = msg->pt.x;
2393 event.paramH = msg->pt.y;
2394 HOOK_CallHooks( WH_JOURNALRECORD, HC_ACTION, 0, (LPARAM)&event, TRUE );
2396 if (!check_hwnd_filter( msg, hwnd_filter )) return FALSE;
2399 message = msg->message;
2400 /* Note: windows has no concept of a non-client wheel message */
2401 if (message != WM_MOUSEWHEEL)
2403 if (hittest != HTCLIENT)
2405 message += WM_NCMOUSEMOVE - WM_MOUSEMOVE;
2406 msg->wParam = hittest;
2410 /* coordinates don't get translated while tracking a menu */
2411 /* FIXME: should differentiate popups and top-level menus */
2412 if (!(info.flags & GUI_INMENUMODE))
2413 ScreenToClient( msg->hwnd, &pt );
2416 msg->lParam = MAKELONG( pt.x, pt.y );
2418 /* translate double clicks */
2420 if ((msg->message == WM_LBUTTONDOWN) ||
2421 (msg->message == WM_RBUTTONDOWN) ||
2422 (msg->message == WM_MBUTTONDOWN) ||
2423 (msg->message == WM_XBUTTONDOWN))
2425 BOOL update = remove;
2427 /* translate double clicks -
2428 * note that ...MOUSEMOVEs can slip in between
2429 * ...BUTTONDOWN and ...BUTTONDBLCLK messages */
2431 if ((info.flags & (GUI_INMENUMODE|GUI_INMOVESIZE)) ||
2432 hittest != HTCLIENT ||
2433 (GetClassLongA( msg->hwnd, GCL_STYLE ) & CS_DBLCLKS))
2435 if ((msg->message == clk_msg.message) &&
2436 (msg->hwnd == clk_msg.hwnd) &&
2437 (msg->wParam == clk_msg.wParam) &&
2438 (msg->time - clk_msg.time < GetDoubleClickTime()) &&
2439 (abs(msg->pt.x - clk_msg.pt.x) < GetSystemMetrics(SM_CXDOUBLECLK)/2) &&
2440 (abs(msg->pt.y - clk_msg.pt.y) < GetSystemMetrics(SM_CYDOUBLECLK)/2))
2442 message += (WM_LBUTTONDBLCLK - WM_LBUTTONDOWN);
2445 clk_msg.message = 0; /* clear the double click conditions */
2450 if (message < first || message > last) return FALSE;
2451 /* update static double click conditions */
2452 if (update) clk_msg = *msg;
2456 if (message < first || message > last) return FALSE;
2459 /* message is accepted now (but may still get dropped) */
2462 hook.hwnd = msg->hwnd;
2463 hook.wHitTestCode = hittest;
2464 hook.dwExtraInfo = extra_info;
2465 if (HOOK_CallHooks( WH_MOUSE, remove ? HC_ACTION : HC_NOREMOVE,
2466 message, (LPARAM)&hook, TRUE ))
2469 hook.hwnd = msg->hwnd;
2470 hook.wHitTestCode = hittest;
2471 hook.dwExtraInfo = extra_info;
2472 HOOK_CallHooks( WH_CBT, HCBT_CLICKSKIPPED, message, (LPARAM)&hook, TRUE );
2473 accept_hardware_message( hw_id, TRUE, 0 );
2477 if ((hittest == HTERROR) || (hittest == HTNOWHERE))
2479 SendMessageW( msg->hwnd, WM_SETCURSOR, (WPARAM)msg->hwnd,
2480 MAKELONG( hittest, msg->message ));
2481 accept_hardware_message( hw_id, TRUE, 0 );
2485 accept_hardware_message( hw_id, remove, 0 );
2487 if (!remove || info.hwndCapture)
2489 msg->message = message;
2495 if ((msg->message == WM_LBUTTONDOWN) ||
2496 (msg->message == WM_RBUTTONDOWN) ||
2497 (msg->message == WM_MBUTTONDOWN) ||
2498 (msg->message == WM_XBUTTONDOWN))
2500 /* Send the WM_PARENTNOTIFY,
2501 * note that even for double/nonclient clicks
2502 * notification message is still WM_L/M/RBUTTONDOWN.
2504 send_parent_notify( msg->hwnd, msg->message, 0, msg->pt );
2506 /* Activate the window if needed */
2508 if (msg->hwnd != info.hwndActive)
2510 HWND hwndTop = msg->hwnd;
2513 if ((GetWindowLongW( hwndTop, GWL_STYLE ) & (WS_POPUP|WS_CHILD)) != WS_CHILD) break;
2514 hwndTop = GetParent( hwndTop );
2517 if (hwndTop && hwndTop != GetDesktopWindow())
2519 LONG ret = SendMessageW( msg->hwnd, WM_MOUSEACTIVATE, (WPARAM)hwndTop,
2520 MAKELONG( hittest, msg->message ) );
2523 case MA_NOACTIVATEANDEAT:
2528 case MA_ACTIVATEANDEAT:
2533 if (!FOCUS_MouseActivate( hwndTop )) eatMsg = TRUE;
2536 WARN( "unknown WM_MOUSEACTIVATE code %d\n", ret );
2543 /* send the WM_SETCURSOR message */
2545 /* Windows sends the normal mouse message as the message parameter
2546 in the WM_SETCURSOR message even if it's non-client mouse message */
2547 SendMessageW( msg->hwnd, WM_SETCURSOR, (WPARAM)msg->hwnd, MAKELONG( hittest, msg->message ));
2549 msg->message = message;
2554 /***********************************************************************
2555 * process_hardware_message
2557 * Process a hardware message; return TRUE if message should be passed on to the app
2559 static BOOL process_hardware_message( MSG *msg, UINT hw_id, ULONG_PTR extra_info, HWND hwnd_filter,
2560 UINT first, UINT last, BOOL remove )
2562 if (is_keyboard_message( msg->message ))
2563 return process_keyboard_message( msg, hw_id, hwnd_filter, first, last, remove );
2565 if (is_mouse_message( msg->message ))
2566 return process_mouse_message( msg, hw_id, extra_info, hwnd_filter, first, last, remove );
2568 ERR( "unknown message type %x\n", msg->message );
2573 /***********************************************************************
2574 * call_sendmsg_callback
2576 * Call the callback function of SendMessageCallback.
2578 static inline void call_sendmsg_callback( SENDASYNCPROC callback, HWND hwnd, UINT msg,
2579 ULONG_PTR data, LRESULT result )
2581 if (!callback) return;
2583 if (TRACE_ON(relay))
2584 DPRINTF( "%04x:Call message callback %p (hwnd=%p,msg=%s,data=%08lx,result=%08lx)\n",
2585 GetCurrentThreadId(), callback, hwnd, SPY_GetMsgName( msg, hwnd ),
2587 callback( hwnd, msg, data, result );
2588 if (TRACE_ON(relay))
2589 DPRINTF( "%04x:Ret message callback %p (hwnd=%p,msg=%s,data=%08lx,result=%08lx)\n",
2590 GetCurrentThreadId(), callback, hwnd, SPY_GetMsgName( msg, hwnd ),
2595 /***********************************************************************
2598 * Peek for a message matching the given parameters. Return FALSE if none available.
2599 * All pending sent messages are processed before returning.
2601 static BOOL peek_message( MSG *msg, HWND hwnd, UINT first, UINT last, UINT flags, UINT changed_mask )
2604 struct user_thread_info *thread_info = get_user_thread_info();
2605 struct received_message_info info, *old_info;
2606 unsigned int hw_id = 0; /* id of previous hardware message */
2608 size_t buffer_size = 256;
2610 if (!(buffer = HeapAlloc( GetProcessHeap(), 0, buffer_size ))) return FALSE;
2612 if (!first && !last) last = ~0;
2613 if (hwnd == HWND_BROADCAST) hwnd = HWND_TOPMOST;
2619 const message_data_t *msg_data = buffer;
2621 SERVER_START_REQ( get_message )
2624 req->get_win = wine_server_user_handle( hwnd );
2625 req->get_first = first;
2626 req->get_last = last;
2628 req->wake_mask = changed_mask & (QS_SENDMESSAGE | QS_SMRESULT);
2629 req->changed_mask = changed_mask;
2630 wine_server_set_reply( req, buffer, buffer_size );
2631 if (!(res = wine_server_call( req )))
2633 size = wine_server_reply_size( reply );
2634 info.type = reply->type;
2635 info.msg.hwnd = wine_server_ptr_handle( reply->win );
2636 info.msg.message = reply->msg;
2637 info.msg.wParam = reply->wparam;
2638 info.msg.lParam = reply->lparam;
2639 info.msg.time = reply->time;
2643 thread_info->active_hooks = reply->active_hooks;
2645 else buffer_size = reply->total;
2651 HeapFree( GetProcessHeap(), 0, buffer );
2652 if (res != STATUS_BUFFER_OVERFLOW) return FALSE;
2653 if (!(buffer = HeapAlloc( GetProcessHeap(), 0, buffer_size ))) return FALSE;
2657 TRACE( "got type %d msg %x (%s) hwnd %p wp %lx lp %lx\n",
2658 info.type, info.msg.message,
2659 (info.type == MSG_WINEVENT) ? "MSG_WINEVENT" : SPY_GetMsgName(info.msg.message, info.msg.hwnd),
2660 info.msg.hwnd, info.msg.wParam, info.msg.lParam );
2666 info.flags = ISMEX_SEND;
2669 info.flags = ISMEX_NOTIFY;
2672 info.flags = ISMEX_CALLBACK;
2674 case MSG_CALLBACK_RESULT:
2675 if (size >= sizeof(msg_data->callback))
2676 call_sendmsg_callback( wine_server_get_ptr(msg_data->callback.callback),
2677 info.msg.hwnd, info.msg.message,
2678 msg_data->callback.data, msg_data->callback.result );
2681 if (size >= sizeof(msg_data->winevent))
2683 WINEVENTPROC hook_proc;
2685 hook_proc = wine_server_get_ptr( msg_data->winevent.hook_proc );
2686 size -= sizeof(msg_data->winevent);
2689 WCHAR module[MAX_PATH];
2691 size = min( size, (MAX_PATH - 1) * sizeof(WCHAR) );
2692 memcpy( module, &msg_data->winevent + 1, size );
2693 module[size / sizeof(WCHAR)] = 0;
2694 if (!(hook_proc = get_hook_proc( hook_proc, module )))
2696 ERR( "invalid winevent hook module name %s\n", debugstr_w(module) );
2701 if (TRACE_ON(relay))
2702 DPRINTF( "%04x:Call winevent proc %p (hook=%04x,event=%x,hwnd=%p,object_id=%lx,child_id=%lx,tid=%04x,time=%x)\n",
2703 GetCurrentThreadId(), hook_proc,
2704 msg_data->winevent.hook, info.msg.message, info.msg.hwnd, info.msg.wParam,
2705 info.msg.lParam, msg_data->winevent.tid, info.msg.time);
2707 hook_proc( wine_server_ptr_handle( msg_data->winevent.hook ), info.msg.message,
2708 info.msg.hwnd, info.msg.wParam, info.msg.lParam,
2709 msg_data->winevent.tid, info.msg.time );
2711 if (TRACE_ON(relay))
2712 DPRINTF( "%04x:Ret winevent proc %p (hook=%04x,event=%x,hwnd=%p,object_id=%lx,child_id=%lx,tid=%04x,time=%x)\n",
2713 GetCurrentThreadId(), hook_proc,
2714 msg_data->winevent.hook, info.msg.message, info.msg.hwnd, info.msg.wParam,
2715 info.msg.lParam, msg_data->winevent.tid, info.msg.time);
2719 info.flags = ISMEX_SEND;
2721 if (info.msg.message == WH_KEYBOARD_LL && size >= sizeof(msg_data->hardware))
2723 KBDLLHOOKSTRUCT hook;
2725 hook.vkCode = LOWORD( info.msg.lParam );
2726 hook.scanCode = HIWORD( info.msg.lParam );
2727 hook.flags = msg_data->hardware.flags;
2728 hook.time = info.msg.time;
2729 hook.dwExtraInfo = msg_data->hardware.info;
2730 TRACE( "calling keyboard LL hook vk %x scan %x flags %x time %u info %lx\n",
2731 hook.vkCode, hook.scanCode, hook.flags, hook.time, hook.dwExtraInfo );
2732 result = HOOK_CallHooks( WH_KEYBOARD_LL, HC_ACTION, info.msg.wParam, (LPARAM)&hook, TRUE );
2734 else if (info.msg.message == WH_MOUSE_LL && size >= sizeof(msg_data->hardware))
2736 MSLLHOOKSTRUCT hook;
2738 hook.pt.x = msg_data->hardware.x;
2739 hook.pt.y = msg_data->hardware.y;
2740 hook.mouseData = info.msg.lParam;
2741 hook.flags = msg_data->hardware.flags;
2742 hook.time = info.msg.time;
2743 hook.dwExtraInfo = msg_data->hardware.info;
2744 TRACE( "calling mouse LL hook pos %d,%d data %x flags %x time %u info %lx\n",
2745 hook.pt.x, hook.pt.y, hook.mouseData, hook.flags, hook.time, hook.dwExtraInfo );
2746 result = HOOK_CallHooks( WH_MOUSE_LL, HC_ACTION, info.msg.wParam, (LPARAM)&hook, TRUE );
2748 reply_message( &info, result, TRUE );
2750 case MSG_OTHER_PROCESS:
2751 info.flags = ISMEX_SEND;
2752 if (!unpack_message( info.msg.hwnd, info.msg.message, &info.msg.wParam,
2753 &info.msg.lParam, &buffer, size ))
2756 reply_message( &info, 0, TRUE );
2761 if (size >= sizeof(msg_data->hardware))
2763 info.msg.pt.x = msg_data->hardware.x;
2764 info.msg.pt.y = msg_data->hardware.y;
2765 hw_id = msg_data->hardware.hw_id;
2766 if (!process_hardware_message( &info.msg, hw_id, msg_data->hardware.info,
2767 hwnd, first, last, flags & PM_REMOVE ))
2769 TRACE("dropping msg %x\n", info.msg.message );
2770 continue; /* ignore it */
2773 thread_info->GetMessagePosVal = MAKELONG( info.msg.pt.x, info.msg.pt.y );
2774 thread_info->GetMessageTimeVal = info.msg.time;
2775 thread_info->GetMessageExtraInfoVal = msg_data->hardware.info;
2776 HeapFree( GetProcessHeap(), 0, buffer );
2777 HOOK_CallHooks( WH_GETMESSAGE, HC_ACTION, flags & PM_REMOVE, (LPARAM)msg, TRUE );
2782 if (info.msg.message & 0x80000000) /* internal message */
2784 if (flags & PM_REMOVE)
2786 handle_internal_message( info.msg.hwnd, info.msg.message,
2787 info.msg.wParam, info.msg.lParam );
2788 /* if this is a nested call return right away */
2789 if (first == info.msg.message && last == info.msg.message) return FALSE;
2792 peek_message( msg, info.msg.hwnd, info.msg.message,
2793 info.msg.message, flags | PM_REMOVE, changed_mask );
2796 if (info.msg.message >= WM_DDE_FIRST && info.msg.message <= WM_DDE_LAST)
2798 if (!unpack_dde_message( info.msg.hwnd, info.msg.message, &info.msg.wParam,
2799 &info.msg.lParam, &buffer, size ))
2800 continue; /* ignore it */
2803 msg->pt.x = (short)LOWORD( thread_info->GetMessagePosVal );
2804 msg->pt.y = (short)HIWORD( thread_info->GetMessagePosVal );
2805 thread_info->GetMessageTimeVal = info.msg.time;
2806 thread_info->GetMessageExtraInfoVal = 0;
2807 HeapFree( GetProcessHeap(), 0, buffer );
2808 HOOK_CallHooks( WH_GETMESSAGE, HC_ACTION, flags & PM_REMOVE, (LPARAM)msg, TRUE );
2812 /* if we get here, we have a sent message; call the window procedure */
2813 old_info = thread_info->receive_info;
2814 thread_info->receive_info = &info;
2815 result = call_window_proc( info.msg.hwnd, info.msg.message, info.msg.wParam,
2816 info.msg.lParam, (info.type != MSG_ASCII), FALSE,
2817 WMCHAR_MAP_RECVMESSAGE );
2818 reply_message( &info, result, TRUE );
2819 thread_info->receive_info = old_info;
2821 /* if some PM_QS* flags were specified, only handle sent messages from now on */
2822 if (HIWORD(flags) && !changed_mask) flags = PM_QS_SENDMESSAGE | LOWORD(flags);
2827 /***********************************************************************
2828 * process_sent_messages
2830 * Process all pending sent messages.
2832 static inline void process_sent_messages(void)
2835 peek_message( &msg, 0, 0, 0, PM_REMOVE | PM_QS_SENDMESSAGE, 0 );
2839 /***********************************************************************
2840 * get_server_queue_handle
2842 * Get a handle to the server message queue for the current thread.
2844 static HANDLE get_server_queue_handle(void)
2846 struct user_thread_info *thread_info = get_user_thread_info();
2849 if (!(ret = thread_info->server_queue))
2851 SERVER_START_REQ( get_msg_queue )
2853 wine_server_call( req );
2854 ret = wine_server_ptr_handle( reply->handle );
2857 thread_info->server_queue = ret;
2858 if (!ret) ERR( "Cannot get server thread queue\n" );
2864 /***********************************************************************
2865 * wait_message_reply
2867 * Wait until a sent message gets replied to.
2869 static void wait_message_reply( UINT flags )
2871 HANDLE server_queue = get_server_queue_handle();
2875 unsigned int wake_bits = 0;
2877 SERVER_START_REQ( set_queue_mask )
2879 req->wake_mask = QS_SMRESULT | ((flags & SMTO_BLOCK) ? 0 : QS_SENDMESSAGE);
2880 req->changed_mask = req->wake_mask;
2882 if (!wine_server_call( req ))
2883 wake_bits = reply->wake_bits;
2887 if (wake_bits & QS_SMRESULT) return; /* got a result */
2888 if (wake_bits & QS_SENDMESSAGE)
2890 /* Process the sent message immediately */
2891 process_sent_messages();
2895 wow_handlers.wait_message( 1, &server_queue, INFINITE, QS_SENDMESSAGE, 0 );
2899 /***********************************************************************
2900 * put_message_in_queue
2902 * Put a sent message into the destination queue.
2903 * For inter-process message, reply_size is set to expected size of reply data.
2905 static BOOL put_message_in_queue( const struct send_message_info *info, size_t *reply_size )
2907 struct packed_message data;
2908 message_data_t msg_data;
2911 timeout_t timeout = TIMEOUT_INFINITE;
2913 /* Check for INFINITE timeout for compatibility with Win9x,
2914 * although Windows >= NT does not do so
2916 if (info->type != MSG_NOTIFY &&
2917 info->type != MSG_CALLBACK &&
2918 info->type != MSG_POSTED &&
2920 info->timeout != INFINITE)
2922 /* timeout is signed despite the prototype */
2923 timeout = (timeout_t)max( 0, (int)info->timeout ) * -10000;
2926 memset( &data, 0, sizeof(data) );
2927 if (info->type == MSG_OTHER_PROCESS)
2929 *reply_size = pack_message( info->hwnd, info->msg, info->wparam, info->lparam, &data );
2930 if (data.count == -1)
2932 WARN( "cannot pack message %x\n", info->msg );
2936 else if (info->type == MSG_CALLBACK)
2938 msg_data.callback.callback = wine_server_client_ptr( info->callback );
2939 msg_data.callback.data = info->data;
2940 msg_data.callback.result = 0;
2941 data.data[0] = &msg_data;
2942 data.size[0] = sizeof(msg_data.callback);
2945 else if (info->type == MSG_POSTED && info->msg >= WM_DDE_FIRST && info->msg <= WM_DDE_LAST)
2947 return post_dde_message( &data, info );
2950 SERVER_START_REQ( send_message )
2952 req->id = info->dest_tid;
2953 req->type = info->type;
2955 req->win = wine_server_user_handle( info->hwnd );
2956 req->msg = info->msg;
2957 req->wparam = info->wparam;
2958 req->lparam = info->lparam;
2959 req->timeout = timeout;
2961 if (info->flags & SMTO_ABORTIFHUNG) req->flags |= SEND_MSG_ABORT_IF_HUNG;
2962 for (i = 0; i < data.count; i++) wine_server_add_data( req, data.data[i], data.size[i] );
2963 if ((res = wine_server_call( req )))
2965 if (res == STATUS_INVALID_PARAMETER)
2966 /* FIXME: find a STATUS_ value for this one */
2967 SetLastError( ERROR_INVALID_THREAD_ID );
2969 SetLastError( RtlNtStatusToDosError(res) );
2977 /***********************************************************************
2980 * Retrieve a message reply from the server.
2982 static LRESULT retrieve_reply( const struct send_message_info *info,
2983 size_t reply_size, LRESULT *result )
2986 void *reply_data = NULL;
2990 if (!(reply_data = HeapAlloc( GetProcessHeap(), 0, reply_size )))
2992 WARN( "no memory for reply, will be truncated\n" );
2996 SERVER_START_REQ( get_message_reply )
2999 if (reply_size) wine_server_set_reply( req, reply_data, reply_size );
3000 if (!(status = wine_server_call( req ))) *result = reply->result;
3001 reply_size = wine_server_reply_size( reply );
3004 if (!status && reply_size)
3005 unpack_reply( info->hwnd, info->msg, info->wparam, info->lparam, reply_data, reply_size );
3007 HeapFree( GetProcessHeap(), 0, reply_data );
3009 TRACE( "hwnd %p msg %x (%s) wp %lx lp %lx got reply %lx (err=%d)\n",
3010 info->hwnd, info->msg, SPY_GetMsgName(info->msg, info->hwnd), info->wparam,
3011 info->lparam, *result, status );
3013 /* MSDN states that last error is 0 on timeout, but at least NT4 returns ERROR_TIMEOUT */
3014 if (status) SetLastError( RtlNtStatusToDosError(status) );
3019 /***********************************************************************
3020 * send_inter_thread_message
3022 static LRESULT send_inter_thread_message( const struct send_message_info *info, LRESULT *res_ptr )
3024 size_t reply_size = 0;
3026 TRACE( "hwnd %p msg %x (%s) wp %lx lp %lx\n",
3027 info->hwnd, info->msg, SPY_GetMsgName(info->msg, info->hwnd), info->wparam, info->lparam );
3029 USER_CheckNotLock();
3031 if (!put_message_in_queue( info, &reply_size )) return 0;
3033 /* there's no reply to wait for on notify/callback messages */
3034 if (info->type == MSG_NOTIFY || info->type == MSG_CALLBACK) return 1;
3036 wait_message_reply( info->flags );
3037 return retrieve_reply( info, reply_size, res_ptr );
3041 /***********************************************************************
3042 * send_inter_thread_callback
3044 static LRESULT send_inter_thread_callback( HWND hwnd, UINT msg, WPARAM wp, LPARAM lp,
3045 LRESULT *result, void *arg )
3047 struct send_message_info *info = arg;
3052 return send_inter_thread_message( info, result );
3056 /***********************************************************************
3059 * Backend implementation of the various SendMessage functions.
3061 static BOOL send_message( struct send_message_info *info, DWORD_PTR *res_ptr, BOOL unicode )
3067 if (is_broadcast(info->hwnd))
3069 EnumWindows( broadcast_message_callback, (LPARAM)info );
3070 if (res_ptr) *res_ptr = 1;
3074 if (!(info->dest_tid = GetWindowThreadProcessId( info->hwnd, &dest_pid ))) return FALSE;
3076 if (USER_IsExitingThread( info->dest_tid )) return FALSE;
3078 SPY_EnterMessage( SPY_SENDMESSAGE, info->hwnd, info->msg, info->wparam, info->lparam );
3080 if (info->dest_tid == GetCurrentThreadId())
3082 result = call_window_proc( info->hwnd, info->msg, info->wparam, info->lparam,
3083 unicode, TRUE, info->wm_char );
3084 if (info->type == MSG_CALLBACK)
3085 call_sendmsg_callback( info->callback, info->hwnd, info->msg, info->data, result );
3090 if (dest_pid != GetCurrentProcessId() && (info->type == MSG_ASCII || info->type == MSG_UNICODE))
3091 info->type = MSG_OTHER_PROCESS;
3093 /* MSG_ASCII can be sent unconverted except for WM_CHAR; everything else needs to be Unicode */
3094 if (!unicode && is_unicode_message( info->msg ) &&
3095 (info->type != MSG_ASCII || info->msg == WM_CHAR))
3096 ret = WINPROC_CallProcAtoW( send_inter_thread_callback, info->hwnd, info->msg,
3097 info->wparam, info->lparam, &result, info, info->wm_char );
3099 ret = send_inter_thread_message( info, &result );
3102 SPY_ExitMessage( SPY_RESULT_OK, info->hwnd, info->msg, result, info->wparam, info->lparam );
3103 if (ret && res_ptr) *res_ptr = result;
3108 /***********************************************************************
3109 * send_hardware_message
3111 NTSTATUS send_hardware_message( HWND hwnd, const INPUT *input, UINT flags )
3113 struct send_message_info info;
3117 info.type = MSG_HARDWARE;
3123 SERVER_START_REQ( send_hardware_message )
3125 req->win = wine_server_user_handle( hwnd );
3127 req->input.type = input->type;
3128 switch (input->type)
3131 req->input.mouse.x = input->u.mi.dx;
3132 req->input.mouse.y = input->u.mi.dy;
3133 req->input.mouse.data = input->u.mi.mouseData;
3134 req->input.mouse.flags = input->u.mi.dwFlags;
3135 req->input.mouse.time = input->u.mi.time;
3136 req->input.mouse.info = input->u.mi.dwExtraInfo;
3138 case INPUT_KEYBOARD:
3139 req->input.kbd.vkey = input->u.ki.wVk;
3140 req->input.kbd.scan = input->u.ki.wScan;
3141 req->input.kbd.flags = input->u.ki.dwFlags;
3142 req->input.kbd.time = input->u.ki.time;
3143 req->input.kbd.info = input->u.ki.dwExtraInfo;
3145 case INPUT_HARDWARE:
3146 req->input.hw.msg = input->u.hi.uMsg;
3147 req->input.hw.lparam = MAKELONG( input->u.hi.wParamL, input->u.hi.wParamH );
3150 ret = wine_server_call( req );
3158 wait_message_reply( 0 );
3159 retrieve_reply( &info, 0, &ignored );
3165 /***********************************************************************
3166 * MSG_SendInternalMessageTimeout
3168 * Same as SendMessageTimeoutW but sends the message to a specific thread
3169 * without requiring a window handle. Only works for internal Wine messages.
3171 LRESULT MSG_SendInternalMessageTimeout( DWORD dest_pid, DWORD dest_tid,
3172 UINT msg, WPARAM wparam, LPARAM lparam,
3173 UINT flags, UINT timeout, PDWORD_PTR res_ptr )
3175 struct send_message_info info;
3176 LRESULT ret, result;
3178 assert( msg & 0x80000000 ); /* must be an internal Wine message */
3180 info.type = MSG_UNICODE;
3181 info.dest_tid = dest_tid;
3184 info.wparam = wparam;
3185 info.lparam = lparam;
3187 info.timeout = timeout;
3189 if (USER_IsExitingThread( dest_tid )) return 0;
3191 if (dest_tid == GetCurrentThreadId())
3193 result = handle_internal_message( 0, msg, wparam, lparam );
3198 if (dest_pid != GetCurrentProcessId()) info.type = MSG_OTHER_PROCESS;
3199 ret = send_inter_thread_message( &info, &result );
3201 if (ret && res_ptr) *res_ptr = result;
3206 /***********************************************************************
3207 * SendMessageTimeoutW (USER32.@)
3209 LRESULT WINAPI SendMessageTimeoutW( HWND hwnd, UINT msg, WPARAM wparam, LPARAM lparam,
3210 UINT flags, UINT timeout, PDWORD_PTR res_ptr )
3212 struct send_message_info info;
3214 info.type = MSG_UNICODE;
3217 info.wparam = wparam;
3218 info.lparam = lparam;
3220 info.timeout = timeout;
3222 return send_message( &info, res_ptr, TRUE );
3225 /***********************************************************************
3226 * SendMessageTimeoutA (USER32.@)
3228 LRESULT WINAPI SendMessageTimeoutA( HWND hwnd, UINT msg, WPARAM wparam, LPARAM lparam,
3229 UINT flags, UINT timeout, PDWORD_PTR res_ptr )
3231 struct send_message_info info;
3233 info.type = MSG_ASCII;
3236 info.wparam = wparam;
3237 info.lparam = lparam;
3239 info.timeout = timeout;
3240 info.wm_char = WMCHAR_MAP_SENDMESSAGETIMEOUT;
3242 return send_message( &info, res_ptr, FALSE );
3246 /***********************************************************************
3247 * SendMessageW (USER32.@)
3249 LRESULT WINAPI SendMessageW( HWND hwnd, UINT msg, WPARAM wparam, LPARAM lparam )
3252 struct send_message_info info;
3254 info.type = MSG_UNICODE;
3257 info.wparam = wparam;
3258 info.lparam = lparam;
3259 info.flags = SMTO_NORMAL;
3262 send_message( &info, &res, TRUE );
3267 /***********************************************************************
3268 * SendMessageA (USER32.@)
3270 LRESULT WINAPI SendMessageA( HWND hwnd, UINT msg, WPARAM wparam, LPARAM lparam )
3273 struct send_message_info info;
3275 info.type = MSG_ASCII;
3278 info.wparam = wparam;
3279 info.lparam = lparam;
3280 info.flags = SMTO_NORMAL;
3282 info.wm_char = WMCHAR_MAP_SENDMESSAGE;
3284 send_message( &info, &res, FALSE );
3289 /***********************************************************************
3290 * SendNotifyMessageA (USER32.@)
3292 BOOL WINAPI SendNotifyMessageA( HWND hwnd, UINT msg, WPARAM wparam, LPARAM lparam )
3294 struct send_message_info info;
3296 if (is_pointer_message(msg))
3298 SetLastError( ERROR_MESSAGE_SYNC_ONLY );
3302 info.type = MSG_NOTIFY;
3305 info.wparam = wparam;
3306 info.lparam = lparam;
3308 info.wm_char = WMCHAR_MAP_SENDMESSAGETIMEOUT;
3310 return send_message( &info, NULL, FALSE );
3314 /***********************************************************************
3315 * SendNotifyMessageW (USER32.@)
3317 BOOL WINAPI SendNotifyMessageW( HWND hwnd, UINT msg, WPARAM wparam, LPARAM lparam )
3319 struct send_message_info info;
3321 if (is_pointer_message(msg))
3323 SetLastError( ERROR_MESSAGE_SYNC_ONLY );
3327 info.type = MSG_NOTIFY;
3330 info.wparam = wparam;
3331 info.lparam = lparam;
3334 return send_message( &info, NULL, TRUE );
3338 /***********************************************************************
3339 * SendMessageCallbackA (USER32.@)
3341 BOOL WINAPI SendMessageCallbackA( HWND hwnd, UINT msg, WPARAM wparam, LPARAM lparam,
3342 SENDASYNCPROC callback, ULONG_PTR data )
3344 struct send_message_info info;
3346 if (is_pointer_message(msg))
3348 SetLastError( ERROR_MESSAGE_SYNC_ONLY );
3352 info.type = MSG_CALLBACK;
3355 info.wparam = wparam;
3356 info.lparam = lparam;
3357 info.callback = callback;
3360 info.wm_char = WMCHAR_MAP_SENDMESSAGETIMEOUT;
3362 return send_message( &info, NULL, FALSE );
3366 /***********************************************************************
3367 * SendMessageCallbackW (USER32.@)
3369 BOOL WINAPI SendMessageCallbackW( HWND hwnd, UINT msg, WPARAM wparam, LPARAM lparam,
3370 SENDASYNCPROC callback, ULONG_PTR data )
3372 struct send_message_info info;
3374 if (is_pointer_message(msg))
3376 SetLastError( ERROR_MESSAGE_SYNC_ONLY );
3380 info.type = MSG_CALLBACK;
3383 info.wparam = wparam;
3384 info.lparam = lparam;
3385 info.callback = callback;
3389 return send_message( &info, NULL, TRUE );
3393 /***********************************************************************
3394 * ReplyMessage (USER32.@)
3396 BOOL WINAPI ReplyMessage( LRESULT result )
3398 struct received_message_info *info = get_user_thread_info()->receive_info;
3400 if (!info) return FALSE;
3401 reply_message( info, result, FALSE );
3406 /***********************************************************************
3407 * InSendMessage (USER32.@)
3409 BOOL WINAPI InSendMessage(void)
3411 return (InSendMessageEx(NULL) & (ISMEX_SEND|ISMEX_REPLIED)) == ISMEX_SEND;
3415 /***********************************************************************
3416 * InSendMessageEx (USER32.@)
3418 DWORD WINAPI InSendMessageEx( LPVOID reserved )
3420 struct received_message_info *info = get_user_thread_info()->receive_info;
3422 if (info) return info->flags;
3423 return ISMEX_NOSEND;
3427 /***********************************************************************
3428 * PostMessageA (USER32.@)
3430 BOOL WINAPI PostMessageA( HWND hwnd, UINT msg, WPARAM wparam, LPARAM lparam )
3432 if (!map_wparam_AtoW( msg, &wparam, WMCHAR_MAP_POSTMESSAGE )) return TRUE;
3433 return PostMessageW( hwnd, msg, wparam, lparam );
3437 /***********************************************************************
3438 * PostMessageW (USER32.@)
3440 BOOL WINAPI PostMessageW( HWND hwnd, UINT msg, WPARAM wparam, LPARAM lparam )
3442 struct send_message_info info;
3444 if (is_pointer_message( msg ))
3446 SetLastError( ERROR_MESSAGE_SYNC_ONLY );
3450 TRACE( "hwnd %p msg %x (%s) wp %lx lp %lx\n",
3451 hwnd, msg, SPY_GetMsgName(msg, hwnd), wparam, lparam );
3453 info.type = MSG_POSTED;
3456 info.wparam = wparam;
3457 info.lparam = lparam;
3460 if (is_broadcast(hwnd))
3462 EnumWindows( broadcast_message_callback, (LPARAM)&info );
3466 if (!hwnd) return PostThreadMessageW( GetCurrentThreadId(), msg, wparam, lparam );
3468 if (!(info.dest_tid = GetWindowThreadProcessId( hwnd, NULL ))) return FALSE;
3470 if (USER_IsExitingThread( info.dest_tid )) return TRUE;
3472 return put_message_in_queue( &info, NULL );
3476 /**********************************************************************
3477 * PostThreadMessageA (USER32.@)
3479 BOOL WINAPI PostThreadMessageA( DWORD thread, UINT msg, WPARAM wparam, LPARAM lparam )
3481 if (!map_wparam_AtoW( msg, &wparam, WMCHAR_MAP_POSTMESSAGE )) return TRUE;
3482 return PostThreadMessageW( thread, msg, wparam, lparam );
3486 /**********************************************************************
3487 * PostThreadMessageW (USER32.@)
3489 BOOL WINAPI PostThreadMessageW( DWORD thread, UINT msg, WPARAM wparam, LPARAM lparam )
3491 struct send_message_info info;
3493 if (is_pointer_message( msg ))
3495 SetLastError( ERROR_MESSAGE_SYNC_ONLY );
3498 if (USER_IsExitingThread( thread )) return TRUE;
3500 info.type = MSG_POSTED;
3501 info.dest_tid = thread;
3504 info.wparam = wparam;
3505 info.lparam = lparam;
3507 return put_message_in_queue( &info, NULL );
3511 /***********************************************************************
3512 * PostQuitMessage (USER32.@)
3514 * Posts a quit message to the current thread's message queue.
3517 * exit_code [I] Exit code to return from message loop.
3523 * This function is not the same as calling:
3524 *|PostThreadMessage(GetCurrentThreadId(), WM_QUIT, exit_code, 0);
3525 * It instead sets a flag in the message queue that signals it to generate
3526 * a WM_QUIT message when there are no other pending sent or posted messages
3529 void WINAPI PostQuitMessage( INT exit_code )
3531 SERVER_START_REQ( post_quit_message )
3533 req->exit_code = exit_code;
3534 wine_server_call( req );
3540 /***********************************************************************
3541 * PeekMessageW (USER32.@)
3543 BOOL WINAPI DECLSPEC_HOTPATCH PeekMessageW( MSG *msg_out, HWND hwnd, UINT first, UINT last, UINT flags )
3547 USER_CheckNotLock();
3549 /* check for graphics events */
3550 USER_Driver->pMsgWaitForMultipleObjectsEx( 0, NULL, 0, QS_ALLINPUT, 0 );
3552 if (!peek_message( &msg, hwnd, first, last, flags, 0 ))
3554 if (!(flags & PM_NOYIELD)) wow_handlers.wait_message( 0, NULL, 0, 0, 0 );
3558 /* copy back our internal safe copy of message data to msg_out.
3559 * msg_out is a variable from the *program*, so it can't be used
3560 * internally as it can get "corrupted" by our use of SendMessage()
3561 * (back to the program) inside the message handling itself. */
3564 SetLastError( ERROR_NOACCESS );
3572 /***********************************************************************
3573 * PeekMessageA (USER32.@)
3575 BOOL WINAPI DECLSPEC_HOTPATCH PeekMessageA( MSG *msg, HWND hwnd, UINT first, UINT last, UINT flags )
3577 if (get_pending_wmchar( msg, first, last, (flags & PM_REMOVE) )) return TRUE;
3578 if (!PeekMessageW( msg, hwnd, first, last, flags )) return FALSE;
3579 map_wparam_WtoA( msg, (flags & PM_REMOVE) );
3584 /***********************************************************************
3585 * GetMessageW (USER32.@)
3587 BOOL WINAPI DECLSPEC_HOTPATCH GetMessageW( MSG *msg, HWND hwnd, UINT first, UINT last )
3589 HANDLE server_queue = get_server_queue_handle();
3590 unsigned int mask = QS_POSTMESSAGE | QS_SENDMESSAGE; /* Always selected */
3592 USER_CheckNotLock();
3594 /* check for graphics events */
3595 USER_Driver->pMsgWaitForMultipleObjectsEx( 0, NULL, 0, QS_ALLINPUT, 0 );
3599 if ((first <= WM_KEYLAST) && (last >= WM_KEYFIRST)) mask |= QS_KEY;
3600 if ( ((first <= WM_MOUSELAST) && (last >= WM_MOUSEFIRST)) ||
3601 ((first <= WM_NCMOUSELAST) && (last >= WM_NCMOUSEFIRST)) ) mask |= QS_MOUSE;
3602 if ((first <= WM_TIMER) && (last >= WM_TIMER)) mask |= QS_TIMER;
3603 if ((first <= WM_SYSTIMER) && (last >= WM_SYSTIMER)) mask |= QS_TIMER;
3604 if ((first <= WM_PAINT) && (last >= WM_PAINT)) mask |= QS_PAINT;
3606 else mask = QS_ALLINPUT;
3608 while (!peek_message( msg, hwnd, first, last, PM_REMOVE | (mask << 16), mask ))
3610 wow_handlers.wait_message( 1, &server_queue, INFINITE, mask, 0 );
3613 return (msg->message != WM_QUIT);
3617 /***********************************************************************
3618 * GetMessageA (USER32.@)
3620 BOOL WINAPI DECLSPEC_HOTPATCH GetMessageA( MSG *msg, HWND hwnd, UINT first, UINT last )
3622 if (get_pending_wmchar( msg, first, last, TRUE )) return TRUE;
3623 GetMessageW( msg, hwnd, first, last );
3624 map_wparam_WtoA( msg, TRUE );
3625 return (msg->message != WM_QUIT);
3629 /***********************************************************************
3630 * IsDialogMessageA (USER32.@)
3631 * IsDialogMessage (USER32.@)
3633 BOOL WINAPI IsDialogMessageA( HWND hwndDlg, LPMSG pmsg )
3636 map_wparam_AtoW( msg.message, &msg.wParam, WMCHAR_MAP_NOMAPPING );
3637 return IsDialogMessageW( hwndDlg, &msg );
3641 /***********************************************************************
3642 * TranslateMessage (USER32.@)
3644 * Implementation of TranslateMessage.
3646 * TranslateMessage translates virtual-key messages into character-messages,
3648 * WM_KEYDOWN/WM_KEYUP combinations produce a WM_CHAR or WM_DEADCHAR message.
3649 * ditto replacing WM_* with WM_SYS*
3650 * This produces WM_CHAR messages only for keys mapped to ASCII characters
3651 * by the keyboard driver.
3653 * If the message is WM_KEYDOWN, WM_KEYUP, WM_SYSKEYDOWN, or WM_SYSKEYUP, the
3654 * return value is nonzero, regardless of the translation.
3657 BOOL WINAPI TranslateMessage( const MSG *msg )
3663 if (msg->message < WM_KEYFIRST || msg->message > WM_KEYLAST) return FALSE;
3664 if (msg->message != WM_KEYDOWN && msg->message != WM_SYSKEYDOWN) return TRUE;
3666 TRACE_(key)("Translating key %s (%04lX), scancode %04x\n",
3667 SPY_GetVKeyName(msg->wParam), msg->wParam, HIWORD(msg->lParam));
3669 switch (msg->wParam)
3672 message = (msg->message == WM_KEYDOWN) ? WM_CHAR : WM_SYSCHAR;
3673 TRACE_(key)("PostMessageW(%p,%s,%04x,%08x)\n",
3674 msg->hwnd, SPY_GetMsgName(message, msg->hwnd), HIWORD(msg->lParam), LOWORD(msg->lParam));
3675 PostMessageW( msg->hwnd, message, HIWORD(msg->lParam), LOWORD(msg->lParam));
3679 return ImmTranslateMessage(msg->hwnd, msg->message, msg->wParam, msg->lParam);
3682 GetKeyboardState( state );
3683 /* FIXME : should handle ToUnicode yielding 2 */
3684 switch (ToUnicode(msg->wParam, HIWORD(msg->lParam), state, wp, 2, 0))
3687 message = (msg->message == WM_KEYDOWN) ? WM_CHAR : WM_SYSCHAR;
3688 TRACE_(key)("1 -> PostMessageW(%p,%s,%04x,%08lx)\n",
3689 msg->hwnd, SPY_GetMsgName(message, msg->hwnd), wp[0], msg->lParam);
3690 PostMessageW( msg->hwnd, message, wp[0], msg->lParam );
3694 message = (msg->message == WM_KEYDOWN) ? WM_DEADCHAR : WM_SYSDEADCHAR;
3695 TRACE_(key)("-1 -> PostMessageW(%p,%s,%04x,%08lx)\n",
3696 msg->hwnd, SPY_GetMsgName(message, msg->hwnd), wp[0], msg->lParam);
3697 PostMessageW( msg->hwnd, message, wp[0], msg->lParam );
3704 /***********************************************************************
3705 * DispatchMessageA (USER32.@)
3707 * See DispatchMessageW.
3709 LRESULT WINAPI DECLSPEC_HOTPATCH DispatchMessageA( const MSG* msg )
3713 /* Process timer messages */
3714 if ((msg->message == WM_TIMER) || (msg->message == WM_SYSTIMER))
3720 retval = CallWindowProcA( (WNDPROC)msg->lParam, msg->hwnd,
3721 msg->message, msg->wParam, GetTickCount() );
3731 if (!msg->hwnd) return 0;
3733 SPY_EnterMessage( SPY_DISPATCHMESSAGE, msg->hwnd, msg->message,
3734 msg->wParam, msg->lParam );
3736 if (!WINPROC_call_window( msg->hwnd, msg->message, msg->wParam, msg->lParam,
3737 &retval, FALSE, WMCHAR_MAP_DISPATCHMESSAGE ))
3739 if (!IsWindow( msg->hwnd )) SetLastError( ERROR_INVALID_WINDOW_HANDLE );
3740 else SetLastError( ERROR_MESSAGE_SYNC_ONLY );
3744 SPY_ExitMessage( SPY_RESULT_OK, msg->hwnd, msg->message, retval,
3745 msg->wParam, msg->lParam );
3747 if (msg->message == WM_PAINT)
3749 /* send a WM_NCPAINT and WM_ERASEBKGND if the non-client area is still invalid */
3750 HRGN hrgn = CreateRectRgn( 0, 0, 0, 0 );
3751 GetUpdateRgn( msg->hwnd, hrgn, TRUE );
3752 DeleteObject( hrgn );
3758 /***********************************************************************
3759 * DispatchMessageW (USER32.@) Process a message
3761 * Process the message specified in the structure *_msg_.
3763 * If the lpMsg parameter points to a WM_TIMER message and the
3764 * parameter of the WM_TIMER message is not NULL, the lParam parameter
3765 * points to the function that is called instead of the window
3766 * procedure. The function stored in lParam (timer callback) is protected
3767 * from causing page-faults.
3769 * The message must be valid.
3773 * DispatchMessage() returns the result of the window procedure invoked.
3780 LRESULT WINAPI DECLSPEC_HOTPATCH DispatchMessageW( const MSG* msg )
3784 /* Process timer messages */
3785 if ((msg->message == WM_TIMER) || (msg->message == WM_SYSTIMER))
3791 retval = CallWindowProcW( (WNDPROC)msg->lParam, msg->hwnd,
3792 msg->message, msg->wParam, GetTickCount() );
3802 if (!msg->hwnd) return 0;
3804 SPY_EnterMessage( SPY_DISPATCHMESSAGE, msg->hwnd, msg->message,
3805 msg->wParam, msg->lParam );
3807 if (!WINPROC_call_window( msg->hwnd, msg->message, msg->wParam, msg->lParam,
3808 &retval, TRUE, WMCHAR_MAP_DISPATCHMESSAGE ))
3810 if (!IsWindow( msg->hwnd )) SetLastError( ERROR_INVALID_WINDOW_HANDLE );
3811 else SetLastError( ERROR_MESSAGE_SYNC_ONLY );
3815 SPY_ExitMessage( SPY_RESULT_OK, msg->hwnd, msg->message, retval,
3816 msg->wParam, msg->lParam );
3818 if (msg->message == WM_PAINT)
3820 /* send a WM_NCPAINT and WM_ERASEBKGND if the non-client area is still invalid */
3821 HRGN hrgn = CreateRectRgn( 0, 0, 0, 0 );
3822 GetUpdateRgn( msg->hwnd, hrgn, TRUE );
3823 DeleteObject( hrgn );
3829 /***********************************************************************
3830 * GetMessagePos (USER.119)
3831 * GetMessagePos (USER32.@)
3833 * The GetMessagePos() function returns a long value representing a
3834 * cursor position, in screen coordinates, when the last message
3835 * retrieved by the GetMessage() function occurs. The x-coordinate is
3836 * in the low-order word of the return value, the y-coordinate is in
3837 * the high-order word. The application can use the MAKEPOINT()
3838 * macro to obtain a POINT structure from the return value.
3840 * For the current cursor position, use GetCursorPos().
3844 * Cursor position of last message on success, zero on failure.
3851 DWORD WINAPI GetMessagePos(void)
3853 return get_user_thread_info()->GetMessagePosVal;
3857 /***********************************************************************
3858 * GetMessageTime (USER.120)
3859 * GetMessageTime (USER32.@)
3861 * GetMessageTime() returns the message time for the last message
3862 * retrieved by the function. The time is measured in milliseconds with
3863 * the same offset as GetTickCount().
3865 * Since the tick count wraps, this is only useful for moderately short
3866 * relative time comparisons.
3870 * Time of last message on success, zero on failure.
3872 LONG WINAPI GetMessageTime(void)
3874 return get_user_thread_info()->GetMessageTimeVal;
3878 /***********************************************************************
3879 * GetMessageExtraInfo (USER.288)
3880 * GetMessageExtraInfo (USER32.@)
3882 LPARAM WINAPI GetMessageExtraInfo(void)
3884 return get_user_thread_info()->GetMessageExtraInfoVal;
3888 /***********************************************************************
3889 * SetMessageExtraInfo (USER32.@)
3891 LPARAM WINAPI SetMessageExtraInfo(LPARAM lParam)
3893 struct user_thread_info *thread_info = get_user_thread_info();
3894 LONG old_value = thread_info->GetMessageExtraInfoVal;
3895 thread_info->GetMessageExtraInfoVal = lParam;
3900 /***********************************************************************
3901 * WaitMessage (USER.112) Suspend thread pending messages
3902 * WaitMessage (USER32.@) Suspend thread pending messages
3904 * WaitMessage() suspends a thread until events appear in the thread's
3907 BOOL WINAPI WaitMessage(void)
3909 return (MsgWaitForMultipleObjectsEx( 0, NULL, INFINITE, QS_ALLINPUT, 0 ) != WAIT_FAILED);
3913 /***********************************************************************
3914 * MsgWaitForMultipleObjectsEx (USER32.@)
3916 DWORD WINAPI MsgWaitForMultipleObjectsEx( DWORD count, CONST HANDLE *pHandles,
3917 DWORD timeout, DWORD mask, DWORD flags )
3919 HANDLE handles[MAXIMUM_WAIT_OBJECTS];
3922 if (count > MAXIMUM_WAIT_OBJECTS-1)
3924 SetLastError( ERROR_INVALID_PARAMETER );
3928 /* set the queue mask */
3929 SERVER_START_REQ( set_queue_mask )
3931 req->wake_mask = (flags & MWMO_INPUTAVAILABLE) ? mask : 0;
3932 req->changed_mask = mask;
3934 wine_server_call( req );
3938 /* add the queue to the handle list */
3939 for (i = 0; i < count; i++) handles[i] = pHandles[i];
3940 handles[count] = get_server_queue_handle();
3942 return wow_handlers.wait_message( count+1, handles, timeout, mask, flags );
3946 /***********************************************************************
3947 * MsgWaitForMultipleObjects (USER32.@)
3949 DWORD WINAPI MsgWaitForMultipleObjects( DWORD count, CONST HANDLE *handles,
3950 BOOL wait_all, DWORD timeout, DWORD mask )
3952 return MsgWaitForMultipleObjectsEx( count, handles, timeout, mask,
3953 wait_all ? MWMO_WAITALL : 0 );
3957 /***********************************************************************
3958 * WaitForInputIdle (USER32.@)
3960 DWORD WINAPI WaitForInputIdle( HANDLE hProcess, DWORD dwTimeOut )
3962 DWORD start_time, elapsed, ret;
3965 handles[0] = hProcess;
3966 SERVER_START_REQ( get_process_idle_event )
3968 req->handle = wine_server_obj_handle( hProcess );
3969 wine_server_call_err( req );
3970 handles[1] = wine_server_ptr_handle( reply->event );
3973 if (!handles[1]) return WAIT_FAILED; /* no event to wait on */
3975 start_time = GetTickCount();
3978 TRACE("waiting for %p\n", handles[1] );
3981 ret = MsgWaitForMultipleObjects ( 2, handles, FALSE, dwTimeOut - elapsed, QS_SENDMESSAGE );
3986 case WAIT_OBJECT_0+2:
3987 process_sent_messages();
3991 TRACE("timeout or error\n");
3994 TRACE("finished\n");
3997 if (dwTimeOut != INFINITE)
3999 elapsed = GetTickCount() - start_time;
4000 if (elapsed > dwTimeOut)
4006 return WAIT_TIMEOUT;
4010 /***********************************************************************
4011 * RegisterWindowMessageA (USER32.@)
4012 * RegisterWindowMessage (USER.118)
4014 UINT WINAPI RegisterWindowMessageA( LPCSTR str )
4016 UINT ret = GlobalAddAtomA(str);
4017 TRACE("%s, ret=%x\n", str, ret);
4022 /***********************************************************************
4023 * RegisterWindowMessageW (USER32.@)
4025 UINT WINAPI RegisterWindowMessageW( LPCWSTR str )
4027 UINT ret = GlobalAddAtomW(str);
4028 TRACE("%s ret=%x\n", debugstr_w(str), ret);
4032 typedef struct BroadcastParm
4043 static BOOL CALLBACK bcast_childwindow( HWND hw, LPARAM lp )
4045 BroadcastParm *parm = (BroadcastParm*)lp;
4046 DWORD_PTR retval = 0;
4049 if (parm->flags & BSF_IGNORECURRENTTASK && WIN_IsCurrentProcess(hw))
4051 TRACE("Not telling myself %p\n", hw);
4055 /* I don't know 100% for sure if this is what Windows does, but it fits the tests */
4056 if (parm->flags & BSF_QUERY)
4058 TRACE("Telling window %p using SendMessageTimeout\n", hw);
4060 /* Not tested for conflicting flags */
4061 if (parm->flags & BSF_FORCEIFHUNG || parm->flags & BSF_NOHANG)
4062 lresult = SendMessageTimeoutW( hw, parm->msg, parm->wp, parm->lp, SMTO_ABORTIFHUNG, 2000, &retval );
4063 else if (parm->flags & BSF_NOTIMEOUTIFNOTHUNG)
4064 lresult = SendMessageTimeoutW( hw, parm->msg, parm->wp, parm->lp, SMTO_NOTIMEOUTIFNOTHUNG, 2000, &retval );
4066 lresult = SendMessageTimeoutW( hw, parm->msg, parm->wp, parm->lp, SMTO_NORMAL, 2000, &retval );
4068 if (!lresult && GetLastError() == ERROR_TIMEOUT)
4070 WARN("Timed out!\n");
4071 if (!(parm->flags & BSF_FORCEIFHUNG))
4074 if (retval == BROADCAST_QUERY_DENY)
4083 else if (parm->flags & BSF_POSTMESSAGE)
4085 TRACE("Telling window %p using PostMessage\n", hw);
4086 PostMessageW( hw, parm->msg, parm->wp, parm->lp );
4090 TRACE("Telling window %p using SendNotifyMessage\n", hw);
4091 SendNotifyMessageW( hw, parm->msg, parm->wp, parm->lp );
4097 static BOOL CALLBACK bcast_desktop( LPWSTR desktop, LPARAM lp )
4101 BroadcastParm *parm = (BroadcastParm*)lp;
4103 TRACE("desktop: %s\n", debugstr_w( desktop ));
4105 hdesktop = open_winstation_desktop( parm->winsta, desktop, 0, FALSE, DESKTOP_ENUMERATE|DESKTOP_WRITEOBJECTS|STANDARD_RIGHTS_WRITE );
4108 FIXME("Could not open desktop %s\n", debugstr_w(desktop));
4112 ret = EnumDesktopWindows( hdesktop, bcast_childwindow, lp );
4113 CloseDesktop(hdesktop);
4114 TRACE("-->%d\n", ret);
4115 return parm->success;
4118 static BOOL CALLBACK bcast_winsta( LPWSTR winsta, LPARAM lp )
4121 HWINSTA hwinsta = OpenWindowStationW( winsta, FALSE, WINSTA_ENUMDESKTOPS );
4122 TRACE("hwinsta: %p/%s/%08x\n", hwinsta, debugstr_w( winsta ), GetLastError());
4125 ((BroadcastParm *)lp)->winsta = hwinsta;
4126 ret = EnumDesktopsW( hwinsta, bcast_desktop, lp );
4127 CloseWindowStation( hwinsta );
4128 TRACE("-->%d\n", ret);
4132 /***********************************************************************
4133 * BroadcastSystemMessageA (USER32.@)
4134 * BroadcastSystemMessage (USER32.@)
4136 LONG WINAPI BroadcastSystemMessageA( DWORD flags, LPDWORD recipients, UINT msg, WPARAM wp, LPARAM lp )
4138 return BroadcastSystemMessageExA( flags, recipients, msg, wp, lp, NULL );
4142 /***********************************************************************
4143 * BroadcastSystemMessageW (USER32.@)
4145 LONG WINAPI BroadcastSystemMessageW( DWORD flags, LPDWORD recipients, UINT msg, WPARAM wp, LPARAM lp )
4147 return BroadcastSystemMessageExW( flags, recipients, msg, wp, lp, NULL );
4150 /***********************************************************************
4151 * BroadcastSystemMessageExA (USER32.@)
4153 LONG WINAPI BroadcastSystemMessageExA( DWORD flags, LPDWORD recipients, UINT msg, WPARAM wp, LPARAM lp, PBSMINFO pinfo )
4155 map_wparam_AtoW( msg, &wp, WMCHAR_MAP_NOMAPPING );
4156 return BroadcastSystemMessageExW( flags, recipients, msg, wp, lp, NULL );
4160 /***********************************************************************
4161 * BroadcastSystemMessageExW (USER32.@)
4163 LONG WINAPI BroadcastSystemMessageExW( DWORD flags, LPDWORD recipients, UINT msg, WPARAM wp, LPARAM lp, PBSMINFO pinfo )
4166 DWORD recips = BSM_ALLCOMPONENTS;
4168 static const DWORD all_flags = ( BSF_QUERY | BSF_IGNORECURRENTTASK | BSF_FLUSHDISK | BSF_NOHANG
4169 | BSF_POSTMESSAGE | BSF_FORCEIFHUNG | BSF_NOTIMEOUTIFNOTHUNG
4170 | BSF_ALLOWSFW | BSF_SENDNOTIFYMESSAGE | BSF_RETURNHDESK | BSF_LUID );
4172 TRACE("Flags: %08x, recipients: %p(0x%x), msg: %04x, wparam: %08lx, lparam: %08lx\n", flags, recipients,
4173 (recipients ? *recipients : recips), msg, wp, lp);
4175 if (flags & ~all_flags)
4177 SetLastError(ERROR_INVALID_PARAMETER);
4182 recipients = &recips;
4184 if ( pinfo && flags & BSF_QUERY )
4185 FIXME("Not returning PBSMINFO information yet\n");
4188 parm.recipients = recipients;
4192 parm.success = TRUE;
4194 if (*recipients & BSM_ALLDESKTOPS || *recipients == BSM_ALLCOMPONENTS)
4195 ret = EnumWindowStationsW(bcast_winsta, (LONG_PTR)&parm);
4196 else if (*recipients & BSM_APPLICATIONS)
4198 EnumWindows(bcast_childwindow, (LONG_PTR)&parm);
4202 FIXME("Recipients %08x not supported!\n", *recipients);
4207 /***********************************************************************
4208 * SetMessageQueue (USER32.@)
4210 BOOL WINAPI SetMessageQueue( INT size )
4212 /* now obsolete the message queue will be expanded dynamically as necessary */
4217 /***********************************************************************
4218 * MessageBeep (USER32.@)
4220 BOOL WINAPI MessageBeep( UINT i )
4223 SystemParametersInfoA( SPI_GETBEEP, 0, &active, FALSE );
4224 if (active) USER_Driver->pBeep();
4229 /***********************************************************************
4230 * SetTimer (USER32.@)
4232 UINT_PTR WINAPI SetTimer( HWND hwnd, UINT_PTR id, UINT timeout, TIMERPROC proc )
4235 WNDPROC winproc = 0;
4237 if (proc) winproc = WINPROC_AllocProc( (WNDPROC)proc, FALSE );
4239 SERVER_START_REQ( set_win_timer )
4241 req->win = wine_server_user_handle( hwnd );
4242 req->msg = WM_TIMER;
4244 req->rate = max( timeout, SYS_TIMER_RATE );
4245 req->lparam = (ULONG_PTR)winproc;
4246 if (!wine_server_call_err( req ))
4249 if (!ret) ret = TRUE;
4255 TRACE("Added %p %lx %p timeout %d\n", hwnd, id, winproc, timeout );
4260 /***********************************************************************
4261 * SetSystemTimer (USER32.@)
4263 UINT_PTR WINAPI SetSystemTimer( HWND hwnd, UINT_PTR id, UINT timeout, TIMERPROC proc )
4266 WNDPROC winproc = 0;
4268 if (proc) winproc = WINPROC_AllocProc( (WNDPROC)proc, FALSE );
4270 SERVER_START_REQ( set_win_timer )
4272 req->win = wine_server_user_handle( hwnd );
4273 req->msg = WM_SYSTIMER;
4275 req->rate = max( timeout, SYS_TIMER_RATE );
4276 req->lparam = (ULONG_PTR)winproc;
4277 if (!wine_server_call_err( req ))
4280 if (!ret) ret = TRUE;
4286 TRACE("Added %p %lx %p timeout %d\n", hwnd, id, winproc, timeout );
4291 /***********************************************************************
4292 * KillTimer (USER32.@)
4294 BOOL WINAPI KillTimer( HWND hwnd, UINT_PTR id )
4298 SERVER_START_REQ( kill_win_timer )
4300 req->win = wine_server_user_handle( hwnd );
4301 req->msg = WM_TIMER;
4303 ret = !wine_server_call_err( req );
4310 /***********************************************************************
4311 * KillSystemTimer (USER32.@)
4313 BOOL WINAPI KillSystemTimer( HWND hwnd, UINT_PTR id )
4317 SERVER_START_REQ( kill_win_timer )
4319 req->win = wine_server_user_handle( hwnd );
4320 req->msg = WM_SYSTIMER;
4322 ret = !wine_server_call_err( req );
4329 /**********************************************************************
4330 * IsGUIThread (USER32.@)
4332 BOOL WINAPI IsGUIThread( BOOL convert )
4334 FIXME( "%u: stub\n", convert );
4339 /**********************************************************************
4340 * GetGUIThreadInfo (USER32.@)
4342 BOOL WINAPI GetGUIThreadInfo( DWORD id, GUITHREADINFO *info )
4346 if (info->cbSize != sizeof(*info))
4348 SetLastError( ERROR_INVALID_PARAMETER );
4352 SERVER_START_REQ( get_thread_input )
4355 if ((ret = !wine_server_call_err( req )))
4358 info->hwndActive = wine_server_ptr_handle( reply->active );
4359 info->hwndFocus = wine_server_ptr_handle( reply->focus );
4360 info->hwndCapture = wine_server_ptr_handle( reply->capture );
4361 info->hwndMenuOwner = wine_server_ptr_handle( reply->menu_owner );
4362 info->hwndMoveSize = wine_server_ptr_handle( reply->move_size );
4363 info->hwndCaret = wine_server_ptr_handle( reply->caret );
4364 info->rcCaret.left = reply->rect.left;
4365 info->rcCaret.top = reply->rect.top;
4366 info->rcCaret.right = reply->rect.right;
4367 info->rcCaret.bottom = reply->rect.bottom;
4368 if (reply->menu_owner) info->flags |= GUI_INMENUMODE;
4369 if (reply->move_size) info->flags |= GUI_INMOVESIZE;
4370 if (reply->caret) info->flags |= GUI_CARETBLINKING;
4378 /******************************************************************
4379 * IsHungAppWindow (USER32.@)
4382 BOOL WINAPI IsHungAppWindow( HWND hWnd )
4386 SERVER_START_REQ( is_window_hung )
4388 req->win = wine_server_user_handle( hWnd );
4389 ret = !wine_server_call_err( req ) && reply->is_hung;
4395 /******************************************************************
4396 * ChangeWindowMessageFilter (USER32.@)
4398 BOOL WINAPI ChangeWindowMessageFilter( UINT message, DWORD flag )
4400 FIXME( "%x %08x\n", message, flag );