ntdll: Load .so builtin modules without using libwine.
[wine/zf.git] / dlls / user32 / message.c
blob2717d91dbb518c9ec25b3639598938a4515ef00d
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;
283 static const INPUT_MESSAGE_SOURCE msg_source_unavailable = { IMDT_UNAVAILABLE, IMO_UNAVAILABLE };
286 /* Message class descriptor */
287 static const WCHAR messageW[] = {'M','e','s','s','a','g','e',0};
289 const struct builtin_class_descr MESSAGE_builtin_class =
291 messageW, /* name */
292 0, /* style */
293 WINPROC_MESSAGE, /* proc */
294 0, /* extra */
295 0, /* cursor */
296 0 /* brush */
301 /* flag for messages that contain pointers */
302 /* 32 messages per entry, messages 0..31 map to bits 0..31 */
304 #define SET(msg) (1 << ((msg) & 31))
306 static const unsigned int message_pointer_flags[] =
308 /* 0x00 - 0x1f */
309 SET(WM_CREATE) | SET(WM_SETTEXT) | SET(WM_GETTEXT) |
310 SET(WM_WININICHANGE) | SET(WM_DEVMODECHANGE),
311 /* 0x20 - 0x3f */
312 SET(WM_GETMINMAXINFO) | SET(WM_DRAWITEM) | SET(WM_MEASUREITEM) | SET(WM_DELETEITEM) |
313 SET(WM_COMPAREITEM),
314 /* 0x40 - 0x5f */
315 SET(WM_WINDOWPOSCHANGING) | SET(WM_WINDOWPOSCHANGED) | SET(WM_COPYDATA) | SET(WM_HELP),
316 /* 0x60 - 0x7f */
317 SET(WM_STYLECHANGING) | SET(WM_STYLECHANGED),
318 /* 0x80 - 0x9f */
319 SET(WM_NCCREATE) | SET(WM_NCCALCSIZE) | SET(WM_GETDLGCODE),
320 /* 0xa0 - 0xbf */
321 SET(EM_GETSEL) | SET(EM_GETRECT) | SET(EM_SETRECT) | SET(EM_SETRECTNP),
322 /* 0xc0 - 0xdf */
323 SET(EM_REPLACESEL) | SET(EM_GETLINE) | SET(EM_SETTABSTOPS),
324 /* 0xe0 - 0xff */
325 SET(SBM_GETRANGE) | SET(SBM_SETSCROLLINFO) | SET(SBM_GETSCROLLINFO) | SET(SBM_GETSCROLLBARINFO),
326 /* 0x100 - 0x11f */
328 /* 0x120 - 0x13f */
330 /* 0x140 - 0x15f */
331 SET(CB_GETEDITSEL) | SET(CB_ADDSTRING) | SET(CB_DIR) | SET(CB_GETLBTEXT) |
332 SET(CB_INSERTSTRING) | SET(CB_FINDSTRING) | SET(CB_SELECTSTRING) |
333 SET(CB_GETDROPPEDCONTROLRECT) | SET(CB_FINDSTRINGEXACT),
334 /* 0x160 - 0x17f */
336 /* 0x180 - 0x19f */
337 SET(LB_ADDSTRING) | SET(LB_INSERTSTRING) | SET(LB_GETTEXT) | SET(LB_SELECTSTRING) |
338 SET(LB_DIR) | SET(LB_FINDSTRING) |
339 SET(LB_GETSELITEMS) | SET(LB_SETTABSTOPS) | SET(LB_ADDFILE) | SET(LB_GETITEMRECT),
340 /* 0x1a0 - 0x1bf */
341 SET(LB_FINDSTRINGEXACT),
342 /* 0x1c0 - 0x1df */
344 /* 0x1e0 - 0x1ff */
346 /* 0x200 - 0x21f */
347 SET(WM_NEXTMENU) | SET(WM_SIZING) | SET(WM_MOVING) | SET(WM_DEVICECHANGE),
348 /* 0x220 - 0x23f */
349 SET(WM_MDICREATE) | SET(WM_MDIGETACTIVE) | SET(WM_DROPOBJECT) |
350 SET(WM_QUERYDROPOBJECT) | SET(WM_DRAGLOOP) | SET(WM_DRAGSELECT) | SET(WM_DRAGMOVE),
351 /* 0x240 - 0x25f */
353 /* 0x260 - 0x27f */
355 /* 0x280 - 0x29f */
357 /* 0x2a0 - 0x2bf */
359 /* 0x2c0 - 0x2df */
361 /* 0x2e0 - 0x2ff */
363 /* 0x300 - 0x31f */
364 SET(WM_ASKCBFORMATNAME)
367 /* flags for messages that contain Unicode strings */
368 static const unsigned int message_unicode_flags[] =
370 /* 0x00 - 0x1f */
371 SET(WM_CREATE) | SET(WM_SETTEXT) | SET(WM_GETTEXT) | SET(WM_GETTEXTLENGTH) |
372 SET(WM_WININICHANGE) | SET(WM_DEVMODECHANGE),
373 /* 0x20 - 0x3f */
374 SET(WM_CHARTOITEM),
375 /* 0x40 - 0x5f */
377 /* 0x60 - 0x7f */
379 /* 0x80 - 0x9f */
380 SET(WM_NCCREATE),
381 /* 0xa0 - 0xbf */
383 /* 0xc0 - 0xdf */
384 SET(EM_REPLACESEL) | SET(EM_GETLINE) | SET(EM_SETPASSWORDCHAR),
385 /* 0xe0 - 0xff */
387 /* 0x100 - 0x11f */
388 SET(WM_CHAR) | SET(WM_DEADCHAR) | SET(WM_SYSCHAR) | SET(WM_SYSDEADCHAR),
389 /* 0x120 - 0x13f */
390 SET(WM_MENUCHAR),
391 /* 0x140 - 0x15f */
392 SET(CB_ADDSTRING) | SET(CB_DIR) | SET(CB_GETLBTEXT) | SET(CB_GETLBTEXTLEN) |
393 SET(CB_INSERTSTRING) | SET(CB_FINDSTRING) | SET(CB_SELECTSTRING) | SET(CB_FINDSTRINGEXACT),
394 /* 0x160 - 0x17f */
396 /* 0x180 - 0x19f */
397 SET(LB_ADDSTRING) | SET(LB_INSERTSTRING) | SET(LB_GETTEXT) | SET(LB_GETTEXTLEN) |
398 SET(LB_SELECTSTRING) | SET(LB_DIR) | SET(LB_FINDSTRING) | SET(LB_ADDFILE),
399 /* 0x1a0 - 0x1bf */
400 SET(LB_FINDSTRINGEXACT),
401 /* 0x1c0 - 0x1df */
403 /* 0x1e0 - 0x1ff */
405 /* 0x200 - 0x21f */
407 /* 0x220 - 0x23f */
408 SET(WM_MDICREATE),
409 /* 0x240 - 0x25f */
411 /* 0x260 - 0x27f */
413 /* 0x280 - 0x29f */
414 SET(WM_IME_CHAR),
415 /* 0x2a0 - 0x2bf */
417 /* 0x2c0 - 0x2df */
419 /* 0x2e0 - 0x2ff */
421 /* 0x300 - 0x31f */
422 SET(WM_PAINTCLIPBOARD) | SET(WM_SIZECLIPBOARD) | SET(WM_ASKCBFORMATNAME)
425 /* check whether a given message type includes pointers */
426 static inline BOOL is_pointer_message( UINT message, WPARAM wparam )
428 if (message >= 8*sizeof(message_pointer_flags)) return FALSE;
429 if (message == WM_DEVICECHANGE && !(wparam & 0x8000)) return FALSE;
430 return (message_pointer_flags[message / 32] & SET(message)) != 0;
433 /* check whether a given message type contains Unicode (or ASCII) chars */
434 static inline BOOL is_unicode_message( UINT message )
436 if (message >= 8*sizeof(message_unicode_flags)) return FALSE;
437 return (message_unicode_flags[message / 32] & SET(message)) != 0;
440 #undef SET
442 /* add a data field to a packed message */
443 static inline void push_data( struct packed_message *data, const void *ptr, size_t size )
445 data->data[data->count] = ptr;
446 data->size[data->count] = size;
447 data->count++;
450 /* add a string to a packed message */
451 static inline void push_string( struct packed_message *data, LPCWSTR str )
453 push_data( data, str, (strlenW(str) + 1) * sizeof(WCHAR) );
456 /* make sure that the buffer contains a valid null-terminated Unicode string */
457 static inline BOOL check_string( LPCWSTR str, size_t size )
459 for (size /= sizeof(WCHAR); size; size--, str++)
460 if (!*str) return TRUE;
461 return FALSE;
464 /* pack a pointer into a 32/64 portable format */
465 static inline ULONGLONG pack_ptr( const void *ptr )
467 return (ULONG_PTR)ptr;
470 /* unpack a potentially 64-bit pointer, returning 0 when truncated */
471 static inline void *unpack_ptr( ULONGLONG ptr64 )
473 if ((ULONG_PTR)ptr64 != ptr64) return 0;
474 return (void *)(ULONG_PTR)ptr64;
477 /* make sure that there is space for 'size' bytes in buffer, growing it if needed */
478 static inline void *get_buffer_space( void **buffer, size_t size )
480 void *ret;
482 if (*buffer)
484 if (!(ret = HeapReAlloc( GetProcessHeap(), 0, *buffer, size )))
485 HeapFree( GetProcessHeap(), 0, *buffer );
487 else ret = HeapAlloc( GetProcessHeap(), 0, size );
489 *buffer = ret;
490 return ret;
493 /* check whether a combobox expects strings or ids in CB_ADDSTRING/CB_INSERTSTRING */
494 static inline BOOL combobox_has_strings( HWND hwnd )
496 DWORD style = GetWindowLongA( hwnd, GWL_STYLE );
497 return (!(style & (CBS_OWNERDRAWFIXED | CBS_OWNERDRAWVARIABLE)) || (style & CBS_HASSTRINGS));
500 /* check whether a listbox expects strings or ids in LB_ADDSTRING/LB_INSERTSTRING */
501 static inline BOOL listbox_has_strings( HWND hwnd )
503 DWORD style = GetWindowLongA( hwnd, GWL_STYLE );
504 return (!(style & (LBS_OWNERDRAWFIXED | LBS_OWNERDRAWVARIABLE)) || (style & LBS_HASSTRINGS));
507 /* check whether message is in the range of keyboard messages */
508 static inline BOOL is_keyboard_message( UINT message )
510 return (message >= WM_KEYFIRST && message <= WM_KEYLAST);
513 /* check whether message is in the range of mouse messages */
514 static inline BOOL is_mouse_message( UINT message )
516 return ((message >= WM_NCMOUSEFIRST && message <= WM_NCMOUSELAST) ||
517 (message >= WM_MOUSEFIRST && message <= WM_MOUSELAST));
520 /* check whether message matches the specified hwnd filter */
521 static inline BOOL check_hwnd_filter( const MSG *msg, HWND hwnd_filter )
523 if (!hwnd_filter || hwnd_filter == GetDesktopWindow()) return TRUE;
524 return (msg->hwnd == hwnd_filter || IsChild( hwnd_filter, msg->hwnd ));
527 /* check for pending WM_CHAR message with DBCS trailing byte */
528 static inline BOOL get_pending_wmchar( MSG *msg, UINT first, UINT last, BOOL remove )
530 struct wm_char_mapping_data *data = get_user_thread_info()->wmchar_data;
532 if (!data || !data->get_msg.message) return FALSE;
533 if ((first || last) && (first > WM_CHAR || last < WM_CHAR)) return FALSE;
534 if (!msg) return FALSE;
535 *msg = data->get_msg;
536 if (remove) data->get_msg.message = 0;
537 return TRUE;
541 /***********************************************************************
542 * MessageWndProc
544 * Window procedure for "Message" windows (HWND_MESSAGE parent).
546 LRESULT WINAPI MessageWndProc( HWND hwnd, UINT message, WPARAM wParam, LPARAM lParam )
548 if (message == WM_NCCREATE) return TRUE;
549 return 0; /* all other messages are ignored */
553 /***********************************************************************
554 * broadcast_message_callback
556 * Helper callback for broadcasting messages.
558 static BOOL CALLBACK broadcast_message_callback( HWND hwnd, LPARAM lparam )
560 struct send_message_info *info = (struct send_message_info *)lparam;
561 if (!(GetWindowLongW( hwnd, GWL_STYLE ) & (WS_POPUP|WS_CAPTION))) return TRUE;
562 switch(info->type)
564 case MSG_UNICODE:
565 SendMessageTimeoutW( hwnd, info->msg, info->wparam, info->lparam,
566 info->flags, info->timeout, NULL );
567 break;
568 case MSG_ASCII:
569 SendMessageTimeoutA( hwnd, info->msg, info->wparam, info->lparam,
570 info->flags, info->timeout, NULL );
571 break;
572 case MSG_NOTIFY:
573 SendNotifyMessageW( hwnd, info->msg, info->wparam, info->lparam );
574 break;
575 case MSG_CALLBACK:
576 SendMessageCallbackW( hwnd, info->msg, info->wparam, info->lparam,
577 info->callback, info->data );
578 break;
579 case MSG_POSTED:
580 PostMessageW( hwnd, info->msg, info->wparam, info->lparam );
581 break;
582 default:
583 ERR( "bad type %d\n", info->type );
584 break;
586 return TRUE;
589 DWORD get_input_codepage( void )
591 DWORD cp;
592 int ret;
593 HKL hkl = GetKeyboardLayout( 0 );
595 ret = GetLocaleInfoW( LOWORD(hkl), LOCALE_IDEFAULTANSICODEPAGE | LOCALE_RETURN_NUMBER,
596 (WCHAR *)&cp, sizeof(cp) / sizeof(WCHAR) );
597 if (!ret) cp = CP_ACP;
598 return cp;
601 /***********************************************************************
602 * map_wparam_AtoW
604 * Convert the wparam of an ASCII message to Unicode.
606 BOOL map_wparam_AtoW( UINT message, WPARAM *wparam, enum wm_char_mapping mapping )
608 char ch[2];
609 WCHAR wch[2];
610 DWORD cp = get_input_codepage();
612 wch[0] = wch[1] = 0;
613 switch(message)
615 case WM_CHAR:
616 /* WM_CHAR is magic: a DBCS char can be sent/posted as two consecutive WM_CHAR
617 * messages, in which case the first char is stored, and the conversion
618 * to Unicode only takes place once the second char is sent/posted.
620 if (mapping != WMCHAR_MAP_NOMAPPING)
622 struct wm_char_mapping_data *data = get_user_thread_info()->wmchar_data;
623 BYTE low = LOBYTE(*wparam);
625 if (HIBYTE(*wparam))
627 ch[0] = low;
628 ch[1] = HIBYTE(*wparam);
629 MultiByteToWideChar( cp, 0, ch, 2, wch, 2 );
630 TRACE( "map %02x,%02x -> %04x mapping %u\n", (BYTE)ch[0], (BYTE)ch[1], wch[0], mapping );
631 if (data) data->lead_byte[mapping] = 0;
633 else if (data && data->lead_byte[mapping])
635 ch[0] = data->lead_byte[mapping];
636 ch[1] = low;
637 MultiByteToWideChar( cp, 0, ch, 2, wch, 2 );
638 TRACE( "map stored %02x,%02x -> %04x mapping %u\n", (BYTE)ch[0], (BYTE)ch[1], wch[0], mapping );
639 data->lead_byte[mapping] = 0;
641 else if (!IsDBCSLeadByte( low ))
643 ch[0] = low;
644 MultiByteToWideChar( cp, 0, ch, 1, wch, 2 );
645 TRACE( "map %02x -> %04x\n", (BYTE)ch[0], wch[0] );
646 if (data) data->lead_byte[mapping] = 0;
648 else /* store it and wait for trail byte */
650 if (!data)
652 if (!(data = HeapAlloc( GetProcessHeap(), HEAP_ZERO_MEMORY, sizeof(*data) )))
653 return FALSE;
654 get_user_thread_info()->wmchar_data = data;
656 TRACE( "storing lead byte %02x mapping %u\n", low, mapping );
657 data->lead_byte[mapping] = low;
658 return FALSE;
660 *wparam = MAKEWPARAM(wch[0], wch[1]);
661 break;
663 /* else fall through */
664 case WM_CHARTOITEM:
665 case EM_SETPASSWORDCHAR:
666 case WM_DEADCHAR:
667 case WM_SYSCHAR:
668 case WM_SYSDEADCHAR:
669 case WM_MENUCHAR:
670 ch[0] = LOBYTE(*wparam);
671 ch[1] = HIBYTE(*wparam);
672 MultiByteToWideChar( cp, 0, ch, 2, wch, 2 );
673 *wparam = MAKEWPARAM(wch[0], wch[1]);
674 break;
675 case WM_IME_CHAR:
676 ch[0] = HIBYTE(*wparam);
677 ch[1] = LOBYTE(*wparam);
678 if (ch[0]) MultiByteToWideChar( cp, 0, ch, 2, wch, 2 );
679 else MultiByteToWideChar( cp, 0, ch + 1, 1, wch, 1 );
680 *wparam = MAKEWPARAM(wch[0], HIWORD(*wparam));
681 break;
683 return TRUE;
687 /***********************************************************************
688 * map_wparam_WtoA
690 * Convert the wparam of a Unicode message to ASCII.
692 static void map_wparam_WtoA( MSG *msg, BOOL remove )
694 BYTE ch[4];
695 WCHAR wch[2];
696 DWORD len;
697 DWORD cp = get_input_codepage();
699 switch(msg->message)
701 case WM_CHAR:
702 if (!HIWORD(msg->wParam))
704 wch[0] = LOWORD(msg->wParam);
705 ch[0] = ch[1] = 0;
706 len = WideCharToMultiByte( cp, 0, wch, 1, (LPSTR)ch, 2, NULL, NULL );
707 if (len == 2) /* DBCS char */
709 struct wm_char_mapping_data *data = get_user_thread_info()->wmchar_data;
710 if (!data)
712 if (!(data = HeapAlloc( GetProcessHeap(), HEAP_ZERO_MEMORY, sizeof(*data) ))) return;
713 get_user_thread_info()->wmchar_data = data;
715 if (remove)
717 data->get_msg = *msg;
718 data->get_msg.wParam = ch[1];
720 msg->wParam = ch[0];
721 return;
724 /* else fall through */
725 case WM_CHARTOITEM:
726 case EM_SETPASSWORDCHAR:
727 case WM_DEADCHAR:
728 case WM_SYSCHAR:
729 case WM_SYSDEADCHAR:
730 case WM_MENUCHAR:
731 wch[0] = LOWORD(msg->wParam);
732 wch[1] = HIWORD(msg->wParam);
733 ch[0] = ch[1] = 0;
734 WideCharToMultiByte( cp, 0, wch, 2, (LPSTR)ch, 4, NULL, NULL );
735 msg->wParam = MAKEWPARAM( ch[0] | (ch[1] << 8), 0 );
736 break;
737 case WM_IME_CHAR:
738 wch[0] = LOWORD(msg->wParam);
739 ch[0] = ch[1] = 0;
740 len = WideCharToMultiByte( cp, 0, wch, 1, (LPSTR)ch, 2, NULL, NULL );
741 if (len == 2)
742 msg->wParam = MAKEWPARAM( (ch[0] << 8) | ch[1], HIWORD(msg->wParam) );
743 else
744 msg->wParam = MAKEWPARAM( ch[0], HIWORD(msg->wParam) );
745 break;
750 /***********************************************************************
751 * pack_message
753 * Pack a message for sending to another process.
754 * Return the size of the data we expect in the message reply.
755 * Set data->count to -1 if there is an error.
757 static size_t pack_message( HWND hwnd, UINT message, WPARAM wparam, LPARAM lparam,
758 struct packed_message *data )
760 data->count = 0;
761 switch(message)
763 case WM_NCCREATE:
764 case WM_CREATE:
766 CREATESTRUCTW *cs = (CREATESTRUCTW *)lparam;
767 data->ps.cs.lpCreateParams = pack_ptr( cs->lpCreateParams );
768 data->ps.cs.hInstance = pack_ptr( cs->hInstance );
769 data->ps.cs.hMenu = wine_server_user_handle( cs->hMenu );
770 data->ps.cs.hwndParent = wine_server_user_handle( cs->hwndParent );
771 data->ps.cs.cy = cs->cy;
772 data->ps.cs.cx = cs->cx;
773 data->ps.cs.y = cs->y;
774 data->ps.cs.x = cs->x;
775 data->ps.cs.style = cs->style;
776 data->ps.cs.dwExStyle = cs->dwExStyle;
777 data->ps.cs.lpszName = pack_ptr( cs->lpszName );
778 data->ps.cs.lpszClass = pack_ptr( cs->lpszClass );
779 push_data( data, &data->ps.cs, sizeof(data->ps.cs) );
780 if (!IS_INTRESOURCE(cs->lpszName)) push_string( data, cs->lpszName );
781 if (!IS_INTRESOURCE(cs->lpszClass)) push_string( data, cs->lpszClass );
782 return sizeof(data->ps.cs);
784 case WM_GETTEXT:
785 case WM_ASKCBFORMATNAME:
786 return wparam * sizeof(WCHAR);
787 case WM_WININICHANGE:
788 if (lparam) push_string(data, (LPWSTR)lparam );
789 return 0;
790 case WM_SETTEXT:
791 case WM_DEVMODECHANGE:
792 case CB_DIR:
793 case LB_DIR:
794 case LB_ADDFILE:
795 case EM_REPLACESEL:
796 push_string( data, (LPWSTR)lparam );
797 return 0;
798 case WM_GETMINMAXINFO:
799 push_data( data, (MINMAXINFO *)lparam, sizeof(MINMAXINFO) );
800 return sizeof(MINMAXINFO);
801 case WM_DRAWITEM:
803 DRAWITEMSTRUCT *dis = (DRAWITEMSTRUCT *)lparam;
804 data->ps.dis.CtlType = dis->CtlType;
805 data->ps.dis.CtlID = dis->CtlID;
806 data->ps.dis.itemID = dis->itemID;
807 data->ps.dis.itemAction = dis->itemAction;
808 data->ps.dis.itemState = dis->itemState;
809 data->ps.dis.hwndItem = wine_server_user_handle( dis->hwndItem );
810 data->ps.dis.hDC = wine_server_user_handle( dis->hDC ); /* FIXME */
811 data->ps.dis.rcItem = dis->rcItem;
812 data->ps.dis.itemData = dis->itemData;
813 push_data( data, &data->ps.dis, sizeof(data->ps.dis) );
814 return 0;
816 case WM_MEASUREITEM:
818 MEASUREITEMSTRUCT *mis = (MEASUREITEMSTRUCT *)lparam;
819 data->ps.mis.CtlType = mis->CtlType;
820 data->ps.mis.CtlID = mis->CtlID;
821 data->ps.mis.itemID = mis->itemID;
822 data->ps.mis.itemWidth = mis->itemWidth;
823 data->ps.mis.itemHeight = mis->itemHeight;
824 data->ps.mis.itemData = mis->itemData;
825 push_data( data, &data->ps.mis, sizeof(data->ps.mis) );
826 return sizeof(data->ps.mis);
828 case WM_DELETEITEM:
830 DELETEITEMSTRUCT *dls = (DELETEITEMSTRUCT *)lparam;
831 data->ps.dls.CtlType = dls->CtlType;
832 data->ps.dls.CtlID = dls->CtlID;
833 data->ps.dls.itemID = dls->itemID;
834 data->ps.dls.hwndItem = wine_server_user_handle( dls->hwndItem );
835 data->ps.dls.itemData = dls->itemData;
836 push_data( data, &data->ps.dls, sizeof(data->ps.dls) );
837 return 0;
839 case WM_COMPAREITEM:
841 COMPAREITEMSTRUCT *cis = (COMPAREITEMSTRUCT *)lparam;
842 data->ps.cis.CtlType = cis->CtlType;
843 data->ps.cis.CtlID = cis->CtlID;
844 data->ps.cis.hwndItem = wine_server_user_handle( cis->hwndItem );
845 data->ps.cis.itemID1 = cis->itemID1;
846 data->ps.cis.itemData1 = cis->itemData1;
847 data->ps.cis.itemID2 = cis->itemID2;
848 data->ps.cis.itemData2 = cis->itemData2;
849 data->ps.cis.dwLocaleId = cis->dwLocaleId;
850 push_data( data, &data->ps.cis, sizeof(data->ps.cis) );
851 return 0;
853 case WM_WINE_SETWINDOWPOS:
854 case WM_WINDOWPOSCHANGING:
855 case WM_WINDOWPOSCHANGED:
857 WINDOWPOS *wp = (WINDOWPOS *)lparam;
858 data->ps.wp.hwnd = wine_server_user_handle( wp->hwnd );
859 data->ps.wp.hwndInsertAfter = wine_server_user_handle( wp->hwndInsertAfter );
860 data->ps.wp.x = wp->x;
861 data->ps.wp.y = wp->y;
862 data->ps.wp.cx = wp->cx;
863 data->ps.wp.cy = wp->cy;
864 data->ps.wp.flags = wp->flags;
865 push_data( data, &data->ps.wp, sizeof(data->ps.wp) );
866 return sizeof(data->ps.wp);
868 case WM_COPYDATA:
870 COPYDATASTRUCT *cds = (COPYDATASTRUCT *)lparam;
871 data->ps.cds.cbData = cds->cbData;
872 data->ps.cds.dwData = cds->dwData;
873 data->ps.cds.lpData = pack_ptr( cds->lpData );
874 push_data( data, &data->ps.cds, sizeof(data->ps.cds) );
875 if (cds->lpData) push_data( data, cds->lpData, cds->cbData );
876 return 0;
878 case WM_NOTIFY:
879 /* WM_NOTIFY cannot be sent across processes (MSDN) */
880 data->count = -1;
881 return 0;
882 case WM_HELP:
884 HELPINFO *hi = (HELPINFO *)lparam;
885 data->ps.hi.iContextType = hi->iContextType;
886 data->ps.hi.iCtrlId = hi->iCtrlId;
887 data->ps.hi.hItemHandle = wine_server_user_handle( hi->hItemHandle );
888 data->ps.hi.dwContextId = hi->dwContextId;
889 data->ps.hi.MousePos = hi->MousePos;
890 push_data( data, &data->ps.hi, sizeof(data->ps.hi) );
891 return 0;
893 case WM_STYLECHANGING:
894 case WM_STYLECHANGED:
895 push_data( data, (STYLESTRUCT *)lparam, sizeof(STYLESTRUCT) );
896 return 0;
897 case WM_NCCALCSIZE:
898 if (!wparam)
900 push_data( data, (RECT *)lparam, sizeof(RECT) );
901 return sizeof(RECT);
903 else
905 NCCALCSIZE_PARAMS *ncp = (NCCALCSIZE_PARAMS *)lparam;
906 data->ps.ncp.rgrc[0] = ncp->rgrc[0];
907 data->ps.ncp.rgrc[1] = ncp->rgrc[1];
908 data->ps.ncp.rgrc[2] = ncp->rgrc[2];
909 data->ps.ncp.hwnd = wine_server_user_handle( ncp->lppos->hwnd );
910 data->ps.ncp.hwndInsertAfter = wine_server_user_handle( ncp->lppos->hwndInsertAfter );
911 data->ps.ncp.x = ncp->lppos->x;
912 data->ps.ncp.y = ncp->lppos->y;
913 data->ps.ncp.cx = ncp->lppos->cx;
914 data->ps.ncp.cy = ncp->lppos->cy;
915 data->ps.ncp.flags = ncp->lppos->flags;
916 push_data( data, &data->ps.ncp, sizeof(data->ps.ncp) );
917 return sizeof(data->ps.ncp);
919 case WM_GETDLGCODE:
920 if (lparam)
922 MSG *msg = (MSG *)lparam;
923 data->ps.msg.hwnd = wine_server_user_handle( msg->hwnd );
924 data->ps.msg.message = msg->message;
925 data->ps.msg.wParam = msg->wParam;
926 data->ps.msg.lParam = msg->lParam;
927 data->ps.msg.time = msg->time;
928 data->ps.msg.pt = msg->pt;
929 push_data( data, &data->ps.msg, sizeof(data->ps.msg) );
930 return sizeof(data->ps.msg);
932 return 0;
933 case SBM_SETSCROLLINFO:
934 push_data( data, (SCROLLINFO *)lparam, sizeof(SCROLLINFO) );
935 return 0;
936 case SBM_GETSCROLLINFO:
937 push_data( data, (SCROLLINFO *)lparam, sizeof(SCROLLINFO) );
938 return sizeof(SCROLLINFO);
939 case SBM_GETSCROLLBARINFO:
941 const SCROLLBARINFO *info = (const SCROLLBARINFO *)lparam;
942 size_t size = min( info->cbSize, sizeof(SCROLLBARINFO) );
943 push_data( data, info, size );
944 return size;
946 case EM_GETSEL:
947 case SBM_GETRANGE:
948 case CB_GETEDITSEL:
950 size_t size = 0;
951 if (wparam) size += sizeof(DWORD);
952 if (lparam) size += sizeof(DWORD);
953 return size;
955 case EM_GETRECT:
956 case LB_GETITEMRECT:
957 case CB_GETDROPPEDCONTROLRECT:
958 return sizeof(RECT);
959 case EM_SETRECT:
960 case EM_SETRECTNP:
961 push_data( data, (RECT *)lparam, sizeof(RECT) );
962 return 0;
963 case EM_GETLINE:
965 WORD *pw = (WORD *)lparam;
966 push_data( data, pw, sizeof(*pw) );
967 return *pw * sizeof(WCHAR);
969 case EM_SETTABSTOPS:
970 case LB_SETTABSTOPS:
971 if (wparam) push_data( data, (UINT *)lparam, sizeof(UINT) * wparam );
972 return 0;
973 case CB_ADDSTRING:
974 case CB_INSERTSTRING:
975 case CB_FINDSTRING:
976 case CB_FINDSTRINGEXACT:
977 case CB_SELECTSTRING:
978 if (combobox_has_strings( hwnd )) push_string( data, (LPWSTR)lparam );
979 return 0;
980 case CB_GETLBTEXT:
981 if (!combobox_has_strings( hwnd )) return sizeof(ULONG_PTR);
982 return (SendMessageW( hwnd, CB_GETLBTEXTLEN, wparam, 0 ) + 1) * sizeof(WCHAR);
983 case LB_ADDSTRING:
984 case LB_INSERTSTRING:
985 case LB_FINDSTRING:
986 case LB_FINDSTRINGEXACT:
987 case LB_SELECTSTRING:
988 if (listbox_has_strings( hwnd )) push_string( data, (LPWSTR)lparam );
989 return 0;
990 case LB_GETTEXT:
991 if (!listbox_has_strings( hwnd )) return sizeof(ULONG_PTR);
992 return (SendMessageW( hwnd, LB_GETTEXTLEN, wparam, 0 ) + 1) * sizeof(WCHAR);
993 case LB_GETSELITEMS:
994 return wparam * sizeof(UINT);
995 case WM_NEXTMENU:
997 MDINEXTMENU *mnm = (MDINEXTMENU *)lparam;
998 data->ps.mnm.hmenuIn = wine_server_user_handle( mnm->hmenuIn );
999 data->ps.mnm.hmenuNext = wine_server_user_handle( mnm->hmenuNext );
1000 data->ps.mnm.hwndNext = wine_server_user_handle( mnm->hwndNext );
1001 push_data( data, &data->ps.mnm, sizeof(data->ps.mnm) );
1002 return sizeof(data->ps.mnm);
1004 case WM_SIZING:
1005 case WM_MOVING:
1006 push_data( data, (RECT *)lparam, sizeof(RECT) );
1007 return sizeof(RECT);
1008 case WM_MDICREATE:
1010 MDICREATESTRUCTW *mcs = (MDICREATESTRUCTW *)lparam;
1011 data->ps.mcs.szClass = pack_ptr( mcs->szClass );
1012 data->ps.mcs.szTitle = pack_ptr( mcs->szTitle );
1013 data->ps.mcs.hOwner = pack_ptr( mcs->hOwner );
1014 data->ps.mcs.x = mcs->x;
1015 data->ps.mcs.y = mcs->y;
1016 data->ps.mcs.cx = mcs->cx;
1017 data->ps.mcs.cy = mcs->cy;
1018 data->ps.mcs.style = mcs->style;
1019 data->ps.mcs.lParam = mcs->lParam;
1020 push_data( data, &data->ps.mcs, sizeof(data->ps.mcs) );
1021 if (!IS_INTRESOURCE(mcs->szClass)) push_string( data, mcs->szClass );
1022 if (!IS_INTRESOURCE(mcs->szTitle)) push_string( data, mcs->szTitle );
1023 return sizeof(data->ps.mcs);
1025 case WM_MDIGETACTIVE:
1026 if (lparam) return sizeof(BOOL);
1027 return 0;
1028 case WM_DEVICECHANGE:
1030 DEV_BROADCAST_HDR *header = (DEV_BROADCAST_HDR *)lparam;
1031 push_data( data, header, header->dbch_size );
1032 return 0;
1034 case WM_WINE_KEYBOARD_LL_HOOK:
1036 struct hook_extra_info *h_extra = (struct hook_extra_info *)lparam;
1037 data->ps.hook.handle = wine_server_user_handle( h_extra->handle );
1038 push_data( data, &data->ps.hook, sizeof(data->ps.hook) );
1039 push_data( data, (LPVOID)h_extra->lparam, sizeof(KBDLLHOOKSTRUCT) );
1040 return 0;
1042 case WM_WINE_MOUSE_LL_HOOK:
1044 struct hook_extra_info *h_extra = (struct hook_extra_info *)lparam;
1045 data->ps.hook.handle = wine_server_user_handle( h_extra->handle );
1046 push_data( data, &data->ps.hook, sizeof(data->ps.hook) );
1047 push_data( data, (LPVOID)h_extra->lparam, sizeof(MSLLHOOKSTRUCT) );
1048 return 0;
1050 case WM_NCPAINT:
1051 if (wparam <= 1) return 0;
1052 FIXME( "WM_NCPAINT hdc packing not supported yet\n" );
1053 data->count = -1;
1054 return 0;
1055 case WM_PAINT:
1056 if (!wparam) return 0;
1057 /* fall through */
1059 /* these contain an HFONT */
1060 case WM_SETFONT:
1061 case WM_GETFONT:
1062 /* these contain an HDC */
1063 case WM_ERASEBKGND:
1064 case WM_ICONERASEBKGND:
1065 case WM_CTLCOLORMSGBOX:
1066 case WM_CTLCOLOREDIT:
1067 case WM_CTLCOLORLISTBOX:
1068 case WM_CTLCOLORBTN:
1069 case WM_CTLCOLORDLG:
1070 case WM_CTLCOLORSCROLLBAR:
1071 case WM_CTLCOLORSTATIC:
1072 case WM_PRINT:
1073 case WM_PRINTCLIENT:
1074 /* these contain an HGLOBAL */
1075 case WM_PAINTCLIPBOARD:
1076 case WM_SIZECLIPBOARD:
1077 /* these contain HICON */
1078 case WM_GETICON:
1079 case WM_SETICON:
1080 case WM_QUERYDRAGICON:
1081 case WM_QUERYPARKICON:
1082 /* these contain pointers */
1083 case WM_DROPOBJECT:
1084 case WM_QUERYDROPOBJECT:
1085 case WM_DRAGLOOP:
1086 case WM_DRAGSELECT:
1087 case WM_DRAGMOVE:
1088 FIXME( "msg %x (%s) not supported yet\n", message, SPY_GetMsgName(message, hwnd) );
1089 data->count = -1;
1090 return 0;
1092 return 0;
1096 /***********************************************************************
1097 * unpack_message
1099 * Unpack a message received from another process.
1101 static BOOL unpack_message( HWND hwnd, UINT message, WPARAM *wparam, LPARAM *lparam,
1102 void **buffer, size_t size )
1104 size_t minsize = 0;
1105 union packed_structs *ps = *buffer;
1107 switch(message)
1109 case WM_NCCREATE:
1110 case WM_CREATE:
1112 CREATESTRUCTW cs;
1113 WCHAR *str = (WCHAR *)(&ps->cs + 1);
1114 if (size < sizeof(ps->cs)) return FALSE;
1115 size -= sizeof(ps->cs);
1116 cs.lpCreateParams = unpack_ptr( ps->cs.lpCreateParams );
1117 cs.hInstance = unpack_ptr( ps->cs.hInstance );
1118 cs.hMenu = wine_server_ptr_handle( ps->cs.hMenu );
1119 cs.hwndParent = wine_server_ptr_handle( ps->cs.hwndParent );
1120 cs.cy = ps->cs.cy;
1121 cs.cx = ps->cs.cx;
1122 cs.y = ps->cs.y;
1123 cs.x = ps->cs.x;
1124 cs.style = ps->cs.style;
1125 cs.dwExStyle = ps->cs.dwExStyle;
1126 cs.lpszName = unpack_ptr( ps->cs.lpszName );
1127 cs.lpszClass = unpack_ptr( ps->cs.lpszClass );
1128 if (ps->cs.lpszName >> 16)
1130 if (!check_string( str, size )) return FALSE;
1131 cs.lpszName = str;
1132 size -= (strlenW(str) + 1) * sizeof(WCHAR);
1133 str += strlenW(str) + 1;
1135 if (ps->cs.lpszClass >> 16)
1137 if (!check_string( str, size )) return FALSE;
1138 cs.lpszClass = str;
1140 memcpy( &ps->cs, &cs, sizeof(cs) );
1141 break;
1143 case WM_GETTEXT:
1144 case WM_ASKCBFORMATNAME:
1145 if (!get_buffer_space( buffer, (*wparam * sizeof(WCHAR)) )) return FALSE;
1146 break;
1147 case WM_WININICHANGE:
1148 if (!*lparam) return TRUE;
1149 /* fall through */
1150 case WM_SETTEXT:
1151 case WM_DEVMODECHANGE:
1152 case CB_DIR:
1153 case LB_DIR:
1154 case LB_ADDFILE:
1155 case EM_REPLACESEL:
1156 if (!check_string( *buffer, size )) return FALSE;
1157 break;
1158 case WM_GETMINMAXINFO:
1159 minsize = sizeof(MINMAXINFO);
1160 break;
1161 case WM_DRAWITEM:
1163 DRAWITEMSTRUCT dis;
1164 if (size < sizeof(ps->dis)) return FALSE;
1165 dis.CtlType = ps->dis.CtlType;
1166 dis.CtlID = ps->dis.CtlID;
1167 dis.itemID = ps->dis.itemID;
1168 dis.itemAction = ps->dis.itemAction;
1169 dis.itemState = ps->dis.itemState;
1170 dis.hwndItem = wine_server_ptr_handle( ps->dis.hwndItem );
1171 dis.hDC = wine_server_ptr_handle( ps->dis.hDC );
1172 dis.rcItem = ps->dis.rcItem;
1173 dis.itemData = (ULONG_PTR)unpack_ptr( ps->dis.itemData );
1174 memcpy( &ps->dis, &dis, sizeof(dis) );
1175 break;
1177 case WM_MEASUREITEM:
1179 MEASUREITEMSTRUCT mis;
1180 if (size < sizeof(ps->mis)) return FALSE;
1181 mis.CtlType = ps->mis.CtlType;
1182 mis.CtlID = ps->mis.CtlID;
1183 mis.itemID = ps->mis.itemID;
1184 mis.itemWidth = ps->mis.itemWidth;
1185 mis.itemHeight = ps->mis.itemHeight;
1186 mis.itemData = (ULONG_PTR)unpack_ptr( ps->mis.itemData );
1187 memcpy( &ps->mis, &mis, sizeof(mis) );
1188 break;
1190 case WM_DELETEITEM:
1192 DELETEITEMSTRUCT dls;
1193 if (size < sizeof(ps->dls)) return FALSE;
1194 dls.CtlType = ps->dls.CtlType;
1195 dls.CtlID = ps->dls.CtlID;
1196 dls.itemID = ps->dls.itemID;
1197 dls.hwndItem = wine_server_ptr_handle( ps->dls.hwndItem );
1198 dls.itemData = (ULONG_PTR)unpack_ptr( ps->dls.itemData );
1199 memcpy( &ps->dls, &dls, sizeof(dls) );
1200 break;
1202 case WM_COMPAREITEM:
1204 COMPAREITEMSTRUCT cis;
1205 if (size < sizeof(ps->cis)) return FALSE;
1206 cis.CtlType = ps->cis.CtlType;
1207 cis.CtlID = ps->cis.CtlID;
1208 cis.hwndItem = wine_server_ptr_handle( ps->cis.hwndItem );
1209 cis.itemID1 = ps->cis.itemID1;
1210 cis.itemData1 = (ULONG_PTR)unpack_ptr( ps->cis.itemData1 );
1211 cis.itemID2 = ps->cis.itemID2;
1212 cis.itemData2 = (ULONG_PTR)unpack_ptr( ps->cis.itemData2 );
1213 cis.dwLocaleId = ps->cis.dwLocaleId;
1214 memcpy( &ps->cis, &cis, sizeof(cis) );
1215 break;
1217 case WM_WINDOWPOSCHANGING:
1218 case WM_WINDOWPOSCHANGED:
1219 case WM_WINE_SETWINDOWPOS:
1221 WINDOWPOS wp;
1222 if (size < sizeof(ps->wp)) return FALSE;
1223 wp.hwnd = wine_server_ptr_handle( ps->wp.hwnd );
1224 wp.hwndInsertAfter = wine_server_ptr_handle( ps->wp.hwndInsertAfter );
1225 wp.x = ps->wp.x;
1226 wp.y = ps->wp.y;
1227 wp.cx = ps->wp.cx;
1228 wp.cy = ps->wp.cy;
1229 wp.flags = ps->wp.flags;
1230 memcpy( &ps->wp, &wp, sizeof(wp) );
1231 break;
1233 case WM_COPYDATA:
1235 COPYDATASTRUCT cds;
1236 if (size < sizeof(ps->cds)) return FALSE;
1237 cds.dwData = (ULONG_PTR)unpack_ptr( ps->cds.dwData );
1238 if (ps->cds.lpData)
1240 cds.cbData = ps->cds.cbData;
1241 cds.lpData = &ps->cds + 1;
1242 minsize = sizeof(ps->cds) + cds.cbData;
1244 else
1246 cds.cbData = 0;
1247 cds.lpData = 0;
1249 memcpy( &ps->cds, &cds, sizeof(cds) );
1250 break;
1252 case WM_NOTIFY:
1253 /* WM_NOTIFY cannot be sent across processes (MSDN) */
1254 return FALSE;
1255 case WM_HELP:
1257 HELPINFO hi;
1258 if (size < sizeof(ps->hi)) return FALSE;
1259 hi.cbSize = sizeof(hi);
1260 hi.iContextType = ps->hi.iContextType;
1261 hi.iCtrlId = ps->hi.iCtrlId;
1262 hi.hItemHandle = wine_server_ptr_handle( ps->hi.hItemHandle );
1263 hi.dwContextId = (ULONG_PTR)unpack_ptr( ps->hi.dwContextId );
1264 hi.MousePos = ps->hi.MousePos;
1265 memcpy( &ps->hi, &hi, sizeof(hi) );
1266 break;
1268 case WM_STYLECHANGING:
1269 case WM_STYLECHANGED:
1270 minsize = sizeof(STYLESTRUCT);
1271 break;
1272 case WM_NCCALCSIZE:
1273 if (!*wparam) minsize = sizeof(RECT);
1274 else
1276 NCCALCSIZE_PARAMS ncp;
1277 WINDOWPOS wp;
1278 if (size < sizeof(ps->ncp)) return FALSE;
1279 ncp.rgrc[0] = ps->ncp.rgrc[0];
1280 ncp.rgrc[1] = ps->ncp.rgrc[1];
1281 ncp.rgrc[2] = ps->ncp.rgrc[2];
1282 wp.hwnd = wine_server_ptr_handle( ps->ncp.hwnd );
1283 wp.hwndInsertAfter = wine_server_ptr_handle( ps->ncp.hwndInsertAfter );
1284 wp.x = ps->ncp.x;
1285 wp.y = ps->ncp.y;
1286 wp.cx = ps->ncp.cx;
1287 wp.cy = ps->ncp.cy;
1288 wp.flags = ps->ncp.flags;
1289 ncp.lppos = (WINDOWPOS *)((NCCALCSIZE_PARAMS *)&ps->ncp + 1);
1290 memcpy( &ps->ncp, &ncp, sizeof(ncp) );
1291 *ncp.lppos = wp;
1293 break;
1294 case WM_GETDLGCODE:
1295 if (*lparam)
1297 MSG msg;
1298 if (size < sizeof(ps->msg)) return FALSE;
1299 msg.hwnd = wine_server_ptr_handle( ps->msg.hwnd );
1300 msg.message = ps->msg.message;
1301 msg.wParam = (ULONG_PTR)unpack_ptr( ps->msg.wParam );
1302 msg.lParam = (ULONG_PTR)unpack_ptr( ps->msg.lParam );
1303 msg.time = ps->msg.time;
1304 msg.pt = ps->msg.pt;
1305 memcpy( &ps->msg, &msg, sizeof(msg) );
1306 break;
1308 return TRUE;
1309 case SBM_SETSCROLLINFO:
1310 minsize = sizeof(SCROLLINFO);
1311 break;
1312 case SBM_GETSCROLLINFO:
1313 if (!get_buffer_space( buffer, sizeof(SCROLLINFO ))) return FALSE;
1314 break;
1315 case SBM_GETSCROLLBARINFO:
1316 if (!get_buffer_space( buffer, sizeof(SCROLLBARINFO ))) return FALSE;
1317 break;
1318 case EM_GETSEL:
1319 case SBM_GETRANGE:
1320 case CB_GETEDITSEL:
1321 if (*wparam || *lparam)
1323 if (!get_buffer_space( buffer, 2*sizeof(DWORD) )) return FALSE;
1324 if (*wparam) *wparam = (WPARAM)*buffer;
1325 if (*lparam) *lparam = (LPARAM)((DWORD *)*buffer + 1);
1327 return TRUE;
1328 case EM_GETRECT:
1329 case LB_GETITEMRECT:
1330 case CB_GETDROPPEDCONTROLRECT:
1331 if (!get_buffer_space( buffer, sizeof(RECT) )) return FALSE;
1332 break;
1333 case EM_SETRECT:
1334 case EM_SETRECTNP:
1335 minsize = sizeof(RECT);
1336 break;
1337 case EM_GETLINE:
1339 WORD len;
1340 if (size < sizeof(WORD)) return FALSE;
1341 len = *(WORD *)*buffer;
1342 if (!get_buffer_space( buffer, (len + 1) * sizeof(WCHAR) )) return FALSE;
1343 *lparam = (LPARAM)*buffer + sizeof(WORD); /* don't erase WORD at start of buffer */
1344 return TRUE;
1346 case EM_SETTABSTOPS:
1347 case LB_SETTABSTOPS:
1348 if (!*wparam) return TRUE;
1349 minsize = *wparam * sizeof(UINT);
1350 break;
1351 case CB_ADDSTRING:
1352 case CB_INSERTSTRING:
1353 case CB_FINDSTRING:
1354 case CB_FINDSTRINGEXACT:
1355 case CB_SELECTSTRING:
1356 case LB_ADDSTRING:
1357 case LB_INSERTSTRING:
1358 case LB_FINDSTRING:
1359 case LB_FINDSTRINGEXACT:
1360 case LB_SELECTSTRING:
1361 if (!*buffer) return TRUE;
1362 if (!check_string( *buffer, size )) return FALSE;
1363 break;
1364 case CB_GETLBTEXT:
1366 size = sizeof(ULONG_PTR);
1367 if (combobox_has_strings( hwnd ))
1368 size = (SendMessageW( hwnd, CB_GETLBTEXTLEN, *wparam, 0 ) + 1) * sizeof(WCHAR);
1369 if (!get_buffer_space( buffer, size )) return FALSE;
1370 break;
1372 case LB_GETTEXT:
1374 size = sizeof(ULONG_PTR);
1375 if (listbox_has_strings( hwnd ))
1376 size = (SendMessageW( hwnd, LB_GETTEXTLEN, *wparam, 0 ) + 1) * sizeof(WCHAR);
1377 if (!get_buffer_space( buffer, size )) return FALSE;
1378 break;
1380 case LB_GETSELITEMS:
1381 if (!get_buffer_space( buffer, *wparam * sizeof(UINT) )) return FALSE;
1382 break;
1383 case WM_NEXTMENU:
1385 MDINEXTMENU mnm;
1386 if (size < sizeof(ps->mnm)) return FALSE;
1387 mnm.hmenuIn = wine_server_ptr_handle( ps->mnm.hmenuIn );
1388 mnm.hmenuNext = wine_server_ptr_handle( ps->mnm.hmenuNext );
1389 mnm.hwndNext = wine_server_ptr_handle( ps->mnm.hwndNext );
1390 memcpy( &ps->mnm, &mnm, sizeof(mnm) );
1391 break;
1393 case WM_SIZING:
1394 case WM_MOVING:
1395 minsize = sizeof(RECT);
1396 if (!get_buffer_space( buffer, sizeof(RECT) )) return FALSE;
1397 break;
1398 case WM_MDICREATE:
1400 MDICREATESTRUCTW mcs;
1401 WCHAR *str = (WCHAR *)(&ps->mcs + 1);
1402 if (size < sizeof(ps->mcs)) return FALSE;
1403 size -= sizeof(ps->mcs);
1405 mcs.szClass = unpack_ptr( ps->mcs.szClass );
1406 mcs.szTitle = unpack_ptr( ps->mcs.szTitle );
1407 mcs.hOwner = unpack_ptr( ps->mcs.hOwner );
1408 mcs.x = ps->mcs.x;
1409 mcs.y = ps->mcs.y;
1410 mcs.cx = ps->mcs.cx;
1411 mcs.cy = ps->mcs.cy;
1412 mcs.style = ps->mcs.style;
1413 mcs.lParam = (LPARAM)unpack_ptr( ps->mcs.lParam );
1414 if (ps->mcs.szClass >> 16)
1416 if (!check_string( str, size )) return FALSE;
1417 mcs.szClass = str;
1418 size -= (strlenW(str) + 1) * sizeof(WCHAR);
1419 str += strlenW(str) + 1;
1421 if (ps->mcs.szTitle >> 16)
1423 if (!check_string( str, size )) return FALSE;
1424 mcs.szTitle = str;
1426 memcpy( &ps->mcs, &mcs, sizeof(mcs) );
1427 break;
1429 case WM_MDIGETACTIVE:
1430 if (!*lparam) return TRUE;
1431 if (!get_buffer_space( buffer, sizeof(BOOL) )) return FALSE;
1432 break;
1433 case WM_DEVICECHANGE:
1434 minsize = sizeof(DEV_BROADCAST_HDR);
1435 break;
1436 case WM_WINE_KEYBOARD_LL_HOOK:
1437 case WM_WINE_MOUSE_LL_HOOK:
1439 struct hook_extra_info h_extra;
1440 minsize = sizeof(ps->hook) +
1441 (message == WM_WINE_KEYBOARD_LL_HOOK ? sizeof(KBDLLHOOKSTRUCT)
1442 : sizeof(MSLLHOOKSTRUCT));
1443 if (size < minsize) return FALSE;
1444 h_extra.handle = wine_server_ptr_handle( ps->hook.handle );
1445 h_extra.lparam = (LPARAM)(&ps->hook + 1);
1446 memcpy( &ps->hook, &h_extra, sizeof(h_extra) );
1447 break;
1449 case WM_NCPAINT:
1450 if (*wparam <= 1) return TRUE;
1451 FIXME( "WM_NCPAINT hdc unpacking not supported\n" );
1452 return FALSE;
1453 case WM_PAINT:
1454 if (!*wparam) return TRUE;
1455 /* fall through */
1457 /* these contain an HFONT */
1458 case WM_SETFONT:
1459 case WM_GETFONT:
1460 /* these contain an HDC */
1461 case WM_ERASEBKGND:
1462 case WM_ICONERASEBKGND:
1463 case WM_CTLCOLORMSGBOX:
1464 case WM_CTLCOLOREDIT:
1465 case WM_CTLCOLORLISTBOX:
1466 case WM_CTLCOLORBTN:
1467 case WM_CTLCOLORDLG:
1468 case WM_CTLCOLORSCROLLBAR:
1469 case WM_CTLCOLORSTATIC:
1470 case WM_PRINT:
1471 case WM_PRINTCLIENT:
1472 /* these contain an HGLOBAL */
1473 case WM_PAINTCLIPBOARD:
1474 case WM_SIZECLIPBOARD:
1475 /* these contain HICON */
1476 case WM_GETICON:
1477 case WM_SETICON:
1478 case WM_QUERYDRAGICON:
1479 case WM_QUERYPARKICON:
1480 /* these contain pointers */
1481 case WM_DROPOBJECT:
1482 case WM_QUERYDROPOBJECT:
1483 case WM_DRAGLOOP:
1484 case WM_DRAGSELECT:
1485 case WM_DRAGMOVE:
1486 FIXME( "msg %x (%s) not supported yet\n", message, SPY_GetMsgName(message, hwnd) );
1487 return FALSE;
1489 default:
1490 return TRUE; /* message doesn't need any unpacking */
1493 /* default exit for most messages: check minsize and store buffer in lparam */
1494 if (size < minsize) return FALSE;
1495 *lparam = (LPARAM)*buffer;
1496 return TRUE;
1500 /***********************************************************************
1501 * pack_reply
1503 * Pack a reply to a message for sending to another process.
1505 static void pack_reply( HWND hwnd, UINT message, WPARAM wparam, LPARAM lparam,
1506 LRESULT res, struct packed_message *data )
1508 data->count = 0;
1509 switch(message)
1511 case WM_NCCREATE:
1512 case WM_CREATE:
1514 CREATESTRUCTW *cs = (CREATESTRUCTW *)lparam;
1515 data->ps.cs.lpCreateParams = (ULONG_PTR)cs->lpCreateParams;
1516 data->ps.cs.hInstance = (ULONG_PTR)cs->hInstance;
1517 data->ps.cs.hMenu = wine_server_user_handle( cs->hMenu );
1518 data->ps.cs.hwndParent = wine_server_user_handle( cs->hwndParent );
1519 data->ps.cs.cy = cs->cy;
1520 data->ps.cs.cx = cs->cx;
1521 data->ps.cs.y = cs->y;
1522 data->ps.cs.x = cs->x;
1523 data->ps.cs.style = cs->style;
1524 data->ps.cs.dwExStyle = cs->dwExStyle;
1525 data->ps.cs.lpszName = (ULONG_PTR)cs->lpszName;
1526 data->ps.cs.lpszClass = (ULONG_PTR)cs->lpszClass;
1527 push_data( data, &data->ps.cs, sizeof(data->ps.cs) );
1528 break;
1530 case WM_GETTEXT:
1531 case CB_GETLBTEXT:
1532 case LB_GETTEXT:
1533 push_data( data, (WCHAR *)lparam, (res + 1) * sizeof(WCHAR) );
1534 break;
1535 case WM_GETMINMAXINFO:
1536 push_data( data, (MINMAXINFO *)lparam, sizeof(MINMAXINFO) );
1537 break;
1538 case WM_MEASUREITEM:
1540 MEASUREITEMSTRUCT *mis = (MEASUREITEMSTRUCT *)lparam;
1541 data->ps.mis.CtlType = mis->CtlType;
1542 data->ps.mis.CtlID = mis->CtlID;
1543 data->ps.mis.itemID = mis->itemID;
1544 data->ps.mis.itemWidth = mis->itemWidth;
1545 data->ps.mis.itemHeight = mis->itemHeight;
1546 data->ps.mis.itemData = mis->itemData;
1547 push_data( data, &data->ps.mis, sizeof(data->ps.mis) );
1548 break;
1550 case WM_WINDOWPOSCHANGING:
1551 case WM_WINDOWPOSCHANGED:
1553 WINDOWPOS *wp = (WINDOWPOS *)lparam;
1554 data->ps.wp.hwnd = wine_server_user_handle( wp->hwnd );
1555 data->ps.wp.hwndInsertAfter = wine_server_user_handle( wp->hwndInsertAfter );
1556 data->ps.wp.x = wp->x;
1557 data->ps.wp.y = wp->y;
1558 data->ps.wp.cx = wp->cx;
1559 data->ps.wp.cy = wp->cy;
1560 data->ps.wp.flags = wp->flags;
1561 push_data( data, &data->ps.wp, sizeof(data->ps.wp) );
1562 break;
1564 case WM_GETDLGCODE:
1565 if (lparam)
1567 MSG *msg = (MSG *)lparam;
1568 data->ps.msg.hwnd = wine_server_user_handle( msg->hwnd );
1569 data->ps.msg.message = msg->message;
1570 data->ps.msg.wParam = msg->wParam;
1571 data->ps.msg.lParam = msg->lParam;
1572 data->ps.msg.time = msg->time;
1573 data->ps.msg.pt = msg->pt;
1574 push_data( data, &data->ps.msg, sizeof(data->ps.msg) );
1576 break;
1577 case SBM_GETSCROLLINFO:
1578 push_data( data, (SCROLLINFO *)lparam, sizeof(SCROLLINFO) );
1579 break;
1580 case EM_GETRECT:
1581 case LB_GETITEMRECT:
1582 case CB_GETDROPPEDCONTROLRECT:
1583 case WM_SIZING:
1584 case WM_MOVING:
1585 push_data( data, (RECT *)lparam, sizeof(RECT) );
1586 break;
1587 case EM_GETLINE:
1589 WORD *ptr = (WORD *)lparam;
1590 push_data( data, ptr, ptr[-1] * sizeof(WCHAR) );
1591 break;
1593 case LB_GETSELITEMS:
1594 push_data( data, (UINT *)lparam, wparam * sizeof(UINT) );
1595 break;
1596 case WM_MDIGETACTIVE:
1597 if (lparam) push_data( data, (BOOL *)lparam, sizeof(BOOL) );
1598 break;
1599 case WM_NCCALCSIZE:
1600 if (!wparam)
1601 push_data( data, (RECT *)lparam, sizeof(RECT) );
1602 else
1604 NCCALCSIZE_PARAMS *ncp = (NCCALCSIZE_PARAMS *)lparam;
1605 data->ps.ncp.rgrc[0] = ncp->rgrc[0];
1606 data->ps.ncp.rgrc[1] = ncp->rgrc[1];
1607 data->ps.ncp.rgrc[2] = ncp->rgrc[2];
1608 data->ps.ncp.hwnd = wine_server_user_handle( ncp->lppos->hwnd );
1609 data->ps.ncp.hwndInsertAfter = wine_server_user_handle( ncp->lppos->hwndInsertAfter );
1610 data->ps.ncp.x = ncp->lppos->x;
1611 data->ps.ncp.y = ncp->lppos->y;
1612 data->ps.ncp.cx = ncp->lppos->cx;
1613 data->ps.ncp.cy = ncp->lppos->cy;
1614 data->ps.ncp.flags = ncp->lppos->flags;
1615 push_data( data, &data->ps.ncp, sizeof(data->ps.ncp) );
1617 break;
1618 case EM_GETSEL:
1619 case SBM_GETRANGE:
1620 case CB_GETEDITSEL:
1621 if (wparam) push_data( data, (DWORD *)wparam, sizeof(DWORD) );
1622 if (lparam) push_data( data, (DWORD *)lparam, sizeof(DWORD) );
1623 break;
1624 case WM_NEXTMENU:
1626 MDINEXTMENU *mnm = (MDINEXTMENU *)lparam;
1627 data->ps.mnm.hmenuIn = wine_server_user_handle( mnm->hmenuIn );
1628 data->ps.mnm.hmenuNext = wine_server_user_handle( mnm->hmenuNext );
1629 data->ps.mnm.hwndNext = wine_server_user_handle( mnm->hwndNext );
1630 push_data( data, &data->ps.mnm, sizeof(data->ps.mnm) );
1631 break;
1633 case WM_MDICREATE:
1635 MDICREATESTRUCTW *mcs = (MDICREATESTRUCTW *)lparam;
1636 data->ps.mcs.szClass = pack_ptr( mcs->szClass );
1637 data->ps.mcs.szTitle = pack_ptr( mcs->szTitle );
1638 data->ps.mcs.hOwner = pack_ptr( mcs->hOwner );
1639 data->ps.mcs.x = mcs->x;
1640 data->ps.mcs.y = mcs->y;
1641 data->ps.mcs.cx = mcs->cx;
1642 data->ps.mcs.cy = mcs->cy;
1643 data->ps.mcs.style = mcs->style;
1644 data->ps.mcs.lParam = mcs->lParam;
1645 push_data( data, &data->ps.mcs, sizeof(data->ps.mcs) );
1646 break;
1648 case WM_ASKCBFORMATNAME:
1649 push_data( data, (WCHAR *)lparam, (strlenW((WCHAR *)lparam) + 1) * sizeof(WCHAR) );
1650 break;
1655 /***********************************************************************
1656 * unpack_reply
1658 * Unpack a message reply received from another process.
1660 static void unpack_reply( HWND hwnd, UINT message, WPARAM wparam, LPARAM lparam,
1661 void *buffer, size_t size )
1663 union packed_structs *ps = buffer;
1665 switch(message)
1667 case WM_NCCREATE:
1668 case WM_CREATE:
1669 if (size >= sizeof(ps->cs))
1671 CREATESTRUCTW *cs = (CREATESTRUCTW *)lparam;
1672 cs->lpCreateParams = unpack_ptr( ps->cs.lpCreateParams );
1673 cs->hInstance = unpack_ptr( ps->cs.hInstance );
1674 cs->hMenu = wine_server_ptr_handle( ps->cs.hMenu );
1675 cs->hwndParent = wine_server_ptr_handle( ps->cs.hwndParent );
1676 cs->cy = ps->cs.cy;
1677 cs->cx = ps->cs.cx;
1678 cs->y = ps->cs.y;
1679 cs->x = ps->cs.x;
1680 cs->style = ps->cs.style;
1681 cs->dwExStyle = ps->cs.dwExStyle;
1682 /* don't allow changing name and class pointers */
1684 break;
1685 case WM_GETTEXT:
1686 case WM_ASKCBFORMATNAME:
1687 memcpy( (WCHAR *)lparam, buffer, min( wparam*sizeof(WCHAR), size ));
1688 break;
1689 case WM_GETMINMAXINFO:
1690 memcpy( (MINMAXINFO *)lparam, buffer, min( sizeof(MINMAXINFO), size ));
1691 break;
1692 case WM_MEASUREITEM:
1693 if (size >= sizeof(ps->mis))
1695 MEASUREITEMSTRUCT *mis = (MEASUREITEMSTRUCT *)lparam;
1696 mis->CtlType = ps->mis.CtlType;
1697 mis->CtlID = ps->mis.CtlID;
1698 mis->itemID = ps->mis.itemID;
1699 mis->itemWidth = ps->mis.itemWidth;
1700 mis->itemHeight = ps->mis.itemHeight;
1701 mis->itemData = (ULONG_PTR)unpack_ptr( ps->mis.itemData );
1703 break;
1704 case WM_WINDOWPOSCHANGING:
1705 case WM_WINDOWPOSCHANGED:
1706 if (size >= sizeof(ps->wp))
1708 WINDOWPOS *wp = (WINDOWPOS *)lparam;
1709 wp->hwnd = wine_server_ptr_handle( ps->wp.hwnd );
1710 wp->hwndInsertAfter = wine_server_ptr_handle( ps->wp.hwndInsertAfter );
1711 wp->x = ps->wp.x;
1712 wp->y = ps->wp.y;
1713 wp->cx = ps->wp.cx;
1714 wp->cy = ps->wp.cy;
1715 wp->flags = ps->wp.flags;
1717 break;
1718 case WM_GETDLGCODE:
1719 if (lparam && size >= sizeof(ps->msg))
1721 MSG *msg = (MSG *)lparam;
1722 msg->hwnd = wine_server_ptr_handle( ps->msg.hwnd );
1723 msg->message = ps->msg.message;
1724 msg->wParam = (ULONG_PTR)unpack_ptr( ps->msg.wParam );
1725 msg->lParam = (ULONG_PTR)unpack_ptr( ps->msg.lParam );
1726 msg->time = ps->msg.time;
1727 msg->pt = ps->msg.pt;
1729 break;
1730 case SBM_GETSCROLLINFO:
1731 memcpy( (SCROLLINFO *)lparam, buffer, min( sizeof(SCROLLINFO), size ));
1732 break;
1733 case SBM_GETSCROLLBARINFO:
1734 memcpy( (SCROLLBARINFO *)lparam, buffer, min( sizeof(SCROLLBARINFO), size ));
1735 break;
1736 case EM_GETRECT:
1737 case CB_GETDROPPEDCONTROLRECT:
1738 case LB_GETITEMRECT:
1739 case WM_SIZING:
1740 case WM_MOVING:
1741 memcpy( (RECT *)lparam, buffer, min( sizeof(RECT), size ));
1742 break;
1743 case EM_GETLINE:
1744 size = min( size, (size_t)*(WORD *)lparam );
1745 memcpy( (WCHAR *)lparam, buffer, size );
1746 break;
1747 case LB_GETSELITEMS:
1748 memcpy( (UINT *)lparam, buffer, min( wparam*sizeof(UINT), size ));
1749 break;
1750 case LB_GETTEXT:
1751 case CB_GETLBTEXT:
1752 memcpy( (WCHAR *)lparam, buffer, size );
1753 break;
1754 case WM_NEXTMENU:
1755 if (size >= sizeof(ps->mnm))
1757 MDINEXTMENU *mnm = (MDINEXTMENU *)lparam;
1758 mnm->hmenuIn = wine_server_ptr_handle( ps->mnm.hmenuIn );
1759 mnm->hmenuNext = wine_server_ptr_handle( ps->mnm.hmenuNext );
1760 mnm->hwndNext = wine_server_ptr_handle( ps->mnm.hwndNext );
1762 break;
1763 case WM_MDIGETACTIVE:
1764 if (lparam) memcpy( (BOOL *)lparam, buffer, min( sizeof(BOOL), size ));
1765 break;
1766 case WM_NCCALCSIZE:
1767 if (!wparam)
1768 memcpy( (RECT *)lparam, buffer, min( sizeof(RECT), size ));
1769 else if (size >= sizeof(ps->ncp))
1771 NCCALCSIZE_PARAMS *ncp = (NCCALCSIZE_PARAMS *)lparam;
1772 ncp->rgrc[0] = ps->ncp.rgrc[0];
1773 ncp->rgrc[1] = ps->ncp.rgrc[1];
1774 ncp->rgrc[2] = ps->ncp.rgrc[2];
1775 ncp->lppos->hwnd = wine_server_ptr_handle( ps->ncp.hwnd );
1776 ncp->lppos->hwndInsertAfter = wine_server_ptr_handle( ps->ncp.hwndInsertAfter );
1777 ncp->lppos->x = ps->ncp.x;
1778 ncp->lppos->y = ps->ncp.y;
1779 ncp->lppos->cx = ps->ncp.cx;
1780 ncp->lppos->cy = ps->ncp.cy;
1781 ncp->lppos->flags = ps->ncp.flags;
1783 break;
1784 case EM_GETSEL:
1785 case SBM_GETRANGE:
1786 case CB_GETEDITSEL:
1787 if (wparam)
1789 memcpy( (DWORD *)wparam, buffer, min( sizeof(DWORD), size ));
1790 if (size <= sizeof(DWORD)) break;
1791 size -= sizeof(DWORD);
1792 buffer = (DWORD *)buffer + 1;
1794 if (lparam) memcpy( (DWORD *)lparam, buffer, min( sizeof(DWORD), size ));
1795 break;
1796 case WM_MDICREATE:
1797 if (size >= sizeof(ps->mcs))
1799 MDICREATESTRUCTW *mcs = (MDICREATESTRUCTW *)lparam;
1800 mcs->hOwner = unpack_ptr( ps->mcs.hOwner );
1801 mcs->x = ps->mcs.x;
1802 mcs->y = ps->mcs.y;
1803 mcs->cx = ps->mcs.cx;
1804 mcs->cy = ps->mcs.cy;
1805 mcs->style = ps->mcs.style;
1806 mcs->lParam = (LPARAM)unpack_ptr( ps->mcs.lParam );
1807 /* don't allow changing class and title pointers */
1809 break;
1810 default:
1811 ERR( "should not happen: unexpected message %x\n", message );
1812 break;
1817 /***********************************************************************
1818 * reply_message
1820 * Send a reply to a sent message.
1822 static void reply_message( struct received_message_info *info, LRESULT result, BOOL remove )
1824 struct packed_message data;
1825 int i, replied = info->flags & ISMEX_REPLIED;
1827 if (info->flags & ISMEX_NOTIFY) return; /* notify messages don't get replies */
1828 if (!remove && replied) return; /* replied already */
1830 memset( &data, 0, sizeof(data) );
1831 info->flags |= ISMEX_REPLIED;
1833 if (info->type == MSG_OTHER_PROCESS && !replied)
1835 pack_reply( info->msg.hwnd, info->msg.message, info->msg.wParam,
1836 info->msg.lParam, result, &data );
1839 SERVER_START_REQ( reply_message )
1841 req->result = result;
1842 req->remove = remove;
1843 for (i = 0; i < data.count; i++) wine_server_add_data( req, data.data[i], data.size[i] );
1844 wine_server_call( req );
1846 SERVER_END_REQ;
1850 /***********************************************************************
1851 * handle_internal_message
1853 * Handle an internal Wine message instead of calling the window proc.
1855 static LRESULT handle_internal_message( HWND hwnd, UINT msg, WPARAM wparam, LPARAM lparam )
1857 switch(msg)
1859 case WM_WINE_DESTROYWINDOW:
1860 return WIN_DestroyWindow( hwnd );
1861 case WM_WINE_SETWINDOWPOS:
1862 if (is_desktop_window( hwnd )) return 0;
1863 return USER_SetWindowPos( (WINDOWPOS *)lparam, 0, 0 );
1864 case WM_WINE_SHOWWINDOW:
1865 if (is_desktop_window( hwnd )) return 0;
1866 return ShowWindow( hwnd, wparam );
1867 case WM_WINE_SETPARENT:
1868 if (is_desktop_window( hwnd )) return 0;
1869 return (LRESULT)SetParent( hwnd, (HWND)wparam );
1870 case WM_WINE_SETWINDOWLONG:
1871 return WIN_SetWindowLong( hwnd, (short)LOWORD(wparam), HIWORD(wparam), lparam, TRUE );
1872 case WM_WINE_SETSTYLE:
1873 if (is_desktop_window( hwnd )) return 0;
1874 return WIN_SetStyle(hwnd, wparam, lparam);
1875 case WM_WINE_SETACTIVEWINDOW:
1876 if (!wparam && GetForegroundWindow() == hwnd) return 0;
1877 return (LRESULT)SetActiveWindow( (HWND)wparam );
1878 case WM_WINE_KEYBOARD_LL_HOOK:
1879 case WM_WINE_MOUSE_LL_HOOK:
1881 struct hook_extra_info *h_extra = (struct hook_extra_info *)lparam;
1883 return call_current_hook( h_extra->handle, HC_ACTION, wparam, h_extra->lparam );
1885 case WM_WINE_CLIPCURSOR:
1886 if (wparam)
1888 RECT rect;
1889 GetClipCursor( &rect );
1890 return USER_Driver->pClipCursor( &rect );
1892 return USER_Driver->pClipCursor( NULL );
1893 default:
1894 if (msg >= WM_WINE_FIRST_DRIVER_MSG && msg <= WM_WINE_LAST_DRIVER_MSG)
1895 return USER_Driver->pWindowMessage( hwnd, msg, wparam, lparam );
1896 FIXME( "unknown internal message %x\n", msg );
1897 return 0;
1901 /* since the WM_DDE_ACK response to a WM_DDE_EXECUTE message should contain the handle
1902 * to the memory handle, we keep track (in the server side) of all pairs of handle
1903 * used (the client passes its value and the content of the memory handle), and
1904 * the server stored both values (the client, and the local one, created after the
1905 * content). When a ACK message is generated, the list of pair is searched for a
1906 * matching pair, so that the client memory handle can be returned.
1908 struct DDE_pair {
1909 HGLOBAL client_hMem;
1910 HGLOBAL server_hMem;
1913 static struct DDE_pair* dde_pairs;
1914 static int dde_num_alloc;
1915 static int dde_num_used;
1917 static CRITICAL_SECTION dde_crst;
1918 static CRITICAL_SECTION_DEBUG critsect_debug =
1920 0, 0, &dde_crst,
1921 { &critsect_debug.ProcessLocksList, &critsect_debug.ProcessLocksList },
1922 0, 0, { (DWORD_PTR)(__FILE__ ": dde_crst") }
1924 static CRITICAL_SECTION dde_crst = { &critsect_debug, -1, 0, 0, 0, 0 };
1926 static BOOL dde_add_pair(HGLOBAL chm, HGLOBAL shm)
1928 int i;
1929 #define GROWBY 4
1931 EnterCriticalSection(&dde_crst);
1933 /* now remember the pair of hMem on both sides */
1934 if (dde_num_used == dde_num_alloc)
1936 struct DDE_pair* tmp;
1937 if (dde_pairs)
1938 tmp = HeapReAlloc( GetProcessHeap(), 0, dde_pairs,
1939 (dde_num_alloc + GROWBY) * sizeof(struct DDE_pair));
1940 else
1941 tmp = HeapAlloc( GetProcessHeap(), 0,
1942 (dde_num_alloc + GROWBY) * sizeof(struct DDE_pair));
1944 if (!tmp)
1946 LeaveCriticalSection(&dde_crst);
1947 return FALSE;
1949 dde_pairs = tmp;
1950 /* zero out newly allocated part */
1951 memset(&dde_pairs[dde_num_alloc], 0, GROWBY * sizeof(struct DDE_pair));
1952 dde_num_alloc += GROWBY;
1954 #undef GROWBY
1955 for (i = 0; i < dde_num_alloc; i++)
1957 if (dde_pairs[i].server_hMem == 0)
1959 dde_pairs[i].client_hMem = chm;
1960 dde_pairs[i].server_hMem = shm;
1961 dde_num_used++;
1962 break;
1965 LeaveCriticalSection(&dde_crst);
1966 return TRUE;
1969 static HGLOBAL dde_get_pair(HGLOBAL shm)
1971 int i;
1972 HGLOBAL ret = 0;
1974 EnterCriticalSection(&dde_crst);
1975 for (i = 0; i < dde_num_alloc; i++)
1977 if (dde_pairs[i].server_hMem == shm)
1979 /* free this pair */
1980 dde_pairs[i].server_hMem = 0;
1981 dde_num_used--;
1982 ret = dde_pairs[i].client_hMem;
1983 break;
1986 LeaveCriticalSection(&dde_crst);
1987 return ret;
1990 /***********************************************************************
1991 * post_dde_message
1993 * Post a DDE message
1995 static BOOL post_dde_message( struct packed_message *data, const struct send_message_info *info )
1997 void* ptr = NULL;
1998 int size = 0;
1999 UINT_PTR uiLo, uiHi;
2000 LPARAM lp;
2001 HGLOBAL hunlock = 0;
2002 int i;
2003 DWORD res;
2004 ULONGLONG hpack;
2006 if (!UnpackDDElParam( info->msg, info->lparam, &uiLo, &uiHi ))
2007 return FALSE;
2009 lp = info->lparam;
2010 switch (info->msg)
2012 /* DDE messages which don't require packing are:
2013 * WM_DDE_INITIATE
2014 * WM_DDE_TERMINATE
2015 * WM_DDE_REQUEST
2016 * WM_DDE_UNADVISE
2018 case WM_DDE_ACK:
2019 if (HIWORD(uiHi))
2021 /* uiHi should contain a hMem from WM_DDE_EXECUTE */
2022 HGLOBAL h = dde_get_pair( (HANDLE)uiHi );
2023 if (h)
2025 hpack = pack_ptr( h );
2026 /* send back the value of h on the other side */
2027 push_data( data, &hpack, sizeof(hpack) );
2028 lp = uiLo;
2029 TRACE( "send dde-ack %lx %08lx => %p\n", uiLo, uiHi, h );
2032 else
2034 /* uiHi should contain either an atom or 0 */
2035 TRACE( "send dde-ack %lx atom=%lx\n", uiLo, uiHi );
2036 lp = MAKELONG( uiLo, uiHi );
2038 break;
2039 case WM_DDE_ADVISE:
2040 case WM_DDE_DATA:
2041 case WM_DDE_POKE:
2042 size = 0;
2043 if (uiLo)
2045 size = GlobalSize( (HGLOBAL)uiLo ) ;
2046 if ((info->msg == WM_DDE_ADVISE && size < sizeof(DDEADVISE)) ||
2047 (info->msg == WM_DDE_DATA && size < FIELD_OFFSET(DDEDATA, Value)) ||
2048 (info->msg == WM_DDE_POKE && size < FIELD_OFFSET(DDEPOKE, Value))
2050 return FALSE;
2052 else if (info->msg != WM_DDE_DATA) return FALSE;
2054 lp = uiHi;
2055 if (uiLo)
2057 if ((ptr = GlobalLock( (HGLOBAL)uiLo) ))
2059 DDEDATA *dde_data = ptr;
2060 TRACE("unused %d, fResponse %d, fRelease %d, fDeferUpd %d, fAckReq %d, cfFormat %d\n",
2061 dde_data->unused, dde_data->fResponse, dde_data->fRelease,
2062 dde_data->reserved, dde_data->fAckReq, dde_data->cfFormat);
2063 push_data( data, ptr, size );
2064 hunlock = (HGLOBAL)uiLo;
2067 TRACE( "send ddepack %u %lx\n", size, uiHi );
2068 break;
2069 case WM_DDE_EXECUTE:
2070 if (info->lparam)
2072 if ((ptr = GlobalLock( (HGLOBAL)info->lparam) ))
2074 push_data(data, ptr, GlobalSize( (HGLOBAL)info->lparam ));
2075 /* so that the other side can send it back on ACK */
2076 lp = info->lparam;
2077 hunlock = (HGLOBAL)info->lparam;
2080 break;
2082 SERVER_START_REQ( send_message )
2084 req->id = info->dest_tid;
2085 req->type = info->type;
2086 req->flags = 0;
2087 req->win = wine_server_user_handle( info->hwnd );
2088 req->msg = info->msg;
2089 req->wparam = info->wparam;
2090 req->lparam = lp;
2091 req->timeout = TIMEOUT_INFINITE;
2092 for (i = 0; i < data->count; i++)
2093 wine_server_add_data( req, data->data[i], data->size[i] );
2094 if ((res = wine_server_call( req )))
2096 if (res == STATUS_INVALID_PARAMETER)
2097 /* FIXME: find a STATUS_ value for this one */
2098 SetLastError( ERROR_INVALID_THREAD_ID );
2099 else
2100 SetLastError( RtlNtStatusToDosError(res) );
2102 else
2103 FreeDDElParam(info->msg, info->lparam);
2105 SERVER_END_REQ;
2106 if (hunlock) GlobalUnlock(hunlock);
2108 return !res;
2111 /***********************************************************************
2112 * unpack_dde_message
2114 * Unpack a posted DDE message received from another process.
2116 static BOOL unpack_dde_message( HWND hwnd, UINT message, WPARAM *wparam, LPARAM *lparam,
2117 void **buffer, size_t size )
2119 UINT_PTR uiLo, uiHi;
2120 HGLOBAL hMem = 0;
2121 void* ptr;
2123 switch (message)
2125 case WM_DDE_ACK:
2126 if (size)
2128 ULONGLONG hpack;
2129 /* hMem is being passed */
2130 if (size != sizeof(hpack)) return FALSE;
2131 if (!buffer || !*buffer) return FALSE;
2132 uiLo = *lparam;
2133 memcpy( &hpack, *buffer, size );
2134 hMem = unpack_ptr( hpack );
2135 uiHi = (UINT_PTR)hMem;
2136 TRACE("recv dde-ack %lx mem=%lx[%lx]\n", uiLo, uiHi, GlobalSize( hMem ));
2138 else
2140 uiLo = LOWORD( *lparam );
2141 uiHi = HIWORD( *lparam );
2142 TRACE("recv dde-ack %lx atom=%lx\n", uiLo, uiHi);
2144 *lparam = PackDDElParam( WM_DDE_ACK, uiLo, uiHi );
2145 break;
2146 case WM_DDE_ADVISE:
2147 case WM_DDE_DATA:
2148 case WM_DDE_POKE:
2149 if ((!buffer || !*buffer) && message != WM_DDE_DATA) return FALSE;
2150 uiHi = *lparam;
2151 if (size)
2153 if (!(hMem = GlobalAlloc( GMEM_MOVEABLE|GMEM_DDESHARE, size )))
2154 return FALSE;
2155 if ((ptr = GlobalLock( hMem )))
2157 memcpy( ptr, *buffer, size );
2158 GlobalUnlock( hMem );
2160 else
2162 GlobalFree( hMem );
2163 return FALSE;
2166 uiLo = (UINT_PTR)hMem;
2168 *lparam = PackDDElParam( message, uiLo, uiHi );
2169 break;
2170 case WM_DDE_EXECUTE:
2171 if (size)
2173 if (!buffer || !*buffer) return FALSE;
2174 if (!(hMem = GlobalAlloc( GMEM_MOVEABLE|GMEM_DDESHARE, size ))) return FALSE;
2175 if ((ptr = GlobalLock( hMem )))
2177 memcpy( ptr, *buffer, size );
2178 GlobalUnlock( hMem );
2179 TRACE( "exec: pairing c=%08lx s=%p\n", *lparam, hMem );
2180 if (!dde_add_pair( (HGLOBAL)*lparam, hMem ))
2182 GlobalFree( hMem );
2183 return FALSE;
2186 else
2188 GlobalFree( hMem );
2189 return FALSE;
2191 } else return FALSE;
2192 *lparam = (LPARAM)hMem;
2193 break;
2195 return TRUE;
2198 /***********************************************************************
2199 * call_window_proc
2201 * Call a window procedure and the corresponding hooks.
2203 static LRESULT call_window_proc( HWND hwnd, UINT msg, WPARAM wparam, LPARAM lparam,
2204 BOOL unicode, BOOL same_thread, enum wm_char_mapping mapping )
2206 LRESULT result = 0;
2207 CWPSTRUCT cwp;
2208 CWPRETSTRUCT cwpret;
2210 if (msg & 0x80000000)
2212 result = handle_internal_message( hwnd, msg, wparam, lparam );
2213 goto done;
2216 /* first the WH_CALLWNDPROC hook */
2217 hwnd = WIN_GetFullHandle( hwnd );
2218 cwp.lParam = lparam;
2219 cwp.wParam = wparam;
2220 cwp.message = msg;
2221 cwp.hwnd = hwnd;
2222 HOOK_CallHooks( WH_CALLWNDPROC, HC_ACTION, same_thread, (LPARAM)&cwp, unicode );
2224 /* now call the window procedure */
2225 if (!WINPROC_call_window( hwnd, msg, wparam, lparam, &result, unicode, mapping )) goto done;
2227 /* and finally the WH_CALLWNDPROCRET hook */
2228 cwpret.lResult = result;
2229 cwpret.lParam = lparam;
2230 cwpret.wParam = wparam;
2231 cwpret.message = msg;
2232 cwpret.hwnd = hwnd;
2233 HOOK_CallHooks( WH_CALLWNDPROCRET, HC_ACTION, same_thread, (LPARAM)&cwpret, unicode );
2234 done:
2235 return result;
2239 /***********************************************************************
2240 * send_parent_notify
2242 * Send a WM_PARENTNOTIFY to all ancestors of the given window, unless
2243 * the window has the WS_EX_NOPARENTNOTIFY style.
2245 static void send_parent_notify( HWND hwnd, WORD event, WORD idChild, POINT pt )
2247 /* pt has to be in the client coordinates of the parent window */
2248 MapWindowPoints( 0, hwnd, &pt, 1 );
2249 for (;;)
2251 HWND parent;
2253 if (!(GetWindowLongW( hwnd, GWL_STYLE ) & WS_CHILD)) break;
2254 if (GetWindowLongW( hwnd, GWL_EXSTYLE ) & WS_EX_NOPARENTNOTIFY) break;
2255 if (!(parent = GetParent(hwnd))) break;
2256 if (parent == GetDesktopWindow()) break;
2257 MapWindowPoints( hwnd, parent, &pt, 1 );
2258 hwnd = parent;
2259 SendMessageW( hwnd, WM_PARENTNOTIFY,
2260 MAKEWPARAM( event, idChild ), MAKELPARAM( pt.x, pt.y ) );
2265 /***********************************************************************
2266 * accept_hardware_message
2268 * Tell the server we have passed the message to the app
2269 * (even though we may end up dropping it later on)
2271 static void accept_hardware_message( UINT hw_id, BOOL remove )
2273 SERVER_START_REQ( accept_hardware_message )
2275 req->hw_id = hw_id;
2276 req->remove = remove;
2277 if (wine_server_call( req ))
2278 FIXME("Failed to reply to MSG_HARDWARE message. Message may not be removed from queue.\n");
2280 SERVER_END_REQ;
2284 static BOOL process_rawinput_message( MSG *msg, const struct hardware_msg_data *msg_data )
2286 struct user_thread_info *thread_info = get_user_thread_info();
2287 RAWINPUT *rawinput = thread_info->rawinput;
2289 if (!rawinput)
2291 thread_info->rawinput = HeapAlloc( GetProcessHeap(), 0, sizeof(*rawinput) );
2292 if (!(rawinput = thread_info->rawinput)) return FALSE;
2295 rawinput->header.dwType = msg_data->rawinput.type;
2296 if (msg_data->rawinput.type == RIM_TYPEMOUSE)
2298 static const unsigned int button_flags[] =
2300 0, /* MOUSEEVENTF_MOVE */
2301 RI_MOUSE_LEFT_BUTTON_DOWN, /* MOUSEEVENTF_LEFTDOWN */
2302 RI_MOUSE_LEFT_BUTTON_UP, /* MOUSEEVENTF_LEFTUP */
2303 RI_MOUSE_RIGHT_BUTTON_DOWN, /* MOUSEEVENTF_RIGHTDOWN */
2304 RI_MOUSE_RIGHT_BUTTON_UP, /* MOUSEEVENTF_RIGHTUP */
2305 RI_MOUSE_MIDDLE_BUTTON_DOWN, /* MOUSEEVENTF_MIDDLEDOWN */
2306 RI_MOUSE_MIDDLE_BUTTON_UP, /* MOUSEEVENTF_MIDDLEUP */
2308 unsigned int i;
2310 rawinput->header.dwSize = FIELD_OFFSET(RAWINPUT, data) + sizeof(RAWMOUSE);
2311 rawinput->header.hDevice = WINE_MOUSE_HANDLE;
2312 rawinput->header.wParam = 0;
2314 rawinput->data.mouse.usFlags = MOUSE_MOVE_RELATIVE;
2315 rawinput->data.mouse.u.s.usButtonFlags = 0;
2316 rawinput->data.mouse.u.s.usButtonData = 0;
2317 for (i = 1; i < ARRAY_SIZE(button_flags); ++i)
2319 if (msg_data->flags & (1 << i))
2320 rawinput->data.mouse.u.s.usButtonFlags |= button_flags[i];
2322 if (msg_data->flags & MOUSEEVENTF_WHEEL)
2324 rawinput->data.mouse.u.s.usButtonFlags |= RI_MOUSE_WHEEL;
2325 rawinput->data.mouse.u.s.usButtonData = msg_data->rawinput.mouse.data;
2327 if (msg_data->flags & MOUSEEVENTF_HWHEEL)
2329 rawinput->data.mouse.u.s.usButtonFlags |= RI_MOUSE_HORIZONTAL_WHEEL;
2330 rawinput->data.mouse.u.s.usButtonData = msg_data->rawinput.mouse.data;
2332 if (msg_data->flags & MOUSEEVENTF_XDOWN)
2334 if (msg_data->rawinput.mouse.data == XBUTTON1)
2335 rawinput->data.mouse.u.s.usButtonFlags |= RI_MOUSE_BUTTON_4_DOWN;
2336 else if (msg_data->rawinput.mouse.data == XBUTTON2)
2337 rawinput->data.mouse.u.s.usButtonFlags |= RI_MOUSE_BUTTON_5_DOWN;
2339 if (msg_data->flags & MOUSEEVENTF_XUP)
2341 if (msg_data->rawinput.mouse.data == XBUTTON1)
2342 rawinput->data.mouse.u.s.usButtonFlags |= RI_MOUSE_BUTTON_4_UP;
2343 else if (msg_data->rawinput.mouse.data == XBUTTON2)
2344 rawinput->data.mouse.u.s.usButtonFlags |= RI_MOUSE_BUTTON_5_UP;
2347 rawinput->data.mouse.ulRawButtons = 0;
2348 rawinput->data.mouse.lLastX = msg_data->rawinput.mouse.x;
2349 rawinput->data.mouse.lLastY = msg_data->rawinput.mouse.y;
2350 rawinput->data.mouse.ulExtraInformation = msg_data->info;
2352 else if (msg_data->rawinput.type == RIM_TYPEKEYBOARD)
2354 rawinput->header.dwSize = FIELD_OFFSET(RAWINPUT, data) + sizeof(RAWKEYBOARD);
2355 rawinput->header.hDevice = WINE_KEYBOARD_HANDLE;
2356 rawinput->header.wParam = 0;
2358 rawinput->data.keyboard.MakeCode = msg_data->rawinput.kbd.scan;
2359 rawinput->data.keyboard.Flags = msg_data->flags & KEYEVENTF_KEYUP ? RI_KEY_BREAK : RI_KEY_MAKE;
2360 if (msg_data->flags & KEYEVENTF_EXTENDEDKEY) rawinput->data.keyboard.Flags |= RI_KEY_E0;
2361 rawinput->data.keyboard.Reserved = 0;
2363 switch (msg_data->rawinput.kbd.vkey)
2365 case VK_LSHIFT:
2366 case VK_RSHIFT:
2367 rawinput->data.keyboard.VKey = VK_SHIFT;
2368 rawinput->data.keyboard.Flags &= ~RI_KEY_E0;
2369 break;
2370 case VK_LCONTROL:
2371 case VK_RCONTROL:
2372 rawinput->data.keyboard.VKey = VK_CONTROL;
2373 break;
2374 case VK_LMENU:
2375 case VK_RMENU:
2376 rawinput->data.keyboard.VKey = VK_MENU;
2377 break;
2378 default:
2379 rawinput->data.keyboard.VKey = msg_data->rawinput.kbd.vkey;
2380 break;
2383 rawinput->data.keyboard.Message = msg_data->rawinput.kbd.message;
2384 rawinput->data.keyboard.ExtraInformation = msg_data->info;
2386 else
2388 FIXME("Unhandled rawinput type %#x.\n", msg_data->rawinput.type);
2389 return FALSE;
2392 msg->lParam = (LPARAM)rawinput;
2393 msg->pt = point_phys_to_win_dpi( msg->hwnd, msg->pt );
2394 return TRUE;
2397 /***********************************************************************
2398 * process_keyboard_message
2400 * returns TRUE if the contents of 'msg' should be passed to the application
2402 static BOOL process_keyboard_message( MSG *msg, UINT hw_id, HWND hwnd_filter,
2403 UINT first, UINT last, BOOL remove )
2405 EVENTMSG event;
2407 if (msg->message == WM_KEYDOWN || msg->message == WM_SYSKEYDOWN ||
2408 msg->message == WM_KEYUP || msg->message == WM_SYSKEYUP)
2409 switch (msg->wParam)
2411 case VK_LSHIFT: case VK_RSHIFT:
2412 msg->wParam = VK_SHIFT;
2413 break;
2414 case VK_LCONTROL: case VK_RCONTROL:
2415 msg->wParam = VK_CONTROL;
2416 break;
2417 case VK_LMENU: case VK_RMENU:
2418 msg->wParam = VK_MENU;
2419 break;
2422 /* FIXME: is this really the right place for this hook? */
2423 event.message = msg->message;
2424 event.hwnd = msg->hwnd;
2425 event.time = msg->time;
2426 event.paramL = (msg->wParam & 0xFF) | (HIWORD(msg->lParam) << 8);
2427 event.paramH = msg->lParam & 0x7FFF;
2428 if (HIWORD(msg->lParam) & 0x0100) event.paramH |= 0x8000; /* special_key - bit */
2429 HOOK_CallHooks( WH_JOURNALRECORD, HC_ACTION, 0, (LPARAM)&event, TRUE );
2431 /* check message filters */
2432 if (msg->message < first || msg->message > last) return FALSE;
2433 if (!check_hwnd_filter( msg, hwnd_filter )) return FALSE;
2435 if (remove)
2437 if((msg->message == WM_KEYDOWN) &&
2438 (msg->hwnd != GetDesktopWindow()))
2440 /* Handle F1 key by sending out WM_HELP message */
2441 if (msg->wParam == VK_F1)
2443 PostMessageW( msg->hwnd, WM_KEYF1, 0, 0 );
2445 else if(msg->wParam >= VK_BROWSER_BACK &&
2446 msg->wParam <= VK_LAUNCH_APP2)
2448 /* FIXME: Process keystate */
2449 SendMessageW(msg->hwnd, WM_APPCOMMAND, (WPARAM)msg->hwnd, MAKELPARAM(0, (FAPPCOMMAND_KEY | (msg->wParam - VK_BROWSER_BACK + 1))));
2452 else if (msg->message == WM_KEYUP)
2454 /* Handle VK_APPS key by posting a WM_CONTEXTMENU message */
2455 if (msg->wParam == VK_APPS && !MENU_IsMenuActive())
2456 PostMessageW(msg->hwnd, WM_CONTEXTMENU, (WPARAM)msg->hwnd, -1);
2460 if (HOOK_CallHooks( WH_KEYBOARD, remove ? HC_ACTION : HC_NOREMOVE,
2461 LOWORD(msg->wParam), msg->lParam, TRUE ))
2463 /* skip this message */
2464 HOOK_CallHooks( WH_CBT, HCBT_KEYSKIPPED, LOWORD(msg->wParam), msg->lParam, TRUE );
2465 accept_hardware_message( hw_id, TRUE );
2466 return FALSE;
2468 accept_hardware_message( hw_id, remove );
2469 msg->pt = point_phys_to_win_dpi( msg->hwnd, msg->pt );
2471 if ( remove && msg->message == WM_KEYDOWN )
2472 if (ImmProcessKey(msg->hwnd, GetKeyboardLayout(0), msg->wParam, msg->lParam, 0) )
2473 msg->wParam = VK_PROCESSKEY;
2475 return TRUE;
2479 /***********************************************************************
2480 * process_mouse_message
2482 * returns TRUE if the contents of 'msg' should be passed to the application
2484 static BOOL process_mouse_message( MSG *msg, UINT hw_id, ULONG_PTR extra_info, HWND hwnd_filter,
2485 UINT first, UINT last, BOOL remove )
2487 static MSG clk_msg;
2489 POINT pt;
2490 UINT message;
2491 INT hittest;
2492 EVENTMSG event;
2493 GUITHREADINFO info;
2494 MOUSEHOOKSTRUCTEX hook;
2495 BOOL eatMsg;
2496 WPARAM wparam;
2498 /* find the window to dispatch this mouse message to */
2500 info.cbSize = sizeof(info);
2501 GetGUIThreadInfo( GetCurrentThreadId(), &info );
2502 if (info.hwndCapture)
2504 hittest = HTCLIENT;
2505 msg->hwnd = info.hwndCapture;
2507 else
2509 HWND orig = msg->hwnd;
2511 msg->hwnd = WINPOS_WindowFromPoint( msg->hwnd, msg->pt, &hittest );
2512 if (!msg->hwnd) /* As a heuristic, try the next window if it's the owner of orig */
2514 HWND next = GetWindow( orig, GW_HWNDNEXT );
2516 if (next && GetWindow( orig, GW_OWNER ) == next && WIN_IsCurrentThread( next ))
2517 msg->hwnd = WINPOS_WindowFromPoint( next, msg->pt, &hittest );
2521 if (!msg->hwnd || !WIN_IsCurrentThread( msg->hwnd ))
2523 accept_hardware_message( hw_id, TRUE );
2524 return FALSE;
2527 msg->pt = point_phys_to_win_dpi( msg->hwnd, msg->pt );
2528 SetThreadDpiAwarenessContext( GetWindowDpiAwarenessContext( msg->hwnd ));
2530 /* FIXME: is this really the right place for this hook? */
2531 event.message = msg->message;
2532 event.time = msg->time;
2533 event.hwnd = msg->hwnd;
2534 event.paramL = msg->pt.x;
2535 event.paramH = msg->pt.y;
2536 HOOK_CallHooks( WH_JOURNALRECORD, HC_ACTION, 0, (LPARAM)&event, TRUE );
2538 if (!check_hwnd_filter( msg, hwnd_filter )) return FALSE;
2540 pt = msg->pt;
2541 message = msg->message;
2542 wparam = msg->wParam;
2543 /* Note: windows has no concept of a non-client wheel message */
2544 if (message != WM_MOUSEWHEEL)
2546 if (hittest != HTCLIENT)
2548 message += WM_NCMOUSEMOVE - WM_MOUSEMOVE;
2549 wparam = hittest;
2551 else
2553 /* coordinates don't get translated while tracking a menu */
2554 /* FIXME: should differentiate popups and top-level menus */
2555 if (!(info.flags & GUI_INMENUMODE))
2556 ScreenToClient( msg->hwnd, &pt );
2559 msg->lParam = MAKELONG( pt.x, pt.y );
2561 /* translate double clicks */
2563 if ((msg->message == WM_LBUTTONDOWN) ||
2564 (msg->message == WM_RBUTTONDOWN) ||
2565 (msg->message == WM_MBUTTONDOWN) ||
2566 (msg->message == WM_XBUTTONDOWN))
2568 BOOL update = remove;
2570 /* translate double clicks -
2571 * note that ...MOUSEMOVEs can slip in between
2572 * ...BUTTONDOWN and ...BUTTONDBLCLK messages */
2574 if ((info.flags & (GUI_INMENUMODE|GUI_INMOVESIZE)) ||
2575 hittest != HTCLIENT ||
2576 (GetClassLongA( msg->hwnd, GCL_STYLE ) & CS_DBLCLKS))
2578 if ((msg->message == clk_msg.message) &&
2579 (msg->hwnd == clk_msg.hwnd) &&
2580 (msg->wParam == clk_msg.wParam) &&
2581 (msg->time - clk_msg.time < GetDoubleClickTime()) &&
2582 (abs(msg->pt.x - clk_msg.pt.x) < GetSystemMetrics(SM_CXDOUBLECLK)/2) &&
2583 (abs(msg->pt.y - clk_msg.pt.y) < GetSystemMetrics(SM_CYDOUBLECLK)/2))
2585 message += (WM_LBUTTONDBLCLK - WM_LBUTTONDOWN);
2586 if (update)
2588 clk_msg.message = 0; /* clear the double click conditions */
2589 update = FALSE;
2593 if (message < first || message > last) return FALSE;
2594 /* update static double click conditions */
2595 if (update) clk_msg = *msg;
2597 else
2599 if (message < first || message > last) return FALSE;
2601 msg->wParam = wparam;
2603 /* message is accepted now (but may still get dropped) */
2605 hook.s.pt = msg->pt;
2606 hook.s.hwnd = msg->hwnd;
2607 hook.s.wHitTestCode = hittest;
2608 hook.s.dwExtraInfo = extra_info;
2609 hook.mouseData = msg->wParam;
2610 if (HOOK_CallHooks( WH_MOUSE, remove ? HC_ACTION : HC_NOREMOVE,
2611 message, (LPARAM)&hook, TRUE ))
2613 hook.s.pt = msg->pt;
2614 hook.s.hwnd = msg->hwnd;
2615 hook.s.wHitTestCode = hittest;
2616 hook.s.dwExtraInfo = extra_info;
2617 hook.mouseData = msg->wParam;
2618 HOOK_CallHooks( WH_CBT, HCBT_CLICKSKIPPED, message, (LPARAM)&hook, TRUE );
2619 accept_hardware_message( hw_id, TRUE );
2620 return FALSE;
2623 if ((hittest == HTERROR) || (hittest == HTNOWHERE))
2625 SendMessageW( msg->hwnd, WM_SETCURSOR, (WPARAM)msg->hwnd,
2626 MAKELONG( hittest, msg->message ));
2627 accept_hardware_message( hw_id, TRUE );
2628 return FALSE;
2631 accept_hardware_message( hw_id, remove );
2633 if (!remove || info.hwndCapture)
2635 msg->message = message;
2636 return TRUE;
2639 eatMsg = FALSE;
2641 if ((msg->message == WM_LBUTTONDOWN) ||
2642 (msg->message == WM_RBUTTONDOWN) ||
2643 (msg->message == WM_MBUTTONDOWN) ||
2644 (msg->message == WM_XBUTTONDOWN))
2646 /* Send the WM_PARENTNOTIFY,
2647 * note that even for double/nonclient clicks
2648 * notification message is still WM_L/M/RBUTTONDOWN.
2650 send_parent_notify( msg->hwnd, msg->message, 0, msg->pt );
2652 /* Activate the window if needed */
2654 if (msg->hwnd != info.hwndActive)
2656 HWND hwndTop = GetAncestor( msg->hwnd, GA_ROOT );
2658 if ((GetWindowLongW( hwndTop, GWL_STYLE ) & (WS_POPUP|WS_CHILD)) != WS_CHILD)
2660 LONG ret = SendMessageW( msg->hwnd, WM_MOUSEACTIVATE, (WPARAM)hwndTop,
2661 MAKELONG( hittest, msg->message ) );
2662 switch(ret)
2664 case MA_NOACTIVATEANDEAT:
2665 eatMsg = TRUE;
2666 /* fall through */
2667 case MA_NOACTIVATE:
2668 break;
2669 case MA_ACTIVATEANDEAT:
2670 eatMsg = TRUE;
2671 /* fall through */
2672 case MA_ACTIVATE:
2673 case 0:
2674 if (!FOCUS_MouseActivate( hwndTop )) eatMsg = TRUE;
2675 break;
2676 default:
2677 WARN( "unknown WM_MOUSEACTIVATE code %d\n", ret );
2678 break;
2684 /* send the WM_SETCURSOR message */
2686 /* Windows sends the normal mouse message as the message parameter
2687 in the WM_SETCURSOR message even if it's non-client mouse message */
2688 SendMessageW( msg->hwnd, WM_SETCURSOR, (WPARAM)msg->hwnd, MAKELONG( hittest, msg->message ));
2690 msg->message = message;
2691 return !eatMsg;
2695 /***********************************************************************
2696 * process_hardware_message
2698 * Process a hardware message; return TRUE if message should be passed on to the app
2700 static BOOL process_hardware_message( MSG *msg, UINT hw_id, const struct hardware_msg_data *msg_data,
2701 HWND hwnd_filter, UINT first, UINT last, BOOL remove )
2703 DPI_AWARENESS_CONTEXT context;
2704 BOOL ret = FALSE;
2706 get_user_thread_info()->msg_source.deviceType = msg_data->source.device;
2707 get_user_thread_info()->msg_source.originId = msg_data->source.origin;
2709 /* hardware messages are always in physical coords */
2710 context = SetThreadDpiAwarenessContext( DPI_AWARENESS_CONTEXT_PER_MONITOR_AWARE );
2712 if (msg->message == WM_INPUT)
2713 ret = process_rawinput_message( msg, msg_data );
2714 else if (is_keyboard_message( msg->message ))
2715 ret = process_keyboard_message( msg, hw_id, hwnd_filter, first, last, remove );
2716 else if (is_mouse_message( msg->message ))
2717 ret = process_mouse_message( msg, hw_id, msg_data->info, hwnd_filter, first, last, remove );
2718 else
2719 ERR( "unknown message type %x\n", msg->message );
2720 SetThreadDpiAwarenessContext( context );
2721 return ret;
2725 /***********************************************************************
2726 * call_sendmsg_callback
2728 * Call the callback function of SendMessageCallback.
2730 static inline void call_sendmsg_callback( SENDASYNCPROC callback, HWND hwnd, UINT msg,
2731 ULONG_PTR data, LRESULT result )
2733 if (!callback) return;
2735 TRACE_(relay)( "\1Call message callback %p (hwnd=%p,msg=%s,data=%08lx,result=%08lx)\n",
2736 callback, hwnd, SPY_GetMsgName( msg, hwnd ), data, result );
2737 callback( hwnd, msg, data, result );
2738 TRACE_(relay)( "\1Ret message callback %p (hwnd=%p,msg=%s,data=%08lx,result=%08lx)\n",
2739 callback, hwnd, SPY_GetMsgName( msg, hwnd ), data, result );
2743 /***********************************************************************
2744 * peek_message
2746 * Peek for a message matching the given parameters. Return 0 if none are
2747 * available; -1 on error.
2748 * All pending sent messages are processed before returning.
2750 static int peek_message( MSG *msg, HWND hwnd, UINT first, UINT last, UINT flags, UINT changed_mask )
2752 LRESULT result;
2753 struct user_thread_info *thread_info = get_user_thread_info();
2754 INPUT_MESSAGE_SOURCE prev_source = thread_info->msg_source;
2755 struct received_message_info info, *old_info;
2756 unsigned int hw_id = 0; /* id of previous hardware message */
2757 void *buffer;
2758 size_t buffer_size = 256;
2760 if (!(buffer = HeapAlloc( GetProcessHeap(), 0, buffer_size ))) return -1;
2762 if (!first && !last) last = ~0;
2763 if (hwnd == HWND_BROADCAST) hwnd = HWND_TOPMOST;
2765 for (;;)
2767 NTSTATUS res;
2768 size_t size = 0;
2769 const message_data_t *msg_data = buffer;
2771 thread_info->msg_source = prev_source;
2773 SERVER_START_REQ( get_message )
2775 req->flags = flags;
2776 req->get_win = wine_server_user_handle( hwnd );
2777 req->get_first = first;
2778 req->get_last = last;
2779 req->hw_id = hw_id;
2780 req->wake_mask = changed_mask & (QS_SENDMESSAGE | QS_SMRESULT);
2781 req->changed_mask = changed_mask;
2782 wine_server_set_reply( req, buffer, buffer_size );
2783 if (!(res = wine_server_call( req )))
2785 size = wine_server_reply_size( reply );
2786 info.type = reply->type;
2787 info.msg.hwnd = wine_server_ptr_handle( reply->win );
2788 info.msg.message = reply->msg;
2789 info.msg.wParam = reply->wparam;
2790 info.msg.lParam = reply->lparam;
2791 info.msg.time = reply->time;
2792 info.msg.pt.x = reply->x;
2793 info.msg.pt.y = reply->y;
2794 hw_id = 0;
2795 thread_info->active_hooks = reply->active_hooks;
2797 else buffer_size = reply->total;
2799 SERVER_END_REQ;
2801 if (res)
2803 HeapFree( GetProcessHeap(), 0, buffer );
2804 if (res == STATUS_PENDING)
2806 thread_info->wake_mask = changed_mask & (QS_SENDMESSAGE | QS_SMRESULT);
2807 thread_info->changed_mask = changed_mask;
2808 return 0;
2810 if (res != STATUS_BUFFER_OVERFLOW)
2812 SetLastError( RtlNtStatusToDosError(res) );
2813 return -1;
2815 if (!(buffer = HeapAlloc( GetProcessHeap(), 0, buffer_size ))) return -1;
2816 continue;
2819 TRACE( "got type %d msg %x (%s) hwnd %p wp %lx lp %lx\n",
2820 info.type, info.msg.message,
2821 (info.type == MSG_WINEVENT) ? "MSG_WINEVENT" : SPY_GetMsgName(info.msg.message, info.msg.hwnd),
2822 info.msg.hwnd, info.msg.wParam, info.msg.lParam );
2824 switch(info.type)
2826 case MSG_ASCII:
2827 case MSG_UNICODE:
2828 info.flags = ISMEX_SEND;
2829 break;
2830 case MSG_NOTIFY:
2831 info.flags = ISMEX_NOTIFY;
2832 if (!unpack_message( info.msg.hwnd, info.msg.message, &info.msg.wParam,
2833 &info.msg.lParam, &buffer, size ))
2834 continue;
2835 break;
2836 case MSG_CALLBACK:
2837 info.flags = ISMEX_CALLBACK;
2838 break;
2839 case MSG_CALLBACK_RESULT:
2840 if (size >= sizeof(msg_data->callback))
2841 call_sendmsg_callback( wine_server_get_ptr(msg_data->callback.callback),
2842 info.msg.hwnd, info.msg.message,
2843 msg_data->callback.data, msg_data->callback.result );
2844 continue;
2845 case MSG_WINEVENT:
2846 if (size >= sizeof(msg_data->winevent))
2848 WINEVENTPROC hook_proc;
2849 HMODULE free_module = 0;
2851 hook_proc = wine_server_get_ptr( msg_data->winevent.hook_proc );
2852 size -= sizeof(msg_data->winevent);
2853 if (size)
2855 WCHAR module[MAX_PATH];
2857 size = min( size, (MAX_PATH - 1) * sizeof(WCHAR) );
2858 memcpy( module, &msg_data->winevent + 1, size );
2859 module[size / sizeof(WCHAR)] = 0;
2860 if (!(hook_proc = get_hook_proc( hook_proc, module, &free_module )))
2862 ERR( "invalid winevent hook module name %s\n", debugstr_w(module) );
2863 continue;
2867 TRACE_(relay)( "\1Call winevent proc %p (hook=%04x,event=%x,hwnd=%p,object_id=%lx,child_id=%lx,tid=%04x,time=%x)\n",
2868 hook_proc, msg_data->winevent.hook, info.msg.message, info.msg.hwnd,
2869 info.msg.wParam, info.msg.lParam, msg_data->winevent.tid, info.msg.time);
2871 hook_proc( wine_server_ptr_handle( msg_data->winevent.hook ), info.msg.message,
2872 info.msg.hwnd, info.msg.wParam, info.msg.lParam,
2873 msg_data->winevent.tid, info.msg.time );
2875 TRACE_(relay)( "\1Ret winevent proc %p (hook=%04x,event=%x,hwnd=%p,object_id=%lx,child_id=%lx,tid=%04x,time=%x)\n",
2876 hook_proc, msg_data->winevent.hook, info.msg.message, info.msg.hwnd,
2877 info.msg.wParam, info.msg.lParam, msg_data->winevent.tid, info.msg.time);
2879 if (free_module) FreeLibrary(free_module);
2881 continue;
2882 case MSG_HOOK_LL:
2883 info.flags = ISMEX_SEND;
2884 result = 0;
2885 if (info.msg.message == WH_KEYBOARD_LL && size >= sizeof(msg_data->hardware))
2887 KBDLLHOOKSTRUCT hook;
2889 hook.vkCode = LOWORD( info.msg.lParam );
2890 hook.scanCode = HIWORD( info.msg.lParam );
2891 hook.flags = msg_data->hardware.flags;
2892 hook.time = info.msg.time;
2893 hook.dwExtraInfo = msg_data->hardware.info;
2894 TRACE( "calling keyboard LL hook vk %x scan %x flags %x time %u info %lx\n",
2895 hook.vkCode, hook.scanCode, hook.flags, hook.time, hook.dwExtraInfo );
2896 result = HOOK_CallHooks( WH_KEYBOARD_LL, HC_ACTION, info.msg.wParam, (LPARAM)&hook, TRUE );
2898 else if (info.msg.message == WH_MOUSE_LL && size >= sizeof(msg_data->hardware))
2900 MSLLHOOKSTRUCT hook;
2902 hook.pt = info.msg.pt;
2903 hook.mouseData = info.msg.lParam;
2904 hook.flags = msg_data->hardware.flags;
2905 hook.time = info.msg.time;
2906 hook.dwExtraInfo = msg_data->hardware.info;
2907 TRACE( "calling mouse LL hook pos %d,%d data %x flags %x time %u info %lx\n",
2908 hook.pt.x, hook.pt.y, hook.mouseData, hook.flags, hook.time, hook.dwExtraInfo );
2909 result = HOOK_CallHooks( WH_MOUSE_LL, HC_ACTION, info.msg.wParam, (LPARAM)&hook, TRUE );
2911 reply_message( &info, result, TRUE );
2912 continue;
2913 case MSG_OTHER_PROCESS:
2914 info.flags = ISMEX_SEND;
2915 if (!unpack_message( info.msg.hwnd, info.msg.message, &info.msg.wParam,
2916 &info.msg.lParam, &buffer, size ))
2918 /* ignore it */
2919 reply_message( &info, 0, TRUE );
2920 continue;
2922 break;
2923 case MSG_HARDWARE:
2924 if (size >= sizeof(msg_data->hardware))
2926 hw_id = msg_data->hardware.hw_id;
2927 if (!process_hardware_message( &info.msg, hw_id, &msg_data->hardware,
2928 hwnd, first, last, flags & PM_REMOVE ))
2930 TRACE("dropping msg %x\n", info.msg.message );
2931 continue; /* ignore it */
2933 *msg = info.msg;
2934 thread_info->GetMessagePosVal = MAKELONG( info.msg.pt.x, info.msg.pt.y );
2935 thread_info->GetMessageTimeVal = info.msg.time;
2936 thread_info->GetMessageExtraInfoVal = msg_data->hardware.info;
2937 HeapFree( GetProcessHeap(), 0, buffer );
2938 HOOK_CallHooks( WH_GETMESSAGE, HC_ACTION, flags & PM_REMOVE, (LPARAM)msg, TRUE );
2939 return 1;
2941 continue;
2942 case MSG_POSTED:
2943 if (info.msg.message & 0x80000000) /* internal message */
2945 if (flags & PM_REMOVE)
2947 handle_internal_message( info.msg.hwnd, info.msg.message,
2948 info.msg.wParam, info.msg.lParam );
2949 /* if this is a nested call return right away */
2950 if (first == info.msg.message && last == info.msg.message)
2952 HeapFree( GetProcessHeap(), 0, buffer );
2953 return 0;
2956 else
2957 peek_message( msg, info.msg.hwnd, info.msg.message,
2958 info.msg.message, flags | PM_REMOVE, changed_mask );
2959 continue;
2961 if (info.msg.message >= WM_DDE_FIRST && info.msg.message <= WM_DDE_LAST)
2963 if (!unpack_dde_message( info.msg.hwnd, info.msg.message, &info.msg.wParam,
2964 &info.msg.lParam, &buffer, size ))
2965 continue; /* ignore it */
2967 *msg = info.msg;
2968 msg->pt = point_phys_to_win_dpi( info.msg.hwnd, info.msg.pt );
2969 thread_info->GetMessagePosVal = MAKELONG( msg->pt.x, msg->pt.y );
2970 thread_info->GetMessageTimeVal = info.msg.time;
2971 thread_info->GetMessageExtraInfoVal = 0;
2972 thread_info->msg_source = msg_source_unavailable;
2973 HeapFree( GetProcessHeap(), 0, buffer );
2974 HOOK_CallHooks( WH_GETMESSAGE, HC_ACTION, flags & PM_REMOVE, (LPARAM)msg, TRUE );
2975 return 1;
2978 /* if we get here, we have a sent message; call the window procedure */
2979 old_info = thread_info->receive_info;
2980 thread_info->receive_info = &info;
2981 thread_info->msg_source = msg_source_unavailable;
2982 result = call_window_proc( info.msg.hwnd, info.msg.message, info.msg.wParam,
2983 info.msg.lParam, (info.type != MSG_ASCII), FALSE,
2984 WMCHAR_MAP_RECVMESSAGE );
2985 reply_message( &info, result, TRUE );
2986 thread_info->receive_info = old_info;
2988 /* if some PM_QS* flags were specified, only handle sent messages from now on */
2989 if (HIWORD(flags) && !changed_mask) flags = PM_QS_SENDMESSAGE | LOWORD(flags);
2994 /***********************************************************************
2995 * process_sent_messages
2997 * Process all pending sent messages.
2999 static inline void process_sent_messages(void)
3001 MSG msg;
3002 peek_message( &msg, 0, 0, 0, PM_REMOVE | PM_QS_SENDMESSAGE, 0 );
3006 /***********************************************************************
3007 * get_server_queue_handle
3009 * Get a handle to the server message queue for the current thread.
3011 static HANDLE get_server_queue_handle(void)
3013 struct user_thread_info *thread_info = get_user_thread_info();
3014 HANDLE ret;
3016 if (!(ret = thread_info->server_queue))
3018 SERVER_START_REQ( get_msg_queue )
3020 wine_server_call( req );
3021 ret = wine_server_ptr_handle( reply->handle );
3023 SERVER_END_REQ;
3024 thread_info->server_queue = ret;
3025 if (!ret) ERR( "Cannot get server thread queue\n" );
3027 return ret;
3031 /***********************************************************************
3032 * wait_message_reply
3034 * Wait until a sent message gets replied to.
3036 static void wait_message_reply( UINT flags )
3038 struct user_thread_info *thread_info = get_user_thread_info();
3039 HANDLE server_queue = get_server_queue_handle();
3040 unsigned int wake_mask = QS_SMRESULT | ((flags & SMTO_BLOCK) ? 0 : QS_SENDMESSAGE);
3042 for (;;)
3044 unsigned int wake_bits = 0;
3046 SERVER_START_REQ( set_queue_mask )
3048 req->wake_mask = wake_mask;
3049 req->changed_mask = wake_mask;
3050 req->skip_wait = 1;
3051 if (!wine_server_call( req )) wake_bits = reply->wake_bits & wake_mask;
3053 SERVER_END_REQ;
3055 thread_info->wake_mask = thread_info->changed_mask = 0;
3057 if (wake_bits & QS_SMRESULT) return; /* got a result */
3058 if (wake_bits & QS_SENDMESSAGE)
3060 /* Process the sent message immediately */
3061 process_sent_messages();
3062 continue;
3065 wow_handlers.wait_message( 1, &server_queue, INFINITE, wake_mask, 0 );
3070 /***********************************************************************
3071 * wait_objects
3073 * Wait for multiple objects including the server queue, with specific queue masks.
3075 static DWORD wait_objects( DWORD count, const HANDLE *handles, DWORD timeout,
3076 DWORD wake_mask, DWORD changed_mask, DWORD flags )
3078 struct user_thread_info *thread_info = get_user_thread_info();
3079 DWORD ret;
3081 assert( count ); /* we must have at least the server queue */
3083 flush_window_surfaces( TRUE );
3085 if (thread_info->wake_mask != wake_mask || thread_info->changed_mask != changed_mask)
3087 SERVER_START_REQ( set_queue_mask )
3089 req->wake_mask = wake_mask;
3090 req->changed_mask = changed_mask;
3091 req->skip_wait = 0;
3092 wine_server_call( req );
3094 SERVER_END_REQ;
3095 thread_info->wake_mask = wake_mask;
3096 thread_info->changed_mask = changed_mask;
3099 ret = wow_handlers.wait_message( count, handles, timeout, changed_mask, flags );
3101 if (ret != WAIT_TIMEOUT) thread_info->wake_mask = thread_info->changed_mask = 0;
3102 return ret;
3106 /***********************************************************************
3107 * put_message_in_queue
3109 * Put a sent message into the destination queue.
3110 * For inter-process message, reply_size is set to expected size of reply data.
3112 static BOOL put_message_in_queue( const struct send_message_info *info, size_t *reply_size )
3114 struct packed_message data;
3115 message_data_t msg_data;
3116 unsigned int res;
3117 int i;
3118 timeout_t timeout = TIMEOUT_INFINITE;
3120 /* Check for INFINITE timeout for compatibility with Win9x,
3121 * although Windows >= NT does not do so
3123 if (info->type != MSG_NOTIFY &&
3124 info->type != MSG_CALLBACK &&
3125 info->type != MSG_POSTED &&
3126 info->timeout &&
3127 info->timeout != INFINITE)
3129 /* timeout is signed despite the prototype */
3130 timeout = (timeout_t)max( 0, (int)info->timeout ) * -10000;
3133 memset( &data, 0, sizeof(data) );
3134 if (info->type == MSG_OTHER_PROCESS || info->type == MSG_NOTIFY)
3136 *reply_size = pack_message( info->hwnd, info->msg, info->wparam, info->lparam, &data );
3137 if (data.count == -1)
3139 WARN( "cannot pack message %x\n", info->msg );
3140 return FALSE;
3143 else if (info->type == MSG_CALLBACK)
3145 msg_data.callback.callback = wine_server_client_ptr( info->callback );
3146 msg_data.callback.data = info->data;
3147 msg_data.callback.result = 0;
3148 data.data[0] = &msg_data;
3149 data.size[0] = sizeof(msg_data.callback);
3150 data.count = 1;
3152 else if (info->type == MSG_POSTED && info->msg >= WM_DDE_FIRST && info->msg <= WM_DDE_LAST)
3154 return post_dde_message( &data, info );
3157 SERVER_START_REQ( send_message )
3159 req->id = info->dest_tid;
3160 req->type = info->type;
3161 req->flags = 0;
3162 req->win = wine_server_user_handle( info->hwnd );
3163 req->msg = info->msg;
3164 req->wparam = info->wparam;
3165 req->lparam = info->lparam;
3166 req->timeout = timeout;
3168 if (info->flags & SMTO_ABORTIFHUNG) req->flags |= SEND_MSG_ABORT_IF_HUNG;
3169 for (i = 0; i < data.count; i++) wine_server_add_data( req, data.data[i], data.size[i] );
3170 if ((res = wine_server_call( req )))
3172 if (res == STATUS_INVALID_PARAMETER)
3173 /* FIXME: find a STATUS_ value for this one */
3174 SetLastError( ERROR_INVALID_THREAD_ID );
3175 else
3176 SetLastError( RtlNtStatusToDosError(res) );
3179 SERVER_END_REQ;
3180 return !res;
3184 /***********************************************************************
3185 * retrieve_reply
3187 * Retrieve a message reply from the server.
3189 static LRESULT retrieve_reply( const struct send_message_info *info,
3190 size_t reply_size, LRESULT *result )
3192 NTSTATUS status;
3193 void *reply_data = NULL;
3195 if (reply_size)
3197 if (!(reply_data = HeapAlloc( GetProcessHeap(), 0, reply_size )))
3199 WARN( "no memory for reply, will be truncated\n" );
3200 reply_size = 0;
3203 SERVER_START_REQ( get_message_reply )
3205 req->cancel = 1;
3206 if (reply_size) wine_server_set_reply( req, reply_data, reply_size );
3207 if (!(status = wine_server_call( req ))) *result = reply->result;
3208 reply_size = wine_server_reply_size( reply );
3210 SERVER_END_REQ;
3211 if (!status && reply_size)
3212 unpack_reply( info->hwnd, info->msg, info->wparam, info->lparam, reply_data, reply_size );
3214 HeapFree( GetProcessHeap(), 0, reply_data );
3216 TRACE( "hwnd %p msg %x (%s) wp %lx lp %lx got reply %lx (err=%d)\n",
3217 info->hwnd, info->msg, SPY_GetMsgName(info->msg, info->hwnd), info->wparam,
3218 info->lparam, *result, status );
3220 /* MSDN states that last error is 0 on timeout, but at least NT4 returns ERROR_TIMEOUT */
3221 if (status) SetLastError( RtlNtStatusToDosError(status) );
3222 return !status;
3226 /***********************************************************************
3227 * send_inter_thread_message
3229 static LRESULT send_inter_thread_message( const struct send_message_info *info, LRESULT *res_ptr )
3231 size_t reply_size = 0;
3233 TRACE( "hwnd %p msg %x (%s) wp %lx lp %lx\n",
3234 info->hwnd, info->msg, SPY_GetMsgName(info->msg, info->hwnd), info->wparam, info->lparam );
3236 USER_CheckNotLock();
3238 if (!put_message_in_queue( info, &reply_size )) return 0;
3240 /* there's no reply to wait for on notify/callback messages */
3241 if (info->type == MSG_NOTIFY || info->type == MSG_CALLBACK) return 1;
3243 wait_message_reply( info->flags );
3244 return retrieve_reply( info, reply_size, res_ptr );
3248 /***********************************************************************
3249 * send_inter_thread_callback
3251 static LRESULT send_inter_thread_callback( HWND hwnd, UINT msg, WPARAM wp, LPARAM lp,
3252 LRESULT *result, void *arg )
3254 struct send_message_info *info = arg;
3255 info->hwnd = hwnd;
3256 info->msg = msg;
3257 info->wparam = wp;
3258 info->lparam = lp;
3259 return send_inter_thread_message( info, result );
3262 static BOOL is_message_broadcastable(UINT msg)
3264 return msg < WM_USER || msg >= 0xc000;
3267 /***********************************************************************
3268 * send_message
3270 * Backend implementation of the various SendMessage functions.
3272 static BOOL send_message( struct send_message_info *info, DWORD_PTR *res_ptr, BOOL unicode )
3274 struct user_thread_info *thread_info = get_user_thread_info();
3275 INPUT_MESSAGE_SOURCE prev_source = thread_info->msg_source;
3276 DWORD dest_pid;
3277 BOOL ret;
3278 LRESULT result;
3280 if (is_broadcast(info->hwnd))
3282 if (is_message_broadcastable( info->msg ))
3283 EnumWindows( broadcast_message_callback, (LPARAM)info );
3284 if (res_ptr) *res_ptr = 1;
3285 return TRUE;
3288 if (!(info->dest_tid = GetWindowThreadProcessId( info->hwnd, &dest_pid ))) return FALSE;
3290 if (USER_IsExitingThread( info->dest_tid )) return FALSE;
3292 thread_info->msg_source = msg_source_unavailable;
3293 SPY_EnterMessage( SPY_SENDMESSAGE, info->hwnd, info->msg, info->wparam, info->lparam );
3295 if (info->dest_tid == GetCurrentThreadId())
3297 result = call_window_proc( info->hwnd, info->msg, info->wparam, info->lparam,
3298 unicode, TRUE, info->wm_char );
3299 if (info->type == MSG_CALLBACK)
3300 call_sendmsg_callback( info->callback, info->hwnd, info->msg, info->data, result );
3301 ret = TRUE;
3303 else
3305 if (dest_pid != GetCurrentProcessId() && (info->type == MSG_ASCII || info->type == MSG_UNICODE))
3306 info->type = MSG_OTHER_PROCESS;
3308 /* MSG_ASCII can be sent unconverted except for WM_CHAR; everything else needs to be Unicode */
3309 if (!unicode && is_unicode_message( info->msg ) &&
3310 (info->type != MSG_ASCII || info->msg == WM_CHAR))
3311 ret = WINPROC_CallProcAtoW( send_inter_thread_callback, info->hwnd, info->msg,
3312 info->wparam, info->lparam, &result, info, info->wm_char );
3313 else
3314 ret = send_inter_thread_message( info, &result );
3317 SPY_ExitMessage( SPY_RESULT_OK, info->hwnd, info->msg, result, info->wparam, info->lparam );
3318 thread_info->msg_source = prev_source;
3319 if (ret && res_ptr) *res_ptr = result;
3320 return ret;
3324 /***********************************************************************
3325 * send_hardware_message
3327 NTSTATUS send_hardware_message( HWND hwnd, const INPUT *input, UINT flags )
3329 struct user_key_state_info *key_state_info = get_user_thread_info()->key_state;
3330 struct send_message_info info;
3331 int prev_x, prev_y, new_x, new_y;
3332 INT counter = global_key_state_counter;
3333 NTSTATUS ret;
3334 BOOL wait;
3336 info.type = MSG_HARDWARE;
3337 info.dest_tid = 0;
3338 info.hwnd = hwnd;
3339 info.flags = 0;
3340 info.timeout = 0;
3342 SERVER_START_REQ( send_hardware_message )
3344 req->win = wine_server_user_handle( hwnd );
3345 req->flags = flags;
3346 req->input.type = input->type;
3347 switch (input->type)
3349 case INPUT_MOUSE:
3350 req->input.mouse.x = input->u.mi.dx;
3351 req->input.mouse.y = input->u.mi.dy;
3352 req->input.mouse.data = input->u.mi.mouseData;
3353 req->input.mouse.flags = input->u.mi.dwFlags;
3354 req->input.mouse.time = input->u.mi.time;
3355 req->input.mouse.info = input->u.mi.dwExtraInfo;
3356 break;
3357 case INPUT_KEYBOARD:
3358 req->input.kbd.vkey = input->u.ki.wVk;
3359 req->input.kbd.scan = input->u.ki.wScan;
3360 req->input.kbd.flags = input->u.ki.dwFlags;
3361 req->input.kbd.time = input->u.ki.time;
3362 req->input.kbd.info = input->u.ki.dwExtraInfo;
3363 break;
3364 case INPUT_HARDWARE:
3365 req->input.hw.msg = input->u.hi.uMsg;
3366 req->input.hw.lparam = MAKELONG( input->u.hi.wParamL, input->u.hi.wParamH );
3367 break;
3369 if (key_state_info) wine_server_set_reply( req, key_state_info->state,
3370 sizeof(key_state_info->state) );
3371 ret = wine_server_call( req );
3372 wait = reply->wait;
3373 prev_x = reply->prev_x;
3374 prev_y = reply->prev_y;
3375 new_x = reply->new_x;
3376 new_y = reply->new_y;
3378 SERVER_END_REQ;
3380 if (!ret)
3382 if (key_state_info)
3384 key_state_info->time = GetTickCount();
3385 key_state_info->counter = counter;
3387 if ((flags & SEND_HWMSG_INJECTED) && (prev_x != new_x || prev_y != new_y))
3388 USER_Driver->pSetCursorPos( new_x, new_y );
3391 if (wait)
3393 LRESULT ignored;
3394 wait_message_reply( 0 );
3395 retrieve_reply( &info, 0, &ignored );
3397 return ret;
3401 /***********************************************************************
3402 * MSG_SendInternalMessageTimeout
3404 * Same as SendMessageTimeoutW but sends the message to a specific thread
3405 * without requiring a window handle. Only works for internal Wine messages.
3407 LRESULT MSG_SendInternalMessageTimeout( DWORD dest_pid, DWORD dest_tid,
3408 UINT msg, WPARAM wparam, LPARAM lparam,
3409 UINT flags, UINT timeout, PDWORD_PTR res_ptr )
3411 struct send_message_info info;
3412 LRESULT ret, result;
3414 assert( msg & 0x80000000 ); /* must be an internal Wine message */
3416 info.type = MSG_UNICODE;
3417 info.dest_tid = dest_tid;
3418 info.hwnd = 0;
3419 info.msg = msg;
3420 info.wparam = wparam;
3421 info.lparam = lparam;
3422 info.flags = flags;
3423 info.timeout = timeout;
3425 if (USER_IsExitingThread( dest_tid )) return 0;
3427 if (dest_tid == GetCurrentThreadId())
3429 result = handle_internal_message( 0, msg, wparam, lparam );
3430 ret = 1;
3432 else
3434 if (dest_pid != GetCurrentProcessId()) info.type = MSG_OTHER_PROCESS;
3435 ret = send_inter_thread_message( &info, &result );
3437 if (ret && res_ptr) *res_ptr = result;
3438 return ret;
3442 /***********************************************************************
3443 * SendMessageTimeoutW (USER32.@)
3445 LRESULT WINAPI SendMessageTimeoutW( HWND hwnd, UINT msg, WPARAM wparam, LPARAM lparam,
3446 UINT flags, UINT timeout, PDWORD_PTR res_ptr )
3448 struct send_message_info info;
3450 info.type = MSG_UNICODE;
3451 info.hwnd = hwnd;
3452 info.msg = msg;
3453 info.wparam = wparam;
3454 info.lparam = lparam;
3455 info.flags = flags;
3456 info.timeout = timeout;
3458 return send_message( &info, res_ptr, TRUE );
3461 /***********************************************************************
3462 * SendMessageTimeoutA (USER32.@)
3464 LRESULT WINAPI SendMessageTimeoutA( HWND hwnd, UINT msg, WPARAM wparam, LPARAM lparam,
3465 UINT flags, UINT timeout, PDWORD_PTR res_ptr )
3467 struct send_message_info info;
3469 info.type = MSG_ASCII;
3470 info.hwnd = hwnd;
3471 info.msg = msg;
3472 info.wparam = wparam;
3473 info.lparam = lparam;
3474 info.flags = flags;
3475 info.timeout = timeout;
3476 info.wm_char = WMCHAR_MAP_SENDMESSAGETIMEOUT;
3478 return send_message( &info, res_ptr, FALSE );
3482 /***********************************************************************
3483 * SendMessageW (USER32.@)
3485 LRESULT WINAPI SendMessageW( HWND hwnd, UINT msg, WPARAM wparam, LPARAM lparam )
3487 DWORD_PTR res = 0;
3488 struct send_message_info info;
3490 info.type = MSG_UNICODE;
3491 info.hwnd = hwnd;
3492 info.msg = msg;
3493 info.wparam = wparam;
3494 info.lparam = lparam;
3495 info.flags = SMTO_NORMAL;
3496 info.timeout = 0;
3498 send_message( &info, &res, TRUE );
3499 return res;
3503 /***********************************************************************
3504 * SendMessageA (USER32.@)
3506 LRESULT WINAPI SendMessageA( HWND hwnd, UINT msg, WPARAM wparam, LPARAM lparam )
3508 DWORD_PTR res = 0;
3509 struct send_message_info info;
3511 info.type = MSG_ASCII;
3512 info.hwnd = hwnd;
3513 info.msg = msg;
3514 info.wparam = wparam;
3515 info.lparam = lparam;
3516 info.flags = SMTO_NORMAL;
3517 info.timeout = 0;
3518 info.wm_char = WMCHAR_MAP_SENDMESSAGE;
3520 send_message( &info, &res, FALSE );
3521 return res;
3525 /***********************************************************************
3526 * SendNotifyMessageA (USER32.@)
3528 BOOL WINAPI SendNotifyMessageA( HWND hwnd, UINT msg, WPARAM wparam, LPARAM lparam )
3530 struct send_message_info info;
3532 if (is_pointer_message( msg, wparam ))
3534 SetLastError( ERROR_MESSAGE_SYNC_ONLY );
3535 return FALSE;
3538 info.type = MSG_NOTIFY;
3539 info.hwnd = hwnd;
3540 info.msg = msg;
3541 info.wparam = wparam;
3542 info.lparam = lparam;
3543 info.flags = 0;
3544 info.wm_char = WMCHAR_MAP_SENDMESSAGETIMEOUT;
3546 return send_message( &info, NULL, FALSE );
3550 /***********************************************************************
3551 * SendNotifyMessageW (USER32.@)
3553 BOOL WINAPI SendNotifyMessageW( HWND hwnd, UINT msg, WPARAM wparam, LPARAM lparam )
3555 struct send_message_info info;
3557 if (is_pointer_message( msg, wparam ))
3559 SetLastError( ERROR_MESSAGE_SYNC_ONLY );
3560 return FALSE;
3563 info.type = MSG_NOTIFY;
3564 info.hwnd = hwnd;
3565 info.msg = msg;
3566 info.wparam = wparam;
3567 info.lparam = lparam;
3568 info.flags = 0;
3570 return send_message( &info, NULL, TRUE );
3574 /***********************************************************************
3575 * SendMessageCallbackA (USER32.@)
3577 BOOL WINAPI SendMessageCallbackA( HWND hwnd, UINT msg, WPARAM wparam, LPARAM lparam,
3578 SENDASYNCPROC callback, ULONG_PTR data )
3580 struct send_message_info info;
3582 if (is_pointer_message( msg, wparam ))
3584 SetLastError( ERROR_MESSAGE_SYNC_ONLY );
3585 return FALSE;
3588 info.type = MSG_CALLBACK;
3589 info.hwnd = hwnd;
3590 info.msg = msg;
3591 info.wparam = wparam;
3592 info.lparam = lparam;
3593 info.callback = callback;
3594 info.data = data;
3595 info.flags = 0;
3596 info.wm_char = WMCHAR_MAP_SENDMESSAGETIMEOUT;
3598 return send_message( &info, NULL, FALSE );
3602 /***********************************************************************
3603 * SendMessageCallbackW (USER32.@)
3605 BOOL WINAPI SendMessageCallbackW( HWND hwnd, UINT msg, WPARAM wparam, LPARAM lparam,
3606 SENDASYNCPROC callback, ULONG_PTR data )
3608 struct send_message_info info;
3610 if (is_pointer_message( msg, wparam ))
3612 SetLastError( ERROR_MESSAGE_SYNC_ONLY );
3613 return FALSE;
3616 info.type = MSG_CALLBACK;
3617 info.hwnd = hwnd;
3618 info.msg = msg;
3619 info.wparam = wparam;
3620 info.lparam = lparam;
3621 info.callback = callback;
3622 info.data = data;
3623 info.flags = 0;
3625 return send_message( &info, NULL, TRUE );
3629 /***********************************************************************
3630 * ReplyMessage (USER32.@)
3632 BOOL WINAPI ReplyMessage( LRESULT result )
3634 struct received_message_info *info = get_user_thread_info()->receive_info;
3636 if (!info) return FALSE;
3637 reply_message( info, result, FALSE );
3638 return TRUE;
3642 /***********************************************************************
3643 * InSendMessage (USER32.@)
3645 BOOL WINAPI InSendMessage(void)
3647 return (InSendMessageEx( NULL ) & (ISMEX_SEND | ISMEX_NOTIFY | ISMEX_CALLBACK)) != 0;
3651 /***********************************************************************
3652 * InSendMessageEx (USER32.@)
3654 DWORD WINAPI InSendMessageEx( LPVOID reserved )
3656 struct received_message_info *info = get_user_thread_info()->receive_info;
3658 if (info) return info->flags;
3659 return ISMEX_NOSEND;
3663 /***********************************************************************
3664 * PostMessageA (USER32.@)
3666 BOOL WINAPI PostMessageA( HWND hwnd, UINT msg, WPARAM wparam, LPARAM lparam )
3668 if (!map_wparam_AtoW( msg, &wparam, WMCHAR_MAP_POSTMESSAGE )) return TRUE;
3669 return PostMessageW( hwnd, msg, wparam, lparam );
3673 /***********************************************************************
3674 * PostMessageW (USER32.@)
3676 BOOL WINAPI PostMessageW( HWND hwnd, UINT msg, WPARAM wparam, LPARAM lparam )
3678 struct send_message_info info;
3680 if (is_pointer_message( msg, wparam ))
3682 SetLastError( ERROR_MESSAGE_SYNC_ONLY );
3683 return FALSE;
3686 TRACE( "hwnd %p msg %x (%s) wp %lx lp %lx\n",
3687 hwnd, msg, SPY_GetMsgName(msg, hwnd), wparam, lparam );
3689 info.type = MSG_POSTED;
3690 info.hwnd = hwnd;
3691 info.msg = msg;
3692 info.wparam = wparam;
3693 info.lparam = lparam;
3694 info.flags = 0;
3696 if (is_broadcast(hwnd))
3698 if (is_message_broadcastable( info.msg ))
3699 EnumWindows( broadcast_message_callback, (LPARAM)&info );
3700 return TRUE;
3703 if (!hwnd) return PostThreadMessageW( GetCurrentThreadId(), msg, wparam, lparam );
3705 if (!(info.dest_tid = GetWindowThreadProcessId( hwnd, NULL ))) return FALSE;
3707 if (USER_IsExitingThread( info.dest_tid )) return TRUE;
3709 return put_message_in_queue( &info, NULL );
3713 /**********************************************************************
3714 * PostThreadMessageA (USER32.@)
3716 BOOL WINAPI PostThreadMessageA( DWORD thread, UINT msg, WPARAM wparam, LPARAM lparam )
3718 if (!map_wparam_AtoW( msg, &wparam, WMCHAR_MAP_POSTMESSAGE )) return TRUE;
3719 return PostThreadMessageW( thread, msg, wparam, lparam );
3723 /**********************************************************************
3724 * PostThreadMessageW (USER32.@)
3726 BOOL WINAPI PostThreadMessageW( DWORD thread, UINT msg, WPARAM wparam, LPARAM lparam )
3728 struct send_message_info info;
3730 if (is_pointer_message( msg, wparam ))
3732 SetLastError( ERROR_MESSAGE_SYNC_ONLY );
3733 return FALSE;
3735 if (USER_IsExitingThread( thread )) return TRUE;
3737 info.type = MSG_POSTED;
3738 info.dest_tid = thread;
3739 info.hwnd = 0;
3740 info.msg = msg;
3741 info.wparam = wparam;
3742 info.lparam = lparam;
3743 info.flags = 0;
3744 return put_message_in_queue( &info, NULL );
3748 /***********************************************************************
3749 * PostQuitMessage (USER32.@)
3751 * Posts a quit message to the current thread's message queue.
3753 * PARAMS
3754 * exit_code [I] Exit code to return from message loop.
3756 * RETURNS
3757 * Nothing.
3759 * NOTES
3760 * This function is not the same as calling:
3761 *|PostThreadMessage(GetCurrentThreadId(), WM_QUIT, exit_code, 0);
3762 * It instead sets a flag in the message queue that signals it to generate
3763 * a WM_QUIT message when there are no other pending sent or posted messages
3764 * in the queue.
3766 void WINAPI PostQuitMessage( INT exit_code )
3768 SERVER_START_REQ( post_quit_message )
3770 req->exit_code = exit_code;
3771 wine_server_call( req );
3773 SERVER_END_REQ;
3776 /* check for driver events if we detect that the app is not properly consuming messages */
3777 static inline void check_for_driver_events( UINT msg )
3779 if (get_user_thread_info()->message_count > 200)
3781 flush_window_surfaces( FALSE );
3782 USER_Driver->pMsgWaitForMultipleObjectsEx( 0, NULL, 0, QS_ALLINPUT, 0 );
3784 else if (msg == WM_TIMER || msg == WM_SYSTIMER)
3786 /* driver events should have priority over timers, so make sure we'll check for them soon */
3787 get_user_thread_info()->message_count += 100;
3789 else get_user_thread_info()->message_count++;
3792 /***********************************************************************
3793 * PeekMessageW (USER32.@)
3795 BOOL WINAPI DECLSPEC_HOTPATCH PeekMessageW( MSG *msg_out, HWND hwnd, UINT first, UINT last, UINT flags )
3797 MSG msg;
3798 int ret;
3800 USER_CheckNotLock();
3801 check_for_driver_events( 0 );
3803 ret = peek_message( &msg, hwnd, first, last, flags, 0 );
3804 if (ret < 0) return FALSE;
3806 if (!ret)
3808 flush_window_surfaces( TRUE );
3809 ret = wow_handlers.wait_message( 0, NULL, 0, QS_ALLINPUT, 0 );
3810 /* if we received driver events, check again for a pending message */
3811 if (ret == WAIT_TIMEOUT || peek_message( &msg, hwnd, first, last, flags, 0 ) <= 0) return FALSE;
3814 check_for_driver_events( msg.message );
3816 /* copy back our internal safe copy of message data to msg_out.
3817 * msg_out is a variable from the *program*, so it can't be used
3818 * internally as it can get "corrupted" by our use of SendMessage()
3819 * (back to the program) inside the message handling itself. */
3820 if (!msg_out)
3822 SetLastError( ERROR_NOACCESS );
3823 return FALSE;
3825 *msg_out = msg;
3826 return TRUE;
3830 /***********************************************************************
3831 * PeekMessageA (USER32.@)
3833 BOOL WINAPI DECLSPEC_HOTPATCH PeekMessageA( MSG *msg, HWND hwnd, UINT first, UINT last, UINT flags )
3835 if (get_pending_wmchar( msg, first, last, (flags & PM_REMOVE) )) return TRUE;
3836 if (!PeekMessageW( msg, hwnd, first, last, flags )) return FALSE;
3837 map_wparam_WtoA( msg, (flags & PM_REMOVE) );
3838 return TRUE;
3842 /***********************************************************************
3843 * GetMessageW (USER32.@)
3845 BOOL WINAPI DECLSPEC_HOTPATCH GetMessageW( MSG *msg, HWND hwnd, UINT first, UINT last )
3847 HANDLE server_queue = get_server_queue_handle();
3848 unsigned int mask = QS_POSTMESSAGE | QS_SENDMESSAGE; /* Always selected */
3849 int ret;
3851 USER_CheckNotLock();
3852 check_for_driver_events( 0 );
3854 if (first || last)
3856 if ((first <= WM_KEYLAST) && (last >= WM_KEYFIRST)) mask |= QS_KEY;
3857 if ( ((first <= WM_MOUSELAST) && (last >= WM_MOUSEFIRST)) ||
3858 ((first <= WM_NCMOUSELAST) && (last >= WM_NCMOUSEFIRST)) ) mask |= QS_MOUSE;
3859 if ((first <= WM_TIMER) && (last >= WM_TIMER)) mask |= QS_TIMER;
3860 if ((first <= WM_SYSTIMER) && (last >= WM_SYSTIMER)) mask |= QS_TIMER;
3861 if ((first <= WM_PAINT) && (last >= WM_PAINT)) mask |= QS_PAINT;
3863 else mask = QS_ALLINPUT;
3865 while (!(ret = peek_message( msg, hwnd, first, last, PM_REMOVE | (mask << 16), mask )))
3867 wait_objects( 1, &server_queue, INFINITE, mask & (QS_SENDMESSAGE | QS_SMRESULT), mask, 0 );
3869 if (ret < 0) return -1;
3871 check_for_driver_events( msg->message );
3873 return (msg->message != WM_QUIT);
3877 /***********************************************************************
3878 * GetMessageA (USER32.@)
3880 BOOL WINAPI DECLSPEC_HOTPATCH GetMessageA( MSG *msg, HWND hwnd, UINT first, UINT last )
3882 if (get_pending_wmchar( msg, first, last, TRUE )) return TRUE;
3883 if (GetMessageW( msg, hwnd, first, last ) < 0) return -1;
3884 map_wparam_WtoA( msg, TRUE );
3885 return (msg->message != WM_QUIT);
3889 /***********************************************************************
3890 * IsDialogMessageA (USER32.@)
3891 * IsDialogMessage (USER32.@)
3893 BOOL WINAPI IsDialogMessageA( HWND hwndDlg, LPMSG pmsg )
3895 MSG msg = *pmsg;
3896 map_wparam_AtoW( msg.message, &msg.wParam, WMCHAR_MAP_NOMAPPING );
3897 return IsDialogMessageW( hwndDlg, &msg );
3901 /***********************************************************************
3902 * TranslateMessage (USER32.@)
3904 * Implementation of TranslateMessage.
3906 * TranslateMessage translates virtual-key messages into character-messages,
3907 * as follows :
3908 * WM_KEYDOWN/WM_KEYUP combinations produce a WM_CHAR or WM_DEADCHAR message.
3909 * ditto replacing WM_* with WM_SYS*
3910 * This produces WM_CHAR messages only for keys mapped to ASCII characters
3911 * by the keyboard driver.
3913 * If the message is WM_KEYDOWN, WM_KEYUP, WM_SYSKEYDOWN, or WM_SYSKEYUP, the
3914 * return value is nonzero, regardless of the translation.
3917 BOOL WINAPI TranslateMessage( const MSG *msg )
3919 UINT message;
3920 WCHAR wp[8];
3921 BYTE state[256];
3922 INT len;
3924 if (msg->message < WM_KEYFIRST || msg->message > WM_KEYLAST) return FALSE;
3925 if (msg->message != WM_KEYDOWN && msg->message != WM_SYSKEYDOWN) return TRUE;
3927 TRACE_(key)("Translating key %s (%04lX), scancode %04x\n",
3928 SPY_GetVKeyName(msg->wParam), msg->wParam, HIWORD(msg->lParam));
3930 switch (msg->wParam)
3932 case VK_PACKET:
3933 message = (msg->message == WM_KEYDOWN) ? WM_CHAR : WM_SYSCHAR;
3934 TRACE_(key)("PostMessageW(%p,%s,%04x,%08x)\n",
3935 msg->hwnd, SPY_GetMsgName(message, msg->hwnd), HIWORD(msg->lParam), LOWORD(msg->lParam));
3936 PostMessageW( msg->hwnd, message, HIWORD(msg->lParam), LOWORD(msg->lParam));
3937 return TRUE;
3939 case VK_PROCESSKEY:
3940 return ImmTranslateMessage(msg->hwnd, msg->message, msg->wParam, msg->lParam);
3943 GetKeyboardState( state );
3944 len = ToUnicode(msg->wParam, HIWORD(msg->lParam), state, wp, ARRAY_SIZE(wp), 0);
3945 if (len == -1)
3947 message = (msg->message == WM_KEYDOWN) ? WM_DEADCHAR : WM_SYSDEADCHAR;
3948 TRACE_(key)("-1 -> PostMessageW(%p,%s,%04x,%08lx)\n",
3949 msg->hwnd, SPY_GetMsgName(message, msg->hwnd), wp[0], msg->lParam);
3950 PostMessageW( msg->hwnd, message, wp[0], msg->lParam );
3952 else if (len > 0)
3954 INT i;
3956 message = (msg->message == WM_KEYDOWN) ? WM_CHAR : WM_SYSCHAR;
3957 TRACE_(key)("%d -> PostMessageW(%p,%s,<x>,%08lx) for <x> in %s\n", len, msg->hwnd,
3958 SPY_GetMsgName(message, msg->hwnd), msg->lParam, debugstr_wn(wp, len));
3959 for (i = 0; i < len; i++)
3960 PostMessageW( msg->hwnd, message, wp[i], msg->lParam );
3962 return TRUE;
3966 /***********************************************************************
3967 * DispatchMessageA (USER32.@)
3969 * See DispatchMessageW.
3971 LRESULT WINAPI DECLSPEC_HOTPATCH DispatchMessageA( const MSG* msg )
3973 LRESULT retval;
3975 /* Process timer messages */
3976 if ((msg->message == WM_TIMER) || (msg->message == WM_SYSTIMER))
3978 if (msg->lParam)
3980 __TRY
3982 retval = CallWindowProcA( (WNDPROC)msg->lParam, msg->hwnd,
3983 msg->message, msg->wParam, GetTickCount() );
3985 __EXCEPT_ALL
3987 retval = 0;
3989 __ENDTRY
3990 return retval;
3993 if (!msg->hwnd) return 0;
3995 SPY_EnterMessage( SPY_DISPATCHMESSAGE, msg->hwnd, msg->message,
3996 msg->wParam, msg->lParam );
3998 if (!WINPROC_call_window( msg->hwnd, msg->message, msg->wParam, msg->lParam,
3999 &retval, FALSE, WMCHAR_MAP_DISPATCHMESSAGE ))
4001 if (!IsWindow( msg->hwnd )) SetLastError( ERROR_INVALID_WINDOW_HANDLE );
4002 else SetLastError( ERROR_MESSAGE_SYNC_ONLY );
4003 retval = 0;
4006 SPY_ExitMessage( SPY_RESULT_OK, msg->hwnd, msg->message, retval,
4007 msg->wParam, msg->lParam );
4009 if (msg->message == WM_PAINT)
4011 /* send a WM_NCPAINT and WM_ERASEBKGND if the non-client area is still invalid */
4012 HRGN hrgn = CreateRectRgn( 0, 0, 0, 0 );
4013 GetUpdateRgn( msg->hwnd, hrgn, TRUE );
4014 DeleteObject( hrgn );
4016 return retval;
4020 /***********************************************************************
4021 * DispatchMessageW (USER32.@) Process a message
4023 * Process the message specified in the structure *_msg_.
4025 * If the lpMsg parameter points to a WM_TIMER message and the
4026 * parameter of the WM_TIMER message is not NULL, the lParam parameter
4027 * points to the function that is called instead of the window
4028 * procedure. The function stored in lParam (timer callback) is protected
4029 * from causing page-faults.
4031 * The message must be valid.
4033 * RETURNS
4035 * DispatchMessage() returns the result of the window procedure invoked.
4037 * CONFORMANCE
4039 * ECMA-234, Win32
4042 LRESULT WINAPI DECLSPEC_HOTPATCH DispatchMessageW( const MSG* msg )
4044 LRESULT retval;
4046 /* Process timer messages */
4047 if ((msg->message == WM_TIMER) || (msg->message == WM_SYSTIMER))
4049 if (msg->lParam)
4051 __TRY
4053 retval = CallWindowProcW( (WNDPROC)msg->lParam, msg->hwnd,
4054 msg->message, msg->wParam, GetTickCount() );
4056 __EXCEPT_ALL
4058 retval = 0;
4060 __ENDTRY
4061 return retval;
4064 if (!msg->hwnd) return 0;
4066 SPY_EnterMessage( SPY_DISPATCHMESSAGE, msg->hwnd, msg->message,
4067 msg->wParam, msg->lParam );
4069 if (!WINPROC_call_window( msg->hwnd, msg->message, msg->wParam, msg->lParam,
4070 &retval, TRUE, WMCHAR_MAP_DISPATCHMESSAGE ))
4072 if (!IsWindow( msg->hwnd )) SetLastError( ERROR_INVALID_WINDOW_HANDLE );
4073 else SetLastError( ERROR_MESSAGE_SYNC_ONLY );
4074 retval = 0;
4077 SPY_ExitMessage( SPY_RESULT_OK, msg->hwnd, msg->message, retval,
4078 msg->wParam, msg->lParam );
4080 if (msg->message == WM_PAINT)
4082 /* send a WM_NCPAINT and WM_ERASEBKGND if the non-client area is still invalid */
4083 HRGN hrgn = CreateRectRgn( 0, 0, 0, 0 );
4084 GetUpdateRgn( msg->hwnd, hrgn, TRUE );
4085 DeleteObject( hrgn );
4087 return retval;
4091 /***********************************************************************
4092 * GetMessagePos (USER.119)
4093 * GetMessagePos (USER32.@)
4095 * The GetMessagePos() function returns a long value representing a
4096 * cursor position, in screen coordinates, when the last message
4097 * retrieved by the GetMessage() function occurs. The x-coordinate is
4098 * in the low-order word of the return value, the y-coordinate is in
4099 * the high-order word. The application can use the MAKEPOINT()
4100 * macro to obtain a POINT structure from the return value.
4102 * For the current cursor position, use GetCursorPos().
4104 * RETURNS
4106 * Cursor position of last message on success, zero on failure.
4108 * CONFORMANCE
4110 * ECMA-234, Win32
4113 DWORD WINAPI GetMessagePos(void)
4115 return get_user_thread_info()->GetMessagePosVal;
4119 /***********************************************************************
4120 * GetMessageTime (USER.120)
4121 * GetMessageTime (USER32.@)
4123 * GetMessageTime() returns the message time for the last message
4124 * retrieved by the function. The time is measured in milliseconds with
4125 * the same offset as GetTickCount().
4127 * Since the tick count wraps, this is only useful for moderately short
4128 * relative time comparisons.
4130 * RETURNS
4132 * Time of last message on success, zero on failure.
4134 LONG WINAPI GetMessageTime(void)
4136 return get_user_thread_info()->GetMessageTimeVal;
4140 /***********************************************************************
4141 * GetMessageExtraInfo (USER.288)
4142 * GetMessageExtraInfo (USER32.@)
4144 LPARAM WINAPI GetMessageExtraInfo(void)
4146 return get_user_thread_info()->GetMessageExtraInfoVal;
4150 /***********************************************************************
4151 * SetMessageExtraInfo (USER32.@)
4153 LPARAM WINAPI SetMessageExtraInfo(LPARAM lParam)
4155 struct user_thread_info *thread_info = get_user_thread_info();
4156 LONG old_value = thread_info->GetMessageExtraInfoVal;
4157 thread_info->GetMessageExtraInfoVal = lParam;
4158 return old_value;
4162 /***********************************************************************
4163 * GetCurrentInputMessageSource (USER32.@)
4165 BOOL WINAPI GetCurrentInputMessageSource( INPUT_MESSAGE_SOURCE *source )
4167 *source = get_user_thread_info()->msg_source;
4168 return TRUE;
4172 /***********************************************************************
4173 * WaitMessage (USER.112) Suspend thread pending messages
4174 * WaitMessage (USER32.@) Suspend thread pending messages
4176 * WaitMessage() suspends a thread until events appear in the thread's
4177 * queue.
4179 BOOL WINAPI WaitMessage(void)
4181 return (MsgWaitForMultipleObjectsEx( 0, NULL, INFINITE, QS_ALLINPUT, 0 ) != WAIT_FAILED);
4185 /***********************************************************************
4186 * MsgWaitForMultipleObjectsEx (USER32.@)
4188 DWORD WINAPI MsgWaitForMultipleObjectsEx( DWORD count, const HANDLE *pHandles,
4189 DWORD timeout, DWORD mask, DWORD flags )
4191 HANDLE handles[MAXIMUM_WAIT_OBJECTS];
4192 DWORD i;
4194 if (count > MAXIMUM_WAIT_OBJECTS-1)
4196 SetLastError( ERROR_INVALID_PARAMETER );
4197 return WAIT_FAILED;
4200 /* add the queue to the handle list */
4201 for (i = 0; i < count; i++) handles[i] = pHandles[i];
4202 handles[count] = get_server_queue_handle();
4204 return wait_objects( count+1, handles, timeout,
4205 (flags & MWMO_INPUTAVAILABLE) ? mask : 0, mask, flags );
4209 /***********************************************************************
4210 * MsgWaitForMultipleObjects (USER32.@)
4212 DWORD WINAPI MsgWaitForMultipleObjects( DWORD count, const HANDLE *handles,
4213 BOOL wait_all, DWORD timeout, DWORD mask )
4215 return MsgWaitForMultipleObjectsEx( count, handles, timeout, mask,
4216 wait_all ? MWMO_WAITALL : 0 );
4220 /***********************************************************************
4221 * WaitForInputIdle (USER32.@)
4223 DWORD WINAPI WaitForInputIdle( HANDLE hProcess, DWORD dwTimeOut )
4225 DWORD start_time, elapsed, ret;
4226 HANDLE handles[2];
4228 handles[0] = hProcess;
4229 SERVER_START_REQ( get_process_idle_event )
4231 req->handle = wine_server_obj_handle( hProcess );
4232 wine_server_call_err( req );
4233 handles[1] = wine_server_ptr_handle( reply->event );
4235 SERVER_END_REQ;
4236 if (!handles[1]) return WAIT_FAILED; /* no event to wait on */
4238 start_time = GetTickCount();
4239 elapsed = 0;
4241 TRACE("waiting for %p\n", handles[1] );
4244 ret = MsgWaitForMultipleObjects ( 2, handles, FALSE, dwTimeOut - elapsed, QS_SENDMESSAGE );
4245 switch (ret)
4247 case WAIT_OBJECT_0:
4248 return 0;
4249 case WAIT_OBJECT_0+2:
4250 process_sent_messages();
4251 break;
4252 case WAIT_TIMEOUT:
4253 case WAIT_FAILED:
4254 TRACE("timeout or error\n");
4255 return ret;
4256 default:
4257 TRACE("finished\n");
4258 return 0;
4260 if (dwTimeOut != INFINITE)
4262 elapsed = GetTickCount() - start_time;
4263 if (elapsed > dwTimeOut)
4264 break;
4267 while (1);
4269 return WAIT_TIMEOUT;
4273 /***********************************************************************
4274 * RegisterWindowMessageA (USER32.@)
4275 * RegisterWindowMessage (USER.118)
4277 UINT WINAPI RegisterWindowMessageA( LPCSTR str )
4279 UINT ret = GlobalAddAtomA(str);
4280 TRACE("%s, ret=%x\n", str, ret);
4281 return ret;
4285 /***********************************************************************
4286 * RegisterWindowMessageW (USER32.@)
4288 UINT WINAPI RegisterWindowMessageW( LPCWSTR str )
4290 UINT ret = GlobalAddAtomW(str);
4291 TRACE("%s ret=%x\n", debugstr_w(str), ret);
4292 return ret;
4295 typedef struct BroadcastParm
4297 DWORD flags;
4298 LPDWORD recipients;
4299 UINT msg;
4300 WPARAM wp;
4301 LPARAM lp;
4302 BOOL success;
4303 HWINSTA winsta;
4304 } BroadcastParm;
4306 static BOOL CALLBACK bcast_childwindow( HWND hw, LPARAM lp )
4308 BroadcastParm *parm = (BroadcastParm*)lp;
4309 DWORD_PTR retval = 0;
4310 LRESULT lresult;
4312 if (parm->flags & BSF_IGNORECURRENTTASK && WIN_IsCurrentProcess(hw))
4314 TRACE("Not telling myself %p\n", hw);
4315 return TRUE;
4318 /* I don't know 100% for sure if this is what Windows does, but it fits the tests */
4319 if (parm->flags & BSF_QUERY)
4321 TRACE("Telling window %p using SendMessageTimeout\n", hw);
4323 /* Not tested for conflicting flags */
4324 if (parm->flags & BSF_FORCEIFHUNG || parm->flags & BSF_NOHANG)
4325 lresult = SendMessageTimeoutW( hw, parm->msg, parm->wp, parm->lp, SMTO_ABORTIFHUNG, 2000, &retval );
4326 else if (parm->flags & BSF_NOTIMEOUTIFNOTHUNG)
4327 lresult = SendMessageTimeoutW( hw, parm->msg, parm->wp, parm->lp, SMTO_NOTIMEOUTIFNOTHUNG, 2000, &retval );
4328 else
4329 lresult = SendMessageTimeoutW( hw, parm->msg, parm->wp, parm->lp, SMTO_NORMAL, 2000, &retval );
4331 if (!lresult && GetLastError() == ERROR_TIMEOUT)
4333 WARN("Timed out!\n");
4334 if (!(parm->flags & BSF_FORCEIFHUNG))
4335 goto fail;
4337 if (retval == BROADCAST_QUERY_DENY)
4338 goto fail;
4340 return TRUE;
4342 fail:
4343 parm->success = FALSE;
4344 return FALSE;
4346 else if (parm->flags & BSF_POSTMESSAGE)
4348 TRACE("Telling window %p using PostMessage\n", hw);
4349 PostMessageW( hw, parm->msg, parm->wp, parm->lp );
4351 else
4353 TRACE("Telling window %p using SendNotifyMessage\n", hw);
4354 SendNotifyMessageW( hw, parm->msg, parm->wp, parm->lp );
4357 return TRUE;
4360 static BOOL CALLBACK bcast_desktop( LPWSTR desktop, LPARAM lp )
4362 BOOL ret;
4363 HDESK hdesktop;
4364 BroadcastParm *parm = (BroadcastParm*)lp;
4366 TRACE("desktop: %s\n", debugstr_w( desktop ));
4368 hdesktop = open_winstation_desktop( parm->winsta, desktop, 0, FALSE, DESKTOP_ENUMERATE|DESKTOP_WRITEOBJECTS|STANDARD_RIGHTS_WRITE );
4369 if (!hdesktop)
4371 FIXME("Could not open desktop %s\n", debugstr_w(desktop));
4372 return TRUE;
4375 ret = EnumDesktopWindows( hdesktop, bcast_childwindow, lp );
4376 CloseDesktop(hdesktop);
4377 TRACE("-->%d\n", ret);
4378 return parm->success;
4381 static BOOL CALLBACK bcast_winsta( LPWSTR winsta, LPARAM lp )
4383 BOOL ret;
4384 HWINSTA hwinsta = OpenWindowStationW( winsta, FALSE, WINSTA_ENUMDESKTOPS );
4385 TRACE("hwinsta: %p/%s/%08x\n", hwinsta, debugstr_w( winsta ), GetLastError());
4386 if (!hwinsta)
4387 return TRUE;
4388 ((BroadcastParm *)lp)->winsta = hwinsta;
4389 ret = EnumDesktopsW( hwinsta, bcast_desktop, lp );
4390 CloseWindowStation( hwinsta );
4391 TRACE("-->%d\n", ret);
4392 return ret;
4395 /***********************************************************************
4396 * BroadcastSystemMessageA (USER32.@)
4397 * BroadcastSystemMessage (USER32.@)
4399 LONG WINAPI BroadcastSystemMessageA( DWORD flags, LPDWORD recipients, UINT msg, WPARAM wp, LPARAM lp )
4401 return BroadcastSystemMessageExA( flags, recipients, msg, wp, lp, NULL );
4405 /***********************************************************************
4406 * BroadcastSystemMessageW (USER32.@)
4408 LONG WINAPI BroadcastSystemMessageW( DWORD flags, LPDWORD recipients, UINT msg, WPARAM wp, LPARAM lp )
4410 return BroadcastSystemMessageExW( flags, recipients, msg, wp, lp, NULL );
4413 /***********************************************************************
4414 * BroadcastSystemMessageExA (USER32.@)
4416 LONG WINAPI BroadcastSystemMessageExA( DWORD flags, LPDWORD recipients, UINT msg, WPARAM wp, LPARAM lp, PBSMINFO pinfo )
4418 map_wparam_AtoW( msg, &wp, WMCHAR_MAP_NOMAPPING );
4419 return BroadcastSystemMessageExW( flags, recipients, msg, wp, lp, NULL );
4423 /***********************************************************************
4424 * BroadcastSystemMessageExW (USER32.@)
4426 LONG WINAPI BroadcastSystemMessageExW( DWORD flags, LPDWORD recipients, UINT msg, WPARAM wp, LPARAM lp, PBSMINFO pinfo )
4428 BroadcastParm parm;
4429 DWORD recips = BSM_ALLCOMPONENTS;
4430 BOOL ret = TRUE;
4431 static const DWORD all_flags = ( BSF_QUERY | BSF_IGNORECURRENTTASK | BSF_FLUSHDISK | BSF_NOHANG
4432 | BSF_POSTMESSAGE | BSF_FORCEIFHUNG | BSF_NOTIMEOUTIFNOTHUNG
4433 | BSF_ALLOWSFW | BSF_SENDNOTIFYMESSAGE | BSF_RETURNHDESK | BSF_LUID );
4435 TRACE("Flags: %08x, recipients: %p(0x%x), msg: %04x, wparam: %08lx, lparam: %08lx\n", flags, recipients,
4436 (recipients ? *recipients : recips), msg, wp, lp);
4438 if (flags & ~all_flags)
4440 SetLastError(ERROR_INVALID_PARAMETER);
4441 return 0;
4444 if (!recipients)
4445 recipients = &recips;
4447 if ( pinfo && flags & BSF_QUERY )
4448 FIXME("Not returning PBSMINFO information yet\n");
4450 parm.flags = flags;
4451 parm.recipients = recipients;
4452 parm.msg = msg;
4453 parm.wp = wp;
4454 parm.lp = lp;
4455 parm.success = TRUE;
4457 if (*recipients & BSM_ALLDESKTOPS || *recipients == BSM_ALLCOMPONENTS)
4458 ret = EnumWindowStationsW(bcast_winsta, (LONG_PTR)&parm);
4459 else if (*recipients & BSM_APPLICATIONS)
4461 EnumWindows(bcast_childwindow, (LONG_PTR)&parm);
4462 ret = parm.success;
4464 else
4465 FIXME("Recipients %08x not supported!\n", *recipients);
4467 return ret;
4470 /***********************************************************************
4471 * SetMessageQueue (USER32.@)
4473 BOOL WINAPI SetMessageQueue( INT size )
4475 /* now obsolete the message queue will be expanded dynamically as necessary */
4476 return TRUE;
4480 /***********************************************************************
4481 * MessageBeep (USER32.@)
4483 BOOL WINAPI MessageBeep( UINT i )
4485 BOOL active = TRUE;
4486 SystemParametersInfoA( SPI_GETBEEP, 0, &active, FALSE );
4487 if (active) USER_Driver->pBeep();
4488 return TRUE;
4492 /***********************************************************************
4493 * SetCoalescableTimer (USER32.@)
4495 UINT_PTR WINAPI SetCoalescableTimer( HWND hwnd, UINT_PTR id, UINT timeout, TIMERPROC proc, ULONG tolerance )
4497 UINT_PTR ret;
4498 WNDPROC winproc = 0;
4500 if (proc) winproc = WINPROC_AllocProc( (WNDPROC)proc, FALSE );
4502 timeout = min( max( USER_TIMER_MINIMUM, timeout ), USER_TIMER_MAXIMUM );
4504 SERVER_START_REQ( set_win_timer )
4506 req->win = wine_server_user_handle( hwnd );
4507 req->msg = WM_TIMER;
4508 req->id = id;
4509 req->rate = timeout;
4510 req->lparam = (ULONG_PTR)winproc;
4511 if (!wine_server_call_err( req ))
4513 ret = reply->id;
4514 if (!ret) ret = TRUE;
4516 else ret = 0;
4518 SERVER_END_REQ;
4520 TRACE("Added %p %lx %p timeout %d\n", hwnd, id, winproc, timeout );
4521 return ret;
4525 /******************************************************************
4526 * SetTimer (USER32.@)
4528 UINT_PTR WINAPI SetTimer( HWND hwnd, UINT_PTR id, UINT timeout, TIMERPROC proc )
4530 return SetCoalescableTimer( hwnd, id, timeout, proc, TIMERV_DEFAULT_COALESCING );
4534 /***********************************************************************
4535 * SetSystemTimer (USER32.@)
4537 UINT_PTR WINAPI SetSystemTimer( HWND hwnd, UINT_PTR id, UINT timeout, TIMERPROC proc )
4539 UINT_PTR ret;
4540 WNDPROC winproc = 0;
4542 if (proc) winproc = WINPROC_AllocProc( (WNDPROC)proc, FALSE );
4544 timeout = min( max( USER_TIMER_MINIMUM, timeout ), USER_TIMER_MAXIMUM );
4546 SERVER_START_REQ( set_win_timer )
4548 req->win = wine_server_user_handle( hwnd );
4549 req->msg = WM_SYSTIMER;
4550 req->id = id;
4551 req->rate = timeout;
4552 req->lparam = (ULONG_PTR)winproc;
4553 if (!wine_server_call_err( req ))
4555 ret = reply->id;
4556 if (!ret) ret = TRUE;
4558 else ret = 0;
4560 SERVER_END_REQ;
4562 TRACE("Added %p %lx %p timeout %d\n", hwnd, id, winproc, timeout );
4563 return ret;
4567 /***********************************************************************
4568 * KillTimer (USER32.@)
4570 BOOL WINAPI KillTimer( HWND hwnd, UINT_PTR id )
4572 BOOL ret;
4574 SERVER_START_REQ( kill_win_timer )
4576 req->win = wine_server_user_handle( hwnd );
4577 req->msg = WM_TIMER;
4578 req->id = id;
4579 ret = !wine_server_call_err( req );
4581 SERVER_END_REQ;
4582 return ret;
4586 /***********************************************************************
4587 * KillSystemTimer (USER32.@)
4589 BOOL WINAPI KillSystemTimer( HWND hwnd, UINT_PTR id )
4591 BOOL ret;
4593 SERVER_START_REQ( kill_win_timer )
4595 req->win = wine_server_user_handle( hwnd );
4596 req->msg = WM_SYSTIMER;
4597 req->id = id;
4598 ret = !wine_server_call_err( req );
4600 SERVER_END_REQ;
4601 return ret;
4605 /**********************************************************************
4606 * IsGUIThread (USER32.@)
4608 BOOL WINAPI IsGUIThread( BOOL convert )
4610 FIXME( "%u: stub\n", convert );
4611 return TRUE;
4615 /**********************************************************************
4616 * GetGUIThreadInfo (USER32.@)
4618 BOOL WINAPI GetGUIThreadInfo( DWORD id, GUITHREADINFO *info )
4620 BOOL ret;
4622 if (info->cbSize != sizeof(*info))
4624 SetLastError( ERROR_INVALID_PARAMETER );
4625 return FALSE;
4628 SERVER_START_REQ( get_thread_input )
4630 req->tid = id;
4631 if ((ret = !wine_server_call_err( req )))
4633 info->flags = 0;
4634 info->hwndActive = wine_server_ptr_handle( reply->active );
4635 info->hwndFocus = wine_server_ptr_handle( reply->focus );
4636 info->hwndCapture = wine_server_ptr_handle( reply->capture );
4637 info->hwndMenuOwner = wine_server_ptr_handle( reply->menu_owner );
4638 info->hwndMoveSize = wine_server_ptr_handle( reply->move_size );
4639 info->hwndCaret = wine_server_ptr_handle( reply->caret );
4640 info->rcCaret.left = reply->rect.left;
4641 info->rcCaret.top = reply->rect.top;
4642 info->rcCaret.right = reply->rect.right;
4643 info->rcCaret.bottom = reply->rect.bottom;
4644 if (reply->menu_owner) info->flags |= GUI_INMENUMODE;
4645 if (reply->move_size) info->flags |= GUI_INMOVESIZE;
4646 if (reply->caret) info->flags |= GUI_CARETBLINKING;
4649 SERVER_END_REQ;
4650 return ret;
4654 /******************************************************************
4655 * IsHungAppWindow (USER32.@)
4658 BOOL WINAPI IsHungAppWindow( HWND hWnd )
4660 BOOL ret;
4662 SERVER_START_REQ( is_window_hung )
4664 req->win = wine_server_user_handle( hWnd );
4665 ret = !wine_server_call_err( req ) && reply->is_hung;
4667 SERVER_END_REQ;
4668 return ret;
4671 /******************************************************************
4672 * ChangeWindowMessageFilter (USER32.@)
4674 BOOL WINAPI ChangeWindowMessageFilter( UINT message, DWORD flag )
4676 FIXME( "%x %08x\n", message, flag );
4677 return TRUE;
4680 /******************************************************************
4681 * ChangeWindowMessageFilterEx (USER32.@)
4683 BOOL WINAPI ChangeWindowMessageFilterEx( HWND hwnd, UINT message, DWORD action, CHANGEFILTERSTRUCT *changefilter )
4685 FIXME( "%p %x %d %p\n", hwnd, message, action, changefilter );
4686 return TRUE;