evr: Add a forward for MFGetStrideForBitmapInfoHeader().
[wine.git] / dlls / user32 / message.c
blob6f0f58a5f3f6e77f103b5d378c38e57f8578238b
1 /*
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
22 #include <assert.h>
23 #include <stdarg.h>
25 #define NONAMELESSUNION
26 #define NONAMELESSSTRUCT
27 #include "ntstatus.h"
28 #define WIN32_NO_STATUS
29 #include "windef.h"
30 #include "winbase.h"
31 #include "wingdi.h"
32 #include "winuser.h"
33 #include "winerror.h"
34 #include "winnls.h"
35 #include "dbt.h"
36 #include "dde.h"
37 #include "imm.h"
38 #include "hidusage.h"
39 #include "ddk/imm.h"
40 #include "wine/server.h"
41 #include "user_private.h"
42 #include "win.h"
43 #include "controls.h"
44 #include "wine/debug.h"
45 #include "wine/exception.h"
47 WINE_DEFAULT_DEBUG_CHANNEL(msg);
48 WINE_DECLARE_DEBUG_CHANNEL(relay);
49 WINE_DECLARE_DEBUG_CHANNEL(key);
51 #define WM_NCMOUSEFIRST WM_NCMOUSEMOVE
52 #define WM_NCMOUSELAST (WM_NCMOUSEFIRST+(WM_MOUSELAST-WM_MOUSEFIRST))
54 #define MAX_PACK_COUNT 4
56 /* the various structures that can be sent in messages, in platform-independent layout */
57 struct packed_CREATESTRUCTW
59 ULONGLONG lpCreateParams;
60 ULONGLONG hInstance;
61 user_handle_t hMenu;
62 DWORD __pad1;
63 user_handle_t hwndParent;
64 DWORD __pad2;
65 INT cy;
66 INT cx;
67 INT y;
68 INT x;
69 LONG style;
70 ULONGLONG lpszName;
71 ULONGLONG lpszClass;
72 DWORD dwExStyle;
73 DWORD __pad3;
76 struct packed_DRAWITEMSTRUCT
78 UINT CtlType;
79 UINT CtlID;
80 UINT itemID;
81 UINT itemAction;
82 UINT itemState;
83 user_handle_t hwndItem;
84 DWORD __pad1;
85 user_handle_t hDC;
86 DWORD __pad2;
87 RECT rcItem;
88 ULONGLONG itemData;
91 struct packed_MEASUREITEMSTRUCT
93 UINT CtlType;
94 UINT CtlID;
95 UINT itemID;
96 UINT itemWidth;
97 UINT itemHeight;
98 ULONGLONG itemData;
101 struct packed_DELETEITEMSTRUCT
103 UINT CtlType;
104 UINT CtlID;
105 UINT itemID;
106 user_handle_t hwndItem;
107 DWORD __pad;
108 ULONGLONG itemData;
111 struct packed_COMPAREITEMSTRUCT
113 UINT CtlType;
114 UINT CtlID;
115 user_handle_t hwndItem;
116 DWORD __pad1;
117 UINT itemID1;
118 ULONGLONG itemData1;
119 UINT itemID2;
120 ULONGLONG itemData2;
121 DWORD dwLocaleId;
122 DWORD __pad2;
125 struct packed_WINDOWPOS
127 user_handle_t hwnd;
128 DWORD __pad1;
129 user_handle_t hwndInsertAfter;
130 DWORD __pad2;
131 INT x;
132 INT y;
133 INT cx;
134 INT cy;
135 UINT flags;
136 DWORD __pad3;
139 struct packed_COPYDATASTRUCT
141 ULONGLONG dwData;
142 DWORD cbData;
143 ULONGLONG lpData;
146 struct packed_HELPINFO
148 UINT cbSize;
149 INT iContextType;
150 INT iCtrlId;
151 user_handle_t hItemHandle;
152 DWORD __pad;
153 ULONGLONG dwContextId;
154 POINT MousePos;
157 struct packed_NCCALCSIZE_PARAMS
159 RECT rgrc[3];
160 ULONGLONG __pad1;
161 user_handle_t hwnd;
162 DWORD __pad2;
163 user_handle_t hwndInsertAfter;
164 DWORD __pad3;
165 INT x;
166 INT y;
167 INT cx;
168 INT cy;
169 UINT flags;
170 DWORD __pad4;
173 struct packed_MSG
175 user_handle_t hwnd;
176 DWORD __pad1;
177 UINT message;
178 ULONGLONG wParam;
179 ULONGLONG lParam;
180 DWORD time;
181 POINT pt;
182 DWORD __pad2;
185 struct packed_MDINEXTMENU
187 user_handle_t hmenuIn;
188 DWORD __pad1;
189 user_handle_t hmenuNext;
190 DWORD __pad2;
191 user_handle_t hwndNext;
192 DWORD __pad3;
195 struct packed_MDICREATESTRUCTW
197 ULONGLONG szClass;
198 ULONGLONG szTitle;
199 ULONGLONG hOwner;
200 INT x;
201 INT y;
202 INT cx;
203 INT cy;
204 DWORD style;
205 ULONGLONG lParam;
208 struct packed_hook_extra_info
210 user_handle_t handle;
211 DWORD __pad;
212 ULONGLONG lparam;
215 /* the structures are unpacked on top of the packed ones, so make sure they fit */
216 C_ASSERT( sizeof(struct packed_CREATESTRUCTW) >= sizeof(CREATESTRUCTW) );
217 C_ASSERT( sizeof(struct packed_DRAWITEMSTRUCT) >= sizeof(DRAWITEMSTRUCT) );
218 C_ASSERT( sizeof(struct packed_MEASUREITEMSTRUCT) >= sizeof(MEASUREITEMSTRUCT) );
219 C_ASSERT( sizeof(struct packed_DELETEITEMSTRUCT) >= sizeof(DELETEITEMSTRUCT) );
220 C_ASSERT( sizeof(struct packed_COMPAREITEMSTRUCT) >= sizeof(COMPAREITEMSTRUCT) );
221 C_ASSERT( sizeof(struct packed_WINDOWPOS) >= sizeof(WINDOWPOS) );
222 C_ASSERT( sizeof(struct packed_COPYDATASTRUCT) >= sizeof(COPYDATASTRUCT) );
223 C_ASSERT( sizeof(struct packed_HELPINFO) >= sizeof(HELPINFO) );
224 C_ASSERT( sizeof(struct packed_NCCALCSIZE_PARAMS) >= sizeof(NCCALCSIZE_PARAMS) + sizeof(WINDOWPOS) );
225 C_ASSERT( sizeof(struct packed_MSG) >= sizeof(MSG) );
226 C_ASSERT( sizeof(struct packed_MDINEXTMENU) >= sizeof(MDINEXTMENU) );
227 C_ASSERT( sizeof(struct packed_MDICREATESTRUCTW) >= sizeof(MDICREATESTRUCTW) );
228 C_ASSERT( sizeof(struct packed_hook_extra_info) >= sizeof(struct hook_extra_info) );
230 union packed_structs
232 struct packed_CREATESTRUCTW cs;
233 struct packed_DRAWITEMSTRUCT dis;
234 struct packed_MEASUREITEMSTRUCT mis;
235 struct packed_DELETEITEMSTRUCT dls;
236 struct packed_COMPAREITEMSTRUCT cis;
237 struct packed_WINDOWPOS wp;
238 struct packed_COPYDATASTRUCT cds;
239 struct packed_HELPINFO hi;
240 struct packed_NCCALCSIZE_PARAMS ncp;
241 struct packed_MSG msg;
242 struct packed_MDINEXTMENU mnm;
243 struct packed_MDICREATESTRUCTW mcs;
244 struct packed_hook_extra_info hook;
247 /* description of the data fields that need to be packed along with a sent message */
248 struct packed_message
250 union packed_structs ps;
251 int count;
252 const void *data[MAX_PACK_COUNT];
253 size_t size[MAX_PACK_COUNT];
256 /* info about the message currently being received by the current thread */
257 struct received_message_info
259 enum message_type type;
260 MSG msg;
261 UINT flags; /* InSendMessageEx return flags */
264 /* structure to group all parameters for sent messages of the various kinds */
265 struct send_message_info
267 enum message_type type;
268 DWORD dest_tid;
269 HWND hwnd;
270 UINT msg;
271 WPARAM wparam;
272 LPARAM lparam;
273 UINT flags; /* flags for SendMessageTimeout */
274 UINT timeout; /* timeout for SendMessageTimeout */
275 SENDASYNCPROC callback; /* callback function for SendMessageCallback */
276 ULONG_PTR data; /* callback data */
277 enum wm_char_mapping wm_char;
280 static const INPUT_MESSAGE_SOURCE msg_source_unavailable = { IMDT_UNAVAILABLE, IMO_UNAVAILABLE };
283 /* Message class descriptor */
284 const struct builtin_class_descr MESSAGE_builtin_class =
286 L"Message", /* name */
287 0, /* style */
288 WINPROC_MESSAGE, /* proc */
289 0, /* extra */
290 0, /* cursor */
291 0 /* brush */
296 /* flag for messages that contain pointers */
297 /* 32 messages per entry, messages 0..31 map to bits 0..31 */
299 #define SET(msg) (1 << ((msg) & 31))
301 static const unsigned int message_pointer_flags[] =
303 /* 0x00 - 0x1f */
304 SET(WM_CREATE) | SET(WM_SETTEXT) | SET(WM_GETTEXT) |
305 SET(WM_WININICHANGE) | SET(WM_DEVMODECHANGE),
306 /* 0x20 - 0x3f */
307 SET(WM_GETMINMAXINFO) | SET(WM_DRAWITEM) | SET(WM_MEASUREITEM) | SET(WM_DELETEITEM) |
308 SET(WM_COMPAREITEM),
309 /* 0x40 - 0x5f */
310 SET(WM_WINDOWPOSCHANGING) | SET(WM_WINDOWPOSCHANGED) | SET(WM_COPYDATA) | SET(WM_HELP),
311 /* 0x60 - 0x7f */
312 SET(WM_STYLECHANGING) | SET(WM_STYLECHANGED),
313 /* 0x80 - 0x9f */
314 SET(WM_NCCREATE) | SET(WM_NCCALCSIZE) | SET(WM_GETDLGCODE),
315 /* 0xa0 - 0xbf */
316 SET(EM_GETSEL) | SET(EM_GETRECT) | SET(EM_SETRECT) | SET(EM_SETRECTNP),
317 /* 0xc0 - 0xdf */
318 SET(EM_REPLACESEL) | SET(EM_GETLINE) | SET(EM_SETTABSTOPS),
319 /* 0xe0 - 0xff */
320 SET(SBM_GETRANGE) | SET(SBM_SETSCROLLINFO) | SET(SBM_GETSCROLLINFO) | SET(SBM_GETSCROLLBARINFO),
321 /* 0x100 - 0x11f */
323 /* 0x120 - 0x13f */
325 /* 0x140 - 0x15f */
326 SET(CB_GETEDITSEL) | SET(CB_ADDSTRING) | SET(CB_DIR) | SET(CB_GETLBTEXT) |
327 SET(CB_INSERTSTRING) | SET(CB_FINDSTRING) | SET(CB_SELECTSTRING) |
328 SET(CB_GETDROPPEDCONTROLRECT) | SET(CB_FINDSTRINGEXACT),
329 /* 0x160 - 0x17f */
331 /* 0x180 - 0x19f */
332 SET(LB_ADDSTRING) | SET(LB_INSERTSTRING) | SET(LB_GETTEXT) | SET(LB_SELECTSTRING) |
333 SET(LB_DIR) | SET(LB_FINDSTRING) |
334 SET(LB_GETSELITEMS) | SET(LB_SETTABSTOPS) | SET(LB_ADDFILE) | SET(LB_GETITEMRECT),
335 /* 0x1a0 - 0x1bf */
336 SET(LB_FINDSTRINGEXACT),
337 /* 0x1c0 - 0x1df */
339 /* 0x1e0 - 0x1ff */
341 /* 0x200 - 0x21f */
342 SET(WM_NEXTMENU) | SET(WM_SIZING) | SET(WM_MOVING) | SET(WM_DEVICECHANGE),
343 /* 0x220 - 0x23f */
344 SET(WM_MDICREATE) | SET(WM_MDIGETACTIVE) | SET(WM_DROPOBJECT) |
345 SET(WM_QUERYDROPOBJECT) | SET(WM_DRAGLOOP) | SET(WM_DRAGSELECT) | SET(WM_DRAGMOVE),
346 /* 0x240 - 0x25f */
348 /* 0x260 - 0x27f */
350 /* 0x280 - 0x29f */
352 /* 0x2a0 - 0x2bf */
354 /* 0x2c0 - 0x2df */
356 /* 0x2e0 - 0x2ff */
358 /* 0x300 - 0x31f */
359 SET(WM_ASKCBFORMATNAME)
362 /* flags for messages that contain Unicode strings */
363 static const unsigned int message_unicode_flags[] =
365 /* 0x00 - 0x1f */
366 SET(WM_CREATE) | SET(WM_SETTEXT) | SET(WM_GETTEXT) | SET(WM_GETTEXTLENGTH) |
367 SET(WM_WININICHANGE) | SET(WM_DEVMODECHANGE),
368 /* 0x20 - 0x3f */
369 SET(WM_CHARTOITEM),
370 /* 0x40 - 0x5f */
372 /* 0x60 - 0x7f */
374 /* 0x80 - 0x9f */
375 SET(WM_NCCREATE),
376 /* 0xa0 - 0xbf */
378 /* 0xc0 - 0xdf */
379 SET(EM_REPLACESEL) | SET(EM_GETLINE) | SET(EM_SETPASSWORDCHAR),
380 /* 0xe0 - 0xff */
382 /* 0x100 - 0x11f */
383 SET(WM_CHAR) | SET(WM_DEADCHAR) | SET(WM_SYSCHAR) | SET(WM_SYSDEADCHAR),
384 /* 0x120 - 0x13f */
385 SET(WM_MENUCHAR),
386 /* 0x140 - 0x15f */
387 SET(CB_ADDSTRING) | SET(CB_DIR) | SET(CB_GETLBTEXT) | SET(CB_GETLBTEXTLEN) |
388 SET(CB_INSERTSTRING) | SET(CB_FINDSTRING) | SET(CB_SELECTSTRING) | SET(CB_FINDSTRINGEXACT),
389 /* 0x160 - 0x17f */
391 /* 0x180 - 0x19f */
392 SET(LB_ADDSTRING) | SET(LB_INSERTSTRING) | SET(LB_GETTEXT) | SET(LB_GETTEXTLEN) |
393 SET(LB_SELECTSTRING) | SET(LB_DIR) | SET(LB_FINDSTRING) | SET(LB_ADDFILE),
394 /* 0x1a0 - 0x1bf */
395 SET(LB_FINDSTRINGEXACT),
396 /* 0x1c0 - 0x1df */
398 /* 0x1e0 - 0x1ff */
400 /* 0x200 - 0x21f */
402 /* 0x220 - 0x23f */
403 SET(WM_MDICREATE),
404 /* 0x240 - 0x25f */
406 /* 0x260 - 0x27f */
408 /* 0x280 - 0x29f */
409 SET(WM_IME_CHAR),
410 /* 0x2a0 - 0x2bf */
412 /* 0x2c0 - 0x2df */
414 /* 0x2e0 - 0x2ff */
416 /* 0x300 - 0x31f */
417 SET(WM_PAINTCLIPBOARD) | SET(WM_SIZECLIPBOARD) | SET(WM_ASKCBFORMATNAME)
420 /* check whether a given message type includes pointers */
421 static inline BOOL is_pointer_message( UINT message, WPARAM wparam )
423 if (message >= 8*sizeof(message_pointer_flags)) return FALSE;
424 if (message == WM_DEVICECHANGE && !(wparam & 0x8000)) return FALSE;
425 return (message_pointer_flags[message / 32] & SET(message)) != 0;
428 /* check whether a given message type contains Unicode (or ASCII) chars */
429 static inline BOOL is_unicode_message( UINT message )
431 if (message >= 8*sizeof(message_unicode_flags)) return FALSE;
432 return (message_unicode_flags[message / 32] & SET(message)) != 0;
435 #undef SET
437 /* add a data field to a packed message */
438 static inline void push_data( struct packed_message *data, const void *ptr, size_t size )
440 data->data[data->count] = ptr;
441 data->size[data->count] = size;
442 data->count++;
445 /* add a string to a packed message */
446 static inline void push_string( struct packed_message *data, LPCWSTR str )
448 push_data( data, str, (lstrlenW(str) + 1) * sizeof(WCHAR) );
451 /* make sure that the buffer contains a valid null-terminated Unicode string */
452 static inline BOOL check_string( LPCWSTR str, size_t size )
454 for (size /= sizeof(WCHAR); size; size--, str++)
455 if (!*str) return TRUE;
456 return FALSE;
459 /* pack a pointer into a 32/64 portable format */
460 static inline ULONGLONG pack_ptr( const void *ptr )
462 return (ULONG_PTR)ptr;
465 /* unpack a potentially 64-bit pointer, returning 0 when truncated */
466 static inline void *unpack_ptr( ULONGLONG ptr64 )
468 if ((ULONG_PTR)ptr64 != ptr64) return 0;
469 return (void *)(ULONG_PTR)ptr64;
472 /* make sure that there is space for 'size' bytes in buffer, growing it if needed */
473 static inline void *get_buffer_space( void **buffer, size_t size )
475 void *ret;
477 if (*buffer)
479 if (!(ret = HeapReAlloc( GetProcessHeap(), 0, *buffer, size )))
480 HeapFree( GetProcessHeap(), 0, *buffer );
482 else ret = HeapAlloc( GetProcessHeap(), 0, size );
484 *buffer = ret;
485 return ret;
488 /* check whether a combobox expects strings or ids in CB_ADDSTRING/CB_INSERTSTRING */
489 static inline BOOL combobox_has_strings( HWND hwnd )
491 DWORD style = GetWindowLongA( hwnd, GWL_STYLE );
492 return (!(style & (CBS_OWNERDRAWFIXED | CBS_OWNERDRAWVARIABLE)) || (style & CBS_HASSTRINGS));
495 /* check whether a listbox expects strings or ids in LB_ADDSTRING/LB_INSERTSTRING */
496 static inline BOOL listbox_has_strings( HWND hwnd )
498 DWORD style = GetWindowLongA( hwnd, GWL_STYLE );
499 return (!(style & (LBS_OWNERDRAWFIXED | LBS_OWNERDRAWVARIABLE)) || (style & LBS_HASSTRINGS));
502 /* check whether message is in the range of keyboard messages */
503 static inline BOOL is_keyboard_message( UINT message )
505 return (message >= WM_KEYFIRST && message <= WM_KEYLAST);
508 /* check whether message is in the range of mouse messages */
509 static inline BOOL is_mouse_message( UINT message )
511 return ((message >= WM_NCMOUSEFIRST && message <= WM_NCMOUSELAST) ||
512 (message >= WM_MOUSEFIRST && message <= WM_MOUSELAST));
515 /* check whether message matches the specified hwnd filter */
516 static inline BOOL check_hwnd_filter( const MSG *msg, HWND hwnd_filter )
518 if (!hwnd_filter || hwnd_filter == GetDesktopWindow()) return TRUE;
519 return (msg->hwnd == hwnd_filter || IsChild( hwnd_filter, msg->hwnd ));
522 /* check for pending WM_CHAR message with DBCS trailing byte */
523 static inline BOOL get_pending_wmchar( MSG *msg, UINT first, UINT last, BOOL remove )
525 struct wm_char_mapping_data *data = get_user_thread_info()->wmchar_data;
527 if (!data || !data->get_msg.message) return FALSE;
528 if ((first || last) && (first > WM_CHAR || last < WM_CHAR)) return FALSE;
529 if (!msg) return FALSE;
530 *msg = data->get_msg;
531 if (remove) data->get_msg.message = 0;
532 return TRUE;
536 /***********************************************************************
537 * MessageWndProc
539 * Window procedure for "Message" windows (HWND_MESSAGE parent).
541 LRESULT WINAPI MessageWndProc( HWND hwnd, UINT message, WPARAM wParam, LPARAM lParam )
543 if (message == WM_NCCREATE) return TRUE;
544 return 0; /* all other messages are ignored */
548 /***********************************************************************
549 * broadcast_message_callback
551 * Helper callback for broadcasting messages.
553 static BOOL CALLBACK broadcast_message_callback( HWND hwnd, LPARAM lparam )
555 struct send_message_info *info = (struct send_message_info *)lparam;
556 if ((GetWindowLongW( hwnd, GWL_STYLE ) & (WS_POPUP|WS_CHILD)) == WS_CHILD)
557 return TRUE;
558 switch(info->type)
560 case MSG_UNICODE:
561 SendMessageTimeoutW( hwnd, info->msg, info->wparam, info->lparam,
562 info->flags, info->timeout, NULL );
563 break;
564 case MSG_ASCII:
565 SendMessageTimeoutA( hwnd, info->msg, info->wparam, info->lparam,
566 info->flags, info->timeout, NULL );
567 break;
568 case MSG_NOTIFY:
569 SendNotifyMessageW( hwnd, info->msg, info->wparam, info->lparam );
570 break;
571 case MSG_CALLBACK:
572 SendMessageCallbackW( hwnd, info->msg, info->wparam, info->lparam,
573 info->callback, info->data );
574 break;
575 case MSG_POSTED:
576 PostMessageW( hwnd, info->msg, info->wparam, info->lparam );
577 break;
578 default:
579 ERR( "bad type %d\n", info->type );
580 break;
582 return TRUE;
585 DWORD get_input_codepage( void )
587 DWORD cp;
588 int ret;
589 HKL hkl = GetKeyboardLayout( 0 );
591 ret = GetLocaleInfoW( LOWORD(hkl), LOCALE_IDEFAULTANSICODEPAGE | LOCALE_RETURN_NUMBER,
592 (WCHAR *)&cp, sizeof(cp) / sizeof(WCHAR) );
593 if (!ret) cp = CP_ACP;
594 return cp;
597 /***********************************************************************
598 * map_wparam_AtoW
600 * Convert the wparam of an ASCII message to Unicode.
602 BOOL map_wparam_AtoW( UINT message, WPARAM *wparam, enum wm_char_mapping mapping )
604 char ch[2];
605 WCHAR wch[2];
606 DWORD cp;
608 wch[0] = wch[1] = 0;
609 switch(message)
611 case WM_CHAR:
612 /* WM_CHAR is magic: a DBCS char can be sent/posted as two consecutive WM_CHAR
613 * messages, in which case the first char is stored, and the conversion
614 * to Unicode only takes place once the second char is sent/posted.
616 if (mapping != WMCHAR_MAP_NOMAPPING)
618 struct wm_char_mapping_data *data = get_user_thread_info()->wmchar_data;
619 BYTE low = LOBYTE(*wparam);
620 cp = get_input_codepage();
622 if (HIBYTE(*wparam))
624 ch[0] = low;
625 ch[1] = HIBYTE(*wparam);
626 MultiByteToWideChar( cp, 0, ch, 2, wch, 2 );
627 TRACE( "map %02x,%02x -> %04x mapping %u\n", (BYTE)ch[0], (BYTE)ch[1], wch[0], mapping );
628 if (data) data->lead_byte[mapping] = 0;
630 else if (data && data->lead_byte[mapping])
632 ch[0] = data->lead_byte[mapping];
633 ch[1] = low;
634 MultiByteToWideChar( cp, 0, ch, 2, wch, 2 );
635 TRACE( "map stored %02x,%02x -> %04x mapping %u\n", (BYTE)ch[0], (BYTE)ch[1], wch[0], mapping );
636 data->lead_byte[mapping] = 0;
638 else if (!IsDBCSLeadByte( low ))
640 ch[0] = low;
641 MultiByteToWideChar( cp, 0, ch, 1, wch, 2 );
642 TRACE( "map %02x -> %04x\n", (BYTE)ch[0], wch[0] );
643 if (data) data->lead_byte[mapping] = 0;
645 else /* store it and wait for trail byte */
647 if (!data)
649 if (!(data = HeapAlloc( GetProcessHeap(), HEAP_ZERO_MEMORY, sizeof(*data) )))
650 return FALSE;
651 get_user_thread_info()->wmchar_data = data;
653 TRACE( "storing lead byte %02x mapping %u\n", low, mapping );
654 data->lead_byte[mapping] = low;
655 return FALSE;
657 *wparam = MAKEWPARAM(wch[0], wch[1]);
658 break;
660 /* else fall through */
661 case WM_CHARTOITEM:
662 case EM_SETPASSWORDCHAR:
663 case WM_DEADCHAR:
664 case WM_SYSCHAR:
665 case WM_SYSDEADCHAR:
666 case WM_MENUCHAR:
667 cp = get_input_codepage();
668 ch[0] = LOBYTE(*wparam);
669 ch[1] = HIBYTE(*wparam);
670 MultiByteToWideChar( cp, 0, ch, 2, wch, 2 );
671 *wparam = MAKEWPARAM(wch[0], wch[1]);
672 break;
673 case WM_IME_CHAR:
674 cp = get_input_codepage();
675 ch[0] = HIBYTE(*wparam);
676 ch[1] = LOBYTE(*wparam);
677 if (ch[0]) MultiByteToWideChar( cp, 0, ch, 2, wch, 2 );
678 else MultiByteToWideChar( cp, 0, ch + 1, 1, wch, 1 );
679 *wparam = MAKEWPARAM(wch[0], HIWORD(*wparam));
680 break;
682 return TRUE;
686 /***********************************************************************
687 * map_wparam_WtoA
689 * Convert the wparam of a Unicode message to ASCII.
691 static void map_wparam_WtoA( MSG *msg, BOOL remove )
693 BYTE ch[4];
694 WCHAR wch[2];
695 DWORD len;
696 DWORD cp;
698 switch(msg->message)
700 case WM_CHAR:
701 if (!HIWORD(msg->wParam))
703 cp = get_input_codepage();
704 wch[0] = LOWORD(msg->wParam);
705 ch[0] = ch[1] = 0;
706 len = WideCharToMultiByte( cp, 0, wch, 1, (LPSTR)ch, 2, NULL, NULL );
707 if (len == 2) /* DBCS char */
709 struct wm_char_mapping_data *data = get_user_thread_info()->wmchar_data;
710 if (!data)
712 if (!(data = HeapAlloc( GetProcessHeap(), HEAP_ZERO_MEMORY, sizeof(*data) ))) return;
713 get_user_thread_info()->wmchar_data = data;
715 if (remove)
717 data->get_msg = *msg;
718 data->get_msg.wParam = ch[1];
720 msg->wParam = ch[0];
721 return;
724 /* else fall through */
725 case WM_CHARTOITEM:
726 case EM_SETPASSWORDCHAR:
727 case WM_DEADCHAR:
728 case WM_SYSCHAR:
729 case WM_SYSDEADCHAR:
730 case WM_MENUCHAR:
731 cp = get_input_codepage();
732 wch[0] = LOWORD(msg->wParam);
733 wch[1] = HIWORD(msg->wParam);
734 ch[0] = ch[1] = 0;
735 WideCharToMultiByte( cp, 0, wch, 2, (LPSTR)ch, 4, NULL, NULL );
736 msg->wParam = MAKEWPARAM( ch[0] | (ch[1] << 8), 0 );
737 break;
738 case WM_IME_CHAR:
739 cp = get_input_codepage();
740 wch[0] = LOWORD(msg->wParam);
741 ch[0] = ch[1] = 0;
742 len = WideCharToMultiByte( cp, 0, wch, 1, (LPSTR)ch, 2, NULL, NULL );
743 if (len == 2)
744 msg->wParam = MAKEWPARAM( (ch[0] << 8) | ch[1], HIWORD(msg->wParam) );
745 else
746 msg->wParam = MAKEWPARAM( ch[0], HIWORD(msg->wParam) );
747 break;
752 /***********************************************************************
753 * pack_message
755 * Pack a message for sending to another process.
756 * Return the size of the data we expect in the message reply.
757 * Set data->count to -1 if there is an error.
759 static size_t pack_message( HWND hwnd, UINT message, WPARAM wparam, LPARAM lparam,
760 struct packed_message *data )
762 data->count = 0;
763 switch(message)
765 case WM_NCCREATE:
766 case WM_CREATE:
768 CREATESTRUCTW *cs = (CREATESTRUCTW *)lparam;
769 data->ps.cs.lpCreateParams = pack_ptr( cs->lpCreateParams );
770 data->ps.cs.hInstance = pack_ptr( cs->hInstance );
771 data->ps.cs.hMenu = wine_server_user_handle( cs->hMenu );
772 data->ps.cs.hwndParent = wine_server_user_handle( cs->hwndParent );
773 data->ps.cs.cy = cs->cy;
774 data->ps.cs.cx = cs->cx;
775 data->ps.cs.y = cs->y;
776 data->ps.cs.x = cs->x;
777 data->ps.cs.style = cs->style;
778 data->ps.cs.dwExStyle = cs->dwExStyle;
779 data->ps.cs.lpszName = pack_ptr( cs->lpszName );
780 data->ps.cs.lpszClass = pack_ptr( cs->lpszClass );
781 push_data( data, &data->ps.cs, sizeof(data->ps.cs) );
782 if (!IS_INTRESOURCE(cs->lpszName)) push_string( data, cs->lpszName );
783 if (!IS_INTRESOURCE(cs->lpszClass)) push_string( data, cs->lpszClass );
784 return sizeof(data->ps.cs);
786 case WM_GETTEXT:
787 case WM_ASKCBFORMATNAME:
788 return wparam * sizeof(WCHAR);
789 case WM_WININICHANGE:
790 if (lparam) push_string(data, (LPWSTR)lparam );
791 return 0;
792 case WM_SETTEXT:
793 case WM_DEVMODECHANGE:
794 case CB_DIR:
795 case LB_DIR:
796 case LB_ADDFILE:
797 case EM_REPLACESEL:
798 push_string( data, (LPWSTR)lparam );
799 return 0;
800 case WM_GETMINMAXINFO:
801 push_data( data, (MINMAXINFO *)lparam, sizeof(MINMAXINFO) );
802 return sizeof(MINMAXINFO);
803 case WM_DRAWITEM:
805 DRAWITEMSTRUCT *dis = (DRAWITEMSTRUCT *)lparam;
806 data->ps.dis.CtlType = dis->CtlType;
807 data->ps.dis.CtlID = dis->CtlID;
808 data->ps.dis.itemID = dis->itemID;
809 data->ps.dis.itemAction = dis->itemAction;
810 data->ps.dis.itemState = dis->itemState;
811 data->ps.dis.hwndItem = wine_server_user_handle( dis->hwndItem );
812 data->ps.dis.hDC = wine_server_user_handle( dis->hDC ); /* FIXME */
813 data->ps.dis.rcItem = dis->rcItem;
814 data->ps.dis.itemData = dis->itemData;
815 push_data( data, &data->ps.dis, sizeof(data->ps.dis) );
816 return 0;
818 case WM_MEASUREITEM:
820 MEASUREITEMSTRUCT *mis = (MEASUREITEMSTRUCT *)lparam;
821 data->ps.mis.CtlType = mis->CtlType;
822 data->ps.mis.CtlID = mis->CtlID;
823 data->ps.mis.itemID = mis->itemID;
824 data->ps.mis.itemWidth = mis->itemWidth;
825 data->ps.mis.itemHeight = mis->itemHeight;
826 data->ps.mis.itemData = mis->itemData;
827 push_data( data, &data->ps.mis, sizeof(data->ps.mis) );
828 return sizeof(data->ps.mis);
830 case WM_DELETEITEM:
832 DELETEITEMSTRUCT *dls = (DELETEITEMSTRUCT *)lparam;
833 data->ps.dls.CtlType = dls->CtlType;
834 data->ps.dls.CtlID = dls->CtlID;
835 data->ps.dls.itemID = dls->itemID;
836 data->ps.dls.hwndItem = wine_server_user_handle( dls->hwndItem );
837 data->ps.dls.itemData = dls->itemData;
838 push_data( data, &data->ps.dls, sizeof(data->ps.dls) );
839 return 0;
841 case WM_COMPAREITEM:
843 COMPAREITEMSTRUCT *cis = (COMPAREITEMSTRUCT *)lparam;
844 data->ps.cis.CtlType = cis->CtlType;
845 data->ps.cis.CtlID = cis->CtlID;
846 data->ps.cis.hwndItem = wine_server_user_handle( cis->hwndItem );
847 data->ps.cis.itemID1 = cis->itemID1;
848 data->ps.cis.itemData1 = cis->itemData1;
849 data->ps.cis.itemID2 = cis->itemID2;
850 data->ps.cis.itemData2 = cis->itemData2;
851 data->ps.cis.dwLocaleId = cis->dwLocaleId;
852 push_data( data, &data->ps.cis, sizeof(data->ps.cis) );
853 return 0;
855 case WM_WINE_SETWINDOWPOS:
856 case WM_WINDOWPOSCHANGING:
857 case WM_WINDOWPOSCHANGED:
859 WINDOWPOS *wp = (WINDOWPOS *)lparam;
860 data->ps.wp.hwnd = wine_server_user_handle( wp->hwnd );
861 data->ps.wp.hwndInsertAfter = wine_server_user_handle( wp->hwndInsertAfter );
862 data->ps.wp.x = wp->x;
863 data->ps.wp.y = wp->y;
864 data->ps.wp.cx = wp->cx;
865 data->ps.wp.cy = wp->cy;
866 data->ps.wp.flags = wp->flags;
867 push_data( data, &data->ps.wp, sizeof(data->ps.wp) );
868 return sizeof(data->ps.wp);
870 case WM_COPYDATA:
872 COPYDATASTRUCT *cds = (COPYDATASTRUCT *)lparam;
873 data->ps.cds.cbData = cds->cbData;
874 data->ps.cds.dwData = cds->dwData;
875 data->ps.cds.lpData = pack_ptr( cds->lpData );
876 push_data( data, &data->ps.cds, sizeof(data->ps.cds) );
877 if (cds->lpData) push_data( data, cds->lpData, cds->cbData );
878 return 0;
880 case WM_NOTIFY:
881 /* WM_NOTIFY cannot be sent across processes (MSDN) */
882 data->count = -1;
883 return 0;
884 case WM_HELP:
886 HELPINFO *hi = (HELPINFO *)lparam;
887 data->ps.hi.iContextType = hi->iContextType;
888 data->ps.hi.iCtrlId = hi->iCtrlId;
889 data->ps.hi.hItemHandle = wine_server_user_handle( hi->hItemHandle );
890 data->ps.hi.dwContextId = hi->dwContextId;
891 data->ps.hi.MousePos = hi->MousePos;
892 push_data( data, &data->ps.hi, sizeof(data->ps.hi) );
893 return 0;
895 case WM_STYLECHANGING:
896 case WM_STYLECHANGED:
897 push_data( data, (STYLESTRUCT *)lparam, sizeof(STYLESTRUCT) );
898 return 0;
899 case WM_NCCALCSIZE:
900 if (!wparam)
902 push_data( data, (RECT *)lparam, sizeof(RECT) );
903 return sizeof(RECT);
905 else
907 NCCALCSIZE_PARAMS *ncp = (NCCALCSIZE_PARAMS *)lparam;
908 data->ps.ncp.rgrc[0] = ncp->rgrc[0];
909 data->ps.ncp.rgrc[1] = ncp->rgrc[1];
910 data->ps.ncp.rgrc[2] = ncp->rgrc[2];
911 data->ps.ncp.hwnd = wine_server_user_handle( ncp->lppos->hwnd );
912 data->ps.ncp.hwndInsertAfter = wine_server_user_handle( ncp->lppos->hwndInsertAfter );
913 data->ps.ncp.x = ncp->lppos->x;
914 data->ps.ncp.y = ncp->lppos->y;
915 data->ps.ncp.cx = ncp->lppos->cx;
916 data->ps.ncp.cy = ncp->lppos->cy;
917 data->ps.ncp.flags = ncp->lppos->flags;
918 push_data( data, &data->ps.ncp, sizeof(data->ps.ncp) );
919 return sizeof(data->ps.ncp);
921 case WM_GETDLGCODE:
922 if (lparam)
924 MSG *msg = (MSG *)lparam;
925 data->ps.msg.hwnd = wine_server_user_handle( msg->hwnd );
926 data->ps.msg.message = msg->message;
927 data->ps.msg.wParam = msg->wParam;
928 data->ps.msg.lParam = msg->lParam;
929 data->ps.msg.time = msg->time;
930 data->ps.msg.pt = msg->pt;
931 push_data( data, &data->ps.msg, sizeof(data->ps.msg) );
932 return sizeof(data->ps.msg);
934 return 0;
935 case SBM_SETSCROLLINFO:
936 push_data( data, (SCROLLINFO *)lparam, sizeof(SCROLLINFO) );
937 return 0;
938 case SBM_GETSCROLLINFO:
939 push_data( data, (SCROLLINFO *)lparam, sizeof(SCROLLINFO) );
940 return sizeof(SCROLLINFO);
941 case SBM_GETSCROLLBARINFO:
943 const SCROLLBARINFO *info = (const SCROLLBARINFO *)lparam;
944 size_t size = min( info->cbSize, sizeof(SCROLLBARINFO) );
945 push_data( data, info, size );
946 return size;
948 case EM_GETSEL:
949 case SBM_GETRANGE:
950 case CB_GETEDITSEL:
952 size_t size = 0;
953 if (wparam) size += sizeof(DWORD);
954 if (lparam) size += sizeof(DWORD);
955 return size;
957 case EM_GETRECT:
958 case LB_GETITEMRECT:
959 case CB_GETDROPPEDCONTROLRECT:
960 return sizeof(RECT);
961 case EM_SETRECT:
962 case EM_SETRECTNP:
963 push_data( data, (RECT *)lparam, sizeof(RECT) );
964 return 0;
965 case EM_GETLINE:
967 WORD *pw = (WORD *)lparam;
968 push_data( data, pw, sizeof(*pw) );
969 return *pw * sizeof(WCHAR);
971 case EM_SETTABSTOPS:
972 case LB_SETTABSTOPS:
973 if (wparam) push_data( data, (UINT *)lparam, sizeof(UINT) * wparam );
974 return 0;
975 case CB_ADDSTRING:
976 case CB_INSERTSTRING:
977 case CB_FINDSTRING:
978 case CB_FINDSTRINGEXACT:
979 case CB_SELECTSTRING:
980 if (combobox_has_strings( hwnd )) push_string( data, (LPWSTR)lparam );
981 return 0;
982 case CB_GETLBTEXT:
983 if (!combobox_has_strings( hwnd )) return sizeof(ULONG_PTR);
984 return (SendMessageW( hwnd, CB_GETLBTEXTLEN, wparam, 0 ) + 1) * sizeof(WCHAR);
985 case LB_ADDSTRING:
986 case LB_INSERTSTRING:
987 case LB_FINDSTRING:
988 case LB_FINDSTRINGEXACT:
989 case LB_SELECTSTRING:
990 if (listbox_has_strings( hwnd )) push_string( data, (LPWSTR)lparam );
991 return 0;
992 case LB_GETTEXT:
993 if (!listbox_has_strings( hwnd )) return sizeof(ULONG_PTR);
994 return (SendMessageW( hwnd, LB_GETTEXTLEN, wparam, 0 ) + 1) * sizeof(WCHAR);
995 case LB_GETSELITEMS:
996 return wparam * sizeof(UINT);
997 case WM_NEXTMENU:
999 MDINEXTMENU *mnm = (MDINEXTMENU *)lparam;
1000 data->ps.mnm.hmenuIn = wine_server_user_handle( mnm->hmenuIn );
1001 data->ps.mnm.hmenuNext = wine_server_user_handle( mnm->hmenuNext );
1002 data->ps.mnm.hwndNext = wine_server_user_handle( mnm->hwndNext );
1003 push_data( data, &data->ps.mnm, sizeof(data->ps.mnm) );
1004 return sizeof(data->ps.mnm);
1006 case WM_SIZING:
1007 case WM_MOVING:
1008 push_data( data, (RECT *)lparam, sizeof(RECT) );
1009 return sizeof(RECT);
1010 case WM_MDICREATE:
1012 MDICREATESTRUCTW *mcs = (MDICREATESTRUCTW *)lparam;
1013 data->ps.mcs.szClass = pack_ptr( mcs->szClass );
1014 data->ps.mcs.szTitle = pack_ptr( mcs->szTitle );
1015 data->ps.mcs.hOwner = pack_ptr( mcs->hOwner );
1016 data->ps.mcs.x = mcs->x;
1017 data->ps.mcs.y = mcs->y;
1018 data->ps.mcs.cx = mcs->cx;
1019 data->ps.mcs.cy = mcs->cy;
1020 data->ps.mcs.style = mcs->style;
1021 data->ps.mcs.lParam = mcs->lParam;
1022 push_data( data, &data->ps.mcs, sizeof(data->ps.mcs) );
1023 if (!IS_INTRESOURCE(mcs->szClass)) push_string( data, mcs->szClass );
1024 if (!IS_INTRESOURCE(mcs->szTitle)) push_string( data, mcs->szTitle );
1025 return sizeof(data->ps.mcs);
1027 case WM_MDIGETACTIVE:
1028 if (lparam) return sizeof(BOOL);
1029 return 0;
1030 case WM_DEVICECHANGE:
1032 DEV_BROADCAST_HDR *header = (DEV_BROADCAST_HDR *)lparam;
1033 if ((wparam & 0x8000) && header) push_data( data, header, header->dbch_size );
1034 return 0;
1036 case WM_WINE_KEYBOARD_LL_HOOK:
1038 struct hook_extra_info *h_extra = (struct hook_extra_info *)lparam;
1039 data->ps.hook.handle = wine_server_user_handle( h_extra->handle );
1040 push_data( data, &data->ps.hook, sizeof(data->ps.hook) );
1041 push_data( data, (LPVOID)h_extra->lparam, sizeof(KBDLLHOOKSTRUCT) );
1042 return 0;
1044 case WM_WINE_MOUSE_LL_HOOK:
1046 struct hook_extra_info *h_extra = (struct hook_extra_info *)lparam;
1047 data->ps.hook.handle = wine_server_user_handle( h_extra->handle );
1048 push_data( data, &data->ps.hook, sizeof(data->ps.hook) );
1049 push_data( data, (LPVOID)h_extra->lparam, sizeof(MSLLHOOKSTRUCT) );
1050 return 0;
1052 case WM_NCPAINT:
1053 if (wparam <= 1) return 0;
1054 FIXME( "WM_NCPAINT hdc packing not supported yet\n" );
1055 data->count = -1;
1056 return 0;
1057 case WM_PAINT:
1058 if (!wparam) return 0;
1059 /* fall through */
1061 /* these contain an HFONT */
1062 case WM_SETFONT:
1063 case WM_GETFONT:
1064 /* these contain an HDC */
1065 case WM_ERASEBKGND:
1066 case WM_ICONERASEBKGND:
1067 case WM_CTLCOLORMSGBOX:
1068 case WM_CTLCOLOREDIT:
1069 case WM_CTLCOLORLISTBOX:
1070 case WM_CTLCOLORBTN:
1071 case WM_CTLCOLORDLG:
1072 case WM_CTLCOLORSCROLLBAR:
1073 case WM_CTLCOLORSTATIC:
1074 case WM_PRINT:
1075 case WM_PRINTCLIENT:
1076 /* these contain an HGLOBAL */
1077 case WM_PAINTCLIPBOARD:
1078 case WM_SIZECLIPBOARD:
1079 /* these contain HICON */
1080 case WM_GETICON:
1081 case WM_SETICON:
1082 case WM_QUERYDRAGICON:
1083 case WM_QUERYPARKICON:
1084 /* these contain pointers */
1085 case WM_DROPOBJECT:
1086 case WM_QUERYDROPOBJECT:
1087 case WM_DRAGLOOP:
1088 case WM_DRAGSELECT:
1089 case WM_DRAGMOVE:
1090 FIXME( "msg %x (%s) not supported yet\n", message, SPY_GetMsgName(message, hwnd) );
1091 data->count = -1;
1092 return 0;
1094 return 0;
1098 /***********************************************************************
1099 * unpack_message
1101 * Unpack a message received from another process.
1103 static BOOL unpack_message( HWND hwnd, UINT message, WPARAM *wparam, LPARAM *lparam,
1104 void **buffer, size_t size )
1106 size_t minsize = 0;
1107 union packed_structs *ps = *buffer;
1109 switch(message)
1111 case WM_NCCREATE:
1112 case WM_CREATE:
1114 CREATESTRUCTW cs;
1115 WCHAR *str = (WCHAR *)(&ps->cs + 1);
1116 if (size < sizeof(ps->cs)) return FALSE;
1117 size -= sizeof(ps->cs);
1118 cs.lpCreateParams = unpack_ptr( ps->cs.lpCreateParams );
1119 cs.hInstance = unpack_ptr( ps->cs.hInstance );
1120 cs.hMenu = wine_server_ptr_handle( ps->cs.hMenu );
1121 cs.hwndParent = wine_server_ptr_handle( ps->cs.hwndParent );
1122 cs.cy = ps->cs.cy;
1123 cs.cx = ps->cs.cx;
1124 cs.y = ps->cs.y;
1125 cs.x = ps->cs.x;
1126 cs.style = ps->cs.style;
1127 cs.dwExStyle = ps->cs.dwExStyle;
1128 cs.lpszName = unpack_ptr( ps->cs.lpszName );
1129 cs.lpszClass = unpack_ptr( ps->cs.lpszClass );
1130 if (ps->cs.lpszName >> 16)
1132 if (!check_string( str, size )) return FALSE;
1133 cs.lpszName = str;
1134 size -= (lstrlenW(str) + 1) * sizeof(WCHAR);
1135 str += lstrlenW(str) + 1;
1137 if (ps->cs.lpszClass >> 16)
1139 if (!check_string( str, size )) return FALSE;
1140 cs.lpszClass = str;
1142 memcpy( &ps->cs, &cs, sizeof(cs) );
1143 break;
1145 case WM_GETTEXT:
1146 case WM_ASKCBFORMATNAME:
1147 if (!get_buffer_space( buffer, (*wparam * sizeof(WCHAR)) )) return FALSE;
1148 break;
1149 case WM_WININICHANGE:
1150 if (!*lparam) return TRUE;
1151 /* fall through */
1152 case WM_SETTEXT:
1153 case WM_DEVMODECHANGE:
1154 case CB_DIR:
1155 case LB_DIR:
1156 case LB_ADDFILE:
1157 case EM_REPLACESEL:
1158 if (!check_string( *buffer, size )) return FALSE;
1159 break;
1160 case WM_GETMINMAXINFO:
1161 minsize = sizeof(MINMAXINFO);
1162 break;
1163 case WM_DRAWITEM:
1165 DRAWITEMSTRUCT dis;
1166 if (size < sizeof(ps->dis)) return FALSE;
1167 dis.CtlType = ps->dis.CtlType;
1168 dis.CtlID = ps->dis.CtlID;
1169 dis.itemID = ps->dis.itemID;
1170 dis.itemAction = ps->dis.itemAction;
1171 dis.itemState = ps->dis.itemState;
1172 dis.hwndItem = wine_server_ptr_handle( ps->dis.hwndItem );
1173 dis.hDC = wine_server_ptr_handle( ps->dis.hDC );
1174 dis.rcItem = ps->dis.rcItem;
1175 dis.itemData = (ULONG_PTR)unpack_ptr( ps->dis.itemData );
1176 memcpy( &ps->dis, &dis, sizeof(dis) );
1177 break;
1179 case WM_MEASUREITEM:
1181 MEASUREITEMSTRUCT mis;
1182 if (size < sizeof(ps->mis)) return FALSE;
1183 mis.CtlType = ps->mis.CtlType;
1184 mis.CtlID = ps->mis.CtlID;
1185 mis.itemID = ps->mis.itemID;
1186 mis.itemWidth = ps->mis.itemWidth;
1187 mis.itemHeight = ps->mis.itemHeight;
1188 mis.itemData = (ULONG_PTR)unpack_ptr( ps->mis.itemData );
1189 memcpy( &ps->mis, &mis, sizeof(mis) );
1190 break;
1192 case WM_DELETEITEM:
1194 DELETEITEMSTRUCT dls;
1195 if (size < sizeof(ps->dls)) return FALSE;
1196 dls.CtlType = ps->dls.CtlType;
1197 dls.CtlID = ps->dls.CtlID;
1198 dls.itemID = ps->dls.itemID;
1199 dls.hwndItem = wine_server_ptr_handle( ps->dls.hwndItem );
1200 dls.itemData = (ULONG_PTR)unpack_ptr( ps->dls.itemData );
1201 memcpy( &ps->dls, &dls, sizeof(dls) );
1202 break;
1204 case WM_COMPAREITEM:
1206 COMPAREITEMSTRUCT cis;
1207 if (size < sizeof(ps->cis)) return FALSE;
1208 cis.CtlType = ps->cis.CtlType;
1209 cis.CtlID = ps->cis.CtlID;
1210 cis.hwndItem = wine_server_ptr_handle( ps->cis.hwndItem );
1211 cis.itemID1 = ps->cis.itemID1;
1212 cis.itemData1 = (ULONG_PTR)unpack_ptr( ps->cis.itemData1 );
1213 cis.itemID2 = ps->cis.itemID2;
1214 cis.itemData2 = (ULONG_PTR)unpack_ptr( ps->cis.itemData2 );
1215 cis.dwLocaleId = ps->cis.dwLocaleId;
1216 memcpy( &ps->cis, &cis, sizeof(cis) );
1217 break;
1219 case WM_WINDOWPOSCHANGING:
1220 case WM_WINDOWPOSCHANGED:
1221 case WM_WINE_SETWINDOWPOS:
1223 WINDOWPOS wp;
1224 if (size < sizeof(ps->wp)) return FALSE;
1225 wp.hwnd = wine_server_ptr_handle( ps->wp.hwnd );
1226 wp.hwndInsertAfter = wine_server_ptr_handle( ps->wp.hwndInsertAfter );
1227 wp.x = ps->wp.x;
1228 wp.y = ps->wp.y;
1229 wp.cx = ps->wp.cx;
1230 wp.cy = ps->wp.cy;
1231 wp.flags = ps->wp.flags;
1232 memcpy( &ps->wp, &wp, sizeof(wp) );
1233 break;
1235 case WM_COPYDATA:
1237 COPYDATASTRUCT cds;
1238 if (size < sizeof(ps->cds)) return FALSE;
1239 cds.dwData = (ULONG_PTR)unpack_ptr( ps->cds.dwData );
1240 if (ps->cds.lpData)
1242 cds.cbData = ps->cds.cbData;
1243 cds.lpData = &ps->cds + 1;
1244 minsize = sizeof(ps->cds) + cds.cbData;
1246 else
1248 cds.cbData = 0;
1249 cds.lpData = 0;
1251 memcpy( &ps->cds, &cds, sizeof(cds) );
1252 break;
1254 case WM_NOTIFY:
1255 /* WM_NOTIFY cannot be sent across processes (MSDN) */
1256 return FALSE;
1257 case WM_HELP:
1259 HELPINFO hi;
1260 if (size < sizeof(ps->hi)) return FALSE;
1261 hi.cbSize = sizeof(hi);
1262 hi.iContextType = ps->hi.iContextType;
1263 hi.iCtrlId = ps->hi.iCtrlId;
1264 hi.hItemHandle = wine_server_ptr_handle( ps->hi.hItemHandle );
1265 hi.dwContextId = (ULONG_PTR)unpack_ptr( ps->hi.dwContextId );
1266 hi.MousePos = ps->hi.MousePos;
1267 memcpy( &ps->hi, &hi, sizeof(hi) );
1268 break;
1270 case WM_STYLECHANGING:
1271 case WM_STYLECHANGED:
1272 minsize = sizeof(STYLESTRUCT);
1273 break;
1274 case WM_NCCALCSIZE:
1275 if (!*wparam) minsize = sizeof(RECT);
1276 else
1278 NCCALCSIZE_PARAMS ncp;
1279 WINDOWPOS wp;
1280 if (size < sizeof(ps->ncp)) return FALSE;
1281 ncp.rgrc[0] = ps->ncp.rgrc[0];
1282 ncp.rgrc[1] = ps->ncp.rgrc[1];
1283 ncp.rgrc[2] = ps->ncp.rgrc[2];
1284 wp.hwnd = wine_server_ptr_handle( ps->ncp.hwnd );
1285 wp.hwndInsertAfter = wine_server_ptr_handle( ps->ncp.hwndInsertAfter );
1286 wp.x = ps->ncp.x;
1287 wp.y = ps->ncp.y;
1288 wp.cx = ps->ncp.cx;
1289 wp.cy = ps->ncp.cy;
1290 wp.flags = ps->ncp.flags;
1291 ncp.lppos = (WINDOWPOS *)((NCCALCSIZE_PARAMS *)&ps->ncp + 1);
1292 memcpy( &ps->ncp, &ncp, sizeof(ncp) );
1293 *ncp.lppos = wp;
1295 break;
1296 case WM_GETDLGCODE:
1297 if (*lparam)
1299 MSG msg;
1300 if (size < sizeof(ps->msg)) return FALSE;
1301 msg.hwnd = wine_server_ptr_handle( ps->msg.hwnd );
1302 msg.message = ps->msg.message;
1303 msg.wParam = (ULONG_PTR)unpack_ptr( ps->msg.wParam );
1304 msg.lParam = (ULONG_PTR)unpack_ptr( ps->msg.lParam );
1305 msg.time = ps->msg.time;
1306 msg.pt = ps->msg.pt;
1307 memcpy( &ps->msg, &msg, sizeof(msg) );
1308 break;
1310 return TRUE;
1311 case SBM_SETSCROLLINFO:
1312 minsize = sizeof(SCROLLINFO);
1313 break;
1314 case SBM_GETSCROLLINFO:
1315 if (!get_buffer_space( buffer, sizeof(SCROLLINFO ))) return FALSE;
1316 break;
1317 case SBM_GETSCROLLBARINFO:
1318 if (!get_buffer_space( buffer, sizeof(SCROLLBARINFO ))) return FALSE;
1319 break;
1320 case EM_GETSEL:
1321 case SBM_GETRANGE:
1322 case CB_GETEDITSEL:
1323 if (*wparam || *lparam)
1325 if (!get_buffer_space( buffer, 2*sizeof(DWORD) )) return FALSE;
1326 if (*wparam) *wparam = (WPARAM)*buffer;
1327 if (*lparam) *lparam = (LPARAM)((DWORD *)*buffer + 1);
1329 return TRUE;
1330 case EM_GETRECT:
1331 case LB_GETITEMRECT:
1332 case CB_GETDROPPEDCONTROLRECT:
1333 if (!get_buffer_space( buffer, sizeof(RECT) )) return FALSE;
1334 break;
1335 case EM_SETRECT:
1336 case EM_SETRECTNP:
1337 minsize = sizeof(RECT);
1338 break;
1339 case EM_GETLINE:
1341 WORD len;
1342 if (size < sizeof(WORD)) return FALSE;
1343 len = *(WORD *)*buffer;
1344 if (!get_buffer_space( buffer, (len + 1) * sizeof(WCHAR) )) return FALSE;
1345 *lparam = (LPARAM)*buffer + sizeof(WORD); /* don't erase WORD at start of buffer */
1346 return TRUE;
1348 case EM_SETTABSTOPS:
1349 case LB_SETTABSTOPS:
1350 if (!*wparam) return TRUE;
1351 minsize = *wparam * sizeof(UINT);
1352 break;
1353 case CB_ADDSTRING:
1354 case CB_INSERTSTRING:
1355 case CB_FINDSTRING:
1356 case CB_FINDSTRINGEXACT:
1357 case CB_SELECTSTRING:
1358 case LB_ADDSTRING:
1359 case LB_INSERTSTRING:
1360 case LB_FINDSTRING:
1361 case LB_FINDSTRINGEXACT:
1362 case LB_SELECTSTRING:
1363 if (!*buffer) return TRUE;
1364 if (!check_string( *buffer, size )) return FALSE;
1365 break;
1366 case CB_GETLBTEXT:
1368 size = sizeof(ULONG_PTR);
1369 if (combobox_has_strings( hwnd ))
1370 size = (SendMessageW( hwnd, CB_GETLBTEXTLEN, *wparam, 0 ) + 1) * sizeof(WCHAR);
1371 if (!get_buffer_space( buffer, size )) return FALSE;
1372 break;
1374 case LB_GETTEXT:
1376 size = sizeof(ULONG_PTR);
1377 if (listbox_has_strings( hwnd ))
1378 size = (SendMessageW( hwnd, LB_GETTEXTLEN, *wparam, 0 ) + 1) * sizeof(WCHAR);
1379 if (!get_buffer_space( buffer, size )) return FALSE;
1380 break;
1382 case LB_GETSELITEMS:
1383 if (!get_buffer_space( buffer, *wparam * sizeof(UINT) )) return FALSE;
1384 break;
1385 case WM_NEXTMENU:
1387 MDINEXTMENU mnm;
1388 if (size < sizeof(ps->mnm)) return FALSE;
1389 mnm.hmenuIn = wine_server_ptr_handle( ps->mnm.hmenuIn );
1390 mnm.hmenuNext = wine_server_ptr_handle( ps->mnm.hmenuNext );
1391 mnm.hwndNext = wine_server_ptr_handle( ps->mnm.hwndNext );
1392 memcpy( &ps->mnm, &mnm, sizeof(mnm) );
1393 break;
1395 case WM_SIZING:
1396 case WM_MOVING:
1397 minsize = sizeof(RECT);
1398 if (!get_buffer_space( buffer, sizeof(RECT) )) return FALSE;
1399 break;
1400 case WM_MDICREATE:
1402 MDICREATESTRUCTW mcs;
1403 WCHAR *str = (WCHAR *)(&ps->mcs + 1);
1404 if (size < sizeof(ps->mcs)) return FALSE;
1405 size -= sizeof(ps->mcs);
1407 mcs.szClass = unpack_ptr( ps->mcs.szClass );
1408 mcs.szTitle = unpack_ptr( ps->mcs.szTitle );
1409 mcs.hOwner = unpack_ptr( ps->mcs.hOwner );
1410 mcs.x = ps->mcs.x;
1411 mcs.y = ps->mcs.y;
1412 mcs.cx = ps->mcs.cx;
1413 mcs.cy = ps->mcs.cy;
1414 mcs.style = ps->mcs.style;
1415 mcs.lParam = (LPARAM)unpack_ptr( ps->mcs.lParam );
1416 if (ps->mcs.szClass >> 16)
1418 if (!check_string( str, size )) return FALSE;
1419 mcs.szClass = str;
1420 size -= (lstrlenW(str) + 1) * sizeof(WCHAR);
1421 str += lstrlenW(str) + 1;
1423 if (ps->mcs.szTitle >> 16)
1425 if (!check_string( str, size )) return FALSE;
1426 mcs.szTitle = str;
1428 memcpy( &ps->mcs, &mcs, sizeof(mcs) );
1429 break;
1431 case WM_MDIGETACTIVE:
1432 if (!*lparam) return TRUE;
1433 if (!get_buffer_space( buffer, sizeof(BOOL) )) return FALSE;
1434 break;
1435 case WM_DEVICECHANGE:
1436 if (!(*wparam & 0x8000)) return TRUE;
1437 minsize = sizeof(DEV_BROADCAST_HDR);
1438 break;
1439 case WM_WINE_KEYBOARD_LL_HOOK:
1440 case WM_WINE_MOUSE_LL_HOOK:
1442 struct hook_extra_info h_extra;
1443 minsize = sizeof(ps->hook) +
1444 (message == WM_WINE_KEYBOARD_LL_HOOK ? sizeof(KBDLLHOOKSTRUCT)
1445 : sizeof(MSLLHOOKSTRUCT));
1446 if (size < minsize) return FALSE;
1447 h_extra.handle = wine_server_ptr_handle( ps->hook.handle );
1448 h_extra.lparam = (LPARAM)(&ps->hook + 1);
1449 memcpy( &ps->hook, &h_extra, sizeof(h_extra) );
1450 break;
1452 case WM_NCPAINT:
1453 if (*wparam <= 1) return TRUE;
1454 FIXME( "WM_NCPAINT hdc unpacking not supported\n" );
1455 return FALSE;
1456 case WM_PAINT:
1457 if (!*wparam) return TRUE;
1458 /* fall through */
1460 /* these contain an HFONT */
1461 case WM_SETFONT:
1462 case WM_GETFONT:
1463 /* these contain an HDC */
1464 case WM_ERASEBKGND:
1465 case WM_ICONERASEBKGND:
1466 case WM_CTLCOLORMSGBOX:
1467 case WM_CTLCOLOREDIT:
1468 case WM_CTLCOLORLISTBOX:
1469 case WM_CTLCOLORBTN:
1470 case WM_CTLCOLORDLG:
1471 case WM_CTLCOLORSCROLLBAR:
1472 case WM_CTLCOLORSTATIC:
1473 case WM_PRINT:
1474 case WM_PRINTCLIENT:
1475 /* these contain an HGLOBAL */
1476 case WM_PAINTCLIPBOARD:
1477 case WM_SIZECLIPBOARD:
1478 /* these contain HICON */
1479 case WM_GETICON:
1480 case WM_SETICON:
1481 case WM_QUERYDRAGICON:
1482 case WM_QUERYPARKICON:
1483 /* these contain pointers */
1484 case WM_DROPOBJECT:
1485 case WM_QUERYDROPOBJECT:
1486 case WM_DRAGLOOP:
1487 case WM_DRAGSELECT:
1488 case WM_DRAGMOVE:
1489 FIXME( "msg %x (%s) not supported yet\n", message, SPY_GetMsgName(message, hwnd) );
1490 return FALSE;
1492 default:
1493 return TRUE; /* message doesn't need any unpacking */
1496 /* default exit for most messages: check minsize and store buffer in lparam */
1497 if (size < minsize) return FALSE;
1498 *lparam = (LPARAM)*buffer;
1499 return TRUE;
1503 /***********************************************************************
1504 * pack_reply
1506 * Pack a reply to a message for sending to another process.
1508 static void pack_reply( HWND hwnd, UINT message, WPARAM wparam, LPARAM lparam,
1509 LRESULT res, struct packed_message *data )
1511 data->count = 0;
1512 switch(message)
1514 case WM_NCCREATE:
1515 case WM_CREATE:
1517 CREATESTRUCTW *cs = (CREATESTRUCTW *)lparam;
1518 data->ps.cs.lpCreateParams = (ULONG_PTR)cs->lpCreateParams;
1519 data->ps.cs.hInstance = (ULONG_PTR)cs->hInstance;
1520 data->ps.cs.hMenu = wine_server_user_handle( cs->hMenu );
1521 data->ps.cs.hwndParent = wine_server_user_handle( cs->hwndParent );
1522 data->ps.cs.cy = cs->cy;
1523 data->ps.cs.cx = cs->cx;
1524 data->ps.cs.y = cs->y;
1525 data->ps.cs.x = cs->x;
1526 data->ps.cs.style = cs->style;
1527 data->ps.cs.dwExStyle = cs->dwExStyle;
1528 data->ps.cs.lpszName = (ULONG_PTR)cs->lpszName;
1529 data->ps.cs.lpszClass = (ULONG_PTR)cs->lpszClass;
1530 push_data( data, &data->ps.cs, sizeof(data->ps.cs) );
1531 break;
1533 case WM_GETTEXT:
1534 case CB_GETLBTEXT:
1535 case LB_GETTEXT:
1536 push_data( data, (WCHAR *)lparam, (res + 1) * sizeof(WCHAR) );
1537 break;
1538 case WM_GETMINMAXINFO:
1539 push_data( data, (MINMAXINFO *)lparam, sizeof(MINMAXINFO) );
1540 break;
1541 case WM_MEASUREITEM:
1543 MEASUREITEMSTRUCT *mis = (MEASUREITEMSTRUCT *)lparam;
1544 data->ps.mis.CtlType = mis->CtlType;
1545 data->ps.mis.CtlID = mis->CtlID;
1546 data->ps.mis.itemID = mis->itemID;
1547 data->ps.mis.itemWidth = mis->itemWidth;
1548 data->ps.mis.itemHeight = mis->itemHeight;
1549 data->ps.mis.itemData = mis->itemData;
1550 push_data( data, &data->ps.mis, sizeof(data->ps.mis) );
1551 break;
1553 case WM_WINDOWPOSCHANGING:
1554 case WM_WINDOWPOSCHANGED:
1556 WINDOWPOS *wp = (WINDOWPOS *)lparam;
1557 data->ps.wp.hwnd = wine_server_user_handle( wp->hwnd );
1558 data->ps.wp.hwndInsertAfter = wine_server_user_handle( wp->hwndInsertAfter );
1559 data->ps.wp.x = wp->x;
1560 data->ps.wp.y = wp->y;
1561 data->ps.wp.cx = wp->cx;
1562 data->ps.wp.cy = wp->cy;
1563 data->ps.wp.flags = wp->flags;
1564 push_data( data, &data->ps.wp, sizeof(data->ps.wp) );
1565 break;
1567 case WM_GETDLGCODE:
1568 if (lparam)
1570 MSG *msg = (MSG *)lparam;
1571 data->ps.msg.hwnd = wine_server_user_handle( msg->hwnd );
1572 data->ps.msg.message = msg->message;
1573 data->ps.msg.wParam = msg->wParam;
1574 data->ps.msg.lParam = msg->lParam;
1575 data->ps.msg.time = msg->time;
1576 data->ps.msg.pt = msg->pt;
1577 push_data( data, &data->ps.msg, sizeof(data->ps.msg) );
1579 break;
1580 case SBM_GETSCROLLINFO:
1581 push_data( data, (SCROLLINFO *)lparam, sizeof(SCROLLINFO) );
1582 break;
1583 case EM_GETRECT:
1584 case LB_GETITEMRECT:
1585 case CB_GETDROPPEDCONTROLRECT:
1586 case WM_SIZING:
1587 case WM_MOVING:
1588 push_data( data, (RECT *)lparam, sizeof(RECT) );
1589 break;
1590 case EM_GETLINE:
1592 WORD *ptr = (WORD *)lparam;
1593 push_data( data, ptr, ptr[-1] * sizeof(WCHAR) );
1594 break;
1596 case LB_GETSELITEMS:
1597 push_data( data, (UINT *)lparam, wparam * sizeof(UINT) );
1598 break;
1599 case WM_MDIGETACTIVE:
1600 if (lparam) push_data( data, (BOOL *)lparam, sizeof(BOOL) );
1601 break;
1602 case WM_NCCALCSIZE:
1603 if (!wparam)
1604 push_data( data, (RECT *)lparam, sizeof(RECT) );
1605 else
1607 NCCALCSIZE_PARAMS *ncp = (NCCALCSIZE_PARAMS *)lparam;
1608 data->ps.ncp.rgrc[0] = ncp->rgrc[0];
1609 data->ps.ncp.rgrc[1] = ncp->rgrc[1];
1610 data->ps.ncp.rgrc[2] = ncp->rgrc[2];
1611 data->ps.ncp.hwnd = wine_server_user_handle( ncp->lppos->hwnd );
1612 data->ps.ncp.hwndInsertAfter = wine_server_user_handle( ncp->lppos->hwndInsertAfter );
1613 data->ps.ncp.x = ncp->lppos->x;
1614 data->ps.ncp.y = ncp->lppos->y;
1615 data->ps.ncp.cx = ncp->lppos->cx;
1616 data->ps.ncp.cy = ncp->lppos->cy;
1617 data->ps.ncp.flags = ncp->lppos->flags;
1618 push_data( data, &data->ps.ncp, sizeof(data->ps.ncp) );
1620 break;
1621 case EM_GETSEL:
1622 case SBM_GETRANGE:
1623 case CB_GETEDITSEL:
1624 if (wparam) push_data( data, (DWORD *)wparam, sizeof(DWORD) );
1625 if (lparam) push_data( data, (DWORD *)lparam, sizeof(DWORD) );
1626 break;
1627 case WM_NEXTMENU:
1629 MDINEXTMENU *mnm = (MDINEXTMENU *)lparam;
1630 data->ps.mnm.hmenuIn = wine_server_user_handle( mnm->hmenuIn );
1631 data->ps.mnm.hmenuNext = wine_server_user_handle( mnm->hmenuNext );
1632 data->ps.mnm.hwndNext = wine_server_user_handle( mnm->hwndNext );
1633 push_data( data, &data->ps.mnm, sizeof(data->ps.mnm) );
1634 break;
1636 case WM_MDICREATE:
1638 MDICREATESTRUCTW *mcs = (MDICREATESTRUCTW *)lparam;
1639 data->ps.mcs.szClass = pack_ptr( mcs->szClass );
1640 data->ps.mcs.szTitle = pack_ptr( mcs->szTitle );
1641 data->ps.mcs.hOwner = pack_ptr( mcs->hOwner );
1642 data->ps.mcs.x = mcs->x;
1643 data->ps.mcs.y = mcs->y;
1644 data->ps.mcs.cx = mcs->cx;
1645 data->ps.mcs.cy = mcs->cy;
1646 data->ps.mcs.style = mcs->style;
1647 data->ps.mcs.lParam = mcs->lParam;
1648 push_data( data, &data->ps.mcs, sizeof(data->ps.mcs) );
1649 break;
1651 case WM_ASKCBFORMATNAME:
1652 push_data( data, (WCHAR *)lparam, (lstrlenW((WCHAR *)lparam) + 1) * sizeof(WCHAR) );
1653 break;
1658 /***********************************************************************
1659 * unpack_reply
1661 * Unpack a message reply received from another process.
1663 static void unpack_reply( HWND hwnd, UINT message, WPARAM wparam, LPARAM lparam,
1664 void *buffer, size_t size )
1666 union packed_structs *ps = buffer;
1668 switch(message)
1670 case WM_NCCREATE:
1671 case WM_CREATE:
1672 if (size >= sizeof(ps->cs))
1674 CREATESTRUCTW *cs = (CREATESTRUCTW *)lparam;
1675 cs->lpCreateParams = unpack_ptr( ps->cs.lpCreateParams );
1676 cs->hInstance = unpack_ptr( ps->cs.hInstance );
1677 cs->hMenu = wine_server_ptr_handle( ps->cs.hMenu );
1678 cs->hwndParent = wine_server_ptr_handle( ps->cs.hwndParent );
1679 cs->cy = ps->cs.cy;
1680 cs->cx = ps->cs.cx;
1681 cs->y = ps->cs.y;
1682 cs->x = ps->cs.x;
1683 cs->style = ps->cs.style;
1684 cs->dwExStyle = ps->cs.dwExStyle;
1685 /* don't allow changing name and class pointers */
1687 break;
1688 case WM_GETTEXT:
1689 case WM_ASKCBFORMATNAME:
1690 memcpy( (WCHAR *)lparam, buffer, min( wparam*sizeof(WCHAR), size ));
1691 break;
1692 case WM_GETMINMAXINFO:
1693 memcpy( (MINMAXINFO *)lparam, buffer, min( sizeof(MINMAXINFO), size ));
1694 break;
1695 case WM_MEASUREITEM:
1696 if (size >= sizeof(ps->mis))
1698 MEASUREITEMSTRUCT *mis = (MEASUREITEMSTRUCT *)lparam;
1699 mis->CtlType = ps->mis.CtlType;
1700 mis->CtlID = ps->mis.CtlID;
1701 mis->itemID = ps->mis.itemID;
1702 mis->itemWidth = ps->mis.itemWidth;
1703 mis->itemHeight = ps->mis.itemHeight;
1704 mis->itemData = (ULONG_PTR)unpack_ptr( ps->mis.itemData );
1706 break;
1707 case WM_WINDOWPOSCHANGING:
1708 case WM_WINDOWPOSCHANGED:
1709 if (size >= sizeof(ps->wp))
1711 WINDOWPOS *wp = (WINDOWPOS *)lparam;
1712 wp->hwnd = wine_server_ptr_handle( ps->wp.hwnd );
1713 wp->hwndInsertAfter = wine_server_ptr_handle( ps->wp.hwndInsertAfter );
1714 wp->x = ps->wp.x;
1715 wp->y = ps->wp.y;
1716 wp->cx = ps->wp.cx;
1717 wp->cy = ps->wp.cy;
1718 wp->flags = ps->wp.flags;
1720 break;
1721 case WM_GETDLGCODE:
1722 if (lparam && size >= sizeof(ps->msg))
1724 MSG *msg = (MSG *)lparam;
1725 msg->hwnd = wine_server_ptr_handle( ps->msg.hwnd );
1726 msg->message = ps->msg.message;
1727 msg->wParam = (ULONG_PTR)unpack_ptr( ps->msg.wParam );
1728 msg->lParam = (ULONG_PTR)unpack_ptr( ps->msg.lParam );
1729 msg->time = ps->msg.time;
1730 msg->pt = ps->msg.pt;
1732 break;
1733 case SBM_GETSCROLLINFO:
1734 memcpy( (SCROLLINFO *)lparam, buffer, min( sizeof(SCROLLINFO), size ));
1735 break;
1736 case SBM_GETSCROLLBARINFO:
1737 memcpy( (SCROLLBARINFO *)lparam, buffer, min( sizeof(SCROLLBARINFO), size ));
1738 break;
1739 case EM_GETRECT:
1740 case CB_GETDROPPEDCONTROLRECT:
1741 case LB_GETITEMRECT:
1742 case WM_SIZING:
1743 case WM_MOVING:
1744 memcpy( (RECT *)lparam, buffer, min( sizeof(RECT), size ));
1745 break;
1746 case EM_GETLINE:
1747 size = min( size, (size_t)*(WORD *)lparam );
1748 memcpy( (WCHAR *)lparam, buffer, size );
1749 break;
1750 case LB_GETSELITEMS:
1751 memcpy( (UINT *)lparam, buffer, min( wparam*sizeof(UINT), size ));
1752 break;
1753 case LB_GETTEXT:
1754 case CB_GETLBTEXT:
1755 memcpy( (WCHAR *)lparam, buffer, size );
1756 break;
1757 case WM_NEXTMENU:
1758 if (size >= sizeof(ps->mnm))
1760 MDINEXTMENU *mnm = (MDINEXTMENU *)lparam;
1761 mnm->hmenuIn = wine_server_ptr_handle( ps->mnm.hmenuIn );
1762 mnm->hmenuNext = wine_server_ptr_handle( ps->mnm.hmenuNext );
1763 mnm->hwndNext = wine_server_ptr_handle( ps->mnm.hwndNext );
1765 break;
1766 case WM_MDIGETACTIVE:
1767 if (lparam) memcpy( (BOOL *)lparam, buffer, min( sizeof(BOOL), size ));
1768 break;
1769 case WM_NCCALCSIZE:
1770 if (!wparam)
1771 memcpy( (RECT *)lparam, buffer, min( sizeof(RECT), size ));
1772 else if (size >= sizeof(ps->ncp))
1774 NCCALCSIZE_PARAMS *ncp = (NCCALCSIZE_PARAMS *)lparam;
1775 ncp->rgrc[0] = ps->ncp.rgrc[0];
1776 ncp->rgrc[1] = ps->ncp.rgrc[1];
1777 ncp->rgrc[2] = ps->ncp.rgrc[2];
1778 ncp->lppos->hwnd = wine_server_ptr_handle( ps->ncp.hwnd );
1779 ncp->lppos->hwndInsertAfter = wine_server_ptr_handle( ps->ncp.hwndInsertAfter );
1780 ncp->lppos->x = ps->ncp.x;
1781 ncp->lppos->y = ps->ncp.y;
1782 ncp->lppos->cx = ps->ncp.cx;
1783 ncp->lppos->cy = ps->ncp.cy;
1784 ncp->lppos->flags = ps->ncp.flags;
1786 break;
1787 case EM_GETSEL:
1788 case SBM_GETRANGE:
1789 case CB_GETEDITSEL:
1790 if (wparam)
1792 memcpy( (DWORD *)wparam, buffer, min( sizeof(DWORD), size ));
1793 if (size <= sizeof(DWORD)) break;
1794 size -= sizeof(DWORD);
1795 buffer = (DWORD *)buffer + 1;
1797 if (lparam) memcpy( (DWORD *)lparam, buffer, min( sizeof(DWORD), size ));
1798 break;
1799 case WM_MDICREATE:
1800 if (size >= sizeof(ps->mcs))
1802 MDICREATESTRUCTW *mcs = (MDICREATESTRUCTW *)lparam;
1803 mcs->hOwner = unpack_ptr( ps->mcs.hOwner );
1804 mcs->x = ps->mcs.x;
1805 mcs->y = ps->mcs.y;
1806 mcs->cx = ps->mcs.cx;
1807 mcs->cy = ps->mcs.cy;
1808 mcs->style = ps->mcs.style;
1809 mcs->lParam = (LPARAM)unpack_ptr( ps->mcs.lParam );
1810 /* don't allow changing class and title pointers */
1812 break;
1813 default:
1814 ERR( "should not happen: unexpected message %x\n", message );
1815 break;
1820 /***********************************************************************
1821 * reply_message
1823 * Send a reply to a sent message.
1825 static void reply_message( struct received_message_info *info, LRESULT result, BOOL remove )
1827 struct packed_message data;
1828 int i, replied = info->flags & ISMEX_REPLIED;
1830 if (info->flags & ISMEX_NOTIFY) return; /* notify messages don't get replies */
1831 if (!remove && replied) return; /* replied already */
1833 memset( &data, 0, sizeof(data) );
1834 info->flags |= ISMEX_REPLIED;
1836 if (info->type == MSG_OTHER_PROCESS && !replied)
1838 pack_reply( info->msg.hwnd, info->msg.message, info->msg.wParam,
1839 info->msg.lParam, result, &data );
1842 SERVER_START_REQ( reply_message )
1844 req->result = result;
1845 req->remove = remove;
1846 for (i = 0; i < data.count; i++) wine_server_add_data( req, data.data[i], data.size[i] );
1847 wine_server_call( req );
1849 SERVER_END_REQ;
1853 /***********************************************************************
1854 * handle_internal_message
1856 * Handle an internal Wine message instead of calling the window proc.
1858 static LRESULT handle_internal_message( HWND hwnd, UINT msg, WPARAM wparam, LPARAM lparam )
1860 switch(msg)
1862 case WM_WINE_DESTROYWINDOW:
1863 return WIN_DestroyWindow( hwnd );
1864 case WM_WINE_SETWINDOWPOS:
1865 if (is_desktop_window( hwnd )) return 0;
1866 return USER_SetWindowPos( (WINDOWPOS *)lparam, 0, 0 );
1867 case WM_WINE_SHOWWINDOW:
1868 if (is_desktop_window( hwnd )) return 0;
1869 return ShowWindow( hwnd, wparam );
1870 case WM_WINE_SETPARENT:
1871 if (is_desktop_window( hwnd )) return 0;
1872 return (LRESULT)SetParent( hwnd, (HWND)wparam );
1873 case WM_WINE_SETWINDOWLONG:
1874 return WIN_SetWindowLong( hwnd, (short)LOWORD(wparam), HIWORD(wparam), lparam, TRUE );
1875 case WM_WINE_SETSTYLE:
1876 if (is_desktop_window( hwnd )) return 0;
1877 return WIN_SetStyle(hwnd, wparam, lparam);
1878 case WM_WINE_SETACTIVEWINDOW:
1879 if (!wparam && GetForegroundWindow() == hwnd) return 0;
1880 return (LRESULT)SetActiveWindow( (HWND)wparam );
1881 case WM_WINE_KEYBOARD_LL_HOOK:
1882 case WM_WINE_MOUSE_LL_HOOK:
1884 struct hook_extra_info *h_extra = (struct hook_extra_info *)lparam;
1886 return call_current_hook( h_extra->handle, HC_ACTION, wparam, h_extra->lparam );
1888 case WM_WINE_CLIPCURSOR:
1889 if (wparam)
1891 RECT rect;
1892 GetClipCursor( &rect );
1893 return USER_Driver->pClipCursor( &rect );
1895 return USER_Driver->pClipCursor( NULL );
1896 case WM_WINE_UPDATEWINDOWSTATE:
1897 update_window_state( hwnd );
1898 return 0;
1899 default:
1900 if (msg >= WM_WINE_FIRST_DRIVER_MSG && msg <= WM_WINE_LAST_DRIVER_MSG)
1901 return USER_Driver->pWindowMessage( hwnd, msg, wparam, lparam );
1902 FIXME( "unknown internal message %x\n", msg );
1903 return 0;
1907 /* since the WM_DDE_ACK response to a WM_DDE_EXECUTE message should contain the handle
1908 * to the memory handle, we keep track (in the server side) of all pairs of handle
1909 * used (the client passes its value and the content of the memory handle), and
1910 * the server stored both values (the client, and the local one, created after the
1911 * content). When a ACK message is generated, the list of pair is searched for a
1912 * matching pair, so that the client memory handle can be returned.
1914 struct DDE_pair {
1915 HGLOBAL client_hMem;
1916 HGLOBAL server_hMem;
1919 static struct DDE_pair* dde_pairs;
1920 static int dde_num_alloc;
1921 static int dde_num_used;
1923 static CRITICAL_SECTION dde_crst;
1924 static CRITICAL_SECTION_DEBUG critsect_debug =
1926 0, 0, &dde_crst,
1927 { &critsect_debug.ProcessLocksList, &critsect_debug.ProcessLocksList },
1928 0, 0, { (DWORD_PTR)(__FILE__ ": dde_crst") }
1930 static CRITICAL_SECTION dde_crst = { &critsect_debug, -1, 0, 0, 0, 0 };
1932 static BOOL dde_add_pair(HGLOBAL chm, HGLOBAL shm)
1934 int i;
1935 #define GROWBY 4
1937 EnterCriticalSection(&dde_crst);
1939 /* now remember the pair of hMem on both sides */
1940 if (dde_num_used == dde_num_alloc)
1942 struct DDE_pair* tmp;
1943 if (dde_pairs)
1944 tmp = HeapReAlloc( GetProcessHeap(), 0, dde_pairs,
1945 (dde_num_alloc + GROWBY) * sizeof(struct DDE_pair));
1946 else
1947 tmp = HeapAlloc( GetProcessHeap(), 0,
1948 (dde_num_alloc + GROWBY) * sizeof(struct DDE_pair));
1950 if (!tmp)
1952 LeaveCriticalSection(&dde_crst);
1953 return FALSE;
1955 dde_pairs = tmp;
1956 /* zero out newly allocated part */
1957 memset(&dde_pairs[dde_num_alloc], 0, GROWBY * sizeof(struct DDE_pair));
1958 dde_num_alloc += GROWBY;
1960 #undef GROWBY
1961 for (i = 0; i < dde_num_alloc; i++)
1963 if (dde_pairs[i].server_hMem == 0)
1965 dde_pairs[i].client_hMem = chm;
1966 dde_pairs[i].server_hMem = shm;
1967 dde_num_used++;
1968 break;
1971 LeaveCriticalSection(&dde_crst);
1972 return TRUE;
1975 static HGLOBAL dde_get_pair(HGLOBAL shm)
1977 int i;
1978 HGLOBAL ret = 0;
1980 EnterCriticalSection(&dde_crst);
1981 for (i = 0; i < dde_num_alloc; i++)
1983 if (dde_pairs[i].server_hMem == shm)
1985 /* free this pair */
1986 dde_pairs[i].server_hMem = 0;
1987 dde_num_used--;
1988 ret = dde_pairs[i].client_hMem;
1989 break;
1992 LeaveCriticalSection(&dde_crst);
1993 return ret;
1996 /***********************************************************************
1997 * post_dde_message
1999 * Post a DDE message
2001 static BOOL post_dde_message( struct packed_message *data, const struct send_message_info *info )
2003 void* ptr = NULL;
2004 int size = 0;
2005 UINT_PTR uiLo, uiHi;
2006 LPARAM lp;
2007 HGLOBAL hunlock = 0;
2008 int i;
2009 DWORD res;
2010 ULONGLONG hpack;
2012 if (!UnpackDDElParam( info->msg, info->lparam, &uiLo, &uiHi ))
2013 return FALSE;
2015 lp = info->lparam;
2016 switch (info->msg)
2018 /* DDE messages which don't require packing are:
2019 * WM_DDE_INITIATE
2020 * WM_DDE_TERMINATE
2021 * WM_DDE_REQUEST
2022 * WM_DDE_UNADVISE
2024 case WM_DDE_ACK:
2025 if (HIWORD(uiHi))
2027 /* uiHi should contain a hMem from WM_DDE_EXECUTE */
2028 HGLOBAL h = dde_get_pair( (HANDLE)uiHi );
2029 if (h)
2031 hpack = pack_ptr( h );
2032 /* send back the value of h on the other side */
2033 push_data( data, &hpack, sizeof(hpack) );
2034 lp = uiLo;
2035 TRACE( "send dde-ack %lx %08lx => %p\n", uiLo, uiHi, h );
2038 else
2040 /* uiHi should contain either an atom or 0 */
2041 TRACE( "send dde-ack %lx atom=%lx\n", uiLo, uiHi );
2042 lp = MAKELONG( uiLo, uiHi );
2044 break;
2045 case WM_DDE_ADVISE:
2046 case WM_DDE_DATA:
2047 case WM_DDE_POKE:
2048 size = 0;
2049 if (uiLo)
2051 size = GlobalSize( (HGLOBAL)uiLo ) ;
2052 if ((info->msg == WM_DDE_ADVISE && size < sizeof(DDEADVISE)) ||
2053 (info->msg == WM_DDE_DATA && size < FIELD_OFFSET(DDEDATA, Value)) ||
2054 (info->msg == WM_DDE_POKE && size < FIELD_OFFSET(DDEPOKE, Value))
2056 return FALSE;
2058 else if (info->msg != WM_DDE_DATA) return FALSE;
2060 lp = uiHi;
2061 if (uiLo)
2063 if ((ptr = GlobalLock( (HGLOBAL)uiLo) ))
2065 DDEDATA *dde_data = ptr;
2066 TRACE("unused %d, fResponse %d, fRelease %d, fDeferUpd %d, fAckReq %d, cfFormat %d\n",
2067 dde_data->unused, dde_data->fResponse, dde_data->fRelease,
2068 dde_data->reserved, dde_data->fAckReq, dde_data->cfFormat);
2069 push_data( data, ptr, size );
2070 hunlock = (HGLOBAL)uiLo;
2073 TRACE( "send ddepack %u %lx\n", size, uiHi );
2074 break;
2075 case WM_DDE_EXECUTE:
2076 if (info->lparam)
2078 if ((ptr = GlobalLock( (HGLOBAL)info->lparam) ))
2080 push_data(data, ptr, GlobalSize( (HGLOBAL)info->lparam ));
2081 /* so that the other side can send it back on ACK */
2082 lp = info->lparam;
2083 hunlock = (HGLOBAL)info->lparam;
2086 break;
2088 SERVER_START_REQ( send_message )
2090 req->id = info->dest_tid;
2091 req->type = info->type;
2092 req->flags = 0;
2093 req->win = wine_server_user_handle( info->hwnd );
2094 req->msg = info->msg;
2095 req->wparam = info->wparam;
2096 req->lparam = lp;
2097 req->timeout = TIMEOUT_INFINITE;
2098 for (i = 0; i < data->count; i++)
2099 wine_server_add_data( req, data->data[i], data->size[i] );
2100 if ((res = wine_server_call( req )))
2102 if (res == STATUS_INVALID_PARAMETER)
2103 /* FIXME: find a STATUS_ value for this one */
2104 SetLastError( ERROR_INVALID_THREAD_ID );
2105 else
2106 SetLastError( RtlNtStatusToDosError(res) );
2108 else
2109 FreeDDElParam(info->msg, info->lparam);
2111 SERVER_END_REQ;
2112 if (hunlock) GlobalUnlock(hunlock);
2114 return !res;
2117 /***********************************************************************
2118 * unpack_dde_message
2120 * Unpack a posted DDE message received from another process.
2122 static BOOL unpack_dde_message( HWND hwnd, UINT message, WPARAM *wparam, LPARAM *lparam,
2123 void **buffer, size_t size )
2125 UINT_PTR uiLo, uiHi;
2126 HGLOBAL hMem = 0;
2127 void* ptr;
2129 switch (message)
2131 case WM_DDE_ACK:
2132 if (size)
2134 ULONGLONG hpack;
2135 /* hMem is being passed */
2136 if (size != sizeof(hpack)) return FALSE;
2137 if (!buffer || !*buffer) return FALSE;
2138 uiLo = *lparam;
2139 memcpy( &hpack, *buffer, size );
2140 hMem = unpack_ptr( hpack );
2141 uiHi = (UINT_PTR)hMem;
2142 TRACE("recv dde-ack %lx mem=%lx[%lx]\n", uiLo, uiHi, GlobalSize( hMem ));
2144 else
2146 uiLo = LOWORD( *lparam );
2147 uiHi = HIWORD( *lparam );
2148 TRACE("recv dde-ack %lx atom=%lx\n", uiLo, uiHi);
2150 *lparam = PackDDElParam( WM_DDE_ACK, uiLo, uiHi );
2151 break;
2152 case WM_DDE_ADVISE:
2153 case WM_DDE_DATA:
2154 case WM_DDE_POKE:
2155 if ((!buffer || !*buffer) && message != WM_DDE_DATA) return FALSE;
2156 uiHi = *lparam;
2157 if (size)
2159 if (!(hMem = GlobalAlloc( GMEM_MOVEABLE|GMEM_DDESHARE, size )))
2160 return FALSE;
2161 if ((ptr = GlobalLock( hMem )))
2163 memcpy( ptr, *buffer, size );
2164 GlobalUnlock( hMem );
2166 else
2168 GlobalFree( hMem );
2169 return FALSE;
2172 uiLo = (UINT_PTR)hMem;
2174 *lparam = PackDDElParam( message, uiLo, uiHi );
2175 break;
2176 case WM_DDE_EXECUTE:
2177 if (size)
2179 if (!buffer || !*buffer) return FALSE;
2180 if (!(hMem = GlobalAlloc( GMEM_MOVEABLE|GMEM_DDESHARE, size ))) return FALSE;
2181 if ((ptr = GlobalLock( hMem )))
2183 memcpy( ptr, *buffer, size );
2184 GlobalUnlock( hMem );
2185 TRACE( "exec: pairing c=%08lx s=%p\n", *lparam, hMem );
2186 if (!dde_add_pair( (HGLOBAL)*lparam, hMem ))
2188 GlobalFree( hMem );
2189 return FALSE;
2192 else
2194 GlobalFree( hMem );
2195 return FALSE;
2197 } else return FALSE;
2198 *lparam = (LPARAM)hMem;
2199 break;
2201 return TRUE;
2204 /***********************************************************************
2205 * call_window_proc
2207 * Call a window procedure and the corresponding hooks.
2209 static LRESULT call_window_proc( HWND hwnd, UINT msg, WPARAM wparam, LPARAM lparam,
2210 BOOL unicode, BOOL same_thread, enum wm_char_mapping mapping )
2212 LRESULT result = 0;
2213 CWPSTRUCT cwp;
2214 CWPRETSTRUCT cwpret;
2216 if (msg & 0x80000000)
2218 result = handle_internal_message( hwnd, msg, wparam, lparam );
2219 goto done;
2222 /* first the WH_CALLWNDPROC hook */
2223 hwnd = WIN_GetFullHandle( hwnd );
2224 cwp.lParam = lparam;
2225 cwp.wParam = wparam;
2226 cwp.message = msg;
2227 cwp.hwnd = hwnd;
2228 HOOK_CallHooks( WH_CALLWNDPROC, HC_ACTION, same_thread, (LPARAM)&cwp, unicode );
2230 /* now call the window procedure */
2231 if (!WINPROC_call_window( hwnd, msg, wparam, lparam, &result, unicode, mapping )) goto done;
2233 /* and finally the WH_CALLWNDPROCRET hook */
2234 cwpret.lResult = result;
2235 cwpret.lParam = lparam;
2236 cwpret.wParam = wparam;
2237 cwpret.message = msg;
2238 cwpret.hwnd = hwnd;
2239 HOOK_CallHooks( WH_CALLWNDPROCRET, HC_ACTION, same_thread, (LPARAM)&cwpret, unicode );
2240 done:
2241 return result;
2245 /***********************************************************************
2246 * send_parent_notify
2248 * Send a WM_PARENTNOTIFY to all ancestors of the given window, unless
2249 * the window has the WS_EX_NOPARENTNOTIFY style.
2251 static void send_parent_notify( HWND hwnd, WORD event, WORD idChild, POINT pt )
2253 /* pt has to be in the client coordinates of the parent window */
2254 MapWindowPoints( 0, hwnd, &pt, 1 );
2255 for (;;)
2257 HWND parent;
2259 if (!(GetWindowLongW( hwnd, GWL_STYLE ) & WS_CHILD)) break;
2260 if (GetWindowLongW( hwnd, GWL_EXSTYLE ) & WS_EX_NOPARENTNOTIFY) break;
2261 if (!(parent = GetParent(hwnd))) break;
2262 if (parent == GetDesktopWindow()) break;
2263 MapWindowPoints( hwnd, parent, &pt, 1 );
2264 hwnd = parent;
2265 SendMessageW( hwnd, WM_PARENTNOTIFY,
2266 MAKEWPARAM( event, idChild ), MAKELPARAM( pt.x, pt.y ) );
2271 /***********************************************************************
2272 * accept_hardware_message
2274 * Tell the server we have passed the message to the app
2275 * (even though we may end up dropping it later on)
2277 static void accept_hardware_message( UINT hw_id )
2279 SERVER_START_REQ( accept_hardware_message )
2281 req->hw_id = hw_id;
2282 if (wine_server_call( req ))
2283 FIXME("Failed to reply to MSG_HARDWARE message. Message may not be removed from queue.\n");
2285 SERVER_END_REQ;
2289 static BOOL process_rawinput_message( MSG *msg, UINT hw_id, const struct hardware_msg_data *msg_data )
2291 struct rawinput_thread_data *thread_data = rawinput_thread_data();
2293 if (msg->message == WM_INPUT)
2295 thread_data->buffer->header.dwSize = RAWINPUT_BUFFER_SIZE;
2296 if (!rawinput_from_hardware_message( thread_data->buffer, msg_data )) return FALSE;
2297 thread_data->hw_id = hw_id;
2298 msg->lParam = (LPARAM)hw_id;
2301 msg->pt = point_phys_to_win_dpi( msg->hwnd, msg->pt );
2302 return TRUE;
2305 /***********************************************************************
2306 * process_keyboard_message
2308 * returns TRUE if the contents of 'msg' should be passed to the application
2310 static BOOL process_keyboard_message( MSG *msg, UINT hw_id, HWND hwnd_filter,
2311 UINT first, UINT last, BOOL remove )
2313 EVENTMSG event;
2315 if (msg->message == WM_KEYDOWN || msg->message == WM_SYSKEYDOWN ||
2316 msg->message == WM_KEYUP || msg->message == WM_SYSKEYUP)
2317 switch (msg->wParam)
2319 case VK_LSHIFT: case VK_RSHIFT:
2320 msg->wParam = VK_SHIFT;
2321 break;
2322 case VK_LCONTROL: case VK_RCONTROL:
2323 msg->wParam = VK_CONTROL;
2324 break;
2325 case VK_LMENU: case VK_RMENU:
2326 msg->wParam = VK_MENU;
2327 break;
2330 /* FIXME: is this really the right place for this hook? */
2331 event.message = msg->message;
2332 event.hwnd = msg->hwnd;
2333 event.time = msg->time;
2334 event.paramL = (msg->wParam & 0xFF) | (HIWORD(msg->lParam) << 8);
2335 event.paramH = msg->lParam & 0x7FFF;
2336 if (HIWORD(msg->lParam) & 0x0100) event.paramH |= 0x8000; /* special_key - bit */
2337 HOOK_CallHooks( WH_JOURNALRECORD, HC_ACTION, 0, (LPARAM)&event, TRUE );
2339 /* check message filters */
2340 if (msg->message < first || msg->message > last) return FALSE;
2341 if (!check_hwnd_filter( msg, hwnd_filter )) return FALSE;
2343 if (remove)
2345 if((msg->message == WM_KEYDOWN) &&
2346 (msg->hwnd != GetDesktopWindow()))
2348 /* Handle F1 key by sending out WM_HELP message */
2349 if (msg->wParam == VK_F1)
2351 PostMessageW( msg->hwnd, WM_KEYF1, 0, 0 );
2353 else if(msg->wParam >= VK_BROWSER_BACK &&
2354 msg->wParam <= VK_LAUNCH_APP2)
2356 /* FIXME: Process keystate */
2357 SendMessageW(msg->hwnd, WM_APPCOMMAND, (WPARAM)msg->hwnd, MAKELPARAM(0, (FAPPCOMMAND_KEY | (msg->wParam - VK_BROWSER_BACK + 1))));
2360 else if (msg->message == WM_KEYUP)
2362 /* Handle VK_APPS key by posting a WM_CONTEXTMENU message */
2363 if (msg->wParam == VK_APPS && !MENU_IsMenuActive())
2364 PostMessageW(msg->hwnd, WM_CONTEXTMENU, (WPARAM)msg->hwnd, -1);
2368 if (HOOK_CallHooks( WH_KEYBOARD, remove ? HC_ACTION : HC_NOREMOVE,
2369 LOWORD(msg->wParam), msg->lParam, TRUE ))
2371 /* skip this message */
2372 HOOK_CallHooks( WH_CBT, HCBT_KEYSKIPPED, LOWORD(msg->wParam), msg->lParam, TRUE );
2373 accept_hardware_message( hw_id );
2374 return FALSE;
2376 if (remove) accept_hardware_message( hw_id );
2377 msg->pt = point_phys_to_win_dpi( msg->hwnd, msg->pt );
2379 if ( remove && msg->message == WM_KEYDOWN )
2380 if (ImmProcessKey(msg->hwnd, GetKeyboardLayout(0), msg->wParam, msg->lParam, 0) )
2381 msg->wParam = VK_PROCESSKEY;
2383 return TRUE;
2387 /***********************************************************************
2388 * process_mouse_message
2390 * returns TRUE if the contents of 'msg' should be passed to the application
2392 static BOOL process_mouse_message( MSG *msg, UINT hw_id, ULONG_PTR extra_info, HWND hwnd_filter,
2393 UINT first, UINT last, BOOL remove )
2395 static MSG clk_msg;
2397 POINT pt;
2398 UINT message;
2399 INT hittest;
2400 EVENTMSG event;
2401 GUITHREADINFO info;
2402 MOUSEHOOKSTRUCTEX hook;
2403 BOOL eatMsg;
2404 WPARAM wparam;
2406 /* find the window to dispatch this mouse message to */
2408 info.cbSize = sizeof(info);
2409 GetGUIThreadInfo( GetCurrentThreadId(), &info );
2410 if (info.hwndCapture)
2412 hittest = HTCLIENT;
2413 msg->hwnd = info.hwndCapture;
2415 else
2417 HWND orig = msg->hwnd;
2419 msg->hwnd = WINPOS_WindowFromPoint( msg->hwnd, msg->pt, &hittest );
2420 if (!msg->hwnd) /* As a heuristic, try the next window if it's the owner of orig */
2422 HWND next = GetWindow( orig, GW_HWNDNEXT );
2424 if (next && GetWindow( orig, GW_OWNER ) == next && WIN_IsCurrentThread( next ))
2425 msg->hwnd = WINPOS_WindowFromPoint( next, msg->pt, &hittest );
2429 if (!msg->hwnd || !WIN_IsCurrentThread( msg->hwnd ))
2431 accept_hardware_message( hw_id );
2432 return FALSE;
2435 msg->pt = point_phys_to_win_dpi( msg->hwnd, msg->pt );
2436 SetThreadDpiAwarenessContext( GetWindowDpiAwarenessContext( msg->hwnd ));
2438 /* FIXME: is this really the right place for this hook? */
2439 event.message = msg->message;
2440 event.time = msg->time;
2441 event.hwnd = msg->hwnd;
2442 event.paramL = msg->pt.x;
2443 event.paramH = msg->pt.y;
2444 HOOK_CallHooks( WH_JOURNALRECORD, HC_ACTION, 0, (LPARAM)&event, TRUE );
2446 if (!check_hwnd_filter( msg, hwnd_filter )) return FALSE;
2448 pt = msg->pt;
2449 message = msg->message;
2450 wparam = msg->wParam;
2451 /* Note: windows has no concept of a non-client wheel message */
2452 if (message != WM_MOUSEWHEEL)
2454 if (hittest != HTCLIENT)
2456 message += WM_NCMOUSEMOVE - WM_MOUSEMOVE;
2457 wparam = hittest;
2459 else
2461 /* coordinates don't get translated while tracking a menu */
2462 /* FIXME: should differentiate popups and top-level menus */
2463 if (!(info.flags & GUI_INMENUMODE))
2464 ScreenToClient( msg->hwnd, &pt );
2467 msg->lParam = MAKELONG( pt.x, pt.y );
2469 /* translate double clicks */
2471 if ((msg->message == WM_LBUTTONDOWN) ||
2472 (msg->message == WM_RBUTTONDOWN) ||
2473 (msg->message == WM_MBUTTONDOWN) ||
2474 (msg->message == WM_XBUTTONDOWN))
2476 BOOL update = remove;
2478 /* translate double clicks -
2479 * note that ...MOUSEMOVEs can slip in between
2480 * ...BUTTONDOWN and ...BUTTONDBLCLK messages */
2482 if ((info.flags & (GUI_INMENUMODE|GUI_INMOVESIZE)) ||
2483 hittest != HTCLIENT ||
2484 (GetClassLongA( msg->hwnd, GCL_STYLE ) & CS_DBLCLKS))
2486 if ((msg->message == clk_msg.message) &&
2487 (msg->hwnd == clk_msg.hwnd) &&
2488 (msg->wParam == clk_msg.wParam) &&
2489 (msg->time - clk_msg.time < GetDoubleClickTime()) &&
2490 (abs(msg->pt.x - clk_msg.pt.x) < GetSystemMetrics(SM_CXDOUBLECLK)/2) &&
2491 (abs(msg->pt.y - clk_msg.pt.y) < GetSystemMetrics(SM_CYDOUBLECLK)/2))
2493 message += (WM_LBUTTONDBLCLK - WM_LBUTTONDOWN);
2494 if (update)
2496 clk_msg.message = 0; /* clear the double click conditions */
2497 update = FALSE;
2501 if (message < first || message > last) return FALSE;
2502 /* update static double click conditions */
2503 if (update) clk_msg = *msg;
2505 else
2507 if (message < first || message > last) return FALSE;
2509 msg->wParam = wparam;
2511 /* message is accepted now (but may still get dropped) */
2513 hook.s.pt = msg->pt;
2514 hook.s.hwnd = msg->hwnd;
2515 hook.s.wHitTestCode = hittest;
2516 hook.s.dwExtraInfo = extra_info;
2517 hook.mouseData = msg->wParam;
2518 if (HOOK_CallHooks( WH_MOUSE, remove ? HC_ACTION : HC_NOREMOVE,
2519 message, (LPARAM)&hook, TRUE ))
2521 hook.s.pt = msg->pt;
2522 hook.s.hwnd = msg->hwnd;
2523 hook.s.wHitTestCode = hittest;
2524 hook.s.dwExtraInfo = extra_info;
2525 hook.mouseData = msg->wParam;
2526 HOOK_CallHooks( WH_CBT, HCBT_CLICKSKIPPED, message, (LPARAM)&hook, TRUE );
2527 accept_hardware_message( hw_id );
2528 return FALSE;
2531 if ((hittest == HTERROR) || (hittest == HTNOWHERE))
2533 SendMessageW( msg->hwnd, WM_SETCURSOR, (WPARAM)msg->hwnd,
2534 MAKELONG( hittest, msg->message ));
2535 accept_hardware_message( hw_id );
2536 return FALSE;
2539 if (remove) accept_hardware_message( hw_id );
2541 if (!remove || info.hwndCapture)
2543 msg->message = message;
2544 return TRUE;
2547 eatMsg = FALSE;
2549 if ((msg->message == WM_LBUTTONDOWN) ||
2550 (msg->message == WM_RBUTTONDOWN) ||
2551 (msg->message == WM_MBUTTONDOWN) ||
2552 (msg->message == WM_XBUTTONDOWN))
2554 /* Send the WM_PARENTNOTIFY,
2555 * note that even for double/nonclient clicks
2556 * notification message is still WM_L/M/RBUTTONDOWN.
2558 send_parent_notify( msg->hwnd, msg->message, 0, msg->pt );
2560 /* Activate the window if needed */
2562 if (msg->hwnd != info.hwndActive)
2564 HWND hwndTop = GetAncestor( msg->hwnd, GA_ROOT );
2566 if ((GetWindowLongW( hwndTop, GWL_STYLE ) & (WS_POPUP|WS_CHILD)) != WS_CHILD)
2568 LONG ret = SendMessageW( msg->hwnd, WM_MOUSEACTIVATE, (WPARAM)hwndTop,
2569 MAKELONG( hittest, msg->message ) );
2570 switch(ret)
2572 case MA_NOACTIVATEANDEAT:
2573 eatMsg = TRUE;
2574 /* fall through */
2575 case MA_NOACTIVATE:
2576 break;
2577 case MA_ACTIVATEANDEAT:
2578 eatMsg = TRUE;
2579 /* fall through */
2580 case MA_ACTIVATE:
2581 case 0:
2582 if (!FOCUS_MouseActivate( hwndTop )) eatMsg = TRUE;
2583 break;
2584 default:
2585 WARN( "unknown WM_MOUSEACTIVATE code %d\n", ret );
2586 break;
2592 /* send the WM_SETCURSOR message */
2594 /* Windows sends the normal mouse message as the message parameter
2595 in the WM_SETCURSOR message even if it's non-client mouse message */
2596 SendMessageW( msg->hwnd, WM_SETCURSOR, (WPARAM)msg->hwnd, MAKELONG( hittest, msg->message ));
2598 msg->message = message;
2599 return !eatMsg;
2603 /***********************************************************************
2604 * process_hardware_message
2606 * Process a hardware message; return TRUE if message should be passed on to the app
2608 static BOOL process_hardware_message( MSG *msg, UINT hw_id, const struct hardware_msg_data *msg_data,
2609 HWND hwnd_filter, UINT first, UINT last, BOOL remove )
2611 DPI_AWARENESS_CONTEXT context;
2612 BOOL ret = FALSE;
2614 get_user_thread_info()->msg_source.deviceType = msg_data->source.device;
2615 get_user_thread_info()->msg_source.originId = msg_data->source.origin;
2617 /* hardware messages are always in physical coords */
2618 context = SetThreadDpiAwarenessContext( DPI_AWARENESS_CONTEXT_PER_MONITOR_AWARE );
2620 if (msg->message == WM_INPUT || msg->message == WM_INPUT_DEVICE_CHANGE)
2621 ret = process_rawinput_message( msg, hw_id, msg_data );
2622 else if (is_keyboard_message( msg->message ))
2623 ret = process_keyboard_message( msg, hw_id, hwnd_filter, first, last, remove );
2624 else if (is_mouse_message( msg->message ))
2625 ret = process_mouse_message( msg, hw_id, msg_data->info, hwnd_filter, first, last, remove );
2626 else
2627 ERR( "unknown message type %x\n", msg->message );
2628 SetThreadDpiAwarenessContext( context );
2629 return ret;
2633 /***********************************************************************
2634 * call_sendmsg_callback
2636 * Call the callback function of SendMessageCallback.
2638 static inline void call_sendmsg_callback( SENDASYNCPROC callback, HWND hwnd, UINT msg,
2639 ULONG_PTR data, LRESULT result )
2641 if (!callback) return;
2643 TRACE_(relay)( "\1Call message callback %p (hwnd=%p,msg=%s,data=%08lx,result=%08lx)\n",
2644 callback, hwnd, SPY_GetMsgName( msg, hwnd ), data, result );
2645 callback( hwnd, msg, data, result );
2646 TRACE_(relay)( "\1Ret message callback %p (hwnd=%p,msg=%s,data=%08lx,result=%08lx)\n",
2647 callback, hwnd, SPY_GetMsgName( msg, hwnd ), data, result );
2651 /***********************************************************************
2652 * peek_message
2654 * Peek for a message matching the given parameters. Return 0 if none are
2655 * available; -1 on error.
2656 * All pending sent messages are processed before returning.
2658 static int peek_message( MSG *msg, HWND hwnd, UINT first, UINT last, UINT flags, UINT changed_mask )
2660 LRESULT result;
2661 struct user_thread_info *thread_info = get_user_thread_info();
2662 INPUT_MESSAGE_SOURCE prev_source = thread_info->msg_source;
2663 struct received_message_info info, *old_info;
2664 unsigned int hw_id = 0; /* id of previous hardware message */
2665 void *buffer;
2666 size_t buffer_size = 256;
2668 if (!(buffer = HeapAlloc( GetProcessHeap(), 0, buffer_size ))) return -1;
2670 if (!first && !last) last = ~0;
2671 if (hwnd == HWND_BROADCAST) hwnd = HWND_TOPMOST;
2673 for (;;)
2675 NTSTATUS res;
2676 size_t size = 0;
2677 const message_data_t *msg_data = buffer;
2679 thread_info->msg_source = prev_source;
2681 SERVER_START_REQ( get_message )
2683 req->flags = flags;
2684 req->get_win = wine_server_user_handle( hwnd );
2685 req->get_first = first;
2686 req->get_last = last;
2687 req->hw_id = hw_id;
2688 req->wake_mask = changed_mask & (QS_SENDMESSAGE | QS_SMRESULT);
2689 req->changed_mask = changed_mask;
2690 wine_server_set_reply( req, buffer, buffer_size );
2691 if (!(res = wine_server_call( req )))
2693 size = wine_server_reply_size( reply );
2694 info.type = reply->type;
2695 info.msg.hwnd = wine_server_ptr_handle( reply->win );
2696 info.msg.message = reply->msg;
2697 info.msg.wParam = reply->wparam;
2698 info.msg.lParam = reply->lparam;
2699 info.msg.time = reply->time;
2700 info.msg.pt.x = reply->x;
2701 info.msg.pt.y = reply->y;
2702 hw_id = 0;
2703 thread_info->active_hooks = reply->active_hooks;
2705 else buffer_size = reply->total;
2707 SERVER_END_REQ;
2709 if (res)
2711 HeapFree( GetProcessHeap(), 0, buffer );
2712 if (res == STATUS_PENDING)
2714 thread_info->wake_mask = changed_mask & (QS_SENDMESSAGE | QS_SMRESULT);
2715 thread_info->changed_mask = changed_mask;
2716 return 0;
2718 if (res != STATUS_BUFFER_OVERFLOW)
2720 SetLastError( RtlNtStatusToDosError(res) );
2721 return -1;
2723 if (!(buffer = HeapAlloc( GetProcessHeap(), 0, buffer_size ))) return -1;
2724 continue;
2727 TRACE( "got type %d msg %x (%s) hwnd %p wp %lx lp %lx\n",
2728 info.type, info.msg.message,
2729 (info.type == MSG_WINEVENT) ? "MSG_WINEVENT" : SPY_GetMsgName(info.msg.message, info.msg.hwnd),
2730 info.msg.hwnd, info.msg.wParam, info.msg.lParam );
2732 switch(info.type)
2734 case MSG_ASCII:
2735 case MSG_UNICODE:
2736 info.flags = ISMEX_SEND;
2737 break;
2738 case MSG_NOTIFY:
2739 info.flags = ISMEX_NOTIFY;
2740 if (!unpack_message( info.msg.hwnd, info.msg.message, &info.msg.wParam,
2741 &info.msg.lParam, &buffer, size ))
2742 continue;
2743 break;
2744 case MSG_CALLBACK:
2745 info.flags = ISMEX_CALLBACK;
2746 break;
2747 case MSG_CALLBACK_RESULT:
2748 if (size >= sizeof(msg_data->callback))
2749 call_sendmsg_callback( wine_server_get_ptr(msg_data->callback.callback),
2750 info.msg.hwnd, info.msg.message,
2751 msg_data->callback.data, msg_data->callback.result );
2752 continue;
2753 case MSG_WINEVENT:
2754 if (size >= sizeof(msg_data->winevent))
2756 WINEVENTPROC hook_proc;
2757 HMODULE free_module = 0;
2759 hook_proc = wine_server_get_ptr( msg_data->winevent.hook_proc );
2760 size -= sizeof(msg_data->winevent);
2761 if (size)
2763 WCHAR module[MAX_PATH];
2765 size = min( size, (MAX_PATH - 1) * sizeof(WCHAR) );
2766 memcpy( module, &msg_data->winevent + 1, size );
2767 module[size / sizeof(WCHAR)] = 0;
2768 if (!(hook_proc = get_hook_proc( hook_proc, module, &free_module )))
2770 ERR( "invalid winevent hook module name %s\n", debugstr_w(module) );
2771 continue;
2775 TRACE_(relay)( "\1Call winevent proc %p (hook=%04x,event=%x,hwnd=%p,object_id=%lx,child_id=%lx,tid=%04x,time=%x)\n",
2776 hook_proc, msg_data->winevent.hook, info.msg.message, info.msg.hwnd,
2777 info.msg.wParam, info.msg.lParam, msg_data->winevent.tid, info.msg.time);
2779 hook_proc( wine_server_ptr_handle( msg_data->winevent.hook ), info.msg.message,
2780 info.msg.hwnd, info.msg.wParam, info.msg.lParam,
2781 msg_data->winevent.tid, info.msg.time );
2783 TRACE_(relay)( "\1Ret winevent proc %p (hook=%04x,event=%x,hwnd=%p,object_id=%lx,child_id=%lx,tid=%04x,time=%x)\n",
2784 hook_proc, msg_data->winevent.hook, info.msg.message, info.msg.hwnd,
2785 info.msg.wParam, info.msg.lParam, msg_data->winevent.tid, info.msg.time);
2787 if (free_module) FreeLibrary(free_module);
2789 continue;
2790 case MSG_HOOK_LL:
2791 info.flags = ISMEX_SEND;
2792 result = 0;
2793 if (info.msg.message == WH_KEYBOARD_LL && size >= sizeof(msg_data->hardware))
2795 KBDLLHOOKSTRUCT hook;
2797 hook.vkCode = LOWORD( info.msg.lParam );
2798 hook.scanCode = HIWORD( info.msg.lParam );
2799 hook.flags = msg_data->hardware.flags;
2800 hook.time = info.msg.time;
2801 hook.dwExtraInfo = msg_data->hardware.info;
2802 TRACE( "calling keyboard LL hook vk %x scan %x flags %x time %u info %lx\n",
2803 hook.vkCode, hook.scanCode, hook.flags, hook.time, hook.dwExtraInfo );
2804 result = HOOK_CallHooks( WH_KEYBOARD_LL, HC_ACTION, info.msg.wParam, (LPARAM)&hook, TRUE );
2806 else if (info.msg.message == WH_MOUSE_LL && size >= sizeof(msg_data->hardware))
2808 MSLLHOOKSTRUCT hook;
2810 hook.pt = info.msg.pt;
2811 hook.mouseData = info.msg.lParam;
2812 hook.flags = msg_data->hardware.flags;
2813 hook.time = info.msg.time;
2814 hook.dwExtraInfo = msg_data->hardware.info;
2815 TRACE( "calling mouse LL hook pos %d,%d data %x flags %x time %u info %lx\n",
2816 hook.pt.x, hook.pt.y, hook.mouseData, hook.flags, hook.time, hook.dwExtraInfo );
2817 result = HOOK_CallHooks( WH_MOUSE_LL, HC_ACTION, info.msg.wParam, (LPARAM)&hook, TRUE );
2819 reply_message( &info, result, TRUE );
2820 continue;
2821 case MSG_OTHER_PROCESS:
2822 info.flags = ISMEX_SEND;
2823 if (!unpack_message( info.msg.hwnd, info.msg.message, &info.msg.wParam,
2824 &info.msg.lParam, &buffer, size ))
2826 /* ignore it */
2827 reply_message( &info, 0, TRUE );
2828 continue;
2830 break;
2831 case MSG_HARDWARE:
2832 if (size >= sizeof(msg_data->hardware))
2834 hw_id = msg_data->hardware.hw_id;
2835 if (!process_hardware_message( &info.msg, hw_id, &msg_data->hardware,
2836 hwnd, first, last, flags & PM_REMOVE ))
2838 TRACE("dropping msg %x\n", info.msg.message );
2839 continue; /* ignore it */
2841 *msg = info.msg;
2842 thread_info->GetMessagePosVal = MAKELONG( info.msg.pt.x, info.msg.pt.y );
2843 thread_info->GetMessageTimeVal = info.msg.time;
2844 thread_info->GetMessageExtraInfoVal = msg_data->hardware.info;
2845 HeapFree( GetProcessHeap(), 0, buffer );
2846 HOOK_CallHooks( WH_GETMESSAGE, HC_ACTION, flags & PM_REMOVE, (LPARAM)msg, TRUE );
2847 return 1;
2849 continue;
2850 case MSG_POSTED:
2851 if (info.msg.message & 0x80000000) /* internal message */
2853 if (flags & PM_REMOVE)
2855 handle_internal_message( info.msg.hwnd, info.msg.message,
2856 info.msg.wParam, info.msg.lParam );
2857 /* if this is a nested call return right away */
2858 if (first == info.msg.message && last == info.msg.message)
2860 HeapFree( GetProcessHeap(), 0, buffer );
2861 return 0;
2864 else
2865 peek_message( msg, info.msg.hwnd, info.msg.message,
2866 info.msg.message, flags | PM_REMOVE, changed_mask );
2867 continue;
2869 if (info.msg.message >= WM_DDE_FIRST && info.msg.message <= WM_DDE_LAST)
2871 if (!unpack_dde_message( info.msg.hwnd, info.msg.message, &info.msg.wParam,
2872 &info.msg.lParam, &buffer, size ))
2873 continue; /* ignore it */
2875 *msg = info.msg;
2876 msg->pt = point_phys_to_win_dpi( info.msg.hwnd, info.msg.pt );
2877 thread_info->GetMessagePosVal = MAKELONG( msg->pt.x, msg->pt.y );
2878 thread_info->GetMessageTimeVal = info.msg.time;
2879 thread_info->GetMessageExtraInfoVal = 0;
2880 thread_info->msg_source = msg_source_unavailable;
2881 HeapFree( GetProcessHeap(), 0, buffer );
2882 HOOK_CallHooks( WH_GETMESSAGE, HC_ACTION, flags & PM_REMOVE, (LPARAM)msg, TRUE );
2883 return 1;
2886 /* if we get here, we have a sent message; call the window procedure */
2887 old_info = thread_info->receive_info;
2888 thread_info->receive_info = &info;
2889 thread_info->msg_source = msg_source_unavailable;
2890 result = call_window_proc( info.msg.hwnd, info.msg.message, info.msg.wParam,
2891 info.msg.lParam, (info.type != MSG_ASCII), FALSE,
2892 WMCHAR_MAP_RECVMESSAGE );
2893 reply_message( &info, result, TRUE );
2894 thread_info->receive_info = old_info;
2896 /* if some PM_QS* flags were specified, only handle sent messages from now on */
2897 if (HIWORD(flags) && !changed_mask) flags = PM_QS_SENDMESSAGE | LOWORD(flags);
2902 /***********************************************************************
2903 * process_sent_messages
2905 * Process all pending sent messages.
2907 static inline void process_sent_messages(void)
2909 MSG msg;
2910 peek_message( &msg, 0, 0, 0, PM_REMOVE | PM_QS_SENDMESSAGE, 0 );
2914 /***********************************************************************
2915 * get_server_queue_handle
2917 * Get a handle to the server message queue for the current thread.
2919 static HANDLE get_server_queue_handle(void)
2921 struct user_thread_info *thread_info = get_user_thread_info();
2922 HANDLE ret;
2924 if (!(ret = thread_info->server_queue))
2926 SERVER_START_REQ( get_msg_queue )
2928 wine_server_call( req );
2929 ret = wine_server_ptr_handle( reply->handle );
2931 SERVER_END_REQ;
2932 thread_info->server_queue = ret;
2933 if (!ret) ERR( "Cannot get server thread queue\n" );
2935 return ret;
2939 /***********************************************************************
2940 * wait_message_reply
2942 * Wait until a sent message gets replied to.
2944 static void wait_message_reply( UINT flags )
2946 struct user_thread_info *thread_info = get_user_thread_info();
2947 HANDLE server_queue = get_server_queue_handle();
2948 unsigned int wake_mask = QS_SMRESULT | ((flags & SMTO_BLOCK) ? 0 : QS_SENDMESSAGE);
2950 for (;;)
2952 unsigned int wake_bits = 0;
2954 SERVER_START_REQ( set_queue_mask )
2956 req->wake_mask = wake_mask;
2957 req->changed_mask = wake_mask;
2958 req->skip_wait = 1;
2959 if (!wine_server_call( req )) wake_bits = reply->wake_bits & wake_mask;
2961 SERVER_END_REQ;
2963 thread_info->wake_mask = thread_info->changed_mask = 0;
2965 if (wake_bits & QS_SMRESULT) return; /* got a result */
2966 if (wake_bits & QS_SENDMESSAGE)
2968 /* Process the sent message immediately */
2969 process_sent_messages();
2970 continue;
2973 wow_handlers.wait_message( 1, &server_queue, INFINITE, wake_mask, 0 );
2978 /***********************************************************************
2979 * wait_objects
2981 * Wait for multiple objects including the server queue, with specific queue masks.
2983 static DWORD wait_objects( DWORD count, const HANDLE *handles, DWORD timeout,
2984 DWORD wake_mask, DWORD changed_mask, DWORD flags )
2986 struct user_thread_info *thread_info = get_user_thread_info();
2987 DWORD ret;
2989 assert( count ); /* we must have at least the server queue */
2991 flush_window_surfaces( TRUE );
2993 if (thread_info->wake_mask != wake_mask || thread_info->changed_mask != changed_mask)
2995 SERVER_START_REQ( set_queue_mask )
2997 req->wake_mask = wake_mask;
2998 req->changed_mask = changed_mask;
2999 req->skip_wait = 0;
3000 wine_server_call( req );
3002 SERVER_END_REQ;
3003 thread_info->wake_mask = wake_mask;
3004 thread_info->changed_mask = changed_mask;
3007 ret = wow_handlers.wait_message( count, handles, timeout, changed_mask, flags );
3009 if (ret != WAIT_TIMEOUT) thread_info->wake_mask = thread_info->changed_mask = 0;
3010 return ret;
3014 /***********************************************************************
3015 * put_message_in_queue
3017 * Put a sent message into the destination queue.
3018 * For inter-process message, reply_size is set to expected size of reply data.
3020 static BOOL put_message_in_queue( const struct send_message_info *info, size_t *reply_size )
3022 struct packed_message data;
3023 message_data_t msg_data;
3024 unsigned int res;
3025 int i;
3026 timeout_t timeout = TIMEOUT_INFINITE;
3028 /* Check for INFINITE timeout for compatibility with Win9x,
3029 * although Windows >= NT does not do so
3031 if (info->type != MSG_NOTIFY &&
3032 info->type != MSG_CALLBACK &&
3033 info->type != MSG_POSTED &&
3034 info->timeout &&
3035 info->timeout != INFINITE)
3037 /* timeout is signed despite the prototype */
3038 timeout = (timeout_t)max( 0, (int)info->timeout ) * -10000;
3041 memset( &data, 0, sizeof(data) );
3042 if (info->type == MSG_OTHER_PROCESS || info->type == MSG_NOTIFY)
3044 *reply_size = pack_message( info->hwnd, info->msg, info->wparam, info->lparam, &data );
3045 if (data.count == -1)
3047 WARN( "cannot pack message %x\n", info->msg );
3048 return FALSE;
3051 else if (info->type == MSG_CALLBACK)
3053 msg_data.callback.callback = wine_server_client_ptr( info->callback );
3054 msg_data.callback.data = info->data;
3055 msg_data.callback.result = 0;
3056 data.data[0] = &msg_data;
3057 data.size[0] = sizeof(msg_data.callback);
3058 data.count = 1;
3060 else if (info->type == MSG_POSTED && info->msg >= WM_DDE_FIRST && info->msg <= WM_DDE_LAST)
3062 return post_dde_message( &data, info );
3065 SERVER_START_REQ( send_message )
3067 req->id = info->dest_tid;
3068 req->type = info->type;
3069 req->flags = 0;
3070 req->win = wine_server_user_handle( info->hwnd );
3071 req->msg = info->msg;
3072 req->wparam = info->wparam;
3073 req->lparam = info->lparam;
3074 req->timeout = timeout;
3076 if (info->flags & SMTO_ABORTIFHUNG) req->flags |= SEND_MSG_ABORT_IF_HUNG;
3077 for (i = 0; i < data.count; i++) wine_server_add_data( req, data.data[i], data.size[i] );
3078 if ((res = wine_server_call( req )))
3080 if (res == STATUS_INVALID_PARAMETER)
3081 /* FIXME: find a STATUS_ value for this one */
3082 SetLastError( ERROR_INVALID_THREAD_ID );
3083 else
3084 SetLastError( RtlNtStatusToDosError(res) );
3087 SERVER_END_REQ;
3088 return !res;
3092 /***********************************************************************
3093 * retrieve_reply
3095 * Retrieve a message reply from the server.
3097 static LRESULT retrieve_reply( const struct send_message_info *info,
3098 size_t reply_size, LRESULT *result )
3100 NTSTATUS status;
3101 void *reply_data = NULL;
3103 if (reply_size)
3105 if (!(reply_data = HeapAlloc( GetProcessHeap(), 0, reply_size )))
3107 WARN( "no memory for reply, will be truncated\n" );
3108 reply_size = 0;
3111 SERVER_START_REQ( get_message_reply )
3113 req->cancel = 1;
3114 if (reply_size) wine_server_set_reply( req, reply_data, reply_size );
3115 if (!(status = wine_server_call( req ))) *result = reply->result;
3116 reply_size = wine_server_reply_size( reply );
3118 SERVER_END_REQ;
3119 if (!status && reply_size)
3120 unpack_reply( info->hwnd, info->msg, info->wparam, info->lparam, reply_data, reply_size );
3122 HeapFree( GetProcessHeap(), 0, reply_data );
3124 TRACE( "hwnd %p msg %x (%s) wp %lx lp %lx got reply %lx (err=%d)\n",
3125 info->hwnd, info->msg, SPY_GetMsgName(info->msg, info->hwnd), info->wparam,
3126 info->lparam, *result, status );
3128 /* MSDN states that last error is 0 on timeout, but at least NT4 returns ERROR_TIMEOUT */
3129 if (status) SetLastError( RtlNtStatusToDosError(status) );
3130 return !status;
3134 /***********************************************************************
3135 * send_inter_thread_message
3137 static LRESULT send_inter_thread_message( const struct send_message_info *info, LRESULT *res_ptr )
3139 size_t reply_size = 0;
3141 TRACE( "hwnd %p msg %x (%s) wp %lx lp %lx\n",
3142 info->hwnd, info->msg, SPY_GetMsgName(info->msg, info->hwnd), info->wparam, info->lparam );
3144 USER_CheckNotLock();
3146 if (!put_message_in_queue( info, &reply_size )) return 0;
3148 /* there's no reply to wait for on notify/callback messages */
3149 if (info->type == MSG_NOTIFY || info->type == MSG_CALLBACK) return 1;
3151 wait_message_reply( info->flags );
3152 return retrieve_reply( info, reply_size, res_ptr );
3156 /***********************************************************************
3157 * send_inter_thread_callback
3159 static LRESULT send_inter_thread_callback( HWND hwnd, UINT msg, WPARAM wp, LPARAM lp,
3160 LRESULT *result, void *arg )
3162 struct send_message_info *info = arg;
3163 info->hwnd = hwnd;
3164 info->msg = msg;
3165 info->wparam = wp;
3166 info->lparam = lp;
3167 return send_inter_thread_message( info, result );
3170 static BOOL is_message_broadcastable(UINT msg)
3172 return msg < WM_USER || msg >= 0xc000;
3175 /***********************************************************************
3176 * send_message
3178 * Backend implementation of the various SendMessage functions.
3180 static BOOL send_message( struct send_message_info *info, DWORD_PTR *res_ptr, BOOL unicode )
3182 struct user_thread_info *thread_info = get_user_thread_info();
3183 INPUT_MESSAGE_SOURCE prev_source = thread_info->msg_source;
3184 DWORD dest_pid;
3185 BOOL ret;
3186 LRESULT result;
3188 if (is_broadcast(info->hwnd))
3190 if (is_message_broadcastable( info->msg ))
3191 EnumWindows( broadcast_message_callback, (LPARAM)info );
3192 if (res_ptr) *res_ptr = 1;
3193 return TRUE;
3196 if (!(info->dest_tid = GetWindowThreadProcessId( info->hwnd, &dest_pid ))) return FALSE;
3198 if (USER_IsExitingThread( info->dest_tid )) return FALSE;
3200 thread_info->msg_source = msg_source_unavailable;
3201 SPY_EnterMessage( SPY_SENDMESSAGE, info->hwnd, info->msg, info->wparam, info->lparam );
3203 if (info->dest_tid == GetCurrentThreadId())
3205 result = call_window_proc( info->hwnd, info->msg, info->wparam, info->lparam,
3206 unicode, TRUE, info->wm_char );
3207 if (info->type == MSG_CALLBACK)
3208 call_sendmsg_callback( info->callback, info->hwnd, info->msg, info->data, result );
3209 ret = TRUE;
3211 else
3213 if (dest_pid != GetCurrentProcessId() && (info->type == MSG_ASCII || info->type == MSG_UNICODE))
3214 info->type = MSG_OTHER_PROCESS;
3216 /* MSG_ASCII can be sent unconverted except for WM_CHAR; everything else needs to be Unicode */
3217 if (!unicode && is_unicode_message( info->msg ) &&
3218 (info->type != MSG_ASCII || info->msg == WM_CHAR))
3219 ret = WINPROC_CallProcAtoW( send_inter_thread_callback, info->hwnd, info->msg,
3220 info->wparam, info->lparam, &result, info, info->wm_char );
3221 else
3222 ret = send_inter_thread_message( info, &result );
3225 SPY_ExitMessage( SPY_RESULT_OK, info->hwnd, info->msg, result, info->wparam, info->lparam );
3226 thread_info->msg_source = prev_source;
3227 if (ret && res_ptr) *res_ptr = result;
3228 return ret;
3232 /***********************************************************************
3233 * send_hardware_message
3235 NTSTATUS send_hardware_message( HWND hwnd, const INPUT *input, const RAWINPUT *rawinput, UINT flags )
3237 struct user_key_state_info *key_state_info = get_user_thread_info()->key_state;
3238 struct send_message_info info;
3239 int prev_x, prev_y, new_x, new_y;
3240 INT counter = global_key_state_counter;
3241 USAGE hid_usage_page, hid_usage;
3242 NTSTATUS ret;
3243 BOOL wait;
3245 info.type = MSG_HARDWARE;
3246 info.dest_tid = 0;
3247 info.hwnd = hwnd;
3248 info.flags = 0;
3249 info.timeout = 0;
3251 if (input->type == INPUT_HARDWARE && rawinput->header.dwType == RIM_TYPEHID)
3253 if (input->u.hi.uMsg == WM_INPUT_DEVICE_CHANGE)
3255 hid_usage_page = ((USAGE *)rawinput->data.hid.bRawData)[0];
3256 hid_usage = ((USAGE *)rawinput->data.hid.bRawData)[1];
3258 if (input->u.hi.uMsg == WM_INPUT)
3260 if (!rawinput_device_get_usages( rawinput->header.hDevice, &hid_usage_page, &hid_usage ))
3262 WARN( "unable to get HID usages for device %p\n", rawinput->header.hDevice );
3263 return STATUS_INVALID_HANDLE;
3268 SERVER_START_REQ( send_hardware_message )
3270 req->win = wine_server_user_handle( hwnd );
3271 req->flags = flags;
3272 req->input.type = input->type;
3273 switch (input->type)
3275 case INPUT_MOUSE:
3276 req->input.mouse.x = input->u.mi.dx;
3277 req->input.mouse.y = input->u.mi.dy;
3278 req->input.mouse.data = input->u.mi.mouseData;
3279 req->input.mouse.flags = input->u.mi.dwFlags;
3280 req->input.mouse.time = input->u.mi.time;
3281 req->input.mouse.info = input->u.mi.dwExtraInfo;
3282 break;
3283 case INPUT_KEYBOARD:
3284 req->input.kbd.vkey = input->u.ki.wVk;
3285 req->input.kbd.scan = input->u.ki.wScan;
3286 req->input.kbd.flags = input->u.ki.dwFlags;
3287 req->input.kbd.time = input->u.ki.time;
3288 req->input.kbd.info = input->u.ki.dwExtraInfo;
3289 break;
3290 case INPUT_HARDWARE:
3291 req->input.hw.msg = input->u.hi.uMsg;
3292 req->input.hw.lparam = MAKELONG( input->u.hi.wParamL, input->u.hi.wParamH );
3293 switch (input->u.hi.uMsg)
3295 case WM_INPUT:
3296 case WM_INPUT_DEVICE_CHANGE:
3297 req->input.hw.rawinput.type = rawinput->header.dwType;
3298 switch (rawinput->header.dwType)
3300 case RIM_TYPEHID:
3301 req->input.hw.rawinput.hid.device = HandleToUlong( rawinput->header.hDevice );
3302 req->input.hw.rawinput.hid.param = rawinput->header.wParam;
3303 req->input.hw.rawinput.hid.usage_page = hid_usage_page;
3304 req->input.hw.rawinput.hid.usage = hid_usage;
3305 req->input.hw.rawinput.hid.count = rawinput->data.hid.dwCount;
3306 req->input.hw.rawinput.hid.length = rawinput->data.hid.dwSizeHid;
3307 wine_server_add_data( req, rawinput->data.hid.bRawData,
3308 rawinput->data.hid.dwCount * rawinput->data.hid.dwSizeHid );
3309 break;
3310 default:
3311 assert( 0 );
3312 break;
3315 break;
3317 if (key_state_info) wine_server_set_reply( req, key_state_info->state,
3318 sizeof(key_state_info->state) );
3319 ret = wine_server_call( req );
3320 wait = reply->wait;
3321 prev_x = reply->prev_x;
3322 prev_y = reply->prev_y;
3323 new_x = reply->new_x;
3324 new_y = reply->new_y;
3326 SERVER_END_REQ;
3328 if (!ret)
3330 if (key_state_info)
3332 key_state_info->time = GetTickCount();
3333 key_state_info->counter = counter;
3335 if ((flags & SEND_HWMSG_INJECTED) && (prev_x != new_x || prev_y != new_y))
3336 USER_Driver->pSetCursorPos( new_x, new_y );
3339 if (wait)
3341 LRESULT ignored;
3342 wait_message_reply( 0 );
3343 retrieve_reply( &info, 0, &ignored );
3345 return ret;
3349 /***********************************************************************
3350 * MSG_SendInternalMessageTimeout
3352 * Same as SendMessageTimeoutW but sends the message to a specific thread
3353 * without requiring a window handle. Only works for internal Wine messages.
3355 LRESULT MSG_SendInternalMessageTimeout( DWORD dest_pid, DWORD dest_tid,
3356 UINT msg, WPARAM wparam, LPARAM lparam,
3357 UINT flags, UINT timeout, PDWORD_PTR res_ptr )
3359 struct send_message_info info;
3360 LRESULT ret, result;
3362 assert( msg & 0x80000000 ); /* must be an internal Wine message */
3364 info.type = MSG_UNICODE;
3365 info.dest_tid = dest_tid;
3366 info.hwnd = 0;
3367 info.msg = msg;
3368 info.wparam = wparam;
3369 info.lparam = lparam;
3370 info.flags = flags;
3371 info.timeout = timeout;
3373 if (USER_IsExitingThread( dest_tid )) return 0;
3375 if (dest_tid == GetCurrentThreadId())
3377 result = handle_internal_message( 0, msg, wparam, lparam );
3378 ret = 1;
3380 else
3382 if (dest_pid != GetCurrentProcessId()) info.type = MSG_OTHER_PROCESS;
3383 ret = send_inter_thread_message( &info, &result );
3385 if (ret && res_ptr) *res_ptr = result;
3386 return ret;
3390 /***********************************************************************
3391 * SendMessageTimeoutW (USER32.@)
3393 LRESULT WINAPI SendMessageTimeoutW( HWND hwnd, UINT msg, WPARAM wparam, LPARAM lparam,
3394 UINT flags, UINT timeout, PDWORD_PTR res_ptr )
3396 struct send_message_info info;
3398 info.type = MSG_UNICODE;
3399 info.hwnd = hwnd;
3400 info.msg = msg;
3401 info.wparam = wparam;
3402 info.lparam = lparam;
3403 info.flags = flags;
3404 info.timeout = timeout;
3406 return send_message( &info, res_ptr, TRUE );
3409 /***********************************************************************
3410 * SendMessageTimeoutA (USER32.@)
3412 LRESULT WINAPI SendMessageTimeoutA( HWND hwnd, UINT msg, WPARAM wparam, LPARAM lparam,
3413 UINT flags, UINT timeout, PDWORD_PTR res_ptr )
3415 struct send_message_info info;
3417 info.type = MSG_ASCII;
3418 info.hwnd = hwnd;
3419 info.msg = msg;
3420 info.wparam = wparam;
3421 info.lparam = lparam;
3422 info.flags = flags;
3423 info.timeout = timeout;
3424 info.wm_char = WMCHAR_MAP_SENDMESSAGETIMEOUT;
3426 return send_message( &info, res_ptr, FALSE );
3430 /***********************************************************************
3431 * SendMessageW (USER32.@)
3433 LRESULT WINAPI SendMessageW( HWND hwnd, UINT msg, WPARAM wparam, LPARAM lparam )
3435 DWORD_PTR res = 0;
3436 struct send_message_info info;
3438 info.type = MSG_UNICODE;
3439 info.hwnd = hwnd;
3440 info.msg = msg;
3441 info.wparam = wparam;
3442 info.lparam = lparam;
3443 info.flags = SMTO_NORMAL;
3444 info.timeout = 0;
3446 send_message( &info, &res, TRUE );
3447 return res;
3451 /***********************************************************************
3452 * SendMessageA (USER32.@)
3454 LRESULT WINAPI SendMessageA( HWND hwnd, UINT msg, WPARAM wparam, LPARAM lparam )
3456 DWORD_PTR res = 0;
3457 struct send_message_info info;
3459 info.type = MSG_ASCII;
3460 info.hwnd = hwnd;
3461 info.msg = msg;
3462 info.wparam = wparam;
3463 info.lparam = lparam;
3464 info.flags = SMTO_NORMAL;
3465 info.timeout = 0;
3466 info.wm_char = WMCHAR_MAP_SENDMESSAGE;
3468 send_message( &info, &res, FALSE );
3469 return res;
3473 /***********************************************************************
3474 * SendNotifyMessageA (USER32.@)
3476 BOOL WINAPI SendNotifyMessageA( HWND hwnd, UINT msg, WPARAM wparam, LPARAM lparam )
3478 struct send_message_info info;
3480 if (is_pointer_message( msg, wparam ))
3482 SetLastError( ERROR_MESSAGE_SYNC_ONLY );
3483 return FALSE;
3486 info.type = MSG_NOTIFY;
3487 info.hwnd = hwnd;
3488 info.msg = msg;
3489 info.wparam = wparam;
3490 info.lparam = lparam;
3491 info.flags = 0;
3492 info.wm_char = WMCHAR_MAP_SENDMESSAGETIMEOUT;
3494 return send_message( &info, NULL, FALSE );
3498 /***********************************************************************
3499 * SendNotifyMessageW (USER32.@)
3501 BOOL WINAPI SendNotifyMessageW( HWND hwnd, UINT msg, WPARAM wparam, LPARAM lparam )
3503 struct send_message_info info;
3505 if (is_pointer_message( msg, wparam ))
3507 SetLastError( ERROR_MESSAGE_SYNC_ONLY );
3508 return FALSE;
3511 info.type = MSG_NOTIFY;
3512 info.hwnd = hwnd;
3513 info.msg = msg;
3514 info.wparam = wparam;
3515 info.lparam = lparam;
3516 info.flags = 0;
3518 return send_message( &info, NULL, TRUE );
3522 /***********************************************************************
3523 * SendMessageCallbackA (USER32.@)
3525 BOOL WINAPI SendMessageCallbackA( HWND hwnd, UINT msg, WPARAM wparam, LPARAM lparam,
3526 SENDASYNCPROC callback, ULONG_PTR data )
3528 struct send_message_info info;
3530 if (is_pointer_message( msg, wparam ))
3532 SetLastError( ERROR_MESSAGE_SYNC_ONLY );
3533 return FALSE;
3536 info.type = MSG_CALLBACK;
3537 info.hwnd = hwnd;
3538 info.msg = msg;
3539 info.wparam = wparam;
3540 info.lparam = lparam;
3541 info.callback = callback;
3542 info.data = data;
3543 info.flags = 0;
3544 info.wm_char = WMCHAR_MAP_SENDMESSAGETIMEOUT;
3546 return send_message( &info, NULL, FALSE );
3550 /***********************************************************************
3551 * SendMessageCallbackW (USER32.@)
3553 BOOL WINAPI SendMessageCallbackW( HWND hwnd, UINT msg, WPARAM wparam, LPARAM lparam,
3554 SENDASYNCPROC callback, ULONG_PTR data )
3556 struct send_message_info info;
3558 if (is_pointer_message( msg, wparam ))
3560 SetLastError( ERROR_MESSAGE_SYNC_ONLY );
3561 return FALSE;
3564 info.type = MSG_CALLBACK;
3565 info.hwnd = hwnd;
3566 info.msg = msg;
3567 info.wparam = wparam;
3568 info.lparam = lparam;
3569 info.callback = callback;
3570 info.data = data;
3571 info.flags = 0;
3573 return send_message( &info, NULL, TRUE );
3577 /***********************************************************************
3578 * ReplyMessage (USER32.@)
3580 BOOL WINAPI ReplyMessage( LRESULT result )
3582 struct received_message_info *info = get_user_thread_info()->receive_info;
3584 if (!info) return FALSE;
3585 reply_message( info, result, FALSE );
3586 return TRUE;
3590 /***********************************************************************
3591 * InSendMessage (USER32.@)
3593 BOOL WINAPI InSendMessage(void)
3595 return (InSendMessageEx( NULL ) & (ISMEX_SEND | ISMEX_NOTIFY | ISMEX_CALLBACK)) != 0;
3599 /***********************************************************************
3600 * InSendMessageEx (USER32.@)
3602 DWORD WINAPI InSendMessageEx( LPVOID reserved )
3604 struct received_message_info *info = get_user_thread_info()->receive_info;
3606 if (info) return info->flags;
3607 return ISMEX_NOSEND;
3611 /***********************************************************************
3612 * PostMessageA (USER32.@)
3614 BOOL WINAPI PostMessageA( HWND hwnd, UINT msg, WPARAM wparam, LPARAM lparam )
3616 if (!map_wparam_AtoW( msg, &wparam, WMCHAR_MAP_POSTMESSAGE )) return TRUE;
3617 return PostMessageW( hwnd, msg, wparam, lparam );
3621 /***********************************************************************
3622 * PostMessageW (USER32.@)
3624 BOOL WINAPI PostMessageW( HWND hwnd, UINT msg, WPARAM wparam, LPARAM lparam )
3626 struct send_message_info info;
3628 if (is_pointer_message( msg, wparam ))
3630 SetLastError( ERROR_MESSAGE_SYNC_ONLY );
3631 return FALSE;
3634 TRACE( "hwnd %p msg %x (%s) wp %lx lp %lx\n",
3635 hwnd, msg, SPY_GetMsgName(msg, hwnd), wparam, lparam );
3637 info.type = MSG_POSTED;
3638 info.hwnd = hwnd;
3639 info.msg = msg;
3640 info.wparam = wparam;
3641 info.lparam = lparam;
3642 info.flags = 0;
3644 if (is_broadcast(hwnd))
3646 if (is_message_broadcastable( info.msg ))
3647 EnumWindows( broadcast_message_callback, (LPARAM)&info );
3648 return TRUE;
3651 if (!hwnd) return PostThreadMessageW( GetCurrentThreadId(), msg, wparam, lparam );
3653 if (!(info.dest_tid = GetWindowThreadProcessId( hwnd, NULL ))) return FALSE;
3655 if (USER_IsExitingThread( info.dest_tid )) return TRUE;
3657 return put_message_in_queue( &info, NULL );
3661 /**********************************************************************
3662 * PostThreadMessageA (USER32.@)
3664 BOOL WINAPI PostThreadMessageA( DWORD thread, UINT msg, WPARAM wparam, LPARAM lparam )
3666 if (!map_wparam_AtoW( msg, &wparam, WMCHAR_MAP_POSTMESSAGE )) return TRUE;
3667 return PostThreadMessageW( thread, msg, wparam, lparam );
3671 /**********************************************************************
3672 * PostThreadMessageW (USER32.@)
3674 BOOL WINAPI PostThreadMessageW( DWORD thread, UINT msg, WPARAM wparam, LPARAM lparam )
3676 struct send_message_info info;
3678 if (is_pointer_message( msg, wparam ))
3680 SetLastError( ERROR_MESSAGE_SYNC_ONLY );
3681 return FALSE;
3683 if (USER_IsExitingThread( thread )) return TRUE;
3685 info.type = MSG_POSTED;
3686 info.dest_tid = thread;
3687 info.hwnd = 0;
3688 info.msg = msg;
3689 info.wparam = wparam;
3690 info.lparam = lparam;
3691 info.flags = 0;
3692 return put_message_in_queue( &info, NULL );
3696 /***********************************************************************
3697 * PostQuitMessage (USER32.@)
3699 * Posts a quit message to the current thread's message queue.
3701 * PARAMS
3702 * exit_code [I] Exit code to return from message loop.
3704 * RETURNS
3705 * Nothing.
3707 * NOTES
3708 * This function is not the same as calling:
3709 *|PostThreadMessage(GetCurrentThreadId(), WM_QUIT, exit_code, 0);
3710 * It instead sets a flag in the message queue that signals it to generate
3711 * a WM_QUIT message when there are no other pending sent or posted messages
3712 * in the queue.
3714 void WINAPI PostQuitMessage( INT exit_code )
3716 SERVER_START_REQ( post_quit_message )
3718 req->exit_code = exit_code;
3719 wine_server_call( req );
3721 SERVER_END_REQ;
3724 /* check for driver events if we detect that the app is not properly consuming messages */
3725 static inline void check_for_driver_events( UINT msg )
3727 if (get_user_thread_info()->message_count > 200)
3729 flush_window_surfaces( FALSE );
3730 USER_Driver->pMsgWaitForMultipleObjectsEx( 0, NULL, 0, QS_ALLINPUT, 0 );
3732 else if (msg == WM_TIMER || msg == WM_SYSTIMER)
3734 /* driver events should have priority over timers, so make sure we'll check for them soon */
3735 get_user_thread_info()->message_count += 100;
3737 else get_user_thread_info()->message_count++;
3740 /***********************************************************************
3741 * PeekMessageW (USER32.@)
3743 BOOL WINAPI DECLSPEC_HOTPATCH PeekMessageW( MSG *msg_out, HWND hwnd, UINT first, UINT last, UINT flags )
3745 MSG msg;
3746 int ret;
3748 USER_CheckNotLock();
3749 check_for_driver_events( 0 );
3751 ret = peek_message( &msg, hwnd, first, last, flags, 0 );
3752 if (ret < 0) return FALSE;
3754 if (!ret)
3756 flush_window_surfaces( TRUE );
3757 ret = wow_handlers.wait_message( 0, NULL, 0, QS_ALLINPUT, 0 );
3758 /* if we received driver events, check again for a pending message */
3759 if (ret == WAIT_TIMEOUT || peek_message( &msg, hwnd, first, last, flags, 0 ) <= 0) return FALSE;
3762 check_for_driver_events( msg.message );
3764 /* copy back our internal safe copy of message data to msg_out.
3765 * msg_out is a variable from the *program*, so it can't be used
3766 * internally as it can get "corrupted" by our use of SendMessage()
3767 * (back to the program) inside the message handling itself. */
3768 if (!msg_out)
3770 SetLastError( ERROR_NOACCESS );
3771 return FALSE;
3773 *msg_out = msg;
3774 return TRUE;
3778 /***********************************************************************
3779 * PeekMessageA (USER32.@)
3781 BOOL WINAPI DECLSPEC_HOTPATCH PeekMessageA( MSG *msg, HWND hwnd, UINT first, UINT last, UINT flags )
3783 if (get_pending_wmchar( msg, first, last, (flags & PM_REMOVE) )) return TRUE;
3784 if (!PeekMessageW( msg, hwnd, first, last, flags )) return FALSE;
3785 map_wparam_WtoA( msg, (flags & PM_REMOVE) );
3786 return TRUE;
3790 /***********************************************************************
3791 * GetMessageW (USER32.@)
3793 BOOL WINAPI DECLSPEC_HOTPATCH GetMessageW( MSG *msg, HWND hwnd, UINT first, UINT last )
3795 HANDLE server_queue = get_server_queue_handle();
3796 unsigned int mask = QS_POSTMESSAGE | QS_SENDMESSAGE; /* Always selected */
3797 int ret;
3799 USER_CheckNotLock();
3800 check_for_driver_events( 0 );
3802 if (first || last)
3804 if ((first <= WM_KEYLAST) && (last >= WM_KEYFIRST)) mask |= QS_KEY;
3805 if ( ((first <= WM_MOUSELAST) && (last >= WM_MOUSEFIRST)) ||
3806 ((first <= WM_NCMOUSELAST) && (last >= WM_NCMOUSEFIRST)) ) mask |= QS_MOUSE;
3807 if ((first <= WM_TIMER) && (last >= WM_TIMER)) mask |= QS_TIMER;
3808 if ((first <= WM_SYSTIMER) && (last >= WM_SYSTIMER)) mask |= QS_TIMER;
3809 if ((first <= WM_PAINT) && (last >= WM_PAINT)) mask |= QS_PAINT;
3811 else mask = QS_ALLINPUT;
3813 while (!(ret = peek_message( msg, hwnd, first, last, PM_REMOVE | (mask << 16), mask )))
3815 wait_objects( 1, &server_queue, INFINITE, mask & (QS_SENDMESSAGE | QS_SMRESULT), mask, 0 );
3817 if (ret < 0) return -1;
3819 check_for_driver_events( msg->message );
3821 return (msg->message != WM_QUIT);
3825 /***********************************************************************
3826 * GetMessageA (USER32.@)
3828 BOOL WINAPI DECLSPEC_HOTPATCH GetMessageA( MSG *msg, HWND hwnd, UINT first, UINT last )
3830 if (get_pending_wmchar( msg, first, last, TRUE )) return TRUE;
3831 if (GetMessageW( msg, hwnd, first, last ) < 0) return -1;
3832 map_wparam_WtoA( msg, TRUE );
3833 return (msg->message != WM_QUIT);
3837 /***********************************************************************
3838 * IsDialogMessageA (USER32.@)
3839 * IsDialogMessage (USER32.@)
3841 BOOL WINAPI IsDialogMessageA( HWND hwndDlg, LPMSG pmsg )
3843 MSG msg = *pmsg;
3844 map_wparam_AtoW( msg.message, &msg.wParam, WMCHAR_MAP_NOMAPPING );
3845 return IsDialogMessageW( hwndDlg, &msg );
3849 /***********************************************************************
3850 * TranslateMessage (USER32.@)
3852 * Implementation of TranslateMessage.
3854 * TranslateMessage translates virtual-key messages into character-messages,
3855 * as follows :
3856 * WM_KEYDOWN/WM_KEYUP combinations produce a WM_CHAR or WM_DEADCHAR message.
3857 * ditto replacing WM_* with WM_SYS*
3858 * This produces WM_CHAR messages only for keys mapped to ASCII characters
3859 * by the keyboard driver.
3861 * If the message is WM_KEYDOWN, WM_KEYUP, WM_SYSKEYDOWN, or WM_SYSKEYUP, the
3862 * return value is nonzero, regardless of the translation.
3865 BOOL WINAPI TranslateMessage( const MSG *msg )
3867 UINT message;
3868 WCHAR wp[8];
3869 BYTE state[256];
3870 INT len;
3872 if (msg->message < WM_KEYFIRST || msg->message > WM_KEYLAST) return FALSE;
3873 if (msg->message != WM_KEYDOWN && msg->message != WM_SYSKEYDOWN) return TRUE;
3875 TRACE_(key)("Translating key %s (%04lX), scancode %04x\n",
3876 SPY_GetVKeyName(msg->wParam), msg->wParam, HIWORD(msg->lParam));
3878 switch (msg->wParam)
3880 case VK_PACKET:
3881 message = (msg->message == WM_KEYDOWN) ? WM_CHAR : WM_SYSCHAR;
3882 TRACE_(key)("PostMessageW(%p,%s,%04x,%08x)\n",
3883 msg->hwnd, SPY_GetMsgName(message, msg->hwnd), HIWORD(msg->lParam), LOWORD(msg->lParam));
3884 PostMessageW( msg->hwnd, message, HIWORD(msg->lParam), LOWORD(msg->lParam));
3885 return TRUE;
3887 case VK_PROCESSKEY:
3888 return ImmTranslateMessage(msg->hwnd, msg->message, msg->wParam, msg->lParam);
3891 GetKeyboardState( state );
3892 len = ToUnicode(msg->wParam, HIWORD(msg->lParam), state, wp, ARRAY_SIZE(wp), 0);
3893 if (len == -1)
3895 message = (msg->message == WM_KEYDOWN) ? WM_DEADCHAR : WM_SYSDEADCHAR;
3896 TRACE_(key)("-1 -> PostMessageW(%p,%s,%04x,%08lx)\n",
3897 msg->hwnd, SPY_GetMsgName(message, msg->hwnd), wp[0], msg->lParam);
3898 PostMessageW( msg->hwnd, message, wp[0], msg->lParam );
3900 else if (len > 0)
3902 INT i;
3904 message = (msg->message == WM_KEYDOWN) ? WM_CHAR : WM_SYSCHAR;
3905 TRACE_(key)("%d -> PostMessageW(%p,%s,<x>,%08lx) for <x> in %s\n", len, msg->hwnd,
3906 SPY_GetMsgName(message, msg->hwnd), msg->lParam, debugstr_wn(wp, len));
3907 for (i = 0; i < len; i++)
3908 PostMessageW( msg->hwnd, message, wp[i], msg->lParam );
3910 return TRUE;
3914 /***********************************************************************
3915 * DispatchMessageA (USER32.@)
3917 * See DispatchMessageW.
3919 LRESULT WINAPI DECLSPEC_HOTPATCH DispatchMessageA( const MSG* msg )
3921 LRESULT retval;
3923 /* Process timer messages */
3924 if ((msg->message == WM_TIMER) || (msg->message == WM_SYSTIMER))
3926 if (msg->lParam)
3928 __TRY
3930 retval = CallWindowProcA( (WNDPROC)msg->lParam, msg->hwnd,
3931 msg->message, msg->wParam, GetTickCount() );
3933 __EXCEPT_ALL
3935 retval = 0;
3937 __ENDTRY
3938 return retval;
3941 if (!msg->hwnd) return 0;
3943 SPY_EnterMessage( SPY_DISPATCHMESSAGE, msg->hwnd, msg->message,
3944 msg->wParam, msg->lParam );
3946 if (!WINPROC_call_window( msg->hwnd, msg->message, msg->wParam, msg->lParam,
3947 &retval, FALSE, WMCHAR_MAP_DISPATCHMESSAGE ))
3949 if (!IsWindow( msg->hwnd )) SetLastError( ERROR_INVALID_WINDOW_HANDLE );
3950 else SetLastError( ERROR_MESSAGE_SYNC_ONLY );
3951 retval = 0;
3954 SPY_ExitMessage( SPY_RESULT_OK, msg->hwnd, msg->message, retval,
3955 msg->wParam, msg->lParam );
3957 if (msg->message == WM_PAINT)
3959 /* send a WM_NCPAINT and WM_ERASEBKGND if the non-client area is still invalid */
3960 HRGN hrgn = CreateRectRgn( 0, 0, 0, 0 );
3961 GetUpdateRgn( msg->hwnd, hrgn, TRUE );
3962 DeleteObject( hrgn );
3964 return retval;
3968 /***********************************************************************
3969 * DispatchMessageW (USER32.@) Process a message
3971 * Process the message specified in the structure *_msg_.
3973 * If the lpMsg parameter points to a WM_TIMER message and the
3974 * parameter of the WM_TIMER message is not NULL, the lParam parameter
3975 * points to the function that is called instead of the window
3976 * procedure. The function stored in lParam (timer callback) is protected
3977 * from causing page-faults.
3979 * The message must be valid.
3981 * RETURNS
3983 * DispatchMessage() returns the result of the window procedure invoked.
3985 * CONFORMANCE
3987 * ECMA-234, Win32
3990 LRESULT WINAPI DECLSPEC_HOTPATCH DispatchMessageW( const MSG* msg )
3992 LRESULT retval;
3994 /* Process timer messages */
3995 if ((msg->message == WM_TIMER) || (msg->message == WM_SYSTIMER))
3997 if (msg->lParam)
3999 __TRY
4001 retval = CallWindowProcW( (WNDPROC)msg->lParam, msg->hwnd,
4002 msg->message, msg->wParam, GetTickCount() );
4004 __EXCEPT_ALL
4006 retval = 0;
4008 __ENDTRY
4009 return retval;
4012 if (!msg->hwnd) return 0;
4014 SPY_EnterMessage( SPY_DISPATCHMESSAGE, msg->hwnd, msg->message,
4015 msg->wParam, msg->lParam );
4017 if (!WINPROC_call_window( msg->hwnd, msg->message, msg->wParam, msg->lParam,
4018 &retval, TRUE, WMCHAR_MAP_DISPATCHMESSAGE ))
4020 if (!IsWindow( msg->hwnd )) SetLastError( ERROR_INVALID_WINDOW_HANDLE );
4021 else SetLastError( ERROR_MESSAGE_SYNC_ONLY );
4022 retval = 0;
4025 SPY_ExitMessage( SPY_RESULT_OK, msg->hwnd, msg->message, retval,
4026 msg->wParam, msg->lParam );
4028 if (msg->message == WM_PAINT)
4030 /* send a WM_NCPAINT and WM_ERASEBKGND if the non-client area is still invalid */
4031 HRGN hrgn = CreateRectRgn( 0, 0, 0, 0 );
4032 GetUpdateRgn( msg->hwnd, hrgn, TRUE );
4033 DeleteObject( hrgn );
4035 return retval;
4039 /***********************************************************************
4040 * GetMessagePos (USER.119)
4041 * GetMessagePos (USER32.@)
4043 * The GetMessagePos() function returns a long value representing a
4044 * cursor position, in screen coordinates, when the last message
4045 * retrieved by the GetMessage() function occurs. The x-coordinate is
4046 * in the low-order word of the return value, the y-coordinate is in
4047 * the high-order word. The application can use the MAKEPOINT()
4048 * macro to obtain a POINT structure from the return value.
4050 * For the current cursor position, use GetCursorPos().
4052 * RETURNS
4054 * Cursor position of last message on success, zero on failure.
4056 * CONFORMANCE
4058 * ECMA-234, Win32
4061 DWORD WINAPI GetMessagePos(void)
4063 return get_user_thread_info()->GetMessagePosVal;
4067 /***********************************************************************
4068 * GetMessageTime (USER.120)
4069 * GetMessageTime (USER32.@)
4071 * GetMessageTime() returns the message time for the last message
4072 * retrieved by the function. The time is measured in milliseconds with
4073 * the same offset as GetTickCount().
4075 * Since the tick count wraps, this is only useful for moderately short
4076 * relative time comparisons.
4078 * RETURNS
4080 * Time of last message on success, zero on failure.
4082 LONG WINAPI GetMessageTime(void)
4084 return get_user_thread_info()->GetMessageTimeVal;
4088 /***********************************************************************
4089 * GetMessageExtraInfo (USER.288)
4090 * GetMessageExtraInfo (USER32.@)
4092 LPARAM WINAPI GetMessageExtraInfo(void)
4094 return get_user_thread_info()->GetMessageExtraInfoVal;
4098 /***********************************************************************
4099 * SetMessageExtraInfo (USER32.@)
4101 LPARAM WINAPI SetMessageExtraInfo(LPARAM lParam)
4103 struct user_thread_info *thread_info = get_user_thread_info();
4104 LONG old_value = thread_info->GetMessageExtraInfoVal;
4105 thread_info->GetMessageExtraInfoVal = lParam;
4106 return old_value;
4110 /***********************************************************************
4111 * GetCurrentInputMessageSource (USER32.@)
4113 BOOL WINAPI GetCurrentInputMessageSource( INPUT_MESSAGE_SOURCE *source )
4115 *source = get_user_thread_info()->msg_source;
4116 return TRUE;
4120 /***********************************************************************
4121 * WaitMessage (USER.112) Suspend thread pending messages
4122 * WaitMessage (USER32.@) Suspend thread pending messages
4124 * WaitMessage() suspends a thread until events appear in the thread's
4125 * queue.
4127 BOOL WINAPI WaitMessage(void)
4129 return (MsgWaitForMultipleObjectsEx( 0, NULL, INFINITE, QS_ALLINPUT, 0 ) != WAIT_FAILED);
4133 /***********************************************************************
4134 * MsgWaitForMultipleObjectsEx (USER32.@)
4136 DWORD WINAPI MsgWaitForMultipleObjectsEx( DWORD count, const HANDLE *pHandles,
4137 DWORD timeout, DWORD mask, DWORD flags )
4139 HANDLE handles[MAXIMUM_WAIT_OBJECTS];
4140 DWORD i;
4142 if (count > MAXIMUM_WAIT_OBJECTS-1)
4144 SetLastError( ERROR_INVALID_PARAMETER );
4145 return WAIT_FAILED;
4148 /* add the queue to the handle list */
4149 for (i = 0; i < count; i++) handles[i] = pHandles[i];
4150 handles[count] = get_server_queue_handle();
4152 return wait_objects( count+1, handles, timeout,
4153 (flags & MWMO_INPUTAVAILABLE) ? mask : 0, mask, flags );
4157 /***********************************************************************
4158 * MsgWaitForMultipleObjects (USER32.@)
4160 DWORD WINAPI MsgWaitForMultipleObjects( DWORD count, const HANDLE *handles,
4161 BOOL wait_all, DWORD timeout, DWORD mask )
4163 return MsgWaitForMultipleObjectsEx( count, handles, timeout, mask,
4164 wait_all ? MWMO_WAITALL : 0 );
4168 /***********************************************************************
4169 * WaitForInputIdle (USER32.@)
4171 DWORD WINAPI WaitForInputIdle( HANDLE hProcess, DWORD dwTimeOut )
4173 DWORD start_time, elapsed, ret;
4174 HANDLE handles[2];
4176 handles[0] = hProcess;
4177 SERVER_START_REQ( get_process_idle_event )
4179 req->handle = wine_server_obj_handle( hProcess );
4180 wine_server_call_err( req );
4181 handles[1] = wine_server_ptr_handle( reply->event );
4183 SERVER_END_REQ;
4184 if (!handles[1]) return WAIT_FAILED; /* no event to wait on */
4186 start_time = GetTickCount();
4187 elapsed = 0;
4189 TRACE("waiting for %p\n", handles[1] );
4192 ret = MsgWaitForMultipleObjects ( 2, handles, FALSE, dwTimeOut - elapsed, QS_SENDMESSAGE );
4193 switch (ret)
4195 case WAIT_OBJECT_0:
4196 return 0;
4197 case WAIT_OBJECT_0+2:
4198 process_sent_messages();
4199 break;
4200 case WAIT_TIMEOUT:
4201 case WAIT_FAILED:
4202 TRACE("timeout or error\n");
4203 return ret;
4204 default:
4205 TRACE("finished\n");
4206 return 0;
4208 if (dwTimeOut != INFINITE)
4210 elapsed = GetTickCount() - start_time;
4211 if (elapsed > dwTimeOut)
4212 break;
4215 while (1);
4217 return WAIT_TIMEOUT;
4221 /***********************************************************************
4222 * RegisterWindowMessageA (USER32.@)
4223 * RegisterWindowMessage (USER.118)
4225 UINT WINAPI RegisterWindowMessageA( LPCSTR str )
4227 UINT ret = GlobalAddAtomA(str);
4228 TRACE("%s, ret=%x\n", str, ret);
4229 return ret;
4233 /***********************************************************************
4234 * RegisterWindowMessageW (USER32.@)
4236 UINT WINAPI RegisterWindowMessageW( LPCWSTR str )
4238 UINT ret = GlobalAddAtomW(str);
4239 TRACE("%s ret=%x\n", debugstr_w(str), ret);
4240 return ret;
4243 typedef struct BroadcastParm
4245 DWORD flags;
4246 LPDWORD recipients;
4247 UINT msg;
4248 WPARAM wp;
4249 LPARAM lp;
4250 BOOL success;
4251 HWINSTA winsta;
4252 } BroadcastParm;
4254 static BOOL CALLBACK bcast_childwindow( HWND hw, LPARAM lp )
4256 BroadcastParm *parm = (BroadcastParm*)lp;
4257 DWORD_PTR retval = 0;
4258 LRESULT lresult;
4260 if (parm->flags & BSF_IGNORECURRENTTASK && WIN_IsCurrentProcess(hw))
4262 TRACE("Not telling myself %p\n", hw);
4263 return TRUE;
4266 /* I don't know 100% for sure if this is what Windows does, but it fits the tests */
4267 if (parm->flags & BSF_QUERY)
4269 TRACE("Telling window %p using SendMessageTimeout\n", hw);
4271 /* Not tested for conflicting flags */
4272 if (parm->flags & BSF_FORCEIFHUNG || parm->flags & BSF_NOHANG)
4273 lresult = SendMessageTimeoutW( hw, parm->msg, parm->wp, parm->lp, SMTO_ABORTIFHUNG, 2000, &retval );
4274 else if (parm->flags & BSF_NOTIMEOUTIFNOTHUNG)
4275 lresult = SendMessageTimeoutW( hw, parm->msg, parm->wp, parm->lp, SMTO_NOTIMEOUTIFNOTHUNG, 2000, &retval );
4276 else
4277 lresult = SendMessageTimeoutW( hw, parm->msg, parm->wp, parm->lp, SMTO_NORMAL, 2000, &retval );
4279 if (!lresult && GetLastError() == ERROR_TIMEOUT)
4281 WARN("Timed out!\n");
4282 if (!(parm->flags & BSF_FORCEIFHUNG))
4283 goto fail;
4285 if (retval == BROADCAST_QUERY_DENY)
4286 goto fail;
4288 return TRUE;
4290 fail:
4291 parm->success = FALSE;
4292 return FALSE;
4294 else if (parm->flags & BSF_POSTMESSAGE)
4296 TRACE("Telling window %p using PostMessage\n", hw);
4297 PostMessageW( hw, parm->msg, parm->wp, parm->lp );
4299 else
4301 TRACE("Telling window %p using SendNotifyMessage\n", hw);
4302 SendNotifyMessageW( hw, parm->msg, parm->wp, parm->lp );
4305 return TRUE;
4308 static BOOL CALLBACK bcast_desktop( LPWSTR desktop, LPARAM lp )
4310 BOOL ret;
4311 HDESK hdesktop;
4312 BroadcastParm *parm = (BroadcastParm*)lp;
4314 TRACE("desktop: %s\n", debugstr_w( desktop ));
4316 hdesktop = open_winstation_desktop( parm->winsta, desktop, 0, FALSE, DESKTOP_ENUMERATE|DESKTOP_WRITEOBJECTS|STANDARD_RIGHTS_WRITE );
4317 if (!hdesktop)
4319 FIXME("Could not open desktop %s\n", debugstr_w(desktop));
4320 return TRUE;
4323 ret = EnumDesktopWindows( hdesktop, bcast_childwindow, lp );
4324 CloseDesktop(hdesktop);
4325 TRACE("-->%d\n", ret);
4326 return parm->success;
4329 static BOOL CALLBACK bcast_winsta( LPWSTR winsta, LPARAM lp )
4331 BOOL ret;
4332 HWINSTA hwinsta = OpenWindowStationW( winsta, FALSE, WINSTA_ENUMDESKTOPS );
4333 TRACE("hwinsta: %p/%s/%08x\n", hwinsta, debugstr_w( winsta ), GetLastError());
4334 if (!hwinsta)
4335 return TRUE;
4336 ((BroadcastParm *)lp)->winsta = hwinsta;
4337 ret = EnumDesktopsW( hwinsta, bcast_desktop, lp );
4338 CloseWindowStation( hwinsta );
4339 TRACE("-->%d\n", ret);
4340 return ret;
4343 /***********************************************************************
4344 * BroadcastSystemMessageA (USER32.@)
4345 * BroadcastSystemMessage (USER32.@)
4347 LONG WINAPI BroadcastSystemMessageA( DWORD flags, LPDWORD recipients, UINT msg, WPARAM wp, LPARAM lp )
4349 return BroadcastSystemMessageExA( flags, recipients, msg, wp, lp, NULL );
4353 /***********************************************************************
4354 * BroadcastSystemMessageW (USER32.@)
4356 LONG WINAPI BroadcastSystemMessageW( DWORD flags, LPDWORD recipients, UINT msg, WPARAM wp, LPARAM lp )
4358 return BroadcastSystemMessageExW( flags, recipients, msg, wp, lp, NULL );
4361 /***********************************************************************
4362 * BroadcastSystemMessageExA (USER32.@)
4364 LONG WINAPI BroadcastSystemMessageExA( DWORD flags, LPDWORD recipients, UINT msg, WPARAM wp, LPARAM lp, PBSMINFO pinfo )
4366 map_wparam_AtoW( msg, &wp, WMCHAR_MAP_NOMAPPING );
4367 return BroadcastSystemMessageExW( flags, recipients, msg, wp, lp, NULL );
4371 /***********************************************************************
4372 * BroadcastSystemMessageExW (USER32.@)
4374 LONG WINAPI BroadcastSystemMessageExW( DWORD flags, LPDWORD recipients, UINT msg, WPARAM wp, LPARAM lp, PBSMINFO pinfo )
4376 BroadcastParm parm;
4377 DWORD recips = BSM_ALLCOMPONENTS;
4378 BOOL ret = TRUE;
4379 static const DWORD all_flags = ( BSF_QUERY | BSF_IGNORECURRENTTASK | BSF_FLUSHDISK | BSF_NOHANG
4380 | BSF_POSTMESSAGE | BSF_FORCEIFHUNG | BSF_NOTIMEOUTIFNOTHUNG
4381 | BSF_ALLOWSFW | BSF_SENDNOTIFYMESSAGE | BSF_RETURNHDESK | BSF_LUID );
4383 TRACE("Flags: %08x, recipients: %p(0x%x), msg: %04x, wparam: %08lx, lparam: %08lx\n", flags, recipients,
4384 (recipients ? *recipients : recips), msg, wp, lp);
4386 if (flags & ~all_flags)
4388 SetLastError(ERROR_INVALID_PARAMETER);
4389 return 0;
4392 if (!recipients)
4393 recipients = &recips;
4395 if ( pinfo && flags & BSF_QUERY )
4396 FIXME("Not returning PBSMINFO information yet\n");
4398 parm.flags = flags;
4399 parm.recipients = recipients;
4400 parm.msg = msg;
4401 parm.wp = wp;
4402 parm.lp = lp;
4403 parm.success = TRUE;
4405 if (*recipients & BSM_ALLDESKTOPS || *recipients == BSM_ALLCOMPONENTS)
4406 ret = EnumWindowStationsW(bcast_winsta, (LONG_PTR)&parm);
4407 else if (*recipients & BSM_APPLICATIONS)
4409 EnumWindows(bcast_childwindow, (LONG_PTR)&parm);
4410 ret = parm.success;
4412 else
4413 FIXME("Recipients %08x not supported!\n", *recipients);
4415 return ret;
4418 /***********************************************************************
4419 * SetMessageQueue (USER32.@)
4421 BOOL WINAPI SetMessageQueue( INT size )
4423 /* now obsolete the message queue will be expanded dynamically as necessary */
4424 return TRUE;
4428 /***********************************************************************
4429 * MessageBeep (USER32.@)
4431 BOOL WINAPI MessageBeep( UINT i )
4433 BOOL active = TRUE;
4434 SystemParametersInfoA( SPI_GETBEEP, 0, &active, FALSE );
4435 if (active) USER_Driver->pBeep();
4436 return TRUE;
4440 /***********************************************************************
4441 * SetCoalescableTimer (USER32.@)
4443 UINT_PTR WINAPI SetCoalescableTimer( HWND hwnd, UINT_PTR id, UINT timeout, TIMERPROC proc, ULONG tolerance )
4445 UINT_PTR ret;
4446 WNDPROC winproc = 0;
4448 if (proc) winproc = WINPROC_AllocProc( (WNDPROC)proc, FALSE );
4450 timeout = min( max( USER_TIMER_MINIMUM, timeout ), USER_TIMER_MAXIMUM );
4452 SERVER_START_REQ( set_win_timer )
4454 req->win = wine_server_user_handle( hwnd );
4455 req->msg = WM_TIMER;
4456 req->id = id;
4457 req->rate = timeout;
4458 req->lparam = (ULONG_PTR)winproc;
4459 if (!wine_server_call_err( req ))
4461 ret = reply->id;
4462 if (!ret) ret = TRUE;
4464 else ret = 0;
4466 SERVER_END_REQ;
4468 TRACE("Added %p %lx %p timeout %d\n", hwnd, id, winproc, timeout );
4469 return ret;
4473 /******************************************************************
4474 * SetTimer (USER32.@)
4476 UINT_PTR WINAPI SetTimer( HWND hwnd, UINT_PTR id, UINT timeout, TIMERPROC proc )
4478 return SetCoalescableTimer( hwnd, id, timeout, proc, TIMERV_DEFAULT_COALESCING );
4482 /***********************************************************************
4483 * SetSystemTimer (USER32.@)
4485 UINT_PTR WINAPI SetSystemTimer( HWND hwnd, UINT_PTR id, UINT timeout, TIMERPROC proc )
4487 UINT_PTR ret;
4488 WNDPROC winproc = 0;
4490 if (proc) winproc = WINPROC_AllocProc( (WNDPROC)proc, FALSE );
4492 timeout = min( max( USER_TIMER_MINIMUM, timeout ), USER_TIMER_MAXIMUM );
4494 SERVER_START_REQ( set_win_timer )
4496 req->win = wine_server_user_handle( hwnd );
4497 req->msg = WM_SYSTIMER;
4498 req->id = id;
4499 req->rate = timeout;
4500 req->lparam = (ULONG_PTR)winproc;
4501 if (!wine_server_call_err( req ))
4503 ret = reply->id;
4504 if (!ret) ret = TRUE;
4506 else ret = 0;
4508 SERVER_END_REQ;
4510 TRACE("Added %p %lx %p timeout %d\n", hwnd, id, winproc, timeout );
4511 return ret;
4515 /***********************************************************************
4516 * KillTimer (USER32.@)
4518 BOOL WINAPI KillTimer( HWND hwnd, UINT_PTR id )
4520 BOOL ret;
4522 SERVER_START_REQ( kill_win_timer )
4524 req->win = wine_server_user_handle( hwnd );
4525 req->msg = WM_TIMER;
4526 req->id = id;
4527 ret = !wine_server_call_err( req );
4529 SERVER_END_REQ;
4530 return ret;
4534 /***********************************************************************
4535 * KillSystemTimer (USER32.@)
4537 BOOL WINAPI KillSystemTimer( HWND hwnd, UINT_PTR id )
4539 BOOL ret;
4541 SERVER_START_REQ( kill_win_timer )
4543 req->win = wine_server_user_handle( hwnd );
4544 req->msg = WM_SYSTIMER;
4545 req->id = id;
4546 ret = !wine_server_call_err( req );
4548 SERVER_END_REQ;
4549 return ret;
4553 /**********************************************************************
4554 * IsGUIThread (USER32.@)
4556 BOOL WINAPI IsGUIThread( BOOL convert )
4558 FIXME( "%u: stub\n", convert );
4559 return TRUE;
4563 /**********************************************************************
4564 * GetGUIThreadInfo (USER32.@)
4566 BOOL WINAPI GetGUIThreadInfo( DWORD id, GUITHREADINFO *info )
4568 BOOL ret;
4570 if (info->cbSize != sizeof(*info))
4572 SetLastError( ERROR_INVALID_PARAMETER );
4573 return FALSE;
4576 SERVER_START_REQ( get_thread_input )
4578 req->tid = id;
4579 if ((ret = !wine_server_call_err( req )))
4581 info->flags = 0;
4582 info->hwndActive = wine_server_ptr_handle( reply->active );
4583 info->hwndFocus = wine_server_ptr_handle( reply->focus );
4584 info->hwndCapture = wine_server_ptr_handle( reply->capture );
4585 info->hwndMenuOwner = wine_server_ptr_handle( reply->menu_owner );
4586 info->hwndMoveSize = wine_server_ptr_handle( reply->move_size );
4587 info->hwndCaret = wine_server_ptr_handle( reply->caret );
4588 info->rcCaret.left = reply->rect.left;
4589 info->rcCaret.top = reply->rect.top;
4590 info->rcCaret.right = reply->rect.right;
4591 info->rcCaret.bottom = reply->rect.bottom;
4592 if (reply->menu_owner) info->flags |= GUI_INMENUMODE;
4593 if (reply->move_size) info->flags |= GUI_INMOVESIZE;
4594 if (reply->caret) info->flags |= GUI_CARETBLINKING;
4597 SERVER_END_REQ;
4598 return ret;
4602 /******************************************************************
4603 * IsHungAppWindow (USER32.@)
4606 BOOL WINAPI IsHungAppWindow( HWND hWnd )
4608 BOOL ret;
4610 SERVER_START_REQ( is_window_hung )
4612 req->win = wine_server_user_handle( hWnd );
4613 ret = !wine_server_call_err( req ) && reply->is_hung;
4615 SERVER_END_REQ;
4616 return ret;
4619 /******************************************************************
4620 * ChangeWindowMessageFilter (USER32.@)
4622 BOOL WINAPI ChangeWindowMessageFilter( UINT message, DWORD flag )
4624 FIXME( "%x %08x\n", message, flag );
4625 return TRUE;
4628 /******************************************************************
4629 * ChangeWindowMessageFilterEx (USER32.@)
4631 BOOL WINAPI ChangeWindowMessageFilterEx( HWND hwnd, UINT message, DWORD action, CHANGEFILTERSTRUCT *changefilter )
4633 FIXME( "%p %x %d %p\n", hwnd, message, action, changefilter );
4634 return TRUE;