server: Set appropriate status for a terminated thread.
[wine.git] / dlls / user32 / message.c
blobe81998327ad606fb06c16cdbfd59817ce14e308d
1 /*
2 * Window messaging support
4 * Copyright 2001 Alexandre Julliard
5 * Copyright 2008 Maarten Lankhorst
7 * This library is free software; you can redistribute it and/or
8 * modify it under the terms of the GNU Lesser General Public
9 * License as published by the Free Software Foundation; either
10 * version 2.1 of the License, or (at your option) any later version.
12 * This library is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
15 * Lesser General Public License for more details.
17 * You should have received a copy of the GNU Lesser General Public
18 * License along with this library; if not, write to the Free Software
19 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
22 #include "config.h"
23 #include "wine/port.h"
25 #include <assert.h>
26 #include <stdarg.h>
28 #define NONAMELESSUNION
29 #define NONAMELESSSTRUCT
30 #include "ntstatus.h"
31 #define WIN32_NO_STATUS
32 #include "windef.h"
33 #include "winbase.h"
34 #include "wingdi.h"
35 #include "winuser.h"
36 #include "winerror.h"
37 #include "winnls.h"
38 #include "dbt.h"
39 #include "dde.h"
40 #include "imm.h"
41 #include "ddk/imm.h"
42 #include "wine/unicode.h"
43 #include "wine/server.h"
44 #include "user_private.h"
45 #include "win.h"
46 #include "controls.h"
47 #include "wine/debug.h"
48 #include "wine/exception.h"
50 WINE_DEFAULT_DEBUG_CHANNEL(msg);
51 WINE_DECLARE_DEBUG_CHANNEL(relay);
52 WINE_DECLARE_DEBUG_CHANNEL(key);
54 #define WM_NCMOUSEFIRST WM_NCMOUSEMOVE
55 #define WM_NCMOUSELAST (WM_NCMOUSEFIRST+(WM_MOUSELAST-WM_MOUSEFIRST))
57 #define MAX_PACK_COUNT 4
59 /* the various structures that can be sent in messages, in platform-independent layout */
60 struct packed_CREATESTRUCTW
62 ULONGLONG lpCreateParams;
63 ULONGLONG hInstance;
64 user_handle_t hMenu;
65 DWORD __pad1;
66 user_handle_t hwndParent;
67 DWORD __pad2;
68 INT cy;
69 INT cx;
70 INT y;
71 INT x;
72 LONG style;
73 ULONGLONG lpszName;
74 ULONGLONG lpszClass;
75 DWORD dwExStyle;
76 DWORD __pad3;
79 struct packed_DRAWITEMSTRUCT
81 UINT CtlType;
82 UINT CtlID;
83 UINT itemID;
84 UINT itemAction;
85 UINT itemState;
86 user_handle_t hwndItem;
87 DWORD __pad1;
88 user_handle_t hDC;
89 DWORD __pad2;
90 RECT rcItem;
91 ULONGLONG itemData;
94 struct packed_MEASUREITEMSTRUCT
96 UINT CtlType;
97 UINT CtlID;
98 UINT itemID;
99 UINT itemWidth;
100 UINT itemHeight;
101 ULONGLONG itemData;
104 struct packed_DELETEITEMSTRUCT
106 UINT CtlType;
107 UINT CtlID;
108 UINT itemID;
109 user_handle_t hwndItem;
110 DWORD __pad;
111 ULONGLONG itemData;
114 struct packed_COMPAREITEMSTRUCT
116 UINT CtlType;
117 UINT CtlID;
118 user_handle_t hwndItem;
119 DWORD __pad1;
120 UINT itemID1;
121 ULONGLONG itemData1;
122 UINT itemID2;
123 ULONGLONG itemData2;
124 DWORD dwLocaleId;
125 DWORD __pad2;
128 struct packed_WINDOWPOS
130 user_handle_t hwnd;
131 DWORD __pad1;
132 user_handle_t hwndInsertAfter;
133 DWORD __pad2;
134 INT x;
135 INT y;
136 INT cx;
137 INT cy;
138 UINT flags;
139 DWORD __pad3;
142 struct packed_COPYDATASTRUCT
144 ULONGLONG dwData;
145 DWORD cbData;
146 ULONGLONG lpData;
149 struct packed_HELPINFO
151 UINT cbSize;
152 INT iContextType;
153 INT iCtrlId;
154 user_handle_t hItemHandle;
155 DWORD __pad;
156 ULONGLONG dwContextId;
157 POINT MousePos;
160 struct packed_NCCALCSIZE_PARAMS
162 RECT rgrc[3];
163 ULONGLONG __pad1;
164 user_handle_t hwnd;
165 DWORD __pad2;
166 user_handle_t hwndInsertAfter;
167 DWORD __pad3;
168 INT x;
169 INT y;
170 INT cx;
171 INT cy;
172 UINT flags;
173 DWORD __pad4;
176 struct packed_MSG
178 user_handle_t hwnd;
179 DWORD __pad1;
180 UINT message;
181 ULONGLONG wParam;
182 ULONGLONG lParam;
183 DWORD time;
184 POINT pt;
185 DWORD __pad2;
188 struct packed_MDINEXTMENU
190 user_handle_t hmenuIn;
191 DWORD __pad1;
192 user_handle_t hmenuNext;
193 DWORD __pad2;
194 user_handle_t hwndNext;
195 DWORD __pad3;
198 struct packed_MDICREATESTRUCTW
200 ULONGLONG szClass;
201 ULONGLONG szTitle;
202 ULONGLONG hOwner;
203 INT x;
204 INT y;
205 INT cx;
206 INT cy;
207 DWORD style;
208 ULONGLONG lParam;
211 struct packed_hook_extra_info
213 user_handle_t handle;
214 DWORD __pad;
215 ULONGLONG lparam;
218 /* the structures are unpacked on top of the packed ones, so make sure they fit */
219 C_ASSERT( sizeof(struct packed_CREATESTRUCTW) >= sizeof(CREATESTRUCTW) );
220 C_ASSERT( sizeof(struct packed_DRAWITEMSTRUCT) >= sizeof(DRAWITEMSTRUCT) );
221 C_ASSERT( sizeof(struct packed_MEASUREITEMSTRUCT) >= sizeof(MEASUREITEMSTRUCT) );
222 C_ASSERT( sizeof(struct packed_DELETEITEMSTRUCT) >= sizeof(DELETEITEMSTRUCT) );
223 C_ASSERT( sizeof(struct packed_COMPAREITEMSTRUCT) >= sizeof(COMPAREITEMSTRUCT) );
224 C_ASSERT( sizeof(struct packed_WINDOWPOS) >= sizeof(WINDOWPOS) );
225 C_ASSERT( sizeof(struct packed_COPYDATASTRUCT) >= sizeof(COPYDATASTRUCT) );
226 C_ASSERT( sizeof(struct packed_HELPINFO) >= sizeof(HELPINFO) );
227 C_ASSERT( sizeof(struct packed_NCCALCSIZE_PARAMS) >= sizeof(NCCALCSIZE_PARAMS) + sizeof(WINDOWPOS) );
228 C_ASSERT( sizeof(struct packed_MSG) >= sizeof(MSG) );
229 C_ASSERT( sizeof(struct packed_MDINEXTMENU) >= sizeof(MDINEXTMENU) );
230 C_ASSERT( sizeof(struct packed_MDICREATESTRUCTW) >= sizeof(MDICREATESTRUCTW) );
231 C_ASSERT( sizeof(struct packed_hook_extra_info) >= sizeof(struct hook_extra_info) );
233 union packed_structs
235 struct packed_CREATESTRUCTW cs;
236 struct packed_DRAWITEMSTRUCT dis;
237 struct packed_MEASUREITEMSTRUCT mis;
238 struct packed_DELETEITEMSTRUCT dls;
239 struct packed_COMPAREITEMSTRUCT cis;
240 struct packed_WINDOWPOS wp;
241 struct packed_COPYDATASTRUCT cds;
242 struct packed_HELPINFO hi;
243 struct packed_NCCALCSIZE_PARAMS ncp;
244 struct packed_MSG msg;
245 struct packed_MDINEXTMENU mnm;
246 struct packed_MDICREATESTRUCTW mcs;
247 struct packed_hook_extra_info hook;
250 /* description of the data fields that need to be packed along with a sent message */
251 struct packed_message
253 union packed_structs ps;
254 int count;
255 const void *data[MAX_PACK_COUNT];
256 size_t size[MAX_PACK_COUNT];
259 /* info about the message currently being received by the current thread */
260 struct received_message_info
262 enum message_type type;
263 MSG msg;
264 UINT flags; /* InSendMessageEx return flags */
267 /* structure to group all parameters for sent messages of the various kinds */
268 struct send_message_info
270 enum message_type type;
271 DWORD dest_tid;
272 HWND hwnd;
273 UINT msg;
274 WPARAM wparam;
275 LPARAM lparam;
276 UINT flags; /* flags for SendMessageTimeout */
277 UINT timeout; /* timeout for SendMessageTimeout */
278 SENDASYNCPROC callback; /* callback function for SendMessageCallback */
279 ULONG_PTR data; /* callback data */
280 enum wm_char_mapping wm_char;
284 /* Message class descriptor */
285 static const WCHAR messageW[] = {'M','e','s','s','a','g','e',0};
287 const struct builtin_class_descr MESSAGE_builtin_class =
289 messageW, /* name */
290 0, /* style */
291 WINPROC_MESSAGE, /* proc */
292 0, /* extra */
293 IDC_ARROW, /* cursor */
294 0 /* brush */
299 /* flag for messages that contain pointers */
300 /* 32 messages per entry, messages 0..31 map to bits 0..31 */
302 #define SET(msg) (1 << ((msg) & 31))
304 static const unsigned int message_pointer_flags[] =
306 /* 0x00 - 0x1f */
307 SET(WM_CREATE) | SET(WM_SETTEXT) | SET(WM_GETTEXT) |
308 SET(WM_WININICHANGE) | SET(WM_DEVMODECHANGE),
309 /* 0x20 - 0x3f */
310 SET(WM_GETMINMAXINFO) | SET(WM_DRAWITEM) | SET(WM_MEASUREITEM) | SET(WM_DELETEITEM) |
311 SET(WM_COMPAREITEM),
312 /* 0x40 - 0x5f */
313 SET(WM_WINDOWPOSCHANGING) | SET(WM_WINDOWPOSCHANGED) | SET(WM_COPYDATA) |
314 SET(WM_NOTIFY) | SET(WM_HELP),
315 /* 0x60 - 0x7f */
316 SET(WM_STYLECHANGING) | SET(WM_STYLECHANGED),
317 /* 0x80 - 0x9f */
318 SET(WM_NCCREATE) | SET(WM_NCCALCSIZE) | SET(WM_GETDLGCODE),
319 /* 0xa0 - 0xbf */
320 SET(EM_GETSEL) | SET(EM_GETRECT) | SET(EM_SETRECT) | SET(EM_SETRECTNP),
321 /* 0xc0 - 0xdf */
322 SET(EM_REPLACESEL) | SET(EM_GETLINE) | SET(EM_SETTABSTOPS),
323 /* 0xe0 - 0xff */
324 SET(SBM_GETRANGE) | SET(SBM_SETSCROLLINFO) | SET(SBM_GETSCROLLINFO) | SET(SBM_GETSCROLLBARINFO),
325 /* 0x100 - 0x11f */
327 /* 0x120 - 0x13f */
329 /* 0x140 - 0x15f */
330 SET(CB_GETEDITSEL) | SET(CB_ADDSTRING) | SET(CB_DIR) | SET(CB_GETLBTEXT) |
331 SET(CB_INSERTSTRING) | SET(CB_FINDSTRING) | SET(CB_SELECTSTRING) |
332 SET(CB_GETDROPPEDCONTROLRECT) | SET(CB_FINDSTRINGEXACT),
333 /* 0x160 - 0x17f */
335 /* 0x180 - 0x19f */
336 SET(LB_ADDSTRING) | SET(LB_INSERTSTRING) | SET(LB_GETTEXT) | SET(LB_SELECTSTRING) |
337 SET(LB_DIR) | SET(LB_FINDSTRING) |
338 SET(LB_GETSELITEMS) | SET(LB_SETTABSTOPS) | SET(LB_ADDFILE) | SET(LB_GETITEMRECT),
339 /* 0x1a0 - 0x1bf */
340 SET(LB_FINDSTRINGEXACT),
341 /* 0x1c0 - 0x1df */
343 /* 0x1e0 - 0x1ff */
345 /* 0x200 - 0x21f */
346 SET(WM_NEXTMENU) | SET(WM_SIZING) | SET(WM_MOVING) | SET(WM_DEVICECHANGE),
347 /* 0x220 - 0x23f */
348 SET(WM_MDICREATE) | SET(WM_MDIGETACTIVE) | SET(WM_DROPOBJECT) |
349 SET(WM_QUERYDROPOBJECT) | SET(WM_DRAGLOOP) | SET(WM_DRAGSELECT) | SET(WM_DRAGMOVE),
350 /* 0x240 - 0x25f */
352 /* 0x260 - 0x27f */
354 /* 0x280 - 0x29f */
356 /* 0x2a0 - 0x2bf */
358 /* 0x2c0 - 0x2df */
360 /* 0x2e0 - 0x2ff */
362 /* 0x300 - 0x31f */
363 SET(WM_ASKCBFORMATNAME)
366 /* flags for messages that contain Unicode strings */
367 static const unsigned int message_unicode_flags[] =
369 /* 0x00 - 0x1f */
370 SET(WM_CREATE) | SET(WM_SETTEXT) | SET(WM_GETTEXT) | SET(WM_GETTEXTLENGTH) |
371 SET(WM_WININICHANGE) | SET(WM_DEVMODECHANGE),
372 /* 0x20 - 0x3f */
373 SET(WM_CHARTOITEM),
374 /* 0x40 - 0x5f */
376 /* 0x60 - 0x7f */
378 /* 0x80 - 0x9f */
379 SET(WM_NCCREATE),
380 /* 0xa0 - 0xbf */
382 /* 0xc0 - 0xdf */
383 SET(EM_REPLACESEL) | SET(EM_GETLINE) | SET(EM_SETPASSWORDCHAR),
384 /* 0xe0 - 0xff */
386 /* 0x100 - 0x11f */
387 SET(WM_CHAR) | SET(WM_DEADCHAR) | SET(WM_SYSCHAR) | SET(WM_SYSDEADCHAR),
388 /* 0x120 - 0x13f */
389 SET(WM_MENUCHAR),
390 /* 0x140 - 0x15f */
391 SET(CB_ADDSTRING) | SET(CB_DIR) | SET(CB_GETLBTEXT) | SET(CB_GETLBTEXTLEN) |
392 SET(CB_INSERTSTRING) | SET(CB_FINDSTRING) | SET(CB_SELECTSTRING) | SET(CB_FINDSTRINGEXACT),
393 /* 0x160 - 0x17f */
395 /* 0x180 - 0x19f */
396 SET(LB_ADDSTRING) | SET(LB_INSERTSTRING) | SET(LB_GETTEXT) | SET(LB_GETTEXTLEN) |
397 SET(LB_SELECTSTRING) | SET(LB_DIR) | SET(LB_FINDSTRING) | SET(LB_ADDFILE),
398 /* 0x1a0 - 0x1bf */
399 SET(LB_FINDSTRINGEXACT),
400 /* 0x1c0 - 0x1df */
402 /* 0x1e0 - 0x1ff */
404 /* 0x200 - 0x21f */
406 /* 0x220 - 0x23f */
407 SET(WM_MDICREATE),
408 /* 0x240 - 0x25f */
410 /* 0x260 - 0x27f */
412 /* 0x280 - 0x29f */
413 SET(WM_IME_CHAR),
414 /* 0x2a0 - 0x2bf */
416 /* 0x2c0 - 0x2df */
418 /* 0x2e0 - 0x2ff */
420 /* 0x300 - 0x31f */
421 SET(WM_PAINTCLIPBOARD) | SET(WM_SIZECLIPBOARD) | SET(WM_ASKCBFORMATNAME)
424 /* check whether a given message type includes pointers */
425 static inline int is_pointer_message( UINT message )
427 if (message >= 8*sizeof(message_pointer_flags)) return FALSE;
428 return (message_pointer_flags[message / 32] & SET(message)) != 0;
431 /* check whether a given message type contains Unicode (or ASCII) chars */
432 static inline int is_unicode_message( UINT message )
434 if (message >= 8*sizeof(message_unicode_flags)) return FALSE;
435 return (message_unicode_flags[message / 32] & SET(message)) != 0;
438 #undef SET
440 /* add a data field to a packed message */
441 static inline void push_data( struct packed_message *data, const void *ptr, size_t size )
443 data->data[data->count] = ptr;
444 data->size[data->count] = size;
445 data->count++;
448 /* add a string to a packed message */
449 static inline void push_string( struct packed_message *data, LPCWSTR str )
451 push_data( data, str, (strlenW(str) + 1) * sizeof(WCHAR) );
454 /* make sure that the buffer contains a valid null-terminated Unicode string */
455 static inline BOOL check_string( LPCWSTR str, size_t size )
457 for (size /= sizeof(WCHAR); size; size--, str++)
458 if (!*str) return TRUE;
459 return FALSE;
462 /* pack a pointer into a 32/64 portable format */
463 static inline ULONGLONG pack_ptr( const void *ptr )
465 return (ULONG_PTR)ptr;
468 /* unpack a potentially 64-bit pointer, returning 0 when truncated */
469 static inline void *unpack_ptr( ULONGLONG ptr64 )
471 if ((ULONG_PTR)ptr64 != ptr64) return 0;
472 return (void *)(ULONG_PTR)ptr64;
475 /* make sure that there is space for 'size' bytes in buffer, growing it if needed */
476 static inline void *get_buffer_space( void **buffer, size_t size )
478 void *ret;
480 if (*buffer)
482 if (!(ret = HeapReAlloc( GetProcessHeap(), 0, *buffer, size )))
483 HeapFree( GetProcessHeap(), 0, *buffer );
485 else ret = HeapAlloc( GetProcessHeap(), 0, size );
487 *buffer = ret;
488 return ret;
491 /* check whether a combobox expects strings or ids in CB_ADDSTRING/CB_INSERTSTRING */
492 static inline BOOL combobox_has_strings( HWND hwnd )
494 DWORD style = GetWindowLongA( hwnd, GWL_STYLE );
495 return (!(style & (CBS_OWNERDRAWFIXED | CBS_OWNERDRAWVARIABLE)) || (style & CBS_HASSTRINGS));
498 /* check whether a listbox expects strings or ids in LB_ADDSTRING/LB_INSERTSTRING */
499 static inline BOOL listbox_has_strings( HWND hwnd )
501 DWORD style = GetWindowLongA( hwnd, GWL_STYLE );
502 return (!(style & (LBS_OWNERDRAWFIXED | LBS_OWNERDRAWVARIABLE)) || (style & LBS_HASSTRINGS));
505 /* check whether message is in the range of keyboard messages */
506 static inline BOOL is_keyboard_message( UINT message )
508 return (message >= WM_KEYFIRST && message <= WM_KEYLAST);
511 /* check whether message is in the range of mouse messages */
512 static inline BOOL is_mouse_message( UINT message )
514 return ((message >= WM_NCMOUSEFIRST && message <= WM_NCMOUSELAST) ||
515 (message >= WM_MOUSEFIRST && message <= WM_MOUSELAST));
518 /* check whether message matches the specified hwnd filter */
519 static inline BOOL check_hwnd_filter( const MSG *msg, HWND hwnd_filter )
521 if (!hwnd_filter || hwnd_filter == GetDesktopWindow()) return TRUE;
522 return (msg->hwnd == hwnd_filter || IsChild( hwnd_filter, msg->hwnd ));
525 /* check for pending WM_CHAR message with DBCS trailing byte */
526 static inline BOOL get_pending_wmchar( MSG *msg, UINT first, UINT last, BOOL remove )
528 struct wm_char_mapping_data *data = get_user_thread_info()->wmchar_data;
530 if (!data || !data->get_msg.message) return FALSE;
531 if ((first || last) && (first > WM_CHAR || last < WM_CHAR)) return FALSE;
532 if (!msg) return FALSE;
533 *msg = data->get_msg;
534 if (remove) data->get_msg.message = 0;
535 return TRUE;
539 /***********************************************************************
540 * MessageWndProc
542 * Window procedure for "Message" windows (HWND_MESSAGE parent).
544 LRESULT WINAPI MessageWndProc( HWND hwnd, UINT message, WPARAM wParam, LPARAM lParam )
546 if (message == WM_NCCREATE) return TRUE;
547 return 0; /* all other messages are ignored */
551 /***********************************************************************
552 * broadcast_message_callback
554 * Helper callback for broadcasting messages.
556 static BOOL CALLBACK broadcast_message_callback( HWND hwnd, LPARAM lparam )
558 struct send_message_info *info = (struct send_message_info *)lparam;
559 if (!(GetWindowLongW( hwnd, GWL_STYLE ) & (WS_POPUP|WS_CAPTION))) return TRUE;
560 switch(info->type)
562 case MSG_UNICODE:
563 SendMessageTimeoutW( hwnd, info->msg, info->wparam, info->lparam,
564 info->flags, info->timeout, NULL );
565 break;
566 case MSG_ASCII:
567 SendMessageTimeoutA( hwnd, info->msg, info->wparam, info->lparam,
568 info->flags, info->timeout, NULL );
569 break;
570 case MSG_NOTIFY:
571 SendNotifyMessageW( hwnd, info->msg, info->wparam, info->lparam );
572 break;
573 case MSG_CALLBACK:
574 SendMessageCallbackW( hwnd, info->msg, info->wparam, info->lparam,
575 info->callback, info->data );
576 break;
577 case MSG_POSTED:
578 PostMessageW( hwnd, info->msg, info->wparam, info->lparam );
579 break;
580 default:
581 ERR( "bad type %d\n", info->type );
582 break;
584 return TRUE;
588 /***********************************************************************
589 * map_wparam_AtoW
591 * Convert the wparam of an ASCII message to Unicode.
593 BOOL map_wparam_AtoW( UINT message, WPARAM *wparam, enum wm_char_mapping mapping )
595 char ch[2];
596 WCHAR wch[2];
598 wch[0] = wch[1] = 0;
599 switch(message)
601 case WM_CHAR:
602 /* WM_CHAR is magic: a DBCS char can be sent/posted as two consecutive WM_CHAR
603 * messages, in which case the first char is stored, and the conversion
604 * to Unicode only takes place once the second char is sent/posted.
606 if (mapping != WMCHAR_MAP_NOMAPPING)
608 struct wm_char_mapping_data *data = get_user_thread_info()->wmchar_data;
609 BYTE low = LOBYTE(*wparam);
611 if (HIBYTE(*wparam))
613 ch[0] = low;
614 ch[1] = HIBYTE(*wparam);
615 RtlMultiByteToUnicodeN( wch, sizeof(wch), NULL, ch, 2 );
616 TRACE( "map %02x,%02x -> %04x mapping %u\n", (BYTE)ch[0], (BYTE)ch[1], wch[0], mapping );
617 if (data) data->lead_byte[mapping] = 0;
619 else if (data && data->lead_byte[mapping])
621 ch[0] = data->lead_byte[mapping];
622 ch[1] = low;
623 RtlMultiByteToUnicodeN( wch, sizeof(wch), NULL, ch, 2 );
624 TRACE( "map stored %02x,%02x -> %04x mapping %u\n", (BYTE)ch[0], (BYTE)ch[1], wch[0], mapping );
625 data->lead_byte[mapping] = 0;
627 else if (!IsDBCSLeadByte( low ))
629 ch[0] = low;
630 RtlMultiByteToUnicodeN( wch, sizeof(wch), NULL, ch, 1 );
631 TRACE( "map %02x -> %04x\n", (BYTE)ch[0], wch[0] );
632 if (data) data->lead_byte[mapping] = 0;
634 else /* store it and wait for trail byte */
636 if (!data)
638 if (!(data = HeapAlloc( GetProcessHeap(), HEAP_ZERO_MEMORY, sizeof(*data) )))
639 return FALSE;
640 get_user_thread_info()->wmchar_data = data;
642 TRACE( "storing lead byte %02x mapping %u\n", low, mapping );
643 data->lead_byte[mapping] = low;
644 return FALSE;
646 *wparam = MAKEWPARAM(wch[0], wch[1]);
647 break;
649 /* else fall through */
650 case WM_CHARTOITEM:
651 case EM_SETPASSWORDCHAR:
652 case WM_DEADCHAR:
653 case WM_SYSCHAR:
654 case WM_SYSDEADCHAR:
655 case WM_MENUCHAR:
656 ch[0] = LOBYTE(*wparam);
657 ch[1] = HIBYTE(*wparam);
658 RtlMultiByteToUnicodeN( wch, sizeof(wch), NULL, ch, 2 );
659 *wparam = MAKEWPARAM(wch[0], wch[1]);
660 break;
661 case WM_IME_CHAR:
662 ch[0] = HIBYTE(*wparam);
663 ch[1] = LOBYTE(*wparam);
664 if (ch[0]) RtlMultiByteToUnicodeN( wch, sizeof(wch[0]), NULL, ch, 2 );
665 else RtlMultiByteToUnicodeN( wch, sizeof(wch[0]), NULL, ch + 1, 1 );
666 *wparam = MAKEWPARAM(wch[0], HIWORD(*wparam));
667 break;
669 return TRUE;
673 /***********************************************************************
674 * map_wparam_WtoA
676 * Convert the wparam of a Unicode message to ASCII.
678 static void map_wparam_WtoA( MSG *msg, BOOL remove )
680 BYTE ch[2];
681 WCHAR wch[2];
682 DWORD len;
684 switch(msg->message)
686 case WM_CHAR:
687 if (!HIWORD(msg->wParam))
689 wch[0] = LOWORD(msg->wParam);
690 ch[0] = ch[1] = 0;
691 RtlUnicodeToMultiByteN( (LPSTR)ch, 2, &len, wch, sizeof(wch[0]) );
692 if (len == 2) /* DBCS char */
694 struct wm_char_mapping_data *data = get_user_thread_info()->wmchar_data;
695 if (!data)
697 if (!(data = HeapAlloc( GetProcessHeap(), HEAP_ZERO_MEMORY, sizeof(*data) ))) return;
698 get_user_thread_info()->wmchar_data = data;
700 if (remove)
702 data->get_msg = *msg;
703 data->get_msg.wParam = ch[1];
705 msg->wParam = ch[0];
706 return;
709 /* else fall through */
710 case WM_CHARTOITEM:
711 case EM_SETPASSWORDCHAR:
712 case WM_DEADCHAR:
713 case WM_SYSCHAR:
714 case WM_SYSDEADCHAR:
715 case WM_MENUCHAR:
716 wch[0] = LOWORD(msg->wParam);
717 wch[1] = HIWORD(msg->wParam);
718 ch[0] = ch[1] = 0;
719 RtlUnicodeToMultiByteN( (LPSTR)ch, 2, NULL, wch, sizeof(wch) );
720 msg->wParam = MAKEWPARAM( ch[0] | (ch[1] << 8), 0 );
721 break;
722 case WM_IME_CHAR:
723 wch[0] = LOWORD(msg->wParam);
724 ch[0] = ch[1] = 0;
725 RtlUnicodeToMultiByteN( (LPSTR)ch, 2, &len, wch, sizeof(wch[0]) );
726 if (len == 2)
727 msg->wParam = MAKEWPARAM( (ch[0] << 8) | ch[1], HIWORD(msg->wParam) );
728 else
729 msg->wParam = MAKEWPARAM( ch[0], HIWORD(msg->wParam) );
730 break;
735 /***********************************************************************
736 * pack_message
738 * Pack a message for sending to another process.
739 * Return the size of the data we expect in the message reply.
740 * Set data->count to -1 if there is an error.
742 static size_t pack_message( HWND hwnd, UINT message, WPARAM wparam, LPARAM lparam,
743 struct packed_message *data )
745 data->count = 0;
746 switch(message)
748 case WM_NCCREATE:
749 case WM_CREATE:
751 CREATESTRUCTW *cs = (CREATESTRUCTW *)lparam;
752 data->ps.cs.lpCreateParams = pack_ptr( cs->lpCreateParams );
753 data->ps.cs.hInstance = pack_ptr( cs->hInstance );
754 data->ps.cs.hMenu = wine_server_user_handle( cs->hMenu );
755 data->ps.cs.hwndParent = wine_server_user_handle( cs->hwndParent );
756 data->ps.cs.cy = cs->cy;
757 data->ps.cs.cx = cs->cx;
758 data->ps.cs.y = cs->y;
759 data->ps.cs.x = cs->x;
760 data->ps.cs.style = cs->style;
761 data->ps.cs.dwExStyle = cs->dwExStyle;
762 data->ps.cs.lpszName = pack_ptr( cs->lpszName );
763 data->ps.cs.lpszClass = pack_ptr( cs->lpszClass );
764 push_data( data, &data->ps.cs, sizeof(data->ps.cs) );
765 if (!IS_INTRESOURCE(cs->lpszName)) push_string( data, cs->lpszName );
766 if (!IS_INTRESOURCE(cs->lpszClass)) push_string( data, cs->lpszClass );
767 return sizeof(data->ps.cs);
769 case WM_GETTEXT:
770 case WM_ASKCBFORMATNAME:
771 return wparam * sizeof(WCHAR);
772 case WM_WININICHANGE:
773 if (lparam) push_string(data, (LPWSTR)lparam );
774 return 0;
775 case WM_SETTEXT:
776 case WM_DEVMODECHANGE:
777 case CB_DIR:
778 case LB_DIR:
779 case LB_ADDFILE:
780 case EM_REPLACESEL:
781 push_string( data, (LPWSTR)lparam );
782 return 0;
783 case WM_GETMINMAXINFO:
784 push_data( data, (MINMAXINFO *)lparam, sizeof(MINMAXINFO) );
785 return sizeof(MINMAXINFO);
786 case WM_DRAWITEM:
788 DRAWITEMSTRUCT *dis = (DRAWITEMSTRUCT *)lparam;
789 data->ps.dis.CtlType = dis->CtlType;
790 data->ps.dis.CtlID = dis->CtlID;
791 data->ps.dis.itemID = dis->itemID;
792 data->ps.dis.itemAction = dis->itemAction;
793 data->ps.dis.itemState = dis->itemState;
794 data->ps.dis.hwndItem = wine_server_user_handle( dis->hwndItem );
795 data->ps.dis.hDC = wine_server_user_handle( dis->hDC ); /* FIXME */
796 data->ps.dis.rcItem = dis->rcItem;
797 data->ps.dis.itemData = dis->itemData;
798 push_data( data, &data->ps.dis, sizeof(data->ps.dis) );
799 return 0;
801 case WM_MEASUREITEM:
803 MEASUREITEMSTRUCT *mis = (MEASUREITEMSTRUCT *)lparam;
804 data->ps.mis.CtlType = mis->CtlType;
805 data->ps.mis.CtlID = mis->CtlID;
806 data->ps.mis.itemID = mis->itemID;
807 data->ps.mis.itemWidth = mis->itemWidth;
808 data->ps.mis.itemHeight = mis->itemHeight;
809 data->ps.mis.itemData = mis->itemData;
810 push_data( data, &data->ps.mis, sizeof(data->ps.mis) );
811 return sizeof(data->ps.mis);
813 case WM_DELETEITEM:
815 DELETEITEMSTRUCT *dls = (DELETEITEMSTRUCT *)lparam;
816 data->ps.dls.CtlType = dls->CtlType;
817 data->ps.dls.CtlID = dls->CtlID;
818 data->ps.dls.itemID = dls->itemID;
819 data->ps.dls.hwndItem = wine_server_user_handle( dls->hwndItem );
820 data->ps.dls.itemData = dls->itemData;
821 push_data( data, &data->ps.dls, sizeof(data->ps.dls) );
822 return 0;
824 case WM_COMPAREITEM:
826 COMPAREITEMSTRUCT *cis = (COMPAREITEMSTRUCT *)lparam;
827 data->ps.cis.CtlType = cis->CtlType;
828 data->ps.cis.CtlID = cis->CtlID;
829 data->ps.cis.hwndItem = wine_server_user_handle( cis->hwndItem );
830 data->ps.cis.itemID1 = cis->itemID1;
831 data->ps.cis.itemData1 = cis->itemData1;
832 data->ps.cis.itemID2 = cis->itemID2;
833 data->ps.cis.itemData2 = cis->itemData2;
834 data->ps.cis.dwLocaleId = cis->dwLocaleId;
835 push_data( data, &data->ps.cis, sizeof(data->ps.cis) );
836 return 0;
838 case WM_WINE_SETWINDOWPOS:
839 case WM_WINDOWPOSCHANGING:
840 case WM_WINDOWPOSCHANGED:
842 WINDOWPOS *wp = (WINDOWPOS *)lparam;
843 data->ps.wp.hwnd = wine_server_user_handle( wp->hwnd );
844 data->ps.wp.hwndInsertAfter = wine_server_user_handle( wp->hwndInsertAfter );
845 data->ps.wp.x = wp->x;
846 data->ps.wp.y = wp->y;
847 data->ps.wp.cx = wp->cx;
848 data->ps.wp.cy = wp->cy;
849 data->ps.wp.flags = wp->flags;
850 push_data( data, &data->ps.wp, sizeof(data->ps.wp) );
851 return sizeof(data->ps.wp);
853 case WM_COPYDATA:
855 COPYDATASTRUCT *cds = (COPYDATASTRUCT *)lparam;
856 data->ps.cds.cbData = cds->cbData;
857 data->ps.cds.dwData = cds->dwData;
858 data->ps.cds.lpData = pack_ptr( cds->lpData );
859 push_data( data, &data->ps.cds, sizeof(data->ps.cds) );
860 if (cds->lpData) push_data( data, cds->lpData, cds->cbData );
861 return 0;
863 case WM_NOTIFY:
864 /* WM_NOTIFY cannot be sent across processes (MSDN) */
865 data->count = -1;
866 return 0;
867 case WM_HELP:
869 HELPINFO *hi = (HELPINFO *)lparam;
870 data->ps.hi.iContextType = hi->iContextType;
871 data->ps.hi.iCtrlId = hi->iCtrlId;
872 data->ps.hi.hItemHandle = wine_server_user_handle( hi->hItemHandle );
873 data->ps.hi.dwContextId = hi->dwContextId;
874 data->ps.hi.MousePos = hi->MousePos;
875 push_data( data, &data->ps.hi, sizeof(data->ps.hi) );
876 return 0;
878 case WM_STYLECHANGING:
879 case WM_STYLECHANGED:
880 push_data( data, (STYLESTRUCT *)lparam, sizeof(STYLESTRUCT) );
881 return 0;
882 case WM_NCCALCSIZE:
883 if (!wparam)
885 push_data( data, (RECT *)lparam, sizeof(RECT) );
886 return sizeof(RECT);
888 else
890 NCCALCSIZE_PARAMS *ncp = (NCCALCSIZE_PARAMS *)lparam;
891 data->ps.ncp.rgrc[0] = ncp->rgrc[0];
892 data->ps.ncp.rgrc[1] = ncp->rgrc[1];
893 data->ps.ncp.rgrc[2] = ncp->rgrc[2];
894 data->ps.ncp.hwnd = wine_server_user_handle( ncp->lppos->hwnd );
895 data->ps.ncp.hwndInsertAfter = wine_server_user_handle( ncp->lppos->hwndInsertAfter );
896 data->ps.ncp.x = ncp->lppos->x;
897 data->ps.ncp.y = ncp->lppos->y;
898 data->ps.ncp.cx = ncp->lppos->cx;
899 data->ps.ncp.cy = ncp->lppos->cy;
900 data->ps.ncp.flags = ncp->lppos->flags;
901 push_data( data, &data->ps.ncp, sizeof(data->ps.ncp) );
902 return sizeof(data->ps.ncp);
904 case WM_GETDLGCODE:
905 if (lparam)
907 MSG *msg = (MSG *)lparam;
908 data->ps.msg.hwnd = wine_server_user_handle( msg->hwnd );
909 data->ps.msg.message = msg->message;
910 data->ps.msg.wParam = msg->wParam;
911 data->ps.msg.lParam = msg->lParam;
912 data->ps.msg.time = msg->time;
913 data->ps.msg.pt = msg->pt;
914 push_data( data, &data->ps.msg, sizeof(data->ps.msg) );
915 return sizeof(data->ps.msg);
917 return 0;
918 case SBM_SETSCROLLINFO:
919 push_data( data, (SCROLLINFO *)lparam, sizeof(SCROLLINFO) );
920 return 0;
921 case SBM_GETSCROLLINFO:
922 push_data( data, (SCROLLINFO *)lparam, sizeof(SCROLLINFO) );
923 return sizeof(SCROLLINFO);
924 case SBM_GETSCROLLBARINFO:
926 const SCROLLBARINFO *info = (const SCROLLBARINFO *)lparam;
927 size_t size = min( info->cbSize, sizeof(SCROLLBARINFO) );
928 push_data( data, info, size );
929 return size;
931 case EM_GETSEL:
932 case SBM_GETRANGE:
933 case CB_GETEDITSEL:
935 size_t size = 0;
936 if (wparam) size += sizeof(DWORD);
937 if (lparam) size += sizeof(DWORD);
938 return size;
940 case EM_GETRECT:
941 case LB_GETITEMRECT:
942 case CB_GETDROPPEDCONTROLRECT:
943 return sizeof(RECT);
944 case EM_SETRECT:
945 case EM_SETRECTNP:
946 push_data( data, (RECT *)lparam, sizeof(RECT) );
947 return 0;
948 case EM_GETLINE:
950 WORD *pw = (WORD *)lparam;
951 push_data( data, pw, sizeof(*pw) );
952 return *pw * sizeof(WCHAR);
954 case EM_SETTABSTOPS:
955 case LB_SETTABSTOPS:
956 if (wparam) push_data( data, (UINT *)lparam, sizeof(UINT) * wparam );
957 return 0;
958 case CB_ADDSTRING:
959 case CB_INSERTSTRING:
960 case CB_FINDSTRING:
961 case CB_FINDSTRINGEXACT:
962 case CB_SELECTSTRING:
963 if (combobox_has_strings( hwnd )) push_string( data, (LPWSTR)lparam );
964 return 0;
965 case CB_GETLBTEXT:
966 if (!combobox_has_strings( hwnd )) return sizeof(ULONG_PTR);
967 return (SendMessageW( hwnd, CB_GETLBTEXTLEN, wparam, 0 ) + 1) * sizeof(WCHAR);
968 case LB_ADDSTRING:
969 case LB_INSERTSTRING:
970 case LB_FINDSTRING:
971 case LB_FINDSTRINGEXACT:
972 case LB_SELECTSTRING:
973 if (listbox_has_strings( hwnd )) push_string( data, (LPWSTR)lparam );
974 return 0;
975 case LB_GETTEXT:
976 if (!listbox_has_strings( hwnd )) return sizeof(ULONG_PTR);
977 return (SendMessageW( hwnd, LB_GETTEXTLEN, wparam, 0 ) + 1) * sizeof(WCHAR);
978 case LB_GETSELITEMS:
979 return wparam * sizeof(UINT);
980 case WM_NEXTMENU:
982 MDINEXTMENU *mnm = (MDINEXTMENU *)lparam;
983 data->ps.mnm.hmenuIn = wine_server_user_handle( mnm->hmenuIn );
984 data->ps.mnm.hmenuNext = wine_server_user_handle( mnm->hmenuNext );
985 data->ps.mnm.hwndNext = wine_server_user_handle( mnm->hwndNext );
986 push_data( data, &data->ps.mnm, sizeof(data->ps.mnm) );
987 return sizeof(data->ps.mnm);
989 case WM_SIZING:
990 case WM_MOVING:
991 push_data( data, (RECT *)lparam, sizeof(RECT) );
992 return sizeof(RECT);
993 case WM_MDICREATE:
995 MDICREATESTRUCTW *mcs = (MDICREATESTRUCTW *)lparam;
996 data->ps.mcs.szClass = pack_ptr( mcs->szClass );
997 data->ps.mcs.szTitle = pack_ptr( mcs->szTitle );
998 data->ps.mcs.hOwner = pack_ptr( mcs->hOwner );
999 data->ps.mcs.x = mcs->x;
1000 data->ps.mcs.y = mcs->y;
1001 data->ps.mcs.cx = mcs->cx;
1002 data->ps.mcs.cy = mcs->cy;
1003 data->ps.mcs.style = mcs->style;
1004 data->ps.mcs.lParam = mcs->lParam;
1005 push_data( data, &data->ps.mcs, sizeof(data->ps.mcs) );
1006 if (!IS_INTRESOURCE(mcs->szClass)) push_string( data, mcs->szClass );
1007 if (!IS_INTRESOURCE(mcs->szTitle)) push_string( data, mcs->szTitle );
1008 return sizeof(data->ps.mcs);
1010 case WM_MDIGETACTIVE:
1011 if (lparam) return sizeof(BOOL);
1012 return 0;
1013 case WM_DEVICECHANGE:
1015 DEV_BROADCAST_HDR *header = (DEV_BROADCAST_HDR *)lparam;
1016 push_data( data, header, header->dbch_size );
1017 return 0;
1019 case WM_WINE_KEYBOARD_LL_HOOK:
1021 struct hook_extra_info *h_extra = (struct hook_extra_info *)lparam;
1022 data->ps.hook.handle = wine_server_user_handle( h_extra->handle );
1023 push_data( data, &data->ps.hook, sizeof(data->ps.hook) );
1024 push_data( data, (LPVOID)h_extra->lparam, sizeof(KBDLLHOOKSTRUCT) );
1025 return 0;
1027 case WM_WINE_MOUSE_LL_HOOK:
1029 struct hook_extra_info *h_extra = (struct hook_extra_info *)lparam;
1030 data->ps.hook.handle = wine_server_user_handle( h_extra->handle );
1031 push_data( data, &data->ps.hook, sizeof(data->ps.hook) );
1032 push_data( data, (LPVOID)h_extra->lparam, sizeof(MSLLHOOKSTRUCT) );
1033 return 0;
1035 case WM_NCPAINT:
1036 if (wparam <= 1) return 0;
1037 FIXME( "WM_NCPAINT hdc packing not supported yet\n" );
1038 data->count = -1;
1039 return 0;
1040 case WM_PAINT:
1041 if (!wparam) return 0;
1042 /* fall through */
1044 /* these contain an HFONT */
1045 case WM_SETFONT:
1046 case WM_GETFONT:
1047 /* these contain an HDC */
1048 case WM_ERASEBKGND:
1049 case WM_ICONERASEBKGND:
1050 case WM_CTLCOLORMSGBOX:
1051 case WM_CTLCOLOREDIT:
1052 case WM_CTLCOLORLISTBOX:
1053 case WM_CTLCOLORBTN:
1054 case WM_CTLCOLORDLG:
1055 case WM_CTLCOLORSCROLLBAR:
1056 case WM_CTLCOLORSTATIC:
1057 case WM_PRINT:
1058 case WM_PRINTCLIENT:
1059 /* these contain an HGLOBAL */
1060 case WM_PAINTCLIPBOARD:
1061 case WM_SIZECLIPBOARD:
1062 /* these contain HICON */
1063 case WM_GETICON:
1064 case WM_SETICON:
1065 case WM_QUERYDRAGICON:
1066 case WM_QUERYPARKICON:
1067 /* these contain pointers */
1068 case WM_DROPOBJECT:
1069 case WM_QUERYDROPOBJECT:
1070 case WM_DRAGLOOP:
1071 case WM_DRAGSELECT:
1072 case WM_DRAGMOVE:
1073 FIXME( "msg %x (%s) not supported yet\n", message, SPY_GetMsgName(message, hwnd) );
1074 data->count = -1;
1075 return 0;
1077 return 0;
1081 /***********************************************************************
1082 * unpack_message
1084 * Unpack a message received from another process.
1086 static BOOL unpack_message( HWND hwnd, UINT message, WPARAM *wparam, LPARAM *lparam,
1087 void **buffer, size_t size )
1089 size_t minsize = 0;
1090 union packed_structs *ps = *buffer;
1092 switch(message)
1094 case WM_NCCREATE:
1095 case WM_CREATE:
1097 CREATESTRUCTW cs;
1098 WCHAR *str = (WCHAR *)(&ps->cs + 1);
1099 if (size < sizeof(ps->cs)) return FALSE;
1100 size -= sizeof(ps->cs);
1101 cs.lpCreateParams = unpack_ptr( ps->cs.lpCreateParams );
1102 cs.hInstance = unpack_ptr( ps->cs.hInstance );
1103 cs.hMenu = wine_server_ptr_handle( ps->cs.hMenu );
1104 cs.hwndParent = wine_server_ptr_handle( ps->cs.hwndParent );
1105 cs.cy = ps->cs.cy;
1106 cs.cx = ps->cs.cx;
1107 cs.y = ps->cs.y;
1108 cs.x = ps->cs.x;
1109 cs.style = ps->cs.style;
1110 cs.dwExStyle = ps->cs.dwExStyle;
1111 cs.lpszName = unpack_ptr( ps->cs.lpszName );
1112 cs.lpszClass = unpack_ptr( ps->cs.lpszClass );
1113 if (ps->cs.lpszName >> 16)
1115 if (!check_string( str, size )) return FALSE;
1116 cs.lpszName = str;
1117 size -= (strlenW(str) + 1) * sizeof(WCHAR);
1118 str += strlenW(str) + 1;
1120 if (ps->cs.lpszClass >> 16)
1122 if (!check_string( str, size )) return FALSE;
1123 cs.lpszClass = str;
1125 memcpy( &ps->cs, &cs, sizeof(cs) );
1126 break;
1128 case WM_GETTEXT:
1129 case WM_ASKCBFORMATNAME:
1130 if (!get_buffer_space( buffer, (*wparam * sizeof(WCHAR)) )) return FALSE;
1131 break;
1132 case WM_WININICHANGE:
1133 if (!*lparam) return TRUE;
1134 /* fall through */
1135 case WM_SETTEXT:
1136 case WM_DEVMODECHANGE:
1137 case CB_DIR:
1138 case LB_DIR:
1139 case LB_ADDFILE:
1140 case EM_REPLACESEL:
1141 if (!check_string( *buffer, size )) return FALSE;
1142 break;
1143 case WM_GETMINMAXINFO:
1144 minsize = sizeof(MINMAXINFO);
1145 break;
1146 case WM_DRAWITEM:
1148 DRAWITEMSTRUCT dis;
1149 if (size < sizeof(ps->dis)) return FALSE;
1150 dis.CtlType = ps->dis.CtlType;
1151 dis.CtlID = ps->dis.CtlID;
1152 dis.itemID = ps->dis.itemID;
1153 dis.itemAction = ps->dis.itemAction;
1154 dis.itemState = ps->dis.itemState;
1155 dis.hwndItem = wine_server_ptr_handle( ps->dis.hwndItem );
1156 dis.hDC = wine_server_ptr_handle( ps->dis.hDC );
1157 dis.rcItem = ps->dis.rcItem;
1158 dis.itemData = (ULONG_PTR)unpack_ptr( ps->dis.itemData );
1159 memcpy( &ps->dis, &dis, sizeof(dis) );
1160 break;
1162 case WM_MEASUREITEM:
1164 MEASUREITEMSTRUCT mis;
1165 if (size < sizeof(ps->mis)) return FALSE;
1166 mis.CtlType = ps->mis.CtlType;
1167 mis.CtlID = ps->mis.CtlID;
1168 mis.itemID = ps->mis.itemID;
1169 mis.itemWidth = ps->mis.itemWidth;
1170 mis.itemHeight = ps->mis.itemHeight;
1171 mis.itemData = (ULONG_PTR)unpack_ptr( ps->mis.itemData );
1172 memcpy( &ps->mis, &mis, sizeof(mis) );
1173 break;
1175 case WM_DELETEITEM:
1177 DELETEITEMSTRUCT dls;
1178 if (size < sizeof(ps->dls)) return FALSE;
1179 dls.CtlType = ps->dls.CtlType;
1180 dls.CtlID = ps->dls.CtlID;
1181 dls.itemID = ps->dls.itemID;
1182 dls.hwndItem = wine_server_ptr_handle( ps->dls.hwndItem );
1183 dls.itemData = (ULONG_PTR)unpack_ptr( ps->dls.itemData );
1184 memcpy( &ps->dls, &dls, sizeof(dls) );
1185 break;
1187 case WM_COMPAREITEM:
1189 COMPAREITEMSTRUCT cis;
1190 if (size < sizeof(ps->cis)) return FALSE;
1191 cis.CtlType = ps->cis.CtlType;
1192 cis.CtlID = ps->cis.CtlID;
1193 cis.hwndItem = wine_server_ptr_handle( ps->cis.hwndItem );
1194 cis.itemID1 = ps->cis.itemID1;
1195 cis.itemData1 = (ULONG_PTR)unpack_ptr( ps->cis.itemData1 );
1196 cis.itemID2 = ps->cis.itemID2;
1197 cis.itemData2 = (ULONG_PTR)unpack_ptr( ps->cis.itemData2 );
1198 cis.dwLocaleId = ps->cis.dwLocaleId;
1199 memcpy( &ps->cis, &cis, sizeof(cis) );
1200 break;
1202 case WM_WINDOWPOSCHANGING:
1203 case WM_WINDOWPOSCHANGED:
1204 case WM_WINE_SETWINDOWPOS:
1206 WINDOWPOS wp;
1207 if (size < sizeof(ps->wp)) return FALSE;
1208 wp.hwnd = wine_server_ptr_handle( ps->wp.hwnd );
1209 wp.hwndInsertAfter = wine_server_ptr_handle( ps->wp.hwndInsertAfter );
1210 wp.x = ps->wp.x;
1211 wp.y = ps->wp.y;
1212 wp.cx = ps->wp.cx;
1213 wp.cy = ps->wp.cy;
1214 wp.flags = ps->wp.flags;
1215 memcpy( &ps->wp, &wp, sizeof(wp) );
1216 break;
1218 case WM_COPYDATA:
1220 COPYDATASTRUCT cds;
1221 if (size < sizeof(ps->cds)) return FALSE;
1222 cds.dwData = (ULONG_PTR)unpack_ptr( ps->cds.dwData );
1223 if (ps->cds.lpData)
1225 cds.cbData = ps->cds.cbData;
1226 cds.lpData = &ps->cds + 1;
1227 minsize = sizeof(ps->cds) + cds.cbData;
1229 else
1231 cds.cbData = 0;
1232 cds.lpData = 0;
1234 memcpy( &ps->cds, &cds, sizeof(cds) );
1235 break;
1237 case WM_NOTIFY:
1238 /* WM_NOTIFY cannot be sent across processes (MSDN) */
1239 return FALSE;
1240 case WM_HELP:
1242 HELPINFO hi;
1243 if (size < sizeof(ps->hi)) return FALSE;
1244 hi.cbSize = sizeof(hi);
1245 hi.iContextType = ps->hi.iContextType;
1246 hi.iCtrlId = ps->hi.iCtrlId;
1247 hi.hItemHandle = wine_server_ptr_handle( ps->hi.hItemHandle );
1248 hi.dwContextId = (ULONG_PTR)unpack_ptr( ps->hi.dwContextId );
1249 hi.MousePos = ps->hi.MousePos;
1250 memcpy( &ps->hi, &hi, sizeof(hi) );
1251 break;
1253 case WM_STYLECHANGING:
1254 case WM_STYLECHANGED:
1255 minsize = sizeof(STYLESTRUCT);
1256 break;
1257 case WM_NCCALCSIZE:
1258 if (!*wparam) minsize = sizeof(RECT);
1259 else
1261 NCCALCSIZE_PARAMS ncp;
1262 WINDOWPOS wp;
1263 if (size < sizeof(ps->ncp)) return FALSE;
1264 ncp.rgrc[0] = ps->ncp.rgrc[0];
1265 ncp.rgrc[1] = ps->ncp.rgrc[1];
1266 ncp.rgrc[2] = ps->ncp.rgrc[2];
1267 wp.hwnd = wine_server_ptr_handle( ps->ncp.hwnd );
1268 wp.hwndInsertAfter = wine_server_ptr_handle( ps->ncp.hwndInsertAfter );
1269 wp.x = ps->ncp.x;
1270 wp.y = ps->ncp.y;
1271 wp.cx = ps->ncp.cx;
1272 wp.cy = ps->ncp.cy;
1273 wp.flags = ps->ncp.flags;
1274 ncp.lppos = (WINDOWPOS *)((NCCALCSIZE_PARAMS *)&ps->ncp + 1);
1275 memcpy( &ps->ncp, &ncp, sizeof(ncp) );
1276 *ncp.lppos = wp;
1278 break;
1279 case WM_GETDLGCODE:
1280 if (*lparam)
1282 MSG msg;
1283 if (size < sizeof(ps->msg)) return FALSE;
1284 msg.hwnd = wine_server_ptr_handle( ps->msg.hwnd );
1285 msg.message = ps->msg.message;
1286 msg.wParam = (ULONG_PTR)unpack_ptr( ps->msg.wParam );
1287 msg.lParam = (ULONG_PTR)unpack_ptr( ps->msg.lParam );
1288 msg.time = ps->msg.time;
1289 msg.pt = ps->msg.pt;
1290 memcpy( &ps->msg, &msg, sizeof(msg) );
1291 break;
1293 return TRUE;
1294 case SBM_SETSCROLLINFO:
1295 minsize = sizeof(SCROLLINFO);
1296 break;
1297 case SBM_GETSCROLLINFO:
1298 if (!get_buffer_space( buffer, sizeof(SCROLLINFO ))) return FALSE;
1299 break;
1300 case SBM_GETSCROLLBARINFO:
1301 if (!get_buffer_space( buffer, sizeof(SCROLLBARINFO ))) return FALSE;
1302 break;
1303 case EM_GETSEL:
1304 case SBM_GETRANGE:
1305 case CB_GETEDITSEL:
1306 if (*wparam || *lparam)
1308 if (!get_buffer_space( buffer, 2*sizeof(DWORD) )) return FALSE;
1309 if (*wparam) *wparam = (WPARAM)*buffer;
1310 if (*lparam) *lparam = (LPARAM)((DWORD *)*buffer + 1);
1312 return TRUE;
1313 case EM_GETRECT:
1314 case LB_GETITEMRECT:
1315 case CB_GETDROPPEDCONTROLRECT:
1316 if (!get_buffer_space( buffer, sizeof(RECT) )) return FALSE;
1317 break;
1318 case EM_SETRECT:
1319 case EM_SETRECTNP:
1320 minsize = sizeof(RECT);
1321 break;
1322 case EM_GETLINE:
1324 WORD len;
1325 if (size < sizeof(WORD)) return FALSE;
1326 len = *(WORD *)*buffer;
1327 if (!get_buffer_space( buffer, (len + 1) * sizeof(WCHAR) )) return FALSE;
1328 *lparam = (LPARAM)*buffer + sizeof(WORD); /* don't erase WORD at start of buffer */
1329 return TRUE;
1331 case EM_SETTABSTOPS:
1332 case LB_SETTABSTOPS:
1333 if (!*wparam) return TRUE;
1334 minsize = *wparam * sizeof(UINT);
1335 break;
1336 case CB_ADDSTRING:
1337 case CB_INSERTSTRING:
1338 case CB_FINDSTRING:
1339 case CB_FINDSTRINGEXACT:
1340 case CB_SELECTSTRING:
1341 case LB_ADDSTRING:
1342 case LB_INSERTSTRING:
1343 case LB_FINDSTRING:
1344 case LB_FINDSTRINGEXACT:
1345 case LB_SELECTSTRING:
1346 if (!*buffer) return TRUE;
1347 if (!check_string( *buffer, size )) return FALSE;
1348 break;
1349 case CB_GETLBTEXT:
1351 size = sizeof(ULONG_PTR);
1352 if (combobox_has_strings( hwnd ))
1353 size = (SendMessageW( hwnd, CB_GETLBTEXTLEN, *wparam, 0 ) + 1) * sizeof(WCHAR);
1354 if (!get_buffer_space( buffer, size )) return FALSE;
1355 break;
1357 case LB_GETTEXT:
1359 size = sizeof(ULONG_PTR);
1360 if (listbox_has_strings( hwnd ))
1361 size = (SendMessageW( hwnd, LB_GETTEXTLEN, *wparam, 0 ) + 1) * sizeof(WCHAR);
1362 if (!get_buffer_space( buffer, size )) return FALSE;
1363 break;
1365 case LB_GETSELITEMS:
1366 if (!get_buffer_space( buffer, *wparam * sizeof(UINT) )) return FALSE;
1367 break;
1368 case WM_NEXTMENU:
1370 MDINEXTMENU mnm;
1371 if (size < sizeof(ps->mnm)) return FALSE;
1372 mnm.hmenuIn = wine_server_ptr_handle( ps->mnm.hmenuIn );
1373 mnm.hmenuNext = wine_server_ptr_handle( ps->mnm.hmenuNext );
1374 mnm.hwndNext = wine_server_ptr_handle( ps->mnm.hwndNext );
1375 memcpy( &ps->mnm, &mnm, sizeof(mnm) );
1376 break;
1378 case WM_SIZING:
1379 case WM_MOVING:
1380 minsize = sizeof(RECT);
1381 if (!get_buffer_space( buffer, sizeof(RECT) )) return FALSE;
1382 break;
1383 case WM_MDICREATE:
1385 MDICREATESTRUCTW mcs;
1386 WCHAR *str = (WCHAR *)(&ps->mcs + 1);
1387 if (size < sizeof(ps->mcs)) return FALSE;
1388 size -= sizeof(ps->mcs);
1390 mcs.szClass = unpack_ptr( ps->mcs.szClass );
1391 mcs.szTitle = unpack_ptr( ps->mcs.szTitle );
1392 mcs.hOwner = unpack_ptr( ps->mcs.hOwner );
1393 mcs.x = ps->mcs.x;
1394 mcs.y = ps->mcs.y;
1395 mcs.cx = ps->mcs.cx;
1396 mcs.cy = ps->mcs.cy;
1397 mcs.style = ps->mcs.style;
1398 mcs.lParam = (LPARAM)unpack_ptr( ps->mcs.lParam );
1399 if (ps->mcs.szClass >> 16)
1401 if (!check_string( str, size )) return FALSE;
1402 mcs.szClass = str;
1403 size -= (strlenW(str) + 1) * sizeof(WCHAR);
1404 str += strlenW(str) + 1;
1406 if (ps->mcs.szTitle >> 16)
1408 if (!check_string( str, size )) return FALSE;
1409 mcs.szTitle = str;
1411 memcpy( &ps->mcs, &mcs, sizeof(mcs) );
1412 break;
1414 case WM_MDIGETACTIVE:
1415 if (!*lparam) return TRUE;
1416 if (!get_buffer_space( buffer, sizeof(BOOL) )) return FALSE;
1417 break;
1418 case WM_DEVICECHANGE:
1419 minsize = sizeof(DEV_BROADCAST_HDR);
1420 break;
1421 case WM_WINE_KEYBOARD_LL_HOOK:
1422 case WM_WINE_MOUSE_LL_HOOK:
1424 struct hook_extra_info h_extra;
1425 minsize = sizeof(ps->hook) +
1426 (message == WM_WINE_KEYBOARD_LL_HOOK ? sizeof(KBDLLHOOKSTRUCT)
1427 : sizeof(MSLLHOOKSTRUCT));
1428 if (size < minsize) return FALSE;
1429 h_extra.handle = wine_server_ptr_handle( ps->hook.handle );
1430 h_extra.lparam = (LPARAM)(&ps->hook + 1);
1431 memcpy( &ps->hook, &h_extra, sizeof(h_extra) );
1432 break;
1434 case WM_NCPAINT:
1435 if (*wparam <= 1) return TRUE;
1436 FIXME( "WM_NCPAINT hdc unpacking not supported\n" );
1437 return FALSE;
1438 case WM_PAINT:
1439 if (!*wparam) return TRUE;
1440 /* fall through */
1442 /* these contain an HFONT */
1443 case WM_SETFONT:
1444 case WM_GETFONT:
1445 /* these contain an HDC */
1446 case WM_ERASEBKGND:
1447 case WM_ICONERASEBKGND:
1448 case WM_CTLCOLORMSGBOX:
1449 case WM_CTLCOLOREDIT:
1450 case WM_CTLCOLORLISTBOX:
1451 case WM_CTLCOLORBTN:
1452 case WM_CTLCOLORDLG:
1453 case WM_CTLCOLORSCROLLBAR:
1454 case WM_CTLCOLORSTATIC:
1455 case WM_PRINT:
1456 case WM_PRINTCLIENT:
1457 /* these contain an HGLOBAL */
1458 case WM_PAINTCLIPBOARD:
1459 case WM_SIZECLIPBOARD:
1460 /* these contain HICON */
1461 case WM_GETICON:
1462 case WM_SETICON:
1463 case WM_QUERYDRAGICON:
1464 case WM_QUERYPARKICON:
1465 /* these contain pointers */
1466 case WM_DROPOBJECT:
1467 case WM_QUERYDROPOBJECT:
1468 case WM_DRAGLOOP:
1469 case WM_DRAGSELECT:
1470 case WM_DRAGMOVE:
1471 FIXME( "msg %x (%s) not supported yet\n", message, SPY_GetMsgName(message, hwnd) );
1472 return FALSE;
1474 default:
1475 return TRUE; /* message doesn't need any unpacking */
1478 /* default exit for most messages: check minsize and store buffer in lparam */
1479 if (size < minsize) return FALSE;
1480 *lparam = (LPARAM)*buffer;
1481 return TRUE;
1485 /***********************************************************************
1486 * pack_reply
1488 * Pack a reply to a message for sending to another process.
1490 static void pack_reply( HWND hwnd, UINT message, WPARAM wparam, LPARAM lparam,
1491 LRESULT res, struct packed_message *data )
1493 data->count = 0;
1494 switch(message)
1496 case WM_NCCREATE:
1497 case WM_CREATE:
1499 CREATESTRUCTW *cs = (CREATESTRUCTW *)lparam;
1500 data->ps.cs.lpCreateParams = (ULONG_PTR)cs->lpCreateParams;
1501 data->ps.cs.hInstance = (ULONG_PTR)cs->hInstance;
1502 data->ps.cs.hMenu = wine_server_user_handle( cs->hMenu );
1503 data->ps.cs.hwndParent = wine_server_user_handle( cs->hwndParent );
1504 data->ps.cs.cy = cs->cy;
1505 data->ps.cs.cx = cs->cx;
1506 data->ps.cs.y = cs->y;
1507 data->ps.cs.x = cs->x;
1508 data->ps.cs.style = cs->style;
1509 data->ps.cs.dwExStyle = cs->dwExStyle;
1510 data->ps.cs.lpszName = (ULONG_PTR)cs->lpszName;
1511 data->ps.cs.lpszClass = (ULONG_PTR)cs->lpszClass;
1512 push_data( data, &data->ps.cs, sizeof(data->ps.cs) );
1513 break;
1515 case WM_GETTEXT:
1516 case CB_GETLBTEXT:
1517 case LB_GETTEXT:
1518 push_data( data, (WCHAR *)lparam, (res + 1) * sizeof(WCHAR) );
1519 break;
1520 case WM_GETMINMAXINFO:
1521 push_data( data, (MINMAXINFO *)lparam, sizeof(MINMAXINFO) );
1522 break;
1523 case WM_MEASUREITEM:
1525 MEASUREITEMSTRUCT *mis = (MEASUREITEMSTRUCT *)lparam;
1526 data->ps.mis.CtlType = mis->CtlType;
1527 data->ps.mis.CtlID = mis->CtlID;
1528 data->ps.mis.itemID = mis->itemID;
1529 data->ps.mis.itemWidth = mis->itemWidth;
1530 data->ps.mis.itemHeight = mis->itemHeight;
1531 data->ps.mis.itemData = mis->itemData;
1532 push_data( data, &data->ps.mis, sizeof(data->ps.mis) );
1533 break;
1535 case WM_WINDOWPOSCHANGING:
1536 case WM_WINDOWPOSCHANGED:
1538 WINDOWPOS *wp = (WINDOWPOS *)lparam;
1539 data->ps.wp.hwnd = wine_server_user_handle( wp->hwnd );
1540 data->ps.wp.hwndInsertAfter = wine_server_user_handle( wp->hwndInsertAfter );
1541 data->ps.wp.x = wp->x;
1542 data->ps.wp.y = wp->y;
1543 data->ps.wp.cx = wp->cx;
1544 data->ps.wp.cy = wp->cy;
1545 data->ps.wp.flags = wp->flags;
1546 push_data( data, &data->ps.wp, sizeof(data->ps.wp) );
1547 break;
1549 case WM_GETDLGCODE:
1550 if (lparam)
1552 MSG *msg = (MSG *)lparam;
1553 data->ps.msg.hwnd = wine_server_user_handle( msg->hwnd );
1554 data->ps.msg.message = msg->message;
1555 data->ps.msg.wParam = msg->wParam;
1556 data->ps.msg.lParam = msg->lParam;
1557 data->ps.msg.time = msg->time;
1558 data->ps.msg.pt = msg->pt;
1559 push_data( data, &data->ps.msg, sizeof(data->ps.msg) );
1561 break;
1562 case SBM_GETSCROLLINFO:
1563 push_data( data, (SCROLLINFO *)lparam, sizeof(SCROLLINFO) );
1564 break;
1565 case EM_GETRECT:
1566 case LB_GETITEMRECT:
1567 case CB_GETDROPPEDCONTROLRECT:
1568 case WM_SIZING:
1569 case WM_MOVING:
1570 push_data( data, (RECT *)lparam, sizeof(RECT) );
1571 break;
1572 case EM_GETLINE:
1574 WORD *ptr = (WORD *)lparam;
1575 push_data( data, ptr, ptr[-1] * sizeof(WCHAR) );
1576 break;
1578 case LB_GETSELITEMS:
1579 push_data( data, (UINT *)lparam, wparam * sizeof(UINT) );
1580 break;
1581 case WM_MDIGETACTIVE:
1582 if (lparam) push_data( data, (BOOL *)lparam, sizeof(BOOL) );
1583 break;
1584 case WM_NCCALCSIZE:
1585 if (!wparam)
1586 push_data( data, (RECT *)lparam, sizeof(RECT) );
1587 else
1589 NCCALCSIZE_PARAMS *ncp = (NCCALCSIZE_PARAMS *)lparam;
1590 data->ps.ncp.rgrc[0] = ncp->rgrc[0];
1591 data->ps.ncp.rgrc[1] = ncp->rgrc[1];
1592 data->ps.ncp.rgrc[2] = ncp->rgrc[2];
1593 data->ps.ncp.hwnd = wine_server_user_handle( ncp->lppos->hwnd );
1594 data->ps.ncp.hwndInsertAfter = wine_server_user_handle( ncp->lppos->hwndInsertAfter );
1595 data->ps.ncp.x = ncp->lppos->x;
1596 data->ps.ncp.y = ncp->lppos->y;
1597 data->ps.ncp.cx = ncp->lppos->cx;
1598 data->ps.ncp.cy = ncp->lppos->cy;
1599 data->ps.ncp.flags = ncp->lppos->flags;
1600 push_data( data, &data->ps.ncp, sizeof(data->ps.ncp) );
1602 break;
1603 case EM_GETSEL:
1604 case SBM_GETRANGE:
1605 case CB_GETEDITSEL:
1606 if (wparam) push_data( data, (DWORD *)wparam, sizeof(DWORD) );
1607 if (lparam) push_data( data, (DWORD *)lparam, sizeof(DWORD) );
1608 break;
1609 case WM_NEXTMENU:
1611 MDINEXTMENU *mnm = (MDINEXTMENU *)lparam;
1612 data->ps.mnm.hmenuIn = wine_server_user_handle( mnm->hmenuIn );
1613 data->ps.mnm.hmenuNext = wine_server_user_handle( mnm->hmenuNext );
1614 data->ps.mnm.hwndNext = wine_server_user_handle( mnm->hwndNext );
1615 push_data( data, &data->ps.mnm, sizeof(data->ps.mnm) );
1616 break;
1618 case WM_MDICREATE:
1620 MDICREATESTRUCTW *mcs = (MDICREATESTRUCTW *)lparam;
1621 data->ps.mcs.szClass = pack_ptr( mcs->szClass );
1622 data->ps.mcs.szTitle = pack_ptr( mcs->szTitle );
1623 data->ps.mcs.hOwner = pack_ptr( mcs->hOwner );
1624 data->ps.mcs.x = mcs->x;
1625 data->ps.mcs.y = mcs->y;
1626 data->ps.mcs.cx = mcs->cx;
1627 data->ps.mcs.cy = mcs->cy;
1628 data->ps.mcs.style = mcs->style;
1629 data->ps.mcs.lParam = mcs->lParam;
1630 push_data( data, &data->ps.mcs, sizeof(data->ps.mcs) );
1631 break;
1633 case WM_ASKCBFORMATNAME:
1634 push_data( data, (WCHAR *)lparam, (strlenW((WCHAR *)lparam) + 1) * sizeof(WCHAR) );
1635 break;
1640 /***********************************************************************
1641 * unpack_reply
1643 * Unpack a message reply received from another process.
1645 static void unpack_reply( HWND hwnd, UINT message, WPARAM wparam, LPARAM lparam,
1646 void *buffer, size_t size )
1648 union packed_structs *ps = buffer;
1650 switch(message)
1652 case WM_NCCREATE:
1653 case WM_CREATE:
1654 if (size >= sizeof(ps->cs))
1656 CREATESTRUCTW *cs = (CREATESTRUCTW *)lparam;
1657 cs->lpCreateParams = unpack_ptr( ps->cs.lpCreateParams );
1658 cs->hInstance = unpack_ptr( ps->cs.hInstance );
1659 cs->hMenu = wine_server_ptr_handle( ps->cs.hMenu );
1660 cs->hwndParent = wine_server_ptr_handle( ps->cs.hwndParent );
1661 cs->cy = ps->cs.cy;
1662 cs->cx = ps->cs.cx;
1663 cs->y = ps->cs.y;
1664 cs->x = ps->cs.x;
1665 cs->style = ps->cs.style;
1666 cs->dwExStyle = ps->cs.dwExStyle;
1667 /* don't allow changing name and class pointers */
1669 break;
1670 case WM_GETTEXT:
1671 case WM_ASKCBFORMATNAME:
1672 memcpy( (WCHAR *)lparam, buffer, min( wparam*sizeof(WCHAR), size ));
1673 break;
1674 case WM_GETMINMAXINFO:
1675 memcpy( (MINMAXINFO *)lparam, buffer, min( sizeof(MINMAXINFO), size ));
1676 break;
1677 case WM_MEASUREITEM:
1678 if (size >= sizeof(ps->mis))
1680 MEASUREITEMSTRUCT *mis = (MEASUREITEMSTRUCT *)lparam;
1681 mis->CtlType = ps->mis.CtlType;
1682 mis->CtlID = ps->mis.CtlID;
1683 mis->itemID = ps->mis.itemID;
1684 mis->itemWidth = ps->mis.itemWidth;
1685 mis->itemHeight = ps->mis.itemHeight;
1686 mis->itemData = (ULONG_PTR)unpack_ptr( ps->mis.itemData );
1688 break;
1689 case WM_WINDOWPOSCHANGING:
1690 case WM_WINDOWPOSCHANGED:
1691 if (size >= sizeof(ps->wp))
1693 WINDOWPOS *wp = (WINDOWPOS *)lparam;
1694 wp->hwnd = wine_server_ptr_handle( ps->wp.hwnd );
1695 wp->hwndInsertAfter = wine_server_ptr_handle( ps->wp.hwndInsertAfter );
1696 wp->x = ps->wp.x;
1697 wp->y = ps->wp.y;
1698 wp->cx = ps->wp.cx;
1699 wp->cy = ps->wp.cy;
1700 wp->flags = ps->wp.flags;
1702 break;
1703 case WM_GETDLGCODE:
1704 if (lparam && size >= sizeof(ps->msg))
1706 MSG *msg = (MSG *)lparam;
1707 msg->hwnd = wine_server_ptr_handle( ps->msg.hwnd );
1708 msg->message = ps->msg.message;
1709 msg->wParam = (ULONG_PTR)unpack_ptr( ps->msg.wParam );
1710 msg->lParam = (ULONG_PTR)unpack_ptr( ps->msg.lParam );
1711 msg->time = ps->msg.time;
1712 msg->pt = ps->msg.pt;
1714 break;
1715 case SBM_GETSCROLLINFO:
1716 memcpy( (SCROLLINFO *)lparam, buffer, min( sizeof(SCROLLINFO), size ));
1717 break;
1718 case SBM_GETSCROLLBARINFO:
1719 memcpy( (SCROLLBARINFO *)lparam, buffer, min( sizeof(SCROLLBARINFO), size ));
1720 break;
1721 case EM_GETRECT:
1722 case CB_GETDROPPEDCONTROLRECT:
1723 case LB_GETITEMRECT:
1724 case WM_SIZING:
1725 case WM_MOVING:
1726 memcpy( (RECT *)lparam, buffer, min( sizeof(RECT), size ));
1727 break;
1728 case EM_GETLINE:
1729 size = min( size, (size_t)*(WORD *)lparam );
1730 memcpy( (WCHAR *)lparam, buffer, size );
1731 break;
1732 case LB_GETSELITEMS:
1733 memcpy( (UINT *)lparam, buffer, min( wparam*sizeof(UINT), size ));
1734 break;
1735 case LB_GETTEXT:
1736 case CB_GETLBTEXT:
1737 memcpy( (WCHAR *)lparam, buffer, size );
1738 break;
1739 case WM_NEXTMENU:
1740 if (size >= sizeof(ps->mnm))
1742 MDINEXTMENU *mnm = (MDINEXTMENU *)lparam;
1743 mnm->hmenuIn = wine_server_ptr_handle( ps->mnm.hmenuIn );
1744 mnm->hmenuNext = wine_server_ptr_handle( ps->mnm.hmenuNext );
1745 mnm->hwndNext = wine_server_ptr_handle( ps->mnm.hwndNext );
1747 break;
1748 case WM_MDIGETACTIVE:
1749 if (lparam) memcpy( (BOOL *)lparam, buffer, min( sizeof(BOOL), size ));
1750 break;
1751 case WM_NCCALCSIZE:
1752 if (!wparam)
1753 memcpy( (RECT *)lparam, buffer, min( sizeof(RECT), size ));
1754 else if (size >= sizeof(ps->ncp))
1756 NCCALCSIZE_PARAMS *ncp = (NCCALCSIZE_PARAMS *)lparam;
1757 ncp->rgrc[0] = ps->ncp.rgrc[0];
1758 ncp->rgrc[1] = ps->ncp.rgrc[1];
1759 ncp->rgrc[2] = ps->ncp.rgrc[2];
1760 ncp->lppos->hwnd = wine_server_ptr_handle( ps->ncp.hwnd );
1761 ncp->lppos->hwndInsertAfter = wine_server_ptr_handle( ps->ncp.hwndInsertAfter );
1762 ncp->lppos->x = ps->ncp.x;
1763 ncp->lppos->y = ps->ncp.y;
1764 ncp->lppos->cx = ps->ncp.cx;
1765 ncp->lppos->cy = ps->ncp.cy;
1766 ncp->lppos->flags = ps->ncp.flags;
1768 break;
1769 case EM_GETSEL:
1770 case SBM_GETRANGE:
1771 case CB_GETEDITSEL:
1772 if (wparam)
1774 memcpy( (DWORD *)wparam, buffer, min( sizeof(DWORD), size ));
1775 if (size <= sizeof(DWORD)) break;
1776 size -= sizeof(DWORD);
1777 buffer = (DWORD *)buffer + 1;
1779 if (lparam) memcpy( (DWORD *)lparam, buffer, min( sizeof(DWORD), size ));
1780 break;
1781 case WM_MDICREATE:
1782 if (size >= sizeof(ps->mcs))
1784 MDICREATESTRUCTW *mcs = (MDICREATESTRUCTW *)lparam;
1785 mcs->hOwner = unpack_ptr( ps->mcs.hOwner );
1786 mcs->x = ps->mcs.x;
1787 mcs->y = ps->mcs.y;
1788 mcs->cx = ps->mcs.cx;
1789 mcs->cy = ps->mcs.cy;
1790 mcs->style = ps->mcs.style;
1791 mcs->lParam = (LPARAM)unpack_ptr( ps->mcs.lParam );
1792 /* don't allow changing class and title pointers */
1794 break;
1795 default:
1796 ERR( "should not happen: unexpected message %x\n", message );
1797 break;
1802 /***********************************************************************
1803 * reply_message
1805 * Send a reply to a sent message.
1807 static void reply_message( struct received_message_info *info, LRESULT result, BOOL remove )
1809 struct packed_message data;
1810 int i, replied = info->flags & ISMEX_REPLIED;
1812 if (info->flags & ISMEX_NOTIFY) return; /* notify messages don't get replies */
1813 if (!remove && replied) return; /* replied already */
1815 memset( &data, 0, sizeof(data) );
1816 info->flags |= ISMEX_REPLIED;
1818 if (info->type == MSG_OTHER_PROCESS && !replied)
1820 pack_reply( info->msg.hwnd, info->msg.message, info->msg.wParam,
1821 info->msg.lParam, result, &data );
1824 SERVER_START_REQ( reply_message )
1826 req->result = result;
1827 req->remove = remove;
1828 for (i = 0; i < data.count; i++) wine_server_add_data( req, data.data[i], data.size[i] );
1829 wine_server_call( req );
1831 SERVER_END_REQ;
1835 /***********************************************************************
1836 * handle_internal_message
1838 * Handle an internal Wine message instead of calling the window proc.
1840 static LRESULT handle_internal_message( HWND hwnd, UINT msg, WPARAM wparam, LPARAM lparam )
1842 switch(msg)
1844 case WM_WINE_DESTROYWINDOW:
1845 return WIN_DestroyWindow( hwnd );
1846 case WM_WINE_SETWINDOWPOS:
1847 if (is_desktop_window( hwnd )) return 0;
1848 return USER_SetWindowPos( (WINDOWPOS *)lparam );
1849 case WM_WINE_SHOWWINDOW:
1850 if (is_desktop_window( hwnd )) return 0;
1851 return ShowWindow( hwnd, wparam );
1852 case WM_WINE_SETPARENT:
1853 if (is_desktop_window( hwnd )) return 0;
1854 return (LRESULT)SetParent( hwnd, (HWND)wparam );
1855 case WM_WINE_SETWINDOWLONG:
1856 return WIN_SetWindowLong( hwnd, (short)LOWORD(wparam), HIWORD(wparam), lparam, TRUE );
1857 case WM_WINE_ENABLEWINDOW:
1858 if (is_desktop_window( hwnd )) return 0;
1859 return EnableWindow( hwnd, wparam );
1860 case WM_WINE_SETACTIVEWINDOW:
1861 if (is_desktop_window( hwnd )) return 0;
1862 return (LRESULT)SetActiveWindow( (HWND)wparam );
1863 case WM_WINE_KEYBOARD_LL_HOOK:
1864 case WM_WINE_MOUSE_LL_HOOK:
1866 struct hook_extra_info *h_extra = (struct hook_extra_info *)lparam;
1868 return call_current_hook( h_extra->handle, HC_ACTION, wparam, h_extra->lparam );
1870 case WM_WINE_CLIPCURSOR:
1871 if (wparam)
1873 RECT rect;
1874 GetClipCursor( &rect );
1875 return USER_Driver->pClipCursor( &rect );
1877 return USER_Driver->pClipCursor( NULL );
1878 default:
1879 if (msg >= WM_WINE_FIRST_DRIVER_MSG && msg <= WM_WINE_LAST_DRIVER_MSG)
1880 return USER_Driver->pWindowMessage( hwnd, msg, wparam, lparam );
1881 FIXME( "unknown internal message %x\n", msg );
1882 return 0;
1886 /* since the WM_DDE_ACK response to a WM_DDE_EXECUTE message should contain the handle
1887 * to the memory handle, we keep track (in the server side) of all pairs of handle
1888 * used (the client passes its value and the content of the memory handle), and
1889 * the server stored both values (the client, and the local one, created after the
1890 * content). When a ACK message is generated, the list of pair is searched for a
1891 * matching pair, so that the client memory handle can be returned.
1893 struct DDE_pair {
1894 HGLOBAL client_hMem;
1895 HGLOBAL server_hMem;
1898 static struct DDE_pair* dde_pairs;
1899 static int dde_num_alloc;
1900 static int dde_num_used;
1902 static CRITICAL_SECTION dde_crst;
1903 static CRITICAL_SECTION_DEBUG critsect_debug =
1905 0, 0, &dde_crst,
1906 { &critsect_debug.ProcessLocksList, &critsect_debug.ProcessLocksList },
1907 0, 0, { (DWORD_PTR)(__FILE__ ": dde_crst") }
1909 static CRITICAL_SECTION dde_crst = { &critsect_debug, -1, 0, 0, 0, 0 };
1911 static BOOL dde_add_pair(HGLOBAL chm, HGLOBAL shm)
1913 int i;
1914 #define GROWBY 4
1916 EnterCriticalSection(&dde_crst);
1918 /* now remember the pair of hMem on both sides */
1919 if (dde_num_used == dde_num_alloc)
1921 struct DDE_pair* tmp;
1922 if (dde_pairs)
1923 tmp = HeapReAlloc( GetProcessHeap(), 0, dde_pairs,
1924 (dde_num_alloc + GROWBY) * sizeof(struct DDE_pair));
1925 else
1926 tmp = HeapAlloc( GetProcessHeap(), 0,
1927 (dde_num_alloc + GROWBY) * sizeof(struct DDE_pair));
1929 if (!tmp)
1931 LeaveCriticalSection(&dde_crst);
1932 return FALSE;
1934 dde_pairs = tmp;
1935 /* zero out newly allocated part */
1936 memset(&dde_pairs[dde_num_alloc], 0, GROWBY * sizeof(struct DDE_pair));
1937 dde_num_alloc += GROWBY;
1939 #undef GROWBY
1940 for (i = 0; i < dde_num_alloc; i++)
1942 if (dde_pairs[i].server_hMem == 0)
1944 dde_pairs[i].client_hMem = chm;
1945 dde_pairs[i].server_hMem = shm;
1946 dde_num_used++;
1947 break;
1950 LeaveCriticalSection(&dde_crst);
1951 return TRUE;
1954 static HGLOBAL dde_get_pair(HGLOBAL shm)
1956 int i;
1957 HGLOBAL ret = 0;
1959 EnterCriticalSection(&dde_crst);
1960 for (i = 0; i < dde_num_alloc; i++)
1962 if (dde_pairs[i].server_hMem == shm)
1964 /* free this pair */
1965 dde_pairs[i].server_hMem = 0;
1966 dde_num_used--;
1967 ret = dde_pairs[i].client_hMem;
1968 break;
1971 LeaveCriticalSection(&dde_crst);
1972 return ret;
1975 /***********************************************************************
1976 * post_dde_message
1978 * Post a DDE message
1980 static BOOL post_dde_message( struct packed_message *data, const struct send_message_info *info )
1982 void* ptr = NULL;
1983 int size = 0;
1984 UINT_PTR uiLo, uiHi;
1985 LPARAM lp = 0;
1986 HGLOBAL hunlock = 0;
1987 int i;
1988 DWORD res;
1990 if (!UnpackDDElParam( info->msg, info->lparam, &uiLo, &uiHi ))
1991 return FALSE;
1993 lp = info->lparam;
1994 switch (info->msg)
1996 /* DDE messages which don't require packing are:
1997 * WM_DDE_INITIATE
1998 * WM_DDE_TERMINATE
1999 * WM_DDE_REQUEST
2000 * WM_DDE_UNADVISE
2002 case WM_DDE_ACK:
2003 if (HIWORD(uiHi))
2005 /* uiHi should contain a hMem from WM_DDE_EXECUTE */
2006 HGLOBAL h = dde_get_pair( (HANDLE)uiHi );
2007 if (h)
2009 ULONGLONG hpack = pack_ptr( h );
2010 /* send back the value of h on the other side */
2011 push_data( data, &hpack, sizeof(hpack) );
2012 lp = uiLo;
2013 TRACE( "send dde-ack %lx %08lx => %p\n", uiLo, uiHi, h );
2016 else
2018 /* uiHi should contain either an atom or 0 */
2019 TRACE( "send dde-ack %lx atom=%lx\n", uiLo, uiHi );
2020 lp = MAKELONG( uiLo, uiHi );
2022 break;
2023 case WM_DDE_ADVISE:
2024 case WM_DDE_DATA:
2025 case WM_DDE_POKE:
2026 size = 0;
2027 if (uiLo)
2029 size = GlobalSize( (HGLOBAL)uiLo ) ;
2030 if ((info->msg == WM_DDE_ADVISE && size < sizeof(DDEADVISE)) ||
2031 (info->msg == WM_DDE_DATA && size < FIELD_OFFSET(DDEDATA, Value)) ||
2032 (info->msg == WM_DDE_POKE && size < FIELD_OFFSET(DDEPOKE, Value))
2034 return FALSE;
2036 else if (info->msg != WM_DDE_DATA) return FALSE;
2038 lp = uiHi;
2039 if (uiLo)
2041 if ((ptr = GlobalLock( (HGLOBAL)uiLo) ))
2043 DDEDATA *dde_data = ptr;
2044 TRACE("unused %d, fResponse %d, fRelease %d, fDeferUpd %d, fAckReq %d, cfFormat %d\n",
2045 dde_data->unused, dde_data->fResponse, dde_data->fRelease,
2046 dde_data->reserved, dde_data->fAckReq, dde_data->cfFormat);
2047 push_data( data, ptr, size );
2048 hunlock = (HGLOBAL)uiLo;
2051 TRACE( "send ddepack %u %lx\n", size, uiHi );
2052 break;
2053 case WM_DDE_EXECUTE:
2054 if (info->lparam)
2056 if ((ptr = GlobalLock( (HGLOBAL)info->lparam) ))
2058 push_data(data, ptr, GlobalSize( (HGLOBAL)info->lparam ));
2059 /* so that the other side can send it back on ACK */
2060 lp = info->lparam;
2061 hunlock = (HGLOBAL)info->lparam;
2064 break;
2066 SERVER_START_REQ( send_message )
2068 req->id = info->dest_tid;
2069 req->type = info->type;
2070 req->flags = 0;
2071 req->win = wine_server_user_handle( info->hwnd );
2072 req->msg = info->msg;
2073 req->wparam = info->wparam;
2074 req->lparam = lp;
2075 req->timeout = TIMEOUT_INFINITE;
2076 for (i = 0; i < data->count; i++)
2077 wine_server_add_data( req, data->data[i], data->size[i] );
2078 if ((res = wine_server_call( req )))
2080 if (res == STATUS_INVALID_PARAMETER)
2081 /* FIXME: find a STATUS_ value for this one */
2082 SetLastError( ERROR_INVALID_THREAD_ID );
2083 else
2084 SetLastError( RtlNtStatusToDosError(res) );
2086 else
2087 FreeDDElParam(info->msg, info->lparam);
2089 SERVER_END_REQ;
2090 if (hunlock) GlobalUnlock(hunlock);
2092 return !res;
2095 /***********************************************************************
2096 * unpack_dde_message
2098 * Unpack a posted DDE message received from another process.
2100 static BOOL unpack_dde_message( HWND hwnd, UINT message, WPARAM *wparam, LPARAM *lparam,
2101 void **buffer, size_t size )
2103 UINT_PTR uiLo, uiHi;
2104 HGLOBAL hMem = 0;
2105 void* ptr;
2107 switch (message)
2109 case WM_DDE_ACK:
2110 if (size)
2112 ULONGLONG hpack;
2113 /* hMem is being passed */
2114 if (size != sizeof(hpack)) return FALSE;
2115 if (!buffer || !*buffer) return FALSE;
2116 uiLo = *lparam;
2117 memcpy( &hpack, *buffer, size );
2118 hMem = unpack_ptr( hpack );
2119 uiHi = (UINT_PTR)hMem;
2120 TRACE("recv dde-ack %lx mem=%lx[%lx]\n", uiLo, uiHi, GlobalSize( hMem ));
2122 else
2124 uiLo = LOWORD( *lparam );
2125 uiHi = HIWORD( *lparam );
2126 TRACE("recv dde-ack %lx atom=%lx\n", uiLo, uiHi);
2128 *lparam = PackDDElParam( WM_DDE_ACK, uiLo, uiHi );
2129 break;
2130 case WM_DDE_ADVISE:
2131 case WM_DDE_DATA:
2132 case WM_DDE_POKE:
2133 if ((!buffer || !*buffer) && message != WM_DDE_DATA) return FALSE;
2134 uiHi = *lparam;
2135 if (size)
2137 if (!(hMem = GlobalAlloc( GMEM_MOVEABLE|GMEM_DDESHARE, size )))
2138 return FALSE;
2139 if ((ptr = GlobalLock( hMem )))
2141 memcpy( ptr, *buffer, size );
2142 GlobalUnlock( hMem );
2144 else
2146 GlobalFree( hMem );
2147 return FALSE;
2150 uiLo = (UINT_PTR)hMem;
2152 *lparam = PackDDElParam( message, uiLo, uiHi );
2153 break;
2154 case WM_DDE_EXECUTE:
2155 if (size)
2157 if (!buffer || !*buffer) return FALSE;
2158 if (!(hMem = GlobalAlloc( GMEM_MOVEABLE|GMEM_DDESHARE, size ))) return FALSE;
2159 if ((ptr = GlobalLock( hMem )))
2161 memcpy( ptr, *buffer, size );
2162 GlobalUnlock( hMem );
2163 TRACE( "exec: pairing c=%08lx s=%p\n", *lparam, hMem );
2164 if (!dde_add_pair( (HGLOBAL)*lparam, hMem ))
2166 GlobalFree( hMem );
2167 return FALSE;
2170 else
2172 GlobalFree( hMem );
2173 return FALSE;
2175 } else return FALSE;
2176 *lparam = (LPARAM)hMem;
2177 break;
2179 return TRUE;
2182 /***********************************************************************
2183 * call_window_proc
2185 * Call a window procedure and the corresponding hooks.
2187 static LRESULT call_window_proc( HWND hwnd, UINT msg, WPARAM wparam, LPARAM lparam,
2188 BOOL unicode, BOOL same_thread, enum wm_char_mapping mapping )
2190 LRESULT result = 0;
2191 CWPSTRUCT cwp;
2192 CWPRETSTRUCT cwpret;
2194 if (msg & 0x80000000)
2196 result = handle_internal_message( hwnd, msg, wparam, lparam );
2197 goto done;
2200 /* first the WH_CALLWNDPROC hook */
2201 hwnd = WIN_GetFullHandle( hwnd );
2202 cwp.lParam = lparam;
2203 cwp.wParam = wparam;
2204 cwp.message = msg;
2205 cwp.hwnd = hwnd;
2206 HOOK_CallHooks( WH_CALLWNDPROC, HC_ACTION, same_thread, (LPARAM)&cwp, unicode );
2208 /* now call the window procedure */
2209 if (!WINPROC_call_window( hwnd, msg, wparam, lparam, &result, unicode, mapping )) goto done;
2211 /* and finally the WH_CALLWNDPROCRET hook */
2212 cwpret.lResult = result;
2213 cwpret.lParam = lparam;
2214 cwpret.wParam = wparam;
2215 cwpret.message = msg;
2216 cwpret.hwnd = hwnd;
2217 HOOK_CallHooks( WH_CALLWNDPROCRET, HC_ACTION, same_thread, (LPARAM)&cwpret, unicode );
2218 done:
2219 return result;
2223 /***********************************************************************
2224 * send_parent_notify
2226 * Send a WM_PARENTNOTIFY to all ancestors of the given window, unless
2227 * the window has the WS_EX_NOPARENTNOTIFY style.
2229 static void send_parent_notify( HWND hwnd, WORD event, WORD idChild, POINT pt )
2231 /* pt has to be in the client coordinates of the parent window */
2232 MapWindowPoints( 0, hwnd, &pt, 1 );
2233 for (;;)
2235 HWND parent;
2237 if (!(GetWindowLongW( hwnd, GWL_STYLE ) & WS_CHILD)) break;
2238 if (GetWindowLongW( hwnd, GWL_EXSTYLE ) & WS_EX_NOPARENTNOTIFY) break;
2239 if (!(parent = GetParent(hwnd))) break;
2240 if (parent == GetDesktopWindow()) break;
2241 MapWindowPoints( hwnd, parent, &pt, 1 );
2242 hwnd = parent;
2243 SendMessageW( hwnd, WM_PARENTNOTIFY,
2244 MAKEWPARAM( event, idChild ), MAKELPARAM( pt.x, pt.y ) );
2249 /***********************************************************************
2250 * accept_hardware_message
2252 * Tell the server we have passed the message to the app
2253 * (even though we may end up dropping it later on)
2255 static void accept_hardware_message( UINT hw_id, BOOL remove, HWND new_hwnd )
2257 SERVER_START_REQ( accept_hardware_message )
2259 req->hw_id = hw_id;
2260 req->remove = remove;
2261 req->new_win = wine_server_user_handle( new_hwnd );
2262 if (wine_server_call( req ))
2263 FIXME("Failed to reply to MSG_HARDWARE message. Message may not be removed from queue.\n");
2265 SERVER_END_REQ;
2269 static BOOL process_rawinput_message( MSG *msg, const struct hardware_msg_data *msg_data )
2271 struct user_thread_info *thread_info = get_user_thread_info();
2272 RAWINPUT *rawinput = thread_info->rawinput;
2274 if (!rawinput)
2276 thread_info->rawinput = HeapAlloc( GetProcessHeap(), 0, sizeof(*rawinput) );
2277 if (!(rawinput = thread_info->rawinput)) return FALSE;
2280 rawinput->header.dwType = msg_data->rawinput.type;
2281 if (msg_data->rawinput.type == RIM_TYPEMOUSE)
2283 static const unsigned int button_flags[] =
2285 0, /* MOUSEEVENTF_MOVE */
2286 RI_MOUSE_LEFT_BUTTON_DOWN, /* MOUSEEVENTF_LEFTDOWN */
2287 RI_MOUSE_LEFT_BUTTON_UP, /* MOUSEEVENTF_LEFTUP */
2288 RI_MOUSE_RIGHT_BUTTON_DOWN, /* MOUSEEVENTF_RIGHTDOWN */
2289 RI_MOUSE_RIGHT_BUTTON_UP, /* MOUSEEVENTF_RIGHTUP */
2290 RI_MOUSE_MIDDLE_BUTTON_DOWN, /* MOUSEEVENTF_MIDDLEDOWN */
2291 RI_MOUSE_MIDDLE_BUTTON_UP, /* MOUSEEVENTF_MIDDLEUP */
2293 unsigned int i;
2295 rawinput->header.dwSize = FIELD_OFFSET(RAWINPUT, data) + sizeof(RAWMOUSE);
2296 rawinput->header.hDevice = WINE_MOUSE_HANDLE;
2297 rawinput->header.wParam = 0;
2299 rawinput->data.mouse.usFlags = MOUSE_MOVE_RELATIVE;
2300 rawinput->data.mouse.u.s.usButtonFlags = 0;
2301 rawinput->data.mouse.u.s.usButtonData = 0;
2302 for (i = 1; i < sizeof(button_flags) / sizeof(*button_flags); ++i)
2304 if (msg_data->flags & (1 << i))
2305 rawinput->data.mouse.u.s.usButtonFlags |= button_flags[i];
2307 if (msg_data->flags & MOUSEEVENTF_WHEEL)
2309 rawinput->data.mouse.u.s.usButtonFlags |= RI_MOUSE_WHEEL;
2310 rawinput->data.mouse.u.s.usButtonData = msg_data->rawinput.mouse.data;
2312 if (msg_data->flags & MOUSEEVENTF_HWHEEL)
2314 rawinput->data.mouse.u.s.usButtonFlags |= RI_MOUSE_HORIZONTAL_WHEEL;
2315 rawinput->data.mouse.u.s.usButtonData = msg_data->rawinput.mouse.data;
2317 if (msg_data->flags & MOUSEEVENTF_XDOWN)
2319 if (msg_data->rawinput.mouse.data == XBUTTON1)
2320 rawinput->data.mouse.u.s.usButtonFlags |= RI_MOUSE_BUTTON_4_DOWN;
2321 else if (msg_data->rawinput.mouse.data == XBUTTON2)
2322 rawinput->data.mouse.u.s.usButtonFlags |= RI_MOUSE_BUTTON_5_DOWN;
2324 if (msg_data->flags & MOUSEEVENTF_XUP)
2326 if (msg_data->rawinput.mouse.data == XBUTTON1)
2327 rawinput->data.mouse.u.s.usButtonFlags |= RI_MOUSE_BUTTON_4_UP;
2328 else if (msg_data->rawinput.mouse.data == XBUTTON2)
2329 rawinput->data.mouse.u.s.usButtonFlags |= RI_MOUSE_BUTTON_5_UP;
2332 rawinput->data.mouse.ulRawButtons = 0;
2333 rawinput->data.mouse.lLastX = msg_data->rawinput.mouse.x;
2334 rawinput->data.mouse.lLastY = msg_data->rawinput.mouse.y;
2335 rawinput->data.mouse.ulExtraInformation = msg_data->info;
2337 else if (msg_data->rawinput.type == RIM_TYPEKEYBOARD)
2339 rawinput->header.dwSize = FIELD_OFFSET(RAWINPUT, data) + sizeof(RAWKEYBOARD);
2340 rawinput->header.hDevice = WINE_KEYBOARD_HANDLE;
2341 rawinput->header.wParam = 0;
2343 rawinput->data.keyboard.MakeCode = msg_data->rawinput.kbd.scan;
2344 rawinput->data.keyboard.Flags = msg_data->flags & KEYEVENTF_KEYUP ? RI_KEY_BREAK : RI_KEY_MAKE;
2345 if (msg_data->flags & KEYEVENTF_EXTENDEDKEY) rawinput->data.keyboard.Flags |= RI_KEY_E0;
2346 rawinput->data.keyboard.Reserved = 0;
2348 switch (msg_data->rawinput.kbd.vkey)
2350 case VK_LSHIFT:
2351 case VK_RSHIFT:
2352 rawinput->data.keyboard.VKey = VK_SHIFT;
2353 rawinput->data.keyboard.Flags &= ~RI_KEY_E0;
2354 break;
2355 case VK_LCONTROL:
2356 case VK_RCONTROL:
2357 rawinput->data.keyboard.VKey = VK_CONTROL;
2358 break;
2359 case VK_LMENU:
2360 case VK_RMENU:
2361 rawinput->data.keyboard.VKey = VK_MENU;
2362 break;
2363 default:
2364 rawinput->data.keyboard.VKey = msg_data->rawinput.kbd.vkey;
2365 break;
2368 rawinput->data.keyboard.Message = msg_data->rawinput.kbd.message;
2369 rawinput->data.keyboard.ExtraInformation = msg_data->info;
2371 else
2373 FIXME("Unhandled rawinput type %#x.\n", msg_data->rawinput.type);
2374 return FALSE;
2377 msg->lParam = (LPARAM)rawinput;
2378 return TRUE;
2381 /***********************************************************************
2382 * process_keyboard_message
2384 * returns TRUE if the contents of 'msg' should be passed to the application
2386 static BOOL process_keyboard_message( MSG *msg, UINT hw_id, HWND hwnd_filter,
2387 UINT first, UINT last, BOOL remove )
2389 EVENTMSG event;
2391 if (msg->message == WM_KEYDOWN || msg->message == WM_SYSKEYDOWN ||
2392 msg->message == WM_KEYUP || msg->message == WM_SYSKEYUP)
2393 switch (msg->wParam)
2395 case VK_LSHIFT: case VK_RSHIFT:
2396 msg->wParam = VK_SHIFT;
2397 break;
2398 case VK_LCONTROL: case VK_RCONTROL:
2399 msg->wParam = VK_CONTROL;
2400 break;
2401 case VK_LMENU: case VK_RMENU:
2402 msg->wParam = VK_MENU;
2403 break;
2406 /* FIXME: is this really the right place for this hook? */
2407 event.message = msg->message;
2408 event.hwnd = msg->hwnd;
2409 event.time = msg->time;
2410 event.paramL = (msg->wParam & 0xFF) | (HIWORD(msg->lParam) << 8);
2411 event.paramH = msg->lParam & 0x7FFF;
2412 if (HIWORD(msg->lParam) & 0x0100) event.paramH |= 0x8000; /* special_key - bit */
2413 HOOK_CallHooks( WH_JOURNALRECORD, HC_ACTION, 0, (LPARAM)&event, TRUE );
2415 /* check message filters */
2416 if (msg->message < first || msg->message > last) return FALSE;
2417 if (!check_hwnd_filter( msg, hwnd_filter )) return FALSE;
2419 if (remove)
2421 if((msg->message == WM_KEYDOWN) &&
2422 (msg->hwnd != GetDesktopWindow()))
2424 /* Handle F1 key by sending out WM_HELP message */
2425 if (msg->wParam == VK_F1)
2427 PostMessageW( msg->hwnd, WM_KEYF1, 0, 0 );
2429 else if(msg->wParam >= VK_BROWSER_BACK &&
2430 msg->wParam <= VK_LAUNCH_APP2)
2432 /* FIXME: Process keystate */
2433 SendMessageW(msg->hwnd, WM_APPCOMMAND, (WPARAM)msg->hwnd, MAKELPARAM(0, (FAPPCOMMAND_KEY | (msg->wParam - VK_BROWSER_BACK + 1))));
2436 else if (msg->message == WM_KEYUP)
2438 /* Handle VK_APPS key by posting a WM_CONTEXTMENU message */
2439 if (msg->wParam == VK_APPS && !MENU_IsMenuActive())
2440 PostMessageW(msg->hwnd, WM_CONTEXTMENU, (WPARAM)msg->hwnd, -1);
2444 if (HOOK_CallHooks( WH_KEYBOARD, remove ? HC_ACTION : HC_NOREMOVE,
2445 LOWORD(msg->wParam), msg->lParam, TRUE ))
2447 /* skip this message */
2448 HOOK_CallHooks( WH_CBT, HCBT_KEYSKIPPED, LOWORD(msg->wParam), msg->lParam, TRUE );
2449 accept_hardware_message( hw_id, TRUE, 0 );
2450 return FALSE;
2452 accept_hardware_message( hw_id, remove, 0 );
2454 if ( remove && msg->message == WM_KEYDOWN )
2455 if (ImmProcessKey(msg->hwnd, GetKeyboardLayout(0), msg->wParam, msg->lParam, 0) )
2456 msg->wParam = VK_PROCESSKEY;
2458 return TRUE;
2462 /***********************************************************************
2463 * process_mouse_message
2465 * returns TRUE if the contents of 'msg' should be passed to the application
2467 static BOOL process_mouse_message( MSG *msg, UINT hw_id, ULONG_PTR extra_info, HWND hwnd_filter,
2468 UINT first, UINT last, BOOL remove )
2470 static MSG clk_msg;
2472 POINT pt;
2473 UINT message;
2474 INT hittest;
2475 EVENTMSG event;
2476 GUITHREADINFO info;
2477 MOUSEHOOKSTRUCT hook;
2478 BOOL eatMsg;
2480 /* find the window to dispatch this mouse message to */
2482 info.cbSize = sizeof(info);
2483 GetGUIThreadInfo( GetCurrentThreadId(), &info );
2484 if (info.hwndCapture)
2486 hittest = HTCLIENT;
2487 msg->hwnd = info.hwndCapture;
2489 else
2491 msg->hwnd = WINPOS_WindowFromPoint( msg->hwnd, msg->pt, &hittest );
2494 if (!msg->hwnd || !WIN_IsCurrentThread( msg->hwnd ))
2496 accept_hardware_message( hw_id, TRUE, msg->hwnd );
2497 return FALSE;
2500 /* FIXME: is this really the right place for this hook? */
2501 event.message = msg->message;
2502 event.time = msg->time;
2503 event.hwnd = msg->hwnd;
2504 event.paramL = msg->pt.x;
2505 event.paramH = msg->pt.y;
2506 HOOK_CallHooks( WH_JOURNALRECORD, HC_ACTION, 0, (LPARAM)&event, TRUE );
2508 if (!check_hwnd_filter( msg, hwnd_filter )) return FALSE;
2510 pt = msg->pt;
2511 message = msg->message;
2512 /* Note: windows has no concept of a non-client wheel message */
2513 if (message != WM_MOUSEWHEEL)
2515 if (hittest != HTCLIENT)
2517 message += WM_NCMOUSEMOVE - WM_MOUSEMOVE;
2518 msg->wParam = hittest;
2520 else
2522 /* coordinates don't get translated while tracking a menu */
2523 /* FIXME: should differentiate popups and top-level menus */
2524 if (!(info.flags & GUI_INMENUMODE))
2525 ScreenToClient( msg->hwnd, &pt );
2528 msg->lParam = MAKELONG( pt.x, pt.y );
2530 /* translate double clicks */
2532 if ((msg->message == WM_LBUTTONDOWN) ||
2533 (msg->message == WM_RBUTTONDOWN) ||
2534 (msg->message == WM_MBUTTONDOWN) ||
2535 (msg->message == WM_XBUTTONDOWN))
2537 BOOL update = remove;
2539 /* translate double clicks -
2540 * note that ...MOUSEMOVEs can slip in between
2541 * ...BUTTONDOWN and ...BUTTONDBLCLK messages */
2543 if ((info.flags & (GUI_INMENUMODE|GUI_INMOVESIZE)) ||
2544 hittest != HTCLIENT ||
2545 (GetClassLongA( msg->hwnd, GCL_STYLE ) & CS_DBLCLKS))
2547 if ((msg->message == clk_msg.message) &&
2548 (msg->hwnd == clk_msg.hwnd) &&
2549 (msg->wParam == clk_msg.wParam) &&
2550 (msg->time - clk_msg.time < GetDoubleClickTime()) &&
2551 (abs(msg->pt.x - clk_msg.pt.x) < GetSystemMetrics(SM_CXDOUBLECLK)/2) &&
2552 (abs(msg->pt.y - clk_msg.pt.y) < GetSystemMetrics(SM_CYDOUBLECLK)/2))
2554 message += (WM_LBUTTONDBLCLK - WM_LBUTTONDOWN);
2555 if (update)
2557 clk_msg.message = 0; /* clear the double click conditions */
2558 update = FALSE;
2562 if (message < first || message > last) return FALSE;
2563 /* update static double click conditions */
2564 if (update) clk_msg = *msg;
2566 else
2568 if (message < first || message > last) return FALSE;
2571 /* message is accepted now (but may still get dropped) */
2573 hook.pt = msg->pt;
2574 hook.hwnd = msg->hwnd;
2575 hook.wHitTestCode = hittest;
2576 hook.dwExtraInfo = extra_info;
2577 if (HOOK_CallHooks( WH_MOUSE, remove ? HC_ACTION : HC_NOREMOVE,
2578 message, (LPARAM)&hook, TRUE ))
2580 hook.pt = msg->pt;
2581 hook.hwnd = msg->hwnd;
2582 hook.wHitTestCode = hittest;
2583 hook.dwExtraInfo = extra_info;
2584 HOOK_CallHooks( WH_CBT, HCBT_CLICKSKIPPED, message, (LPARAM)&hook, TRUE );
2585 accept_hardware_message( hw_id, TRUE, 0 );
2586 return FALSE;
2589 if ((hittest == HTERROR) || (hittest == HTNOWHERE))
2591 SendMessageW( msg->hwnd, WM_SETCURSOR, (WPARAM)msg->hwnd,
2592 MAKELONG( hittest, msg->message ));
2593 accept_hardware_message( hw_id, TRUE, 0 );
2594 return FALSE;
2597 accept_hardware_message( hw_id, remove, 0 );
2599 if (!remove || info.hwndCapture)
2601 msg->message = message;
2602 return TRUE;
2605 eatMsg = FALSE;
2607 if ((msg->message == WM_LBUTTONDOWN) ||
2608 (msg->message == WM_RBUTTONDOWN) ||
2609 (msg->message == WM_MBUTTONDOWN) ||
2610 (msg->message == WM_XBUTTONDOWN))
2612 /* Send the WM_PARENTNOTIFY,
2613 * note that even for double/nonclient clicks
2614 * notification message is still WM_L/M/RBUTTONDOWN.
2616 send_parent_notify( msg->hwnd, msg->message, 0, msg->pt );
2618 /* Activate the window if needed */
2620 if (msg->hwnd != info.hwndActive)
2622 HWND hwndTop = msg->hwnd;
2623 while (hwndTop)
2625 if ((GetWindowLongW( hwndTop, GWL_STYLE ) & (WS_POPUP|WS_CHILD)) != WS_CHILD) break;
2626 hwndTop = GetParent( hwndTop );
2629 if (hwndTop && hwndTop != GetDesktopWindow())
2631 LONG ret = SendMessageW( msg->hwnd, WM_MOUSEACTIVATE, (WPARAM)hwndTop,
2632 MAKELONG( hittest, msg->message ) );
2633 switch(ret)
2635 case MA_NOACTIVATEANDEAT:
2636 eatMsg = TRUE;
2637 /* fall through */
2638 case MA_NOACTIVATE:
2639 break;
2640 case MA_ACTIVATEANDEAT:
2641 eatMsg = TRUE;
2642 /* fall through */
2643 case MA_ACTIVATE:
2644 case 0:
2645 if (!FOCUS_MouseActivate( hwndTop )) eatMsg = TRUE;
2646 break;
2647 default:
2648 WARN( "unknown WM_MOUSEACTIVATE code %d\n", ret );
2649 break;
2655 /* send the WM_SETCURSOR message */
2657 /* Windows sends the normal mouse message as the message parameter
2658 in the WM_SETCURSOR message even if it's non-client mouse message */
2659 SendMessageW( msg->hwnd, WM_SETCURSOR, (WPARAM)msg->hwnd, MAKELONG( hittest, msg->message ));
2661 msg->message = message;
2662 return !eatMsg;
2666 /***********************************************************************
2667 * process_hardware_message
2669 * Process a hardware message; return TRUE if message should be passed on to the app
2671 static BOOL process_hardware_message( MSG *msg, UINT hw_id, const struct hardware_msg_data *msg_data,
2672 HWND hwnd_filter, UINT first, UINT last, BOOL remove )
2674 if (msg->message == WM_INPUT)
2675 return process_rawinput_message( msg, msg_data );
2677 if (is_keyboard_message( msg->message ))
2678 return process_keyboard_message( msg, hw_id, hwnd_filter, first, last, remove );
2680 if (is_mouse_message( msg->message ))
2681 return process_mouse_message( msg, hw_id, msg_data->info, hwnd_filter, first, last, remove );
2683 ERR( "unknown message type %x\n", msg->message );
2684 return FALSE;
2688 /***********************************************************************
2689 * call_sendmsg_callback
2691 * Call the callback function of SendMessageCallback.
2693 static inline void call_sendmsg_callback( SENDASYNCPROC callback, HWND hwnd, UINT msg,
2694 ULONG_PTR data, LRESULT result )
2696 if (!callback) return;
2698 if (TRACE_ON(relay))
2699 DPRINTF( "%04x:Call message callback %p (hwnd=%p,msg=%s,data=%08lx,result=%08lx)\n",
2700 GetCurrentThreadId(), callback, hwnd, SPY_GetMsgName( msg, hwnd ),
2701 data, result );
2702 callback( hwnd, msg, data, result );
2703 if (TRACE_ON(relay))
2704 DPRINTF( "%04x:Ret message callback %p (hwnd=%p,msg=%s,data=%08lx,result=%08lx)\n",
2705 GetCurrentThreadId(), callback, hwnd, SPY_GetMsgName( msg, hwnd ),
2706 data, result );
2710 /***********************************************************************
2711 * peek_message
2713 * Peek for a message matching the given parameters. Return FALSE if none available.
2714 * All pending sent messages are processed before returning.
2716 static BOOL peek_message( MSG *msg, HWND hwnd, UINT first, UINT last, UINT flags, UINT changed_mask )
2718 LRESULT result;
2719 struct user_thread_info *thread_info = get_user_thread_info();
2720 struct received_message_info info, *old_info;
2721 unsigned int hw_id = 0; /* id of previous hardware message */
2722 void *buffer;
2723 size_t buffer_size = 256;
2725 if (!(buffer = HeapAlloc( GetProcessHeap(), 0, buffer_size ))) return FALSE;
2727 if (!first && !last) last = ~0;
2728 if (hwnd == HWND_BROADCAST) hwnd = HWND_TOPMOST;
2730 for (;;)
2732 NTSTATUS res;
2733 size_t size = 0;
2734 const message_data_t *msg_data = buffer;
2736 SERVER_START_REQ( get_message )
2738 req->flags = flags;
2739 req->get_win = wine_server_user_handle( hwnd );
2740 req->get_first = first;
2741 req->get_last = last;
2742 req->hw_id = hw_id;
2743 req->wake_mask = changed_mask & (QS_SENDMESSAGE | QS_SMRESULT);
2744 req->changed_mask = changed_mask;
2745 wine_server_set_reply( req, buffer, buffer_size );
2746 if (!(res = wine_server_call( req )))
2748 size = wine_server_reply_size( reply );
2749 info.type = reply->type;
2750 info.msg.hwnd = wine_server_ptr_handle( reply->win );
2751 info.msg.message = reply->msg;
2752 info.msg.wParam = reply->wparam;
2753 info.msg.lParam = reply->lparam;
2754 info.msg.time = reply->time;
2755 info.msg.pt.x = 0;
2756 info.msg.pt.y = 0;
2757 hw_id = 0;
2758 thread_info->active_hooks = reply->active_hooks;
2760 else buffer_size = reply->total;
2762 SERVER_END_REQ;
2764 if (res)
2766 HeapFree( GetProcessHeap(), 0, buffer );
2767 if (res != STATUS_BUFFER_OVERFLOW) return FALSE;
2768 if (!(buffer = HeapAlloc( GetProcessHeap(), 0, buffer_size ))) return FALSE;
2769 continue;
2772 TRACE( "got type %d msg %x (%s) hwnd %p wp %lx lp %lx\n",
2773 info.type, info.msg.message,
2774 (info.type == MSG_WINEVENT) ? "MSG_WINEVENT" : SPY_GetMsgName(info.msg.message, info.msg.hwnd),
2775 info.msg.hwnd, info.msg.wParam, info.msg.lParam );
2777 switch(info.type)
2779 case MSG_ASCII:
2780 case MSG_UNICODE:
2781 info.flags = ISMEX_SEND;
2782 break;
2783 case MSG_NOTIFY:
2784 info.flags = ISMEX_NOTIFY;
2785 break;
2786 case MSG_CALLBACK:
2787 info.flags = ISMEX_CALLBACK;
2788 break;
2789 case MSG_CALLBACK_RESULT:
2790 if (size >= sizeof(msg_data->callback))
2791 call_sendmsg_callback( wine_server_get_ptr(msg_data->callback.callback),
2792 info.msg.hwnd, info.msg.message,
2793 msg_data->callback.data, msg_data->callback.result );
2794 continue;
2795 case MSG_WINEVENT:
2796 if (size >= sizeof(msg_data->winevent))
2798 WINEVENTPROC hook_proc;
2800 hook_proc = wine_server_get_ptr( msg_data->winevent.hook_proc );
2801 size -= sizeof(msg_data->winevent);
2802 if (size)
2804 WCHAR module[MAX_PATH];
2806 size = min( size, (MAX_PATH - 1) * sizeof(WCHAR) );
2807 memcpy( module, &msg_data->winevent + 1, size );
2808 module[size / sizeof(WCHAR)] = 0;
2809 if (!(hook_proc = get_hook_proc( hook_proc, module )))
2811 ERR( "invalid winevent hook module name %s\n", debugstr_w(module) );
2812 continue;
2816 if (TRACE_ON(relay))
2817 DPRINTF( "%04x:Call winevent proc %p (hook=%04x,event=%x,hwnd=%p,object_id=%lx,child_id=%lx,tid=%04x,time=%x)\n",
2818 GetCurrentThreadId(), hook_proc,
2819 msg_data->winevent.hook, info.msg.message, info.msg.hwnd, info.msg.wParam,
2820 info.msg.lParam, msg_data->winevent.tid, info.msg.time);
2822 hook_proc( wine_server_ptr_handle( msg_data->winevent.hook ), info.msg.message,
2823 info.msg.hwnd, info.msg.wParam, info.msg.lParam,
2824 msg_data->winevent.tid, info.msg.time );
2826 if (TRACE_ON(relay))
2827 DPRINTF( "%04x:Ret winevent proc %p (hook=%04x,event=%x,hwnd=%p,object_id=%lx,child_id=%lx,tid=%04x,time=%x)\n",
2828 GetCurrentThreadId(), hook_proc,
2829 msg_data->winevent.hook, info.msg.message, info.msg.hwnd, info.msg.wParam,
2830 info.msg.lParam, msg_data->winevent.tid, info.msg.time);
2832 continue;
2833 case MSG_HOOK_LL:
2834 info.flags = ISMEX_SEND;
2835 result = 0;
2836 if (info.msg.message == WH_KEYBOARD_LL && size >= sizeof(msg_data->hardware))
2838 KBDLLHOOKSTRUCT hook;
2840 hook.vkCode = LOWORD( info.msg.lParam );
2841 hook.scanCode = HIWORD( info.msg.lParam );
2842 hook.flags = msg_data->hardware.flags;
2843 hook.time = info.msg.time;
2844 hook.dwExtraInfo = msg_data->hardware.info;
2845 TRACE( "calling keyboard LL hook vk %x scan %x flags %x time %u info %lx\n",
2846 hook.vkCode, hook.scanCode, hook.flags, hook.time, hook.dwExtraInfo );
2847 result = HOOK_CallHooks( WH_KEYBOARD_LL, HC_ACTION, info.msg.wParam, (LPARAM)&hook, TRUE );
2849 else if (info.msg.message == WH_MOUSE_LL && size >= sizeof(msg_data->hardware))
2851 MSLLHOOKSTRUCT hook;
2853 hook.pt.x = msg_data->hardware.x;
2854 hook.pt.y = msg_data->hardware.y;
2855 hook.mouseData = info.msg.lParam;
2856 hook.flags = msg_data->hardware.flags;
2857 hook.time = info.msg.time;
2858 hook.dwExtraInfo = msg_data->hardware.info;
2859 TRACE( "calling mouse LL hook pos %d,%d data %x flags %x time %u info %lx\n",
2860 hook.pt.x, hook.pt.y, hook.mouseData, hook.flags, hook.time, hook.dwExtraInfo );
2861 result = HOOK_CallHooks( WH_MOUSE_LL, HC_ACTION, info.msg.wParam, (LPARAM)&hook, TRUE );
2863 reply_message( &info, result, TRUE );
2864 continue;
2865 case MSG_OTHER_PROCESS:
2866 info.flags = ISMEX_SEND;
2867 if (!unpack_message( info.msg.hwnd, info.msg.message, &info.msg.wParam,
2868 &info.msg.lParam, &buffer, size ))
2870 /* ignore it */
2871 reply_message( &info, 0, TRUE );
2872 continue;
2874 break;
2875 case MSG_HARDWARE:
2876 if (size >= sizeof(msg_data->hardware))
2878 info.msg.pt.x = msg_data->hardware.x;
2879 info.msg.pt.y = msg_data->hardware.y;
2880 hw_id = msg_data->hardware.hw_id;
2881 if (!process_hardware_message( &info.msg, hw_id, &msg_data->hardware,
2882 hwnd, first, last, flags & PM_REMOVE ))
2884 TRACE("dropping msg %x\n", info.msg.message );
2885 continue; /* ignore it */
2887 *msg = info.msg;
2888 thread_info->GetMessagePosVal = MAKELONG( info.msg.pt.x, info.msg.pt.y );
2889 thread_info->GetMessageTimeVal = info.msg.time;
2890 thread_info->GetMessageExtraInfoVal = msg_data->hardware.info;
2891 HeapFree( GetProcessHeap(), 0, buffer );
2892 HOOK_CallHooks( WH_GETMESSAGE, HC_ACTION, flags & PM_REMOVE, (LPARAM)msg, TRUE );
2893 return TRUE;
2895 continue;
2896 case MSG_POSTED:
2897 if (info.msg.message & 0x80000000) /* internal message */
2899 if (flags & PM_REMOVE)
2901 handle_internal_message( info.msg.hwnd, info.msg.message,
2902 info.msg.wParam, info.msg.lParam );
2903 /* if this is a nested call return right away */
2904 if (first == info.msg.message && last == info.msg.message)
2906 HeapFree( GetProcessHeap(), 0, buffer );
2907 return FALSE;
2910 else
2911 peek_message( msg, info.msg.hwnd, info.msg.message,
2912 info.msg.message, flags | PM_REMOVE, changed_mask );
2913 continue;
2915 if (info.msg.message >= WM_DDE_FIRST && info.msg.message <= WM_DDE_LAST)
2917 if (!unpack_dde_message( info.msg.hwnd, info.msg.message, &info.msg.wParam,
2918 &info.msg.lParam, &buffer, size ))
2919 continue; /* ignore it */
2921 *msg = info.msg;
2922 msg->pt.x = (short)LOWORD( thread_info->GetMessagePosVal );
2923 msg->pt.y = (short)HIWORD( thread_info->GetMessagePosVal );
2924 thread_info->GetMessageTimeVal = info.msg.time;
2925 thread_info->GetMessageExtraInfoVal = 0;
2926 HeapFree( GetProcessHeap(), 0, buffer );
2927 HOOK_CallHooks( WH_GETMESSAGE, HC_ACTION, flags & PM_REMOVE, (LPARAM)msg, TRUE );
2928 return TRUE;
2931 /* if we get here, we have a sent message; call the window procedure */
2932 old_info = thread_info->receive_info;
2933 thread_info->receive_info = &info;
2934 result = call_window_proc( info.msg.hwnd, info.msg.message, info.msg.wParam,
2935 info.msg.lParam, (info.type != MSG_ASCII), FALSE,
2936 WMCHAR_MAP_RECVMESSAGE );
2937 reply_message( &info, result, TRUE );
2938 thread_info->receive_info = old_info;
2940 /* if some PM_QS* flags were specified, only handle sent messages from now on */
2941 if (HIWORD(flags) && !changed_mask) flags = PM_QS_SENDMESSAGE | LOWORD(flags);
2946 /***********************************************************************
2947 * process_sent_messages
2949 * Process all pending sent messages.
2951 static inline void process_sent_messages(void)
2953 MSG msg;
2954 peek_message( &msg, 0, 0, 0, PM_REMOVE | PM_QS_SENDMESSAGE, 0 );
2958 /***********************************************************************
2959 * get_server_queue_handle
2961 * Get a handle to the server message queue for the current thread.
2963 static HANDLE get_server_queue_handle(void)
2965 struct user_thread_info *thread_info = get_user_thread_info();
2966 HANDLE ret;
2968 if (!(ret = thread_info->server_queue))
2970 SERVER_START_REQ( get_msg_queue )
2972 wine_server_call( req );
2973 ret = wine_server_ptr_handle( reply->handle );
2975 SERVER_END_REQ;
2976 thread_info->server_queue = ret;
2977 if (!ret) ERR( "Cannot get server thread queue\n" );
2979 return ret;
2983 /***********************************************************************
2984 * wait_message_reply
2986 * Wait until a sent message gets replied to.
2988 static void wait_message_reply( UINT flags )
2990 HANDLE server_queue = get_server_queue_handle();
2992 for (;;)
2994 unsigned int wake_bits = 0;
2996 SERVER_START_REQ( set_queue_mask )
2998 req->wake_mask = QS_SMRESULT | ((flags & SMTO_BLOCK) ? 0 : QS_SENDMESSAGE);
2999 req->changed_mask = req->wake_mask;
3000 req->skip_wait = 1;
3001 if (!wine_server_call( req ))
3002 wake_bits = reply->wake_bits;
3004 SERVER_END_REQ;
3006 if (wake_bits & QS_SMRESULT) return; /* got a result */
3007 if (wake_bits & QS_SENDMESSAGE)
3009 /* Process the sent message immediately */
3010 process_sent_messages();
3011 continue;
3014 wow_handlers.wait_message( 1, &server_queue, INFINITE, QS_SENDMESSAGE, 0 );
3018 /***********************************************************************
3019 * put_message_in_queue
3021 * Put a sent message into the destination queue.
3022 * For inter-process message, reply_size is set to expected size of reply data.
3024 static BOOL put_message_in_queue( const struct send_message_info *info, size_t *reply_size )
3026 struct packed_message data;
3027 message_data_t msg_data;
3028 unsigned int res;
3029 int i;
3030 timeout_t timeout = TIMEOUT_INFINITE;
3032 /* Check for INFINITE timeout for compatibility with Win9x,
3033 * although Windows >= NT does not do so
3035 if (info->type != MSG_NOTIFY &&
3036 info->type != MSG_CALLBACK &&
3037 info->type != MSG_POSTED &&
3038 info->timeout &&
3039 info->timeout != INFINITE)
3041 /* timeout is signed despite the prototype */
3042 timeout = (timeout_t)max( 0, (int)info->timeout ) * -10000;
3045 memset( &data, 0, sizeof(data) );
3046 if (info->type == MSG_OTHER_PROCESS)
3048 *reply_size = pack_message( info->hwnd, info->msg, info->wparam, info->lparam, &data );
3049 if (data.count == -1)
3051 WARN( "cannot pack message %x\n", info->msg );
3052 return FALSE;
3055 else if (info->type == MSG_CALLBACK)
3057 msg_data.callback.callback = wine_server_client_ptr( info->callback );
3058 msg_data.callback.data = info->data;
3059 msg_data.callback.result = 0;
3060 data.data[0] = &msg_data;
3061 data.size[0] = sizeof(msg_data.callback);
3062 data.count = 1;
3064 else if (info->type == MSG_POSTED && info->msg >= WM_DDE_FIRST && info->msg <= WM_DDE_LAST)
3066 return post_dde_message( &data, info );
3069 SERVER_START_REQ( send_message )
3071 req->id = info->dest_tid;
3072 req->type = info->type;
3073 req->flags = 0;
3074 req->win = wine_server_user_handle( info->hwnd );
3075 req->msg = info->msg;
3076 req->wparam = info->wparam;
3077 req->lparam = info->lparam;
3078 req->timeout = timeout;
3080 if (info->flags & SMTO_ABORTIFHUNG) req->flags |= SEND_MSG_ABORT_IF_HUNG;
3081 for (i = 0; i < data.count; i++) wine_server_add_data( req, data.data[i], data.size[i] );
3082 if ((res = wine_server_call( req )))
3084 if (res == STATUS_INVALID_PARAMETER)
3085 /* FIXME: find a STATUS_ value for this one */
3086 SetLastError( ERROR_INVALID_THREAD_ID );
3087 else
3088 SetLastError( RtlNtStatusToDosError(res) );
3091 SERVER_END_REQ;
3092 return !res;
3096 /***********************************************************************
3097 * retrieve_reply
3099 * Retrieve a message reply from the server.
3101 static LRESULT retrieve_reply( const struct send_message_info *info,
3102 size_t reply_size, LRESULT *result )
3104 NTSTATUS status;
3105 void *reply_data = NULL;
3107 if (reply_size)
3109 if (!(reply_data = HeapAlloc( GetProcessHeap(), 0, reply_size )))
3111 WARN( "no memory for reply, will be truncated\n" );
3112 reply_size = 0;
3115 SERVER_START_REQ( get_message_reply )
3117 req->cancel = 1;
3118 if (reply_size) wine_server_set_reply( req, reply_data, reply_size );
3119 if (!(status = wine_server_call( req ))) *result = reply->result;
3120 reply_size = wine_server_reply_size( reply );
3122 SERVER_END_REQ;
3123 if (!status && reply_size)
3124 unpack_reply( info->hwnd, info->msg, info->wparam, info->lparam, reply_data, reply_size );
3126 HeapFree( GetProcessHeap(), 0, reply_data );
3128 TRACE( "hwnd %p msg %x (%s) wp %lx lp %lx got reply %lx (err=%d)\n",
3129 info->hwnd, info->msg, SPY_GetMsgName(info->msg, info->hwnd), info->wparam,
3130 info->lparam, *result, status );
3132 /* MSDN states that last error is 0 on timeout, but at least NT4 returns ERROR_TIMEOUT */
3133 if (status) SetLastError( RtlNtStatusToDosError(status) );
3134 return !status;
3138 /***********************************************************************
3139 * send_inter_thread_message
3141 static LRESULT send_inter_thread_message( const struct send_message_info *info, LRESULT *res_ptr )
3143 size_t reply_size = 0;
3145 TRACE( "hwnd %p msg %x (%s) wp %lx lp %lx\n",
3146 info->hwnd, info->msg, SPY_GetMsgName(info->msg, info->hwnd), info->wparam, info->lparam );
3148 USER_CheckNotLock();
3150 if (!put_message_in_queue( info, &reply_size )) return 0;
3152 /* there's no reply to wait for on notify/callback messages */
3153 if (info->type == MSG_NOTIFY || info->type == MSG_CALLBACK) return 1;
3155 wait_message_reply( info->flags );
3156 return retrieve_reply( info, reply_size, res_ptr );
3160 /***********************************************************************
3161 * send_inter_thread_callback
3163 static LRESULT send_inter_thread_callback( HWND hwnd, UINT msg, WPARAM wp, LPARAM lp,
3164 LRESULT *result, void *arg )
3166 struct send_message_info *info = arg;
3167 info->hwnd = hwnd;
3168 info->msg = msg;
3169 info->wparam = wp;
3170 info->lparam = lp;
3171 return send_inter_thread_message( info, result );
3175 /***********************************************************************
3176 * send_message
3178 * Backend implementation of the various SendMessage functions.
3180 static BOOL send_message( struct send_message_info *info, DWORD_PTR *res_ptr, BOOL unicode )
3182 DWORD dest_pid;
3183 BOOL ret;
3184 LRESULT result;
3186 if (is_broadcast(info->hwnd))
3188 EnumWindows( broadcast_message_callback, (LPARAM)info );
3189 if (res_ptr) *res_ptr = 1;
3190 return TRUE;
3193 if (!(info->dest_tid = GetWindowThreadProcessId( info->hwnd, &dest_pid ))) return FALSE;
3195 if (USER_IsExitingThread( info->dest_tid )) return FALSE;
3197 SPY_EnterMessage( SPY_SENDMESSAGE, info->hwnd, info->msg, info->wparam, info->lparam );
3199 if (info->dest_tid == GetCurrentThreadId())
3201 result = call_window_proc( info->hwnd, info->msg, info->wparam, info->lparam,
3202 unicode, TRUE, info->wm_char );
3203 if (info->type == MSG_CALLBACK)
3204 call_sendmsg_callback( info->callback, info->hwnd, info->msg, info->data, result );
3205 ret = TRUE;
3207 else
3209 if (dest_pid != GetCurrentProcessId() && (info->type == MSG_ASCII || info->type == MSG_UNICODE))
3210 info->type = MSG_OTHER_PROCESS;
3212 /* MSG_ASCII can be sent unconverted except for WM_CHAR; everything else needs to be Unicode */
3213 if (!unicode && is_unicode_message( info->msg ) &&
3214 (info->type != MSG_ASCII || info->msg == WM_CHAR))
3215 ret = WINPROC_CallProcAtoW( send_inter_thread_callback, info->hwnd, info->msg,
3216 info->wparam, info->lparam, &result, info, info->wm_char );
3217 else
3218 ret = send_inter_thread_message( info, &result );
3221 SPY_ExitMessage( SPY_RESULT_OK, info->hwnd, info->msg, result, info->wparam, info->lparam );
3222 if (ret && res_ptr) *res_ptr = result;
3223 return ret;
3227 /***********************************************************************
3228 * send_hardware_message
3230 NTSTATUS send_hardware_message( HWND hwnd, const INPUT *input, UINT flags )
3232 struct user_thread_info *thread_info = get_user_thread_info();
3233 struct send_message_info info;
3234 int prev_x, prev_y, new_x, new_y;
3235 NTSTATUS ret;
3236 BOOL wait;
3238 info.type = MSG_HARDWARE;
3239 info.dest_tid = 0;
3240 info.hwnd = hwnd;
3241 info.flags = 0;
3242 info.timeout = 0;
3244 SERVER_START_REQ( send_hardware_message )
3246 req->win = wine_server_user_handle( hwnd );
3247 req->flags = flags;
3248 req->input.type = input->type;
3249 switch (input->type)
3251 case INPUT_MOUSE:
3252 req->input.mouse.x = input->u.mi.dx;
3253 req->input.mouse.y = input->u.mi.dy;
3254 req->input.mouse.data = input->u.mi.mouseData;
3255 req->input.mouse.flags = input->u.mi.dwFlags;
3256 req->input.mouse.time = input->u.mi.time;
3257 req->input.mouse.info = input->u.mi.dwExtraInfo;
3258 break;
3259 case INPUT_KEYBOARD:
3260 req->input.kbd.vkey = input->u.ki.wVk;
3261 req->input.kbd.scan = input->u.ki.wScan;
3262 req->input.kbd.flags = input->u.ki.dwFlags;
3263 req->input.kbd.time = input->u.ki.time;
3264 req->input.kbd.info = input->u.ki.dwExtraInfo;
3265 break;
3266 case INPUT_HARDWARE:
3267 req->input.hw.msg = input->u.hi.uMsg;
3268 req->input.hw.lparam = MAKELONG( input->u.hi.wParamL, input->u.hi.wParamH );
3269 break;
3271 if (thread_info->key_state) wine_server_set_reply( req, thread_info->key_state, 256 );
3272 ret = wine_server_call( req );
3273 wait = reply->wait;
3274 prev_x = reply->prev_x;
3275 prev_y = reply->prev_y;
3276 new_x = reply->new_x;
3277 new_y = reply->new_y;
3279 SERVER_END_REQ;
3281 if (!ret)
3283 if (thread_info->key_state) thread_info->key_state_time = GetTickCount();
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))
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))
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))
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))
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_REPLIED)) == ISMEX_SEND;
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 ))
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 EnumWindows( broadcast_message_callback, (LPARAM)&info );
3596 return TRUE;
3599 if (!hwnd) return PostThreadMessageW( GetCurrentThreadId(), msg, wparam, lparam );
3601 if (!(info.dest_tid = GetWindowThreadProcessId( hwnd, NULL ))) return FALSE;
3603 if (USER_IsExitingThread( info.dest_tid )) return TRUE;
3605 return put_message_in_queue( &info, NULL );
3609 /**********************************************************************
3610 * PostThreadMessageA (USER32.@)
3612 BOOL WINAPI PostThreadMessageA( DWORD thread, UINT msg, WPARAM wparam, LPARAM lparam )
3614 if (!map_wparam_AtoW( msg, &wparam, WMCHAR_MAP_POSTMESSAGE )) return TRUE;
3615 return PostThreadMessageW( thread, msg, wparam, lparam );
3619 /**********************************************************************
3620 * PostThreadMessageW (USER32.@)
3622 BOOL WINAPI PostThreadMessageW( DWORD thread, UINT msg, WPARAM wparam, LPARAM lparam )
3624 struct send_message_info info;
3626 if (is_pointer_message( msg ))
3628 SetLastError( ERROR_MESSAGE_SYNC_ONLY );
3629 return FALSE;
3631 if (USER_IsExitingThread( thread )) return TRUE;
3633 info.type = MSG_POSTED;
3634 info.dest_tid = thread;
3635 info.hwnd = 0;
3636 info.msg = msg;
3637 info.wparam = wparam;
3638 info.lparam = lparam;
3639 info.flags = 0;
3640 return put_message_in_queue( &info, NULL );
3644 /***********************************************************************
3645 * PostQuitMessage (USER32.@)
3647 * Posts a quit message to the current thread's message queue.
3649 * PARAMS
3650 * exit_code [I] Exit code to return from message loop.
3652 * RETURNS
3653 * Nothing.
3655 * NOTES
3656 * This function is not the same as calling:
3657 *|PostThreadMessage(GetCurrentThreadId(), WM_QUIT, exit_code, 0);
3658 * It instead sets a flag in the message queue that signals it to generate
3659 * a WM_QUIT message when there are no other pending sent or posted messages
3660 * in the queue.
3662 void WINAPI PostQuitMessage( INT exit_code )
3664 SERVER_START_REQ( post_quit_message )
3666 req->exit_code = exit_code;
3667 wine_server_call( req );
3669 SERVER_END_REQ;
3672 /* check for driver events if we detect that the app is not properly consuming messages */
3673 static inline void check_for_driver_events(void)
3675 if (get_user_thread_info()->message_count > 200)
3677 flush_window_surfaces( FALSE );
3678 USER_Driver->pMsgWaitForMultipleObjectsEx( 0, NULL, 0, QS_ALLINPUT, 0 );
3680 else get_user_thread_info()->message_count++;
3683 /***********************************************************************
3684 * PeekMessageW (USER32.@)
3686 BOOL WINAPI DECLSPEC_HOTPATCH PeekMessageW( MSG *msg_out, HWND hwnd, UINT first, UINT last, UINT flags )
3688 MSG msg;
3690 USER_CheckNotLock();
3691 check_for_driver_events();
3693 if (!peek_message( &msg, hwnd, first, last, flags, 0 ))
3695 DWORD ret;
3697 flush_window_surfaces( TRUE );
3698 ret = wow_handlers.wait_message( 0, NULL, 0, QS_ALLINPUT, 0 );
3699 /* if we received driver events, check again for a pending message */
3700 if (ret == WAIT_TIMEOUT || !peek_message( &msg, hwnd, first, last, flags, 0 )) return FALSE;
3703 /* copy back our internal safe copy of message data to msg_out.
3704 * msg_out is a variable from the *program*, so it can't be used
3705 * internally as it can get "corrupted" by our use of SendMessage()
3706 * (back to the program) inside the message handling itself. */
3707 if (!msg_out)
3709 SetLastError( ERROR_NOACCESS );
3710 return FALSE;
3712 *msg_out = msg;
3713 return TRUE;
3717 /***********************************************************************
3718 * PeekMessageA (USER32.@)
3720 BOOL WINAPI DECLSPEC_HOTPATCH PeekMessageA( MSG *msg, HWND hwnd, UINT first, UINT last, UINT flags )
3722 if (get_pending_wmchar( msg, first, last, (flags & PM_REMOVE) )) return TRUE;
3723 if (!PeekMessageW( msg, hwnd, first, last, flags )) return FALSE;
3724 map_wparam_WtoA( msg, (flags & PM_REMOVE) );
3725 return TRUE;
3729 /***********************************************************************
3730 * GetMessageW (USER32.@)
3732 BOOL WINAPI DECLSPEC_HOTPATCH GetMessageW( MSG *msg, HWND hwnd, UINT first, UINT last )
3734 HANDLE server_queue = get_server_queue_handle();
3735 unsigned int mask = QS_POSTMESSAGE | QS_SENDMESSAGE; /* Always selected */
3737 USER_CheckNotLock();
3738 check_for_driver_events();
3740 if (first || last)
3742 if ((first <= WM_KEYLAST) && (last >= WM_KEYFIRST)) mask |= QS_KEY;
3743 if ( ((first <= WM_MOUSELAST) && (last >= WM_MOUSEFIRST)) ||
3744 ((first <= WM_NCMOUSELAST) && (last >= WM_NCMOUSEFIRST)) ) mask |= QS_MOUSE;
3745 if ((first <= WM_TIMER) && (last >= WM_TIMER)) mask |= QS_TIMER;
3746 if ((first <= WM_SYSTIMER) && (last >= WM_SYSTIMER)) mask |= QS_TIMER;
3747 if ((first <= WM_PAINT) && (last >= WM_PAINT)) mask |= QS_PAINT;
3749 else mask = QS_ALLINPUT;
3751 while (!peek_message( msg, hwnd, first, last, PM_REMOVE | (mask << 16), mask ))
3753 flush_window_surfaces( TRUE );
3754 wow_handlers.wait_message( 1, &server_queue, INFINITE, mask, 0 );
3757 return (msg->message != WM_QUIT);
3761 /***********************************************************************
3762 * GetMessageA (USER32.@)
3764 BOOL WINAPI DECLSPEC_HOTPATCH GetMessageA( MSG *msg, HWND hwnd, UINT first, UINT last )
3766 if (get_pending_wmchar( msg, first, last, TRUE )) return TRUE;
3767 GetMessageW( msg, hwnd, first, last );
3768 map_wparam_WtoA( msg, TRUE );
3769 return (msg->message != WM_QUIT);
3773 /***********************************************************************
3774 * IsDialogMessageA (USER32.@)
3775 * IsDialogMessage (USER32.@)
3777 BOOL WINAPI IsDialogMessageA( HWND hwndDlg, LPMSG pmsg )
3779 MSG msg = *pmsg;
3780 map_wparam_AtoW( msg.message, &msg.wParam, WMCHAR_MAP_NOMAPPING );
3781 return IsDialogMessageW( hwndDlg, &msg );
3785 /***********************************************************************
3786 * TranslateMessage (USER32.@)
3788 * Implementation of TranslateMessage.
3790 * TranslateMessage translates virtual-key messages into character-messages,
3791 * as follows :
3792 * WM_KEYDOWN/WM_KEYUP combinations produce a WM_CHAR or WM_DEADCHAR message.
3793 * ditto replacing WM_* with WM_SYS*
3794 * This produces WM_CHAR messages only for keys mapped to ASCII characters
3795 * by the keyboard driver.
3797 * If the message is WM_KEYDOWN, WM_KEYUP, WM_SYSKEYDOWN, or WM_SYSKEYUP, the
3798 * return value is nonzero, regardless of the translation.
3801 BOOL WINAPI TranslateMessage( const MSG *msg )
3803 UINT message;
3804 WCHAR wp[8];
3805 BYTE state[256];
3806 INT len;
3808 if (msg->message < WM_KEYFIRST || msg->message > WM_KEYLAST) return FALSE;
3809 if (msg->message != WM_KEYDOWN && msg->message != WM_SYSKEYDOWN) return TRUE;
3811 TRACE_(key)("Translating key %s (%04lX), scancode %04x\n",
3812 SPY_GetVKeyName(msg->wParam), msg->wParam, HIWORD(msg->lParam));
3814 switch (msg->wParam)
3816 case VK_PACKET:
3817 message = (msg->message == WM_KEYDOWN) ? WM_CHAR : WM_SYSCHAR;
3818 TRACE_(key)("PostMessageW(%p,%s,%04x,%08x)\n",
3819 msg->hwnd, SPY_GetMsgName(message, msg->hwnd), HIWORD(msg->lParam), LOWORD(msg->lParam));
3820 PostMessageW( msg->hwnd, message, HIWORD(msg->lParam), LOWORD(msg->lParam));
3821 return TRUE;
3823 case VK_PROCESSKEY:
3824 return ImmTranslateMessage(msg->hwnd, msg->message, msg->wParam, msg->lParam);
3827 GetKeyboardState( state );
3828 len = ToUnicode(msg->wParam, HIWORD(msg->lParam), state, wp, sizeof(wp)/sizeof(WCHAR), 0);
3829 if (len == -1)
3831 message = (msg->message == WM_KEYDOWN) ? WM_DEADCHAR : WM_SYSDEADCHAR;
3832 TRACE_(key)("-1 -> PostMessageW(%p,%s,%04x,%08lx)\n",
3833 msg->hwnd, SPY_GetMsgName(message, msg->hwnd), wp[0], msg->lParam);
3834 PostMessageW( msg->hwnd, message, wp[0], msg->lParam );
3836 else if (len > 0)
3838 INT i;
3840 message = (msg->message == WM_KEYDOWN) ? WM_CHAR : WM_SYSCHAR;
3841 TRACE_(key)("%d -> PostMessageW(%p,%s,<x>,%08lx) for <x> in %s\n", len, msg->hwnd,
3842 SPY_GetMsgName(message, msg->hwnd), msg->lParam, debugstr_wn(wp, len));
3843 for (i = 0; i < len; i++)
3844 PostMessageW( msg->hwnd, message, wp[i], msg->lParam );
3846 return TRUE;
3850 /***********************************************************************
3851 * DispatchMessageA (USER32.@)
3853 * See DispatchMessageW.
3855 LRESULT WINAPI DECLSPEC_HOTPATCH DispatchMessageA( const MSG* msg )
3857 LRESULT retval;
3859 /* Process timer messages */
3860 if ((msg->message == WM_TIMER) || (msg->message == WM_SYSTIMER))
3862 if (msg->lParam)
3864 __TRY
3866 retval = CallWindowProcA( (WNDPROC)msg->lParam, msg->hwnd,
3867 msg->message, msg->wParam, GetTickCount() );
3869 __EXCEPT_PAGE_FAULT
3871 retval = 0;
3873 __ENDTRY
3874 return retval;
3877 if (!msg->hwnd) return 0;
3879 SPY_EnterMessage( SPY_DISPATCHMESSAGE, msg->hwnd, msg->message,
3880 msg->wParam, msg->lParam );
3882 if (!WINPROC_call_window( msg->hwnd, msg->message, msg->wParam, msg->lParam,
3883 &retval, FALSE, WMCHAR_MAP_DISPATCHMESSAGE ))
3885 if (!IsWindow( msg->hwnd )) SetLastError( ERROR_INVALID_WINDOW_HANDLE );
3886 else SetLastError( ERROR_MESSAGE_SYNC_ONLY );
3887 retval = 0;
3890 SPY_ExitMessage( SPY_RESULT_OK, msg->hwnd, msg->message, retval,
3891 msg->wParam, msg->lParam );
3893 if (msg->message == WM_PAINT)
3895 /* send a WM_NCPAINT and WM_ERASEBKGND if the non-client area is still invalid */
3896 HRGN hrgn = CreateRectRgn( 0, 0, 0, 0 );
3897 GetUpdateRgn( msg->hwnd, hrgn, TRUE );
3898 DeleteObject( hrgn );
3900 return retval;
3904 /***********************************************************************
3905 * DispatchMessageW (USER32.@) Process a message
3907 * Process the message specified in the structure *_msg_.
3909 * If the lpMsg parameter points to a WM_TIMER message and the
3910 * parameter of the WM_TIMER message is not NULL, the lParam parameter
3911 * points to the function that is called instead of the window
3912 * procedure. The function stored in lParam (timer callback) is protected
3913 * from causing page-faults.
3915 * The message must be valid.
3917 * RETURNS
3919 * DispatchMessage() returns the result of the window procedure invoked.
3921 * CONFORMANCE
3923 * ECMA-234, Win32
3926 LRESULT WINAPI DECLSPEC_HOTPATCH DispatchMessageW( const MSG* msg )
3928 LRESULT retval;
3930 /* Process timer messages */
3931 if ((msg->message == WM_TIMER) || (msg->message == WM_SYSTIMER))
3933 if (msg->lParam)
3935 __TRY
3937 retval = CallWindowProcW( (WNDPROC)msg->lParam, msg->hwnd,
3938 msg->message, msg->wParam, GetTickCount() );
3940 __EXCEPT_PAGE_FAULT
3942 retval = 0;
3944 __ENDTRY
3945 return retval;
3948 if (!msg->hwnd) return 0;
3950 SPY_EnterMessage( SPY_DISPATCHMESSAGE, msg->hwnd, msg->message,
3951 msg->wParam, msg->lParam );
3953 if (!WINPROC_call_window( msg->hwnd, msg->message, msg->wParam, msg->lParam,
3954 &retval, TRUE, WMCHAR_MAP_DISPATCHMESSAGE ))
3956 if (!IsWindow( msg->hwnd )) SetLastError( ERROR_INVALID_WINDOW_HANDLE );
3957 else SetLastError( ERROR_MESSAGE_SYNC_ONLY );
3958 retval = 0;
3961 SPY_ExitMessage( SPY_RESULT_OK, msg->hwnd, msg->message, retval,
3962 msg->wParam, msg->lParam );
3964 if (msg->message == WM_PAINT)
3966 /* send a WM_NCPAINT and WM_ERASEBKGND if the non-client area is still invalid */
3967 HRGN hrgn = CreateRectRgn( 0, 0, 0, 0 );
3968 GetUpdateRgn( msg->hwnd, hrgn, TRUE );
3969 DeleteObject( hrgn );
3971 return retval;
3975 /***********************************************************************
3976 * GetMessagePos (USER.119)
3977 * GetMessagePos (USER32.@)
3979 * The GetMessagePos() function returns a long value representing a
3980 * cursor position, in screen coordinates, when the last message
3981 * retrieved by the GetMessage() function occurs. The x-coordinate is
3982 * in the low-order word of the return value, the y-coordinate is in
3983 * the high-order word. The application can use the MAKEPOINT()
3984 * macro to obtain a POINT structure from the return value.
3986 * For the current cursor position, use GetCursorPos().
3988 * RETURNS
3990 * Cursor position of last message on success, zero on failure.
3992 * CONFORMANCE
3994 * ECMA-234, Win32
3997 DWORD WINAPI GetMessagePos(void)
3999 return get_user_thread_info()->GetMessagePosVal;
4003 /***********************************************************************
4004 * GetMessageTime (USER.120)
4005 * GetMessageTime (USER32.@)
4007 * GetMessageTime() returns the message time for the last message
4008 * retrieved by the function. The time is measured in milliseconds with
4009 * the same offset as GetTickCount().
4011 * Since the tick count wraps, this is only useful for moderately short
4012 * relative time comparisons.
4014 * RETURNS
4016 * Time of last message on success, zero on failure.
4018 LONG WINAPI GetMessageTime(void)
4020 return get_user_thread_info()->GetMessageTimeVal;
4024 /***********************************************************************
4025 * GetMessageExtraInfo (USER.288)
4026 * GetMessageExtraInfo (USER32.@)
4028 LPARAM WINAPI GetMessageExtraInfo(void)
4030 return get_user_thread_info()->GetMessageExtraInfoVal;
4034 /***********************************************************************
4035 * SetMessageExtraInfo (USER32.@)
4037 LPARAM WINAPI SetMessageExtraInfo(LPARAM lParam)
4039 struct user_thread_info *thread_info = get_user_thread_info();
4040 LONG old_value = thread_info->GetMessageExtraInfoVal;
4041 thread_info->GetMessageExtraInfoVal = lParam;
4042 return old_value;
4046 /***********************************************************************
4047 * WaitMessage (USER.112) Suspend thread pending messages
4048 * WaitMessage (USER32.@) Suspend thread pending messages
4050 * WaitMessage() suspends a thread until events appear in the thread's
4051 * queue.
4053 BOOL WINAPI WaitMessage(void)
4055 return (MsgWaitForMultipleObjectsEx( 0, NULL, INFINITE, QS_ALLINPUT, 0 ) != WAIT_FAILED);
4059 /***********************************************************************
4060 * MsgWaitForMultipleObjectsEx (USER32.@)
4062 DWORD WINAPI MsgWaitForMultipleObjectsEx( DWORD count, CONST HANDLE *pHandles,
4063 DWORD timeout, DWORD mask, DWORD flags )
4065 HANDLE handles[MAXIMUM_WAIT_OBJECTS];
4066 DWORD i;
4068 if (count > MAXIMUM_WAIT_OBJECTS-1)
4070 SetLastError( ERROR_INVALID_PARAMETER );
4071 return WAIT_FAILED;
4074 /* set the queue mask */
4075 SERVER_START_REQ( set_queue_mask )
4077 req->wake_mask = (flags & MWMO_INPUTAVAILABLE) ? mask : 0;
4078 req->changed_mask = mask;
4079 req->skip_wait = 0;
4080 wine_server_call( req );
4082 SERVER_END_REQ;
4084 /* add the queue to the handle list */
4085 for (i = 0; i < count; i++) handles[i] = pHandles[i];
4086 handles[count] = get_server_queue_handle();
4088 flush_window_surfaces( TRUE );
4089 return wow_handlers.wait_message( count+1, handles, timeout, mask, flags );
4093 /***********************************************************************
4094 * MsgWaitForMultipleObjects (USER32.@)
4096 DWORD WINAPI MsgWaitForMultipleObjects( DWORD count, CONST HANDLE *handles,
4097 BOOL wait_all, DWORD timeout, DWORD mask )
4099 return MsgWaitForMultipleObjectsEx( count, handles, timeout, mask,
4100 wait_all ? MWMO_WAITALL : 0 );
4104 /***********************************************************************
4105 * WaitForInputIdle (USER32.@)
4107 DWORD WINAPI WaitForInputIdle( HANDLE hProcess, DWORD dwTimeOut )
4109 DWORD start_time, elapsed, ret;
4110 HANDLE handles[2];
4112 handles[0] = hProcess;
4113 SERVER_START_REQ( get_process_idle_event )
4115 req->handle = wine_server_obj_handle( hProcess );
4116 wine_server_call_err( req );
4117 handles[1] = wine_server_ptr_handle( reply->event );
4119 SERVER_END_REQ;
4120 if (!handles[1]) return WAIT_FAILED; /* no event to wait on */
4122 start_time = GetTickCount();
4123 elapsed = 0;
4125 TRACE("waiting for %p\n", handles[1] );
4128 ret = MsgWaitForMultipleObjects ( 2, handles, FALSE, dwTimeOut - elapsed, QS_SENDMESSAGE );
4129 switch (ret)
4131 case WAIT_OBJECT_0:
4132 return 0;
4133 case WAIT_OBJECT_0+2:
4134 process_sent_messages();
4135 break;
4136 case WAIT_TIMEOUT:
4137 case WAIT_FAILED:
4138 TRACE("timeout or error\n");
4139 return ret;
4140 default:
4141 TRACE("finished\n");
4142 return 0;
4144 if (dwTimeOut != INFINITE)
4146 elapsed = GetTickCount() - start_time;
4147 if (elapsed > dwTimeOut)
4148 break;
4151 while (1);
4153 return WAIT_TIMEOUT;
4157 /***********************************************************************
4158 * RegisterWindowMessageA (USER32.@)
4159 * RegisterWindowMessage (USER.118)
4161 UINT WINAPI RegisterWindowMessageA( LPCSTR str )
4163 UINT ret = GlobalAddAtomA(str);
4164 TRACE("%s, ret=%x\n", str, ret);
4165 return ret;
4169 /***********************************************************************
4170 * RegisterWindowMessageW (USER32.@)
4172 UINT WINAPI RegisterWindowMessageW( LPCWSTR str )
4174 UINT ret = GlobalAddAtomW(str);
4175 TRACE("%s ret=%x\n", debugstr_w(str), ret);
4176 return ret;
4179 typedef struct BroadcastParm
4181 DWORD flags;
4182 LPDWORD recipients;
4183 UINT msg;
4184 WPARAM wp;
4185 LPARAM lp;
4186 DWORD success;
4187 HWINSTA winsta;
4188 } BroadcastParm;
4190 static BOOL CALLBACK bcast_childwindow( HWND hw, LPARAM lp )
4192 BroadcastParm *parm = (BroadcastParm*)lp;
4193 DWORD_PTR retval = 0;
4194 LRESULT lresult;
4196 if (parm->flags & BSF_IGNORECURRENTTASK && WIN_IsCurrentProcess(hw))
4198 TRACE("Not telling myself %p\n", hw);
4199 return TRUE;
4202 /* I don't know 100% for sure if this is what Windows does, but it fits the tests */
4203 if (parm->flags & BSF_QUERY)
4205 TRACE("Telling window %p using SendMessageTimeout\n", hw);
4207 /* Not tested for conflicting flags */
4208 if (parm->flags & BSF_FORCEIFHUNG || parm->flags & BSF_NOHANG)
4209 lresult = SendMessageTimeoutW( hw, parm->msg, parm->wp, parm->lp, SMTO_ABORTIFHUNG, 2000, &retval );
4210 else if (parm->flags & BSF_NOTIMEOUTIFNOTHUNG)
4211 lresult = SendMessageTimeoutW( hw, parm->msg, parm->wp, parm->lp, SMTO_NOTIMEOUTIFNOTHUNG, 2000, &retval );
4212 else
4213 lresult = SendMessageTimeoutW( hw, parm->msg, parm->wp, parm->lp, SMTO_NORMAL, 2000, &retval );
4215 if (!lresult && GetLastError() == ERROR_TIMEOUT)
4217 WARN("Timed out!\n");
4218 if (!(parm->flags & BSF_FORCEIFHUNG))
4219 goto fail;
4221 if (retval == BROADCAST_QUERY_DENY)
4222 goto fail;
4224 return TRUE;
4226 fail:
4227 parm->success = 0;
4228 return FALSE;
4230 else if (parm->flags & BSF_POSTMESSAGE)
4232 TRACE("Telling window %p using PostMessage\n", hw);
4233 PostMessageW( hw, parm->msg, parm->wp, parm->lp );
4235 else
4237 TRACE("Telling window %p using SendNotifyMessage\n", hw);
4238 SendNotifyMessageW( hw, parm->msg, parm->wp, parm->lp );
4241 return TRUE;
4244 static BOOL CALLBACK bcast_desktop( LPWSTR desktop, LPARAM lp )
4246 BOOL ret;
4247 HDESK hdesktop;
4248 BroadcastParm *parm = (BroadcastParm*)lp;
4250 TRACE("desktop: %s\n", debugstr_w( desktop ));
4252 hdesktop = open_winstation_desktop( parm->winsta, desktop, 0, FALSE, DESKTOP_ENUMERATE|DESKTOP_WRITEOBJECTS|STANDARD_RIGHTS_WRITE );
4253 if (!hdesktop)
4255 FIXME("Could not open desktop %s\n", debugstr_w(desktop));
4256 return TRUE;
4259 ret = EnumDesktopWindows( hdesktop, bcast_childwindow, lp );
4260 CloseDesktop(hdesktop);
4261 TRACE("-->%d\n", ret);
4262 return parm->success;
4265 static BOOL CALLBACK bcast_winsta( LPWSTR winsta, LPARAM lp )
4267 BOOL ret;
4268 HWINSTA hwinsta = OpenWindowStationW( winsta, FALSE, WINSTA_ENUMDESKTOPS );
4269 TRACE("hwinsta: %p/%s/%08x\n", hwinsta, debugstr_w( winsta ), GetLastError());
4270 if (!hwinsta)
4271 return TRUE;
4272 ((BroadcastParm *)lp)->winsta = hwinsta;
4273 ret = EnumDesktopsW( hwinsta, bcast_desktop, lp );
4274 CloseWindowStation( hwinsta );
4275 TRACE("-->%d\n", ret);
4276 return ret;
4279 /***********************************************************************
4280 * BroadcastSystemMessageA (USER32.@)
4281 * BroadcastSystemMessage (USER32.@)
4283 LONG WINAPI BroadcastSystemMessageA( DWORD flags, LPDWORD recipients, UINT msg, WPARAM wp, LPARAM lp )
4285 return BroadcastSystemMessageExA( flags, recipients, msg, wp, lp, NULL );
4289 /***********************************************************************
4290 * BroadcastSystemMessageW (USER32.@)
4292 LONG WINAPI BroadcastSystemMessageW( DWORD flags, LPDWORD recipients, UINT msg, WPARAM wp, LPARAM lp )
4294 return BroadcastSystemMessageExW( flags, recipients, msg, wp, lp, NULL );
4297 /***********************************************************************
4298 * BroadcastSystemMessageExA (USER32.@)
4300 LONG WINAPI BroadcastSystemMessageExA( DWORD flags, LPDWORD recipients, UINT msg, WPARAM wp, LPARAM lp, PBSMINFO pinfo )
4302 map_wparam_AtoW( msg, &wp, WMCHAR_MAP_NOMAPPING );
4303 return BroadcastSystemMessageExW( flags, recipients, msg, wp, lp, NULL );
4307 /***********************************************************************
4308 * BroadcastSystemMessageExW (USER32.@)
4310 LONG WINAPI BroadcastSystemMessageExW( DWORD flags, LPDWORD recipients, UINT msg, WPARAM wp, LPARAM lp, PBSMINFO pinfo )
4312 BroadcastParm parm;
4313 DWORD recips = BSM_ALLCOMPONENTS;
4314 BOOL ret = TRUE;
4315 static const DWORD all_flags = ( BSF_QUERY | BSF_IGNORECURRENTTASK | BSF_FLUSHDISK | BSF_NOHANG
4316 | BSF_POSTMESSAGE | BSF_FORCEIFHUNG | BSF_NOTIMEOUTIFNOTHUNG
4317 | BSF_ALLOWSFW | BSF_SENDNOTIFYMESSAGE | BSF_RETURNHDESK | BSF_LUID );
4319 TRACE("Flags: %08x, recipients: %p(0x%x), msg: %04x, wparam: %08lx, lparam: %08lx\n", flags, recipients,
4320 (recipients ? *recipients : recips), msg, wp, lp);
4322 if (flags & ~all_flags)
4324 SetLastError(ERROR_INVALID_PARAMETER);
4325 return 0;
4328 if (!recipients)
4329 recipients = &recips;
4331 if ( pinfo && flags & BSF_QUERY )
4332 FIXME("Not returning PBSMINFO information yet\n");
4334 parm.flags = flags;
4335 parm.recipients = recipients;
4336 parm.msg = msg;
4337 parm.wp = wp;
4338 parm.lp = lp;
4339 parm.success = TRUE;
4341 if (*recipients & BSM_ALLDESKTOPS || *recipients == BSM_ALLCOMPONENTS)
4342 ret = EnumWindowStationsW(bcast_winsta, (LONG_PTR)&parm);
4343 else if (*recipients & BSM_APPLICATIONS)
4345 EnumWindows(bcast_childwindow, (LONG_PTR)&parm);
4346 ret = parm.success;
4348 else
4349 FIXME("Recipients %08x not supported!\n", *recipients);
4351 return ret;
4354 /***********************************************************************
4355 * SetMessageQueue (USER32.@)
4357 BOOL WINAPI SetMessageQueue( INT size )
4359 /* now obsolete the message queue will be expanded dynamically as necessary */
4360 return TRUE;
4364 /***********************************************************************
4365 * MessageBeep (USER32.@)
4367 BOOL WINAPI MessageBeep( UINT i )
4369 BOOL active = TRUE;
4370 SystemParametersInfoA( SPI_GETBEEP, 0, &active, FALSE );
4371 if (active) USER_Driver->pBeep();
4372 return TRUE;
4376 /***********************************************************************
4377 * SetTimer (USER32.@)
4379 UINT_PTR WINAPI SetTimer( HWND hwnd, UINT_PTR id, UINT timeout, TIMERPROC proc )
4381 UINT_PTR ret;
4382 WNDPROC winproc = 0;
4384 if (proc) winproc = WINPROC_AllocProc( (WNDPROC)proc, FALSE );
4386 /* MSDN states that the minimum timeout should be USER_TIMER_MINIMUM (10.0 ms), but testing
4387 * indicates that the true minimum is closer to 15.6 ms. */
4388 timeout = min( max( 15, timeout ), USER_TIMER_MAXIMUM );
4390 SERVER_START_REQ( set_win_timer )
4392 req->win = wine_server_user_handle( hwnd );
4393 req->msg = WM_TIMER;
4394 req->id = id;
4395 req->rate = timeout;
4396 req->lparam = (ULONG_PTR)winproc;
4397 if (!wine_server_call_err( req ))
4399 ret = reply->id;
4400 if (!ret) ret = TRUE;
4402 else ret = 0;
4404 SERVER_END_REQ;
4406 TRACE("Added %p %lx %p timeout %d\n", hwnd, id, winproc, timeout );
4407 return ret;
4411 /***********************************************************************
4412 * SetSystemTimer (USER32.@)
4414 UINT_PTR WINAPI SetSystemTimer( HWND hwnd, UINT_PTR id, UINT timeout, TIMERPROC proc )
4416 UINT_PTR ret;
4417 WNDPROC winproc = 0;
4419 if (proc) winproc = WINPROC_AllocProc( (WNDPROC)proc, FALSE );
4421 /* MSDN states that the minimum timeout should be USER_TIMER_MINIMUM (10.0 ms), but testing
4422 * indicates that the true minimum is closer to 15.6 ms. */
4423 timeout = min( max( 15, timeout ), USER_TIMER_MAXIMUM );
4425 SERVER_START_REQ( set_win_timer )
4427 req->win = wine_server_user_handle( hwnd );
4428 req->msg = WM_SYSTIMER;
4429 req->id = id;
4430 req->rate = timeout;
4431 req->lparam = (ULONG_PTR)winproc;
4432 if (!wine_server_call_err( req ))
4434 ret = reply->id;
4435 if (!ret) ret = TRUE;
4437 else ret = 0;
4439 SERVER_END_REQ;
4441 TRACE("Added %p %lx %p timeout %d\n", hwnd, id, winproc, timeout );
4442 return ret;
4446 /***********************************************************************
4447 * KillTimer (USER32.@)
4449 BOOL WINAPI KillTimer( HWND hwnd, UINT_PTR id )
4451 BOOL ret;
4453 SERVER_START_REQ( kill_win_timer )
4455 req->win = wine_server_user_handle( hwnd );
4456 req->msg = WM_TIMER;
4457 req->id = id;
4458 ret = !wine_server_call_err( req );
4460 SERVER_END_REQ;
4461 return ret;
4465 /***********************************************************************
4466 * KillSystemTimer (USER32.@)
4468 BOOL WINAPI KillSystemTimer( HWND hwnd, UINT_PTR id )
4470 BOOL ret;
4472 SERVER_START_REQ( kill_win_timer )
4474 req->win = wine_server_user_handle( hwnd );
4475 req->msg = WM_SYSTIMER;
4476 req->id = id;
4477 ret = !wine_server_call_err( req );
4479 SERVER_END_REQ;
4480 return ret;
4484 /**********************************************************************
4485 * IsGUIThread (USER32.@)
4487 BOOL WINAPI IsGUIThread( BOOL convert )
4489 FIXME( "%u: stub\n", convert );
4490 return TRUE;
4494 /**********************************************************************
4495 * GetGUIThreadInfo (USER32.@)
4497 BOOL WINAPI GetGUIThreadInfo( DWORD id, GUITHREADINFO *info )
4499 BOOL ret;
4501 if (info->cbSize != sizeof(*info))
4503 SetLastError( ERROR_INVALID_PARAMETER );
4504 return FALSE;
4507 SERVER_START_REQ( get_thread_input )
4509 req->tid = id;
4510 if ((ret = !wine_server_call_err( req )))
4512 info->flags = 0;
4513 info->hwndActive = wine_server_ptr_handle( reply->active );
4514 info->hwndFocus = wine_server_ptr_handle( reply->focus );
4515 info->hwndCapture = wine_server_ptr_handle( reply->capture );
4516 info->hwndMenuOwner = wine_server_ptr_handle( reply->menu_owner );
4517 info->hwndMoveSize = wine_server_ptr_handle( reply->move_size );
4518 info->hwndCaret = wine_server_ptr_handle( reply->caret );
4519 info->rcCaret.left = reply->rect.left;
4520 info->rcCaret.top = reply->rect.top;
4521 info->rcCaret.right = reply->rect.right;
4522 info->rcCaret.bottom = reply->rect.bottom;
4523 if (reply->menu_owner) info->flags |= GUI_INMENUMODE;
4524 if (reply->move_size) info->flags |= GUI_INMOVESIZE;
4525 if (reply->caret) info->flags |= GUI_CARETBLINKING;
4528 SERVER_END_REQ;
4529 return ret;
4533 /******************************************************************
4534 * IsHungAppWindow (USER32.@)
4537 BOOL WINAPI IsHungAppWindow( HWND hWnd )
4539 BOOL ret;
4541 SERVER_START_REQ( is_window_hung )
4543 req->win = wine_server_user_handle( hWnd );
4544 ret = !wine_server_call_err( req ) && reply->is_hung;
4546 SERVER_END_REQ;
4547 return ret;
4550 /******************************************************************
4551 * ChangeWindowMessageFilter (USER32.@)
4553 BOOL WINAPI ChangeWindowMessageFilter( UINT message, DWORD flag )
4555 FIXME( "%x %08x\n", message, flag );
4556 return TRUE;