user32: Move back to using WC<->MB in order to specify an alternative codepage.
[wine/wine-gecko.git] / dlls / user32 / message.c
blob24588ac1a89f7a7404367e8c9a7d225337823606
1 /*
2 * Window messaging support
4 * Copyright 2001 Alexandre Julliard
5 * Copyright 2008 Maarten Lankhorst
7 * This library is free software; you can redistribute it and/or
8 * modify it under the terms of the GNU Lesser General Public
9 * License as published by the Free Software Foundation; either
10 * version 2.1 of the License, or (at your option) any later version.
12 * This library is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
15 * Lesser General Public License for more details.
17 * You should have received a copy of the GNU Lesser General Public
18 * License along with this library; if not, write to the Free Software
19 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
22 #include "config.h"
23 #include "wine/port.h"
25 #include <assert.h>
26 #include <stdarg.h>
28 #define NONAMELESSUNION
29 #define NONAMELESSSTRUCT
30 #include "ntstatus.h"
31 #define WIN32_NO_STATUS
32 #include "windef.h"
33 #include "winbase.h"
34 #include "wingdi.h"
35 #include "winuser.h"
36 #include "winerror.h"
37 #include "winnls.h"
38 #include "dbt.h"
39 #include "dde.h"
40 #include "imm.h"
41 #include "ddk/imm.h"
42 #include "wine/unicode.h"
43 #include "wine/server.h"
44 #include "user_private.h"
45 #include "win.h"
46 #include "controls.h"
47 #include "wine/debug.h"
48 #include "wine/exception.h"
50 WINE_DEFAULT_DEBUG_CHANNEL(msg);
51 WINE_DECLARE_DEBUG_CHANNEL(relay);
52 WINE_DECLARE_DEBUG_CHANNEL(key);
54 #define WM_NCMOUSEFIRST WM_NCMOUSEMOVE
55 #define WM_NCMOUSELAST (WM_NCMOUSEFIRST+(WM_MOUSELAST-WM_MOUSEFIRST))
57 #define MAX_PACK_COUNT 4
59 /* the various structures that can be sent in messages, in platform-independent layout */
60 struct packed_CREATESTRUCTW
62 ULONGLONG lpCreateParams;
63 ULONGLONG hInstance;
64 user_handle_t hMenu;
65 DWORD __pad1;
66 user_handle_t hwndParent;
67 DWORD __pad2;
68 INT cy;
69 INT cx;
70 INT y;
71 INT x;
72 LONG style;
73 ULONGLONG lpszName;
74 ULONGLONG lpszClass;
75 DWORD dwExStyle;
76 DWORD __pad3;
79 struct packed_DRAWITEMSTRUCT
81 UINT CtlType;
82 UINT CtlID;
83 UINT itemID;
84 UINT itemAction;
85 UINT itemState;
86 user_handle_t hwndItem;
87 DWORD __pad1;
88 user_handle_t hDC;
89 DWORD __pad2;
90 RECT rcItem;
91 ULONGLONG itemData;
94 struct packed_MEASUREITEMSTRUCT
96 UINT CtlType;
97 UINT CtlID;
98 UINT itemID;
99 UINT itemWidth;
100 UINT itemHeight;
101 ULONGLONG itemData;
104 struct packed_DELETEITEMSTRUCT
106 UINT CtlType;
107 UINT CtlID;
108 UINT itemID;
109 user_handle_t hwndItem;
110 DWORD __pad;
111 ULONGLONG itemData;
114 struct packed_COMPAREITEMSTRUCT
116 UINT CtlType;
117 UINT CtlID;
118 user_handle_t hwndItem;
119 DWORD __pad1;
120 UINT itemID1;
121 ULONGLONG itemData1;
122 UINT itemID2;
123 ULONGLONG itemData2;
124 DWORD dwLocaleId;
125 DWORD __pad2;
128 struct packed_WINDOWPOS
130 user_handle_t hwnd;
131 DWORD __pad1;
132 user_handle_t hwndInsertAfter;
133 DWORD __pad2;
134 INT x;
135 INT y;
136 INT cx;
137 INT cy;
138 UINT flags;
139 DWORD __pad3;
142 struct packed_COPYDATASTRUCT
144 ULONGLONG dwData;
145 DWORD cbData;
146 ULONGLONG lpData;
149 struct packed_HELPINFO
151 UINT cbSize;
152 INT iContextType;
153 INT iCtrlId;
154 user_handle_t hItemHandle;
155 DWORD __pad;
156 ULONGLONG dwContextId;
157 POINT MousePos;
160 struct packed_NCCALCSIZE_PARAMS
162 RECT rgrc[3];
163 ULONGLONG __pad1;
164 user_handle_t hwnd;
165 DWORD __pad2;
166 user_handle_t hwndInsertAfter;
167 DWORD __pad3;
168 INT x;
169 INT y;
170 INT cx;
171 INT cy;
172 UINT flags;
173 DWORD __pad4;
176 struct packed_MSG
178 user_handle_t hwnd;
179 DWORD __pad1;
180 UINT message;
181 ULONGLONG wParam;
182 ULONGLONG lParam;
183 DWORD time;
184 POINT pt;
185 DWORD __pad2;
188 struct packed_MDINEXTMENU
190 user_handle_t hmenuIn;
191 DWORD __pad1;
192 user_handle_t hmenuNext;
193 DWORD __pad2;
194 user_handle_t hwndNext;
195 DWORD __pad3;
198 struct packed_MDICREATESTRUCTW
200 ULONGLONG szClass;
201 ULONGLONG szTitle;
202 ULONGLONG hOwner;
203 INT x;
204 INT y;
205 INT cx;
206 INT cy;
207 DWORD style;
208 ULONGLONG lParam;
211 struct packed_hook_extra_info
213 user_handle_t handle;
214 DWORD __pad;
215 ULONGLONG lparam;
218 /* the structures are unpacked on top of the packed ones, so make sure they fit */
219 C_ASSERT( sizeof(struct packed_CREATESTRUCTW) >= sizeof(CREATESTRUCTW) );
220 C_ASSERT( sizeof(struct packed_DRAWITEMSTRUCT) >= sizeof(DRAWITEMSTRUCT) );
221 C_ASSERT( sizeof(struct packed_MEASUREITEMSTRUCT) >= sizeof(MEASUREITEMSTRUCT) );
222 C_ASSERT( sizeof(struct packed_DELETEITEMSTRUCT) >= sizeof(DELETEITEMSTRUCT) );
223 C_ASSERT( sizeof(struct packed_COMPAREITEMSTRUCT) >= sizeof(COMPAREITEMSTRUCT) );
224 C_ASSERT( sizeof(struct packed_WINDOWPOS) >= sizeof(WINDOWPOS) );
225 C_ASSERT( sizeof(struct packed_COPYDATASTRUCT) >= sizeof(COPYDATASTRUCT) );
226 C_ASSERT( sizeof(struct packed_HELPINFO) >= sizeof(HELPINFO) );
227 C_ASSERT( sizeof(struct packed_NCCALCSIZE_PARAMS) >= sizeof(NCCALCSIZE_PARAMS) + sizeof(WINDOWPOS) );
228 C_ASSERT( sizeof(struct packed_MSG) >= sizeof(MSG) );
229 C_ASSERT( sizeof(struct packed_MDINEXTMENU) >= sizeof(MDINEXTMENU) );
230 C_ASSERT( sizeof(struct packed_MDICREATESTRUCTW) >= sizeof(MDICREATESTRUCTW) );
231 C_ASSERT( sizeof(struct packed_hook_extra_info) >= sizeof(struct hook_extra_info) );
233 union packed_structs
235 struct packed_CREATESTRUCTW cs;
236 struct packed_DRAWITEMSTRUCT dis;
237 struct packed_MEASUREITEMSTRUCT mis;
238 struct packed_DELETEITEMSTRUCT dls;
239 struct packed_COMPAREITEMSTRUCT cis;
240 struct packed_WINDOWPOS wp;
241 struct packed_COPYDATASTRUCT cds;
242 struct packed_HELPINFO hi;
243 struct packed_NCCALCSIZE_PARAMS ncp;
244 struct packed_MSG msg;
245 struct packed_MDINEXTMENU mnm;
246 struct packed_MDICREATESTRUCTW mcs;
247 struct packed_hook_extra_info hook;
250 /* description of the data fields that need to be packed along with a sent message */
251 struct packed_message
253 union packed_structs ps;
254 int count;
255 const void *data[MAX_PACK_COUNT];
256 size_t size[MAX_PACK_COUNT];
259 /* info about the message currently being received by the current thread */
260 struct received_message_info
262 enum message_type type;
263 MSG msg;
264 UINT flags; /* InSendMessageEx return flags */
267 /* structure to group all parameters for sent messages of the various kinds */
268 struct send_message_info
270 enum message_type type;
271 DWORD dest_tid;
272 HWND hwnd;
273 UINT msg;
274 WPARAM wparam;
275 LPARAM lparam;
276 UINT flags; /* flags for SendMessageTimeout */
277 UINT timeout; /* timeout for SendMessageTimeout */
278 SENDASYNCPROC callback; /* callback function for SendMessageCallback */
279 ULONG_PTR data; /* callback data */
280 enum wm_char_mapping wm_char;
284 /* Message class descriptor */
285 static const WCHAR messageW[] = {'M','e','s','s','a','g','e',0};
287 const struct builtin_class_descr MESSAGE_builtin_class =
289 messageW, /* name */
290 0, /* style */
291 WINPROC_MESSAGE, /* proc */
292 0, /* extra */
293 IDC_ARROW, /* cursor */
294 0 /* brush */
299 /* flag for messages that contain pointers */
300 /* 32 messages per entry, messages 0..31 map to bits 0..31 */
302 #define SET(msg) (1 << ((msg) & 31))
304 static const unsigned int message_pointer_flags[] =
306 /* 0x00 - 0x1f */
307 SET(WM_CREATE) | SET(WM_SETTEXT) | SET(WM_GETTEXT) |
308 SET(WM_WININICHANGE) | SET(WM_DEVMODECHANGE),
309 /* 0x20 - 0x3f */
310 SET(WM_GETMINMAXINFO) | SET(WM_DRAWITEM) | SET(WM_MEASUREITEM) | SET(WM_DELETEITEM) |
311 SET(WM_COMPAREITEM),
312 /* 0x40 - 0x5f */
313 SET(WM_WINDOWPOSCHANGING) | SET(WM_WINDOWPOSCHANGED) | SET(WM_COPYDATA) |
314 SET(WM_NOTIFY) | SET(WM_HELP),
315 /* 0x60 - 0x7f */
316 SET(WM_STYLECHANGING) | SET(WM_STYLECHANGED),
317 /* 0x80 - 0x9f */
318 SET(WM_NCCREATE) | SET(WM_NCCALCSIZE) | SET(WM_GETDLGCODE),
319 /* 0xa0 - 0xbf */
320 SET(EM_GETSEL) | SET(EM_GETRECT) | SET(EM_SETRECT) | SET(EM_SETRECTNP),
321 /* 0xc0 - 0xdf */
322 SET(EM_REPLACESEL) | SET(EM_GETLINE) | SET(EM_SETTABSTOPS),
323 /* 0xe0 - 0xff */
324 SET(SBM_GETRANGE) | SET(SBM_SETSCROLLINFO) | SET(SBM_GETSCROLLINFO) | SET(SBM_GETSCROLLBARINFO),
325 /* 0x100 - 0x11f */
327 /* 0x120 - 0x13f */
329 /* 0x140 - 0x15f */
330 SET(CB_GETEDITSEL) | SET(CB_ADDSTRING) | SET(CB_DIR) | SET(CB_GETLBTEXT) |
331 SET(CB_INSERTSTRING) | SET(CB_FINDSTRING) | SET(CB_SELECTSTRING) |
332 SET(CB_GETDROPPEDCONTROLRECT) | SET(CB_FINDSTRINGEXACT),
333 /* 0x160 - 0x17f */
335 /* 0x180 - 0x19f */
336 SET(LB_ADDSTRING) | SET(LB_INSERTSTRING) | SET(LB_GETTEXT) | SET(LB_SELECTSTRING) |
337 SET(LB_DIR) | SET(LB_FINDSTRING) |
338 SET(LB_GETSELITEMS) | SET(LB_SETTABSTOPS) | SET(LB_ADDFILE) | SET(LB_GETITEMRECT),
339 /* 0x1a0 - 0x1bf */
340 SET(LB_FINDSTRINGEXACT),
341 /* 0x1c0 - 0x1df */
343 /* 0x1e0 - 0x1ff */
345 /* 0x200 - 0x21f */
346 SET(WM_NEXTMENU) | SET(WM_SIZING) | SET(WM_MOVING) | SET(WM_DEVICECHANGE),
347 /* 0x220 - 0x23f */
348 SET(WM_MDICREATE) | SET(WM_MDIGETACTIVE) | SET(WM_DROPOBJECT) |
349 SET(WM_QUERYDROPOBJECT) | SET(WM_DRAGLOOP) | SET(WM_DRAGSELECT) | SET(WM_DRAGMOVE),
350 /* 0x240 - 0x25f */
352 /* 0x260 - 0x27f */
354 /* 0x280 - 0x29f */
356 /* 0x2a0 - 0x2bf */
358 /* 0x2c0 - 0x2df */
360 /* 0x2e0 - 0x2ff */
362 /* 0x300 - 0x31f */
363 SET(WM_ASKCBFORMATNAME)
366 /* flags for messages that contain Unicode strings */
367 static const unsigned int message_unicode_flags[] =
369 /* 0x00 - 0x1f */
370 SET(WM_CREATE) | SET(WM_SETTEXT) | SET(WM_GETTEXT) | SET(WM_GETTEXTLENGTH) |
371 SET(WM_WININICHANGE) | SET(WM_DEVMODECHANGE),
372 /* 0x20 - 0x3f */
373 SET(WM_CHARTOITEM),
374 /* 0x40 - 0x5f */
376 /* 0x60 - 0x7f */
378 /* 0x80 - 0x9f */
379 SET(WM_NCCREATE),
380 /* 0xa0 - 0xbf */
382 /* 0xc0 - 0xdf */
383 SET(EM_REPLACESEL) | SET(EM_GETLINE) | SET(EM_SETPASSWORDCHAR),
384 /* 0xe0 - 0xff */
386 /* 0x100 - 0x11f */
387 SET(WM_CHAR) | SET(WM_DEADCHAR) | SET(WM_SYSCHAR) | SET(WM_SYSDEADCHAR),
388 /* 0x120 - 0x13f */
389 SET(WM_MENUCHAR),
390 /* 0x140 - 0x15f */
391 SET(CB_ADDSTRING) | SET(CB_DIR) | SET(CB_GETLBTEXT) | SET(CB_GETLBTEXTLEN) |
392 SET(CB_INSERTSTRING) | SET(CB_FINDSTRING) | SET(CB_SELECTSTRING) | SET(CB_FINDSTRINGEXACT),
393 /* 0x160 - 0x17f */
395 /* 0x180 - 0x19f */
396 SET(LB_ADDSTRING) | SET(LB_INSERTSTRING) | SET(LB_GETTEXT) | SET(LB_GETTEXTLEN) |
397 SET(LB_SELECTSTRING) | SET(LB_DIR) | SET(LB_FINDSTRING) | SET(LB_ADDFILE),
398 /* 0x1a0 - 0x1bf */
399 SET(LB_FINDSTRINGEXACT),
400 /* 0x1c0 - 0x1df */
402 /* 0x1e0 - 0x1ff */
404 /* 0x200 - 0x21f */
406 /* 0x220 - 0x23f */
407 SET(WM_MDICREATE),
408 /* 0x240 - 0x25f */
410 /* 0x260 - 0x27f */
412 /* 0x280 - 0x29f */
413 SET(WM_IME_CHAR),
414 /* 0x2a0 - 0x2bf */
416 /* 0x2c0 - 0x2df */
418 /* 0x2e0 - 0x2ff */
420 /* 0x300 - 0x31f */
421 SET(WM_PAINTCLIPBOARD) | SET(WM_SIZECLIPBOARD) | SET(WM_ASKCBFORMATNAME)
424 /* check whether a given message type includes pointers */
425 static inline int is_pointer_message( UINT message )
427 if (message >= 8*sizeof(message_pointer_flags)) return FALSE;
428 return (message_pointer_flags[message / 32] & SET(message)) != 0;
431 /* check whether a given message type contains Unicode (or ASCII) chars */
432 static inline int is_unicode_message( UINT message )
434 if (message >= 8*sizeof(message_unicode_flags)) return FALSE;
435 return (message_unicode_flags[message / 32] & SET(message)) != 0;
438 #undef SET
440 /* add a data field to a packed message */
441 static inline void push_data( struct packed_message *data, const void *ptr, size_t size )
443 data->data[data->count] = ptr;
444 data->size[data->count] = size;
445 data->count++;
448 /* add a string to a packed message */
449 static inline void push_string( struct packed_message *data, LPCWSTR str )
451 push_data( data, str, (strlenW(str) + 1) * sizeof(WCHAR) );
454 /* make sure that the buffer contains a valid null-terminated Unicode string */
455 static inline BOOL check_string( LPCWSTR str, size_t size )
457 for (size /= sizeof(WCHAR); size; size--, str++)
458 if (!*str) return TRUE;
459 return FALSE;
462 /* pack a pointer into a 32/64 portable format */
463 static inline ULONGLONG pack_ptr( const void *ptr )
465 return (ULONG_PTR)ptr;
468 /* unpack a potentially 64-bit pointer, returning 0 when truncated */
469 static inline void *unpack_ptr( ULONGLONG ptr64 )
471 if ((ULONG_PTR)ptr64 != ptr64) return 0;
472 return (void *)(ULONG_PTR)ptr64;
475 /* make sure that there is space for 'size' bytes in buffer, growing it if needed */
476 static inline void *get_buffer_space( void **buffer, size_t size )
478 void *ret;
480 if (*buffer)
482 if (!(ret = HeapReAlloc( GetProcessHeap(), 0, *buffer, size )))
483 HeapFree( GetProcessHeap(), 0, *buffer );
485 else ret = HeapAlloc( GetProcessHeap(), 0, size );
487 *buffer = ret;
488 return ret;
491 /* check whether a combobox expects strings or ids in CB_ADDSTRING/CB_INSERTSTRING */
492 static inline BOOL combobox_has_strings( HWND hwnd )
494 DWORD style = GetWindowLongA( hwnd, GWL_STYLE );
495 return (!(style & (CBS_OWNERDRAWFIXED | CBS_OWNERDRAWVARIABLE)) || (style & CBS_HASSTRINGS));
498 /* check whether a listbox expects strings or ids in LB_ADDSTRING/LB_INSERTSTRING */
499 static inline BOOL listbox_has_strings( HWND hwnd )
501 DWORD style = GetWindowLongA( hwnd, GWL_STYLE );
502 return (!(style & (LBS_OWNERDRAWFIXED | LBS_OWNERDRAWVARIABLE)) || (style & LBS_HASSTRINGS));
505 /* check whether message is in the range of keyboard messages */
506 static inline BOOL is_keyboard_message( UINT message )
508 return (message >= WM_KEYFIRST && message <= WM_KEYLAST);
511 /* check whether message is in the range of mouse messages */
512 static inline BOOL is_mouse_message( UINT message )
514 return ((message >= WM_NCMOUSEFIRST && message <= WM_NCMOUSELAST) ||
515 (message >= WM_MOUSEFIRST && message <= WM_MOUSELAST));
518 /* check whether message matches the specified hwnd filter */
519 static inline BOOL check_hwnd_filter( const MSG *msg, HWND hwnd_filter )
521 if (!hwnd_filter || hwnd_filter == GetDesktopWindow()) return TRUE;
522 return (msg->hwnd == hwnd_filter || IsChild( hwnd_filter, msg->hwnd ));
525 /* check for pending WM_CHAR message with DBCS trailing byte */
526 static inline BOOL get_pending_wmchar( MSG *msg, UINT first, UINT last, BOOL remove )
528 struct wm_char_mapping_data *data = get_user_thread_info()->wmchar_data;
530 if (!data || !data->get_msg.message) return FALSE;
531 if ((first || last) && (first > WM_CHAR || last < WM_CHAR)) return FALSE;
532 if (!msg) return FALSE;
533 *msg = data->get_msg;
534 if (remove) data->get_msg.message = 0;
535 return TRUE;
539 /***********************************************************************
540 * MessageWndProc
542 * Window procedure for "Message" windows (HWND_MESSAGE parent).
544 LRESULT WINAPI MessageWndProc( HWND hwnd, UINT message, WPARAM wParam, LPARAM lParam )
546 if (message == WM_NCCREATE) return TRUE;
547 return 0; /* all other messages are ignored */
551 /***********************************************************************
552 * broadcast_message_callback
554 * Helper callback for broadcasting messages.
556 static BOOL CALLBACK broadcast_message_callback( HWND hwnd, LPARAM lparam )
558 struct send_message_info *info = (struct send_message_info *)lparam;
559 if (!(GetWindowLongW( hwnd, GWL_STYLE ) & (WS_POPUP|WS_CAPTION))) return TRUE;
560 switch(info->type)
562 case MSG_UNICODE:
563 SendMessageTimeoutW( hwnd, info->msg, info->wparam, info->lparam,
564 info->flags, info->timeout, NULL );
565 break;
566 case MSG_ASCII:
567 SendMessageTimeoutA( hwnd, info->msg, info->wparam, info->lparam,
568 info->flags, info->timeout, NULL );
569 break;
570 case MSG_NOTIFY:
571 SendNotifyMessageW( hwnd, info->msg, info->wparam, info->lparam );
572 break;
573 case MSG_CALLBACK:
574 SendMessageCallbackW( hwnd, info->msg, info->wparam, info->lparam,
575 info->callback, info->data );
576 break;
577 case MSG_POSTED:
578 PostMessageW( hwnd, info->msg, info->wparam, info->lparam );
579 break;
580 default:
581 ERR( "bad type %d\n", info->type );
582 break;
584 return TRUE;
587 DWORD get_input_codepage( void )
589 return CP_ACP;
592 /***********************************************************************
593 * map_wparam_AtoW
595 * Convert the wparam of an ASCII message to Unicode.
597 BOOL map_wparam_AtoW( UINT message, WPARAM *wparam, enum wm_char_mapping mapping )
599 char ch[2];
600 WCHAR wch[2];
601 DWORD cp = get_input_codepage();
603 wch[0] = wch[1] = 0;
604 switch(message)
606 case WM_CHAR:
607 /* WM_CHAR is magic: a DBCS char can be sent/posted as two consecutive WM_CHAR
608 * messages, in which case the first char is stored, and the conversion
609 * to Unicode only takes place once the second char is sent/posted.
611 if (mapping != WMCHAR_MAP_NOMAPPING)
613 struct wm_char_mapping_data *data = get_user_thread_info()->wmchar_data;
614 BYTE low = LOBYTE(*wparam);
616 if (HIBYTE(*wparam))
618 ch[0] = low;
619 ch[1] = HIBYTE(*wparam);
620 MultiByteToWideChar( cp, 0, ch, 2, wch, 2 );
621 TRACE( "map %02x,%02x -> %04x mapping %u\n", (BYTE)ch[0], (BYTE)ch[1], wch[0], mapping );
622 if (data) data->lead_byte[mapping] = 0;
624 else if (data && data->lead_byte[mapping])
626 ch[0] = data->lead_byte[mapping];
627 ch[1] = low;
628 MultiByteToWideChar( cp, 0, ch, 2, wch, 2 );
629 TRACE( "map stored %02x,%02x -> %04x mapping %u\n", (BYTE)ch[0], (BYTE)ch[1], wch[0], mapping );
630 data->lead_byte[mapping] = 0;
632 else if (!IsDBCSLeadByte( low ))
634 ch[0] = low;
635 MultiByteToWideChar( cp, 0, ch, 1, wch, 2 );
636 TRACE( "map %02x -> %04x\n", (BYTE)ch[0], wch[0] );
637 if (data) data->lead_byte[mapping] = 0;
639 else /* store it and wait for trail byte */
641 if (!data)
643 if (!(data = HeapAlloc( GetProcessHeap(), HEAP_ZERO_MEMORY, sizeof(*data) )))
644 return FALSE;
645 get_user_thread_info()->wmchar_data = data;
647 TRACE( "storing lead byte %02x mapping %u\n", low, mapping );
648 data->lead_byte[mapping] = low;
649 return FALSE;
651 *wparam = MAKEWPARAM(wch[0], wch[1]);
652 break;
654 /* else fall through */
655 case WM_CHARTOITEM:
656 case EM_SETPASSWORDCHAR:
657 case WM_DEADCHAR:
658 case WM_SYSCHAR:
659 case WM_SYSDEADCHAR:
660 case WM_MENUCHAR:
661 ch[0] = LOBYTE(*wparam);
662 ch[1] = HIBYTE(*wparam);
663 MultiByteToWideChar( cp, 0, ch, 2, wch, 2 );
664 *wparam = MAKEWPARAM(wch[0], wch[1]);
665 break;
666 case WM_IME_CHAR:
667 ch[0] = HIBYTE(*wparam);
668 ch[1] = LOBYTE(*wparam);
669 if (ch[0]) MultiByteToWideChar( cp, 0, ch, 2, wch, 2 );
670 else MultiByteToWideChar( cp, 0, ch + 1, 1, wch, 1 );
671 *wparam = MAKEWPARAM(wch[0], HIWORD(*wparam));
672 break;
674 return TRUE;
678 /***********************************************************************
679 * map_wparam_WtoA
681 * Convert the wparam of a Unicode message to ASCII.
683 static void map_wparam_WtoA( MSG *msg, BOOL remove )
685 BYTE ch[4];
686 WCHAR wch[2];
687 DWORD len;
688 DWORD cp = get_input_codepage();
690 switch(msg->message)
692 case WM_CHAR:
693 if (!HIWORD(msg->wParam))
695 wch[0] = LOWORD(msg->wParam);
696 ch[0] = ch[1] = 0;
697 len = WideCharToMultiByte( cp, 0, wch, 1, (LPSTR)ch, 2, NULL, NULL );
698 if (len == 2) /* DBCS char */
700 struct wm_char_mapping_data *data = get_user_thread_info()->wmchar_data;
701 if (!data)
703 if (!(data = HeapAlloc( GetProcessHeap(), HEAP_ZERO_MEMORY, sizeof(*data) ))) return;
704 get_user_thread_info()->wmchar_data = data;
706 if (remove)
708 data->get_msg = *msg;
709 data->get_msg.wParam = ch[1];
711 msg->wParam = ch[0];
712 return;
715 /* else fall through */
716 case WM_CHARTOITEM:
717 case EM_SETPASSWORDCHAR:
718 case WM_DEADCHAR:
719 case WM_SYSCHAR:
720 case WM_SYSDEADCHAR:
721 case WM_MENUCHAR:
722 wch[0] = LOWORD(msg->wParam);
723 wch[1] = HIWORD(msg->wParam);
724 ch[0] = ch[1] = 0;
725 WideCharToMultiByte( cp, 0, wch, 2, (LPSTR)ch, 4, NULL, NULL );
726 msg->wParam = MAKEWPARAM( ch[0] | (ch[1] << 8), 0 );
727 break;
728 case WM_IME_CHAR:
729 wch[0] = LOWORD(msg->wParam);
730 ch[0] = ch[1] = 0;
731 len = WideCharToMultiByte( cp, 0, wch, 1, (LPSTR)ch, 2, NULL, NULL );
732 if (len == 2)
733 msg->wParam = MAKEWPARAM( (ch[0] << 8) | ch[1], HIWORD(msg->wParam) );
734 else
735 msg->wParam = MAKEWPARAM( ch[0], HIWORD(msg->wParam) );
736 break;
741 /***********************************************************************
742 * pack_message
744 * Pack a message for sending to another process.
745 * Return the size of the data we expect in the message reply.
746 * Set data->count to -1 if there is an error.
748 static size_t pack_message( HWND hwnd, UINT message, WPARAM wparam, LPARAM lparam,
749 struct packed_message *data )
751 data->count = 0;
752 switch(message)
754 case WM_NCCREATE:
755 case WM_CREATE:
757 CREATESTRUCTW *cs = (CREATESTRUCTW *)lparam;
758 data->ps.cs.lpCreateParams = pack_ptr( cs->lpCreateParams );
759 data->ps.cs.hInstance = pack_ptr( cs->hInstance );
760 data->ps.cs.hMenu = wine_server_user_handle( cs->hMenu );
761 data->ps.cs.hwndParent = wine_server_user_handle( cs->hwndParent );
762 data->ps.cs.cy = cs->cy;
763 data->ps.cs.cx = cs->cx;
764 data->ps.cs.y = cs->y;
765 data->ps.cs.x = cs->x;
766 data->ps.cs.style = cs->style;
767 data->ps.cs.dwExStyle = cs->dwExStyle;
768 data->ps.cs.lpszName = pack_ptr( cs->lpszName );
769 data->ps.cs.lpszClass = pack_ptr( cs->lpszClass );
770 push_data( data, &data->ps.cs, sizeof(data->ps.cs) );
771 if (!IS_INTRESOURCE(cs->lpszName)) push_string( data, cs->lpszName );
772 if (!IS_INTRESOURCE(cs->lpszClass)) push_string( data, cs->lpszClass );
773 return sizeof(data->ps.cs);
775 case WM_GETTEXT:
776 case WM_ASKCBFORMATNAME:
777 return wparam * sizeof(WCHAR);
778 case WM_WININICHANGE:
779 if (lparam) push_string(data, (LPWSTR)lparam );
780 return 0;
781 case WM_SETTEXT:
782 case WM_DEVMODECHANGE:
783 case CB_DIR:
784 case LB_DIR:
785 case LB_ADDFILE:
786 case EM_REPLACESEL:
787 push_string( data, (LPWSTR)lparam );
788 return 0;
789 case WM_GETMINMAXINFO:
790 push_data( data, (MINMAXINFO *)lparam, sizeof(MINMAXINFO) );
791 return sizeof(MINMAXINFO);
792 case WM_DRAWITEM:
794 DRAWITEMSTRUCT *dis = (DRAWITEMSTRUCT *)lparam;
795 data->ps.dis.CtlType = dis->CtlType;
796 data->ps.dis.CtlID = dis->CtlID;
797 data->ps.dis.itemID = dis->itemID;
798 data->ps.dis.itemAction = dis->itemAction;
799 data->ps.dis.itemState = dis->itemState;
800 data->ps.dis.hwndItem = wine_server_user_handle( dis->hwndItem );
801 data->ps.dis.hDC = wine_server_user_handle( dis->hDC ); /* FIXME */
802 data->ps.dis.rcItem = dis->rcItem;
803 data->ps.dis.itemData = dis->itemData;
804 push_data( data, &data->ps.dis, sizeof(data->ps.dis) );
805 return 0;
807 case WM_MEASUREITEM:
809 MEASUREITEMSTRUCT *mis = (MEASUREITEMSTRUCT *)lparam;
810 data->ps.mis.CtlType = mis->CtlType;
811 data->ps.mis.CtlID = mis->CtlID;
812 data->ps.mis.itemID = mis->itemID;
813 data->ps.mis.itemWidth = mis->itemWidth;
814 data->ps.mis.itemHeight = mis->itemHeight;
815 data->ps.mis.itemData = mis->itemData;
816 push_data( data, &data->ps.mis, sizeof(data->ps.mis) );
817 return sizeof(data->ps.mis);
819 case WM_DELETEITEM:
821 DELETEITEMSTRUCT *dls = (DELETEITEMSTRUCT *)lparam;
822 data->ps.dls.CtlType = dls->CtlType;
823 data->ps.dls.CtlID = dls->CtlID;
824 data->ps.dls.itemID = dls->itemID;
825 data->ps.dls.hwndItem = wine_server_user_handle( dls->hwndItem );
826 data->ps.dls.itemData = dls->itemData;
827 push_data( data, &data->ps.dls, sizeof(data->ps.dls) );
828 return 0;
830 case WM_COMPAREITEM:
832 COMPAREITEMSTRUCT *cis = (COMPAREITEMSTRUCT *)lparam;
833 data->ps.cis.CtlType = cis->CtlType;
834 data->ps.cis.CtlID = cis->CtlID;
835 data->ps.cis.hwndItem = wine_server_user_handle( cis->hwndItem );
836 data->ps.cis.itemID1 = cis->itemID1;
837 data->ps.cis.itemData1 = cis->itemData1;
838 data->ps.cis.itemID2 = cis->itemID2;
839 data->ps.cis.itemData2 = cis->itemData2;
840 data->ps.cis.dwLocaleId = cis->dwLocaleId;
841 push_data( data, &data->ps.cis, sizeof(data->ps.cis) );
842 return 0;
844 case WM_WINE_SETWINDOWPOS:
845 case WM_WINDOWPOSCHANGING:
846 case WM_WINDOWPOSCHANGED:
848 WINDOWPOS *wp = (WINDOWPOS *)lparam;
849 data->ps.wp.hwnd = wine_server_user_handle( wp->hwnd );
850 data->ps.wp.hwndInsertAfter = wine_server_user_handle( wp->hwndInsertAfter );
851 data->ps.wp.x = wp->x;
852 data->ps.wp.y = wp->y;
853 data->ps.wp.cx = wp->cx;
854 data->ps.wp.cy = wp->cy;
855 data->ps.wp.flags = wp->flags;
856 push_data( data, &data->ps.wp, sizeof(data->ps.wp) );
857 return sizeof(data->ps.wp);
859 case WM_COPYDATA:
861 COPYDATASTRUCT *cds = (COPYDATASTRUCT *)lparam;
862 data->ps.cds.cbData = cds->cbData;
863 data->ps.cds.dwData = cds->dwData;
864 data->ps.cds.lpData = pack_ptr( cds->lpData );
865 push_data( data, &data->ps.cds, sizeof(data->ps.cds) );
866 if (cds->lpData) push_data( data, cds->lpData, cds->cbData );
867 return 0;
869 case WM_NOTIFY:
870 /* WM_NOTIFY cannot be sent across processes (MSDN) */
871 data->count = -1;
872 return 0;
873 case WM_HELP:
875 HELPINFO *hi = (HELPINFO *)lparam;
876 data->ps.hi.iContextType = hi->iContextType;
877 data->ps.hi.iCtrlId = hi->iCtrlId;
878 data->ps.hi.hItemHandle = wine_server_user_handle( hi->hItemHandle );
879 data->ps.hi.dwContextId = hi->dwContextId;
880 data->ps.hi.MousePos = hi->MousePos;
881 push_data( data, &data->ps.hi, sizeof(data->ps.hi) );
882 return 0;
884 case WM_STYLECHANGING:
885 case WM_STYLECHANGED:
886 push_data( data, (STYLESTRUCT *)lparam, sizeof(STYLESTRUCT) );
887 return 0;
888 case WM_NCCALCSIZE:
889 if (!wparam)
891 push_data( data, (RECT *)lparam, sizeof(RECT) );
892 return sizeof(RECT);
894 else
896 NCCALCSIZE_PARAMS *ncp = (NCCALCSIZE_PARAMS *)lparam;
897 data->ps.ncp.rgrc[0] = ncp->rgrc[0];
898 data->ps.ncp.rgrc[1] = ncp->rgrc[1];
899 data->ps.ncp.rgrc[2] = ncp->rgrc[2];
900 data->ps.ncp.hwnd = wine_server_user_handle( ncp->lppos->hwnd );
901 data->ps.ncp.hwndInsertAfter = wine_server_user_handle( ncp->lppos->hwndInsertAfter );
902 data->ps.ncp.x = ncp->lppos->x;
903 data->ps.ncp.y = ncp->lppos->y;
904 data->ps.ncp.cx = ncp->lppos->cx;
905 data->ps.ncp.cy = ncp->lppos->cy;
906 data->ps.ncp.flags = ncp->lppos->flags;
907 push_data( data, &data->ps.ncp, sizeof(data->ps.ncp) );
908 return sizeof(data->ps.ncp);
910 case WM_GETDLGCODE:
911 if (lparam)
913 MSG *msg = (MSG *)lparam;
914 data->ps.msg.hwnd = wine_server_user_handle( msg->hwnd );
915 data->ps.msg.message = msg->message;
916 data->ps.msg.wParam = msg->wParam;
917 data->ps.msg.lParam = msg->lParam;
918 data->ps.msg.time = msg->time;
919 data->ps.msg.pt = msg->pt;
920 push_data( data, &data->ps.msg, sizeof(data->ps.msg) );
921 return sizeof(data->ps.msg);
923 return 0;
924 case SBM_SETSCROLLINFO:
925 push_data( data, (SCROLLINFO *)lparam, sizeof(SCROLLINFO) );
926 return 0;
927 case SBM_GETSCROLLINFO:
928 push_data( data, (SCROLLINFO *)lparam, sizeof(SCROLLINFO) );
929 return sizeof(SCROLLINFO);
930 case SBM_GETSCROLLBARINFO:
932 const SCROLLBARINFO *info = (const SCROLLBARINFO *)lparam;
933 size_t size = min( info->cbSize, sizeof(SCROLLBARINFO) );
934 push_data( data, info, size );
935 return size;
937 case EM_GETSEL:
938 case SBM_GETRANGE:
939 case CB_GETEDITSEL:
941 size_t size = 0;
942 if (wparam) size += sizeof(DWORD);
943 if (lparam) size += sizeof(DWORD);
944 return size;
946 case EM_GETRECT:
947 case LB_GETITEMRECT:
948 case CB_GETDROPPEDCONTROLRECT:
949 return sizeof(RECT);
950 case EM_SETRECT:
951 case EM_SETRECTNP:
952 push_data( data, (RECT *)lparam, sizeof(RECT) );
953 return 0;
954 case EM_GETLINE:
956 WORD *pw = (WORD *)lparam;
957 push_data( data, pw, sizeof(*pw) );
958 return *pw * sizeof(WCHAR);
960 case EM_SETTABSTOPS:
961 case LB_SETTABSTOPS:
962 if (wparam) push_data( data, (UINT *)lparam, sizeof(UINT) * wparam );
963 return 0;
964 case CB_ADDSTRING:
965 case CB_INSERTSTRING:
966 case CB_FINDSTRING:
967 case CB_FINDSTRINGEXACT:
968 case CB_SELECTSTRING:
969 if (combobox_has_strings( hwnd )) push_string( data, (LPWSTR)lparam );
970 return 0;
971 case CB_GETLBTEXT:
972 if (!combobox_has_strings( hwnd )) return sizeof(ULONG_PTR);
973 return (SendMessageW( hwnd, CB_GETLBTEXTLEN, wparam, 0 ) + 1) * sizeof(WCHAR);
974 case LB_ADDSTRING:
975 case LB_INSERTSTRING:
976 case LB_FINDSTRING:
977 case LB_FINDSTRINGEXACT:
978 case LB_SELECTSTRING:
979 if (listbox_has_strings( hwnd )) push_string( data, (LPWSTR)lparam );
980 return 0;
981 case LB_GETTEXT:
982 if (!listbox_has_strings( hwnd )) return sizeof(ULONG_PTR);
983 return (SendMessageW( hwnd, LB_GETTEXTLEN, wparam, 0 ) + 1) * sizeof(WCHAR);
984 case LB_GETSELITEMS:
985 return wparam * sizeof(UINT);
986 case WM_NEXTMENU:
988 MDINEXTMENU *mnm = (MDINEXTMENU *)lparam;
989 data->ps.mnm.hmenuIn = wine_server_user_handle( mnm->hmenuIn );
990 data->ps.mnm.hmenuNext = wine_server_user_handle( mnm->hmenuNext );
991 data->ps.mnm.hwndNext = wine_server_user_handle( mnm->hwndNext );
992 push_data( data, &data->ps.mnm, sizeof(data->ps.mnm) );
993 return sizeof(data->ps.mnm);
995 case WM_SIZING:
996 case WM_MOVING:
997 push_data( data, (RECT *)lparam, sizeof(RECT) );
998 return sizeof(RECT);
999 case WM_MDICREATE:
1001 MDICREATESTRUCTW *mcs = (MDICREATESTRUCTW *)lparam;
1002 data->ps.mcs.szClass = pack_ptr( mcs->szClass );
1003 data->ps.mcs.szTitle = pack_ptr( mcs->szTitle );
1004 data->ps.mcs.hOwner = pack_ptr( mcs->hOwner );
1005 data->ps.mcs.x = mcs->x;
1006 data->ps.mcs.y = mcs->y;
1007 data->ps.mcs.cx = mcs->cx;
1008 data->ps.mcs.cy = mcs->cy;
1009 data->ps.mcs.style = mcs->style;
1010 data->ps.mcs.lParam = mcs->lParam;
1011 push_data( data, &data->ps.mcs, sizeof(data->ps.mcs) );
1012 if (!IS_INTRESOURCE(mcs->szClass)) push_string( data, mcs->szClass );
1013 if (!IS_INTRESOURCE(mcs->szTitle)) push_string( data, mcs->szTitle );
1014 return sizeof(data->ps.mcs);
1016 case WM_MDIGETACTIVE:
1017 if (lparam) return sizeof(BOOL);
1018 return 0;
1019 case WM_DEVICECHANGE:
1021 DEV_BROADCAST_HDR *header = (DEV_BROADCAST_HDR *)lparam;
1022 push_data( data, header, header->dbch_size );
1023 return 0;
1025 case WM_WINE_KEYBOARD_LL_HOOK:
1027 struct hook_extra_info *h_extra = (struct hook_extra_info *)lparam;
1028 data->ps.hook.handle = wine_server_user_handle( h_extra->handle );
1029 push_data( data, &data->ps.hook, sizeof(data->ps.hook) );
1030 push_data( data, (LPVOID)h_extra->lparam, sizeof(KBDLLHOOKSTRUCT) );
1031 return 0;
1033 case WM_WINE_MOUSE_LL_HOOK:
1035 struct hook_extra_info *h_extra = (struct hook_extra_info *)lparam;
1036 data->ps.hook.handle = wine_server_user_handle( h_extra->handle );
1037 push_data( data, &data->ps.hook, sizeof(data->ps.hook) );
1038 push_data( data, (LPVOID)h_extra->lparam, sizeof(MSLLHOOKSTRUCT) );
1039 return 0;
1041 case WM_NCPAINT:
1042 if (wparam <= 1) return 0;
1043 FIXME( "WM_NCPAINT hdc packing not supported yet\n" );
1044 data->count = -1;
1045 return 0;
1046 case WM_PAINT:
1047 if (!wparam) return 0;
1048 /* fall through */
1050 /* these contain an HFONT */
1051 case WM_SETFONT:
1052 case WM_GETFONT:
1053 /* these contain an HDC */
1054 case WM_ERASEBKGND:
1055 case WM_ICONERASEBKGND:
1056 case WM_CTLCOLORMSGBOX:
1057 case WM_CTLCOLOREDIT:
1058 case WM_CTLCOLORLISTBOX:
1059 case WM_CTLCOLORBTN:
1060 case WM_CTLCOLORDLG:
1061 case WM_CTLCOLORSCROLLBAR:
1062 case WM_CTLCOLORSTATIC:
1063 case WM_PRINT:
1064 case WM_PRINTCLIENT:
1065 /* these contain an HGLOBAL */
1066 case WM_PAINTCLIPBOARD:
1067 case WM_SIZECLIPBOARD:
1068 /* these contain HICON */
1069 case WM_GETICON:
1070 case WM_SETICON:
1071 case WM_QUERYDRAGICON:
1072 case WM_QUERYPARKICON:
1073 /* these contain pointers */
1074 case WM_DROPOBJECT:
1075 case WM_QUERYDROPOBJECT:
1076 case WM_DRAGLOOP:
1077 case WM_DRAGSELECT:
1078 case WM_DRAGMOVE:
1079 FIXME( "msg %x (%s) not supported yet\n", message, SPY_GetMsgName(message, hwnd) );
1080 data->count = -1;
1081 return 0;
1083 return 0;
1087 /***********************************************************************
1088 * unpack_message
1090 * Unpack a message received from another process.
1092 static BOOL unpack_message( HWND hwnd, UINT message, WPARAM *wparam, LPARAM *lparam,
1093 void **buffer, size_t size )
1095 size_t minsize = 0;
1096 union packed_structs *ps = *buffer;
1098 switch(message)
1100 case WM_NCCREATE:
1101 case WM_CREATE:
1103 CREATESTRUCTW cs;
1104 WCHAR *str = (WCHAR *)(&ps->cs + 1);
1105 if (size < sizeof(ps->cs)) return FALSE;
1106 size -= sizeof(ps->cs);
1107 cs.lpCreateParams = unpack_ptr( ps->cs.lpCreateParams );
1108 cs.hInstance = unpack_ptr( ps->cs.hInstance );
1109 cs.hMenu = wine_server_ptr_handle( ps->cs.hMenu );
1110 cs.hwndParent = wine_server_ptr_handle( ps->cs.hwndParent );
1111 cs.cy = ps->cs.cy;
1112 cs.cx = ps->cs.cx;
1113 cs.y = ps->cs.y;
1114 cs.x = ps->cs.x;
1115 cs.style = ps->cs.style;
1116 cs.dwExStyle = ps->cs.dwExStyle;
1117 cs.lpszName = unpack_ptr( ps->cs.lpszName );
1118 cs.lpszClass = unpack_ptr( ps->cs.lpszClass );
1119 if (ps->cs.lpszName >> 16)
1121 if (!check_string( str, size )) return FALSE;
1122 cs.lpszName = str;
1123 size -= (strlenW(str) + 1) * sizeof(WCHAR);
1124 str += strlenW(str) + 1;
1126 if (ps->cs.lpszClass >> 16)
1128 if (!check_string( str, size )) return FALSE;
1129 cs.lpszClass = str;
1131 memcpy( &ps->cs, &cs, sizeof(cs) );
1132 break;
1134 case WM_GETTEXT:
1135 case WM_ASKCBFORMATNAME:
1136 if (!get_buffer_space( buffer, (*wparam * sizeof(WCHAR)) )) return FALSE;
1137 break;
1138 case WM_WININICHANGE:
1139 if (!*lparam) return TRUE;
1140 /* fall through */
1141 case WM_SETTEXT:
1142 case WM_DEVMODECHANGE:
1143 case CB_DIR:
1144 case LB_DIR:
1145 case LB_ADDFILE:
1146 case EM_REPLACESEL:
1147 if (!check_string( *buffer, size )) return FALSE;
1148 break;
1149 case WM_GETMINMAXINFO:
1150 minsize = sizeof(MINMAXINFO);
1151 break;
1152 case WM_DRAWITEM:
1154 DRAWITEMSTRUCT dis;
1155 if (size < sizeof(ps->dis)) return FALSE;
1156 dis.CtlType = ps->dis.CtlType;
1157 dis.CtlID = ps->dis.CtlID;
1158 dis.itemID = ps->dis.itemID;
1159 dis.itemAction = ps->dis.itemAction;
1160 dis.itemState = ps->dis.itemState;
1161 dis.hwndItem = wine_server_ptr_handle( ps->dis.hwndItem );
1162 dis.hDC = wine_server_ptr_handle( ps->dis.hDC );
1163 dis.rcItem = ps->dis.rcItem;
1164 dis.itemData = (ULONG_PTR)unpack_ptr( ps->dis.itemData );
1165 memcpy( &ps->dis, &dis, sizeof(dis) );
1166 break;
1168 case WM_MEASUREITEM:
1170 MEASUREITEMSTRUCT mis;
1171 if (size < sizeof(ps->mis)) return FALSE;
1172 mis.CtlType = ps->mis.CtlType;
1173 mis.CtlID = ps->mis.CtlID;
1174 mis.itemID = ps->mis.itemID;
1175 mis.itemWidth = ps->mis.itemWidth;
1176 mis.itemHeight = ps->mis.itemHeight;
1177 mis.itemData = (ULONG_PTR)unpack_ptr( ps->mis.itemData );
1178 memcpy( &ps->mis, &mis, sizeof(mis) );
1179 break;
1181 case WM_DELETEITEM:
1183 DELETEITEMSTRUCT dls;
1184 if (size < sizeof(ps->dls)) return FALSE;
1185 dls.CtlType = ps->dls.CtlType;
1186 dls.CtlID = ps->dls.CtlID;
1187 dls.itemID = ps->dls.itemID;
1188 dls.hwndItem = wine_server_ptr_handle( ps->dls.hwndItem );
1189 dls.itemData = (ULONG_PTR)unpack_ptr( ps->dls.itemData );
1190 memcpy( &ps->dls, &dls, sizeof(dls) );
1191 break;
1193 case WM_COMPAREITEM:
1195 COMPAREITEMSTRUCT cis;
1196 if (size < sizeof(ps->cis)) return FALSE;
1197 cis.CtlType = ps->cis.CtlType;
1198 cis.CtlID = ps->cis.CtlID;
1199 cis.hwndItem = wine_server_ptr_handle( ps->cis.hwndItem );
1200 cis.itemID1 = ps->cis.itemID1;
1201 cis.itemData1 = (ULONG_PTR)unpack_ptr( ps->cis.itemData1 );
1202 cis.itemID2 = ps->cis.itemID2;
1203 cis.itemData2 = (ULONG_PTR)unpack_ptr( ps->cis.itemData2 );
1204 cis.dwLocaleId = ps->cis.dwLocaleId;
1205 memcpy( &ps->cis, &cis, sizeof(cis) );
1206 break;
1208 case WM_WINDOWPOSCHANGING:
1209 case WM_WINDOWPOSCHANGED:
1210 case WM_WINE_SETWINDOWPOS:
1212 WINDOWPOS wp;
1213 if (size < sizeof(ps->wp)) return FALSE;
1214 wp.hwnd = wine_server_ptr_handle( ps->wp.hwnd );
1215 wp.hwndInsertAfter = wine_server_ptr_handle( ps->wp.hwndInsertAfter );
1216 wp.x = ps->wp.x;
1217 wp.y = ps->wp.y;
1218 wp.cx = ps->wp.cx;
1219 wp.cy = ps->wp.cy;
1220 wp.flags = ps->wp.flags;
1221 memcpy( &ps->wp, &wp, sizeof(wp) );
1222 break;
1224 case WM_COPYDATA:
1226 COPYDATASTRUCT cds;
1227 if (size < sizeof(ps->cds)) return FALSE;
1228 cds.dwData = (ULONG_PTR)unpack_ptr( ps->cds.dwData );
1229 if (ps->cds.lpData)
1231 cds.cbData = ps->cds.cbData;
1232 cds.lpData = &ps->cds + 1;
1233 minsize = sizeof(ps->cds) + cds.cbData;
1235 else
1237 cds.cbData = 0;
1238 cds.lpData = 0;
1240 memcpy( &ps->cds, &cds, sizeof(cds) );
1241 break;
1243 case WM_NOTIFY:
1244 /* WM_NOTIFY cannot be sent across processes (MSDN) */
1245 return FALSE;
1246 case WM_HELP:
1248 HELPINFO hi;
1249 if (size < sizeof(ps->hi)) return FALSE;
1250 hi.cbSize = sizeof(hi);
1251 hi.iContextType = ps->hi.iContextType;
1252 hi.iCtrlId = ps->hi.iCtrlId;
1253 hi.hItemHandle = wine_server_ptr_handle( ps->hi.hItemHandle );
1254 hi.dwContextId = (ULONG_PTR)unpack_ptr( ps->hi.dwContextId );
1255 hi.MousePos = ps->hi.MousePos;
1256 memcpy( &ps->hi, &hi, sizeof(hi) );
1257 break;
1259 case WM_STYLECHANGING:
1260 case WM_STYLECHANGED:
1261 minsize = sizeof(STYLESTRUCT);
1262 break;
1263 case WM_NCCALCSIZE:
1264 if (!*wparam) minsize = sizeof(RECT);
1265 else
1267 NCCALCSIZE_PARAMS ncp;
1268 WINDOWPOS wp;
1269 if (size < sizeof(ps->ncp)) return FALSE;
1270 ncp.rgrc[0] = ps->ncp.rgrc[0];
1271 ncp.rgrc[1] = ps->ncp.rgrc[1];
1272 ncp.rgrc[2] = ps->ncp.rgrc[2];
1273 wp.hwnd = wine_server_ptr_handle( ps->ncp.hwnd );
1274 wp.hwndInsertAfter = wine_server_ptr_handle( ps->ncp.hwndInsertAfter );
1275 wp.x = ps->ncp.x;
1276 wp.y = ps->ncp.y;
1277 wp.cx = ps->ncp.cx;
1278 wp.cy = ps->ncp.cy;
1279 wp.flags = ps->ncp.flags;
1280 ncp.lppos = (WINDOWPOS *)((NCCALCSIZE_PARAMS *)&ps->ncp + 1);
1281 memcpy( &ps->ncp, &ncp, sizeof(ncp) );
1282 *ncp.lppos = wp;
1284 break;
1285 case WM_GETDLGCODE:
1286 if (*lparam)
1288 MSG msg;
1289 if (size < sizeof(ps->msg)) return FALSE;
1290 msg.hwnd = wine_server_ptr_handle( ps->msg.hwnd );
1291 msg.message = ps->msg.message;
1292 msg.wParam = (ULONG_PTR)unpack_ptr( ps->msg.wParam );
1293 msg.lParam = (ULONG_PTR)unpack_ptr( ps->msg.lParam );
1294 msg.time = ps->msg.time;
1295 msg.pt = ps->msg.pt;
1296 memcpy( &ps->msg, &msg, sizeof(msg) );
1297 break;
1299 return TRUE;
1300 case SBM_SETSCROLLINFO:
1301 minsize = sizeof(SCROLLINFO);
1302 break;
1303 case SBM_GETSCROLLINFO:
1304 if (!get_buffer_space( buffer, sizeof(SCROLLINFO ))) return FALSE;
1305 break;
1306 case SBM_GETSCROLLBARINFO:
1307 if (!get_buffer_space( buffer, sizeof(SCROLLBARINFO ))) return FALSE;
1308 break;
1309 case EM_GETSEL:
1310 case SBM_GETRANGE:
1311 case CB_GETEDITSEL:
1312 if (*wparam || *lparam)
1314 if (!get_buffer_space( buffer, 2*sizeof(DWORD) )) return FALSE;
1315 if (*wparam) *wparam = (WPARAM)*buffer;
1316 if (*lparam) *lparam = (LPARAM)((DWORD *)*buffer + 1);
1318 return TRUE;
1319 case EM_GETRECT:
1320 case LB_GETITEMRECT:
1321 case CB_GETDROPPEDCONTROLRECT:
1322 if (!get_buffer_space( buffer, sizeof(RECT) )) return FALSE;
1323 break;
1324 case EM_SETRECT:
1325 case EM_SETRECTNP:
1326 minsize = sizeof(RECT);
1327 break;
1328 case EM_GETLINE:
1330 WORD len;
1331 if (size < sizeof(WORD)) return FALSE;
1332 len = *(WORD *)*buffer;
1333 if (!get_buffer_space( buffer, (len + 1) * sizeof(WCHAR) )) return FALSE;
1334 *lparam = (LPARAM)*buffer + sizeof(WORD); /* don't erase WORD at start of buffer */
1335 return TRUE;
1337 case EM_SETTABSTOPS:
1338 case LB_SETTABSTOPS:
1339 if (!*wparam) return TRUE;
1340 minsize = *wparam * sizeof(UINT);
1341 break;
1342 case CB_ADDSTRING:
1343 case CB_INSERTSTRING:
1344 case CB_FINDSTRING:
1345 case CB_FINDSTRINGEXACT:
1346 case CB_SELECTSTRING:
1347 case LB_ADDSTRING:
1348 case LB_INSERTSTRING:
1349 case LB_FINDSTRING:
1350 case LB_FINDSTRINGEXACT:
1351 case LB_SELECTSTRING:
1352 if (!*buffer) return TRUE;
1353 if (!check_string( *buffer, size )) return FALSE;
1354 break;
1355 case CB_GETLBTEXT:
1357 size = sizeof(ULONG_PTR);
1358 if (combobox_has_strings( hwnd ))
1359 size = (SendMessageW( hwnd, CB_GETLBTEXTLEN, *wparam, 0 ) + 1) * sizeof(WCHAR);
1360 if (!get_buffer_space( buffer, size )) return FALSE;
1361 break;
1363 case LB_GETTEXT:
1365 size = sizeof(ULONG_PTR);
1366 if (listbox_has_strings( hwnd ))
1367 size = (SendMessageW( hwnd, LB_GETTEXTLEN, *wparam, 0 ) + 1) * sizeof(WCHAR);
1368 if (!get_buffer_space( buffer, size )) return FALSE;
1369 break;
1371 case LB_GETSELITEMS:
1372 if (!get_buffer_space( buffer, *wparam * sizeof(UINT) )) return FALSE;
1373 break;
1374 case WM_NEXTMENU:
1376 MDINEXTMENU mnm;
1377 if (size < sizeof(ps->mnm)) return FALSE;
1378 mnm.hmenuIn = wine_server_ptr_handle( ps->mnm.hmenuIn );
1379 mnm.hmenuNext = wine_server_ptr_handle( ps->mnm.hmenuNext );
1380 mnm.hwndNext = wine_server_ptr_handle( ps->mnm.hwndNext );
1381 memcpy( &ps->mnm, &mnm, sizeof(mnm) );
1382 break;
1384 case WM_SIZING:
1385 case WM_MOVING:
1386 minsize = sizeof(RECT);
1387 if (!get_buffer_space( buffer, sizeof(RECT) )) return FALSE;
1388 break;
1389 case WM_MDICREATE:
1391 MDICREATESTRUCTW mcs;
1392 WCHAR *str = (WCHAR *)(&ps->mcs + 1);
1393 if (size < sizeof(ps->mcs)) return FALSE;
1394 size -= sizeof(ps->mcs);
1396 mcs.szClass = unpack_ptr( ps->mcs.szClass );
1397 mcs.szTitle = unpack_ptr( ps->mcs.szTitle );
1398 mcs.hOwner = unpack_ptr( ps->mcs.hOwner );
1399 mcs.x = ps->mcs.x;
1400 mcs.y = ps->mcs.y;
1401 mcs.cx = ps->mcs.cx;
1402 mcs.cy = ps->mcs.cy;
1403 mcs.style = ps->mcs.style;
1404 mcs.lParam = (LPARAM)unpack_ptr( ps->mcs.lParam );
1405 if (ps->mcs.szClass >> 16)
1407 if (!check_string( str, size )) return FALSE;
1408 mcs.szClass = str;
1409 size -= (strlenW(str) + 1) * sizeof(WCHAR);
1410 str += strlenW(str) + 1;
1412 if (ps->mcs.szTitle >> 16)
1414 if (!check_string( str, size )) return FALSE;
1415 mcs.szTitle = str;
1417 memcpy( &ps->mcs, &mcs, sizeof(mcs) );
1418 break;
1420 case WM_MDIGETACTIVE:
1421 if (!*lparam) return TRUE;
1422 if (!get_buffer_space( buffer, sizeof(BOOL) )) return FALSE;
1423 break;
1424 case WM_DEVICECHANGE:
1425 minsize = sizeof(DEV_BROADCAST_HDR);
1426 break;
1427 case WM_WINE_KEYBOARD_LL_HOOK:
1428 case WM_WINE_MOUSE_LL_HOOK:
1430 struct hook_extra_info h_extra;
1431 minsize = sizeof(ps->hook) +
1432 (message == WM_WINE_KEYBOARD_LL_HOOK ? sizeof(KBDLLHOOKSTRUCT)
1433 : sizeof(MSLLHOOKSTRUCT));
1434 if (size < minsize) return FALSE;
1435 h_extra.handle = wine_server_ptr_handle( ps->hook.handle );
1436 h_extra.lparam = (LPARAM)(&ps->hook + 1);
1437 memcpy( &ps->hook, &h_extra, sizeof(h_extra) );
1438 break;
1440 case WM_NCPAINT:
1441 if (*wparam <= 1) return TRUE;
1442 FIXME( "WM_NCPAINT hdc unpacking not supported\n" );
1443 return FALSE;
1444 case WM_PAINT:
1445 if (!*wparam) return TRUE;
1446 /* fall through */
1448 /* these contain an HFONT */
1449 case WM_SETFONT:
1450 case WM_GETFONT:
1451 /* these contain an HDC */
1452 case WM_ERASEBKGND:
1453 case WM_ICONERASEBKGND:
1454 case WM_CTLCOLORMSGBOX:
1455 case WM_CTLCOLOREDIT:
1456 case WM_CTLCOLORLISTBOX:
1457 case WM_CTLCOLORBTN:
1458 case WM_CTLCOLORDLG:
1459 case WM_CTLCOLORSCROLLBAR:
1460 case WM_CTLCOLORSTATIC:
1461 case WM_PRINT:
1462 case WM_PRINTCLIENT:
1463 /* these contain an HGLOBAL */
1464 case WM_PAINTCLIPBOARD:
1465 case WM_SIZECLIPBOARD:
1466 /* these contain HICON */
1467 case WM_GETICON:
1468 case WM_SETICON:
1469 case WM_QUERYDRAGICON:
1470 case WM_QUERYPARKICON:
1471 /* these contain pointers */
1472 case WM_DROPOBJECT:
1473 case WM_QUERYDROPOBJECT:
1474 case WM_DRAGLOOP:
1475 case WM_DRAGSELECT:
1476 case WM_DRAGMOVE:
1477 FIXME( "msg %x (%s) not supported yet\n", message, SPY_GetMsgName(message, hwnd) );
1478 return FALSE;
1480 default:
1481 return TRUE; /* message doesn't need any unpacking */
1484 /* default exit for most messages: check minsize and store buffer in lparam */
1485 if (size < minsize) return FALSE;
1486 *lparam = (LPARAM)*buffer;
1487 return TRUE;
1491 /***********************************************************************
1492 * pack_reply
1494 * Pack a reply to a message for sending to another process.
1496 static void pack_reply( HWND hwnd, UINT message, WPARAM wparam, LPARAM lparam,
1497 LRESULT res, struct packed_message *data )
1499 data->count = 0;
1500 switch(message)
1502 case WM_NCCREATE:
1503 case WM_CREATE:
1505 CREATESTRUCTW *cs = (CREATESTRUCTW *)lparam;
1506 data->ps.cs.lpCreateParams = (ULONG_PTR)cs->lpCreateParams;
1507 data->ps.cs.hInstance = (ULONG_PTR)cs->hInstance;
1508 data->ps.cs.hMenu = wine_server_user_handle( cs->hMenu );
1509 data->ps.cs.hwndParent = wine_server_user_handle( cs->hwndParent );
1510 data->ps.cs.cy = cs->cy;
1511 data->ps.cs.cx = cs->cx;
1512 data->ps.cs.y = cs->y;
1513 data->ps.cs.x = cs->x;
1514 data->ps.cs.style = cs->style;
1515 data->ps.cs.dwExStyle = cs->dwExStyle;
1516 data->ps.cs.lpszName = (ULONG_PTR)cs->lpszName;
1517 data->ps.cs.lpszClass = (ULONG_PTR)cs->lpszClass;
1518 push_data( data, &data->ps.cs, sizeof(data->ps.cs) );
1519 break;
1521 case WM_GETTEXT:
1522 case CB_GETLBTEXT:
1523 case LB_GETTEXT:
1524 push_data( data, (WCHAR *)lparam, (res + 1) * sizeof(WCHAR) );
1525 break;
1526 case WM_GETMINMAXINFO:
1527 push_data( data, (MINMAXINFO *)lparam, sizeof(MINMAXINFO) );
1528 break;
1529 case WM_MEASUREITEM:
1531 MEASUREITEMSTRUCT *mis = (MEASUREITEMSTRUCT *)lparam;
1532 data->ps.mis.CtlType = mis->CtlType;
1533 data->ps.mis.CtlID = mis->CtlID;
1534 data->ps.mis.itemID = mis->itemID;
1535 data->ps.mis.itemWidth = mis->itemWidth;
1536 data->ps.mis.itemHeight = mis->itemHeight;
1537 data->ps.mis.itemData = mis->itemData;
1538 push_data( data, &data->ps.mis, sizeof(data->ps.mis) );
1539 break;
1541 case WM_WINDOWPOSCHANGING:
1542 case WM_WINDOWPOSCHANGED:
1544 WINDOWPOS *wp = (WINDOWPOS *)lparam;
1545 data->ps.wp.hwnd = wine_server_user_handle( wp->hwnd );
1546 data->ps.wp.hwndInsertAfter = wine_server_user_handle( wp->hwndInsertAfter );
1547 data->ps.wp.x = wp->x;
1548 data->ps.wp.y = wp->y;
1549 data->ps.wp.cx = wp->cx;
1550 data->ps.wp.cy = wp->cy;
1551 data->ps.wp.flags = wp->flags;
1552 push_data( data, &data->ps.wp, sizeof(data->ps.wp) );
1553 break;
1555 case WM_GETDLGCODE:
1556 if (lparam)
1558 MSG *msg = (MSG *)lparam;
1559 data->ps.msg.hwnd = wine_server_user_handle( msg->hwnd );
1560 data->ps.msg.message = msg->message;
1561 data->ps.msg.wParam = msg->wParam;
1562 data->ps.msg.lParam = msg->lParam;
1563 data->ps.msg.time = msg->time;
1564 data->ps.msg.pt = msg->pt;
1565 push_data( data, &data->ps.msg, sizeof(data->ps.msg) );
1567 break;
1568 case SBM_GETSCROLLINFO:
1569 push_data( data, (SCROLLINFO *)lparam, sizeof(SCROLLINFO) );
1570 break;
1571 case EM_GETRECT:
1572 case LB_GETITEMRECT:
1573 case CB_GETDROPPEDCONTROLRECT:
1574 case WM_SIZING:
1575 case WM_MOVING:
1576 push_data( data, (RECT *)lparam, sizeof(RECT) );
1577 break;
1578 case EM_GETLINE:
1580 WORD *ptr = (WORD *)lparam;
1581 push_data( data, ptr, ptr[-1] * sizeof(WCHAR) );
1582 break;
1584 case LB_GETSELITEMS:
1585 push_data( data, (UINT *)lparam, wparam * sizeof(UINT) );
1586 break;
1587 case WM_MDIGETACTIVE:
1588 if (lparam) push_data( data, (BOOL *)lparam, sizeof(BOOL) );
1589 break;
1590 case WM_NCCALCSIZE:
1591 if (!wparam)
1592 push_data( data, (RECT *)lparam, sizeof(RECT) );
1593 else
1595 NCCALCSIZE_PARAMS *ncp = (NCCALCSIZE_PARAMS *)lparam;
1596 data->ps.ncp.rgrc[0] = ncp->rgrc[0];
1597 data->ps.ncp.rgrc[1] = ncp->rgrc[1];
1598 data->ps.ncp.rgrc[2] = ncp->rgrc[2];
1599 data->ps.ncp.hwnd = wine_server_user_handle( ncp->lppos->hwnd );
1600 data->ps.ncp.hwndInsertAfter = wine_server_user_handle( ncp->lppos->hwndInsertAfter );
1601 data->ps.ncp.x = ncp->lppos->x;
1602 data->ps.ncp.y = ncp->lppos->y;
1603 data->ps.ncp.cx = ncp->lppos->cx;
1604 data->ps.ncp.cy = ncp->lppos->cy;
1605 data->ps.ncp.flags = ncp->lppos->flags;
1606 push_data( data, &data->ps.ncp, sizeof(data->ps.ncp) );
1608 break;
1609 case EM_GETSEL:
1610 case SBM_GETRANGE:
1611 case CB_GETEDITSEL:
1612 if (wparam) push_data( data, (DWORD *)wparam, sizeof(DWORD) );
1613 if (lparam) push_data( data, (DWORD *)lparam, sizeof(DWORD) );
1614 break;
1615 case WM_NEXTMENU:
1617 MDINEXTMENU *mnm = (MDINEXTMENU *)lparam;
1618 data->ps.mnm.hmenuIn = wine_server_user_handle( mnm->hmenuIn );
1619 data->ps.mnm.hmenuNext = wine_server_user_handle( mnm->hmenuNext );
1620 data->ps.mnm.hwndNext = wine_server_user_handle( mnm->hwndNext );
1621 push_data( data, &data->ps.mnm, sizeof(data->ps.mnm) );
1622 break;
1624 case WM_MDICREATE:
1626 MDICREATESTRUCTW *mcs = (MDICREATESTRUCTW *)lparam;
1627 data->ps.mcs.szClass = pack_ptr( mcs->szClass );
1628 data->ps.mcs.szTitle = pack_ptr( mcs->szTitle );
1629 data->ps.mcs.hOwner = pack_ptr( mcs->hOwner );
1630 data->ps.mcs.x = mcs->x;
1631 data->ps.mcs.y = mcs->y;
1632 data->ps.mcs.cx = mcs->cx;
1633 data->ps.mcs.cy = mcs->cy;
1634 data->ps.mcs.style = mcs->style;
1635 data->ps.mcs.lParam = mcs->lParam;
1636 push_data( data, &data->ps.mcs, sizeof(data->ps.mcs) );
1637 break;
1639 case WM_ASKCBFORMATNAME:
1640 push_data( data, (WCHAR *)lparam, (strlenW((WCHAR *)lparam) + 1) * sizeof(WCHAR) );
1641 break;
1646 /***********************************************************************
1647 * unpack_reply
1649 * Unpack a message reply received from another process.
1651 static void unpack_reply( HWND hwnd, UINT message, WPARAM wparam, LPARAM lparam,
1652 void *buffer, size_t size )
1654 union packed_structs *ps = buffer;
1656 switch(message)
1658 case WM_NCCREATE:
1659 case WM_CREATE:
1660 if (size >= sizeof(ps->cs))
1662 CREATESTRUCTW *cs = (CREATESTRUCTW *)lparam;
1663 cs->lpCreateParams = unpack_ptr( ps->cs.lpCreateParams );
1664 cs->hInstance = unpack_ptr( ps->cs.hInstance );
1665 cs->hMenu = wine_server_ptr_handle( ps->cs.hMenu );
1666 cs->hwndParent = wine_server_ptr_handle( ps->cs.hwndParent );
1667 cs->cy = ps->cs.cy;
1668 cs->cx = ps->cs.cx;
1669 cs->y = ps->cs.y;
1670 cs->x = ps->cs.x;
1671 cs->style = ps->cs.style;
1672 cs->dwExStyle = ps->cs.dwExStyle;
1673 /* don't allow changing name and class pointers */
1675 break;
1676 case WM_GETTEXT:
1677 case WM_ASKCBFORMATNAME:
1678 memcpy( (WCHAR *)lparam, buffer, min( wparam*sizeof(WCHAR), size ));
1679 break;
1680 case WM_GETMINMAXINFO:
1681 memcpy( (MINMAXINFO *)lparam, buffer, min( sizeof(MINMAXINFO), size ));
1682 break;
1683 case WM_MEASUREITEM:
1684 if (size >= sizeof(ps->mis))
1686 MEASUREITEMSTRUCT *mis = (MEASUREITEMSTRUCT *)lparam;
1687 mis->CtlType = ps->mis.CtlType;
1688 mis->CtlID = ps->mis.CtlID;
1689 mis->itemID = ps->mis.itemID;
1690 mis->itemWidth = ps->mis.itemWidth;
1691 mis->itemHeight = ps->mis.itemHeight;
1692 mis->itemData = (ULONG_PTR)unpack_ptr( ps->mis.itemData );
1694 break;
1695 case WM_WINDOWPOSCHANGING:
1696 case WM_WINDOWPOSCHANGED:
1697 if (size >= sizeof(ps->wp))
1699 WINDOWPOS *wp = (WINDOWPOS *)lparam;
1700 wp->hwnd = wine_server_ptr_handle( ps->wp.hwnd );
1701 wp->hwndInsertAfter = wine_server_ptr_handle( ps->wp.hwndInsertAfter );
1702 wp->x = ps->wp.x;
1703 wp->y = ps->wp.y;
1704 wp->cx = ps->wp.cx;
1705 wp->cy = ps->wp.cy;
1706 wp->flags = ps->wp.flags;
1708 break;
1709 case WM_GETDLGCODE:
1710 if (lparam && size >= sizeof(ps->msg))
1712 MSG *msg = (MSG *)lparam;
1713 msg->hwnd = wine_server_ptr_handle( ps->msg.hwnd );
1714 msg->message = ps->msg.message;
1715 msg->wParam = (ULONG_PTR)unpack_ptr( ps->msg.wParam );
1716 msg->lParam = (ULONG_PTR)unpack_ptr( ps->msg.lParam );
1717 msg->time = ps->msg.time;
1718 msg->pt = ps->msg.pt;
1720 break;
1721 case SBM_GETSCROLLINFO:
1722 memcpy( (SCROLLINFO *)lparam, buffer, min( sizeof(SCROLLINFO), size ));
1723 break;
1724 case SBM_GETSCROLLBARINFO:
1725 memcpy( (SCROLLBARINFO *)lparam, buffer, min( sizeof(SCROLLBARINFO), size ));
1726 break;
1727 case EM_GETRECT:
1728 case CB_GETDROPPEDCONTROLRECT:
1729 case LB_GETITEMRECT:
1730 case WM_SIZING:
1731 case WM_MOVING:
1732 memcpy( (RECT *)lparam, buffer, min( sizeof(RECT), size ));
1733 break;
1734 case EM_GETLINE:
1735 size = min( size, (size_t)*(WORD *)lparam );
1736 memcpy( (WCHAR *)lparam, buffer, size );
1737 break;
1738 case LB_GETSELITEMS:
1739 memcpy( (UINT *)lparam, buffer, min( wparam*sizeof(UINT), size ));
1740 break;
1741 case LB_GETTEXT:
1742 case CB_GETLBTEXT:
1743 memcpy( (WCHAR *)lparam, buffer, size );
1744 break;
1745 case WM_NEXTMENU:
1746 if (size >= sizeof(ps->mnm))
1748 MDINEXTMENU *mnm = (MDINEXTMENU *)lparam;
1749 mnm->hmenuIn = wine_server_ptr_handle( ps->mnm.hmenuIn );
1750 mnm->hmenuNext = wine_server_ptr_handle( ps->mnm.hmenuNext );
1751 mnm->hwndNext = wine_server_ptr_handle( ps->mnm.hwndNext );
1753 break;
1754 case WM_MDIGETACTIVE:
1755 if (lparam) memcpy( (BOOL *)lparam, buffer, min( sizeof(BOOL), size ));
1756 break;
1757 case WM_NCCALCSIZE:
1758 if (!wparam)
1759 memcpy( (RECT *)lparam, buffer, min( sizeof(RECT), size ));
1760 else if (size >= sizeof(ps->ncp))
1762 NCCALCSIZE_PARAMS *ncp = (NCCALCSIZE_PARAMS *)lparam;
1763 ncp->rgrc[0] = ps->ncp.rgrc[0];
1764 ncp->rgrc[1] = ps->ncp.rgrc[1];
1765 ncp->rgrc[2] = ps->ncp.rgrc[2];
1766 ncp->lppos->hwnd = wine_server_ptr_handle( ps->ncp.hwnd );
1767 ncp->lppos->hwndInsertAfter = wine_server_ptr_handle( ps->ncp.hwndInsertAfter );
1768 ncp->lppos->x = ps->ncp.x;
1769 ncp->lppos->y = ps->ncp.y;
1770 ncp->lppos->cx = ps->ncp.cx;
1771 ncp->lppos->cy = ps->ncp.cy;
1772 ncp->lppos->flags = ps->ncp.flags;
1774 break;
1775 case EM_GETSEL:
1776 case SBM_GETRANGE:
1777 case CB_GETEDITSEL:
1778 if (wparam)
1780 memcpy( (DWORD *)wparam, buffer, min( sizeof(DWORD), size ));
1781 if (size <= sizeof(DWORD)) break;
1782 size -= sizeof(DWORD);
1783 buffer = (DWORD *)buffer + 1;
1785 if (lparam) memcpy( (DWORD *)lparam, buffer, min( sizeof(DWORD), size ));
1786 break;
1787 case WM_MDICREATE:
1788 if (size >= sizeof(ps->mcs))
1790 MDICREATESTRUCTW *mcs = (MDICREATESTRUCTW *)lparam;
1791 mcs->hOwner = unpack_ptr( ps->mcs.hOwner );
1792 mcs->x = ps->mcs.x;
1793 mcs->y = ps->mcs.y;
1794 mcs->cx = ps->mcs.cx;
1795 mcs->cy = ps->mcs.cy;
1796 mcs->style = ps->mcs.style;
1797 mcs->lParam = (LPARAM)unpack_ptr( ps->mcs.lParam );
1798 /* don't allow changing class and title pointers */
1800 break;
1801 default:
1802 ERR( "should not happen: unexpected message %x\n", message );
1803 break;
1808 /***********************************************************************
1809 * reply_message
1811 * Send a reply to a sent message.
1813 static void reply_message( struct received_message_info *info, LRESULT result, BOOL remove )
1815 struct packed_message data;
1816 int i, replied = info->flags & ISMEX_REPLIED;
1818 if (info->flags & ISMEX_NOTIFY) return; /* notify messages don't get replies */
1819 if (!remove && replied) return; /* replied already */
1821 memset( &data, 0, sizeof(data) );
1822 info->flags |= ISMEX_REPLIED;
1824 if (info->type == MSG_OTHER_PROCESS && !replied)
1826 pack_reply( info->msg.hwnd, info->msg.message, info->msg.wParam,
1827 info->msg.lParam, result, &data );
1830 SERVER_START_REQ( reply_message )
1832 req->result = result;
1833 req->remove = remove;
1834 for (i = 0; i < data.count; i++) wine_server_add_data( req, data.data[i], data.size[i] );
1835 wine_server_call( req );
1837 SERVER_END_REQ;
1841 /***********************************************************************
1842 * handle_internal_message
1844 * Handle an internal Wine message instead of calling the window proc.
1846 static LRESULT handle_internal_message( HWND hwnd, UINT msg, WPARAM wparam, LPARAM lparam )
1848 switch(msg)
1850 case WM_WINE_DESTROYWINDOW:
1851 return WIN_DestroyWindow( hwnd );
1852 case WM_WINE_SETWINDOWPOS:
1853 if (is_desktop_window( hwnd )) return 0;
1854 return USER_SetWindowPos( (WINDOWPOS *)lparam );
1855 case WM_WINE_SHOWWINDOW:
1856 if (is_desktop_window( hwnd )) return 0;
1857 return ShowWindow( hwnd, wparam );
1858 case WM_WINE_SETPARENT:
1859 if (is_desktop_window( hwnd )) return 0;
1860 return (LRESULT)SetParent( hwnd, (HWND)wparam );
1861 case WM_WINE_SETWINDOWLONG:
1862 return WIN_SetWindowLong( hwnd, (short)LOWORD(wparam), HIWORD(wparam), lparam, TRUE );
1863 case WM_WINE_ENABLEWINDOW:
1864 if (is_desktop_window( hwnd )) return 0;
1865 return EnableWindow( hwnd, wparam );
1866 case WM_WINE_SETACTIVEWINDOW:
1867 if (is_desktop_window( hwnd )) return 0;
1868 return (LRESULT)SetActiveWindow( (HWND)wparam );
1869 case WM_WINE_KEYBOARD_LL_HOOK:
1870 case WM_WINE_MOUSE_LL_HOOK:
1872 struct hook_extra_info *h_extra = (struct hook_extra_info *)lparam;
1874 return call_current_hook( h_extra->handle, HC_ACTION, wparam, h_extra->lparam );
1876 case WM_WINE_CLIPCURSOR:
1877 if (wparam)
1879 RECT rect;
1880 GetClipCursor( &rect );
1881 return USER_Driver->pClipCursor( &rect );
1883 return USER_Driver->pClipCursor( NULL );
1884 default:
1885 if (msg >= WM_WINE_FIRST_DRIVER_MSG && msg <= WM_WINE_LAST_DRIVER_MSG)
1886 return USER_Driver->pWindowMessage( hwnd, msg, wparam, lparam );
1887 FIXME( "unknown internal message %x\n", msg );
1888 return 0;
1892 /* since the WM_DDE_ACK response to a WM_DDE_EXECUTE message should contain the handle
1893 * to the memory handle, we keep track (in the server side) of all pairs of handle
1894 * used (the client passes its value and the content of the memory handle), and
1895 * the server stored both values (the client, and the local one, created after the
1896 * content). When a ACK message is generated, the list of pair is searched for a
1897 * matching pair, so that the client memory handle can be returned.
1899 struct DDE_pair {
1900 HGLOBAL client_hMem;
1901 HGLOBAL server_hMem;
1904 static struct DDE_pair* dde_pairs;
1905 static int dde_num_alloc;
1906 static int dde_num_used;
1908 static CRITICAL_SECTION dde_crst;
1909 static CRITICAL_SECTION_DEBUG critsect_debug =
1911 0, 0, &dde_crst,
1912 { &critsect_debug.ProcessLocksList, &critsect_debug.ProcessLocksList },
1913 0, 0, { (DWORD_PTR)(__FILE__ ": dde_crst") }
1915 static CRITICAL_SECTION dde_crst = { &critsect_debug, -1, 0, 0, 0, 0 };
1917 static BOOL dde_add_pair(HGLOBAL chm, HGLOBAL shm)
1919 int i;
1920 #define GROWBY 4
1922 EnterCriticalSection(&dde_crst);
1924 /* now remember the pair of hMem on both sides */
1925 if (dde_num_used == dde_num_alloc)
1927 struct DDE_pair* tmp;
1928 if (dde_pairs)
1929 tmp = HeapReAlloc( GetProcessHeap(), 0, dde_pairs,
1930 (dde_num_alloc + GROWBY) * sizeof(struct DDE_pair));
1931 else
1932 tmp = HeapAlloc( GetProcessHeap(), 0,
1933 (dde_num_alloc + GROWBY) * sizeof(struct DDE_pair));
1935 if (!tmp)
1937 LeaveCriticalSection(&dde_crst);
1938 return FALSE;
1940 dde_pairs = tmp;
1941 /* zero out newly allocated part */
1942 memset(&dde_pairs[dde_num_alloc], 0, GROWBY * sizeof(struct DDE_pair));
1943 dde_num_alloc += GROWBY;
1945 #undef GROWBY
1946 for (i = 0; i < dde_num_alloc; i++)
1948 if (dde_pairs[i].server_hMem == 0)
1950 dde_pairs[i].client_hMem = chm;
1951 dde_pairs[i].server_hMem = shm;
1952 dde_num_used++;
1953 break;
1956 LeaveCriticalSection(&dde_crst);
1957 return TRUE;
1960 static HGLOBAL dde_get_pair(HGLOBAL shm)
1962 int i;
1963 HGLOBAL ret = 0;
1965 EnterCriticalSection(&dde_crst);
1966 for (i = 0; i < dde_num_alloc; i++)
1968 if (dde_pairs[i].server_hMem == shm)
1970 /* free this pair */
1971 dde_pairs[i].server_hMem = 0;
1972 dde_num_used--;
1973 ret = dde_pairs[i].client_hMem;
1974 break;
1977 LeaveCriticalSection(&dde_crst);
1978 return ret;
1981 /***********************************************************************
1982 * post_dde_message
1984 * Post a DDE message
1986 static BOOL post_dde_message( struct packed_message *data, const struct send_message_info *info )
1988 void* ptr = NULL;
1989 int size = 0;
1990 UINT_PTR uiLo, uiHi;
1991 LPARAM lp = 0;
1992 HGLOBAL hunlock = 0;
1993 int i;
1994 DWORD res;
1996 if (!UnpackDDElParam( info->msg, info->lparam, &uiLo, &uiHi ))
1997 return FALSE;
1999 lp = info->lparam;
2000 switch (info->msg)
2002 /* DDE messages which don't require packing are:
2003 * WM_DDE_INITIATE
2004 * WM_DDE_TERMINATE
2005 * WM_DDE_REQUEST
2006 * WM_DDE_UNADVISE
2008 case WM_DDE_ACK:
2009 if (HIWORD(uiHi))
2011 /* uiHi should contain a hMem from WM_DDE_EXECUTE */
2012 HGLOBAL h = dde_get_pair( (HANDLE)uiHi );
2013 if (h)
2015 ULONGLONG hpack = pack_ptr( h );
2016 /* send back the value of h on the other side */
2017 push_data( data, &hpack, sizeof(hpack) );
2018 lp = uiLo;
2019 TRACE( "send dde-ack %lx %08lx => %p\n", uiLo, uiHi, h );
2022 else
2024 /* uiHi should contain either an atom or 0 */
2025 TRACE( "send dde-ack %lx atom=%lx\n", uiLo, uiHi );
2026 lp = MAKELONG( uiLo, uiHi );
2028 break;
2029 case WM_DDE_ADVISE:
2030 case WM_DDE_DATA:
2031 case WM_DDE_POKE:
2032 size = 0;
2033 if (uiLo)
2035 size = GlobalSize( (HGLOBAL)uiLo ) ;
2036 if ((info->msg == WM_DDE_ADVISE && size < sizeof(DDEADVISE)) ||
2037 (info->msg == WM_DDE_DATA && size < FIELD_OFFSET(DDEDATA, Value)) ||
2038 (info->msg == WM_DDE_POKE && size < FIELD_OFFSET(DDEPOKE, Value))
2040 return FALSE;
2042 else if (info->msg != WM_DDE_DATA) return FALSE;
2044 lp = uiHi;
2045 if (uiLo)
2047 if ((ptr = GlobalLock( (HGLOBAL)uiLo) ))
2049 DDEDATA *dde_data = ptr;
2050 TRACE("unused %d, fResponse %d, fRelease %d, fDeferUpd %d, fAckReq %d, cfFormat %d\n",
2051 dde_data->unused, dde_data->fResponse, dde_data->fRelease,
2052 dde_data->reserved, dde_data->fAckReq, dde_data->cfFormat);
2053 push_data( data, ptr, size );
2054 hunlock = (HGLOBAL)uiLo;
2057 TRACE( "send ddepack %u %lx\n", size, uiHi );
2058 break;
2059 case WM_DDE_EXECUTE:
2060 if (info->lparam)
2062 if ((ptr = GlobalLock( (HGLOBAL)info->lparam) ))
2064 push_data(data, ptr, GlobalSize( (HGLOBAL)info->lparam ));
2065 /* so that the other side can send it back on ACK */
2066 lp = info->lparam;
2067 hunlock = (HGLOBAL)info->lparam;
2070 break;
2072 SERVER_START_REQ( send_message )
2074 req->id = info->dest_tid;
2075 req->type = info->type;
2076 req->flags = 0;
2077 req->win = wine_server_user_handle( info->hwnd );
2078 req->msg = info->msg;
2079 req->wparam = info->wparam;
2080 req->lparam = lp;
2081 req->timeout = TIMEOUT_INFINITE;
2082 for (i = 0; i < data->count; i++)
2083 wine_server_add_data( req, data->data[i], data->size[i] );
2084 if ((res = wine_server_call( req )))
2086 if (res == STATUS_INVALID_PARAMETER)
2087 /* FIXME: find a STATUS_ value for this one */
2088 SetLastError( ERROR_INVALID_THREAD_ID );
2089 else
2090 SetLastError( RtlNtStatusToDosError(res) );
2092 else
2093 FreeDDElParam(info->msg, info->lparam);
2095 SERVER_END_REQ;
2096 if (hunlock) GlobalUnlock(hunlock);
2098 return !res;
2101 /***********************************************************************
2102 * unpack_dde_message
2104 * Unpack a posted DDE message received from another process.
2106 static BOOL unpack_dde_message( HWND hwnd, UINT message, WPARAM *wparam, LPARAM *lparam,
2107 void **buffer, size_t size )
2109 UINT_PTR uiLo, uiHi;
2110 HGLOBAL hMem = 0;
2111 void* ptr;
2113 switch (message)
2115 case WM_DDE_ACK:
2116 if (size)
2118 ULONGLONG hpack;
2119 /* hMem is being passed */
2120 if (size != sizeof(hpack)) return FALSE;
2121 if (!buffer || !*buffer) return FALSE;
2122 uiLo = *lparam;
2123 memcpy( &hpack, *buffer, size );
2124 hMem = unpack_ptr( hpack );
2125 uiHi = (UINT_PTR)hMem;
2126 TRACE("recv dde-ack %lx mem=%lx[%lx]\n", uiLo, uiHi, GlobalSize( hMem ));
2128 else
2130 uiLo = LOWORD( *lparam );
2131 uiHi = HIWORD( *lparam );
2132 TRACE("recv dde-ack %lx atom=%lx\n", uiLo, uiHi);
2134 *lparam = PackDDElParam( WM_DDE_ACK, uiLo, uiHi );
2135 break;
2136 case WM_DDE_ADVISE:
2137 case WM_DDE_DATA:
2138 case WM_DDE_POKE:
2139 if ((!buffer || !*buffer) && message != WM_DDE_DATA) return FALSE;
2140 uiHi = *lparam;
2141 if (size)
2143 if (!(hMem = GlobalAlloc( GMEM_MOVEABLE|GMEM_DDESHARE, size )))
2144 return FALSE;
2145 if ((ptr = GlobalLock( hMem )))
2147 memcpy( ptr, *buffer, size );
2148 GlobalUnlock( hMem );
2150 else
2152 GlobalFree( hMem );
2153 return FALSE;
2156 uiLo = (UINT_PTR)hMem;
2158 *lparam = PackDDElParam( message, uiLo, uiHi );
2159 break;
2160 case WM_DDE_EXECUTE:
2161 if (size)
2163 if (!buffer || !*buffer) return FALSE;
2164 if (!(hMem = GlobalAlloc( GMEM_MOVEABLE|GMEM_DDESHARE, size ))) return FALSE;
2165 if ((ptr = GlobalLock( hMem )))
2167 memcpy( ptr, *buffer, size );
2168 GlobalUnlock( hMem );
2169 TRACE( "exec: pairing c=%08lx s=%p\n", *lparam, hMem );
2170 if (!dde_add_pair( (HGLOBAL)*lparam, hMem ))
2172 GlobalFree( hMem );
2173 return FALSE;
2176 else
2178 GlobalFree( hMem );
2179 return FALSE;
2181 } else return FALSE;
2182 *lparam = (LPARAM)hMem;
2183 break;
2185 return TRUE;
2188 /***********************************************************************
2189 * call_window_proc
2191 * Call a window procedure and the corresponding hooks.
2193 static LRESULT call_window_proc( HWND hwnd, UINT msg, WPARAM wparam, LPARAM lparam,
2194 BOOL unicode, BOOL same_thread, enum wm_char_mapping mapping )
2196 LRESULT result = 0;
2197 CWPSTRUCT cwp;
2198 CWPRETSTRUCT cwpret;
2200 if (msg & 0x80000000)
2202 result = handle_internal_message( hwnd, msg, wparam, lparam );
2203 goto done;
2206 /* first the WH_CALLWNDPROC hook */
2207 hwnd = WIN_GetFullHandle( hwnd );
2208 cwp.lParam = lparam;
2209 cwp.wParam = wparam;
2210 cwp.message = msg;
2211 cwp.hwnd = hwnd;
2212 HOOK_CallHooks( WH_CALLWNDPROC, HC_ACTION, same_thread, (LPARAM)&cwp, unicode );
2214 /* now call the window procedure */
2215 if (!WINPROC_call_window( hwnd, msg, wparam, lparam, &result, unicode, mapping )) goto done;
2217 /* and finally the WH_CALLWNDPROCRET hook */
2218 cwpret.lResult = result;
2219 cwpret.lParam = lparam;
2220 cwpret.wParam = wparam;
2221 cwpret.message = msg;
2222 cwpret.hwnd = hwnd;
2223 HOOK_CallHooks( WH_CALLWNDPROCRET, HC_ACTION, same_thread, (LPARAM)&cwpret, unicode );
2224 done:
2225 return result;
2229 /***********************************************************************
2230 * send_parent_notify
2232 * Send a WM_PARENTNOTIFY to all ancestors of the given window, unless
2233 * the window has the WS_EX_NOPARENTNOTIFY style.
2235 static void send_parent_notify( HWND hwnd, WORD event, WORD idChild, POINT pt )
2237 /* pt has to be in the client coordinates of the parent window */
2238 MapWindowPoints( 0, hwnd, &pt, 1 );
2239 for (;;)
2241 HWND parent;
2243 if (!(GetWindowLongW( hwnd, GWL_STYLE ) & WS_CHILD)) break;
2244 if (GetWindowLongW( hwnd, GWL_EXSTYLE ) & WS_EX_NOPARENTNOTIFY) break;
2245 if (!(parent = GetParent(hwnd))) break;
2246 if (parent == GetDesktopWindow()) break;
2247 MapWindowPoints( hwnd, parent, &pt, 1 );
2248 hwnd = parent;
2249 SendMessageW( hwnd, WM_PARENTNOTIFY,
2250 MAKEWPARAM( event, idChild ), MAKELPARAM( pt.x, pt.y ) );
2255 /***********************************************************************
2256 * accept_hardware_message
2258 * Tell the server we have passed the message to the app
2259 * (even though we may end up dropping it later on)
2261 static void accept_hardware_message( UINT hw_id, BOOL remove, HWND new_hwnd )
2263 SERVER_START_REQ( accept_hardware_message )
2265 req->hw_id = hw_id;
2266 req->remove = remove;
2267 req->new_win = wine_server_user_handle( new_hwnd );
2268 if (wine_server_call( req ))
2269 FIXME("Failed to reply to MSG_HARDWARE message. Message may not be removed from queue.\n");
2271 SERVER_END_REQ;
2275 static BOOL process_rawinput_message( MSG *msg, const struct hardware_msg_data *msg_data )
2277 struct user_thread_info *thread_info = get_user_thread_info();
2278 RAWINPUT *rawinput = thread_info->rawinput;
2280 if (!rawinput)
2282 thread_info->rawinput = HeapAlloc( GetProcessHeap(), 0, sizeof(*rawinput) );
2283 if (!(rawinput = thread_info->rawinput)) return FALSE;
2286 rawinput->header.dwType = msg_data->rawinput.type;
2287 if (msg_data->rawinput.type == RIM_TYPEMOUSE)
2289 static const unsigned int button_flags[] =
2291 0, /* MOUSEEVENTF_MOVE */
2292 RI_MOUSE_LEFT_BUTTON_DOWN, /* MOUSEEVENTF_LEFTDOWN */
2293 RI_MOUSE_LEFT_BUTTON_UP, /* MOUSEEVENTF_LEFTUP */
2294 RI_MOUSE_RIGHT_BUTTON_DOWN, /* MOUSEEVENTF_RIGHTDOWN */
2295 RI_MOUSE_RIGHT_BUTTON_UP, /* MOUSEEVENTF_RIGHTUP */
2296 RI_MOUSE_MIDDLE_BUTTON_DOWN, /* MOUSEEVENTF_MIDDLEDOWN */
2297 RI_MOUSE_MIDDLE_BUTTON_UP, /* MOUSEEVENTF_MIDDLEUP */
2299 unsigned int i;
2301 rawinput->header.dwSize = FIELD_OFFSET(RAWINPUT, data) + sizeof(RAWMOUSE);
2302 rawinput->header.hDevice = WINE_MOUSE_HANDLE;
2303 rawinput->header.wParam = 0;
2305 rawinput->data.mouse.usFlags = MOUSE_MOVE_RELATIVE;
2306 rawinput->data.mouse.u.s.usButtonFlags = 0;
2307 rawinput->data.mouse.u.s.usButtonData = 0;
2308 for (i = 1; i < sizeof(button_flags) / sizeof(*button_flags); ++i)
2310 if (msg_data->flags & (1 << i))
2311 rawinput->data.mouse.u.s.usButtonFlags |= button_flags[i];
2313 if (msg_data->flags & MOUSEEVENTF_WHEEL)
2315 rawinput->data.mouse.u.s.usButtonFlags |= RI_MOUSE_WHEEL;
2316 rawinput->data.mouse.u.s.usButtonData = msg_data->rawinput.mouse.data;
2318 if (msg_data->flags & MOUSEEVENTF_HWHEEL)
2320 rawinput->data.mouse.u.s.usButtonFlags |= RI_MOUSE_HORIZONTAL_WHEEL;
2321 rawinput->data.mouse.u.s.usButtonData = msg_data->rawinput.mouse.data;
2323 if (msg_data->flags & MOUSEEVENTF_XDOWN)
2325 if (msg_data->rawinput.mouse.data == XBUTTON1)
2326 rawinput->data.mouse.u.s.usButtonFlags |= RI_MOUSE_BUTTON_4_DOWN;
2327 else if (msg_data->rawinput.mouse.data == XBUTTON2)
2328 rawinput->data.mouse.u.s.usButtonFlags |= RI_MOUSE_BUTTON_5_DOWN;
2330 if (msg_data->flags & MOUSEEVENTF_XUP)
2332 if (msg_data->rawinput.mouse.data == XBUTTON1)
2333 rawinput->data.mouse.u.s.usButtonFlags |= RI_MOUSE_BUTTON_4_UP;
2334 else if (msg_data->rawinput.mouse.data == XBUTTON2)
2335 rawinput->data.mouse.u.s.usButtonFlags |= RI_MOUSE_BUTTON_5_UP;
2338 rawinput->data.mouse.ulRawButtons = 0;
2339 rawinput->data.mouse.lLastX = msg_data->rawinput.mouse.x;
2340 rawinput->data.mouse.lLastY = msg_data->rawinput.mouse.y;
2341 rawinput->data.mouse.ulExtraInformation = msg_data->info;
2343 else if (msg_data->rawinput.type == RIM_TYPEKEYBOARD)
2345 rawinput->header.dwSize = FIELD_OFFSET(RAWINPUT, data) + sizeof(RAWKEYBOARD);
2346 rawinput->header.hDevice = WINE_KEYBOARD_HANDLE;
2347 rawinput->header.wParam = 0;
2349 rawinput->data.keyboard.MakeCode = msg_data->rawinput.kbd.scan;
2350 rawinput->data.keyboard.Flags = msg_data->flags & KEYEVENTF_KEYUP ? RI_KEY_BREAK : RI_KEY_MAKE;
2351 if (msg_data->flags & KEYEVENTF_EXTENDEDKEY) rawinput->data.keyboard.Flags |= RI_KEY_E0;
2352 rawinput->data.keyboard.Reserved = 0;
2354 switch (msg_data->rawinput.kbd.vkey)
2356 case VK_LSHIFT:
2357 case VK_RSHIFT:
2358 rawinput->data.keyboard.VKey = VK_SHIFT;
2359 rawinput->data.keyboard.Flags &= ~RI_KEY_E0;
2360 break;
2361 case VK_LCONTROL:
2362 case VK_RCONTROL:
2363 rawinput->data.keyboard.VKey = VK_CONTROL;
2364 break;
2365 case VK_LMENU:
2366 case VK_RMENU:
2367 rawinput->data.keyboard.VKey = VK_MENU;
2368 break;
2369 default:
2370 rawinput->data.keyboard.VKey = msg_data->rawinput.kbd.vkey;
2371 break;
2374 rawinput->data.keyboard.Message = msg_data->rawinput.kbd.message;
2375 rawinput->data.keyboard.ExtraInformation = msg_data->info;
2377 else
2379 FIXME("Unhandled rawinput type %#x.\n", msg_data->rawinput.type);
2380 return FALSE;
2383 msg->lParam = (LPARAM)rawinput;
2384 return TRUE;
2387 /***********************************************************************
2388 * process_keyboard_message
2390 * returns TRUE if the contents of 'msg' should be passed to the application
2392 static BOOL process_keyboard_message( MSG *msg, UINT hw_id, HWND hwnd_filter,
2393 UINT first, UINT last, BOOL remove )
2395 EVENTMSG event;
2397 if (msg->message == WM_KEYDOWN || msg->message == WM_SYSKEYDOWN ||
2398 msg->message == WM_KEYUP || msg->message == WM_SYSKEYUP)
2399 switch (msg->wParam)
2401 case VK_LSHIFT: case VK_RSHIFT:
2402 msg->wParam = VK_SHIFT;
2403 break;
2404 case VK_LCONTROL: case VK_RCONTROL:
2405 msg->wParam = VK_CONTROL;
2406 break;
2407 case VK_LMENU: case VK_RMENU:
2408 msg->wParam = VK_MENU;
2409 break;
2412 /* FIXME: is this really the right place for this hook? */
2413 event.message = msg->message;
2414 event.hwnd = msg->hwnd;
2415 event.time = msg->time;
2416 event.paramL = (msg->wParam & 0xFF) | (HIWORD(msg->lParam) << 8);
2417 event.paramH = msg->lParam & 0x7FFF;
2418 if (HIWORD(msg->lParam) & 0x0100) event.paramH |= 0x8000; /* special_key - bit */
2419 HOOK_CallHooks( WH_JOURNALRECORD, HC_ACTION, 0, (LPARAM)&event, TRUE );
2421 /* check message filters */
2422 if (msg->message < first || msg->message > last) return FALSE;
2423 if (!check_hwnd_filter( msg, hwnd_filter )) return FALSE;
2425 if (remove)
2427 if((msg->message == WM_KEYDOWN) &&
2428 (msg->hwnd != GetDesktopWindow()))
2430 /* Handle F1 key by sending out WM_HELP message */
2431 if (msg->wParam == VK_F1)
2433 PostMessageW( msg->hwnd, WM_KEYF1, 0, 0 );
2435 else if(msg->wParam >= VK_BROWSER_BACK &&
2436 msg->wParam <= VK_LAUNCH_APP2)
2438 /* FIXME: Process keystate */
2439 SendMessageW(msg->hwnd, WM_APPCOMMAND, (WPARAM)msg->hwnd, MAKELPARAM(0, (FAPPCOMMAND_KEY | (msg->wParam - VK_BROWSER_BACK + 1))));
2442 else if (msg->message == WM_KEYUP)
2444 /* Handle VK_APPS key by posting a WM_CONTEXTMENU message */
2445 if (msg->wParam == VK_APPS && !MENU_IsMenuActive())
2446 PostMessageW(msg->hwnd, WM_CONTEXTMENU, (WPARAM)msg->hwnd, -1);
2450 if (HOOK_CallHooks( WH_KEYBOARD, remove ? HC_ACTION : HC_NOREMOVE,
2451 LOWORD(msg->wParam), msg->lParam, TRUE ))
2453 /* skip this message */
2454 HOOK_CallHooks( WH_CBT, HCBT_KEYSKIPPED, LOWORD(msg->wParam), msg->lParam, TRUE );
2455 accept_hardware_message( hw_id, TRUE, 0 );
2456 return FALSE;
2458 accept_hardware_message( hw_id, remove, 0 );
2460 if ( remove && msg->message == WM_KEYDOWN )
2461 if (ImmProcessKey(msg->hwnd, GetKeyboardLayout(0), msg->wParam, msg->lParam, 0) )
2462 msg->wParam = VK_PROCESSKEY;
2464 return TRUE;
2468 /***********************************************************************
2469 * process_mouse_message
2471 * returns TRUE if the contents of 'msg' should be passed to the application
2473 static BOOL process_mouse_message( MSG *msg, UINT hw_id, ULONG_PTR extra_info, HWND hwnd_filter,
2474 UINT first, UINT last, BOOL remove )
2476 static MSG clk_msg;
2478 POINT pt;
2479 UINT message;
2480 INT hittest;
2481 EVENTMSG event;
2482 GUITHREADINFO info;
2483 MOUSEHOOKSTRUCT hook;
2484 BOOL eatMsg;
2486 /* find the window to dispatch this mouse message to */
2488 info.cbSize = sizeof(info);
2489 GetGUIThreadInfo( GetCurrentThreadId(), &info );
2490 if (info.hwndCapture)
2492 hittest = HTCLIENT;
2493 msg->hwnd = info.hwndCapture;
2495 else
2497 msg->hwnd = WINPOS_WindowFromPoint( msg->hwnd, msg->pt, &hittest );
2500 if (!msg->hwnd || !WIN_IsCurrentThread( msg->hwnd ))
2502 accept_hardware_message( hw_id, TRUE, msg->hwnd );
2503 return FALSE;
2506 /* FIXME: is this really the right place for this hook? */
2507 event.message = msg->message;
2508 event.time = msg->time;
2509 event.hwnd = msg->hwnd;
2510 event.paramL = msg->pt.x;
2511 event.paramH = msg->pt.y;
2512 HOOK_CallHooks( WH_JOURNALRECORD, HC_ACTION, 0, (LPARAM)&event, TRUE );
2514 if (!check_hwnd_filter( msg, hwnd_filter )) return FALSE;
2516 pt = msg->pt;
2517 message = msg->message;
2518 /* Note: windows has no concept of a non-client wheel message */
2519 if (message != WM_MOUSEWHEEL)
2521 if (hittest != HTCLIENT)
2523 message += WM_NCMOUSEMOVE - WM_MOUSEMOVE;
2524 msg->wParam = hittest;
2526 else
2528 /* coordinates don't get translated while tracking a menu */
2529 /* FIXME: should differentiate popups and top-level menus */
2530 if (!(info.flags & GUI_INMENUMODE))
2531 ScreenToClient( msg->hwnd, &pt );
2534 msg->lParam = MAKELONG( pt.x, pt.y );
2536 /* translate double clicks */
2538 if ((msg->message == WM_LBUTTONDOWN) ||
2539 (msg->message == WM_RBUTTONDOWN) ||
2540 (msg->message == WM_MBUTTONDOWN) ||
2541 (msg->message == WM_XBUTTONDOWN))
2543 BOOL update = remove;
2545 /* translate double clicks -
2546 * note that ...MOUSEMOVEs can slip in between
2547 * ...BUTTONDOWN and ...BUTTONDBLCLK messages */
2549 if ((info.flags & (GUI_INMENUMODE|GUI_INMOVESIZE)) ||
2550 hittest != HTCLIENT ||
2551 (GetClassLongA( msg->hwnd, GCL_STYLE ) & CS_DBLCLKS))
2553 if ((msg->message == clk_msg.message) &&
2554 (msg->hwnd == clk_msg.hwnd) &&
2555 (msg->wParam == clk_msg.wParam) &&
2556 (msg->time - clk_msg.time < GetDoubleClickTime()) &&
2557 (abs(msg->pt.x - clk_msg.pt.x) < GetSystemMetrics(SM_CXDOUBLECLK)/2) &&
2558 (abs(msg->pt.y - clk_msg.pt.y) < GetSystemMetrics(SM_CYDOUBLECLK)/2))
2560 message += (WM_LBUTTONDBLCLK - WM_LBUTTONDOWN);
2561 if (update)
2563 clk_msg.message = 0; /* clear the double click conditions */
2564 update = FALSE;
2568 if (message < first || message > last) return FALSE;
2569 /* update static double click conditions */
2570 if (update) clk_msg = *msg;
2572 else
2574 if (message < first || message > last) return FALSE;
2577 /* message is accepted now (but may still get dropped) */
2579 hook.pt = msg->pt;
2580 hook.hwnd = msg->hwnd;
2581 hook.wHitTestCode = hittest;
2582 hook.dwExtraInfo = extra_info;
2583 if (HOOK_CallHooks( WH_MOUSE, remove ? HC_ACTION : HC_NOREMOVE,
2584 message, (LPARAM)&hook, TRUE ))
2586 hook.pt = msg->pt;
2587 hook.hwnd = msg->hwnd;
2588 hook.wHitTestCode = hittest;
2589 hook.dwExtraInfo = extra_info;
2590 HOOK_CallHooks( WH_CBT, HCBT_CLICKSKIPPED, message, (LPARAM)&hook, TRUE );
2591 accept_hardware_message( hw_id, TRUE, 0 );
2592 return FALSE;
2595 if ((hittest == HTERROR) || (hittest == HTNOWHERE))
2597 SendMessageW( msg->hwnd, WM_SETCURSOR, (WPARAM)msg->hwnd,
2598 MAKELONG( hittest, msg->message ));
2599 accept_hardware_message( hw_id, TRUE, 0 );
2600 return FALSE;
2603 accept_hardware_message( hw_id, remove, 0 );
2605 if (!remove || info.hwndCapture)
2607 msg->message = message;
2608 return TRUE;
2611 eatMsg = FALSE;
2613 if ((msg->message == WM_LBUTTONDOWN) ||
2614 (msg->message == WM_RBUTTONDOWN) ||
2615 (msg->message == WM_MBUTTONDOWN) ||
2616 (msg->message == WM_XBUTTONDOWN))
2618 /* Send the WM_PARENTNOTIFY,
2619 * note that even for double/nonclient clicks
2620 * notification message is still WM_L/M/RBUTTONDOWN.
2622 send_parent_notify( msg->hwnd, msg->message, 0, msg->pt );
2624 /* Activate the window if needed */
2626 if (msg->hwnd != info.hwndActive)
2628 HWND hwndTop = msg->hwnd;
2629 while (hwndTop)
2631 if ((GetWindowLongW( hwndTop, GWL_STYLE ) & (WS_POPUP|WS_CHILD)) != WS_CHILD) break;
2632 hwndTop = GetParent( hwndTop );
2635 if (hwndTop && hwndTop != GetDesktopWindow())
2637 LONG ret = SendMessageW( msg->hwnd, WM_MOUSEACTIVATE, (WPARAM)hwndTop,
2638 MAKELONG( hittest, msg->message ) );
2639 switch(ret)
2641 case MA_NOACTIVATEANDEAT:
2642 eatMsg = TRUE;
2643 /* fall through */
2644 case MA_NOACTIVATE:
2645 break;
2646 case MA_ACTIVATEANDEAT:
2647 eatMsg = TRUE;
2648 /* fall through */
2649 case MA_ACTIVATE:
2650 case 0:
2651 if (!FOCUS_MouseActivate( hwndTop )) eatMsg = TRUE;
2652 break;
2653 default:
2654 WARN( "unknown WM_MOUSEACTIVATE code %d\n", ret );
2655 break;
2661 /* send the WM_SETCURSOR message */
2663 /* Windows sends the normal mouse message as the message parameter
2664 in the WM_SETCURSOR message even if it's non-client mouse message */
2665 SendMessageW( msg->hwnd, WM_SETCURSOR, (WPARAM)msg->hwnd, MAKELONG( hittest, msg->message ));
2667 msg->message = message;
2668 return !eatMsg;
2672 /***********************************************************************
2673 * process_hardware_message
2675 * Process a hardware message; return TRUE if message should be passed on to the app
2677 static BOOL process_hardware_message( MSG *msg, UINT hw_id, const struct hardware_msg_data *msg_data,
2678 HWND hwnd_filter, UINT first, UINT last, BOOL remove )
2680 if (msg->message == WM_INPUT)
2681 return process_rawinput_message( msg, msg_data );
2683 if (is_keyboard_message( msg->message ))
2684 return process_keyboard_message( msg, hw_id, hwnd_filter, first, last, remove );
2686 if (is_mouse_message( msg->message ))
2687 return process_mouse_message( msg, hw_id, msg_data->info, hwnd_filter, first, last, remove );
2689 ERR( "unknown message type %x\n", msg->message );
2690 return FALSE;
2694 /***********************************************************************
2695 * call_sendmsg_callback
2697 * Call the callback function of SendMessageCallback.
2699 static inline void call_sendmsg_callback( SENDASYNCPROC callback, HWND hwnd, UINT msg,
2700 ULONG_PTR data, LRESULT result )
2702 if (!callback) return;
2704 if (TRACE_ON(relay))
2705 DPRINTF( "%04x:Call message callback %p (hwnd=%p,msg=%s,data=%08lx,result=%08lx)\n",
2706 GetCurrentThreadId(), callback, hwnd, SPY_GetMsgName( msg, hwnd ),
2707 data, result );
2708 callback( hwnd, msg, data, result );
2709 if (TRACE_ON(relay))
2710 DPRINTF( "%04x:Ret message callback %p (hwnd=%p,msg=%s,data=%08lx,result=%08lx)\n",
2711 GetCurrentThreadId(), callback, hwnd, SPY_GetMsgName( msg, hwnd ),
2712 data, result );
2716 /***********************************************************************
2717 * peek_message
2719 * Peek for a message matching the given parameters. Return FALSE if none available.
2720 * All pending sent messages are processed before returning.
2722 static BOOL peek_message( MSG *msg, HWND hwnd, UINT first, UINT last, UINT flags, UINT changed_mask )
2724 LRESULT result;
2725 struct user_thread_info *thread_info = get_user_thread_info();
2726 struct received_message_info info, *old_info;
2727 unsigned int hw_id = 0; /* id of previous hardware message */
2728 void *buffer;
2729 size_t buffer_size = 256;
2731 if (!(buffer = HeapAlloc( GetProcessHeap(), 0, buffer_size ))) return FALSE;
2733 if (!first && !last) last = ~0;
2734 if (hwnd == HWND_BROADCAST) hwnd = HWND_TOPMOST;
2736 for (;;)
2738 NTSTATUS res;
2739 size_t size = 0;
2740 const message_data_t *msg_data = buffer;
2742 SERVER_START_REQ( get_message )
2744 req->flags = flags;
2745 req->get_win = wine_server_user_handle( hwnd );
2746 req->get_first = first;
2747 req->get_last = last;
2748 req->hw_id = hw_id;
2749 req->wake_mask = changed_mask & (QS_SENDMESSAGE | QS_SMRESULT);
2750 req->changed_mask = changed_mask;
2751 wine_server_set_reply( req, buffer, buffer_size );
2752 if (!(res = wine_server_call( req )))
2754 size = wine_server_reply_size( reply );
2755 info.type = reply->type;
2756 info.msg.hwnd = wine_server_ptr_handle( reply->win );
2757 info.msg.message = reply->msg;
2758 info.msg.wParam = reply->wparam;
2759 info.msg.lParam = reply->lparam;
2760 info.msg.time = reply->time;
2761 info.msg.pt.x = 0;
2762 info.msg.pt.y = 0;
2763 hw_id = 0;
2764 thread_info->active_hooks = reply->active_hooks;
2766 else buffer_size = reply->total;
2768 SERVER_END_REQ;
2770 if (res)
2772 HeapFree( GetProcessHeap(), 0, buffer );
2773 if (res != STATUS_BUFFER_OVERFLOW) return FALSE;
2774 if (!(buffer = HeapAlloc( GetProcessHeap(), 0, buffer_size ))) return FALSE;
2775 continue;
2778 TRACE( "got type %d msg %x (%s) hwnd %p wp %lx lp %lx\n",
2779 info.type, info.msg.message,
2780 (info.type == MSG_WINEVENT) ? "MSG_WINEVENT" : SPY_GetMsgName(info.msg.message, info.msg.hwnd),
2781 info.msg.hwnd, info.msg.wParam, info.msg.lParam );
2783 switch(info.type)
2785 case MSG_ASCII:
2786 case MSG_UNICODE:
2787 info.flags = ISMEX_SEND;
2788 break;
2789 case MSG_NOTIFY:
2790 info.flags = ISMEX_NOTIFY;
2791 break;
2792 case MSG_CALLBACK:
2793 info.flags = ISMEX_CALLBACK;
2794 break;
2795 case MSG_CALLBACK_RESULT:
2796 if (size >= sizeof(msg_data->callback))
2797 call_sendmsg_callback( wine_server_get_ptr(msg_data->callback.callback),
2798 info.msg.hwnd, info.msg.message,
2799 msg_data->callback.data, msg_data->callback.result );
2800 continue;
2801 case MSG_WINEVENT:
2802 if (size >= sizeof(msg_data->winevent))
2804 WINEVENTPROC hook_proc;
2806 hook_proc = wine_server_get_ptr( msg_data->winevent.hook_proc );
2807 size -= sizeof(msg_data->winevent);
2808 if (size)
2810 WCHAR module[MAX_PATH];
2812 size = min( size, (MAX_PATH - 1) * sizeof(WCHAR) );
2813 memcpy( module, &msg_data->winevent + 1, size );
2814 module[size / sizeof(WCHAR)] = 0;
2815 if (!(hook_proc = get_hook_proc( hook_proc, module )))
2817 ERR( "invalid winevent hook module name %s\n", debugstr_w(module) );
2818 continue;
2822 if (TRACE_ON(relay))
2823 DPRINTF( "%04x:Call winevent proc %p (hook=%04x,event=%x,hwnd=%p,object_id=%lx,child_id=%lx,tid=%04x,time=%x)\n",
2824 GetCurrentThreadId(), hook_proc,
2825 msg_data->winevent.hook, info.msg.message, info.msg.hwnd, info.msg.wParam,
2826 info.msg.lParam, msg_data->winevent.tid, info.msg.time);
2828 hook_proc( wine_server_ptr_handle( msg_data->winevent.hook ), info.msg.message,
2829 info.msg.hwnd, info.msg.wParam, info.msg.lParam,
2830 msg_data->winevent.tid, info.msg.time );
2832 if (TRACE_ON(relay))
2833 DPRINTF( "%04x:Ret winevent proc %p (hook=%04x,event=%x,hwnd=%p,object_id=%lx,child_id=%lx,tid=%04x,time=%x)\n",
2834 GetCurrentThreadId(), hook_proc,
2835 msg_data->winevent.hook, info.msg.message, info.msg.hwnd, info.msg.wParam,
2836 info.msg.lParam, msg_data->winevent.tid, info.msg.time);
2838 continue;
2839 case MSG_HOOK_LL:
2840 info.flags = ISMEX_SEND;
2841 result = 0;
2842 if (info.msg.message == WH_KEYBOARD_LL && size >= sizeof(msg_data->hardware))
2844 KBDLLHOOKSTRUCT hook;
2846 hook.vkCode = LOWORD( info.msg.lParam );
2847 hook.scanCode = HIWORD( info.msg.lParam );
2848 hook.flags = msg_data->hardware.flags;
2849 hook.time = info.msg.time;
2850 hook.dwExtraInfo = msg_data->hardware.info;
2851 TRACE( "calling keyboard LL hook vk %x scan %x flags %x time %u info %lx\n",
2852 hook.vkCode, hook.scanCode, hook.flags, hook.time, hook.dwExtraInfo );
2853 result = HOOK_CallHooks( WH_KEYBOARD_LL, HC_ACTION, info.msg.wParam, (LPARAM)&hook, TRUE );
2855 else if (info.msg.message == WH_MOUSE_LL && size >= sizeof(msg_data->hardware))
2857 MSLLHOOKSTRUCT hook;
2859 hook.pt.x = msg_data->hardware.x;
2860 hook.pt.y = msg_data->hardware.y;
2861 hook.mouseData = info.msg.lParam;
2862 hook.flags = msg_data->hardware.flags;
2863 hook.time = info.msg.time;
2864 hook.dwExtraInfo = msg_data->hardware.info;
2865 TRACE( "calling mouse LL hook pos %d,%d data %x flags %x time %u info %lx\n",
2866 hook.pt.x, hook.pt.y, hook.mouseData, hook.flags, hook.time, hook.dwExtraInfo );
2867 result = HOOK_CallHooks( WH_MOUSE_LL, HC_ACTION, info.msg.wParam, (LPARAM)&hook, TRUE );
2869 reply_message( &info, result, TRUE );
2870 continue;
2871 case MSG_OTHER_PROCESS:
2872 info.flags = ISMEX_SEND;
2873 if (!unpack_message( info.msg.hwnd, info.msg.message, &info.msg.wParam,
2874 &info.msg.lParam, &buffer, size ))
2876 /* ignore it */
2877 reply_message( &info, 0, TRUE );
2878 continue;
2880 break;
2881 case MSG_HARDWARE:
2882 if (size >= sizeof(msg_data->hardware))
2884 info.msg.pt.x = msg_data->hardware.x;
2885 info.msg.pt.y = msg_data->hardware.y;
2886 hw_id = msg_data->hardware.hw_id;
2887 if (!process_hardware_message( &info.msg, hw_id, &msg_data->hardware,
2888 hwnd, first, last, flags & PM_REMOVE ))
2890 TRACE("dropping msg %x\n", info.msg.message );
2891 continue; /* ignore it */
2893 *msg = info.msg;
2894 thread_info->GetMessagePosVal = MAKELONG( info.msg.pt.x, info.msg.pt.y );
2895 thread_info->GetMessageTimeVal = info.msg.time;
2896 thread_info->GetMessageExtraInfoVal = msg_data->hardware.info;
2897 HeapFree( GetProcessHeap(), 0, buffer );
2898 HOOK_CallHooks( WH_GETMESSAGE, HC_ACTION, flags & PM_REMOVE, (LPARAM)msg, TRUE );
2899 return TRUE;
2901 continue;
2902 case MSG_POSTED:
2903 if (info.msg.message & 0x80000000) /* internal message */
2905 if (flags & PM_REMOVE)
2907 handle_internal_message( info.msg.hwnd, info.msg.message,
2908 info.msg.wParam, info.msg.lParam );
2909 /* if this is a nested call return right away */
2910 if (first == info.msg.message && last == info.msg.message)
2912 HeapFree( GetProcessHeap(), 0, buffer );
2913 return FALSE;
2916 else
2917 peek_message( msg, info.msg.hwnd, info.msg.message,
2918 info.msg.message, flags | PM_REMOVE, changed_mask );
2919 continue;
2921 if (info.msg.message >= WM_DDE_FIRST && info.msg.message <= WM_DDE_LAST)
2923 if (!unpack_dde_message( info.msg.hwnd, info.msg.message, &info.msg.wParam,
2924 &info.msg.lParam, &buffer, size ))
2925 continue; /* ignore it */
2927 *msg = info.msg;
2928 msg->pt.x = (short)LOWORD( thread_info->GetMessagePosVal );
2929 msg->pt.y = (short)HIWORD( thread_info->GetMessagePosVal );
2930 thread_info->GetMessageTimeVal = info.msg.time;
2931 thread_info->GetMessageExtraInfoVal = 0;
2932 HeapFree( GetProcessHeap(), 0, buffer );
2933 HOOK_CallHooks( WH_GETMESSAGE, HC_ACTION, flags & PM_REMOVE, (LPARAM)msg, TRUE );
2934 return TRUE;
2937 /* if we get here, we have a sent message; call the window procedure */
2938 old_info = thread_info->receive_info;
2939 thread_info->receive_info = &info;
2940 result = call_window_proc( info.msg.hwnd, info.msg.message, info.msg.wParam,
2941 info.msg.lParam, (info.type != MSG_ASCII), FALSE,
2942 WMCHAR_MAP_RECVMESSAGE );
2943 reply_message( &info, result, TRUE );
2944 thread_info->receive_info = old_info;
2946 /* if some PM_QS* flags were specified, only handle sent messages from now on */
2947 if (HIWORD(flags) && !changed_mask) flags = PM_QS_SENDMESSAGE | LOWORD(flags);
2952 /***********************************************************************
2953 * process_sent_messages
2955 * Process all pending sent messages.
2957 static inline void process_sent_messages(void)
2959 MSG msg;
2960 peek_message( &msg, 0, 0, 0, PM_REMOVE | PM_QS_SENDMESSAGE, 0 );
2964 /***********************************************************************
2965 * get_server_queue_handle
2967 * Get a handle to the server message queue for the current thread.
2969 static HANDLE get_server_queue_handle(void)
2971 struct user_thread_info *thread_info = get_user_thread_info();
2972 HANDLE ret;
2974 if (!(ret = thread_info->server_queue))
2976 SERVER_START_REQ( get_msg_queue )
2978 wine_server_call( req );
2979 ret = wine_server_ptr_handle( reply->handle );
2981 SERVER_END_REQ;
2982 thread_info->server_queue = ret;
2983 if (!ret) ERR( "Cannot get server thread queue\n" );
2985 return ret;
2989 /***********************************************************************
2990 * wait_message_reply
2992 * Wait until a sent message gets replied to.
2994 static void wait_message_reply( UINT flags )
2996 HANDLE server_queue = get_server_queue_handle();
2998 for (;;)
3000 unsigned int wake_bits = 0;
3002 SERVER_START_REQ( set_queue_mask )
3004 req->wake_mask = QS_SMRESULT | ((flags & SMTO_BLOCK) ? 0 : QS_SENDMESSAGE);
3005 req->changed_mask = req->wake_mask;
3006 req->skip_wait = 1;
3007 if (!wine_server_call( req ))
3008 wake_bits = reply->wake_bits;
3010 SERVER_END_REQ;
3012 if (wake_bits & QS_SMRESULT) return; /* got a result */
3013 if (wake_bits & QS_SENDMESSAGE)
3015 /* Process the sent message immediately */
3016 process_sent_messages();
3017 continue;
3020 wow_handlers.wait_message( 1, &server_queue, INFINITE, QS_SENDMESSAGE, 0 );
3024 /***********************************************************************
3025 * put_message_in_queue
3027 * Put a sent message into the destination queue.
3028 * For inter-process message, reply_size is set to expected size of reply data.
3030 static BOOL put_message_in_queue( const struct send_message_info *info, size_t *reply_size )
3032 struct packed_message data;
3033 message_data_t msg_data;
3034 unsigned int res;
3035 int i;
3036 timeout_t timeout = TIMEOUT_INFINITE;
3038 /* Check for INFINITE timeout for compatibility with Win9x,
3039 * although Windows >= NT does not do so
3041 if (info->type != MSG_NOTIFY &&
3042 info->type != MSG_CALLBACK &&
3043 info->type != MSG_POSTED &&
3044 info->timeout &&
3045 info->timeout != INFINITE)
3047 /* timeout is signed despite the prototype */
3048 timeout = (timeout_t)max( 0, (int)info->timeout ) * -10000;
3051 memset( &data, 0, sizeof(data) );
3052 if (info->type == MSG_OTHER_PROCESS)
3054 *reply_size = pack_message( info->hwnd, info->msg, info->wparam, info->lparam, &data );
3055 if (data.count == -1)
3057 WARN( "cannot pack message %x\n", info->msg );
3058 return FALSE;
3061 else if (info->type == MSG_CALLBACK)
3063 msg_data.callback.callback = wine_server_client_ptr( info->callback );
3064 msg_data.callback.data = info->data;
3065 msg_data.callback.result = 0;
3066 data.data[0] = &msg_data;
3067 data.size[0] = sizeof(msg_data.callback);
3068 data.count = 1;
3070 else if (info->type == MSG_POSTED && info->msg >= WM_DDE_FIRST && info->msg <= WM_DDE_LAST)
3072 return post_dde_message( &data, info );
3075 SERVER_START_REQ( send_message )
3077 req->id = info->dest_tid;
3078 req->type = info->type;
3079 req->flags = 0;
3080 req->win = wine_server_user_handle( info->hwnd );
3081 req->msg = info->msg;
3082 req->wparam = info->wparam;
3083 req->lparam = info->lparam;
3084 req->timeout = timeout;
3086 if (info->flags & SMTO_ABORTIFHUNG) req->flags |= SEND_MSG_ABORT_IF_HUNG;
3087 for (i = 0; i < data.count; i++) wine_server_add_data( req, data.data[i], data.size[i] );
3088 if ((res = wine_server_call( req )))
3090 if (res == STATUS_INVALID_PARAMETER)
3091 /* FIXME: find a STATUS_ value for this one */
3092 SetLastError( ERROR_INVALID_THREAD_ID );
3093 else
3094 SetLastError( RtlNtStatusToDosError(res) );
3097 SERVER_END_REQ;
3098 return !res;
3102 /***********************************************************************
3103 * retrieve_reply
3105 * Retrieve a message reply from the server.
3107 static LRESULT retrieve_reply( const struct send_message_info *info,
3108 size_t reply_size, LRESULT *result )
3110 NTSTATUS status;
3111 void *reply_data = NULL;
3113 if (reply_size)
3115 if (!(reply_data = HeapAlloc( GetProcessHeap(), 0, reply_size )))
3117 WARN( "no memory for reply, will be truncated\n" );
3118 reply_size = 0;
3121 SERVER_START_REQ( get_message_reply )
3123 req->cancel = 1;
3124 if (reply_size) wine_server_set_reply( req, reply_data, reply_size );
3125 if (!(status = wine_server_call( req ))) *result = reply->result;
3126 reply_size = wine_server_reply_size( reply );
3128 SERVER_END_REQ;
3129 if (!status && reply_size)
3130 unpack_reply( info->hwnd, info->msg, info->wparam, info->lparam, reply_data, reply_size );
3132 HeapFree( GetProcessHeap(), 0, reply_data );
3134 TRACE( "hwnd %p msg %x (%s) wp %lx lp %lx got reply %lx (err=%d)\n",
3135 info->hwnd, info->msg, SPY_GetMsgName(info->msg, info->hwnd), info->wparam,
3136 info->lparam, *result, status );
3138 /* MSDN states that last error is 0 on timeout, but at least NT4 returns ERROR_TIMEOUT */
3139 if (status) SetLastError( RtlNtStatusToDosError(status) );
3140 return !status;
3144 /***********************************************************************
3145 * send_inter_thread_message
3147 static LRESULT send_inter_thread_message( const struct send_message_info *info, LRESULT *res_ptr )
3149 size_t reply_size = 0;
3151 TRACE( "hwnd %p msg %x (%s) wp %lx lp %lx\n",
3152 info->hwnd, info->msg, SPY_GetMsgName(info->msg, info->hwnd), info->wparam, info->lparam );
3154 USER_CheckNotLock();
3156 if (!put_message_in_queue( info, &reply_size )) return 0;
3158 /* there's no reply to wait for on notify/callback messages */
3159 if (info->type == MSG_NOTIFY || info->type == MSG_CALLBACK) return 1;
3161 wait_message_reply( info->flags );
3162 return retrieve_reply( info, reply_size, res_ptr );
3166 /***********************************************************************
3167 * send_inter_thread_callback
3169 static LRESULT send_inter_thread_callback( HWND hwnd, UINT msg, WPARAM wp, LPARAM lp,
3170 LRESULT *result, void *arg )
3172 struct send_message_info *info = arg;
3173 info->hwnd = hwnd;
3174 info->msg = msg;
3175 info->wparam = wp;
3176 info->lparam = lp;
3177 return send_inter_thread_message( info, result );
3181 /***********************************************************************
3182 * send_message
3184 * Backend implementation of the various SendMessage functions.
3186 static BOOL send_message( struct send_message_info *info, DWORD_PTR *res_ptr, BOOL unicode )
3188 DWORD dest_pid;
3189 BOOL ret;
3190 LRESULT result;
3192 if (is_broadcast(info->hwnd))
3194 EnumWindows( broadcast_message_callback, (LPARAM)info );
3195 if (res_ptr) *res_ptr = 1;
3196 return TRUE;
3199 if (!(info->dest_tid = GetWindowThreadProcessId( info->hwnd, &dest_pid ))) return FALSE;
3201 if (USER_IsExitingThread( info->dest_tid )) return FALSE;
3203 SPY_EnterMessage( SPY_SENDMESSAGE, info->hwnd, info->msg, info->wparam, info->lparam );
3205 if (info->dest_tid == GetCurrentThreadId())
3207 result = call_window_proc( info->hwnd, info->msg, info->wparam, info->lparam,
3208 unicode, TRUE, info->wm_char );
3209 if (info->type == MSG_CALLBACK)
3210 call_sendmsg_callback( info->callback, info->hwnd, info->msg, info->data, result );
3211 ret = TRUE;
3213 else
3215 if (dest_pid != GetCurrentProcessId() && (info->type == MSG_ASCII || info->type == MSG_UNICODE))
3216 info->type = MSG_OTHER_PROCESS;
3218 /* MSG_ASCII can be sent unconverted except for WM_CHAR; everything else needs to be Unicode */
3219 if (!unicode && is_unicode_message( info->msg ) &&
3220 (info->type != MSG_ASCII || info->msg == WM_CHAR))
3221 ret = WINPROC_CallProcAtoW( send_inter_thread_callback, info->hwnd, info->msg,
3222 info->wparam, info->lparam, &result, info, info->wm_char );
3223 else
3224 ret = send_inter_thread_message( info, &result );
3227 SPY_ExitMessage( SPY_RESULT_OK, info->hwnd, info->msg, result, info->wparam, info->lparam );
3228 if (ret && res_ptr) *res_ptr = result;
3229 return ret;
3233 /***********************************************************************
3234 * send_hardware_message
3236 NTSTATUS send_hardware_message( HWND hwnd, const INPUT *input, UINT flags )
3238 struct user_thread_info *thread_info = get_user_thread_info();
3239 struct send_message_info info;
3240 int prev_x, prev_y, new_x, new_y;
3241 NTSTATUS ret;
3242 BOOL wait;
3244 info.type = MSG_HARDWARE;
3245 info.dest_tid = 0;
3246 info.hwnd = hwnd;
3247 info.flags = 0;
3248 info.timeout = 0;
3250 SERVER_START_REQ( send_hardware_message )
3252 req->win = wine_server_user_handle( hwnd );
3253 req->flags = flags;
3254 req->input.type = input->type;
3255 switch (input->type)
3257 case INPUT_MOUSE:
3258 req->input.mouse.x = input->u.mi.dx;
3259 req->input.mouse.y = input->u.mi.dy;
3260 req->input.mouse.data = input->u.mi.mouseData;
3261 req->input.mouse.flags = input->u.mi.dwFlags;
3262 req->input.mouse.time = input->u.mi.time;
3263 req->input.mouse.info = input->u.mi.dwExtraInfo;
3264 break;
3265 case INPUT_KEYBOARD:
3266 req->input.kbd.vkey = input->u.ki.wVk;
3267 req->input.kbd.scan = input->u.ki.wScan;
3268 req->input.kbd.flags = input->u.ki.dwFlags;
3269 req->input.kbd.time = input->u.ki.time;
3270 req->input.kbd.info = input->u.ki.dwExtraInfo;
3271 break;
3272 case INPUT_HARDWARE:
3273 req->input.hw.msg = input->u.hi.uMsg;
3274 req->input.hw.lparam = MAKELONG( input->u.hi.wParamL, input->u.hi.wParamH );
3275 break;
3277 if (thread_info->key_state) wine_server_set_reply( req, thread_info->key_state, 256 );
3278 ret = wine_server_call( req );
3279 wait = reply->wait;
3280 prev_x = reply->prev_x;
3281 prev_y = reply->prev_y;
3282 new_x = reply->new_x;
3283 new_y = reply->new_y;
3285 SERVER_END_REQ;
3287 if (!ret)
3289 if (thread_info->key_state) thread_info->key_state_time = GetTickCount();
3290 if ((flags & SEND_HWMSG_INJECTED) && (prev_x != new_x || prev_y != new_y))
3291 USER_Driver->pSetCursorPos( new_x, new_y );
3294 if (wait)
3296 LRESULT ignored;
3297 wait_message_reply( 0 );
3298 retrieve_reply( &info, 0, &ignored );
3300 return ret;
3304 /***********************************************************************
3305 * MSG_SendInternalMessageTimeout
3307 * Same as SendMessageTimeoutW but sends the message to a specific thread
3308 * without requiring a window handle. Only works for internal Wine messages.
3310 LRESULT MSG_SendInternalMessageTimeout( DWORD dest_pid, DWORD dest_tid,
3311 UINT msg, WPARAM wparam, LPARAM lparam,
3312 UINT flags, UINT timeout, PDWORD_PTR res_ptr )
3314 struct send_message_info info;
3315 LRESULT ret, result;
3317 assert( msg & 0x80000000 ); /* must be an internal Wine message */
3319 info.type = MSG_UNICODE;
3320 info.dest_tid = dest_tid;
3321 info.hwnd = 0;
3322 info.msg = msg;
3323 info.wparam = wparam;
3324 info.lparam = lparam;
3325 info.flags = flags;
3326 info.timeout = timeout;
3328 if (USER_IsExitingThread( dest_tid )) return 0;
3330 if (dest_tid == GetCurrentThreadId())
3332 result = handle_internal_message( 0, msg, wparam, lparam );
3333 ret = 1;
3335 else
3337 if (dest_pid != GetCurrentProcessId()) info.type = MSG_OTHER_PROCESS;
3338 ret = send_inter_thread_message( &info, &result );
3340 if (ret && res_ptr) *res_ptr = result;
3341 return ret;
3345 /***********************************************************************
3346 * SendMessageTimeoutW (USER32.@)
3348 LRESULT WINAPI SendMessageTimeoutW( HWND hwnd, UINT msg, WPARAM wparam, LPARAM lparam,
3349 UINT flags, UINT timeout, PDWORD_PTR res_ptr )
3351 struct send_message_info info;
3353 info.type = MSG_UNICODE;
3354 info.hwnd = hwnd;
3355 info.msg = msg;
3356 info.wparam = wparam;
3357 info.lparam = lparam;
3358 info.flags = flags;
3359 info.timeout = timeout;
3361 return send_message( &info, res_ptr, TRUE );
3364 /***********************************************************************
3365 * SendMessageTimeoutA (USER32.@)
3367 LRESULT WINAPI SendMessageTimeoutA( HWND hwnd, UINT msg, WPARAM wparam, LPARAM lparam,
3368 UINT flags, UINT timeout, PDWORD_PTR res_ptr )
3370 struct send_message_info info;
3372 info.type = MSG_ASCII;
3373 info.hwnd = hwnd;
3374 info.msg = msg;
3375 info.wparam = wparam;
3376 info.lparam = lparam;
3377 info.flags = flags;
3378 info.timeout = timeout;
3379 info.wm_char = WMCHAR_MAP_SENDMESSAGETIMEOUT;
3381 return send_message( &info, res_ptr, FALSE );
3385 /***********************************************************************
3386 * SendMessageW (USER32.@)
3388 LRESULT WINAPI SendMessageW( HWND hwnd, UINT msg, WPARAM wparam, LPARAM lparam )
3390 DWORD_PTR res = 0;
3391 struct send_message_info info;
3393 info.type = MSG_UNICODE;
3394 info.hwnd = hwnd;
3395 info.msg = msg;
3396 info.wparam = wparam;
3397 info.lparam = lparam;
3398 info.flags = SMTO_NORMAL;
3399 info.timeout = 0;
3401 send_message( &info, &res, TRUE );
3402 return res;
3406 /***********************************************************************
3407 * SendMessageA (USER32.@)
3409 LRESULT WINAPI SendMessageA( HWND hwnd, UINT msg, WPARAM wparam, LPARAM lparam )
3411 DWORD_PTR res = 0;
3412 struct send_message_info info;
3414 info.type = MSG_ASCII;
3415 info.hwnd = hwnd;
3416 info.msg = msg;
3417 info.wparam = wparam;
3418 info.lparam = lparam;
3419 info.flags = SMTO_NORMAL;
3420 info.timeout = 0;
3421 info.wm_char = WMCHAR_MAP_SENDMESSAGE;
3423 send_message( &info, &res, FALSE );
3424 return res;
3428 /***********************************************************************
3429 * SendNotifyMessageA (USER32.@)
3431 BOOL WINAPI SendNotifyMessageA( HWND hwnd, UINT msg, WPARAM wparam, LPARAM lparam )
3433 struct send_message_info info;
3435 if (is_pointer_message(msg))
3437 SetLastError( ERROR_MESSAGE_SYNC_ONLY );
3438 return FALSE;
3441 info.type = MSG_NOTIFY;
3442 info.hwnd = hwnd;
3443 info.msg = msg;
3444 info.wparam = wparam;
3445 info.lparam = lparam;
3446 info.flags = 0;
3447 info.wm_char = WMCHAR_MAP_SENDMESSAGETIMEOUT;
3449 return send_message( &info, NULL, FALSE );
3453 /***********************************************************************
3454 * SendNotifyMessageW (USER32.@)
3456 BOOL WINAPI SendNotifyMessageW( HWND hwnd, UINT msg, WPARAM wparam, LPARAM lparam )
3458 struct send_message_info info;
3460 if (is_pointer_message(msg))
3462 SetLastError( ERROR_MESSAGE_SYNC_ONLY );
3463 return FALSE;
3466 info.type = MSG_NOTIFY;
3467 info.hwnd = hwnd;
3468 info.msg = msg;
3469 info.wparam = wparam;
3470 info.lparam = lparam;
3471 info.flags = 0;
3473 return send_message( &info, NULL, TRUE );
3477 /***********************************************************************
3478 * SendMessageCallbackA (USER32.@)
3480 BOOL WINAPI SendMessageCallbackA( HWND hwnd, UINT msg, WPARAM wparam, LPARAM lparam,
3481 SENDASYNCPROC callback, ULONG_PTR data )
3483 struct send_message_info info;
3485 if (is_pointer_message(msg))
3487 SetLastError( ERROR_MESSAGE_SYNC_ONLY );
3488 return FALSE;
3491 info.type = MSG_CALLBACK;
3492 info.hwnd = hwnd;
3493 info.msg = msg;
3494 info.wparam = wparam;
3495 info.lparam = lparam;
3496 info.callback = callback;
3497 info.data = data;
3498 info.flags = 0;
3499 info.wm_char = WMCHAR_MAP_SENDMESSAGETIMEOUT;
3501 return send_message( &info, NULL, FALSE );
3505 /***********************************************************************
3506 * SendMessageCallbackW (USER32.@)
3508 BOOL WINAPI SendMessageCallbackW( HWND hwnd, UINT msg, WPARAM wparam, LPARAM lparam,
3509 SENDASYNCPROC callback, ULONG_PTR data )
3511 struct send_message_info info;
3513 if (is_pointer_message(msg))
3515 SetLastError( ERROR_MESSAGE_SYNC_ONLY );
3516 return FALSE;
3519 info.type = MSG_CALLBACK;
3520 info.hwnd = hwnd;
3521 info.msg = msg;
3522 info.wparam = wparam;
3523 info.lparam = lparam;
3524 info.callback = callback;
3525 info.data = data;
3526 info.flags = 0;
3528 return send_message( &info, NULL, TRUE );
3532 /***********************************************************************
3533 * ReplyMessage (USER32.@)
3535 BOOL WINAPI ReplyMessage( LRESULT result )
3537 struct received_message_info *info = get_user_thread_info()->receive_info;
3539 if (!info) return FALSE;
3540 reply_message( info, result, FALSE );
3541 return TRUE;
3545 /***********************************************************************
3546 * InSendMessage (USER32.@)
3548 BOOL WINAPI InSendMessage(void)
3550 return (InSendMessageEx(NULL) & (ISMEX_SEND|ISMEX_REPLIED)) == ISMEX_SEND;
3554 /***********************************************************************
3555 * InSendMessageEx (USER32.@)
3557 DWORD WINAPI InSendMessageEx( LPVOID reserved )
3559 struct received_message_info *info = get_user_thread_info()->receive_info;
3561 if (info) return info->flags;
3562 return ISMEX_NOSEND;
3566 /***********************************************************************
3567 * PostMessageA (USER32.@)
3569 BOOL WINAPI PostMessageA( HWND hwnd, UINT msg, WPARAM wparam, LPARAM lparam )
3571 if (!map_wparam_AtoW( msg, &wparam, WMCHAR_MAP_POSTMESSAGE )) return TRUE;
3572 return PostMessageW( hwnd, msg, wparam, lparam );
3576 /***********************************************************************
3577 * PostMessageW (USER32.@)
3579 BOOL WINAPI PostMessageW( HWND hwnd, UINT msg, WPARAM wparam, LPARAM lparam )
3581 struct send_message_info info;
3583 if (is_pointer_message( msg ))
3585 SetLastError( ERROR_MESSAGE_SYNC_ONLY );
3586 return FALSE;
3589 TRACE( "hwnd %p msg %x (%s) wp %lx lp %lx\n",
3590 hwnd, msg, SPY_GetMsgName(msg, hwnd), wparam, lparam );
3592 info.type = MSG_POSTED;
3593 info.hwnd = hwnd;
3594 info.msg = msg;
3595 info.wparam = wparam;
3596 info.lparam = lparam;
3597 info.flags = 0;
3599 if (is_broadcast(hwnd))
3601 EnumWindows( broadcast_message_callback, (LPARAM)&info );
3602 return TRUE;
3605 if (!hwnd) return PostThreadMessageW( GetCurrentThreadId(), msg, wparam, lparam );
3607 if (!(info.dest_tid = GetWindowThreadProcessId( hwnd, NULL ))) return FALSE;
3609 if (USER_IsExitingThread( info.dest_tid )) return TRUE;
3611 return put_message_in_queue( &info, NULL );
3615 /**********************************************************************
3616 * PostThreadMessageA (USER32.@)
3618 BOOL WINAPI PostThreadMessageA( DWORD thread, UINT msg, WPARAM wparam, LPARAM lparam )
3620 if (!map_wparam_AtoW( msg, &wparam, WMCHAR_MAP_POSTMESSAGE )) return TRUE;
3621 return PostThreadMessageW( thread, msg, wparam, lparam );
3625 /**********************************************************************
3626 * PostThreadMessageW (USER32.@)
3628 BOOL WINAPI PostThreadMessageW( DWORD thread, UINT msg, WPARAM wparam, LPARAM lparam )
3630 struct send_message_info info;
3632 if (is_pointer_message( msg ))
3634 SetLastError( ERROR_MESSAGE_SYNC_ONLY );
3635 return FALSE;
3637 if (USER_IsExitingThread( thread )) return TRUE;
3639 info.type = MSG_POSTED;
3640 info.dest_tid = thread;
3641 info.hwnd = 0;
3642 info.msg = msg;
3643 info.wparam = wparam;
3644 info.lparam = lparam;
3645 info.flags = 0;
3646 return put_message_in_queue( &info, NULL );
3650 /***********************************************************************
3651 * PostQuitMessage (USER32.@)
3653 * Posts a quit message to the current thread's message queue.
3655 * PARAMS
3656 * exit_code [I] Exit code to return from message loop.
3658 * RETURNS
3659 * Nothing.
3661 * NOTES
3662 * This function is not the same as calling:
3663 *|PostThreadMessage(GetCurrentThreadId(), WM_QUIT, exit_code, 0);
3664 * It instead sets a flag in the message queue that signals it to generate
3665 * a WM_QUIT message when there are no other pending sent or posted messages
3666 * in the queue.
3668 void WINAPI PostQuitMessage( INT exit_code )
3670 SERVER_START_REQ( post_quit_message )
3672 req->exit_code = exit_code;
3673 wine_server_call( req );
3675 SERVER_END_REQ;
3678 /* check for driver events if we detect that the app is not properly consuming messages */
3679 static inline void check_for_driver_events(void)
3681 if (get_user_thread_info()->message_count > 200)
3683 flush_window_surfaces( FALSE );
3684 USER_Driver->pMsgWaitForMultipleObjectsEx( 0, NULL, 0, QS_ALLINPUT, 0 );
3686 else get_user_thread_info()->message_count++;
3689 /***********************************************************************
3690 * PeekMessageW (USER32.@)
3692 BOOL WINAPI DECLSPEC_HOTPATCH PeekMessageW( MSG *msg_out, HWND hwnd, UINT first, UINT last, UINT flags )
3694 MSG msg;
3696 USER_CheckNotLock();
3697 check_for_driver_events();
3699 if (!peek_message( &msg, hwnd, first, last, flags, 0 ))
3701 DWORD ret;
3703 flush_window_surfaces( TRUE );
3704 ret = wow_handlers.wait_message( 0, NULL, 0, QS_ALLINPUT, 0 );
3705 /* if we received driver events, check again for a pending message */
3706 if (ret == WAIT_TIMEOUT || !peek_message( &msg, hwnd, first, last, flags, 0 )) return FALSE;
3709 /* copy back our internal safe copy of message data to msg_out.
3710 * msg_out is a variable from the *program*, so it can't be used
3711 * internally as it can get "corrupted" by our use of SendMessage()
3712 * (back to the program) inside the message handling itself. */
3713 if (!msg_out)
3715 SetLastError( ERROR_NOACCESS );
3716 return FALSE;
3718 *msg_out = msg;
3719 return TRUE;
3723 /***********************************************************************
3724 * PeekMessageA (USER32.@)
3726 BOOL WINAPI DECLSPEC_HOTPATCH PeekMessageA( MSG *msg, HWND hwnd, UINT first, UINT last, UINT flags )
3728 if (get_pending_wmchar( msg, first, last, (flags & PM_REMOVE) )) return TRUE;
3729 if (!PeekMessageW( msg, hwnd, first, last, flags )) return FALSE;
3730 map_wparam_WtoA( msg, (flags & PM_REMOVE) );
3731 return TRUE;
3735 /***********************************************************************
3736 * GetMessageW (USER32.@)
3738 BOOL WINAPI DECLSPEC_HOTPATCH GetMessageW( MSG *msg, HWND hwnd, UINT first, UINT last )
3740 HANDLE server_queue = get_server_queue_handle();
3741 unsigned int mask = QS_POSTMESSAGE | QS_SENDMESSAGE; /* Always selected */
3743 USER_CheckNotLock();
3744 check_for_driver_events();
3746 if (first || last)
3748 if ((first <= WM_KEYLAST) && (last >= WM_KEYFIRST)) mask |= QS_KEY;
3749 if ( ((first <= WM_MOUSELAST) && (last >= WM_MOUSEFIRST)) ||
3750 ((first <= WM_NCMOUSELAST) && (last >= WM_NCMOUSEFIRST)) ) mask |= QS_MOUSE;
3751 if ((first <= WM_TIMER) && (last >= WM_TIMER)) mask |= QS_TIMER;
3752 if ((first <= WM_SYSTIMER) && (last >= WM_SYSTIMER)) mask |= QS_TIMER;
3753 if ((first <= WM_PAINT) && (last >= WM_PAINT)) mask |= QS_PAINT;
3755 else mask = QS_ALLINPUT;
3757 while (!peek_message( msg, hwnd, first, last, PM_REMOVE | (mask << 16), mask ))
3759 flush_window_surfaces( TRUE );
3760 wow_handlers.wait_message( 1, &server_queue, INFINITE, mask, 0 );
3763 return (msg->message != WM_QUIT);
3767 /***********************************************************************
3768 * GetMessageA (USER32.@)
3770 BOOL WINAPI DECLSPEC_HOTPATCH GetMessageA( MSG *msg, HWND hwnd, UINT first, UINT last )
3772 if (get_pending_wmchar( msg, first, last, TRUE )) return TRUE;
3773 GetMessageW( msg, hwnd, first, last );
3774 map_wparam_WtoA( msg, TRUE );
3775 return (msg->message != WM_QUIT);
3779 /***********************************************************************
3780 * IsDialogMessageA (USER32.@)
3781 * IsDialogMessage (USER32.@)
3783 BOOL WINAPI IsDialogMessageA( HWND hwndDlg, LPMSG pmsg )
3785 MSG msg = *pmsg;
3786 map_wparam_AtoW( msg.message, &msg.wParam, WMCHAR_MAP_NOMAPPING );
3787 return IsDialogMessageW( hwndDlg, &msg );
3791 /***********************************************************************
3792 * TranslateMessage (USER32.@)
3794 * Implementation of TranslateMessage.
3796 * TranslateMessage translates virtual-key messages into character-messages,
3797 * as follows :
3798 * WM_KEYDOWN/WM_KEYUP combinations produce a WM_CHAR or WM_DEADCHAR message.
3799 * ditto replacing WM_* with WM_SYS*
3800 * This produces WM_CHAR messages only for keys mapped to ASCII characters
3801 * by the keyboard driver.
3803 * If the message is WM_KEYDOWN, WM_KEYUP, WM_SYSKEYDOWN, or WM_SYSKEYUP, the
3804 * return value is nonzero, regardless of the translation.
3807 BOOL WINAPI TranslateMessage( const MSG *msg )
3809 UINT message;
3810 WCHAR wp[8];
3811 BYTE state[256];
3812 INT len;
3814 if (msg->message < WM_KEYFIRST || msg->message > WM_KEYLAST) return FALSE;
3815 if (msg->message != WM_KEYDOWN && msg->message != WM_SYSKEYDOWN) return TRUE;
3817 TRACE_(key)("Translating key %s (%04lX), scancode %04x\n",
3818 SPY_GetVKeyName(msg->wParam), msg->wParam, HIWORD(msg->lParam));
3820 switch (msg->wParam)
3822 case VK_PACKET:
3823 message = (msg->message == WM_KEYDOWN) ? WM_CHAR : WM_SYSCHAR;
3824 TRACE_(key)("PostMessageW(%p,%s,%04x,%08x)\n",
3825 msg->hwnd, SPY_GetMsgName(message, msg->hwnd), HIWORD(msg->lParam), LOWORD(msg->lParam));
3826 PostMessageW( msg->hwnd, message, HIWORD(msg->lParam), LOWORD(msg->lParam));
3827 return TRUE;
3829 case VK_PROCESSKEY:
3830 return ImmTranslateMessage(msg->hwnd, msg->message, msg->wParam, msg->lParam);
3833 GetKeyboardState( state );
3834 len = ToUnicode(msg->wParam, HIWORD(msg->lParam), state, wp, sizeof(wp)/sizeof(WCHAR), 0);
3835 if (len == -1)
3837 message = (msg->message == WM_KEYDOWN) ? WM_DEADCHAR : WM_SYSDEADCHAR;
3838 TRACE_(key)("-1 -> PostMessageW(%p,%s,%04x,%08lx)\n",
3839 msg->hwnd, SPY_GetMsgName(message, msg->hwnd), wp[0], msg->lParam);
3840 PostMessageW( msg->hwnd, message, wp[0], msg->lParam );
3842 else if (len > 0)
3844 INT i;
3846 message = (msg->message == WM_KEYDOWN) ? WM_CHAR : WM_SYSCHAR;
3847 TRACE_(key)("%d -> PostMessageW(%p,%s,<x>,%08lx) for <x> in %s\n", len, msg->hwnd,
3848 SPY_GetMsgName(message, msg->hwnd), msg->lParam, debugstr_wn(wp, len));
3849 for (i = 0; i < len; i++)
3850 PostMessageW( msg->hwnd, message, wp[i], msg->lParam );
3852 return TRUE;
3856 /***********************************************************************
3857 * DispatchMessageA (USER32.@)
3859 * See DispatchMessageW.
3861 LRESULT WINAPI DECLSPEC_HOTPATCH DispatchMessageA( const MSG* msg )
3863 LRESULT retval;
3865 /* Process timer messages */
3866 if ((msg->message == WM_TIMER) || (msg->message == WM_SYSTIMER))
3868 if (msg->lParam)
3870 __TRY
3872 retval = CallWindowProcA( (WNDPROC)msg->lParam, msg->hwnd,
3873 msg->message, msg->wParam, GetTickCount() );
3875 __EXCEPT_PAGE_FAULT
3877 retval = 0;
3879 __ENDTRY
3880 return retval;
3883 if (!msg->hwnd) return 0;
3885 SPY_EnterMessage( SPY_DISPATCHMESSAGE, msg->hwnd, msg->message,
3886 msg->wParam, msg->lParam );
3888 if (!WINPROC_call_window( msg->hwnd, msg->message, msg->wParam, msg->lParam,
3889 &retval, FALSE, WMCHAR_MAP_DISPATCHMESSAGE ))
3891 if (!IsWindow( msg->hwnd )) SetLastError( ERROR_INVALID_WINDOW_HANDLE );
3892 else SetLastError( ERROR_MESSAGE_SYNC_ONLY );
3893 retval = 0;
3896 SPY_ExitMessage( SPY_RESULT_OK, msg->hwnd, msg->message, retval,
3897 msg->wParam, msg->lParam );
3899 if (msg->message == WM_PAINT)
3901 /* send a WM_NCPAINT and WM_ERASEBKGND if the non-client area is still invalid */
3902 HRGN hrgn = CreateRectRgn( 0, 0, 0, 0 );
3903 GetUpdateRgn( msg->hwnd, hrgn, TRUE );
3904 DeleteObject( hrgn );
3906 return retval;
3910 /***********************************************************************
3911 * DispatchMessageW (USER32.@) Process a message
3913 * Process the message specified in the structure *_msg_.
3915 * If the lpMsg parameter points to a WM_TIMER message and the
3916 * parameter of the WM_TIMER message is not NULL, the lParam parameter
3917 * points to the function that is called instead of the window
3918 * procedure. The function stored in lParam (timer callback) is protected
3919 * from causing page-faults.
3921 * The message must be valid.
3923 * RETURNS
3925 * DispatchMessage() returns the result of the window procedure invoked.
3927 * CONFORMANCE
3929 * ECMA-234, Win32
3932 LRESULT WINAPI DECLSPEC_HOTPATCH DispatchMessageW( const MSG* msg )
3934 LRESULT retval;
3936 /* Process timer messages */
3937 if ((msg->message == WM_TIMER) || (msg->message == WM_SYSTIMER))
3939 if (msg->lParam)
3941 __TRY
3943 retval = CallWindowProcW( (WNDPROC)msg->lParam, msg->hwnd,
3944 msg->message, msg->wParam, GetTickCount() );
3946 __EXCEPT_PAGE_FAULT
3948 retval = 0;
3950 __ENDTRY
3951 return retval;
3954 if (!msg->hwnd) return 0;
3956 SPY_EnterMessage( SPY_DISPATCHMESSAGE, msg->hwnd, msg->message,
3957 msg->wParam, msg->lParam );
3959 if (!WINPROC_call_window( msg->hwnd, msg->message, msg->wParam, msg->lParam,
3960 &retval, TRUE, WMCHAR_MAP_DISPATCHMESSAGE ))
3962 if (!IsWindow( msg->hwnd )) SetLastError( ERROR_INVALID_WINDOW_HANDLE );
3963 else SetLastError( ERROR_MESSAGE_SYNC_ONLY );
3964 retval = 0;
3967 SPY_ExitMessage( SPY_RESULT_OK, msg->hwnd, msg->message, retval,
3968 msg->wParam, msg->lParam );
3970 if (msg->message == WM_PAINT)
3972 /* send a WM_NCPAINT and WM_ERASEBKGND if the non-client area is still invalid */
3973 HRGN hrgn = CreateRectRgn( 0, 0, 0, 0 );
3974 GetUpdateRgn( msg->hwnd, hrgn, TRUE );
3975 DeleteObject( hrgn );
3977 return retval;
3981 /***********************************************************************
3982 * GetMessagePos (USER.119)
3983 * GetMessagePos (USER32.@)
3985 * The GetMessagePos() function returns a long value representing a
3986 * cursor position, in screen coordinates, when the last message
3987 * retrieved by the GetMessage() function occurs. The x-coordinate is
3988 * in the low-order word of the return value, the y-coordinate is in
3989 * the high-order word. The application can use the MAKEPOINT()
3990 * macro to obtain a POINT structure from the return value.
3992 * For the current cursor position, use GetCursorPos().
3994 * RETURNS
3996 * Cursor position of last message on success, zero on failure.
3998 * CONFORMANCE
4000 * ECMA-234, Win32
4003 DWORD WINAPI GetMessagePos(void)
4005 return get_user_thread_info()->GetMessagePosVal;
4009 /***********************************************************************
4010 * GetMessageTime (USER.120)
4011 * GetMessageTime (USER32.@)
4013 * GetMessageTime() returns the message time for the last message
4014 * retrieved by the function. The time is measured in milliseconds with
4015 * the same offset as GetTickCount().
4017 * Since the tick count wraps, this is only useful for moderately short
4018 * relative time comparisons.
4020 * RETURNS
4022 * Time of last message on success, zero on failure.
4024 LONG WINAPI GetMessageTime(void)
4026 return get_user_thread_info()->GetMessageTimeVal;
4030 /***********************************************************************
4031 * GetMessageExtraInfo (USER.288)
4032 * GetMessageExtraInfo (USER32.@)
4034 LPARAM WINAPI GetMessageExtraInfo(void)
4036 return get_user_thread_info()->GetMessageExtraInfoVal;
4040 /***********************************************************************
4041 * SetMessageExtraInfo (USER32.@)
4043 LPARAM WINAPI SetMessageExtraInfo(LPARAM lParam)
4045 struct user_thread_info *thread_info = get_user_thread_info();
4046 LONG old_value = thread_info->GetMessageExtraInfoVal;
4047 thread_info->GetMessageExtraInfoVal = lParam;
4048 return old_value;
4052 /***********************************************************************
4053 * WaitMessage (USER.112) Suspend thread pending messages
4054 * WaitMessage (USER32.@) Suspend thread pending messages
4056 * WaitMessage() suspends a thread until events appear in the thread's
4057 * queue.
4059 BOOL WINAPI WaitMessage(void)
4061 return (MsgWaitForMultipleObjectsEx( 0, NULL, INFINITE, QS_ALLINPUT, 0 ) != WAIT_FAILED);
4065 /***********************************************************************
4066 * MsgWaitForMultipleObjectsEx (USER32.@)
4068 DWORD WINAPI MsgWaitForMultipleObjectsEx( DWORD count, CONST HANDLE *pHandles,
4069 DWORD timeout, DWORD mask, DWORD flags )
4071 HANDLE handles[MAXIMUM_WAIT_OBJECTS];
4072 DWORD i;
4074 if (count > MAXIMUM_WAIT_OBJECTS-1)
4076 SetLastError( ERROR_INVALID_PARAMETER );
4077 return WAIT_FAILED;
4080 /* set the queue mask */
4081 SERVER_START_REQ( set_queue_mask )
4083 req->wake_mask = (flags & MWMO_INPUTAVAILABLE) ? mask : 0;
4084 req->changed_mask = mask;
4085 req->skip_wait = 0;
4086 wine_server_call( req );
4088 SERVER_END_REQ;
4090 /* add the queue to the handle list */
4091 for (i = 0; i < count; i++) handles[i] = pHandles[i];
4092 handles[count] = get_server_queue_handle();
4094 flush_window_surfaces( TRUE );
4095 return wow_handlers.wait_message( count+1, handles, timeout, mask, flags );
4099 /***********************************************************************
4100 * MsgWaitForMultipleObjects (USER32.@)
4102 DWORD WINAPI MsgWaitForMultipleObjects( DWORD count, CONST HANDLE *handles,
4103 BOOL wait_all, DWORD timeout, DWORD mask )
4105 return MsgWaitForMultipleObjectsEx( count, handles, timeout, mask,
4106 wait_all ? MWMO_WAITALL : 0 );
4110 /***********************************************************************
4111 * WaitForInputIdle (USER32.@)
4113 DWORD WINAPI WaitForInputIdle( HANDLE hProcess, DWORD dwTimeOut )
4115 DWORD start_time, elapsed, ret;
4116 HANDLE handles[2];
4118 handles[0] = hProcess;
4119 SERVER_START_REQ( get_process_idle_event )
4121 req->handle = wine_server_obj_handle( hProcess );
4122 wine_server_call_err( req );
4123 handles[1] = wine_server_ptr_handle( reply->event );
4125 SERVER_END_REQ;
4126 if (!handles[1]) return WAIT_FAILED; /* no event to wait on */
4128 start_time = GetTickCount();
4129 elapsed = 0;
4131 TRACE("waiting for %p\n", handles[1] );
4134 ret = MsgWaitForMultipleObjects ( 2, handles, FALSE, dwTimeOut - elapsed, QS_SENDMESSAGE );
4135 switch (ret)
4137 case WAIT_OBJECT_0:
4138 return 0;
4139 case WAIT_OBJECT_0+2:
4140 process_sent_messages();
4141 break;
4142 case WAIT_TIMEOUT:
4143 case WAIT_FAILED:
4144 TRACE("timeout or error\n");
4145 return ret;
4146 default:
4147 TRACE("finished\n");
4148 return 0;
4150 if (dwTimeOut != INFINITE)
4152 elapsed = GetTickCount() - start_time;
4153 if (elapsed > dwTimeOut)
4154 break;
4157 while (1);
4159 return WAIT_TIMEOUT;
4163 /***********************************************************************
4164 * RegisterWindowMessageA (USER32.@)
4165 * RegisterWindowMessage (USER.118)
4167 UINT WINAPI RegisterWindowMessageA( LPCSTR str )
4169 UINT ret = GlobalAddAtomA(str);
4170 TRACE("%s, ret=%x\n", str, ret);
4171 return ret;
4175 /***********************************************************************
4176 * RegisterWindowMessageW (USER32.@)
4178 UINT WINAPI RegisterWindowMessageW( LPCWSTR str )
4180 UINT ret = GlobalAddAtomW(str);
4181 TRACE("%s ret=%x\n", debugstr_w(str), ret);
4182 return ret;
4185 typedef struct BroadcastParm
4187 DWORD flags;
4188 LPDWORD recipients;
4189 UINT msg;
4190 WPARAM wp;
4191 LPARAM lp;
4192 DWORD success;
4193 HWINSTA winsta;
4194 } BroadcastParm;
4196 static BOOL CALLBACK bcast_childwindow( HWND hw, LPARAM lp )
4198 BroadcastParm *parm = (BroadcastParm*)lp;
4199 DWORD_PTR retval = 0;
4200 LRESULT lresult;
4202 if (parm->flags & BSF_IGNORECURRENTTASK && WIN_IsCurrentProcess(hw))
4204 TRACE("Not telling myself %p\n", hw);
4205 return TRUE;
4208 /* I don't know 100% for sure if this is what Windows does, but it fits the tests */
4209 if (parm->flags & BSF_QUERY)
4211 TRACE("Telling window %p using SendMessageTimeout\n", hw);
4213 /* Not tested for conflicting flags */
4214 if (parm->flags & BSF_FORCEIFHUNG || parm->flags & BSF_NOHANG)
4215 lresult = SendMessageTimeoutW( hw, parm->msg, parm->wp, parm->lp, SMTO_ABORTIFHUNG, 2000, &retval );
4216 else if (parm->flags & BSF_NOTIMEOUTIFNOTHUNG)
4217 lresult = SendMessageTimeoutW( hw, parm->msg, parm->wp, parm->lp, SMTO_NOTIMEOUTIFNOTHUNG, 2000, &retval );
4218 else
4219 lresult = SendMessageTimeoutW( hw, parm->msg, parm->wp, parm->lp, SMTO_NORMAL, 2000, &retval );
4221 if (!lresult && GetLastError() == ERROR_TIMEOUT)
4223 WARN("Timed out!\n");
4224 if (!(parm->flags & BSF_FORCEIFHUNG))
4225 goto fail;
4227 if (retval == BROADCAST_QUERY_DENY)
4228 goto fail;
4230 return TRUE;
4232 fail:
4233 parm->success = 0;
4234 return FALSE;
4236 else if (parm->flags & BSF_POSTMESSAGE)
4238 TRACE("Telling window %p using PostMessage\n", hw);
4239 PostMessageW( hw, parm->msg, parm->wp, parm->lp );
4241 else
4243 TRACE("Telling window %p using SendNotifyMessage\n", hw);
4244 SendNotifyMessageW( hw, parm->msg, parm->wp, parm->lp );
4247 return TRUE;
4250 static BOOL CALLBACK bcast_desktop( LPWSTR desktop, LPARAM lp )
4252 BOOL ret;
4253 HDESK hdesktop;
4254 BroadcastParm *parm = (BroadcastParm*)lp;
4256 TRACE("desktop: %s\n", debugstr_w( desktop ));
4258 hdesktop = open_winstation_desktop( parm->winsta, desktop, 0, FALSE, DESKTOP_ENUMERATE|DESKTOP_WRITEOBJECTS|STANDARD_RIGHTS_WRITE );
4259 if (!hdesktop)
4261 FIXME("Could not open desktop %s\n", debugstr_w(desktop));
4262 return TRUE;
4265 ret = EnumDesktopWindows( hdesktop, bcast_childwindow, lp );
4266 CloseDesktop(hdesktop);
4267 TRACE("-->%d\n", ret);
4268 return parm->success;
4271 static BOOL CALLBACK bcast_winsta( LPWSTR winsta, LPARAM lp )
4273 BOOL ret;
4274 HWINSTA hwinsta = OpenWindowStationW( winsta, FALSE, WINSTA_ENUMDESKTOPS );
4275 TRACE("hwinsta: %p/%s/%08x\n", hwinsta, debugstr_w( winsta ), GetLastError());
4276 if (!hwinsta)
4277 return TRUE;
4278 ((BroadcastParm *)lp)->winsta = hwinsta;
4279 ret = EnumDesktopsW( hwinsta, bcast_desktop, lp );
4280 CloseWindowStation( hwinsta );
4281 TRACE("-->%d\n", ret);
4282 return ret;
4285 /***********************************************************************
4286 * BroadcastSystemMessageA (USER32.@)
4287 * BroadcastSystemMessage (USER32.@)
4289 LONG WINAPI BroadcastSystemMessageA( DWORD flags, LPDWORD recipients, UINT msg, WPARAM wp, LPARAM lp )
4291 return BroadcastSystemMessageExA( flags, recipients, msg, wp, lp, NULL );
4295 /***********************************************************************
4296 * BroadcastSystemMessageW (USER32.@)
4298 LONG WINAPI BroadcastSystemMessageW( DWORD flags, LPDWORD recipients, UINT msg, WPARAM wp, LPARAM lp )
4300 return BroadcastSystemMessageExW( flags, recipients, msg, wp, lp, NULL );
4303 /***********************************************************************
4304 * BroadcastSystemMessageExA (USER32.@)
4306 LONG WINAPI BroadcastSystemMessageExA( DWORD flags, LPDWORD recipients, UINT msg, WPARAM wp, LPARAM lp, PBSMINFO pinfo )
4308 map_wparam_AtoW( msg, &wp, WMCHAR_MAP_NOMAPPING );
4309 return BroadcastSystemMessageExW( flags, recipients, msg, wp, lp, NULL );
4313 /***********************************************************************
4314 * BroadcastSystemMessageExW (USER32.@)
4316 LONG WINAPI BroadcastSystemMessageExW( DWORD flags, LPDWORD recipients, UINT msg, WPARAM wp, LPARAM lp, PBSMINFO pinfo )
4318 BroadcastParm parm;
4319 DWORD recips = BSM_ALLCOMPONENTS;
4320 BOOL ret = TRUE;
4321 static const DWORD all_flags = ( BSF_QUERY | BSF_IGNORECURRENTTASK | BSF_FLUSHDISK | BSF_NOHANG
4322 | BSF_POSTMESSAGE | BSF_FORCEIFHUNG | BSF_NOTIMEOUTIFNOTHUNG
4323 | BSF_ALLOWSFW | BSF_SENDNOTIFYMESSAGE | BSF_RETURNHDESK | BSF_LUID );
4325 TRACE("Flags: %08x, recipients: %p(0x%x), msg: %04x, wparam: %08lx, lparam: %08lx\n", flags, recipients,
4326 (recipients ? *recipients : recips), msg, wp, lp);
4328 if (flags & ~all_flags)
4330 SetLastError(ERROR_INVALID_PARAMETER);
4331 return 0;
4334 if (!recipients)
4335 recipients = &recips;
4337 if ( pinfo && flags & BSF_QUERY )
4338 FIXME("Not returning PBSMINFO information yet\n");
4340 parm.flags = flags;
4341 parm.recipients = recipients;
4342 parm.msg = msg;
4343 parm.wp = wp;
4344 parm.lp = lp;
4345 parm.success = TRUE;
4347 if (*recipients & BSM_ALLDESKTOPS || *recipients == BSM_ALLCOMPONENTS)
4348 ret = EnumWindowStationsW(bcast_winsta, (LONG_PTR)&parm);
4349 else if (*recipients & BSM_APPLICATIONS)
4351 EnumWindows(bcast_childwindow, (LONG_PTR)&parm);
4352 ret = parm.success;
4354 else
4355 FIXME("Recipients %08x not supported!\n", *recipients);
4357 return ret;
4360 /***********************************************************************
4361 * SetMessageQueue (USER32.@)
4363 BOOL WINAPI SetMessageQueue( INT size )
4365 /* now obsolete the message queue will be expanded dynamically as necessary */
4366 return TRUE;
4370 /***********************************************************************
4371 * MessageBeep (USER32.@)
4373 BOOL WINAPI MessageBeep( UINT i )
4375 BOOL active = TRUE;
4376 SystemParametersInfoA( SPI_GETBEEP, 0, &active, FALSE );
4377 if (active) USER_Driver->pBeep();
4378 return TRUE;
4382 /***********************************************************************
4383 * SetTimer (USER32.@)
4385 UINT_PTR WINAPI SetTimer( HWND hwnd, UINT_PTR id, UINT timeout, TIMERPROC proc )
4387 UINT_PTR ret;
4388 WNDPROC winproc = 0;
4390 if (proc) winproc = WINPROC_AllocProc( (WNDPROC)proc, FALSE );
4392 /* MSDN states that the minimum timeout should be USER_TIMER_MINIMUM (10.0 ms), but testing
4393 * indicates that the true minimum is closer to 15.6 ms. */
4394 timeout = min( max( 15, timeout ), USER_TIMER_MAXIMUM );
4396 SERVER_START_REQ( set_win_timer )
4398 req->win = wine_server_user_handle( hwnd );
4399 req->msg = WM_TIMER;
4400 req->id = id;
4401 req->rate = timeout;
4402 req->lparam = (ULONG_PTR)winproc;
4403 if (!wine_server_call_err( req ))
4405 ret = reply->id;
4406 if (!ret) ret = TRUE;
4408 else ret = 0;
4410 SERVER_END_REQ;
4412 TRACE("Added %p %lx %p timeout %d\n", hwnd, id, winproc, timeout );
4413 return ret;
4417 /***********************************************************************
4418 * SetSystemTimer (USER32.@)
4420 UINT_PTR WINAPI SetSystemTimer( HWND hwnd, UINT_PTR id, UINT timeout, TIMERPROC proc )
4422 UINT_PTR ret;
4423 WNDPROC winproc = 0;
4425 if (proc) winproc = WINPROC_AllocProc( (WNDPROC)proc, FALSE );
4427 /* MSDN states that the minimum timeout should be USER_TIMER_MINIMUM (10.0 ms), but testing
4428 * indicates that the true minimum is closer to 15.6 ms. */
4429 timeout = min( max( 15, timeout ), USER_TIMER_MAXIMUM );
4431 SERVER_START_REQ( set_win_timer )
4433 req->win = wine_server_user_handle( hwnd );
4434 req->msg = WM_SYSTIMER;
4435 req->id = id;
4436 req->rate = timeout;
4437 req->lparam = (ULONG_PTR)winproc;
4438 if (!wine_server_call_err( req ))
4440 ret = reply->id;
4441 if (!ret) ret = TRUE;
4443 else ret = 0;
4445 SERVER_END_REQ;
4447 TRACE("Added %p %lx %p timeout %d\n", hwnd, id, winproc, timeout );
4448 return ret;
4452 /***********************************************************************
4453 * KillTimer (USER32.@)
4455 BOOL WINAPI KillTimer( HWND hwnd, UINT_PTR id )
4457 BOOL ret;
4459 SERVER_START_REQ( kill_win_timer )
4461 req->win = wine_server_user_handle( hwnd );
4462 req->msg = WM_TIMER;
4463 req->id = id;
4464 ret = !wine_server_call_err( req );
4466 SERVER_END_REQ;
4467 return ret;
4471 /***********************************************************************
4472 * KillSystemTimer (USER32.@)
4474 BOOL WINAPI KillSystemTimer( HWND hwnd, UINT_PTR id )
4476 BOOL ret;
4478 SERVER_START_REQ( kill_win_timer )
4480 req->win = wine_server_user_handle( hwnd );
4481 req->msg = WM_SYSTIMER;
4482 req->id = id;
4483 ret = !wine_server_call_err( req );
4485 SERVER_END_REQ;
4486 return ret;
4490 /**********************************************************************
4491 * IsGUIThread (USER32.@)
4493 BOOL WINAPI IsGUIThread( BOOL convert )
4495 FIXME( "%u: stub\n", convert );
4496 return TRUE;
4500 /**********************************************************************
4501 * GetGUIThreadInfo (USER32.@)
4503 BOOL WINAPI GetGUIThreadInfo( DWORD id, GUITHREADINFO *info )
4505 BOOL ret;
4507 if (info->cbSize != sizeof(*info))
4509 SetLastError( ERROR_INVALID_PARAMETER );
4510 return FALSE;
4513 SERVER_START_REQ( get_thread_input )
4515 req->tid = id;
4516 if ((ret = !wine_server_call_err( req )))
4518 info->flags = 0;
4519 info->hwndActive = wine_server_ptr_handle( reply->active );
4520 info->hwndFocus = wine_server_ptr_handle( reply->focus );
4521 info->hwndCapture = wine_server_ptr_handle( reply->capture );
4522 info->hwndMenuOwner = wine_server_ptr_handle( reply->menu_owner );
4523 info->hwndMoveSize = wine_server_ptr_handle( reply->move_size );
4524 info->hwndCaret = wine_server_ptr_handle( reply->caret );
4525 info->rcCaret.left = reply->rect.left;
4526 info->rcCaret.top = reply->rect.top;
4527 info->rcCaret.right = reply->rect.right;
4528 info->rcCaret.bottom = reply->rect.bottom;
4529 if (reply->menu_owner) info->flags |= GUI_INMENUMODE;
4530 if (reply->move_size) info->flags |= GUI_INMOVESIZE;
4531 if (reply->caret) info->flags |= GUI_CARETBLINKING;
4534 SERVER_END_REQ;
4535 return ret;
4539 /******************************************************************
4540 * IsHungAppWindow (USER32.@)
4543 BOOL WINAPI IsHungAppWindow( HWND hWnd )
4545 BOOL ret;
4547 SERVER_START_REQ( is_window_hung )
4549 req->win = wine_server_user_handle( hWnd );
4550 ret = !wine_server_call_err( req ) && reply->is_hung;
4552 SERVER_END_REQ;
4553 return ret;
4556 /******************************************************************
4557 * ChangeWindowMessageFilter (USER32.@)
4559 BOOL WINAPI ChangeWindowMessageFilter( UINT message, DWORD flag )
4561 FIXME( "%x %08x\n", message, flag );
4562 return TRUE;