d3dx9: Implement GetMaxNum* functions.
[wine.git] / dlls / user32 / message.c
blobba3f4c6d86d8bbc7cbcbbd1d0adc0799349d518d
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 "config.h"
23 #include "wine/port.h"
25 #include <assert.h>
26 #include <stdarg.h>
28 #define NONAMELESSUNION
29 #define NONAMELESSSTRUCT
30 #include "ntstatus.h"
31 #define WIN32_NO_STATUS
32 #include "windef.h"
33 #include "winbase.h"
34 #include "wingdi.h"
35 #include "winuser.h"
36 #include "winerror.h"
37 #include "winnls.h"
38 #include "dbt.h"
39 #include "dde.h"
40 #include "imm.h"
41 #include "ddk/imm.h"
42 #include "wine/unicode.h"
43 #include "wine/server.h"
44 #include "user_private.h"
45 #include "win.h"
46 #include "controls.h"
47 #include "wine/debug.h"
48 #include "wine/exception.h"
50 WINE_DEFAULT_DEBUG_CHANNEL(msg);
51 WINE_DECLARE_DEBUG_CHANNEL(relay);
52 WINE_DECLARE_DEBUG_CHANNEL(key);
54 #define WM_NCMOUSEFIRST WM_NCMOUSEMOVE
55 #define WM_NCMOUSELAST (WM_NCMOUSEFIRST+(WM_MOUSELAST-WM_MOUSEFIRST))
57 #define MAX_PACK_COUNT 4
59 /* the various structures that can be sent in messages, in platform-independent layout */
60 struct packed_CREATESTRUCTW
62 ULONGLONG lpCreateParams;
63 ULONGLONG hInstance;
64 user_handle_t hMenu;
65 DWORD __pad1;
66 user_handle_t hwndParent;
67 DWORD __pad2;
68 INT cy;
69 INT cx;
70 INT y;
71 INT x;
72 LONG style;
73 ULONGLONG lpszName;
74 ULONGLONG lpszClass;
75 DWORD dwExStyle;
76 DWORD __pad3;
79 struct packed_DRAWITEMSTRUCT
81 UINT CtlType;
82 UINT CtlID;
83 UINT itemID;
84 UINT itemAction;
85 UINT itemState;
86 user_handle_t hwndItem;
87 DWORD __pad1;
88 user_handle_t hDC;
89 DWORD __pad2;
90 RECT rcItem;
91 ULONGLONG itemData;
94 struct packed_MEASUREITEMSTRUCT
96 UINT CtlType;
97 UINT CtlID;
98 UINT itemID;
99 UINT itemWidth;
100 UINT itemHeight;
101 ULONGLONG itemData;
104 struct packed_DELETEITEMSTRUCT
106 UINT CtlType;
107 UINT CtlID;
108 UINT itemID;
109 user_handle_t hwndItem;
110 DWORD __pad;
111 ULONGLONG itemData;
114 struct packed_COMPAREITEMSTRUCT
116 UINT CtlType;
117 UINT CtlID;
118 user_handle_t hwndItem;
119 DWORD __pad1;
120 UINT itemID1;
121 ULONGLONG itemData1;
122 UINT itemID2;
123 ULONGLONG itemData2;
124 DWORD dwLocaleId;
125 DWORD __pad2;
128 struct packed_WINDOWPOS
130 user_handle_t hwnd;
131 DWORD __pad1;
132 user_handle_t hwndInsertAfter;
133 DWORD __pad2;
134 INT x;
135 INT y;
136 INT cx;
137 INT cy;
138 UINT flags;
139 DWORD __pad3;
142 struct packed_COPYDATASTRUCT
144 ULONGLONG dwData;
145 DWORD cbData;
146 ULONGLONG lpData;
149 struct packed_HELPINFO
151 UINT cbSize;
152 INT iContextType;
153 INT iCtrlId;
154 user_handle_t hItemHandle;
155 DWORD __pad;
156 ULONGLONG dwContextId;
157 POINT MousePos;
160 struct packed_NCCALCSIZE_PARAMS
162 RECT rgrc[3];
163 ULONGLONG __pad1;
164 user_handle_t hwnd;
165 DWORD __pad2;
166 user_handle_t hwndInsertAfter;
167 DWORD __pad3;
168 INT x;
169 INT y;
170 INT cx;
171 INT cy;
172 UINT flags;
173 DWORD __pad4;
176 struct packed_MSG
178 user_handle_t hwnd;
179 DWORD __pad1;
180 UINT message;
181 ULONGLONG wParam;
182 ULONGLONG lParam;
183 DWORD time;
184 POINT pt;
185 DWORD __pad2;
188 struct packed_MDINEXTMENU
190 user_handle_t hmenuIn;
191 DWORD __pad1;
192 user_handle_t hmenuNext;
193 DWORD __pad2;
194 user_handle_t hwndNext;
195 DWORD __pad3;
198 struct packed_MDICREATESTRUCTW
200 ULONGLONG szClass;
201 ULONGLONG szTitle;
202 ULONGLONG hOwner;
203 INT x;
204 INT y;
205 INT cx;
206 INT cy;
207 DWORD style;
208 ULONGLONG lParam;
211 struct packed_hook_extra_info
213 user_handle_t handle;
214 DWORD __pad;
215 ULONGLONG lparam;
218 /* the structures are unpacked on top of the packed ones, so make sure they fit */
219 C_ASSERT( sizeof(struct packed_CREATESTRUCTW) >= sizeof(CREATESTRUCTW) );
220 C_ASSERT( sizeof(struct packed_DRAWITEMSTRUCT) >= sizeof(DRAWITEMSTRUCT) );
221 C_ASSERT( sizeof(struct packed_MEASUREITEMSTRUCT) >= sizeof(MEASUREITEMSTRUCT) );
222 C_ASSERT( sizeof(struct packed_DELETEITEMSTRUCT) >= sizeof(DELETEITEMSTRUCT) );
223 C_ASSERT( sizeof(struct packed_COMPAREITEMSTRUCT) >= sizeof(COMPAREITEMSTRUCT) );
224 C_ASSERT( sizeof(struct packed_WINDOWPOS) >= sizeof(WINDOWPOS) );
225 C_ASSERT( sizeof(struct packed_COPYDATASTRUCT) >= sizeof(COPYDATASTRUCT) );
226 C_ASSERT( sizeof(struct packed_HELPINFO) >= sizeof(HELPINFO) );
227 C_ASSERT( sizeof(struct packed_NCCALCSIZE_PARAMS) >= sizeof(NCCALCSIZE_PARAMS) + sizeof(WINDOWPOS) );
228 C_ASSERT( sizeof(struct packed_MSG) >= sizeof(MSG) );
229 C_ASSERT( sizeof(struct packed_MDINEXTMENU) >= sizeof(MDINEXTMENU) );
230 C_ASSERT( sizeof(struct packed_MDICREATESTRUCTW) >= sizeof(MDICREATESTRUCTW) );
231 C_ASSERT( sizeof(struct packed_hook_extra_info) >= sizeof(struct hook_extra_info) );
233 union packed_structs
235 struct packed_CREATESTRUCTW cs;
236 struct packed_DRAWITEMSTRUCT dis;
237 struct packed_MEASUREITEMSTRUCT mis;
238 struct packed_DELETEITEMSTRUCT dls;
239 struct packed_COMPAREITEMSTRUCT cis;
240 struct packed_WINDOWPOS wp;
241 struct packed_COPYDATASTRUCT cds;
242 struct packed_HELPINFO hi;
243 struct packed_NCCALCSIZE_PARAMS ncp;
244 struct packed_MSG msg;
245 struct packed_MDINEXTMENU mnm;
246 struct packed_MDICREATESTRUCTW mcs;
247 struct packed_hook_extra_info hook;
250 /* description of the data fields that need to be packed along with a sent message */
251 struct packed_message
253 union packed_structs ps;
254 int count;
255 const void *data[MAX_PACK_COUNT];
256 size_t size[MAX_PACK_COUNT];
259 /* info about the message currently being received by the current thread */
260 struct received_message_info
262 enum message_type type;
263 MSG msg;
264 UINT flags; /* InSendMessageEx return flags */
267 /* structure to group all parameters for sent messages of the various kinds */
268 struct send_message_info
270 enum message_type type;
271 DWORD dest_tid;
272 HWND hwnd;
273 UINT msg;
274 WPARAM wparam;
275 LPARAM lparam;
276 UINT flags; /* flags for SendMessageTimeout */
277 UINT timeout; /* timeout for SendMessageTimeout */
278 SENDASYNCPROC callback; /* callback function for SendMessageCallback */
279 ULONG_PTR data; /* callback data */
280 enum wm_char_mapping wm_char;
284 /* Message class descriptor */
285 static const WCHAR messageW[] = {'M','e','s','s','a','g','e',0};
287 const struct builtin_class_descr MESSAGE_builtin_class =
289 messageW, /* name */
290 0, /* style */
291 WINPROC_MESSAGE, /* proc */
292 0, /* extra */
293 0, /* cursor */
294 0 /* brush */
299 /* flag for messages that contain pointers */
300 /* 32 messages per entry, messages 0..31 map to bits 0..31 */
302 #define SET(msg) (1 << ((msg) & 31))
304 static const unsigned int message_pointer_flags[] =
306 /* 0x00 - 0x1f */
307 SET(WM_CREATE) | SET(WM_SETTEXT) | SET(WM_GETTEXT) |
308 SET(WM_WININICHANGE) | SET(WM_DEVMODECHANGE),
309 /* 0x20 - 0x3f */
310 SET(WM_GETMINMAXINFO) | SET(WM_DRAWITEM) | SET(WM_MEASUREITEM) | SET(WM_DELETEITEM) |
311 SET(WM_COMPAREITEM),
312 /* 0x40 - 0x5f */
313 SET(WM_WINDOWPOSCHANGING) | SET(WM_WINDOWPOSCHANGED) | SET(WM_COPYDATA) |
314 SET(WM_NOTIFY) | SET(WM_HELP),
315 /* 0x60 - 0x7f */
316 SET(WM_STYLECHANGING) | SET(WM_STYLECHANGED),
317 /* 0x80 - 0x9f */
318 SET(WM_NCCREATE) | SET(WM_NCCALCSIZE) | SET(WM_GETDLGCODE),
319 /* 0xa0 - 0xbf */
320 SET(EM_GETSEL) | SET(EM_GETRECT) | SET(EM_SETRECT) | SET(EM_SETRECTNP),
321 /* 0xc0 - 0xdf */
322 SET(EM_REPLACESEL) | SET(EM_GETLINE) | SET(EM_SETTABSTOPS),
323 /* 0xe0 - 0xff */
324 SET(SBM_GETRANGE) | SET(SBM_SETSCROLLINFO) | SET(SBM_GETSCROLLINFO) | SET(SBM_GETSCROLLBARINFO),
325 /* 0x100 - 0x11f */
327 /* 0x120 - 0x13f */
329 /* 0x140 - 0x15f */
330 SET(CB_GETEDITSEL) | SET(CB_ADDSTRING) | SET(CB_DIR) | SET(CB_GETLBTEXT) |
331 SET(CB_INSERTSTRING) | SET(CB_FINDSTRING) | SET(CB_SELECTSTRING) |
332 SET(CB_GETDROPPEDCONTROLRECT) | SET(CB_FINDSTRINGEXACT),
333 /* 0x160 - 0x17f */
335 /* 0x180 - 0x19f */
336 SET(LB_ADDSTRING) | SET(LB_INSERTSTRING) | SET(LB_GETTEXT) | SET(LB_SELECTSTRING) |
337 SET(LB_DIR) | SET(LB_FINDSTRING) |
338 SET(LB_GETSELITEMS) | SET(LB_SETTABSTOPS) | SET(LB_ADDFILE) | SET(LB_GETITEMRECT),
339 /* 0x1a0 - 0x1bf */
340 SET(LB_FINDSTRINGEXACT),
341 /* 0x1c0 - 0x1df */
343 /* 0x1e0 - 0x1ff */
345 /* 0x200 - 0x21f */
346 SET(WM_NEXTMENU) | SET(WM_SIZING) | SET(WM_MOVING) | SET(WM_DEVICECHANGE),
347 /* 0x220 - 0x23f */
348 SET(WM_MDICREATE) | SET(WM_MDIGETACTIVE) | SET(WM_DROPOBJECT) |
349 SET(WM_QUERYDROPOBJECT) | SET(WM_DRAGLOOP) | SET(WM_DRAGSELECT) | SET(WM_DRAGMOVE),
350 /* 0x240 - 0x25f */
352 /* 0x260 - 0x27f */
354 /* 0x280 - 0x29f */
356 /* 0x2a0 - 0x2bf */
358 /* 0x2c0 - 0x2df */
360 /* 0x2e0 - 0x2ff */
362 /* 0x300 - 0x31f */
363 SET(WM_ASKCBFORMATNAME)
366 /* flags for messages that contain Unicode strings */
367 static const unsigned int message_unicode_flags[] =
369 /* 0x00 - 0x1f */
370 SET(WM_CREATE) | SET(WM_SETTEXT) | SET(WM_GETTEXT) | SET(WM_GETTEXTLENGTH) |
371 SET(WM_WININICHANGE) | SET(WM_DEVMODECHANGE),
372 /* 0x20 - 0x3f */
373 SET(WM_CHARTOITEM),
374 /* 0x40 - 0x5f */
376 /* 0x60 - 0x7f */
378 /* 0x80 - 0x9f */
379 SET(WM_NCCREATE),
380 /* 0xa0 - 0xbf */
382 /* 0xc0 - 0xdf */
383 SET(EM_REPLACESEL) | SET(EM_GETLINE) | SET(EM_SETPASSWORDCHAR),
384 /* 0xe0 - 0xff */
386 /* 0x100 - 0x11f */
387 SET(WM_CHAR) | SET(WM_DEADCHAR) | SET(WM_SYSCHAR) | SET(WM_SYSDEADCHAR),
388 /* 0x120 - 0x13f */
389 SET(WM_MENUCHAR),
390 /* 0x140 - 0x15f */
391 SET(CB_ADDSTRING) | SET(CB_DIR) | SET(CB_GETLBTEXT) | SET(CB_GETLBTEXTLEN) |
392 SET(CB_INSERTSTRING) | SET(CB_FINDSTRING) | SET(CB_SELECTSTRING) | SET(CB_FINDSTRINGEXACT),
393 /* 0x160 - 0x17f */
395 /* 0x180 - 0x19f */
396 SET(LB_ADDSTRING) | SET(LB_INSERTSTRING) | SET(LB_GETTEXT) | SET(LB_GETTEXTLEN) |
397 SET(LB_SELECTSTRING) | SET(LB_DIR) | SET(LB_FINDSTRING) | SET(LB_ADDFILE),
398 /* 0x1a0 - 0x1bf */
399 SET(LB_FINDSTRINGEXACT),
400 /* 0x1c0 - 0x1df */
402 /* 0x1e0 - 0x1ff */
404 /* 0x200 - 0x21f */
406 /* 0x220 - 0x23f */
407 SET(WM_MDICREATE),
408 /* 0x240 - 0x25f */
410 /* 0x260 - 0x27f */
412 /* 0x280 - 0x29f */
413 SET(WM_IME_CHAR),
414 /* 0x2a0 - 0x2bf */
416 /* 0x2c0 - 0x2df */
418 /* 0x2e0 - 0x2ff */
420 /* 0x300 - 0x31f */
421 SET(WM_PAINTCLIPBOARD) | SET(WM_SIZECLIPBOARD) | SET(WM_ASKCBFORMATNAME)
424 /* check whether a given message type includes pointers */
425 static inline BOOL is_pointer_message( UINT message, WPARAM wparam )
427 if (message >= 8*sizeof(message_pointer_flags)) return FALSE;
428 if (message == WM_DEVICECHANGE && !(wparam & 0x8000)) return FALSE;
429 return (message_pointer_flags[message / 32] & SET(message)) != 0;
432 /* check whether a given message type contains Unicode (or ASCII) chars */
433 static inline BOOL is_unicode_message( UINT message )
435 if (message >= 8*sizeof(message_unicode_flags)) return FALSE;
436 return (message_unicode_flags[message / 32] & SET(message)) != 0;
439 #undef SET
441 /* add a data field to a packed message */
442 static inline void push_data( struct packed_message *data, const void *ptr, size_t size )
444 data->data[data->count] = ptr;
445 data->size[data->count] = size;
446 data->count++;
449 /* add a string to a packed message */
450 static inline void push_string( struct packed_message *data, LPCWSTR str )
452 push_data( data, str, (strlenW(str) + 1) * sizeof(WCHAR) );
455 /* make sure that the buffer contains a valid null-terminated Unicode string */
456 static inline BOOL check_string( LPCWSTR str, size_t size )
458 for (size /= sizeof(WCHAR); size; size--, str++)
459 if (!*str) return TRUE;
460 return FALSE;
463 /* pack a pointer into a 32/64 portable format */
464 static inline ULONGLONG pack_ptr( const void *ptr )
466 return (ULONG_PTR)ptr;
469 /* unpack a potentially 64-bit pointer, returning 0 when truncated */
470 static inline void *unpack_ptr( ULONGLONG ptr64 )
472 if ((ULONG_PTR)ptr64 != ptr64) return 0;
473 return (void *)(ULONG_PTR)ptr64;
476 /* make sure that there is space for 'size' bytes in buffer, growing it if needed */
477 static inline void *get_buffer_space( void **buffer, size_t size )
479 void *ret;
481 if (*buffer)
483 if (!(ret = HeapReAlloc( GetProcessHeap(), 0, *buffer, size )))
484 HeapFree( GetProcessHeap(), 0, *buffer );
486 else ret = HeapAlloc( GetProcessHeap(), 0, size );
488 *buffer = ret;
489 return ret;
492 /* check whether a combobox expects strings or ids in CB_ADDSTRING/CB_INSERTSTRING */
493 static inline BOOL combobox_has_strings( HWND hwnd )
495 DWORD style = GetWindowLongA( hwnd, GWL_STYLE );
496 return (!(style & (CBS_OWNERDRAWFIXED | CBS_OWNERDRAWVARIABLE)) || (style & CBS_HASSTRINGS));
499 /* check whether a listbox expects strings or ids in LB_ADDSTRING/LB_INSERTSTRING */
500 static inline BOOL listbox_has_strings( HWND hwnd )
502 DWORD style = GetWindowLongA( hwnd, GWL_STYLE );
503 return (!(style & (LBS_OWNERDRAWFIXED | LBS_OWNERDRAWVARIABLE)) || (style & LBS_HASSTRINGS));
506 /* check whether message is in the range of keyboard messages */
507 static inline BOOL is_keyboard_message( UINT message )
509 return (message >= WM_KEYFIRST && message <= WM_KEYLAST);
512 /* check whether message is in the range of mouse messages */
513 static inline BOOL is_mouse_message( UINT message )
515 return ((message >= WM_NCMOUSEFIRST && message <= WM_NCMOUSELAST) ||
516 (message >= WM_MOUSEFIRST && message <= WM_MOUSELAST));
519 /* check whether message matches the specified hwnd filter */
520 static inline BOOL check_hwnd_filter( const MSG *msg, HWND hwnd_filter )
522 if (!hwnd_filter || hwnd_filter == GetDesktopWindow()) return TRUE;
523 return (msg->hwnd == hwnd_filter || IsChild( hwnd_filter, msg->hwnd ));
526 /* check for pending WM_CHAR message with DBCS trailing byte */
527 static inline BOOL get_pending_wmchar( MSG *msg, UINT first, UINT last, BOOL remove )
529 struct wm_char_mapping_data *data = get_user_thread_info()->wmchar_data;
531 if (!data || !data->get_msg.message) return FALSE;
532 if ((first || last) && (first > WM_CHAR || last < WM_CHAR)) return FALSE;
533 if (!msg) return FALSE;
534 *msg = data->get_msg;
535 if (remove) data->get_msg.message = 0;
536 return TRUE;
540 /***********************************************************************
541 * MessageWndProc
543 * Window procedure for "Message" windows (HWND_MESSAGE parent).
545 LRESULT WINAPI MessageWndProc( HWND hwnd, UINT message, WPARAM wParam, LPARAM lParam )
547 if (message == WM_NCCREATE) return TRUE;
548 return 0; /* all other messages are ignored */
552 /***********************************************************************
553 * broadcast_message_callback
555 * Helper callback for broadcasting messages.
557 static BOOL CALLBACK broadcast_message_callback( HWND hwnd, LPARAM lparam )
559 struct send_message_info *info = (struct send_message_info *)lparam;
560 if (!(GetWindowLongW( hwnd, GWL_STYLE ) & (WS_POPUP|WS_CAPTION))) return TRUE;
561 switch(info->type)
563 case MSG_UNICODE:
564 SendMessageTimeoutW( hwnd, info->msg, info->wparam, info->lparam,
565 info->flags, info->timeout, NULL );
566 break;
567 case MSG_ASCII:
568 SendMessageTimeoutA( hwnd, info->msg, info->wparam, info->lparam,
569 info->flags, info->timeout, NULL );
570 break;
571 case MSG_NOTIFY:
572 SendNotifyMessageW( hwnd, info->msg, info->wparam, info->lparam );
573 break;
574 case MSG_CALLBACK:
575 SendMessageCallbackW( hwnd, info->msg, info->wparam, info->lparam,
576 info->callback, info->data );
577 break;
578 case MSG_POSTED:
579 PostMessageW( hwnd, info->msg, info->wparam, info->lparam );
580 break;
581 default:
582 ERR( "bad type %d\n", info->type );
583 break;
585 return TRUE;
588 DWORD get_input_codepage( void )
590 DWORD cp;
591 int ret;
592 HKL hkl = GetKeyboardLayout( 0 );
594 ret = GetLocaleInfoW( LOWORD(hkl), LOCALE_IDEFAULTANSICODEPAGE | LOCALE_RETURN_NUMBER,
595 (WCHAR *)&cp, sizeof(cp) / sizeof(WCHAR) );
596 if (!ret) cp = CP_ACP;
597 return cp;
600 /***********************************************************************
601 * map_wparam_AtoW
603 * Convert the wparam of an ASCII message to Unicode.
605 BOOL map_wparam_AtoW( UINT message, WPARAM *wparam, enum wm_char_mapping mapping )
607 char ch[2];
608 WCHAR wch[2];
609 DWORD cp = get_input_codepage();
611 wch[0] = wch[1] = 0;
612 switch(message)
614 case WM_CHAR:
615 /* WM_CHAR is magic: a DBCS char can be sent/posted as two consecutive WM_CHAR
616 * messages, in which case the first char is stored, and the conversion
617 * to Unicode only takes place once the second char is sent/posted.
619 if (mapping != WMCHAR_MAP_NOMAPPING)
621 struct wm_char_mapping_data *data = get_user_thread_info()->wmchar_data;
622 BYTE low = LOBYTE(*wparam);
624 if (HIBYTE(*wparam))
626 ch[0] = low;
627 ch[1] = HIBYTE(*wparam);
628 MultiByteToWideChar( cp, 0, ch, 2, wch, 2 );
629 TRACE( "map %02x,%02x -> %04x mapping %u\n", (BYTE)ch[0], (BYTE)ch[1], wch[0], mapping );
630 if (data) data->lead_byte[mapping] = 0;
632 else if (data && data->lead_byte[mapping])
634 ch[0] = data->lead_byte[mapping];
635 ch[1] = low;
636 MultiByteToWideChar( cp, 0, ch, 2, wch, 2 );
637 TRACE( "map stored %02x,%02x -> %04x mapping %u\n", (BYTE)ch[0], (BYTE)ch[1], wch[0], mapping );
638 data->lead_byte[mapping] = 0;
640 else if (!IsDBCSLeadByte( low ))
642 ch[0] = low;
643 MultiByteToWideChar( cp, 0, ch, 1, wch, 2 );
644 TRACE( "map %02x -> %04x\n", (BYTE)ch[0], wch[0] );
645 if (data) data->lead_byte[mapping] = 0;
647 else /* store it and wait for trail byte */
649 if (!data)
651 if (!(data = HeapAlloc( GetProcessHeap(), HEAP_ZERO_MEMORY, sizeof(*data) )))
652 return FALSE;
653 get_user_thread_info()->wmchar_data = data;
655 TRACE( "storing lead byte %02x mapping %u\n", low, mapping );
656 data->lead_byte[mapping] = low;
657 return FALSE;
659 *wparam = MAKEWPARAM(wch[0], wch[1]);
660 break;
662 /* else fall through */
663 case WM_CHARTOITEM:
664 case EM_SETPASSWORDCHAR:
665 case WM_DEADCHAR:
666 case WM_SYSCHAR:
667 case WM_SYSDEADCHAR:
668 case WM_MENUCHAR:
669 ch[0] = LOBYTE(*wparam);
670 ch[1] = HIBYTE(*wparam);
671 MultiByteToWideChar( cp, 0, ch, 2, wch, 2 );
672 *wparam = MAKEWPARAM(wch[0], wch[1]);
673 break;
674 case WM_IME_CHAR:
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 = get_input_codepage();
698 switch(msg->message)
700 case WM_CHAR:
701 if (!HIWORD(msg->wParam))
703 wch[0] = LOWORD(msg->wParam);
704 ch[0] = ch[1] = 0;
705 len = WideCharToMultiByte( cp, 0, wch, 1, (LPSTR)ch, 2, NULL, NULL );
706 if (len == 2) /* DBCS char */
708 struct wm_char_mapping_data *data = get_user_thread_info()->wmchar_data;
709 if (!data)
711 if (!(data = HeapAlloc( GetProcessHeap(), HEAP_ZERO_MEMORY, sizeof(*data) ))) return;
712 get_user_thread_info()->wmchar_data = data;
714 if (remove)
716 data->get_msg = *msg;
717 data->get_msg.wParam = ch[1];
719 msg->wParam = ch[0];
720 return;
723 /* else fall through */
724 case WM_CHARTOITEM:
725 case EM_SETPASSWORDCHAR:
726 case WM_DEADCHAR:
727 case WM_SYSCHAR:
728 case WM_SYSDEADCHAR:
729 case WM_MENUCHAR:
730 wch[0] = LOWORD(msg->wParam);
731 wch[1] = HIWORD(msg->wParam);
732 ch[0] = ch[1] = 0;
733 WideCharToMultiByte( cp, 0, wch, 2, (LPSTR)ch, 4, NULL, NULL );
734 msg->wParam = MAKEWPARAM( ch[0] | (ch[1] << 8), 0 );
735 break;
736 case WM_IME_CHAR:
737 wch[0] = LOWORD(msg->wParam);
738 ch[0] = ch[1] = 0;
739 len = WideCharToMultiByte( cp, 0, wch, 1, (LPSTR)ch, 2, NULL, NULL );
740 if (len == 2)
741 msg->wParam = MAKEWPARAM( (ch[0] << 8) | ch[1], HIWORD(msg->wParam) );
742 else
743 msg->wParam = MAKEWPARAM( ch[0], HIWORD(msg->wParam) );
744 break;
749 /***********************************************************************
750 * pack_message
752 * Pack a message for sending to another process.
753 * Return the size of the data we expect in the message reply.
754 * Set data->count to -1 if there is an error.
756 static size_t pack_message( HWND hwnd, UINT message, WPARAM wparam, LPARAM lparam,
757 struct packed_message *data )
759 data->count = 0;
760 switch(message)
762 case WM_NCCREATE:
763 case WM_CREATE:
765 CREATESTRUCTW *cs = (CREATESTRUCTW *)lparam;
766 data->ps.cs.lpCreateParams = pack_ptr( cs->lpCreateParams );
767 data->ps.cs.hInstance = pack_ptr( cs->hInstance );
768 data->ps.cs.hMenu = wine_server_user_handle( cs->hMenu );
769 data->ps.cs.hwndParent = wine_server_user_handle( cs->hwndParent );
770 data->ps.cs.cy = cs->cy;
771 data->ps.cs.cx = cs->cx;
772 data->ps.cs.y = cs->y;
773 data->ps.cs.x = cs->x;
774 data->ps.cs.style = cs->style;
775 data->ps.cs.dwExStyle = cs->dwExStyle;
776 data->ps.cs.lpszName = pack_ptr( cs->lpszName );
777 data->ps.cs.lpszClass = pack_ptr( cs->lpszClass );
778 push_data( data, &data->ps.cs, sizeof(data->ps.cs) );
779 if (!IS_INTRESOURCE(cs->lpszName)) push_string( data, cs->lpszName );
780 if (!IS_INTRESOURCE(cs->lpszClass)) push_string( data, cs->lpszClass );
781 return sizeof(data->ps.cs);
783 case WM_GETTEXT:
784 case WM_ASKCBFORMATNAME:
785 return wparam * sizeof(WCHAR);
786 case WM_WININICHANGE:
787 if (lparam) push_string(data, (LPWSTR)lparam );
788 return 0;
789 case WM_SETTEXT:
790 case WM_DEVMODECHANGE:
791 case CB_DIR:
792 case LB_DIR:
793 case LB_ADDFILE:
794 case EM_REPLACESEL:
795 push_string( data, (LPWSTR)lparam );
796 return 0;
797 case WM_GETMINMAXINFO:
798 push_data( data, (MINMAXINFO *)lparam, sizeof(MINMAXINFO) );
799 return sizeof(MINMAXINFO);
800 case WM_DRAWITEM:
802 DRAWITEMSTRUCT *dis = (DRAWITEMSTRUCT *)lparam;
803 data->ps.dis.CtlType = dis->CtlType;
804 data->ps.dis.CtlID = dis->CtlID;
805 data->ps.dis.itemID = dis->itemID;
806 data->ps.dis.itemAction = dis->itemAction;
807 data->ps.dis.itemState = dis->itemState;
808 data->ps.dis.hwndItem = wine_server_user_handle( dis->hwndItem );
809 data->ps.dis.hDC = wine_server_user_handle( dis->hDC ); /* FIXME */
810 data->ps.dis.rcItem = dis->rcItem;
811 data->ps.dis.itemData = dis->itemData;
812 push_data( data, &data->ps.dis, sizeof(data->ps.dis) );
813 return 0;
815 case WM_MEASUREITEM:
817 MEASUREITEMSTRUCT *mis = (MEASUREITEMSTRUCT *)lparam;
818 data->ps.mis.CtlType = mis->CtlType;
819 data->ps.mis.CtlID = mis->CtlID;
820 data->ps.mis.itemID = mis->itemID;
821 data->ps.mis.itemWidth = mis->itemWidth;
822 data->ps.mis.itemHeight = mis->itemHeight;
823 data->ps.mis.itemData = mis->itemData;
824 push_data( data, &data->ps.mis, sizeof(data->ps.mis) );
825 return sizeof(data->ps.mis);
827 case WM_DELETEITEM:
829 DELETEITEMSTRUCT *dls = (DELETEITEMSTRUCT *)lparam;
830 data->ps.dls.CtlType = dls->CtlType;
831 data->ps.dls.CtlID = dls->CtlID;
832 data->ps.dls.itemID = dls->itemID;
833 data->ps.dls.hwndItem = wine_server_user_handle( dls->hwndItem );
834 data->ps.dls.itemData = dls->itemData;
835 push_data( data, &data->ps.dls, sizeof(data->ps.dls) );
836 return 0;
838 case WM_COMPAREITEM:
840 COMPAREITEMSTRUCT *cis = (COMPAREITEMSTRUCT *)lparam;
841 data->ps.cis.CtlType = cis->CtlType;
842 data->ps.cis.CtlID = cis->CtlID;
843 data->ps.cis.hwndItem = wine_server_user_handle( cis->hwndItem );
844 data->ps.cis.itemID1 = cis->itemID1;
845 data->ps.cis.itemData1 = cis->itemData1;
846 data->ps.cis.itemID2 = cis->itemID2;
847 data->ps.cis.itemData2 = cis->itemData2;
848 data->ps.cis.dwLocaleId = cis->dwLocaleId;
849 push_data( data, &data->ps.cis, sizeof(data->ps.cis) );
850 return 0;
852 case WM_WINE_SETWINDOWPOS:
853 case WM_WINDOWPOSCHANGING:
854 case WM_WINDOWPOSCHANGED:
856 WINDOWPOS *wp = (WINDOWPOS *)lparam;
857 data->ps.wp.hwnd = wine_server_user_handle( wp->hwnd );
858 data->ps.wp.hwndInsertAfter = wine_server_user_handle( wp->hwndInsertAfter );
859 data->ps.wp.x = wp->x;
860 data->ps.wp.y = wp->y;
861 data->ps.wp.cx = wp->cx;
862 data->ps.wp.cy = wp->cy;
863 data->ps.wp.flags = wp->flags;
864 push_data( data, &data->ps.wp, sizeof(data->ps.wp) );
865 return sizeof(data->ps.wp);
867 case WM_COPYDATA:
869 COPYDATASTRUCT *cds = (COPYDATASTRUCT *)lparam;
870 data->ps.cds.cbData = cds->cbData;
871 data->ps.cds.dwData = cds->dwData;
872 data->ps.cds.lpData = pack_ptr( cds->lpData );
873 push_data( data, &data->ps.cds, sizeof(data->ps.cds) );
874 if (cds->lpData) push_data( data, cds->lpData, cds->cbData );
875 return 0;
877 case WM_NOTIFY:
878 /* WM_NOTIFY cannot be sent across processes (MSDN) */
879 data->count = -1;
880 return 0;
881 case WM_HELP:
883 HELPINFO *hi = (HELPINFO *)lparam;
884 data->ps.hi.iContextType = hi->iContextType;
885 data->ps.hi.iCtrlId = hi->iCtrlId;
886 data->ps.hi.hItemHandle = wine_server_user_handle( hi->hItemHandle );
887 data->ps.hi.dwContextId = hi->dwContextId;
888 data->ps.hi.MousePos = hi->MousePos;
889 push_data( data, &data->ps.hi, sizeof(data->ps.hi) );
890 return 0;
892 case WM_STYLECHANGING:
893 case WM_STYLECHANGED:
894 push_data( data, (STYLESTRUCT *)lparam, sizeof(STYLESTRUCT) );
895 return 0;
896 case WM_NCCALCSIZE:
897 if (!wparam)
899 push_data( data, (RECT *)lparam, sizeof(RECT) );
900 return sizeof(RECT);
902 else
904 NCCALCSIZE_PARAMS *ncp = (NCCALCSIZE_PARAMS *)lparam;
905 data->ps.ncp.rgrc[0] = ncp->rgrc[0];
906 data->ps.ncp.rgrc[1] = ncp->rgrc[1];
907 data->ps.ncp.rgrc[2] = ncp->rgrc[2];
908 data->ps.ncp.hwnd = wine_server_user_handle( ncp->lppos->hwnd );
909 data->ps.ncp.hwndInsertAfter = wine_server_user_handle( ncp->lppos->hwndInsertAfter );
910 data->ps.ncp.x = ncp->lppos->x;
911 data->ps.ncp.y = ncp->lppos->y;
912 data->ps.ncp.cx = ncp->lppos->cx;
913 data->ps.ncp.cy = ncp->lppos->cy;
914 data->ps.ncp.flags = ncp->lppos->flags;
915 push_data( data, &data->ps.ncp, sizeof(data->ps.ncp) );
916 return sizeof(data->ps.ncp);
918 case WM_GETDLGCODE:
919 if (lparam)
921 MSG *msg = (MSG *)lparam;
922 data->ps.msg.hwnd = wine_server_user_handle( msg->hwnd );
923 data->ps.msg.message = msg->message;
924 data->ps.msg.wParam = msg->wParam;
925 data->ps.msg.lParam = msg->lParam;
926 data->ps.msg.time = msg->time;
927 data->ps.msg.pt = msg->pt;
928 push_data( data, &data->ps.msg, sizeof(data->ps.msg) );
929 return sizeof(data->ps.msg);
931 return 0;
932 case SBM_SETSCROLLINFO:
933 push_data( data, (SCROLLINFO *)lparam, sizeof(SCROLLINFO) );
934 return 0;
935 case SBM_GETSCROLLINFO:
936 push_data( data, (SCROLLINFO *)lparam, sizeof(SCROLLINFO) );
937 return sizeof(SCROLLINFO);
938 case SBM_GETSCROLLBARINFO:
940 const SCROLLBARINFO *info = (const SCROLLBARINFO *)lparam;
941 size_t size = min( info->cbSize, sizeof(SCROLLBARINFO) );
942 push_data( data, info, size );
943 return size;
945 case EM_GETSEL:
946 case SBM_GETRANGE:
947 case CB_GETEDITSEL:
949 size_t size = 0;
950 if (wparam) size += sizeof(DWORD);
951 if (lparam) size += sizeof(DWORD);
952 return size;
954 case EM_GETRECT:
955 case LB_GETITEMRECT:
956 case CB_GETDROPPEDCONTROLRECT:
957 return sizeof(RECT);
958 case EM_SETRECT:
959 case EM_SETRECTNP:
960 push_data( data, (RECT *)lparam, sizeof(RECT) );
961 return 0;
962 case EM_GETLINE:
964 WORD *pw = (WORD *)lparam;
965 push_data( data, pw, sizeof(*pw) );
966 return *pw * sizeof(WCHAR);
968 case EM_SETTABSTOPS:
969 case LB_SETTABSTOPS:
970 if (wparam) push_data( data, (UINT *)lparam, sizeof(UINT) * wparam );
971 return 0;
972 case CB_ADDSTRING:
973 case CB_INSERTSTRING:
974 case CB_FINDSTRING:
975 case CB_FINDSTRINGEXACT:
976 case CB_SELECTSTRING:
977 if (combobox_has_strings( hwnd )) push_string( data, (LPWSTR)lparam );
978 return 0;
979 case CB_GETLBTEXT:
980 if (!combobox_has_strings( hwnd )) return sizeof(ULONG_PTR);
981 return (SendMessageW( hwnd, CB_GETLBTEXTLEN, wparam, 0 ) + 1) * sizeof(WCHAR);
982 case LB_ADDSTRING:
983 case LB_INSERTSTRING:
984 case LB_FINDSTRING:
985 case LB_FINDSTRINGEXACT:
986 case LB_SELECTSTRING:
987 if (listbox_has_strings( hwnd )) push_string( data, (LPWSTR)lparam );
988 return 0;
989 case LB_GETTEXT:
990 if (!listbox_has_strings( hwnd )) return sizeof(ULONG_PTR);
991 return (SendMessageW( hwnd, LB_GETTEXTLEN, wparam, 0 ) + 1) * sizeof(WCHAR);
992 case LB_GETSELITEMS:
993 return wparam * sizeof(UINT);
994 case WM_NEXTMENU:
996 MDINEXTMENU *mnm = (MDINEXTMENU *)lparam;
997 data->ps.mnm.hmenuIn = wine_server_user_handle( mnm->hmenuIn );
998 data->ps.mnm.hmenuNext = wine_server_user_handle( mnm->hmenuNext );
999 data->ps.mnm.hwndNext = wine_server_user_handle( mnm->hwndNext );
1000 push_data( data, &data->ps.mnm, sizeof(data->ps.mnm) );
1001 return sizeof(data->ps.mnm);
1003 case WM_SIZING:
1004 case WM_MOVING:
1005 push_data( data, (RECT *)lparam, sizeof(RECT) );
1006 return sizeof(RECT);
1007 case WM_MDICREATE:
1009 MDICREATESTRUCTW *mcs = (MDICREATESTRUCTW *)lparam;
1010 data->ps.mcs.szClass = pack_ptr( mcs->szClass );
1011 data->ps.mcs.szTitle = pack_ptr( mcs->szTitle );
1012 data->ps.mcs.hOwner = pack_ptr( mcs->hOwner );
1013 data->ps.mcs.x = mcs->x;
1014 data->ps.mcs.y = mcs->y;
1015 data->ps.mcs.cx = mcs->cx;
1016 data->ps.mcs.cy = mcs->cy;
1017 data->ps.mcs.style = mcs->style;
1018 data->ps.mcs.lParam = mcs->lParam;
1019 push_data( data, &data->ps.mcs, sizeof(data->ps.mcs) );
1020 if (!IS_INTRESOURCE(mcs->szClass)) push_string( data, mcs->szClass );
1021 if (!IS_INTRESOURCE(mcs->szTitle)) push_string( data, mcs->szTitle );
1022 return sizeof(data->ps.mcs);
1024 case WM_MDIGETACTIVE:
1025 if (lparam) return sizeof(BOOL);
1026 return 0;
1027 case WM_DEVICECHANGE:
1029 DEV_BROADCAST_HDR *header = (DEV_BROADCAST_HDR *)lparam;
1030 push_data( data, header, header->dbch_size );
1031 return 0;
1033 case WM_WINE_KEYBOARD_LL_HOOK:
1035 struct hook_extra_info *h_extra = (struct hook_extra_info *)lparam;
1036 data->ps.hook.handle = wine_server_user_handle( h_extra->handle );
1037 push_data( data, &data->ps.hook, sizeof(data->ps.hook) );
1038 push_data( data, (LPVOID)h_extra->lparam, sizeof(KBDLLHOOKSTRUCT) );
1039 return 0;
1041 case WM_WINE_MOUSE_LL_HOOK:
1043 struct hook_extra_info *h_extra = (struct hook_extra_info *)lparam;
1044 data->ps.hook.handle = wine_server_user_handle( h_extra->handle );
1045 push_data( data, &data->ps.hook, sizeof(data->ps.hook) );
1046 push_data( data, (LPVOID)h_extra->lparam, sizeof(MSLLHOOKSTRUCT) );
1047 return 0;
1049 case WM_NCPAINT:
1050 if (wparam <= 1) return 0;
1051 FIXME( "WM_NCPAINT hdc packing not supported yet\n" );
1052 data->count = -1;
1053 return 0;
1054 case WM_PAINT:
1055 if (!wparam) return 0;
1056 /* fall through */
1058 /* these contain an HFONT */
1059 case WM_SETFONT:
1060 case WM_GETFONT:
1061 /* these contain an HDC */
1062 case WM_ERASEBKGND:
1063 case WM_ICONERASEBKGND:
1064 case WM_CTLCOLORMSGBOX:
1065 case WM_CTLCOLOREDIT:
1066 case WM_CTLCOLORLISTBOX:
1067 case WM_CTLCOLORBTN:
1068 case WM_CTLCOLORDLG:
1069 case WM_CTLCOLORSCROLLBAR:
1070 case WM_CTLCOLORSTATIC:
1071 case WM_PRINT:
1072 case WM_PRINTCLIENT:
1073 /* these contain an HGLOBAL */
1074 case WM_PAINTCLIPBOARD:
1075 case WM_SIZECLIPBOARD:
1076 /* these contain HICON */
1077 case WM_GETICON:
1078 case WM_SETICON:
1079 case WM_QUERYDRAGICON:
1080 case WM_QUERYPARKICON:
1081 /* these contain pointers */
1082 case WM_DROPOBJECT:
1083 case WM_QUERYDROPOBJECT:
1084 case WM_DRAGLOOP:
1085 case WM_DRAGSELECT:
1086 case WM_DRAGMOVE:
1087 FIXME( "msg %x (%s) not supported yet\n", message, SPY_GetMsgName(message, hwnd) );
1088 data->count = -1;
1089 return 0;
1091 return 0;
1095 /***********************************************************************
1096 * unpack_message
1098 * Unpack a message received from another process.
1100 static BOOL unpack_message( HWND hwnd, UINT message, WPARAM *wparam, LPARAM *lparam,
1101 void **buffer, size_t size )
1103 size_t minsize = 0;
1104 union packed_structs *ps = *buffer;
1106 switch(message)
1108 case WM_NCCREATE:
1109 case WM_CREATE:
1111 CREATESTRUCTW cs;
1112 WCHAR *str = (WCHAR *)(&ps->cs + 1);
1113 if (size < sizeof(ps->cs)) return FALSE;
1114 size -= sizeof(ps->cs);
1115 cs.lpCreateParams = unpack_ptr( ps->cs.lpCreateParams );
1116 cs.hInstance = unpack_ptr( ps->cs.hInstance );
1117 cs.hMenu = wine_server_ptr_handle( ps->cs.hMenu );
1118 cs.hwndParent = wine_server_ptr_handle( ps->cs.hwndParent );
1119 cs.cy = ps->cs.cy;
1120 cs.cx = ps->cs.cx;
1121 cs.y = ps->cs.y;
1122 cs.x = ps->cs.x;
1123 cs.style = ps->cs.style;
1124 cs.dwExStyle = ps->cs.dwExStyle;
1125 cs.lpszName = unpack_ptr( ps->cs.lpszName );
1126 cs.lpszClass = unpack_ptr( ps->cs.lpszClass );
1127 if (ps->cs.lpszName >> 16)
1129 if (!check_string( str, size )) return FALSE;
1130 cs.lpszName = str;
1131 size -= (strlenW(str) + 1) * sizeof(WCHAR);
1132 str += strlenW(str) + 1;
1134 if (ps->cs.lpszClass >> 16)
1136 if (!check_string( str, size )) return FALSE;
1137 cs.lpszClass = str;
1139 memcpy( &ps->cs, &cs, sizeof(cs) );
1140 break;
1142 case WM_GETTEXT:
1143 case WM_ASKCBFORMATNAME:
1144 if (!get_buffer_space( buffer, (*wparam * sizeof(WCHAR)) )) return FALSE;
1145 break;
1146 case WM_WININICHANGE:
1147 if (!*lparam) return TRUE;
1148 /* fall through */
1149 case WM_SETTEXT:
1150 case WM_DEVMODECHANGE:
1151 case CB_DIR:
1152 case LB_DIR:
1153 case LB_ADDFILE:
1154 case EM_REPLACESEL:
1155 if (!check_string( *buffer, size )) return FALSE;
1156 break;
1157 case WM_GETMINMAXINFO:
1158 minsize = sizeof(MINMAXINFO);
1159 break;
1160 case WM_DRAWITEM:
1162 DRAWITEMSTRUCT dis;
1163 if (size < sizeof(ps->dis)) return FALSE;
1164 dis.CtlType = ps->dis.CtlType;
1165 dis.CtlID = ps->dis.CtlID;
1166 dis.itemID = ps->dis.itemID;
1167 dis.itemAction = ps->dis.itemAction;
1168 dis.itemState = ps->dis.itemState;
1169 dis.hwndItem = wine_server_ptr_handle( ps->dis.hwndItem );
1170 dis.hDC = wine_server_ptr_handle( ps->dis.hDC );
1171 dis.rcItem = ps->dis.rcItem;
1172 dis.itemData = (ULONG_PTR)unpack_ptr( ps->dis.itemData );
1173 memcpy( &ps->dis, &dis, sizeof(dis) );
1174 break;
1176 case WM_MEASUREITEM:
1178 MEASUREITEMSTRUCT mis;
1179 if (size < sizeof(ps->mis)) return FALSE;
1180 mis.CtlType = ps->mis.CtlType;
1181 mis.CtlID = ps->mis.CtlID;
1182 mis.itemID = ps->mis.itemID;
1183 mis.itemWidth = ps->mis.itemWidth;
1184 mis.itemHeight = ps->mis.itemHeight;
1185 mis.itemData = (ULONG_PTR)unpack_ptr( ps->mis.itemData );
1186 memcpy( &ps->mis, &mis, sizeof(mis) );
1187 break;
1189 case WM_DELETEITEM:
1191 DELETEITEMSTRUCT dls;
1192 if (size < sizeof(ps->dls)) return FALSE;
1193 dls.CtlType = ps->dls.CtlType;
1194 dls.CtlID = ps->dls.CtlID;
1195 dls.itemID = ps->dls.itemID;
1196 dls.hwndItem = wine_server_ptr_handle( ps->dls.hwndItem );
1197 dls.itemData = (ULONG_PTR)unpack_ptr( ps->dls.itemData );
1198 memcpy( &ps->dls, &dls, sizeof(dls) );
1199 break;
1201 case WM_COMPAREITEM:
1203 COMPAREITEMSTRUCT cis;
1204 if (size < sizeof(ps->cis)) return FALSE;
1205 cis.CtlType = ps->cis.CtlType;
1206 cis.CtlID = ps->cis.CtlID;
1207 cis.hwndItem = wine_server_ptr_handle( ps->cis.hwndItem );
1208 cis.itemID1 = ps->cis.itemID1;
1209 cis.itemData1 = (ULONG_PTR)unpack_ptr( ps->cis.itemData1 );
1210 cis.itemID2 = ps->cis.itemID2;
1211 cis.itemData2 = (ULONG_PTR)unpack_ptr( ps->cis.itemData2 );
1212 cis.dwLocaleId = ps->cis.dwLocaleId;
1213 memcpy( &ps->cis, &cis, sizeof(cis) );
1214 break;
1216 case WM_WINDOWPOSCHANGING:
1217 case WM_WINDOWPOSCHANGED:
1218 case WM_WINE_SETWINDOWPOS:
1220 WINDOWPOS wp;
1221 if (size < sizeof(ps->wp)) return FALSE;
1222 wp.hwnd = wine_server_ptr_handle( ps->wp.hwnd );
1223 wp.hwndInsertAfter = wine_server_ptr_handle( ps->wp.hwndInsertAfter );
1224 wp.x = ps->wp.x;
1225 wp.y = ps->wp.y;
1226 wp.cx = ps->wp.cx;
1227 wp.cy = ps->wp.cy;
1228 wp.flags = ps->wp.flags;
1229 memcpy( &ps->wp, &wp, sizeof(wp) );
1230 break;
1232 case WM_COPYDATA:
1234 COPYDATASTRUCT cds;
1235 if (size < sizeof(ps->cds)) return FALSE;
1236 cds.dwData = (ULONG_PTR)unpack_ptr( ps->cds.dwData );
1237 if (ps->cds.lpData)
1239 cds.cbData = ps->cds.cbData;
1240 cds.lpData = &ps->cds + 1;
1241 minsize = sizeof(ps->cds) + cds.cbData;
1243 else
1245 cds.cbData = 0;
1246 cds.lpData = 0;
1248 memcpy( &ps->cds, &cds, sizeof(cds) );
1249 break;
1251 case WM_NOTIFY:
1252 /* WM_NOTIFY cannot be sent across processes (MSDN) */
1253 return FALSE;
1254 case WM_HELP:
1256 HELPINFO hi;
1257 if (size < sizeof(ps->hi)) return FALSE;
1258 hi.cbSize = sizeof(hi);
1259 hi.iContextType = ps->hi.iContextType;
1260 hi.iCtrlId = ps->hi.iCtrlId;
1261 hi.hItemHandle = wine_server_ptr_handle( ps->hi.hItemHandle );
1262 hi.dwContextId = (ULONG_PTR)unpack_ptr( ps->hi.dwContextId );
1263 hi.MousePos = ps->hi.MousePos;
1264 memcpy( &ps->hi, &hi, sizeof(hi) );
1265 break;
1267 case WM_STYLECHANGING:
1268 case WM_STYLECHANGED:
1269 minsize = sizeof(STYLESTRUCT);
1270 break;
1271 case WM_NCCALCSIZE:
1272 if (!*wparam) minsize = sizeof(RECT);
1273 else
1275 NCCALCSIZE_PARAMS ncp;
1276 WINDOWPOS wp;
1277 if (size < sizeof(ps->ncp)) return FALSE;
1278 ncp.rgrc[0] = ps->ncp.rgrc[0];
1279 ncp.rgrc[1] = ps->ncp.rgrc[1];
1280 ncp.rgrc[2] = ps->ncp.rgrc[2];
1281 wp.hwnd = wine_server_ptr_handle( ps->ncp.hwnd );
1282 wp.hwndInsertAfter = wine_server_ptr_handle( ps->ncp.hwndInsertAfter );
1283 wp.x = ps->ncp.x;
1284 wp.y = ps->ncp.y;
1285 wp.cx = ps->ncp.cx;
1286 wp.cy = ps->ncp.cy;
1287 wp.flags = ps->ncp.flags;
1288 ncp.lppos = (WINDOWPOS *)((NCCALCSIZE_PARAMS *)&ps->ncp + 1);
1289 memcpy( &ps->ncp, &ncp, sizeof(ncp) );
1290 *ncp.lppos = wp;
1292 break;
1293 case WM_GETDLGCODE:
1294 if (*lparam)
1296 MSG msg;
1297 if (size < sizeof(ps->msg)) return FALSE;
1298 msg.hwnd = wine_server_ptr_handle( ps->msg.hwnd );
1299 msg.message = ps->msg.message;
1300 msg.wParam = (ULONG_PTR)unpack_ptr( ps->msg.wParam );
1301 msg.lParam = (ULONG_PTR)unpack_ptr( ps->msg.lParam );
1302 msg.time = ps->msg.time;
1303 msg.pt = ps->msg.pt;
1304 memcpy( &ps->msg, &msg, sizeof(msg) );
1305 break;
1307 return TRUE;
1308 case SBM_SETSCROLLINFO:
1309 minsize = sizeof(SCROLLINFO);
1310 break;
1311 case SBM_GETSCROLLINFO:
1312 if (!get_buffer_space( buffer, sizeof(SCROLLINFO ))) return FALSE;
1313 break;
1314 case SBM_GETSCROLLBARINFO:
1315 if (!get_buffer_space( buffer, sizeof(SCROLLBARINFO ))) return FALSE;
1316 break;
1317 case EM_GETSEL:
1318 case SBM_GETRANGE:
1319 case CB_GETEDITSEL:
1320 if (*wparam || *lparam)
1322 if (!get_buffer_space( buffer, 2*sizeof(DWORD) )) return FALSE;
1323 if (*wparam) *wparam = (WPARAM)*buffer;
1324 if (*lparam) *lparam = (LPARAM)((DWORD *)*buffer + 1);
1326 return TRUE;
1327 case EM_GETRECT:
1328 case LB_GETITEMRECT:
1329 case CB_GETDROPPEDCONTROLRECT:
1330 if (!get_buffer_space( buffer, sizeof(RECT) )) return FALSE;
1331 break;
1332 case EM_SETRECT:
1333 case EM_SETRECTNP:
1334 minsize = sizeof(RECT);
1335 break;
1336 case EM_GETLINE:
1338 WORD len;
1339 if (size < sizeof(WORD)) return FALSE;
1340 len = *(WORD *)*buffer;
1341 if (!get_buffer_space( buffer, (len + 1) * sizeof(WCHAR) )) return FALSE;
1342 *lparam = (LPARAM)*buffer + sizeof(WORD); /* don't erase WORD at start of buffer */
1343 return TRUE;
1345 case EM_SETTABSTOPS:
1346 case LB_SETTABSTOPS:
1347 if (!*wparam) return TRUE;
1348 minsize = *wparam * sizeof(UINT);
1349 break;
1350 case CB_ADDSTRING:
1351 case CB_INSERTSTRING:
1352 case CB_FINDSTRING:
1353 case CB_FINDSTRINGEXACT:
1354 case CB_SELECTSTRING:
1355 case LB_ADDSTRING:
1356 case LB_INSERTSTRING:
1357 case LB_FINDSTRING:
1358 case LB_FINDSTRINGEXACT:
1359 case LB_SELECTSTRING:
1360 if (!*buffer) return TRUE;
1361 if (!check_string( *buffer, size )) return FALSE;
1362 break;
1363 case CB_GETLBTEXT:
1365 size = sizeof(ULONG_PTR);
1366 if (combobox_has_strings( hwnd ))
1367 size = (SendMessageW( hwnd, CB_GETLBTEXTLEN, *wparam, 0 ) + 1) * sizeof(WCHAR);
1368 if (!get_buffer_space( buffer, size )) return FALSE;
1369 break;
1371 case LB_GETTEXT:
1373 size = sizeof(ULONG_PTR);
1374 if (listbox_has_strings( hwnd ))
1375 size = (SendMessageW( hwnd, LB_GETTEXTLEN, *wparam, 0 ) + 1) * sizeof(WCHAR);
1376 if (!get_buffer_space( buffer, size )) return FALSE;
1377 break;
1379 case LB_GETSELITEMS:
1380 if (!get_buffer_space( buffer, *wparam * sizeof(UINT) )) return FALSE;
1381 break;
1382 case WM_NEXTMENU:
1384 MDINEXTMENU mnm;
1385 if (size < sizeof(ps->mnm)) return FALSE;
1386 mnm.hmenuIn = wine_server_ptr_handle( ps->mnm.hmenuIn );
1387 mnm.hmenuNext = wine_server_ptr_handle( ps->mnm.hmenuNext );
1388 mnm.hwndNext = wine_server_ptr_handle( ps->mnm.hwndNext );
1389 memcpy( &ps->mnm, &mnm, sizeof(mnm) );
1390 break;
1392 case WM_SIZING:
1393 case WM_MOVING:
1394 minsize = sizeof(RECT);
1395 if (!get_buffer_space( buffer, sizeof(RECT) )) return FALSE;
1396 break;
1397 case WM_MDICREATE:
1399 MDICREATESTRUCTW mcs;
1400 WCHAR *str = (WCHAR *)(&ps->mcs + 1);
1401 if (size < sizeof(ps->mcs)) return FALSE;
1402 size -= sizeof(ps->mcs);
1404 mcs.szClass = unpack_ptr( ps->mcs.szClass );
1405 mcs.szTitle = unpack_ptr( ps->mcs.szTitle );
1406 mcs.hOwner = unpack_ptr( ps->mcs.hOwner );
1407 mcs.x = ps->mcs.x;
1408 mcs.y = ps->mcs.y;
1409 mcs.cx = ps->mcs.cx;
1410 mcs.cy = ps->mcs.cy;
1411 mcs.style = ps->mcs.style;
1412 mcs.lParam = (LPARAM)unpack_ptr( ps->mcs.lParam );
1413 if (ps->mcs.szClass >> 16)
1415 if (!check_string( str, size )) return FALSE;
1416 mcs.szClass = str;
1417 size -= (strlenW(str) + 1) * sizeof(WCHAR);
1418 str += strlenW(str) + 1;
1420 if (ps->mcs.szTitle >> 16)
1422 if (!check_string( str, size )) return FALSE;
1423 mcs.szTitle = str;
1425 memcpy( &ps->mcs, &mcs, sizeof(mcs) );
1426 break;
1428 case WM_MDIGETACTIVE:
1429 if (!*lparam) return TRUE;
1430 if (!get_buffer_space( buffer, sizeof(BOOL) )) return FALSE;
1431 break;
1432 case WM_DEVICECHANGE:
1433 minsize = sizeof(DEV_BROADCAST_HDR);
1434 break;
1435 case WM_WINE_KEYBOARD_LL_HOOK:
1436 case WM_WINE_MOUSE_LL_HOOK:
1438 struct hook_extra_info h_extra;
1439 minsize = sizeof(ps->hook) +
1440 (message == WM_WINE_KEYBOARD_LL_HOOK ? sizeof(KBDLLHOOKSTRUCT)
1441 : sizeof(MSLLHOOKSTRUCT));
1442 if (size < minsize) return FALSE;
1443 h_extra.handle = wine_server_ptr_handle( ps->hook.handle );
1444 h_extra.lparam = (LPARAM)(&ps->hook + 1);
1445 memcpy( &ps->hook, &h_extra, sizeof(h_extra) );
1446 break;
1448 case WM_NCPAINT:
1449 if (*wparam <= 1) return TRUE;
1450 FIXME( "WM_NCPAINT hdc unpacking not supported\n" );
1451 return FALSE;
1452 case WM_PAINT:
1453 if (!*wparam) return TRUE;
1454 /* fall through */
1456 /* these contain an HFONT */
1457 case WM_SETFONT:
1458 case WM_GETFONT:
1459 /* these contain an HDC */
1460 case WM_ERASEBKGND:
1461 case WM_ICONERASEBKGND:
1462 case WM_CTLCOLORMSGBOX:
1463 case WM_CTLCOLOREDIT:
1464 case WM_CTLCOLORLISTBOX:
1465 case WM_CTLCOLORBTN:
1466 case WM_CTLCOLORDLG:
1467 case WM_CTLCOLORSCROLLBAR:
1468 case WM_CTLCOLORSTATIC:
1469 case WM_PRINT:
1470 case WM_PRINTCLIENT:
1471 /* these contain an HGLOBAL */
1472 case WM_PAINTCLIPBOARD:
1473 case WM_SIZECLIPBOARD:
1474 /* these contain HICON */
1475 case WM_GETICON:
1476 case WM_SETICON:
1477 case WM_QUERYDRAGICON:
1478 case WM_QUERYPARKICON:
1479 /* these contain pointers */
1480 case WM_DROPOBJECT:
1481 case WM_QUERYDROPOBJECT:
1482 case WM_DRAGLOOP:
1483 case WM_DRAGSELECT:
1484 case WM_DRAGMOVE:
1485 FIXME( "msg %x (%s) not supported yet\n", message, SPY_GetMsgName(message, hwnd) );
1486 return FALSE;
1488 default:
1489 return TRUE; /* message doesn't need any unpacking */
1492 /* default exit for most messages: check minsize and store buffer in lparam */
1493 if (size < minsize) return FALSE;
1494 *lparam = (LPARAM)*buffer;
1495 return TRUE;
1499 /***********************************************************************
1500 * pack_reply
1502 * Pack a reply to a message for sending to another process.
1504 static void pack_reply( HWND hwnd, UINT message, WPARAM wparam, LPARAM lparam,
1505 LRESULT res, struct packed_message *data )
1507 data->count = 0;
1508 switch(message)
1510 case WM_NCCREATE:
1511 case WM_CREATE:
1513 CREATESTRUCTW *cs = (CREATESTRUCTW *)lparam;
1514 data->ps.cs.lpCreateParams = (ULONG_PTR)cs->lpCreateParams;
1515 data->ps.cs.hInstance = (ULONG_PTR)cs->hInstance;
1516 data->ps.cs.hMenu = wine_server_user_handle( cs->hMenu );
1517 data->ps.cs.hwndParent = wine_server_user_handle( cs->hwndParent );
1518 data->ps.cs.cy = cs->cy;
1519 data->ps.cs.cx = cs->cx;
1520 data->ps.cs.y = cs->y;
1521 data->ps.cs.x = cs->x;
1522 data->ps.cs.style = cs->style;
1523 data->ps.cs.dwExStyle = cs->dwExStyle;
1524 data->ps.cs.lpszName = (ULONG_PTR)cs->lpszName;
1525 data->ps.cs.lpszClass = (ULONG_PTR)cs->lpszClass;
1526 push_data( data, &data->ps.cs, sizeof(data->ps.cs) );
1527 break;
1529 case WM_GETTEXT:
1530 case CB_GETLBTEXT:
1531 case LB_GETTEXT:
1532 push_data( data, (WCHAR *)lparam, (res + 1) * sizeof(WCHAR) );
1533 break;
1534 case WM_GETMINMAXINFO:
1535 push_data( data, (MINMAXINFO *)lparam, sizeof(MINMAXINFO) );
1536 break;
1537 case WM_MEASUREITEM:
1539 MEASUREITEMSTRUCT *mis = (MEASUREITEMSTRUCT *)lparam;
1540 data->ps.mis.CtlType = mis->CtlType;
1541 data->ps.mis.CtlID = mis->CtlID;
1542 data->ps.mis.itemID = mis->itemID;
1543 data->ps.mis.itemWidth = mis->itemWidth;
1544 data->ps.mis.itemHeight = mis->itemHeight;
1545 data->ps.mis.itemData = mis->itemData;
1546 push_data( data, &data->ps.mis, sizeof(data->ps.mis) );
1547 break;
1549 case WM_WINDOWPOSCHANGING:
1550 case WM_WINDOWPOSCHANGED:
1552 WINDOWPOS *wp = (WINDOWPOS *)lparam;
1553 data->ps.wp.hwnd = wine_server_user_handle( wp->hwnd );
1554 data->ps.wp.hwndInsertAfter = wine_server_user_handle( wp->hwndInsertAfter );
1555 data->ps.wp.x = wp->x;
1556 data->ps.wp.y = wp->y;
1557 data->ps.wp.cx = wp->cx;
1558 data->ps.wp.cy = wp->cy;
1559 data->ps.wp.flags = wp->flags;
1560 push_data( data, &data->ps.wp, sizeof(data->ps.wp) );
1561 break;
1563 case WM_GETDLGCODE:
1564 if (lparam)
1566 MSG *msg = (MSG *)lparam;
1567 data->ps.msg.hwnd = wine_server_user_handle( msg->hwnd );
1568 data->ps.msg.message = msg->message;
1569 data->ps.msg.wParam = msg->wParam;
1570 data->ps.msg.lParam = msg->lParam;
1571 data->ps.msg.time = msg->time;
1572 data->ps.msg.pt = msg->pt;
1573 push_data( data, &data->ps.msg, sizeof(data->ps.msg) );
1575 break;
1576 case SBM_GETSCROLLINFO:
1577 push_data( data, (SCROLLINFO *)lparam, sizeof(SCROLLINFO) );
1578 break;
1579 case EM_GETRECT:
1580 case LB_GETITEMRECT:
1581 case CB_GETDROPPEDCONTROLRECT:
1582 case WM_SIZING:
1583 case WM_MOVING:
1584 push_data( data, (RECT *)lparam, sizeof(RECT) );
1585 break;
1586 case EM_GETLINE:
1588 WORD *ptr = (WORD *)lparam;
1589 push_data( data, ptr, ptr[-1] * sizeof(WCHAR) );
1590 break;
1592 case LB_GETSELITEMS:
1593 push_data( data, (UINT *)lparam, wparam * sizeof(UINT) );
1594 break;
1595 case WM_MDIGETACTIVE:
1596 if (lparam) push_data( data, (BOOL *)lparam, sizeof(BOOL) );
1597 break;
1598 case WM_NCCALCSIZE:
1599 if (!wparam)
1600 push_data( data, (RECT *)lparam, sizeof(RECT) );
1601 else
1603 NCCALCSIZE_PARAMS *ncp = (NCCALCSIZE_PARAMS *)lparam;
1604 data->ps.ncp.rgrc[0] = ncp->rgrc[0];
1605 data->ps.ncp.rgrc[1] = ncp->rgrc[1];
1606 data->ps.ncp.rgrc[2] = ncp->rgrc[2];
1607 data->ps.ncp.hwnd = wine_server_user_handle( ncp->lppos->hwnd );
1608 data->ps.ncp.hwndInsertAfter = wine_server_user_handle( ncp->lppos->hwndInsertAfter );
1609 data->ps.ncp.x = ncp->lppos->x;
1610 data->ps.ncp.y = ncp->lppos->y;
1611 data->ps.ncp.cx = ncp->lppos->cx;
1612 data->ps.ncp.cy = ncp->lppos->cy;
1613 data->ps.ncp.flags = ncp->lppos->flags;
1614 push_data( data, &data->ps.ncp, sizeof(data->ps.ncp) );
1616 break;
1617 case EM_GETSEL:
1618 case SBM_GETRANGE:
1619 case CB_GETEDITSEL:
1620 if (wparam) push_data( data, (DWORD *)wparam, sizeof(DWORD) );
1621 if (lparam) push_data( data, (DWORD *)lparam, sizeof(DWORD) );
1622 break;
1623 case WM_NEXTMENU:
1625 MDINEXTMENU *mnm = (MDINEXTMENU *)lparam;
1626 data->ps.mnm.hmenuIn = wine_server_user_handle( mnm->hmenuIn );
1627 data->ps.mnm.hmenuNext = wine_server_user_handle( mnm->hmenuNext );
1628 data->ps.mnm.hwndNext = wine_server_user_handle( mnm->hwndNext );
1629 push_data( data, &data->ps.mnm, sizeof(data->ps.mnm) );
1630 break;
1632 case WM_MDICREATE:
1634 MDICREATESTRUCTW *mcs = (MDICREATESTRUCTW *)lparam;
1635 data->ps.mcs.szClass = pack_ptr( mcs->szClass );
1636 data->ps.mcs.szTitle = pack_ptr( mcs->szTitle );
1637 data->ps.mcs.hOwner = pack_ptr( mcs->hOwner );
1638 data->ps.mcs.x = mcs->x;
1639 data->ps.mcs.y = mcs->y;
1640 data->ps.mcs.cx = mcs->cx;
1641 data->ps.mcs.cy = mcs->cy;
1642 data->ps.mcs.style = mcs->style;
1643 data->ps.mcs.lParam = mcs->lParam;
1644 push_data( data, &data->ps.mcs, sizeof(data->ps.mcs) );
1645 break;
1647 case WM_ASKCBFORMATNAME:
1648 push_data( data, (WCHAR *)lparam, (strlenW((WCHAR *)lparam) + 1) * sizeof(WCHAR) );
1649 break;
1654 /***********************************************************************
1655 * unpack_reply
1657 * Unpack a message reply received from another process.
1659 static void unpack_reply( HWND hwnd, UINT message, WPARAM wparam, LPARAM lparam,
1660 void *buffer, size_t size )
1662 union packed_structs *ps = buffer;
1664 switch(message)
1666 case WM_NCCREATE:
1667 case WM_CREATE:
1668 if (size >= sizeof(ps->cs))
1670 CREATESTRUCTW *cs = (CREATESTRUCTW *)lparam;
1671 cs->lpCreateParams = unpack_ptr( ps->cs.lpCreateParams );
1672 cs->hInstance = unpack_ptr( ps->cs.hInstance );
1673 cs->hMenu = wine_server_ptr_handle( ps->cs.hMenu );
1674 cs->hwndParent = wine_server_ptr_handle( ps->cs.hwndParent );
1675 cs->cy = ps->cs.cy;
1676 cs->cx = ps->cs.cx;
1677 cs->y = ps->cs.y;
1678 cs->x = ps->cs.x;
1679 cs->style = ps->cs.style;
1680 cs->dwExStyle = ps->cs.dwExStyle;
1681 /* don't allow changing name and class pointers */
1683 break;
1684 case WM_GETTEXT:
1685 case WM_ASKCBFORMATNAME:
1686 memcpy( (WCHAR *)lparam, buffer, min( wparam*sizeof(WCHAR), size ));
1687 break;
1688 case WM_GETMINMAXINFO:
1689 memcpy( (MINMAXINFO *)lparam, buffer, min( sizeof(MINMAXINFO), size ));
1690 break;
1691 case WM_MEASUREITEM:
1692 if (size >= sizeof(ps->mis))
1694 MEASUREITEMSTRUCT *mis = (MEASUREITEMSTRUCT *)lparam;
1695 mis->CtlType = ps->mis.CtlType;
1696 mis->CtlID = ps->mis.CtlID;
1697 mis->itemID = ps->mis.itemID;
1698 mis->itemWidth = ps->mis.itemWidth;
1699 mis->itemHeight = ps->mis.itemHeight;
1700 mis->itemData = (ULONG_PTR)unpack_ptr( ps->mis.itemData );
1702 break;
1703 case WM_WINDOWPOSCHANGING:
1704 case WM_WINDOWPOSCHANGED:
1705 if (size >= sizeof(ps->wp))
1707 WINDOWPOS *wp = (WINDOWPOS *)lparam;
1708 wp->hwnd = wine_server_ptr_handle( ps->wp.hwnd );
1709 wp->hwndInsertAfter = wine_server_ptr_handle( ps->wp.hwndInsertAfter );
1710 wp->x = ps->wp.x;
1711 wp->y = ps->wp.y;
1712 wp->cx = ps->wp.cx;
1713 wp->cy = ps->wp.cy;
1714 wp->flags = ps->wp.flags;
1716 break;
1717 case WM_GETDLGCODE:
1718 if (lparam && size >= sizeof(ps->msg))
1720 MSG *msg = (MSG *)lparam;
1721 msg->hwnd = wine_server_ptr_handle( ps->msg.hwnd );
1722 msg->message = ps->msg.message;
1723 msg->wParam = (ULONG_PTR)unpack_ptr( ps->msg.wParam );
1724 msg->lParam = (ULONG_PTR)unpack_ptr( ps->msg.lParam );
1725 msg->time = ps->msg.time;
1726 msg->pt = ps->msg.pt;
1728 break;
1729 case SBM_GETSCROLLINFO:
1730 memcpy( (SCROLLINFO *)lparam, buffer, min( sizeof(SCROLLINFO), size ));
1731 break;
1732 case SBM_GETSCROLLBARINFO:
1733 memcpy( (SCROLLBARINFO *)lparam, buffer, min( sizeof(SCROLLBARINFO), size ));
1734 break;
1735 case EM_GETRECT:
1736 case CB_GETDROPPEDCONTROLRECT:
1737 case LB_GETITEMRECT:
1738 case WM_SIZING:
1739 case WM_MOVING:
1740 memcpy( (RECT *)lparam, buffer, min( sizeof(RECT), size ));
1741 break;
1742 case EM_GETLINE:
1743 size = min( size, (size_t)*(WORD *)lparam );
1744 memcpy( (WCHAR *)lparam, buffer, size );
1745 break;
1746 case LB_GETSELITEMS:
1747 memcpy( (UINT *)lparam, buffer, min( wparam*sizeof(UINT), size ));
1748 break;
1749 case LB_GETTEXT:
1750 case CB_GETLBTEXT:
1751 memcpy( (WCHAR *)lparam, buffer, size );
1752 break;
1753 case WM_NEXTMENU:
1754 if (size >= sizeof(ps->mnm))
1756 MDINEXTMENU *mnm = (MDINEXTMENU *)lparam;
1757 mnm->hmenuIn = wine_server_ptr_handle( ps->mnm.hmenuIn );
1758 mnm->hmenuNext = wine_server_ptr_handle( ps->mnm.hmenuNext );
1759 mnm->hwndNext = wine_server_ptr_handle( ps->mnm.hwndNext );
1761 break;
1762 case WM_MDIGETACTIVE:
1763 if (lparam) memcpy( (BOOL *)lparam, buffer, min( sizeof(BOOL), size ));
1764 break;
1765 case WM_NCCALCSIZE:
1766 if (!wparam)
1767 memcpy( (RECT *)lparam, buffer, min( sizeof(RECT), size ));
1768 else if (size >= sizeof(ps->ncp))
1770 NCCALCSIZE_PARAMS *ncp = (NCCALCSIZE_PARAMS *)lparam;
1771 ncp->rgrc[0] = ps->ncp.rgrc[0];
1772 ncp->rgrc[1] = ps->ncp.rgrc[1];
1773 ncp->rgrc[2] = ps->ncp.rgrc[2];
1774 ncp->lppos->hwnd = wine_server_ptr_handle( ps->ncp.hwnd );
1775 ncp->lppos->hwndInsertAfter = wine_server_ptr_handle( ps->ncp.hwndInsertAfter );
1776 ncp->lppos->x = ps->ncp.x;
1777 ncp->lppos->y = ps->ncp.y;
1778 ncp->lppos->cx = ps->ncp.cx;
1779 ncp->lppos->cy = ps->ncp.cy;
1780 ncp->lppos->flags = ps->ncp.flags;
1782 break;
1783 case EM_GETSEL:
1784 case SBM_GETRANGE:
1785 case CB_GETEDITSEL:
1786 if (wparam)
1788 memcpy( (DWORD *)wparam, buffer, min( sizeof(DWORD), size ));
1789 if (size <= sizeof(DWORD)) break;
1790 size -= sizeof(DWORD);
1791 buffer = (DWORD *)buffer + 1;
1793 if (lparam) memcpy( (DWORD *)lparam, buffer, min( sizeof(DWORD), size ));
1794 break;
1795 case WM_MDICREATE:
1796 if (size >= sizeof(ps->mcs))
1798 MDICREATESTRUCTW *mcs = (MDICREATESTRUCTW *)lparam;
1799 mcs->hOwner = unpack_ptr( ps->mcs.hOwner );
1800 mcs->x = ps->mcs.x;
1801 mcs->y = ps->mcs.y;
1802 mcs->cx = ps->mcs.cx;
1803 mcs->cy = ps->mcs.cy;
1804 mcs->style = ps->mcs.style;
1805 mcs->lParam = (LPARAM)unpack_ptr( ps->mcs.lParam );
1806 /* don't allow changing class and title pointers */
1808 break;
1809 default:
1810 ERR( "should not happen: unexpected message %x\n", message );
1811 break;
1816 /***********************************************************************
1817 * reply_message
1819 * Send a reply to a sent message.
1821 static void reply_message( struct received_message_info *info, LRESULT result, BOOL remove )
1823 struct packed_message data;
1824 int i, replied = info->flags & ISMEX_REPLIED;
1826 if (info->flags & ISMEX_NOTIFY) return; /* notify messages don't get replies */
1827 if (!remove && replied) return; /* replied already */
1829 memset( &data, 0, sizeof(data) );
1830 info->flags |= ISMEX_REPLIED;
1832 if (info->type == MSG_OTHER_PROCESS && !replied)
1834 pack_reply( info->msg.hwnd, info->msg.message, info->msg.wParam,
1835 info->msg.lParam, result, &data );
1838 SERVER_START_REQ( reply_message )
1840 req->result = result;
1841 req->remove = remove;
1842 for (i = 0; i < data.count; i++) wine_server_add_data( req, data.data[i], data.size[i] );
1843 wine_server_call( req );
1845 SERVER_END_REQ;
1849 /***********************************************************************
1850 * handle_internal_message
1852 * Handle an internal Wine message instead of calling the window proc.
1854 static LRESULT handle_internal_message( HWND hwnd, UINT msg, WPARAM wparam, LPARAM lparam )
1856 switch(msg)
1858 case WM_WINE_DESTROYWINDOW:
1859 return WIN_DestroyWindow( hwnd );
1860 case WM_WINE_SETWINDOWPOS:
1861 if (is_desktop_window( hwnd )) return 0;
1862 return USER_SetWindowPos( (WINDOWPOS *)lparam );
1863 case WM_WINE_SHOWWINDOW:
1864 if (is_desktop_window( hwnd )) return 0;
1865 return ShowWindow( hwnd, wparam );
1866 case WM_WINE_SETPARENT:
1867 if (is_desktop_window( hwnd )) return 0;
1868 return (LRESULT)SetParent( hwnd, (HWND)wparam );
1869 case WM_WINE_SETWINDOWLONG:
1870 return WIN_SetWindowLong( hwnd, (short)LOWORD(wparam), HIWORD(wparam), lparam, TRUE );
1871 case WM_WINE_ENABLEWINDOW:
1872 if (is_desktop_window( hwnd )) return 0;
1873 return EnableWindow( hwnd, wparam );
1874 case WM_WINE_SETACTIVEWINDOW:
1875 if (is_desktop_window( hwnd )) return 0;
1876 if (!wparam && GetForegroundWindow() == hwnd) return 0;
1877 return (LRESULT)SetActiveWindow( (HWND)wparam );
1878 case WM_WINE_KEYBOARD_LL_HOOK:
1879 case WM_WINE_MOUSE_LL_HOOK:
1881 struct hook_extra_info *h_extra = (struct hook_extra_info *)lparam;
1883 return call_current_hook( h_extra->handle, HC_ACTION, wparam, h_extra->lparam );
1885 case WM_WINE_CLIPCURSOR:
1886 if (wparam)
1888 RECT rect;
1889 GetClipCursor( &rect );
1890 return USER_Driver->pClipCursor( &rect );
1892 return USER_Driver->pClipCursor( NULL );
1893 default:
1894 if (msg >= WM_WINE_FIRST_DRIVER_MSG && msg <= WM_WINE_LAST_DRIVER_MSG)
1895 return USER_Driver->pWindowMessage( hwnd, msg, wparam, lparam );
1896 FIXME( "unknown internal message %x\n", msg );
1897 return 0;
1901 /* since the WM_DDE_ACK response to a WM_DDE_EXECUTE message should contain the handle
1902 * to the memory handle, we keep track (in the server side) of all pairs of handle
1903 * used (the client passes its value and the content of the memory handle), and
1904 * the server stored both values (the client, and the local one, created after the
1905 * content). When a ACK message is generated, the list of pair is searched for a
1906 * matching pair, so that the client memory handle can be returned.
1908 struct DDE_pair {
1909 HGLOBAL client_hMem;
1910 HGLOBAL server_hMem;
1913 static struct DDE_pair* dde_pairs;
1914 static int dde_num_alloc;
1915 static int dde_num_used;
1917 static CRITICAL_SECTION dde_crst;
1918 static CRITICAL_SECTION_DEBUG critsect_debug =
1920 0, 0, &dde_crst,
1921 { &critsect_debug.ProcessLocksList, &critsect_debug.ProcessLocksList },
1922 0, 0, { (DWORD_PTR)(__FILE__ ": dde_crst") }
1924 static CRITICAL_SECTION dde_crst = { &critsect_debug, -1, 0, 0, 0, 0 };
1926 static BOOL dde_add_pair(HGLOBAL chm, HGLOBAL shm)
1928 int i;
1929 #define GROWBY 4
1931 EnterCriticalSection(&dde_crst);
1933 /* now remember the pair of hMem on both sides */
1934 if (dde_num_used == dde_num_alloc)
1936 struct DDE_pair* tmp;
1937 if (dde_pairs)
1938 tmp = HeapReAlloc( GetProcessHeap(), 0, dde_pairs,
1939 (dde_num_alloc + GROWBY) * sizeof(struct DDE_pair));
1940 else
1941 tmp = HeapAlloc( GetProcessHeap(), 0,
1942 (dde_num_alloc + GROWBY) * sizeof(struct DDE_pair));
1944 if (!tmp)
1946 LeaveCriticalSection(&dde_crst);
1947 return FALSE;
1949 dde_pairs = tmp;
1950 /* zero out newly allocated part */
1951 memset(&dde_pairs[dde_num_alloc], 0, GROWBY * sizeof(struct DDE_pair));
1952 dde_num_alloc += GROWBY;
1954 #undef GROWBY
1955 for (i = 0; i < dde_num_alloc; i++)
1957 if (dde_pairs[i].server_hMem == 0)
1959 dde_pairs[i].client_hMem = chm;
1960 dde_pairs[i].server_hMem = shm;
1961 dde_num_used++;
1962 break;
1965 LeaveCriticalSection(&dde_crst);
1966 return TRUE;
1969 static HGLOBAL dde_get_pair(HGLOBAL shm)
1971 int i;
1972 HGLOBAL ret = 0;
1974 EnterCriticalSection(&dde_crst);
1975 for (i = 0; i < dde_num_alloc; i++)
1977 if (dde_pairs[i].server_hMem == shm)
1979 /* free this pair */
1980 dde_pairs[i].server_hMem = 0;
1981 dde_num_used--;
1982 ret = dde_pairs[i].client_hMem;
1983 break;
1986 LeaveCriticalSection(&dde_crst);
1987 return ret;
1990 /***********************************************************************
1991 * post_dde_message
1993 * Post a DDE message
1995 static BOOL post_dde_message( struct packed_message *data, const struct send_message_info *info )
1997 void* ptr = NULL;
1998 int size = 0;
1999 UINT_PTR uiLo, uiHi;
2000 LPARAM lp;
2001 HGLOBAL hunlock = 0;
2002 int i;
2003 DWORD res;
2004 ULONGLONG hpack;
2006 if (!UnpackDDElParam( info->msg, info->lparam, &uiLo, &uiHi ))
2007 return FALSE;
2009 lp = info->lparam;
2010 switch (info->msg)
2012 /* DDE messages which don't require packing are:
2013 * WM_DDE_INITIATE
2014 * WM_DDE_TERMINATE
2015 * WM_DDE_REQUEST
2016 * WM_DDE_UNADVISE
2018 case WM_DDE_ACK:
2019 if (HIWORD(uiHi))
2021 /* uiHi should contain a hMem from WM_DDE_EXECUTE */
2022 HGLOBAL h = dde_get_pair( (HANDLE)uiHi );
2023 if (h)
2025 hpack = pack_ptr( h );
2026 /* send back the value of h on the other side */
2027 push_data( data, &hpack, sizeof(hpack) );
2028 lp = uiLo;
2029 TRACE( "send dde-ack %lx %08lx => %p\n", uiLo, uiHi, h );
2032 else
2034 /* uiHi should contain either an atom or 0 */
2035 TRACE( "send dde-ack %lx atom=%lx\n", uiLo, uiHi );
2036 lp = MAKELONG( uiLo, uiHi );
2038 break;
2039 case WM_DDE_ADVISE:
2040 case WM_DDE_DATA:
2041 case WM_DDE_POKE:
2042 size = 0;
2043 if (uiLo)
2045 size = GlobalSize( (HGLOBAL)uiLo ) ;
2046 if ((info->msg == WM_DDE_ADVISE && size < sizeof(DDEADVISE)) ||
2047 (info->msg == WM_DDE_DATA && size < FIELD_OFFSET(DDEDATA, Value)) ||
2048 (info->msg == WM_DDE_POKE && size < FIELD_OFFSET(DDEPOKE, Value))
2050 return FALSE;
2052 else if (info->msg != WM_DDE_DATA) return FALSE;
2054 lp = uiHi;
2055 if (uiLo)
2057 if ((ptr = GlobalLock( (HGLOBAL)uiLo) ))
2059 DDEDATA *dde_data = ptr;
2060 TRACE("unused %d, fResponse %d, fRelease %d, fDeferUpd %d, fAckReq %d, cfFormat %d\n",
2061 dde_data->unused, dde_data->fResponse, dde_data->fRelease,
2062 dde_data->reserved, dde_data->fAckReq, dde_data->cfFormat);
2063 push_data( data, ptr, size );
2064 hunlock = (HGLOBAL)uiLo;
2067 TRACE( "send ddepack %u %lx\n", size, uiHi );
2068 break;
2069 case WM_DDE_EXECUTE:
2070 if (info->lparam)
2072 if ((ptr = GlobalLock( (HGLOBAL)info->lparam) ))
2074 push_data(data, ptr, GlobalSize( (HGLOBAL)info->lparam ));
2075 /* so that the other side can send it back on ACK */
2076 lp = info->lparam;
2077 hunlock = (HGLOBAL)info->lparam;
2080 break;
2082 SERVER_START_REQ( send_message )
2084 req->id = info->dest_tid;
2085 req->type = info->type;
2086 req->flags = 0;
2087 req->win = wine_server_user_handle( info->hwnd );
2088 req->msg = info->msg;
2089 req->wparam = info->wparam;
2090 req->lparam = lp;
2091 req->timeout = TIMEOUT_INFINITE;
2092 for (i = 0; i < data->count; i++)
2093 wine_server_add_data( req, data->data[i], data->size[i] );
2094 if ((res = wine_server_call( req )))
2096 if (res == STATUS_INVALID_PARAMETER)
2097 /* FIXME: find a STATUS_ value for this one */
2098 SetLastError( ERROR_INVALID_THREAD_ID );
2099 else
2100 SetLastError( RtlNtStatusToDosError(res) );
2102 else
2103 FreeDDElParam(info->msg, info->lparam);
2105 SERVER_END_REQ;
2106 if (hunlock) GlobalUnlock(hunlock);
2108 return !res;
2111 /***********************************************************************
2112 * unpack_dde_message
2114 * Unpack a posted DDE message received from another process.
2116 static BOOL unpack_dde_message( HWND hwnd, UINT message, WPARAM *wparam, LPARAM *lparam,
2117 void **buffer, size_t size )
2119 UINT_PTR uiLo, uiHi;
2120 HGLOBAL hMem = 0;
2121 void* ptr;
2123 switch (message)
2125 case WM_DDE_ACK:
2126 if (size)
2128 ULONGLONG hpack;
2129 /* hMem is being passed */
2130 if (size != sizeof(hpack)) return FALSE;
2131 if (!buffer || !*buffer) return FALSE;
2132 uiLo = *lparam;
2133 memcpy( &hpack, *buffer, size );
2134 hMem = unpack_ptr( hpack );
2135 uiHi = (UINT_PTR)hMem;
2136 TRACE("recv dde-ack %lx mem=%lx[%lx]\n", uiLo, uiHi, GlobalSize( hMem ));
2138 else
2140 uiLo = LOWORD( *lparam );
2141 uiHi = HIWORD( *lparam );
2142 TRACE("recv dde-ack %lx atom=%lx\n", uiLo, uiHi);
2144 *lparam = PackDDElParam( WM_DDE_ACK, uiLo, uiHi );
2145 break;
2146 case WM_DDE_ADVISE:
2147 case WM_DDE_DATA:
2148 case WM_DDE_POKE:
2149 if ((!buffer || !*buffer) && message != WM_DDE_DATA) return FALSE;
2150 uiHi = *lparam;
2151 if (size)
2153 if (!(hMem = GlobalAlloc( GMEM_MOVEABLE|GMEM_DDESHARE, size )))
2154 return FALSE;
2155 if ((ptr = GlobalLock( hMem )))
2157 memcpy( ptr, *buffer, size );
2158 GlobalUnlock( hMem );
2160 else
2162 GlobalFree( hMem );
2163 return FALSE;
2166 uiLo = (UINT_PTR)hMem;
2168 *lparam = PackDDElParam( message, uiLo, uiHi );
2169 break;
2170 case WM_DDE_EXECUTE:
2171 if (size)
2173 if (!buffer || !*buffer) return FALSE;
2174 if (!(hMem = GlobalAlloc( GMEM_MOVEABLE|GMEM_DDESHARE, size ))) return FALSE;
2175 if ((ptr = GlobalLock( hMem )))
2177 memcpy( ptr, *buffer, size );
2178 GlobalUnlock( hMem );
2179 TRACE( "exec: pairing c=%08lx s=%p\n", *lparam, hMem );
2180 if (!dde_add_pair( (HGLOBAL)*lparam, hMem ))
2182 GlobalFree( hMem );
2183 return FALSE;
2186 else
2188 GlobalFree( hMem );
2189 return FALSE;
2191 } else return FALSE;
2192 *lparam = (LPARAM)hMem;
2193 break;
2195 return TRUE;
2198 /***********************************************************************
2199 * call_window_proc
2201 * Call a window procedure and the corresponding hooks.
2203 static LRESULT call_window_proc( HWND hwnd, UINT msg, WPARAM wparam, LPARAM lparam,
2204 BOOL unicode, BOOL same_thread, enum wm_char_mapping mapping )
2206 LRESULT result = 0;
2207 CWPSTRUCT cwp;
2208 CWPRETSTRUCT cwpret;
2210 if (msg & 0x80000000)
2212 result = handle_internal_message( hwnd, msg, wparam, lparam );
2213 goto done;
2216 /* first the WH_CALLWNDPROC hook */
2217 hwnd = WIN_GetFullHandle( hwnd );
2218 cwp.lParam = lparam;
2219 cwp.wParam = wparam;
2220 cwp.message = msg;
2221 cwp.hwnd = hwnd;
2222 HOOK_CallHooks( WH_CALLWNDPROC, HC_ACTION, same_thread, (LPARAM)&cwp, unicode );
2224 /* now call the window procedure */
2225 if (!WINPROC_call_window( hwnd, msg, wparam, lparam, &result, unicode, mapping )) goto done;
2227 /* and finally the WH_CALLWNDPROCRET hook */
2228 cwpret.lResult = result;
2229 cwpret.lParam = lparam;
2230 cwpret.wParam = wparam;
2231 cwpret.message = msg;
2232 cwpret.hwnd = hwnd;
2233 HOOK_CallHooks( WH_CALLWNDPROCRET, HC_ACTION, same_thread, (LPARAM)&cwpret, unicode );
2234 done:
2235 return result;
2239 /***********************************************************************
2240 * send_parent_notify
2242 * Send a WM_PARENTNOTIFY to all ancestors of the given window, unless
2243 * the window has the WS_EX_NOPARENTNOTIFY style.
2245 static void send_parent_notify( HWND hwnd, WORD event, WORD idChild, POINT pt )
2247 /* pt has to be in the client coordinates of the parent window */
2248 MapWindowPoints( 0, hwnd, &pt, 1 );
2249 for (;;)
2251 HWND parent;
2253 if (!(GetWindowLongW( hwnd, GWL_STYLE ) & WS_CHILD)) break;
2254 if (GetWindowLongW( hwnd, GWL_EXSTYLE ) & WS_EX_NOPARENTNOTIFY) break;
2255 if (!(parent = GetParent(hwnd))) break;
2256 if (parent == GetDesktopWindow()) break;
2257 MapWindowPoints( hwnd, parent, &pt, 1 );
2258 hwnd = parent;
2259 SendMessageW( hwnd, WM_PARENTNOTIFY,
2260 MAKEWPARAM( event, idChild ), MAKELPARAM( pt.x, pt.y ) );
2265 /***********************************************************************
2266 * accept_hardware_message
2268 * Tell the server we have passed the message to the app
2269 * (even though we may end up dropping it later on)
2271 static void accept_hardware_message( UINT hw_id, BOOL remove )
2273 SERVER_START_REQ( accept_hardware_message )
2275 req->hw_id = hw_id;
2276 req->remove = remove;
2277 if (wine_server_call( req ))
2278 FIXME("Failed to reply to MSG_HARDWARE message. Message may not be removed from queue.\n");
2280 SERVER_END_REQ;
2284 static BOOL process_rawinput_message( MSG *msg, const struct hardware_msg_data *msg_data )
2286 struct user_thread_info *thread_info = get_user_thread_info();
2287 RAWINPUT *rawinput = thread_info->rawinput;
2289 if (!rawinput)
2291 thread_info->rawinput = HeapAlloc( GetProcessHeap(), 0, sizeof(*rawinput) );
2292 if (!(rawinput = thread_info->rawinput)) return FALSE;
2295 rawinput->header.dwType = msg_data->rawinput.type;
2296 if (msg_data->rawinput.type == RIM_TYPEMOUSE)
2298 static const unsigned int button_flags[] =
2300 0, /* MOUSEEVENTF_MOVE */
2301 RI_MOUSE_LEFT_BUTTON_DOWN, /* MOUSEEVENTF_LEFTDOWN */
2302 RI_MOUSE_LEFT_BUTTON_UP, /* MOUSEEVENTF_LEFTUP */
2303 RI_MOUSE_RIGHT_BUTTON_DOWN, /* MOUSEEVENTF_RIGHTDOWN */
2304 RI_MOUSE_RIGHT_BUTTON_UP, /* MOUSEEVENTF_RIGHTUP */
2305 RI_MOUSE_MIDDLE_BUTTON_DOWN, /* MOUSEEVENTF_MIDDLEDOWN */
2306 RI_MOUSE_MIDDLE_BUTTON_UP, /* MOUSEEVENTF_MIDDLEUP */
2308 unsigned int i;
2310 rawinput->header.dwSize = FIELD_OFFSET(RAWINPUT, data) + sizeof(RAWMOUSE);
2311 rawinput->header.hDevice = WINE_MOUSE_HANDLE;
2312 rawinput->header.wParam = 0;
2314 rawinput->data.mouse.usFlags = MOUSE_MOVE_RELATIVE;
2315 rawinput->data.mouse.u.s.usButtonFlags = 0;
2316 rawinput->data.mouse.u.s.usButtonData = 0;
2317 for (i = 1; i < sizeof(button_flags) / sizeof(*button_flags); ++i)
2319 if (msg_data->flags & (1 << i))
2320 rawinput->data.mouse.u.s.usButtonFlags |= button_flags[i];
2322 if (msg_data->flags & MOUSEEVENTF_WHEEL)
2324 rawinput->data.mouse.u.s.usButtonFlags |= RI_MOUSE_WHEEL;
2325 rawinput->data.mouse.u.s.usButtonData = msg_data->rawinput.mouse.data;
2327 if (msg_data->flags & MOUSEEVENTF_HWHEEL)
2329 rawinput->data.mouse.u.s.usButtonFlags |= RI_MOUSE_HORIZONTAL_WHEEL;
2330 rawinput->data.mouse.u.s.usButtonData = msg_data->rawinput.mouse.data;
2332 if (msg_data->flags & MOUSEEVENTF_XDOWN)
2334 if (msg_data->rawinput.mouse.data == XBUTTON1)
2335 rawinput->data.mouse.u.s.usButtonFlags |= RI_MOUSE_BUTTON_4_DOWN;
2336 else if (msg_data->rawinput.mouse.data == XBUTTON2)
2337 rawinput->data.mouse.u.s.usButtonFlags |= RI_MOUSE_BUTTON_5_DOWN;
2339 if (msg_data->flags & MOUSEEVENTF_XUP)
2341 if (msg_data->rawinput.mouse.data == XBUTTON1)
2342 rawinput->data.mouse.u.s.usButtonFlags |= RI_MOUSE_BUTTON_4_UP;
2343 else if (msg_data->rawinput.mouse.data == XBUTTON2)
2344 rawinput->data.mouse.u.s.usButtonFlags |= RI_MOUSE_BUTTON_5_UP;
2347 rawinput->data.mouse.ulRawButtons = 0;
2348 rawinput->data.mouse.lLastX = msg_data->rawinput.mouse.x;
2349 rawinput->data.mouse.lLastY = msg_data->rawinput.mouse.y;
2350 rawinput->data.mouse.ulExtraInformation = msg_data->info;
2352 else if (msg_data->rawinput.type == RIM_TYPEKEYBOARD)
2354 rawinput->header.dwSize = FIELD_OFFSET(RAWINPUT, data) + sizeof(RAWKEYBOARD);
2355 rawinput->header.hDevice = WINE_KEYBOARD_HANDLE;
2356 rawinput->header.wParam = 0;
2358 rawinput->data.keyboard.MakeCode = msg_data->rawinput.kbd.scan;
2359 rawinput->data.keyboard.Flags = msg_data->flags & KEYEVENTF_KEYUP ? RI_KEY_BREAK : RI_KEY_MAKE;
2360 if (msg_data->flags & KEYEVENTF_EXTENDEDKEY) rawinput->data.keyboard.Flags |= RI_KEY_E0;
2361 rawinput->data.keyboard.Reserved = 0;
2363 switch (msg_data->rawinput.kbd.vkey)
2365 case VK_LSHIFT:
2366 case VK_RSHIFT:
2367 rawinput->data.keyboard.VKey = VK_SHIFT;
2368 rawinput->data.keyboard.Flags &= ~RI_KEY_E0;
2369 break;
2370 case VK_LCONTROL:
2371 case VK_RCONTROL:
2372 rawinput->data.keyboard.VKey = VK_CONTROL;
2373 break;
2374 case VK_LMENU:
2375 case VK_RMENU:
2376 rawinput->data.keyboard.VKey = VK_MENU;
2377 break;
2378 default:
2379 rawinput->data.keyboard.VKey = msg_data->rawinput.kbd.vkey;
2380 break;
2383 rawinput->data.keyboard.Message = msg_data->rawinput.kbd.message;
2384 rawinput->data.keyboard.ExtraInformation = msg_data->info;
2386 else
2388 FIXME("Unhandled rawinput type %#x.\n", msg_data->rawinput.type);
2389 return FALSE;
2392 msg->lParam = (LPARAM)rawinput;
2393 return TRUE;
2396 /***********************************************************************
2397 * process_keyboard_message
2399 * returns TRUE if the contents of 'msg' should be passed to the application
2401 static BOOL process_keyboard_message( MSG *msg, UINT hw_id, HWND hwnd_filter,
2402 UINT first, UINT last, BOOL remove )
2404 EVENTMSG event;
2406 if (msg->message == WM_KEYDOWN || msg->message == WM_SYSKEYDOWN ||
2407 msg->message == WM_KEYUP || msg->message == WM_SYSKEYUP)
2408 switch (msg->wParam)
2410 case VK_LSHIFT: case VK_RSHIFT:
2411 msg->wParam = VK_SHIFT;
2412 break;
2413 case VK_LCONTROL: case VK_RCONTROL:
2414 msg->wParam = VK_CONTROL;
2415 break;
2416 case VK_LMENU: case VK_RMENU:
2417 msg->wParam = VK_MENU;
2418 break;
2421 /* FIXME: is this really the right place for this hook? */
2422 event.message = msg->message;
2423 event.hwnd = msg->hwnd;
2424 event.time = msg->time;
2425 event.paramL = (msg->wParam & 0xFF) | (HIWORD(msg->lParam) << 8);
2426 event.paramH = msg->lParam & 0x7FFF;
2427 if (HIWORD(msg->lParam) & 0x0100) event.paramH |= 0x8000; /* special_key - bit */
2428 HOOK_CallHooks( WH_JOURNALRECORD, HC_ACTION, 0, (LPARAM)&event, TRUE );
2430 /* check message filters */
2431 if (msg->message < first || msg->message > last) return FALSE;
2432 if (!check_hwnd_filter( msg, hwnd_filter )) return FALSE;
2434 if (remove)
2436 if((msg->message == WM_KEYDOWN) &&
2437 (msg->hwnd != GetDesktopWindow()))
2439 /* Handle F1 key by sending out WM_HELP message */
2440 if (msg->wParam == VK_F1)
2442 PostMessageW( msg->hwnd, WM_KEYF1, 0, 0 );
2444 else if(msg->wParam >= VK_BROWSER_BACK &&
2445 msg->wParam <= VK_LAUNCH_APP2)
2447 /* FIXME: Process keystate */
2448 SendMessageW(msg->hwnd, WM_APPCOMMAND, (WPARAM)msg->hwnd, MAKELPARAM(0, (FAPPCOMMAND_KEY | (msg->wParam - VK_BROWSER_BACK + 1))));
2451 else if (msg->message == WM_KEYUP)
2453 /* Handle VK_APPS key by posting a WM_CONTEXTMENU message */
2454 if (msg->wParam == VK_APPS && !MENU_IsMenuActive())
2455 PostMessageW(msg->hwnd, WM_CONTEXTMENU, (WPARAM)msg->hwnd, -1);
2459 if (HOOK_CallHooks( WH_KEYBOARD, remove ? HC_ACTION : HC_NOREMOVE,
2460 LOWORD(msg->wParam), msg->lParam, TRUE ))
2462 /* skip this message */
2463 HOOK_CallHooks( WH_CBT, HCBT_KEYSKIPPED, LOWORD(msg->wParam), msg->lParam, TRUE );
2464 accept_hardware_message( hw_id, TRUE );
2465 return FALSE;
2467 accept_hardware_message( hw_id, remove );
2469 if ( remove && msg->message == WM_KEYDOWN )
2470 if (ImmProcessKey(msg->hwnd, GetKeyboardLayout(0), msg->wParam, msg->lParam, 0) )
2471 msg->wParam = VK_PROCESSKEY;
2473 return TRUE;
2477 /***********************************************************************
2478 * process_mouse_message
2480 * returns TRUE if the contents of 'msg' should be passed to the application
2482 static BOOL process_mouse_message( MSG *msg, UINT hw_id, ULONG_PTR extra_info, HWND hwnd_filter,
2483 UINT first, UINT last, BOOL remove )
2485 static MSG clk_msg;
2487 POINT pt;
2488 UINT message;
2489 INT hittest;
2490 EVENTMSG event;
2491 GUITHREADINFO info;
2492 MOUSEHOOKSTRUCT hook;
2493 BOOL eatMsg;
2495 /* find the window to dispatch this mouse message to */
2497 info.cbSize = sizeof(info);
2498 GetGUIThreadInfo( GetCurrentThreadId(), &info );
2499 if (info.hwndCapture)
2501 hittest = HTCLIENT;
2502 msg->hwnd = info.hwndCapture;
2504 else
2506 msg->hwnd = WINPOS_WindowFromPoint( msg->hwnd, msg->pt, &hittest );
2509 if (!msg->hwnd || !WIN_IsCurrentThread( msg->hwnd ))
2511 accept_hardware_message( hw_id, TRUE );
2512 return FALSE;
2515 /* FIXME: is this really the right place for this hook? */
2516 event.message = msg->message;
2517 event.time = msg->time;
2518 event.hwnd = msg->hwnd;
2519 event.paramL = msg->pt.x;
2520 event.paramH = msg->pt.y;
2521 HOOK_CallHooks( WH_JOURNALRECORD, HC_ACTION, 0, (LPARAM)&event, TRUE );
2523 if (!check_hwnd_filter( msg, hwnd_filter )) return FALSE;
2525 pt = msg->pt;
2526 message = msg->message;
2527 /* Note: windows has no concept of a non-client wheel message */
2528 if (message != WM_MOUSEWHEEL)
2530 if (hittest != HTCLIENT)
2532 message += WM_NCMOUSEMOVE - WM_MOUSEMOVE;
2533 msg->wParam = hittest;
2535 else
2537 /* coordinates don't get translated while tracking a menu */
2538 /* FIXME: should differentiate popups and top-level menus */
2539 if (!(info.flags & GUI_INMENUMODE))
2540 ScreenToClient( msg->hwnd, &pt );
2543 msg->lParam = MAKELONG( pt.x, pt.y );
2545 /* translate double clicks */
2547 if ((msg->message == WM_LBUTTONDOWN) ||
2548 (msg->message == WM_RBUTTONDOWN) ||
2549 (msg->message == WM_MBUTTONDOWN) ||
2550 (msg->message == WM_XBUTTONDOWN))
2552 BOOL update = remove;
2554 /* translate double clicks -
2555 * note that ...MOUSEMOVEs can slip in between
2556 * ...BUTTONDOWN and ...BUTTONDBLCLK messages */
2558 if ((info.flags & (GUI_INMENUMODE|GUI_INMOVESIZE)) ||
2559 hittest != HTCLIENT ||
2560 (GetClassLongA( msg->hwnd, GCL_STYLE ) & CS_DBLCLKS))
2562 if ((msg->message == clk_msg.message) &&
2563 (msg->hwnd == clk_msg.hwnd) &&
2564 (msg->wParam == clk_msg.wParam) &&
2565 (msg->time - clk_msg.time < GetDoubleClickTime()) &&
2566 (abs(msg->pt.x - clk_msg.pt.x) < GetSystemMetrics(SM_CXDOUBLECLK)/2) &&
2567 (abs(msg->pt.y - clk_msg.pt.y) < GetSystemMetrics(SM_CYDOUBLECLK)/2))
2569 message += (WM_LBUTTONDBLCLK - WM_LBUTTONDOWN);
2570 if (update)
2572 clk_msg.message = 0; /* clear the double click conditions */
2573 update = FALSE;
2577 if (message < first || message > last) return FALSE;
2578 /* update static double click conditions */
2579 if (update) clk_msg = *msg;
2581 else
2583 if (message < first || message > last) return FALSE;
2586 /* message is accepted now (but may still get dropped) */
2588 hook.pt = msg->pt;
2589 hook.hwnd = msg->hwnd;
2590 hook.wHitTestCode = hittest;
2591 hook.dwExtraInfo = extra_info;
2592 if (HOOK_CallHooks( WH_MOUSE, remove ? HC_ACTION : HC_NOREMOVE,
2593 message, (LPARAM)&hook, TRUE ))
2595 hook.pt = msg->pt;
2596 hook.hwnd = msg->hwnd;
2597 hook.wHitTestCode = hittest;
2598 hook.dwExtraInfo = extra_info;
2599 HOOK_CallHooks( WH_CBT, HCBT_CLICKSKIPPED, message, (LPARAM)&hook, TRUE );
2600 accept_hardware_message( hw_id, TRUE );
2601 return FALSE;
2604 if ((hittest == HTERROR) || (hittest == HTNOWHERE))
2606 SendMessageW( msg->hwnd, WM_SETCURSOR, (WPARAM)msg->hwnd,
2607 MAKELONG( hittest, msg->message ));
2608 accept_hardware_message( hw_id, TRUE );
2609 return FALSE;
2612 accept_hardware_message( hw_id, remove );
2614 if (!remove || info.hwndCapture)
2616 msg->message = message;
2617 return TRUE;
2620 eatMsg = FALSE;
2622 if ((msg->message == WM_LBUTTONDOWN) ||
2623 (msg->message == WM_RBUTTONDOWN) ||
2624 (msg->message == WM_MBUTTONDOWN) ||
2625 (msg->message == WM_XBUTTONDOWN))
2627 /* Send the WM_PARENTNOTIFY,
2628 * note that even for double/nonclient clicks
2629 * notification message is still WM_L/M/RBUTTONDOWN.
2631 send_parent_notify( msg->hwnd, msg->message, 0, msg->pt );
2633 /* Activate the window if needed */
2635 if (msg->hwnd != info.hwndActive)
2637 HWND hwndTop = msg->hwnd;
2638 while (hwndTop)
2640 if ((GetWindowLongW( hwndTop, GWL_STYLE ) & (WS_POPUP|WS_CHILD)) != WS_CHILD) break;
2641 hwndTop = GetParent( hwndTop );
2644 if (hwndTop && hwndTop != GetDesktopWindow())
2646 LONG ret = SendMessageW( msg->hwnd, WM_MOUSEACTIVATE, (WPARAM)hwndTop,
2647 MAKELONG( hittest, msg->message ) );
2648 switch(ret)
2650 case MA_NOACTIVATEANDEAT:
2651 eatMsg = TRUE;
2652 /* fall through */
2653 case MA_NOACTIVATE:
2654 break;
2655 case MA_ACTIVATEANDEAT:
2656 eatMsg = TRUE;
2657 /* fall through */
2658 case MA_ACTIVATE:
2659 case 0:
2660 if (!FOCUS_MouseActivate( hwndTop )) eatMsg = TRUE;
2661 break;
2662 default:
2663 WARN( "unknown WM_MOUSEACTIVATE code %d\n", ret );
2664 break;
2670 /* send the WM_SETCURSOR message */
2672 /* Windows sends the normal mouse message as the message parameter
2673 in the WM_SETCURSOR message even if it's non-client mouse message */
2674 SendMessageW( msg->hwnd, WM_SETCURSOR, (WPARAM)msg->hwnd, MAKELONG( hittest, msg->message ));
2676 msg->message = message;
2677 return !eatMsg;
2681 /***********************************************************************
2682 * process_hardware_message
2684 * Process a hardware message; return TRUE if message should be passed on to the app
2686 static BOOL process_hardware_message( MSG *msg, UINT hw_id, const struct hardware_msg_data *msg_data,
2687 HWND hwnd_filter, UINT first, UINT last, BOOL remove )
2689 if (msg->message == WM_INPUT)
2690 return process_rawinput_message( msg, msg_data );
2692 if (is_keyboard_message( msg->message ))
2693 return process_keyboard_message( msg, hw_id, hwnd_filter, first, last, remove );
2695 if (is_mouse_message( msg->message ))
2696 return process_mouse_message( msg, hw_id, msg_data->info, hwnd_filter, first, last, remove );
2698 ERR( "unknown message type %x\n", msg->message );
2699 return FALSE;
2703 /***********************************************************************
2704 * call_sendmsg_callback
2706 * Call the callback function of SendMessageCallback.
2708 static inline void call_sendmsg_callback( SENDASYNCPROC callback, HWND hwnd, UINT msg,
2709 ULONG_PTR data, LRESULT result )
2711 if (!callback) return;
2713 if (TRACE_ON(relay))
2714 DPRINTF( "%04x:Call message callback %p (hwnd=%p,msg=%s,data=%08lx,result=%08lx)\n",
2715 GetCurrentThreadId(), callback, hwnd, SPY_GetMsgName( msg, hwnd ),
2716 data, result );
2717 callback( hwnd, msg, data, result );
2718 if (TRACE_ON(relay))
2719 DPRINTF( "%04x:Ret message callback %p (hwnd=%p,msg=%s,data=%08lx,result=%08lx)\n",
2720 GetCurrentThreadId(), callback, hwnd, SPY_GetMsgName( msg, hwnd ),
2721 data, result );
2725 /***********************************************************************
2726 * peek_message
2728 * Peek for a message matching the given parameters. Return FALSE if none available.
2729 * All pending sent messages are processed before returning.
2731 static BOOL peek_message( MSG *msg, HWND hwnd, UINT first, UINT last, UINT flags, UINT changed_mask )
2733 LRESULT result;
2734 struct user_thread_info *thread_info = get_user_thread_info();
2735 struct received_message_info info, *old_info;
2736 unsigned int hw_id = 0; /* id of previous hardware message */
2737 void *buffer;
2738 size_t buffer_size = 256;
2740 if (!(buffer = HeapAlloc( GetProcessHeap(), 0, buffer_size ))) return FALSE;
2742 if (!first && !last) last = ~0;
2743 if (hwnd == HWND_BROADCAST) hwnd = HWND_TOPMOST;
2745 for (;;)
2747 NTSTATUS res;
2748 size_t size = 0;
2749 const message_data_t *msg_data = buffer;
2751 SERVER_START_REQ( get_message )
2753 req->flags = flags;
2754 req->get_win = wine_server_user_handle( hwnd );
2755 req->get_first = first;
2756 req->get_last = last;
2757 req->hw_id = hw_id;
2758 req->wake_mask = changed_mask & (QS_SENDMESSAGE | QS_SMRESULT);
2759 req->changed_mask = changed_mask;
2760 wine_server_set_reply( req, buffer, buffer_size );
2761 if (!(res = wine_server_call( req )))
2763 size = wine_server_reply_size( reply );
2764 info.type = reply->type;
2765 info.msg.hwnd = wine_server_ptr_handle( reply->win );
2766 info.msg.message = reply->msg;
2767 info.msg.wParam = reply->wparam;
2768 info.msg.lParam = reply->lparam;
2769 info.msg.time = reply->time;
2770 info.msg.pt.x = reply->x;
2771 info.msg.pt.y = reply->y;
2772 hw_id = 0;
2773 thread_info->active_hooks = reply->active_hooks;
2775 else buffer_size = reply->total;
2777 SERVER_END_REQ;
2779 if (res)
2781 HeapFree( GetProcessHeap(), 0, buffer );
2782 if (res == STATUS_PENDING)
2784 thread_info->wake_mask = changed_mask & (QS_SENDMESSAGE | QS_SMRESULT);
2785 thread_info->changed_mask = changed_mask;
2787 if (res != STATUS_BUFFER_OVERFLOW) return FALSE;
2788 if (!(buffer = HeapAlloc( GetProcessHeap(), 0, buffer_size ))) return FALSE;
2789 continue;
2792 TRACE( "got type %d msg %x (%s) hwnd %p wp %lx lp %lx\n",
2793 info.type, info.msg.message,
2794 (info.type == MSG_WINEVENT) ? "MSG_WINEVENT" : SPY_GetMsgName(info.msg.message, info.msg.hwnd),
2795 info.msg.hwnd, info.msg.wParam, info.msg.lParam );
2797 switch(info.type)
2799 case MSG_ASCII:
2800 case MSG_UNICODE:
2801 info.flags = ISMEX_SEND;
2802 break;
2803 case MSG_NOTIFY:
2804 info.flags = ISMEX_NOTIFY;
2805 break;
2806 case MSG_CALLBACK:
2807 info.flags = ISMEX_CALLBACK;
2808 break;
2809 case MSG_CALLBACK_RESULT:
2810 if (size >= sizeof(msg_data->callback))
2811 call_sendmsg_callback( wine_server_get_ptr(msg_data->callback.callback),
2812 info.msg.hwnd, info.msg.message,
2813 msg_data->callback.data, msg_data->callback.result );
2814 continue;
2815 case MSG_WINEVENT:
2816 if (size >= sizeof(msg_data->winevent))
2818 WINEVENTPROC hook_proc;
2819 HMODULE free_module = 0;
2821 hook_proc = wine_server_get_ptr( msg_data->winevent.hook_proc );
2822 size -= sizeof(msg_data->winevent);
2823 if (size)
2825 WCHAR module[MAX_PATH];
2827 size = min( size, (MAX_PATH - 1) * sizeof(WCHAR) );
2828 memcpy( module, &msg_data->winevent + 1, size );
2829 module[size / sizeof(WCHAR)] = 0;
2830 if (!(hook_proc = get_hook_proc( hook_proc, module, &free_module )))
2832 ERR( "invalid winevent hook module name %s\n", debugstr_w(module) );
2833 continue;
2837 if (TRACE_ON(relay))
2838 DPRINTF( "%04x:Call winevent proc %p (hook=%04x,event=%x,hwnd=%p,object_id=%lx,child_id=%lx,tid=%04x,time=%x)\n",
2839 GetCurrentThreadId(), hook_proc,
2840 msg_data->winevent.hook, info.msg.message, info.msg.hwnd, info.msg.wParam,
2841 info.msg.lParam, msg_data->winevent.tid, info.msg.time);
2843 hook_proc( wine_server_ptr_handle( msg_data->winevent.hook ), info.msg.message,
2844 info.msg.hwnd, info.msg.wParam, info.msg.lParam,
2845 msg_data->winevent.tid, info.msg.time );
2847 if (TRACE_ON(relay))
2848 DPRINTF( "%04x:Ret winevent proc %p (hook=%04x,event=%x,hwnd=%p,object_id=%lx,child_id=%lx,tid=%04x,time=%x)\n",
2849 GetCurrentThreadId(), hook_proc,
2850 msg_data->winevent.hook, info.msg.message, info.msg.hwnd, info.msg.wParam,
2851 info.msg.lParam, msg_data->winevent.tid, info.msg.time);
2853 if (free_module) FreeLibrary(free_module);
2855 continue;
2856 case MSG_HOOK_LL:
2857 info.flags = ISMEX_SEND;
2858 result = 0;
2859 if (info.msg.message == WH_KEYBOARD_LL && size >= sizeof(msg_data->hardware))
2861 KBDLLHOOKSTRUCT hook;
2863 hook.vkCode = LOWORD( info.msg.lParam );
2864 hook.scanCode = HIWORD( info.msg.lParam );
2865 hook.flags = msg_data->hardware.flags;
2866 hook.time = info.msg.time;
2867 hook.dwExtraInfo = msg_data->hardware.info;
2868 TRACE( "calling keyboard LL hook vk %x scan %x flags %x time %u info %lx\n",
2869 hook.vkCode, hook.scanCode, hook.flags, hook.time, hook.dwExtraInfo );
2870 result = HOOK_CallHooks( WH_KEYBOARD_LL, HC_ACTION, info.msg.wParam, (LPARAM)&hook, TRUE );
2872 else if (info.msg.message == WH_MOUSE_LL && size >= sizeof(msg_data->hardware))
2874 MSLLHOOKSTRUCT hook;
2876 hook.pt = info.msg.pt;
2877 hook.mouseData = info.msg.lParam;
2878 hook.flags = msg_data->hardware.flags;
2879 hook.time = info.msg.time;
2880 hook.dwExtraInfo = msg_data->hardware.info;
2881 TRACE( "calling mouse LL hook pos %d,%d data %x flags %x time %u info %lx\n",
2882 hook.pt.x, hook.pt.y, hook.mouseData, hook.flags, hook.time, hook.dwExtraInfo );
2883 result = HOOK_CallHooks( WH_MOUSE_LL, HC_ACTION, info.msg.wParam, (LPARAM)&hook, TRUE );
2885 reply_message( &info, result, TRUE );
2886 continue;
2887 case MSG_OTHER_PROCESS:
2888 info.flags = ISMEX_SEND;
2889 if (!unpack_message( info.msg.hwnd, info.msg.message, &info.msg.wParam,
2890 &info.msg.lParam, &buffer, size ))
2892 /* ignore it */
2893 reply_message( &info, 0, TRUE );
2894 continue;
2896 break;
2897 case MSG_HARDWARE:
2898 if (size >= sizeof(msg_data->hardware))
2900 hw_id = msg_data->hardware.hw_id;
2901 if (!process_hardware_message( &info.msg, hw_id, &msg_data->hardware,
2902 hwnd, first, last, flags & PM_REMOVE ))
2904 TRACE("dropping msg %x\n", info.msg.message );
2905 continue; /* ignore it */
2907 *msg = info.msg;
2908 thread_info->GetMessagePosVal = MAKELONG( info.msg.pt.x, info.msg.pt.y );
2909 thread_info->GetMessageTimeVal = info.msg.time;
2910 thread_info->GetMessageExtraInfoVal = msg_data->hardware.info;
2911 HeapFree( GetProcessHeap(), 0, buffer );
2912 HOOK_CallHooks( WH_GETMESSAGE, HC_ACTION, flags & PM_REMOVE, (LPARAM)msg, TRUE );
2913 return TRUE;
2915 continue;
2916 case MSG_POSTED:
2917 if (info.msg.message & 0x80000000) /* internal message */
2919 if (flags & PM_REMOVE)
2921 handle_internal_message( info.msg.hwnd, info.msg.message,
2922 info.msg.wParam, info.msg.lParam );
2923 /* if this is a nested call return right away */
2924 if (first == info.msg.message && last == info.msg.message)
2926 HeapFree( GetProcessHeap(), 0, buffer );
2927 return FALSE;
2930 else
2931 peek_message( msg, info.msg.hwnd, info.msg.message,
2932 info.msg.message, flags | PM_REMOVE, changed_mask );
2933 continue;
2935 if (info.msg.message >= WM_DDE_FIRST && info.msg.message <= WM_DDE_LAST)
2937 if (!unpack_dde_message( info.msg.hwnd, info.msg.message, &info.msg.wParam,
2938 &info.msg.lParam, &buffer, size ))
2939 continue; /* ignore it */
2941 *msg = info.msg;
2942 thread_info->GetMessagePosVal = MAKELONG( info.msg.pt.x, info.msg.pt.y );
2943 thread_info->GetMessageTimeVal = info.msg.time;
2944 thread_info->GetMessageExtraInfoVal = 0;
2945 HeapFree( GetProcessHeap(), 0, buffer );
2946 HOOK_CallHooks( WH_GETMESSAGE, HC_ACTION, flags & PM_REMOVE, (LPARAM)msg, TRUE );
2947 return TRUE;
2950 /* if we get here, we have a sent message; call the window procedure */
2951 old_info = thread_info->receive_info;
2952 thread_info->receive_info = &info;
2953 result = call_window_proc( info.msg.hwnd, info.msg.message, info.msg.wParam,
2954 info.msg.lParam, (info.type != MSG_ASCII), FALSE,
2955 WMCHAR_MAP_RECVMESSAGE );
2956 reply_message( &info, result, TRUE );
2957 thread_info->receive_info = old_info;
2959 /* if some PM_QS* flags were specified, only handle sent messages from now on */
2960 if (HIWORD(flags) && !changed_mask) flags = PM_QS_SENDMESSAGE | LOWORD(flags);
2965 /***********************************************************************
2966 * process_sent_messages
2968 * Process all pending sent messages.
2970 static inline void process_sent_messages(void)
2972 MSG msg;
2973 peek_message( &msg, 0, 0, 0, PM_REMOVE | PM_QS_SENDMESSAGE, 0 );
2977 /***********************************************************************
2978 * get_server_queue_handle
2980 * Get a handle to the server message queue for the current thread.
2982 static HANDLE get_server_queue_handle(void)
2984 struct user_thread_info *thread_info = get_user_thread_info();
2985 HANDLE ret;
2987 if (!(ret = thread_info->server_queue))
2989 SERVER_START_REQ( get_msg_queue )
2991 wine_server_call( req );
2992 ret = wine_server_ptr_handle( reply->handle );
2994 SERVER_END_REQ;
2995 thread_info->server_queue = ret;
2996 if (!ret) ERR( "Cannot get server thread queue\n" );
2998 return ret;
3002 /***********************************************************************
3003 * wait_message_reply
3005 * Wait until a sent message gets replied to.
3007 static void wait_message_reply( UINT flags )
3009 struct user_thread_info *thread_info = get_user_thread_info();
3010 HANDLE server_queue = get_server_queue_handle();
3011 unsigned int wake_mask = QS_SMRESULT | ((flags & SMTO_BLOCK) ? 0 : QS_SENDMESSAGE);
3013 for (;;)
3015 unsigned int wake_bits = 0;
3017 SERVER_START_REQ( set_queue_mask )
3019 req->wake_mask = wake_mask;
3020 req->changed_mask = wake_mask;
3021 req->skip_wait = 1;
3022 if (!wine_server_call( req )) wake_bits = reply->wake_bits & wake_mask;
3024 SERVER_END_REQ;
3026 thread_info->wake_mask = thread_info->changed_mask = 0;
3028 if (wake_bits & QS_SMRESULT) return; /* got a result */
3029 if (wake_bits & QS_SENDMESSAGE)
3031 /* Process the sent message immediately */
3032 process_sent_messages();
3033 continue;
3036 wow_handlers.wait_message( 1, &server_queue, INFINITE, wake_mask, 0 );
3041 /***********************************************************************
3042 * wait_objects
3044 * Wait for multiple objects including the server queue, with specific queue masks.
3046 static DWORD wait_objects( DWORD count, const HANDLE *handles, DWORD timeout,
3047 DWORD wake_mask, DWORD changed_mask, DWORD flags )
3049 struct user_thread_info *thread_info = get_user_thread_info();
3050 DWORD ret;
3052 assert( count ); /* we must have at least the server queue */
3054 flush_window_surfaces( TRUE );
3056 if (thread_info->wake_mask != wake_mask || thread_info->changed_mask != changed_mask)
3058 SERVER_START_REQ( set_queue_mask )
3060 req->wake_mask = wake_mask;
3061 req->changed_mask = changed_mask;
3062 req->skip_wait = 0;
3063 wine_server_call( req );
3065 SERVER_END_REQ;
3066 thread_info->wake_mask = wake_mask;
3067 thread_info->changed_mask = changed_mask;
3070 ret = wow_handlers.wait_message( count, handles, timeout, changed_mask, flags );
3072 if (ret != WAIT_TIMEOUT) thread_info->wake_mask = thread_info->changed_mask = 0;
3073 return ret;
3077 /***********************************************************************
3078 * put_message_in_queue
3080 * Put a sent message into the destination queue.
3081 * For inter-process message, reply_size is set to expected size of reply data.
3083 static BOOL put_message_in_queue( const struct send_message_info *info, size_t *reply_size )
3085 struct packed_message data;
3086 message_data_t msg_data;
3087 unsigned int res;
3088 int i;
3089 timeout_t timeout = TIMEOUT_INFINITE;
3091 /* Check for INFINITE timeout for compatibility with Win9x,
3092 * although Windows >= NT does not do so
3094 if (info->type != MSG_NOTIFY &&
3095 info->type != MSG_CALLBACK &&
3096 info->type != MSG_POSTED &&
3097 info->timeout &&
3098 info->timeout != INFINITE)
3100 /* timeout is signed despite the prototype */
3101 timeout = (timeout_t)max( 0, (int)info->timeout ) * -10000;
3104 memset( &data, 0, sizeof(data) );
3105 if (info->type == MSG_OTHER_PROCESS)
3107 *reply_size = pack_message( info->hwnd, info->msg, info->wparam, info->lparam, &data );
3108 if (data.count == -1)
3110 WARN( "cannot pack message %x\n", info->msg );
3111 return FALSE;
3114 else if (info->type == MSG_CALLBACK)
3116 msg_data.callback.callback = wine_server_client_ptr( info->callback );
3117 msg_data.callback.data = info->data;
3118 msg_data.callback.result = 0;
3119 data.data[0] = &msg_data;
3120 data.size[0] = sizeof(msg_data.callback);
3121 data.count = 1;
3123 else if (info->type == MSG_POSTED && info->msg >= WM_DDE_FIRST && info->msg <= WM_DDE_LAST)
3125 return post_dde_message( &data, info );
3128 SERVER_START_REQ( send_message )
3130 req->id = info->dest_tid;
3131 req->type = info->type;
3132 req->flags = 0;
3133 req->win = wine_server_user_handle( info->hwnd );
3134 req->msg = info->msg;
3135 req->wparam = info->wparam;
3136 req->lparam = info->lparam;
3137 req->timeout = timeout;
3139 if (info->flags & SMTO_ABORTIFHUNG) req->flags |= SEND_MSG_ABORT_IF_HUNG;
3140 for (i = 0; i < data.count; i++) wine_server_add_data( req, data.data[i], data.size[i] );
3141 if ((res = wine_server_call( req )))
3143 if (res == STATUS_INVALID_PARAMETER)
3144 /* FIXME: find a STATUS_ value for this one */
3145 SetLastError( ERROR_INVALID_THREAD_ID );
3146 else
3147 SetLastError( RtlNtStatusToDosError(res) );
3150 SERVER_END_REQ;
3151 return !res;
3155 /***********************************************************************
3156 * retrieve_reply
3158 * Retrieve a message reply from the server.
3160 static LRESULT retrieve_reply( const struct send_message_info *info,
3161 size_t reply_size, LRESULT *result )
3163 NTSTATUS status;
3164 void *reply_data = NULL;
3166 if (reply_size)
3168 if (!(reply_data = HeapAlloc( GetProcessHeap(), 0, reply_size )))
3170 WARN( "no memory for reply, will be truncated\n" );
3171 reply_size = 0;
3174 SERVER_START_REQ( get_message_reply )
3176 req->cancel = 1;
3177 if (reply_size) wine_server_set_reply( req, reply_data, reply_size );
3178 if (!(status = wine_server_call( req ))) *result = reply->result;
3179 reply_size = wine_server_reply_size( reply );
3181 SERVER_END_REQ;
3182 if (!status && reply_size)
3183 unpack_reply( info->hwnd, info->msg, info->wparam, info->lparam, reply_data, reply_size );
3185 HeapFree( GetProcessHeap(), 0, reply_data );
3187 TRACE( "hwnd %p msg %x (%s) wp %lx lp %lx got reply %lx (err=%d)\n",
3188 info->hwnd, info->msg, SPY_GetMsgName(info->msg, info->hwnd), info->wparam,
3189 info->lparam, *result, status );
3191 /* MSDN states that last error is 0 on timeout, but at least NT4 returns ERROR_TIMEOUT */
3192 if (status) SetLastError( RtlNtStatusToDosError(status) );
3193 return !status;
3197 /***********************************************************************
3198 * send_inter_thread_message
3200 static LRESULT send_inter_thread_message( const struct send_message_info *info, LRESULT *res_ptr )
3202 size_t reply_size = 0;
3204 TRACE( "hwnd %p msg %x (%s) wp %lx lp %lx\n",
3205 info->hwnd, info->msg, SPY_GetMsgName(info->msg, info->hwnd), info->wparam, info->lparam );
3207 USER_CheckNotLock();
3209 if (!put_message_in_queue( info, &reply_size )) return 0;
3211 /* there's no reply to wait for on notify/callback messages */
3212 if (info->type == MSG_NOTIFY || info->type == MSG_CALLBACK) return 1;
3214 wait_message_reply( info->flags );
3215 return retrieve_reply( info, reply_size, res_ptr );
3219 /***********************************************************************
3220 * send_inter_thread_callback
3222 static LRESULT send_inter_thread_callback( HWND hwnd, UINT msg, WPARAM wp, LPARAM lp,
3223 LRESULT *result, void *arg )
3225 struct send_message_info *info = arg;
3226 info->hwnd = hwnd;
3227 info->msg = msg;
3228 info->wparam = wp;
3229 info->lparam = lp;
3230 return send_inter_thread_message( info, result );
3234 /***********************************************************************
3235 * send_message
3237 * Backend implementation of the various SendMessage functions.
3239 static BOOL send_message( struct send_message_info *info, DWORD_PTR *res_ptr, BOOL unicode )
3241 DWORD dest_pid;
3242 BOOL ret;
3243 LRESULT result;
3245 if (is_broadcast(info->hwnd))
3247 EnumWindows( broadcast_message_callback, (LPARAM)info );
3248 if (res_ptr) *res_ptr = 1;
3249 return TRUE;
3252 if (!(info->dest_tid = GetWindowThreadProcessId( info->hwnd, &dest_pid ))) return FALSE;
3254 if (USER_IsExitingThread( info->dest_tid )) return FALSE;
3256 SPY_EnterMessage( SPY_SENDMESSAGE, info->hwnd, info->msg, info->wparam, info->lparam );
3258 if (info->dest_tid == GetCurrentThreadId())
3260 result = call_window_proc( info->hwnd, info->msg, info->wparam, info->lparam,
3261 unicode, TRUE, info->wm_char );
3262 if (info->type == MSG_CALLBACK)
3263 call_sendmsg_callback( info->callback, info->hwnd, info->msg, info->data, result );
3264 ret = TRUE;
3266 else
3268 if (dest_pid != GetCurrentProcessId() && (info->type == MSG_ASCII || info->type == MSG_UNICODE))
3269 info->type = MSG_OTHER_PROCESS;
3271 /* MSG_ASCII can be sent unconverted except for WM_CHAR; everything else needs to be Unicode */
3272 if (!unicode && is_unicode_message( info->msg ) &&
3273 (info->type != MSG_ASCII || info->msg == WM_CHAR))
3274 ret = WINPROC_CallProcAtoW( send_inter_thread_callback, info->hwnd, info->msg,
3275 info->wparam, info->lparam, &result, info, info->wm_char );
3276 else
3277 ret = send_inter_thread_message( info, &result );
3280 SPY_ExitMessage( SPY_RESULT_OK, info->hwnd, info->msg, result, info->wparam, info->lparam );
3281 if (ret && res_ptr) *res_ptr = result;
3282 return ret;
3286 /***********************************************************************
3287 * send_hardware_message
3289 NTSTATUS send_hardware_message( HWND hwnd, const INPUT *input, UINT flags )
3291 struct user_key_state_info *key_state_info = get_user_thread_info()->key_state;
3292 struct send_message_info info;
3293 int prev_x, prev_y, new_x, new_y;
3294 INT counter = global_key_state_counter;
3295 NTSTATUS ret;
3296 BOOL wait;
3298 info.type = MSG_HARDWARE;
3299 info.dest_tid = 0;
3300 info.hwnd = hwnd;
3301 info.flags = 0;
3302 info.timeout = 0;
3304 SERVER_START_REQ( send_hardware_message )
3306 req->win = wine_server_user_handle( hwnd );
3307 req->flags = flags;
3308 req->input.type = input->type;
3309 switch (input->type)
3311 case INPUT_MOUSE:
3312 req->input.mouse.x = input->u.mi.dx;
3313 req->input.mouse.y = input->u.mi.dy;
3314 req->input.mouse.data = input->u.mi.mouseData;
3315 req->input.mouse.flags = input->u.mi.dwFlags;
3316 req->input.mouse.time = input->u.mi.time;
3317 req->input.mouse.info = input->u.mi.dwExtraInfo;
3318 break;
3319 case INPUT_KEYBOARD:
3320 req->input.kbd.vkey = input->u.ki.wVk;
3321 req->input.kbd.scan = input->u.ki.wScan;
3322 req->input.kbd.flags = input->u.ki.dwFlags;
3323 req->input.kbd.time = input->u.ki.time;
3324 req->input.kbd.info = input->u.ki.dwExtraInfo;
3325 break;
3326 case INPUT_HARDWARE:
3327 req->input.hw.msg = input->u.hi.uMsg;
3328 req->input.hw.lparam = MAKELONG( input->u.hi.wParamL, input->u.hi.wParamH );
3329 break;
3331 if (key_state_info) wine_server_set_reply( req, key_state_info->state,
3332 sizeof(key_state_info->state) );
3333 ret = wine_server_call( req );
3334 wait = reply->wait;
3335 prev_x = reply->prev_x;
3336 prev_y = reply->prev_y;
3337 new_x = reply->new_x;
3338 new_y = reply->new_y;
3340 SERVER_END_REQ;
3342 if (!ret)
3344 if (key_state_info)
3346 key_state_info->time = GetTickCount();
3347 key_state_info->counter = counter;
3349 if ((flags & SEND_HWMSG_INJECTED) && (prev_x != new_x || prev_y != new_y))
3350 USER_Driver->pSetCursorPos( new_x, new_y );
3353 if (wait)
3355 LRESULT ignored;
3356 wait_message_reply( 0 );
3357 retrieve_reply( &info, 0, &ignored );
3359 return ret;
3363 /***********************************************************************
3364 * MSG_SendInternalMessageTimeout
3366 * Same as SendMessageTimeoutW but sends the message to a specific thread
3367 * without requiring a window handle. Only works for internal Wine messages.
3369 LRESULT MSG_SendInternalMessageTimeout( DWORD dest_pid, DWORD dest_tid,
3370 UINT msg, WPARAM wparam, LPARAM lparam,
3371 UINT flags, UINT timeout, PDWORD_PTR res_ptr )
3373 struct send_message_info info;
3374 LRESULT ret, result;
3376 assert( msg & 0x80000000 ); /* must be an internal Wine message */
3378 info.type = MSG_UNICODE;
3379 info.dest_tid = dest_tid;
3380 info.hwnd = 0;
3381 info.msg = msg;
3382 info.wparam = wparam;
3383 info.lparam = lparam;
3384 info.flags = flags;
3385 info.timeout = timeout;
3387 if (USER_IsExitingThread( dest_tid )) return 0;
3389 if (dest_tid == GetCurrentThreadId())
3391 result = handle_internal_message( 0, msg, wparam, lparam );
3392 ret = 1;
3394 else
3396 if (dest_pid != GetCurrentProcessId()) info.type = MSG_OTHER_PROCESS;
3397 ret = send_inter_thread_message( &info, &result );
3399 if (ret && res_ptr) *res_ptr = result;
3400 return ret;
3404 /***********************************************************************
3405 * SendMessageTimeoutW (USER32.@)
3407 LRESULT WINAPI SendMessageTimeoutW( HWND hwnd, UINT msg, WPARAM wparam, LPARAM lparam,
3408 UINT flags, UINT timeout, PDWORD_PTR res_ptr )
3410 struct send_message_info info;
3412 info.type = MSG_UNICODE;
3413 info.hwnd = hwnd;
3414 info.msg = msg;
3415 info.wparam = wparam;
3416 info.lparam = lparam;
3417 info.flags = flags;
3418 info.timeout = timeout;
3420 return send_message( &info, res_ptr, TRUE );
3423 /***********************************************************************
3424 * SendMessageTimeoutA (USER32.@)
3426 LRESULT WINAPI SendMessageTimeoutA( HWND hwnd, UINT msg, WPARAM wparam, LPARAM lparam,
3427 UINT flags, UINT timeout, PDWORD_PTR res_ptr )
3429 struct send_message_info info;
3431 info.type = MSG_ASCII;
3432 info.hwnd = hwnd;
3433 info.msg = msg;
3434 info.wparam = wparam;
3435 info.lparam = lparam;
3436 info.flags = flags;
3437 info.timeout = timeout;
3438 info.wm_char = WMCHAR_MAP_SENDMESSAGETIMEOUT;
3440 return send_message( &info, res_ptr, FALSE );
3444 /***********************************************************************
3445 * SendMessageW (USER32.@)
3447 LRESULT WINAPI SendMessageW( HWND hwnd, UINT msg, WPARAM wparam, LPARAM lparam )
3449 DWORD_PTR res = 0;
3450 struct send_message_info info;
3452 info.type = MSG_UNICODE;
3453 info.hwnd = hwnd;
3454 info.msg = msg;
3455 info.wparam = wparam;
3456 info.lparam = lparam;
3457 info.flags = SMTO_NORMAL;
3458 info.timeout = 0;
3460 send_message( &info, &res, TRUE );
3461 return res;
3465 /***********************************************************************
3466 * SendMessageA (USER32.@)
3468 LRESULT WINAPI SendMessageA( HWND hwnd, UINT msg, WPARAM wparam, LPARAM lparam )
3470 DWORD_PTR res = 0;
3471 struct send_message_info info;
3473 info.type = MSG_ASCII;
3474 info.hwnd = hwnd;
3475 info.msg = msg;
3476 info.wparam = wparam;
3477 info.lparam = lparam;
3478 info.flags = SMTO_NORMAL;
3479 info.timeout = 0;
3480 info.wm_char = WMCHAR_MAP_SENDMESSAGE;
3482 send_message( &info, &res, FALSE );
3483 return res;
3487 /***********************************************************************
3488 * SendNotifyMessageA (USER32.@)
3490 BOOL WINAPI SendNotifyMessageA( HWND hwnd, UINT msg, WPARAM wparam, LPARAM lparam )
3492 struct send_message_info info;
3494 if (is_pointer_message( msg, wparam ))
3496 SetLastError( ERROR_MESSAGE_SYNC_ONLY );
3497 return FALSE;
3500 info.type = MSG_NOTIFY;
3501 info.hwnd = hwnd;
3502 info.msg = msg;
3503 info.wparam = wparam;
3504 info.lparam = lparam;
3505 info.flags = 0;
3506 info.wm_char = WMCHAR_MAP_SENDMESSAGETIMEOUT;
3508 return send_message( &info, NULL, FALSE );
3512 /***********************************************************************
3513 * SendNotifyMessageW (USER32.@)
3515 BOOL WINAPI SendNotifyMessageW( HWND hwnd, UINT msg, WPARAM wparam, LPARAM lparam )
3517 struct send_message_info info;
3519 if (is_pointer_message( msg, wparam ))
3521 SetLastError( ERROR_MESSAGE_SYNC_ONLY );
3522 return FALSE;
3525 info.type = MSG_NOTIFY;
3526 info.hwnd = hwnd;
3527 info.msg = msg;
3528 info.wparam = wparam;
3529 info.lparam = lparam;
3530 info.flags = 0;
3532 return send_message( &info, NULL, TRUE );
3536 /***********************************************************************
3537 * SendMessageCallbackA (USER32.@)
3539 BOOL WINAPI SendMessageCallbackA( HWND hwnd, UINT msg, WPARAM wparam, LPARAM lparam,
3540 SENDASYNCPROC callback, ULONG_PTR data )
3542 struct send_message_info info;
3544 if (is_pointer_message( msg, wparam ))
3546 SetLastError( ERROR_MESSAGE_SYNC_ONLY );
3547 return FALSE;
3550 info.type = MSG_CALLBACK;
3551 info.hwnd = hwnd;
3552 info.msg = msg;
3553 info.wparam = wparam;
3554 info.lparam = lparam;
3555 info.callback = callback;
3556 info.data = data;
3557 info.flags = 0;
3558 info.wm_char = WMCHAR_MAP_SENDMESSAGETIMEOUT;
3560 return send_message( &info, NULL, FALSE );
3564 /***********************************************************************
3565 * SendMessageCallbackW (USER32.@)
3567 BOOL WINAPI SendMessageCallbackW( HWND hwnd, UINT msg, WPARAM wparam, LPARAM lparam,
3568 SENDASYNCPROC callback, ULONG_PTR data )
3570 struct send_message_info info;
3572 if (is_pointer_message( msg, wparam ))
3574 SetLastError( ERROR_MESSAGE_SYNC_ONLY );
3575 return FALSE;
3578 info.type = MSG_CALLBACK;
3579 info.hwnd = hwnd;
3580 info.msg = msg;
3581 info.wparam = wparam;
3582 info.lparam = lparam;
3583 info.callback = callback;
3584 info.data = data;
3585 info.flags = 0;
3587 return send_message( &info, NULL, TRUE );
3591 /***********************************************************************
3592 * ReplyMessage (USER32.@)
3594 BOOL WINAPI ReplyMessage( LRESULT result )
3596 struct received_message_info *info = get_user_thread_info()->receive_info;
3598 if (!info) return FALSE;
3599 reply_message( info, result, FALSE );
3600 return TRUE;
3604 /***********************************************************************
3605 * InSendMessage (USER32.@)
3607 BOOL WINAPI InSendMessage(void)
3609 return (InSendMessageEx(NULL) & (ISMEX_SEND|ISMEX_REPLIED)) == ISMEX_SEND;
3613 /***********************************************************************
3614 * InSendMessageEx (USER32.@)
3616 DWORD WINAPI InSendMessageEx( LPVOID reserved )
3618 struct received_message_info *info = get_user_thread_info()->receive_info;
3620 if (info) return info->flags;
3621 return ISMEX_NOSEND;
3625 /***********************************************************************
3626 * PostMessageA (USER32.@)
3628 BOOL WINAPI PostMessageA( HWND hwnd, UINT msg, WPARAM wparam, LPARAM lparam )
3630 if (!map_wparam_AtoW( msg, &wparam, WMCHAR_MAP_POSTMESSAGE )) return TRUE;
3631 return PostMessageW( hwnd, msg, wparam, lparam );
3635 /***********************************************************************
3636 * PostMessageW (USER32.@)
3638 BOOL WINAPI PostMessageW( HWND hwnd, UINT msg, WPARAM wparam, LPARAM lparam )
3640 struct send_message_info info;
3642 if (is_pointer_message( msg, wparam ))
3644 SetLastError( ERROR_MESSAGE_SYNC_ONLY );
3645 return FALSE;
3648 TRACE( "hwnd %p msg %x (%s) wp %lx lp %lx\n",
3649 hwnd, msg, SPY_GetMsgName(msg, hwnd), wparam, lparam );
3651 info.type = MSG_POSTED;
3652 info.hwnd = hwnd;
3653 info.msg = msg;
3654 info.wparam = wparam;
3655 info.lparam = lparam;
3656 info.flags = 0;
3658 if (is_broadcast(hwnd))
3660 EnumWindows( broadcast_message_callback, (LPARAM)&info );
3661 return TRUE;
3664 if (!hwnd) return PostThreadMessageW( GetCurrentThreadId(), msg, wparam, lparam );
3666 if (!(info.dest_tid = GetWindowThreadProcessId( hwnd, NULL ))) return FALSE;
3668 if (USER_IsExitingThread( info.dest_tid )) return TRUE;
3670 return put_message_in_queue( &info, NULL );
3674 /**********************************************************************
3675 * PostThreadMessageA (USER32.@)
3677 BOOL WINAPI PostThreadMessageA( DWORD thread, UINT msg, WPARAM wparam, LPARAM lparam )
3679 if (!map_wparam_AtoW( msg, &wparam, WMCHAR_MAP_POSTMESSAGE )) return TRUE;
3680 return PostThreadMessageW( thread, msg, wparam, lparam );
3684 /**********************************************************************
3685 * PostThreadMessageW (USER32.@)
3687 BOOL WINAPI PostThreadMessageW( DWORD thread, UINT msg, WPARAM wparam, LPARAM lparam )
3689 struct send_message_info info;
3691 if (is_pointer_message( msg, wparam ))
3693 SetLastError( ERROR_MESSAGE_SYNC_ONLY );
3694 return FALSE;
3696 if (USER_IsExitingThread( thread )) return TRUE;
3698 info.type = MSG_POSTED;
3699 info.dest_tid = thread;
3700 info.hwnd = 0;
3701 info.msg = msg;
3702 info.wparam = wparam;
3703 info.lparam = lparam;
3704 info.flags = 0;
3705 return put_message_in_queue( &info, NULL );
3709 /***********************************************************************
3710 * PostQuitMessage (USER32.@)
3712 * Posts a quit message to the current thread's message queue.
3714 * PARAMS
3715 * exit_code [I] Exit code to return from message loop.
3717 * RETURNS
3718 * Nothing.
3720 * NOTES
3721 * This function is not the same as calling:
3722 *|PostThreadMessage(GetCurrentThreadId(), WM_QUIT, exit_code, 0);
3723 * It instead sets a flag in the message queue that signals it to generate
3724 * a WM_QUIT message when there are no other pending sent or posted messages
3725 * in the queue.
3727 void WINAPI PostQuitMessage( INT exit_code )
3729 SERVER_START_REQ( post_quit_message )
3731 req->exit_code = exit_code;
3732 wine_server_call( req );
3734 SERVER_END_REQ;
3737 /* check for driver events if we detect that the app is not properly consuming messages */
3738 static inline void check_for_driver_events( UINT msg )
3740 if (get_user_thread_info()->message_count > 200)
3742 flush_window_surfaces( FALSE );
3743 USER_Driver->pMsgWaitForMultipleObjectsEx( 0, NULL, 0, QS_ALLINPUT, 0 );
3745 else if (msg == WM_TIMER || msg == WM_SYSTIMER)
3747 /* driver events should have priority over timers, so make sure we'll check for them soon */
3748 get_user_thread_info()->message_count += 100;
3750 else get_user_thread_info()->message_count++;
3753 /***********************************************************************
3754 * PeekMessageW (USER32.@)
3756 BOOL WINAPI DECLSPEC_HOTPATCH PeekMessageW( MSG *msg_out, HWND hwnd, UINT first, UINT last, UINT flags )
3758 MSG msg;
3760 USER_CheckNotLock();
3761 check_for_driver_events( 0 );
3763 if (!peek_message( &msg, hwnd, first, last, flags, 0 ))
3765 DWORD ret;
3767 flush_window_surfaces( TRUE );
3768 ret = wow_handlers.wait_message( 0, NULL, 0, QS_ALLINPUT, 0 );
3769 /* if we received driver events, check again for a pending message */
3770 if (ret == WAIT_TIMEOUT || !peek_message( &msg, hwnd, first, last, flags, 0 )) return FALSE;
3773 check_for_driver_events( msg.message );
3775 /* copy back our internal safe copy of message data to msg_out.
3776 * msg_out is a variable from the *program*, so it can't be used
3777 * internally as it can get "corrupted" by our use of SendMessage()
3778 * (back to the program) inside the message handling itself. */
3779 if (!msg_out)
3781 SetLastError( ERROR_NOACCESS );
3782 return FALSE;
3784 *msg_out = msg;
3785 return TRUE;
3789 /***********************************************************************
3790 * PeekMessageA (USER32.@)
3792 BOOL WINAPI DECLSPEC_HOTPATCH PeekMessageA( MSG *msg, HWND hwnd, UINT first, UINT last, UINT flags )
3794 if (get_pending_wmchar( msg, first, last, (flags & PM_REMOVE) )) return TRUE;
3795 if (!PeekMessageW( msg, hwnd, first, last, flags )) return FALSE;
3796 map_wparam_WtoA( msg, (flags & PM_REMOVE) );
3797 return TRUE;
3801 /***********************************************************************
3802 * GetMessageW (USER32.@)
3804 BOOL WINAPI DECLSPEC_HOTPATCH GetMessageW( MSG *msg, HWND hwnd, UINT first, UINT last )
3806 HANDLE server_queue = get_server_queue_handle();
3807 unsigned int mask = QS_POSTMESSAGE | QS_SENDMESSAGE; /* Always selected */
3809 USER_CheckNotLock();
3810 check_for_driver_events( 0 );
3812 if (first || last)
3814 if ((first <= WM_KEYLAST) && (last >= WM_KEYFIRST)) mask |= QS_KEY;
3815 if ( ((first <= WM_MOUSELAST) && (last >= WM_MOUSEFIRST)) ||
3816 ((first <= WM_NCMOUSELAST) && (last >= WM_NCMOUSEFIRST)) ) mask |= QS_MOUSE;
3817 if ((first <= WM_TIMER) && (last >= WM_TIMER)) mask |= QS_TIMER;
3818 if ((first <= WM_SYSTIMER) && (last >= WM_SYSTIMER)) mask |= QS_TIMER;
3819 if ((first <= WM_PAINT) && (last >= WM_PAINT)) mask |= QS_PAINT;
3821 else mask = QS_ALLINPUT;
3823 while (!peek_message( msg, hwnd, first, last, PM_REMOVE | (mask << 16), mask ))
3825 wait_objects( 1, &server_queue, INFINITE, mask & (QS_SENDMESSAGE | QS_SMRESULT), mask, 0 );
3827 check_for_driver_events( msg->message );
3829 return (msg->message != WM_QUIT);
3833 /***********************************************************************
3834 * GetMessageA (USER32.@)
3836 BOOL WINAPI DECLSPEC_HOTPATCH GetMessageA( MSG *msg, HWND hwnd, UINT first, UINT last )
3838 if (get_pending_wmchar( msg, first, last, TRUE )) return TRUE;
3839 GetMessageW( msg, hwnd, first, last );
3840 map_wparam_WtoA( msg, TRUE );
3841 return (msg->message != WM_QUIT);
3845 /***********************************************************************
3846 * IsDialogMessageA (USER32.@)
3847 * IsDialogMessage (USER32.@)
3849 BOOL WINAPI IsDialogMessageA( HWND hwndDlg, LPMSG pmsg )
3851 MSG msg = *pmsg;
3852 map_wparam_AtoW( msg.message, &msg.wParam, WMCHAR_MAP_NOMAPPING );
3853 return IsDialogMessageW( hwndDlg, &msg );
3857 /***********************************************************************
3858 * TranslateMessage (USER32.@)
3860 * Implementation of TranslateMessage.
3862 * TranslateMessage translates virtual-key messages into character-messages,
3863 * as follows :
3864 * WM_KEYDOWN/WM_KEYUP combinations produce a WM_CHAR or WM_DEADCHAR message.
3865 * ditto replacing WM_* with WM_SYS*
3866 * This produces WM_CHAR messages only for keys mapped to ASCII characters
3867 * by the keyboard driver.
3869 * If the message is WM_KEYDOWN, WM_KEYUP, WM_SYSKEYDOWN, or WM_SYSKEYUP, the
3870 * return value is nonzero, regardless of the translation.
3873 BOOL WINAPI TranslateMessage( const MSG *msg )
3875 UINT message;
3876 WCHAR wp[8];
3877 BYTE state[256];
3878 INT len;
3880 if (msg->message < WM_KEYFIRST || msg->message > WM_KEYLAST) return FALSE;
3881 if (msg->message != WM_KEYDOWN && msg->message != WM_SYSKEYDOWN) return TRUE;
3883 TRACE_(key)("Translating key %s (%04lX), scancode %04x\n",
3884 SPY_GetVKeyName(msg->wParam), msg->wParam, HIWORD(msg->lParam));
3886 switch (msg->wParam)
3888 case VK_PACKET:
3889 message = (msg->message == WM_KEYDOWN) ? WM_CHAR : WM_SYSCHAR;
3890 TRACE_(key)("PostMessageW(%p,%s,%04x,%08x)\n",
3891 msg->hwnd, SPY_GetMsgName(message, msg->hwnd), HIWORD(msg->lParam), LOWORD(msg->lParam));
3892 PostMessageW( msg->hwnd, message, HIWORD(msg->lParam), LOWORD(msg->lParam));
3893 return TRUE;
3895 case VK_PROCESSKEY:
3896 return ImmTranslateMessage(msg->hwnd, msg->message, msg->wParam, msg->lParam);
3899 GetKeyboardState( state );
3900 len = ToUnicode(msg->wParam, HIWORD(msg->lParam), state, wp, sizeof(wp)/sizeof(WCHAR), 0);
3901 if (len == -1)
3903 message = (msg->message == WM_KEYDOWN) ? WM_DEADCHAR : WM_SYSDEADCHAR;
3904 TRACE_(key)("-1 -> PostMessageW(%p,%s,%04x,%08lx)\n",
3905 msg->hwnd, SPY_GetMsgName(message, msg->hwnd), wp[0], msg->lParam);
3906 PostMessageW( msg->hwnd, message, wp[0], msg->lParam );
3908 else if (len > 0)
3910 INT i;
3912 message = (msg->message == WM_KEYDOWN) ? WM_CHAR : WM_SYSCHAR;
3913 TRACE_(key)("%d -> PostMessageW(%p,%s,<x>,%08lx) for <x> in %s\n", len, msg->hwnd,
3914 SPY_GetMsgName(message, msg->hwnd), msg->lParam, debugstr_wn(wp, len));
3915 for (i = 0; i < len; i++)
3916 PostMessageW( msg->hwnd, message, wp[i], msg->lParam );
3918 return TRUE;
3922 /***********************************************************************
3923 * DispatchMessageA (USER32.@)
3925 * See DispatchMessageW.
3927 LRESULT WINAPI DECLSPEC_HOTPATCH DispatchMessageA( const MSG* msg )
3929 LRESULT retval;
3931 /* Process timer messages */
3932 if ((msg->message == WM_TIMER) || (msg->message == WM_SYSTIMER))
3934 if (msg->lParam)
3936 __TRY
3938 retval = CallWindowProcA( (WNDPROC)msg->lParam, msg->hwnd,
3939 msg->message, msg->wParam, GetTickCount() );
3941 __EXCEPT_ALL
3943 retval = 0;
3945 __ENDTRY
3946 return retval;
3949 if (!msg->hwnd) return 0;
3951 SPY_EnterMessage( SPY_DISPATCHMESSAGE, msg->hwnd, msg->message,
3952 msg->wParam, msg->lParam );
3954 if (!WINPROC_call_window( msg->hwnd, msg->message, msg->wParam, msg->lParam,
3955 &retval, FALSE, WMCHAR_MAP_DISPATCHMESSAGE ))
3957 if (!IsWindow( msg->hwnd )) SetLastError( ERROR_INVALID_WINDOW_HANDLE );
3958 else SetLastError( ERROR_MESSAGE_SYNC_ONLY );
3959 retval = 0;
3962 SPY_ExitMessage( SPY_RESULT_OK, msg->hwnd, msg->message, retval,
3963 msg->wParam, msg->lParam );
3965 if (msg->message == WM_PAINT)
3967 /* send a WM_NCPAINT and WM_ERASEBKGND if the non-client area is still invalid */
3968 HRGN hrgn = CreateRectRgn( 0, 0, 0, 0 );
3969 GetUpdateRgn( msg->hwnd, hrgn, TRUE );
3970 DeleteObject( hrgn );
3972 return retval;
3976 /***********************************************************************
3977 * DispatchMessageW (USER32.@) Process a message
3979 * Process the message specified in the structure *_msg_.
3981 * If the lpMsg parameter points to a WM_TIMER message and the
3982 * parameter of the WM_TIMER message is not NULL, the lParam parameter
3983 * points to the function that is called instead of the window
3984 * procedure. The function stored in lParam (timer callback) is protected
3985 * from causing page-faults.
3987 * The message must be valid.
3989 * RETURNS
3991 * DispatchMessage() returns the result of the window procedure invoked.
3993 * CONFORMANCE
3995 * ECMA-234, Win32
3998 LRESULT WINAPI DECLSPEC_HOTPATCH DispatchMessageW( const MSG* msg )
4000 LRESULT retval;
4002 /* Process timer messages */
4003 if ((msg->message == WM_TIMER) || (msg->message == WM_SYSTIMER))
4005 if (msg->lParam)
4007 __TRY
4009 retval = CallWindowProcW( (WNDPROC)msg->lParam, msg->hwnd,
4010 msg->message, msg->wParam, GetTickCount() );
4012 __EXCEPT_ALL
4014 retval = 0;
4016 __ENDTRY
4017 return retval;
4020 if (!msg->hwnd) return 0;
4022 SPY_EnterMessage( SPY_DISPATCHMESSAGE, msg->hwnd, msg->message,
4023 msg->wParam, msg->lParam );
4025 if (!WINPROC_call_window( msg->hwnd, msg->message, msg->wParam, msg->lParam,
4026 &retval, TRUE, WMCHAR_MAP_DISPATCHMESSAGE ))
4028 if (!IsWindow( msg->hwnd )) SetLastError( ERROR_INVALID_WINDOW_HANDLE );
4029 else SetLastError( ERROR_MESSAGE_SYNC_ONLY );
4030 retval = 0;
4033 SPY_ExitMessage( SPY_RESULT_OK, msg->hwnd, msg->message, retval,
4034 msg->wParam, msg->lParam );
4036 if (msg->message == WM_PAINT)
4038 /* send a WM_NCPAINT and WM_ERASEBKGND if the non-client area is still invalid */
4039 HRGN hrgn = CreateRectRgn( 0, 0, 0, 0 );
4040 GetUpdateRgn( msg->hwnd, hrgn, TRUE );
4041 DeleteObject( hrgn );
4043 return retval;
4047 /***********************************************************************
4048 * GetMessagePos (USER.119)
4049 * GetMessagePos (USER32.@)
4051 * The GetMessagePos() function returns a long value representing a
4052 * cursor position, in screen coordinates, when the last message
4053 * retrieved by the GetMessage() function occurs. The x-coordinate is
4054 * in the low-order word of the return value, the y-coordinate is in
4055 * the high-order word. The application can use the MAKEPOINT()
4056 * macro to obtain a POINT structure from the return value.
4058 * For the current cursor position, use GetCursorPos().
4060 * RETURNS
4062 * Cursor position of last message on success, zero on failure.
4064 * CONFORMANCE
4066 * ECMA-234, Win32
4069 DWORD WINAPI GetMessagePos(void)
4071 return get_user_thread_info()->GetMessagePosVal;
4075 /***********************************************************************
4076 * GetMessageTime (USER.120)
4077 * GetMessageTime (USER32.@)
4079 * GetMessageTime() returns the message time for the last message
4080 * retrieved by the function. The time is measured in milliseconds with
4081 * the same offset as GetTickCount().
4083 * Since the tick count wraps, this is only useful for moderately short
4084 * relative time comparisons.
4086 * RETURNS
4088 * Time of last message on success, zero on failure.
4090 LONG WINAPI GetMessageTime(void)
4092 return get_user_thread_info()->GetMessageTimeVal;
4096 /***********************************************************************
4097 * GetMessageExtraInfo (USER.288)
4098 * GetMessageExtraInfo (USER32.@)
4100 LPARAM WINAPI GetMessageExtraInfo(void)
4102 return get_user_thread_info()->GetMessageExtraInfoVal;
4106 /***********************************************************************
4107 * SetMessageExtraInfo (USER32.@)
4109 LPARAM WINAPI SetMessageExtraInfo(LPARAM lParam)
4111 struct user_thread_info *thread_info = get_user_thread_info();
4112 LONG old_value = thread_info->GetMessageExtraInfoVal;
4113 thread_info->GetMessageExtraInfoVal = lParam;
4114 return old_value;
4118 /***********************************************************************
4119 * WaitMessage (USER.112) Suspend thread pending messages
4120 * WaitMessage (USER32.@) Suspend thread pending messages
4122 * WaitMessage() suspends a thread until events appear in the thread's
4123 * queue.
4125 BOOL WINAPI WaitMessage(void)
4127 return (MsgWaitForMultipleObjectsEx( 0, NULL, INFINITE, QS_ALLINPUT, 0 ) != WAIT_FAILED);
4131 /***********************************************************************
4132 * MsgWaitForMultipleObjectsEx (USER32.@)
4134 DWORD WINAPI MsgWaitForMultipleObjectsEx( DWORD count, const HANDLE *pHandles,
4135 DWORD timeout, DWORD mask, DWORD flags )
4137 HANDLE handles[MAXIMUM_WAIT_OBJECTS];
4138 DWORD i;
4140 if (count > MAXIMUM_WAIT_OBJECTS-1)
4142 SetLastError( ERROR_INVALID_PARAMETER );
4143 return WAIT_FAILED;
4146 /* add the queue to the handle list */
4147 for (i = 0; i < count; i++) handles[i] = pHandles[i];
4148 handles[count] = get_server_queue_handle();
4150 return wait_objects( count+1, handles, timeout,
4151 (flags & MWMO_INPUTAVAILABLE) ? mask : 0, mask, flags );
4155 /***********************************************************************
4156 * MsgWaitForMultipleObjects (USER32.@)
4158 DWORD WINAPI MsgWaitForMultipleObjects( DWORD count, const HANDLE *handles,
4159 BOOL wait_all, DWORD timeout, DWORD mask )
4161 return MsgWaitForMultipleObjectsEx( count, handles, timeout, mask,
4162 wait_all ? MWMO_WAITALL : 0 );
4166 /***********************************************************************
4167 * WaitForInputIdle (USER32.@)
4169 DWORD WINAPI WaitForInputIdle( HANDLE hProcess, DWORD dwTimeOut )
4171 DWORD start_time, elapsed, ret;
4172 HANDLE handles[2];
4174 handles[0] = hProcess;
4175 SERVER_START_REQ( get_process_idle_event )
4177 req->handle = wine_server_obj_handle( hProcess );
4178 wine_server_call_err( req );
4179 handles[1] = wine_server_ptr_handle( reply->event );
4181 SERVER_END_REQ;
4182 if (!handles[1]) return WAIT_FAILED; /* no event to wait on */
4184 start_time = GetTickCount();
4185 elapsed = 0;
4187 TRACE("waiting for %p\n", handles[1] );
4190 ret = MsgWaitForMultipleObjects ( 2, handles, FALSE, dwTimeOut - elapsed, QS_SENDMESSAGE );
4191 switch (ret)
4193 case WAIT_OBJECT_0:
4194 return 0;
4195 case WAIT_OBJECT_0+2:
4196 process_sent_messages();
4197 break;
4198 case WAIT_TIMEOUT:
4199 case WAIT_FAILED:
4200 TRACE("timeout or error\n");
4201 return ret;
4202 default:
4203 TRACE("finished\n");
4204 return 0;
4206 if (dwTimeOut != INFINITE)
4208 elapsed = GetTickCount() - start_time;
4209 if (elapsed > dwTimeOut)
4210 break;
4213 while (1);
4215 return WAIT_TIMEOUT;
4219 /***********************************************************************
4220 * RegisterWindowMessageA (USER32.@)
4221 * RegisterWindowMessage (USER.118)
4223 UINT WINAPI RegisterWindowMessageA( LPCSTR str )
4225 UINT ret = GlobalAddAtomA(str);
4226 TRACE("%s, ret=%x\n", str, ret);
4227 return ret;
4231 /***********************************************************************
4232 * RegisterWindowMessageW (USER32.@)
4234 UINT WINAPI RegisterWindowMessageW( LPCWSTR str )
4236 UINT ret = GlobalAddAtomW(str);
4237 TRACE("%s ret=%x\n", debugstr_w(str), ret);
4238 return ret;
4241 typedef struct BroadcastParm
4243 DWORD flags;
4244 LPDWORD recipients;
4245 UINT msg;
4246 WPARAM wp;
4247 LPARAM lp;
4248 BOOL success;
4249 HWINSTA winsta;
4250 } BroadcastParm;
4252 static BOOL CALLBACK bcast_childwindow( HWND hw, LPARAM lp )
4254 BroadcastParm *parm = (BroadcastParm*)lp;
4255 DWORD_PTR retval = 0;
4256 LRESULT lresult;
4258 if (parm->flags & BSF_IGNORECURRENTTASK && WIN_IsCurrentProcess(hw))
4260 TRACE("Not telling myself %p\n", hw);
4261 return TRUE;
4264 /* I don't know 100% for sure if this is what Windows does, but it fits the tests */
4265 if (parm->flags & BSF_QUERY)
4267 TRACE("Telling window %p using SendMessageTimeout\n", hw);
4269 /* Not tested for conflicting flags */
4270 if (parm->flags & BSF_FORCEIFHUNG || parm->flags & BSF_NOHANG)
4271 lresult = SendMessageTimeoutW( hw, parm->msg, parm->wp, parm->lp, SMTO_ABORTIFHUNG, 2000, &retval );
4272 else if (parm->flags & BSF_NOTIMEOUTIFNOTHUNG)
4273 lresult = SendMessageTimeoutW( hw, parm->msg, parm->wp, parm->lp, SMTO_NOTIMEOUTIFNOTHUNG, 2000, &retval );
4274 else
4275 lresult = SendMessageTimeoutW( hw, parm->msg, parm->wp, parm->lp, SMTO_NORMAL, 2000, &retval );
4277 if (!lresult && GetLastError() == ERROR_TIMEOUT)
4279 WARN("Timed out!\n");
4280 if (!(parm->flags & BSF_FORCEIFHUNG))
4281 goto fail;
4283 if (retval == BROADCAST_QUERY_DENY)
4284 goto fail;
4286 return TRUE;
4288 fail:
4289 parm->success = FALSE;
4290 return FALSE;
4292 else if (parm->flags & BSF_POSTMESSAGE)
4294 TRACE("Telling window %p using PostMessage\n", hw);
4295 PostMessageW( hw, parm->msg, parm->wp, parm->lp );
4297 else
4299 TRACE("Telling window %p using SendNotifyMessage\n", hw);
4300 SendNotifyMessageW( hw, parm->msg, parm->wp, parm->lp );
4303 return TRUE;
4306 static BOOL CALLBACK bcast_desktop( LPWSTR desktop, LPARAM lp )
4308 BOOL ret;
4309 HDESK hdesktop;
4310 BroadcastParm *parm = (BroadcastParm*)lp;
4312 TRACE("desktop: %s\n", debugstr_w( desktop ));
4314 hdesktop = open_winstation_desktop( parm->winsta, desktop, 0, FALSE, DESKTOP_ENUMERATE|DESKTOP_WRITEOBJECTS|STANDARD_RIGHTS_WRITE );
4315 if (!hdesktop)
4317 FIXME("Could not open desktop %s\n", debugstr_w(desktop));
4318 return TRUE;
4321 ret = EnumDesktopWindows( hdesktop, bcast_childwindow, lp );
4322 CloseDesktop(hdesktop);
4323 TRACE("-->%d\n", ret);
4324 return parm->success;
4327 static BOOL CALLBACK bcast_winsta( LPWSTR winsta, LPARAM lp )
4329 BOOL ret;
4330 HWINSTA hwinsta = OpenWindowStationW( winsta, FALSE, WINSTA_ENUMDESKTOPS );
4331 TRACE("hwinsta: %p/%s/%08x\n", hwinsta, debugstr_w( winsta ), GetLastError());
4332 if (!hwinsta)
4333 return TRUE;
4334 ((BroadcastParm *)lp)->winsta = hwinsta;
4335 ret = EnumDesktopsW( hwinsta, bcast_desktop, lp );
4336 CloseWindowStation( hwinsta );
4337 TRACE("-->%d\n", ret);
4338 return ret;
4341 /***********************************************************************
4342 * BroadcastSystemMessageA (USER32.@)
4343 * BroadcastSystemMessage (USER32.@)
4345 LONG WINAPI BroadcastSystemMessageA( DWORD flags, LPDWORD recipients, UINT msg, WPARAM wp, LPARAM lp )
4347 return BroadcastSystemMessageExA( flags, recipients, msg, wp, lp, NULL );
4351 /***********************************************************************
4352 * BroadcastSystemMessageW (USER32.@)
4354 LONG WINAPI BroadcastSystemMessageW( DWORD flags, LPDWORD recipients, UINT msg, WPARAM wp, LPARAM lp )
4356 return BroadcastSystemMessageExW( flags, recipients, msg, wp, lp, NULL );
4359 /***********************************************************************
4360 * BroadcastSystemMessageExA (USER32.@)
4362 LONG WINAPI BroadcastSystemMessageExA( DWORD flags, LPDWORD recipients, UINT msg, WPARAM wp, LPARAM lp, PBSMINFO pinfo )
4364 map_wparam_AtoW( msg, &wp, WMCHAR_MAP_NOMAPPING );
4365 return BroadcastSystemMessageExW( flags, recipients, msg, wp, lp, NULL );
4369 /***********************************************************************
4370 * BroadcastSystemMessageExW (USER32.@)
4372 LONG WINAPI BroadcastSystemMessageExW( DWORD flags, LPDWORD recipients, UINT msg, WPARAM wp, LPARAM lp, PBSMINFO pinfo )
4374 BroadcastParm parm;
4375 DWORD recips = BSM_ALLCOMPONENTS;
4376 BOOL ret = TRUE;
4377 static const DWORD all_flags = ( BSF_QUERY | BSF_IGNORECURRENTTASK | BSF_FLUSHDISK | BSF_NOHANG
4378 | BSF_POSTMESSAGE | BSF_FORCEIFHUNG | BSF_NOTIMEOUTIFNOTHUNG
4379 | BSF_ALLOWSFW | BSF_SENDNOTIFYMESSAGE | BSF_RETURNHDESK | BSF_LUID );
4381 TRACE("Flags: %08x, recipients: %p(0x%x), msg: %04x, wparam: %08lx, lparam: %08lx\n", flags, recipients,
4382 (recipients ? *recipients : recips), msg, wp, lp);
4384 if (flags & ~all_flags)
4386 SetLastError(ERROR_INVALID_PARAMETER);
4387 return 0;
4390 if (!recipients)
4391 recipients = &recips;
4393 if ( pinfo && flags & BSF_QUERY )
4394 FIXME("Not returning PBSMINFO information yet\n");
4396 parm.flags = flags;
4397 parm.recipients = recipients;
4398 parm.msg = msg;
4399 parm.wp = wp;
4400 parm.lp = lp;
4401 parm.success = TRUE;
4403 if (*recipients & BSM_ALLDESKTOPS || *recipients == BSM_ALLCOMPONENTS)
4404 ret = EnumWindowStationsW(bcast_winsta, (LONG_PTR)&parm);
4405 else if (*recipients & BSM_APPLICATIONS)
4407 EnumWindows(bcast_childwindow, (LONG_PTR)&parm);
4408 ret = parm.success;
4410 else
4411 FIXME("Recipients %08x not supported!\n", *recipients);
4413 return ret;
4416 /***********************************************************************
4417 * SetMessageQueue (USER32.@)
4419 BOOL WINAPI SetMessageQueue( INT size )
4421 /* now obsolete the message queue will be expanded dynamically as necessary */
4422 return TRUE;
4426 /***********************************************************************
4427 * MessageBeep (USER32.@)
4429 BOOL WINAPI MessageBeep( UINT i )
4431 BOOL active = TRUE;
4432 SystemParametersInfoA( SPI_GETBEEP, 0, &active, FALSE );
4433 if (active) USER_Driver->pBeep();
4434 return TRUE;
4438 /***********************************************************************
4439 * SetTimer (USER32.@)
4441 UINT_PTR WINAPI SetTimer( HWND hwnd, UINT_PTR id, UINT timeout, TIMERPROC proc )
4443 UINT_PTR ret;
4444 WNDPROC winproc = 0;
4446 if (proc) winproc = WINPROC_AllocProc( (WNDPROC)proc, FALSE );
4448 timeout = min( max( USER_TIMER_MINIMUM, timeout ), USER_TIMER_MAXIMUM );
4450 SERVER_START_REQ( set_win_timer )
4452 req->win = wine_server_user_handle( hwnd );
4453 req->msg = WM_TIMER;
4454 req->id = id;
4455 req->rate = timeout;
4456 req->lparam = (ULONG_PTR)winproc;
4457 if (!wine_server_call_err( req ))
4459 ret = reply->id;
4460 if (!ret) ret = TRUE;
4462 else ret = 0;
4464 SERVER_END_REQ;
4466 TRACE("Added %p %lx %p timeout %d\n", hwnd, id, winproc, timeout );
4467 return ret;
4471 /***********************************************************************
4472 * SetSystemTimer (USER32.@)
4474 UINT_PTR WINAPI SetSystemTimer( HWND hwnd, UINT_PTR id, UINT timeout, TIMERPROC proc )
4476 UINT_PTR ret;
4477 WNDPROC winproc = 0;
4479 if (proc) winproc = WINPROC_AllocProc( (WNDPROC)proc, FALSE );
4481 timeout = min( max( USER_TIMER_MINIMUM, timeout ), USER_TIMER_MAXIMUM );
4483 SERVER_START_REQ( set_win_timer )
4485 req->win = wine_server_user_handle( hwnd );
4486 req->msg = WM_SYSTIMER;
4487 req->id = id;
4488 req->rate = timeout;
4489 req->lparam = (ULONG_PTR)winproc;
4490 if (!wine_server_call_err( req ))
4492 ret = reply->id;
4493 if (!ret) ret = TRUE;
4495 else ret = 0;
4497 SERVER_END_REQ;
4499 TRACE("Added %p %lx %p timeout %d\n", hwnd, id, winproc, timeout );
4500 return ret;
4504 /***********************************************************************
4505 * KillTimer (USER32.@)
4507 BOOL WINAPI KillTimer( HWND hwnd, UINT_PTR id )
4509 BOOL ret;
4511 SERVER_START_REQ( kill_win_timer )
4513 req->win = wine_server_user_handle( hwnd );
4514 req->msg = WM_TIMER;
4515 req->id = id;
4516 ret = !wine_server_call_err( req );
4518 SERVER_END_REQ;
4519 return ret;
4523 /***********************************************************************
4524 * KillSystemTimer (USER32.@)
4526 BOOL WINAPI KillSystemTimer( HWND hwnd, UINT_PTR id )
4528 BOOL ret;
4530 SERVER_START_REQ( kill_win_timer )
4532 req->win = wine_server_user_handle( hwnd );
4533 req->msg = WM_SYSTIMER;
4534 req->id = id;
4535 ret = !wine_server_call_err( req );
4537 SERVER_END_REQ;
4538 return ret;
4542 /**********************************************************************
4543 * IsGUIThread (USER32.@)
4545 BOOL WINAPI IsGUIThread( BOOL convert )
4547 FIXME( "%u: stub\n", convert );
4548 return TRUE;
4552 /**********************************************************************
4553 * GetGUIThreadInfo (USER32.@)
4555 BOOL WINAPI GetGUIThreadInfo( DWORD id, GUITHREADINFO *info )
4557 BOOL ret;
4559 if (info->cbSize != sizeof(*info))
4561 SetLastError( ERROR_INVALID_PARAMETER );
4562 return FALSE;
4565 SERVER_START_REQ( get_thread_input )
4567 req->tid = id;
4568 if ((ret = !wine_server_call_err( req )))
4570 info->flags = 0;
4571 info->hwndActive = wine_server_ptr_handle( reply->active );
4572 info->hwndFocus = wine_server_ptr_handle( reply->focus );
4573 info->hwndCapture = wine_server_ptr_handle( reply->capture );
4574 info->hwndMenuOwner = wine_server_ptr_handle( reply->menu_owner );
4575 info->hwndMoveSize = wine_server_ptr_handle( reply->move_size );
4576 info->hwndCaret = wine_server_ptr_handle( reply->caret );
4577 info->rcCaret.left = reply->rect.left;
4578 info->rcCaret.top = reply->rect.top;
4579 info->rcCaret.right = reply->rect.right;
4580 info->rcCaret.bottom = reply->rect.bottom;
4581 if (reply->menu_owner) info->flags |= GUI_INMENUMODE;
4582 if (reply->move_size) info->flags |= GUI_INMOVESIZE;
4583 if (reply->caret) info->flags |= GUI_CARETBLINKING;
4586 SERVER_END_REQ;
4587 return ret;
4591 /******************************************************************
4592 * IsHungAppWindow (USER32.@)
4595 BOOL WINAPI IsHungAppWindow( HWND hWnd )
4597 BOOL ret;
4599 SERVER_START_REQ( is_window_hung )
4601 req->win = wine_server_user_handle( hWnd );
4602 ret = !wine_server_call_err( req ) && reply->is_hung;
4604 SERVER_END_REQ;
4605 return ret;
4608 /******************************************************************
4609 * ChangeWindowMessageFilter (USER32.@)
4611 BOOL WINAPI ChangeWindowMessageFilter( UINT message, DWORD flag )
4613 FIXME( "%x %08x\n", message, flag );
4614 return TRUE;
4617 /******************************************************************
4618 * ChangeWindowMessageFilterEx (USER32.@)
4620 BOOL WINAPI ChangeWindowMessageFilterEx( HWND hwnd, UINT message, DWORD action, CHANGEFILTERSTRUCT *changefilter )
4622 FIXME( "%p %x %d %p\n", hwnd, message, action, changefilter );
4623 return TRUE;