user32: Pack the COPYDATASTRUCT structure in messages to allow crossing 32/64 boundaries.
[wine/multimedia.git] / dlls / user32 / message.c
blobef4c0347854f713649162bbbe7044731161ee281
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 #include "ntstatus.h"
29 #define WIN32_NO_STATUS
30 #include "windef.h"
31 #include "winbase.h"
32 #include "wingdi.h"
33 #include "winuser.h"
34 #include "winerror.h"
35 #include "winnls.h"
36 #include "dbt.h"
37 #include "dde.h"
38 #include "imm.h"
39 #include "ddk/imm.h"
40 #include "wine/unicode.h"
41 #include "wine/server.h"
42 #include "user_private.h"
43 #include "win.h"
44 #include "controls.h"
45 #include "wine/debug.h"
46 #include "wine/exception.h"
48 WINE_DEFAULT_DEBUG_CHANNEL(msg);
49 WINE_DECLARE_DEBUG_CHANNEL(relay);
50 WINE_DECLARE_DEBUG_CHANNEL(key);
52 #define WM_NCMOUSEFIRST WM_NCMOUSEMOVE
53 #define WM_NCMOUSELAST (WM_NCMOUSEFIRST+(WM_MOUSELAST-WM_MOUSEFIRST))
55 #define MAX_PACK_COUNT 4
57 #define SYS_TIMER_RATE 55 /* min. timer rate in ms (actually 54.925)*/
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 /* the structures are unpacked on top of the packed ones, so make sure they fit */
150 C_ASSERT( sizeof(struct packed_CREATESTRUCTW) >= sizeof(CREATESTRUCTW) );
151 C_ASSERT( sizeof(struct packed_DRAWITEMSTRUCT) >= sizeof(DRAWITEMSTRUCT) );
152 C_ASSERT( sizeof(struct packed_MEASUREITEMSTRUCT) >= sizeof(MEASUREITEMSTRUCT) );
153 C_ASSERT( sizeof(struct packed_DELETEITEMSTRUCT) >= sizeof(DELETEITEMSTRUCT) );
154 C_ASSERT( sizeof(struct packed_COMPAREITEMSTRUCT) >= sizeof(COMPAREITEMSTRUCT) );
155 C_ASSERT( sizeof(struct packed_WINDOWPOS) >= sizeof(WINDOWPOS) );
156 C_ASSERT( sizeof(struct packed_COPYDATASTRUCT) >= sizeof(COPYDATASTRUCT) );
158 union packed_structs
160 struct packed_CREATESTRUCTW cs;
161 struct packed_DRAWITEMSTRUCT dis;
162 struct packed_MEASUREITEMSTRUCT mis;
163 struct packed_DELETEITEMSTRUCT dls;
164 struct packed_COMPAREITEMSTRUCT cis;
165 struct packed_WINDOWPOS wp;
166 struct packed_COPYDATASTRUCT cds;
169 /* description of the data fields that need to be packed along with a sent message */
170 struct packed_message
172 union packed_structs ps;
173 int count;
174 const void *data[MAX_PACK_COUNT];
175 size_t size[MAX_PACK_COUNT];
178 /* info about the message currently being received by the current thread */
179 struct received_message_info
181 enum message_type type;
182 MSG msg;
183 UINT flags; /* InSendMessageEx return flags */
186 /* structure to group all parameters for sent messages of the various kinds */
187 struct send_message_info
189 enum message_type type;
190 DWORD dest_tid;
191 HWND hwnd;
192 UINT msg;
193 WPARAM wparam;
194 LPARAM lparam;
195 UINT flags; /* flags for SendMessageTimeout */
196 UINT timeout; /* timeout for SendMessageTimeout */
197 SENDASYNCPROC callback; /* callback function for SendMessageCallback */
198 ULONG_PTR data; /* callback data */
199 enum wm_char_mapping wm_char;
203 /* Message class descriptor */
204 static const WCHAR messageW[] = {'M','e','s','s','a','g','e',0};
206 const struct builtin_class_descr MESSAGE_builtin_class =
208 messageW, /* name */
209 0, /* style */
210 WINPROC_MESSAGE, /* proc */
211 0, /* extra */
212 IDC_ARROW, /* cursor */
213 0 /* brush */
218 /* flag for messages that contain pointers */
219 /* 32 messages per entry, messages 0..31 map to bits 0..31 */
221 #define SET(msg) (1 << ((msg) & 31))
223 static const unsigned int message_pointer_flags[] =
225 /* 0x00 - 0x1f */
226 SET(WM_CREATE) | SET(WM_SETTEXT) | SET(WM_GETTEXT) |
227 SET(WM_WININICHANGE) | SET(WM_DEVMODECHANGE),
228 /* 0x20 - 0x3f */
229 SET(WM_GETMINMAXINFO) | SET(WM_DRAWITEM) | SET(WM_MEASUREITEM) | SET(WM_DELETEITEM) |
230 SET(WM_COMPAREITEM),
231 /* 0x40 - 0x5f */
232 SET(WM_WINDOWPOSCHANGING) | SET(WM_WINDOWPOSCHANGED) | SET(WM_COPYDATA) |
233 SET(WM_NOTIFY) | SET(WM_HELP),
234 /* 0x60 - 0x7f */
235 SET(WM_STYLECHANGING) | SET(WM_STYLECHANGED),
236 /* 0x80 - 0x9f */
237 SET(WM_NCCREATE) | SET(WM_NCCALCSIZE) | SET(WM_GETDLGCODE),
238 /* 0xa0 - 0xbf */
239 SET(EM_GETSEL) | SET(EM_GETRECT) | SET(EM_SETRECT) | SET(EM_SETRECTNP),
240 /* 0xc0 - 0xdf */
241 SET(EM_REPLACESEL) | SET(EM_GETLINE) | SET(EM_SETTABSTOPS),
242 /* 0xe0 - 0xff */
243 SET(SBM_GETRANGE) | SET(SBM_SETSCROLLINFO) | SET(SBM_GETSCROLLINFO) | SET(SBM_GETSCROLLBARINFO),
244 /* 0x100 - 0x11f */
246 /* 0x120 - 0x13f */
248 /* 0x140 - 0x15f */
249 SET(CB_GETEDITSEL) | SET(CB_ADDSTRING) | SET(CB_DIR) | SET(CB_GETLBTEXT) |
250 SET(CB_INSERTSTRING) | SET(CB_FINDSTRING) | SET(CB_SELECTSTRING) |
251 SET(CB_GETDROPPEDCONTROLRECT) | SET(CB_FINDSTRINGEXACT),
252 /* 0x160 - 0x17f */
254 /* 0x180 - 0x19f */
255 SET(LB_ADDSTRING) | SET(LB_INSERTSTRING) | SET(LB_GETTEXT) | SET(LB_SELECTSTRING) |
256 SET(LB_DIR) | SET(LB_FINDSTRING) |
257 SET(LB_GETSELITEMS) | SET(LB_SETTABSTOPS) | SET(LB_ADDFILE) | SET(LB_GETITEMRECT),
258 /* 0x1a0 - 0x1bf */
259 SET(LB_FINDSTRINGEXACT),
260 /* 0x1c0 - 0x1df */
262 /* 0x1e0 - 0x1ff */
264 /* 0x200 - 0x21f */
265 SET(WM_NEXTMENU) | SET(WM_SIZING) | SET(WM_MOVING) | SET(WM_DEVICECHANGE),
266 /* 0x220 - 0x23f */
267 SET(WM_MDICREATE) | SET(WM_MDIGETACTIVE) | SET(WM_DROPOBJECT) |
268 SET(WM_QUERYDROPOBJECT) | SET(WM_DRAGLOOP) | SET(WM_DRAGSELECT) | SET(WM_DRAGMOVE),
269 /* 0x240 - 0x25f */
271 /* 0x260 - 0x27f */
273 /* 0x280 - 0x29f */
275 /* 0x2a0 - 0x2bf */
277 /* 0x2c0 - 0x2df */
279 /* 0x2e0 - 0x2ff */
281 /* 0x300 - 0x31f */
282 SET(WM_ASKCBFORMATNAME)
285 /* flags for messages that contain Unicode strings */
286 static const unsigned int message_unicode_flags[] =
288 /* 0x00 - 0x1f */
289 SET(WM_CREATE) | SET(WM_SETTEXT) | SET(WM_GETTEXT) | SET(WM_GETTEXTLENGTH) |
290 SET(WM_WININICHANGE) | SET(WM_DEVMODECHANGE),
291 /* 0x20 - 0x3f */
292 SET(WM_CHARTOITEM),
293 /* 0x40 - 0x5f */
295 /* 0x60 - 0x7f */
297 /* 0x80 - 0x9f */
298 SET(WM_NCCREATE),
299 /* 0xa0 - 0xbf */
301 /* 0xc0 - 0xdf */
302 SET(EM_REPLACESEL) | SET(EM_GETLINE) | SET(EM_SETPASSWORDCHAR),
303 /* 0xe0 - 0xff */
305 /* 0x100 - 0x11f */
306 SET(WM_CHAR) | SET(WM_DEADCHAR) | SET(WM_SYSCHAR) | SET(WM_SYSDEADCHAR),
307 /* 0x120 - 0x13f */
308 SET(WM_MENUCHAR),
309 /* 0x140 - 0x15f */
310 SET(CB_ADDSTRING) | SET(CB_DIR) | SET(CB_GETLBTEXT) | SET(CB_GETLBTEXTLEN) |
311 SET(CB_INSERTSTRING) | SET(CB_FINDSTRING) | SET(CB_SELECTSTRING) | SET(CB_FINDSTRINGEXACT),
312 /* 0x160 - 0x17f */
314 /* 0x180 - 0x19f */
315 SET(LB_ADDSTRING) | SET(LB_INSERTSTRING) | SET(LB_GETTEXT) | SET(LB_GETTEXTLEN) |
316 SET(LB_SELECTSTRING) | SET(LB_DIR) | SET(LB_FINDSTRING) | SET(LB_ADDFILE),
317 /* 0x1a0 - 0x1bf */
318 SET(LB_FINDSTRINGEXACT),
319 /* 0x1c0 - 0x1df */
321 /* 0x1e0 - 0x1ff */
323 /* 0x200 - 0x21f */
325 /* 0x220 - 0x23f */
326 SET(WM_MDICREATE),
327 /* 0x240 - 0x25f */
329 /* 0x260 - 0x27f */
331 /* 0x280 - 0x29f */
332 SET(WM_IME_CHAR),
333 /* 0x2a0 - 0x2bf */
335 /* 0x2c0 - 0x2df */
337 /* 0x2e0 - 0x2ff */
339 /* 0x300 - 0x31f */
340 SET(WM_PAINTCLIPBOARD) | SET(WM_SIZECLIPBOARD) | SET(WM_ASKCBFORMATNAME)
343 /* check whether a given message type includes pointers */
344 static inline int is_pointer_message( UINT message )
346 if (message >= 8*sizeof(message_pointer_flags)) return FALSE;
347 return (message_pointer_flags[message / 32] & SET(message)) != 0;
350 /* check whether a given message type contains Unicode (or ASCII) chars */
351 static inline int is_unicode_message( UINT message )
353 if (message >= 8*sizeof(message_unicode_flags)) return FALSE;
354 return (message_unicode_flags[message / 32] & SET(message)) != 0;
357 #undef SET
359 /* add a data field to a packed message */
360 static inline void push_data( struct packed_message *data, const void *ptr, size_t size )
362 data->data[data->count] = ptr;
363 data->size[data->count] = size;
364 data->count++;
367 /* add a string to a packed message */
368 static inline void push_string( struct packed_message *data, LPCWSTR str )
370 push_data( data, str, (strlenW(str) + 1) * sizeof(WCHAR) );
373 /* make sure that the buffer contains a valid null-terminated Unicode string */
374 static inline BOOL check_string( LPCWSTR str, size_t size )
376 for (size /= sizeof(WCHAR); size; size--, str++)
377 if (!*str) return TRUE;
378 return FALSE;
381 /* pack a pointer into a 32/64 portable format */
382 static inline ULONGLONG pack_ptr( const void *ptr )
384 return (ULONG_PTR)ptr;
387 /* unpack a potentially 64-bit pointer, returning 0 when truncated */
388 static inline void *unpack_ptr( ULONGLONG ptr64 )
390 if ((ULONG_PTR)ptr64 != ptr64) return 0;
391 return (void *)(ULONG_PTR)ptr64;
394 /* make sure that there is space for 'size' bytes in buffer, growing it if needed */
395 static inline void *get_buffer_space( void **buffer, size_t size )
397 void *ret;
399 if (*buffer)
401 if (!(ret = HeapReAlloc( GetProcessHeap(), 0, *buffer, size )))
402 HeapFree( GetProcessHeap(), 0, *buffer );
404 else ret = HeapAlloc( GetProcessHeap(), 0, size );
406 *buffer = ret;
407 return ret;
410 /* check whether a combobox expects strings or ids in CB_ADDSTRING/CB_INSERTSTRING */
411 static inline BOOL combobox_has_strings( HWND hwnd )
413 DWORD style = GetWindowLongA( hwnd, GWL_STYLE );
414 return (!(style & (CBS_OWNERDRAWFIXED | CBS_OWNERDRAWVARIABLE)) || (style & CBS_HASSTRINGS));
417 /* check whether a listbox expects strings or ids in LB_ADDSTRING/LB_INSERTSTRING */
418 static inline BOOL listbox_has_strings( HWND hwnd )
420 DWORD style = GetWindowLongA( hwnd, GWL_STYLE );
421 return (!(style & (LBS_OWNERDRAWFIXED | LBS_OWNERDRAWVARIABLE)) || (style & LBS_HASSTRINGS));
424 /* check whether message is in the range of keyboard messages */
425 static inline BOOL is_keyboard_message( UINT message )
427 return (message >= WM_KEYFIRST && message <= WM_KEYLAST);
430 /* check whether message is in the range of mouse messages */
431 static inline BOOL is_mouse_message( UINT message )
433 return ((message >= WM_NCMOUSEFIRST && message <= WM_NCMOUSELAST) ||
434 (message >= WM_MOUSEFIRST && message <= WM_MOUSELAST));
437 /* check whether message matches the specified hwnd filter */
438 static inline BOOL check_hwnd_filter( const MSG *msg, HWND hwnd_filter )
440 if (!hwnd_filter || hwnd_filter == GetDesktopWindow()) return TRUE;
441 return (msg->hwnd == hwnd_filter || IsChild( hwnd_filter, msg->hwnd ));
444 /* check for pending WM_CHAR message with DBCS trailing byte */
445 static inline BOOL get_pending_wmchar( MSG *msg, UINT first, UINT last, BOOL remove )
447 struct wm_char_mapping_data *data = get_user_thread_info()->wmchar_data;
449 if (!data || !data->get_msg.message) return FALSE;
450 if ((first || last) && (first > WM_CHAR || last < WM_CHAR)) return FALSE;
451 if (!msg) return FALSE;
452 *msg = data->get_msg;
453 if (remove) data->get_msg.message = 0;
454 return TRUE;
458 /***********************************************************************
459 * MessageWndProc
461 * Window procedure for "Message" windows (HWND_MESSAGE parent).
463 LRESULT WINAPI MessageWndProc( HWND hwnd, UINT message, WPARAM wParam, LPARAM lParam )
465 if (message == WM_NCCREATE) return TRUE;
466 return 0; /* all other messages are ignored */
470 /***********************************************************************
471 * broadcast_message_callback
473 * Helper callback for broadcasting messages.
475 static BOOL CALLBACK broadcast_message_callback( HWND hwnd, LPARAM lparam )
477 struct send_message_info *info = (struct send_message_info *)lparam;
478 if (!(GetWindowLongW( hwnd, GWL_STYLE ) & (WS_POPUP|WS_CAPTION))) return TRUE;
479 switch(info->type)
481 case MSG_UNICODE:
482 SendMessageTimeoutW( hwnd, info->msg, info->wparam, info->lparam,
483 info->flags, info->timeout, NULL );
484 break;
485 case MSG_ASCII:
486 SendMessageTimeoutA( hwnd, info->msg, info->wparam, info->lparam,
487 info->flags, info->timeout, NULL );
488 break;
489 case MSG_NOTIFY:
490 SendNotifyMessageW( hwnd, info->msg, info->wparam, info->lparam );
491 break;
492 case MSG_CALLBACK:
493 SendMessageCallbackW( hwnd, info->msg, info->wparam, info->lparam,
494 info->callback, info->data );
495 break;
496 case MSG_POSTED:
497 PostMessageW( hwnd, info->msg, info->wparam, info->lparam );
498 break;
499 default:
500 ERR( "bad type %d\n", info->type );
501 break;
503 return TRUE;
507 /***********************************************************************
508 * map_wparam_AtoW
510 * Convert the wparam of an ASCII message to Unicode.
512 BOOL map_wparam_AtoW( UINT message, WPARAM *wparam, enum wm_char_mapping mapping )
514 char ch[2];
515 WCHAR wch[2];
517 wch[0] = wch[1] = 0;
518 switch(message)
520 case WM_CHAR:
521 /* WM_CHAR is magic: a DBCS char can be sent/posted as two consecutive WM_CHAR
522 * messages, in which case the first char is stored, and the conversion
523 * to Unicode only takes place once the second char is sent/posted.
525 if (mapping != WMCHAR_MAP_NOMAPPING)
527 struct wm_char_mapping_data *data = get_user_thread_info()->wmchar_data;
528 BYTE low = LOBYTE(*wparam);
530 if (HIBYTE(*wparam))
532 ch[0] = low;
533 ch[1] = HIBYTE(*wparam);
534 RtlMultiByteToUnicodeN( wch, sizeof(wch), NULL, ch, 2 );
535 TRACE( "map %02x,%02x -> %04x mapping %u\n", (BYTE)ch[0], (BYTE)ch[1], wch[0], mapping );
536 if (data) data->lead_byte[mapping] = 0;
538 else if (data && data->lead_byte[mapping])
540 ch[0] = data->lead_byte[mapping];
541 ch[1] = low;
542 RtlMultiByteToUnicodeN( wch, sizeof(wch), NULL, ch, 2 );
543 TRACE( "map stored %02x,%02x -> %04x mapping %u\n", (BYTE)ch[0], (BYTE)ch[1], wch[0], mapping );
544 data->lead_byte[mapping] = 0;
546 else if (!IsDBCSLeadByte( low ))
548 ch[0] = low;
549 RtlMultiByteToUnicodeN( wch, sizeof(wch), NULL, ch, 1 );
550 TRACE( "map %02x -> %04x\n", (BYTE)ch[0], wch[0] );
551 if (data) data->lead_byte[mapping] = 0;
553 else /* store it and wait for trail byte */
555 if (!data)
557 if (!(data = HeapAlloc( GetProcessHeap(), HEAP_ZERO_MEMORY, sizeof(*data) )))
558 return FALSE;
559 get_user_thread_info()->wmchar_data = data;
561 TRACE( "storing lead byte %02x mapping %u\n", low, mapping );
562 data->lead_byte[mapping] = low;
563 return FALSE;
565 *wparam = MAKEWPARAM(wch[0], wch[1]);
566 break;
568 /* else fall through */
569 case WM_CHARTOITEM:
570 case EM_SETPASSWORDCHAR:
571 case WM_DEADCHAR:
572 case WM_SYSCHAR:
573 case WM_SYSDEADCHAR:
574 case WM_MENUCHAR:
575 ch[0] = LOBYTE(*wparam);
576 ch[1] = HIBYTE(*wparam);
577 RtlMultiByteToUnicodeN( wch, sizeof(wch), NULL, ch, 2 );
578 *wparam = MAKEWPARAM(wch[0], wch[1]);
579 break;
580 case WM_IME_CHAR:
581 ch[0] = HIBYTE(*wparam);
582 ch[1] = LOBYTE(*wparam);
583 if (ch[0]) RtlMultiByteToUnicodeN( wch, sizeof(wch[0]), NULL, ch, 2 );
584 else RtlMultiByteToUnicodeN( wch, sizeof(wch[0]), NULL, ch + 1, 1 );
585 *wparam = MAKEWPARAM(wch[0], HIWORD(*wparam));
586 break;
588 return TRUE;
592 /***********************************************************************
593 * map_wparam_WtoA
595 * Convert the wparam of a Unicode message to ASCII.
597 static void map_wparam_WtoA( MSG *msg, BOOL remove )
599 BYTE ch[2];
600 WCHAR wch[2];
601 DWORD len;
603 switch(msg->message)
605 case WM_CHAR:
606 if (!HIWORD(msg->wParam))
608 wch[0] = LOWORD(msg->wParam);
609 ch[0] = ch[1] = 0;
610 RtlUnicodeToMultiByteN( (LPSTR)ch, 2, &len, wch, sizeof(wch[0]) );
611 if (len == 2) /* DBCS char */
613 struct wm_char_mapping_data *data = get_user_thread_info()->wmchar_data;
614 if (!data)
616 if (!(data = HeapAlloc( GetProcessHeap(), HEAP_ZERO_MEMORY, sizeof(*data) ))) return;
617 get_user_thread_info()->wmchar_data = data;
619 if (remove)
621 data->get_msg = *msg;
622 data->get_msg.wParam = ch[1];
624 msg->wParam = ch[0];
625 return;
628 /* else fall through */
629 case WM_CHARTOITEM:
630 case EM_SETPASSWORDCHAR:
631 case WM_DEADCHAR:
632 case WM_SYSCHAR:
633 case WM_SYSDEADCHAR:
634 case WM_MENUCHAR:
635 wch[0] = LOWORD(msg->wParam);
636 wch[1] = HIWORD(msg->wParam);
637 ch[0] = ch[1] = 0;
638 RtlUnicodeToMultiByteN( (LPSTR)ch, 2, NULL, wch, sizeof(wch) );
639 msg->wParam = MAKEWPARAM( ch[0] | (ch[1] << 8), 0 );
640 break;
641 case WM_IME_CHAR:
642 wch[0] = LOWORD(msg->wParam);
643 ch[0] = ch[1] = 0;
644 RtlUnicodeToMultiByteN( (LPSTR)ch, 2, &len, wch, sizeof(wch[0]) );
645 if (len == 2)
646 msg->wParam = MAKEWPARAM( (ch[0] << 8) | ch[1], HIWORD(msg->wParam) );
647 else
648 msg->wParam = MAKEWPARAM( ch[0], HIWORD(msg->wParam) );
649 break;
654 /***********************************************************************
655 * pack_message
657 * Pack a message for sending to another process.
658 * Return the size of the data we expect in the message reply.
659 * Set data->count to -1 if there is an error.
661 static size_t pack_message( HWND hwnd, UINT message, WPARAM wparam, LPARAM lparam,
662 struct packed_message *data )
664 data->count = 0;
665 switch(message)
667 case WM_NCCREATE:
668 case WM_CREATE:
670 CREATESTRUCTW *cs = (CREATESTRUCTW *)lparam;
671 data->ps.cs.lpCreateParams = pack_ptr( cs->lpCreateParams );
672 data->ps.cs.hInstance = pack_ptr( cs->hInstance );
673 data->ps.cs.hMenu = wine_server_user_handle( cs->hMenu );
674 data->ps.cs.hwndParent = wine_server_user_handle( cs->hwndParent );
675 data->ps.cs.cy = cs->cy;
676 data->ps.cs.cx = cs->cx;
677 data->ps.cs.y = cs->y;
678 data->ps.cs.x = cs->x;
679 data->ps.cs.style = cs->style;
680 data->ps.cs.dwExStyle = cs->dwExStyle;
681 data->ps.cs.lpszName = pack_ptr( cs->lpszName );
682 data->ps.cs.lpszClass = pack_ptr( cs->lpszClass );
683 push_data( data, &data->ps.cs, sizeof(data->ps.cs) );
684 if (!IS_INTRESOURCE(cs->lpszName)) push_string( data, cs->lpszName );
685 if (!IS_INTRESOURCE(cs->lpszClass)) push_string( data, cs->lpszClass );
686 return sizeof(data->ps.cs);
688 case WM_GETTEXT:
689 case WM_ASKCBFORMATNAME:
690 return wparam * sizeof(WCHAR);
691 case WM_WININICHANGE:
692 if (lparam) push_string(data, (LPWSTR)lparam );
693 return 0;
694 case WM_SETTEXT:
695 case WM_DEVMODECHANGE:
696 case CB_DIR:
697 case LB_DIR:
698 case LB_ADDFILE:
699 case EM_REPLACESEL:
700 push_string( data, (LPWSTR)lparam );
701 return 0;
702 case WM_GETMINMAXINFO:
703 push_data( data, (MINMAXINFO *)lparam, sizeof(MINMAXINFO) );
704 return sizeof(MINMAXINFO);
705 case WM_DRAWITEM:
707 DRAWITEMSTRUCT *dis = (DRAWITEMSTRUCT *)lparam;
708 data->ps.dis.CtlType = dis->CtlType;
709 data->ps.dis.CtlID = dis->CtlID;
710 data->ps.dis.itemID = dis->itemID;
711 data->ps.dis.itemAction = dis->itemAction;
712 data->ps.dis.itemState = dis->itemState;
713 data->ps.dis.hwndItem = wine_server_user_handle( dis->hwndItem );
714 data->ps.dis.hDC = wine_server_user_handle( dis->hDC ); /* FIXME */
715 data->ps.dis.rcItem = dis->rcItem;
716 data->ps.dis.itemData = dis->itemData;
717 push_data( data, &data->ps.dis, sizeof(data->ps.dis) );
718 return 0;
720 case WM_MEASUREITEM:
722 MEASUREITEMSTRUCT *mis = (MEASUREITEMSTRUCT *)lparam;
723 data->ps.mis.CtlType = mis->CtlType;
724 data->ps.mis.CtlID = mis->CtlID;
725 data->ps.mis.itemID = mis->itemID;
726 data->ps.mis.itemWidth = mis->itemWidth;
727 data->ps.mis.itemHeight = mis->itemHeight;
728 data->ps.mis.itemData = mis->itemData;
729 push_data( data, &data->ps.mis, sizeof(data->ps.mis) );
730 return sizeof(data->ps.mis);
732 case WM_DELETEITEM:
734 DELETEITEMSTRUCT *dls = (DELETEITEMSTRUCT *)lparam;
735 data->ps.dls.CtlType = dls->CtlType;
736 data->ps.dls.CtlID = dls->CtlID;
737 data->ps.dls.itemID = dls->itemID;
738 data->ps.dls.hwndItem = wine_server_user_handle( dls->hwndItem );
739 data->ps.dls.itemData = dls->itemData;
740 push_data( data, &data->ps.dls, sizeof(data->ps.dls) );
741 return 0;
743 case WM_COMPAREITEM:
745 COMPAREITEMSTRUCT *cis = (COMPAREITEMSTRUCT *)lparam;
746 data->ps.cis.CtlType = cis->CtlType;
747 data->ps.cis.CtlID = cis->CtlID;
748 data->ps.cis.hwndItem = wine_server_user_handle( cis->hwndItem );
749 data->ps.cis.itemID1 = cis->itemID1;
750 data->ps.cis.itemData1 = cis->itemData1;
751 data->ps.cis.itemID2 = cis->itemID2;
752 data->ps.cis.itemData2 = cis->itemData2;
753 data->ps.cis.dwLocaleId = cis->dwLocaleId;
754 push_data( data, &data->ps.cis, sizeof(data->ps.cis) );
755 return 0;
757 case WM_WINDOWPOSCHANGING:
758 case WM_WINDOWPOSCHANGED:
760 WINDOWPOS *wp = (WINDOWPOS *)lparam;
761 data->ps.wp.hwnd = wine_server_user_handle( wp->hwnd );
762 data->ps.wp.hwndInsertAfter = wine_server_user_handle( wp->hwndInsertAfter );
763 data->ps.wp.x = wp->x;
764 data->ps.wp.y = wp->y;
765 data->ps.wp.cx = wp->cx;
766 data->ps.wp.cy = wp->cy;
767 data->ps.wp.flags = wp->flags;
768 push_data( data, &data->ps.wp, sizeof(data->ps.wp) );
769 return sizeof(data->ps.wp);
771 case WM_COPYDATA:
773 COPYDATASTRUCT *cds = (COPYDATASTRUCT *)lparam;
774 data->ps.cds.cbData = cds->cbData;
775 data->ps.cds.dwData = cds->dwData;
776 data->ps.cds.lpData = pack_ptr( cds->lpData );
777 push_data( data, &data->ps.cds, sizeof(data->ps.cds) );
778 if (cds->lpData) push_data( data, cds->lpData, cds->cbData );
779 return 0;
781 case WM_NOTIFY:
782 /* WM_NOTIFY cannot be sent across processes (MSDN) */
783 data->count = -1;
784 return 0;
785 case WM_HELP:
786 push_data( data, (HELPINFO *)lparam, sizeof(HELPINFO) );
787 return 0;
788 case WM_STYLECHANGING:
789 case WM_STYLECHANGED:
790 push_data( data, (STYLESTRUCT *)lparam, sizeof(STYLESTRUCT) );
791 return 0;
792 case WM_NCCALCSIZE:
793 if (!wparam)
795 push_data( data, (RECT *)lparam, sizeof(RECT) );
796 return sizeof(RECT);
798 else
800 NCCALCSIZE_PARAMS *nc = (NCCALCSIZE_PARAMS *)lparam;
801 push_data( data, nc, sizeof(*nc) );
802 push_data( data, nc->lppos, sizeof(*nc->lppos) );
803 return sizeof(*nc) + sizeof(*nc->lppos);
805 case WM_GETDLGCODE:
806 if (lparam) push_data( data, (MSG *)lparam, sizeof(MSG) );
807 return sizeof(MSG);
808 case SBM_SETSCROLLINFO:
809 push_data( data, (SCROLLINFO *)lparam, sizeof(SCROLLINFO) );
810 return 0;
811 case SBM_GETSCROLLINFO:
812 push_data( data, (SCROLLINFO *)lparam, sizeof(SCROLLINFO) );
813 return sizeof(SCROLLINFO);
814 case SBM_GETSCROLLBARINFO:
816 const SCROLLBARINFO *info = (const SCROLLBARINFO *)lparam;
817 size_t size = min( info->cbSize, sizeof(SCROLLBARINFO) );
818 push_data( data, info, size );
819 return size;
821 case EM_GETSEL:
822 case SBM_GETRANGE:
823 case CB_GETEDITSEL:
825 size_t size = 0;
826 if (wparam) size += sizeof(DWORD);
827 if (lparam) size += sizeof(DWORD);
828 return size;
830 case EM_GETRECT:
831 case LB_GETITEMRECT:
832 case CB_GETDROPPEDCONTROLRECT:
833 return sizeof(RECT);
834 case EM_SETRECT:
835 case EM_SETRECTNP:
836 push_data( data, (RECT *)lparam, sizeof(RECT) );
837 return 0;
838 case EM_GETLINE:
840 WORD *pw = (WORD *)lparam;
841 push_data( data, pw, sizeof(*pw) );
842 return *pw * sizeof(WCHAR);
844 case EM_SETTABSTOPS:
845 case LB_SETTABSTOPS:
846 if (wparam) push_data( data, (UINT *)lparam, sizeof(UINT) * wparam );
847 return 0;
848 case CB_ADDSTRING:
849 case CB_INSERTSTRING:
850 case CB_FINDSTRING:
851 case CB_FINDSTRINGEXACT:
852 case CB_SELECTSTRING:
853 if (combobox_has_strings( hwnd )) push_string( data, (LPWSTR)lparam );
854 return 0;
855 case CB_GETLBTEXT:
856 if (!combobox_has_strings( hwnd )) return sizeof(ULONG_PTR);
857 return (SendMessageW( hwnd, CB_GETLBTEXTLEN, wparam, 0 ) + 1) * sizeof(WCHAR);
858 case LB_ADDSTRING:
859 case LB_INSERTSTRING:
860 case LB_FINDSTRING:
861 case LB_FINDSTRINGEXACT:
862 case LB_SELECTSTRING:
863 if (listbox_has_strings( hwnd )) push_string( data, (LPWSTR)lparam );
864 return 0;
865 case LB_GETTEXT:
866 if (!listbox_has_strings( hwnd )) return sizeof(ULONG_PTR);
867 return (SendMessageW( hwnd, LB_GETTEXTLEN, wparam, 0 ) + 1) * sizeof(WCHAR);
868 case LB_GETSELITEMS:
869 return wparam * sizeof(UINT);
870 case WM_NEXTMENU:
871 push_data( data, (MDINEXTMENU *)lparam, sizeof(MDINEXTMENU) );
872 return sizeof(MDINEXTMENU);
873 case WM_SIZING:
874 case WM_MOVING:
875 push_data( data, (RECT *)lparam, sizeof(RECT) );
876 return sizeof(RECT);
877 case WM_MDICREATE:
879 MDICREATESTRUCTW *cs = (MDICREATESTRUCTW *)lparam;
880 push_data( data, cs, sizeof(*cs) );
881 if (!IS_INTRESOURCE(cs->szTitle)) push_string( data, cs->szTitle );
882 if (!IS_INTRESOURCE(cs->szClass)) push_string( data, cs->szClass );
883 return sizeof(*cs);
885 case WM_MDIGETACTIVE:
886 if (lparam) return sizeof(BOOL);
887 return 0;
888 case WM_DEVICECHANGE:
890 DEV_BROADCAST_HDR *header = (DEV_BROADCAST_HDR *)lparam;
891 push_data( data, header, header->dbch_size );
892 return 0;
894 case WM_WINE_SETWINDOWPOS:
895 push_data( data, (WINDOWPOS *)lparam, sizeof(WINDOWPOS) );
896 return 0;
897 case WM_WINE_KEYBOARD_LL_HOOK:
899 struct hook_extra_info *h_extra = (struct hook_extra_info *)lparam;
900 push_data( data, h_extra, sizeof(*h_extra) );
901 push_data( data, (LPVOID)h_extra->lparam, sizeof(KBDLLHOOKSTRUCT) );
902 return 0;
904 case WM_WINE_MOUSE_LL_HOOK:
906 struct hook_extra_info *h_extra = (struct hook_extra_info *)lparam;
907 push_data( data, h_extra, sizeof(*h_extra) );
908 push_data( data, (LPVOID)h_extra->lparam, sizeof(MSLLHOOKSTRUCT) );
909 return 0;
911 case WM_NCPAINT:
912 if (wparam <= 1) return 0;
913 FIXME( "WM_NCPAINT hdc packing not supported yet\n" );
914 data->count = -1;
915 return 0;
916 case WM_PAINT:
917 if (!wparam) return 0;
918 /* fall through */
920 /* these contain an HFONT */
921 case WM_SETFONT:
922 case WM_GETFONT:
923 /* these contain an HDC */
924 case WM_ERASEBKGND:
925 case WM_ICONERASEBKGND:
926 case WM_CTLCOLORMSGBOX:
927 case WM_CTLCOLOREDIT:
928 case WM_CTLCOLORLISTBOX:
929 case WM_CTLCOLORBTN:
930 case WM_CTLCOLORDLG:
931 case WM_CTLCOLORSCROLLBAR:
932 case WM_CTLCOLORSTATIC:
933 case WM_PRINT:
934 case WM_PRINTCLIENT:
935 /* these contain an HGLOBAL */
936 case WM_PAINTCLIPBOARD:
937 case WM_SIZECLIPBOARD:
938 /* these contain HICON */
939 case WM_GETICON:
940 case WM_SETICON:
941 case WM_QUERYDRAGICON:
942 case WM_QUERYPARKICON:
943 /* these contain pointers */
944 case WM_DROPOBJECT:
945 case WM_QUERYDROPOBJECT:
946 case WM_DRAGLOOP:
947 case WM_DRAGSELECT:
948 case WM_DRAGMOVE:
949 FIXME( "msg %x (%s) not supported yet\n", message, SPY_GetMsgName(message, hwnd) );
950 data->count = -1;
951 return 0;
953 return 0;
957 /***********************************************************************
958 * unpack_message
960 * Unpack a message received from another process.
962 static BOOL unpack_message( HWND hwnd, UINT message, WPARAM *wparam, LPARAM *lparam,
963 void **buffer, size_t size )
965 size_t minsize = 0;
966 union packed_structs *ps = *buffer;
968 switch(message)
970 case WM_NCCREATE:
971 case WM_CREATE:
973 CREATESTRUCTW cs;
974 WCHAR *str = (WCHAR *)(&ps->cs + 1);
975 if (size < sizeof(ps->cs)) return FALSE;
976 size -= sizeof(ps->cs);
977 cs.lpCreateParams = unpack_ptr( ps->cs.lpCreateParams );
978 cs.hInstance = unpack_ptr( ps->cs.hInstance );
979 cs.hMenu = wine_server_ptr_handle( ps->cs.hMenu );
980 cs.hwndParent = wine_server_ptr_handle( ps->cs.hwndParent );
981 cs.cy = ps->cs.cy;
982 cs.cx = ps->cs.cx;
983 cs.y = ps->cs.y;
984 cs.x = ps->cs.x;
985 cs.style = ps->cs.style;
986 cs.dwExStyle = ps->cs.dwExStyle;
987 cs.lpszName = unpack_ptr( ps->cs.lpszName );
988 cs.lpszClass = unpack_ptr( ps->cs.lpszClass );
989 if (ps->cs.lpszName >> 16)
991 if (!check_string( str, size )) return FALSE;
992 cs.lpszName = str;
993 size -= (strlenW(str) + 1) * sizeof(WCHAR);
994 str += strlenW(str) + 1;
996 if (ps->cs.lpszClass >> 16)
998 if (!check_string( str, size )) return FALSE;
999 cs.lpszClass = str;
1001 memcpy( &ps->cs, &cs, sizeof(cs) );
1002 break;
1004 case WM_GETTEXT:
1005 case WM_ASKCBFORMATNAME:
1006 if (!get_buffer_space( buffer, (*wparam * sizeof(WCHAR)) )) return FALSE;
1007 break;
1008 case WM_WININICHANGE:
1009 if (!*lparam) return TRUE;
1010 /* fall through */
1011 case WM_SETTEXT:
1012 case WM_DEVMODECHANGE:
1013 case CB_DIR:
1014 case LB_DIR:
1015 case LB_ADDFILE:
1016 case EM_REPLACESEL:
1017 if (!check_string( *buffer, size )) return FALSE;
1018 break;
1019 case WM_GETMINMAXINFO:
1020 minsize = sizeof(MINMAXINFO);
1021 break;
1022 case WM_DRAWITEM:
1024 DRAWITEMSTRUCT dis;
1025 if (size < sizeof(ps->dis)) return FALSE;
1026 dis.CtlType = ps->dis.CtlType;
1027 dis.CtlID = ps->dis.CtlID;
1028 dis.itemID = ps->dis.itemID;
1029 dis.itemAction = ps->dis.itemAction;
1030 dis.itemState = ps->dis.itemState;
1031 dis.hwndItem = wine_server_ptr_handle( ps->dis.hwndItem );
1032 dis.hDC = wine_server_ptr_handle( ps->dis.hDC );
1033 dis.rcItem = ps->dis.rcItem;
1034 dis.itemData = (ULONG_PTR)unpack_ptr( ps->dis.itemData );
1035 memcpy( &ps->dis, &dis, sizeof(dis) );
1036 break;
1038 case WM_MEASUREITEM:
1040 MEASUREITEMSTRUCT mis;
1041 if (size < sizeof(ps->mis)) return FALSE;
1042 mis.CtlType = ps->mis.CtlType;
1043 mis.CtlID = ps->mis.CtlID;
1044 mis.itemID = ps->mis.itemID;
1045 mis.itemWidth = ps->mis.itemWidth;
1046 mis.itemHeight = ps->mis.itemHeight;
1047 mis.itemData = (ULONG_PTR)unpack_ptr( ps->mis.itemData );
1048 memcpy( &ps->mis, &mis, sizeof(mis) );
1049 break;
1051 case WM_DELETEITEM:
1053 DELETEITEMSTRUCT dls;
1054 if (size < sizeof(ps->dls)) return FALSE;
1055 dls.CtlType = ps->dls.CtlType;
1056 dls.CtlID = ps->dls.CtlID;
1057 dls.itemID = ps->dls.itemID;
1058 dls.hwndItem = wine_server_ptr_handle( ps->dls.hwndItem );
1059 dls.itemData = (ULONG_PTR)unpack_ptr( ps->dls.itemData );
1060 memcpy( &ps->dls, &dls, sizeof(dls) );
1061 break;
1063 case WM_COMPAREITEM:
1065 COMPAREITEMSTRUCT cis;
1066 if (size < sizeof(ps->cis)) return FALSE;
1067 cis.CtlType = ps->cis.CtlType;
1068 cis.CtlID = ps->cis.CtlID;
1069 cis.hwndItem = wine_server_ptr_handle( ps->cis.hwndItem );
1070 cis.itemID1 = ps->cis.itemID1;
1071 cis.itemData1 = (ULONG_PTR)unpack_ptr( ps->cis.itemData1 );
1072 cis.itemID2 = ps->cis.itemID2;
1073 cis.itemData2 = (ULONG_PTR)unpack_ptr( ps->cis.itemData2 );
1074 cis.dwLocaleId = ps->cis.dwLocaleId;
1075 memcpy( &ps->cis, &cis, sizeof(cis) );
1076 break;
1078 case WM_WINDOWPOSCHANGING:
1079 case WM_WINDOWPOSCHANGED:
1080 case WM_WINE_SETWINDOWPOS:
1082 WINDOWPOS wp;
1083 if (size < sizeof(ps->wp)) return FALSE;
1084 wp.hwnd = wine_server_ptr_handle( ps->wp.hwnd );
1085 wp.hwndInsertAfter = wine_server_ptr_handle( ps->wp.hwndInsertAfter );
1086 wp.x = ps->wp.x;
1087 wp.y = ps->wp.y;
1088 wp.cx = ps->wp.cx;
1089 wp.cy = ps->wp.cy;
1090 wp.flags = ps->wp.flags;
1091 memcpy( &ps->wp, &wp, sizeof(wp) );
1092 break;
1094 case WM_COPYDATA:
1096 COPYDATASTRUCT cds;
1097 if (size < sizeof(ps->cds)) return FALSE;
1098 cds.dwData = (ULONG_PTR)unpack_ptr( ps->cds.dwData );
1099 if (ps->cds.lpData)
1101 cds.cbData = ps->cds.cbData;
1102 cds.lpData = &ps->cds + 1;
1103 minsize = sizeof(ps->cds) + cds.cbData;
1105 else
1107 cds.cbData = 0;
1108 cds.lpData = 0;
1110 memcpy( &ps->cds, &cds, sizeof(cds) );
1111 break;
1113 case WM_NOTIFY:
1114 /* WM_NOTIFY cannot be sent across processes (MSDN) */
1115 return FALSE;
1116 case WM_HELP:
1117 minsize = sizeof(HELPINFO);
1118 break;
1119 case WM_STYLECHANGING:
1120 case WM_STYLECHANGED:
1121 minsize = sizeof(STYLESTRUCT);
1122 break;
1123 case WM_NCCALCSIZE:
1124 if (!*wparam) minsize = sizeof(RECT);
1125 else
1127 NCCALCSIZE_PARAMS *nc = *buffer;
1128 if (size < sizeof(*nc) + sizeof(*nc->lppos)) return FALSE;
1129 nc->lppos = (WINDOWPOS *)(nc + 1);
1131 break;
1132 case WM_GETDLGCODE:
1133 if (!*lparam) return TRUE;
1134 minsize = sizeof(MSG);
1135 break;
1136 case SBM_SETSCROLLINFO:
1137 minsize = sizeof(SCROLLINFO);
1138 break;
1139 case SBM_GETSCROLLINFO:
1140 if (!get_buffer_space( buffer, sizeof(SCROLLINFO ))) return FALSE;
1141 break;
1142 case SBM_GETSCROLLBARINFO:
1143 if (!get_buffer_space( buffer, sizeof(SCROLLBARINFO ))) return FALSE;
1144 break;
1145 case EM_GETSEL:
1146 case SBM_GETRANGE:
1147 case CB_GETEDITSEL:
1148 if (*wparam || *lparam)
1150 if (!get_buffer_space( buffer, 2*sizeof(DWORD) )) return FALSE;
1151 if (*wparam) *wparam = (WPARAM)*buffer;
1152 if (*lparam) *lparam = (LPARAM)((DWORD *)*buffer + 1);
1154 return TRUE;
1155 case EM_GETRECT:
1156 case LB_GETITEMRECT:
1157 case CB_GETDROPPEDCONTROLRECT:
1158 if (!get_buffer_space( buffer, sizeof(RECT) )) return FALSE;
1159 break;
1160 case EM_SETRECT:
1161 case EM_SETRECTNP:
1162 minsize = sizeof(RECT);
1163 break;
1164 case EM_GETLINE:
1166 WORD len;
1167 if (size < sizeof(WORD)) return FALSE;
1168 len = *(WORD *)*buffer;
1169 if (!get_buffer_space( buffer, (len + 1) * sizeof(WCHAR) )) return FALSE;
1170 *lparam = (LPARAM)*buffer + sizeof(WORD); /* don't erase WORD at start of buffer */
1171 return TRUE;
1173 case EM_SETTABSTOPS:
1174 case LB_SETTABSTOPS:
1175 if (!*wparam) return TRUE;
1176 minsize = *wparam * sizeof(UINT);
1177 break;
1178 case CB_ADDSTRING:
1179 case CB_INSERTSTRING:
1180 case CB_FINDSTRING:
1181 case CB_FINDSTRINGEXACT:
1182 case CB_SELECTSTRING:
1183 case LB_ADDSTRING:
1184 case LB_INSERTSTRING:
1185 case LB_FINDSTRING:
1186 case LB_FINDSTRINGEXACT:
1187 case LB_SELECTSTRING:
1188 if (!*buffer) return TRUE;
1189 if (!check_string( *buffer, size )) return FALSE;
1190 break;
1191 case CB_GETLBTEXT:
1193 size = sizeof(ULONG_PTR);
1194 if (combobox_has_strings( hwnd ))
1195 size = (SendMessageW( hwnd, CB_GETLBTEXTLEN, *wparam, 0 ) + 1) * sizeof(WCHAR);
1196 if (!get_buffer_space( buffer, size )) return FALSE;
1197 break;
1199 case LB_GETTEXT:
1201 size = sizeof(ULONG_PTR);
1202 if (listbox_has_strings( hwnd ))
1203 size = (SendMessageW( hwnd, LB_GETTEXTLEN, *wparam, 0 ) + 1) * sizeof(WCHAR);
1204 if (!get_buffer_space( buffer, size )) return FALSE;
1205 break;
1207 case LB_GETSELITEMS:
1208 if (!get_buffer_space( buffer, *wparam * sizeof(UINT) )) return FALSE;
1209 break;
1210 case WM_NEXTMENU:
1211 minsize = sizeof(MDINEXTMENU);
1212 if (!get_buffer_space( buffer, sizeof(MDINEXTMENU) )) return FALSE;
1213 break;
1214 case WM_SIZING:
1215 case WM_MOVING:
1216 minsize = sizeof(RECT);
1217 if (!get_buffer_space( buffer, sizeof(RECT) )) return FALSE;
1218 break;
1219 case WM_MDICREATE:
1221 MDICREATESTRUCTW *cs = *buffer;
1222 WCHAR *str = (WCHAR *)(cs + 1);
1223 if (size < sizeof(*cs)) return FALSE;
1224 size -= sizeof(*cs);
1225 if (!IS_INTRESOURCE(cs->szTitle))
1227 if (!check_string( str, size )) return FALSE;
1228 cs->szTitle = str;
1229 size -= (strlenW(str) + 1) * sizeof(WCHAR);
1230 str += strlenW(str) + 1;
1232 if (!IS_INTRESOURCE(cs->szClass))
1234 if (!check_string( str, size )) return FALSE;
1235 cs->szClass = str;
1237 break;
1239 case WM_MDIGETACTIVE:
1240 if (!*lparam) return TRUE;
1241 if (!get_buffer_space( buffer, sizeof(BOOL) )) return FALSE;
1242 break;
1243 case WM_DEVICECHANGE:
1244 minsize = sizeof(DEV_BROADCAST_HDR);
1245 break;
1246 case WM_WINE_KEYBOARD_LL_HOOK:
1247 case WM_WINE_MOUSE_LL_HOOK:
1249 struct hook_extra_info *h_extra = *buffer;
1251 minsize = sizeof(struct hook_extra_info) +
1252 (message == WM_WINE_KEYBOARD_LL_HOOK ? sizeof(KBDLLHOOKSTRUCT)
1253 : sizeof(MSLLHOOKSTRUCT));
1254 if (size < minsize) return FALSE;
1255 h_extra->lparam = (LPARAM)(h_extra + 1);
1256 break;
1258 case WM_NCPAINT:
1259 if (*wparam <= 1) return TRUE;
1260 FIXME( "WM_NCPAINT hdc unpacking not supported\n" );
1261 return FALSE;
1262 case WM_PAINT:
1263 if (!*wparam) return TRUE;
1264 /* fall through */
1266 /* these contain an HFONT */
1267 case WM_SETFONT:
1268 case WM_GETFONT:
1269 /* these contain an HDC */
1270 case WM_ERASEBKGND:
1271 case WM_ICONERASEBKGND:
1272 case WM_CTLCOLORMSGBOX:
1273 case WM_CTLCOLOREDIT:
1274 case WM_CTLCOLORLISTBOX:
1275 case WM_CTLCOLORBTN:
1276 case WM_CTLCOLORDLG:
1277 case WM_CTLCOLORSCROLLBAR:
1278 case WM_CTLCOLORSTATIC:
1279 case WM_PRINT:
1280 case WM_PRINTCLIENT:
1281 /* these contain an HGLOBAL */
1282 case WM_PAINTCLIPBOARD:
1283 case WM_SIZECLIPBOARD:
1284 /* these contain HICON */
1285 case WM_GETICON:
1286 case WM_SETICON:
1287 case WM_QUERYDRAGICON:
1288 case WM_QUERYPARKICON:
1289 /* these contain pointers */
1290 case WM_DROPOBJECT:
1291 case WM_QUERYDROPOBJECT:
1292 case WM_DRAGLOOP:
1293 case WM_DRAGSELECT:
1294 case WM_DRAGMOVE:
1295 FIXME( "msg %x (%s) not supported yet\n", message, SPY_GetMsgName(message, hwnd) );
1296 return FALSE;
1298 default:
1299 return TRUE; /* message doesn't need any unpacking */
1302 /* default exit for most messages: check minsize and store buffer in lparam */
1303 if (size < minsize) return FALSE;
1304 *lparam = (LPARAM)*buffer;
1305 return TRUE;
1309 /***********************************************************************
1310 * pack_reply
1312 * Pack a reply to a message for sending to another process.
1314 static void pack_reply( HWND hwnd, UINT message, WPARAM wparam, LPARAM lparam,
1315 LRESULT res, struct packed_message *data )
1317 data->count = 0;
1318 switch(message)
1320 case WM_NCCREATE:
1321 case WM_CREATE:
1323 CREATESTRUCTW *cs = (CREATESTRUCTW *)lparam;
1324 data->ps.cs.lpCreateParams = (ULONG_PTR)cs->lpCreateParams;
1325 data->ps.cs.hInstance = (ULONG_PTR)cs->hInstance;
1326 data->ps.cs.hMenu = wine_server_user_handle( cs->hMenu );
1327 data->ps.cs.hwndParent = wine_server_user_handle( cs->hwndParent );
1328 data->ps.cs.cy = cs->cy;
1329 data->ps.cs.cx = cs->cx;
1330 data->ps.cs.y = cs->y;
1331 data->ps.cs.x = cs->x;
1332 data->ps.cs.style = cs->style;
1333 data->ps.cs.dwExStyle = cs->dwExStyle;
1334 data->ps.cs.lpszName = (ULONG_PTR)cs->lpszName;
1335 data->ps.cs.lpszClass = (ULONG_PTR)cs->lpszClass;
1336 push_data( data, &data->ps.cs, sizeof(data->ps.cs) );
1337 break;
1339 case WM_GETTEXT:
1340 case CB_GETLBTEXT:
1341 case LB_GETTEXT:
1342 push_data( data, (WCHAR *)lparam, (res + 1) * sizeof(WCHAR) );
1343 break;
1344 case WM_GETMINMAXINFO:
1345 push_data( data, (MINMAXINFO *)lparam, sizeof(MINMAXINFO) );
1346 break;
1347 case WM_MEASUREITEM:
1349 MEASUREITEMSTRUCT *mis = (MEASUREITEMSTRUCT *)lparam;
1350 data->ps.mis.CtlType = mis->CtlType;
1351 data->ps.mis.CtlID = mis->CtlID;
1352 data->ps.mis.itemID = mis->itemID;
1353 data->ps.mis.itemWidth = mis->itemWidth;
1354 data->ps.mis.itemHeight = mis->itemHeight;
1355 data->ps.mis.itemData = mis->itemData;
1356 push_data( data, &data->ps.mis, sizeof(data->ps.mis) );
1357 break;
1359 case WM_WINDOWPOSCHANGING:
1360 case WM_WINDOWPOSCHANGED:
1362 WINDOWPOS *wp = (WINDOWPOS *)lparam;
1363 data->ps.wp.hwnd = wine_server_user_handle( wp->hwnd );
1364 data->ps.wp.hwndInsertAfter = wine_server_user_handle( wp->hwndInsertAfter );
1365 data->ps.wp.x = wp->x;
1366 data->ps.wp.y = wp->y;
1367 data->ps.wp.cx = wp->cx;
1368 data->ps.wp.cy = wp->cy;
1369 data->ps.wp.flags = wp->flags;
1370 push_data( data, &data->ps.wp, sizeof(data->ps.wp) );
1371 break;
1373 case WM_GETDLGCODE:
1374 if (lparam) push_data( data, (MSG *)lparam, sizeof(MSG) );
1375 break;
1376 case SBM_GETSCROLLINFO:
1377 push_data( data, (SCROLLINFO *)lparam, sizeof(SCROLLINFO) );
1378 break;
1379 case EM_GETRECT:
1380 case LB_GETITEMRECT:
1381 case CB_GETDROPPEDCONTROLRECT:
1382 case WM_SIZING:
1383 case WM_MOVING:
1384 push_data( data, (RECT *)lparam, sizeof(RECT) );
1385 break;
1386 case EM_GETLINE:
1388 WORD *ptr = (WORD *)lparam;
1389 push_data( data, ptr, ptr[-1] * sizeof(WCHAR) );
1390 break;
1392 case LB_GETSELITEMS:
1393 push_data( data, (UINT *)lparam, wparam * sizeof(UINT) );
1394 break;
1395 case WM_MDIGETACTIVE:
1396 if (lparam) push_data( data, (BOOL *)lparam, sizeof(BOOL) );
1397 break;
1398 case WM_NCCALCSIZE:
1399 if (!wparam)
1400 push_data( data, (RECT *)lparam, sizeof(RECT) );
1401 else
1403 NCCALCSIZE_PARAMS *nc = (NCCALCSIZE_PARAMS *)lparam;
1404 push_data( data, nc, sizeof(*nc) );
1405 push_data( data, nc->lppos, sizeof(*nc->lppos) );
1407 break;
1408 case EM_GETSEL:
1409 case SBM_GETRANGE:
1410 case CB_GETEDITSEL:
1411 if (wparam) push_data( data, (DWORD *)wparam, sizeof(DWORD) );
1412 if (lparam) push_data( data, (DWORD *)lparam, sizeof(DWORD) );
1413 break;
1414 case WM_NEXTMENU:
1415 push_data( data, (MDINEXTMENU *)lparam, sizeof(MDINEXTMENU) );
1416 break;
1417 case WM_MDICREATE:
1418 push_data( data, (MDICREATESTRUCTW *)lparam, sizeof(MDICREATESTRUCTW) );
1419 break;
1420 case WM_ASKCBFORMATNAME:
1421 push_data( data, (WCHAR *)lparam, (strlenW((WCHAR *)lparam) + 1) * sizeof(WCHAR) );
1422 break;
1427 /***********************************************************************
1428 * unpack_reply
1430 * Unpack a message reply received from another process.
1432 static void unpack_reply( HWND hwnd, UINT message, WPARAM wparam, LPARAM lparam,
1433 void *buffer, size_t size )
1435 union packed_structs *ps = buffer;
1437 switch(message)
1439 case WM_NCCREATE:
1440 case WM_CREATE:
1441 if (size >= sizeof(ps->cs))
1443 CREATESTRUCTW *cs = (CREATESTRUCTW *)lparam;
1444 cs->lpCreateParams = unpack_ptr( ps->cs.lpCreateParams );
1445 cs->hInstance = unpack_ptr( ps->cs.hInstance );
1446 cs->hMenu = wine_server_ptr_handle( ps->cs.hMenu );
1447 cs->hwndParent = wine_server_ptr_handle( ps->cs.hwndParent );
1448 cs->cy = ps->cs.cy;
1449 cs->cx = ps->cs.cx;
1450 cs->y = ps->cs.y;
1451 cs->x = ps->cs.x;
1452 cs->style = ps->cs.style;
1453 cs->dwExStyle = ps->cs.dwExStyle;
1454 /* don't allow changing name and class pointers */
1456 break;
1457 case WM_GETTEXT:
1458 case WM_ASKCBFORMATNAME:
1459 memcpy( (WCHAR *)lparam, buffer, min( wparam*sizeof(WCHAR), size ));
1460 break;
1461 case WM_GETMINMAXINFO:
1462 memcpy( (MINMAXINFO *)lparam, buffer, min( sizeof(MINMAXINFO), size ));
1463 break;
1464 case WM_MEASUREITEM:
1465 if (size >= sizeof(ps->mis))
1467 MEASUREITEMSTRUCT *mis = (MEASUREITEMSTRUCT *)lparam;
1468 mis->CtlType = ps->mis.CtlType;
1469 mis->CtlID = ps->mis.CtlID;
1470 mis->itemID = ps->mis.itemID;
1471 mis->itemWidth = ps->mis.itemWidth;
1472 mis->itemHeight = ps->mis.itemHeight;
1473 mis->itemData = (ULONG_PTR)unpack_ptr( ps->mis.itemData );
1475 break;
1476 case WM_WINDOWPOSCHANGING:
1477 case WM_WINDOWPOSCHANGED:
1478 if (size >= sizeof(ps->wp))
1480 WINDOWPOS *wp = (WINDOWPOS *)lparam;
1481 wp->hwnd = wine_server_ptr_handle( ps->wp.hwnd );
1482 wp->hwndInsertAfter = wine_server_ptr_handle( ps->wp.hwndInsertAfter );
1483 wp->x = ps->wp.x;
1484 wp->y = ps->wp.y;
1485 wp->cx = ps->wp.cx;
1486 wp->cy = ps->wp.cy;
1487 wp->flags = ps->wp.flags;
1489 break;
1490 case WM_GETDLGCODE:
1491 if (lparam) memcpy( (MSG *)lparam, buffer, min( sizeof(MSG), size ));
1492 break;
1493 case SBM_GETSCROLLINFO:
1494 memcpy( (SCROLLINFO *)lparam, buffer, min( sizeof(SCROLLINFO), size ));
1495 break;
1496 case SBM_GETSCROLLBARINFO:
1497 memcpy( (SCROLLBARINFO *)lparam, buffer, min( sizeof(SCROLLBARINFO), size ));
1498 break;
1499 case EM_GETRECT:
1500 case CB_GETDROPPEDCONTROLRECT:
1501 case LB_GETITEMRECT:
1502 case WM_SIZING:
1503 case WM_MOVING:
1504 memcpy( (RECT *)lparam, buffer, min( sizeof(RECT), size ));
1505 break;
1506 case EM_GETLINE:
1507 size = min( size, (size_t)*(WORD *)lparam );
1508 memcpy( (WCHAR *)lparam, buffer, size );
1509 break;
1510 case LB_GETSELITEMS:
1511 memcpy( (UINT *)lparam, buffer, min( wparam*sizeof(UINT), size ));
1512 break;
1513 case LB_GETTEXT:
1514 case CB_GETLBTEXT:
1515 memcpy( (WCHAR *)lparam, buffer, size );
1516 break;
1517 case WM_NEXTMENU:
1518 memcpy( (MDINEXTMENU *)lparam, buffer, min( sizeof(MDINEXTMENU), size ));
1519 break;
1520 case WM_MDIGETACTIVE:
1521 if (lparam) memcpy( (BOOL *)lparam, buffer, min( sizeof(BOOL), size ));
1522 break;
1523 case WM_NCCALCSIZE:
1524 if (!wparam)
1525 memcpy( (RECT *)lparam, buffer, min( sizeof(RECT), size ));
1526 else
1528 NCCALCSIZE_PARAMS *nc = (NCCALCSIZE_PARAMS *)lparam;
1529 WINDOWPOS *wp = nc->lppos;
1530 memcpy( nc, buffer, min( sizeof(*nc), size ));
1531 if (size > sizeof(*nc))
1533 size -= sizeof(*nc);
1534 memcpy( wp, (NCCALCSIZE_PARAMS*)buffer + 1, min( sizeof(*wp), size ));
1536 nc->lppos = wp; /* restore the original pointer */
1538 break;
1539 case EM_GETSEL:
1540 case SBM_GETRANGE:
1541 case CB_GETEDITSEL:
1542 if (wparam)
1544 memcpy( (DWORD *)wparam, buffer, min( sizeof(DWORD), size ));
1545 if (size <= sizeof(DWORD)) break;
1546 size -= sizeof(DWORD);
1547 buffer = (DWORD *)buffer + 1;
1549 if (lparam) memcpy( (DWORD *)lparam, buffer, min( sizeof(DWORD), size ));
1550 break;
1551 case WM_MDICREATE:
1553 MDICREATESTRUCTW *cs = (MDICREATESTRUCTW *)lparam;
1554 LPCWSTR title = cs->szTitle, class = cs->szClass;
1555 memcpy( cs, buffer, min( sizeof(*cs), size ));
1556 cs->szTitle = title; /* restore the original pointers */
1557 cs->szClass = class;
1558 break;
1560 default:
1561 ERR( "should not happen: unexpected message %x\n", message );
1562 break;
1567 /***********************************************************************
1568 * reply_message
1570 * Send a reply to a sent message.
1572 static void reply_message( struct received_message_info *info, LRESULT result, BOOL remove )
1574 struct packed_message data;
1575 int i, replied = info->flags & ISMEX_REPLIED;
1577 if (info->flags & ISMEX_NOTIFY) return; /* notify messages don't get replies */
1578 if (!remove && replied) return; /* replied already */
1580 memset( &data, 0, sizeof(data) );
1581 info->flags |= ISMEX_REPLIED;
1583 if (info->type == MSG_OTHER_PROCESS && !replied)
1585 pack_reply( info->msg.hwnd, info->msg.message, info->msg.wParam,
1586 info->msg.lParam, result, &data );
1589 SERVER_START_REQ( reply_message )
1591 req->result = result;
1592 req->remove = remove;
1593 for (i = 0; i < data.count; i++) wine_server_add_data( req, data.data[i], data.size[i] );
1594 wine_server_call( req );
1596 SERVER_END_REQ;
1600 /***********************************************************************
1601 * handle_internal_message
1603 * Handle an internal Wine message instead of calling the window proc.
1605 static LRESULT handle_internal_message( HWND hwnd, UINT msg, WPARAM wparam, LPARAM lparam )
1607 switch(msg)
1609 case WM_WINE_DESTROYWINDOW:
1610 return WIN_DestroyWindow( hwnd );
1611 case WM_WINE_SETWINDOWPOS:
1612 if (is_desktop_window( hwnd )) return 0;
1613 return USER_SetWindowPos( (WINDOWPOS *)lparam );
1614 case WM_WINE_SHOWWINDOW:
1615 if (is_desktop_window( hwnd )) return 0;
1616 return ShowWindow( hwnd, wparam );
1617 case WM_WINE_SETPARENT:
1618 if (is_desktop_window( hwnd )) return 0;
1619 return (LRESULT)SetParent( hwnd, (HWND)wparam );
1620 case WM_WINE_SETWINDOWLONG:
1621 return WIN_SetWindowLong( hwnd, (short)LOWORD(wparam), HIWORD(wparam), lparam, TRUE );
1622 case WM_WINE_ENABLEWINDOW:
1623 if (is_desktop_window( hwnd )) return 0;
1624 return EnableWindow( hwnd, wparam );
1625 case WM_WINE_SETACTIVEWINDOW:
1626 if (is_desktop_window( hwnd )) return 0;
1627 return (LRESULT)SetActiveWindow( (HWND)wparam );
1628 case WM_WINE_KEYBOARD_LL_HOOK:
1629 case WM_WINE_MOUSE_LL_HOOK:
1631 struct hook_extra_info *h_extra = (struct hook_extra_info *)lparam;
1633 return call_current_hook( h_extra->handle, HC_ACTION, wparam, h_extra->lparam );
1635 default:
1636 if (msg >= WM_WINE_FIRST_DRIVER_MSG && msg <= WM_WINE_LAST_DRIVER_MSG)
1637 return USER_Driver->pWindowMessage( hwnd, msg, wparam, lparam );
1638 FIXME( "unknown internal message %x\n", msg );
1639 return 0;
1643 /* since the WM_DDE_ACK response to a WM_DDE_EXECUTE message should contain the handle
1644 * to the memory handle, we keep track (in the server side) of all pairs of handle
1645 * used (the client passes its value and the content of the memory handle), and
1646 * the server stored both values (the client, and the local one, created after the
1647 * content). When a ACK message is generated, the list of pair is searched for a
1648 * matching pair, so that the client memory handle can be returned.
1650 struct DDE_pair {
1651 HGLOBAL client_hMem;
1652 HGLOBAL server_hMem;
1655 static struct DDE_pair* dde_pairs;
1656 static int dde_num_alloc;
1657 static int dde_num_used;
1659 static CRITICAL_SECTION dde_crst;
1660 static CRITICAL_SECTION_DEBUG critsect_debug =
1662 0, 0, &dde_crst,
1663 { &critsect_debug.ProcessLocksList, &critsect_debug.ProcessLocksList },
1664 0, 0, { (DWORD_PTR)(__FILE__ ": dde_crst") }
1666 static CRITICAL_SECTION dde_crst = { &critsect_debug, -1, 0, 0, 0, 0 };
1668 static BOOL dde_add_pair(HGLOBAL chm, HGLOBAL shm)
1670 int i;
1671 #define GROWBY 4
1673 EnterCriticalSection(&dde_crst);
1675 /* now remember the pair of hMem on both sides */
1676 if (dde_num_used == dde_num_alloc)
1678 struct DDE_pair* tmp;
1679 if (dde_pairs)
1680 tmp = HeapReAlloc( GetProcessHeap(), 0, dde_pairs,
1681 (dde_num_alloc + GROWBY) * sizeof(struct DDE_pair));
1682 else
1683 tmp = HeapAlloc( GetProcessHeap(), 0,
1684 (dde_num_alloc + GROWBY) * sizeof(struct DDE_pair));
1686 if (!tmp)
1688 LeaveCriticalSection(&dde_crst);
1689 return FALSE;
1691 dde_pairs = tmp;
1692 /* zero out newly allocated part */
1693 memset(&dde_pairs[dde_num_alloc], 0, GROWBY * sizeof(struct DDE_pair));
1694 dde_num_alloc += GROWBY;
1696 #undef GROWBY
1697 for (i = 0; i < dde_num_alloc; i++)
1699 if (dde_pairs[i].server_hMem == 0)
1701 dde_pairs[i].client_hMem = chm;
1702 dde_pairs[i].server_hMem = shm;
1703 dde_num_used++;
1704 break;
1707 LeaveCriticalSection(&dde_crst);
1708 return TRUE;
1711 static HGLOBAL dde_get_pair(HGLOBAL shm)
1713 int i;
1714 HGLOBAL ret = 0;
1716 EnterCriticalSection(&dde_crst);
1717 for (i = 0; i < dde_num_alloc; i++)
1719 if (dde_pairs[i].server_hMem == shm)
1721 /* free this pair */
1722 dde_pairs[i].server_hMem = 0;
1723 dde_num_used--;
1724 ret = dde_pairs[i].client_hMem;
1725 break;
1728 LeaveCriticalSection(&dde_crst);
1729 return ret;
1732 /***********************************************************************
1733 * post_dde_message
1735 * Post a DDE message
1737 static BOOL post_dde_message( struct packed_message *data, const struct send_message_info *info )
1739 void* ptr = NULL;
1740 int size = 0;
1741 UINT_PTR uiLo, uiHi;
1742 LPARAM lp = 0;
1743 HGLOBAL hunlock = 0;
1744 int i;
1745 DWORD res;
1747 if (!UnpackDDElParam( info->msg, info->lparam, &uiLo, &uiHi ))
1748 return FALSE;
1750 lp = info->lparam;
1751 switch (info->msg)
1753 /* DDE messages which don't require packing are:
1754 * WM_DDE_INITIATE
1755 * WM_DDE_TERMINATE
1756 * WM_DDE_REQUEST
1757 * WM_DDE_UNADVISE
1759 case WM_DDE_ACK:
1760 if (HIWORD(uiHi))
1762 /* uiHi should contain a hMem from WM_DDE_EXECUTE */
1763 HGLOBAL h = dde_get_pair( (HANDLE)uiHi );
1764 if (h)
1766 /* send back the value of h on the other side */
1767 push_data( data, &h, sizeof(HGLOBAL) );
1768 lp = uiLo;
1769 TRACE( "send dde-ack %lx %08lx => %p\n", uiLo, uiHi, h );
1772 else
1774 /* uiHi should contain either an atom or 0 */
1775 TRACE( "send dde-ack %lx atom=%lx\n", uiLo, uiHi );
1776 lp = MAKELONG( uiLo, uiHi );
1778 break;
1779 case WM_DDE_ADVISE:
1780 case WM_DDE_DATA:
1781 case WM_DDE_POKE:
1782 size = 0;
1783 if (uiLo)
1785 size = GlobalSize( (HGLOBAL)uiLo ) ;
1786 if ((info->msg == WM_DDE_ADVISE && size < sizeof(DDEADVISE)) ||
1787 (info->msg == WM_DDE_DATA && size < FIELD_OFFSET(DDEDATA, Value)) ||
1788 (info->msg == WM_DDE_POKE && size < FIELD_OFFSET(DDEPOKE, Value))
1790 return FALSE;
1792 else if (info->msg != WM_DDE_DATA) return FALSE;
1794 lp = uiHi;
1795 if (uiLo)
1797 if ((ptr = GlobalLock( (HGLOBAL)uiLo) ))
1799 DDEDATA *dde_data = ptr;
1800 TRACE("unused %d, fResponse %d, fRelease %d, fDeferUpd %d, fAckReq %d, cfFormat %d\n",
1801 dde_data->unused, dde_data->fResponse, dde_data->fRelease,
1802 dde_data->reserved, dde_data->fAckReq, dde_data->cfFormat);
1803 push_data( data, ptr, size );
1804 hunlock = (HGLOBAL)uiLo;
1807 TRACE( "send ddepack %u %lx\n", size, uiHi );
1808 break;
1809 case WM_DDE_EXECUTE:
1810 if (info->lparam)
1812 if ((ptr = GlobalLock( (HGLOBAL)info->lparam) ))
1814 push_data(data, ptr, GlobalSize( (HGLOBAL)info->lparam ));
1815 /* so that the other side can send it back on ACK */
1816 lp = info->lparam;
1817 hunlock = (HGLOBAL)info->lparam;
1820 break;
1822 SERVER_START_REQ( send_message )
1824 req->id = info->dest_tid;
1825 req->type = info->type;
1826 req->flags = 0;
1827 req->win = wine_server_user_handle( info->hwnd );
1828 req->msg = info->msg;
1829 req->wparam = info->wparam;
1830 req->lparam = lp;
1831 req->timeout = TIMEOUT_INFINITE;
1832 for (i = 0; i < data->count; i++)
1833 wine_server_add_data( req, data->data[i], data->size[i] );
1834 if ((res = wine_server_call( req )))
1836 if (res == STATUS_INVALID_PARAMETER)
1837 /* FIXME: find a STATUS_ value for this one */
1838 SetLastError( ERROR_INVALID_THREAD_ID );
1839 else
1840 SetLastError( RtlNtStatusToDosError(res) );
1842 else
1843 FreeDDElParam(info->msg, info->lparam);
1845 SERVER_END_REQ;
1846 if (hunlock) GlobalUnlock(hunlock);
1848 return !res;
1851 /***********************************************************************
1852 * unpack_dde_message
1854 * Unpack a posted DDE message received from another process.
1856 static BOOL unpack_dde_message( HWND hwnd, UINT message, WPARAM *wparam, LPARAM *lparam,
1857 void **buffer, size_t size )
1859 UINT_PTR uiLo, uiHi;
1860 HGLOBAL hMem = 0;
1861 void* ptr;
1863 switch (message)
1865 case WM_DDE_ACK:
1866 if (size)
1868 /* hMem is being passed */
1869 if (size != sizeof(HGLOBAL)) return FALSE;
1870 if (!buffer || !*buffer) return FALSE;
1871 uiLo = *lparam;
1872 memcpy( &hMem, *buffer, size );
1873 uiHi = (UINT_PTR)hMem;
1874 TRACE("recv dde-ack %lx mem=%lx[%lx]\n", uiLo, uiHi, GlobalSize( hMem ));
1876 else
1878 uiLo = LOWORD( *lparam );
1879 uiHi = HIWORD( *lparam );
1880 TRACE("recv dde-ack %lx atom=%lx\n", uiLo, uiHi);
1882 *lparam = PackDDElParam( WM_DDE_ACK, uiLo, uiHi );
1883 break;
1884 case WM_DDE_ADVISE:
1885 case WM_DDE_DATA:
1886 case WM_DDE_POKE:
1887 if ((!buffer || !*buffer) && message != WM_DDE_DATA) return FALSE;
1888 uiHi = *lparam;
1889 if (size)
1891 if (!(hMem = GlobalAlloc( GMEM_MOVEABLE|GMEM_DDESHARE, size )))
1892 return FALSE;
1893 if ((ptr = GlobalLock( hMem )))
1895 memcpy( ptr, *buffer, size );
1896 GlobalUnlock( hMem );
1898 else
1900 GlobalFree( hMem );
1901 return FALSE;
1904 uiLo = (UINT_PTR)hMem;
1906 *lparam = PackDDElParam( message, uiLo, uiHi );
1907 break;
1908 case WM_DDE_EXECUTE:
1909 if (size)
1911 if (!buffer || !*buffer) return FALSE;
1912 if (!(hMem = GlobalAlloc( GMEM_MOVEABLE|GMEM_DDESHARE, size ))) return FALSE;
1913 if ((ptr = GlobalLock( hMem )))
1915 memcpy( ptr, *buffer, size );
1916 GlobalUnlock( hMem );
1917 TRACE( "exec: pairing c=%08lx s=%p\n", *lparam, hMem );
1918 if (!dde_add_pair( (HGLOBAL)*lparam, hMem ))
1920 GlobalFree( hMem );
1921 return FALSE;
1924 else
1926 GlobalFree( hMem );
1927 return FALSE;
1929 } else return FALSE;
1930 *lparam = (LPARAM)hMem;
1931 break;
1933 return TRUE;
1936 /***********************************************************************
1937 * call_window_proc
1939 * Call a window procedure and the corresponding hooks.
1941 static LRESULT call_window_proc( HWND hwnd, UINT msg, WPARAM wparam, LPARAM lparam,
1942 BOOL unicode, BOOL same_thread, enum wm_char_mapping mapping )
1944 LRESULT result = 0;
1945 CWPSTRUCT cwp;
1946 CWPRETSTRUCT cwpret;
1948 if (msg & 0x80000000)
1950 result = handle_internal_message( hwnd, msg, wparam, lparam );
1951 goto done;
1954 /* first the WH_CALLWNDPROC hook */
1955 hwnd = WIN_GetFullHandle( hwnd );
1956 cwp.lParam = lparam;
1957 cwp.wParam = wparam;
1958 cwp.message = msg;
1959 cwp.hwnd = hwnd;
1960 HOOK_CallHooks( WH_CALLWNDPROC, HC_ACTION, same_thread, (LPARAM)&cwp, unicode );
1962 /* now call the window procedure */
1963 if (!WINPROC_call_window( hwnd, msg, wparam, lparam, &result, unicode, mapping )) goto done;
1965 /* and finally the WH_CALLWNDPROCRET hook */
1966 cwpret.lResult = result;
1967 cwpret.lParam = lparam;
1968 cwpret.wParam = wparam;
1969 cwpret.message = msg;
1970 cwpret.hwnd = hwnd;
1971 HOOK_CallHooks( WH_CALLWNDPROCRET, HC_ACTION, same_thread, (LPARAM)&cwpret, unicode );
1972 done:
1973 return result;
1977 /***********************************************************************
1978 * send_parent_notify
1980 * Send a WM_PARENTNOTIFY to all ancestors of the given window, unless
1981 * the window has the WS_EX_NOPARENTNOTIFY style.
1983 static void send_parent_notify( HWND hwnd, WORD event, WORD idChild, POINT pt )
1985 /* pt has to be in the client coordinates of the parent window */
1986 MapWindowPoints( 0, hwnd, &pt, 1 );
1987 for (;;)
1989 HWND parent;
1991 if (!(GetWindowLongW( hwnd, GWL_STYLE ) & WS_CHILD)) break;
1992 if (GetWindowLongW( hwnd, GWL_EXSTYLE ) & WS_EX_NOPARENTNOTIFY) break;
1993 if (!(parent = GetParent(hwnd))) break;
1994 if (parent == GetDesktopWindow()) break;
1995 MapWindowPoints( hwnd, parent, &pt, 1 );
1996 hwnd = parent;
1997 SendMessageW( hwnd, WM_PARENTNOTIFY,
1998 MAKEWPARAM( event, idChild ), MAKELPARAM( pt.x, pt.y ) );
2003 /***********************************************************************
2004 * accept_hardware_message
2006 * Tell the server we have passed the message to the app
2007 * (even though we may end up dropping it later on)
2009 static void accept_hardware_message( UINT hw_id, BOOL remove, HWND new_hwnd )
2011 SERVER_START_REQ( accept_hardware_message )
2013 req->hw_id = hw_id;
2014 req->remove = remove;
2015 req->new_win = wine_server_user_handle( new_hwnd );
2016 if (wine_server_call( req ))
2017 FIXME("Failed to reply to MSG_HARDWARE message. Message may not be removed from queue.\n");
2019 SERVER_END_REQ;
2023 /***********************************************************************
2024 * process_keyboard_message
2026 * returns TRUE if the contents of 'msg' should be passed to the application
2028 static BOOL process_keyboard_message( MSG *msg, UINT hw_id, HWND hwnd_filter,
2029 UINT first, UINT last, BOOL remove )
2031 EVENTMSG event;
2033 if (msg->message == WM_KEYDOWN || msg->message == WM_SYSKEYDOWN ||
2034 msg->message == WM_KEYUP || msg->message == WM_SYSKEYUP)
2035 switch (msg->wParam)
2037 case VK_LSHIFT: case VK_RSHIFT:
2038 msg->wParam = VK_SHIFT;
2039 break;
2040 case VK_LCONTROL: case VK_RCONTROL:
2041 msg->wParam = VK_CONTROL;
2042 break;
2043 case VK_LMENU: case VK_RMENU:
2044 msg->wParam = VK_MENU;
2045 break;
2048 /* FIXME: is this really the right place for this hook? */
2049 event.message = msg->message;
2050 event.hwnd = msg->hwnd;
2051 event.time = msg->time;
2052 event.paramL = (msg->wParam & 0xFF) | (HIWORD(msg->lParam) << 8);
2053 event.paramH = msg->lParam & 0x7FFF;
2054 if (HIWORD(msg->lParam) & 0x0100) event.paramH |= 0x8000; /* special_key - bit */
2055 HOOK_CallHooks( WH_JOURNALRECORD, HC_ACTION, 0, (LPARAM)&event, TRUE );
2057 /* check message filters */
2058 if (msg->message < first || msg->message > last) return FALSE;
2059 if (!check_hwnd_filter( msg, hwnd_filter )) return FALSE;
2061 if (remove)
2063 if((msg->message == WM_KEYDOWN) &&
2064 (msg->hwnd != GetDesktopWindow()))
2066 /* Handle F1 key by sending out WM_HELP message */
2067 if (msg->wParam == VK_F1)
2069 PostMessageW( msg->hwnd, WM_KEYF1, 0, 0 );
2071 else if(msg->wParam >= VK_BROWSER_BACK &&
2072 msg->wParam <= VK_LAUNCH_APP2)
2074 /* FIXME: Process keystate */
2075 SendMessageW(msg->hwnd, WM_APPCOMMAND, (WPARAM)msg->hwnd, MAKELPARAM(0, (FAPPCOMMAND_KEY | (msg->wParam - VK_BROWSER_BACK + 1))));
2078 else if (msg->message == WM_KEYUP)
2080 /* Handle VK_APPS key by posting a WM_CONTEXTMENU message */
2081 if (msg->wParam == VK_APPS && !MENU_IsMenuActive())
2082 PostMessageW(msg->hwnd, WM_CONTEXTMENU, (WPARAM)msg->hwnd, -1);
2086 if (HOOK_CallHooks( WH_KEYBOARD, remove ? HC_ACTION : HC_NOREMOVE,
2087 LOWORD(msg->wParam), msg->lParam, TRUE ))
2089 /* skip this message */
2090 HOOK_CallHooks( WH_CBT, HCBT_KEYSKIPPED, LOWORD(msg->wParam), msg->lParam, TRUE );
2091 accept_hardware_message( hw_id, TRUE, 0 );
2092 return FALSE;
2094 accept_hardware_message( hw_id, remove, 0 );
2096 if ( msg->message == WM_KEYDOWN || msg->message == WM_KEYUP )
2097 if ( ImmProcessKey(msg->hwnd, GetKeyboardLayout(0), msg->wParam, msg->lParam, 0) )
2098 msg->wParam = VK_PROCESSKEY;
2100 return TRUE;
2104 /***********************************************************************
2105 * process_mouse_message
2107 * returns TRUE if the contents of 'msg' should be passed to the application
2109 static BOOL process_mouse_message( MSG *msg, UINT hw_id, ULONG_PTR extra_info, HWND hwnd_filter,
2110 UINT first, UINT last, BOOL remove )
2112 static MSG clk_msg;
2114 POINT pt;
2115 UINT message;
2116 INT hittest;
2117 EVENTMSG event;
2118 GUITHREADINFO info;
2119 MOUSEHOOKSTRUCT hook;
2120 BOOL eatMsg;
2122 /* find the window to dispatch this mouse message to */
2124 GetGUIThreadInfo( GetCurrentThreadId(), &info );
2125 if (info.hwndCapture)
2127 hittest = HTCLIENT;
2128 msg->hwnd = info.hwndCapture;
2130 else
2132 msg->hwnd = WINPOS_WindowFromPoint( msg->hwnd, msg->pt, &hittest );
2135 if (!msg->hwnd || !WIN_IsCurrentThread( msg->hwnd ))
2137 accept_hardware_message( hw_id, TRUE, msg->hwnd );
2138 return FALSE;
2141 /* FIXME: is this really the right place for this hook? */
2142 event.message = msg->message;
2143 event.time = msg->time;
2144 event.hwnd = msg->hwnd;
2145 event.paramL = msg->pt.x;
2146 event.paramH = msg->pt.y;
2147 HOOK_CallHooks( WH_JOURNALRECORD, HC_ACTION, 0, (LPARAM)&event, TRUE );
2149 if (!check_hwnd_filter( msg, hwnd_filter )) return FALSE;
2151 pt = msg->pt;
2152 message = msg->message;
2153 /* Note: windows has no concept of a non-client wheel message */
2154 if (message != WM_MOUSEWHEEL)
2156 if (hittest != HTCLIENT)
2158 message += WM_NCMOUSEMOVE - WM_MOUSEMOVE;
2159 msg->wParam = hittest;
2161 else
2163 /* coordinates don't get translated while tracking a menu */
2164 /* FIXME: should differentiate popups and top-level menus */
2165 if (!(info.flags & GUI_INMENUMODE))
2166 ScreenToClient( msg->hwnd, &pt );
2169 msg->lParam = MAKELONG( pt.x, pt.y );
2171 /* translate double clicks */
2173 if ((msg->message == WM_LBUTTONDOWN) ||
2174 (msg->message == WM_RBUTTONDOWN) ||
2175 (msg->message == WM_MBUTTONDOWN) ||
2176 (msg->message == WM_XBUTTONDOWN))
2178 BOOL update = remove;
2180 /* translate double clicks -
2181 * note that ...MOUSEMOVEs can slip in between
2182 * ...BUTTONDOWN and ...BUTTONDBLCLK messages */
2184 if ((info.flags & (GUI_INMENUMODE|GUI_INMOVESIZE)) ||
2185 hittest != HTCLIENT ||
2186 (GetClassLongA( msg->hwnd, GCL_STYLE ) & CS_DBLCLKS))
2188 if ((msg->message == clk_msg.message) &&
2189 (msg->hwnd == clk_msg.hwnd) &&
2190 (msg->wParam == clk_msg.wParam) &&
2191 (msg->time - clk_msg.time < GetDoubleClickTime()) &&
2192 (abs(msg->pt.x - clk_msg.pt.x) < GetSystemMetrics(SM_CXDOUBLECLK)/2) &&
2193 (abs(msg->pt.y - clk_msg.pt.y) < GetSystemMetrics(SM_CYDOUBLECLK)/2))
2195 message += (WM_LBUTTONDBLCLK - WM_LBUTTONDOWN);
2196 if (update)
2198 clk_msg.message = 0; /* clear the double click conditions */
2199 update = FALSE;
2203 if (message < first || message > last) return FALSE;
2204 /* update static double click conditions */
2205 if (update) clk_msg = *msg;
2207 else
2209 if (message < first || message > last) return FALSE;
2212 /* message is accepted now (but may still get dropped) */
2214 hook.pt = msg->pt;
2215 hook.hwnd = msg->hwnd;
2216 hook.wHitTestCode = hittest;
2217 hook.dwExtraInfo = extra_info;
2218 if (HOOK_CallHooks( WH_MOUSE, remove ? HC_ACTION : HC_NOREMOVE,
2219 message, (LPARAM)&hook, TRUE ))
2221 hook.pt = msg->pt;
2222 hook.hwnd = msg->hwnd;
2223 hook.wHitTestCode = hittest;
2224 hook.dwExtraInfo = extra_info;
2225 HOOK_CallHooks( WH_CBT, HCBT_CLICKSKIPPED, message, (LPARAM)&hook, TRUE );
2226 accept_hardware_message( hw_id, TRUE, 0 );
2227 return FALSE;
2230 if ((hittest == HTERROR) || (hittest == HTNOWHERE))
2232 SendMessageW( msg->hwnd, WM_SETCURSOR, (WPARAM)msg->hwnd,
2233 MAKELONG( hittest, msg->message ));
2234 accept_hardware_message( hw_id, TRUE, 0 );
2235 return FALSE;
2238 accept_hardware_message( hw_id, remove, 0 );
2240 if (!remove || info.hwndCapture)
2242 msg->message = message;
2243 return TRUE;
2246 eatMsg = FALSE;
2248 if ((msg->message == WM_LBUTTONDOWN) ||
2249 (msg->message == WM_RBUTTONDOWN) ||
2250 (msg->message == WM_MBUTTONDOWN) ||
2251 (msg->message == WM_XBUTTONDOWN))
2253 /* Send the WM_PARENTNOTIFY,
2254 * note that even for double/nonclient clicks
2255 * notification message is still WM_L/M/RBUTTONDOWN.
2257 send_parent_notify( msg->hwnd, msg->message, 0, msg->pt );
2259 /* Activate the window if needed */
2261 if (msg->hwnd != info.hwndActive)
2263 HWND hwndTop = msg->hwnd;
2264 while (hwndTop)
2266 if ((GetWindowLongW( hwndTop, GWL_STYLE ) & (WS_POPUP|WS_CHILD)) != WS_CHILD) break;
2267 hwndTop = GetParent( hwndTop );
2270 if (hwndTop && hwndTop != GetDesktopWindow())
2272 LONG ret = SendMessageW( msg->hwnd, WM_MOUSEACTIVATE, (WPARAM)hwndTop,
2273 MAKELONG( hittest, msg->message ) );
2274 switch(ret)
2276 case MA_NOACTIVATEANDEAT:
2277 eatMsg = TRUE;
2278 /* fall through */
2279 case MA_NOACTIVATE:
2280 break;
2281 case MA_ACTIVATEANDEAT:
2282 eatMsg = TRUE;
2283 /* fall through */
2284 case MA_ACTIVATE:
2285 case 0:
2286 if (!FOCUS_MouseActivate( hwndTop )) eatMsg = TRUE;
2287 break;
2288 default:
2289 WARN( "unknown WM_MOUSEACTIVATE code %d\n", ret );
2290 break;
2296 /* send the WM_SETCURSOR message */
2298 /* Windows sends the normal mouse message as the message parameter
2299 in the WM_SETCURSOR message even if it's non-client mouse message */
2300 SendMessageW( msg->hwnd, WM_SETCURSOR, (WPARAM)msg->hwnd, MAKELONG( hittest, msg->message ));
2302 msg->message = message;
2303 return !eatMsg;
2307 /***********************************************************************
2308 * process_hardware_message
2310 * Process a hardware message; return TRUE if message should be passed on to the app
2312 static BOOL process_hardware_message( MSG *msg, UINT hw_id, ULONG_PTR extra_info, HWND hwnd_filter,
2313 UINT first, UINT last, BOOL remove )
2315 if (is_keyboard_message( msg->message ))
2316 return process_keyboard_message( msg, hw_id, hwnd_filter, first, last, remove );
2318 if (is_mouse_message( msg->message ))
2319 return process_mouse_message( msg, hw_id, extra_info, hwnd_filter, first, last, remove );
2321 ERR( "unknown message type %x\n", msg->message );
2322 return FALSE;
2326 /***********************************************************************
2327 * call_sendmsg_callback
2329 * Call the callback function of SendMessageCallback.
2331 static inline void call_sendmsg_callback( SENDASYNCPROC callback, HWND hwnd, UINT msg,
2332 ULONG_PTR data, LRESULT result )
2334 if (!callback) return;
2336 if (TRACE_ON(relay))
2337 DPRINTF( "%04x:Call message callback %p (hwnd=%p,msg=%s,data=%08lx,result=%08lx)\n",
2338 GetCurrentThreadId(), callback, hwnd, SPY_GetMsgName( msg, hwnd ),
2339 data, result );
2340 callback( hwnd, msg, data, result );
2341 if (TRACE_ON(relay))
2342 DPRINTF( "%04x:Ret message callback %p (hwnd=%p,msg=%s,data=%08lx,result=%08lx)\n",
2343 GetCurrentThreadId(), callback, hwnd, SPY_GetMsgName( msg, hwnd ),
2344 data, result );
2348 /***********************************************************************
2349 * peek_message
2351 * Peek for a message matching the given parameters. Return FALSE if none available.
2352 * All pending sent messages are processed before returning.
2354 static BOOL peek_message( MSG *msg, HWND hwnd, UINT first, UINT last, UINT flags, UINT changed_mask )
2356 LRESULT result;
2357 struct user_thread_info *thread_info = get_user_thread_info();
2358 struct received_message_info info, *old_info;
2359 unsigned int hw_id = 0; /* id of previous hardware message */
2360 void *buffer;
2361 size_t buffer_size = 256;
2363 if (!(buffer = HeapAlloc( GetProcessHeap(), 0, buffer_size ))) return FALSE;
2365 if (!first && !last) last = ~0;
2366 if (hwnd == HWND_BROADCAST) hwnd = HWND_TOPMOST;
2368 for (;;)
2370 NTSTATUS res;
2371 size_t size = 0;
2372 const message_data_t *msg_data = buffer;
2374 SERVER_START_REQ( get_message )
2376 req->flags = flags;
2377 req->get_win = wine_server_user_handle( hwnd );
2378 req->get_first = first;
2379 req->get_last = last;
2380 req->hw_id = hw_id;
2381 req->wake_mask = changed_mask & (QS_SENDMESSAGE | QS_SMRESULT);
2382 req->changed_mask = changed_mask;
2383 wine_server_set_reply( req, buffer, buffer_size );
2384 if (!(res = wine_server_call( req )))
2386 size = wine_server_reply_size( reply );
2387 info.type = reply->type;
2388 info.msg.hwnd = wine_server_ptr_handle( reply->win );
2389 info.msg.message = reply->msg;
2390 info.msg.wParam = reply->wparam;
2391 info.msg.lParam = reply->lparam;
2392 info.msg.time = reply->time;
2393 info.msg.pt.x = 0;
2394 info.msg.pt.y = 0;
2395 hw_id = 0;
2396 thread_info->active_hooks = reply->active_hooks;
2398 else buffer_size = reply->total;
2400 SERVER_END_REQ;
2402 if (res)
2404 HeapFree( GetProcessHeap(), 0, buffer );
2405 if (res != STATUS_BUFFER_OVERFLOW) return FALSE;
2406 if (!(buffer = HeapAlloc( GetProcessHeap(), 0, buffer_size ))) return FALSE;
2407 continue;
2410 TRACE( "got type %d msg %x (%s) hwnd %p wp %lx lp %lx\n",
2411 info.type, info.msg.message,
2412 (info.type == MSG_WINEVENT) ? "MSG_WINEVENT" : SPY_GetMsgName(info.msg.message, info.msg.hwnd),
2413 info.msg.hwnd, info.msg.wParam, info.msg.lParam );
2415 switch(info.type)
2417 case MSG_ASCII:
2418 case MSG_UNICODE:
2419 info.flags = ISMEX_SEND;
2420 break;
2421 case MSG_NOTIFY:
2422 info.flags = ISMEX_NOTIFY;
2423 break;
2424 case MSG_CALLBACK:
2425 info.flags = ISMEX_CALLBACK;
2426 break;
2427 case MSG_CALLBACK_RESULT:
2428 if (size >= sizeof(msg_data->callback))
2429 call_sendmsg_callback( wine_server_get_ptr(msg_data->callback.callback),
2430 info.msg.hwnd, info.msg.message,
2431 msg_data->callback.data, msg_data->callback.result );
2432 continue;
2433 case MSG_WINEVENT:
2434 if (size >= sizeof(msg_data->winevent))
2436 WINEVENTPROC hook_proc;
2438 hook_proc = wine_server_get_ptr( msg_data->winevent.hook_proc );
2439 size -= sizeof(msg_data->winevent);
2440 if (size)
2442 WCHAR module[MAX_PATH];
2444 size = min( size, (MAX_PATH - 1) * sizeof(WCHAR) );
2445 memcpy( module, &msg_data->winevent + 1, size );
2446 module[size / sizeof(WCHAR)] = 0;
2447 if (!(hook_proc = get_hook_proc( hook_proc, module )))
2449 ERR( "invalid winevent hook module name %s\n", debugstr_w(module) );
2450 continue;
2454 if (TRACE_ON(relay))
2455 DPRINTF( "%04x:Call winevent proc %p (hook=%04x,event=%x,hwnd=%p,object_id=%lx,child_id=%lx,tid=%04x,time=%x)\n",
2456 GetCurrentThreadId(), hook_proc,
2457 msg_data->winevent.hook, info.msg.message, info.msg.hwnd, info.msg.wParam,
2458 info.msg.lParam, msg_data->winevent.tid, info.msg.time);
2460 hook_proc( wine_server_ptr_handle( msg_data->winevent.hook ), info.msg.message,
2461 info.msg.hwnd, info.msg.wParam, info.msg.lParam,
2462 msg_data->winevent.tid, info.msg.time );
2464 if (TRACE_ON(relay))
2465 DPRINTF( "%04x:Ret winevent proc %p (hook=%04x,event=%x,hwnd=%p,object_id=%lx,child_id=%lx,tid=%04x,time=%x)\n",
2466 GetCurrentThreadId(), hook_proc,
2467 msg_data->winevent.hook, info.msg.message, info.msg.hwnd, info.msg.wParam,
2468 info.msg.lParam, msg_data->winevent.tid, info.msg.time);
2470 continue;
2471 case MSG_OTHER_PROCESS:
2472 info.flags = ISMEX_SEND;
2473 if (!unpack_message( info.msg.hwnd, info.msg.message, &info.msg.wParam,
2474 &info.msg.lParam, &buffer, size ))
2476 /* ignore it */
2477 reply_message( &info, 0, TRUE );
2478 continue;
2480 break;
2481 case MSG_HARDWARE:
2482 if (size >= sizeof(msg_data->hardware))
2484 info.msg.pt.x = msg_data->hardware.x;
2485 info.msg.pt.y = msg_data->hardware.y;
2486 hw_id = msg_data->hardware.hw_id;
2487 if (!process_hardware_message( &info.msg, hw_id, msg_data->hardware.info,
2488 hwnd, first, last, flags & PM_REMOVE ))
2490 TRACE("dropping msg %x\n", info.msg.message );
2491 continue; /* ignore it */
2493 *msg = info.msg;
2494 thread_info->GetMessagePosVal = MAKELONG( info.msg.pt.x, info.msg.pt.y );
2495 thread_info->GetMessageTimeVal = info.msg.time;
2496 thread_info->GetMessageExtraInfoVal = msg_data->hardware.info;
2497 HeapFree( GetProcessHeap(), 0, buffer );
2498 HOOK_CallHooks( WH_GETMESSAGE, HC_ACTION, flags & PM_REMOVE, (LPARAM)msg, TRUE );
2499 return TRUE;
2501 continue;
2502 case MSG_POSTED:
2503 if (info.msg.message & 0x80000000) /* internal message */
2505 if (flags & PM_REMOVE)
2507 handle_internal_message( info.msg.hwnd, info.msg.message,
2508 info.msg.wParam, info.msg.lParam );
2509 /* if this is a nested call return right away */
2510 if (first == info.msg.message && last == info.msg.message) return FALSE;
2512 else
2513 peek_message( msg, info.msg.hwnd, info.msg.message,
2514 info.msg.message, flags | PM_REMOVE, changed_mask );
2515 continue;
2517 if (info.msg.message >= WM_DDE_FIRST && info.msg.message <= WM_DDE_LAST)
2519 if (!unpack_dde_message( info.msg.hwnd, info.msg.message, &info.msg.wParam,
2520 &info.msg.lParam, &buffer, size ))
2521 continue; /* ignore it */
2523 *msg = info.msg;
2524 msg->pt.x = (short)LOWORD( thread_info->GetMessagePosVal );
2525 msg->pt.y = (short)HIWORD( thread_info->GetMessagePosVal );
2526 thread_info->GetMessageTimeVal = info.msg.time;
2527 thread_info->GetMessageExtraInfoVal = 0;
2528 HeapFree( GetProcessHeap(), 0, buffer );
2529 HOOK_CallHooks( WH_GETMESSAGE, HC_ACTION, flags & PM_REMOVE, (LPARAM)msg, TRUE );
2530 return TRUE;
2533 /* if we get here, we have a sent message; call the window procedure */
2534 old_info = thread_info->receive_info;
2535 thread_info->receive_info = &info;
2536 result = call_window_proc( info.msg.hwnd, info.msg.message, info.msg.wParam,
2537 info.msg.lParam, (info.type != MSG_ASCII), FALSE,
2538 WMCHAR_MAP_RECVMESSAGE );
2539 reply_message( &info, result, TRUE );
2540 thread_info->receive_info = old_info;
2542 /* if some PM_QS* flags were specified, only handle sent messages from now on */
2543 if (HIWORD(flags) && !changed_mask) flags = PM_QS_SENDMESSAGE | LOWORD(flags);
2548 /***********************************************************************
2549 * process_sent_messages
2551 * Process all pending sent messages.
2553 static inline void process_sent_messages(void)
2555 MSG msg;
2556 peek_message( &msg, 0, 0, 0, PM_REMOVE | PM_QS_SENDMESSAGE, 0 );
2560 /***********************************************************************
2561 * get_server_queue_handle
2563 * Get a handle to the server message queue for the current thread.
2565 static HANDLE get_server_queue_handle(void)
2567 struct user_thread_info *thread_info = get_user_thread_info();
2568 HANDLE ret;
2570 if (!(ret = thread_info->server_queue))
2572 SERVER_START_REQ( get_msg_queue )
2574 wine_server_call( req );
2575 ret = wine_server_ptr_handle( reply->handle );
2577 SERVER_END_REQ;
2578 thread_info->server_queue = ret;
2579 if (!ret) ERR( "Cannot get server thread queue\n" );
2581 return ret;
2585 /***********************************************************************
2586 * wait_message_reply
2588 * Wait until a sent message gets replied to.
2590 static void wait_message_reply( UINT flags )
2592 HANDLE server_queue = get_server_queue_handle();
2594 for (;;)
2596 unsigned int wake_bits = 0;
2598 SERVER_START_REQ( set_queue_mask )
2600 req->wake_mask = QS_SMRESULT | ((flags & SMTO_BLOCK) ? 0 : QS_SENDMESSAGE);
2601 req->changed_mask = req->wake_mask;
2602 req->skip_wait = 1;
2603 if (!wine_server_call( req ))
2604 wake_bits = reply->wake_bits;
2606 SERVER_END_REQ;
2608 if (wake_bits & QS_SMRESULT) return; /* got a result */
2609 if (wake_bits & QS_SENDMESSAGE)
2611 /* Process the sent message immediately */
2612 process_sent_messages();
2613 continue;
2616 wow_handlers.wait_message( 1, &server_queue, INFINITE, QS_SENDMESSAGE, 0 );
2620 /***********************************************************************
2621 * put_message_in_queue
2623 * Put a sent message into the destination queue.
2624 * For inter-process message, reply_size is set to expected size of reply data.
2626 static BOOL put_message_in_queue( const struct send_message_info *info, size_t *reply_size )
2628 struct packed_message data;
2629 message_data_t msg_data;
2630 unsigned int res;
2631 int i;
2632 timeout_t timeout = TIMEOUT_INFINITE;
2634 /* Check for INFINITE timeout for compatibility with Win9x,
2635 * although Windows >= NT does not do so
2637 if (info->type != MSG_NOTIFY &&
2638 info->type != MSG_CALLBACK &&
2639 info->type != MSG_POSTED &&
2640 info->timeout &&
2641 info->timeout != INFINITE)
2643 /* timeout is signed despite the prototype */
2644 timeout = (timeout_t)max( 0, (int)info->timeout ) * -10000;
2647 memset( &data, 0, sizeof(data) );
2648 if (info->type == MSG_OTHER_PROCESS)
2650 *reply_size = pack_message( info->hwnd, info->msg, info->wparam, info->lparam, &data );
2651 if (data.count == -1)
2653 WARN( "cannot pack message %x\n", info->msg );
2654 return FALSE;
2657 else if (info->type == MSG_CALLBACK)
2659 msg_data.callback.callback = wine_server_client_ptr( info->callback );
2660 msg_data.callback.data = info->data;
2661 msg_data.callback.result = 0;
2662 data.data[0] = &msg_data;
2663 data.size[0] = sizeof(msg_data.callback);
2664 data.count = 1;
2666 else if (info->type == MSG_POSTED && info->msg >= WM_DDE_FIRST && info->msg <= WM_DDE_LAST)
2668 return post_dde_message( &data, info );
2671 SERVER_START_REQ( send_message )
2673 req->id = info->dest_tid;
2674 req->type = info->type;
2675 req->flags = 0;
2676 req->win = wine_server_user_handle( info->hwnd );
2677 req->msg = info->msg;
2678 req->wparam = info->wparam;
2679 req->lparam = info->lparam;
2680 req->timeout = timeout;
2682 if (info->flags & SMTO_ABORTIFHUNG) req->flags |= SEND_MSG_ABORT_IF_HUNG;
2683 for (i = 0; i < data.count; i++) wine_server_add_data( req, data.data[i], data.size[i] );
2684 if ((res = wine_server_call( req )))
2686 if (res == STATUS_INVALID_PARAMETER)
2687 /* FIXME: find a STATUS_ value for this one */
2688 SetLastError( ERROR_INVALID_THREAD_ID );
2689 else
2690 SetLastError( RtlNtStatusToDosError(res) );
2693 SERVER_END_REQ;
2694 return !res;
2698 /***********************************************************************
2699 * retrieve_reply
2701 * Retrieve a message reply from the server.
2703 static LRESULT retrieve_reply( const struct send_message_info *info,
2704 size_t reply_size, LRESULT *result )
2706 NTSTATUS status;
2707 void *reply_data = NULL;
2709 if (reply_size)
2711 if (!(reply_data = HeapAlloc( GetProcessHeap(), 0, reply_size )))
2713 WARN( "no memory for reply, will be truncated\n" );
2714 reply_size = 0;
2717 SERVER_START_REQ( get_message_reply )
2719 req->cancel = 1;
2720 if (reply_size) wine_server_set_reply( req, reply_data, reply_size );
2721 if (!(status = wine_server_call( req ))) *result = reply->result;
2722 reply_size = wine_server_reply_size( reply );
2724 SERVER_END_REQ;
2725 if (!status && reply_size)
2726 unpack_reply( info->hwnd, info->msg, info->wparam, info->lparam, reply_data, reply_size );
2728 HeapFree( GetProcessHeap(), 0, reply_data );
2730 TRACE( "hwnd %p msg %x (%s) wp %lx lp %lx got reply %lx (err=%d)\n",
2731 info->hwnd, info->msg, SPY_GetMsgName(info->msg, info->hwnd), info->wparam,
2732 info->lparam, *result, status );
2734 /* MSDN states that last error is 0 on timeout, but at least NT4 returns ERROR_TIMEOUT */
2735 if (status) SetLastError( RtlNtStatusToDosError(status) );
2736 return !status;
2740 /***********************************************************************
2741 * send_inter_thread_message
2743 static LRESULT send_inter_thread_message( const struct send_message_info *info, LRESULT *res_ptr )
2745 size_t reply_size = 0;
2747 TRACE( "hwnd %p msg %x (%s) wp %lx lp %lx\n",
2748 info->hwnd, info->msg, SPY_GetMsgName(info->msg, info->hwnd), info->wparam, info->lparam );
2750 USER_CheckNotLock();
2752 if (!put_message_in_queue( info, &reply_size )) return 0;
2754 /* there's no reply to wait for on notify/callback messages */
2755 if (info->type == MSG_NOTIFY || info->type == MSG_CALLBACK) return 1;
2757 wait_message_reply( info->flags );
2758 return retrieve_reply( info, reply_size, res_ptr );
2762 /***********************************************************************
2763 * send_inter_thread_callback
2765 static LRESULT send_inter_thread_callback( HWND hwnd, UINT msg, WPARAM wp, LPARAM lp,
2766 LRESULT *result, void *arg )
2768 struct send_message_info *info = arg;
2769 info->hwnd = hwnd;
2770 info->msg = msg;
2771 info->wparam = wp;
2772 info->lparam = lp;
2773 return send_inter_thread_message( info, result );
2777 /***********************************************************************
2778 * send_message
2780 * Backend implementation of the various SendMessage functions.
2782 static BOOL send_message( struct send_message_info *info, DWORD_PTR *res_ptr, BOOL unicode )
2784 DWORD dest_pid;
2785 BOOL ret;
2786 LRESULT result;
2788 if (is_broadcast(info->hwnd))
2790 EnumWindows( broadcast_message_callback, (LPARAM)info );
2791 if (res_ptr) *res_ptr = 1;
2792 return TRUE;
2795 if (!(info->dest_tid = GetWindowThreadProcessId( info->hwnd, &dest_pid ))) return FALSE;
2797 if (USER_IsExitingThread( info->dest_tid )) return FALSE;
2799 SPY_EnterMessage( SPY_SENDMESSAGE, info->hwnd, info->msg, info->wparam, info->lparam );
2801 if (info->dest_tid == GetCurrentThreadId())
2803 result = call_window_proc( info->hwnd, info->msg, info->wparam, info->lparam,
2804 unicode, TRUE, info->wm_char );
2805 if (info->type == MSG_CALLBACK)
2806 call_sendmsg_callback( info->callback, info->hwnd, info->msg, info->data, result );
2807 ret = TRUE;
2809 else
2811 if (dest_pid != GetCurrentProcessId() && (info->type == MSG_ASCII || info->type == MSG_UNICODE))
2812 info->type = MSG_OTHER_PROCESS;
2814 /* MSG_ASCII can be sent unconverted except for WM_CHAR; everything else needs to be Unicode */
2815 if (!unicode && is_unicode_message( info->msg ) &&
2816 (info->type != MSG_ASCII || info->msg == WM_CHAR))
2817 ret = WINPROC_CallProcAtoW( send_inter_thread_callback, info->hwnd, info->msg,
2818 info->wparam, info->lparam, &result, info, info->wm_char );
2819 else
2820 ret = send_inter_thread_message( info, &result );
2823 SPY_ExitMessage( SPY_RESULT_OK, info->hwnd, info->msg, result, info->wparam, info->lparam );
2824 if (ret && res_ptr) *res_ptr = result;
2825 return ret;
2829 /***********************************************************************
2830 * MSG_SendInternalMessageTimeout
2832 * Same as SendMessageTimeoutW but sends the message to a specific thread
2833 * without requiring a window handle. Only works for internal Wine messages.
2835 LRESULT MSG_SendInternalMessageTimeout( DWORD dest_pid, DWORD dest_tid,
2836 UINT msg, WPARAM wparam, LPARAM lparam,
2837 UINT flags, UINT timeout, PDWORD_PTR res_ptr )
2839 struct send_message_info info;
2840 LRESULT ret, result;
2842 assert( msg & 0x80000000 ); /* must be an internal Wine message */
2844 info.type = MSG_UNICODE;
2845 info.dest_tid = dest_tid;
2846 info.hwnd = 0;
2847 info.msg = msg;
2848 info.wparam = wparam;
2849 info.lparam = lparam;
2850 info.flags = flags;
2851 info.timeout = timeout;
2853 if (USER_IsExitingThread( dest_tid )) return 0;
2855 if (dest_tid == GetCurrentThreadId())
2857 result = handle_internal_message( 0, msg, wparam, lparam );
2858 ret = 1;
2860 else
2862 if (dest_pid != GetCurrentProcessId()) info.type = MSG_OTHER_PROCESS;
2863 ret = send_inter_thread_message( &info, &result );
2865 if (ret && res_ptr) *res_ptr = result;
2866 return ret;
2870 /***********************************************************************
2871 * SendMessageTimeoutW (USER32.@)
2873 LRESULT WINAPI SendMessageTimeoutW( HWND hwnd, UINT msg, WPARAM wparam, LPARAM lparam,
2874 UINT flags, UINT timeout, PDWORD_PTR res_ptr )
2876 struct send_message_info info;
2878 info.type = MSG_UNICODE;
2879 info.hwnd = hwnd;
2880 info.msg = msg;
2881 info.wparam = wparam;
2882 info.lparam = lparam;
2883 info.flags = flags;
2884 info.timeout = timeout;
2886 return send_message( &info, res_ptr, TRUE );
2889 /***********************************************************************
2890 * SendMessageTimeoutA (USER32.@)
2892 LRESULT WINAPI SendMessageTimeoutA( HWND hwnd, UINT msg, WPARAM wparam, LPARAM lparam,
2893 UINT flags, UINT timeout, PDWORD_PTR res_ptr )
2895 struct send_message_info info;
2897 info.type = MSG_ASCII;
2898 info.hwnd = hwnd;
2899 info.msg = msg;
2900 info.wparam = wparam;
2901 info.lparam = lparam;
2902 info.flags = flags;
2903 info.timeout = timeout;
2904 info.wm_char = WMCHAR_MAP_SENDMESSAGETIMEOUT;
2906 return send_message( &info, res_ptr, FALSE );
2910 /***********************************************************************
2911 * SendMessageW (USER32.@)
2913 LRESULT WINAPI SendMessageW( HWND hwnd, UINT msg, WPARAM wparam, LPARAM lparam )
2915 DWORD_PTR res = 0;
2916 struct send_message_info info;
2918 info.type = MSG_UNICODE;
2919 info.hwnd = hwnd;
2920 info.msg = msg;
2921 info.wparam = wparam;
2922 info.lparam = lparam;
2923 info.flags = SMTO_NORMAL;
2924 info.timeout = 0;
2926 send_message( &info, &res, TRUE );
2927 return res;
2931 /***********************************************************************
2932 * SendMessageA (USER32.@)
2934 LRESULT WINAPI SendMessageA( HWND hwnd, UINT msg, WPARAM wparam, LPARAM lparam )
2936 DWORD_PTR res = 0;
2937 struct send_message_info info;
2939 info.type = MSG_ASCII;
2940 info.hwnd = hwnd;
2941 info.msg = msg;
2942 info.wparam = wparam;
2943 info.lparam = lparam;
2944 info.flags = SMTO_NORMAL;
2945 info.timeout = 0;
2946 info.wm_char = WMCHAR_MAP_SENDMESSAGE;
2948 send_message( &info, &res, FALSE );
2949 return res;
2953 /***********************************************************************
2954 * SendNotifyMessageA (USER32.@)
2956 BOOL WINAPI SendNotifyMessageA( HWND hwnd, UINT msg, WPARAM wparam, LPARAM lparam )
2958 struct send_message_info info;
2960 if (is_pointer_message(msg))
2962 SetLastError( ERROR_MESSAGE_SYNC_ONLY );
2963 return FALSE;
2966 info.type = MSG_NOTIFY;
2967 info.hwnd = hwnd;
2968 info.msg = msg;
2969 info.wparam = wparam;
2970 info.lparam = lparam;
2971 info.flags = 0;
2972 info.wm_char = WMCHAR_MAP_SENDMESSAGETIMEOUT;
2974 return send_message( &info, NULL, FALSE );
2978 /***********************************************************************
2979 * SendNotifyMessageW (USER32.@)
2981 BOOL WINAPI SendNotifyMessageW( HWND hwnd, UINT msg, WPARAM wparam, LPARAM lparam )
2983 struct send_message_info info;
2985 if (is_pointer_message(msg))
2987 SetLastError( ERROR_MESSAGE_SYNC_ONLY );
2988 return FALSE;
2991 info.type = MSG_NOTIFY;
2992 info.hwnd = hwnd;
2993 info.msg = msg;
2994 info.wparam = wparam;
2995 info.lparam = lparam;
2996 info.flags = 0;
2998 return send_message( &info, NULL, TRUE );
3002 /***********************************************************************
3003 * SendMessageCallbackA (USER32.@)
3005 BOOL WINAPI SendMessageCallbackA( HWND hwnd, UINT msg, WPARAM wparam, LPARAM lparam,
3006 SENDASYNCPROC callback, ULONG_PTR data )
3008 struct send_message_info info;
3010 if (is_pointer_message(msg))
3012 SetLastError( ERROR_MESSAGE_SYNC_ONLY );
3013 return FALSE;
3016 info.type = MSG_CALLBACK;
3017 info.hwnd = hwnd;
3018 info.msg = msg;
3019 info.wparam = wparam;
3020 info.lparam = lparam;
3021 info.callback = callback;
3022 info.data = data;
3023 info.flags = 0;
3024 info.wm_char = WMCHAR_MAP_SENDMESSAGETIMEOUT;
3026 return send_message( &info, NULL, FALSE );
3030 /***********************************************************************
3031 * SendMessageCallbackW (USER32.@)
3033 BOOL WINAPI SendMessageCallbackW( HWND hwnd, UINT msg, WPARAM wparam, LPARAM lparam,
3034 SENDASYNCPROC callback, ULONG_PTR data )
3036 struct send_message_info info;
3038 if (is_pointer_message(msg))
3040 SetLastError( ERROR_MESSAGE_SYNC_ONLY );
3041 return FALSE;
3044 info.type = MSG_CALLBACK;
3045 info.hwnd = hwnd;
3046 info.msg = msg;
3047 info.wparam = wparam;
3048 info.lparam = lparam;
3049 info.callback = callback;
3050 info.data = data;
3051 info.flags = 0;
3053 return send_message( &info, NULL, TRUE );
3057 /***********************************************************************
3058 * ReplyMessage (USER32.@)
3060 BOOL WINAPI ReplyMessage( LRESULT result )
3062 struct received_message_info *info = get_user_thread_info()->receive_info;
3064 if (!info) return FALSE;
3065 reply_message( info, result, FALSE );
3066 return TRUE;
3070 /***********************************************************************
3071 * InSendMessage (USER32.@)
3073 BOOL WINAPI InSendMessage(void)
3075 return (InSendMessageEx(NULL) & (ISMEX_SEND|ISMEX_REPLIED)) == ISMEX_SEND;
3079 /***********************************************************************
3080 * InSendMessageEx (USER32.@)
3082 DWORD WINAPI InSendMessageEx( LPVOID reserved )
3084 struct received_message_info *info = get_user_thread_info()->receive_info;
3086 if (info) return info->flags;
3087 return ISMEX_NOSEND;
3091 /***********************************************************************
3092 * PostMessageA (USER32.@)
3094 BOOL WINAPI PostMessageA( HWND hwnd, UINT msg, WPARAM wparam, LPARAM lparam )
3096 if (!map_wparam_AtoW( msg, &wparam, WMCHAR_MAP_POSTMESSAGE )) return TRUE;
3097 return PostMessageW( hwnd, msg, wparam, lparam );
3101 /***********************************************************************
3102 * PostMessageW (USER32.@)
3104 BOOL WINAPI PostMessageW( HWND hwnd, UINT msg, WPARAM wparam, LPARAM lparam )
3106 struct send_message_info info;
3108 if (is_pointer_message( msg ))
3110 SetLastError( ERROR_MESSAGE_SYNC_ONLY );
3111 return FALSE;
3114 TRACE( "hwnd %p msg %x (%s) wp %lx lp %lx\n",
3115 hwnd, msg, SPY_GetMsgName(msg, hwnd), wparam, lparam );
3117 info.type = MSG_POSTED;
3118 info.hwnd = hwnd;
3119 info.msg = msg;
3120 info.wparam = wparam;
3121 info.lparam = lparam;
3122 info.flags = 0;
3124 if (is_broadcast(hwnd))
3126 EnumWindows( broadcast_message_callback, (LPARAM)&info );
3127 return TRUE;
3130 if (!hwnd) return PostThreadMessageW( GetCurrentThreadId(), msg, wparam, lparam );
3132 if (!(info.dest_tid = GetWindowThreadProcessId( hwnd, NULL ))) return FALSE;
3134 if (USER_IsExitingThread( info.dest_tid )) return TRUE;
3136 return put_message_in_queue( &info, NULL );
3140 /**********************************************************************
3141 * PostThreadMessageA (USER32.@)
3143 BOOL WINAPI PostThreadMessageA( DWORD thread, UINT msg, WPARAM wparam, LPARAM lparam )
3145 if (!map_wparam_AtoW( msg, &wparam, WMCHAR_MAP_POSTMESSAGE )) return TRUE;
3146 return PostThreadMessageW( thread, msg, wparam, lparam );
3150 /**********************************************************************
3151 * PostThreadMessageW (USER32.@)
3153 BOOL WINAPI PostThreadMessageW( DWORD thread, UINT msg, WPARAM wparam, LPARAM lparam )
3155 struct send_message_info info;
3157 if (is_pointer_message( msg ))
3159 SetLastError( ERROR_MESSAGE_SYNC_ONLY );
3160 return FALSE;
3162 if (USER_IsExitingThread( thread )) return TRUE;
3164 info.type = MSG_POSTED;
3165 info.dest_tid = thread;
3166 info.hwnd = 0;
3167 info.msg = msg;
3168 info.wparam = wparam;
3169 info.lparam = lparam;
3170 info.flags = 0;
3171 return put_message_in_queue( &info, NULL );
3175 /***********************************************************************
3176 * PostQuitMessage (USER32.@)
3178 * Posts a quit message to the current thread's message queue.
3180 * PARAMS
3181 * exit_code [I] Exit code to return from message loop.
3183 * RETURNS
3184 * Nothing.
3186 * NOTES
3187 * This function is not the same as calling:
3188 *|PostThreadMessage(GetCurrentThreadId(), WM_QUIT, exit_code, 0);
3189 * It instead sets a flag in the message queue that signals it to generate
3190 * a WM_QUIT message when there are no other pending sent or posted messages
3191 * in the queue.
3193 void WINAPI PostQuitMessage( INT exit_code )
3195 SERVER_START_REQ( post_quit_message )
3197 req->exit_code = exit_code;
3198 wine_server_call( req );
3200 SERVER_END_REQ;
3204 /***********************************************************************
3205 * PeekMessageW (USER32.@)
3207 BOOL WINAPI PeekMessageW( MSG *msg_out, HWND hwnd, UINT first, UINT last, UINT flags )
3209 MSG msg;
3211 USER_CheckNotLock();
3213 /* check for graphics events */
3214 USER_Driver->pMsgWaitForMultipleObjectsEx( 0, NULL, 0, QS_ALLINPUT, 0 );
3216 if (!peek_message( &msg, hwnd, first, last, flags, 0 ))
3218 if (!(flags & PM_NOYIELD)) wow_handlers.wait_message( 0, NULL, 0, 0, 0 );
3219 return FALSE;
3222 /* copy back our internal safe copy of message data to msg_out.
3223 * msg_out is a variable from the *program*, so it can't be used
3224 * internally as it can get "corrupted" by our use of SendMessage()
3225 * (back to the program) inside the message handling itself. */
3226 if (!msg_out)
3228 SetLastError( ERROR_NOACCESS );
3229 return FALSE;
3231 *msg_out = msg;
3232 return TRUE;
3236 /***********************************************************************
3237 * PeekMessageA (USER32.@)
3239 BOOL WINAPI PeekMessageA( MSG *msg, HWND hwnd, UINT first, UINT last, UINT flags )
3241 if (get_pending_wmchar( msg, first, last, (flags & PM_REMOVE) )) return TRUE;
3242 if (!PeekMessageW( msg, hwnd, first, last, flags )) return FALSE;
3243 map_wparam_WtoA( msg, (flags & PM_REMOVE) );
3244 return TRUE;
3248 /***********************************************************************
3249 * GetMessageW (USER32.@)
3251 BOOL WINAPI GetMessageW( MSG *msg, HWND hwnd, UINT first, UINT last )
3253 HANDLE server_queue = get_server_queue_handle();
3254 unsigned int mask = QS_POSTMESSAGE | QS_SENDMESSAGE; /* Always selected */
3256 USER_CheckNotLock();
3258 /* check for graphics events */
3259 USER_Driver->pMsgWaitForMultipleObjectsEx( 0, NULL, 0, QS_ALLINPUT, 0 );
3261 if (first || last)
3263 if ((first <= WM_KEYLAST) && (last >= WM_KEYFIRST)) mask |= QS_KEY;
3264 if ( ((first <= WM_MOUSELAST) && (last >= WM_MOUSEFIRST)) ||
3265 ((first <= WM_NCMOUSELAST) && (last >= WM_NCMOUSEFIRST)) ) mask |= QS_MOUSE;
3266 if ((first <= WM_TIMER) && (last >= WM_TIMER)) mask |= QS_TIMER;
3267 if ((first <= WM_SYSTIMER) && (last >= WM_SYSTIMER)) mask |= QS_TIMER;
3268 if ((first <= WM_PAINT) && (last >= WM_PAINT)) mask |= QS_PAINT;
3270 else mask = QS_ALLINPUT;
3272 while (!peek_message( msg, hwnd, first, last, PM_REMOVE | (mask << 16), mask ))
3274 wow_handlers.wait_message( 1, &server_queue, INFINITE, mask, 0 );
3277 return (msg->message != WM_QUIT);
3281 /***********************************************************************
3282 * GetMessageA (USER32.@)
3284 BOOL WINAPI GetMessageA( MSG *msg, HWND hwnd, UINT first, UINT last )
3286 if (get_pending_wmchar( msg, first, last, TRUE )) return TRUE;
3287 GetMessageW( msg, hwnd, first, last );
3288 map_wparam_WtoA( msg, TRUE );
3289 return (msg->message != WM_QUIT);
3293 /***********************************************************************
3294 * IsDialogMessageA (USER32.@)
3295 * IsDialogMessage (USER32.@)
3297 BOOL WINAPI IsDialogMessageA( HWND hwndDlg, LPMSG pmsg )
3299 MSG msg = *pmsg;
3300 map_wparam_AtoW( msg.message, &msg.wParam, WMCHAR_MAP_NOMAPPING );
3301 return IsDialogMessageW( hwndDlg, &msg );
3305 /***********************************************************************
3306 * TranslateMessage (USER32.@)
3308 * Implementation of TranslateMessage.
3310 * TranslateMessage translates virtual-key messages into character-messages,
3311 * as follows :
3312 * WM_KEYDOWN/WM_KEYUP combinations produce a WM_CHAR or WM_DEADCHAR message.
3313 * ditto replacing WM_* with WM_SYS*
3314 * This produces WM_CHAR messages only for keys mapped to ASCII characters
3315 * by the keyboard driver.
3317 * If the message is WM_KEYDOWN, WM_KEYUP, WM_SYSKEYDOWN, or WM_SYSKEYUP, the
3318 * return value is nonzero, regardless of the translation.
3321 BOOL WINAPI TranslateMessage( const MSG *msg )
3323 UINT message;
3324 WCHAR wp[2];
3325 BYTE state[256];
3327 if (msg->message < WM_KEYFIRST || msg->message > WM_KEYLAST) return FALSE;
3328 if (msg->message != WM_KEYDOWN && msg->message != WM_SYSKEYDOWN) return TRUE;
3330 TRACE_(key)("Translating key %s (%04lX), scancode %04x\n",
3331 SPY_GetVKeyName(msg->wParam), msg->wParam, HIWORD(msg->lParam));
3333 switch (msg->wParam)
3335 case VK_PACKET:
3336 message = (msg->message == WM_KEYDOWN) ? WM_CHAR : WM_SYSCHAR;
3337 TRACE_(key)("PostMessageW(%p,%s,%04x,%08x)\n",
3338 msg->hwnd, SPY_GetMsgName(message, msg->hwnd), HIWORD(msg->lParam), LOWORD(msg->lParam));
3339 PostMessageW( msg->hwnd, message, HIWORD(msg->lParam), LOWORD(msg->lParam));
3340 return TRUE;
3342 case VK_PROCESSKEY:
3343 return ImmTranslateMessage(msg->hwnd, msg->message, msg->wParam, msg->lParam);
3346 GetKeyboardState( state );
3347 /* FIXME : should handle ToUnicode yielding 2 */
3348 switch (ToUnicode(msg->wParam, HIWORD(msg->lParam), state, wp, 2, 0))
3350 case 1:
3351 message = (msg->message == WM_KEYDOWN) ? WM_CHAR : WM_SYSCHAR;
3352 TRACE_(key)("1 -> PostMessageW(%p,%s,%04x,%08lx)\n",
3353 msg->hwnd, SPY_GetMsgName(message, msg->hwnd), wp[0], msg->lParam);
3354 PostMessageW( msg->hwnd, message, wp[0], msg->lParam );
3355 break;
3357 case -1:
3358 message = (msg->message == WM_KEYDOWN) ? WM_DEADCHAR : WM_SYSDEADCHAR;
3359 TRACE_(key)("-1 -> PostMessageW(%p,%s,%04x,%08lx)\n",
3360 msg->hwnd, SPY_GetMsgName(message, msg->hwnd), wp[0], msg->lParam);
3361 PostMessageW( msg->hwnd, message, wp[0], msg->lParam );
3362 break;
3364 return TRUE;
3368 /***********************************************************************
3369 * DispatchMessageA (USER32.@)
3371 * See DispatchMessageW.
3373 LRESULT WINAPI DECLSPEC_HOTPATCH DispatchMessageA( const MSG* msg )
3375 LRESULT retval;
3377 /* Process timer messages */
3378 if ((msg->message == WM_TIMER) || (msg->message == WM_SYSTIMER))
3380 if (msg->lParam)
3382 __TRY
3384 retval = CallWindowProcA( (WNDPROC)msg->lParam, msg->hwnd,
3385 msg->message, msg->wParam, GetTickCount() );
3387 __EXCEPT_PAGE_FAULT
3389 retval = 0;
3391 __ENDTRY
3392 return retval;
3395 if (!msg->hwnd) return 0;
3397 SPY_EnterMessage( SPY_DISPATCHMESSAGE, msg->hwnd, msg->message,
3398 msg->wParam, msg->lParam );
3400 if (!WINPROC_call_window( msg->hwnd, msg->message, msg->wParam, msg->lParam,
3401 &retval, FALSE, WMCHAR_MAP_DISPATCHMESSAGE ))
3403 if (!IsWindow( msg->hwnd )) SetLastError( ERROR_INVALID_WINDOW_HANDLE );
3404 else SetLastError( ERROR_MESSAGE_SYNC_ONLY );
3405 retval = 0;
3408 SPY_ExitMessage( SPY_RESULT_OK, msg->hwnd, msg->message, retval,
3409 msg->wParam, msg->lParam );
3411 if (msg->message == WM_PAINT)
3413 /* send a WM_NCPAINT and WM_ERASEBKGND if the non-client area is still invalid */
3414 HRGN hrgn = CreateRectRgn( 0, 0, 0, 0 );
3415 GetUpdateRgn( msg->hwnd, hrgn, TRUE );
3416 DeleteObject( hrgn );
3418 return retval;
3422 /***********************************************************************
3423 * DispatchMessageW (USER32.@) Process a message
3425 * Process the message specified in the structure *_msg_.
3427 * If the lpMsg parameter points to a WM_TIMER message and the
3428 * parameter of the WM_TIMER message is not NULL, the lParam parameter
3429 * points to the function that is called instead of the window
3430 * procedure. The function stored in lParam (timer callback) is protected
3431 * from causing page-faults.
3433 * The message must be valid.
3435 * RETURNS
3437 * DispatchMessage() returns the result of the window procedure invoked.
3439 * CONFORMANCE
3441 * ECMA-234, Win32
3444 LRESULT WINAPI DECLSPEC_HOTPATCH DispatchMessageW( const MSG* msg )
3446 LRESULT retval;
3448 /* Process timer messages */
3449 if ((msg->message == WM_TIMER) || (msg->message == WM_SYSTIMER))
3451 if (msg->lParam)
3453 __TRY
3455 retval = CallWindowProcW( (WNDPROC)msg->lParam, msg->hwnd,
3456 msg->message, msg->wParam, GetTickCount() );
3458 __EXCEPT_PAGE_FAULT
3460 retval = 0;
3462 __ENDTRY
3463 return retval;
3466 if (!msg->hwnd) return 0;
3468 SPY_EnterMessage( SPY_DISPATCHMESSAGE, msg->hwnd, msg->message,
3469 msg->wParam, msg->lParam );
3471 if (!WINPROC_call_window( msg->hwnd, msg->message, msg->wParam, msg->lParam,
3472 &retval, TRUE, WMCHAR_MAP_DISPATCHMESSAGE ))
3474 if (!IsWindow( msg->hwnd )) SetLastError( ERROR_INVALID_WINDOW_HANDLE );
3475 else SetLastError( ERROR_MESSAGE_SYNC_ONLY );
3476 retval = 0;
3479 SPY_ExitMessage( SPY_RESULT_OK, msg->hwnd, msg->message, retval,
3480 msg->wParam, msg->lParam );
3482 if (msg->message == WM_PAINT)
3484 /* send a WM_NCPAINT and WM_ERASEBKGND if the non-client area is still invalid */
3485 HRGN hrgn = CreateRectRgn( 0, 0, 0, 0 );
3486 GetUpdateRgn( msg->hwnd, hrgn, TRUE );
3487 DeleteObject( hrgn );
3489 return retval;
3493 /***********************************************************************
3494 * GetMessagePos (USER.119)
3495 * GetMessagePos (USER32.@)
3497 * The GetMessagePos() function returns a long value representing a
3498 * cursor position, in screen coordinates, when the last message
3499 * retrieved by the GetMessage() function occurs. The x-coordinate is
3500 * in the low-order word of the return value, the y-coordinate is in
3501 * the high-order word. The application can use the MAKEPOINT()
3502 * macro to obtain a POINT structure from the return value.
3504 * For the current cursor position, use GetCursorPos().
3506 * RETURNS
3508 * Cursor position of last message on success, zero on failure.
3510 * CONFORMANCE
3512 * ECMA-234, Win32
3515 DWORD WINAPI GetMessagePos(void)
3517 return get_user_thread_info()->GetMessagePosVal;
3521 /***********************************************************************
3522 * GetMessageTime (USER.120)
3523 * GetMessageTime (USER32.@)
3525 * GetMessageTime() returns the message time for the last message
3526 * retrieved by the function. The time is measured in milliseconds with
3527 * the same offset as GetTickCount().
3529 * Since the tick count wraps, this is only useful for moderately short
3530 * relative time comparisons.
3532 * RETURNS
3534 * Time of last message on success, zero on failure.
3536 LONG WINAPI GetMessageTime(void)
3538 return get_user_thread_info()->GetMessageTimeVal;
3542 /***********************************************************************
3543 * GetMessageExtraInfo (USER.288)
3544 * GetMessageExtraInfo (USER32.@)
3546 LPARAM WINAPI GetMessageExtraInfo(void)
3548 return get_user_thread_info()->GetMessageExtraInfoVal;
3552 /***********************************************************************
3553 * SetMessageExtraInfo (USER32.@)
3555 LPARAM WINAPI SetMessageExtraInfo(LPARAM lParam)
3557 struct user_thread_info *thread_info = get_user_thread_info();
3558 LONG old_value = thread_info->GetMessageExtraInfoVal;
3559 thread_info->GetMessageExtraInfoVal = lParam;
3560 return old_value;
3564 /***********************************************************************
3565 * WaitMessage (USER.112) Suspend thread pending messages
3566 * WaitMessage (USER32.@) Suspend thread pending messages
3568 * WaitMessage() suspends a thread until events appear in the thread's
3569 * queue.
3571 BOOL WINAPI WaitMessage(void)
3573 return (MsgWaitForMultipleObjectsEx( 0, NULL, INFINITE, QS_ALLINPUT, 0 ) != WAIT_FAILED);
3577 /***********************************************************************
3578 * MsgWaitForMultipleObjectsEx (USER32.@)
3580 DWORD WINAPI MsgWaitForMultipleObjectsEx( DWORD count, CONST HANDLE *pHandles,
3581 DWORD timeout, DWORD mask, DWORD flags )
3583 HANDLE handles[MAXIMUM_WAIT_OBJECTS];
3584 DWORD i;
3586 if (count > MAXIMUM_WAIT_OBJECTS-1)
3588 SetLastError( ERROR_INVALID_PARAMETER );
3589 return WAIT_FAILED;
3592 /* set the queue mask */
3593 SERVER_START_REQ( set_queue_mask )
3595 req->wake_mask = (flags & MWMO_INPUTAVAILABLE) ? mask : 0;
3596 req->changed_mask = mask;
3597 req->skip_wait = 0;
3598 wine_server_call( req );
3600 SERVER_END_REQ;
3602 /* add the queue to the handle list */
3603 for (i = 0; i < count; i++) handles[i] = pHandles[i];
3604 handles[count] = get_server_queue_handle();
3606 return wow_handlers.wait_message( count+1, handles, timeout, mask, flags );
3610 /***********************************************************************
3611 * MsgWaitForMultipleObjects (USER32.@)
3613 DWORD WINAPI MsgWaitForMultipleObjects( DWORD count, CONST HANDLE *handles,
3614 BOOL wait_all, DWORD timeout, DWORD mask )
3616 return MsgWaitForMultipleObjectsEx( count, handles, timeout, mask,
3617 wait_all ? MWMO_WAITALL : 0 );
3621 /***********************************************************************
3622 * WaitForInputIdle (USER32.@)
3624 DWORD WINAPI WaitForInputIdle( HANDLE hProcess, DWORD dwTimeOut )
3626 DWORD start_time, elapsed, ret;
3627 HANDLE handles[2];
3629 handles[0] = hProcess;
3630 SERVER_START_REQ( get_process_idle_event )
3632 req->handle = wine_server_obj_handle( hProcess );
3633 wine_server_call_err( req );
3634 handles[1] = wine_server_ptr_handle( reply->event );
3636 SERVER_END_REQ;
3637 if (!handles[1]) return WAIT_FAILED; /* no event to wait on */
3639 start_time = GetTickCount();
3640 elapsed = 0;
3642 TRACE("waiting for %p\n", handles[1] );
3645 ret = MsgWaitForMultipleObjects ( 2, handles, FALSE, dwTimeOut - elapsed, QS_SENDMESSAGE );
3646 switch (ret)
3648 case WAIT_OBJECT_0:
3649 return 0;
3650 case WAIT_OBJECT_0+2:
3651 process_sent_messages();
3652 break;
3653 case WAIT_TIMEOUT:
3654 case WAIT_FAILED:
3655 TRACE("timeout or error\n");
3656 return ret;
3657 default:
3658 TRACE("finished\n");
3659 return 0;
3661 if (dwTimeOut != INFINITE)
3663 elapsed = GetTickCount() - start_time;
3664 if (elapsed > dwTimeOut)
3665 break;
3668 while (1);
3670 return WAIT_TIMEOUT;
3674 /***********************************************************************
3675 * RegisterWindowMessageA (USER32.@)
3676 * RegisterWindowMessage (USER.118)
3678 UINT WINAPI RegisterWindowMessageA( LPCSTR str )
3680 UINT ret = GlobalAddAtomA(str);
3681 TRACE("%s, ret=%x\n", str, ret);
3682 return ret;
3686 /***********************************************************************
3687 * RegisterWindowMessageW (USER32.@)
3689 UINT WINAPI RegisterWindowMessageW( LPCWSTR str )
3691 UINT ret = GlobalAddAtomW(str);
3692 TRACE("%s ret=%x\n", debugstr_w(str), ret);
3693 return ret;
3696 typedef struct BroadcastParm
3698 DWORD flags;
3699 LPDWORD recipients;
3700 UINT msg;
3701 WPARAM wp;
3702 LPARAM lp;
3703 DWORD success;
3704 HWINSTA winsta;
3705 } BroadcastParm;
3707 static BOOL CALLBACK bcast_childwindow( HWND hw, LPARAM lp )
3709 BroadcastParm *parm = (BroadcastParm*)lp;
3710 DWORD_PTR retval = 0;
3711 LRESULT lresult;
3713 if (parm->flags & BSF_IGNORECURRENTTASK && WIN_IsCurrentProcess(hw))
3715 TRACE("Not telling myself %p\n", hw);
3716 return TRUE;
3719 /* I don't know 100% for sure if this is what Windows does, but it fits the tests */
3720 if (parm->flags & BSF_QUERY)
3722 TRACE("Telling window %p using SendMessageTimeout\n", hw);
3724 /* Not tested for conflicting flags */
3725 if (parm->flags & BSF_FORCEIFHUNG || parm->flags & BSF_NOHANG)
3726 lresult = SendMessageTimeoutW( hw, parm->msg, parm->wp, parm->lp, SMTO_ABORTIFHUNG, 2000, &retval );
3727 else if (parm->flags & BSF_NOTIMEOUTIFNOTHUNG)
3728 lresult = SendMessageTimeoutW( hw, parm->msg, parm->wp, parm->lp, SMTO_NOTIMEOUTIFNOTHUNG, 2000, &retval );
3729 else
3730 lresult = SendMessageTimeoutW( hw, parm->msg, parm->wp, parm->lp, SMTO_NORMAL, 2000, &retval );
3732 if (!lresult && GetLastError() == ERROR_TIMEOUT)
3734 WARN("Timed out!\n");
3735 if (!(parm->flags & BSF_FORCEIFHUNG))
3736 goto fail;
3738 if (retval == BROADCAST_QUERY_DENY)
3739 goto fail;
3741 return TRUE;
3743 fail:
3744 parm->success = 0;
3745 return FALSE;
3747 else if (parm->flags & BSF_POSTMESSAGE)
3749 TRACE("Telling window %p using PostMessage\n", hw);
3750 PostMessageW( hw, parm->msg, parm->wp, parm->lp );
3752 else
3754 TRACE("Telling window %p using SendNotifyMessage\n", hw);
3755 SendNotifyMessageW( hw, parm->msg, parm->wp, parm->lp );
3758 return TRUE;
3761 static BOOL CALLBACK bcast_desktop( LPWSTR desktop, LPARAM lp )
3763 BOOL ret;
3764 HDESK hdesktop;
3765 BroadcastParm *parm = (BroadcastParm*)lp;
3767 TRACE("desktop: %s\n", debugstr_w( desktop ));
3769 hdesktop = open_winstation_desktop( parm->winsta, desktop, 0, FALSE, DESKTOP_ENUMERATE|DESKTOP_WRITEOBJECTS|STANDARD_RIGHTS_WRITE );
3770 if (!hdesktop)
3772 FIXME("Could not open desktop %s\n", debugstr_w(desktop));
3773 return TRUE;
3776 ret = EnumDesktopWindows( hdesktop, bcast_childwindow, lp );
3777 CloseDesktop(hdesktop);
3778 TRACE("-->%d\n", ret);
3779 return parm->success;
3782 static BOOL CALLBACK bcast_winsta( LPWSTR winsta, LPARAM lp )
3784 BOOL ret;
3785 HWINSTA hwinsta = OpenWindowStationW( winsta, FALSE, WINSTA_ENUMDESKTOPS );
3786 TRACE("hwinsta: %p/%s/%08x\n", hwinsta, debugstr_w( winsta ), GetLastError());
3787 if (!hwinsta)
3788 return TRUE;
3789 ((BroadcastParm *)lp)->winsta = hwinsta;
3790 ret = EnumDesktopsW( hwinsta, bcast_desktop, lp );
3791 CloseWindowStation( hwinsta );
3792 TRACE("-->%d\n", ret);
3793 return ret;
3796 /***********************************************************************
3797 * BroadcastSystemMessageA (USER32.@)
3798 * BroadcastSystemMessage (USER32.@)
3800 LONG WINAPI BroadcastSystemMessageA( DWORD flags, LPDWORD recipients, UINT msg, WPARAM wp, LPARAM lp )
3802 return BroadcastSystemMessageExA( flags, recipients, msg, wp, lp, NULL );
3806 /***********************************************************************
3807 * BroadcastSystemMessageW (USER32.@)
3809 LONG WINAPI BroadcastSystemMessageW( DWORD flags, LPDWORD recipients, UINT msg, WPARAM wp, LPARAM lp )
3811 return BroadcastSystemMessageExW( flags, recipients, msg, wp, lp, NULL );
3814 /***********************************************************************
3815 * BroadcastSystemMessageExA (USER32.@)
3817 LONG WINAPI BroadcastSystemMessageExA( DWORD flags, LPDWORD recipients, UINT msg, WPARAM wp, LPARAM lp, PBSMINFO pinfo )
3819 map_wparam_AtoW( msg, &wp, WMCHAR_MAP_NOMAPPING );
3820 return BroadcastSystemMessageExW( flags, recipients, msg, wp, lp, NULL );
3824 /***********************************************************************
3825 * BroadcastSystemMessageExW (USER32.@)
3827 LONG WINAPI BroadcastSystemMessageExW( DWORD flags, LPDWORD recipients, UINT msg, WPARAM wp, LPARAM lp, PBSMINFO pinfo )
3829 BroadcastParm parm;
3830 DWORD recips = BSM_ALLCOMPONENTS;
3831 BOOL ret = TRUE;
3832 static const DWORD all_flags = ( BSF_QUERY | BSF_IGNORECURRENTTASK | BSF_FLUSHDISK | BSF_NOHANG
3833 | BSF_POSTMESSAGE | BSF_FORCEIFHUNG | BSF_NOTIMEOUTIFNOTHUNG
3834 | BSF_ALLOWSFW | BSF_SENDNOTIFYMESSAGE | BSF_RETURNHDESK | BSF_LUID );
3836 TRACE("Flags: %08x, recipients: %p(0x%x), msg: %04x, wparam: %08lx, lparam: %08lx\n", flags, recipients,
3837 (recipients ? *recipients : recips), msg, wp, lp);
3839 if (flags & ~all_flags)
3841 SetLastError(ERROR_INVALID_PARAMETER);
3842 return 0;
3845 if (!recipients)
3846 recipients = &recips;
3848 if ( pinfo && flags & BSF_QUERY )
3849 FIXME("Not returning PBSMINFO information yet\n");
3851 parm.flags = flags;
3852 parm.recipients = recipients;
3853 parm.msg = msg;
3854 parm.wp = wp;
3855 parm.lp = lp;
3856 parm.success = TRUE;
3858 if (*recipients & BSM_ALLDESKTOPS || *recipients == BSM_ALLCOMPONENTS)
3859 ret = EnumWindowStationsW(bcast_winsta, (LONG_PTR)&parm);
3860 else if (*recipients & BSM_APPLICATIONS)
3862 EnumWindows(bcast_childwindow, (LONG_PTR)&parm);
3863 ret = parm.success;
3865 else
3866 FIXME("Recipients %08x not supported!\n", *recipients);
3868 return ret;
3871 /***********************************************************************
3872 * SetMessageQueue (USER32.@)
3874 BOOL WINAPI SetMessageQueue( INT size )
3876 /* now obsolete the message queue will be expanded dynamically as necessary */
3877 return TRUE;
3881 /***********************************************************************
3882 * MessageBeep (USER32.@)
3884 BOOL WINAPI MessageBeep( UINT i )
3886 BOOL active = TRUE;
3887 SystemParametersInfoA( SPI_GETBEEP, 0, &active, FALSE );
3888 if (active) USER_Driver->pBeep();
3889 return TRUE;
3893 /***********************************************************************
3894 * SetTimer (USER32.@)
3896 UINT_PTR WINAPI SetTimer( HWND hwnd, UINT_PTR id, UINT timeout, TIMERPROC proc )
3898 UINT_PTR ret;
3899 WNDPROC winproc = 0;
3901 if (proc) winproc = WINPROC_AllocProc( (WNDPROC)proc, FALSE );
3903 SERVER_START_REQ( set_win_timer )
3905 req->win = wine_server_user_handle( hwnd );
3906 req->msg = WM_TIMER;
3907 req->id = id;
3908 req->rate = max( timeout, SYS_TIMER_RATE );
3909 req->lparam = (ULONG_PTR)winproc;
3910 if (!wine_server_call_err( req ))
3912 ret = reply->id;
3913 if (!ret) ret = TRUE;
3915 else ret = 0;
3917 SERVER_END_REQ;
3919 TRACE("Added %p %lx %p timeout %d\n", hwnd, id, winproc, timeout );
3920 return ret;
3924 /***********************************************************************
3925 * SetSystemTimer (USER32.@)
3927 UINT_PTR WINAPI SetSystemTimer( HWND hwnd, UINT_PTR id, UINT timeout, TIMERPROC proc )
3929 UINT_PTR ret;
3930 WNDPROC winproc = 0;
3932 if (proc) winproc = WINPROC_AllocProc( (WNDPROC)proc, FALSE );
3934 SERVER_START_REQ( set_win_timer )
3936 req->win = wine_server_user_handle( hwnd );
3937 req->msg = WM_SYSTIMER;
3938 req->id = id;
3939 req->rate = max( timeout, SYS_TIMER_RATE );
3940 req->lparam = (ULONG_PTR)winproc;
3941 if (!wine_server_call_err( req ))
3943 ret = reply->id;
3944 if (!ret) ret = TRUE;
3946 else ret = 0;
3948 SERVER_END_REQ;
3950 TRACE("Added %p %lx %p timeout %d\n", hwnd, id, winproc, timeout );
3951 return ret;
3955 /***********************************************************************
3956 * KillTimer (USER32.@)
3958 BOOL WINAPI KillTimer( HWND hwnd, UINT_PTR id )
3960 BOOL ret;
3962 SERVER_START_REQ( kill_win_timer )
3964 req->win = wine_server_user_handle( hwnd );
3965 req->msg = WM_TIMER;
3966 req->id = id;
3967 ret = !wine_server_call_err( req );
3969 SERVER_END_REQ;
3970 return ret;
3974 /***********************************************************************
3975 * KillSystemTimer (USER32.@)
3977 BOOL WINAPI KillSystemTimer( HWND hwnd, UINT_PTR id )
3979 BOOL ret;
3981 SERVER_START_REQ( kill_win_timer )
3983 req->win = wine_server_user_handle( hwnd );
3984 req->msg = WM_SYSTIMER;
3985 req->id = id;
3986 ret = !wine_server_call_err( req );
3988 SERVER_END_REQ;
3989 return ret;
3993 /**********************************************************************
3994 * GetGUIThreadInfo (USER32.@)
3996 BOOL WINAPI GetGUIThreadInfo( DWORD id, GUITHREADINFO *info )
3998 BOOL ret;
4000 SERVER_START_REQ( get_thread_input )
4002 req->tid = id;
4003 if ((ret = !wine_server_call_err( req )))
4005 info->flags = 0;
4006 info->hwndActive = wine_server_ptr_handle( reply->active );
4007 info->hwndFocus = wine_server_ptr_handle( reply->focus );
4008 info->hwndCapture = wine_server_ptr_handle( reply->capture );
4009 info->hwndMenuOwner = wine_server_ptr_handle( reply->menu_owner );
4010 info->hwndMoveSize = wine_server_ptr_handle( reply->move_size );
4011 info->hwndCaret = wine_server_ptr_handle( reply->caret );
4012 info->rcCaret.left = reply->rect.left;
4013 info->rcCaret.top = reply->rect.top;
4014 info->rcCaret.right = reply->rect.right;
4015 info->rcCaret.bottom = reply->rect.bottom;
4016 if (reply->menu_owner) info->flags |= GUI_INMENUMODE;
4017 if (reply->move_size) info->flags |= GUI_INMOVESIZE;
4018 if (reply->caret) info->flags |= GUI_CARETBLINKING;
4021 SERVER_END_REQ;
4022 return ret;
4026 /******************************************************************
4027 * IsHungAppWindow (USER32.@)
4030 BOOL WINAPI IsHungAppWindow( HWND hWnd )
4032 BOOL ret;
4034 SERVER_START_REQ( is_window_hung )
4036 req->win = wine_server_user_handle( hWnd );
4037 ret = !wine_server_call_err( req ) && reply->is_hung;
4039 SERVER_END_REQ;
4040 return ret;
4043 /******************************************************************
4044 * ChangeWindowMessageFilter (USER32.@)
4046 BOOL WINAPI ChangeWindowMessageFilter( UINT message, DWORD flag )
4048 FIXME( "%x %08x\n", message, flag );
4049 return TRUE;