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 */
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
) | SET(WM_HELP
),
315 SET(WM_STYLECHANGING
) | SET(WM_STYLECHANGED
),
317 SET(WM_NCCREATE
) | SET(WM_NCCALCSIZE
) | SET(WM_GETDLGCODE
),
319 SET(EM_GETSEL
) | SET(EM_GETRECT
) | SET(EM_SETRECT
) | SET(EM_SETRECTNP
),
321 SET(EM_REPLACESEL
) | SET(EM_GETLINE
) | SET(EM_SETTABSTOPS
),
323 SET(SBM_GETRANGE
) | SET(SBM_SETSCROLLINFO
) | SET(SBM_GETSCROLLINFO
) | SET(SBM_GETSCROLLBARINFO
),
329 SET(CB_GETEDITSEL
) | SET(CB_ADDSTRING
) | SET(CB_DIR
) | SET(CB_GETLBTEXT
) |
330 SET(CB_INSERTSTRING
) | SET(CB_FINDSTRING
) | SET(CB_SELECTSTRING
) |
331 SET(CB_GETDROPPEDCONTROLRECT
) | SET(CB_FINDSTRINGEXACT
),
335 SET(LB_ADDSTRING
) | SET(LB_INSERTSTRING
) | SET(LB_GETTEXT
) | SET(LB_SELECTSTRING
) |
336 SET(LB_DIR
) | SET(LB_FINDSTRING
) |
337 SET(LB_GETSELITEMS
) | SET(LB_SETTABSTOPS
) | SET(LB_ADDFILE
) | SET(LB_GETITEMRECT
),
339 SET(LB_FINDSTRINGEXACT
),
345 SET(WM_NEXTMENU
) | SET(WM_SIZING
) | SET(WM_MOVING
) | SET(WM_DEVICECHANGE
),
347 SET(WM_MDICREATE
) | SET(WM_MDIGETACTIVE
) | SET(WM_DROPOBJECT
) |
348 SET(WM_QUERYDROPOBJECT
) | SET(WM_DRAGLOOP
) | SET(WM_DRAGSELECT
) | SET(WM_DRAGMOVE
),
362 SET(WM_ASKCBFORMATNAME
)
365 /* flags for messages that contain Unicode strings */
366 static const unsigned int message_unicode_flags
[] =
369 SET(WM_CREATE
) | SET(WM_SETTEXT
) | SET(WM_GETTEXT
) | SET(WM_GETTEXTLENGTH
) |
370 SET(WM_WININICHANGE
) | SET(WM_DEVMODECHANGE
),
382 SET(EM_REPLACESEL
) | SET(EM_GETLINE
) | SET(EM_SETPASSWORDCHAR
),
386 SET(WM_CHAR
) | SET(WM_DEADCHAR
) | SET(WM_SYSCHAR
) | SET(WM_SYSDEADCHAR
),
390 SET(CB_ADDSTRING
) | SET(CB_DIR
) | SET(CB_GETLBTEXT
) | SET(CB_GETLBTEXTLEN
) |
391 SET(CB_INSERTSTRING
) | SET(CB_FINDSTRING
) | SET(CB_SELECTSTRING
) | SET(CB_FINDSTRINGEXACT
),
395 SET(LB_ADDSTRING
) | SET(LB_INSERTSTRING
) | SET(LB_GETTEXT
) | SET(LB_GETTEXTLEN
) |
396 SET(LB_SELECTSTRING
) | SET(LB_DIR
) | SET(LB_FINDSTRING
) | SET(LB_ADDFILE
),
398 SET(LB_FINDSTRINGEXACT
),
420 SET(WM_PAINTCLIPBOARD
) | SET(WM_SIZECLIPBOARD
) | SET(WM_ASKCBFORMATNAME
)
423 /* check whether a given message type includes pointers */
424 static inline BOOL
is_pointer_message( UINT message
, WPARAM wparam
)
426 if (message
>= 8*sizeof(message_pointer_flags
)) return FALSE
;
427 if (message
== WM_DEVICECHANGE
&& !(wparam
& 0x8000)) 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 BOOL
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
);
587 DWORD
get_input_codepage( void )
591 HKL hkl
= GetKeyboardLayout( 0 );
593 ret
= GetLocaleInfoW( LOWORD(hkl
), LOCALE_IDEFAULTANSICODEPAGE
| LOCALE_RETURN_NUMBER
,
594 (WCHAR
*)&cp
, sizeof(cp
) / sizeof(WCHAR
) );
595 if (!ret
) cp
= CP_ACP
;
599 /***********************************************************************
602 * Convert the wparam of an ASCII message to Unicode.
604 BOOL
map_wparam_AtoW( UINT message
, WPARAM
*wparam
, enum wm_char_mapping mapping
)
608 DWORD cp
= get_input_codepage();
614 /* WM_CHAR is magic: a DBCS char can be sent/posted as two consecutive WM_CHAR
615 * messages, in which case the first char is stored, and the conversion
616 * to Unicode only takes place once the second char is sent/posted.
618 if (mapping
!= WMCHAR_MAP_NOMAPPING
)
620 struct wm_char_mapping_data
*data
= get_user_thread_info()->wmchar_data
;
621 BYTE low
= LOBYTE(*wparam
);
626 ch
[1] = HIBYTE(*wparam
);
627 MultiByteToWideChar( cp
, 0, ch
, 2, wch
, 2 );
628 TRACE( "map %02x,%02x -> %04x mapping %u\n", (BYTE
)ch
[0], (BYTE
)ch
[1], wch
[0], mapping
);
629 if (data
) data
->lead_byte
[mapping
] = 0;
631 else if (data
&& data
->lead_byte
[mapping
])
633 ch
[0] = data
->lead_byte
[mapping
];
635 MultiByteToWideChar( cp
, 0, ch
, 2, wch
, 2 );
636 TRACE( "map stored %02x,%02x -> %04x mapping %u\n", (BYTE
)ch
[0], (BYTE
)ch
[1], wch
[0], mapping
);
637 data
->lead_byte
[mapping
] = 0;
639 else if (!IsDBCSLeadByte( low
))
642 MultiByteToWideChar( cp
, 0, ch
, 1, wch
, 2 );
643 TRACE( "map %02x -> %04x\n", (BYTE
)ch
[0], wch
[0] );
644 if (data
) data
->lead_byte
[mapping
] = 0;
646 else /* store it and wait for trail byte */
650 if (!(data
= HeapAlloc( GetProcessHeap(), HEAP_ZERO_MEMORY
, sizeof(*data
) )))
652 get_user_thread_info()->wmchar_data
= data
;
654 TRACE( "storing lead byte %02x mapping %u\n", low
, mapping
);
655 data
->lead_byte
[mapping
] = low
;
658 *wparam
= MAKEWPARAM(wch
[0], wch
[1]);
661 /* else fall through */
663 case EM_SETPASSWORDCHAR
:
668 ch
[0] = LOBYTE(*wparam
);
669 ch
[1] = HIBYTE(*wparam
);
670 MultiByteToWideChar( cp
, 0, ch
, 2, wch
, 2 );
671 *wparam
= MAKEWPARAM(wch
[0], wch
[1]);
674 ch
[0] = HIBYTE(*wparam
);
675 ch
[1] = LOBYTE(*wparam
);
676 if (ch
[0]) MultiByteToWideChar( cp
, 0, ch
, 2, wch
, 2 );
677 else MultiByteToWideChar( cp
, 0, ch
+ 1, 1, wch
, 1 );
678 *wparam
= MAKEWPARAM(wch
[0], HIWORD(*wparam
));
685 /***********************************************************************
688 * Convert the wparam of a Unicode message to ASCII.
690 static void map_wparam_WtoA( MSG
*msg
, BOOL remove
)
695 DWORD cp
= get_input_codepage();
700 if (!HIWORD(msg
->wParam
))
702 wch
[0] = LOWORD(msg
->wParam
);
704 len
= WideCharToMultiByte( cp
, 0, wch
, 1, (LPSTR
)ch
, 2, NULL
, NULL
);
705 if (len
== 2) /* DBCS char */
707 struct wm_char_mapping_data
*data
= get_user_thread_info()->wmchar_data
;
710 if (!(data
= HeapAlloc( GetProcessHeap(), HEAP_ZERO_MEMORY
, sizeof(*data
) ))) return;
711 get_user_thread_info()->wmchar_data
= data
;
715 data
->get_msg
= *msg
;
716 data
->get_msg
.wParam
= ch
[1];
722 /* else fall through */
724 case EM_SETPASSWORDCHAR
:
729 wch
[0] = LOWORD(msg
->wParam
);
730 wch
[1] = HIWORD(msg
->wParam
);
732 WideCharToMultiByte( cp
, 0, wch
, 2, (LPSTR
)ch
, 4, NULL
, NULL
);
733 msg
->wParam
= MAKEWPARAM( ch
[0] | (ch
[1] << 8), 0 );
736 wch
[0] = LOWORD(msg
->wParam
);
738 len
= WideCharToMultiByte( cp
, 0, wch
, 1, (LPSTR
)ch
, 2, NULL
, NULL
);
740 msg
->wParam
= MAKEWPARAM( (ch
[0] << 8) | ch
[1], HIWORD(msg
->wParam
) );
742 msg
->wParam
= MAKEWPARAM( ch
[0], HIWORD(msg
->wParam
) );
748 /***********************************************************************
751 * Pack a message for sending to another process.
752 * Return the size of the data we expect in the message reply.
753 * Set data->count to -1 if there is an error.
755 static size_t pack_message( HWND hwnd
, UINT message
, WPARAM wparam
, LPARAM lparam
,
756 struct packed_message
*data
)
764 CREATESTRUCTW
*cs
= (CREATESTRUCTW
*)lparam
;
765 data
->ps
.cs
.lpCreateParams
= pack_ptr( cs
->lpCreateParams
);
766 data
->ps
.cs
.hInstance
= pack_ptr( cs
->hInstance
);
767 data
->ps
.cs
.hMenu
= wine_server_user_handle( cs
->hMenu
);
768 data
->ps
.cs
.hwndParent
= wine_server_user_handle( cs
->hwndParent
);
769 data
->ps
.cs
.cy
= cs
->cy
;
770 data
->ps
.cs
.cx
= cs
->cx
;
771 data
->ps
.cs
.y
= cs
->y
;
772 data
->ps
.cs
.x
= cs
->x
;
773 data
->ps
.cs
.style
= cs
->style
;
774 data
->ps
.cs
.dwExStyle
= cs
->dwExStyle
;
775 data
->ps
.cs
.lpszName
= pack_ptr( cs
->lpszName
);
776 data
->ps
.cs
.lpszClass
= pack_ptr( cs
->lpszClass
);
777 push_data( data
, &data
->ps
.cs
, sizeof(data
->ps
.cs
) );
778 if (!IS_INTRESOURCE(cs
->lpszName
)) push_string( data
, cs
->lpszName
);
779 if (!IS_INTRESOURCE(cs
->lpszClass
)) push_string( data
, cs
->lpszClass
);
780 return sizeof(data
->ps
.cs
);
783 case WM_ASKCBFORMATNAME
:
784 return wparam
* sizeof(WCHAR
);
785 case WM_WININICHANGE
:
786 if (lparam
) push_string(data
, (LPWSTR
)lparam
);
789 case WM_DEVMODECHANGE
:
794 push_string( data
, (LPWSTR
)lparam
);
796 case WM_GETMINMAXINFO
:
797 push_data( data
, (MINMAXINFO
*)lparam
, sizeof(MINMAXINFO
) );
798 return sizeof(MINMAXINFO
);
801 DRAWITEMSTRUCT
*dis
= (DRAWITEMSTRUCT
*)lparam
;
802 data
->ps
.dis
.CtlType
= dis
->CtlType
;
803 data
->ps
.dis
.CtlID
= dis
->CtlID
;
804 data
->ps
.dis
.itemID
= dis
->itemID
;
805 data
->ps
.dis
.itemAction
= dis
->itemAction
;
806 data
->ps
.dis
.itemState
= dis
->itemState
;
807 data
->ps
.dis
.hwndItem
= wine_server_user_handle( dis
->hwndItem
);
808 data
->ps
.dis
.hDC
= wine_server_user_handle( dis
->hDC
); /* FIXME */
809 data
->ps
.dis
.rcItem
= dis
->rcItem
;
810 data
->ps
.dis
.itemData
= dis
->itemData
;
811 push_data( data
, &data
->ps
.dis
, sizeof(data
->ps
.dis
) );
816 MEASUREITEMSTRUCT
*mis
= (MEASUREITEMSTRUCT
*)lparam
;
817 data
->ps
.mis
.CtlType
= mis
->CtlType
;
818 data
->ps
.mis
.CtlID
= mis
->CtlID
;
819 data
->ps
.mis
.itemID
= mis
->itemID
;
820 data
->ps
.mis
.itemWidth
= mis
->itemWidth
;
821 data
->ps
.mis
.itemHeight
= mis
->itemHeight
;
822 data
->ps
.mis
.itemData
= mis
->itemData
;
823 push_data( data
, &data
->ps
.mis
, sizeof(data
->ps
.mis
) );
824 return sizeof(data
->ps
.mis
);
828 DELETEITEMSTRUCT
*dls
= (DELETEITEMSTRUCT
*)lparam
;
829 data
->ps
.dls
.CtlType
= dls
->CtlType
;
830 data
->ps
.dls
.CtlID
= dls
->CtlID
;
831 data
->ps
.dls
.itemID
= dls
->itemID
;
832 data
->ps
.dls
.hwndItem
= wine_server_user_handle( dls
->hwndItem
);
833 data
->ps
.dls
.itemData
= dls
->itemData
;
834 push_data( data
, &data
->ps
.dls
, sizeof(data
->ps
.dls
) );
839 COMPAREITEMSTRUCT
*cis
= (COMPAREITEMSTRUCT
*)lparam
;
840 data
->ps
.cis
.CtlType
= cis
->CtlType
;
841 data
->ps
.cis
.CtlID
= cis
->CtlID
;
842 data
->ps
.cis
.hwndItem
= wine_server_user_handle( cis
->hwndItem
);
843 data
->ps
.cis
.itemID1
= cis
->itemID1
;
844 data
->ps
.cis
.itemData1
= cis
->itemData1
;
845 data
->ps
.cis
.itemID2
= cis
->itemID2
;
846 data
->ps
.cis
.itemData2
= cis
->itemData2
;
847 data
->ps
.cis
.dwLocaleId
= cis
->dwLocaleId
;
848 push_data( data
, &data
->ps
.cis
, sizeof(data
->ps
.cis
) );
851 case WM_WINE_SETWINDOWPOS
:
852 case WM_WINDOWPOSCHANGING
:
853 case WM_WINDOWPOSCHANGED
:
855 WINDOWPOS
*wp
= (WINDOWPOS
*)lparam
;
856 data
->ps
.wp
.hwnd
= wine_server_user_handle( wp
->hwnd
);
857 data
->ps
.wp
.hwndInsertAfter
= wine_server_user_handle( wp
->hwndInsertAfter
);
858 data
->ps
.wp
.x
= wp
->x
;
859 data
->ps
.wp
.y
= wp
->y
;
860 data
->ps
.wp
.cx
= wp
->cx
;
861 data
->ps
.wp
.cy
= wp
->cy
;
862 data
->ps
.wp
.flags
= wp
->flags
;
863 push_data( data
, &data
->ps
.wp
, sizeof(data
->ps
.wp
) );
864 return sizeof(data
->ps
.wp
);
868 COPYDATASTRUCT
*cds
= (COPYDATASTRUCT
*)lparam
;
869 data
->ps
.cds
.cbData
= cds
->cbData
;
870 data
->ps
.cds
.dwData
= cds
->dwData
;
871 data
->ps
.cds
.lpData
= pack_ptr( cds
->lpData
);
872 push_data( data
, &data
->ps
.cds
, sizeof(data
->ps
.cds
) );
873 if (cds
->lpData
) push_data( data
, cds
->lpData
, cds
->cbData
);
877 /* WM_NOTIFY cannot be sent across processes (MSDN) */
882 HELPINFO
*hi
= (HELPINFO
*)lparam
;
883 data
->ps
.hi
.iContextType
= hi
->iContextType
;
884 data
->ps
.hi
.iCtrlId
= hi
->iCtrlId
;
885 data
->ps
.hi
.hItemHandle
= wine_server_user_handle( hi
->hItemHandle
);
886 data
->ps
.hi
.dwContextId
= hi
->dwContextId
;
887 data
->ps
.hi
.MousePos
= hi
->MousePos
;
888 push_data( data
, &data
->ps
.hi
, sizeof(data
->ps
.hi
) );
891 case WM_STYLECHANGING
:
892 case WM_STYLECHANGED
:
893 push_data( data
, (STYLESTRUCT
*)lparam
, sizeof(STYLESTRUCT
) );
898 push_data( data
, (RECT
*)lparam
, sizeof(RECT
) );
903 NCCALCSIZE_PARAMS
*ncp
= (NCCALCSIZE_PARAMS
*)lparam
;
904 data
->ps
.ncp
.rgrc
[0] = ncp
->rgrc
[0];
905 data
->ps
.ncp
.rgrc
[1] = ncp
->rgrc
[1];
906 data
->ps
.ncp
.rgrc
[2] = ncp
->rgrc
[2];
907 data
->ps
.ncp
.hwnd
= wine_server_user_handle( ncp
->lppos
->hwnd
);
908 data
->ps
.ncp
.hwndInsertAfter
= wine_server_user_handle( ncp
->lppos
->hwndInsertAfter
);
909 data
->ps
.ncp
.x
= ncp
->lppos
->x
;
910 data
->ps
.ncp
.y
= ncp
->lppos
->y
;
911 data
->ps
.ncp
.cx
= ncp
->lppos
->cx
;
912 data
->ps
.ncp
.cy
= ncp
->lppos
->cy
;
913 data
->ps
.ncp
.flags
= ncp
->lppos
->flags
;
914 push_data( data
, &data
->ps
.ncp
, sizeof(data
->ps
.ncp
) );
915 return sizeof(data
->ps
.ncp
);
920 MSG
*msg
= (MSG
*)lparam
;
921 data
->ps
.msg
.hwnd
= wine_server_user_handle( msg
->hwnd
);
922 data
->ps
.msg
.message
= msg
->message
;
923 data
->ps
.msg
.wParam
= msg
->wParam
;
924 data
->ps
.msg
.lParam
= msg
->lParam
;
925 data
->ps
.msg
.time
= msg
->time
;
926 data
->ps
.msg
.pt
= msg
->pt
;
927 push_data( data
, &data
->ps
.msg
, sizeof(data
->ps
.msg
) );
928 return sizeof(data
->ps
.msg
);
931 case SBM_SETSCROLLINFO
:
932 push_data( data
, (SCROLLINFO
*)lparam
, sizeof(SCROLLINFO
) );
934 case SBM_GETSCROLLINFO
:
935 push_data( data
, (SCROLLINFO
*)lparam
, sizeof(SCROLLINFO
) );
936 return sizeof(SCROLLINFO
);
937 case SBM_GETSCROLLBARINFO
:
939 const SCROLLBARINFO
*info
= (const SCROLLBARINFO
*)lparam
;
940 size_t size
= min( info
->cbSize
, sizeof(SCROLLBARINFO
) );
941 push_data( data
, info
, size
);
949 if (wparam
) size
+= sizeof(DWORD
);
950 if (lparam
) size
+= sizeof(DWORD
);
955 case CB_GETDROPPEDCONTROLRECT
:
959 push_data( data
, (RECT
*)lparam
, sizeof(RECT
) );
963 WORD
*pw
= (WORD
*)lparam
;
964 push_data( data
, pw
, sizeof(*pw
) );
965 return *pw
* sizeof(WCHAR
);
969 if (wparam
) push_data( data
, (UINT
*)lparam
, sizeof(UINT
) * wparam
);
972 case CB_INSERTSTRING
:
974 case CB_FINDSTRINGEXACT
:
975 case CB_SELECTSTRING
:
976 if (combobox_has_strings( hwnd
)) push_string( data
, (LPWSTR
)lparam
);
979 if (!combobox_has_strings( hwnd
)) return sizeof(ULONG_PTR
);
980 return (SendMessageW( hwnd
, CB_GETLBTEXTLEN
, wparam
, 0 ) + 1) * sizeof(WCHAR
);
982 case LB_INSERTSTRING
:
984 case LB_FINDSTRINGEXACT
:
985 case LB_SELECTSTRING
:
986 if (listbox_has_strings( hwnd
)) push_string( data
, (LPWSTR
)lparam
);
989 if (!listbox_has_strings( hwnd
)) return sizeof(ULONG_PTR
);
990 return (SendMessageW( hwnd
, LB_GETTEXTLEN
, wparam
, 0 ) + 1) * sizeof(WCHAR
);
992 return wparam
* sizeof(UINT
);
995 MDINEXTMENU
*mnm
= (MDINEXTMENU
*)lparam
;
996 data
->ps
.mnm
.hmenuIn
= wine_server_user_handle( mnm
->hmenuIn
);
997 data
->ps
.mnm
.hmenuNext
= wine_server_user_handle( mnm
->hmenuNext
);
998 data
->ps
.mnm
.hwndNext
= wine_server_user_handle( mnm
->hwndNext
);
999 push_data( data
, &data
->ps
.mnm
, sizeof(data
->ps
.mnm
) );
1000 return sizeof(data
->ps
.mnm
);
1004 push_data( data
, (RECT
*)lparam
, sizeof(RECT
) );
1005 return sizeof(RECT
);
1008 MDICREATESTRUCTW
*mcs
= (MDICREATESTRUCTW
*)lparam
;
1009 data
->ps
.mcs
.szClass
= pack_ptr( mcs
->szClass
);
1010 data
->ps
.mcs
.szTitle
= pack_ptr( mcs
->szTitle
);
1011 data
->ps
.mcs
.hOwner
= pack_ptr( mcs
->hOwner
);
1012 data
->ps
.mcs
.x
= mcs
->x
;
1013 data
->ps
.mcs
.y
= mcs
->y
;
1014 data
->ps
.mcs
.cx
= mcs
->cx
;
1015 data
->ps
.mcs
.cy
= mcs
->cy
;
1016 data
->ps
.mcs
.style
= mcs
->style
;
1017 data
->ps
.mcs
.lParam
= mcs
->lParam
;
1018 push_data( data
, &data
->ps
.mcs
, sizeof(data
->ps
.mcs
) );
1019 if (!IS_INTRESOURCE(mcs
->szClass
)) push_string( data
, mcs
->szClass
);
1020 if (!IS_INTRESOURCE(mcs
->szTitle
)) push_string( data
, mcs
->szTitle
);
1021 return sizeof(data
->ps
.mcs
);
1023 case WM_MDIGETACTIVE
:
1024 if (lparam
) return sizeof(BOOL
);
1026 case WM_DEVICECHANGE
:
1028 DEV_BROADCAST_HDR
*header
= (DEV_BROADCAST_HDR
*)lparam
;
1029 push_data( data
, header
, header
->dbch_size
);
1032 case WM_WINE_KEYBOARD_LL_HOOK
:
1034 struct hook_extra_info
*h_extra
= (struct hook_extra_info
*)lparam
;
1035 data
->ps
.hook
.handle
= wine_server_user_handle( h_extra
->handle
);
1036 push_data( data
, &data
->ps
.hook
, sizeof(data
->ps
.hook
) );
1037 push_data( data
, (LPVOID
)h_extra
->lparam
, sizeof(KBDLLHOOKSTRUCT
) );
1040 case WM_WINE_MOUSE_LL_HOOK
:
1042 struct hook_extra_info
*h_extra
= (struct hook_extra_info
*)lparam
;
1043 data
->ps
.hook
.handle
= wine_server_user_handle( h_extra
->handle
);
1044 push_data( data
, &data
->ps
.hook
, sizeof(data
->ps
.hook
) );
1045 push_data( data
, (LPVOID
)h_extra
->lparam
, sizeof(MSLLHOOKSTRUCT
) );
1049 if (wparam
<= 1) return 0;
1050 FIXME( "WM_NCPAINT hdc packing not supported yet\n" );
1054 if (!wparam
) return 0;
1057 /* these contain an HFONT */
1060 /* these contain an HDC */
1062 case WM_ICONERASEBKGND
:
1063 case WM_CTLCOLORMSGBOX
:
1064 case WM_CTLCOLOREDIT
:
1065 case WM_CTLCOLORLISTBOX
:
1066 case WM_CTLCOLORBTN
:
1067 case WM_CTLCOLORDLG
:
1068 case WM_CTLCOLORSCROLLBAR
:
1069 case WM_CTLCOLORSTATIC
:
1071 case WM_PRINTCLIENT
:
1072 /* these contain an HGLOBAL */
1073 case WM_PAINTCLIPBOARD
:
1074 case WM_SIZECLIPBOARD
:
1075 /* these contain HICON */
1078 case WM_QUERYDRAGICON
:
1079 case WM_QUERYPARKICON
:
1080 /* these contain pointers */
1082 case WM_QUERYDROPOBJECT
:
1086 FIXME( "msg %x (%s) not supported yet\n", message
, SPY_GetMsgName(message
, hwnd
) );
1094 /***********************************************************************
1097 * Unpack a message received from another process.
1099 static BOOL
unpack_message( HWND hwnd
, UINT message
, WPARAM
*wparam
, LPARAM
*lparam
,
1100 void **buffer
, size_t size
)
1103 union packed_structs
*ps
= *buffer
;
1111 WCHAR
*str
= (WCHAR
*)(&ps
->cs
+ 1);
1112 if (size
< sizeof(ps
->cs
)) return FALSE
;
1113 size
-= sizeof(ps
->cs
);
1114 cs
.lpCreateParams
= unpack_ptr( ps
->cs
.lpCreateParams
);
1115 cs
.hInstance
= unpack_ptr( ps
->cs
.hInstance
);
1116 cs
.hMenu
= wine_server_ptr_handle( ps
->cs
.hMenu
);
1117 cs
.hwndParent
= wine_server_ptr_handle( ps
->cs
.hwndParent
);
1122 cs
.style
= ps
->cs
.style
;
1123 cs
.dwExStyle
= ps
->cs
.dwExStyle
;
1124 cs
.lpszName
= unpack_ptr( ps
->cs
.lpszName
);
1125 cs
.lpszClass
= unpack_ptr( ps
->cs
.lpszClass
);
1126 if (ps
->cs
.lpszName
>> 16)
1128 if (!check_string( str
, size
)) return FALSE
;
1130 size
-= (strlenW(str
) + 1) * sizeof(WCHAR
);
1131 str
+= strlenW(str
) + 1;
1133 if (ps
->cs
.lpszClass
>> 16)
1135 if (!check_string( str
, size
)) return FALSE
;
1138 memcpy( &ps
->cs
, &cs
, sizeof(cs
) );
1142 case WM_ASKCBFORMATNAME
:
1143 if (!get_buffer_space( buffer
, (*wparam
* sizeof(WCHAR
)) )) return FALSE
;
1145 case WM_WININICHANGE
:
1146 if (!*lparam
) return TRUE
;
1149 case WM_DEVMODECHANGE
:
1154 if (!check_string( *buffer
, size
)) return FALSE
;
1156 case WM_GETMINMAXINFO
:
1157 minsize
= sizeof(MINMAXINFO
);
1162 if (size
< sizeof(ps
->dis
)) return FALSE
;
1163 dis
.CtlType
= ps
->dis
.CtlType
;
1164 dis
.CtlID
= ps
->dis
.CtlID
;
1165 dis
.itemID
= ps
->dis
.itemID
;
1166 dis
.itemAction
= ps
->dis
.itemAction
;
1167 dis
.itemState
= ps
->dis
.itemState
;
1168 dis
.hwndItem
= wine_server_ptr_handle( ps
->dis
.hwndItem
);
1169 dis
.hDC
= wine_server_ptr_handle( ps
->dis
.hDC
);
1170 dis
.rcItem
= ps
->dis
.rcItem
;
1171 dis
.itemData
= (ULONG_PTR
)unpack_ptr( ps
->dis
.itemData
);
1172 memcpy( &ps
->dis
, &dis
, sizeof(dis
) );
1175 case WM_MEASUREITEM
:
1177 MEASUREITEMSTRUCT mis
;
1178 if (size
< sizeof(ps
->mis
)) return FALSE
;
1179 mis
.CtlType
= ps
->mis
.CtlType
;
1180 mis
.CtlID
= ps
->mis
.CtlID
;
1181 mis
.itemID
= ps
->mis
.itemID
;
1182 mis
.itemWidth
= ps
->mis
.itemWidth
;
1183 mis
.itemHeight
= ps
->mis
.itemHeight
;
1184 mis
.itemData
= (ULONG_PTR
)unpack_ptr( ps
->mis
.itemData
);
1185 memcpy( &ps
->mis
, &mis
, sizeof(mis
) );
1190 DELETEITEMSTRUCT dls
;
1191 if (size
< sizeof(ps
->dls
)) return FALSE
;
1192 dls
.CtlType
= ps
->dls
.CtlType
;
1193 dls
.CtlID
= ps
->dls
.CtlID
;
1194 dls
.itemID
= ps
->dls
.itemID
;
1195 dls
.hwndItem
= wine_server_ptr_handle( ps
->dls
.hwndItem
);
1196 dls
.itemData
= (ULONG_PTR
)unpack_ptr( ps
->dls
.itemData
);
1197 memcpy( &ps
->dls
, &dls
, sizeof(dls
) );
1200 case WM_COMPAREITEM
:
1202 COMPAREITEMSTRUCT cis
;
1203 if (size
< sizeof(ps
->cis
)) return FALSE
;
1204 cis
.CtlType
= ps
->cis
.CtlType
;
1205 cis
.CtlID
= ps
->cis
.CtlID
;
1206 cis
.hwndItem
= wine_server_ptr_handle( ps
->cis
.hwndItem
);
1207 cis
.itemID1
= ps
->cis
.itemID1
;
1208 cis
.itemData1
= (ULONG_PTR
)unpack_ptr( ps
->cis
.itemData1
);
1209 cis
.itemID2
= ps
->cis
.itemID2
;
1210 cis
.itemData2
= (ULONG_PTR
)unpack_ptr( ps
->cis
.itemData2
);
1211 cis
.dwLocaleId
= ps
->cis
.dwLocaleId
;
1212 memcpy( &ps
->cis
, &cis
, sizeof(cis
) );
1215 case WM_WINDOWPOSCHANGING
:
1216 case WM_WINDOWPOSCHANGED
:
1217 case WM_WINE_SETWINDOWPOS
:
1220 if (size
< sizeof(ps
->wp
)) return FALSE
;
1221 wp
.hwnd
= wine_server_ptr_handle( ps
->wp
.hwnd
);
1222 wp
.hwndInsertAfter
= wine_server_ptr_handle( ps
->wp
.hwndInsertAfter
);
1227 wp
.flags
= ps
->wp
.flags
;
1228 memcpy( &ps
->wp
, &wp
, sizeof(wp
) );
1234 if (size
< sizeof(ps
->cds
)) return FALSE
;
1235 cds
.dwData
= (ULONG_PTR
)unpack_ptr( ps
->cds
.dwData
);
1238 cds
.cbData
= ps
->cds
.cbData
;
1239 cds
.lpData
= &ps
->cds
+ 1;
1240 minsize
= sizeof(ps
->cds
) + cds
.cbData
;
1247 memcpy( &ps
->cds
, &cds
, sizeof(cds
) );
1251 /* WM_NOTIFY cannot be sent across processes (MSDN) */
1256 if (size
< sizeof(ps
->hi
)) return FALSE
;
1257 hi
.cbSize
= sizeof(hi
);
1258 hi
.iContextType
= ps
->hi
.iContextType
;
1259 hi
.iCtrlId
= ps
->hi
.iCtrlId
;
1260 hi
.hItemHandle
= wine_server_ptr_handle( ps
->hi
.hItemHandle
);
1261 hi
.dwContextId
= (ULONG_PTR
)unpack_ptr( ps
->hi
.dwContextId
);
1262 hi
.MousePos
= ps
->hi
.MousePos
;
1263 memcpy( &ps
->hi
, &hi
, sizeof(hi
) );
1266 case WM_STYLECHANGING
:
1267 case WM_STYLECHANGED
:
1268 minsize
= sizeof(STYLESTRUCT
);
1271 if (!*wparam
) minsize
= sizeof(RECT
);
1274 NCCALCSIZE_PARAMS ncp
;
1276 if (size
< sizeof(ps
->ncp
)) return FALSE
;
1277 ncp
.rgrc
[0] = ps
->ncp
.rgrc
[0];
1278 ncp
.rgrc
[1] = ps
->ncp
.rgrc
[1];
1279 ncp
.rgrc
[2] = ps
->ncp
.rgrc
[2];
1280 wp
.hwnd
= wine_server_ptr_handle( ps
->ncp
.hwnd
);
1281 wp
.hwndInsertAfter
= wine_server_ptr_handle( ps
->ncp
.hwndInsertAfter
);
1286 wp
.flags
= ps
->ncp
.flags
;
1287 ncp
.lppos
= (WINDOWPOS
*)((NCCALCSIZE_PARAMS
*)&ps
->ncp
+ 1);
1288 memcpy( &ps
->ncp
, &ncp
, sizeof(ncp
) );
1296 if (size
< sizeof(ps
->msg
)) return FALSE
;
1297 msg
.hwnd
= wine_server_ptr_handle( ps
->msg
.hwnd
);
1298 msg
.message
= ps
->msg
.message
;
1299 msg
.wParam
= (ULONG_PTR
)unpack_ptr( ps
->msg
.wParam
);
1300 msg
.lParam
= (ULONG_PTR
)unpack_ptr( ps
->msg
.lParam
);
1301 msg
.time
= ps
->msg
.time
;
1302 msg
.pt
= ps
->msg
.pt
;
1303 memcpy( &ps
->msg
, &msg
, sizeof(msg
) );
1307 case SBM_SETSCROLLINFO
:
1308 minsize
= sizeof(SCROLLINFO
);
1310 case SBM_GETSCROLLINFO
:
1311 if (!get_buffer_space( buffer
, sizeof(SCROLLINFO
))) return FALSE
;
1313 case SBM_GETSCROLLBARINFO
:
1314 if (!get_buffer_space( buffer
, sizeof(SCROLLBARINFO
))) return FALSE
;
1319 if (*wparam
|| *lparam
)
1321 if (!get_buffer_space( buffer
, 2*sizeof(DWORD
) )) return FALSE
;
1322 if (*wparam
) *wparam
= (WPARAM
)*buffer
;
1323 if (*lparam
) *lparam
= (LPARAM
)((DWORD
*)*buffer
+ 1);
1327 case LB_GETITEMRECT
:
1328 case CB_GETDROPPEDCONTROLRECT
:
1329 if (!get_buffer_space( buffer
, sizeof(RECT
) )) return FALSE
;
1333 minsize
= sizeof(RECT
);
1338 if (size
< sizeof(WORD
)) return FALSE
;
1339 len
= *(WORD
*)*buffer
;
1340 if (!get_buffer_space( buffer
, (len
+ 1) * sizeof(WCHAR
) )) return FALSE
;
1341 *lparam
= (LPARAM
)*buffer
+ sizeof(WORD
); /* don't erase WORD at start of buffer */
1344 case EM_SETTABSTOPS
:
1345 case LB_SETTABSTOPS
:
1346 if (!*wparam
) return TRUE
;
1347 minsize
= *wparam
* sizeof(UINT
);
1350 case CB_INSERTSTRING
:
1352 case CB_FINDSTRINGEXACT
:
1353 case CB_SELECTSTRING
:
1355 case LB_INSERTSTRING
:
1357 case LB_FINDSTRINGEXACT
:
1358 case LB_SELECTSTRING
:
1359 if (!*buffer
) return TRUE
;
1360 if (!check_string( *buffer
, size
)) return FALSE
;
1364 size
= sizeof(ULONG_PTR
);
1365 if (combobox_has_strings( hwnd
))
1366 size
= (SendMessageW( hwnd
, CB_GETLBTEXTLEN
, *wparam
, 0 ) + 1) * sizeof(WCHAR
);
1367 if (!get_buffer_space( buffer
, size
)) return FALSE
;
1372 size
= sizeof(ULONG_PTR
);
1373 if (listbox_has_strings( hwnd
))
1374 size
= (SendMessageW( hwnd
, LB_GETTEXTLEN
, *wparam
, 0 ) + 1) * sizeof(WCHAR
);
1375 if (!get_buffer_space( buffer
, size
)) return FALSE
;
1378 case LB_GETSELITEMS
:
1379 if (!get_buffer_space( buffer
, *wparam
* sizeof(UINT
) )) return FALSE
;
1384 if (size
< sizeof(ps
->mnm
)) return FALSE
;
1385 mnm
.hmenuIn
= wine_server_ptr_handle( ps
->mnm
.hmenuIn
);
1386 mnm
.hmenuNext
= wine_server_ptr_handle( ps
->mnm
.hmenuNext
);
1387 mnm
.hwndNext
= wine_server_ptr_handle( ps
->mnm
.hwndNext
);
1388 memcpy( &ps
->mnm
, &mnm
, sizeof(mnm
) );
1393 minsize
= sizeof(RECT
);
1394 if (!get_buffer_space( buffer
, sizeof(RECT
) )) return FALSE
;
1398 MDICREATESTRUCTW mcs
;
1399 WCHAR
*str
= (WCHAR
*)(&ps
->mcs
+ 1);
1400 if (size
< sizeof(ps
->mcs
)) return FALSE
;
1401 size
-= sizeof(ps
->mcs
);
1403 mcs
.szClass
= unpack_ptr( ps
->mcs
.szClass
);
1404 mcs
.szTitle
= unpack_ptr( ps
->mcs
.szTitle
);
1405 mcs
.hOwner
= unpack_ptr( ps
->mcs
.hOwner
);
1408 mcs
.cx
= ps
->mcs
.cx
;
1409 mcs
.cy
= ps
->mcs
.cy
;
1410 mcs
.style
= ps
->mcs
.style
;
1411 mcs
.lParam
= (LPARAM
)unpack_ptr( ps
->mcs
.lParam
);
1412 if (ps
->mcs
.szClass
>> 16)
1414 if (!check_string( str
, size
)) return FALSE
;
1416 size
-= (strlenW(str
) + 1) * sizeof(WCHAR
);
1417 str
+= strlenW(str
) + 1;
1419 if (ps
->mcs
.szTitle
>> 16)
1421 if (!check_string( str
, size
)) return FALSE
;
1424 memcpy( &ps
->mcs
, &mcs
, sizeof(mcs
) );
1427 case WM_MDIGETACTIVE
:
1428 if (!*lparam
) return TRUE
;
1429 if (!get_buffer_space( buffer
, sizeof(BOOL
) )) return FALSE
;
1431 case WM_DEVICECHANGE
:
1432 minsize
= sizeof(DEV_BROADCAST_HDR
);
1434 case WM_WINE_KEYBOARD_LL_HOOK
:
1435 case WM_WINE_MOUSE_LL_HOOK
:
1437 struct hook_extra_info h_extra
;
1438 minsize
= sizeof(ps
->hook
) +
1439 (message
== WM_WINE_KEYBOARD_LL_HOOK
? sizeof(KBDLLHOOKSTRUCT
)
1440 : sizeof(MSLLHOOKSTRUCT
));
1441 if (size
< minsize
) return FALSE
;
1442 h_extra
.handle
= wine_server_ptr_handle( ps
->hook
.handle
);
1443 h_extra
.lparam
= (LPARAM
)(&ps
->hook
+ 1);
1444 memcpy( &ps
->hook
, &h_extra
, sizeof(h_extra
) );
1448 if (*wparam
<= 1) return TRUE
;
1449 FIXME( "WM_NCPAINT hdc unpacking not supported\n" );
1452 if (!*wparam
) return TRUE
;
1455 /* these contain an HFONT */
1458 /* these contain an HDC */
1460 case WM_ICONERASEBKGND
:
1461 case WM_CTLCOLORMSGBOX
:
1462 case WM_CTLCOLOREDIT
:
1463 case WM_CTLCOLORLISTBOX
:
1464 case WM_CTLCOLORBTN
:
1465 case WM_CTLCOLORDLG
:
1466 case WM_CTLCOLORSCROLLBAR
:
1467 case WM_CTLCOLORSTATIC
:
1469 case WM_PRINTCLIENT
:
1470 /* these contain an HGLOBAL */
1471 case WM_PAINTCLIPBOARD
:
1472 case WM_SIZECLIPBOARD
:
1473 /* these contain HICON */
1476 case WM_QUERYDRAGICON
:
1477 case WM_QUERYPARKICON
:
1478 /* these contain pointers */
1480 case WM_QUERYDROPOBJECT
:
1484 FIXME( "msg %x (%s) not supported yet\n", message
, SPY_GetMsgName(message
, hwnd
) );
1488 return TRUE
; /* message doesn't need any unpacking */
1491 /* default exit for most messages: check minsize and store buffer in lparam */
1492 if (size
< minsize
) return FALSE
;
1493 *lparam
= (LPARAM
)*buffer
;
1498 /***********************************************************************
1501 * Pack a reply to a message for sending to another process.
1503 static void pack_reply( HWND hwnd
, UINT message
, WPARAM wparam
, LPARAM lparam
,
1504 LRESULT res
, struct packed_message
*data
)
1512 CREATESTRUCTW
*cs
= (CREATESTRUCTW
*)lparam
;
1513 data
->ps
.cs
.lpCreateParams
= (ULONG_PTR
)cs
->lpCreateParams
;
1514 data
->ps
.cs
.hInstance
= (ULONG_PTR
)cs
->hInstance
;
1515 data
->ps
.cs
.hMenu
= wine_server_user_handle( cs
->hMenu
);
1516 data
->ps
.cs
.hwndParent
= wine_server_user_handle( cs
->hwndParent
);
1517 data
->ps
.cs
.cy
= cs
->cy
;
1518 data
->ps
.cs
.cx
= cs
->cx
;
1519 data
->ps
.cs
.y
= cs
->y
;
1520 data
->ps
.cs
.x
= cs
->x
;
1521 data
->ps
.cs
.style
= cs
->style
;
1522 data
->ps
.cs
.dwExStyle
= cs
->dwExStyle
;
1523 data
->ps
.cs
.lpszName
= (ULONG_PTR
)cs
->lpszName
;
1524 data
->ps
.cs
.lpszClass
= (ULONG_PTR
)cs
->lpszClass
;
1525 push_data( data
, &data
->ps
.cs
, sizeof(data
->ps
.cs
) );
1531 push_data( data
, (WCHAR
*)lparam
, (res
+ 1) * sizeof(WCHAR
) );
1533 case WM_GETMINMAXINFO
:
1534 push_data( data
, (MINMAXINFO
*)lparam
, sizeof(MINMAXINFO
) );
1536 case WM_MEASUREITEM
:
1538 MEASUREITEMSTRUCT
*mis
= (MEASUREITEMSTRUCT
*)lparam
;
1539 data
->ps
.mis
.CtlType
= mis
->CtlType
;
1540 data
->ps
.mis
.CtlID
= mis
->CtlID
;
1541 data
->ps
.mis
.itemID
= mis
->itemID
;
1542 data
->ps
.mis
.itemWidth
= mis
->itemWidth
;
1543 data
->ps
.mis
.itemHeight
= mis
->itemHeight
;
1544 data
->ps
.mis
.itemData
= mis
->itemData
;
1545 push_data( data
, &data
->ps
.mis
, sizeof(data
->ps
.mis
) );
1548 case WM_WINDOWPOSCHANGING
:
1549 case WM_WINDOWPOSCHANGED
:
1551 WINDOWPOS
*wp
= (WINDOWPOS
*)lparam
;
1552 data
->ps
.wp
.hwnd
= wine_server_user_handle( wp
->hwnd
);
1553 data
->ps
.wp
.hwndInsertAfter
= wine_server_user_handle( wp
->hwndInsertAfter
);
1554 data
->ps
.wp
.x
= wp
->x
;
1555 data
->ps
.wp
.y
= wp
->y
;
1556 data
->ps
.wp
.cx
= wp
->cx
;
1557 data
->ps
.wp
.cy
= wp
->cy
;
1558 data
->ps
.wp
.flags
= wp
->flags
;
1559 push_data( data
, &data
->ps
.wp
, sizeof(data
->ps
.wp
) );
1565 MSG
*msg
= (MSG
*)lparam
;
1566 data
->ps
.msg
.hwnd
= wine_server_user_handle( msg
->hwnd
);
1567 data
->ps
.msg
.message
= msg
->message
;
1568 data
->ps
.msg
.wParam
= msg
->wParam
;
1569 data
->ps
.msg
.lParam
= msg
->lParam
;
1570 data
->ps
.msg
.time
= msg
->time
;
1571 data
->ps
.msg
.pt
= msg
->pt
;
1572 push_data( data
, &data
->ps
.msg
, sizeof(data
->ps
.msg
) );
1575 case SBM_GETSCROLLINFO
:
1576 push_data( data
, (SCROLLINFO
*)lparam
, sizeof(SCROLLINFO
) );
1579 case LB_GETITEMRECT
:
1580 case CB_GETDROPPEDCONTROLRECT
:
1583 push_data( data
, (RECT
*)lparam
, sizeof(RECT
) );
1587 WORD
*ptr
= (WORD
*)lparam
;
1588 push_data( data
, ptr
, ptr
[-1] * sizeof(WCHAR
) );
1591 case LB_GETSELITEMS
:
1592 push_data( data
, (UINT
*)lparam
, wparam
* sizeof(UINT
) );
1594 case WM_MDIGETACTIVE
:
1595 if (lparam
) push_data( data
, (BOOL
*)lparam
, sizeof(BOOL
) );
1599 push_data( data
, (RECT
*)lparam
, sizeof(RECT
) );
1602 NCCALCSIZE_PARAMS
*ncp
= (NCCALCSIZE_PARAMS
*)lparam
;
1603 data
->ps
.ncp
.rgrc
[0] = ncp
->rgrc
[0];
1604 data
->ps
.ncp
.rgrc
[1] = ncp
->rgrc
[1];
1605 data
->ps
.ncp
.rgrc
[2] = ncp
->rgrc
[2];
1606 data
->ps
.ncp
.hwnd
= wine_server_user_handle( ncp
->lppos
->hwnd
);
1607 data
->ps
.ncp
.hwndInsertAfter
= wine_server_user_handle( ncp
->lppos
->hwndInsertAfter
);
1608 data
->ps
.ncp
.x
= ncp
->lppos
->x
;
1609 data
->ps
.ncp
.y
= ncp
->lppos
->y
;
1610 data
->ps
.ncp
.cx
= ncp
->lppos
->cx
;
1611 data
->ps
.ncp
.cy
= ncp
->lppos
->cy
;
1612 data
->ps
.ncp
.flags
= ncp
->lppos
->flags
;
1613 push_data( data
, &data
->ps
.ncp
, sizeof(data
->ps
.ncp
) );
1619 if (wparam
) push_data( data
, (DWORD
*)wparam
, sizeof(DWORD
) );
1620 if (lparam
) push_data( data
, (DWORD
*)lparam
, sizeof(DWORD
) );
1624 MDINEXTMENU
*mnm
= (MDINEXTMENU
*)lparam
;
1625 data
->ps
.mnm
.hmenuIn
= wine_server_user_handle( mnm
->hmenuIn
);
1626 data
->ps
.mnm
.hmenuNext
= wine_server_user_handle( mnm
->hmenuNext
);
1627 data
->ps
.mnm
.hwndNext
= wine_server_user_handle( mnm
->hwndNext
);
1628 push_data( data
, &data
->ps
.mnm
, sizeof(data
->ps
.mnm
) );
1633 MDICREATESTRUCTW
*mcs
= (MDICREATESTRUCTW
*)lparam
;
1634 data
->ps
.mcs
.szClass
= pack_ptr( mcs
->szClass
);
1635 data
->ps
.mcs
.szTitle
= pack_ptr( mcs
->szTitle
);
1636 data
->ps
.mcs
.hOwner
= pack_ptr( mcs
->hOwner
);
1637 data
->ps
.mcs
.x
= mcs
->x
;
1638 data
->ps
.mcs
.y
= mcs
->y
;
1639 data
->ps
.mcs
.cx
= mcs
->cx
;
1640 data
->ps
.mcs
.cy
= mcs
->cy
;
1641 data
->ps
.mcs
.style
= mcs
->style
;
1642 data
->ps
.mcs
.lParam
= mcs
->lParam
;
1643 push_data( data
, &data
->ps
.mcs
, sizeof(data
->ps
.mcs
) );
1646 case WM_ASKCBFORMATNAME
:
1647 push_data( data
, (WCHAR
*)lparam
, (strlenW((WCHAR
*)lparam
) + 1) * sizeof(WCHAR
) );
1653 /***********************************************************************
1656 * Unpack a message reply received from another process.
1658 static void unpack_reply( HWND hwnd
, UINT message
, WPARAM wparam
, LPARAM lparam
,
1659 void *buffer
, size_t size
)
1661 union packed_structs
*ps
= buffer
;
1667 if (size
>= sizeof(ps
->cs
))
1669 CREATESTRUCTW
*cs
= (CREATESTRUCTW
*)lparam
;
1670 cs
->lpCreateParams
= unpack_ptr( ps
->cs
.lpCreateParams
);
1671 cs
->hInstance
= unpack_ptr( ps
->cs
.hInstance
);
1672 cs
->hMenu
= wine_server_ptr_handle( ps
->cs
.hMenu
);
1673 cs
->hwndParent
= wine_server_ptr_handle( ps
->cs
.hwndParent
);
1678 cs
->style
= ps
->cs
.style
;
1679 cs
->dwExStyle
= ps
->cs
.dwExStyle
;
1680 /* don't allow changing name and class pointers */
1684 case WM_ASKCBFORMATNAME
:
1685 memcpy( (WCHAR
*)lparam
, buffer
, min( wparam
*sizeof(WCHAR
), size
));
1687 case WM_GETMINMAXINFO
:
1688 memcpy( (MINMAXINFO
*)lparam
, buffer
, min( sizeof(MINMAXINFO
), size
));
1690 case WM_MEASUREITEM
:
1691 if (size
>= sizeof(ps
->mis
))
1693 MEASUREITEMSTRUCT
*mis
= (MEASUREITEMSTRUCT
*)lparam
;
1694 mis
->CtlType
= ps
->mis
.CtlType
;
1695 mis
->CtlID
= ps
->mis
.CtlID
;
1696 mis
->itemID
= ps
->mis
.itemID
;
1697 mis
->itemWidth
= ps
->mis
.itemWidth
;
1698 mis
->itemHeight
= ps
->mis
.itemHeight
;
1699 mis
->itemData
= (ULONG_PTR
)unpack_ptr( ps
->mis
.itemData
);
1702 case WM_WINDOWPOSCHANGING
:
1703 case WM_WINDOWPOSCHANGED
:
1704 if (size
>= sizeof(ps
->wp
))
1706 WINDOWPOS
*wp
= (WINDOWPOS
*)lparam
;
1707 wp
->hwnd
= wine_server_ptr_handle( ps
->wp
.hwnd
);
1708 wp
->hwndInsertAfter
= wine_server_ptr_handle( ps
->wp
.hwndInsertAfter
);
1713 wp
->flags
= ps
->wp
.flags
;
1717 if (lparam
&& size
>= sizeof(ps
->msg
))
1719 MSG
*msg
= (MSG
*)lparam
;
1720 msg
->hwnd
= wine_server_ptr_handle( ps
->msg
.hwnd
);
1721 msg
->message
= ps
->msg
.message
;
1722 msg
->wParam
= (ULONG_PTR
)unpack_ptr( ps
->msg
.wParam
);
1723 msg
->lParam
= (ULONG_PTR
)unpack_ptr( ps
->msg
.lParam
);
1724 msg
->time
= ps
->msg
.time
;
1725 msg
->pt
= ps
->msg
.pt
;
1728 case SBM_GETSCROLLINFO
:
1729 memcpy( (SCROLLINFO
*)lparam
, buffer
, min( sizeof(SCROLLINFO
), size
));
1731 case SBM_GETSCROLLBARINFO
:
1732 memcpy( (SCROLLBARINFO
*)lparam
, buffer
, min( sizeof(SCROLLBARINFO
), size
));
1735 case CB_GETDROPPEDCONTROLRECT
:
1736 case LB_GETITEMRECT
:
1739 memcpy( (RECT
*)lparam
, buffer
, min( sizeof(RECT
), size
));
1742 size
= min( size
, (size_t)*(WORD
*)lparam
);
1743 memcpy( (WCHAR
*)lparam
, buffer
, size
);
1745 case LB_GETSELITEMS
:
1746 memcpy( (UINT
*)lparam
, buffer
, min( wparam
*sizeof(UINT
), size
));
1750 memcpy( (WCHAR
*)lparam
, buffer
, size
);
1753 if (size
>= sizeof(ps
->mnm
))
1755 MDINEXTMENU
*mnm
= (MDINEXTMENU
*)lparam
;
1756 mnm
->hmenuIn
= wine_server_ptr_handle( ps
->mnm
.hmenuIn
);
1757 mnm
->hmenuNext
= wine_server_ptr_handle( ps
->mnm
.hmenuNext
);
1758 mnm
->hwndNext
= wine_server_ptr_handle( ps
->mnm
.hwndNext
);
1761 case WM_MDIGETACTIVE
:
1762 if (lparam
) memcpy( (BOOL
*)lparam
, buffer
, min( sizeof(BOOL
), size
));
1766 memcpy( (RECT
*)lparam
, buffer
, min( sizeof(RECT
), size
));
1767 else if (size
>= sizeof(ps
->ncp
))
1769 NCCALCSIZE_PARAMS
*ncp
= (NCCALCSIZE_PARAMS
*)lparam
;
1770 ncp
->rgrc
[0] = ps
->ncp
.rgrc
[0];
1771 ncp
->rgrc
[1] = ps
->ncp
.rgrc
[1];
1772 ncp
->rgrc
[2] = ps
->ncp
.rgrc
[2];
1773 ncp
->lppos
->hwnd
= wine_server_ptr_handle( ps
->ncp
.hwnd
);
1774 ncp
->lppos
->hwndInsertAfter
= wine_server_ptr_handle( ps
->ncp
.hwndInsertAfter
);
1775 ncp
->lppos
->x
= ps
->ncp
.x
;
1776 ncp
->lppos
->y
= ps
->ncp
.y
;
1777 ncp
->lppos
->cx
= ps
->ncp
.cx
;
1778 ncp
->lppos
->cy
= ps
->ncp
.cy
;
1779 ncp
->lppos
->flags
= ps
->ncp
.flags
;
1787 memcpy( (DWORD
*)wparam
, buffer
, min( sizeof(DWORD
), size
));
1788 if (size
<= sizeof(DWORD
)) break;
1789 size
-= sizeof(DWORD
);
1790 buffer
= (DWORD
*)buffer
+ 1;
1792 if (lparam
) memcpy( (DWORD
*)lparam
, buffer
, min( sizeof(DWORD
), size
));
1795 if (size
>= sizeof(ps
->mcs
))
1797 MDICREATESTRUCTW
*mcs
= (MDICREATESTRUCTW
*)lparam
;
1798 mcs
->hOwner
= unpack_ptr( ps
->mcs
.hOwner
);
1801 mcs
->cx
= ps
->mcs
.cx
;
1802 mcs
->cy
= ps
->mcs
.cy
;
1803 mcs
->style
= ps
->mcs
.style
;
1804 mcs
->lParam
= (LPARAM
)unpack_ptr( ps
->mcs
.lParam
);
1805 /* don't allow changing class and title pointers */
1809 ERR( "should not happen: unexpected message %x\n", message
);
1815 /***********************************************************************
1818 * Send a reply to a sent message.
1820 static void reply_message( struct received_message_info
*info
, LRESULT result
, BOOL remove
)
1822 struct packed_message data
;
1823 int i
, replied
= info
->flags
& ISMEX_REPLIED
;
1825 if (info
->flags
& ISMEX_NOTIFY
) return; /* notify messages don't get replies */
1826 if (!remove
&& replied
) return; /* replied already */
1828 memset( &data
, 0, sizeof(data
) );
1829 info
->flags
|= ISMEX_REPLIED
;
1831 if (info
->type
== MSG_OTHER_PROCESS
&& !replied
)
1833 pack_reply( info
->msg
.hwnd
, info
->msg
.message
, info
->msg
.wParam
,
1834 info
->msg
.lParam
, result
, &data
);
1837 SERVER_START_REQ( reply_message
)
1839 req
->result
= result
;
1840 req
->remove
= remove
;
1841 for (i
= 0; i
< data
.count
; i
++) wine_server_add_data( req
, data
.data
[i
], data
.size
[i
] );
1842 wine_server_call( req
);
1848 /***********************************************************************
1849 * handle_internal_message
1851 * Handle an internal Wine message instead of calling the window proc.
1853 static LRESULT
handle_internal_message( HWND hwnd
, UINT msg
, WPARAM wparam
, LPARAM lparam
)
1857 case WM_WINE_DESTROYWINDOW
:
1858 return WIN_DestroyWindow( hwnd
);
1859 case WM_WINE_SETWINDOWPOS
:
1860 if (is_desktop_window( hwnd
)) return 0;
1861 return USER_SetWindowPos( (WINDOWPOS
*)lparam
, 0, 0 );
1862 case WM_WINE_SHOWWINDOW
:
1863 if (is_desktop_window( hwnd
)) return 0;
1864 return ShowWindow( hwnd
, wparam
);
1865 case WM_WINE_SETPARENT
:
1866 if (is_desktop_window( hwnd
)) return 0;
1867 return (LRESULT
)SetParent( hwnd
, (HWND
)wparam
);
1868 case WM_WINE_SETWINDOWLONG
:
1869 return WIN_SetWindowLong( hwnd
, (short)LOWORD(wparam
), HIWORD(wparam
), lparam
, TRUE
);
1870 case WM_WINE_SETSTYLE
:
1871 if (is_desktop_window( hwnd
)) return 0;
1872 return WIN_SetStyle(hwnd
, wparam
, lparam
);
1873 case WM_WINE_SETACTIVEWINDOW
:
1874 if (!wparam
&& GetForegroundWindow() == hwnd
) return 0;
1875 return (LRESULT
)SetActiveWindow( (HWND
)wparam
);
1876 case WM_WINE_KEYBOARD_LL_HOOK
:
1877 case WM_WINE_MOUSE_LL_HOOK
:
1879 struct hook_extra_info
*h_extra
= (struct hook_extra_info
*)lparam
;
1881 return call_current_hook( h_extra
->handle
, HC_ACTION
, wparam
, h_extra
->lparam
);
1883 case WM_WINE_CLIPCURSOR
:
1887 GetClipCursor( &rect
);
1888 return USER_Driver
->pClipCursor( &rect
);
1890 return USER_Driver
->pClipCursor( NULL
);
1892 if (msg
>= WM_WINE_FIRST_DRIVER_MSG
&& msg
<= WM_WINE_LAST_DRIVER_MSG
)
1893 return USER_Driver
->pWindowMessage( hwnd
, msg
, wparam
, lparam
);
1894 FIXME( "unknown internal message %x\n", msg
);
1899 /* since the WM_DDE_ACK response to a WM_DDE_EXECUTE message should contain the handle
1900 * to the memory handle, we keep track (in the server side) of all pairs of handle
1901 * used (the client passes its value and the content of the memory handle), and
1902 * the server stored both values (the client, and the local one, created after the
1903 * content). When a ACK message is generated, the list of pair is searched for a
1904 * matching pair, so that the client memory handle can be returned.
1907 HGLOBAL client_hMem
;
1908 HGLOBAL server_hMem
;
1911 static struct DDE_pair
* dde_pairs
;
1912 static int dde_num_alloc
;
1913 static int dde_num_used
;
1915 static CRITICAL_SECTION dde_crst
;
1916 static CRITICAL_SECTION_DEBUG critsect_debug
=
1919 { &critsect_debug
.ProcessLocksList
, &critsect_debug
.ProcessLocksList
},
1920 0, 0, { (DWORD_PTR
)(__FILE__
": dde_crst") }
1922 static CRITICAL_SECTION dde_crst
= { &critsect_debug
, -1, 0, 0, 0, 0 };
1924 static BOOL
dde_add_pair(HGLOBAL chm
, HGLOBAL shm
)
1929 EnterCriticalSection(&dde_crst
);
1931 /* now remember the pair of hMem on both sides */
1932 if (dde_num_used
== dde_num_alloc
)
1934 struct DDE_pair
* tmp
;
1936 tmp
= HeapReAlloc( GetProcessHeap(), 0, dde_pairs
,
1937 (dde_num_alloc
+ GROWBY
) * sizeof(struct DDE_pair
));
1939 tmp
= HeapAlloc( GetProcessHeap(), 0,
1940 (dde_num_alloc
+ GROWBY
) * sizeof(struct DDE_pair
));
1944 LeaveCriticalSection(&dde_crst
);
1948 /* zero out newly allocated part */
1949 memset(&dde_pairs
[dde_num_alloc
], 0, GROWBY
* sizeof(struct DDE_pair
));
1950 dde_num_alloc
+= GROWBY
;
1953 for (i
= 0; i
< dde_num_alloc
; i
++)
1955 if (dde_pairs
[i
].server_hMem
== 0)
1957 dde_pairs
[i
].client_hMem
= chm
;
1958 dde_pairs
[i
].server_hMem
= shm
;
1963 LeaveCriticalSection(&dde_crst
);
1967 static HGLOBAL
dde_get_pair(HGLOBAL shm
)
1972 EnterCriticalSection(&dde_crst
);
1973 for (i
= 0; i
< dde_num_alloc
; i
++)
1975 if (dde_pairs
[i
].server_hMem
== shm
)
1977 /* free this pair */
1978 dde_pairs
[i
].server_hMem
= 0;
1980 ret
= dde_pairs
[i
].client_hMem
;
1984 LeaveCriticalSection(&dde_crst
);
1988 /***********************************************************************
1991 * Post a DDE message
1993 static BOOL
post_dde_message( struct packed_message
*data
, const struct send_message_info
*info
)
1997 UINT_PTR uiLo
, uiHi
;
1999 HGLOBAL hunlock
= 0;
2004 if (!UnpackDDElParam( info
->msg
, info
->lparam
, &uiLo
, &uiHi
))
2010 /* DDE messages which don't require packing are:
2019 /* uiHi should contain a hMem from WM_DDE_EXECUTE */
2020 HGLOBAL h
= dde_get_pair( (HANDLE
)uiHi
);
2023 hpack
= pack_ptr( h
);
2024 /* send back the value of h on the other side */
2025 push_data( data
, &hpack
, sizeof(hpack
) );
2027 TRACE( "send dde-ack %lx %08lx => %p\n", uiLo
, uiHi
, h
);
2032 /* uiHi should contain either an atom or 0 */
2033 TRACE( "send dde-ack %lx atom=%lx\n", uiLo
, uiHi
);
2034 lp
= MAKELONG( uiLo
, uiHi
);
2043 size
= GlobalSize( (HGLOBAL
)uiLo
) ;
2044 if ((info
->msg
== WM_DDE_ADVISE
&& size
< sizeof(DDEADVISE
)) ||
2045 (info
->msg
== WM_DDE_DATA
&& size
< FIELD_OFFSET(DDEDATA
, Value
)) ||
2046 (info
->msg
== WM_DDE_POKE
&& size
< FIELD_OFFSET(DDEPOKE
, Value
))
2050 else if (info
->msg
!= WM_DDE_DATA
) return FALSE
;
2055 if ((ptr
= GlobalLock( (HGLOBAL
)uiLo
) ))
2057 DDEDATA
*dde_data
= ptr
;
2058 TRACE("unused %d, fResponse %d, fRelease %d, fDeferUpd %d, fAckReq %d, cfFormat %d\n",
2059 dde_data
->unused
, dde_data
->fResponse
, dde_data
->fRelease
,
2060 dde_data
->reserved
, dde_data
->fAckReq
, dde_data
->cfFormat
);
2061 push_data( data
, ptr
, size
);
2062 hunlock
= (HGLOBAL
)uiLo
;
2065 TRACE( "send ddepack %u %lx\n", size
, uiHi
);
2067 case WM_DDE_EXECUTE
:
2070 if ((ptr
= GlobalLock( (HGLOBAL
)info
->lparam
) ))
2072 push_data(data
, ptr
, GlobalSize( (HGLOBAL
)info
->lparam
));
2073 /* so that the other side can send it back on ACK */
2075 hunlock
= (HGLOBAL
)info
->lparam
;
2080 SERVER_START_REQ( send_message
)
2082 req
->id
= info
->dest_tid
;
2083 req
->type
= info
->type
;
2085 req
->win
= wine_server_user_handle( info
->hwnd
);
2086 req
->msg
= info
->msg
;
2087 req
->wparam
= info
->wparam
;
2089 req
->timeout
= TIMEOUT_INFINITE
;
2090 for (i
= 0; i
< data
->count
; i
++)
2091 wine_server_add_data( req
, data
->data
[i
], data
->size
[i
] );
2092 if ((res
= wine_server_call( req
)))
2094 if (res
== STATUS_INVALID_PARAMETER
)
2095 /* FIXME: find a STATUS_ value for this one */
2096 SetLastError( ERROR_INVALID_THREAD_ID
);
2098 SetLastError( RtlNtStatusToDosError(res
) );
2101 FreeDDElParam(info
->msg
, info
->lparam
);
2104 if (hunlock
) GlobalUnlock(hunlock
);
2109 /***********************************************************************
2110 * unpack_dde_message
2112 * Unpack a posted DDE message received from another process.
2114 static BOOL
unpack_dde_message( HWND hwnd
, UINT message
, WPARAM
*wparam
, LPARAM
*lparam
,
2115 void **buffer
, size_t size
)
2117 UINT_PTR uiLo
, uiHi
;
2127 /* hMem is being passed */
2128 if (size
!= sizeof(hpack
)) return FALSE
;
2129 if (!buffer
|| !*buffer
) return FALSE
;
2131 memcpy( &hpack
, *buffer
, size
);
2132 hMem
= unpack_ptr( hpack
);
2133 uiHi
= (UINT_PTR
)hMem
;
2134 TRACE("recv dde-ack %lx mem=%lx[%lx]\n", uiLo
, uiHi
, GlobalSize( hMem
));
2138 uiLo
= LOWORD( *lparam
);
2139 uiHi
= HIWORD( *lparam
);
2140 TRACE("recv dde-ack %lx atom=%lx\n", uiLo
, uiHi
);
2142 *lparam
= PackDDElParam( WM_DDE_ACK
, uiLo
, uiHi
);
2147 if ((!buffer
|| !*buffer
) && message
!= WM_DDE_DATA
) return FALSE
;
2151 if (!(hMem
= GlobalAlloc( GMEM_MOVEABLE
|GMEM_DDESHARE
, size
)))
2153 if ((ptr
= GlobalLock( hMem
)))
2155 memcpy( ptr
, *buffer
, size
);
2156 GlobalUnlock( hMem
);
2164 uiLo
= (UINT_PTR
)hMem
;
2166 *lparam
= PackDDElParam( message
, uiLo
, uiHi
);
2168 case WM_DDE_EXECUTE
:
2171 if (!buffer
|| !*buffer
) return FALSE
;
2172 if (!(hMem
= GlobalAlloc( GMEM_MOVEABLE
|GMEM_DDESHARE
, size
))) return FALSE
;
2173 if ((ptr
= GlobalLock( hMem
)))
2175 memcpy( ptr
, *buffer
, size
);
2176 GlobalUnlock( hMem
);
2177 TRACE( "exec: pairing c=%08lx s=%p\n", *lparam
, hMem
);
2178 if (!dde_add_pair( (HGLOBAL
)*lparam
, hMem
))
2189 } else return FALSE
;
2190 *lparam
= (LPARAM
)hMem
;
2196 /***********************************************************************
2199 * Call a window procedure and the corresponding hooks.
2201 static LRESULT
call_window_proc( HWND hwnd
, UINT msg
, WPARAM wparam
, LPARAM lparam
,
2202 BOOL unicode
, BOOL same_thread
, enum wm_char_mapping mapping
)
2206 CWPRETSTRUCT cwpret
;
2208 if (msg
& 0x80000000)
2210 result
= handle_internal_message( hwnd
, msg
, wparam
, lparam
);
2214 /* first the WH_CALLWNDPROC hook */
2215 hwnd
= WIN_GetFullHandle( hwnd
);
2216 cwp
.lParam
= lparam
;
2217 cwp
.wParam
= wparam
;
2220 HOOK_CallHooks( WH_CALLWNDPROC
, HC_ACTION
, same_thread
, (LPARAM
)&cwp
, unicode
);
2222 /* now call the window procedure */
2223 if (!WINPROC_call_window( hwnd
, msg
, wparam
, lparam
, &result
, unicode
, mapping
)) goto done
;
2225 /* and finally the WH_CALLWNDPROCRET hook */
2226 cwpret
.lResult
= result
;
2227 cwpret
.lParam
= lparam
;
2228 cwpret
.wParam
= wparam
;
2229 cwpret
.message
= msg
;
2231 HOOK_CallHooks( WH_CALLWNDPROCRET
, HC_ACTION
, same_thread
, (LPARAM
)&cwpret
, unicode
);
2237 /***********************************************************************
2238 * send_parent_notify
2240 * Send a WM_PARENTNOTIFY to all ancestors of the given window, unless
2241 * the window has the WS_EX_NOPARENTNOTIFY style.
2243 static void send_parent_notify( HWND hwnd
, WORD event
, WORD idChild
, POINT pt
)
2245 /* pt has to be in the client coordinates of the parent window */
2246 MapWindowPoints( 0, hwnd
, &pt
, 1 );
2251 if (!(GetWindowLongW( hwnd
, GWL_STYLE
) & WS_CHILD
)) break;
2252 if (GetWindowLongW( hwnd
, GWL_EXSTYLE
) & WS_EX_NOPARENTNOTIFY
) break;
2253 if (!(parent
= GetParent(hwnd
))) break;
2254 if (parent
== GetDesktopWindow()) break;
2255 MapWindowPoints( hwnd
, parent
, &pt
, 1 );
2257 SendMessageW( hwnd
, WM_PARENTNOTIFY
,
2258 MAKEWPARAM( event
, idChild
), MAKELPARAM( pt
.x
, pt
.y
) );
2263 /***********************************************************************
2264 * accept_hardware_message
2266 * Tell the server we have passed the message to the app
2267 * (even though we may end up dropping it later on)
2269 static void accept_hardware_message( UINT hw_id
, BOOL remove
)
2271 SERVER_START_REQ( accept_hardware_message
)
2274 req
->remove
= remove
;
2275 if (wine_server_call( req
))
2276 FIXME("Failed to reply to MSG_HARDWARE message. Message may not be removed from queue.\n");
2282 static BOOL
process_rawinput_message( MSG
*msg
, const struct hardware_msg_data
*msg_data
)
2284 struct user_thread_info
*thread_info
= get_user_thread_info();
2285 RAWINPUT
*rawinput
= thread_info
->rawinput
;
2289 thread_info
->rawinput
= HeapAlloc( GetProcessHeap(), 0, sizeof(*rawinput
) );
2290 if (!(rawinput
= thread_info
->rawinput
)) return FALSE
;
2293 rawinput
->header
.dwType
= msg_data
->rawinput
.type
;
2294 if (msg_data
->rawinput
.type
== RIM_TYPEMOUSE
)
2296 static const unsigned int button_flags
[] =
2298 0, /* MOUSEEVENTF_MOVE */
2299 RI_MOUSE_LEFT_BUTTON_DOWN
, /* MOUSEEVENTF_LEFTDOWN */
2300 RI_MOUSE_LEFT_BUTTON_UP
, /* MOUSEEVENTF_LEFTUP */
2301 RI_MOUSE_RIGHT_BUTTON_DOWN
, /* MOUSEEVENTF_RIGHTDOWN */
2302 RI_MOUSE_RIGHT_BUTTON_UP
, /* MOUSEEVENTF_RIGHTUP */
2303 RI_MOUSE_MIDDLE_BUTTON_DOWN
, /* MOUSEEVENTF_MIDDLEDOWN */
2304 RI_MOUSE_MIDDLE_BUTTON_UP
, /* MOUSEEVENTF_MIDDLEUP */
2308 rawinput
->header
.dwSize
= FIELD_OFFSET(RAWINPUT
, data
) + sizeof(RAWMOUSE
);
2309 rawinput
->header
.hDevice
= WINE_MOUSE_HANDLE
;
2310 rawinput
->header
.wParam
= 0;
2312 rawinput
->data
.mouse
.usFlags
= MOUSE_MOVE_RELATIVE
;
2313 rawinput
->data
.mouse
.u
.s
.usButtonFlags
= 0;
2314 rawinput
->data
.mouse
.u
.s
.usButtonData
= 0;
2315 for (i
= 1; i
< ARRAY_SIZE(button_flags
); ++i
)
2317 if (msg_data
->flags
& (1 << i
))
2318 rawinput
->data
.mouse
.u
.s
.usButtonFlags
|= button_flags
[i
];
2320 if (msg_data
->flags
& MOUSEEVENTF_WHEEL
)
2322 rawinput
->data
.mouse
.u
.s
.usButtonFlags
|= RI_MOUSE_WHEEL
;
2323 rawinput
->data
.mouse
.u
.s
.usButtonData
= msg_data
->rawinput
.mouse
.data
;
2325 if (msg_data
->flags
& MOUSEEVENTF_HWHEEL
)
2327 rawinput
->data
.mouse
.u
.s
.usButtonFlags
|= RI_MOUSE_HORIZONTAL_WHEEL
;
2328 rawinput
->data
.mouse
.u
.s
.usButtonData
= msg_data
->rawinput
.mouse
.data
;
2330 if (msg_data
->flags
& MOUSEEVENTF_XDOWN
)
2332 if (msg_data
->rawinput
.mouse
.data
== XBUTTON1
)
2333 rawinput
->data
.mouse
.u
.s
.usButtonFlags
|= RI_MOUSE_BUTTON_4_DOWN
;
2334 else if (msg_data
->rawinput
.mouse
.data
== XBUTTON2
)
2335 rawinput
->data
.mouse
.u
.s
.usButtonFlags
|= RI_MOUSE_BUTTON_5_DOWN
;
2337 if (msg_data
->flags
& MOUSEEVENTF_XUP
)
2339 if (msg_data
->rawinput
.mouse
.data
== XBUTTON1
)
2340 rawinput
->data
.mouse
.u
.s
.usButtonFlags
|= RI_MOUSE_BUTTON_4_UP
;
2341 else if (msg_data
->rawinput
.mouse
.data
== XBUTTON2
)
2342 rawinput
->data
.mouse
.u
.s
.usButtonFlags
|= RI_MOUSE_BUTTON_5_UP
;
2345 rawinput
->data
.mouse
.ulRawButtons
= 0;
2346 rawinput
->data
.mouse
.lLastX
= msg_data
->rawinput
.mouse
.x
;
2347 rawinput
->data
.mouse
.lLastY
= msg_data
->rawinput
.mouse
.y
;
2348 rawinput
->data
.mouse
.ulExtraInformation
= msg_data
->info
;
2350 else if (msg_data
->rawinput
.type
== RIM_TYPEKEYBOARD
)
2352 rawinput
->header
.dwSize
= FIELD_OFFSET(RAWINPUT
, data
) + sizeof(RAWKEYBOARD
);
2353 rawinput
->header
.hDevice
= WINE_KEYBOARD_HANDLE
;
2354 rawinput
->header
.wParam
= 0;
2356 rawinput
->data
.keyboard
.MakeCode
= msg_data
->rawinput
.kbd
.scan
;
2357 rawinput
->data
.keyboard
.Flags
= msg_data
->flags
& KEYEVENTF_KEYUP
? RI_KEY_BREAK
: RI_KEY_MAKE
;
2358 if (msg_data
->flags
& KEYEVENTF_EXTENDEDKEY
) rawinput
->data
.keyboard
.Flags
|= RI_KEY_E0
;
2359 rawinput
->data
.keyboard
.Reserved
= 0;
2361 switch (msg_data
->rawinput
.kbd
.vkey
)
2365 rawinput
->data
.keyboard
.VKey
= VK_SHIFT
;
2366 rawinput
->data
.keyboard
.Flags
&= ~RI_KEY_E0
;
2370 rawinput
->data
.keyboard
.VKey
= VK_CONTROL
;
2374 rawinput
->data
.keyboard
.VKey
= VK_MENU
;
2377 rawinput
->data
.keyboard
.VKey
= msg_data
->rawinput
.kbd
.vkey
;
2381 rawinput
->data
.keyboard
.Message
= msg_data
->rawinput
.kbd
.message
;
2382 rawinput
->data
.keyboard
.ExtraInformation
= msg_data
->info
;
2386 FIXME("Unhandled rawinput type %#x.\n", msg_data
->rawinput
.type
);
2390 msg
->lParam
= (LPARAM
)rawinput
;
2391 msg
->pt
= point_phys_to_win_dpi( msg
->hwnd
, msg
->pt
);
2395 /***********************************************************************
2396 * process_keyboard_message
2398 * returns TRUE if the contents of 'msg' should be passed to the application
2400 static BOOL
process_keyboard_message( MSG
*msg
, UINT hw_id
, HWND hwnd_filter
,
2401 UINT first
, UINT last
, BOOL remove
)
2405 if (msg
->message
== WM_KEYDOWN
|| msg
->message
== WM_SYSKEYDOWN
||
2406 msg
->message
== WM_KEYUP
|| msg
->message
== WM_SYSKEYUP
)
2407 switch (msg
->wParam
)
2409 case VK_LSHIFT
: case VK_RSHIFT
:
2410 msg
->wParam
= VK_SHIFT
;
2412 case VK_LCONTROL
: case VK_RCONTROL
:
2413 msg
->wParam
= VK_CONTROL
;
2415 case VK_LMENU
: case VK_RMENU
:
2416 msg
->wParam
= VK_MENU
;
2420 /* FIXME: is this really the right place for this hook? */
2421 event
.message
= msg
->message
;
2422 event
.hwnd
= msg
->hwnd
;
2423 event
.time
= msg
->time
;
2424 event
.paramL
= (msg
->wParam
& 0xFF) | (HIWORD(msg
->lParam
) << 8);
2425 event
.paramH
= msg
->lParam
& 0x7FFF;
2426 if (HIWORD(msg
->lParam
) & 0x0100) event
.paramH
|= 0x8000; /* special_key - bit */
2427 HOOK_CallHooks( WH_JOURNALRECORD
, HC_ACTION
, 0, (LPARAM
)&event
, TRUE
);
2429 /* check message filters */
2430 if (msg
->message
< first
|| msg
->message
> last
) return FALSE
;
2431 if (!check_hwnd_filter( msg
, hwnd_filter
)) return FALSE
;
2435 if((msg
->message
== WM_KEYDOWN
) &&
2436 (msg
->hwnd
!= GetDesktopWindow()))
2438 /* Handle F1 key by sending out WM_HELP message */
2439 if (msg
->wParam
== VK_F1
)
2441 PostMessageW( msg
->hwnd
, WM_KEYF1
, 0, 0 );
2443 else if(msg
->wParam
>= VK_BROWSER_BACK
&&
2444 msg
->wParam
<= VK_LAUNCH_APP2
)
2446 /* FIXME: Process keystate */
2447 SendMessageW(msg
->hwnd
, WM_APPCOMMAND
, (WPARAM
)msg
->hwnd
, MAKELPARAM(0, (FAPPCOMMAND_KEY
| (msg
->wParam
- VK_BROWSER_BACK
+ 1))));
2450 else if (msg
->message
== WM_KEYUP
)
2452 /* Handle VK_APPS key by posting a WM_CONTEXTMENU message */
2453 if (msg
->wParam
== VK_APPS
&& !MENU_IsMenuActive())
2454 PostMessageW(msg
->hwnd
, WM_CONTEXTMENU
, (WPARAM
)msg
->hwnd
, -1);
2458 if (HOOK_CallHooks( WH_KEYBOARD
, remove
? HC_ACTION
: HC_NOREMOVE
,
2459 LOWORD(msg
->wParam
), msg
->lParam
, TRUE
))
2461 /* skip this message */
2462 HOOK_CallHooks( WH_CBT
, HCBT_KEYSKIPPED
, LOWORD(msg
->wParam
), msg
->lParam
, TRUE
);
2463 accept_hardware_message( hw_id
, TRUE
);
2466 accept_hardware_message( hw_id
, remove
);
2467 msg
->pt
= point_phys_to_win_dpi( msg
->hwnd
, msg
->pt
);
2469 if ( remove
&& msg
->message
== WM_KEYDOWN
)
2470 if (ImmProcessKey(msg
->hwnd
, GetKeyboardLayout(0), msg
->wParam
, msg
->lParam
, 0) )
2471 msg
->wParam
= VK_PROCESSKEY
;
2477 /***********************************************************************
2478 * process_mouse_message
2480 * returns TRUE if the contents of 'msg' should be passed to the application
2482 static BOOL
process_mouse_message( MSG
*msg
, UINT hw_id
, ULONG_PTR extra_info
, HWND hwnd_filter
,
2483 UINT first
, UINT last
, BOOL remove
)
2492 MOUSEHOOKSTRUCTEX hook
;
2496 /* find the window to dispatch this mouse message to */
2498 info
.cbSize
= sizeof(info
);
2499 GetGUIThreadInfo( GetCurrentThreadId(), &info
);
2500 if (info
.hwndCapture
)
2503 msg
->hwnd
= info
.hwndCapture
;
2507 HWND orig
= msg
->hwnd
;
2509 msg
->hwnd
= WINPOS_WindowFromPoint( msg
->hwnd
, msg
->pt
, &hittest
);
2510 if (!msg
->hwnd
) /* As a heuristic, try the next window if it's the owner of orig */
2512 HWND next
= GetWindow( orig
, GW_HWNDNEXT
);
2514 if (next
&& GetWindow( orig
, GW_OWNER
) == next
&& WIN_IsCurrentThread( next
))
2515 msg
->hwnd
= WINPOS_WindowFromPoint( next
, msg
->pt
, &hittest
);
2519 if (!msg
->hwnd
|| !WIN_IsCurrentThread( msg
->hwnd
))
2521 accept_hardware_message( hw_id
, TRUE
);
2525 msg
->pt
= point_phys_to_win_dpi( msg
->hwnd
, msg
->pt
);
2526 SetThreadDpiAwarenessContext( GetWindowDpiAwarenessContext( msg
->hwnd
));
2528 /* FIXME: is this really the right place for this hook? */
2529 event
.message
= msg
->message
;
2530 event
.time
= msg
->time
;
2531 event
.hwnd
= msg
->hwnd
;
2532 event
.paramL
= msg
->pt
.x
;
2533 event
.paramH
= msg
->pt
.y
;
2534 HOOK_CallHooks( WH_JOURNALRECORD
, HC_ACTION
, 0, (LPARAM
)&event
, TRUE
);
2536 if (!check_hwnd_filter( msg
, hwnd_filter
)) return FALSE
;
2539 message
= msg
->message
;
2540 wparam
= msg
->wParam
;
2541 /* Note: windows has no concept of a non-client wheel message */
2542 if (message
!= WM_MOUSEWHEEL
)
2544 if (hittest
!= HTCLIENT
)
2546 message
+= WM_NCMOUSEMOVE
- WM_MOUSEMOVE
;
2551 /* coordinates don't get translated while tracking a menu */
2552 /* FIXME: should differentiate popups and top-level menus */
2553 if (!(info
.flags
& GUI_INMENUMODE
))
2554 ScreenToClient( msg
->hwnd
, &pt
);
2557 msg
->lParam
= MAKELONG( pt
.x
, pt
.y
);
2559 /* translate double clicks */
2561 if ((msg
->message
== WM_LBUTTONDOWN
) ||
2562 (msg
->message
== WM_RBUTTONDOWN
) ||
2563 (msg
->message
== WM_MBUTTONDOWN
) ||
2564 (msg
->message
== WM_XBUTTONDOWN
))
2566 BOOL update
= remove
;
2568 /* translate double clicks -
2569 * note that ...MOUSEMOVEs can slip in between
2570 * ...BUTTONDOWN and ...BUTTONDBLCLK messages */
2572 if ((info
.flags
& (GUI_INMENUMODE
|GUI_INMOVESIZE
)) ||
2573 hittest
!= HTCLIENT
||
2574 (GetClassLongA( msg
->hwnd
, GCL_STYLE
) & CS_DBLCLKS
))
2576 if ((msg
->message
== clk_msg
.message
) &&
2577 (msg
->hwnd
== clk_msg
.hwnd
) &&
2578 (msg
->wParam
== clk_msg
.wParam
) &&
2579 (msg
->time
- clk_msg
.time
< GetDoubleClickTime()) &&
2580 (abs(msg
->pt
.x
- clk_msg
.pt
.x
) < GetSystemMetrics(SM_CXDOUBLECLK
)/2) &&
2581 (abs(msg
->pt
.y
- clk_msg
.pt
.y
) < GetSystemMetrics(SM_CYDOUBLECLK
)/2))
2583 message
+= (WM_LBUTTONDBLCLK
- WM_LBUTTONDOWN
);
2586 clk_msg
.message
= 0; /* clear the double click conditions */
2591 if (message
< first
|| message
> last
) return FALSE
;
2592 /* update static double click conditions */
2593 if (update
) clk_msg
= *msg
;
2597 if (message
< first
|| message
> last
) return FALSE
;
2599 msg
->wParam
= wparam
;
2601 /* message is accepted now (but may still get dropped) */
2603 hook
.s
.pt
= msg
->pt
;
2604 hook
.s
.hwnd
= msg
->hwnd
;
2605 hook
.s
.wHitTestCode
= hittest
;
2606 hook
.s
.dwExtraInfo
= extra_info
;
2607 hook
.mouseData
= msg
->wParam
;
2608 if (HOOK_CallHooks( WH_MOUSE
, remove
? HC_ACTION
: HC_NOREMOVE
,
2609 message
, (LPARAM
)&hook
, TRUE
))
2611 hook
.s
.pt
= msg
->pt
;
2612 hook
.s
.hwnd
= msg
->hwnd
;
2613 hook
.s
.wHitTestCode
= hittest
;
2614 hook
.s
.dwExtraInfo
= extra_info
;
2615 hook
.mouseData
= msg
->wParam
;
2616 HOOK_CallHooks( WH_CBT
, HCBT_CLICKSKIPPED
, message
, (LPARAM
)&hook
, TRUE
);
2617 accept_hardware_message( hw_id
, TRUE
);
2621 if ((hittest
== HTERROR
) || (hittest
== HTNOWHERE
))
2623 SendMessageW( msg
->hwnd
, WM_SETCURSOR
, (WPARAM
)msg
->hwnd
,
2624 MAKELONG( hittest
, msg
->message
));
2625 accept_hardware_message( hw_id
, TRUE
);
2629 accept_hardware_message( hw_id
, remove
);
2631 if (!remove
|| info
.hwndCapture
)
2633 msg
->message
= message
;
2639 if ((msg
->message
== WM_LBUTTONDOWN
) ||
2640 (msg
->message
== WM_RBUTTONDOWN
) ||
2641 (msg
->message
== WM_MBUTTONDOWN
) ||
2642 (msg
->message
== WM_XBUTTONDOWN
))
2644 /* Send the WM_PARENTNOTIFY,
2645 * note that even for double/nonclient clicks
2646 * notification message is still WM_L/M/RBUTTONDOWN.
2648 send_parent_notify( msg
->hwnd
, msg
->message
, 0, msg
->pt
);
2650 /* Activate the window if needed */
2652 if (msg
->hwnd
!= info
.hwndActive
)
2654 HWND hwndTop
= GetAncestor( msg
->hwnd
, GA_ROOT
);
2656 if ((GetWindowLongW( hwndTop
, GWL_STYLE
) & (WS_POPUP
|WS_CHILD
)) != WS_CHILD
)
2658 LONG ret
= SendMessageW( msg
->hwnd
, WM_MOUSEACTIVATE
, (WPARAM
)hwndTop
,
2659 MAKELONG( hittest
, msg
->message
) );
2662 case MA_NOACTIVATEANDEAT
:
2667 case MA_ACTIVATEANDEAT
:
2672 if (!FOCUS_MouseActivate( hwndTop
)) eatMsg
= TRUE
;
2675 WARN( "unknown WM_MOUSEACTIVATE code %d\n", ret
);
2682 /* send the WM_SETCURSOR message */
2684 /* Windows sends the normal mouse message as the message parameter
2685 in the WM_SETCURSOR message even if it's non-client mouse message */
2686 SendMessageW( msg
->hwnd
, WM_SETCURSOR
, (WPARAM
)msg
->hwnd
, MAKELONG( hittest
, msg
->message
));
2688 msg
->message
= message
;
2693 /***********************************************************************
2694 * process_hardware_message
2696 * Process a hardware message; return TRUE if message should be passed on to the app
2698 static BOOL
process_hardware_message( MSG
*msg
, UINT hw_id
, const struct hardware_msg_data
*msg_data
,
2699 HWND hwnd_filter
, UINT first
, UINT last
, BOOL remove
)
2701 DPI_AWARENESS_CONTEXT context
;
2704 /* hardware messages are always in physical coords */
2705 context
= SetThreadDpiAwarenessContext( DPI_AWARENESS_CONTEXT_PER_MONITOR_AWARE
);
2707 if (msg
->message
== WM_INPUT
)
2708 ret
= process_rawinput_message( msg
, msg_data
);
2709 else if (is_keyboard_message( msg
->message
))
2710 ret
= process_keyboard_message( msg
, hw_id
, hwnd_filter
, first
, last
, remove
);
2711 else if (is_mouse_message( msg
->message
))
2712 ret
= process_mouse_message( msg
, hw_id
, msg_data
->info
, hwnd_filter
, first
, last
, remove
);
2714 ERR( "unknown message type %x\n", msg
->message
);
2715 SetThreadDpiAwarenessContext( context
);
2720 /***********************************************************************
2721 * call_sendmsg_callback
2723 * Call the callback function of SendMessageCallback.
2725 static inline void call_sendmsg_callback( SENDASYNCPROC callback
, HWND hwnd
, UINT msg
,
2726 ULONG_PTR data
, LRESULT result
)
2728 if (!callback
) return;
2730 TRACE_(relay
)( "\1Call message callback %p (hwnd=%p,msg=%s,data=%08lx,result=%08lx)\n",
2731 callback
, hwnd
, SPY_GetMsgName( msg
, hwnd
), data
, result
);
2732 callback( hwnd
, msg
, data
, result
);
2733 TRACE_(relay
)( "\1Ret message callback %p (hwnd=%p,msg=%s,data=%08lx,result=%08lx)\n",
2734 callback
, hwnd
, SPY_GetMsgName( msg
, hwnd
), data
, result
);
2738 /***********************************************************************
2741 * Peek for a message matching the given parameters. Return FALSE if none available.
2742 * All pending sent messages are processed before returning.
2744 static BOOL
peek_message( MSG
*msg
, HWND hwnd
, UINT first
, UINT last
, UINT flags
, UINT changed_mask
)
2747 struct user_thread_info
*thread_info
= get_user_thread_info();
2748 struct received_message_info info
, *old_info
;
2749 unsigned int hw_id
= 0; /* id of previous hardware message */
2751 size_t buffer_size
= 256;
2753 if (!(buffer
= HeapAlloc( GetProcessHeap(), 0, buffer_size
))) return FALSE
;
2755 if (!first
&& !last
) last
= ~0;
2756 if (hwnd
== HWND_BROADCAST
) hwnd
= HWND_TOPMOST
;
2762 const message_data_t
*msg_data
= buffer
;
2764 SERVER_START_REQ( get_message
)
2767 req
->get_win
= wine_server_user_handle( hwnd
);
2768 req
->get_first
= first
;
2769 req
->get_last
= last
;
2771 req
->wake_mask
= changed_mask
& (QS_SENDMESSAGE
| QS_SMRESULT
);
2772 req
->changed_mask
= changed_mask
;
2773 wine_server_set_reply( req
, buffer
, buffer_size
);
2774 if (!(res
= wine_server_call( req
)))
2776 size
= wine_server_reply_size( reply
);
2777 info
.type
= reply
->type
;
2778 info
.msg
.hwnd
= wine_server_ptr_handle( reply
->win
);
2779 info
.msg
.message
= reply
->msg
;
2780 info
.msg
.wParam
= reply
->wparam
;
2781 info
.msg
.lParam
= reply
->lparam
;
2782 info
.msg
.time
= reply
->time
;
2783 info
.msg
.pt
.x
= reply
->x
;
2784 info
.msg
.pt
.y
= reply
->y
;
2786 thread_info
->active_hooks
= reply
->active_hooks
;
2788 else buffer_size
= reply
->total
;
2794 HeapFree( GetProcessHeap(), 0, buffer
);
2795 if (res
== STATUS_PENDING
)
2797 thread_info
->wake_mask
= changed_mask
& (QS_SENDMESSAGE
| QS_SMRESULT
);
2798 thread_info
->changed_mask
= changed_mask
;
2800 if (res
!= STATUS_BUFFER_OVERFLOW
) return FALSE
;
2801 if (!(buffer
= HeapAlloc( GetProcessHeap(), 0, buffer_size
))) return FALSE
;
2805 TRACE( "got type %d msg %x (%s) hwnd %p wp %lx lp %lx\n",
2806 info
.type
, info
.msg
.message
,
2807 (info
.type
== MSG_WINEVENT
) ? "MSG_WINEVENT" : SPY_GetMsgName(info
.msg
.message
, info
.msg
.hwnd
),
2808 info
.msg
.hwnd
, info
.msg
.wParam
, info
.msg
.lParam
);
2814 info
.flags
= ISMEX_SEND
;
2817 info
.flags
= ISMEX_NOTIFY
;
2820 info
.flags
= ISMEX_CALLBACK
;
2822 case MSG_CALLBACK_RESULT
:
2823 if (size
>= sizeof(msg_data
->callback
))
2824 call_sendmsg_callback( wine_server_get_ptr(msg_data
->callback
.callback
),
2825 info
.msg
.hwnd
, info
.msg
.message
,
2826 msg_data
->callback
.data
, msg_data
->callback
.result
);
2829 if (size
>= sizeof(msg_data
->winevent
))
2831 WINEVENTPROC hook_proc
;
2832 HMODULE free_module
= 0;
2834 hook_proc
= wine_server_get_ptr( msg_data
->winevent
.hook_proc
);
2835 size
-= sizeof(msg_data
->winevent
);
2838 WCHAR module
[MAX_PATH
];
2840 size
= min( size
, (MAX_PATH
- 1) * sizeof(WCHAR
) );
2841 memcpy( module
, &msg_data
->winevent
+ 1, size
);
2842 module
[size
/ sizeof(WCHAR
)] = 0;
2843 if (!(hook_proc
= get_hook_proc( hook_proc
, module
, &free_module
)))
2845 ERR( "invalid winevent hook module name %s\n", debugstr_w(module
) );
2850 TRACE_(relay
)( "\1Call winevent proc %p (hook=%04x,event=%x,hwnd=%p,object_id=%lx,child_id=%lx,tid=%04x,time=%x)\n",
2851 hook_proc
, msg_data
->winevent
.hook
, info
.msg
.message
, info
.msg
.hwnd
,
2852 info
.msg
.wParam
, info
.msg
.lParam
, msg_data
->winevent
.tid
, info
.msg
.time
);
2854 hook_proc( wine_server_ptr_handle( msg_data
->winevent
.hook
), info
.msg
.message
,
2855 info
.msg
.hwnd
, info
.msg
.wParam
, info
.msg
.lParam
,
2856 msg_data
->winevent
.tid
, info
.msg
.time
);
2858 TRACE_(relay
)( "\1Ret winevent proc %p (hook=%04x,event=%x,hwnd=%p,object_id=%lx,child_id=%lx,tid=%04x,time=%x)\n",
2859 hook_proc
, msg_data
->winevent
.hook
, info
.msg
.message
, info
.msg
.hwnd
,
2860 info
.msg
.wParam
, info
.msg
.lParam
, msg_data
->winevent
.tid
, info
.msg
.time
);
2862 if (free_module
) FreeLibrary(free_module
);
2866 info
.flags
= ISMEX_SEND
;
2868 if (info
.msg
.message
== WH_KEYBOARD_LL
&& size
>= sizeof(msg_data
->hardware
))
2870 KBDLLHOOKSTRUCT hook
;
2872 hook
.vkCode
= LOWORD( info
.msg
.lParam
);
2873 hook
.scanCode
= HIWORD( info
.msg
.lParam
);
2874 hook
.flags
= msg_data
->hardware
.flags
;
2875 hook
.time
= info
.msg
.time
;
2876 hook
.dwExtraInfo
= msg_data
->hardware
.info
;
2877 TRACE( "calling keyboard LL hook vk %x scan %x flags %x time %u info %lx\n",
2878 hook
.vkCode
, hook
.scanCode
, hook
.flags
, hook
.time
, hook
.dwExtraInfo
);
2879 result
= HOOK_CallHooks( WH_KEYBOARD_LL
, HC_ACTION
, info
.msg
.wParam
, (LPARAM
)&hook
, TRUE
);
2881 else if (info
.msg
.message
== WH_MOUSE_LL
&& size
>= sizeof(msg_data
->hardware
))
2883 MSLLHOOKSTRUCT hook
;
2885 hook
.pt
= info
.msg
.pt
;
2886 hook
.mouseData
= info
.msg
.lParam
;
2887 hook
.flags
= msg_data
->hardware
.flags
;
2888 hook
.time
= info
.msg
.time
;
2889 hook
.dwExtraInfo
= msg_data
->hardware
.info
;
2890 TRACE( "calling mouse LL hook pos %d,%d data %x flags %x time %u info %lx\n",
2891 hook
.pt
.x
, hook
.pt
.y
, hook
.mouseData
, hook
.flags
, hook
.time
, hook
.dwExtraInfo
);
2892 result
= HOOK_CallHooks( WH_MOUSE_LL
, HC_ACTION
, info
.msg
.wParam
, (LPARAM
)&hook
, TRUE
);
2894 reply_message( &info
, result
, TRUE
);
2896 case MSG_OTHER_PROCESS
:
2897 info
.flags
= ISMEX_SEND
;
2898 if (!unpack_message( info
.msg
.hwnd
, info
.msg
.message
, &info
.msg
.wParam
,
2899 &info
.msg
.lParam
, &buffer
, size
))
2902 reply_message( &info
, 0, TRUE
);
2907 if (size
>= sizeof(msg_data
->hardware
))
2909 hw_id
= msg_data
->hardware
.hw_id
;
2910 if (!process_hardware_message( &info
.msg
, hw_id
, &msg_data
->hardware
,
2911 hwnd
, first
, last
, flags
& PM_REMOVE
))
2913 TRACE("dropping msg %x\n", info
.msg
.message
);
2914 continue; /* ignore it */
2917 thread_info
->GetMessagePosVal
= MAKELONG( info
.msg
.pt
.x
, info
.msg
.pt
.y
);
2918 thread_info
->GetMessageTimeVal
= info
.msg
.time
;
2919 thread_info
->GetMessageExtraInfoVal
= msg_data
->hardware
.info
;
2920 HeapFree( GetProcessHeap(), 0, buffer
);
2921 HOOK_CallHooks( WH_GETMESSAGE
, HC_ACTION
, flags
& PM_REMOVE
, (LPARAM
)msg
, TRUE
);
2926 if (info
.msg
.message
& 0x80000000) /* internal message */
2928 if (flags
& PM_REMOVE
)
2930 handle_internal_message( info
.msg
.hwnd
, info
.msg
.message
,
2931 info
.msg
.wParam
, info
.msg
.lParam
);
2932 /* if this is a nested call return right away */
2933 if (first
== info
.msg
.message
&& last
== info
.msg
.message
)
2935 HeapFree( GetProcessHeap(), 0, buffer
);
2940 peek_message( msg
, info
.msg
.hwnd
, info
.msg
.message
,
2941 info
.msg
.message
, flags
| PM_REMOVE
, changed_mask
);
2944 if (info
.msg
.message
>= WM_DDE_FIRST
&& info
.msg
.message
<= WM_DDE_LAST
)
2946 if (!unpack_dde_message( info
.msg
.hwnd
, info
.msg
.message
, &info
.msg
.wParam
,
2947 &info
.msg
.lParam
, &buffer
, size
))
2948 continue; /* ignore it */
2951 msg
->pt
= point_phys_to_win_dpi( info
.msg
.hwnd
, info
.msg
.pt
);
2952 thread_info
->GetMessagePosVal
= MAKELONG( msg
->pt
.x
, msg
->pt
.y
);
2953 thread_info
->GetMessageTimeVal
= info
.msg
.time
;
2954 thread_info
->GetMessageExtraInfoVal
= 0;
2955 HeapFree( GetProcessHeap(), 0, buffer
);
2956 HOOK_CallHooks( WH_GETMESSAGE
, HC_ACTION
, flags
& PM_REMOVE
, (LPARAM
)msg
, TRUE
);
2960 /* if we get here, we have a sent message; call the window procedure */
2961 old_info
= thread_info
->receive_info
;
2962 thread_info
->receive_info
= &info
;
2963 result
= call_window_proc( info
.msg
.hwnd
, info
.msg
.message
, info
.msg
.wParam
,
2964 info
.msg
.lParam
, (info
.type
!= MSG_ASCII
), FALSE
,
2965 WMCHAR_MAP_RECVMESSAGE
);
2966 reply_message( &info
, result
, TRUE
);
2967 thread_info
->receive_info
= old_info
;
2969 /* if some PM_QS* flags were specified, only handle sent messages from now on */
2970 if (HIWORD(flags
) && !changed_mask
) flags
= PM_QS_SENDMESSAGE
| LOWORD(flags
);
2975 /***********************************************************************
2976 * process_sent_messages
2978 * Process all pending sent messages.
2980 static inline void process_sent_messages(void)
2983 peek_message( &msg
, 0, 0, 0, PM_REMOVE
| PM_QS_SENDMESSAGE
, 0 );
2987 /***********************************************************************
2988 * get_server_queue_handle
2990 * Get a handle to the server message queue for the current thread.
2992 static HANDLE
get_server_queue_handle(void)
2994 struct user_thread_info
*thread_info
= get_user_thread_info();
2997 if (!(ret
= thread_info
->server_queue
))
2999 SERVER_START_REQ( get_msg_queue
)
3001 wine_server_call( req
);
3002 ret
= wine_server_ptr_handle( reply
->handle
);
3005 thread_info
->server_queue
= ret
;
3006 if (!ret
) ERR( "Cannot get server thread queue\n" );
3012 /***********************************************************************
3013 * wait_message_reply
3015 * Wait until a sent message gets replied to.
3017 static void wait_message_reply( UINT flags
)
3019 struct user_thread_info
*thread_info
= get_user_thread_info();
3020 HANDLE server_queue
= get_server_queue_handle();
3021 unsigned int wake_mask
= QS_SMRESULT
| ((flags
& SMTO_BLOCK
) ? 0 : QS_SENDMESSAGE
);
3025 unsigned int wake_bits
= 0;
3027 SERVER_START_REQ( set_queue_mask
)
3029 req
->wake_mask
= wake_mask
;
3030 req
->changed_mask
= wake_mask
;
3032 if (!wine_server_call( req
)) wake_bits
= reply
->wake_bits
& wake_mask
;
3036 thread_info
->wake_mask
= thread_info
->changed_mask
= 0;
3038 if (wake_bits
& QS_SMRESULT
) return; /* got a result */
3039 if (wake_bits
& QS_SENDMESSAGE
)
3041 /* Process the sent message immediately */
3042 process_sent_messages();
3046 wow_handlers
.wait_message( 1, &server_queue
, INFINITE
, wake_mask
, 0 );
3051 /***********************************************************************
3054 * Wait for multiple objects including the server queue, with specific queue masks.
3056 static DWORD
wait_objects( DWORD count
, const HANDLE
*handles
, DWORD timeout
,
3057 DWORD wake_mask
, DWORD changed_mask
, DWORD flags
)
3059 struct user_thread_info
*thread_info
= get_user_thread_info();
3062 assert( count
); /* we must have at least the server queue */
3064 flush_window_surfaces( TRUE
);
3066 if (thread_info
->wake_mask
!= wake_mask
|| thread_info
->changed_mask
!= changed_mask
)
3068 SERVER_START_REQ( set_queue_mask
)
3070 req
->wake_mask
= wake_mask
;
3071 req
->changed_mask
= changed_mask
;
3073 wine_server_call( req
);
3076 thread_info
->wake_mask
= wake_mask
;
3077 thread_info
->changed_mask
= changed_mask
;
3080 ret
= wow_handlers
.wait_message( count
, handles
, timeout
, changed_mask
, flags
);
3082 if (ret
!= WAIT_TIMEOUT
) thread_info
->wake_mask
= thread_info
->changed_mask
= 0;
3087 /***********************************************************************
3088 * put_message_in_queue
3090 * Put a sent message into the destination queue.
3091 * For inter-process message, reply_size is set to expected size of reply data.
3093 static BOOL
put_message_in_queue( const struct send_message_info
*info
, size_t *reply_size
)
3095 struct packed_message data
;
3096 message_data_t msg_data
;
3099 timeout_t timeout
= TIMEOUT_INFINITE
;
3101 /* Check for INFINITE timeout for compatibility with Win9x,
3102 * although Windows >= NT does not do so
3104 if (info
->type
!= MSG_NOTIFY
&&
3105 info
->type
!= MSG_CALLBACK
&&
3106 info
->type
!= MSG_POSTED
&&
3108 info
->timeout
!= INFINITE
)
3110 /* timeout is signed despite the prototype */
3111 timeout
= (timeout_t
)max( 0, (int)info
->timeout
) * -10000;
3114 memset( &data
, 0, sizeof(data
) );
3115 if (info
->type
== MSG_OTHER_PROCESS
)
3117 *reply_size
= pack_message( info
->hwnd
, info
->msg
, info
->wparam
, info
->lparam
, &data
);
3118 if (data
.count
== -1)
3120 WARN( "cannot pack message %x\n", info
->msg
);
3124 else if (info
->type
== MSG_CALLBACK
)
3126 msg_data
.callback
.callback
= wine_server_client_ptr( info
->callback
);
3127 msg_data
.callback
.data
= info
->data
;
3128 msg_data
.callback
.result
= 0;
3129 data
.data
[0] = &msg_data
;
3130 data
.size
[0] = sizeof(msg_data
.callback
);
3133 else if (info
->type
== MSG_POSTED
&& info
->msg
>= WM_DDE_FIRST
&& info
->msg
<= WM_DDE_LAST
)
3135 return post_dde_message( &data
, info
);
3138 SERVER_START_REQ( send_message
)
3140 req
->id
= info
->dest_tid
;
3141 req
->type
= info
->type
;
3143 req
->win
= wine_server_user_handle( info
->hwnd
);
3144 req
->msg
= info
->msg
;
3145 req
->wparam
= info
->wparam
;
3146 req
->lparam
= info
->lparam
;
3147 req
->timeout
= timeout
;
3149 if (info
->flags
& SMTO_ABORTIFHUNG
) req
->flags
|= SEND_MSG_ABORT_IF_HUNG
;
3150 for (i
= 0; i
< data
.count
; i
++) wine_server_add_data( req
, data
.data
[i
], data
.size
[i
] );
3151 if ((res
= wine_server_call( req
)))
3153 if (res
== STATUS_INVALID_PARAMETER
)
3154 /* FIXME: find a STATUS_ value for this one */
3155 SetLastError( ERROR_INVALID_THREAD_ID
);
3157 SetLastError( RtlNtStatusToDosError(res
) );
3165 /***********************************************************************
3168 * Retrieve a message reply from the server.
3170 static LRESULT
retrieve_reply( const struct send_message_info
*info
,
3171 size_t reply_size
, LRESULT
*result
)
3174 void *reply_data
= NULL
;
3178 if (!(reply_data
= HeapAlloc( GetProcessHeap(), 0, reply_size
)))
3180 WARN( "no memory for reply, will be truncated\n" );
3184 SERVER_START_REQ( get_message_reply
)
3187 if (reply_size
) wine_server_set_reply( req
, reply_data
, reply_size
);
3188 if (!(status
= wine_server_call( req
))) *result
= reply
->result
;
3189 reply_size
= wine_server_reply_size( reply
);
3192 if (!status
&& reply_size
)
3193 unpack_reply( info
->hwnd
, info
->msg
, info
->wparam
, info
->lparam
, reply_data
, reply_size
);
3195 HeapFree( GetProcessHeap(), 0, reply_data
);
3197 TRACE( "hwnd %p msg %x (%s) wp %lx lp %lx got reply %lx (err=%d)\n",
3198 info
->hwnd
, info
->msg
, SPY_GetMsgName(info
->msg
, info
->hwnd
), info
->wparam
,
3199 info
->lparam
, *result
, status
);
3201 /* MSDN states that last error is 0 on timeout, but at least NT4 returns ERROR_TIMEOUT */
3202 if (status
) SetLastError( RtlNtStatusToDosError(status
) );
3207 /***********************************************************************
3208 * send_inter_thread_message
3210 static LRESULT
send_inter_thread_message( const struct send_message_info
*info
, LRESULT
*res_ptr
)
3212 size_t reply_size
= 0;
3214 TRACE( "hwnd %p msg %x (%s) wp %lx lp %lx\n",
3215 info
->hwnd
, info
->msg
, SPY_GetMsgName(info
->msg
, info
->hwnd
), info
->wparam
, info
->lparam
);
3217 USER_CheckNotLock();
3219 if (!put_message_in_queue( info
, &reply_size
)) return 0;
3221 /* there's no reply to wait for on notify/callback messages */
3222 if (info
->type
== MSG_NOTIFY
|| info
->type
== MSG_CALLBACK
) return 1;
3224 wait_message_reply( info
->flags
);
3225 return retrieve_reply( info
, reply_size
, res_ptr
);
3229 /***********************************************************************
3230 * send_inter_thread_callback
3232 static LRESULT
send_inter_thread_callback( HWND hwnd
, UINT msg
, WPARAM wp
, LPARAM lp
,
3233 LRESULT
*result
, void *arg
)
3235 struct send_message_info
*info
= arg
;
3240 return send_inter_thread_message( info
, result
);
3243 static BOOL
is_message_broadcastable(UINT msg
)
3245 return msg
< WM_USER
|| msg
>= 0xc000;
3248 /***********************************************************************
3251 * Backend implementation of the various SendMessage functions.
3253 static BOOL
send_message( struct send_message_info
*info
, DWORD_PTR
*res_ptr
, BOOL unicode
)
3259 if (is_broadcast(info
->hwnd
))
3261 if (is_message_broadcastable( info
->msg
))
3262 EnumWindows( broadcast_message_callback
, (LPARAM
)info
);
3263 if (res_ptr
) *res_ptr
= 1;
3267 if (!(info
->dest_tid
= GetWindowThreadProcessId( info
->hwnd
, &dest_pid
))) return FALSE
;
3269 if (USER_IsExitingThread( info
->dest_tid
)) return FALSE
;
3271 SPY_EnterMessage( SPY_SENDMESSAGE
, info
->hwnd
, info
->msg
, info
->wparam
, info
->lparam
);
3273 if (info
->dest_tid
== GetCurrentThreadId())
3275 result
= call_window_proc( info
->hwnd
, info
->msg
, info
->wparam
, info
->lparam
,
3276 unicode
, TRUE
, info
->wm_char
);
3277 if (info
->type
== MSG_CALLBACK
)
3278 call_sendmsg_callback( info
->callback
, info
->hwnd
, info
->msg
, info
->data
, result
);
3283 if (dest_pid
!= GetCurrentProcessId() && (info
->type
== MSG_ASCII
|| info
->type
== MSG_UNICODE
))
3284 info
->type
= MSG_OTHER_PROCESS
;
3286 /* MSG_ASCII can be sent unconverted except for WM_CHAR; everything else needs to be Unicode */
3287 if (!unicode
&& is_unicode_message( info
->msg
) &&
3288 (info
->type
!= MSG_ASCII
|| info
->msg
== WM_CHAR
))
3289 ret
= WINPROC_CallProcAtoW( send_inter_thread_callback
, info
->hwnd
, info
->msg
,
3290 info
->wparam
, info
->lparam
, &result
, info
, info
->wm_char
);
3292 ret
= send_inter_thread_message( info
, &result
);
3295 SPY_ExitMessage( SPY_RESULT_OK
, info
->hwnd
, info
->msg
, result
, info
->wparam
, info
->lparam
);
3296 if (ret
&& res_ptr
) *res_ptr
= result
;
3301 /***********************************************************************
3302 * send_hardware_message
3304 NTSTATUS
send_hardware_message( HWND hwnd
, const INPUT
*input
, UINT flags
)
3306 struct user_key_state_info
*key_state_info
= get_user_thread_info()->key_state
;
3307 struct send_message_info info
;
3308 int prev_x
, prev_y
, new_x
, new_y
;
3309 INT counter
= global_key_state_counter
;
3313 info
.type
= MSG_HARDWARE
;
3319 SERVER_START_REQ( send_hardware_message
)
3321 req
->win
= wine_server_user_handle( hwnd
);
3323 req
->input
.type
= input
->type
;
3324 switch (input
->type
)
3327 req
->input
.mouse
.x
= input
->u
.mi
.dx
;
3328 req
->input
.mouse
.y
= input
->u
.mi
.dy
;
3329 req
->input
.mouse
.data
= input
->u
.mi
.mouseData
;
3330 req
->input
.mouse
.flags
= input
->u
.mi
.dwFlags
;
3331 req
->input
.mouse
.time
= input
->u
.mi
.time
;
3332 req
->input
.mouse
.info
= input
->u
.mi
.dwExtraInfo
;
3334 case INPUT_KEYBOARD
:
3335 req
->input
.kbd
.vkey
= input
->u
.ki
.wVk
;
3336 req
->input
.kbd
.scan
= input
->u
.ki
.wScan
;
3337 req
->input
.kbd
.flags
= input
->u
.ki
.dwFlags
;
3338 req
->input
.kbd
.time
= input
->u
.ki
.time
;
3339 req
->input
.kbd
.info
= input
->u
.ki
.dwExtraInfo
;
3341 case INPUT_HARDWARE
:
3342 req
->input
.hw
.msg
= input
->u
.hi
.uMsg
;
3343 req
->input
.hw
.lparam
= MAKELONG( input
->u
.hi
.wParamL
, input
->u
.hi
.wParamH
);
3346 if (key_state_info
) wine_server_set_reply( req
, key_state_info
->state
,
3347 sizeof(key_state_info
->state
) );
3348 ret
= wine_server_call( req
);
3350 prev_x
= reply
->prev_x
;
3351 prev_y
= reply
->prev_y
;
3352 new_x
= reply
->new_x
;
3353 new_y
= reply
->new_y
;
3361 key_state_info
->time
= GetTickCount();
3362 key_state_info
->counter
= counter
;
3364 if ((flags
& SEND_HWMSG_INJECTED
) && (prev_x
!= new_x
|| prev_y
!= new_y
))
3365 USER_Driver
->pSetCursorPos( new_x
, new_y
);
3371 wait_message_reply( 0 );
3372 retrieve_reply( &info
, 0, &ignored
);
3378 /***********************************************************************
3379 * MSG_SendInternalMessageTimeout
3381 * Same as SendMessageTimeoutW but sends the message to a specific thread
3382 * without requiring a window handle. Only works for internal Wine messages.
3384 LRESULT
MSG_SendInternalMessageTimeout( DWORD dest_pid
, DWORD dest_tid
,
3385 UINT msg
, WPARAM wparam
, LPARAM lparam
,
3386 UINT flags
, UINT timeout
, PDWORD_PTR res_ptr
)
3388 struct send_message_info info
;
3389 LRESULT ret
, result
;
3391 assert( msg
& 0x80000000 ); /* must be an internal Wine message */
3393 info
.type
= MSG_UNICODE
;
3394 info
.dest_tid
= dest_tid
;
3397 info
.wparam
= wparam
;
3398 info
.lparam
= lparam
;
3400 info
.timeout
= timeout
;
3402 if (USER_IsExitingThread( dest_tid
)) return 0;
3404 if (dest_tid
== GetCurrentThreadId())
3406 result
= handle_internal_message( 0, msg
, wparam
, lparam
);
3411 if (dest_pid
!= GetCurrentProcessId()) info
.type
= MSG_OTHER_PROCESS
;
3412 ret
= send_inter_thread_message( &info
, &result
);
3414 if (ret
&& res_ptr
) *res_ptr
= result
;
3419 /***********************************************************************
3420 * SendMessageTimeoutW (USER32.@)
3422 LRESULT WINAPI
SendMessageTimeoutW( HWND hwnd
, UINT msg
, WPARAM wparam
, LPARAM lparam
,
3423 UINT flags
, UINT timeout
, PDWORD_PTR res_ptr
)
3425 struct send_message_info info
;
3427 info
.type
= MSG_UNICODE
;
3430 info
.wparam
= wparam
;
3431 info
.lparam
= lparam
;
3433 info
.timeout
= timeout
;
3435 return send_message( &info
, res_ptr
, TRUE
);
3438 /***********************************************************************
3439 * SendMessageTimeoutA (USER32.@)
3441 LRESULT WINAPI
SendMessageTimeoutA( HWND hwnd
, UINT msg
, WPARAM wparam
, LPARAM lparam
,
3442 UINT flags
, UINT timeout
, PDWORD_PTR res_ptr
)
3444 struct send_message_info info
;
3446 info
.type
= MSG_ASCII
;
3449 info
.wparam
= wparam
;
3450 info
.lparam
= lparam
;
3452 info
.timeout
= timeout
;
3453 info
.wm_char
= WMCHAR_MAP_SENDMESSAGETIMEOUT
;
3455 return send_message( &info
, res_ptr
, FALSE
);
3459 /***********************************************************************
3460 * SendMessageW (USER32.@)
3462 LRESULT WINAPI
SendMessageW( HWND hwnd
, UINT msg
, WPARAM wparam
, LPARAM lparam
)
3465 struct send_message_info info
;
3467 info
.type
= MSG_UNICODE
;
3470 info
.wparam
= wparam
;
3471 info
.lparam
= lparam
;
3472 info
.flags
= SMTO_NORMAL
;
3475 send_message( &info
, &res
, TRUE
);
3480 /***********************************************************************
3481 * SendMessageA (USER32.@)
3483 LRESULT WINAPI
SendMessageA( HWND hwnd
, UINT msg
, WPARAM wparam
, LPARAM lparam
)
3486 struct send_message_info info
;
3488 info
.type
= MSG_ASCII
;
3491 info
.wparam
= wparam
;
3492 info
.lparam
= lparam
;
3493 info
.flags
= SMTO_NORMAL
;
3495 info
.wm_char
= WMCHAR_MAP_SENDMESSAGE
;
3497 send_message( &info
, &res
, FALSE
);
3502 /***********************************************************************
3503 * SendNotifyMessageA (USER32.@)
3505 BOOL WINAPI
SendNotifyMessageA( HWND hwnd
, UINT msg
, WPARAM wparam
, LPARAM lparam
)
3507 struct send_message_info info
;
3509 if (is_pointer_message( msg
, wparam
))
3511 SetLastError( ERROR_MESSAGE_SYNC_ONLY
);
3515 info
.type
= MSG_NOTIFY
;
3518 info
.wparam
= wparam
;
3519 info
.lparam
= lparam
;
3521 info
.wm_char
= WMCHAR_MAP_SENDMESSAGETIMEOUT
;
3523 return send_message( &info
, NULL
, FALSE
);
3527 /***********************************************************************
3528 * SendNotifyMessageW (USER32.@)
3530 BOOL WINAPI
SendNotifyMessageW( HWND hwnd
, UINT msg
, WPARAM wparam
, LPARAM lparam
)
3532 struct send_message_info info
;
3534 if (is_pointer_message( msg
, wparam
))
3536 SetLastError( ERROR_MESSAGE_SYNC_ONLY
);
3540 info
.type
= MSG_NOTIFY
;
3543 info
.wparam
= wparam
;
3544 info
.lparam
= lparam
;
3547 return send_message( &info
, NULL
, TRUE
);
3551 /***********************************************************************
3552 * SendMessageCallbackA (USER32.@)
3554 BOOL WINAPI
SendMessageCallbackA( HWND hwnd
, UINT msg
, WPARAM wparam
, LPARAM lparam
,
3555 SENDASYNCPROC callback
, ULONG_PTR data
)
3557 struct send_message_info info
;
3559 if (is_pointer_message( msg
, wparam
))
3561 SetLastError( ERROR_MESSAGE_SYNC_ONLY
);
3565 info
.type
= MSG_CALLBACK
;
3568 info
.wparam
= wparam
;
3569 info
.lparam
= lparam
;
3570 info
.callback
= callback
;
3573 info
.wm_char
= WMCHAR_MAP_SENDMESSAGETIMEOUT
;
3575 return send_message( &info
, NULL
, FALSE
);
3579 /***********************************************************************
3580 * SendMessageCallbackW (USER32.@)
3582 BOOL WINAPI
SendMessageCallbackW( HWND hwnd
, UINT msg
, WPARAM wparam
, LPARAM lparam
,
3583 SENDASYNCPROC callback
, ULONG_PTR data
)
3585 struct send_message_info info
;
3587 if (is_pointer_message( msg
, wparam
))
3589 SetLastError( ERROR_MESSAGE_SYNC_ONLY
);
3593 info
.type
= MSG_CALLBACK
;
3596 info
.wparam
= wparam
;
3597 info
.lparam
= lparam
;
3598 info
.callback
= callback
;
3602 return send_message( &info
, NULL
, TRUE
);
3606 /***********************************************************************
3607 * ReplyMessage (USER32.@)
3609 BOOL WINAPI
ReplyMessage( LRESULT result
)
3611 struct received_message_info
*info
= get_user_thread_info()->receive_info
;
3613 if (!info
) return FALSE
;
3614 reply_message( info
, result
, FALSE
);
3619 /***********************************************************************
3620 * InSendMessage (USER32.@)
3622 BOOL WINAPI
InSendMessage(void)
3624 return (InSendMessageEx( NULL
) & (ISMEX_SEND
| ISMEX_NOTIFY
| ISMEX_CALLBACK
)) != 0;
3628 /***********************************************************************
3629 * InSendMessageEx (USER32.@)
3631 DWORD WINAPI
InSendMessageEx( LPVOID reserved
)
3633 struct received_message_info
*info
= get_user_thread_info()->receive_info
;
3635 if (info
) return info
->flags
;
3636 return ISMEX_NOSEND
;
3640 /***********************************************************************
3641 * PostMessageA (USER32.@)
3643 BOOL WINAPI
PostMessageA( HWND hwnd
, UINT msg
, WPARAM wparam
, LPARAM lparam
)
3645 if (!map_wparam_AtoW( msg
, &wparam
, WMCHAR_MAP_POSTMESSAGE
)) return TRUE
;
3646 return PostMessageW( hwnd
, msg
, wparam
, lparam
);
3650 /***********************************************************************
3651 * PostMessageW (USER32.@)
3653 BOOL WINAPI
PostMessageW( HWND hwnd
, UINT msg
, WPARAM wparam
, LPARAM lparam
)
3655 struct send_message_info info
;
3657 if (is_pointer_message( msg
, wparam
))
3659 SetLastError( ERROR_MESSAGE_SYNC_ONLY
);
3663 TRACE( "hwnd %p msg %x (%s) wp %lx lp %lx\n",
3664 hwnd
, msg
, SPY_GetMsgName(msg
, hwnd
), wparam
, lparam
);
3666 info
.type
= MSG_POSTED
;
3669 info
.wparam
= wparam
;
3670 info
.lparam
= lparam
;
3673 if (is_broadcast(hwnd
))
3675 if (is_message_broadcastable( info
.msg
))
3676 EnumWindows( broadcast_message_callback
, (LPARAM
)&info
);
3680 if (!hwnd
) return PostThreadMessageW( GetCurrentThreadId(), msg
, wparam
, lparam
);
3682 if (!(info
.dest_tid
= GetWindowThreadProcessId( hwnd
, NULL
))) return FALSE
;
3684 if (USER_IsExitingThread( info
.dest_tid
)) return TRUE
;
3686 return put_message_in_queue( &info
, NULL
);
3690 /**********************************************************************
3691 * PostThreadMessageA (USER32.@)
3693 BOOL WINAPI
PostThreadMessageA( DWORD thread
, UINT msg
, WPARAM wparam
, LPARAM lparam
)
3695 if (!map_wparam_AtoW( msg
, &wparam
, WMCHAR_MAP_POSTMESSAGE
)) return TRUE
;
3696 return PostThreadMessageW( thread
, msg
, wparam
, lparam
);
3700 /**********************************************************************
3701 * PostThreadMessageW (USER32.@)
3703 BOOL WINAPI
PostThreadMessageW( DWORD thread
, UINT msg
, WPARAM wparam
, LPARAM lparam
)
3705 struct send_message_info info
;
3707 if (is_pointer_message( msg
, wparam
))
3709 SetLastError( ERROR_MESSAGE_SYNC_ONLY
);
3712 if (USER_IsExitingThread( thread
)) return TRUE
;
3714 info
.type
= MSG_POSTED
;
3715 info
.dest_tid
= thread
;
3718 info
.wparam
= wparam
;
3719 info
.lparam
= lparam
;
3721 return put_message_in_queue( &info
, NULL
);
3725 /***********************************************************************
3726 * PostQuitMessage (USER32.@)
3728 * Posts a quit message to the current thread's message queue.
3731 * exit_code [I] Exit code to return from message loop.
3737 * This function is not the same as calling:
3738 *|PostThreadMessage(GetCurrentThreadId(), WM_QUIT, exit_code, 0);
3739 * It instead sets a flag in the message queue that signals it to generate
3740 * a WM_QUIT message when there are no other pending sent or posted messages
3743 void WINAPI
PostQuitMessage( INT exit_code
)
3745 SERVER_START_REQ( post_quit_message
)
3747 req
->exit_code
= exit_code
;
3748 wine_server_call( req
);
3753 /* check for driver events if we detect that the app is not properly consuming messages */
3754 static inline void check_for_driver_events( UINT msg
)
3756 if (get_user_thread_info()->message_count
> 200)
3758 flush_window_surfaces( FALSE
);
3759 USER_Driver
->pMsgWaitForMultipleObjectsEx( 0, NULL
, 0, QS_ALLINPUT
, 0 );
3761 else if (msg
== WM_TIMER
|| msg
== WM_SYSTIMER
)
3763 /* driver events should have priority over timers, so make sure we'll check for them soon */
3764 get_user_thread_info()->message_count
+= 100;
3766 else get_user_thread_info()->message_count
++;
3769 /***********************************************************************
3770 * PeekMessageW (USER32.@)
3772 BOOL WINAPI DECLSPEC_HOTPATCH
PeekMessageW( MSG
*msg_out
, HWND hwnd
, UINT first
, UINT last
, UINT flags
)
3776 USER_CheckNotLock();
3777 check_for_driver_events( 0 );
3779 if (!peek_message( &msg
, hwnd
, first
, last
, flags
, 0 ))
3783 flush_window_surfaces( TRUE
);
3784 ret
= wow_handlers
.wait_message( 0, NULL
, 0, QS_ALLINPUT
, 0 );
3785 /* if we received driver events, check again for a pending message */
3786 if (ret
== WAIT_TIMEOUT
|| !peek_message( &msg
, hwnd
, first
, last
, flags
, 0 )) return FALSE
;
3789 check_for_driver_events( msg
.message
);
3791 /* copy back our internal safe copy of message data to msg_out.
3792 * msg_out is a variable from the *program*, so it can't be used
3793 * internally as it can get "corrupted" by our use of SendMessage()
3794 * (back to the program) inside the message handling itself. */
3797 SetLastError( ERROR_NOACCESS
);
3805 /***********************************************************************
3806 * PeekMessageA (USER32.@)
3808 BOOL WINAPI DECLSPEC_HOTPATCH
PeekMessageA( MSG
*msg
, HWND hwnd
, UINT first
, UINT last
, UINT flags
)
3810 if (get_pending_wmchar( msg
, first
, last
, (flags
& PM_REMOVE
) )) return TRUE
;
3811 if (!PeekMessageW( msg
, hwnd
, first
, last
, flags
)) return FALSE
;
3812 map_wparam_WtoA( msg
, (flags
& PM_REMOVE
) );
3817 /***********************************************************************
3818 * GetMessageW (USER32.@)
3820 BOOL WINAPI DECLSPEC_HOTPATCH
GetMessageW( MSG
*msg
, HWND hwnd
, UINT first
, UINT last
)
3822 HANDLE server_queue
= get_server_queue_handle();
3823 unsigned int mask
= QS_POSTMESSAGE
| QS_SENDMESSAGE
; /* Always selected */
3825 USER_CheckNotLock();
3826 check_for_driver_events( 0 );
3830 if ((first
<= WM_KEYLAST
) && (last
>= WM_KEYFIRST
)) mask
|= QS_KEY
;
3831 if ( ((first
<= WM_MOUSELAST
) && (last
>= WM_MOUSEFIRST
)) ||
3832 ((first
<= WM_NCMOUSELAST
) && (last
>= WM_NCMOUSEFIRST
)) ) mask
|= QS_MOUSE
;
3833 if ((first
<= WM_TIMER
) && (last
>= WM_TIMER
)) mask
|= QS_TIMER
;
3834 if ((first
<= WM_SYSTIMER
) && (last
>= WM_SYSTIMER
)) mask
|= QS_TIMER
;
3835 if ((first
<= WM_PAINT
) && (last
>= WM_PAINT
)) mask
|= QS_PAINT
;
3837 else mask
= QS_ALLINPUT
;
3839 while (!peek_message( msg
, hwnd
, first
, last
, PM_REMOVE
| (mask
<< 16), mask
))
3841 wait_objects( 1, &server_queue
, INFINITE
, mask
& (QS_SENDMESSAGE
| QS_SMRESULT
), mask
, 0 );
3843 check_for_driver_events( msg
->message
);
3845 return (msg
->message
!= WM_QUIT
);
3849 /***********************************************************************
3850 * GetMessageA (USER32.@)
3852 BOOL WINAPI DECLSPEC_HOTPATCH
GetMessageA( MSG
*msg
, HWND hwnd
, UINT first
, UINT last
)
3854 if (get_pending_wmchar( msg
, first
, last
, TRUE
)) return TRUE
;
3855 GetMessageW( msg
, hwnd
, first
, last
);
3856 map_wparam_WtoA( msg
, TRUE
);
3857 return (msg
->message
!= WM_QUIT
);
3861 /***********************************************************************
3862 * IsDialogMessageA (USER32.@)
3863 * IsDialogMessage (USER32.@)
3865 BOOL WINAPI
IsDialogMessageA( HWND hwndDlg
, LPMSG pmsg
)
3868 map_wparam_AtoW( msg
.message
, &msg
.wParam
, WMCHAR_MAP_NOMAPPING
);
3869 return IsDialogMessageW( hwndDlg
, &msg
);
3873 /***********************************************************************
3874 * TranslateMessage (USER32.@)
3876 * Implementation of TranslateMessage.
3878 * TranslateMessage translates virtual-key messages into character-messages,
3880 * WM_KEYDOWN/WM_KEYUP combinations produce a WM_CHAR or WM_DEADCHAR message.
3881 * ditto replacing WM_* with WM_SYS*
3882 * This produces WM_CHAR messages only for keys mapped to ASCII characters
3883 * by the keyboard driver.
3885 * If the message is WM_KEYDOWN, WM_KEYUP, WM_SYSKEYDOWN, or WM_SYSKEYUP, the
3886 * return value is nonzero, regardless of the translation.
3889 BOOL WINAPI
TranslateMessage( const MSG
*msg
)
3896 if (msg
->message
< WM_KEYFIRST
|| msg
->message
> WM_KEYLAST
) return FALSE
;
3897 if (msg
->message
!= WM_KEYDOWN
&& msg
->message
!= WM_SYSKEYDOWN
) return TRUE
;
3899 TRACE_(key
)("Translating key %s (%04lX), scancode %04x\n",
3900 SPY_GetVKeyName(msg
->wParam
), msg
->wParam
, HIWORD(msg
->lParam
));
3902 switch (msg
->wParam
)
3905 message
= (msg
->message
== WM_KEYDOWN
) ? WM_CHAR
: WM_SYSCHAR
;
3906 TRACE_(key
)("PostMessageW(%p,%s,%04x,%08x)\n",
3907 msg
->hwnd
, SPY_GetMsgName(message
, msg
->hwnd
), HIWORD(msg
->lParam
), LOWORD(msg
->lParam
));
3908 PostMessageW( msg
->hwnd
, message
, HIWORD(msg
->lParam
), LOWORD(msg
->lParam
));
3912 return ImmTranslateMessage(msg
->hwnd
, msg
->message
, msg
->wParam
, msg
->lParam
);
3915 GetKeyboardState( state
);
3916 len
= ToUnicode(msg
->wParam
, HIWORD(msg
->lParam
), state
, wp
, ARRAY_SIZE(wp
), 0);
3919 message
= (msg
->message
== WM_KEYDOWN
) ? WM_DEADCHAR
: WM_SYSDEADCHAR
;
3920 TRACE_(key
)("-1 -> PostMessageW(%p,%s,%04x,%08lx)\n",
3921 msg
->hwnd
, SPY_GetMsgName(message
, msg
->hwnd
), wp
[0], msg
->lParam
);
3922 PostMessageW( msg
->hwnd
, message
, wp
[0], msg
->lParam
);
3928 message
= (msg
->message
== WM_KEYDOWN
) ? WM_CHAR
: WM_SYSCHAR
;
3929 TRACE_(key
)("%d -> PostMessageW(%p,%s,<x>,%08lx) for <x> in %s\n", len
, msg
->hwnd
,
3930 SPY_GetMsgName(message
, msg
->hwnd
), msg
->lParam
, debugstr_wn(wp
, len
));
3931 for (i
= 0; i
< len
; i
++)
3932 PostMessageW( msg
->hwnd
, message
, wp
[i
], msg
->lParam
);
3938 /***********************************************************************
3939 * DispatchMessageA (USER32.@)
3941 * See DispatchMessageW.
3943 LRESULT WINAPI DECLSPEC_HOTPATCH
DispatchMessageA( const MSG
* msg
)
3947 /* Process timer messages */
3948 if ((msg
->message
== WM_TIMER
) || (msg
->message
== WM_SYSTIMER
))
3954 retval
= CallWindowProcA( (WNDPROC
)msg
->lParam
, msg
->hwnd
,
3955 msg
->message
, msg
->wParam
, GetTickCount() );
3965 if (!msg
->hwnd
) return 0;
3967 SPY_EnterMessage( SPY_DISPATCHMESSAGE
, msg
->hwnd
, msg
->message
,
3968 msg
->wParam
, msg
->lParam
);
3970 if (!WINPROC_call_window( msg
->hwnd
, msg
->message
, msg
->wParam
, msg
->lParam
,
3971 &retval
, FALSE
, WMCHAR_MAP_DISPATCHMESSAGE
))
3973 if (!IsWindow( msg
->hwnd
)) SetLastError( ERROR_INVALID_WINDOW_HANDLE
);
3974 else SetLastError( ERROR_MESSAGE_SYNC_ONLY
);
3978 SPY_ExitMessage( SPY_RESULT_OK
, msg
->hwnd
, msg
->message
, retval
,
3979 msg
->wParam
, msg
->lParam
);
3981 if (msg
->message
== WM_PAINT
)
3983 /* send a WM_NCPAINT and WM_ERASEBKGND if the non-client area is still invalid */
3984 HRGN hrgn
= CreateRectRgn( 0, 0, 0, 0 );
3985 GetUpdateRgn( msg
->hwnd
, hrgn
, TRUE
);
3986 DeleteObject( hrgn
);
3992 /***********************************************************************
3993 * DispatchMessageW (USER32.@) Process a message
3995 * Process the message specified in the structure *_msg_.
3997 * If the lpMsg parameter points to a WM_TIMER message and the
3998 * parameter of the WM_TIMER message is not NULL, the lParam parameter
3999 * points to the function that is called instead of the window
4000 * procedure. The function stored in lParam (timer callback) is protected
4001 * from causing page-faults.
4003 * The message must be valid.
4007 * DispatchMessage() returns the result of the window procedure invoked.
4014 LRESULT WINAPI DECLSPEC_HOTPATCH
DispatchMessageW( const MSG
* msg
)
4018 /* Process timer messages */
4019 if ((msg
->message
== WM_TIMER
) || (msg
->message
== WM_SYSTIMER
))
4025 retval
= CallWindowProcW( (WNDPROC
)msg
->lParam
, msg
->hwnd
,
4026 msg
->message
, msg
->wParam
, GetTickCount() );
4036 if (!msg
->hwnd
) return 0;
4038 SPY_EnterMessage( SPY_DISPATCHMESSAGE
, msg
->hwnd
, msg
->message
,
4039 msg
->wParam
, msg
->lParam
);
4041 if (!WINPROC_call_window( msg
->hwnd
, msg
->message
, msg
->wParam
, msg
->lParam
,
4042 &retval
, TRUE
, WMCHAR_MAP_DISPATCHMESSAGE
))
4044 if (!IsWindow( msg
->hwnd
)) SetLastError( ERROR_INVALID_WINDOW_HANDLE
);
4045 else SetLastError( ERROR_MESSAGE_SYNC_ONLY
);
4049 SPY_ExitMessage( SPY_RESULT_OK
, msg
->hwnd
, msg
->message
, retval
,
4050 msg
->wParam
, msg
->lParam
);
4052 if (msg
->message
== WM_PAINT
)
4054 /* send a WM_NCPAINT and WM_ERASEBKGND if the non-client area is still invalid */
4055 HRGN hrgn
= CreateRectRgn( 0, 0, 0, 0 );
4056 GetUpdateRgn( msg
->hwnd
, hrgn
, TRUE
);
4057 DeleteObject( hrgn
);
4063 /***********************************************************************
4064 * GetMessagePos (USER.119)
4065 * GetMessagePos (USER32.@)
4067 * The GetMessagePos() function returns a long value representing a
4068 * cursor position, in screen coordinates, when the last message
4069 * retrieved by the GetMessage() function occurs. The x-coordinate is
4070 * in the low-order word of the return value, the y-coordinate is in
4071 * the high-order word. The application can use the MAKEPOINT()
4072 * macro to obtain a POINT structure from the return value.
4074 * For the current cursor position, use GetCursorPos().
4078 * Cursor position of last message on success, zero on failure.
4085 DWORD WINAPI
GetMessagePos(void)
4087 return get_user_thread_info()->GetMessagePosVal
;
4091 /***********************************************************************
4092 * GetMessageTime (USER.120)
4093 * GetMessageTime (USER32.@)
4095 * GetMessageTime() returns the message time for the last message
4096 * retrieved by the function. The time is measured in milliseconds with
4097 * the same offset as GetTickCount().
4099 * Since the tick count wraps, this is only useful for moderately short
4100 * relative time comparisons.
4104 * Time of last message on success, zero on failure.
4106 LONG WINAPI
GetMessageTime(void)
4108 return get_user_thread_info()->GetMessageTimeVal
;
4112 /***********************************************************************
4113 * GetMessageExtraInfo (USER.288)
4114 * GetMessageExtraInfo (USER32.@)
4116 LPARAM WINAPI
GetMessageExtraInfo(void)
4118 return get_user_thread_info()->GetMessageExtraInfoVal
;
4122 /***********************************************************************
4123 * SetMessageExtraInfo (USER32.@)
4125 LPARAM WINAPI
SetMessageExtraInfo(LPARAM lParam
)
4127 struct user_thread_info
*thread_info
= get_user_thread_info();
4128 LONG old_value
= thread_info
->GetMessageExtraInfoVal
;
4129 thread_info
->GetMessageExtraInfoVal
= lParam
;
4134 /***********************************************************************
4135 * WaitMessage (USER.112) Suspend thread pending messages
4136 * WaitMessage (USER32.@) Suspend thread pending messages
4138 * WaitMessage() suspends a thread until events appear in the thread's
4141 BOOL WINAPI
WaitMessage(void)
4143 return (MsgWaitForMultipleObjectsEx( 0, NULL
, INFINITE
, QS_ALLINPUT
, 0 ) != WAIT_FAILED
);
4147 /***********************************************************************
4148 * MsgWaitForMultipleObjectsEx (USER32.@)
4150 DWORD WINAPI
MsgWaitForMultipleObjectsEx( DWORD count
, const HANDLE
*pHandles
,
4151 DWORD timeout
, DWORD mask
, DWORD flags
)
4153 HANDLE handles
[MAXIMUM_WAIT_OBJECTS
];
4156 if (count
> MAXIMUM_WAIT_OBJECTS
-1)
4158 SetLastError( ERROR_INVALID_PARAMETER
);
4162 /* add the queue to the handle list */
4163 for (i
= 0; i
< count
; i
++) handles
[i
] = pHandles
[i
];
4164 handles
[count
] = get_server_queue_handle();
4166 return wait_objects( count
+1, handles
, timeout
,
4167 (flags
& MWMO_INPUTAVAILABLE
) ? mask
: 0, mask
, flags
);
4171 /***********************************************************************
4172 * MsgWaitForMultipleObjects (USER32.@)
4174 DWORD WINAPI
MsgWaitForMultipleObjects( DWORD count
, const HANDLE
*handles
,
4175 BOOL wait_all
, DWORD timeout
, DWORD mask
)
4177 return MsgWaitForMultipleObjectsEx( count
, handles
, timeout
, mask
,
4178 wait_all
? MWMO_WAITALL
: 0 );
4182 /***********************************************************************
4183 * WaitForInputIdle (USER32.@)
4185 DWORD WINAPI
WaitForInputIdle( HANDLE hProcess
, DWORD dwTimeOut
)
4187 DWORD start_time
, elapsed
, ret
;
4190 handles
[0] = hProcess
;
4191 SERVER_START_REQ( get_process_idle_event
)
4193 req
->handle
= wine_server_obj_handle( hProcess
);
4194 wine_server_call_err( req
);
4195 handles
[1] = wine_server_ptr_handle( reply
->event
);
4198 if (!handles
[1]) return WAIT_FAILED
; /* no event to wait on */
4200 start_time
= GetTickCount();
4203 TRACE("waiting for %p\n", handles
[1] );
4206 ret
= MsgWaitForMultipleObjects ( 2, handles
, FALSE
, dwTimeOut
- elapsed
, QS_SENDMESSAGE
);
4211 case WAIT_OBJECT_0
+2:
4212 process_sent_messages();
4216 TRACE("timeout or error\n");
4219 TRACE("finished\n");
4222 if (dwTimeOut
!= INFINITE
)
4224 elapsed
= GetTickCount() - start_time
;
4225 if (elapsed
> dwTimeOut
)
4231 return WAIT_TIMEOUT
;
4235 /***********************************************************************
4236 * RegisterWindowMessageA (USER32.@)
4237 * RegisterWindowMessage (USER.118)
4239 UINT WINAPI
RegisterWindowMessageA( LPCSTR str
)
4241 UINT ret
= GlobalAddAtomA(str
);
4242 TRACE("%s, ret=%x\n", str
, ret
);
4247 /***********************************************************************
4248 * RegisterWindowMessageW (USER32.@)
4250 UINT WINAPI
RegisterWindowMessageW( LPCWSTR str
)
4252 UINT ret
= GlobalAddAtomW(str
);
4253 TRACE("%s ret=%x\n", debugstr_w(str
), ret
);
4257 typedef struct BroadcastParm
4268 static BOOL CALLBACK
bcast_childwindow( HWND hw
, LPARAM lp
)
4270 BroadcastParm
*parm
= (BroadcastParm
*)lp
;
4271 DWORD_PTR retval
= 0;
4274 if (parm
->flags
& BSF_IGNORECURRENTTASK
&& WIN_IsCurrentProcess(hw
))
4276 TRACE("Not telling myself %p\n", hw
);
4280 /* I don't know 100% for sure if this is what Windows does, but it fits the tests */
4281 if (parm
->flags
& BSF_QUERY
)
4283 TRACE("Telling window %p using SendMessageTimeout\n", hw
);
4285 /* Not tested for conflicting flags */
4286 if (parm
->flags
& BSF_FORCEIFHUNG
|| parm
->flags
& BSF_NOHANG
)
4287 lresult
= SendMessageTimeoutW( hw
, parm
->msg
, parm
->wp
, parm
->lp
, SMTO_ABORTIFHUNG
, 2000, &retval
);
4288 else if (parm
->flags
& BSF_NOTIMEOUTIFNOTHUNG
)
4289 lresult
= SendMessageTimeoutW( hw
, parm
->msg
, parm
->wp
, parm
->lp
, SMTO_NOTIMEOUTIFNOTHUNG
, 2000, &retval
);
4291 lresult
= SendMessageTimeoutW( hw
, parm
->msg
, parm
->wp
, parm
->lp
, SMTO_NORMAL
, 2000, &retval
);
4293 if (!lresult
&& GetLastError() == ERROR_TIMEOUT
)
4295 WARN("Timed out!\n");
4296 if (!(parm
->flags
& BSF_FORCEIFHUNG
))
4299 if (retval
== BROADCAST_QUERY_DENY
)
4305 parm
->success
= FALSE
;
4308 else if (parm
->flags
& BSF_POSTMESSAGE
)
4310 TRACE("Telling window %p using PostMessage\n", hw
);
4311 PostMessageW( hw
, parm
->msg
, parm
->wp
, parm
->lp
);
4315 TRACE("Telling window %p using SendNotifyMessage\n", hw
);
4316 SendNotifyMessageW( hw
, parm
->msg
, parm
->wp
, parm
->lp
);
4322 static BOOL CALLBACK
bcast_desktop( LPWSTR desktop
, LPARAM lp
)
4326 BroadcastParm
*parm
= (BroadcastParm
*)lp
;
4328 TRACE("desktop: %s\n", debugstr_w( desktop
));
4330 hdesktop
= open_winstation_desktop( parm
->winsta
, desktop
, 0, FALSE
, DESKTOP_ENUMERATE
|DESKTOP_WRITEOBJECTS
|STANDARD_RIGHTS_WRITE
);
4333 FIXME("Could not open desktop %s\n", debugstr_w(desktop
));
4337 ret
= EnumDesktopWindows( hdesktop
, bcast_childwindow
, lp
);
4338 CloseDesktop(hdesktop
);
4339 TRACE("-->%d\n", ret
);
4340 return parm
->success
;
4343 static BOOL CALLBACK
bcast_winsta( LPWSTR winsta
, LPARAM lp
)
4346 HWINSTA hwinsta
= OpenWindowStationW( winsta
, FALSE
, WINSTA_ENUMDESKTOPS
);
4347 TRACE("hwinsta: %p/%s/%08x\n", hwinsta
, debugstr_w( winsta
), GetLastError());
4350 ((BroadcastParm
*)lp
)->winsta
= hwinsta
;
4351 ret
= EnumDesktopsW( hwinsta
, bcast_desktop
, lp
);
4352 CloseWindowStation( hwinsta
);
4353 TRACE("-->%d\n", ret
);
4357 /***********************************************************************
4358 * BroadcastSystemMessageA (USER32.@)
4359 * BroadcastSystemMessage (USER32.@)
4361 LONG WINAPI
BroadcastSystemMessageA( DWORD flags
, LPDWORD recipients
, UINT msg
, WPARAM wp
, LPARAM lp
)
4363 return BroadcastSystemMessageExA( flags
, recipients
, msg
, wp
, lp
, NULL
);
4367 /***********************************************************************
4368 * BroadcastSystemMessageW (USER32.@)
4370 LONG WINAPI
BroadcastSystemMessageW( DWORD flags
, LPDWORD recipients
, UINT msg
, WPARAM wp
, LPARAM lp
)
4372 return BroadcastSystemMessageExW( flags
, recipients
, msg
, wp
, lp
, NULL
);
4375 /***********************************************************************
4376 * BroadcastSystemMessageExA (USER32.@)
4378 LONG WINAPI
BroadcastSystemMessageExA( DWORD flags
, LPDWORD recipients
, UINT msg
, WPARAM wp
, LPARAM lp
, PBSMINFO pinfo
)
4380 map_wparam_AtoW( msg
, &wp
, WMCHAR_MAP_NOMAPPING
);
4381 return BroadcastSystemMessageExW( flags
, recipients
, msg
, wp
, lp
, NULL
);
4385 /***********************************************************************
4386 * BroadcastSystemMessageExW (USER32.@)
4388 LONG WINAPI
BroadcastSystemMessageExW( DWORD flags
, LPDWORD recipients
, UINT msg
, WPARAM wp
, LPARAM lp
, PBSMINFO pinfo
)
4391 DWORD recips
= BSM_ALLCOMPONENTS
;
4393 static const DWORD all_flags
= ( BSF_QUERY
| BSF_IGNORECURRENTTASK
| BSF_FLUSHDISK
| BSF_NOHANG
4394 | BSF_POSTMESSAGE
| BSF_FORCEIFHUNG
| BSF_NOTIMEOUTIFNOTHUNG
4395 | BSF_ALLOWSFW
| BSF_SENDNOTIFYMESSAGE
| BSF_RETURNHDESK
| BSF_LUID
);
4397 TRACE("Flags: %08x, recipients: %p(0x%x), msg: %04x, wparam: %08lx, lparam: %08lx\n", flags
, recipients
,
4398 (recipients
? *recipients
: recips
), msg
, wp
, lp
);
4400 if (flags
& ~all_flags
)
4402 SetLastError(ERROR_INVALID_PARAMETER
);
4407 recipients
= &recips
;
4409 if ( pinfo
&& flags
& BSF_QUERY
)
4410 FIXME("Not returning PBSMINFO information yet\n");
4413 parm
.recipients
= recipients
;
4417 parm
.success
= TRUE
;
4419 if (*recipients
& BSM_ALLDESKTOPS
|| *recipients
== BSM_ALLCOMPONENTS
)
4420 ret
= EnumWindowStationsW(bcast_winsta
, (LONG_PTR
)&parm
);
4421 else if (*recipients
& BSM_APPLICATIONS
)
4423 EnumWindows(bcast_childwindow
, (LONG_PTR
)&parm
);
4427 FIXME("Recipients %08x not supported!\n", *recipients
);
4432 /***********************************************************************
4433 * SetMessageQueue (USER32.@)
4435 BOOL WINAPI
SetMessageQueue( INT size
)
4437 /* now obsolete the message queue will be expanded dynamically as necessary */
4442 /***********************************************************************
4443 * MessageBeep (USER32.@)
4445 BOOL WINAPI
MessageBeep( UINT i
)
4448 SystemParametersInfoA( SPI_GETBEEP
, 0, &active
, FALSE
);
4449 if (active
) USER_Driver
->pBeep();
4454 /***********************************************************************
4455 * SetCoalescableTimer (USER32.@)
4457 UINT_PTR WINAPI
SetCoalescableTimer( HWND hwnd
, UINT_PTR id
, UINT timeout
, TIMERPROC proc
, ULONG tolerance
)
4460 WNDPROC winproc
= 0;
4462 if (proc
) winproc
= WINPROC_AllocProc( (WNDPROC
)proc
, FALSE
);
4464 timeout
= min( max( USER_TIMER_MINIMUM
, timeout
), USER_TIMER_MAXIMUM
);
4466 SERVER_START_REQ( set_win_timer
)
4468 req
->win
= wine_server_user_handle( hwnd
);
4469 req
->msg
= WM_TIMER
;
4471 req
->rate
= timeout
;
4472 req
->lparam
= (ULONG_PTR
)winproc
;
4473 if (!wine_server_call_err( req
))
4476 if (!ret
) ret
= TRUE
;
4482 TRACE("Added %p %lx %p timeout %d\n", hwnd
, id
, winproc
, timeout
);
4487 /******************************************************************
4488 * SetTimer (USER32.@)
4490 UINT_PTR WINAPI
SetTimer( HWND hwnd
, UINT_PTR id
, UINT timeout
, TIMERPROC proc
)
4492 return SetCoalescableTimer( hwnd
, id
, timeout
, proc
, TIMERV_DEFAULT_COALESCING
);
4496 /***********************************************************************
4497 * SetSystemTimer (USER32.@)
4499 UINT_PTR WINAPI
SetSystemTimer( HWND hwnd
, UINT_PTR id
, UINT timeout
, TIMERPROC proc
)
4502 WNDPROC winproc
= 0;
4504 if (proc
) winproc
= WINPROC_AllocProc( (WNDPROC
)proc
, FALSE
);
4506 timeout
= min( max( USER_TIMER_MINIMUM
, timeout
), USER_TIMER_MAXIMUM
);
4508 SERVER_START_REQ( set_win_timer
)
4510 req
->win
= wine_server_user_handle( hwnd
);
4511 req
->msg
= WM_SYSTIMER
;
4513 req
->rate
= timeout
;
4514 req
->lparam
= (ULONG_PTR
)winproc
;
4515 if (!wine_server_call_err( req
))
4518 if (!ret
) ret
= TRUE
;
4524 TRACE("Added %p %lx %p timeout %d\n", hwnd
, id
, winproc
, timeout
);
4529 /***********************************************************************
4530 * KillTimer (USER32.@)
4532 BOOL WINAPI
KillTimer( HWND hwnd
, UINT_PTR id
)
4536 SERVER_START_REQ( kill_win_timer
)
4538 req
->win
= wine_server_user_handle( hwnd
);
4539 req
->msg
= WM_TIMER
;
4541 ret
= !wine_server_call_err( req
);
4548 /***********************************************************************
4549 * KillSystemTimer (USER32.@)
4551 BOOL WINAPI
KillSystemTimer( HWND hwnd
, UINT_PTR id
)
4555 SERVER_START_REQ( kill_win_timer
)
4557 req
->win
= wine_server_user_handle( hwnd
);
4558 req
->msg
= WM_SYSTIMER
;
4560 ret
= !wine_server_call_err( req
);
4567 /**********************************************************************
4568 * IsGUIThread (USER32.@)
4570 BOOL WINAPI
IsGUIThread( BOOL convert
)
4572 FIXME( "%u: stub\n", convert
);
4577 /**********************************************************************
4578 * GetGUIThreadInfo (USER32.@)
4580 BOOL WINAPI
GetGUIThreadInfo( DWORD id
, GUITHREADINFO
*info
)
4584 if (info
->cbSize
!= sizeof(*info
))
4586 SetLastError( ERROR_INVALID_PARAMETER
);
4590 SERVER_START_REQ( get_thread_input
)
4593 if ((ret
= !wine_server_call_err( req
)))
4596 info
->hwndActive
= wine_server_ptr_handle( reply
->active
);
4597 info
->hwndFocus
= wine_server_ptr_handle( reply
->focus
);
4598 info
->hwndCapture
= wine_server_ptr_handle( reply
->capture
);
4599 info
->hwndMenuOwner
= wine_server_ptr_handle( reply
->menu_owner
);
4600 info
->hwndMoveSize
= wine_server_ptr_handle( reply
->move_size
);
4601 info
->hwndCaret
= wine_server_ptr_handle( reply
->caret
);
4602 info
->rcCaret
.left
= reply
->rect
.left
;
4603 info
->rcCaret
.top
= reply
->rect
.top
;
4604 info
->rcCaret
.right
= reply
->rect
.right
;
4605 info
->rcCaret
.bottom
= reply
->rect
.bottom
;
4606 if (reply
->menu_owner
) info
->flags
|= GUI_INMENUMODE
;
4607 if (reply
->move_size
) info
->flags
|= GUI_INMOVESIZE
;
4608 if (reply
->caret
) info
->flags
|= GUI_CARETBLINKING
;
4616 /******************************************************************
4617 * IsHungAppWindow (USER32.@)
4620 BOOL WINAPI
IsHungAppWindow( HWND hWnd
)
4624 SERVER_START_REQ( is_window_hung
)
4626 req
->win
= wine_server_user_handle( hWnd
);
4627 ret
= !wine_server_call_err( req
) && reply
->is_hung
;
4633 /******************************************************************
4634 * ChangeWindowMessageFilter (USER32.@)
4636 BOOL WINAPI
ChangeWindowMessageFilter( UINT message
, DWORD flag
)
4638 FIXME( "%x %08x\n", message
, flag
);
4642 /******************************************************************
4643 * ChangeWindowMessageFilterEx (USER32.@)
4645 BOOL WINAPI
ChangeWindowMessageFilterEx( HWND hwnd
, UINT message
, DWORD action
, CHANGEFILTERSTRUCT
*changefilter
)
4647 FIXME( "%p %x %d %p\n", hwnd
, message
, action
, changefilter
);