user32: Properly translate keyboard left/right-shift, alt, ctrl keys hardware messages.
[wine/multimedia.git] / dlls / user32 / message.c
blobcc2603f7ac1a9d01f1c88e65302646148b7aece8
1 /*
2 * Window messaging support
4 * Copyright 2001 Alexandre Julliard
6 * This library is free software; you can redistribute it and/or
7 * modify it under the terms of the GNU Lesser General Public
8 * License as published by the Free Software Foundation; either
9 * version 2.1 of the License, or (at your option) any later version.
11 * This library is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 * Lesser General Public License for more details.
16 * You should have received a copy of the GNU Lesser General Public
17 * License along with this library; if not, write to the Free Software
18 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
21 #include "config.h"
22 #include "wine/port.h"
24 #include <assert.h>
25 #include <stdarg.h>
27 #include "ntstatus.h"
28 #define WIN32_NO_STATUS
29 #include "windef.h"
30 #include "winbase.h"
31 #include "wingdi.h"
32 #include "winuser.h"
33 #include "winerror.h"
34 #include "winnls.h"
35 #include "dbt.h"
36 #include "dde.h"
37 #include "wine/unicode.h"
38 #include "wine/server.h"
39 #include "user_private.h"
40 #include "win.h"
41 #include "controls.h"
42 #include "wine/debug.h"
44 WINE_DEFAULT_DEBUG_CHANNEL(msg);
45 WINE_DECLARE_DEBUG_CHANNEL(relay);
46 WINE_DECLARE_DEBUG_CHANNEL(key);
48 #define WM_NCMOUSEFIRST WM_NCMOUSEMOVE
49 #define WM_NCMOUSELAST (WM_NCMOUSEFIRST+(WM_MOUSELAST-WM_MOUSEFIRST))
51 #define MAX_PACK_COUNT 4
52 #define MAX_SENDMSG_RECURSION 64
54 #define SYS_TIMER_RATE 55 /* min. timer rate in ms (actually 54.925)*/
56 /* description of the data fields that need to be packed along with a sent message */
57 struct packed_message
59 int count;
60 const void *data[MAX_PACK_COUNT];
61 size_t size[MAX_PACK_COUNT];
64 /* info about the message currently being received by the current thread */
65 struct received_message_info
67 enum message_type type;
68 MSG msg;
69 UINT flags; /* InSendMessageEx return flags */
72 /* structure to group all parameters for sent messages of the various kinds */
73 struct send_message_info
75 enum message_type type;
76 DWORD dest_tid;
77 HWND hwnd;
78 UINT msg;
79 WPARAM wparam;
80 LPARAM lparam;
81 UINT flags; /* flags for SendMessageTimeout */
82 UINT timeout; /* timeout for SendMessageTimeout */
83 SENDASYNCPROC callback; /* callback function for SendMessageCallback */
84 ULONG_PTR data; /* callback data */
85 enum wm_char_mapping wm_char;
89 /* flag for messages that contain pointers */
90 /* 32 messages per entry, messages 0..31 map to bits 0..31 */
92 #define SET(msg) (1 << ((msg) & 31))
94 static const unsigned int message_pointer_flags[] =
96 /* 0x00 - 0x1f */
97 SET(WM_CREATE) | SET(WM_SETTEXT) | SET(WM_GETTEXT) |
98 SET(WM_WININICHANGE) | SET(WM_DEVMODECHANGE),
99 /* 0x20 - 0x3f */
100 SET(WM_GETMINMAXINFO) | SET(WM_DRAWITEM) | SET(WM_MEASUREITEM) | SET(WM_DELETEITEM) |
101 SET(WM_COMPAREITEM),
102 /* 0x40 - 0x5f */
103 SET(WM_WINDOWPOSCHANGING) | SET(WM_WINDOWPOSCHANGED) | SET(WM_COPYDATA) |
104 SET(WM_NOTIFY) | SET(WM_HELP),
105 /* 0x60 - 0x7f */
106 SET(WM_STYLECHANGING) | SET(WM_STYLECHANGED),
107 /* 0x80 - 0x9f */
108 SET(WM_NCCREATE) | SET(WM_NCCALCSIZE) | SET(WM_GETDLGCODE),
109 /* 0xa0 - 0xbf */
110 SET(EM_GETSEL) | SET(EM_GETRECT) | SET(EM_SETRECT) | SET(EM_SETRECTNP),
111 /* 0xc0 - 0xdf */
112 SET(EM_REPLACESEL) | SET(EM_GETLINE) | SET(EM_SETTABSTOPS),
113 /* 0xe0 - 0xff */
114 SET(SBM_GETRANGE) | SET(SBM_SETSCROLLINFO) | SET(SBM_GETSCROLLINFO) | SET(SBM_GETSCROLLBARINFO),
115 /* 0x100 - 0x11f */
117 /* 0x120 - 0x13f */
119 /* 0x140 - 0x15f */
120 SET(CB_GETEDITSEL) | SET(CB_ADDSTRING) | SET(CB_DIR) | SET(CB_GETLBTEXT) |
121 SET(CB_INSERTSTRING) | SET(CB_FINDSTRING) | SET(CB_SELECTSTRING) |
122 SET(CB_GETDROPPEDCONTROLRECT) | SET(CB_FINDSTRINGEXACT),
123 /* 0x160 - 0x17f */
125 /* 0x180 - 0x19f */
126 SET(LB_ADDSTRING) | SET(LB_INSERTSTRING) | SET(LB_GETTEXT) | SET(LB_SELECTSTRING) |
127 SET(LB_DIR) | SET(LB_FINDSTRING) |
128 SET(LB_GETSELITEMS) | SET(LB_SETTABSTOPS) | SET(LB_ADDFILE) | SET(LB_GETITEMRECT),
129 /* 0x1a0 - 0x1bf */
130 SET(LB_FINDSTRINGEXACT),
131 /* 0x1c0 - 0x1df */
133 /* 0x1e0 - 0x1ff */
135 /* 0x200 - 0x21f */
136 SET(WM_NEXTMENU) | SET(WM_SIZING) | SET(WM_MOVING) | SET(WM_DEVICECHANGE),
137 /* 0x220 - 0x23f */
138 SET(WM_MDICREATE) | SET(WM_MDIGETACTIVE) | SET(WM_DROPOBJECT) |
139 SET(WM_QUERYDROPOBJECT) | SET(WM_DRAGLOOP) | SET(WM_DRAGSELECT) | SET(WM_DRAGMOVE),
140 /* 0x240 - 0x25f */
142 /* 0x260 - 0x27f */
144 /* 0x280 - 0x29f */
146 /* 0x2a0 - 0x2bf */
148 /* 0x2c0 - 0x2df */
150 /* 0x2e0 - 0x2ff */
152 /* 0x300 - 0x31f */
153 SET(WM_ASKCBFORMATNAME)
156 /* flags for messages that contain Unicode strings */
157 static const unsigned int message_unicode_flags[] =
159 /* 0x00 - 0x1f */
160 SET(WM_CREATE) | SET(WM_SETTEXT) | SET(WM_GETTEXT) | SET(WM_GETTEXTLENGTH) |
161 SET(WM_WININICHANGE) | SET(WM_DEVMODECHANGE),
162 /* 0x20 - 0x3f */
163 SET(WM_CHARTOITEM),
164 /* 0x40 - 0x5f */
166 /* 0x60 - 0x7f */
168 /* 0x80 - 0x9f */
169 SET(WM_NCCREATE),
170 /* 0xa0 - 0xbf */
172 /* 0xc0 - 0xdf */
173 SET(EM_REPLACESEL) | SET(EM_GETLINE) | SET(EM_SETPASSWORDCHAR),
174 /* 0xe0 - 0xff */
176 /* 0x100 - 0x11f */
177 SET(WM_CHAR) | SET(WM_DEADCHAR) | SET(WM_SYSCHAR) | SET(WM_SYSDEADCHAR),
178 /* 0x120 - 0x13f */
179 SET(WM_MENUCHAR),
180 /* 0x140 - 0x15f */
181 SET(CB_ADDSTRING) | SET(CB_DIR) | SET(CB_GETLBTEXT) | SET(CB_GETLBTEXTLEN) |
182 SET(CB_INSERTSTRING) | SET(CB_FINDSTRING) | SET(CB_SELECTSTRING) | SET(CB_FINDSTRINGEXACT),
183 /* 0x160 - 0x17f */
185 /* 0x180 - 0x19f */
186 SET(LB_ADDSTRING) | SET(LB_INSERTSTRING) | SET(LB_GETTEXT) | SET(LB_GETTEXTLEN) |
187 SET(LB_SELECTSTRING) | SET(LB_DIR) | SET(LB_FINDSTRING) | SET(LB_ADDFILE),
188 /* 0x1a0 - 0x1bf */
189 SET(LB_FINDSTRINGEXACT),
190 /* 0x1c0 - 0x1df */
192 /* 0x1e0 - 0x1ff */
194 /* 0x200 - 0x21f */
196 /* 0x220 - 0x23f */
197 SET(WM_MDICREATE),
198 /* 0x240 - 0x25f */
200 /* 0x260 - 0x27f */
202 /* 0x280 - 0x29f */
203 SET(WM_IME_CHAR),
204 /* 0x2a0 - 0x2bf */
206 /* 0x2c0 - 0x2df */
208 /* 0x2e0 - 0x2ff */
210 /* 0x300 - 0x31f */
211 SET(WM_PAINTCLIPBOARD) | SET(WM_SIZECLIPBOARD) | SET(WM_ASKCBFORMATNAME)
214 /* check whether a given message type includes pointers */
215 static inline int is_pointer_message( UINT message )
217 if (message >= 8*sizeof(message_pointer_flags)) return FALSE;
218 return (message_pointer_flags[message / 32] & SET(message)) != 0;
221 /* check whether a given message type contains Unicode (or ASCII) chars */
222 static inline int is_unicode_message( UINT message )
224 if (message >= 8*sizeof(message_unicode_flags)) return FALSE;
225 return (message_unicode_flags[message / 32] & SET(message)) != 0;
228 #undef SET
230 /* add a data field to a packed message */
231 static inline void push_data( struct packed_message *data, const void *ptr, size_t size )
233 data->data[data->count] = ptr;
234 data->size[data->count] = size;
235 data->count++;
238 /* add a string to a packed message */
239 static inline void push_string( struct packed_message *data, LPCWSTR str )
241 push_data( data, str, (strlenW(str) + 1) * sizeof(WCHAR) );
244 /* retrieve a pointer to data from a packed message and increment the buffer pointer */
245 static inline void *get_data( void **buffer, size_t size )
247 void *ret = *buffer;
248 *buffer = (char *)*buffer + size;
249 return ret;
252 /* make sure that the buffer contains a valid null-terminated Unicode string */
253 static inline BOOL check_string( LPCWSTR str, size_t size )
255 for (size /= sizeof(WCHAR); size; size--, str++)
256 if (!*str) return TRUE;
257 return FALSE;
260 /* make sure that there is space for 'size' bytes in buffer, growing it if needed */
261 static inline void *get_buffer_space( void **buffer, size_t size )
263 void *ret;
265 if (*buffer)
267 if (!(ret = HeapReAlloc( GetProcessHeap(), 0, *buffer, size )))
268 HeapFree( GetProcessHeap(), 0, *buffer );
270 else ret = HeapAlloc( GetProcessHeap(), 0, size );
272 *buffer = ret;
273 return ret;
276 /* check whether a combobox expects strings or ids in CB_ADDSTRING/CB_INSERTSTRING */
277 static inline BOOL combobox_has_strings( HWND hwnd )
279 DWORD style = GetWindowLongA( hwnd, GWL_STYLE );
280 return (!(style & (CBS_OWNERDRAWFIXED | CBS_OWNERDRAWVARIABLE)) || (style & CBS_HASSTRINGS));
283 /* check whether a listbox expects strings or ids in LB_ADDSTRING/LB_INSERTSTRING */
284 static inline BOOL listbox_has_strings( HWND hwnd )
286 DWORD style = GetWindowLongA( hwnd, GWL_STYLE );
287 return (!(style & (LBS_OWNERDRAWFIXED | LBS_OWNERDRAWVARIABLE)) || (style & LBS_HASSTRINGS));
290 /* check whether message is in the range of keyboard messages */
291 static inline BOOL is_keyboard_message( UINT message )
293 return (message >= WM_KEYFIRST && message <= WM_KEYLAST);
296 /* check whether message is in the range of mouse messages */
297 static inline BOOL is_mouse_message( UINT message )
299 return ((message >= WM_NCMOUSEFIRST && message <= WM_NCMOUSELAST) ||
300 (message >= WM_MOUSEFIRST && message <= WM_MOUSELAST));
303 /* check whether message matches the specified hwnd filter */
304 static inline BOOL check_hwnd_filter( const MSG *msg, HWND hwnd_filter )
306 if (!hwnd_filter || hwnd_filter == GetDesktopWindow()) return TRUE;
307 return (msg->hwnd == hwnd_filter || IsChild( hwnd_filter, msg->hwnd ));
310 /* check for pending WM_CHAR message with DBCS trailing byte */
311 static inline BOOL get_pending_wmchar( MSG *msg, UINT first, UINT last, BOOL remove )
313 struct wm_char_mapping_data *data = get_user_thread_info()->wmchar_data;
315 if (!data || !data->get_msg.message) return FALSE;
316 if ((first || last) && (first > WM_CHAR || last < WM_CHAR)) return FALSE;
317 if (!msg) return FALSE;
318 *msg = data->get_msg;
319 if (remove) data->get_msg.message = 0;
320 return TRUE;
323 /***********************************************************************
324 * broadcast_message_callback
326 * Helper callback for broadcasting messages.
328 static BOOL CALLBACK broadcast_message_callback( HWND hwnd, LPARAM lparam )
330 struct send_message_info *info = (struct send_message_info *)lparam;
331 if (!(GetWindowLongW( hwnd, GWL_STYLE ) & (WS_POPUP|WS_CAPTION))) return TRUE;
332 switch(info->type)
334 case MSG_UNICODE:
335 SendMessageTimeoutW( hwnd, info->msg, info->wparam, info->lparam,
336 info->flags, info->timeout, NULL );
337 break;
338 case MSG_ASCII:
339 SendMessageTimeoutA( hwnd, info->msg, info->wparam, info->lparam,
340 info->flags, info->timeout, NULL );
341 break;
342 case MSG_NOTIFY:
343 SendNotifyMessageW( hwnd, info->msg, info->wparam, info->lparam );
344 break;
345 case MSG_CALLBACK:
346 SendMessageCallbackW( hwnd, info->msg, info->wparam, info->lparam,
347 info->callback, info->data );
348 break;
349 case MSG_POSTED:
350 PostMessageW( hwnd, info->msg, info->wparam, info->lparam );
351 break;
352 default:
353 ERR( "bad type %d\n", info->type );
354 break;
356 return TRUE;
360 /***********************************************************************
361 * map_wparam_AtoW
363 * Convert the wparam of an ASCII message to Unicode.
365 BOOL map_wparam_AtoW( UINT message, WPARAM *wparam, enum wm_char_mapping mapping )
367 char ch[2];
368 WCHAR wch[2];
370 wch[0] = wch[1] = 0;
371 switch(message)
373 case WM_CHAR:
374 /* WM_CHAR is magic: a DBCS char can be sent/posted as two consecutive WM_CHAR
375 * messages, in which case the first char is stored, and the conversion
376 * to Unicode only takes place once the second char is sent/posted.
378 if (mapping != WMCHAR_MAP_NOMAPPING)
380 struct wm_char_mapping_data *data = get_user_thread_info()->wmchar_data;
381 BYTE low = LOBYTE(*wparam);
383 if (HIBYTE(*wparam))
385 ch[0] = low;
386 ch[1] = HIBYTE(*wparam);
387 RtlMultiByteToUnicodeN( wch, sizeof(wch), NULL, ch, 2 );
388 TRACE( "map %02x,%02x -> %04x mapping %u\n", (BYTE)ch[0], (BYTE)ch[1], wch[0], mapping );
389 if (data) data->lead_byte[mapping] = 0;
391 else if (data && data->lead_byte[mapping])
393 ch[0] = data->lead_byte[mapping];
394 ch[1] = low;
395 RtlMultiByteToUnicodeN( wch, sizeof(wch), NULL, ch, 2 );
396 TRACE( "map stored %02x,%02x -> %04x mapping %u\n", (BYTE)ch[0], (BYTE)ch[1], wch[0], mapping );
397 data->lead_byte[mapping] = 0;
399 else if (!IsDBCSLeadByte( low ))
401 ch[0] = low;
402 RtlMultiByteToUnicodeN( wch, sizeof(wch), NULL, ch, 1 );
403 TRACE( "map %02x -> %04x\n", (BYTE)ch[0], wch[0] );
404 if (data) data->lead_byte[mapping] = 0;
406 else /* store it and wait for trail byte */
408 if (!data)
410 if (!(data = HeapAlloc( GetProcessHeap(), HEAP_ZERO_MEMORY, sizeof(*data) )))
411 return FALSE;
412 get_user_thread_info()->wmchar_data = data;
414 TRACE( "storing lead byte %02x mapping %u\n", low, mapping );
415 data->lead_byte[mapping] = low;
416 return FALSE;
418 *wparam = MAKEWPARAM(wch[0], wch[1]);
419 break;
421 /* else fall through */
422 case WM_CHARTOITEM:
423 case EM_SETPASSWORDCHAR:
424 case WM_DEADCHAR:
425 case WM_SYSCHAR:
426 case WM_SYSDEADCHAR:
427 case WM_MENUCHAR:
428 ch[0] = LOBYTE(*wparam);
429 ch[1] = HIBYTE(*wparam);
430 RtlMultiByteToUnicodeN( wch, sizeof(wch), NULL, ch, 2 );
431 *wparam = MAKEWPARAM(wch[0], wch[1]);
432 break;
433 case WM_IME_CHAR:
434 ch[0] = HIBYTE(*wparam);
435 ch[1] = LOBYTE(*wparam);
436 if (ch[0]) RtlMultiByteToUnicodeN( wch, sizeof(wch[0]), NULL, ch, 2 );
437 else RtlMultiByteToUnicodeN( wch, sizeof(wch[0]), NULL, ch + 1, 1 );
438 *wparam = MAKEWPARAM(wch[0], HIWORD(*wparam));
439 break;
441 return TRUE;
445 /***********************************************************************
446 * map_wparam_WtoA
448 * Convert the wparam of a Unicode message to ASCII.
450 static void map_wparam_WtoA( MSG *msg, BOOL remove )
452 BYTE ch[2];
453 WCHAR wch[2];
454 DWORD len;
456 switch(msg->message)
458 case WM_CHAR:
459 if (!HIWORD(msg->wParam))
461 wch[0] = LOWORD(msg->wParam);
462 ch[0] = ch[1] = 0;
463 RtlUnicodeToMultiByteN( (LPSTR)ch, 2, &len, wch, sizeof(wch[0]) );
464 if (len == 2) /* DBCS char */
466 struct wm_char_mapping_data *data = get_user_thread_info()->wmchar_data;
467 if (!data)
469 if (!(data = HeapAlloc( GetProcessHeap(), HEAP_ZERO_MEMORY, sizeof(*data) ))) return;
470 get_user_thread_info()->wmchar_data = data;
472 if (remove)
474 data->get_msg = *msg;
475 data->get_msg.wParam = ch[1];
477 msg->wParam = ch[0];
478 return;
481 /* else fall through */
482 case WM_CHARTOITEM:
483 case EM_SETPASSWORDCHAR:
484 case WM_DEADCHAR:
485 case WM_SYSCHAR:
486 case WM_SYSDEADCHAR:
487 case WM_MENUCHAR:
488 wch[0] = LOWORD(msg->wParam);
489 wch[1] = HIWORD(msg->wParam);
490 ch[0] = ch[1] = 0;
491 RtlUnicodeToMultiByteN( (LPSTR)ch, 2, NULL, wch, sizeof(wch) );
492 msg->wParam = MAKEWPARAM( ch[0] | (ch[1] << 8), 0 );
493 break;
494 case WM_IME_CHAR:
495 wch[0] = LOWORD(msg->wParam);
496 ch[0] = ch[1] = 0;
497 RtlUnicodeToMultiByteN( (LPSTR)ch, 2, &len, wch, sizeof(wch[0]) );
498 if (len == 2)
499 msg->wParam = MAKEWPARAM( (ch[0] << 8) | ch[1], HIWORD(msg->wParam) );
500 else
501 msg->wParam = MAKEWPARAM( ch[0], HIWORD(msg->wParam) );
502 break;
507 /***********************************************************************
508 * pack_message
510 * Pack a message for sending to another process.
511 * Return the size of the data we expect in the message reply.
512 * Set data->count to -1 if there is an error.
514 static size_t pack_message( HWND hwnd, UINT message, WPARAM wparam, LPARAM lparam,
515 struct packed_message *data )
517 data->count = 0;
518 switch(message)
520 case WM_NCCREATE:
521 case WM_CREATE:
523 CREATESTRUCTW *cs = (CREATESTRUCTW *)lparam;
524 push_data( data, cs, sizeof(*cs) );
525 if (HIWORD(cs->lpszName)) push_string( data, cs->lpszName );
526 if (HIWORD(cs->lpszClass)) push_string( data, cs->lpszClass );
527 return sizeof(*cs);
529 case WM_GETTEXT:
530 case WM_ASKCBFORMATNAME:
531 return wparam * sizeof(WCHAR);
532 case WM_WININICHANGE:
533 if (lparam) push_string(data, (LPWSTR)lparam );
534 return 0;
535 case WM_SETTEXT:
536 case WM_DEVMODECHANGE:
537 case CB_DIR:
538 case LB_DIR:
539 case LB_ADDFILE:
540 case EM_REPLACESEL:
541 push_string( data, (LPWSTR)lparam );
542 return 0;
543 case WM_GETMINMAXINFO:
544 push_data( data, (MINMAXINFO *)lparam, sizeof(MINMAXINFO) );
545 return sizeof(MINMAXINFO);
546 case WM_DRAWITEM:
547 push_data( data, (DRAWITEMSTRUCT *)lparam, sizeof(DRAWITEMSTRUCT) );
548 return 0;
549 case WM_MEASUREITEM:
550 push_data( data, (MEASUREITEMSTRUCT *)lparam, sizeof(MEASUREITEMSTRUCT) );
551 return sizeof(MEASUREITEMSTRUCT);
552 case WM_DELETEITEM:
553 push_data( data, (DELETEITEMSTRUCT *)lparam, sizeof(DELETEITEMSTRUCT) );
554 return 0;
555 case WM_COMPAREITEM:
556 push_data( data, (COMPAREITEMSTRUCT *)lparam, sizeof(COMPAREITEMSTRUCT) );
557 return 0;
558 case WM_WINDOWPOSCHANGING:
559 case WM_WINDOWPOSCHANGED:
560 push_data( data, (WINDOWPOS *)lparam, sizeof(WINDOWPOS) );
561 return sizeof(WINDOWPOS);
562 case WM_COPYDATA:
564 COPYDATASTRUCT *cp = (COPYDATASTRUCT *)lparam;
565 push_data( data, cp, sizeof(*cp) );
566 if (cp->lpData) push_data( data, cp->lpData, cp->cbData );
567 return 0;
569 case WM_NOTIFY:
570 /* WM_NOTIFY cannot be sent across processes (MSDN) */
571 data->count = -1;
572 return 0;
573 case WM_HELP:
574 push_data( data, (HELPINFO *)lparam, sizeof(HELPINFO) );
575 return 0;
576 case WM_STYLECHANGING:
577 case WM_STYLECHANGED:
578 push_data( data, (STYLESTRUCT *)lparam, sizeof(STYLESTRUCT) );
579 return 0;
580 case WM_NCCALCSIZE:
581 if (!wparam)
583 push_data( data, (RECT *)lparam, sizeof(RECT) );
584 return sizeof(RECT);
586 else
588 NCCALCSIZE_PARAMS *nc = (NCCALCSIZE_PARAMS *)lparam;
589 push_data( data, nc, sizeof(*nc) );
590 push_data( data, nc->lppos, sizeof(*nc->lppos) );
591 return sizeof(*nc) + sizeof(*nc->lppos);
593 case WM_GETDLGCODE:
594 if (lparam) push_data( data, (MSG *)lparam, sizeof(MSG) );
595 return sizeof(MSG);
596 case SBM_SETSCROLLINFO:
597 push_data( data, (SCROLLINFO *)lparam, sizeof(SCROLLINFO) );
598 return 0;
599 case SBM_GETSCROLLINFO:
600 push_data( data, (SCROLLINFO *)lparam, sizeof(SCROLLINFO) );
601 return sizeof(SCROLLINFO);
602 case SBM_GETSCROLLBARINFO:
604 const SCROLLBARINFO *info = (const SCROLLBARINFO *)lparam;
605 size_t size = min( info->cbSize, sizeof(SCROLLBARINFO) );
606 push_data( data, info, size );
607 return size;
609 case EM_GETSEL:
610 case SBM_GETRANGE:
611 case CB_GETEDITSEL:
613 size_t size = 0;
614 if (wparam) size += sizeof(DWORD);
615 if (lparam) size += sizeof(DWORD);
616 return size;
618 case EM_GETRECT:
619 case LB_GETITEMRECT:
620 case CB_GETDROPPEDCONTROLRECT:
621 return sizeof(RECT);
622 case EM_SETRECT:
623 case EM_SETRECTNP:
624 push_data( data, (RECT *)lparam, sizeof(RECT) );
625 return 0;
626 case EM_GETLINE:
628 WORD *pw = (WORD *)lparam;
629 push_data( data, pw, sizeof(*pw) );
630 return *pw * sizeof(WCHAR);
632 case EM_SETTABSTOPS:
633 case LB_SETTABSTOPS:
634 if (wparam) push_data( data, (UINT *)lparam, sizeof(UINT) * wparam );
635 return 0;
636 case CB_ADDSTRING:
637 case CB_INSERTSTRING:
638 case CB_FINDSTRING:
639 case CB_FINDSTRINGEXACT:
640 case CB_SELECTSTRING:
641 if (combobox_has_strings( hwnd )) push_string( data, (LPWSTR)lparam );
642 return 0;
643 case CB_GETLBTEXT:
644 if (!combobox_has_strings( hwnd )) return sizeof(ULONG_PTR);
645 return (SendMessageW( hwnd, CB_GETLBTEXTLEN, wparam, 0 ) + 1) * sizeof(WCHAR);
646 case LB_ADDSTRING:
647 case LB_INSERTSTRING:
648 case LB_FINDSTRING:
649 case LB_FINDSTRINGEXACT:
650 case LB_SELECTSTRING:
651 if (listbox_has_strings( hwnd )) push_string( data, (LPWSTR)lparam );
652 return 0;
653 case LB_GETTEXT:
654 if (!listbox_has_strings( hwnd )) return sizeof(ULONG_PTR);
655 return (SendMessageW( hwnd, LB_GETTEXTLEN, wparam, 0 ) + 1) * sizeof(WCHAR);
656 case LB_GETSELITEMS:
657 return wparam * sizeof(UINT);
658 case WM_NEXTMENU:
659 push_data( data, (MDINEXTMENU *)lparam, sizeof(MDINEXTMENU) );
660 return sizeof(MDINEXTMENU);
661 case WM_SIZING:
662 case WM_MOVING:
663 push_data( data, (RECT *)lparam, sizeof(RECT) );
664 return sizeof(RECT);
665 case WM_MDICREATE:
667 MDICREATESTRUCTW *cs = (MDICREATESTRUCTW *)lparam;
668 push_data( data, cs, sizeof(*cs) );
669 if (HIWORD(cs->szTitle)) push_string( data, cs->szTitle );
670 if (HIWORD(cs->szClass)) push_string( data, cs->szClass );
671 return sizeof(*cs);
673 case WM_MDIGETACTIVE:
674 if (lparam) return sizeof(BOOL);
675 return 0;
676 case WM_DEVICECHANGE:
678 DEV_BROADCAST_HDR *header = (DEV_BROADCAST_HDR *)lparam;
679 push_data( data, header, header->dbch_size );
680 return 0;
682 case WM_WINE_SETWINDOWPOS:
683 push_data( data, (WINDOWPOS *)lparam, sizeof(WINDOWPOS) );
684 return 0;
685 case WM_WINE_KEYBOARD_LL_HOOK:
687 struct hook_extra_info *h_extra = (struct hook_extra_info *)lparam;
688 push_data( data, h_extra, sizeof(*h_extra) );
689 push_data( data, (LPVOID)h_extra->lparam, sizeof(KBDLLHOOKSTRUCT) );
690 return 0;
692 case WM_WINE_MOUSE_LL_HOOK:
694 struct hook_extra_info *h_extra = (struct hook_extra_info *)lparam;
695 push_data( data, h_extra, sizeof(*h_extra) );
696 push_data( data, (LPVOID)h_extra->lparam, sizeof(MSLLHOOKSTRUCT) );
697 return 0;
699 case WM_NCPAINT:
700 if (wparam <= 1) return 0;
701 FIXME( "WM_NCPAINT hdc packing not supported yet\n" );
702 data->count = -1;
703 return 0;
704 case WM_PAINT:
705 if (!wparam) return 0;
706 /* fall through */
708 /* these contain an HFONT */
709 case WM_SETFONT:
710 case WM_GETFONT:
711 /* these contain an HDC */
712 case WM_ERASEBKGND:
713 case WM_ICONERASEBKGND:
714 case WM_CTLCOLORMSGBOX:
715 case WM_CTLCOLOREDIT:
716 case WM_CTLCOLORLISTBOX:
717 case WM_CTLCOLORBTN:
718 case WM_CTLCOLORDLG:
719 case WM_CTLCOLORSCROLLBAR:
720 case WM_CTLCOLORSTATIC:
721 case WM_PRINT:
722 case WM_PRINTCLIENT:
723 /* these contain an HGLOBAL */
724 case WM_PAINTCLIPBOARD:
725 case WM_SIZECLIPBOARD:
726 /* these contain HICON */
727 case WM_GETICON:
728 case WM_SETICON:
729 case WM_QUERYDRAGICON:
730 case WM_QUERYPARKICON:
731 /* these contain pointers */
732 case WM_DROPOBJECT:
733 case WM_QUERYDROPOBJECT:
734 case WM_DRAGLOOP:
735 case WM_DRAGSELECT:
736 case WM_DRAGMOVE:
737 FIXME( "msg %x (%s) not supported yet\n", message, SPY_GetMsgName(message, hwnd) );
738 data->count = -1;
739 return 0;
741 return 0;
745 /***********************************************************************
746 * unpack_message
748 * Unpack a message received from another process.
750 static BOOL unpack_message( HWND hwnd, UINT message, WPARAM *wparam, LPARAM *lparam,
751 void **buffer, size_t size )
753 size_t minsize = 0;
755 switch(message)
757 case WM_NCCREATE:
758 case WM_CREATE:
760 CREATESTRUCTW *cs = *buffer;
761 WCHAR *str = (WCHAR *)(cs + 1);
762 if (size < sizeof(*cs)) return FALSE;
763 size -= sizeof(*cs);
764 if (HIWORD(cs->lpszName))
766 if (!check_string( str, size )) return FALSE;
767 cs->lpszName = str;
768 size -= (strlenW(str) + 1) * sizeof(WCHAR);
769 str += strlenW(str) + 1;
771 if (HIWORD(cs->lpszClass))
773 if (!check_string( str, size )) return FALSE;
774 cs->lpszClass = str;
776 break;
778 case WM_GETTEXT:
779 case WM_ASKCBFORMATNAME:
780 if (!get_buffer_space( buffer, (*wparam * sizeof(WCHAR)) )) return FALSE;
781 break;
782 case WM_WININICHANGE:
783 if (!*lparam) return TRUE;
784 /* fall through */
785 case WM_SETTEXT:
786 case WM_DEVMODECHANGE:
787 case CB_DIR:
788 case LB_DIR:
789 case LB_ADDFILE:
790 case EM_REPLACESEL:
791 if (!check_string( *buffer, size )) return FALSE;
792 break;
793 case WM_GETMINMAXINFO:
794 minsize = sizeof(MINMAXINFO);
795 break;
796 case WM_DRAWITEM:
797 minsize = sizeof(DRAWITEMSTRUCT);
798 break;
799 case WM_MEASUREITEM:
800 minsize = sizeof(MEASUREITEMSTRUCT);
801 break;
802 case WM_DELETEITEM:
803 minsize = sizeof(DELETEITEMSTRUCT);
804 break;
805 case WM_COMPAREITEM:
806 minsize = sizeof(COMPAREITEMSTRUCT);
807 break;
808 case WM_WINDOWPOSCHANGING:
809 case WM_WINDOWPOSCHANGED:
810 case WM_WINE_SETWINDOWPOS:
811 minsize = sizeof(WINDOWPOS);
812 break;
813 case WM_COPYDATA:
815 COPYDATASTRUCT *cp = *buffer;
816 if (size < sizeof(*cp)) return FALSE;
817 if (cp->lpData)
819 minsize = sizeof(*cp) + cp->cbData;
820 cp->lpData = cp + 1;
822 break;
824 case WM_NOTIFY:
825 /* WM_NOTIFY cannot be sent across processes (MSDN) */
826 return FALSE;
827 case WM_HELP:
828 minsize = sizeof(HELPINFO);
829 break;
830 case WM_STYLECHANGING:
831 case WM_STYLECHANGED:
832 minsize = sizeof(STYLESTRUCT);
833 break;
834 case WM_NCCALCSIZE:
835 if (!*wparam) minsize = sizeof(RECT);
836 else
838 NCCALCSIZE_PARAMS *nc = *buffer;
839 if (size < sizeof(*nc) + sizeof(*nc->lppos)) return FALSE;
840 nc->lppos = (WINDOWPOS *)(nc + 1);
842 break;
843 case WM_GETDLGCODE:
844 if (!*lparam) return TRUE;
845 minsize = sizeof(MSG);
846 break;
847 case SBM_SETSCROLLINFO:
848 minsize = sizeof(SCROLLINFO);
849 break;
850 case SBM_GETSCROLLINFO:
851 if (!get_buffer_space( buffer, sizeof(SCROLLINFO ))) return FALSE;
852 break;
853 case SBM_GETSCROLLBARINFO:
854 if (!get_buffer_space( buffer, sizeof(SCROLLBARINFO ))) return FALSE;
855 break;
856 case EM_GETSEL:
857 case SBM_GETRANGE:
858 case CB_GETEDITSEL:
859 if (*wparam || *lparam)
861 if (!get_buffer_space( buffer, 2*sizeof(DWORD) )) return FALSE;
862 if (*wparam) *wparam = (WPARAM)*buffer;
863 if (*lparam) *lparam = (LPARAM)((DWORD *)*buffer + 1);
865 return TRUE;
866 case EM_GETRECT:
867 case LB_GETITEMRECT:
868 case CB_GETDROPPEDCONTROLRECT:
869 if (!get_buffer_space( buffer, sizeof(RECT) )) return FALSE;
870 break;
871 case EM_SETRECT:
872 case EM_SETRECTNP:
873 minsize = sizeof(RECT);
874 break;
875 case EM_GETLINE:
877 WORD len;
878 if (size < sizeof(WORD)) return FALSE;
879 len = *(WORD *)*buffer;
880 if (!get_buffer_space( buffer, (len + 1) * sizeof(WCHAR) )) return FALSE;
881 *lparam = (LPARAM)*buffer + sizeof(WORD); /* don't erase WORD at start of buffer */
882 return TRUE;
884 case EM_SETTABSTOPS:
885 case LB_SETTABSTOPS:
886 if (!*wparam) return TRUE;
887 minsize = *wparam * sizeof(UINT);
888 break;
889 case CB_ADDSTRING:
890 case CB_INSERTSTRING:
891 case CB_FINDSTRING:
892 case CB_FINDSTRINGEXACT:
893 case CB_SELECTSTRING:
894 case LB_ADDSTRING:
895 case LB_INSERTSTRING:
896 case LB_FINDSTRING:
897 case LB_FINDSTRINGEXACT:
898 case LB_SELECTSTRING:
899 if (!*buffer) return TRUE;
900 if (!check_string( *buffer, size )) return FALSE;
901 break;
902 case CB_GETLBTEXT:
904 size = sizeof(ULONG_PTR);
905 if (combobox_has_strings( hwnd ))
906 size = (SendMessageW( hwnd, CB_GETLBTEXTLEN, *wparam, 0 ) + 1) * sizeof(WCHAR);
907 if (!get_buffer_space( buffer, size )) return FALSE;
908 break;
910 case LB_GETTEXT:
912 size = sizeof(ULONG_PTR);
913 if (listbox_has_strings( hwnd ))
914 size = (SendMessageW( hwnd, LB_GETTEXTLEN, *wparam, 0 ) + 1) * sizeof(WCHAR);
915 if (!get_buffer_space( buffer, size )) return FALSE;
916 break;
918 case LB_GETSELITEMS:
919 if (!get_buffer_space( buffer, *wparam * sizeof(UINT) )) return FALSE;
920 break;
921 case WM_NEXTMENU:
922 minsize = sizeof(MDINEXTMENU);
923 if (!get_buffer_space( buffer, sizeof(MDINEXTMENU) )) return FALSE;
924 break;
925 case WM_SIZING:
926 case WM_MOVING:
927 minsize = sizeof(RECT);
928 if (!get_buffer_space( buffer, sizeof(RECT) )) return FALSE;
929 break;
930 case WM_MDICREATE:
932 MDICREATESTRUCTW *cs = *buffer;
933 WCHAR *str = (WCHAR *)(cs + 1);
934 if (size < sizeof(*cs)) return FALSE;
935 size -= sizeof(*cs);
936 if (HIWORD(cs->szTitle))
938 if (!check_string( str, size )) return FALSE;
939 cs->szTitle = str;
940 size -= (strlenW(str) + 1) * sizeof(WCHAR);
941 str += strlenW(str) + 1;
943 if (HIWORD(cs->szClass))
945 if (!check_string( str, size )) return FALSE;
946 cs->szClass = str;
948 break;
950 case WM_MDIGETACTIVE:
951 if (!*lparam) return TRUE;
952 if (!get_buffer_space( buffer, sizeof(BOOL) )) return FALSE;
953 break;
954 case WM_DEVICECHANGE:
955 minsize = sizeof(DEV_BROADCAST_HDR);
956 break;
957 case WM_WINE_KEYBOARD_LL_HOOK:
958 case WM_WINE_MOUSE_LL_HOOK:
960 struct hook_extra_info *h_extra = (struct hook_extra_info *)*buffer;
962 minsize = sizeof(struct hook_extra_info) +
963 (message == WM_WINE_KEYBOARD_LL_HOOK ? sizeof(KBDLLHOOKSTRUCT)
964 : sizeof(MSLLHOOKSTRUCT));
965 if (size < minsize) return FALSE;
966 h_extra->lparam = (LPARAM)(h_extra + 1);
967 break;
969 case WM_NCPAINT:
970 if (*wparam <= 1) return TRUE;
971 FIXME( "WM_NCPAINT hdc unpacking not supported\n" );
972 return FALSE;
973 case WM_PAINT:
974 if (!*wparam) return TRUE;
975 /* fall through */
977 /* these contain an HFONT */
978 case WM_SETFONT:
979 case WM_GETFONT:
980 /* these contain an HDC */
981 case WM_ERASEBKGND:
982 case WM_ICONERASEBKGND:
983 case WM_CTLCOLORMSGBOX:
984 case WM_CTLCOLOREDIT:
985 case WM_CTLCOLORLISTBOX:
986 case WM_CTLCOLORBTN:
987 case WM_CTLCOLORDLG:
988 case WM_CTLCOLORSCROLLBAR:
989 case WM_CTLCOLORSTATIC:
990 case WM_PRINT:
991 case WM_PRINTCLIENT:
992 /* these contain an HGLOBAL */
993 case WM_PAINTCLIPBOARD:
994 case WM_SIZECLIPBOARD:
995 /* these contain HICON */
996 case WM_GETICON:
997 case WM_SETICON:
998 case WM_QUERYDRAGICON:
999 case WM_QUERYPARKICON:
1000 /* these contain pointers */
1001 case WM_DROPOBJECT:
1002 case WM_QUERYDROPOBJECT:
1003 case WM_DRAGLOOP:
1004 case WM_DRAGSELECT:
1005 case WM_DRAGMOVE:
1006 FIXME( "msg %x (%s) not supported yet\n", message, SPY_GetMsgName(message, hwnd) );
1007 return FALSE;
1009 default:
1010 return TRUE; /* message doesn't need any unpacking */
1013 /* default exit for most messages: check minsize and store buffer in lparam */
1014 if (size < minsize) return FALSE;
1015 *lparam = (LPARAM)*buffer;
1016 return TRUE;
1020 /***********************************************************************
1021 * pack_reply
1023 * Pack a reply to a message for sending to another process.
1025 static void pack_reply( HWND hwnd, UINT message, WPARAM wparam, LPARAM lparam,
1026 LRESULT res, struct packed_message *data )
1028 data->count = 0;
1029 switch(message)
1031 case WM_NCCREATE:
1032 case WM_CREATE:
1033 push_data( data, (CREATESTRUCTW *)lparam, sizeof(CREATESTRUCTW) );
1034 break;
1035 case WM_GETTEXT:
1036 case CB_GETLBTEXT:
1037 case LB_GETTEXT:
1038 push_data( data, (WCHAR *)lparam, (res + 1) * sizeof(WCHAR) );
1039 break;
1040 case WM_GETMINMAXINFO:
1041 push_data( data, (MINMAXINFO *)lparam, sizeof(MINMAXINFO) );
1042 break;
1043 case WM_MEASUREITEM:
1044 push_data( data, (MEASUREITEMSTRUCT *)lparam, sizeof(MEASUREITEMSTRUCT) );
1045 break;
1046 case WM_WINDOWPOSCHANGING:
1047 case WM_WINDOWPOSCHANGED:
1048 push_data( data, (WINDOWPOS *)lparam, sizeof(WINDOWPOS) );
1049 break;
1050 case WM_GETDLGCODE:
1051 if (lparam) push_data( data, (MSG *)lparam, sizeof(MSG) );
1052 break;
1053 case SBM_GETSCROLLINFO:
1054 push_data( data, (SCROLLINFO *)lparam, sizeof(SCROLLINFO) );
1055 break;
1056 case EM_GETRECT:
1057 case LB_GETITEMRECT:
1058 case CB_GETDROPPEDCONTROLRECT:
1059 case WM_SIZING:
1060 case WM_MOVING:
1061 push_data( data, (RECT *)lparam, sizeof(RECT) );
1062 break;
1063 case EM_GETLINE:
1065 WORD *ptr = (WORD *)lparam;
1066 push_data( data, ptr, ptr[-1] * sizeof(WCHAR) );
1067 break;
1069 case LB_GETSELITEMS:
1070 push_data( data, (UINT *)lparam, wparam * sizeof(UINT) );
1071 break;
1072 case WM_MDIGETACTIVE:
1073 if (lparam) push_data( data, (BOOL *)lparam, sizeof(BOOL) );
1074 break;
1075 case WM_NCCALCSIZE:
1076 if (!wparam)
1077 push_data( data, (RECT *)lparam, sizeof(RECT) );
1078 else
1080 NCCALCSIZE_PARAMS *nc = (NCCALCSIZE_PARAMS *)lparam;
1081 push_data( data, nc, sizeof(*nc) );
1082 push_data( data, nc->lppos, sizeof(*nc->lppos) );
1084 break;
1085 case EM_GETSEL:
1086 case SBM_GETRANGE:
1087 case CB_GETEDITSEL:
1088 if (wparam) push_data( data, (DWORD *)wparam, sizeof(DWORD) );
1089 if (lparam) push_data( data, (DWORD *)lparam, sizeof(DWORD) );
1090 break;
1091 case WM_NEXTMENU:
1092 push_data( data, (MDINEXTMENU *)lparam, sizeof(MDINEXTMENU) );
1093 break;
1094 case WM_MDICREATE:
1095 push_data( data, (MDICREATESTRUCTW *)lparam, sizeof(MDICREATESTRUCTW) );
1096 break;
1097 case WM_ASKCBFORMATNAME:
1098 push_data( data, (WCHAR *)lparam, (strlenW((WCHAR *)lparam) + 1) * sizeof(WCHAR) );
1099 break;
1104 /***********************************************************************
1105 * unpack_reply
1107 * Unpack a message reply received from another process.
1109 static void unpack_reply( HWND hwnd, UINT message, WPARAM wparam, LPARAM lparam,
1110 void *buffer, size_t size )
1112 switch(message)
1114 case WM_NCCREATE:
1115 case WM_CREATE:
1117 CREATESTRUCTW *cs = (CREATESTRUCTW *)lparam;
1118 LPCWSTR name = cs->lpszName, class = cs->lpszClass;
1119 memcpy( cs, buffer, min( sizeof(*cs), size ));
1120 cs->lpszName = name; /* restore the original pointers */
1121 cs->lpszClass = class;
1122 break;
1124 case WM_GETTEXT:
1125 case WM_ASKCBFORMATNAME:
1126 memcpy( (WCHAR *)lparam, buffer, min( wparam*sizeof(WCHAR), size ));
1127 break;
1128 case WM_GETMINMAXINFO:
1129 memcpy( (MINMAXINFO *)lparam, buffer, min( sizeof(MINMAXINFO), size ));
1130 break;
1131 case WM_MEASUREITEM:
1132 memcpy( (MEASUREITEMSTRUCT *)lparam, buffer, min( sizeof(MEASUREITEMSTRUCT), size ));
1133 break;
1134 case WM_WINDOWPOSCHANGING:
1135 case WM_WINDOWPOSCHANGED:
1136 memcpy( (WINDOWPOS *)lparam, buffer, min( sizeof(WINDOWPOS), size ));
1137 break;
1138 case WM_GETDLGCODE:
1139 if (lparam) memcpy( (MSG *)lparam, buffer, min( sizeof(MSG), size ));
1140 break;
1141 case SBM_GETSCROLLINFO:
1142 memcpy( (SCROLLINFO *)lparam, buffer, min( sizeof(SCROLLINFO), size ));
1143 break;
1144 case SBM_GETSCROLLBARINFO:
1145 memcpy( (SCROLLBARINFO *)lparam, buffer, min( sizeof(SCROLLBARINFO), size ));
1146 break;
1147 case EM_GETRECT:
1148 case CB_GETDROPPEDCONTROLRECT:
1149 case LB_GETITEMRECT:
1150 case WM_SIZING:
1151 case WM_MOVING:
1152 memcpy( (RECT *)lparam, buffer, min( sizeof(RECT), size ));
1153 break;
1154 case EM_GETLINE:
1155 size = min( size, (size_t)*(WORD *)lparam );
1156 memcpy( (WCHAR *)lparam, buffer, size );
1157 break;
1158 case LB_GETSELITEMS:
1159 memcpy( (UINT *)lparam, buffer, min( wparam*sizeof(UINT), size ));
1160 break;
1161 case LB_GETTEXT:
1162 case CB_GETLBTEXT:
1163 memcpy( (WCHAR *)lparam, buffer, size );
1164 break;
1165 case WM_NEXTMENU:
1166 memcpy( (MDINEXTMENU *)lparam, buffer, min( sizeof(MDINEXTMENU), size ));
1167 break;
1168 case WM_MDIGETACTIVE:
1169 if (lparam) memcpy( (BOOL *)lparam, buffer, min( sizeof(BOOL), size ));
1170 break;
1171 case WM_NCCALCSIZE:
1172 if (!wparam)
1173 memcpy( (RECT *)lparam, buffer, min( sizeof(RECT), size ));
1174 else
1176 NCCALCSIZE_PARAMS *nc = (NCCALCSIZE_PARAMS *)lparam;
1177 WINDOWPOS *wp = nc->lppos;
1178 memcpy( nc, buffer, min( sizeof(*nc), size ));
1179 if (size > sizeof(*nc))
1181 size -= sizeof(*nc);
1182 memcpy( wp, (NCCALCSIZE_PARAMS*)buffer + 1, min( sizeof(*wp), size ));
1184 nc->lppos = wp; /* restore the original pointer */
1186 break;
1187 case EM_GETSEL:
1188 case SBM_GETRANGE:
1189 case CB_GETEDITSEL:
1190 if (wparam)
1192 memcpy( (DWORD *)wparam, buffer, min( sizeof(DWORD), size ));
1193 if (size <= sizeof(DWORD)) break;
1194 size -= sizeof(DWORD);
1195 buffer = (DWORD *)buffer + 1;
1197 if (lparam) memcpy( (DWORD *)lparam, buffer, min( sizeof(DWORD), size ));
1198 break;
1199 case WM_MDICREATE:
1201 MDICREATESTRUCTW *cs = (MDICREATESTRUCTW *)lparam;
1202 LPCWSTR title = cs->szTitle, class = cs->szClass;
1203 memcpy( cs, buffer, min( sizeof(*cs), size ));
1204 cs->szTitle = title; /* restore the original pointers */
1205 cs->szClass = class;
1206 break;
1208 default:
1209 ERR( "should not happen: unexpected message %x\n", message );
1210 break;
1215 /***********************************************************************
1216 * reply_message
1218 * Send a reply to a sent message.
1220 static void reply_message( struct received_message_info *info, LRESULT result, BOOL remove )
1222 struct packed_message data;
1223 int i, replied = info->flags & ISMEX_REPLIED;
1225 if (info->flags & ISMEX_NOTIFY) return; /* notify messages don't get replies */
1226 if (!remove && replied) return; /* replied already */
1228 data.count = 0;
1229 info->flags |= ISMEX_REPLIED;
1231 if (info->type == MSG_OTHER_PROCESS && !replied)
1233 pack_reply( info->msg.hwnd, info->msg.message, info->msg.wParam,
1234 info->msg.lParam, result, &data );
1237 SERVER_START_REQ( reply_message )
1239 req->result = result;
1240 req->remove = remove;
1241 for (i = 0; i < data.count; i++) wine_server_add_data( req, data.data[i], data.size[i] );
1242 wine_server_call( req );
1244 SERVER_END_REQ;
1248 /***********************************************************************
1249 * handle_internal_message
1251 * Handle an internal Wine message instead of calling the window proc.
1253 static LRESULT handle_internal_message( HWND hwnd, UINT msg, WPARAM wparam, LPARAM lparam )
1255 switch(msg)
1257 case WM_WINE_DESTROYWINDOW:
1258 return WIN_DestroyWindow( hwnd );
1259 case WM_WINE_SETWINDOWPOS:
1260 if (hwnd == GetDesktopWindow()) return 0;
1261 return USER_SetWindowPos( (WINDOWPOS *)lparam );
1262 case WM_WINE_SHOWWINDOW:
1263 if (hwnd == GetDesktopWindow()) return 0;
1264 return ShowWindow( hwnd, wparam );
1265 case WM_WINE_SETPARENT:
1266 if (hwnd == GetDesktopWindow()) return 0;
1267 return (LRESULT)SetParent( hwnd, (HWND)wparam );
1268 case WM_WINE_SETWINDOWLONG:
1269 return WIN_SetWindowLong( hwnd, (short)LOWORD(wparam), HIWORD(wparam), lparam, TRUE );
1270 case WM_WINE_ENABLEWINDOW:
1271 if (hwnd == GetDesktopWindow()) return 0;
1272 return EnableWindow( hwnd, wparam );
1273 case WM_WINE_SETACTIVEWINDOW:
1274 if (hwnd == GetDesktopWindow()) return 0;
1275 return (LRESULT)SetActiveWindow( (HWND)wparam );
1276 case WM_WINE_KEYBOARD_LL_HOOK:
1277 case WM_WINE_MOUSE_LL_HOOK:
1279 struct hook_extra_info *h_extra = (struct hook_extra_info *)lparam;
1281 return call_current_hook( h_extra->handle, HC_ACTION, wparam, h_extra->lparam );
1283 default:
1284 if (msg >= WM_WINE_FIRST_DRIVER_MSG && msg <= WM_WINE_LAST_DRIVER_MSG)
1285 return USER_Driver->pWindowMessage( hwnd, msg, wparam, lparam );
1286 FIXME( "unknown internal message %x\n", msg );
1287 return 0;
1291 /* since the WM_DDE_ACK response to a WM_DDE_EXECUTE message should contain the handle
1292 * to the memory handle, we keep track (in the server side) of all pairs of handle
1293 * used (the client passes its value and the content of the memory handle), and
1294 * the server stored both values (the client, and the local one, created after the
1295 * content). When a ACK message is generated, the list of pair is searched for a
1296 * matching pair, so that the client memory handle can be returned.
1298 struct DDE_pair {
1299 HGLOBAL client_hMem;
1300 HGLOBAL server_hMem;
1303 static struct DDE_pair* dde_pairs;
1304 static int dde_num_alloc;
1305 static int dde_num_used;
1307 static CRITICAL_SECTION dde_crst;
1308 static CRITICAL_SECTION_DEBUG critsect_debug =
1310 0, 0, &dde_crst,
1311 { &critsect_debug.ProcessLocksList, &critsect_debug.ProcessLocksList },
1312 0, 0, { (DWORD_PTR)(__FILE__ ": dde_crst") }
1314 static CRITICAL_SECTION dde_crst = { &critsect_debug, -1, 0, 0, 0, 0 };
1316 static BOOL dde_add_pair(HGLOBAL chm, HGLOBAL shm)
1318 int i;
1319 #define GROWBY 4
1321 EnterCriticalSection(&dde_crst);
1323 /* now remember the pair of hMem on both sides */
1324 if (dde_num_used == dde_num_alloc)
1326 struct DDE_pair* tmp;
1327 if (dde_pairs)
1328 tmp = HeapReAlloc( GetProcessHeap(), 0, dde_pairs,
1329 (dde_num_alloc + GROWBY) * sizeof(struct DDE_pair));
1330 else
1331 tmp = HeapAlloc( GetProcessHeap(), 0,
1332 (dde_num_alloc + GROWBY) * sizeof(struct DDE_pair));
1334 if (!tmp)
1336 LeaveCriticalSection(&dde_crst);
1337 return FALSE;
1339 dde_pairs = tmp;
1340 /* zero out newly allocated part */
1341 memset(&dde_pairs[dde_num_alloc], 0, GROWBY * sizeof(struct DDE_pair));
1342 dde_num_alloc += GROWBY;
1344 #undef GROWBY
1345 for (i = 0; i < dde_num_alloc; i++)
1347 if (dde_pairs[i].server_hMem == 0)
1349 dde_pairs[i].client_hMem = chm;
1350 dde_pairs[i].server_hMem = shm;
1351 dde_num_used++;
1352 break;
1355 LeaveCriticalSection(&dde_crst);
1356 return TRUE;
1359 static HGLOBAL dde_get_pair(HGLOBAL shm)
1361 int i;
1362 HGLOBAL ret = 0;
1364 EnterCriticalSection(&dde_crst);
1365 for (i = 0; i < dde_num_alloc; i++)
1367 if (dde_pairs[i].server_hMem == shm)
1369 /* free this pair */
1370 dde_pairs[i].server_hMem = 0;
1371 dde_num_used--;
1372 ret = dde_pairs[i].client_hMem;
1373 break;
1376 LeaveCriticalSection(&dde_crst);
1377 return ret;
1380 /***********************************************************************
1381 * post_dde_message
1383 * Post a DDE message
1385 static BOOL post_dde_message( struct packed_message *data, const struct send_message_info *info )
1387 void* ptr = NULL;
1388 int size = 0;
1389 UINT_PTR uiLo, uiHi;
1390 LPARAM lp = 0;
1391 HGLOBAL hunlock = 0;
1392 int i;
1393 DWORD res;
1395 if (!UnpackDDElParam( info->msg, info->lparam, &uiLo, &uiHi ))
1396 return FALSE;
1398 lp = info->lparam;
1399 switch (info->msg)
1401 /* DDE messages which don't require packing are:
1402 * WM_DDE_INITIATE
1403 * WM_DDE_TERMINATE
1404 * WM_DDE_REQUEST
1405 * WM_DDE_UNADVISE
1407 case WM_DDE_ACK:
1408 if (HIWORD(uiHi))
1410 /* uiHi should contain a hMem from WM_DDE_EXECUTE */
1411 HGLOBAL h = dde_get_pair( (HANDLE)uiHi );
1412 if (h)
1414 /* send back the value of h on the other side */
1415 push_data( data, &h, sizeof(HGLOBAL) );
1416 lp = uiLo;
1417 TRACE( "send dde-ack %lx %08lx => %p\n", uiLo, uiHi, h );
1420 else
1422 /* uiHi should contain either an atom or 0 */
1423 TRACE( "send dde-ack %lx atom=%lx\n", uiLo, uiHi );
1424 lp = MAKELONG( uiLo, uiHi );
1426 break;
1427 case WM_DDE_ADVISE:
1428 case WM_DDE_DATA:
1429 case WM_DDE_POKE:
1430 size = 0;
1431 if (uiLo)
1433 size = GlobalSize( (HGLOBAL)uiLo ) ;
1434 if ((info->msg == WM_DDE_ADVISE && size < sizeof(DDEADVISE)) ||
1435 (info->msg == WM_DDE_DATA && size < sizeof(DDEDATA)) ||
1436 (info->msg == WM_DDE_POKE && size < sizeof(DDEPOKE))
1438 return FALSE;
1440 else if (info->msg != WM_DDE_DATA) return FALSE;
1442 lp = uiHi;
1443 if (uiLo)
1445 if ((ptr = GlobalLock( (HGLOBAL)uiLo) ))
1447 DDEDATA *dde_data = (DDEDATA *)ptr;
1448 TRACE("unused %d, fResponse %d, fRelease %d, fDeferUpd %d, fAckReq %d, cfFormat %d\n",
1449 dde_data->unused, dde_data->fResponse, dde_data->fRelease,
1450 dde_data->reserved, dde_data->fAckReq, dde_data->cfFormat);
1451 push_data( data, ptr, size );
1452 hunlock = (HGLOBAL)uiLo;
1455 TRACE( "send ddepack %u %lx\n", size, uiHi );
1456 break;
1457 case WM_DDE_EXECUTE:
1458 if (info->lparam)
1460 if ((ptr = GlobalLock( (HGLOBAL)info->lparam) ))
1462 push_data(data, ptr, GlobalSize( (HGLOBAL)info->lparam ));
1463 /* so that the other side can send it back on ACK */
1464 lp = info->lparam;
1465 hunlock = (HGLOBAL)info->lparam;
1468 break;
1470 SERVER_START_REQ( send_message )
1472 req->id = info->dest_tid;
1473 req->type = info->type;
1474 req->flags = 0;
1475 req->win = info->hwnd;
1476 req->msg = info->msg;
1477 req->wparam = info->wparam;
1478 req->lparam = lp;
1479 req->timeout = TIMEOUT_INFINITE;
1480 for (i = 0; i < data->count; i++)
1481 wine_server_add_data( req, data->data[i], data->size[i] );
1482 if ((res = wine_server_call( req )))
1484 if (res == STATUS_INVALID_PARAMETER)
1485 /* FIXME: find a STATUS_ value for this one */
1486 SetLastError( ERROR_INVALID_THREAD_ID );
1487 else
1488 SetLastError( RtlNtStatusToDosError(res) );
1490 else
1491 FreeDDElParam(info->msg, info->lparam);
1493 SERVER_END_REQ;
1494 if (hunlock) GlobalUnlock(hunlock);
1496 return !res;
1499 /***********************************************************************
1500 * unpack_dde_message
1502 * Unpack a posted DDE message received from another process.
1504 static BOOL unpack_dde_message( HWND hwnd, UINT message, WPARAM *wparam, LPARAM *lparam,
1505 void **buffer, size_t size )
1507 UINT_PTR uiLo, uiHi;
1508 HGLOBAL hMem = 0;
1509 void* ptr;
1511 switch (message)
1513 case WM_DDE_ACK:
1514 if (size)
1516 /* hMem is being passed */
1517 if (size != sizeof(HGLOBAL)) return FALSE;
1518 if (!buffer || !*buffer) return FALSE;
1519 uiLo = *lparam;
1520 memcpy( &hMem, *buffer, size );
1521 uiHi = (UINT_PTR)hMem;
1522 TRACE("recv dde-ack %lx mem=%lx[%lx]\n", uiLo, uiHi, GlobalSize( hMem ));
1524 else
1526 uiLo = LOWORD( *lparam );
1527 uiHi = HIWORD( *lparam );
1528 TRACE("recv dde-ack %lx atom=%lx\n", uiLo, uiHi);
1530 *lparam = PackDDElParam( WM_DDE_ACK, uiLo, uiHi );
1531 break;
1532 case WM_DDE_ADVISE:
1533 case WM_DDE_DATA:
1534 case WM_DDE_POKE:
1535 if ((!buffer || !*buffer) && message != WM_DDE_DATA) return FALSE;
1536 uiHi = *lparam;
1537 if (size)
1539 if (!(hMem = GlobalAlloc( GMEM_MOVEABLE|GMEM_DDESHARE, size )))
1540 return FALSE;
1541 if ((ptr = GlobalLock( hMem )))
1543 memcpy( ptr, *buffer, size );
1544 GlobalUnlock( hMem );
1546 else
1548 GlobalFree( hMem );
1549 return FALSE;
1552 uiLo = (UINT_PTR)hMem;
1554 *lparam = PackDDElParam( message, uiLo, uiHi );
1555 break;
1556 case WM_DDE_EXECUTE:
1557 if (size)
1559 if (!buffer || !*buffer) return FALSE;
1560 if (!(hMem = GlobalAlloc( GMEM_MOVEABLE|GMEM_DDESHARE, size ))) return FALSE;
1561 if ((ptr = GlobalLock( hMem )))
1563 memcpy( ptr, *buffer, size );
1564 GlobalUnlock( hMem );
1565 TRACE( "exec: pairing c=%08lx s=%p\n", *lparam, hMem );
1566 if (!dde_add_pair( (HGLOBAL)*lparam, hMem ))
1568 GlobalFree( hMem );
1569 return FALSE;
1572 else
1574 GlobalFree( hMem );
1575 return FALSE;
1577 } else return FALSE;
1578 *lparam = (LPARAM)hMem;
1579 break;
1581 return TRUE;
1584 /***********************************************************************
1585 * call_window_proc
1587 * Call a window procedure and the corresponding hooks.
1589 static LRESULT call_window_proc( HWND hwnd, UINT msg, WPARAM wparam, LPARAM lparam,
1590 BOOL unicode, BOOL same_thread, enum wm_char_mapping mapping )
1592 struct user_thread_info *thread_info = get_user_thread_info();
1593 LRESULT result = 0;
1594 CWPSTRUCT cwp;
1595 CWPRETSTRUCT cwpret;
1597 if (thread_info->recursion_count > MAX_SENDMSG_RECURSION) return 0;
1598 thread_info->recursion_count++;
1600 if (msg & 0x80000000)
1602 result = handle_internal_message( hwnd, msg, wparam, lparam );
1603 goto done;
1606 /* first the WH_CALLWNDPROC hook */
1607 hwnd = WIN_GetFullHandle( hwnd );
1608 cwp.lParam = lparam;
1609 cwp.wParam = wparam;
1610 cwp.message = msg;
1611 cwp.hwnd = hwnd;
1612 HOOK_CallHooks( WH_CALLWNDPROC, HC_ACTION, same_thread, (LPARAM)&cwp, unicode );
1614 /* now call the window procedure */
1615 if (!WINPROC_call_window( hwnd, msg, wparam, lparam, &result, unicode, mapping )) goto done;
1617 /* and finally the WH_CALLWNDPROCRET hook */
1618 cwpret.lResult = result;
1619 cwpret.lParam = lparam;
1620 cwpret.wParam = wparam;
1621 cwpret.message = msg;
1622 cwpret.hwnd = hwnd;
1623 HOOK_CallHooks( WH_CALLWNDPROCRET, HC_ACTION, same_thread, (LPARAM)&cwpret, unicode );
1624 done:
1625 thread_info->recursion_count--;
1626 return result;
1630 /***********************************************************************
1631 * send_parent_notify
1633 * Send a WM_PARENTNOTIFY to all ancestors of the given window, unless
1634 * the window has the WS_EX_NOPARENTNOTIFY style.
1636 static void send_parent_notify( HWND hwnd, WORD event, WORD idChild, POINT pt )
1638 /* pt has to be in the client coordinates of the parent window */
1639 MapWindowPoints( 0, hwnd, &pt, 1 );
1640 for (;;)
1642 HWND parent;
1644 if (!(GetWindowLongW( hwnd, GWL_STYLE ) & WS_CHILD)) break;
1645 if (GetWindowLongW( hwnd, GWL_EXSTYLE ) & WS_EX_NOPARENTNOTIFY) break;
1646 if (!(parent = GetParent(hwnd))) break;
1647 if (parent == GetDesktopWindow()) break;
1648 MapWindowPoints( hwnd, parent, &pt, 1 );
1649 hwnd = parent;
1650 SendMessageW( hwnd, WM_PARENTNOTIFY,
1651 MAKEWPARAM( event, idChild ), MAKELPARAM( pt.x, pt.y ) );
1656 /***********************************************************************
1657 * accept_hardware_message
1659 * Tell the server we have passed the message to the app
1660 * (even though we may end up dropping it later on)
1662 static void accept_hardware_message( UINT hw_id, BOOL remove, HWND new_hwnd )
1664 SERVER_START_REQ( accept_hardware_message )
1666 req->hw_id = hw_id;
1667 req->remove = remove;
1668 req->new_win = new_hwnd;
1669 if (wine_server_call( req ))
1670 FIXME("Failed to reply to MSG_HARDWARE message. Message may not be removed from queue.\n");
1672 SERVER_END_REQ;
1676 /***********************************************************************
1677 * process_keyboard_message
1679 * returns TRUE if the contents of 'msg' should be passed to the application
1681 static BOOL process_keyboard_message( MSG *msg, UINT hw_id, HWND hwnd_filter,
1682 UINT first, UINT last, BOOL remove )
1684 EVENTMSG event;
1686 if (msg->message == WM_KEYDOWN || msg->message == WM_SYSKEYDOWN ||
1687 msg->message == WM_KEYUP || msg->message == WM_SYSKEYUP)
1688 switch (msg->wParam)
1690 case VK_LSHIFT: case VK_RSHIFT:
1691 msg->wParam = VK_SHIFT;
1692 break;
1693 case VK_LCONTROL: case VK_RCONTROL:
1694 msg->wParam = VK_CONTROL;
1695 break;
1696 case VK_LMENU: case VK_RMENU:
1697 msg->wParam = VK_MENU;
1698 break;
1701 /* FIXME: is this really the right place for this hook? */
1702 event.message = msg->message;
1703 event.hwnd = msg->hwnd;
1704 event.time = msg->time;
1705 event.paramL = (msg->wParam & 0xFF) | (HIWORD(msg->lParam) << 8);
1706 event.paramH = msg->lParam & 0x7FFF;
1707 if (HIWORD(msg->lParam) & 0x0100) event.paramH |= 0x8000; /* special_key - bit */
1708 HOOK_CallHooks( WH_JOURNALRECORD, HC_ACTION, 0, (LPARAM)&event, TRUE );
1710 /* check message filters */
1711 if (msg->message < first || msg->message > last) return FALSE;
1712 if (!check_hwnd_filter( msg, hwnd_filter )) return FALSE;
1714 if (remove)
1716 if((msg->message == WM_KEYDOWN) &&
1717 (msg->hwnd != GetDesktopWindow()))
1719 /* Handle F1 key by sending out WM_HELP message */
1720 if (msg->wParam == VK_F1)
1722 PostMessageW( msg->hwnd, WM_KEYF1, 0, 0 );
1724 else if(msg->wParam >= VK_BROWSER_BACK &&
1725 msg->wParam <= VK_LAUNCH_APP2)
1727 /* FIXME: Process keystate */
1728 SendMessageW(msg->hwnd, WM_APPCOMMAND, (WPARAM)msg->hwnd, MAKELPARAM(0, (FAPPCOMMAND_KEY | (msg->wParam - VK_BROWSER_BACK + 1))));
1731 else if (msg->message == WM_KEYUP)
1733 /* Handle VK_APPS key by posting a WM_CONTEXTMENU message */
1734 if (msg->wParam == VK_APPS && !MENU_IsMenuActive())
1735 PostMessageW(msg->hwnd, WM_CONTEXTMENU, (WPARAM)msg->hwnd, (LPARAM)-1);
1739 if (HOOK_CallHooks( WH_KEYBOARD, remove ? HC_ACTION : HC_NOREMOVE,
1740 LOWORD(msg->wParam), msg->lParam, TRUE ))
1742 /* skip this message */
1743 HOOK_CallHooks( WH_CBT, HCBT_KEYSKIPPED, LOWORD(msg->wParam), msg->lParam, TRUE );
1744 accept_hardware_message( hw_id, TRUE, 0 );
1745 return FALSE;
1747 accept_hardware_message( hw_id, remove, 0 );
1748 return TRUE;
1752 /***********************************************************************
1753 * process_mouse_message
1755 * returns TRUE if the contents of 'msg' should be passed to the application
1757 static BOOL process_mouse_message( MSG *msg, UINT hw_id, ULONG_PTR extra_info, HWND hwnd_filter,
1758 UINT first, UINT last, BOOL remove )
1760 static MSG clk_msg;
1762 POINT pt;
1763 UINT message;
1764 INT hittest;
1765 EVENTMSG event;
1766 GUITHREADINFO info;
1767 MOUSEHOOKSTRUCT hook;
1768 BOOL eatMsg;
1770 /* find the window to dispatch this mouse message to */
1772 GetGUIThreadInfo( GetCurrentThreadId(), &info );
1773 if (info.hwndCapture)
1775 hittest = HTCLIENT;
1776 msg->hwnd = info.hwndCapture;
1778 else
1780 msg->hwnd = WINPOS_WindowFromPoint( msg->hwnd, msg->pt, &hittest );
1783 if (!msg->hwnd || !WIN_IsCurrentThread( msg->hwnd ))
1785 accept_hardware_message( hw_id, TRUE, msg->hwnd );
1786 return FALSE;
1789 /* FIXME: is this really the right place for this hook? */
1790 event.message = msg->message;
1791 event.time = msg->time;
1792 event.hwnd = msg->hwnd;
1793 event.paramL = msg->pt.x;
1794 event.paramH = msg->pt.y;
1795 HOOK_CallHooks( WH_JOURNALRECORD, HC_ACTION, 0, (LPARAM)&event, TRUE );
1797 if (!check_hwnd_filter( msg, hwnd_filter )) return FALSE;
1799 pt = msg->pt;
1800 message = msg->message;
1801 /* Note: windows has no concept of a non-client wheel message */
1802 if (message != WM_MOUSEWHEEL)
1804 if (hittest != HTCLIENT)
1806 message += WM_NCMOUSEMOVE - WM_MOUSEMOVE;
1807 msg->wParam = hittest;
1809 else
1811 /* coordinates don't get translated while tracking a menu */
1812 /* FIXME: should differentiate popups and top-level menus */
1813 if (!(info.flags & GUI_INMENUMODE))
1814 ScreenToClient( msg->hwnd, &pt );
1817 msg->lParam = MAKELONG( pt.x, pt.y );
1819 /* translate double clicks */
1821 if ((msg->message == WM_LBUTTONDOWN) ||
1822 (msg->message == WM_RBUTTONDOWN) ||
1823 (msg->message == WM_MBUTTONDOWN) ||
1824 (msg->message == WM_XBUTTONDOWN))
1826 BOOL update = remove;
1828 /* translate double clicks -
1829 * note that ...MOUSEMOVEs can slip in between
1830 * ...BUTTONDOWN and ...BUTTONDBLCLK messages */
1832 if ((info.flags & (GUI_INMENUMODE|GUI_INMOVESIZE)) ||
1833 hittest != HTCLIENT ||
1834 (GetClassLongA( msg->hwnd, GCL_STYLE ) & CS_DBLCLKS))
1836 if ((msg->message == clk_msg.message) &&
1837 (msg->hwnd == clk_msg.hwnd) &&
1838 (msg->wParam == clk_msg.wParam) &&
1839 (msg->time - clk_msg.time < GetDoubleClickTime()) &&
1840 (abs(msg->pt.x - clk_msg.pt.x) < GetSystemMetrics(SM_CXDOUBLECLK)/2) &&
1841 (abs(msg->pt.y - clk_msg.pt.y) < GetSystemMetrics(SM_CYDOUBLECLK)/2))
1843 message += (WM_LBUTTONDBLCLK - WM_LBUTTONDOWN);
1844 if (update)
1846 clk_msg.message = 0; /* clear the double click conditions */
1847 update = FALSE;
1851 if (message < first || message > last) return FALSE;
1852 /* update static double click conditions */
1853 if (update) clk_msg = *msg;
1855 else
1857 if (message < first || message > last) return FALSE;
1860 /* message is accepted now (but may still get dropped) */
1862 hook.pt = msg->pt;
1863 hook.hwnd = msg->hwnd;
1864 hook.wHitTestCode = hittest;
1865 hook.dwExtraInfo = extra_info;
1866 if (HOOK_CallHooks( WH_MOUSE, remove ? HC_ACTION : HC_NOREMOVE,
1867 message, (LPARAM)&hook, TRUE ))
1869 hook.pt = msg->pt;
1870 hook.hwnd = msg->hwnd;
1871 hook.wHitTestCode = hittest;
1872 hook.dwExtraInfo = extra_info;
1873 HOOK_CallHooks( WH_CBT, HCBT_CLICKSKIPPED, message, (LPARAM)&hook, TRUE );
1874 accept_hardware_message( hw_id, TRUE, 0 );
1875 return FALSE;
1878 if ((hittest == HTERROR) || (hittest == HTNOWHERE))
1880 SendMessageW( msg->hwnd, WM_SETCURSOR, (WPARAM)msg->hwnd,
1881 MAKELONG( hittest, msg->message ));
1882 accept_hardware_message( hw_id, TRUE, 0 );
1883 return FALSE;
1886 accept_hardware_message( hw_id, remove, 0 );
1888 if (!remove || info.hwndCapture)
1890 msg->message = message;
1891 return TRUE;
1894 eatMsg = FALSE;
1896 if ((msg->message == WM_LBUTTONDOWN) ||
1897 (msg->message == WM_RBUTTONDOWN) ||
1898 (msg->message == WM_MBUTTONDOWN) ||
1899 (msg->message == WM_XBUTTONDOWN))
1901 /* Send the WM_PARENTNOTIFY,
1902 * note that even for double/nonclient clicks
1903 * notification message is still WM_L/M/RBUTTONDOWN.
1905 send_parent_notify( msg->hwnd, msg->message, 0, msg->pt );
1907 /* Activate the window if needed */
1909 if (msg->hwnd != info.hwndActive)
1911 HWND hwndTop = msg->hwnd;
1912 while (hwndTop)
1914 if ((GetWindowLongW( hwndTop, GWL_STYLE ) & (WS_POPUP|WS_CHILD)) != WS_CHILD) break;
1915 hwndTop = GetParent( hwndTop );
1918 if (hwndTop && hwndTop != GetDesktopWindow())
1920 LONG ret = SendMessageW( msg->hwnd, WM_MOUSEACTIVATE, (WPARAM)hwndTop,
1921 MAKELONG( hittest, msg->message ) );
1922 switch(ret)
1924 case MA_NOACTIVATEANDEAT:
1925 eatMsg = TRUE;
1926 /* fall through */
1927 case MA_NOACTIVATE:
1928 break;
1929 case MA_ACTIVATEANDEAT:
1930 eatMsg = TRUE;
1931 /* fall through */
1932 case MA_ACTIVATE:
1933 case 0:
1934 if (!FOCUS_MouseActivate( hwndTop )) eatMsg = TRUE;
1935 break;
1936 default:
1937 WARN( "unknown WM_MOUSEACTIVATE code %d\n", ret );
1938 break;
1944 /* send the WM_SETCURSOR message */
1946 /* Windows sends the normal mouse message as the message parameter
1947 in the WM_SETCURSOR message even if it's non-client mouse message */
1948 SendMessageW( msg->hwnd, WM_SETCURSOR, (WPARAM)msg->hwnd, MAKELONG( hittest, msg->message ));
1950 msg->message = message;
1951 return !eatMsg;
1955 /***********************************************************************
1956 * process_hardware_message
1958 * Process a hardware message; return TRUE if message should be passed on to the app
1960 static BOOL process_hardware_message( MSG *msg, UINT hw_id, ULONG_PTR extra_info, HWND hwnd_filter,
1961 UINT first, UINT last, BOOL remove )
1963 if (is_keyboard_message( msg->message ))
1964 return process_keyboard_message( msg, hw_id, hwnd_filter, first, last, remove );
1966 if (is_mouse_message( msg->message ))
1967 return process_mouse_message( msg, hw_id, extra_info, hwnd_filter, first, last, remove );
1969 ERR( "unknown message type %x\n", msg->message );
1970 return FALSE;
1974 /***********************************************************************
1975 * call_sendmsg_callback
1977 * Call the callback function of SendMessageCallback.
1979 static inline void call_sendmsg_callback( SENDASYNCPROC callback, HWND hwnd, UINT msg,
1980 ULONG_PTR data, LRESULT result )
1982 if (!callback) return;
1984 if (TRACE_ON(relay))
1985 DPRINTF( "%04x:Call message callback %p (hwnd=%p,msg=%s,data=%08lx,result=%08lx)\n",
1986 GetCurrentThreadId(), callback, hwnd, SPY_GetMsgName( msg, hwnd ),
1987 data, result );
1988 callback( hwnd, msg, data, result );
1989 if (TRACE_ON(relay))
1990 DPRINTF( "%04x:Ret message callback %p (hwnd=%p,msg=%s,data=%08lx,result=%08lx)\n",
1991 GetCurrentThreadId(), callback, hwnd, SPY_GetMsgName( msg, hwnd ),
1992 data, result );
1996 /***********************************************************************
1997 * peek_message
1999 * Peek for a message matching the given parameters. Return FALSE if none available.
2000 * All pending sent messages are processed before returning.
2002 static BOOL peek_message( MSG *msg, HWND hwnd, UINT first, UINT last, UINT flags )
2004 LRESULT result;
2005 ULONG_PTR extra_info = 0;
2006 struct user_thread_info *thread_info = get_user_thread_info();
2007 struct received_message_info info, *old_info;
2008 unsigned int wake_mask, changed_mask = HIWORD(flags);
2009 unsigned int hw_id = 0; /* id of previous hardware message */
2011 if (!first && !last) last = ~0;
2012 if (!changed_mask) changed_mask = QS_ALLINPUT;
2013 wake_mask = changed_mask & (QS_SENDMESSAGE | QS_SMRESULT);
2015 for (;;)
2017 NTSTATUS res;
2018 void *buffer = NULL;
2019 size_t size = 0, buffer_size = 0;
2021 do /* loop while buffer is too small */
2023 if (buffer_size && !(buffer = HeapAlloc( GetProcessHeap(), 0, buffer_size )))
2024 return FALSE;
2025 SERVER_START_REQ( get_message )
2027 req->flags = flags;
2028 req->get_win = hwnd;
2029 req->get_first = first;
2030 req->get_last = last;
2031 req->hw_id = hw_id;
2032 req->wake_mask = wake_mask;
2033 req->changed_mask = changed_mask;
2034 if (buffer_size) wine_server_set_reply( req, buffer, buffer_size );
2035 if (!(res = wine_server_call( req )))
2037 size = wine_server_reply_size( reply );
2038 info.type = reply->type;
2039 info.msg.hwnd = reply->win;
2040 info.msg.message = reply->msg;
2041 info.msg.wParam = reply->wparam;
2042 info.msg.lParam = reply->lparam;
2043 info.msg.time = reply->time;
2044 info.msg.pt.x = reply->x;
2045 info.msg.pt.y = reply->y;
2046 hw_id = reply->hw_id;
2047 extra_info = reply->info;
2048 thread_info->active_hooks = reply->active_hooks;
2050 else
2052 HeapFree( GetProcessHeap(), 0, buffer );
2053 buffer_size = reply->total;
2056 SERVER_END_REQ;
2057 } while (res == STATUS_BUFFER_OVERFLOW);
2059 if (res) return FALSE;
2061 TRACE( "got type %d msg %x (%s) hwnd %p wp %lx lp %lx\n",
2062 info.type, info.msg.message,
2063 (info.type == MSG_WINEVENT) ? "MSG_WINEVENT" : SPY_GetMsgName(info.msg.message, info.msg.hwnd),
2064 info.msg.hwnd, info.msg.wParam, info.msg.lParam );
2066 switch(info.type)
2068 case MSG_ASCII:
2069 case MSG_UNICODE:
2070 info.flags = ISMEX_SEND;
2071 break;
2072 case MSG_NOTIFY:
2073 info.flags = ISMEX_NOTIFY;
2074 break;
2075 case MSG_CALLBACK:
2076 info.flags = ISMEX_CALLBACK;
2077 break;
2078 case MSG_CALLBACK_RESULT:
2079 if (size >= sizeof(struct callback_msg_data))
2081 const struct callback_msg_data *data = (const struct callback_msg_data *)buffer;
2082 call_sendmsg_callback( data->callback, info.msg.hwnd,
2083 info.msg.message, data->data, data->result );
2085 goto next;
2086 case MSG_WINEVENT:
2087 if (size >= sizeof(struct winevent_msg_data))
2089 WINEVENTPROC hook_proc;
2090 const struct winevent_msg_data *data = (const struct winevent_msg_data *)buffer;
2092 hook_proc = data->hook_proc;
2093 size -= sizeof(*data);
2094 if (size)
2096 WCHAR module[MAX_PATH];
2098 size = min( size, (MAX_PATH - 1) * sizeof(WCHAR) );
2099 memcpy( module, buffer, size );
2100 module[size / sizeof(WCHAR)] = 0;
2101 if (!(hook_proc = get_hook_proc( hook_proc, module )))
2103 ERR( "invalid winevent hook module name %s\n", debugstr_w(module) );
2104 goto next;
2108 if (TRACE_ON(relay))
2109 DPRINTF( "%04x:Call winevent proc %p (hook=%p,event=%x,hwnd=%p,object_id=%lx,child_id=%lx,tid=%04x,time=%x)\n",
2110 GetCurrentThreadId(), hook_proc,
2111 data->hook, info.msg.message, info.msg.hwnd, info.msg.wParam,
2112 info.msg.lParam, data->tid, info.msg.time);
2114 hook_proc( data->hook, info.msg.message, info.msg.hwnd, info.msg.wParam,
2115 info.msg.lParam, data->tid, info.msg.time );
2117 if (TRACE_ON(relay))
2118 DPRINTF( "%04x:Ret winevent proc %p (hook=%p,event=%x,hwnd=%p,object_id=%lx,child_id=%lx,tid=%04x,time=%x)\n",
2119 GetCurrentThreadId(), hook_proc,
2120 data->hook, info.msg.message, info.msg.hwnd, info.msg.wParam,
2121 info.msg.lParam, data->tid, info.msg.time);
2123 goto next;
2124 case MSG_OTHER_PROCESS:
2125 info.flags = ISMEX_SEND;
2126 if (!unpack_message( info.msg.hwnd, info.msg.message, &info.msg.wParam,
2127 &info.msg.lParam, &buffer, size ))
2129 /* ignore it */
2130 reply_message( &info, 0, TRUE );
2131 goto next;
2133 break;
2134 case MSG_HARDWARE:
2135 if (!process_hardware_message( &info.msg, hw_id, extra_info,
2136 hwnd, first, last, flags & PM_REMOVE ))
2138 TRACE("dropping msg %x\n", info.msg.message );
2139 goto next; /* ignore it */
2141 thread_info->GetMessagePosVal = MAKELONG( info.msg.pt.x, info.msg.pt.y );
2142 /* fall through */
2143 case MSG_POSTED:
2144 thread_info->GetMessageExtraInfoVal = extra_info;
2145 if (info.msg.message >= WM_DDE_FIRST && info.msg.message <= WM_DDE_LAST)
2147 if (!unpack_dde_message( info.msg.hwnd, info.msg.message, &info.msg.wParam,
2148 &info.msg.lParam, &buffer, size ))
2149 goto next; /* ignore it */
2151 *msg = info.msg;
2152 HeapFree( GetProcessHeap(), 0, buffer );
2153 return TRUE;
2156 /* if we get here, we have a sent message; call the window procedure */
2157 old_info = thread_info->receive_info;
2158 thread_info->receive_info = &info;
2159 result = call_window_proc( info.msg.hwnd, info.msg.message, info.msg.wParam,
2160 info.msg.lParam, (info.type != MSG_ASCII), FALSE,
2161 WMCHAR_MAP_RECVMESSAGE );
2162 reply_message( &info, result, TRUE );
2163 thread_info->receive_info = old_info;
2165 /* if some PM_QS* flags were specified, only handle sent messages from now on */
2166 if (HIWORD(flags)) flags = PM_QS_SENDMESSAGE | LOWORD(flags);
2167 next:
2168 HeapFree( GetProcessHeap(), 0, buffer );
2173 /***********************************************************************
2174 * process_sent_messages
2176 * Process all pending sent messages.
2178 static inline void process_sent_messages(void)
2180 MSG msg;
2181 peek_message( &msg, 0, 0, 0, PM_REMOVE | PM_QS_SENDMESSAGE );
2185 /***********************************************************************
2186 * get_server_queue_handle
2188 * Get a handle to the server message queue for the current thread.
2190 static HANDLE get_server_queue_handle(void)
2192 struct user_thread_info *thread_info = get_user_thread_info();
2193 HANDLE ret;
2195 if (!(ret = thread_info->server_queue))
2197 SERVER_START_REQ( get_msg_queue )
2199 wine_server_call( req );
2200 ret = reply->handle;
2202 SERVER_END_REQ;
2203 thread_info->server_queue = ret;
2204 if (!ret) ERR( "Cannot get server thread queue\n" );
2206 return ret;
2210 /***********************************************************************
2211 * wait_message_reply
2213 * Wait until a sent message gets replied to.
2215 static void wait_message_reply( UINT flags )
2217 HANDLE server_queue = get_server_queue_handle();
2219 for (;;)
2221 unsigned int wake_bits = 0, changed_bits = 0;
2222 DWORD dwlc, res;
2224 SERVER_START_REQ( set_queue_mask )
2226 req->wake_mask = QS_SMRESULT | ((flags & SMTO_BLOCK) ? 0 : QS_SENDMESSAGE);
2227 req->changed_mask = req->wake_mask;
2228 req->skip_wait = 1;
2229 if (!wine_server_call( req ))
2231 wake_bits = reply->wake_bits;
2232 changed_bits = reply->changed_bits;
2235 SERVER_END_REQ;
2237 if (wake_bits & QS_SMRESULT) return; /* got a result */
2238 if (wake_bits & QS_SENDMESSAGE)
2240 /* Process the sent message immediately */
2241 process_sent_messages();
2242 continue;
2245 /* now wait for it */
2247 ReleaseThunkLock( &dwlc );
2248 res = USER_Driver->pMsgWaitForMultipleObjectsEx( 1, &server_queue,
2249 INFINITE, QS_SENDMESSAGE, 0 );
2250 if (dwlc) RestoreThunkLock( dwlc );
2254 /***********************************************************************
2255 * put_message_in_queue
2257 * Put a sent message into the destination queue.
2258 * For inter-process message, reply_size is set to expected size of reply data.
2260 static BOOL put_message_in_queue( const struct send_message_info *info, size_t *reply_size )
2262 struct packed_message data;
2263 message_data_t msg_data;
2264 unsigned int res;
2265 int i;
2266 timeout_t timeout = TIMEOUT_INFINITE;
2268 /* Check for INFINITE timeout for compatibility with Win9x,
2269 * although Windows >= NT does not do so
2271 if (info->type != MSG_NOTIFY &&
2272 info->type != MSG_CALLBACK &&
2273 info->type != MSG_POSTED &&
2274 info->timeout &&
2275 info->timeout != INFINITE)
2277 /* timeout is signed despite the prototype */
2278 timeout = (timeout_t)max( 0, (int)info->timeout ) * -10000;
2281 data.count = 0;
2282 if (info->type == MSG_OTHER_PROCESS)
2284 *reply_size = pack_message( info->hwnd, info->msg, info->wparam, info->lparam, &data );
2285 if (data.count == -1)
2287 WARN( "cannot pack message %x\n", info->msg );
2288 return FALSE;
2291 else if (info->type == MSG_CALLBACK)
2293 msg_data.callback.callback = info->callback;
2294 msg_data.callback.data = info->data;
2295 msg_data.callback.result = 0;
2296 data.data[0] = &msg_data;
2297 data.size[0] = sizeof(msg_data.callback);
2298 data.count = 1;
2300 else if (info->type == MSG_POSTED && info->msg >= WM_DDE_FIRST && info->msg <= WM_DDE_LAST)
2302 return post_dde_message( &data, info );
2305 SERVER_START_REQ( send_message )
2307 req->id = info->dest_tid;
2308 req->type = info->type;
2309 req->flags = 0;
2310 req->win = info->hwnd;
2311 req->msg = info->msg;
2312 req->wparam = info->wparam;
2313 req->lparam = info->lparam;
2314 req->timeout = timeout;
2316 if (info->flags & SMTO_ABORTIFHUNG) req->flags |= SEND_MSG_ABORT_IF_HUNG;
2317 for (i = 0; i < data.count; i++) wine_server_add_data( req, data.data[i], data.size[i] );
2318 if ((res = wine_server_call( req )))
2320 if (res == STATUS_INVALID_PARAMETER)
2321 /* FIXME: find a STATUS_ value for this one */
2322 SetLastError( ERROR_INVALID_THREAD_ID );
2323 else
2324 SetLastError( RtlNtStatusToDosError(res) );
2327 SERVER_END_REQ;
2328 return !res;
2332 /***********************************************************************
2333 * retrieve_reply
2335 * Retrieve a message reply from the server.
2337 static LRESULT retrieve_reply( const struct send_message_info *info,
2338 size_t reply_size, LRESULT *result )
2340 NTSTATUS status;
2341 void *reply_data = NULL;
2343 if (reply_size)
2345 if (!(reply_data = HeapAlloc( GetProcessHeap(), 0, reply_size )))
2347 WARN( "no memory for reply, will be truncated\n" );
2348 reply_size = 0;
2351 SERVER_START_REQ( get_message_reply )
2353 req->cancel = 1;
2354 if (reply_size) wine_server_set_reply( req, reply_data, reply_size );
2355 if (!(status = wine_server_call( req ))) *result = reply->result;
2356 reply_size = wine_server_reply_size( reply );
2358 SERVER_END_REQ;
2359 if (!status && reply_size)
2360 unpack_reply( info->hwnd, info->msg, info->wparam, info->lparam, reply_data, reply_size );
2362 HeapFree( GetProcessHeap(), 0, reply_data );
2364 TRACE( "hwnd %p msg %x (%s) wp %lx lp %lx got reply %lx (err=%d)\n",
2365 info->hwnd, info->msg, SPY_GetMsgName(info->msg, info->hwnd), info->wparam,
2366 info->lparam, *result, status );
2368 /* MSDN states that last error is 0 on timeout, but at least NT4 returns ERROR_TIMEOUT */
2369 if (status) SetLastError( RtlNtStatusToDosError(status) );
2370 return !status;
2374 /***********************************************************************
2375 * send_inter_thread_message
2377 static LRESULT send_inter_thread_message( const struct send_message_info *info, LRESULT *res_ptr )
2379 size_t reply_size = 0;
2381 TRACE( "hwnd %p msg %x (%s) wp %lx lp %lx\n",
2382 info->hwnd, info->msg, SPY_GetMsgName(info->msg, info->hwnd), info->wparam, info->lparam );
2384 USER_CheckNotLock();
2386 if (!put_message_in_queue( info, &reply_size )) return 0;
2388 /* there's no reply to wait for on notify/callback messages */
2389 if (info->type == MSG_NOTIFY || info->type == MSG_CALLBACK) return 1;
2391 wait_message_reply( info->flags );
2392 return retrieve_reply( info, reply_size, res_ptr );
2396 /***********************************************************************
2397 * send_inter_thread_callback
2399 static LRESULT send_inter_thread_callback( HWND hwnd, UINT msg, WPARAM wp, LPARAM lp,
2400 LRESULT *result, void *arg )
2402 struct send_message_info *info = arg;
2403 info->hwnd = hwnd;
2404 info->msg = msg;
2405 info->wparam = wp;
2406 info->lparam = lp;
2407 return send_inter_thread_message( info, result );
2411 /***********************************************************************
2412 * send_message
2414 * Backend implementation of the various SendMessage functions.
2416 static BOOL send_message( struct send_message_info *info, DWORD_PTR *res_ptr, BOOL unicode )
2418 DWORD dest_pid;
2419 BOOL ret;
2420 LRESULT result;
2422 if (is_broadcast(info->hwnd))
2424 EnumWindows( broadcast_message_callback, (LPARAM)info );
2425 if (res_ptr) *res_ptr = 1;
2426 return TRUE;
2429 if (!(info->dest_tid = GetWindowThreadProcessId( info->hwnd, &dest_pid ))) return FALSE;
2431 if (USER_IsExitingThread( info->dest_tid )) return FALSE;
2433 SPY_EnterMessage( SPY_SENDMESSAGE, info->hwnd, info->msg, info->wparam, info->lparam );
2435 if (info->dest_tid == GetCurrentThreadId())
2437 result = call_window_proc( info->hwnd, info->msg, info->wparam, info->lparam,
2438 unicode, TRUE, info->wm_char );
2439 if (info->type == MSG_CALLBACK)
2440 call_sendmsg_callback( info->callback, info->hwnd, info->msg, info->data, result );
2441 ret = TRUE;
2443 else
2445 if (dest_pid != GetCurrentProcessId() && (info->type == MSG_ASCII || info->type == MSG_UNICODE))
2446 info->type = MSG_OTHER_PROCESS;
2448 /* MSG_ASCII can be sent unconverted except for WM_CHAR; everything else needs to be Unicode */
2449 if (!unicode && is_unicode_message( info->msg ) &&
2450 (info->type != MSG_ASCII || info->msg == WM_CHAR))
2451 ret = WINPROC_CallProcAtoW( send_inter_thread_callback, info->hwnd, info->msg,
2452 info->wparam, info->lparam, &result, info, info->wm_char );
2453 else
2454 ret = send_inter_thread_message( info, &result );
2457 SPY_ExitMessage( SPY_RESULT_OK, info->hwnd, info->msg, result, info->wparam, info->lparam );
2458 if (ret && res_ptr) *res_ptr = result;
2459 return ret;
2463 /***********************************************************************
2464 * MSG_SendInternalMessageTimeout
2466 * Same as SendMessageTimeoutW but sends the message to a specific thread
2467 * without requiring a window handle. Only works for internal Wine messages.
2469 LRESULT MSG_SendInternalMessageTimeout( DWORD dest_pid, DWORD dest_tid,
2470 UINT msg, WPARAM wparam, LPARAM lparam,
2471 UINT flags, UINT timeout, PDWORD_PTR res_ptr )
2473 struct send_message_info info;
2474 LRESULT ret, result;
2476 assert( msg & 0x80000000 ); /* must be an internal Wine message */
2478 info.type = MSG_UNICODE;
2479 info.dest_tid = dest_tid;
2480 info.hwnd = 0;
2481 info.msg = msg;
2482 info.wparam = wparam;
2483 info.lparam = lparam;
2484 info.flags = flags;
2485 info.timeout = timeout;
2487 if (USER_IsExitingThread( dest_tid )) return 0;
2489 if (dest_tid == GetCurrentThreadId())
2491 result = handle_internal_message( 0, msg, wparam, lparam );
2492 ret = 1;
2494 else
2496 if (dest_pid != GetCurrentProcessId()) info.type = MSG_OTHER_PROCESS;
2497 ret = send_inter_thread_message( &info, &result );
2499 if (ret && res_ptr) *res_ptr = result;
2500 return ret;
2504 /***********************************************************************
2505 * SendMessageTimeoutW (USER32.@)
2507 LRESULT WINAPI SendMessageTimeoutW( HWND hwnd, UINT msg, WPARAM wparam, LPARAM lparam,
2508 UINT flags, UINT timeout, PDWORD_PTR res_ptr )
2510 struct send_message_info info;
2512 info.type = MSG_UNICODE;
2513 info.hwnd = hwnd;
2514 info.msg = msg;
2515 info.wparam = wparam;
2516 info.lparam = lparam;
2517 info.flags = flags;
2518 info.timeout = timeout;
2520 return send_message( &info, res_ptr, TRUE );
2523 /***********************************************************************
2524 * SendMessageTimeoutA (USER32.@)
2526 LRESULT WINAPI SendMessageTimeoutA( HWND hwnd, UINT msg, WPARAM wparam, LPARAM lparam,
2527 UINT flags, UINT timeout, PDWORD_PTR res_ptr )
2529 struct send_message_info info;
2531 info.type = MSG_ASCII;
2532 info.hwnd = hwnd;
2533 info.msg = msg;
2534 info.wparam = wparam;
2535 info.lparam = lparam;
2536 info.flags = flags;
2537 info.timeout = timeout;
2538 info.wm_char = WMCHAR_MAP_SENDMESSAGETIMEOUT;
2540 return send_message( &info, res_ptr, FALSE );
2544 /***********************************************************************
2545 * SendMessageW (USER32.@)
2547 LRESULT WINAPI SendMessageW( HWND hwnd, UINT msg, WPARAM wparam, LPARAM lparam )
2549 DWORD_PTR res = 0;
2550 struct send_message_info info;
2552 info.type = MSG_UNICODE;
2553 info.hwnd = hwnd;
2554 info.msg = msg;
2555 info.wparam = wparam;
2556 info.lparam = lparam;
2557 info.flags = SMTO_NORMAL;
2558 info.timeout = 0;
2560 send_message( &info, &res, TRUE );
2561 return res;
2565 /***********************************************************************
2566 * SendMessageA (USER32.@)
2568 LRESULT WINAPI SendMessageA( HWND hwnd, UINT msg, WPARAM wparam, LPARAM lparam )
2570 DWORD_PTR res = 0;
2571 struct send_message_info info;
2573 info.type = MSG_ASCII;
2574 info.hwnd = hwnd;
2575 info.msg = msg;
2576 info.wparam = wparam;
2577 info.lparam = lparam;
2578 info.flags = SMTO_NORMAL;
2579 info.timeout = 0;
2580 info.wm_char = WMCHAR_MAP_SENDMESSAGE;
2582 send_message( &info, &res, FALSE );
2583 return res;
2587 /***********************************************************************
2588 * SendNotifyMessageA (USER32.@)
2590 BOOL WINAPI SendNotifyMessageA( HWND hwnd, UINT msg, WPARAM wparam, LPARAM lparam )
2592 struct send_message_info info;
2594 if (is_pointer_message(msg))
2596 SetLastError( ERROR_MESSAGE_SYNC_ONLY );
2597 return FALSE;
2600 info.type = MSG_NOTIFY;
2601 info.hwnd = hwnd;
2602 info.msg = msg;
2603 info.wparam = wparam;
2604 info.lparam = lparam;
2605 info.flags = 0;
2606 info.wm_char = WMCHAR_MAP_SENDMESSAGETIMEOUT;
2608 return send_message( &info, NULL, FALSE );
2612 /***********************************************************************
2613 * SendNotifyMessageW (USER32.@)
2615 BOOL WINAPI SendNotifyMessageW( HWND hwnd, UINT msg, WPARAM wparam, LPARAM lparam )
2617 struct send_message_info info;
2619 if (is_pointer_message(msg))
2621 SetLastError( ERROR_MESSAGE_SYNC_ONLY );
2622 return FALSE;
2625 info.type = MSG_NOTIFY;
2626 info.hwnd = hwnd;
2627 info.msg = msg;
2628 info.wparam = wparam;
2629 info.lparam = lparam;
2630 info.flags = 0;
2632 return send_message( &info, NULL, TRUE );
2636 /***********************************************************************
2637 * SendMessageCallbackA (USER32.@)
2639 BOOL WINAPI SendMessageCallbackA( HWND hwnd, UINT msg, WPARAM wparam, LPARAM lparam,
2640 SENDASYNCPROC callback, ULONG_PTR data )
2642 struct send_message_info info;
2644 if (is_pointer_message(msg))
2646 SetLastError( ERROR_MESSAGE_SYNC_ONLY );
2647 return FALSE;
2650 info.type = MSG_CALLBACK;
2651 info.hwnd = hwnd;
2652 info.msg = msg;
2653 info.wparam = wparam;
2654 info.lparam = lparam;
2655 info.callback = callback;
2656 info.data = data;
2657 info.flags = 0;
2658 info.wm_char = WMCHAR_MAP_SENDMESSAGETIMEOUT;
2660 return send_message( &info, NULL, FALSE );
2664 /***********************************************************************
2665 * SendMessageCallbackW (USER32.@)
2667 BOOL WINAPI SendMessageCallbackW( HWND hwnd, UINT msg, WPARAM wparam, LPARAM lparam,
2668 SENDASYNCPROC callback, ULONG_PTR data )
2670 struct send_message_info info;
2672 if (is_pointer_message(msg))
2674 SetLastError( ERROR_MESSAGE_SYNC_ONLY );
2675 return FALSE;
2678 info.type = MSG_CALLBACK;
2679 info.hwnd = hwnd;
2680 info.msg = msg;
2681 info.wparam = wparam;
2682 info.lparam = lparam;
2683 info.callback = callback;
2684 info.data = data;
2685 info.flags = 0;
2687 return send_message( &info, NULL, TRUE );
2691 /***********************************************************************
2692 * ReplyMessage (USER32.@)
2694 BOOL WINAPI ReplyMessage( LRESULT result )
2696 struct received_message_info *info = get_user_thread_info()->receive_info;
2698 if (!info) return FALSE;
2699 reply_message( info, result, FALSE );
2700 return TRUE;
2704 /***********************************************************************
2705 * InSendMessage (USER32.@)
2707 BOOL WINAPI InSendMessage(void)
2709 return (InSendMessageEx(NULL) & (ISMEX_SEND|ISMEX_REPLIED)) == ISMEX_SEND;
2713 /***********************************************************************
2714 * InSendMessageEx (USER32.@)
2716 DWORD WINAPI InSendMessageEx( LPVOID reserved )
2718 struct received_message_info *info = get_user_thread_info()->receive_info;
2720 if (info) return info->flags;
2721 return ISMEX_NOSEND;
2725 /***********************************************************************
2726 * PostMessageA (USER32.@)
2728 BOOL WINAPI PostMessageA( HWND hwnd, UINT msg, WPARAM wparam, LPARAM lparam )
2730 if (!map_wparam_AtoW( msg, &wparam, WMCHAR_MAP_POSTMESSAGE )) return TRUE;
2731 return PostMessageW( hwnd, msg, wparam, lparam );
2735 /***********************************************************************
2736 * PostMessageW (USER32.@)
2738 BOOL WINAPI PostMessageW( HWND hwnd, UINT msg, WPARAM wparam, LPARAM lparam )
2740 struct send_message_info info;
2742 if (is_pointer_message( msg ))
2744 SetLastError( ERROR_MESSAGE_SYNC_ONLY );
2745 return FALSE;
2748 TRACE( "hwnd %p msg %x (%s) wp %lx lp %lx\n",
2749 hwnd, msg, SPY_GetMsgName(msg, hwnd), wparam, lparam );
2751 info.type = MSG_POSTED;
2752 info.hwnd = hwnd;
2753 info.msg = msg;
2754 info.wparam = wparam;
2755 info.lparam = lparam;
2756 info.flags = 0;
2758 if (is_broadcast(hwnd))
2760 EnumWindows( broadcast_message_callback, (LPARAM)&info );
2761 return TRUE;
2764 if (!hwnd) return PostThreadMessageW( GetCurrentThreadId(), msg, wparam, lparam );
2766 if (!(info.dest_tid = GetWindowThreadProcessId( hwnd, NULL ))) return FALSE;
2768 if (USER_IsExitingThread( info.dest_tid )) return TRUE;
2770 return put_message_in_queue( &info, NULL );
2774 /**********************************************************************
2775 * PostThreadMessageA (USER32.@)
2777 BOOL WINAPI PostThreadMessageA( DWORD thread, UINT msg, WPARAM wparam, LPARAM lparam )
2779 if (!map_wparam_AtoW( msg, &wparam, WMCHAR_MAP_POSTMESSAGE )) return TRUE;
2780 return PostThreadMessageW( thread, msg, wparam, lparam );
2784 /**********************************************************************
2785 * PostThreadMessageW (USER32.@)
2787 BOOL WINAPI PostThreadMessageW( DWORD thread, UINT msg, WPARAM wparam, LPARAM lparam )
2789 struct send_message_info info;
2791 if (is_pointer_message( msg ))
2793 SetLastError( ERROR_MESSAGE_SYNC_ONLY );
2794 return FALSE;
2796 if (USER_IsExitingThread( thread )) return TRUE;
2798 info.type = MSG_POSTED;
2799 info.dest_tid = thread;
2800 info.hwnd = 0;
2801 info.msg = msg;
2802 info.wparam = wparam;
2803 info.lparam = lparam;
2804 info.flags = 0;
2805 return put_message_in_queue( &info, NULL );
2809 /***********************************************************************
2810 * PostQuitMessage (USER32.@)
2812 * Posts a quit message to the current thread's message queue.
2814 * PARAMS
2815 * exit_code [I] Exit code to return from message loop.
2817 * RETURNS
2818 * Nothing.
2820 * NOTES
2821 * This function is not the same as calling:
2822 *|PostThreadMessage(GetCurrentThreadId(), WM_QUIT, exit_code, 0);
2823 * It instead sets a flag in the message queue that signals it to generate
2824 * a WM_QUIT message when there are no other pending sent or posted messages
2825 * in the queue.
2827 void WINAPI PostQuitMessage( INT exit_code )
2829 SERVER_START_REQ( post_quit_message )
2831 req->exit_code = exit_code;
2832 wine_server_call( req );
2834 SERVER_END_REQ;
2838 /***********************************************************************
2839 * PeekMessageW (USER32.@)
2841 BOOL WINAPI PeekMessageW( MSG *msg_out, HWND hwnd, UINT first, UINT last, UINT flags )
2843 struct user_thread_info *thread_info = get_user_thread_info();
2844 MSG msg;
2846 USER_CheckNotLock();
2848 /* check for graphics events */
2849 USER_Driver->pMsgWaitForMultipleObjectsEx( 0, NULL, 0, QS_ALLINPUT, 0 );
2851 hwnd = WIN_GetFullHandle( hwnd );
2853 for (;;)
2855 if (!peek_message( &msg, hwnd, first, last, flags ))
2857 if (!(flags & PM_NOYIELD))
2859 DWORD count;
2860 ReleaseThunkLock(&count);
2861 NtYieldExecution();
2862 if (count) RestoreThunkLock(count);
2864 return FALSE;
2866 if (msg.message & 0x80000000)
2868 if (!(flags & PM_REMOVE))
2870 /* Have to remove the message explicitly.
2871 Do this before handling it, because the message handler may
2872 call PeekMessage again */
2873 peek_message( &msg, msg.hwnd, msg.message, msg.message, flags | PM_REMOVE );
2875 handle_internal_message( msg.hwnd, msg.message, msg.wParam, msg.lParam );
2877 else break;
2880 thread_info->GetMessageTimeVal = msg.time;
2881 msg.pt.x = (short)LOWORD( thread_info->GetMessagePosVal );
2882 msg.pt.y = (short)HIWORD( thread_info->GetMessagePosVal );
2884 HOOK_CallHooks( WH_GETMESSAGE, HC_ACTION, flags & PM_REMOVE, (LPARAM)&msg, TRUE );
2886 /* copy back our internal safe copy of message data to msg_out.
2887 * msg_out is a variable from the *program*, so it can't be used
2888 * internally as it can get "corrupted" by our use of SendMessage()
2889 * (back to the program) inside the message handling itself. */
2890 if (!msg_out)
2892 SetLastError( ERROR_NOACCESS );
2893 return FALSE;
2895 *msg_out = msg;
2896 return TRUE;
2900 /***********************************************************************
2901 * PeekMessageA (USER32.@)
2903 BOOL WINAPI PeekMessageA( MSG *msg, HWND hwnd, UINT first, UINT last, UINT flags )
2905 if (get_pending_wmchar( msg, first, last, (flags & PM_REMOVE) )) return TRUE;
2906 if (!PeekMessageW( msg, hwnd, first, last, flags )) return FALSE;
2907 map_wparam_WtoA( msg, (flags & PM_REMOVE) );
2908 return TRUE;
2912 /***********************************************************************
2913 * GetMessageW (USER32.@)
2915 BOOL WINAPI GetMessageW( MSG *msg, HWND hwnd, UINT first, UINT last )
2917 HANDLE server_queue = get_server_queue_handle();
2918 int mask = QS_POSTMESSAGE | QS_SENDMESSAGE; /* Always selected */
2920 if (first || last)
2922 if ((first <= WM_KEYLAST) && (last >= WM_KEYFIRST)) mask |= QS_KEY;
2923 if ( ((first <= WM_MOUSELAST) && (last >= WM_MOUSEFIRST)) ||
2924 ((first <= WM_NCMOUSELAST) && (last >= WM_NCMOUSEFIRST)) ) mask |= QS_MOUSE;
2925 if ((first <= WM_TIMER) && (last >= WM_TIMER)) mask |= QS_TIMER;
2926 if ((first <= WM_SYSTIMER) && (last >= WM_SYSTIMER)) mask |= QS_TIMER;
2927 if ((first <= WM_PAINT) && (last >= WM_PAINT)) mask |= QS_PAINT;
2929 else mask = QS_ALLINPUT;
2931 while (!PeekMessageW( msg, hwnd, first, last, PM_REMOVE | PM_NOYIELD | (mask << 16) ))
2933 DWORD dwlc;
2935 ReleaseThunkLock( &dwlc );
2936 USER_Driver->pMsgWaitForMultipleObjectsEx( 1, &server_queue, INFINITE, mask, 0 );
2937 if (dwlc) RestoreThunkLock( dwlc );
2940 return (msg->message != WM_QUIT);
2944 /***********************************************************************
2945 * GetMessageA (USER32.@)
2947 BOOL WINAPI GetMessageA( MSG *msg, HWND hwnd, UINT first, UINT last )
2949 if (get_pending_wmchar( msg, first, last, TRUE )) return TRUE;
2950 GetMessageW( msg, hwnd, first, last );
2951 map_wparam_WtoA( msg, TRUE );
2952 return (msg->message != WM_QUIT);
2956 /***********************************************************************
2957 * IsDialogMessageA (USER32.@)
2958 * IsDialogMessage (USER32.@)
2960 BOOL WINAPI IsDialogMessageA( HWND hwndDlg, LPMSG pmsg )
2962 MSG msg = *pmsg;
2963 map_wparam_AtoW( msg.message, &msg.wParam, WMCHAR_MAP_NOMAPPING );
2964 return IsDialogMessageW( hwndDlg, &msg );
2968 /***********************************************************************
2969 * TranslateMessage (USER32.@)
2971 * Implementation of TranslateMessage.
2973 * TranslateMessage translates virtual-key messages into character-messages,
2974 * as follows :
2975 * WM_KEYDOWN/WM_KEYUP combinations produce a WM_CHAR or WM_DEADCHAR message.
2976 * ditto replacing WM_* with WM_SYS*
2977 * This produces WM_CHAR messages only for keys mapped to ASCII characters
2978 * by the keyboard driver.
2980 * If the message is WM_KEYDOWN, WM_KEYUP, WM_SYSKEYDOWN, or WM_SYSKEYUP, the
2981 * return value is nonzero, regardless of the translation.
2984 BOOL WINAPI TranslateMessage( const MSG *msg )
2986 UINT message;
2987 WCHAR wp[2];
2988 BYTE state[256];
2990 if (msg->message < WM_KEYFIRST || msg->message > WM_KEYLAST) return FALSE;
2991 if (msg->message != WM_KEYDOWN && msg->message != WM_SYSKEYDOWN) return TRUE;
2993 TRACE_(key)("Translating key %s (%04lx), scancode %02x\n",
2994 SPY_GetVKeyName(msg->wParam), msg->wParam, LOBYTE(HIWORD(msg->lParam)));
2996 GetKeyboardState( state );
2997 /* FIXME : should handle ToUnicode yielding 2 */
2998 switch (ToUnicode(msg->wParam, HIWORD(msg->lParam), state, wp, 2, 0))
3000 case 1:
3001 message = (msg->message == WM_KEYDOWN) ? WM_CHAR : WM_SYSCHAR;
3002 TRACE_(key)("1 -> PostMessageW(%p,%s,%04x,%08lx)\n",
3003 msg->hwnd, SPY_GetMsgName(message, msg->hwnd), wp[0], msg->lParam);
3004 PostMessageW( msg->hwnd, message, wp[0], msg->lParam );
3005 break;
3007 case -1:
3008 message = (msg->message == WM_KEYDOWN) ? WM_DEADCHAR : WM_SYSDEADCHAR;
3009 TRACE_(key)("-1 -> PostMessageW(%p,%s,%04x,%08lx)\n",
3010 msg->hwnd, SPY_GetMsgName(message, msg->hwnd), wp[0], msg->lParam);
3011 PostMessageW( msg->hwnd, message, wp[0], msg->lParam );
3012 break;
3014 return TRUE;
3018 /***********************************************************************
3019 * DispatchMessageA (USER32.@)
3021 * See DispatchMessageW.
3023 LRESULT WINAPI DispatchMessageA( const MSG* msg )
3025 LRESULT retval;
3027 /* Process timer messages */
3028 if ((msg->message == WM_TIMER) || (msg->message == WM_SYSTIMER))
3030 if (msg->lParam) return CallWindowProcA( (WNDPROC)msg->lParam, msg->hwnd,
3031 msg->message, msg->wParam, GetTickCount() );
3033 if (!msg->hwnd) return 0;
3035 SPY_EnterMessage( SPY_DISPATCHMESSAGE, msg->hwnd, msg->message,
3036 msg->wParam, msg->lParam );
3038 if (!WINPROC_call_window( msg->hwnd, msg->message, msg->wParam, msg->lParam,
3039 &retval, FALSE, WMCHAR_MAP_DISPATCHMESSAGE ))
3041 if (!IsWindow( msg->hwnd )) SetLastError( ERROR_INVALID_WINDOW_HANDLE );
3042 else SetLastError( ERROR_MESSAGE_SYNC_ONLY );
3043 retval = 0;
3046 SPY_ExitMessage( SPY_RESULT_OK, msg->hwnd, msg->message, retval,
3047 msg->wParam, msg->lParam );
3049 if (msg->message == WM_PAINT)
3051 /* send a WM_NCPAINT and WM_ERASEBKGND if the non-client area is still invalid */
3052 HRGN hrgn = CreateRectRgn( 0, 0, 0, 0 );
3053 GetUpdateRgn( msg->hwnd, hrgn, TRUE );
3054 DeleteObject( hrgn );
3056 return retval;
3060 /***********************************************************************
3061 * DispatchMessageW (USER32.@) Process a message
3063 * Process the message specified in the structure *_msg_.
3065 * If the lpMsg parameter points to a WM_TIMER message and the
3066 * parameter of the WM_TIMER message is not NULL, the lParam parameter
3067 * points to the function that is called instead of the window
3068 * procedure.
3070 * The message must be valid.
3072 * RETURNS
3074 * DispatchMessage() returns the result of the window procedure invoked.
3076 * CONFORMANCE
3078 * ECMA-234, Win32
3081 LRESULT WINAPI DispatchMessageW( const MSG* msg )
3083 LRESULT retval;
3085 /* Process timer messages */
3086 if ((msg->message == WM_TIMER) || (msg->message == WM_SYSTIMER))
3088 if (msg->lParam) return CallWindowProcW( (WNDPROC)msg->lParam, msg->hwnd,
3089 msg->message, msg->wParam, GetTickCount() );
3091 if (!msg->hwnd) return 0;
3093 SPY_EnterMessage( SPY_DISPATCHMESSAGE, msg->hwnd, msg->message,
3094 msg->wParam, msg->lParam );
3096 if (!WINPROC_call_window( msg->hwnd, msg->message, msg->wParam, msg->lParam,
3097 &retval, TRUE, WMCHAR_MAP_DISPATCHMESSAGE ))
3099 if (!IsWindow( msg->hwnd )) SetLastError( ERROR_INVALID_WINDOW_HANDLE );
3100 else SetLastError( ERROR_MESSAGE_SYNC_ONLY );
3101 retval = 0;
3104 SPY_ExitMessage( SPY_RESULT_OK, msg->hwnd, msg->message, retval,
3105 msg->wParam, msg->lParam );
3107 if (msg->message == WM_PAINT)
3109 /* send a WM_NCPAINT and WM_ERASEBKGND if the non-client area is still invalid */
3110 HRGN hrgn = CreateRectRgn( 0, 0, 0, 0 );
3111 GetUpdateRgn( msg->hwnd, hrgn, TRUE );
3112 DeleteObject( hrgn );
3114 return retval;
3118 /***********************************************************************
3119 * GetMessagePos (USER.119)
3120 * GetMessagePos (USER32.@)
3122 * The GetMessagePos() function returns a long value representing a
3123 * cursor position, in screen coordinates, when the last message
3124 * retrieved by the GetMessage() function occurs. The x-coordinate is
3125 * in the low-order word of the return value, the y-coordinate is in
3126 * the high-order word. The application can use the MAKEPOINT()
3127 * macro to obtain a POINT structure from the return value.
3129 * For the current cursor position, use GetCursorPos().
3131 * RETURNS
3133 * Cursor position of last message on success, zero on failure.
3135 * CONFORMANCE
3137 * ECMA-234, Win32
3140 DWORD WINAPI GetMessagePos(void)
3142 return get_user_thread_info()->GetMessagePosVal;
3146 /***********************************************************************
3147 * GetMessageTime (USER.120)
3148 * GetMessageTime (USER32.@)
3150 * GetMessageTime() returns the message time for the last message
3151 * retrieved by the function. The time is measured in milliseconds with
3152 * the same offset as GetTickCount().
3154 * Since the tick count wraps, this is only useful for moderately short
3155 * relative time comparisons.
3157 * RETURNS
3159 * Time of last message on success, zero on failure.
3161 LONG WINAPI GetMessageTime(void)
3163 return get_user_thread_info()->GetMessageTimeVal;
3167 /***********************************************************************
3168 * GetMessageExtraInfo (USER.288)
3169 * GetMessageExtraInfo (USER32.@)
3171 LPARAM WINAPI GetMessageExtraInfo(void)
3173 return get_user_thread_info()->GetMessageExtraInfoVal;
3177 /***********************************************************************
3178 * SetMessageExtraInfo (USER32.@)
3180 LPARAM WINAPI SetMessageExtraInfo(LPARAM lParam)
3182 struct user_thread_info *thread_info = get_user_thread_info();
3183 LONG old_value = thread_info->GetMessageExtraInfoVal;
3184 thread_info->GetMessageExtraInfoVal = lParam;
3185 return old_value;
3189 /***********************************************************************
3190 * WaitMessage (USER.112) Suspend thread pending messages
3191 * WaitMessage (USER32.@) Suspend thread pending messages
3193 * WaitMessage() suspends a thread until events appear in the thread's
3194 * queue.
3196 BOOL WINAPI WaitMessage(void)
3198 return (MsgWaitForMultipleObjectsEx( 0, NULL, INFINITE, QS_ALLINPUT, 0 ) != WAIT_FAILED);
3202 /***********************************************************************
3203 * MsgWaitForMultipleObjectsEx (USER32.@)
3205 DWORD WINAPI MsgWaitForMultipleObjectsEx( DWORD count, CONST HANDLE *pHandles,
3206 DWORD timeout, DWORD mask, DWORD flags )
3208 HANDLE handles[MAXIMUM_WAIT_OBJECTS];
3209 DWORD i, ret, lock;
3211 if (count > MAXIMUM_WAIT_OBJECTS-1)
3213 SetLastError( ERROR_INVALID_PARAMETER );
3214 return WAIT_FAILED;
3217 /* set the queue mask */
3218 SERVER_START_REQ( set_queue_mask )
3220 req->wake_mask = (flags & MWMO_INPUTAVAILABLE) ? mask : 0;
3221 req->changed_mask = mask;
3222 req->skip_wait = 0;
3223 wine_server_call( req );
3225 SERVER_END_REQ;
3227 /* add the queue to the handle list */
3228 for (i = 0; i < count; i++) handles[i] = pHandles[i];
3229 handles[count] = get_server_queue_handle();
3231 ReleaseThunkLock( &lock );
3232 ret = USER_Driver->pMsgWaitForMultipleObjectsEx( count+1, handles, timeout, mask, flags );
3233 if (lock) RestoreThunkLock( lock );
3234 return ret;
3238 /***********************************************************************
3239 * MsgWaitForMultipleObjects (USER32.@)
3241 DWORD WINAPI MsgWaitForMultipleObjects( DWORD count, CONST HANDLE *handles,
3242 BOOL wait_all, DWORD timeout, DWORD mask )
3244 return MsgWaitForMultipleObjectsEx( count, handles, timeout, mask,
3245 wait_all ? MWMO_WAITALL : 0 );
3249 /***********************************************************************
3250 * WaitForInputIdle (USER32.@)
3252 DWORD WINAPI WaitForInputIdle( HANDLE hProcess, DWORD dwTimeOut )
3254 DWORD start_time, elapsed, ret;
3255 HANDLE handles[2];
3257 handles[0] = hProcess;
3258 SERVER_START_REQ( get_process_idle_event )
3260 req->handle = hProcess;
3261 if (!(ret = wine_server_call_err( req ))) handles[1] = reply->event;
3263 SERVER_END_REQ;
3264 if (ret) return WAIT_FAILED; /* error */
3265 if (!handles[1]) return 0; /* no event to wait on */
3267 start_time = GetTickCount();
3268 elapsed = 0;
3270 TRACE("waiting for %p\n", handles[1] );
3273 ret = MsgWaitForMultipleObjects ( 2, handles, FALSE, dwTimeOut - elapsed, QS_SENDMESSAGE );
3274 switch (ret)
3276 case WAIT_OBJECT_0:
3277 return WAIT_FAILED;
3278 case WAIT_OBJECT_0+2:
3279 process_sent_messages();
3280 break;
3281 case WAIT_TIMEOUT:
3282 case WAIT_FAILED:
3283 TRACE("timeout or error\n");
3284 return ret;
3285 default:
3286 TRACE("finished\n");
3287 return 0;
3289 if (dwTimeOut != INFINITE)
3291 elapsed = GetTickCount() - start_time;
3292 if (elapsed > dwTimeOut)
3293 break;
3296 while (1);
3298 return WAIT_TIMEOUT;
3302 /***********************************************************************
3303 * UserYield (USER.332)
3305 void WINAPI UserYield16(void)
3307 DWORD count;
3309 /* Handle sent messages */
3310 process_sent_messages();
3312 /* Yield */
3313 ReleaseThunkLock(&count);
3315 if (count)
3317 RestoreThunkLock(count);
3318 /* Handle sent messages again */
3319 process_sent_messages();
3324 /***********************************************************************
3325 * RegisterWindowMessageA (USER32.@)
3326 * RegisterWindowMessage (USER.118)
3328 UINT WINAPI RegisterWindowMessageA( LPCSTR str )
3330 UINT ret = GlobalAddAtomA(str);
3331 TRACE("%s, ret=%x\n", str, ret);
3332 return ret;
3336 /***********************************************************************
3337 * RegisterWindowMessageW (USER32.@)
3339 UINT WINAPI RegisterWindowMessageW( LPCWSTR str )
3341 UINT ret = GlobalAddAtomW(str);
3342 TRACE("%s ret=%x\n", debugstr_w(str), ret);
3343 return ret;
3347 /***********************************************************************
3348 * BroadcastSystemMessageA (USER32.@)
3349 * BroadcastSystemMessage (USER32.@)
3351 LONG WINAPI BroadcastSystemMessageA( DWORD flags, LPDWORD recipients, UINT msg, WPARAM wp, LPARAM lp )
3353 if ((*recipients & BSM_APPLICATIONS) || (*recipients == BSM_ALLCOMPONENTS))
3355 FIXME( "(%08x,%08x,%08x,%08lx,%08lx): semi-stub!\n", flags, *recipients, msg, wp, lp );
3356 PostMessageA( HWND_BROADCAST, msg, wp, lp );
3357 return 1;
3359 else
3361 FIXME( "(%08x,%08x,%08x,%08lx,%08lx): stub!\n", flags, *recipients, msg, wp, lp);
3362 return -1;
3367 /***********************************************************************
3368 * BroadcastSystemMessageW (USER32.@)
3370 LONG WINAPI BroadcastSystemMessageW( DWORD flags, LPDWORD recipients, UINT msg, WPARAM wp, LPARAM lp )
3372 if ((*recipients & BSM_APPLICATIONS) || (*recipients == BSM_ALLCOMPONENTS))
3374 FIXME( "(%08x,%08x,%08x,%08lx,%08lx): semi-stub!\n", flags, *recipients, msg, wp, lp );
3375 PostMessageW( HWND_BROADCAST, msg, wp, lp );
3376 return 1;
3378 else
3380 FIXME( "(%08x,%08x,%08x,%08lx,%08lx): stub!\n", flags, *recipients, msg, wp, lp );
3381 return -1;
3386 /***********************************************************************
3387 * SetMessageQueue (USER32.@)
3389 BOOL WINAPI SetMessageQueue( INT size )
3391 /* now obsolete the message queue will be expanded dynamically as necessary */
3392 return TRUE;
3396 /***********************************************************************
3397 * MessageBeep (USER32.@)
3399 BOOL WINAPI MessageBeep( UINT i )
3401 BOOL active = TRUE;
3402 SystemParametersInfoA( SPI_GETBEEP, 0, &active, FALSE );
3403 if (active) USER_Driver->pBeep();
3404 return TRUE;
3408 /***********************************************************************
3409 * SetTimer (USER32.@)
3411 UINT_PTR WINAPI SetTimer( HWND hwnd, UINT_PTR id, UINT timeout, TIMERPROC proc )
3413 UINT_PTR ret;
3414 WNDPROC winproc = 0;
3416 if (proc) winproc = WINPROC_AllocProc( (WNDPROC)proc, NULL );
3418 SERVER_START_REQ( set_win_timer )
3420 req->win = hwnd;
3421 req->msg = WM_TIMER;
3422 req->id = id;
3423 req->rate = max( timeout, SYS_TIMER_RATE );
3424 req->lparam = (unsigned long)winproc;
3425 if (!wine_server_call_err( req ))
3427 ret = reply->id;
3428 if (!ret) ret = TRUE;
3430 else ret = 0;
3432 SERVER_END_REQ;
3434 TRACE("Added %p %lx %p timeout %d\n", hwnd, id, winproc, timeout );
3435 return ret;
3439 /***********************************************************************
3440 * SetSystemTimer (USER32.@)
3442 UINT_PTR WINAPI SetSystemTimer( HWND hwnd, UINT_PTR id, UINT timeout, TIMERPROC proc )
3444 UINT_PTR ret;
3445 WNDPROC winproc = 0;
3447 if (proc) winproc = WINPROC_AllocProc( (WNDPROC)proc, NULL );
3449 SERVER_START_REQ( set_win_timer )
3451 req->win = hwnd;
3452 req->msg = WM_SYSTIMER;
3453 req->id = id;
3454 req->rate = max( timeout, SYS_TIMER_RATE );
3455 req->lparam = (unsigned long)winproc;
3456 if (!wine_server_call_err( req ))
3458 ret = reply->id;
3459 if (!ret) ret = TRUE;
3461 else ret = 0;
3463 SERVER_END_REQ;
3465 TRACE("Added %p %lx %p timeout %d\n", hwnd, id, winproc, timeout );
3466 return ret;
3470 /***********************************************************************
3471 * KillTimer (USER32.@)
3473 BOOL WINAPI KillTimer( HWND hwnd, UINT_PTR id )
3475 BOOL ret;
3477 SERVER_START_REQ( kill_win_timer )
3479 req->win = hwnd;
3480 req->msg = WM_TIMER;
3481 req->id = id;
3482 ret = !wine_server_call_err( req );
3484 SERVER_END_REQ;
3485 return ret;
3489 /***********************************************************************
3490 * KillSystemTimer (USER32.@)
3492 BOOL WINAPI KillSystemTimer( HWND hwnd, UINT_PTR id )
3494 BOOL ret;
3496 SERVER_START_REQ( kill_win_timer )
3498 req->win = hwnd;
3499 req->msg = WM_SYSTIMER;
3500 req->id = id;
3501 ret = !wine_server_call_err( req );
3503 SERVER_END_REQ;
3504 return ret;
3508 /**********************************************************************
3509 * GetGUIThreadInfo (USER32.@)
3511 BOOL WINAPI GetGUIThreadInfo( DWORD id, GUITHREADINFO *info )
3513 BOOL ret;
3515 SERVER_START_REQ( get_thread_input )
3517 req->tid = id;
3518 if ((ret = !wine_server_call_err( req )))
3520 info->flags = 0;
3521 info->hwndActive = reply->active;
3522 info->hwndFocus = reply->focus;
3523 info->hwndCapture = reply->capture;
3524 info->hwndMenuOwner = reply->menu_owner;
3525 info->hwndMoveSize = reply->move_size;
3526 info->hwndCaret = reply->caret;
3527 info->rcCaret.left = reply->rect.left;
3528 info->rcCaret.top = reply->rect.top;
3529 info->rcCaret.right = reply->rect.right;
3530 info->rcCaret.bottom = reply->rect.bottom;
3531 if (reply->menu_owner) info->flags |= GUI_INMENUMODE;
3532 if (reply->move_size) info->flags |= GUI_INMOVESIZE;
3533 if (reply->caret) info->flags |= GUI_CARETBLINKING;
3536 SERVER_END_REQ;
3537 return ret;
3541 /******************************************************************
3542 * IsHungAppWindow (USER32.@)
3545 BOOL WINAPI IsHungAppWindow( HWND hWnd )
3547 BOOL ret;
3549 SERVER_START_REQ( is_window_hung )
3551 req->win = hWnd;
3552 ret = !wine_server_call_err( req ) && reply->is_hung;
3554 SERVER_END_REQ;
3555 return ret;