Assorted spelling fixes.
[wine/wine-kai.git] / dlls / user / message.c
blob6f7d3d1487d56a7d877cb0911970564ae4e9a3a3
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., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
21 #include "config.h"
22 #include "wine/port.h"
24 #include <assert.h>
25 #include <stdarg.h>
27 #include "ntstatus.h"
28 #include "windef.h"
29 #include "winbase.h"
30 #include "wingdi.h"
31 #include "winuser.h"
32 #include "winerror.h"
33 #include "winnls.h"
34 #include "dde.h"
35 #include "wine/unicode.h"
36 #include "wine/server.h"
37 #include "user_private.h"
38 #include "win.h"
39 #include "winpos.h"
40 #include "controls.h"
41 #include "winproc.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 */
70 HWINEVENTHOOK hook; /* winevent hook handle */
71 WINEVENTPROC hook_proc; /* winevent hook proc address */
74 /* structure to group all parameters for sent messages of the various kinds */
75 struct send_message_info
77 enum message_type type;
78 HWND hwnd;
79 UINT msg;
80 WPARAM wparam;
81 LPARAM lparam;
82 UINT flags; /* flags for SendMessageTimeout */
83 UINT timeout; /* timeout for SendMessageTimeout */
84 SENDASYNCPROC callback; /* callback function for SendMessageCallback */
85 ULONG_PTR data; /* callback data */
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 inline static 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 inline static 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 inline static 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 inline static 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 inline static 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 inline static 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 inline static 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 /* retrieve a string pointer from packed data */
277 inline static LPWSTR get_string( void **buffer )
279 return get_data( buffer, (strlenW( (LPWSTR)*buffer ) + 1) * sizeof(WCHAR) );
282 /* check whether a combobox expects strings or ids in CB_ADDSTRING/CB_INSERTSTRING */
283 inline static BOOL combobox_has_strings( HWND hwnd )
285 DWORD style = GetWindowLongA( hwnd, GWL_STYLE );
286 return (!(style & (CBS_OWNERDRAWFIXED | CBS_OWNERDRAWVARIABLE)) || (style & CBS_HASSTRINGS));
289 /* check whether a listbox expects strings or ids in LB_ADDSTRING/LB_INSERTSTRING */
290 inline static BOOL listbox_has_strings( HWND hwnd )
292 DWORD style = GetWindowLongA( hwnd, GWL_STYLE );
293 return (!(style & (LBS_OWNERDRAWFIXED | LBS_OWNERDRAWVARIABLE)) || (style & LBS_HASSTRINGS));
296 /* check whether message is in the range of keyboard messages */
297 inline static BOOL is_keyboard_message( UINT message )
299 return (message >= WM_KEYFIRST && message <= WM_KEYLAST);
302 /* check whether message is in the range of mouse messages */
303 inline static BOOL is_mouse_message( UINT message )
305 return ((message >= WM_NCMOUSEFIRST && message <= WM_NCMOUSELAST) ||
306 (message >= WM_MOUSEFIRST && message <= WM_MOUSELAST));
309 /* check whether message matches the specified hwnd filter */
310 inline static BOOL check_hwnd_filter( const MSG *msg, HWND hwnd_filter )
312 if (!hwnd_filter) return TRUE;
313 return (msg->hwnd == hwnd_filter || IsChild( hwnd_filter, msg->hwnd ));
317 /***********************************************************************
318 * broadcast_message_callback
320 * Helper callback for broadcasting messages.
322 static BOOL CALLBACK broadcast_message_callback( HWND hwnd, LPARAM lparam )
324 struct send_message_info *info = (struct send_message_info *)lparam;
325 if (!(GetWindowLongW( hwnd, GWL_STYLE ) & (WS_POPUP|WS_CAPTION))) return TRUE;
326 switch(info->type)
328 case MSG_UNICODE:
329 SendMessageTimeoutW( hwnd, info->msg, info->wparam, info->lparam,
330 info->flags, info->timeout, NULL );
331 break;
332 case MSG_ASCII:
333 SendMessageTimeoutA( hwnd, info->msg, info->wparam, info->lparam,
334 info->flags, info->timeout, NULL );
335 break;
336 case MSG_NOTIFY:
337 SendNotifyMessageW( hwnd, info->msg, info->wparam, info->lparam );
338 break;
339 case MSG_CALLBACK:
340 SendMessageCallbackW( hwnd, info->msg, info->wparam, info->lparam,
341 info->callback, info->data );
342 break;
343 case MSG_POSTED:
344 PostMessageW( hwnd, info->msg, info->wparam, info->lparam );
345 break;
346 default:
347 ERR( "bad type %d\n", info->type );
348 break;
350 return TRUE;
354 /***********************************************************************
355 * map_wparam_AtoW
357 * Convert the wparam of an ASCII message to Unicode.
359 static WPARAM map_wparam_AtoW( UINT message, WPARAM wparam )
361 switch(message)
363 case WM_CHARTOITEM:
364 case EM_SETPASSWORDCHAR:
365 case WM_CHAR:
366 case WM_DEADCHAR:
367 case WM_SYSCHAR:
368 case WM_SYSDEADCHAR:
369 case WM_MENUCHAR:
371 char ch = LOWORD(wparam);
372 WCHAR wch;
373 MultiByteToWideChar(CP_ACP, 0, &ch, 1, &wch, 1);
374 wparam = MAKEWPARAM( wch, HIWORD(wparam) );
376 break;
377 case WM_IME_CHAR:
379 char ch[2];
380 WCHAR wch;
381 ch[0] = (wparam >> 8);
382 ch[1] = (wparam & 0xff);
383 if (ch[0]) MultiByteToWideChar(CP_ACP, 0, ch, 2, &wch, 1);
384 else MultiByteToWideChar(CP_ACP, 0, &ch[1], 1, &wch, 1);
385 wparam = MAKEWPARAM( wch, HIWORD(wparam) );
387 break;
389 return wparam;
393 /***********************************************************************
394 * map_wparam_WtoA
396 * Convert the wparam of a Unicode message to ASCII.
398 static WPARAM map_wparam_WtoA( UINT message, WPARAM wparam )
400 switch(message)
402 case WM_CHARTOITEM:
403 case EM_SETPASSWORDCHAR:
404 case WM_CHAR:
405 case WM_DEADCHAR:
406 case WM_SYSCHAR:
407 case WM_SYSDEADCHAR:
408 case WM_MENUCHAR:
410 WCHAR wch = LOWORD(wparam);
411 BYTE ch;
412 WideCharToMultiByte( CP_ACP, 0, &wch, 1, (LPSTR)&ch, 1, NULL, NULL );
413 wparam = MAKEWPARAM( ch, HIWORD(wparam) );
415 break;
416 case WM_IME_CHAR:
418 WCHAR wch = LOWORD(wparam);
419 BYTE ch[2];
421 if (WideCharToMultiByte( CP_ACP, 0, &wch, 1, (LPSTR)ch, 2, NULL, NULL ) == 2)
422 wparam = MAKEWPARAM( (ch[0] << 8) | ch[1], HIWORD(wparam) );
423 else
424 wparam = MAKEWPARAM( ch[0], HIWORD(wparam) );
426 break;
428 return wparam;
432 /***********************************************************************
433 * pack_message
435 * Pack a message for sending to another process.
436 * Return the size of the data we expect in the message reply.
437 * Set data->count to -1 if there is an error.
439 static size_t pack_message( HWND hwnd, UINT message, WPARAM wparam, LPARAM lparam,
440 struct packed_message *data )
442 data->count = 0;
443 switch(message)
445 case WM_NCCREATE:
446 case WM_CREATE:
448 CREATESTRUCTW *cs = (CREATESTRUCTW *)lparam;
449 push_data( data, cs, sizeof(*cs) );
450 if (HIWORD(cs->lpszName)) push_string( data, cs->lpszName );
451 if (HIWORD(cs->lpszClass)) push_string( data, cs->lpszClass );
452 return sizeof(*cs);
454 case WM_GETTEXT:
455 case WM_ASKCBFORMATNAME:
456 return wparam * sizeof(WCHAR);
457 case WM_WININICHANGE:
458 if (lparam) push_string(data, (LPWSTR)lparam );
459 return 0;
460 case WM_SETTEXT:
461 case WM_DEVMODECHANGE:
462 case CB_DIR:
463 case LB_DIR:
464 case LB_ADDFILE:
465 case EM_REPLACESEL:
466 push_string( data, (LPWSTR)lparam );
467 return 0;
468 case WM_GETMINMAXINFO:
469 push_data( data, (MINMAXINFO *)lparam, sizeof(MINMAXINFO) );
470 return sizeof(MINMAXINFO);
471 case WM_DRAWITEM:
472 push_data( data, (DRAWITEMSTRUCT *)lparam, sizeof(DRAWITEMSTRUCT) );
473 return 0;
474 case WM_MEASUREITEM:
475 push_data( data, (MEASUREITEMSTRUCT *)lparam, sizeof(MEASUREITEMSTRUCT) );
476 return sizeof(MEASUREITEMSTRUCT);
477 case WM_DELETEITEM:
478 push_data( data, (DELETEITEMSTRUCT *)lparam, sizeof(DELETEITEMSTRUCT) );
479 return 0;
480 case WM_COMPAREITEM:
481 push_data( data, (COMPAREITEMSTRUCT *)lparam, sizeof(COMPAREITEMSTRUCT) );
482 return 0;
483 case WM_WINDOWPOSCHANGING:
484 case WM_WINDOWPOSCHANGED:
485 push_data( data, (WINDOWPOS *)lparam, sizeof(WINDOWPOS) );
486 return sizeof(WINDOWPOS);
487 case WM_COPYDATA:
489 COPYDATASTRUCT *cp = (COPYDATASTRUCT *)lparam;
490 push_data( data, cp, sizeof(*cp) );
491 if (cp->lpData) push_data( data, cp->lpData, cp->cbData );
492 return 0;
494 case WM_NOTIFY:
495 /* WM_NOTIFY cannot be sent across processes (MSDN) */
496 data->count = -1;
497 return 0;
498 case WM_HELP:
499 push_data( data, (HELPINFO *)lparam, sizeof(HELPINFO) );
500 return 0;
501 case WM_STYLECHANGING:
502 case WM_STYLECHANGED:
503 push_data( data, (STYLESTRUCT *)lparam, sizeof(STYLESTRUCT) );
504 return 0;
505 case WM_NCCALCSIZE:
506 if (!wparam)
508 push_data( data, (RECT *)lparam, sizeof(RECT) );
509 return sizeof(RECT);
511 else
513 NCCALCSIZE_PARAMS *nc = (NCCALCSIZE_PARAMS *)lparam;
514 push_data( data, nc, sizeof(*nc) );
515 push_data( data, nc->lppos, sizeof(*nc->lppos) );
516 return sizeof(*nc) + sizeof(*nc->lppos);
518 case WM_GETDLGCODE:
519 if (lparam) push_data( data, (MSG *)lparam, sizeof(MSG) );
520 return sizeof(MSG);
521 case SBM_SETSCROLLINFO:
522 push_data( data, (SCROLLINFO *)lparam, sizeof(SCROLLINFO) );
523 return 0;
524 case SBM_GETSCROLLINFO:
525 push_data( data, (SCROLLINFO *)lparam, sizeof(SCROLLINFO) );
526 return sizeof(SCROLLINFO);
527 case SBM_GETSCROLLBARINFO:
529 const SCROLLBARINFO *info = (const SCROLLBARINFO *)lparam;
530 size_t size = min( info->cbSize, sizeof(SCROLLBARINFO) );
531 push_data( data, info, size );
532 return size;
534 case EM_GETSEL:
535 case SBM_GETRANGE:
536 case CB_GETEDITSEL:
538 size_t size = 0;
539 if (wparam) size += sizeof(DWORD);
540 if (lparam) size += sizeof(DWORD);
541 return size;
543 case EM_GETRECT:
544 case LB_GETITEMRECT:
545 case CB_GETDROPPEDCONTROLRECT:
546 return sizeof(RECT);
547 case EM_SETRECT:
548 case EM_SETRECTNP:
549 push_data( data, (RECT *)lparam, sizeof(RECT) );
550 return 0;
551 case EM_GETLINE:
553 WORD *pw = (WORD *)lparam;
554 push_data( data, pw, sizeof(*pw) );
555 return *pw * sizeof(WCHAR);
557 case EM_SETTABSTOPS:
558 case LB_SETTABSTOPS:
559 if (wparam) push_data( data, (UINT *)lparam, sizeof(UINT) * wparam );
560 return 0;
561 case CB_ADDSTRING:
562 case CB_INSERTSTRING:
563 case CB_FINDSTRING:
564 case CB_FINDSTRINGEXACT:
565 case CB_SELECTSTRING:
566 if (combobox_has_strings( hwnd )) push_string( data, (LPWSTR)lparam );
567 return 0;
568 case CB_GETLBTEXT:
569 if (!combobox_has_strings( hwnd )) return sizeof(ULONG_PTR);
570 return (SendMessageW( hwnd, CB_GETLBTEXTLEN, wparam, 0 ) + 1) * sizeof(WCHAR);
571 case LB_ADDSTRING:
572 case LB_INSERTSTRING:
573 case LB_FINDSTRING:
574 case LB_FINDSTRINGEXACT:
575 case LB_SELECTSTRING:
576 if (listbox_has_strings( hwnd )) push_string( data, (LPWSTR)lparam );
577 return 0;
578 case LB_GETTEXT:
579 if (!listbox_has_strings( hwnd )) return sizeof(ULONG_PTR);
580 return (SendMessageW( hwnd, LB_GETTEXTLEN, wparam, 0 ) + 1) * sizeof(WCHAR);
581 case LB_GETSELITEMS:
582 return wparam * sizeof(UINT);
583 case WM_NEXTMENU:
584 push_data( data, (MDINEXTMENU *)lparam, sizeof(MDINEXTMENU) );
585 return sizeof(MDINEXTMENU);
586 case WM_SIZING:
587 case WM_MOVING:
588 push_data( data, (RECT *)lparam, sizeof(RECT) );
589 return sizeof(RECT);
590 case WM_MDICREATE:
592 MDICREATESTRUCTW *cs = (MDICREATESTRUCTW *)lparam;
593 push_data( data, cs, sizeof(*cs) );
594 if (HIWORD(cs->szTitle)) push_string( data, cs->szTitle );
595 if (HIWORD(cs->szClass)) push_string( data, cs->szClass );
596 return sizeof(*cs);
598 case WM_MDIGETACTIVE:
599 if (lparam) return sizeof(BOOL);
600 return 0;
601 case WM_WINE_SETWINDOWPOS:
602 push_data( data, (WINDOWPOS *)lparam, sizeof(WINDOWPOS) );
603 return 0;
604 case WM_WINE_KEYBOARD_LL_HOOK:
605 push_data( data, (KBDLLHOOKSTRUCT *)lparam, sizeof(KBDLLHOOKSTRUCT) );
606 return 0;
607 case WM_WINE_MOUSE_LL_HOOK:
608 push_data( data, (MSLLHOOKSTRUCT *)lparam, sizeof(MSLLHOOKSTRUCT) );
609 return 0;
610 case WM_PAINT:
611 if (!wparam) return 0;
612 /* fall through */
614 /* these contain an HFONT */
615 case WM_SETFONT:
616 case WM_GETFONT:
617 /* these contain an HDC */
618 case WM_ERASEBKGND:
619 case WM_ICONERASEBKGND:
620 case WM_NCPAINT:
621 case WM_CTLCOLORMSGBOX:
622 case WM_CTLCOLOREDIT:
623 case WM_CTLCOLORLISTBOX:
624 case WM_CTLCOLORBTN:
625 case WM_CTLCOLORDLG:
626 case WM_CTLCOLORSCROLLBAR:
627 case WM_CTLCOLORSTATIC:
628 case WM_PRINT:
629 case WM_PRINTCLIENT:
630 /* these contain an HGLOBAL */
631 case WM_PAINTCLIPBOARD:
632 case WM_SIZECLIPBOARD:
633 /* these contain HICON */
634 case WM_GETICON:
635 case WM_SETICON:
636 case WM_QUERYDRAGICON:
637 case WM_QUERYPARKICON:
638 /* these contain pointers */
639 case WM_DROPOBJECT:
640 case WM_QUERYDROPOBJECT:
641 case WM_DRAGLOOP:
642 case WM_DRAGSELECT:
643 case WM_DRAGMOVE:
644 case WM_DEVICECHANGE:
645 FIXME( "msg %x (%s) not supported yet\n", message, SPY_GetMsgName(message, hwnd) );
646 data->count = -1;
647 return 0;
649 return 0;
653 /***********************************************************************
654 * unpack_message
656 * Unpack a message received from another process.
658 static BOOL unpack_message( HWND hwnd, UINT message, WPARAM *wparam, LPARAM *lparam,
659 void **buffer, size_t size )
661 size_t minsize = 0;
663 switch(message)
665 case WM_NCCREATE:
666 case WM_CREATE:
668 CREATESTRUCTW *cs = *buffer;
669 WCHAR *str = (WCHAR *)(cs + 1);
670 if (size < sizeof(*cs)) return FALSE;
671 size -= sizeof(*cs);
672 if (HIWORD(cs->lpszName))
674 if (!check_string( str, size )) return FALSE;
675 cs->lpszName = str;
676 size -= (strlenW(str) + 1) * sizeof(WCHAR);
677 str += strlenW(str) + 1;
679 if (HIWORD(cs->lpszClass))
681 if (!check_string( str, size )) return FALSE;
682 cs->lpszClass = str;
684 break;
686 case WM_GETTEXT:
687 case WM_ASKCBFORMATNAME:
688 if (!get_buffer_space( buffer, (*wparam * sizeof(WCHAR)) )) return FALSE;
689 break;
690 case WM_WININICHANGE:
691 if (!*lparam) return TRUE;
692 /* fall through */
693 case WM_SETTEXT:
694 case WM_DEVMODECHANGE:
695 case CB_DIR:
696 case LB_DIR:
697 case LB_ADDFILE:
698 case EM_REPLACESEL:
699 if (!check_string( *buffer, size )) return FALSE;
700 break;
701 case WM_GETMINMAXINFO:
702 minsize = sizeof(MINMAXINFO);
703 break;
704 case WM_DRAWITEM:
705 minsize = sizeof(DRAWITEMSTRUCT);
706 break;
707 case WM_MEASUREITEM:
708 minsize = sizeof(MEASUREITEMSTRUCT);
709 break;
710 case WM_DELETEITEM:
711 minsize = sizeof(DELETEITEMSTRUCT);
712 break;
713 case WM_COMPAREITEM:
714 minsize = sizeof(COMPAREITEMSTRUCT);
715 break;
716 case WM_WINDOWPOSCHANGING:
717 case WM_WINDOWPOSCHANGED:
718 case WM_WINE_SETWINDOWPOS:
719 minsize = sizeof(WINDOWPOS);
720 break;
721 case WM_COPYDATA:
723 COPYDATASTRUCT *cp = *buffer;
724 if (size < sizeof(*cp)) return FALSE;
725 if (cp->lpData)
727 minsize = sizeof(*cp) + cp->cbData;
728 cp->lpData = cp + 1;
730 break;
732 case WM_NOTIFY:
733 /* WM_NOTIFY cannot be sent across processes (MSDN) */
734 return FALSE;
735 case WM_HELP:
736 minsize = sizeof(HELPINFO);
737 break;
738 case WM_STYLECHANGING:
739 case WM_STYLECHANGED:
740 minsize = sizeof(STYLESTRUCT);
741 break;
742 case WM_NCCALCSIZE:
743 if (!*wparam) minsize = sizeof(RECT);
744 else
746 NCCALCSIZE_PARAMS *nc = *buffer;
747 if (size < sizeof(*nc) + sizeof(*nc->lppos)) return FALSE;
748 nc->lppos = (WINDOWPOS *)(nc + 1);
750 break;
751 case WM_GETDLGCODE:
752 if (!*lparam) return TRUE;
753 minsize = sizeof(MSG);
754 break;
755 case SBM_SETSCROLLINFO:
756 minsize = sizeof(SCROLLINFO);
757 break;
758 case SBM_GETSCROLLINFO:
759 if (!get_buffer_space( buffer, sizeof(SCROLLINFO ))) return FALSE;
760 break;
761 case SBM_GETSCROLLBARINFO:
762 if (!get_buffer_space( buffer, sizeof(SCROLLBARINFO ))) return FALSE;
763 break;
764 case EM_GETSEL:
765 case SBM_GETRANGE:
766 case CB_GETEDITSEL:
767 if (*wparam || *lparam)
769 if (!get_buffer_space( buffer, 2*sizeof(DWORD) )) return FALSE;
770 if (*wparam) *wparam = (WPARAM)*buffer;
771 if (*lparam) *lparam = (LPARAM)((DWORD *)*buffer + 1);
773 return TRUE;
774 case EM_GETRECT:
775 case LB_GETITEMRECT:
776 case CB_GETDROPPEDCONTROLRECT:
777 if (!get_buffer_space( buffer, sizeof(RECT) )) return FALSE;
778 break;
779 case EM_SETRECT:
780 case EM_SETRECTNP:
781 minsize = sizeof(RECT);
782 break;
783 case EM_GETLINE:
785 WORD len;
786 if (size < sizeof(WORD)) return FALSE;
787 len = *(WORD *)*buffer;
788 if (!get_buffer_space( buffer, (len + 1) * sizeof(WCHAR) )) return FALSE;
789 *lparam = (LPARAM)*buffer + sizeof(WORD); /* don't erase WORD at start of buffer */
790 return TRUE;
792 case EM_SETTABSTOPS:
793 case LB_SETTABSTOPS:
794 if (!*wparam) return TRUE;
795 minsize = *wparam * sizeof(UINT);
796 break;
797 case CB_ADDSTRING:
798 case CB_INSERTSTRING:
799 case CB_FINDSTRING:
800 case CB_FINDSTRINGEXACT:
801 case CB_SELECTSTRING:
802 case LB_ADDSTRING:
803 case LB_INSERTSTRING:
804 case LB_FINDSTRING:
805 case LB_FINDSTRINGEXACT:
806 case LB_SELECTSTRING:
807 if (!*buffer) return TRUE;
808 if (!check_string( *buffer, size )) return FALSE;
809 break;
810 case CB_GETLBTEXT:
812 size = sizeof(ULONG_PTR);
813 if (combobox_has_strings( hwnd ))
814 size = (SendMessageW( hwnd, CB_GETLBTEXTLEN, *wparam, 0 ) + 1) * sizeof(WCHAR);
815 if (!get_buffer_space( buffer, size )) return FALSE;
816 break;
818 case LB_GETTEXT:
820 size = sizeof(ULONG_PTR);
821 if (listbox_has_strings( hwnd ))
822 size = (SendMessageW( hwnd, LB_GETTEXTLEN, *wparam, 0 ) + 1) * sizeof(WCHAR);
823 if (!get_buffer_space( buffer, size )) return FALSE;
824 break;
826 case LB_GETSELITEMS:
827 if (!get_buffer_space( buffer, *wparam * sizeof(UINT) )) return FALSE;
828 break;
829 case WM_NEXTMENU:
830 minsize = sizeof(MDINEXTMENU);
831 if (!get_buffer_space( buffer, sizeof(MDINEXTMENU) )) return FALSE;
832 break;
833 case WM_SIZING:
834 case WM_MOVING:
835 minsize = sizeof(RECT);
836 if (!get_buffer_space( buffer, sizeof(RECT) )) return FALSE;
837 break;
838 case WM_MDICREATE:
840 MDICREATESTRUCTW *cs = *buffer;
841 WCHAR *str = (WCHAR *)(cs + 1);
842 if (size < sizeof(*cs)) return FALSE;
843 size -= sizeof(*cs);
844 if (HIWORD(cs->szTitle))
846 if (!check_string( str, size )) return FALSE;
847 cs->szTitle = str;
848 size -= (strlenW(str) + 1) * sizeof(WCHAR);
849 str += strlenW(str) + 1;
851 if (HIWORD(cs->szClass))
853 if (!check_string( str, size )) return FALSE;
854 cs->szClass = str;
856 break;
858 case WM_MDIGETACTIVE:
859 if (!*lparam) return TRUE;
860 if (!get_buffer_space( buffer, sizeof(BOOL) )) return FALSE;
861 break;
862 case WM_WINE_KEYBOARD_LL_HOOK:
863 minsize = sizeof(KBDLLHOOKSTRUCT);
864 break;
865 case WM_WINE_MOUSE_LL_HOOK:
866 minsize = sizeof(MSLLHOOKSTRUCT);
867 break;
868 case WM_PAINT:
869 if (!*wparam) return TRUE;
870 /* fall through */
872 /* these contain an HFONT */
873 case WM_SETFONT:
874 case WM_GETFONT:
875 /* these contain an HDC */
876 case WM_ERASEBKGND:
877 case WM_ICONERASEBKGND:
878 case WM_NCPAINT:
879 case WM_CTLCOLORMSGBOX:
880 case WM_CTLCOLOREDIT:
881 case WM_CTLCOLORLISTBOX:
882 case WM_CTLCOLORBTN:
883 case WM_CTLCOLORDLG:
884 case WM_CTLCOLORSCROLLBAR:
885 case WM_CTLCOLORSTATIC:
886 case WM_PRINT:
887 case WM_PRINTCLIENT:
888 /* these contain an HGLOBAL */
889 case WM_PAINTCLIPBOARD:
890 case WM_SIZECLIPBOARD:
891 /* these contain HICON */
892 case WM_GETICON:
893 case WM_SETICON:
894 case WM_QUERYDRAGICON:
895 case WM_QUERYPARKICON:
896 /* these contain pointers */
897 case WM_DROPOBJECT:
898 case WM_QUERYDROPOBJECT:
899 case WM_DRAGLOOP:
900 case WM_DRAGSELECT:
901 case WM_DRAGMOVE:
902 case WM_DEVICECHANGE:
903 FIXME( "msg %x (%s) not supported yet\n", message, SPY_GetMsgName(message, hwnd) );
904 return FALSE;
906 default:
907 return TRUE; /* message doesn't need any unpacking */
910 /* default exit for most messages: check minsize and store buffer in lparam */
911 if (size < minsize) return FALSE;
912 *lparam = (LPARAM)*buffer;
913 return TRUE;
917 /***********************************************************************
918 * pack_reply
920 * Pack a reply to a message for sending to another process.
922 static void pack_reply( HWND hwnd, UINT message, WPARAM wparam, LPARAM lparam,
923 LRESULT res, struct packed_message *data )
925 data->count = 0;
926 switch(message)
928 case WM_NCCREATE:
929 case WM_CREATE:
930 push_data( data, (CREATESTRUCTW *)lparam, sizeof(CREATESTRUCTW) );
931 break;
932 case WM_GETTEXT:
933 case CB_GETLBTEXT:
934 case LB_GETTEXT:
935 push_data( data, (WCHAR *)lparam, (res + 1) * sizeof(WCHAR) );
936 break;
937 case WM_GETMINMAXINFO:
938 push_data( data, (MINMAXINFO *)lparam, sizeof(MINMAXINFO) );
939 break;
940 case WM_MEASUREITEM:
941 push_data( data, (MEASUREITEMSTRUCT *)lparam, sizeof(MEASUREITEMSTRUCT) );
942 break;
943 case WM_WINDOWPOSCHANGING:
944 case WM_WINDOWPOSCHANGED:
945 push_data( data, (WINDOWPOS *)lparam, sizeof(WINDOWPOS) );
946 break;
947 case WM_GETDLGCODE:
948 if (lparam) push_data( data, (MSG *)lparam, sizeof(MSG) );
949 break;
950 case SBM_GETSCROLLINFO:
951 push_data( data, (SCROLLINFO *)lparam, sizeof(SCROLLINFO) );
952 break;
953 case EM_GETRECT:
954 case LB_GETITEMRECT:
955 case CB_GETDROPPEDCONTROLRECT:
956 case WM_SIZING:
957 case WM_MOVING:
958 push_data( data, (RECT *)lparam, sizeof(RECT) );
959 break;
960 case EM_GETLINE:
962 WORD *ptr = (WORD *)lparam;
963 push_data( data, ptr, ptr[-1] * sizeof(WCHAR) );
964 break;
966 case LB_GETSELITEMS:
967 push_data( data, (UINT *)lparam, wparam * sizeof(UINT) );
968 break;
969 case WM_MDIGETACTIVE:
970 if (lparam) push_data( data, (BOOL *)lparam, sizeof(BOOL) );
971 break;
972 case WM_NCCALCSIZE:
973 if (!wparam)
974 push_data( data, (RECT *)lparam, sizeof(RECT) );
975 else
977 NCCALCSIZE_PARAMS *nc = (NCCALCSIZE_PARAMS *)lparam;
978 push_data( data, nc, sizeof(*nc) );
979 push_data( data, nc->lppos, sizeof(*nc->lppos) );
981 break;
982 case EM_GETSEL:
983 case SBM_GETRANGE:
984 case CB_GETEDITSEL:
985 if (wparam) push_data( data, (DWORD *)wparam, sizeof(DWORD) );
986 if (lparam) push_data( data, (DWORD *)lparam, sizeof(DWORD) );
987 break;
988 case WM_NEXTMENU:
989 push_data( data, (MDINEXTMENU *)lparam, sizeof(MDINEXTMENU) );
990 break;
991 case WM_MDICREATE:
992 push_data( data, (MDICREATESTRUCTW *)lparam, sizeof(MDICREATESTRUCTW) );
993 break;
994 case WM_ASKCBFORMATNAME:
995 push_data( data, (WCHAR *)lparam, (strlenW((WCHAR *)lparam) + 1) * sizeof(WCHAR) );
996 break;
1001 /***********************************************************************
1002 * unpack_reply
1004 * Unpack a message reply received from another process.
1006 static void unpack_reply( HWND hwnd, UINT message, WPARAM wparam, LPARAM lparam,
1007 void *buffer, size_t size )
1009 switch(message)
1011 case WM_NCCREATE:
1012 case WM_CREATE:
1014 CREATESTRUCTW *cs = (CREATESTRUCTW *)lparam;
1015 LPCWSTR name = cs->lpszName, class = cs->lpszClass;
1016 memcpy( cs, buffer, min( sizeof(*cs), size ));
1017 cs->lpszName = name; /* restore the original pointers */
1018 cs->lpszClass = class;
1019 break;
1021 case WM_GETTEXT:
1022 case WM_ASKCBFORMATNAME:
1023 memcpy( (WCHAR *)lparam, buffer, min( wparam*sizeof(WCHAR), size ));
1024 break;
1025 case WM_GETMINMAXINFO:
1026 memcpy( (MINMAXINFO *)lparam, buffer, min( sizeof(MINMAXINFO), size ));
1027 break;
1028 case WM_MEASUREITEM:
1029 memcpy( (MEASUREITEMSTRUCT *)lparam, buffer, min( sizeof(MEASUREITEMSTRUCT), size ));
1030 break;
1031 case WM_WINDOWPOSCHANGING:
1032 case WM_WINDOWPOSCHANGED:
1033 memcpy( (WINDOWPOS *)lparam, buffer, min( sizeof(WINDOWPOS), size ));
1034 break;
1035 case WM_GETDLGCODE:
1036 if (lparam) memcpy( (MSG *)lparam, buffer, min( sizeof(MSG), size ));
1037 break;
1038 case SBM_GETSCROLLINFO:
1039 memcpy( (SCROLLINFO *)lparam, buffer, min( sizeof(SCROLLINFO), size ));
1040 break;
1041 case SBM_GETSCROLLBARINFO:
1042 memcpy( (SCROLLBARINFO *)lparam, buffer, min( sizeof(SCROLLBARINFO), size ));
1043 break;
1044 case EM_GETRECT:
1045 case CB_GETDROPPEDCONTROLRECT:
1046 case LB_GETITEMRECT:
1047 case WM_SIZING:
1048 case WM_MOVING:
1049 memcpy( (RECT *)lparam, buffer, min( sizeof(RECT), size ));
1050 break;
1051 case EM_GETLINE:
1052 size = min( size, (size_t)*(WORD *)lparam );
1053 memcpy( (WCHAR *)lparam, buffer, size );
1054 break;
1055 case LB_GETSELITEMS:
1056 memcpy( (UINT *)lparam, buffer, min( wparam*sizeof(UINT), size ));
1057 break;
1058 case LB_GETTEXT:
1059 case CB_GETLBTEXT:
1060 memcpy( (WCHAR *)lparam, buffer, size );
1061 break;
1062 case WM_NEXTMENU:
1063 memcpy( (MDINEXTMENU *)lparam, buffer, min( sizeof(MDINEXTMENU), size ));
1064 break;
1065 case WM_MDIGETACTIVE:
1066 if (lparam) memcpy( (BOOL *)lparam, buffer, min( sizeof(BOOL), size ));
1067 break;
1068 case WM_NCCALCSIZE:
1069 if (!wparam)
1070 memcpy( (RECT *)lparam, buffer, min( sizeof(RECT), size ));
1071 else
1073 NCCALCSIZE_PARAMS *nc = (NCCALCSIZE_PARAMS *)lparam;
1074 WINDOWPOS *wp = nc->lppos;
1075 memcpy( nc, buffer, min( sizeof(*nc), size ));
1076 if (size > sizeof(*nc))
1078 size -= sizeof(*nc);
1079 memcpy( wp, (NCCALCSIZE_PARAMS*)buffer + 1, min( sizeof(*wp), size ));
1081 nc->lppos = wp; /* restore the original pointer */
1083 break;
1084 case EM_GETSEL:
1085 case SBM_GETRANGE:
1086 case CB_GETEDITSEL:
1087 if (wparam)
1089 memcpy( (DWORD *)wparam, buffer, min( sizeof(DWORD), size ));
1090 if (size <= sizeof(DWORD)) break;
1091 size -= sizeof(DWORD);
1092 buffer = (DWORD *)buffer + 1;
1094 if (lparam) memcpy( (DWORD *)lparam, buffer, min( sizeof(DWORD), size ));
1095 break;
1096 case WM_MDICREATE:
1098 MDICREATESTRUCTW *cs = (MDICREATESTRUCTW *)lparam;
1099 LPCWSTR title = cs->szTitle, class = cs->szClass;
1100 memcpy( cs, buffer, min( sizeof(*cs), size ));
1101 cs->szTitle = title; /* restore the original pointers */
1102 cs->szClass = class;
1103 break;
1105 default:
1106 ERR( "should not happen: unexpected message %x\n", message );
1107 break;
1112 /***********************************************************************
1113 * reply_message
1115 * Send a reply to a sent message.
1117 static void reply_message( struct received_message_info *info, LRESULT result, BOOL remove )
1119 struct packed_message data;
1120 int i, replied = info->flags & ISMEX_REPLIED;
1122 if (info->flags & ISMEX_NOTIFY) return; /* notify messages don't get replies */
1123 if (!remove && replied) return; /* replied already */
1125 data.count = 0;
1126 info->flags |= ISMEX_REPLIED;
1128 if (info->type == MSG_OTHER_PROCESS && !replied)
1130 pack_reply( info->msg.hwnd, info->msg.message, info->msg.wParam,
1131 info->msg.lParam, result, &data );
1134 SERVER_START_REQ( reply_message )
1136 req->result = result;
1137 req->remove = remove;
1138 for (i = 0; i < data.count; i++) wine_server_add_data( req, data.data[i], data.size[i] );
1139 wine_server_call( req );
1141 SERVER_END_REQ;
1145 /***********************************************************************
1146 * handle_internal_message
1148 * Handle an internal Wine message instead of calling the window proc.
1150 static LRESULT handle_internal_message( HWND hwnd, UINT msg, WPARAM wparam, LPARAM lparam )
1152 if (hwnd == GetDesktopWindow()) return 0;
1153 switch(msg)
1155 case WM_WINE_DESTROYWINDOW:
1156 return WIN_DestroyWindow( hwnd );
1157 case WM_WINE_SETWINDOWPOS:
1158 return USER_Driver->pSetWindowPos( (WINDOWPOS *)lparam );
1159 case WM_WINE_SHOWWINDOW:
1160 return ShowWindow( hwnd, wparam );
1161 case WM_WINE_SETPARENT:
1162 return (LRESULT)SetParent( hwnd, (HWND)wparam );
1163 case WM_WINE_SETWINDOWLONG:
1164 return (LRESULT)SetWindowLongW( hwnd, wparam, lparam );
1165 case WM_WINE_ENABLEWINDOW:
1166 return EnableWindow( hwnd, wparam );
1167 case WM_WINE_SETACTIVEWINDOW:
1168 return (LRESULT)SetActiveWindow( (HWND)wparam );
1169 case WM_WINE_KEYBOARD_LL_HOOK:
1170 return HOOK_CallHooks( WH_KEYBOARD_LL, HC_ACTION, wparam, lparam, TRUE );
1171 case WM_WINE_MOUSE_LL_HOOK:
1172 return HOOK_CallHooks( WH_MOUSE_LL, HC_ACTION, wparam, lparam, TRUE );
1173 default:
1174 if (msg >= WM_WINE_FIRST_DRIVER_MSG && msg <= WM_WINE_LAST_DRIVER_MSG)
1175 return USER_Driver->pWindowMessage( hwnd, msg, wparam, lparam );
1176 FIXME( "unknown internal message %x\n", msg );
1177 return 0;
1181 /* since the WM_DDE_ACK response to a WM_DDE_EXECUTE message should contain the handle
1182 * to the memory handle, we keep track (in the server side) of all pairs of handle
1183 * used (the client passes its value and the content of the memory handle), and
1184 * the server stored both values (the client, and the local one, created after the
1185 * content). When a ACK message is generated, the list of pair is searched for a
1186 * matching pair, so that the client memory handle can be returned.
1188 struct DDE_pair {
1189 HGLOBAL client_hMem;
1190 HGLOBAL server_hMem;
1193 static struct DDE_pair* dde_pairs;
1194 static int dde_num_alloc;
1195 static int dde_num_used;
1197 static CRITICAL_SECTION dde_crst;
1198 static CRITICAL_SECTION_DEBUG critsect_debug =
1200 0, 0, &dde_crst,
1201 { &critsect_debug.ProcessLocksList, &critsect_debug.ProcessLocksList },
1202 0, 0, { 0, (DWORD)(__FILE__ ": dde_crst") }
1204 static CRITICAL_SECTION dde_crst = { &critsect_debug, -1, 0, 0, 0, 0 };
1206 static BOOL dde_add_pair(HGLOBAL chm, HGLOBAL shm)
1208 int i;
1209 #define GROWBY 4
1211 EnterCriticalSection(&dde_crst);
1213 /* now remember the pair of hMem on both sides */
1214 if (dde_num_used == dde_num_alloc)
1216 struct DDE_pair* tmp;
1217 if (dde_pairs)
1218 tmp = HeapReAlloc( GetProcessHeap(), 0, dde_pairs,
1219 (dde_num_alloc + GROWBY) * sizeof(struct DDE_pair));
1220 else
1221 tmp = HeapAlloc( GetProcessHeap(), 0,
1222 (dde_num_alloc + GROWBY) * sizeof(struct DDE_pair));
1224 if (!tmp)
1226 LeaveCriticalSection(&dde_crst);
1227 return FALSE;
1229 dde_pairs = tmp;
1230 /* zero out newly allocated part */
1231 memset(&dde_pairs[dde_num_alloc], 0, GROWBY * sizeof(struct DDE_pair));
1232 dde_num_alloc += GROWBY;
1234 #undef GROWBY
1235 for (i = 0; i < dde_num_alloc; i++)
1237 if (dde_pairs[i].server_hMem == 0)
1239 dde_pairs[i].client_hMem = chm;
1240 dde_pairs[i].server_hMem = shm;
1241 dde_num_used++;
1242 break;
1245 LeaveCriticalSection(&dde_crst);
1246 return TRUE;
1249 static HGLOBAL dde_get_pair(HGLOBAL shm)
1251 int i;
1252 HGLOBAL ret = 0;
1254 EnterCriticalSection(&dde_crst);
1255 for (i = 0; i < dde_num_alloc; i++)
1257 if (dde_pairs[i].server_hMem == shm)
1259 /* free this pair */
1260 dde_pairs[i].server_hMem = 0;
1261 dde_num_used--;
1262 ret = dde_pairs[i].client_hMem;
1263 break;
1266 LeaveCriticalSection(&dde_crst);
1267 return ret;
1270 /***********************************************************************
1271 * post_dde_message
1273 * Post a DDE message
1275 static BOOL post_dde_message( DWORD dest_tid, struct packed_message *data, const struct send_message_info *info )
1277 void* ptr = NULL;
1278 int size = 0;
1279 UINT uiLo, uiHi;
1280 LPARAM lp = 0;
1281 HGLOBAL hunlock = 0;
1282 int i;
1283 DWORD res;
1285 if (!UnpackDDElParam( info->msg, info->lparam, &uiLo, &uiHi ))
1286 return FALSE;
1288 lp = info->lparam;
1289 switch (info->msg)
1291 /* DDE messages which don't require packing are:
1292 * WM_DDE_INITIATE
1293 * WM_DDE_TERMINATE
1294 * WM_DDE_REQUEST
1295 * WM_DDE_UNADVISE
1297 case WM_DDE_ACK:
1298 if (HIWORD(uiHi))
1300 /* uiHi should contain a hMem from WM_DDE_EXECUTE */
1301 HGLOBAL h = dde_get_pair( (HANDLE)uiHi );
1302 if (h)
1304 /* send back the value of h on the other side */
1305 push_data( data, &h, sizeof(HGLOBAL) );
1306 lp = uiLo;
1307 TRACE( "send dde-ack %x %08x => %08lx\n", uiLo, uiHi, (DWORD)h );
1310 else
1312 /* uiHi should contain either an atom or 0 */
1313 TRACE( "send dde-ack %x atom=%x\n", uiLo, uiHi );
1314 lp = MAKELONG( uiLo, uiHi );
1316 break;
1317 case WM_DDE_ADVISE:
1318 case WM_DDE_DATA:
1319 case WM_DDE_POKE:
1320 size = 0;
1321 if (uiLo)
1323 size = GlobalSize( (HGLOBAL)uiLo ) ;
1324 if ((info->msg == WM_DDE_ADVISE && size < sizeof(DDEADVISE)) ||
1325 (info->msg == WM_DDE_DATA && size < sizeof(DDEDATA)) ||
1326 (info->msg == WM_DDE_POKE && size < sizeof(DDEPOKE))
1328 return FALSE;
1330 else if (info->msg != WM_DDE_DATA) return FALSE;
1332 lp = uiHi;
1333 if (uiLo)
1335 if ((ptr = GlobalLock( (HGLOBAL)uiLo) ))
1337 DDEDATA *dde_data = (DDEDATA *)ptr;
1338 TRACE("unused %d, fResponse %d, fRelease %d, fDeferUpd %d, fAckReq %d, cfFormat %d\n",
1339 dde_data->unused, dde_data->fResponse, dde_data->fRelease,
1340 dde_data->reserved, dde_data->fAckReq, dde_data->cfFormat);
1341 push_data( data, ptr, size );
1342 hunlock = (HGLOBAL)uiLo;
1345 TRACE( "send ddepack %u %x\n", size, uiHi );
1346 break;
1347 case WM_DDE_EXECUTE:
1348 if (info->lparam)
1350 if ((ptr = GlobalLock( (HGLOBAL)info->lparam) ))
1352 push_data(data, ptr, GlobalSize( (HGLOBAL)info->lparam ));
1353 /* so that the other side can send it back on ACK */
1354 lp = info->lparam;
1355 hunlock = (HGLOBAL)info->lparam;
1358 break;
1360 SERVER_START_REQ( send_message )
1362 req->id = dest_tid;
1363 req->type = info->type;
1364 req->flags = 0;
1365 req->win = info->hwnd;
1366 req->msg = info->msg;
1367 req->wparam = info->wparam;
1368 req->lparam = lp;
1369 req->time = GetCurrentTime();
1370 req->timeout = -1;
1371 for (i = 0; i < data->count; i++)
1372 wine_server_add_data( req, data->data[i], data->size[i] );
1373 if ((res = wine_server_call( req )))
1375 if (res == STATUS_INVALID_PARAMETER)
1376 /* FIXME: find a STATUS_ value for this one */
1377 SetLastError( ERROR_INVALID_THREAD_ID );
1378 else
1379 SetLastError( RtlNtStatusToDosError(res) );
1381 else
1382 FreeDDElParam(info->msg, info->lparam);
1384 SERVER_END_REQ;
1385 if (hunlock) GlobalUnlock(hunlock);
1387 return !res;
1390 /***********************************************************************
1391 * unpack_dde_message
1393 * Unpack a posted DDE message received from another process.
1395 static BOOL unpack_dde_message( HWND hwnd, UINT message, WPARAM *wparam, LPARAM *lparam,
1396 void **buffer, size_t size )
1398 UINT uiLo, uiHi;
1399 HGLOBAL hMem = 0;
1400 void* ptr;
1402 switch (message)
1404 case WM_DDE_ACK:
1405 if (size)
1407 /* hMem is being passed */
1408 if (size != sizeof(HGLOBAL)) return FALSE;
1409 if (!buffer || !*buffer) return FALSE;
1410 uiLo = *lparam;
1411 memcpy( &hMem, *buffer, size );
1412 uiHi = (UINT)hMem;
1413 TRACE("recv dde-ack %x mem=%x[%lx]\n", uiLo, uiHi, GlobalSize( hMem ));
1415 else
1417 uiLo = LOWORD( *lparam );
1418 uiHi = HIWORD( *lparam );
1419 TRACE("recv dde-ack %x atom=%x\n", uiLo, uiHi);
1421 *lparam = PackDDElParam( WM_DDE_ACK, uiLo, uiHi );
1422 break;
1423 case WM_DDE_ADVISE:
1424 case WM_DDE_DATA:
1425 case WM_DDE_POKE:
1426 if ((!buffer || !*buffer) && message != WM_DDE_DATA) return FALSE;
1427 uiHi = *lparam;
1428 TRACE( "recv ddepack %u %x\n", size, uiHi );
1429 if (size)
1431 if (!(hMem = GlobalAlloc( GMEM_MOVEABLE|GMEM_DDESHARE, size )))
1432 return FALSE;
1433 if ((ptr = GlobalLock( hMem )))
1435 memcpy( ptr, *buffer, size );
1436 GlobalUnlock( hMem );
1438 else
1440 GlobalFree( hMem );
1441 return FALSE;
1444 uiLo = (UINT)hMem;
1446 *lparam = PackDDElParam( message, uiLo, uiHi );
1447 break;
1448 case WM_DDE_EXECUTE:
1449 if (size)
1451 if (!buffer || !*buffer) return FALSE;
1452 if (!(hMem = GlobalAlloc( GMEM_MOVEABLE|GMEM_DDESHARE, size ))) return FALSE;
1453 if ((ptr = GlobalLock( hMem )))
1455 memcpy( ptr, *buffer, size );
1456 GlobalUnlock( hMem );
1457 TRACE( "exec: pairing c=%08lx s=%08lx\n", *lparam, (DWORD)hMem );
1458 if (!dde_add_pair( (HGLOBAL)*lparam, hMem ))
1460 GlobalFree( hMem );
1461 return FALSE;
1464 else
1466 GlobalFree( hMem );
1467 return FALSE;
1469 } else return FALSE;
1470 *lparam = (LPARAM)hMem;
1471 break;
1473 return TRUE;
1476 /***********************************************************************
1477 * call_window_proc
1479 * Call a window procedure and the corresponding hooks.
1481 static LRESULT call_window_proc( HWND hwnd, UINT msg, WPARAM wparam, LPARAM lparam,
1482 BOOL unicode, BOOL same_thread )
1484 struct user_thread_info *thread_info = get_user_thread_info();
1485 LRESULT result = 0;
1486 WNDPROC winproc;
1487 CWPSTRUCT cwp;
1488 CWPRETSTRUCT cwpret;
1490 if (thread_info->recursion_count > MAX_SENDMSG_RECURSION) return 0;
1491 thread_info->recursion_count++;
1493 if (msg & 0x80000000)
1495 result = handle_internal_message( hwnd, msg, wparam, lparam );
1496 goto done;
1499 /* first the WH_CALLWNDPROC hook */
1500 hwnd = WIN_GetFullHandle( hwnd );
1501 cwp.lParam = lparam;
1502 cwp.wParam = wparam;
1503 cwp.message = msg;
1504 cwp.hwnd = hwnd;
1505 HOOK_CallHooks( WH_CALLWNDPROC, HC_ACTION, same_thread, (LPARAM)&cwp, unicode );
1507 /* now call the window procedure */
1508 if (unicode)
1510 if (!(winproc = (WNDPROC)GetWindowLongPtrW( hwnd, GWLP_WNDPROC ))) goto done;
1511 result = CallWindowProcW( winproc, hwnd, msg, wparam, lparam );
1513 else
1515 if (!(winproc = (WNDPROC)GetWindowLongPtrA( hwnd, GWLP_WNDPROC ))) goto done;
1516 result = CallWindowProcA( winproc, hwnd, msg, wparam, lparam );
1519 /* and finally the WH_CALLWNDPROCRET hook */
1520 cwpret.lResult = result;
1521 cwpret.lParam = lparam;
1522 cwpret.wParam = wparam;
1523 cwpret.message = msg;
1524 cwpret.hwnd = hwnd;
1525 HOOK_CallHooks( WH_CALLWNDPROCRET, HC_ACTION, same_thread, (LPARAM)&cwpret, unicode );
1526 done:
1527 thread_info->recursion_count--;
1528 return result;
1532 /***********************************************************************
1533 * send_parent_notify
1535 * Send a WM_PARENTNOTIFY to all ancestors of the given window, unless
1536 * the window has the WS_EX_NOPARENTNOTIFY style.
1538 static void send_parent_notify( HWND hwnd, WORD event, WORD idChild, POINT pt )
1540 /* pt has to be in the client coordinates of the parent window */
1541 MapWindowPoints( 0, hwnd, &pt, 1 );
1542 for (;;)
1544 HWND parent;
1546 if (!(GetWindowLongW( hwnd, GWL_STYLE ) & WS_CHILD)) break;
1547 if (GetWindowLongW( hwnd, GWL_EXSTYLE ) & WS_EX_NOPARENTNOTIFY) break;
1548 if (!(parent = GetParent(hwnd))) break;
1549 MapWindowPoints( hwnd, parent, &pt, 1 );
1550 hwnd = parent;
1551 SendMessageW( hwnd, WM_PARENTNOTIFY,
1552 MAKEWPARAM( event, idChild ), MAKELPARAM( pt.x, pt.y ) );
1557 /***********************************************************************
1558 * accept_hardware_message
1560 * Tell the server we have passed the message to the app
1561 * (even though we may end up dropping it later on)
1563 static void accept_hardware_message( UINT hw_id, BOOL remove, HWND new_hwnd )
1565 SERVER_START_REQ( accept_hardware_message )
1567 req->hw_id = hw_id;
1568 req->remove = remove;
1569 req->new_win = new_hwnd;
1570 if (wine_server_call( req ))
1571 FIXME("Failed to reply to MSG_HARDWARE message. Message may not be removed from queue.\n");
1573 SERVER_END_REQ;
1577 /***********************************************************************
1578 * process_keyboard_message
1580 * returns TRUE if the contents of 'msg' should be passed to the application
1582 static BOOL process_keyboard_message( MSG *msg, UINT hw_id, HWND hwnd_filter,
1583 UINT first, UINT last, BOOL remove )
1585 EVENTMSG event;
1587 /* FIXME: is this really the right place for this hook? */
1588 event.message = msg->message;
1589 event.hwnd = msg->hwnd;
1590 event.time = msg->time;
1591 event.paramL = (msg->wParam & 0xFF) | (HIWORD(msg->lParam) << 8);
1592 event.paramH = msg->lParam & 0x7FFF;
1593 if (HIWORD(msg->lParam) & 0x0100) event.paramH |= 0x8000; /* special_key - bit */
1594 HOOK_CallHooks( WH_JOURNALRECORD, HC_ACTION, 0, (LPARAM)&event, TRUE );
1596 /* check message filters */
1597 if (msg->message < first || msg->message > last) return FALSE;
1598 if (!check_hwnd_filter( msg, hwnd_filter )) return FALSE;
1600 if (remove)
1602 /* Handle F1 key by sending out WM_HELP message */
1603 if ((msg->message == WM_KEYUP) &&
1604 (msg->wParam == VK_F1) &&
1605 (msg->hwnd != GetDesktopWindow()) &&
1606 !MENU_IsMenuActive())
1608 HELPINFO hi;
1609 hi.cbSize = sizeof(HELPINFO);
1610 hi.iContextType = HELPINFO_WINDOW;
1611 hi.iCtrlId = GetWindowLongPtrA( msg->hwnd, GWLP_ID );
1612 hi.hItemHandle = msg->hwnd;
1613 hi.dwContextId = GetWindowContextHelpId( msg->hwnd );
1614 hi.MousePos = msg->pt;
1615 SendMessageW( msg->hwnd, WM_HELP, 0, (LPARAM)&hi );
1619 if (HOOK_CallHooks( WH_KEYBOARD, remove ? HC_ACTION : HC_NOREMOVE,
1620 LOWORD(msg->wParam), msg->lParam, TRUE ))
1622 /* skip this message */
1623 HOOK_CallHooks( WH_CBT, HCBT_KEYSKIPPED, LOWORD(msg->wParam), msg->lParam, TRUE );
1624 accept_hardware_message( hw_id, TRUE, 0 );
1625 return FALSE;
1627 accept_hardware_message( hw_id, remove, 0 );
1628 return TRUE;
1632 /***********************************************************************
1633 * process_mouse_message
1635 * returns TRUE if the contents of 'msg' should be passed to the application
1637 static BOOL process_mouse_message( MSG *msg, UINT hw_id, ULONG_PTR extra_info, HWND hwnd_filter,
1638 UINT first, UINT last, BOOL remove )
1640 static MSG clk_msg;
1642 POINT pt;
1643 UINT message;
1644 INT hittest;
1645 EVENTMSG event;
1646 GUITHREADINFO info;
1647 MOUSEHOOKSTRUCT hook;
1648 BOOL eatMsg;
1649 HWND hWndScope = msg->hwnd;
1651 /* find the window to dispatch this mouse message to */
1653 hittest = HTCLIENT;
1654 GetGUIThreadInfo( GetCurrentThreadId(), &info );
1655 if (!(msg->hwnd = info.hwndCapture))
1657 /* If no capture HWND, find window which contains the mouse position.
1658 * Also find the position of the cursor hot spot (hittest) */
1659 if (!IsWindow(hWndScope)) hWndScope = 0;
1660 if (!(msg->hwnd = WINPOS_WindowFromPoint( hWndScope, msg->pt, &hittest )))
1661 msg->hwnd = GetDesktopWindow();
1664 if (!WIN_IsCurrentThread( msg->hwnd ))
1666 accept_hardware_message( hw_id, FALSE, msg->hwnd );
1667 return FALSE;
1670 /* FIXME: is this really the right place for this hook? */
1671 event.message = msg->message;
1672 event.time = msg->time;
1673 event.hwnd = msg->hwnd;
1674 event.paramL = msg->pt.x;
1675 event.paramH = msg->pt.y;
1676 HOOK_CallHooks( WH_JOURNALRECORD, HC_ACTION, 0, (LPARAM)&event, TRUE );
1678 if (!check_hwnd_filter( msg, hwnd_filter )) return FALSE;
1680 pt = msg->pt;
1681 message = msg->message;
1682 /* Note: windows has no concept of a non-client wheel message */
1683 if (message != WM_MOUSEWHEEL)
1685 if (hittest != HTCLIENT)
1687 message += WM_NCMOUSEMOVE - WM_MOUSEMOVE;
1688 msg->wParam = hittest;
1690 else
1692 /* coordinates don't get translated while tracking a menu */
1693 /* FIXME: should differentiate popups and top-level menus */
1694 if (!(info.flags & GUI_INMENUMODE))
1695 ScreenToClient( msg->hwnd, &pt );
1698 msg->lParam = MAKELONG( pt.x, pt.y );
1700 /* translate double clicks */
1702 if ((msg->message == WM_LBUTTONDOWN) ||
1703 (msg->message == WM_RBUTTONDOWN) ||
1704 (msg->message == WM_MBUTTONDOWN) ||
1705 (msg->message == WM_XBUTTONDOWN))
1707 BOOL update = remove;
1709 /* translate double clicks -
1710 * note that ...MOUSEMOVEs can slip in between
1711 * ...BUTTONDOWN and ...BUTTONDBLCLK messages */
1713 if ((info.flags & (GUI_INMENUMODE|GUI_INMOVESIZE)) ||
1714 hittest != HTCLIENT ||
1715 (GetClassLongA( msg->hwnd, GCL_STYLE ) & CS_DBLCLKS))
1717 if ((msg->message == clk_msg.message) &&
1718 (msg->hwnd == clk_msg.hwnd) &&
1719 (msg->wParam == clk_msg.wParam) &&
1720 (msg->time - clk_msg.time < GetDoubleClickTime()) &&
1721 (abs(msg->pt.x - clk_msg.pt.x) < GetSystemMetrics(SM_CXDOUBLECLK)/2) &&
1722 (abs(msg->pt.y - clk_msg.pt.y) < GetSystemMetrics(SM_CYDOUBLECLK)/2))
1724 message += (WM_LBUTTONDBLCLK - WM_LBUTTONDOWN);
1725 if (update)
1727 clk_msg.message = 0; /* clear the double click conditions */
1728 update = FALSE;
1732 if (message < first || message > last) return FALSE;
1733 /* update static double click conditions */
1734 if (update) clk_msg = *msg;
1736 else
1738 if (message < first || message > last) return FALSE;
1741 /* message is accepted now (but may still get dropped) */
1743 hook.pt = msg->pt;
1744 hook.hwnd = msg->hwnd;
1745 hook.wHitTestCode = hittest;
1746 hook.dwExtraInfo = extra_info;
1747 if (HOOK_CallHooks( WH_MOUSE, remove ? HC_ACTION : HC_NOREMOVE,
1748 message, (LPARAM)&hook, TRUE ))
1750 hook.pt = msg->pt;
1751 hook.hwnd = msg->hwnd;
1752 hook.wHitTestCode = hittest;
1753 hook.dwExtraInfo = extra_info;
1754 HOOK_CallHooks( WH_CBT, HCBT_CLICKSKIPPED, message, (LPARAM)&hook, TRUE );
1755 accept_hardware_message( hw_id, TRUE, 0 );
1756 return FALSE;
1759 if ((hittest == HTERROR) || (hittest == HTNOWHERE))
1761 SendMessageW( msg->hwnd, WM_SETCURSOR, (WPARAM)msg->hwnd,
1762 MAKELONG( hittest, msg->message ));
1763 accept_hardware_message( hw_id, TRUE, 0 );
1764 return FALSE;
1767 accept_hardware_message( hw_id, remove, 0 );
1769 if (!remove || info.hwndCapture)
1771 msg->message = message;
1772 return TRUE;
1775 eatMsg = FALSE;
1777 if ((msg->message == WM_LBUTTONDOWN) ||
1778 (msg->message == WM_RBUTTONDOWN) ||
1779 (msg->message == WM_MBUTTONDOWN) ||
1780 (msg->message == WM_XBUTTONDOWN))
1782 /* Send the WM_PARENTNOTIFY,
1783 * note that even for double/nonclient clicks
1784 * notification message is still WM_L/M/RBUTTONDOWN.
1786 send_parent_notify( msg->hwnd, msg->message, 0, msg->pt );
1788 /* Activate the window if needed */
1790 if (msg->hwnd != info.hwndActive)
1792 HWND hwndTop = msg->hwnd;
1793 while (hwndTop)
1795 if ((GetWindowLongW( hwndTop, GWL_STYLE ) & (WS_POPUP|WS_CHILD)) != WS_CHILD) break;
1796 hwndTop = GetParent( hwndTop );
1799 if (hwndTop && hwndTop != GetDesktopWindow())
1801 LONG ret = SendMessageW( msg->hwnd, WM_MOUSEACTIVATE, (WPARAM)hwndTop,
1802 MAKELONG( hittest, msg->message ) );
1803 switch(ret)
1805 case MA_NOACTIVATEANDEAT:
1806 eatMsg = TRUE;
1807 /* fall through */
1808 case MA_NOACTIVATE:
1809 break;
1810 case MA_ACTIVATEANDEAT:
1811 eatMsg = TRUE;
1812 /* fall through */
1813 case MA_ACTIVATE:
1814 case 0:
1815 if (!FOCUS_MouseActivate( hwndTop )) eatMsg = TRUE;
1816 break;
1817 default:
1818 WARN( "unknown WM_MOUSEACTIVATE code %ld\n", ret );
1819 break;
1825 /* send the WM_SETCURSOR message */
1827 /* Windows sends the normal mouse message as the message parameter
1828 in the WM_SETCURSOR message even if it's non-client mouse message */
1829 SendMessageW( msg->hwnd, WM_SETCURSOR, (WPARAM)msg->hwnd, MAKELONG( hittest, msg->message ));
1831 msg->message = message;
1832 return !eatMsg;
1836 /***********************************************************************
1837 * process_hardware_message
1839 * Process a hardware message; return TRUE if message should be passed on to the app
1841 static BOOL process_hardware_message( MSG *msg, UINT hw_id, ULONG_PTR extra_info, HWND hwnd_filter,
1842 UINT first, UINT last, BOOL remove )
1844 if (is_keyboard_message( msg->message ))
1845 return process_keyboard_message( msg, hw_id, hwnd_filter, first, last, remove );
1847 if (is_mouse_message( msg->message ))
1848 return process_mouse_message( msg, hw_id, extra_info, hwnd_filter, first, last, remove );
1850 ERR( "unknown message type %x\n", msg->message );
1851 return FALSE;
1855 /***********************************************************************
1856 * call_sendmsg_callback
1858 * Call the callback function of SendMessageCallback.
1860 static inline void call_sendmsg_callback( SENDASYNCPROC callback, HWND hwnd, UINT msg,
1861 ULONG_PTR data, LRESULT result )
1863 if (TRACE_ON(relay))
1864 DPRINTF( "%04lx:Call message callback %p (hwnd=%p,msg=%s,data=%08lx,result=%08lx)\n",
1865 GetCurrentThreadId(), callback, hwnd, SPY_GetMsgName( msg, hwnd ),
1866 data, result );
1867 callback( hwnd, msg, data, result );
1868 if (TRACE_ON(relay))
1869 DPRINTF( "%04lx:Ret message callback %p (hwnd=%p,msg=%s,data=%08lx,result=%08lx)\n",
1870 GetCurrentThreadId(), callback, hwnd, SPY_GetMsgName( msg, hwnd ),
1871 data, result );
1875 /***********************************************************************
1876 * get_hook_proc
1878 * Retrieve the hook procedure real value for a module-relative proc
1880 static void *get_hook_proc( void *proc, const WCHAR *module )
1882 HMODULE mod;
1884 if (!(mod = GetModuleHandleW(module)))
1886 TRACE( "loading %s\n", debugstr_w(module) );
1887 /* FIXME: the library will never be freed */
1888 if (!(mod = LoadLibraryW(module))) return NULL;
1890 return (char *)mod + (ULONG_PTR)proc;
1894 /***********************************************************************
1895 * peek_message
1897 * Peek for a message matching the given parameters. Return FALSE if none available.
1898 * All pending sent messages are processed before returning.
1900 static BOOL peek_message( MSG *msg, HWND hwnd, UINT first, UINT last, int flags )
1902 LRESULT result;
1903 ULONG_PTR extra_info = 0;
1904 struct user_thread_info *thread_info = get_user_thread_info();
1905 struct received_message_info info, *old_info;
1906 unsigned int hw_id = 0; /* id of previous hardware message */
1908 if (!first && !last) last = ~0;
1910 for (;;)
1912 NTSTATUS res;
1913 void *buffer = NULL;
1914 size_t size = 0, buffer_size = 0;
1916 do /* loop while buffer is too small */
1918 if (buffer_size && !(buffer = HeapAlloc( GetProcessHeap(), 0, buffer_size )))
1919 return FALSE;
1920 SERVER_START_REQ( get_message )
1922 req->flags = flags;
1923 req->get_win = hwnd;
1924 req->get_first = first;
1925 req->get_last = last;
1926 req->hw_id = hw_id;
1927 if (buffer_size) wine_server_set_reply( req, buffer, buffer_size );
1928 if (!(res = wine_server_call( req )))
1930 size = wine_server_reply_size( reply );
1931 info.type = reply->type;
1932 info.msg.hwnd = reply->win;
1933 info.msg.message = reply->msg;
1934 info.msg.wParam = reply->wparam;
1935 info.msg.lParam = reply->lparam;
1936 info.msg.time = reply->time;
1937 info.msg.pt.x = reply->x;
1938 info.msg.pt.y = reply->y;
1939 info.hook = reply->hook;
1940 info.hook_proc = reply->hook_proc;
1941 hw_id = reply->hw_id;
1942 extra_info = reply->info;
1943 thread_info->active_hooks = reply->active_hooks;
1945 else
1947 HeapFree( GetProcessHeap(), 0, buffer );
1948 buffer_size = reply->total;
1951 SERVER_END_REQ;
1952 } while (res == STATUS_BUFFER_OVERFLOW);
1954 if (res) return FALSE;
1956 TRACE( "got type %d msg %x (%s) hwnd %p wp %x lp %lx\n",
1957 info.type, info.msg.message,
1958 (info.type == MSG_WINEVENT) ? "MSG_WINEVENT" : SPY_GetMsgName(info.msg.message, info.msg.hwnd),
1959 info.msg.hwnd, info.msg.wParam, info.msg.lParam );
1961 switch(info.type)
1963 case MSG_ASCII:
1964 case MSG_UNICODE:
1965 info.flags = ISMEX_SEND;
1966 break;
1967 case MSG_NOTIFY:
1968 info.flags = ISMEX_NOTIFY;
1969 break;
1970 case MSG_CALLBACK:
1971 info.flags = ISMEX_CALLBACK;
1972 break;
1973 case MSG_CALLBACK_RESULT:
1974 call_sendmsg_callback( (SENDASYNCPROC)info.msg.wParam, info.msg.hwnd,
1975 info.msg.message, extra_info, info.msg.lParam );
1976 goto next;
1977 case MSG_WINEVENT:
1978 if (size)
1980 WCHAR module[MAX_PATH];
1981 size = min( size, (MAX_PATH - 1) * sizeof(WCHAR) );
1982 memcpy( module, buffer, size );
1983 module[size / sizeof(WCHAR)] = 0;
1984 if (!(info.hook_proc = get_hook_proc( info.hook_proc, module )))
1986 ERR( "invalid winevent hook module name %s\n", debugstr_w(module) );
1987 goto next;
1990 if (TRACE_ON(relay))
1991 DPRINTF( "%04lx:Call winevent proc %p (hook=%p,event=%x,hwnd=%p,object_id=%x,child_id=%lx,tid=%04lx,time=%lx)\n",
1992 GetCurrentThreadId(), info.hook_proc,
1993 info.hook, info.msg.message, info.msg.hwnd, info.msg.wParam,
1994 info.msg.lParam, extra_info, info.msg.time);
1996 info.hook_proc( info.hook, info.msg.message, info.msg.hwnd, info.msg.wParam,
1997 info.msg.lParam, extra_info, info.msg.time );
1999 if (TRACE_ON(relay))
2000 DPRINTF( "%04lx:Ret winevent proc %p (hook=%p,event=%x,hwnd=%p,object_id=%x,child_id=%lx,tid=%04lx,time=%lx)\n",
2001 GetCurrentThreadId(), info.hook_proc,
2002 info.hook, info.msg.message, info.msg.hwnd, info.msg.wParam,
2003 info.msg.lParam, extra_info, info.msg.time);
2004 goto next;
2005 case MSG_OTHER_PROCESS:
2006 info.flags = ISMEX_SEND;
2007 if (!unpack_message( info.msg.hwnd, info.msg.message, &info.msg.wParam,
2008 &info.msg.lParam, &buffer, size ))
2010 ERR( "invalid packed message %x (%s) hwnd %p wp %x lp %lx size %d\n",
2011 info.msg.message, SPY_GetMsgName(info.msg.message, info.msg.hwnd), info.msg.hwnd,
2012 info.msg.wParam, info.msg.lParam, size );
2013 /* ignore it */
2014 reply_message( &info, 0, TRUE );
2015 goto next;
2017 break;
2018 case MSG_HARDWARE:
2019 if (!process_hardware_message( &info.msg, hw_id, extra_info,
2020 hwnd, first, last, flags & GET_MSG_REMOVE ))
2022 TRACE("dropping msg %x\n", info.msg.message );
2023 goto next; /* ignore it */
2025 thread_info->GetMessagePosVal = MAKELONG( info.msg.pt.x, info.msg.pt.y );
2026 /* fall through */
2027 case MSG_POSTED:
2028 thread_info->GetMessageExtraInfoVal = extra_info;
2029 if (info.msg.message >= WM_DDE_FIRST && info.msg.message <= WM_DDE_LAST)
2031 if (!unpack_dde_message( info.msg.hwnd, info.msg.message, &info.msg.wParam,
2032 &info.msg.lParam, &buffer, size ))
2034 ERR( "invalid packed dde-message %x (%s) hwnd %p wp %x lp %lx size %d\n",
2035 info.msg.message, SPY_GetMsgName(info.msg.message, info.msg.hwnd),
2036 info.msg.hwnd, info.msg.wParam, info.msg.lParam, size );
2037 goto next; /* ignore it */
2040 *msg = info.msg;
2041 HeapFree( GetProcessHeap(), 0, buffer );
2042 return TRUE;
2045 /* if we get here, we have a sent message; call the window procedure */
2046 old_info = thread_info->receive_info;
2047 thread_info->receive_info = &info;
2048 result = call_window_proc( info.msg.hwnd, info.msg.message, info.msg.wParam,
2049 info.msg.lParam, (info.type != MSG_ASCII), FALSE );
2050 reply_message( &info, result, TRUE );
2051 thread_info->receive_info = old_info;
2052 next:
2053 HeapFree( GetProcessHeap(), 0, buffer );
2058 /***********************************************************************
2059 * process_sent_messages
2061 * Process all pending sent messages.
2063 inline static void process_sent_messages(void)
2065 MSG msg;
2066 peek_message( &msg, 0, 0, 0, GET_MSG_REMOVE | GET_MSG_SENT_ONLY );
2070 /***********************************************************************
2071 * get_server_queue_handle
2073 * Get a handle to the server message queue for the current thread.
2075 static HANDLE get_server_queue_handle(void)
2077 struct user_thread_info *thread_info = get_user_thread_info();
2078 HANDLE ret;
2080 if (!(ret = thread_info->server_queue))
2082 SERVER_START_REQ( get_msg_queue )
2084 wine_server_call( req );
2085 ret = reply->handle;
2087 SERVER_END_REQ;
2088 thread_info->server_queue = ret;
2089 if (!ret) ERR( "Cannot get server thread queue\n" );
2091 return ret;
2095 /***********************************************************************
2096 * wait_message_reply
2098 * Wait until a sent message gets replied to.
2100 static void wait_message_reply( UINT flags )
2102 HANDLE server_queue = get_server_queue_handle();
2104 for (;;)
2106 unsigned int wake_bits = 0, changed_bits = 0;
2107 DWORD dwlc, res;
2109 SERVER_START_REQ( set_queue_mask )
2111 req->wake_mask = QS_SMRESULT | ((flags & SMTO_BLOCK) ? 0 : QS_SENDMESSAGE);
2112 req->changed_mask = req->wake_mask;
2113 req->skip_wait = 1;
2114 if (!wine_server_call( req ))
2116 wake_bits = reply->wake_bits;
2117 changed_bits = reply->changed_bits;
2120 SERVER_END_REQ;
2122 if (wake_bits & QS_SMRESULT) return; /* got a result */
2123 if (wake_bits & QS_SENDMESSAGE)
2125 /* Process the sent message immediately */
2126 process_sent_messages();
2127 continue;
2130 /* now wait for it */
2132 ReleaseThunkLock( &dwlc );
2133 res = USER_Driver->pMsgWaitForMultipleObjectsEx( 1, &server_queue,
2134 INFINITE, QS_ALLINPUT, 0 );
2135 if (dwlc) RestoreThunkLock( dwlc );
2139 /***********************************************************************
2140 * put_message_in_queue
2142 * Put a sent message into the destination queue.
2143 * For inter-process message, reply_size is set to expected size of reply data.
2145 static BOOL put_message_in_queue( DWORD dest_tid, const struct send_message_info *info,
2146 size_t *reply_size )
2148 struct packed_message data;
2149 unsigned int res;
2150 int i, timeout = -1;
2152 if (info->type != MSG_NOTIFY &&
2153 info->type != MSG_CALLBACK &&
2154 info->type != MSG_POSTED &&
2155 info->timeout != INFINITE)
2156 timeout = info->timeout;
2158 data.count = 0;
2159 if (info->type == MSG_OTHER_PROCESS)
2161 *reply_size = pack_message( info->hwnd, info->msg, info->wparam, info->lparam, &data );
2162 if (data.count == -1)
2164 WARN( "cannot pack message %x\n", info->msg );
2165 return FALSE;
2168 else if (info->type == MSG_POSTED && info->msg >= WM_DDE_FIRST && info->msg <= WM_DDE_LAST)
2170 return post_dde_message( dest_tid, &data, info );
2173 SERVER_START_REQ( send_message )
2175 req->id = dest_tid;
2176 req->type = info->type;
2177 req->flags = 0;
2178 req->win = info->hwnd;
2179 req->msg = info->msg;
2180 req->wparam = info->wparam;
2181 req->lparam = info->lparam;
2182 req->time = GetCurrentTime();
2183 req->timeout = timeout;
2185 if (info->type == MSG_CALLBACK)
2187 req->callback = info->callback;
2188 req->info = info->data;
2191 if (info->flags & SMTO_ABORTIFHUNG) req->flags |= SEND_MSG_ABORT_IF_HUNG;
2192 for (i = 0; i < data.count; i++) wine_server_add_data( req, data.data[i], data.size[i] );
2193 if ((res = wine_server_call( req )))
2195 if (res == STATUS_INVALID_PARAMETER)
2196 /* FIXME: find a STATUS_ value for this one */
2197 SetLastError( ERROR_INVALID_THREAD_ID );
2198 else
2199 SetLastError( RtlNtStatusToDosError(res) );
2202 SERVER_END_REQ;
2203 return !res;
2207 /***********************************************************************
2208 * retrieve_reply
2210 * Retrieve a message reply from the server.
2212 static LRESULT retrieve_reply( const struct send_message_info *info,
2213 size_t reply_size, LRESULT *result )
2215 NTSTATUS status;
2216 void *reply_data = NULL;
2218 if (reply_size)
2220 if (!(reply_data = HeapAlloc( GetProcessHeap(), 0, reply_size )))
2222 WARN( "no memory for reply %d bytes, will be truncated\n", reply_size );
2223 reply_size = 0;
2226 SERVER_START_REQ( get_message_reply )
2228 req->cancel = 1;
2229 if (reply_size) wine_server_set_reply( req, reply_data, reply_size );
2230 if (!(status = wine_server_call( req ))) *result = reply->result;
2231 reply_size = wine_server_reply_size( reply );
2233 SERVER_END_REQ;
2234 if (!status && reply_size)
2235 unpack_reply( info->hwnd, info->msg, info->wparam, info->lparam, reply_data, reply_size );
2237 HeapFree( GetProcessHeap(), 0, reply_data );
2239 TRACE( "hwnd %p msg %x (%s) wp %x lp %lx got reply %lx (err=%ld)\n",
2240 info->hwnd, info->msg, SPY_GetMsgName(info->msg, info->hwnd), info->wparam,
2241 info->lparam, *result, status );
2243 /* MSDN states that last error is 0 on timeout, but at least NT4 returns ERROR_TIMEOUT */
2244 if (status) SetLastError( RtlNtStatusToDosError(status) );
2245 return !status;
2249 /***********************************************************************
2250 * send_inter_thread_message
2252 static LRESULT send_inter_thread_message( DWORD dest_tid, const struct send_message_info *info,
2253 LRESULT *res_ptr )
2255 size_t reply_size = 0;
2257 TRACE( "hwnd %p msg %x (%s) wp %x lp %lx\n",
2258 info->hwnd, info->msg, SPY_GetMsgName(info->msg, info->hwnd), info->wparam, info->lparam );
2260 USER_CheckNotLock();
2262 if (!put_message_in_queue( dest_tid, info, &reply_size )) return 0;
2264 /* there's no reply to wait for on notify/callback messages */
2265 if (info->type == MSG_NOTIFY || info->type == MSG_CALLBACK) return 1;
2267 wait_message_reply( info->flags );
2268 return retrieve_reply( info, reply_size, res_ptr );
2272 /***********************************************************************
2273 * MSG_SendInternalMessageTimeout
2275 * Same as SendMessageTimeoutW but sends the message to a specific thread
2276 * without requiring a window handle. Only works for internal Wine messages.
2278 LRESULT MSG_SendInternalMessageTimeout( DWORD dest_pid, DWORD dest_tid,
2279 UINT msg, WPARAM wparam, LPARAM lparam,
2280 UINT flags, UINT timeout, PDWORD_PTR res_ptr )
2282 struct send_message_info info;
2283 LRESULT ret, result;
2285 assert( msg & 0x80000000 ); /* must be an internal Wine message */
2287 info.type = MSG_UNICODE;
2288 info.hwnd = 0;
2289 info.msg = msg;
2290 info.wparam = wparam;
2291 info.lparam = lparam;
2292 info.flags = flags;
2293 info.timeout = timeout;
2295 if (USER_IsExitingThread( dest_tid )) return 0;
2297 if (dest_tid == GetCurrentThreadId())
2299 result = handle_internal_message( 0, msg, wparam, lparam );
2300 ret = 1;
2302 else
2304 if (dest_pid != GetCurrentProcessId()) info.type = MSG_OTHER_PROCESS;
2305 ret = send_inter_thread_message( dest_tid, &info, &result );
2307 if (ret && res_ptr) *res_ptr = result;
2308 return ret;
2312 /***********************************************************************
2313 * SendMessageTimeoutW (USER32.@)
2315 LRESULT WINAPI SendMessageTimeoutW( HWND hwnd, UINT msg, WPARAM wparam, LPARAM lparam,
2316 UINT flags, UINT timeout, PDWORD_PTR res_ptr )
2318 struct send_message_info info;
2319 DWORD dest_tid, dest_pid;
2320 LRESULT ret, result;
2322 info.type = MSG_UNICODE;
2323 info.hwnd = hwnd;
2324 info.msg = msg;
2325 info.wparam = wparam;
2326 info.lparam = lparam;
2327 info.flags = flags;
2328 info.timeout = timeout;
2330 if (is_broadcast(hwnd))
2332 EnumWindows( broadcast_message_callback, (LPARAM)&info );
2333 if (res_ptr) *res_ptr = 1;
2334 return 1;
2337 if (!(dest_tid = GetWindowThreadProcessId( hwnd, &dest_pid ))) return 0;
2339 if (USER_IsExitingThread( dest_tid )) return 0;
2341 SPY_EnterMessage( SPY_SENDMESSAGE, hwnd, msg, wparam, lparam );
2343 if (dest_tid == GetCurrentThreadId())
2345 result = call_window_proc( hwnd, msg, wparam, lparam, TRUE, TRUE );
2346 ret = 1;
2348 else
2350 if (dest_pid != GetCurrentProcessId()) info.type = MSG_OTHER_PROCESS;
2351 ret = send_inter_thread_message( dest_tid, &info, &result );
2354 SPY_ExitMessage( SPY_RESULT_OK, hwnd, msg, result, wparam, lparam );
2355 if (ret && res_ptr) *res_ptr = result;
2356 return ret;
2360 /***********************************************************************
2361 * SendMessageTimeoutA (USER32.@)
2363 LRESULT WINAPI SendMessageTimeoutA( HWND hwnd, UINT msg, WPARAM wparam, LPARAM lparam,
2364 UINT flags, UINT timeout, PDWORD_PTR res_ptr )
2366 struct send_message_info info;
2367 DWORD dest_tid, dest_pid;
2368 LRESULT ret, result;
2370 info.type = MSG_ASCII;
2371 info.hwnd = hwnd;
2372 info.msg = msg;
2373 info.wparam = wparam;
2374 info.lparam = lparam;
2375 info.flags = flags;
2376 info.timeout = timeout;
2378 if (is_broadcast(hwnd))
2380 EnumWindows( broadcast_message_callback, (LPARAM)&info );
2381 if (res_ptr) *res_ptr = 1;
2382 return 1;
2385 if (!(dest_tid = GetWindowThreadProcessId( hwnd, &dest_pid ))) return 0;
2387 if (USER_IsExitingThread( dest_tid )) return 0;
2389 SPY_EnterMessage( SPY_SENDMESSAGE, hwnd, msg, wparam, lparam );
2391 if (dest_tid == GetCurrentThreadId())
2393 result = call_window_proc( hwnd, msg, wparam, lparam, FALSE, TRUE );
2394 ret = 1;
2396 else if (dest_pid == GetCurrentProcessId())
2398 ret = send_inter_thread_message( dest_tid, &info, &result );
2400 else
2402 /* inter-process message: need to map to Unicode */
2403 info.type = MSG_OTHER_PROCESS;
2404 if (is_unicode_message( info.msg ))
2406 if (WINPROC_MapMsg32ATo32W( info.hwnd, info.msg, &info.wparam, &info.lparam ) == -1)
2407 return 0;
2408 ret = send_inter_thread_message( dest_tid, &info, &result );
2409 result = WINPROC_UnmapMsg32ATo32W( info.hwnd, info.msg, info.wparam,
2410 info.lparam, result );
2412 else ret = send_inter_thread_message( dest_tid, &info, &result );
2414 SPY_ExitMessage( SPY_RESULT_OK, hwnd, msg, result, wparam, lparam );
2415 if (ret && res_ptr) *res_ptr = result;
2416 return ret;
2420 /***********************************************************************
2421 * SendMessageW (USER32.@)
2423 LRESULT WINAPI SendMessageW( HWND hwnd, UINT msg, WPARAM wparam, LPARAM lparam )
2425 DWORD_PTR res = 0;
2426 SendMessageTimeoutW( hwnd, msg, wparam, lparam, SMTO_NORMAL, INFINITE, &res );
2427 return res;
2431 /***********************************************************************
2432 * SendMessageA (USER32.@)
2434 LRESULT WINAPI SendMessageA( HWND hwnd, UINT msg, WPARAM wparam, LPARAM lparam )
2436 DWORD_PTR res = 0;
2437 SendMessageTimeoutA( hwnd, msg, wparam, lparam, SMTO_NORMAL, INFINITE, &res );
2438 return res;
2442 /***********************************************************************
2443 * SendNotifyMessageA (USER32.@)
2445 BOOL WINAPI SendNotifyMessageA( HWND hwnd, UINT msg, WPARAM wparam, LPARAM lparam )
2447 return SendNotifyMessageW( hwnd, msg, map_wparam_AtoW( msg, wparam ), lparam );
2451 /***********************************************************************
2452 * SendNotifyMessageW (USER32.@)
2454 BOOL WINAPI SendNotifyMessageW( HWND hwnd, UINT msg, WPARAM wparam, LPARAM lparam )
2456 struct send_message_info info;
2457 DWORD dest_tid;
2458 LRESULT result;
2460 if (is_pointer_message(msg))
2462 SetLastError( ERROR_MESSAGE_SYNC_ONLY );
2463 return FALSE;
2466 info.type = MSG_NOTIFY;
2467 info.hwnd = hwnd;
2468 info.msg = msg;
2469 info.wparam = wparam;
2470 info.lparam = lparam;
2471 info.flags = 0;
2473 if (is_broadcast(hwnd))
2475 EnumWindows( broadcast_message_callback, (LPARAM)&info );
2476 return TRUE;
2479 if (!(dest_tid = GetWindowThreadProcessId( hwnd, NULL ))) return FALSE;
2481 if (USER_IsExitingThread( dest_tid )) return TRUE;
2483 if (dest_tid == GetCurrentThreadId())
2485 call_window_proc( hwnd, msg, wparam, lparam, TRUE, TRUE );
2486 return TRUE;
2488 return send_inter_thread_message( dest_tid, &info, &result );
2492 /***********************************************************************
2493 * SendMessageCallbackA (USER32.@)
2495 BOOL WINAPI SendMessageCallbackA( HWND hwnd, UINT msg, WPARAM wparam, LPARAM lparam,
2496 SENDASYNCPROC callback, ULONG_PTR data )
2498 return SendMessageCallbackW( hwnd, msg, map_wparam_AtoW( msg, wparam ),
2499 lparam, callback, data );
2503 /***********************************************************************
2504 * SendMessageCallbackW (USER32.@)
2506 BOOL WINAPI SendMessageCallbackW( HWND hwnd, UINT msg, WPARAM wparam, LPARAM lparam,
2507 SENDASYNCPROC callback, ULONG_PTR data )
2509 struct send_message_info info;
2510 LRESULT result;
2511 DWORD dest_tid;
2513 if (is_pointer_message(msg))
2515 SetLastError( ERROR_MESSAGE_SYNC_ONLY );
2516 return FALSE;
2519 info.type = MSG_CALLBACK;
2520 info.hwnd = hwnd;
2521 info.msg = msg;
2522 info.wparam = wparam;
2523 info.lparam = lparam;
2524 info.callback = callback;
2525 info.data = data;
2526 info.flags = 0;
2528 if (is_broadcast(hwnd))
2530 EnumWindows( broadcast_message_callback, (LPARAM)&info );
2531 return TRUE;
2534 if (!(dest_tid = GetWindowThreadProcessId( hwnd, NULL ))) return FALSE;
2536 if (USER_IsExitingThread( dest_tid )) return TRUE;
2538 if (dest_tid == GetCurrentThreadId())
2540 result = call_window_proc( hwnd, msg, wparam, lparam, TRUE, TRUE );
2541 call_sendmsg_callback( callback, hwnd, msg, data, result );
2542 return TRUE;
2544 FIXME( "callback will not be called\n" );
2545 return send_inter_thread_message( dest_tid, &info, &result );
2549 /***********************************************************************
2550 * ReplyMessage (USER32.@)
2552 BOOL WINAPI ReplyMessage( LRESULT result )
2554 struct received_message_info *info = get_user_thread_info()->receive_info;
2556 if (!info) return FALSE;
2557 reply_message( info, result, FALSE );
2558 return TRUE;
2562 /***********************************************************************
2563 * InSendMessage (USER32.@)
2565 BOOL WINAPI InSendMessage(void)
2567 return (InSendMessageEx(NULL) & (ISMEX_SEND|ISMEX_REPLIED)) == ISMEX_SEND;
2571 /***********************************************************************
2572 * InSendMessageEx (USER32.@)
2574 DWORD WINAPI InSendMessageEx( LPVOID reserved )
2576 struct received_message_info *info = get_user_thread_info()->receive_info;
2578 if (info) return info->flags;
2579 return ISMEX_NOSEND;
2583 /***********************************************************************
2584 * PostMessageA (USER32.@)
2586 BOOL WINAPI PostMessageA( HWND hwnd, UINT msg, WPARAM wparam, LPARAM lparam )
2588 return PostMessageW( hwnd, msg, map_wparam_AtoW( msg, wparam ), lparam );
2592 /***********************************************************************
2593 * PostMessageW (USER32.@)
2595 BOOL WINAPI PostMessageW( HWND hwnd, UINT msg, WPARAM wparam, LPARAM lparam )
2597 struct send_message_info info;
2598 DWORD dest_tid;
2600 if (is_pointer_message( msg ))
2602 SetLastError( ERROR_MESSAGE_SYNC_ONLY );
2603 return FALSE;
2606 TRACE( "hwnd %p msg %x (%s) wp %x lp %lx\n",
2607 hwnd, msg, SPY_GetMsgName(msg, hwnd), wparam, lparam );
2609 info.type = MSG_POSTED;
2610 info.hwnd = hwnd;
2611 info.msg = msg;
2612 info.wparam = wparam;
2613 info.lparam = lparam;
2614 info.flags = 0;
2616 if (is_broadcast(hwnd))
2618 EnumWindows( broadcast_message_callback, (LPARAM)&info );
2619 return TRUE;
2622 if (!hwnd) return PostThreadMessageW( GetCurrentThreadId(), msg, wparam, lparam );
2624 if (!(dest_tid = GetWindowThreadProcessId( hwnd, NULL ))) return FALSE;
2626 if (USER_IsExitingThread( dest_tid )) return TRUE;
2628 return put_message_in_queue( dest_tid, &info, NULL );
2632 /**********************************************************************
2633 * PostThreadMessageA (USER32.@)
2635 BOOL WINAPI PostThreadMessageA( DWORD thread, UINT msg, WPARAM wparam, LPARAM lparam )
2637 return PostThreadMessageW( thread, msg, map_wparam_AtoW( msg, wparam ), lparam );
2641 /**********************************************************************
2642 * PostThreadMessageW (USER32.@)
2644 BOOL WINAPI PostThreadMessageW( DWORD thread, UINT msg, WPARAM wparam, LPARAM lparam )
2646 struct send_message_info info;
2648 if (is_pointer_message( msg ))
2650 SetLastError( ERROR_MESSAGE_SYNC_ONLY );
2651 return FALSE;
2653 if (USER_IsExitingThread( thread )) return TRUE;
2655 info.type = MSG_POSTED;
2656 info.hwnd = 0;
2657 info.msg = msg;
2658 info.wparam = wparam;
2659 info.lparam = lparam;
2660 info.flags = 0;
2661 return put_message_in_queue( thread, &info, NULL );
2665 /***********************************************************************
2666 * PostQuitMessage (USER32.@)
2668 void WINAPI PostQuitMessage( INT exitCode )
2670 PostThreadMessageW( GetCurrentThreadId(), WM_QUIT, exitCode, 0 );
2674 /***********************************************************************
2675 * PeekMessageW (USER32.@)
2677 BOOL WINAPI PeekMessageW( MSG *msg_out, HWND hwnd, UINT first, UINT last, UINT flags )
2679 struct user_thread_info *thread_info = get_user_thread_info();
2680 MSG msg;
2682 USER_CheckNotLock();
2684 /* check for graphics events */
2685 USER_Driver->pMsgWaitForMultipleObjectsEx( 0, NULL, 0, QS_ALLINPUT, 0 );
2687 hwnd = WIN_GetFullHandle( hwnd );
2689 for (;;)
2691 if (!peek_message( &msg, hwnd, first, last, (flags & PM_REMOVE) ? GET_MSG_REMOVE : 0 ))
2693 if (!(flags & PM_NOYIELD))
2695 DWORD count;
2696 ReleaseThunkLock(&count);
2697 NtYieldExecution();
2698 if (count) RestoreThunkLock(count);
2700 return FALSE;
2702 if (msg.message & 0x80000000)
2704 handle_internal_message( msg.hwnd, msg.message, msg.wParam, msg.lParam );
2705 if (!(flags & PM_REMOVE)) /* have to remove it explicitly */
2706 peek_message( &msg, msg.hwnd, msg.message, msg.message, GET_MSG_REMOVE );
2708 else break;
2711 thread_info->GetMessageTimeVal = msg.time;
2712 msg.pt.x = LOWORD( thread_info->GetMessagePosVal );
2713 msg.pt.y = HIWORD( thread_info->GetMessagePosVal );
2715 HOOK_CallHooks( WH_GETMESSAGE, HC_ACTION, flags & PM_REMOVE, (LPARAM)&msg, TRUE );
2717 /* copy back our internal safe copy of message data to msg_out.
2718 * msg_out is a variable from the *program*, so it can't be used
2719 * internally as it can get "corrupted" by our use of SendMessage()
2720 * (back to the program) inside the message handling itself. */
2721 if (!msg_out)
2723 SetLastError( ERROR_NOACCESS );
2724 return FALSE;
2726 *msg_out = msg;
2727 return TRUE;
2731 /***********************************************************************
2732 * PeekMessageA (USER32.@)
2734 BOOL WINAPI PeekMessageA( MSG *msg, HWND hwnd, UINT first, UINT last, UINT flags )
2736 BOOL ret = PeekMessageW( msg, hwnd, first, last, flags );
2737 if (ret) msg->wParam = map_wparam_WtoA( msg->message, msg->wParam );
2738 return ret;
2742 /***********************************************************************
2743 * GetMessageW (USER32.@)
2745 BOOL WINAPI GetMessageW( MSG *msg, HWND hwnd, UINT first, UINT last )
2747 HANDLE server_queue = get_server_queue_handle();
2748 int mask = QS_POSTMESSAGE | QS_SENDMESSAGE; /* Always selected */
2750 if (first || last)
2752 if ((first <= WM_KEYLAST) && (last >= WM_KEYFIRST)) mask |= QS_KEY;
2753 if ( ((first <= WM_MOUSELAST) && (last >= WM_MOUSEFIRST)) ||
2754 ((first <= WM_NCMOUSELAST) && (last >= WM_NCMOUSEFIRST)) ) mask |= QS_MOUSE;
2755 if ((first <= WM_TIMER) && (last >= WM_TIMER)) mask |= QS_TIMER;
2756 if ((first <= WM_SYSTIMER) && (last >= WM_SYSTIMER)) mask |= QS_TIMER;
2757 if ((first <= WM_PAINT) && (last >= WM_PAINT)) mask |= QS_PAINT;
2759 else mask |= QS_MOUSE | QS_KEY | QS_TIMER | QS_PAINT;
2761 while (!PeekMessageW( msg, hwnd, first, last, PM_REMOVE ))
2763 /* wait until one of the bits is set */
2764 unsigned int wake_bits = 0, changed_bits = 0;
2765 DWORD dwlc;
2767 SERVER_START_REQ( set_queue_mask )
2769 req->wake_mask = QS_SENDMESSAGE;
2770 req->changed_mask = mask;
2771 req->skip_wait = 1;
2772 if (!wine_server_call( req ))
2774 wake_bits = reply->wake_bits;
2775 changed_bits = reply->changed_bits;
2778 SERVER_END_REQ;
2780 if (changed_bits & mask) continue;
2781 if (wake_bits & QS_SENDMESSAGE) continue;
2783 TRACE( "(%04lx) mask=%08x, bits=%08x, changed=%08x, waiting\n",
2784 GetCurrentThreadId(), mask, wake_bits, changed_bits );
2786 ReleaseThunkLock( &dwlc );
2787 USER_Driver->pMsgWaitForMultipleObjectsEx( 1, &server_queue, INFINITE, QS_ALLINPUT, 0 );
2788 if (dwlc) RestoreThunkLock( dwlc );
2791 return (msg->message != WM_QUIT);
2795 /***********************************************************************
2796 * GetMessageA (USER32.@)
2798 BOOL WINAPI GetMessageA( MSG *msg, HWND hwnd, UINT first, UINT last )
2800 GetMessageW( msg, hwnd, first, last );
2801 msg->wParam = map_wparam_WtoA( msg->message, msg->wParam );
2802 return (msg->message != WM_QUIT);
2806 /***********************************************************************
2807 * IsDialogMessage (USER32.@)
2808 * IsDialogMessageA (USER32.@)
2810 BOOL WINAPI IsDialogMessageA( HWND hwndDlg, LPMSG pmsg )
2812 MSG msg = *pmsg;
2813 msg.wParam = map_wparam_AtoW( msg.message, msg.wParam );
2814 return IsDialogMessageW( hwndDlg, &msg );
2818 /***********************************************************************
2819 * TranslateMessage (USER32.@)
2821 * Implementation of TranslateMessage.
2823 * TranslateMessage translates virtual-key messages into character-messages,
2824 * as follows :
2825 * WM_KEYDOWN/WM_KEYUP combinations produce a WM_CHAR or WM_DEADCHAR message.
2826 * ditto replacing WM_* with WM_SYS*
2827 * This produces WM_CHAR messages only for keys mapped to ASCII characters
2828 * by the keyboard driver.
2830 * If the message is WM_KEYDOWN, WM_KEYUP, WM_SYSKEYDOWN, or WM_SYSKEYUP, the
2831 * return value is nonzero, regardless of the translation.
2834 BOOL WINAPI TranslateMessage( const MSG *msg )
2836 UINT message;
2837 WCHAR wp[2];
2838 BYTE state[256];
2840 if (msg->message < WM_KEYFIRST || msg->message > WM_KEYLAST) return FALSE;
2841 if (msg->message != WM_KEYDOWN && msg->message != WM_SYSKEYDOWN) return TRUE;
2843 TRACE_(key)("Translating key %s (%04x), scancode %02x\n",
2844 SPY_GetVKeyName(msg->wParam), msg->wParam, LOBYTE(HIWORD(msg->lParam)));
2846 GetKeyboardState( state );
2847 /* FIXME : should handle ToUnicode yielding 2 */
2848 switch (ToUnicode(msg->wParam, HIWORD(msg->lParam), state, wp, 2, 0))
2850 case 1:
2851 message = (msg->message == WM_KEYDOWN) ? WM_CHAR : WM_SYSCHAR;
2852 TRACE_(key)("1 -> PostMessageW(%p,%s,%04x,%08lx)\n",
2853 msg->hwnd, SPY_GetMsgName(message, msg->hwnd), wp[0], msg->lParam);
2854 PostMessageW( msg->hwnd, message, wp[0], msg->lParam );
2855 break;
2857 case -1:
2858 message = (msg->message == WM_KEYDOWN) ? WM_DEADCHAR : WM_SYSDEADCHAR;
2859 TRACE_(key)("-1 -> PostMessageW(%p,%s,%04x,%08lx)\n",
2860 msg->hwnd, SPY_GetMsgName(message, msg->hwnd), wp[0], msg->lParam);
2861 PostMessageW( msg->hwnd, message, wp[0], msg->lParam );
2862 break;
2864 return TRUE;
2868 /***********************************************************************
2869 * DispatchMessageA (USER32.@)
2871 LONG WINAPI DispatchMessageA( const MSG* msg )
2873 WND * wndPtr;
2874 LONG retval;
2875 WNDPROC winproc;
2877 /* Process timer messages */
2878 if ((msg->message == WM_TIMER) || (msg->message == WM_SYSTIMER))
2880 if (msg->lParam) return CallWindowProcA( (WNDPROC)msg->lParam, msg->hwnd,
2881 msg->message, msg->wParam, GetTickCount() );
2884 if (!(wndPtr = WIN_GetPtr( msg->hwnd )))
2886 if (msg->hwnd) SetLastError( ERROR_INVALID_WINDOW_HANDLE );
2887 return 0;
2889 if (wndPtr == WND_OTHER_PROCESS || wndPtr == WND_DESKTOP)
2891 if (IsWindow( msg->hwnd )) SetLastError( ERROR_MESSAGE_SYNC_ONLY );
2892 else SetLastError( ERROR_INVALID_WINDOW_HANDLE );
2893 return 0;
2895 if (wndPtr->tid != GetCurrentThreadId())
2897 SetLastError( ERROR_MESSAGE_SYNC_ONLY );
2898 WIN_ReleasePtr( wndPtr );
2899 return 0;
2901 winproc = wndPtr->winproc;
2902 WIN_ReleasePtr( wndPtr );
2904 SPY_EnterMessage( SPY_DISPATCHMESSAGE, msg->hwnd, msg->message,
2905 msg->wParam, msg->lParam );
2906 retval = CallWindowProcA( winproc, msg->hwnd, msg->message,
2907 msg->wParam, msg->lParam );
2908 SPY_ExitMessage( SPY_RESULT_OK, msg->hwnd, msg->message, retval,
2909 msg->wParam, msg->lParam );
2911 if (msg->message == WM_PAINT)
2913 /* send a WM_NCPAINT and WM_ERASEBKGND if the non-client area is still invalid */
2914 HRGN hrgn = CreateRectRgn( 0, 0, 0, 0 );
2915 GetUpdateRgn( msg->hwnd, hrgn, TRUE );
2916 DeleteObject( hrgn );
2918 return retval;
2922 /***********************************************************************
2923 * DispatchMessageW (USER32.@) Process a message
2925 * Process the message specified in the structure *_msg_.
2927 * If the lpMsg parameter points to a WM_TIMER message and the
2928 * parameter of the WM_TIMER message is not NULL, the lParam parameter
2929 * points to the function that is called instead of the window
2930 * procedure.
2932 * The message must be valid.
2934 * RETURNS
2936 * DispatchMessage() returns the result of the window procedure invoked.
2938 * CONFORMANCE
2940 * ECMA-234, Win32
2943 LONG WINAPI DispatchMessageW( const MSG* msg )
2945 WND * wndPtr;
2946 LONG retval;
2947 WNDPROC winproc;
2949 /* Process timer messages */
2950 if ((msg->message == WM_TIMER) || (msg->message == WM_SYSTIMER))
2952 if (msg->lParam) return CallWindowProcW( (WNDPROC)msg->lParam, msg->hwnd,
2953 msg->message, msg->wParam, GetTickCount() );
2956 if (!(wndPtr = WIN_GetPtr( msg->hwnd )))
2958 if (msg->hwnd) SetLastError( ERROR_INVALID_WINDOW_HANDLE );
2959 return 0;
2961 if (wndPtr == WND_OTHER_PROCESS || wndPtr == WND_DESKTOP)
2963 if (IsWindow( msg->hwnd )) SetLastError( ERROR_MESSAGE_SYNC_ONLY );
2964 else SetLastError( ERROR_INVALID_WINDOW_HANDLE );
2965 return 0;
2967 if (wndPtr->tid != GetCurrentThreadId())
2969 SetLastError( ERROR_MESSAGE_SYNC_ONLY );
2970 WIN_ReleasePtr( wndPtr );
2971 return 0;
2973 winproc = wndPtr->winproc;
2974 WIN_ReleasePtr( wndPtr );
2976 SPY_EnterMessage( SPY_DISPATCHMESSAGE, msg->hwnd, msg->message,
2977 msg->wParam, msg->lParam );
2978 retval = CallWindowProcW( winproc, msg->hwnd, msg->message,
2979 msg->wParam, msg->lParam );
2980 SPY_ExitMessage( SPY_RESULT_OK, msg->hwnd, msg->message, retval,
2981 msg->wParam, msg->lParam );
2983 if (msg->message == WM_PAINT)
2985 /* send a WM_NCPAINT and WM_ERASEBKGND if the non-client area is still invalid */
2986 HRGN hrgn = CreateRectRgn( 0, 0, 0, 0 );
2987 GetUpdateRgn( msg->hwnd, hrgn, TRUE );
2988 DeleteObject( hrgn );
2990 return retval;
2994 /***********************************************************************
2995 * GetMessagePos (USER.119)
2996 * GetMessagePos (USER32.@)
2998 * The GetMessagePos() function returns a long value representing a
2999 * cursor position, in screen coordinates, when the last message
3000 * retrieved by the GetMessage() function occurs. The x-coordinate is
3001 * in the low-order word of the return value, the y-coordinate is in
3002 * the high-order word. The application can use the MAKEPOINT()
3003 * macro to obtain a POINT structure from the return value.
3005 * For the current cursor position, use GetCursorPos().
3007 * RETURNS
3009 * Cursor position of last message on success, zero on failure.
3011 * CONFORMANCE
3013 * ECMA-234, Win32
3016 DWORD WINAPI GetMessagePos(void)
3018 return get_user_thread_info()->GetMessagePosVal;
3022 /***********************************************************************
3023 * GetMessageTime (USER.120)
3024 * GetMessageTime (USER32.@)
3026 * GetMessageTime() returns the message time for the last message
3027 * retrieved by the function. The time is measured in milliseconds with
3028 * the same offset as GetTickCount().
3030 * Since the tick count wraps, this is only useful for moderately short
3031 * relative time comparisons.
3033 * RETURNS
3035 * Time of last message on success, zero on failure.
3037 LONG WINAPI GetMessageTime(void)
3039 return get_user_thread_info()->GetMessageTimeVal;
3043 /***********************************************************************
3044 * GetMessageExtraInfo (USER.288)
3045 * GetMessageExtraInfo (USER32.@)
3047 LPARAM WINAPI GetMessageExtraInfo(void)
3049 return get_user_thread_info()->GetMessageExtraInfoVal;
3053 /***********************************************************************
3054 * SetMessageExtraInfo (USER32.@)
3056 LPARAM WINAPI SetMessageExtraInfo(LPARAM lParam)
3058 struct user_thread_info *thread_info = get_user_thread_info();
3059 LONG old_value = thread_info->GetMessageExtraInfoVal;
3060 thread_info->GetMessageExtraInfoVal = lParam;
3061 return old_value;
3065 /***********************************************************************
3066 * WaitMessage (USER.112) Suspend thread pending messages
3067 * WaitMessage (USER32.@) Suspend thread pending messages
3069 * WaitMessage() suspends a thread until events appear in the thread's
3070 * queue.
3072 BOOL WINAPI WaitMessage(void)
3074 return (MsgWaitForMultipleObjectsEx( 0, NULL, INFINITE, QS_ALLINPUT, 0 ) != WAIT_FAILED);
3078 /***********************************************************************
3079 * MsgWaitForMultipleObjectsEx (USER32.@)
3081 DWORD WINAPI MsgWaitForMultipleObjectsEx( DWORD count, CONST HANDLE *pHandles,
3082 DWORD timeout, DWORD mask, DWORD flags )
3084 HANDLE handles[MAXIMUM_WAIT_OBJECTS];
3085 DWORD i, ret, lock;
3087 if (count > MAXIMUM_WAIT_OBJECTS-1)
3089 SetLastError( ERROR_INVALID_PARAMETER );
3090 return WAIT_FAILED;
3093 /* set the queue mask */
3094 SERVER_START_REQ( set_queue_mask )
3096 req->wake_mask = (flags & MWMO_INPUTAVAILABLE) ? mask : 0;
3097 req->changed_mask = mask;
3098 req->skip_wait = 0;
3099 wine_server_call( req );
3101 SERVER_END_REQ;
3103 /* Add the thread event to the handle list */
3104 for (i = 0; i < count; i++) handles[i] = pHandles[i];
3105 handles[count] = get_server_queue_handle();
3107 ReleaseThunkLock( &lock );
3108 ret = USER_Driver->pMsgWaitForMultipleObjectsEx( count+1, handles, timeout, mask, flags );
3109 if (ret == count+1) ret = count; /* pretend the msg queue is ready */
3110 if (lock) RestoreThunkLock( lock );
3111 return ret;
3115 /***********************************************************************
3116 * MsgWaitForMultipleObjects (USER32.@)
3118 DWORD WINAPI MsgWaitForMultipleObjects( DWORD count, CONST HANDLE *handles,
3119 BOOL wait_all, DWORD timeout, DWORD mask )
3121 return MsgWaitForMultipleObjectsEx( count, handles, timeout, mask,
3122 wait_all ? MWMO_WAITALL : 0 );
3126 /***********************************************************************
3127 * WaitForInputIdle (USER32.@)
3129 DWORD WINAPI WaitForInputIdle( HANDLE hProcess, DWORD dwTimeOut )
3131 DWORD start_time, elapsed, ret;
3132 HANDLE idle_event = (HANDLE)-1;
3134 SERVER_START_REQ( wait_input_idle )
3136 req->handle = hProcess;
3137 req->timeout = dwTimeOut;
3138 if (!(ret = wine_server_call_err( req ))) idle_event = reply->event;
3140 SERVER_END_REQ;
3141 if (ret) return WAIT_FAILED; /* error */
3142 if (!idle_event) return 0; /* no event to wait on */
3144 start_time = GetTickCount();
3145 elapsed = 0;
3147 TRACE("waiting for %p\n", idle_event );
3150 ret = MsgWaitForMultipleObjects ( 1, &idle_event, FALSE, dwTimeOut - elapsed, QS_SENDMESSAGE );
3151 switch (ret)
3153 case WAIT_OBJECT_0+1:
3154 process_sent_messages();
3155 break;
3156 case WAIT_TIMEOUT:
3157 case WAIT_FAILED:
3158 TRACE("timeout or error\n");
3159 return ret;
3160 default:
3161 TRACE("finished\n");
3162 return 0;
3164 if (dwTimeOut != INFINITE)
3166 elapsed = GetTickCount() - start_time;
3167 if (elapsed > dwTimeOut)
3168 break;
3171 while (1);
3173 return WAIT_TIMEOUT;
3177 /***********************************************************************
3178 * UserYield (USER.332)
3180 void WINAPI UserYield16(void)
3182 DWORD count;
3184 /* Handle sent messages */
3185 process_sent_messages();
3187 /* Yield */
3188 ReleaseThunkLock(&count);
3190 if (count)
3192 RestoreThunkLock(count);
3193 /* Handle sent messages again */
3194 process_sent_messages();
3199 /***********************************************************************
3200 * RegisterWindowMessage (USER.118)
3201 * RegisterWindowMessageA (USER32.@)
3203 WORD WINAPI RegisterWindowMessageA( LPCSTR str )
3205 TRACE("%s\n", str );
3206 return GlobalAddAtomA( str );
3210 /***********************************************************************
3211 * RegisterWindowMessageW (USER32.@)
3213 WORD WINAPI RegisterWindowMessageW( LPCWSTR str )
3215 TRACE("%p\n", str );
3216 return GlobalAddAtomW( str );
3220 /***********************************************************************
3221 * BroadcastSystemMessage (USER32.@)
3222 * BroadcastSystemMessageA (USER32.@)
3224 LONG WINAPI BroadcastSystemMessageA( DWORD flags, LPDWORD recipients, UINT msg, WPARAM wp, LPARAM lp )
3226 if ((*recipients & BSM_APPLICATIONS) || (*recipients == BSM_ALLCOMPONENTS))
3228 FIXME( "(%08lx,%08lx,%08x,%08x,%08lx): semi-stub!\n", flags, *recipients, msg, wp, lp );
3229 PostMessageA( HWND_BROADCAST, msg, wp, lp );
3230 return 1;
3232 else
3234 FIXME( "(%08lx,%08lx,%08x,%08x,%08lx): stub!\n", flags, *recipients, msg, wp, lp);
3235 return -1;
3240 /***********************************************************************
3241 * BroadcastSystemMessageW (USER32.@)
3243 LONG WINAPI BroadcastSystemMessageW( DWORD flags, LPDWORD recipients, UINT msg, WPARAM wp, LPARAM lp )
3245 if ((*recipients & BSM_APPLICATIONS) || (*recipients == BSM_ALLCOMPONENTS))
3247 FIXME( "(%08lx,%08lx,%08x,%08x,%08lx): semi-stub!\n", flags, *recipients, msg, wp, lp );
3248 PostMessageW( HWND_BROADCAST, msg, wp, lp );
3249 return 1;
3251 else
3253 FIXME( "(%08lx,%08lx,%08x,%08x,%08lx): stub!\n", flags, *recipients, msg, wp, lp );
3254 return -1;
3259 /***********************************************************************
3260 * SetMessageQueue (USER32.@)
3262 BOOL WINAPI SetMessageQueue( INT size )
3264 /* now obsolete the message queue will be expanded dynamically as necessary */
3265 return TRUE;
3269 /***********************************************************************
3270 * MessageBeep (USER32.@)
3272 BOOL WINAPI MessageBeep( UINT i )
3274 BOOL active = TRUE;
3275 SystemParametersInfoA( SPI_GETBEEP, 0, &active, FALSE );
3276 if (active) USER_Driver->pBeep();
3277 return TRUE;
3281 /***********************************************************************
3282 * SetTimer (USER32.@)
3284 UINT_PTR WINAPI SetTimer( HWND hwnd, UINT_PTR id, UINT timeout, TIMERPROC proc )
3286 UINT_PTR ret;
3287 WNDPROC winproc = 0;
3289 if (proc) winproc = WINPROC_AllocProc( (WNDPROC)proc, WIN_PROC_32A );
3291 SERVER_START_REQ( set_win_timer )
3293 req->win = hwnd;
3294 req->msg = WM_TIMER;
3295 req->id = id;
3296 req->rate = max( timeout, SYS_TIMER_RATE );
3297 req->lparam = (unsigned int)winproc;
3298 if (!wine_server_call_err( req ))
3300 ret = reply->id;
3301 if (!ret) ret = TRUE;
3303 else ret = 0;
3305 SERVER_END_REQ;
3307 TRACE("Added %p %x %p timeout %d\n", hwnd, id, winproc, timeout );
3308 return ret;
3312 /***********************************************************************
3313 * SetSystemTimer (USER32.@)
3315 UINT_PTR WINAPI SetSystemTimer( HWND hwnd, UINT_PTR id, UINT timeout, TIMERPROC proc )
3317 UINT_PTR ret;
3318 WNDPROC winproc = 0;
3320 if (proc) winproc = WINPROC_AllocProc( (WNDPROC)proc, WIN_PROC_32A );
3322 SERVER_START_REQ( set_win_timer )
3324 req->win = hwnd;
3325 req->msg = WM_SYSTIMER;
3326 req->id = id;
3327 req->rate = max( timeout, SYS_TIMER_RATE );
3328 req->lparam = (unsigned int)winproc;
3329 if (!wine_server_call_err( req ))
3331 ret = reply->id;
3332 if (!ret) ret = TRUE;
3334 else ret = 0;
3336 SERVER_END_REQ;
3338 TRACE("Added %p %x %p timeout %d\n", hwnd, id, winproc, timeout );
3339 return ret;
3343 /***********************************************************************
3344 * KillTimer (USER32.@)
3346 BOOL WINAPI KillTimer( HWND hwnd, UINT_PTR id )
3348 BOOL ret;
3350 TRACE("%p %d\n", hwnd, id );
3352 SERVER_START_REQ( kill_win_timer )
3354 req->win = hwnd;
3355 req->msg = WM_TIMER;
3356 req->id = id;
3357 ret = !wine_server_call_err( req );
3359 SERVER_END_REQ;
3360 return ret;
3364 /***********************************************************************
3365 * KillSystemTimer (USER32.@)
3367 BOOL WINAPI KillSystemTimer( HWND hwnd, UINT_PTR id )
3369 BOOL ret;
3371 TRACE("%p %d\n", hwnd, id );
3373 SERVER_START_REQ( kill_win_timer )
3375 req->win = hwnd;
3376 req->msg = WM_SYSTIMER;
3377 req->id = id;
3378 ret = !wine_server_call_err( req );
3380 SERVER_END_REQ;
3381 return ret;
3385 /**********************************************************************
3386 * GetGUIThreadInfo (USER32.@)
3388 BOOL WINAPI GetGUIThreadInfo( DWORD id, GUITHREADINFO *info )
3390 BOOL ret;
3392 SERVER_START_REQ( get_thread_input )
3394 req->tid = id;
3395 if ((ret = !wine_server_call_err( req )))
3397 info->flags = 0;
3398 info->hwndActive = reply->active;
3399 info->hwndFocus = reply->focus;
3400 info->hwndCapture = reply->capture;
3401 info->hwndMenuOwner = reply->menu_owner;
3402 info->hwndMoveSize = reply->move_size;
3403 info->hwndCaret = reply->caret;
3404 info->rcCaret.left = reply->rect.left;
3405 info->rcCaret.top = reply->rect.top;
3406 info->rcCaret.right = reply->rect.right;
3407 info->rcCaret.bottom = reply->rect.bottom;
3408 if (reply->menu_owner) info->flags |= GUI_INMENUMODE;
3409 if (reply->move_size) info->flags |= GUI_INMOVESIZE;
3410 if (reply->caret) info->flags |= GUI_CARETBLINKING;
3413 SERVER_END_REQ;
3414 return ret;
3418 /******************************************************************
3419 * IsHungAppWindow (USER32.@)
3422 BOOL WINAPI IsHungAppWindow( HWND hWnd )
3424 DWORD dwResult;
3425 return !SendMessageTimeoutA(hWnd, WM_NULL, 0, 0, SMTO_ABORTIFHUNG, 5000, &dwResult);