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
29 #define WIN32_NO_STATUS
30 #include "win32u_private.h"
31 #include "ntuser_private.h"
37 #include "wine/server.h"
38 #include "wine/debug.h"
40 WINE_DEFAULT_DEBUG_CHANNEL(msg
);
41 WINE_DECLARE_DEBUG_CHANNEL(key
);
42 WINE_DECLARE_DEBUG_CHANNEL(relay
);
44 #define MAX_WINPROC_RECURSION 64
46 #define WM_NCMOUSEFIRST WM_NCMOUSEMOVE
47 #define WM_NCMOUSELAST (WM_NCMOUSEFIRST+(WM_MOUSELAST-WM_MOUSEFIRST))
49 #define MAX_PACK_COUNT 4
51 /* info about the message currently being received by the current thread */
52 struct received_message_info
56 UINT flags
; /* InSendMessageEx return flags */
58 struct received_message_info
*prev
;
61 #define MSG_CLIENT_MESSAGE 0xff
63 struct packed_hook_extra_info
70 /* the structures are unpacked on top of the packed ones, so make sure they fit */
71 C_ASSERT( sizeof(struct packed_CREATESTRUCTW
) >= sizeof(CREATESTRUCTW
) );
72 C_ASSERT( sizeof(struct packed_DRAWITEMSTRUCT
) >= sizeof(DRAWITEMSTRUCT
) );
73 C_ASSERT( sizeof(struct packed_MEASUREITEMSTRUCT
) >= sizeof(MEASUREITEMSTRUCT
) );
74 C_ASSERT( sizeof(struct packed_DELETEITEMSTRUCT
) >= sizeof(DELETEITEMSTRUCT
) );
75 C_ASSERT( sizeof(struct packed_COMPAREITEMSTRUCT
) >= sizeof(COMPAREITEMSTRUCT
) );
76 C_ASSERT( sizeof(struct packed_WINDOWPOS
) >= sizeof(WINDOWPOS
) );
77 C_ASSERT( sizeof(struct packed_COPYDATASTRUCT
) >= sizeof(COPYDATASTRUCT
) );
78 C_ASSERT( sizeof(struct packed_HELPINFO
) >= sizeof(HELPINFO
) );
79 C_ASSERT( sizeof(struct packed_NCCALCSIZE_PARAMS
) >= sizeof(NCCALCSIZE_PARAMS
) + sizeof(WINDOWPOS
) );
80 C_ASSERT( sizeof(struct packed_MSG
) >= sizeof(MSG
) );
81 C_ASSERT( sizeof(struct packed_MDINEXTMENU
) >= sizeof(MDINEXTMENU
) );
82 C_ASSERT( sizeof(struct packed_MDICREATESTRUCTW
) >= sizeof(MDICREATESTRUCTW
) );
83 C_ASSERT( sizeof(struct packed_hook_extra_info
) >= sizeof(struct hook_extra_info
) );
87 struct packed_CREATESTRUCTW cs
;
88 struct packed_DRAWITEMSTRUCT dis
;
89 struct packed_MEASUREITEMSTRUCT mis
;
90 struct packed_DELETEITEMSTRUCT dls
;
91 struct packed_COMPAREITEMSTRUCT cis
;
92 struct packed_WINDOWPOS wp
;
93 struct packed_COPYDATASTRUCT cds
;
94 struct packed_HELPINFO hi
;
95 struct packed_NCCALCSIZE_PARAMS ncp
;
96 struct packed_MSG msg
;
97 struct packed_MDINEXTMENU mnm
;
98 struct packed_MDICREATESTRUCTW mcs
;
99 struct packed_hook_extra_info hook
;
102 /* description of the data fields that need to be packed along with a sent message */
103 struct packed_message
105 union packed_structs ps
;
107 const void *data
[MAX_PACK_COUNT
];
108 size_t size
[MAX_PACK_COUNT
];
111 /* structure to group all parameters for sent messages of the various kinds */
112 struct send_message_info
114 enum message_type type
;
120 UINT flags
; /* flags for SendMessageTimeout */
121 UINT timeout
; /* timeout for SendMessageTimeout */
122 SENDASYNCPROC callback
; /* callback function for SendMessageCallback */
123 ULONG_PTR data
; /* callback data */
124 enum wm_char_mapping wm_char
;
125 struct win_proc_params
*params
;
128 static const INPUT_MESSAGE_SOURCE msg_source_unavailable
= { IMDT_UNAVAILABLE
, IMO_UNAVAILABLE
};
130 /* flag for messages that contain pointers */
131 /* 32 messages per entry, messages 0..31 map to bits 0..31 */
133 #define SET(msg) (1 << ((msg) & 31))
135 static const unsigned int message_pointer_flags
[] =
138 SET(WM_CREATE
) | SET(WM_SETTEXT
) | SET(WM_GETTEXT
) |
139 SET(WM_WININICHANGE
) | SET(WM_DEVMODECHANGE
),
141 SET(WM_GETMINMAXINFO
) | SET(WM_DRAWITEM
) | SET(WM_MEASUREITEM
) | SET(WM_DELETEITEM
) |
144 SET(WM_WINDOWPOSCHANGING
) | SET(WM_WINDOWPOSCHANGED
) | SET(WM_COPYDATA
) | SET(WM_HELP
),
146 SET(WM_STYLECHANGING
) | SET(WM_STYLECHANGED
),
148 SET(WM_NCCREATE
) | SET(WM_NCCALCSIZE
) | SET(WM_GETDLGCODE
),
150 SET(EM_GETSEL
) | SET(EM_GETRECT
) | SET(EM_SETRECT
) | SET(EM_SETRECTNP
),
152 SET(EM_REPLACESEL
) | SET(EM_GETLINE
) | SET(EM_SETTABSTOPS
),
154 SET(SBM_GETRANGE
) | SET(SBM_SETSCROLLINFO
) | SET(SBM_GETSCROLLINFO
) | SET(SBM_GETSCROLLBARINFO
),
160 SET(CB_GETEDITSEL
) | SET(CB_ADDSTRING
) | SET(CB_DIR
) | SET(CB_GETLBTEXT
) |
161 SET(CB_INSERTSTRING
) | SET(CB_FINDSTRING
) | SET(CB_SELECTSTRING
) |
162 SET(CB_GETDROPPEDCONTROLRECT
) | SET(CB_FINDSTRINGEXACT
),
166 SET(LB_ADDSTRING
) | SET(LB_INSERTSTRING
) | SET(LB_GETTEXT
) | SET(LB_SELECTSTRING
) |
167 SET(LB_DIR
) | SET(LB_FINDSTRING
) |
168 SET(LB_GETSELITEMS
) | SET(LB_SETTABSTOPS
) | SET(LB_ADDFILE
) | SET(LB_GETITEMRECT
),
170 SET(LB_FINDSTRINGEXACT
),
176 SET(WM_NEXTMENU
) | SET(WM_SIZING
) | SET(WM_MOVING
) | SET(WM_DEVICECHANGE
),
178 SET(WM_MDICREATE
) | SET(WM_MDIGETACTIVE
) | SET(WM_DROPOBJECT
) |
179 SET(WM_QUERYDROPOBJECT
) | SET(WM_DRAGLOOP
) | SET(WM_DRAGSELECT
) | SET(WM_DRAGMOVE
),
193 SET(WM_ASKCBFORMATNAME
)
196 /* check whether a given message type includes pointers */
197 static inline BOOL
is_pointer_message( UINT message
, WPARAM wparam
)
199 if (message
>= 8*sizeof(message_pointer_flags
)) return FALSE
;
200 if (message
== WM_DEVICECHANGE
&& !(wparam
& 0x8000)) return FALSE
;
201 return (message_pointer_flags
[message
/ 32] & SET(message
)) != 0;
206 static BOOL
init_win_proc_params( struct win_proc_params
*params
, HWND hwnd
, UINT msg
,
207 WPARAM wparam
, LPARAM lparam
, BOOL ansi
)
209 if (!params
->func
) return FALSE
;
211 user_check_not_lock();
213 params
->hwnd
= get_full_window_handle( hwnd
);
215 params
->wparam
= wparam
;
216 params
->lparam
= lparam
;
217 params
->ansi
= params
->ansi_dst
= ansi
;
218 params
->needs_unpack
= FALSE
;
219 params
->mapping
= WMCHAR_MAP_CALLWINDOWPROC
;
220 params
->dpi_awareness
= get_window_dpi_awareness_context( params
->hwnd
);
221 get_winproc_params( params
, TRUE
);
225 static BOOL
init_window_call_params( struct win_proc_params
*params
, HWND hwnd
, UINT msg
, WPARAM wParam
,
226 LPARAM lParam
, LRESULT
*result
, BOOL ansi
,
227 enum wm_char_mapping mapping
)
232 user_check_not_lock();
234 if (!(win
= get_win_ptr( hwnd
))) return FALSE
;
235 if (win
== WND_OTHER_PROCESS
|| win
== WND_DESKTOP
) return FALSE
;
236 if (win
->tid
!= GetCurrentThreadId())
238 release_win_ptr( win
);
241 params
->func
= win
->winproc
;
242 params
->ansi_dst
= !(win
->flags
& WIN_ISUNICODE
);
243 is_dialog
= win
->dlgInfo
!= NULL
;
244 release_win_ptr( win
);
246 params
->hwnd
= get_full_window_handle( hwnd
);
248 params
->wparam
= wParam
;
249 params
->lparam
= lParam
;
250 params
->result
= result
;
252 params
->needs_unpack
= FALSE
;
253 params
->mapping
= mapping
;
254 params
->dpi_awareness
= get_window_dpi_awareness_context( params
->hwnd
);
255 get_winproc_params( params
, !is_dialog
);
259 static BOOL
dispatch_win_proc_params( struct win_proc_params
*params
, size_t size
)
261 struct ntuser_thread_info
*thread_info
= NtUserGetThreadInfo();
265 if (thread_info
->recursion_count
> MAX_WINPROC_RECURSION
) return FALSE
;
266 thread_info
->recursion_count
++;
268 KeUserModeCallback( NtUserCallWinProc
, params
, size
, &ret_ptr
, &ret_len
);
269 if (ret_len
== sizeof(*params
->result
)) *params
->result
= *(LRESULT
*)ret_ptr
;
271 thread_info
->recursion_count
--;
275 /* add a data field to a packed message */
276 static inline void push_data( struct packed_message
*data
, const void *ptr
, size_t size
)
278 data
->data
[data
->count
] = ptr
;
279 data
->size
[data
->count
] = size
;
283 /* pack a pointer into a 32/64 portable format */
284 static inline ULONGLONG
pack_ptr( const void *ptr
)
286 return (ULONG_PTR
)ptr
;
289 /* unpack a potentially 64-bit pointer, returning 0 when truncated */
290 static inline void *unpack_ptr( ULONGLONG ptr64
)
292 if ((ULONG_PTR
)ptr64
!= ptr64
) return 0;
293 return (void *)(ULONG_PTR
)ptr64
;
296 /* add a string to a packed message */
297 static inline void push_string( struct packed_message
*data
, LPCWSTR str
)
299 push_data( data
, str
, (lstrlenW(str
) + 1) * sizeof(WCHAR
) );
302 /* check whether a combobox expects strings or ids in CB_ADDSTRING/CB_INSERTSTRING */
303 static inline BOOL
combobox_has_strings( HWND hwnd
)
305 DWORD style
= get_window_long( hwnd
, GWL_STYLE
);
306 return (!(style
& (CBS_OWNERDRAWFIXED
| CBS_OWNERDRAWVARIABLE
)) || (style
& CBS_HASSTRINGS
));
309 /* check whether a listbox expects strings or ids in LB_ADDSTRING/LB_INSERTSTRING */
310 static inline BOOL
listbox_has_strings( HWND hwnd
)
312 DWORD style
= get_window_long( hwnd
, GWL_STYLE
);
313 return (!(style
& (LBS_OWNERDRAWFIXED
| LBS_OWNERDRAWVARIABLE
)) || (style
& LBS_HASSTRINGS
));
316 /* check whether message is in the range of keyboard messages */
317 static inline BOOL
is_keyboard_message( UINT message
)
319 return (message
>= WM_KEYFIRST
&& message
<= WM_KEYLAST
);
322 /* check whether message is in the range of mouse messages */
323 static inline BOOL
is_mouse_message( UINT message
)
325 return ((message
>= WM_NCMOUSEFIRST
&& message
<= WM_NCMOUSELAST
) ||
326 (message
>= WM_MOUSEFIRST
&& message
<= WM_MOUSELAST
));
329 /* check whether message matches the specified hwnd filter */
330 static inline BOOL
check_hwnd_filter( const MSG
*msg
, HWND hwnd_filter
)
332 if (!hwnd_filter
|| hwnd_filter
== get_desktop_window()) return TRUE
;
333 return (msg
->hwnd
== hwnd_filter
|| is_child( hwnd_filter
, msg
->hwnd
));
336 /***********************************************************************
339 * Unpack a message received from another process.
341 static BOOL
unpack_message( HWND hwnd
, UINT message
, WPARAM
*wparam
, LPARAM
*lparam
,
342 void **buffer
, size_t size
)
345 union packed_structs
*ps
= *buffer
;
349 case WM_WINE_SETWINDOWPOS
:
352 if (size
< sizeof(ps
->wp
)) return FALSE
;
353 wp
.hwnd
= wine_server_ptr_handle( ps
->wp
.hwnd
);
354 wp
.hwndInsertAfter
= wine_server_ptr_handle( ps
->wp
.hwndInsertAfter
);
359 wp
.flags
= ps
->wp
.flags
;
360 memcpy( ps
, &wp
, sizeof(wp
) );
363 case WM_WINE_KEYBOARD_LL_HOOK
:
364 case WM_WINE_MOUSE_LL_HOOK
:
366 struct hook_extra_info h_extra
;
367 minsize
= sizeof(ps
->hook
) +
368 (message
== WM_WINE_KEYBOARD_LL_HOOK
? sizeof(KBDLLHOOKSTRUCT
)
369 : sizeof(MSLLHOOKSTRUCT
));
370 if (size
< minsize
) return FALSE
;
371 h_extra
.handle
= wine_server_ptr_handle( ps
->hook
.handle
);
372 h_extra
.lparam
= (LPARAM
)(&ps
->hook
+ 1);
373 memcpy( &ps
->hook
, &h_extra
, sizeof(h_extra
) );
377 return TRUE
; /* message doesn't need any unpacking */
380 /* default exit for most messages: check minsize and store buffer in lparam */
381 if (size
< minsize
) return FALSE
;
382 *lparam
= (LPARAM
)*buffer
;
386 /***********************************************************************
389 * Pack a message for sending to another process.
390 * Return the size of the data we expect in the message reply.
391 * Set data->count to -1 if there is an error.
393 static size_t pack_message( HWND hwnd
, UINT message
, WPARAM wparam
, LPARAM lparam
,
394 struct packed_message
*data
)
402 CREATESTRUCTW
*cs
= (CREATESTRUCTW
*)lparam
;
403 data
->ps
.cs
.lpCreateParams
= pack_ptr( cs
->lpCreateParams
);
404 data
->ps
.cs
.hInstance
= pack_ptr( cs
->hInstance
);
405 data
->ps
.cs
.hMenu
= wine_server_user_handle( cs
->hMenu
);
406 data
->ps
.cs
.hwndParent
= wine_server_user_handle( cs
->hwndParent
);
407 data
->ps
.cs
.cy
= cs
->cy
;
408 data
->ps
.cs
.cx
= cs
->cx
;
409 data
->ps
.cs
.y
= cs
->y
;
410 data
->ps
.cs
.x
= cs
->x
;
411 data
->ps
.cs
.style
= cs
->style
;
412 data
->ps
.cs
.dwExStyle
= cs
->dwExStyle
;
413 data
->ps
.cs
.lpszName
= pack_ptr( cs
->lpszName
);
414 data
->ps
.cs
.lpszClass
= pack_ptr( cs
->lpszClass
);
415 push_data( data
, &data
->ps
.cs
, sizeof(data
->ps
.cs
) );
416 if (!IS_INTRESOURCE(cs
->lpszName
)) push_string( data
, cs
->lpszName
);
417 if (!IS_INTRESOURCE(cs
->lpszClass
)) push_string( data
, cs
->lpszClass
);
418 return sizeof(data
->ps
.cs
);
421 case WM_ASKCBFORMATNAME
:
422 return wparam
* sizeof(WCHAR
);
423 case WM_WININICHANGE
:
424 if (lparam
) push_string(data
, (LPWSTR
)lparam
);
427 case WM_DEVMODECHANGE
:
432 push_string( data
, (LPWSTR
)lparam
);
434 case WM_GETMINMAXINFO
:
435 push_data( data
, (MINMAXINFO
*)lparam
, sizeof(MINMAXINFO
) );
436 return sizeof(MINMAXINFO
);
439 DRAWITEMSTRUCT
*dis
= (DRAWITEMSTRUCT
*)lparam
;
440 data
->ps
.dis
.CtlType
= dis
->CtlType
;
441 data
->ps
.dis
.CtlID
= dis
->CtlID
;
442 data
->ps
.dis
.itemID
= dis
->itemID
;
443 data
->ps
.dis
.itemAction
= dis
->itemAction
;
444 data
->ps
.dis
.itemState
= dis
->itemState
;
445 data
->ps
.dis
.hwndItem
= wine_server_user_handle( dis
->hwndItem
);
446 data
->ps
.dis
.hDC
= wine_server_user_handle( dis
->hDC
); /* FIXME */
447 data
->ps
.dis
.rcItem
= dis
->rcItem
;
448 data
->ps
.dis
.itemData
= dis
->itemData
;
449 push_data( data
, &data
->ps
.dis
, sizeof(data
->ps
.dis
) );
454 MEASUREITEMSTRUCT
*mis
= (MEASUREITEMSTRUCT
*)lparam
;
455 data
->ps
.mis
.CtlType
= mis
->CtlType
;
456 data
->ps
.mis
.CtlID
= mis
->CtlID
;
457 data
->ps
.mis
.itemID
= mis
->itemID
;
458 data
->ps
.mis
.itemWidth
= mis
->itemWidth
;
459 data
->ps
.mis
.itemHeight
= mis
->itemHeight
;
460 data
->ps
.mis
.itemData
= mis
->itemData
;
461 push_data( data
, &data
->ps
.mis
, sizeof(data
->ps
.mis
) );
462 return sizeof(data
->ps
.mis
);
466 DELETEITEMSTRUCT
*dls
= (DELETEITEMSTRUCT
*)lparam
;
467 data
->ps
.dls
.CtlType
= dls
->CtlType
;
468 data
->ps
.dls
.CtlID
= dls
->CtlID
;
469 data
->ps
.dls
.itemID
= dls
->itemID
;
470 data
->ps
.dls
.hwndItem
= wine_server_user_handle( dls
->hwndItem
);
471 data
->ps
.dls
.itemData
= dls
->itemData
;
472 push_data( data
, &data
->ps
.dls
, sizeof(data
->ps
.dls
) );
477 COMPAREITEMSTRUCT
*cis
= (COMPAREITEMSTRUCT
*)lparam
;
478 data
->ps
.cis
.CtlType
= cis
->CtlType
;
479 data
->ps
.cis
.CtlID
= cis
->CtlID
;
480 data
->ps
.cis
.hwndItem
= wine_server_user_handle( cis
->hwndItem
);
481 data
->ps
.cis
.itemID1
= cis
->itemID1
;
482 data
->ps
.cis
.itemData1
= cis
->itemData1
;
483 data
->ps
.cis
.itemID2
= cis
->itemID2
;
484 data
->ps
.cis
.itemData2
= cis
->itemData2
;
485 data
->ps
.cis
.dwLocaleId
= cis
->dwLocaleId
;
486 push_data( data
, &data
->ps
.cis
, sizeof(data
->ps
.cis
) );
489 case WM_WINE_SETWINDOWPOS
:
490 case WM_WINDOWPOSCHANGING
:
491 case WM_WINDOWPOSCHANGED
:
493 WINDOWPOS
*wp
= (WINDOWPOS
*)lparam
;
494 data
->ps
.wp
.hwnd
= wine_server_user_handle( wp
->hwnd
);
495 data
->ps
.wp
.hwndInsertAfter
= wine_server_user_handle( wp
->hwndInsertAfter
);
496 data
->ps
.wp
.x
= wp
->x
;
497 data
->ps
.wp
.y
= wp
->y
;
498 data
->ps
.wp
.cx
= wp
->cx
;
499 data
->ps
.wp
.cy
= wp
->cy
;
500 data
->ps
.wp
.flags
= wp
->flags
;
501 push_data( data
, &data
->ps
.wp
, sizeof(data
->ps
.wp
) );
502 return sizeof(data
->ps
.wp
);
506 COPYDATASTRUCT
*cds
= (COPYDATASTRUCT
*)lparam
;
507 data
->ps
.cds
.cbData
= cds
->cbData
;
508 data
->ps
.cds
.dwData
= cds
->dwData
;
509 data
->ps
.cds
.lpData
= pack_ptr( cds
->lpData
);
510 push_data( data
, &data
->ps
.cds
, sizeof(data
->ps
.cds
) );
511 if (cds
->lpData
) push_data( data
, cds
->lpData
, cds
->cbData
);
515 /* WM_NOTIFY cannot be sent across processes (MSDN) */
520 HELPINFO
*hi
= (HELPINFO
*)lparam
;
521 data
->ps
.hi
.iContextType
= hi
->iContextType
;
522 data
->ps
.hi
.iCtrlId
= hi
->iCtrlId
;
523 data
->ps
.hi
.hItemHandle
= wine_server_user_handle( hi
->hItemHandle
);
524 data
->ps
.hi
.dwContextId
= hi
->dwContextId
;
525 data
->ps
.hi
.MousePos
= hi
->MousePos
;
526 push_data( data
, &data
->ps
.hi
, sizeof(data
->ps
.hi
) );
529 case WM_STYLECHANGING
:
530 case WM_STYLECHANGED
:
531 push_data( data
, (STYLESTRUCT
*)lparam
, sizeof(STYLESTRUCT
) );
536 push_data( data
, (RECT
*)lparam
, sizeof(RECT
) );
541 NCCALCSIZE_PARAMS
*ncp
= (NCCALCSIZE_PARAMS
*)lparam
;
542 data
->ps
.ncp
.rgrc
[0] = ncp
->rgrc
[0];
543 data
->ps
.ncp
.rgrc
[1] = ncp
->rgrc
[1];
544 data
->ps
.ncp
.rgrc
[2] = ncp
->rgrc
[2];
545 data
->ps
.ncp
.hwnd
= wine_server_user_handle( ncp
->lppos
->hwnd
);
546 data
->ps
.ncp
.hwndInsertAfter
= wine_server_user_handle( ncp
->lppos
->hwndInsertAfter
);
547 data
->ps
.ncp
.x
= ncp
->lppos
->x
;
548 data
->ps
.ncp
.y
= ncp
->lppos
->y
;
549 data
->ps
.ncp
.cx
= ncp
->lppos
->cx
;
550 data
->ps
.ncp
.cy
= ncp
->lppos
->cy
;
551 data
->ps
.ncp
.flags
= ncp
->lppos
->flags
;
552 push_data( data
, &data
->ps
.ncp
, sizeof(data
->ps
.ncp
) );
553 return sizeof(data
->ps
.ncp
);
558 MSG
*msg
= (MSG
*)lparam
;
559 data
->ps
.msg
.hwnd
= wine_server_user_handle( msg
->hwnd
);
560 data
->ps
.msg
.message
= msg
->message
;
561 data
->ps
.msg
.wParam
= msg
->wParam
;
562 data
->ps
.msg
.lParam
= msg
->lParam
;
563 data
->ps
.msg
.time
= msg
->time
;
564 data
->ps
.msg
.pt
= msg
->pt
;
565 push_data( data
, &data
->ps
.msg
, sizeof(data
->ps
.msg
) );
566 return sizeof(data
->ps
.msg
);
569 case SBM_SETSCROLLINFO
:
570 push_data( data
, (SCROLLINFO
*)lparam
, sizeof(SCROLLINFO
) );
572 case SBM_GETSCROLLINFO
:
573 push_data( data
, (SCROLLINFO
*)lparam
, sizeof(SCROLLINFO
) );
574 return sizeof(SCROLLINFO
);
575 case SBM_GETSCROLLBARINFO
:
577 const SCROLLBARINFO
*info
= (const SCROLLBARINFO
*)lparam
;
578 size_t size
= min( info
->cbSize
, sizeof(SCROLLBARINFO
) );
579 push_data( data
, info
, size
);
587 if (wparam
) size
+= sizeof(DWORD
);
588 if (lparam
) size
+= sizeof(DWORD
);
593 case CB_GETDROPPEDCONTROLRECT
:
597 push_data( data
, (RECT
*)lparam
, sizeof(RECT
) );
601 WORD
*pw
= (WORD
*)lparam
;
602 push_data( data
, pw
, sizeof(*pw
) );
603 return *pw
* sizeof(WCHAR
);
607 if (wparam
) push_data( data
, (UINT
*)lparam
, sizeof(UINT
) * wparam
);
610 case CB_INSERTSTRING
:
612 case CB_FINDSTRINGEXACT
:
613 case CB_SELECTSTRING
:
614 if (combobox_has_strings( hwnd
)) push_string( data
, (LPWSTR
)lparam
);
617 if (!combobox_has_strings( hwnd
)) return sizeof(ULONG_PTR
);
618 return (send_message( hwnd
, CB_GETLBTEXTLEN
, wparam
, 0 ) + 1) * sizeof(WCHAR
);
620 case LB_INSERTSTRING
:
622 case LB_FINDSTRINGEXACT
:
623 case LB_SELECTSTRING
:
624 if (listbox_has_strings( hwnd
)) push_string( data
, (LPWSTR
)lparam
);
627 if (!listbox_has_strings( hwnd
)) return sizeof(ULONG_PTR
);
628 return (send_message( hwnd
, LB_GETTEXTLEN
, wparam
, 0 ) + 1) * sizeof(WCHAR
);
630 return wparam
* sizeof(UINT
);
633 MDINEXTMENU
*mnm
= (MDINEXTMENU
*)lparam
;
634 data
->ps
.mnm
.hmenuIn
= wine_server_user_handle( mnm
->hmenuIn
);
635 data
->ps
.mnm
.hmenuNext
= wine_server_user_handle( mnm
->hmenuNext
);
636 data
->ps
.mnm
.hwndNext
= wine_server_user_handle( mnm
->hwndNext
);
637 push_data( data
, &data
->ps
.mnm
, sizeof(data
->ps
.mnm
) );
638 return sizeof(data
->ps
.mnm
);
642 push_data( data
, (RECT
*)lparam
, sizeof(RECT
) );
646 MDICREATESTRUCTW
*mcs
= (MDICREATESTRUCTW
*)lparam
;
647 data
->ps
.mcs
.szClass
= pack_ptr( mcs
->szClass
);
648 data
->ps
.mcs
.szTitle
= pack_ptr( mcs
->szTitle
);
649 data
->ps
.mcs
.hOwner
= pack_ptr( mcs
->hOwner
);
650 data
->ps
.mcs
.x
= mcs
->x
;
651 data
->ps
.mcs
.y
= mcs
->y
;
652 data
->ps
.mcs
.cx
= mcs
->cx
;
653 data
->ps
.mcs
.cy
= mcs
->cy
;
654 data
->ps
.mcs
.style
= mcs
->style
;
655 data
->ps
.mcs
.lParam
= mcs
->lParam
;
656 push_data( data
, &data
->ps
.mcs
, sizeof(data
->ps
.mcs
) );
657 if (!IS_INTRESOURCE(mcs
->szClass
)) push_string( data
, mcs
->szClass
);
658 if (!IS_INTRESOURCE(mcs
->szTitle
)) push_string( data
, mcs
->szTitle
);
659 return sizeof(data
->ps
.mcs
);
661 case WM_MDIGETACTIVE
:
662 if (lparam
) return sizeof(BOOL
);
664 case WM_DEVICECHANGE
:
666 DEV_BROADCAST_HDR
*header
= (DEV_BROADCAST_HDR
*)lparam
;
667 if ((wparam
& 0x8000) && header
) push_data( data
, header
, header
->dbch_size
);
670 case WM_WINE_KEYBOARD_LL_HOOK
:
672 struct hook_extra_info
*h_extra
= (struct hook_extra_info
*)lparam
;
673 data
->ps
.hook
.handle
= wine_server_user_handle( h_extra
->handle
);
674 push_data( data
, &data
->ps
.hook
, sizeof(data
->ps
.hook
) );
675 push_data( data
, (LPVOID
)h_extra
->lparam
, sizeof(KBDLLHOOKSTRUCT
) );
678 case WM_WINE_MOUSE_LL_HOOK
:
680 struct hook_extra_info
*h_extra
= (struct hook_extra_info
*)lparam
;
681 data
->ps
.hook
.handle
= wine_server_user_handle( h_extra
->handle
);
682 push_data( data
, &data
->ps
.hook
, sizeof(data
->ps
.hook
) );
683 push_data( data
, (LPVOID
)h_extra
->lparam
, sizeof(MSLLHOOKSTRUCT
) );
687 if (wparam
<= 1) return 0;
688 FIXME( "WM_NCPAINT hdc packing not supported yet\n" );
692 if (!wparam
) return 0;
695 /* these contain an HFONT */
698 /* these contain an HDC */
700 case WM_ICONERASEBKGND
:
701 case WM_CTLCOLORMSGBOX
:
702 case WM_CTLCOLOREDIT
:
703 case WM_CTLCOLORLISTBOX
:
706 case WM_CTLCOLORSCROLLBAR
:
707 case WM_CTLCOLORSTATIC
:
710 /* these contain an HGLOBAL */
711 case WM_PAINTCLIPBOARD
:
712 case WM_SIZECLIPBOARD
:
713 /* these contain HICON */
716 case WM_QUERYDRAGICON
:
717 case WM_QUERYPARKICON
:
718 /* these contain pointers */
720 case WM_QUERYDROPOBJECT
:
724 FIXME( "msg %x (%s) not supported yet\n", message
, debugstr_msg_name(message
, hwnd
) );
731 /***********************************************************************
734 * Pack a reply to a message for sending to another process.
736 static void pack_reply( HWND hwnd
, UINT message
, WPARAM wparam
, LPARAM lparam
,
737 LRESULT res
, struct packed_message
*data
)
745 CREATESTRUCTW
*cs
= (CREATESTRUCTW
*)lparam
;
746 data
->ps
.cs
.lpCreateParams
= (ULONG_PTR
)cs
->lpCreateParams
;
747 data
->ps
.cs
.hInstance
= (ULONG_PTR
)cs
->hInstance
;
748 data
->ps
.cs
.hMenu
= wine_server_user_handle( cs
->hMenu
);
749 data
->ps
.cs
.hwndParent
= wine_server_user_handle( cs
->hwndParent
);
750 data
->ps
.cs
.cy
= cs
->cy
;
751 data
->ps
.cs
.cx
= cs
->cx
;
752 data
->ps
.cs
.y
= cs
->y
;
753 data
->ps
.cs
.x
= cs
->x
;
754 data
->ps
.cs
.style
= cs
->style
;
755 data
->ps
.cs
.dwExStyle
= cs
->dwExStyle
;
756 data
->ps
.cs
.lpszName
= (ULONG_PTR
)cs
->lpszName
;
757 data
->ps
.cs
.lpszClass
= (ULONG_PTR
)cs
->lpszClass
;
758 push_data( data
, &data
->ps
.cs
, sizeof(data
->ps
.cs
) );
764 push_data( data
, (WCHAR
*)lparam
, (res
+ 1) * sizeof(WCHAR
) );
766 case WM_GETMINMAXINFO
:
767 push_data( data
, (MINMAXINFO
*)lparam
, sizeof(MINMAXINFO
) );
771 MEASUREITEMSTRUCT
*mis
= (MEASUREITEMSTRUCT
*)lparam
;
772 data
->ps
.mis
.CtlType
= mis
->CtlType
;
773 data
->ps
.mis
.CtlID
= mis
->CtlID
;
774 data
->ps
.mis
.itemID
= mis
->itemID
;
775 data
->ps
.mis
.itemWidth
= mis
->itemWidth
;
776 data
->ps
.mis
.itemHeight
= mis
->itemHeight
;
777 data
->ps
.mis
.itemData
= mis
->itemData
;
778 push_data( data
, &data
->ps
.mis
, sizeof(data
->ps
.mis
) );
781 case WM_WINDOWPOSCHANGING
:
782 case WM_WINDOWPOSCHANGED
:
784 WINDOWPOS
*wp
= (WINDOWPOS
*)lparam
;
785 data
->ps
.wp
.hwnd
= wine_server_user_handle( wp
->hwnd
);
786 data
->ps
.wp
.hwndInsertAfter
= wine_server_user_handle( wp
->hwndInsertAfter
);
787 data
->ps
.wp
.x
= wp
->x
;
788 data
->ps
.wp
.y
= wp
->y
;
789 data
->ps
.wp
.cx
= wp
->cx
;
790 data
->ps
.wp
.cy
= wp
->cy
;
791 data
->ps
.wp
.flags
= wp
->flags
;
792 push_data( data
, &data
->ps
.wp
, sizeof(data
->ps
.wp
) );
798 MSG
*msg
= (MSG
*)lparam
;
799 data
->ps
.msg
.hwnd
= wine_server_user_handle( msg
->hwnd
);
800 data
->ps
.msg
.message
= msg
->message
;
801 data
->ps
.msg
.wParam
= msg
->wParam
;
802 data
->ps
.msg
.lParam
= msg
->lParam
;
803 data
->ps
.msg
.time
= msg
->time
;
804 data
->ps
.msg
.pt
= msg
->pt
;
805 push_data( data
, &data
->ps
.msg
, sizeof(data
->ps
.msg
) );
808 case SBM_GETSCROLLINFO
:
809 push_data( data
, (SCROLLINFO
*)lparam
, sizeof(SCROLLINFO
) );
813 case CB_GETDROPPEDCONTROLRECT
:
816 push_data( data
, (RECT
*)lparam
, sizeof(RECT
) );
820 WORD
*ptr
= (WORD
*)lparam
;
821 push_data( data
, ptr
, ptr
[-1] * sizeof(WCHAR
) );
825 push_data( data
, (UINT
*)lparam
, wparam
* sizeof(UINT
) );
827 case WM_MDIGETACTIVE
:
828 if (lparam
) push_data( data
, (BOOL
*)lparam
, sizeof(BOOL
) );
832 push_data( data
, (RECT
*)lparam
, sizeof(RECT
) );
835 NCCALCSIZE_PARAMS
*ncp
= (NCCALCSIZE_PARAMS
*)lparam
;
836 data
->ps
.ncp
.rgrc
[0] = ncp
->rgrc
[0];
837 data
->ps
.ncp
.rgrc
[1] = ncp
->rgrc
[1];
838 data
->ps
.ncp
.rgrc
[2] = ncp
->rgrc
[2];
839 data
->ps
.ncp
.hwnd
= wine_server_user_handle( ncp
->lppos
->hwnd
);
840 data
->ps
.ncp
.hwndInsertAfter
= wine_server_user_handle( ncp
->lppos
->hwndInsertAfter
);
841 data
->ps
.ncp
.x
= ncp
->lppos
->x
;
842 data
->ps
.ncp
.y
= ncp
->lppos
->y
;
843 data
->ps
.ncp
.cx
= ncp
->lppos
->cx
;
844 data
->ps
.ncp
.cy
= ncp
->lppos
->cy
;
845 data
->ps
.ncp
.flags
= ncp
->lppos
->flags
;
846 push_data( data
, &data
->ps
.ncp
, sizeof(data
->ps
.ncp
) );
852 if (wparam
) push_data( data
, (DWORD
*)wparam
, sizeof(DWORD
) );
853 if (lparam
) push_data( data
, (DWORD
*)lparam
, sizeof(DWORD
) );
857 MDINEXTMENU
*mnm
= (MDINEXTMENU
*)lparam
;
858 data
->ps
.mnm
.hmenuIn
= wine_server_user_handle( mnm
->hmenuIn
);
859 data
->ps
.mnm
.hmenuNext
= wine_server_user_handle( mnm
->hmenuNext
);
860 data
->ps
.mnm
.hwndNext
= wine_server_user_handle( mnm
->hwndNext
);
861 push_data( data
, &data
->ps
.mnm
, sizeof(data
->ps
.mnm
) );
866 MDICREATESTRUCTW
*mcs
= (MDICREATESTRUCTW
*)lparam
;
867 data
->ps
.mcs
.szClass
= pack_ptr( mcs
->szClass
);
868 data
->ps
.mcs
.szTitle
= pack_ptr( mcs
->szTitle
);
869 data
->ps
.mcs
.hOwner
= pack_ptr( mcs
->hOwner
);
870 data
->ps
.mcs
.x
= mcs
->x
;
871 data
->ps
.mcs
.y
= mcs
->y
;
872 data
->ps
.mcs
.cx
= mcs
->cx
;
873 data
->ps
.mcs
.cy
= mcs
->cy
;
874 data
->ps
.mcs
.style
= mcs
->style
;
875 data
->ps
.mcs
.lParam
= mcs
->lParam
;
876 push_data( data
, &data
->ps
.mcs
, sizeof(data
->ps
.mcs
) );
879 case WM_ASKCBFORMATNAME
:
880 push_data( data
, (WCHAR
*)lparam
, (lstrlenW((WCHAR
*)lparam
) + 1) * sizeof(WCHAR
) );
885 /***********************************************************************
888 * Unpack a message reply received from another process.
890 static void unpack_reply( HWND hwnd
, UINT message
, WPARAM wparam
, LPARAM lparam
,
891 void *buffer
, size_t size
)
893 union packed_structs
*ps
= buffer
;
899 if (size
>= sizeof(ps
->cs
))
901 CREATESTRUCTW
*cs
= (CREATESTRUCTW
*)lparam
;
902 cs
->lpCreateParams
= unpack_ptr( ps
->cs
.lpCreateParams
);
903 cs
->hInstance
= unpack_ptr( ps
->cs
.hInstance
);
904 cs
->hMenu
= wine_server_ptr_handle( ps
->cs
.hMenu
);
905 cs
->hwndParent
= wine_server_ptr_handle( ps
->cs
.hwndParent
);
910 cs
->style
= ps
->cs
.style
;
911 cs
->dwExStyle
= ps
->cs
.dwExStyle
;
912 /* don't allow changing name and class pointers */
916 case WM_ASKCBFORMATNAME
:
917 memcpy( (WCHAR
*)lparam
, buffer
, min( wparam
*sizeof(WCHAR
), size
));
919 case WM_GETMINMAXINFO
:
920 memcpy( (MINMAXINFO
*)lparam
, buffer
, min( sizeof(MINMAXINFO
), size
));
923 if (size
>= sizeof(ps
->mis
))
925 MEASUREITEMSTRUCT
*mis
= (MEASUREITEMSTRUCT
*)lparam
;
926 mis
->CtlType
= ps
->mis
.CtlType
;
927 mis
->CtlID
= ps
->mis
.CtlID
;
928 mis
->itemID
= ps
->mis
.itemID
;
929 mis
->itemWidth
= ps
->mis
.itemWidth
;
930 mis
->itemHeight
= ps
->mis
.itemHeight
;
931 mis
->itemData
= (ULONG_PTR
)unpack_ptr( ps
->mis
.itemData
);
934 case WM_WINDOWPOSCHANGING
:
935 case WM_WINDOWPOSCHANGED
:
936 if (size
>= sizeof(ps
->wp
))
938 WINDOWPOS
*wp
= (WINDOWPOS
*)lparam
;
939 wp
->hwnd
= wine_server_ptr_handle( ps
->wp
.hwnd
);
940 wp
->hwndInsertAfter
= wine_server_ptr_handle( ps
->wp
.hwndInsertAfter
);
945 wp
->flags
= ps
->wp
.flags
;
949 if (lparam
&& size
>= sizeof(ps
->msg
))
951 MSG
*msg
= (MSG
*)lparam
;
952 msg
->hwnd
= wine_server_ptr_handle( ps
->msg
.hwnd
);
953 msg
->message
= ps
->msg
.message
;
954 msg
->wParam
= (ULONG_PTR
)unpack_ptr( ps
->msg
.wParam
);
955 msg
->lParam
= (ULONG_PTR
)unpack_ptr( ps
->msg
.lParam
);
956 msg
->time
= ps
->msg
.time
;
957 msg
->pt
= ps
->msg
.pt
;
960 case SBM_GETSCROLLINFO
:
961 memcpy( (SCROLLINFO
*)lparam
, buffer
, min( sizeof(SCROLLINFO
), size
));
963 case SBM_GETSCROLLBARINFO
:
964 memcpy( (SCROLLBARINFO
*)lparam
, buffer
, min( sizeof(SCROLLBARINFO
), size
));
967 case CB_GETDROPPEDCONTROLRECT
:
971 memcpy( (RECT
*)lparam
, buffer
, min( sizeof(RECT
), size
));
974 size
= min( size
, (size_t)*(WORD
*)lparam
);
975 memcpy( (WCHAR
*)lparam
, buffer
, size
);
978 memcpy( (UINT
*)lparam
, buffer
, min( wparam
*sizeof(UINT
), size
));
982 memcpy( (WCHAR
*)lparam
, buffer
, size
);
985 if (size
>= sizeof(ps
->mnm
))
987 MDINEXTMENU
*mnm
= (MDINEXTMENU
*)lparam
;
988 mnm
->hmenuIn
= wine_server_ptr_handle( ps
->mnm
.hmenuIn
);
989 mnm
->hmenuNext
= wine_server_ptr_handle( ps
->mnm
.hmenuNext
);
990 mnm
->hwndNext
= wine_server_ptr_handle( ps
->mnm
.hwndNext
);
993 case WM_MDIGETACTIVE
:
994 if (lparam
) memcpy( (BOOL
*)lparam
, buffer
, min( sizeof(BOOL
), size
));
998 memcpy( (RECT
*)lparam
, buffer
, min( sizeof(RECT
), size
));
999 else if (size
>= sizeof(ps
->ncp
))
1001 NCCALCSIZE_PARAMS
*ncp
= (NCCALCSIZE_PARAMS
*)lparam
;
1002 ncp
->rgrc
[0] = ps
->ncp
.rgrc
[0];
1003 ncp
->rgrc
[1] = ps
->ncp
.rgrc
[1];
1004 ncp
->rgrc
[2] = ps
->ncp
.rgrc
[2];
1005 ncp
->lppos
->hwnd
= wine_server_ptr_handle( ps
->ncp
.hwnd
);
1006 ncp
->lppos
->hwndInsertAfter
= wine_server_ptr_handle( ps
->ncp
.hwndInsertAfter
);
1007 ncp
->lppos
->x
= ps
->ncp
.x
;
1008 ncp
->lppos
->y
= ps
->ncp
.y
;
1009 ncp
->lppos
->cx
= ps
->ncp
.cx
;
1010 ncp
->lppos
->cy
= ps
->ncp
.cy
;
1011 ncp
->lppos
->flags
= ps
->ncp
.flags
;
1019 memcpy( (DWORD
*)wparam
, buffer
, min( sizeof(DWORD
), size
));
1020 if (size
<= sizeof(DWORD
)) break;
1021 size
-= sizeof(DWORD
);
1022 buffer
= (DWORD
*)buffer
+ 1;
1024 if (lparam
) memcpy( (DWORD
*)lparam
, buffer
, min( sizeof(DWORD
), size
));
1027 if (size
>= sizeof(ps
->mcs
))
1029 MDICREATESTRUCTW
*mcs
= (MDICREATESTRUCTW
*)lparam
;
1030 mcs
->hOwner
= unpack_ptr( ps
->mcs
.hOwner
);
1033 mcs
->cx
= ps
->mcs
.cx
;
1034 mcs
->cy
= ps
->mcs
.cy
;
1035 mcs
->style
= ps
->mcs
.style
;
1036 mcs
->lParam
= (LPARAM
)unpack_ptr( ps
->mcs
.lParam
);
1037 /* don't allow changing class and title pointers */
1041 ERR( "should not happen: unexpected message %x\n", message
);
1046 /***********************************************************************
1049 * Copy a message reply received from client.
1051 static void copy_reply( LRESULT result
, HWND hwnd
, UINT message
, WPARAM wparam
, LPARAM lparam
,
1052 WPARAM wparam_src
, LPARAM lparam_src
)
1054 size_t copy_size
= 0;
1061 CREATESTRUCTW
*dst
= (CREATESTRUCTW
*)lparam
;
1062 CREATESTRUCTW
*src
= (CREATESTRUCTW
*)lparam_src
;
1063 dst
->lpCreateParams
= src
->lpCreateParams
;
1064 dst
->hInstance
= src
->hInstance
;
1065 dst
->hMenu
= src
->hMenu
;
1066 dst
->hwndParent
= src
->hwndParent
;
1071 dst
->style
= src
->style
;
1072 dst
->dwExStyle
= src
->dwExStyle
;
1073 /* don't allow changing name and class pointers */
1079 copy_size
= (result
+ 1) * sizeof(WCHAR
);
1081 case WM_GETMINMAXINFO
:
1082 copy_size
= sizeof(MINMAXINFO
);
1084 case WM_MEASUREITEM
:
1085 copy_size
= sizeof(MEASUREITEMSTRUCT
);
1087 case WM_WINDOWPOSCHANGING
:
1088 case WM_WINDOWPOSCHANGED
:
1089 copy_size
= sizeof(WINDOWPOS
);
1091 case WM_STYLECHANGING
:
1092 copy_size
= sizeof(STYLESTRUCT
);
1095 if (lparam
) copy_size
= sizeof(MSG
);
1097 case SBM_GETSCROLLINFO
:
1098 copy_size
= sizeof(SCROLLINFO
);
1100 case SBM_GETSCROLLBARINFO
:
1101 copy_size
= sizeof(SCROLLBARINFO
);
1104 case LB_GETITEMRECT
:
1105 case CB_GETDROPPEDCONTROLRECT
:
1108 copy_size
= sizeof(RECT
);
1112 WORD
*ptr
= (WORD
*)lparam
;
1113 copy_size
= ptr
[-1] * sizeof(WCHAR
);
1116 case LB_GETSELITEMS
:
1117 copy_size
= wparam
* sizeof(UINT
);
1119 case WM_MDIGETACTIVE
:
1120 if (lparam
) copy_size
= sizeof(BOOL
);
1125 NCCALCSIZE_PARAMS
*dst
= (NCCALCSIZE_PARAMS
*)lparam
;
1126 NCCALCSIZE_PARAMS
*src
= (NCCALCSIZE_PARAMS
*)lparam_src
;
1127 dst
->rgrc
[0] = src
->rgrc
[0];
1128 dst
->rgrc
[1] = src
->rgrc
[1];
1129 dst
->rgrc
[2] = src
->rgrc
[2];
1130 *dst
->lppos
= *src
->lppos
;
1133 copy_size
= sizeof(RECT
);
1138 if (wparam
) *(DWORD
*)wparam
= *(DWORD
*)wparam_src
;
1139 if (lparam
) copy_size
= sizeof(DWORD
);
1142 copy_size
= sizeof(MDINEXTMENU
);
1145 copy_size
= sizeof(MDICREATESTRUCTW
);
1147 case WM_ASKCBFORMATNAME
:
1148 copy_size
= (lstrlenW((WCHAR
*)lparam
) + 1) * sizeof(WCHAR
);
1154 if (copy_size
) memcpy( (void *)lparam
, (void *)lparam_src
, copy_size
);
1157 /***********************************************************************
1160 * Send a reply to a sent message.
1162 static void reply_message( struct received_message_info
*info
, LRESULT result
, MSG
*msg
)
1164 struct packed_message data
;
1165 int i
, replied
= info
->flags
& ISMEX_REPLIED
;
1166 BOOL remove
= msg
!= NULL
;
1168 if (info
->flags
& ISMEX_NOTIFY
) return; /* notify messages don't get replies */
1169 if (!remove
&& replied
) return; /* replied already */
1171 memset( &data
, 0, sizeof(data
) );
1172 info
->flags
|= ISMEX_REPLIED
;
1173 if (info
== get_user_thread_info()->receive_info
)
1174 NtUserGetThreadInfo()->receive_flags
= info
->flags
;
1176 if (info
->type
== MSG_OTHER_PROCESS
&& !replied
)
1178 if (!msg
) msg
= &info
->msg
;
1179 pack_reply( msg
->hwnd
, msg
->message
, msg
->wParam
, msg
->lParam
, result
, &data
);
1182 SERVER_START_REQ( reply_message
)
1184 req
->result
= result
;
1185 req
->remove
= remove
;
1186 for (i
= 0; i
< data
.count
; i
++) wine_server_add_data( req
, data
.data
[i
], data
.size
[i
] );
1187 wine_server_call( req
);
1192 /***********************************************************************
1193 * reply_message_result
1195 * Send a reply to a sent message and update thread receive info.
1197 BOOL
reply_message_result( LRESULT result
)
1199 struct user_thread_info
*thread_info
= get_user_thread_info();
1200 struct received_message_info
*info
= thread_info
->receive_info
;
1202 while (info
&& info
->type
== MSG_CLIENT_MESSAGE
) info
= info
->prev
;
1203 if (!info
) return FALSE
;
1204 reply_message( info
, result
, NULL
);
1208 /***********************************************************************
1209 * reply_winproc_result
1211 * Send a reply to a sent message and update thread receive info.
1213 static BOOL
reply_winproc_result( LRESULT result
, HWND hwnd
, UINT message
, WPARAM wparam
, LPARAM lparam
)
1215 struct user_thread_info
*thread_info
= get_user_thread_info();
1216 struct received_message_info
*info
= thread_info
->receive_info
;
1219 if (!info
) return FALSE
;
1221 if (info
->type
== MSG_CLIENT_MESSAGE
)
1223 copy_reply( result
, hwnd
, message
, info
->msg
.wParam
, info
->msg
.lParam
, wparam
, lparam
);
1224 info
->result
= result
;
1229 msg
.message
= message
;
1230 msg
.wParam
= wparam
;
1231 msg
.lParam
= lparam
;
1232 reply_message( info
, result
, &msg
);
1234 thread_info
->receive_info
= info
->prev
;
1235 thread_info
->client_info
.receive_flags
= info
->prev
? info
->prev
->flags
: ISMEX_NOSEND
;
1239 /***********************************************************************
1240 * handle_internal_message
1242 * Handle an internal Wine message instead of calling the window proc.
1244 static LRESULT
handle_internal_message( HWND hwnd
, UINT msg
, WPARAM wparam
, LPARAM lparam
)
1248 case WM_WINE_DESTROYWINDOW
:
1249 return destroy_window( hwnd
);
1250 case WM_WINE_SETWINDOWPOS
:
1251 if (is_desktop_window( hwnd
)) return 0;
1252 return set_window_pos( (WINDOWPOS
*)lparam
, 0, 0 );
1253 case WM_WINE_SHOWWINDOW
:
1254 if (is_desktop_window( hwnd
)) return 0;
1255 return NtUserShowWindow( hwnd
, wparam
);
1256 case WM_WINE_SETPARENT
:
1257 if (is_desktop_window( hwnd
)) return 0;
1258 return HandleToUlong( NtUserSetParent( hwnd
, UlongToHandle(wparam
) ));
1259 case WM_WINE_SETWINDOWLONG
:
1260 return set_window_long( hwnd
, (short)LOWORD(wparam
), HIWORD(wparam
), lparam
, FALSE
);
1261 case WM_WINE_SETSTYLE
:
1262 if (is_desktop_window( hwnd
)) return 0;
1263 return set_window_style( hwnd
, wparam
, lparam
);
1264 case WM_WINE_SETACTIVEWINDOW
:
1265 if (!wparam
&& NtUserGetForegroundWindow() == hwnd
) return 0;
1266 return (LRESULT
)NtUserSetActiveWindow( (HWND
)wparam
);
1267 case WM_WINE_KEYBOARD_LL_HOOK
:
1268 case WM_WINE_MOUSE_LL_HOOK
:
1270 struct hook_extra_info
*h_extra
= (struct hook_extra_info
*)lparam
;
1272 return call_current_hook( h_extra
->handle
, HC_ACTION
, wparam
, h_extra
->lparam
);
1274 case WM_WINE_CLIPCURSOR
:
1278 get_clip_cursor( &rect
);
1279 return user_driver
->pClipCursor( &rect
);
1281 return user_driver
->pClipCursor( NULL
);
1282 case WM_WINE_UPDATEWINDOWSTATE
:
1283 update_window_state( hwnd
);
1286 if (msg
>= WM_WINE_FIRST_DRIVER_MSG
&& msg
<= WM_WINE_LAST_DRIVER_MSG
)
1287 return user_driver
->pWindowMessage( hwnd
, msg
, wparam
, lparam
);
1288 FIXME( "unknown internal message %x\n", msg
);
1293 /**********************************************************************
1294 * NtUserGetGUIThreadInfo (win32u.@)
1296 BOOL WINAPI
NtUserGetGUIThreadInfo( DWORD id
, GUITHREADINFO
*info
)
1300 if (info
->cbSize
!= sizeof(*info
))
1302 RtlSetLastWin32Error( ERROR_INVALID_PARAMETER
);
1306 SERVER_START_REQ( get_thread_input
)
1309 if ((ret
= !wine_server_call_err( req
)))
1312 info
->hwndActive
= wine_server_ptr_handle( reply
->active
);
1313 info
->hwndFocus
= wine_server_ptr_handle( reply
->focus
);
1314 info
->hwndCapture
= wine_server_ptr_handle( reply
->capture
);
1315 info
->hwndMenuOwner
= wine_server_ptr_handle( reply
->menu_owner
);
1316 info
->hwndMoveSize
= wine_server_ptr_handle( reply
->move_size
);
1317 info
->hwndCaret
= wine_server_ptr_handle( reply
->caret
);
1318 info
->rcCaret
.left
= reply
->rect
.left
;
1319 info
->rcCaret
.top
= reply
->rect
.top
;
1320 info
->rcCaret
.right
= reply
->rect
.right
;
1321 info
->rcCaret
.bottom
= reply
->rect
.bottom
;
1322 if (reply
->menu_owner
) info
->flags
|= GUI_INMENUMODE
;
1323 if (reply
->move_size
) info
->flags
|= GUI_INMOVESIZE
;
1324 if (reply
->caret
) info
->flags
|= GUI_CARETBLINKING
;
1331 /***********************************************************************
1334 * Call a window procedure and the corresponding hooks.
1336 static LRESULT
call_window_proc( HWND hwnd
, UINT msg
, WPARAM wparam
, LPARAM lparam
,
1337 BOOL unicode
, BOOL same_thread
, enum wm_char_mapping mapping
,
1338 BOOL needs_unpack
, void *buffer
, size_t size
)
1340 struct win_proc_params p
, *params
= &p
;
1343 CWPRETSTRUCT cwpret
;
1345 if (msg
& 0x80000000)
1346 return handle_internal_message( hwnd
, msg
, wparam
, lparam
);
1348 if (!needs_unpack
) size
= 0;
1349 if (!is_current_thread_window( hwnd
)) return 0;
1351 /* first the WH_CALLWNDPROC hook */
1352 cwp
.lParam
= lparam
;
1353 cwp
.wParam
= wparam
;
1355 cwp
.hwnd
= hwnd
= get_full_window_handle( hwnd
);
1356 call_hooks( WH_CALLWNDPROC
, HC_ACTION
, same_thread
, (LPARAM
)&cwp
, sizeof(cwp
) );
1358 if (size
&& !(params
= malloc( sizeof(*params
) + size
))) return 0;
1359 if (!init_window_call_params( params
, hwnd
, msg
, wparam
, lparam
, &result
, !unicode
, mapping
))
1361 if (params
!= &p
) free( params
);
1367 params
->needs_unpack
= TRUE
;
1368 params
->ansi
= FALSE
;
1369 if (size
) memcpy( params
+ 1, buffer
, size
);
1371 dispatch_win_proc_params( params
, sizeof(*params
) + size
);
1372 if (params
!= &p
) free( params
);
1374 /* and finally the WH_CALLWNDPROCRET hook */
1375 cwpret
.lResult
= result
;
1376 cwpret
.lParam
= lparam
;
1377 cwpret
.wParam
= wparam
;
1378 cwpret
.message
= msg
;
1380 call_hooks( WH_CALLWNDPROCRET
, HC_ACTION
, same_thread
, (LPARAM
)&cwpret
, sizeof(cwpret
) );
1384 /***********************************************************************
1385 * call_sendmsg_callback
1387 * Call the callback function of SendMessageCallback.
1389 static inline void call_sendmsg_callback( SENDASYNCPROC callback
, HWND hwnd
, UINT msg
,
1390 ULONG_PTR data
, LRESULT result
)
1392 struct send_async_params params
;
1396 if (!callback
) return;
1398 params
.callback
= callback
;
1402 params
.result
= result
;
1404 TRACE_(relay
)( "\1Call message callback %p (hwnd=%p,msg=%s,data=%08lx,result=%08lx)\n",
1405 callback
, hwnd
, debugstr_msg_name( msg
, hwnd
), data
, result
);
1407 KeUserModeCallback( NtUserCallSendAsyncCallback
, ¶ms
, sizeof(params
), &ret_ptr
, &ret_len
);
1409 TRACE_(relay
)( "\1Ret message callback %p (hwnd=%p,msg=%s,data=%08lx,result=%08lx)\n",
1410 callback
, hwnd
, debugstr_msg_name( msg
, hwnd
), data
, result
);
1413 /***********************************************************************
1414 * accept_hardware_message
1416 * Tell the server we have passed the message to the app
1417 * (even though we may end up dropping it later on)
1419 static void accept_hardware_message( UINT hw_id
)
1421 SERVER_START_REQ( accept_hardware_message
)
1424 if (wine_server_call( req
))
1425 FIXME("Failed to reply to MSG_HARDWARE message. Message may not be removed from queue.\n");
1430 /***********************************************************************
1431 * send_parent_notify
1433 * Send a WM_PARENTNOTIFY to all ancestors of the given window, unless
1434 * the window has the WS_EX_NOPARENTNOTIFY style.
1436 static void send_parent_notify( HWND hwnd
, WORD event
, WORD idChild
, POINT pt
)
1438 /* pt has to be in the client coordinates of the parent window */
1439 map_window_points( 0, hwnd
, &pt
, 1, get_thread_dpi() );
1444 if (!(get_window_long( hwnd
, GWL_STYLE
) & WS_CHILD
)) break;
1445 if (get_window_long( hwnd
, GWL_EXSTYLE
) & WS_EX_NOPARENTNOTIFY
) break;
1446 if (!(parent
= get_parent( hwnd
))) break;
1447 if (parent
== get_desktop_window()) break;
1448 map_window_points( hwnd
, parent
, &pt
, 1, get_thread_dpi() );
1450 send_message( hwnd
, WM_PARENTNOTIFY
,
1451 MAKEWPARAM( event
, idChild
), MAKELPARAM( pt
.x
, pt
.y
) );
1455 /***********************************************************************
1456 * process_keyboard_message
1458 * returns TRUE if the contents of 'msg' should be passed to the application
1460 static BOOL
process_keyboard_message( MSG
*msg
, UINT hw_id
, HWND hwnd_filter
,
1461 UINT first
, UINT last
, BOOL remove
)
1465 if (msg
->message
== WM_KEYDOWN
|| msg
->message
== WM_SYSKEYDOWN
||
1466 msg
->message
== WM_KEYUP
|| msg
->message
== WM_SYSKEYUP
)
1467 switch (msg
->wParam
)
1469 case VK_LSHIFT
: case VK_RSHIFT
:
1470 msg
->wParam
= VK_SHIFT
;
1472 case VK_LCONTROL
: case VK_RCONTROL
:
1473 msg
->wParam
= VK_CONTROL
;
1475 case VK_LMENU
: case VK_RMENU
:
1476 msg
->wParam
= VK_MENU
;
1480 /* FIXME: is this really the right place for this hook? */
1481 event
.message
= msg
->message
;
1482 event
.hwnd
= msg
->hwnd
;
1483 event
.time
= msg
->time
;
1484 event
.paramL
= (msg
->wParam
& 0xFF) | (HIWORD(msg
->lParam
) << 8);
1485 event
.paramH
= msg
->lParam
& 0x7FFF;
1486 if (HIWORD(msg
->lParam
) & 0x0100) event
.paramH
|= 0x8000; /* special_key - bit */
1487 call_hooks( WH_JOURNALRECORD
, HC_ACTION
, 0, (LPARAM
)&event
, sizeof(event
) );
1489 /* check message filters */
1490 if (msg
->message
< first
|| msg
->message
> last
) return FALSE
;
1491 if (!check_hwnd_filter( msg
, hwnd_filter
)) return FALSE
;
1495 if((msg
->message
== WM_KEYDOWN
) &&
1496 (msg
->hwnd
!= get_desktop_window()))
1498 /* Handle F1 key by sending out WM_HELP message */
1499 if (msg
->wParam
== VK_F1
)
1501 NtUserPostMessage( msg
->hwnd
, WM_KEYF1
, 0, 0 );
1503 else if(msg
->wParam
>= VK_BROWSER_BACK
&&
1504 msg
->wParam
<= VK_LAUNCH_APP2
)
1506 /* FIXME: Process keystate */
1507 send_message( msg
->hwnd
, WM_APPCOMMAND
, (WPARAM
)msg
->hwnd
,
1508 MAKELPARAM(0, (FAPPCOMMAND_KEY
| (msg
->wParam
- VK_BROWSER_BACK
+ 1))) );
1511 else if (msg
->message
== WM_KEYUP
)
1513 /* Handle VK_APPS key by posting a WM_CONTEXTMENU message */
1514 if (msg
->wParam
== VK_APPS
&& !is_menu_active())
1515 NtUserPostMessage( msg
->hwnd
, WM_CONTEXTMENU
, (WPARAM
)msg
->hwnd
, -1 );
1519 if (call_hooks( WH_KEYBOARD
, remove
? HC_ACTION
: HC_NOREMOVE
,
1520 LOWORD(msg
->wParam
), msg
->lParam
, 0 ))
1522 /* skip this message */
1523 call_hooks( WH_CBT
, HCBT_KEYSKIPPED
, LOWORD(msg
->wParam
), msg
->lParam
, 0 );
1524 accept_hardware_message( hw_id
);
1527 if (remove
) accept_hardware_message( hw_id
);
1528 msg
->pt
= point_phys_to_win_dpi( msg
->hwnd
, msg
->pt
);
1530 if (remove
&& msg
->message
== WM_KEYDOWN
)
1531 if (ImmProcessKey( msg
->hwnd
, NtUserGetKeyboardLayout(0), msg
->wParam
, msg
->lParam
, 0 ))
1532 msg
->wParam
= VK_PROCESSKEY
;
1537 /***********************************************************************
1538 * process_mouse_message
1540 * returns TRUE if the contents of 'msg' should be passed to the application
1542 static BOOL
process_mouse_message( MSG
*msg
, UINT hw_id
, ULONG_PTR extra_info
, HWND hwnd_filter
,
1543 UINT first
, UINT last
, BOOL remove
)
1552 MOUSEHOOKSTRUCTEX hook
;
1556 /* find the window to dispatch this mouse message to */
1558 info
.cbSize
= sizeof(info
);
1559 NtUserGetGUIThreadInfo( GetCurrentThreadId(), &info
);
1560 if (info
.hwndCapture
)
1563 msg
->hwnd
= info
.hwndCapture
;
1567 HWND orig
= msg
->hwnd
;
1569 msg
->hwnd
= window_from_point( msg
->hwnd
, msg
->pt
, &hittest
);
1570 if (!msg
->hwnd
) /* As a heuristic, try the next window if it's the owner of orig */
1572 HWND next
= get_window_relative( orig
, GW_HWNDNEXT
);
1574 if (next
&& get_window_relative( orig
, GW_OWNER
) == next
&&
1575 is_current_thread_window( next
))
1576 msg
->hwnd
= window_from_point( next
, msg
->pt
, &hittest
);
1580 if (!msg
->hwnd
|| !is_current_thread_window( msg
->hwnd
))
1582 accept_hardware_message( hw_id
);
1586 msg
->pt
= point_phys_to_win_dpi( msg
->hwnd
, msg
->pt
);
1587 SetThreadDpiAwarenessContext( get_window_dpi_awareness_context( msg
->hwnd
));
1589 /* FIXME: is this really the right place for this hook? */
1590 event
.message
= msg
->message
;
1591 event
.time
= msg
->time
;
1592 event
.hwnd
= msg
->hwnd
;
1593 event
.paramL
= msg
->pt
.x
;
1594 event
.paramH
= msg
->pt
.y
;
1595 call_hooks( WH_JOURNALRECORD
, HC_ACTION
, 0, (LPARAM
)&event
, sizeof(event
) );
1597 if (!check_hwnd_filter( msg
, hwnd_filter
)) return FALSE
;
1600 message
= msg
->message
;
1601 wparam
= msg
->wParam
;
1602 /* Note: windows has no concept of a non-client wheel message */
1603 if (message
!= WM_MOUSEWHEEL
)
1605 if (hittest
!= HTCLIENT
)
1607 message
+= WM_NCMOUSEMOVE
- WM_MOUSEMOVE
;
1612 /* coordinates don't get translated while tracking a menu */
1613 /* FIXME: should differentiate popups and top-level menus */
1614 if (!(info
.flags
& GUI_INMENUMODE
))
1615 screen_to_client( msg
->hwnd
, &pt
);
1618 msg
->lParam
= MAKELONG( pt
.x
, pt
.y
);
1620 /* translate double clicks */
1622 if (msg
->message
== WM_LBUTTONDOWN
||
1623 msg
->message
== WM_RBUTTONDOWN
||
1624 msg
->message
== WM_MBUTTONDOWN
||
1625 msg
->message
== WM_XBUTTONDOWN
)
1627 BOOL update
= remove
;
1629 /* translate double clicks -
1630 * note that ...MOUSEMOVEs can slip in between
1631 * ...BUTTONDOWN and ...BUTTONDBLCLK messages */
1633 if ((info
.flags
& (GUI_INMENUMODE
|GUI_INMOVESIZE
)) ||
1634 hittest
!= HTCLIENT
||
1635 (get_class_long( msg
->hwnd
, GCL_STYLE
, FALSE
) & CS_DBLCLKS
))
1637 if ((msg
->message
== clk_msg
.message
) &&
1638 (msg
->hwnd
== clk_msg
.hwnd
) &&
1639 (msg
->wParam
== clk_msg
.wParam
) &&
1640 (msg
->time
- clk_msg
.time
< NtUserGetDoubleClickTime()) &&
1641 (abs(msg
->pt
.x
- clk_msg
.pt
.x
) < get_system_metrics( SM_CXDOUBLECLK
) / 2) &&
1642 (abs(msg
->pt
.y
- clk_msg
.pt
.y
) < get_system_metrics( SM_CYDOUBLECLK
) / 2))
1644 message
+= (WM_LBUTTONDBLCLK
- WM_LBUTTONDOWN
);
1647 clk_msg
.message
= 0; /* clear the double click conditions */
1652 if (message
< first
|| message
> last
) return FALSE
;
1653 /* update static double click conditions */
1654 if (update
) clk_msg
= *msg
;
1658 if (message
< first
|| message
> last
) return FALSE
;
1660 msg
->wParam
= wparam
;
1662 /* message is accepted now (but may still get dropped) */
1665 hook
.hwnd
= msg
->hwnd
;
1666 hook
.wHitTestCode
= hittest
;
1667 hook
.dwExtraInfo
= extra_info
;
1668 hook
.mouseData
= msg
->wParam
;
1669 if (call_hooks( WH_MOUSE
, remove
? HC_ACTION
: HC_NOREMOVE
, message
, (LPARAM
)&hook
, sizeof(hook
) ))
1672 hook
.hwnd
= msg
->hwnd
;
1673 hook
.wHitTestCode
= hittest
;
1674 hook
.dwExtraInfo
= extra_info
;
1675 hook
.mouseData
= msg
->wParam
;
1676 call_hooks( WH_CBT
, HCBT_CLICKSKIPPED
, message
, (LPARAM
)&hook
, sizeof(hook
) );
1677 accept_hardware_message( hw_id
);
1681 if ((hittest
== HTERROR
) || (hittest
== HTNOWHERE
))
1683 send_message( msg
->hwnd
, WM_SETCURSOR
, (WPARAM
)msg
->hwnd
, MAKELONG( hittest
, msg
->message
));
1684 accept_hardware_message( hw_id
);
1688 if (remove
) accept_hardware_message( hw_id
);
1690 if (!remove
|| info
.hwndCapture
)
1692 msg
->message
= message
;
1698 if (msg
->message
== WM_LBUTTONDOWN
||
1699 msg
->message
== WM_RBUTTONDOWN
||
1700 msg
->message
== WM_MBUTTONDOWN
||
1701 msg
->message
== WM_XBUTTONDOWN
)
1703 /* Send the WM_PARENTNOTIFY,
1704 * note that even for double/nonclient clicks
1705 * notification message is still WM_L/M/RBUTTONDOWN.
1707 send_parent_notify( msg
->hwnd
, msg
->message
, 0, msg
->pt
);
1709 /* Activate the window if needed */
1711 if (msg
->hwnd
!= info
.hwndActive
)
1713 HWND hwndTop
= NtUserGetAncestor( msg
->hwnd
, GA_ROOT
);
1715 if ((get_window_long( hwndTop
, GWL_STYLE
) & (WS_POPUP
|WS_CHILD
)) != WS_CHILD
)
1717 UINT ret
= send_message( msg
->hwnd
, WM_MOUSEACTIVATE
, (WPARAM
)hwndTop
,
1718 MAKELONG( hittest
, msg
->message
) );
1721 case MA_NOACTIVATEANDEAT
:
1726 case MA_ACTIVATEANDEAT
:
1731 if (!set_foreground_window( hwndTop
, TRUE
)) eat_msg
= TRUE
;
1734 WARN( "unknown WM_MOUSEACTIVATE code %d\n", ret
);
1741 /* send the WM_SETCURSOR message */
1743 /* Windows sends the normal mouse message as the message parameter
1744 in the WM_SETCURSOR message even if it's non-client mouse message */
1745 send_message( msg
->hwnd
, WM_SETCURSOR
, (WPARAM
)msg
->hwnd
, MAKELONG( hittest
, msg
->message
));
1747 msg
->message
= message
;
1751 /***********************************************************************
1752 * process_hardware_message
1754 * Process a hardware message; return TRUE if message should be passed on to the app
1756 static BOOL
process_hardware_message( MSG
*msg
, UINT hw_id
, const struct hardware_msg_data
*msg_data
,
1757 HWND hwnd_filter
, UINT first
, UINT last
, BOOL remove
)
1759 struct ntuser_thread_info
*thread_info
= NtUserGetThreadInfo();
1760 DPI_AWARENESS_CONTEXT context
;
1763 thread_info
->msg_source
.deviceType
= msg_data
->source
.device
;
1764 thread_info
->msg_source
.originId
= msg_data
->source
.origin
;
1766 /* hardware messages are always in physical coords */
1767 context
= SetThreadDpiAwarenessContext( DPI_AWARENESS_CONTEXT_PER_MONITOR_AWARE
);
1769 if (msg
->message
== WM_INPUT
|| msg
->message
== WM_INPUT_DEVICE_CHANGE
)
1770 ret
= process_rawinput_message( msg
, hw_id
, msg_data
);
1771 else if (is_keyboard_message( msg
->message
))
1772 ret
= process_keyboard_message( msg
, hw_id
, hwnd_filter
, first
, last
, remove
);
1773 else if (is_mouse_message( msg
->message
))
1774 ret
= process_mouse_message( msg
, hw_id
, msg_data
->info
, hwnd_filter
, first
, last
, remove
);
1776 ERR( "unknown message type %x\n", msg
->message
);
1777 SetThreadDpiAwarenessContext( context
);
1781 /***********************************************************************
1784 * Peek for a message matching the given parameters. Return 0 if none are
1785 * available; -1 on error.
1786 * All pending sent messages are processed before returning.
1788 static int peek_message( MSG
*msg
, HWND hwnd
, UINT first
, UINT last
, UINT flags
, UINT changed_mask
)
1791 struct user_thread_info
*thread_info
= get_user_thread_info();
1792 INPUT_MESSAGE_SOURCE prev_source
= thread_info
->client_info
.msg_source
;
1793 struct received_message_info info
;
1794 unsigned int hw_id
= 0; /* id of previous hardware message */
1796 size_t buffer_size
= 1024;
1798 if (!(buffer
= malloc( buffer_size
))) return -1;
1800 if (!first
&& !last
) last
= ~0;
1801 if (hwnd
== HWND_BROADCAST
) hwnd
= HWND_TOPMOST
;
1807 const message_data_t
*msg_data
= buffer
;
1808 BOOL needs_unpack
= FALSE
;
1810 thread_info
->client_info
.msg_source
= prev_source
;
1812 SERVER_START_REQ( get_message
)
1815 req
->get_win
= wine_server_user_handle( hwnd
);
1816 req
->get_first
= first
;
1817 req
->get_last
= last
;
1819 req
->wake_mask
= changed_mask
& (QS_SENDMESSAGE
| QS_SMRESULT
);
1820 req
->changed_mask
= changed_mask
;
1821 wine_server_set_reply( req
, buffer
, buffer_size
);
1822 if (!(res
= wine_server_call( req
)))
1824 size
= wine_server_reply_size( reply
);
1825 info
.type
= reply
->type
;
1826 info
.msg
.hwnd
= wine_server_ptr_handle( reply
->win
);
1827 info
.msg
.message
= reply
->msg
;
1828 info
.msg
.wParam
= reply
->wparam
;
1829 info
.msg
.lParam
= reply
->lparam
;
1830 info
.msg
.time
= reply
->time
;
1831 info
.msg
.pt
.x
= reply
->x
;
1832 info
.msg
.pt
.y
= reply
->y
;
1834 thread_info
->active_hooks
= reply
->active_hooks
;
1836 else buffer_size
= reply
->total
;
1843 if (res
== STATUS_PENDING
)
1845 thread_info
->wake_mask
= changed_mask
& (QS_SENDMESSAGE
| QS_SMRESULT
);
1846 thread_info
->changed_mask
= changed_mask
;
1849 if (res
!= STATUS_BUFFER_OVERFLOW
)
1851 RtlSetLastWin32Error( RtlNtStatusToDosError(res
) );
1854 if (!(buffer
= malloc( buffer_size
))) return -1;
1858 TRACE( "got type %d msg %x (%s) hwnd %p wp %lx lp %lx\n",
1859 info
.type
, info
.msg
.message
,
1860 (info
.type
== MSG_WINEVENT
) ? "MSG_WINEVENT" : debugstr_msg_name(info
.msg
.message
, info
.msg
.hwnd
),
1861 info
.msg
.hwnd
, (long)info
.msg
.wParam
, info
.msg
.lParam
);
1867 info
.flags
= ISMEX_SEND
;
1870 info
.flags
= ISMEX_NOTIFY
;
1871 if (!unpack_message( info
.msg
.hwnd
, info
.msg
.message
, &info
.msg
.wParam
,
1872 &info
.msg
.lParam
, &buffer
, size
))
1874 needs_unpack
= TRUE
;
1877 info
.flags
= ISMEX_CALLBACK
;
1879 case MSG_CALLBACK_RESULT
:
1880 if (size
>= sizeof(msg_data
->callback
))
1881 call_sendmsg_callback( wine_server_get_ptr(msg_data
->callback
.callback
),
1882 info
.msg
.hwnd
, info
.msg
.message
,
1883 msg_data
->callback
.data
, msg_data
->callback
.result
);
1886 if (size
>= sizeof(msg_data
->winevent
))
1888 struct win_event_hook_params params
;
1892 params
.proc
= wine_server_get_ptr( msg_data
->winevent
.hook_proc
);
1893 size
-= sizeof(msg_data
->winevent
);
1896 size
= min( size
, sizeof(params
.module
) - sizeof(WCHAR
) );
1897 memcpy( params
.module
, &msg_data
->winevent
+ 1, size
);
1899 params
.module
[size
/ sizeof(WCHAR
)] = 0;
1900 size
= FIELD_OFFSET( struct win_event_hook_params
, module
[size
/ sizeof(WCHAR
) + 1] );
1902 params
.handle
= wine_server_ptr_handle( msg_data
->winevent
.hook
);
1903 params
.event
= info
.msg
.message
;
1904 params
.hwnd
= info
.msg
.hwnd
;
1905 params
.object_id
= info
.msg
.wParam
;
1906 params
.child_id
= info
.msg
.lParam
;
1907 params
.tid
= msg_data
->winevent
.tid
;
1908 params
.time
= info
.msg
.time
;
1910 KeUserModeCallback( NtUserCallWinEventHook
, ¶ms
, size
, &ret_ptr
, &ret_len
);
1914 info
.flags
= ISMEX_SEND
;
1916 if (info
.msg
.message
== WH_KEYBOARD_LL
&& size
>= sizeof(msg_data
->hardware
))
1918 KBDLLHOOKSTRUCT hook
;
1920 hook
.vkCode
= LOWORD( info
.msg
.lParam
);
1921 hook
.scanCode
= HIWORD( info
.msg
.lParam
);
1922 hook
.flags
= msg_data
->hardware
.flags
;
1923 hook
.time
= info
.msg
.time
;
1924 hook
.dwExtraInfo
= msg_data
->hardware
.info
;
1925 TRACE( "calling keyboard LL hook vk %x scan %x flags %x time %u info %lx\n",
1926 (int)hook
.vkCode
, (int)hook
.scanCode
, (int)hook
.flags
,
1927 (int)hook
.time
, (long)hook
.dwExtraInfo
);
1928 result
= call_hooks( WH_KEYBOARD_LL
, HC_ACTION
, info
.msg
.wParam
,
1929 (LPARAM
)&hook
, sizeof(hook
) );
1931 else if (info
.msg
.message
== WH_MOUSE_LL
&& size
>= sizeof(msg_data
->hardware
))
1933 MSLLHOOKSTRUCT hook
;
1935 hook
.pt
= info
.msg
.pt
;
1936 hook
.mouseData
= info
.msg
.lParam
;
1937 hook
.flags
= msg_data
->hardware
.flags
;
1938 hook
.time
= info
.msg
.time
;
1939 hook
.dwExtraInfo
= msg_data
->hardware
.info
;
1940 TRACE( "calling mouse LL hook pos %d,%d data %x flags %x time %u info %lx\n",
1941 (int)hook
.pt
.x
, (int)hook
.pt
.y
, (int)hook
.mouseData
, (int)hook
.flags
,
1942 (int)hook
.time
, (long)hook
.dwExtraInfo
);
1943 result
= call_hooks( WH_MOUSE_LL
, HC_ACTION
, info
.msg
.wParam
,
1944 (LPARAM
)&hook
, sizeof(hook
) );
1946 reply_message( &info
, result
, &info
.msg
);
1948 case MSG_OTHER_PROCESS
:
1949 info
.flags
= ISMEX_SEND
;
1950 if (!unpack_message( info
.msg
.hwnd
, info
.msg
.message
, &info
.msg
.wParam
,
1951 &info
.msg
.lParam
, &buffer
, size
))
1954 reply_message( &info
, 0, &info
.msg
);
1957 needs_unpack
= TRUE
;
1960 if (size
>= sizeof(msg_data
->hardware
))
1962 hw_id
= msg_data
->hardware
.hw_id
;
1963 if (!process_hardware_message( &info
.msg
, hw_id
, &msg_data
->hardware
,
1964 hwnd
, first
, last
, flags
& PM_REMOVE
))
1966 TRACE("dropping msg %x\n", info
.msg
.message
);
1967 continue; /* ignore it */
1970 thread_info
->client_info
.message_pos
= MAKELONG( info
.msg
.pt
.x
, info
.msg
.pt
.y
);
1971 thread_info
->client_info
.message_time
= info
.msg
.time
;
1972 thread_info
->client_info
.message_extra
= msg_data
->hardware
.info
;
1974 call_hooks( WH_GETMESSAGE
, HC_ACTION
, flags
& PM_REMOVE
, (LPARAM
)msg
, sizeof(*msg
) );
1979 if (info
.msg
.message
& 0x80000000) /* internal message */
1981 if (flags
& PM_REMOVE
)
1983 handle_internal_message( info
.msg
.hwnd
, info
.msg
.message
,
1984 info
.msg
.wParam
, info
.msg
.lParam
);
1985 /* if this is a nested call return right away */
1986 if (first
== info
.msg
.message
&& last
== info
.msg
.message
)
1993 peek_message( msg
, info
.msg
.hwnd
, info
.msg
.message
,
1994 info
.msg
.message
, flags
| PM_REMOVE
, changed_mask
);
1997 if (info
.msg
.message
>= WM_DDE_FIRST
&& info
.msg
.message
<= WM_DDE_LAST
)
1999 struct unpack_dde_message_result result
;
2000 struct unpack_dde_message_params
*params
;
2005 len
= FIELD_OFFSET( struct unpack_dde_message_params
, data
[size
] );
2006 if (!(params
= malloc( len
)))
2008 params
->result
= &result
;
2009 params
->hwnd
= info
.msg
.hwnd
;
2010 params
->message
= info
.msg
.message
;
2011 params
->wparam
= info
.msg
.wParam
;
2012 params
->lparam
= info
.msg
.lParam
;
2013 if (size
) memcpy( params
->data
, buffer
, size
);
2014 ret
= KeUserModeCallback( NtUserUnpackDDEMessage
, params
, len
, &ret_ptr
, &len
);
2015 if (len
== sizeof(result
)) result
= *(struct unpack_dde_message_result
*)ret_ptr
;
2017 if (!ret
) continue; /* ignore it */
2018 info
.msg
.wParam
= result
.wparam
;
2019 info
.msg
.lParam
= result
.lparam
;
2022 msg
->pt
= point_phys_to_win_dpi( info
.msg
.hwnd
, info
.msg
.pt
);
2023 thread_info
->client_info
.message_pos
= MAKELONG( msg
->pt
.x
, msg
->pt
.y
);
2024 thread_info
->client_info
.message_time
= info
.msg
.time
;
2025 thread_info
->client_info
.message_extra
= 0;
2026 thread_info
->client_info
.msg_source
= msg_source_unavailable
;
2028 call_hooks( WH_GETMESSAGE
, HC_ACTION
, flags
& PM_REMOVE
, (LPARAM
)msg
, sizeof(*msg
) );
2032 /* if we get here, we have a sent message; call the window procedure */
2033 info
.prev
= thread_info
->receive_info
;
2034 thread_info
->receive_info
= &info
;
2035 thread_info
->client_info
.msg_source
= msg_source_unavailable
;
2036 thread_info
->client_info
.receive_flags
= info
.flags
;
2037 result
= call_window_proc( info
.msg
.hwnd
, info
.msg
.message
, info
.msg
.wParam
,
2038 info
.msg
.lParam
, (info
.type
!= MSG_ASCII
), FALSE
,
2039 WMCHAR_MAP_RECVMESSAGE
, needs_unpack
, buffer
, size
);
2040 if (thread_info
->receive_info
== &info
)
2041 reply_winproc_result( result
, info
.msg
.hwnd
, info
.msg
.message
,
2042 info
.msg
.wParam
, info
.msg
.lParam
);
2044 /* if some PM_QS* flags were specified, only handle sent messages from now on */
2045 if (HIWORD(flags
) && !changed_mask
) flags
= PM_QS_SENDMESSAGE
| LOWORD(flags
);
2049 /***********************************************************************
2050 * process_sent_messages
2052 * Process all pending sent messages.
2054 static void process_sent_messages(void)
2057 peek_message( &msg
, 0, 0, 0, PM_REMOVE
| PM_QS_SENDMESSAGE
, 0 );
2060 /***********************************************************************
2061 * get_server_queue_handle
2063 * Get a handle to the server message queue for the current thread.
2065 static HANDLE
get_server_queue_handle(void)
2067 struct user_thread_info
*thread_info
= get_user_thread_info();
2070 if (!(ret
= thread_info
->server_queue
))
2072 SERVER_START_REQ( get_msg_queue
)
2074 wine_server_call( req
);
2075 ret
= wine_server_ptr_handle( reply
->handle
);
2078 thread_info
->server_queue
= ret
;
2079 if (!ret
) ERR( "Cannot get server thread queue\n" );
2084 /* check for driver events if we detect that the app is not properly consuming messages */
2085 static inline void check_for_driver_events( UINT msg
)
2087 if (get_user_thread_info()->message_count
> 200)
2089 flush_window_surfaces( FALSE
);
2090 user_driver
->pProcessEvents( QS_ALLINPUT
);
2092 else if (msg
== WM_TIMER
|| msg
== WM_SYSTIMER
)
2094 /* driver events should have priority over timers, so make sure we'll check for them soon */
2095 get_user_thread_info()->message_count
+= 100;
2097 else get_user_thread_info()->message_count
++;
2100 /* helper for kernel32->ntdll timeout format conversion */
2101 static inline LARGE_INTEGER
*get_nt_timeout( LARGE_INTEGER
*time
, DWORD timeout
)
2103 if (timeout
== INFINITE
) return NULL
;
2104 time
->QuadPart
= (ULONGLONG
)timeout
* -10000;
2108 /* wait for message or signaled handle */
2109 static DWORD
wait_message( DWORD count
, const HANDLE
*handles
, DWORD timeout
, DWORD mask
, DWORD flags
)
2116 if (enable_thunk_lock
)
2117 lock
= KeUserModeCallback( NtUserThunkLock
, NULL
, 0, &ret_ptr
, &ret_len
);
2119 if (user_driver
->pProcessEvents( mask
)) ret
= count
? count
- 1 : 0;
2122 ret
= NtWaitForMultipleObjects( count
, handles
, !(flags
& MWMO_WAITALL
),
2123 !!(flags
& MWMO_ALERTABLE
), get_nt_timeout( &time
, timeout
));
2124 if (ret
== count
- 1) user_driver
->pProcessEvents( mask
);
2125 else if (HIWORD(ret
)) /* is it an error code? */
2127 RtlSetLastWin32Error( RtlNtStatusToDosError(ret
) );
2131 else ret
= WAIT_TIMEOUT
;
2133 if (ret
== WAIT_TIMEOUT
&& !count
&& !timeout
) NtYieldExecution();
2134 if ((mask
& QS_INPUT
) == QS_INPUT
) get_user_thread_info()->message_count
= 0;
2136 if (enable_thunk_lock
)
2137 KeUserModeCallback( NtUserThunkLock
, &lock
, sizeof(lock
), &ret_ptr
, &ret_len
);
2142 /***********************************************************************
2145 * Wait for multiple objects including the server queue, with specific queue masks.
2147 static DWORD
wait_objects( DWORD count
, const HANDLE
*handles
, DWORD timeout
,
2148 DWORD wake_mask
, DWORD changed_mask
, DWORD flags
)
2150 struct user_thread_info
*thread_info
= get_user_thread_info();
2153 assert( count
); /* we must have at least the server queue */
2155 flush_window_surfaces( TRUE
);
2157 if (thread_info
->wake_mask
!= wake_mask
|| thread_info
->changed_mask
!= changed_mask
)
2159 SERVER_START_REQ( set_queue_mask
)
2161 req
->wake_mask
= wake_mask
;
2162 req
->changed_mask
= changed_mask
;
2164 wine_server_call( req
);
2167 thread_info
->wake_mask
= wake_mask
;
2168 thread_info
->changed_mask
= changed_mask
;
2171 ret
= wait_message( count
, handles
, timeout
, changed_mask
, flags
);
2173 if (ret
!= WAIT_TIMEOUT
) thread_info
->wake_mask
= thread_info
->changed_mask
= 0;
2177 static HANDLE
normalize_std_handle( HANDLE handle
)
2179 if (handle
== (HANDLE
)STD_INPUT_HANDLE
)
2180 return NtCurrentTeb()->Peb
->ProcessParameters
->hStdInput
;
2181 if (handle
== (HANDLE
)STD_OUTPUT_HANDLE
)
2182 return NtCurrentTeb()->Peb
->ProcessParameters
->hStdOutput
;
2183 if (handle
== (HANDLE
)STD_ERROR_HANDLE
)
2184 return NtCurrentTeb()->Peb
->ProcessParameters
->hStdError
;
2189 /***********************************************************************
2190 * NtUserMsgWaitForMultipleObjectsEx (win32u.@)
2192 DWORD WINAPI
NtUserMsgWaitForMultipleObjectsEx( DWORD count
, const HANDLE
*handles
,
2193 DWORD timeout
, DWORD mask
, DWORD flags
)
2195 HANDLE wait_handles
[MAXIMUM_WAIT_OBJECTS
];
2198 if (count
> MAXIMUM_WAIT_OBJECTS
-1)
2200 RtlSetLastWin32Error( ERROR_INVALID_PARAMETER
);
2204 /* add the queue to the handle list */
2205 for (i
= 0; i
< count
; i
++) wait_handles
[i
] = normalize_std_handle( handles
[i
] );
2206 wait_handles
[count
] = get_server_queue_handle();
2208 return wait_objects( count
+1, wait_handles
, timeout
,
2209 (flags
& MWMO_INPUTAVAILABLE
) ? mask
: 0, mask
, flags
);
2212 /***********************************************************************
2213 * NtUserWaitForInputIdle (win32u.@)
2215 DWORD WINAPI
NtUserWaitForInputIdle( HANDLE process
, DWORD timeout
, BOOL wow
)
2217 DWORD start_time
, elapsed
, ret
;
2220 handles
[0] = process
;
2221 SERVER_START_REQ( get_process_idle_event
)
2223 req
->handle
= wine_server_obj_handle( process
);
2224 wine_server_call_err( req
);
2225 handles
[1] = wine_server_ptr_handle( reply
->event
);
2228 if (!handles
[1]) return WAIT_FAILED
; /* no event to wait on */
2230 start_time
= NtGetTickCount();
2233 TRACE("waiting for %p\n", handles
[1] );
2237 ret
= NtUserMsgWaitForMultipleObjectsEx( 2, handles
, timeout
- elapsed
, QS_SENDMESSAGE
, 0 );
2242 case WAIT_OBJECT_0
+2:
2243 process_sent_messages();
2247 TRACE("timeout or error\n");
2250 TRACE("finished\n");
2253 if (timeout
!= INFINITE
)
2255 elapsed
= NtGetTickCount() - start_time
;
2256 if (elapsed
> timeout
)
2261 return WAIT_TIMEOUT
;
2264 /***********************************************************************
2265 * NtUserWaitMessage (win32u.@)
2267 BOOL WINAPI
NtUserWaitMessage(void)
2269 return NtUserMsgWaitForMultipleObjectsEx( 0, NULL
, INFINITE
, QS_ALLINPUT
, 0 ) != WAIT_FAILED
;
2272 /***********************************************************************
2273 * NtUserPeekMessage (win32u.@)
2275 BOOL WINAPI
NtUserPeekMessage( MSG
*msg_out
, HWND hwnd
, UINT first
, UINT last
, UINT flags
)
2280 user_check_not_lock();
2281 check_for_driver_events( 0 );
2283 ret
= peek_message( &msg
, hwnd
, first
, last
, flags
, 0 );
2284 if (ret
< 0) return FALSE
;
2288 flush_window_surfaces( TRUE
);
2289 ret
= wait_message( 0, NULL
, 0, QS_ALLINPUT
, 0 );
2290 /* if we received driver events, check again for a pending message */
2291 if (ret
== WAIT_TIMEOUT
|| peek_message( &msg
, hwnd
, first
, last
, flags
, 0 ) <= 0) return FALSE
;
2294 check_for_driver_events( msg
.message
);
2296 /* copy back our internal safe copy of message data to msg_out.
2297 * msg_out is a variable from the *program*, so it can't be used
2298 * internally as it can get "corrupted" by our use of SendMessage()
2299 * (back to the program) inside the message handling itself. */
2302 RtlSetLastWin32Error( ERROR_NOACCESS
);
2309 /***********************************************************************
2310 * NtUserGetMessage (win32u.@)
2312 BOOL WINAPI
NtUserGetMessage( MSG
*msg
, HWND hwnd
, UINT first
, UINT last
)
2314 HANDLE server_queue
= get_server_queue_handle();
2315 unsigned int mask
= QS_POSTMESSAGE
| QS_SENDMESSAGE
; /* Always selected */
2318 user_check_not_lock();
2319 check_for_driver_events( 0 );
2323 if ((first
<= WM_KEYLAST
) && (last
>= WM_KEYFIRST
)) mask
|= QS_KEY
;
2324 if ( ((first
<= WM_MOUSELAST
) && (last
>= WM_MOUSEFIRST
)) ||
2325 ((first
<= WM_NCMOUSELAST
) && (last
>= WM_NCMOUSEFIRST
)) ) mask
|= QS_MOUSE
;
2326 if ((first
<= WM_TIMER
) && (last
>= WM_TIMER
)) mask
|= QS_TIMER
;
2327 if ((first
<= WM_SYSTIMER
) && (last
>= WM_SYSTIMER
)) mask
|= QS_TIMER
;
2328 if ((first
<= WM_PAINT
) && (last
>= WM_PAINT
)) mask
|= QS_PAINT
;
2330 else mask
= QS_ALLINPUT
;
2332 while (!(ret
= peek_message( msg
, hwnd
, first
, last
, PM_REMOVE
| (mask
<< 16), mask
)))
2334 wait_objects( 1, &server_queue
, INFINITE
, mask
& (QS_SENDMESSAGE
| QS_SMRESULT
), mask
, 0 );
2336 if (ret
< 0) return -1;
2338 check_for_driver_events( msg
->message
);
2340 return msg
->message
!= WM_QUIT
;
2343 /***********************************************************************
2344 * put_message_in_queue
2346 * Put a sent message into the destination queue.
2347 * For inter-process message, reply_size is set to expected size of reply data.
2349 static BOOL
put_message_in_queue( const struct send_message_info
*info
, size_t *reply_size
)
2351 struct packed_message data
;
2352 message_data_t msg_data
;
2355 timeout_t timeout
= TIMEOUT_INFINITE
;
2357 /* Check for INFINITE timeout for compatibility with Win9x,
2358 * although Windows >= NT does not do so
2360 if (info
->type
!= MSG_NOTIFY
&&
2361 info
->type
!= MSG_CALLBACK
&&
2362 info
->type
!= MSG_POSTED
&&
2364 info
->timeout
!= INFINITE
)
2366 /* timeout is signed despite the prototype */
2367 timeout
= (timeout_t
)max( 0, (int)info
->timeout
) * -10000;
2370 memset( &data
, 0, sizeof(data
) );
2371 if (info
->type
== MSG_OTHER_PROCESS
|| info
->type
== MSG_NOTIFY
)
2373 *reply_size
= pack_message( info
->hwnd
, info
->msg
, info
->wparam
, info
->lparam
, &data
);
2374 if (data
.count
== -1)
2376 WARN( "cannot pack message %x\n", info
->msg
);
2380 else if (info
->type
== MSG_CALLBACK
)
2382 msg_data
.callback
.callback
= wine_server_client_ptr( info
->callback
);
2383 msg_data
.callback
.data
= info
->data
;
2384 msg_data
.callback
.result
= 0;
2385 data
.data
[0] = &msg_data
;
2386 data
.size
[0] = sizeof(msg_data
.callback
);
2389 else if (info
->type
== MSG_POSTED
&& info
->msg
>= WM_DDE_FIRST
&& info
->msg
<= WM_DDE_LAST
)
2391 struct post_dde_message_params params
;
2395 params
.hwnd
= info
->hwnd
;
2396 params
.msg
= info
->msg
;
2397 params
.wparam
= info
->wparam
;
2398 params
.lparam
= info
->lparam
;
2399 params
.dest_tid
= info
->dest_tid
;
2400 params
.type
= info
->type
;
2401 return KeUserModeCallback( NtUserPostDDEMessage
, ¶ms
, sizeof(params
), &ret_ptr
, &ret_len
);
2404 SERVER_START_REQ( send_message
)
2406 req
->id
= info
->dest_tid
;
2407 req
->type
= info
->type
;
2409 req
->win
= wine_server_user_handle( info
->hwnd
);
2410 req
->msg
= info
->msg
;
2411 req
->wparam
= info
->wparam
;
2412 req
->lparam
= info
->lparam
;
2413 req
->timeout
= timeout
;
2415 if (info
->flags
& SMTO_ABORTIFHUNG
) req
->flags
|= SEND_MSG_ABORT_IF_HUNG
;
2416 for (i
= 0; i
< data
.count
; i
++) wine_server_add_data( req
, data
.data
[i
], data
.size
[i
] );
2417 if ((res
= wine_server_call( req
)))
2419 if (res
== STATUS_INVALID_PARAMETER
)
2420 /* FIXME: find a STATUS_ value for this one */
2421 RtlSetLastWin32Error( ERROR_INVALID_THREAD_ID
);
2423 RtlSetLastWin32Error( RtlNtStatusToDosError(res
) );
2430 /***********************************************************************
2431 * wait_message_reply
2433 * Wait until a sent message gets replied to.
2435 static void wait_message_reply( UINT flags
)
2437 struct user_thread_info
*thread_info
= get_user_thread_info();
2438 HANDLE server_queue
= get_server_queue_handle();
2439 unsigned int wake_mask
= QS_SMRESULT
| ((flags
& SMTO_BLOCK
) ? 0 : QS_SENDMESSAGE
);
2443 unsigned int wake_bits
= 0;
2445 SERVER_START_REQ( set_queue_mask
)
2447 req
->wake_mask
= wake_mask
;
2448 req
->changed_mask
= wake_mask
;
2450 if (!wine_server_call( req
)) wake_bits
= reply
->wake_bits
& wake_mask
;
2454 thread_info
->wake_mask
= thread_info
->changed_mask
= 0;
2456 if (wake_bits
& QS_SMRESULT
) return; /* got a result */
2457 if (wake_bits
& QS_SENDMESSAGE
)
2459 /* Process the sent message immediately */
2460 process_sent_messages();
2464 wait_message( 1, &server_queue
, INFINITE
, wake_mask
, 0 );
2468 /***********************************************************************
2471 * Retrieve a message reply from the server.
2473 static LRESULT
retrieve_reply( const struct send_message_info
*info
,
2474 size_t reply_size
, LRESULT
*result
)
2476 unsigned int status
;
2477 void *reply_data
= NULL
;
2481 if (!(reply_data
= malloc( reply_size
)))
2483 WARN( "no memory for reply, will be truncated\n" );
2487 SERVER_START_REQ( get_message_reply
)
2490 if (reply_size
) wine_server_set_reply( req
, reply_data
, reply_size
);
2491 if (!(status
= wine_server_call( req
))) *result
= reply
->result
;
2492 reply_size
= wine_server_reply_size( reply
);
2495 if (!status
&& reply_size
)
2496 unpack_reply( info
->hwnd
, info
->msg
, info
->wparam
, info
->lparam
, reply_data
, reply_size
);
2500 TRACE( "hwnd %p msg %x (%s) wp %lx lp %lx got reply %lx (err=%d)\n",
2501 info
->hwnd
, info
->msg
, debugstr_msg_name(info
->msg
, info
->hwnd
), (long)info
->wparam
,
2502 info
->lparam
, *result
, status
);
2504 /* MSDN states that last error is 0 on timeout, but at least NT4 returns ERROR_TIMEOUT */
2505 if (status
) RtlSetLastWin32Error( RtlNtStatusToDosError(status
) );
2509 /***********************************************************************
2510 * send_inter_thread_message
2512 static LRESULT
send_inter_thread_message( const struct send_message_info
*info
, LRESULT
*res_ptr
)
2514 size_t reply_size
= 0;
2516 TRACE( "hwnd %p msg %x (%s) wp %lx lp %lx\n",
2517 info
->hwnd
, info
->msg
, debugstr_msg_name(info
->msg
, info
->hwnd
),
2518 (long)info
->wparam
, info
->lparam
);
2520 user_check_not_lock();
2522 if (!put_message_in_queue( info
, &reply_size
)) return 0;
2524 /* there's no reply to wait for on notify/callback messages */
2525 if (info
->type
== MSG_NOTIFY
|| info
->type
== MSG_CALLBACK
) return 1;
2527 wait_message_reply( info
->flags
);
2528 return retrieve_reply( info
, reply_size
, res_ptr
);
2531 static LRESULT
send_inter_thread_callback( HWND hwnd
, UINT msg
, WPARAM wp
, LPARAM lp
,
2532 LRESULT
*result
, void *arg
)
2534 struct send_message_info
*info
= arg
;
2539 return send_inter_thread_message( info
, result
);
2542 /***********************************************************************
2543 * send_internal_message_timeout
2545 * Same as SendMessageTimeoutW but sends the message to a specific thread
2546 * without requiring a window handle. Only works for internal Wine messages.
2548 LRESULT
send_internal_message_timeout( DWORD dest_pid
, DWORD dest_tid
,
2549 UINT msg
, WPARAM wparam
, LPARAM lparam
,
2550 UINT flags
, UINT timeout
, PDWORD_PTR res_ptr
)
2552 LRESULT ret
, result
= 0;
2554 assert( msg
& 0x80000000 ); /* must be an internal Wine message */
2556 if (is_exiting_thread( dest_tid
)) return 0;
2558 if (dest_tid
== GetCurrentThreadId())
2560 result
= handle_internal_message( 0, msg
, wparam
, lparam
);
2565 struct send_message_info info
;
2567 info
.type
= dest_pid
== GetCurrentProcessId() ? MSG_UNICODE
: MSG_OTHER_PROCESS
;
2568 info
.dest_tid
= dest_tid
;
2571 info
.wparam
= wparam
;
2572 info
.lparam
= lparam
;
2574 info
.timeout
= timeout
;
2577 ret
= send_inter_thread_message( &info
, &result
);
2579 if (ret
&& res_ptr
) *res_ptr
= result
;
2583 /***********************************************************************
2584 * send_hardware_message
2586 NTSTATUS
send_hardware_message( HWND hwnd
, const INPUT
*input
, const RAWINPUT
*rawinput
, UINT flags
)
2588 struct send_message_info info
;
2589 int prev_x
, prev_y
, new_x
, new_y
;
2590 USAGE hid_usage_page
, hid_usage
;
2592 BOOL wait
, affects_key_state
= FALSE
;
2594 info
.type
= MSG_HARDWARE
;
2601 if (input
->type
== INPUT_HARDWARE
&& rawinput
->header
.dwType
== RIM_TYPEHID
)
2603 if (input
->hi
.uMsg
== WM_INPUT_DEVICE_CHANGE
)
2605 hid_usage_page
= ((USAGE
*)rawinput
->data
.hid
.bRawData
)[0];
2606 hid_usage
= ((USAGE
*)rawinput
->data
.hid
.bRawData
)[1];
2608 if (input
->hi
.uMsg
== WM_INPUT
&&
2609 !rawinput_device_get_usages( rawinput
->header
.hDevice
, &hid_usage_page
, &hid_usage
))
2611 WARN( "unable to get HID usages for device %p\n", rawinput
->header
.hDevice
);
2612 return STATUS_INVALID_HANDLE
;
2616 SERVER_START_REQ( send_hardware_message
)
2618 req
->win
= wine_server_user_handle( hwnd
);
2620 req
->input
.type
= input
->type
;
2621 switch (input
->type
)
2624 req
->input
.mouse
.x
= input
->mi
.dx
;
2625 req
->input
.mouse
.y
= input
->mi
.dy
;
2626 req
->input
.mouse
.data
= input
->mi
.mouseData
;
2627 req
->input
.mouse
.flags
= input
->mi
.dwFlags
;
2628 req
->input
.mouse
.time
= input
->mi
.time
;
2629 req
->input
.mouse
.info
= input
->mi
.dwExtraInfo
;
2630 affects_key_state
= !!(input
->mi
.dwFlags
& (MOUSEEVENTF_LEFTDOWN
| MOUSEEVENTF_LEFTUP
|
2631 MOUSEEVENTF_RIGHTDOWN
| MOUSEEVENTF_RIGHTUP
|
2632 MOUSEEVENTF_MIDDLEDOWN
| MOUSEEVENTF_MIDDLEUP
|
2633 MOUSEEVENTF_XDOWN
| MOUSEEVENTF_XUP
));
2635 case INPUT_KEYBOARD
:
2636 req
->input
.kbd
.vkey
= input
->ki
.wVk
;
2637 req
->input
.kbd
.scan
= input
->ki
.wScan
;
2638 req
->input
.kbd
.flags
= input
->ki
.dwFlags
;
2639 req
->input
.kbd
.time
= input
->ki
.time
;
2640 req
->input
.kbd
.info
= input
->ki
.dwExtraInfo
;
2641 affects_key_state
= TRUE
;
2643 case INPUT_HARDWARE
:
2644 req
->input
.hw
.msg
= input
->hi
.uMsg
;
2645 req
->input
.hw
.lparam
= MAKELONG( input
->hi
.wParamL
, input
->hi
.wParamH
);
2646 switch (input
->hi
.uMsg
)
2649 case WM_INPUT_DEVICE_CHANGE
:
2650 req
->input
.hw
.rawinput
.type
= rawinput
->header
.dwType
;
2651 switch (rawinput
->header
.dwType
)
2654 req
->input
.hw
.rawinput
.hid
.device
= HandleToUlong( rawinput
->header
.hDevice
);
2655 req
->input
.hw
.rawinput
.hid
.param
= rawinput
->header
.wParam
;
2656 req
->input
.hw
.rawinput
.hid
.usage_page
= hid_usage_page
;
2657 req
->input
.hw
.rawinput
.hid
.usage
= hid_usage
;
2658 req
->input
.hw
.rawinput
.hid
.count
= rawinput
->data
.hid
.dwCount
;
2659 req
->input
.hw
.rawinput
.hid
.length
= rawinput
->data
.hid
.dwSizeHid
;
2660 wine_server_add_data( req
, rawinput
->data
.hid
.bRawData
,
2661 rawinput
->data
.hid
.dwCount
* rawinput
->data
.hid
.dwSizeHid
);
2670 ret
= wine_server_call( req
);
2672 prev_x
= reply
->prev_x
;
2673 prev_y
= reply
->prev_y
;
2674 new_x
= reply
->new_x
;
2675 new_y
= reply
->new_y
;
2681 if (affects_key_state
)
2682 InterlockedIncrement( &global_key_state_counter
); /* force refreshing the key state cache */
2683 if ((flags
& SEND_HWMSG_INJECTED
) && (prev_x
!= new_x
|| prev_y
!= new_y
))
2684 user_driver
->pSetCursorPos( new_x
, new_y
);
2690 wait_message_reply( 0 );
2691 retrieve_reply( &info
, 0, &ignored
);
2696 /**********************************************************************
2697 * NtUserDispatchMessage (win32u.@)
2699 LRESULT WINAPI
NtUserDispatchMessage( const MSG
*msg
)
2701 struct win_proc_params params
;
2704 /* Process timer messages */
2705 if (msg
->lParam
&& msg
->message
== WM_TIMER
)
2707 params
.func
= (WNDPROC
)msg
->lParam
;
2708 params
.result
= &retval
; /* FIXME */
2709 if (!init_win_proc_params( ¶ms
, msg
->hwnd
, msg
->message
,
2710 msg
->wParam
, NtGetTickCount(), FALSE
))
2712 dispatch_win_proc_params( ¶ms
, sizeof(params
) );
2715 if (msg
->message
== WM_SYSTIMER
)
2717 switch (msg
->wParam
)
2719 case SYSTEM_TIMER_CARET
:
2720 toggle_caret( msg
->hwnd
);
2723 case SYSTEM_TIMER_TRACK_MOUSE
:
2724 update_mouse_tracking_info( msg
->hwnd
);
2729 if (!msg
->hwnd
) return 0;
2731 spy_enter_message( SPY_DISPATCHMESSAGE
, msg
->hwnd
, msg
->message
, msg
->wParam
, msg
->lParam
);
2733 if (init_window_call_params( ¶ms
, msg
->hwnd
, msg
->message
, msg
->wParam
, msg
->lParam
,
2734 &retval
, FALSE
, WMCHAR_MAP_DISPATCHMESSAGE
))
2735 dispatch_win_proc_params( ¶ms
, sizeof(params
) );
2736 else if (!is_window( msg
->hwnd
)) RtlSetLastWin32Error( ERROR_INVALID_WINDOW_HANDLE
);
2737 else RtlSetLastWin32Error( ERROR_MESSAGE_SYNC_ONLY
);
2739 spy_exit_message( SPY_RESULT_OK
, msg
->hwnd
, msg
->message
, retval
, msg
->wParam
, msg
->lParam
);
2741 if (msg
->message
== WM_PAINT
)
2743 /* send a WM_NCPAINT and WM_ERASEBKGND if the non-client area is still invalid */
2744 HRGN hrgn
= NtGdiCreateRectRgn( 0, 0, 0, 0 );
2745 NtUserGetUpdateRgn( msg
->hwnd
, hrgn
, TRUE
);
2746 NtGdiDeleteObjectApp( hrgn
);
2751 static BOOL
is_message_broadcastable( UINT msg
)
2753 return msg
< WM_USER
|| msg
>= 0xc000;
2756 /***********************************************************************
2759 static BOOL
broadcast_message( struct send_message_info
*info
, DWORD_PTR
*res_ptr
)
2763 if (is_message_broadcastable( info
->msg
) &&
2764 (list
= list_window_children( 0, get_desktop_window(), NULL
, 0 )))
2768 for (i
= 0; list
[i
]; i
++)
2770 if (!is_window(list
[i
])) continue;
2771 if ((get_window_long( list
[i
], GWL_STYLE
) & (WS_POPUP
|WS_CHILD
)) == WS_CHILD
)
2777 case MSG_OTHER_PROCESS
:
2778 send_message_timeout( list
[i
], info
->msg
, info
->wparam
, info
->lparam
,
2779 info
->flags
, info
->timeout
, FALSE
);
2782 send_message_timeout( list
[i
], info
->msg
, info
->wparam
, info
->lparam
,
2783 info
->flags
, info
->timeout
, TRUE
);
2786 NtUserMessageCall( list
[i
], info
->msg
, info
->wparam
, info
->lparam
,
2787 0, NtUserSendNotifyMessage
, FALSE
);
2791 struct send_message_callback_params params
=
2792 { .callback
= info
->callback
, .data
= info
->data
};
2793 NtUserMessageCall( list
[i
], info
->msg
, info
->wparam
, info
->lparam
,
2794 ¶ms
, NtUserSendMessageCallback
, FALSE
);
2798 NtUserPostMessage( list
[i
], info
->msg
, info
->wparam
, info
->lparam
);
2801 ERR( "bad type %d\n", info
->type
);
2809 if (res_ptr
) *res_ptr
= 1;
2813 static BOOL
process_packed_message( struct send_message_info
*info
, LRESULT
*res_ptr
, BOOL ansi
)
2815 struct user_thread_info
*thread_info
= get_user_thread_info();
2816 struct received_message_info receive_info
;
2817 struct packed_message data
;
2818 size_t buffer_size
= 0, i
;
2819 void *buffer
= NULL
;
2822 pack_message( info
->hwnd
, info
->msg
, info
->wparam
, info
->lparam
, &data
);
2823 if (data
.count
== -1) return FALSE
;
2825 for (i
= 0; i
< data
.count
; i
++) buffer_size
+= data
.size
[i
];
2826 if (!(buffer
= malloc( buffer_size
))) return FALSE
;
2827 for (ptr
= buffer
, i
= 0; i
< data
.count
; i
++)
2829 memcpy( ptr
, data
.data
[i
], data
.size
[i
] );
2830 ptr
+= data
.size
[i
];
2833 receive_info
.type
= MSG_CLIENT_MESSAGE
;
2834 receive_info
.msg
.hwnd
= info
->hwnd
;
2835 receive_info
.msg
.message
= info
->msg
;
2836 receive_info
.msg
.wParam
= info
->wparam
;
2837 receive_info
.msg
.lParam
= info
->lparam
;
2838 receive_info
.flags
= 0;
2839 receive_info
.prev
= thread_info
->receive_info
;
2840 receive_info
.result
= 0;
2841 thread_info
->receive_info
= &receive_info
;
2843 *res_ptr
= call_window_proc( info
->hwnd
, info
->msg
, info
->wparam
, info
->lparam
,
2844 !ansi
, TRUE
, info
->wm_char
, TRUE
, buffer
, buffer_size
);
2845 if (thread_info
->receive_info
== &receive_info
)
2847 thread_info
->receive_info
= receive_info
.prev
;
2848 *res_ptr
= receive_info
.result
;
2854 static inline void *get_buffer( void *static_buffer
, size_t size
, size_t need
)
2856 if (size
>= need
) return static_buffer
;
2857 return malloc( need
);
2860 static inline void free_buffer( void *static_buffer
, void *buffer
)
2862 if (buffer
!= static_buffer
) free( buffer
);
2865 typedef LRESULT (*winproc_callback_t
)( HWND hwnd
, UINT msg
, WPARAM wp
, LPARAM lp
,
2866 LRESULT
*result
, void *arg
);
2868 /**********************************************************************
2869 * test_lb_for_string
2871 * Return TRUE if the lparam is a string
2873 static inline BOOL
test_lb_for_string( HWND hwnd
, UINT msg
)
2875 DWORD style
= get_window_long( hwnd
, GWL_STYLE
);
2876 if (msg
<= CB_MSGMAX
)
2877 return (!(style
& (CBS_OWNERDRAWFIXED
| CBS_OWNERDRAWVARIABLE
)) || (style
& CBS_HASSTRINGS
));
2879 return (!(style
& (LBS_OWNERDRAWFIXED
| LBS_OWNERDRAWVARIABLE
)) || (style
& LBS_HASSTRINGS
));
2883 static CPTABLEINFO
*get_input_codepage( void )
2885 const NLS_LOCALE_DATA
*locale
;
2886 HKL hkl
= NtUserGetKeyboardLayout( 0 );
2887 CPTABLEINFO
*ret
= NULL
;
2889 locale
= get_locale_data( LOWORD(hkl
) );
2890 if (locale
&& locale
->idefaultansicodepage
!= CP_UTF8
)
2891 ret
= get_cptable( locale
->idefaultansicodepage
);
2892 return ret
? ret
: &ansi_cp
;
2895 /***********************************************************************
2898 * Convert the wparam of an ASCII message to Unicode.
2900 static BOOL
map_wparam_AtoW( UINT message
, WPARAM
*wparam
, enum wm_char_mapping mapping
)
2905 wch
[0] = wch
[1] = 0;
2909 case EM_SETPASSWORDCHAR
:
2912 case WM_SYSDEADCHAR
:
2914 ch
[0] = LOBYTE(*wparam
);
2915 ch
[1] = HIBYTE(*wparam
);
2916 win32u_mbtowc( get_input_codepage(), wch
, 2, ch
, 2 );
2917 *wparam
= MAKEWPARAM(wch
[0], wch
[1]);
2921 ch
[0] = HIBYTE(*wparam
);
2922 ch
[1] = LOBYTE(*wparam
);
2923 if (ch
[0]) win32u_mbtowc( get_input_codepage(), wch
, 2, ch
, 2 );
2924 else win32u_mbtowc( get_input_codepage(), wch
, 1, ch
+ 1, 1 );
2925 *wparam
= MAKEWPARAM(wch
[0], HIWORD(*wparam
));
2931 /**********************************************************************
2934 * Call a window procedure, translating args from Ansi to Unicode.
2936 static LRESULT
call_messageAtoW( winproc_callback_t callback
, HWND hwnd
, UINT msg
, WPARAM wparam
,
2937 LPARAM lparam
, LRESULT
*result
, void *arg
, enum wm_char_mapping mapping
)
2941 TRACE( "(hwnd=%p,msg=%s,wp=%#lx,lp=%#lx)\n", hwnd
, debugstr_msg_name( msg
, hwnd
),
2942 (long)wparam
, (long)lparam
);
2948 WCHAR
*ptr
, buffer
[512];
2949 DWORD title_lenA
= 0, title_lenW
= 0, class_lenA
= 0, class_lenW
= 0;
2950 MDICREATESTRUCTA
*csA
= (MDICREATESTRUCTA
*)lparam
;
2951 MDICREATESTRUCTW csW
;
2953 memcpy( &csW
, csA
, sizeof(csW
) );
2955 if (!IS_INTRESOURCE(csA
->szTitle
))
2957 title_lenA
= strlen(csA
->szTitle
) + 1;
2958 title_lenW
= win32u_mbtowc_size( &ansi_cp
, csA
->szTitle
, title_lenA
);
2960 if (!IS_INTRESOURCE(csA
->szClass
))
2962 class_lenA
= strlen(csA
->szClass
) + 1;
2963 class_lenW
= win32u_mbtowc_size( &ansi_cp
, csA
->szClass
, class_lenA
);
2966 if (!(ptr
= get_buffer( buffer
, sizeof(buffer
), (title_lenW
+ class_lenW
) * sizeof(WCHAR
) )))
2972 win32u_mbtowc( &ansi_cp
, ptr
, title_lenW
, csA
->szTitle
, title_lenA
);
2976 csW
.szClass
= ptr
+ title_lenW
;
2977 win32u_mbtowc( &ansi_cp
, ptr
+ title_lenW
, class_lenW
, csA
->szClass
, class_lenA
);
2979 ret
= callback( hwnd
, msg
, wparam
, (LPARAM
)&csW
, result
, arg
);
2980 free_buffer( buffer
, ptr
);
2985 case WM_ASKCBFORMATNAME
:
2987 WCHAR
*ptr
, buffer
[512];
2988 LPSTR str
= (LPSTR
)lparam
;
2989 DWORD len
= wparam
* sizeof(WCHAR
);
2991 if (!(ptr
= get_buffer( buffer
, sizeof(buffer
), len
))) break;
2992 ret
= callback( hwnd
, msg
, wparam
, (LPARAM
)ptr
, result
, arg
);
2996 len
= *result
? win32u_wctomb( &ansi_cp
, str
, wparam
- 1, ptr
, *result
) : 0;
3000 free_buffer( buffer
, ptr
);
3005 case LB_INSERTSTRING
:
3007 case LB_FINDSTRINGEXACT
:
3008 case LB_SELECTSTRING
:
3010 case CB_INSERTSTRING
:
3012 case CB_FINDSTRINGEXACT
:
3013 case CB_SELECTSTRING
:
3014 if (!lparam
|| !test_lb_for_string( hwnd
, msg
))
3016 ret
= callback( hwnd
, msg
, wparam
, lparam
, result
, arg
);
3021 case WM_WININICHANGE
:
3022 case WM_DEVMODECHANGE
:
3029 ret
= callback( hwnd
, msg
, wparam
, lparam
, result
, arg
);
3033 WCHAR
*ptr
, buffer
[512];
3034 LPCSTR strA
= (LPCSTR
)lparam
;
3035 DWORD lenW
, lenA
= strlen(strA
) + 1;
3037 lenW
= win32u_mbtowc_size( &ansi_cp
, strA
, lenA
);
3038 if ((ptr
= get_buffer( buffer
, sizeof(buffer
), lenW
* sizeof(WCHAR
) )))
3040 win32u_mbtowc( &ansi_cp
, ptr
, lenW
, strA
, lenA
);
3041 ret
= callback( hwnd
, msg
, wparam
, (LPARAM
)ptr
, result
, arg
);
3042 free_buffer( buffer
, ptr
);
3049 WCHAR
*ptr
, buffer
[512];
3050 WORD len
= *(WORD
*)lparam
;
3052 if (!(ptr
= get_buffer( buffer
, sizeof(buffer
), len
* sizeof(WCHAR
) ))) break;
3053 *((WORD
*)ptr
) = len
; /* store the length */
3054 ret
= callback( hwnd
, msg
, wparam
, (LPARAM
)ptr
, result
, arg
);
3058 reslen
= win32u_wctomb( &ansi_cp
, (char *)lparam
, len
, ptr
, *result
);
3059 if (reslen
< len
) ((LPSTR
)lparam
)[reslen
] = 0;
3062 free_buffer( buffer
, ptr
);
3069 MSG newmsg
= *(MSG
*)lparam
;
3070 if (map_wparam_AtoW( newmsg
.message
, &newmsg
.wParam
, WMCHAR_MAP_NOMAPPING
))
3071 ret
= callback( hwnd
, msg
, wparam
, (LPARAM
)&newmsg
, result
, arg
);
3073 else ret
= callback( hwnd
, msg
, wparam
, lparam
, result
, arg
);
3080 case WM_SYSDEADCHAR
:
3081 case EM_SETPASSWORDCHAR
:
3083 if (map_wparam_AtoW( msg
, &wparam
, mapping
))
3084 ret
= callback( hwnd
, msg
, wparam
, lparam
, result
, arg
);
3087 case WM_GETTEXTLENGTH
:
3088 case CB_GETLBTEXTLEN
:
3090 ret
= callback( hwnd
, msg
, wparam
, lparam
, result
, arg
);
3093 WCHAR
*ptr
, buffer
[512];
3095 DWORD len
= *result
+ 1;
3096 /* Determine respective GETTEXT message */
3097 UINT msg_get_text
= msg
== WM_GETTEXTLENGTH
? WM_GETTEXT
:
3098 (msg
== CB_GETLBTEXTLEN
? CB_GETLBTEXT
: LB_GETTEXT
);
3099 /* wparam differs between the messages */
3100 WPARAM wp
= msg
== WM_GETTEXTLENGTH
? len
: wparam
;
3102 if (!(ptr
= get_buffer( buffer
, sizeof(buffer
), len
* sizeof(WCHAR
) ))) break;
3104 res
= send_message( hwnd
, msg_get_text
, wp
, (LPARAM
)ptr
);
3105 *result
= win32u_wctomb_size( &ansi_cp
, ptr
, res
);
3106 free_buffer( buffer
, ptr
);
3111 ret
= callback( hwnd
, msg
, wparam
, lparam
, result
, arg
);
3117 /***********************************************************************
3120 * Backend implementation of the various SendMessage functions.
3122 static BOOL
process_message( struct send_message_info
*info
, DWORD_PTR
*res_ptr
, BOOL ansi
)
3124 struct ntuser_thread_info
*thread_info
= NtUserGetThreadInfo();
3125 INPUT_MESSAGE_SOURCE prev_source
= thread_info
->msg_source
;
3130 if (is_broadcast( info
->hwnd
)) return broadcast_message( info
, res_ptr
);
3132 if (!(info
->dest_tid
= get_window_thread( info
->hwnd
, &dest_pid
))) return FALSE
;
3133 if (is_exiting_thread( info
->dest_tid
)) return FALSE
;
3135 if (info
->params
&& info
->dest_tid
== GetCurrentThreadId() &&
3136 !is_hooked( WH_CALLWNDPROC
) && !is_hooked( WH_CALLWNDPROCRET
) &&
3137 thread_info
->recursion_count
<= MAX_WINPROC_RECURSION
)
3139 /* if we're called from client side and need just a simple winproc call,
3140 * just fill dispatch params and let user32 do the rest */
3141 return init_window_call_params( info
->params
, info
->hwnd
, info
->msg
, info
->wparam
, info
->lparam
,
3142 NULL
, ansi
, info
->wm_char
);
3145 thread_info
->msg_source
= msg_source_unavailable
;
3146 spy_enter_message( SPY_SENDMESSAGE
, info
->hwnd
, info
->msg
, info
->wparam
, info
->lparam
);
3148 if (info
->dest_tid
!= GetCurrentThreadId())
3150 if (dest_pid
!= GetCurrentProcessId() && (info
->type
== MSG_ASCII
|| info
->type
== MSG_UNICODE
))
3151 info
->type
= MSG_OTHER_PROCESS
;
3153 /* MSG_ASCII can be sent unconverted except for WM_CHAR; everything else needs to be Unicode */
3154 if (ansi
&& (info
->type
!= MSG_ASCII
|| info
->msg
== WM_CHAR
))
3155 ret
= call_messageAtoW( send_inter_thread_callback
, info
->hwnd
, info
->msg
,
3156 info
->wparam
, info
->lparam
, &result
, info
, info
->wm_char
);
3158 ret
= send_inter_thread_message( info
, &result
);
3160 else if (info
->type
!= MSG_OTHER_PROCESS
)
3162 result
= call_window_proc( info
->hwnd
, info
->msg
, info
->wparam
, info
->lparam
,
3163 !ansi
, TRUE
, info
->wm_char
, FALSE
, NULL
, 0 );
3164 if (info
->type
== MSG_CALLBACK
)
3165 call_sendmsg_callback( info
->callback
, info
->hwnd
, info
->msg
, info
->data
, result
);
3170 ret
= process_packed_message( info
, &result
, ansi
);
3173 spy_exit_message( SPY_RESULT_OK
, info
->hwnd
, info
->msg
, result
, info
->wparam
, info
->lparam
);
3174 thread_info
->msg_source
= prev_source
;
3175 if (ret
&& res_ptr
) *res_ptr
= result
;
3179 /***********************************************************************
3180 * NtUserSetTimer (win32u.@)
3182 UINT_PTR WINAPI
NtUserSetTimer( HWND hwnd
, UINT_PTR id
, UINT timeout
, TIMERPROC proc
, ULONG tolerance
)
3185 WNDPROC winproc
= 0;
3187 if (proc
) winproc
= alloc_winproc( (WNDPROC
)proc
, TRUE
);
3189 timeout
= min( max( USER_TIMER_MINIMUM
, timeout
), USER_TIMER_MAXIMUM
);
3191 SERVER_START_REQ( set_win_timer
)
3193 req
->win
= wine_server_user_handle( hwnd
);
3194 req
->msg
= WM_TIMER
;
3196 req
->rate
= timeout
;
3197 req
->lparam
= (ULONG_PTR
)winproc
;
3198 if (!wine_server_call_err( req
))
3201 if (!ret
) ret
= TRUE
;
3207 TRACE( "Added %p %lx %p timeout %d\n", hwnd
, (long)id
, winproc
, timeout
);
3211 /***********************************************************************
3212 * NtUserSetSystemTimer (win32u.@)
3214 UINT_PTR WINAPI
NtUserSetSystemTimer( HWND hwnd
, UINT_PTR id
, UINT timeout
)
3218 TRACE( "window %p, id %#lx, timeout %u\n", hwnd
, (long)id
, timeout
);
3220 timeout
= min( max( USER_TIMER_MINIMUM
, timeout
), USER_TIMER_MAXIMUM
);
3222 SERVER_START_REQ( set_win_timer
)
3224 req
->win
= wine_server_user_handle( hwnd
);
3225 req
->msg
= WM_SYSTIMER
;
3227 req
->rate
= timeout
;
3229 if (!wine_server_call_err( req
))
3232 if (!ret
) ret
= TRUE
;
3241 /***********************************************************************
3242 * NtUserKillTimer (win32u.@)
3244 BOOL WINAPI
NtUserKillTimer( HWND hwnd
, UINT_PTR id
)
3248 SERVER_START_REQ( kill_win_timer
)
3250 req
->win
= wine_server_user_handle( hwnd
);
3251 req
->msg
= WM_TIMER
;
3253 ret
= !wine_server_call_err( req
);
3259 /* see KillSystemTimer */
3260 BOOL
kill_system_timer( HWND hwnd
, UINT_PTR id
)
3264 SERVER_START_REQ( kill_win_timer
)
3266 req
->win
= wine_server_user_handle( hwnd
);
3267 req
->msg
= WM_SYSTIMER
;
3269 ret
= !wine_server_call_err( req
);
3275 static LRESULT
send_window_message( HWND hwnd
, UINT msg
, WPARAM wparam
, LPARAM lparam
,
3276 struct win_proc_params
*client_params
, BOOL ansi
)
3278 struct send_message_info info
;
3281 info
.type
= ansi
? MSG_ASCII
: MSG_UNICODE
;
3284 info
.wparam
= wparam
;
3285 info
.lparam
= lparam
;
3286 info
.flags
= SMTO_NORMAL
;
3288 info
.wm_char
= WMCHAR_MAP_SENDMESSAGE
;
3289 info
.params
= client_params
;
3291 process_message( &info
, &res
, ansi
);
3295 /* see SendMessageTimeoutW */
3296 static LRESULT
send_client_message( HWND hwnd
, UINT msg
, WPARAM wparam
, LPARAM lparam
,
3297 UINT flags
, UINT timeout
, DWORD_PTR
*res_ptr
, BOOL ansi
)
3299 struct send_message_info info
;
3301 info
.type
= ansi
? MSG_ASCII
: MSG_UNICODE
;
3304 info
.wparam
= wparam
;
3305 info
.lparam
= lparam
;
3307 info
.timeout
= timeout
;
3308 info
.wm_char
= WMCHAR_MAP_SENDMESSAGETIMEOUT
;
3311 return process_message( &info
, res_ptr
, ansi
);
3314 LRESULT
send_message_timeout( HWND hwnd
, UINT msg
, WPARAM wparam
, LPARAM lparam
,
3315 UINT flags
, UINT timeout
, BOOL ansi
)
3317 struct send_message_info info
;
3320 if (!is_pointer_message( msg
, wparam
))
3322 send_client_message( hwnd
, msg
, wparam
, lparam
, flags
, timeout
, &res
, ansi
);
3326 info
.type
= MSG_OTHER_PROCESS
;
3329 info
.wparam
= wparam
;
3330 info
.lparam
= lparam
;
3332 info
.timeout
= timeout
;
3333 info
.wm_char
= WMCHAR_MAP_SENDMESSAGETIMEOUT
;
3336 process_message( &info
, &res
, ansi
);
3340 /* see SendMessageW */
3341 LRESULT
send_message( HWND hwnd
, UINT msg
, WPARAM wparam
, LPARAM lparam
)
3343 return send_message_timeout( hwnd
, msg
, wparam
, lparam
, SMTO_NORMAL
, 0, FALSE
);
3346 /* see SendNotifyMessageW */
3347 BOOL
send_notify_message( HWND hwnd
, UINT msg
, WPARAM wparam
, LPARAM lparam
, BOOL ansi
)
3349 struct send_message_info info
;
3351 if (is_pointer_message( msg
, wparam
))
3353 RtlSetLastWin32Error( ERROR_MESSAGE_SYNC_ONLY
);
3357 info
.type
= MSG_NOTIFY
;
3360 info
.wparam
= wparam
;
3361 info
.lparam
= lparam
;
3363 info
.wm_char
= WMCHAR_MAP_SENDMESSAGETIMEOUT
;
3366 return process_message( &info
, NULL
, ansi
);
3369 /* see SendMessageCallbackW */
3370 static BOOL
send_message_callback( HWND hwnd
, UINT msg
, WPARAM wparam
, LPARAM lparam
,
3371 const struct send_message_callback_params
*params
, BOOL ansi
)
3373 struct send_message_info info
;
3375 if (is_pointer_message( msg
, wparam
))
3377 RtlSetLastWin32Error( ERROR_MESSAGE_SYNC_ONLY
);
3381 info
.type
= MSG_CALLBACK
;
3384 info
.wparam
= wparam
;
3385 info
.lparam
= lparam
;
3386 info
.callback
= params
->callback
;
3387 info
.data
= params
->data
;
3389 info
.wm_char
= WMCHAR_MAP_SENDMESSAGETIMEOUT
;
3392 return process_message( &info
, NULL
, ansi
);
3395 /***********************************************************************
3396 * NtUserPostMessage (win32u.@)
3398 BOOL WINAPI
NtUserPostMessage( HWND hwnd
, UINT msg
, WPARAM wparam
, LPARAM lparam
)
3400 struct send_message_info info
;
3402 if (is_pointer_message( msg
, wparam
))
3404 RtlSetLastWin32Error( ERROR_MESSAGE_SYNC_ONLY
);
3408 TRACE( "hwnd %p msg %x (%s) wp %lx lp %lx\n",
3409 hwnd
, msg
, debugstr_msg_name(msg
, hwnd
), (long)wparam
, lparam
);
3411 info
.type
= MSG_POSTED
;
3414 info
.wparam
= wparam
;
3415 info
.lparam
= lparam
;
3419 if (is_broadcast(hwnd
)) return broadcast_message( &info
, NULL
);
3421 if (!hwnd
) return NtUserPostThreadMessage( GetCurrentThreadId(), msg
, wparam
, lparam
);
3423 if (!(info
.dest_tid
= get_window_thread( hwnd
, NULL
))) return FALSE
;
3425 if (is_exiting_thread( info
.dest_tid
)) return TRUE
;
3427 return put_message_in_queue( &info
, NULL
);
3430 /**********************************************************************
3431 * NtUserPostThreadMessage (win32u.@)
3433 BOOL WINAPI
NtUserPostThreadMessage( DWORD thread
, UINT msg
, WPARAM wparam
, LPARAM lparam
)
3435 struct send_message_info info
;
3437 if (is_pointer_message( msg
, wparam
))
3439 RtlSetLastWin32Error( ERROR_MESSAGE_SYNC_ONLY
);
3442 if (is_exiting_thread( thread
)) return TRUE
;
3444 info
.type
= MSG_POSTED
;
3445 info
.dest_tid
= thread
;
3448 info
.wparam
= wparam
;
3449 info
.lparam
= lparam
;
3452 return put_message_in_queue( &info
, NULL
);
3455 LRESULT WINAPI
NtUserMessageCall( HWND hwnd
, UINT msg
, WPARAM wparam
, LPARAM lparam
,
3456 void *result_info
, DWORD type
, BOOL ansi
)
3460 case NtUserScrollBarWndProc
:
3461 return scroll_bar_window_proc( hwnd
, msg
, wparam
, lparam
, ansi
);
3463 case NtUserPopupMenuWndProc
:
3464 return popup_menu_window_proc( hwnd
, msg
, wparam
, lparam
);
3466 case NtUserDesktopWindowProc
:
3467 return desktop_window_proc( hwnd
, msg
, wparam
, lparam
);
3469 case NtUserDefWindowProc
:
3470 return default_window_proc( hwnd
, msg
, wparam
, lparam
, ansi
);
3472 case NtUserCallWindowProc
:
3473 return init_win_proc_params( (struct win_proc_params
*)result_info
, hwnd
, msg
,
3474 wparam
, lparam
, ansi
);
3476 case NtUserSendMessage
:
3477 return send_window_message( hwnd
, msg
, wparam
, lparam
, result_info
, ansi
);
3479 case NtUserSendMessageTimeout
:
3481 struct send_message_timeout_params
*params
= (void *)result_info
;
3483 params
->result
= send_client_message( hwnd
, msg
, wparam
, lparam
, params
->flags
,
3484 params
->timeout
, &res
, ansi
);
3488 case NtUserSendNotifyMessage
:
3489 return send_notify_message( hwnd
, msg
, wparam
, lparam
, ansi
);
3491 case NtUserSendMessageCallback
:
3492 return send_message_callback( hwnd
, msg
, wparam
, lparam
, result_info
, ansi
);
3494 case NtUserClipboardWindowProc
:
3495 return user_driver
->pClipboardWindowProc( hwnd
, msg
, wparam
, lparam
);
3497 case NtUserWinProcResult
:
3498 return reply_winproc_result( (LRESULT
)result_info
, hwnd
, msg
, wparam
, lparam
);
3500 case NtUserGetDispatchParams
:
3501 if (!hwnd
) return FALSE
;
3502 if (init_window_call_params( result_info
, hwnd
, msg
, wparam
, lparam
,
3503 NULL
, ansi
, WMCHAR_MAP_DISPATCHMESSAGE
))
3505 if (!is_window( hwnd
)) RtlSetLastWin32Error( ERROR_INVALID_WINDOW_HANDLE
);
3506 else RtlSetLastWin32Error( ERROR_MESSAGE_SYNC_ONLY
);
3509 case NtUserSendDriverMessage
:
3510 /* used by driver to send packed messages */
3511 return send_message( hwnd
, msg
, wparam
, lparam
);
3513 case NtUserSpyEnter
:
3514 spy_enter_message( ansi
, hwnd
, msg
, wparam
, lparam
);
3517 case NtUserSpyGetMsgName
:
3518 lstrcpynA( result_info
, debugstr_msg_name( msg
, hwnd
), wparam
);
3522 spy_exit_message( ansi
, hwnd
, msg
, (LPARAM
)result_info
, wparam
, lparam
);
3525 case NtUserImeDriverCall
:
3526 return ime_driver_call( hwnd
, msg
, wparam
, lparam
, result_info
);
3529 FIXME( "%p %x %lx %lx %p %x %x\n", hwnd
, msg
, (long)wparam
, lparam
, result_info
, (int)type
, ansi
);
3534 /***********************************************************************
3535 * NtUserTranslateMessage (win32u.@)
3537 BOOL WINAPI
NtUserTranslateMessage( const MSG
*msg
, UINT flags
)
3544 if (flags
) FIXME( "unsupported flags %x\n", flags
);
3546 if (msg
->message
< WM_KEYFIRST
|| msg
->message
> WM_KEYLAST
) return FALSE
;
3547 if (msg
->message
!= WM_KEYDOWN
&& msg
->message
!= WM_SYSKEYDOWN
) return TRUE
;
3549 TRACE_(key
)( "Translating key %s (%04x), scancode %04x\n",
3550 debugstr_vkey_name( msg
->wParam
), LOWORD(msg
->wParam
), HIWORD(msg
->lParam
) );
3552 switch (msg
->wParam
)
3555 message
= (msg
->message
== WM_KEYDOWN
) ? WM_CHAR
: WM_SYSCHAR
;
3556 TRACE_(key
)( "PostMessageW(%p,%s,%04x,%08x)\n", msg
->hwnd
,
3557 debugstr_msg_name( message
, msg
->hwnd
),
3558 HIWORD(msg
->lParam
), LOWORD(msg
->lParam
) );
3559 NtUserPostMessage( msg
->hwnd
, message
, HIWORD(msg
->lParam
), LOWORD(msg
->lParam
) );
3563 return ImmTranslateMessage( msg
->hwnd
, msg
->message
, msg
->wParam
, msg
->lParam
);
3566 NtUserGetKeyboardState( state
);
3567 len
= NtUserToUnicodeEx( msg
->wParam
, HIWORD(msg
->lParam
), state
, wp
, ARRAY_SIZE(wp
), 0,
3568 NtUserGetKeyboardLayout(0) );
3571 message
= msg
->message
== WM_KEYDOWN
? WM_DEADCHAR
: WM_SYSDEADCHAR
;
3572 TRACE_(key
)( "-1 -> PostMessageW(%p,%s,%04x,%08lx)\n",
3573 msg
->hwnd
, debugstr_msg_name( message
, msg
->hwnd
), wp
[0], msg
->lParam
);
3574 NtUserPostMessage( msg
->hwnd
, message
, wp
[0], msg
->lParam
);
3580 message
= msg
->message
== WM_KEYDOWN
? WM_CHAR
: WM_SYSCHAR
;
3581 TRACE_(key
)( "%d -> PostMessageW(%p,%s,<x>,%08lx) for <x> in %s\n", len
, msg
->hwnd
,
3582 debugstr_msg_name(message
, msg
->hwnd
), msg
->lParam
, debugstr_wn(wp
, len
) );
3583 for (i
= 0; i
< len
; i
++)
3584 NtUserPostMessage( msg
->hwnd
, message
, wp
[i
], msg
->lParam
);