include: Make sure __int64 is correctly defined on PPC64.
[wine.git] / dlls / user32 / message.c
blobf7ce262f90dbbea88afd96352e2db4348ae5425d
1 /*
2 * Window messaging support
4 * Copyright 2001 Alexandre Julliard
5 * Copyright 2008 Maarten Lankhorst
7 * This library is free software; you can redistribute it and/or
8 * modify it under the terms of the GNU Lesser General Public
9 * License as published by the Free Software Foundation; either
10 * version 2.1 of the License, or (at your option) any later version.
12 * This library is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
15 * Lesser General Public License for more details.
17 * You should have received a copy of the GNU Lesser General Public
18 * License along with this library; if not, write to the Free Software
19 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
22 #include <assert.h>
23 #include <stdarg.h>
25 #define NONAMELESSUNION
26 #define NONAMELESSSTRUCT
27 #include "ntstatus.h"
28 #define WIN32_NO_STATUS
29 #include "windef.h"
30 #include "winbase.h"
31 #include "wingdi.h"
32 #include "winuser.h"
33 #include "winerror.h"
34 #include "winnls.h"
35 #include "dbt.h"
36 #include "dde.h"
37 #include "imm.h"
38 #include "ddk/imm.h"
39 #include "wine/server.h"
40 #include "user_private.h"
41 #include "win.h"
42 #include "controls.h"
43 #include "wine/debug.h"
44 #include "wine/exception.h"
46 WINE_DEFAULT_DEBUG_CHANNEL(msg);
47 WINE_DECLARE_DEBUG_CHANNEL(relay);
48 WINE_DECLARE_DEBUG_CHANNEL(key);
50 #define WM_NCMOUSEFIRST WM_NCMOUSEMOVE
51 #define WM_NCMOUSELAST (WM_NCMOUSEFIRST+(WM_MOUSELAST-WM_MOUSEFIRST))
53 #define MAX_PACK_COUNT 4
55 /* the various structures that can be sent in messages, in platform-independent layout */
56 struct packed_CREATESTRUCTW
58 ULONGLONG lpCreateParams;
59 ULONGLONG hInstance;
60 user_handle_t hMenu;
61 DWORD __pad1;
62 user_handle_t hwndParent;
63 DWORD __pad2;
64 INT cy;
65 INT cx;
66 INT y;
67 INT x;
68 LONG style;
69 ULONGLONG lpszName;
70 ULONGLONG lpszClass;
71 DWORD dwExStyle;
72 DWORD __pad3;
75 struct packed_DRAWITEMSTRUCT
77 UINT CtlType;
78 UINT CtlID;
79 UINT itemID;
80 UINT itemAction;
81 UINT itemState;
82 user_handle_t hwndItem;
83 DWORD __pad1;
84 user_handle_t hDC;
85 DWORD __pad2;
86 RECT rcItem;
87 ULONGLONG itemData;
90 struct packed_MEASUREITEMSTRUCT
92 UINT CtlType;
93 UINT CtlID;
94 UINT itemID;
95 UINT itemWidth;
96 UINT itemHeight;
97 ULONGLONG itemData;
100 struct packed_DELETEITEMSTRUCT
102 UINT CtlType;
103 UINT CtlID;
104 UINT itemID;
105 user_handle_t hwndItem;
106 DWORD __pad;
107 ULONGLONG itemData;
110 struct packed_COMPAREITEMSTRUCT
112 UINT CtlType;
113 UINT CtlID;
114 user_handle_t hwndItem;
115 DWORD __pad1;
116 UINT itemID1;
117 ULONGLONG itemData1;
118 UINT itemID2;
119 ULONGLONG itemData2;
120 DWORD dwLocaleId;
121 DWORD __pad2;
124 struct packed_WINDOWPOS
126 user_handle_t hwnd;
127 DWORD __pad1;
128 user_handle_t hwndInsertAfter;
129 DWORD __pad2;
130 INT x;
131 INT y;
132 INT cx;
133 INT cy;
134 UINT flags;
135 DWORD __pad3;
138 struct packed_COPYDATASTRUCT
140 ULONGLONG dwData;
141 DWORD cbData;
142 ULONGLONG lpData;
145 struct packed_HELPINFO
147 UINT cbSize;
148 INT iContextType;
149 INT iCtrlId;
150 user_handle_t hItemHandle;
151 DWORD __pad;
152 ULONGLONG dwContextId;
153 POINT MousePos;
156 struct packed_NCCALCSIZE_PARAMS
158 RECT rgrc[3];
159 ULONGLONG __pad1;
160 user_handle_t hwnd;
161 DWORD __pad2;
162 user_handle_t hwndInsertAfter;
163 DWORD __pad3;
164 INT x;
165 INT y;
166 INT cx;
167 INT cy;
168 UINT flags;
169 DWORD __pad4;
172 struct packed_MSG
174 user_handle_t hwnd;
175 DWORD __pad1;
176 UINT message;
177 ULONGLONG wParam;
178 ULONGLONG lParam;
179 DWORD time;
180 POINT pt;
181 DWORD __pad2;
184 struct packed_MDINEXTMENU
186 user_handle_t hmenuIn;
187 DWORD __pad1;
188 user_handle_t hmenuNext;
189 DWORD __pad2;
190 user_handle_t hwndNext;
191 DWORD __pad3;
194 struct packed_MDICREATESTRUCTW
196 ULONGLONG szClass;
197 ULONGLONG szTitle;
198 ULONGLONG hOwner;
199 INT x;
200 INT y;
201 INT cx;
202 INT cy;
203 DWORD style;
204 ULONGLONG lParam;
207 struct packed_hook_extra_info
209 user_handle_t handle;
210 DWORD __pad;
211 ULONGLONG lparam;
214 /* the structures are unpacked on top of the packed ones, so make sure they fit */
215 C_ASSERT( sizeof(struct packed_CREATESTRUCTW) >= sizeof(CREATESTRUCTW) );
216 C_ASSERT( sizeof(struct packed_DRAWITEMSTRUCT) >= sizeof(DRAWITEMSTRUCT) );
217 C_ASSERT( sizeof(struct packed_MEASUREITEMSTRUCT) >= sizeof(MEASUREITEMSTRUCT) );
218 C_ASSERT( sizeof(struct packed_DELETEITEMSTRUCT) >= sizeof(DELETEITEMSTRUCT) );
219 C_ASSERT( sizeof(struct packed_COMPAREITEMSTRUCT) >= sizeof(COMPAREITEMSTRUCT) );
220 C_ASSERT( sizeof(struct packed_WINDOWPOS) >= sizeof(WINDOWPOS) );
221 C_ASSERT( sizeof(struct packed_COPYDATASTRUCT) >= sizeof(COPYDATASTRUCT) );
222 C_ASSERT( sizeof(struct packed_HELPINFO) >= sizeof(HELPINFO) );
223 C_ASSERT( sizeof(struct packed_NCCALCSIZE_PARAMS) >= sizeof(NCCALCSIZE_PARAMS) + sizeof(WINDOWPOS) );
224 C_ASSERT( sizeof(struct packed_MSG) >= sizeof(MSG) );
225 C_ASSERT( sizeof(struct packed_MDINEXTMENU) >= sizeof(MDINEXTMENU) );
226 C_ASSERT( sizeof(struct packed_MDICREATESTRUCTW) >= sizeof(MDICREATESTRUCTW) );
227 C_ASSERT( sizeof(struct packed_hook_extra_info) >= sizeof(struct hook_extra_info) );
229 union packed_structs
231 struct packed_CREATESTRUCTW cs;
232 struct packed_DRAWITEMSTRUCT dis;
233 struct packed_MEASUREITEMSTRUCT mis;
234 struct packed_DELETEITEMSTRUCT dls;
235 struct packed_COMPAREITEMSTRUCT cis;
236 struct packed_WINDOWPOS wp;
237 struct packed_COPYDATASTRUCT cds;
238 struct packed_HELPINFO hi;
239 struct packed_NCCALCSIZE_PARAMS ncp;
240 struct packed_MSG msg;
241 struct packed_MDINEXTMENU mnm;
242 struct packed_MDICREATESTRUCTW mcs;
243 struct packed_hook_extra_info hook;
246 /* description of the data fields that need to be packed along with a sent message */
247 struct packed_message
249 union packed_structs ps;
250 int count;
251 const void *data[MAX_PACK_COUNT];
252 size_t size[MAX_PACK_COUNT];
255 /* info about the message currently being received by the current thread */
256 struct received_message_info
258 enum message_type type;
259 MSG msg;
260 UINT flags; /* InSendMessageEx return flags */
263 /* structure to group all parameters for sent messages of the various kinds */
264 struct send_message_info
266 enum message_type type;
267 DWORD dest_tid;
268 HWND hwnd;
269 UINT msg;
270 WPARAM wparam;
271 LPARAM lparam;
272 UINT flags; /* flags for SendMessageTimeout */
273 UINT timeout; /* timeout for SendMessageTimeout */
274 SENDASYNCPROC callback; /* callback function for SendMessageCallback */
275 ULONG_PTR data; /* callback data */
276 enum wm_char_mapping wm_char;
279 static const INPUT_MESSAGE_SOURCE msg_source_unavailable = { IMDT_UNAVAILABLE, IMO_UNAVAILABLE };
282 /* Message class descriptor */
283 const struct builtin_class_descr MESSAGE_builtin_class =
285 L"Message", /* name */
286 0, /* style */
287 WINPROC_MESSAGE, /* proc */
288 0, /* extra */
289 0, /* cursor */
290 0 /* brush */
295 /* flag for messages that contain pointers */
296 /* 32 messages per entry, messages 0..31 map to bits 0..31 */
298 #define SET(msg) (1 << ((msg) & 31))
300 static const unsigned int message_pointer_flags[] =
302 /* 0x00 - 0x1f */
303 SET(WM_CREATE) | SET(WM_SETTEXT) | SET(WM_GETTEXT) |
304 SET(WM_WININICHANGE) | SET(WM_DEVMODECHANGE),
305 /* 0x20 - 0x3f */
306 SET(WM_GETMINMAXINFO) | SET(WM_DRAWITEM) | SET(WM_MEASUREITEM) | SET(WM_DELETEITEM) |
307 SET(WM_COMPAREITEM),
308 /* 0x40 - 0x5f */
309 SET(WM_WINDOWPOSCHANGING) | SET(WM_WINDOWPOSCHANGED) | SET(WM_COPYDATA) | SET(WM_HELP),
310 /* 0x60 - 0x7f */
311 SET(WM_STYLECHANGING) | SET(WM_STYLECHANGED),
312 /* 0x80 - 0x9f */
313 SET(WM_NCCREATE) | SET(WM_NCCALCSIZE) | SET(WM_GETDLGCODE),
314 /* 0xa0 - 0xbf */
315 SET(EM_GETSEL) | SET(EM_GETRECT) | SET(EM_SETRECT) | SET(EM_SETRECTNP),
316 /* 0xc0 - 0xdf */
317 SET(EM_REPLACESEL) | SET(EM_GETLINE) | SET(EM_SETTABSTOPS),
318 /* 0xe0 - 0xff */
319 SET(SBM_GETRANGE) | SET(SBM_SETSCROLLINFO) | SET(SBM_GETSCROLLINFO) | SET(SBM_GETSCROLLBARINFO),
320 /* 0x100 - 0x11f */
322 /* 0x120 - 0x13f */
324 /* 0x140 - 0x15f */
325 SET(CB_GETEDITSEL) | SET(CB_ADDSTRING) | SET(CB_DIR) | SET(CB_GETLBTEXT) |
326 SET(CB_INSERTSTRING) | SET(CB_FINDSTRING) | SET(CB_SELECTSTRING) |
327 SET(CB_GETDROPPEDCONTROLRECT) | SET(CB_FINDSTRINGEXACT),
328 /* 0x160 - 0x17f */
330 /* 0x180 - 0x19f */
331 SET(LB_ADDSTRING) | SET(LB_INSERTSTRING) | SET(LB_GETTEXT) | SET(LB_SELECTSTRING) |
332 SET(LB_DIR) | SET(LB_FINDSTRING) |
333 SET(LB_GETSELITEMS) | SET(LB_SETTABSTOPS) | SET(LB_ADDFILE) | SET(LB_GETITEMRECT),
334 /* 0x1a0 - 0x1bf */
335 SET(LB_FINDSTRINGEXACT),
336 /* 0x1c0 - 0x1df */
338 /* 0x1e0 - 0x1ff */
340 /* 0x200 - 0x21f */
341 SET(WM_NEXTMENU) | SET(WM_SIZING) | SET(WM_MOVING) | SET(WM_DEVICECHANGE),
342 /* 0x220 - 0x23f */
343 SET(WM_MDICREATE) | SET(WM_MDIGETACTIVE) | SET(WM_DROPOBJECT) |
344 SET(WM_QUERYDROPOBJECT) | SET(WM_DRAGLOOP) | SET(WM_DRAGSELECT) | SET(WM_DRAGMOVE),
345 /* 0x240 - 0x25f */
347 /* 0x260 - 0x27f */
349 /* 0x280 - 0x29f */
351 /* 0x2a0 - 0x2bf */
353 /* 0x2c0 - 0x2df */
355 /* 0x2e0 - 0x2ff */
357 /* 0x300 - 0x31f */
358 SET(WM_ASKCBFORMATNAME)
361 /* flags for messages that contain Unicode strings */
362 static const unsigned int message_unicode_flags[] =
364 /* 0x00 - 0x1f */
365 SET(WM_CREATE) | SET(WM_SETTEXT) | SET(WM_GETTEXT) | SET(WM_GETTEXTLENGTH) |
366 SET(WM_WININICHANGE) | SET(WM_DEVMODECHANGE),
367 /* 0x20 - 0x3f */
368 SET(WM_CHARTOITEM),
369 /* 0x40 - 0x5f */
371 /* 0x60 - 0x7f */
373 /* 0x80 - 0x9f */
374 SET(WM_NCCREATE),
375 /* 0xa0 - 0xbf */
377 /* 0xc0 - 0xdf */
378 SET(EM_REPLACESEL) | SET(EM_GETLINE) | SET(EM_SETPASSWORDCHAR),
379 /* 0xe0 - 0xff */
381 /* 0x100 - 0x11f */
382 SET(WM_CHAR) | SET(WM_DEADCHAR) | SET(WM_SYSCHAR) | SET(WM_SYSDEADCHAR),
383 /* 0x120 - 0x13f */
384 SET(WM_MENUCHAR),
385 /* 0x140 - 0x15f */
386 SET(CB_ADDSTRING) | SET(CB_DIR) | SET(CB_GETLBTEXT) | SET(CB_GETLBTEXTLEN) |
387 SET(CB_INSERTSTRING) | SET(CB_FINDSTRING) | SET(CB_SELECTSTRING) | SET(CB_FINDSTRINGEXACT),
388 /* 0x160 - 0x17f */
390 /* 0x180 - 0x19f */
391 SET(LB_ADDSTRING) | SET(LB_INSERTSTRING) | SET(LB_GETTEXT) | SET(LB_GETTEXTLEN) |
392 SET(LB_SELECTSTRING) | SET(LB_DIR) | SET(LB_FINDSTRING) | SET(LB_ADDFILE),
393 /* 0x1a0 - 0x1bf */
394 SET(LB_FINDSTRINGEXACT),
395 /* 0x1c0 - 0x1df */
397 /* 0x1e0 - 0x1ff */
399 /* 0x200 - 0x21f */
401 /* 0x220 - 0x23f */
402 SET(WM_MDICREATE),
403 /* 0x240 - 0x25f */
405 /* 0x260 - 0x27f */
407 /* 0x280 - 0x29f */
408 SET(WM_IME_CHAR),
409 /* 0x2a0 - 0x2bf */
411 /* 0x2c0 - 0x2df */
413 /* 0x2e0 - 0x2ff */
415 /* 0x300 - 0x31f */
416 SET(WM_PAINTCLIPBOARD) | SET(WM_SIZECLIPBOARD) | SET(WM_ASKCBFORMATNAME)
419 /* check whether a given message type includes pointers */
420 static inline BOOL is_pointer_message( UINT message, WPARAM wparam )
422 if (message >= 8*sizeof(message_pointer_flags)) return FALSE;
423 if (message == WM_DEVICECHANGE && !(wparam & 0x8000)) return FALSE;
424 return (message_pointer_flags[message / 32] & SET(message)) != 0;
427 /* check whether a given message type contains Unicode (or ASCII) chars */
428 static inline BOOL is_unicode_message( UINT message )
430 if (message >= 8*sizeof(message_unicode_flags)) return FALSE;
431 return (message_unicode_flags[message / 32] & SET(message)) != 0;
434 #undef SET
436 /* add a data field to a packed message */
437 static inline void push_data( struct packed_message *data, const void *ptr, size_t size )
439 data->data[data->count] = ptr;
440 data->size[data->count] = size;
441 data->count++;
444 /* add a string to a packed message */
445 static inline void push_string( struct packed_message *data, LPCWSTR str )
447 push_data( data, str, (lstrlenW(str) + 1) * sizeof(WCHAR) );
450 /* make sure that the buffer contains a valid null-terminated Unicode string */
451 static inline BOOL check_string( LPCWSTR str, size_t size )
453 for (size /= sizeof(WCHAR); size; size--, str++)
454 if (!*str) return TRUE;
455 return FALSE;
458 /* pack a pointer into a 32/64 portable format */
459 static inline ULONGLONG pack_ptr( const void *ptr )
461 return (ULONG_PTR)ptr;
464 /* unpack a potentially 64-bit pointer, returning 0 when truncated */
465 static inline void *unpack_ptr( ULONGLONG ptr64 )
467 if ((ULONG_PTR)ptr64 != ptr64) return 0;
468 return (void *)(ULONG_PTR)ptr64;
471 /* make sure that there is space for 'size' bytes in buffer, growing it if needed */
472 static inline void *get_buffer_space( void **buffer, size_t size )
474 void *ret;
476 if (*buffer)
478 if (!(ret = HeapReAlloc( GetProcessHeap(), 0, *buffer, size )))
479 HeapFree( GetProcessHeap(), 0, *buffer );
481 else ret = HeapAlloc( GetProcessHeap(), 0, size );
483 *buffer = ret;
484 return ret;
487 /* check whether a combobox expects strings or ids in CB_ADDSTRING/CB_INSERTSTRING */
488 static inline BOOL combobox_has_strings( HWND hwnd )
490 DWORD style = GetWindowLongA( hwnd, GWL_STYLE );
491 return (!(style & (CBS_OWNERDRAWFIXED | CBS_OWNERDRAWVARIABLE)) || (style & CBS_HASSTRINGS));
494 /* check whether a listbox expects strings or ids in LB_ADDSTRING/LB_INSERTSTRING */
495 static inline BOOL listbox_has_strings( HWND hwnd )
497 DWORD style = GetWindowLongA( hwnd, GWL_STYLE );
498 return (!(style & (LBS_OWNERDRAWFIXED | LBS_OWNERDRAWVARIABLE)) || (style & LBS_HASSTRINGS));
501 /* check whether message is in the range of keyboard messages */
502 static inline BOOL is_keyboard_message( UINT message )
504 return (message >= WM_KEYFIRST && message <= WM_KEYLAST);
507 /* check whether message is in the range of mouse messages */
508 static inline BOOL is_mouse_message( UINT message )
510 return ((message >= WM_NCMOUSEFIRST && message <= WM_NCMOUSELAST) ||
511 (message >= WM_MOUSEFIRST && message <= WM_MOUSELAST));
514 /* check whether message matches the specified hwnd filter */
515 static inline BOOL check_hwnd_filter( const MSG *msg, HWND hwnd_filter )
517 if (!hwnd_filter || hwnd_filter == GetDesktopWindow()) return TRUE;
518 return (msg->hwnd == hwnd_filter || IsChild( hwnd_filter, msg->hwnd ));
521 /* check for pending WM_CHAR message with DBCS trailing byte */
522 static inline BOOL get_pending_wmchar( MSG *msg, UINT first, UINT last, BOOL remove )
524 struct wm_char_mapping_data *data = get_user_thread_info()->wmchar_data;
526 if (!data || !data->get_msg.message) return FALSE;
527 if ((first || last) && (first > WM_CHAR || last < WM_CHAR)) return FALSE;
528 if (!msg) return FALSE;
529 *msg = data->get_msg;
530 if (remove) data->get_msg.message = 0;
531 return TRUE;
535 /***********************************************************************
536 * MessageWndProc
538 * Window procedure for "Message" windows (HWND_MESSAGE parent).
540 LRESULT WINAPI MessageWndProc( HWND hwnd, UINT message, WPARAM wParam, LPARAM lParam )
542 if (message == WM_NCCREATE) return TRUE;
543 return 0; /* all other messages are ignored */
547 /***********************************************************************
548 * broadcast_message_callback
550 * Helper callback for broadcasting messages.
552 static BOOL CALLBACK broadcast_message_callback( HWND hwnd, LPARAM lparam )
554 struct send_message_info *info = (struct send_message_info *)lparam;
555 if ((GetWindowLongW( hwnd, GWL_STYLE ) & (WS_POPUP|WS_CHILD)) == WS_CHILD)
556 return TRUE;
557 switch(info->type)
559 case MSG_UNICODE:
560 SendMessageTimeoutW( hwnd, info->msg, info->wparam, info->lparam,
561 info->flags, info->timeout, NULL );
562 break;
563 case MSG_ASCII:
564 SendMessageTimeoutA( hwnd, info->msg, info->wparam, info->lparam,
565 info->flags, info->timeout, NULL );
566 break;
567 case MSG_NOTIFY:
568 SendNotifyMessageW( hwnd, info->msg, info->wparam, info->lparam );
569 break;
570 case MSG_CALLBACK:
571 SendMessageCallbackW( hwnd, info->msg, info->wparam, info->lparam,
572 info->callback, info->data );
573 break;
574 case MSG_POSTED:
575 PostMessageW( hwnd, info->msg, info->wparam, info->lparam );
576 break;
577 default:
578 ERR( "bad type %d\n", info->type );
579 break;
581 return TRUE;
584 DWORD get_input_codepage( void )
586 DWORD cp;
587 int ret;
588 HKL hkl = GetKeyboardLayout( 0 );
590 ret = GetLocaleInfoW( LOWORD(hkl), LOCALE_IDEFAULTANSICODEPAGE | LOCALE_RETURN_NUMBER,
591 (WCHAR *)&cp, sizeof(cp) / sizeof(WCHAR) );
592 if (!ret) cp = CP_ACP;
593 return cp;
596 /***********************************************************************
597 * map_wparam_AtoW
599 * Convert the wparam of an ASCII message to Unicode.
601 BOOL map_wparam_AtoW( UINT message, WPARAM *wparam, enum wm_char_mapping mapping )
603 char ch[2];
604 WCHAR wch[2];
605 DWORD cp = get_input_codepage();
607 wch[0] = wch[1] = 0;
608 switch(message)
610 case WM_CHAR:
611 /* WM_CHAR is magic: a DBCS char can be sent/posted as two consecutive WM_CHAR
612 * messages, in which case the first char is stored, and the conversion
613 * to Unicode only takes place once the second char is sent/posted.
615 if (mapping != WMCHAR_MAP_NOMAPPING)
617 struct wm_char_mapping_data *data = get_user_thread_info()->wmchar_data;
618 BYTE low = LOBYTE(*wparam);
620 if (HIBYTE(*wparam))
622 ch[0] = low;
623 ch[1] = HIBYTE(*wparam);
624 MultiByteToWideChar( cp, 0, ch, 2, wch, 2 );
625 TRACE( "map %02x,%02x -> %04x mapping %u\n", (BYTE)ch[0], (BYTE)ch[1], wch[0], mapping );
626 if (data) data->lead_byte[mapping] = 0;
628 else if (data && data->lead_byte[mapping])
630 ch[0] = data->lead_byte[mapping];
631 ch[1] = low;
632 MultiByteToWideChar( cp, 0, ch, 2, wch, 2 );
633 TRACE( "map stored %02x,%02x -> %04x mapping %u\n", (BYTE)ch[0], (BYTE)ch[1], wch[0], mapping );
634 data->lead_byte[mapping] = 0;
636 else if (!IsDBCSLeadByte( low ))
638 ch[0] = low;
639 MultiByteToWideChar( cp, 0, ch, 1, wch, 2 );
640 TRACE( "map %02x -> %04x\n", (BYTE)ch[0], wch[0] );
641 if (data) data->lead_byte[mapping] = 0;
643 else /* store it and wait for trail byte */
645 if (!data)
647 if (!(data = HeapAlloc( GetProcessHeap(), HEAP_ZERO_MEMORY, sizeof(*data) )))
648 return FALSE;
649 get_user_thread_info()->wmchar_data = data;
651 TRACE( "storing lead byte %02x mapping %u\n", low, mapping );
652 data->lead_byte[mapping] = low;
653 return FALSE;
655 *wparam = MAKEWPARAM(wch[0], wch[1]);
656 break;
658 /* else fall through */
659 case WM_CHARTOITEM:
660 case EM_SETPASSWORDCHAR:
661 case WM_DEADCHAR:
662 case WM_SYSCHAR:
663 case WM_SYSDEADCHAR:
664 case WM_MENUCHAR:
665 ch[0] = LOBYTE(*wparam);
666 ch[1] = HIBYTE(*wparam);
667 MultiByteToWideChar( cp, 0, ch, 2, wch, 2 );
668 *wparam = MAKEWPARAM(wch[0], wch[1]);
669 break;
670 case WM_IME_CHAR:
671 ch[0] = HIBYTE(*wparam);
672 ch[1] = LOBYTE(*wparam);
673 if (ch[0]) MultiByteToWideChar( cp, 0, ch, 2, wch, 2 );
674 else MultiByteToWideChar( cp, 0, ch + 1, 1, wch, 1 );
675 *wparam = MAKEWPARAM(wch[0], HIWORD(*wparam));
676 break;
678 return TRUE;
682 /***********************************************************************
683 * map_wparam_WtoA
685 * Convert the wparam of a Unicode message to ASCII.
687 static void map_wparam_WtoA( MSG *msg, BOOL remove )
689 BYTE ch[4];
690 WCHAR wch[2];
691 DWORD len;
692 DWORD cp = get_input_codepage();
694 switch(msg->message)
696 case WM_CHAR:
697 if (!HIWORD(msg->wParam))
699 wch[0] = LOWORD(msg->wParam);
700 ch[0] = ch[1] = 0;
701 len = WideCharToMultiByte( cp, 0, wch, 1, (LPSTR)ch, 2, NULL, NULL );
702 if (len == 2) /* DBCS char */
704 struct wm_char_mapping_data *data = get_user_thread_info()->wmchar_data;
705 if (!data)
707 if (!(data = HeapAlloc( GetProcessHeap(), HEAP_ZERO_MEMORY, sizeof(*data) ))) return;
708 get_user_thread_info()->wmchar_data = data;
710 if (remove)
712 data->get_msg = *msg;
713 data->get_msg.wParam = ch[1];
715 msg->wParam = ch[0];
716 return;
719 /* else fall through */
720 case WM_CHARTOITEM:
721 case EM_SETPASSWORDCHAR:
722 case WM_DEADCHAR:
723 case WM_SYSCHAR:
724 case WM_SYSDEADCHAR:
725 case WM_MENUCHAR:
726 wch[0] = LOWORD(msg->wParam);
727 wch[1] = HIWORD(msg->wParam);
728 ch[0] = ch[1] = 0;
729 WideCharToMultiByte( cp, 0, wch, 2, (LPSTR)ch, 4, NULL, NULL );
730 msg->wParam = MAKEWPARAM( ch[0] | (ch[1] << 8), 0 );
731 break;
732 case WM_IME_CHAR:
733 wch[0] = LOWORD(msg->wParam);
734 ch[0] = ch[1] = 0;
735 len = WideCharToMultiByte( cp, 0, wch, 1, (LPSTR)ch, 2, NULL, NULL );
736 if (len == 2)
737 msg->wParam = MAKEWPARAM( (ch[0] << 8) | ch[1], HIWORD(msg->wParam) );
738 else
739 msg->wParam = MAKEWPARAM( ch[0], HIWORD(msg->wParam) );
740 break;
745 /***********************************************************************
746 * pack_message
748 * Pack a message for sending to another process.
749 * Return the size of the data we expect in the message reply.
750 * Set data->count to -1 if there is an error.
752 static size_t pack_message( HWND hwnd, UINT message, WPARAM wparam, LPARAM lparam,
753 struct packed_message *data )
755 data->count = 0;
756 switch(message)
758 case WM_NCCREATE:
759 case WM_CREATE:
761 CREATESTRUCTW *cs = (CREATESTRUCTW *)lparam;
762 data->ps.cs.lpCreateParams = pack_ptr( cs->lpCreateParams );
763 data->ps.cs.hInstance = pack_ptr( cs->hInstance );
764 data->ps.cs.hMenu = wine_server_user_handle( cs->hMenu );
765 data->ps.cs.hwndParent = wine_server_user_handle( cs->hwndParent );
766 data->ps.cs.cy = cs->cy;
767 data->ps.cs.cx = cs->cx;
768 data->ps.cs.y = cs->y;
769 data->ps.cs.x = cs->x;
770 data->ps.cs.style = cs->style;
771 data->ps.cs.dwExStyle = cs->dwExStyle;
772 data->ps.cs.lpszName = pack_ptr( cs->lpszName );
773 data->ps.cs.lpszClass = pack_ptr( cs->lpszClass );
774 push_data( data, &data->ps.cs, sizeof(data->ps.cs) );
775 if (!IS_INTRESOURCE(cs->lpszName)) push_string( data, cs->lpszName );
776 if (!IS_INTRESOURCE(cs->lpszClass)) push_string( data, cs->lpszClass );
777 return sizeof(data->ps.cs);
779 case WM_GETTEXT:
780 case WM_ASKCBFORMATNAME:
781 return wparam * sizeof(WCHAR);
782 case WM_WININICHANGE:
783 if (lparam) push_string(data, (LPWSTR)lparam );
784 return 0;
785 case WM_SETTEXT:
786 case WM_DEVMODECHANGE:
787 case CB_DIR:
788 case LB_DIR:
789 case LB_ADDFILE:
790 case EM_REPLACESEL:
791 push_string( data, (LPWSTR)lparam );
792 return 0;
793 case WM_GETMINMAXINFO:
794 push_data( data, (MINMAXINFO *)lparam, sizeof(MINMAXINFO) );
795 return sizeof(MINMAXINFO);
796 case WM_DRAWITEM:
798 DRAWITEMSTRUCT *dis = (DRAWITEMSTRUCT *)lparam;
799 data->ps.dis.CtlType = dis->CtlType;
800 data->ps.dis.CtlID = dis->CtlID;
801 data->ps.dis.itemID = dis->itemID;
802 data->ps.dis.itemAction = dis->itemAction;
803 data->ps.dis.itemState = dis->itemState;
804 data->ps.dis.hwndItem = wine_server_user_handle( dis->hwndItem );
805 data->ps.dis.hDC = wine_server_user_handle( dis->hDC ); /* FIXME */
806 data->ps.dis.rcItem = dis->rcItem;
807 data->ps.dis.itemData = dis->itemData;
808 push_data( data, &data->ps.dis, sizeof(data->ps.dis) );
809 return 0;
811 case WM_MEASUREITEM:
813 MEASUREITEMSTRUCT *mis = (MEASUREITEMSTRUCT *)lparam;
814 data->ps.mis.CtlType = mis->CtlType;
815 data->ps.mis.CtlID = mis->CtlID;
816 data->ps.mis.itemID = mis->itemID;
817 data->ps.mis.itemWidth = mis->itemWidth;
818 data->ps.mis.itemHeight = mis->itemHeight;
819 data->ps.mis.itemData = mis->itemData;
820 push_data( data, &data->ps.mis, sizeof(data->ps.mis) );
821 return sizeof(data->ps.mis);
823 case WM_DELETEITEM:
825 DELETEITEMSTRUCT *dls = (DELETEITEMSTRUCT *)lparam;
826 data->ps.dls.CtlType = dls->CtlType;
827 data->ps.dls.CtlID = dls->CtlID;
828 data->ps.dls.itemID = dls->itemID;
829 data->ps.dls.hwndItem = wine_server_user_handle( dls->hwndItem );
830 data->ps.dls.itemData = dls->itemData;
831 push_data( data, &data->ps.dls, sizeof(data->ps.dls) );
832 return 0;
834 case WM_COMPAREITEM:
836 COMPAREITEMSTRUCT *cis = (COMPAREITEMSTRUCT *)lparam;
837 data->ps.cis.CtlType = cis->CtlType;
838 data->ps.cis.CtlID = cis->CtlID;
839 data->ps.cis.hwndItem = wine_server_user_handle( cis->hwndItem );
840 data->ps.cis.itemID1 = cis->itemID1;
841 data->ps.cis.itemData1 = cis->itemData1;
842 data->ps.cis.itemID2 = cis->itemID2;
843 data->ps.cis.itemData2 = cis->itemData2;
844 data->ps.cis.dwLocaleId = cis->dwLocaleId;
845 push_data( data, &data->ps.cis, sizeof(data->ps.cis) );
846 return 0;
848 case WM_WINE_SETWINDOWPOS:
849 case WM_WINDOWPOSCHANGING:
850 case WM_WINDOWPOSCHANGED:
852 WINDOWPOS *wp = (WINDOWPOS *)lparam;
853 data->ps.wp.hwnd = wine_server_user_handle( wp->hwnd );
854 data->ps.wp.hwndInsertAfter = wine_server_user_handle( wp->hwndInsertAfter );
855 data->ps.wp.x = wp->x;
856 data->ps.wp.y = wp->y;
857 data->ps.wp.cx = wp->cx;
858 data->ps.wp.cy = wp->cy;
859 data->ps.wp.flags = wp->flags;
860 push_data( data, &data->ps.wp, sizeof(data->ps.wp) );
861 return sizeof(data->ps.wp);
863 case WM_COPYDATA:
865 COPYDATASTRUCT *cds = (COPYDATASTRUCT *)lparam;
866 data->ps.cds.cbData = cds->cbData;
867 data->ps.cds.dwData = cds->dwData;
868 data->ps.cds.lpData = pack_ptr( cds->lpData );
869 push_data( data, &data->ps.cds, sizeof(data->ps.cds) );
870 if (cds->lpData) push_data( data, cds->lpData, cds->cbData );
871 return 0;
873 case WM_NOTIFY:
874 /* WM_NOTIFY cannot be sent across processes (MSDN) */
875 data->count = -1;
876 return 0;
877 case WM_HELP:
879 HELPINFO *hi = (HELPINFO *)lparam;
880 data->ps.hi.iContextType = hi->iContextType;
881 data->ps.hi.iCtrlId = hi->iCtrlId;
882 data->ps.hi.hItemHandle = wine_server_user_handle( hi->hItemHandle );
883 data->ps.hi.dwContextId = hi->dwContextId;
884 data->ps.hi.MousePos = hi->MousePos;
885 push_data( data, &data->ps.hi, sizeof(data->ps.hi) );
886 return 0;
888 case WM_STYLECHANGING:
889 case WM_STYLECHANGED:
890 push_data( data, (STYLESTRUCT *)lparam, sizeof(STYLESTRUCT) );
891 return 0;
892 case WM_NCCALCSIZE:
893 if (!wparam)
895 push_data( data, (RECT *)lparam, sizeof(RECT) );
896 return sizeof(RECT);
898 else
900 NCCALCSIZE_PARAMS *ncp = (NCCALCSIZE_PARAMS *)lparam;
901 data->ps.ncp.rgrc[0] = ncp->rgrc[0];
902 data->ps.ncp.rgrc[1] = ncp->rgrc[1];
903 data->ps.ncp.rgrc[2] = ncp->rgrc[2];
904 data->ps.ncp.hwnd = wine_server_user_handle( ncp->lppos->hwnd );
905 data->ps.ncp.hwndInsertAfter = wine_server_user_handle( ncp->lppos->hwndInsertAfter );
906 data->ps.ncp.x = ncp->lppos->x;
907 data->ps.ncp.y = ncp->lppos->y;
908 data->ps.ncp.cx = ncp->lppos->cx;
909 data->ps.ncp.cy = ncp->lppos->cy;
910 data->ps.ncp.flags = ncp->lppos->flags;
911 push_data( data, &data->ps.ncp, sizeof(data->ps.ncp) );
912 return sizeof(data->ps.ncp);
914 case WM_GETDLGCODE:
915 if (lparam)
917 MSG *msg = (MSG *)lparam;
918 data->ps.msg.hwnd = wine_server_user_handle( msg->hwnd );
919 data->ps.msg.message = msg->message;
920 data->ps.msg.wParam = msg->wParam;
921 data->ps.msg.lParam = msg->lParam;
922 data->ps.msg.time = msg->time;
923 data->ps.msg.pt = msg->pt;
924 push_data( data, &data->ps.msg, sizeof(data->ps.msg) );
925 return sizeof(data->ps.msg);
927 return 0;
928 case SBM_SETSCROLLINFO:
929 push_data( data, (SCROLLINFO *)lparam, sizeof(SCROLLINFO) );
930 return 0;
931 case SBM_GETSCROLLINFO:
932 push_data( data, (SCROLLINFO *)lparam, sizeof(SCROLLINFO) );
933 return sizeof(SCROLLINFO);
934 case SBM_GETSCROLLBARINFO:
936 const SCROLLBARINFO *info = (const SCROLLBARINFO *)lparam;
937 size_t size = min( info->cbSize, sizeof(SCROLLBARINFO) );
938 push_data( data, info, size );
939 return size;
941 case EM_GETSEL:
942 case SBM_GETRANGE:
943 case CB_GETEDITSEL:
945 size_t size = 0;
946 if (wparam) size += sizeof(DWORD);
947 if (lparam) size += sizeof(DWORD);
948 return size;
950 case EM_GETRECT:
951 case LB_GETITEMRECT:
952 case CB_GETDROPPEDCONTROLRECT:
953 return sizeof(RECT);
954 case EM_SETRECT:
955 case EM_SETRECTNP:
956 push_data( data, (RECT *)lparam, sizeof(RECT) );
957 return 0;
958 case EM_GETLINE:
960 WORD *pw = (WORD *)lparam;
961 push_data( data, pw, sizeof(*pw) );
962 return *pw * sizeof(WCHAR);
964 case EM_SETTABSTOPS:
965 case LB_SETTABSTOPS:
966 if (wparam) push_data( data, (UINT *)lparam, sizeof(UINT) * wparam );
967 return 0;
968 case CB_ADDSTRING:
969 case CB_INSERTSTRING:
970 case CB_FINDSTRING:
971 case CB_FINDSTRINGEXACT:
972 case CB_SELECTSTRING:
973 if (combobox_has_strings( hwnd )) push_string( data, (LPWSTR)lparam );
974 return 0;
975 case CB_GETLBTEXT:
976 if (!combobox_has_strings( hwnd )) return sizeof(ULONG_PTR);
977 return (SendMessageW( hwnd, CB_GETLBTEXTLEN, wparam, 0 ) + 1) * sizeof(WCHAR);
978 case LB_ADDSTRING:
979 case LB_INSERTSTRING:
980 case LB_FINDSTRING:
981 case LB_FINDSTRINGEXACT:
982 case LB_SELECTSTRING:
983 if (listbox_has_strings( hwnd )) push_string( data, (LPWSTR)lparam );
984 return 0;
985 case LB_GETTEXT:
986 if (!listbox_has_strings( hwnd )) return sizeof(ULONG_PTR);
987 return (SendMessageW( hwnd, LB_GETTEXTLEN, wparam, 0 ) + 1) * sizeof(WCHAR);
988 case LB_GETSELITEMS:
989 return wparam * sizeof(UINT);
990 case WM_NEXTMENU:
992 MDINEXTMENU *mnm = (MDINEXTMENU *)lparam;
993 data->ps.mnm.hmenuIn = wine_server_user_handle( mnm->hmenuIn );
994 data->ps.mnm.hmenuNext = wine_server_user_handle( mnm->hmenuNext );
995 data->ps.mnm.hwndNext = wine_server_user_handle( mnm->hwndNext );
996 push_data( data, &data->ps.mnm, sizeof(data->ps.mnm) );
997 return sizeof(data->ps.mnm);
999 case WM_SIZING:
1000 case WM_MOVING:
1001 push_data( data, (RECT *)lparam, sizeof(RECT) );
1002 return sizeof(RECT);
1003 case WM_MDICREATE:
1005 MDICREATESTRUCTW *mcs = (MDICREATESTRUCTW *)lparam;
1006 data->ps.mcs.szClass = pack_ptr( mcs->szClass );
1007 data->ps.mcs.szTitle = pack_ptr( mcs->szTitle );
1008 data->ps.mcs.hOwner = pack_ptr( mcs->hOwner );
1009 data->ps.mcs.x = mcs->x;
1010 data->ps.mcs.y = mcs->y;
1011 data->ps.mcs.cx = mcs->cx;
1012 data->ps.mcs.cy = mcs->cy;
1013 data->ps.mcs.style = mcs->style;
1014 data->ps.mcs.lParam = mcs->lParam;
1015 push_data( data, &data->ps.mcs, sizeof(data->ps.mcs) );
1016 if (!IS_INTRESOURCE(mcs->szClass)) push_string( data, mcs->szClass );
1017 if (!IS_INTRESOURCE(mcs->szTitle)) push_string( data, mcs->szTitle );
1018 return sizeof(data->ps.mcs);
1020 case WM_MDIGETACTIVE:
1021 if (lparam) return sizeof(BOOL);
1022 return 0;
1023 case WM_DEVICECHANGE:
1025 DEV_BROADCAST_HDR *header = (DEV_BROADCAST_HDR *)lparam;
1026 if ((wparam & 0x8000) && header) push_data( data, header, header->dbch_size );
1027 return 0;
1029 case WM_WINE_KEYBOARD_LL_HOOK:
1031 struct hook_extra_info *h_extra = (struct hook_extra_info *)lparam;
1032 data->ps.hook.handle = wine_server_user_handle( h_extra->handle );
1033 push_data( data, &data->ps.hook, sizeof(data->ps.hook) );
1034 push_data( data, (LPVOID)h_extra->lparam, sizeof(KBDLLHOOKSTRUCT) );
1035 return 0;
1037 case WM_WINE_MOUSE_LL_HOOK:
1039 struct hook_extra_info *h_extra = (struct hook_extra_info *)lparam;
1040 data->ps.hook.handle = wine_server_user_handle( h_extra->handle );
1041 push_data( data, &data->ps.hook, sizeof(data->ps.hook) );
1042 push_data( data, (LPVOID)h_extra->lparam, sizeof(MSLLHOOKSTRUCT) );
1043 return 0;
1045 case WM_NCPAINT:
1046 if (wparam <= 1) return 0;
1047 FIXME( "WM_NCPAINT hdc packing not supported yet\n" );
1048 data->count = -1;
1049 return 0;
1050 case WM_PAINT:
1051 if (!wparam) return 0;
1052 /* fall through */
1054 /* these contain an HFONT */
1055 case WM_SETFONT:
1056 case WM_GETFONT:
1057 /* these contain an HDC */
1058 case WM_ERASEBKGND:
1059 case WM_ICONERASEBKGND:
1060 case WM_CTLCOLORMSGBOX:
1061 case WM_CTLCOLOREDIT:
1062 case WM_CTLCOLORLISTBOX:
1063 case WM_CTLCOLORBTN:
1064 case WM_CTLCOLORDLG:
1065 case WM_CTLCOLORSCROLLBAR:
1066 case WM_CTLCOLORSTATIC:
1067 case WM_PRINT:
1068 case WM_PRINTCLIENT:
1069 /* these contain an HGLOBAL */
1070 case WM_PAINTCLIPBOARD:
1071 case WM_SIZECLIPBOARD:
1072 /* these contain HICON */
1073 case WM_GETICON:
1074 case WM_SETICON:
1075 case WM_QUERYDRAGICON:
1076 case WM_QUERYPARKICON:
1077 /* these contain pointers */
1078 case WM_DROPOBJECT:
1079 case WM_QUERYDROPOBJECT:
1080 case WM_DRAGLOOP:
1081 case WM_DRAGSELECT:
1082 case WM_DRAGMOVE:
1083 FIXME( "msg %x (%s) not supported yet\n", message, SPY_GetMsgName(message, hwnd) );
1084 data->count = -1;
1085 return 0;
1087 return 0;
1091 /***********************************************************************
1092 * unpack_message
1094 * Unpack a message received from another process.
1096 static BOOL unpack_message( HWND hwnd, UINT message, WPARAM *wparam, LPARAM *lparam,
1097 void **buffer, size_t size )
1099 size_t minsize = 0;
1100 union packed_structs *ps = *buffer;
1102 switch(message)
1104 case WM_NCCREATE:
1105 case WM_CREATE:
1107 CREATESTRUCTW cs;
1108 WCHAR *str = (WCHAR *)(&ps->cs + 1);
1109 if (size < sizeof(ps->cs)) return FALSE;
1110 size -= sizeof(ps->cs);
1111 cs.lpCreateParams = unpack_ptr( ps->cs.lpCreateParams );
1112 cs.hInstance = unpack_ptr( ps->cs.hInstance );
1113 cs.hMenu = wine_server_ptr_handle( ps->cs.hMenu );
1114 cs.hwndParent = wine_server_ptr_handle( ps->cs.hwndParent );
1115 cs.cy = ps->cs.cy;
1116 cs.cx = ps->cs.cx;
1117 cs.y = ps->cs.y;
1118 cs.x = ps->cs.x;
1119 cs.style = ps->cs.style;
1120 cs.dwExStyle = ps->cs.dwExStyle;
1121 cs.lpszName = unpack_ptr( ps->cs.lpszName );
1122 cs.lpszClass = unpack_ptr( ps->cs.lpszClass );
1123 if (ps->cs.lpszName >> 16)
1125 if (!check_string( str, size )) return FALSE;
1126 cs.lpszName = str;
1127 size -= (lstrlenW(str) + 1) * sizeof(WCHAR);
1128 str += lstrlenW(str) + 1;
1130 if (ps->cs.lpszClass >> 16)
1132 if (!check_string( str, size )) return FALSE;
1133 cs.lpszClass = str;
1135 memcpy( &ps->cs, &cs, sizeof(cs) );
1136 break;
1138 case WM_GETTEXT:
1139 case WM_ASKCBFORMATNAME:
1140 if (!get_buffer_space( buffer, (*wparam * sizeof(WCHAR)) )) return FALSE;
1141 break;
1142 case WM_WININICHANGE:
1143 if (!*lparam) return TRUE;
1144 /* fall through */
1145 case WM_SETTEXT:
1146 case WM_DEVMODECHANGE:
1147 case CB_DIR:
1148 case LB_DIR:
1149 case LB_ADDFILE:
1150 case EM_REPLACESEL:
1151 if (!check_string( *buffer, size )) return FALSE;
1152 break;
1153 case WM_GETMINMAXINFO:
1154 minsize = sizeof(MINMAXINFO);
1155 break;
1156 case WM_DRAWITEM:
1158 DRAWITEMSTRUCT dis;
1159 if (size < sizeof(ps->dis)) return FALSE;
1160 dis.CtlType = ps->dis.CtlType;
1161 dis.CtlID = ps->dis.CtlID;
1162 dis.itemID = ps->dis.itemID;
1163 dis.itemAction = ps->dis.itemAction;
1164 dis.itemState = ps->dis.itemState;
1165 dis.hwndItem = wine_server_ptr_handle( ps->dis.hwndItem );
1166 dis.hDC = wine_server_ptr_handle( ps->dis.hDC );
1167 dis.rcItem = ps->dis.rcItem;
1168 dis.itemData = (ULONG_PTR)unpack_ptr( ps->dis.itemData );
1169 memcpy( &ps->dis, &dis, sizeof(dis) );
1170 break;
1172 case WM_MEASUREITEM:
1174 MEASUREITEMSTRUCT mis;
1175 if (size < sizeof(ps->mis)) return FALSE;
1176 mis.CtlType = ps->mis.CtlType;
1177 mis.CtlID = ps->mis.CtlID;
1178 mis.itemID = ps->mis.itemID;
1179 mis.itemWidth = ps->mis.itemWidth;
1180 mis.itemHeight = ps->mis.itemHeight;
1181 mis.itemData = (ULONG_PTR)unpack_ptr( ps->mis.itemData );
1182 memcpy( &ps->mis, &mis, sizeof(mis) );
1183 break;
1185 case WM_DELETEITEM:
1187 DELETEITEMSTRUCT dls;
1188 if (size < sizeof(ps->dls)) return FALSE;
1189 dls.CtlType = ps->dls.CtlType;
1190 dls.CtlID = ps->dls.CtlID;
1191 dls.itemID = ps->dls.itemID;
1192 dls.hwndItem = wine_server_ptr_handle( ps->dls.hwndItem );
1193 dls.itemData = (ULONG_PTR)unpack_ptr( ps->dls.itemData );
1194 memcpy( &ps->dls, &dls, sizeof(dls) );
1195 break;
1197 case WM_COMPAREITEM:
1199 COMPAREITEMSTRUCT cis;
1200 if (size < sizeof(ps->cis)) return FALSE;
1201 cis.CtlType = ps->cis.CtlType;
1202 cis.CtlID = ps->cis.CtlID;
1203 cis.hwndItem = wine_server_ptr_handle( ps->cis.hwndItem );
1204 cis.itemID1 = ps->cis.itemID1;
1205 cis.itemData1 = (ULONG_PTR)unpack_ptr( ps->cis.itemData1 );
1206 cis.itemID2 = ps->cis.itemID2;
1207 cis.itemData2 = (ULONG_PTR)unpack_ptr( ps->cis.itemData2 );
1208 cis.dwLocaleId = ps->cis.dwLocaleId;
1209 memcpy( &ps->cis, &cis, sizeof(cis) );
1210 break;
1212 case WM_WINDOWPOSCHANGING:
1213 case WM_WINDOWPOSCHANGED:
1214 case WM_WINE_SETWINDOWPOS:
1216 WINDOWPOS wp;
1217 if (size < sizeof(ps->wp)) return FALSE;
1218 wp.hwnd = wine_server_ptr_handle( ps->wp.hwnd );
1219 wp.hwndInsertAfter = wine_server_ptr_handle( ps->wp.hwndInsertAfter );
1220 wp.x = ps->wp.x;
1221 wp.y = ps->wp.y;
1222 wp.cx = ps->wp.cx;
1223 wp.cy = ps->wp.cy;
1224 wp.flags = ps->wp.flags;
1225 memcpy( &ps->wp, &wp, sizeof(wp) );
1226 break;
1228 case WM_COPYDATA:
1230 COPYDATASTRUCT cds;
1231 if (size < sizeof(ps->cds)) return FALSE;
1232 cds.dwData = (ULONG_PTR)unpack_ptr( ps->cds.dwData );
1233 if (ps->cds.lpData)
1235 cds.cbData = ps->cds.cbData;
1236 cds.lpData = &ps->cds + 1;
1237 minsize = sizeof(ps->cds) + cds.cbData;
1239 else
1241 cds.cbData = 0;
1242 cds.lpData = 0;
1244 memcpy( &ps->cds, &cds, sizeof(cds) );
1245 break;
1247 case WM_NOTIFY:
1248 /* WM_NOTIFY cannot be sent across processes (MSDN) */
1249 return FALSE;
1250 case WM_HELP:
1252 HELPINFO hi;
1253 if (size < sizeof(ps->hi)) return FALSE;
1254 hi.cbSize = sizeof(hi);
1255 hi.iContextType = ps->hi.iContextType;
1256 hi.iCtrlId = ps->hi.iCtrlId;
1257 hi.hItemHandle = wine_server_ptr_handle( ps->hi.hItemHandle );
1258 hi.dwContextId = (ULONG_PTR)unpack_ptr( ps->hi.dwContextId );
1259 hi.MousePos = ps->hi.MousePos;
1260 memcpy( &ps->hi, &hi, sizeof(hi) );
1261 break;
1263 case WM_STYLECHANGING:
1264 case WM_STYLECHANGED:
1265 minsize = sizeof(STYLESTRUCT);
1266 break;
1267 case WM_NCCALCSIZE:
1268 if (!*wparam) minsize = sizeof(RECT);
1269 else
1271 NCCALCSIZE_PARAMS ncp;
1272 WINDOWPOS wp;
1273 if (size < sizeof(ps->ncp)) return FALSE;
1274 ncp.rgrc[0] = ps->ncp.rgrc[0];
1275 ncp.rgrc[1] = ps->ncp.rgrc[1];
1276 ncp.rgrc[2] = ps->ncp.rgrc[2];
1277 wp.hwnd = wine_server_ptr_handle( ps->ncp.hwnd );
1278 wp.hwndInsertAfter = wine_server_ptr_handle( ps->ncp.hwndInsertAfter );
1279 wp.x = ps->ncp.x;
1280 wp.y = ps->ncp.y;
1281 wp.cx = ps->ncp.cx;
1282 wp.cy = ps->ncp.cy;
1283 wp.flags = ps->ncp.flags;
1284 ncp.lppos = (WINDOWPOS *)((NCCALCSIZE_PARAMS *)&ps->ncp + 1);
1285 memcpy( &ps->ncp, &ncp, sizeof(ncp) );
1286 *ncp.lppos = wp;
1288 break;
1289 case WM_GETDLGCODE:
1290 if (*lparam)
1292 MSG msg;
1293 if (size < sizeof(ps->msg)) return FALSE;
1294 msg.hwnd = wine_server_ptr_handle( ps->msg.hwnd );
1295 msg.message = ps->msg.message;
1296 msg.wParam = (ULONG_PTR)unpack_ptr( ps->msg.wParam );
1297 msg.lParam = (ULONG_PTR)unpack_ptr( ps->msg.lParam );
1298 msg.time = ps->msg.time;
1299 msg.pt = ps->msg.pt;
1300 memcpy( &ps->msg, &msg, sizeof(msg) );
1301 break;
1303 return TRUE;
1304 case SBM_SETSCROLLINFO:
1305 minsize = sizeof(SCROLLINFO);
1306 break;
1307 case SBM_GETSCROLLINFO:
1308 if (!get_buffer_space( buffer, sizeof(SCROLLINFO ))) return FALSE;
1309 break;
1310 case SBM_GETSCROLLBARINFO:
1311 if (!get_buffer_space( buffer, sizeof(SCROLLBARINFO ))) return FALSE;
1312 break;
1313 case EM_GETSEL:
1314 case SBM_GETRANGE:
1315 case CB_GETEDITSEL:
1316 if (*wparam || *lparam)
1318 if (!get_buffer_space( buffer, 2*sizeof(DWORD) )) return FALSE;
1319 if (*wparam) *wparam = (WPARAM)*buffer;
1320 if (*lparam) *lparam = (LPARAM)((DWORD *)*buffer + 1);
1322 return TRUE;
1323 case EM_GETRECT:
1324 case LB_GETITEMRECT:
1325 case CB_GETDROPPEDCONTROLRECT:
1326 if (!get_buffer_space( buffer, sizeof(RECT) )) return FALSE;
1327 break;
1328 case EM_SETRECT:
1329 case EM_SETRECTNP:
1330 minsize = sizeof(RECT);
1331 break;
1332 case EM_GETLINE:
1334 WORD len;
1335 if (size < sizeof(WORD)) return FALSE;
1336 len = *(WORD *)*buffer;
1337 if (!get_buffer_space( buffer, (len + 1) * sizeof(WCHAR) )) return FALSE;
1338 *lparam = (LPARAM)*buffer + sizeof(WORD); /* don't erase WORD at start of buffer */
1339 return TRUE;
1341 case EM_SETTABSTOPS:
1342 case LB_SETTABSTOPS:
1343 if (!*wparam) return TRUE;
1344 minsize = *wparam * sizeof(UINT);
1345 break;
1346 case CB_ADDSTRING:
1347 case CB_INSERTSTRING:
1348 case CB_FINDSTRING:
1349 case CB_FINDSTRINGEXACT:
1350 case CB_SELECTSTRING:
1351 case LB_ADDSTRING:
1352 case LB_INSERTSTRING:
1353 case LB_FINDSTRING:
1354 case LB_FINDSTRINGEXACT:
1355 case LB_SELECTSTRING:
1356 if (!*buffer) return TRUE;
1357 if (!check_string( *buffer, size )) return FALSE;
1358 break;
1359 case CB_GETLBTEXT:
1361 size = sizeof(ULONG_PTR);
1362 if (combobox_has_strings( hwnd ))
1363 size = (SendMessageW( hwnd, CB_GETLBTEXTLEN, *wparam, 0 ) + 1) * sizeof(WCHAR);
1364 if (!get_buffer_space( buffer, size )) return FALSE;
1365 break;
1367 case LB_GETTEXT:
1369 size = sizeof(ULONG_PTR);
1370 if (listbox_has_strings( hwnd ))
1371 size = (SendMessageW( hwnd, LB_GETTEXTLEN, *wparam, 0 ) + 1) * sizeof(WCHAR);
1372 if (!get_buffer_space( buffer, size )) return FALSE;
1373 break;
1375 case LB_GETSELITEMS:
1376 if (!get_buffer_space( buffer, *wparam * sizeof(UINT) )) return FALSE;
1377 break;
1378 case WM_NEXTMENU:
1380 MDINEXTMENU mnm;
1381 if (size < sizeof(ps->mnm)) return FALSE;
1382 mnm.hmenuIn = wine_server_ptr_handle( ps->mnm.hmenuIn );
1383 mnm.hmenuNext = wine_server_ptr_handle( ps->mnm.hmenuNext );
1384 mnm.hwndNext = wine_server_ptr_handle( ps->mnm.hwndNext );
1385 memcpy( &ps->mnm, &mnm, sizeof(mnm) );
1386 break;
1388 case WM_SIZING:
1389 case WM_MOVING:
1390 minsize = sizeof(RECT);
1391 if (!get_buffer_space( buffer, sizeof(RECT) )) return FALSE;
1392 break;
1393 case WM_MDICREATE:
1395 MDICREATESTRUCTW mcs;
1396 WCHAR *str = (WCHAR *)(&ps->mcs + 1);
1397 if (size < sizeof(ps->mcs)) return FALSE;
1398 size -= sizeof(ps->mcs);
1400 mcs.szClass = unpack_ptr( ps->mcs.szClass );
1401 mcs.szTitle = unpack_ptr( ps->mcs.szTitle );
1402 mcs.hOwner = unpack_ptr( ps->mcs.hOwner );
1403 mcs.x = ps->mcs.x;
1404 mcs.y = ps->mcs.y;
1405 mcs.cx = ps->mcs.cx;
1406 mcs.cy = ps->mcs.cy;
1407 mcs.style = ps->mcs.style;
1408 mcs.lParam = (LPARAM)unpack_ptr( ps->mcs.lParam );
1409 if (ps->mcs.szClass >> 16)
1411 if (!check_string( str, size )) return FALSE;
1412 mcs.szClass = str;
1413 size -= (lstrlenW(str) + 1) * sizeof(WCHAR);
1414 str += lstrlenW(str) + 1;
1416 if (ps->mcs.szTitle >> 16)
1418 if (!check_string( str, size )) return FALSE;
1419 mcs.szTitle = str;
1421 memcpy( &ps->mcs, &mcs, sizeof(mcs) );
1422 break;
1424 case WM_MDIGETACTIVE:
1425 if (!*lparam) return TRUE;
1426 if (!get_buffer_space( buffer, sizeof(BOOL) )) return FALSE;
1427 break;
1428 case WM_DEVICECHANGE:
1429 if (!(*wparam & 0x8000)) return TRUE;
1430 minsize = sizeof(DEV_BROADCAST_HDR);
1431 break;
1432 case WM_WINE_KEYBOARD_LL_HOOK:
1433 case WM_WINE_MOUSE_LL_HOOK:
1435 struct hook_extra_info h_extra;
1436 minsize = sizeof(ps->hook) +
1437 (message == WM_WINE_KEYBOARD_LL_HOOK ? sizeof(KBDLLHOOKSTRUCT)
1438 : sizeof(MSLLHOOKSTRUCT));
1439 if (size < minsize) return FALSE;
1440 h_extra.handle = wine_server_ptr_handle( ps->hook.handle );
1441 h_extra.lparam = (LPARAM)(&ps->hook + 1);
1442 memcpy( &ps->hook, &h_extra, sizeof(h_extra) );
1443 break;
1445 case WM_NCPAINT:
1446 if (*wparam <= 1) return TRUE;
1447 FIXME( "WM_NCPAINT hdc unpacking not supported\n" );
1448 return FALSE;
1449 case WM_PAINT:
1450 if (!*wparam) return TRUE;
1451 /* fall through */
1453 /* these contain an HFONT */
1454 case WM_SETFONT:
1455 case WM_GETFONT:
1456 /* these contain an HDC */
1457 case WM_ERASEBKGND:
1458 case WM_ICONERASEBKGND:
1459 case WM_CTLCOLORMSGBOX:
1460 case WM_CTLCOLOREDIT:
1461 case WM_CTLCOLORLISTBOX:
1462 case WM_CTLCOLORBTN:
1463 case WM_CTLCOLORDLG:
1464 case WM_CTLCOLORSCROLLBAR:
1465 case WM_CTLCOLORSTATIC:
1466 case WM_PRINT:
1467 case WM_PRINTCLIENT:
1468 /* these contain an HGLOBAL */
1469 case WM_PAINTCLIPBOARD:
1470 case WM_SIZECLIPBOARD:
1471 /* these contain HICON */
1472 case WM_GETICON:
1473 case WM_SETICON:
1474 case WM_QUERYDRAGICON:
1475 case WM_QUERYPARKICON:
1476 /* these contain pointers */
1477 case WM_DROPOBJECT:
1478 case WM_QUERYDROPOBJECT:
1479 case WM_DRAGLOOP:
1480 case WM_DRAGSELECT:
1481 case WM_DRAGMOVE:
1482 FIXME( "msg %x (%s) not supported yet\n", message, SPY_GetMsgName(message, hwnd) );
1483 return FALSE;
1485 default:
1486 return TRUE; /* message doesn't need any unpacking */
1489 /* default exit for most messages: check minsize and store buffer in lparam */
1490 if (size < minsize) return FALSE;
1491 *lparam = (LPARAM)*buffer;
1492 return TRUE;
1496 /***********************************************************************
1497 * pack_reply
1499 * Pack a reply to a message for sending to another process.
1501 static void pack_reply( HWND hwnd, UINT message, WPARAM wparam, LPARAM lparam,
1502 LRESULT res, struct packed_message *data )
1504 data->count = 0;
1505 switch(message)
1507 case WM_NCCREATE:
1508 case WM_CREATE:
1510 CREATESTRUCTW *cs = (CREATESTRUCTW *)lparam;
1511 data->ps.cs.lpCreateParams = (ULONG_PTR)cs->lpCreateParams;
1512 data->ps.cs.hInstance = (ULONG_PTR)cs->hInstance;
1513 data->ps.cs.hMenu = wine_server_user_handle( cs->hMenu );
1514 data->ps.cs.hwndParent = wine_server_user_handle( cs->hwndParent );
1515 data->ps.cs.cy = cs->cy;
1516 data->ps.cs.cx = cs->cx;
1517 data->ps.cs.y = cs->y;
1518 data->ps.cs.x = cs->x;
1519 data->ps.cs.style = cs->style;
1520 data->ps.cs.dwExStyle = cs->dwExStyle;
1521 data->ps.cs.lpszName = (ULONG_PTR)cs->lpszName;
1522 data->ps.cs.lpszClass = (ULONG_PTR)cs->lpszClass;
1523 push_data( data, &data->ps.cs, sizeof(data->ps.cs) );
1524 break;
1526 case WM_GETTEXT:
1527 case CB_GETLBTEXT:
1528 case LB_GETTEXT:
1529 push_data( data, (WCHAR *)lparam, (res + 1) * sizeof(WCHAR) );
1530 break;
1531 case WM_GETMINMAXINFO:
1532 push_data( data, (MINMAXINFO *)lparam, sizeof(MINMAXINFO) );
1533 break;
1534 case WM_MEASUREITEM:
1536 MEASUREITEMSTRUCT *mis = (MEASUREITEMSTRUCT *)lparam;
1537 data->ps.mis.CtlType = mis->CtlType;
1538 data->ps.mis.CtlID = mis->CtlID;
1539 data->ps.mis.itemID = mis->itemID;
1540 data->ps.mis.itemWidth = mis->itemWidth;
1541 data->ps.mis.itemHeight = mis->itemHeight;
1542 data->ps.mis.itemData = mis->itemData;
1543 push_data( data, &data->ps.mis, sizeof(data->ps.mis) );
1544 break;
1546 case WM_WINDOWPOSCHANGING:
1547 case WM_WINDOWPOSCHANGED:
1549 WINDOWPOS *wp = (WINDOWPOS *)lparam;
1550 data->ps.wp.hwnd = wine_server_user_handle( wp->hwnd );
1551 data->ps.wp.hwndInsertAfter = wine_server_user_handle( wp->hwndInsertAfter );
1552 data->ps.wp.x = wp->x;
1553 data->ps.wp.y = wp->y;
1554 data->ps.wp.cx = wp->cx;
1555 data->ps.wp.cy = wp->cy;
1556 data->ps.wp.flags = wp->flags;
1557 push_data( data, &data->ps.wp, sizeof(data->ps.wp) );
1558 break;
1560 case WM_GETDLGCODE:
1561 if (lparam)
1563 MSG *msg = (MSG *)lparam;
1564 data->ps.msg.hwnd = wine_server_user_handle( msg->hwnd );
1565 data->ps.msg.message = msg->message;
1566 data->ps.msg.wParam = msg->wParam;
1567 data->ps.msg.lParam = msg->lParam;
1568 data->ps.msg.time = msg->time;
1569 data->ps.msg.pt = msg->pt;
1570 push_data( data, &data->ps.msg, sizeof(data->ps.msg) );
1572 break;
1573 case SBM_GETSCROLLINFO:
1574 push_data( data, (SCROLLINFO *)lparam, sizeof(SCROLLINFO) );
1575 break;
1576 case EM_GETRECT:
1577 case LB_GETITEMRECT:
1578 case CB_GETDROPPEDCONTROLRECT:
1579 case WM_SIZING:
1580 case WM_MOVING:
1581 push_data( data, (RECT *)lparam, sizeof(RECT) );
1582 break;
1583 case EM_GETLINE:
1585 WORD *ptr = (WORD *)lparam;
1586 push_data( data, ptr, ptr[-1] * sizeof(WCHAR) );
1587 break;
1589 case LB_GETSELITEMS:
1590 push_data( data, (UINT *)lparam, wparam * sizeof(UINT) );
1591 break;
1592 case WM_MDIGETACTIVE:
1593 if (lparam) push_data( data, (BOOL *)lparam, sizeof(BOOL) );
1594 break;
1595 case WM_NCCALCSIZE:
1596 if (!wparam)
1597 push_data( data, (RECT *)lparam, sizeof(RECT) );
1598 else
1600 NCCALCSIZE_PARAMS *ncp = (NCCALCSIZE_PARAMS *)lparam;
1601 data->ps.ncp.rgrc[0] = ncp->rgrc[0];
1602 data->ps.ncp.rgrc[1] = ncp->rgrc[1];
1603 data->ps.ncp.rgrc[2] = ncp->rgrc[2];
1604 data->ps.ncp.hwnd = wine_server_user_handle( ncp->lppos->hwnd );
1605 data->ps.ncp.hwndInsertAfter = wine_server_user_handle( ncp->lppos->hwndInsertAfter );
1606 data->ps.ncp.x = ncp->lppos->x;
1607 data->ps.ncp.y = ncp->lppos->y;
1608 data->ps.ncp.cx = ncp->lppos->cx;
1609 data->ps.ncp.cy = ncp->lppos->cy;
1610 data->ps.ncp.flags = ncp->lppos->flags;
1611 push_data( data, &data->ps.ncp, sizeof(data->ps.ncp) );
1613 break;
1614 case EM_GETSEL:
1615 case SBM_GETRANGE:
1616 case CB_GETEDITSEL:
1617 if (wparam) push_data( data, (DWORD *)wparam, sizeof(DWORD) );
1618 if (lparam) push_data( data, (DWORD *)lparam, sizeof(DWORD) );
1619 break;
1620 case WM_NEXTMENU:
1622 MDINEXTMENU *mnm = (MDINEXTMENU *)lparam;
1623 data->ps.mnm.hmenuIn = wine_server_user_handle( mnm->hmenuIn );
1624 data->ps.mnm.hmenuNext = wine_server_user_handle( mnm->hmenuNext );
1625 data->ps.mnm.hwndNext = wine_server_user_handle( mnm->hwndNext );
1626 push_data( data, &data->ps.mnm, sizeof(data->ps.mnm) );
1627 break;
1629 case WM_MDICREATE:
1631 MDICREATESTRUCTW *mcs = (MDICREATESTRUCTW *)lparam;
1632 data->ps.mcs.szClass = pack_ptr( mcs->szClass );
1633 data->ps.mcs.szTitle = pack_ptr( mcs->szTitle );
1634 data->ps.mcs.hOwner = pack_ptr( mcs->hOwner );
1635 data->ps.mcs.x = mcs->x;
1636 data->ps.mcs.y = mcs->y;
1637 data->ps.mcs.cx = mcs->cx;
1638 data->ps.mcs.cy = mcs->cy;
1639 data->ps.mcs.style = mcs->style;
1640 data->ps.mcs.lParam = mcs->lParam;
1641 push_data( data, &data->ps.mcs, sizeof(data->ps.mcs) );
1642 break;
1644 case WM_ASKCBFORMATNAME:
1645 push_data( data, (WCHAR *)lparam, (lstrlenW((WCHAR *)lparam) + 1) * sizeof(WCHAR) );
1646 break;
1651 /***********************************************************************
1652 * unpack_reply
1654 * Unpack a message reply received from another process.
1656 static void unpack_reply( HWND hwnd, UINT message, WPARAM wparam, LPARAM lparam,
1657 void *buffer, size_t size )
1659 union packed_structs *ps = buffer;
1661 switch(message)
1663 case WM_NCCREATE:
1664 case WM_CREATE:
1665 if (size >= sizeof(ps->cs))
1667 CREATESTRUCTW *cs = (CREATESTRUCTW *)lparam;
1668 cs->lpCreateParams = unpack_ptr( ps->cs.lpCreateParams );
1669 cs->hInstance = unpack_ptr( ps->cs.hInstance );
1670 cs->hMenu = wine_server_ptr_handle( ps->cs.hMenu );
1671 cs->hwndParent = wine_server_ptr_handle( ps->cs.hwndParent );
1672 cs->cy = ps->cs.cy;
1673 cs->cx = ps->cs.cx;
1674 cs->y = ps->cs.y;
1675 cs->x = ps->cs.x;
1676 cs->style = ps->cs.style;
1677 cs->dwExStyle = ps->cs.dwExStyle;
1678 /* don't allow changing name and class pointers */
1680 break;
1681 case WM_GETTEXT:
1682 case WM_ASKCBFORMATNAME:
1683 memcpy( (WCHAR *)lparam, buffer, min( wparam*sizeof(WCHAR), size ));
1684 break;
1685 case WM_GETMINMAXINFO:
1686 memcpy( (MINMAXINFO *)lparam, buffer, min( sizeof(MINMAXINFO), size ));
1687 break;
1688 case WM_MEASUREITEM:
1689 if (size >= sizeof(ps->mis))
1691 MEASUREITEMSTRUCT *mis = (MEASUREITEMSTRUCT *)lparam;
1692 mis->CtlType = ps->mis.CtlType;
1693 mis->CtlID = ps->mis.CtlID;
1694 mis->itemID = ps->mis.itemID;
1695 mis->itemWidth = ps->mis.itemWidth;
1696 mis->itemHeight = ps->mis.itemHeight;
1697 mis->itemData = (ULONG_PTR)unpack_ptr( ps->mis.itemData );
1699 break;
1700 case WM_WINDOWPOSCHANGING:
1701 case WM_WINDOWPOSCHANGED:
1702 if (size >= sizeof(ps->wp))
1704 WINDOWPOS *wp = (WINDOWPOS *)lparam;
1705 wp->hwnd = wine_server_ptr_handle( ps->wp.hwnd );
1706 wp->hwndInsertAfter = wine_server_ptr_handle( ps->wp.hwndInsertAfter );
1707 wp->x = ps->wp.x;
1708 wp->y = ps->wp.y;
1709 wp->cx = ps->wp.cx;
1710 wp->cy = ps->wp.cy;
1711 wp->flags = ps->wp.flags;
1713 break;
1714 case WM_GETDLGCODE:
1715 if (lparam && size >= sizeof(ps->msg))
1717 MSG *msg = (MSG *)lparam;
1718 msg->hwnd = wine_server_ptr_handle( ps->msg.hwnd );
1719 msg->message = ps->msg.message;
1720 msg->wParam = (ULONG_PTR)unpack_ptr( ps->msg.wParam );
1721 msg->lParam = (ULONG_PTR)unpack_ptr( ps->msg.lParam );
1722 msg->time = ps->msg.time;
1723 msg->pt = ps->msg.pt;
1725 break;
1726 case SBM_GETSCROLLINFO:
1727 memcpy( (SCROLLINFO *)lparam, buffer, min( sizeof(SCROLLINFO), size ));
1728 break;
1729 case SBM_GETSCROLLBARINFO:
1730 memcpy( (SCROLLBARINFO *)lparam, buffer, min( sizeof(SCROLLBARINFO), size ));
1731 break;
1732 case EM_GETRECT:
1733 case CB_GETDROPPEDCONTROLRECT:
1734 case LB_GETITEMRECT:
1735 case WM_SIZING:
1736 case WM_MOVING:
1737 memcpy( (RECT *)lparam, buffer, min( sizeof(RECT), size ));
1738 break;
1739 case EM_GETLINE:
1740 size = min( size, (size_t)*(WORD *)lparam );
1741 memcpy( (WCHAR *)lparam, buffer, size );
1742 break;
1743 case LB_GETSELITEMS:
1744 memcpy( (UINT *)lparam, buffer, min( wparam*sizeof(UINT), size ));
1745 break;
1746 case LB_GETTEXT:
1747 case CB_GETLBTEXT:
1748 memcpy( (WCHAR *)lparam, buffer, size );
1749 break;
1750 case WM_NEXTMENU:
1751 if (size >= sizeof(ps->mnm))
1753 MDINEXTMENU *mnm = (MDINEXTMENU *)lparam;
1754 mnm->hmenuIn = wine_server_ptr_handle( ps->mnm.hmenuIn );
1755 mnm->hmenuNext = wine_server_ptr_handle( ps->mnm.hmenuNext );
1756 mnm->hwndNext = wine_server_ptr_handle( ps->mnm.hwndNext );
1758 break;
1759 case WM_MDIGETACTIVE:
1760 if (lparam) memcpy( (BOOL *)lparam, buffer, min( sizeof(BOOL), size ));
1761 break;
1762 case WM_NCCALCSIZE:
1763 if (!wparam)
1764 memcpy( (RECT *)lparam, buffer, min( sizeof(RECT), size ));
1765 else if (size >= sizeof(ps->ncp))
1767 NCCALCSIZE_PARAMS *ncp = (NCCALCSIZE_PARAMS *)lparam;
1768 ncp->rgrc[0] = ps->ncp.rgrc[0];
1769 ncp->rgrc[1] = ps->ncp.rgrc[1];
1770 ncp->rgrc[2] = ps->ncp.rgrc[2];
1771 ncp->lppos->hwnd = wine_server_ptr_handle( ps->ncp.hwnd );
1772 ncp->lppos->hwndInsertAfter = wine_server_ptr_handle( ps->ncp.hwndInsertAfter );
1773 ncp->lppos->x = ps->ncp.x;
1774 ncp->lppos->y = ps->ncp.y;
1775 ncp->lppos->cx = ps->ncp.cx;
1776 ncp->lppos->cy = ps->ncp.cy;
1777 ncp->lppos->flags = ps->ncp.flags;
1779 break;
1780 case EM_GETSEL:
1781 case SBM_GETRANGE:
1782 case CB_GETEDITSEL:
1783 if (wparam)
1785 memcpy( (DWORD *)wparam, buffer, min( sizeof(DWORD), size ));
1786 if (size <= sizeof(DWORD)) break;
1787 size -= sizeof(DWORD);
1788 buffer = (DWORD *)buffer + 1;
1790 if (lparam) memcpy( (DWORD *)lparam, buffer, min( sizeof(DWORD), size ));
1791 break;
1792 case WM_MDICREATE:
1793 if (size >= sizeof(ps->mcs))
1795 MDICREATESTRUCTW *mcs = (MDICREATESTRUCTW *)lparam;
1796 mcs->hOwner = unpack_ptr( ps->mcs.hOwner );
1797 mcs->x = ps->mcs.x;
1798 mcs->y = ps->mcs.y;
1799 mcs->cx = ps->mcs.cx;
1800 mcs->cy = ps->mcs.cy;
1801 mcs->style = ps->mcs.style;
1802 mcs->lParam = (LPARAM)unpack_ptr( ps->mcs.lParam );
1803 /* don't allow changing class and title pointers */
1805 break;
1806 default:
1807 ERR( "should not happen: unexpected message %x\n", message );
1808 break;
1813 /***********************************************************************
1814 * reply_message
1816 * Send a reply to a sent message.
1818 static void reply_message( struct received_message_info *info, LRESULT result, BOOL remove )
1820 struct packed_message data;
1821 int i, replied = info->flags & ISMEX_REPLIED;
1823 if (info->flags & ISMEX_NOTIFY) return; /* notify messages don't get replies */
1824 if (!remove && replied) return; /* replied already */
1826 memset( &data, 0, sizeof(data) );
1827 info->flags |= ISMEX_REPLIED;
1829 if (info->type == MSG_OTHER_PROCESS && !replied)
1831 pack_reply( info->msg.hwnd, info->msg.message, info->msg.wParam,
1832 info->msg.lParam, result, &data );
1835 SERVER_START_REQ( reply_message )
1837 req->result = result;
1838 req->remove = remove;
1839 for (i = 0; i < data.count; i++) wine_server_add_data( req, data.data[i], data.size[i] );
1840 wine_server_call( req );
1842 SERVER_END_REQ;
1846 /***********************************************************************
1847 * handle_internal_message
1849 * Handle an internal Wine message instead of calling the window proc.
1851 static LRESULT handle_internal_message( HWND hwnd, UINT msg, WPARAM wparam, LPARAM lparam )
1853 switch(msg)
1855 case WM_WINE_DESTROYWINDOW:
1856 return WIN_DestroyWindow( hwnd );
1857 case WM_WINE_SETWINDOWPOS:
1858 if (is_desktop_window( hwnd )) return 0;
1859 return USER_SetWindowPos( (WINDOWPOS *)lparam, 0, 0 );
1860 case WM_WINE_SHOWWINDOW:
1861 if (is_desktop_window( hwnd )) return 0;
1862 return ShowWindow( hwnd, wparam );
1863 case WM_WINE_SETPARENT:
1864 if (is_desktop_window( hwnd )) return 0;
1865 return (LRESULT)SetParent( hwnd, (HWND)wparam );
1866 case WM_WINE_SETWINDOWLONG:
1867 return WIN_SetWindowLong( hwnd, (short)LOWORD(wparam), HIWORD(wparam), lparam, TRUE );
1868 case WM_WINE_SETSTYLE:
1869 if (is_desktop_window( hwnd )) return 0;
1870 return WIN_SetStyle(hwnd, wparam, lparam);
1871 case WM_WINE_SETACTIVEWINDOW:
1872 if (!wparam && GetForegroundWindow() == hwnd) return 0;
1873 return (LRESULT)SetActiveWindow( (HWND)wparam );
1874 case WM_WINE_KEYBOARD_LL_HOOK:
1875 case WM_WINE_MOUSE_LL_HOOK:
1877 struct hook_extra_info *h_extra = (struct hook_extra_info *)lparam;
1879 return call_current_hook( h_extra->handle, HC_ACTION, wparam, h_extra->lparam );
1881 case WM_WINE_CLIPCURSOR:
1882 if (wparam)
1884 RECT rect;
1885 GetClipCursor( &rect );
1886 return USER_Driver->pClipCursor( &rect );
1888 return USER_Driver->pClipCursor( NULL );
1889 case WM_WINE_UPDATEWINDOWSTATE:
1890 update_window_state( hwnd );
1891 return 0;
1892 default:
1893 if (msg >= WM_WINE_FIRST_DRIVER_MSG && msg <= WM_WINE_LAST_DRIVER_MSG)
1894 return USER_Driver->pWindowMessage( hwnd, msg, wparam, lparam );
1895 FIXME( "unknown internal message %x\n", msg );
1896 return 0;
1900 /* since the WM_DDE_ACK response to a WM_DDE_EXECUTE message should contain the handle
1901 * to the memory handle, we keep track (in the server side) of all pairs of handle
1902 * used (the client passes its value and the content of the memory handle), and
1903 * the server stored both values (the client, and the local one, created after the
1904 * content). When a ACK message is generated, the list of pair is searched for a
1905 * matching pair, so that the client memory handle can be returned.
1907 struct DDE_pair {
1908 HGLOBAL client_hMem;
1909 HGLOBAL server_hMem;
1912 static struct DDE_pair* dde_pairs;
1913 static int dde_num_alloc;
1914 static int dde_num_used;
1916 static CRITICAL_SECTION dde_crst;
1917 static CRITICAL_SECTION_DEBUG critsect_debug =
1919 0, 0, &dde_crst,
1920 { &critsect_debug.ProcessLocksList, &critsect_debug.ProcessLocksList },
1921 0, 0, { (DWORD_PTR)(__FILE__ ": dde_crst") }
1923 static CRITICAL_SECTION dde_crst = { &critsect_debug, -1, 0, 0, 0, 0 };
1925 static BOOL dde_add_pair(HGLOBAL chm, HGLOBAL shm)
1927 int i;
1928 #define GROWBY 4
1930 EnterCriticalSection(&dde_crst);
1932 /* now remember the pair of hMem on both sides */
1933 if (dde_num_used == dde_num_alloc)
1935 struct DDE_pair* tmp;
1936 if (dde_pairs)
1937 tmp = HeapReAlloc( GetProcessHeap(), 0, dde_pairs,
1938 (dde_num_alloc + GROWBY) * sizeof(struct DDE_pair));
1939 else
1940 tmp = HeapAlloc( GetProcessHeap(), 0,
1941 (dde_num_alloc + GROWBY) * sizeof(struct DDE_pair));
1943 if (!tmp)
1945 LeaveCriticalSection(&dde_crst);
1946 return FALSE;
1948 dde_pairs = tmp;
1949 /* zero out newly allocated part */
1950 memset(&dde_pairs[dde_num_alloc], 0, GROWBY * sizeof(struct DDE_pair));
1951 dde_num_alloc += GROWBY;
1953 #undef GROWBY
1954 for (i = 0; i < dde_num_alloc; i++)
1956 if (dde_pairs[i].server_hMem == 0)
1958 dde_pairs[i].client_hMem = chm;
1959 dde_pairs[i].server_hMem = shm;
1960 dde_num_used++;
1961 break;
1964 LeaveCriticalSection(&dde_crst);
1965 return TRUE;
1968 static HGLOBAL dde_get_pair(HGLOBAL shm)
1970 int i;
1971 HGLOBAL ret = 0;
1973 EnterCriticalSection(&dde_crst);
1974 for (i = 0; i < dde_num_alloc; i++)
1976 if (dde_pairs[i].server_hMem == shm)
1978 /* free this pair */
1979 dde_pairs[i].server_hMem = 0;
1980 dde_num_used--;
1981 ret = dde_pairs[i].client_hMem;
1982 break;
1985 LeaveCriticalSection(&dde_crst);
1986 return ret;
1989 /***********************************************************************
1990 * post_dde_message
1992 * Post a DDE message
1994 static BOOL post_dde_message( struct packed_message *data, const struct send_message_info *info )
1996 void* ptr = NULL;
1997 int size = 0;
1998 UINT_PTR uiLo, uiHi;
1999 LPARAM lp;
2000 HGLOBAL hunlock = 0;
2001 int i;
2002 DWORD res;
2003 ULONGLONG hpack;
2005 if (!UnpackDDElParam( info->msg, info->lparam, &uiLo, &uiHi ))
2006 return FALSE;
2008 lp = info->lparam;
2009 switch (info->msg)
2011 /* DDE messages which don't require packing are:
2012 * WM_DDE_INITIATE
2013 * WM_DDE_TERMINATE
2014 * WM_DDE_REQUEST
2015 * WM_DDE_UNADVISE
2017 case WM_DDE_ACK:
2018 if (HIWORD(uiHi))
2020 /* uiHi should contain a hMem from WM_DDE_EXECUTE */
2021 HGLOBAL h = dde_get_pair( (HANDLE)uiHi );
2022 if (h)
2024 hpack = pack_ptr( h );
2025 /* send back the value of h on the other side */
2026 push_data( data, &hpack, sizeof(hpack) );
2027 lp = uiLo;
2028 TRACE( "send dde-ack %lx %08lx => %p\n", uiLo, uiHi, h );
2031 else
2033 /* uiHi should contain either an atom or 0 */
2034 TRACE( "send dde-ack %lx atom=%lx\n", uiLo, uiHi );
2035 lp = MAKELONG( uiLo, uiHi );
2037 break;
2038 case WM_DDE_ADVISE:
2039 case WM_DDE_DATA:
2040 case WM_DDE_POKE:
2041 size = 0;
2042 if (uiLo)
2044 size = GlobalSize( (HGLOBAL)uiLo ) ;
2045 if ((info->msg == WM_DDE_ADVISE && size < sizeof(DDEADVISE)) ||
2046 (info->msg == WM_DDE_DATA && size < FIELD_OFFSET(DDEDATA, Value)) ||
2047 (info->msg == WM_DDE_POKE && size < FIELD_OFFSET(DDEPOKE, Value))
2049 return FALSE;
2051 else if (info->msg != WM_DDE_DATA) return FALSE;
2053 lp = uiHi;
2054 if (uiLo)
2056 if ((ptr = GlobalLock( (HGLOBAL)uiLo) ))
2058 DDEDATA *dde_data = ptr;
2059 TRACE("unused %d, fResponse %d, fRelease %d, fDeferUpd %d, fAckReq %d, cfFormat %d\n",
2060 dde_data->unused, dde_data->fResponse, dde_data->fRelease,
2061 dde_data->reserved, dde_data->fAckReq, dde_data->cfFormat);
2062 push_data( data, ptr, size );
2063 hunlock = (HGLOBAL)uiLo;
2066 TRACE( "send ddepack %u %lx\n", size, uiHi );
2067 break;
2068 case WM_DDE_EXECUTE:
2069 if (info->lparam)
2071 if ((ptr = GlobalLock( (HGLOBAL)info->lparam) ))
2073 push_data(data, ptr, GlobalSize( (HGLOBAL)info->lparam ));
2074 /* so that the other side can send it back on ACK */
2075 lp = info->lparam;
2076 hunlock = (HGLOBAL)info->lparam;
2079 break;
2081 SERVER_START_REQ( send_message )
2083 req->id = info->dest_tid;
2084 req->type = info->type;
2085 req->flags = 0;
2086 req->win = wine_server_user_handle( info->hwnd );
2087 req->msg = info->msg;
2088 req->wparam = info->wparam;
2089 req->lparam = lp;
2090 req->timeout = TIMEOUT_INFINITE;
2091 for (i = 0; i < data->count; i++)
2092 wine_server_add_data( req, data->data[i], data->size[i] );
2093 if ((res = wine_server_call( req )))
2095 if (res == STATUS_INVALID_PARAMETER)
2096 /* FIXME: find a STATUS_ value for this one */
2097 SetLastError( ERROR_INVALID_THREAD_ID );
2098 else
2099 SetLastError( RtlNtStatusToDosError(res) );
2101 else
2102 FreeDDElParam(info->msg, info->lparam);
2104 SERVER_END_REQ;
2105 if (hunlock) GlobalUnlock(hunlock);
2107 return !res;
2110 /***********************************************************************
2111 * unpack_dde_message
2113 * Unpack a posted DDE message received from another process.
2115 static BOOL unpack_dde_message( HWND hwnd, UINT message, WPARAM *wparam, LPARAM *lparam,
2116 void **buffer, size_t size )
2118 UINT_PTR uiLo, uiHi;
2119 HGLOBAL hMem = 0;
2120 void* ptr;
2122 switch (message)
2124 case WM_DDE_ACK:
2125 if (size)
2127 ULONGLONG hpack;
2128 /* hMem is being passed */
2129 if (size != sizeof(hpack)) return FALSE;
2130 if (!buffer || !*buffer) return FALSE;
2131 uiLo = *lparam;
2132 memcpy( &hpack, *buffer, size );
2133 hMem = unpack_ptr( hpack );
2134 uiHi = (UINT_PTR)hMem;
2135 TRACE("recv dde-ack %lx mem=%lx[%lx]\n", uiLo, uiHi, GlobalSize( hMem ));
2137 else
2139 uiLo = LOWORD( *lparam );
2140 uiHi = HIWORD( *lparam );
2141 TRACE("recv dde-ack %lx atom=%lx\n", uiLo, uiHi);
2143 *lparam = PackDDElParam( WM_DDE_ACK, uiLo, uiHi );
2144 break;
2145 case WM_DDE_ADVISE:
2146 case WM_DDE_DATA:
2147 case WM_DDE_POKE:
2148 if ((!buffer || !*buffer) && message != WM_DDE_DATA) return FALSE;
2149 uiHi = *lparam;
2150 if (size)
2152 if (!(hMem = GlobalAlloc( GMEM_MOVEABLE|GMEM_DDESHARE, size )))
2153 return FALSE;
2154 if ((ptr = GlobalLock( hMem )))
2156 memcpy( ptr, *buffer, size );
2157 GlobalUnlock( hMem );
2159 else
2161 GlobalFree( hMem );
2162 return FALSE;
2165 uiLo = (UINT_PTR)hMem;
2167 *lparam = PackDDElParam( message, uiLo, uiHi );
2168 break;
2169 case WM_DDE_EXECUTE:
2170 if (size)
2172 if (!buffer || !*buffer) return FALSE;
2173 if (!(hMem = GlobalAlloc( GMEM_MOVEABLE|GMEM_DDESHARE, size ))) return FALSE;
2174 if ((ptr = GlobalLock( hMem )))
2176 memcpy( ptr, *buffer, size );
2177 GlobalUnlock( hMem );
2178 TRACE( "exec: pairing c=%08lx s=%p\n", *lparam, hMem );
2179 if (!dde_add_pair( (HGLOBAL)*lparam, hMem ))
2181 GlobalFree( hMem );
2182 return FALSE;
2185 else
2187 GlobalFree( hMem );
2188 return FALSE;
2190 } else return FALSE;
2191 *lparam = (LPARAM)hMem;
2192 break;
2194 return TRUE;
2197 /***********************************************************************
2198 * call_window_proc
2200 * Call a window procedure and the corresponding hooks.
2202 static LRESULT call_window_proc( HWND hwnd, UINT msg, WPARAM wparam, LPARAM lparam,
2203 BOOL unicode, BOOL same_thread, enum wm_char_mapping mapping )
2205 LRESULT result = 0;
2206 CWPSTRUCT cwp;
2207 CWPRETSTRUCT cwpret;
2209 if (msg & 0x80000000)
2211 result = handle_internal_message( hwnd, msg, wparam, lparam );
2212 goto done;
2215 /* first the WH_CALLWNDPROC hook */
2216 hwnd = WIN_GetFullHandle( hwnd );
2217 cwp.lParam = lparam;
2218 cwp.wParam = wparam;
2219 cwp.message = msg;
2220 cwp.hwnd = hwnd;
2221 HOOK_CallHooks( WH_CALLWNDPROC, HC_ACTION, same_thread, (LPARAM)&cwp, unicode );
2223 /* now call the window procedure */
2224 if (!WINPROC_call_window( hwnd, msg, wparam, lparam, &result, unicode, mapping )) goto done;
2226 /* and finally the WH_CALLWNDPROCRET hook */
2227 cwpret.lResult = result;
2228 cwpret.lParam = lparam;
2229 cwpret.wParam = wparam;
2230 cwpret.message = msg;
2231 cwpret.hwnd = hwnd;
2232 HOOK_CallHooks( WH_CALLWNDPROCRET, HC_ACTION, same_thread, (LPARAM)&cwpret, unicode );
2233 done:
2234 return result;
2238 /***********************************************************************
2239 * send_parent_notify
2241 * Send a WM_PARENTNOTIFY to all ancestors of the given window, unless
2242 * the window has the WS_EX_NOPARENTNOTIFY style.
2244 static void send_parent_notify( HWND hwnd, WORD event, WORD idChild, POINT pt )
2246 /* pt has to be in the client coordinates of the parent window */
2247 MapWindowPoints( 0, hwnd, &pt, 1 );
2248 for (;;)
2250 HWND parent;
2252 if (!(GetWindowLongW( hwnd, GWL_STYLE ) & WS_CHILD)) break;
2253 if (GetWindowLongW( hwnd, GWL_EXSTYLE ) & WS_EX_NOPARENTNOTIFY) break;
2254 if (!(parent = GetParent(hwnd))) break;
2255 if (parent == GetDesktopWindow()) break;
2256 MapWindowPoints( hwnd, parent, &pt, 1 );
2257 hwnd = parent;
2258 SendMessageW( hwnd, WM_PARENTNOTIFY,
2259 MAKEWPARAM( event, idChild ), MAKELPARAM( pt.x, pt.y ) );
2264 /***********************************************************************
2265 * accept_hardware_message
2267 * Tell the server we have passed the message to the app
2268 * (even though we may end up dropping it later on)
2270 static void accept_hardware_message( UINT hw_id )
2272 SERVER_START_REQ( accept_hardware_message )
2274 req->hw_id = hw_id;
2275 if (wine_server_call( req ))
2276 FIXME("Failed to reply to MSG_HARDWARE message. Message may not be removed from queue.\n");
2278 SERVER_END_REQ;
2282 static BOOL process_rawinput_message( MSG *msg, UINT hw_id, const struct hardware_msg_data *msg_data )
2284 struct rawinput_thread_data *thread_data = rawinput_thread_data();
2285 if (!rawinput_from_hardware_message( thread_data->buffer, msg_data ))
2286 return FALSE;
2288 thread_data->hw_id = hw_id;
2289 msg->lParam = (LPARAM)hw_id;
2290 msg->pt = point_phys_to_win_dpi( msg->hwnd, msg->pt );
2291 return TRUE;
2294 /***********************************************************************
2295 * process_keyboard_message
2297 * returns TRUE if the contents of 'msg' should be passed to the application
2299 static BOOL process_keyboard_message( MSG *msg, UINT hw_id, HWND hwnd_filter,
2300 UINT first, UINT last, BOOL remove )
2302 EVENTMSG event;
2304 if (msg->message == WM_KEYDOWN || msg->message == WM_SYSKEYDOWN ||
2305 msg->message == WM_KEYUP || msg->message == WM_SYSKEYUP)
2306 switch (msg->wParam)
2308 case VK_LSHIFT: case VK_RSHIFT:
2309 msg->wParam = VK_SHIFT;
2310 break;
2311 case VK_LCONTROL: case VK_RCONTROL:
2312 msg->wParam = VK_CONTROL;
2313 break;
2314 case VK_LMENU: case VK_RMENU:
2315 msg->wParam = VK_MENU;
2316 break;
2319 /* FIXME: is this really the right place for this hook? */
2320 event.message = msg->message;
2321 event.hwnd = msg->hwnd;
2322 event.time = msg->time;
2323 event.paramL = (msg->wParam & 0xFF) | (HIWORD(msg->lParam) << 8);
2324 event.paramH = msg->lParam & 0x7FFF;
2325 if (HIWORD(msg->lParam) & 0x0100) event.paramH |= 0x8000; /* special_key - bit */
2326 HOOK_CallHooks( WH_JOURNALRECORD, HC_ACTION, 0, (LPARAM)&event, TRUE );
2328 /* check message filters */
2329 if (msg->message < first || msg->message > last) return FALSE;
2330 if (!check_hwnd_filter( msg, hwnd_filter )) return FALSE;
2332 if (remove)
2334 if((msg->message == WM_KEYDOWN) &&
2335 (msg->hwnd != GetDesktopWindow()))
2337 /* Handle F1 key by sending out WM_HELP message */
2338 if (msg->wParam == VK_F1)
2340 PostMessageW( msg->hwnd, WM_KEYF1, 0, 0 );
2342 else if(msg->wParam >= VK_BROWSER_BACK &&
2343 msg->wParam <= VK_LAUNCH_APP2)
2345 /* FIXME: Process keystate */
2346 SendMessageW(msg->hwnd, WM_APPCOMMAND, (WPARAM)msg->hwnd, MAKELPARAM(0, (FAPPCOMMAND_KEY | (msg->wParam - VK_BROWSER_BACK + 1))));
2349 else if (msg->message == WM_KEYUP)
2351 /* Handle VK_APPS key by posting a WM_CONTEXTMENU message */
2352 if (msg->wParam == VK_APPS && !MENU_IsMenuActive())
2353 PostMessageW(msg->hwnd, WM_CONTEXTMENU, (WPARAM)msg->hwnd, -1);
2357 if (HOOK_CallHooks( WH_KEYBOARD, remove ? HC_ACTION : HC_NOREMOVE,
2358 LOWORD(msg->wParam), msg->lParam, TRUE ))
2360 /* skip this message */
2361 HOOK_CallHooks( WH_CBT, HCBT_KEYSKIPPED, LOWORD(msg->wParam), msg->lParam, TRUE );
2362 accept_hardware_message( hw_id );
2363 return FALSE;
2365 if (remove) accept_hardware_message( hw_id );
2366 msg->pt = point_phys_to_win_dpi( msg->hwnd, msg->pt );
2368 if ( remove && msg->message == WM_KEYDOWN )
2369 if (ImmProcessKey(msg->hwnd, GetKeyboardLayout(0), msg->wParam, msg->lParam, 0) )
2370 msg->wParam = VK_PROCESSKEY;
2372 return TRUE;
2376 /***********************************************************************
2377 * process_mouse_message
2379 * returns TRUE if the contents of 'msg' should be passed to the application
2381 static BOOL process_mouse_message( MSG *msg, UINT hw_id, ULONG_PTR extra_info, HWND hwnd_filter,
2382 UINT first, UINT last, BOOL remove )
2384 static MSG clk_msg;
2386 POINT pt;
2387 UINT message;
2388 INT hittest;
2389 EVENTMSG event;
2390 GUITHREADINFO info;
2391 MOUSEHOOKSTRUCTEX hook;
2392 BOOL eatMsg;
2393 WPARAM wparam;
2395 /* find the window to dispatch this mouse message to */
2397 info.cbSize = sizeof(info);
2398 GetGUIThreadInfo( GetCurrentThreadId(), &info );
2399 if (info.hwndCapture)
2401 hittest = HTCLIENT;
2402 msg->hwnd = info.hwndCapture;
2404 else
2406 HWND orig = msg->hwnd;
2408 msg->hwnd = WINPOS_WindowFromPoint( msg->hwnd, msg->pt, &hittest );
2409 if (!msg->hwnd) /* As a heuristic, try the next window if it's the owner of orig */
2411 HWND next = GetWindow( orig, GW_HWNDNEXT );
2413 if (next && GetWindow( orig, GW_OWNER ) == next && WIN_IsCurrentThread( next ))
2414 msg->hwnd = WINPOS_WindowFromPoint( next, msg->pt, &hittest );
2418 if (!msg->hwnd || !WIN_IsCurrentThread( msg->hwnd ))
2420 accept_hardware_message( hw_id );
2421 return FALSE;
2424 msg->pt = point_phys_to_win_dpi( msg->hwnd, msg->pt );
2425 SetThreadDpiAwarenessContext( GetWindowDpiAwarenessContext( msg->hwnd ));
2427 /* FIXME: is this really the right place for this hook? */
2428 event.message = msg->message;
2429 event.time = msg->time;
2430 event.hwnd = msg->hwnd;
2431 event.paramL = msg->pt.x;
2432 event.paramH = msg->pt.y;
2433 HOOK_CallHooks( WH_JOURNALRECORD, HC_ACTION, 0, (LPARAM)&event, TRUE );
2435 if (!check_hwnd_filter( msg, hwnd_filter )) return FALSE;
2437 pt = msg->pt;
2438 message = msg->message;
2439 wparam = msg->wParam;
2440 /* Note: windows has no concept of a non-client wheel message */
2441 if (message != WM_MOUSEWHEEL)
2443 if (hittest != HTCLIENT)
2445 message += WM_NCMOUSEMOVE - WM_MOUSEMOVE;
2446 wparam = hittest;
2448 else
2450 /* coordinates don't get translated while tracking a menu */
2451 /* FIXME: should differentiate popups and top-level menus */
2452 if (!(info.flags & GUI_INMENUMODE))
2453 ScreenToClient( msg->hwnd, &pt );
2456 msg->lParam = MAKELONG( pt.x, pt.y );
2458 /* translate double clicks */
2460 if ((msg->message == WM_LBUTTONDOWN) ||
2461 (msg->message == WM_RBUTTONDOWN) ||
2462 (msg->message == WM_MBUTTONDOWN) ||
2463 (msg->message == WM_XBUTTONDOWN))
2465 BOOL update = remove;
2467 /* translate double clicks -
2468 * note that ...MOUSEMOVEs can slip in between
2469 * ...BUTTONDOWN and ...BUTTONDBLCLK messages */
2471 if ((info.flags & (GUI_INMENUMODE|GUI_INMOVESIZE)) ||
2472 hittest != HTCLIENT ||
2473 (GetClassLongA( msg->hwnd, GCL_STYLE ) & CS_DBLCLKS))
2475 if ((msg->message == clk_msg.message) &&
2476 (msg->hwnd == clk_msg.hwnd) &&
2477 (msg->wParam == clk_msg.wParam) &&
2478 (msg->time - clk_msg.time < GetDoubleClickTime()) &&
2479 (abs(msg->pt.x - clk_msg.pt.x) < GetSystemMetrics(SM_CXDOUBLECLK)/2) &&
2480 (abs(msg->pt.y - clk_msg.pt.y) < GetSystemMetrics(SM_CYDOUBLECLK)/2))
2482 message += (WM_LBUTTONDBLCLK - WM_LBUTTONDOWN);
2483 if (update)
2485 clk_msg.message = 0; /* clear the double click conditions */
2486 update = FALSE;
2490 if (message < first || message > last) return FALSE;
2491 /* update static double click conditions */
2492 if (update) clk_msg = *msg;
2494 else
2496 if (message < first || message > last) return FALSE;
2498 msg->wParam = wparam;
2500 /* message is accepted now (but may still get dropped) */
2502 hook.s.pt = msg->pt;
2503 hook.s.hwnd = msg->hwnd;
2504 hook.s.wHitTestCode = hittest;
2505 hook.s.dwExtraInfo = extra_info;
2506 hook.mouseData = msg->wParam;
2507 if (HOOK_CallHooks( WH_MOUSE, remove ? HC_ACTION : HC_NOREMOVE,
2508 message, (LPARAM)&hook, TRUE ))
2510 hook.s.pt = msg->pt;
2511 hook.s.hwnd = msg->hwnd;
2512 hook.s.wHitTestCode = hittest;
2513 hook.s.dwExtraInfo = extra_info;
2514 hook.mouseData = msg->wParam;
2515 HOOK_CallHooks( WH_CBT, HCBT_CLICKSKIPPED, message, (LPARAM)&hook, TRUE );
2516 accept_hardware_message( hw_id );
2517 return FALSE;
2520 if ((hittest == HTERROR) || (hittest == HTNOWHERE))
2522 SendMessageW( msg->hwnd, WM_SETCURSOR, (WPARAM)msg->hwnd,
2523 MAKELONG( hittest, msg->message ));
2524 accept_hardware_message( hw_id );
2525 return FALSE;
2528 if (remove) accept_hardware_message( hw_id );
2530 if (!remove || info.hwndCapture)
2532 msg->message = message;
2533 return TRUE;
2536 eatMsg = FALSE;
2538 if ((msg->message == WM_LBUTTONDOWN) ||
2539 (msg->message == WM_RBUTTONDOWN) ||
2540 (msg->message == WM_MBUTTONDOWN) ||
2541 (msg->message == WM_XBUTTONDOWN))
2543 /* Send the WM_PARENTNOTIFY,
2544 * note that even for double/nonclient clicks
2545 * notification message is still WM_L/M/RBUTTONDOWN.
2547 send_parent_notify( msg->hwnd, msg->message, 0, msg->pt );
2549 /* Activate the window if needed */
2551 if (msg->hwnd != info.hwndActive)
2553 HWND hwndTop = GetAncestor( msg->hwnd, GA_ROOT );
2555 if ((GetWindowLongW( hwndTop, GWL_STYLE ) & (WS_POPUP|WS_CHILD)) != WS_CHILD)
2557 LONG ret = SendMessageW( msg->hwnd, WM_MOUSEACTIVATE, (WPARAM)hwndTop,
2558 MAKELONG( hittest, msg->message ) );
2559 switch(ret)
2561 case MA_NOACTIVATEANDEAT:
2562 eatMsg = TRUE;
2563 /* fall through */
2564 case MA_NOACTIVATE:
2565 break;
2566 case MA_ACTIVATEANDEAT:
2567 eatMsg = TRUE;
2568 /* fall through */
2569 case MA_ACTIVATE:
2570 case 0:
2571 if (!FOCUS_MouseActivate( hwndTop )) eatMsg = TRUE;
2572 break;
2573 default:
2574 WARN( "unknown WM_MOUSEACTIVATE code %d\n", ret );
2575 break;
2581 /* send the WM_SETCURSOR message */
2583 /* Windows sends the normal mouse message as the message parameter
2584 in the WM_SETCURSOR message even if it's non-client mouse message */
2585 SendMessageW( msg->hwnd, WM_SETCURSOR, (WPARAM)msg->hwnd, MAKELONG( hittest, msg->message ));
2587 msg->message = message;
2588 return !eatMsg;
2592 /***********************************************************************
2593 * process_hardware_message
2595 * Process a hardware message; return TRUE if message should be passed on to the app
2597 static BOOL process_hardware_message( MSG *msg, UINT hw_id, const struct hardware_msg_data *msg_data,
2598 HWND hwnd_filter, UINT first, UINT last, BOOL remove )
2600 DPI_AWARENESS_CONTEXT context;
2601 BOOL ret = FALSE;
2603 get_user_thread_info()->msg_source.deviceType = msg_data->source.device;
2604 get_user_thread_info()->msg_source.originId = msg_data->source.origin;
2606 /* hardware messages are always in physical coords */
2607 context = SetThreadDpiAwarenessContext( DPI_AWARENESS_CONTEXT_PER_MONITOR_AWARE );
2609 if (msg->message == WM_INPUT)
2610 ret = process_rawinput_message( msg, hw_id, msg_data );
2611 else if (is_keyboard_message( msg->message ))
2612 ret = process_keyboard_message( msg, hw_id, hwnd_filter, first, last, remove );
2613 else if (is_mouse_message( msg->message ))
2614 ret = process_mouse_message( msg, hw_id, msg_data->info, hwnd_filter, first, last, remove );
2615 else
2616 ERR( "unknown message type %x\n", msg->message );
2617 SetThreadDpiAwarenessContext( context );
2618 return ret;
2622 /***********************************************************************
2623 * call_sendmsg_callback
2625 * Call the callback function of SendMessageCallback.
2627 static inline void call_sendmsg_callback( SENDASYNCPROC callback, HWND hwnd, UINT msg,
2628 ULONG_PTR data, LRESULT result )
2630 if (!callback) return;
2632 TRACE_(relay)( "\1Call message callback %p (hwnd=%p,msg=%s,data=%08lx,result=%08lx)\n",
2633 callback, hwnd, SPY_GetMsgName( msg, hwnd ), data, result );
2634 callback( hwnd, msg, data, result );
2635 TRACE_(relay)( "\1Ret message callback %p (hwnd=%p,msg=%s,data=%08lx,result=%08lx)\n",
2636 callback, hwnd, SPY_GetMsgName( msg, hwnd ), data, result );
2640 /***********************************************************************
2641 * peek_message
2643 * Peek for a message matching the given parameters. Return 0 if none are
2644 * available; -1 on error.
2645 * All pending sent messages are processed before returning.
2647 static int peek_message( MSG *msg, HWND hwnd, UINT first, UINT last, UINT flags, UINT changed_mask )
2649 LRESULT result;
2650 struct user_thread_info *thread_info = get_user_thread_info();
2651 INPUT_MESSAGE_SOURCE prev_source = thread_info->msg_source;
2652 struct received_message_info info, *old_info;
2653 unsigned int hw_id = 0; /* id of previous hardware message */
2654 void *buffer;
2655 size_t buffer_size = 256;
2657 if (!(buffer = HeapAlloc( GetProcessHeap(), 0, buffer_size ))) return -1;
2659 if (!first && !last) last = ~0;
2660 if (hwnd == HWND_BROADCAST) hwnd = HWND_TOPMOST;
2662 for (;;)
2664 NTSTATUS res;
2665 size_t size = 0;
2666 const message_data_t *msg_data = buffer;
2668 thread_info->msg_source = prev_source;
2670 SERVER_START_REQ( get_message )
2672 req->flags = flags;
2673 req->get_win = wine_server_user_handle( hwnd );
2674 req->get_first = first;
2675 req->get_last = last;
2676 req->hw_id = hw_id;
2677 req->wake_mask = changed_mask & (QS_SENDMESSAGE | QS_SMRESULT);
2678 req->changed_mask = changed_mask;
2679 wine_server_set_reply( req, buffer, buffer_size );
2680 if (!(res = wine_server_call( req )))
2682 size = wine_server_reply_size( reply );
2683 info.type = reply->type;
2684 info.msg.hwnd = wine_server_ptr_handle( reply->win );
2685 info.msg.message = reply->msg;
2686 info.msg.wParam = reply->wparam;
2687 info.msg.lParam = reply->lparam;
2688 info.msg.time = reply->time;
2689 info.msg.pt.x = reply->x;
2690 info.msg.pt.y = reply->y;
2691 hw_id = 0;
2692 thread_info->active_hooks = reply->active_hooks;
2694 else buffer_size = reply->total;
2696 SERVER_END_REQ;
2698 if (res)
2700 HeapFree( GetProcessHeap(), 0, buffer );
2701 if (res == STATUS_PENDING)
2703 thread_info->wake_mask = changed_mask & (QS_SENDMESSAGE | QS_SMRESULT);
2704 thread_info->changed_mask = changed_mask;
2705 return 0;
2707 if (res != STATUS_BUFFER_OVERFLOW)
2709 SetLastError( RtlNtStatusToDosError(res) );
2710 return -1;
2712 if (!(buffer = HeapAlloc( GetProcessHeap(), 0, buffer_size ))) return -1;
2713 continue;
2716 TRACE( "got type %d msg %x (%s) hwnd %p wp %lx lp %lx\n",
2717 info.type, info.msg.message,
2718 (info.type == MSG_WINEVENT) ? "MSG_WINEVENT" : SPY_GetMsgName(info.msg.message, info.msg.hwnd),
2719 info.msg.hwnd, info.msg.wParam, info.msg.lParam );
2721 switch(info.type)
2723 case MSG_ASCII:
2724 case MSG_UNICODE:
2725 info.flags = ISMEX_SEND;
2726 break;
2727 case MSG_NOTIFY:
2728 info.flags = ISMEX_NOTIFY;
2729 if (!unpack_message( info.msg.hwnd, info.msg.message, &info.msg.wParam,
2730 &info.msg.lParam, &buffer, size ))
2731 continue;
2732 break;
2733 case MSG_CALLBACK:
2734 info.flags = ISMEX_CALLBACK;
2735 break;
2736 case MSG_CALLBACK_RESULT:
2737 if (size >= sizeof(msg_data->callback))
2738 call_sendmsg_callback( wine_server_get_ptr(msg_data->callback.callback),
2739 info.msg.hwnd, info.msg.message,
2740 msg_data->callback.data, msg_data->callback.result );
2741 continue;
2742 case MSG_WINEVENT:
2743 if (size >= sizeof(msg_data->winevent))
2745 WINEVENTPROC hook_proc;
2746 HMODULE free_module = 0;
2748 hook_proc = wine_server_get_ptr( msg_data->winevent.hook_proc );
2749 size -= sizeof(msg_data->winevent);
2750 if (size)
2752 WCHAR module[MAX_PATH];
2754 size = min( size, (MAX_PATH - 1) * sizeof(WCHAR) );
2755 memcpy( module, &msg_data->winevent + 1, size );
2756 module[size / sizeof(WCHAR)] = 0;
2757 if (!(hook_proc = get_hook_proc( hook_proc, module, &free_module )))
2759 ERR( "invalid winevent hook module name %s\n", debugstr_w(module) );
2760 continue;
2764 TRACE_(relay)( "\1Call winevent proc %p (hook=%04x,event=%x,hwnd=%p,object_id=%lx,child_id=%lx,tid=%04x,time=%x)\n",
2765 hook_proc, msg_data->winevent.hook, info.msg.message, info.msg.hwnd,
2766 info.msg.wParam, info.msg.lParam, msg_data->winevent.tid, info.msg.time);
2768 hook_proc( wine_server_ptr_handle( msg_data->winevent.hook ), info.msg.message,
2769 info.msg.hwnd, info.msg.wParam, info.msg.lParam,
2770 msg_data->winevent.tid, info.msg.time );
2772 TRACE_(relay)( "\1Ret winevent proc %p (hook=%04x,event=%x,hwnd=%p,object_id=%lx,child_id=%lx,tid=%04x,time=%x)\n",
2773 hook_proc, msg_data->winevent.hook, info.msg.message, info.msg.hwnd,
2774 info.msg.wParam, info.msg.lParam, msg_data->winevent.tid, info.msg.time);
2776 if (free_module) FreeLibrary(free_module);
2778 continue;
2779 case MSG_HOOK_LL:
2780 info.flags = ISMEX_SEND;
2781 result = 0;
2782 if (info.msg.message == WH_KEYBOARD_LL && size >= sizeof(msg_data->hardware))
2784 KBDLLHOOKSTRUCT hook;
2786 hook.vkCode = LOWORD( info.msg.lParam );
2787 hook.scanCode = HIWORD( info.msg.lParam );
2788 hook.flags = msg_data->hardware.flags;
2789 hook.time = info.msg.time;
2790 hook.dwExtraInfo = msg_data->hardware.info;
2791 TRACE( "calling keyboard LL hook vk %x scan %x flags %x time %u info %lx\n",
2792 hook.vkCode, hook.scanCode, hook.flags, hook.time, hook.dwExtraInfo );
2793 result = HOOK_CallHooks( WH_KEYBOARD_LL, HC_ACTION, info.msg.wParam, (LPARAM)&hook, TRUE );
2795 else if (info.msg.message == WH_MOUSE_LL && size >= sizeof(msg_data->hardware))
2797 MSLLHOOKSTRUCT hook;
2799 hook.pt = info.msg.pt;
2800 hook.mouseData = info.msg.lParam;
2801 hook.flags = msg_data->hardware.flags;
2802 hook.time = info.msg.time;
2803 hook.dwExtraInfo = msg_data->hardware.info;
2804 TRACE( "calling mouse LL hook pos %d,%d data %x flags %x time %u info %lx\n",
2805 hook.pt.x, hook.pt.y, hook.mouseData, hook.flags, hook.time, hook.dwExtraInfo );
2806 result = HOOK_CallHooks( WH_MOUSE_LL, HC_ACTION, info.msg.wParam, (LPARAM)&hook, TRUE );
2808 reply_message( &info, result, TRUE );
2809 continue;
2810 case MSG_OTHER_PROCESS:
2811 info.flags = ISMEX_SEND;
2812 if (!unpack_message( info.msg.hwnd, info.msg.message, &info.msg.wParam,
2813 &info.msg.lParam, &buffer, size ))
2815 /* ignore it */
2816 reply_message( &info, 0, TRUE );
2817 continue;
2819 break;
2820 case MSG_HARDWARE:
2821 if (size >= sizeof(msg_data->hardware))
2823 hw_id = msg_data->hardware.hw_id;
2824 if (!process_hardware_message( &info.msg, hw_id, &msg_data->hardware,
2825 hwnd, first, last, flags & PM_REMOVE ))
2827 TRACE("dropping msg %x\n", info.msg.message );
2828 continue; /* ignore it */
2830 *msg = info.msg;
2831 thread_info->GetMessagePosVal = MAKELONG( info.msg.pt.x, info.msg.pt.y );
2832 thread_info->GetMessageTimeVal = info.msg.time;
2833 thread_info->GetMessageExtraInfoVal = msg_data->hardware.info;
2834 HeapFree( GetProcessHeap(), 0, buffer );
2835 HOOK_CallHooks( WH_GETMESSAGE, HC_ACTION, flags & PM_REMOVE, (LPARAM)msg, TRUE );
2836 return 1;
2838 continue;
2839 case MSG_POSTED:
2840 if (info.msg.message & 0x80000000) /* internal message */
2842 if (flags & PM_REMOVE)
2844 handle_internal_message( info.msg.hwnd, info.msg.message,
2845 info.msg.wParam, info.msg.lParam );
2846 /* if this is a nested call return right away */
2847 if (first == info.msg.message && last == info.msg.message)
2849 HeapFree( GetProcessHeap(), 0, buffer );
2850 return 0;
2853 else
2854 peek_message( msg, info.msg.hwnd, info.msg.message,
2855 info.msg.message, flags | PM_REMOVE, changed_mask );
2856 continue;
2858 if (info.msg.message >= WM_DDE_FIRST && info.msg.message <= WM_DDE_LAST)
2860 if (!unpack_dde_message( info.msg.hwnd, info.msg.message, &info.msg.wParam,
2861 &info.msg.lParam, &buffer, size ))
2862 continue; /* ignore it */
2864 *msg = info.msg;
2865 msg->pt = point_phys_to_win_dpi( info.msg.hwnd, info.msg.pt );
2866 thread_info->GetMessagePosVal = MAKELONG( msg->pt.x, msg->pt.y );
2867 thread_info->GetMessageTimeVal = info.msg.time;
2868 thread_info->GetMessageExtraInfoVal = 0;
2869 thread_info->msg_source = msg_source_unavailable;
2870 HeapFree( GetProcessHeap(), 0, buffer );
2871 HOOK_CallHooks( WH_GETMESSAGE, HC_ACTION, flags & PM_REMOVE, (LPARAM)msg, TRUE );
2872 return 1;
2875 /* if we get here, we have a sent message; call the window procedure */
2876 old_info = thread_info->receive_info;
2877 thread_info->receive_info = &info;
2878 thread_info->msg_source = msg_source_unavailable;
2879 result = call_window_proc( info.msg.hwnd, info.msg.message, info.msg.wParam,
2880 info.msg.lParam, (info.type != MSG_ASCII), FALSE,
2881 WMCHAR_MAP_RECVMESSAGE );
2882 reply_message( &info, result, TRUE );
2883 thread_info->receive_info = old_info;
2885 /* if some PM_QS* flags were specified, only handle sent messages from now on */
2886 if (HIWORD(flags) && !changed_mask) flags = PM_QS_SENDMESSAGE | LOWORD(flags);
2891 /***********************************************************************
2892 * process_sent_messages
2894 * Process all pending sent messages.
2896 static inline void process_sent_messages(void)
2898 MSG msg;
2899 peek_message( &msg, 0, 0, 0, PM_REMOVE | PM_QS_SENDMESSAGE, 0 );
2903 /***********************************************************************
2904 * get_server_queue_handle
2906 * Get a handle to the server message queue for the current thread.
2908 static HANDLE get_server_queue_handle(void)
2910 struct user_thread_info *thread_info = get_user_thread_info();
2911 HANDLE ret;
2913 if (!(ret = thread_info->server_queue))
2915 SERVER_START_REQ( get_msg_queue )
2917 wine_server_call( req );
2918 ret = wine_server_ptr_handle( reply->handle );
2920 SERVER_END_REQ;
2921 thread_info->server_queue = ret;
2922 if (!ret) ERR( "Cannot get server thread queue\n" );
2924 return ret;
2928 /***********************************************************************
2929 * wait_message_reply
2931 * Wait until a sent message gets replied to.
2933 static void wait_message_reply( UINT flags )
2935 struct user_thread_info *thread_info = get_user_thread_info();
2936 HANDLE server_queue = get_server_queue_handle();
2937 unsigned int wake_mask = QS_SMRESULT | ((flags & SMTO_BLOCK) ? 0 : QS_SENDMESSAGE);
2939 for (;;)
2941 unsigned int wake_bits = 0;
2943 SERVER_START_REQ( set_queue_mask )
2945 req->wake_mask = wake_mask;
2946 req->changed_mask = wake_mask;
2947 req->skip_wait = 1;
2948 if (!wine_server_call( req )) wake_bits = reply->wake_bits & wake_mask;
2950 SERVER_END_REQ;
2952 thread_info->wake_mask = thread_info->changed_mask = 0;
2954 if (wake_bits & QS_SMRESULT) return; /* got a result */
2955 if (wake_bits & QS_SENDMESSAGE)
2957 /* Process the sent message immediately */
2958 process_sent_messages();
2959 continue;
2962 wow_handlers.wait_message( 1, &server_queue, INFINITE, wake_mask, 0 );
2967 /***********************************************************************
2968 * wait_objects
2970 * Wait for multiple objects including the server queue, with specific queue masks.
2972 static DWORD wait_objects( DWORD count, const HANDLE *handles, DWORD timeout,
2973 DWORD wake_mask, DWORD changed_mask, DWORD flags )
2975 struct user_thread_info *thread_info = get_user_thread_info();
2976 DWORD ret;
2978 assert( count ); /* we must have at least the server queue */
2980 flush_window_surfaces( TRUE );
2982 if (thread_info->wake_mask != wake_mask || thread_info->changed_mask != changed_mask)
2984 SERVER_START_REQ( set_queue_mask )
2986 req->wake_mask = wake_mask;
2987 req->changed_mask = changed_mask;
2988 req->skip_wait = 0;
2989 wine_server_call( req );
2991 SERVER_END_REQ;
2992 thread_info->wake_mask = wake_mask;
2993 thread_info->changed_mask = changed_mask;
2996 ret = wow_handlers.wait_message( count, handles, timeout, changed_mask, flags );
2998 if (ret != WAIT_TIMEOUT) thread_info->wake_mask = thread_info->changed_mask = 0;
2999 return ret;
3003 /***********************************************************************
3004 * put_message_in_queue
3006 * Put a sent message into the destination queue.
3007 * For inter-process message, reply_size is set to expected size of reply data.
3009 static BOOL put_message_in_queue( const struct send_message_info *info, size_t *reply_size )
3011 struct packed_message data;
3012 message_data_t msg_data;
3013 unsigned int res;
3014 int i;
3015 timeout_t timeout = TIMEOUT_INFINITE;
3017 /* Check for INFINITE timeout for compatibility with Win9x,
3018 * although Windows >= NT does not do so
3020 if (info->type != MSG_NOTIFY &&
3021 info->type != MSG_CALLBACK &&
3022 info->type != MSG_POSTED &&
3023 info->timeout &&
3024 info->timeout != INFINITE)
3026 /* timeout is signed despite the prototype */
3027 timeout = (timeout_t)max( 0, (int)info->timeout ) * -10000;
3030 memset( &data, 0, sizeof(data) );
3031 if (info->type == MSG_OTHER_PROCESS || info->type == MSG_NOTIFY)
3033 *reply_size = pack_message( info->hwnd, info->msg, info->wparam, info->lparam, &data );
3034 if (data.count == -1)
3036 WARN( "cannot pack message %x\n", info->msg );
3037 return FALSE;
3040 else if (info->type == MSG_CALLBACK)
3042 msg_data.callback.callback = wine_server_client_ptr( info->callback );
3043 msg_data.callback.data = info->data;
3044 msg_data.callback.result = 0;
3045 data.data[0] = &msg_data;
3046 data.size[0] = sizeof(msg_data.callback);
3047 data.count = 1;
3049 else if (info->type == MSG_POSTED && info->msg >= WM_DDE_FIRST && info->msg <= WM_DDE_LAST)
3051 return post_dde_message( &data, info );
3054 SERVER_START_REQ( send_message )
3056 req->id = info->dest_tid;
3057 req->type = info->type;
3058 req->flags = 0;
3059 req->win = wine_server_user_handle( info->hwnd );
3060 req->msg = info->msg;
3061 req->wparam = info->wparam;
3062 req->lparam = info->lparam;
3063 req->timeout = timeout;
3065 if (info->flags & SMTO_ABORTIFHUNG) req->flags |= SEND_MSG_ABORT_IF_HUNG;
3066 for (i = 0; i < data.count; i++) wine_server_add_data( req, data.data[i], data.size[i] );
3067 if ((res = wine_server_call( req )))
3069 if (res == STATUS_INVALID_PARAMETER)
3070 /* FIXME: find a STATUS_ value for this one */
3071 SetLastError( ERROR_INVALID_THREAD_ID );
3072 else
3073 SetLastError( RtlNtStatusToDosError(res) );
3076 SERVER_END_REQ;
3077 return !res;
3081 /***********************************************************************
3082 * retrieve_reply
3084 * Retrieve a message reply from the server.
3086 static LRESULT retrieve_reply( const struct send_message_info *info,
3087 size_t reply_size, LRESULT *result )
3089 NTSTATUS status;
3090 void *reply_data = NULL;
3092 if (reply_size)
3094 if (!(reply_data = HeapAlloc( GetProcessHeap(), 0, reply_size )))
3096 WARN( "no memory for reply, will be truncated\n" );
3097 reply_size = 0;
3100 SERVER_START_REQ( get_message_reply )
3102 req->cancel = 1;
3103 if (reply_size) wine_server_set_reply( req, reply_data, reply_size );
3104 if (!(status = wine_server_call( req ))) *result = reply->result;
3105 reply_size = wine_server_reply_size( reply );
3107 SERVER_END_REQ;
3108 if (!status && reply_size)
3109 unpack_reply( info->hwnd, info->msg, info->wparam, info->lparam, reply_data, reply_size );
3111 HeapFree( GetProcessHeap(), 0, reply_data );
3113 TRACE( "hwnd %p msg %x (%s) wp %lx lp %lx got reply %lx (err=%d)\n",
3114 info->hwnd, info->msg, SPY_GetMsgName(info->msg, info->hwnd), info->wparam,
3115 info->lparam, *result, status );
3117 /* MSDN states that last error is 0 on timeout, but at least NT4 returns ERROR_TIMEOUT */
3118 if (status) SetLastError( RtlNtStatusToDosError(status) );
3119 return !status;
3123 /***********************************************************************
3124 * send_inter_thread_message
3126 static LRESULT send_inter_thread_message( const struct send_message_info *info, LRESULT *res_ptr )
3128 size_t reply_size = 0;
3130 TRACE( "hwnd %p msg %x (%s) wp %lx lp %lx\n",
3131 info->hwnd, info->msg, SPY_GetMsgName(info->msg, info->hwnd), info->wparam, info->lparam );
3133 USER_CheckNotLock();
3135 if (!put_message_in_queue( info, &reply_size )) return 0;
3137 /* there's no reply to wait for on notify/callback messages */
3138 if (info->type == MSG_NOTIFY || info->type == MSG_CALLBACK) return 1;
3140 wait_message_reply( info->flags );
3141 return retrieve_reply( info, reply_size, res_ptr );
3145 /***********************************************************************
3146 * send_inter_thread_callback
3148 static LRESULT send_inter_thread_callback( HWND hwnd, UINT msg, WPARAM wp, LPARAM lp,
3149 LRESULT *result, void *arg )
3151 struct send_message_info *info = arg;
3152 info->hwnd = hwnd;
3153 info->msg = msg;
3154 info->wparam = wp;
3155 info->lparam = lp;
3156 return send_inter_thread_message( info, result );
3159 static BOOL is_message_broadcastable(UINT msg)
3161 return msg < WM_USER || msg >= 0xc000;
3164 /***********************************************************************
3165 * send_message
3167 * Backend implementation of the various SendMessage functions.
3169 static BOOL send_message( struct send_message_info *info, DWORD_PTR *res_ptr, BOOL unicode )
3171 struct user_thread_info *thread_info = get_user_thread_info();
3172 INPUT_MESSAGE_SOURCE prev_source = thread_info->msg_source;
3173 DWORD dest_pid;
3174 BOOL ret;
3175 LRESULT result;
3177 if (is_broadcast(info->hwnd))
3179 if (is_message_broadcastable( info->msg ))
3180 EnumWindows( broadcast_message_callback, (LPARAM)info );
3181 if (res_ptr) *res_ptr = 1;
3182 return TRUE;
3185 if (!(info->dest_tid = GetWindowThreadProcessId( info->hwnd, &dest_pid ))) return FALSE;
3187 if (USER_IsExitingThread( info->dest_tid )) return FALSE;
3189 thread_info->msg_source = msg_source_unavailable;
3190 SPY_EnterMessage( SPY_SENDMESSAGE, info->hwnd, info->msg, info->wparam, info->lparam );
3192 if (info->dest_tid == GetCurrentThreadId())
3194 result = call_window_proc( info->hwnd, info->msg, info->wparam, info->lparam,
3195 unicode, TRUE, info->wm_char );
3196 if (info->type == MSG_CALLBACK)
3197 call_sendmsg_callback( info->callback, info->hwnd, info->msg, info->data, result );
3198 ret = TRUE;
3200 else
3202 if (dest_pid != GetCurrentProcessId() && (info->type == MSG_ASCII || info->type == MSG_UNICODE))
3203 info->type = MSG_OTHER_PROCESS;
3205 /* MSG_ASCII can be sent unconverted except for WM_CHAR; everything else needs to be Unicode */
3206 if (!unicode && is_unicode_message( info->msg ) &&
3207 (info->type != MSG_ASCII || info->msg == WM_CHAR))
3208 ret = WINPROC_CallProcAtoW( send_inter_thread_callback, info->hwnd, info->msg,
3209 info->wparam, info->lparam, &result, info, info->wm_char );
3210 else
3211 ret = send_inter_thread_message( info, &result );
3214 SPY_ExitMessage( SPY_RESULT_OK, info->hwnd, info->msg, result, info->wparam, info->lparam );
3215 thread_info->msg_source = prev_source;
3216 if (ret && res_ptr) *res_ptr = result;
3217 return ret;
3221 /***********************************************************************
3222 * send_hardware_message
3224 NTSTATUS send_hardware_message( HWND hwnd, const INPUT *input, UINT flags )
3226 struct user_key_state_info *key_state_info = get_user_thread_info()->key_state;
3227 struct send_message_info info;
3228 int prev_x, prev_y, new_x, new_y;
3229 INT counter = global_key_state_counter;
3230 NTSTATUS ret;
3231 BOOL wait;
3233 info.type = MSG_HARDWARE;
3234 info.dest_tid = 0;
3235 info.hwnd = hwnd;
3236 info.flags = 0;
3237 info.timeout = 0;
3239 SERVER_START_REQ( send_hardware_message )
3241 req->win = wine_server_user_handle( hwnd );
3242 req->flags = flags;
3243 req->input.type = input->type;
3244 switch (input->type)
3246 case INPUT_MOUSE:
3247 req->input.mouse.x = input->u.mi.dx;
3248 req->input.mouse.y = input->u.mi.dy;
3249 req->input.mouse.data = input->u.mi.mouseData;
3250 req->input.mouse.flags = input->u.mi.dwFlags;
3251 req->input.mouse.time = input->u.mi.time;
3252 req->input.mouse.info = input->u.mi.dwExtraInfo;
3253 break;
3254 case INPUT_KEYBOARD:
3255 req->input.kbd.vkey = input->u.ki.wVk;
3256 req->input.kbd.scan = input->u.ki.wScan;
3257 req->input.kbd.flags = input->u.ki.dwFlags;
3258 req->input.kbd.time = input->u.ki.time;
3259 req->input.kbd.info = input->u.ki.dwExtraInfo;
3260 break;
3261 case INPUT_HARDWARE:
3262 req->input.hw.msg = input->u.hi.uMsg;
3263 req->input.hw.lparam = MAKELONG( input->u.hi.wParamL, input->u.hi.wParamH );
3264 break;
3266 if (key_state_info) wine_server_set_reply( req, key_state_info->state,
3267 sizeof(key_state_info->state) );
3268 ret = wine_server_call( req );
3269 wait = reply->wait;
3270 prev_x = reply->prev_x;
3271 prev_y = reply->prev_y;
3272 new_x = reply->new_x;
3273 new_y = reply->new_y;
3275 SERVER_END_REQ;
3277 if (!ret)
3279 if (key_state_info)
3281 key_state_info->time = GetTickCount();
3282 key_state_info->counter = counter;
3284 if ((flags & SEND_HWMSG_INJECTED) && (prev_x != new_x || prev_y != new_y))
3285 USER_Driver->pSetCursorPos( new_x, new_y );
3288 if (wait)
3290 LRESULT ignored;
3291 wait_message_reply( 0 );
3292 retrieve_reply( &info, 0, &ignored );
3294 return ret;
3298 /***********************************************************************
3299 * MSG_SendInternalMessageTimeout
3301 * Same as SendMessageTimeoutW but sends the message to a specific thread
3302 * without requiring a window handle. Only works for internal Wine messages.
3304 LRESULT MSG_SendInternalMessageTimeout( DWORD dest_pid, DWORD dest_tid,
3305 UINT msg, WPARAM wparam, LPARAM lparam,
3306 UINT flags, UINT timeout, PDWORD_PTR res_ptr )
3308 struct send_message_info info;
3309 LRESULT ret, result;
3311 assert( msg & 0x80000000 ); /* must be an internal Wine message */
3313 info.type = MSG_UNICODE;
3314 info.dest_tid = dest_tid;
3315 info.hwnd = 0;
3316 info.msg = msg;
3317 info.wparam = wparam;
3318 info.lparam = lparam;
3319 info.flags = flags;
3320 info.timeout = timeout;
3322 if (USER_IsExitingThread( dest_tid )) return 0;
3324 if (dest_tid == GetCurrentThreadId())
3326 result = handle_internal_message( 0, msg, wparam, lparam );
3327 ret = 1;
3329 else
3331 if (dest_pid != GetCurrentProcessId()) info.type = MSG_OTHER_PROCESS;
3332 ret = send_inter_thread_message( &info, &result );
3334 if (ret && res_ptr) *res_ptr = result;
3335 return ret;
3339 /***********************************************************************
3340 * SendMessageTimeoutW (USER32.@)
3342 LRESULT WINAPI SendMessageTimeoutW( HWND hwnd, UINT msg, WPARAM wparam, LPARAM lparam,
3343 UINT flags, UINT timeout, PDWORD_PTR res_ptr )
3345 struct send_message_info info;
3347 info.type = MSG_UNICODE;
3348 info.hwnd = hwnd;
3349 info.msg = msg;
3350 info.wparam = wparam;
3351 info.lparam = lparam;
3352 info.flags = flags;
3353 info.timeout = timeout;
3355 return send_message( &info, res_ptr, TRUE );
3358 /***********************************************************************
3359 * SendMessageTimeoutA (USER32.@)
3361 LRESULT WINAPI SendMessageTimeoutA( HWND hwnd, UINT msg, WPARAM wparam, LPARAM lparam,
3362 UINT flags, UINT timeout, PDWORD_PTR res_ptr )
3364 struct send_message_info info;
3366 info.type = MSG_ASCII;
3367 info.hwnd = hwnd;
3368 info.msg = msg;
3369 info.wparam = wparam;
3370 info.lparam = lparam;
3371 info.flags = flags;
3372 info.timeout = timeout;
3373 info.wm_char = WMCHAR_MAP_SENDMESSAGETIMEOUT;
3375 return send_message( &info, res_ptr, FALSE );
3379 /***********************************************************************
3380 * SendMessageW (USER32.@)
3382 LRESULT WINAPI SendMessageW( HWND hwnd, UINT msg, WPARAM wparam, LPARAM lparam )
3384 DWORD_PTR res = 0;
3385 struct send_message_info info;
3387 info.type = MSG_UNICODE;
3388 info.hwnd = hwnd;
3389 info.msg = msg;
3390 info.wparam = wparam;
3391 info.lparam = lparam;
3392 info.flags = SMTO_NORMAL;
3393 info.timeout = 0;
3395 send_message( &info, &res, TRUE );
3396 return res;
3400 /***********************************************************************
3401 * SendMessageA (USER32.@)
3403 LRESULT WINAPI SendMessageA( HWND hwnd, UINT msg, WPARAM wparam, LPARAM lparam )
3405 DWORD_PTR res = 0;
3406 struct send_message_info info;
3408 info.type = MSG_ASCII;
3409 info.hwnd = hwnd;
3410 info.msg = msg;
3411 info.wparam = wparam;
3412 info.lparam = lparam;
3413 info.flags = SMTO_NORMAL;
3414 info.timeout = 0;
3415 info.wm_char = WMCHAR_MAP_SENDMESSAGE;
3417 send_message( &info, &res, FALSE );
3418 return res;
3422 /***********************************************************************
3423 * SendNotifyMessageA (USER32.@)
3425 BOOL WINAPI SendNotifyMessageA( HWND hwnd, UINT msg, WPARAM wparam, LPARAM lparam )
3427 struct send_message_info info;
3429 if (is_pointer_message( msg, wparam ))
3431 SetLastError( ERROR_MESSAGE_SYNC_ONLY );
3432 return FALSE;
3435 info.type = MSG_NOTIFY;
3436 info.hwnd = hwnd;
3437 info.msg = msg;
3438 info.wparam = wparam;
3439 info.lparam = lparam;
3440 info.flags = 0;
3441 info.wm_char = WMCHAR_MAP_SENDMESSAGETIMEOUT;
3443 return send_message( &info, NULL, FALSE );
3447 /***********************************************************************
3448 * SendNotifyMessageW (USER32.@)
3450 BOOL WINAPI SendNotifyMessageW( HWND hwnd, UINT msg, WPARAM wparam, LPARAM lparam )
3452 struct send_message_info info;
3454 if (is_pointer_message( msg, wparam ))
3456 SetLastError( ERROR_MESSAGE_SYNC_ONLY );
3457 return FALSE;
3460 info.type = MSG_NOTIFY;
3461 info.hwnd = hwnd;
3462 info.msg = msg;
3463 info.wparam = wparam;
3464 info.lparam = lparam;
3465 info.flags = 0;
3467 return send_message( &info, NULL, TRUE );
3471 /***********************************************************************
3472 * SendMessageCallbackA (USER32.@)
3474 BOOL WINAPI SendMessageCallbackA( HWND hwnd, UINT msg, WPARAM wparam, LPARAM lparam,
3475 SENDASYNCPROC callback, ULONG_PTR data )
3477 struct send_message_info info;
3479 if (is_pointer_message( msg, wparam ))
3481 SetLastError( ERROR_MESSAGE_SYNC_ONLY );
3482 return FALSE;
3485 info.type = MSG_CALLBACK;
3486 info.hwnd = hwnd;
3487 info.msg = msg;
3488 info.wparam = wparam;
3489 info.lparam = lparam;
3490 info.callback = callback;
3491 info.data = data;
3492 info.flags = 0;
3493 info.wm_char = WMCHAR_MAP_SENDMESSAGETIMEOUT;
3495 return send_message( &info, NULL, FALSE );
3499 /***********************************************************************
3500 * SendMessageCallbackW (USER32.@)
3502 BOOL WINAPI SendMessageCallbackW( HWND hwnd, UINT msg, WPARAM wparam, LPARAM lparam,
3503 SENDASYNCPROC callback, ULONG_PTR data )
3505 struct send_message_info info;
3507 if (is_pointer_message( msg, wparam ))
3509 SetLastError( ERROR_MESSAGE_SYNC_ONLY );
3510 return FALSE;
3513 info.type = MSG_CALLBACK;
3514 info.hwnd = hwnd;
3515 info.msg = msg;
3516 info.wparam = wparam;
3517 info.lparam = lparam;
3518 info.callback = callback;
3519 info.data = data;
3520 info.flags = 0;
3522 return send_message( &info, NULL, TRUE );
3526 /***********************************************************************
3527 * ReplyMessage (USER32.@)
3529 BOOL WINAPI ReplyMessage( LRESULT result )
3531 struct received_message_info *info = get_user_thread_info()->receive_info;
3533 if (!info) return FALSE;
3534 reply_message( info, result, FALSE );
3535 return TRUE;
3539 /***********************************************************************
3540 * InSendMessage (USER32.@)
3542 BOOL WINAPI InSendMessage(void)
3544 return (InSendMessageEx( NULL ) & (ISMEX_SEND | ISMEX_NOTIFY | ISMEX_CALLBACK)) != 0;
3548 /***********************************************************************
3549 * InSendMessageEx (USER32.@)
3551 DWORD WINAPI InSendMessageEx( LPVOID reserved )
3553 struct received_message_info *info = get_user_thread_info()->receive_info;
3555 if (info) return info->flags;
3556 return ISMEX_NOSEND;
3560 /***********************************************************************
3561 * PostMessageA (USER32.@)
3563 BOOL WINAPI PostMessageA( HWND hwnd, UINT msg, WPARAM wparam, LPARAM lparam )
3565 if (!map_wparam_AtoW( msg, &wparam, WMCHAR_MAP_POSTMESSAGE )) return TRUE;
3566 return PostMessageW( hwnd, msg, wparam, lparam );
3570 /***********************************************************************
3571 * PostMessageW (USER32.@)
3573 BOOL WINAPI PostMessageW( HWND hwnd, UINT msg, WPARAM wparam, LPARAM lparam )
3575 struct send_message_info info;
3577 if (is_pointer_message( msg, wparam ))
3579 SetLastError( ERROR_MESSAGE_SYNC_ONLY );
3580 return FALSE;
3583 TRACE( "hwnd %p msg %x (%s) wp %lx lp %lx\n",
3584 hwnd, msg, SPY_GetMsgName(msg, hwnd), wparam, lparam );
3586 info.type = MSG_POSTED;
3587 info.hwnd = hwnd;
3588 info.msg = msg;
3589 info.wparam = wparam;
3590 info.lparam = lparam;
3591 info.flags = 0;
3593 if (is_broadcast(hwnd))
3595 if (is_message_broadcastable( info.msg ))
3596 EnumWindows( broadcast_message_callback, (LPARAM)&info );
3597 return TRUE;
3600 if (!hwnd) return PostThreadMessageW( GetCurrentThreadId(), msg, wparam, lparam );
3602 if (!(info.dest_tid = GetWindowThreadProcessId( hwnd, NULL ))) return FALSE;
3604 if (USER_IsExitingThread( info.dest_tid )) return TRUE;
3606 return put_message_in_queue( &info, NULL );
3610 /**********************************************************************
3611 * PostThreadMessageA (USER32.@)
3613 BOOL WINAPI PostThreadMessageA( DWORD thread, UINT msg, WPARAM wparam, LPARAM lparam )
3615 if (!map_wparam_AtoW( msg, &wparam, WMCHAR_MAP_POSTMESSAGE )) return TRUE;
3616 return PostThreadMessageW( thread, msg, wparam, lparam );
3620 /**********************************************************************
3621 * PostThreadMessageW (USER32.@)
3623 BOOL WINAPI PostThreadMessageW( DWORD thread, UINT msg, WPARAM wparam, LPARAM lparam )
3625 struct send_message_info info;
3627 if (is_pointer_message( msg, wparam ))
3629 SetLastError( ERROR_MESSAGE_SYNC_ONLY );
3630 return FALSE;
3632 if (USER_IsExitingThread( thread )) return TRUE;
3634 info.type = MSG_POSTED;
3635 info.dest_tid = thread;
3636 info.hwnd = 0;
3637 info.msg = msg;
3638 info.wparam = wparam;
3639 info.lparam = lparam;
3640 info.flags = 0;
3641 return put_message_in_queue( &info, NULL );
3645 /***********************************************************************
3646 * PostQuitMessage (USER32.@)
3648 * Posts a quit message to the current thread's message queue.
3650 * PARAMS
3651 * exit_code [I] Exit code to return from message loop.
3653 * RETURNS
3654 * Nothing.
3656 * NOTES
3657 * This function is not the same as calling:
3658 *|PostThreadMessage(GetCurrentThreadId(), WM_QUIT, exit_code, 0);
3659 * It instead sets a flag in the message queue that signals it to generate
3660 * a WM_QUIT message when there are no other pending sent or posted messages
3661 * in the queue.
3663 void WINAPI PostQuitMessage( INT exit_code )
3665 SERVER_START_REQ( post_quit_message )
3667 req->exit_code = exit_code;
3668 wine_server_call( req );
3670 SERVER_END_REQ;
3673 /* check for driver events if we detect that the app is not properly consuming messages */
3674 static inline void check_for_driver_events( UINT msg )
3676 if (get_user_thread_info()->message_count > 200)
3678 flush_window_surfaces( FALSE );
3679 USER_Driver->pMsgWaitForMultipleObjectsEx( 0, NULL, 0, QS_ALLINPUT, 0 );
3681 else if (msg == WM_TIMER || msg == WM_SYSTIMER)
3683 /* driver events should have priority over timers, so make sure we'll check for them soon */
3684 get_user_thread_info()->message_count += 100;
3686 else get_user_thread_info()->message_count++;
3689 /***********************************************************************
3690 * PeekMessageW (USER32.@)
3692 BOOL WINAPI DECLSPEC_HOTPATCH PeekMessageW( MSG *msg_out, HWND hwnd, UINT first, UINT last, UINT flags )
3694 MSG msg;
3695 int ret;
3697 USER_CheckNotLock();
3698 check_for_driver_events( 0 );
3700 ret = peek_message( &msg, hwnd, first, last, flags, 0 );
3701 if (ret < 0) return FALSE;
3703 if (!ret)
3705 flush_window_surfaces( TRUE );
3706 ret = wow_handlers.wait_message( 0, NULL, 0, QS_ALLINPUT, 0 );
3707 /* if we received driver events, check again for a pending message */
3708 if (ret == WAIT_TIMEOUT || peek_message( &msg, hwnd, first, last, flags, 0 ) <= 0) return FALSE;
3711 check_for_driver_events( msg.message );
3713 /* copy back our internal safe copy of message data to msg_out.
3714 * msg_out is a variable from the *program*, so it can't be used
3715 * internally as it can get "corrupted" by our use of SendMessage()
3716 * (back to the program) inside the message handling itself. */
3717 if (!msg_out)
3719 SetLastError( ERROR_NOACCESS );
3720 return FALSE;
3722 *msg_out = msg;
3723 return TRUE;
3727 /***********************************************************************
3728 * PeekMessageA (USER32.@)
3730 BOOL WINAPI DECLSPEC_HOTPATCH PeekMessageA( MSG *msg, HWND hwnd, UINT first, UINT last, UINT flags )
3732 if (get_pending_wmchar( msg, first, last, (flags & PM_REMOVE) )) return TRUE;
3733 if (!PeekMessageW( msg, hwnd, first, last, flags )) return FALSE;
3734 map_wparam_WtoA( msg, (flags & PM_REMOVE) );
3735 return TRUE;
3739 /***********************************************************************
3740 * GetMessageW (USER32.@)
3742 BOOL WINAPI DECLSPEC_HOTPATCH GetMessageW( MSG *msg, HWND hwnd, UINT first, UINT last )
3744 HANDLE server_queue = get_server_queue_handle();
3745 unsigned int mask = QS_POSTMESSAGE | QS_SENDMESSAGE; /* Always selected */
3746 int ret;
3748 USER_CheckNotLock();
3749 check_for_driver_events( 0 );
3751 if (first || last)
3753 if ((first <= WM_KEYLAST) && (last >= WM_KEYFIRST)) mask |= QS_KEY;
3754 if ( ((first <= WM_MOUSELAST) && (last >= WM_MOUSEFIRST)) ||
3755 ((first <= WM_NCMOUSELAST) && (last >= WM_NCMOUSEFIRST)) ) mask |= QS_MOUSE;
3756 if ((first <= WM_TIMER) && (last >= WM_TIMER)) mask |= QS_TIMER;
3757 if ((first <= WM_SYSTIMER) && (last >= WM_SYSTIMER)) mask |= QS_TIMER;
3758 if ((first <= WM_PAINT) && (last >= WM_PAINT)) mask |= QS_PAINT;
3760 else mask = QS_ALLINPUT;
3762 while (!(ret = peek_message( msg, hwnd, first, last, PM_REMOVE | (mask << 16), mask )))
3764 wait_objects( 1, &server_queue, INFINITE, mask & (QS_SENDMESSAGE | QS_SMRESULT), mask, 0 );
3766 if (ret < 0) return -1;
3768 check_for_driver_events( msg->message );
3770 return (msg->message != WM_QUIT);
3774 /***********************************************************************
3775 * GetMessageA (USER32.@)
3777 BOOL WINAPI DECLSPEC_HOTPATCH GetMessageA( MSG *msg, HWND hwnd, UINT first, UINT last )
3779 if (get_pending_wmchar( msg, first, last, TRUE )) return TRUE;
3780 if (GetMessageW( msg, hwnd, first, last ) < 0) return -1;
3781 map_wparam_WtoA( msg, TRUE );
3782 return (msg->message != WM_QUIT);
3786 /***********************************************************************
3787 * IsDialogMessageA (USER32.@)
3788 * IsDialogMessage (USER32.@)
3790 BOOL WINAPI IsDialogMessageA( HWND hwndDlg, LPMSG pmsg )
3792 MSG msg = *pmsg;
3793 map_wparam_AtoW( msg.message, &msg.wParam, WMCHAR_MAP_NOMAPPING );
3794 return IsDialogMessageW( hwndDlg, &msg );
3798 /***********************************************************************
3799 * TranslateMessage (USER32.@)
3801 * Implementation of TranslateMessage.
3803 * TranslateMessage translates virtual-key messages into character-messages,
3804 * as follows :
3805 * WM_KEYDOWN/WM_KEYUP combinations produce a WM_CHAR or WM_DEADCHAR message.
3806 * ditto replacing WM_* with WM_SYS*
3807 * This produces WM_CHAR messages only for keys mapped to ASCII characters
3808 * by the keyboard driver.
3810 * If the message is WM_KEYDOWN, WM_KEYUP, WM_SYSKEYDOWN, or WM_SYSKEYUP, the
3811 * return value is nonzero, regardless of the translation.
3814 BOOL WINAPI TranslateMessage( const MSG *msg )
3816 UINT message;
3817 WCHAR wp[8];
3818 BYTE state[256];
3819 INT len;
3821 if (msg->message < WM_KEYFIRST || msg->message > WM_KEYLAST) return FALSE;
3822 if (msg->message != WM_KEYDOWN && msg->message != WM_SYSKEYDOWN) return TRUE;
3824 TRACE_(key)("Translating key %s (%04lX), scancode %04x\n",
3825 SPY_GetVKeyName(msg->wParam), msg->wParam, HIWORD(msg->lParam));
3827 switch (msg->wParam)
3829 case VK_PACKET:
3830 message = (msg->message == WM_KEYDOWN) ? WM_CHAR : WM_SYSCHAR;
3831 TRACE_(key)("PostMessageW(%p,%s,%04x,%08x)\n",
3832 msg->hwnd, SPY_GetMsgName(message, msg->hwnd), HIWORD(msg->lParam), LOWORD(msg->lParam));
3833 PostMessageW( msg->hwnd, message, HIWORD(msg->lParam), LOWORD(msg->lParam));
3834 return TRUE;
3836 case VK_PROCESSKEY:
3837 return ImmTranslateMessage(msg->hwnd, msg->message, msg->wParam, msg->lParam);
3840 GetKeyboardState( state );
3841 len = ToUnicode(msg->wParam, HIWORD(msg->lParam), state, wp, ARRAY_SIZE(wp), 0);
3842 if (len == -1)
3844 message = (msg->message == WM_KEYDOWN) ? WM_DEADCHAR : WM_SYSDEADCHAR;
3845 TRACE_(key)("-1 -> PostMessageW(%p,%s,%04x,%08lx)\n",
3846 msg->hwnd, SPY_GetMsgName(message, msg->hwnd), wp[0], msg->lParam);
3847 PostMessageW( msg->hwnd, message, wp[0], msg->lParam );
3849 else if (len > 0)
3851 INT i;
3853 message = (msg->message == WM_KEYDOWN) ? WM_CHAR : WM_SYSCHAR;
3854 TRACE_(key)("%d -> PostMessageW(%p,%s,<x>,%08lx) for <x> in %s\n", len, msg->hwnd,
3855 SPY_GetMsgName(message, msg->hwnd), msg->lParam, debugstr_wn(wp, len));
3856 for (i = 0; i < len; i++)
3857 PostMessageW( msg->hwnd, message, wp[i], msg->lParam );
3859 return TRUE;
3863 /***********************************************************************
3864 * DispatchMessageA (USER32.@)
3866 * See DispatchMessageW.
3868 LRESULT WINAPI DECLSPEC_HOTPATCH DispatchMessageA( const MSG* msg )
3870 LRESULT retval;
3872 /* Process timer messages */
3873 if ((msg->message == WM_TIMER) || (msg->message == WM_SYSTIMER))
3875 if (msg->lParam)
3877 __TRY
3879 retval = CallWindowProcA( (WNDPROC)msg->lParam, msg->hwnd,
3880 msg->message, msg->wParam, GetTickCount() );
3882 __EXCEPT_ALL
3884 retval = 0;
3886 __ENDTRY
3887 return retval;
3890 if (!msg->hwnd) return 0;
3892 SPY_EnterMessage( SPY_DISPATCHMESSAGE, msg->hwnd, msg->message,
3893 msg->wParam, msg->lParam );
3895 if (!WINPROC_call_window( msg->hwnd, msg->message, msg->wParam, msg->lParam,
3896 &retval, FALSE, WMCHAR_MAP_DISPATCHMESSAGE ))
3898 if (!IsWindow( msg->hwnd )) SetLastError( ERROR_INVALID_WINDOW_HANDLE );
3899 else SetLastError( ERROR_MESSAGE_SYNC_ONLY );
3900 retval = 0;
3903 SPY_ExitMessage( SPY_RESULT_OK, msg->hwnd, msg->message, retval,
3904 msg->wParam, msg->lParam );
3906 if (msg->message == WM_PAINT)
3908 /* send a WM_NCPAINT and WM_ERASEBKGND if the non-client area is still invalid */
3909 HRGN hrgn = CreateRectRgn( 0, 0, 0, 0 );
3910 GetUpdateRgn( msg->hwnd, hrgn, TRUE );
3911 DeleteObject( hrgn );
3913 return retval;
3917 /***********************************************************************
3918 * DispatchMessageW (USER32.@) Process a message
3920 * Process the message specified in the structure *_msg_.
3922 * If the lpMsg parameter points to a WM_TIMER message and the
3923 * parameter of the WM_TIMER message is not NULL, the lParam parameter
3924 * points to the function that is called instead of the window
3925 * procedure. The function stored in lParam (timer callback) is protected
3926 * from causing page-faults.
3928 * The message must be valid.
3930 * RETURNS
3932 * DispatchMessage() returns the result of the window procedure invoked.
3934 * CONFORMANCE
3936 * ECMA-234, Win32
3939 LRESULT WINAPI DECLSPEC_HOTPATCH DispatchMessageW( const MSG* msg )
3941 LRESULT retval;
3943 /* Process timer messages */
3944 if ((msg->message == WM_TIMER) || (msg->message == WM_SYSTIMER))
3946 if (msg->lParam)
3948 __TRY
3950 retval = CallWindowProcW( (WNDPROC)msg->lParam, msg->hwnd,
3951 msg->message, msg->wParam, GetTickCount() );
3953 __EXCEPT_ALL
3955 retval = 0;
3957 __ENDTRY
3958 return retval;
3961 if (!msg->hwnd) return 0;
3963 SPY_EnterMessage( SPY_DISPATCHMESSAGE, msg->hwnd, msg->message,
3964 msg->wParam, msg->lParam );
3966 if (!WINPROC_call_window( msg->hwnd, msg->message, msg->wParam, msg->lParam,
3967 &retval, TRUE, WMCHAR_MAP_DISPATCHMESSAGE ))
3969 if (!IsWindow( msg->hwnd )) SetLastError( ERROR_INVALID_WINDOW_HANDLE );
3970 else SetLastError( ERROR_MESSAGE_SYNC_ONLY );
3971 retval = 0;
3974 SPY_ExitMessage( SPY_RESULT_OK, msg->hwnd, msg->message, retval,
3975 msg->wParam, msg->lParam );
3977 if (msg->message == WM_PAINT)
3979 /* send a WM_NCPAINT and WM_ERASEBKGND if the non-client area is still invalid */
3980 HRGN hrgn = CreateRectRgn( 0, 0, 0, 0 );
3981 GetUpdateRgn( msg->hwnd, hrgn, TRUE );
3982 DeleteObject( hrgn );
3984 return retval;
3988 /***********************************************************************
3989 * GetMessagePos (USER.119)
3990 * GetMessagePos (USER32.@)
3992 * The GetMessagePos() function returns a long value representing a
3993 * cursor position, in screen coordinates, when the last message
3994 * retrieved by the GetMessage() function occurs. The x-coordinate is
3995 * in the low-order word of the return value, the y-coordinate is in
3996 * the high-order word. The application can use the MAKEPOINT()
3997 * macro to obtain a POINT structure from the return value.
3999 * For the current cursor position, use GetCursorPos().
4001 * RETURNS
4003 * Cursor position of last message on success, zero on failure.
4005 * CONFORMANCE
4007 * ECMA-234, Win32
4010 DWORD WINAPI GetMessagePos(void)
4012 return get_user_thread_info()->GetMessagePosVal;
4016 /***********************************************************************
4017 * GetMessageTime (USER.120)
4018 * GetMessageTime (USER32.@)
4020 * GetMessageTime() returns the message time for the last message
4021 * retrieved by the function. The time is measured in milliseconds with
4022 * the same offset as GetTickCount().
4024 * Since the tick count wraps, this is only useful for moderately short
4025 * relative time comparisons.
4027 * RETURNS
4029 * Time of last message on success, zero on failure.
4031 LONG WINAPI GetMessageTime(void)
4033 return get_user_thread_info()->GetMessageTimeVal;
4037 /***********************************************************************
4038 * GetMessageExtraInfo (USER.288)
4039 * GetMessageExtraInfo (USER32.@)
4041 LPARAM WINAPI GetMessageExtraInfo(void)
4043 return get_user_thread_info()->GetMessageExtraInfoVal;
4047 /***********************************************************************
4048 * SetMessageExtraInfo (USER32.@)
4050 LPARAM WINAPI SetMessageExtraInfo(LPARAM lParam)
4052 struct user_thread_info *thread_info = get_user_thread_info();
4053 LONG old_value = thread_info->GetMessageExtraInfoVal;
4054 thread_info->GetMessageExtraInfoVal = lParam;
4055 return old_value;
4059 /***********************************************************************
4060 * GetCurrentInputMessageSource (USER32.@)
4062 BOOL WINAPI GetCurrentInputMessageSource( INPUT_MESSAGE_SOURCE *source )
4064 *source = get_user_thread_info()->msg_source;
4065 return TRUE;
4069 /***********************************************************************
4070 * WaitMessage (USER.112) Suspend thread pending messages
4071 * WaitMessage (USER32.@) Suspend thread pending messages
4073 * WaitMessage() suspends a thread until events appear in the thread's
4074 * queue.
4076 BOOL WINAPI WaitMessage(void)
4078 return (MsgWaitForMultipleObjectsEx( 0, NULL, INFINITE, QS_ALLINPUT, 0 ) != WAIT_FAILED);
4082 /***********************************************************************
4083 * MsgWaitForMultipleObjectsEx (USER32.@)
4085 DWORD WINAPI MsgWaitForMultipleObjectsEx( DWORD count, const HANDLE *pHandles,
4086 DWORD timeout, DWORD mask, DWORD flags )
4088 HANDLE handles[MAXIMUM_WAIT_OBJECTS];
4089 DWORD i;
4091 if (count > MAXIMUM_WAIT_OBJECTS-1)
4093 SetLastError( ERROR_INVALID_PARAMETER );
4094 return WAIT_FAILED;
4097 /* add the queue to the handle list */
4098 for (i = 0; i < count; i++) handles[i] = pHandles[i];
4099 handles[count] = get_server_queue_handle();
4101 return wait_objects( count+1, handles, timeout,
4102 (flags & MWMO_INPUTAVAILABLE) ? mask : 0, mask, flags );
4106 /***********************************************************************
4107 * MsgWaitForMultipleObjects (USER32.@)
4109 DWORD WINAPI MsgWaitForMultipleObjects( DWORD count, const HANDLE *handles,
4110 BOOL wait_all, DWORD timeout, DWORD mask )
4112 return MsgWaitForMultipleObjectsEx( count, handles, timeout, mask,
4113 wait_all ? MWMO_WAITALL : 0 );
4117 /***********************************************************************
4118 * WaitForInputIdle (USER32.@)
4120 DWORD WINAPI WaitForInputIdle( HANDLE hProcess, DWORD dwTimeOut )
4122 DWORD start_time, elapsed, ret;
4123 HANDLE handles[2];
4125 handles[0] = hProcess;
4126 SERVER_START_REQ( get_process_idle_event )
4128 req->handle = wine_server_obj_handle( hProcess );
4129 wine_server_call_err( req );
4130 handles[1] = wine_server_ptr_handle( reply->event );
4132 SERVER_END_REQ;
4133 if (!handles[1]) return WAIT_FAILED; /* no event to wait on */
4135 start_time = GetTickCount();
4136 elapsed = 0;
4138 TRACE("waiting for %p\n", handles[1] );
4141 ret = MsgWaitForMultipleObjects ( 2, handles, FALSE, dwTimeOut - elapsed, QS_SENDMESSAGE );
4142 switch (ret)
4144 case WAIT_OBJECT_0:
4145 return 0;
4146 case WAIT_OBJECT_0+2:
4147 process_sent_messages();
4148 break;
4149 case WAIT_TIMEOUT:
4150 case WAIT_FAILED:
4151 TRACE("timeout or error\n");
4152 return ret;
4153 default:
4154 TRACE("finished\n");
4155 return 0;
4157 if (dwTimeOut != INFINITE)
4159 elapsed = GetTickCount() - start_time;
4160 if (elapsed > dwTimeOut)
4161 break;
4164 while (1);
4166 return WAIT_TIMEOUT;
4170 /***********************************************************************
4171 * RegisterWindowMessageA (USER32.@)
4172 * RegisterWindowMessage (USER.118)
4174 UINT WINAPI RegisterWindowMessageA( LPCSTR str )
4176 UINT ret = GlobalAddAtomA(str);
4177 TRACE("%s, ret=%x\n", str, ret);
4178 return ret;
4182 /***********************************************************************
4183 * RegisterWindowMessageW (USER32.@)
4185 UINT WINAPI RegisterWindowMessageW( LPCWSTR str )
4187 UINT ret = GlobalAddAtomW(str);
4188 TRACE("%s ret=%x\n", debugstr_w(str), ret);
4189 return ret;
4192 typedef struct BroadcastParm
4194 DWORD flags;
4195 LPDWORD recipients;
4196 UINT msg;
4197 WPARAM wp;
4198 LPARAM lp;
4199 BOOL success;
4200 HWINSTA winsta;
4201 } BroadcastParm;
4203 static BOOL CALLBACK bcast_childwindow( HWND hw, LPARAM lp )
4205 BroadcastParm *parm = (BroadcastParm*)lp;
4206 DWORD_PTR retval = 0;
4207 LRESULT lresult;
4209 if (parm->flags & BSF_IGNORECURRENTTASK && WIN_IsCurrentProcess(hw))
4211 TRACE("Not telling myself %p\n", hw);
4212 return TRUE;
4215 /* I don't know 100% for sure if this is what Windows does, but it fits the tests */
4216 if (parm->flags & BSF_QUERY)
4218 TRACE("Telling window %p using SendMessageTimeout\n", hw);
4220 /* Not tested for conflicting flags */
4221 if (parm->flags & BSF_FORCEIFHUNG || parm->flags & BSF_NOHANG)
4222 lresult = SendMessageTimeoutW( hw, parm->msg, parm->wp, parm->lp, SMTO_ABORTIFHUNG, 2000, &retval );
4223 else if (parm->flags & BSF_NOTIMEOUTIFNOTHUNG)
4224 lresult = SendMessageTimeoutW( hw, parm->msg, parm->wp, parm->lp, SMTO_NOTIMEOUTIFNOTHUNG, 2000, &retval );
4225 else
4226 lresult = SendMessageTimeoutW( hw, parm->msg, parm->wp, parm->lp, SMTO_NORMAL, 2000, &retval );
4228 if (!lresult && GetLastError() == ERROR_TIMEOUT)
4230 WARN("Timed out!\n");
4231 if (!(parm->flags & BSF_FORCEIFHUNG))
4232 goto fail;
4234 if (retval == BROADCAST_QUERY_DENY)
4235 goto fail;
4237 return TRUE;
4239 fail:
4240 parm->success = FALSE;
4241 return FALSE;
4243 else if (parm->flags & BSF_POSTMESSAGE)
4245 TRACE("Telling window %p using PostMessage\n", hw);
4246 PostMessageW( hw, parm->msg, parm->wp, parm->lp );
4248 else
4250 TRACE("Telling window %p using SendNotifyMessage\n", hw);
4251 SendNotifyMessageW( hw, parm->msg, parm->wp, parm->lp );
4254 return TRUE;
4257 static BOOL CALLBACK bcast_desktop( LPWSTR desktop, LPARAM lp )
4259 BOOL ret;
4260 HDESK hdesktop;
4261 BroadcastParm *parm = (BroadcastParm*)lp;
4263 TRACE("desktop: %s\n", debugstr_w( desktop ));
4265 hdesktop = open_winstation_desktop( parm->winsta, desktop, 0, FALSE, DESKTOP_ENUMERATE|DESKTOP_WRITEOBJECTS|STANDARD_RIGHTS_WRITE );
4266 if (!hdesktop)
4268 FIXME("Could not open desktop %s\n", debugstr_w(desktop));
4269 return TRUE;
4272 ret = EnumDesktopWindows( hdesktop, bcast_childwindow, lp );
4273 CloseDesktop(hdesktop);
4274 TRACE("-->%d\n", ret);
4275 return parm->success;
4278 static BOOL CALLBACK bcast_winsta( LPWSTR winsta, LPARAM lp )
4280 BOOL ret;
4281 HWINSTA hwinsta = OpenWindowStationW( winsta, FALSE, WINSTA_ENUMDESKTOPS );
4282 TRACE("hwinsta: %p/%s/%08x\n", hwinsta, debugstr_w( winsta ), GetLastError());
4283 if (!hwinsta)
4284 return TRUE;
4285 ((BroadcastParm *)lp)->winsta = hwinsta;
4286 ret = EnumDesktopsW( hwinsta, bcast_desktop, lp );
4287 CloseWindowStation( hwinsta );
4288 TRACE("-->%d\n", ret);
4289 return ret;
4292 /***********************************************************************
4293 * BroadcastSystemMessageA (USER32.@)
4294 * BroadcastSystemMessage (USER32.@)
4296 LONG WINAPI BroadcastSystemMessageA( DWORD flags, LPDWORD recipients, UINT msg, WPARAM wp, LPARAM lp )
4298 return BroadcastSystemMessageExA( flags, recipients, msg, wp, lp, NULL );
4302 /***********************************************************************
4303 * BroadcastSystemMessageW (USER32.@)
4305 LONG WINAPI BroadcastSystemMessageW( DWORD flags, LPDWORD recipients, UINT msg, WPARAM wp, LPARAM lp )
4307 return BroadcastSystemMessageExW( flags, recipients, msg, wp, lp, NULL );
4310 /***********************************************************************
4311 * BroadcastSystemMessageExA (USER32.@)
4313 LONG WINAPI BroadcastSystemMessageExA( DWORD flags, LPDWORD recipients, UINT msg, WPARAM wp, LPARAM lp, PBSMINFO pinfo )
4315 map_wparam_AtoW( msg, &wp, WMCHAR_MAP_NOMAPPING );
4316 return BroadcastSystemMessageExW( flags, recipients, msg, wp, lp, NULL );
4320 /***********************************************************************
4321 * BroadcastSystemMessageExW (USER32.@)
4323 LONG WINAPI BroadcastSystemMessageExW( DWORD flags, LPDWORD recipients, UINT msg, WPARAM wp, LPARAM lp, PBSMINFO pinfo )
4325 BroadcastParm parm;
4326 DWORD recips = BSM_ALLCOMPONENTS;
4327 BOOL ret = TRUE;
4328 static const DWORD all_flags = ( BSF_QUERY | BSF_IGNORECURRENTTASK | BSF_FLUSHDISK | BSF_NOHANG
4329 | BSF_POSTMESSAGE | BSF_FORCEIFHUNG | BSF_NOTIMEOUTIFNOTHUNG
4330 | BSF_ALLOWSFW | BSF_SENDNOTIFYMESSAGE | BSF_RETURNHDESK | BSF_LUID );
4332 TRACE("Flags: %08x, recipients: %p(0x%x), msg: %04x, wparam: %08lx, lparam: %08lx\n", flags, recipients,
4333 (recipients ? *recipients : recips), msg, wp, lp);
4335 if (flags & ~all_flags)
4337 SetLastError(ERROR_INVALID_PARAMETER);
4338 return 0;
4341 if (!recipients)
4342 recipients = &recips;
4344 if ( pinfo && flags & BSF_QUERY )
4345 FIXME("Not returning PBSMINFO information yet\n");
4347 parm.flags = flags;
4348 parm.recipients = recipients;
4349 parm.msg = msg;
4350 parm.wp = wp;
4351 parm.lp = lp;
4352 parm.success = TRUE;
4354 if (*recipients & BSM_ALLDESKTOPS || *recipients == BSM_ALLCOMPONENTS)
4355 ret = EnumWindowStationsW(bcast_winsta, (LONG_PTR)&parm);
4356 else if (*recipients & BSM_APPLICATIONS)
4358 EnumWindows(bcast_childwindow, (LONG_PTR)&parm);
4359 ret = parm.success;
4361 else
4362 FIXME("Recipients %08x not supported!\n", *recipients);
4364 return ret;
4367 /***********************************************************************
4368 * SetMessageQueue (USER32.@)
4370 BOOL WINAPI SetMessageQueue( INT size )
4372 /* now obsolete the message queue will be expanded dynamically as necessary */
4373 return TRUE;
4377 /***********************************************************************
4378 * MessageBeep (USER32.@)
4380 BOOL WINAPI MessageBeep( UINT i )
4382 BOOL active = TRUE;
4383 SystemParametersInfoA( SPI_GETBEEP, 0, &active, FALSE );
4384 if (active) USER_Driver->pBeep();
4385 return TRUE;
4389 /***********************************************************************
4390 * SetCoalescableTimer (USER32.@)
4392 UINT_PTR WINAPI SetCoalescableTimer( HWND hwnd, UINT_PTR id, UINT timeout, TIMERPROC proc, ULONG tolerance )
4394 UINT_PTR ret;
4395 WNDPROC winproc = 0;
4397 if (proc) winproc = WINPROC_AllocProc( (WNDPROC)proc, FALSE );
4399 timeout = min( max( USER_TIMER_MINIMUM, timeout ), USER_TIMER_MAXIMUM );
4401 SERVER_START_REQ( set_win_timer )
4403 req->win = wine_server_user_handle( hwnd );
4404 req->msg = WM_TIMER;
4405 req->id = id;
4406 req->rate = timeout;
4407 req->lparam = (ULONG_PTR)winproc;
4408 if (!wine_server_call_err( req ))
4410 ret = reply->id;
4411 if (!ret) ret = TRUE;
4413 else ret = 0;
4415 SERVER_END_REQ;
4417 TRACE("Added %p %lx %p timeout %d\n", hwnd, id, winproc, timeout );
4418 return ret;
4422 /******************************************************************
4423 * SetTimer (USER32.@)
4425 UINT_PTR WINAPI SetTimer( HWND hwnd, UINT_PTR id, UINT timeout, TIMERPROC proc )
4427 return SetCoalescableTimer( hwnd, id, timeout, proc, TIMERV_DEFAULT_COALESCING );
4431 /***********************************************************************
4432 * SetSystemTimer (USER32.@)
4434 UINT_PTR WINAPI SetSystemTimer( HWND hwnd, UINT_PTR id, UINT timeout, TIMERPROC proc )
4436 UINT_PTR ret;
4437 WNDPROC winproc = 0;
4439 if (proc) winproc = WINPROC_AllocProc( (WNDPROC)proc, FALSE );
4441 timeout = min( max( USER_TIMER_MINIMUM, timeout ), USER_TIMER_MAXIMUM );
4443 SERVER_START_REQ( set_win_timer )
4445 req->win = wine_server_user_handle( hwnd );
4446 req->msg = WM_SYSTIMER;
4447 req->id = id;
4448 req->rate = timeout;
4449 req->lparam = (ULONG_PTR)winproc;
4450 if (!wine_server_call_err( req ))
4452 ret = reply->id;
4453 if (!ret) ret = TRUE;
4455 else ret = 0;
4457 SERVER_END_REQ;
4459 TRACE("Added %p %lx %p timeout %d\n", hwnd, id, winproc, timeout );
4460 return ret;
4464 /***********************************************************************
4465 * KillTimer (USER32.@)
4467 BOOL WINAPI KillTimer( HWND hwnd, UINT_PTR id )
4469 BOOL ret;
4471 SERVER_START_REQ( kill_win_timer )
4473 req->win = wine_server_user_handle( hwnd );
4474 req->msg = WM_TIMER;
4475 req->id = id;
4476 ret = !wine_server_call_err( req );
4478 SERVER_END_REQ;
4479 return ret;
4483 /***********************************************************************
4484 * KillSystemTimer (USER32.@)
4486 BOOL WINAPI KillSystemTimer( HWND hwnd, UINT_PTR id )
4488 BOOL ret;
4490 SERVER_START_REQ( kill_win_timer )
4492 req->win = wine_server_user_handle( hwnd );
4493 req->msg = WM_SYSTIMER;
4494 req->id = id;
4495 ret = !wine_server_call_err( req );
4497 SERVER_END_REQ;
4498 return ret;
4502 /**********************************************************************
4503 * IsGUIThread (USER32.@)
4505 BOOL WINAPI IsGUIThread( BOOL convert )
4507 FIXME( "%u: stub\n", convert );
4508 return TRUE;
4512 /**********************************************************************
4513 * GetGUIThreadInfo (USER32.@)
4515 BOOL WINAPI GetGUIThreadInfo( DWORD id, GUITHREADINFO *info )
4517 BOOL ret;
4519 if (info->cbSize != sizeof(*info))
4521 SetLastError( ERROR_INVALID_PARAMETER );
4522 return FALSE;
4525 SERVER_START_REQ( get_thread_input )
4527 req->tid = id;
4528 if ((ret = !wine_server_call_err( req )))
4530 info->flags = 0;
4531 info->hwndActive = wine_server_ptr_handle( reply->active );
4532 info->hwndFocus = wine_server_ptr_handle( reply->focus );
4533 info->hwndCapture = wine_server_ptr_handle( reply->capture );
4534 info->hwndMenuOwner = wine_server_ptr_handle( reply->menu_owner );
4535 info->hwndMoveSize = wine_server_ptr_handle( reply->move_size );
4536 info->hwndCaret = wine_server_ptr_handle( reply->caret );
4537 info->rcCaret.left = reply->rect.left;
4538 info->rcCaret.top = reply->rect.top;
4539 info->rcCaret.right = reply->rect.right;
4540 info->rcCaret.bottom = reply->rect.bottom;
4541 if (reply->menu_owner) info->flags |= GUI_INMENUMODE;
4542 if (reply->move_size) info->flags |= GUI_INMOVESIZE;
4543 if (reply->caret) info->flags |= GUI_CARETBLINKING;
4546 SERVER_END_REQ;
4547 return ret;
4551 /******************************************************************
4552 * IsHungAppWindow (USER32.@)
4555 BOOL WINAPI IsHungAppWindow( HWND hWnd )
4557 BOOL ret;
4559 SERVER_START_REQ( is_window_hung )
4561 req->win = wine_server_user_handle( hWnd );
4562 ret = !wine_server_call_err( req ) && reply->is_hung;
4564 SERVER_END_REQ;
4565 return ret;
4568 /******************************************************************
4569 * ChangeWindowMessageFilter (USER32.@)
4571 BOOL WINAPI ChangeWindowMessageFilter( UINT message, DWORD flag )
4573 FIXME( "%x %08x\n", message, flag );
4574 return TRUE;
4577 /******************************************************************
4578 * ChangeWindowMessageFilterEx (USER32.@)
4580 BOOL WINAPI ChangeWindowMessageFilterEx( HWND hwnd, UINT message, DWORD action, CHANGEFILTERSTRUCT *changefilter )
4582 FIXME( "%p %x %d %p\n", hwnd, message, action, changefilter );
4583 return TRUE;