gdiplus: Don't require specific gdi+ versions in metafile structures.
[wine.git] / dlls / user32 / message.c
blob61a154389ede5cc10f64e0151398b471c58d3697
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) | SET(WM_HELP),
314 /* 0x60 - 0x7f */
315 SET(WM_STYLECHANGING) | SET(WM_STYLECHANGED),
316 /* 0x80 - 0x9f */
317 SET(WM_NCCREATE) | SET(WM_NCCALCSIZE) | SET(WM_GETDLGCODE),
318 /* 0xa0 - 0xbf */
319 SET(EM_GETSEL) | SET(EM_GETRECT) | SET(EM_SETRECT) | SET(EM_SETRECTNP),
320 /* 0xc0 - 0xdf */
321 SET(EM_REPLACESEL) | SET(EM_GETLINE) | SET(EM_SETTABSTOPS),
322 /* 0xe0 - 0xff */
323 SET(SBM_GETRANGE) | SET(SBM_SETSCROLLINFO) | SET(SBM_GETSCROLLINFO) | SET(SBM_GETSCROLLBARINFO),
324 /* 0x100 - 0x11f */
326 /* 0x120 - 0x13f */
328 /* 0x140 - 0x15f */
329 SET(CB_GETEDITSEL) | SET(CB_ADDSTRING) | SET(CB_DIR) | SET(CB_GETLBTEXT) |
330 SET(CB_INSERTSTRING) | SET(CB_FINDSTRING) | SET(CB_SELECTSTRING) |
331 SET(CB_GETDROPPEDCONTROLRECT) | SET(CB_FINDSTRINGEXACT),
332 /* 0x160 - 0x17f */
334 /* 0x180 - 0x19f */
335 SET(LB_ADDSTRING) | SET(LB_INSERTSTRING) | SET(LB_GETTEXT) | SET(LB_SELECTSTRING) |
336 SET(LB_DIR) | SET(LB_FINDSTRING) |
337 SET(LB_GETSELITEMS) | SET(LB_SETTABSTOPS) | SET(LB_ADDFILE) | SET(LB_GETITEMRECT),
338 /* 0x1a0 - 0x1bf */
339 SET(LB_FINDSTRINGEXACT),
340 /* 0x1c0 - 0x1df */
342 /* 0x1e0 - 0x1ff */
344 /* 0x200 - 0x21f */
345 SET(WM_NEXTMENU) | SET(WM_SIZING) | SET(WM_MOVING) | SET(WM_DEVICECHANGE),
346 /* 0x220 - 0x23f */
347 SET(WM_MDICREATE) | SET(WM_MDIGETACTIVE) | SET(WM_DROPOBJECT) |
348 SET(WM_QUERYDROPOBJECT) | SET(WM_DRAGLOOP) | SET(WM_DRAGSELECT) | SET(WM_DRAGMOVE),
349 /* 0x240 - 0x25f */
351 /* 0x260 - 0x27f */
353 /* 0x280 - 0x29f */
355 /* 0x2a0 - 0x2bf */
357 /* 0x2c0 - 0x2df */
359 /* 0x2e0 - 0x2ff */
361 /* 0x300 - 0x31f */
362 SET(WM_ASKCBFORMATNAME)
365 /* flags for messages that contain Unicode strings */
366 static const unsigned int message_unicode_flags[] =
368 /* 0x00 - 0x1f */
369 SET(WM_CREATE) | SET(WM_SETTEXT) | SET(WM_GETTEXT) | SET(WM_GETTEXTLENGTH) |
370 SET(WM_WININICHANGE) | SET(WM_DEVMODECHANGE),
371 /* 0x20 - 0x3f */
372 SET(WM_CHARTOITEM),
373 /* 0x40 - 0x5f */
375 /* 0x60 - 0x7f */
377 /* 0x80 - 0x9f */
378 SET(WM_NCCREATE),
379 /* 0xa0 - 0xbf */
381 /* 0xc0 - 0xdf */
382 SET(EM_REPLACESEL) | SET(EM_GETLINE) | SET(EM_SETPASSWORDCHAR),
383 /* 0xe0 - 0xff */
385 /* 0x100 - 0x11f */
386 SET(WM_CHAR) | SET(WM_DEADCHAR) | SET(WM_SYSCHAR) | SET(WM_SYSDEADCHAR),
387 /* 0x120 - 0x13f */
388 SET(WM_MENUCHAR),
389 /* 0x140 - 0x15f */
390 SET(CB_ADDSTRING) | SET(CB_DIR) | SET(CB_GETLBTEXT) | SET(CB_GETLBTEXTLEN) |
391 SET(CB_INSERTSTRING) | SET(CB_FINDSTRING) | SET(CB_SELECTSTRING) | SET(CB_FINDSTRINGEXACT),
392 /* 0x160 - 0x17f */
394 /* 0x180 - 0x19f */
395 SET(LB_ADDSTRING) | SET(LB_INSERTSTRING) | SET(LB_GETTEXT) | SET(LB_GETTEXTLEN) |
396 SET(LB_SELECTSTRING) | SET(LB_DIR) | SET(LB_FINDSTRING) | SET(LB_ADDFILE),
397 /* 0x1a0 - 0x1bf */
398 SET(LB_FINDSTRINGEXACT),
399 /* 0x1c0 - 0x1df */
401 /* 0x1e0 - 0x1ff */
403 /* 0x200 - 0x21f */
405 /* 0x220 - 0x23f */
406 SET(WM_MDICREATE),
407 /* 0x240 - 0x25f */
409 /* 0x260 - 0x27f */
411 /* 0x280 - 0x29f */
412 SET(WM_IME_CHAR),
413 /* 0x2a0 - 0x2bf */
415 /* 0x2c0 - 0x2df */
417 /* 0x2e0 - 0x2ff */
419 /* 0x300 - 0x31f */
420 SET(WM_PAINTCLIPBOARD) | SET(WM_SIZECLIPBOARD) | SET(WM_ASKCBFORMATNAME)
423 /* check whether a given message type includes pointers */
424 static inline BOOL is_pointer_message( UINT message, WPARAM wparam )
426 if (message >= 8*sizeof(message_pointer_flags)) return FALSE;
427 if (message == WM_DEVICECHANGE && !(wparam & 0x8000)) return FALSE;
428 return (message_pointer_flags[message / 32] & SET(message)) != 0;
431 /* check whether a given message type contains Unicode (or ASCII) chars */
432 static inline BOOL is_unicode_message( UINT message )
434 if (message >= 8*sizeof(message_unicode_flags)) return FALSE;
435 return (message_unicode_flags[message / 32] & SET(message)) != 0;
438 #undef SET
440 /* add a data field to a packed message */
441 static inline void push_data( struct packed_message *data, const void *ptr, size_t size )
443 data->data[data->count] = ptr;
444 data->size[data->count] = size;
445 data->count++;
448 /* add a string to a packed message */
449 static inline void push_string( struct packed_message *data, LPCWSTR str )
451 push_data( data, str, (strlenW(str) + 1) * sizeof(WCHAR) );
454 /* make sure that the buffer contains a valid null-terminated Unicode string */
455 static inline BOOL check_string( LPCWSTR str, size_t size )
457 for (size /= sizeof(WCHAR); size; size--, str++)
458 if (!*str) return TRUE;
459 return FALSE;
462 /* pack a pointer into a 32/64 portable format */
463 static inline ULONGLONG pack_ptr( const void *ptr )
465 return (ULONG_PTR)ptr;
468 /* unpack a potentially 64-bit pointer, returning 0 when truncated */
469 static inline void *unpack_ptr( ULONGLONG ptr64 )
471 if ((ULONG_PTR)ptr64 != ptr64) return 0;
472 return (void *)(ULONG_PTR)ptr64;
475 /* make sure that there is space for 'size' bytes in buffer, growing it if needed */
476 static inline void *get_buffer_space( void **buffer, size_t size )
478 void *ret;
480 if (*buffer)
482 if (!(ret = HeapReAlloc( GetProcessHeap(), 0, *buffer, size )))
483 HeapFree( GetProcessHeap(), 0, *buffer );
485 else ret = HeapAlloc( GetProcessHeap(), 0, size );
487 *buffer = ret;
488 return ret;
491 /* check whether a combobox expects strings or ids in CB_ADDSTRING/CB_INSERTSTRING */
492 static inline BOOL combobox_has_strings( HWND hwnd )
494 DWORD style = GetWindowLongA( hwnd, GWL_STYLE );
495 return (!(style & (CBS_OWNERDRAWFIXED | CBS_OWNERDRAWVARIABLE)) || (style & CBS_HASSTRINGS));
498 /* check whether a listbox expects strings or ids in LB_ADDSTRING/LB_INSERTSTRING */
499 static inline BOOL listbox_has_strings( HWND hwnd )
501 DWORD style = GetWindowLongA( hwnd, GWL_STYLE );
502 return (!(style & (LBS_OWNERDRAWFIXED | LBS_OWNERDRAWVARIABLE)) || (style & LBS_HASSTRINGS));
505 /* check whether message is in the range of keyboard messages */
506 static inline BOOL is_keyboard_message( UINT message )
508 return (message >= WM_KEYFIRST && message <= WM_KEYLAST);
511 /* check whether message is in the range of mouse messages */
512 static inline BOOL is_mouse_message( UINT message )
514 return ((message >= WM_NCMOUSEFIRST && message <= WM_NCMOUSELAST) ||
515 (message >= WM_MOUSEFIRST && message <= WM_MOUSELAST));
518 /* check whether message matches the specified hwnd filter */
519 static inline BOOL check_hwnd_filter( const MSG *msg, HWND hwnd_filter )
521 if (!hwnd_filter || hwnd_filter == GetDesktopWindow()) return TRUE;
522 return (msg->hwnd == hwnd_filter || IsChild( hwnd_filter, msg->hwnd ));
525 /* check for pending WM_CHAR message with DBCS trailing byte */
526 static inline BOOL get_pending_wmchar( MSG *msg, UINT first, UINT last, BOOL remove )
528 struct wm_char_mapping_data *data = get_user_thread_info()->wmchar_data;
530 if (!data || !data->get_msg.message) return FALSE;
531 if ((first || last) && (first > WM_CHAR || last < WM_CHAR)) return FALSE;
532 if (!msg) return FALSE;
533 *msg = data->get_msg;
534 if (remove) data->get_msg.message = 0;
535 return TRUE;
539 /***********************************************************************
540 * MessageWndProc
542 * Window procedure for "Message" windows (HWND_MESSAGE parent).
544 LRESULT WINAPI MessageWndProc( HWND hwnd, UINT message, WPARAM wParam, LPARAM lParam )
546 if (message == WM_NCCREATE) return TRUE;
547 return 0; /* all other messages are ignored */
551 /***********************************************************************
552 * broadcast_message_callback
554 * Helper callback for broadcasting messages.
556 static BOOL CALLBACK broadcast_message_callback( HWND hwnd, LPARAM lparam )
558 struct send_message_info *info = (struct send_message_info *)lparam;
559 if (!(GetWindowLongW( hwnd, GWL_STYLE ) & (WS_POPUP|WS_CAPTION))) return TRUE;
560 switch(info->type)
562 case MSG_UNICODE:
563 SendMessageTimeoutW( hwnd, info->msg, info->wparam, info->lparam,
564 info->flags, info->timeout, NULL );
565 break;
566 case MSG_ASCII:
567 SendMessageTimeoutA( hwnd, info->msg, info->wparam, info->lparam,
568 info->flags, info->timeout, NULL );
569 break;
570 case MSG_NOTIFY:
571 SendNotifyMessageW( hwnd, info->msg, info->wparam, info->lparam );
572 break;
573 case MSG_CALLBACK:
574 SendMessageCallbackW( hwnd, info->msg, info->wparam, info->lparam,
575 info->callback, info->data );
576 break;
577 case MSG_POSTED:
578 PostMessageW( hwnd, info->msg, info->wparam, info->lparam );
579 break;
580 default:
581 ERR( "bad type %d\n", info->type );
582 break;
584 return TRUE;
587 DWORD get_input_codepage( void )
589 DWORD cp;
590 int ret;
591 HKL hkl = GetKeyboardLayout( 0 );
593 ret = GetLocaleInfoW( LOWORD(hkl), LOCALE_IDEFAULTANSICODEPAGE | LOCALE_RETURN_NUMBER,
594 (WCHAR *)&cp, sizeof(cp) / sizeof(WCHAR) );
595 if (!ret) cp = CP_ACP;
596 return cp;
599 /***********************************************************************
600 * map_wparam_AtoW
602 * Convert the wparam of an ASCII message to Unicode.
604 BOOL map_wparam_AtoW( UINT message, WPARAM *wparam, enum wm_char_mapping mapping )
606 char ch[2];
607 WCHAR wch[2];
608 DWORD cp = get_input_codepage();
610 wch[0] = wch[1] = 0;
611 switch(message)
613 case WM_CHAR:
614 /* WM_CHAR is magic: a DBCS char can be sent/posted as two consecutive WM_CHAR
615 * messages, in which case the first char is stored, and the conversion
616 * to Unicode only takes place once the second char is sent/posted.
618 if (mapping != WMCHAR_MAP_NOMAPPING)
620 struct wm_char_mapping_data *data = get_user_thread_info()->wmchar_data;
621 BYTE low = LOBYTE(*wparam);
623 if (HIBYTE(*wparam))
625 ch[0] = low;
626 ch[1] = HIBYTE(*wparam);
627 MultiByteToWideChar( cp, 0, ch, 2, wch, 2 );
628 TRACE( "map %02x,%02x -> %04x mapping %u\n", (BYTE)ch[0], (BYTE)ch[1], wch[0], mapping );
629 if (data) data->lead_byte[mapping] = 0;
631 else if (data && data->lead_byte[mapping])
633 ch[0] = data->lead_byte[mapping];
634 ch[1] = low;
635 MultiByteToWideChar( cp, 0, ch, 2, wch, 2 );
636 TRACE( "map stored %02x,%02x -> %04x mapping %u\n", (BYTE)ch[0], (BYTE)ch[1], wch[0], mapping );
637 data->lead_byte[mapping] = 0;
639 else if (!IsDBCSLeadByte( low ))
641 ch[0] = low;
642 MultiByteToWideChar( cp, 0, ch, 1, wch, 2 );
643 TRACE( "map %02x -> %04x\n", (BYTE)ch[0], wch[0] );
644 if (data) data->lead_byte[mapping] = 0;
646 else /* store it and wait for trail byte */
648 if (!data)
650 if (!(data = HeapAlloc( GetProcessHeap(), HEAP_ZERO_MEMORY, sizeof(*data) )))
651 return FALSE;
652 get_user_thread_info()->wmchar_data = data;
654 TRACE( "storing lead byte %02x mapping %u\n", low, mapping );
655 data->lead_byte[mapping] = low;
656 return FALSE;
658 *wparam = MAKEWPARAM(wch[0], wch[1]);
659 break;
661 /* else fall through */
662 case WM_CHARTOITEM:
663 case EM_SETPASSWORDCHAR:
664 case WM_DEADCHAR:
665 case WM_SYSCHAR:
666 case WM_SYSDEADCHAR:
667 case WM_MENUCHAR:
668 ch[0] = LOBYTE(*wparam);
669 ch[1] = HIBYTE(*wparam);
670 MultiByteToWideChar( cp, 0, ch, 2, wch, 2 );
671 *wparam = MAKEWPARAM(wch[0], wch[1]);
672 break;
673 case WM_IME_CHAR:
674 ch[0] = HIBYTE(*wparam);
675 ch[1] = LOBYTE(*wparam);
676 if (ch[0]) MultiByteToWideChar( cp, 0, ch, 2, wch, 2 );
677 else MultiByteToWideChar( cp, 0, ch + 1, 1, wch, 1 );
678 *wparam = MAKEWPARAM(wch[0], HIWORD(*wparam));
679 break;
681 return TRUE;
685 /***********************************************************************
686 * map_wparam_WtoA
688 * Convert the wparam of a Unicode message to ASCII.
690 static void map_wparam_WtoA( MSG *msg, BOOL remove )
692 BYTE ch[4];
693 WCHAR wch[2];
694 DWORD len;
695 DWORD cp = get_input_codepage();
697 switch(msg->message)
699 case WM_CHAR:
700 if (!HIWORD(msg->wParam))
702 wch[0] = LOWORD(msg->wParam);
703 ch[0] = ch[1] = 0;
704 len = WideCharToMultiByte( cp, 0, wch, 1, (LPSTR)ch, 2, NULL, NULL );
705 if (len == 2) /* DBCS char */
707 struct wm_char_mapping_data *data = get_user_thread_info()->wmchar_data;
708 if (!data)
710 if (!(data = HeapAlloc( GetProcessHeap(), HEAP_ZERO_MEMORY, sizeof(*data) ))) return;
711 get_user_thread_info()->wmchar_data = data;
713 if (remove)
715 data->get_msg = *msg;
716 data->get_msg.wParam = ch[1];
718 msg->wParam = ch[0];
719 return;
722 /* else fall through */
723 case WM_CHARTOITEM:
724 case EM_SETPASSWORDCHAR:
725 case WM_DEADCHAR:
726 case WM_SYSCHAR:
727 case WM_SYSDEADCHAR:
728 case WM_MENUCHAR:
729 wch[0] = LOWORD(msg->wParam);
730 wch[1] = HIWORD(msg->wParam);
731 ch[0] = ch[1] = 0;
732 WideCharToMultiByte( cp, 0, wch, 2, (LPSTR)ch, 4, NULL, NULL );
733 msg->wParam = MAKEWPARAM( ch[0] | (ch[1] << 8), 0 );
734 break;
735 case WM_IME_CHAR:
736 wch[0] = LOWORD(msg->wParam);
737 ch[0] = ch[1] = 0;
738 len = WideCharToMultiByte( cp, 0, wch, 1, (LPSTR)ch, 2, NULL, NULL );
739 if (len == 2)
740 msg->wParam = MAKEWPARAM( (ch[0] << 8) | ch[1], HIWORD(msg->wParam) );
741 else
742 msg->wParam = MAKEWPARAM( ch[0], HIWORD(msg->wParam) );
743 break;
748 /***********************************************************************
749 * pack_message
751 * Pack a message for sending to another process.
752 * Return the size of the data we expect in the message reply.
753 * Set data->count to -1 if there is an error.
755 static size_t pack_message( HWND hwnd, UINT message, WPARAM wparam, LPARAM lparam,
756 struct packed_message *data )
758 data->count = 0;
759 switch(message)
761 case WM_NCCREATE:
762 case WM_CREATE:
764 CREATESTRUCTW *cs = (CREATESTRUCTW *)lparam;
765 data->ps.cs.lpCreateParams = pack_ptr( cs->lpCreateParams );
766 data->ps.cs.hInstance = pack_ptr( cs->hInstance );
767 data->ps.cs.hMenu = wine_server_user_handle( cs->hMenu );
768 data->ps.cs.hwndParent = wine_server_user_handle( cs->hwndParent );
769 data->ps.cs.cy = cs->cy;
770 data->ps.cs.cx = cs->cx;
771 data->ps.cs.y = cs->y;
772 data->ps.cs.x = cs->x;
773 data->ps.cs.style = cs->style;
774 data->ps.cs.dwExStyle = cs->dwExStyle;
775 data->ps.cs.lpszName = pack_ptr( cs->lpszName );
776 data->ps.cs.lpszClass = pack_ptr( cs->lpszClass );
777 push_data( data, &data->ps.cs, sizeof(data->ps.cs) );
778 if (!IS_INTRESOURCE(cs->lpszName)) push_string( data, cs->lpszName );
779 if (!IS_INTRESOURCE(cs->lpszClass)) push_string( data, cs->lpszClass );
780 return sizeof(data->ps.cs);
782 case WM_GETTEXT:
783 case WM_ASKCBFORMATNAME:
784 return wparam * sizeof(WCHAR);
785 case WM_WININICHANGE:
786 if (lparam) push_string(data, (LPWSTR)lparam );
787 return 0;
788 case WM_SETTEXT:
789 case WM_DEVMODECHANGE:
790 case CB_DIR:
791 case LB_DIR:
792 case LB_ADDFILE:
793 case EM_REPLACESEL:
794 push_string( data, (LPWSTR)lparam );
795 return 0;
796 case WM_GETMINMAXINFO:
797 push_data( data, (MINMAXINFO *)lparam, sizeof(MINMAXINFO) );
798 return sizeof(MINMAXINFO);
799 case WM_DRAWITEM:
801 DRAWITEMSTRUCT *dis = (DRAWITEMSTRUCT *)lparam;
802 data->ps.dis.CtlType = dis->CtlType;
803 data->ps.dis.CtlID = dis->CtlID;
804 data->ps.dis.itemID = dis->itemID;
805 data->ps.dis.itemAction = dis->itemAction;
806 data->ps.dis.itemState = dis->itemState;
807 data->ps.dis.hwndItem = wine_server_user_handle( dis->hwndItem );
808 data->ps.dis.hDC = wine_server_user_handle( dis->hDC ); /* FIXME */
809 data->ps.dis.rcItem = dis->rcItem;
810 data->ps.dis.itemData = dis->itemData;
811 push_data( data, &data->ps.dis, sizeof(data->ps.dis) );
812 return 0;
814 case WM_MEASUREITEM:
816 MEASUREITEMSTRUCT *mis = (MEASUREITEMSTRUCT *)lparam;
817 data->ps.mis.CtlType = mis->CtlType;
818 data->ps.mis.CtlID = mis->CtlID;
819 data->ps.mis.itemID = mis->itemID;
820 data->ps.mis.itemWidth = mis->itemWidth;
821 data->ps.mis.itemHeight = mis->itemHeight;
822 data->ps.mis.itemData = mis->itemData;
823 push_data( data, &data->ps.mis, sizeof(data->ps.mis) );
824 return sizeof(data->ps.mis);
826 case WM_DELETEITEM:
828 DELETEITEMSTRUCT *dls = (DELETEITEMSTRUCT *)lparam;
829 data->ps.dls.CtlType = dls->CtlType;
830 data->ps.dls.CtlID = dls->CtlID;
831 data->ps.dls.itemID = dls->itemID;
832 data->ps.dls.hwndItem = wine_server_user_handle( dls->hwndItem );
833 data->ps.dls.itemData = dls->itemData;
834 push_data( data, &data->ps.dls, sizeof(data->ps.dls) );
835 return 0;
837 case WM_COMPAREITEM:
839 COMPAREITEMSTRUCT *cis = (COMPAREITEMSTRUCT *)lparam;
840 data->ps.cis.CtlType = cis->CtlType;
841 data->ps.cis.CtlID = cis->CtlID;
842 data->ps.cis.hwndItem = wine_server_user_handle( cis->hwndItem );
843 data->ps.cis.itemID1 = cis->itemID1;
844 data->ps.cis.itemData1 = cis->itemData1;
845 data->ps.cis.itemID2 = cis->itemID2;
846 data->ps.cis.itemData2 = cis->itemData2;
847 data->ps.cis.dwLocaleId = cis->dwLocaleId;
848 push_data( data, &data->ps.cis, sizeof(data->ps.cis) );
849 return 0;
851 case WM_WINE_SETWINDOWPOS:
852 case WM_WINDOWPOSCHANGING:
853 case WM_WINDOWPOSCHANGED:
855 WINDOWPOS *wp = (WINDOWPOS *)lparam;
856 data->ps.wp.hwnd = wine_server_user_handle( wp->hwnd );
857 data->ps.wp.hwndInsertAfter = wine_server_user_handle( wp->hwndInsertAfter );
858 data->ps.wp.x = wp->x;
859 data->ps.wp.y = wp->y;
860 data->ps.wp.cx = wp->cx;
861 data->ps.wp.cy = wp->cy;
862 data->ps.wp.flags = wp->flags;
863 push_data( data, &data->ps.wp, sizeof(data->ps.wp) );
864 return sizeof(data->ps.wp);
866 case WM_COPYDATA:
868 COPYDATASTRUCT *cds = (COPYDATASTRUCT *)lparam;
869 data->ps.cds.cbData = cds->cbData;
870 data->ps.cds.dwData = cds->dwData;
871 data->ps.cds.lpData = pack_ptr( cds->lpData );
872 push_data( data, &data->ps.cds, sizeof(data->ps.cds) );
873 if (cds->lpData) push_data( data, cds->lpData, cds->cbData );
874 return 0;
876 case WM_NOTIFY:
877 /* WM_NOTIFY cannot be sent across processes (MSDN) */
878 data->count = -1;
879 return 0;
880 case WM_HELP:
882 HELPINFO *hi = (HELPINFO *)lparam;
883 data->ps.hi.iContextType = hi->iContextType;
884 data->ps.hi.iCtrlId = hi->iCtrlId;
885 data->ps.hi.hItemHandle = wine_server_user_handle( hi->hItemHandle );
886 data->ps.hi.dwContextId = hi->dwContextId;
887 data->ps.hi.MousePos = hi->MousePos;
888 push_data( data, &data->ps.hi, sizeof(data->ps.hi) );
889 return 0;
891 case WM_STYLECHANGING:
892 case WM_STYLECHANGED:
893 push_data( data, (STYLESTRUCT *)lparam, sizeof(STYLESTRUCT) );
894 return 0;
895 case WM_NCCALCSIZE:
896 if (!wparam)
898 push_data( data, (RECT *)lparam, sizeof(RECT) );
899 return sizeof(RECT);
901 else
903 NCCALCSIZE_PARAMS *ncp = (NCCALCSIZE_PARAMS *)lparam;
904 data->ps.ncp.rgrc[0] = ncp->rgrc[0];
905 data->ps.ncp.rgrc[1] = ncp->rgrc[1];
906 data->ps.ncp.rgrc[2] = ncp->rgrc[2];
907 data->ps.ncp.hwnd = wine_server_user_handle( ncp->lppos->hwnd );
908 data->ps.ncp.hwndInsertAfter = wine_server_user_handle( ncp->lppos->hwndInsertAfter );
909 data->ps.ncp.x = ncp->lppos->x;
910 data->ps.ncp.y = ncp->lppos->y;
911 data->ps.ncp.cx = ncp->lppos->cx;
912 data->ps.ncp.cy = ncp->lppos->cy;
913 data->ps.ncp.flags = ncp->lppos->flags;
914 push_data( data, &data->ps.ncp, sizeof(data->ps.ncp) );
915 return sizeof(data->ps.ncp);
917 case WM_GETDLGCODE:
918 if (lparam)
920 MSG *msg = (MSG *)lparam;
921 data->ps.msg.hwnd = wine_server_user_handle( msg->hwnd );
922 data->ps.msg.message = msg->message;
923 data->ps.msg.wParam = msg->wParam;
924 data->ps.msg.lParam = msg->lParam;
925 data->ps.msg.time = msg->time;
926 data->ps.msg.pt = msg->pt;
927 push_data( data, &data->ps.msg, sizeof(data->ps.msg) );
928 return sizeof(data->ps.msg);
930 return 0;
931 case SBM_SETSCROLLINFO:
932 push_data( data, (SCROLLINFO *)lparam, sizeof(SCROLLINFO) );
933 return 0;
934 case SBM_GETSCROLLINFO:
935 push_data( data, (SCROLLINFO *)lparam, sizeof(SCROLLINFO) );
936 return sizeof(SCROLLINFO);
937 case SBM_GETSCROLLBARINFO:
939 const SCROLLBARINFO *info = (const SCROLLBARINFO *)lparam;
940 size_t size = min( info->cbSize, sizeof(SCROLLBARINFO) );
941 push_data( data, info, size );
942 return size;
944 case EM_GETSEL:
945 case SBM_GETRANGE:
946 case CB_GETEDITSEL:
948 size_t size = 0;
949 if (wparam) size += sizeof(DWORD);
950 if (lparam) size += sizeof(DWORD);
951 return size;
953 case EM_GETRECT:
954 case LB_GETITEMRECT:
955 case CB_GETDROPPEDCONTROLRECT:
956 return sizeof(RECT);
957 case EM_SETRECT:
958 case EM_SETRECTNP:
959 push_data( data, (RECT *)lparam, sizeof(RECT) );
960 return 0;
961 case EM_GETLINE:
963 WORD *pw = (WORD *)lparam;
964 push_data( data, pw, sizeof(*pw) );
965 return *pw * sizeof(WCHAR);
967 case EM_SETTABSTOPS:
968 case LB_SETTABSTOPS:
969 if (wparam) push_data( data, (UINT *)lparam, sizeof(UINT) * wparam );
970 return 0;
971 case CB_ADDSTRING:
972 case CB_INSERTSTRING:
973 case CB_FINDSTRING:
974 case CB_FINDSTRINGEXACT:
975 case CB_SELECTSTRING:
976 if (combobox_has_strings( hwnd )) push_string( data, (LPWSTR)lparam );
977 return 0;
978 case CB_GETLBTEXT:
979 if (!combobox_has_strings( hwnd )) return sizeof(ULONG_PTR);
980 return (SendMessageW( hwnd, CB_GETLBTEXTLEN, wparam, 0 ) + 1) * sizeof(WCHAR);
981 case LB_ADDSTRING:
982 case LB_INSERTSTRING:
983 case LB_FINDSTRING:
984 case LB_FINDSTRINGEXACT:
985 case LB_SELECTSTRING:
986 if (listbox_has_strings( hwnd )) push_string( data, (LPWSTR)lparam );
987 return 0;
988 case LB_GETTEXT:
989 if (!listbox_has_strings( hwnd )) return sizeof(ULONG_PTR);
990 return (SendMessageW( hwnd, LB_GETTEXTLEN, wparam, 0 ) + 1) * sizeof(WCHAR);
991 case LB_GETSELITEMS:
992 return wparam * sizeof(UINT);
993 case WM_NEXTMENU:
995 MDINEXTMENU *mnm = (MDINEXTMENU *)lparam;
996 data->ps.mnm.hmenuIn = wine_server_user_handle( mnm->hmenuIn );
997 data->ps.mnm.hmenuNext = wine_server_user_handle( mnm->hmenuNext );
998 data->ps.mnm.hwndNext = wine_server_user_handle( mnm->hwndNext );
999 push_data( data, &data->ps.mnm, sizeof(data->ps.mnm) );
1000 return sizeof(data->ps.mnm);
1002 case WM_SIZING:
1003 case WM_MOVING:
1004 push_data( data, (RECT *)lparam, sizeof(RECT) );
1005 return sizeof(RECT);
1006 case WM_MDICREATE:
1008 MDICREATESTRUCTW *mcs = (MDICREATESTRUCTW *)lparam;
1009 data->ps.mcs.szClass = pack_ptr( mcs->szClass );
1010 data->ps.mcs.szTitle = pack_ptr( mcs->szTitle );
1011 data->ps.mcs.hOwner = pack_ptr( mcs->hOwner );
1012 data->ps.mcs.x = mcs->x;
1013 data->ps.mcs.y = mcs->y;
1014 data->ps.mcs.cx = mcs->cx;
1015 data->ps.mcs.cy = mcs->cy;
1016 data->ps.mcs.style = mcs->style;
1017 data->ps.mcs.lParam = mcs->lParam;
1018 push_data( data, &data->ps.mcs, sizeof(data->ps.mcs) );
1019 if (!IS_INTRESOURCE(mcs->szClass)) push_string( data, mcs->szClass );
1020 if (!IS_INTRESOURCE(mcs->szTitle)) push_string( data, mcs->szTitle );
1021 return sizeof(data->ps.mcs);
1023 case WM_MDIGETACTIVE:
1024 if (lparam) return sizeof(BOOL);
1025 return 0;
1026 case WM_DEVICECHANGE:
1028 DEV_BROADCAST_HDR *header = (DEV_BROADCAST_HDR *)lparam;
1029 push_data( data, header, header->dbch_size );
1030 return 0;
1032 case WM_WINE_KEYBOARD_LL_HOOK:
1034 struct hook_extra_info *h_extra = (struct hook_extra_info *)lparam;
1035 data->ps.hook.handle = wine_server_user_handle( h_extra->handle );
1036 push_data( data, &data->ps.hook, sizeof(data->ps.hook) );
1037 push_data( data, (LPVOID)h_extra->lparam, sizeof(KBDLLHOOKSTRUCT) );
1038 return 0;
1040 case WM_WINE_MOUSE_LL_HOOK:
1042 struct hook_extra_info *h_extra = (struct hook_extra_info *)lparam;
1043 data->ps.hook.handle = wine_server_user_handle( h_extra->handle );
1044 push_data( data, &data->ps.hook, sizeof(data->ps.hook) );
1045 push_data( data, (LPVOID)h_extra->lparam, sizeof(MSLLHOOKSTRUCT) );
1046 return 0;
1048 case WM_NCPAINT:
1049 if (wparam <= 1) return 0;
1050 FIXME( "WM_NCPAINT hdc packing not supported yet\n" );
1051 data->count = -1;
1052 return 0;
1053 case WM_PAINT:
1054 if (!wparam) return 0;
1055 /* fall through */
1057 /* these contain an HFONT */
1058 case WM_SETFONT:
1059 case WM_GETFONT:
1060 /* these contain an HDC */
1061 case WM_ERASEBKGND:
1062 case WM_ICONERASEBKGND:
1063 case WM_CTLCOLORMSGBOX:
1064 case WM_CTLCOLOREDIT:
1065 case WM_CTLCOLORLISTBOX:
1066 case WM_CTLCOLORBTN:
1067 case WM_CTLCOLORDLG:
1068 case WM_CTLCOLORSCROLLBAR:
1069 case WM_CTLCOLORSTATIC:
1070 case WM_PRINT:
1071 case WM_PRINTCLIENT:
1072 /* these contain an HGLOBAL */
1073 case WM_PAINTCLIPBOARD:
1074 case WM_SIZECLIPBOARD:
1075 /* these contain HICON */
1076 case WM_GETICON:
1077 case WM_SETICON:
1078 case WM_QUERYDRAGICON:
1079 case WM_QUERYPARKICON:
1080 /* these contain pointers */
1081 case WM_DROPOBJECT:
1082 case WM_QUERYDROPOBJECT:
1083 case WM_DRAGLOOP:
1084 case WM_DRAGSELECT:
1085 case WM_DRAGMOVE:
1086 FIXME( "msg %x (%s) not supported yet\n", message, SPY_GetMsgName(message, hwnd) );
1087 data->count = -1;
1088 return 0;
1090 return 0;
1094 /***********************************************************************
1095 * unpack_message
1097 * Unpack a message received from another process.
1099 static BOOL unpack_message( HWND hwnd, UINT message, WPARAM *wparam, LPARAM *lparam,
1100 void **buffer, size_t size )
1102 size_t minsize = 0;
1103 union packed_structs *ps = *buffer;
1105 switch(message)
1107 case WM_NCCREATE:
1108 case WM_CREATE:
1110 CREATESTRUCTW cs;
1111 WCHAR *str = (WCHAR *)(&ps->cs + 1);
1112 if (size < sizeof(ps->cs)) return FALSE;
1113 size -= sizeof(ps->cs);
1114 cs.lpCreateParams = unpack_ptr( ps->cs.lpCreateParams );
1115 cs.hInstance = unpack_ptr( ps->cs.hInstance );
1116 cs.hMenu = wine_server_ptr_handle( ps->cs.hMenu );
1117 cs.hwndParent = wine_server_ptr_handle( ps->cs.hwndParent );
1118 cs.cy = ps->cs.cy;
1119 cs.cx = ps->cs.cx;
1120 cs.y = ps->cs.y;
1121 cs.x = ps->cs.x;
1122 cs.style = ps->cs.style;
1123 cs.dwExStyle = ps->cs.dwExStyle;
1124 cs.lpszName = unpack_ptr( ps->cs.lpszName );
1125 cs.lpszClass = unpack_ptr( ps->cs.lpszClass );
1126 if (ps->cs.lpszName >> 16)
1128 if (!check_string( str, size )) return FALSE;
1129 cs.lpszName = str;
1130 size -= (strlenW(str) + 1) * sizeof(WCHAR);
1131 str += strlenW(str) + 1;
1133 if (ps->cs.lpszClass >> 16)
1135 if (!check_string( str, size )) return FALSE;
1136 cs.lpszClass = str;
1138 memcpy( &ps->cs, &cs, sizeof(cs) );
1139 break;
1141 case WM_GETTEXT:
1142 case WM_ASKCBFORMATNAME:
1143 if (!get_buffer_space( buffer, (*wparam * sizeof(WCHAR)) )) return FALSE;
1144 break;
1145 case WM_WININICHANGE:
1146 if (!*lparam) return TRUE;
1147 /* fall through */
1148 case WM_SETTEXT:
1149 case WM_DEVMODECHANGE:
1150 case CB_DIR:
1151 case LB_DIR:
1152 case LB_ADDFILE:
1153 case EM_REPLACESEL:
1154 if (!check_string( *buffer, size )) return FALSE;
1155 break;
1156 case WM_GETMINMAXINFO:
1157 minsize = sizeof(MINMAXINFO);
1158 break;
1159 case WM_DRAWITEM:
1161 DRAWITEMSTRUCT dis;
1162 if (size < sizeof(ps->dis)) return FALSE;
1163 dis.CtlType = ps->dis.CtlType;
1164 dis.CtlID = ps->dis.CtlID;
1165 dis.itemID = ps->dis.itemID;
1166 dis.itemAction = ps->dis.itemAction;
1167 dis.itemState = ps->dis.itemState;
1168 dis.hwndItem = wine_server_ptr_handle( ps->dis.hwndItem );
1169 dis.hDC = wine_server_ptr_handle( ps->dis.hDC );
1170 dis.rcItem = ps->dis.rcItem;
1171 dis.itemData = (ULONG_PTR)unpack_ptr( ps->dis.itemData );
1172 memcpy( &ps->dis, &dis, sizeof(dis) );
1173 break;
1175 case WM_MEASUREITEM:
1177 MEASUREITEMSTRUCT mis;
1178 if (size < sizeof(ps->mis)) return FALSE;
1179 mis.CtlType = ps->mis.CtlType;
1180 mis.CtlID = ps->mis.CtlID;
1181 mis.itemID = ps->mis.itemID;
1182 mis.itemWidth = ps->mis.itemWidth;
1183 mis.itemHeight = ps->mis.itemHeight;
1184 mis.itemData = (ULONG_PTR)unpack_ptr( ps->mis.itemData );
1185 memcpy( &ps->mis, &mis, sizeof(mis) );
1186 break;
1188 case WM_DELETEITEM:
1190 DELETEITEMSTRUCT dls;
1191 if (size < sizeof(ps->dls)) return FALSE;
1192 dls.CtlType = ps->dls.CtlType;
1193 dls.CtlID = ps->dls.CtlID;
1194 dls.itemID = ps->dls.itemID;
1195 dls.hwndItem = wine_server_ptr_handle( ps->dls.hwndItem );
1196 dls.itemData = (ULONG_PTR)unpack_ptr( ps->dls.itemData );
1197 memcpy( &ps->dls, &dls, sizeof(dls) );
1198 break;
1200 case WM_COMPAREITEM:
1202 COMPAREITEMSTRUCT cis;
1203 if (size < sizeof(ps->cis)) return FALSE;
1204 cis.CtlType = ps->cis.CtlType;
1205 cis.CtlID = ps->cis.CtlID;
1206 cis.hwndItem = wine_server_ptr_handle( ps->cis.hwndItem );
1207 cis.itemID1 = ps->cis.itemID1;
1208 cis.itemData1 = (ULONG_PTR)unpack_ptr( ps->cis.itemData1 );
1209 cis.itemID2 = ps->cis.itemID2;
1210 cis.itemData2 = (ULONG_PTR)unpack_ptr( ps->cis.itemData2 );
1211 cis.dwLocaleId = ps->cis.dwLocaleId;
1212 memcpy( &ps->cis, &cis, sizeof(cis) );
1213 break;
1215 case WM_WINDOWPOSCHANGING:
1216 case WM_WINDOWPOSCHANGED:
1217 case WM_WINE_SETWINDOWPOS:
1219 WINDOWPOS wp;
1220 if (size < sizeof(ps->wp)) return FALSE;
1221 wp.hwnd = wine_server_ptr_handle( ps->wp.hwnd );
1222 wp.hwndInsertAfter = wine_server_ptr_handle( ps->wp.hwndInsertAfter );
1223 wp.x = ps->wp.x;
1224 wp.y = ps->wp.y;
1225 wp.cx = ps->wp.cx;
1226 wp.cy = ps->wp.cy;
1227 wp.flags = ps->wp.flags;
1228 memcpy( &ps->wp, &wp, sizeof(wp) );
1229 break;
1231 case WM_COPYDATA:
1233 COPYDATASTRUCT cds;
1234 if (size < sizeof(ps->cds)) return FALSE;
1235 cds.dwData = (ULONG_PTR)unpack_ptr( ps->cds.dwData );
1236 if (ps->cds.lpData)
1238 cds.cbData = ps->cds.cbData;
1239 cds.lpData = &ps->cds + 1;
1240 minsize = sizeof(ps->cds) + cds.cbData;
1242 else
1244 cds.cbData = 0;
1245 cds.lpData = 0;
1247 memcpy( &ps->cds, &cds, sizeof(cds) );
1248 break;
1250 case WM_NOTIFY:
1251 /* WM_NOTIFY cannot be sent across processes (MSDN) */
1252 return FALSE;
1253 case WM_HELP:
1255 HELPINFO hi;
1256 if (size < sizeof(ps->hi)) return FALSE;
1257 hi.cbSize = sizeof(hi);
1258 hi.iContextType = ps->hi.iContextType;
1259 hi.iCtrlId = ps->hi.iCtrlId;
1260 hi.hItemHandle = wine_server_ptr_handle( ps->hi.hItemHandle );
1261 hi.dwContextId = (ULONG_PTR)unpack_ptr( ps->hi.dwContextId );
1262 hi.MousePos = ps->hi.MousePos;
1263 memcpy( &ps->hi, &hi, sizeof(hi) );
1264 break;
1266 case WM_STYLECHANGING:
1267 case WM_STYLECHANGED:
1268 minsize = sizeof(STYLESTRUCT);
1269 break;
1270 case WM_NCCALCSIZE:
1271 if (!*wparam) minsize = sizeof(RECT);
1272 else
1274 NCCALCSIZE_PARAMS ncp;
1275 WINDOWPOS wp;
1276 if (size < sizeof(ps->ncp)) return FALSE;
1277 ncp.rgrc[0] = ps->ncp.rgrc[0];
1278 ncp.rgrc[1] = ps->ncp.rgrc[1];
1279 ncp.rgrc[2] = ps->ncp.rgrc[2];
1280 wp.hwnd = wine_server_ptr_handle( ps->ncp.hwnd );
1281 wp.hwndInsertAfter = wine_server_ptr_handle( ps->ncp.hwndInsertAfter );
1282 wp.x = ps->ncp.x;
1283 wp.y = ps->ncp.y;
1284 wp.cx = ps->ncp.cx;
1285 wp.cy = ps->ncp.cy;
1286 wp.flags = ps->ncp.flags;
1287 ncp.lppos = (WINDOWPOS *)((NCCALCSIZE_PARAMS *)&ps->ncp + 1);
1288 memcpy( &ps->ncp, &ncp, sizeof(ncp) );
1289 *ncp.lppos = wp;
1291 break;
1292 case WM_GETDLGCODE:
1293 if (*lparam)
1295 MSG msg;
1296 if (size < sizeof(ps->msg)) return FALSE;
1297 msg.hwnd = wine_server_ptr_handle( ps->msg.hwnd );
1298 msg.message = ps->msg.message;
1299 msg.wParam = (ULONG_PTR)unpack_ptr( ps->msg.wParam );
1300 msg.lParam = (ULONG_PTR)unpack_ptr( ps->msg.lParam );
1301 msg.time = ps->msg.time;
1302 msg.pt = ps->msg.pt;
1303 memcpy( &ps->msg, &msg, sizeof(msg) );
1304 break;
1306 return TRUE;
1307 case SBM_SETSCROLLINFO:
1308 minsize = sizeof(SCROLLINFO);
1309 break;
1310 case SBM_GETSCROLLINFO:
1311 if (!get_buffer_space( buffer, sizeof(SCROLLINFO ))) return FALSE;
1312 break;
1313 case SBM_GETSCROLLBARINFO:
1314 if (!get_buffer_space( buffer, sizeof(SCROLLBARINFO ))) return FALSE;
1315 break;
1316 case EM_GETSEL:
1317 case SBM_GETRANGE:
1318 case CB_GETEDITSEL:
1319 if (*wparam || *lparam)
1321 if (!get_buffer_space( buffer, 2*sizeof(DWORD) )) return FALSE;
1322 if (*wparam) *wparam = (WPARAM)*buffer;
1323 if (*lparam) *lparam = (LPARAM)((DWORD *)*buffer + 1);
1325 return TRUE;
1326 case EM_GETRECT:
1327 case LB_GETITEMRECT:
1328 case CB_GETDROPPEDCONTROLRECT:
1329 if (!get_buffer_space( buffer, sizeof(RECT) )) return FALSE;
1330 break;
1331 case EM_SETRECT:
1332 case EM_SETRECTNP:
1333 minsize = sizeof(RECT);
1334 break;
1335 case EM_GETLINE:
1337 WORD len;
1338 if (size < sizeof(WORD)) return FALSE;
1339 len = *(WORD *)*buffer;
1340 if (!get_buffer_space( buffer, (len + 1) * sizeof(WCHAR) )) return FALSE;
1341 *lparam = (LPARAM)*buffer + sizeof(WORD); /* don't erase WORD at start of buffer */
1342 return TRUE;
1344 case EM_SETTABSTOPS:
1345 case LB_SETTABSTOPS:
1346 if (!*wparam) return TRUE;
1347 minsize = *wparam * sizeof(UINT);
1348 break;
1349 case CB_ADDSTRING:
1350 case CB_INSERTSTRING:
1351 case CB_FINDSTRING:
1352 case CB_FINDSTRINGEXACT:
1353 case CB_SELECTSTRING:
1354 case LB_ADDSTRING:
1355 case LB_INSERTSTRING:
1356 case LB_FINDSTRING:
1357 case LB_FINDSTRINGEXACT:
1358 case LB_SELECTSTRING:
1359 if (!*buffer) return TRUE;
1360 if (!check_string( *buffer, size )) return FALSE;
1361 break;
1362 case CB_GETLBTEXT:
1364 size = sizeof(ULONG_PTR);
1365 if (combobox_has_strings( hwnd ))
1366 size = (SendMessageW( hwnd, CB_GETLBTEXTLEN, *wparam, 0 ) + 1) * sizeof(WCHAR);
1367 if (!get_buffer_space( buffer, size )) return FALSE;
1368 break;
1370 case LB_GETTEXT:
1372 size = sizeof(ULONG_PTR);
1373 if (listbox_has_strings( hwnd ))
1374 size = (SendMessageW( hwnd, LB_GETTEXTLEN, *wparam, 0 ) + 1) * sizeof(WCHAR);
1375 if (!get_buffer_space( buffer, size )) return FALSE;
1376 break;
1378 case LB_GETSELITEMS:
1379 if (!get_buffer_space( buffer, *wparam * sizeof(UINT) )) return FALSE;
1380 break;
1381 case WM_NEXTMENU:
1383 MDINEXTMENU mnm;
1384 if (size < sizeof(ps->mnm)) return FALSE;
1385 mnm.hmenuIn = wine_server_ptr_handle( ps->mnm.hmenuIn );
1386 mnm.hmenuNext = wine_server_ptr_handle( ps->mnm.hmenuNext );
1387 mnm.hwndNext = wine_server_ptr_handle( ps->mnm.hwndNext );
1388 memcpy( &ps->mnm, &mnm, sizeof(mnm) );
1389 break;
1391 case WM_SIZING:
1392 case WM_MOVING:
1393 minsize = sizeof(RECT);
1394 if (!get_buffer_space( buffer, sizeof(RECT) )) return FALSE;
1395 break;
1396 case WM_MDICREATE:
1398 MDICREATESTRUCTW mcs;
1399 WCHAR *str = (WCHAR *)(&ps->mcs + 1);
1400 if (size < sizeof(ps->mcs)) return FALSE;
1401 size -= sizeof(ps->mcs);
1403 mcs.szClass = unpack_ptr( ps->mcs.szClass );
1404 mcs.szTitle = unpack_ptr( ps->mcs.szTitle );
1405 mcs.hOwner = unpack_ptr( ps->mcs.hOwner );
1406 mcs.x = ps->mcs.x;
1407 mcs.y = ps->mcs.y;
1408 mcs.cx = ps->mcs.cx;
1409 mcs.cy = ps->mcs.cy;
1410 mcs.style = ps->mcs.style;
1411 mcs.lParam = (LPARAM)unpack_ptr( ps->mcs.lParam );
1412 if (ps->mcs.szClass >> 16)
1414 if (!check_string( str, size )) return FALSE;
1415 mcs.szClass = str;
1416 size -= (strlenW(str) + 1) * sizeof(WCHAR);
1417 str += strlenW(str) + 1;
1419 if (ps->mcs.szTitle >> 16)
1421 if (!check_string( str, size )) return FALSE;
1422 mcs.szTitle = str;
1424 memcpy( &ps->mcs, &mcs, sizeof(mcs) );
1425 break;
1427 case WM_MDIGETACTIVE:
1428 if (!*lparam) return TRUE;
1429 if (!get_buffer_space( buffer, sizeof(BOOL) )) return FALSE;
1430 break;
1431 case WM_DEVICECHANGE:
1432 minsize = sizeof(DEV_BROADCAST_HDR);
1433 break;
1434 case WM_WINE_KEYBOARD_LL_HOOK:
1435 case WM_WINE_MOUSE_LL_HOOK:
1437 struct hook_extra_info h_extra;
1438 minsize = sizeof(ps->hook) +
1439 (message == WM_WINE_KEYBOARD_LL_HOOK ? sizeof(KBDLLHOOKSTRUCT)
1440 : sizeof(MSLLHOOKSTRUCT));
1441 if (size < minsize) return FALSE;
1442 h_extra.handle = wine_server_ptr_handle( ps->hook.handle );
1443 h_extra.lparam = (LPARAM)(&ps->hook + 1);
1444 memcpy( &ps->hook, &h_extra, sizeof(h_extra) );
1445 break;
1447 case WM_NCPAINT:
1448 if (*wparam <= 1) return TRUE;
1449 FIXME( "WM_NCPAINT hdc unpacking not supported\n" );
1450 return FALSE;
1451 case WM_PAINT:
1452 if (!*wparam) return TRUE;
1453 /* fall through */
1455 /* these contain an HFONT */
1456 case WM_SETFONT:
1457 case WM_GETFONT:
1458 /* these contain an HDC */
1459 case WM_ERASEBKGND:
1460 case WM_ICONERASEBKGND:
1461 case WM_CTLCOLORMSGBOX:
1462 case WM_CTLCOLOREDIT:
1463 case WM_CTLCOLORLISTBOX:
1464 case WM_CTLCOLORBTN:
1465 case WM_CTLCOLORDLG:
1466 case WM_CTLCOLORSCROLLBAR:
1467 case WM_CTLCOLORSTATIC:
1468 case WM_PRINT:
1469 case WM_PRINTCLIENT:
1470 /* these contain an HGLOBAL */
1471 case WM_PAINTCLIPBOARD:
1472 case WM_SIZECLIPBOARD:
1473 /* these contain HICON */
1474 case WM_GETICON:
1475 case WM_SETICON:
1476 case WM_QUERYDRAGICON:
1477 case WM_QUERYPARKICON:
1478 /* these contain pointers */
1479 case WM_DROPOBJECT:
1480 case WM_QUERYDROPOBJECT:
1481 case WM_DRAGLOOP:
1482 case WM_DRAGSELECT:
1483 case WM_DRAGMOVE:
1484 FIXME( "msg %x (%s) not supported yet\n", message, SPY_GetMsgName(message, hwnd) );
1485 return FALSE;
1487 default:
1488 return TRUE; /* message doesn't need any unpacking */
1491 /* default exit for most messages: check minsize and store buffer in lparam */
1492 if (size < minsize) return FALSE;
1493 *lparam = (LPARAM)*buffer;
1494 return TRUE;
1498 /***********************************************************************
1499 * pack_reply
1501 * Pack a reply to a message for sending to another process.
1503 static void pack_reply( HWND hwnd, UINT message, WPARAM wparam, LPARAM lparam,
1504 LRESULT res, struct packed_message *data )
1506 data->count = 0;
1507 switch(message)
1509 case WM_NCCREATE:
1510 case WM_CREATE:
1512 CREATESTRUCTW *cs = (CREATESTRUCTW *)lparam;
1513 data->ps.cs.lpCreateParams = (ULONG_PTR)cs->lpCreateParams;
1514 data->ps.cs.hInstance = (ULONG_PTR)cs->hInstance;
1515 data->ps.cs.hMenu = wine_server_user_handle( cs->hMenu );
1516 data->ps.cs.hwndParent = wine_server_user_handle( cs->hwndParent );
1517 data->ps.cs.cy = cs->cy;
1518 data->ps.cs.cx = cs->cx;
1519 data->ps.cs.y = cs->y;
1520 data->ps.cs.x = cs->x;
1521 data->ps.cs.style = cs->style;
1522 data->ps.cs.dwExStyle = cs->dwExStyle;
1523 data->ps.cs.lpszName = (ULONG_PTR)cs->lpszName;
1524 data->ps.cs.lpszClass = (ULONG_PTR)cs->lpszClass;
1525 push_data( data, &data->ps.cs, sizeof(data->ps.cs) );
1526 break;
1528 case WM_GETTEXT:
1529 case CB_GETLBTEXT:
1530 case LB_GETTEXT:
1531 push_data( data, (WCHAR *)lparam, (res + 1) * sizeof(WCHAR) );
1532 break;
1533 case WM_GETMINMAXINFO:
1534 push_data( data, (MINMAXINFO *)lparam, sizeof(MINMAXINFO) );
1535 break;
1536 case WM_MEASUREITEM:
1538 MEASUREITEMSTRUCT *mis = (MEASUREITEMSTRUCT *)lparam;
1539 data->ps.mis.CtlType = mis->CtlType;
1540 data->ps.mis.CtlID = mis->CtlID;
1541 data->ps.mis.itemID = mis->itemID;
1542 data->ps.mis.itemWidth = mis->itemWidth;
1543 data->ps.mis.itemHeight = mis->itemHeight;
1544 data->ps.mis.itemData = mis->itemData;
1545 push_data( data, &data->ps.mis, sizeof(data->ps.mis) );
1546 break;
1548 case WM_WINDOWPOSCHANGING:
1549 case WM_WINDOWPOSCHANGED:
1551 WINDOWPOS *wp = (WINDOWPOS *)lparam;
1552 data->ps.wp.hwnd = wine_server_user_handle( wp->hwnd );
1553 data->ps.wp.hwndInsertAfter = wine_server_user_handle( wp->hwndInsertAfter );
1554 data->ps.wp.x = wp->x;
1555 data->ps.wp.y = wp->y;
1556 data->ps.wp.cx = wp->cx;
1557 data->ps.wp.cy = wp->cy;
1558 data->ps.wp.flags = wp->flags;
1559 push_data( data, &data->ps.wp, sizeof(data->ps.wp) );
1560 break;
1562 case WM_GETDLGCODE:
1563 if (lparam)
1565 MSG *msg = (MSG *)lparam;
1566 data->ps.msg.hwnd = wine_server_user_handle( msg->hwnd );
1567 data->ps.msg.message = msg->message;
1568 data->ps.msg.wParam = msg->wParam;
1569 data->ps.msg.lParam = msg->lParam;
1570 data->ps.msg.time = msg->time;
1571 data->ps.msg.pt = msg->pt;
1572 push_data( data, &data->ps.msg, sizeof(data->ps.msg) );
1574 break;
1575 case SBM_GETSCROLLINFO:
1576 push_data( data, (SCROLLINFO *)lparam, sizeof(SCROLLINFO) );
1577 break;
1578 case EM_GETRECT:
1579 case LB_GETITEMRECT:
1580 case CB_GETDROPPEDCONTROLRECT:
1581 case WM_SIZING:
1582 case WM_MOVING:
1583 push_data( data, (RECT *)lparam, sizeof(RECT) );
1584 break;
1585 case EM_GETLINE:
1587 WORD *ptr = (WORD *)lparam;
1588 push_data( data, ptr, ptr[-1] * sizeof(WCHAR) );
1589 break;
1591 case LB_GETSELITEMS:
1592 push_data( data, (UINT *)lparam, wparam * sizeof(UINT) );
1593 break;
1594 case WM_MDIGETACTIVE:
1595 if (lparam) push_data( data, (BOOL *)lparam, sizeof(BOOL) );
1596 break;
1597 case WM_NCCALCSIZE:
1598 if (!wparam)
1599 push_data( data, (RECT *)lparam, sizeof(RECT) );
1600 else
1602 NCCALCSIZE_PARAMS *ncp = (NCCALCSIZE_PARAMS *)lparam;
1603 data->ps.ncp.rgrc[0] = ncp->rgrc[0];
1604 data->ps.ncp.rgrc[1] = ncp->rgrc[1];
1605 data->ps.ncp.rgrc[2] = ncp->rgrc[2];
1606 data->ps.ncp.hwnd = wine_server_user_handle( ncp->lppos->hwnd );
1607 data->ps.ncp.hwndInsertAfter = wine_server_user_handle( ncp->lppos->hwndInsertAfter );
1608 data->ps.ncp.x = ncp->lppos->x;
1609 data->ps.ncp.y = ncp->lppos->y;
1610 data->ps.ncp.cx = ncp->lppos->cx;
1611 data->ps.ncp.cy = ncp->lppos->cy;
1612 data->ps.ncp.flags = ncp->lppos->flags;
1613 push_data( data, &data->ps.ncp, sizeof(data->ps.ncp) );
1615 break;
1616 case EM_GETSEL:
1617 case SBM_GETRANGE:
1618 case CB_GETEDITSEL:
1619 if (wparam) push_data( data, (DWORD *)wparam, sizeof(DWORD) );
1620 if (lparam) push_data( data, (DWORD *)lparam, sizeof(DWORD) );
1621 break;
1622 case WM_NEXTMENU:
1624 MDINEXTMENU *mnm = (MDINEXTMENU *)lparam;
1625 data->ps.mnm.hmenuIn = wine_server_user_handle( mnm->hmenuIn );
1626 data->ps.mnm.hmenuNext = wine_server_user_handle( mnm->hmenuNext );
1627 data->ps.mnm.hwndNext = wine_server_user_handle( mnm->hwndNext );
1628 push_data( data, &data->ps.mnm, sizeof(data->ps.mnm) );
1629 break;
1631 case WM_MDICREATE:
1633 MDICREATESTRUCTW *mcs = (MDICREATESTRUCTW *)lparam;
1634 data->ps.mcs.szClass = pack_ptr( mcs->szClass );
1635 data->ps.mcs.szTitle = pack_ptr( mcs->szTitle );
1636 data->ps.mcs.hOwner = pack_ptr( mcs->hOwner );
1637 data->ps.mcs.x = mcs->x;
1638 data->ps.mcs.y = mcs->y;
1639 data->ps.mcs.cx = mcs->cx;
1640 data->ps.mcs.cy = mcs->cy;
1641 data->ps.mcs.style = mcs->style;
1642 data->ps.mcs.lParam = mcs->lParam;
1643 push_data( data, &data->ps.mcs, sizeof(data->ps.mcs) );
1644 break;
1646 case WM_ASKCBFORMATNAME:
1647 push_data( data, (WCHAR *)lparam, (strlenW((WCHAR *)lparam) + 1) * sizeof(WCHAR) );
1648 break;
1653 /***********************************************************************
1654 * unpack_reply
1656 * Unpack a message reply received from another process.
1658 static void unpack_reply( HWND hwnd, UINT message, WPARAM wparam, LPARAM lparam,
1659 void *buffer, size_t size )
1661 union packed_structs *ps = buffer;
1663 switch(message)
1665 case WM_NCCREATE:
1666 case WM_CREATE:
1667 if (size >= sizeof(ps->cs))
1669 CREATESTRUCTW *cs = (CREATESTRUCTW *)lparam;
1670 cs->lpCreateParams = unpack_ptr( ps->cs.lpCreateParams );
1671 cs->hInstance = unpack_ptr( ps->cs.hInstance );
1672 cs->hMenu = wine_server_ptr_handle( ps->cs.hMenu );
1673 cs->hwndParent = wine_server_ptr_handle( ps->cs.hwndParent );
1674 cs->cy = ps->cs.cy;
1675 cs->cx = ps->cs.cx;
1676 cs->y = ps->cs.y;
1677 cs->x = ps->cs.x;
1678 cs->style = ps->cs.style;
1679 cs->dwExStyle = ps->cs.dwExStyle;
1680 /* don't allow changing name and class pointers */
1682 break;
1683 case WM_GETTEXT:
1684 case WM_ASKCBFORMATNAME:
1685 memcpy( (WCHAR *)lparam, buffer, min( wparam*sizeof(WCHAR), size ));
1686 break;
1687 case WM_GETMINMAXINFO:
1688 memcpy( (MINMAXINFO *)lparam, buffer, min( sizeof(MINMAXINFO), size ));
1689 break;
1690 case WM_MEASUREITEM:
1691 if (size >= sizeof(ps->mis))
1693 MEASUREITEMSTRUCT *mis = (MEASUREITEMSTRUCT *)lparam;
1694 mis->CtlType = ps->mis.CtlType;
1695 mis->CtlID = ps->mis.CtlID;
1696 mis->itemID = ps->mis.itemID;
1697 mis->itemWidth = ps->mis.itemWidth;
1698 mis->itemHeight = ps->mis.itemHeight;
1699 mis->itemData = (ULONG_PTR)unpack_ptr( ps->mis.itemData );
1701 break;
1702 case WM_WINDOWPOSCHANGING:
1703 case WM_WINDOWPOSCHANGED:
1704 if (size >= sizeof(ps->wp))
1706 WINDOWPOS *wp = (WINDOWPOS *)lparam;
1707 wp->hwnd = wine_server_ptr_handle( ps->wp.hwnd );
1708 wp->hwndInsertAfter = wine_server_ptr_handle( ps->wp.hwndInsertAfter );
1709 wp->x = ps->wp.x;
1710 wp->y = ps->wp.y;
1711 wp->cx = ps->wp.cx;
1712 wp->cy = ps->wp.cy;
1713 wp->flags = ps->wp.flags;
1715 break;
1716 case WM_GETDLGCODE:
1717 if (lparam && size >= sizeof(ps->msg))
1719 MSG *msg = (MSG *)lparam;
1720 msg->hwnd = wine_server_ptr_handle( ps->msg.hwnd );
1721 msg->message = ps->msg.message;
1722 msg->wParam = (ULONG_PTR)unpack_ptr( ps->msg.wParam );
1723 msg->lParam = (ULONG_PTR)unpack_ptr( ps->msg.lParam );
1724 msg->time = ps->msg.time;
1725 msg->pt = ps->msg.pt;
1727 break;
1728 case SBM_GETSCROLLINFO:
1729 memcpy( (SCROLLINFO *)lparam, buffer, min( sizeof(SCROLLINFO), size ));
1730 break;
1731 case SBM_GETSCROLLBARINFO:
1732 memcpy( (SCROLLBARINFO *)lparam, buffer, min( sizeof(SCROLLBARINFO), size ));
1733 break;
1734 case EM_GETRECT:
1735 case CB_GETDROPPEDCONTROLRECT:
1736 case LB_GETITEMRECT:
1737 case WM_SIZING:
1738 case WM_MOVING:
1739 memcpy( (RECT *)lparam, buffer, min( sizeof(RECT), size ));
1740 break;
1741 case EM_GETLINE:
1742 size = min( size, (size_t)*(WORD *)lparam );
1743 memcpy( (WCHAR *)lparam, buffer, size );
1744 break;
1745 case LB_GETSELITEMS:
1746 memcpy( (UINT *)lparam, buffer, min( wparam*sizeof(UINT), size ));
1747 break;
1748 case LB_GETTEXT:
1749 case CB_GETLBTEXT:
1750 memcpy( (WCHAR *)lparam, buffer, size );
1751 break;
1752 case WM_NEXTMENU:
1753 if (size >= sizeof(ps->mnm))
1755 MDINEXTMENU *mnm = (MDINEXTMENU *)lparam;
1756 mnm->hmenuIn = wine_server_ptr_handle( ps->mnm.hmenuIn );
1757 mnm->hmenuNext = wine_server_ptr_handle( ps->mnm.hmenuNext );
1758 mnm->hwndNext = wine_server_ptr_handle( ps->mnm.hwndNext );
1760 break;
1761 case WM_MDIGETACTIVE:
1762 if (lparam) memcpy( (BOOL *)lparam, buffer, min( sizeof(BOOL), size ));
1763 break;
1764 case WM_NCCALCSIZE:
1765 if (!wparam)
1766 memcpy( (RECT *)lparam, buffer, min( sizeof(RECT), size ));
1767 else if (size >= sizeof(ps->ncp))
1769 NCCALCSIZE_PARAMS *ncp = (NCCALCSIZE_PARAMS *)lparam;
1770 ncp->rgrc[0] = ps->ncp.rgrc[0];
1771 ncp->rgrc[1] = ps->ncp.rgrc[1];
1772 ncp->rgrc[2] = ps->ncp.rgrc[2];
1773 ncp->lppos->hwnd = wine_server_ptr_handle( ps->ncp.hwnd );
1774 ncp->lppos->hwndInsertAfter = wine_server_ptr_handle( ps->ncp.hwndInsertAfter );
1775 ncp->lppos->x = ps->ncp.x;
1776 ncp->lppos->y = ps->ncp.y;
1777 ncp->lppos->cx = ps->ncp.cx;
1778 ncp->lppos->cy = ps->ncp.cy;
1779 ncp->lppos->flags = ps->ncp.flags;
1781 break;
1782 case EM_GETSEL:
1783 case SBM_GETRANGE:
1784 case CB_GETEDITSEL:
1785 if (wparam)
1787 memcpy( (DWORD *)wparam, buffer, min( sizeof(DWORD), size ));
1788 if (size <= sizeof(DWORD)) break;
1789 size -= sizeof(DWORD);
1790 buffer = (DWORD *)buffer + 1;
1792 if (lparam) memcpy( (DWORD *)lparam, buffer, min( sizeof(DWORD), size ));
1793 break;
1794 case WM_MDICREATE:
1795 if (size >= sizeof(ps->mcs))
1797 MDICREATESTRUCTW *mcs = (MDICREATESTRUCTW *)lparam;
1798 mcs->hOwner = unpack_ptr( ps->mcs.hOwner );
1799 mcs->x = ps->mcs.x;
1800 mcs->y = ps->mcs.y;
1801 mcs->cx = ps->mcs.cx;
1802 mcs->cy = ps->mcs.cy;
1803 mcs->style = ps->mcs.style;
1804 mcs->lParam = (LPARAM)unpack_ptr( ps->mcs.lParam );
1805 /* don't allow changing class and title pointers */
1807 break;
1808 default:
1809 ERR( "should not happen: unexpected message %x\n", message );
1810 break;
1815 /***********************************************************************
1816 * reply_message
1818 * Send a reply to a sent message.
1820 static void reply_message( struct received_message_info *info, LRESULT result, BOOL remove )
1822 struct packed_message data;
1823 int i, replied = info->flags & ISMEX_REPLIED;
1825 if (info->flags & ISMEX_NOTIFY) return; /* notify messages don't get replies */
1826 if (!remove && replied) return; /* replied already */
1828 memset( &data, 0, sizeof(data) );
1829 info->flags |= ISMEX_REPLIED;
1831 if (info->type == MSG_OTHER_PROCESS && !replied)
1833 pack_reply( info->msg.hwnd, info->msg.message, info->msg.wParam,
1834 info->msg.lParam, result, &data );
1837 SERVER_START_REQ( reply_message )
1839 req->result = result;
1840 req->remove = remove;
1841 for (i = 0; i < data.count; i++) wine_server_add_data( req, data.data[i], data.size[i] );
1842 wine_server_call( req );
1844 SERVER_END_REQ;
1848 /***********************************************************************
1849 * handle_internal_message
1851 * Handle an internal Wine message instead of calling the window proc.
1853 static LRESULT handle_internal_message( HWND hwnd, UINT msg, WPARAM wparam, LPARAM lparam )
1855 switch(msg)
1857 case WM_WINE_DESTROYWINDOW:
1858 return WIN_DestroyWindow( hwnd );
1859 case WM_WINE_SETWINDOWPOS:
1860 if (is_desktop_window( hwnd )) return 0;
1861 return USER_SetWindowPos( (WINDOWPOS *)lparam );
1862 case WM_WINE_SHOWWINDOW:
1863 if (is_desktop_window( hwnd )) return 0;
1864 return ShowWindow( hwnd, wparam );
1865 case WM_WINE_SETPARENT:
1866 if (is_desktop_window( hwnd )) return 0;
1867 return (LRESULT)SetParent( hwnd, (HWND)wparam );
1868 case WM_WINE_SETWINDOWLONG:
1869 return WIN_SetWindowLong( hwnd, (short)LOWORD(wparam), HIWORD(wparam), lparam, TRUE );
1870 case WM_WINE_SETSTYLE:
1871 if (is_desktop_window( hwnd )) return 0;
1872 return WIN_SetStyle(hwnd, wparam, lparam);
1873 case WM_WINE_SETACTIVEWINDOW:
1874 if (is_desktop_window( hwnd )) return 0;
1875 if (!wparam && GetForegroundWindow() == hwnd) return 0;
1876 return (LRESULT)SetActiveWindow( (HWND)wparam );
1877 case WM_WINE_KEYBOARD_LL_HOOK:
1878 case WM_WINE_MOUSE_LL_HOOK:
1880 struct hook_extra_info *h_extra = (struct hook_extra_info *)lparam;
1882 return call_current_hook( h_extra->handle, HC_ACTION, wparam, h_extra->lparam );
1884 case WM_WINE_CLIPCURSOR:
1885 if (wparam)
1887 RECT rect;
1888 GetClipCursor( &rect );
1889 return USER_Driver->pClipCursor( &rect );
1891 return USER_Driver->pClipCursor( NULL );
1892 default:
1893 if (msg >= WM_WINE_FIRST_DRIVER_MSG && msg <= WM_WINE_LAST_DRIVER_MSG)
1894 return USER_Driver->pWindowMessage( hwnd, msg, wparam, lparam );
1895 FIXME( "unknown internal message %x\n", msg );
1896 return 0;
1900 /* since the WM_DDE_ACK response to a WM_DDE_EXECUTE message should contain the handle
1901 * to the memory handle, we keep track (in the server side) of all pairs of handle
1902 * used (the client passes its value and the content of the memory handle), and
1903 * the server stored both values (the client, and the local one, created after the
1904 * content). When a ACK message is generated, the list of pair is searched for a
1905 * matching pair, so that the client memory handle can be returned.
1907 struct DDE_pair {
1908 HGLOBAL client_hMem;
1909 HGLOBAL server_hMem;
1912 static struct DDE_pair* dde_pairs;
1913 static int dde_num_alloc;
1914 static int dde_num_used;
1916 static CRITICAL_SECTION dde_crst;
1917 static CRITICAL_SECTION_DEBUG critsect_debug =
1919 0, 0, &dde_crst,
1920 { &critsect_debug.ProcessLocksList, &critsect_debug.ProcessLocksList },
1921 0, 0, { (DWORD_PTR)(__FILE__ ": dde_crst") }
1923 static CRITICAL_SECTION dde_crst = { &critsect_debug, -1, 0, 0, 0, 0 };
1925 static BOOL dde_add_pair(HGLOBAL chm, HGLOBAL shm)
1927 int i;
1928 #define GROWBY 4
1930 EnterCriticalSection(&dde_crst);
1932 /* now remember the pair of hMem on both sides */
1933 if (dde_num_used == dde_num_alloc)
1935 struct DDE_pair* tmp;
1936 if (dde_pairs)
1937 tmp = HeapReAlloc( GetProcessHeap(), 0, dde_pairs,
1938 (dde_num_alloc + GROWBY) * sizeof(struct DDE_pair));
1939 else
1940 tmp = HeapAlloc( GetProcessHeap(), 0,
1941 (dde_num_alloc + GROWBY) * sizeof(struct DDE_pair));
1943 if (!tmp)
1945 LeaveCriticalSection(&dde_crst);
1946 return FALSE;
1948 dde_pairs = tmp;
1949 /* zero out newly allocated part */
1950 memset(&dde_pairs[dde_num_alloc], 0, GROWBY * sizeof(struct DDE_pair));
1951 dde_num_alloc += GROWBY;
1953 #undef GROWBY
1954 for (i = 0; i < dde_num_alloc; i++)
1956 if (dde_pairs[i].server_hMem == 0)
1958 dde_pairs[i].client_hMem = chm;
1959 dde_pairs[i].server_hMem = shm;
1960 dde_num_used++;
1961 break;
1964 LeaveCriticalSection(&dde_crst);
1965 return TRUE;
1968 static HGLOBAL dde_get_pair(HGLOBAL shm)
1970 int i;
1971 HGLOBAL ret = 0;
1973 EnterCriticalSection(&dde_crst);
1974 for (i = 0; i < dde_num_alloc; i++)
1976 if (dde_pairs[i].server_hMem == shm)
1978 /* free this pair */
1979 dde_pairs[i].server_hMem = 0;
1980 dde_num_used--;
1981 ret = dde_pairs[i].client_hMem;
1982 break;
1985 LeaveCriticalSection(&dde_crst);
1986 return ret;
1989 /***********************************************************************
1990 * post_dde_message
1992 * Post a DDE message
1994 static BOOL post_dde_message( struct packed_message *data, const struct send_message_info *info )
1996 void* ptr = NULL;
1997 int size = 0;
1998 UINT_PTR uiLo, uiHi;
1999 LPARAM lp;
2000 HGLOBAL hunlock = 0;
2001 int i;
2002 DWORD res;
2003 ULONGLONG hpack;
2005 if (!UnpackDDElParam( info->msg, info->lparam, &uiLo, &uiHi ))
2006 return FALSE;
2008 lp = info->lparam;
2009 switch (info->msg)
2011 /* DDE messages which don't require packing are:
2012 * WM_DDE_INITIATE
2013 * WM_DDE_TERMINATE
2014 * WM_DDE_REQUEST
2015 * WM_DDE_UNADVISE
2017 case WM_DDE_ACK:
2018 if (HIWORD(uiHi))
2020 /* uiHi should contain a hMem from WM_DDE_EXECUTE */
2021 HGLOBAL h = dde_get_pair( (HANDLE)uiHi );
2022 if (h)
2024 hpack = pack_ptr( h );
2025 /* send back the value of h on the other side */
2026 push_data( data, &hpack, sizeof(hpack) );
2027 lp = uiLo;
2028 TRACE( "send dde-ack %lx %08lx => %p\n", uiLo, uiHi, h );
2031 else
2033 /* uiHi should contain either an atom or 0 */
2034 TRACE( "send dde-ack %lx atom=%lx\n", uiLo, uiHi );
2035 lp = MAKELONG( uiLo, uiHi );
2037 break;
2038 case WM_DDE_ADVISE:
2039 case WM_DDE_DATA:
2040 case WM_DDE_POKE:
2041 size = 0;
2042 if (uiLo)
2044 size = GlobalSize( (HGLOBAL)uiLo ) ;
2045 if ((info->msg == WM_DDE_ADVISE && size < sizeof(DDEADVISE)) ||
2046 (info->msg == WM_DDE_DATA && size < FIELD_OFFSET(DDEDATA, Value)) ||
2047 (info->msg == WM_DDE_POKE && size < FIELD_OFFSET(DDEPOKE, Value))
2049 return FALSE;
2051 else if (info->msg != WM_DDE_DATA) return FALSE;
2053 lp = uiHi;
2054 if (uiLo)
2056 if ((ptr = GlobalLock( (HGLOBAL)uiLo) ))
2058 DDEDATA *dde_data = ptr;
2059 TRACE("unused %d, fResponse %d, fRelease %d, fDeferUpd %d, fAckReq %d, cfFormat %d\n",
2060 dde_data->unused, dde_data->fResponse, dde_data->fRelease,
2061 dde_data->reserved, dde_data->fAckReq, dde_data->cfFormat);
2062 push_data( data, ptr, size );
2063 hunlock = (HGLOBAL)uiLo;
2066 TRACE( "send ddepack %u %lx\n", size, uiHi );
2067 break;
2068 case WM_DDE_EXECUTE:
2069 if (info->lparam)
2071 if ((ptr = GlobalLock( (HGLOBAL)info->lparam) ))
2073 push_data(data, ptr, GlobalSize( (HGLOBAL)info->lparam ));
2074 /* so that the other side can send it back on ACK */
2075 lp = info->lparam;
2076 hunlock = (HGLOBAL)info->lparam;
2079 break;
2081 SERVER_START_REQ( send_message )
2083 req->id = info->dest_tid;
2084 req->type = info->type;
2085 req->flags = 0;
2086 req->win = wine_server_user_handle( info->hwnd );
2087 req->msg = info->msg;
2088 req->wparam = info->wparam;
2089 req->lparam = lp;
2090 req->timeout = TIMEOUT_INFINITE;
2091 for (i = 0; i < data->count; i++)
2092 wine_server_add_data( req, data->data[i], data->size[i] );
2093 if ((res = wine_server_call( req )))
2095 if (res == STATUS_INVALID_PARAMETER)
2096 /* FIXME: find a STATUS_ value for this one */
2097 SetLastError( ERROR_INVALID_THREAD_ID );
2098 else
2099 SetLastError( RtlNtStatusToDosError(res) );
2101 else
2102 FreeDDElParam(info->msg, info->lparam);
2104 SERVER_END_REQ;
2105 if (hunlock) GlobalUnlock(hunlock);
2107 return !res;
2110 /***********************************************************************
2111 * unpack_dde_message
2113 * Unpack a posted DDE message received from another process.
2115 static BOOL unpack_dde_message( HWND hwnd, UINT message, WPARAM *wparam, LPARAM *lparam,
2116 void **buffer, size_t size )
2118 UINT_PTR uiLo, uiHi;
2119 HGLOBAL hMem = 0;
2120 void* ptr;
2122 switch (message)
2124 case WM_DDE_ACK:
2125 if (size)
2127 ULONGLONG hpack;
2128 /* hMem is being passed */
2129 if (size != sizeof(hpack)) return FALSE;
2130 if (!buffer || !*buffer) return FALSE;
2131 uiLo = *lparam;
2132 memcpy( &hpack, *buffer, size );
2133 hMem = unpack_ptr( hpack );
2134 uiHi = (UINT_PTR)hMem;
2135 TRACE("recv dde-ack %lx mem=%lx[%lx]\n", uiLo, uiHi, GlobalSize( hMem ));
2137 else
2139 uiLo = LOWORD( *lparam );
2140 uiHi = HIWORD( *lparam );
2141 TRACE("recv dde-ack %lx atom=%lx\n", uiLo, uiHi);
2143 *lparam = PackDDElParam( WM_DDE_ACK, uiLo, uiHi );
2144 break;
2145 case WM_DDE_ADVISE:
2146 case WM_DDE_DATA:
2147 case WM_DDE_POKE:
2148 if ((!buffer || !*buffer) && message != WM_DDE_DATA) return FALSE;
2149 uiHi = *lparam;
2150 if (size)
2152 if (!(hMem = GlobalAlloc( GMEM_MOVEABLE|GMEM_DDESHARE, size )))
2153 return FALSE;
2154 if ((ptr = GlobalLock( hMem )))
2156 memcpy( ptr, *buffer, size );
2157 GlobalUnlock( hMem );
2159 else
2161 GlobalFree( hMem );
2162 return FALSE;
2165 uiLo = (UINT_PTR)hMem;
2167 *lparam = PackDDElParam( message, uiLo, uiHi );
2168 break;
2169 case WM_DDE_EXECUTE:
2170 if (size)
2172 if (!buffer || !*buffer) return FALSE;
2173 if (!(hMem = GlobalAlloc( GMEM_MOVEABLE|GMEM_DDESHARE, size ))) return FALSE;
2174 if ((ptr = GlobalLock( hMem )))
2176 memcpy( ptr, *buffer, size );
2177 GlobalUnlock( hMem );
2178 TRACE( "exec: pairing c=%08lx s=%p\n", *lparam, hMem );
2179 if (!dde_add_pair( (HGLOBAL)*lparam, hMem ))
2181 GlobalFree( hMem );
2182 return FALSE;
2185 else
2187 GlobalFree( hMem );
2188 return FALSE;
2190 } else return FALSE;
2191 *lparam = (LPARAM)hMem;
2192 break;
2194 return TRUE;
2197 /***********************************************************************
2198 * call_window_proc
2200 * Call a window procedure and the corresponding hooks.
2202 static LRESULT call_window_proc( HWND hwnd, UINT msg, WPARAM wparam, LPARAM lparam,
2203 BOOL unicode, BOOL same_thread, enum wm_char_mapping mapping )
2205 LRESULT result = 0;
2206 CWPSTRUCT cwp;
2207 CWPRETSTRUCT cwpret;
2209 if (msg & 0x80000000)
2211 result = handle_internal_message( hwnd, msg, wparam, lparam );
2212 goto done;
2215 /* first the WH_CALLWNDPROC hook */
2216 hwnd = WIN_GetFullHandle( hwnd );
2217 cwp.lParam = lparam;
2218 cwp.wParam = wparam;
2219 cwp.message = msg;
2220 cwp.hwnd = hwnd;
2221 HOOK_CallHooks( WH_CALLWNDPROC, HC_ACTION, same_thread, (LPARAM)&cwp, unicode );
2223 /* now call the window procedure */
2224 if (!WINPROC_call_window( hwnd, msg, wparam, lparam, &result, unicode, mapping )) goto done;
2226 /* and finally the WH_CALLWNDPROCRET hook */
2227 cwpret.lResult = result;
2228 cwpret.lParam = lparam;
2229 cwpret.wParam = wparam;
2230 cwpret.message = msg;
2231 cwpret.hwnd = hwnd;
2232 HOOK_CallHooks( WH_CALLWNDPROCRET, HC_ACTION, same_thread, (LPARAM)&cwpret, unicode );
2233 done:
2234 return result;
2238 /***********************************************************************
2239 * send_parent_notify
2241 * Send a WM_PARENTNOTIFY to all ancestors of the given window, unless
2242 * the window has the WS_EX_NOPARENTNOTIFY style.
2244 static void send_parent_notify( HWND hwnd, WORD event, WORD idChild, POINT pt )
2246 /* pt has to be in the client coordinates of the parent window */
2247 MapWindowPoints( 0, hwnd, &pt, 1 );
2248 for (;;)
2250 HWND parent;
2252 if (!(GetWindowLongW( hwnd, GWL_STYLE ) & WS_CHILD)) break;
2253 if (GetWindowLongW( hwnd, GWL_EXSTYLE ) & WS_EX_NOPARENTNOTIFY) break;
2254 if (!(parent = GetParent(hwnd))) break;
2255 if (parent == GetDesktopWindow()) break;
2256 MapWindowPoints( hwnd, parent, &pt, 1 );
2257 hwnd = parent;
2258 SendMessageW( hwnd, WM_PARENTNOTIFY,
2259 MAKEWPARAM( event, idChild ), MAKELPARAM( pt.x, pt.y ) );
2264 /***********************************************************************
2265 * accept_hardware_message
2267 * Tell the server we have passed the message to the app
2268 * (even though we may end up dropping it later on)
2270 static void accept_hardware_message( UINT hw_id, BOOL remove )
2272 SERVER_START_REQ( accept_hardware_message )
2274 req->hw_id = hw_id;
2275 req->remove = remove;
2276 if (wine_server_call( req ))
2277 FIXME("Failed to reply to MSG_HARDWARE message. Message may not be removed from queue.\n");
2279 SERVER_END_REQ;
2283 static BOOL process_rawinput_message( MSG *msg, const struct hardware_msg_data *msg_data )
2285 struct user_thread_info *thread_info = get_user_thread_info();
2286 RAWINPUT *rawinput = thread_info->rawinput;
2288 if (!rawinput)
2290 thread_info->rawinput = HeapAlloc( GetProcessHeap(), 0, sizeof(*rawinput) );
2291 if (!(rawinput = thread_info->rawinput)) return FALSE;
2294 rawinput->header.dwType = msg_data->rawinput.type;
2295 if (msg_data->rawinput.type == RIM_TYPEMOUSE)
2297 static const unsigned int button_flags[] =
2299 0, /* MOUSEEVENTF_MOVE */
2300 RI_MOUSE_LEFT_BUTTON_DOWN, /* MOUSEEVENTF_LEFTDOWN */
2301 RI_MOUSE_LEFT_BUTTON_UP, /* MOUSEEVENTF_LEFTUP */
2302 RI_MOUSE_RIGHT_BUTTON_DOWN, /* MOUSEEVENTF_RIGHTDOWN */
2303 RI_MOUSE_RIGHT_BUTTON_UP, /* MOUSEEVENTF_RIGHTUP */
2304 RI_MOUSE_MIDDLE_BUTTON_DOWN, /* MOUSEEVENTF_MIDDLEDOWN */
2305 RI_MOUSE_MIDDLE_BUTTON_UP, /* MOUSEEVENTF_MIDDLEUP */
2307 unsigned int i;
2309 rawinput->header.dwSize = FIELD_OFFSET(RAWINPUT, data) + sizeof(RAWMOUSE);
2310 rawinput->header.hDevice = WINE_MOUSE_HANDLE;
2311 rawinput->header.wParam = 0;
2313 rawinput->data.mouse.usFlags = MOUSE_MOVE_RELATIVE;
2314 rawinput->data.mouse.u.s.usButtonFlags = 0;
2315 rawinput->data.mouse.u.s.usButtonData = 0;
2316 for (i = 1; i < sizeof(button_flags) / sizeof(*button_flags); ++i)
2318 if (msg_data->flags & (1 << i))
2319 rawinput->data.mouse.u.s.usButtonFlags |= button_flags[i];
2321 if (msg_data->flags & MOUSEEVENTF_WHEEL)
2323 rawinput->data.mouse.u.s.usButtonFlags |= RI_MOUSE_WHEEL;
2324 rawinput->data.mouse.u.s.usButtonData = msg_data->rawinput.mouse.data;
2326 if (msg_data->flags & MOUSEEVENTF_HWHEEL)
2328 rawinput->data.mouse.u.s.usButtonFlags |= RI_MOUSE_HORIZONTAL_WHEEL;
2329 rawinput->data.mouse.u.s.usButtonData = msg_data->rawinput.mouse.data;
2331 if (msg_data->flags & MOUSEEVENTF_XDOWN)
2333 if (msg_data->rawinput.mouse.data == XBUTTON1)
2334 rawinput->data.mouse.u.s.usButtonFlags |= RI_MOUSE_BUTTON_4_DOWN;
2335 else if (msg_data->rawinput.mouse.data == XBUTTON2)
2336 rawinput->data.mouse.u.s.usButtonFlags |= RI_MOUSE_BUTTON_5_DOWN;
2338 if (msg_data->flags & MOUSEEVENTF_XUP)
2340 if (msg_data->rawinput.mouse.data == XBUTTON1)
2341 rawinput->data.mouse.u.s.usButtonFlags |= RI_MOUSE_BUTTON_4_UP;
2342 else if (msg_data->rawinput.mouse.data == XBUTTON2)
2343 rawinput->data.mouse.u.s.usButtonFlags |= RI_MOUSE_BUTTON_5_UP;
2346 rawinput->data.mouse.ulRawButtons = 0;
2347 rawinput->data.mouse.lLastX = msg_data->rawinput.mouse.x;
2348 rawinput->data.mouse.lLastY = msg_data->rawinput.mouse.y;
2349 rawinput->data.mouse.ulExtraInformation = msg_data->info;
2351 else if (msg_data->rawinput.type == RIM_TYPEKEYBOARD)
2353 rawinput->header.dwSize = FIELD_OFFSET(RAWINPUT, data) + sizeof(RAWKEYBOARD);
2354 rawinput->header.hDevice = WINE_KEYBOARD_HANDLE;
2355 rawinput->header.wParam = 0;
2357 rawinput->data.keyboard.MakeCode = msg_data->rawinput.kbd.scan;
2358 rawinput->data.keyboard.Flags = msg_data->flags & KEYEVENTF_KEYUP ? RI_KEY_BREAK : RI_KEY_MAKE;
2359 if (msg_data->flags & KEYEVENTF_EXTENDEDKEY) rawinput->data.keyboard.Flags |= RI_KEY_E0;
2360 rawinput->data.keyboard.Reserved = 0;
2362 switch (msg_data->rawinput.kbd.vkey)
2364 case VK_LSHIFT:
2365 case VK_RSHIFT:
2366 rawinput->data.keyboard.VKey = VK_SHIFT;
2367 rawinput->data.keyboard.Flags &= ~RI_KEY_E0;
2368 break;
2369 case VK_LCONTROL:
2370 case VK_RCONTROL:
2371 rawinput->data.keyboard.VKey = VK_CONTROL;
2372 break;
2373 case VK_LMENU:
2374 case VK_RMENU:
2375 rawinput->data.keyboard.VKey = VK_MENU;
2376 break;
2377 default:
2378 rawinput->data.keyboard.VKey = msg_data->rawinput.kbd.vkey;
2379 break;
2382 rawinput->data.keyboard.Message = msg_data->rawinput.kbd.message;
2383 rawinput->data.keyboard.ExtraInformation = msg_data->info;
2385 else
2387 FIXME("Unhandled rawinput type %#x.\n", msg_data->rawinput.type);
2388 return FALSE;
2391 msg->lParam = (LPARAM)rawinput;
2392 return TRUE;
2395 /***********************************************************************
2396 * process_keyboard_message
2398 * returns TRUE if the contents of 'msg' should be passed to the application
2400 static BOOL process_keyboard_message( MSG *msg, UINT hw_id, HWND hwnd_filter,
2401 UINT first, UINT last, BOOL remove )
2403 EVENTMSG event;
2405 if (msg->message == WM_KEYDOWN || msg->message == WM_SYSKEYDOWN ||
2406 msg->message == WM_KEYUP || msg->message == WM_SYSKEYUP)
2407 switch (msg->wParam)
2409 case VK_LSHIFT: case VK_RSHIFT:
2410 msg->wParam = VK_SHIFT;
2411 break;
2412 case VK_LCONTROL: case VK_RCONTROL:
2413 msg->wParam = VK_CONTROL;
2414 break;
2415 case VK_LMENU: case VK_RMENU:
2416 msg->wParam = VK_MENU;
2417 break;
2420 /* FIXME: is this really the right place for this hook? */
2421 event.message = msg->message;
2422 event.hwnd = msg->hwnd;
2423 event.time = msg->time;
2424 event.paramL = (msg->wParam & 0xFF) | (HIWORD(msg->lParam) << 8);
2425 event.paramH = msg->lParam & 0x7FFF;
2426 if (HIWORD(msg->lParam) & 0x0100) event.paramH |= 0x8000; /* special_key - bit */
2427 HOOK_CallHooks( WH_JOURNALRECORD, HC_ACTION, 0, (LPARAM)&event, TRUE );
2429 /* check message filters */
2430 if (msg->message < first || msg->message > last) return FALSE;
2431 if (!check_hwnd_filter( msg, hwnd_filter )) return FALSE;
2433 if (remove)
2435 if((msg->message == WM_KEYDOWN) &&
2436 (msg->hwnd != GetDesktopWindow()))
2438 /* Handle F1 key by sending out WM_HELP message */
2439 if (msg->wParam == VK_F1)
2441 PostMessageW( msg->hwnd, WM_KEYF1, 0, 0 );
2443 else if(msg->wParam >= VK_BROWSER_BACK &&
2444 msg->wParam <= VK_LAUNCH_APP2)
2446 /* FIXME: Process keystate */
2447 SendMessageW(msg->hwnd, WM_APPCOMMAND, (WPARAM)msg->hwnd, MAKELPARAM(0, (FAPPCOMMAND_KEY | (msg->wParam - VK_BROWSER_BACK + 1))));
2450 else if (msg->message == WM_KEYUP)
2452 /* Handle VK_APPS key by posting a WM_CONTEXTMENU message */
2453 if (msg->wParam == VK_APPS && !MENU_IsMenuActive())
2454 PostMessageW(msg->hwnd, WM_CONTEXTMENU, (WPARAM)msg->hwnd, -1);
2458 if (HOOK_CallHooks( WH_KEYBOARD, remove ? HC_ACTION : HC_NOREMOVE,
2459 LOWORD(msg->wParam), msg->lParam, TRUE ))
2461 /* skip this message */
2462 HOOK_CallHooks( WH_CBT, HCBT_KEYSKIPPED, LOWORD(msg->wParam), msg->lParam, TRUE );
2463 accept_hardware_message( hw_id, TRUE );
2464 return FALSE;
2466 accept_hardware_message( hw_id, remove );
2468 if ( remove && msg->message == WM_KEYDOWN )
2469 if (ImmProcessKey(msg->hwnd, GetKeyboardLayout(0), msg->wParam, msg->lParam, 0) )
2470 msg->wParam = VK_PROCESSKEY;
2472 return TRUE;
2476 /***********************************************************************
2477 * process_mouse_message
2479 * returns TRUE if the contents of 'msg' should be passed to the application
2481 static BOOL process_mouse_message( MSG *msg, UINT hw_id, ULONG_PTR extra_info, HWND hwnd_filter,
2482 UINT first, UINT last, BOOL remove )
2484 static MSG clk_msg;
2486 POINT pt;
2487 UINT message;
2488 INT hittest;
2489 EVENTMSG event;
2490 GUITHREADINFO info;
2491 MOUSEHOOKSTRUCTEX hook;
2492 BOOL eatMsg;
2493 WPARAM wparam;
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 wparam = msg->wParam;
2528 /* Note: windows has no concept of a non-client wheel message */
2529 if (message != WM_MOUSEWHEEL)
2531 if (hittest != HTCLIENT)
2533 message += WM_NCMOUSEMOVE - WM_MOUSEMOVE;
2534 wparam = hittest;
2536 else
2538 /* coordinates don't get translated while tracking a menu */
2539 /* FIXME: should differentiate popups and top-level menus */
2540 if (!(info.flags & GUI_INMENUMODE))
2541 ScreenToClient( msg->hwnd, &pt );
2544 msg->lParam = MAKELONG( pt.x, pt.y );
2546 /* translate double clicks */
2548 if ((msg->message == WM_LBUTTONDOWN) ||
2549 (msg->message == WM_RBUTTONDOWN) ||
2550 (msg->message == WM_MBUTTONDOWN) ||
2551 (msg->message == WM_XBUTTONDOWN))
2553 BOOL update = remove;
2555 /* translate double clicks -
2556 * note that ...MOUSEMOVEs can slip in between
2557 * ...BUTTONDOWN and ...BUTTONDBLCLK messages */
2559 if ((info.flags & (GUI_INMENUMODE|GUI_INMOVESIZE)) ||
2560 hittest != HTCLIENT ||
2561 (GetClassLongA( msg->hwnd, GCL_STYLE ) & CS_DBLCLKS))
2563 if ((msg->message == clk_msg.message) &&
2564 (msg->hwnd == clk_msg.hwnd) &&
2565 (msg->wParam == clk_msg.wParam) &&
2566 (msg->time - clk_msg.time < GetDoubleClickTime()) &&
2567 (abs(msg->pt.x - clk_msg.pt.x) < GetSystemMetrics(SM_CXDOUBLECLK)/2) &&
2568 (abs(msg->pt.y - clk_msg.pt.y) < GetSystemMetrics(SM_CYDOUBLECLK)/2))
2570 message += (WM_LBUTTONDBLCLK - WM_LBUTTONDOWN);
2571 if (update)
2573 clk_msg.message = 0; /* clear the double click conditions */
2574 update = FALSE;
2578 if (message < first || message > last) return FALSE;
2579 /* update static double click conditions */
2580 if (update) clk_msg = *msg;
2582 else
2584 if (message < first || message > last) return FALSE;
2586 msg->wParam = wparam;
2588 /* message is accepted now (but may still get dropped) */
2590 hook.s.pt = msg->pt;
2591 hook.s.hwnd = msg->hwnd;
2592 hook.s.wHitTestCode = hittest;
2593 hook.s.dwExtraInfo = extra_info;
2594 hook.mouseData = msg->wParam;
2595 if (HOOK_CallHooks( WH_MOUSE, remove ? HC_ACTION : HC_NOREMOVE,
2596 message, (LPARAM)&hook, TRUE ))
2598 hook.s.pt = msg->pt;
2599 hook.s.hwnd = msg->hwnd;
2600 hook.s.wHitTestCode = hittest;
2601 hook.s.dwExtraInfo = extra_info;
2602 hook.mouseData = msg->wParam;
2603 HOOK_CallHooks( WH_CBT, HCBT_CLICKSKIPPED, message, (LPARAM)&hook, TRUE );
2604 accept_hardware_message( hw_id, TRUE );
2605 return FALSE;
2608 if ((hittest == HTERROR) || (hittest == HTNOWHERE))
2610 SendMessageW( msg->hwnd, WM_SETCURSOR, (WPARAM)msg->hwnd,
2611 MAKELONG( hittest, msg->message ));
2612 accept_hardware_message( hw_id, TRUE );
2613 return FALSE;
2616 accept_hardware_message( hw_id, remove );
2618 if (!remove || info.hwndCapture)
2620 msg->message = message;
2621 return TRUE;
2624 eatMsg = FALSE;
2626 if ((msg->message == WM_LBUTTONDOWN) ||
2627 (msg->message == WM_RBUTTONDOWN) ||
2628 (msg->message == WM_MBUTTONDOWN) ||
2629 (msg->message == WM_XBUTTONDOWN))
2631 /* Send the WM_PARENTNOTIFY,
2632 * note that even for double/nonclient clicks
2633 * notification message is still WM_L/M/RBUTTONDOWN.
2635 send_parent_notify( msg->hwnd, msg->message, 0, msg->pt );
2637 /* Activate the window if needed */
2639 if (msg->hwnd != info.hwndActive)
2641 HWND hwndTop = msg->hwnd;
2642 while (hwndTop)
2644 if ((GetWindowLongW( hwndTop, GWL_STYLE ) & (WS_POPUP|WS_CHILD)) != WS_CHILD) break;
2645 hwndTop = GetParent( hwndTop );
2648 if (hwndTop && hwndTop != GetDesktopWindow())
2650 LONG ret = SendMessageW( msg->hwnd, WM_MOUSEACTIVATE, (WPARAM)hwndTop,
2651 MAKELONG( hittest, msg->message ) );
2652 switch(ret)
2654 case MA_NOACTIVATEANDEAT:
2655 eatMsg = TRUE;
2656 /* fall through */
2657 case MA_NOACTIVATE:
2658 break;
2659 case MA_ACTIVATEANDEAT:
2660 eatMsg = TRUE;
2661 /* fall through */
2662 case MA_ACTIVATE:
2663 case 0:
2664 if (!FOCUS_MouseActivate( hwndTop )) eatMsg = TRUE;
2665 break;
2666 default:
2667 WARN( "unknown WM_MOUSEACTIVATE code %d\n", ret );
2668 break;
2674 /* send the WM_SETCURSOR message */
2676 /* Windows sends the normal mouse message as the message parameter
2677 in the WM_SETCURSOR message even if it's non-client mouse message */
2678 SendMessageW( msg->hwnd, WM_SETCURSOR, (WPARAM)msg->hwnd, MAKELONG( hittest, msg->message ));
2680 msg->message = message;
2681 return !eatMsg;
2685 /***********************************************************************
2686 * process_hardware_message
2688 * Process a hardware message; return TRUE if message should be passed on to the app
2690 static BOOL process_hardware_message( MSG *msg, UINT hw_id, const struct hardware_msg_data *msg_data,
2691 HWND hwnd_filter, UINT first, UINT last, BOOL remove )
2693 if (msg->message == WM_INPUT)
2694 return process_rawinput_message( msg, msg_data );
2696 if (is_keyboard_message( msg->message ))
2697 return process_keyboard_message( msg, hw_id, hwnd_filter, first, last, remove );
2699 if (is_mouse_message( msg->message ))
2700 return process_mouse_message( msg, hw_id, msg_data->info, hwnd_filter, first, last, remove );
2702 ERR( "unknown message type %x\n", msg->message );
2703 return FALSE;
2707 /***********************************************************************
2708 * call_sendmsg_callback
2710 * Call the callback function of SendMessageCallback.
2712 static inline void call_sendmsg_callback( SENDASYNCPROC callback, HWND hwnd, UINT msg,
2713 ULONG_PTR data, LRESULT result )
2715 if (!callback) return;
2717 if (TRACE_ON(relay))
2718 DPRINTF( "%04x:Call message callback %p (hwnd=%p,msg=%s,data=%08lx,result=%08lx)\n",
2719 GetCurrentThreadId(), callback, hwnd, SPY_GetMsgName( msg, hwnd ),
2720 data, result );
2721 callback( hwnd, msg, data, result );
2722 if (TRACE_ON(relay))
2723 DPRINTF( "%04x:Ret message callback %p (hwnd=%p,msg=%s,data=%08lx,result=%08lx)\n",
2724 GetCurrentThreadId(), callback, hwnd, SPY_GetMsgName( msg, hwnd ),
2725 data, result );
2729 /***********************************************************************
2730 * peek_message
2732 * Peek for a message matching the given parameters. Return FALSE if none available.
2733 * All pending sent messages are processed before returning.
2735 static BOOL peek_message( MSG *msg, HWND hwnd, UINT first, UINT last, UINT flags, UINT changed_mask )
2737 LRESULT result;
2738 struct user_thread_info *thread_info = get_user_thread_info();
2739 struct received_message_info info, *old_info;
2740 unsigned int hw_id = 0; /* id of previous hardware message */
2741 void *buffer;
2742 size_t buffer_size = 256;
2744 if (!(buffer = HeapAlloc( GetProcessHeap(), 0, buffer_size ))) return FALSE;
2746 if (!first && !last) last = ~0;
2747 if (hwnd == HWND_BROADCAST) hwnd = HWND_TOPMOST;
2749 for (;;)
2751 NTSTATUS res;
2752 size_t size = 0;
2753 const message_data_t *msg_data = buffer;
2755 SERVER_START_REQ( get_message )
2757 req->flags = flags;
2758 req->get_win = wine_server_user_handle( hwnd );
2759 req->get_first = first;
2760 req->get_last = last;
2761 req->hw_id = hw_id;
2762 req->wake_mask = changed_mask & (QS_SENDMESSAGE | QS_SMRESULT);
2763 req->changed_mask = changed_mask;
2764 wine_server_set_reply( req, buffer, buffer_size );
2765 if (!(res = wine_server_call( req )))
2767 size = wine_server_reply_size( reply );
2768 info.type = reply->type;
2769 info.msg.hwnd = wine_server_ptr_handle( reply->win );
2770 info.msg.message = reply->msg;
2771 info.msg.wParam = reply->wparam;
2772 info.msg.lParam = reply->lparam;
2773 info.msg.time = reply->time;
2774 info.msg.pt.x = reply->x;
2775 info.msg.pt.y = reply->y;
2776 hw_id = 0;
2777 thread_info->active_hooks = reply->active_hooks;
2779 else buffer_size = reply->total;
2781 SERVER_END_REQ;
2783 if (res)
2785 HeapFree( GetProcessHeap(), 0, buffer );
2786 if (res == STATUS_PENDING)
2788 thread_info->wake_mask = changed_mask & (QS_SENDMESSAGE | QS_SMRESULT);
2789 thread_info->changed_mask = changed_mask;
2791 if (res != STATUS_BUFFER_OVERFLOW) return FALSE;
2792 if (!(buffer = HeapAlloc( GetProcessHeap(), 0, buffer_size ))) return FALSE;
2793 continue;
2796 TRACE( "got type %d msg %x (%s) hwnd %p wp %lx lp %lx\n",
2797 info.type, info.msg.message,
2798 (info.type == MSG_WINEVENT) ? "MSG_WINEVENT" : SPY_GetMsgName(info.msg.message, info.msg.hwnd),
2799 info.msg.hwnd, info.msg.wParam, info.msg.lParam );
2801 switch(info.type)
2803 case MSG_ASCII:
2804 case MSG_UNICODE:
2805 info.flags = ISMEX_SEND;
2806 break;
2807 case MSG_NOTIFY:
2808 info.flags = ISMEX_NOTIFY;
2809 break;
2810 case MSG_CALLBACK:
2811 info.flags = ISMEX_CALLBACK;
2812 break;
2813 case MSG_CALLBACK_RESULT:
2814 if (size >= sizeof(msg_data->callback))
2815 call_sendmsg_callback( wine_server_get_ptr(msg_data->callback.callback),
2816 info.msg.hwnd, info.msg.message,
2817 msg_data->callback.data, msg_data->callback.result );
2818 continue;
2819 case MSG_WINEVENT:
2820 if (size >= sizeof(msg_data->winevent))
2822 WINEVENTPROC hook_proc;
2823 HMODULE free_module = 0;
2825 hook_proc = wine_server_get_ptr( msg_data->winevent.hook_proc );
2826 size -= sizeof(msg_data->winevent);
2827 if (size)
2829 WCHAR module[MAX_PATH];
2831 size = min( size, (MAX_PATH - 1) * sizeof(WCHAR) );
2832 memcpy( module, &msg_data->winevent + 1, size );
2833 module[size / sizeof(WCHAR)] = 0;
2834 if (!(hook_proc = get_hook_proc( hook_proc, module, &free_module )))
2836 ERR( "invalid winevent hook module name %s\n", debugstr_w(module) );
2837 continue;
2841 if (TRACE_ON(relay))
2842 DPRINTF( "%04x:Call winevent proc %p (hook=%04x,event=%x,hwnd=%p,object_id=%lx,child_id=%lx,tid=%04x,time=%x)\n",
2843 GetCurrentThreadId(), hook_proc,
2844 msg_data->winevent.hook, info.msg.message, info.msg.hwnd, info.msg.wParam,
2845 info.msg.lParam, msg_data->winevent.tid, info.msg.time);
2847 hook_proc( wine_server_ptr_handle( msg_data->winevent.hook ), info.msg.message,
2848 info.msg.hwnd, info.msg.wParam, info.msg.lParam,
2849 msg_data->winevent.tid, info.msg.time );
2851 if (TRACE_ON(relay))
2852 DPRINTF( "%04x:Ret winevent proc %p (hook=%04x,event=%x,hwnd=%p,object_id=%lx,child_id=%lx,tid=%04x,time=%x)\n",
2853 GetCurrentThreadId(), hook_proc,
2854 msg_data->winevent.hook, info.msg.message, info.msg.hwnd, info.msg.wParam,
2855 info.msg.lParam, msg_data->winevent.tid, info.msg.time);
2857 if (free_module) FreeLibrary(free_module);
2859 continue;
2860 case MSG_HOOK_LL:
2861 info.flags = ISMEX_SEND;
2862 result = 0;
2863 if (info.msg.message == WH_KEYBOARD_LL && size >= sizeof(msg_data->hardware))
2865 KBDLLHOOKSTRUCT hook;
2867 hook.vkCode = LOWORD( info.msg.lParam );
2868 hook.scanCode = HIWORD( info.msg.lParam );
2869 hook.flags = msg_data->hardware.flags;
2870 hook.time = info.msg.time;
2871 hook.dwExtraInfo = msg_data->hardware.info;
2872 TRACE( "calling keyboard LL hook vk %x scan %x flags %x time %u info %lx\n",
2873 hook.vkCode, hook.scanCode, hook.flags, hook.time, hook.dwExtraInfo );
2874 result = HOOK_CallHooks( WH_KEYBOARD_LL, HC_ACTION, info.msg.wParam, (LPARAM)&hook, TRUE );
2876 else if (info.msg.message == WH_MOUSE_LL && size >= sizeof(msg_data->hardware))
2878 MSLLHOOKSTRUCT hook;
2880 hook.pt = info.msg.pt;
2881 hook.mouseData = info.msg.lParam;
2882 hook.flags = msg_data->hardware.flags;
2883 hook.time = info.msg.time;
2884 hook.dwExtraInfo = msg_data->hardware.info;
2885 TRACE( "calling mouse LL hook pos %d,%d data %x flags %x time %u info %lx\n",
2886 hook.pt.x, hook.pt.y, hook.mouseData, hook.flags, hook.time, hook.dwExtraInfo );
2887 result = HOOK_CallHooks( WH_MOUSE_LL, HC_ACTION, info.msg.wParam, (LPARAM)&hook, TRUE );
2889 reply_message( &info, result, TRUE );
2890 continue;
2891 case MSG_OTHER_PROCESS:
2892 info.flags = ISMEX_SEND;
2893 if (!unpack_message( info.msg.hwnd, info.msg.message, &info.msg.wParam,
2894 &info.msg.lParam, &buffer, size ))
2896 /* ignore it */
2897 reply_message( &info, 0, TRUE );
2898 continue;
2900 break;
2901 case MSG_HARDWARE:
2902 if (size >= sizeof(msg_data->hardware))
2904 hw_id = msg_data->hardware.hw_id;
2905 if (!process_hardware_message( &info.msg, hw_id, &msg_data->hardware,
2906 hwnd, first, last, flags & PM_REMOVE ))
2908 TRACE("dropping msg %x\n", info.msg.message );
2909 continue; /* ignore it */
2911 *msg = info.msg;
2912 thread_info->GetMessagePosVal = MAKELONG( info.msg.pt.x, info.msg.pt.y );
2913 thread_info->GetMessageTimeVal = info.msg.time;
2914 thread_info->GetMessageExtraInfoVal = msg_data->hardware.info;
2915 HeapFree( GetProcessHeap(), 0, buffer );
2916 HOOK_CallHooks( WH_GETMESSAGE, HC_ACTION, flags & PM_REMOVE, (LPARAM)msg, TRUE );
2917 return TRUE;
2919 continue;
2920 case MSG_POSTED:
2921 if (info.msg.message & 0x80000000) /* internal message */
2923 if (flags & PM_REMOVE)
2925 handle_internal_message( info.msg.hwnd, info.msg.message,
2926 info.msg.wParam, info.msg.lParam );
2927 /* if this is a nested call return right away */
2928 if (first == info.msg.message && last == info.msg.message)
2930 HeapFree( GetProcessHeap(), 0, buffer );
2931 return FALSE;
2934 else
2935 peek_message( msg, info.msg.hwnd, info.msg.message,
2936 info.msg.message, flags | PM_REMOVE, changed_mask );
2937 continue;
2939 if (info.msg.message >= WM_DDE_FIRST && info.msg.message <= WM_DDE_LAST)
2941 if (!unpack_dde_message( info.msg.hwnd, info.msg.message, &info.msg.wParam,
2942 &info.msg.lParam, &buffer, size ))
2943 continue; /* ignore it */
2945 *msg = info.msg;
2946 thread_info->GetMessagePosVal = MAKELONG( info.msg.pt.x, info.msg.pt.y );
2947 thread_info->GetMessageTimeVal = info.msg.time;
2948 thread_info->GetMessageExtraInfoVal = 0;
2949 HeapFree( GetProcessHeap(), 0, buffer );
2950 HOOK_CallHooks( WH_GETMESSAGE, HC_ACTION, flags & PM_REMOVE, (LPARAM)msg, TRUE );
2951 return TRUE;
2954 /* if we get here, we have a sent message; call the window procedure */
2955 old_info = thread_info->receive_info;
2956 thread_info->receive_info = &info;
2957 result = call_window_proc( info.msg.hwnd, info.msg.message, info.msg.wParam,
2958 info.msg.lParam, (info.type != MSG_ASCII), FALSE,
2959 WMCHAR_MAP_RECVMESSAGE );
2960 reply_message( &info, result, TRUE );
2961 thread_info->receive_info = old_info;
2963 /* if some PM_QS* flags were specified, only handle sent messages from now on */
2964 if (HIWORD(flags) && !changed_mask) flags = PM_QS_SENDMESSAGE | LOWORD(flags);
2969 /***********************************************************************
2970 * process_sent_messages
2972 * Process all pending sent messages.
2974 static inline void process_sent_messages(void)
2976 MSG msg;
2977 peek_message( &msg, 0, 0, 0, PM_REMOVE | PM_QS_SENDMESSAGE, 0 );
2981 /***********************************************************************
2982 * get_server_queue_handle
2984 * Get a handle to the server message queue for the current thread.
2986 static HANDLE get_server_queue_handle(void)
2988 struct user_thread_info *thread_info = get_user_thread_info();
2989 HANDLE ret;
2991 if (!(ret = thread_info->server_queue))
2993 SERVER_START_REQ( get_msg_queue )
2995 wine_server_call( req );
2996 ret = wine_server_ptr_handle( reply->handle );
2998 SERVER_END_REQ;
2999 thread_info->server_queue = ret;
3000 if (!ret) ERR( "Cannot get server thread queue\n" );
3002 return ret;
3006 /***********************************************************************
3007 * wait_message_reply
3009 * Wait until a sent message gets replied to.
3011 static void wait_message_reply( UINT flags )
3013 struct user_thread_info *thread_info = get_user_thread_info();
3014 HANDLE server_queue = get_server_queue_handle();
3015 unsigned int wake_mask = QS_SMRESULT | ((flags & SMTO_BLOCK) ? 0 : QS_SENDMESSAGE);
3017 for (;;)
3019 unsigned int wake_bits = 0;
3021 SERVER_START_REQ( set_queue_mask )
3023 req->wake_mask = wake_mask;
3024 req->changed_mask = wake_mask;
3025 req->skip_wait = 1;
3026 if (!wine_server_call( req )) wake_bits = reply->wake_bits & wake_mask;
3028 SERVER_END_REQ;
3030 thread_info->wake_mask = thread_info->changed_mask = 0;
3032 if (wake_bits & QS_SMRESULT) return; /* got a result */
3033 if (wake_bits & QS_SENDMESSAGE)
3035 /* Process the sent message immediately */
3036 process_sent_messages();
3037 continue;
3040 wow_handlers.wait_message( 1, &server_queue, INFINITE, wake_mask, 0 );
3045 /***********************************************************************
3046 * wait_objects
3048 * Wait for multiple objects including the server queue, with specific queue masks.
3050 static DWORD wait_objects( DWORD count, const HANDLE *handles, DWORD timeout,
3051 DWORD wake_mask, DWORD changed_mask, DWORD flags )
3053 struct user_thread_info *thread_info = get_user_thread_info();
3054 DWORD ret;
3056 assert( count ); /* we must have at least the server queue */
3058 flush_window_surfaces( TRUE );
3060 if (thread_info->wake_mask != wake_mask || thread_info->changed_mask != changed_mask)
3062 SERVER_START_REQ( set_queue_mask )
3064 req->wake_mask = wake_mask;
3065 req->changed_mask = changed_mask;
3066 req->skip_wait = 0;
3067 wine_server_call( req );
3069 SERVER_END_REQ;
3070 thread_info->wake_mask = wake_mask;
3071 thread_info->changed_mask = changed_mask;
3074 ret = wow_handlers.wait_message( count, handles, timeout, changed_mask, flags );
3076 if (ret != WAIT_TIMEOUT) thread_info->wake_mask = thread_info->changed_mask = 0;
3077 return ret;
3081 /***********************************************************************
3082 * put_message_in_queue
3084 * Put a sent message into the destination queue.
3085 * For inter-process message, reply_size is set to expected size of reply data.
3087 static BOOL put_message_in_queue( const struct send_message_info *info, size_t *reply_size )
3089 struct packed_message data;
3090 message_data_t msg_data;
3091 unsigned int res;
3092 int i;
3093 timeout_t timeout = TIMEOUT_INFINITE;
3095 /* Check for INFINITE timeout for compatibility with Win9x,
3096 * although Windows >= NT does not do so
3098 if (info->type != MSG_NOTIFY &&
3099 info->type != MSG_CALLBACK &&
3100 info->type != MSG_POSTED &&
3101 info->timeout &&
3102 info->timeout != INFINITE)
3104 /* timeout is signed despite the prototype */
3105 timeout = (timeout_t)max( 0, (int)info->timeout ) * -10000;
3108 memset( &data, 0, sizeof(data) );
3109 if (info->type == MSG_OTHER_PROCESS)
3111 *reply_size = pack_message( info->hwnd, info->msg, info->wparam, info->lparam, &data );
3112 if (data.count == -1)
3114 WARN( "cannot pack message %x\n", info->msg );
3115 return FALSE;
3118 else if (info->type == MSG_CALLBACK)
3120 msg_data.callback.callback = wine_server_client_ptr( info->callback );
3121 msg_data.callback.data = info->data;
3122 msg_data.callback.result = 0;
3123 data.data[0] = &msg_data;
3124 data.size[0] = sizeof(msg_data.callback);
3125 data.count = 1;
3127 else if (info->type == MSG_POSTED && info->msg >= WM_DDE_FIRST && info->msg <= WM_DDE_LAST)
3129 return post_dde_message( &data, info );
3132 SERVER_START_REQ( send_message )
3134 req->id = info->dest_tid;
3135 req->type = info->type;
3136 req->flags = 0;
3137 req->win = wine_server_user_handle( info->hwnd );
3138 req->msg = info->msg;
3139 req->wparam = info->wparam;
3140 req->lparam = info->lparam;
3141 req->timeout = timeout;
3143 if (info->flags & SMTO_ABORTIFHUNG) req->flags |= SEND_MSG_ABORT_IF_HUNG;
3144 for (i = 0; i < data.count; i++) wine_server_add_data( req, data.data[i], data.size[i] );
3145 if ((res = wine_server_call( req )))
3147 if (res == STATUS_INVALID_PARAMETER)
3148 /* FIXME: find a STATUS_ value for this one */
3149 SetLastError( ERROR_INVALID_THREAD_ID );
3150 else
3151 SetLastError( RtlNtStatusToDosError(res) );
3154 SERVER_END_REQ;
3155 return !res;
3159 /***********************************************************************
3160 * retrieve_reply
3162 * Retrieve a message reply from the server.
3164 static LRESULT retrieve_reply( const struct send_message_info *info,
3165 size_t reply_size, LRESULT *result )
3167 NTSTATUS status;
3168 void *reply_data = NULL;
3170 if (reply_size)
3172 if (!(reply_data = HeapAlloc( GetProcessHeap(), 0, reply_size )))
3174 WARN( "no memory for reply, will be truncated\n" );
3175 reply_size = 0;
3178 SERVER_START_REQ( get_message_reply )
3180 req->cancel = 1;
3181 if (reply_size) wine_server_set_reply( req, reply_data, reply_size );
3182 if (!(status = wine_server_call( req ))) *result = reply->result;
3183 reply_size = wine_server_reply_size( reply );
3185 SERVER_END_REQ;
3186 if (!status && reply_size)
3187 unpack_reply( info->hwnd, info->msg, info->wparam, info->lparam, reply_data, reply_size );
3189 HeapFree( GetProcessHeap(), 0, reply_data );
3191 TRACE( "hwnd %p msg %x (%s) wp %lx lp %lx got reply %lx (err=%d)\n",
3192 info->hwnd, info->msg, SPY_GetMsgName(info->msg, info->hwnd), info->wparam,
3193 info->lparam, *result, status );
3195 /* MSDN states that last error is 0 on timeout, but at least NT4 returns ERROR_TIMEOUT */
3196 if (status) SetLastError( RtlNtStatusToDosError(status) );
3197 return !status;
3201 /***********************************************************************
3202 * send_inter_thread_message
3204 static LRESULT send_inter_thread_message( const struct send_message_info *info, LRESULT *res_ptr )
3206 size_t reply_size = 0;
3208 TRACE( "hwnd %p msg %x (%s) wp %lx lp %lx\n",
3209 info->hwnd, info->msg, SPY_GetMsgName(info->msg, info->hwnd), info->wparam, info->lparam );
3211 USER_CheckNotLock();
3213 if (!put_message_in_queue( info, &reply_size )) return 0;
3215 /* there's no reply to wait for on notify/callback messages */
3216 if (info->type == MSG_NOTIFY || info->type == MSG_CALLBACK) return 1;
3218 wait_message_reply( info->flags );
3219 return retrieve_reply( info, reply_size, res_ptr );
3223 /***********************************************************************
3224 * send_inter_thread_callback
3226 static LRESULT send_inter_thread_callback( HWND hwnd, UINT msg, WPARAM wp, LPARAM lp,
3227 LRESULT *result, void *arg )
3229 struct send_message_info *info = arg;
3230 info->hwnd = hwnd;
3231 info->msg = msg;
3232 info->wparam = wp;
3233 info->lparam = lp;
3234 return send_inter_thread_message( info, result );
3237 static BOOL is_message_broadcastable(UINT msg)
3239 return msg < WM_USER || msg >= 0xc000;
3242 /***********************************************************************
3243 * send_message
3245 * Backend implementation of the various SendMessage functions.
3247 static BOOL send_message( struct send_message_info *info, DWORD_PTR *res_ptr, BOOL unicode )
3249 DWORD dest_pid;
3250 BOOL ret;
3251 LRESULT result;
3253 if (is_broadcast(info->hwnd))
3255 if (is_message_broadcastable( info->msg ))
3256 EnumWindows( broadcast_message_callback, (LPARAM)info );
3257 if (res_ptr) *res_ptr = 1;
3258 return TRUE;
3261 if (!(info->dest_tid = GetWindowThreadProcessId( info->hwnd, &dest_pid ))) return FALSE;
3263 if (USER_IsExitingThread( info->dest_tid )) return FALSE;
3265 SPY_EnterMessage( SPY_SENDMESSAGE, info->hwnd, info->msg, info->wparam, info->lparam );
3267 if (info->dest_tid == GetCurrentThreadId())
3269 result = call_window_proc( info->hwnd, info->msg, info->wparam, info->lparam,
3270 unicode, TRUE, info->wm_char );
3271 if (info->type == MSG_CALLBACK)
3272 call_sendmsg_callback( info->callback, info->hwnd, info->msg, info->data, result );
3273 ret = TRUE;
3275 else
3277 if (dest_pid != GetCurrentProcessId() && (info->type == MSG_ASCII || info->type == MSG_UNICODE))
3278 info->type = MSG_OTHER_PROCESS;
3280 /* MSG_ASCII can be sent unconverted except for WM_CHAR; everything else needs to be Unicode */
3281 if (!unicode && is_unicode_message( info->msg ) &&
3282 (info->type != MSG_ASCII || info->msg == WM_CHAR))
3283 ret = WINPROC_CallProcAtoW( send_inter_thread_callback, info->hwnd, info->msg,
3284 info->wparam, info->lparam, &result, info, info->wm_char );
3285 else
3286 ret = send_inter_thread_message( info, &result );
3289 SPY_ExitMessage( SPY_RESULT_OK, info->hwnd, info->msg, result, info->wparam, info->lparam );
3290 if (ret && res_ptr) *res_ptr = result;
3291 return ret;
3295 /***********************************************************************
3296 * send_hardware_message
3298 NTSTATUS send_hardware_message( HWND hwnd, const INPUT *input, UINT flags )
3300 struct user_key_state_info *key_state_info = get_user_thread_info()->key_state;
3301 struct send_message_info info;
3302 int prev_x, prev_y, new_x, new_y;
3303 INT counter = global_key_state_counter;
3304 NTSTATUS ret;
3305 BOOL wait;
3307 info.type = MSG_HARDWARE;
3308 info.dest_tid = 0;
3309 info.hwnd = hwnd;
3310 info.flags = 0;
3311 info.timeout = 0;
3313 SERVER_START_REQ( send_hardware_message )
3315 req->win = wine_server_user_handle( hwnd );
3316 req->flags = flags;
3317 req->input.type = input->type;
3318 switch (input->type)
3320 case INPUT_MOUSE:
3321 req->input.mouse.x = input->u.mi.dx;
3322 req->input.mouse.y = input->u.mi.dy;
3323 req->input.mouse.data = input->u.mi.mouseData;
3324 req->input.mouse.flags = input->u.mi.dwFlags;
3325 req->input.mouse.time = input->u.mi.time;
3326 req->input.mouse.info = input->u.mi.dwExtraInfo;
3327 break;
3328 case INPUT_KEYBOARD:
3329 req->input.kbd.vkey = input->u.ki.wVk;
3330 req->input.kbd.scan = input->u.ki.wScan;
3331 req->input.kbd.flags = input->u.ki.dwFlags;
3332 req->input.kbd.time = input->u.ki.time;
3333 req->input.kbd.info = input->u.ki.dwExtraInfo;
3334 break;
3335 case INPUT_HARDWARE:
3336 req->input.hw.msg = input->u.hi.uMsg;
3337 req->input.hw.lparam = MAKELONG( input->u.hi.wParamL, input->u.hi.wParamH );
3338 break;
3340 if (key_state_info) wine_server_set_reply( req, key_state_info->state,
3341 sizeof(key_state_info->state) );
3342 ret = wine_server_call( req );
3343 wait = reply->wait;
3344 prev_x = reply->prev_x;
3345 prev_y = reply->prev_y;
3346 new_x = reply->new_x;
3347 new_y = reply->new_y;
3349 SERVER_END_REQ;
3351 if (!ret)
3353 if (key_state_info)
3355 key_state_info->time = GetTickCount();
3356 key_state_info->counter = counter;
3358 if ((flags & SEND_HWMSG_INJECTED) && (prev_x != new_x || prev_y != new_y))
3359 USER_Driver->pSetCursorPos( new_x, new_y );
3362 if (wait)
3364 LRESULT ignored;
3365 wait_message_reply( 0 );
3366 retrieve_reply( &info, 0, &ignored );
3368 return ret;
3372 /***********************************************************************
3373 * MSG_SendInternalMessageTimeout
3375 * Same as SendMessageTimeoutW but sends the message to a specific thread
3376 * without requiring a window handle. Only works for internal Wine messages.
3378 LRESULT MSG_SendInternalMessageTimeout( DWORD dest_pid, DWORD dest_tid,
3379 UINT msg, WPARAM wparam, LPARAM lparam,
3380 UINT flags, UINT timeout, PDWORD_PTR res_ptr )
3382 struct send_message_info info;
3383 LRESULT ret, result;
3385 assert( msg & 0x80000000 ); /* must be an internal Wine message */
3387 info.type = MSG_UNICODE;
3388 info.dest_tid = dest_tid;
3389 info.hwnd = 0;
3390 info.msg = msg;
3391 info.wparam = wparam;
3392 info.lparam = lparam;
3393 info.flags = flags;
3394 info.timeout = timeout;
3396 if (USER_IsExitingThread( dest_tid )) return 0;
3398 if (dest_tid == GetCurrentThreadId())
3400 result = handle_internal_message( 0, msg, wparam, lparam );
3401 ret = 1;
3403 else
3405 if (dest_pid != GetCurrentProcessId()) info.type = MSG_OTHER_PROCESS;
3406 ret = send_inter_thread_message( &info, &result );
3408 if (ret && res_ptr) *res_ptr = result;
3409 return ret;
3413 /***********************************************************************
3414 * SendMessageTimeoutW (USER32.@)
3416 LRESULT WINAPI SendMessageTimeoutW( HWND hwnd, UINT msg, WPARAM wparam, LPARAM lparam,
3417 UINT flags, UINT timeout, PDWORD_PTR res_ptr )
3419 struct send_message_info info;
3421 info.type = MSG_UNICODE;
3422 info.hwnd = hwnd;
3423 info.msg = msg;
3424 info.wparam = wparam;
3425 info.lparam = lparam;
3426 info.flags = flags;
3427 info.timeout = timeout;
3429 return send_message( &info, res_ptr, TRUE );
3432 /***********************************************************************
3433 * SendMessageTimeoutA (USER32.@)
3435 LRESULT WINAPI SendMessageTimeoutA( HWND hwnd, UINT msg, WPARAM wparam, LPARAM lparam,
3436 UINT flags, UINT timeout, PDWORD_PTR res_ptr )
3438 struct send_message_info info;
3440 info.type = MSG_ASCII;
3441 info.hwnd = hwnd;
3442 info.msg = msg;
3443 info.wparam = wparam;
3444 info.lparam = lparam;
3445 info.flags = flags;
3446 info.timeout = timeout;
3447 info.wm_char = WMCHAR_MAP_SENDMESSAGETIMEOUT;
3449 return send_message( &info, res_ptr, FALSE );
3453 /***********************************************************************
3454 * SendMessageW (USER32.@)
3456 LRESULT WINAPI SendMessageW( HWND hwnd, UINT msg, WPARAM wparam, LPARAM lparam )
3458 DWORD_PTR res = 0;
3459 struct send_message_info info;
3461 info.type = MSG_UNICODE;
3462 info.hwnd = hwnd;
3463 info.msg = msg;
3464 info.wparam = wparam;
3465 info.lparam = lparam;
3466 info.flags = SMTO_NORMAL;
3467 info.timeout = 0;
3469 send_message( &info, &res, TRUE );
3470 return res;
3474 /***********************************************************************
3475 * SendMessageA (USER32.@)
3477 LRESULT WINAPI SendMessageA( HWND hwnd, UINT msg, WPARAM wparam, LPARAM lparam )
3479 DWORD_PTR res = 0;
3480 struct send_message_info info;
3482 info.type = MSG_ASCII;
3483 info.hwnd = hwnd;
3484 info.msg = msg;
3485 info.wparam = wparam;
3486 info.lparam = lparam;
3487 info.flags = SMTO_NORMAL;
3488 info.timeout = 0;
3489 info.wm_char = WMCHAR_MAP_SENDMESSAGE;
3491 send_message( &info, &res, FALSE );
3492 return res;
3496 /***********************************************************************
3497 * SendNotifyMessageA (USER32.@)
3499 BOOL WINAPI SendNotifyMessageA( HWND hwnd, UINT msg, WPARAM wparam, LPARAM lparam )
3501 struct send_message_info info;
3503 if (is_pointer_message( msg, wparam ))
3505 SetLastError( ERROR_MESSAGE_SYNC_ONLY );
3506 return FALSE;
3509 info.type = MSG_NOTIFY;
3510 info.hwnd = hwnd;
3511 info.msg = msg;
3512 info.wparam = wparam;
3513 info.lparam = lparam;
3514 info.flags = 0;
3515 info.wm_char = WMCHAR_MAP_SENDMESSAGETIMEOUT;
3517 return send_message( &info, NULL, FALSE );
3521 /***********************************************************************
3522 * SendNotifyMessageW (USER32.@)
3524 BOOL WINAPI SendNotifyMessageW( HWND hwnd, UINT msg, WPARAM wparam, LPARAM lparam )
3526 struct send_message_info info;
3528 if (is_pointer_message( msg, wparam ))
3530 SetLastError( ERROR_MESSAGE_SYNC_ONLY );
3531 return FALSE;
3534 info.type = MSG_NOTIFY;
3535 info.hwnd = hwnd;
3536 info.msg = msg;
3537 info.wparam = wparam;
3538 info.lparam = lparam;
3539 info.flags = 0;
3541 return send_message( &info, NULL, TRUE );
3545 /***********************************************************************
3546 * SendMessageCallbackA (USER32.@)
3548 BOOL WINAPI SendMessageCallbackA( HWND hwnd, UINT msg, WPARAM wparam, LPARAM lparam,
3549 SENDASYNCPROC callback, ULONG_PTR data )
3551 struct send_message_info info;
3553 if (is_pointer_message( msg, wparam ))
3555 SetLastError( ERROR_MESSAGE_SYNC_ONLY );
3556 return FALSE;
3559 info.type = MSG_CALLBACK;
3560 info.hwnd = hwnd;
3561 info.msg = msg;
3562 info.wparam = wparam;
3563 info.lparam = lparam;
3564 info.callback = callback;
3565 info.data = data;
3566 info.flags = 0;
3567 info.wm_char = WMCHAR_MAP_SENDMESSAGETIMEOUT;
3569 return send_message( &info, NULL, FALSE );
3573 /***********************************************************************
3574 * SendMessageCallbackW (USER32.@)
3576 BOOL WINAPI SendMessageCallbackW( HWND hwnd, UINT msg, WPARAM wparam, LPARAM lparam,
3577 SENDASYNCPROC callback, ULONG_PTR data )
3579 struct send_message_info info;
3581 if (is_pointer_message( msg, wparam ))
3583 SetLastError( ERROR_MESSAGE_SYNC_ONLY );
3584 return FALSE;
3587 info.type = MSG_CALLBACK;
3588 info.hwnd = hwnd;
3589 info.msg = msg;
3590 info.wparam = wparam;
3591 info.lparam = lparam;
3592 info.callback = callback;
3593 info.data = data;
3594 info.flags = 0;
3596 return send_message( &info, NULL, TRUE );
3600 /***********************************************************************
3601 * ReplyMessage (USER32.@)
3603 BOOL WINAPI ReplyMessage( LRESULT result )
3605 struct received_message_info *info = get_user_thread_info()->receive_info;
3607 if (!info) return FALSE;
3608 reply_message( info, result, FALSE );
3609 return TRUE;
3613 /***********************************************************************
3614 * InSendMessage (USER32.@)
3616 BOOL WINAPI InSendMessage(void)
3618 return (InSendMessageEx( NULL ) & (ISMEX_SEND | ISMEX_NOTIFY | ISMEX_CALLBACK)) != 0;
3622 /***********************************************************************
3623 * InSendMessageEx (USER32.@)
3625 DWORD WINAPI InSendMessageEx( LPVOID reserved )
3627 struct received_message_info *info = get_user_thread_info()->receive_info;
3629 if (info) return info->flags;
3630 return ISMEX_NOSEND;
3634 /***********************************************************************
3635 * PostMessageA (USER32.@)
3637 BOOL WINAPI PostMessageA( HWND hwnd, UINT msg, WPARAM wparam, LPARAM lparam )
3639 if (!map_wparam_AtoW( msg, &wparam, WMCHAR_MAP_POSTMESSAGE )) return TRUE;
3640 return PostMessageW( hwnd, msg, wparam, lparam );
3644 /***********************************************************************
3645 * PostMessageW (USER32.@)
3647 BOOL WINAPI PostMessageW( HWND hwnd, UINT msg, WPARAM wparam, LPARAM lparam )
3649 struct send_message_info info;
3651 if (is_pointer_message( msg, wparam ))
3653 SetLastError( ERROR_MESSAGE_SYNC_ONLY );
3654 return FALSE;
3657 TRACE( "hwnd %p msg %x (%s) wp %lx lp %lx\n",
3658 hwnd, msg, SPY_GetMsgName(msg, hwnd), wparam, lparam );
3660 info.type = MSG_POSTED;
3661 info.hwnd = hwnd;
3662 info.msg = msg;
3663 info.wparam = wparam;
3664 info.lparam = lparam;
3665 info.flags = 0;
3667 if (is_broadcast(hwnd))
3669 if (is_message_broadcastable( info.msg ))
3670 EnumWindows( broadcast_message_callback, (LPARAM)&info );
3671 return TRUE;
3674 if (!hwnd) return PostThreadMessageW( GetCurrentThreadId(), msg, wparam, lparam );
3676 if (!(info.dest_tid = GetWindowThreadProcessId( hwnd, NULL ))) return FALSE;
3678 if (USER_IsExitingThread( info.dest_tid )) return TRUE;
3680 return put_message_in_queue( &info, NULL );
3684 /**********************************************************************
3685 * PostThreadMessageA (USER32.@)
3687 BOOL WINAPI PostThreadMessageA( DWORD thread, UINT msg, WPARAM wparam, LPARAM lparam )
3689 if (!map_wparam_AtoW( msg, &wparam, WMCHAR_MAP_POSTMESSAGE )) return TRUE;
3690 return PostThreadMessageW( thread, msg, wparam, lparam );
3694 /**********************************************************************
3695 * PostThreadMessageW (USER32.@)
3697 BOOL WINAPI PostThreadMessageW( DWORD thread, UINT msg, WPARAM wparam, LPARAM lparam )
3699 struct send_message_info info;
3701 if (is_pointer_message( msg, wparam ))
3703 SetLastError( ERROR_MESSAGE_SYNC_ONLY );
3704 return FALSE;
3706 if (USER_IsExitingThread( thread )) return TRUE;
3708 info.type = MSG_POSTED;
3709 info.dest_tid = thread;
3710 info.hwnd = 0;
3711 info.msg = msg;
3712 info.wparam = wparam;
3713 info.lparam = lparam;
3714 info.flags = 0;
3715 return put_message_in_queue( &info, NULL );
3719 /***********************************************************************
3720 * PostQuitMessage (USER32.@)
3722 * Posts a quit message to the current thread's message queue.
3724 * PARAMS
3725 * exit_code [I] Exit code to return from message loop.
3727 * RETURNS
3728 * Nothing.
3730 * NOTES
3731 * This function is not the same as calling:
3732 *|PostThreadMessage(GetCurrentThreadId(), WM_QUIT, exit_code, 0);
3733 * It instead sets a flag in the message queue that signals it to generate
3734 * a WM_QUIT message when there are no other pending sent or posted messages
3735 * in the queue.
3737 void WINAPI PostQuitMessage( INT exit_code )
3739 SERVER_START_REQ( post_quit_message )
3741 req->exit_code = exit_code;
3742 wine_server_call( req );
3744 SERVER_END_REQ;
3747 /* check for driver events if we detect that the app is not properly consuming messages */
3748 static inline void check_for_driver_events( UINT msg )
3750 if (get_user_thread_info()->message_count > 200)
3752 flush_window_surfaces( FALSE );
3753 USER_Driver->pMsgWaitForMultipleObjectsEx( 0, NULL, 0, QS_ALLINPUT, 0 );
3755 else if (msg == WM_TIMER || msg == WM_SYSTIMER)
3757 /* driver events should have priority over timers, so make sure we'll check for them soon */
3758 get_user_thread_info()->message_count += 100;
3760 else get_user_thread_info()->message_count++;
3763 /***********************************************************************
3764 * PeekMessageW (USER32.@)
3766 BOOL WINAPI DECLSPEC_HOTPATCH PeekMessageW( MSG *msg_out, HWND hwnd, UINT first, UINT last, UINT flags )
3768 MSG msg;
3770 USER_CheckNotLock();
3771 check_for_driver_events( 0 );
3773 if (!peek_message( &msg, hwnd, first, last, flags, 0 ))
3775 DWORD ret;
3777 flush_window_surfaces( TRUE );
3778 ret = wow_handlers.wait_message( 0, NULL, 0, QS_ALLINPUT, 0 );
3779 /* if we received driver events, check again for a pending message */
3780 if (ret == WAIT_TIMEOUT || !peek_message( &msg, hwnd, first, last, flags, 0 )) return FALSE;
3783 check_for_driver_events( msg.message );
3785 /* copy back our internal safe copy of message data to msg_out.
3786 * msg_out is a variable from the *program*, so it can't be used
3787 * internally as it can get "corrupted" by our use of SendMessage()
3788 * (back to the program) inside the message handling itself. */
3789 if (!msg_out)
3791 SetLastError( ERROR_NOACCESS );
3792 return FALSE;
3794 *msg_out = msg;
3795 return TRUE;
3799 /***********************************************************************
3800 * PeekMessageA (USER32.@)
3802 BOOL WINAPI DECLSPEC_HOTPATCH PeekMessageA( MSG *msg, HWND hwnd, UINT first, UINT last, UINT flags )
3804 if (get_pending_wmchar( msg, first, last, (flags & PM_REMOVE) )) return TRUE;
3805 if (!PeekMessageW( msg, hwnd, first, last, flags )) return FALSE;
3806 map_wparam_WtoA( msg, (flags & PM_REMOVE) );
3807 return TRUE;
3811 /***********************************************************************
3812 * GetMessageW (USER32.@)
3814 BOOL WINAPI DECLSPEC_HOTPATCH GetMessageW( MSG *msg, HWND hwnd, UINT first, UINT last )
3816 HANDLE server_queue = get_server_queue_handle();
3817 unsigned int mask = QS_POSTMESSAGE | QS_SENDMESSAGE; /* Always selected */
3819 USER_CheckNotLock();
3820 check_for_driver_events( 0 );
3822 if (first || last)
3824 if ((first <= WM_KEYLAST) && (last >= WM_KEYFIRST)) mask |= QS_KEY;
3825 if ( ((first <= WM_MOUSELAST) && (last >= WM_MOUSEFIRST)) ||
3826 ((first <= WM_NCMOUSELAST) && (last >= WM_NCMOUSEFIRST)) ) mask |= QS_MOUSE;
3827 if ((first <= WM_TIMER) && (last >= WM_TIMER)) mask |= QS_TIMER;
3828 if ((first <= WM_SYSTIMER) && (last >= WM_SYSTIMER)) mask |= QS_TIMER;
3829 if ((first <= WM_PAINT) && (last >= WM_PAINT)) mask |= QS_PAINT;
3831 else mask = QS_ALLINPUT;
3833 while (!peek_message( msg, hwnd, first, last, PM_REMOVE | (mask << 16), mask ))
3835 wait_objects( 1, &server_queue, INFINITE, mask & (QS_SENDMESSAGE | QS_SMRESULT), mask, 0 );
3837 check_for_driver_events( msg->message );
3839 return (msg->message != WM_QUIT);
3843 /***********************************************************************
3844 * GetMessageA (USER32.@)
3846 BOOL WINAPI DECLSPEC_HOTPATCH GetMessageA( MSG *msg, HWND hwnd, UINT first, UINT last )
3848 if (get_pending_wmchar( msg, first, last, TRUE )) return TRUE;
3849 GetMessageW( msg, hwnd, first, last );
3850 map_wparam_WtoA( msg, TRUE );
3851 return (msg->message != WM_QUIT);
3855 /***********************************************************************
3856 * IsDialogMessageA (USER32.@)
3857 * IsDialogMessage (USER32.@)
3859 BOOL WINAPI IsDialogMessageA( HWND hwndDlg, LPMSG pmsg )
3861 MSG msg = *pmsg;
3862 map_wparam_AtoW( msg.message, &msg.wParam, WMCHAR_MAP_NOMAPPING );
3863 return IsDialogMessageW( hwndDlg, &msg );
3867 /***********************************************************************
3868 * TranslateMessage (USER32.@)
3870 * Implementation of TranslateMessage.
3872 * TranslateMessage translates virtual-key messages into character-messages,
3873 * as follows :
3874 * WM_KEYDOWN/WM_KEYUP combinations produce a WM_CHAR or WM_DEADCHAR message.
3875 * ditto replacing WM_* with WM_SYS*
3876 * This produces WM_CHAR messages only for keys mapped to ASCII characters
3877 * by the keyboard driver.
3879 * If the message is WM_KEYDOWN, WM_KEYUP, WM_SYSKEYDOWN, or WM_SYSKEYUP, the
3880 * return value is nonzero, regardless of the translation.
3883 BOOL WINAPI TranslateMessage( const MSG *msg )
3885 UINT message;
3886 WCHAR wp[8];
3887 BYTE state[256];
3888 INT len;
3890 if (msg->message < WM_KEYFIRST || msg->message > WM_KEYLAST) return FALSE;
3891 if (msg->message != WM_KEYDOWN && msg->message != WM_SYSKEYDOWN) return TRUE;
3893 TRACE_(key)("Translating key %s (%04lX), scancode %04x\n",
3894 SPY_GetVKeyName(msg->wParam), msg->wParam, HIWORD(msg->lParam));
3896 switch (msg->wParam)
3898 case VK_PACKET:
3899 message = (msg->message == WM_KEYDOWN) ? WM_CHAR : WM_SYSCHAR;
3900 TRACE_(key)("PostMessageW(%p,%s,%04x,%08x)\n",
3901 msg->hwnd, SPY_GetMsgName(message, msg->hwnd), HIWORD(msg->lParam), LOWORD(msg->lParam));
3902 PostMessageW( msg->hwnd, message, HIWORD(msg->lParam), LOWORD(msg->lParam));
3903 return TRUE;
3905 case VK_PROCESSKEY:
3906 return ImmTranslateMessage(msg->hwnd, msg->message, msg->wParam, msg->lParam);
3909 GetKeyboardState( state );
3910 len = ToUnicode(msg->wParam, HIWORD(msg->lParam), state, wp, sizeof(wp)/sizeof(WCHAR), 0);
3911 if (len == -1)
3913 message = (msg->message == WM_KEYDOWN) ? WM_DEADCHAR : WM_SYSDEADCHAR;
3914 TRACE_(key)("-1 -> PostMessageW(%p,%s,%04x,%08lx)\n",
3915 msg->hwnd, SPY_GetMsgName(message, msg->hwnd), wp[0], msg->lParam);
3916 PostMessageW( msg->hwnd, message, wp[0], msg->lParam );
3918 else if (len > 0)
3920 INT i;
3922 message = (msg->message == WM_KEYDOWN) ? WM_CHAR : WM_SYSCHAR;
3923 TRACE_(key)("%d -> PostMessageW(%p,%s,<x>,%08lx) for <x> in %s\n", len, msg->hwnd,
3924 SPY_GetMsgName(message, msg->hwnd), msg->lParam, debugstr_wn(wp, len));
3925 for (i = 0; i < len; i++)
3926 PostMessageW( msg->hwnd, message, wp[i], msg->lParam );
3928 return TRUE;
3932 /***********************************************************************
3933 * DispatchMessageA (USER32.@)
3935 * See DispatchMessageW.
3937 LRESULT WINAPI DECLSPEC_HOTPATCH DispatchMessageA( const MSG* msg )
3939 LRESULT retval;
3941 /* Process timer messages */
3942 if ((msg->message == WM_TIMER) || (msg->message == WM_SYSTIMER))
3944 if (msg->lParam)
3946 __TRY
3948 retval = CallWindowProcA( (WNDPROC)msg->lParam, msg->hwnd,
3949 msg->message, msg->wParam, GetTickCount() );
3951 __EXCEPT_ALL
3953 retval = 0;
3955 __ENDTRY
3956 return retval;
3959 if (!msg->hwnd) return 0;
3961 SPY_EnterMessage( SPY_DISPATCHMESSAGE, msg->hwnd, msg->message,
3962 msg->wParam, msg->lParam );
3964 if (!WINPROC_call_window( msg->hwnd, msg->message, msg->wParam, msg->lParam,
3965 &retval, FALSE, WMCHAR_MAP_DISPATCHMESSAGE ))
3967 if (!IsWindow( msg->hwnd )) SetLastError( ERROR_INVALID_WINDOW_HANDLE );
3968 else SetLastError( ERROR_MESSAGE_SYNC_ONLY );
3969 retval = 0;
3972 SPY_ExitMessage( SPY_RESULT_OK, msg->hwnd, msg->message, retval,
3973 msg->wParam, msg->lParam );
3975 if (msg->message == WM_PAINT)
3977 /* send a WM_NCPAINT and WM_ERASEBKGND if the non-client area is still invalid */
3978 HRGN hrgn = CreateRectRgn( 0, 0, 0, 0 );
3979 GetUpdateRgn( msg->hwnd, hrgn, TRUE );
3980 DeleteObject( hrgn );
3982 return retval;
3986 /***********************************************************************
3987 * DispatchMessageW (USER32.@) Process a message
3989 * Process the message specified in the structure *_msg_.
3991 * If the lpMsg parameter points to a WM_TIMER message and the
3992 * parameter of the WM_TIMER message is not NULL, the lParam parameter
3993 * points to the function that is called instead of the window
3994 * procedure. The function stored in lParam (timer callback) is protected
3995 * from causing page-faults.
3997 * The message must be valid.
3999 * RETURNS
4001 * DispatchMessage() returns the result of the window procedure invoked.
4003 * CONFORMANCE
4005 * ECMA-234, Win32
4008 LRESULT WINAPI DECLSPEC_HOTPATCH DispatchMessageW( const MSG* msg )
4010 LRESULT retval;
4012 /* Process timer messages */
4013 if ((msg->message == WM_TIMER) || (msg->message == WM_SYSTIMER))
4015 if (msg->lParam)
4017 __TRY
4019 retval = CallWindowProcW( (WNDPROC)msg->lParam, msg->hwnd,
4020 msg->message, msg->wParam, GetTickCount() );
4022 __EXCEPT_ALL
4024 retval = 0;
4026 __ENDTRY
4027 return retval;
4030 if (!msg->hwnd) return 0;
4032 SPY_EnterMessage( SPY_DISPATCHMESSAGE, msg->hwnd, msg->message,
4033 msg->wParam, msg->lParam );
4035 if (!WINPROC_call_window( msg->hwnd, msg->message, msg->wParam, msg->lParam,
4036 &retval, TRUE, WMCHAR_MAP_DISPATCHMESSAGE ))
4038 if (!IsWindow( msg->hwnd )) SetLastError( ERROR_INVALID_WINDOW_HANDLE );
4039 else SetLastError( ERROR_MESSAGE_SYNC_ONLY );
4040 retval = 0;
4043 SPY_ExitMessage( SPY_RESULT_OK, msg->hwnd, msg->message, retval,
4044 msg->wParam, msg->lParam );
4046 if (msg->message == WM_PAINT)
4048 /* send a WM_NCPAINT and WM_ERASEBKGND if the non-client area is still invalid */
4049 HRGN hrgn = CreateRectRgn( 0, 0, 0, 0 );
4050 GetUpdateRgn( msg->hwnd, hrgn, TRUE );
4051 DeleteObject( hrgn );
4053 return retval;
4057 /***********************************************************************
4058 * GetMessagePos (USER.119)
4059 * GetMessagePos (USER32.@)
4061 * The GetMessagePos() function returns a long value representing a
4062 * cursor position, in screen coordinates, when the last message
4063 * retrieved by the GetMessage() function occurs. The x-coordinate is
4064 * in the low-order word of the return value, the y-coordinate is in
4065 * the high-order word. The application can use the MAKEPOINT()
4066 * macro to obtain a POINT structure from the return value.
4068 * For the current cursor position, use GetCursorPos().
4070 * RETURNS
4072 * Cursor position of last message on success, zero on failure.
4074 * CONFORMANCE
4076 * ECMA-234, Win32
4079 DWORD WINAPI GetMessagePos(void)
4081 return get_user_thread_info()->GetMessagePosVal;
4085 /***********************************************************************
4086 * GetMessageTime (USER.120)
4087 * GetMessageTime (USER32.@)
4089 * GetMessageTime() returns the message time for the last message
4090 * retrieved by the function. The time is measured in milliseconds with
4091 * the same offset as GetTickCount().
4093 * Since the tick count wraps, this is only useful for moderately short
4094 * relative time comparisons.
4096 * RETURNS
4098 * Time of last message on success, zero on failure.
4100 LONG WINAPI GetMessageTime(void)
4102 return get_user_thread_info()->GetMessageTimeVal;
4106 /***********************************************************************
4107 * GetMessageExtraInfo (USER.288)
4108 * GetMessageExtraInfo (USER32.@)
4110 LPARAM WINAPI GetMessageExtraInfo(void)
4112 return get_user_thread_info()->GetMessageExtraInfoVal;
4116 /***********************************************************************
4117 * SetMessageExtraInfo (USER32.@)
4119 LPARAM WINAPI SetMessageExtraInfo(LPARAM lParam)
4121 struct user_thread_info *thread_info = get_user_thread_info();
4122 LONG old_value = thread_info->GetMessageExtraInfoVal;
4123 thread_info->GetMessageExtraInfoVal = lParam;
4124 return old_value;
4128 /***********************************************************************
4129 * WaitMessage (USER.112) Suspend thread pending messages
4130 * WaitMessage (USER32.@) Suspend thread pending messages
4132 * WaitMessage() suspends a thread until events appear in the thread's
4133 * queue.
4135 BOOL WINAPI WaitMessage(void)
4137 return (MsgWaitForMultipleObjectsEx( 0, NULL, INFINITE, QS_ALLINPUT, 0 ) != WAIT_FAILED);
4141 /***********************************************************************
4142 * MsgWaitForMultipleObjectsEx (USER32.@)
4144 DWORD WINAPI MsgWaitForMultipleObjectsEx( DWORD count, const HANDLE *pHandles,
4145 DWORD timeout, DWORD mask, DWORD flags )
4147 HANDLE handles[MAXIMUM_WAIT_OBJECTS];
4148 DWORD i;
4150 if (count > MAXIMUM_WAIT_OBJECTS-1)
4152 SetLastError( ERROR_INVALID_PARAMETER );
4153 return WAIT_FAILED;
4156 /* add the queue to the handle list */
4157 for (i = 0; i < count; i++) handles[i] = pHandles[i];
4158 handles[count] = get_server_queue_handle();
4160 return wait_objects( count+1, handles, timeout,
4161 (flags & MWMO_INPUTAVAILABLE) ? mask : 0, mask, flags );
4165 /***********************************************************************
4166 * MsgWaitForMultipleObjects (USER32.@)
4168 DWORD WINAPI MsgWaitForMultipleObjects( DWORD count, const HANDLE *handles,
4169 BOOL wait_all, DWORD timeout, DWORD mask )
4171 return MsgWaitForMultipleObjectsEx( count, handles, timeout, mask,
4172 wait_all ? MWMO_WAITALL : 0 );
4176 /***********************************************************************
4177 * WaitForInputIdle (USER32.@)
4179 DWORD WINAPI WaitForInputIdle( HANDLE hProcess, DWORD dwTimeOut )
4181 DWORD start_time, elapsed, ret;
4182 HANDLE handles[2];
4184 handles[0] = hProcess;
4185 SERVER_START_REQ( get_process_idle_event )
4187 req->handle = wine_server_obj_handle( hProcess );
4188 wine_server_call_err( req );
4189 handles[1] = wine_server_ptr_handle( reply->event );
4191 SERVER_END_REQ;
4192 if (!handles[1]) return WAIT_FAILED; /* no event to wait on */
4194 start_time = GetTickCount();
4195 elapsed = 0;
4197 TRACE("waiting for %p\n", handles[1] );
4200 ret = MsgWaitForMultipleObjects ( 2, handles, FALSE, dwTimeOut - elapsed, QS_SENDMESSAGE );
4201 switch (ret)
4203 case WAIT_OBJECT_0:
4204 return 0;
4205 case WAIT_OBJECT_0+2:
4206 process_sent_messages();
4207 break;
4208 case WAIT_TIMEOUT:
4209 case WAIT_FAILED:
4210 TRACE("timeout or error\n");
4211 return ret;
4212 default:
4213 TRACE("finished\n");
4214 return 0;
4216 if (dwTimeOut != INFINITE)
4218 elapsed = GetTickCount() - start_time;
4219 if (elapsed > dwTimeOut)
4220 break;
4223 while (1);
4225 return WAIT_TIMEOUT;
4229 /***********************************************************************
4230 * RegisterWindowMessageA (USER32.@)
4231 * RegisterWindowMessage (USER.118)
4233 UINT WINAPI RegisterWindowMessageA( LPCSTR str )
4235 UINT ret = GlobalAddAtomA(str);
4236 TRACE("%s, ret=%x\n", str, ret);
4237 return ret;
4241 /***********************************************************************
4242 * RegisterWindowMessageW (USER32.@)
4244 UINT WINAPI RegisterWindowMessageW( LPCWSTR str )
4246 UINT ret = GlobalAddAtomW(str);
4247 TRACE("%s ret=%x\n", debugstr_w(str), ret);
4248 return ret;
4251 typedef struct BroadcastParm
4253 DWORD flags;
4254 LPDWORD recipients;
4255 UINT msg;
4256 WPARAM wp;
4257 LPARAM lp;
4258 BOOL success;
4259 HWINSTA winsta;
4260 } BroadcastParm;
4262 static BOOL CALLBACK bcast_childwindow( HWND hw, LPARAM lp )
4264 BroadcastParm *parm = (BroadcastParm*)lp;
4265 DWORD_PTR retval = 0;
4266 LRESULT lresult;
4268 if (parm->flags & BSF_IGNORECURRENTTASK && WIN_IsCurrentProcess(hw))
4270 TRACE("Not telling myself %p\n", hw);
4271 return TRUE;
4274 /* I don't know 100% for sure if this is what Windows does, but it fits the tests */
4275 if (parm->flags & BSF_QUERY)
4277 TRACE("Telling window %p using SendMessageTimeout\n", hw);
4279 /* Not tested for conflicting flags */
4280 if (parm->flags & BSF_FORCEIFHUNG || parm->flags & BSF_NOHANG)
4281 lresult = SendMessageTimeoutW( hw, parm->msg, parm->wp, parm->lp, SMTO_ABORTIFHUNG, 2000, &retval );
4282 else if (parm->flags & BSF_NOTIMEOUTIFNOTHUNG)
4283 lresult = SendMessageTimeoutW( hw, parm->msg, parm->wp, parm->lp, SMTO_NOTIMEOUTIFNOTHUNG, 2000, &retval );
4284 else
4285 lresult = SendMessageTimeoutW( hw, parm->msg, parm->wp, parm->lp, SMTO_NORMAL, 2000, &retval );
4287 if (!lresult && GetLastError() == ERROR_TIMEOUT)
4289 WARN("Timed out!\n");
4290 if (!(parm->flags & BSF_FORCEIFHUNG))
4291 goto fail;
4293 if (retval == BROADCAST_QUERY_DENY)
4294 goto fail;
4296 return TRUE;
4298 fail:
4299 parm->success = FALSE;
4300 return FALSE;
4302 else if (parm->flags & BSF_POSTMESSAGE)
4304 TRACE("Telling window %p using PostMessage\n", hw);
4305 PostMessageW( hw, parm->msg, parm->wp, parm->lp );
4307 else
4309 TRACE("Telling window %p using SendNotifyMessage\n", hw);
4310 SendNotifyMessageW( hw, parm->msg, parm->wp, parm->lp );
4313 return TRUE;
4316 static BOOL CALLBACK bcast_desktop( LPWSTR desktop, LPARAM lp )
4318 BOOL ret;
4319 HDESK hdesktop;
4320 BroadcastParm *parm = (BroadcastParm*)lp;
4322 TRACE("desktop: %s\n", debugstr_w( desktop ));
4324 hdesktop = open_winstation_desktop( parm->winsta, desktop, 0, FALSE, DESKTOP_ENUMERATE|DESKTOP_WRITEOBJECTS|STANDARD_RIGHTS_WRITE );
4325 if (!hdesktop)
4327 FIXME("Could not open desktop %s\n", debugstr_w(desktop));
4328 return TRUE;
4331 ret = EnumDesktopWindows( hdesktop, bcast_childwindow, lp );
4332 CloseDesktop(hdesktop);
4333 TRACE("-->%d\n", ret);
4334 return parm->success;
4337 static BOOL CALLBACK bcast_winsta( LPWSTR winsta, LPARAM lp )
4339 BOOL ret;
4340 HWINSTA hwinsta = OpenWindowStationW( winsta, FALSE, WINSTA_ENUMDESKTOPS );
4341 TRACE("hwinsta: %p/%s/%08x\n", hwinsta, debugstr_w( winsta ), GetLastError());
4342 if (!hwinsta)
4343 return TRUE;
4344 ((BroadcastParm *)lp)->winsta = hwinsta;
4345 ret = EnumDesktopsW( hwinsta, bcast_desktop, lp );
4346 CloseWindowStation( hwinsta );
4347 TRACE("-->%d\n", ret);
4348 return ret;
4351 /***********************************************************************
4352 * BroadcastSystemMessageA (USER32.@)
4353 * BroadcastSystemMessage (USER32.@)
4355 LONG WINAPI BroadcastSystemMessageA( DWORD flags, LPDWORD recipients, UINT msg, WPARAM wp, LPARAM lp )
4357 return BroadcastSystemMessageExA( flags, recipients, msg, wp, lp, NULL );
4361 /***********************************************************************
4362 * BroadcastSystemMessageW (USER32.@)
4364 LONG WINAPI BroadcastSystemMessageW( DWORD flags, LPDWORD recipients, UINT msg, WPARAM wp, LPARAM lp )
4366 return BroadcastSystemMessageExW( flags, recipients, msg, wp, lp, NULL );
4369 /***********************************************************************
4370 * BroadcastSystemMessageExA (USER32.@)
4372 LONG WINAPI BroadcastSystemMessageExA( DWORD flags, LPDWORD recipients, UINT msg, WPARAM wp, LPARAM lp, PBSMINFO pinfo )
4374 map_wparam_AtoW( msg, &wp, WMCHAR_MAP_NOMAPPING );
4375 return BroadcastSystemMessageExW( flags, recipients, msg, wp, lp, NULL );
4379 /***********************************************************************
4380 * BroadcastSystemMessageExW (USER32.@)
4382 LONG WINAPI BroadcastSystemMessageExW( DWORD flags, LPDWORD recipients, UINT msg, WPARAM wp, LPARAM lp, PBSMINFO pinfo )
4384 BroadcastParm parm;
4385 DWORD recips = BSM_ALLCOMPONENTS;
4386 BOOL ret = TRUE;
4387 static const DWORD all_flags = ( BSF_QUERY | BSF_IGNORECURRENTTASK | BSF_FLUSHDISK | BSF_NOHANG
4388 | BSF_POSTMESSAGE | BSF_FORCEIFHUNG | BSF_NOTIMEOUTIFNOTHUNG
4389 | BSF_ALLOWSFW | BSF_SENDNOTIFYMESSAGE | BSF_RETURNHDESK | BSF_LUID );
4391 TRACE("Flags: %08x, recipients: %p(0x%x), msg: %04x, wparam: %08lx, lparam: %08lx\n", flags, recipients,
4392 (recipients ? *recipients : recips), msg, wp, lp);
4394 if (flags & ~all_flags)
4396 SetLastError(ERROR_INVALID_PARAMETER);
4397 return 0;
4400 if (!recipients)
4401 recipients = &recips;
4403 if ( pinfo && flags & BSF_QUERY )
4404 FIXME("Not returning PBSMINFO information yet\n");
4406 parm.flags = flags;
4407 parm.recipients = recipients;
4408 parm.msg = msg;
4409 parm.wp = wp;
4410 parm.lp = lp;
4411 parm.success = TRUE;
4413 if (*recipients & BSM_ALLDESKTOPS || *recipients == BSM_ALLCOMPONENTS)
4414 ret = EnumWindowStationsW(bcast_winsta, (LONG_PTR)&parm);
4415 else if (*recipients & BSM_APPLICATIONS)
4417 EnumWindows(bcast_childwindow, (LONG_PTR)&parm);
4418 ret = parm.success;
4420 else
4421 FIXME("Recipients %08x not supported!\n", *recipients);
4423 return ret;
4426 /***********************************************************************
4427 * SetMessageQueue (USER32.@)
4429 BOOL WINAPI SetMessageQueue( INT size )
4431 /* now obsolete the message queue will be expanded dynamically as necessary */
4432 return TRUE;
4436 /***********************************************************************
4437 * MessageBeep (USER32.@)
4439 BOOL WINAPI MessageBeep( UINT i )
4441 BOOL active = TRUE;
4442 SystemParametersInfoA( SPI_GETBEEP, 0, &active, FALSE );
4443 if (active) USER_Driver->pBeep();
4444 return TRUE;
4448 /***********************************************************************
4449 * SetCoalescableTimer (USER32.@)
4451 UINT_PTR WINAPI SetCoalescableTimer( HWND hwnd, UINT_PTR id, UINT timeout, TIMERPROC proc, ULONG tolerance )
4453 UINT_PTR ret;
4454 WNDPROC winproc = 0;
4456 if (proc) winproc = WINPROC_AllocProc( (WNDPROC)proc, FALSE );
4458 timeout = min( max( USER_TIMER_MINIMUM, timeout ), USER_TIMER_MAXIMUM );
4460 SERVER_START_REQ( set_win_timer )
4462 req->win = wine_server_user_handle( hwnd );
4463 req->msg = WM_TIMER;
4464 req->id = id;
4465 req->rate = timeout;
4466 req->lparam = (ULONG_PTR)winproc;
4467 if (!wine_server_call_err( req ))
4469 ret = reply->id;
4470 if (!ret) ret = TRUE;
4472 else ret = 0;
4474 SERVER_END_REQ;
4476 TRACE("Added %p %lx %p timeout %d\n", hwnd, id, winproc, timeout );
4477 return ret;
4481 /******************************************************************
4482 * SetTimer (USER32.@)
4484 UINT_PTR WINAPI SetTimer( HWND hwnd, UINT_PTR id, UINT timeout, TIMERPROC proc )
4486 return SetCoalescableTimer( hwnd, id, timeout, proc, TIMERV_DEFAULT_COALESCING );
4490 /***********************************************************************
4491 * SetSystemTimer (USER32.@)
4493 UINT_PTR WINAPI SetSystemTimer( HWND hwnd, UINT_PTR id, UINT timeout, TIMERPROC proc )
4495 UINT_PTR ret;
4496 WNDPROC winproc = 0;
4498 if (proc) winproc = WINPROC_AllocProc( (WNDPROC)proc, FALSE );
4500 timeout = min( max( USER_TIMER_MINIMUM, timeout ), USER_TIMER_MAXIMUM );
4502 SERVER_START_REQ( set_win_timer )
4504 req->win = wine_server_user_handle( hwnd );
4505 req->msg = WM_SYSTIMER;
4506 req->id = id;
4507 req->rate = timeout;
4508 req->lparam = (ULONG_PTR)winproc;
4509 if (!wine_server_call_err( req ))
4511 ret = reply->id;
4512 if (!ret) ret = TRUE;
4514 else ret = 0;
4516 SERVER_END_REQ;
4518 TRACE("Added %p %lx %p timeout %d\n", hwnd, id, winproc, timeout );
4519 return ret;
4523 /***********************************************************************
4524 * KillTimer (USER32.@)
4526 BOOL WINAPI KillTimer( 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_TIMER;
4534 req->id = id;
4535 ret = !wine_server_call_err( req );
4537 SERVER_END_REQ;
4538 return ret;
4542 /***********************************************************************
4543 * KillSystemTimer (USER32.@)
4545 BOOL WINAPI KillSystemTimer( HWND hwnd, UINT_PTR id )
4547 BOOL ret;
4549 SERVER_START_REQ( kill_win_timer )
4551 req->win = wine_server_user_handle( hwnd );
4552 req->msg = WM_SYSTIMER;
4553 req->id = id;
4554 ret = !wine_server_call_err( req );
4556 SERVER_END_REQ;
4557 return ret;
4561 /**********************************************************************
4562 * IsGUIThread (USER32.@)
4564 BOOL WINAPI IsGUIThread( BOOL convert )
4566 FIXME( "%u: stub\n", convert );
4567 return TRUE;
4571 /**********************************************************************
4572 * GetGUIThreadInfo (USER32.@)
4574 BOOL WINAPI GetGUIThreadInfo( DWORD id, GUITHREADINFO *info )
4576 BOOL ret;
4578 if (info->cbSize != sizeof(*info))
4580 SetLastError( ERROR_INVALID_PARAMETER );
4581 return FALSE;
4584 SERVER_START_REQ( get_thread_input )
4586 req->tid = id;
4587 if ((ret = !wine_server_call_err( req )))
4589 info->flags = 0;
4590 info->hwndActive = wine_server_ptr_handle( reply->active );
4591 info->hwndFocus = wine_server_ptr_handle( reply->focus );
4592 info->hwndCapture = wine_server_ptr_handle( reply->capture );
4593 info->hwndMenuOwner = wine_server_ptr_handle( reply->menu_owner );
4594 info->hwndMoveSize = wine_server_ptr_handle( reply->move_size );
4595 info->hwndCaret = wine_server_ptr_handle( reply->caret );
4596 info->rcCaret.left = reply->rect.left;
4597 info->rcCaret.top = reply->rect.top;
4598 info->rcCaret.right = reply->rect.right;
4599 info->rcCaret.bottom = reply->rect.bottom;
4600 if (reply->menu_owner) info->flags |= GUI_INMENUMODE;
4601 if (reply->move_size) info->flags |= GUI_INMOVESIZE;
4602 if (reply->caret) info->flags |= GUI_CARETBLINKING;
4605 SERVER_END_REQ;
4606 return ret;
4610 /******************************************************************
4611 * IsHungAppWindow (USER32.@)
4614 BOOL WINAPI IsHungAppWindow( HWND hWnd )
4616 BOOL ret;
4618 SERVER_START_REQ( is_window_hung )
4620 req->win = wine_server_user_handle( hWnd );
4621 ret = !wine_server_call_err( req ) && reply->is_hung;
4623 SERVER_END_REQ;
4624 return ret;
4627 /******************************************************************
4628 * ChangeWindowMessageFilter (USER32.@)
4630 BOOL WINAPI ChangeWindowMessageFilter( UINT message, DWORD flag )
4632 FIXME( "%x %08x\n", message, flag );
4633 return TRUE;
4636 /******************************************************************
4637 * ChangeWindowMessageFilterEx (USER32.@)
4639 BOOL WINAPI ChangeWindowMessageFilterEx( HWND hwnd, UINT message, DWORD action, CHANGEFILTERSTRUCT *changefilter )
4641 FIXME( "%p %x %d %p\n", hwnd, message, action, changefilter );
4642 return TRUE;