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"
29 #define WIN32_NO_STATUS
40 #include "wine/unicode.h"
41 #include "wine/server.h"
42 #include "user_private.h"
45 #include "wine/debug.h"
46 #include "wine/exception.h"
48 WINE_DEFAULT_DEBUG_CHANNEL(msg
);
49 WINE_DECLARE_DEBUG_CHANNEL(relay
);
50 WINE_DECLARE_DEBUG_CHANNEL(key
);
52 #define WM_NCMOUSEFIRST WM_NCMOUSEMOVE
53 #define WM_NCMOUSELAST (WM_NCMOUSEFIRST+(WM_MOUSELAST-WM_MOUSEFIRST))
55 #define MAX_PACK_COUNT 4
57 #define SYS_TIMER_RATE 55 /* min. timer rate in ms (actually 54.925)*/
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 /* the structures are unpacked on top of the packed ones, so make sure they fit */
150 C_ASSERT( sizeof(struct packed_CREATESTRUCTW
) >= sizeof(CREATESTRUCTW
) );
151 C_ASSERT( sizeof(struct packed_DRAWITEMSTRUCT
) >= sizeof(DRAWITEMSTRUCT
) );
152 C_ASSERT( sizeof(struct packed_MEASUREITEMSTRUCT
) >= sizeof(MEASUREITEMSTRUCT
) );
153 C_ASSERT( sizeof(struct packed_DELETEITEMSTRUCT
) >= sizeof(DELETEITEMSTRUCT
) );
154 C_ASSERT( sizeof(struct packed_COMPAREITEMSTRUCT
) >= sizeof(COMPAREITEMSTRUCT
) );
155 C_ASSERT( sizeof(struct packed_WINDOWPOS
) >= sizeof(WINDOWPOS
) );
156 C_ASSERT( sizeof(struct packed_COPYDATASTRUCT
) >= sizeof(COPYDATASTRUCT
) );
160 struct packed_CREATESTRUCTW cs
;
161 struct packed_DRAWITEMSTRUCT dis
;
162 struct packed_MEASUREITEMSTRUCT mis
;
163 struct packed_DELETEITEMSTRUCT dls
;
164 struct packed_COMPAREITEMSTRUCT cis
;
165 struct packed_WINDOWPOS wp
;
166 struct packed_COPYDATASTRUCT cds
;
169 /* description of the data fields that need to be packed along with a sent message */
170 struct packed_message
172 union packed_structs ps
;
174 const void *data
[MAX_PACK_COUNT
];
175 size_t size
[MAX_PACK_COUNT
];
178 /* info about the message currently being received by the current thread */
179 struct received_message_info
181 enum message_type type
;
183 UINT flags
; /* InSendMessageEx return flags */
186 /* structure to group all parameters for sent messages of the various kinds */
187 struct send_message_info
189 enum message_type type
;
195 UINT flags
; /* flags for SendMessageTimeout */
196 UINT timeout
; /* timeout for SendMessageTimeout */
197 SENDASYNCPROC callback
; /* callback function for SendMessageCallback */
198 ULONG_PTR data
; /* callback data */
199 enum wm_char_mapping wm_char
;
203 /* Message class descriptor */
204 static const WCHAR messageW
[] = {'M','e','s','s','a','g','e',0};
206 const struct builtin_class_descr MESSAGE_builtin_class
=
210 WINPROC_MESSAGE
, /* proc */
212 IDC_ARROW
, /* cursor */
218 /* flag for messages that contain pointers */
219 /* 32 messages per entry, messages 0..31 map to bits 0..31 */
221 #define SET(msg) (1 << ((msg) & 31))
223 static const unsigned int message_pointer_flags
[] =
226 SET(WM_CREATE
) | SET(WM_SETTEXT
) | SET(WM_GETTEXT
) |
227 SET(WM_WININICHANGE
) | SET(WM_DEVMODECHANGE
),
229 SET(WM_GETMINMAXINFO
) | SET(WM_DRAWITEM
) | SET(WM_MEASUREITEM
) | SET(WM_DELETEITEM
) |
232 SET(WM_WINDOWPOSCHANGING
) | SET(WM_WINDOWPOSCHANGED
) | SET(WM_COPYDATA
) |
233 SET(WM_NOTIFY
) | SET(WM_HELP
),
235 SET(WM_STYLECHANGING
) | SET(WM_STYLECHANGED
),
237 SET(WM_NCCREATE
) | SET(WM_NCCALCSIZE
) | SET(WM_GETDLGCODE
),
239 SET(EM_GETSEL
) | SET(EM_GETRECT
) | SET(EM_SETRECT
) | SET(EM_SETRECTNP
),
241 SET(EM_REPLACESEL
) | SET(EM_GETLINE
) | SET(EM_SETTABSTOPS
),
243 SET(SBM_GETRANGE
) | SET(SBM_SETSCROLLINFO
) | SET(SBM_GETSCROLLINFO
) | SET(SBM_GETSCROLLBARINFO
),
249 SET(CB_GETEDITSEL
) | SET(CB_ADDSTRING
) | SET(CB_DIR
) | SET(CB_GETLBTEXT
) |
250 SET(CB_INSERTSTRING
) | SET(CB_FINDSTRING
) | SET(CB_SELECTSTRING
) |
251 SET(CB_GETDROPPEDCONTROLRECT
) | SET(CB_FINDSTRINGEXACT
),
255 SET(LB_ADDSTRING
) | SET(LB_INSERTSTRING
) | SET(LB_GETTEXT
) | SET(LB_SELECTSTRING
) |
256 SET(LB_DIR
) | SET(LB_FINDSTRING
) |
257 SET(LB_GETSELITEMS
) | SET(LB_SETTABSTOPS
) | SET(LB_ADDFILE
) | SET(LB_GETITEMRECT
),
259 SET(LB_FINDSTRINGEXACT
),
265 SET(WM_NEXTMENU
) | SET(WM_SIZING
) | SET(WM_MOVING
) | SET(WM_DEVICECHANGE
),
267 SET(WM_MDICREATE
) | SET(WM_MDIGETACTIVE
) | SET(WM_DROPOBJECT
) |
268 SET(WM_QUERYDROPOBJECT
) | SET(WM_DRAGLOOP
) | SET(WM_DRAGSELECT
) | SET(WM_DRAGMOVE
),
282 SET(WM_ASKCBFORMATNAME
)
285 /* flags for messages that contain Unicode strings */
286 static const unsigned int message_unicode_flags
[] =
289 SET(WM_CREATE
) | SET(WM_SETTEXT
) | SET(WM_GETTEXT
) | SET(WM_GETTEXTLENGTH
) |
290 SET(WM_WININICHANGE
) | SET(WM_DEVMODECHANGE
),
302 SET(EM_REPLACESEL
) | SET(EM_GETLINE
) | SET(EM_SETPASSWORDCHAR
),
306 SET(WM_CHAR
) | SET(WM_DEADCHAR
) | SET(WM_SYSCHAR
) | SET(WM_SYSDEADCHAR
),
310 SET(CB_ADDSTRING
) | SET(CB_DIR
) | SET(CB_GETLBTEXT
) | SET(CB_GETLBTEXTLEN
) |
311 SET(CB_INSERTSTRING
) | SET(CB_FINDSTRING
) | SET(CB_SELECTSTRING
) | SET(CB_FINDSTRINGEXACT
),
315 SET(LB_ADDSTRING
) | SET(LB_INSERTSTRING
) | SET(LB_GETTEXT
) | SET(LB_GETTEXTLEN
) |
316 SET(LB_SELECTSTRING
) | SET(LB_DIR
) | SET(LB_FINDSTRING
) | SET(LB_ADDFILE
),
318 SET(LB_FINDSTRINGEXACT
),
340 SET(WM_PAINTCLIPBOARD
) | SET(WM_SIZECLIPBOARD
) | SET(WM_ASKCBFORMATNAME
)
343 /* check whether a given message type includes pointers */
344 static inline int is_pointer_message( UINT message
)
346 if (message
>= 8*sizeof(message_pointer_flags
)) return FALSE
;
347 return (message_pointer_flags
[message
/ 32] & SET(message
)) != 0;
350 /* check whether a given message type contains Unicode (or ASCII) chars */
351 static inline int is_unicode_message( UINT message
)
353 if (message
>= 8*sizeof(message_unicode_flags
)) return FALSE
;
354 return (message_unicode_flags
[message
/ 32] & SET(message
)) != 0;
359 /* add a data field to a packed message */
360 static inline void push_data( struct packed_message
*data
, const void *ptr
, size_t size
)
362 data
->data
[data
->count
] = ptr
;
363 data
->size
[data
->count
] = size
;
367 /* add a string to a packed message */
368 static inline void push_string( struct packed_message
*data
, LPCWSTR str
)
370 push_data( data
, str
, (strlenW(str
) + 1) * sizeof(WCHAR
) );
373 /* make sure that the buffer contains a valid null-terminated Unicode string */
374 static inline BOOL
check_string( LPCWSTR str
, size_t size
)
376 for (size
/= sizeof(WCHAR
); size
; size
--, str
++)
377 if (!*str
) return TRUE
;
381 /* pack a pointer into a 32/64 portable format */
382 static inline ULONGLONG
pack_ptr( const void *ptr
)
384 return (ULONG_PTR
)ptr
;
387 /* unpack a potentially 64-bit pointer, returning 0 when truncated */
388 static inline void *unpack_ptr( ULONGLONG ptr64
)
390 if ((ULONG_PTR
)ptr64
!= ptr64
) return 0;
391 return (void *)(ULONG_PTR
)ptr64
;
394 /* make sure that there is space for 'size' bytes in buffer, growing it if needed */
395 static inline void *get_buffer_space( void **buffer
, size_t size
)
401 if (!(ret
= HeapReAlloc( GetProcessHeap(), 0, *buffer
, size
)))
402 HeapFree( GetProcessHeap(), 0, *buffer
);
404 else ret
= HeapAlloc( GetProcessHeap(), 0, size
);
410 /* check whether a combobox expects strings or ids in CB_ADDSTRING/CB_INSERTSTRING */
411 static inline BOOL
combobox_has_strings( HWND hwnd
)
413 DWORD style
= GetWindowLongA( hwnd
, GWL_STYLE
);
414 return (!(style
& (CBS_OWNERDRAWFIXED
| CBS_OWNERDRAWVARIABLE
)) || (style
& CBS_HASSTRINGS
));
417 /* check whether a listbox expects strings or ids in LB_ADDSTRING/LB_INSERTSTRING */
418 static inline BOOL
listbox_has_strings( HWND hwnd
)
420 DWORD style
= GetWindowLongA( hwnd
, GWL_STYLE
);
421 return (!(style
& (LBS_OWNERDRAWFIXED
| LBS_OWNERDRAWVARIABLE
)) || (style
& LBS_HASSTRINGS
));
424 /* check whether message is in the range of keyboard messages */
425 static inline BOOL
is_keyboard_message( UINT message
)
427 return (message
>= WM_KEYFIRST
&& message
<= WM_KEYLAST
);
430 /* check whether message is in the range of mouse messages */
431 static inline BOOL
is_mouse_message( UINT message
)
433 return ((message
>= WM_NCMOUSEFIRST
&& message
<= WM_NCMOUSELAST
) ||
434 (message
>= WM_MOUSEFIRST
&& message
<= WM_MOUSELAST
));
437 /* check whether message matches the specified hwnd filter */
438 static inline BOOL
check_hwnd_filter( const MSG
*msg
, HWND hwnd_filter
)
440 if (!hwnd_filter
|| hwnd_filter
== GetDesktopWindow()) return TRUE
;
441 return (msg
->hwnd
== hwnd_filter
|| IsChild( hwnd_filter
, msg
->hwnd
));
444 /* check for pending WM_CHAR message with DBCS trailing byte */
445 static inline BOOL
get_pending_wmchar( MSG
*msg
, UINT first
, UINT last
, BOOL remove
)
447 struct wm_char_mapping_data
*data
= get_user_thread_info()->wmchar_data
;
449 if (!data
|| !data
->get_msg
.message
) return FALSE
;
450 if ((first
|| last
) && (first
> WM_CHAR
|| last
< WM_CHAR
)) return FALSE
;
451 if (!msg
) return FALSE
;
452 *msg
= data
->get_msg
;
453 if (remove
) data
->get_msg
.message
= 0;
458 /***********************************************************************
461 * Window procedure for "Message" windows (HWND_MESSAGE parent).
463 LRESULT WINAPI
MessageWndProc( HWND hwnd
, UINT message
, WPARAM wParam
, LPARAM lParam
)
465 if (message
== WM_NCCREATE
) return TRUE
;
466 return 0; /* all other messages are ignored */
470 /***********************************************************************
471 * broadcast_message_callback
473 * Helper callback for broadcasting messages.
475 static BOOL CALLBACK
broadcast_message_callback( HWND hwnd
, LPARAM lparam
)
477 struct send_message_info
*info
= (struct send_message_info
*)lparam
;
478 if (!(GetWindowLongW( hwnd
, GWL_STYLE
) & (WS_POPUP
|WS_CAPTION
))) return TRUE
;
482 SendMessageTimeoutW( hwnd
, info
->msg
, info
->wparam
, info
->lparam
,
483 info
->flags
, info
->timeout
, NULL
);
486 SendMessageTimeoutA( hwnd
, info
->msg
, info
->wparam
, info
->lparam
,
487 info
->flags
, info
->timeout
, NULL
);
490 SendNotifyMessageW( hwnd
, info
->msg
, info
->wparam
, info
->lparam
);
493 SendMessageCallbackW( hwnd
, info
->msg
, info
->wparam
, info
->lparam
,
494 info
->callback
, info
->data
);
497 PostMessageW( hwnd
, info
->msg
, info
->wparam
, info
->lparam
);
500 ERR( "bad type %d\n", info
->type
);
507 /***********************************************************************
510 * Convert the wparam of an ASCII message to Unicode.
512 BOOL
map_wparam_AtoW( UINT message
, WPARAM
*wparam
, enum wm_char_mapping mapping
)
521 /* WM_CHAR is magic: a DBCS char can be sent/posted as two consecutive WM_CHAR
522 * messages, in which case the first char is stored, and the conversion
523 * to Unicode only takes place once the second char is sent/posted.
525 if (mapping
!= WMCHAR_MAP_NOMAPPING
)
527 struct wm_char_mapping_data
*data
= get_user_thread_info()->wmchar_data
;
528 BYTE low
= LOBYTE(*wparam
);
533 ch
[1] = HIBYTE(*wparam
);
534 RtlMultiByteToUnicodeN( wch
, sizeof(wch
), NULL
, ch
, 2 );
535 TRACE( "map %02x,%02x -> %04x mapping %u\n", (BYTE
)ch
[0], (BYTE
)ch
[1], wch
[0], mapping
);
536 if (data
) data
->lead_byte
[mapping
] = 0;
538 else if (data
&& data
->lead_byte
[mapping
])
540 ch
[0] = data
->lead_byte
[mapping
];
542 RtlMultiByteToUnicodeN( wch
, sizeof(wch
), NULL
, ch
, 2 );
543 TRACE( "map stored %02x,%02x -> %04x mapping %u\n", (BYTE
)ch
[0], (BYTE
)ch
[1], wch
[0], mapping
);
544 data
->lead_byte
[mapping
] = 0;
546 else if (!IsDBCSLeadByte( low
))
549 RtlMultiByteToUnicodeN( wch
, sizeof(wch
), NULL
, ch
, 1 );
550 TRACE( "map %02x -> %04x\n", (BYTE
)ch
[0], wch
[0] );
551 if (data
) data
->lead_byte
[mapping
] = 0;
553 else /* store it and wait for trail byte */
557 if (!(data
= HeapAlloc( GetProcessHeap(), HEAP_ZERO_MEMORY
, sizeof(*data
) )))
559 get_user_thread_info()->wmchar_data
= data
;
561 TRACE( "storing lead byte %02x mapping %u\n", low
, mapping
);
562 data
->lead_byte
[mapping
] = low
;
565 *wparam
= MAKEWPARAM(wch
[0], wch
[1]);
568 /* else fall through */
570 case EM_SETPASSWORDCHAR
:
575 ch
[0] = LOBYTE(*wparam
);
576 ch
[1] = HIBYTE(*wparam
);
577 RtlMultiByteToUnicodeN( wch
, sizeof(wch
), NULL
, ch
, 2 );
578 *wparam
= MAKEWPARAM(wch
[0], wch
[1]);
581 ch
[0] = HIBYTE(*wparam
);
582 ch
[1] = LOBYTE(*wparam
);
583 if (ch
[0]) RtlMultiByteToUnicodeN( wch
, sizeof(wch
[0]), NULL
, ch
, 2 );
584 else RtlMultiByteToUnicodeN( wch
, sizeof(wch
[0]), NULL
, ch
+ 1, 1 );
585 *wparam
= MAKEWPARAM(wch
[0], HIWORD(*wparam
));
592 /***********************************************************************
595 * Convert the wparam of a Unicode message to ASCII.
597 static void map_wparam_WtoA( MSG
*msg
, BOOL remove
)
606 if (!HIWORD(msg
->wParam
))
608 wch
[0] = LOWORD(msg
->wParam
);
610 RtlUnicodeToMultiByteN( (LPSTR
)ch
, 2, &len
, wch
, sizeof(wch
[0]) );
611 if (len
== 2) /* DBCS char */
613 struct wm_char_mapping_data
*data
= get_user_thread_info()->wmchar_data
;
616 if (!(data
= HeapAlloc( GetProcessHeap(), HEAP_ZERO_MEMORY
, sizeof(*data
) ))) return;
617 get_user_thread_info()->wmchar_data
= data
;
621 data
->get_msg
= *msg
;
622 data
->get_msg
.wParam
= ch
[1];
628 /* else fall through */
630 case EM_SETPASSWORDCHAR
:
635 wch
[0] = LOWORD(msg
->wParam
);
636 wch
[1] = HIWORD(msg
->wParam
);
638 RtlUnicodeToMultiByteN( (LPSTR
)ch
, 2, NULL
, wch
, sizeof(wch
) );
639 msg
->wParam
= MAKEWPARAM( ch
[0] | (ch
[1] << 8), 0 );
642 wch
[0] = LOWORD(msg
->wParam
);
644 RtlUnicodeToMultiByteN( (LPSTR
)ch
, 2, &len
, wch
, sizeof(wch
[0]) );
646 msg
->wParam
= MAKEWPARAM( (ch
[0] << 8) | ch
[1], HIWORD(msg
->wParam
) );
648 msg
->wParam
= MAKEWPARAM( ch
[0], HIWORD(msg
->wParam
) );
654 /***********************************************************************
657 * Pack a message for sending to another process.
658 * Return the size of the data we expect in the message reply.
659 * Set data->count to -1 if there is an error.
661 static size_t pack_message( HWND hwnd
, UINT message
, WPARAM wparam
, LPARAM lparam
,
662 struct packed_message
*data
)
670 CREATESTRUCTW
*cs
= (CREATESTRUCTW
*)lparam
;
671 data
->ps
.cs
.lpCreateParams
= pack_ptr( cs
->lpCreateParams
);
672 data
->ps
.cs
.hInstance
= pack_ptr( cs
->hInstance
);
673 data
->ps
.cs
.hMenu
= wine_server_user_handle( cs
->hMenu
);
674 data
->ps
.cs
.hwndParent
= wine_server_user_handle( cs
->hwndParent
);
675 data
->ps
.cs
.cy
= cs
->cy
;
676 data
->ps
.cs
.cx
= cs
->cx
;
677 data
->ps
.cs
.y
= cs
->y
;
678 data
->ps
.cs
.x
= cs
->x
;
679 data
->ps
.cs
.style
= cs
->style
;
680 data
->ps
.cs
.dwExStyle
= cs
->dwExStyle
;
681 data
->ps
.cs
.lpszName
= pack_ptr( cs
->lpszName
);
682 data
->ps
.cs
.lpszClass
= pack_ptr( cs
->lpszClass
);
683 push_data( data
, &data
->ps
.cs
, sizeof(data
->ps
.cs
) );
684 if (!IS_INTRESOURCE(cs
->lpszName
)) push_string( data
, cs
->lpszName
);
685 if (!IS_INTRESOURCE(cs
->lpszClass
)) push_string( data
, cs
->lpszClass
);
686 return sizeof(data
->ps
.cs
);
689 case WM_ASKCBFORMATNAME
:
690 return wparam
* sizeof(WCHAR
);
691 case WM_WININICHANGE
:
692 if (lparam
) push_string(data
, (LPWSTR
)lparam
);
695 case WM_DEVMODECHANGE
:
700 push_string( data
, (LPWSTR
)lparam
);
702 case WM_GETMINMAXINFO
:
703 push_data( data
, (MINMAXINFO
*)lparam
, sizeof(MINMAXINFO
) );
704 return sizeof(MINMAXINFO
);
707 DRAWITEMSTRUCT
*dis
= (DRAWITEMSTRUCT
*)lparam
;
708 data
->ps
.dis
.CtlType
= dis
->CtlType
;
709 data
->ps
.dis
.CtlID
= dis
->CtlID
;
710 data
->ps
.dis
.itemID
= dis
->itemID
;
711 data
->ps
.dis
.itemAction
= dis
->itemAction
;
712 data
->ps
.dis
.itemState
= dis
->itemState
;
713 data
->ps
.dis
.hwndItem
= wine_server_user_handle( dis
->hwndItem
);
714 data
->ps
.dis
.hDC
= wine_server_user_handle( dis
->hDC
); /* FIXME */
715 data
->ps
.dis
.rcItem
= dis
->rcItem
;
716 data
->ps
.dis
.itemData
= dis
->itemData
;
717 push_data( data
, &data
->ps
.dis
, sizeof(data
->ps
.dis
) );
722 MEASUREITEMSTRUCT
*mis
= (MEASUREITEMSTRUCT
*)lparam
;
723 data
->ps
.mis
.CtlType
= mis
->CtlType
;
724 data
->ps
.mis
.CtlID
= mis
->CtlID
;
725 data
->ps
.mis
.itemID
= mis
->itemID
;
726 data
->ps
.mis
.itemWidth
= mis
->itemWidth
;
727 data
->ps
.mis
.itemHeight
= mis
->itemHeight
;
728 data
->ps
.mis
.itemData
= mis
->itemData
;
729 push_data( data
, &data
->ps
.mis
, sizeof(data
->ps
.mis
) );
730 return sizeof(data
->ps
.mis
);
734 DELETEITEMSTRUCT
*dls
= (DELETEITEMSTRUCT
*)lparam
;
735 data
->ps
.dls
.CtlType
= dls
->CtlType
;
736 data
->ps
.dls
.CtlID
= dls
->CtlID
;
737 data
->ps
.dls
.itemID
= dls
->itemID
;
738 data
->ps
.dls
.hwndItem
= wine_server_user_handle( dls
->hwndItem
);
739 data
->ps
.dls
.itemData
= dls
->itemData
;
740 push_data( data
, &data
->ps
.dls
, sizeof(data
->ps
.dls
) );
745 COMPAREITEMSTRUCT
*cis
= (COMPAREITEMSTRUCT
*)lparam
;
746 data
->ps
.cis
.CtlType
= cis
->CtlType
;
747 data
->ps
.cis
.CtlID
= cis
->CtlID
;
748 data
->ps
.cis
.hwndItem
= wine_server_user_handle( cis
->hwndItem
);
749 data
->ps
.cis
.itemID1
= cis
->itemID1
;
750 data
->ps
.cis
.itemData1
= cis
->itemData1
;
751 data
->ps
.cis
.itemID2
= cis
->itemID2
;
752 data
->ps
.cis
.itemData2
= cis
->itemData2
;
753 data
->ps
.cis
.dwLocaleId
= cis
->dwLocaleId
;
754 push_data( data
, &data
->ps
.cis
, sizeof(data
->ps
.cis
) );
757 case WM_WINDOWPOSCHANGING
:
758 case WM_WINDOWPOSCHANGED
:
760 WINDOWPOS
*wp
= (WINDOWPOS
*)lparam
;
761 data
->ps
.wp
.hwnd
= wine_server_user_handle( wp
->hwnd
);
762 data
->ps
.wp
.hwndInsertAfter
= wine_server_user_handle( wp
->hwndInsertAfter
);
763 data
->ps
.wp
.x
= wp
->x
;
764 data
->ps
.wp
.y
= wp
->y
;
765 data
->ps
.wp
.cx
= wp
->cx
;
766 data
->ps
.wp
.cy
= wp
->cy
;
767 data
->ps
.wp
.flags
= wp
->flags
;
768 push_data( data
, &data
->ps
.wp
, sizeof(data
->ps
.wp
) );
769 return sizeof(data
->ps
.wp
);
773 COPYDATASTRUCT
*cds
= (COPYDATASTRUCT
*)lparam
;
774 data
->ps
.cds
.cbData
= cds
->cbData
;
775 data
->ps
.cds
.dwData
= cds
->dwData
;
776 data
->ps
.cds
.lpData
= pack_ptr( cds
->lpData
);
777 push_data( data
, &data
->ps
.cds
, sizeof(data
->ps
.cds
) );
778 if (cds
->lpData
) push_data( data
, cds
->lpData
, cds
->cbData
);
782 /* WM_NOTIFY cannot be sent across processes (MSDN) */
786 push_data( data
, (HELPINFO
*)lparam
, sizeof(HELPINFO
) );
788 case WM_STYLECHANGING
:
789 case WM_STYLECHANGED
:
790 push_data( data
, (STYLESTRUCT
*)lparam
, sizeof(STYLESTRUCT
) );
795 push_data( data
, (RECT
*)lparam
, sizeof(RECT
) );
800 NCCALCSIZE_PARAMS
*nc
= (NCCALCSIZE_PARAMS
*)lparam
;
801 push_data( data
, nc
, sizeof(*nc
) );
802 push_data( data
, nc
->lppos
, sizeof(*nc
->lppos
) );
803 return sizeof(*nc
) + sizeof(*nc
->lppos
);
806 if (lparam
) push_data( data
, (MSG
*)lparam
, sizeof(MSG
) );
808 case SBM_SETSCROLLINFO
:
809 push_data( data
, (SCROLLINFO
*)lparam
, sizeof(SCROLLINFO
) );
811 case SBM_GETSCROLLINFO
:
812 push_data( data
, (SCROLLINFO
*)lparam
, sizeof(SCROLLINFO
) );
813 return sizeof(SCROLLINFO
);
814 case SBM_GETSCROLLBARINFO
:
816 const SCROLLBARINFO
*info
= (const SCROLLBARINFO
*)lparam
;
817 size_t size
= min( info
->cbSize
, sizeof(SCROLLBARINFO
) );
818 push_data( data
, info
, size
);
826 if (wparam
) size
+= sizeof(DWORD
);
827 if (lparam
) size
+= sizeof(DWORD
);
832 case CB_GETDROPPEDCONTROLRECT
:
836 push_data( data
, (RECT
*)lparam
, sizeof(RECT
) );
840 WORD
*pw
= (WORD
*)lparam
;
841 push_data( data
, pw
, sizeof(*pw
) );
842 return *pw
* sizeof(WCHAR
);
846 if (wparam
) push_data( data
, (UINT
*)lparam
, sizeof(UINT
) * wparam
);
849 case CB_INSERTSTRING
:
851 case CB_FINDSTRINGEXACT
:
852 case CB_SELECTSTRING
:
853 if (combobox_has_strings( hwnd
)) push_string( data
, (LPWSTR
)lparam
);
856 if (!combobox_has_strings( hwnd
)) return sizeof(ULONG_PTR
);
857 return (SendMessageW( hwnd
, CB_GETLBTEXTLEN
, wparam
, 0 ) + 1) * sizeof(WCHAR
);
859 case LB_INSERTSTRING
:
861 case LB_FINDSTRINGEXACT
:
862 case LB_SELECTSTRING
:
863 if (listbox_has_strings( hwnd
)) push_string( data
, (LPWSTR
)lparam
);
866 if (!listbox_has_strings( hwnd
)) return sizeof(ULONG_PTR
);
867 return (SendMessageW( hwnd
, LB_GETTEXTLEN
, wparam
, 0 ) + 1) * sizeof(WCHAR
);
869 return wparam
* sizeof(UINT
);
871 push_data( data
, (MDINEXTMENU
*)lparam
, sizeof(MDINEXTMENU
) );
872 return sizeof(MDINEXTMENU
);
875 push_data( data
, (RECT
*)lparam
, sizeof(RECT
) );
879 MDICREATESTRUCTW
*cs
= (MDICREATESTRUCTW
*)lparam
;
880 push_data( data
, cs
, sizeof(*cs
) );
881 if (!IS_INTRESOURCE(cs
->szTitle
)) push_string( data
, cs
->szTitle
);
882 if (!IS_INTRESOURCE(cs
->szClass
)) push_string( data
, cs
->szClass
);
885 case WM_MDIGETACTIVE
:
886 if (lparam
) return sizeof(BOOL
);
888 case WM_DEVICECHANGE
:
890 DEV_BROADCAST_HDR
*header
= (DEV_BROADCAST_HDR
*)lparam
;
891 push_data( data
, header
, header
->dbch_size
);
894 case WM_WINE_SETWINDOWPOS
:
895 push_data( data
, (WINDOWPOS
*)lparam
, sizeof(WINDOWPOS
) );
897 case WM_WINE_KEYBOARD_LL_HOOK
:
899 struct hook_extra_info
*h_extra
= (struct hook_extra_info
*)lparam
;
900 push_data( data
, h_extra
, sizeof(*h_extra
) );
901 push_data( data
, (LPVOID
)h_extra
->lparam
, sizeof(KBDLLHOOKSTRUCT
) );
904 case WM_WINE_MOUSE_LL_HOOK
:
906 struct hook_extra_info
*h_extra
= (struct hook_extra_info
*)lparam
;
907 push_data( data
, h_extra
, sizeof(*h_extra
) );
908 push_data( data
, (LPVOID
)h_extra
->lparam
, sizeof(MSLLHOOKSTRUCT
) );
912 if (wparam
<= 1) return 0;
913 FIXME( "WM_NCPAINT hdc packing not supported yet\n" );
917 if (!wparam
) return 0;
920 /* these contain an HFONT */
923 /* these contain an HDC */
925 case WM_ICONERASEBKGND
:
926 case WM_CTLCOLORMSGBOX
:
927 case WM_CTLCOLOREDIT
:
928 case WM_CTLCOLORLISTBOX
:
931 case WM_CTLCOLORSCROLLBAR
:
932 case WM_CTLCOLORSTATIC
:
935 /* these contain an HGLOBAL */
936 case WM_PAINTCLIPBOARD
:
937 case WM_SIZECLIPBOARD
:
938 /* these contain HICON */
941 case WM_QUERYDRAGICON
:
942 case WM_QUERYPARKICON
:
943 /* these contain pointers */
945 case WM_QUERYDROPOBJECT
:
949 FIXME( "msg %x (%s) not supported yet\n", message
, SPY_GetMsgName(message
, hwnd
) );
957 /***********************************************************************
960 * Unpack a message received from another process.
962 static BOOL
unpack_message( HWND hwnd
, UINT message
, WPARAM
*wparam
, LPARAM
*lparam
,
963 void **buffer
, size_t size
)
966 union packed_structs
*ps
= *buffer
;
974 WCHAR
*str
= (WCHAR
*)(&ps
->cs
+ 1);
975 if (size
< sizeof(ps
->cs
)) return FALSE
;
976 size
-= sizeof(ps
->cs
);
977 cs
.lpCreateParams
= unpack_ptr( ps
->cs
.lpCreateParams
);
978 cs
.hInstance
= unpack_ptr( ps
->cs
.hInstance
);
979 cs
.hMenu
= wine_server_ptr_handle( ps
->cs
.hMenu
);
980 cs
.hwndParent
= wine_server_ptr_handle( ps
->cs
.hwndParent
);
985 cs
.style
= ps
->cs
.style
;
986 cs
.dwExStyle
= ps
->cs
.dwExStyle
;
987 cs
.lpszName
= unpack_ptr( ps
->cs
.lpszName
);
988 cs
.lpszClass
= unpack_ptr( ps
->cs
.lpszClass
);
989 if (ps
->cs
.lpszName
>> 16)
991 if (!check_string( str
, size
)) return FALSE
;
993 size
-= (strlenW(str
) + 1) * sizeof(WCHAR
);
994 str
+= strlenW(str
) + 1;
996 if (ps
->cs
.lpszClass
>> 16)
998 if (!check_string( str
, size
)) return FALSE
;
1001 memcpy( &ps
->cs
, &cs
, sizeof(cs
) );
1005 case WM_ASKCBFORMATNAME
:
1006 if (!get_buffer_space( buffer
, (*wparam
* sizeof(WCHAR
)) )) return FALSE
;
1008 case WM_WININICHANGE
:
1009 if (!*lparam
) return TRUE
;
1012 case WM_DEVMODECHANGE
:
1017 if (!check_string( *buffer
, size
)) return FALSE
;
1019 case WM_GETMINMAXINFO
:
1020 minsize
= sizeof(MINMAXINFO
);
1025 if (size
< sizeof(ps
->dis
)) return FALSE
;
1026 dis
.CtlType
= ps
->dis
.CtlType
;
1027 dis
.CtlID
= ps
->dis
.CtlID
;
1028 dis
.itemID
= ps
->dis
.itemID
;
1029 dis
.itemAction
= ps
->dis
.itemAction
;
1030 dis
.itemState
= ps
->dis
.itemState
;
1031 dis
.hwndItem
= wine_server_ptr_handle( ps
->dis
.hwndItem
);
1032 dis
.hDC
= wine_server_ptr_handle( ps
->dis
.hDC
);
1033 dis
.rcItem
= ps
->dis
.rcItem
;
1034 dis
.itemData
= (ULONG_PTR
)unpack_ptr( ps
->dis
.itemData
);
1035 memcpy( &ps
->dis
, &dis
, sizeof(dis
) );
1038 case WM_MEASUREITEM
:
1040 MEASUREITEMSTRUCT mis
;
1041 if (size
< sizeof(ps
->mis
)) return FALSE
;
1042 mis
.CtlType
= ps
->mis
.CtlType
;
1043 mis
.CtlID
= ps
->mis
.CtlID
;
1044 mis
.itemID
= ps
->mis
.itemID
;
1045 mis
.itemWidth
= ps
->mis
.itemWidth
;
1046 mis
.itemHeight
= ps
->mis
.itemHeight
;
1047 mis
.itemData
= (ULONG_PTR
)unpack_ptr( ps
->mis
.itemData
);
1048 memcpy( &ps
->mis
, &mis
, sizeof(mis
) );
1053 DELETEITEMSTRUCT dls
;
1054 if (size
< sizeof(ps
->dls
)) return FALSE
;
1055 dls
.CtlType
= ps
->dls
.CtlType
;
1056 dls
.CtlID
= ps
->dls
.CtlID
;
1057 dls
.itemID
= ps
->dls
.itemID
;
1058 dls
.hwndItem
= wine_server_ptr_handle( ps
->dls
.hwndItem
);
1059 dls
.itemData
= (ULONG_PTR
)unpack_ptr( ps
->dls
.itemData
);
1060 memcpy( &ps
->dls
, &dls
, sizeof(dls
) );
1063 case WM_COMPAREITEM
:
1065 COMPAREITEMSTRUCT cis
;
1066 if (size
< sizeof(ps
->cis
)) return FALSE
;
1067 cis
.CtlType
= ps
->cis
.CtlType
;
1068 cis
.CtlID
= ps
->cis
.CtlID
;
1069 cis
.hwndItem
= wine_server_ptr_handle( ps
->cis
.hwndItem
);
1070 cis
.itemID1
= ps
->cis
.itemID1
;
1071 cis
.itemData1
= (ULONG_PTR
)unpack_ptr( ps
->cis
.itemData1
);
1072 cis
.itemID2
= ps
->cis
.itemID2
;
1073 cis
.itemData2
= (ULONG_PTR
)unpack_ptr( ps
->cis
.itemData2
);
1074 cis
.dwLocaleId
= ps
->cis
.dwLocaleId
;
1075 memcpy( &ps
->cis
, &cis
, sizeof(cis
) );
1078 case WM_WINDOWPOSCHANGING
:
1079 case WM_WINDOWPOSCHANGED
:
1080 case WM_WINE_SETWINDOWPOS
:
1083 if (size
< sizeof(ps
->wp
)) return FALSE
;
1084 wp
.hwnd
= wine_server_ptr_handle( ps
->wp
.hwnd
);
1085 wp
.hwndInsertAfter
= wine_server_ptr_handle( ps
->wp
.hwndInsertAfter
);
1090 wp
.flags
= ps
->wp
.flags
;
1091 memcpy( &ps
->wp
, &wp
, sizeof(wp
) );
1097 if (size
< sizeof(ps
->cds
)) return FALSE
;
1098 cds
.dwData
= (ULONG_PTR
)unpack_ptr( ps
->cds
.dwData
);
1101 cds
.cbData
= ps
->cds
.cbData
;
1102 cds
.lpData
= &ps
->cds
+ 1;
1103 minsize
= sizeof(ps
->cds
) + cds
.cbData
;
1110 memcpy( &ps
->cds
, &cds
, sizeof(cds
) );
1114 /* WM_NOTIFY cannot be sent across processes (MSDN) */
1117 minsize
= sizeof(HELPINFO
);
1119 case WM_STYLECHANGING
:
1120 case WM_STYLECHANGED
:
1121 minsize
= sizeof(STYLESTRUCT
);
1124 if (!*wparam
) minsize
= sizeof(RECT
);
1127 NCCALCSIZE_PARAMS
*nc
= *buffer
;
1128 if (size
< sizeof(*nc
) + sizeof(*nc
->lppos
)) return FALSE
;
1129 nc
->lppos
= (WINDOWPOS
*)(nc
+ 1);
1133 if (!*lparam
) return TRUE
;
1134 minsize
= sizeof(MSG
);
1136 case SBM_SETSCROLLINFO
:
1137 minsize
= sizeof(SCROLLINFO
);
1139 case SBM_GETSCROLLINFO
:
1140 if (!get_buffer_space( buffer
, sizeof(SCROLLINFO
))) return FALSE
;
1142 case SBM_GETSCROLLBARINFO
:
1143 if (!get_buffer_space( buffer
, sizeof(SCROLLBARINFO
))) return FALSE
;
1148 if (*wparam
|| *lparam
)
1150 if (!get_buffer_space( buffer
, 2*sizeof(DWORD
) )) return FALSE
;
1151 if (*wparam
) *wparam
= (WPARAM
)*buffer
;
1152 if (*lparam
) *lparam
= (LPARAM
)((DWORD
*)*buffer
+ 1);
1156 case LB_GETITEMRECT
:
1157 case CB_GETDROPPEDCONTROLRECT
:
1158 if (!get_buffer_space( buffer
, sizeof(RECT
) )) return FALSE
;
1162 minsize
= sizeof(RECT
);
1167 if (size
< sizeof(WORD
)) return FALSE
;
1168 len
= *(WORD
*)*buffer
;
1169 if (!get_buffer_space( buffer
, (len
+ 1) * sizeof(WCHAR
) )) return FALSE
;
1170 *lparam
= (LPARAM
)*buffer
+ sizeof(WORD
); /* don't erase WORD at start of buffer */
1173 case EM_SETTABSTOPS
:
1174 case LB_SETTABSTOPS
:
1175 if (!*wparam
) return TRUE
;
1176 minsize
= *wparam
* sizeof(UINT
);
1179 case CB_INSERTSTRING
:
1181 case CB_FINDSTRINGEXACT
:
1182 case CB_SELECTSTRING
:
1184 case LB_INSERTSTRING
:
1186 case LB_FINDSTRINGEXACT
:
1187 case LB_SELECTSTRING
:
1188 if (!*buffer
) return TRUE
;
1189 if (!check_string( *buffer
, size
)) return FALSE
;
1193 size
= sizeof(ULONG_PTR
);
1194 if (combobox_has_strings( hwnd
))
1195 size
= (SendMessageW( hwnd
, CB_GETLBTEXTLEN
, *wparam
, 0 ) + 1) * sizeof(WCHAR
);
1196 if (!get_buffer_space( buffer
, size
)) return FALSE
;
1201 size
= sizeof(ULONG_PTR
);
1202 if (listbox_has_strings( hwnd
))
1203 size
= (SendMessageW( hwnd
, LB_GETTEXTLEN
, *wparam
, 0 ) + 1) * sizeof(WCHAR
);
1204 if (!get_buffer_space( buffer
, size
)) return FALSE
;
1207 case LB_GETSELITEMS
:
1208 if (!get_buffer_space( buffer
, *wparam
* sizeof(UINT
) )) return FALSE
;
1211 minsize
= sizeof(MDINEXTMENU
);
1212 if (!get_buffer_space( buffer
, sizeof(MDINEXTMENU
) )) return FALSE
;
1216 minsize
= sizeof(RECT
);
1217 if (!get_buffer_space( buffer
, sizeof(RECT
) )) return FALSE
;
1221 MDICREATESTRUCTW
*cs
= *buffer
;
1222 WCHAR
*str
= (WCHAR
*)(cs
+ 1);
1223 if (size
< sizeof(*cs
)) return FALSE
;
1224 size
-= sizeof(*cs
);
1225 if (!IS_INTRESOURCE(cs
->szTitle
))
1227 if (!check_string( str
, size
)) return FALSE
;
1229 size
-= (strlenW(str
) + 1) * sizeof(WCHAR
);
1230 str
+= strlenW(str
) + 1;
1232 if (!IS_INTRESOURCE(cs
->szClass
))
1234 if (!check_string( str
, size
)) return FALSE
;
1239 case WM_MDIGETACTIVE
:
1240 if (!*lparam
) return TRUE
;
1241 if (!get_buffer_space( buffer
, sizeof(BOOL
) )) return FALSE
;
1243 case WM_DEVICECHANGE
:
1244 minsize
= sizeof(DEV_BROADCAST_HDR
);
1246 case WM_WINE_KEYBOARD_LL_HOOK
:
1247 case WM_WINE_MOUSE_LL_HOOK
:
1249 struct hook_extra_info
*h_extra
= *buffer
;
1251 minsize
= sizeof(struct hook_extra_info
) +
1252 (message
== WM_WINE_KEYBOARD_LL_HOOK
? sizeof(KBDLLHOOKSTRUCT
)
1253 : sizeof(MSLLHOOKSTRUCT
));
1254 if (size
< minsize
) return FALSE
;
1255 h_extra
->lparam
= (LPARAM
)(h_extra
+ 1);
1259 if (*wparam
<= 1) return TRUE
;
1260 FIXME( "WM_NCPAINT hdc unpacking not supported\n" );
1263 if (!*wparam
) return TRUE
;
1266 /* these contain an HFONT */
1269 /* these contain an HDC */
1271 case WM_ICONERASEBKGND
:
1272 case WM_CTLCOLORMSGBOX
:
1273 case WM_CTLCOLOREDIT
:
1274 case WM_CTLCOLORLISTBOX
:
1275 case WM_CTLCOLORBTN
:
1276 case WM_CTLCOLORDLG
:
1277 case WM_CTLCOLORSCROLLBAR
:
1278 case WM_CTLCOLORSTATIC
:
1280 case WM_PRINTCLIENT
:
1281 /* these contain an HGLOBAL */
1282 case WM_PAINTCLIPBOARD
:
1283 case WM_SIZECLIPBOARD
:
1284 /* these contain HICON */
1287 case WM_QUERYDRAGICON
:
1288 case WM_QUERYPARKICON
:
1289 /* these contain pointers */
1291 case WM_QUERYDROPOBJECT
:
1295 FIXME( "msg %x (%s) not supported yet\n", message
, SPY_GetMsgName(message
, hwnd
) );
1299 return TRUE
; /* message doesn't need any unpacking */
1302 /* default exit for most messages: check minsize and store buffer in lparam */
1303 if (size
< minsize
) return FALSE
;
1304 *lparam
= (LPARAM
)*buffer
;
1309 /***********************************************************************
1312 * Pack a reply to a message for sending to another process.
1314 static void pack_reply( HWND hwnd
, UINT message
, WPARAM wparam
, LPARAM lparam
,
1315 LRESULT res
, struct packed_message
*data
)
1323 CREATESTRUCTW
*cs
= (CREATESTRUCTW
*)lparam
;
1324 data
->ps
.cs
.lpCreateParams
= (ULONG_PTR
)cs
->lpCreateParams
;
1325 data
->ps
.cs
.hInstance
= (ULONG_PTR
)cs
->hInstance
;
1326 data
->ps
.cs
.hMenu
= wine_server_user_handle( cs
->hMenu
);
1327 data
->ps
.cs
.hwndParent
= wine_server_user_handle( cs
->hwndParent
);
1328 data
->ps
.cs
.cy
= cs
->cy
;
1329 data
->ps
.cs
.cx
= cs
->cx
;
1330 data
->ps
.cs
.y
= cs
->y
;
1331 data
->ps
.cs
.x
= cs
->x
;
1332 data
->ps
.cs
.style
= cs
->style
;
1333 data
->ps
.cs
.dwExStyle
= cs
->dwExStyle
;
1334 data
->ps
.cs
.lpszName
= (ULONG_PTR
)cs
->lpszName
;
1335 data
->ps
.cs
.lpszClass
= (ULONG_PTR
)cs
->lpszClass
;
1336 push_data( data
, &data
->ps
.cs
, sizeof(data
->ps
.cs
) );
1342 push_data( data
, (WCHAR
*)lparam
, (res
+ 1) * sizeof(WCHAR
) );
1344 case WM_GETMINMAXINFO
:
1345 push_data( data
, (MINMAXINFO
*)lparam
, sizeof(MINMAXINFO
) );
1347 case WM_MEASUREITEM
:
1349 MEASUREITEMSTRUCT
*mis
= (MEASUREITEMSTRUCT
*)lparam
;
1350 data
->ps
.mis
.CtlType
= mis
->CtlType
;
1351 data
->ps
.mis
.CtlID
= mis
->CtlID
;
1352 data
->ps
.mis
.itemID
= mis
->itemID
;
1353 data
->ps
.mis
.itemWidth
= mis
->itemWidth
;
1354 data
->ps
.mis
.itemHeight
= mis
->itemHeight
;
1355 data
->ps
.mis
.itemData
= mis
->itemData
;
1356 push_data( data
, &data
->ps
.mis
, sizeof(data
->ps
.mis
) );
1359 case WM_WINDOWPOSCHANGING
:
1360 case WM_WINDOWPOSCHANGED
:
1362 WINDOWPOS
*wp
= (WINDOWPOS
*)lparam
;
1363 data
->ps
.wp
.hwnd
= wine_server_user_handle( wp
->hwnd
);
1364 data
->ps
.wp
.hwndInsertAfter
= wine_server_user_handle( wp
->hwndInsertAfter
);
1365 data
->ps
.wp
.x
= wp
->x
;
1366 data
->ps
.wp
.y
= wp
->y
;
1367 data
->ps
.wp
.cx
= wp
->cx
;
1368 data
->ps
.wp
.cy
= wp
->cy
;
1369 data
->ps
.wp
.flags
= wp
->flags
;
1370 push_data( data
, &data
->ps
.wp
, sizeof(data
->ps
.wp
) );
1374 if (lparam
) push_data( data
, (MSG
*)lparam
, sizeof(MSG
) );
1376 case SBM_GETSCROLLINFO
:
1377 push_data( data
, (SCROLLINFO
*)lparam
, sizeof(SCROLLINFO
) );
1380 case LB_GETITEMRECT
:
1381 case CB_GETDROPPEDCONTROLRECT
:
1384 push_data( data
, (RECT
*)lparam
, sizeof(RECT
) );
1388 WORD
*ptr
= (WORD
*)lparam
;
1389 push_data( data
, ptr
, ptr
[-1] * sizeof(WCHAR
) );
1392 case LB_GETSELITEMS
:
1393 push_data( data
, (UINT
*)lparam
, wparam
* sizeof(UINT
) );
1395 case WM_MDIGETACTIVE
:
1396 if (lparam
) push_data( data
, (BOOL
*)lparam
, sizeof(BOOL
) );
1400 push_data( data
, (RECT
*)lparam
, sizeof(RECT
) );
1403 NCCALCSIZE_PARAMS
*nc
= (NCCALCSIZE_PARAMS
*)lparam
;
1404 push_data( data
, nc
, sizeof(*nc
) );
1405 push_data( data
, nc
->lppos
, sizeof(*nc
->lppos
) );
1411 if (wparam
) push_data( data
, (DWORD
*)wparam
, sizeof(DWORD
) );
1412 if (lparam
) push_data( data
, (DWORD
*)lparam
, sizeof(DWORD
) );
1415 push_data( data
, (MDINEXTMENU
*)lparam
, sizeof(MDINEXTMENU
) );
1418 push_data( data
, (MDICREATESTRUCTW
*)lparam
, sizeof(MDICREATESTRUCTW
) );
1420 case WM_ASKCBFORMATNAME
:
1421 push_data( data
, (WCHAR
*)lparam
, (strlenW((WCHAR
*)lparam
) + 1) * sizeof(WCHAR
) );
1427 /***********************************************************************
1430 * Unpack a message reply received from another process.
1432 static void unpack_reply( HWND hwnd
, UINT message
, WPARAM wparam
, LPARAM lparam
,
1433 void *buffer
, size_t size
)
1435 union packed_structs
*ps
= buffer
;
1441 if (size
>= sizeof(ps
->cs
))
1443 CREATESTRUCTW
*cs
= (CREATESTRUCTW
*)lparam
;
1444 cs
->lpCreateParams
= unpack_ptr( ps
->cs
.lpCreateParams
);
1445 cs
->hInstance
= unpack_ptr( ps
->cs
.hInstance
);
1446 cs
->hMenu
= wine_server_ptr_handle( ps
->cs
.hMenu
);
1447 cs
->hwndParent
= wine_server_ptr_handle( ps
->cs
.hwndParent
);
1452 cs
->style
= ps
->cs
.style
;
1453 cs
->dwExStyle
= ps
->cs
.dwExStyle
;
1454 /* don't allow changing name and class pointers */
1458 case WM_ASKCBFORMATNAME
:
1459 memcpy( (WCHAR
*)lparam
, buffer
, min( wparam
*sizeof(WCHAR
), size
));
1461 case WM_GETMINMAXINFO
:
1462 memcpy( (MINMAXINFO
*)lparam
, buffer
, min( sizeof(MINMAXINFO
), size
));
1464 case WM_MEASUREITEM
:
1465 if (size
>= sizeof(ps
->mis
))
1467 MEASUREITEMSTRUCT
*mis
= (MEASUREITEMSTRUCT
*)lparam
;
1468 mis
->CtlType
= ps
->mis
.CtlType
;
1469 mis
->CtlID
= ps
->mis
.CtlID
;
1470 mis
->itemID
= ps
->mis
.itemID
;
1471 mis
->itemWidth
= ps
->mis
.itemWidth
;
1472 mis
->itemHeight
= ps
->mis
.itemHeight
;
1473 mis
->itemData
= (ULONG_PTR
)unpack_ptr( ps
->mis
.itemData
);
1476 case WM_WINDOWPOSCHANGING
:
1477 case WM_WINDOWPOSCHANGED
:
1478 if (size
>= sizeof(ps
->wp
))
1480 WINDOWPOS
*wp
= (WINDOWPOS
*)lparam
;
1481 wp
->hwnd
= wine_server_ptr_handle( ps
->wp
.hwnd
);
1482 wp
->hwndInsertAfter
= wine_server_ptr_handle( ps
->wp
.hwndInsertAfter
);
1487 wp
->flags
= ps
->wp
.flags
;
1491 if (lparam
) memcpy( (MSG
*)lparam
, buffer
, min( sizeof(MSG
), size
));
1493 case SBM_GETSCROLLINFO
:
1494 memcpy( (SCROLLINFO
*)lparam
, buffer
, min( sizeof(SCROLLINFO
), size
));
1496 case SBM_GETSCROLLBARINFO
:
1497 memcpy( (SCROLLBARINFO
*)lparam
, buffer
, min( sizeof(SCROLLBARINFO
), size
));
1500 case CB_GETDROPPEDCONTROLRECT
:
1501 case LB_GETITEMRECT
:
1504 memcpy( (RECT
*)lparam
, buffer
, min( sizeof(RECT
), size
));
1507 size
= min( size
, (size_t)*(WORD
*)lparam
);
1508 memcpy( (WCHAR
*)lparam
, buffer
, size
);
1510 case LB_GETSELITEMS
:
1511 memcpy( (UINT
*)lparam
, buffer
, min( wparam
*sizeof(UINT
), size
));
1515 memcpy( (WCHAR
*)lparam
, buffer
, size
);
1518 memcpy( (MDINEXTMENU
*)lparam
, buffer
, min( sizeof(MDINEXTMENU
), size
));
1520 case WM_MDIGETACTIVE
:
1521 if (lparam
) memcpy( (BOOL
*)lparam
, buffer
, min( sizeof(BOOL
), size
));
1525 memcpy( (RECT
*)lparam
, buffer
, min( sizeof(RECT
), size
));
1528 NCCALCSIZE_PARAMS
*nc
= (NCCALCSIZE_PARAMS
*)lparam
;
1529 WINDOWPOS
*wp
= nc
->lppos
;
1530 memcpy( nc
, buffer
, min( sizeof(*nc
), size
));
1531 if (size
> sizeof(*nc
))
1533 size
-= sizeof(*nc
);
1534 memcpy( wp
, (NCCALCSIZE_PARAMS
*)buffer
+ 1, min( sizeof(*wp
), size
));
1536 nc
->lppos
= wp
; /* restore the original pointer */
1544 memcpy( (DWORD
*)wparam
, buffer
, min( sizeof(DWORD
), size
));
1545 if (size
<= sizeof(DWORD
)) break;
1546 size
-= sizeof(DWORD
);
1547 buffer
= (DWORD
*)buffer
+ 1;
1549 if (lparam
) memcpy( (DWORD
*)lparam
, buffer
, min( sizeof(DWORD
), size
));
1553 MDICREATESTRUCTW
*cs
= (MDICREATESTRUCTW
*)lparam
;
1554 LPCWSTR title
= cs
->szTitle
, class = cs
->szClass
;
1555 memcpy( cs
, buffer
, min( sizeof(*cs
), size
));
1556 cs
->szTitle
= title
; /* restore the original pointers */
1557 cs
->szClass
= class;
1561 ERR( "should not happen: unexpected message %x\n", message
);
1567 /***********************************************************************
1570 * Send a reply to a sent message.
1572 static void reply_message( struct received_message_info
*info
, LRESULT result
, BOOL remove
)
1574 struct packed_message data
;
1575 int i
, replied
= info
->flags
& ISMEX_REPLIED
;
1577 if (info
->flags
& ISMEX_NOTIFY
) return; /* notify messages don't get replies */
1578 if (!remove
&& replied
) return; /* replied already */
1580 memset( &data
, 0, sizeof(data
) );
1581 info
->flags
|= ISMEX_REPLIED
;
1583 if (info
->type
== MSG_OTHER_PROCESS
&& !replied
)
1585 pack_reply( info
->msg
.hwnd
, info
->msg
.message
, info
->msg
.wParam
,
1586 info
->msg
.lParam
, result
, &data
);
1589 SERVER_START_REQ( reply_message
)
1591 req
->result
= result
;
1592 req
->remove
= remove
;
1593 for (i
= 0; i
< data
.count
; i
++) wine_server_add_data( req
, data
.data
[i
], data
.size
[i
] );
1594 wine_server_call( req
);
1600 /***********************************************************************
1601 * handle_internal_message
1603 * Handle an internal Wine message instead of calling the window proc.
1605 static LRESULT
handle_internal_message( HWND hwnd
, UINT msg
, WPARAM wparam
, LPARAM lparam
)
1609 case WM_WINE_DESTROYWINDOW
:
1610 return WIN_DestroyWindow( hwnd
);
1611 case WM_WINE_SETWINDOWPOS
:
1612 if (is_desktop_window( hwnd
)) return 0;
1613 return USER_SetWindowPos( (WINDOWPOS
*)lparam
);
1614 case WM_WINE_SHOWWINDOW
:
1615 if (is_desktop_window( hwnd
)) return 0;
1616 return ShowWindow( hwnd
, wparam
);
1617 case WM_WINE_SETPARENT
:
1618 if (is_desktop_window( hwnd
)) return 0;
1619 return (LRESULT
)SetParent( hwnd
, (HWND
)wparam
);
1620 case WM_WINE_SETWINDOWLONG
:
1621 return WIN_SetWindowLong( hwnd
, (short)LOWORD(wparam
), HIWORD(wparam
), lparam
, TRUE
);
1622 case WM_WINE_ENABLEWINDOW
:
1623 if (is_desktop_window( hwnd
)) return 0;
1624 return EnableWindow( hwnd
, wparam
);
1625 case WM_WINE_SETACTIVEWINDOW
:
1626 if (is_desktop_window( hwnd
)) return 0;
1627 return (LRESULT
)SetActiveWindow( (HWND
)wparam
);
1628 case WM_WINE_KEYBOARD_LL_HOOK
:
1629 case WM_WINE_MOUSE_LL_HOOK
:
1631 struct hook_extra_info
*h_extra
= (struct hook_extra_info
*)lparam
;
1633 return call_current_hook( h_extra
->handle
, HC_ACTION
, wparam
, h_extra
->lparam
);
1636 if (msg
>= WM_WINE_FIRST_DRIVER_MSG
&& msg
<= WM_WINE_LAST_DRIVER_MSG
)
1637 return USER_Driver
->pWindowMessage( hwnd
, msg
, wparam
, lparam
);
1638 FIXME( "unknown internal message %x\n", msg
);
1643 /* since the WM_DDE_ACK response to a WM_DDE_EXECUTE message should contain the handle
1644 * to the memory handle, we keep track (in the server side) of all pairs of handle
1645 * used (the client passes its value and the content of the memory handle), and
1646 * the server stored both values (the client, and the local one, created after the
1647 * content). When a ACK message is generated, the list of pair is searched for a
1648 * matching pair, so that the client memory handle can be returned.
1651 HGLOBAL client_hMem
;
1652 HGLOBAL server_hMem
;
1655 static struct DDE_pair
* dde_pairs
;
1656 static int dde_num_alloc
;
1657 static int dde_num_used
;
1659 static CRITICAL_SECTION dde_crst
;
1660 static CRITICAL_SECTION_DEBUG critsect_debug
=
1663 { &critsect_debug
.ProcessLocksList
, &critsect_debug
.ProcessLocksList
},
1664 0, 0, { (DWORD_PTR
)(__FILE__
": dde_crst") }
1666 static CRITICAL_SECTION dde_crst
= { &critsect_debug
, -1, 0, 0, 0, 0 };
1668 static BOOL
dde_add_pair(HGLOBAL chm
, HGLOBAL shm
)
1673 EnterCriticalSection(&dde_crst
);
1675 /* now remember the pair of hMem on both sides */
1676 if (dde_num_used
== dde_num_alloc
)
1678 struct DDE_pair
* tmp
;
1680 tmp
= HeapReAlloc( GetProcessHeap(), 0, dde_pairs
,
1681 (dde_num_alloc
+ GROWBY
) * sizeof(struct DDE_pair
));
1683 tmp
= HeapAlloc( GetProcessHeap(), 0,
1684 (dde_num_alloc
+ GROWBY
) * sizeof(struct DDE_pair
));
1688 LeaveCriticalSection(&dde_crst
);
1692 /* zero out newly allocated part */
1693 memset(&dde_pairs
[dde_num_alloc
], 0, GROWBY
* sizeof(struct DDE_pair
));
1694 dde_num_alloc
+= GROWBY
;
1697 for (i
= 0; i
< dde_num_alloc
; i
++)
1699 if (dde_pairs
[i
].server_hMem
== 0)
1701 dde_pairs
[i
].client_hMem
= chm
;
1702 dde_pairs
[i
].server_hMem
= shm
;
1707 LeaveCriticalSection(&dde_crst
);
1711 static HGLOBAL
dde_get_pair(HGLOBAL shm
)
1716 EnterCriticalSection(&dde_crst
);
1717 for (i
= 0; i
< dde_num_alloc
; i
++)
1719 if (dde_pairs
[i
].server_hMem
== shm
)
1721 /* free this pair */
1722 dde_pairs
[i
].server_hMem
= 0;
1724 ret
= dde_pairs
[i
].client_hMem
;
1728 LeaveCriticalSection(&dde_crst
);
1732 /***********************************************************************
1735 * Post a DDE message
1737 static BOOL
post_dde_message( struct packed_message
*data
, const struct send_message_info
*info
)
1741 UINT_PTR uiLo
, uiHi
;
1743 HGLOBAL hunlock
= 0;
1747 if (!UnpackDDElParam( info
->msg
, info
->lparam
, &uiLo
, &uiHi
))
1753 /* DDE messages which don't require packing are:
1762 /* uiHi should contain a hMem from WM_DDE_EXECUTE */
1763 HGLOBAL h
= dde_get_pair( (HANDLE
)uiHi
);
1766 /* send back the value of h on the other side */
1767 push_data( data
, &h
, sizeof(HGLOBAL
) );
1769 TRACE( "send dde-ack %lx %08lx => %p\n", uiLo
, uiHi
, h
);
1774 /* uiHi should contain either an atom or 0 */
1775 TRACE( "send dde-ack %lx atom=%lx\n", uiLo
, uiHi
);
1776 lp
= MAKELONG( uiLo
, uiHi
);
1785 size
= GlobalSize( (HGLOBAL
)uiLo
) ;
1786 if ((info
->msg
== WM_DDE_ADVISE
&& size
< sizeof(DDEADVISE
)) ||
1787 (info
->msg
== WM_DDE_DATA
&& size
< FIELD_OFFSET(DDEDATA
, Value
)) ||
1788 (info
->msg
== WM_DDE_POKE
&& size
< FIELD_OFFSET(DDEPOKE
, Value
))
1792 else if (info
->msg
!= WM_DDE_DATA
) return FALSE
;
1797 if ((ptr
= GlobalLock( (HGLOBAL
)uiLo
) ))
1799 DDEDATA
*dde_data
= ptr
;
1800 TRACE("unused %d, fResponse %d, fRelease %d, fDeferUpd %d, fAckReq %d, cfFormat %d\n",
1801 dde_data
->unused
, dde_data
->fResponse
, dde_data
->fRelease
,
1802 dde_data
->reserved
, dde_data
->fAckReq
, dde_data
->cfFormat
);
1803 push_data( data
, ptr
, size
);
1804 hunlock
= (HGLOBAL
)uiLo
;
1807 TRACE( "send ddepack %u %lx\n", size
, uiHi
);
1809 case WM_DDE_EXECUTE
:
1812 if ((ptr
= GlobalLock( (HGLOBAL
)info
->lparam
) ))
1814 push_data(data
, ptr
, GlobalSize( (HGLOBAL
)info
->lparam
));
1815 /* so that the other side can send it back on ACK */
1817 hunlock
= (HGLOBAL
)info
->lparam
;
1822 SERVER_START_REQ( send_message
)
1824 req
->id
= info
->dest_tid
;
1825 req
->type
= info
->type
;
1827 req
->win
= wine_server_user_handle( info
->hwnd
);
1828 req
->msg
= info
->msg
;
1829 req
->wparam
= info
->wparam
;
1831 req
->timeout
= TIMEOUT_INFINITE
;
1832 for (i
= 0; i
< data
->count
; i
++)
1833 wine_server_add_data( req
, data
->data
[i
], data
->size
[i
] );
1834 if ((res
= wine_server_call( req
)))
1836 if (res
== STATUS_INVALID_PARAMETER
)
1837 /* FIXME: find a STATUS_ value for this one */
1838 SetLastError( ERROR_INVALID_THREAD_ID
);
1840 SetLastError( RtlNtStatusToDosError(res
) );
1843 FreeDDElParam(info
->msg
, info
->lparam
);
1846 if (hunlock
) GlobalUnlock(hunlock
);
1851 /***********************************************************************
1852 * unpack_dde_message
1854 * Unpack a posted DDE message received from another process.
1856 static BOOL
unpack_dde_message( HWND hwnd
, UINT message
, WPARAM
*wparam
, LPARAM
*lparam
,
1857 void **buffer
, size_t size
)
1859 UINT_PTR uiLo
, uiHi
;
1868 /* hMem is being passed */
1869 if (size
!= sizeof(HGLOBAL
)) return FALSE
;
1870 if (!buffer
|| !*buffer
) return FALSE
;
1872 memcpy( &hMem
, *buffer
, size
);
1873 uiHi
= (UINT_PTR
)hMem
;
1874 TRACE("recv dde-ack %lx mem=%lx[%lx]\n", uiLo
, uiHi
, GlobalSize( hMem
));
1878 uiLo
= LOWORD( *lparam
);
1879 uiHi
= HIWORD( *lparam
);
1880 TRACE("recv dde-ack %lx atom=%lx\n", uiLo
, uiHi
);
1882 *lparam
= PackDDElParam( WM_DDE_ACK
, uiLo
, uiHi
);
1887 if ((!buffer
|| !*buffer
) && message
!= WM_DDE_DATA
) return FALSE
;
1891 if (!(hMem
= GlobalAlloc( GMEM_MOVEABLE
|GMEM_DDESHARE
, size
)))
1893 if ((ptr
= GlobalLock( hMem
)))
1895 memcpy( ptr
, *buffer
, size
);
1896 GlobalUnlock( hMem
);
1904 uiLo
= (UINT_PTR
)hMem
;
1906 *lparam
= PackDDElParam( message
, uiLo
, uiHi
);
1908 case WM_DDE_EXECUTE
:
1911 if (!buffer
|| !*buffer
) return FALSE
;
1912 if (!(hMem
= GlobalAlloc( GMEM_MOVEABLE
|GMEM_DDESHARE
, size
))) return FALSE
;
1913 if ((ptr
= GlobalLock( hMem
)))
1915 memcpy( ptr
, *buffer
, size
);
1916 GlobalUnlock( hMem
);
1917 TRACE( "exec: pairing c=%08lx s=%p\n", *lparam
, hMem
);
1918 if (!dde_add_pair( (HGLOBAL
)*lparam
, hMem
))
1929 } else return FALSE
;
1930 *lparam
= (LPARAM
)hMem
;
1936 /***********************************************************************
1939 * Call a window procedure and the corresponding hooks.
1941 static LRESULT
call_window_proc( HWND hwnd
, UINT msg
, WPARAM wparam
, LPARAM lparam
,
1942 BOOL unicode
, BOOL same_thread
, enum wm_char_mapping mapping
)
1946 CWPRETSTRUCT cwpret
;
1948 if (msg
& 0x80000000)
1950 result
= handle_internal_message( hwnd
, msg
, wparam
, lparam
);
1954 /* first the WH_CALLWNDPROC hook */
1955 hwnd
= WIN_GetFullHandle( hwnd
);
1956 cwp
.lParam
= lparam
;
1957 cwp
.wParam
= wparam
;
1960 HOOK_CallHooks( WH_CALLWNDPROC
, HC_ACTION
, same_thread
, (LPARAM
)&cwp
, unicode
);
1962 /* now call the window procedure */
1963 if (!WINPROC_call_window( hwnd
, msg
, wparam
, lparam
, &result
, unicode
, mapping
)) goto done
;
1965 /* and finally the WH_CALLWNDPROCRET hook */
1966 cwpret
.lResult
= result
;
1967 cwpret
.lParam
= lparam
;
1968 cwpret
.wParam
= wparam
;
1969 cwpret
.message
= msg
;
1971 HOOK_CallHooks( WH_CALLWNDPROCRET
, HC_ACTION
, same_thread
, (LPARAM
)&cwpret
, unicode
);
1977 /***********************************************************************
1978 * send_parent_notify
1980 * Send a WM_PARENTNOTIFY to all ancestors of the given window, unless
1981 * the window has the WS_EX_NOPARENTNOTIFY style.
1983 static void send_parent_notify( HWND hwnd
, WORD event
, WORD idChild
, POINT pt
)
1985 /* pt has to be in the client coordinates of the parent window */
1986 MapWindowPoints( 0, hwnd
, &pt
, 1 );
1991 if (!(GetWindowLongW( hwnd
, GWL_STYLE
) & WS_CHILD
)) break;
1992 if (GetWindowLongW( hwnd
, GWL_EXSTYLE
) & WS_EX_NOPARENTNOTIFY
) break;
1993 if (!(parent
= GetParent(hwnd
))) break;
1994 if (parent
== GetDesktopWindow()) break;
1995 MapWindowPoints( hwnd
, parent
, &pt
, 1 );
1997 SendMessageW( hwnd
, WM_PARENTNOTIFY
,
1998 MAKEWPARAM( event
, idChild
), MAKELPARAM( pt
.x
, pt
.y
) );
2003 /***********************************************************************
2004 * accept_hardware_message
2006 * Tell the server we have passed the message to the app
2007 * (even though we may end up dropping it later on)
2009 static void accept_hardware_message( UINT hw_id
, BOOL remove
, HWND new_hwnd
)
2011 SERVER_START_REQ( accept_hardware_message
)
2014 req
->remove
= remove
;
2015 req
->new_win
= wine_server_user_handle( new_hwnd
);
2016 if (wine_server_call( req
))
2017 FIXME("Failed to reply to MSG_HARDWARE message. Message may not be removed from queue.\n");
2023 /***********************************************************************
2024 * process_keyboard_message
2026 * returns TRUE if the contents of 'msg' should be passed to the application
2028 static BOOL
process_keyboard_message( MSG
*msg
, UINT hw_id
, HWND hwnd_filter
,
2029 UINT first
, UINT last
, BOOL remove
)
2033 if (msg
->message
== WM_KEYDOWN
|| msg
->message
== WM_SYSKEYDOWN
||
2034 msg
->message
== WM_KEYUP
|| msg
->message
== WM_SYSKEYUP
)
2035 switch (msg
->wParam
)
2037 case VK_LSHIFT
: case VK_RSHIFT
:
2038 msg
->wParam
= VK_SHIFT
;
2040 case VK_LCONTROL
: case VK_RCONTROL
:
2041 msg
->wParam
= VK_CONTROL
;
2043 case VK_LMENU
: case VK_RMENU
:
2044 msg
->wParam
= VK_MENU
;
2048 /* FIXME: is this really the right place for this hook? */
2049 event
.message
= msg
->message
;
2050 event
.hwnd
= msg
->hwnd
;
2051 event
.time
= msg
->time
;
2052 event
.paramL
= (msg
->wParam
& 0xFF) | (HIWORD(msg
->lParam
) << 8);
2053 event
.paramH
= msg
->lParam
& 0x7FFF;
2054 if (HIWORD(msg
->lParam
) & 0x0100) event
.paramH
|= 0x8000; /* special_key - bit */
2055 HOOK_CallHooks( WH_JOURNALRECORD
, HC_ACTION
, 0, (LPARAM
)&event
, TRUE
);
2057 /* check message filters */
2058 if (msg
->message
< first
|| msg
->message
> last
) return FALSE
;
2059 if (!check_hwnd_filter( msg
, hwnd_filter
)) return FALSE
;
2063 if((msg
->message
== WM_KEYDOWN
) &&
2064 (msg
->hwnd
!= GetDesktopWindow()))
2066 /* Handle F1 key by sending out WM_HELP message */
2067 if (msg
->wParam
== VK_F1
)
2069 PostMessageW( msg
->hwnd
, WM_KEYF1
, 0, 0 );
2071 else if(msg
->wParam
>= VK_BROWSER_BACK
&&
2072 msg
->wParam
<= VK_LAUNCH_APP2
)
2074 /* FIXME: Process keystate */
2075 SendMessageW(msg
->hwnd
, WM_APPCOMMAND
, (WPARAM
)msg
->hwnd
, MAKELPARAM(0, (FAPPCOMMAND_KEY
| (msg
->wParam
- VK_BROWSER_BACK
+ 1))));
2078 else if (msg
->message
== WM_KEYUP
)
2080 /* Handle VK_APPS key by posting a WM_CONTEXTMENU message */
2081 if (msg
->wParam
== VK_APPS
&& !MENU_IsMenuActive())
2082 PostMessageW(msg
->hwnd
, WM_CONTEXTMENU
, (WPARAM
)msg
->hwnd
, -1);
2086 if (HOOK_CallHooks( WH_KEYBOARD
, remove
? HC_ACTION
: HC_NOREMOVE
,
2087 LOWORD(msg
->wParam
), msg
->lParam
, TRUE
))
2089 /* skip this message */
2090 HOOK_CallHooks( WH_CBT
, HCBT_KEYSKIPPED
, LOWORD(msg
->wParam
), msg
->lParam
, TRUE
);
2091 accept_hardware_message( hw_id
, TRUE
, 0 );
2094 accept_hardware_message( hw_id
, remove
, 0 );
2096 if ( msg
->message
== WM_KEYDOWN
|| msg
->message
== WM_KEYUP
)
2097 if ( ImmProcessKey(msg
->hwnd
, GetKeyboardLayout(0), msg
->wParam
, msg
->lParam
, 0) )
2098 msg
->wParam
= VK_PROCESSKEY
;
2104 /***********************************************************************
2105 * process_mouse_message
2107 * returns TRUE if the contents of 'msg' should be passed to the application
2109 static BOOL
process_mouse_message( MSG
*msg
, UINT hw_id
, ULONG_PTR extra_info
, HWND hwnd_filter
,
2110 UINT first
, UINT last
, BOOL remove
)
2119 MOUSEHOOKSTRUCT hook
;
2122 /* find the window to dispatch this mouse message to */
2124 GetGUIThreadInfo( GetCurrentThreadId(), &info
);
2125 if (info
.hwndCapture
)
2128 msg
->hwnd
= info
.hwndCapture
;
2132 msg
->hwnd
= WINPOS_WindowFromPoint( msg
->hwnd
, msg
->pt
, &hittest
);
2135 if (!msg
->hwnd
|| !WIN_IsCurrentThread( msg
->hwnd
))
2137 accept_hardware_message( hw_id
, TRUE
, msg
->hwnd
);
2141 /* FIXME: is this really the right place for this hook? */
2142 event
.message
= msg
->message
;
2143 event
.time
= msg
->time
;
2144 event
.hwnd
= msg
->hwnd
;
2145 event
.paramL
= msg
->pt
.x
;
2146 event
.paramH
= msg
->pt
.y
;
2147 HOOK_CallHooks( WH_JOURNALRECORD
, HC_ACTION
, 0, (LPARAM
)&event
, TRUE
);
2149 if (!check_hwnd_filter( msg
, hwnd_filter
)) return FALSE
;
2152 message
= msg
->message
;
2153 /* Note: windows has no concept of a non-client wheel message */
2154 if (message
!= WM_MOUSEWHEEL
)
2156 if (hittest
!= HTCLIENT
)
2158 message
+= WM_NCMOUSEMOVE
- WM_MOUSEMOVE
;
2159 msg
->wParam
= hittest
;
2163 /* coordinates don't get translated while tracking a menu */
2164 /* FIXME: should differentiate popups and top-level menus */
2165 if (!(info
.flags
& GUI_INMENUMODE
))
2166 ScreenToClient( msg
->hwnd
, &pt
);
2169 msg
->lParam
= MAKELONG( pt
.x
, pt
.y
);
2171 /* translate double clicks */
2173 if ((msg
->message
== WM_LBUTTONDOWN
) ||
2174 (msg
->message
== WM_RBUTTONDOWN
) ||
2175 (msg
->message
== WM_MBUTTONDOWN
) ||
2176 (msg
->message
== WM_XBUTTONDOWN
))
2178 BOOL update
= remove
;
2180 /* translate double clicks -
2181 * note that ...MOUSEMOVEs can slip in between
2182 * ...BUTTONDOWN and ...BUTTONDBLCLK messages */
2184 if ((info
.flags
& (GUI_INMENUMODE
|GUI_INMOVESIZE
)) ||
2185 hittest
!= HTCLIENT
||
2186 (GetClassLongA( msg
->hwnd
, GCL_STYLE
) & CS_DBLCLKS
))
2188 if ((msg
->message
== clk_msg
.message
) &&
2189 (msg
->hwnd
== clk_msg
.hwnd
) &&
2190 (msg
->wParam
== clk_msg
.wParam
) &&
2191 (msg
->time
- clk_msg
.time
< GetDoubleClickTime()) &&
2192 (abs(msg
->pt
.x
- clk_msg
.pt
.x
) < GetSystemMetrics(SM_CXDOUBLECLK
)/2) &&
2193 (abs(msg
->pt
.y
- clk_msg
.pt
.y
) < GetSystemMetrics(SM_CYDOUBLECLK
)/2))
2195 message
+= (WM_LBUTTONDBLCLK
- WM_LBUTTONDOWN
);
2198 clk_msg
.message
= 0; /* clear the double click conditions */
2203 if (message
< first
|| message
> last
) return FALSE
;
2204 /* update static double click conditions */
2205 if (update
) clk_msg
= *msg
;
2209 if (message
< first
|| message
> last
) return FALSE
;
2212 /* message is accepted now (but may still get dropped) */
2215 hook
.hwnd
= msg
->hwnd
;
2216 hook
.wHitTestCode
= hittest
;
2217 hook
.dwExtraInfo
= extra_info
;
2218 if (HOOK_CallHooks( WH_MOUSE
, remove
? HC_ACTION
: HC_NOREMOVE
,
2219 message
, (LPARAM
)&hook
, TRUE
))
2222 hook
.hwnd
= msg
->hwnd
;
2223 hook
.wHitTestCode
= hittest
;
2224 hook
.dwExtraInfo
= extra_info
;
2225 HOOK_CallHooks( WH_CBT
, HCBT_CLICKSKIPPED
, message
, (LPARAM
)&hook
, TRUE
);
2226 accept_hardware_message( hw_id
, TRUE
, 0 );
2230 if ((hittest
== HTERROR
) || (hittest
== HTNOWHERE
))
2232 SendMessageW( msg
->hwnd
, WM_SETCURSOR
, (WPARAM
)msg
->hwnd
,
2233 MAKELONG( hittest
, msg
->message
));
2234 accept_hardware_message( hw_id
, TRUE
, 0 );
2238 accept_hardware_message( hw_id
, remove
, 0 );
2240 if (!remove
|| info
.hwndCapture
)
2242 msg
->message
= message
;
2248 if ((msg
->message
== WM_LBUTTONDOWN
) ||
2249 (msg
->message
== WM_RBUTTONDOWN
) ||
2250 (msg
->message
== WM_MBUTTONDOWN
) ||
2251 (msg
->message
== WM_XBUTTONDOWN
))
2253 /* Send the WM_PARENTNOTIFY,
2254 * note that even for double/nonclient clicks
2255 * notification message is still WM_L/M/RBUTTONDOWN.
2257 send_parent_notify( msg
->hwnd
, msg
->message
, 0, msg
->pt
);
2259 /* Activate the window if needed */
2261 if (msg
->hwnd
!= info
.hwndActive
)
2263 HWND hwndTop
= msg
->hwnd
;
2266 if ((GetWindowLongW( hwndTop
, GWL_STYLE
) & (WS_POPUP
|WS_CHILD
)) != WS_CHILD
) break;
2267 hwndTop
= GetParent( hwndTop
);
2270 if (hwndTop
&& hwndTop
!= GetDesktopWindow())
2272 LONG ret
= SendMessageW( msg
->hwnd
, WM_MOUSEACTIVATE
, (WPARAM
)hwndTop
,
2273 MAKELONG( hittest
, msg
->message
) );
2276 case MA_NOACTIVATEANDEAT
:
2281 case MA_ACTIVATEANDEAT
:
2286 if (!FOCUS_MouseActivate( hwndTop
)) eatMsg
= TRUE
;
2289 WARN( "unknown WM_MOUSEACTIVATE code %d\n", ret
);
2296 /* send the WM_SETCURSOR message */
2298 /* Windows sends the normal mouse message as the message parameter
2299 in the WM_SETCURSOR message even if it's non-client mouse message */
2300 SendMessageW( msg
->hwnd
, WM_SETCURSOR
, (WPARAM
)msg
->hwnd
, MAKELONG( hittest
, msg
->message
));
2302 msg
->message
= message
;
2307 /***********************************************************************
2308 * process_hardware_message
2310 * Process a hardware message; return TRUE if message should be passed on to the app
2312 static BOOL
process_hardware_message( MSG
*msg
, UINT hw_id
, ULONG_PTR extra_info
, HWND hwnd_filter
,
2313 UINT first
, UINT last
, BOOL remove
)
2315 if (is_keyboard_message( msg
->message
))
2316 return process_keyboard_message( msg
, hw_id
, hwnd_filter
, first
, last
, remove
);
2318 if (is_mouse_message( msg
->message
))
2319 return process_mouse_message( msg
, hw_id
, extra_info
, hwnd_filter
, first
, last
, remove
);
2321 ERR( "unknown message type %x\n", msg
->message
);
2326 /***********************************************************************
2327 * call_sendmsg_callback
2329 * Call the callback function of SendMessageCallback.
2331 static inline void call_sendmsg_callback( SENDASYNCPROC callback
, HWND hwnd
, UINT msg
,
2332 ULONG_PTR data
, LRESULT result
)
2334 if (!callback
) return;
2336 if (TRACE_ON(relay
))
2337 DPRINTF( "%04x:Call message callback %p (hwnd=%p,msg=%s,data=%08lx,result=%08lx)\n",
2338 GetCurrentThreadId(), callback
, hwnd
, SPY_GetMsgName( msg
, hwnd
),
2340 callback( hwnd
, msg
, data
, result
);
2341 if (TRACE_ON(relay
))
2342 DPRINTF( "%04x:Ret message callback %p (hwnd=%p,msg=%s,data=%08lx,result=%08lx)\n",
2343 GetCurrentThreadId(), callback
, hwnd
, SPY_GetMsgName( msg
, hwnd
),
2348 /***********************************************************************
2351 * Peek for a message matching the given parameters. Return FALSE if none available.
2352 * All pending sent messages are processed before returning.
2354 static BOOL
peek_message( MSG
*msg
, HWND hwnd
, UINT first
, UINT last
, UINT flags
, UINT changed_mask
)
2357 struct user_thread_info
*thread_info
= get_user_thread_info();
2358 struct received_message_info info
, *old_info
;
2359 unsigned int hw_id
= 0; /* id of previous hardware message */
2361 size_t buffer_size
= 256;
2363 if (!(buffer
= HeapAlloc( GetProcessHeap(), 0, buffer_size
))) return FALSE
;
2365 if (!first
&& !last
) last
= ~0;
2366 if (hwnd
== HWND_BROADCAST
) hwnd
= HWND_TOPMOST
;
2372 const message_data_t
*msg_data
= buffer
;
2374 SERVER_START_REQ( get_message
)
2377 req
->get_win
= wine_server_user_handle( hwnd
);
2378 req
->get_first
= first
;
2379 req
->get_last
= last
;
2381 req
->wake_mask
= changed_mask
& (QS_SENDMESSAGE
| QS_SMRESULT
);
2382 req
->changed_mask
= changed_mask
;
2383 wine_server_set_reply( req
, buffer
, buffer_size
);
2384 if (!(res
= wine_server_call( req
)))
2386 size
= wine_server_reply_size( reply
);
2387 info
.type
= reply
->type
;
2388 info
.msg
.hwnd
= wine_server_ptr_handle( reply
->win
);
2389 info
.msg
.message
= reply
->msg
;
2390 info
.msg
.wParam
= reply
->wparam
;
2391 info
.msg
.lParam
= reply
->lparam
;
2392 info
.msg
.time
= reply
->time
;
2396 thread_info
->active_hooks
= reply
->active_hooks
;
2398 else buffer_size
= reply
->total
;
2404 HeapFree( GetProcessHeap(), 0, buffer
);
2405 if (res
!= STATUS_BUFFER_OVERFLOW
) return FALSE
;
2406 if (!(buffer
= HeapAlloc( GetProcessHeap(), 0, buffer_size
))) return FALSE
;
2410 TRACE( "got type %d msg %x (%s) hwnd %p wp %lx lp %lx\n",
2411 info
.type
, info
.msg
.message
,
2412 (info
.type
== MSG_WINEVENT
) ? "MSG_WINEVENT" : SPY_GetMsgName(info
.msg
.message
, info
.msg
.hwnd
),
2413 info
.msg
.hwnd
, info
.msg
.wParam
, info
.msg
.lParam
);
2419 info
.flags
= ISMEX_SEND
;
2422 info
.flags
= ISMEX_NOTIFY
;
2425 info
.flags
= ISMEX_CALLBACK
;
2427 case MSG_CALLBACK_RESULT
:
2428 if (size
>= sizeof(msg_data
->callback
))
2429 call_sendmsg_callback( wine_server_get_ptr(msg_data
->callback
.callback
),
2430 info
.msg
.hwnd
, info
.msg
.message
,
2431 msg_data
->callback
.data
, msg_data
->callback
.result
);
2434 if (size
>= sizeof(msg_data
->winevent
))
2436 WINEVENTPROC hook_proc
;
2438 hook_proc
= wine_server_get_ptr( msg_data
->winevent
.hook_proc
);
2439 size
-= sizeof(msg_data
->winevent
);
2442 WCHAR module
[MAX_PATH
];
2444 size
= min( size
, (MAX_PATH
- 1) * sizeof(WCHAR
) );
2445 memcpy( module
, &msg_data
->winevent
+ 1, size
);
2446 module
[size
/ sizeof(WCHAR
)] = 0;
2447 if (!(hook_proc
= get_hook_proc( hook_proc
, module
)))
2449 ERR( "invalid winevent hook module name %s\n", debugstr_w(module
) );
2454 if (TRACE_ON(relay
))
2455 DPRINTF( "%04x:Call winevent proc %p (hook=%04x,event=%x,hwnd=%p,object_id=%lx,child_id=%lx,tid=%04x,time=%x)\n",
2456 GetCurrentThreadId(), hook_proc
,
2457 msg_data
->winevent
.hook
, info
.msg
.message
, info
.msg
.hwnd
, info
.msg
.wParam
,
2458 info
.msg
.lParam
, msg_data
->winevent
.tid
, info
.msg
.time
);
2460 hook_proc( wine_server_ptr_handle( msg_data
->winevent
.hook
), info
.msg
.message
,
2461 info
.msg
.hwnd
, info
.msg
.wParam
, info
.msg
.lParam
,
2462 msg_data
->winevent
.tid
, info
.msg
.time
);
2464 if (TRACE_ON(relay
))
2465 DPRINTF( "%04x:Ret winevent proc %p (hook=%04x,event=%x,hwnd=%p,object_id=%lx,child_id=%lx,tid=%04x,time=%x)\n",
2466 GetCurrentThreadId(), hook_proc
,
2467 msg_data
->winevent
.hook
, info
.msg
.message
, info
.msg
.hwnd
, info
.msg
.wParam
,
2468 info
.msg
.lParam
, msg_data
->winevent
.tid
, info
.msg
.time
);
2471 case MSG_OTHER_PROCESS
:
2472 info
.flags
= ISMEX_SEND
;
2473 if (!unpack_message( info
.msg
.hwnd
, info
.msg
.message
, &info
.msg
.wParam
,
2474 &info
.msg
.lParam
, &buffer
, size
))
2477 reply_message( &info
, 0, TRUE
);
2482 if (size
>= sizeof(msg_data
->hardware
))
2484 info
.msg
.pt
.x
= msg_data
->hardware
.x
;
2485 info
.msg
.pt
.y
= msg_data
->hardware
.y
;
2486 hw_id
= msg_data
->hardware
.hw_id
;
2487 if (!process_hardware_message( &info
.msg
, hw_id
, msg_data
->hardware
.info
,
2488 hwnd
, first
, last
, flags
& PM_REMOVE
))
2490 TRACE("dropping msg %x\n", info
.msg
.message
);
2491 continue; /* ignore it */
2494 thread_info
->GetMessagePosVal
= MAKELONG( info
.msg
.pt
.x
, info
.msg
.pt
.y
);
2495 thread_info
->GetMessageTimeVal
= info
.msg
.time
;
2496 thread_info
->GetMessageExtraInfoVal
= msg_data
->hardware
.info
;
2497 HeapFree( GetProcessHeap(), 0, buffer
);
2498 HOOK_CallHooks( WH_GETMESSAGE
, HC_ACTION
, flags
& PM_REMOVE
, (LPARAM
)msg
, TRUE
);
2503 if (info
.msg
.message
& 0x80000000) /* internal message */
2505 if (flags
& PM_REMOVE
)
2507 handle_internal_message( info
.msg
.hwnd
, info
.msg
.message
,
2508 info
.msg
.wParam
, info
.msg
.lParam
);
2509 /* if this is a nested call return right away */
2510 if (first
== info
.msg
.message
&& last
== info
.msg
.message
) return FALSE
;
2513 peek_message( msg
, info
.msg
.hwnd
, info
.msg
.message
,
2514 info
.msg
.message
, flags
| PM_REMOVE
, changed_mask
);
2517 if (info
.msg
.message
>= WM_DDE_FIRST
&& info
.msg
.message
<= WM_DDE_LAST
)
2519 if (!unpack_dde_message( info
.msg
.hwnd
, info
.msg
.message
, &info
.msg
.wParam
,
2520 &info
.msg
.lParam
, &buffer
, size
))
2521 continue; /* ignore it */
2524 msg
->pt
.x
= (short)LOWORD( thread_info
->GetMessagePosVal
);
2525 msg
->pt
.y
= (short)HIWORD( thread_info
->GetMessagePosVal
);
2526 thread_info
->GetMessageTimeVal
= info
.msg
.time
;
2527 thread_info
->GetMessageExtraInfoVal
= 0;
2528 HeapFree( GetProcessHeap(), 0, buffer
);
2529 HOOK_CallHooks( WH_GETMESSAGE
, HC_ACTION
, flags
& PM_REMOVE
, (LPARAM
)msg
, TRUE
);
2533 /* if we get here, we have a sent message; call the window procedure */
2534 old_info
= thread_info
->receive_info
;
2535 thread_info
->receive_info
= &info
;
2536 result
= call_window_proc( info
.msg
.hwnd
, info
.msg
.message
, info
.msg
.wParam
,
2537 info
.msg
.lParam
, (info
.type
!= MSG_ASCII
), FALSE
,
2538 WMCHAR_MAP_RECVMESSAGE
);
2539 reply_message( &info
, result
, TRUE
);
2540 thread_info
->receive_info
= old_info
;
2542 /* if some PM_QS* flags were specified, only handle sent messages from now on */
2543 if (HIWORD(flags
) && !changed_mask
) flags
= PM_QS_SENDMESSAGE
| LOWORD(flags
);
2548 /***********************************************************************
2549 * process_sent_messages
2551 * Process all pending sent messages.
2553 static inline void process_sent_messages(void)
2556 peek_message( &msg
, 0, 0, 0, PM_REMOVE
| PM_QS_SENDMESSAGE
, 0 );
2560 /***********************************************************************
2561 * get_server_queue_handle
2563 * Get a handle to the server message queue for the current thread.
2565 static HANDLE
get_server_queue_handle(void)
2567 struct user_thread_info
*thread_info
= get_user_thread_info();
2570 if (!(ret
= thread_info
->server_queue
))
2572 SERVER_START_REQ( get_msg_queue
)
2574 wine_server_call( req
);
2575 ret
= wine_server_ptr_handle( reply
->handle
);
2578 thread_info
->server_queue
= ret
;
2579 if (!ret
) ERR( "Cannot get server thread queue\n" );
2585 /***********************************************************************
2586 * wait_message_reply
2588 * Wait until a sent message gets replied to.
2590 static void wait_message_reply( UINT flags
)
2592 HANDLE server_queue
= get_server_queue_handle();
2596 unsigned int wake_bits
= 0;
2598 SERVER_START_REQ( set_queue_mask
)
2600 req
->wake_mask
= QS_SMRESULT
| ((flags
& SMTO_BLOCK
) ? 0 : QS_SENDMESSAGE
);
2601 req
->changed_mask
= req
->wake_mask
;
2603 if (!wine_server_call( req
))
2604 wake_bits
= reply
->wake_bits
;
2608 if (wake_bits
& QS_SMRESULT
) return; /* got a result */
2609 if (wake_bits
& QS_SENDMESSAGE
)
2611 /* Process the sent message immediately */
2612 process_sent_messages();
2616 wow_handlers
.wait_message( 1, &server_queue
, INFINITE
, QS_SENDMESSAGE
, 0 );
2620 /***********************************************************************
2621 * put_message_in_queue
2623 * Put a sent message into the destination queue.
2624 * For inter-process message, reply_size is set to expected size of reply data.
2626 static BOOL
put_message_in_queue( const struct send_message_info
*info
, size_t *reply_size
)
2628 struct packed_message data
;
2629 message_data_t msg_data
;
2632 timeout_t timeout
= TIMEOUT_INFINITE
;
2634 /* Check for INFINITE timeout for compatibility with Win9x,
2635 * although Windows >= NT does not do so
2637 if (info
->type
!= MSG_NOTIFY
&&
2638 info
->type
!= MSG_CALLBACK
&&
2639 info
->type
!= MSG_POSTED
&&
2641 info
->timeout
!= INFINITE
)
2643 /* timeout is signed despite the prototype */
2644 timeout
= (timeout_t
)max( 0, (int)info
->timeout
) * -10000;
2647 memset( &data
, 0, sizeof(data
) );
2648 if (info
->type
== MSG_OTHER_PROCESS
)
2650 *reply_size
= pack_message( info
->hwnd
, info
->msg
, info
->wparam
, info
->lparam
, &data
);
2651 if (data
.count
== -1)
2653 WARN( "cannot pack message %x\n", info
->msg
);
2657 else if (info
->type
== MSG_CALLBACK
)
2659 msg_data
.callback
.callback
= wine_server_client_ptr( info
->callback
);
2660 msg_data
.callback
.data
= info
->data
;
2661 msg_data
.callback
.result
= 0;
2662 data
.data
[0] = &msg_data
;
2663 data
.size
[0] = sizeof(msg_data
.callback
);
2666 else if (info
->type
== MSG_POSTED
&& info
->msg
>= WM_DDE_FIRST
&& info
->msg
<= WM_DDE_LAST
)
2668 return post_dde_message( &data
, info
);
2671 SERVER_START_REQ( send_message
)
2673 req
->id
= info
->dest_tid
;
2674 req
->type
= info
->type
;
2676 req
->win
= wine_server_user_handle( info
->hwnd
);
2677 req
->msg
= info
->msg
;
2678 req
->wparam
= info
->wparam
;
2679 req
->lparam
= info
->lparam
;
2680 req
->timeout
= timeout
;
2682 if (info
->flags
& SMTO_ABORTIFHUNG
) req
->flags
|= SEND_MSG_ABORT_IF_HUNG
;
2683 for (i
= 0; i
< data
.count
; i
++) wine_server_add_data( req
, data
.data
[i
], data
.size
[i
] );
2684 if ((res
= wine_server_call( req
)))
2686 if (res
== STATUS_INVALID_PARAMETER
)
2687 /* FIXME: find a STATUS_ value for this one */
2688 SetLastError( ERROR_INVALID_THREAD_ID
);
2690 SetLastError( RtlNtStatusToDosError(res
) );
2698 /***********************************************************************
2701 * Retrieve a message reply from the server.
2703 static LRESULT
retrieve_reply( const struct send_message_info
*info
,
2704 size_t reply_size
, LRESULT
*result
)
2707 void *reply_data
= NULL
;
2711 if (!(reply_data
= HeapAlloc( GetProcessHeap(), 0, reply_size
)))
2713 WARN( "no memory for reply, will be truncated\n" );
2717 SERVER_START_REQ( get_message_reply
)
2720 if (reply_size
) wine_server_set_reply( req
, reply_data
, reply_size
);
2721 if (!(status
= wine_server_call( req
))) *result
= reply
->result
;
2722 reply_size
= wine_server_reply_size( reply
);
2725 if (!status
&& reply_size
)
2726 unpack_reply( info
->hwnd
, info
->msg
, info
->wparam
, info
->lparam
, reply_data
, reply_size
);
2728 HeapFree( GetProcessHeap(), 0, reply_data
);
2730 TRACE( "hwnd %p msg %x (%s) wp %lx lp %lx got reply %lx (err=%d)\n",
2731 info
->hwnd
, info
->msg
, SPY_GetMsgName(info
->msg
, info
->hwnd
), info
->wparam
,
2732 info
->lparam
, *result
, status
);
2734 /* MSDN states that last error is 0 on timeout, but at least NT4 returns ERROR_TIMEOUT */
2735 if (status
) SetLastError( RtlNtStatusToDosError(status
) );
2740 /***********************************************************************
2741 * send_inter_thread_message
2743 static LRESULT
send_inter_thread_message( const struct send_message_info
*info
, LRESULT
*res_ptr
)
2745 size_t reply_size
= 0;
2747 TRACE( "hwnd %p msg %x (%s) wp %lx lp %lx\n",
2748 info
->hwnd
, info
->msg
, SPY_GetMsgName(info
->msg
, info
->hwnd
), info
->wparam
, info
->lparam
);
2750 USER_CheckNotLock();
2752 if (!put_message_in_queue( info
, &reply_size
)) return 0;
2754 /* there's no reply to wait for on notify/callback messages */
2755 if (info
->type
== MSG_NOTIFY
|| info
->type
== MSG_CALLBACK
) return 1;
2757 wait_message_reply( info
->flags
);
2758 return retrieve_reply( info
, reply_size
, res_ptr
);
2762 /***********************************************************************
2763 * send_inter_thread_callback
2765 static LRESULT
send_inter_thread_callback( HWND hwnd
, UINT msg
, WPARAM wp
, LPARAM lp
,
2766 LRESULT
*result
, void *arg
)
2768 struct send_message_info
*info
= arg
;
2773 return send_inter_thread_message( info
, result
);
2777 /***********************************************************************
2780 * Backend implementation of the various SendMessage functions.
2782 static BOOL
send_message( struct send_message_info
*info
, DWORD_PTR
*res_ptr
, BOOL unicode
)
2788 if (is_broadcast(info
->hwnd
))
2790 EnumWindows( broadcast_message_callback
, (LPARAM
)info
);
2791 if (res_ptr
) *res_ptr
= 1;
2795 if (!(info
->dest_tid
= GetWindowThreadProcessId( info
->hwnd
, &dest_pid
))) return FALSE
;
2797 if (USER_IsExitingThread( info
->dest_tid
)) return FALSE
;
2799 SPY_EnterMessage( SPY_SENDMESSAGE
, info
->hwnd
, info
->msg
, info
->wparam
, info
->lparam
);
2801 if (info
->dest_tid
== GetCurrentThreadId())
2803 result
= call_window_proc( info
->hwnd
, info
->msg
, info
->wparam
, info
->lparam
,
2804 unicode
, TRUE
, info
->wm_char
);
2805 if (info
->type
== MSG_CALLBACK
)
2806 call_sendmsg_callback( info
->callback
, info
->hwnd
, info
->msg
, info
->data
, result
);
2811 if (dest_pid
!= GetCurrentProcessId() && (info
->type
== MSG_ASCII
|| info
->type
== MSG_UNICODE
))
2812 info
->type
= MSG_OTHER_PROCESS
;
2814 /* MSG_ASCII can be sent unconverted except for WM_CHAR; everything else needs to be Unicode */
2815 if (!unicode
&& is_unicode_message( info
->msg
) &&
2816 (info
->type
!= MSG_ASCII
|| info
->msg
== WM_CHAR
))
2817 ret
= WINPROC_CallProcAtoW( send_inter_thread_callback
, info
->hwnd
, info
->msg
,
2818 info
->wparam
, info
->lparam
, &result
, info
, info
->wm_char
);
2820 ret
= send_inter_thread_message( info
, &result
);
2823 SPY_ExitMessage( SPY_RESULT_OK
, info
->hwnd
, info
->msg
, result
, info
->wparam
, info
->lparam
);
2824 if (ret
&& res_ptr
) *res_ptr
= result
;
2829 /***********************************************************************
2830 * MSG_SendInternalMessageTimeout
2832 * Same as SendMessageTimeoutW but sends the message to a specific thread
2833 * without requiring a window handle. Only works for internal Wine messages.
2835 LRESULT
MSG_SendInternalMessageTimeout( DWORD dest_pid
, DWORD dest_tid
,
2836 UINT msg
, WPARAM wparam
, LPARAM lparam
,
2837 UINT flags
, UINT timeout
, PDWORD_PTR res_ptr
)
2839 struct send_message_info info
;
2840 LRESULT ret
, result
;
2842 assert( msg
& 0x80000000 ); /* must be an internal Wine message */
2844 info
.type
= MSG_UNICODE
;
2845 info
.dest_tid
= dest_tid
;
2848 info
.wparam
= wparam
;
2849 info
.lparam
= lparam
;
2851 info
.timeout
= timeout
;
2853 if (USER_IsExitingThread( dest_tid
)) return 0;
2855 if (dest_tid
== GetCurrentThreadId())
2857 result
= handle_internal_message( 0, msg
, wparam
, lparam
);
2862 if (dest_pid
!= GetCurrentProcessId()) info
.type
= MSG_OTHER_PROCESS
;
2863 ret
= send_inter_thread_message( &info
, &result
);
2865 if (ret
&& res_ptr
) *res_ptr
= result
;
2870 /***********************************************************************
2871 * SendMessageTimeoutW (USER32.@)
2873 LRESULT WINAPI
SendMessageTimeoutW( HWND hwnd
, UINT msg
, WPARAM wparam
, LPARAM lparam
,
2874 UINT flags
, UINT timeout
, PDWORD_PTR res_ptr
)
2876 struct send_message_info info
;
2878 info
.type
= MSG_UNICODE
;
2881 info
.wparam
= wparam
;
2882 info
.lparam
= lparam
;
2884 info
.timeout
= timeout
;
2886 return send_message( &info
, res_ptr
, TRUE
);
2889 /***********************************************************************
2890 * SendMessageTimeoutA (USER32.@)
2892 LRESULT WINAPI
SendMessageTimeoutA( HWND hwnd
, UINT msg
, WPARAM wparam
, LPARAM lparam
,
2893 UINT flags
, UINT timeout
, PDWORD_PTR res_ptr
)
2895 struct send_message_info info
;
2897 info
.type
= MSG_ASCII
;
2900 info
.wparam
= wparam
;
2901 info
.lparam
= lparam
;
2903 info
.timeout
= timeout
;
2904 info
.wm_char
= WMCHAR_MAP_SENDMESSAGETIMEOUT
;
2906 return send_message( &info
, res_ptr
, FALSE
);
2910 /***********************************************************************
2911 * SendMessageW (USER32.@)
2913 LRESULT WINAPI
SendMessageW( HWND hwnd
, UINT msg
, WPARAM wparam
, LPARAM lparam
)
2916 struct send_message_info info
;
2918 info
.type
= MSG_UNICODE
;
2921 info
.wparam
= wparam
;
2922 info
.lparam
= lparam
;
2923 info
.flags
= SMTO_NORMAL
;
2926 send_message( &info
, &res
, TRUE
);
2931 /***********************************************************************
2932 * SendMessageA (USER32.@)
2934 LRESULT WINAPI
SendMessageA( HWND hwnd
, UINT msg
, WPARAM wparam
, LPARAM lparam
)
2937 struct send_message_info info
;
2939 info
.type
= MSG_ASCII
;
2942 info
.wparam
= wparam
;
2943 info
.lparam
= lparam
;
2944 info
.flags
= SMTO_NORMAL
;
2946 info
.wm_char
= WMCHAR_MAP_SENDMESSAGE
;
2948 send_message( &info
, &res
, FALSE
);
2953 /***********************************************************************
2954 * SendNotifyMessageA (USER32.@)
2956 BOOL WINAPI
SendNotifyMessageA( HWND hwnd
, UINT msg
, WPARAM wparam
, LPARAM lparam
)
2958 struct send_message_info info
;
2960 if (is_pointer_message(msg
))
2962 SetLastError( ERROR_MESSAGE_SYNC_ONLY
);
2966 info
.type
= MSG_NOTIFY
;
2969 info
.wparam
= wparam
;
2970 info
.lparam
= lparam
;
2972 info
.wm_char
= WMCHAR_MAP_SENDMESSAGETIMEOUT
;
2974 return send_message( &info
, NULL
, FALSE
);
2978 /***********************************************************************
2979 * SendNotifyMessageW (USER32.@)
2981 BOOL WINAPI
SendNotifyMessageW( HWND hwnd
, UINT msg
, WPARAM wparam
, LPARAM lparam
)
2983 struct send_message_info info
;
2985 if (is_pointer_message(msg
))
2987 SetLastError( ERROR_MESSAGE_SYNC_ONLY
);
2991 info
.type
= MSG_NOTIFY
;
2994 info
.wparam
= wparam
;
2995 info
.lparam
= lparam
;
2998 return send_message( &info
, NULL
, TRUE
);
3002 /***********************************************************************
3003 * SendMessageCallbackA (USER32.@)
3005 BOOL WINAPI
SendMessageCallbackA( HWND hwnd
, UINT msg
, WPARAM wparam
, LPARAM lparam
,
3006 SENDASYNCPROC callback
, ULONG_PTR data
)
3008 struct send_message_info info
;
3010 if (is_pointer_message(msg
))
3012 SetLastError( ERROR_MESSAGE_SYNC_ONLY
);
3016 info
.type
= MSG_CALLBACK
;
3019 info
.wparam
= wparam
;
3020 info
.lparam
= lparam
;
3021 info
.callback
= callback
;
3024 info
.wm_char
= WMCHAR_MAP_SENDMESSAGETIMEOUT
;
3026 return send_message( &info
, NULL
, FALSE
);
3030 /***********************************************************************
3031 * SendMessageCallbackW (USER32.@)
3033 BOOL WINAPI
SendMessageCallbackW( HWND hwnd
, UINT msg
, WPARAM wparam
, LPARAM lparam
,
3034 SENDASYNCPROC callback
, ULONG_PTR data
)
3036 struct send_message_info info
;
3038 if (is_pointer_message(msg
))
3040 SetLastError( ERROR_MESSAGE_SYNC_ONLY
);
3044 info
.type
= MSG_CALLBACK
;
3047 info
.wparam
= wparam
;
3048 info
.lparam
= lparam
;
3049 info
.callback
= callback
;
3053 return send_message( &info
, NULL
, TRUE
);
3057 /***********************************************************************
3058 * ReplyMessage (USER32.@)
3060 BOOL WINAPI
ReplyMessage( LRESULT result
)
3062 struct received_message_info
*info
= get_user_thread_info()->receive_info
;
3064 if (!info
) return FALSE
;
3065 reply_message( info
, result
, FALSE
);
3070 /***********************************************************************
3071 * InSendMessage (USER32.@)
3073 BOOL WINAPI
InSendMessage(void)
3075 return (InSendMessageEx(NULL
) & (ISMEX_SEND
|ISMEX_REPLIED
)) == ISMEX_SEND
;
3079 /***********************************************************************
3080 * InSendMessageEx (USER32.@)
3082 DWORD WINAPI
InSendMessageEx( LPVOID reserved
)
3084 struct received_message_info
*info
= get_user_thread_info()->receive_info
;
3086 if (info
) return info
->flags
;
3087 return ISMEX_NOSEND
;
3091 /***********************************************************************
3092 * PostMessageA (USER32.@)
3094 BOOL WINAPI
PostMessageA( HWND hwnd
, UINT msg
, WPARAM wparam
, LPARAM lparam
)
3096 if (!map_wparam_AtoW( msg
, &wparam
, WMCHAR_MAP_POSTMESSAGE
)) return TRUE
;
3097 return PostMessageW( hwnd
, msg
, wparam
, lparam
);
3101 /***********************************************************************
3102 * PostMessageW (USER32.@)
3104 BOOL WINAPI
PostMessageW( HWND hwnd
, UINT msg
, WPARAM wparam
, LPARAM lparam
)
3106 struct send_message_info info
;
3108 if (is_pointer_message( msg
))
3110 SetLastError( ERROR_MESSAGE_SYNC_ONLY
);
3114 TRACE( "hwnd %p msg %x (%s) wp %lx lp %lx\n",
3115 hwnd
, msg
, SPY_GetMsgName(msg
, hwnd
), wparam
, lparam
);
3117 info
.type
= MSG_POSTED
;
3120 info
.wparam
= wparam
;
3121 info
.lparam
= lparam
;
3124 if (is_broadcast(hwnd
))
3126 EnumWindows( broadcast_message_callback
, (LPARAM
)&info
);
3130 if (!hwnd
) return PostThreadMessageW( GetCurrentThreadId(), msg
, wparam
, lparam
);
3132 if (!(info
.dest_tid
= GetWindowThreadProcessId( hwnd
, NULL
))) return FALSE
;
3134 if (USER_IsExitingThread( info
.dest_tid
)) return TRUE
;
3136 return put_message_in_queue( &info
, NULL
);
3140 /**********************************************************************
3141 * PostThreadMessageA (USER32.@)
3143 BOOL WINAPI
PostThreadMessageA( DWORD thread
, UINT msg
, WPARAM wparam
, LPARAM lparam
)
3145 if (!map_wparam_AtoW( msg
, &wparam
, WMCHAR_MAP_POSTMESSAGE
)) return TRUE
;
3146 return PostThreadMessageW( thread
, msg
, wparam
, lparam
);
3150 /**********************************************************************
3151 * PostThreadMessageW (USER32.@)
3153 BOOL WINAPI
PostThreadMessageW( DWORD thread
, UINT msg
, WPARAM wparam
, LPARAM lparam
)
3155 struct send_message_info info
;
3157 if (is_pointer_message( msg
))
3159 SetLastError( ERROR_MESSAGE_SYNC_ONLY
);
3162 if (USER_IsExitingThread( thread
)) return TRUE
;
3164 info
.type
= MSG_POSTED
;
3165 info
.dest_tid
= thread
;
3168 info
.wparam
= wparam
;
3169 info
.lparam
= lparam
;
3171 return put_message_in_queue( &info
, NULL
);
3175 /***********************************************************************
3176 * PostQuitMessage (USER32.@)
3178 * Posts a quit message to the current thread's message queue.
3181 * exit_code [I] Exit code to return from message loop.
3187 * This function is not the same as calling:
3188 *|PostThreadMessage(GetCurrentThreadId(), WM_QUIT, exit_code, 0);
3189 * It instead sets a flag in the message queue that signals it to generate
3190 * a WM_QUIT message when there are no other pending sent or posted messages
3193 void WINAPI
PostQuitMessage( INT exit_code
)
3195 SERVER_START_REQ( post_quit_message
)
3197 req
->exit_code
= exit_code
;
3198 wine_server_call( req
);
3204 /***********************************************************************
3205 * PeekMessageW (USER32.@)
3207 BOOL WINAPI
PeekMessageW( MSG
*msg_out
, HWND hwnd
, UINT first
, UINT last
, UINT flags
)
3211 USER_CheckNotLock();
3213 /* check for graphics events */
3214 USER_Driver
->pMsgWaitForMultipleObjectsEx( 0, NULL
, 0, QS_ALLINPUT
, 0 );
3216 if (!peek_message( &msg
, hwnd
, first
, last
, flags
, 0 ))
3218 if (!(flags
& PM_NOYIELD
)) wow_handlers
.wait_message( 0, NULL
, 0, 0, 0 );
3222 /* copy back our internal safe copy of message data to msg_out.
3223 * msg_out is a variable from the *program*, so it can't be used
3224 * internally as it can get "corrupted" by our use of SendMessage()
3225 * (back to the program) inside the message handling itself. */
3228 SetLastError( ERROR_NOACCESS
);
3236 /***********************************************************************
3237 * PeekMessageA (USER32.@)
3239 BOOL WINAPI
PeekMessageA( MSG
*msg
, HWND hwnd
, UINT first
, UINT last
, UINT flags
)
3241 if (get_pending_wmchar( msg
, first
, last
, (flags
& PM_REMOVE
) )) return TRUE
;
3242 if (!PeekMessageW( msg
, hwnd
, first
, last
, flags
)) return FALSE
;
3243 map_wparam_WtoA( msg
, (flags
& PM_REMOVE
) );
3248 /***********************************************************************
3249 * GetMessageW (USER32.@)
3251 BOOL WINAPI
GetMessageW( MSG
*msg
, HWND hwnd
, UINT first
, UINT last
)
3253 HANDLE server_queue
= get_server_queue_handle();
3254 unsigned int mask
= QS_POSTMESSAGE
| QS_SENDMESSAGE
; /* Always selected */
3256 USER_CheckNotLock();
3258 /* check for graphics events */
3259 USER_Driver
->pMsgWaitForMultipleObjectsEx( 0, NULL
, 0, QS_ALLINPUT
, 0 );
3263 if ((first
<= WM_KEYLAST
) && (last
>= WM_KEYFIRST
)) mask
|= QS_KEY
;
3264 if ( ((first
<= WM_MOUSELAST
) && (last
>= WM_MOUSEFIRST
)) ||
3265 ((first
<= WM_NCMOUSELAST
) && (last
>= WM_NCMOUSEFIRST
)) ) mask
|= QS_MOUSE
;
3266 if ((first
<= WM_TIMER
) && (last
>= WM_TIMER
)) mask
|= QS_TIMER
;
3267 if ((first
<= WM_SYSTIMER
) && (last
>= WM_SYSTIMER
)) mask
|= QS_TIMER
;
3268 if ((first
<= WM_PAINT
) && (last
>= WM_PAINT
)) mask
|= QS_PAINT
;
3270 else mask
= QS_ALLINPUT
;
3272 while (!peek_message( msg
, hwnd
, first
, last
, PM_REMOVE
| (mask
<< 16), mask
))
3274 wow_handlers
.wait_message( 1, &server_queue
, INFINITE
, mask
, 0 );
3277 return (msg
->message
!= WM_QUIT
);
3281 /***********************************************************************
3282 * GetMessageA (USER32.@)
3284 BOOL WINAPI
GetMessageA( MSG
*msg
, HWND hwnd
, UINT first
, UINT last
)
3286 if (get_pending_wmchar( msg
, first
, last
, TRUE
)) return TRUE
;
3287 GetMessageW( msg
, hwnd
, first
, last
);
3288 map_wparam_WtoA( msg
, TRUE
);
3289 return (msg
->message
!= WM_QUIT
);
3293 /***********************************************************************
3294 * IsDialogMessageA (USER32.@)
3295 * IsDialogMessage (USER32.@)
3297 BOOL WINAPI
IsDialogMessageA( HWND hwndDlg
, LPMSG pmsg
)
3300 map_wparam_AtoW( msg
.message
, &msg
.wParam
, WMCHAR_MAP_NOMAPPING
);
3301 return IsDialogMessageW( hwndDlg
, &msg
);
3305 /***********************************************************************
3306 * TranslateMessage (USER32.@)
3308 * Implementation of TranslateMessage.
3310 * TranslateMessage translates virtual-key messages into character-messages,
3312 * WM_KEYDOWN/WM_KEYUP combinations produce a WM_CHAR or WM_DEADCHAR message.
3313 * ditto replacing WM_* with WM_SYS*
3314 * This produces WM_CHAR messages only for keys mapped to ASCII characters
3315 * by the keyboard driver.
3317 * If the message is WM_KEYDOWN, WM_KEYUP, WM_SYSKEYDOWN, or WM_SYSKEYUP, the
3318 * return value is nonzero, regardless of the translation.
3321 BOOL WINAPI
TranslateMessage( const MSG
*msg
)
3327 if (msg
->message
< WM_KEYFIRST
|| msg
->message
> WM_KEYLAST
) return FALSE
;
3328 if (msg
->message
!= WM_KEYDOWN
&& msg
->message
!= WM_SYSKEYDOWN
) return TRUE
;
3330 TRACE_(key
)("Translating key %s (%04lX), scancode %04x\n",
3331 SPY_GetVKeyName(msg
->wParam
), msg
->wParam
, HIWORD(msg
->lParam
));
3333 switch (msg
->wParam
)
3336 message
= (msg
->message
== WM_KEYDOWN
) ? WM_CHAR
: WM_SYSCHAR
;
3337 TRACE_(key
)("PostMessageW(%p,%s,%04x,%08x)\n",
3338 msg
->hwnd
, SPY_GetMsgName(message
, msg
->hwnd
), HIWORD(msg
->lParam
), LOWORD(msg
->lParam
));
3339 PostMessageW( msg
->hwnd
, message
, HIWORD(msg
->lParam
), LOWORD(msg
->lParam
));
3343 return ImmTranslateMessage(msg
->hwnd
, msg
->message
, msg
->wParam
, msg
->lParam
);
3346 GetKeyboardState( state
);
3347 /* FIXME : should handle ToUnicode yielding 2 */
3348 switch (ToUnicode(msg
->wParam
, HIWORD(msg
->lParam
), state
, wp
, 2, 0))
3351 message
= (msg
->message
== WM_KEYDOWN
) ? WM_CHAR
: WM_SYSCHAR
;
3352 TRACE_(key
)("1 -> PostMessageW(%p,%s,%04x,%08lx)\n",
3353 msg
->hwnd
, SPY_GetMsgName(message
, msg
->hwnd
), wp
[0], msg
->lParam
);
3354 PostMessageW( msg
->hwnd
, message
, wp
[0], msg
->lParam
);
3358 message
= (msg
->message
== WM_KEYDOWN
) ? WM_DEADCHAR
: WM_SYSDEADCHAR
;
3359 TRACE_(key
)("-1 -> PostMessageW(%p,%s,%04x,%08lx)\n",
3360 msg
->hwnd
, SPY_GetMsgName(message
, msg
->hwnd
), wp
[0], msg
->lParam
);
3361 PostMessageW( msg
->hwnd
, message
, wp
[0], msg
->lParam
);
3368 /***********************************************************************
3369 * DispatchMessageA (USER32.@)
3371 * See DispatchMessageW.
3373 LRESULT WINAPI DECLSPEC_HOTPATCH
DispatchMessageA( const MSG
* msg
)
3377 /* Process timer messages */
3378 if ((msg
->message
== WM_TIMER
) || (msg
->message
== WM_SYSTIMER
))
3384 retval
= CallWindowProcA( (WNDPROC
)msg
->lParam
, msg
->hwnd
,
3385 msg
->message
, msg
->wParam
, GetTickCount() );
3395 if (!msg
->hwnd
) return 0;
3397 SPY_EnterMessage( SPY_DISPATCHMESSAGE
, msg
->hwnd
, msg
->message
,
3398 msg
->wParam
, msg
->lParam
);
3400 if (!WINPROC_call_window( msg
->hwnd
, msg
->message
, msg
->wParam
, msg
->lParam
,
3401 &retval
, FALSE
, WMCHAR_MAP_DISPATCHMESSAGE
))
3403 if (!IsWindow( msg
->hwnd
)) SetLastError( ERROR_INVALID_WINDOW_HANDLE
);
3404 else SetLastError( ERROR_MESSAGE_SYNC_ONLY
);
3408 SPY_ExitMessage( SPY_RESULT_OK
, msg
->hwnd
, msg
->message
, retval
,
3409 msg
->wParam
, msg
->lParam
);
3411 if (msg
->message
== WM_PAINT
)
3413 /* send a WM_NCPAINT and WM_ERASEBKGND if the non-client area is still invalid */
3414 HRGN hrgn
= CreateRectRgn( 0, 0, 0, 0 );
3415 GetUpdateRgn( msg
->hwnd
, hrgn
, TRUE
);
3416 DeleteObject( hrgn
);
3422 /***********************************************************************
3423 * DispatchMessageW (USER32.@) Process a message
3425 * Process the message specified in the structure *_msg_.
3427 * If the lpMsg parameter points to a WM_TIMER message and the
3428 * parameter of the WM_TIMER message is not NULL, the lParam parameter
3429 * points to the function that is called instead of the window
3430 * procedure. The function stored in lParam (timer callback) is protected
3431 * from causing page-faults.
3433 * The message must be valid.
3437 * DispatchMessage() returns the result of the window procedure invoked.
3444 LRESULT WINAPI DECLSPEC_HOTPATCH
DispatchMessageW( const MSG
* msg
)
3448 /* Process timer messages */
3449 if ((msg
->message
== WM_TIMER
) || (msg
->message
== WM_SYSTIMER
))
3455 retval
= CallWindowProcW( (WNDPROC
)msg
->lParam
, msg
->hwnd
,
3456 msg
->message
, msg
->wParam
, GetTickCount() );
3466 if (!msg
->hwnd
) return 0;
3468 SPY_EnterMessage( SPY_DISPATCHMESSAGE
, msg
->hwnd
, msg
->message
,
3469 msg
->wParam
, msg
->lParam
);
3471 if (!WINPROC_call_window( msg
->hwnd
, msg
->message
, msg
->wParam
, msg
->lParam
,
3472 &retval
, TRUE
, WMCHAR_MAP_DISPATCHMESSAGE
))
3474 if (!IsWindow( msg
->hwnd
)) SetLastError( ERROR_INVALID_WINDOW_HANDLE
);
3475 else SetLastError( ERROR_MESSAGE_SYNC_ONLY
);
3479 SPY_ExitMessage( SPY_RESULT_OK
, msg
->hwnd
, msg
->message
, retval
,
3480 msg
->wParam
, msg
->lParam
);
3482 if (msg
->message
== WM_PAINT
)
3484 /* send a WM_NCPAINT and WM_ERASEBKGND if the non-client area is still invalid */
3485 HRGN hrgn
= CreateRectRgn( 0, 0, 0, 0 );
3486 GetUpdateRgn( msg
->hwnd
, hrgn
, TRUE
);
3487 DeleteObject( hrgn
);
3493 /***********************************************************************
3494 * GetMessagePos (USER.119)
3495 * GetMessagePos (USER32.@)
3497 * The GetMessagePos() function returns a long value representing a
3498 * cursor position, in screen coordinates, when the last message
3499 * retrieved by the GetMessage() function occurs. The x-coordinate is
3500 * in the low-order word of the return value, the y-coordinate is in
3501 * the high-order word. The application can use the MAKEPOINT()
3502 * macro to obtain a POINT structure from the return value.
3504 * For the current cursor position, use GetCursorPos().
3508 * Cursor position of last message on success, zero on failure.
3515 DWORD WINAPI
GetMessagePos(void)
3517 return get_user_thread_info()->GetMessagePosVal
;
3521 /***********************************************************************
3522 * GetMessageTime (USER.120)
3523 * GetMessageTime (USER32.@)
3525 * GetMessageTime() returns the message time for the last message
3526 * retrieved by the function. The time is measured in milliseconds with
3527 * the same offset as GetTickCount().
3529 * Since the tick count wraps, this is only useful for moderately short
3530 * relative time comparisons.
3534 * Time of last message on success, zero on failure.
3536 LONG WINAPI
GetMessageTime(void)
3538 return get_user_thread_info()->GetMessageTimeVal
;
3542 /***********************************************************************
3543 * GetMessageExtraInfo (USER.288)
3544 * GetMessageExtraInfo (USER32.@)
3546 LPARAM WINAPI
GetMessageExtraInfo(void)
3548 return get_user_thread_info()->GetMessageExtraInfoVal
;
3552 /***********************************************************************
3553 * SetMessageExtraInfo (USER32.@)
3555 LPARAM WINAPI
SetMessageExtraInfo(LPARAM lParam
)
3557 struct user_thread_info
*thread_info
= get_user_thread_info();
3558 LONG old_value
= thread_info
->GetMessageExtraInfoVal
;
3559 thread_info
->GetMessageExtraInfoVal
= lParam
;
3564 /***********************************************************************
3565 * WaitMessage (USER.112) Suspend thread pending messages
3566 * WaitMessage (USER32.@) Suspend thread pending messages
3568 * WaitMessage() suspends a thread until events appear in the thread's
3571 BOOL WINAPI
WaitMessage(void)
3573 return (MsgWaitForMultipleObjectsEx( 0, NULL
, INFINITE
, QS_ALLINPUT
, 0 ) != WAIT_FAILED
);
3577 /***********************************************************************
3578 * MsgWaitForMultipleObjectsEx (USER32.@)
3580 DWORD WINAPI
MsgWaitForMultipleObjectsEx( DWORD count
, CONST HANDLE
*pHandles
,
3581 DWORD timeout
, DWORD mask
, DWORD flags
)
3583 HANDLE handles
[MAXIMUM_WAIT_OBJECTS
];
3586 if (count
> MAXIMUM_WAIT_OBJECTS
-1)
3588 SetLastError( ERROR_INVALID_PARAMETER
);
3592 /* set the queue mask */
3593 SERVER_START_REQ( set_queue_mask
)
3595 req
->wake_mask
= (flags
& MWMO_INPUTAVAILABLE
) ? mask
: 0;
3596 req
->changed_mask
= mask
;
3598 wine_server_call( req
);
3602 /* add the queue to the handle list */
3603 for (i
= 0; i
< count
; i
++) handles
[i
] = pHandles
[i
];
3604 handles
[count
] = get_server_queue_handle();
3606 return wow_handlers
.wait_message( count
+1, handles
, timeout
, mask
, flags
);
3610 /***********************************************************************
3611 * MsgWaitForMultipleObjects (USER32.@)
3613 DWORD WINAPI
MsgWaitForMultipleObjects( DWORD count
, CONST HANDLE
*handles
,
3614 BOOL wait_all
, DWORD timeout
, DWORD mask
)
3616 return MsgWaitForMultipleObjectsEx( count
, handles
, timeout
, mask
,
3617 wait_all
? MWMO_WAITALL
: 0 );
3621 /***********************************************************************
3622 * WaitForInputIdle (USER32.@)
3624 DWORD WINAPI
WaitForInputIdle( HANDLE hProcess
, DWORD dwTimeOut
)
3626 DWORD start_time
, elapsed
, ret
;
3629 handles
[0] = hProcess
;
3630 SERVER_START_REQ( get_process_idle_event
)
3632 req
->handle
= wine_server_obj_handle( hProcess
);
3633 wine_server_call_err( req
);
3634 handles
[1] = wine_server_ptr_handle( reply
->event
);
3637 if (!handles
[1]) return WAIT_FAILED
; /* no event to wait on */
3639 start_time
= GetTickCount();
3642 TRACE("waiting for %p\n", handles
[1] );
3645 ret
= MsgWaitForMultipleObjects ( 2, handles
, FALSE
, dwTimeOut
- elapsed
, QS_SENDMESSAGE
);
3650 case WAIT_OBJECT_0
+2:
3651 process_sent_messages();
3655 TRACE("timeout or error\n");
3658 TRACE("finished\n");
3661 if (dwTimeOut
!= INFINITE
)
3663 elapsed
= GetTickCount() - start_time
;
3664 if (elapsed
> dwTimeOut
)
3670 return WAIT_TIMEOUT
;
3674 /***********************************************************************
3675 * RegisterWindowMessageA (USER32.@)
3676 * RegisterWindowMessage (USER.118)
3678 UINT WINAPI
RegisterWindowMessageA( LPCSTR str
)
3680 UINT ret
= GlobalAddAtomA(str
);
3681 TRACE("%s, ret=%x\n", str
, ret
);
3686 /***********************************************************************
3687 * RegisterWindowMessageW (USER32.@)
3689 UINT WINAPI
RegisterWindowMessageW( LPCWSTR str
)
3691 UINT ret
= GlobalAddAtomW(str
);
3692 TRACE("%s ret=%x\n", debugstr_w(str
), ret
);
3696 typedef struct BroadcastParm
3707 static BOOL CALLBACK
bcast_childwindow( HWND hw
, LPARAM lp
)
3709 BroadcastParm
*parm
= (BroadcastParm
*)lp
;
3710 DWORD_PTR retval
= 0;
3713 if (parm
->flags
& BSF_IGNORECURRENTTASK
&& WIN_IsCurrentProcess(hw
))
3715 TRACE("Not telling myself %p\n", hw
);
3719 /* I don't know 100% for sure if this is what Windows does, but it fits the tests */
3720 if (parm
->flags
& BSF_QUERY
)
3722 TRACE("Telling window %p using SendMessageTimeout\n", hw
);
3724 /* Not tested for conflicting flags */
3725 if (parm
->flags
& BSF_FORCEIFHUNG
|| parm
->flags
& BSF_NOHANG
)
3726 lresult
= SendMessageTimeoutW( hw
, parm
->msg
, parm
->wp
, parm
->lp
, SMTO_ABORTIFHUNG
, 2000, &retval
);
3727 else if (parm
->flags
& BSF_NOTIMEOUTIFNOTHUNG
)
3728 lresult
= SendMessageTimeoutW( hw
, parm
->msg
, parm
->wp
, parm
->lp
, SMTO_NOTIMEOUTIFNOTHUNG
, 2000, &retval
);
3730 lresult
= SendMessageTimeoutW( hw
, parm
->msg
, parm
->wp
, parm
->lp
, SMTO_NORMAL
, 2000, &retval
);
3732 if (!lresult
&& GetLastError() == ERROR_TIMEOUT
)
3734 WARN("Timed out!\n");
3735 if (!(parm
->flags
& BSF_FORCEIFHUNG
))
3738 if (retval
== BROADCAST_QUERY_DENY
)
3747 else if (parm
->flags
& BSF_POSTMESSAGE
)
3749 TRACE("Telling window %p using PostMessage\n", hw
);
3750 PostMessageW( hw
, parm
->msg
, parm
->wp
, parm
->lp
);
3754 TRACE("Telling window %p using SendNotifyMessage\n", hw
);
3755 SendNotifyMessageW( hw
, parm
->msg
, parm
->wp
, parm
->lp
);
3761 static BOOL CALLBACK
bcast_desktop( LPWSTR desktop
, LPARAM lp
)
3765 BroadcastParm
*parm
= (BroadcastParm
*)lp
;
3767 TRACE("desktop: %s\n", debugstr_w( desktop
));
3769 hdesktop
= open_winstation_desktop( parm
->winsta
, desktop
, 0, FALSE
, DESKTOP_ENUMERATE
|DESKTOP_WRITEOBJECTS
|STANDARD_RIGHTS_WRITE
);
3772 FIXME("Could not open desktop %s\n", debugstr_w(desktop
));
3776 ret
= EnumDesktopWindows( hdesktop
, bcast_childwindow
, lp
);
3777 CloseDesktop(hdesktop
);
3778 TRACE("-->%d\n", ret
);
3779 return parm
->success
;
3782 static BOOL CALLBACK
bcast_winsta( LPWSTR winsta
, LPARAM lp
)
3785 HWINSTA hwinsta
= OpenWindowStationW( winsta
, FALSE
, WINSTA_ENUMDESKTOPS
);
3786 TRACE("hwinsta: %p/%s/%08x\n", hwinsta
, debugstr_w( winsta
), GetLastError());
3789 ((BroadcastParm
*)lp
)->winsta
= hwinsta
;
3790 ret
= EnumDesktopsW( hwinsta
, bcast_desktop
, lp
);
3791 CloseWindowStation( hwinsta
);
3792 TRACE("-->%d\n", ret
);
3796 /***********************************************************************
3797 * BroadcastSystemMessageA (USER32.@)
3798 * BroadcastSystemMessage (USER32.@)
3800 LONG WINAPI
BroadcastSystemMessageA( DWORD flags
, LPDWORD recipients
, UINT msg
, WPARAM wp
, LPARAM lp
)
3802 return BroadcastSystemMessageExA( flags
, recipients
, msg
, wp
, lp
, NULL
);
3806 /***********************************************************************
3807 * BroadcastSystemMessageW (USER32.@)
3809 LONG WINAPI
BroadcastSystemMessageW( DWORD flags
, LPDWORD recipients
, UINT msg
, WPARAM wp
, LPARAM lp
)
3811 return BroadcastSystemMessageExW( flags
, recipients
, msg
, wp
, lp
, NULL
);
3814 /***********************************************************************
3815 * BroadcastSystemMessageExA (USER32.@)
3817 LONG WINAPI
BroadcastSystemMessageExA( DWORD flags
, LPDWORD recipients
, UINT msg
, WPARAM wp
, LPARAM lp
, PBSMINFO pinfo
)
3819 map_wparam_AtoW( msg
, &wp
, WMCHAR_MAP_NOMAPPING
);
3820 return BroadcastSystemMessageExW( flags
, recipients
, msg
, wp
, lp
, NULL
);
3824 /***********************************************************************
3825 * BroadcastSystemMessageExW (USER32.@)
3827 LONG WINAPI
BroadcastSystemMessageExW( DWORD flags
, LPDWORD recipients
, UINT msg
, WPARAM wp
, LPARAM lp
, PBSMINFO pinfo
)
3830 DWORD recips
= BSM_ALLCOMPONENTS
;
3832 static const DWORD all_flags
= ( BSF_QUERY
| BSF_IGNORECURRENTTASK
| BSF_FLUSHDISK
| BSF_NOHANG
3833 | BSF_POSTMESSAGE
| BSF_FORCEIFHUNG
| BSF_NOTIMEOUTIFNOTHUNG
3834 | BSF_ALLOWSFW
| BSF_SENDNOTIFYMESSAGE
| BSF_RETURNHDESK
| BSF_LUID
);
3836 TRACE("Flags: %08x, recipients: %p(0x%x), msg: %04x, wparam: %08lx, lparam: %08lx\n", flags
, recipients
,
3837 (recipients
? *recipients
: recips
), msg
, wp
, lp
);
3839 if (flags
& ~all_flags
)
3841 SetLastError(ERROR_INVALID_PARAMETER
);
3846 recipients
= &recips
;
3848 if ( pinfo
&& flags
& BSF_QUERY
)
3849 FIXME("Not returning PBSMINFO information yet\n");
3852 parm
.recipients
= recipients
;
3856 parm
.success
= TRUE
;
3858 if (*recipients
& BSM_ALLDESKTOPS
|| *recipients
== BSM_ALLCOMPONENTS
)
3859 ret
= EnumWindowStationsW(bcast_winsta
, (LONG_PTR
)&parm
);
3860 else if (*recipients
& BSM_APPLICATIONS
)
3862 EnumWindows(bcast_childwindow
, (LONG_PTR
)&parm
);
3866 FIXME("Recipients %08x not supported!\n", *recipients
);
3871 /***********************************************************************
3872 * SetMessageQueue (USER32.@)
3874 BOOL WINAPI
SetMessageQueue( INT size
)
3876 /* now obsolete the message queue will be expanded dynamically as necessary */
3881 /***********************************************************************
3882 * MessageBeep (USER32.@)
3884 BOOL WINAPI
MessageBeep( UINT i
)
3887 SystemParametersInfoA( SPI_GETBEEP
, 0, &active
, FALSE
);
3888 if (active
) USER_Driver
->pBeep();
3893 /***********************************************************************
3894 * SetTimer (USER32.@)
3896 UINT_PTR WINAPI
SetTimer( HWND hwnd
, UINT_PTR id
, UINT timeout
, TIMERPROC proc
)
3899 WNDPROC winproc
= 0;
3901 if (proc
) winproc
= WINPROC_AllocProc( (WNDPROC
)proc
, FALSE
);
3903 SERVER_START_REQ( set_win_timer
)
3905 req
->win
= wine_server_user_handle( hwnd
);
3906 req
->msg
= WM_TIMER
;
3908 req
->rate
= max( timeout
, SYS_TIMER_RATE
);
3909 req
->lparam
= (ULONG_PTR
)winproc
;
3910 if (!wine_server_call_err( req
))
3913 if (!ret
) ret
= TRUE
;
3919 TRACE("Added %p %lx %p timeout %d\n", hwnd
, id
, winproc
, timeout
);
3924 /***********************************************************************
3925 * SetSystemTimer (USER32.@)
3927 UINT_PTR WINAPI
SetSystemTimer( HWND hwnd
, UINT_PTR id
, UINT timeout
, TIMERPROC proc
)
3930 WNDPROC winproc
= 0;
3932 if (proc
) winproc
= WINPROC_AllocProc( (WNDPROC
)proc
, FALSE
);
3934 SERVER_START_REQ( set_win_timer
)
3936 req
->win
= wine_server_user_handle( hwnd
);
3937 req
->msg
= WM_SYSTIMER
;
3939 req
->rate
= max( timeout
, SYS_TIMER_RATE
);
3940 req
->lparam
= (ULONG_PTR
)winproc
;
3941 if (!wine_server_call_err( req
))
3944 if (!ret
) ret
= TRUE
;
3950 TRACE("Added %p %lx %p timeout %d\n", hwnd
, id
, winproc
, timeout
);
3955 /***********************************************************************
3956 * KillTimer (USER32.@)
3958 BOOL WINAPI
KillTimer( HWND hwnd
, UINT_PTR id
)
3962 SERVER_START_REQ( kill_win_timer
)
3964 req
->win
= wine_server_user_handle( hwnd
);
3965 req
->msg
= WM_TIMER
;
3967 ret
= !wine_server_call_err( req
);
3974 /***********************************************************************
3975 * KillSystemTimer (USER32.@)
3977 BOOL WINAPI
KillSystemTimer( HWND hwnd
, UINT_PTR id
)
3981 SERVER_START_REQ( kill_win_timer
)
3983 req
->win
= wine_server_user_handle( hwnd
);
3984 req
->msg
= WM_SYSTIMER
;
3986 ret
= !wine_server_call_err( req
);
3993 /**********************************************************************
3994 * GetGUIThreadInfo (USER32.@)
3996 BOOL WINAPI
GetGUIThreadInfo( DWORD id
, GUITHREADINFO
*info
)
4000 SERVER_START_REQ( get_thread_input
)
4003 if ((ret
= !wine_server_call_err( req
)))
4006 info
->hwndActive
= wine_server_ptr_handle( reply
->active
);
4007 info
->hwndFocus
= wine_server_ptr_handle( reply
->focus
);
4008 info
->hwndCapture
= wine_server_ptr_handle( reply
->capture
);
4009 info
->hwndMenuOwner
= wine_server_ptr_handle( reply
->menu_owner
);
4010 info
->hwndMoveSize
= wine_server_ptr_handle( reply
->move_size
);
4011 info
->hwndCaret
= wine_server_ptr_handle( reply
->caret
);
4012 info
->rcCaret
.left
= reply
->rect
.left
;
4013 info
->rcCaret
.top
= reply
->rect
.top
;
4014 info
->rcCaret
.right
= reply
->rect
.right
;
4015 info
->rcCaret
.bottom
= reply
->rect
.bottom
;
4016 if (reply
->menu_owner
) info
->flags
|= GUI_INMENUMODE
;
4017 if (reply
->move_size
) info
->flags
|= GUI_INMOVESIZE
;
4018 if (reply
->caret
) info
->flags
|= GUI_CARETBLINKING
;
4026 /******************************************************************
4027 * IsHungAppWindow (USER32.@)
4030 BOOL WINAPI
IsHungAppWindow( HWND hWnd
)
4034 SERVER_START_REQ( is_window_hung
)
4036 req
->win
= wine_server_user_handle( hWnd
);
4037 ret
= !wine_server_call_err( req
) && reply
->is_hung
;
4043 /******************************************************************
4044 * ChangeWindowMessageFilter (USER32.@)
4046 BOOL WINAPI
ChangeWindowMessageFilter( UINT message
, DWORD flag
)
4048 FIXME( "%x %08x\n", message
, flag
);