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 if (!rawinput_from_hardware_message( thread_data
->buffer
, msg_data
)) return FALSE
;
2296 thread_data
->hw_id
= hw_id
;
2297 msg
->lParam
= (LPARAM
)hw_id
;
2300 msg
->pt
= point_phys_to_win_dpi( msg
->hwnd
, msg
->pt
);
2304 /***********************************************************************
2305 * process_keyboard_message
2307 * returns TRUE if the contents of 'msg' should be passed to the application
2309 static BOOL
process_keyboard_message( MSG
*msg
, UINT hw_id
, HWND hwnd_filter
,
2310 UINT first
, UINT last
, BOOL remove
)
2314 if (msg
->message
== WM_KEYDOWN
|| msg
->message
== WM_SYSKEYDOWN
||
2315 msg
->message
== WM_KEYUP
|| msg
->message
== WM_SYSKEYUP
)
2316 switch (msg
->wParam
)
2318 case VK_LSHIFT
: case VK_RSHIFT
:
2319 msg
->wParam
= VK_SHIFT
;
2321 case VK_LCONTROL
: case VK_RCONTROL
:
2322 msg
->wParam
= VK_CONTROL
;
2324 case VK_LMENU
: case VK_RMENU
:
2325 msg
->wParam
= VK_MENU
;
2329 /* FIXME: is this really the right place for this hook? */
2330 event
.message
= msg
->message
;
2331 event
.hwnd
= msg
->hwnd
;
2332 event
.time
= msg
->time
;
2333 event
.paramL
= (msg
->wParam
& 0xFF) | (HIWORD(msg
->lParam
) << 8);
2334 event
.paramH
= msg
->lParam
& 0x7FFF;
2335 if (HIWORD(msg
->lParam
) & 0x0100) event
.paramH
|= 0x8000; /* special_key - bit */
2336 HOOK_CallHooks( WH_JOURNALRECORD
, HC_ACTION
, 0, (LPARAM
)&event
, TRUE
);
2338 /* check message filters */
2339 if (msg
->message
< first
|| msg
->message
> last
) return FALSE
;
2340 if (!check_hwnd_filter( msg
, hwnd_filter
)) return FALSE
;
2344 if((msg
->message
== WM_KEYDOWN
) &&
2345 (msg
->hwnd
!= GetDesktopWindow()))
2347 /* Handle F1 key by sending out WM_HELP message */
2348 if (msg
->wParam
== VK_F1
)
2350 PostMessageW( msg
->hwnd
, WM_KEYF1
, 0, 0 );
2352 else if(msg
->wParam
>= VK_BROWSER_BACK
&&
2353 msg
->wParam
<= VK_LAUNCH_APP2
)
2355 /* FIXME: Process keystate */
2356 SendMessageW(msg
->hwnd
, WM_APPCOMMAND
, (WPARAM
)msg
->hwnd
, MAKELPARAM(0, (FAPPCOMMAND_KEY
| (msg
->wParam
- VK_BROWSER_BACK
+ 1))));
2359 else if (msg
->message
== WM_KEYUP
)
2361 /* Handle VK_APPS key by posting a WM_CONTEXTMENU message */
2362 if (msg
->wParam
== VK_APPS
&& !MENU_IsMenuActive())
2363 PostMessageW(msg
->hwnd
, WM_CONTEXTMENU
, (WPARAM
)msg
->hwnd
, -1);
2367 if (HOOK_CallHooks( WH_KEYBOARD
, remove
? HC_ACTION
: HC_NOREMOVE
,
2368 LOWORD(msg
->wParam
), msg
->lParam
, TRUE
))
2370 /* skip this message */
2371 HOOK_CallHooks( WH_CBT
, HCBT_KEYSKIPPED
, LOWORD(msg
->wParam
), msg
->lParam
, TRUE
);
2372 accept_hardware_message( hw_id
);
2375 if (remove
) accept_hardware_message( hw_id
);
2376 msg
->pt
= point_phys_to_win_dpi( msg
->hwnd
, msg
->pt
);
2378 if ( remove
&& msg
->message
== WM_KEYDOWN
)
2379 if (ImmProcessKey(msg
->hwnd
, GetKeyboardLayout(0), msg
->wParam
, msg
->lParam
, 0) )
2380 msg
->wParam
= VK_PROCESSKEY
;
2386 /***********************************************************************
2387 * process_mouse_message
2389 * returns TRUE if the contents of 'msg' should be passed to the application
2391 static BOOL
process_mouse_message( MSG
*msg
, UINT hw_id
, ULONG_PTR extra_info
, HWND hwnd_filter
,
2392 UINT first
, UINT last
, BOOL remove
)
2401 MOUSEHOOKSTRUCTEX hook
;
2405 /* find the window to dispatch this mouse message to */
2407 info
.cbSize
= sizeof(info
);
2408 GetGUIThreadInfo( GetCurrentThreadId(), &info
);
2409 if (info
.hwndCapture
)
2412 msg
->hwnd
= info
.hwndCapture
;
2416 HWND orig
= msg
->hwnd
;
2418 msg
->hwnd
= WINPOS_WindowFromPoint( msg
->hwnd
, msg
->pt
, &hittest
);
2419 if (!msg
->hwnd
) /* As a heuristic, try the next window if it's the owner of orig */
2421 HWND next
= GetWindow( orig
, GW_HWNDNEXT
);
2423 if (next
&& GetWindow( orig
, GW_OWNER
) == next
&& WIN_IsCurrentThread( next
))
2424 msg
->hwnd
= WINPOS_WindowFromPoint( next
, msg
->pt
, &hittest
);
2428 if (!msg
->hwnd
|| !WIN_IsCurrentThread( msg
->hwnd
))
2430 accept_hardware_message( hw_id
);
2434 msg
->pt
= point_phys_to_win_dpi( msg
->hwnd
, msg
->pt
);
2435 SetThreadDpiAwarenessContext( GetWindowDpiAwarenessContext( msg
->hwnd
));
2437 /* FIXME: is this really the right place for this hook? */
2438 event
.message
= msg
->message
;
2439 event
.time
= msg
->time
;
2440 event
.hwnd
= msg
->hwnd
;
2441 event
.paramL
= msg
->pt
.x
;
2442 event
.paramH
= msg
->pt
.y
;
2443 HOOK_CallHooks( WH_JOURNALRECORD
, HC_ACTION
, 0, (LPARAM
)&event
, TRUE
);
2445 if (!check_hwnd_filter( msg
, hwnd_filter
)) return FALSE
;
2448 message
= msg
->message
;
2449 wparam
= msg
->wParam
;
2450 /* Note: windows has no concept of a non-client wheel message */
2451 if (message
!= WM_MOUSEWHEEL
)
2453 if (hittest
!= HTCLIENT
)
2455 message
+= WM_NCMOUSEMOVE
- WM_MOUSEMOVE
;
2460 /* coordinates don't get translated while tracking a menu */
2461 /* FIXME: should differentiate popups and top-level menus */
2462 if (!(info
.flags
& GUI_INMENUMODE
))
2463 ScreenToClient( msg
->hwnd
, &pt
);
2466 msg
->lParam
= MAKELONG( pt
.x
, pt
.y
);
2468 /* translate double clicks */
2470 if ((msg
->message
== WM_LBUTTONDOWN
) ||
2471 (msg
->message
== WM_RBUTTONDOWN
) ||
2472 (msg
->message
== WM_MBUTTONDOWN
) ||
2473 (msg
->message
== WM_XBUTTONDOWN
))
2475 BOOL update
= remove
;
2477 /* translate double clicks -
2478 * note that ...MOUSEMOVEs can slip in between
2479 * ...BUTTONDOWN and ...BUTTONDBLCLK messages */
2481 if ((info
.flags
& (GUI_INMENUMODE
|GUI_INMOVESIZE
)) ||
2482 hittest
!= HTCLIENT
||
2483 (GetClassLongA( msg
->hwnd
, GCL_STYLE
) & CS_DBLCLKS
))
2485 if ((msg
->message
== clk_msg
.message
) &&
2486 (msg
->hwnd
== clk_msg
.hwnd
) &&
2487 (msg
->wParam
== clk_msg
.wParam
) &&
2488 (msg
->time
- clk_msg
.time
< GetDoubleClickTime()) &&
2489 (abs(msg
->pt
.x
- clk_msg
.pt
.x
) < GetSystemMetrics(SM_CXDOUBLECLK
)/2) &&
2490 (abs(msg
->pt
.y
- clk_msg
.pt
.y
) < GetSystemMetrics(SM_CYDOUBLECLK
)/2))
2492 message
+= (WM_LBUTTONDBLCLK
- WM_LBUTTONDOWN
);
2495 clk_msg
.message
= 0; /* clear the double click conditions */
2500 if (message
< first
|| message
> last
) return FALSE
;
2501 /* update static double click conditions */
2502 if (update
) clk_msg
= *msg
;
2506 if (message
< first
|| message
> last
) return FALSE
;
2508 msg
->wParam
= wparam
;
2510 /* message is accepted now (but may still get dropped) */
2512 hook
.s
.pt
= msg
->pt
;
2513 hook
.s
.hwnd
= msg
->hwnd
;
2514 hook
.s
.wHitTestCode
= hittest
;
2515 hook
.s
.dwExtraInfo
= extra_info
;
2516 hook
.mouseData
= msg
->wParam
;
2517 if (HOOK_CallHooks( WH_MOUSE
, remove
? HC_ACTION
: HC_NOREMOVE
,
2518 message
, (LPARAM
)&hook
, TRUE
))
2520 hook
.s
.pt
= msg
->pt
;
2521 hook
.s
.hwnd
= msg
->hwnd
;
2522 hook
.s
.wHitTestCode
= hittest
;
2523 hook
.s
.dwExtraInfo
= extra_info
;
2524 hook
.mouseData
= msg
->wParam
;
2525 HOOK_CallHooks( WH_CBT
, HCBT_CLICKSKIPPED
, message
, (LPARAM
)&hook
, TRUE
);
2526 accept_hardware_message( hw_id
);
2530 if ((hittest
== HTERROR
) || (hittest
== HTNOWHERE
))
2532 SendMessageW( msg
->hwnd
, WM_SETCURSOR
, (WPARAM
)msg
->hwnd
,
2533 MAKELONG( hittest
, msg
->message
));
2534 accept_hardware_message( hw_id
);
2538 if (remove
) accept_hardware_message( hw_id
);
2540 if (!remove
|| info
.hwndCapture
)
2542 msg
->message
= message
;
2548 if ((msg
->message
== WM_LBUTTONDOWN
) ||
2549 (msg
->message
== WM_RBUTTONDOWN
) ||
2550 (msg
->message
== WM_MBUTTONDOWN
) ||
2551 (msg
->message
== WM_XBUTTONDOWN
))
2553 /* Send the WM_PARENTNOTIFY,
2554 * note that even for double/nonclient clicks
2555 * notification message is still WM_L/M/RBUTTONDOWN.
2557 send_parent_notify( msg
->hwnd
, msg
->message
, 0, msg
->pt
);
2559 /* Activate the window if needed */
2561 if (msg
->hwnd
!= info
.hwndActive
)
2563 HWND hwndTop
= GetAncestor( msg
->hwnd
, GA_ROOT
);
2565 if ((GetWindowLongW( hwndTop
, GWL_STYLE
) & (WS_POPUP
|WS_CHILD
)) != WS_CHILD
)
2567 LONG ret
= SendMessageW( msg
->hwnd
, WM_MOUSEACTIVATE
, (WPARAM
)hwndTop
,
2568 MAKELONG( hittest
, msg
->message
) );
2571 case MA_NOACTIVATEANDEAT
:
2576 case MA_ACTIVATEANDEAT
:
2581 if (!FOCUS_MouseActivate( hwndTop
)) eatMsg
= TRUE
;
2584 WARN( "unknown WM_MOUSEACTIVATE code %d\n", ret
);
2591 /* send the WM_SETCURSOR message */
2593 /* Windows sends the normal mouse message as the message parameter
2594 in the WM_SETCURSOR message even if it's non-client mouse message */
2595 SendMessageW( msg
->hwnd
, WM_SETCURSOR
, (WPARAM
)msg
->hwnd
, MAKELONG( hittest
, msg
->message
));
2597 msg
->message
= message
;
2602 /***********************************************************************
2603 * process_hardware_message
2605 * Process a hardware message; return TRUE if message should be passed on to the app
2607 static BOOL
process_hardware_message( MSG
*msg
, UINT hw_id
, const struct hardware_msg_data
*msg_data
,
2608 HWND hwnd_filter
, UINT first
, UINT last
, BOOL remove
)
2610 DPI_AWARENESS_CONTEXT context
;
2613 get_user_thread_info()->msg_source
.deviceType
= msg_data
->source
.device
;
2614 get_user_thread_info()->msg_source
.originId
= msg_data
->source
.origin
;
2616 /* hardware messages are always in physical coords */
2617 context
= SetThreadDpiAwarenessContext( DPI_AWARENESS_CONTEXT_PER_MONITOR_AWARE
);
2619 if (msg
->message
== WM_INPUT
|| msg
->message
== WM_INPUT_DEVICE_CHANGE
)
2620 ret
= process_rawinput_message( msg
, hw_id
, msg_data
);
2621 else if (is_keyboard_message( msg
->message
))
2622 ret
= process_keyboard_message( msg
, hw_id
, hwnd_filter
, first
, last
, remove
);
2623 else if (is_mouse_message( msg
->message
))
2624 ret
= process_mouse_message( msg
, hw_id
, msg_data
->info
, hwnd_filter
, first
, last
, remove
);
2626 ERR( "unknown message type %x\n", msg
->message
);
2627 SetThreadDpiAwarenessContext( context
);
2632 /***********************************************************************
2633 * call_sendmsg_callback
2635 * Call the callback function of SendMessageCallback.
2637 static inline void call_sendmsg_callback( SENDASYNCPROC callback
, HWND hwnd
, UINT msg
,
2638 ULONG_PTR data
, LRESULT result
)
2640 if (!callback
) return;
2642 TRACE_(relay
)( "\1Call message callback %p (hwnd=%p,msg=%s,data=%08lx,result=%08lx)\n",
2643 callback
, hwnd
, SPY_GetMsgName( msg
, hwnd
), data
, result
);
2644 callback( hwnd
, msg
, data
, result
);
2645 TRACE_(relay
)( "\1Ret message callback %p (hwnd=%p,msg=%s,data=%08lx,result=%08lx)\n",
2646 callback
, hwnd
, SPY_GetMsgName( msg
, hwnd
), data
, result
);
2650 /***********************************************************************
2653 * Peek for a message matching the given parameters. Return 0 if none are
2654 * available; -1 on error.
2655 * All pending sent messages are processed before returning.
2657 static int peek_message( MSG
*msg
, HWND hwnd
, UINT first
, UINT last
, UINT flags
, UINT changed_mask
)
2660 struct user_thread_info
*thread_info
= get_user_thread_info();
2661 INPUT_MESSAGE_SOURCE prev_source
= thread_info
->msg_source
;
2662 struct received_message_info info
, *old_info
;
2663 unsigned int hw_id
= 0; /* id of previous hardware message */
2665 size_t buffer_size
= 256;
2667 if (!(buffer
= HeapAlloc( GetProcessHeap(), 0, buffer_size
))) return -1;
2669 if (!first
&& !last
) last
= ~0;
2670 if (hwnd
== HWND_BROADCAST
) hwnd
= HWND_TOPMOST
;
2676 const message_data_t
*msg_data
= buffer
;
2678 thread_info
->msg_source
= prev_source
;
2680 SERVER_START_REQ( get_message
)
2683 req
->get_win
= wine_server_user_handle( hwnd
);
2684 req
->get_first
= first
;
2685 req
->get_last
= last
;
2687 req
->wake_mask
= changed_mask
& (QS_SENDMESSAGE
| QS_SMRESULT
);
2688 req
->changed_mask
= changed_mask
;
2689 wine_server_set_reply( req
, buffer
, buffer_size
);
2690 if (!(res
= wine_server_call( req
)))
2692 size
= wine_server_reply_size( reply
);
2693 info
.type
= reply
->type
;
2694 info
.msg
.hwnd
= wine_server_ptr_handle( reply
->win
);
2695 info
.msg
.message
= reply
->msg
;
2696 info
.msg
.wParam
= reply
->wparam
;
2697 info
.msg
.lParam
= reply
->lparam
;
2698 info
.msg
.time
= reply
->time
;
2699 info
.msg
.pt
.x
= reply
->x
;
2700 info
.msg
.pt
.y
= reply
->y
;
2702 thread_info
->active_hooks
= reply
->active_hooks
;
2704 else buffer_size
= reply
->total
;
2710 HeapFree( GetProcessHeap(), 0, buffer
);
2711 if (res
== STATUS_PENDING
)
2713 thread_info
->wake_mask
= changed_mask
& (QS_SENDMESSAGE
| QS_SMRESULT
);
2714 thread_info
->changed_mask
= changed_mask
;
2717 if (res
!= STATUS_BUFFER_OVERFLOW
)
2719 SetLastError( RtlNtStatusToDosError(res
) );
2722 if (!(buffer
= HeapAlloc( GetProcessHeap(), 0, buffer_size
))) return -1;
2726 TRACE( "got type %d msg %x (%s) hwnd %p wp %lx lp %lx\n",
2727 info
.type
, info
.msg
.message
,
2728 (info
.type
== MSG_WINEVENT
) ? "MSG_WINEVENT" : SPY_GetMsgName(info
.msg
.message
, info
.msg
.hwnd
),
2729 info
.msg
.hwnd
, info
.msg
.wParam
, info
.msg
.lParam
);
2735 info
.flags
= ISMEX_SEND
;
2738 info
.flags
= ISMEX_NOTIFY
;
2739 if (!unpack_message( info
.msg
.hwnd
, info
.msg
.message
, &info
.msg
.wParam
,
2740 &info
.msg
.lParam
, &buffer
, size
))
2744 info
.flags
= ISMEX_CALLBACK
;
2746 case MSG_CALLBACK_RESULT
:
2747 if (size
>= sizeof(msg_data
->callback
))
2748 call_sendmsg_callback( wine_server_get_ptr(msg_data
->callback
.callback
),
2749 info
.msg
.hwnd
, info
.msg
.message
,
2750 msg_data
->callback
.data
, msg_data
->callback
.result
);
2753 if (size
>= sizeof(msg_data
->winevent
))
2755 WINEVENTPROC hook_proc
;
2756 HMODULE free_module
= 0;
2758 hook_proc
= wine_server_get_ptr( msg_data
->winevent
.hook_proc
);
2759 size
-= sizeof(msg_data
->winevent
);
2762 WCHAR module
[MAX_PATH
];
2764 size
= min( size
, (MAX_PATH
- 1) * sizeof(WCHAR
) );
2765 memcpy( module
, &msg_data
->winevent
+ 1, size
);
2766 module
[size
/ sizeof(WCHAR
)] = 0;
2767 if (!(hook_proc
= get_hook_proc( hook_proc
, module
, &free_module
)))
2769 ERR( "invalid winevent hook module name %s\n", debugstr_w(module
) );
2774 TRACE_(relay
)( "\1Call winevent proc %p (hook=%04x,event=%x,hwnd=%p,object_id=%lx,child_id=%lx,tid=%04x,time=%x)\n",
2775 hook_proc
, msg_data
->winevent
.hook
, info
.msg
.message
, info
.msg
.hwnd
,
2776 info
.msg
.wParam
, info
.msg
.lParam
, msg_data
->winevent
.tid
, info
.msg
.time
);
2778 hook_proc( wine_server_ptr_handle( msg_data
->winevent
.hook
), info
.msg
.message
,
2779 info
.msg
.hwnd
, info
.msg
.wParam
, info
.msg
.lParam
,
2780 msg_data
->winevent
.tid
, info
.msg
.time
);
2782 TRACE_(relay
)( "\1Ret winevent proc %p (hook=%04x,event=%x,hwnd=%p,object_id=%lx,child_id=%lx,tid=%04x,time=%x)\n",
2783 hook_proc
, msg_data
->winevent
.hook
, info
.msg
.message
, info
.msg
.hwnd
,
2784 info
.msg
.wParam
, info
.msg
.lParam
, msg_data
->winevent
.tid
, info
.msg
.time
);
2786 if (free_module
) FreeLibrary(free_module
);
2790 info
.flags
= ISMEX_SEND
;
2792 if (info
.msg
.message
== WH_KEYBOARD_LL
&& size
>= sizeof(msg_data
->hardware
))
2794 KBDLLHOOKSTRUCT hook
;
2796 hook
.vkCode
= LOWORD( info
.msg
.lParam
);
2797 hook
.scanCode
= HIWORD( info
.msg
.lParam
);
2798 hook
.flags
= msg_data
->hardware
.flags
;
2799 hook
.time
= info
.msg
.time
;
2800 hook
.dwExtraInfo
= msg_data
->hardware
.info
;
2801 TRACE( "calling keyboard LL hook vk %x scan %x flags %x time %u info %lx\n",
2802 hook
.vkCode
, hook
.scanCode
, hook
.flags
, hook
.time
, hook
.dwExtraInfo
);
2803 result
= HOOK_CallHooks( WH_KEYBOARD_LL
, HC_ACTION
, info
.msg
.wParam
, (LPARAM
)&hook
, TRUE
);
2805 else if (info
.msg
.message
== WH_MOUSE_LL
&& size
>= sizeof(msg_data
->hardware
))
2807 MSLLHOOKSTRUCT hook
;
2809 hook
.pt
= info
.msg
.pt
;
2810 hook
.mouseData
= info
.msg
.lParam
;
2811 hook
.flags
= msg_data
->hardware
.flags
;
2812 hook
.time
= info
.msg
.time
;
2813 hook
.dwExtraInfo
= msg_data
->hardware
.info
;
2814 TRACE( "calling mouse LL hook pos %d,%d data %x flags %x time %u info %lx\n",
2815 hook
.pt
.x
, hook
.pt
.y
, hook
.mouseData
, hook
.flags
, hook
.time
, hook
.dwExtraInfo
);
2816 result
= HOOK_CallHooks( WH_MOUSE_LL
, HC_ACTION
, info
.msg
.wParam
, (LPARAM
)&hook
, TRUE
);
2818 reply_message( &info
, result
, TRUE
);
2820 case MSG_OTHER_PROCESS
:
2821 info
.flags
= ISMEX_SEND
;
2822 if (!unpack_message( info
.msg
.hwnd
, info
.msg
.message
, &info
.msg
.wParam
,
2823 &info
.msg
.lParam
, &buffer
, size
))
2826 reply_message( &info
, 0, TRUE
);
2831 if (size
>= sizeof(msg_data
->hardware
))
2833 hw_id
= msg_data
->hardware
.hw_id
;
2834 if (!process_hardware_message( &info
.msg
, hw_id
, &msg_data
->hardware
,
2835 hwnd
, first
, last
, flags
& PM_REMOVE
))
2837 TRACE("dropping msg %x\n", info
.msg
.message
);
2838 continue; /* ignore it */
2841 thread_info
->GetMessagePosVal
= MAKELONG( info
.msg
.pt
.x
, info
.msg
.pt
.y
);
2842 thread_info
->GetMessageTimeVal
= info
.msg
.time
;
2843 thread_info
->GetMessageExtraInfoVal
= msg_data
->hardware
.info
;
2844 HeapFree( GetProcessHeap(), 0, buffer
);
2845 HOOK_CallHooks( WH_GETMESSAGE
, HC_ACTION
, flags
& PM_REMOVE
, (LPARAM
)msg
, TRUE
);
2850 if (info
.msg
.message
& 0x80000000) /* internal message */
2852 if (flags
& PM_REMOVE
)
2854 handle_internal_message( info
.msg
.hwnd
, info
.msg
.message
,
2855 info
.msg
.wParam
, info
.msg
.lParam
);
2856 /* if this is a nested call return right away */
2857 if (first
== info
.msg
.message
&& last
== info
.msg
.message
)
2859 HeapFree( GetProcessHeap(), 0, buffer
);
2864 peek_message( msg
, info
.msg
.hwnd
, info
.msg
.message
,
2865 info
.msg
.message
, flags
| PM_REMOVE
, changed_mask
);
2868 if (info
.msg
.message
>= WM_DDE_FIRST
&& info
.msg
.message
<= WM_DDE_LAST
)
2870 if (!unpack_dde_message( info
.msg
.hwnd
, info
.msg
.message
, &info
.msg
.wParam
,
2871 &info
.msg
.lParam
, &buffer
, size
))
2872 continue; /* ignore it */
2875 msg
->pt
= point_phys_to_win_dpi( info
.msg
.hwnd
, info
.msg
.pt
);
2876 thread_info
->GetMessagePosVal
= MAKELONG( msg
->pt
.x
, msg
->pt
.y
);
2877 thread_info
->GetMessageTimeVal
= info
.msg
.time
;
2878 thread_info
->GetMessageExtraInfoVal
= 0;
2879 thread_info
->msg_source
= msg_source_unavailable
;
2880 HeapFree( GetProcessHeap(), 0, buffer
);
2881 HOOK_CallHooks( WH_GETMESSAGE
, HC_ACTION
, flags
& PM_REMOVE
, (LPARAM
)msg
, TRUE
);
2885 /* if we get here, we have a sent message; call the window procedure */
2886 old_info
= thread_info
->receive_info
;
2887 thread_info
->receive_info
= &info
;
2888 thread_info
->msg_source
= msg_source_unavailable
;
2889 result
= call_window_proc( info
.msg
.hwnd
, info
.msg
.message
, info
.msg
.wParam
,
2890 info
.msg
.lParam
, (info
.type
!= MSG_ASCII
), FALSE
,
2891 WMCHAR_MAP_RECVMESSAGE
);
2892 reply_message( &info
, result
, TRUE
);
2893 thread_info
->receive_info
= old_info
;
2895 /* if some PM_QS* flags were specified, only handle sent messages from now on */
2896 if (HIWORD(flags
) && !changed_mask
) flags
= PM_QS_SENDMESSAGE
| LOWORD(flags
);
2901 /***********************************************************************
2902 * process_sent_messages
2904 * Process all pending sent messages.
2906 static inline void process_sent_messages(void)
2909 peek_message( &msg
, 0, 0, 0, PM_REMOVE
| PM_QS_SENDMESSAGE
, 0 );
2913 /***********************************************************************
2914 * get_server_queue_handle
2916 * Get a handle to the server message queue for the current thread.
2918 static HANDLE
get_server_queue_handle(void)
2920 struct user_thread_info
*thread_info
= get_user_thread_info();
2923 if (!(ret
= thread_info
->server_queue
))
2925 SERVER_START_REQ( get_msg_queue
)
2927 wine_server_call( req
);
2928 ret
= wine_server_ptr_handle( reply
->handle
);
2931 thread_info
->server_queue
= ret
;
2932 if (!ret
) ERR( "Cannot get server thread queue\n" );
2938 /***********************************************************************
2939 * wait_message_reply
2941 * Wait until a sent message gets replied to.
2943 static void wait_message_reply( UINT flags
)
2945 struct user_thread_info
*thread_info
= get_user_thread_info();
2946 HANDLE server_queue
= get_server_queue_handle();
2947 unsigned int wake_mask
= QS_SMRESULT
| ((flags
& SMTO_BLOCK
) ? 0 : QS_SENDMESSAGE
);
2951 unsigned int wake_bits
= 0;
2953 SERVER_START_REQ( set_queue_mask
)
2955 req
->wake_mask
= wake_mask
;
2956 req
->changed_mask
= wake_mask
;
2958 if (!wine_server_call( req
)) wake_bits
= reply
->wake_bits
& wake_mask
;
2962 thread_info
->wake_mask
= thread_info
->changed_mask
= 0;
2964 if (wake_bits
& QS_SMRESULT
) return; /* got a result */
2965 if (wake_bits
& QS_SENDMESSAGE
)
2967 /* Process the sent message immediately */
2968 process_sent_messages();
2972 wow_handlers
.wait_message( 1, &server_queue
, INFINITE
, wake_mask
, 0 );
2977 /***********************************************************************
2980 * Wait for multiple objects including the server queue, with specific queue masks.
2982 static DWORD
wait_objects( DWORD count
, const HANDLE
*handles
, DWORD timeout
,
2983 DWORD wake_mask
, DWORD changed_mask
, DWORD flags
)
2985 struct user_thread_info
*thread_info
= get_user_thread_info();
2988 assert( count
); /* we must have at least the server queue */
2990 flush_window_surfaces( TRUE
);
2992 if (thread_info
->wake_mask
!= wake_mask
|| thread_info
->changed_mask
!= changed_mask
)
2994 SERVER_START_REQ( set_queue_mask
)
2996 req
->wake_mask
= wake_mask
;
2997 req
->changed_mask
= changed_mask
;
2999 wine_server_call( req
);
3002 thread_info
->wake_mask
= wake_mask
;
3003 thread_info
->changed_mask
= changed_mask
;
3006 ret
= wow_handlers
.wait_message( count
, handles
, timeout
, changed_mask
, flags
);
3008 if (ret
!= WAIT_TIMEOUT
) thread_info
->wake_mask
= thread_info
->changed_mask
= 0;
3013 /***********************************************************************
3014 * put_message_in_queue
3016 * Put a sent message into the destination queue.
3017 * For inter-process message, reply_size is set to expected size of reply data.
3019 static BOOL
put_message_in_queue( const struct send_message_info
*info
, size_t *reply_size
)
3021 struct packed_message data
;
3022 message_data_t msg_data
;
3025 timeout_t timeout
= TIMEOUT_INFINITE
;
3027 /* Check for INFINITE timeout for compatibility with Win9x,
3028 * although Windows >= NT does not do so
3030 if (info
->type
!= MSG_NOTIFY
&&
3031 info
->type
!= MSG_CALLBACK
&&
3032 info
->type
!= MSG_POSTED
&&
3034 info
->timeout
!= INFINITE
)
3036 /* timeout is signed despite the prototype */
3037 timeout
= (timeout_t
)max( 0, (int)info
->timeout
) * -10000;
3040 memset( &data
, 0, sizeof(data
) );
3041 if (info
->type
== MSG_OTHER_PROCESS
|| info
->type
== MSG_NOTIFY
)
3043 *reply_size
= pack_message( info
->hwnd
, info
->msg
, info
->wparam
, info
->lparam
, &data
);
3044 if (data
.count
== -1)
3046 WARN( "cannot pack message %x\n", info
->msg
);
3050 else if (info
->type
== MSG_CALLBACK
)
3052 msg_data
.callback
.callback
= wine_server_client_ptr( info
->callback
);
3053 msg_data
.callback
.data
= info
->data
;
3054 msg_data
.callback
.result
= 0;
3055 data
.data
[0] = &msg_data
;
3056 data
.size
[0] = sizeof(msg_data
.callback
);
3059 else if (info
->type
== MSG_POSTED
&& info
->msg
>= WM_DDE_FIRST
&& info
->msg
<= WM_DDE_LAST
)
3061 return post_dde_message( &data
, info
);
3064 SERVER_START_REQ( send_message
)
3066 req
->id
= info
->dest_tid
;
3067 req
->type
= info
->type
;
3069 req
->win
= wine_server_user_handle( info
->hwnd
);
3070 req
->msg
= info
->msg
;
3071 req
->wparam
= info
->wparam
;
3072 req
->lparam
= info
->lparam
;
3073 req
->timeout
= timeout
;
3075 if (info
->flags
& SMTO_ABORTIFHUNG
) req
->flags
|= SEND_MSG_ABORT_IF_HUNG
;
3076 for (i
= 0; i
< data
.count
; i
++) wine_server_add_data( req
, data
.data
[i
], data
.size
[i
] );
3077 if ((res
= wine_server_call( req
)))
3079 if (res
== STATUS_INVALID_PARAMETER
)
3080 /* FIXME: find a STATUS_ value for this one */
3081 SetLastError( ERROR_INVALID_THREAD_ID
);
3083 SetLastError( RtlNtStatusToDosError(res
) );
3091 /***********************************************************************
3094 * Retrieve a message reply from the server.
3096 static LRESULT
retrieve_reply( const struct send_message_info
*info
,
3097 size_t reply_size
, LRESULT
*result
)
3100 void *reply_data
= NULL
;
3104 if (!(reply_data
= HeapAlloc( GetProcessHeap(), 0, reply_size
)))
3106 WARN( "no memory for reply, will be truncated\n" );
3110 SERVER_START_REQ( get_message_reply
)
3113 if (reply_size
) wine_server_set_reply( req
, reply_data
, reply_size
);
3114 if (!(status
= wine_server_call( req
))) *result
= reply
->result
;
3115 reply_size
= wine_server_reply_size( reply
);
3118 if (!status
&& reply_size
)
3119 unpack_reply( info
->hwnd
, info
->msg
, info
->wparam
, info
->lparam
, reply_data
, reply_size
);
3121 HeapFree( GetProcessHeap(), 0, reply_data
);
3123 TRACE( "hwnd %p msg %x (%s) wp %lx lp %lx got reply %lx (err=%d)\n",
3124 info
->hwnd
, info
->msg
, SPY_GetMsgName(info
->msg
, info
->hwnd
), info
->wparam
,
3125 info
->lparam
, *result
, status
);
3127 /* MSDN states that last error is 0 on timeout, but at least NT4 returns ERROR_TIMEOUT */
3128 if (status
) SetLastError( RtlNtStatusToDosError(status
) );
3133 /***********************************************************************
3134 * send_inter_thread_message
3136 static LRESULT
send_inter_thread_message( const struct send_message_info
*info
, LRESULT
*res_ptr
)
3138 size_t reply_size
= 0;
3140 TRACE( "hwnd %p msg %x (%s) wp %lx lp %lx\n",
3141 info
->hwnd
, info
->msg
, SPY_GetMsgName(info
->msg
, info
->hwnd
), info
->wparam
, info
->lparam
);
3143 USER_CheckNotLock();
3145 if (!put_message_in_queue( info
, &reply_size
)) return 0;
3147 /* there's no reply to wait for on notify/callback messages */
3148 if (info
->type
== MSG_NOTIFY
|| info
->type
== MSG_CALLBACK
) return 1;
3150 wait_message_reply( info
->flags
);
3151 return retrieve_reply( info
, reply_size
, res_ptr
);
3155 /***********************************************************************
3156 * send_inter_thread_callback
3158 static LRESULT
send_inter_thread_callback( HWND hwnd
, UINT msg
, WPARAM wp
, LPARAM lp
,
3159 LRESULT
*result
, void *arg
)
3161 struct send_message_info
*info
= arg
;
3166 return send_inter_thread_message( info
, result
);
3169 static BOOL
is_message_broadcastable(UINT msg
)
3171 return msg
< WM_USER
|| msg
>= 0xc000;
3174 /***********************************************************************
3177 * Backend implementation of the various SendMessage functions.
3179 static BOOL
send_message( struct send_message_info
*info
, DWORD_PTR
*res_ptr
, BOOL unicode
)
3181 struct user_thread_info
*thread_info
= get_user_thread_info();
3182 INPUT_MESSAGE_SOURCE prev_source
= thread_info
->msg_source
;
3187 if (is_broadcast(info
->hwnd
))
3189 if (is_message_broadcastable( info
->msg
))
3190 EnumWindows( broadcast_message_callback
, (LPARAM
)info
);
3191 if (res_ptr
) *res_ptr
= 1;
3195 if (!(info
->dest_tid
= GetWindowThreadProcessId( info
->hwnd
, &dest_pid
))) return FALSE
;
3197 if (USER_IsExitingThread( info
->dest_tid
)) return FALSE
;
3199 thread_info
->msg_source
= msg_source_unavailable
;
3200 SPY_EnterMessage( SPY_SENDMESSAGE
, info
->hwnd
, info
->msg
, info
->wparam
, info
->lparam
);
3202 if (info
->dest_tid
== GetCurrentThreadId())
3204 result
= call_window_proc( info
->hwnd
, info
->msg
, info
->wparam
, info
->lparam
,
3205 unicode
, TRUE
, info
->wm_char
);
3206 if (info
->type
== MSG_CALLBACK
)
3207 call_sendmsg_callback( info
->callback
, info
->hwnd
, info
->msg
, info
->data
, result
);
3212 if (dest_pid
!= GetCurrentProcessId() && (info
->type
== MSG_ASCII
|| info
->type
== MSG_UNICODE
))
3213 info
->type
= MSG_OTHER_PROCESS
;
3215 /* MSG_ASCII can be sent unconverted except for WM_CHAR; everything else needs to be Unicode */
3216 if (!unicode
&& is_unicode_message( info
->msg
) &&
3217 (info
->type
!= MSG_ASCII
|| info
->msg
== WM_CHAR
))
3218 ret
= WINPROC_CallProcAtoW( send_inter_thread_callback
, info
->hwnd
, info
->msg
,
3219 info
->wparam
, info
->lparam
, &result
, info
, info
->wm_char
);
3221 ret
= send_inter_thread_message( info
, &result
);
3224 SPY_ExitMessage( SPY_RESULT_OK
, info
->hwnd
, info
->msg
, result
, info
->wparam
, info
->lparam
);
3225 thread_info
->msg_source
= prev_source
;
3226 if (ret
&& res_ptr
) *res_ptr
= result
;
3231 /***********************************************************************
3232 * send_hardware_message
3234 NTSTATUS
send_hardware_message( HWND hwnd
, const INPUT
*input
, const RAWINPUT
*rawinput
, UINT flags
)
3236 struct user_key_state_info
*key_state_info
= get_user_thread_info()->key_state
;
3237 struct send_message_info info
;
3238 int prev_x
, prev_y
, new_x
, new_y
;
3239 INT counter
= global_key_state_counter
;
3240 USAGE hid_usage_page
, hid_usage
;
3244 info
.type
= MSG_HARDWARE
;
3250 if (input
->type
== INPUT_HARDWARE
&& rawinput
->header
.dwType
== RIM_TYPEHID
)
3252 if (input
->u
.hi
.uMsg
== WM_INPUT_DEVICE_CHANGE
)
3254 hid_usage_page
= ((USAGE
*)rawinput
->data
.hid
.bRawData
)[0];
3255 hid_usage
= ((USAGE
*)rawinput
->data
.hid
.bRawData
)[1];
3259 SERVER_START_REQ( send_hardware_message
)
3261 req
->win
= wine_server_user_handle( hwnd
);
3263 req
->input
.type
= input
->type
;
3264 switch (input
->type
)
3267 req
->input
.mouse
.x
= input
->u
.mi
.dx
;
3268 req
->input
.mouse
.y
= input
->u
.mi
.dy
;
3269 req
->input
.mouse
.data
= input
->u
.mi
.mouseData
;
3270 req
->input
.mouse
.flags
= input
->u
.mi
.dwFlags
;
3271 req
->input
.mouse
.time
= input
->u
.mi
.time
;
3272 req
->input
.mouse
.info
= input
->u
.mi
.dwExtraInfo
;
3274 case INPUT_KEYBOARD
:
3275 req
->input
.kbd
.vkey
= input
->u
.ki
.wVk
;
3276 req
->input
.kbd
.scan
= input
->u
.ki
.wScan
;
3277 req
->input
.kbd
.flags
= input
->u
.ki
.dwFlags
;
3278 req
->input
.kbd
.time
= input
->u
.ki
.time
;
3279 req
->input
.kbd
.info
= input
->u
.ki
.dwExtraInfo
;
3281 case INPUT_HARDWARE
:
3282 req
->input
.hw
.msg
= input
->u
.hi
.uMsg
;
3283 req
->input
.hw
.lparam
= MAKELONG( input
->u
.hi
.wParamL
, input
->u
.hi
.wParamH
);
3284 switch (input
->u
.hi
.uMsg
)
3286 case WM_INPUT_DEVICE_CHANGE
:
3287 req
->input
.hw
.rawinput
.type
= rawinput
->header
.dwType
;
3288 switch (rawinput
->header
.dwType
)
3291 assert( rawinput
->data
.hid
.dwCount
<= 1 );
3292 req
->input
.hw
.rawinput
.hid
.device
= HandleToUlong( rawinput
->header
.hDevice
);
3293 req
->input
.hw
.rawinput
.hid
.param
= rawinput
->header
.wParam
;
3294 req
->input
.hw
.rawinput
.hid
.usage_page
= hid_usage_page
;
3295 req
->input
.hw
.rawinput
.hid
.usage
= hid_usage
;
3304 if (key_state_info
) wine_server_set_reply( req
, key_state_info
->state
,
3305 sizeof(key_state_info
->state
) );
3306 ret
= wine_server_call( req
);
3308 prev_x
= reply
->prev_x
;
3309 prev_y
= reply
->prev_y
;
3310 new_x
= reply
->new_x
;
3311 new_y
= reply
->new_y
;
3319 key_state_info
->time
= GetTickCount();
3320 key_state_info
->counter
= counter
;
3322 if ((flags
& SEND_HWMSG_INJECTED
) && (prev_x
!= new_x
|| prev_y
!= new_y
))
3323 USER_Driver
->pSetCursorPos( new_x
, new_y
);
3329 wait_message_reply( 0 );
3330 retrieve_reply( &info
, 0, &ignored
);
3336 /***********************************************************************
3337 * MSG_SendInternalMessageTimeout
3339 * Same as SendMessageTimeoutW but sends the message to a specific thread
3340 * without requiring a window handle. Only works for internal Wine messages.
3342 LRESULT
MSG_SendInternalMessageTimeout( DWORD dest_pid
, DWORD dest_tid
,
3343 UINT msg
, WPARAM wparam
, LPARAM lparam
,
3344 UINT flags
, UINT timeout
, PDWORD_PTR res_ptr
)
3346 struct send_message_info info
;
3347 LRESULT ret
, result
;
3349 assert( msg
& 0x80000000 ); /* must be an internal Wine message */
3351 info
.type
= MSG_UNICODE
;
3352 info
.dest_tid
= dest_tid
;
3355 info
.wparam
= wparam
;
3356 info
.lparam
= lparam
;
3358 info
.timeout
= timeout
;
3360 if (USER_IsExitingThread( dest_tid
)) return 0;
3362 if (dest_tid
== GetCurrentThreadId())
3364 result
= handle_internal_message( 0, msg
, wparam
, lparam
);
3369 if (dest_pid
!= GetCurrentProcessId()) info
.type
= MSG_OTHER_PROCESS
;
3370 ret
= send_inter_thread_message( &info
, &result
);
3372 if (ret
&& res_ptr
) *res_ptr
= result
;
3377 /***********************************************************************
3378 * SendMessageTimeoutW (USER32.@)
3380 LRESULT WINAPI
SendMessageTimeoutW( HWND hwnd
, UINT msg
, WPARAM wparam
, LPARAM lparam
,
3381 UINT flags
, UINT timeout
, PDWORD_PTR res_ptr
)
3383 struct send_message_info info
;
3385 info
.type
= MSG_UNICODE
;
3388 info
.wparam
= wparam
;
3389 info
.lparam
= lparam
;
3391 info
.timeout
= timeout
;
3393 return send_message( &info
, res_ptr
, TRUE
);
3396 /***********************************************************************
3397 * SendMessageTimeoutA (USER32.@)
3399 LRESULT WINAPI
SendMessageTimeoutA( HWND hwnd
, UINT msg
, WPARAM wparam
, LPARAM lparam
,
3400 UINT flags
, UINT timeout
, PDWORD_PTR res_ptr
)
3402 struct send_message_info info
;
3404 info
.type
= MSG_ASCII
;
3407 info
.wparam
= wparam
;
3408 info
.lparam
= lparam
;
3410 info
.timeout
= timeout
;
3411 info
.wm_char
= WMCHAR_MAP_SENDMESSAGETIMEOUT
;
3413 return send_message( &info
, res_ptr
, FALSE
);
3417 /***********************************************************************
3418 * SendMessageW (USER32.@)
3420 LRESULT WINAPI
SendMessageW( HWND hwnd
, UINT msg
, WPARAM wparam
, LPARAM lparam
)
3423 struct send_message_info info
;
3425 info
.type
= MSG_UNICODE
;
3428 info
.wparam
= wparam
;
3429 info
.lparam
= lparam
;
3430 info
.flags
= SMTO_NORMAL
;
3433 send_message( &info
, &res
, TRUE
);
3438 /***********************************************************************
3439 * SendMessageA (USER32.@)
3441 LRESULT WINAPI
SendMessageA( HWND hwnd
, UINT msg
, WPARAM wparam
, LPARAM lparam
)
3444 struct send_message_info info
;
3446 info
.type
= MSG_ASCII
;
3449 info
.wparam
= wparam
;
3450 info
.lparam
= lparam
;
3451 info
.flags
= SMTO_NORMAL
;
3453 info
.wm_char
= WMCHAR_MAP_SENDMESSAGE
;
3455 send_message( &info
, &res
, FALSE
);
3460 /***********************************************************************
3461 * SendNotifyMessageA (USER32.@)
3463 BOOL WINAPI
SendNotifyMessageA( HWND hwnd
, UINT msg
, WPARAM wparam
, LPARAM lparam
)
3465 struct send_message_info info
;
3467 if (is_pointer_message( msg
, wparam
))
3469 SetLastError( ERROR_MESSAGE_SYNC_ONLY
);
3473 info
.type
= MSG_NOTIFY
;
3476 info
.wparam
= wparam
;
3477 info
.lparam
= lparam
;
3479 info
.wm_char
= WMCHAR_MAP_SENDMESSAGETIMEOUT
;
3481 return send_message( &info
, NULL
, FALSE
);
3485 /***********************************************************************
3486 * SendNotifyMessageW (USER32.@)
3488 BOOL WINAPI
SendNotifyMessageW( HWND hwnd
, UINT msg
, WPARAM wparam
, LPARAM lparam
)
3490 struct send_message_info info
;
3492 if (is_pointer_message( msg
, wparam
))
3494 SetLastError( ERROR_MESSAGE_SYNC_ONLY
);
3498 info
.type
= MSG_NOTIFY
;
3501 info
.wparam
= wparam
;
3502 info
.lparam
= lparam
;
3505 return send_message( &info
, NULL
, TRUE
);
3509 /***********************************************************************
3510 * SendMessageCallbackA (USER32.@)
3512 BOOL WINAPI
SendMessageCallbackA( HWND hwnd
, UINT msg
, WPARAM wparam
, LPARAM lparam
,
3513 SENDASYNCPROC callback
, ULONG_PTR data
)
3515 struct send_message_info info
;
3517 if (is_pointer_message( msg
, wparam
))
3519 SetLastError( ERROR_MESSAGE_SYNC_ONLY
);
3523 info
.type
= MSG_CALLBACK
;
3526 info
.wparam
= wparam
;
3527 info
.lparam
= lparam
;
3528 info
.callback
= callback
;
3531 info
.wm_char
= WMCHAR_MAP_SENDMESSAGETIMEOUT
;
3533 return send_message( &info
, NULL
, FALSE
);
3537 /***********************************************************************
3538 * SendMessageCallbackW (USER32.@)
3540 BOOL WINAPI
SendMessageCallbackW( HWND hwnd
, UINT msg
, WPARAM wparam
, LPARAM lparam
,
3541 SENDASYNCPROC callback
, ULONG_PTR data
)
3543 struct send_message_info info
;
3545 if (is_pointer_message( msg
, wparam
))
3547 SetLastError( ERROR_MESSAGE_SYNC_ONLY
);
3551 info
.type
= MSG_CALLBACK
;
3554 info
.wparam
= wparam
;
3555 info
.lparam
= lparam
;
3556 info
.callback
= callback
;
3560 return send_message( &info
, NULL
, TRUE
);
3564 /***********************************************************************
3565 * ReplyMessage (USER32.@)
3567 BOOL WINAPI
ReplyMessage( LRESULT result
)
3569 struct received_message_info
*info
= get_user_thread_info()->receive_info
;
3571 if (!info
) return FALSE
;
3572 reply_message( info
, result
, FALSE
);
3577 /***********************************************************************
3578 * InSendMessage (USER32.@)
3580 BOOL WINAPI
InSendMessage(void)
3582 return (InSendMessageEx( NULL
) & (ISMEX_SEND
| ISMEX_NOTIFY
| ISMEX_CALLBACK
)) != 0;
3586 /***********************************************************************
3587 * InSendMessageEx (USER32.@)
3589 DWORD WINAPI
InSendMessageEx( LPVOID reserved
)
3591 struct received_message_info
*info
= get_user_thread_info()->receive_info
;
3593 if (info
) return info
->flags
;
3594 return ISMEX_NOSEND
;
3598 /***********************************************************************
3599 * PostMessageA (USER32.@)
3601 BOOL WINAPI
PostMessageA( HWND hwnd
, UINT msg
, WPARAM wparam
, LPARAM lparam
)
3603 if (!map_wparam_AtoW( msg
, &wparam
, WMCHAR_MAP_POSTMESSAGE
)) return TRUE
;
3604 return PostMessageW( hwnd
, msg
, wparam
, lparam
);
3608 /***********************************************************************
3609 * PostMessageW (USER32.@)
3611 BOOL WINAPI
PostMessageW( HWND hwnd
, UINT msg
, WPARAM wparam
, LPARAM lparam
)
3613 struct send_message_info info
;
3615 if (is_pointer_message( msg
, wparam
))
3617 SetLastError( ERROR_MESSAGE_SYNC_ONLY
);
3621 TRACE( "hwnd %p msg %x (%s) wp %lx lp %lx\n",
3622 hwnd
, msg
, SPY_GetMsgName(msg
, hwnd
), wparam
, lparam
);
3624 info
.type
= MSG_POSTED
;
3627 info
.wparam
= wparam
;
3628 info
.lparam
= lparam
;
3631 if (is_broadcast(hwnd
))
3633 if (is_message_broadcastable( info
.msg
))
3634 EnumWindows( broadcast_message_callback
, (LPARAM
)&info
);
3638 if (!hwnd
) return PostThreadMessageW( GetCurrentThreadId(), msg
, wparam
, lparam
);
3640 if (!(info
.dest_tid
= GetWindowThreadProcessId( hwnd
, NULL
))) return FALSE
;
3642 if (USER_IsExitingThread( info
.dest_tid
)) return TRUE
;
3644 return put_message_in_queue( &info
, NULL
);
3648 /**********************************************************************
3649 * PostThreadMessageA (USER32.@)
3651 BOOL WINAPI
PostThreadMessageA( DWORD thread
, UINT msg
, WPARAM wparam
, LPARAM lparam
)
3653 if (!map_wparam_AtoW( msg
, &wparam
, WMCHAR_MAP_POSTMESSAGE
)) return TRUE
;
3654 return PostThreadMessageW( thread
, msg
, wparam
, lparam
);
3658 /**********************************************************************
3659 * PostThreadMessageW (USER32.@)
3661 BOOL WINAPI
PostThreadMessageW( DWORD thread
, UINT msg
, WPARAM wparam
, LPARAM lparam
)
3663 struct send_message_info info
;
3665 if (is_pointer_message( msg
, wparam
))
3667 SetLastError( ERROR_MESSAGE_SYNC_ONLY
);
3670 if (USER_IsExitingThread( thread
)) return TRUE
;
3672 info
.type
= MSG_POSTED
;
3673 info
.dest_tid
= thread
;
3676 info
.wparam
= wparam
;
3677 info
.lparam
= lparam
;
3679 return put_message_in_queue( &info
, NULL
);
3683 /***********************************************************************
3684 * PostQuitMessage (USER32.@)
3686 * Posts a quit message to the current thread's message queue.
3689 * exit_code [I] Exit code to return from message loop.
3695 * This function is not the same as calling:
3696 *|PostThreadMessage(GetCurrentThreadId(), WM_QUIT, exit_code, 0);
3697 * It instead sets a flag in the message queue that signals it to generate
3698 * a WM_QUIT message when there are no other pending sent or posted messages
3701 void WINAPI
PostQuitMessage( INT exit_code
)
3703 SERVER_START_REQ( post_quit_message
)
3705 req
->exit_code
= exit_code
;
3706 wine_server_call( req
);
3711 /* check for driver events if we detect that the app is not properly consuming messages */
3712 static inline void check_for_driver_events( UINT msg
)
3714 if (get_user_thread_info()->message_count
> 200)
3716 flush_window_surfaces( FALSE
);
3717 USER_Driver
->pMsgWaitForMultipleObjectsEx( 0, NULL
, 0, QS_ALLINPUT
, 0 );
3719 else if (msg
== WM_TIMER
|| msg
== WM_SYSTIMER
)
3721 /* driver events should have priority over timers, so make sure we'll check for them soon */
3722 get_user_thread_info()->message_count
+= 100;
3724 else get_user_thread_info()->message_count
++;
3727 /***********************************************************************
3728 * PeekMessageW (USER32.@)
3730 BOOL WINAPI DECLSPEC_HOTPATCH
PeekMessageW( MSG
*msg_out
, HWND hwnd
, UINT first
, UINT last
, UINT flags
)
3735 USER_CheckNotLock();
3736 check_for_driver_events( 0 );
3738 ret
= peek_message( &msg
, hwnd
, first
, last
, flags
, 0 );
3739 if (ret
< 0) return FALSE
;
3743 flush_window_surfaces( TRUE
);
3744 ret
= wow_handlers
.wait_message( 0, NULL
, 0, QS_ALLINPUT
, 0 );
3745 /* if we received driver events, check again for a pending message */
3746 if (ret
== WAIT_TIMEOUT
|| peek_message( &msg
, hwnd
, first
, last
, flags
, 0 ) <= 0) return FALSE
;
3749 check_for_driver_events( msg
.message
);
3751 /* copy back our internal safe copy of message data to msg_out.
3752 * msg_out is a variable from the *program*, so it can't be used
3753 * internally as it can get "corrupted" by our use of SendMessage()
3754 * (back to the program) inside the message handling itself. */
3757 SetLastError( ERROR_NOACCESS
);
3765 /***********************************************************************
3766 * PeekMessageA (USER32.@)
3768 BOOL WINAPI DECLSPEC_HOTPATCH
PeekMessageA( MSG
*msg
, HWND hwnd
, UINT first
, UINT last
, UINT flags
)
3770 if (get_pending_wmchar( msg
, first
, last
, (flags
& PM_REMOVE
) )) return TRUE
;
3771 if (!PeekMessageW( msg
, hwnd
, first
, last
, flags
)) return FALSE
;
3772 map_wparam_WtoA( msg
, (flags
& PM_REMOVE
) );
3777 /***********************************************************************
3778 * GetMessageW (USER32.@)
3780 BOOL WINAPI DECLSPEC_HOTPATCH
GetMessageW( MSG
*msg
, HWND hwnd
, UINT first
, UINT last
)
3782 HANDLE server_queue
= get_server_queue_handle();
3783 unsigned int mask
= QS_POSTMESSAGE
| QS_SENDMESSAGE
; /* Always selected */
3786 USER_CheckNotLock();
3787 check_for_driver_events( 0 );
3791 if ((first
<= WM_KEYLAST
) && (last
>= WM_KEYFIRST
)) mask
|= QS_KEY
;
3792 if ( ((first
<= WM_MOUSELAST
) && (last
>= WM_MOUSEFIRST
)) ||
3793 ((first
<= WM_NCMOUSELAST
) && (last
>= WM_NCMOUSEFIRST
)) ) mask
|= QS_MOUSE
;
3794 if ((first
<= WM_TIMER
) && (last
>= WM_TIMER
)) mask
|= QS_TIMER
;
3795 if ((first
<= WM_SYSTIMER
) && (last
>= WM_SYSTIMER
)) mask
|= QS_TIMER
;
3796 if ((first
<= WM_PAINT
) && (last
>= WM_PAINT
)) mask
|= QS_PAINT
;
3798 else mask
= QS_ALLINPUT
;
3800 while (!(ret
= peek_message( msg
, hwnd
, first
, last
, PM_REMOVE
| (mask
<< 16), mask
)))
3802 wait_objects( 1, &server_queue
, INFINITE
, mask
& (QS_SENDMESSAGE
| QS_SMRESULT
), mask
, 0 );
3804 if (ret
< 0) return -1;
3806 check_for_driver_events( msg
->message
);
3808 return (msg
->message
!= WM_QUIT
);
3812 /***********************************************************************
3813 * GetMessageA (USER32.@)
3815 BOOL WINAPI DECLSPEC_HOTPATCH
GetMessageA( MSG
*msg
, HWND hwnd
, UINT first
, UINT last
)
3817 if (get_pending_wmchar( msg
, first
, last
, TRUE
)) return TRUE
;
3818 if (GetMessageW( msg
, hwnd
, first
, last
) < 0) return -1;
3819 map_wparam_WtoA( msg
, TRUE
);
3820 return (msg
->message
!= WM_QUIT
);
3824 /***********************************************************************
3825 * IsDialogMessageA (USER32.@)
3826 * IsDialogMessage (USER32.@)
3828 BOOL WINAPI
IsDialogMessageA( HWND hwndDlg
, LPMSG pmsg
)
3831 map_wparam_AtoW( msg
.message
, &msg
.wParam
, WMCHAR_MAP_NOMAPPING
);
3832 return IsDialogMessageW( hwndDlg
, &msg
);
3836 /***********************************************************************
3837 * TranslateMessage (USER32.@)
3839 * Implementation of TranslateMessage.
3841 * TranslateMessage translates virtual-key messages into character-messages,
3843 * WM_KEYDOWN/WM_KEYUP combinations produce a WM_CHAR or WM_DEADCHAR message.
3844 * ditto replacing WM_* with WM_SYS*
3845 * This produces WM_CHAR messages only for keys mapped to ASCII characters
3846 * by the keyboard driver.
3848 * If the message is WM_KEYDOWN, WM_KEYUP, WM_SYSKEYDOWN, or WM_SYSKEYUP, the
3849 * return value is nonzero, regardless of the translation.
3852 BOOL WINAPI
TranslateMessage( const MSG
*msg
)
3859 if (msg
->message
< WM_KEYFIRST
|| msg
->message
> WM_KEYLAST
) return FALSE
;
3860 if (msg
->message
!= WM_KEYDOWN
&& msg
->message
!= WM_SYSKEYDOWN
) return TRUE
;
3862 TRACE_(key
)("Translating key %s (%04lX), scancode %04x\n",
3863 SPY_GetVKeyName(msg
->wParam
), msg
->wParam
, HIWORD(msg
->lParam
));
3865 switch (msg
->wParam
)
3868 message
= (msg
->message
== WM_KEYDOWN
) ? WM_CHAR
: WM_SYSCHAR
;
3869 TRACE_(key
)("PostMessageW(%p,%s,%04x,%08x)\n",
3870 msg
->hwnd
, SPY_GetMsgName(message
, msg
->hwnd
), HIWORD(msg
->lParam
), LOWORD(msg
->lParam
));
3871 PostMessageW( msg
->hwnd
, message
, HIWORD(msg
->lParam
), LOWORD(msg
->lParam
));
3875 return ImmTranslateMessage(msg
->hwnd
, msg
->message
, msg
->wParam
, msg
->lParam
);
3878 GetKeyboardState( state
);
3879 len
= ToUnicode(msg
->wParam
, HIWORD(msg
->lParam
), state
, wp
, ARRAY_SIZE(wp
), 0);
3882 message
= (msg
->message
== WM_KEYDOWN
) ? WM_DEADCHAR
: WM_SYSDEADCHAR
;
3883 TRACE_(key
)("-1 -> PostMessageW(%p,%s,%04x,%08lx)\n",
3884 msg
->hwnd
, SPY_GetMsgName(message
, msg
->hwnd
), wp
[0], msg
->lParam
);
3885 PostMessageW( msg
->hwnd
, message
, wp
[0], msg
->lParam
);
3891 message
= (msg
->message
== WM_KEYDOWN
) ? WM_CHAR
: WM_SYSCHAR
;
3892 TRACE_(key
)("%d -> PostMessageW(%p,%s,<x>,%08lx) for <x> in %s\n", len
, msg
->hwnd
,
3893 SPY_GetMsgName(message
, msg
->hwnd
), msg
->lParam
, debugstr_wn(wp
, len
));
3894 for (i
= 0; i
< len
; i
++)
3895 PostMessageW( msg
->hwnd
, message
, wp
[i
], msg
->lParam
);
3901 /***********************************************************************
3902 * DispatchMessageA (USER32.@)
3904 * See DispatchMessageW.
3906 LRESULT WINAPI DECLSPEC_HOTPATCH
DispatchMessageA( const MSG
* msg
)
3910 /* Process timer messages */
3911 if ((msg
->message
== WM_TIMER
) || (msg
->message
== WM_SYSTIMER
))
3917 retval
= CallWindowProcA( (WNDPROC
)msg
->lParam
, msg
->hwnd
,
3918 msg
->message
, msg
->wParam
, GetTickCount() );
3928 if (!msg
->hwnd
) return 0;
3930 SPY_EnterMessage( SPY_DISPATCHMESSAGE
, msg
->hwnd
, msg
->message
,
3931 msg
->wParam
, msg
->lParam
);
3933 if (!WINPROC_call_window( msg
->hwnd
, msg
->message
, msg
->wParam
, msg
->lParam
,
3934 &retval
, FALSE
, WMCHAR_MAP_DISPATCHMESSAGE
))
3936 if (!IsWindow( msg
->hwnd
)) SetLastError( ERROR_INVALID_WINDOW_HANDLE
);
3937 else SetLastError( ERROR_MESSAGE_SYNC_ONLY
);
3941 SPY_ExitMessage( SPY_RESULT_OK
, msg
->hwnd
, msg
->message
, retval
,
3942 msg
->wParam
, msg
->lParam
);
3944 if (msg
->message
== WM_PAINT
)
3946 /* send a WM_NCPAINT and WM_ERASEBKGND if the non-client area is still invalid */
3947 HRGN hrgn
= CreateRectRgn( 0, 0, 0, 0 );
3948 GetUpdateRgn( msg
->hwnd
, hrgn
, TRUE
);
3949 DeleteObject( hrgn
);
3955 /***********************************************************************
3956 * DispatchMessageW (USER32.@) Process a message
3958 * Process the message specified in the structure *_msg_.
3960 * If the lpMsg parameter points to a WM_TIMER message and the
3961 * parameter of the WM_TIMER message is not NULL, the lParam parameter
3962 * points to the function that is called instead of the window
3963 * procedure. The function stored in lParam (timer callback) is protected
3964 * from causing page-faults.
3966 * The message must be valid.
3970 * DispatchMessage() returns the result of the window procedure invoked.
3977 LRESULT WINAPI DECLSPEC_HOTPATCH
DispatchMessageW( const MSG
* msg
)
3981 /* Process timer messages */
3982 if ((msg
->message
== WM_TIMER
) || (msg
->message
== WM_SYSTIMER
))
3988 retval
= CallWindowProcW( (WNDPROC
)msg
->lParam
, msg
->hwnd
,
3989 msg
->message
, msg
->wParam
, GetTickCount() );
3999 if (!msg
->hwnd
) return 0;
4001 SPY_EnterMessage( SPY_DISPATCHMESSAGE
, msg
->hwnd
, msg
->message
,
4002 msg
->wParam
, msg
->lParam
);
4004 if (!WINPROC_call_window( msg
->hwnd
, msg
->message
, msg
->wParam
, msg
->lParam
,
4005 &retval
, TRUE
, WMCHAR_MAP_DISPATCHMESSAGE
))
4007 if (!IsWindow( msg
->hwnd
)) SetLastError( ERROR_INVALID_WINDOW_HANDLE
);
4008 else SetLastError( ERROR_MESSAGE_SYNC_ONLY
);
4012 SPY_ExitMessage( SPY_RESULT_OK
, msg
->hwnd
, msg
->message
, retval
,
4013 msg
->wParam
, msg
->lParam
);
4015 if (msg
->message
== WM_PAINT
)
4017 /* send a WM_NCPAINT and WM_ERASEBKGND if the non-client area is still invalid */
4018 HRGN hrgn
= CreateRectRgn( 0, 0, 0, 0 );
4019 GetUpdateRgn( msg
->hwnd
, hrgn
, TRUE
);
4020 DeleteObject( hrgn
);
4026 /***********************************************************************
4027 * GetMessagePos (USER.119)
4028 * GetMessagePos (USER32.@)
4030 * The GetMessagePos() function returns a long value representing a
4031 * cursor position, in screen coordinates, when the last message
4032 * retrieved by the GetMessage() function occurs. The x-coordinate is
4033 * in the low-order word of the return value, the y-coordinate is in
4034 * the high-order word. The application can use the MAKEPOINT()
4035 * macro to obtain a POINT structure from the return value.
4037 * For the current cursor position, use GetCursorPos().
4041 * Cursor position of last message on success, zero on failure.
4048 DWORD WINAPI
GetMessagePos(void)
4050 return get_user_thread_info()->GetMessagePosVal
;
4054 /***********************************************************************
4055 * GetMessageTime (USER.120)
4056 * GetMessageTime (USER32.@)
4058 * GetMessageTime() returns the message time for the last message
4059 * retrieved by the function. The time is measured in milliseconds with
4060 * the same offset as GetTickCount().
4062 * Since the tick count wraps, this is only useful for moderately short
4063 * relative time comparisons.
4067 * Time of last message on success, zero on failure.
4069 LONG WINAPI
GetMessageTime(void)
4071 return get_user_thread_info()->GetMessageTimeVal
;
4075 /***********************************************************************
4076 * GetMessageExtraInfo (USER.288)
4077 * GetMessageExtraInfo (USER32.@)
4079 LPARAM WINAPI
GetMessageExtraInfo(void)
4081 return get_user_thread_info()->GetMessageExtraInfoVal
;
4085 /***********************************************************************
4086 * SetMessageExtraInfo (USER32.@)
4088 LPARAM WINAPI
SetMessageExtraInfo(LPARAM lParam
)
4090 struct user_thread_info
*thread_info
= get_user_thread_info();
4091 LONG old_value
= thread_info
->GetMessageExtraInfoVal
;
4092 thread_info
->GetMessageExtraInfoVal
= lParam
;
4097 /***********************************************************************
4098 * GetCurrentInputMessageSource (USER32.@)
4100 BOOL WINAPI
GetCurrentInputMessageSource( INPUT_MESSAGE_SOURCE
*source
)
4102 *source
= get_user_thread_info()->msg_source
;
4107 /***********************************************************************
4108 * WaitMessage (USER.112) Suspend thread pending messages
4109 * WaitMessage (USER32.@) Suspend thread pending messages
4111 * WaitMessage() suspends a thread until events appear in the thread's
4114 BOOL WINAPI
WaitMessage(void)
4116 return (MsgWaitForMultipleObjectsEx( 0, NULL
, INFINITE
, QS_ALLINPUT
, 0 ) != WAIT_FAILED
);
4120 /***********************************************************************
4121 * MsgWaitForMultipleObjectsEx (USER32.@)
4123 DWORD WINAPI
MsgWaitForMultipleObjectsEx( DWORD count
, const HANDLE
*pHandles
,
4124 DWORD timeout
, DWORD mask
, DWORD flags
)
4126 HANDLE handles
[MAXIMUM_WAIT_OBJECTS
];
4129 if (count
> MAXIMUM_WAIT_OBJECTS
-1)
4131 SetLastError( ERROR_INVALID_PARAMETER
);
4135 /* add the queue to the handle list */
4136 for (i
= 0; i
< count
; i
++) handles
[i
] = pHandles
[i
];
4137 handles
[count
] = get_server_queue_handle();
4139 return wait_objects( count
+1, handles
, timeout
,
4140 (flags
& MWMO_INPUTAVAILABLE
) ? mask
: 0, mask
, flags
);
4144 /***********************************************************************
4145 * MsgWaitForMultipleObjects (USER32.@)
4147 DWORD WINAPI
MsgWaitForMultipleObjects( DWORD count
, const HANDLE
*handles
,
4148 BOOL wait_all
, DWORD timeout
, DWORD mask
)
4150 return MsgWaitForMultipleObjectsEx( count
, handles
, timeout
, mask
,
4151 wait_all
? MWMO_WAITALL
: 0 );
4155 /***********************************************************************
4156 * WaitForInputIdle (USER32.@)
4158 DWORD WINAPI
WaitForInputIdle( HANDLE hProcess
, DWORD dwTimeOut
)
4160 DWORD start_time
, elapsed
, ret
;
4163 handles
[0] = hProcess
;
4164 SERVER_START_REQ( get_process_idle_event
)
4166 req
->handle
= wine_server_obj_handle( hProcess
);
4167 wine_server_call_err( req
);
4168 handles
[1] = wine_server_ptr_handle( reply
->event
);
4171 if (!handles
[1]) return WAIT_FAILED
; /* no event to wait on */
4173 start_time
= GetTickCount();
4176 TRACE("waiting for %p\n", handles
[1] );
4179 ret
= MsgWaitForMultipleObjects ( 2, handles
, FALSE
, dwTimeOut
- elapsed
, QS_SENDMESSAGE
);
4184 case WAIT_OBJECT_0
+2:
4185 process_sent_messages();
4189 TRACE("timeout or error\n");
4192 TRACE("finished\n");
4195 if (dwTimeOut
!= INFINITE
)
4197 elapsed
= GetTickCount() - start_time
;
4198 if (elapsed
> dwTimeOut
)
4204 return WAIT_TIMEOUT
;
4208 /***********************************************************************
4209 * RegisterWindowMessageA (USER32.@)
4210 * RegisterWindowMessage (USER.118)
4212 UINT WINAPI
RegisterWindowMessageA( LPCSTR str
)
4214 UINT ret
= GlobalAddAtomA(str
);
4215 TRACE("%s, ret=%x\n", str
, ret
);
4220 /***********************************************************************
4221 * RegisterWindowMessageW (USER32.@)
4223 UINT WINAPI
RegisterWindowMessageW( LPCWSTR str
)
4225 UINT ret
= GlobalAddAtomW(str
);
4226 TRACE("%s ret=%x\n", debugstr_w(str
), ret
);
4230 typedef struct BroadcastParm
4241 static BOOL CALLBACK
bcast_childwindow( HWND hw
, LPARAM lp
)
4243 BroadcastParm
*parm
= (BroadcastParm
*)lp
;
4244 DWORD_PTR retval
= 0;
4247 if (parm
->flags
& BSF_IGNORECURRENTTASK
&& WIN_IsCurrentProcess(hw
))
4249 TRACE("Not telling myself %p\n", hw
);
4253 /* I don't know 100% for sure if this is what Windows does, but it fits the tests */
4254 if (parm
->flags
& BSF_QUERY
)
4256 TRACE("Telling window %p using SendMessageTimeout\n", hw
);
4258 /* Not tested for conflicting flags */
4259 if (parm
->flags
& BSF_FORCEIFHUNG
|| parm
->flags
& BSF_NOHANG
)
4260 lresult
= SendMessageTimeoutW( hw
, parm
->msg
, parm
->wp
, parm
->lp
, SMTO_ABORTIFHUNG
, 2000, &retval
);
4261 else if (parm
->flags
& BSF_NOTIMEOUTIFNOTHUNG
)
4262 lresult
= SendMessageTimeoutW( hw
, parm
->msg
, parm
->wp
, parm
->lp
, SMTO_NOTIMEOUTIFNOTHUNG
, 2000, &retval
);
4264 lresult
= SendMessageTimeoutW( hw
, parm
->msg
, parm
->wp
, parm
->lp
, SMTO_NORMAL
, 2000, &retval
);
4266 if (!lresult
&& GetLastError() == ERROR_TIMEOUT
)
4268 WARN("Timed out!\n");
4269 if (!(parm
->flags
& BSF_FORCEIFHUNG
))
4272 if (retval
== BROADCAST_QUERY_DENY
)
4278 parm
->success
= FALSE
;
4281 else if (parm
->flags
& BSF_POSTMESSAGE
)
4283 TRACE("Telling window %p using PostMessage\n", hw
);
4284 PostMessageW( hw
, parm
->msg
, parm
->wp
, parm
->lp
);
4288 TRACE("Telling window %p using SendNotifyMessage\n", hw
);
4289 SendNotifyMessageW( hw
, parm
->msg
, parm
->wp
, parm
->lp
);
4295 static BOOL CALLBACK
bcast_desktop( LPWSTR desktop
, LPARAM lp
)
4299 BroadcastParm
*parm
= (BroadcastParm
*)lp
;
4301 TRACE("desktop: %s\n", debugstr_w( desktop
));
4303 hdesktop
= open_winstation_desktop( parm
->winsta
, desktop
, 0, FALSE
, DESKTOP_ENUMERATE
|DESKTOP_WRITEOBJECTS
|STANDARD_RIGHTS_WRITE
);
4306 FIXME("Could not open desktop %s\n", debugstr_w(desktop
));
4310 ret
= EnumDesktopWindows( hdesktop
, bcast_childwindow
, lp
);
4311 CloseDesktop(hdesktop
);
4312 TRACE("-->%d\n", ret
);
4313 return parm
->success
;
4316 static BOOL CALLBACK
bcast_winsta( LPWSTR winsta
, LPARAM lp
)
4319 HWINSTA hwinsta
= OpenWindowStationW( winsta
, FALSE
, WINSTA_ENUMDESKTOPS
);
4320 TRACE("hwinsta: %p/%s/%08x\n", hwinsta
, debugstr_w( winsta
), GetLastError());
4323 ((BroadcastParm
*)lp
)->winsta
= hwinsta
;
4324 ret
= EnumDesktopsW( hwinsta
, bcast_desktop
, lp
);
4325 CloseWindowStation( hwinsta
);
4326 TRACE("-->%d\n", ret
);
4330 /***********************************************************************
4331 * BroadcastSystemMessageA (USER32.@)
4332 * BroadcastSystemMessage (USER32.@)
4334 LONG WINAPI
BroadcastSystemMessageA( DWORD flags
, LPDWORD recipients
, UINT msg
, WPARAM wp
, LPARAM lp
)
4336 return BroadcastSystemMessageExA( flags
, recipients
, msg
, wp
, lp
, NULL
);
4340 /***********************************************************************
4341 * BroadcastSystemMessageW (USER32.@)
4343 LONG WINAPI
BroadcastSystemMessageW( DWORD flags
, LPDWORD recipients
, UINT msg
, WPARAM wp
, LPARAM lp
)
4345 return BroadcastSystemMessageExW( flags
, recipients
, msg
, wp
, lp
, NULL
);
4348 /***********************************************************************
4349 * BroadcastSystemMessageExA (USER32.@)
4351 LONG WINAPI
BroadcastSystemMessageExA( DWORD flags
, LPDWORD recipients
, UINT msg
, WPARAM wp
, LPARAM lp
, PBSMINFO pinfo
)
4353 map_wparam_AtoW( msg
, &wp
, WMCHAR_MAP_NOMAPPING
);
4354 return BroadcastSystemMessageExW( flags
, recipients
, msg
, wp
, lp
, NULL
);
4358 /***********************************************************************
4359 * BroadcastSystemMessageExW (USER32.@)
4361 LONG WINAPI
BroadcastSystemMessageExW( DWORD flags
, LPDWORD recipients
, UINT msg
, WPARAM wp
, LPARAM lp
, PBSMINFO pinfo
)
4364 DWORD recips
= BSM_ALLCOMPONENTS
;
4366 static const DWORD all_flags
= ( BSF_QUERY
| BSF_IGNORECURRENTTASK
| BSF_FLUSHDISK
| BSF_NOHANG
4367 | BSF_POSTMESSAGE
| BSF_FORCEIFHUNG
| BSF_NOTIMEOUTIFNOTHUNG
4368 | BSF_ALLOWSFW
| BSF_SENDNOTIFYMESSAGE
| BSF_RETURNHDESK
| BSF_LUID
);
4370 TRACE("Flags: %08x, recipients: %p(0x%x), msg: %04x, wparam: %08lx, lparam: %08lx\n", flags
, recipients
,
4371 (recipients
? *recipients
: recips
), msg
, wp
, lp
);
4373 if (flags
& ~all_flags
)
4375 SetLastError(ERROR_INVALID_PARAMETER
);
4380 recipients
= &recips
;
4382 if ( pinfo
&& flags
& BSF_QUERY
)
4383 FIXME("Not returning PBSMINFO information yet\n");
4386 parm
.recipients
= recipients
;
4390 parm
.success
= TRUE
;
4392 if (*recipients
& BSM_ALLDESKTOPS
|| *recipients
== BSM_ALLCOMPONENTS
)
4393 ret
= EnumWindowStationsW(bcast_winsta
, (LONG_PTR
)&parm
);
4394 else if (*recipients
& BSM_APPLICATIONS
)
4396 EnumWindows(bcast_childwindow
, (LONG_PTR
)&parm
);
4400 FIXME("Recipients %08x not supported!\n", *recipients
);
4405 /***********************************************************************
4406 * SetMessageQueue (USER32.@)
4408 BOOL WINAPI
SetMessageQueue( INT size
)
4410 /* now obsolete the message queue will be expanded dynamically as necessary */
4415 /***********************************************************************
4416 * MessageBeep (USER32.@)
4418 BOOL WINAPI
MessageBeep( UINT i
)
4421 SystemParametersInfoA( SPI_GETBEEP
, 0, &active
, FALSE
);
4422 if (active
) USER_Driver
->pBeep();
4427 /***********************************************************************
4428 * SetCoalescableTimer (USER32.@)
4430 UINT_PTR WINAPI
SetCoalescableTimer( HWND hwnd
, UINT_PTR id
, UINT timeout
, TIMERPROC proc
, ULONG tolerance
)
4433 WNDPROC winproc
= 0;
4435 if (proc
) winproc
= WINPROC_AllocProc( (WNDPROC
)proc
, FALSE
);
4437 timeout
= min( max( USER_TIMER_MINIMUM
, timeout
), USER_TIMER_MAXIMUM
);
4439 SERVER_START_REQ( set_win_timer
)
4441 req
->win
= wine_server_user_handle( hwnd
);
4442 req
->msg
= WM_TIMER
;
4444 req
->rate
= timeout
;
4445 req
->lparam
= (ULONG_PTR
)winproc
;
4446 if (!wine_server_call_err( req
))
4449 if (!ret
) ret
= TRUE
;
4455 TRACE("Added %p %lx %p timeout %d\n", hwnd
, id
, winproc
, timeout
);
4460 /******************************************************************
4461 * SetTimer (USER32.@)
4463 UINT_PTR WINAPI
SetTimer( HWND hwnd
, UINT_PTR id
, UINT timeout
, TIMERPROC proc
)
4465 return SetCoalescableTimer( hwnd
, id
, timeout
, proc
, TIMERV_DEFAULT_COALESCING
);
4469 /***********************************************************************
4470 * SetSystemTimer (USER32.@)
4472 UINT_PTR WINAPI
SetSystemTimer( HWND hwnd
, UINT_PTR id
, UINT timeout
, TIMERPROC proc
)
4475 WNDPROC winproc
= 0;
4477 if (proc
) winproc
= WINPROC_AllocProc( (WNDPROC
)proc
, FALSE
);
4479 timeout
= min( max( USER_TIMER_MINIMUM
, timeout
), USER_TIMER_MAXIMUM
);
4481 SERVER_START_REQ( set_win_timer
)
4483 req
->win
= wine_server_user_handle( hwnd
);
4484 req
->msg
= WM_SYSTIMER
;
4486 req
->rate
= timeout
;
4487 req
->lparam
= (ULONG_PTR
)winproc
;
4488 if (!wine_server_call_err( req
))
4491 if (!ret
) ret
= TRUE
;
4497 TRACE("Added %p %lx %p timeout %d\n", hwnd
, id
, winproc
, timeout
);
4502 /***********************************************************************
4503 * KillTimer (USER32.@)
4505 BOOL WINAPI
KillTimer( HWND hwnd
, UINT_PTR id
)
4509 SERVER_START_REQ( kill_win_timer
)
4511 req
->win
= wine_server_user_handle( hwnd
);
4512 req
->msg
= WM_TIMER
;
4514 ret
= !wine_server_call_err( req
);
4521 /***********************************************************************
4522 * KillSystemTimer (USER32.@)
4524 BOOL WINAPI
KillSystemTimer( HWND hwnd
, UINT_PTR id
)
4528 SERVER_START_REQ( kill_win_timer
)
4530 req
->win
= wine_server_user_handle( hwnd
);
4531 req
->msg
= WM_SYSTIMER
;
4533 ret
= !wine_server_call_err( req
);
4540 /**********************************************************************
4541 * IsGUIThread (USER32.@)
4543 BOOL WINAPI
IsGUIThread( BOOL convert
)
4545 FIXME( "%u: stub\n", convert
);
4550 /**********************************************************************
4551 * GetGUIThreadInfo (USER32.@)
4553 BOOL WINAPI
GetGUIThreadInfo( DWORD id
, GUITHREADINFO
*info
)
4557 if (info
->cbSize
!= sizeof(*info
))
4559 SetLastError( ERROR_INVALID_PARAMETER
);
4563 SERVER_START_REQ( get_thread_input
)
4566 if ((ret
= !wine_server_call_err( req
)))
4569 info
->hwndActive
= wine_server_ptr_handle( reply
->active
);
4570 info
->hwndFocus
= wine_server_ptr_handle( reply
->focus
);
4571 info
->hwndCapture
= wine_server_ptr_handle( reply
->capture
);
4572 info
->hwndMenuOwner
= wine_server_ptr_handle( reply
->menu_owner
);
4573 info
->hwndMoveSize
= wine_server_ptr_handle( reply
->move_size
);
4574 info
->hwndCaret
= wine_server_ptr_handle( reply
->caret
);
4575 info
->rcCaret
.left
= reply
->rect
.left
;
4576 info
->rcCaret
.top
= reply
->rect
.top
;
4577 info
->rcCaret
.right
= reply
->rect
.right
;
4578 info
->rcCaret
.bottom
= reply
->rect
.bottom
;
4579 if (reply
->menu_owner
) info
->flags
|= GUI_INMENUMODE
;
4580 if (reply
->move_size
) info
->flags
|= GUI_INMOVESIZE
;
4581 if (reply
->caret
) info
->flags
|= GUI_CARETBLINKING
;
4589 /******************************************************************
4590 * IsHungAppWindow (USER32.@)
4593 BOOL WINAPI
IsHungAppWindow( HWND hWnd
)
4597 SERVER_START_REQ( is_window_hung
)
4599 req
->win
= wine_server_user_handle( hWnd
);
4600 ret
= !wine_server_call_err( req
) && reply
->is_hung
;
4606 /******************************************************************
4607 * ChangeWindowMessageFilter (USER32.@)
4609 BOOL WINAPI
ChangeWindowMessageFilter( UINT message
, DWORD flag
)
4611 FIXME( "%x %08x\n", message
, flag
);
4615 /******************************************************************
4616 * ChangeWindowMessageFilterEx (USER32.@)
4618 BOOL WINAPI
ChangeWindowMessageFilterEx( HWND hwnd
, UINT message
, DWORD action
, CHANGEFILTERSTRUCT
*changefilter
)
4620 FIXME( "%p %x %d %p\n", hwnd
, message
, action
, changefilter
);