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
= GetKeyboardLayout( 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
)
2295 thread_data
->buffer
->header
.dwSize
= RAWINPUT_BUFFER_SIZE
;
2296 if (!rawinput_from_hardware_message( thread_data
->buffer
, msg_data
)) return FALSE
;
2297 thread_data
->hw_id
= hw_id
;
2298 msg
->lParam
= (LPARAM
)hw_id
;
2301 msg
->pt
= point_phys_to_win_dpi( msg
->hwnd
, msg
->pt
);
2305 /***********************************************************************
2306 * process_keyboard_message
2308 * returns TRUE if the contents of 'msg' should be passed to the application
2310 static BOOL
process_keyboard_message( MSG
*msg
, UINT hw_id
, HWND hwnd_filter
,
2311 UINT first
, UINT last
, BOOL remove
)
2315 if (msg
->message
== WM_KEYDOWN
|| msg
->message
== WM_SYSKEYDOWN
||
2316 msg
->message
== WM_KEYUP
|| msg
->message
== WM_SYSKEYUP
)
2317 switch (msg
->wParam
)
2319 case VK_LSHIFT
: case VK_RSHIFT
:
2320 msg
->wParam
= VK_SHIFT
;
2322 case VK_LCONTROL
: case VK_RCONTROL
:
2323 msg
->wParam
= VK_CONTROL
;
2325 case VK_LMENU
: case VK_RMENU
:
2326 msg
->wParam
= VK_MENU
;
2330 /* FIXME: is this really the right place for this hook? */
2331 event
.message
= msg
->message
;
2332 event
.hwnd
= msg
->hwnd
;
2333 event
.time
= msg
->time
;
2334 event
.paramL
= (msg
->wParam
& 0xFF) | (HIWORD(msg
->lParam
) << 8);
2335 event
.paramH
= msg
->lParam
& 0x7FFF;
2336 if (HIWORD(msg
->lParam
) & 0x0100) event
.paramH
|= 0x8000; /* special_key - bit */
2337 HOOK_CallHooks( WH_JOURNALRECORD
, HC_ACTION
, 0, (LPARAM
)&event
, TRUE
);
2339 /* check message filters */
2340 if (msg
->message
< first
|| msg
->message
> last
) return FALSE
;
2341 if (!check_hwnd_filter( msg
, hwnd_filter
)) return FALSE
;
2345 if((msg
->message
== WM_KEYDOWN
) &&
2346 (msg
->hwnd
!= GetDesktopWindow()))
2348 /* Handle F1 key by sending out WM_HELP message */
2349 if (msg
->wParam
== VK_F1
)
2351 PostMessageW( msg
->hwnd
, WM_KEYF1
, 0, 0 );
2353 else if(msg
->wParam
>= VK_BROWSER_BACK
&&
2354 msg
->wParam
<= VK_LAUNCH_APP2
)
2356 /* FIXME: Process keystate */
2357 SendMessageW(msg
->hwnd
, WM_APPCOMMAND
, (WPARAM
)msg
->hwnd
, MAKELPARAM(0, (FAPPCOMMAND_KEY
| (msg
->wParam
- VK_BROWSER_BACK
+ 1))));
2360 else if (msg
->message
== WM_KEYUP
)
2362 /* Handle VK_APPS key by posting a WM_CONTEXTMENU message */
2363 if (msg
->wParam
== VK_APPS
&& !MENU_IsMenuActive())
2364 PostMessageW(msg
->hwnd
, WM_CONTEXTMENU
, (WPARAM
)msg
->hwnd
, -1);
2368 if (HOOK_CallHooks( WH_KEYBOARD
, remove
? HC_ACTION
: HC_NOREMOVE
,
2369 LOWORD(msg
->wParam
), msg
->lParam
, TRUE
))
2371 /* skip this message */
2372 HOOK_CallHooks( WH_CBT
, HCBT_KEYSKIPPED
, LOWORD(msg
->wParam
), msg
->lParam
, TRUE
);
2373 accept_hardware_message( hw_id
);
2376 if (remove
) accept_hardware_message( hw_id
);
2377 msg
->pt
= point_phys_to_win_dpi( msg
->hwnd
, msg
->pt
);
2379 if ( remove
&& msg
->message
== WM_KEYDOWN
)
2380 if (ImmProcessKey(msg
->hwnd
, GetKeyboardLayout(0), msg
->wParam
, msg
->lParam
, 0) )
2381 msg
->wParam
= VK_PROCESSKEY
;
2387 /***********************************************************************
2388 * process_mouse_message
2390 * returns TRUE if the contents of 'msg' should be passed to the application
2392 static BOOL
process_mouse_message( MSG
*msg
, UINT hw_id
, ULONG_PTR extra_info
, HWND hwnd_filter
,
2393 UINT first
, UINT last
, BOOL remove
)
2402 MOUSEHOOKSTRUCTEX hook
;
2406 /* find the window to dispatch this mouse message to */
2408 info
.cbSize
= sizeof(info
);
2409 GetGUIThreadInfo( GetCurrentThreadId(), &info
);
2410 if (info
.hwndCapture
)
2413 msg
->hwnd
= info
.hwndCapture
;
2417 HWND orig
= msg
->hwnd
;
2419 msg
->hwnd
= WINPOS_WindowFromPoint( msg
->hwnd
, msg
->pt
, &hittest
);
2420 if (!msg
->hwnd
) /* As a heuristic, try the next window if it's the owner of orig */
2422 HWND next
= GetWindow( orig
, GW_HWNDNEXT
);
2424 if (next
&& GetWindow( orig
, GW_OWNER
) == next
&& WIN_IsCurrentThread( next
))
2425 msg
->hwnd
= WINPOS_WindowFromPoint( next
, msg
->pt
, &hittest
);
2429 if (!msg
->hwnd
|| !WIN_IsCurrentThread( msg
->hwnd
))
2431 accept_hardware_message( hw_id
);
2435 msg
->pt
= point_phys_to_win_dpi( msg
->hwnd
, msg
->pt
);
2436 SetThreadDpiAwarenessContext( GetWindowDpiAwarenessContext( msg
->hwnd
));
2438 /* FIXME: is this really the right place for this hook? */
2439 event
.message
= msg
->message
;
2440 event
.time
= msg
->time
;
2441 event
.hwnd
= msg
->hwnd
;
2442 event
.paramL
= msg
->pt
.x
;
2443 event
.paramH
= msg
->pt
.y
;
2444 HOOK_CallHooks( WH_JOURNALRECORD
, HC_ACTION
, 0, (LPARAM
)&event
, TRUE
);
2446 if (!check_hwnd_filter( msg
, hwnd_filter
)) return FALSE
;
2449 message
= msg
->message
;
2450 wparam
= msg
->wParam
;
2451 /* Note: windows has no concept of a non-client wheel message */
2452 if (message
!= WM_MOUSEWHEEL
)
2454 if (hittest
!= HTCLIENT
)
2456 message
+= WM_NCMOUSEMOVE
- WM_MOUSEMOVE
;
2461 /* coordinates don't get translated while tracking a menu */
2462 /* FIXME: should differentiate popups and top-level menus */
2463 if (!(info
.flags
& GUI_INMENUMODE
))
2464 ScreenToClient( msg
->hwnd
, &pt
);
2467 msg
->lParam
= MAKELONG( pt
.x
, pt
.y
);
2469 /* translate double clicks */
2471 if ((msg
->message
== WM_LBUTTONDOWN
) ||
2472 (msg
->message
== WM_RBUTTONDOWN
) ||
2473 (msg
->message
== WM_MBUTTONDOWN
) ||
2474 (msg
->message
== WM_XBUTTONDOWN
))
2476 BOOL update
= remove
;
2478 /* translate double clicks -
2479 * note that ...MOUSEMOVEs can slip in between
2480 * ...BUTTONDOWN and ...BUTTONDBLCLK messages */
2482 if ((info
.flags
& (GUI_INMENUMODE
|GUI_INMOVESIZE
)) ||
2483 hittest
!= HTCLIENT
||
2484 (GetClassLongA( msg
->hwnd
, GCL_STYLE
) & CS_DBLCLKS
))
2486 if ((msg
->message
== clk_msg
.message
) &&
2487 (msg
->hwnd
== clk_msg
.hwnd
) &&
2488 (msg
->wParam
== clk_msg
.wParam
) &&
2489 (msg
->time
- clk_msg
.time
< GetDoubleClickTime()) &&
2490 (abs(msg
->pt
.x
- clk_msg
.pt
.x
) < GetSystemMetrics(SM_CXDOUBLECLK
)/2) &&
2491 (abs(msg
->pt
.y
- clk_msg
.pt
.y
) < GetSystemMetrics(SM_CYDOUBLECLK
)/2))
2493 message
+= (WM_LBUTTONDBLCLK
- WM_LBUTTONDOWN
);
2496 clk_msg
.message
= 0; /* clear the double click conditions */
2501 if (message
< first
|| message
> last
) return FALSE
;
2502 /* update static double click conditions */
2503 if (update
) clk_msg
= *msg
;
2507 if (message
< first
|| message
> last
) return FALSE
;
2509 msg
->wParam
= wparam
;
2511 /* message is accepted now (but may still get dropped) */
2513 hook
.s
.pt
= msg
->pt
;
2514 hook
.s
.hwnd
= msg
->hwnd
;
2515 hook
.s
.wHitTestCode
= hittest
;
2516 hook
.s
.dwExtraInfo
= extra_info
;
2517 hook
.mouseData
= msg
->wParam
;
2518 if (HOOK_CallHooks( WH_MOUSE
, remove
? HC_ACTION
: HC_NOREMOVE
,
2519 message
, (LPARAM
)&hook
, TRUE
))
2521 hook
.s
.pt
= msg
->pt
;
2522 hook
.s
.hwnd
= msg
->hwnd
;
2523 hook
.s
.wHitTestCode
= hittest
;
2524 hook
.s
.dwExtraInfo
= extra_info
;
2525 hook
.mouseData
= msg
->wParam
;
2526 HOOK_CallHooks( WH_CBT
, HCBT_CLICKSKIPPED
, message
, (LPARAM
)&hook
, TRUE
);
2527 accept_hardware_message( hw_id
);
2531 if ((hittest
== HTERROR
) || (hittest
== HTNOWHERE
))
2533 SendMessageW( msg
->hwnd
, WM_SETCURSOR
, (WPARAM
)msg
->hwnd
,
2534 MAKELONG( hittest
, msg
->message
));
2535 accept_hardware_message( hw_id
);
2539 if (remove
) accept_hardware_message( hw_id
);
2541 if (!remove
|| info
.hwndCapture
)
2543 msg
->message
= message
;
2549 if ((msg
->message
== WM_LBUTTONDOWN
) ||
2550 (msg
->message
== WM_RBUTTONDOWN
) ||
2551 (msg
->message
== WM_MBUTTONDOWN
) ||
2552 (msg
->message
== WM_XBUTTONDOWN
))
2554 /* Send the WM_PARENTNOTIFY,
2555 * note that even for double/nonclient clicks
2556 * notification message is still WM_L/M/RBUTTONDOWN.
2558 send_parent_notify( msg
->hwnd
, msg
->message
, 0, msg
->pt
);
2560 /* Activate the window if needed */
2562 if (msg
->hwnd
!= info
.hwndActive
)
2564 HWND hwndTop
= GetAncestor( msg
->hwnd
, GA_ROOT
);
2566 if ((GetWindowLongW( hwndTop
, GWL_STYLE
) & (WS_POPUP
|WS_CHILD
)) != WS_CHILD
)
2568 LONG ret
= SendMessageW( msg
->hwnd
, WM_MOUSEACTIVATE
, (WPARAM
)hwndTop
,
2569 MAKELONG( hittest
, msg
->message
) );
2572 case MA_NOACTIVATEANDEAT
:
2577 case MA_ACTIVATEANDEAT
:
2582 if (!FOCUS_MouseActivate( hwndTop
)) eatMsg
= TRUE
;
2585 WARN( "unknown WM_MOUSEACTIVATE code %d\n", ret
);
2592 /* send the WM_SETCURSOR message */
2594 /* Windows sends the normal mouse message as the message parameter
2595 in the WM_SETCURSOR message even if it's non-client mouse message */
2596 SendMessageW( msg
->hwnd
, WM_SETCURSOR
, (WPARAM
)msg
->hwnd
, MAKELONG( hittest
, msg
->message
));
2598 msg
->message
= message
;
2603 /***********************************************************************
2604 * process_hardware_message
2606 * Process a hardware message; return TRUE if message should be passed on to the app
2608 static BOOL
process_hardware_message( MSG
*msg
, UINT hw_id
, const struct hardware_msg_data
*msg_data
,
2609 HWND hwnd_filter
, UINT first
, UINT last
, BOOL remove
)
2611 DPI_AWARENESS_CONTEXT context
;
2614 get_user_thread_info()->msg_source
.deviceType
= msg_data
->source
.device
;
2615 get_user_thread_info()->msg_source
.originId
= msg_data
->source
.origin
;
2617 /* hardware messages are always in physical coords */
2618 context
= SetThreadDpiAwarenessContext( DPI_AWARENESS_CONTEXT_PER_MONITOR_AWARE
);
2620 if (msg
->message
== WM_INPUT
|| msg
->message
== WM_INPUT_DEVICE_CHANGE
)
2621 ret
= process_rawinput_message( msg
, hw_id
, msg_data
);
2622 else if (is_keyboard_message( msg
->message
))
2623 ret
= process_keyboard_message( msg
, hw_id
, hwnd_filter
, first
, last
, remove
);
2624 else if (is_mouse_message( msg
->message
))
2625 ret
= process_mouse_message( msg
, hw_id
, msg_data
->info
, hwnd_filter
, first
, last
, remove
);
2627 ERR( "unknown message type %x\n", msg
->message
);
2628 SetThreadDpiAwarenessContext( context
);
2633 /***********************************************************************
2634 * call_sendmsg_callback
2636 * Call the callback function of SendMessageCallback.
2638 static inline void call_sendmsg_callback( SENDASYNCPROC callback
, HWND hwnd
, UINT msg
,
2639 ULONG_PTR data
, LRESULT result
)
2641 if (!callback
) return;
2643 TRACE_(relay
)( "\1Call message callback %p (hwnd=%p,msg=%s,data=%08lx,result=%08lx)\n",
2644 callback
, hwnd
, SPY_GetMsgName( msg
, hwnd
), data
, result
);
2645 callback( hwnd
, msg
, data
, result
);
2646 TRACE_(relay
)( "\1Ret message callback %p (hwnd=%p,msg=%s,data=%08lx,result=%08lx)\n",
2647 callback
, hwnd
, SPY_GetMsgName( msg
, hwnd
), data
, result
);
2651 /***********************************************************************
2654 * Peek for a message matching the given parameters. Return 0 if none are
2655 * available; -1 on error.
2656 * All pending sent messages are processed before returning.
2658 static int peek_message( MSG
*msg
, HWND hwnd
, UINT first
, UINT last
, UINT flags
, UINT changed_mask
)
2661 struct user_thread_info
*thread_info
= get_user_thread_info();
2662 INPUT_MESSAGE_SOURCE prev_source
= thread_info
->msg_source
;
2663 struct received_message_info info
, *old_info
;
2664 unsigned int hw_id
= 0; /* id of previous hardware message */
2666 size_t buffer_size
= 256;
2668 if (!(buffer
= HeapAlloc( GetProcessHeap(), 0, buffer_size
))) return -1;
2670 if (!first
&& !last
) last
= ~0;
2671 if (hwnd
== HWND_BROADCAST
) hwnd
= HWND_TOPMOST
;
2677 const message_data_t
*msg_data
= buffer
;
2679 thread_info
->msg_source
= prev_source
;
2681 SERVER_START_REQ( get_message
)
2684 req
->get_win
= wine_server_user_handle( hwnd
);
2685 req
->get_first
= first
;
2686 req
->get_last
= last
;
2688 req
->wake_mask
= changed_mask
& (QS_SENDMESSAGE
| QS_SMRESULT
);
2689 req
->changed_mask
= changed_mask
;
2690 wine_server_set_reply( req
, buffer
, buffer_size
);
2691 if (!(res
= wine_server_call( req
)))
2693 size
= wine_server_reply_size( reply
);
2694 info
.type
= reply
->type
;
2695 info
.msg
.hwnd
= wine_server_ptr_handle( reply
->win
);
2696 info
.msg
.message
= reply
->msg
;
2697 info
.msg
.wParam
= reply
->wparam
;
2698 info
.msg
.lParam
= reply
->lparam
;
2699 info
.msg
.time
= reply
->time
;
2700 info
.msg
.pt
.x
= reply
->x
;
2701 info
.msg
.pt
.y
= reply
->y
;
2703 thread_info
->active_hooks
= reply
->active_hooks
;
2705 else buffer_size
= reply
->total
;
2711 HeapFree( GetProcessHeap(), 0, buffer
);
2712 if (res
== STATUS_PENDING
)
2714 thread_info
->wake_mask
= changed_mask
& (QS_SENDMESSAGE
| QS_SMRESULT
);
2715 thread_info
->changed_mask
= changed_mask
;
2718 if (res
!= STATUS_BUFFER_OVERFLOW
)
2720 SetLastError( RtlNtStatusToDosError(res
) );
2723 if (!(buffer
= HeapAlloc( GetProcessHeap(), 0, buffer_size
))) return -1;
2727 TRACE( "got type %d msg %x (%s) hwnd %p wp %lx lp %lx\n",
2728 info
.type
, info
.msg
.message
,
2729 (info
.type
== MSG_WINEVENT
) ? "MSG_WINEVENT" : SPY_GetMsgName(info
.msg
.message
, info
.msg
.hwnd
),
2730 info
.msg
.hwnd
, info
.msg
.wParam
, info
.msg
.lParam
);
2736 info
.flags
= ISMEX_SEND
;
2739 info
.flags
= ISMEX_NOTIFY
;
2740 if (!unpack_message( info
.msg
.hwnd
, info
.msg
.message
, &info
.msg
.wParam
,
2741 &info
.msg
.lParam
, &buffer
, size
))
2745 info
.flags
= ISMEX_CALLBACK
;
2747 case MSG_CALLBACK_RESULT
:
2748 if (size
>= sizeof(msg_data
->callback
))
2749 call_sendmsg_callback( wine_server_get_ptr(msg_data
->callback
.callback
),
2750 info
.msg
.hwnd
, info
.msg
.message
,
2751 msg_data
->callback
.data
, msg_data
->callback
.result
);
2754 if (size
>= sizeof(msg_data
->winevent
))
2756 WINEVENTPROC hook_proc
;
2757 HMODULE free_module
= 0;
2759 hook_proc
= wine_server_get_ptr( msg_data
->winevent
.hook_proc
);
2760 size
-= sizeof(msg_data
->winevent
);
2763 WCHAR module
[MAX_PATH
];
2765 size
= min( size
, (MAX_PATH
- 1) * sizeof(WCHAR
) );
2766 memcpy( module
, &msg_data
->winevent
+ 1, size
);
2767 module
[size
/ sizeof(WCHAR
)] = 0;
2768 if (!(hook_proc
= get_hook_proc( hook_proc
, module
, &free_module
)))
2770 ERR( "invalid winevent hook module name %s\n", debugstr_w(module
) );
2775 TRACE_(relay
)( "\1Call winevent proc %p (hook=%04x,event=%x,hwnd=%p,object_id=%lx,child_id=%lx,tid=%04x,time=%x)\n",
2776 hook_proc
, msg_data
->winevent
.hook
, info
.msg
.message
, info
.msg
.hwnd
,
2777 info
.msg
.wParam
, info
.msg
.lParam
, msg_data
->winevent
.tid
, info
.msg
.time
);
2779 hook_proc( wine_server_ptr_handle( msg_data
->winevent
.hook
), info
.msg
.message
,
2780 info
.msg
.hwnd
, info
.msg
.wParam
, info
.msg
.lParam
,
2781 msg_data
->winevent
.tid
, info
.msg
.time
);
2783 TRACE_(relay
)( "\1Ret winevent proc %p (hook=%04x,event=%x,hwnd=%p,object_id=%lx,child_id=%lx,tid=%04x,time=%x)\n",
2784 hook_proc
, msg_data
->winevent
.hook
, info
.msg
.message
, info
.msg
.hwnd
,
2785 info
.msg
.wParam
, info
.msg
.lParam
, msg_data
->winevent
.tid
, info
.msg
.time
);
2787 if (free_module
) FreeLibrary(free_module
);
2791 info
.flags
= ISMEX_SEND
;
2793 if (info
.msg
.message
== WH_KEYBOARD_LL
&& size
>= sizeof(msg_data
->hardware
))
2795 KBDLLHOOKSTRUCT hook
;
2797 hook
.vkCode
= LOWORD( info
.msg
.lParam
);
2798 hook
.scanCode
= HIWORD( info
.msg
.lParam
);
2799 hook
.flags
= msg_data
->hardware
.flags
;
2800 hook
.time
= info
.msg
.time
;
2801 hook
.dwExtraInfo
= msg_data
->hardware
.info
;
2802 TRACE( "calling keyboard LL hook vk %x scan %x flags %x time %u info %lx\n",
2803 hook
.vkCode
, hook
.scanCode
, hook
.flags
, hook
.time
, hook
.dwExtraInfo
);
2804 result
= HOOK_CallHooks( WH_KEYBOARD_LL
, HC_ACTION
, info
.msg
.wParam
, (LPARAM
)&hook
, TRUE
);
2806 else if (info
.msg
.message
== WH_MOUSE_LL
&& size
>= sizeof(msg_data
->hardware
))
2808 MSLLHOOKSTRUCT hook
;
2810 hook
.pt
= info
.msg
.pt
;
2811 hook
.mouseData
= info
.msg
.lParam
;
2812 hook
.flags
= msg_data
->hardware
.flags
;
2813 hook
.time
= info
.msg
.time
;
2814 hook
.dwExtraInfo
= msg_data
->hardware
.info
;
2815 TRACE( "calling mouse LL hook pos %d,%d data %x flags %x time %u info %lx\n",
2816 hook
.pt
.x
, hook
.pt
.y
, hook
.mouseData
, hook
.flags
, hook
.time
, hook
.dwExtraInfo
);
2817 result
= HOOK_CallHooks( WH_MOUSE_LL
, HC_ACTION
, info
.msg
.wParam
, (LPARAM
)&hook
, TRUE
);
2819 reply_message( &info
, result
, TRUE
);
2821 case MSG_OTHER_PROCESS
:
2822 info
.flags
= ISMEX_SEND
;
2823 if (!unpack_message( info
.msg
.hwnd
, info
.msg
.message
, &info
.msg
.wParam
,
2824 &info
.msg
.lParam
, &buffer
, size
))
2827 reply_message( &info
, 0, TRUE
);
2832 if (size
>= sizeof(msg_data
->hardware
))
2834 hw_id
= msg_data
->hardware
.hw_id
;
2835 if (!process_hardware_message( &info
.msg
, hw_id
, &msg_data
->hardware
,
2836 hwnd
, first
, last
, flags
& PM_REMOVE
))
2838 TRACE("dropping msg %x\n", info
.msg
.message
);
2839 continue; /* ignore it */
2842 thread_info
->GetMessagePosVal
= MAKELONG( info
.msg
.pt
.x
, info
.msg
.pt
.y
);
2843 thread_info
->GetMessageTimeVal
= info
.msg
.time
;
2844 thread_info
->GetMessageExtraInfoVal
= msg_data
->hardware
.info
;
2845 HeapFree( GetProcessHeap(), 0, buffer
);
2846 HOOK_CallHooks( WH_GETMESSAGE
, HC_ACTION
, flags
& PM_REMOVE
, (LPARAM
)msg
, TRUE
);
2851 if (info
.msg
.message
& 0x80000000) /* internal message */
2853 if (flags
& PM_REMOVE
)
2855 handle_internal_message( info
.msg
.hwnd
, info
.msg
.message
,
2856 info
.msg
.wParam
, info
.msg
.lParam
);
2857 /* if this is a nested call return right away */
2858 if (first
== info
.msg
.message
&& last
== info
.msg
.message
)
2860 HeapFree( GetProcessHeap(), 0, buffer
);
2865 peek_message( msg
, info
.msg
.hwnd
, info
.msg
.message
,
2866 info
.msg
.message
, flags
| PM_REMOVE
, changed_mask
);
2869 if (info
.msg
.message
>= WM_DDE_FIRST
&& info
.msg
.message
<= WM_DDE_LAST
)
2871 if (!unpack_dde_message( info
.msg
.hwnd
, info
.msg
.message
, &info
.msg
.wParam
,
2872 &info
.msg
.lParam
, &buffer
, size
))
2873 continue; /* ignore it */
2876 msg
->pt
= point_phys_to_win_dpi( info
.msg
.hwnd
, info
.msg
.pt
);
2877 thread_info
->GetMessagePosVal
= MAKELONG( msg
->pt
.x
, msg
->pt
.y
);
2878 thread_info
->GetMessageTimeVal
= info
.msg
.time
;
2879 thread_info
->GetMessageExtraInfoVal
= 0;
2880 thread_info
->msg_source
= msg_source_unavailable
;
2881 HeapFree( GetProcessHeap(), 0, buffer
);
2882 HOOK_CallHooks( WH_GETMESSAGE
, HC_ACTION
, flags
& PM_REMOVE
, (LPARAM
)msg
, TRUE
);
2886 /* if we get here, we have a sent message; call the window procedure */
2887 old_info
= thread_info
->receive_info
;
2888 thread_info
->receive_info
= &info
;
2889 thread_info
->msg_source
= msg_source_unavailable
;
2890 result
= call_window_proc( info
.msg
.hwnd
, info
.msg
.message
, info
.msg
.wParam
,
2891 info
.msg
.lParam
, (info
.type
!= MSG_ASCII
), FALSE
,
2892 WMCHAR_MAP_RECVMESSAGE
);
2893 reply_message( &info
, result
, TRUE
);
2894 thread_info
->receive_info
= old_info
;
2896 /* if some PM_QS* flags were specified, only handle sent messages from now on */
2897 if (HIWORD(flags
) && !changed_mask
) flags
= PM_QS_SENDMESSAGE
| LOWORD(flags
);
2902 /***********************************************************************
2903 * process_sent_messages
2905 * Process all pending sent messages.
2907 static inline void process_sent_messages(void)
2910 peek_message( &msg
, 0, 0, 0, PM_REMOVE
| PM_QS_SENDMESSAGE
, 0 );
2914 /***********************************************************************
2915 * get_server_queue_handle
2917 * Get a handle to the server message queue for the current thread.
2919 static HANDLE
get_server_queue_handle(void)
2921 struct user_thread_info
*thread_info
= get_user_thread_info();
2924 if (!(ret
= thread_info
->server_queue
))
2926 SERVER_START_REQ( get_msg_queue
)
2928 wine_server_call( req
);
2929 ret
= wine_server_ptr_handle( reply
->handle
);
2932 thread_info
->server_queue
= ret
;
2933 if (!ret
) ERR( "Cannot get server thread queue\n" );
2939 /***********************************************************************
2940 * wait_message_reply
2942 * Wait until a sent message gets replied to.
2944 static void wait_message_reply( UINT flags
)
2946 struct user_thread_info
*thread_info
= get_user_thread_info();
2947 HANDLE server_queue
= get_server_queue_handle();
2948 unsigned int wake_mask
= QS_SMRESULT
| ((flags
& SMTO_BLOCK
) ? 0 : QS_SENDMESSAGE
);
2952 unsigned int wake_bits
= 0;
2954 SERVER_START_REQ( set_queue_mask
)
2956 req
->wake_mask
= wake_mask
;
2957 req
->changed_mask
= wake_mask
;
2959 if (!wine_server_call( req
)) wake_bits
= reply
->wake_bits
& wake_mask
;
2963 thread_info
->wake_mask
= thread_info
->changed_mask
= 0;
2965 if (wake_bits
& QS_SMRESULT
) return; /* got a result */
2966 if (wake_bits
& QS_SENDMESSAGE
)
2968 /* Process the sent message immediately */
2969 process_sent_messages();
2973 wow_handlers
.wait_message( 1, &server_queue
, INFINITE
, wake_mask
, 0 );
2978 /***********************************************************************
2981 * Wait for multiple objects including the server queue, with specific queue masks.
2983 static DWORD
wait_objects( DWORD count
, const HANDLE
*handles
, DWORD timeout
,
2984 DWORD wake_mask
, DWORD changed_mask
, DWORD flags
)
2986 struct user_thread_info
*thread_info
= get_user_thread_info();
2989 assert( count
); /* we must have at least the server queue */
2991 flush_window_surfaces( TRUE
);
2993 if (thread_info
->wake_mask
!= wake_mask
|| thread_info
->changed_mask
!= changed_mask
)
2995 SERVER_START_REQ( set_queue_mask
)
2997 req
->wake_mask
= wake_mask
;
2998 req
->changed_mask
= changed_mask
;
3000 wine_server_call( req
);
3003 thread_info
->wake_mask
= wake_mask
;
3004 thread_info
->changed_mask
= changed_mask
;
3007 ret
= wow_handlers
.wait_message( count
, handles
, timeout
, changed_mask
, flags
);
3009 if (ret
!= WAIT_TIMEOUT
) thread_info
->wake_mask
= thread_info
->changed_mask
= 0;
3014 /***********************************************************************
3015 * put_message_in_queue
3017 * Put a sent message into the destination queue.
3018 * For inter-process message, reply_size is set to expected size of reply data.
3020 static BOOL
put_message_in_queue( const struct send_message_info
*info
, size_t *reply_size
)
3022 struct packed_message data
;
3023 message_data_t msg_data
;
3026 timeout_t timeout
= TIMEOUT_INFINITE
;
3028 /* Check for INFINITE timeout for compatibility with Win9x,
3029 * although Windows >= NT does not do so
3031 if (info
->type
!= MSG_NOTIFY
&&
3032 info
->type
!= MSG_CALLBACK
&&
3033 info
->type
!= MSG_POSTED
&&
3035 info
->timeout
!= INFINITE
)
3037 /* timeout is signed despite the prototype */
3038 timeout
= (timeout_t
)max( 0, (int)info
->timeout
) * -10000;
3041 memset( &data
, 0, sizeof(data
) );
3042 if (info
->type
== MSG_OTHER_PROCESS
|| info
->type
== MSG_NOTIFY
)
3044 *reply_size
= pack_message( info
->hwnd
, info
->msg
, info
->wparam
, info
->lparam
, &data
);
3045 if (data
.count
== -1)
3047 WARN( "cannot pack message %x\n", info
->msg
);
3051 else if (info
->type
== MSG_CALLBACK
)
3053 msg_data
.callback
.callback
= wine_server_client_ptr( info
->callback
);
3054 msg_data
.callback
.data
= info
->data
;
3055 msg_data
.callback
.result
= 0;
3056 data
.data
[0] = &msg_data
;
3057 data
.size
[0] = sizeof(msg_data
.callback
);
3060 else if (info
->type
== MSG_POSTED
&& info
->msg
>= WM_DDE_FIRST
&& info
->msg
<= WM_DDE_LAST
)
3062 return post_dde_message( &data
, info
);
3065 SERVER_START_REQ( send_message
)
3067 req
->id
= info
->dest_tid
;
3068 req
->type
= info
->type
;
3070 req
->win
= wine_server_user_handle( info
->hwnd
);
3071 req
->msg
= info
->msg
;
3072 req
->wparam
= info
->wparam
;
3073 req
->lparam
= info
->lparam
;
3074 req
->timeout
= timeout
;
3076 if (info
->flags
& SMTO_ABORTIFHUNG
) req
->flags
|= SEND_MSG_ABORT_IF_HUNG
;
3077 for (i
= 0; i
< data
.count
; i
++) wine_server_add_data( req
, data
.data
[i
], data
.size
[i
] );
3078 if ((res
= wine_server_call( req
)))
3080 if (res
== STATUS_INVALID_PARAMETER
)
3081 /* FIXME: find a STATUS_ value for this one */
3082 SetLastError( ERROR_INVALID_THREAD_ID
);
3084 SetLastError( RtlNtStatusToDosError(res
) );
3092 /***********************************************************************
3095 * Retrieve a message reply from the server.
3097 static LRESULT
retrieve_reply( const struct send_message_info
*info
,
3098 size_t reply_size
, LRESULT
*result
)
3101 void *reply_data
= NULL
;
3105 if (!(reply_data
= HeapAlloc( GetProcessHeap(), 0, reply_size
)))
3107 WARN( "no memory for reply, will be truncated\n" );
3111 SERVER_START_REQ( get_message_reply
)
3114 if (reply_size
) wine_server_set_reply( req
, reply_data
, reply_size
);
3115 if (!(status
= wine_server_call( req
))) *result
= reply
->result
;
3116 reply_size
= wine_server_reply_size( reply
);
3119 if (!status
&& reply_size
)
3120 unpack_reply( info
->hwnd
, info
->msg
, info
->wparam
, info
->lparam
, reply_data
, reply_size
);
3122 HeapFree( GetProcessHeap(), 0, reply_data
);
3124 TRACE( "hwnd %p msg %x (%s) wp %lx lp %lx got reply %lx (err=%d)\n",
3125 info
->hwnd
, info
->msg
, SPY_GetMsgName(info
->msg
, info
->hwnd
), info
->wparam
,
3126 info
->lparam
, *result
, status
);
3128 /* MSDN states that last error is 0 on timeout, but at least NT4 returns ERROR_TIMEOUT */
3129 if (status
) SetLastError( RtlNtStatusToDosError(status
) );
3134 /***********************************************************************
3135 * send_inter_thread_message
3137 static LRESULT
send_inter_thread_message( const struct send_message_info
*info
, LRESULT
*res_ptr
)
3139 size_t reply_size
= 0;
3141 TRACE( "hwnd %p msg %x (%s) wp %lx lp %lx\n",
3142 info
->hwnd
, info
->msg
, SPY_GetMsgName(info
->msg
, info
->hwnd
), info
->wparam
, info
->lparam
);
3144 USER_CheckNotLock();
3146 if (!put_message_in_queue( info
, &reply_size
)) return 0;
3148 /* there's no reply to wait for on notify/callback messages */
3149 if (info
->type
== MSG_NOTIFY
|| info
->type
== MSG_CALLBACK
) return 1;
3151 wait_message_reply( info
->flags
);
3152 return retrieve_reply( info
, reply_size
, res_ptr
);
3156 /***********************************************************************
3157 * send_inter_thread_callback
3159 static LRESULT
send_inter_thread_callback( HWND hwnd
, UINT msg
, WPARAM wp
, LPARAM lp
,
3160 LRESULT
*result
, void *arg
)
3162 struct send_message_info
*info
= arg
;
3167 return send_inter_thread_message( info
, result
);
3170 static BOOL
is_message_broadcastable(UINT msg
)
3172 return msg
< WM_USER
|| msg
>= 0xc000;
3175 /***********************************************************************
3178 * Backend implementation of the various SendMessage functions.
3180 static BOOL
send_message( struct send_message_info
*info
, DWORD_PTR
*res_ptr
, BOOL unicode
)
3182 struct user_thread_info
*thread_info
= get_user_thread_info();
3183 INPUT_MESSAGE_SOURCE prev_source
= thread_info
->msg_source
;
3188 if (is_broadcast(info
->hwnd
))
3190 if (is_message_broadcastable( info
->msg
))
3191 EnumWindows( broadcast_message_callback
, (LPARAM
)info
);
3192 if (res_ptr
) *res_ptr
= 1;
3196 if (!(info
->dest_tid
= GetWindowThreadProcessId( info
->hwnd
, &dest_pid
))) return FALSE
;
3198 if (USER_IsExitingThread( info
->dest_tid
)) return FALSE
;
3200 thread_info
->msg_source
= msg_source_unavailable
;
3201 SPY_EnterMessage( SPY_SENDMESSAGE
, info
->hwnd
, info
->msg
, info
->wparam
, info
->lparam
);
3203 if (info
->dest_tid
== GetCurrentThreadId())
3205 result
= call_window_proc( info
->hwnd
, info
->msg
, info
->wparam
, info
->lparam
,
3206 unicode
, TRUE
, info
->wm_char
);
3207 if (info
->type
== MSG_CALLBACK
)
3208 call_sendmsg_callback( info
->callback
, info
->hwnd
, info
->msg
, info
->data
, result
);
3213 if (dest_pid
!= GetCurrentProcessId() && (info
->type
== MSG_ASCII
|| info
->type
== MSG_UNICODE
))
3214 info
->type
= MSG_OTHER_PROCESS
;
3216 /* MSG_ASCII can be sent unconverted except for WM_CHAR; everything else needs to be Unicode */
3217 if (!unicode
&& is_unicode_message( info
->msg
) &&
3218 (info
->type
!= MSG_ASCII
|| info
->msg
== WM_CHAR
))
3219 ret
= WINPROC_CallProcAtoW( send_inter_thread_callback
, info
->hwnd
, info
->msg
,
3220 info
->wparam
, info
->lparam
, &result
, info
, info
->wm_char
);
3222 ret
= send_inter_thread_message( info
, &result
);
3225 SPY_ExitMessage( SPY_RESULT_OK
, info
->hwnd
, info
->msg
, result
, info
->wparam
, info
->lparam
);
3226 thread_info
->msg_source
= prev_source
;
3227 if (ret
&& res_ptr
) *res_ptr
= result
;
3232 /***********************************************************************
3233 * send_hardware_message
3235 NTSTATUS
send_hardware_message( HWND hwnd
, const INPUT
*input
, const RAWINPUT
*rawinput
, UINT flags
)
3237 struct user_key_state_info
*key_state_info
= get_user_thread_info()->key_state
;
3238 struct send_message_info info
;
3239 int prev_x
, prev_y
, new_x
, new_y
;
3240 INT counter
= global_key_state_counter
;
3241 USAGE hid_usage_page
, hid_usage
;
3245 info
.type
= MSG_HARDWARE
;
3251 if (input
->type
== INPUT_HARDWARE
&& rawinput
->header
.dwType
== RIM_TYPEHID
)
3253 if (input
->u
.hi
.uMsg
== WM_INPUT_DEVICE_CHANGE
)
3255 hid_usage_page
= ((USAGE
*)rawinput
->data
.hid
.bRawData
)[0];
3256 hid_usage
= ((USAGE
*)rawinput
->data
.hid
.bRawData
)[1];
3258 if (input
->u
.hi
.uMsg
== WM_INPUT
)
3260 if (!rawinput_device_get_usages( rawinput
->header
.hDevice
, &hid_usage_page
, &hid_usage
))
3262 WARN( "unable to get HID usages for device %p\n", rawinput
->header
.hDevice
);
3263 return STATUS_INVALID_HANDLE
;
3268 SERVER_START_REQ( send_hardware_message
)
3270 req
->win
= wine_server_user_handle( hwnd
);
3272 req
->input
.type
= input
->type
;
3273 switch (input
->type
)
3276 req
->input
.mouse
.x
= input
->u
.mi
.dx
;
3277 req
->input
.mouse
.y
= input
->u
.mi
.dy
;
3278 req
->input
.mouse
.data
= input
->u
.mi
.mouseData
;
3279 req
->input
.mouse
.flags
= input
->u
.mi
.dwFlags
;
3280 req
->input
.mouse
.time
= input
->u
.mi
.time
;
3281 req
->input
.mouse
.info
= input
->u
.mi
.dwExtraInfo
;
3283 case INPUT_KEYBOARD
:
3284 req
->input
.kbd
.vkey
= input
->u
.ki
.wVk
;
3285 req
->input
.kbd
.scan
= input
->u
.ki
.wScan
;
3286 req
->input
.kbd
.flags
= input
->u
.ki
.dwFlags
;
3287 req
->input
.kbd
.time
= input
->u
.ki
.time
;
3288 req
->input
.kbd
.info
= input
->u
.ki
.dwExtraInfo
;
3290 case INPUT_HARDWARE
:
3291 req
->input
.hw
.msg
= input
->u
.hi
.uMsg
;
3292 req
->input
.hw
.lparam
= MAKELONG( input
->u
.hi
.wParamL
, input
->u
.hi
.wParamH
);
3293 switch (input
->u
.hi
.uMsg
)
3296 case WM_INPUT_DEVICE_CHANGE
:
3297 req
->input
.hw
.rawinput
.type
= rawinput
->header
.dwType
;
3298 switch (rawinput
->header
.dwType
)
3301 req
->input
.hw
.rawinput
.hid
.device
= HandleToUlong( rawinput
->header
.hDevice
);
3302 req
->input
.hw
.rawinput
.hid
.param
= rawinput
->header
.wParam
;
3303 req
->input
.hw
.rawinput
.hid
.usage_page
= hid_usage_page
;
3304 req
->input
.hw
.rawinput
.hid
.usage
= hid_usage
;
3305 req
->input
.hw
.rawinput
.hid
.count
= rawinput
->data
.hid
.dwCount
;
3306 req
->input
.hw
.rawinput
.hid
.length
= rawinput
->data
.hid
.dwSizeHid
;
3307 wine_server_add_data( req
, rawinput
->data
.hid
.bRawData
,
3308 rawinput
->data
.hid
.dwCount
* rawinput
->data
.hid
.dwSizeHid
);
3317 if (key_state_info
) wine_server_set_reply( req
, key_state_info
->state
,
3318 sizeof(key_state_info
->state
) );
3319 ret
= wine_server_call( req
);
3321 prev_x
= reply
->prev_x
;
3322 prev_y
= reply
->prev_y
;
3323 new_x
= reply
->new_x
;
3324 new_y
= reply
->new_y
;
3332 key_state_info
->time
= GetTickCount();
3333 key_state_info
->counter
= counter
;
3335 if ((flags
& SEND_HWMSG_INJECTED
) && (prev_x
!= new_x
|| prev_y
!= new_y
))
3336 USER_Driver
->pSetCursorPos( new_x
, new_y
);
3342 wait_message_reply( 0 );
3343 retrieve_reply( &info
, 0, &ignored
);
3349 /***********************************************************************
3350 * MSG_SendInternalMessageTimeout
3352 * Same as SendMessageTimeoutW but sends the message to a specific thread
3353 * without requiring a window handle. Only works for internal Wine messages.
3355 LRESULT
MSG_SendInternalMessageTimeout( DWORD dest_pid
, DWORD dest_tid
,
3356 UINT msg
, WPARAM wparam
, LPARAM lparam
,
3357 UINT flags
, UINT timeout
, PDWORD_PTR res_ptr
)
3359 struct send_message_info info
;
3360 LRESULT ret
, result
;
3362 assert( msg
& 0x80000000 ); /* must be an internal Wine message */
3364 info
.type
= MSG_UNICODE
;
3365 info
.dest_tid
= dest_tid
;
3368 info
.wparam
= wparam
;
3369 info
.lparam
= lparam
;
3371 info
.timeout
= timeout
;
3373 if (USER_IsExitingThread( dest_tid
)) return 0;
3375 if (dest_tid
== GetCurrentThreadId())
3377 result
= handle_internal_message( 0, msg
, wparam
, lparam
);
3382 if (dest_pid
!= GetCurrentProcessId()) info
.type
= MSG_OTHER_PROCESS
;
3383 ret
= send_inter_thread_message( &info
, &result
);
3385 if (ret
&& res_ptr
) *res_ptr
= result
;
3390 /***********************************************************************
3391 * SendMessageTimeoutW (USER32.@)
3393 LRESULT WINAPI
SendMessageTimeoutW( HWND hwnd
, UINT msg
, WPARAM wparam
, LPARAM lparam
,
3394 UINT flags
, UINT timeout
, PDWORD_PTR res_ptr
)
3396 struct send_message_info info
;
3398 info
.type
= MSG_UNICODE
;
3401 info
.wparam
= wparam
;
3402 info
.lparam
= lparam
;
3404 info
.timeout
= timeout
;
3406 return send_message( &info
, res_ptr
, TRUE
);
3409 /***********************************************************************
3410 * SendMessageTimeoutA (USER32.@)
3412 LRESULT WINAPI
SendMessageTimeoutA( HWND hwnd
, UINT msg
, WPARAM wparam
, LPARAM lparam
,
3413 UINT flags
, UINT timeout
, PDWORD_PTR res_ptr
)
3415 struct send_message_info info
;
3417 info
.type
= MSG_ASCII
;
3420 info
.wparam
= wparam
;
3421 info
.lparam
= lparam
;
3423 info
.timeout
= timeout
;
3424 info
.wm_char
= WMCHAR_MAP_SENDMESSAGETIMEOUT
;
3426 return send_message( &info
, res_ptr
, FALSE
);
3430 /***********************************************************************
3431 * SendMessageW (USER32.@)
3433 LRESULT WINAPI
SendMessageW( HWND hwnd
, UINT msg
, WPARAM wparam
, LPARAM lparam
)
3436 struct send_message_info info
;
3438 info
.type
= MSG_UNICODE
;
3441 info
.wparam
= wparam
;
3442 info
.lparam
= lparam
;
3443 info
.flags
= SMTO_NORMAL
;
3446 send_message( &info
, &res
, TRUE
);
3451 /***********************************************************************
3452 * SendMessageA (USER32.@)
3454 LRESULT WINAPI
SendMessageA( HWND hwnd
, UINT msg
, WPARAM wparam
, LPARAM lparam
)
3457 struct send_message_info info
;
3459 info
.type
= MSG_ASCII
;
3462 info
.wparam
= wparam
;
3463 info
.lparam
= lparam
;
3464 info
.flags
= SMTO_NORMAL
;
3466 info
.wm_char
= WMCHAR_MAP_SENDMESSAGE
;
3468 send_message( &info
, &res
, FALSE
);
3473 /***********************************************************************
3474 * SendNotifyMessageA (USER32.@)
3476 BOOL WINAPI
SendNotifyMessageA( HWND hwnd
, UINT msg
, WPARAM wparam
, LPARAM lparam
)
3478 struct send_message_info info
;
3480 if (is_pointer_message( msg
, wparam
))
3482 SetLastError( ERROR_MESSAGE_SYNC_ONLY
);
3486 info
.type
= MSG_NOTIFY
;
3489 info
.wparam
= wparam
;
3490 info
.lparam
= lparam
;
3492 info
.wm_char
= WMCHAR_MAP_SENDMESSAGETIMEOUT
;
3494 return send_message( &info
, NULL
, FALSE
);
3498 /***********************************************************************
3499 * SendNotifyMessageW (USER32.@)
3501 BOOL WINAPI
SendNotifyMessageW( HWND hwnd
, UINT msg
, WPARAM wparam
, LPARAM lparam
)
3503 struct send_message_info info
;
3505 if (is_pointer_message( msg
, wparam
))
3507 SetLastError( ERROR_MESSAGE_SYNC_ONLY
);
3511 info
.type
= MSG_NOTIFY
;
3514 info
.wparam
= wparam
;
3515 info
.lparam
= lparam
;
3518 return send_message( &info
, NULL
, TRUE
);
3522 /***********************************************************************
3523 * SendMessageCallbackA (USER32.@)
3525 BOOL WINAPI
SendMessageCallbackA( HWND hwnd
, UINT msg
, WPARAM wparam
, LPARAM lparam
,
3526 SENDASYNCPROC callback
, ULONG_PTR data
)
3528 struct send_message_info info
;
3530 if (is_pointer_message( msg
, wparam
))
3532 SetLastError( ERROR_MESSAGE_SYNC_ONLY
);
3536 info
.type
= MSG_CALLBACK
;
3539 info
.wparam
= wparam
;
3540 info
.lparam
= lparam
;
3541 info
.callback
= callback
;
3544 info
.wm_char
= WMCHAR_MAP_SENDMESSAGETIMEOUT
;
3546 return send_message( &info
, NULL
, FALSE
);
3550 /***********************************************************************
3551 * SendMessageCallbackW (USER32.@)
3553 BOOL WINAPI
SendMessageCallbackW( HWND hwnd
, UINT msg
, WPARAM wparam
, LPARAM lparam
,
3554 SENDASYNCPROC callback
, ULONG_PTR data
)
3556 struct send_message_info info
;
3558 if (is_pointer_message( msg
, wparam
))
3560 SetLastError( ERROR_MESSAGE_SYNC_ONLY
);
3564 info
.type
= MSG_CALLBACK
;
3567 info
.wparam
= wparam
;
3568 info
.lparam
= lparam
;
3569 info
.callback
= callback
;
3573 return send_message( &info
, NULL
, TRUE
);
3577 /***********************************************************************
3578 * ReplyMessage (USER32.@)
3580 BOOL WINAPI
ReplyMessage( LRESULT result
)
3582 struct received_message_info
*info
= get_user_thread_info()->receive_info
;
3584 if (!info
) return FALSE
;
3585 reply_message( info
, result
, FALSE
);
3590 /***********************************************************************
3591 * InSendMessage (USER32.@)
3593 BOOL WINAPI
InSendMessage(void)
3595 return (InSendMessageEx( NULL
) & (ISMEX_SEND
| ISMEX_NOTIFY
| ISMEX_CALLBACK
)) != 0;
3599 /***********************************************************************
3600 * InSendMessageEx (USER32.@)
3602 DWORD WINAPI
InSendMessageEx( LPVOID reserved
)
3604 struct received_message_info
*info
= get_user_thread_info()->receive_info
;
3606 if (info
) return info
->flags
;
3607 return ISMEX_NOSEND
;
3611 /***********************************************************************
3612 * PostMessageA (USER32.@)
3614 BOOL WINAPI
PostMessageA( HWND hwnd
, UINT msg
, WPARAM wparam
, LPARAM lparam
)
3616 if (!map_wparam_AtoW( msg
, &wparam
, WMCHAR_MAP_POSTMESSAGE
)) return TRUE
;
3617 return PostMessageW( hwnd
, msg
, wparam
, lparam
);
3621 /***********************************************************************
3622 * PostMessageW (USER32.@)
3624 BOOL WINAPI
PostMessageW( HWND hwnd
, UINT msg
, WPARAM wparam
, LPARAM lparam
)
3626 struct send_message_info info
;
3628 if (is_pointer_message( msg
, wparam
))
3630 SetLastError( ERROR_MESSAGE_SYNC_ONLY
);
3634 TRACE( "hwnd %p msg %x (%s) wp %lx lp %lx\n",
3635 hwnd
, msg
, SPY_GetMsgName(msg
, hwnd
), wparam
, lparam
);
3637 info
.type
= MSG_POSTED
;
3640 info
.wparam
= wparam
;
3641 info
.lparam
= lparam
;
3644 if (is_broadcast(hwnd
))
3646 if (is_message_broadcastable( info
.msg
))
3647 EnumWindows( broadcast_message_callback
, (LPARAM
)&info
);
3651 if (!hwnd
) return PostThreadMessageW( GetCurrentThreadId(), msg
, wparam
, lparam
);
3653 if (!(info
.dest_tid
= GetWindowThreadProcessId( hwnd
, NULL
))) return FALSE
;
3655 if (USER_IsExitingThread( info
.dest_tid
)) return TRUE
;
3657 return put_message_in_queue( &info
, NULL
);
3661 /**********************************************************************
3662 * PostThreadMessageA (USER32.@)
3664 BOOL WINAPI
PostThreadMessageA( DWORD thread
, UINT msg
, WPARAM wparam
, LPARAM lparam
)
3666 if (!map_wparam_AtoW( msg
, &wparam
, WMCHAR_MAP_POSTMESSAGE
)) return TRUE
;
3667 return PostThreadMessageW( thread
, msg
, wparam
, lparam
);
3671 /**********************************************************************
3672 * PostThreadMessageW (USER32.@)
3674 BOOL WINAPI
PostThreadMessageW( DWORD thread
, UINT msg
, WPARAM wparam
, LPARAM lparam
)
3676 struct send_message_info info
;
3678 if (is_pointer_message( msg
, wparam
))
3680 SetLastError( ERROR_MESSAGE_SYNC_ONLY
);
3683 if (USER_IsExitingThread( thread
)) return TRUE
;
3685 info
.type
= MSG_POSTED
;
3686 info
.dest_tid
= thread
;
3689 info
.wparam
= wparam
;
3690 info
.lparam
= lparam
;
3692 return put_message_in_queue( &info
, NULL
);
3696 /***********************************************************************
3697 * PostQuitMessage (USER32.@)
3699 * Posts a quit message to the current thread's message queue.
3702 * exit_code [I] Exit code to return from message loop.
3708 * This function is not the same as calling:
3709 *|PostThreadMessage(GetCurrentThreadId(), WM_QUIT, exit_code, 0);
3710 * It instead sets a flag in the message queue that signals it to generate
3711 * a WM_QUIT message when there are no other pending sent or posted messages
3714 void WINAPI
PostQuitMessage( INT exit_code
)
3716 SERVER_START_REQ( post_quit_message
)
3718 req
->exit_code
= exit_code
;
3719 wine_server_call( req
);
3724 /* check for driver events if we detect that the app is not properly consuming messages */
3725 static inline void check_for_driver_events( UINT msg
)
3727 if (get_user_thread_info()->message_count
> 200)
3729 flush_window_surfaces( FALSE
);
3730 USER_Driver
->pMsgWaitForMultipleObjectsEx( 0, NULL
, 0, QS_ALLINPUT
, 0 );
3732 else if (msg
== WM_TIMER
|| msg
== WM_SYSTIMER
)
3734 /* driver events should have priority over timers, so make sure we'll check for them soon */
3735 get_user_thread_info()->message_count
+= 100;
3737 else get_user_thread_info()->message_count
++;
3740 /***********************************************************************
3741 * PeekMessageW (USER32.@)
3743 BOOL WINAPI DECLSPEC_HOTPATCH
PeekMessageW( MSG
*msg_out
, HWND hwnd
, UINT first
, UINT last
, UINT flags
)
3748 USER_CheckNotLock();
3749 check_for_driver_events( 0 );
3751 ret
= peek_message( &msg
, hwnd
, first
, last
, flags
, 0 );
3752 if (ret
< 0) return FALSE
;
3756 flush_window_surfaces( TRUE
);
3757 ret
= wow_handlers
.wait_message( 0, NULL
, 0, QS_ALLINPUT
, 0 );
3758 /* if we received driver events, check again for a pending message */
3759 if (ret
== WAIT_TIMEOUT
|| peek_message( &msg
, hwnd
, first
, last
, flags
, 0 ) <= 0) return FALSE
;
3762 check_for_driver_events( msg
.message
);
3764 /* copy back our internal safe copy of message data to msg_out.
3765 * msg_out is a variable from the *program*, so it can't be used
3766 * internally as it can get "corrupted" by our use of SendMessage()
3767 * (back to the program) inside the message handling itself. */
3770 SetLastError( ERROR_NOACCESS
);
3778 /***********************************************************************
3779 * PeekMessageA (USER32.@)
3781 BOOL WINAPI DECLSPEC_HOTPATCH
PeekMessageA( MSG
*msg
, HWND hwnd
, UINT first
, UINT last
, UINT flags
)
3783 if (get_pending_wmchar( msg
, first
, last
, (flags
& PM_REMOVE
) )) return TRUE
;
3784 if (!PeekMessageW( msg
, hwnd
, first
, last
, flags
)) return FALSE
;
3785 map_wparam_WtoA( msg
, (flags
& PM_REMOVE
) );
3790 /***********************************************************************
3791 * GetMessageW (USER32.@)
3793 BOOL WINAPI DECLSPEC_HOTPATCH
GetMessageW( MSG
*msg
, HWND hwnd
, UINT first
, UINT last
)
3795 HANDLE server_queue
= get_server_queue_handle();
3796 unsigned int mask
= QS_POSTMESSAGE
| QS_SENDMESSAGE
; /* Always selected */
3799 USER_CheckNotLock();
3800 check_for_driver_events( 0 );
3804 if ((first
<= WM_KEYLAST
) && (last
>= WM_KEYFIRST
)) mask
|= QS_KEY
;
3805 if ( ((first
<= WM_MOUSELAST
) && (last
>= WM_MOUSEFIRST
)) ||
3806 ((first
<= WM_NCMOUSELAST
) && (last
>= WM_NCMOUSEFIRST
)) ) mask
|= QS_MOUSE
;
3807 if ((first
<= WM_TIMER
) && (last
>= WM_TIMER
)) mask
|= QS_TIMER
;
3808 if ((first
<= WM_SYSTIMER
) && (last
>= WM_SYSTIMER
)) mask
|= QS_TIMER
;
3809 if ((first
<= WM_PAINT
) && (last
>= WM_PAINT
)) mask
|= QS_PAINT
;
3811 else mask
= QS_ALLINPUT
;
3813 while (!(ret
= peek_message( msg
, hwnd
, first
, last
, PM_REMOVE
| (mask
<< 16), mask
)))
3815 wait_objects( 1, &server_queue
, INFINITE
, mask
& (QS_SENDMESSAGE
| QS_SMRESULT
), mask
, 0 );
3817 if (ret
< 0) return -1;
3819 check_for_driver_events( msg
->message
);
3821 return (msg
->message
!= WM_QUIT
);
3825 /***********************************************************************
3826 * GetMessageA (USER32.@)
3828 BOOL WINAPI DECLSPEC_HOTPATCH
GetMessageA( MSG
*msg
, HWND hwnd
, UINT first
, UINT last
)
3830 if (get_pending_wmchar( msg
, first
, last
, TRUE
)) return TRUE
;
3831 if (GetMessageW( msg
, hwnd
, first
, last
) < 0) return -1;
3832 map_wparam_WtoA( msg
, TRUE
);
3833 return (msg
->message
!= WM_QUIT
);
3837 /***********************************************************************
3838 * IsDialogMessageA (USER32.@)
3839 * IsDialogMessage (USER32.@)
3841 BOOL WINAPI
IsDialogMessageA( HWND hwndDlg
, LPMSG pmsg
)
3844 map_wparam_AtoW( msg
.message
, &msg
.wParam
, WMCHAR_MAP_NOMAPPING
);
3845 return IsDialogMessageW( hwndDlg
, &msg
);
3849 /***********************************************************************
3850 * TranslateMessage (USER32.@)
3852 * Implementation of TranslateMessage.
3854 * TranslateMessage translates virtual-key messages into character-messages,
3856 * WM_KEYDOWN/WM_KEYUP combinations produce a WM_CHAR or WM_DEADCHAR message.
3857 * ditto replacing WM_* with WM_SYS*
3858 * This produces WM_CHAR messages only for keys mapped to ASCII characters
3859 * by the keyboard driver.
3861 * If the message is WM_KEYDOWN, WM_KEYUP, WM_SYSKEYDOWN, or WM_SYSKEYUP, the
3862 * return value is nonzero, regardless of the translation.
3865 BOOL WINAPI
TranslateMessage( const MSG
*msg
)
3872 if (msg
->message
< WM_KEYFIRST
|| msg
->message
> WM_KEYLAST
) return FALSE
;
3873 if (msg
->message
!= WM_KEYDOWN
&& msg
->message
!= WM_SYSKEYDOWN
) return TRUE
;
3875 TRACE_(key
)("Translating key %s (%04lX), scancode %04x\n",
3876 SPY_GetVKeyName(msg
->wParam
), msg
->wParam
, HIWORD(msg
->lParam
));
3878 switch (msg
->wParam
)
3881 message
= (msg
->message
== WM_KEYDOWN
) ? WM_CHAR
: WM_SYSCHAR
;
3882 TRACE_(key
)("PostMessageW(%p,%s,%04x,%08x)\n",
3883 msg
->hwnd
, SPY_GetMsgName(message
, msg
->hwnd
), HIWORD(msg
->lParam
), LOWORD(msg
->lParam
));
3884 PostMessageW( msg
->hwnd
, message
, HIWORD(msg
->lParam
), LOWORD(msg
->lParam
));
3888 return ImmTranslateMessage(msg
->hwnd
, msg
->message
, msg
->wParam
, msg
->lParam
);
3891 GetKeyboardState( state
);
3892 len
= ToUnicode(msg
->wParam
, HIWORD(msg
->lParam
), state
, wp
, ARRAY_SIZE(wp
), 0);
3895 message
= (msg
->message
== WM_KEYDOWN
) ? WM_DEADCHAR
: WM_SYSDEADCHAR
;
3896 TRACE_(key
)("-1 -> PostMessageW(%p,%s,%04x,%08lx)\n",
3897 msg
->hwnd
, SPY_GetMsgName(message
, msg
->hwnd
), wp
[0], msg
->lParam
);
3898 PostMessageW( msg
->hwnd
, message
, wp
[0], msg
->lParam
);
3904 message
= (msg
->message
== WM_KEYDOWN
) ? WM_CHAR
: WM_SYSCHAR
;
3905 TRACE_(key
)("%d -> PostMessageW(%p,%s,<x>,%08lx) for <x> in %s\n", len
, msg
->hwnd
,
3906 SPY_GetMsgName(message
, msg
->hwnd
), msg
->lParam
, debugstr_wn(wp
, len
));
3907 for (i
= 0; i
< len
; i
++)
3908 PostMessageW( msg
->hwnd
, message
, wp
[i
], msg
->lParam
);
3914 /***********************************************************************
3915 * DispatchMessageA (USER32.@)
3917 * See DispatchMessageW.
3919 LRESULT WINAPI DECLSPEC_HOTPATCH
DispatchMessageA( const MSG
* msg
)
3923 /* Process timer messages */
3924 if ((msg
->message
== WM_TIMER
) || (msg
->message
== WM_SYSTIMER
))
3930 retval
= CallWindowProcA( (WNDPROC
)msg
->lParam
, msg
->hwnd
,
3931 msg
->message
, msg
->wParam
, GetTickCount() );
3941 if (!msg
->hwnd
) return 0;
3943 SPY_EnterMessage( SPY_DISPATCHMESSAGE
, msg
->hwnd
, msg
->message
,
3944 msg
->wParam
, msg
->lParam
);
3946 if (!WINPROC_call_window( msg
->hwnd
, msg
->message
, msg
->wParam
, msg
->lParam
,
3947 &retval
, FALSE
, WMCHAR_MAP_DISPATCHMESSAGE
))
3949 if (!IsWindow( msg
->hwnd
)) SetLastError( ERROR_INVALID_WINDOW_HANDLE
);
3950 else SetLastError( ERROR_MESSAGE_SYNC_ONLY
);
3954 SPY_ExitMessage( SPY_RESULT_OK
, msg
->hwnd
, msg
->message
, retval
,
3955 msg
->wParam
, msg
->lParam
);
3957 if (msg
->message
== WM_PAINT
)
3959 /* send a WM_NCPAINT and WM_ERASEBKGND if the non-client area is still invalid */
3960 HRGN hrgn
= CreateRectRgn( 0, 0, 0, 0 );
3961 GetUpdateRgn( msg
->hwnd
, hrgn
, TRUE
);
3962 DeleteObject( hrgn
);
3968 /***********************************************************************
3969 * DispatchMessageW (USER32.@) Process a message
3971 * Process the message specified in the structure *_msg_.
3973 * If the lpMsg parameter points to a WM_TIMER message and the
3974 * parameter of the WM_TIMER message is not NULL, the lParam parameter
3975 * points to the function that is called instead of the window
3976 * procedure. The function stored in lParam (timer callback) is protected
3977 * from causing page-faults.
3979 * The message must be valid.
3983 * DispatchMessage() returns the result of the window procedure invoked.
3990 LRESULT WINAPI DECLSPEC_HOTPATCH
DispatchMessageW( const MSG
* msg
)
3994 /* Process timer messages */
3995 if ((msg
->message
== WM_TIMER
) || (msg
->message
== WM_SYSTIMER
))
4001 retval
= CallWindowProcW( (WNDPROC
)msg
->lParam
, msg
->hwnd
,
4002 msg
->message
, msg
->wParam
, GetTickCount() );
4012 if (!msg
->hwnd
) return 0;
4014 SPY_EnterMessage( SPY_DISPATCHMESSAGE
, msg
->hwnd
, msg
->message
,
4015 msg
->wParam
, msg
->lParam
);
4017 if (!WINPROC_call_window( msg
->hwnd
, msg
->message
, msg
->wParam
, msg
->lParam
,
4018 &retval
, TRUE
, WMCHAR_MAP_DISPATCHMESSAGE
))
4020 if (!IsWindow( msg
->hwnd
)) SetLastError( ERROR_INVALID_WINDOW_HANDLE
);
4021 else SetLastError( ERROR_MESSAGE_SYNC_ONLY
);
4025 SPY_ExitMessage( SPY_RESULT_OK
, msg
->hwnd
, msg
->message
, retval
,
4026 msg
->wParam
, msg
->lParam
);
4028 if (msg
->message
== WM_PAINT
)
4030 /* send a WM_NCPAINT and WM_ERASEBKGND if the non-client area is still invalid */
4031 HRGN hrgn
= CreateRectRgn( 0, 0, 0, 0 );
4032 GetUpdateRgn( msg
->hwnd
, hrgn
, TRUE
);
4033 DeleteObject( hrgn
);
4039 /***********************************************************************
4040 * GetMessagePos (USER.119)
4041 * GetMessagePos (USER32.@)
4043 * The GetMessagePos() function returns a long value representing a
4044 * cursor position, in screen coordinates, when the last message
4045 * retrieved by the GetMessage() function occurs. The x-coordinate is
4046 * in the low-order word of the return value, the y-coordinate is in
4047 * the high-order word. The application can use the MAKEPOINT()
4048 * macro to obtain a POINT structure from the return value.
4050 * For the current cursor position, use GetCursorPos().
4054 * Cursor position of last message on success, zero on failure.
4061 DWORD WINAPI
GetMessagePos(void)
4063 return get_user_thread_info()->GetMessagePosVal
;
4067 /***********************************************************************
4068 * GetMessageTime (USER.120)
4069 * GetMessageTime (USER32.@)
4071 * GetMessageTime() returns the message time for the last message
4072 * retrieved by the function. The time is measured in milliseconds with
4073 * the same offset as GetTickCount().
4075 * Since the tick count wraps, this is only useful for moderately short
4076 * relative time comparisons.
4080 * Time of last message on success, zero on failure.
4082 LONG WINAPI
GetMessageTime(void)
4084 return get_user_thread_info()->GetMessageTimeVal
;
4088 /***********************************************************************
4089 * GetMessageExtraInfo (USER.288)
4090 * GetMessageExtraInfo (USER32.@)
4092 LPARAM WINAPI
GetMessageExtraInfo(void)
4094 return get_user_thread_info()->GetMessageExtraInfoVal
;
4098 /***********************************************************************
4099 * SetMessageExtraInfo (USER32.@)
4101 LPARAM WINAPI
SetMessageExtraInfo(LPARAM lParam
)
4103 struct user_thread_info
*thread_info
= get_user_thread_info();
4104 LONG old_value
= thread_info
->GetMessageExtraInfoVal
;
4105 thread_info
->GetMessageExtraInfoVal
= lParam
;
4110 /***********************************************************************
4111 * GetCurrentInputMessageSource (USER32.@)
4113 BOOL WINAPI
GetCurrentInputMessageSource( INPUT_MESSAGE_SOURCE
*source
)
4115 *source
= get_user_thread_info()->msg_source
;
4120 /***********************************************************************
4121 * WaitMessage (USER.112) Suspend thread pending messages
4122 * WaitMessage (USER32.@) Suspend thread pending messages
4124 * WaitMessage() suspends a thread until events appear in the thread's
4127 BOOL WINAPI
WaitMessage(void)
4129 return (MsgWaitForMultipleObjectsEx( 0, NULL
, INFINITE
, QS_ALLINPUT
, 0 ) != WAIT_FAILED
);
4133 /***********************************************************************
4134 * MsgWaitForMultipleObjectsEx (USER32.@)
4136 DWORD WINAPI
MsgWaitForMultipleObjectsEx( DWORD count
, const HANDLE
*pHandles
,
4137 DWORD timeout
, DWORD mask
, DWORD flags
)
4139 HANDLE handles
[MAXIMUM_WAIT_OBJECTS
];
4142 if (count
> MAXIMUM_WAIT_OBJECTS
-1)
4144 SetLastError( ERROR_INVALID_PARAMETER
);
4148 /* add the queue to the handle list */
4149 for (i
= 0; i
< count
; i
++) handles
[i
] = pHandles
[i
];
4150 handles
[count
] = get_server_queue_handle();
4152 return wait_objects( count
+1, handles
, timeout
,
4153 (flags
& MWMO_INPUTAVAILABLE
) ? mask
: 0, mask
, flags
);
4157 /***********************************************************************
4158 * MsgWaitForMultipleObjects (USER32.@)
4160 DWORD WINAPI
MsgWaitForMultipleObjects( DWORD count
, const HANDLE
*handles
,
4161 BOOL wait_all
, DWORD timeout
, DWORD mask
)
4163 return MsgWaitForMultipleObjectsEx( count
, handles
, timeout
, mask
,
4164 wait_all
? MWMO_WAITALL
: 0 );
4168 /***********************************************************************
4169 * WaitForInputIdle (USER32.@)
4171 DWORD WINAPI
WaitForInputIdle( HANDLE hProcess
, DWORD dwTimeOut
)
4173 DWORD start_time
, elapsed
, ret
;
4176 handles
[0] = hProcess
;
4177 SERVER_START_REQ( get_process_idle_event
)
4179 req
->handle
= wine_server_obj_handle( hProcess
);
4180 wine_server_call_err( req
);
4181 handles
[1] = wine_server_ptr_handle( reply
->event
);
4184 if (!handles
[1]) return WAIT_FAILED
; /* no event to wait on */
4186 start_time
= GetTickCount();
4189 TRACE("waiting for %p\n", handles
[1] );
4192 ret
= MsgWaitForMultipleObjects ( 2, handles
, FALSE
, dwTimeOut
- elapsed
, QS_SENDMESSAGE
);
4197 case WAIT_OBJECT_0
+2:
4198 process_sent_messages();
4202 TRACE("timeout or error\n");
4205 TRACE("finished\n");
4208 if (dwTimeOut
!= INFINITE
)
4210 elapsed
= GetTickCount() - start_time
;
4211 if (elapsed
> dwTimeOut
)
4217 return WAIT_TIMEOUT
;
4221 /***********************************************************************
4222 * RegisterWindowMessageA (USER32.@)
4223 * RegisterWindowMessage (USER.118)
4225 UINT WINAPI
RegisterWindowMessageA( LPCSTR str
)
4227 UINT ret
= GlobalAddAtomA(str
);
4228 TRACE("%s, ret=%x\n", str
, ret
);
4233 /***********************************************************************
4234 * RegisterWindowMessageW (USER32.@)
4236 UINT WINAPI
RegisterWindowMessageW( LPCWSTR str
)
4238 UINT ret
= GlobalAddAtomW(str
);
4239 TRACE("%s ret=%x\n", debugstr_w(str
), ret
);
4243 typedef struct BroadcastParm
4254 static BOOL CALLBACK
bcast_childwindow( HWND hw
, LPARAM lp
)
4256 BroadcastParm
*parm
= (BroadcastParm
*)lp
;
4257 DWORD_PTR retval
= 0;
4260 if (parm
->flags
& BSF_IGNORECURRENTTASK
&& WIN_IsCurrentProcess(hw
))
4262 TRACE("Not telling myself %p\n", hw
);
4266 /* I don't know 100% for sure if this is what Windows does, but it fits the tests */
4267 if (parm
->flags
& BSF_QUERY
)
4269 TRACE("Telling window %p using SendMessageTimeout\n", hw
);
4271 /* Not tested for conflicting flags */
4272 if (parm
->flags
& BSF_FORCEIFHUNG
|| parm
->flags
& BSF_NOHANG
)
4273 lresult
= SendMessageTimeoutW( hw
, parm
->msg
, parm
->wp
, parm
->lp
, SMTO_ABORTIFHUNG
, 2000, &retval
);
4274 else if (parm
->flags
& BSF_NOTIMEOUTIFNOTHUNG
)
4275 lresult
= SendMessageTimeoutW( hw
, parm
->msg
, parm
->wp
, parm
->lp
, SMTO_NOTIMEOUTIFNOTHUNG
, 2000, &retval
);
4277 lresult
= SendMessageTimeoutW( hw
, parm
->msg
, parm
->wp
, parm
->lp
, SMTO_NORMAL
, 2000, &retval
);
4279 if (!lresult
&& GetLastError() == ERROR_TIMEOUT
)
4281 WARN("Timed out!\n");
4282 if (!(parm
->flags
& BSF_FORCEIFHUNG
))
4285 if (retval
== BROADCAST_QUERY_DENY
)
4291 parm
->success
= FALSE
;
4294 else if (parm
->flags
& BSF_POSTMESSAGE
)
4296 TRACE("Telling window %p using PostMessage\n", hw
);
4297 PostMessageW( hw
, parm
->msg
, parm
->wp
, parm
->lp
);
4301 TRACE("Telling window %p using SendNotifyMessage\n", hw
);
4302 SendNotifyMessageW( hw
, parm
->msg
, parm
->wp
, parm
->lp
);
4308 static BOOL CALLBACK
bcast_desktop( LPWSTR desktop
, LPARAM lp
)
4312 BroadcastParm
*parm
= (BroadcastParm
*)lp
;
4314 TRACE("desktop: %s\n", debugstr_w( desktop
));
4316 hdesktop
= open_winstation_desktop( parm
->winsta
, desktop
, 0, FALSE
, DESKTOP_ENUMERATE
|DESKTOP_WRITEOBJECTS
|STANDARD_RIGHTS_WRITE
);
4319 FIXME("Could not open desktop %s\n", debugstr_w(desktop
));
4323 ret
= EnumDesktopWindows( hdesktop
, bcast_childwindow
, lp
);
4324 CloseDesktop(hdesktop
);
4325 TRACE("-->%d\n", ret
);
4326 return parm
->success
;
4329 static BOOL CALLBACK
bcast_winsta( LPWSTR winsta
, LPARAM lp
)
4332 HWINSTA hwinsta
= OpenWindowStationW( winsta
, FALSE
, WINSTA_ENUMDESKTOPS
);
4333 TRACE("hwinsta: %p/%s/%08x\n", hwinsta
, debugstr_w( winsta
), GetLastError());
4336 ((BroadcastParm
*)lp
)->winsta
= hwinsta
;
4337 ret
= EnumDesktopsW( hwinsta
, bcast_desktop
, lp
);
4338 CloseWindowStation( hwinsta
);
4339 TRACE("-->%d\n", ret
);
4343 /***********************************************************************
4344 * BroadcastSystemMessageA (USER32.@)
4345 * BroadcastSystemMessage (USER32.@)
4347 LONG WINAPI
BroadcastSystemMessageA( DWORD flags
, LPDWORD recipients
, UINT msg
, WPARAM wp
, LPARAM lp
)
4349 return BroadcastSystemMessageExA( flags
, recipients
, msg
, wp
, lp
, NULL
);
4353 /***********************************************************************
4354 * BroadcastSystemMessageW (USER32.@)
4356 LONG WINAPI
BroadcastSystemMessageW( DWORD flags
, LPDWORD recipients
, UINT msg
, WPARAM wp
, LPARAM lp
)
4358 return BroadcastSystemMessageExW( flags
, recipients
, msg
, wp
, lp
, NULL
);
4361 /***********************************************************************
4362 * BroadcastSystemMessageExA (USER32.@)
4364 LONG WINAPI
BroadcastSystemMessageExA( DWORD flags
, LPDWORD recipients
, UINT msg
, WPARAM wp
, LPARAM lp
, PBSMINFO pinfo
)
4366 map_wparam_AtoW( msg
, &wp
, WMCHAR_MAP_NOMAPPING
);
4367 return BroadcastSystemMessageExW( flags
, recipients
, msg
, wp
, lp
, NULL
);
4371 /***********************************************************************
4372 * BroadcastSystemMessageExW (USER32.@)
4374 LONG WINAPI
BroadcastSystemMessageExW( DWORD flags
, LPDWORD recipients
, UINT msg
, WPARAM wp
, LPARAM lp
, PBSMINFO pinfo
)
4377 DWORD recips
= BSM_ALLCOMPONENTS
;
4379 static const DWORD all_flags
= ( BSF_QUERY
| BSF_IGNORECURRENTTASK
| BSF_FLUSHDISK
| BSF_NOHANG
4380 | BSF_POSTMESSAGE
| BSF_FORCEIFHUNG
| BSF_NOTIMEOUTIFNOTHUNG
4381 | BSF_ALLOWSFW
| BSF_SENDNOTIFYMESSAGE
| BSF_RETURNHDESK
| BSF_LUID
);
4383 TRACE("Flags: %08x, recipients: %p(0x%x), msg: %04x, wparam: %08lx, lparam: %08lx\n", flags
, recipients
,
4384 (recipients
? *recipients
: recips
), msg
, wp
, lp
);
4386 if (flags
& ~all_flags
)
4388 SetLastError(ERROR_INVALID_PARAMETER
);
4393 recipients
= &recips
;
4395 if ( pinfo
&& flags
& BSF_QUERY
)
4396 FIXME("Not returning PBSMINFO information yet\n");
4399 parm
.recipients
= recipients
;
4403 parm
.success
= TRUE
;
4405 if (*recipients
& BSM_ALLDESKTOPS
|| *recipients
== BSM_ALLCOMPONENTS
)
4406 ret
= EnumWindowStationsW(bcast_winsta
, (LONG_PTR
)&parm
);
4407 else if (*recipients
& BSM_APPLICATIONS
)
4409 EnumWindows(bcast_childwindow
, (LONG_PTR
)&parm
);
4413 FIXME("Recipients %08x not supported!\n", *recipients
);
4418 /***********************************************************************
4419 * SetMessageQueue (USER32.@)
4421 BOOL WINAPI
SetMessageQueue( INT size
)
4423 /* now obsolete the message queue will be expanded dynamically as necessary */
4428 /***********************************************************************
4429 * MessageBeep (USER32.@)
4431 BOOL WINAPI
MessageBeep( UINT i
)
4434 SystemParametersInfoA( SPI_GETBEEP
, 0, &active
, FALSE
);
4435 if (active
) USER_Driver
->pBeep();
4440 /***********************************************************************
4441 * SetCoalescableTimer (USER32.@)
4443 UINT_PTR WINAPI
SetCoalescableTimer( HWND hwnd
, UINT_PTR id
, UINT timeout
, TIMERPROC proc
, ULONG tolerance
)
4446 WNDPROC winproc
= 0;
4448 if (proc
) winproc
= WINPROC_AllocProc( (WNDPROC
)proc
, FALSE
);
4450 timeout
= min( max( USER_TIMER_MINIMUM
, timeout
), USER_TIMER_MAXIMUM
);
4452 SERVER_START_REQ( set_win_timer
)
4454 req
->win
= wine_server_user_handle( hwnd
);
4455 req
->msg
= WM_TIMER
;
4457 req
->rate
= timeout
;
4458 req
->lparam
= (ULONG_PTR
)winproc
;
4459 if (!wine_server_call_err( req
))
4462 if (!ret
) ret
= TRUE
;
4468 TRACE("Added %p %lx %p timeout %d\n", hwnd
, id
, winproc
, timeout
);
4473 /******************************************************************
4474 * SetTimer (USER32.@)
4476 UINT_PTR WINAPI
SetTimer( HWND hwnd
, UINT_PTR id
, UINT timeout
, TIMERPROC proc
)
4478 return SetCoalescableTimer( hwnd
, id
, timeout
, proc
, TIMERV_DEFAULT_COALESCING
);
4482 /***********************************************************************
4483 * SetSystemTimer (USER32.@)
4485 UINT_PTR WINAPI
SetSystemTimer( HWND hwnd
, UINT_PTR id
, UINT timeout
, TIMERPROC proc
)
4488 WNDPROC winproc
= 0;
4490 if (proc
) winproc
= WINPROC_AllocProc( (WNDPROC
)proc
, FALSE
);
4492 timeout
= min( max( USER_TIMER_MINIMUM
, timeout
), USER_TIMER_MAXIMUM
);
4494 SERVER_START_REQ( set_win_timer
)
4496 req
->win
= wine_server_user_handle( hwnd
);
4497 req
->msg
= WM_SYSTIMER
;
4499 req
->rate
= timeout
;
4500 req
->lparam
= (ULONG_PTR
)winproc
;
4501 if (!wine_server_call_err( req
))
4504 if (!ret
) ret
= TRUE
;
4510 TRACE("Added %p %lx %p timeout %d\n", hwnd
, id
, winproc
, timeout
);
4515 /***********************************************************************
4516 * KillTimer (USER32.@)
4518 BOOL WINAPI
KillTimer( HWND hwnd
, UINT_PTR id
)
4522 SERVER_START_REQ( kill_win_timer
)
4524 req
->win
= wine_server_user_handle( hwnd
);
4525 req
->msg
= WM_TIMER
;
4527 ret
= !wine_server_call_err( req
);
4534 /***********************************************************************
4535 * KillSystemTimer (USER32.@)
4537 BOOL WINAPI
KillSystemTimer( HWND hwnd
, UINT_PTR id
)
4541 SERVER_START_REQ( kill_win_timer
)
4543 req
->win
= wine_server_user_handle( hwnd
);
4544 req
->msg
= WM_SYSTIMER
;
4546 ret
= !wine_server_call_err( req
);
4553 /**********************************************************************
4554 * IsGUIThread (USER32.@)
4556 BOOL WINAPI
IsGUIThread( BOOL convert
)
4558 FIXME( "%u: stub\n", convert
);
4563 /**********************************************************************
4564 * GetGUIThreadInfo (USER32.@)
4566 BOOL WINAPI
GetGUIThreadInfo( DWORD id
, GUITHREADINFO
*info
)
4570 if (info
->cbSize
!= sizeof(*info
))
4572 SetLastError( ERROR_INVALID_PARAMETER
);
4576 SERVER_START_REQ( get_thread_input
)
4579 if ((ret
= !wine_server_call_err( req
)))
4582 info
->hwndActive
= wine_server_ptr_handle( reply
->active
);
4583 info
->hwndFocus
= wine_server_ptr_handle( reply
->focus
);
4584 info
->hwndCapture
= wine_server_ptr_handle( reply
->capture
);
4585 info
->hwndMenuOwner
= wine_server_ptr_handle( reply
->menu_owner
);
4586 info
->hwndMoveSize
= wine_server_ptr_handle( reply
->move_size
);
4587 info
->hwndCaret
= wine_server_ptr_handle( reply
->caret
);
4588 info
->rcCaret
.left
= reply
->rect
.left
;
4589 info
->rcCaret
.top
= reply
->rect
.top
;
4590 info
->rcCaret
.right
= reply
->rect
.right
;
4591 info
->rcCaret
.bottom
= reply
->rect
.bottom
;
4592 if (reply
->menu_owner
) info
->flags
|= GUI_INMENUMODE
;
4593 if (reply
->move_size
) info
->flags
|= GUI_INMOVESIZE
;
4594 if (reply
->caret
) info
->flags
|= GUI_CARETBLINKING
;
4602 /******************************************************************
4603 * IsHungAppWindow (USER32.@)
4606 BOOL WINAPI
IsHungAppWindow( HWND hWnd
)
4610 SERVER_START_REQ( is_window_hung
)
4612 req
->win
= wine_server_user_handle( hWnd
);
4613 ret
= !wine_server_call_err( req
) && reply
->is_hung
;
4619 /******************************************************************
4620 * ChangeWindowMessageFilter (USER32.@)
4622 BOOL WINAPI
ChangeWindowMessageFilter( UINT message
, DWORD flag
)
4624 FIXME( "%x %08x\n", message
, flag
);
4628 /******************************************************************
4629 * ChangeWindowMessageFilterEx (USER32.@)
4631 BOOL WINAPI
ChangeWindowMessageFilterEx( HWND hwnd
, UINT message
, DWORD action
, CHANGEFILTERSTRUCT
*changefilter
)
4633 FIXME( "%p %x %d %p\n", hwnd
, message
, action
, changefilter
);