urlmon: Improve IUri support for mk: URIs.
[wine/multimedia.git] / dlls / user32 / message.c
blobb073e1c44baf11397ac60991ef893a0144f7c547
1 /*
2 * Window messaging support
4 * Copyright 2001 Alexandre Julliard
5 * Copyright 2008 Maarten Lankhorst
7 * This library is free software; you can redistribute it and/or
8 * modify it under the terms of the GNU Lesser General Public
9 * License as published by the Free Software Foundation; either
10 * version 2.1 of the License, or (at your option) any later version.
12 * This library is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
15 * Lesser General Public License for more details.
17 * You should have received a copy of the GNU Lesser General Public
18 * License along with this library; if not, write to the Free Software
19 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
22 #include "config.h"
23 #include "wine/port.h"
25 #include <assert.h>
26 #include <stdarg.h>
28 #include "ntstatus.h"
29 #define WIN32_NO_STATUS
30 #include "windef.h"
31 #include "winbase.h"
32 #include "wingdi.h"
33 #include "winuser.h"
34 #include "winerror.h"
35 #include "winnls.h"
36 #include "dbt.h"
37 #include "dde.h"
38 #include "imm.h"
39 #include "ddk/imm.h"
40 #include "wine/unicode.h"
41 #include "wine/server.h"
42 #include "user_private.h"
43 #include "win.h"
44 #include "controls.h"
45 #include "wine/debug.h"
46 #include "wine/exception.h"
48 WINE_DEFAULT_DEBUG_CHANNEL(msg);
49 WINE_DECLARE_DEBUG_CHANNEL(relay);
50 WINE_DECLARE_DEBUG_CHANNEL(key);
52 #define WM_NCMOUSEFIRST WM_NCMOUSEMOVE
53 #define WM_NCMOUSELAST (WM_NCMOUSEFIRST+(WM_MOUSELAST-WM_MOUSEFIRST))
55 #define MAX_PACK_COUNT 4
57 #define SYS_TIMER_RATE 55 /* min. timer rate in ms (actually 54.925)*/
59 /* the various structures that can be sent in messages, in platform-independent layout */
60 struct packed_CREATESTRUCTW
62 ULONGLONG lpCreateParams;
63 ULONGLONG hInstance;
64 user_handle_t hMenu;
65 DWORD __pad1;
66 user_handle_t hwndParent;
67 DWORD __pad2;
68 INT cy;
69 INT cx;
70 INT y;
71 INT x;
72 LONG style;
73 ULONGLONG lpszName;
74 ULONGLONG lpszClass;
75 DWORD dwExStyle;
76 DWORD __pad3;
79 struct packed_DRAWITEMSTRUCT
81 UINT CtlType;
82 UINT CtlID;
83 UINT itemID;
84 UINT itemAction;
85 UINT itemState;
86 user_handle_t hwndItem;
87 DWORD __pad1;
88 user_handle_t hDC;
89 DWORD __pad2;
90 RECT rcItem;
91 ULONGLONG itemData;
94 struct packed_MEASUREITEMSTRUCT
96 UINT CtlType;
97 UINT CtlID;
98 UINT itemID;
99 UINT itemWidth;
100 UINT itemHeight;
101 ULONGLONG itemData;
104 struct packed_DELETEITEMSTRUCT
106 UINT CtlType;
107 UINT CtlID;
108 UINT itemID;
109 user_handle_t hwndItem;
110 DWORD __pad;
111 ULONGLONG itemData;
114 struct packed_COMPAREITEMSTRUCT
116 UINT CtlType;
117 UINT CtlID;
118 user_handle_t hwndItem;
119 DWORD __pad1;
120 UINT itemID1;
121 ULONGLONG itemData1;
122 UINT itemID2;
123 ULONGLONG itemData2;
124 DWORD dwLocaleId;
125 DWORD __pad2;
128 struct packed_WINDOWPOS
130 user_handle_t hwnd;
131 DWORD __pad1;
132 user_handle_t hwndInsertAfter;
133 DWORD __pad2;
134 INT x;
135 INT y;
136 INT cx;
137 INT cy;
138 UINT flags;
139 DWORD __pad3;
142 struct packed_COPYDATASTRUCT
144 ULONGLONG dwData;
145 DWORD cbData;
146 ULONGLONG lpData;
149 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;
588 /***********************************************************************
589 * map_wparam_AtoW
591 * Convert the wparam of an ASCII message to Unicode.
593 BOOL map_wparam_AtoW( UINT message, WPARAM *wparam, enum wm_char_mapping mapping )
595 char ch[2];
596 WCHAR wch[2];
598 wch[0] = wch[1] = 0;
599 switch(message)
601 case WM_CHAR:
602 /* WM_CHAR is magic: a DBCS char can be sent/posted as two consecutive WM_CHAR
603 * messages, in which case the first char is stored, and the conversion
604 * to Unicode only takes place once the second char is sent/posted.
606 if (mapping != WMCHAR_MAP_NOMAPPING)
608 struct wm_char_mapping_data *data = get_user_thread_info()->wmchar_data;
609 BYTE low = LOBYTE(*wparam);
611 if (HIBYTE(*wparam))
613 ch[0] = low;
614 ch[1] = HIBYTE(*wparam);
615 RtlMultiByteToUnicodeN( wch, sizeof(wch), NULL, ch, 2 );
616 TRACE( "map %02x,%02x -> %04x mapping %u\n", (BYTE)ch[0], (BYTE)ch[1], wch[0], mapping );
617 if (data) data->lead_byte[mapping] = 0;
619 else if (data && data->lead_byte[mapping])
621 ch[0] = data->lead_byte[mapping];
622 ch[1] = low;
623 RtlMultiByteToUnicodeN( wch, sizeof(wch), NULL, ch, 2 );
624 TRACE( "map stored %02x,%02x -> %04x mapping %u\n", (BYTE)ch[0], (BYTE)ch[1], wch[0], mapping );
625 data->lead_byte[mapping] = 0;
627 else if (!IsDBCSLeadByte( low ))
629 ch[0] = low;
630 RtlMultiByteToUnicodeN( wch, sizeof(wch), NULL, ch, 1 );
631 TRACE( "map %02x -> %04x\n", (BYTE)ch[0], wch[0] );
632 if (data) data->lead_byte[mapping] = 0;
634 else /* store it and wait for trail byte */
636 if (!data)
638 if (!(data = HeapAlloc( GetProcessHeap(), HEAP_ZERO_MEMORY, sizeof(*data) )))
639 return FALSE;
640 get_user_thread_info()->wmchar_data = data;
642 TRACE( "storing lead byte %02x mapping %u\n", low, mapping );
643 data->lead_byte[mapping] = low;
644 return FALSE;
646 *wparam = MAKEWPARAM(wch[0], wch[1]);
647 break;
649 /* else fall through */
650 case WM_CHARTOITEM:
651 case EM_SETPASSWORDCHAR:
652 case WM_DEADCHAR:
653 case WM_SYSCHAR:
654 case WM_SYSDEADCHAR:
655 case WM_MENUCHAR:
656 ch[0] = LOBYTE(*wparam);
657 ch[1] = HIBYTE(*wparam);
658 RtlMultiByteToUnicodeN( wch, sizeof(wch), NULL, ch, 2 );
659 *wparam = MAKEWPARAM(wch[0], wch[1]);
660 break;
661 case WM_IME_CHAR:
662 ch[0] = HIBYTE(*wparam);
663 ch[1] = LOBYTE(*wparam);
664 if (ch[0]) RtlMultiByteToUnicodeN( wch, sizeof(wch[0]), NULL, ch, 2 );
665 else RtlMultiByteToUnicodeN( wch, sizeof(wch[0]), NULL, ch + 1, 1 );
666 *wparam = MAKEWPARAM(wch[0], HIWORD(*wparam));
667 break;
669 return TRUE;
673 /***********************************************************************
674 * map_wparam_WtoA
676 * Convert the wparam of a Unicode message to ASCII.
678 static void map_wparam_WtoA( MSG *msg, BOOL remove )
680 BYTE ch[2];
681 WCHAR wch[2];
682 DWORD len;
684 switch(msg->message)
686 case WM_CHAR:
687 if (!HIWORD(msg->wParam))
689 wch[0] = LOWORD(msg->wParam);
690 ch[0] = ch[1] = 0;
691 RtlUnicodeToMultiByteN( (LPSTR)ch, 2, &len, wch, sizeof(wch[0]) );
692 if (len == 2) /* DBCS char */
694 struct wm_char_mapping_data *data = get_user_thread_info()->wmchar_data;
695 if (!data)
697 if (!(data = HeapAlloc( GetProcessHeap(), HEAP_ZERO_MEMORY, sizeof(*data) ))) return;
698 get_user_thread_info()->wmchar_data = data;
700 if (remove)
702 data->get_msg = *msg;
703 data->get_msg.wParam = ch[1];
705 msg->wParam = ch[0];
706 return;
709 /* else fall through */
710 case WM_CHARTOITEM:
711 case EM_SETPASSWORDCHAR:
712 case WM_DEADCHAR:
713 case WM_SYSCHAR:
714 case WM_SYSDEADCHAR:
715 case WM_MENUCHAR:
716 wch[0] = LOWORD(msg->wParam);
717 wch[1] = HIWORD(msg->wParam);
718 ch[0] = ch[1] = 0;
719 RtlUnicodeToMultiByteN( (LPSTR)ch, 2, NULL, wch, sizeof(wch) );
720 msg->wParam = MAKEWPARAM( ch[0] | (ch[1] << 8), 0 );
721 break;
722 case WM_IME_CHAR:
723 wch[0] = LOWORD(msg->wParam);
724 ch[0] = ch[1] = 0;
725 RtlUnicodeToMultiByteN( (LPSTR)ch, 2, &len, wch, sizeof(wch[0]) );
726 if (len == 2)
727 msg->wParam = MAKEWPARAM( (ch[0] << 8) | ch[1], HIWORD(msg->wParam) );
728 else
729 msg->wParam = MAKEWPARAM( ch[0], HIWORD(msg->wParam) );
730 break;
735 /***********************************************************************
736 * pack_message
738 * Pack a message for sending to another process.
739 * Return the size of the data we expect in the message reply.
740 * Set data->count to -1 if there is an error.
742 static size_t pack_message( HWND hwnd, UINT message, WPARAM wparam, LPARAM lparam,
743 struct packed_message *data )
745 data->count = 0;
746 switch(message)
748 case WM_NCCREATE:
749 case WM_CREATE:
751 CREATESTRUCTW *cs = (CREATESTRUCTW *)lparam;
752 data->ps.cs.lpCreateParams = pack_ptr( cs->lpCreateParams );
753 data->ps.cs.hInstance = pack_ptr( cs->hInstance );
754 data->ps.cs.hMenu = wine_server_user_handle( cs->hMenu );
755 data->ps.cs.hwndParent = wine_server_user_handle( cs->hwndParent );
756 data->ps.cs.cy = cs->cy;
757 data->ps.cs.cx = cs->cx;
758 data->ps.cs.y = cs->y;
759 data->ps.cs.x = cs->x;
760 data->ps.cs.style = cs->style;
761 data->ps.cs.dwExStyle = cs->dwExStyle;
762 data->ps.cs.lpszName = pack_ptr( cs->lpszName );
763 data->ps.cs.lpszClass = pack_ptr( cs->lpszClass );
764 push_data( data, &data->ps.cs, sizeof(data->ps.cs) );
765 if (!IS_INTRESOURCE(cs->lpszName)) push_string( data, cs->lpszName );
766 if (!IS_INTRESOURCE(cs->lpszClass)) push_string( data, cs->lpszClass );
767 return sizeof(data->ps.cs);
769 case WM_GETTEXT:
770 case WM_ASKCBFORMATNAME:
771 return wparam * sizeof(WCHAR);
772 case WM_WININICHANGE:
773 if (lparam) push_string(data, (LPWSTR)lparam );
774 return 0;
775 case WM_SETTEXT:
776 case WM_DEVMODECHANGE:
777 case CB_DIR:
778 case LB_DIR:
779 case LB_ADDFILE:
780 case EM_REPLACESEL:
781 push_string( data, (LPWSTR)lparam );
782 return 0;
783 case WM_GETMINMAXINFO:
784 push_data( data, (MINMAXINFO *)lparam, sizeof(MINMAXINFO) );
785 return sizeof(MINMAXINFO);
786 case WM_DRAWITEM:
788 DRAWITEMSTRUCT *dis = (DRAWITEMSTRUCT *)lparam;
789 data->ps.dis.CtlType = dis->CtlType;
790 data->ps.dis.CtlID = dis->CtlID;
791 data->ps.dis.itemID = dis->itemID;
792 data->ps.dis.itemAction = dis->itemAction;
793 data->ps.dis.itemState = dis->itemState;
794 data->ps.dis.hwndItem = wine_server_user_handle( dis->hwndItem );
795 data->ps.dis.hDC = wine_server_user_handle( dis->hDC ); /* FIXME */
796 data->ps.dis.rcItem = dis->rcItem;
797 data->ps.dis.itemData = dis->itemData;
798 push_data( data, &data->ps.dis, sizeof(data->ps.dis) );
799 return 0;
801 case WM_MEASUREITEM:
803 MEASUREITEMSTRUCT *mis = (MEASUREITEMSTRUCT *)lparam;
804 data->ps.mis.CtlType = mis->CtlType;
805 data->ps.mis.CtlID = mis->CtlID;
806 data->ps.mis.itemID = mis->itemID;
807 data->ps.mis.itemWidth = mis->itemWidth;
808 data->ps.mis.itemHeight = mis->itemHeight;
809 data->ps.mis.itemData = mis->itemData;
810 push_data( data, &data->ps.mis, sizeof(data->ps.mis) );
811 return sizeof(data->ps.mis);
813 case WM_DELETEITEM:
815 DELETEITEMSTRUCT *dls = (DELETEITEMSTRUCT *)lparam;
816 data->ps.dls.CtlType = dls->CtlType;
817 data->ps.dls.CtlID = dls->CtlID;
818 data->ps.dls.itemID = dls->itemID;
819 data->ps.dls.hwndItem = wine_server_user_handle( dls->hwndItem );
820 data->ps.dls.itemData = dls->itemData;
821 push_data( data, &data->ps.dls, sizeof(data->ps.dls) );
822 return 0;
824 case WM_COMPAREITEM:
826 COMPAREITEMSTRUCT *cis = (COMPAREITEMSTRUCT *)lparam;
827 data->ps.cis.CtlType = cis->CtlType;
828 data->ps.cis.CtlID = cis->CtlID;
829 data->ps.cis.hwndItem = wine_server_user_handle( cis->hwndItem );
830 data->ps.cis.itemID1 = cis->itemID1;
831 data->ps.cis.itemData1 = cis->itemData1;
832 data->ps.cis.itemID2 = cis->itemID2;
833 data->ps.cis.itemData2 = cis->itemData2;
834 data->ps.cis.dwLocaleId = cis->dwLocaleId;
835 push_data( data, &data->ps.cis, sizeof(data->ps.cis) );
836 return 0;
838 case WM_WINE_SETWINDOWPOS:
839 case WM_WINDOWPOSCHANGING:
840 case WM_WINDOWPOSCHANGED:
842 WINDOWPOS *wp = (WINDOWPOS *)lparam;
843 data->ps.wp.hwnd = wine_server_user_handle( wp->hwnd );
844 data->ps.wp.hwndInsertAfter = wine_server_user_handle( wp->hwndInsertAfter );
845 data->ps.wp.x = wp->x;
846 data->ps.wp.y = wp->y;
847 data->ps.wp.cx = wp->cx;
848 data->ps.wp.cy = wp->cy;
849 data->ps.wp.flags = wp->flags;
850 push_data( data, &data->ps.wp, sizeof(data->ps.wp) );
851 return sizeof(data->ps.wp);
853 case WM_COPYDATA:
855 COPYDATASTRUCT *cds = (COPYDATASTRUCT *)lparam;
856 data->ps.cds.cbData = cds->cbData;
857 data->ps.cds.dwData = cds->dwData;
858 data->ps.cds.lpData = pack_ptr( cds->lpData );
859 push_data( data, &data->ps.cds, sizeof(data->ps.cds) );
860 if (cds->lpData) push_data( data, cds->lpData, cds->cbData );
861 return 0;
863 case WM_NOTIFY:
864 /* WM_NOTIFY cannot be sent across processes (MSDN) */
865 data->count = -1;
866 return 0;
867 case WM_HELP:
869 HELPINFO *hi = (HELPINFO *)lparam;
870 data->ps.hi.iContextType = hi->iContextType;
871 data->ps.hi.iCtrlId = hi->iCtrlId;
872 data->ps.hi.hItemHandle = wine_server_user_handle( hi->hItemHandle );
873 data->ps.hi.dwContextId = hi->dwContextId;
874 data->ps.hi.MousePos = hi->MousePos;
875 push_data( data, &data->ps.hi, sizeof(data->ps.hi) );
876 return 0;
878 case WM_STYLECHANGING:
879 case WM_STYLECHANGED:
880 push_data( data, (STYLESTRUCT *)lparam, sizeof(STYLESTRUCT) );
881 return 0;
882 case WM_NCCALCSIZE:
883 if (!wparam)
885 push_data( data, (RECT *)lparam, sizeof(RECT) );
886 return sizeof(RECT);
888 else
890 NCCALCSIZE_PARAMS *ncp = (NCCALCSIZE_PARAMS *)lparam;
891 data->ps.ncp.rgrc[0] = ncp->rgrc[0];
892 data->ps.ncp.rgrc[1] = ncp->rgrc[1];
893 data->ps.ncp.rgrc[2] = ncp->rgrc[2];
894 data->ps.ncp.hwnd = wine_server_user_handle( ncp->lppos->hwnd );
895 data->ps.ncp.hwndInsertAfter = wine_server_user_handle( ncp->lppos->hwndInsertAfter );
896 data->ps.ncp.x = ncp->lppos->x;
897 data->ps.ncp.y = ncp->lppos->y;
898 data->ps.ncp.cx = ncp->lppos->cx;
899 data->ps.ncp.cy = ncp->lppos->cy;
900 data->ps.ncp.flags = ncp->lppos->flags;
901 push_data( data, &data->ps.ncp, sizeof(data->ps.ncp) );
902 return sizeof(data->ps.ncp);
904 case WM_GETDLGCODE:
905 if (lparam)
907 MSG *msg = (MSG *)lparam;
908 data->ps.msg.hwnd = wine_server_user_handle( msg->hwnd );
909 data->ps.msg.message = msg->message;
910 data->ps.msg.wParam = msg->wParam;
911 data->ps.msg.lParam = msg->lParam;
912 data->ps.msg.time = msg->time;
913 data->ps.msg.pt = msg->pt;
914 push_data( data, &data->ps.msg, sizeof(data->ps.msg) );
915 return sizeof(data->ps.msg);
917 return 0;
918 case SBM_SETSCROLLINFO:
919 push_data( data, (SCROLLINFO *)lparam, sizeof(SCROLLINFO) );
920 return 0;
921 case SBM_GETSCROLLINFO:
922 push_data( data, (SCROLLINFO *)lparam, sizeof(SCROLLINFO) );
923 return sizeof(SCROLLINFO);
924 case SBM_GETSCROLLBARINFO:
926 const SCROLLBARINFO *info = (const SCROLLBARINFO *)lparam;
927 size_t size = min( info->cbSize, sizeof(SCROLLBARINFO) );
928 push_data( data, info, size );
929 return size;
931 case EM_GETSEL:
932 case SBM_GETRANGE:
933 case CB_GETEDITSEL:
935 size_t size = 0;
936 if (wparam) size += sizeof(DWORD);
937 if (lparam) size += sizeof(DWORD);
938 return size;
940 case EM_GETRECT:
941 case LB_GETITEMRECT:
942 case CB_GETDROPPEDCONTROLRECT:
943 return sizeof(RECT);
944 case EM_SETRECT:
945 case EM_SETRECTNP:
946 push_data( data, (RECT *)lparam, sizeof(RECT) );
947 return 0;
948 case EM_GETLINE:
950 WORD *pw = (WORD *)lparam;
951 push_data( data, pw, sizeof(*pw) );
952 return *pw * sizeof(WCHAR);
954 case EM_SETTABSTOPS:
955 case LB_SETTABSTOPS:
956 if (wparam) push_data( data, (UINT *)lparam, sizeof(UINT) * wparam );
957 return 0;
958 case CB_ADDSTRING:
959 case CB_INSERTSTRING:
960 case CB_FINDSTRING:
961 case CB_FINDSTRINGEXACT:
962 case CB_SELECTSTRING:
963 if (combobox_has_strings( hwnd )) push_string( data, (LPWSTR)lparam );
964 return 0;
965 case CB_GETLBTEXT:
966 if (!combobox_has_strings( hwnd )) return sizeof(ULONG_PTR);
967 return (SendMessageW( hwnd, CB_GETLBTEXTLEN, wparam, 0 ) + 1) * sizeof(WCHAR);
968 case LB_ADDSTRING:
969 case LB_INSERTSTRING:
970 case LB_FINDSTRING:
971 case LB_FINDSTRINGEXACT:
972 case LB_SELECTSTRING:
973 if (listbox_has_strings( hwnd )) push_string( data, (LPWSTR)lparam );
974 return 0;
975 case LB_GETTEXT:
976 if (!listbox_has_strings( hwnd )) return sizeof(ULONG_PTR);
977 return (SendMessageW( hwnd, LB_GETTEXTLEN, wparam, 0 ) + 1) * sizeof(WCHAR);
978 case LB_GETSELITEMS:
979 return wparam * sizeof(UINT);
980 case WM_NEXTMENU:
982 MDINEXTMENU *mnm = (MDINEXTMENU *)lparam;
983 data->ps.mnm.hmenuIn = wine_server_user_handle( mnm->hmenuIn );
984 data->ps.mnm.hmenuNext = wine_server_user_handle( mnm->hmenuNext );
985 data->ps.mnm.hwndNext = wine_server_user_handle( mnm->hwndNext );
986 push_data( data, &data->ps.mnm, sizeof(data->ps.mnm) );
987 return sizeof(data->ps.mnm);
989 case WM_SIZING:
990 case WM_MOVING:
991 push_data( data, (RECT *)lparam, sizeof(RECT) );
992 return sizeof(RECT);
993 case WM_MDICREATE:
995 MDICREATESTRUCTW *mcs = (MDICREATESTRUCTW *)lparam;
996 data->ps.mcs.szClass = pack_ptr( mcs->szClass );
997 data->ps.mcs.szTitle = pack_ptr( mcs->szTitle );
998 data->ps.mcs.hOwner = pack_ptr( mcs->hOwner );
999 data->ps.mcs.x = mcs->x;
1000 data->ps.mcs.y = mcs->y;
1001 data->ps.mcs.cx = mcs->cx;
1002 data->ps.mcs.cy = mcs->cy;
1003 data->ps.mcs.style = mcs->style;
1004 data->ps.mcs.lParam = mcs->lParam;
1005 push_data( data, &data->ps.mcs, sizeof(data->ps.mcs) );
1006 if (!IS_INTRESOURCE(mcs->szClass)) push_string( data, mcs->szClass );
1007 if (!IS_INTRESOURCE(mcs->szTitle)) push_string( data, mcs->szTitle );
1008 return sizeof(data->ps.mcs);
1010 case WM_MDIGETACTIVE:
1011 if (lparam) return sizeof(BOOL);
1012 return 0;
1013 case WM_DEVICECHANGE:
1015 DEV_BROADCAST_HDR *header = (DEV_BROADCAST_HDR *)lparam;
1016 push_data( data, header, header->dbch_size );
1017 return 0;
1019 case WM_WINE_KEYBOARD_LL_HOOK:
1021 struct hook_extra_info *h_extra = (struct hook_extra_info *)lparam;
1022 data->ps.hook.handle = wine_server_user_handle( h_extra->handle );
1023 push_data( data, &data->ps.hook, sizeof(data->ps.hook) );
1024 push_data( data, (LPVOID)h_extra->lparam, sizeof(KBDLLHOOKSTRUCT) );
1025 return 0;
1027 case WM_WINE_MOUSE_LL_HOOK:
1029 struct hook_extra_info *h_extra = (struct hook_extra_info *)lparam;
1030 data->ps.hook.handle = wine_server_user_handle( h_extra->handle );
1031 push_data( data, &data->ps.hook, sizeof(data->ps.hook) );
1032 push_data( data, (LPVOID)h_extra->lparam, sizeof(MSLLHOOKSTRUCT) );
1033 return 0;
1035 case WM_NCPAINT:
1036 if (wparam <= 1) return 0;
1037 FIXME( "WM_NCPAINT hdc packing not supported yet\n" );
1038 data->count = -1;
1039 return 0;
1040 case WM_PAINT:
1041 if (!wparam) return 0;
1042 /* fall through */
1044 /* these contain an HFONT */
1045 case WM_SETFONT:
1046 case WM_GETFONT:
1047 /* these contain an HDC */
1048 case WM_ERASEBKGND:
1049 case WM_ICONERASEBKGND:
1050 case WM_CTLCOLORMSGBOX:
1051 case WM_CTLCOLOREDIT:
1052 case WM_CTLCOLORLISTBOX:
1053 case WM_CTLCOLORBTN:
1054 case WM_CTLCOLORDLG:
1055 case WM_CTLCOLORSCROLLBAR:
1056 case WM_CTLCOLORSTATIC:
1057 case WM_PRINT:
1058 case WM_PRINTCLIENT:
1059 /* these contain an HGLOBAL */
1060 case WM_PAINTCLIPBOARD:
1061 case WM_SIZECLIPBOARD:
1062 /* these contain HICON */
1063 case WM_GETICON:
1064 case WM_SETICON:
1065 case WM_QUERYDRAGICON:
1066 case WM_QUERYPARKICON:
1067 /* these contain pointers */
1068 case WM_DROPOBJECT:
1069 case WM_QUERYDROPOBJECT:
1070 case WM_DRAGLOOP:
1071 case WM_DRAGSELECT:
1072 case WM_DRAGMOVE:
1073 FIXME( "msg %x (%s) not supported yet\n", message, SPY_GetMsgName(message, hwnd) );
1074 data->count = -1;
1075 return 0;
1077 return 0;
1081 /***********************************************************************
1082 * unpack_message
1084 * Unpack a message received from another process.
1086 static BOOL unpack_message( HWND hwnd, UINT message, WPARAM *wparam, LPARAM *lparam,
1087 void **buffer, size_t size )
1089 size_t minsize = 0;
1090 union packed_structs *ps = *buffer;
1092 switch(message)
1094 case WM_NCCREATE:
1095 case WM_CREATE:
1097 CREATESTRUCTW cs;
1098 WCHAR *str = (WCHAR *)(&ps->cs + 1);
1099 if (size < sizeof(ps->cs)) return FALSE;
1100 size -= sizeof(ps->cs);
1101 cs.lpCreateParams = unpack_ptr( ps->cs.lpCreateParams );
1102 cs.hInstance = unpack_ptr( ps->cs.hInstance );
1103 cs.hMenu = wine_server_ptr_handle( ps->cs.hMenu );
1104 cs.hwndParent = wine_server_ptr_handle( ps->cs.hwndParent );
1105 cs.cy = ps->cs.cy;
1106 cs.cx = ps->cs.cx;
1107 cs.y = ps->cs.y;
1108 cs.x = ps->cs.x;
1109 cs.style = ps->cs.style;
1110 cs.dwExStyle = ps->cs.dwExStyle;
1111 cs.lpszName = unpack_ptr( ps->cs.lpszName );
1112 cs.lpszClass = unpack_ptr( ps->cs.lpszClass );
1113 if (ps->cs.lpszName >> 16)
1115 if (!check_string( str, size )) return FALSE;
1116 cs.lpszName = str;
1117 size -= (strlenW(str) + 1) * sizeof(WCHAR);
1118 str += strlenW(str) + 1;
1120 if (ps->cs.lpszClass >> 16)
1122 if (!check_string( str, size )) return FALSE;
1123 cs.lpszClass = str;
1125 memcpy( &ps->cs, &cs, sizeof(cs) );
1126 break;
1128 case WM_GETTEXT:
1129 case WM_ASKCBFORMATNAME:
1130 if (!get_buffer_space( buffer, (*wparam * sizeof(WCHAR)) )) return FALSE;
1131 break;
1132 case WM_WININICHANGE:
1133 if (!*lparam) return TRUE;
1134 /* fall through */
1135 case WM_SETTEXT:
1136 case WM_DEVMODECHANGE:
1137 case CB_DIR:
1138 case LB_DIR:
1139 case LB_ADDFILE:
1140 case EM_REPLACESEL:
1141 if (!check_string( *buffer, size )) return FALSE;
1142 break;
1143 case WM_GETMINMAXINFO:
1144 minsize = sizeof(MINMAXINFO);
1145 break;
1146 case WM_DRAWITEM:
1148 DRAWITEMSTRUCT dis;
1149 if (size < sizeof(ps->dis)) return FALSE;
1150 dis.CtlType = ps->dis.CtlType;
1151 dis.CtlID = ps->dis.CtlID;
1152 dis.itemID = ps->dis.itemID;
1153 dis.itemAction = ps->dis.itemAction;
1154 dis.itemState = ps->dis.itemState;
1155 dis.hwndItem = wine_server_ptr_handle( ps->dis.hwndItem );
1156 dis.hDC = wine_server_ptr_handle( ps->dis.hDC );
1157 dis.rcItem = ps->dis.rcItem;
1158 dis.itemData = (ULONG_PTR)unpack_ptr( ps->dis.itemData );
1159 memcpy( &ps->dis, &dis, sizeof(dis) );
1160 break;
1162 case WM_MEASUREITEM:
1164 MEASUREITEMSTRUCT mis;
1165 if (size < sizeof(ps->mis)) return FALSE;
1166 mis.CtlType = ps->mis.CtlType;
1167 mis.CtlID = ps->mis.CtlID;
1168 mis.itemID = ps->mis.itemID;
1169 mis.itemWidth = ps->mis.itemWidth;
1170 mis.itemHeight = ps->mis.itemHeight;
1171 mis.itemData = (ULONG_PTR)unpack_ptr( ps->mis.itemData );
1172 memcpy( &ps->mis, &mis, sizeof(mis) );
1173 break;
1175 case WM_DELETEITEM:
1177 DELETEITEMSTRUCT dls;
1178 if (size < sizeof(ps->dls)) return FALSE;
1179 dls.CtlType = ps->dls.CtlType;
1180 dls.CtlID = ps->dls.CtlID;
1181 dls.itemID = ps->dls.itemID;
1182 dls.hwndItem = wine_server_ptr_handle( ps->dls.hwndItem );
1183 dls.itemData = (ULONG_PTR)unpack_ptr( ps->dls.itemData );
1184 memcpy( &ps->dls, &dls, sizeof(dls) );
1185 break;
1187 case WM_COMPAREITEM:
1189 COMPAREITEMSTRUCT cis;
1190 if (size < sizeof(ps->cis)) return FALSE;
1191 cis.CtlType = ps->cis.CtlType;
1192 cis.CtlID = ps->cis.CtlID;
1193 cis.hwndItem = wine_server_ptr_handle( ps->cis.hwndItem );
1194 cis.itemID1 = ps->cis.itemID1;
1195 cis.itemData1 = (ULONG_PTR)unpack_ptr( ps->cis.itemData1 );
1196 cis.itemID2 = ps->cis.itemID2;
1197 cis.itemData2 = (ULONG_PTR)unpack_ptr( ps->cis.itemData2 );
1198 cis.dwLocaleId = ps->cis.dwLocaleId;
1199 memcpy( &ps->cis, &cis, sizeof(cis) );
1200 break;
1202 case WM_WINDOWPOSCHANGING:
1203 case WM_WINDOWPOSCHANGED:
1204 case WM_WINE_SETWINDOWPOS:
1206 WINDOWPOS wp;
1207 if (size < sizeof(ps->wp)) return FALSE;
1208 wp.hwnd = wine_server_ptr_handle( ps->wp.hwnd );
1209 wp.hwndInsertAfter = wine_server_ptr_handle( ps->wp.hwndInsertAfter );
1210 wp.x = ps->wp.x;
1211 wp.y = ps->wp.y;
1212 wp.cx = ps->wp.cx;
1213 wp.cy = ps->wp.cy;
1214 wp.flags = ps->wp.flags;
1215 memcpy( &ps->wp, &wp, sizeof(wp) );
1216 break;
1218 case WM_COPYDATA:
1220 COPYDATASTRUCT cds;
1221 if (size < sizeof(ps->cds)) return FALSE;
1222 cds.dwData = (ULONG_PTR)unpack_ptr( ps->cds.dwData );
1223 if (ps->cds.lpData)
1225 cds.cbData = ps->cds.cbData;
1226 cds.lpData = &ps->cds + 1;
1227 minsize = sizeof(ps->cds) + cds.cbData;
1229 else
1231 cds.cbData = 0;
1232 cds.lpData = 0;
1234 memcpy( &ps->cds, &cds, sizeof(cds) );
1235 break;
1237 case WM_NOTIFY:
1238 /* WM_NOTIFY cannot be sent across processes (MSDN) */
1239 return FALSE;
1240 case WM_HELP:
1242 HELPINFO hi;
1243 if (size < sizeof(ps->hi)) return FALSE;
1244 hi.cbSize = sizeof(hi);
1245 hi.iContextType = ps->hi.iContextType;
1246 hi.iCtrlId = ps->hi.iCtrlId;
1247 hi.hItemHandle = wine_server_ptr_handle( ps->hi.hItemHandle );
1248 hi.dwContextId = (ULONG_PTR)unpack_ptr( ps->hi.dwContextId );
1249 hi.MousePos = ps->hi.MousePos;
1250 memcpy( &ps->hi, &hi, sizeof(hi) );
1251 break;
1253 case WM_STYLECHANGING:
1254 case WM_STYLECHANGED:
1255 minsize = sizeof(STYLESTRUCT);
1256 break;
1257 case WM_NCCALCSIZE:
1258 if (!*wparam) minsize = sizeof(RECT);
1259 else
1261 NCCALCSIZE_PARAMS ncp;
1262 WINDOWPOS wp;
1263 if (size < sizeof(ps->ncp)) return FALSE;
1264 ncp.rgrc[0] = ps->ncp.rgrc[0];
1265 ncp.rgrc[1] = ps->ncp.rgrc[1];
1266 ncp.rgrc[2] = ps->ncp.rgrc[2];
1267 wp.hwnd = wine_server_ptr_handle( ps->ncp.hwnd );
1268 wp.hwndInsertAfter = wine_server_ptr_handle( ps->ncp.hwndInsertAfter );
1269 wp.x = ps->ncp.x;
1270 wp.y = ps->ncp.y;
1271 wp.cx = ps->ncp.cx;
1272 wp.cy = ps->ncp.cy;
1273 wp.flags = ps->ncp.flags;
1274 ncp.lppos = (WINDOWPOS *)((NCCALCSIZE_PARAMS *)&ps->ncp + 1);
1275 memcpy( &ps->ncp, &ncp, sizeof(ncp) );
1276 *ncp.lppos = wp;
1278 break;
1279 case WM_GETDLGCODE:
1280 if (*lparam)
1282 MSG msg;
1283 if (size < sizeof(ps->msg)) return FALSE;
1284 msg.hwnd = wine_server_ptr_handle( ps->msg.hwnd );
1285 msg.message = ps->msg.message;
1286 msg.wParam = (ULONG_PTR)unpack_ptr( ps->msg.wParam );
1287 msg.lParam = (ULONG_PTR)unpack_ptr( ps->msg.lParam );
1288 msg.time = ps->msg.time;
1289 msg.pt = ps->msg.pt;
1290 memcpy( &ps->msg, &msg, sizeof(msg) );
1291 break;
1293 return TRUE;
1294 case SBM_SETSCROLLINFO:
1295 minsize = sizeof(SCROLLINFO);
1296 break;
1297 case SBM_GETSCROLLINFO:
1298 if (!get_buffer_space( buffer, sizeof(SCROLLINFO ))) return FALSE;
1299 break;
1300 case SBM_GETSCROLLBARINFO:
1301 if (!get_buffer_space( buffer, sizeof(SCROLLBARINFO ))) return FALSE;
1302 break;
1303 case EM_GETSEL:
1304 case SBM_GETRANGE:
1305 case CB_GETEDITSEL:
1306 if (*wparam || *lparam)
1308 if (!get_buffer_space( buffer, 2*sizeof(DWORD) )) return FALSE;
1309 if (*wparam) *wparam = (WPARAM)*buffer;
1310 if (*lparam) *lparam = (LPARAM)((DWORD *)*buffer + 1);
1312 return TRUE;
1313 case EM_GETRECT:
1314 case LB_GETITEMRECT:
1315 case CB_GETDROPPEDCONTROLRECT:
1316 if (!get_buffer_space( buffer, sizeof(RECT) )) return FALSE;
1317 break;
1318 case EM_SETRECT:
1319 case EM_SETRECTNP:
1320 minsize = sizeof(RECT);
1321 break;
1322 case EM_GETLINE:
1324 WORD len;
1325 if (size < sizeof(WORD)) return FALSE;
1326 len = *(WORD *)*buffer;
1327 if (!get_buffer_space( buffer, (len + 1) * sizeof(WCHAR) )) return FALSE;
1328 *lparam = (LPARAM)*buffer + sizeof(WORD); /* don't erase WORD at start of buffer */
1329 return TRUE;
1331 case EM_SETTABSTOPS:
1332 case LB_SETTABSTOPS:
1333 if (!*wparam) return TRUE;
1334 minsize = *wparam * sizeof(UINT);
1335 break;
1336 case CB_ADDSTRING:
1337 case CB_INSERTSTRING:
1338 case CB_FINDSTRING:
1339 case CB_FINDSTRINGEXACT:
1340 case CB_SELECTSTRING:
1341 case LB_ADDSTRING:
1342 case LB_INSERTSTRING:
1343 case LB_FINDSTRING:
1344 case LB_FINDSTRINGEXACT:
1345 case LB_SELECTSTRING:
1346 if (!*buffer) return TRUE;
1347 if (!check_string( *buffer, size )) return FALSE;
1348 break;
1349 case CB_GETLBTEXT:
1351 size = sizeof(ULONG_PTR);
1352 if (combobox_has_strings( hwnd ))
1353 size = (SendMessageW( hwnd, CB_GETLBTEXTLEN, *wparam, 0 ) + 1) * sizeof(WCHAR);
1354 if (!get_buffer_space( buffer, size )) return FALSE;
1355 break;
1357 case LB_GETTEXT:
1359 size = sizeof(ULONG_PTR);
1360 if (listbox_has_strings( hwnd ))
1361 size = (SendMessageW( hwnd, LB_GETTEXTLEN, *wparam, 0 ) + 1) * sizeof(WCHAR);
1362 if (!get_buffer_space( buffer, size )) return FALSE;
1363 break;
1365 case LB_GETSELITEMS:
1366 if (!get_buffer_space( buffer, *wparam * sizeof(UINT) )) return FALSE;
1367 break;
1368 case WM_NEXTMENU:
1370 MDINEXTMENU mnm;
1371 if (size < sizeof(ps->mnm)) return FALSE;
1372 mnm.hmenuIn = wine_server_ptr_handle( ps->mnm.hmenuIn );
1373 mnm.hmenuNext = wine_server_ptr_handle( ps->mnm.hmenuNext );
1374 mnm.hwndNext = wine_server_ptr_handle( ps->mnm.hwndNext );
1375 memcpy( &ps->mnm, &mnm, sizeof(mnm) );
1376 break;
1378 case WM_SIZING:
1379 case WM_MOVING:
1380 minsize = sizeof(RECT);
1381 if (!get_buffer_space( buffer, sizeof(RECT) )) return FALSE;
1382 break;
1383 case WM_MDICREATE:
1385 MDICREATESTRUCTW mcs;
1386 WCHAR *str = (WCHAR *)(&ps->mcs + 1);
1387 if (size < sizeof(ps->mcs)) return FALSE;
1388 size -= sizeof(ps->mcs);
1390 mcs.szClass = unpack_ptr( ps->mcs.szClass );
1391 mcs.szTitle = unpack_ptr( ps->mcs.szTitle );
1392 mcs.hOwner = unpack_ptr( ps->mcs.hOwner );
1393 mcs.x = ps->mcs.x;
1394 mcs.y = ps->mcs.y;
1395 mcs.cx = ps->mcs.cx;
1396 mcs.cy = ps->mcs.cy;
1397 mcs.style = ps->mcs.style;
1398 mcs.lParam = (LPARAM)unpack_ptr( ps->mcs.lParam );
1399 if (ps->mcs.szClass >> 16)
1401 if (!check_string( str, size )) return FALSE;
1402 mcs.szClass = str;
1403 size -= (strlenW(str) + 1) * sizeof(WCHAR);
1404 str += strlenW(str) + 1;
1406 if (ps->mcs.szTitle >> 16)
1408 if (!check_string( str, size )) return FALSE;
1409 mcs.szTitle = str;
1411 memcpy( &ps->mcs, &mcs, sizeof(mcs) );
1412 break;
1414 case WM_MDIGETACTIVE:
1415 if (!*lparam) return TRUE;
1416 if (!get_buffer_space( buffer, sizeof(BOOL) )) return FALSE;
1417 break;
1418 case WM_DEVICECHANGE:
1419 minsize = sizeof(DEV_BROADCAST_HDR);
1420 break;
1421 case WM_WINE_KEYBOARD_LL_HOOK:
1422 case WM_WINE_MOUSE_LL_HOOK:
1424 struct hook_extra_info h_extra;
1425 minsize = sizeof(ps->hook) +
1426 (message == WM_WINE_KEYBOARD_LL_HOOK ? sizeof(KBDLLHOOKSTRUCT)
1427 : sizeof(MSLLHOOKSTRUCT));
1428 if (size < minsize) return FALSE;
1429 h_extra.handle = wine_server_ptr_handle( ps->hook.handle );
1430 h_extra.lparam = (LPARAM)(&ps->hook + 1);
1431 memcpy( &ps->hook, &h_extra, sizeof(h_extra) );
1432 break;
1434 case WM_NCPAINT:
1435 if (*wparam <= 1) return TRUE;
1436 FIXME( "WM_NCPAINT hdc unpacking not supported\n" );
1437 return FALSE;
1438 case WM_PAINT:
1439 if (!*wparam) return TRUE;
1440 /* fall through */
1442 /* these contain an HFONT */
1443 case WM_SETFONT:
1444 case WM_GETFONT:
1445 /* these contain an HDC */
1446 case WM_ERASEBKGND:
1447 case WM_ICONERASEBKGND:
1448 case WM_CTLCOLORMSGBOX:
1449 case WM_CTLCOLOREDIT:
1450 case WM_CTLCOLORLISTBOX:
1451 case WM_CTLCOLORBTN:
1452 case WM_CTLCOLORDLG:
1453 case WM_CTLCOLORSCROLLBAR:
1454 case WM_CTLCOLORSTATIC:
1455 case WM_PRINT:
1456 case WM_PRINTCLIENT:
1457 /* these contain an HGLOBAL */
1458 case WM_PAINTCLIPBOARD:
1459 case WM_SIZECLIPBOARD:
1460 /* these contain HICON */
1461 case WM_GETICON:
1462 case WM_SETICON:
1463 case WM_QUERYDRAGICON:
1464 case WM_QUERYPARKICON:
1465 /* these contain pointers */
1466 case WM_DROPOBJECT:
1467 case WM_QUERYDROPOBJECT:
1468 case WM_DRAGLOOP:
1469 case WM_DRAGSELECT:
1470 case WM_DRAGMOVE:
1471 FIXME( "msg %x (%s) not supported yet\n", message, SPY_GetMsgName(message, hwnd) );
1472 return FALSE;
1474 default:
1475 return TRUE; /* message doesn't need any unpacking */
1478 /* default exit for most messages: check minsize and store buffer in lparam */
1479 if (size < minsize) return FALSE;
1480 *lparam = (LPARAM)*buffer;
1481 return TRUE;
1485 /***********************************************************************
1486 * pack_reply
1488 * Pack a reply to a message for sending to another process.
1490 static void pack_reply( HWND hwnd, UINT message, WPARAM wparam, LPARAM lparam,
1491 LRESULT res, struct packed_message *data )
1493 data->count = 0;
1494 switch(message)
1496 case WM_NCCREATE:
1497 case WM_CREATE:
1499 CREATESTRUCTW *cs = (CREATESTRUCTW *)lparam;
1500 data->ps.cs.lpCreateParams = (ULONG_PTR)cs->lpCreateParams;
1501 data->ps.cs.hInstance = (ULONG_PTR)cs->hInstance;
1502 data->ps.cs.hMenu = wine_server_user_handle( cs->hMenu );
1503 data->ps.cs.hwndParent = wine_server_user_handle( cs->hwndParent );
1504 data->ps.cs.cy = cs->cy;
1505 data->ps.cs.cx = cs->cx;
1506 data->ps.cs.y = cs->y;
1507 data->ps.cs.x = cs->x;
1508 data->ps.cs.style = cs->style;
1509 data->ps.cs.dwExStyle = cs->dwExStyle;
1510 data->ps.cs.lpszName = (ULONG_PTR)cs->lpszName;
1511 data->ps.cs.lpszClass = (ULONG_PTR)cs->lpszClass;
1512 push_data( data, &data->ps.cs, sizeof(data->ps.cs) );
1513 break;
1515 case WM_GETTEXT:
1516 case CB_GETLBTEXT:
1517 case LB_GETTEXT:
1518 push_data( data, (WCHAR *)lparam, (res + 1) * sizeof(WCHAR) );
1519 break;
1520 case WM_GETMINMAXINFO:
1521 push_data( data, (MINMAXINFO *)lparam, sizeof(MINMAXINFO) );
1522 break;
1523 case WM_MEASUREITEM:
1525 MEASUREITEMSTRUCT *mis = (MEASUREITEMSTRUCT *)lparam;
1526 data->ps.mis.CtlType = mis->CtlType;
1527 data->ps.mis.CtlID = mis->CtlID;
1528 data->ps.mis.itemID = mis->itemID;
1529 data->ps.mis.itemWidth = mis->itemWidth;
1530 data->ps.mis.itemHeight = mis->itemHeight;
1531 data->ps.mis.itemData = mis->itemData;
1532 push_data( data, &data->ps.mis, sizeof(data->ps.mis) );
1533 break;
1535 case WM_WINDOWPOSCHANGING:
1536 case WM_WINDOWPOSCHANGED:
1538 WINDOWPOS *wp = (WINDOWPOS *)lparam;
1539 data->ps.wp.hwnd = wine_server_user_handle( wp->hwnd );
1540 data->ps.wp.hwndInsertAfter = wine_server_user_handle( wp->hwndInsertAfter );
1541 data->ps.wp.x = wp->x;
1542 data->ps.wp.y = wp->y;
1543 data->ps.wp.cx = wp->cx;
1544 data->ps.wp.cy = wp->cy;
1545 data->ps.wp.flags = wp->flags;
1546 push_data( data, &data->ps.wp, sizeof(data->ps.wp) );
1547 break;
1549 case WM_GETDLGCODE:
1550 if (lparam)
1552 MSG *msg = (MSG *)lparam;
1553 data->ps.msg.hwnd = wine_server_user_handle( msg->hwnd );
1554 data->ps.msg.message = msg->message;
1555 data->ps.msg.wParam = msg->wParam;
1556 data->ps.msg.lParam = msg->lParam;
1557 data->ps.msg.time = msg->time;
1558 data->ps.msg.pt = msg->pt;
1559 push_data( data, &data->ps.msg, sizeof(data->ps.msg) );
1561 break;
1562 case SBM_GETSCROLLINFO:
1563 push_data( data, (SCROLLINFO *)lparam, sizeof(SCROLLINFO) );
1564 break;
1565 case EM_GETRECT:
1566 case LB_GETITEMRECT:
1567 case CB_GETDROPPEDCONTROLRECT:
1568 case WM_SIZING:
1569 case WM_MOVING:
1570 push_data( data, (RECT *)lparam, sizeof(RECT) );
1571 break;
1572 case EM_GETLINE:
1574 WORD *ptr = (WORD *)lparam;
1575 push_data( data, ptr, ptr[-1] * sizeof(WCHAR) );
1576 break;
1578 case LB_GETSELITEMS:
1579 push_data( data, (UINT *)lparam, wparam * sizeof(UINT) );
1580 break;
1581 case WM_MDIGETACTIVE:
1582 if (lparam) push_data( data, (BOOL *)lparam, sizeof(BOOL) );
1583 break;
1584 case WM_NCCALCSIZE:
1585 if (!wparam)
1586 push_data( data, (RECT *)lparam, sizeof(RECT) );
1587 else
1589 NCCALCSIZE_PARAMS *ncp = (NCCALCSIZE_PARAMS *)lparam;
1590 data->ps.ncp.rgrc[0] = ncp->rgrc[0];
1591 data->ps.ncp.rgrc[1] = ncp->rgrc[1];
1592 data->ps.ncp.rgrc[2] = ncp->rgrc[2];
1593 data->ps.ncp.hwnd = wine_server_user_handle( ncp->lppos->hwnd );
1594 data->ps.ncp.hwndInsertAfter = wine_server_user_handle( ncp->lppos->hwndInsertAfter );
1595 data->ps.ncp.x = ncp->lppos->x;
1596 data->ps.ncp.y = ncp->lppos->y;
1597 data->ps.ncp.cx = ncp->lppos->cx;
1598 data->ps.ncp.cy = ncp->lppos->cy;
1599 data->ps.ncp.flags = ncp->lppos->flags;
1600 push_data( data, &data->ps.ncp, sizeof(data->ps.ncp) );
1602 break;
1603 case EM_GETSEL:
1604 case SBM_GETRANGE:
1605 case CB_GETEDITSEL:
1606 if (wparam) push_data( data, (DWORD *)wparam, sizeof(DWORD) );
1607 if (lparam) push_data( data, (DWORD *)lparam, sizeof(DWORD) );
1608 break;
1609 case WM_NEXTMENU:
1611 MDINEXTMENU *mnm = (MDINEXTMENU *)lparam;
1612 data->ps.mnm.hmenuIn = wine_server_user_handle( mnm->hmenuIn );
1613 data->ps.mnm.hmenuNext = wine_server_user_handle( mnm->hmenuNext );
1614 data->ps.mnm.hwndNext = wine_server_user_handle( mnm->hwndNext );
1615 push_data( data, &data->ps.mnm, sizeof(data->ps.mnm) );
1616 break;
1618 case WM_MDICREATE:
1620 MDICREATESTRUCTW *mcs = (MDICREATESTRUCTW *)lparam;
1621 data->ps.mcs.szClass = pack_ptr( mcs->szClass );
1622 data->ps.mcs.szTitle = pack_ptr( mcs->szTitle );
1623 data->ps.mcs.hOwner = pack_ptr( mcs->hOwner );
1624 data->ps.mcs.x = mcs->x;
1625 data->ps.mcs.y = mcs->y;
1626 data->ps.mcs.cx = mcs->cx;
1627 data->ps.mcs.cy = mcs->cy;
1628 data->ps.mcs.style = mcs->style;
1629 data->ps.mcs.lParam = mcs->lParam;
1630 push_data( data, &data->ps.mcs, sizeof(data->ps.mcs) );
1631 break;
1633 case WM_ASKCBFORMATNAME:
1634 push_data( data, (WCHAR *)lparam, (strlenW((WCHAR *)lparam) + 1) * sizeof(WCHAR) );
1635 break;
1640 /***********************************************************************
1641 * unpack_reply
1643 * Unpack a message reply received from another process.
1645 static void unpack_reply( HWND hwnd, UINT message, WPARAM wparam, LPARAM lparam,
1646 void *buffer, size_t size )
1648 union packed_structs *ps = buffer;
1650 switch(message)
1652 case WM_NCCREATE:
1653 case WM_CREATE:
1654 if (size >= sizeof(ps->cs))
1656 CREATESTRUCTW *cs = (CREATESTRUCTW *)lparam;
1657 cs->lpCreateParams = unpack_ptr( ps->cs.lpCreateParams );
1658 cs->hInstance = unpack_ptr( ps->cs.hInstance );
1659 cs->hMenu = wine_server_ptr_handle( ps->cs.hMenu );
1660 cs->hwndParent = wine_server_ptr_handle( ps->cs.hwndParent );
1661 cs->cy = ps->cs.cy;
1662 cs->cx = ps->cs.cx;
1663 cs->y = ps->cs.y;
1664 cs->x = ps->cs.x;
1665 cs->style = ps->cs.style;
1666 cs->dwExStyle = ps->cs.dwExStyle;
1667 /* don't allow changing name and class pointers */
1669 break;
1670 case WM_GETTEXT:
1671 case WM_ASKCBFORMATNAME:
1672 memcpy( (WCHAR *)lparam, buffer, min( wparam*sizeof(WCHAR), size ));
1673 break;
1674 case WM_GETMINMAXINFO:
1675 memcpy( (MINMAXINFO *)lparam, buffer, min( sizeof(MINMAXINFO), size ));
1676 break;
1677 case WM_MEASUREITEM:
1678 if (size >= sizeof(ps->mis))
1680 MEASUREITEMSTRUCT *mis = (MEASUREITEMSTRUCT *)lparam;
1681 mis->CtlType = ps->mis.CtlType;
1682 mis->CtlID = ps->mis.CtlID;
1683 mis->itemID = ps->mis.itemID;
1684 mis->itemWidth = ps->mis.itemWidth;
1685 mis->itemHeight = ps->mis.itemHeight;
1686 mis->itemData = (ULONG_PTR)unpack_ptr( ps->mis.itemData );
1688 break;
1689 case WM_WINDOWPOSCHANGING:
1690 case WM_WINDOWPOSCHANGED:
1691 if (size >= sizeof(ps->wp))
1693 WINDOWPOS *wp = (WINDOWPOS *)lparam;
1694 wp->hwnd = wine_server_ptr_handle( ps->wp.hwnd );
1695 wp->hwndInsertAfter = wine_server_ptr_handle( ps->wp.hwndInsertAfter );
1696 wp->x = ps->wp.x;
1697 wp->y = ps->wp.y;
1698 wp->cx = ps->wp.cx;
1699 wp->cy = ps->wp.cy;
1700 wp->flags = ps->wp.flags;
1702 break;
1703 case WM_GETDLGCODE:
1704 if (lparam && size >= sizeof(ps->msg))
1706 MSG *msg = (MSG *)lparam;
1707 msg->hwnd = wine_server_ptr_handle( ps->msg.hwnd );
1708 msg->message = ps->msg.message;
1709 msg->wParam = (ULONG_PTR)unpack_ptr( ps->msg.wParam );
1710 msg->lParam = (ULONG_PTR)unpack_ptr( ps->msg.lParam );
1711 msg->time = ps->msg.time;
1712 msg->pt = ps->msg.pt;
1714 break;
1715 case SBM_GETSCROLLINFO:
1716 memcpy( (SCROLLINFO *)lparam, buffer, min( sizeof(SCROLLINFO), size ));
1717 break;
1718 case SBM_GETSCROLLBARINFO:
1719 memcpy( (SCROLLBARINFO *)lparam, buffer, min( sizeof(SCROLLBARINFO), size ));
1720 break;
1721 case EM_GETRECT:
1722 case CB_GETDROPPEDCONTROLRECT:
1723 case LB_GETITEMRECT:
1724 case WM_SIZING:
1725 case WM_MOVING:
1726 memcpy( (RECT *)lparam, buffer, min( sizeof(RECT), size ));
1727 break;
1728 case EM_GETLINE:
1729 size = min( size, (size_t)*(WORD *)lparam );
1730 memcpy( (WCHAR *)lparam, buffer, size );
1731 break;
1732 case LB_GETSELITEMS:
1733 memcpy( (UINT *)lparam, buffer, min( wparam*sizeof(UINT), size ));
1734 break;
1735 case LB_GETTEXT:
1736 case CB_GETLBTEXT:
1737 memcpy( (WCHAR *)lparam, buffer, size );
1738 break;
1739 case WM_NEXTMENU:
1740 if (size >= sizeof(ps->mnm))
1742 MDINEXTMENU *mnm = (MDINEXTMENU *)lparam;
1743 mnm->hmenuIn = wine_server_ptr_handle( ps->mnm.hmenuIn );
1744 mnm->hmenuNext = wine_server_ptr_handle( ps->mnm.hmenuNext );
1745 mnm->hwndNext = wine_server_ptr_handle( ps->mnm.hwndNext );
1747 break;
1748 case WM_MDIGETACTIVE:
1749 if (lparam) memcpy( (BOOL *)lparam, buffer, min( sizeof(BOOL), size ));
1750 break;
1751 case WM_NCCALCSIZE:
1752 if (!wparam)
1753 memcpy( (RECT *)lparam, buffer, min( sizeof(RECT), size ));
1754 else if (size >= sizeof(ps->ncp))
1756 NCCALCSIZE_PARAMS *ncp = (NCCALCSIZE_PARAMS *)lparam;
1757 ncp->rgrc[0] = ps->ncp.rgrc[0];
1758 ncp->rgrc[1] = ps->ncp.rgrc[1];
1759 ncp->rgrc[2] = ps->ncp.rgrc[2];
1760 ncp->lppos->hwnd = wine_server_ptr_handle( ps->ncp.hwnd );
1761 ncp->lppos->hwndInsertAfter = wine_server_ptr_handle( ps->ncp.hwndInsertAfter );
1762 ncp->lppos->x = ps->ncp.x;
1763 ncp->lppos->y = ps->ncp.y;
1764 ncp->lppos->cx = ps->ncp.cx;
1765 ncp->lppos->cy = ps->ncp.cy;
1766 ncp->lppos->flags = ps->ncp.flags;
1768 break;
1769 case EM_GETSEL:
1770 case SBM_GETRANGE:
1771 case CB_GETEDITSEL:
1772 if (wparam)
1774 memcpy( (DWORD *)wparam, buffer, min( sizeof(DWORD), size ));
1775 if (size <= sizeof(DWORD)) break;
1776 size -= sizeof(DWORD);
1777 buffer = (DWORD *)buffer + 1;
1779 if (lparam) memcpy( (DWORD *)lparam, buffer, min( sizeof(DWORD), size ));
1780 break;
1781 case WM_MDICREATE:
1782 if (size >= sizeof(ps->mcs))
1784 MDICREATESTRUCTW *mcs = (MDICREATESTRUCTW *)lparam;
1785 mcs->hOwner = unpack_ptr( ps->mcs.hOwner );
1786 mcs->x = ps->mcs.x;
1787 mcs->y = ps->mcs.y;
1788 mcs->cx = ps->mcs.cx;
1789 mcs->cy = ps->mcs.cy;
1790 mcs->style = ps->mcs.style;
1791 mcs->lParam = (LPARAM)unpack_ptr( ps->mcs.lParam );
1792 /* don't allow changing class and title pointers */
1794 break;
1795 default:
1796 ERR( "should not happen: unexpected message %x\n", message );
1797 break;
1802 /***********************************************************************
1803 * reply_message
1805 * Send a reply to a sent message.
1807 static void reply_message( struct received_message_info *info, LRESULT result, BOOL remove )
1809 struct packed_message data;
1810 int i, replied = info->flags & ISMEX_REPLIED;
1812 if (info->flags & ISMEX_NOTIFY) return; /* notify messages don't get replies */
1813 if (!remove && replied) return; /* replied already */
1815 memset( &data, 0, sizeof(data) );
1816 info->flags |= ISMEX_REPLIED;
1818 if (info->type == MSG_OTHER_PROCESS && !replied)
1820 pack_reply( info->msg.hwnd, info->msg.message, info->msg.wParam,
1821 info->msg.lParam, result, &data );
1824 SERVER_START_REQ( reply_message )
1826 req->result = result;
1827 req->remove = remove;
1828 for (i = 0; i < data.count; i++) wine_server_add_data( req, data.data[i], data.size[i] );
1829 wine_server_call( req );
1831 SERVER_END_REQ;
1835 /***********************************************************************
1836 * handle_internal_message
1838 * Handle an internal Wine message instead of calling the window proc.
1840 static LRESULT handle_internal_message( HWND hwnd, UINT msg, WPARAM wparam, LPARAM lparam )
1842 switch(msg)
1844 case WM_WINE_DESTROYWINDOW:
1845 return WIN_DestroyWindow( hwnd );
1846 case WM_WINE_SETWINDOWPOS:
1847 if (is_desktop_window( hwnd )) return 0;
1848 return USER_SetWindowPos( (WINDOWPOS *)lparam );
1849 case WM_WINE_SHOWWINDOW:
1850 if (is_desktop_window( hwnd )) return 0;
1851 return ShowWindow( hwnd, wparam );
1852 case WM_WINE_SETPARENT:
1853 if (is_desktop_window( hwnd )) return 0;
1854 return (LRESULT)SetParent( hwnd, (HWND)wparam );
1855 case WM_WINE_SETWINDOWLONG:
1856 return WIN_SetWindowLong( hwnd, (short)LOWORD(wparam), HIWORD(wparam), lparam, TRUE );
1857 case WM_WINE_ENABLEWINDOW:
1858 if (is_desktop_window( hwnd )) return 0;
1859 return EnableWindow( hwnd, wparam );
1860 case WM_WINE_SETACTIVEWINDOW:
1861 if (is_desktop_window( hwnd )) return 0;
1862 return (LRESULT)SetActiveWindow( (HWND)wparam );
1863 case WM_WINE_KEYBOARD_LL_HOOK:
1864 case WM_WINE_MOUSE_LL_HOOK:
1866 struct hook_extra_info *h_extra = (struct hook_extra_info *)lparam;
1868 return call_current_hook( h_extra->handle, HC_ACTION, wparam, h_extra->lparam );
1870 default:
1871 if (msg >= WM_WINE_FIRST_DRIVER_MSG && msg <= WM_WINE_LAST_DRIVER_MSG)
1872 return USER_Driver->pWindowMessage( hwnd, msg, wparam, lparam );
1873 FIXME( "unknown internal message %x\n", msg );
1874 return 0;
1878 /* since the WM_DDE_ACK response to a WM_DDE_EXECUTE message should contain the handle
1879 * to the memory handle, we keep track (in the server side) of all pairs of handle
1880 * used (the client passes its value and the content of the memory handle), and
1881 * the server stored both values (the client, and the local one, created after the
1882 * content). When a ACK message is generated, the list of pair is searched for a
1883 * matching pair, so that the client memory handle can be returned.
1885 struct DDE_pair {
1886 HGLOBAL client_hMem;
1887 HGLOBAL server_hMem;
1890 static struct DDE_pair* dde_pairs;
1891 static int dde_num_alloc;
1892 static int dde_num_used;
1894 static CRITICAL_SECTION dde_crst;
1895 static CRITICAL_SECTION_DEBUG critsect_debug =
1897 0, 0, &dde_crst,
1898 { &critsect_debug.ProcessLocksList, &critsect_debug.ProcessLocksList },
1899 0, 0, { (DWORD_PTR)(__FILE__ ": dde_crst") }
1901 static CRITICAL_SECTION dde_crst = { &critsect_debug, -1, 0, 0, 0, 0 };
1903 static BOOL dde_add_pair(HGLOBAL chm, HGLOBAL shm)
1905 int i;
1906 #define GROWBY 4
1908 EnterCriticalSection(&dde_crst);
1910 /* now remember the pair of hMem on both sides */
1911 if (dde_num_used == dde_num_alloc)
1913 struct DDE_pair* tmp;
1914 if (dde_pairs)
1915 tmp = HeapReAlloc( GetProcessHeap(), 0, dde_pairs,
1916 (dde_num_alloc + GROWBY) * sizeof(struct DDE_pair));
1917 else
1918 tmp = HeapAlloc( GetProcessHeap(), 0,
1919 (dde_num_alloc + GROWBY) * sizeof(struct DDE_pair));
1921 if (!tmp)
1923 LeaveCriticalSection(&dde_crst);
1924 return FALSE;
1926 dde_pairs = tmp;
1927 /* zero out newly allocated part */
1928 memset(&dde_pairs[dde_num_alloc], 0, GROWBY * sizeof(struct DDE_pair));
1929 dde_num_alloc += GROWBY;
1931 #undef GROWBY
1932 for (i = 0; i < dde_num_alloc; i++)
1934 if (dde_pairs[i].server_hMem == 0)
1936 dde_pairs[i].client_hMem = chm;
1937 dde_pairs[i].server_hMem = shm;
1938 dde_num_used++;
1939 break;
1942 LeaveCriticalSection(&dde_crst);
1943 return TRUE;
1946 static HGLOBAL dde_get_pair(HGLOBAL shm)
1948 int i;
1949 HGLOBAL ret = 0;
1951 EnterCriticalSection(&dde_crst);
1952 for (i = 0; i < dde_num_alloc; i++)
1954 if (dde_pairs[i].server_hMem == shm)
1956 /* free this pair */
1957 dde_pairs[i].server_hMem = 0;
1958 dde_num_used--;
1959 ret = dde_pairs[i].client_hMem;
1960 break;
1963 LeaveCriticalSection(&dde_crst);
1964 return ret;
1967 /***********************************************************************
1968 * post_dde_message
1970 * Post a DDE message
1972 static BOOL post_dde_message( struct packed_message *data, const struct send_message_info *info )
1974 void* ptr = NULL;
1975 int size = 0;
1976 UINT_PTR uiLo, uiHi;
1977 LPARAM lp = 0;
1978 HGLOBAL hunlock = 0;
1979 int i;
1980 DWORD res;
1982 if (!UnpackDDElParam( info->msg, info->lparam, &uiLo, &uiHi ))
1983 return FALSE;
1985 lp = info->lparam;
1986 switch (info->msg)
1988 /* DDE messages which don't require packing are:
1989 * WM_DDE_INITIATE
1990 * WM_DDE_TERMINATE
1991 * WM_DDE_REQUEST
1992 * WM_DDE_UNADVISE
1994 case WM_DDE_ACK:
1995 if (HIWORD(uiHi))
1997 /* uiHi should contain a hMem from WM_DDE_EXECUTE */
1998 HGLOBAL h = dde_get_pair( (HANDLE)uiHi );
1999 if (h)
2001 ULONGLONG hpack = pack_ptr( h );
2002 /* send back the value of h on the other side */
2003 push_data( data, &hpack, sizeof(hpack) );
2004 lp = uiLo;
2005 TRACE( "send dde-ack %lx %08lx => %p\n", uiLo, uiHi, h );
2008 else
2010 /* uiHi should contain either an atom or 0 */
2011 TRACE( "send dde-ack %lx atom=%lx\n", uiLo, uiHi );
2012 lp = MAKELONG( uiLo, uiHi );
2014 break;
2015 case WM_DDE_ADVISE:
2016 case WM_DDE_DATA:
2017 case WM_DDE_POKE:
2018 size = 0;
2019 if (uiLo)
2021 size = GlobalSize( (HGLOBAL)uiLo ) ;
2022 if ((info->msg == WM_DDE_ADVISE && size < sizeof(DDEADVISE)) ||
2023 (info->msg == WM_DDE_DATA && size < FIELD_OFFSET(DDEDATA, Value)) ||
2024 (info->msg == WM_DDE_POKE && size < FIELD_OFFSET(DDEPOKE, Value))
2026 return FALSE;
2028 else if (info->msg != WM_DDE_DATA) return FALSE;
2030 lp = uiHi;
2031 if (uiLo)
2033 if ((ptr = GlobalLock( (HGLOBAL)uiLo) ))
2035 DDEDATA *dde_data = ptr;
2036 TRACE("unused %d, fResponse %d, fRelease %d, fDeferUpd %d, fAckReq %d, cfFormat %d\n",
2037 dde_data->unused, dde_data->fResponse, dde_data->fRelease,
2038 dde_data->reserved, dde_data->fAckReq, dde_data->cfFormat);
2039 push_data( data, ptr, size );
2040 hunlock = (HGLOBAL)uiLo;
2043 TRACE( "send ddepack %u %lx\n", size, uiHi );
2044 break;
2045 case WM_DDE_EXECUTE:
2046 if (info->lparam)
2048 if ((ptr = GlobalLock( (HGLOBAL)info->lparam) ))
2050 push_data(data, ptr, GlobalSize( (HGLOBAL)info->lparam ));
2051 /* so that the other side can send it back on ACK */
2052 lp = info->lparam;
2053 hunlock = (HGLOBAL)info->lparam;
2056 break;
2058 SERVER_START_REQ( send_message )
2060 req->id = info->dest_tid;
2061 req->type = info->type;
2062 req->flags = 0;
2063 req->win = wine_server_user_handle( info->hwnd );
2064 req->msg = info->msg;
2065 req->wparam = info->wparam;
2066 req->lparam = lp;
2067 req->timeout = TIMEOUT_INFINITE;
2068 for (i = 0; i < data->count; i++)
2069 wine_server_add_data( req, data->data[i], data->size[i] );
2070 if ((res = wine_server_call( req )))
2072 if (res == STATUS_INVALID_PARAMETER)
2073 /* FIXME: find a STATUS_ value for this one */
2074 SetLastError( ERROR_INVALID_THREAD_ID );
2075 else
2076 SetLastError( RtlNtStatusToDosError(res) );
2078 else
2079 FreeDDElParam(info->msg, info->lparam);
2081 SERVER_END_REQ;
2082 if (hunlock) GlobalUnlock(hunlock);
2084 return !res;
2087 /***********************************************************************
2088 * unpack_dde_message
2090 * Unpack a posted DDE message received from another process.
2092 static BOOL unpack_dde_message( HWND hwnd, UINT message, WPARAM *wparam, LPARAM *lparam,
2093 void **buffer, size_t size )
2095 UINT_PTR uiLo, uiHi;
2096 HGLOBAL hMem = 0;
2097 void* ptr;
2099 switch (message)
2101 case WM_DDE_ACK:
2102 if (size)
2104 ULONGLONG hpack;
2105 /* hMem is being passed */
2106 if (size != sizeof(hpack)) return FALSE;
2107 if (!buffer || !*buffer) return FALSE;
2108 uiLo = *lparam;
2109 memcpy( &hpack, *buffer, size );
2110 hMem = unpack_ptr( hpack );
2111 uiHi = (UINT_PTR)hMem;
2112 TRACE("recv dde-ack %lx mem=%lx[%lx]\n", uiLo, uiHi, GlobalSize( hMem ));
2114 else
2116 uiLo = LOWORD( *lparam );
2117 uiHi = HIWORD( *lparam );
2118 TRACE("recv dde-ack %lx atom=%lx\n", uiLo, uiHi);
2120 *lparam = PackDDElParam( WM_DDE_ACK, uiLo, uiHi );
2121 break;
2122 case WM_DDE_ADVISE:
2123 case WM_DDE_DATA:
2124 case WM_DDE_POKE:
2125 if ((!buffer || !*buffer) && message != WM_DDE_DATA) return FALSE;
2126 uiHi = *lparam;
2127 if (size)
2129 if (!(hMem = GlobalAlloc( GMEM_MOVEABLE|GMEM_DDESHARE, size )))
2130 return FALSE;
2131 if ((ptr = GlobalLock( hMem )))
2133 memcpy( ptr, *buffer, size );
2134 GlobalUnlock( hMem );
2136 else
2138 GlobalFree( hMem );
2139 return FALSE;
2142 uiLo = (UINT_PTR)hMem;
2144 *lparam = PackDDElParam( message, uiLo, uiHi );
2145 break;
2146 case WM_DDE_EXECUTE:
2147 if (size)
2149 if (!buffer || !*buffer) return FALSE;
2150 if (!(hMem = GlobalAlloc( GMEM_MOVEABLE|GMEM_DDESHARE, size ))) return FALSE;
2151 if ((ptr = GlobalLock( hMem )))
2153 memcpy( ptr, *buffer, size );
2154 GlobalUnlock( hMem );
2155 TRACE( "exec: pairing c=%08lx s=%p\n", *lparam, hMem );
2156 if (!dde_add_pair( (HGLOBAL)*lparam, hMem ))
2158 GlobalFree( hMem );
2159 return FALSE;
2162 else
2164 GlobalFree( hMem );
2165 return FALSE;
2167 } else return FALSE;
2168 *lparam = (LPARAM)hMem;
2169 break;
2171 return TRUE;
2174 /***********************************************************************
2175 * call_window_proc
2177 * Call a window procedure and the corresponding hooks.
2179 static LRESULT call_window_proc( HWND hwnd, UINT msg, WPARAM wparam, LPARAM lparam,
2180 BOOL unicode, BOOL same_thread, enum wm_char_mapping mapping )
2182 LRESULT result = 0;
2183 CWPSTRUCT cwp;
2184 CWPRETSTRUCT cwpret;
2186 if (msg & 0x80000000)
2188 result = handle_internal_message( hwnd, msg, wparam, lparam );
2189 goto done;
2192 /* first the WH_CALLWNDPROC hook */
2193 hwnd = WIN_GetFullHandle( hwnd );
2194 cwp.lParam = lparam;
2195 cwp.wParam = wparam;
2196 cwp.message = msg;
2197 cwp.hwnd = hwnd;
2198 HOOK_CallHooks( WH_CALLWNDPROC, HC_ACTION, same_thread, (LPARAM)&cwp, unicode );
2200 /* now call the window procedure */
2201 if (!WINPROC_call_window( hwnd, msg, wparam, lparam, &result, unicode, mapping )) goto done;
2203 /* and finally the WH_CALLWNDPROCRET hook */
2204 cwpret.lResult = result;
2205 cwpret.lParam = lparam;
2206 cwpret.wParam = wparam;
2207 cwpret.message = msg;
2208 cwpret.hwnd = hwnd;
2209 HOOK_CallHooks( WH_CALLWNDPROCRET, HC_ACTION, same_thread, (LPARAM)&cwpret, unicode );
2210 done:
2211 return result;
2215 /***********************************************************************
2216 * send_parent_notify
2218 * Send a WM_PARENTNOTIFY to all ancestors of the given window, unless
2219 * the window has the WS_EX_NOPARENTNOTIFY style.
2221 static void send_parent_notify( HWND hwnd, WORD event, WORD idChild, POINT pt )
2223 /* pt has to be in the client coordinates of the parent window */
2224 MapWindowPoints( 0, hwnd, &pt, 1 );
2225 for (;;)
2227 HWND parent;
2229 if (!(GetWindowLongW( hwnd, GWL_STYLE ) & WS_CHILD)) break;
2230 if (GetWindowLongW( hwnd, GWL_EXSTYLE ) & WS_EX_NOPARENTNOTIFY) break;
2231 if (!(parent = GetParent(hwnd))) break;
2232 if (parent == GetDesktopWindow()) break;
2233 MapWindowPoints( hwnd, parent, &pt, 1 );
2234 hwnd = parent;
2235 SendMessageW( hwnd, WM_PARENTNOTIFY,
2236 MAKEWPARAM( event, idChild ), MAKELPARAM( pt.x, pt.y ) );
2241 /***********************************************************************
2242 * accept_hardware_message
2244 * Tell the server we have passed the message to the app
2245 * (even though we may end up dropping it later on)
2247 static void accept_hardware_message( UINT hw_id, BOOL remove, HWND new_hwnd )
2249 SERVER_START_REQ( accept_hardware_message )
2251 req->hw_id = hw_id;
2252 req->remove = remove;
2253 req->new_win = wine_server_user_handle( new_hwnd );
2254 if (wine_server_call( req ))
2255 FIXME("Failed to reply to MSG_HARDWARE message. Message may not be removed from queue.\n");
2257 SERVER_END_REQ;
2261 /***********************************************************************
2262 * process_keyboard_message
2264 * returns TRUE if the contents of 'msg' should be passed to the application
2266 static BOOL process_keyboard_message( MSG *msg, UINT hw_id, HWND hwnd_filter,
2267 UINT first, UINT last, BOOL remove )
2269 EVENTMSG event;
2271 if (msg->message == WM_KEYDOWN || msg->message == WM_SYSKEYDOWN ||
2272 msg->message == WM_KEYUP || msg->message == WM_SYSKEYUP)
2273 switch (msg->wParam)
2275 case VK_LSHIFT: case VK_RSHIFT:
2276 msg->wParam = VK_SHIFT;
2277 break;
2278 case VK_LCONTROL: case VK_RCONTROL:
2279 msg->wParam = VK_CONTROL;
2280 break;
2281 case VK_LMENU: case VK_RMENU:
2282 msg->wParam = VK_MENU;
2283 break;
2286 /* FIXME: is this really the right place for this hook? */
2287 event.message = msg->message;
2288 event.hwnd = msg->hwnd;
2289 event.time = msg->time;
2290 event.paramL = (msg->wParam & 0xFF) | (HIWORD(msg->lParam) << 8);
2291 event.paramH = msg->lParam & 0x7FFF;
2292 if (HIWORD(msg->lParam) & 0x0100) event.paramH |= 0x8000; /* special_key - bit */
2293 HOOK_CallHooks( WH_JOURNALRECORD, HC_ACTION, 0, (LPARAM)&event, TRUE );
2295 /* check message filters */
2296 if (msg->message < first || msg->message > last) return FALSE;
2297 if (!check_hwnd_filter( msg, hwnd_filter )) return FALSE;
2299 if (remove)
2301 if((msg->message == WM_KEYDOWN) &&
2302 (msg->hwnd != GetDesktopWindow()))
2304 /* Handle F1 key by sending out WM_HELP message */
2305 if (msg->wParam == VK_F1)
2307 PostMessageW( msg->hwnd, WM_KEYF1, 0, 0 );
2309 else if(msg->wParam >= VK_BROWSER_BACK &&
2310 msg->wParam <= VK_LAUNCH_APP2)
2312 /* FIXME: Process keystate */
2313 SendMessageW(msg->hwnd, WM_APPCOMMAND, (WPARAM)msg->hwnd, MAKELPARAM(0, (FAPPCOMMAND_KEY | (msg->wParam - VK_BROWSER_BACK + 1))));
2316 else if (msg->message == WM_KEYUP)
2318 /* Handle VK_APPS key by posting a WM_CONTEXTMENU message */
2319 if (msg->wParam == VK_APPS && !MENU_IsMenuActive())
2320 PostMessageW(msg->hwnd, WM_CONTEXTMENU, (WPARAM)msg->hwnd, -1);
2324 if (HOOK_CallHooks( WH_KEYBOARD, remove ? HC_ACTION : HC_NOREMOVE,
2325 LOWORD(msg->wParam), msg->lParam, TRUE ))
2327 /* skip this message */
2328 HOOK_CallHooks( WH_CBT, HCBT_KEYSKIPPED, LOWORD(msg->wParam), msg->lParam, TRUE );
2329 accept_hardware_message( hw_id, TRUE, 0 );
2330 return FALSE;
2332 accept_hardware_message( hw_id, remove, 0 );
2334 if ( msg->message == WM_KEYDOWN || msg->message == WM_KEYUP )
2335 if ( ImmProcessKey(msg->hwnd, GetKeyboardLayout(0), msg->wParam, msg->lParam, 0) )
2336 msg->wParam = VK_PROCESSKEY;
2338 return TRUE;
2342 /***********************************************************************
2343 * process_mouse_message
2345 * returns TRUE if the contents of 'msg' should be passed to the application
2347 static BOOL process_mouse_message( MSG *msg, UINT hw_id, ULONG_PTR extra_info, HWND hwnd_filter,
2348 UINT first, UINT last, BOOL remove )
2350 static MSG clk_msg;
2352 POINT pt;
2353 UINT message;
2354 INT hittest;
2355 EVENTMSG event;
2356 GUITHREADINFO info;
2357 MOUSEHOOKSTRUCT hook;
2358 BOOL eatMsg;
2360 /* find the window to dispatch this mouse message to */
2362 GetGUIThreadInfo( GetCurrentThreadId(), &info );
2363 if (info.hwndCapture)
2365 hittest = HTCLIENT;
2366 msg->hwnd = info.hwndCapture;
2368 else
2370 msg->hwnd = WINPOS_WindowFromPoint( msg->hwnd, msg->pt, &hittest );
2373 if (!msg->hwnd || !WIN_IsCurrentThread( msg->hwnd ))
2375 accept_hardware_message( hw_id, TRUE, msg->hwnd );
2376 return FALSE;
2379 /* FIXME: is this really the right place for this hook? */
2380 event.message = msg->message;
2381 event.time = msg->time;
2382 event.hwnd = msg->hwnd;
2383 event.paramL = msg->pt.x;
2384 event.paramH = msg->pt.y;
2385 HOOK_CallHooks( WH_JOURNALRECORD, HC_ACTION, 0, (LPARAM)&event, TRUE );
2387 if (!check_hwnd_filter( msg, hwnd_filter )) return FALSE;
2389 pt = msg->pt;
2390 message = msg->message;
2391 /* Note: windows has no concept of a non-client wheel message */
2392 if (message != WM_MOUSEWHEEL)
2394 if (hittest != HTCLIENT)
2396 message += WM_NCMOUSEMOVE - WM_MOUSEMOVE;
2397 msg->wParam = hittest;
2399 else
2401 /* coordinates don't get translated while tracking a menu */
2402 /* FIXME: should differentiate popups and top-level menus */
2403 if (!(info.flags & GUI_INMENUMODE))
2404 ScreenToClient( msg->hwnd, &pt );
2407 msg->lParam = MAKELONG( pt.x, pt.y );
2409 /* translate double clicks */
2411 if ((msg->message == WM_LBUTTONDOWN) ||
2412 (msg->message == WM_RBUTTONDOWN) ||
2413 (msg->message == WM_MBUTTONDOWN) ||
2414 (msg->message == WM_XBUTTONDOWN))
2416 BOOL update = remove;
2418 /* translate double clicks -
2419 * note that ...MOUSEMOVEs can slip in between
2420 * ...BUTTONDOWN and ...BUTTONDBLCLK messages */
2422 if ((info.flags & (GUI_INMENUMODE|GUI_INMOVESIZE)) ||
2423 hittest != HTCLIENT ||
2424 (GetClassLongA( msg->hwnd, GCL_STYLE ) & CS_DBLCLKS))
2426 if ((msg->message == clk_msg.message) &&
2427 (msg->hwnd == clk_msg.hwnd) &&
2428 (msg->wParam == clk_msg.wParam) &&
2429 (msg->time - clk_msg.time < GetDoubleClickTime()) &&
2430 (abs(msg->pt.x - clk_msg.pt.x) < GetSystemMetrics(SM_CXDOUBLECLK)/2) &&
2431 (abs(msg->pt.y - clk_msg.pt.y) < GetSystemMetrics(SM_CYDOUBLECLK)/2))
2433 message += (WM_LBUTTONDBLCLK - WM_LBUTTONDOWN);
2434 if (update)
2436 clk_msg.message = 0; /* clear the double click conditions */
2437 update = FALSE;
2441 if (message < first || message > last) return FALSE;
2442 /* update static double click conditions */
2443 if (update) clk_msg = *msg;
2445 else
2447 if (message < first || message > last) return FALSE;
2450 /* message is accepted now (but may still get dropped) */
2452 hook.pt = msg->pt;
2453 hook.hwnd = msg->hwnd;
2454 hook.wHitTestCode = hittest;
2455 hook.dwExtraInfo = extra_info;
2456 if (HOOK_CallHooks( WH_MOUSE, remove ? HC_ACTION : HC_NOREMOVE,
2457 message, (LPARAM)&hook, TRUE ))
2459 hook.pt = msg->pt;
2460 hook.hwnd = msg->hwnd;
2461 hook.wHitTestCode = hittest;
2462 hook.dwExtraInfo = extra_info;
2463 HOOK_CallHooks( WH_CBT, HCBT_CLICKSKIPPED, message, (LPARAM)&hook, TRUE );
2464 accept_hardware_message( hw_id, TRUE, 0 );
2465 return FALSE;
2468 if ((hittest == HTERROR) || (hittest == HTNOWHERE))
2470 SendMessageW( msg->hwnd, WM_SETCURSOR, (WPARAM)msg->hwnd,
2471 MAKELONG( hittest, msg->message ));
2472 accept_hardware_message( hw_id, TRUE, 0 );
2473 return FALSE;
2476 accept_hardware_message( hw_id, remove, 0 );
2478 if (!remove || info.hwndCapture)
2480 msg->message = message;
2481 return TRUE;
2484 eatMsg = FALSE;
2486 if ((msg->message == WM_LBUTTONDOWN) ||
2487 (msg->message == WM_RBUTTONDOWN) ||
2488 (msg->message == WM_MBUTTONDOWN) ||
2489 (msg->message == WM_XBUTTONDOWN))
2491 /* Send the WM_PARENTNOTIFY,
2492 * note that even for double/nonclient clicks
2493 * notification message is still WM_L/M/RBUTTONDOWN.
2495 send_parent_notify( msg->hwnd, msg->message, 0, msg->pt );
2497 /* Activate the window if needed */
2499 if (msg->hwnd != info.hwndActive)
2501 HWND hwndTop = msg->hwnd;
2502 while (hwndTop)
2504 if ((GetWindowLongW( hwndTop, GWL_STYLE ) & (WS_POPUP|WS_CHILD)) != WS_CHILD) break;
2505 hwndTop = GetParent( hwndTop );
2508 if (hwndTop && hwndTop != GetDesktopWindow())
2510 LONG ret = SendMessageW( msg->hwnd, WM_MOUSEACTIVATE, (WPARAM)hwndTop,
2511 MAKELONG( hittest, msg->message ) );
2512 switch(ret)
2514 case MA_NOACTIVATEANDEAT:
2515 eatMsg = TRUE;
2516 /* fall through */
2517 case MA_NOACTIVATE:
2518 break;
2519 case MA_ACTIVATEANDEAT:
2520 eatMsg = TRUE;
2521 /* fall through */
2522 case MA_ACTIVATE:
2523 case 0:
2524 if (!FOCUS_MouseActivate( hwndTop )) eatMsg = TRUE;
2525 break;
2526 default:
2527 WARN( "unknown WM_MOUSEACTIVATE code %d\n", ret );
2528 break;
2534 /* send the WM_SETCURSOR message */
2536 /* Windows sends the normal mouse message as the message parameter
2537 in the WM_SETCURSOR message even if it's non-client mouse message */
2538 SendMessageW( msg->hwnd, WM_SETCURSOR, (WPARAM)msg->hwnd, MAKELONG( hittest, msg->message ));
2540 msg->message = message;
2541 return !eatMsg;
2545 /***********************************************************************
2546 * process_hardware_message
2548 * Process a hardware message; return TRUE if message should be passed on to the app
2550 static BOOL process_hardware_message( MSG *msg, UINT hw_id, ULONG_PTR extra_info, HWND hwnd_filter,
2551 UINT first, UINT last, BOOL remove )
2553 if (is_keyboard_message( msg->message ))
2554 return process_keyboard_message( msg, hw_id, hwnd_filter, first, last, remove );
2556 if (is_mouse_message( msg->message ))
2557 return process_mouse_message( msg, hw_id, extra_info, hwnd_filter, first, last, remove );
2559 ERR( "unknown message type %x\n", msg->message );
2560 return FALSE;
2564 /***********************************************************************
2565 * call_sendmsg_callback
2567 * Call the callback function of SendMessageCallback.
2569 static inline void call_sendmsg_callback( SENDASYNCPROC callback, HWND hwnd, UINT msg,
2570 ULONG_PTR data, LRESULT result )
2572 if (!callback) return;
2574 if (TRACE_ON(relay))
2575 DPRINTF( "%04x:Call message callback %p (hwnd=%p,msg=%s,data=%08lx,result=%08lx)\n",
2576 GetCurrentThreadId(), callback, hwnd, SPY_GetMsgName( msg, hwnd ),
2577 data, result );
2578 callback( hwnd, msg, data, result );
2579 if (TRACE_ON(relay))
2580 DPRINTF( "%04x:Ret message callback %p (hwnd=%p,msg=%s,data=%08lx,result=%08lx)\n",
2581 GetCurrentThreadId(), callback, hwnd, SPY_GetMsgName( msg, hwnd ),
2582 data, result );
2586 /***********************************************************************
2587 * peek_message
2589 * Peek for a message matching the given parameters. Return FALSE if none available.
2590 * All pending sent messages are processed before returning.
2592 static BOOL peek_message( MSG *msg, HWND hwnd, UINT first, UINT last, UINT flags, UINT changed_mask )
2594 LRESULT result;
2595 struct user_thread_info *thread_info = get_user_thread_info();
2596 struct received_message_info info, *old_info;
2597 unsigned int hw_id = 0; /* id of previous hardware message */
2598 void *buffer;
2599 size_t buffer_size = 256;
2601 if (!(buffer = HeapAlloc( GetProcessHeap(), 0, buffer_size ))) return FALSE;
2603 if (!first && !last) last = ~0;
2604 if (hwnd == HWND_BROADCAST) hwnd = HWND_TOPMOST;
2606 for (;;)
2608 NTSTATUS res;
2609 size_t size = 0;
2610 const message_data_t *msg_data = buffer;
2612 SERVER_START_REQ( get_message )
2614 req->flags = flags;
2615 req->get_win = wine_server_user_handle( hwnd );
2616 req->get_first = first;
2617 req->get_last = last;
2618 req->hw_id = hw_id;
2619 req->wake_mask = changed_mask & (QS_SENDMESSAGE | QS_SMRESULT);
2620 req->changed_mask = changed_mask;
2621 wine_server_set_reply( req, buffer, buffer_size );
2622 if (!(res = wine_server_call( req )))
2624 size = wine_server_reply_size( reply );
2625 info.type = reply->type;
2626 info.msg.hwnd = wine_server_ptr_handle( reply->win );
2627 info.msg.message = reply->msg;
2628 info.msg.wParam = reply->wparam;
2629 info.msg.lParam = reply->lparam;
2630 info.msg.time = reply->time;
2631 info.msg.pt.x = 0;
2632 info.msg.pt.y = 0;
2633 hw_id = 0;
2634 thread_info->active_hooks = reply->active_hooks;
2636 else buffer_size = reply->total;
2638 SERVER_END_REQ;
2640 if (res)
2642 HeapFree( GetProcessHeap(), 0, buffer );
2643 if (res != STATUS_BUFFER_OVERFLOW) return FALSE;
2644 if (!(buffer = HeapAlloc( GetProcessHeap(), 0, buffer_size ))) return FALSE;
2645 continue;
2648 TRACE( "got type %d msg %x (%s) hwnd %p wp %lx lp %lx\n",
2649 info.type, info.msg.message,
2650 (info.type == MSG_WINEVENT) ? "MSG_WINEVENT" : SPY_GetMsgName(info.msg.message, info.msg.hwnd),
2651 info.msg.hwnd, info.msg.wParam, info.msg.lParam );
2653 switch(info.type)
2655 case MSG_ASCII:
2656 case MSG_UNICODE:
2657 info.flags = ISMEX_SEND;
2658 break;
2659 case MSG_NOTIFY:
2660 info.flags = ISMEX_NOTIFY;
2661 break;
2662 case MSG_CALLBACK:
2663 info.flags = ISMEX_CALLBACK;
2664 break;
2665 case MSG_CALLBACK_RESULT:
2666 if (size >= sizeof(msg_data->callback))
2667 call_sendmsg_callback( wine_server_get_ptr(msg_data->callback.callback),
2668 info.msg.hwnd, info.msg.message,
2669 msg_data->callback.data, msg_data->callback.result );
2670 continue;
2671 case MSG_WINEVENT:
2672 if (size >= sizeof(msg_data->winevent))
2674 WINEVENTPROC hook_proc;
2676 hook_proc = wine_server_get_ptr( msg_data->winevent.hook_proc );
2677 size -= sizeof(msg_data->winevent);
2678 if (size)
2680 WCHAR module[MAX_PATH];
2682 size = min( size, (MAX_PATH - 1) * sizeof(WCHAR) );
2683 memcpy( module, &msg_data->winevent + 1, size );
2684 module[size / sizeof(WCHAR)] = 0;
2685 if (!(hook_proc = get_hook_proc( hook_proc, module )))
2687 ERR( "invalid winevent hook module name %s\n", debugstr_w(module) );
2688 continue;
2692 if (TRACE_ON(relay))
2693 DPRINTF( "%04x:Call winevent proc %p (hook=%04x,event=%x,hwnd=%p,object_id=%lx,child_id=%lx,tid=%04x,time=%x)\n",
2694 GetCurrentThreadId(), hook_proc,
2695 msg_data->winevent.hook, info.msg.message, info.msg.hwnd, info.msg.wParam,
2696 info.msg.lParam, msg_data->winevent.tid, info.msg.time);
2698 hook_proc( wine_server_ptr_handle( msg_data->winevent.hook ), info.msg.message,
2699 info.msg.hwnd, info.msg.wParam, info.msg.lParam,
2700 msg_data->winevent.tid, info.msg.time );
2702 if (TRACE_ON(relay))
2703 DPRINTF( "%04x:Ret winevent proc %p (hook=%04x,event=%x,hwnd=%p,object_id=%lx,child_id=%lx,tid=%04x,time=%x)\n",
2704 GetCurrentThreadId(), hook_proc,
2705 msg_data->winevent.hook, info.msg.message, info.msg.hwnd, info.msg.wParam,
2706 info.msg.lParam, msg_data->winevent.tid, info.msg.time);
2708 continue;
2709 case MSG_OTHER_PROCESS:
2710 info.flags = ISMEX_SEND;
2711 if (!unpack_message( info.msg.hwnd, info.msg.message, &info.msg.wParam,
2712 &info.msg.lParam, &buffer, size ))
2714 /* ignore it */
2715 reply_message( &info, 0, TRUE );
2716 continue;
2718 break;
2719 case MSG_HARDWARE:
2720 if (size >= sizeof(msg_data->hardware))
2722 info.msg.pt.x = msg_data->hardware.x;
2723 info.msg.pt.y = msg_data->hardware.y;
2724 hw_id = msg_data->hardware.hw_id;
2725 if (!process_hardware_message( &info.msg, hw_id, msg_data->hardware.info,
2726 hwnd, first, last, flags & PM_REMOVE ))
2728 TRACE("dropping msg %x\n", info.msg.message );
2729 continue; /* ignore it */
2731 *msg = info.msg;
2732 thread_info->GetMessagePosVal = MAKELONG( info.msg.pt.x, info.msg.pt.y );
2733 thread_info->GetMessageTimeVal = info.msg.time;
2734 thread_info->GetMessageExtraInfoVal = msg_data->hardware.info;
2735 HeapFree( GetProcessHeap(), 0, buffer );
2736 HOOK_CallHooks( WH_GETMESSAGE, HC_ACTION, flags & PM_REMOVE, (LPARAM)msg, TRUE );
2737 return TRUE;
2739 continue;
2740 case MSG_POSTED:
2741 if (info.msg.message & 0x80000000) /* internal message */
2743 if (flags & PM_REMOVE)
2745 handle_internal_message( info.msg.hwnd, info.msg.message,
2746 info.msg.wParam, info.msg.lParam );
2747 /* if this is a nested call return right away */
2748 if (first == info.msg.message && last == info.msg.message) return FALSE;
2750 else
2751 peek_message( msg, info.msg.hwnd, info.msg.message,
2752 info.msg.message, flags | PM_REMOVE, changed_mask );
2753 continue;
2755 if (info.msg.message >= WM_DDE_FIRST && info.msg.message <= WM_DDE_LAST)
2757 if (!unpack_dde_message( info.msg.hwnd, info.msg.message, &info.msg.wParam,
2758 &info.msg.lParam, &buffer, size ))
2759 continue; /* ignore it */
2761 *msg = info.msg;
2762 msg->pt.x = (short)LOWORD( thread_info->GetMessagePosVal );
2763 msg->pt.y = (short)HIWORD( thread_info->GetMessagePosVal );
2764 thread_info->GetMessageTimeVal = info.msg.time;
2765 thread_info->GetMessageExtraInfoVal = 0;
2766 HeapFree( GetProcessHeap(), 0, buffer );
2767 HOOK_CallHooks( WH_GETMESSAGE, HC_ACTION, flags & PM_REMOVE, (LPARAM)msg, TRUE );
2768 return TRUE;
2771 /* if we get here, we have a sent message; call the window procedure */
2772 old_info = thread_info->receive_info;
2773 thread_info->receive_info = &info;
2774 result = call_window_proc( info.msg.hwnd, info.msg.message, info.msg.wParam,
2775 info.msg.lParam, (info.type != MSG_ASCII), FALSE,
2776 WMCHAR_MAP_RECVMESSAGE );
2777 reply_message( &info, result, TRUE );
2778 thread_info->receive_info = old_info;
2780 /* if some PM_QS* flags were specified, only handle sent messages from now on */
2781 if (HIWORD(flags) && !changed_mask) flags = PM_QS_SENDMESSAGE | LOWORD(flags);
2786 /***********************************************************************
2787 * process_sent_messages
2789 * Process all pending sent messages.
2791 static inline void process_sent_messages(void)
2793 MSG msg;
2794 peek_message( &msg, 0, 0, 0, PM_REMOVE | PM_QS_SENDMESSAGE, 0 );
2798 /***********************************************************************
2799 * get_server_queue_handle
2801 * Get a handle to the server message queue for the current thread.
2803 static HANDLE get_server_queue_handle(void)
2805 struct user_thread_info *thread_info = get_user_thread_info();
2806 HANDLE ret;
2808 if (!(ret = thread_info->server_queue))
2810 SERVER_START_REQ( get_msg_queue )
2812 wine_server_call( req );
2813 ret = wine_server_ptr_handle( reply->handle );
2815 SERVER_END_REQ;
2816 thread_info->server_queue = ret;
2817 if (!ret) ERR( "Cannot get server thread queue\n" );
2819 return ret;
2823 /***********************************************************************
2824 * wait_message_reply
2826 * Wait until a sent message gets replied to.
2828 static void wait_message_reply( UINT flags )
2830 HANDLE server_queue = get_server_queue_handle();
2832 for (;;)
2834 unsigned int wake_bits = 0;
2836 SERVER_START_REQ( set_queue_mask )
2838 req->wake_mask = QS_SMRESULT | ((flags & SMTO_BLOCK) ? 0 : QS_SENDMESSAGE);
2839 req->changed_mask = req->wake_mask;
2840 req->skip_wait = 1;
2841 if (!wine_server_call( req ))
2842 wake_bits = reply->wake_bits;
2844 SERVER_END_REQ;
2846 if (wake_bits & QS_SMRESULT) return; /* got a result */
2847 if (wake_bits & QS_SENDMESSAGE)
2849 /* Process the sent message immediately */
2850 process_sent_messages();
2851 continue;
2854 wow_handlers.wait_message( 1, &server_queue, INFINITE, QS_SENDMESSAGE, 0 );
2858 /***********************************************************************
2859 * put_message_in_queue
2861 * Put a sent message into the destination queue.
2862 * For inter-process message, reply_size is set to expected size of reply data.
2864 static BOOL put_message_in_queue( const struct send_message_info *info, size_t *reply_size )
2866 struct packed_message data;
2867 message_data_t msg_data;
2868 unsigned int res;
2869 int i;
2870 timeout_t timeout = TIMEOUT_INFINITE;
2872 /* Check for INFINITE timeout for compatibility with Win9x,
2873 * although Windows >= NT does not do so
2875 if (info->type != MSG_NOTIFY &&
2876 info->type != MSG_CALLBACK &&
2877 info->type != MSG_POSTED &&
2878 info->timeout &&
2879 info->timeout != INFINITE)
2881 /* timeout is signed despite the prototype */
2882 timeout = (timeout_t)max( 0, (int)info->timeout ) * -10000;
2885 memset( &data, 0, sizeof(data) );
2886 if (info->type == MSG_OTHER_PROCESS)
2888 *reply_size = pack_message( info->hwnd, info->msg, info->wparam, info->lparam, &data );
2889 if (data.count == -1)
2891 WARN( "cannot pack message %x\n", info->msg );
2892 return FALSE;
2895 else if (info->type == MSG_CALLBACK)
2897 msg_data.callback.callback = wine_server_client_ptr( info->callback );
2898 msg_data.callback.data = info->data;
2899 msg_data.callback.result = 0;
2900 data.data[0] = &msg_data;
2901 data.size[0] = sizeof(msg_data.callback);
2902 data.count = 1;
2904 else if (info->type == MSG_POSTED && info->msg >= WM_DDE_FIRST && info->msg <= WM_DDE_LAST)
2906 return post_dde_message( &data, info );
2909 SERVER_START_REQ( send_message )
2911 req->id = info->dest_tid;
2912 req->type = info->type;
2913 req->flags = 0;
2914 req->win = wine_server_user_handle( info->hwnd );
2915 req->msg = info->msg;
2916 req->wparam = info->wparam;
2917 req->lparam = info->lparam;
2918 req->timeout = timeout;
2920 if (info->flags & SMTO_ABORTIFHUNG) req->flags |= SEND_MSG_ABORT_IF_HUNG;
2921 for (i = 0; i < data.count; i++) wine_server_add_data( req, data.data[i], data.size[i] );
2922 if ((res = wine_server_call( req )))
2924 if (res == STATUS_INVALID_PARAMETER)
2925 /* FIXME: find a STATUS_ value for this one */
2926 SetLastError( ERROR_INVALID_THREAD_ID );
2927 else
2928 SetLastError( RtlNtStatusToDosError(res) );
2931 SERVER_END_REQ;
2932 return !res;
2936 /***********************************************************************
2937 * retrieve_reply
2939 * Retrieve a message reply from the server.
2941 static LRESULT retrieve_reply( const struct send_message_info *info,
2942 size_t reply_size, LRESULT *result )
2944 NTSTATUS status;
2945 void *reply_data = NULL;
2947 if (reply_size)
2949 if (!(reply_data = HeapAlloc( GetProcessHeap(), 0, reply_size )))
2951 WARN( "no memory for reply, will be truncated\n" );
2952 reply_size = 0;
2955 SERVER_START_REQ( get_message_reply )
2957 req->cancel = 1;
2958 if (reply_size) wine_server_set_reply( req, reply_data, reply_size );
2959 if (!(status = wine_server_call( req ))) *result = reply->result;
2960 reply_size = wine_server_reply_size( reply );
2962 SERVER_END_REQ;
2963 if (!status && reply_size)
2964 unpack_reply( info->hwnd, info->msg, info->wparam, info->lparam, reply_data, reply_size );
2966 HeapFree( GetProcessHeap(), 0, reply_data );
2968 TRACE( "hwnd %p msg %x (%s) wp %lx lp %lx got reply %lx (err=%d)\n",
2969 info->hwnd, info->msg, SPY_GetMsgName(info->msg, info->hwnd), info->wparam,
2970 info->lparam, *result, status );
2972 /* MSDN states that last error is 0 on timeout, but at least NT4 returns ERROR_TIMEOUT */
2973 if (status) SetLastError( RtlNtStatusToDosError(status) );
2974 return !status;
2978 /***********************************************************************
2979 * send_inter_thread_message
2981 static LRESULT send_inter_thread_message( const struct send_message_info *info, LRESULT *res_ptr )
2983 size_t reply_size = 0;
2985 TRACE( "hwnd %p msg %x (%s) wp %lx lp %lx\n",
2986 info->hwnd, info->msg, SPY_GetMsgName(info->msg, info->hwnd), info->wparam, info->lparam );
2988 USER_CheckNotLock();
2990 if (!put_message_in_queue( info, &reply_size )) return 0;
2992 /* there's no reply to wait for on notify/callback messages */
2993 if (info->type == MSG_NOTIFY || info->type == MSG_CALLBACK) return 1;
2995 wait_message_reply( info->flags );
2996 return retrieve_reply( info, reply_size, res_ptr );
3000 /***********************************************************************
3001 * send_inter_thread_callback
3003 static LRESULT send_inter_thread_callback( HWND hwnd, UINT msg, WPARAM wp, LPARAM lp,
3004 LRESULT *result, void *arg )
3006 struct send_message_info *info = arg;
3007 info->hwnd = hwnd;
3008 info->msg = msg;
3009 info->wparam = wp;
3010 info->lparam = lp;
3011 return send_inter_thread_message( info, result );
3015 /***********************************************************************
3016 * send_message
3018 * Backend implementation of the various SendMessage functions.
3020 static BOOL send_message( struct send_message_info *info, DWORD_PTR *res_ptr, BOOL unicode )
3022 DWORD dest_pid;
3023 BOOL ret;
3024 LRESULT result;
3026 if (is_broadcast(info->hwnd))
3028 EnumWindows( broadcast_message_callback, (LPARAM)info );
3029 if (res_ptr) *res_ptr = 1;
3030 return TRUE;
3033 if (!(info->dest_tid = GetWindowThreadProcessId( info->hwnd, &dest_pid ))) return FALSE;
3035 if (USER_IsExitingThread( info->dest_tid )) return FALSE;
3037 SPY_EnterMessage( SPY_SENDMESSAGE, info->hwnd, info->msg, info->wparam, info->lparam );
3039 if (info->dest_tid == GetCurrentThreadId())
3041 result = call_window_proc( info->hwnd, info->msg, info->wparam, info->lparam,
3042 unicode, TRUE, info->wm_char );
3043 if (info->type == MSG_CALLBACK)
3044 call_sendmsg_callback( info->callback, info->hwnd, info->msg, info->data, result );
3045 ret = TRUE;
3047 else
3049 if (dest_pid != GetCurrentProcessId() && (info->type == MSG_ASCII || info->type == MSG_UNICODE))
3050 info->type = MSG_OTHER_PROCESS;
3052 /* MSG_ASCII can be sent unconverted except for WM_CHAR; everything else needs to be Unicode */
3053 if (!unicode && is_unicode_message( info->msg ) &&
3054 (info->type != MSG_ASCII || info->msg == WM_CHAR))
3055 ret = WINPROC_CallProcAtoW( send_inter_thread_callback, info->hwnd, info->msg,
3056 info->wparam, info->lparam, &result, info, info->wm_char );
3057 else
3058 ret = send_inter_thread_message( info, &result );
3061 SPY_ExitMessage( SPY_RESULT_OK, info->hwnd, info->msg, result, info->wparam, info->lparam );
3062 if (ret && res_ptr) *res_ptr = result;
3063 return ret;
3067 /***********************************************************************
3068 * MSG_SendInternalMessageTimeout
3070 * Same as SendMessageTimeoutW but sends the message to a specific thread
3071 * without requiring a window handle. Only works for internal Wine messages.
3073 LRESULT MSG_SendInternalMessageTimeout( DWORD dest_pid, DWORD dest_tid,
3074 UINT msg, WPARAM wparam, LPARAM lparam,
3075 UINT flags, UINT timeout, PDWORD_PTR res_ptr )
3077 struct send_message_info info;
3078 LRESULT ret, result;
3080 assert( msg & 0x80000000 ); /* must be an internal Wine message */
3082 info.type = MSG_UNICODE;
3083 info.dest_tid = dest_tid;
3084 info.hwnd = 0;
3085 info.msg = msg;
3086 info.wparam = wparam;
3087 info.lparam = lparam;
3088 info.flags = flags;
3089 info.timeout = timeout;
3091 if (USER_IsExitingThread( dest_tid )) return 0;
3093 if (dest_tid == GetCurrentThreadId())
3095 result = handle_internal_message( 0, msg, wparam, lparam );
3096 ret = 1;
3098 else
3100 if (dest_pid != GetCurrentProcessId()) info.type = MSG_OTHER_PROCESS;
3101 ret = send_inter_thread_message( &info, &result );
3103 if (ret && res_ptr) *res_ptr = result;
3104 return ret;
3108 /***********************************************************************
3109 * SendMessageTimeoutW (USER32.@)
3111 LRESULT WINAPI SendMessageTimeoutW( HWND hwnd, UINT msg, WPARAM wparam, LPARAM lparam,
3112 UINT flags, UINT timeout, PDWORD_PTR res_ptr )
3114 struct send_message_info info;
3116 info.type = MSG_UNICODE;
3117 info.hwnd = hwnd;
3118 info.msg = msg;
3119 info.wparam = wparam;
3120 info.lparam = lparam;
3121 info.flags = flags;
3122 info.timeout = timeout;
3124 return send_message( &info, res_ptr, TRUE );
3127 /***********************************************************************
3128 * SendMessageTimeoutA (USER32.@)
3130 LRESULT WINAPI SendMessageTimeoutA( HWND hwnd, UINT msg, WPARAM wparam, LPARAM lparam,
3131 UINT flags, UINT timeout, PDWORD_PTR res_ptr )
3133 struct send_message_info info;
3135 info.type = MSG_ASCII;
3136 info.hwnd = hwnd;
3137 info.msg = msg;
3138 info.wparam = wparam;
3139 info.lparam = lparam;
3140 info.flags = flags;
3141 info.timeout = timeout;
3142 info.wm_char = WMCHAR_MAP_SENDMESSAGETIMEOUT;
3144 return send_message( &info, res_ptr, FALSE );
3148 /***********************************************************************
3149 * SendMessageW (USER32.@)
3151 LRESULT WINAPI SendMessageW( HWND hwnd, UINT msg, WPARAM wparam, LPARAM lparam )
3153 DWORD_PTR res = 0;
3154 struct send_message_info info;
3156 info.type = MSG_UNICODE;
3157 info.hwnd = hwnd;
3158 info.msg = msg;
3159 info.wparam = wparam;
3160 info.lparam = lparam;
3161 info.flags = SMTO_NORMAL;
3162 info.timeout = 0;
3164 send_message( &info, &res, TRUE );
3165 return res;
3169 /***********************************************************************
3170 * SendMessageA (USER32.@)
3172 LRESULT WINAPI SendMessageA( HWND hwnd, UINT msg, WPARAM wparam, LPARAM lparam )
3174 DWORD_PTR res = 0;
3175 struct send_message_info info;
3177 info.type = MSG_ASCII;
3178 info.hwnd = hwnd;
3179 info.msg = msg;
3180 info.wparam = wparam;
3181 info.lparam = lparam;
3182 info.flags = SMTO_NORMAL;
3183 info.timeout = 0;
3184 info.wm_char = WMCHAR_MAP_SENDMESSAGE;
3186 send_message( &info, &res, FALSE );
3187 return res;
3191 /***********************************************************************
3192 * SendNotifyMessageA (USER32.@)
3194 BOOL WINAPI SendNotifyMessageA( HWND hwnd, UINT msg, WPARAM wparam, LPARAM lparam )
3196 struct send_message_info info;
3198 if (is_pointer_message(msg))
3200 SetLastError( ERROR_MESSAGE_SYNC_ONLY );
3201 return FALSE;
3204 info.type = MSG_NOTIFY;
3205 info.hwnd = hwnd;
3206 info.msg = msg;
3207 info.wparam = wparam;
3208 info.lparam = lparam;
3209 info.flags = 0;
3210 info.wm_char = WMCHAR_MAP_SENDMESSAGETIMEOUT;
3212 return send_message( &info, NULL, FALSE );
3216 /***********************************************************************
3217 * SendNotifyMessageW (USER32.@)
3219 BOOL WINAPI SendNotifyMessageW( HWND hwnd, UINT msg, WPARAM wparam, LPARAM lparam )
3221 struct send_message_info info;
3223 if (is_pointer_message(msg))
3225 SetLastError( ERROR_MESSAGE_SYNC_ONLY );
3226 return FALSE;
3229 info.type = MSG_NOTIFY;
3230 info.hwnd = hwnd;
3231 info.msg = msg;
3232 info.wparam = wparam;
3233 info.lparam = lparam;
3234 info.flags = 0;
3236 return send_message( &info, NULL, TRUE );
3240 /***********************************************************************
3241 * SendMessageCallbackA (USER32.@)
3243 BOOL WINAPI SendMessageCallbackA( HWND hwnd, UINT msg, WPARAM wparam, LPARAM lparam,
3244 SENDASYNCPROC callback, ULONG_PTR data )
3246 struct send_message_info info;
3248 if (is_pointer_message(msg))
3250 SetLastError( ERROR_MESSAGE_SYNC_ONLY );
3251 return FALSE;
3254 info.type = MSG_CALLBACK;
3255 info.hwnd = hwnd;
3256 info.msg = msg;
3257 info.wparam = wparam;
3258 info.lparam = lparam;
3259 info.callback = callback;
3260 info.data = data;
3261 info.flags = 0;
3262 info.wm_char = WMCHAR_MAP_SENDMESSAGETIMEOUT;
3264 return send_message( &info, NULL, FALSE );
3268 /***********************************************************************
3269 * SendMessageCallbackW (USER32.@)
3271 BOOL WINAPI SendMessageCallbackW( HWND hwnd, UINT msg, WPARAM wparam, LPARAM lparam,
3272 SENDASYNCPROC callback, ULONG_PTR data )
3274 struct send_message_info info;
3276 if (is_pointer_message(msg))
3278 SetLastError( ERROR_MESSAGE_SYNC_ONLY );
3279 return FALSE;
3282 info.type = MSG_CALLBACK;
3283 info.hwnd = hwnd;
3284 info.msg = msg;
3285 info.wparam = wparam;
3286 info.lparam = lparam;
3287 info.callback = callback;
3288 info.data = data;
3289 info.flags = 0;
3291 return send_message( &info, NULL, TRUE );
3295 /***********************************************************************
3296 * ReplyMessage (USER32.@)
3298 BOOL WINAPI ReplyMessage( LRESULT result )
3300 struct received_message_info *info = get_user_thread_info()->receive_info;
3302 if (!info) return FALSE;
3303 reply_message( info, result, FALSE );
3304 return TRUE;
3308 /***********************************************************************
3309 * InSendMessage (USER32.@)
3311 BOOL WINAPI InSendMessage(void)
3313 return (InSendMessageEx(NULL) & (ISMEX_SEND|ISMEX_REPLIED)) == ISMEX_SEND;
3317 /***********************************************************************
3318 * InSendMessageEx (USER32.@)
3320 DWORD WINAPI InSendMessageEx( LPVOID reserved )
3322 struct received_message_info *info = get_user_thread_info()->receive_info;
3324 if (info) return info->flags;
3325 return ISMEX_NOSEND;
3329 /***********************************************************************
3330 * PostMessageA (USER32.@)
3332 BOOL WINAPI PostMessageA( HWND hwnd, UINT msg, WPARAM wparam, LPARAM lparam )
3334 if (!map_wparam_AtoW( msg, &wparam, WMCHAR_MAP_POSTMESSAGE )) return TRUE;
3335 return PostMessageW( hwnd, msg, wparam, lparam );
3339 /***********************************************************************
3340 * PostMessageW (USER32.@)
3342 BOOL WINAPI PostMessageW( HWND hwnd, UINT msg, WPARAM wparam, LPARAM lparam )
3344 struct send_message_info info;
3346 if (is_pointer_message( msg ))
3348 SetLastError( ERROR_MESSAGE_SYNC_ONLY );
3349 return FALSE;
3352 TRACE( "hwnd %p msg %x (%s) wp %lx lp %lx\n",
3353 hwnd, msg, SPY_GetMsgName(msg, hwnd), wparam, lparam );
3355 info.type = MSG_POSTED;
3356 info.hwnd = hwnd;
3357 info.msg = msg;
3358 info.wparam = wparam;
3359 info.lparam = lparam;
3360 info.flags = 0;
3362 if (is_broadcast(hwnd))
3364 EnumWindows( broadcast_message_callback, (LPARAM)&info );
3365 return TRUE;
3368 if (!hwnd) return PostThreadMessageW( GetCurrentThreadId(), msg, wparam, lparam );
3370 if (!(info.dest_tid = GetWindowThreadProcessId( hwnd, NULL ))) return FALSE;
3372 if (USER_IsExitingThread( info.dest_tid )) return TRUE;
3374 return put_message_in_queue( &info, NULL );
3378 /**********************************************************************
3379 * PostThreadMessageA (USER32.@)
3381 BOOL WINAPI PostThreadMessageA( DWORD thread, UINT msg, WPARAM wparam, LPARAM lparam )
3383 if (!map_wparam_AtoW( msg, &wparam, WMCHAR_MAP_POSTMESSAGE )) return TRUE;
3384 return PostThreadMessageW( thread, msg, wparam, lparam );
3388 /**********************************************************************
3389 * PostThreadMessageW (USER32.@)
3391 BOOL WINAPI PostThreadMessageW( DWORD thread, UINT msg, WPARAM wparam, LPARAM lparam )
3393 struct send_message_info info;
3395 if (is_pointer_message( msg ))
3397 SetLastError( ERROR_MESSAGE_SYNC_ONLY );
3398 return FALSE;
3400 if (USER_IsExitingThread( thread )) return TRUE;
3402 info.type = MSG_POSTED;
3403 info.dest_tid = thread;
3404 info.hwnd = 0;
3405 info.msg = msg;
3406 info.wparam = wparam;
3407 info.lparam = lparam;
3408 info.flags = 0;
3409 return put_message_in_queue( &info, NULL );
3413 /***********************************************************************
3414 * PostQuitMessage (USER32.@)
3416 * Posts a quit message to the current thread's message queue.
3418 * PARAMS
3419 * exit_code [I] Exit code to return from message loop.
3421 * RETURNS
3422 * Nothing.
3424 * NOTES
3425 * This function is not the same as calling:
3426 *|PostThreadMessage(GetCurrentThreadId(), WM_QUIT, exit_code, 0);
3427 * It instead sets a flag in the message queue that signals it to generate
3428 * a WM_QUIT message when there are no other pending sent or posted messages
3429 * in the queue.
3431 void WINAPI PostQuitMessage( INT exit_code )
3433 SERVER_START_REQ( post_quit_message )
3435 req->exit_code = exit_code;
3436 wine_server_call( req );
3438 SERVER_END_REQ;
3442 /***********************************************************************
3443 * PeekMessageW (USER32.@)
3445 BOOL WINAPI DECLSPEC_HOTPATCH PeekMessageW( MSG *msg_out, HWND hwnd, UINT first, UINT last, UINT flags )
3447 MSG msg;
3449 USER_CheckNotLock();
3451 /* check for graphics events */
3452 USER_Driver->pMsgWaitForMultipleObjectsEx( 0, NULL, 0, QS_ALLINPUT, 0 );
3454 if (!peek_message( &msg, hwnd, first, last, flags, 0 ))
3456 if (!(flags & PM_NOYIELD)) wow_handlers.wait_message( 0, NULL, 0, 0, 0 );
3457 return FALSE;
3460 /* copy back our internal safe copy of message data to msg_out.
3461 * msg_out is a variable from the *program*, so it can't be used
3462 * internally as it can get "corrupted" by our use of SendMessage()
3463 * (back to the program) inside the message handling itself. */
3464 if (!msg_out)
3466 SetLastError( ERROR_NOACCESS );
3467 return FALSE;
3469 *msg_out = msg;
3470 return TRUE;
3474 /***********************************************************************
3475 * PeekMessageA (USER32.@)
3477 BOOL WINAPI DECLSPEC_HOTPATCH PeekMessageA( MSG *msg, HWND hwnd, UINT first, UINT last, UINT flags )
3479 if (get_pending_wmchar( msg, first, last, (flags & PM_REMOVE) )) return TRUE;
3480 if (!PeekMessageW( msg, hwnd, first, last, flags )) return FALSE;
3481 map_wparam_WtoA( msg, (flags & PM_REMOVE) );
3482 return TRUE;
3486 /***********************************************************************
3487 * GetMessageW (USER32.@)
3489 BOOL WINAPI DECLSPEC_HOTPATCH GetMessageW( MSG *msg, HWND hwnd, UINT first, UINT last )
3491 HANDLE server_queue = get_server_queue_handle();
3492 unsigned int mask = QS_POSTMESSAGE | QS_SENDMESSAGE; /* Always selected */
3494 USER_CheckNotLock();
3496 /* check for graphics events */
3497 USER_Driver->pMsgWaitForMultipleObjectsEx( 0, NULL, 0, QS_ALLINPUT, 0 );
3499 if (first || last)
3501 if ((first <= WM_KEYLAST) && (last >= WM_KEYFIRST)) mask |= QS_KEY;
3502 if ( ((first <= WM_MOUSELAST) && (last >= WM_MOUSEFIRST)) ||
3503 ((first <= WM_NCMOUSELAST) && (last >= WM_NCMOUSEFIRST)) ) mask |= QS_MOUSE;
3504 if ((first <= WM_TIMER) && (last >= WM_TIMER)) mask |= QS_TIMER;
3505 if ((first <= WM_SYSTIMER) && (last >= WM_SYSTIMER)) mask |= QS_TIMER;
3506 if ((first <= WM_PAINT) && (last >= WM_PAINT)) mask |= QS_PAINT;
3508 else mask = QS_ALLINPUT;
3510 while (!peek_message( msg, hwnd, first, last, PM_REMOVE | (mask << 16), mask ))
3512 wow_handlers.wait_message( 1, &server_queue, INFINITE, mask, 0 );
3515 return (msg->message != WM_QUIT);
3519 /***********************************************************************
3520 * GetMessageA (USER32.@)
3522 BOOL WINAPI DECLSPEC_HOTPATCH GetMessageA( MSG *msg, HWND hwnd, UINT first, UINT last )
3524 if (get_pending_wmchar( msg, first, last, TRUE )) return TRUE;
3525 GetMessageW( msg, hwnd, first, last );
3526 map_wparam_WtoA( msg, TRUE );
3527 return (msg->message != WM_QUIT);
3531 /***********************************************************************
3532 * IsDialogMessageA (USER32.@)
3533 * IsDialogMessage (USER32.@)
3535 BOOL WINAPI IsDialogMessageA( HWND hwndDlg, LPMSG pmsg )
3537 MSG msg = *pmsg;
3538 map_wparam_AtoW( msg.message, &msg.wParam, WMCHAR_MAP_NOMAPPING );
3539 return IsDialogMessageW( hwndDlg, &msg );
3543 /***********************************************************************
3544 * TranslateMessage (USER32.@)
3546 * Implementation of TranslateMessage.
3548 * TranslateMessage translates virtual-key messages into character-messages,
3549 * as follows :
3550 * WM_KEYDOWN/WM_KEYUP combinations produce a WM_CHAR or WM_DEADCHAR message.
3551 * ditto replacing WM_* with WM_SYS*
3552 * This produces WM_CHAR messages only for keys mapped to ASCII characters
3553 * by the keyboard driver.
3555 * If the message is WM_KEYDOWN, WM_KEYUP, WM_SYSKEYDOWN, or WM_SYSKEYUP, the
3556 * return value is nonzero, regardless of the translation.
3559 BOOL WINAPI TranslateMessage( const MSG *msg )
3561 UINT message;
3562 WCHAR wp[2];
3563 BYTE state[256];
3565 if (msg->message < WM_KEYFIRST || msg->message > WM_KEYLAST) return FALSE;
3566 if (msg->message != WM_KEYDOWN && msg->message != WM_SYSKEYDOWN) return TRUE;
3568 TRACE_(key)("Translating key %s (%04lX), scancode %04x\n",
3569 SPY_GetVKeyName(msg->wParam), msg->wParam, HIWORD(msg->lParam));
3571 switch (msg->wParam)
3573 case VK_PACKET:
3574 message = (msg->message == WM_KEYDOWN) ? WM_CHAR : WM_SYSCHAR;
3575 TRACE_(key)("PostMessageW(%p,%s,%04x,%08x)\n",
3576 msg->hwnd, SPY_GetMsgName(message, msg->hwnd), HIWORD(msg->lParam), LOWORD(msg->lParam));
3577 PostMessageW( msg->hwnd, message, HIWORD(msg->lParam), LOWORD(msg->lParam));
3578 return TRUE;
3580 case VK_PROCESSKEY:
3581 return ImmTranslateMessage(msg->hwnd, msg->message, msg->wParam, msg->lParam);
3584 GetKeyboardState( state );
3585 /* FIXME : should handle ToUnicode yielding 2 */
3586 switch (ToUnicode(msg->wParam, HIWORD(msg->lParam), state, wp, 2, 0))
3588 case 1:
3589 message = (msg->message == WM_KEYDOWN) ? WM_CHAR : WM_SYSCHAR;
3590 TRACE_(key)("1 -> PostMessageW(%p,%s,%04x,%08lx)\n",
3591 msg->hwnd, SPY_GetMsgName(message, msg->hwnd), wp[0], msg->lParam);
3592 PostMessageW( msg->hwnd, message, wp[0], msg->lParam );
3593 break;
3595 case -1:
3596 message = (msg->message == WM_KEYDOWN) ? WM_DEADCHAR : WM_SYSDEADCHAR;
3597 TRACE_(key)("-1 -> PostMessageW(%p,%s,%04x,%08lx)\n",
3598 msg->hwnd, SPY_GetMsgName(message, msg->hwnd), wp[0], msg->lParam);
3599 PostMessageW( msg->hwnd, message, wp[0], msg->lParam );
3600 break;
3602 return TRUE;
3606 /***********************************************************************
3607 * DispatchMessageA (USER32.@)
3609 * See DispatchMessageW.
3611 LRESULT WINAPI DECLSPEC_HOTPATCH DispatchMessageA( const MSG* msg )
3613 LRESULT retval;
3615 /* Process timer messages */
3616 if ((msg->message == WM_TIMER) || (msg->message == WM_SYSTIMER))
3618 if (msg->lParam)
3620 __TRY
3622 retval = CallWindowProcA( (WNDPROC)msg->lParam, msg->hwnd,
3623 msg->message, msg->wParam, GetTickCount() );
3625 __EXCEPT_PAGE_FAULT
3627 retval = 0;
3629 __ENDTRY
3630 return retval;
3633 if (!msg->hwnd) return 0;
3635 SPY_EnterMessage( SPY_DISPATCHMESSAGE, msg->hwnd, msg->message,
3636 msg->wParam, msg->lParam );
3638 if (!WINPROC_call_window( msg->hwnd, msg->message, msg->wParam, msg->lParam,
3639 &retval, FALSE, WMCHAR_MAP_DISPATCHMESSAGE ))
3641 if (!IsWindow( msg->hwnd )) SetLastError( ERROR_INVALID_WINDOW_HANDLE );
3642 else SetLastError( ERROR_MESSAGE_SYNC_ONLY );
3643 retval = 0;
3646 SPY_ExitMessage( SPY_RESULT_OK, msg->hwnd, msg->message, retval,
3647 msg->wParam, msg->lParam );
3649 if (msg->message == WM_PAINT)
3651 /* send a WM_NCPAINT and WM_ERASEBKGND if the non-client area is still invalid */
3652 HRGN hrgn = CreateRectRgn( 0, 0, 0, 0 );
3653 GetUpdateRgn( msg->hwnd, hrgn, TRUE );
3654 DeleteObject( hrgn );
3656 return retval;
3660 /***********************************************************************
3661 * DispatchMessageW (USER32.@) Process a message
3663 * Process the message specified in the structure *_msg_.
3665 * If the lpMsg parameter points to a WM_TIMER message and the
3666 * parameter of the WM_TIMER message is not NULL, the lParam parameter
3667 * points to the function that is called instead of the window
3668 * procedure. The function stored in lParam (timer callback) is protected
3669 * from causing page-faults.
3671 * The message must be valid.
3673 * RETURNS
3675 * DispatchMessage() returns the result of the window procedure invoked.
3677 * CONFORMANCE
3679 * ECMA-234, Win32
3682 LRESULT WINAPI DECLSPEC_HOTPATCH DispatchMessageW( const MSG* msg )
3684 LRESULT retval;
3686 /* Process timer messages */
3687 if ((msg->message == WM_TIMER) || (msg->message == WM_SYSTIMER))
3689 if (msg->lParam)
3691 __TRY
3693 retval = CallWindowProcW( (WNDPROC)msg->lParam, msg->hwnd,
3694 msg->message, msg->wParam, GetTickCount() );
3696 __EXCEPT_PAGE_FAULT
3698 retval = 0;
3700 __ENDTRY
3701 return retval;
3704 if (!msg->hwnd) return 0;
3706 SPY_EnterMessage( SPY_DISPATCHMESSAGE, msg->hwnd, msg->message,
3707 msg->wParam, msg->lParam );
3709 if (!WINPROC_call_window( msg->hwnd, msg->message, msg->wParam, msg->lParam,
3710 &retval, TRUE, WMCHAR_MAP_DISPATCHMESSAGE ))
3712 if (!IsWindow( msg->hwnd )) SetLastError( ERROR_INVALID_WINDOW_HANDLE );
3713 else SetLastError( ERROR_MESSAGE_SYNC_ONLY );
3714 retval = 0;
3717 SPY_ExitMessage( SPY_RESULT_OK, msg->hwnd, msg->message, retval,
3718 msg->wParam, msg->lParam );
3720 if (msg->message == WM_PAINT)
3722 /* send a WM_NCPAINT and WM_ERASEBKGND if the non-client area is still invalid */
3723 HRGN hrgn = CreateRectRgn( 0, 0, 0, 0 );
3724 GetUpdateRgn( msg->hwnd, hrgn, TRUE );
3725 DeleteObject( hrgn );
3727 return retval;
3731 /***********************************************************************
3732 * GetMessagePos (USER.119)
3733 * GetMessagePos (USER32.@)
3735 * The GetMessagePos() function returns a long value representing a
3736 * cursor position, in screen coordinates, when the last message
3737 * retrieved by the GetMessage() function occurs. The x-coordinate is
3738 * in the low-order word of the return value, the y-coordinate is in
3739 * the high-order word. The application can use the MAKEPOINT()
3740 * macro to obtain a POINT structure from the return value.
3742 * For the current cursor position, use GetCursorPos().
3744 * RETURNS
3746 * Cursor position of last message on success, zero on failure.
3748 * CONFORMANCE
3750 * ECMA-234, Win32
3753 DWORD WINAPI GetMessagePos(void)
3755 return get_user_thread_info()->GetMessagePosVal;
3759 /***********************************************************************
3760 * GetMessageTime (USER.120)
3761 * GetMessageTime (USER32.@)
3763 * GetMessageTime() returns the message time for the last message
3764 * retrieved by the function. The time is measured in milliseconds with
3765 * the same offset as GetTickCount().
3767 * Since the tick count wraps, this is only useful for moderately short
3768 * relative time comparisons.
3770 * RETURNS
3772 * Time of last message on success, zero on failure.
3774 LONG WINAPI GetMessageTime(void)
3776 return get_user_thread_info()->GetMessageTimeVal;
3780 /***********************************************************************
3781 * GetMessageExtraInfo (USER.288)
3782 * GetMessageExtraInfo (USER32.@)
3784 LPARAM WINAPI GetMessageExtraInfo(void)
3786 return get_user_thread_info()->GetMessageExtraInfoVal;
3790 /***********************************************************************
3791 * SetMessageExtraInfo (USER32.@)
3793 LPARAM WINAPI SetMessageExtraInfo(LPARAM lParam)
3795 struct user_thread_info *thread_info = get_user_thread_info();
3796 LONG old_value = thread_info->GetMessageExtraInfoVal;
3797 thread_info->GetMessageExtraInfoVal = lParam;
3798 return old_value;
3802 /***********************************************************************
3803 * WaitMessage (USER.112) Suspend thread pending messages
3804 * WaitMessage (USER32.@) Suspend thread pending messages
3806 * WaitMessage() suspends a thread until events appear in the thread's
3807 * queue.
3809 BOOL WINAPI WaitMessage(void)
3811 return (MsgWaitForMultipleObjectsEx( 0, NULL, INFINITE, QS_ALLINPUT, 0 ) != WAIT_FAILED);
3815 /***********************************************************************
3816 * MsgWaitForMultipleObjectsEx (USER32.@)
3818 DWORD WINAPI MsgWaitForMultipleObjectsEx( DWORD count, CONST HANDLE *pHandles,
3819 DWORD timeout, DWORD mask, DWORD flags )
3821 HANDLE handles[MAXIMUM_WAIT_OBJECTS];
3822 DWORD i;
3824 if (count > MAXIMUM_WAIT_OBJECTS-1)
3826 SetLastError( ERROR_INVALID_PARAMETER );
3827 return WAIT_FAILED;
3830 /* set the queue mask */
3831 SERVER_START_REQ( set_queue_mask )
3833 req->wake_mask = (flags & MWMO_INPUTAVAILABLE) ? mask : 0;
3834 req->changed_mask = mask;
3835 req->skip_wait = 0;
3836 wine_server_call( req );
3838 SERVER_END_REQ;
3840 /* add the queue to the handle list */
3841 for (i = 0; i < count; i++) handles[i] = pHandles[i];
3842 handles[count] = get_server_queue_handle();
3844 return wow_handlers.wait_message( count+1, handles, timeout, mask, flags );
3848 /***********************************************************************
3849 * MsgWaitForMultipleObjects (USER32.@)
3851 DWORD WINAPI MsgWaitForMultipleObjects( DWORD count, CONST HANDLE *handles,
3852 BOOL wait_all, DWORD timeout, DWORD mask )
3854 return MsgWaitForMultipleObjectsEx( count, handles, timeout, mask,
3855 wait_all ? MWMO_WAITALL : 0 );
3859 /***********************************************************************
3860 * WaitForInputIdle (USER32.@)
3862 DWORD WINAPI WaitForInputIdle( HANDLE hProcess, DWORD dwTimeOut )
3864 DWORD start_time, elapsed, ret;
3865 HANDLE handles[2];
3867 handles[0] = hProcess;
3868 SERVER_START_REQ( get_process_idle_event )
3870 req->handle = wine_server_obj_handle( hProcess );
3871 wine_server_call_err( req );
3872 handles[1] = wine_server_ptr_handle( reply->event );
3874 SERVER_END_REQ;
3875 if (!handles[1]) return WAIT_FAILED; /* no event to wait on */
3877 start_time = GetTickCount();
3878 elapsed = 0;
3880 TRACE("waiting for %p\n", handles[1] );
3883 ret = MsgWaitForMultipleObjects ( 2, handles, FALSE, dwTimeOut - elapsed, QS_SENDMESSAGE );
3884 switch (ret)
3886 case WAIT_OBJECT_0:
3887 return 0;
3888 case WAIT_OBJECT_0+2:
3889 process_sent_messages();
3890 break;
3891 case WAIT_TIMEOUT:
3892 case WAIT_FAILED:
3893 TRACE("timeout or error\n");
3894 return ret;
3895 default:
3896 TRACE("finished\n");
3897 return 0;
3899 if (dwTimeOut != INFINITE)
3901 elapsed = GetTickCount() - start_time;
3902 if (elapsed > dwTimeOut)
3903 break;
3906 while (1);
3908 return WAIT_TIMEOUT;
3912 /***********************************************************************
3913 * RegisterWindowMessageA (USER32.@)
3914 * RegisterWindowMessage (USER.118)
3916 UINT WINAPI RegisterWindowMessageA( LPCSTR str )
3918 UINT ret = GlobalAddAtomA(str);
3919 TRACE("%s, ret=%x\n", str, ret);
3920 return ret;
3924 /***********************************************************************
3925 * RegisterWindowMessageW (USER32.@)
3927 UINT WINAPI RegisterWindowMessageW( LPCWSTR str )
3929 UINT ret = GlobalAddAtomW(str);
3930 TRACE("%s ret=%x\n", debugstr_w(str), ret);
3931 return ret;
3934 typedef struct BroadcastParm
3936 DWORD flags;
3937 LPDWORD recipients;
3938 UINT msg;
3939 WPARAM wp;
3940 LPARAM lp;
3941 DWORD success;
3942 HWINSTA winsta;
3943 } BroadcastParm;
3945 static BOOL CALLBACK bcast_childwindow( HWND hw, LPARAM lp )
3947 BroadcastParm *parm = (BroadcastParm*)lp;
3948 DWORD_PTR retval = 0;
3949 LRESULT lresult;
3951 if (parm->flags & BSF_IGNORECURRENTTASK && WIN_IsCurrentProcess(hw))
3953 TRACE("Not telling myself %p\n", hw);
3954 return TRUE;
3957 /* I don't know 100% for sure if this is what Windows does, but it fits the tests */
3958 if (parm->flags & BSF_QUERY)
3960 TRACE("Telling window %p using SendMessageTimeout\n", hw);
3962 /* Not tested for conflicting flags */
3963 if (parm->flags & BSF_FORCEIFHUNG || parm->flags & BSF_NOHANG)
3964 lresult = SendMessageTimeoutW( hw, parm->msg, parm->wp, parm->lp, SMTO_ABORTIFHUNG, 2000, &retval );
3965 else if (parm->flags & BSF_NOTIMEOUTIFNOTHUNG)
3966 lresult = SendMessageTimeoutW( hw, parm->msg, parm->wp, parm->lp, SMTO_NOTIMEOUTIFNOTHUNG, 2000, &retval );
3967 else
3968 lresult = SendMessageTimeoutW( hw, parm->msg, parm->wp, parm->lp, SMTO_NORMAL, 2000, &retval );
3970 if (!lresult && GetLastError() == ERROR_TIMEOUT)
3972 WARN("Timed out!\n");
3973 if (!(parm->flags & BSF_FORCEIFHUNG))
3974 goto fail;
3976 if (retval == BROADCAST_QUERY_DENY)
3977 goto fail;
3979 return TRUE;
3981 fail:
3982 parm->success = 0;
3983 return FALSE;
3985 else if (parm->flags & BSF_POSTMESSAGE)
3987 TRACE("Telling window %p using PostMessage\n", hw);
3988 PostMessageW( hw, parm->msg, parm->wp, parm->lp );
3990 else
3992 TRACE("Telling window %p using SendNotifyMessage\n", hw);
3993 SendNotifyMessageW( hw, parm->msg, parm->wp, parm->lp );
3996 return TRUE;
3999 static BOOL CALLBACK bcast_desktop( LPWSTR desktop, LPARAM lp )
4001 BOOL ret;
4002 HDESK hdesktop;
4003 BroadcastParm *parm = (BroadcastParm*)lp;
4005 TRACE("desktop: %s\n", debugstr_w( desktop ));
4007 hdesktop = open_winstation_desktop( parm->winsta, desktop, 0, FALSE, DESKTOP_ENUMERATE|DESKTOP_WRITEOBJECTS|STANDARD_RIGHTS_WRITE );
4008 if (!hdesktop)
4010 FIXME("Could not open desktop %s\n", debugstr_w(desktop));
4011 return TRUE;
4014 ret = EnumDesktopWindows( hdesktop, bcast_childwindow, lp );
4015 CloseDesktop(hdesktop);
4016 TRACE("-->%d\n", ret);
4017 return parm->success;
4020 static BOOL CALLBACK bcast_winsta( LPWSTR winsta, LPARAM lp )
4022 BOOL ret;
4023 HWINSTA hwinsta = OpenWindowStationW( winsta, FALSE, WINSTA_ENUMDESKTOPS );
4024 TRACE("hwinsta: %p/%s/%08x\n", hwinsta, debugstr_w( winsta ), GetLastError());
4025 if (!hwinsta)
4026 return TRUE;
4027 ((BroadcastParm *)lp)->winsta = hwinsta;
4028 ret = EnumDesktopsW( hwinsta, bcast_desktop, lp );
4029 CloseWindowStation( hwinsta );
4030 TRACE("-->%d\n", ret);
4031 return ret;
4034 /***********************************************************************
4035 * BroadcastSystemMessageA (USER32.@)
4036 * BroadcastSystemMessage (USER32.@)
4038 LONG WINAPI BroadcastSystemMessageA( DWORD flags, LPDWORD recipients, UINT msg, WPARAM wp, LPARAM lp )
4040 return BroadcastSystemMessageExA( flags, recipients, msg, wp, lp, NULL );
4044 /***********************************************************************
4045 * BroadcastSystemMessageW (USER32.@)
4047 LONG WINAPI BroadcastSystemMessageW( DWORD flags, LPDWORD recipients, UINT msg, WPARAM wp, LPARAM lp )
4049 return BroadcastSystemMessageExW( flags, recipients, msg, wp, lp, NULL );
4052 /***********************************************************************
4053 * BroadcastSystemMessageExA (USER32.@)
4055 LONG WINAPI BroadcastSystemMessageExA( DWORD flags, LPDWORD recipients, UINT msg, WPARAM wp, LPARAM lp, PBSMINFO pinfo )
4057 map_wparam_AtoW( msg, &wp, WMCHAR_MAP_NOMAPPING );
4058 return BroadcastSystemMessageExW( flags, recipients, msg, wp, lp, NULL );
4062 /***********************************************************************
4063 * BroadcastSystemMessageExW (USER32.@)
4065 LONG WINAPI BroadcastSystemMessageExW( DWORD flags, LPDWORD recipients, UINT msg, WPARAM wp, LPARAM lp, PBSMINFO pinfo )
4067 BroadcastParm parm;
4068 DWORD recips = BSM_ALLCOMPONENTS;
4069 BOOL ret = TRUE;
4070 static const DWORD all_flags = ( BSF_QUERY | BSF_IGNORECURRENTTASK | BSF_FLUSHDISK | BSF_NOHANG
4071 | BSF_POSTMESSAGE | BSF_FORCEIFHUNG | BSF_NOTIMEOUTIFNOTHUNG
4072 | BSF_ALLOWSFW | BSF_SENDNOTIFYMESSAGE | BSF_RETURNHDESK | BSF_LUID );
4074 TRACE("Flags: %08x, recipients: %p(0x%x), msg: %04x, wparam: %08lx, lparam: %08lx\n", flags, recipients,
4075 (recipients ? *recipients : recips), msg, wp, lp);
4077 if (flags & ~all_flags)
4079 SetLastError(ERROR_INVALID_PARAMETER);
4080 return 0;
4083 if (!recipients)
4084 recipients = &recips;
4086 if ( pinfo && flags & BSF_QUERY )
4087 FIXME("Not returning PBSMINFO information yet\n");
4089 parm.flags = flags;
4090 parm.recipients = recipients;
4091 parm.msg = msg;
4092 parm.wp = wp;
4093 parm.lp = lp;
4094 parm.success = TRUE;
4096 if (*recipients & BSM_ALLDESKTOPS || *recipients == BSM_ALLCOMPONENTS)
4097 ret = EnumWindowStationsW(bcast_winsta, (LONG_PTR)&parm);
4098 else if (*recipients & BSM_APPLICATIONS)
4100 EnumWindows(bcast_childwindow, (LONG_PTR)&parm);
4101 ret = parm.success;
4103 else
4104 FIXME("Recipients %08x not supported!\n", *recipients);
4106 return ret;
4109 /***********************************************************************
4110 * SetMessageQueue (USER32.@)
4112 BOOL WINAPI SetMessageQueue( INT size )
4114 /* now obsolete the message queue will be expanded dynamically as necessary */
4115 return TRUE;
4119 /***********************************************************************
4120 * MessageBeep (USER32.@)
4122 BOOL WINAPI MessageBeep( UINT i )
4124 BOOL active = TRUE;
4125 SystemParametersInfoA( SPI_GETBEEP, 0, &active, FALSE );
4126 if (active) USER_Driver->pBeep();
4127 return TRUE;
4131 /***********************************************************************
4132 * SetTimer (USER32.@)
4134 UINT_PTR WINAPI SetTimer( HWND hwnd, UINT_PTR id, UINT timeout, TIMERPROC proc )
4136 UINT_PTR ret;
4137 WNDPROC winproc = 0;
4139 if (proc) winproc = WINPROC_AllocProc( (WNDPROC)proc, FALSE );
4141 SERVER_START_REQ( set_win_timer )
4143 req->win = wine_server_user_handle( hwnd );
4144 req->msg = WM_TIMER;
4145 req->id = id;
4146 req->rate = max( timeout, SYS_TIMER_RATE );
4147 req->lparam = (ULONG_PTR)winproc;
4148 if (!wine_server_call_err( req ))
4150 ret = reply->id;
4151 if (!ret) ret = TRUE;
4153 else ret = 0;
4155 SERVER_END_REQ;
4157 TRACE("Added %p %lx %p timeout %d\n", hwnd, id, winproc, timeout );
4158 return ret;
4162 /***********************************************************************
4163 * SetSystemTimer (USER32.@)
4165 UINT_PTR WINAPI SetSystemTimer( HWND hwnd, UINT_PTR id, UINT timeout, TIMERPROC proc )
4167 UINT_PTR ret;
4168 WNDPROC winproc = 0;
4170 if (proc) winproc = WINPROC_AllocProc( (WNDPROC)proc, FALSE );
4172 SERVER_START_REQ( set_win_timer )
4174 req->win = wine_server_user_handle( hwnd );
4175 req->msg = WM_SYSTIMER;
4176 req->id = id;
4177 req->rate = max( timeout, SYS_TIMER_RATE );
4178 req->lparam = (ULONG_PTR)winproc;
4179 if (!wine_server_call_err( req ))
4181 ret = reply->id;
4182 if (!ret) ret = TRUE;
4184 else ret = 0;
4186 SERVER_END_REQ;
4188 TRACE("Added %p %lx %p timeout %d\n", hwnd, id, winproc, timeout );
4189 return ret;
4193 /***********************************************************************
4194 * KillTimer (USER32.@)
4196 BOOL WINAPI KillTimer( HWND hwnd, UINT_PTR id )
4198 BOOL ret;
4200 SERVER_START_REQ( kill_win_timer )
4202 req->win = wine_server_user_handle( hwnd );
4203 req->msg = WM_TIMER;
4204 req->id = id;
4205 ret = !wine_server_call_err( req );
4207 SERVER_END_REQ;
4208 return ret;
4212 /***********************************************************************
4213 * KillSystemTimer (USER32.@)
4215 BOOL WINAPI KillSystemTimer( HWND hwnd, UINT_PTR id )
4217 BOOL ret;
4219 SERVER_START_REQ( kill_win_timer )
4221 req->win = wine_server_user_handle( hwnd );
4222 req->msg = WM_SYSTIMER;
4223 req->id = id;
4224 ret = !wine_server_call_err( req );
4226 SERVER_END_REQ;
4227 return ret;
4231 /**********************************************************************
4232 * GetGUIThreadInfo (USER32.@)
4234 BOOL WINAPI GetGUIThreadInfo( DWORD id, GUITHREADINFO *info )
4236 BOOL ret;
4238 SERVER_START_REQ( get_thread_input )
4240 req->tid = id;
4241 if ((ret = !wine_server_call_err( req )))
4243 info->flags = 0;
4244 info->hwndActive = wine_server_ptr_handle( reply->active );
4245 info->hwndFocus = wine_server_ptr_handle( reply->focus );
4246 info->hwndCapture = wine_server_ptr_handle( reply->capture );
4247 info->hwndMenuOwner = wine_server_ptr_handle( reply->menu_owner );
4248 info->hwndMoveSize = wine_server_ptr_handle( reply->move_size );
4249 info->hwndCaret = wine_server_ptr_handle( reply->caret );
4250 info->rcCaret.left = reply->rect.left;
4251 info->rcCaret.top = reply->rect.top;
4252 info->rcCaret.right = reply->rect.right;
4253 info->rcCaret.bottom = reply->rect.bottom;
4254 if (reply->menu_owner) info->flags |= GUI_INMENUMODE;
4255 if (reply->move_size) info->flags |= GUI_INMOVESIZE;
4256 if (reply->caret) info->flags |= GUI_CARETBLINKING;
4259 SERVER_END_REQ;
4260 return ret;
4264 /******************************************************************
4265 * IsHungAppWindow (USER32.@)
4268 BOOL WINAPI IsHungAppWindow( HWND hWnd )
4270 BOOL ret;
4272 SERVER_START_REQ( is_window_hung )
4274 req->win = wine_server_user_handle( hWnd );
4275 ret = !wine_server_call_err( req ) && reply->is_hung;
4277 SERVER_END_REQ;
4278 return ret;
4281 /******************************************************************
4282 * ChangeWindowMessageFilter (USER32.@)
4284 BOOL WINAPI ChangeWindowMessageFilter( UINT message, DWORD flag )
4286 FIXME( "%x %08x\n", message, flag );
4287 return TRUE;