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
23 #include "wine/port.h"
28 #define NONAMELESSUNION
29 #define NONAMELESSSTRUCT
31 #define WIN32_NO_STATUS
42 #include "wine/unicode.h"
43 #include "wine/server.h"
44 #include "user_private.h"
47 #include "wine/debug.h"
48 #include "wine/exception.h"
50 WINE_DEFAULT_DEBUG_CHANNEL(msg
);
51 WINE_DECLARE_DEBUG_CHANNEL(relay
);
52 WINE_DECLARE_DEBUG_CHANNEL(key
);
54 #define WM_NCMOUSEFIRST WM_NCMOUSEMOVE
55 #define WM_NCMOUSELAST (WM_NCMOUSEFIRST+(WM_MOUSELAST-WM_MOUSEFIRST))
57 #define MAX_PACK_COUNT 4
59 /* the various structures that can be sent in messages, in platform-independent layout */
60 struct packed_CREATESTRUCTW
62 ULONGLONG lpCreateParams
;
66 user_handle_t hwndParent
;
79 struct packed_DRAWITEMSTRUCT
86 user_handle_t hwndItem
;
94 struct packed_MEASUREITEMSTRUCT
104 struct packed_DELETEITEMSTRUCT
109 user_handle_t hwndItem
;
114 struct packed_COMPAREITEMSTRUCT
118 user_handle_t hwndItem
;
128 struct packed_WINDOWPOS
132 user_handle_t hwndInsertAfter
;
142 struct packed_COPYDATASTRUCT
149 struct packed_HELPINFO
154 user_handle_t hItemHandle
;
156 ULONGLONG dwContextId
;
160 struct packed_NCCALCSIZE_PARAMS
166 user_handle_t hwndInsertAfter
;
188 struct packed_MDINEXTMENU
190 user_handle_t hmenuIn
;
192 user_handle_t hmenuNext
;
194 user_handle_t hwndNext
;
198 struct packed_MDICREATESTRUCTW
211 struct packed_hook_extra_info
213 user_handle_t handle
;
218 /* the structures are unpacked on top of the packed ones, so make sure they fit */
219 C_ASSERT( sizeof(struct packed_CREATESTRUCTW
) >= sizeof(CREATESTRUCTW
) );
220 C_ASSERT( sizeof(struct packed_DRAWITEMSTRUCT
) >= sizeof(DRAWITEMSTRUCT
) );
221 C_ASSERT( sizeof(struct packed_MEASUREITEMSTRUCT
) >= sizeof(MEASUREITEMSTRUCT
) );
222 C_ASSERT( sizeof(struct packed_DELETEITEMSTRUCT
) >= sizeof(DELETEITEMSTRUCT
) );
223 C_ASSERT( sizeof(struct packed_COMPAREITEMSTRUCT
) >= sizeof(COMPAREITEMSTRUCT
) );
224 C_ASSERT( sizeof(struct packed_WINDOWPOS
) >= sizeof(WINDOWPOS
) );
225 C_ASSERT( sizeof(struct packed_COPYDATASTRUCT
) >= sizeof(COPYDATASTRUCT
) );
226 C_ASSERT( sizeof(struct packed_HELPINFO
) >= sizeof(HELPINFO
) );
227 C_ASSERT( sizeof(struct packed_NCCALCSIZE_PARAMS
) >= sizeof(NCCALCSIZE_PARAMS
) + sizeof(WINDOWPOS
) );
228 C_ASSERT( sizeof(struct packed_MSG
) >= sizeof(MSG
) );
229 C_ASSERT( sizeof(struct packed_MDINEXTMENU
) >= sizeof(MDINEXTMENU
) );
230 C_ASSERT( sizeof(struct packed_MDICREATESTRUCTW
) >= sizeof(MDICREATESTRUCTW
) );
231 C_ASSERT( sizeof(struct packed_hook_extra_info
) >= sizeof(struct hook_extra_info
) );
235 struct packed_CREATESTRUCTW cs
;
236 struct packed_DRAWITEMSTRUCT dis
;
237 struct packed_MEASUREITEMSTRUCT mis
;
238 struct packed_DELETEITEMSTRUCT dls
;
239 struct packed_COMPAREITEMSTRUCT cis
;
240 struct packed_WINDOWPOS wp
;
241 struct packed_COPYDATASTRUCT cds
;
242 struct packed_HELPINFO hi
;
243 struct packed_NCCALCSIZE_PARAMS ncp
;
244 struct packed_MSG msg
;
245 struct packed_MDINEXTMENU mnm
;
246 struct packed_MDICREATESTRUCTW mcs
;
247 struct packed_hook_extra_info hook
;
250 /* description of the data fields that need to be packed along with a sent message */
251 struct packed_message
253 union packed_structs ps
;
255 const void *data
[MAX_PACK_COUNT
];
256 size_t size
[MAX_PACK_COUNT
];
259 /* info about the message currently being received by the current thread */
260 struct received_message_info
262 enum message_type type
;
264 UINT flags
; /* InSendMessageEx return flags */
267 /* structure to group all parameters for sent messages of the various kinds */
268 struct send_message_info
270 enum message_type type
;
276 UINT flags
; /* flags for SendMessageTimeout */
277 UINT timeout
; /* timeout for SendMessageTimeout */
278 SENDASYNCPROC callback
; /* callback function for SendMessageCallback */
279 ULONG_PTR data
; /* callback data */
280 enum wm_char_mapping wm_char
;
284 /* Message class descriptor */
285 static const WCHAR messageW
[] = {'M','e','s','s','a','g','e',0};
287 const struct builtin_class_descr MESSAGE_builtin_class
=
291 WINPROC_MESSAGE
, /* proc */
293 IDC_ARROW
, /* cursor */
299 /* flag for messages that contain pointers */
300 /* 32 messages per entry, messages 0..31 map to bits 0..31 */
302 #define SET(msg) (1 << ((msg) & 31))
304 static const unsigned int message_pointer_flags
[] =
307 SET(WM_CREATE
) | SET(WM_SETTEXT
) | SET(WM_GETTEXT
) |
308 SET(WM_WININICHANGE
) | SET(WM_DEVMODECHANGE
),
310 SET(WM_GETMINMAXINFO
) | SET(WM_DRAWITEM
) | SET(WM_MEASUREITEM
) | SET(WM_DELETEITEM
) |
313 SET(WM_WINDOWPOSCHANGING
) | SET(WM_WINDOWPOSCHANGED
) | SET(WM_COPYDATA
) |
314 SET(WM_NOTIFY
) | SET(WM_HELP
),
316 SET(WM_STYLECHANGING
) | SET(WM_STYLECHANGED
),
318 SET(WM_NCCREATE
) | SET(WM_NCCALCSIZE
) | SET(WM_GETDLGCODE
),
320 SET(EM_GETSEL
) | SET(EM_GETRECT
) | SET(EM_SETRECT
) | SET(EM_SETRECTNP
),
322 SET(EM_REPLACESEL
) | SET(EM_GETLINE
) | SET(EM_SETTABSTOPS
),
324 SET(SBM_GETRANGE
) | SET(SBM_SETSCROLLINFO
) | SET(SBM_GETSCROLLINFO
) | SET(SBM_GETSCROLLBARINFO
),
330 SET(CB_GETEDITSEL
) | SET(CB_ADDSTRING
) | SET(CB_DIR
) | SET(CB_GETLBTEXT
) |
331 SET(CB_INSERTSTRING
) | SET(CB_FINDSTRING
) | SET(CB_SELECTSTRING
) |
332 SET(CB_GETDROPPEDCONTROLRECT
) | SET(CB_FINDSTRINGEXACT
),
336 SET(LB_ADDSTRING
) | SET(LB_INSERTSTRING
) | SET(LB_GETTEXT
) | SET(LB_SELECTSTRING
) |
337 SET(LB_DIR
) | SET(LB_FINDSTRING
) |
338 SET(LB_GETSELITEMS
) | SET(LB_SETTABSTOPS
) | SET(LB_ADDFILE
) | SET(LB_GETITEMRECT
),
340 SET(LB_FINDSTRINGEXACT
),
346 SET(WM_NEXTMENU
) | SET(WM_SIZING
) | SET(WM_MOVING
) | SET(WM_DEVICECHANGE
),
348 SET(WM_MDICREATE
) | SET(WM_MDIGETACTIVE
) | SET(WM_DROPOBJECT
) |
349 SET(WM_QUERYDROPOBJECT
) | SET(WM_DRAGLOOP
) | SET(WM_DRAGSELECT
) | SET(WM_DRAGMOVE
),
363 SET(WM_ASKCBFORMATNAME
)
366 /* flags for messages that contain Unicode strings */
367 static const unsigned int message_unicode_flags
[] =
370 SET(WM_CREATE
) | SET(WM_SETTEXT
) | SET(WM_GETTEXT
) | SET(WM_GETTEXTLENGTH
) |
371 SET(WM_WININICHANGE
) | SET(WM_DEVMODECHANGE
),
383 SET(EM_REPLACESEL
) | SET(EM_GETLINE
) | SET(EM_SETPASSWORDCHAR
),
387 SET(WM_CHAR
) | SET(WM_DEADCHAR
) | SET(WM_SYSCHAR
) | SET(WM_SYSDEADCHAR
),
391 SET(CB_ADDSTRING
) | SET(CB_DIR
) | SET(CB_GETLBTEXT
) | SET(CB_GETLBTEXTLEN
) |
392 SET(CB_INSERTSTRING
) | SET(CB_FINDSTRING
) | SET(CB_SELECTSTRING
) | SET(CB_FINDSTRINGEXACT
),
396 SET(LB_ADDSTRING
) | SET(LB_INSERTSTRING
) | SET(LB_GETTEXT
) | SET(LB_GETTEXTLEN
) |
397 SET(LB_SELECTSTRING
) | SET(LB_DIR
) | SET(LB_FINDSTRING
) | SET(LB_ADDFILE
),
399 SET(LB_FINDSTRINGEXACT
),
421 SET(WM_PAINTCLIPBOARD
) | SET(WM_SIZECLIPBOARD
) | SET(WM_ASKCBFORMATNAME
)
424 /* check whether a given message type includes pointers */
425 static inline int is_pointer_message( UINT message
)
427 if (message
>= 8*sizeof(message_pointer_flags
)) return FALSE
;
428 return (message_pointer_flags
[message
/ 32] & SET(message
)) != 0;
431 /* check whether a given message type contains Unicode (or ASCII) chars */
432 static inline int is_unicode_message( UINT message
)
434 if (message
>= 8*sizeof(message_unicode_flags
)) return FALSE
;
435 return (message_unicode_flags
[message
/ 32] & SET(message
)) != 0;
440 /* add a data field to a packed message */
441 static inline void push_data( struct packed_message
*data
, const void *ptr
, size_t size
)
443 data
->data
[data
->count
] = ptr
;
444 data
->size
[data
->count
] = size
;
448 /* add a string to a packed message */
449 static inline void push_string( struct packed_message
*data
, LPCWSTR str
)
451 push_data( data
, str
, (strlenW(str
) + 1) * sizeof(WCHAR
) );
454 /* make sure that the buffer contains a valid null-terminated Unicode string */
455 static inline BOOL
check_string( LPCWSTR str
, size_t size
)
457 for (size
/= sizeof(WCHAR
); size
; size
--, str
++)
458 if (!*str
) return TRUE
;
462 /* pack a pointer into a 32/64 portable format */
463 static inline ULONGLONG
pack_ptr( const void *ptr
)
465 return (ULONG_PTR
)ptr
;
468 /* unpack a potentially 64-bit pointer, returning 0 when truncated */
469 static inline void *unpack_ptr( ULONGLONG ptr64
)
471 if ((ULONG_PTR
)ptr64
!= ptr64
) return 0;
472 return (void *)(ULONG_PTR
)ptr64
;
475 /* make sure that there is space for 'size' bytes in buffer, growing it if needed */
476 static inline void *get_buffer_space( void **buffer
, size_t size
)
482 if (!(ret
= HeapReAlloc( GetProcessHeap(), 0, *buffer
, size
)))
483 HeapFree( GetProcessHeap(), 0, *buffer
);
485 else ret
= HeapAlloc( GetProcessHeap(), 0, size
);
491 /* check whether a combobox expects strings or ids in CB_ADDSTRING/CB_INSERTSTRING */
492 static inline BOOL
combobox_has_strings( HWND hwnd
)
494 DWORD style
= GetWindowLongA( hwnd
, GWL_STYLE
);
495 return (!(style
& (CBS_OWNERDRAWFIXED
| CBS_OWNERDRAWVARIABLE
)) || (style
& CBS_HASSTRINGS
));
498 /* check whether a listbox expects strings or ids in LB_ADDSTRING/LB_INSERTSTRING */
499 static inline BOOL
listbox_has_strings( HWND hwnd
)
501 DWORD style
= GetWindowLongA( hwnd
, GWL_STYLE
);
502 return (!(style
& (LBS_OWNERDRAWFIXED
| LBS_OWNERDRAWVARIABLE
)) || (style
& LBS_HASSTRINGS
));
505 /* check whether message is in the range of keyboard messages */
506 static inline BOOL
is_keyboard_message( UINT message
)
508 return (message
>= WM_KEYFIRST
&& message
<= WM_KEYLAST
);
511 /* check whether message is in the range of mouse messages */
512 static inline BOOL
is_mouse_message( UINT message
)
514 return ((message
>= WM_NCMOUSEFIRST
&& message
<= WM_NCMOUSELAST
) ||
515 (message
>= WM_MOUSEFIRST
&& message
<= WM_MOUSELAST
));
518 /* check whether message matches the specified hwnd filter */
519 static inline BOOL
check_hwnd_filter( const MSG
*msg
, HWND hwnd_filter
)
521 if (!hwnd_filter
|| hwnd_filter
== GetDesktopWindow()) return TRUE
;
522 return (msg
->hwnd
== hwnd_filter
|| IsChild( hwnd_filter
, msg
->hwnd
));
525 /* check for pending WM_CHAR message with DBCS trailing byte */
526 static inline BOOL
get_pending_wmchar( MSG
*msg
, UINT first
, UINT last
, BOOL remove
)
528 struct wm_char_mapping_data
*data
= get_user_thread_info()->wmchar_data
;
530 if (!data
|| !data
->get_msg
.message
) return FALSE
;
531 if ((first
|| last
) && (first
> WM_CHAR
|| last
< WM_CHAR
)) return FALSE
;
532 if (!msg
) return FALSE
;
533 *msg
= data
->get_msg
;
534 if (remove
) data
->get_msg
.message
= 0;
539 /***********************************************************************
542 * Window procedure for "Message" windows (HWND_MESSAGE parent).
544 LRESULT WINAPI
MessageWndProc( HWND hwnd
, UINT message
, WPARAM wParam
, LPARAM lParam
)
546 if (message
== WM_NCCREATE
) return TRUE
;
547 return 0; /* all other messages are ignored */
551 /***********************************************************************
552 * broadcast_message_callback
554 * Helper callback for broadcasting messages.
556 static BOOL CALLBACK
broadcast_message_callback( HWND hwnd
, LPARAM lparam
)
558 struct send_message_info
*info
= (struct send_message_info
*)lparam
;
559 if (!(GetWindowLongW( hwnd
, GWL_STYLE
) & (WS_POPUP
|WS_CAPTION
))) return TRUE
;
563 SendMessageTimeoutW( hwnd
, info
->msg
, info
->wparam
, info
->lparam
,
564 info
->flags
, info
->timeout
, NULL
);
567 SendMessageTimeoutA( hwnd
, info
->msg
, info
->wparam
, info
->lparam
,
568 info
->flags
, info
->timeout
, NULL
);
571 SendNotifyMessageW( hwnd
, info
->msg
, info
->wparam
, info
->lparam
);
574 SendMessageCallbackW( hwnd
, info
->msg
, info
->wparam
, info
->lparam
,
575 info
->callback
, info
->data
);
578 PostMessageW( hwnd
, info
->msg
, info
->wparam
, info
->lparam
);
581 ERR( "bad type %d\n", info
->type
);
588 /***********************************************************************
591 * Convert the wparam of an ASCII message to Unicode.
593 BOOL
map_wparam_AtoW( UINT message
, WPARAM
*wparam
, enum wm_char_mapping mapping
)
602 /* WM_CHAR is magic: a DBCS char can be sent/posted as two consecutive WM_CHAR
603 * messages, in which case the first char is stored, and the conversion
604 * to Unicode only takes place once the second char is sent/posted.
606 if (mapping
!= WMCHAR_MAP_NOMAPPING
)
608 struct wm_char_mapping_data
*data
= get_user_thread_info()->wmchar_data
;
609 BYTE low
= LOBYTE(*wparam
);
614 ch
[1] = HIBYTE(*wparam
);
615 RtlMultiByteToUnicodeN( wch
, sizeof(wch
), NULL
, ch
, 2 );
616 TRACE( "map %02x,%02x -> %04x mapping %u\n", (BYTE
)ch
[0], (BYTE
)ch
[1], wch
[0], mapping
);
617 if (data
) data
->lead_byte
[mapping
] = 0;
619 else if (data
&& data
->lead_byte
[mapping
])
621 ch
[0] = data
->lead_byte
[mapping
];
623 RtlMultiByteToUnicodeN( wch
, sizeof(wch
), NULL
, ch
, 2 );
624 TRACE( "map stored %02x,%02x -> %04x mapping %u\n", (BYTE
)ch
[0], (BYTE
)ch
[1], wch
[0], mapping
);
625 data
->lead_byte
[mapping
] = 0;
627 else if (!IsDBCSLeadByte( low
))
630 RtlMultiByteToUnicodeN( wch
, sizeof(wch
), NULL
, ch
, 1 );
631 TRACE( "map %02x -> %04x\n", (BYTE
)ch
[0], wch
[0] );
632 if (data
) data
->lead_byte
[mapping
] = 0;
634 else /* store it and wait for trail byte */
638 if (!(data
= HeapAlloc( GetProcessHeap(), HEAP_ZERO_MEMORY
, sizeof(*data
) )))
640 get_user_thread_info()->wmchar_data
= data
;
642 TRACE( "storing lead byte %02x mapping %u\n", low
, mapping
);
643 data
->lead_byte
[mapping
] = low
;
646 *wparam
= MAKEWPARAM(wch
[0], wch
[1]);
649 /* else fall through */
651 case EM_SETPASSWORDCHAR
:
656 ch
[0] = LOBYTE(*wparam
);
657 ch
[1] = HIBYTE(*wparam
);
658 RtlMultiByteToUnicodeN( wch
, sizeof(wch
), NULL
, ch
, 2 );
659 *wparam
= MAKEWPARAM(wch
[0], wch
[1]);
662 ch
[0] = HIBYTE(*wparam
);
663 ch
[1] = LOBYTE(*wparam
);
664 if (ch
[0]) RtlMultiByteToUnicodeN( wch
, sizeof(wch
[0]), NULL
, ch
, 2 );
665 else RtlMultiByteToUnicodeN( wch
, sizeof(wch
[0]), NULL
, ch
+ 1, 1 );
666 *wparam
= MAKEWPARAM(wch
[0], HIWORD(*wparam
));
673 /***********************************************************************
676 * Convert the wparam of a Unicode message to ASCII.
678 static void map_wparam_WtoA( MSG
*msg
, BOOL remove
)
687 if (!HIWORD(msg
->wParam
))
689 wch
[0] = LOWORD(msg
->wParam
);
691 RtlUnicodeToMultiByteN( (LPSTR
)ch
, 2, &len
, wch
, sizeof(wch
[0]) );
692 if (len
== 2) /* DBCS char */
694 struct wm_char_mapping_data
*data
= get_user_thread_info()->wmchar_data
;
697 if (!(data
= HeapAlloc( GetProcessHeap(), HEAP_ZERO_MEMORY
, sizeof(*data
) ))) return;
698 get_user_thread_info()->wmchar_data
= data
;
702 data
->get_msg
= *msg
;
703 data
->get_msg
.wParam
= ch
[1];
709 /* else fall through */
711 case EM_SETPASSWORDCHAR
:
716 wch
[0] = LOWORD(msg
->wParam
);
717 wch
[1] = HIWORD(msg
->wParam
);
719 RtlUnicodeToMultiByteN( (LPSTR
)ch
, 2, NULL
, wch
, sizeof(wch
) );
720 msg
->wParam
= MAKEWPARAM( ch
[0] | (ch
[1] << 8), 0 );
723 wch
[0] = LOWORD(msg
->wParam
);
725 RtlUnicodeToMultiByteN( (LPSTR
)ch
, 2, &len
, wch
, sizeof(wch
[0]) );
727 msg
->wParam
= MAKEWPARAM( (ch
[0] << 8) | ch
[1], HIWORD(msg
->wParam
) );
729 msg
->wParam
= MAKEWPARAM( ch
[0], HIWORD(msg
->wParam
) );
735 /***********************************************************************
738 * Pack a message for sending to another process.
739 * Return the size of the data we expect in the message reply.
740 * Set data->count to -1 if there is an error.
742 static size_t pack_message( HWND hwnd
, UINT message
, WPARAM wparam
, LPARAM lparam
,
743 struct packed_message
*data
)
751 CREATESTRUCTW
*cs
= (CREATESTRUCTW
*)lparam
;
752 data
->ps
.cs
.lpCreateParams
= pack_ptr( cs
->lpCreateParams
);
753 data
->ps
.cs
.hInstance
= pack_ptr( cs
->hInstance
);
754 data
->ps
.cs
.hMenu
= wine_server_user_handle( cs
->hMenu
);
755 data
->ps
.cs
.hwndParent
= wine_server_user_handle( cs
->hwndParent
);
756 data
->ps
.cs
.cy
= cs
->cy
;
757 data
->ps
.cs
.cx
= cs
->cx
;
758 data
->ps
.cs
.y
= cs
->y
;
759 data
->ps
.cs
.x
= cs
->x
;
760 data
->ps
.cs
.style
= cs
->style
;
761 data
->ps
.cs
.dwExStyle
= cs
->dwExStyle
;
762 data
->ps
.cs
.lpszName
= pack_ptr( cs
->lpszName
);
763 data
->ps
.cs
.lpszClass
= pack_ptr( cs
->lpszClass
);
764 push_data( data
, &data
->ps
.cs
, sizeof(data
->ps
.cs
) );
765 if (!IS_INTRESOURCE(cs
->lpszName
)) push_string( data
, cs
->lpszName
);
766 if (!IS_INTRESOURCE(cs
->lpszClass
)) push_string( data
, cs
->lpszClass
);
767 return sizeof(data
->ps
.cs
);
770 case WM_ASKCBFORMATNAME
:
771 return wparam
* sizeof(WCHAR
);
772 case WM_WININICHANGE
:
773 if (lparam
) push_string(data
, (LPWSTR
)lparam
);
776 case WM_DEVMODECHANGE
:
781 push_string( data
, (LPWSTR
)lparam
);
783 case WM_GETMINMAXINFO
:
784 push_data( data
, (MINMAXINFO
*)lparam
, sizeof(MINMAXINFO
) );
785 return sizeof(MINMAXINFO
);
788 DRAWITEMSTRUCT
*dis
= (DRAWITEMSTRUCT
*)lparam
;
789 data
->ps
.dis
.CtlType
= dis
->CtlType
;
790 data
->ps
.dis
.CtlID
= dis
->CtlID
;
791 data
->ps
.dis
.itemID
= dis
->itemID
;
792 data
->ps
.dis
.itemAction
= dis
->itemAction
;
793 data
->ps
.dis
.itemState
= dis
->itemState
;
794 data
->ps
.dis
.hwndItem
= wine_server_user_handle( dis
->hwndItem
);
795 data
->ps
.dis
.hDC
= wine_server_user_handle( dis
->hDC
); /* FIXME */
796 data
->ps
.dis
.rcItem
= dis
->rcItem
;
797 data
->ps
.dis
.itemData
= dis
->itemData
;
798 push_data( data
, &data
->ps
.dis
, sizeof(data
->ps
.dis
) );
803 MEASUREITEMSTRUCT
*mis
= (MEASUREITEMSTRUCT
*)lparam
;
804 data
->ps
.mis
.CtlType
= mis
->CtlType
;
805 data
->ps
.mis
.CtlID
= mis
->CtlID
;
806 data
->ps
.mis
.itemID
= mis
->itemID
;
807 data
->ps
.mis
.itemWidth
= mis
->itemWidth
;
808 data
->ps
.mis
.itemHeight
= mis
->itemHeight
;
809 data
->ps
.mis
.itemData
= mis
->itemData
;
810 push_data( data
, &data
->ps
.mis
, sizeof(data
->ps
.mis
) );
811 return sizeof(data
->ps
.mis
);
815 DELETEITEMSTRUCT
*dls
= (DELETEITEMSTRUCT
*)lparam
;
816 data
->ps
.dls
.CtlType
= dls
->CtlType
;
817 data
->ps
.dls
.CtlID
= dls
->CtlID
;
818 data
->ps
.dls
.itemID
= dls
->itemID
;
819 data
->ps
.dls
.hwndItem
= wine_server_user_handle( dls
->hwndItem
);
820 data
->ps
.dls
.itemData
= dls
->itemData
;
821 push_data( data
, &data
->ps
.dls
, sizeof(data
->ps
.dls
) );
826 COMPAREITEMSTRUCT
*cis
= (COMPAREITEMSTRUCT
*)lparam
;
827 data
->ps
.cis
.CtlType
= cis
->CtlType
;
828 data
->ps
.cis
.CtlID
= cis
->CtlID
;
829 data
->ps
.cis
.hwndItem
= wine_server_user_handle( cis
->hwndItem
);
830 data
->ps
.cis
.itemID1
= cis
->itemID1
;
831 data
->ps
.cis
.itemData1
= cis
->itemData1
;
832 data
->ps
.cis
.itemID2
= cis
->itemID2
;
833 data
->ps
.cis
.itemData2
= cis
->itemData2
;
834 data
->ps
.cis
.dwLocaleId
= cis
->dwLocaleId
;
835 push_data( data
, &data
->ps
.cis
, sizeof(data
->ps
.cis
) );
838 case WM_WINE_SETWINDOWPOS
:
839 case WM_WINDOWPOSCHANGING
:
840 case WM_WINDOWPOSCHANGED
:
842 WINDOWPOS
*wp
= (WINDOWPOS
*)lparam
;
843 data
->ps
.wp
.hwnd
= wine_server_user_handle( wp
->hwnd
);
844 data
->ps
.wp
.hwndInsertAfter
= wine_server_user_handle( wp
->hwndInsertAfter
);
845 data
->ps
.wp
.x
= wp
->x
;
846 data
->ps
.wp
.y
= wp
->y
;
847 data
->ps
.wp
.cx
= wp
->cx
;
848 data
->ps
.wp
.cy
= wp
->cy
;
849 data
->ps
.wp
.flags
= wp
->flags
;
850 push_data( data
, &data
->ps
.wp
, sizeof(data
->ps
.wp
) );
851 return sizeof(data
->ps
.wp
);
855 COPYDATASTRUCT
*cds
= (COPYDATASTRUCT
*)lparam
;
856 data
->ps
.cds
.cbData
= cds
->cbData
;
857 data
->ps
.cds
.dwData
= cds
->dwData
;
858 data
->ps
.cds
.lpData
= pack_ptr( cds
->lpData
);
859 push_data( data
, &data
->ps
.cds
, sizeof(data
->ps
.cds
) );
860 if (cds
->lpData
) push_data( data
, cds
->lpData
, cds
->cbData
);
864 /* WM_NOTIFY cannot be sent across processes (MSDN) */
869 HELPINFO
*hi
= (HELPINFO
*)lparam
;
870 data
->ps
.hi
.iContextType
= hi
->iContextType
;
871 data
->ps
.hi
.iCtrlId
= hi
->iCtrlId
;
872 data
->ps
.hi
.hItemHandle
= wine_server_user_handle( hi
->hItemHandle
);
873 data
->ps
.hi
.dwContextId
= hi
->dwContextId
;
874 data
->ps
.hi
.MousePos
= hi
->MousePos
;
875 push_data( data
, &data
->ps
.hi
, sizeof(data
->ps
.hi
) );
878 case WM_STYLECHANGING
:
879 case WM_STYLECHANGED
:
880 push_data( data
, (STYLESTRUCT
*)lparam
, sizeof(STYLESTRUCT
) );
885 push_data( data
, (RECT
*)lparam
, sizeof(RECT
) );
890 NCCALCSIZE_PARAMS
*ncp
= (NCCALCSIZE_PARAMS
*)lparam
;
891 data
->ps
.ncp
.rgrc
[0] = ncp
->rgrc
[0];
892 data
->ps
.ncp
.rgrc
[1] = ncp
->rgrc
[1];
893 data
->ps
.ncp
.rgrc
[2] = ncp
->rgrc
[2];
894 data
->ps
.ncp
.hwnd
= wine_server_user_handle( ncp
->lppos
->hwnd
);
895 data
->ps
.ncp
.hwndInsertAfter
= wine_server_user_handle( ncp
->lppos
->hwndInsertAfter
);
896 data
->ps
.ncp
.x
= ncp
->lppos
->x
;
897 data
->ps
.ncp
.y
= ncp
->lppos
->y
;
898 data
->ps
.ncp
.cx
= ncp
->lppos
->cx
;
899 data
->ps
.ncp
.cy
= ncp
->lppos
->cy
;
900 data
->ps
.ncp
.flags
= ncp
->lppos
->flags
;
901 push_data( data
, &data
->ps
.ncp
, sizeof(data
->ps
.ncp
) );
902 return sizeof(data
->ps
.ncp
);
907 MSG
*msg
= (MSG
*)lparam
;
908 data
->ps
.msg
.hwnd
= wine_server_user_handle( msg
->hwnd
);
909 data
->ps
.msg
.message
= msg
->message
;
910 data
->ps
.msg
.wParam
= msg
->wParam
;
911 data
->ps
.msg
.lParam
= msg
->lParam
;
912 data
->ps
.msg
.time
= msg
->time
;
913 data
->ps
.msg
.pt
= msg
->pt
;
914 push_data( data
, &data
->ps
.msg
, sizeof(data
->ps
.msg
) );
915 return sizeof(data
->ps
.msg
);
918 case SBM_SETSCROLLINFO
:
919 push_data( data
, (SCROLLINFO
*)lparam
, sizeof(SCROLLINFO
) );
921 case SBM_GETSCROLLINFO
:
922 push_data( data
, (SCROLLINFO
*)lparam
, sizeof(SCROLLINFO
) );
923 return sizeof(SCROLLINFO
);
924 case SBM_GETSCROLLBARINFO
:
926 const SCROLLBARINFO
*info
= (const SCROLLBARINFO
*)lparam
;
927 size_t size
= min( info
->cbSize
, sizeof(SCROLLBARINFO
) );
928 push_data( data
, info
, size
);
936 if (wparam
) size
+= sizeof(DWORD
);
937 if (lparam
) size
+= sizeof(DWORD
);
942 case CB_GETDROPPEDCONTROLRECT
:
946 push_data( data
, (RECT
*)lparam
, sizeof(RECT
) );
950 WORD
*pw
= (WORD
*)lparam
;
951 push_data( data
, pw
, sizeof(*pw
) );
952 return *pw
* sizeof(WCHAR
);
956 if (wparam
) push_data( data
, (UINT
*)lparam
, sizeof(UINT
) * wparam
);
959 case CB_INSERTSTRING
:
961 case CB_FINDSTRINGEXACT
:
962 case CB_SELECTSTRING
:
963 if (combobox_has_strings( hwnd
)) push_string( data
, (LPWSTR
)lparam
);
966 if (!combobox_has_strings( hwnd
)) return sizeof(ULONG_PTR
);
967 return (SendMessageW( hwnd
, CB_GETLBTEXTLEN
, wparam
, 0 ) + 1) * sizeof(WCHAR
);
969 case LB_INSERTSTRING
:
971 case LB_FINDSTRINGEXACT
:
972 case LB_SELECTSTRING
:
973 if (listbox_has_strings( hwnd
)) push_string( data
, (LPWSTR
)lparam
);
976 if (!listbox_has_strings( hwnd
)) return sizeof(ULONG_PTR
);
977 return (SendMessageW( hwnd
, LB_GETTEXTLEN
, wparam
, 0 ) + 1) * sizeof(WCHAR
);
979 return wparam
* sizeof(UINT
);
982 MDINEXTMENU
*mnm
= (MDINEXTMENU
*)lparam
;
983 data
->ps
.mnm
.hmenuIn
= wine_server_user_handle( mnm
->hmenuIn
);
984 data
->ps
.mnm
.hmenuNext
= wine_server_user_handle( mnm
->hmenuNext
);
985 data
->ps
.mnm
.hwndNext
= wine_server_user_handle( mnm
->hwndNext
);
986 push_data( data
, &data
->ps
.mnm
, sizeof(data
->ps
.mnm
) );
987 return sizeof(data
->ps
.mnm
);
991 push_data( data
, (RECT
*)lparam
, sizeof(RECT
) );
995 MDICREATESTRUCTW
*mcs
= (MDICREATESTRUCTW
*)lparam
;
996 data
->ps
.mcs
.szClass
= pack_ptr( mcs
->szClass
);
997 data
->ps
.mcs
.szTitle
= pack_ptr( mcs
->szTitle
);
998 data
->ps
.mcs
.hOwner
= pack_ptr( mcs
->hOwner
);
999 data
->ps
.mcs
.x
= mcs
->x
;
1000 data
->ps
.mcs
.y
= mcs
->y
;
1001 data
->ps
.mcs
.cx
= mcs
->cx
;
1002 data
->ps
.mcs
.cy
= mcs
->cy
;
1003 data
->ps
.mcs
.style
= mcs
->style
;
1004 data
->ps
.mcs
.lParam
= mcs
->lParam
;
1005 push_data( data
, &data
->ps
.mcs
, sizeof(data
->ps
.mcs
) );
1006 if (!IS_INTRESOURCE(mcs
->szClass
)) push_string( data
, mcs
->szClass
);
1007 if (!IS_INTRESOURCE(mcs
->szTitle
)) push_string( data
, mcs
->szTitle
);
1008 return sizeof(data
->ps
.mcs
);
1010 case WM_MDIGETACTIVE
:
1011 if (lparam
) return sizeof(BOOL
);
1013 case WM_DEVICECHANGE
:
1015 DEV_BROADCAST_HDR
*header
= (DEV_BROADCAST_HDR
*)lparam
;
1016 push_data( data
, header
, header
->dbch_size
);
1019 case WM_WINE_KEYBOARD_LL_HOOK
:
1021 struct hook_extra_info
*h_extra
= (struct hook_extra_info
*)lparam
;
1022 data
->ps
.hook
.handle
= wine_server_user_handle( h_extra
->handle
);
1023 push_data( data
, &data
->ps
.hook
, sizeof(data
->ps
.hook
) );
1024 push_data( data
, (LPVOID
)h_extra
->lparam
, sizeof(KBDLLHOOKSTRUCT
) );
1027 case WM_WINE_MOUSE_LL_HOOK
:
1029 struct hook_extra_info
*h_extra
= (struct hook_extra_info
*)lparam
;
1030 data
->ps
.hook
.handle
= wine_server_user_handle( h_extra
->handle
);
1031 push_data( data
, &data
->ps
.hook
, sizeof(data
->ps
.hook
) );
1032 push_data( data
, (LPVOID
)h_extra
->lparam
, sizeof(MSLLHOOKSTRUCT
) );
1036 if (wparam
<= 1) return 0;
1037 FIXME( "WM_NCPAINT hdc packing not supported yet\n" );
1041 if (!wparam
) return 0;
1044 /* these contain an HFONT */
1047 /* these contain an HDC */
1049 case WM_ICONERASEBKGND
:
1050 case WM_CTLCOLORMSGBOX
:
1051 case WM_CTLCOLOREDIT
:
1052 case WM_CTLCOLORLISTBOX
:
1053 case WM_CTLCOLORBTN
:
1054 case WM_CTLCOLORDLG
:
1055 case WM_CTLCOLORSCROLLBAR
:
1056 case WM_CTLCOLORSTATIC
:
1058 case WM_PRINTCLIENT
:
1059 /* these contain an HGLOBAL */
1060 case WM_PAINTCLIPBOARD
:
1061 case WM_SIZECLIPBOARD
:
1062 /* these contain HICON */
1065 case WM_QUERYDRAGICON
:
1066 case WM_QUERYPARKICON
:
1067 /* these contain pointers */
1069 case WM_QUERYDROPOBJECT
:
1073 FIXME( "msg %x (%s) not supported yet\n", message
, SPY_GetMsgName(message
, hwnd
) );
1081 /***********************************************************************
1084 * Unpack a message received from another process.
1086 static BOOL
unpack_message( HWND hwnd
, UINT message
, WPARAM
*wparam
, LPARAM
*lparam
,
1087 void **buffer
, size_t size
)
1090 union packed_structs
*ps
= *buffer
;
1098 WCHAR
*str
= (WCHAR
*)(&ps
->cs
+ 1);
1099 if (size
< sizeof(ps
->cs
)) return FALSE
;
1100 size
-= sizeof(ps
->cs
);
1101 cs
.lpCreateParams
= unpack_ptr( ps
->cs
.lpCreateParams
);
1102 cs
.hInstance
= unpack_ptr( ps
->cs
.hInstance
);
1103 cs
.hMenu
= wine_server_ptr_handle( ps
->cs
.hMenu
);
1104 cs
.hwndParent
= wine_server_ptr_handle( ps
->cs
.hwndParent
);
1109 cs
.style
= ps
->cs
.style
;
1110 cs
.dwExStyle
= ps
->cs
.dwExStyle
;
1111 cs
.lpszName
= unpack_ptr( ps
->cs
.lpszName
);
1112 cs
.lpszClass
= unpack_ptr( ps
->cs
.lpszClass
);
1113 if (ps
->cs
.lpszName
>> 16)
1115 if (!check_string( str
, size
)) return FALSE
;
1117 size
-= (strlenW(str
) + 1) * sizeof(WCHAR
);
1118 str
+= strlenW(str
) + 1;
1120 if (ps
->cs
.lpszClass
>> 16)
1122 if (!check_string( str
, size
)) return FALSE
;
1125 memcpy( &ps
->cs
, &cs
, sizeof(cs
) );
1129 case WM_ASKCBFORMATNAME
:
1130 if (!get_buffer_space( buffer
, (*wparam
* sizeof(WCHAR
)) )) return FALSE
;
1132 case WM_WININICHANGE
:
1133 if (!*lparam
) return TRUE
;
1136 case WM_DEVMODECHANGE
:
1141 if (!check_string( *buffer
, size
)) return FALSE
;
1143 case WM_GETMINMAXINFO
:
1144 minsize
= sizeof(MINMAXINFO
);
1149 if (size
< sizeof(ps
->dis
)) return FALSE
;
1150 dis
.CtlType
= ps
->dis
.CtlType
;
1151 dis
.CtlID
= ps
->dis
.CtlID
;
1152 dis
.itemID
= ps
->dis
.itemID
;
1153 dis
.itemAction
= ps
->dis
.itemAction
;
1154 dis
.itemState
= ps
->dis
.itemState
;
1155 dis
.hwndItem
= wine_server_ptr_handle( ps
->dis
.hwndItem
);
1156 dis
.hDC
= wine_server_ptr_handle( ps
->dis
.hDC
);
1157 dis
.rcItem
= ps
->dis
.rcItem
;
1158 dis
.itemData
= (ULONG_PTR
)unpack_ptr( ps
->dis
.itemData
);
1159 memcpy( &ps
->dis
, &dis
, sizeof(dis
) );
1162 case WM_MEASUREITEM
:
1164 MEASUREITEMSTRUCT mis
;
1165 if (size
< sizeof(ps
->mis
)) return FALSE
;
1166 mis
.CtlType
= ps
->mis
.CtlType
;
1167 mis
.CtlID
= ps
->mis
.CtlID
;
1168 mis
.itemID
= ps
->mis
.itemID
;
1169 mis
.itemWidth
= ps
->mis
.itemWidth
;
1170 mis
.itemHeight
= ps
->mis
.itemHeight
;
1171 mis
.itemData
= (ULONG_PTR
)unpack_ptr( ps
->mis
.itemData
);
1172 memcpy( &ps
->mis
, &mis
, sizeof(mis
) );
1177 DELETEITEMSTRUCT dls
;
1178 if (size
< sizeof(ps
->dls
)) return FALSE
;
1179 dls
.CtlType
= ps
->dls
.CtlType
;
1180 dls
.CtlID
= ps
->dls
.CtlID
;
1181 dls
.itemID
= ps
->dls
.itemID
;
1182 dls
.hwndItem
= wine_server_ptr_handle( ps
->dls
.hwndItem
);
1183 dls
.itemData
= (ULONG_PTR
)unpack_ptr( ps
->dls
.itemData
);
1184 memcpy( &ps
->dls
, &dls
, sizeof(dls
) );
1187 case WM_COMPAREITEM
:
1189 COMPAREITEMSTRUCT cis
;
1190 if (size
< sizeof(ps
->cis
)) return FALSE
;
1191 cis
.CtlType
= ps
->cis
.CtlType
;
1192 cis
.CtlID
= ps
->cis
.CtlID
;
1193 cis
.hwndItem
= wine_server_ptr_handle( ps
->cis
.hwndItem
);
1194 cis
.itemID1
= ps
->cis
.itemID1
;
1195 cis
.itemData1
= (ULONG_PTR
)unpack_ptr( ps
->cis
.itemData1
);
1196 cis
.itemID2
= ps
->cis
.itemID2
;
1197 cis
.itemData2
= (ULONG_PTR
)unpack_ptr( ps
->cis
.itemData2
);
1198 cis
.dwLocaleId
= ps
->cis
.dwLocaleId
;
1199 memcpy( &ps
->cis
, &cis
, sizeof(cis
) );
1202 case WM_WINDOWPOSCHANGING
:
1203 case WM_WINDOWPOSCHANGED
:
1204 case WM_WINE_SETWINDOWPOS
:
1207 if (size
< sizeof(ps
->wp
)) return FALSE
;
1208 wp
.hwnd
= wine_server_ptr_handle( ps
->wp
.hwnd
);
1209 wp
.hwndInsertAfter
= wine_server_ptr_handle( ps
->wp
.hwndInsertAfter
);
1214 wp
.flags
= ps
->wp
.flags
;
1215 memcpy( &ps
->wp
, &wp
, sizeof(wp
) );
1221 if (size
< sizeof(ps
->cds
)) return FALSE
;
1222 cds
.dwData
= (ULONG_PTR
)unpack_ptr( ps
->cds
.dwData
);
1225 cds
.cbData
= ps
->cds
.cbData
;
1226 cds
.lpData
= &ps
->cds
+ 1;
1227 minsize
= sizeof(ps
->cds
) + cds
.cbData
;
1234 memcpy( &ps
->cds
, &cds
, sizeof(cds
) );
1238 /* WM_NOTIFY cannot be sent across processes (MSDN) */
1243 if (size
< sizeof(ps
->hi
)) return FALSE
;
1244 hi
.cbSize
= sizeof(hi
);
1245 hi
.iContextType
= ps
->hi
.iContextType
;
1246 hi
.iCtrlId
= ps
->hi
.iCtrlId
;
1247 hi
.hItemHandle
= wine_server_ptr_handle( ps
->hi
.hItemHandle
);
1248 hi
.dwContextId
= (ULONG_PTR
)unpack_ptr( ps
->hi
.dwContextId
);
1249 hi
.MousePos
= ps
->hi
.MousePos
;
1250 memcpy( &ps
->hi
, &hi
, sizeof(hi
) );
1253 case WM_STYLECHANGING
:
1254 case WM_STYLECHANGED
:
1255 minsize
= sizeof(STYLESTRUCT
);
1258 if (!*wparam
) minsize
= sizeof(RECT
);
1261 NCCALCSIZE_PARAMS ncp
;
1263 if (size
< sizeof(ps
->ncp
)) return FALSE
;
1264 ncp
.rgrc
[0] = ps
->ncp
.rgrc
[0];
1265 ncp
.rgrc
[1] = ps
->ncp
.rgrc
[1];
1266 ncp
.rgrc
[2] = ps
->ncp
.rgrc
[2];
1267 wp
.hwnd
= wine_server_ptr_handle( ps
->ncp
.hwnd
);
1268 wp
.hwndInsertAfter
= wine_server_ptr_handle( ps
->ncp
.hwndInsertAfter
);
1273 wp
.flags
= ps
->ncp
.flags
;
1274 ncp
.lppos
= (WINDOWPOS
*)((NCCALCSIZE_PARAMS
*)&ps
->ncp
+ 1);
1275 memcpy( &ps
->ncp
, &ncp
, sizeof(ncp
) );
1283 if (size
< sizeof(ps
->msg
)) return FALSE
;
1284 msg
.hwnd
= wine_server_ptr_handle( ps
->msg
.hwnd
);
1285 msg
.message
= ps
->msg
.message
;
1286 msg
.wParam
= (ULONG_PTR
)unpack_ptr( ps
->msg
.wParam
);
1287 msg
.lParam
= (ULONG_PTR
)unpack_ptr( ps
->msg
.lParam
);
1288 msg
.time
= ps
->msg
.time
;
1289 msg
.pt
= ps
->msg
.pt
;
1290 memcpy( &ps
->msg
, &msg
, sizeof(msg
) );
1294 case SBM_SETSCROLLINFO
:
1295 minsize
= sizeof(SCROLLINFO
);
1297 case SBM_GETSCROLLINFO
:
1298 if (!get_buffer_space( buffer
, sizeof(SCROLLINFO
))) return FALSE
;
1300 case SBM_GETSCROLLBARINFO
:
1301 if (!get_buffer_space( buffer
, sizeof(SCROLLBARINFO
))) return FALSE
;
1306 if (*wparam
|| *lparam
)
1308 if (!get_buffer_space( buffer
, 2*sizeof(DWORD
) )) return FALSE
;
1309 if (*wparam
) *wparam
= (WPARAM
)*buffer
;
1310 if (*lparam
) *lparam
= (LPARAM
)((DWORD
*)*buffer
+ 1);
1314 case LB_GETITEMRECT
:
1315 case CB_GETDROPPEDCONTROLRECT
:
1316 if (!get_buffer_space( buffer
, sizeof(RECT
) )) return FALSE
;
1320 minsize
= sizeof(RECT
);
1325 if (size
< sizeof(WORD
)) return FALSE
;
1326 len
= *(WORD
*)*buffer
;
1327 if (!get_buffer_space( buffer
, (len
+ 1) * sizeof(WCHAR
) )) return FALSE
;
1328 *lparam
= (LPARAM
)*buffer
+ sizeof(WORD
); /* don't erase WORD at start of buffer */
1331 case EM_SETTABSTOPS
:
1332 case LB_SETTABSTOPS
:
1333 if (!*wparam
) return TRUE
;
1334 minsize
= *wparam
* sizeof(UINT
);
1337 case CB_INSERTSTRING
:
1339 case CB_FINDSTRINGEXACT
:
1340 case CB_SELECTSTRING
:
1342 case LB_INSERTSTRING
:
1344 case LB_FINDSTRINGEXACT
:
1345 case LB_SELECTSTRING
:
1346 if (!*buffer
) return TRUE
;
1347 if (!check_string( *buffer
, size
)) return FALSE
;
1351 size
= sizeof(ULONG_PTR
);
1352 if (combobox_has_strings( hwnd
))
1353 size
= (SendMessageW( hwnd
, CB_GETLBTEXTLEN
, *wparam
, 0 ) + 1) * sizeof(WCHAR
);
1354 if (!get_buffer_space( buffer
, size
)) return FALSE
;
1359 size
= sizeof(ULONG_PTR
);
1360 if (listbox_has_strings( hwnd
))
1361 size
= (SendMessageW( hwnd
, LB_GETTEXTLEN
, *wparam
, 0 ) + 1) * sizeof(WCHAR
);
1362 if (!get_buffer_space( buffer
, size
)) return FALSE
;
1365 case LB_GETSELITEMS
:
1366 if (!get_buffer_space( buffer
, *wparam
* sizeof(UINT
) )) return FALSE
;
1371 if (size
< sizeof(ps
->mnm
)) return FALSE
;
1372 mnm
.hmenuIn
= wine_server_ptr_handle( ps
->mnm
.hmenuIn
);
1373 mnm
.hmenuNext
= wine_server_ptr_handle( ps
->mnm
.hmenuNext
);
1374 mnm
.hwndNext
= wine_server_ptr_handle( ps
->mnm
.hwndNext
);
1375 memcpy( &ps
->mnm
, &mnm
, sizeof(mnm
) );
1380 minsize
= sizeof(RECT
);
1381 if (!get_buffer_space( buffer
, sizeof(RECT
) )) return FALSE
;
1385 MDICREATESTRUCTW mcs
;
1386 WCHAR
*str
= (WCHAR
*)(&ps
->mcs
+ 1);
1387 if (size
< sizeof(ps
->mcs
)) return FALSE
;
1388 size
-= sizeof(ps
->mcs
);
1390 mcs
.szClass
= unpack_ptr( ps
->mcs
.szClass
);
1391 mcs
.szTitle
= unpack_ptr( ps
->mcs
.szTitle
);
1392 mcs
.hOwner
= unpack_ptr( ps
->mcs
.hOwner
);
1395 mcs
.cx
= ps
->mcs
.cx
;
1396 mcs
.cy
= ps
->mcs
.cy
;
1397 mcs
.style
= ps
->mcs
.style
;
1398 mcs
.lParam
= (LPARAM
)unpack_ptr( ps
->mcs
.lParam
);
1399 if (ps
->mcs
.szClass
>> 16)
1401 if (!check_string( str
, size
)) return FALSE
;
1403 size
-= (strlenW(str
) + 1) * sizeof(WCHAR
);
1404 str
+= strlenW(str
) + 1;
1406 if (ps
->mcs
.szTitle
>> 16)
1408 if (!check_string( str
, size
)) return FALSE
;
1411 memcpy( &ps
->mcs
, &mcs
, sizeof(mcs
) );
1414 case WM_MDIGETACTIVE
:
1415 if (!*lparam
) return TRUE
;
1416 if (!get_buffer_space( buffer
, sizeof(BOOL
) )) return FALSE
;
1418 case WM_DEVICECHANGE
:
1419 minsize
= sizeof(DEV_BROADCAST_HDR
);
1421 case WM_WINE_KEYBOARD_LL_HOOK
:
1422 case WM_WINE_MOUSE_LL_HOOK
:
1424 struct hook_extra_info h_extra
;
1425 minsize
= sizeof(ps
->hook
) +
1426 (message
== WM_WINE_KEYBOARD_LL_HOOK
? sizeof(KBDLLHOOKSTRUCT
)
1427 : sizeof(MSLLHOOKSTRUCT
));
1428 if (size
< minsize
) return FALSE
;
1429 h_extra
.handle
= wine_server_ptr_handle( ps
->hook
.handle
);
1430 h_extra
.lparam
= (LPARAM
)(&ps
->hook
+ 1);
1431 memcpy( &ps
->hook
, &h_extra
, sizeof(h_extra
) );
1435 if (*wparam
<= 1) return TRUE
;
1436 FIXME( "WM_NCPAINT hdc unpacking not supported\n" );
1439 if (!*wparam
) return TRUE
;
1442 /* these contain an HFONT */
1445 /* these contain an HDC */
1447 case WM_ICONERASEBKGND
:
1448 case WM_CTLCOLORMSGBOX
:
1449 case WM_CTLCOLOREDIT
:
1450 case WM_CTLCOLORLISTBOX
:
1451 case WM_CTLCOLORBTN
:
1452 case WM_CTLCOLORDLG
:
1453 case WM_CTLCOLORSCROLLBAR
:
1454 case WM_CTLCOLORSTATIC
:
1456 case WM_PRINTCLIENT
:
1457 /* these contain an HGLOBAL */
1458 case WM_PAINTCLIPBOARD
:
1459 case WM_SIZECLIPBOARD
:
1460 /* these contain HICON */
1463 case WM_QUERYDRAGICON
:
1464 case WM_QUERYPARKICON
:
1465 /* these contain pointers */
1467 case WM_QUERYDROPOBJECT
:
1471 FIXME( "msg %x (%s) not supported yet\n", message
, SPY_GetMsgName(message
, hwnd
) );
1475 return TRUE
; /* message doesn't need any unpacking */
1478 /* default exit for most messages: check minsize and store buffer in lparam */
1479 if (size
< minsize
) return FALSE
;
1480 *lparam
= (LPARAM
)*buffer
;
1485 /***********************************************************************
1488 * Pack a reply to a message for sending to another process.
1490 static void pack_reply( HWND hwnd
, UINT message
, WPARAM wparam
, LPARAM lparam
,
1491 LRESULT res
, struct packed_message
*data
)
1499 CREATESTRUCTW
*cs
= (CREATESTRUCTW
*)lparam
;
1500 data
->ps
.cs
.lpCreateParams
= (ULONG_PTR
)cs
->lpCreateParams
;
1501 data
->ps
.cs
.hInstance
= (ULONG_PTR
)cs
->hInstance
;
1502 data
->ps
.cs
.hMenu
= wine_server_user_handle( cs
->hMenu
);
1503 data
->ps
.cs
.hwndParent
= wine_server_user_handle( cs
->hwndParent
);
1504 data
->ps
.cs
.cy
= cs
->cy
;
1505 data
->ps
.cs
.cx
= cs
->cx
;
1506 data
->ps
.cs
.y
= cs
->y
;
1507 data
->ps
.cs
.x
= cs
->x
;
1508 data
->ps
.cs
.style
= cs
->style
;
1509 data
->ps
.cs
.dwExStyle
= cs
->dwExStyle
;
1510 data
->ps
.cs
.lpszName
= (ULONG_PTR
)cs
->lpszName
;
1511 data
->ps
.cs
.lpszClass
= (ULONG_PTR
)cs
->lpszClass
;
1512 push_data( data
, &data
->ps
.cs
, sizeof(data
->ps
.cs
) );
1518 push_data( data
, (WCHAR
*)lparam
, (res
+ 1) * sizeof(WCHAR
) );
1520 case WM_GETMINMAXINFO
:
1521 push_data( data
, (MINMAXINFO
*)lparam
, sizeof(MINMAXINFO
) );
1523 case WM_MEASUREITEM
:
1525 MEASUREITEMSTRUCT
*mis
= (MEASUREITEMSTRUCT
*)lparam
;
1526 data
->ps
.mis
.CtlType
= mis
->CtlType
;
1527 data
->ps
.mis
.CtlID
= mis
->CtlID
;
1528 data
->ps
.mis
.itemID
= mis
->itemID
;
1529 data
->ps
.mis
.itemWidth
= mis
->itemWidth
;
1530 data
->ps
.mis
.itemHeight
= mis
->itemHeight
;
1531 data
->ps
.mis
.itemData
= mis
->itemData
;
1532 push_data( data
, &data
->ps
.mis
, sizeof(data
->ps
.mis
) );
1535 case WM_WINDOWPOSCHANGING
:
1536 case WM_WINDOWPOSCHANGED
:
1538 WINDOWPOS
*wp
= (WINDOWPOS
*)lparam
;
1539 data
->ps
.wp
.hwnd
= wine_server_user_handle( wp
->hwnd
);
1540 data
->ps
.wp
.hwndInsertAfter
= wine_server_user_handle( wp
->hwndInsertAfter
);
1541 data
->ps
.wp
.x
= wp
->x
;
1542 data
->ps
.wp
.y
= wp
->y
;
1543 data
->ps
.wp
.cx
= wp
->cx
;
1544 data
->ps
.wp
.cy
= wp
->cy
;
1545 data
->ps
.wp
.flags
= wp
->flags
;
1546 push_data( data
, &data
->ps
.wp
, sizeof(data
->ps
.wp
) );
1552 MSG
*msg
= (MSG
*)lparam
;
1553 data
->ps
.msg
.hwnd
= wine_server_user_handle( msg
->hwnd
);
1554 data
->ps
.msg
.message
= msg
->message
;
1555 data
->ps
.msg
.wParam
= msg
->wParam
;
1556 data
->ps
.msg
.lParam
= msg
->lParam
;
1557 data
->ps
.msg
.time
= msg
->time
;
1558 data
->ps
.msg
.pt
= msg
->pt
;
1559 push_data( data
, &data
->ps
.msg
, sizeof(data
->ps
.msg
) );
1562 case SBM_GETSCROLLINFO
:
1563 push_data( data
, (SCROLLINFO
*)lparam
, sizeof(SCROLLINFO
) );
1566 case LB_GETITEMRECT
:
1567 case CB_GETDROPPEDCONTROLRECT
:
1570 push_data( data
, (RECT
*)lparam
, sizeof(RECT
) );
1574 WORD
*ptr
= (WORD
*)lparam
;
1575 push_data( data
, ptr
, ptr
[-1] * sizeof(WCHAR
) );
1578 case LB_GETSELITEMS
:
1579 push_data( data
, (UINT
*)lparam
, wparam
* sizeof(UINT
) );
1581 case WM_MDIGETACTIVE
:
1582 if (lparam
) push_data( data
, (BOOL
*)lparam
, sizeof(BOOL
) );
1586 push_data( data
, (RECT
*)lparam
, sizeof(RECT
) );
1589 NCCALCSIZE_PARAMS
*ncp
= (NCCALCSIZE_PARAMS
*)lparam
;
1590 data
->ps
.ncp
.rgrc
[0] = ncp
->rgrc
[0];
1591 data
->ps
.ncp
.rgrc
[1] = ncp
->rgrc
[1];
1592 data
->ps
.ncp
.rgrc
[2] = ncp
->rgrc
[2];
1593 data
->ps
.ncp
.hwnd
= wine_server_user_handle( ncp
->lppos
->hwnd
);
1594 data
->ps
.ncp
.hwndInsertAfter
= wine_server_user_handle( ncp
->lppos
->hwndInsertAfter
);
1595 data
->ps
.ncp
.x
= ncp
->lppos
->x
;
1596 data
->ps
.ncp
.y
= ncp
->lppos
->y
;
1597 data
->ps
.ncp
.cx
= ncp
->lppos
->cx
;
1598 data
->ps
.ncp
.cy
= ncp
->lppos
->cy
;
1599 data
->ps
.ncp
.flags
= ncp
->lppos
->flags
;
1600 push_data( data
, &data
->ps
.ncp
, sizeof(data
->ps
.ncp
) );
1606 if (wparam
) push_data( data
, (DWORD
*)wparam
, sizeof(DWORD
) );
1607 if (lparam
) push_data( data
, (DWORD
*)lparam
, sizeof(DWORD
) );
1611 MDINEXTMENU
*mnm
= (MDINEXTMENU
*)lparam
;
1612 data
->ps
.mnm
.hmenuIn
= wine_server_user_handle( mnm
->hmenuIn
);
1613 data
->ps
.mnm
.hmenuNext
= wine_server_user_handle( mnm
->hmenuNext
);
1614 data
->ps
.mnm
.hwndNext
= wine_server_user_handle( mnm
->hwndNext
);
1615 push_data( data
, &data
->ps
.mnm
, sizeof(data
->ps
.mnm
) );
1620 MDICREATESTRUCTW
*mcs
= (MDICREATESTRUCTW
*)lparam
;
1621 data
->ps
.mcs
.szClass
= pack_ptr( mcs
->szClass
);
1622 data
->ps
.mcs
.szTitle
= pack_ptr( mcs
->szTitle
);
1623 data
->ps
.mcs
.hOwner
= pack_ptr( mcs
->hOwner
);
1624 data
->ps
.mcs
.x
= mcs
->x
;
1625 data
->ps
.mcs
.y
= mcs
->y
;
1626 data
->ps
.mcs
.cx
= mcs
->cx
;
1627 data
->ps
.mcs
.cy
= mcs
->cy
;
1628 data
->ps
.mcs
.style
= mcs
->style
;
1629 data
->ps
.mcs
.lParam
= mcs
->lParam
;
1630 push_data( data
, &data
->ps
.mcs
, sizeof(data
->ps
.mcs
) );
1633 case WM_ASKCBFORMATNAME
:
1634 push_data( data
, (WCHAR
*)lparam
, (strlenW((WCHAR
*)lparam
) + 1) * sizeof(WCHAR
) );
1640 /***********************************************************************
1643 * Unpack a message reply received from another process.
1645 static void unpack_reply( HWND hwnd
, UINT message
, WPARAM wparam
, LPARAM lparam
,
1646 void *buffer
, size_t size
)
1648 union packed_structs
*ps
= buffer
;
1654 if (size
>= sizeof(ps
->cs
))
1656 CREATESTRUCTW
*cs
= (CREATESTRUCTW
*)lparam
;
1657 cs
->lpCreateParams
= unpack_ptr( ps
->cs
.lpCreateParams
);
1658 cs
->hInstance
= unpack_ptr( ps
->cs
.hInstance
);
1659 cs
->hMenu
= wine_server_ptr_handle( ps
->cs
.hMenu
);
1660 cs
->hwndParent
= wine_server_ptr_handle( ps
->cs
.hwndParent
);
1665 cs
->style
= ps
->cs
.style
;
1666 cs
->dwExStyle
= ps
->cs
.dwExStyle
;
1667 /* don't allow changing name and class pointers */
1671 case WM_ASKCBFORMATNAME
:
1672 memcpy( (WCHAR
*)lparam
, buffer
, min( wparam
*sizeof(WCHAR
), size
));
1674 case WM_GETMINMAXINFO
:
1675 memcpy( (MINMAXINFO
*)lparam
, buffer
, min( sizeof(MINMAXINFO
), size
));
1677 case WM_MEASUREITEM
:
1678 if (size
>= sizeof(ps
->mis
))
1680 MEASUREITEMSTRUCT
*mis
= (MEASUREITEMSTRUCT
*)lparam
;
1681 mis
->CtlType
= ps
->mis
.CtlType
;
1682 mis
->CtlID
= ps
->mis
.CtlID
;
1683 mis
->itemID
= ps
->mis
.itemID
;
1684 mis
->itemWidth
= ps
->mis
.itemWidth
;
1685 mis
->itemHeight
= ps
->mis
.itemHeight
;
1686 mis
->itemData
= (ULONG_PTR
)unpack_ptr( ps
->mis
.itemData
);
1689 case WM_WINDOWPOSCHANGING
:
1690 case WM_WINDOWPOSCHANGED
:
1691 if (size
>= sizeof(ps
->wp
))
1693 WINDOWPOS
*wp
= (WINDOWPOS
*)lparam
;
1694 wp
->hwnd
= wine_server_ptr_handle( ps
->wp
.hwnd
);
1695 wp
->hwndInsertAfter
= wine_server_ptr_handle( ps
->wp
.hwndInsertAfter
);
1700 wp
->flags
= ps
->wp
.flags
;
1704 if (lparam
&& size
>= sizeof(ps
->msg
))
1706 MSG
*msg
= (MSG
*)lparam
;
1707 msg
->hwnd
= wine_server_ptr_handle( ps
->msg
.hwnd
);
1708 msg
->message
= ps
->msg
.message
;
1709 msg
->wParam
= (ULONG_PTR
)unpack_ptr( ps
->msg
.wParam
);
1710 msg
->lParam
= (ULONG_PTR
)unpack_ptr( ps
->msg
.lParam
);
1711 msg
->time
= ps
->msg
.time
;
1712 msg
->pt
= ps
->msg
.pt
;
1715 case SBM_GETSCROLLINFO
:
1716 memcpy( (SCROLLINFO
*)lparam
, buffer
, min( sizeof(SCROLLINFO
), size
));
1718 case SBM_GETSCROLLBARINFO
:
1719 memcpy( (SCROLLBARINFO
*)lparam
, buffer
, min( sizeof(SCROLLBARINFO
), size
));
1722 case CB_GETDROPPEDCONTROLRECT
:
1723 case LB_GETITEMRECT
:
1726 memcpy( (RECT
*)lparam
, buffer
, min( sizeof(RECT
), size
));
1729 size
= min( size
, (size_t)*(WORD
*)lparam
);
1730 memcpy( (WCHAR
*)lparam
, buffer
, size
);
1732 case LB_GETSELITEMS
:
1733 memcpy( (UINT
*)lparam
, buffer
, min( wparam
*sizeof(UINT
), size
));
1737 memcpy( (WCHAR
*)lparam
, buffer
, size
);
1740 if (size
>= sizeof(ps
->mnm
))
1742 MDINEXTMENU
*mnm
= (MDINEXTMENU
*)lparam
;
1743 mnm
->hmenuIn
= wine_server_ptr_handle( ps
->mnm
.hmenuIn
);
1744 mnm
->hmenuNext
= wine_server_ptr_handle( ps
->mnm
.hmenuNext
);
1745 mnm
->hwndNext
= wine_server_ptr_handle( ps
->mnm
.hwndNext
);
1748 case WM_MDIGETACTIVE
:
1749 if (lparam
) memcpy( (BOOL
*)lparam
, buffer
, min( sizeof(BOOL
), size
));
1753 memcpy( (RECT
*)lparam
, buffer
, min( sizeof(RECT
), size
));
1754 else if (size
>= sizeof(ps
->ncp
))
1756 NCCALCSIZE_PARAMS
*ncp
= (NCCALCSIZE_PARAMS
*)lparam
;
1757 ncp
->rgrc
[0] = ps
->ncp
.rgrc
[0];
1758 ncp
->rgrc
[1] = ps
->ncp
.rgrc
[1];
1759 ncp
->rgrc
[2] = ps
->ncp
.rgrc
[2];
1760 ncp
->lppos
->hwnd
= wine_server_ptr_handle( ps
->ncp
.hwnd
);
1761 ncp
->lppos
->hwndInsertAfter
= wine_server_ptr_handle( ps
->ncp
.hwndInsertAfter
);
1762 ncp
->lppos
->x
= ps
->ncp
.x
;
1763 ncp
->lppos
->y
= ps
->ncp
.y
;
1764 ncp
->lppos
->cx
= ps
->ncp
.cx
;
1765 ncp
->lppos
->cy
= ps
->ncp
.cy
;
1766 ncp
->lppos
->flags
= ps
->ncp
.flags
;
1774 memcpy( (DWORD
*)wparam
, buffer
, min( sizeof(DWORD
), size
));
1775 if (size
<= sizeof(DWORD
)) break;
1776 size
-= sizeof(DWORD
);
1777 buffer
= (DWORD
*)buffer
+ 1;
1779 if (lparam
) memcpy( (DWORD
*)lparam
, buffer
, min( sizeof(DWORD
), size
));
1782 if (size
>= sizeof(ps
->mcs
))
1784 MDICREATESTRUCTW
*mcs
= (MDICREATESTRUCTW
*)lparam
;
1785 mcs
->hOwner
= unpack_ptr( ps
->mcs
.hOwner
);
1788 mcs
->cx
= ps
->mcs
.cx
;
1789 mcs
->cy
= ps
->mcs
.cy
;
1790 mcs
->style
= ps
->mcs
.style
;
1791 mcs
->lParam
= (LPARAM
)unpack_ptr( ps
->mcs
.lParam
);
1792 /* don't allow changing class and title pointers */
1796 ERR( "should not happen: unexpected message %x\n", message
);
1802 /***********************************************************************
1805 * Send a reply to a sent message.
1807 static void reply_message( struct received_message_info
*info
, LRESULT result
, BOOL remove
)
1809 struct packed_message data
;
1810 int i
, replied
= info
->flags
& ISMEX_REPLIED
;
1812 if (info
->flags
& ISMEX_NOTIFY
) return; /* notify messages don't get replies */
1813 if (!remove
&& replied
) return; /* replied already */
1815 memset( &data
, 0, sizeof(data
) );
1816 info
->flags
|= ISMEX_REPLIED
;
1818 if (info
->type
== MSG_OTHER_PROCESS
&& !replied
)
1820 pack_reply( info
->msg
.hwnd
, info
->msg
.message
, info
->msg
.wParam
,
1821 info
->msg
.lParam
, result
, &data
);
1824 SERVER_START_REQ( reply_message
)
1826 req
->result
= result
;
1827 req
->remove
= remove
;
1828 for (i
= 0; i
< data
.count
; i
++) wine_server_add_data( req
, data
.data
[i
], data
.size
[i
] );
1829 wine_server_call( req
);
1835 /***********************************************************************
1836 * handle_internal_message
1838 * Handle an internal Wine message instead of calling the window proc.
1840 static LRESULT
handle_internal_message( HWND hwnd
, UINT msg
, WPARAM wparam
, LPARAM lparam
)
1844 case WM_WINE_DESTROYWINDOW
:
1845 return WIN_DestroyWindow( hwnd
);
1846 case WM_WINE_SETWINDOWPOS
:
1847 if (is_desktop_window( hwnd
)) return 0;
1848 return USER_SetWindowPos( (WINDOWPOS
*)lparam
);
1849 case WM_WINE_SHOWWINDOW
:
1850 if (is_desktop_window( hwnd
)) return 0;
1851 return ShowWindow( hwnd
, wparam
);
1852 case WM_WINE_SETPARENT
:
1853 if (is_desktop_window( hwnd
)) return 0;
1854 return (LRESULT
)SetParent( hwnd
, (HWND
)wparam
);
1855 case WM_WINE_SETWINDOWLONG
:
1856 return WIN_SetWindowLong( hwnd
, (short)LOWORD(wparam
), HIWORD(wparam
), lparam
, TRUE
);
1857 case WM_WINE_ENABLEWINDOW
:
1858 if (is_desktop_window( hwnd
)) return 0;
1859 return EnableWindow( hwnd
, wparam
);
1860 case WM_WINE_SETACTIVEWINDOW
:
1861 if (is_desktop_window( hwnd
)) return 0;
1862 return (LRESULT
)SetActiveWindow( (HWND
)wparam
);
1863 case WM_WINE_KEYBOARD_LL_HOOK
:
1864 case WM_WINE_MOUSE_LL_HOOK
:
1866 struct hook_extra_info
*h_extra
= (struct hook_extra_info
*)lparam
;
1868 return call_current_hook( h_extra
->handle
, HC_ACTION
, wparam
, h_extra
->lparam
);
1870 case WM_WINE_CLIPCURSOR
:
1874 GetClipCursor( &rect
);
1875 return USER_Driver
->pClipCursor( &rect
);
1877 return USER_Driver
->pClipCursor( NULL
);
1879 if (msg
>= WM_WINE_FIRST_DRIVER_MSG
&& msg
<= WM_WINE_LAST_DRIVER_MSG
)
1880 return USER_Driver
->pWindowMessage( hwnd
, msg
, wparam
, lparam
);
1881 FIXME( "unknown internal message %x\n", msg
);
1886 /* since the WM_DDE_ACK response to a WM_DDE_EXECUTE message should contain the handle
1887 * to the memory handle, we keep track (in the server side) of all pairs of handle
1888 * used (the client passes its value and the content of the memory handle), and
1889 * the server stored both values (the client, and the local one, created after the
1890 * content). When a ACK message is generated, the list of pair is searched for a
1891 * matching pair, so that the client memory handle can be returned.
1894 HGLOBAL client_hMem
;
1895 HGLOBAL server_hMem
;
1898 static struct DDE_pair
* dde_pairs
;
1899 static int dde_num_alloc
;
1900 static int dde_num_used
;
1902 static CRITICAL_SECTION dde_crst
;
1903 static CRITICAL_SECTION_DEBUG critsect_debug
=
1906 { &critsect_debug
.ProcessLocksList
, &critsect_debug
.ProcessLocksList
},
1907 0, 0, { (DWORD_PTR
)(__FILE__
": dde_crst") }
1909 static CRITICAL_SECTION dde_crst
= { &critsect_debug
, -1, 0, 0, 0, 0 };
1911 static BOOL
dde_add_pair(HGLOBAL chm
, HGLOBAL shm
)
1916 EnterCriticalSection(&dde_crst
);
1918 /* now remember the pair of hMem on both sides */
1919 if (dde_num_used
== dde_num_alloc
)
1921 struct DDE_pair
* tmp
;
1923 tmp
= HeapReAlloc( GetProcessHeap(), 0, dde_pairs
,
1924 (dde_num_alloc
+ GROWBY
) * sizeof(struct DDE_pair
));
1926 tmp
= HeapAlloc( GetProcessHeap(), 0,
1927 (dde_num_alloc
+ GROWBY
) * sizeof(struct DDE_pair
));
1931 LeaveCriticalSection(&dde_crst
);
1935 /* zero out newly allocated part */
1936 memset(&dde_pairs
[dde_num_alloc
], 0, GROWBY
* sizeof(struct DDE_pair
));
1937 dde_num_alloc
+= GROWBY
;
1940 for (i
= 0; i
< dde_num_alloc
; i
++)
1942 if (dde_pairs
[i
].server_hMem
== 0)
1944 dde_pairs
[i
].client_hMem
= chm
;
1945 dde_pairs
[i
].server_hMem
= shm
;
1950 LeaveCriticalSection(&dde_crst
);
1954 static HGLOBAL
dde_get_pair(HGLOBAL shm
)
1959 EnterCriticalSection(&dde_crst
);
1960 for (i
= 0; i
< dde_num_alloc
; i
++)
1962 if (dde_pairs
[i
].server_hMem
== shm
)
1964 /* free this pair */
1965 dde_pairs
[i
].server_hMem
= 0;
1967 ret
= dde_pairs
[i
].client_hMem
;
1971 LeaveCriticalSection(&dde_crst
);
1975 /***********************************************************************
1978 * Post a DDE message
1980 static BOOL
post_dde_message( struct packed_message
*data
, const struct send_message_info
*info
)
1984 UINT_PTR uiLo
, uiHi
;
1986 HGLOBAL hunlock
= 0;
1990 if (!UnpackDDElParam( info
->msg
, info
->lparam
, &uiLo
, &uiHi
))
1996 /* DDE messages which don't require packing are:
2005 /* uiHi should contain a hMem from WM_DDE_EXECUTE */
2006 HGLOBAL h
= dde_get_pair( (HANDLE
)uiHi
);
2009 ULONGLONG hpack
= pack_ptr( h
);
2010 /* send back the value of h on the other side */
2011 push_data( data
, &hpack
, sizeof(hpack
) );
2013 TRACE( "send dde-ack %lx %08lx => %p\n", uiLo
, uiHi
, h
);
2018 /* uiHi should contain either an atom or 0 */
2019 TRACE( "send dde-ack %lx atom=%lx\n", uiLo
, uiHi
);
2020 lp
= MAKELONG( uiLo
, uiHi
);
2029 size
= GlobalSize( (HGLOBAL
)uiLo
) ;
2030 if ((info
->msg
== WM_DDE_ADVISE
&& size
< sizeof(DDEADVISE
)) ||
2031 (info
->msg
== WM_DDE_DATA
&& size
< FIELD_OFFSET(DDEDATA
, Value
)) ||
2032 (info
->msg
== WM_DDE_POKE
&& size
< FIELD_OFFSET(DDEPOKE
, Value
))
2036 else if (info
->msg
!= WM_DDE_DATA
) return FALSE
;
2041 if ((ptr
= GlobalLock( (HGLOBAL
)uiLo
) ))
2043 DDEDATA
*dde_data
= ptr
;
2044 TRACE("unused %d, fResponse %d, fRelease %d, fDeferUpd %d, fAckReq %d, cfFormat %d\n",
2045 dde_data
->unused
, dde_data
->fResponse
, dde_data
->fRelease
,
2046 dde_data
->reserved
, dde_data
->fAckReq
, dde_data
->cfFormat
);
2047 push_data( data
, ptr
, size
);
2048 hunlock
= (HGLOBAL
)uiLo
;
2051 TRACE( "send ddepack %u %lx\n", size
, uiHi
);
2053 case WM_DDE_EXECUTE
:
2056 if ((ptr
= GlobalLock( (HGLOBAL
)info
->lparam
) ))
2058 push_data(data
, ptr
, GlobalSize( (HGLOBAL
)info
->lparam
));
2059 /* so that the other side can send it back on ACK */
2061 hunlock
= (HGLOBAL
)info
->lparam
;
2066 SERVER_START_REQ( send_message
)
2068 req
->id
= info
->dest_tid
;
2069 req
->type
= info
->type
;
2071 req
->win
= wine_server_user_handle( info
->hwnd
);
2072 req
->msg
= info
->msg
;
2073 req
->wparam
= info
->wparam
;
2075 req
->timeout
= TIMEOUT_INFINITE
;
2076 for (i
= 0; i
< data
->count
; i
++)
2077 wine_server_add_data( req
, data
->data
[i
], data
->size
[i
] );
2078 if ((res
= wine_server_call( req
)))
2080 if (res
== STATUS_INVALID_PARAMETER
)
2081 /* FIXME: find a STATUS_ value for this one */
2082 SetLastError( ERROR_INVALID_THREAD_ID
);
2084 SetLastError( RtlNtStatusToDosError(res
) );
2087 FreeDDElParam(info
->msg
, info
->lparam
);
2090 if (hunlock
) GlobalUnlock(hunlock
);
2095 /***********************************************************************
2096 * unpack_dde_message
2098 * Unpack a posted DDE message received from another process.
2100 static BOOL
unpack_dde_message( HWND hwnd
, UINT message
, WPARAM
*wparam
, LPARAM
*lparam
,
2101 void **buffer
, size_t size
)
2103 UINT_PTR uiLo
, uiHi
;
2113 /* hMem is being passed */
2114 if (size
!= sizeof(hpack
)) return FALSE
;
2115 if (!buffer
|| !*buffer
) return FALSE
;
2117 memcpy( &hpack
, *buffer
, size
);
2118 hMem
= unpack_ptr( hpack
);
2119 uiHi
= (UINT_PTR
)hMem
;
2120 TRACE("recv dde-ack %lx mem=%lx[%lx]\n", uiLo
, uiHi
, GlobalSize( hMem
));
2124 uiLo
= LOWORD( *lparam
);
2125 uiHi
= HIWORD( *lparam
);
2126 TRACE("recv dde-ack %lx atom=%lx\n", uiLo
, uiHi
);
2128 *lparam
= PackDDElParam( WM_DDE_ACK
, uiLo
, uiHi
);
2133 if ((!buffer
|| !*buffer
) && message
!= WM_DDE_DATA
) return FALSE
;
2137 if (!(hMem
= GlobalAlloc( GMEM_MOVEABLE
|GMEM_DDESHARE
, size
)))
2139 if ((ptr
= GlobalLock( hMem
)))
2141 memcpy( ptr
, *buffer
, size
);
2142 GlobalUnlock( hMem
);
2150 uiLo
= (UINT_PTR
)hMem
;
2152 *lparam
= PackDDElParam( message
, uiLo
, uiHi
);
2154 case WM_DDE_EXECUTE
:
2157 if (!buffer
|| !*buffer
) return FALSE
;
2158 if (!(hMem
= GlobalAlloc( GMEM_MOVEABLE
|GMEM_DDESHARE
, size
))) return FALSE
;
2159 if ((ptr
= GlobalLock( hMem
)))
2161 memcpy( ptr
, *buffer
, size
);
2162 GlobalUnlock( hMem
);
2163 TRACE( "exec: pairing c=%08lx s=%p\n", *lparam
, hMem
);
2164 if (!dde_add_pair( (HGLOBAL
)*lparam
, hMem
))
2175 } else return FALSE
;
2176 *lparam
= (LPARAM
)hMem
;
2182 /***********************************************************************
2185 * Call a window procedure and the corresponding hooks.
2187 static LRESULT
call_window_proc( HWND hwnd
, UINT msg
, WPARAM wparam
, LPARAM lparam
,
2188 BOOL unicode
, BOOL same_thread
, enum wm_char_mapping mapping
)
2192 CWPRETSTRUCT cwpret
;
2194 if (msg
& 0x80000000)
2196 result
= handle_internal_message( hwnd
, msg
, wparam
, lparam
);
2200 /* first the WH_CALLWNDPROC hook */
2201 hwnd
= WIN_GetFullHandle( hwnd
);
2202 cwp
.lParam
= lparam
;
2203 cwp
.wParam
= wparam
;
2206 HOOK_CallHooks( WH_CALLWNDPROC
, HC_ACTION
, same_thread
, (LPARAM
)&cwp
, unicode
);
2208 /* now call the window procedure */
2209 if (!WINPROC_call_window( hwnd
, msg
, wparam
, lparam
, &result
, unicode
, mapping
)) goto done
;
2211 /* and finally the WH_CALLWNDPROCRET hook */
2212 cwpret
.lResult
= result
;
2213 cwpret
.lParam
= lparam
;
2214 cwpret
.wParam
= wparam
;
2215 cwpret
.message
= msg
;
2217 HOOK_CallHooks( WH_CALLWNDPROCRET
, HC_ACTION
, same_thread
, (LPARAM
)&cwpret
, unicode
);
2223 /***********************************************************************
2224 * send_parent_notify
2226 * Send a WM_PARENTNOTIFY to all ancestors of the given window, unless
2227 * the window has the WS_EX_NOPARENTNOTIFY style.
2229 static void send_parent_notify( HWND hwnd
, WORD event
, WORD idChild
, POINT pt
)
2231 /* pt has to be in the client coordinates of the parent window */
2232 MapWindowPoints( 0, hwnd
, &pt
, 1 );
2237 if (!(GetWindowLongW( hwnd
, GWL_STYLE
) & WS_CHILD
)) break;
2238 if (GetWindowLongW( hwnd
, GWL_EXSTYLE
) & WS_EX_NOPARENTNOTIFY
) break;
2239 if (!(parent
= GetParent(hwnd
))) break;
2240 if (parent
== GetDesktopWindow()) break;
2241 MapWindowPoints( hwnd
, parent
, &pt
, 1 );
2243 SendMessageW( hwnd
, WM_PARENTNOTIFY
,
2244 MAKEWPARAM( event
, idChild
), MAKELPARAM( pt
.x
, pt
.y
) );
2249 /***********************************************************************
2250 * accept_hardware_message
2252 * Tell the server we have passed the message to the app
2253 * (even though we may end up dropping it later on)
2255 static void accept_hardware_message( UINT hw_id
, BOOL remove
, HWND new_hwnd
)
2257 SERVER_START_REQ( accept_hardware_message
)
2260 req
->remove
= remove
;
2261 req
->new_win
= wine_server_user_handle( new_hwnd
);
2262 if (wine_server_call( req
))
2263 FIXME("Failed to reply to MSG_HARDWARE message. Message may not be removed from queue.\n");
2269 static BOOL
process_rawinput_message( MSG
*msg
, const struct hardware_msg_data
*msg_data
)
2271 struct user_thread_info
*thread_info
= get_user_thread_info();
2272 RAWINPUT
*rawinput
= thread_info
->rawinput
;
2276 thread_info
->rawinput
= HeapAlloc( GetProcessHeap(), 0, sizeof(*rawinput
) );
2277 if (!(rawinput
= thread_info
->rawinput
)) return FALSE
;
2280 rawinput
->header
.dwType
= msg_data
->rawinput
.type
;
2281 if (msg_data
->rawinput
.type
== RIM_TYPEMOUSE
)
2283 static const unsigned int button_flags
[] =
2285 0, /* MOUSEEVENTF_MOVE */
2286 RI_MOUSE_LEFT_BUTTON_DOWN
, /* MOUSEEVENTF_LEFTDOWN */
2287 RI_MOUSE_LEFT_BUTTON_UP
, /* MOUSEEVENTF_LEFTUP */
2288 RI_MOUSE_RIGHT_BUTTON_DOWN
, /* MOUSEEVENTF_RIGHTDOWN */
2289 RI_MOUSE_RIGHT_BUTTON_UP
, /* MOUSEEVENTF_RIGHTUP */
2290 RI_MOUSE_MIDDLE_BUTTON_DOWN
, /* MOUSEEVENTF_MIDDLEDOWN */
2291 RI_MOUSE_MIDDLE_BUTTON_UP
, /* MOUSEEVENTF_MIDDLEUP */
2295 rawinput
->header
.dwSize
= FIELD_OFFSET(RAWINPUT
, data
) + sizeof(RAWMOUSE
);
2296 rawinput
->header
.hDevice
= WINE_MOUSE_HANDLE
;
2297 rawinput
->header
.wParam
= 0;
2299 rawinput
->data
.mouse
.usFlags
= MOUSE_MOVE_RELATIVE
;
2300 rawinput
->data
.mouse
.u
.s
.usButtonFlags
= 0;
2301 rawinput
->data
.mouse
.u
.s
.usButtonData
= 0;
2302 for (i
= 1; i
< sizeof(button_flags
) / sizeof(*button_flags
); ++i
)
2304 if (msg_data
->flags
& (1 << i
))
2305 rawinput
->data
.mouse
.u
.s
.usButtonFlags
|= button_flags
[i
];
2307 if (msg_data
->flags
& MOUSEEVENTF_WHEEL
)
2309 rawinput
->data
.mouse
.u
.s
.usButtonFlags
|= RI_MOUSE_WHEEL
;
2310 rawinput
->data
.mouse
.u
.s
.usButtonData
= msg_data
->rawinput
.mouse
.data
;
2312 if (msg_data
->flags
& MOUSEEVENTF_HWHEEL
)
2314 rawinput
->data
.mouse
.u
.s
.usButtonFlags
|= RI_MOUSE_HORIZONTAL_WHEEL
;
2315 rawinput
->data
.mouse
.u
.s
.usButtonData
= msg_data
->rawinput
.mouse
.data
;
2317 if (msg_data
->flags
& MOUSEEVENTF_XDOWN
)
2319 if (msg_data
->rawinput
.mouse
.data
== XBUTTON1
)
2320 rawinput
->data
.mouse
.u
.s
.usButtonFlags
|= RI_MOUSE_BUTTON_4_DOWN
;
2321 else if (msg_data
->rawinput
.mouse
.data
== XBUTTON2
)
2322 rawinput
->data
.mouse
.u
.s
.usButtonFlags
|= RI_MOUSE_BUTTON_5_DOWN
;
2324 if (msg_data
->flags
& MOUSEEVENTF_XUP
)
2326 if (msg_data
->rawinput
.mouse
.data
== XBUTTON1
)
2327 rawinput
->data
.mouse
.u
.s
.usButtonFlags
|= RI_MOUSE_BUTTON_4_UP
;
2328 else if (msg_data
->rawinput
.mouse
.data
== XBUTTON2
)
2329 rawinput
->data
.mouse
.u
.s
.usButtonFlags
|= RI_MOUSE_BUTTON_5_UP
;
2332 rawinput
->data
.mouse
.ulRawButtons
= 0;
2333 rawinput
->data
.mouse
.lLastX
= msg_data
->rawinput
.mouse
.x
;
2334 rawinput
->data
.mouse
.lLastY
= msg_data
->rawinput
.mouse
.y
;
2335 rawinput
->data
.mouse
.ulExtraInformation
= msg_data
->info
;
2337 else if (msg_data
->rawinput
.type
== RIM_TYPEKEYBOARD
)
2339 rawinput
->header
.dwSize
= FIELD_OFFSET(RAWINPUT
, data
) + sizeof(RAWKEYBOARD
);
2340 rawinput
->header
.hDevice
= WINE_KEYBOARD_HANDLE
;
2341 rawinput
->header
.wParam
= 0;
2343 rawinput
->data
.keyboard
.MakeCode
= msg_data
->rawinput
.kbd
.scan
;
2344 rawinput
->data
.keyboard
.Flags
= msg_data
->flags
& KEYEVENTF_KEYUP
? RI_KEY_BREAK
: RI_KEY_MAKE
;
2345 if (msg_data
->flags
& KEYEVENTF_EXTENDEDKEY
) rawinput
->data
.keyboard
.Flags
|= RI_KEY_E0
;
2346 rawinput
->data
.keyboard
.Reserved
= 0;
2348 switch (msg_data
->rawinput
.kbd
.vkey
)
2352 rawinput
->data
.keyboard
.VKey
= VK_SHIFT
;
2353 rawinput
->data
.keyboard
.Flags
&= ~RI_KEY_E0
;
2357 rawinput
->data
.keyboard
.VKey
= VK_CONTROL
;
2361 rawinput
->data
.keyboard
.VKey
= VK_MENU
;
2364 rawinput
->data
.keyboard
.VKey
= msg_data
->rawinput
.kbd
.vkey
;
2368 rawinput
->data
.keyboard
.Message
= msg_data
->rawinput
.kbd
.message
;
2369 rawinput
->data
.keyboard
.ExtraInformation
= msg_data
->info
;
2373 FIXME("Unhandled rawinput type %#x.\n", msg_data
->rawinput
.type
);
2377 msg
->lParam
= (LPARAM
)rawinput
;
2381 /***********************************************************************
2382 * process_keyboard_message
2384 * returns TRUE if the contents of 'msg' should be passed to the application
2386 static BOOL
process_keyboard_message( MSG
*msg
, UINT hw_id
, HWND hwnd_filter
,
2387 UINT first
, UINT last
, BOOL remove
)
2391 if (msg
->message
== WM_KEYDOWN
|| msg
->message
== WM_SYSKEYDOWN
||
2392 msg
->message
== WM_KEYUP
|| msg
->message
== WM_SYSKEYUP
)
2393 switch (msg
->wParam
)
2395 case VK_LSHIFT
: case VK_RSHIFT
:
2396 msg
->wParam
= VK_SHIFT
;
2398 case VK_LCONTROL
: case VK_RCONTROL
:
2399 msg
->wParam
= VK_CONTROL
;
2401 case VK_LMENU
: case VK_RMENU
:
2402 msg
->wParam
= VK_MENU
;
2406 /* FIXME: is this really the right place for this hook? */
2407 event
.message
= msg
->message
;
2408 event
.hwnd
= msg
->hwnd
;
2409 event
.time
= msg
->time
;
2410 event
.paramL
= (msg
->wParam
& 0xFF) | (HIWORD(msg
->lParam
) << 8);
2411 event
.paramH
= msg
->lParam
& 0x7FFF;
2412 if (HIWORD(msg
->lParam
) & 0x0100) event
.paramH
|= 0x8000; /* special_key - bit */
2413 HOOK_CallHooks( WH_JOURNALRECORD
, HC_ACTION
, 0, (LPARAM
)&event
, TRUE
);
2415 /* check message filters */
2416 if (msg
->message
< first
|| msg
->message
> last
) return FALSE
;
2417 if (!check_hwnd_filter( msg
, hwnd_filter
)) return FALSE
;
2421 if((msg
->message
== WM_KEYDOWN
) &&
2422 (msg
->hwnd
!= GetDesktopWindow()))
2424 /* Handle F1 key by sending out WM_HELP message */
2425 if (msg
->wParam
== VK_F1
)
2427 PostMessageW( msg
->hwnd
, WM_KEYF1
, 0, 0 );
2429 else if(msg
->wParam
>= VK_BROWSER_BACK
&&
2430 msg
->wParam
<= VK_LAUNCH_APP2
)
2432 /* FIXME: Process keystate */
2433 SendMessageW(msg
->hwnd
, WM_APPCOMMAND
, (WPARAM
)msg
->hwnd
, MAKELPARAM(0, (FAPPCOMMAND_KEY
| (msg
->wParam
- VK_BROWSER_BACK
+ 1))));
2436 else if (msg
->message
== WM_KEYUP
)
2438 /* Handle VK_APPS key by posting a WM_CONTEXTMENU message */
2439 if (msg
->wParam
== VK_APPS
&& !MENU_IsMenuActive())
2440 PostMessageW(msg
->hwnd
, WM_CONTEXTMENU
, (WPARAM
)msg
->hwnd
, -1);
2444 if (HOOK_CallHooks( WH_KEYBOARD
, remove
? HC_ACTION
: HC_NOREMOVE
,
2445 LOWORD(msg
->wParam
), msg
->lParam
, TRUE
))
2447 /* skip this message */
2448 HOOK_CallHooks( WH_CBT
, HCBT_KEYSKIPPED
, LOWORD(msg
->wParam
), msg
->lParam
, TRUE
);
2449 accept_hardware_message( hw_id
, TRUE
, 0 );
2452 accept_hardware_message( hw_id
, remove
, 0 );
2454 if ( remove
&& msg
->message
== WM_KEYDOWN
)
2455 if (ImmProcessKey(msg
->hwnd
, GetKeyboardLayout(0), msg
->wParam
, msg
->lParam
, 0) )
2456 msg
->wParam
= VK_PROCESSKEY
;
2462 /***********************************************************************
2463 * process_mouse_message
2465 * returns TRUE if the contents of 'msg' should be passed to the application
2467 static BOOL
process_mouse_message( MSG
*msg
, UINT hw_id
, ULONG_PTR extra_info
, HWND hwnd_filter
,
2468 UINT first
, UINT last
, BOOL remove
)
2477 MOUSEHOOKSTRUCT hook
;
2480 /* find the window to dispatch this mouse message to */
2482 info
.cbSize
= sizeof(info
);
2483 GetGUIThreadInfo( GetCurrentThreadId(), &info
);
2484 if (info
.hwndCapture
)
2487 msg
->hwnd
= info
.hwndCapture
;
2491 msg
->hwnd
= WINPOS_WindowFromPoint( msg
->hwnd
, msg
->pt
, &hittest
);
2494 if (!msg
->hwnd
|| !WIN_IsCurrentThread( msg
->hwnd
))
2496 accept_hardware_message( hw_id
, TRUE
, msg
->hwnd
);
2500 /* FIXME: is this really the right place for this hook? */
2501 event
.message
= msg
->message
;
2502 event
.time
= msg
->time
;
2503 event
.hwnd
= msg
->hwnd
;
2504 event
.paramL
= msg
->pt
.x
;
2505 event
.paramH
= msg
->pt
.y
;
2506 HOOK_CallHooks( WH_JOURNALRECORD
, HC_ACTION
, 0, (LPARAM
)&event
, TRUE
);
2508 if (!check_hwnd_filter( msg
, hwnd_filter
)) return FALSE
;
2511 message
= msg
->message
;
2512 /* Note: windows has no concept of a non-client wheel message */
2513 if (message
!= WM_MOUSEWHEEL
)
2515 if (hittest
!= HTCLIENT
)
2517 message
+= WM_NCMOUSEMOVE
- WM_MOUSEMOVE
;
2518 msg
->wParam
= hittest
;
2522 /* coordinates don't get translated while tracking a menu */
2523 /* FIXME: should differentiate popups and top-level menus */
2524 if (!(info
.flags
& GUI_INMENUMODE
))
2525 ScreenToClient( msg
->hwnd
, &pt
);
2528 msg
->lParam
= MAKELONG( pt
.x
, pt
.y
);
2530 /* translate double clicks */
2532 if ((msg
->message
== WM_LBUTTONDOWN
) ||
2533 (msg
->message
== WM_RBUTTONDOWN
) ||
2534 (msg
->message
== WM_MBUTTONDOWN
) ||
2535 (msg
->message
== WM_XBUTTONDOWN
))
2537 BOOL update
= remove
;
2539 /* translate double clicks -
2540 * note that ...MOUSEMOVEs can slip in between
2541 * ...BUTTONDOWN and ...BUTTONDBLCLK messages */
2543 if ((info
.flags
& (GUI_INMENUMODE
|GUI_INMOVESIZE
)) ||
2544 hittest
!= HTCLIENT
||
2545 (GetClassLongA( msg
->hwnd
, GCL_STYLE
) & CS_DBLCLKS
))
2547 if ((msg
->message
== clk_msg
.message
) &&
2548 (msg
->hwnd
== clk_msg
.hwnd
) &&
2549 (msg
->wParam
== clk_msg
.wParam
) &&
2550 (msg
->time
- clk_msg
.time
< GetDoubleClickTime()) &&
2551 (abs(msg
->pt
.x
- clk_msg
.pt
.x
) < GetSystemMetrics(SM_CXDOUBLECLK
)/2) &&
2552 (abs(msg
->pt
.y
- clk_msg
.pt
.y
) < GetSystemMetrics(SM_CYDOUBLECLK
)/2))
2554 message
+= (WM_LBUTTONDBLCLK
- WM_LBUTTONDOWN
);
2557 clk_msg
.message
= 0; /* clear the double click conditions */
2562 if (message
< first
|| message
> last
) return FALSE
;
2563 /* update static double click conditions */
2564 if (update
) clk_msg
= *msg
;
2568 if (message
< first
|| message
> last
) return FALSE
;
2571 /* message is accepted now (but may still get dropped) */
2574 hook
.hwnd
= msg
->hwnd
;
2575 hook
.wHitTestCode
= hittest
;
2576 hook
.dwExtraInfo
= extra_info
;
2577 if (HOOK_CallHooks( WH_MOUSE
, remove
? HC_ACTION
: HC_NOREMOVE
,
2578 message
, (LPARAM
)&hook
, TRUE
))
2581 hook
.hwnd
= msg
->hwnd
;
2582 hook
.wHitTestCode
= hittest
;
2583 hook
.dwExtraInfo
= extra_info
;
2584 HOOK_CallHooks( WH_CBT
, HCBT_CLICKSKIPPED
, message
, (LPARAM
)&hook
, TRUE
);
2585 accept_hardware_message( hw_id
, TRUE
, 0 );
2589 if ((hittest
== HTERROR
) || (hittest
== HTNOWHERE
))
2591 SendMessageW( msg
->hwnd
, WM_SETCURSOR
, (WPARAM
)msg
->hwnd
,
2592 MAKELONG( hittest
, msg
->message
));
2593 accept_hardware_message( hw_id
, TRUE
, 0 );
2597 accept_hardware_message( hw_id
, remove
, 0 );
2599 if (!remove
|| info
.hwndCapture
)
2601 msg
->message
= message
;
2607 if ((msg
->message
== WM_LBUTTONDOWN
) ||
2608 (msg
->message
== WM_RBUTTONDOWN
) ||
2609 (msg
->message
== WM_MBUTTONDOWN
) ||
2610 (msg
->message
== WM_XBUTTONDOWN
))
2612 /* Send the WM_PARENTNOTIFY,
2613 * note that even for double/nonclient clicks
2614 * notification message is still WM_L/M/RBUTTONDOWN.
2616 send_parent_notify( msg
->hwnd
, msg
->message
, 0, msg
->pt
);
2618 /* Activate the window if needed */
2620 if (msg
->hwnd
!= info
.hwndActive
)
2622 HWND hwndTop
= msg
->hwnd
;
2625 if ((GetWindowLongW( hwndTop
, GWL_STYLE
) & (WS_POPUP
|WS_CHILD
)) != WS_CHILD
) break;
2626 hwndTop
= GetParent( hwndTop
);
2629 if (hwndTop
&& hwndTop
!= GetDesktopWindow())
2631 LONG ret
= SendMessageW( msg
->hwnd
, WM_MOUSEACTIVATE
, (WPARAM
)hwndTop
,
2632 MAKELONG( hittest
, msg
->message
) );
2635 case MA_NOACTIVATEANDEAT
:
2640 case MA_ACTIVATEANDEAT
:
2645 if (!FOCUS_MouseActivate( hwndTop
)) eatMsg
= TRUE
;
2648 WARN( "unknown WM_MOUSEACTIVATE code %d\n", ret
);
2655 /* send the WM_SETCURSOR message */
2657 /* Windows sends the normal mouse message as the message parameter
2658 in the WM_SETCURSOR message even if it's non-client mouse message */
2659 SendMessageW( msg
->hwnd
, WM_SETCURSOR
, (WPARAM
)msg
->hwnd
, MAKELONG( hittest
, msg
->message
));
2661 msg
->message
= message
;
2666 /***********************************************************************
2667 * process_hardware_message
2669 * Process a hardware message; return TRUE if message should be passed on to the app
2671 static BOOL
process_hardware_message( MSG
*msg
, UINT hw_id
, const struct hardware_msg_data
*msg_data
,
2672 HWND hwnd_filter
, UINT first
, UINT last
, BOOL remove
)
2674 if (msg
->message
== WM_INPUT
)
2675 return process_rawinput_message( msg
, msg_data
);
2677 if (is_keyboard_message( msg
->message
))
2678 return process_keyboard_message( msg
, hw_id
, hwnd_filter
, first
, last
, remove
);
2680 if (is_mouse_message( msg
->message
))
2681 return process_mouse_message( msg
, hw_id
, msg_data
->info
, hwnd_filter
, first
, last
, remove
);
2683 ERR( "unknown message type %x\n", msg
->message
);
2688 /***********************************************************************
2689 * call_sendmsg_callback
2691 * Call the callback function of SendMessageCallback.
2693 static inline void call_sendmsg_callback( SENDASYNCPROC callback
, HWND hwnd
, UINT msg
,
2694 ULONG_PTR data
, LRESULT result
)
2696 if (!callback
) return;
2698 if (TRACE_ON(relay
))
2699 DPRINTF( "%04x:Call message callback %p (hwnd=%p,msg=%s,data=%08lx,result=%08lx)\n",
2700 GetCurrentThreadId(), callback
, hwnd
, SPY_GetMsgName( msg
, hwnd
),
2702 callback( hwnd
, msg
, data
, result
);
2703 if (TRACE_ON(relay
))
2704 DPRINTF( "%04x:Ret message callback %p (hwnd=%p,msg=%s,data=%08lx,result=%08lx)\n",
2705 GetCurrentThreadId(), callback
, hwnd
, SPY_GetMsgName( msg
, hwnd
),
2710 /***********************************************************************
2713 * Peek for a message matching the given parameters. Return FALSE if none available.
2714 * All pending sent messages are processed before returning.
2716 static BOOL
peek_message( MSG
*msg
, HWND hwnd
, UINT first
, UINT last
, UINT flags
, UINT changed_mask
)
2719 struct user_thread_info
*thread_info
= get_user_thread_info();
2720 struct received_message_info info
, *old_info
;
2721 unsigned int hw_id
= 0; /* id of previous hardware message */
2723 size_t buffer_size
= 256;
2725 if (!(buffer
= HeapAlloc( GetProcessHeap(), 0, buffer_size
))) return FALSE
;
2727 if (!first
&& !last
) last
= ~0;
2728 if (hwnd
== HWND_BROADCAST
) hwnd
= HWND_TOPMOST
;
2734 const message_data_t
*msg_data
= buffer
;
2736 SERVER_START_REQ( get_message
)
2739 req
->get_win
= wine_server_user_handle( hwnd
);
2740 req
->get_first
= first
;
2741 req
->get_last
= last
;
2743 req
->wake_mask
= changed_mask
& (QS_SENDMESSAGE
| QS_SMRESULT
);
2744 req
->changed_mask
= changed_mask
;
2745 wine_server_set_reply( req
, buffer
, buffer_size
);
2746 if (!(res
= wine_server_call( req
)))
2748 size
= wine_server_reply_size( reply
);
2749 info
.type
= reply
->type
;
2750 info
.msg
.hwnd
= wine_server_ptr_handle( reply
->win
);
2751 info
.msg
.message
= reply
->msg
;
2752 info
.msg
.wParam
= reply
->wparam
;
2753 info
.msg
.lParam
= reply
->lparam
;
2754 info
.msg
.time
= reply
->time
;
2758 thread_info
->active_hooks
= reply
->active_hooks
;
2760 else buffer_size
= reply
->total
;
2766 HeapFree( GetProcessHeap(), 0, buffer
);
2767 if (res
!= STATUS_BUFFER_OVERFLOW
) return FALSE
;
2768 if (!(buffer
= HeapAlloc( GetProcessHeap(), 0, buffer_size
))) return FALSE
;
2772 TRACE( "got type %d msg %x (%s) hwnd %p wp %lx lp %lx\n",
2773 info
.type
, info
.msg
.message
,
2774 (info
.type
== MSG_WINEVENT
) ? "MSG_WINEVENT" : SPY_GetMsgName(info
.msg
.message
, info
.msg
.hwnd
),
2775 info
.msg
.hwnd
, info
.msg
.wParam
, info
.msg
.lParam
);
2781 info
.flags
= ISMEX_SEND
;
2784 info
.flags
= ISMEX_NOTIFY
;
2787 info
.flags
= ISMEX_CALLBACK
;
2789 case MSG_CALLBACK_RESULT
:
2790 if (size
>= sizeof(msg_data
->callback
))
2791 call_sendmsg_callback( wine_server_get_ptr(msg_data
->callback
.callback
),
2792 info
.msg
.hwnd
, info
.msg
.message
,
2793 msg_data
->callback
.data
, msg_data
->callback
.result
);
2796 if (size
>= sizeof(msg_data
->winevent
))
2798 WINEVENTPROC hook_proc
;
2800 hook_proc
= wine_server_get_ptr( msg_data
->winevent
.hook_proc
);
2801 size
-= sizeof(msg_data
->winevent
);
2804 WCHAR module
[MAX_PATH
];
2806 size
= min( size
, (MAX_PATH
- 1) * sizeof(WCHAR
) );
2807 memcpy( module
, &msg_data
->winevent
+ 1, size
);
2808 module
[size
/ sizeof(WCHAR
)] = 0;
2809 if (!(hook_proc
= get_hook_proc( hook_proc
, module
)))
2811 ERR( "invalid winevent hook module name %s\n", debugstr_w(module
) );
2816 if (TRACE_ON(relay
))
2817 DPRINTF( "%04x:Call winevent proc %p (hook=%04x,event=%x,hwnd=%p,object_id=%lx,child_id=%lx,tid=%04x,time=%x)\n",
2818 GetCurrentThreadId(), hook_proc
,
2819 msg_data
->winevent
.hook
, info
.msg
.message
, info
.msg
.hwnd
, info
.msg
.wParam
,
2820 info
.msg
.lParam
, msg_data
->winevent
.tid
, info
.msg
.time
);
2822 hook_proc( wine_server_ptr_handle( msg_data
->winevent
.hook
), info
.msg
.message
,
2823 info
.msg
.hwnd
, info
.msg
.wParam
, info
.msg
.lParam
,
2824 msg_data
->winevent
.tid
, info
.msg
.time
);
2826 if (TRACE_ON(relay
))
2827 DPRINTF( "%04x:Ret winevent proc %p (hook=%04x,event=%x,hwnd=%p,object_id=%lx,child_id=%lx,tid=%04x,time=%x)\n",
2828 GetCurrentThreadId(), hook_proc
,
2829 msg_data
->winevent
.hook
, info
.msg
.message
, info
.msg
.hwnd
, info
.msg
.wParam
,
2830 info
.msg
.lParam
, msg_data
->winevent
.tid
, info
.msg
.time
);
2834 info
.flags
= ISMEX_SEND
;
2836 if (info
.msg
.message
== WH_KEYBOARD_LL
&& size
>= sizeof(msg_data
->hardware
))
2838 KBDLLHOOKSTRUCT hook
;
2840 hook
.vkCode
= LOWORD( info
.msg
.lParam
);
2841 hook
.scanCode
= HIWORD( info
.msg
.lParam
);
2842 hook
.flags
= msg_data
->hardware
.flags
;
2843 hook
.time
= info
.msg
.time
;
2844 hook
.dwExtraInfo
= msg_data
->hardware
.info
;
2845 TRACE( "calling keyboard LL hook vk %x scan %x flags %x time %u info %lx\n",
2846 hook
.vkCode
, hook
.scanCode
, hook
.flags
, hook
.time
, hook
.dwExtraInfo
);
2847 result
= HOOK_CallHooks( WH_KEYBOARD_LL
, HC_ACTION
, info
.msg
.wParam
, (LPARAM
)&hook
, TRUE
);
2849 else if (info
.msg
.message
== WH_MOUSE_LL
&& size
>= sizeof(msg_data
->hardware
))
2851 MSLLHOOKSTRUCT hook
;
2853 hook
.pt
.x
= msg_data
->hardware
.x
;
2854 hook
.pt
.y
= msg_data
->hardware
.y
;
2855 hook
.mouseData
= info
.msg
.lParam
;
2856 hook
.flags
= msg_data
->hardware
.flags
;
2857 hook
.time
= info
.msg
.time
;
2858 hook
.dwExtraInfo
= msg_data
->hardware
.info
;
2859 TRACE( "calling mouse LL hook pos %d,%d data %x flags %x time %u info %lx\n",
2860 hook
.pt
.x
, hook
.pt
.y
, hook
.mouseData
, hook
.flags
, hook
.time
, hook
.dwExtraInfo
);
2861 result
= HOOK_CallHooks( WH_MOUSE_LL
, HC_ACTION
, info
.msg
.wParam
, (LPARAM
)&hook
, TRUE
);
2863 reply_message( &info
, result
, TRUE
);
2865 case MSG_OTHER_PROCESS
:
2866 info
.flags
= ISMEX_SEND
;
2867 if (!unpack_message( info
.msg
.hwnd
, info
.msg
.message
, &info
.msg
.wParam
,
2868 &info
.msg
.lParam
, &buffer
, size
))
2871 reply_message( &info
, 0, TRUE
);
2876 if (size
>= sizeof(msg_data
->hardware
))
2878 info
.msg
.pt
.x
= msg_data
->hardware
.x
;
2879 info
.msg
.pt
.y
= msg_data
->hardware
.y
;
2880 hw_id
= msg_data
->hardware
.hw_id
;
2881 if (!process_hardware_message( &info
.msg
, hw_id
, &msg_data
->hardware
,
2882 hwnd
, first
, last
, flags
& PM_REMOVE
))
2884 TRACE("dropping msg %x\n", info
.msg
.message
);
2885 continue; /* ignore it */
2888 thread_info
->GetMessagePosVal
= MAKELONG( info
.msg
.pt
.x
, info
.msg
.pt
.y
);
2889 thread_info
->GetMessageTimeVal
= info
.msg
.time
;
2890 thread_info
->GetMessageExtraInfoVal
= msg_data
->hardware
.info
;
2891 HeapFree( GetProcessHeap(), 0, buffer
);
2892 HOOK_CallHooks( WH_GETMESSAGE
, HC_ACTION
, flags
& PM_REMOVE
, (LPARAM
)msg
, TRUE
);
2897 if (info
.msg
.message
& 0x80000000) /* internal message */
2899 if (flags
& PM_REMOVE
)
2901 handle_internal_message( info
.msg
.hwnd
, info
.msg
.message
,
2902 info
.msg
.wParam
, info
.msg
.lParam
);
2903 /* if this is a nested call return right away */
2904 if (first
== info
.msg
.message
&& last
== info
.msg
.message
)
2906 HeapFree( GetProcessHeap(), 0, buffer
);
2911 peek_message( msg
, info
.msg
.hwnd
, info
.msg
.message
,
2912 info
.msg
.message
, flags
| PM_REMOVE
, changed_mask
);
2915 if (info
.msg
.message
>= WM_DDE_FIRST
&& info
.msg
.message
<= WM_DDE_LAST
)
2917 if (!unpack_dde_message( info
.msg
.hwnd
, info
.msg
.message
, &info
.msg
.wParam
,
2918 &info
.msg
.lParam
, &buffer
, size
))
2919 continue; /* ignore it */
2922 msg
->pt
.x
= (short)LOWORD( thread_info
->GetMessagePosVal
);
2923 msg
->pt
.y
= (short)HIWORD( thread_info
->GetMessagePosVal
);
2924 thread_info
->GetMessageTimeVal
= info
.msg
.time
;
2925 thread_info
->GetMessageExtraInfoVal
= 0;
2926 HeapFree( GetProcessHeap(), 0, buffer
);
2927 HOOK_CallHooks( WH_GETMESSAGE
, HC_ACTION
, flags
& PM_REMOVE
, (LPARAM
)msg
, TRUE
);
2931 /* if we get here, we have a sent message; call the window procedure */
2932 old_info
= thread_info
->receive_info
;
2933 thread_info
->receive_info
= &info
;
2934 result
= call_window_proc( info
.msg
.hwnd
, info
.msg
.message
, info
.msg
.wParam
,
2935 info
.msg
.lParam
, (info
.type
!= MSG_ASCII
), FALSE
,
2936 WMCHAR_MAP_RECVMESSAGE
);
2937 reply_message( &info
, result
, TRUE
);
2938 thread_info
->receive_info
= old_info
;
2940 /* if some PM_QS* flags were specified, only handle sent messages from now on */
2941 if (HIWORD(flags
) && !changed_mask
) flags
= PM_QS_SENDMESSAGE
| LOWORD(flags
);
2946 /***********************************************************************
2947 * process_sent_messages
2949 * Process all pending sent messages.
2951 static inline void process_sent_messages(void)
2954 peek_message( &msg
, 0, 0, 0, PM_REMOVE
| PM_QS_SENDMESSAGE
, 0 );
2958 /***********************************************************************
2959 * get_server_queue_handle
2961 * Get a handle to the server message queue for the current thread.
2963 static HANDLE
get_server_queue_handle(void)
2965 struct user_thread_info
*thread_info
= get_user_thread_info();
2968 if (!(ret
= thread_info
->server_queue
))
2970 SERVER_START_REQ( get_msg_queue
)
2972 wine_server_call( req
);
2973 ret
= wine_server_ptr_handle( reply
->handle
);
2976 thread_info
->server_queue
= ret
;
2977 if (!ret
) ERR( "Cannot get server thread queue\n" );
2983 /***********************************************************************
2984 * wait_message_reply
2986 * Wait until a sent message gets replied to.
2988 static void wait_message_reply( UINT flags
)
2990 HANDLE server_queue
= get_server_queue_handle();
2994 unsigned int wake_bits
= 0;
2996 SERVER_START_REQ( set_queue_mask
)
2998 req
->wake_mask
= QS_SMRESULT
| ((flags
& SMTO_BLOCK
) ? 0 : QS_SENDMESSAGE
);
2999 req
->changed_mask
= req
->wake_mask
;
3001 if (!wine_server_call( req
))
3002 wake_bits
= reply
->wake_bits
;
3006 if (wake_bits
& QS_SMRESULT
) return; /* got a result */
3007 if (wake_bits
& QS_SENDMESSAGE
)
3009 /* Process the sent message immediately */
3010 process_sent_messages();
3014 wow_handlers
.wait_message( 1, &server_queue
, INFINITE
, QS_SENDMESSAGE
, 0 );
3018 /***********************************************************************
3019 * put_message_in_queue
3021 * Put a sent message into the destination queue.
3022 * For inter-process message, reply_size is set to expected size of reply data.
3024 static BOOL
put_message_in_queue( const struct send_message_info
*info
, size_t *reply_size
)
3026 struct packed_message data
;
3027 message_data_t msg_data
;
3030 timeout_t timeout
= TIMEOUT_INFINITE
;
3032 /* Check for INFINITE timeout for compatibility with Win9x,
3033 * although Windows >= NT does not do so
3035 if (info
->type
!= MSG_NOTIFY
&&
3036 info
->type
!= MSG_CALLBACK
&&
3037 info
->type
!= MSG_POSTED
&&
3039 info
->timeout
!= INFINITE
)
3041 /* timeout is signed despite the prototype */
3042 timeout
= (timeout_t
)max( 0, (int)info
->timeout
) * -10000;
3045 memset( &data
, 0, sizeof(data
) );
3046 if (info
->type
== MSG_OTHER_PROCESS
)
3048 *reply_size
= pack_message( info
->hwnd
, info
->msg
, info
->wparam
, info
->lparam
, &data
);
3049 if (data
.count
== -1)
3051 WARN( "cannot pack message %x\n", info
->msg
);
3055 else if (info
->type
== MSG_CALLBACK
)
3057 msg_data
.callback
.callback
= wine_server_client_ptr( info
->callback
);
3058 msg_data
.callback
.data
= info
->data
;
3059 msg_data
.callback
.result
= 0;
3060 data
.data
[0] = &msg_data
;
3061 data
.size
[0] = sizeof(msg_data
.callback
);
3064 else if (info
->type
== MSG_POSTED
&& info
->msg
>= WM_DDE_FIRST
&& info
->msg
<= WM_DDE_LAST
)
3066 return post_dde_message( &data
, info
);
3069 SERVER_START_REQ( send_message
)
3071 req
->id
= info
->dest_tid
;
3072 req
->type
= info
->type
;
3074 req
->win
= wine_server_user_handle( info
->hwnd
);
3075 req
->msg
= info
->msg
;
3076 req
->wparam
= info
->wparam
;
3077 req
->lparam
= info
->lparam
;
3078 req
->timeout
= timeout
;
3080 if (info
->flags
& SMTO_ABORTIFHUNG
) req
->flags
|= SEND_MSG_ABORT_IF_HUNG
;
3081 for (i
= 0; i
< data
.count
; i
++) wine_server_add_data( req
, data
.data
[i
], data
.size
[i
] );
3082 if ((res
= wine_server_call( req
)))
3084 if (res
== STATUS_INVALID_PARAMETER
)
3085 /* FIXME: find a STATUS_ value for this one */
3086 SetLastError( ERROR_INVALID_THREAD_ID
);
3088 SetLastError( RtlNtStatusToDosError(res
) );
3096 /***********************************************************************
3099 * Retrieve a message reply from the server.
3101 static LRESULT
retrieve_reply( const struct send_message_info
*info
,
3102 size_t reply_size
, LRESULT
*result
)
3105 void *reply_data
= NULL
;
3109 if (!(reply_data
= HeapAlloc( GetProcessHeap(), 0, reply_size
)))
3111 WARN( "no memory for reply, will be truncated\n" );
3115 SERVER_START_REQ( get_message_reply
)
3118 if (reply_size
) wine_server_set_reply( req
, reply_data
, reply_size
);
3119 if (!(status
= wine_server_call( req
))) *result
= reply
->result
;
3120 reply_size
= wine_server_reply_size( reply
);
3123 if (!status
&& reply_size
)
3124 unpack_reply( info
->hwnd
, info
->msg
, info
->wparam
, info
->lparam
, reply_data
, reply_size
);
3126 HeapFree( GetProcessHeap(), 0, reply_data
);
3128 TRACE( "hwnd %p msg %x (%s) wp %lx lp %lx got reply %lx (err=%d)\n",
3129 info
->hwnd
, info
->msg
, SPY_GetMsgName(info
->msg
, info
->hwnd
), info
->wparam
,
3130 info
->lparam
, *result
, status
);
3132 /* MSDN states that last error is 0 on timeout, but at least NT4 returns ERROR_TIMEOUT */
3133 if (status
) SetLastError( RtlNtStatusToDosError(status
) );
3138 /***********************************************************************
3139 * send_inter_thread_message
3141 static LRESULT
send_inter_thread_message( const struct send_message_info
*info
, LRESULT
*res_ptr
)
3143 size_t reply_size
= 0;
3145 TRACE( "hwnd %p msg %x (%s) wp %lx lp %lx\n",
3146 info
->hwnd
, info
->msg
, SPY_GetMsgName(info
->msg
, info
->hwnd
), info
->wparam
, info
->lparam
);
3148 USER_CheckNotLock();
3150 if (!put_message_in_queue( info
, &reply_size
)) return 0;
3152 /* there's no reply to wait for on notify/callback messages */
3153 if (info
->type
== MSG_NOTIFY
|| info
->type
== MSG_CALLBACK
) return 1;
3155 wait_message_reply( info
->flags
);
3156 return retrieve_reply( info
, reply_size
, res_ptr
);
3160 /***********************************************************************
3161 * send_inter_thread_callback
3163 static LRESULT
send_inter_thread_callback( HWND hwnd
, UINT msg
, WPARAM wp
, LPARAM lp
,
3164 LRESULT
*result
, void *arg
)
3166 struct send_message_info
*info
= arg
;
3171 return send_inter_thread_message( info
, result
);
3175 /***********************************************************************
3178 * Backend implementation of the various SendMessage functions.
3180 static BOOL
send_message( struct send_message_info
*info
, DWORD_PTR
*res_ptr
, BOOL unicode
)
3186 if (is_broadcast(info
->hwnd
))
3188 EnumWindows( broadcast_message_callback
, (LPARAM
)info
);
3189 if (res_ptr
) *res_ptr
= 1;
3193 if (!(info
->dest_tid
= GetWindowThreadProcessId( info
->hwnd
, &dest_pid
))) return FALSE
;
3195 if (USER_IsExitingThread( info
->dest_tid
)) return FALSE
;
3197 SPY_EnterMessage( SPY_SENDMESSAGE
, info
->hwnd
, info
->msg
, info
->wparam
, info
->lparam
);
3199 if (info
->dest_tid
== GetCurrentThreadId())
3201 result
= call_window_proc( info
->hwnd
, info
->msg
, info
->wparam
, info
->lparam
,
3202 unicode
, TRUE
, info
->wm_char
);
3203 if (info
->type
== MSG_CALLBACK
)
3204 call_sendmsg_callback( info
->callback
, info
->hwnd
, info
->msg
, info
->data
, result
);
3209 if (dest_pid
!= GetCurrentProcessId() && (info
->type
== MSG_ASCII
|| info
->type
== MSG_UNICODE
))
3210 info
->type
= MSG_OTHER_PROCESS
;
3212 /* MSG_ASCII can be sent unconverted except for WM_CHAR; everything else needs to be Unicode */
3213 if (!unicode
&& is_unicode_message( info
->msg
) &&
3214 (info
->type
!= MSG_ASCII
|| info
->msg
== WM_CHAR
))
3215 ret
= WINPROC_CallProcAtoW( send_inter_thread_callback
, info
->hwnd
, info
->msg
,
3216 info
->wparam
, info
->lparam
, &result
, info
, info
->wm_char
);
3218 ret
= send_inter_thread_message( info
, &result
);
3221 SPY_ExitMessage( SPY_RESULT_OK
, info
->hwnd
, info
->msg
, result
, info
->wparam
, info
->lparam
);
3222 if (ret
&& res_ptr
) *res_ptr
= result
;
3227 /***********************************************************************
3228 * send_hardware_message
3230 NTSTATUS
send_hardware_message( HWND hwnd
, const INPUT
*input
, UINT flags
)
3232 struct user_thread_info
*thread_info
= get_user_thread_info();
3233 struct send_message_info info
;
3234 int prev_x
, prev_y
, new_x
, new_y
;
3238 info
.type
= MSG_HARDWARE
;
3244 SERVER_START_REQ( send_hardware_message
)
3246 req
->win
= wine_server_user_handle( hwnd
);
3248 req
->input
.type
= input
->type
;
3249 switch (input
->type
)
3252 req
->input
.mouse
.x
= input
->u
.mi
.dx
;
3253 req
->input
.mouse
.y
= input
->u
.mi
.dy
;
3254 req
->input
.mouse
.data
= input
->u
.mi
.mouseData
;
3255 req
->input
.mouse
.flags
= input
->u
.mi
.dwFlags
;
3256 req
->input
.mouse
.time
= input
->u
.mi
.time
;
3257 req
->input
.mouse
.info
= input
->u
.mi
.dwExtraInfo
;
3259 case INPUT_KEYBOARD
:
3260 req
->input
.kbd
.vkey
= input
->u
.ki
.wVk
;
3261 req
->input
.kbd
.scan
= input
->u
.ki
.wScan
;
3262 req
->input
.kbd
.flags
= input
->u
.ki
.dwFlags
;
3263 req
->input
.kbd
.time
= input
->u
.ki
.time
;
3264 req
->input
.kbd
.info
= input
->u
.ki
.dwExtraInfo
;
3266 case INPUT_HARDWARE
:
3267 req
->input
.hw
.msg
= input
->u
.hi
.uMsg
;
3268 req
->input
.hw
.lparam
= MAKELONG( input
->u
.hi
.wParamL
, input
->u
.hi
.wParamH
);
3271 if (thread_info
->key_state
) wine_server_set_reply( req
, thread_info
->key_state
, 256 );
3272 ret
= wine_server_call( req
);
3274 prev_x
= reply
->prev_x
;
3275 prev_y
= reply
->prev_y
;
3276 new_x
= reply
->new_x
;
3277 new_y
= reply
->new_y
;
3283 if (thread_info
->key_state
) thread_info
->key_state_time
= GetTickCount();
3284 if ((flags
& SEND_HWMSG_INJECTED
) && (prev_x
!= new_x
|| prev_y
!= new_y
))
3285 USER_Driver
->pSetCursorPos( new_x
, new_y
);
3291 wait_message_reply( 0 );
3292 retrieve_reply( &info
, 0, &ignored
);
3298 /***********************************************************************
3299 * MSG_SendInternalMessageTimeout
3301 * Same as SendMessageTimeoutW but sends the message to a specific thread
3302 * without requiring a window handle. Only works for internal Wine messages.
3304 LRESULT
MSG_SendInternalMessageTimeout( DWORD dest_pid
, DWORD dest_tid
,
3305 UINT msg
, WPARAM wparam
, LPARAM lparam
,
3306 UINT flags
, UINT timeout
, PDWORD_PTR res_ptr
)
3308 struct send_message_info info
;
3309 LRESULT ret
, result
;
3311 assert( msg
& 0x80000000 ); /* must be an internal Wine message */
3313 info
.type
= MSG_UNICODE
;
3314 info
.dest_tid
= dest_tid
;
3317 info
.wparam
= wparam
;
3318 info
.lparam
= lparam
;
3320 info
.timeout
= timeout
;
3322 if (USER_IsExitingThread( dest_tid
)) return 0;
3324 if (dest_tid
== GetCurrentThreadId())
3326 result
= handle_internal_message( 0, msg
, wparam
, lparam
);
3331 if (dest_pid
!= GetCurrentProcessId()) info
.type
= MSG_OTHER_PROCESS
;
3332 ret
= send_inter_thread_message( &info
, &result
);
3334 if (ret
&& res_ptr
) *res_ptr
= result
;
3339 /***********************************************************************
3340 * SendMessageTimeoutW (USER32.@)
3342 LRESULT WINAPI
SendMessageTimeoutW( HWND hwnd
, UINT msg
, WPARAM wparam
, LPARAM lparam
,
3343 UINT flags
, UINT timeout
, PDWORD_PTR res_ptr
)
3345 struct send_message_info info
;
3347 info
.type
= MSG_UNICODE
;
3350 info
.wparam
= wparam
;
3351 info
.lparam
= lparam
;
3353 info
.timeout
= timeout
;
3355 return send_message( &info
, res_ptr
, TRUE
);
3358 /***********************************************************************
3359 * SendMessageTimeoutA (USER32.@)
3361 LRESULT WINAPI
SendMessageTimeoutA( HWND hwnd
, UINT msg
, WPARAM wparam
, LPARAM lparam
,
3362 UINT flags
, UINT timeout
, PDWORD_PTR res_ptr
)
3364 struct send_message_info info
;
3366 info
.type
= MSG_ASCII
;
3369 info
.wparam
= wparam
;
3370 info
.lparam
= lparam
;
3372 info
.timeout
= timeout
;
3373 info
.wm_char
= WMCHAR_MAP_SENDMESSAGETIMEOUT
;
3375 return send_message( &info
, res_ptr
, FALSE
);
3379 /***********************************************************************
3380 * SendMessageW (USER32.@)
3382 LRESULT WINAPI
SendMessageW( HWND hwnd
, UINT msg
, WPARAM wparam
, LPARAM lparam
)
3385 struct send_message_info info
;
3387 info
.type
= MSG_UNICODE
;
3390 info
.wparam
= wparam
;
3391 info
.lparam
= lparam
;
3392 info
.flags
= SMTO_NORMAL
;
3395 send_message( &info
, &res
, TRUE
);
3400 /***********************************************************************
3401 * SendMessageA (USER32.@)
3403 LRESULT WINAPI
SendMessageA( HWND hwnd
, UINT msg
, WPARAM wparam
, LPARAM lparam
)
3406 struct send_message_info info
;
3408 info
.type
= MSG_ASCII
;
3411 info
.wparam
= wparam
;
3412 info
.lparam
= lparam
;
3413 info
.flags
= SMTO_NORMAL
;
3415 info
.wm_char
= WMCHAR_MAP_SENDMESSAGE
;
3417 send_message( &info
, &res
, FALSE
);
3422 /***********************************************************************
3423 * SendNotifyMessageA (USER32.@)
3425 BOOL WINAPI
SendNotifyMessageA( HWND hwnd
, UINT msg
, WPARAM wparam
, LPARAM lparam
)
3427 struct send_message_info info
;
3429 if (is_pointer_message(msg
))
3431 SetLastError( ERROR_MESSAGE_SYNC_ONLY
);
3435 info
.type
= MSG_NOTIFY
;
3438 info
.wparam
= wparam
;
3439 info
.lparam
= lparam
;
3441 info
.wm_char
= WMCHAR_MAP_SENDMESSAGETIMEOUT
;
3443 return send_message( &info
, NULL
, FALSE
);
3447 /***********************************************************************
3448 * SendNotifyMessageW (USER32.@)
3450 BOOL WINAPI
SendNotifyMessageW( HWND hwnd
, UINT msg
, WPARAM wparam
, LPARAM lparam
)
3452 struct send_message_info info
;
3454 if (is_pointer_message(msg
))
3456 SetLastError( ERROR_MESSAGE_SYNC_ONLY
);
3460 info
.type
= MSG_NOTIFY
;
3463 info
.wparam
= wparam
;
3464 info
.lparam
= lparam
;
3467 return send_message( &info
, NULL
, TRUE
);
3471 /***********************************************************************
3472 * SendMessageCallbackA (USER32.@)
3474 BOOL WINAPI
SendMessageCallbackA( HWND hwnd
, UINT msg
, WPARAM wparam
, LPARAM lparam
,
3475 SENDASYNCPROC callback
, ULONG_PTR data
)
3477 struct send_message_info info
;
3479 if (is_pointer_message(msg
))
3481 SetLastError( ERROR_MESSAGE_SYNC_ONLY
);
3485 info
.type
= MSG_CALLBACK
;
3488 info
.wparam
= wparam
;
3489 info
.lparam
= lparam
;
3490 info
.callback
= callback
;
3493 info
.wm_char
= WMCHAR_MAP_SENDMESSAGETIMEOUT
;
3495 return send_message( &info
, NULL
, FALSE
);
3499 /***********************************************************************
3500 * SendMessageCallbackW (USER32.@)
3502 BOOL WINAPI
SendMessageCallbackW( HWND hwnd
, UINT msg
, WPARAM wparam
, LPARAM lparam
,
3503 SENDASYNCPROC callback
, ULONG_PTR data
)
3505 struct send_message_info info
;
3507 if (is_pointer_message(msg
))
3509 SetLastError( ERROR_MESSAGE_SYNC_ONLY
);
3513 info
.type
= MSG_CALLBACK
;
3516 info
.wparam
= wparam
;
3517 info
.lparam
= lparam
;
3518 info
.callback
= callback
;
3522 return send_message( &info
, NULL
, TRUE
);
3526 /***********************************************************************
3527 * ReplyMessage (USER32.@)
3529 BOOL WINAPI
ReplyMessage( LRESULT result
)
3531 struct received_message_info
*info
= get_user_thread_info()->receive_info
;
3533 if (!info
) return FALSE
;
3534 reply_message( info
, result
, FALSE
);
3539 /***********************************************************************
3540 * InSendMessage (USER32.@)
3542 BOOL WINAPI
InSendMessage(void)
3544 return (InSendMessageEx(NULL
) & (ISMEX_SEND
|ISMEX_REPLIED
)) == ISMEX_SEND
;
3548 /***********************************************************************
3549 * InSendMessageEx (USER32.@)
3551 DWORD WINAPI
InSendMessageEx( LPVOID reserved
)
3553 struct received_message_info
*info
= get_user_thread_info()->receive_info
;
3555 if (info
) return info
->flags
;
3556 return ISMEX_NOSEND
;
3560 /***********************************************************************
3561 * PostMessageA (USER32.@)
3563 BOOL WINAPI
PostMessageA( HWND hwnd
, UINT msg
, WPARAM wparam
, LPARAM lparam
)
3565 if (!map_wparam_AtoW( msg
, &wparam
, WMCHAR_MAP_POSTMESSAGE
)) return TRUE
;
3566 return PostMessageW( hwnd
, msg
, wparam
, lparam
);
3570 /***********************************************************************
3571 * PostMessageW (USER32.@)
3573 BOOL WINAPI
PostMessageW( HWND hwnd
, UINT msg
, WPARAM wparam
, LPARAM lparam
)
3575 struct send_message_info info
;
3577 if (is_pointer_message( msg
))
3579 SetLastError( ERROR_MESSAGE_SYNC_ONLY
);
3583 TRACE( "hwnd %p msg %x (%s) wp %lx lp %lx\n",
3584 hwnd
, msg
, SPY_GetMsgName(msg
, hwnd
), wparam
, lparam
);
3586 info
.type
= MSG_POSTED
;
3589 info
.wparam
= wparam
;
3590 info
.lparam
= lparam
;
3593 if (is_broadcast(hwnd
))
3595 EnumWindows( broadcast_message_callback
, (LPARAM
)&info
);
3599 if (!hwnd
) return PostThreadMessageW( GetCurrentThreadId(), msg
, wparam
, lparam
);
3601 if (!(info
.dest_tid
= GetWindowThreadProcessId( hwnd
, NULL
))) return FALSE
;
3603 if (USER_IsExitingThread( info
.dest_tid
)) return TRUE
;
3605 return put_message_in_queue( &info
, NULL
);
3609 /**********************************************************************
3610 * PostThreadMessageA (USER32.@)
3612 BOOL WINAPI
PostThreadMessageA( DWORD thread
, UINT msg
, WPARAM wparam
, LPARAM lparam
)
3614 if (!map_wparam_AtoW( msg
, &wparam
, WMCHAR_MAP_POSTMESSAGE
)) return TRUE
;
3615 return PostThreadMessageW( thread
, msg
, wparam
, lparam
);
3619 /**********************************************************************
3620 * PostThreadMessageW (USER32.@)
3622 BOOL WINAPI
PostThreadMessageW( DWORD thread
, UINT msg
, WPARAM wparam
, LPARAM lparam
)
3624 struct send_message_info info
;
3626 if (is_pointer_message( msg
))
3628 SetLastError( ERROR_MESSAGE_SYNC_ONLY
);
3631 if (USER_IsExitingThread( thread
)) return TRUE
;
3633 info
.type
= MSG_POSTED
;
3634 info
.dest_tid
= thread
;
3637 info
.wparam
= wparam
;
3638 info
.lparam
= lparam
;
3640 return put_message_in_queue( &info
, NULL
);
3644 /***********************************************************************
3645 * PostQuitMessage (USER32.@)
3647 * Posts a quit message to the current thread's message queue.
3650 * exit_code [I] Exit code to return from message loop.
3656 * This function is not the same as calling:
3657 *|PostThreadMessage(GetCurrentThreadId(), WM_QUIT, exit_code, 0);
3658 * It instead sets a flag in the message queue that signals it to generate
3659 * a WM_QUIT message when there are no other pending sent or posted messages
3662 void WINAPI
PostQuitMessage( INT exit_code
)
3664 SERVER_START_REQ( post_quit_message
)
3666 req
->exit_code
= exit_code
;
3667 wine_server_call( req
);
3672 /* check for driver events if we detect that the app is not properly consuming messages */
3673 static inline void check_for_driver_events(void)
3675 if (get_user_thread_info()->message_count
> 200)
3677 flush_window_surfaces( FALSE
);
3678 USER_Driver
->pMsgWaitForMultipleObjectsEx( 0, NULL
, 0, QS_ALLINPUT
, 0 );
3680 else get_user_thread_info()->message_count
++;
3683 /***********************************************************************
3684 * PeekMessageW (USER32.@)
3686 BOOL WINAPI DECLSPEC_HOTPATCH
PeekMessageW( MSG
*msg_out
, HWND hwnd
, UINT first
, UINT last
, UINT flags
)
3690 USER_CheckNotLock();
3691 check_for_driver_events();
3693 if (!peek_message( &msg
, hwnd
, first
, last
, flags
, 0 ))
3697 flush_window_surfaces( TRUE
);
3698 ret
= wow_handlers
.wait_message( 0, NULL
, 0, QS_ALLINPUT
, 0 );
3699 /* if we received driver events, check again for a pending message */
3700 if (ret
== WAIT_TIMEOUT
|| !peek_message( &msg
, hwnd
, first
, last
, flags
, 0 )) return FALSE
;
3703 /* copy back our internal safe copy of message data to msg_out.
3704 * msg_out is a variable from the *program*, so it can't be used
3705 * internally as it can get "corrupted" by our use of SendMessage()
3706 * (back to the program) inside the message handling itself. */
3709 SetLastError( ERROR_NOACCESS
);
3717 /***********************************************************************
3718 * PeekMessageA (USER32.@)
3720 BOOL WINAPI DECLSPEC_HOTPATCH
PeekMessageA( MSG
*msg
, HWND hwnd
, UINT first
, UINT last
, UINT flags
)
3722 if (get_pending_wmchar( msg
, first
, last
, (flags
& PM_REMOVE
) )) return TRUE
;
3723 if (!PeekMessageW( msg
, hwnd
, first
, last
, flags
)) return FALSE
;
3724 map_wparam_WtoA( msg
, (flags
& PM_REMOVE
) );
3729 /***********************************************************************
3730 * GetMessageW (USER32.@)
3732 BOOL WINAPI DECLSPEC_HOTPATCH
GetMessageW( MSG
*msg
, HWND hwnd
, UINT first
, UINT last
)
3734 HANDLE server_queue
= get_server_queue_handle();
3735 unsigned int mask
= QS_POSTMESSAGE
| QS_SENDMESSAGE
; /* Always selected */
3737 USER_CheckNotLock();
3738 check_for_driver_events();
3742 if ((first
<= WM_KEYLAST
) && (last
>= WM_KEYFIRST
)) mask
|= QS_KEY
;
3743 if ( ((first
<= WM_MOUSELAST
) && (last
>= WM_MOUSEFIRST
)) ||
3744 ((first
<= WM_NCMOUSELAST
) && (last
>= WM_NCMOUSEFIRST
)) ) mask
|= QS_MOUSE
;
3745 if ((first
<= WM_TIMER
) && (last
>= WM_TIMER
)) mask
|= QS_TIMER
;
3746 if ((first
<= WM_SYSTIMER
) && (last
>= WM_SYSTIMER
)) mask
|= QS_TIMER
;
3747 if ((first
<= WM_PAINT
) && (last
>= WM_PAINT
)) mask
|= QS_PAINT
;
3749 else mask
= QS_ALLINPUT
;
3751 while (!peek_message( msg
, hwnd
, first
, last
, PM_REMOVE
| (mask
<< 16), mask
))
3753 flush_window_surfaces( TRUE
);
3754 wow_handlers
.wait_message( 1, &server_queue
, INFINITE
, mask
, 0 );
3757 return (msg
->message
!= WM_QUIT
);
3761 /***********************************************************************
3762 * GetMessageA (USER32.@)
3764 BOOL WINAPI DECLSPEC_HOTPATCH
GetMessageA( MSG
*msg
, HWND hwnd
, UINT first
, UINT last
)
3766 if (get_pending_wmchar( msg
, first
, last
, TRUE
)) return TRUE
;
3767 GetMessageW( msg
, hwnd
, first
, last
);
3768 map_wparam_WtoA( msg
, TRUE
);
3769 return (msg
->message
!= WM_QUIT
);
3773 /***********************************************************************
3774 * IsDialogMessageA (USER32.@)
3775 * IsDialogMessage (USER32.@)
3777 BOOL WINAPI
IsDialogMessageA( HWND hwndDlg
, LPMSG pmsg
)
3780 map_wparam_AtoW( msg
.message
, &msg
.wParam
, WMCHAR_MAP_NOMAPPING
);
3781 return IsDialogMessageW( hwndDlg
, &msg
);
3785 /***********************************************************************
3786 * TranslateMessage (USER32.@)
3788 * Implementation of TranslateMessage.
3790 * TranslateMessage translates virtual-key messages into character-messages,
3792 * WM_KEYDOWN/WM_KEYUP combinations produce a WM_CHAR or WM_DEADCHAR message.
3793 * ditto replacing WM_* with WM_SYS*
3794 * This produces WM_CHAR messages only for keys mapped to ASCII characters
3795 * by the keyboard driver.
3797 * If the message is WM_KEYDOWN, WM_KEYUP, WM_SYSKEYDOWN, or WM_SYSKEYUP, the
3798 * return value is nonzero, regardless of the translation.
3801 BOOL WINAPI
TranslateMessage( const MSG
*msg
)
3808 if (msg
->message
< WM_KEYFIRST
|| msg
->message
> WM_KEYLAST
) return FALSE
;
3809 if (msg
->message
!= WM_KEYDOWN
&& msg
->message
!= WM_SYSKEYDOWN
) return TRUE
;
3811 TRACE_(key
)("Translating key %s (%04lX), scancode %04x\n",
3812 SPY_GetVKeyName(msg
->wParam
), msg
->wParam
, HIWORD(msg
->lParam
));
3814 switch (msg
->wParam
)
3817 message
= (msg
->message
== WM_KEYDOWN
) ? WM_CHAR
: WM_SYSCHAR
;
3818 TRACE_(key
)("PostMessageW(%p,%s,%04x,%08x)\n",
3819 msg
->hwnd
, SPY_GetMsgName(message
, msg
->hwnd
), HIWORD(msg
->lParam
), LOWORD(msg
->lParam
));
3820 PostMessageW( msg
->hwnd
, message
, HIWORD(msg
->lParam
), LOWORD(msg
->lParam
));
3824 return ImmTranslateMessage(msg
->hwnd
, msg
->message
, msg
->wParam
, msg
->lParam
);
3827 GetKeyboardState( state
);
3828 len
= ToUnicode(msg
->wParam
, HIWORD(msg
->lParam
), state
, wp
, sizeof(wp
)/sizeof(WCHAR
), 0);
3831 message
= (msg
->message
== WM_KEYDOWN
) ? WM_DEADCHAR
: WM_SYSDEADCHAR
;
3832 TRACE_(key
)("-1 -> PostMessageW(%p,%s,%04x,%08lx)\n",
3833 msg
->hwnd
, SPY_GetMsgName(message
, msg
->hwnd
), wp
[0], msg
->lParam
);
3834 PostMessageW( msg
->hwnd
, message
, wp
[0], msg
->lParam
);
3840 message
= (msg
->message
== WM_KEYDOWN
) ? WM_CHAR
: WM_SYSCHAR
;
3841 TRACE_(key
)("%d -> PostMessageW(%p,%s,<x>,%08lx) for <x> in %s\n", len
, msg
->hwnd
,
3842 SPY_GetMsgName(message
, msg
->hwnd
), msg
->lParam
, debugstr_wn(wp
, len
));
3843 for (i
= 0; i
< len
; i
++)
3844 PostMessageW( msg
->hwnd
, message
, wp
[i
], msg
->lParam
);
3850 /***********************************************************************
3851 * DispatchMessageA (USER32.@)
3853 * See DispatchMessageW.
3855 LRESULT WINAPI DECLSPEC_HOTPATCH
DispatchMessageA( const MSG
* msg
)
3859 /* Process timer messages */
3860 if ((msg
->message
== WM_TIMER
) || (msg
->message
== WM_SYSTIMER
))
3866 retval
= CallWindowProcA( (WNDPROC
)msg
->lParam
, msg
->hwnd
,
3867 msg
->message
, msg
->wParam
, GetTickCount() );
3877 if (!msg
->hwnd
) return 0;
3879 SPY_EnterMessage( SPY_DISPATCHMESSAGE
, msg
->hwnd
, msg
->message
,
3880 msg
->wParam
, msg
->lParam
);
3882 if (!WINPROC_call_window( msg
->hwnd
, msg
->message
, msg
->wParam
, msg
->lParam
,
3883 &retval
, FALSE
, WMCHAR_MAP_DISPATCHMESSAGE
))
3885 if (!IsWindow( msg
->hwnd
)) SetLastError( ERROR_INVALID_WINDOW_HANDLE
);
3886 else SetLastError( ERROR_MESSAGE_SYNC_ONLY
);
3890 SPY_ExitMessage( SPY_RESULT_OK
, msg
->hwnd
, msg
->message
, retval
,
3891 msg
->wParam
, msg
->lParam
);
3893 if (msg
->message
== WM_PAINT
)
3895 /* send a WM_NCPAINT and WM_ERASEBKGND if the non-client area is still invalid */
3896 HRGN hrgn
= CreateRectRgn( 0, 0, 0, 0 );
3897 GetUpdateRgn( msg
->hwnd
, hrgn
, TRUE
);
3898 DeleteObject( hrgn
);
3904 /***********************************************************************
3905 * DispatchMessageW (USER32.@) Process a message
3907 * Process the message specified in the structure *_msg_.
3909 * If the lpMsg parameter points to a WM_TIMER message and the
3910 * parameter of the WM_TIMER message is not NULL, the lParam parameter
3911 * points to the function that is called instead of the window
3912 * procedure. The function stored in lParam (timer callback) is protected
3913 * from causing page-faults.
3915 * The message must be valid.
3919 * DispatchMessage() returns the result of the window procedure invoked.
3926 LRESULT WINAPI DECLSPEC_HOTPATCH
DispatchMessageW( const MSG
* msg
)
3930 /* Process timer messages */
3931 if ((msg
->message
== WM_TIMER
) || (msg
->message
== WM_SYSTIMER
))
3937 retval
= CallWindowProcW( (WNDPROC
)msg
->lParam
, msg
->hwnd
,
3938 msg
->message
, msg
->wParam
, GetTickCount() );
3948 if (!msg
->hwnd
) return 0;
3950 SPY_EnterMessage( SPY_DISPATCHMESSAGE
, msg
->hwnd
, msg
->message
,
3951 msg
->wParam
, msg
->lParam
);
3953 if (!WINPROC_call_window( msg
->hwnd
, msg
->message
, msg
->wParam
, msg
->lParam
,
3954 &retval
, TRUE
, WMCHAR_MAP_DISPATCHMESSAGE
))
3956 if (!IsWindow( msg
->hwnd
)) SetLastError( ERROR_INVALID_WINDOW_HANDLE
);
3957 else SetLastError( ERROR_MESSAGE_SYNC_ONLY
);
3961 SPY_ExitMessage( SPY_RESULT_OK
, msg
->hwnd
, msg
->message
, retval
,
3962 msg
->wParam
, msg
->lParam
);
3964 if (msg
->message
== WM_PAINT
)
3966 /* send a WM_NCPAINT and WM_ERASEBKGND if the non-client area is still invalid */
3967 HRGN hrgn
= CreateRectRgn( 0, 0, 0, 0 );
3968 GetUpdateRgn( msg
->hwnd
, hrgn
, TRUE
);
3969 DeleteObject( hrgn
);
3975 /***********************************************************************
3976 * GetMessagePos (USER.119)
3977 * GetMessagePos (USER32.@)
3979 * The GetMessagePos() function returns a long value representing a
3980 * cursor position, in screen coordinates, when the last message
3981 * retrieved by the GetMessage() function occurs. The x-coordinate is
3982 * in the low-order word of the return value, the y-coordinate is in
3983 * the high-order word. The application can use the MAKEPOINT()
3984 * macro to obtain a POINT structure from the return value.
3986 * For the current cursor position, use GetCursorPos().
3990 * Cursor position of last message on success, zero on failure.
3997 DWORD WINAPI
GetMessagePos(void)
3999 return get_user_thread_info()->GetMessagePosVal
;
4003 /***********************************************************************
4004 * GetMessageTime (USER.120)
4005 * GetMessageTime (USER32.@)
4007 * GetMessageTime() returns the message time for the last message
4008 * retrieved by the function. The time is measured in milliseconds with
4009 * the same offset as GetTickCount().
4011 * Since the tick count wraps, this is only useful for moderately short
4012 * relative time comparisons.
4016 * Time of last message on success, zero on failure.
4018 LONG WINAPI
GetMessageTime(void)
4020 return get_user_thread_info()->GetMessageTimeVal
;
4024 /***********************************************************************
4025 * GetMessageExtraInfo (USER.288)
4026 * GetMessageExtraInfo (USER32.@)
4028 LPARAM WINAPI
GetMessageExtraInfo(void)
4030 return get_user_thread_info()->GetMessageExtraInfoVal
;
4034 /***********************************************************************
4035 * SetMessageExtraInfo (USER32.@)
4037 LPARAM WINAPI
SetMessageExtraInfo(LPARAM lParam
)
4039 struct user_thread_info
*thread_info
= get_user_thread_info();
4040 LONG old_value
= thread_info
->GetMessageExtraInfoVal
;
4041 thread_info
->GetMessageExtraInfoVal
= lParam
;
4046 /***********************************************************************
4047 * WaitMessage (USER.112) Suspend thread pending messages
4048 * WaitMessage (USER32.@) Suspend thread pending messages
4050 * WaitMessage() suspends a thread until events appear in the thread's
4053 BOOL WINAPI
WaitMessage(void)
4055 return (MsgWaitForMultipleObjectsEx( 0, NULL
, INFINITE
, QS_ALLINPUT
, 0 ) != WAIT_FAILED
);
4059 /***********************************************************************
4060 * MsgWaitForMultipleObjectsEx (USER32.@)
4062 DWORD WINAPI
MsgWaitForMultipleObjectsEx( DWORD count
, CONST HANDLE
*pHandles
,
4063 DWORD timeout
, DWORD mask
, DWORD flags
)
4065 HANDLE handles
[MAXIMUM_WAIT_OBJECTS
];
4068 if (count
> MAXIMUM_WAIT_OBJECTS
-1)
4070 SetLastError( ERROR_INVALID_PARAMETER
);
4074 /* set the queue mask */
4075 SERVER_START_REQ( set_queue_mask
)
4077 req
->wake_mask
= (flags
& MWMO_INPUTAVAILABLE
) ? mask
: 0;
4078 req
->changed_mask
= mask
;
4080 wine_server_call( req
);
4084 /* add the queue to the handle list */
4085 for (i
= 0; i
< count
; i
++) handles
[i
] = pHandles
[i
];
4086 handles
[count
] = get_server_queue_handle();
4088 flush_window_surfaces( TRUE
);
4089 return wow_handlers
.wait_message( count
+1, handles
, timeout
, mask
, flags
);
4093 /***********************************************************************
4094 * MsgWaitForMultipleObjects (USER32.@)
4096 DWORD WINAPI
MsgWaitForMultipleObjects( DWORD count
, CONST HANDLE
*handles
,
4097 BOOL wait_all
, DWORD timeout
, DWORD mask
)
4099 return MsgWaitForMultipleObjectsEx( count
, handles
, timeout
, mask
,
4100 wait_all
? MWMO_WAITALL
: 0 );
4104 /***********************************************************************
4105 * WaitForInputIdle (USER32.@)
4107 DWORD WINAPI
WaitForInputIdle( HANDLE hProcess
, DWORD dwTimeOut
)
4109 DWORD start_time
, elapsed
, ret
;
4112 handles
[0] = hProcess
;
4113 SERVER_START_REQ( get_process_idle_event
)
4115 req
->handle
= wine_server_obj_handle( hProcess
);
4116 wine_server_call_err( req
);
4117 handles
[1] = wine_server_ptr_handle( reply
->event
);
4120 if (!handles
[1]) return WAIT_FAILED
; /* no event to wait on */
4122 start_time
= GetTickCount();
4125 TRACE("waiting for %p\n", handles
[1] );
4128 ret
= MsgWaitForMultipleObjects ( 2, handles
, FALSE
, dwTimeOut
- elapsed
, QS_SENDMESSAGE
);
4133 case WAIT_OBJECT_0
+2:
4134 process_sent_messages();
4138 TRACE("timeout or error\n");
4141 TRACE("finished\n");
4144 if (dwTimeOut
!= INFINITE
)
4146 elapsed
= GetTickCount() - start_time
;
4147 if (elapsed
> dwTimeOut
)
4153 return WAIT_TIMEOUT
;
4157 /***********************************************************************
4158 * RegisterWindowMessageA (USER32.@)
4159 * RegisterWindowMessage (USER.118)
4161 UINT WINAPI
RegisterWindowMessageA( LPCSTR str
)
4163 UINT ret
= GlobalAddAtomA(str
);
4164 TRACE("%s, ret=%x\n", str
, ret
);
4169 /***********************************************************************
4170 * RegisterWindowMessageW (USER32.@)
4172 UINT WINAPI
RegisterWindowMessageW( LPCWSTR str
)
4174 UINT ret
= GlobalAddAtomW(str
);
4175 TRACE("%s ret=%x\n", debugstr_w(str
), ret
);
4179 typedef struct BroadcastParm
4190 static BOOL CALLBACK
bcast_childwindow( HWND hw
, LPARAM lp
)
4192 BroadcastParm
*parm
= (BroadcastParm
*)lp
;
4193 DWORD_PTR retval
= 0;
4196 if (parm
->flags
& BSF_IGNORECURRENTTASK
&& WIN_IsCurrentProcess(hw
))
4198 TRACE("Not telling myself %p\n", hw
);
4202 /* I don't know 100% for sure if this is what Windows does, but it fits the tests */
4203 if (parm
->flags
& BSF_QUERY
)
4205 TRACE("Telling window %p using SendMessageTimeout\n", hw
);
4207 /* Not tested for conflicting flags */
4208 if (parm
->flags
& BSF_FORCEIFHUNG
|| parm
->flags
& BSF_NOHANG
)
4209 lresult
= SendMessageTimeoutW( hw
, parm
->msg
, parm
->wp
, parm
->lp
, SMTO_ABORTIFHUNG
, 2000, &retval
);
4210 else if (parm
->flags
& BSF_NOTIMEOUTIFNOTHUNG
)
4211 lresult
= SendMessageTimeoutW( hw
, parm
->msg
, parm
->wp
, parm
->lp
, SMTO_NOTIMEOUTIFNOTHUNG
, 2000, &retval
);
4213 lresult
= SendMessageTimeoutW( hw
, parm
->msg
, parm
->wp
, parm
->lp
, SMTO_NORMAL
, 2000, &retval
);
4215 if (!lresult
&& GetLastError() == ERROR_TIMEOUT
)
4217 WARN("Timed out!\n");
4218 if (!(parm
->flags
& BSF_FORCEIFHUNG
))
4221 if (retval
== BROADCAST_QUERY_DENY
)
4230 else if (parm
->flags
& BSF_POSTMESSAGE
)
4232 TRACE("Telling window %p using PostMessage\n", hw
);
4233 PostMessageW( hw
, parm
->msg
, parm
->wp
, parm
->lp
);
4237 TRACE("Telling window %p using SendNotifyMessage\n", hw
);
4238 SendNotifyMessageW( hw
, parm
->msg
, parm
->wp
, parm
->lp
);
4244 static BOOL CALLBACK
bcast_desktop( LPWSTR desktop
, LPARAM lp
)
4248 BroadcastParm
*parm
= (BroadcastParm
*)lp
;
4250 TRACE("desktop: %s\n", debugstr_w( desktop
));
4252 hdesktop
= open_winstation_desktop( parm
->winsta
, desktop
, 0, FALSE
, DESKTOP_ENUMERATE
|DESKTOP_WRITEOBJECTS
|STANDARD_RIGHTS_WRITE
);
4255 FIXME("Could not open desktop %s\n", debugstr_w(desktop
));
4259 ret
= EnumDesktopWindows( hdesktop
, bcast_childwindow
, lp
);
4260 CloseDesktop(hdesktop
);
4261 TRACE("-->%d\n", ret
);
4262 return parm
->success
;
4265 static BOOL CALLBACK
bcast_winsta( LPWSTR winsta
, LPARAM lp
)
4268 HWINSTA hwinsta
= OpenWindowStationW( winsta
, FALSE
, WINSTA_ENUMDESKTOPS
);
4269 TRACE("hwinsta: %p/%s/%08x\n", hwinsta
, debugstr_w( winsta
), GetLastError());
4272 ((BroadcastParm
*)lp
)->winsta
= hwinsta
;
4273 ret
= EnumDesktopsW( hwinsta
, bcast_desktop
, lp
);
4274 CloseWindowStation( hwinsta
);
4275 TRACE("-->%d\n", ret
);
4279 /***********************************************************************
4280 * BroadcastSystemMessageA (USER32.@)
4281 * BroadcastSystemMessage (USER32.@)
4283 LONG WINAPI
BroadcastSystemMessageA( DWORD flags
, LPDWORD recipients
, UINT msg
, WPARAM wp
, LPARAM lp
)
4285 return BroadcastSystemMessageExA( flags
, recipients
, msg
, wp
, lp
, NULL
);
4289 /***********************************************************************
4290 * BroadcastSystemMessageW (USER32.@)
4292 LONG WINAPI
BroadcastSystemMessageW( DWORD flags
, LPDWORD recipients
, UINT msg
, WPARAM wp
, LPARAM lp
)
4294 return BroadcastSystemMessageExW( flags
, recipients
, msg
, wp
, lp
, NULL
);
4297 /***********************************************************************
4298 * BroadcastSystemMessageExA (USER32.@)
4300 LONG WINAPI
BroadcastSystemMessageExA( DWORD flags
, LPDWORD recipients
, UINT msg
, WPARAM wp
, LPARAM lp
, PBSMINFO pinfo
)
4302 map_wparam_AtoW( msg
, &wp
, WMCHAR_MAP_NOMAPPING
);
4303 return BroadcastSystemMessageExW( flags
, recipients
, msg
, wp
, lp
, NULL
);
4307 /***********************************************************************
4308 * BroadcastSystemMessageExW (USER32.@)
4310 LONG WINAPI
BroadcastSystemMessageExW( DWORD flags
, LPDWORD recipients
, UINT msg
, WPARAM wp
, LPARAM lp
, PBSMINFO pinfo
)
4313 DWORD recips
= BSM_ALLCOMPONENTS
;
4315 static const DWORD all_flags
= ( BSF_QUERY
| BSF_IGNORECURRENTTASK
| BSF_FLUSHDISK
| BSF_NOHANG
4316 | BSF_POSTMESSAGE
| BSF_FORCEIFHUNG
| BSF_NOTIMEOUTIFNOTHUNG
4317 | BSF_ALLOWSFW
| BSF_SENDNOTIFYMESSAGE
| BSF_RETURNHDESK
| BSF_LUID
);
4319 TRACE("Flags: %08x, recipients: %p(0x%x), msg: %04x, wparam: %08lx, lparam: %08lx\n", flags
, recipients
,
4320 (recipients
? *recipients
: recips
), msg
, wp
, lp
);
4322 if (flags
& ~all_flags
)
4324 SetLastError(ERROR_INVALID_PARAMETER
);
4329 recipients
= &recips
;
4331 if ( pinfo
&& flags
& BSF_QUERY
)
4332 FIXME("Not returning PBSMINFO information yet\n");
4335 parm
.recipients
= recipients
;
4339 parm
.success
= TRUE
;
4341 if (*recipients
& BSM_ALLDESKTOPS
|| *recipients
== BSM_ALLCOMPONENTS
)
4342 ret
= EnumWindowStationsW(bcast_winsta
, (LONG_PTR
)&parm
);
4343 else if (*recipients
& BSM_APPLICATIONS
)
4345 EnumWindows(bcast_childwindow
, (LONG_PTR
)&parm
);
4349 FIXME("Recipients %08x not supported!\n", *recipients
);
4354 /***********************************************************************
4355 * SetMessageQueue (USER32.@)
4357 BOOL WINAPI
SetMessageQueue( INT size
)
4359 /* now obsolete the message queue will be expanded dynamically as necessary */
4364 /***********************************************************************
4365 * MessageBeep (USER32.@)
4367 BOOL WINAPI
MessageBeep( UINT i
)
4370 SystemParametersInfoA( SPI_GETBEEP
, 0, &active
, FALSE
);
4371 if (active
) USER_Driver
->pBeep();
4376 /***********************************************************************
4377 * SetTimer (USER32.@)
4379 UINT_PTR WINAPI
SetTimer( HWND hwnd
, UINT_PTR id
, UINT timeout
, TIMERPROC proc
)
4382 WNDPROC winproc
= 0;
4384 if (proc
) winproc
= WINPROC_AllocProc( (WNDPROC
)proc
, FALSE
);
4386 /* MSDN states that the minimum timeout should be USER_TIMER_MINIMUM (10.0 ms), but testing
4387 * indicates that the true minimum is closer to 15.6 ms. */
4388 timeout
= min( max( 15, timeout
), USER_TIMER_MAXIMUM
);
4390 SERVER_START_REQ( set_win_timer
)
4392 req
->win
= wine_server_user_handle( hwnd
);
4393 req
->msg
= WM_TIMER
;
4395 req
->rate
= timeout
;
4396 req
->lparam
= (ULONG_PTR
)winproc
;
4397 if (!wine_server_call_err( req
))
4400 if (!ret
) ret
= TRUE
;
4406 TRACE("Added %p %lx %p timeout %d\n", hwnd
, id
, winproc
, timeout
);
4411 /***********************************************************************
4412 * SetSystemTimer (USER32.@)
4414 UINT_PTR WINAPI
SetSystemTimer( HWND hwnd
, UINT_PTR id
, UINT timeout
, TIMERPROC proc
)
4417 WNDPROC winproc
= 0;
4419 if (proc
) winproc
= WINPROC_AllocProc( (WNDPROC
)proc
, FALSE
);
4421 /* MSDN states that the minimum timeout should be USER_TIMER_MINIMUM (10.0 ms), but testing
4422 * indicates that the true minimum is closer to 15.6 ms. */
4423 timeout
= min( max( 15, timeout
), USER_TIMER_MAXIMUM
);
4425 SERVER_START_REQ( set_win_timer
)
4427 req
->win
= wine_server_user_handle( hwnd
);
4428 req
->msg
= WM_SYSTIMER
;
4430 req
->rate
= timeout
;
4431 req
->lparam
= (ULONG_PTR
)winproc
;
4432 if (!wine_server_call_err( req
))
4435 if (!ret
) ret
= TRUE
;
4441 TRACE("Added %p %lx %p timeout %d\n", hwnd
, id
, winproc
, timeout
);
4446 /***********************************************************************
4447 * KillTimer (USER32.@)
4449 BOOL WINAPI
KillTimer( HWND hwnd
, UINT_PTR id
)
4453 SERVER_START_REQ( kill_win_timer
)
4455 req
->win
= wine_server_user_handle( hwnd
);
4456 req
->msg
= WM_TIMER
;
4458 ret
= !wine_server_call_err( req
);
4465 /***********************************************************************
4466 * KillSystemTimer (USER32.@)
4468 BOOL WINAPI
KillSystemTimer( HWND hwnd
, UINT_PTR id
)
4472 SERVER_START_REQ( kill_win_timer
)
4474 req
->win
= wine_server_user_handle( hwnd
);
4475 req
->msg
= WM_SYSTIMER
;
4477 ret
= !wine_server_call_err( req
);
4484 /**********************************************************************
4485 * IsGUIThread (USER32.@)
4487 BOOL WINAPI
IsGUIThread( BOOL convert
)
4489 FIXME( "%u: stub\n", convert
);
4494 /**********************************************************************
4495 * GetGUIThreadInfo (USER32.@)
4497 BOOL WINAPI
GetGUIThreadInfo( DWORD id
, GUITHREADINFO
*info
)
4501 if (info
->cbSize
!= sizeof(*info
))
4503 SetLastError( ERROR_INVALID_PARAMETER
);
4507 SERVER_START_REQ( get_thread_input
)
4510 if ((ret
= !wine_server_call_err( req
)))
4513 info
->hwndActive
= wine_server_ptr_handle( reply
->active
);
4514 info
->hwndFocus
= wine_server_ptr_handle( reply
->focus
);
4515 info
->hwndCapture
= wine_server_ptr_handle( reply
->capture
);
4516 info
->hwndMenuOwner
= wine_server_ptr_handle( reply
->menu_owner
);
4517 info
->hwndMoveSize
= wine_server_ptr_handle( reply
->move_size
);
4518 info
->hwndCaret
= wine_server_ptr_handle( reply
->caret
);
4519 info
->rcCaret
.left
= reply
->rect
.left
;
4520 info
->rcCaret
.top
= reply
->rect
.top
;
4521 info
->rcCaret
.right
= reply
->rect
.right
;
4522 info
->rcCaret
.bottom
= reply
->rect
.bottom
;
4523 if (reply
->menu_owner
) info
->flags
|= GUI_INMENUMODE
;
4524 if (reply
->move_size
) info
->flags
|= GUI_INMOVESIZE
;
4525 if (reply
->caret
) info
->flags
|= GUI_CARETBLINKING
;
4533 /******************************************************************
4534 * IsHungAppWindow (USER32.@)
4537 BOOL WINAPI
IsHungAppWindow( HWND hWnd
)
4541 SERVER_START_REQ( is_window_hung
)
4543 req
->win
= wine_server_user_handle( hWnd
);
4544 ret
= !wine_server_call_err( req
) && reply
->is_hung
;
4550 /******************************************************************
4551 * ChangeWindowMessageFilter (USER32.@)
4553 BOOL WINAPI
ChangeWindowMessageFilter( UINT message
, DWORD flag
)
4555 FIXME( "%x %08x\n", message
, flag
);