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
25 #define NONAMELESSUNION
26 #define NONAMELESSSTRUCT
28 #define WIN32_NO_STATUS
40 #include "wine/server.h"
41 #include "user_private.h"
44 #include "wine/debug.h"
45 #include "wine/exception.h"
47 WINE_DEFAULT_DEBUG_CHANNEL(msg
);
48 WINE_DECLARE_DEBUG_CHANNEL(relay
);
49 WINE_DECLARE_DEBUG_CHANNEL(key
);
51 #define WM_NCMOUSEFIRST WM_NCMOUSEMOVE
52 #define WM_NCMOUSELAST (WM_NCMOUSEFIRST+(WM_MOUSELAST-WM_MOUSEFIRST))
54 #define MAX_PACK_COUNT 4
56 /* the various structures that can be sent in messages, in platform-independent layout */
57 struct packed_CREATESTRUCTW
59 ULONGLONG lpCreateParams
;
63 user_handle_t hwndParent
;
76 struct packed_DRAWITEMSTRUCT
83 user_handle_t hwndItem
;
91 struct packed_MEASUREITEMSTRUCT
101 struct packed_DELETEITEMSTRUCT
106 user_handle_t hwndItem
;
111 struct packed_COMPAREITEMSTRUCT
115 user_handle_t hwndItem
;
125 struct packed_WINDOWPOS
129 user_handle_t hwndInsertAfter
;
139 struct packed_COPYDATASTRUCT
146 struct packed_HELPINFO
151 user_handle_t hItemHandle
;
153 ULONGLONG dwContextId
;
157 struct packed_NCCALCSIZE_PARAMS
163 user_handle_t hwndInsertAfter
;
185 struct packed_MDINEXTMENU
187 user_handle_t hmenuIn
;
189 user_handle_t hmenuNext
;
191 user_handle_t hwndNext
;
195 struct packed_MDICREATESTRUCTW
208 struct packed_hook_extra_info
210 user_handle_t handle
;
215 /* the structures are unpacked on top of the packed ones, so make sure they fit */
216 C_ASSERT( sizeof(struct packed_CREATESTRUCTW
) >= sizeof(CREATESTRUCTW
) );
217 C_ASSERT( sizeof(struct packed_DRAWITEMSTRUCT
) >= sizeof(DRAWITEMSTRUCT
) );
218 C_ASSERT( sizeof(struct packed_MEASUREITEMSTRUCT
) >= sizeof(MEASUREITEMSTRUCT
) );
219 C_ASSERT( sizeof(struct packed_DELETEITEMSTRUCT
) >= sizeof(DELETEITEMSTRUCT
) );
220 C_ASSERT( sizeof(struct packed_COMPAREITEMSTRUCT
) >= sizeof(COMPAREITEMSTRUCT
) );
221 C_ASSERT( sizeof(struct packed_WINDOWPOS
) >= sizeof(WINDOWPOS
) );
222 C_ASSERT( sizeof(struct packed_COPYDATASTRUCT
) >= sizeof(COPYDATASTRUCT
) );
223 C_ASSERT( sizeof(struct packed_HELPINFO
) >= sizeof(HELPINFO
) );
224 C_ASSERT( sizeof(struct packed_NCCALCSIZE_PARAMS
) >= sizeof(NCCALCSIZE_PARAMS
) + sizeof(WINDOWPOS
) );
225 C_ASSERT( sizeof(struct packed_MSG
) >= sizeof(MSG
) );
226 C_ASSERT( sizeof(struct packed_MDINEXTMENU
) >= sizeof(MDINEXTMENU
) );
227 C_ASSERT( sizeof(struct packed_MDICREATESTRUCTW
) >= sizeof(MDICREATESTRUCTW
) );
228 C_ASSERT( sizeof(struct packed_hook_extra_info
) >= sizeof(struct hook_extra_info
) );
232 struct packed_CREATESTRUCTW cs
;
233 struct packed_DRAWITEMSTRUCT dis
;
234 struct packed_MEASUREITEMSTRUCT mis
;
235 struct packed_DELETEITEMSTRUCT dls
;
236 struct packed_COMPAREITEMSTRUCT cis
;
237 struct packed_WINDOWPOS wp
;
238 struct packed_COPYDATASTRUCT cds
;
239 struct packed_HELPINFO hi
;
240 struct packed_NCCALCSIZE_PARAMS ncp
;
241 struct packed_MSG msg
;
242 struct packed_MDINEXTMENU mnm
;
243 struct packed_MDICREATESTRUCTW mcs
;
244 struct packed_hook_extra_info hook
;
247 /* description of the data fields that need to be packed along with a sent message */
248 struct packed_message
250 union packed_structs ps
;
252 const void *data
[MAX_PACK_COUNT
];
253 size_t size
[MAX_PACK_COUNT
];
256 /* info about the message currently being received by the current thread */
257 struct received_message_info
259 enum message_type type
;
261 UINT flags
; /* InSendMessageEx return flags */
264 /* structure to group all parameters for sent messages of the various kinds */
265 struct send_message_info
267 enum message_type type
;
273 UINT flags
; /* flags for SendMessageTimeout */
274 UINT timeout
; /* timeout for SendMessageTimeout */
275 SENDASYNCPROC callback
; /* callback function for SendMessageCallback */
276 ULONG_PTR data
; /* callback data */
277 enum wm_char_mapping wm_char
;
280 static const INPUT_MESSAGE_SOURCE msg_source_unavailable
= { IMDT_UNAVAILABLE
, IMO_UNAVAILABLE
};
283 /* Message class descriptor */
284 const struct builtin_class_descr MESSAGE_builtin_class
=
286 L
"Message", /* name */
288 WINPROC_MESSAGE
, /* proc */
296 /* flag for messages that contain pointers */
297 /* 32 messages per entry, messages 0..31 map to bits 0..31 */
299 #define SET(msg) (1 << ((msg) & 31))
301 static const unsigned int message_pointer_flags
[] =
304 SET(WM_CREATE
) | SET(WM_SETTEXT
) | SET(WM_GETTEXT
) |
305 SET(WM_WININICHANGE
) | SET(WM_DEVMODECHANGE
),
307 SET(WM_GETMINMAXINFO
) | SET(WM_DRAWITEM
) | SET(WM_MEASUREITEM
) | SET(WM_DELETEITEM
) |
310 SET(WM_WINDOWPOSCHANGING
) | SET(WM_WINDOWPOSCHANGED
) | SET(WM_COPYDATA
) | SET(WM_HELP
),
312 SET(WM_STYLECHANGING
) | SET(WM_STYLECHANGED
),
314 SET(WM_NCCREATE
) | SET(WM_NCCALCSIZE
) | SET(WM_GETDLGCODE
),
316 SET(EM_GETSEL
) | SET(EM_GETRECT
) | SET(EM_SETRECT
) | SET(EM_SETRECTNP
),
318 SET(EM_REPLACESEL
) | SET(EM_GETLINE
) | SET(EM_SETTABSTOPS
),
320 SET(SBM_GETRANGE
) | SET(SBM_SETSCROLLINFO
) | SET(SBM_GETSCROLLINFO
) | SET(SBM_GETSCROLLBARINFO
),
326 SET(CB_GETEDITSEL
) | SET(CB_ADDSTRING
) | SET(CB_DIR
) | SET(CB_GETLBTEXT
) |
327 SET(CB_INSERTSTRING
) | SET(CB_FINDSTRING
) | SET(CB_SELECTSTRING
) |
328 SET(CB_GETDROPPEDCONTROLRECT
) | SET(CB_FINDSTRINGEXACT
),
332 SET(LB_ADDSTRING
) | SET(LB_INSERTSTRING
) | SET(LB_GETTEXT
) | SET(LB_SELECTSTRING
) |
333 SET(LB_DIR
) | SET(LB_FINDSTRING
) |
334 SET(LB_GETSELITEMS
) | SET(LB_SETTABSTOPS
) | SET(LB_ADDFILE
) | SET(LB_GETITEMRECT
),
336 SET(LB_FINDSTRINGEXACT
),
342 SET(WM_NEXTMENU
) | SET(WM_SIZING
) | SET(WM_MOVING
) | SET(WM_DEVICECHANGE
),
344 SET(WM_MDICREATE
) | SET(WM_MDIGETACTIVE
) | SET(WM_DROPOBJECT
) |
345 SET(WM_QUERYDROPOBJECT
) | SET(WM_DRAGLOOP
) | SET(WM_DRAGSELECT
) | SET(WM_DRAGMOVE
),
359 SET(WM_ASKCBFORMATNAME
)
362 /* flags for messages that contain Unicode strings */
363 static const unsigned int message_unicode_flags
[] =
366 SET(WM_CREATE
) | SET(WM_SETTEXT
) | SET(WM_GETTEXT
) | SET(WM_GETTEXTLENGTH
) |
367 SET(WM_WININICHANGE
) | SET(WM_DEVMODECHANGE
),
379 SET(EM_REPLACESEL
) | SET(EM_GETLINE
) | SET(EM_SETPASSWORDCHAR
),
383 SET(WM_CHAR
) | SET(WM_DEADCHAR
) | SET(WM_SYSCHAR
) | SET(WM_SYSDEADCHAR
),
387 SET(CB_ADDSTRING
) | SET(CB_DIR
) | SET(CB_GETLBTEXT
) | SET(CB_GETLBTEXTLEN
) |
388 SET(CB_INSERTSTRING
) | SET(CB_FINDSTRING
) | SET(CB_SELECTSTRING
) | SET(CB_FINDSTRINGEXACT
),
392 SET(LB_ADDSTRING
) | SET(LB_INSERTSTRING
) | SET(LB_GETTEXT
) | SET(LB_GETTEXTLEN
) |
393 SET(LB_SELECTSTRING
) | SET(LB_DIR
) | SET(LB_FINDSTRING
) | SET(LB_ADDFILE
),
395 SET(LB_FINDSTRINGEXACT
),
417 SET(WM_PAINTCLIPBOARD
) | SET(WM_SIZECLIPBOARD
) | SET(WM_ASKCBFORMATNAME
)
420 /* check whether a given message type includes pointers */
421 static inline BOOL
is_pointer_message( UINT message
, WPARAM wparam
)
423 if (message
>= 8*sizeof(message_pointer_flags
)) return FALSE
;
424 if (message
== WM_DEVICECHANGE
&& !(wparam
& 0x8000)) return FALSE
;
425 return (message_pointer_flags
[message
/ 32] & SET(message
)) != 0;
428 /* check whether a given message type contains Unicode (or ASCII) chars */
429 static inline BOOL
is_unicode_message( UINT message
)
431 if (message
>= 8*sizeof(message_unicode_flags
)) return FALSE
;
432 return (message_unicode_flags
[message
/ 32] & SET(message
)) != 0;
437 /* add a data field to a packed message */
438 static inline void push_data( struct packed_message
*data
, const void *ptr
, size_t size
)
440 data
->data
[data
->count
] = ptr
;
441 data
->size
[data
->count
] = size
;
445 /* add a string to a packed message */
446 static inline void push_string( struct packed_message
*data
, LPCWSTR str
)
448 push_data( data
, str
, (lstrlenW(str
) + 1) * sizeof(WCHAR
) );
451 /* make sure that the buffer contains a valid null-terminated Unicode string */
452 static inline BOOL
check_string( LPCWSTR str
, size_t size
)
454 for (size
/= sizeof(WCHAR
); size
; size
--, str
++)
455 if (!*str
) return TRUE
;
459 /* pack a pointer into a 32/64 portable format */
460 static inline ULONGLONG
pack_ptr( const void *ptr
)
462 return (ULONG_PTR
)ptr
;
465 /* unpack a potentially 64-bit pointer, returning 0 when truncated */
466 static inline void *unpack_ptr( ULONGLONG ptr64
)
468 if ((ULONG_PTR
)ptr64
!= ptr64
) return 0;
469 return (void *)(ULONG_PTR
)ptr64
;
472 /* make sure that there is space for 'size' bytes in buffer, growing it if needed */
473 static inline void *get_buffer_space( void **buffer
, size_t size
)
479 if (!(ret
= HeapReAlloc( GetProcessHeap(), 0, *buffer
, size
)))
480 HeapFree( GetProcessHeap(), 0, *buffer
);
482 else ret
= HeapAlloc( GetProcessHeap(), 0, size
);
488 /* check whether a combobox expects strings or ids in CB_ADDSTRING/CB_INSERTSTRING */
489 static inline BOOL
combobox_has_strings( HWND hwnd
)
491 DWORD style
= GetWindowLongA( hwnd
, GWL_STYLE
);
492 return (!(style
& (CBS_OWNERDRAWFIXED
| CBS_OWNERDRAWVARIABLE
)) || (style
& CBS_HASSTRINGS
));
495 /* check whether a listbox expects strings or ids in LB_ADDSTRING/LB_INSERTSTRING */
496 static inline BOOL
listbox_has_strings( HWND hwnd
)
498 DWORD style
= GetWindowLongA( hwnd
, GWL_STYLE
);
499 return (!(style
& (LBS_OWNERDRAWFIXED
| LBS_OWNERDRAWVARIABLE
)) || (style
& LBS_HASSTRINGS
));
502 /* check whether message is in the range of keyboard messages */
503 static inline BOOL
is_keyboard_message( UINT message
)
505 return (message
>= WM_KEYFIRST
&& message
<= WM_KEYLAST
);
508 /* check whether message is in the range of mouse messages */
509 static inline BOOL
is_mouse_message( UINT message
)
511 return ((message
>= WM_NCMOUSEFIRST
&& message
<= WM_NCMOUSELAST
) ||
512 (message
>= WM_MOUSEFIRST
&& message
<= WM_MOUSELAST
));
515 /* check whether message matches the specified hwnd filter */
516 static inline BOOL
check_hwnd_filter( const MSG
*msg
, HWND hwnd_filter
)
518 if (!hwnd_filter
|| hwnd_filter
== GetDesktopWindow()) return TRUE
;
519 return (msg
->hwnd
== hwnd_filter
|| IsChild( hwnd_filter
, msg
->hwnd
));
522 /* check for pending WM_CHAR message with DBCS trailing byte */
523 static inline BOOL
get_pending_wmchar( MSG
*msg
, UINT first
, UINT last
, BOOL remove
)
525 struct wm_char_mapping_data
*data
= get_user_thread_info()->wmchar_data
;
527 if (!data
|| !data
->get_msg
.message
) return FALSE
;
528 if ((first
|| last
) && (first
> WM_CHAR
|| last
< WM_CHAR
)) return FALSE
;
529 if (!msg
) return FALSE
;
530 *msg
= data
->get_msg
;
531 if (remove
) data
->get_msg
.message
= 0;
536 /***********************************************************************
539 * Window procedure for "Message" windows (HWND_MESSAGE parent).
541 LRESULT WINAPI
MessageWndProc( HWND hwnd
, UINT message
, WPARAM wParam
, LPARAM lParam
)
543 if (message
== WM_NCCREATE
) return TRUE
;
544 return 0; /* all other messages are ignored */
548 /***********************************************************************
549 * broadcast_message_callback
551 * Helper callback for broadcasting messages.
553 static BOOL CALLBACK
broadcast_message_callback( HWND hwnd
, LPARAM lparam
)
555 struct send_message_info
*info
= (struct send_message_info
*)lparam
;
556 if ((GetWindowLongW( hwnd
, GWL_STYLE
) & (WS_POPUP
|WS_CHILD
)) == WS_CHILD
)
561 SendMessageTimeoutW( hwnd
, info
->msg
, info
->wparam
, info
->lparam
,
562 info
->flags
, info
->timeout
, NULL
);
565 SendMessageTimeoutA( hwnd
, info
->msg
, info
->wparam
, info
->lparam
,
566 info
->flags
, info
->timeout
, NULL
);
569 SendNotifyMessageW( hwnd
, info
->msg
, info
->wparam
, info
->lparam
);
572 SendMessageCallbackW( hwnd
, info
->msg
, info
->wparam
, info
->lparam
,
573 info
->callback
, info
->data
);
576 PostMessageW( hwnd
, info
->msg
, info
->wparam
, info
->lparam
);
579 ERR( "bad type %d\n", info
->type
);
585 DWORD
get_input_codepage( void )
589 HKL hkl
= NtUserGetKeyboardLayout( 0 );
591 ret
= GetLocaleInfoW( LOWORD(hkl
), LOCALE_IDEFAULTANSICODEPAGE
| LOCALE_RETURN_NUMBER
,
592 (WCHAR
*)&cp
, sizeof(cp
) / sizeof(WCHAR
) );
593 if (!ret
) cp
= CP_ACP
;
597 /***********************************************************************
600 * Convert the wparam of an ASCII message to Unicode.
602 BOOL
map_wparam_AtoW( UINT message
, WPARAM
*wparam
, enum wm_char_mapping mapping
)
612 /* WM_CHAR is magic: a DBCS char can be sent/posted as two consecutive WM_CHAR
613 * messages, in which case the first char is stored, and the conversion
614 * to Unicode only takes place once the second char is sent/posted.
616 if (mapping
!= WMCHAR_MAP_NOMAPPING
)
618 struct wm_char_mapping_data
*data
= get_user_thread_info()->wmchar_data
;
619 BYTE low
= LOBYTE(*wparam
);
620 cp
= get_input_codepage();
625 ch
[1] = HIBYTE(*wparam
);
626 MultiByteToWideChar( cp
, 0, ch
, 2, wch
, 2 );
627 TRACE( "map %02x,%02x -> %04x mapping %u\n", (BYTE
)ch
[0], (BYTE
)ch
[1], wch
[0], mapping
);
628 if (data
) data
->lead_byte
[mapping
] = 0;
630 else if (data
&& data
->lead_byte
[mapping
])
632 ch
[0] = data
->lead_byte
[mapping
];
634 MultiByteToWideChar( cp
, 0, ch
, 2, wch
, 2 );
635 TRACE( "map stored %02x,%02x -> %04x mapping %u\n", (BYTE
)ch
[0], (BYTE
)ch
[1], wch
[0], mapping
);
636 data
->lead_byte
[mapping
] = 0;
638 else if (!IsDBCSLeadByte( low
))
641 MultiByteToWideChar( cp
, 0, ch
, 1, wch
, 2 );
642 TRACE( "map %02x -> %04x\n", (BYTE
)ch
[0], wch
[0] );
643 if (data
) data
->lead_byte
[mapping
] = 0;
645 else /* store it and wait for trail byte */
649 if (!(data
= HeapAlloc( GetProcessHeap(), HEAP_ZERO_MEMORY
, sizeof(*data
) )))
651 get_user_thread_info()->wmchar_data
= data
;
653 TRACE( "storing lead byte %02x mapping %u\n", low
, mapping
);
654 data
->lead_byte
[mapping
] = low
;
657 *wparam
= MAKEWPARAM(wch
[0], wch
[1]);
660 /* else fall through */
662 case EM_SETPASSWORDCHAR
:
667 cp
= get_input_codepage();
668 ch
[0] = LOBYTE(*wparam
);
669 ch
[1] = HIBYTE(*wparam
);
670 MultiByteToWideChar( cp
, 0, ch
, 2, wch
, 2 );
671 *wparam
= MAKEWPARAM(wch
[0], wch
[1]);
674 cp
= get_input_codepage();
675 ch
[0] = HIBYTE(*wparam
);
676 ch
[1] = LOBYTE(*wparam
);
677 if (ch
[0]) MultiByteToWideChar( cp
, 0, ch
, 2, wch
, 2 );
678 else MultiByteToWideChar( cp
, 0, ch
+ 1, 1, wch
, 1 );
679 *wparam
= MAKEWPARAM(wch
[0], HIWORD(*wparam
));
686 /***********************************************************************
689 * Convert the wparam of a Unicode message to ASCII.
691 static void map_wparam_WtoA( MSG
*msg
, BOOL remove
)
701 if (!HIWORD(msg
->wParam
))
703 cp
= get_input_codepage();
704 wch
[0] = LOWORD(msg
->wParam
);
706 len
= WideCharToMultiByte( cp
, 0, wch
, 1, (LPSTR
)ch
, 2, NULL
, NULL
);
707 if (len
== 2) /* DBCS char */
709 struct wm_char_mapping_data
*data
= get_user_thread_info()->wmchar_data
;
712 if (!(data
= HeapAlloc( GetProcessHeap(), HEAP_ZERO_MEMORY
, sizeof(*data
) ))) return;
713 get_user_thread_info()->wmchar_data
= data
;
717 data
->get_msg
= *msg
;
718 data
->get_msg
.wParam
= ch
[1];
724 /* else fall through */
726 case EM_SETPASSWORDCHAR
:
731 cp
= get_input_codepage();
732 wch
[0] = LOWORD(msg
->wParam
);
733 wch
[1] = HIWORD(msg
->wParam
);
735 WideCharToMultiByte( cp
, 0, wch
, 2, (LPSTR
)ch
, 4, NULL
, NULL
);
736 msg
->wParam
= MAKEWPARAM( ch
[0] | (ch
[1] << 8), 0 );
739 cp
= get_input_codepage();
740 wch
[0] = LOWORD(msg
->wParam
);
742 len
= WideCharToMultiByte( cp
, 0, wch
, 1, (LPSTR
)ch
, 2, NULL
, NULL
);
744 msg
->wParam
= MAKEWPARAM( (ch
[0] << 8) | ch
[1], HIWORD(msg
->wParam
) );
746 msg
->wParam
= MAKEWPARAM( ch
[0], HIWORD(msg
->wParam
) );
752 /***********************************************************************
755 * Pack a message for sending to another process.
756 * Return the size of the data we expect in the message reply.
757 * Set data->count to -1 if there is an error.
759 static size_t pack_message( HWND hwnd
, UINT message
, WPARAM wparam
, LPARAM lparam
,
760 struct packed_message
*data
)
768 CREATESTRUCTW
*cs
= (CREATESTRUCTW
*)lparam
;
769 data
->ps
.cs
.lpCreateParams
= pack_ptr( cs
->lpCreateParams
);
770 data
->ps
.cs
.hInstance
= pack_ptr( cs
->hInstance
);
771 data
->ps
.cs
.hMenu
= wine_server_user_handle( cs
->hMenu
);
772 data
->ps
.cs
.hwndParent
= wine_server_user_handle( cs
->hwndParent
);
773 data
->ps
.cs
.cy
= cs
->cy
;
774 data
->ps
.cs
.cx
= cs
->cx
;
775 data
->ps
.cs
.y
= cs
->y
;
776 data
->ps
.cs
.x
= cs
->x
;
777 data
->ps
.cs
.style
= cs
->style
;
778 data
->ps
.cs
.dwExStyle
= cs
->dwExStyle
;
779 data
->ps
.cs
.lpszName
= pack_ptr( cs
->lpszName
);
780 data
->ps
.cs
.lpszClass
= pack_ptr( cs
->lpszClass
);
781 push_data( data
, &data
->ps
.cs
, sizeof(data
->ps
.cs
) );
782 if (!IS_INTRESOURCE(cs
->lpszName
)) push_string( data
, cs
->lpszName
);
783 if (!IS_INTRESOURCE(cs
->lpszClass
)) push_string( data
, cs
->lpszClass
);
784 return sizeof(data
->ps
.cs
);
787 case WM_ASKCBFORMATNAME
:
788 return wparam
* sizeof(WCHAR
);
789 case WM_WININICHANGE
:
790 if (lparam
) push_string(data
, (LPWSTR
)lparam
);
793 case WM_DEVMODECHANGE
:
798 push_string( data
, (LPWSTR
)lparam
);
800 case WM_GETMINMAXINFO
:
801 push_data( data
, (MINMAXINFO
*)lparam
, sizeof(MINMAXINFO
) );
802 return sizeof(MINMAXINFO
);
805 DRAWITEMSTRUCT
*dis
= (DRAWITEMSTRUCT
*)lparam
;
806 data
->ps
.dis
.CtlType
= dis
->CtlType
;
807 data
->ps
.dis
.CtlID
= dis
->CtlID
;
808 data
->ps
.dis
.itemID
= dis
->itemID
;
809 data
->ps
.dis
.itemAction
= dis
->itemAction
;
810 data
->ps
.dis
.itemState
= dis
->itemState
;
811 data
->ps
.dis
.hwndItem
= wine_server_user_handle( dis
->hwndItem
);
812 data
->ps
.dis
.hDC
= wine_server_user_handle( dis
->hDC
); /* FIXME */
813 data
->ps
.dis
.rcItem
= dis
->rcItem
;
814 data
->ps
.dis
.itemData
= dis
->itemData
;
815 push_data( data
, &data
->ps
.dis
, sizeof(data
->ps
.dis
) );
820 MEASUREITEMSTRUCT
*mis
= (MEASUREITEMSTRUCT
*)lparam
;
821 data
->ps
.mis
.CtlType
= mis
->CtlType
;
822 data
->ps
.mis
.CtlID
= mis
->CtlID
;
823 data
->ps
.mis
.itemID
= mis
->itemID
;
824 data
->ps
.mis
.itemWidth
= mis
->itemWidth
;
825 data
->ps
.mis
.itemHeight
= mis
->itemHeight
;
826 data
->ps
.mis
.itemData
= mis
->itemData
;
827 push_data( data
, &data
->ps
.mis
, sizeof(data
->ps
.mis
) );
828 return sizeof(data
->ps
.mis
);
832 DELETEITEMSTRUCT
*dls
= (DELETEITEMSTRUCT
*)lparam
;
833 data
->ps
.dls
.CtlType
= dls
->CtlType
;
834 data
->ps
.dls
.CtlID
= dls
->CtlID
;
835 data
->ps
.dls
.itemID
= dls
->itemID
;
836 data
->ps
.dls
.hwndItem
= wine_server_user_handle( dls
->hwndItem
);
837 data
->ps
.dls
.itemData
= dls
->itemData
;
838 push_data( data
, &data
->ps
.dls
, sizeof(data
->ps
.dls
) );
843 COMPAREITEMSTRUCT
*cis
= (COMPAREITEMSTRUCT
*)lparam
;
844 data
->ps
.cis
.CtlType
= cis
->CtlType
;
845 data
->ps
.cis
.CtlID
= cis
->CtlID
;
846 data
->ps
.cis
.hwndItem
= wine_server_user_handle( cis
->hwndItem
);
847 data
->ps
.cis
.itemID1
= cis
->itemID1
;
848 data
->ps
.cis
.itemData1
= cis
->itemData1
;
849 data
->ps
.cis
.itemID2
= cis
->itemID2
;
850 data
->ps
.cis
.itemData2
= cis
->itemData2
;
851 data
->ps
.cis
.dwLocaleId
= cis
->dwLocaleId
;
852 push_data( data
, &data
->ps
.cis
, sizeof(data
->ps
.cis
) );
855 case WM_WINE_SETWINDOWPOS
:
856 case WM_WINDOWPOSCHANGING
:
857 case WM_WINDOWPOSCHANGED
:
859 WINDOWPOS
*wp
= (WINDOWPOS
*)lparam
;
860 data
->ps
.wp
.hwnd
= wine_server_user_handle( wp
->hwnd
);
861 data
->ps
.wp
.hwndInsertAfter
= wine_server_user_handle( wp
->hwndInsertAfter
);
862 data
->ps
.wp
.x
= wp
->x
;
863 data
->ps
.wp
.y
= wp
->y
;
864 data
->ps
.wp
.cx
= wp
->cx
;
865 data
->ps
.wp
.cy
= wp
->cy
;
866 data
->ps
.wp
.flags
= wp
->flags
;
867 push_data( data
, &data
->ps
.wp
, sizeof(data
->ps
.wp
) );
868 return sizeof(data
->ps
.wp
);
872 COPYDATASTRUCT
*cds
= (COPYDATASTRUCT
*)lparam
;
873 data
->ps
.cds
.cbData
= cds
->cbData
;
874 data
->ps
.cds
.dwData
= cds
->dwData
;
875 data
->ps
.cds
.lpData
= pack_ptr( cds
->lpData
);
876 push_data( data
, &data
->ps
.cds
, sizeof(data
->ps
.cds
) );
877 if (cds
->lpData
) push_data( data
, cds
->lpData
, cds
->cbData
);
881 /* WM_NOTIFY cannot be sent across processes (MSDN) */
886 HELPINFO
*hi
= (HELPINFO
*)lparam
;
887 data
->ps
.hi
.iContextType
= hi
->iContextType
;
888 data
->ps
.hi
.iCtrlId
= hi
->iCtrlId
;
889 data
->ps
.hi
.hItemHandle
= wine_server_user_handle( hi
->hItemHandle
);
890 data
->ps
.hi
.dwContextId
= hi
->dwContextId
;
891 data
->ps
.hi
.MousePos
= hi
->MousePos
;
892 push_data( data
, &data
->ps
.hi
, sizeof(data
->ps
.hi
) );
895 case WM_STYLECHANGING
:
896 case WM_STYLECHANGED
:
897 push_data( data
, (STYLESTRUCT
*)lparam
, sizeof(STYLESTRUCT
) );
902 push_data( data
, (RECT
*)lparam
, sizeof(RECT
) );
907 NCCALCSIZE_PARAMS
*ncp
= (NCCALCSIZE_PARAMS
*)lparam
;
908 data
->ps
.ncp
.rgrc
[0] = ncp
->rgrc
[0];
909 data
->ps
.ncp
.rgrc
[1] = ncp
->rgrc
[1];
910 data
->ps
.ncp
.rgrc
[2] = ncp
->rgrc
[2];
911 data
->ps
.ncp
.hwnd
= wine_server_user_handle( ncp
->lppos
->hwnd
);
912 data
->ps
.ncp
.hwndInsertAfter
= wine_server_user_handle( ncp
->lppos
->hwndInsertAfter
);
913 data
->ps
.ncp
.x
= ncp
->lppos
->x
;
914 data
->ps
.ncp
.y
= ncp
->lppos
->y
;
915 data
->ps
.ncp
.cx
= ncp
->lppos
->cx
;
916 data
->ps
.ncp
.cy
= ncp
->lppos
->cy
;
917 data
->ps
.ncp
.flags
= ncp
->lppos
->flags
;
918 push_data( data
, &data
->ps
.ncp
, sizeof(data
->ps
.ncp
) );
919 return sizeof(data
->ps
.ncp
);
924 MSG
*msg
= (MSG
*)lparam
;
925 data
->ps
.msg
.hwnd
= wine_server_user_handle( msg
->hwnd
);
926 data
->ps
.msg
.message
= msg
->message
;
927 data
->ps
.msg
.wParam
= msg
->wParam
;
928 data
->ps
.msg
.lParam
= msg
->lParam
;
929 data
->ps
.msg
.time
= msg
->time
;
930 data
->ps
.msg
.pt
= msg
->pt
;
931 push_data( data
, &data
->ps
.msg
, sizeof(data
->ps
.msg
) );
932 return sizeof(data
->ps
.msg
);
935 case SBM_SETSCROLLINFO
:
936 push_data( data
, (SCROLLINFO
*)lparam
, sizeof(SCROLLINFO
) );
938 case SBM_GETSCROLLINFO
:
939 push_data( data
, (SCROLLINFO
*)lparam
, sizeof(SCROLLINFO
) );
940 return sizeof(SCROLLINFO
);
941 case SBM_GETSCROLLBARINFO
:
943 const SCROLLBARINFO
*info
= (const SCROLLBARINFO
*)lparam
;
944 size_t size
= min( info
->cbSize
, sizeof(SCROLLBARINFO
) );
945 push_data( data
, info
, size
);
953 if (wparam
) size
+= sizeof(DWORD
);
954 if (lparam
) size
+= sizeof(DWORD
);
959 case CB_GETDROPPEDCONTROLRECT
:
963 push_data( data
, (RECT
*)lparam
, sizeof(RECT
) );
967 WORD
*pw
= (WORD
*)lparam
;
968 push_data( data
, pw
, sizeof(*pw
) );
969 return *pw
* sizeof(WCHAR
);
973 if (wparam
) push_data( data
, (UINT
*)lparam
, sizeof(UINT
) * wparam
);
976 case CB_INSERTSTRING
:
978 case CB_FINDSTRINGEXACT
:
979 case CB_SELECTSTRING
:
980 if (combobox_has_strings( hwnd
)) push_string( data
, (LPWSTR
)lparam
);
983 if (!combobox_has_strings( hwnd
)) return sizeof(ULONG_PTR
);
984 return (SendMessageW( hwnd
, CB_GETLBTEXTLEN
, wparam
, 0 ) + 1) * sizeof(WCHAR
);
986 case LB_INSERTSTRING
:
988 case LB_FINDSTRINGEXACT
:
989 case LB_SELECTSTRING
:
990 if (listbox_has_strings( hwnd
)) push_string( data
, (LPWSTR
)lparam
);
993 if (!listbox_has_strings( hwnd
)) return sizeof(ULONG_PTR
);
994 return (SendMessageW( hwnd
, LB_GETTEXTLEN
, wparam
, 0 ) + 1) * sizeof(WCHAR
);
996 return wparam
* sizeof(UINT
);
999 MDINEXTMENU
*mnm
= (MDINEXTMENU
*)lparam
;
1000 data
->ps
.mnm
.hmenuIn
= wine_server_user_handle( mnm
->hmenuIn
);
1001 data
->ps
.mnm
.hmenuNext
= wine_server_user_handle( mnm
->hmenuNext
);
1002 data
->ps
.mnm
.hwndNext
= wine_server_user_handle( mnm
->hwndNext
);
1003 push_data( data
, &data
->ps
.mnm
, sizeof(data
->ps
.mnm
) );
1004 return sizeof(data
->ps
.mnm
);
1008 push_data( data
, (RECT
*)lparam
, sizeof(RECT
) );
1009 return sizeof(RECT
);
1012 MDICREATESTRUCTW
*mcs
= (MDICREATESTRUCTW
*)lparam
;
1013 data
->ps
.mcs
.szClass
= pack_ptr( mcs
->szClass
);
1014 data
->ps
.mcs
.szTitle
= pack_ptr( mcs
->szTitle
);
1015 data
->ps
.mcs
.hOwner
= pack_ptr( mcs
->hOwner
);
1016 data
->ps
.mcs
.x
= mcs
->x
;
1017 data
->ps
.mcs
.y
= mcs
->y
;
1018 data
->ps
.mcs
.cx
= mcs
->cx
;
1019 data
->ps
.mcs
.cy
= mcs
->cy
;
1020 data
->ps
.mcs
.style
= mcs
->style
;
1021 data
->ps
.mcs
.lParam
= mcs
->lParam
;
1022 push_data( data
, &data
->ps
.mcs
, sizeof(data
->ps
.mcs
) );
1023 if (!IS_INTRESOURCE(mcs
->szClass
)) push_string( data
, mcs
->szClass
);
1024 if (!IS_INTRESOURCE(mcs
->szTitle
)) push_string( data
, mcs
->szTitle
);
1025 return sizeof(data
->ps
.mcs
);
1027 case WM_MDIGETACTIVE
:
1028 if (lparam
) return sizeof(BOOL
);
1030 case WM_DEVICECHANGE
:
1032 DEV_BROADCAST_HDR
*header
= (DEV_BROADCAST_HDR
*)lparam
;
1033 if ((wparam
& 0x8000) && header
) push_data( data
, header
, header
->dbch_size
);
1036 case WM_WINE_KEYBOARD_LL_HOOK
:
1038 struct hook_extra_info
*h_extra
= (struct hook_extra_info
*)lparam
;
1039 data
->ps
.hook
.handle
= wine_server_user_handle( h_extra
->handle
);
1040 push_data( data
, &data
->ps
.hook
, sizeof(data
->ps
.hook
) );
1041 push_data( data
, (LPVOID
)h_extra
->lparam
, sizeof(KBDLLHOOKSTRUCT
) );
1044 case WM_WINE_MOUSE_LL_HOOK
:
1046 struct hook_extra_info
*h_extra
= (struct hook_extra_info
*)lparam
;
1047 data
->ps
.hook
.handle
= wine_server_user_handle( h_extra
->handle
);
1048 push_data( data
, &data
->ps
.hook
, sizeof(data
->ps
.hook
) );
1049 push_data( data
, (LPVOID
)h_extra
->lparam
, sizeof(MSLLHOOKSTRUCT
) );
1053 if (wparam
<= 1) return 0;
1054 FIXME( "WM_NCPAINT hdc packing not supported yet\n" );
1058 if (!wparam
) return 0;
1061 /* these contain an HFONT */
1064 /* these contain an HDC */
1066 case WM_ICONERASEBKGND
:
1067 case WM_CTLCOLORMSGBOX
:
1068 case WM_CTLCOLOREDIT
:
1069 case WM_CTLCOLORLISTBOX
:
1070 case WM_CTLCOLORBTN
:
1071 case WM_CTLCOLORDLG
:
1072 case WM_CTLCOLORSCROLLBAR
:
1073 case WM_CTLCOLORSTATIC
:
1075 case WM_PRINTCLIENT
:
1076 /* these contain an HGLOBAL */
1077 case WM_PAINTCLIPBOARD
:
1078 case WM_SIZECLIPBOARD
:
1079 /* these contain HICON */
1082 case WM_QUERYDRAGICON
:
1083 case WM_QUERYPARKICON
:
1084 /* these contain pointers */
1086 case WM_QUERYDROPOBJECT
:
1090 FIXME( "msg %x (%s) not supported yet\n", message
, SPY_GetMsgName(message
, hwnd
) );
1098 /***********************************************************************
1101 * Unpack a message received from another process.
1103 static BOOL
unpack_message( HWND hwnd
, UINT message
, WPARAM
*wparam
, LPARAM
*lparam
,
1104 void **buffer
, size_t size
)
1107 union packed_structs
*ps
= *buffer
;
1115 WCHAR
*str
= (WCHAR
*)(&ps
->cs
+ 1);
1116 if (size
< sizeof(ps
->cs
)) return FALSE
;
1117 size
-= sizeof(ps
->cs
);
1118 cs
.lpCreateParams
= unpack_ptr( ps
->cs
.lpCreateParams
);
1119 cs
.hInstance
= unpack_ptr( ps
->cs
.hInstance
);
1120 cs
.hMenu
= wine_server_ptr_handle( ps
->cs
.hMenu
);
1121 cs
.hwndParent
= wine_server_ptr_handle( ps
->cs
.hwndParent
);
1126 cs
.style
= ps
->cs
.style
;
1127 cs
.dwExStyle
= ps
->cs
.dwExStyle
;
1128 cs
.lpszName
= unpack_ptr( ps
->cs
.lpszName
);
1129 cs
.lpszClass
= unpack_ptr( ps
->cs
.lpszClass
);
1130 if (ps
->cs
.lpszName
>> 16)
1132 if (!check_string( str
, size
)) return FALSE
;
1134 size
-= (lstrlenW(str
) + 1) * sizeof(WCHAR
);
1135 str
+= lstrlenW(str
) + 1;
1137 if (ps
->cs
.lpszClass
>> 16)
1139 if (!check_string( str
, size
)) return FALSE
;
1142 memcpy( &ps
->cs
, &cs
, sizeof(cs
) );
1146 case WM_ASKCBFORMATNAME
:
1147 if (!get_buffer_space( buffer
, (*wparam
* sizeof(WCHAR
)) )) return FALSE
;
1149 case WM_WININICHANGE
:
1150 if (!*lparam
) return TRUE
;
1153 case WM_DEVMODECHANGE
:
1158 if (!check_string( *buffer
, size
)) return FALSE
;
1160 case WM_GETMINMAXINFO
:
1161 minsize
= sizeof(MINMAXINFO
);
1166 if (size
< sizeof(ps
->dis
)) return FALSE
;
1167 dis
.CtlType
= ps
->dis
.CtlType
;
1168 dis
.CtlID
= ps
->dis
.CtlID
;
1169 dis
.itemID
= ps
->dis
.itemID
;
1170 dis
.itemAction
= ps
->dis
.itemAction
;
1171 dis
.itemState
= ps
->dis
.itemState
;
1172 dis
.hwndItem
= wine_server_ptr_handle( ps
->dis
.hwndItem
);
1173 dis
.hDC
= wine_server_ptr_handle( ps
->dis
.hDC
);
1174 dis
.rcItem
= ps
->dis
.rcItem
;
1175 dis
.itemData
= (ULONG_PTR
)unpack_ptr( ps
->dis
.itemData
);
1176 memcpy( &ps
->dis
, &dis
, sizeof(dis
) );
1179 case WM_MEASUREITEM
:
1181 MEASUREITEMSTRUCT mis
;
1182 if (size
< sizeof(ps
->mis
)) return FALSE
;
1183 mis
.CtlType
= ps
->mis
.CtlType
;
1184 mis
.CtlID
= ps
->mis
.CtlID
;
1185 mis
.itemID
= ps
->mis
.itemID
;
1186 mis
.itemWidth
= ps
->mis
.itemWidth
;
1187 mis
.itemHeight
= ps
->mis
.itemHeight
;
1188 mis
.itemData
= (ULONG_PTR
)unpack_ptr( ps
->mis
.itemData
);
1189 memcpy( &ps
->mis
, &mis
, sizeof(mis
) );
1194 DELETEITEMSTRUCT dls
;
1195 if (size
< sizeof(ps
->dls
)) return FALSE
;
1196 dls
.CtlType
= ps
->dls
.CtlType
;
1197 dls
.CtlID
= ps
->dls
.CtlID
;
1198 dls
.itemID
= ps
->dls
.itemID
;
1199 dls
.hwndItem
= wine_server_ptr_handle( ps
->dls
.hwndItem
);
1200 dls
.itemData
= (ULONG_PTR
)unpack_ptr( ps
->dls
.itemData
);
1201 memcpy( &ps
->dls
, &dls
, sizeof(dls
) );
1204 case WM_COMPAREITEM
:
1206 COMPAREITEMSTRUCT cis
;
1207 if (size
< sizeof(ps
->cis
)) return FALSE
;
1208 cis
.CtlType
= ps
->cis
.CtlType
;
1209 cis
.CtlID
= ps
->cis
.CtlID
;
1210 cis
.hwndItem
= wine_server_ptr_handle( ps
->cis
.hwndItem
);
1211 cis
.itemID1
= ps
->cis
.itemID1
;
1212 cis
.itemData1
= (ULONG_PTR
)unpack_ptr( ps
->cis
.itemData1
);
1213 cis
.itemID2
= ps
->cis
.itemID2
;
1214 cis
.itemData2
= (ULONG_PTR
)unpack_ptr( ps
->cis
.itemData2
);
1215 cis
.dwLocaleId
= ps
->cis
.dwLocaleId
;
1216 memcpy( &ps
->cis
, &cis
, sizeof(cis
) );
1219 case WM_WINDOWPOSCHANGING
:
1220 case WM_WINDOWPOSCHANGED
:
1221 case WM_WINE_SETWINDOWPOS
:
1224 if (size
< sizeof(ps
->wp
)) return FALSE
;
1225 wp
.hwnd
= wine_server_ptr_handle( ps
->wp
.hwnd
);
1226 wp
.hwndInsertAfter
= wine_server_ptr_handle( ps
->wp
.hwndInsertAfter
);
1231 wp
.flags
= ps
->wp
.flags
;
1232 memcpy( &ps
->wp
, &wp
, sizeof(wp
) );
1238 if (size
< sizeof(ps
->cds
)) return FALSE
;
1239 cds
.dwData
= (ULONG_PTR
)unpack_ptr( ps
->cds
.dwData
);
1242 cds
.cbData
= ps
->cds
.cbData
;
1243 cds
.lpData
= &ps
->cds
+ 1;
1244 minsize
= sizeof(ps
->cds
) + cds
.cbData
;
1251 memcpy( &ps
->cds
, &cds
, sizeof(cds
) );
1255 /* WM_NOTIFY cannot be sent across processes (MSDN) */
1260 if (size
< sizeof(ps
->hi
)) return FALSE
;
1261 hi
.cbSize
= sizeof(hi
);
1262 hi
.iContextType
= ps
->hi
.iContextType
;
1263 hi
.iCtrlId
= ps
->hi
.iCtrlId
;
1264 hi
.hItemHandle
= wine_server_ptr_handle( ps
->hi
.hItemHandle
);
1265 hi
.dwContextId
= (ULONG_PTR
)unpack_ptr( ps
->hi
.dwContextId
);
1266 hi
.MousePos
= ps
->hi
.MousePos
;
1267 memcpy( &ps
->hi
, &hi
, sizeof(hi
) );
1270 case WM_STYLECHANGING
:
1271 case WM_STYLECHANGED
:
1272 minsize
= sizeof(STYLESTRUCT
);
1275 if (!*wparam
) minsize
= sizeof(RECT
);
1278 NCCALCSIZE_PARAMS ncp
;
1280 if (size
< sizeof(ps
->ncp
)) return FALSE
;
1281 ncp
.rgrc
[0] = ps
->ncp
.rgrc
[0];
1282 ncp
.rgrc
[1] = ps
->ncp
.rgrc
[1];
1283 ncp
.rgrc
[2] = ps
->ncp
.rgrc
[2];
1284 wp
.hwnd
= wine_server_ptr_handle( ps
->ncp
.hwnd
);
1285 wp
.hwndInsertAfter
= wine_server_ptr_handle( ps
->ncp
.hwndInsertAfter
);
1290 wp
.flags
= ps
->ncp
.flags
;
1291 ncp
.lppos
= (WINDOWPOS
*)((NCCALCSIZE_PARAMS
*)&ps
->ncp
+ 1);
1292 memcpy( &ps
->ncp
, &ncp
, sizeof(ncp
) );
1300 if (size
< sizeof(ps
->msg
)) return FALSE
;
1301 msg
.hwnd
= wine_server_ptr_handle( ps
->msg
.hwnd
);
1302 msg
.message
= ps
->msg
.message
;
1303 msg
.wParam
= (ULONG_PTR
)unpack_ptr( ps
->msg
.wParam
);
1304 msg
.lParam
= (ULONG_PTR
)unpack_ptr( ps
->msg
.lParam
);
1305 msg
.time
= ps
->msg
.time
;
1306 msg
.pt
= ps
->msg
.pt
;
1307 memcpy( &ps
->msg
, &msg
, sizeof(msg
) );
1311 case SBM_SETSCROLLINFO
:
1312 minsize
= sizeof(SCROLLINFO
);
1314 case SBM_GETSCROLLINFO
:
1315 if (!get_buffer_space( buffer
, sizeof(SCROLLINFO
))) return FALSE
;
1317 case SBM_GETSCROLLBARINFO
:
1318 if (!get_buffer_space( buffer
, sizeof(SCROLLBARINFO
))) return FALSE
;
1323 if (*wparam
|| *lparam
)
1325 if (!get_buffer_space( buffer
, 2*sizeof(DWORD
) )) return FALSE
;
1326 if (*wparam
) *wparam
= (WPARAM
)*buffer
;
1327 if (*lparam
) *lparam
= (LPARAM
)((DWORD
*)*buffer
+ 1);
1331 case LB_GETITEMRECT
:
1332 case CB_GETDROPPEDCONTROLRECT
:
1333 if (!get_buffer_space( buffer
, sizeof(RECT
) )) return FALSE
;
1337 minsize
= sizeof(RECT
);
1342 if (size
< sizeof(WORD
)) return FALSE
;
1343 len
= *(WORD
*)*buffer
;
1344 if (!get_buffer_space( buffer
, (len
+ 1) * sizeof(WCHAR
) )) return FALSE
;
1345 *lparam
= (LPARAM
)*buffer
+ sizeof(WORD
); /* don't erase WORD at start of buffer */
1348 case EM_SETTABSTOPS
:
1349 case LB_SETTABSTOPS
:
1350 if (!*wparam
) return TRUE
;
1351 minsize
= *wparam
* sizeof(UINT
);
1354 case CB_INSERTSTRING
:
1356 case CB_FINDSTRINGEXACT
:
1357 case CB_SELECTSTRING
:
1359 case LB_INSERTSTRING
:
1361 case LB_FINDSTRINGEXACT
:
1362 case LB_SELECTSTRING
:
1363 if (!*buffer
) return TRUE
;
1364 if (!check_string( *buffer
, size
)) return FALSE
;
1368 size
= sizeof(ULONG_PTR
);
1369 if (combobox_has_strings( hwnd
))
1370 size
= (SendMessageW( hwnd
, CB_GETLBTEXTLEN
, *wparam
, 0 ) + 1) * sizeof(WCHAR
);
1371 if (!get_buffer_space( buffer
, size
)) return FALSE
;
1376 size
= sizeof(ULONG_PTR
);
1377 if (listbox_has_strings( hwnd
))
1378 size
= (SendMessageW( hwnd
, LB_GETTEXTLEN
, *wparam
, 0 ) + 1) * sizeof(WCHAR
);
1379 if (!get_buffer_space( buffer
, size
)) return FALSE
;
1382 case LB_GETSELITEMS
:
1383 if (!get_buffer_space( buffer
, *wparam
* sizeof(UINT
) )) return FALSE
;
1388 if (size
< sizeof(ps
->mnm
)) return FALSE
;
1389 mnm
.hmenuIn
= wine_server_ptr_handle( ps
->mnm
.hmenuIn
);
1390 mnm
.hmenuNext
= wine_server_ptr_handle( ps
->mnm
.hmenuNext
);
1391 mnm
.hwndNext
= wine_server_ptr_handle( ps
->mnm
.hwndNext
);
1392 memcpy( &ps
->mnm
, &mnm
, sizeof(mnm
) );
1397 minsize
= sizeof(RECT
);
1398 if (!get_buffer_space( buffer
, sizeof(RECT
) )) return FALSE
;
1402 MDICREATESTRUCTW mcs
;
1403 WCHAR
*str
= (WCHAR
*)(&ps
->mcs
+ 1);
1404 if (size
< sizeof(ps
->mcs
)) return FALSE
;
1405 size
-= sizeof(ps
->mcs
);
1407 mcs
.szClass
= unpack_ptr( ps
->mcs
.szClass
);
1408 mcs
.szTitle
= unpack_ptr( ps
->mcs
.szTitle
);
1409 mcs
.hOwner
= unpack_ptr( ps
->mcs
.hOwner
);
1412 mcs
.cx
= ps
->mcs
.cx
;
1413 mcs
.cy
= ps
->mcs
.cy
;
1414 mcs
.style
= ps
->mcs
.style
;
1415 mcs
.lParam
= (LPARAM
)unpack_ptr( ps
->mcs
.lParam
);
1416 if (ps
->mcs
.szClass
>> 16)
1418 if (!check_string( str
, size
)) return FALSE
;
1420 size
-= (lstrlenW(str
) + 1) * sizeof(WCHAR
);
1421 str
+= lstrlenW(str
) + 1;
1423 if (ps
->mcs
.szTitle
>> 16)
1425 if (!check_string( str
, size
)) return FALSE
;
1428 memcpy( &ps
->mcs
, &mcs
, sizeof(mcs
) );
1431 case WM_MDIGETACTIVE
:
1432 if (!*lparam
) return TRUE
;
1433 if (!get_buffer_space( buffer
, sizeof(BOOL
) )) return FALSE
;
1435 case WM_DEVICECHANGE
:
1436 if (!(*wparam
& 0x8000)) return TRUE
;
1437 minsize
= sizeof(DEV_BROADCAST_HDR
);
1439 case WM_WINE_KEYBOARD_LL_HOOK
:
1440 case WM_WINE_MOUSE_LL_HOOK
:
1442 struct hook_extra_info h_extra
;
1443 minsize
= sizeof(ps
->hook
) +
1444 (message
== WM_WINE_KEYBOARD_LL_HOOK
? sizeof(KBDLLHOOKSTRUCT
)
1445 : sizeof(MSLLHOOKSTRUCT
));
1446 if (size
< minsize
) return FALSE
;
1447 h_extra
.handle
= wine_server_ptr_handle( ps
->hook
.handle
);
1448 h_extra
.lparam
= (LPARAM
)(&ps
->hook
+ 1);
1449 memcpy( &ps
->hook
, &h_extra
, sizeof(h_extra
) );
1453 if (*wparam
<= 1) return TRUE
;
1454 FIXME( "WM_NCPAINT hdc unpacking not supported\n" );
1457 if (!*wparam
) return TRUE
;
1460 /* these contain an HFONT */
1463 /* these contain an HDC */
1465 case WM_ICONERASEBKGND
:
1466 case WM_CTLCOLORMSGBOX
:
1467 case WM_CTLCOLOREDIT
:
1468 case WM_CTLCOLORLISTBOX
:
1469 case WM_CTLCOLORBTN
:
1470 case WM_CTLCOLORDLG
:
1471 case WM_CTLCOLORSCROLLBAR
:
1472 case WM_CTLCOLORSTATIC
:
1474 case WM_PRINTCLIENT
:
1475 /* these contain an HGLOBAL */
1476 case WM_PAINTCLIPBOARD
:
1477 case WM_SIZECLIPBOARD
:
1478 /* these contain HICON */
1481 case WM_QUERYDRAGICON
:
1482 case WM_QUERYPARKICON
:
1483 /* these contain pointers */
1485 case WM_QUERYDROPOBJECT
:
1489 FIXME( "msg %x (%s) not supported yet\n", message
, SPY_GetMsgName(message
, hwnd
) );
1493 return TRUE
; /* message doesn't need any unpacking */
1496 /* default exit for most messages: check minsize and store buffer in lparam */
1497 if (size
< minsize
) return FALSE
;
1498 *lparam
= (LPARAM
)*buffer
;
1503 /***********************************************************************
1506 * Pack a reply to a message for sending to another process.
1508 static void pack_reply( HWND hwnd
, UINT message
, WPARAM wparam
, LPARAM lparam
,
1509 LRESULT res
, struct packed_message
*data
)
1517 CREATESTRUCTW
*cs
= (CREATESTRUCTW
*)lparam
;
1518 data
->ps
.cs
.lpCreateParams
= (ULONG_PTR
)cs
->lpCreateParams
;
1519 data
->ps
.cs
.hInstance
= (ULONG_PTR
)cs
->hInstance
;
1520 data
->ps
.cs
.hMenu
= wine_server_user_handle( cs
->hMenu
);
1521 data
->ps
.cs
.hwndParent
= wine_server_user_handle( cs
->hwndParent
);
1522 data
->ps
.cs
.cy
= cs
->cy
;
1523 data
->ps
.cs
.cx
= cs
->cx
;
1524 data
->ps
.cs
.y
= cs
->y
;
1525 data
->ps
.cs
.x
= cs
->x
;
1526 data
->ps
.cs
.style
= cs
->style
;
1527 data
->ps
.cs
.dwExStyle
= cs
->dwExStyle
;
1528 data
->ps
.cs
.lpszName
= (ULONG_PTR
)cs
->lpszName
;
1529 data
->ps
.cs
.lpszClass
= (ULONG_PTR
)cs
->lpszClass
;
1530 push_data( data
, &data
->ps
.cs
, sizeof(data
->ps
.cs
) );
1536 push_data( data
, (WCHAR
*)lparam
, (res
+ 1) * sizeof(WCHAR
) );
1538 case WM_GETMINMAXINFO
:
1539 push_data( data
, (MINMAXINFO
*)lparam
, sizeof(MINMAXINFO
) );
1541 case WM_MEASUREITEM
:
1543 MEASUREITEMSTRUCT
*mis
= (MEASUREITEMSTRUCT
*)lparam
;
1544 data
->ps
.mis
.CtlType
= mis
->CtlType
;
1545 data
->ps
.mis
.CtlID
= mis
->CtlID
;
1546 data
->ps
.mis
.itemID
= mis
->itemID
;
1547 data
->ps
.mis
.itemWidth
= mis
->itemWidth
;
1548 data
->ps
.mis
.itemHeight
= mis
->itemHeight
;
1549 data
->ps
.mis
.itemData
= mis
->itemData
;
1550 push_data( data
, &data
->ps
.mis
, sizeof(data
->ps
.mis
) );
1553 case WM_WINDOWPOSCHANGING
:
1554 case WM_WINDOWPOSCHANGED
:
1556 WINDOWPOS
*wp
= (WINDOWPOS
*)lparam
;
1557 data
->ps
.wp
.hwnd
= wine_server_user_handle( wp
->hwnd
);
1558 data
->ps
.wp
.hwndInsertAfter
= wine_server_user_handle( wp
->hwndInsertAfter
);
1559 data
->ps
.wp
.x
= wp
->x
;
1560 data
->ps
.wp
.y
= wp
->y
;
1561 data
->ps
.wp
.cx
= wp
->cx
;
1562 data
->ps
.wp
.cy
= wp
->cy
;
1563 data
->ps
.wp
.flags
= wp
->flags
;
1564 push_data( data
, &data
->ps
.wp
, sizeof(data
->ps
.wp
) );
1570 MSG
*msg
= (MSG
*)lparam
;
1571 data
->ps
.msg
.hwnd
= wine_server_user_handle( msg
->hwnd
);
1572 data
->ps
.msg
.message
= msg
->message
;
1573 data
->ps
.msg
.wParam
= msg
->wParam
;
1574 data
->ps
.msg
.lParam
= msg
->lParam
;
1575 data
->ps
.msg
.time
= msg
->time
;
1576 data
->ps
.msg
.pt
= msg
->pt
;
1577 push_data( data
, &data
->ps
.msg
, sizeof(data
->ps
.msg
) );
1580 case SBM_GETSCROLLINFO
:
1581 push_data( data
, (SCROLLINFO
*)lparam
, sizeof(SCROLLINFO
) );
1584 case LB_GETITEMRECT
:
1585 case CB_GETDROPPEDCONTROLRECT
:
1588 push_data( data
, (RECT
*)lparam
, sizeof(RECT
) );
1592 WORD
*ptr
= (WORD
*)lparam
;
1593 push_data( data
, ptr
, ptr
[-1] * sizeof(WCHAR
) );
1596 case LB_GETSELITEMS
:
1597 push_data( data
, (UINT
*)lparam
, wparam
* sizeof(UINT
) );
1599 case WM_MDIGETACTIVE
:
1600 if (lparam
) push_data( data
, (BOOL
*)lparam
, sizeof(BOOL
) );
1604 push_data( data
, (RECT
*)lparam
, sizeof(RECT
) );
1607 NCCALCSIZE_PARAMS
*ncp
= (NCCALCSIZE_PARAMS
*)lparam
;
1608 data
->ps
.ncp
.rgrc
[0] = ncp
->rgrc
[0];
1609 data
->ps
.ncp
.rgrc
[1] = ncp
->rgrc
[1];
1610 data
->ps
.ncp
.rgrc
[2] = ncp
->rgrc
[2];
1611 data
->ps
.ncp
.hwnd
= wine_server_user_handle( ncp
->lppos
->hwnd
);
1612 data
->ps
.ncp
.hwndInsertAfter
= wine_server_user_handle( ncp
->lppos
->hwndInsertAfter
);
1613 data
->ps
.ncp
.x
= ncp
->lppos
->x
;
1614 data
->ps
.ncp
.y
= ncp
->lppos
->y
;
1615 data
->ps
.ncp
.cx
= ncp
->lppos
->cx
;
1616 data
->ps
.ncp
.cy
= ncp
->lppos
->cy
;
1617 data
->ps
.ncp
.flags
= ncp
->lppos
->flags
;
1618 push_data( data
, &data
->ps
.ncp
, sizeof(data
->ps
.ncp
) );
1624 if (wparam
) push_data( data
, (DWORD
*)wparam
, sizeof(DWORD
) );
1625 if (lparam
) push_data( data
, (DWORD
*)lparam
, sizeof(DWORD
) );
1629 MDINEXTMENU
*mnm
= (MDINEXTMENU
*)lparam
;
1630 data
->ps
.mnm
.hmenuIn
= wine_server_user_handle( mnm
->hmenuIn
);
1631 data
->ps
.mnm
.hmenuNext
= wine_server_user_handle( mnm
->hmenuNext
);
1632 data
->ps
.mnm
.hwndNext
= wine_server_user_handle( mnm
->hwndNext
);
1633 push_data( data
, &data
->ps
.mnm
, sizeof(data
->ps
.mnm
) );
1638 MDICREATESTRUCTW
*mcs
= (MDICREATESTRUCTW
*)lparam
;
1639 data
->ps
.mcs
.szClass
= pack_ptr( mcs
->szClass
);
1640 data
->ps
.mcs
.szTitle
= pack_ptr( mcs
->szTitle
);
1641 data
->ps
.mcs
.hOwner
= pack_ptr( mcs
->hOwner
);
1642 data
->ps
.mcs
.x
= mcs
->x
;
1643 data
->ps
.mcs
.y
= mcs
->y
;
1644 data
->ps
.mcs
.cx
= mcs
->cx
;
1645 data
->ps
.mcs
.cy
= mcs
->cy
;
1646 data
->ps
.mcs
.style
= mcs
->style
;
1647 data
->ps
.mcs
.lParam
= mcs
->lParam
;
1648 push_data( data
, &data
->ps
.mcs
, sizeof(data
->ps
.mcs
) );
1651 case WM_ASKCBFORMATNAME
:
1652 push_data( data
, (WCHAR
*)lparam
, (lstrlenW((WCHAR
*)lparam
) + 1) * sizeof(WCHAR
) );
1658 /***********************************************************************
1661 * Unpack a message reply received from another process.
1663 static void unpack_reply( HWND hwnd
, UINT message
, WPARAM wparam
, LPARAM lparam
,
1664 void *buffer
, size_t size
)
1666 union packed_structs
*ps
= buffer
;
1672 if (size
>= sizeof(ps
->cs
))
1674 CREATESTRUCTW
*cs
= (CREATESTRUCTW
*)lparam
;
1675 cs
->lpCreateParams
= unpack_ptr( ps
->cs
.lpCreateParams
);
1676 cs
->hInstance
= unpack_ptr( ps
->cs
.hInstance
);
1677 cs
->hMenu
= wine_server_ptr_handle( ps
->cs
.hMenu
);
1678 cs
->hwndParent
= wine_server_ptr_handle( ps
->cs
.hwndParent
);
1683 cs
->style
= ps
->cs
.style
;
1684 cs
->dwExStyle
= ps
->cs
.dwExStyle
;
1685 /* don't allow changing name and class pointers */
1689 case WM_ASKCBFORMATNAME
:
1690 memcpy( (WCHAR
*)lparam
, buffer
, min( wparam
*sizeof(WCHAR
), size
));
1692 case WM_GETMINMAXINFO
:
1693 memcpy( (MINMAXINFO
*)lparam
, buffer
, min( sizeof(MINMAXINFO
), size
));
1695 case WM_MEASUREITEM
:
1696 if (size
>= sizeof(ps
->mis
))
1698 MEASUREITEMSTRUCT
*mis
= (MEASUREITEMSTRUCT
*)lparam
;
1699 mis
->CtlType
= ps
->mis
.CtlType
;
1700 mis
->CtlID
= ps
->mis
.CtlID
;
1701 mis
->itemID
= ps
->mis
.itemID
;
1702 mis
->itemWidth
= ps
->mis
.itemWidth
;
1703 mis
->itemHeight
= ps
->mis
.itemHeight
;
1704 mis
->itemData
= (ULONG_PTR
)unpack_ptr( ps
->mis
.itemData
);
1707 case WM_WINDOWPOSCHANGING
:
1708 case WM_WINDOWPOSCHANGED
:
1709 if (size
>= sizeof(ps
->wp
))
1711 WINDOWPOS
*wp
= (WINDOWPOS
*)lparam
;
1712 wp
->hwnd
= wine_server_ptr_handle( ps
->wp
.hwnd
);
1713 wp
->hwndInsertAfter
= wine_server_ptr_handle( ps
->wp
.hwndInsertAfter
);
1718 wp
->flags
= ps
->wp
.flags
;
1722 if (lparam
&& size
>= sizeof(ps
->msg
))
1724 MSG
*msg
= (MSG
*)lparam
;
1725 msg
->hwnd
= wine_server_ptr_handle( ps
->msg
.hwnd
);
1726 msg
->message
= ps
->msg
.message
;
1727 msg
->wParam
= (ULONG_PTR
)unpack_ptr( ps
->msg
.wParam
);
1728 msg
->lParam
= (ULONG_PTR
)unpack_ptr( ps
->msg
.lParam
);
1729 msg
->time
= ps
->msg
.time
;
1730 msg
->pt
= ps
->msg
.pt
;
1733 case SBM_GETSCROLLINFO
:
1734 memcpy( (SCROLLINFO
*)lparam
, buffer
, min( sizeof(SCROLLINFO
), size
));
1736 case SBM_GETSCROLLBARINFO
:
1737 memcpy( (SCROLLBARINFO
*)lparam
, buffer
, min( sizeof(SCROLLBARINFO
), size
));
1740 case CB_GETDROPPEDCONTROLRECT
:
1741 case LB_GETITEMRECT
:
1744 memcpy( (RECT
*)lparam
, buffer
, min( sizeof(RECT
), size
));
1747 size
= min( size
, (size_t)*(WORD
*)lparam
);
1748 memcpy( (WCHAR
*)lparam
, buffer
, size
);
1750 case LB_GETSELITEMS
:
1751 memcpy( (UINT
*)lparam
, buffer
, min( wparam
*sizeof(UINT
), size
));
1755 memcpy( (WCHAR
*)lparam
, buffer
, size
);
1758 if (size
>= sizeof(ps
->mnm
))
1760 MDINEXTMENU
*mnm
= (MDINEXTMENU
*)lparam
;
1761 mnm
->hmenuIn
= wine_server_ptr_handle( ps
->mnm
.hmenuIn
);
1762 mnm
->hmenuNext
= wine_server_ptr_handle( ps
->mnm
.hmenuNext
);
1763 mnm
->hwndNext
= wine_server_ptr_handle( ps
->mnm
.hwndNext
);
1766 case WM_MDIGETACTIVE
:
1767 if (lparam
) memcpy( (BOOL
*)lparam
, buffer
, min( sizeof(BOOL
), size
));
1771 memcpy( (RECT
*)lparam
, buffer
, min( sizeof(RECT
), size
));
1772 else if (size
>= sizeof(ps
->ncp
))
1774 NCCALCSIZE_PARAMS
*ncp
= (NCCALCSIZE_PARAMS
*)lparam
;
1775 ncp
->rgrc
[0] = ps
->ncp
.rgrc
[0];
1776 ncp
->rgrc
[1] = ps
->ncp
.rgrc
[1];
1777 ncp
->rgrc
[2] = ps
->ncp
.rgrc
[2];
1778 ncp
->lppos
->hwnd
= wine_server_ptr_handle( ps
->ncp
.hwnd
);
1779 ncp
->lppos
->hwndInsertAfter
= wine_server_ptr_handle( ps
->ncp
.hwndInsertAfter
);
1780 ncp
->lppos
->x
= ps
->ncp
.x
;
1781 ncp
->lppos
->y
= ps
->ncp
.y
;
1782 ncp
->lppos
->cx
= ps
->ncp
.cx
;
1783 ncp
->lppos
->cy
= ps
->ncp
.cy
;
1784 ncp
->lppos
->flags
= ps
->ncp
.flags
;
1792 memcpy( (DWORD
*)wparam
, buffer
, min( sizeof(DWORD
), size
));
1793 if (size
<= sizeof(DWORD
)) break;
1794 size
-= sizeof(DWORD
);
1795 buffer
= (DWORD
*)buffer
+ 1;
1797 if (lparam
) memcpy( (DWORD
*)lparam
, buffer
, min( sizeof(DWORD
), size
));
1800 if (size
>= sizeof(ps
->mcs
))
1802 MDICREATESTRUCTW
*mcs
= (MDICREATESTRUCTW
*)lparam
;
1803 mcs
->hOwner
= unpack_ptr( ps
->mcs
.hOwner
);
1806 mcs
->cx
= ps
->mcs
.cx
;
1807 mcs
->cy
= ps
->mcs
.cy
;
1808 mcs
->style
= ps
->mcs
.style
;
1809 mcs
->lParam
= (LPARAM
)unpack_ptr( ps
->mcs
.lParam
);
1810 /* don't allow changing class and title pointers */
1814 ERR( "should not happen: unexpected message %x\n", message
);
1820 /***********************************************************************
1823 * Send a reply to a sent message.
1825 static void reply_message( struct received_message_info
*info
, LRESULT result
, BOOL remove
)
1827 struct packed_message data
;
1828 int i
, replied
= info
->flags
& ISMEX_REPLIED
;
1830 if (info
->flags
& ISMEX_NOTIFY
) return; /* notify messages don't get replies */
1831 if (!remove
&& replied
) return; /* replied already */
1833 memset( &data
, 0, sizeof(data
) );
1834 info
->flags
|= ISMEX_REPLIED
;
1836 if (info
->type
== MSG_OTHER_PROCESS
&& !replied
)
1838 pack_reply( info
->msg
.hwnd
, info
->msg
.message
, info
->msg
.wParam
,
1839 info
->msg
.lParam
, result
, &data
);
1842 SERVER_START_REQ( reply_message
)
1844 req
->result
= result
;
1845 req
->remove
= remove
;
1846 for (i
= 0; i
< data
.count
; i
++) wine_server_add_data( req
, data
.data
[i
], data
.size
[i
] );
1847 wine_server_call( req
);
1853 /***********************************************************************
1854 * handle_internal_message
1856 * Handle an internal Wine message instead of calling the window proc.
1858 static LRESULT
handle_internal_message( HWND hwnd
, UINT msg
, WPARAM wparam
, LPARAM lparam
)
1862 case WM_WINE_DESTROYWINDOW
:
1863 return WIN_DestroyWindow( hwnd
);
1864 case WM_WINE_SETWINDOWPOS
:
1865 if (is_desktop_window( hwnd
)) return 0;
1866 return USER_SetWindowPos( (WINDOWPOS
*)lparam
, 0, 0 );
1867 case WM_WINE_SHOWWINDOW
:
1868 if (is_desktop_window( hwnd
)) return 0;
1869 return ShowWindow( hwnd
, wparam
);
1870 case WM_WINE_SETPARENT
:
1871 if (is_desktop_window( hwnd
)) return 0;
1872 return (LRESULT
)SetParent( hwnd
, (HWND
)wparam
);
1873 case WM_WINE_SETWINDOWLONG
:
1874 return WIN_SetWindowLong( hwnd
, (short)LOWORD(wparam
), HIWORD(wparam
), lparam
, TRUE
);
1875 case WM_WINE_SETSTYLE
:
1876 if (is_desktop_window( hwnd
)) return 0;
1877 return WIN_SetStyle(hwnd
, wparam
, lparam
);
1878 case WM_WINE_SETACTIVEWINDOW
:
1879 if (!wparam
&& GetForegroundWindow() == hwnd
) return 0;
1880 return (LRESULT
)SetActiveWindow( (HWND
)wparam
);
1881 case WM_WINE_KEYBOARD_LL_HOOK
:
1882 case WM_WINE_MOUSE_LL_HOOK
:
1884 struct hook_extra_info
*h_extra
= (struct hook_extra_info
*)lparam
;
1886 return call_current_hook( h_extra
->handle
, HC_ACTION
, wparam
, h_extra
->lparam
);
1888 case WM_WINE_CLIPCURSOR
:
1892 GetClipCursor( &rect
);
1893 return USER_Driver
->pClipCursor( &rect
);
1895 return USER_Driver
->pClipCursor( NULL
);
1896 case WM_WINE_UPDATEWINDOWSTATE
:
1897 update_window_state( hwnd
);
1900 if (msg
>= WM_WINE_FIRST_DRIVER_MSG
&& msg
<= WM_WINE_LAST_DRIVER_MSG
)
1901 return USER_Driver
->pWindowMessage( hwnd
, msg
, wparam
, lparam
);
1902 FIXME( "unknown internal message %x\n", msg
);
1907 /* since the WM_DDE_ACK response to a WM_DDE_EXECUTE message should contain the handle
1908 * to the memory handle, we keep track (in the server side) of all pairs of handle
1909 * used (the client passes its value and the content of the memory handle), and
1910 * the server stored both values (the client, and the local one, created after the
1911 * content). When a ACK message is generated, the list of pair is searched for a
1912 * matching pair, so that the client memory handle can be returned.
1915 HGLOBAL client_hMem
;
1916 HGLOBAL server_hMem
;
1919 static struct DDE_pair
* dde_pairs
;
1920 static int dde_num_alloc
;
1921 static int dde_num_used
;
1923 static CRITICAL_SECTION dde_crst
;
1924 static CRITICAL_SECTION_DEBUG critsect_debug
=
1927 { &critsect_debug
.ProcessLocksList
, &critsect_debug
.ProcessLocksList
},
1928 0, 0, { (DWORD_PTR
)(__FILE__
": dde_crst") }
1930 static CRITICAL_SECTION dde_crst
= { &critsect_debug
, -1, 0, 0, 0, 0 };
1932 static BOOL
dde_add_pair(HGLOBAL chm
, HGLOBAL shm
)
1937 EnterCriticalSection(&dde_crst
);
1939 /* now remember the pair of hMem on both sides */
1940 if (dde_num_used
== dde_num_alloc
)
1942 struct DDE_pair
* tmp
;
1944 tmp
= HeapReAlloc( GetProcessHeap(), 0, dde_pairs
,
1945 (dde_num_alloc
+ GROWBY
) * sizeof(struct DDE_pair
));
1947 tmp
= HeapAlloc( GetProcessHeap(), 0,
1948 (dde_num_alloc
+ GROWBY
) * sizeof(struct DDE_pair
));
1952 LeaveCriticalSection(&dde_crst
);
1956 /* zero out newly allocated part */
1957 memset(&dde_pairs
[dde_num_alloc
], 0, GROWBY
* sizeof(struct DDE_pair
));
1958 dde_num_alloc
+= GROWBY
;
1961 for (i
= 0; i
< dde_num_alloc
; i
++)
1963 if (dde_pairs
[i
].server_hMem
== 0)
1965 dde_pairs
[i
].client_hMem
= chm
;
1966 dde_pairs
[i
].server_hMem
= shm
;
1971 LeaveCriticalSection(&dde_crst
);
1975 static HGLOBAL
dde_get_pair(HGLOBAL shm
)
1980 EnterCriticalSection(&dde_crst
);
1981 for (i
= 0; i
< dde_num_alloc
; i
++)
1983 if (dde_pairs
[i
].server_hMem
== shm
)
1985 /* free this pair */
1986 dde_pairs
[i
].server_hMem
= 0;
1988 ret
= dde_pairs
[i
].client_hMem
;
1992 LeaveCriticalSection(&dde_crst
);
1996 /***********************************************************************
1999 * Post a DDE message
2001 static BOOL
post_dde_message( struct packed_message
*data
, const struct send_message_info
*info
)
2005 UINT_PTR uiLo
, uiHi
;
2007 HGLOBAL hunlock
= 0;
2012 if (!UnpackDDElParam( info
->msg
, info
->lparam
, &uiLo
, &uiHi
))
2018 /* DDE messages which don't require packing are:
2027 /* uiHi should contain a hMem from WM_DDE_EXECUTE */
2028 HGLOBAL h
= dde_get_pair( (HANDLE
)uiHi
);
2031 hpack
= pack_ptr( h
);
2032 /* send back the value of h on the other side */
2033 push_data( data
, &hpack
, sizeof(hpack
) );
2035 TRACE( "send dde-ack %lx %08lx => %p\n", uiLo
, uiHi
, h
);
2040 /* uiHi should contain either an atom or 0 */
2041 TRACE( "send dde-ack %lx atom=%lx\n", uiLo
, uiHi
);
2042 lp
= MAKELONG( uiLo
, uiHi
);
2051 size
= GlobalSize( (HGLOBAL
)uiLo
) ;
2052 if ((info
->msg
== WM_DDE_ADVISE
&& size
< sizeof(DDEADVISE
)) ||
2053 (info
->msg
== WM_DDE_DATA
&& size
< FIELD_OFFSET(DDEDATA
, Value
)) ||
2054 (info
->msg
== WM_DDE_POKE
&& size
< FIELD_OFFSET(DDEPOKE
, Value
))
2058 else if (info
->msg
!= WM_DDE_DATA
) return FALSE
;
2063 if ((ptr
= GlobalLock( (HGLOBAL
)uiLo
) ))
2065 DDEDATA
*dde_data
= ptr
;
2066 TRACE("unused %d, fResponse %d, fRelease %d, fDeferUpd %d, fAckReq %d, cfFormat %d\n",
2067 dde_data
->unused
, dde_data
->fResponse
, dde_data
->fRelease
,
2068 dde_data
->reserved
, dde_data
->fAckReq
, dde_data
->cfFormat
);
2069 push_data( data
, ptr
, size
);
2070 hunlock
= (HGLOBAL
)uiLo
;
2073 TRACE( "send ddepack %u %lx\n", size
, uiHi
);
2075 case WM_DDE_EXECUTE
:
2078 if ((ptr
= GlobalLock( (HGLOBAL
)info
->lparam
) ))
2080 push_data(data
, ptr
, GlobalSize( (HGLOBAL
)info
->lparam
));
2081 /* so that the other side can send it back on ACK */
2083 hunlock
= (HGLOBAL
)info
->lparam
;
2088 SERVER_START_REQ( send_message
)
2090 req
->id
= info
->dest_tid
;
2091 req
->type
= info
->type
;
2093 req
->win
= wine_server_user_handle( info
->hwnd
);
2094 req
->msg
= info
->msg
;
2095 req
->wparam
= info
->wparam
;
2097 req
->timeout
= TIMEOUT_INFINITE
;
2098 for (i
= 0; i
< data
->count
; i
++)
2099 wine_server_add_data( req
, data
->data
[i
], data
->size
[i
] );
2100 if ((res
= wine_server_call( req
)))
2102 if (res
== STATUS_INVALID_PARAMETER
)
2103 /* FIXME: find a STATUS_ value for this one */
2104 SetLastError( ERROR_INVALID_THREAD_ID
);
2106 SetLastError( RtlNtStatusToDosError(res
) );
2109 FreeDDElParam(info
->msg
, info
->lparam
);
2112 if (hunlock
) GlobalUnlock(hunlock
);
2117 /***********************************************************************
2118 * unpack_dde_message
2120 * Unpack a posted DDE message received from another process.
2122 static BOOL
unpack_dde_message( HWND hwnd
, UINT message
, WPARAM
*wparam
, LPARAM
*lparam
,
2123 void **buffer
, size_t size
)
2125 UINT_PTR uiLo
, uiHi
;
2135 /* hMem is being passed */
2136 if (size
!= sizeof(hpack
)) return FALSE
;
2137 if (!buffer
|| !*buffer
) return FALSE
;
2139 memcpy( &hpack
, *buffer
, size
);
2140 hMem
= unpack_ptr( hpack
);
2141 uiHi
= (UINT_PTR
)hMem
;
2142 TRACE("recv dde-ack %lx mem=%lx[%lx]\n", uiLo
, uiHi
, GlobalSize( hMem
));
2146 uiLo
= LOWORD( *lparam
);
2147 uiHi
= HIWORD( *lparam
);
2148 TRACE("recv dde-ack %lx atom=%lx\n", uiLo
, uiHi
);
2150 *lparam
= PackDDElParam( WM_DDE_ACK
, uiLo
, uiHi
);
2155 if ((!buffer
|| !*buffer
) && message
!= WM_DDE_DATA
) return FALSE
;
2159 if (!(hMem
= GlobalAlloc( GMEM_MOVEABLE
|GMEM_DDESHARE
, size
)))
2161 if ((ptr
= GlobalLock( hMem
)))
2163 memcpy( ptr
, *buffer
, size
);
2164 GlobalUnlock( hMem
);
2172 uiLo
= (UINT_PTR
)hMem
;
2174 *lparam
= PackDDElParam( message
, uiLo
, uiHi
);
2176 case WM_DDE_EXECUTE
:
2179 if (!buffer
|| !*buffer
) return FALSE
;
2180 if (!(hMem
= GlobalAlloc( GMEM_MOVEABLE
|GMEM_DDESHARE
, size
))) return FALSE
;
2181 if ((ptr
= GlobalLock( hMem
)))
2183 memcpy( ptr
, *buffer
, size
);
2184 GlobalUnlock( hMem
);
2185 TRACE( "exec: pairing c=%08lx s=%p\n", *lparam
, hMem
);
2186 if (!dde_add_pair( (HGLOBAL
)*lparam
, hMem
))
2197 } else return FALSE
;
2198 *lparam
= (LPARAM
)hMem
;
2204 /***********************************************************************
2207 * Call a window procedure and the corresponding hooks.
2209 static LRESULT
call_window_proc( HWND hwnd
, UINT msg
, WPARAM wparam
, LPARAM lparam
,
2210 BOOL unicode
, BOOL same_thread
, enum wm_char_mapping mapping
)
2214 CWPRETSTRUCT cwpret
;
2216 if (msg
& 0x80000000)
2218 result
= handle_internal_message( hwnd
, msg
, wparam
, lparam
);
2222 /* first the WH_CALLWNDPROC hook */
2223 hwnd
= WIN_GetFullHandle( hwnd
);
2224 cwp
.lParam
= lparam
;
2225 cwp
.wParam
= wparam
;
2228 HOOK_CallHooks( WH_CALLWNDPROC
, HC_ACTION
, same_thread
, (LPARAM
)&cwp
, unicode
);
2230 /* now call the window procedure */
2231 if (!WINPROC_call_window( hwnd
, msg
, wparam
, lparam
, &result
, unicode
, mapping
)) goto done
;
2233 /* and finally the WH_CALLWNDPROCRET hook */
2234 cwpret
.lResult
= result
;
2235 cwpret
.lParam
= lparam
;
2236 cwpret
.wParam
= wparam
;
2237 cwpret
.message
= msg
;
2239 HOOK_CallHooks( WH_CALLWNDPROCRET
, HC_ACTION
, same_thread
, (LPARAM
)&cwpret
, unicode
);
2245 /***********************************************************************
2246 * send_parent_notify
2248 * Send a WM_PARENTNOTIFY to all ancestors of the given window, unless
2249 * the window has the WS_EX_NOPARENTNOTIFY style.
2251 static void send_parent_notify( HWND hwnd
, WORD event
, WORD idChild
, POINT pt
)
2253 /* pt has to be in the client coordinates of the parent window */
2254 MapWindowPoints( 0, hwnd
, &pt
, 1 );
2259 if (!(GetWindowLongW( hwnd
, GWL_STYLE
) & WS_CHILD
)) break;
2260 if (GetWindowLongW( hwnd
, GWL_EXSTYLE
) & WS_EX_NOPARENTNOTIFY
) break;
2261 if (!(parent
= GetParent(hwnd
))) break;
2262 if (parent
== GetDesktopWindow()) break;
2263 MapWindowPoints( hwnd
, parent
, &pt
, 1 );
2265 SendMessageW( hwnd
, WM_PARENTNOTIFY
,
2266 MAKEWPARAM( event
, idChild
), MAKELPARAM( pt
.x
, pt
.y
) );
2271 /***********************************************************************
2272 * accept_hardware_message
2274 * Tell the server we have passed the message to the app
2275 * (even though we may end up dropping it later on)
2277 static void accept_hardware_message( UINT hw_id
)
2279 SERVER_START_REQ( accept_hardware_message
)
2282 if (wine_server_call( req
))
2283 FIXME("Failed to reply to MSG_HARDWARE message. Message may not be removed from queue.\n");
2289 static BOOL
process_rawinput_message( MSG
*msg
, UINT hw_id
, const struct hardware_msg_data
*msg_data
)
2291 struct rawinput_thread_data
*thread_data
= rawinput_thread_data();
2293 if (msg
->message
== WM_INPUT_DEVICE_CHANGE
)
2294 rawinput_update_device_list();
2297 thread_data
->buffer
->header
.dwSize
= RAWINPUT_BUFFER_SIZE
;
2298 if (!rawinput_from_hardware_message( thread_data
->buffer
, msg_data
)) return FALSE
;
2299 thread_data
->hw_id
= hw_id
;
2300 msg
->lParam
= (LPARAM
)hw_id
;
2303 msg
->pt
= point_phys_to_win_dpi( msg
->hwnd
, msg
->pt
);
2307 /***********************************************************************
2308 * process_keyboard_message
2310 * returns TRUE if the contents of 'msg' should be passed to the application
2312 static BOOL
process_keyboard_message( MSG
*msg
, UINT hw_id
, HWND hwnd_filter
,
2313 UINT first
, UINT last
, BOOL remove
)
2317 if (msg
->message
== WM_KEYDOWN
|| msg
->message
== WM_SYSKEYDOWN
||
2318 msg
->message
== WM_KEYUP
|| msg
->message
== WM_SYSKEYUP
)
2319 switch (msg
->wParam
)
2321 case VK_LSHIFT
: case VK_RSHIFT
:
2322 msg
->wParam
= VK_SHIFT
;
2324 case VK_LCONTROL
: case VK_RCONTROL
:
2325 msg
->wParam
= VK_CONTROL
;
2327 case VK_LMENU
: case VK_RMENU
:
2328 msg
->wParam
= VK_MENU
;
2332 /* FIXME: is this really the right place for this hook? */
2333 event
.message
= msg
->message
;
2334 event
.hwnd
= msg
->hwnd
;
2335 event
.time
= msg
->time
;
2336 event
.paramL
= (msg
->wParam
& 0xFF) | (HIWORD(msg
->lParam
) << 8);
2337 event
.paramH
= msg
->lParam
& 0x7FFF;
2338 if (HIWORD(msg
->lParam
) & 0x0100) event
.paramH
|= 0x8000; /* special_key - bit */
2339 HOOK_CallHooks( WH_JOURNALRECORD
, HC_ACTION
, 0, (LPARAM
)&event
, TRUE
);
2341 /* check message filters */
2342 if (msg
->message
< first
|| msg
->message
> last
) return FALSE
;
2343 if (!check_hwnd_filter( msg
, hwnd_filter
)) return FALSE
;
2347 if((msg
->message
== WM_KEYDOWN
) &&
2348 (msg
->hwnd
!= GetDesktopWindow()))
2350 /* Handle F1 key by sending out WM_HELP message */
2351 if (msg
->wParam
== VK_F1
)
2353 PostMessageW( msg
->hwnd
, WM_KEYF1
, 0, 0 );
2355 else if(msg
->wParam
>= VK_BROWSER_BACK
&&
2356 msg
->wParam
<= VK_LAUNCH_APP2
)
2358 /* FIXME: Process keystate */
2359 SendMessageW(msg
->hwnd
, WM_APPCOMMAND
, (WPARAM
)msg
->hwnd
, MAKELPARAM(0, (FAPPCOMMAND_KEY
| (msg
->wParam
- VK_BROWSER_BACK
+ 1))));
2362 else if (msg
->message
== WM_KEYUP
)
2364 /* Handle VK_APPS key by posting a WM_CONTEXTMENU message */
2365 if (msg
->wParam
== VK_APPS
&& !MENU_IsMenuActive())
2366 PostMessageW(msg
->hwnd
, WM_CONTEXTMENU
, (WPARAM
)msg
->hwnd
, -1);
2370 if (HOOK_CallHooks( WH_KEYBOARD
, remove
? HC_ACTION
: HC_NOREMOVE
,
2371 LOWORD(msg
->wParam
), msg
->lParam
, TRUE
))
2373 /* skip this message */
2374 HOOK_CallHooks( WH_CBT
, HCBT_KEYSKIPPED
, LOWORD(msg
->wParam
), msg
->lParam
, TRUE
);
2375 accept_hardware_message( hw_id
);
2378 if (remove
) accept_hardware_message( hw_id
);
2379 msg
->pt
= point_phys_to_win_dpi( msg
->hwnd
, msg
->pt
);
2381 if ( remove
&& msg
->message
== WM_KEYDOWN
)
2382 if (ImmProcessKey(msg
->hwnd
, NtUserGetKeyboardLayout(0), msg
->wParam
, msg
->lParam
, 0) )
2383 msg
->wParam
= VK_PROCESSKEY
;
2389 /***********************************************************************
2390 * process_mouse_message
2392 * returns TRUE if the contents of 'msg' should be passed to the application
2394 static BOOL
process_mouse_message( MSG
*msg
, UINT hw_id
, ULONG_PTR extra_info
, HWND hwnd_filter
,
2395 UINT first
, UINT last
, BOOL remove
)
2404 MOUSEHOOKSTRUCTEX hook
;
2408 /* find the window to dispatch this mouse message to */
2410 info
.cbSize
= sizeof(info
);
2411 GetGUIThreadInfo( GetCurrentThreadId(), &info
);
2412 if (info
.hwndCapture
)
2415 msg
->hwnd
= info
.hwndCapture
;
2419 HWND orig
= msg
->hwnd
;
2421 msg
->hwnd
= WINPOS_WindowFromPoint( msg
->hwnd
, msg
->pt
, &hittest
);
2422 if (!msg
->hwnd
) /* As a heuristic, try the next window if it's the owner of orig */
2424 HWND next
= GetWindow( orig
, GW_HWNDNEXT
);
2426 if (next
&& GetWindow( orig
, GW_OWNER
) == next
&& WIN_IsCurrentThread( next
))
2427 msg
->hwnd
= WINPOS_WindowFromPoint( next
, msg
->pt
, &hittest
);
2431 if (!msg
->hwnd
|| !WIN_IsCurrentThread( msg
->hwnd
))
2433 accept_hardware_message( hw_id
);
2437 msg
->pt
= point_phys_to_win_dpi( msg
->hwnd
, msg
->pt
);
2438 SetThreadDpiAwarenessContext( GetWindowDpiAwarenessContext( msg
->hwnd
));
2440 /* FIXME: is this really the right place for this hook? */
2441 event
.message
= msg
->message
;
2442 event
.time
= msg
->time
;
2443 event
.hwnd
= msg
->hwnd
;
2444 event
.paramL
= msg
->pt
.x
;
2445 event
.paramH
= msg
->pt
.y
;
2446 HOOK_CallHooks( WH_JOURNALRECORD
, HC_ACTION
, 0, (LPARAM
)&event
, TRUE
);
2448 if (!check_hwnd_filter( msg
, hwnd_filter
)) return FALSE
;
2451 message
= msg
->message
;
2452 wparam
= msg
->wParam
;
2453 /* Note: windows has no concept of a non-client wheel message */
2454 if (message
!= WM_MOUSEWHEEL
)
2456 if (hittest
!= HTCLIENT
)
2458 message
+= WM_NCMOUSEMOVE
- WM_MOUSEMOVE
;
2463 /* coordinates don't get translated while tracking a menu */
2464 /* FIXME: should differentiate popups and top-level menus */
2465 if (!(info
.flags
& GUI_INMENUMODE
))
2466 ScreenToClient( msg
->hwnd
, &pt
);
2469 msg
->lParam
= MAKELONG( pt
.x
, pt
.y
);
2471 /* translate double clicks */
2473 if ((msg
->message
== WM_LBUTTONDOWN
) ||
2474 (msg
->message
== WM_RBUTTONDOWN
) ||
2475 (msg
->message
== WM_MBUTTONDOWN
) ||
2476 (msg
->message
== WM_XBUTTONDOWN
))
2478 BOOL update
= remove
;
2480 /* translate double clicks -
2481 * note that ...MOUSEMOVEs can slip in between
2482 * ...BUTTONDOWN and ...BUTTONDBLCLK messages */
2484 if ((info
.flags
& (GUI_INMENUMODE
|GUI_INMOVESIZE
)) ||
2485 hittest
!= HTCLIENT
||
2486 (GetClassLongA( msg
->hwnd
, GCL_STYLE
) & CS_DBLCLKS
))
2488 if ((msg
->message
== clk_msg
.message
) &&
2489 (msg
->hwnd
== clk_msg
.hwnd
) &&
2490 (msg
->wParam
== clk_msg
.wParam
) &&
2491 (msg
->time
- clk_msg
.time
< NtUserGetDoubleClickTime()) &&
2492 (abs(msg
->pt
.x
- clk_msg
.pt
.x
) < GetSystemMetrics(SM_CXDOUBLECLK
)/2) &&
2493 (abs(msg
->pt
.y
- clk_msg
.pt
.y
) < GetSystemMetrics(SM_CYDOUBLECLK
)/2))
2495 message
+= (WM_LBUTTONDBLCLK
- WM_LBUTTONDOWN
);
2498 clk_msg
.message
= 0; /* clear the double click conditions */
2503 if (message
< first
|| message
> last
) return FALSE
;
2504 /* update static double click conditions */
2505 if (update
) clk_msg
= *msg
;
2509 if (message
< first
|| message
> last
) return FALSE
;
2511 msg
->wParam
= wparam
;
2513 /* message is accepted now (but may still get dropped) */
2515 hook
.s
.pt
= msg
->pt
;
2516 hook
.s
.hwnd
= msg
->hwnd
;
2517 hook
.s
.wHitTestCode
= hittest
;
2518 hook
.s
.dwExtraInfo
= extra_info
;
2519 hook
.mouseData
= msg
->wParam
;
2520 if (HOOK_CallHooks( WH_MOUSE
, remove
? HC_ACTION
: HC_NOREMOVE
,
2521 message
, (LPARAM
)&hook
, TRUE
))
2523 hook
.s
.pt
= msg
->pt
;
2524 hook
.s
.hwnd
= msg
->hwnd
;
2525 hook
.s
.wHitTestCode
= hittest
;
2526 hook
.s
.dwExtraInfo
= extra_info
;
2527 hook
.mouseData
= msg
->wParam
;
2528 HOOK_CallHooks( WH_CBT
, HCBT_CLICKSKIPPED
, message
, (LPARAM
)&hook
, TRUE
);
2529 accept_hardware_message( hw_id
);
2533 if ((hittest
== HTERROR
) || (hittest
== HTNOWHERE
))
2535 SendMessageW( msg
->hwnd
, WM_SETCURSOR
, (WPARAM
)msg
->hwnd
,
2536 MAKELONG( hittest
, msg
->message
));
2537 accept_hardware_message( hw_id
);
2541 if (remove
) accept_hardware_message( hw_id
);
2543 if (!remove
|| info
.hwndCapture
)
2545 msg
->message
= message
;
2551 if ((msg
->message
== WM_LBUTTONDOWN
) ||
2552 (msg
->message
== WM_RBUTTONDOWN
) ||
2553 (msg
->message
== WM_MBUTTONDOWN
) ||
2554 (msg
->message
== WM_XBUTTONDOWN
))
2556 /* Send the WM_PARENTNOTIFY,
2557 * note that even for double/nonclient clicks
2558 * notification message is still WM_L/M/RBUTTONDOWN.
2560 send_parent_notify( msg
->hwnd
, msg
->message
, 0, msg
->pt
);
2562 /* Activate the window if needed */
2564 if (msg
->hwnd
!= info
.hwndActive
)
2566 HWND hwndTop
= GetAncestor( msg
->hwnd
, GA_ROOT
);
2568 if ((GetWindowLongW( hwndTop
, GWL_STYLE
) & (WS_POPUP
|WS_CHILD
)) != WS_CHILD
)
2570 LONG ret
= SendMessageW( msg
->hwnd
, WM_MOUSEACTIVATE
, (WPARAM
)hwndTop
,
2571 MAKELONG( hittest
, msg
->message
) );
2574 case MA_NOACTIVATEANDEAT
:
2579 case MA_ACTIVATEANDEAT
:
2584 if (!FOCUS_MouseActivate( hwndTop
)) eatMsg
= TRUE
;
2587 WARN( "unknown WM_MOUSEACTIVATE code %d\n", ret
);
2594 /* send the WM_SETCURSOR message */
2596 /* Windows sends the normal mouse message as the message parameter
2597 in the WM_SETCURSOR message even if it's non-client mouse message */
2598 SendMessageW( msg
->hwnd
, WM_SETCURSOR
, (WPARAM
)msg
->hwnd
, MAKELONG( hittest
, msg
->message
));
2600 msg
->message
= message
;
2605 /***********************************************************************
2606 * process_hardware_message
2608 * Process a hardware message; return TRUE if message should be passed on to the app
2610 static BOOL
process_hardware_message( MSG
*msg
, UINT hw_id
, const struct hardware_msg_data
*msg_data
,
2611 HWND hwnd_filter
, UINT first
, UINT last
, BOOL remove
)
2613 DPI_AWARENESS_CONTEXT context
;
2616 get_user_thread_info()->msg_source
.deviceType
= msg_data
->source
.device
;
2617 get_user_thread_info()->msg_source
.originId
= msg_data
->source
.origin
;
2619 /* hardware messages are always in physical coords */
2620 context
= SetThreadDpiAwarenessContext( DPI_AWARENESS_CONTEXT_PER_MONITOR_AWARE
);
2622 if (msg
->message
== WM_INPUT
|| msg
->message
== WM_INPUT_DEVICE_CHANGE
)
2623 ret
= process_rawinput_message( msg
, hw_id
, msg_data
);
2624 else if (is_keyboard_message( msg
->message
))
2625 ret
= process_keyboard_message( msg
, hw_id
, hwnd_filter
, first
, last
, remove
);
2626 else if (is_mouse_message( msg
->message
))
2627 ret
= process_mouse_message( msg
, hw_id
, msg_data
->info
, hwnd_filter
, first
, last
, remove
);
2629 ERR( "unknown message type %x\n", msg
->message
);
2630 SetThreadDpiAwarenessContext( context
);
2635 /***********************************************************************
2636 * call_sendmsg_callback
2638 * Call the callback function of SendMessageCallback.
2640 static inline void call_sendmsg_callback( SENDASYNCPROC callback
, HWND hwnd
, UINT msg
,
2641 ULONG_PTR data
, LRESULT result
)
2643 if (!callback
) return;
2645 TRACE_(relay
)( "\1Call message callback %p (hwnd=%p,msg=%s,data=%08lx,result=%08lx)\n",
2646 callback
, hwnd
, SPY_GetMsgName( msg
, hwnd
), data
, result
);
2647 callback( hwnd
, msg
, data
, result
);
2648 TRACE_(relay
)( "\1Ret message callback %p (hwnd=%p,msg=%s,data=%08lx,result=%08lx)\n",
2649 callback
, hwnd
, SPY_GetMsgName( msg
, hwnd
), data
, result
);
2653 /***********************************************************************
2656 * Peek for a message matching the given parameters. Return 0 if none are
2657 * available; -1 on error.
2658 * All pending sent messages are processed before returning.
2660 static int peek_message( MSG
*msg
, HWND hwnd
, UINT first
, UINT last
, UINT flags
, UINT changed_mask
)
2663 struct user_thread_info
*thread_info
= get_user_thread_info();
2664 INPUT_MESSAGE_SOURCE prev_source
= thread_info
->msg_source
;
2665 struct received_message_info info
, *old_info
;
2666 unsigned int hw_id
= 0; /* id of previous hardware message */
2668 size_t buffer_size
= 1024;
2670 if (!(buffer
= HeapAlloc( GetProcessHeap(), 0, buffer_size
))) return -1;
2672 if (!first
&& !last
) last
= ~0;
2673 if (hwnd
== HWND_BROADCAST
) hwnd
= HWND_TOPMOST
;
2679 const message_data_t
*msg_data
= buffer
;
2681 thread_info
->msg_source
= prev_source
;
2683 SERVER_START_REQ( get_message
)
2686 req
->get_win
= wine_server_user_handle( hwnd
);
2687 req
->get_first
= first
;
2688 req
->get_last
= last
;
2690 req
->wake_mask
= changed_mask
& (QS_SENDMESSAGE
| QS_SMRESULT
);
2691 req
->changed_mask
= changed_mask
;
2692 wine_server_set_reply( req
, buffer
, buffer_size
);
2693 if (!(res
= wine_server_call( req
)))
2695 size
= wine_server_reply_size( reply
);
2696 info
.type
= reply
->type
;
2697 info
.msg
.hwnd
= wine_server_ptr_handle( reply
->win
);
2698 info
.msg
.message
= reply
->msg
;
2699 info
.msg
.wParam
= reply
->wparam
;
2700 info
.msg
.lParam
= reply
->lparam
;
2701 info
.msg
.time
= reply
->time
;
2702 info
.msg
.pt
.x
= reply
->x
;
2703 info
.msg
.pt
.y
= reply
->y
;
2705 thread_info
->active_hooks
= reply
->active_hooks
;
2707 else buffer_size
= reply
->total
;
2713 HeapFree( GetProcessHeap(), 0, buffer
);
2714 if (res
== STATUS_PENDING
)
2716 thread_info
->wake_mask
= changed_mask
& (QS_SENDMESSAGE
| QS_SMRESULT
);
2717 thread_info
->changed_mask
= changed_mask
;
2720 if (res
!= STATUS_BUFFER_OVERFLOW
)
2722 SetLastError( RtlNtStatusToDosError(res
) );
2725 if (!(buffer
= HeapAlloc( GetProcessHeap(), 0, buffer_size
))) return -1;
2729 TRACE( "got type %d msg %x (%s) hwnd %p wp %lx lp %lx\n",
2730 info
.type
, info
.msg
.message
,
2731 (info
.type
== MSG_WINEVENT
) ? "MSG_WINEVENT" : SPY_GetMsgName(info
.msg
.message
, info
.msg
.hwnd
),
2732 info
.msg
.hwnd
, info
.msg
.wParam
, info
.msg
.lParam
);
2738 info
.flags
= ISMEX_SEND
;
2741 info
.flags
= ISMEX_NOTIFY
;
2742 if (!unpack_message( info
.msg
.hwnd
, info
.msg
.message
, &info
.msg
.wParam
,
2743 &info
.msg
.lParam
, &buffer
, size
))
2747 info
.flags
= ISMEX_CALLBACK
;
2749 case MSG_CALLBACK_RESULT
:
2750 if (size
>= sizeof(msg_data
->callback
))
2751 call_sendmsg_callback( wine_server_get_ptr(msg_data
->callback
.callback
),
2752 info
.msg
.hwnd
, info
.msg
.message
,
2753 msg_data
->callback
.data
, msg_data
->callback
.result
);
2756 if (size
>= sizeof(msg_data
->winevent
))
2758 WINEVENTPROC hook_proc
;
2759 HMODULE free_module
= 0;
2761 hook_proc
= wine_server_get_ptr( msg_data
->winevent
.hook_proc
);
2762 size
-= sizeof(msg_data
->winevent
);
2765 WCHAR module
[MAX_PATH
];
2767 size
= min( size
, (MAX_PATH
- 1) * sizeof(WCHAR
) );
2768 memcpy( module
, &msg_data
->winevent
+ 1, size
);
2769 module
[size
/ sizeof(WCHAR
)] = 0;
2770 if (!(hook_proc
= get_hook_proc( hook_proc
, module
, &free_module
)))
2772 ERR( "invalid winevent hook module name %s\n", debugstr_w(module
) );
2777 TRACE_(relay
)( "\1Call winevent proc %p (hook=%04x,event=%x,hwnd=%p,object_id=%lx,child_id=%lx,tid=%04x,time=%x)\n",
2778 hook_proc
, msg_data
->winevent
.hook
, info
.msg
.message
, info
.msg
.hwnd
,
2779 info
.msg
.wParam
, info
.msg
.lParam
, msg_data
->winevent
.tid
, info
.msg
.time
);
2781 hook_proc( wine_server_ptr_handle( msg_data
->winevent
.hook
), info
.msg
.message
,
2782 info
.msg
.hwnd
, info
.msg
.wParam
, info
.msg
.lParam
,
2783 msg_data
->winevent
.tid
, info
.msg
.time
);
2785 TRACE_(relay
)( "\1Ret winevent proc %p (hook=%04x,event=%x,hwnd=%p,object_id=%lx,child_id=%lx,tid=%04x,time=%x)\n",
2786 hook_proc
, msg_data
->winevent
.hook
, info
.msg
.message
, info
.msg
.hwnd
,
2787 info
.msg
.wParam
, info
.msg
.lParam
, msg_data
->winevent
.tid
, info
.msg
.time
);
2789 if (free_module
) FreeLibrary(free_module
);
2793 info
.flags
= ISMEX_SEND
;
2795 if (info
.msg
.message
== WH_KEYBOARD_LL
&& size
>= sizeof(msg_data
->hardware
))
2797 KBDLLHOOKSTRUCT hook
;
2799 hook
.vkCode
= LOWORD( info
.msg
.lParam
);
2800 hook
.scanCode
= HIWORD( info
.msg
.lParam
);
2801 hook
.flags
= msg_data
->hardware
.flags
;
2802 hook
.time
= info
.msg
.time
;
2803 hook
.dwExtraInfo
= msg_data
->hardware
.info
;
2804 TRACE( "calling keyboard LL hook vk %x scan %x flags %x time %u info %lx\n",
2805 hook
.vkCode
, hook
.scanCode
, hook
.flags
, hook
.time
, hook
.dwExtraInfo
);
2806 result
= HOOK_CallHooks( WH_KEYBOARD_LL
, HC_ACTION
, info
.msg
.wParam
, (LPARAM
)&hook
, TRUE
);
2808 else if (info
.msg
.message
== WH_MOUSE_LL
&& size
>= sizeof(msg_data
->hardware
))
2810 MSLLHOOKSTRUCT hook
;
2812 hook
.pt
= info
.msg
.pt
;
2813 hook
.mouseData
= info
.msg
.lParam
;
2814 hook
.flags
= msg_data
->hardware
.flags
;
2815 hook
.time
= info
.msg
.time
;
2816 hook
.dwExtraInfo
= msg_data
->hardware
.info
;
2817 TRACE( "calling mouse LL hook pos %d,%d data %x flags %x time %u info %lx\n",
2818 hook
.pt
.x
, hook
.pt
.y
, hook
.mouseData
, hook
.flags
, hook
.time
, hook
.dwExtraInfo
);
2819 result
= HOOK_CallHooks( WH_MOUSE_LL
, HC_ACTION
, info
.msg
.wParam
, (LPARAM
)&hook
, TRUE
);
2821 reply_message( &info
, result
, TRUE
);
2823 case MSG_OTHER_PROCESS
:
2824 info
.flags
= ISMEX_SEND
;
2825 if (!unpack_message( info
.msg
.hwnd
, info
.msg
.message
, &info
.msg
.wParam
,
2826 &info
.msg
.lParam
, &buffer
, size
))
2829 reply_message( &info
, 0, TRUE
);
2834 if (size
>= sizeof(msg_data
->hardware
))
2836 hw_id
= msg_data
->hardware
.hw_id
;
2837 if (!process_hardware_message( &info
.msg
, hw_id
, &msg_data
->hardware
,
2838 hwnd
, first
, last
, flags
& PM_REMOVE
))
2840 TRACE("dropping msg %x\n", info
.msg
.message
);
2841 continue; /* ignore it */
2844 thread_info
->GetMessagePosVal
= MAKELONG( info
.msg
.pt
.x
, info
.msg
.pt
.y
);
2845 thread_info
->GetMessageTimeVal
= info
.msg
.time
;
2846 thread_info
->GetMessageExtraInfoVal
= msg_data
->hardware
.info
;
2847 HeapFree( GetProcessHeap(), 0, buffer
);
2848 HOOK_CallHooks( WH_GETMESSAGE
, HC_ACTION
, flags
& PM_REMOVE
, (LPARAM
)msg
, TRUE
);
2853 if (info
.msg
.message
& 0x80000000) /* internal message */
2855 if (flags
& PM_REMOVE
)
2857 handle_internal_message( info
.msg
.hwnd
, info
.msg
.message
,
2858 info
.msg
.wParam
, info
.msg
.lParam
);
2859 /* if this is a nested call return right away */
2860 if (first
== info
.msg
.message
&& last
== info
.msg
.message
)
2862 HeapFree( GetProcessHeap(), 0, buffer
);
2867 peek_message( msg
, info
.msg
.hwnd
, info
.msg
.message
,
2868 info
.msg
.message
, flags
| PM_REMOVE
, changed_mask
);
2871 if (info
.msg
.message
>= WM_DDE_FIRST
&& info
.msg
.message
<= WM_DDE_LAST
)
2873 if (!unpack_dde_message( info
.msg
.hwnd
, info
.msg
.message
, &info
.msg
.wParam
,
2874 &info
.msg
.lParam
, &buffer
, size
))
2875 continue; /* ignore it */
2878 msg
->pt
= point_phys_to_win_dpi( info
.msg
.hwnd
, info
.msg
.pt
);
2879 thread_info
->GetMessagePosVal
= MAKELONG( msg
->pt
.x
, msg
->pt
.y
);
2880 thread_info
->GetMessageTimeVal
= info
.msg
.time
;
2881 thread_info
->GetMessageExtraInfoVal
= 0;
2882 thread_info
->msg_source
= msg_source_unavailable
;
2883 HeapFree( GetProcessHeap(), 0, buffer
);
2884 HOOK_CallHooks( WH_GETMESSAGE
, HC_ACTION
, flags
& PM_REMOVE
, (LPARAM
)msg
, TRUE
);
2888 /* if we get here, we have a sent message; call the window procedure */
2889 old_info
= thread_info
->receive_info
;
2890 thread_info
->receive_info
= &info
;
2891 thread_info
->msg_source
= msg_source_unavailable
;
2892 result
= call_window_proc( info
.msg
.hwnd
, info
.msg
.message
, info
.msg
.wParam
,
2893 info
.msg
.lParam
, (info
.type
!= MSG_ASCII
), FALSE
,
2894 WMCHAR_MAP_RECVMESSAGE
);
2895 reply_message( &info
, result
, TRUE
);
2896 thread_info
->receive_info
= old_info
;
2898 /* if some PM_QS* flags were specified, only handle sent messages from now on */
2899 if (HIWORD(flags
) && !changed_mask
) flags
= PM_QS_SENDMESSAGE
| LOWORD(flags
);
2904 /***********************************************************************
2905 * process_sent_messages
2907 * Process all pending sent messages.
2909 static inline void process_sent_messages(void)
2912 peek_message( &msg
, 0, 0, 0, PM_REMOVE
| PM_QS_SENDMESSAGE
, 0 );
2916 /***********************************************************************
2917 * get_server_queue_handle
2919 * Get a handle to the server message queue for the current thread.
2921 static HANDLE
get_server_queue_handle(void)
2923 struct user_thread_info
*thread_info
= get_user_thread_info();
2926 if (!(ret
= thread_info
->server_queue
))
2928 SERVER_START_REQ( get_msg_queue
)
2930 wine_server_call( req
);
2931 ret
= wine_server_ptr_handle( reply
->handle
);
2934 thread_info
->server_queue
= ret
;
2935 if (!ret
) ERR( "Cannot get server thread queue\n" );
2941 /***********************************************************************
2942 * wait_message_reply
2944 * Wait until a sent message gets replied to.
2946 static void wait_message_reply( UINT flags
)
2948 struct user_thread_info
*thread_info
= get_user_thread_info();
2949 HANDLE server_queue
= get_server_queue_handle();
2950 unsigned int wake_mask
= QS_SMRESULT
| ((flags
& SMTO_BLOCK
) ? 0 : QS_SENDMESSAGE
);
2954 unsigned int wake_bits
= 0;
2956 SERVER_START_REQ( set_queue_mask
)
2958 req
->wake_mask
= wake_mask
;
2959 req
->changed_mask
= wake_mask
;
2961 if (!wine_server_call( req
)) wake_bits
= reply
->wake_bits
& wake_mask
;
2965 thread_info
->wake_mask
= thread_info
->changed_mask
= 0;
2967 if (wake_bits
& QS_SMRESULT
) return; /* got a result */
2968 if (wake_bits
& QS_SENDMESSAGE
)
2970 /* Process the sent message immediately */
2971 process_sent_messages();
2975 wow_handlers
.wait_message( 1, &server_queue
, INFINITE
, wake_mask
, 0 );
2980 /***********************************************************************
2983 * Wait for multiple objects including the server queue, with specific queue masks.
2985 static DWORD
wait_objects( DWORD count
, const HANDLE
*handles
, DWORD timeout
,
2986 DWORD wake_mask
, DWORD changed_mask
, DWORD flags
)
2988 struct user_thread_info
*thread_info
= get_user_thread_info();
2991 assert( count
); /* we must have at least the server queue */
2993 flush_window_surfaces( TRUE
);
2995 if (thread_info
->wake_mask
!= wake_mask
|| thread_info
->changed_mask
!= changed_mask
)
2997 SERVER_START_REQ( set_queue_mask
)
2999 req
->wake_mask
= wake_mask
;
3000 req
->changed_mask
= changed_mask
;
3002 wine_server_call( req
);
3005 thread_info
->wake_mask
= wake_mask
;
3006 thread_info
->changed_mask
= changed_mask
;
3009 ret
= wow_handlers
.wait_message( count
, handles
, timeout
, changed_mask
, flags
);
3011 if (ret
!= WAIT_TIMEOUT
) thread_info
->wake_mask
= thread_info
->changed_mask
= 0;
3016 /***********************************************************************
3017 * put_message_in_queue
3019 * Put a sent message into the destination queue.
3020 * For inter-process message, reply_size is set to expected size of reply data.
3022 static BOOL
put_message_in_queue( const struct send_message_info
*info
, size_t *reply_size
)
3024 struct packed_message data
;
3025 message_data_t msg_data
;
3028 timeout_t timeout
= TIMEOUT_INFINITE
;
3030 /* Check for INFINITE timeout for compatibility with Win9x,
3031 * although Windows >= NT does not do so
3033 if (info
->type
!= MSG_NOTIFY
&&
3034 info
->type
!= MSG_CALLBACK
&&
3035 info
->type
!= MSG_POSTED
&&
3037 info
->timeout
!= INFINITE
)
3039 /* timeout is signed despite the prototype */
3040 timeout
= (timeout_t
)max( 0, (int)info
->timeout
) * -10000;
3043 memset( &data
, 0, sizeof(data
) );
3044 if (info
->type
== MSG_OTHER_PROCESS
|| info
->type
== MSG_NOTIFY
)
3046 *reply_size
= pack_message( info
->hwnd
, info
->msg
, info
->wparam
, info
->lparam
, &data
);
3047 if (data
.count
== -1)
3049 WARN( "cannot pack message %x\n", info
->msg
);
3053 else if (info
->type
== MSG_CALLBACK
)
3055 msg_data
.callback
.callback
= wine_server_client_ptr( info
->callback
);
3056 msg_data
.callback
.data
= info
->data
;
3057 msg_data
.callback
.result
= 0;
3058 data
.data
[0] = &msg_data
;
3059 data
.size
[0] = sizeof(msg_data
.callback
);
3062 else if (info
->type
== MSG_POSTED
&& info
->msg
>= WM_DDE_FIRST
&& info
->msg
<= WM_DDE_LAST
)
3064 return post_dde_message( &data
, info
);
3067 SERVER_START_REQ( send_message
)
3069 req
->id
= info
->dest_tid
;
3070 req
->type
= info
->type
;
3072 req
->win
= wine_server_user_handle( info
->hwnd
);
3073 req
->msg
= info
->msg
;
3074 req
->wparam
= info
->wparam
;
3075 req
->lparam
= info
->lparam
;
3076 req
->timeout
= timeout
;
3078 if (info
->flags
& SMTO_ABORTIFHUNG
) req
->flags
|= SEND_MSG_ABORT_IF_HUNG
;
3079 for (i
= 0; i
< data
.count
; i
++) wine_server_add_data( req
, data
.data
[i
], data
.size
[i
] );
3080 if ((res
= wine_server_call( req
)))
3082 if (res
== STATUS_INVALID_PARAMETER
)
3083 /* FIXME: find a STATUS_ value for this one */
3084 SetLastError( ERROR_INVALID_THREAD_ID
);
3086 SetLastError( RtlNtStatusToDosError(res
) );
3094 /***********************************************************************
3097 * Retrieve a message reply from the server.
3099 static LRESULT
retrieve_reply( const struct send_message_info
*info
,
3100 size_t reply_size
, LRESULT
*result
)
3103 void *reply_data
= NULL
;
3107 if (!(reply_data
= HeapAlloc( GetProcessHeap(), 0, reply_size
)))
3109 WARN( "no memory for reply, will be truncated\n" );
3113 SERVER_START_REQ( get_message_reply
)
3116 if (reply_size
) wine_server_set_reply( req
, reply_data
, reply_size
);
3117 if (!(status
= wine_server_call( req
))) *result
= reply
->result
;
3118 reply_size
= wine_server_reply_size( reply
);
3121 if (!status
&& reply_size
)
3122 unpack_reply( info
->hwnd
, info
->msg
, info
->wparam
, info
->lparam
, reply_data
, reply_size
);
3124 HeapFree( GetProcessHeap(), 0, reply_data
);
3126 TRACE( "hwnd %p msg %x (%s) wp %lx lp %lx got reply %lx (err=%d)\n",
3127 info
->hwnd
, info
->msg
, SPY_GetMsgName(info
->msg
, info
->hwnd
), info
->wparam
,
3128 info
->lparam
, *result
, status
);
3130 /* MSDN states that last error is 0 on timeout, but at least NT4 returns ERROR_TIMEOUT */
3131 if (status
) SetLastError( RtlNtStatusToDosError(status
) );
3136 /***********************************************************************
3137 * send_inter_thread_message
3139 static LRESULT
send_inter_thread_message( const struct send_message_info
*info
, LRESULT
*res_ptr
)
3141 size_t reply_size
= 0;
3143 TRACE( "hwnd %p msg %x (%s) wp %lx lp %lx\n",
3144 info
->hwnd
, info
->msg
, SPY_GetMsgName(info
->msg
, info
->hwnd
), info
->wparam
, info
->lparam
);
3146 USER_CheckNotLock();
3148 if (!put_message_in_queue( info
, &reply_size
)) return 0;
3150 /* there's no reply to wait for on notify/callback messages */
3151 if (info
->type
== MSG_NOTIFY
|| info
->type
== MSG_CALLBACK
) return 1;
3153 wait_message_reply( info
->flags
);
3154 return retrieve_reply( info
, reply_size
, res_ptr
);
3158 /***********************************************************************
3159 * send_inter_thread_callback
3161 static LRESULT
send_inter_thread_callback( HWND hwnd
, UINT msg
, WPARAM wp
, LPARAM lp
,
3162 LRESULT
*result
, void *arg
)
3164 struct send_message_info
*info
= arg
;
3169 return send_inter_thread_message( info
, result
);
3172 static BOOL
is_message_broadcastable(UINT msg
)
3174 return msg
< WM_USER
|| msg
>= 0xc000;
3177 /***********************************************************************
3180 * Backend implementation of the various SendMessage functions.
3182 static BOOL
send_message( struct send_message_info
*info
, DWORD_PTR
*res_ptr
, BOOL unicode
)
3184 struct user_thread_info
*thread_info
= get_user_thread_info();
3185 INPUT_MESSAGE_SOURCE prev_source
= thread_info
->msg_source
;
3190 if (is_broadcast(info
->hwnd
))
3192 if (is_message_broadcastable( info
->msg
))
3193 EnumWindows( broadcast_message_callback
, (LPARAM
)info
);
3194 if (res_ptr
) *res_ptr
= 1;
3198 if (!(info
->dest_tid
= GetWindowThreadProcessId( info
->hwnd
, &dest_pid
))) return FALSE
;
3200 if (USER_IsExitingThread( info
->dest_tid
)) return FALSE
;
3202 thread_info
->msg_source
= msg_source_unavailable
;
3203 SPY_EnterMessage( SPY_SENDMESSAGE
, info
->hwnd
, info
->msg
, info
->wparam
, info
->lparam
);
3205 if (info
->dest_tid
== GetCurrentThreadId())
3207 result
= call_window_proc( info
->hwnd
, info
->msg
, info
->wparam
, info
->lparam
,
3208 unicode
, TRUE
, info
->wm_char
);
3209 if (info
->type
== MSG_CALLBACK
)
3210 call_sendmsg_callback( info
->callback
, info
->hwnd
, info
->msg
, info
->data
, result
);
3215 if (dest_pid
!= GetCurrentProcessId() && (info
->type
== MSG_ASCII
|| info
->type
== MSG_UNICODE
))
3216 info
->type
= MSG_OTHER_PROCESS
;
3218 /* MSG_ASCII can be sent unconverted except for WM_CHAR; everything else needs to be Unicode */
3219 if (!unicode
&& is_unicode_message( info
->msg
) &&
3220 (info
->type
!= MSG_ASCII
|| info
->msg
== WM_CHAR
))
3221 ret
= WINPROC_CallProcAtoW( send_inter_thread_callback
, info
->hwnd
, info
->msg
,
3222 info
->wparam
, info
->lparam
, &result
, info
, info
->wm_char
);
3224 ret
= send_inter_thread_message( info
, &result
);
3227 SPY_ExitMessage( SPY_RESULT_OK
, info
->hwnd
, info
->msg
, result
, info
->wparam
, info
->lparam
);
3228 thread_info
->msg_source
= prev_source
;
3229 if (ret
&& res_ptr
) *res_ptr
= result
;
3234 /***********************************************************************
3235 * send_hardware_message
3237 NTSTATUS
send_hardware_message( HWND hwnd
, const INPUT
*input
, const RAWINPUT
*rawinput
, UINT flags
)
3239 struct user_key_state_info
*key_state_info
= get_user_thread_info()->key_state
;
3240 struct send_message_info info
;
3241 int prev_x
, prev_y
, new_x
, new_y
;
3242 INT counter
= global_key_state_counter
;
3243 USAGE hid_usage_page
, hid_usage
;
3247 info
.type
= MSG_HARDWARE
;
3253 if (input
->type
== INPUT_HARDWARE
&& rawinput
->header
.dwType
== RIM_TYPEHID
)
3255 if (input
->u
.hi
.uMsg
== WM_INPUT_DEVICE_CHANGE
)
3257 hid_usage_page
= ((USAGE
*)rawinput
->data
.hid
.bRawData
)[0];
3258 hid_usage
= ((USAGE
*)rawinput
->data
.hid
.bRawData
)[1];
3260 if (input
->u
.hi
.uMsg
== WM_INPUT
)
3262 if (!rawinput_device_get_usages( rawinput
->header
.hDevice
, &hid_usage_page
, &hid_usage
))
3264 WARN( "unable to get HID usages for device %p\n", rawinput
->header
.hDevice
);
3265 return STATUS_INVALID_HANDLE
;
3270 SERVER_START_REQ( send_hardware_message
)
3272 req
->win
= wine_server_user_handle( hwnd
);
3274 req
->input
.type
= input
->type
;
3275 switch (input
->type
)
3278 req
->input
.mouse
.x
= input
->u
.mi
.dx
;
3279 req
->input
.mouse
.y
= input
->u
.mi
.dy
;
3280 req
->input
.mouse
.data
= input
->u
.mi
.mouseData
;
3281 req
->input
.mouse
.flags
= input
->u
.mi
.dwFlags
;
3282 req
->input
.mouse
.time
= input
->u
.mi
.time
;
3283 req
->input
.mouse
.info
= input
->u
.mi
.dwExtraInfo
;
3285 case INPUT_KEYBOARD
:
3286 req
->input
.kbd
.vkey
= input
->u
.ki
.wVk
;
3287 req
->input
.kbd
.scan
= input
->u
.ki
.wScan
;
3288 req
->input
.kbd
.flags
= input
->u
.ki
.dwFlags
;
3289 req
->input
.kbd
.time
= input
->u
.ki
.time
;
3290 req
->input
.kbd
.info
= input
->u
.ki
.dwExtraInfo
;
3292 case INPUT_HARDWARE
:
3293 req
->input
.hw
.msg
= input
->u
.hi
.uMsg
;
3294 req
->input
.hw
.lparam
= MAKELONG( input
->u
.hi
.wParamL
, input
->u
.hi
.wParamH
);
3295 switch (input
->u
.hi
.uMsg
)
3298 case WM_INPUT_DEVICE_CHANGE
:
3299 req
->input
.hw
.rawinput
.type
= rawinput
->header
.dwType
;
3300 switch (rawinput
->header
.dwType
)
3303 req
->input
.hw
.rawinput
.hid
.device
= HandleToUlong( rawinput
->header
.hDevice
);
3304 req
->input
.hw
.rawinput
.hid
.param
= rawinput
->header
.wParam
;
3305 req
->input
.hw
.rawinput
.hid
.usage_page
= hid_usage_page
;
3306 req
->input
.hw
.rawinput
.hid
.usage
= hid_usage
;
3307 req
->input
.hw
.rawinput
.hid
.count
= rawinput
->data
.hid
.dwCount
;
3308 req
->input
.hw
.rawinput
.hid
.length
= rawinput
->data
.hid
.dwSizeHid
;
3309 wine_server_add_data( req
, rawinput
->data
.hid
.bRawData
,
3310 rawinput
->data
.hid
.dwCount
* rawinput
->data
.hid
.dwSizeHid
);
3319 if (key_state_info
) wine_server_set_reply( req
, key_state_info
->state
,
3320 sizeof(key_state_info
->state
) );
3321 ret
= wine_server_call( req
);
3323 prev_x
= reply
->prev_x
;
3324 prev_y
= reply
->prev_y
;
3325 new_x
= reply
->new_x
;
3326 new_y
= reply
->new_y
;
3334 key_state_info
->time
= GetTickCount();
3335 key_state_info
->counter
= counter
;
3337 if ((flags
& SEND_HWMSG_INJECTED
) && (prev_x
!= new_x
|| prev_y
!= new_y
))
3338 USER_Driver
->pSetCursorPos( new_x
, new_y
);
3344 wait_message_reply( 0 );
3345 retrieve_reply( &info
, 0, &ignored
);
3351 /***********************************************************************
3352 * MSG_SendInternalMessageTimeout
3354 * Same as SendMessageTimeoutW but sends the message to a specific thread
3355 * without requiring a window handle. Only works for internal Wine messages.
3357 LRESULT
MSG_SendInternalMessageTimeout( DWORD dest_pid
, DWORD dest_tid
,
3358 UINT msg
, WPARAM wparam
, LPARAM lparam
,
3359 UINT flags
, UINT timeout
, PDWORD_PTR res_ptr
)
3361 struct send_message_info info
;
3362 LRESULT ret
, result
;
3364 assert( msg
& 0x80000000 ); /* must be an internal Wine message */
3366 info
.type
= MSG_UNICODE
;
3367 info
.dest_tid
= dest_tid
;
3370 info
.wparam
= wparam
;
3371 info
.lparam
= lparam
;
3373 info
.timeout
= timeout
;
3375 if (USER_IsExitingThread( dest_tid
)) return 0;
3377 if (dest_tid
== GetCurrentThreadId())
3379 result
= handle_internal_message( 0, msg
, wparam
, lparam
);
3384 if (dest_pid
!= GetCurrentProcessId()) info
.type
= MSG_OTHER_PROCESS
;
3385 ret
= send_inter_thread_message( &info
, &result
);
3387 if (ret
&& res_ptr
) *res_ptr
= result
;
3392 /***********************************************************************
3393 * SendMessageTimeoutW (USER32.@)
3395 LRESULT WINAPI
SendMessageTimeoutW( HWND hwnd
, UINT msg
, WPARAM wparam
, LPARAM lparam
,
3396 UINT flags
, UINT timeout
, PDWORD_PTR res_ptr
)
3398 struct send_message_info info
;
3400 info
.type
= MSG_UNICODE
;
3403 info
.wparam
= wparam
;
3404 info
.lparam
= lparam
;
3406 info
.timeout
= timeout
;
3408 return send_message( &info
, res_ptr
, TRUE
);
3411 /***********************************************************************
3412 * SendMessageTimeoutA (USER32.@)
3414 LRESULT WINAPI
SendMessageTimeoutA( HWND hwnd
, UINT msg
, WPARAM wparam
, LPARAM lparam
,
3415 UINT flags
, UINT timeout
, PDWORD_PTR res_ptr
)
3417 struct send_message_info info
;
3419 info
.type
= MSG_ASCII
;
3422 info
.wparam
= wparam
;
3423 info
.lparam
= lparam
;
3425 info
.timeout
= timeout
;
3426 info
.wm_char
= WMCHAR_MAP_SENDMESSAGETIMEOUT
;
3428 return send_message( &info
, res_ptr
, FALSE
);
3432 /***********************************************************************
3433 * SendMessageW (USER32.@)
3435 LRESULT WINAPI
SendMessageW( HWND hwnd
, UINT msg
, WPARAM wparam
, LPARAM lparam
)
3438 struct send_message_info info
;
3440 info
.type
= MSG_UNICODE
;
3443 info
.wparam
= wparam
;
3444 info
.lparam
= lparam
;
3445 info
.flags
= SMTO_NORMAL
;
3448 send_message( &info
, &res
, TRUE
);
3453 /***********************************************************************
3454 * SendMessageA (USER32.@)
3456 LRESULT WINAPI
SendMessageA( HWND hwnd
, UINT msg
, WPARAM wparam
, LPARAM lparam
)
3459 struct send_message_info info
;
3461 info
.type
= MSG_ASCII
;
3464 info
.wparam
= wparam
;
3465 info
.lparam
= lparam
;
3466 info
.flags
= SMTO_NORMAL
;
3468 info
.wm_char
= WMCHAR_MAP_SENDMESSAGE
;
3470 send_message( &info
, &res
, FALSE
);
3475 /***********************************************************************
3476 * SendNotifyMessageA (USER32.@)
3478 BOOL WINAPI
SendNotifyMessageA( HWND hwnd
, UINT msg
, WPARAM wparam
, LPARAM lparam
)
3480 struct send_message_info info
;
3482 if (is_pointer_message( msg
, wparam
))
3484 SetLastError( ERROR_MESSAGE_SYNC_ONLY
);
3488 info
.type
= MSG_NOTIFY
;
3491 info
.wparam
= wparam
;
3492 info
.lparam
= lparam
;
3494 info
.wm_char
= WMCHAR_MAP_SENDMESSAGETIMEOUT
;
3496 return send_message( &info
, NULL
, FALSE
);
3500 /***********************************************************************
3501 * SendNotifyMessageW (USER32.@)
3503 BOOL WINAPI
SendNotifyMessageW( HWND hwnd
, UINT msg
, WPARAM wparam
, LPARAM lparam
)
3505 struct send_message_info info
;
3507 if (is_pointer_message( msg
, wparam
))
3509 SetLastError( ERROR_MESSAGE_SYNC_ONLY
);
3513 info
.type
= MSG_NOTIFY
;
3516 info
.wparam
= wparam
;
3517 info
.lparam
= lparam
;
3520 return send_message( &info
, NULL
, TRUE
);
3524 /***********************************************************************
3525 * SendMessageCallbackA (USER32.@)
3527 BOOL WINAPI
SendMessageCallbackA( HWND hwnd
, UINT msg
, WPARAM wparam
, LPARAM lparam
,
3528 SENDASYNCPROC callback
, ULONG_PTR data
)
3530 struct send_message_info info
;
3532 if (is_pointer_message( msg
, wparam
))
3534 SetLastError( ERROR_MESSAGE_SYNC_ONLY
);
3538 info
.type
= MSG_CALLBACK
;
3541 info
.wparam
= wparam
;
3542 info
.lparam
= lparam
;
3543 info
.callback
= callback
;
3546 info
.wm_char
= WMCHAR_MAP_SENDMESSAGETIMEOUT
;
3548 return send_message( &info
, NULL
, FALSE
);
3552 /***********************************************************************
3553 * SendMessageCallbackW (USER32.@)
3555 BOOL WINAPI
SendMessageCallbackW( HWND hwnd
, UINT msg
, WPARAM wparam
, LPARAM lparam
,
3556 SENDASYNCPROC callback
, ULONG_PTR data
)
3558 struct send_message_info info
;
3560 if (is_pointer_message( msg
, wparam
))
3562 SetLastError( ERROR_MESSAGE_SYNC_ONLY
);
3566 info
.type
= MSG_CALLBACK
;
3569 info
.wparam
= wparam
;
3570 info
.lparam
= lparam
;
3571 info
.callback
= callback
;
3575 return send_message( &info
, NULL
, TRUE
);
3579 /***********************************************************************
3580 * ReplyMessage (USER32.@)
3582 BOOL WINAPI
ReplyMessage( LRESULT result
)
3584 struct received_message_info
*info
= get_user_thread_info()->receive_info
;
3586 if (!info
) return FALSE
;
3587 reply_message( info
, result
, FALSE
);
3592 /***********************************************************************
3593 * InSendMessage (USER32.@)
3595 BOOL WINAPI
InSendMessage(void)
3597 return (InSendMessageEx( NULL
) & (ISMEX_SEND
| ISMEX_NOTIFY
| ISMEX_CALLBACK
)) != 0;
3601 /***********************************************************************
3602 * InSendMessageEx (USER32.@)
3604 DWORD WINAPI
InSendMessageEx( LPVOID reserved
)
3606 struct received_message_info
*info
= get_user_thread_info()->receive_info
;
3608 if (info
) return info
->flags
;
3609 return ISMEX_NOSEND
;
3613 /***********************************************************************
3614 * PostMessageA (USER32.@)
3616 BOOL WINAPI
PostMessageA( HWND hwnd
, UINT msg
, WPARAM wparam
, LPARAM lparam
)
3618 if (!map_wparam_AtoW( msg
, &wparam
, WMCHAR_MAP_POSTMESSAGE
)) return TRUE
;
3619 return PostMessageW( hwnd
, msg
, wparam
, lparam
);
3623 /***********************************************************************
3624 * PostMessageW (USER32.@)
3626 BOOL WINAPI
PostMessageW( HWND hwnd
, UINT msg
, WPARAM wparam
, LPARAM lparam
)
3628 struct send_message_info info
;
3630 if (is_pointer_message( msg
, wparam
))
3632 SetLastError( ERROR_MESSAGE_SYNC_ONLY
);
3636 TRACE( "hwnd %p msg %x (%s) wp %lx lp %lx\n",
3637 hwnd
, msg
, SPY_GetMsgName(msg
, hwnd
), wparam
, lparam
);
3639 info
.type
= MSG_POSTED
;
3642 info
.wparam
= wparam
;
3643 info
.lparam
= lparam
;
3646 if (is_broadcast(hwnd
))
3648 if (is_message_broadcastable( info
.msg
))
3649 EnumWindows( broadcast_message_callback
, (LPARAM
)&info
);
3653 if (!hwnd
) return PostThreadMessageW( GetCurrentThreadId(), msg
, wparam
, lparam
);
3655 if (!(info
.dest_tid
= GetWindowThreadProcessId( hwnd
, NULL
))) return FALSE
;
3657 if (USER_IsExitingThread( info
.dest_tid
)) return TRUE
;
3659 return put_message_in_queue( &info
, NULL
);
3663 /**********************************************************************
3664 * PostThreadMessageA (USER32.@)
3666 BOOL WINAPI
PostThreadMessageA( DWORD thread
, UINT msg
, WPARAM wparam
, LPARAM lparam
)
3668 if (!map_wparam_AtoW( msg
, &wparam
, WMCHAR_MAP_POSTMESSAGE
)) return TRUE
;
3669 return PostThreadMessageW( thread
, msg
, wparam
, lparam
);
3673 /**********************************************************************
3674 * PostThreadMessageW (USER32.@)
3676 BOOL WINAPI
PostThreadMessageW( DWORD thread
, UINT msg
, WPARAM wparam
, LPARAM lparam
)
3678 struct send_message_info info
;
3680 if (is_pointer_message( msg
, wparam
))
3682 SetLastError( ERROR_MESSAGE_SYNC_ONLY
);
3685 if (USER_IsExitingThread( thread
)) return TRUE
;
3687 info
.type
= MSG_POSTED
;
3688 info
.dest_tid
= thread
;
3691 info
.wparam
= wparam
;
3692 info
.lparam
= lparam
;
3694 return put_message_in_queue( &info
, NULL
);
3698 /***********************************************************************
3699 * PostQuitMessage (USER32.@)
3701 * Posts a quit message to the current thread's message queue.
3704 * exit_code [I] Exit code to return from message loop.
3710 * This function is not the same as calling:
3711 *|PostThreadMessage(GetCurrentThreadId(), WM_QUIT, exit_code, 0);
3712 * It instead sets a flag in the message queue that signals it to generate
3713 * a WM_QUIT message when there are no other pending sent or posted messages
3716 void WINAPI
PostQuitMessage( INT exit_code
)
3718 SERVER_START_REQ( post_quit_message
)
3720 req
->exit_code
= exit_code
;
3721 wine_server_call( req
);
3726 /* check for driver events if we detect that the app is not properly consuming messages */
3727 static inline void check_for_driver_events( UINT msg
)
3729 if (get_user_thread_info()->message_count
> 200)
3731 flush_window_surfaces( FALSE
);
3732 USER_Driver
->pMsgWaitForMultipleObjectsEx( 0, NULL
, 0, QS_ALLINPUT
, 0 );
3734 else if (msg
== WM_TIMER
|| msg
== WM_SYSTIMER
)
3736 /* driver events should have priority over timers, so make sure we'll check for them soon */
3737 get_user_thread_info()->message_count
+= 100;
3739 else get_user_thread_info()->message_count
++;
3742 /***********************************************************************
3743 * PeekMessageW (USER32.@)
3745 BOOL WINAPI DECLSPEC_HOTPATCH
PeekMessageW( MSG
*msg_out
, HWND hwnd
, UINT first
, UINT last
, UINT flags
)
3750 USER_CheckNotLock();
3751 check_for_driver_events( 0 );
3753 ret
= peek_message( &msg
, hwnd
, first
, last
, flags
, 0 );
3754 if (ret
< 0) return FALSE
;
3758 flush_window_surfaces( TRUE
);
3759 ret
= wow_handlers
.wait_message( 0, NULL
, 0, QS_ALLINPUT
, 0 );
3760 /* if we received driver events, check again for a pending message */
3761 if (ret
== WAIT_TIMEOUT
|| peek_message( &msg
, hwnd
, first
, last
, flags
, 0 ) <= 0) return FALSE
;
3764 check_for_driver_events( msg
.message
);
3766 /* copy back our internal safe copy of message data to msg_out.
3767 * msg_out is a variable from the *program*, so it can't be used
3768 * internally as it can get "corrupted" by our use of SendMessage()
3769 * (back to the program) inside the message handling itself. */
3772 SetLastError( ERROR_NOACCESS
);
3780 /***********************************************************************
3781 * PeekMessageA (USER32.@)
3783 BOOL WINAPI DECLSPEC_HOTPATCH
PeekMessageA( MSG
*msg
, HWND hwnd
, UINT first
, UINT last
, UINT flags
)
3785 if (get_pending_wmchar( msg
, first
, last
, (flags
& PM_REMOVE
) )) return TRUE
;
3786 if (!PeekMessageW( msg
, hwnd
, first
, last
, flags
)) return FALSE
;
3787 map_wparam_WtoA( msg
, (flags
& PM_REMOVE
) );
3792 /***********************************************************************
3793 * GetMessageW (USER32.@)
3795 BOOL WINAPI DECLSPEC_HOTPATCH
GetMessageW( MSG
*msg
, HWND hwnd
, UINT first
, UINT last
)
3797 HANDLE server_queue
= get_server_queue_handle();
3798 unsigned int mask
= QS_POSTMESSAGE
| QS_SENDMESSAGE
; /* Always selected */
3801 USER_CheckNotLock();
3802 check_for_driver_events( 0 );
3806 if ((first
<= WM_KEYLAST
) && (last
>= WM_KEYFIRST
)) mask
|= QS_KEY
;
3807 if ( ((first
<= WM_MOUSELAST
) && (last
>= WM_MOUSEFIRST
)) ||
3808 ((first
<= WM_NCMOUSELAST
) && (last
>= WM_NCMOUSEFIRST
)) ) mask
|= QS_MOUSE
;
3809 if ((first
<= WM_TIMER
) && (last
>= WM_TIMER
)) mask
|= QS_TIMER
;
3810 if ((first
<= WM_SYSTIMER
) && (last
>= WM_SYSTIMER
)) mask
|= QS_TIMER
;
3811 if ((first
<= WM_PAINT
) && (last
>= WM_PAINT
)) mask
|= QS_PAINT
;
3813 else mask
= QS_ALLINPUT
;
3815 while (!(ret
= peek_message( msg
, hwnd
, first
, last
, PM_REMOVE
| (mask
<< 16), mask
)))
3817 wait_objects( 1, &server_queue
, INFINITE
, mask
& (QS_SENDMESSAGE
| QS_SMRESULT
), mask
, 0 );
3819 if (ret
< 0) return -1;
3821 check_for_driver_events( msg
->message
);
3823 return (msg
->message
!= WM_QUIT
);
3827 /***********************************************************************
3828 * GetMessageA (USER32.@)
3830 BOOL WINAPI DECLSPEC_HOTPATCH
GetMessageA( MSG
*msg
, HWND hwnd
, UINT first
, UINT last
)
3832 if (get_pending_wmchar( msg
, first
, last
, TRUE
)) return TRUE
;
3833 if (GetMessageW( msg
, hwnd
, first
, last
) < 0) return -1;
3834 map_wparam_WtoA( msg
, TRUE
);
3835 return (msg
->message
!= WM_QUIT
);
3839 /***********************************************************************
3840 * IsDialogMessageA (USER32.@)
3841 * IsDialogMessage (USER32.@)
3843 BOOL WINAPI
IsDialogMessageA( HWND hwndDlg
, LPMSG pmsg
)
3846 map_wparam_AtoW( msg
.message
, &msg
.wParam
, WMCHAR_MAP_NOMAPPING
);
3847 return IsDialogMessageW( hwndDlg
, &msg
);
3851 /***********************************************************************
3852 * TranslateMessage (USER32.@)
3854 * Implementation of TranslateMessage.
3856 * TranslateMessage translates virtual-key messages into character-messages,
3858 * WM_KEYDOWN/WM_KEYUP combinations produce a WM_CHAR or WM_DEADCHAR message.
3859 * ditto replacing WM_* with WM_SYS*
3860 * This produces WM_CHAR messages only for keys mapped to ASCII characters
3861 * by the keyboard driver.
3863 * If the message is WM_KEYDOWN, WM_KEYUP, WM_SYSKEYDOWN, or WM_SYSKEYUP, the
3864 * return value is nonzero, regardless of the translation.
3867 BOOL WINAPI
TranslateMessage( const MSG
*msg
)
3874 if (msg
->message
< WM_KEYFIRST
|| msg
->message
> WM_KEYLAST
) return FALSE
;
3875 if (msg
->message
!= WM_KEYDOWN
&& msg
->message
!= WM_SYSKEYDOWN
) return TRUE
;
3877 TRACE_(key
)("Translating key %s (%04lX), scancode %04x\n",
3878 SPY_GetVKeyName(msg
->wParam
), msg
->wParam
, HIWORD(msg
->lParam
));
3880 switch (msg
->wParam
)
3883 message
= (msg
->message
== WM_KEYDOWN
) ? WM_CHAR
: WM_SYSCHAR
;
3884 TRACE_(key
)("PostMessageW(%p,%s,%04x,%08x)\n",
3885 msg
->hwnd
, SPY_GetMsgName(message
, msg
->hwnd
), HIWORD(msg
->lParam
), LOWORD(msg
->lParam
));
3886 PostMessageW( msg
->hwnd
, message
, HIWORD(msg
->lParam
), LOWORD(msg
->lParam
));
3890 return ImmTranslateMessage(msg
->hwnd
, msg
->message
, msg
->wParam
, msg
->lParam
);
3893 NtUserGetKeyboardState( state
);
3894 len
= ToUnicode(msg
->wParam
, HIWORD(msg
->lParam
), state
, wp
, ARRAY_SIZE(wp
), 0);
3897 message
= (msg
->message
== WM_KEYDOWN
) ? WM_DEADCHAR
: WM_SYSDEADCHAR
;
3898 TRACE_(key
)("-1 -> PostMessageW(%p,%s,%04x,%08lx)\n",
3899 msg
->hwnd
, SPY_GetMsgName(message
, msg
->hwnd
), wp
[0], msg
->lParam
);
3900 PostMessageW( msg
->hwnd
, message
, wp
[0], msg
->lParam
);
3906 message
= (msg
->message
== WM_KEYDOWN
) ? WM_CHAR
: WM_SYSCHAR
;
3907 TRACE_(key
)("%d -> PostMessageW(%p,%s,<x>,%08lx) for <x> in %s\n", len
, msg
->hwnd
,
3908 SPY_GetMsgName(message
, msg
->hwnd
), msg
->lParam
, debugstr_wn(wp
, len
));
3909 for (i
= 0; i
< len
; i
++)
3910 PostMessageW( msg
->hwnd
, message
, wp
[i
], msg
->lParam
);
3916 /***********************************************************************
3917 * DispatchMessageA (USER32.@)
3919 * See DispatchMessageW.
3921 LRESULT WINAPI DECLSPEC_HOTPATCH
DispatchMessageA( const MSG
* msg
)
3925 /* Process timer messages */
3926 if ((msg
->message
== WM_TIMER
) || (msg
->message
== WM_SYSTIMER
))
3932 retval
= CallWindowProcA( (WNDPROC
)msg
->lParam
, msg
->hwnd
,
3933 msg
->message
, msg
->wParam
, GetTickCount() );
3943 if (!msg
->hwnd
) return 0;
3945 SPY_EnterMessage( SPY_DISPATCHMESSAGE
, msg
->hwnd
, msg
->message
,
3946 msg
->wParam
, msg
->lParam
);
3948 if (!WINPROC_call_window( msg
->hwnd
, msg
->message
, msg
->wParam
, msg
->lParam
,
3949 &retval
, FALSE
, WMCHAR_MAP_DISPATCHMESSAGE
))
3951 if (!IsWindow( msg
->hwnd
)) SetLastError( ERROR_INVALID_WINDOW_HANDLE
);
3952 else SetLastError( ERROR_MESSAGE_SYNC_ONLY
);
3956 SPY_ExitMessage( SPY_RESULT_OK
, msg
->hwnd
, msg
->message
, retval
,
3957 msg
->wParam
, msg
->lParam
);
3959 if (msg
->message
== WM_PAINT
)
3961 /* send a WM_NCPAINT and WM_ERASEBKGND if the non-client area is still invalid */
3962 HRGN hrgn
= CreateRectRgn( 0, 0, 0, 0 );
3963 GetUpdateRgn( msg
->hwnd
, hrgn
, TRUE
);
3964 DeleteObject( hrgn
);
3970 /***********************************************************************
3971 * DispatchMessageW (USER32.@) Process a message
3973 * Process the message specified in the structure *_msg_.
3975 * If the lpMsg parameter points to a WM_TIMER message and the
3976 * parameter of the WM_TIMER message is not NULL, the lParam parameter
3977 * points to the function that is called instead of the window
3978 * procedure. The function stored in lParam (timer callback) is protected
3979 * from causing page-faults.
3981 * The message must be valid.
3985 * DispatchMessage() returns the result of the window procedure invoked.
3992 LRESULT WINAPI DECLSPEC_HOTPATCH
DispatchMessageW( const MSG
* msg
)
3996 /* Process timer messages */
3997 if ((msg
->message
== WM_TIMER
) || (msg
->message
== WM_SYSTIMER
))
4003 retval
= CallWindowProcW( (WNDPROC
)msg
->lParam
, msg
->hwnd
,
4004 msg
->message
, msg
->wParam
, GetTickCount() );
4014 if (!msg
->hwnd
) return 0;
4016 SPY_EnterMessage( SPY_DISPATCHMESSAGE
, msg
->hwnd
, msg
->message
,
4017 msg
->wParam
, msg
->lParam
);
4019 if (!WINPROC_call_window( msg
->hwnd
, msg
->message
, msg
->wParam
, msg
->lParam
,
4020 &retval
, TRUE
, WMCHAR_MAP_DISPATCHMESSAGE
))
4022 if (!IsWindow( msg
->hwnd
)) SetLastError( ERROR_INVALID_WINDOW_HANDLE
);
4023 else SetLastError( ERROR_MESSAGE_SYNC_ONLY
);
4027 SPY_ExitMessage( SPY_RESULT_OK
, msg
->hwnd
, msg
->message
, retval
,
4028 msg
->wParam
, msg
->lParam
);
4030 if (msg
->message
== WM_PAINT
)
4032 /* send a WM_NCPAINT and WM_ERASEBKGND if the non-client area is still invalid */
4033 HRGN hrgn
= CreateRectRgn( 0, 0, 0, 0 );
4034 GetUpdateRgn( msg
->hwnd
, hrgn
, TRUE
);
4035 DeleteObject( hrgn
);
4041 /***********************************************************************
4042 * GetMessagePos (USER.119)
4043 * GetMessagePos (USER32.@)
4045 * The GetMessagePos() function returns a long value representing a
4046 * cursor position, in screen coordinates, when the last message
4047 * retrieved by the GetMessage() function occurs. The x-coordinate is
4048 * in the low-order word of the return value, the y-coordinate is in
4049 * the high-order word. The application can use the MAKEPOINT()
4050 * macro to obtain a POINT structure from the return value.
4052 * For the current cursor position, use GetCursorPos().
4056 * Cursor position of last message on success, zero on failure.
4063 DWORD WINAPI
GetMessagePos(void)
4065 return get_user_thread_info()->GetMessagePosVal
;
4069 /***********************************************************************
4070 * GetMessageTime (USER.120)
4071 * GetMessageTime (USER32.@)
4073 * GetMessageTime() returns the message time for the last message
4074 * retrieved by the function. The time is measured in milliseconds with
4075 * the same offset as GetTickCount().
4077 * Since the tick count wraps, this is only useful for moderately short
4078 * relative time comparisons.
4082 * Time of last message on success, zero on failure.
4084 LONG WINAPI
GetMessageTime(void)
4086 return get_user_thread_info()->GetMessageTimeVal
;
4090 /***********************************************************************
4091 * GetMessageExtraInfo (USER.288)
4092 * GetMessageExtraInfo (USER32.@)
4094 LPARAM WINAPI
GetMessageExtraInfo(void)
4096 return get_user_thread_info()->GetMessageExtraInfoVal
;
4100 /***********************************************************************
4101 * SetMessageExtraInfo (USER32.@)
4103 LPARAM WINAPI
SetMessageExtraInfo(LPARAM lParam
)
4105 struct user_thread_info
*thread_info
= get_user_thread_info();
4106 LONG old_value
= thread_info
->GetMessageExtraInfoVal
;
4107 thread_info
->GetMessageExtraInfoVal
= lParam
;
4112 /***********************************************************************
4113 * GetCurrentInputMessageSource (USER32.@)
4115 BOOL WINAPI
GetCurrentInputMessageSource( INPUT_MESSAGE_SOURCE
*source
)
4117 *source
= get_user_thread_info()->msg_source
;
4122 /***********************************************************************
4123 * WaitMessage (USER.112) Suspend thread pending messages
4124 * WaitMessage (USER32.@) Suspend thread pending messages
4126 * WaitMessage() suspends a thread until events appear in the thread's
4129 BOOL WINAPI
WaitMessage(void)
4131 return (MsgWaitForMultipleObjectsEx( 0, NULL
, INFINITE
, QS_ALLINPUT
, 0 ) != WAIT_FAILED
);
4135 /***********************************************************************
4136 * MsgWaitForMultipleObjectsEx (USER32.@)
4138 DWORD WINAPI
MsgWaitForMultipleObjectsEx( DWORD count
, const HANDLE
*pHandles
,
4139 DWORD timeout
, DWORD mask
, DWORD flags
)
4141 HANDLE handles
[MAXIMUM_WAIT_OBJECTS
];
4144 if (count
> MAXIMUM_WAIT_OBJECTS
-1)
4146 SetLastError( ERROR_INVALID_PARAMETER
);
4150 /* add the queue to the handle list */
4151 for (i
= 0; i
< count
; i
++) handles
[i
] = pHandles
[i
];
4152 handles
[count
] = get_server_queue_handle();
4154 return wait_objects( count
+1, handles
, timeout
,
4155 (flags
& MWMO_INPUTAVAILABLE
) ? mask
: 0, mask
, flags
);
4159 /***********************************************************************
4160 * MsgWaitForMultipleObjects (USER32.@)
4162 DWORD WINAPI
MsgWaitForMultipleObjects( DWORD count
, const HANDLE
*handles
,
4163 BOOL wait_all
, DWORD timeout
, DWORD mask
)
4165 return MsgWaitForMultipleObjectsEx( count
, handles
, timeout
, mask
,
4166 wait_all
? MWMO_WAITALL
: 0 );
4170 /***********************************************************************
4171 * WaitForInputIdle (USER32.@)
4173 DWORD WINAPI
WaitForInputIdle( HANDLE hProcess
, DWORD dwTimeOut
)
4175 DWORD start_time
, elapsed
, ret
;
4178 handles
[0] = hProcess
;
4179 SERVER_START_REQ( get_process_idle_event
)
4181 req
->handle
= wine_server_obj_handle( hProcess
);
4182 wine_server_call_err( req
);
4183 handles
[1] = wine_server_ptr_handle( reply
->event
);
4186 if (!handles
[1]) return WAIT_FAILED
; /* no event to wait on */
4188 start_time
= GetTickCount();
4191 TRACE("waiting for %p\n", handles
[1] );
4194 ret
= MsgWaitForMultipleObjects ( 2, handles
, FALSE
, dwTimeOut
- elapsed
, QS_SENDMESSAGE
);
4199 case WAIT_OBJECT_0
+2:
4200 process_sent_messages();
4204 TRACE("timeout or error\n");
4207 TRACE("finished\n");
4210 if (dwTimeOut
!= INFINITE
)
4212 elapsed
= GetTickCount() - start_time
;
4213 if (elapsed
> dwTimeOut
)
4219 return WAIT_TIMEOUT
;
4223 /***********************************************************************
4224 * RegisterWindowMessageA (USER32.@)
4225 * RegisterWindowMessage (USER.118)
4227 UINT WINAPI
RegisterWindowMessageA( LPCSTR str
)
4229 UINT ret
= GlobalAddAtomA(str
);
4230 TRACE("%s, ret=%x\n", str
, ret
);
4235 /***********************************************************************
4236 * RegisterWindowMessageW (USER32.@)
4238 UINT WINAPI
RegisterWindowMessageW( LPCWSTR str
)
4240 UINT ret
= GlobalAddAtomW(str
);
4241 TRACE("%s ret=%x\n", debugstr_w(str
), ret
);
4245 typedef struct BroadcastParm
4256 static BOOL CALLBACK
bcast_childwindow( HWND hw
, LPARAM lp
)
4258 BroadcastParm
*parm
= (BroadcastParm
*)lp
;
4259 DWORD_PTR retval
= 0;
4262 if (parm
->flags
& BSF_IGNORECURRENTTASK
&& WIN_IsCurrentProcess(hw
))
4264 TRACE("Not telling myself %p\n", hw
);
4268 /* I don't know 100% for sure if this is what Windows does, but it fits the tests */
4269 if (parm
->flags
& BSF_QUERY
)
4271 TRACE("Telling window %p using SendMessageTimeout\n", hw
);
4273 /* Not tested for conflicting flags */
4274 if (parm
->flags
& BSF_FORCEIFHUNG
|| parm
->flags
& BSF_NOHANG
)
4275 lresult
= SendMessageTimeoutW( hw
, parm
->msg
, parm
->wp
, parm
->lp
, SMTO_ABORTIFHUNG
, 2000, &retval
);
4276 else if (parm
->flags
& BSF_NOTIMEOUTIFNOTHUNG
)
4277 lresult
= SendMessageTimeoutW( hw
, parm
->msg
, parm
->wp
, parm
->lp
, SMTO_NOTIMEOUTIFNOTHUNG
, 2000, &retval
);
4279 lresult
= SendMessageTimeoutW( hw
, parm
->msg
, parm
->wp
, parm
->lp
, SMTO_NORMAL
, 2000, &retval
);
4281 if (!lresult
&& GetLastError() == ERROR_TIMEOUT
)
4283 WARN("Timed out!\n");
4284 if (!(parm
->flags
& BSF_FORCEIFHUNG
))
4287 if (retval
== BROADCAST_QUERY_DENY
)
4293 parm
->success
= FALSE
;
4296 else if (parm
->flags
& BSF_POSTMESSAGE
)
4298 TRACE("Telling window %p using PostMessage\n", hw
);
4299 PostMessageW( hw
, parm
->msg
, parm
->wp
, parm
->lp
);
4303 TRACE("Telling window %p using SendNotifyMessage\n", hw
);
4304 SendNotifyMessageW( hw
, parm
->msg
, parm
->wp
, parm
->lp
);
4310 static BOOL CALLBACK
bcast_desktop( LPWSTR desktop
, LPARAM lp
)
4314 BroadcastParm
*parm
= (BroadcastParm
*)lp
;
4316 TRACE("desktop: %s\n", debugstr_w( desktop
));
4318 hdesktop
= open_winstation_desktop( parm
->winsta
, desktop
, 0, FALSE
, DESKTOP_ENUMERATE
|DESKTOP_WRITEOBJECTS
|STANDARD_RIGHTS_WRITE
);
4321 FIXME("Could not open desktop %s\n", debugstr_w(desktop
));
4325 ret
= EnumDesktopWindows( hdesktop
, bcast_childwindow
, lp
);
4326 NtUserCloseDesktop( hdesktop
);
4327 TRACE("-->%d\n", ret
);
4328 return parm
->success
;
4331 static BOOL CALLBACK
bcast_winsta( LPWSTR winsta
, LPARAM lp
)
4334 HWINSTA hwinsta
= OpenWindowStationW( winsta
, FALSE
, WINSTA_ENUMDESKTOPS
);
4335 TRACE("hwinsta: %p/%s/%08x\n", hwinsta
, debugstr_w( winsta
), GetLastError());
4338 ((BroadcastParm
*)lp
)->winsta
= hwinsta
;
4339 ret
= EnumDesktopsW( hwinsta
, bcast_desktop
, lp
);
4340 NtUserCloseWindowStation( hwinsta
);
4341 TRACE("-->%d\n", ret
);
4345 /***********************************************************************
4346 * BroadcastSystemMessageA (USER32.@)
4347 * BroadcastSystemMessage (USER32.@)
4349 LONG WINAPI
BroadcastSystemMessageA( DWORD flags
, LPDWORD recipients
, UINT msg
, WPARAM wp
, LPARAM lp
)
4351 return BroadcastSystemMessageExA( flags
, recipients
, msg
, wp
, lp
, NULL
);
4355 /***********************************************************************
4356 * BroadcastSystemMessageW (USER32.@)
4358 LONG WINAPI
BroadcastSystemMessageW( DWORD flags
, LPDWORD recipients
, UINT msg
, WPARAM wp
, LPARAM lp
)
4360 return BroadcastSystemMessageExW( flags
, recipients
, msg
, wp
, lp
, NULL
);
4363 /***********************************************************************
4364 * BroadcastSystemMessageExA (USER32.@)
4366 LONG WINAPI
BroadcastSystemMessageExA( DWORD flags
, LPDWORD recipients
, UINT msg
, WPARAM wp
, LPARAM lp
, PBSMINFO pinfo
)
4368 map_wparam_AtoW( msg
, &wp
, WMCHAR_MAP_NOMAPPING
);
4369 return BroadcastSystemMessageExW( flags
, recipients
, msg
, wp
, lp
, NULL
);
4373 /***********************************************************************
4374 * BroadcastSystemMessageExW (USER32.@)
4376 LONG WINAPI
BroadcastSystemMessageExW( DWORD flags
, LPDWORD recipients
, UINT msg
, WPARAM wp
, LPARAM lp
, PBSMINFO pinfo
)
4379 DWORD recips
= BSM_ALLCOMPONENTS
;
4381 static const DWORD all_flags
= ( BSF_QUERY
| BSF_IGNORECURRENTTASK
| BSF_FLUSHDISK
| BSF_NOHANG
4382 | BSF_POSTMESSAGE
| BSF_FORCEIFHUNG
| BSF_NOTIMEOUTIFNOTHUNG
4383 | BSF_ALLOWSFW
| BSF_SENDNOTIFYMESSAGE
| BSF_RETURNHDESK
| BSF_LUID
);
4385 TRACE("Flags: %08x, recipients: %p(0x%x), msg: %04x, wparam: %08lx, lparam: %08lx\n", flags
, recipients
,
4386 (recipients
? *recipients
: recips
), msg
, wp
, lp
);
4388 if (flags
& ~all_flags
)
4390 SetLastError(ERROR_INVALID_PARAMETER
);
4395 recipients
= &recips
;
4397 if ( pinfo
&& flags
& BSF_QUERY
)
4398 FIXME("Not returning PBSMINFO information yet\n");
4401 parm
.recipients
= recipients
;
4405 parm
.success
= TRUE
;
4407 if (*recipients
& BSM_ALLDESKTOPS
|| *recipients
== BSM_ALLCOMPONENTS
)
4408 ret
= EnumWindowStationsW(bcast_winsta
, (LONG_PTR
)&parm
);
4409 else if (*recipients
& BSM_APPLICATIONS
)
4411 EnumWindows(bcast_childwindow
, (LONG_PTR
)&parm
);
4415 FIXME("Recipients %08x not supported!\n", *recipients
);
4420 /***********************************************************************
4421 * SetMessageQueue (USER32.@)
4423 BOOL WINAPI
SetMessageQueue( INT size
)
4425 /* now obsolete the message queue will be expanded dynamically as necessary */
4430 /***********************************************************************
4431 * MessageBeep (USER32.@)
4433 BOOL WINAPI
MessageBeep( UINT i
)
4436 SystemParametersInfoA( SPI_GETBEEP
, 0, &active
, FALSE
);
4437 if (active
) USER_Driver
->pBeep();
4442 /***********************************************************************
4443 * SetCoalescableTimer (USER32.@)
4445 UINT_PTR WINAPI
SetCoalescableTimer( HWND hwnd
, UINT_PTR id
, UINT timeout
, TIMERPROC proc
, ULONG tolerance
)
4448 WNDPROC winproc
= 0;
4450 if (proc
) winproc
= WINPROC_AllocProc( (WNDPROC
)proc
, FALSE
);
4452 timeout
= min( max( USER_TIMER_MINIMUM
, timeout
), USER_TIMER_MAXIMUM
);
4454 SERVER_START_REQ( set_win_timer
)
4456 req
->win
= wine_server_user_handle( hwnd
);
4457 req
->msg
= WM_TIMER
;
4459 req
->rate
= timeout
;
4460 req
->lparam
= (ULONG_PTR
)winproc
;
4461 if (!wine_server_call_err( req
))
4464 if (!ret
) ret
= TRUE
;
4470 TRACE("Added %p %lx %p timeout %d\n", hwnd
, id
, winproc
, timeout
);
4475 /******************************************************************
4476 * SetTimer (USER32.@)
4478 UINT_PTR WINAPI
SetTimer( HWND hwnd
, UINT_PTR id
, UINT timeout
, TIMERPROC proc
)
4480 return SetCoalescableTimer( hwnd
, id
, timeout
, proc
, TIMERV_DEFAULT_COALESCING
);
4484 /***********************************************************************
4485 * SetSystemTimer (USER32.@)
4487 UINT_PTR WINAPI
SetSystemTimer( HWND hwnd
, UINT_PTR id
, UINT timeout
, TIMERPROC proc
)
4490 WNDPROC winproc
= 0;
4492 if (proc
) winproc
= WINPROC_AllocProc( (WNDPROC
)proc
, FALSE
);
4494 timeout
= min( max( USER_TIMER_MINIMUM
, timeout
), USER_TIMER_MAXIMUM
);
4496 SERVER_START_REQ( set_win_timer
)
4498 req
->win
= wine_server_user_handle( hwnd
);
4499 req
->msg
= WM_SYSTIMER
;
4501 req
->rate
= timeout
;
4502 req
->lparam
= (ULONG_PTR
)winproc
;
4503 if (!wine_server_call_err( req
))
4506 if (!ret
) ret
= TRUE
;
4512 TRACE("Added %p %lx %p timeout %d\n", hwnd
, id
, winproc
, timeout
);
4517 /***********************************************************************
4518 * KillTimer (USER32.@)
4520 BOOL WINAPI
KillTimer( HWND hwnd
, UINT_PTR id
)
4524 SERVER_START_REQ( kill_win_timer
)
4526 req
->win
= wine_server_user_handle( hwnd
);
4527 req
->msg
= WM_TIMER
;
4529 ret
= !wine_server_call_err( req
);
4536 /***********************************************************************
4537 * KillSystemTimer (USER32.@)
4539 BOOL WINAPI
KillSystemTimer( HWND hwnd
, UINT_PTR id
)
4543 SERVER_START_REQ( kill_win_timer
)
4545 req
->win
= wine_server_user_handle( hwnd
);
4546 req
->msg
= WM_SYSTIMER
;
4548 ret
= !wine_server_call_err( req
);
4555 /**********************************************************************
4556 * IsGUIThread (USER32.@)
4558 BOOL WINAPI
IsGUIThread( BOOL convert
)
4560 FIXME( "%u: stub\n", convert
);
4565 /**********************************************************************
4566 * GetGUIThreadInfo (USER32.@)
4568 BOOL WINAPI
GetGUIThreadInfo( DWORD id
, GUITHREADINFO
*info
)
4572 if (info
->cbSize
!= sizeof(*info
))
4574 SetLastError( ERROR_INVALID_PARAMETER
);
4578 SERVER_START_REQ( get_thread_input
)
4581 if ((ret
= !wine_server_call_err( req
)))
4584 info
->hwndActive
= wine_server_ptr_handle( reply
->active
);
4585 info
->hwndFocus
= wine_server_ptr_handle( reply
->focus
);
4586 info
->hwndCapture
= wine_server_ptr_handle( reply
->capture
);
4587 info
->hwndMenuOwner
= wine_server_ptr_handle( reply
->menu_owner
);
4588 info
->hwndMoveSize
= wine_server_ptr_handle( reply
->move_size
);
4589 info
->hwndCaret
= wine_server_ptr_handle( reply
->caret
);
4590 info
->rcCaret
.left
= reply
->rect
.left
;
4591 info
->rcCaret
.top
= reply
->rect
.top
;
4592 info
->rcCaret
.right
= reply
->rect
.right
;
4593 info
->rcCaret
.bottom
= reply
->rect
.bottom
;
4594 if (reply
->menu_owner
) info
->flags
|= GUI_INMENUMODE
;
4595 if (reply
->move_size
) info
->flags
|= GUI_INMOVESIZE
;
4596 if (reply
->caret
) info
->flags
|= GUI_CARETBLINKING
;
4604 /******************************************************************
4605 * IsHungAppWindow (USER32.@)
4608 BOOL WINAPI
IsHungAppWindow( HWND hWnd
)
4612 SERVER_START_REQ( is_window_hung
)
4614 req
->win
= wine_server_user_handle( hWnd
);
4615 ret
= !wine_server_call_err( req
) && reply
->is_hung
;
4621 /******************************************************************
4622 * ChangeWindowMessageFilter (USER32.@)
4624 BOOL WINAPI
ChangeWindowMessageFilter( UINT message
, DWORD flag
)
4626 FIXME( "%x %08x\n", message
, flag
);
4630 /******************************************************************
4631 * ChangeWindowMessageFilterEx (USER32.@)
4633 BOOL WINAPI
ChangeWindowMessageFilterEx( HWND hwnd
, UINT message
, DWORD action
, CHANGEFILTERSTRUCT
*changefilter
)
4635 FIXME( "%p %x %d %p\n", hwnd
, message
, action
, changefilter
);