Clear the internal paint flag in the server before returning a
[wine/testsucceed.git] / dlls / user / message.c
blobe6bac74a50f5521b6e3dd7584ac1606e68ca736e
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 "message.h"
38 #include "user_private.h"
39 #include "win.h"
40 #include "winpos.h"
41 #include "controls.h"
42 #include "winproc.h"
43 #include "wine/debug.h"
45 WINE_DEFAULT_DEBUG_CHANNEL(msg);
46 WINE_DECLARE_DEBUG_CHANNEL(relay);
47 WINE_DECLARE_DEBUG_CHANNEL(key);
49 #define WM_NCMOUSEFIRST WM_NCMOUSEMOVE
50 #define WM_NCMOUSELAST WM_NCMBUTTONDBLCLK
52 #define MAX_PACK_COUNT 4
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 filter */
310 inline static BOOL check_message_filter( const MSG *msg, HWND hwnd, UINT first, UINT last )
312 if (hwnd && msg->hwnd != hwnd && !IsChild( hwnd, msg->hwnd )) return FALSE;
313 if (first || last) return (msg->message >= first && msg->message <= last);
314 return TRUE;
318 /***********************************************************************
319 * broadcast_message_callback
321 * Helper callback for broadcasting messages.
323 static BOOL CALLBACK broadcast_message_callback( HWND hwnd, LPARAM lparam )
325 struct send_message_info *info = (struct send_message_info *)lparam;
326 if (!(GetWindowLongW( hwnd, GWL_STYLE ) & (WS_POPUP|WS_CAPTION))) return TRUE;
327 switch(info->type)
329 case MSG_UNICODE:
330 SendMessageTimeoutW( hwnd, info->msg, info->wparam, info->lparam,
331 info->flags, info->timeout, NULL );
332 break;
333 case MSG_ASCII:
334 SendMessageTimeoutA( hwnd, info->msg, info->wparam, info->lparam,
335 info->flags, info->timeout, NULL );
336 break;
337 case MSG_NOTIFY:
338 SendNotifyMessageW( hwnd, info->msg, info->wparam, info->lparam );
339 break;
340 case MSG_CALLBACK:
341 SendMessageCallbackW( hwnd, info->msg, info->wparam, info->lparam,
342 info->callback, info->data );
343 break;
344 case MSG_POSTED:
345 PostMessageW( hwnd, info->msg, info->wparam, info->lparam );
346 break;
347 default:
348 ERR( "bad type %d\n", info->type );
349 break;
351 return TRUE;
355 /***********************************************************************
356 * map_wparam_AtoW
358 * Convert the wparam of an ASCII message to Unicode.
360 static WPARAM map_wparam_AtoW( UINT message, WPARAM wparam )
362 switch(message)
364 case WM_CHARTOITEM:
365 case EM_SETPASSWORDCHAR:
366 case WM_CHAR:
367 case WM_DEADCHAR:
368 case WM_SYSCHAR:
369 case WM_SYSDEADCHAR:
370 case WM_MENUCHAR:
372 char ch = LOWORD(wparam);
373 WCHAR wch;
374 MultiByteToWideChar(CP_ACP, 0, &ch, 1, &wch, 1);
375 wparam = MAKEWPARAM( wch, HIWORD(wparam) );
377 break;
378 case WM_IME_CHAR:
380 char ch[2];
381 WCHAR wch;
382 ch[0] = (wparam >> 8);
383 ch[1] = (wparam & 0xff);
384 if (ch[0]) MultiByteToWideChar(CP_ACP, 0, ch, 2, &wch, 1);
385 else MultiByteToWideChar(CP_ACP, 0, &ch[1], 1, &wch, 1);
386 wparam = MAKEWPARAM( wch, HIWORD(wparam) );
388 break;
390 return wparam;
394 /***********************************************************************
395 * map_wparam_WtoA
397 * Convert the wparam of a Unicode message to ASCII.
399 static WPARAM map_wparam_WtoA( UINT message, WPARAM wparam )
401 switch(message)
403 case WM_CHARTOITEM:
404 case EM_SETPASSWORDCHAR:
405 case WM_CHAR:
406 case WM_DEADCHAR:
407 case WM_SYSCHAR:
408 case WM_SYSDEADCHAR:
409 case WM_MENUCHAR:
411 WCHAR wch = LOWORD(wparam);
412 BYTE ch;
413 WideCharToMultiByte( CP_ACP, 0, &wch, 1, &ch, 1, NULL, NULL );
414 wparam = MAKEWPARAM( ch, HIWORD(wparam) );
416 break;
417 case WM_IME_CHAR:
419 WCHAR wch = LOWORD(wparam);
420 BYTE ch[2];
422 if (WideCharToMultiByte( CP_ACP, 0, &wch, 1, ch, 2, NULL, NULL ) == 2)
423 wparam = MAKEWPARAM( (ch[0] << 8) | ch[1], HIWORD(wparam) );
424 else
425 wparam = MAKEWPARAM( ch[0], HIWORD(wparam) );
427 break;
429 return wparam;
433 /***********************************************************************
434 * pack_message
436 * Pack a message for sending to another process.
437 * Return the size of the data we expect in the message reply.
438 * Set data->count to -1 if there is an error.
440 static size_t pack_message( HWND hwnd, UINT message, WPARAM wparam, LPARAM lparam,
441 struct packed_message *data )
443 data->count = 0;
444 switch(message)
446 case WM_NCCREATE:
447 case WM_CREATE:
449 CREATESTRUCTW *cs = (CREATESTRUCTW *)lparam;
450 push_data( data, cs, sizeof(*cs) );
451 if (HIWORD(cs->lpszName)) push_string( data, cs->lpszName );
452 if (HIWORD(cs->lpszClass)) push_string( data, cs->lpszClass );
453 return sizeof(*cs);
455 case WM_GETTEXT:
456 case WM_ASKCBFORMATNAME:
457 return wparam * sizeof(WCHAR);
458 case WM_WININICHANGE:
459 if (lparam) push_string(data, (LPWSTR)lparam );
460 return 0;
461 case WM_SETTEXT:
462 case WM_DEVMODECHANGE:
463 case CB_DIR:
464 case LB_DIR:
465 case LB_ADDFILE:
466 case EM_REPLACESEL:
467 push_string( data, (LPWSTR)lparam );
468 return 0;
469 case WM_GETMINMAXINFO:
470 push_data( data, (MINMAXINFO *)lparam, sizeof(MINMAXINFO) );
471 return sizeof(MINMAXINFO);
472 case WM_DRAWITEM:
473 push_data( data, (DRAWITEMSTRUCT *)lparam, sizeof(DRAWITEMSTRUCT) );
474 return 0;
475 case WM_MEASUREITEM:
476 push_data( data, (MEASUREITEMSTRUCT *)lparam, sizeof(MEASUREITEMSTRUCT) );
477 return sizeof(MEASUREITEMSTRUCT);
478 case WM_DELETEITEM:
479 push_data( data, (DELETEITEMSTRUCT *)lparam, sizeof(DELETEITEMSTRUCT) );
480 return 0;
481 case WM_COMPAREITEM:
482 push_data( data, (COMPAREITEMSTRUCT *)lparam, sizeof(COMPAREITEMSTRUCT) );
483 return 0;
484 case WM_WINDOWPOSCHANGING:
485 case WM_WINDOWPOSCHANGED:
486 push_data( data, (WINDOWPOS *)lparam, sizeof(WINDOWPOS) );
487 return sizeof(WINDOWPOS);
488 case WM_COPYDATA:
490 COPYDATASTRUCT *cp = (COPYDATASTRUCT *)lparam;
491 push_data( data, cp, sizeof(*cp) );
492 if (cp->lpData) push_data( data, cp->lpData, cp->cbData );
493 return 0;
495 case WM_NOTIFY:
496 /* WM_NOTIFY cannot be sent across processes (MSDN) */
497 data->count = -1;
498 return 0;
499 case WM_HELP:
500 push_data( data, (HELPINFO *)lparam, sizeof(HELPINFO) );
501 return 0;
502 case WM_STYLECHANGING:
503 case WM_STYLECHANGED:
504 push_data( data, (STYLESTRUCT *)lparam, sizeof(STYLESTRUCT) );
505 return 0;
506 case WM_NCCALCSIZE:
507 if (!wparam)
509 push_data( data, (RECT *)lparam, sizeof(RECT) );
510 return sizeof(RECT);
512 else
514 NCCALCSIZE_PARAMS *nc = (NCCALCSIZE_PARAMS *)lparam;
515 push_data( data, nc, sizeof(*nc) );
516 push_data( data, nc->lppos, sizeof(*nc->lppos) );
517 return sizeof(*nc) + sizeof(*nc->lppos);
519 case WM_GETDLGCODE:
520 if (lparam) push_data( data, (MSG *)lparam, sizeof(MSG) );
521 return sizeof(MSG);
522 case SBM_SETSCROLLINFO:
523 push_data( data, (SCROLLINFO *)lparam, sizeof(SCROLLINFO) );
524 return 0;
525 case SBM_GETSCROLLINFO:
526 push_data( data, (SCROLLINFO *)lparam, sizeof(SCROLLINFO) );
527 return sizeof(SCROLLINFO);
528 case SBM_GETSCROLLBARINFO:
530 const SCROLLBARINFO *info = (const SCROLLBARINFO *)lparam;
531 size_t size = min( info->cbSize, sizeof(SCROLLBARINFO) );
532 push_data( data, info, size );
533 return size;
535 case EM_GETSEL:
536 case SBM_GETRANGE:
537 case CB_GETEDITSEL:
539 size_t size = 0;
540 if (wparam) size += sizeof(DWORD);
541 if (lparam) size += sizeof(DWORD);
542 return size;
544 case EM_GETRECT:
545 case LB_GETITEMRECT:
546 case CB_GETDROPPEDCONTROLRECT:
547 return sizeof(RECT);
548 case EM_SETRECT:
549 case EM_SETRECTNP:
550 push_data( data, (RECT *)lparam, sizeof(RECT) );
551 return 0;
552 case EM_GETLINE:
554 WORD *pw = (WORD *)lparam;
555 push_data( data, pw, sizeof(*pw) );
556 return *pw * sizeof(WCHAR);
558 case EM_SETTABSTOPS:
559 case LB_SETTABSTOPS:
560 if (wparam) push_data( data, (UINT *)lparam, sizeof(UINT) * wparam );
561 return 0;
562 case CB_ADDSTRING:
563 case CB_INSERTSTRING:
564 case CB_FINDSTRING:
565 case CB_FINDSTRINGEXACT:
566 case CB_SELECTSTRING:
567 if (combobox_has_strings( hwnd )) push_string( data, (LPWSTR)lparam );
568 return 0;
569 case CB_GETLBTEXT:
570 if (!combobox_has_strings( hwnd )) return sizeof(ULONG_PTR);
571 return (SendMessageW( hwnd, CB_GETLBTEXTLEN, wparam, 0 ) + 1) * sizeof(WCHAR);
572 case LB_ADDSTRING:
573 case LB_INSERTSTRING:
574 case LB_FINDSTRING:
575 case LB_FINDSTRINGEXACT:
576 case LB_SELECTSTRING:
577 if (listbox_has_strings( hwnd )) push_string( data, (LPWSTR)lparam );
578 return 0;
579 case LB_GETTEXT:
580 if (!listbox_has_strings( hwnd )) return sizeof(ULONG_PTR);
581 return (SendMessageW( hwnd, LB_GETTEXTLEN, wparam, 0 ) + 1) * sizeof(WCHAR);
582 case LB_GETSELITEMS:
583 return wparam * sizeof(UINT);
584 case WM_NEXTMENU:
585 push_data( data, (MDINEXTMENU *)lparam, sizeof(MDINEXTMENU) );
586 return sizeof(MDINEXTMENU);
587 case WM_SIZING:
588 case WM_MOVING:
589 push_data( data, (RECT *)lparam, sizeof(RECT) );
590 return sizeof(RECT);
591 case WM_MDICREATE:
593 MDICREATESTRUCTW *cs = (MDICREATESTRUCTW *)lparam;
594 push_data( data, cs, sizeof(*cs) );
595 if (HIWORD(cs->szTitle)) push_string( data, cs->szTitle );
596 if (HIWORD(cs->szClass)) push_string( data, cs->szClass );
597 return sizeof(*cs);
599 case WM_MDIGETACTIVE:
600 if (lparam) return sizeof(BOOL);
601 return 0;
602 case WM_WINE_SETWINDOWPOS:
603 push_data( data, (WINDOWPOS *)lparam, sizeof(WINDOWPOS) );
604 return 0;
605 case WM_WINE_KEYBOARD_LL_HOOK:
606 push_data( data, (KBDLLHOOKSTRUCT *)lparam, sizeof(KBDLLHOOKSTRUCT) );
607 return 0;
608 case WM_WINE_MOUSE_LL_HOOK:
609 push_data( data, (MSLLHOOKSTRUCT *)lparam, sizeof(MSLLHOOKSTRUCT) );
610 return 0;
611 case WM_PAINT:
612 if (!wparam) return 0;
613 /* fall through */
615 /* these contain an HFONT */
616 case WM_SETFONT:
617 case WM_GETFONT:
618 /* these contain an HDC */
619 case WM_ERASEBKGND:
620 case WM_ICONERASEBKGND:
621 case WM_NCPAINT:
622 case WM_CTLCOLORMSGBOX:
623 case WM_CTLCOLOREDIT:
624 case WM_CTLCOLORLISTBOX:
625 case WM_CTLCOLORBTN:
626 case WM_CTLCOLORDLG:
627 case WM_CTLCOLORSCROLLBAR:
628 case WM_CTLCOLORSTATIC:
629 case WM_PRINT:
630 case WM_PRINTCLIENT:
631 /* these contain an HGLOBAL */
632 case WM_PAINTCLIPBOARD:
633 case WM_SIZECLIPBOARD:
634 /* these contain HICON */
635 case WM_GETICON:
636 case WM_SETICON:
637 case WM_QUERYDRAGICON:
638 case WM_QUERYPARKICON:
639 /* these contain pointers */
640 case WM_DROPOBJECT:
641 case WM_QUERYDROPOBJECT:
642 case WM_DRAGLOOP:
643 case WM_DRAGSELECT:
644 case WM_DRAGMOVE:
645 case WM_DEVICECHANGE:
646 FIXME( "msg %x (%s) not supported yet\n", message, SPY_GetMsgName(message, hwnd) );
647 data->count = -1;
648 return 0;
650 return 0;
654 /***********************************************************************
655 * unpack_message
657 * Unpack a message received from another process.
659 static BOOL unpack_message( HWND hwnd, UINT message, WPARAM *wparam, LPARAM *lparam,
660 void **buffer, size_t size )
662 size_t minsize = 0;
664 switch(message)
666 case WM_NCCREATE:
667 case WM_CREATE:
669 CREATESTRUCTW *cs = *buffer;
670 WCHAR *str = (WCHAR *)(cs + 1);
671 if (size < sizeof(*cs)) return FALSE;
672 size -= sizeof(*cs);
673 if (HIWORD(cs->lpszName))
675 if (!check_string( str, size )) return FALSE;
676 cs->lpszName = str;
677 size -= (strlenW(str) + 1) * sizeof(WCHAR);
678 str += strlenW(str) + 1;
680 if (HIWORD(cs->lpszClass))
682 if (!check_string( str, size )) return FALSE;
683 cs->lpszClass = str;
685 break;
687 case WM_GETTEXT:
688 case WM_ASKCBFORMATNAME:
689 if (!get_buffer_space( buffer, (*wparam * sizeof(WCHAR)) )) return FALSE;
690 break;
691 case WM_WININICHANGE:
692 if (!*lparam) return TRUE;
693 /* fall through */
694 case WM_SETTEXT:
695 case WM_DEVMODECHANGE:
696 case CB_DIR:
697 case LB_DIR:
698 case LB_ADDFILE:
699 case EM_REPLACESEL:
700 if (!check_string( *buffer, size )) return FALSE;
701 break;
702 case WM_GETMINMAXINFO:
703 minsize = sizeof(MINMAXINFO);
704 break;
705 case WM_DRAWITEM:
706 minsize = sizeof(DRAWITEMSTRUCT);
707 break;
708 case WM_MEASUREITEM:
709 minsize = sizeof(MEASUREITEMSTRUCT);
710 break;
711 case WM_DELETEITEM:
712 minsize = sizeof(DELETEITEMSTRUCT);
713 break;
714 case WM_COMPAREITEM:
715 minsize = sizeof(COMPAREITEMSTRUCT);
716 break;
717 case WM_WINDOWPOSCHANGING:
718 case WM_WINDOWPOSCHANGED:
719 case WM_WINE_SETWINDOWPOS:
720 minsize = sizeof(WINDOWPOS);
721 break;
722 case WM_COPYDATA:
724 COPYDATASTRUCT *cp = *buffer;
725 if (size < sizeof(*cp)) return FALSE;
726 if (cp->lpData)
728 minsize = sizeof(*cp) + cp->cbData;
729 cp->lpData = cp + 1;
731 break;
733 case WM_NOTIFY:
734 /* WM_NOTIFY cannot be sent across processes (MSDN) */
735 return FALSE;
736 case WM_HELP:
737 minsize = sizeof(HELPINFO);
738 break;
739 case WM_STYLECHANGING:
740 case WM_STYLECHANGED:
741 minsize = sizeof(STYLESTRUCT);
742 break;
743 case WM_NCCALCSIZE:
744 if (!*wparam) minsize = sizeof(RECT);
745 else
747 NCCALCSIZE_PARAMS *nc = *buffer;
748 if (size < sizeof(*nc) + sizeof(*nc->lppos)) return FALSE;
749 nc->lppos = (WINDOWPOS *)(nc + 1);
751 break;
752 case WM_GETDLGCODE:
753 if (!*lparam) return TRUE;
754 minsize = sizeof(MSG);
755 break;
756 case SBM_SETSCROLLINFO:
757 minsize = sizeof(SCROLLINFO);
758 break;
759 case SBM_GETSCROLLINFO:
760 if (!get_buffer_space( buffer, sizeof(SCROLLINFO ))) return FALSE;
761 break;
762 case SBM_GETSCROLLBARINFO:
763 if (!get_buffer_space( buffer, sizeof(SCROLLBARINFO ))) return FALSE;
764 break;
765 case EM_GETSEL:
766 case SBM_GETRANGE:
767 case CB_GETEDITSEL:
768 if (*wparam || *lparam)
770 if (!get_buffer_space( buffer, 2*sizeof(DWORD) )) return FALSE;
771 if (*wparam) *wparam = (WPARAM)*buffer;
772 if (*lparam) *lparam = (LPARAM)((DWORD *)*buffer + 1);
774 return TRUE;
775 case EM_GETRECT:
776 case LB_GETITEMRECT:
777 case CB_GETDROPPEDCONTROLRECT:
778 if (!get_buffer_space( buffer, sizeof(RECT) )) return FALSE;
779 break;
780 case EM_SETRECT:
781 case EM_SETRECTNP:
782 minsize = sizeof(RECT);
783 break;
784 case EM_GETLINE:
786 WORD len;
787 if (size < sizeof(WORD)) return FALSE;
788 len = *(WORD *)*buffer;
789 if (!get_buffer_space( buffer, (len + 1) * sizeof(WCHAR) )) return FALSE;
790 *lparam = (LPARAM)*buffer + sizeof(WORD); /* don't erase WORD at start of buffer */
791 return TRUE;
793 case EM_SETTABSTOPS:
794 case LB_SETTABSTOPS:
795 if (!*wparam) return TRUE;
796 minsize = *wparam * sizeof(UINT);
797 break;
798 case CB_ADDSTRING:
799 case CB_INSERTSTRING:
800 case CB_FINDSTRING:
801 case CB_FINDSTRINGEXACT:
802 case CB_SELECTSTRING:
803 case LB_ADDSTRING:
804 case LB_INSERTSTRING:
805 case LB_FINDSTRING:
806 case LB_FINDSTRINGEXACT:
807 case LB_SELECTSTRING:
808 if (!*buffer) return TRUE;
809 if (!check_string( *buffer, size )) return FALSE;
810 break;
811 case CB_GETLBTEXT:
813 size = sizeof(ULONG_PTR);
814 if (combobox_has_strings( hwnd ))
815 size = (SendMessageW( hwnd, CB_GETLBTEXTLEN, *wparam, 0 ) + 1) * sizeof(WCHAR);
816 if (!get_buffer_space( buffer, size )) return FALSE;
817 break;
819 case LB_GETTEXT:
821 size = sizeof(ULONG_PTR);
822 if (listbox_has_strings( hwnd ))
823 size = (SendMessageW( hwnd, LB_GETTEXTLEN, *wparam, 0 ) + 1) * sizeof(WCHAR);
824 if (!get_buffer_space( buffer, size )) return FALSE;
825 break;
827 case LB_GETSELITEMS:
828 if (!get_buffer_space( buffer, *wparam * sizeof(UINT) )) return FALSE;
829 break;
830 case WM_NEXTMENU:
831 minsize = sizeof(MDINEXTMENU);
832 if (!get_buffer_space( buffer, sizeof(MDINEXTMENU) )) return FALSE;
833 break;
834 case WM_SIZING:
835 case WM_MOVING:
836 minsize = sizeof(RECT);
837 if (!get_buffer_space( buffer, sizeof(RECT) )) return FALSE;
838 break;
839 case WM_MDICREATE:
841 MDICREATESTRUCTW *cs = *buffer;
842 WCHAR *str = (WCHAR *)(cs + 1);
843 if (size < sizeof(*cs)) return FALSE;
844 size -= sizeof(*cs);
845 if (HIWORD(cs->szTitle))
847 if (!check_string( str, size )) return FALSE;
848 cs->szTitle = str;
849 size -= (strlenW(str) + 1) * sizeof(WCHAR);
850 str += strlenW(str) + 1;
852 if (HIWORD(cs->szClass))
854 if (!check_string( str, size )) return FALSE;
855 cs->szClass = str;
857 break;
859 case WM_MDIGETACTIVE:
860 if (!*lparam) return TRUE;
861 if (!get_buffer_space( buffer, sizeof(BOOL) )) return FALSE;
862 break;
863 case WM_WINE_KEYBOARD_LL_HOOK:
864 minsize = sizeof(KBDLLHOOKSTRUCT);
865 break;
866 case WM_WINE_MOUSE_LL_HOOK:
867 minsize = sizeof(MSLLHOOKSTRUCT);
868 break;
869 case WM_PAINT:
870 if (!*wparam) return TRUE;
871 /* fall through */
873 /* these contain an HFONT */
874 case WM_SETFONT:
875 case WM_GETFONT:
876 /* these contain an HDC */
877 case WM_ERASEBKGND:
878 case WM_ICONERASEBKGND:
879 case WM_NCPAINT:
880 case WM_CTLCOLORMSGBOX:
881 case WM_CTLCOLOREDIT:
882 case WM_CTLCOLORLISTBOX:
883 case WM_CTLCOLORBTN:
884 case WM_CTLCOLORDLG:
885 case WM_CTLCOLORSCROLLBAR:
886 case WM_CTLCOLORSTATIC:
887 case WM_PRINT:
888 case WM_PRINTCLIENT:
889 /* these contain an HGLOBAL */
890 case WM_PAINTCLIPBOARD:
891 case WM_SIZECLIPBOARD:
892 /* these contain HICON */
893 case WM_GETICON:
894 case WM_SETICON:
895 case WM_QUERYDRAGICON:
896 case WM_QUERYPARKICON:
897 /* these contain pointers */
898 case WM_DROPOBJECT:
899 case WM_QUERYDROPOBJECT:
900 case WM_DRAGLOOP:
901 case WM_DRAGSELECT:
902 case WM_DRAGMOVE:
903 case WM_DEVICECHANGE:
904 FIXME( "msg %x (%s) not supported yet\n", message, SPY_GetMsgName(message, hwnd) );
905 return FALSE;
907 default:
908 return TRUE; /* message doesn't need any unpacking */
911 /* default exit for most messages: check minsize and store buffer in lparam */
912 if (size < minsize) return FALSE;
913 *lparam = (LPARAM)*buffer;
914 return TRUE;
918 /***********************************************************************
919 * pack_reply
921 * Pack a reply to a message for sending to another process.
923 static void pack_reply( HWND hwnd, UINT message, WPARAM wparam, LPARAM lparam,
924 LRESULT res, struct packed_message *data )
926 data->count = 0;
927 switch(message)
929 case WM_NCCREATE:
930 case WM_CREATE:
931 push_data( data, (CREATESTRUCTW *)lparam, sizeof(CREATESTRUCTW) );
932 break;
933 case WM_GETTEXT:
934 case CB_GETLBTEXT:
935 case LB_GETTEXT:
936 push_data( data, (WCHAR *)lparam, (res + 1) * sizeof(WCHAR) );
937 break;
938 case WM_GETMINMAXINFO:
939 push_data( data, (MINMAXINFO *)lparam, sizeof(MINMAXINFO) );
940 break;
941 case WM_MEASUREITEM:
942 push_data( data, (MEASUREITEMSTRUCT *)lparam, sizeof(MEASUREITEMSTRUCT) );
943 break;
944 case WM_WINDOWPOSCHANGING:
945 case WM_WINDOWPOSCHANGED:
946 push_data( data, (WINDOWPOS *)lparam, sizeof(WINDOWPOS) );
947 break;
948 case WM_GETDLGCODE:
949 if (lparam) push_data( data, (MSG *)lparam, sizeof(MSG) );
950 break;
951 case SBM_GETSCROLLINFO:
952 push_data( data, (SCROLLINFO *)lparam, sizeof(SCROLLINFO) );
953 break;
954 case EM_GETRECT:
955 case LB_GETITEMRECT:
956 case CB_GETDROPPEDCONTROLRECT:
957 case WM_SIZING:
958 case WM_MOVING:
959 push_data( data, (RECT *)lparam, sizeof(RECT) );
960 break;
961 case EM_GETLINE:
963 WORD *ptr = (WORD *)lparam;
964 push_data( data, ptr, ptr[-1] * sizeof(WCHAR) );
965 break;
967 case LB_GETSELITEMS:
968 push_data( data, (UINT *)lparam, wparam * sizeof(UINT) );
969 break;
970 case WM_MDIGETACTIVE:
971 if (lparam) push_data( data, (BOOL *)lparam, sizeof(BOOL) );
972 break;
973 case WM_NCCALCSIZE:
974 if (!wparam)
975 push_data( data, (RECT *)lparam, sizeof(RECT) );
976 else
978 NCCALCSIZE_PARAMS *nc = (NCCALCSIZE_PARAMS *)lparam;
979 push_data( data, nc, sizeof(*nc) );
980 push_data( data, nc->lppos, sizeof(*nc->lppos) );
982 break;
983 case EM_GETSEL:
984 case SBM_GETRANGE:
985 case CB_GETEDITSEL:
986 if (wparam) push_data( data, (DWORD *)wparam, sizeof(DWORD) );
987 if (lparam) push_data( data, (DWORD *)lparam, sizeof(DWORD) );
988 break;
989 case WM_NEXTMENU:
990 push_data( data, (MDINEXTMENU *)lparam, sizeof(MDINEXTMENU) );
991 break;
992 case WM_MDICREATE:
993 push_data( data, (MDICREATESTRUCTW *)lparam, sizeof(MDICREATESTRUCTW) );
994 break;
995 case WM_ASKCBFORMATNAME:
996 push_data( data, (WCHAR *)lparam, (strlenW((WCHAR *)lparam) + 1) * sizeof(WCHAR) );
997 break;
1002 /***********************************************************************
1003 * unpack_reply
1005 * Unpack a message reply received from another process.
1007 static void unpack_reply( HWND hwnd, UINT message, WPARAM wparam, LPARAM lparam,
1008 void *buffer, size_t size )
1010 switch(message)
1012 case WM_NCCREATE:
1013 case WM_CREATE:
1015 CREATESTRUCTW *cs = (CREATESTRUCTW *)lparam;
1016 LPCWSTR name = cs->lpszName, class = cs->lpszClass;
1017 memcpy( cs, buffer, min( sizeof(*cs), size ));
1018 cs->lpszName = name; /* restore the original pointers */
1019 cs->lpszClass = class;
1020 break;
1022 case WM_GETTEXT:
1023 case WM_ASKCBFORMATNAME:
1024 memcpy( (WCHAR *)lparam, buffer, min( wparam*sizeof(WCHAR), size ));
1025 break;
1026 case WM_GETMINMAXINFO:
1027 memcpy( (MINMAXINFO *)lparam, buffer, min( sizeof(MINMAXINFO), size ));
1028 break;
1029 case WM_MEASUREITEM:
1030 memcpy( (MEASUREITEMSTRUCT *)lparam, buffer, min( sizeof(MEASUREITEMSTRUCT), size ));
1031 break;
1032 case WM_WINDOWPOSCHANGING:
1033 case WM_WINDOWPOSCHANGED:
1034 memcpy( (WINDOWPOS *)lparam, buffer, min( sizeof(WINDOWPOS), size ));
1035 break;
1036 case WM_GETDLGCODE:
1037 if (lparam) memcpy( (MSG *)lparam, buffer, min( sizeof(MSG), size ));
1038 break;
1039 case SBM_GETSCROLLINFO:
1040 memcpy( (SCROLLINFO *)lparam, buffer, min( sizeof(SCROLLINFO), size ));
1041 break;
1042 case SBM_GETSCROLLBARINFO:
1043 memcpy( (SCROLLBARINFO *)lparam, buffer, min( sizeof(SCROLLBARINFO), size ));
1044 break;
1045 case EM_GETRECT:
1046 case CB_GETDROPPEDCONTROLRECT:
1047 case LB_GETITEMRECT:
1048 case WM_SIZING:
1049 case WM_MOVING:
1050 memcpy( (RECT *)lparam, buffer, min( sizeof(RECT), size ));
1051 break;
1052 case EM_GETLINE:
1053 size = min( size, (size_t)*(WORD *)lparam );
1054 memcpy( (WCHAR *)lparam, buffer, size );
1055 break;
1056 case LB_GETSELITEMS:
1057 memcpy( (UINT *)lparam, buffer, min( wparam*sizeof(UINT), size ));
1058 break;
1059 case LB_GETTEXT:
1060 case CB_GETLBTEXT:
1061 memcpy( (WCHAR *)lparam, buffer, size );
1062 break;
1063 case WM_NEXTMENU:
1064 memcpy( (MDINEXTMENU *)lparam, buffer, min( sizeof(MDINEXTMENU), size ));
1065 break;
1066 case WM_MDIGETACTIVE:
1067 if (lparam) memcpy( (BOOL *)lparam, buffer, min( sizeof(BOOL), size ));
1068 break;
1069 case WM_NCCALCSIZE:
1070 if (!wparam)
1071 memcpy( (RECT *)lparam, buffer, min( sizeof(RECT), size ));
1072 else
1074 NCCALCSIZE_PARAMS *nc = (NCCALCSIZE_PARAMS *)lparam;
1075 WINDOWPOS *wp = nc->lppos;
1076 memcpy( nc, buffer, min( sizeof(*nc), size ));
1077 if (size > sizeof(*nc))
1079 size -= sizeof(*nc);
1080 memcpy( wp, (NCCALCSIZE_PARAMS*)buffer + 1, min( sizeof(*wp), size ));
1082 nc->lppos = wp; /* restore the original pointer */
1084 break;
1085 case EM_GETSEL:
1086 case SBM_GETRANGE:
1087 case CB_GETEDITSEL:
1088 if (wparam)
1090 memcpy( (DWORD *)wparam, buffer, min( sizeof(DWORD), size ));
1091 if (size <= sizeof(DWORD)) break;
1092 size -= sizeof(DWORD);
1093 buffer = (DWORD *)buffer + 1;
1095 if (lparam) memcpy( (DWORD *)lparam, buffer, min( sizeof(DWORD), size ));
1096 break;
1097 case WM_MDICREATE:
1099 MDICREATESTRUCTW *cs = (MDICREATESTRUCTW *)lparam;
1100 LPCWSTR title = cs->szTitle, class = cs->szClass;
1101 memcpy( cs, buffer, min( sizeof(*cs), size ));
1102 cs->szTitle = title; /* restore the original pointers */
1103 cs->szClass = class;
1104 break;
1106 default:
1107 ERR( "should not happen: unexpected message %x\n", message );
1108 break;
1113 /***********************************************************************
1114 * reply_message
1116 * Send a reply to a sent message.
1118 static void reply_message( struct received_message_info *info, LRESULT result, BOOL remove )
1120 struct packed_message data;
1121 int i, replied = info->flags & ISMEX_REPLIED;
1123 if (info->flags & ISMEX_NOTIFY) return; /* notify messages don't get replies */
1124 if (!remove && replied) return; /* replied already */
1126 data.count = 0;
1127 info->flags |= ISMEX_REPLIED;
1129 if (info->type == MSG_OTHER_PROCESS && !replied)
1131 pack_reply( info->msg.hwnd, info->msg.message, info->msg.wParam,
1132 info->msg.lParam, result, &data );
1135 SERVER_START_REQ( reply_message )
1137 req->type = info->type;
1138 req->result = result;
1139 req->remove = remove;
1140 for (i = 0; i < data.count; i++) wine_server_add_data( req, data.data[i], data.size[i] );
1141 wine_server_call( req );
1143 SERVER_END_REQ;
1147 /***********************************************************************
1148 * handle_internal_message
1150 * Handle an internal Wine message instead of calling the window proc.
1152 static LRESULT handle_internal_message( HWND hwnd, UINT msg, WPARAM wparam, LPARAM lparam )
1154 if (hwnd == GetDesktopWindow()) return 0;
1155 switch(msg)
1157 case WM_WINE_DESTROYWINDOW:
1158 return WIN_DestroyWindow( hwnd );
1159 case WM_WINE_SETWINDOWPOS:
1160 if (USER_Driver.pSetWindowPos)
1161 return USER_Driver.pSetWindowPos( (WINDOWPOS *)lparam );
1162 return 0;
1163 case WM_WINE_SHOWWINDOW:
1164 return ShowWindow( hwnd, wparam );
1165 case WM_WINE_SETPARENT:
1166 return (LRESULT)SetParent( hwnd, (HWND)wparam );
1167 case WM_WINE_SETWINDOWLONG:
1168 return (LRESULT)SetWindowLongW( hwnd, wparam, lparam );
1169 case WM_WINE_ENABLEWINDOW:
1170 return EnableWindow( hwnd, wparam );
1171 case WM_WINE_SETACTIVEWINDOW:
1172 return (LRESULT)SetActiveWindow( (HWND)wparam );
1173 case WM_WINE_KEYBOARD_LL_HOOK:
1174 return HOOK_CallHooks( WH_KEYBOARD_LL, HC_ACTION, wparam, lparam, TRUE );
1175 case WM_WINE_MOUSE_LL_HOOK:
1176 return HOOK_CallHooks( WH_MOUSE_LL, HC_ACTION, wparam, lparam, TRUE );
1177 default:
1178 if (msg >= WM_WINE_FIRST_DRIVER_MSG && msg <= WM_WINE_LAST_DRIVER_MSG)
1180 if (!USER_Driver.pWindowMessage) return 0;
1181 return USER_Driver.pWindowMessage( hwnd, msg, wparam, lparam );
1183 FIXME( "unknown internal message %x\n", msg );
1184 return 0;
1188 /* since the WM_DDE_ACK response to a WM_DDE_EXECUTE message should contain the handle
1189 * to the memory handle, we keep track (in the server side) of all pairs of handle
1190 * used (the client passes its value and the content of the memory handle), and
1191 * the server stored both values (the client, and the local one, created after the
1192 * content). When a ACK message is generated, the list of pair is searched for a
1193 * matching pair, so that the client memory handle can be returned.
1195 struct DDE_pair {
1196 HGLOBAL client_hMem;
1197 HGLOBAL server_hMem;
1200 static struct DDE_pair* dde_pairs;
1201 static int dde_num_alloc;
1202 static int dde_num_used;
1204 static CRITICAL_SECTION dde_crst;
1205 static CRITICAL_SECTION_DEBUG critsect_debug =
1207 0, 0, &dde_crst,
1208 { &critsect_debug.ProcessLocksList, &critsect_debug.ProcessLocksList },
1209 0, 0, { 0, (DWORD)(__FILE__ ": dde_crst") }
1211 static CRITICAL_SECTION dde_crst = { &critsect_debug, -1, 0, 0, 0, 0 };
1213 static BOOL dde_add_pair(HGLOBAL chm, HGLOBAL shm)
1215 int i;
1216 #define GROWBY 4
1218 EnterCriticalSection(&dde_crst);
1220 /* now remember the pair of hMem on both sides */
1221 if (dde_num_used == dde_num_alloc)
1223 struct DDE_pair* tmp;
1224 if (dde_pairs)
1225 tmp = HeapReAlloc( GetProcessHeap(), 0, dde_pairs,
1226 (dde_num_alloc + GROWBY) * sizeof(struct DDE_pair));
1227 else
1228 tmp = HeapAlloc( GetProcessHeap(), 0,
1229 (dde_num_alloc + GROWBY) * sizeof(struct DDE_pair));
1231 if (!tmp)
1233 LeaveCriticalSection(&dde_crst);
1234 return FALSE;
1236 dde_pairs = tmp;
1237 /* zero out newly allocated part */
1238 memset(&dde_pairs[dde_num_alloc], 0, GROWBY * sizeof(struct DDE_pair));
1239 dde_num_alloc += GROWBY;
1241 #undef GROWBY
1242 for (i = 0; i < dde_num_alloc; i++)
1244 if (dde_pairs[i].server_hMem == 0)
1246 dde_pairs[i].client_hMem = chm;
1247 dde_pairs[i].server_hMem = shm;
1248 dde_num_used++;
1249 break;
1252 LeaveCriticalSection(&dde_crst);
1253 return TRUE;
1256 static HGLOBAL dde_get_pair(HGLOBAL shm)
1258 int i;
1259 HGLOBAL ret = 0;
1261 EnterCriticalSection(&dde_crst);
1262 for (i = 0; i < dde_num_alloc; i++)
1264 if (dde_pairs[i].server_hMem == shm)
1266 /* free this pair */
1267 dde_pairs[i].server_hMem = 0;
1268 dde_num_used--;
1269 ret = dde_pairs[i].client_hMem;
1270 break;
1273 LeaveCriticalSection(&dde_crst);
1274 return ret;
1277 /***********************************************************************
1278 * post_dde_message
1280 * Post a DDE message
1282 static BOOL post_dde_message( DWORD dest_tid, struct packed_message *data, const struct send_message_info *info )
1284 void* ptr = NULL;
1285 int size = 0;
1286 UINT uiLo, uiHi;
1287 LPARAM lp = 0;
1288 HGLOBAL hunlock = 0;
1289 int i;
1290 DWORD res;
1292 if (!UnpackDDElParam( info->msg, info->lparam, &uiLo, &uiHi ))
1293 return FALSE;
1295 lp = info->lparam;
1296 switch (info->msg)
1298 /* DDE messages which don't require packing are:
1299 * WM_DDE_INITIATE
1300 * WM_DDE_TERMINATE
1301 * WM_DDE_REQUEST
1302 * WM_DDE_UNADVISE
1304 case WM_DDE_ACK:
1305 if (HIWORD(uiHi))
1307 /* uiHi should contain a hMem from WM_DDE_EXECUTE */
1308 HGLOBAL h = dde_get_pair( (HANDLE)uiHi );
1309 if (h)
1311 /* send back the value of h on the other side */
1312 push_data( data, &h, sizeof(HGLOBAL) );
1313 lp = uiLo;
1314 TRACE( "send dde-ack %x %08x => %08lx\n", uiLo, uiHi, (DWORD)h );
1317 else
1319 /* uiHi should contain either an atom or 0 */
1320 TRACE( "send dde-ack %x atom=%x\n", uiLo, uiHi );
1321 lp = MAKELONG( uiLo, uiHi );
1323 break;
1324 case WM_DDE_ADVISE:
1325 case WM_DDE_DATA:
1326 case WM_DDE_POKE:
1327 size = 0;
1328 if (uiLo)
1330 size = GlobalSize( (HGLOBAL)uiLo ) ;
1331 if ((info->msg == WM_DDE_ADVISE && size < sizeof(DDEADVISE)) ||
1332 (info->msg == WM_DDE_DATA && size < sizeof(DDEDATA)) ||
1333 (info->msg == WM_DDE_POKE && size < sizeof(DDEPOKE))
1335 return FALSE;
1337 else if (info->msg != WM_DDE_DATA) return FALSE;
1339 lp = uiHi;
1340 if (uiLo)
1342 if ((ptr = GlobalLock( (HGLOBAL)uiLo) ))
1344 DDEDATA *dde_data = (DDEDATA *)ptr;
1345 TRACE("unused %d, fResponse %d, fRelease %d, fDeferUpd %d, fAckReq %d, cfFormat %d\n",
1346 dde_data->unused, dde_data->fResponse, dde_data->fRelease,
1347 dde_data->reserved, dde_data->fAckReq, dde_data->cfFormat);
1348 push_data( data, ptr, size );
1349 hunlock = (HGLOBAL)uiLo;
1352 TRACE( "send ddepack %u %x\n", size, uiHi );
1353 break;
1354 case WM_DDE_EXECUTE:
1355 if (info->lparam)
1357 if ((ptr = GlobalLock( (HGLOBAL)info->lparam) ))
1359 push_data(data, ptr, GlobalSize( (HGLOBAL)info->lparam ));
1360 /* so that the other side can send it back on ACK */
1361 lp = info->lparam;
1362 hunlock = (HGLOBAL)info->lparam;
1365 break;
1367 SERVER_START_REQ( send_message )
1369 req->id = dest_tid;
1370 req->type = info->type;
1371 req->flags = 0;
1372 req->win = info->hwnd;
1373 req->msg = info->msg;
1374 req->wparam = info->wparam;
1375 req->lparam = lp;
1376 req->time = GetCurrentTime();
1377 req->timeout = -1;
1378 for (i = 0; i < data->count; i++)
1379 wine_server_add_data( req, data->data[i], data->size[i] );
1380 if ((res = wine_server_call( req )))
1382 if (res == STATUS_INVALID_PARAMETER)
1383 /* FIXME: find a STATUS_ value for this one */
1384 SetLastError( ERROR_INVALID_THREAD_ID );
1385 else
1386 SetLastError( RtlNtStatusToDosError(res) );
1388 else
1389 FreeDDElParam(info->msg, info->lparam);
1391 SERVER_END_REQ;
1392 if (hunlock) GlobalUnlock(hunlock);
1394 return !res;
1397 /***********************************************************************
1398 * unpack_dde_message
1400 * Unpack a posted DDE message received from another process.
1402 static BOOL unpack_dde_message( HWND hwnd, UINT message, WPARAM *wparam, LPARAM *lparam,
1403 void **buffer, size_t size )
1405 UINT uiLo, uiHi;
1406 HGLOBAL hMem = 0;
1407 void* ptr;
1409 switch (message)
1411 case WM_DDE_ACK:
1412 if (size)
1414 /* hMem is being passed */
1415 if (size != sizeof(HGLOBAL)) return FALSE;
1416 if (!buffer || !*buffer) return FALSE;
1417 uiLo = *lparam;
1418 memcpy( &hMem, *buffer, size );
1419 uiHi = (UINT)hMem;
1420 TRACE("recv dde-ack %x mem=%x[%lx]\n", uiLo, uiHi, GlobalSize( hMem ));
1422 else
1424 uiLo = LOWORD( *lparam );
1425 uiHi = HIWORD( *lparam );
1426 TRACE("recv dde-ack %x atom=%x\n", uiLo, uiHi);
1428 *lparam = PackDDElParam( WM_DDE_ACK, uiLo, uiHi );
1429 break;
1430 case WM_DDE_ADVISE:
1431 case WM_DDE_DATA:
1432 case WM_DDE_POKE:
1433 if ((!buffer || !*buffer) && message != WM_DDE_DATA) return FALSE;
1434 uiHi = *lparam;
1435 TRACE( "recv ddepack %u %x\n", size, uiHi );
1436 if (size)
1438 hMem = GlobalAlloc( GMEM_MOVEABLE|GMEM_DDESHARE, size );
1439 if (hMem && (ptr = GlobalLock( hMem )))
1441 memcpy( ptr, *buffer, size );
1442 GlobalUnlock( hMem );
1444 else return FALSE;
1446 uiLo = (UINT)hMem;
1448 *lparam = PackDDElParam( message, uiLo, uiHi );
1449 break;
1450 case WM_DDE_EXECUTE:
1451 if (size)
1453 if (!buffer || !*buffer) return FALSE;
1454 hMem = GlobalAlloc( GMEM_MOVEABLE|GMEM_DDESHARE, size );
1455 if (hMem && (ptr = GlobalLock( hMem )))
1457 memcpy( ptr, *buffer, size );
1458 GlobalUnlock( hMem );
1459 TRACE( "exec: pairing c=%08lx s=%08lx\n", *lparam, (DWORD)hMem );
1460 if (!dde_add_pair( (HGLOBAL)*lparam, hMem ))
1462 GlobalFree( hMem );
1463 return FALSE;
1466 } else return FALSE;
1467 *lparam = (LPARAM)hMem;
1468 break;
1470 return TRUE;
1473 /***********************************************************************
1474 * call_window_proc
1476 * Call a window procedure and the corresponding hooks.
1478 static LRESULT call_window_proc( HWND hwnd, UINT msg, WPARAM wparam, LPARAM lparam,
1479 BOOL unicode, BOOL same_thread )
1481 LRESULT result = 0;
1482 WNDPROC winproc;
1483 CWPSTRUCT cwp;
1484 CWPRETSTRUCT cwpret;
1485 MESSAGEQUEUE *queue = QUEUE_Current();
1487 if (queue->recursion_count > MAX_SENDMSG_RECURSION) return 0;
1488 queue->recursion_count++;
1490 if (msg & 0x80000000)
1492 result = handle_internal_message( hwnd, msg, wparam, lparam );
1493 goto done;
1496 /* first the WH_CALLWNDPROC hook */
1497 hwnd = WIN_GetFullHandle( hwnd );
1498 cwp.lParam = lparam;
1499 cwp.wParam = wparam;
1500 cwp.message = msg;
1501 cwp.hwnd = hwnd;
1502 HOOK_CallHooks( WH_CALLWNDPROC, HC_ACTION, same_thread, (LPARAM)&cwp, unicode );
1504 /* now call the window procedure */
1505 if (unicode)
1507 if (!(winproc = (WNDPROC)GetWindowLongPtrW( hwnd, GWLP_WNDPROC ))) goto done;
1508 result = CallWindowProcW( winproc, hwnd, msg, wparam, lparam );
1510 else
1512 if (!(winproc = (WNDPROC)GetWindowLongPtrA( hwnd, GWLP_WNDPROC ))) goto done;
1513 result = CallWindowProcA( winproc, hwnd, msg, wparam, lparam );
1516 /* and finally the WH_CALLWNDPROCRET hook */
1517 cwpret.lResult = result;
1518 cwpret.lParam = lparam;
1519 cwpret.wParam = wparam;
1520 cwpret.message = msg;
1521 cwpret.hwnd = hwnd;
1522 HOOK_CallHooks( WH_CALLWNDPROCRET, HC_ACTION, same_thread, (LPARAM)&cwpret, unicode );
1523 done:
1524 queue->recursion_count--;
1525 return result;
1529 /***********************************************************************
1530 * send_parent_notify
1532 * Send a WM_PARENTNOTIFY to all ancestors of the given window, unless
1533 * the window has the WS_EX_NOPARENTNOTIFY style.
1535 static void send_parent_notify( HWND hwnd, WORD event, WORD idChild, POINT pt )
1537 /* pt has to be in the client coordinates of the parent window */
1538 MapWindowPoints( 0, hwnd, &pt, 1 );
1539 for (;;)
1541 HWND parent;
1543 if (!(GetWindowLongW( hwnd, GWL_STYLE ) & WS_CHILD)) break;
1544 if (GetWindowLongW( hwnd, GWL_EXSTYLE ) & WS_EX_NOPARENTNOTIFY) break;
1545 if (!(parent = GetParent(hwnd))) break;
1546 MapWindowPoints( hwnd, parent, &pt, 1 );
1547 hwnd = parent;
1548 SendMessageW( hwnd, WM_PARENTNOTIFY,
1549 MAKEWPARAM( event, idChild ), MAKELPARAM( pt.x, pt.y ) );
1554 /***********************************************************************
1555 * process_raw_keyboard_message
1557 * returns TRUE if the contents of 'msg' should be passed to the application
1559 static BOOL process_raw_keyboard_message( MSG *msg, HWND hwnd_filter, UINT first, UINT last )
1561 EVENTMSG event;
1563 event.message = msg->message;
1564 event.hwnd = msg->hwnd;
1565 event.time = msg->time;
1566 event.paramL = (msg->wParam & 0xFF) | (HIWORD(msg->lParam) << 8);
1567 event.paramH = msg->lParam & 0x7FFF;
1568 if (HIWORD(msg->lParam) & 0x0100) event.paramH |= 0x8000; /* special_key - bit */
1569 HOOK_CallHooks( WH_JOURNALRECORD, HC_ACTION, 0, (LPARAM)&event, TRUE );
1570 return check_message_filter( msg, hwnd_filter, first, last );
1574 /***********************************************************************
1575 * process_cooked_keyboard_message
1577 * returns TRUE if the contents of 'msg' should be passed to the application
1579 static BOOL process_cooked_keyboard_message( MSG *msg, BOOL remove )
1581 if (remove)
1583 /* Handle F1 key by sending out WM_HELP message */
1584 if ((msg->message == WM_KEYUP) &&
1585 (msg->wParam == VK_F1) &&
1586 (msg->hwnd != GetDesktopWindow()) &&
1587 !MENU_IsMenuActive())
1589 HELPINFO hi;
1590 hi.cbSize = sizeof(HELPINFO);
1591 hi.iContextType = HELPINFO_WINDOW;
1592 hi.iCtrlId = GetWindowLongPtrA( msg->hwnd, GWLP_ID );
1593 hi.hItemHandle = msg->hwnd;
1594 hi.dwContextId = GetWindowContextHelpId( msg->hwnd );
1595 hi.MousePos = msg->pt;
1596 SendMessageW( msg->hwnd, WM_HELP, 0, (LPARAM)&hi );
1600 if (HOOK_CallHooks( WH_KEYBOARD, remove ? HC_ACTION : HC_NOREMOVE,
1601 LOWORD(msg->wParam), msg->lParam, TRUE ))
1603 /* skip this message */
1604 HOOK_CallHooks( WH_CBT, HCBT_KEYSKIPPED, LOWORD(msg->wParam), msg->lParam, TRUE );
1605 return FALSE;
1607 return TRUE;
1611 /***********************************************************************
1612 * process_raw_mouse_message
1614 static BOOL process_raw_mouse_message( MSG *msg, HWND hwnd_filter, UINT first,
1615 UINT last, BOOL remove )
1617 static MSG clk_msg;
1619 POINT pt;
1620 UINT message;
1621 INT hittest;
1622 EVENTMSG event;
1623 GUITHREADINFO info;
1624 HWND hWndScope = msg->hwnd;
1626 /* find the window to dispatch this mouse message to */
1628 hittest = HTCLIENT;
1629 GetGUIThreadInfo( GetCurrentThreadId(), &info );
1630 if (!(msg->hwnd = info.hwndCapture))
1632 /* If no capture HWND, find window which contains the mouse position.
1633 * Also find the position of the cursor hot spot (hittest) */
1634 if (!IsWindow(hWndScope)) hWndScope = 0;
1635 if (!(msg->hwnd = WINPOS_WindowFromPoint( hWndScope, msg->pt, &hittest )))
1636 msg->hwnd = GetDesktopWindow();
1639 event.message = msg->message;
1640 event.time = msg->time;
1641 event.hwnd = msg->hwnd;
1642 event.paramL = msg->pt.x;
1643 event.paramH = msg->pt.y;
1644 HOOK_CallHooks( WH_JOURNALRECORD, HC_ACTION, 0, (LPARAM)&event, TRUE );
1646 if (hwnd_filter)
1648 if (msg->hwnd != hwnd_filter && !IsChild( hwnd_filter, msg->hwnd )) return FALSE;
1651 pt = msg->pt;
1652 message = msg->message;
1653 /* Note: windows has no concept of a non-client wheel message */
1654 if (message != WM_MOUSEWHEEL)
1656 if (hittest != HTCLIENT)
1658 message += WM_NCMOUSEMOVE - WM_MOUSEMOVE;
1659 msg->wParam = hittest;
1661 else
1663 /* coordinates don't get translated while tracking a menu */
1664 /* FIXME: should differentiate popups and top-level menus */
1665 if (!(info.flags & GUI_INMENUMODE))
1666 ScreenToClient( msg->hwnd, &pt );
1669 msg->lParam = MAKELONG( pt.x, pt.y );
1671 /* translate double clicks */
1673 if ((msg->message == WM_LBUTTONDOWN) ||
1674 (msg->message == WM_RBUTTONDOWN) ||
1675 (msg->message == WM_MBUTTONDOWN))
1677 /* translate double clicks -
1678 * note that ...MOUSEMOVEs can slip in between
1679 * ...BUTTONDOWN and ...BUTTONDBLCLK messages */
1681 if ((info.flags & (GUI_INMENUMODE|GUI_INMOVESIZE)) ||
1682 hittest != HTCLIENT ||
1683 (GetClassLongA( msg->hwnd, GCL_STYLE ) & CS_DBLCLKS))
1685 if ((msg->message == clk_msg.message) &&
1686 (msg->hwnd == clk_msg.hwnd) &&
1687 (msg->time - clk_msg.time < GetDoubleClickTime()) &&
1688 (abs(msg->pt.x - clk_msg.pt.x) < GetSystemMetrics(SM_CXDOUBLECLK)/2) &&
1689 (abs(msg->pt.y - clk_msg.pt.y) < GetSystemMetrics(SM_CYDOUBLECLK)/2))
1691 message += (WM_LBUTTONDBLCLK - WM_LBUTTONDOWN);
1692 msg->message = 0; /* to clear the double click conditions */
1695 if (first || last)
1697 if (message < first || message > last) remove = FALSE;
1699 /* update static double click conditions */
1700 if (remove) clk_msg = *msg;
1703 msg->message = message;
1704 if (first || last) return (message >= first && message <= last);
1705 return TRUE;
1709 /***********************************************************************
1710 * process_cooked_mouse_message
1712 * returns TRUE if the contents of 'msg' should be passed to the application
1714 static BOOL process_cooked_mouse_message( MSG *msg, ULONG_PTR extra_info, BOOL remove )
1716 MOUSEHOOKSTRUCT hook;
1717 INT hittest = HTCLIENT;
1718 UINT raw_message = msg->message;
1719 BOOL eatMsg;
1721 if (msg->message >= WM_NCMOUSEFIRST && msg->message <= WM_NCMOUSELAST)
1723 raw_message += WM_MOUSEFIRST - WM_NCMOUSEFIRST;
1724 hittest = msg->wParam;
1726 if (raw_message == WM_LBUTTONDBLCLK ||
1727 raw_message == WM_RBUTTONDBLCLK ||
1728 raw_message == WM_MBUTTONDBLCLK)
1730 raw_message += WM_LBUTTONDOWN - WM_LBUTTONDBLCLK;
1733 hook.pt = msg->pt;
1734 hook.hwnd = msg->hwnd;
1735 hook.wHitTestCode = hittest;
1736 hook.dwExtraInfo = extra_info;
1737 if (HOOK_CallHooks( WH_MOUSE, remove ? HC_ACTION : HC_NOREMOVE,
1738 msg->message, (LPARAM)&hook, TRUE ))
1740 hook.pt = msg->pt;
1741 hook.hwnd = msg->hwnd;
1742 hook.wHitTestCode = hittest;
1743 hook.dwExtraInfo = extra_info;
1744 HOOK_CallHooks( WH_CBT, HCBT_CLICKSKIPPED, msg->message, (LPARAM)&hook, TRUE );
1745 return FALSE;
1748 if ((hittest == HTERROR) || (hittest == HTNOWHERE))
1750 SendMessageW( msg->hwnd, WM_SETCURSOR, (WPARAM)msg->hwnd,
1751 MAKELONG( hittest, raw_message ));
1752 return FALSE;
1755 if (!remove || GetCapture()) return TRUE;
1757 eatMsg = FALSE;
1759 if ((raw_message == WM_LBUTTONDOWN) ||
1760 (raw_message == WM_RBUTTONDOWN) ||
1761 (raw_message == WM_MBUTTONDOWN))
1763 /* Send the WM_PARENTNOTIFY,
1764 * note that even for double/nonclient clicks
1765 * notification message is still WM_L/M/RBUTTONDOWN.
1767 send_parent_notify( msg->hwnd, raw_message, 0, msg->pt );
1769 /* Activate the window if needed */
1771 if (msg->hwnd != GetActiveWindow())
1773 HWND hwndTop = msg->hwnd;
1774 while (hwndTop)
1776 if ((GetWindowLongW( hwndTop, GWL_STYLE ) & (WS_POPUP|WS_CHILD)) != WS_CHILD) break;
1777 hwndTop = GetParent( hwndTop );
1780 if (hwndTop && hwndTop != GetDesktopWindow())
1782 LONG ret = SendMessageW( msg->hwnd, WM_MOUSEACTIVATE, (WPARAM)hwndTop,
1783 MAKELONG( hittest, raw_message ) );
1784 switch(ret)
1786 case MA_NOACTIVATEANDEAT:
1787 eatMsg = TRUE;
1788 /* fall through */
1789 case MA_NOACTIVATE:
1790 break;
1791 case MA_ACTIVATEANDEAT:
1792 eatMsg = TRUE;
1793 /* fall through */
1794 case MA_ACTIVATE:
1795 case 0:
1796 if (!FOCUS_MouseActivate( hwndTop )) eatMsg = TRUE;
1797 break;
1798 default:
1799 WARN( "unknown WM_MOUSEACTIVATE code %ld\n", ret );
1800 break;
1806 /* send the WM_SETCURSOR message */
1808 /* Windows sends the normal mouse message as the message parameter
1809 in the WM_SETCURSOR message even if it's non-client mouse message */
1810 SendMessageW( msg->hwnd, WM_SETCURSOR, (WPARAM)msg->hwnd,
1811 MAKELONG( hittest, raw_message ));
1813 return !eatMsg;
1817 /***********************************************************************
1818 * process_hardware_message
1820 * Process a hardware message; return TRUE if message should be passed on to the app
1822 static BOOL process_hardware_message( MSG *msg, ULONG_PTR extra_info, HWND hwnd,
1823 UINT first, UINT last, BOOL remove )
1825 BOOL ret;
1827 if (is_keyboard_message( msg->message ))
1829 if (!process_raw_keyboard_message( msg, hwnd, first, last )) return FALSE;
1830 ret = process_cooked_keyboard_message( msg, remove );
1832 else if (is_mouse_message( msg->message ))
1834 if (!process_raw_mouse_message( msg, hwnd, first, last, remove )) return FALSE;
1835 ret = process_cooked_mouse_message( msg, extra_info, remove );
1837 else
1839 ERR( "unknown message type %x\n", msg->message );
1840 return FALSE;
1843 /* tell the server we have passed it to the app
1844 * (even though we may end up dropping it later on)
1846 SERVER_START_REQ( reply_message )
1848 req->type = MSG_HARDWARE;
1849 req->result = 0;
1850 req->remove = remove || !ret;
1851 if (wine_server_call( req ))
1852 FIXME("Failed to reply to MSG_HARDWARE message. Message may not be removed from queue.\n");
1854 SERVER_END_REQ;
1855 return ret;
1859 /***********************************************************************
1860 * call_sendmsg_callback
1862 * Call the callback function of SendMessageCallback.
1864 static inline void call_sendmsg_callback( SENDASYNCPROC callback, HWND hwnd, UINT msg,
1865 ULONG_PTR data, LRESULT result )
1867 if (TRACE_ON(relay))
1868 DPRINTF( "%04lx:Call message callback %p (hwnd=%p,msg=%s,data=%08lx,result=%08lx)\n",
1869 GetCurrentThreadId(), callback, hwnd, SPY_GetMsgName( msg, hwnd ),
1870 data, result );
1871 callback( hwnd, msg, data, result );
1872 if (TRACE_ON(relay))
1873 DPRINTF( "%04lx:Ret message callback %p (hwnd=%p,msg=%s,data=%08lx,result=%08lx)\n",
1874 GetCurrentThreadId(), callback, hwnd, SPY_GetMsgName( msg, hwnd ),
1875 data, result );
1879 /***********************************************************************
1880 * get_hook_proc
1882 * Retrieve the hook procedure real value for a module-relative proc
1884 static void *get_hook_proc( void *proc, const WCHAR *module )
1886 HMODULE mod;
1888 if (!(mod = GetModuleHandleW(module)))
1890 TRACE( "loading %s\n", debugstr_w(module) );
1891 /* FIXME: the library will never be freed */
1892 if (!(mod = LoadLibraryW(module))) return NULL;
1894 return (char *)mod + (ULONG_PTR)proc;
1898 /***********************************************************************
1899 * peek_message
1901 * Peek for a message matching the given parameters. Return FALSE if none available.
1902 * All pending sent messages are processed before returning.
1904 static BOOL peek_message( MSG *msg, HWND hwnd, UINT first, UINT last, int flags )
1906 LRESULT result;
1907 ULONG_PTR extra_info = 0;
1908 MESSAGEQUEUE *queue = QUEUE_Current();
1909 struct received_message_info info, *old_info;
1910 int get_next_hw = 0; /* set when the previous message was a rejected hardware message */
1912 if (!first && !last) last = ~0;
1914 for (;;)
1916 NTSTATUS res;
1917 void *buffer = NULL;
1918 size_t size = 0, buffer_size = 0;
1920 do /* loop while buffer is too small */
1922 if (buffer_size && !(buffer = HeapAlloc( GetProcessHeap(), 0, buffer_size )))
1923 return FALSE;
1924 SERVER_START_REQ( get_message )
1926 req->flags = flags;
1927 req->get_win = hwnd;
1928 req->get_first = first;
1929 req->get_last = last;
1930 req->get_next_hw = get_next_hw;
1931 if (buffer_size) wine_server_set_reply( req, buffer, buffer_size );
1932 if (!(res = wine_server_call( req )))
1934 size = wine_server_reply_size( reply );
1935 info.type = reply->type;
1936 info.msg.hwnd = reply->win;
1937 info.msg.message = reply->msg;
1938 info.msg.wParam = reply->wparam;
1939 info.msg.lParam = reply->lparam;
1940 info.msg.time = reply->time;
1941 info.msg.pt.x = reply->x;
1942 info.msg.pt.y = reply->y;
1943 info.hook = reply->hook;
1944 info.hook_proc = reply->hook_proc;
1945 extra_info = reply->info;
1947 else
1949 HeapFree( GetProcessHeap(), 0, buffer );
1950 buffer_size = reply->total;
1953 SERVER_END_REQ;
1954 } while (res == STATUS_BUFFER_OVERFLOW);
1956 if (res) return FALSE;
1957 get_next_hw = 0;
1959 TRACE( "got type %d msg %x (%s) hwnd %p wp %x lp %lx\n",
1960 info.type, info.msg.message,
1961 (info.type == MSG_WINEVENT) ? "MSG_WINEVENT" : SPY_GetMsgName(info.msg.message, info.msg.hwnd),
1962 info.msg.hwnd, info.msg.wParam, info.msg.lParam );
1964 switch(info.type)
1966 case MSG_ASCII:
1967 case MSG_UNICODE:
1968 info.flags = ISMEX_SEND;
1969 break;
1970 case MSG_NOTIFY:
1971 info.flags = ISMEX_NOTIFY;
1972 break;
1973 case MSG_CALLBACK:
1974 info.flags = ISMEX_CALLBACK;
1975 break;
1976 case MSG_CALLBACK_RESULT:
1977 call_sendmsg_callback( (SENDASYNCPROC)info.msg.wParam, info.msg.hwnd,
1978 info.msg.message, extra_info, info.msg.lParam );
1979 goto next;
1980 case MSG_WINEVENT:
1981 if (size)
1983 WCHAR module[MAX_PATH];
1984 size = min( size, (MAX_PATH - 1) * sizeof(WCHAR) );
1985 memcpy( module, buffer, size );
1986 module[size / sizeof(WCHAR)] = 0;
1987 if (!(info.hook_proc = get_hook_proc( info.hook_proc, module )))
1989 ERR( "invalid winevent hook module name %s\n", debugstr_w(module) );
1990 goto next;
1993 if (TRACE_ON(relay))
1994 DPRINTF( "%04lx:Call winevent proc %p (hook=%p,event=%x,hwnd=%p,object_id=%x,child_id=%lx,tid=%04lx,time=%lx)\n",
1995 GetCurrentThreadId(), info.hook_proc,
1996 info.hook, info.msg.message, info.msg.hwnd, info.msg.wParam,
1997 info.msg.lParam, extra_info, info.msg.time);
1999 info.hook_proc( info.hook, info.msg.message, info.msg.hwnd, info.msg.wParam,
2000 info.msg.lParam, extra_info, info.msg.time );
2002 if (TRACE_ON(relay))
2003 DPRINTF( "%04lx:Ret winevent proc %p (hook=%p,event=%x,hwnd=%p,object_id=%x,child_id=%lx,tid=%04lx,time=%lx)\n",
2004 GetCurrentThreadId(), info.hook_proc,
2005 info.hook, info.msg.message, info.msg.hwnd, info.msg.wParam,
2006 info.msg.lParam, extra_info, info.msg.time);
2007 goto next;
2008 case MSG_OTHER_PROCESS:
2009 info.flags = ISMEX_SEND;
2010 if (!unpack_message( info.msg.hwnd, info.msg.message, &info.msg.wParam,
2011 &info.msg.lParam, &buffer, size ))
2013 ERR( "invalid packed message %x (%s) hwnd %p wp %x lp %lx size %d\n",
2014 info.msg.message, SPY_GetMsgName(info.msg.message, info.msg.hwnd), info.msg.hwnd,
2015 info.msg.wParam, info.msg.lParam, size );
2016 /* ignore it */
2017 reply_message( &info, 0, TRUE );
2018 goto next;
2020 break;
2021 case MSG_HARDWARE:
2022 get_next_hw = 1;
2023 if (!process_hardware_message( &info.msg, extra_info,
2024 hwnd, first, last, flags & GET_MSG_REMOVE ))
2026 TRACE("dropping msg %x\n", info.msg.message );
2027 goto next; /* ignore it */
2029 queue->GetMessagePosVal = MAKELONG( info.msg.pt.x, info.msg.pt.y );
2030 /* fall through */
2031 case MSG_POSTED:
2032 queue->GetMessageExtraInfoVal = extra_info;
2033 if (info.msg.message >= WM_DDE_FIRST && info.msg.message <= WM_DDE_LAST)
2035 if (!unpack_dde_message( info.msg.hwnd, info.msg.message, &info.msg.wParam,
2036 &info.msg.lParam, &buffer, size ))
2038 ERR( "invalid packed dde-message %x (%s) hwnd %p wp %x lp %lx size %d\n",
2039 info.msg.message, SPY_GetMsgName(info.msg.message, info.msg.hwnd),
2040 info.msg.hwnd, info.msg.wParam, info.msg.lParam, size );
2041 goto next; /* ignore it */
2044 *msg = info.msg;
2045 HeapFree( GetProcessHeap(), 0, buffer );
2046 return TRUE;
2049 /* if we get here, we have a sent message; call the window procedure */
2050 old_info = queue->receive_info;
2051 queue->receive_info = &info;
2052 result = call_window_proc( info.msg.hwnd, info.msg.message, info.msg.wParam,
2053 info.msg.lParam, (info.type != MSG_ASCII), FALSE );
2054 reply_message( &info, result, TRUE );
2055 queue->receive_info = old_info;
2056 next:
2057 HeapFree( GetProcessHeap(), 0, buffer );
2062 /***********************************************************************
2063 * process_sent_messages
2065 * Process all pending sent messages.
2067 inline static void process_sent_messages(void)
2069 MSG msg;
2070 peek_message( &msg, 0, 0, 0, GET_MSG_REMOVE | GET_MSG_SENT_ONLY );
2074 /***********************************************************************
2075 * wait_message_reply
2077 * Wait until a sent message gets replied to.
2079 static void wait_message_reply( UINT flags )
2081 MESSAGEQUEUE *queue;
2083 if (!(queue = QUEUE_Current())) return;
2085 for (;;)
2087 unsigned int wake_bits = 0, changed_bits = 0;
2088 DWORD dwlc, res;
2090 SERVER_START_REQ( set_queue_mask )
2092 req->wake_mask = QS_SMRESULT | ((flags & SMTO_BLOCK) ? 0 : QS_SENDMESSAGE);
2093 req->changed_mask = req->wake_mask;
2094 req->skip_wait = 1;
2095 if (!wine_server_call( req ))
2097 wake_bits = reply->wake_bits;
2098 changed_bits = reply->changed_bits;
2101 SERVER_END_REQ;
2103 if (wake_bits & QS_SMRESULT) return; /* got a result */
2104 if (wake_bits & QS_SENDMESSAGE)
2106 /* Process the sent message immediately */
2107 process_sent_messages();
2108 continue;
2111 /* now wait for it */
2113 ReleaseThunkLock( &dwlc );
2115 if (USER_Driver.pMsgWaitForMultipleObjectsEx)
2116 res = USER_Driver.pMsgWaitForMultipleObjectsEx( 1, &queue->server_queue,
2117 INFINITE, QS_ALLINPUT, 0 );
2118 else
2119 res = WaitForSingleObject( queue->server_queue, INFINITE );
2121 if (dwlc) RestoreThunkLock( dwlc );
2125 /***********************************************************************
2126 * put_message_in_queue
2128 * Put a sent message into the destination queue.
2129 * For inter-process message, reply_size is set to expected size of reply data.
2131 static BOOL put_message_in_queue( DWORD dest_tid, const struct send_message_info *info,
2132 size_t *reply_size )
2134 struct packed_message data;
2135 unsigned int res;
2136 int i, timeout = -1;
2138 if (info->type != MSG_NOTIFY &&
2139 info->type != MSG_CALLBACK &&
2140 info->type != MSG_POSTED &&
2141 info->timeout != INFINITE)
2142 timeout = info->timeout;
2144 data.count = 0;
2145 if (info->type == MSG_OTHER_PROCESS)
2147 *reply_size = pack_message( info->hwnd, info->msg, info->wparam, info->lparam, &data );
2148 if (data.count == -1)
2150 WARN( "cannot pack message %x\n", info->msg );
2151 return FALSE;
2154 else if (info->type == MSG_POSTED && info->msg >= WM_DDE_FIRST && info->msg <= WM_DDE_LAST)
2156 return post_dde_message( dest_tid, &data, info );
2159 SERVER_START_REQ( send_message )
2161 req->id = dest_tid;
2162 req->type = info->type;
2163 req->flags = 0;
2164 req->win = info->hwnd;
2165 req->msg = info->msg;
2166 req->wparam = info->wparam;
2167 req->lparam = info->lparam;
2168 req->time = GetCurrentTime();
2169 req->timeout = timeout;
2171 if (info->type == MSG_CALLBACK)
2173 req->callback = info->callback;
2174 req->info = info->data;
2177 if (info->flags & SMTO_ABORTIFHUNG) req->flags |= SEND_MSG_ABORT_IF_HUNG;
2178 for (i = 0; i < data.count; i++) wine_server_add_data( req, data.data[i], data.size[i] );
2179 if ((res = wine_server_call( req )))
2181 if (res == STATUS_INVALID_PARAMETER)
2182 /* FIXME: find a STATUS_ value for this one */
2183 SetLastError( ERROR_INVALID_THREAD_ID );
2184 else
2185 SetLastError( RtlNtStatusToDosError(res) );
2188 SERVER_END_REQ;
2189 return !res;
2193 /***********************************************************************
2194 * retrieve_reply
2196 * Retrieve a message reply from the server.
2198 static LRESULT retrieve_reply( const struct send_message_info *info,
2199 size_t reply_size, LRESULT *result )
2201 NTSTATUS status;
2202 void *reply_data = NULL;
2204 if (reply_size)
2206 if (!(reply_data = HeapAlloc( GetProcessHeap(), 0, reply_size )))
2208 WARN( "no memory for reply %d bytes, will be truncated\n", reply_size );
2209 reply_size = 0;
2212 SERVER_START_REQ( get_message_reply )
2214 req->cancel = 1;
2215 if (reply_size) wine_server_set_reply( req, reply_data, reply_size );
2216 if (!(status = wine_server_call( req ))) *result = reply->result;
2217 reply_size = wine_server_reply_size( reply );
2219 SERVER_END_REQ;
2220 if (!status && reply_size)
2221 unpack_reply( info->hwnd, info->msg, info->wparam, info->lparam, reply_data, reply_size );
2223 HeapFree( GetProcessHeap(), 0, reply_data );
2225 TRACE( "hwnd %p msg %x (%s) wp %x lp %lx got reply %lx (err=%ld)\n",
2226 info->hwnd, info->msg, SPY_GetMsgName(info->msg, info->hwnd), info->wparam,
2227 info->lparam, *result, status );
2229 /* MSDN states that last error is 0 on timeout, but at least NT4 returns ERROR_TIMEOUT */
2230 if (status) SetLastError( RtlNtStatusToDosError(status) );
2231 return !status;
2235 /***********************************************************************
2236 * send_inter_thread_message
2238 static LRESULT send_inter_thread_message( DWORD dest_tid, const struct send_message_info *info,
2239 LRESULT *res_ptr )
2241 LRESULT ret;
2242 int locks;
2243 size_t reply_size = 0;
2245 TRACE( "hwnd %p msg %x (%s) wp %x lp %lx\n",
2246 info->hwnd, info->msg, SPY_GetMsgName(info->msg, info->hwnd), info->wparam, info->lparam );
2248 if (!put_message_in_queue( dest_tid, info, &reply_size )) return 0;
2250 /* there's no reply to wait for on notify/callback messages */
2251 if (info->type == MSG_NOTIFY || info->type == MSG_CALLBACK) return 1;
2253 locks = WIN_SuspendWndsLock();
2255 wait_message_reply( info->flags );
2256 ret = retrieve_reply( info, reply_size, res_ptr );
2258 WIN_RestoreWndsLock( locks );
2259 return ret;
2263 /***********************************************************************
2264 * MSG_SendInternalMessageTimeout
2266 * Same as SendMessageTimeoutW but sends the message to a specific thread
2267 * without requiring a window handle. Only works for internal Wine messages.
2269 LRESULT MSG_SendInternalMessageTimeout( DWORD dest_pid, DWORD dest_tid,
2270 UINT msg, WPARAM wparam, LPARAM lparam,
2271 UINT flags, UINT timeout, PDWORD_PTR res_ptr )
2273 struct send_message_info info;
2274 LRESULT ret, result;
2276 assert( msg & 0x80000000 ); /* must be an internal Wine message */
2278 info.type = MSG_UNICODE;
2279 info.hwnd = 0;
2280 info.msg = msg;
2281 info.wparam = wparam;
2282 info.lparam = lparam;
2283 info.flags = flags;
2284 info.timeout = timeout;
2286 if (USER_IsExitingThread( dest_tid )) return 0;
2288 if (dest_tid == GetCurrentThreadId())
2290 result = handle_internal_message( 0, msg, wparam, lparam );
2291 ret = 1;
2293 else
2295 if (dest_pid != GetCurrentProcessId()) info.type = MSG_OTHER_PROCESS;
2296 ret = send_inter_thread_message( dest_tid, &info, &result );
2298 if (ret && res_ptr) *res_ptr = result;
2299 return ret;
2303 /***********************************************************************
2304 * SendMessageTimeoutW (USER32.@)
2306 LRESULT WINAPI SendMessageTimeoutW( HWND hwnd, UINT msg, WPARAM wparam, LPARAM lparam,
2307 UINT flags, UINT timeout, PDWORD_PTR res_ptr )
2309 struct send_message_info info;
2310 DWORD dest_tid, dest_pid;
2311 LRESULT ret, result;
2313 info.type = MSG_UNICODE;
2314 info.hwnd = hwnd;
2315 info.msg = msg;
2316 info.wparam = wparam;
2317 info.lparam = lparam;
2318 info.flags = flags;
2319 info.timeout = timeout;
2321 if (is_broadcast(hwnd))
2323 EnumWindows( broadcast_message_callback, (LPARAM)&info );
2324 if (res_ptr) *res_ptr = 1;
2325 return 1;
2328 if (!(dest_tid = GetWindowThreadProcessId( hwnd, &dest_pid ))) return 0;
2330 if (USER_IsExitingThread( dest_tid )) return 0;
2332 SPY_EnterMessage( SPY_SENDMESSAGE, hwnd, msg, wparam, lparam );
2334 if (dest_tid == GetCurrentThreadId())
2336 result = call_window_proc( hwnd, msg, wparam, lparam, TRUE, TRUE );
2337 ret = 1;
2339 else
2341 if (dest_pid != GetCurrentProcessId()) info.type = MSG_OTHER_PROCESS;
2342 ret = send_inter_thread_message( dest_tid, &info, &result );
2345 SPY_ExitMessage( SPY_RESULT_OK, hwnd, msg, result, wparam, lparam );
2346 if (ret && res_ptr) *res_ptr = result;
2347 return ret;
2351 /***********************************************************************
2352 * SendMessageTimeoutA (USER32.@)
2354 LRESULT WINAPI SendMessageTimeoutA( HWND hwnd, UINT msg, WPARAM wparam, LPARAM lparam,
2355 UINT flags, UINT timeout, PDWORD_PTR res_ptr )
2357 struct send_message_info info;
2358 DWORD dest_tid, dest_pid;
2359 LRESULT ret, result;
2361 info.type = MSG_ASCII;
2362 info.hwnd = hwnd;
2363 info.msg = msg;
2364 info.wparam = wparam;
2365 info.lparam = lparam;
2366 info.flags = flags;
2367 info.timeout = timeout;
2369 if (is_broadcast(hwnd))
2371 EnumWindows( broadcast_message_callback, (LPARAM)&info );
2372 if (res_ptr) *res_ptr = 1;
2373 return 1;
2376 if (!(dest_tid = GetWindowThreadProcessId( hwnd, &dest_pid ))) return 0;
2378 if (USER_IsExitingThread( dest_tid )) return 0;
2380 SPY_EnterMessage( SPY_SENDMESSAGE, hwnd, msg, wparam, lparam );
2382 if (dest_tid == GetCurrentThreadId())
2384 result = call_window_proc( hwnd, msg, wparam, lparam, FALSE, TRUE );
2385 ret = 1;
2387 else if (dest_pid == GetCurrentProcessId())
2389 ret = send_inter_thread_message( dest_tid, &info, &result );
2391 else
2393 /* inter-process message: need to map to Unicode */
2394 info.type = MSG_OTHER_PROCESS;
2395 if (is_unicode_message( info.msg ))
2397 if (WINPROC_MapMsg32ATo32W( info.hwnd, info.msg, &info.wparam, &info.lparam ) == -1)
2398 return 0;
2399 ret = send_inter_thread_message( dest_tid, &info, &result );
2400 result = WINPROC_UnmapMsg32ATo32W( info.hwnd, info.msg, info.wparam,
2401 info.lparam, result );
2403 else ret = send_inter_thread_message( dest_tid, &info, &result );
2405 SPY_ExitMessage( SPY_RESULT_OK, hwnd, msg, result, wparam, lparam );
2406 if (ret && res_ptr) *res_ptr = result;
2407 return ret;
2411 /***********************************************************************
2412 * SendMessageW (USER32.@)
2414 LRESULT WINAPI SendMessageW( HWND hwnd, UINT msg, WPARAM wparam, LPARAM lparam )
2416 LRESULT res = 0;
2417 SendMessageTimeoutW( hwnd, msg, wparam, lparam, SMTO_NORMAL, INFINITE, &res );
2418 return res;
2422 /***********************************************************************
2423 * SendMessageA (USER32.@)
2425 LRESULT WINAPI SendMessageA( HWND hwnd, UINT msg, WPARAM wparam, LPARAM lparam )
2427 LRESULT res = 0;
2428 SendMessageTimeoutA( hwnd, msg, wparam, lparam, SMTO_NORMAL, INFINITE, &res );
2429 return res;
2433 /***********************************************************************
2434 * SendNotifyMessageA (USER32.@)
2436 BOOL WINAPI SendNotifyMessageA( HWND hwnd, UINT msg, WPARAM wparam, LPARAM lparam )
2438 return SendNotifyMessageW( hwnd, msg, map_wparam_AtoW( msg, wparam ), lparam );
2442 /***********************************************************************
2443 * SendNotifyMessageW (USER32.@)
2445 BOOL WINAPI SendNotifyMessageW( HWND hwnd, UINT msg, WPARAM wparam, LPARAM lparam )
2447 struct send_message_info info;
2448 DWORD dest_tid;
2449 LRESULT result;
2451 if (is_pointer_message(msg))
2453 SetLastError( ERROR_MESSAGE_SYNC_ONLY );
2454 return FALSE;
2457 info.type = MSG_NOTIFY;
2458 info.hwnd = hwnd;
2459 info.msg = msg;
2460 info.wparam = wparam;
2461 info.lparam = lparam;
2462 info.flags = 0;
2464 if (is_broadcast(hwnd))
2466 EnumWindows( broadcast_message_callback, (LPARAM)&info );
2467 return TRUE;
2470 if (!(dest_tid = GetWindowThreadProcessId( hwnd, NULL ))) return FALSE;
2472 if (USER_IsExitingThread( dest_tid )) return TRUE;
2474 if (dest_tid == GetCurrentThreadId())
2476 call_window_proc( hwnd, msg, wparam, lparam, TRUE, TRUE );
2477 return TRUE;
2479 return send_inter_thread_message( dest_tid, &info, &result );
2483 /***********************************************************************
2484 * SendMessageCallbackA (USER32.@)
2486 BOOL WINAPI SendMessageCallbackA( HWND hwnd, UINT msg, WPARAM wparam, LPARAM lparam,
2487 SENDASYNCPROC callback, ULONG_PTR data )
2489 return SendMessageCallbackW( hwnd, msg, map_wparam_AtoW( msg, wparam ),
2490 lparam, callback, data );
2494 /***********************************************************************
2495 * SendMessageCallbackW (USER32.@)
2497 BOOL WINAPI SendMessageCallbackW( HWND hwnd, UINT msg, WPARAM wparam, LPARAM lparam,
2498 SENDASYNCPROC callback, ULONG_PTR data )
2500 struct send_message_info info;
2501 LRESULT result;
2502 DWORD dest_tid;
2504 if (is_pointer_message(msg))
2506 SetLastError( ERROR_MESSAGE_SYNC_ONLY );
2507 return FALSE;
2510 info.type = MSG_CALLBACK;
2511 info.hwnd = hwnd;
2512 info.msg = msg;
2513 info.wparam = wparam;
2514 info.lparam = lparam;
2515 info.callback = callback;
2516 info.data = data;
2517 info.flags = 0;
2519 if (is_broadcast(hwnd))
2521 EnumWindows( broadcast_message_callback, (LPARAM)&info );
2522 return TRUE;
2525 if (!(dest_tid = GetWindowThreadProcessId( hwnd, NULL ))) return FALSE;
2527 if (USER_IsExitingThread( dest_tid )) return TRUE;
2529 if (dest_tid == GetCurrentThreadId())
2531 result = call_window_proc( hwnd, msg, wparam, lparam, TRUE, TRUE );
2532 call_sendmsg_callback( callback, hwnd, msg, data, result );
2533 return TRUE;
2535 FIXME( "callback will not be called\n" );
2536 return send_inter_thread_message( dest_tid, &info, &result );
2540 /***********************************************************************
2541 * ReplyMessage (USER32.@)
2543 BOOL WINAPI ReplyMessage( LRESULT result )
2545 MESSAGEQUEUE *queue = QUEUE_Current();
2546 struct received_message_info *info = queue->receive_info;
2548 if (!info) return FALSE;
2549 reply_message( info, result, FALSE );
2550 return TRUE;
2554 /***********************************************************************
2555 * InSendMessage (USER32.@)
2557 BOOL WINAPI InSendMessage(void)
2559 return (InSendMessageEx(NULL) & (ISMEX_SEND|ISMEX_REPLIED)) == ISMEX_SEND;
2563 /***********************************************************************
2564 * InSendMessageEx (USER32.@)
2566 DWORD WINAPI InSendMessageEx( LPVOID reserved )
2568 MESSAGEQUEUE *queue = QUEUE_Current();
2569 struct received_message_info *info = queue->receive_info;
2571 if (info) return info->flags;
2572 return ISMEX_NOSEND;
2576 /***********************************************************************
2577 * PostMessageA (USER32.@)
2579 BOOL WINAPI PostMessageA( HWND hwnd, UINT msg, WPARAM wparam, LPARAM lparam )
2581 return PostMessageW( hwnd, msg, map_wparam_AtoW( msg, wparam ), lparam );
2585 /***********************************************************************
2586 * PostMessageW (USER32.@)
2588 BOOL WINAPI PostMessageW( HWND hwnd, UINT msg, WPARAM wparam, LPARAM lparam )
2590 struct send_message_info info;
2591 DWORD dest_tid;
2593 if (is_pointer_message( msg ))
2595 SetLastError( ERROR_MESSAGE_SYNC_ONLY );
2596 return FALSE;
2599 TRACE( "hwnd %p msg %x (%s) wp %x lp %lx\n",
2600 hwnd, msg, SPY_GetMsgName(msg, hwnd), wparam, lparam );
2602 info.type = MSG_POSTED;
2603 info.hwnd = hwnd;
2604 info.msg = msg;
2605 info.wparam = wparam;
2606 info.lparam = lparam;
2607 info.flags = 0;
2609 if (is_broadcast(hwnd))
2611 EnumWindows( broadcast_message_callback, (LPARAM)&info );
2612 return TRUE;
2615 if (!hwnd) return PostThreadMessageW( GetCurrentThreadId(), msg, wparam, lparam );
2617 if (!(dest_tid = GetWindowThreadProcessId( hwnd, NULL ))) return FALSE;
2619 if (USER_IsExitingThread( dest_tid )) return TRUE;
2621 return put_message_in_queue( dest_tid, &info, NULL );
2625 /**********************************************************************
2626 * PostThreadMessageA (USER32.@)
2628 BOOL WINAPI PostThreadMessageA( DWORD thread, UINT msg, WPARAM wparam, LPARAM lparam )
2630 return PostThreadMessageW( thread, msg, map_wparam_AtoW( msg, wparam ), lparam );
2634 /**********************************************************************
2635 * PostThreadMessageW (USER32.@)
2637 BOOL WINAPI PostThreadMessageW( DWORD thread, UINT msg, WPARAM wparam, LPARAM lparam )
2639 struct send_message_info info;
2641 if (is_pointer_message( msg ))
2643 SetLastError( ERROR_MESSAGE_SYNC_ONLY );
2644 return FALSE;
2646 if (USER_IsExitingThread( thread )) return TRUE;
2648 info.type = MSG_POSTED;
2649 info.hwnd = 0;
2650 info.msg = msg;
2651 info.wparam = wparam;
2652 info.lparam = lparam;
2653 info.flags = 0;
2654 return put_message_in_queue( thread, &info, NULL );
2658 /***********************************************************************
2659 * PostQuitMessage (USER32.@)
2661 void WINAPI PostQuitMessage( INT exitCode )
2663 PostThreadMessageW( GetCurrentThreadId(), WM_QUIT, exitCode, 0 );
2667 /***********************************************************************
2668 * PeekMessageW (USER32.@)
2670 BOOL WINAPI PeekMessageW( MSG *msg_out, HWND hwnd, UINT first, UINT last, UINT flags )
2672 MESSAGEQUEUE *queue;
2673 MSG msg;
2674 int locks;
2676 /* check for graphics events */
2677 if (USER_Driver.pMsgWaitForMultipleObjectsEx)
2678 USER_Driver.pMsgWaitForMultipleObjectsEx( 0, NULL, 0, QS_ALLINPUT, 0 );
2680 hwnd = WIN_GetFullHandle( hwnd );
2681 locks = WIN_SuspendWndsLock();
2683 if (!peek_message( &msg, hwnd, first, last, (flags & PM_REMOVE) ? GET_MSG_REMOVE : 0 ))
2685 if (!(flags & PM_NOYIELD))
2687 DWORD count;
2688 ReleaseThunkLock(&count);
2689 if (count) RestoreThunkLock(count);
2691 WIN_RestoreWndsLock( locks );
2692 return FALSE;
2695 if ((queue = QUEUE_Current()))
2697 queue->GetMessageTimeVal = msg.time;
2698 msg.pt.x = LOWORD( queue->GetMessagePosVal );
2699 msg.pt.y = HIWORD( queue->GetMessagePosVal );
2702 HOOK_CallHooks( WH_GETMESSAGE, HC_ACTION, flags & PM_REMOVE, (LPARAM)&msg, TRUE );
2704 WIN_RestoreWndsLock( locks );
2706 /* copy back our internal safe copy of message data to msg_out.
2707 * msg_out is a variable from the *program*, so it can't be used
2708 * internally as it can get "corrupted" by our use of SendMessage()
2709 * (back to the program) inside the message handling itself. */
2710 if (!msg_out)
2712 SetLastError( ERROR_NOACCESS );
2713 return FALSE;
2715 *msg_out = msg;
2716 return TRUE;
2720 /***********************************************************************
2721 * PeekMessageA (USER32.@)
2723 BOOL WINAPI PeekMessageA( MSG *msg, HWND hwnd, UINT first, UINT last, UINT flags )
2725 BOOL ret = PeekMessageW( msg, hwnd, first, last, flags );
2726 if (ret) msg->wParam = map_wparam_WtoA( msg->message, msg->wParam );
2727 return ret;
2731 /***********************************************************************
2732 * GetMessageW (USER32.@)
2734 BOOL WINAPI GetMessageW( MSG *msg, HWND hwnd, UINT first, UINT last )
2736 MESSAGEQUEUE *queue = QUEUE_Current();
2737 int mask, locks;
2739 mask = QS_POSTMESSAGE | QS_SENDMESSAGE; /* Always selected */
2740 if (first || last)
2742 if ((first <= WM_KEYLAST) && (last >= WM_KEYFIRST)) mask |= QS_KEY;
2743 if ( ((first <= WM_MOUSELAST) && (last >= WM_MOUSEFIRST)) ||
2744 ((first <= WM_NCMOUSELAST) && (last >= WM_NCMOUSEFIRST)) ) mask |= QS_MOUSE;
2745 if ((first <= WM_TIMER) && (last >= WM_TIMER)) mask |= QS_TIMER;
2746 if ((first <= WM_SYSTIMER) && (last >= WM_SYSTIMER)) mask |= QS_TIMER;
2747 if ((first <= WM_PAINT) && (last >= WM_PAINT)) mask |= QS_PAINT;
2749 else mask |= QS_MOUSE | QS_KEY | QS_TIMER | QS_PAINT;
2751 locks = WIN_SuspendWndsLock();
2753 while (!PeekMessageW( msg, hwnd, first, last, PM_REMOVE ))
2755 /* wait until one of the bits is set */
2756 unsigned int wake_bits = 0, changed_bits = 0;
2757 DWORD dwlc;
2759 SERVER_START_REQ( set_queue_mask )
2761 req->wake_mask = QS_SENDMESSAGE;
2762 req->changed_mask = mask;
2763 req->skip_wait = 1;
2764 if (!wine_server_call( req ))
2766 wake_bits = reply->wake_bits;
2767 changed_bits = reply->changed_bits;
2770 SERVER_END_REQ;
2772 if (changed_bits & mask) continue;
2773 if (wake_bits & QS_SENDMESSAGE) continue;
2775 TRACE( "(%04x) mask=%08x, bits=%08x, changed=%08x, waiting\n",
2776 queue->self, mask, wake_bits, changed_bits );
2778 ReleaseThunkLock( &dwlc );
2779 if (USER_Driver.pMsgWaitForMultipleObjectsEx)
2780 USER_Driver.pMsgWaitForMultipleObjectsEx( 1, &queue->server_queue, INFINITE,
2781 QS_ALLINPUT, 0 );
2782 else
2783 WaitForSingleObject( queue->server_queue, INFINITE );
2784 if (dwlc) RestoreThunkLock( dwlc );
2787 WIN_RestoreWndsLock( locks );
2789 return (msg->message != WM_QUIT);
2793 /***********************************************************************
2794 * GetMessageA (USER32.@)
2796 BOOL WINAPI GetMessageA( MSG *msg, HWND hwnd, UINT first, UINT last )
2798 GetMessageW( msg, hwnd, first, last );
2799 msg->wParam = map_wparam_WtoA( msg->message, msg->wParam );
2800 return (msg->message != WM_QUIT);
2804 /***********************************************************************
2805 * IsDialogMessage (USER32.@)
2806 * IsDialogMessageA (USER32.@)
2808 BOOL WINAPI IsDialogMessageA( HWND hwndDlg, LPMSG pmsg )
2810 MSG msg = *pmsg;
2811 msg.wParam = map_wparam_AtoW( msg.message, msg.wParam );
2812 return IsDialogMessageW( hwndDlg, &msg );
2816 /***********************************************************************
2817 * TranslateMessage (USER32.@)
2819 * Implementation of TranslateMessage.
2821 * TranslateMessage translates virtual-key messages into character-messages,
2822 * as follows :
2823 * WM_KEYDOWN/WM_KEYUP combinations produce a WM_CHAR or WM_DEADCHAR message.
2824 * ditto replacing WM_* with WM_SYS*
2825 * This produces WM_CHAR messages only for keys mapped to ASCII characters
2826 * by the keyboard driver.
2828 * If the message is WM_KEYDOWN, WM_KEYUP, WM_SYSKEYDOWN, or WM_SYSKEYUP, the
2829 * return value is nonzero, regardless of the translation.
2832 BOOL WINAPI TranslateMessage( const MSG *msg )
2834 UINT message;
2835 WCHAR wp[2];
2836 BYTE state[256];
2838 if (msg->message < WM_KEYFIRST || msg->message > WM_KEYLAST) return FALSE;
2839 if (msg->message != WM_KEYDOWN && msg->message != WM_SYSKEYDOWN) return TRUE;
2841 TRACE_(key)("Translating key %s (%04x), scancode %02x\n",
2842 SPY_GetVKeyName(msg->wParam), msg->wParam, LOBYTE(HIWORD(msg->lParam)));
2844 GetKeyboardState( state );
2845 /* FIXME : should handle ToUnicode yielding 2 */
2846 switch (ToUnicode(msg->wParam, HIWORD(msg->lParam), state, wp, 2, 0))
2848 case 1:
2849 message = (msg->message == WM_KEYDOWN) ? WM_CHAR : WM_SYSCHAR;
2850 TRACE_(key)("1 -> PostMessageW(%p,%s,%04x,%08lx)\n",
2851 msg->hwnd, SPY_GetMsgName(message, msg->hwnd), wp[0], msg->lParam);
2852 PostMessageW( msg->hwnd, message, wp[0], msg->lParam );
2853 break;
2855 case -1:
2856 message = (msg->message == WM_KEYDOWN) ? WM_DEADCHAR : WM_SYSDEADCHAR;
2857 TRACE_(key)("-1 -> PostMessageW(%p,%s,%04x,%08lx)\n",
2858 msg->hwnd, SPY_GetMsgName(message, msg->hwnd), wp[0], msg->lParam);
2859 PostMessageW( msg->hwnd, message, wp[0], msg->lParam );
2860 break;
2862 return TRUE;
2866 /***********************************************************************
2867 * DispatchMessageA (USER32.@)
2869 LONG WINAPI DispatchMessageA( const MSG* msg )
2871 WND * wndPtr;
2872 LONG retval;
2873 WNDPROC winproc;
2875 /* Process timer messages */
2876 if ((msg->message == WM_TIMER) || (msg->message == WM_SYSTIMER))
2878 if (msg->lParam) return CallWindowProcA( (WNDPROC)msg->lParam, msg->hwnd,
2879 msg->message, msg->wParam, GetTickCount() );
2882 if (msg->message & 0x80000000)
2883 return handle_internal_message( msg->hwnd, msg->message, msg->wParam, msg->lParam );
2885 if (!(wndPtr = WIN_GetPtr( msg->hwnd )))
2887 if (msg->hwnd) SetLastError( ERROR_INVALID_WINDOW_HANDLE );
2888 return 0;
2890 if (wndPtr == WND_OTHER_PROCESS)
2892 if (IsWindow( msg->hwnd )) SetLastError( ERROR_MESSAGE_SYNC_ONLY );
2893 else SetLastError( ERROR_INVALID_WINDOW_HANDLE );
2894 return 0;
2896 if (wndPtr->tid != GetCurrentThreadId())
2898 SetLastError( ERROR_MESSAGE_SYNC_ONLY );
2899 WIN_ReleasePtr( wndPtr );
2900 return 0;
2902 winproc = wndPtr->winproc;
2903 WIN_ReleasePtr( wndPtr );
2905 SPY_EnterMessage( SPY_DISPATCHMESSAGE, msg->hwnd, msg->message,
2906 msg->wParam, msg->lParam );
2907 retval = CallWindowProcA( winproc, msg->hwnd, msg->message,
2908 msg->wParam, msg->lParam );
2909 SPY_ExitMessage( SPY_RESULT_OK, msg->hwnd, msg->message, retval,
2910 msg->wParam, msg->lParam );
2912 if (msg->message == WM_PAINT)
2914 /* send a WM_NCPAINT and WM_ERASEBKGND if the non-client area is still invalid */
2915 HRGN hrgn = CreateRectRgn( 0, 0, 0, 0 );
2916 GetUpdateRgn( msg->hwnd, hrgn, TRUE );
2917 DeleteObject( hrgn );
2919 return retval;
2923 /***********************************************************************
2924 * DispatchMessageW (USER32.@) Process a message
2926 * Process the message specified in the structure *_msg_.
2928 * If the lpMsg parameter points to a WM_TIMER message and the
2929 * parameter of the WM_TIMER message is not NULL, the lParam parameter
2930 * points to the function that is called instead of the window
2931 * procedure.
2933 * The message must be valid.
2935 * RETURNS
2937 * DispatchMessage() returns the result of the window procedure invoked.
2939 * CONFORMANCE
2941 * ECMA-234, Win32
2944 LONG WINAPI DispatchMessageW( const MSG* msg )
2946 WND * wndPtr;
2947 LONG retval;
2948 WNDPROC winproc;
2950 /* Process timer messages */
2951 if ((msg->message == WM_TIMER) || (msg->message == WM_SYSTIMER))
2953 if (msg->lParam) return CallWindowProcW( (WNDPROC)msg->lParam, msg->hwnd,
2954 msg->message, msg->wParam, GetTickCount() );
2957 if (msg->message & 0x80000000)
2958 return handle_internal_message( msg->hwnd, msg->message, msg->wParam, msg->lParam );
2960 if (!(wndPtr = WIN_GetPtr( msg->hwnd )))
2962 if (msg->hwnd) SetLastError( ERROR_INVALID_WINDOW_HANDLE );
2963 return 0;
2965 if (wndPtr == WND_OTHER_PROCESS)
2967 if (IsWindow( msg->hwnd )) SetLastError( ERROR_MESSAGE_SYNC_ONLY );
2968 else SetLastError( ERROR_INVALID_WINDOW_HANDLE );
2969 return 0;
2971 if (wndPtr->tid != GetCurrentThreadId())
2973 SetLastError( ERROR_MESSAGE_SYNC_ONLY );
2974 WIN_ReleasePtr( wndPtr );
2975 return 0;
2977 winproc = wndPtr->winproc;
2978 WIN_ReleasePtr( wndPtr );
2980 SPY_EnterMessage( SPY_DISPATCHMESSAGE, msg->hwnd, msg->message,
2981 msg->wParam, msg->lParam );
2982 retval = CallWindowProcW( winproc, msg->hwnd, msg->message,
2983 msg->wParam, msg->lParam );
2984 SPY_ExitMessage( SPY_RESULT_OK, msg->hwnd, msg->message, retval,
2985 msg->wParam, msg->lParam );
2987 if (msg->message == WM_PAINT)
2989 /* send a WM_NCPAINT and WM_ERASEBKGND if the non-client area is still invalid */
2990 HRGN hrgn = CreateRectRgn( 0, 0, 0, 0 );
2991 GetUpdateRgn( msg->hwnd, hrgn, TRUE );
2992 DeleteObject( hrgn );
2994 return retval;
2998 /***********************************************************************
2999 * WaitMessage (USER.112) Suspend thread pending messages
3000 * WaitMessage (USER32.@) Suspend thread pending messages
3002 * WaitMessage() suspends a thread until events appear in the thread's
3003 * queue.
3005 BOOL WINAPI WaitMessage(void)
3007 return (MsgWaitForMultipleObjectsEx( 0, NULL, INFINITE, QS_ALLINPUT, 0 ) != WAIT_FAILED);
3011 /***********************************************************************
3012 * MsgWaitForMultipleObjectsEx (USER32.@)
3014 DWORD WINAPI MsgWaitForMultipleObjectsEx( DWORD count, CONST HANDLE *pHandles,
3015 DWORD timeout, DWORD mask, DWORD flags )
3017 HANDLE handles[MAXIMUM_WAIT_OBJECTS];
3018 DWORD i, ret, lock;
3019 MESSAGEQUEUE *msgQueue;
3021 if (count > MAXIMUM_WAIT_OBJECTS-1)
3023 SetLastError( ERROR_INVALID_PARAMETER );
3024 return WAIT_FAILED;
3027 if (!(msgQueue = QUEUE_Current())) return WAIT_FAILED;
3029 /* set the queue mask */
3030 SERVER_START_REQ( set_queue_mask )
3032 req->wake_mask = (flags & MWMO_INPUTAVAILABLE) ? mask : 0;
3033 req->changed_mask = mask;
3034 req->skip_wait = 0;
3035 wine_server_call( req );
3037 SERVER_END_REQ;
3039 /* Add the thread event to the handle list */
3040 for (i = 0; i < count; i++) handles[i] = pHandles[i];
3041 handles[count] = msgQueue->server_queue;
3043 ReleaseThunkLock( &lock );
3044 if (USER_Driver.pMsgWaitForMultipleObjectsEx)
3046 ret = USER_Driver.pMsgWaitForMultipleObjectsEx( count+1, handles, timeout, mask, flags );
3047 if (ret == count+1) ret = count; /* pretend the msg queue is ready */
3049 else
3050 ret = WaitForMultipleObjectsEx( count+1, handles, flags & MWMO_WAITALL,
3051 timeout, flags & MWMO_ALERTABLE );
3052 if (lock) RestoreThunkLock( lock );
3053 return ret;
3057 /***********************************************************************
3058 * MsgWaitForMultipleObjects (USER32.@)
3060 DWORD WINAPI MsgWaitForMultipleObjects( DWORD count, CONST HANDLE *handles,
3061 BOOL wait_all, DWORD timeout, DWORD mask )
3063 return MsgWaitForMultipleObjectsEx( count, handles, timeout, mask,
3064 wait_all ? MWMO_WAITALL : 0 );
3068 /***********************************************************************
3069 * WaitForInputIdle (USER32.@)
3071 DWORD WINAPI WaitForInputIdle( HANDLE hProcess, DWORD dwTimeOut )
3073 DWORD start_time, elapsed, ret;
3074 HANDLE idle_event = (HANDLE)-1;
3076 SERVER_START_REQ( wait_input_idle )
3078 req->handle = hProcess;
3079 req->timeout = dwTimeOut;
3080 if (!(ret = wine_server_call_err( req ))) idle_event = reply->event;
3082 SERVER_END_REQ;
3083 if (ret) return WAIT_FAILED; /* error */
3084 if (!idle_event) return 0; /* no event to wait on */
3086 start_time = GetTickCount();
3087 elapsed = 0;
3089 TRACE("waiting for %p\n", idle_event );
3092 ret = MsgWaitForMultipleObjects ( 1, &idle_event, FALSE, dwTimeOut - elapsed, QS_SENDMESSAGE );
3093 switch (ret)
3095 case WAIT_OBJECT_0+1:
3096 process_sent_messages();
3097 break;
3098 case WAIT_TIMEOUT:
3099 case WAIT_FAILED:
3100 TRACE("timeout or error\n");
3101 return ret;
3102 default:
3103 TRACE("finished\n");
3104 return 0;
3106 if (dwTimeOut != INFINITE)
3108 elapsed = GetTickCount() - start_time;
3109 if (elapsed > dwTimeOut)
3110 break;
3113 while (1);
3115 return WAIT_TIMEOUT;
3119 /***********************************************************************
3120 * UserYield (USER.332)
3122 void WINAPI UserYield16(void)
3124 DWORD count;
3126 /* Handle sent messages */
3127 process_sent_messages();
3129 /* Yield */
3130 ReleaseThunkLock(&count);
3132 if (count)
3134 RestoreThunkLock(count);
3135 /* Handle sent messages again */
3136 process_sent_messages();
3141 /***********************************************************************
3142 * RegisterWindowMessage (USER.118)
3143 * RegisterWindowMessageA (USER32.@)
3145 WORD WINAPI RegisterWindowMessageA( LPCSTR str )
3147 TRACE("%s\n", str );
3148 return GlobalAddAtomA( str );
3152 /***********************************************************************
3153 * RegisterWindowMessageW (USER32.@)
3155 WORD WINAPI RegisterWindowMessageW( LPCWSTR str )
3157 TRACE("%p\n", str );
3158 return GlobalAddAtomW( str );
3162 /***********************************************************************
3163 * BroadcastSystemMessage (USER32.@)
3164 * BroadcastSystemMessageA (USER32.@)
3166 LONG WINAPI BroadcastSystemMessageA( DWORD flags, LPDWORD recipients, UINT msg, WPARAM wp, LPARAM lp )
3168 if ((*recipients & BSM_APPLICATIONS) || (*recipients == BSM_ALLCOMPONENTS))
3170 FIXME( "(%08lx,%08lx,%08x,%08x,%08lx): semi-stub!\n", flags, *recipients, msg, wp, lp );
3171 PostMessageA( HWND_BROADCAST, msg, wp, lp );
3172 return 1;
3174 else
3176 FIXME( "(%08lx,%08lx,%08x,%08x,%08lx): stub!\n", flags, *recipients, msg, wp, lp);
3177 return -1;
3182 /***********************************************************************
3183 * BroadcastSystemMessageW (USER32.@)
3185 LONG WINAPI BroadcastSystemMessageW( DWORD flags, LPDWORD recipients, UINT msg, WPARAM wp, LPARAM lp )
3187 if ((*recipients & BSM_APPLICATIONS) || (*recipients == BSM_ALLCOMPONENTS))
3189 FIXME( "(%08lx,%08lx,%08x,%08x,%08lx): semi-stub!\n", flags, *recipients, msg, wp, lp );
3190 PostMessageW( HWND_BROADCAST, msg, wp, lp );
3191 return 1;
3193 else
3195 FIXME( "(%08lx,%08lx,%08x,%08x,%08lx): stub!\n", flags, *recipients, msg, wp, lp );
3196 return -1;
3201 /***********************************************************************
3202 * SetMessageQueue (USER32.@)
3204 BOOL WINAPI SetMessageQueue( INT size )
3206 /* now obsolete the message queue will be expanded dynamically as necessary */
3207 return TRUE;
3211 /***********************************************************************
3212 * MessageBeep (USER32.@)
3214 BOOL WINAPI MessageBeep( UINT i )
3216 BOOL active = TRUE;
3217 SystemParametersInfoA( SPI_GETBEEP, 0, &active, FALSE );
3218 if (active && USER_Driver.pBeep) USER_Driver.pBeep();
3219 return TRUE;
3223 /***********************************************************************
3224 * SetTimer (USER32.@)
3226 UINT_PTR WINAPI SetTimer( HWND hwnd, UINT_PTR id, UINT timeout, TIMERPROC proc )
3228 UINT_PTR ret;
3229 WNDPROC winproc = 0;
3231 if (proc) winproc = WINPROC_AllocProc( (WNDPROC)proc, WIN_PROC_32A );
3233 SERVER_START_REQ( set_win_timer )
3235 req->win = hwnd;
3236 req->msg = WM_TIMER;
3237 req->id = id;
3238 req->rate = max( timeout, SYS_TIMER_RATE );
3239 req->lparam = (unsigned int)winproc;
3240 if (!wine_server_call_err( req ))
3242 ret = reply->id;
3243 if (!ret) ret = TRUE;
3245 else ret = 0;
3247 SERVER_END_REQ;
3249 TRACE("Added %p %x %p timeout %d\n", hwnd, id, winproc, timeout );
3250 return ret;
3254 /***********************************************************************
3255 * SetSystemTimer (USER32.@)
3257 UINT_PTR WINAPI SetSystemTimer( HWND hwnd, UINT_PTR id, UINT timeout, TIMERPROC proc )
3259 UINT_PTR ret;
3260 WNDPROC winproc = 0;
3262 if (proc) winproc = WINPROC_AllocProc( (WNDPROC)proc, WIN_PROC_32A );
3264 SERVER_START_REQ( set_win_timer )
3266 req->win = hwnd;
3267 req->msg = WM_SYSTIMER;
3268 req->id = id;
3269 req->rate = max( timeout, SYS_TIMER_RATE );
3270 req->lparam = (unsigned int)winproc;
3271 if (!wine_server_call_err( req ))
3273 ret = reply->id;
3274 if (!ret) ret = TRUE;
3276 else ret = 0;
3278 SERVER_END_REQ;
3280 TRACE("Added %p %x %p timeout %d\n", hwnd, id, winproc, timeout );
3281 return ret;
3285 /***********************************************************************
3286 * KillTimer (USER32.@)
3288 BOOL WINAPI KillTimer( HWND hwnd, UINT_PTR id )
3290 BOOL ret;
3292 TRACE("%p %d\n", hwnd, id );
3294 SERVER_START_REQ( kill_win_timer )
3296 req->win = hwnd;
3297 req->msg = WM_TIMER;
3298 req->id = id;
3299 ret = !wine_server_call_err( req );
3301 SERVER_END_REQ;
3302 return ret;
3306 /***********************************************************************
3307 * KillSystemTimer (USER32.@)
3309 BOOL WINAPI KillSystemTimer( HWND hwnd, UINT_PTR id )
3311 BOOL ret;
3313 TRACE("%p %d\n", hwnd, id );
3315 SERVER_START_REQ( kill_win_timer )
3317 req->win = hwnd;
3318 req->msg = WM_SYSTIMER;
3319 req->id = id;
3320 ret = !wine_server_call_err( req );
3322 SERVER_END_REQ;
3323 return ret;
3327 /**********************************************************************
3328 * AttachThreadInput (USER32.@)
3330 * Attaches the input processing mechanism of one thread to that of
3331 * another thread.
3333 BOOL WINAPI AttachThreadInput( DWORD from, DWORD to, BOOL attach )
3335 BOOL ret;
3337 SERVER_START_REQ( attach_thread_input )
3339 req->tid_from = from;
3340 req->tid_to = to;
3341 req->attach = attach;
3342 ret = !wine_server_call_err( req );
3344 SERVER_END_REQ;
3345 return ret;
3349 /**********************************************************************
3350 * GetGUIThreadInfo (USER32.@)
3352 BOOL WINAPI GetGUIThreadInfo( DWORD id, GUITHREADINFO *info )
3354 BOOL ret;
3356 SERVER_START_REQ( get_thread_input )
3358 req->tid = id;
3359 if ((ret = !wine_server_call_err( req )))
3361 info->flags = 0;
3362 info->hwndActive = reply->active;
3363 info->hwndFocus = reply->focus;
3364 info->hwndCapture = reply->capture;
3365 info->hwndMenuOwner = reply->menu_owner;
3366 info->hwndMoveSize = reply->move_size;
3367 info->hwndCaret = reply->caret;
3368 info->rcCaret.left = reply->rect.left;
3369 info->rcCaret.top = reply->rect.top;
3370 info->rcCaret.right = reply->rect.right;
3371 info->rcCaret.bottom = reply->rect.bottom;
3372 if (reply->menu_owner) info->flags |= GUI_INMENUMODE;
3373 if (reply->move_size) info->flags |= GUI_INMOVESIZE;
3374 if (reply->caret) info->flags |= GUI_CARETBLINKING;
3377 SERVER_END_REQ;
3378 return ret;
3382 /**********************************************************************
3383 * GetKeyState (USER32.@)
3385 * An application calls the GetKeyState function in response to a
3386 * keyboard-input message. This function retrieves the state of the key
3387 * at the time the input message was generated.
3389 SHORT WINAPI GetKeyState(INT vkey)
3391 SHORT retval = 0;
3393 SERVER_START_REQ( get_key_state )
3395 req->tid = GetCurrentThreadId();
3396 req->key = vkey;
3397 if (!wine_server_call( req )) retval = (signed char)reply->state;
3399 SERVER_END_REQ;
3400 TRACE("key (0x%x) -> %x\n", vkey, retval);
3401 return retval;
3405 /**********************************************************************
3406 * GetKeyboardState (USER32.@)
3408 BOOL WINAPI GetKeyboardState( LPBYTE state )
3410 BOOL ret;
3412 TRACE("(%p)\n", state);
3414 memset( state, 0, 256 );
3415 SERVER_START_REQ( get_key_state )
3417 req->tid = GetCurrentThreadId();
3418 req->key = -1;
3419 wine_server_set_reply( req, state, 256 );
3420 ret = !wine_server_call_err( req );
3422 SERVER_END_REQ;
3423 return ret;
3427 /**********************************************************************
3428 * SetKeyboardState (USER32.@)
3430 BOOL WINAPI SetKeyboardState( LPBYTE state )
3432 BOOL ret;
3434 TRACE("(%p)\n", state);
3436 SERVER_START_REQ( set_key_state )
3438 req->tid = GetCurrentThreadId();
3439 wine_server_add_data( req, state, 256 );
3440 ret = !wine_server_call_err( req );
3442 SERVER_END_REQ;
3443 return ret;
3446 /******************************************************************
3447 * IsHungAppWindow (USER32.@)
3450 BOOL WINAPI IsHungAppWindow( HWND hWnd )
3452 DWORD dwResult;
3453 return !SendMessageTimeoutA(hWnd, WM_NULL, 0, 0, SMTO_ABORTIFHUNG, 5000, &dwResult);
3456 /******************************************************************
3457 * GetLastInputInfo (USER32.@)
3459 BOOL WINAPI GetLastInputInfo(PLASTINPUTINFO plii)
3461 FIXME("%p\n", plii);
3462 return FALSE;