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"
47 WINE_DEFAULT_DEBUG_CHANNEL(msg
);
48 WINE_DECLARE_DEBUG_CHANNEL(relay
);
49 WINE_DECLARE_DEBUG_CHANNEL(key
);
51 #define WM_NCMOUSEFIRST WM_NCMOUSEMOVE
52 #define WM_NCMOUSELAST (WM_NCMOUSEFIRST+(WM_MOUSELAST-WM_MOUSEFIRST))
54 #define MAX_PACK_COUNT 4
55 #define MAX_SENDMSG_RECURSION 64
57 #define SYS_TIMER_RATE 55 /* min. timer rate in ms (actually 54.925)*/
59 /* description of the data fields that need to be packed along with a sent message */
63 const void *data
[MAX_PACK_COUNT
];
64 size_t size
[MAX_PACK_COUNT
];
67 /* info about the message currently being received by the current thread */
68 struct received_message_info
70 enum message_type type
;
72 UINT flags
; /* InSendMessageEx return flags */
75 /* structure to group all parameters for sent messages of the various kinds */
76 struct send_message_info
78 enum message_type type
;
84 UINT flags
; /* flags for SendMessageTimeout */
85 UINT timeout
; /* timeout for SendMessageTimeout */
86 SENDASYNCPROC callback
; /* callback function for SendMessageCallback */
87 ULONG_PTR data
; /* callback data */
88 enum wm_char_mapping wm_char
;
92 /* flag for messages that contain pointers */
93 /* 32 messages per entry, messages 0..31 map to bits 0..31 */
95 #define SET(msg) (1 << ((msg) & 31))
97 static const unsigned int message_pointer_flags
[] =
100 SET(WM_CREATE
) | SET(WM_SETTEXT
) | SET(WM_GETTEXT
) |
101 SET(WM_WININICHANGE
) | SET(WM_DEVMODECHANGE
),
103 SET(WM_GETMINMAXINFO
) | SET(WM_DRAWITEM
) | SET(WM_MEASUREITEM
) | SET(WM_DELETEITEM
) |
106 SET(WM_WINDOWPOSCHANGING
) | SET(WM_WINDOWPOSCHANGED
) | SET(WM_COPYDATA
) |
107 SET(WM_NOTIFY
) | SET(WM_HELP
),
109 SET(WM_STYLECHANGING
) | SET(WM_STYLECHANGED
),
111 SET(WM_NCCREATE
) | SET(WM_NCCALCSIZE
) | SET(WM_GETDLGCODE
),
113 SET(EM_GETSEL
) | SET(EM_GETRECT
) | SET(EM_SETRECT
) | SET(EM_SETRECTNP
),
115 SET(EM_REPLACESEL
) | SET(EM_GETLINE
) | SET(EM_SETTABSTOPS
),
117 SET(SBM_GETRANGE
) | SET(SBM_SETSCROLLINFO
) | SET(SBM_GETSCROLLINFO
) | SET(SBM_GETSCROLLBARINFO
),
123 SET(CB_GETEDITSEL
) | SET(CB_ADDSTRING
) | SET(CB_DIR
) | SET(CB_GETLBTEXT
) |
124 SET(CB_INSERTSTRING
) | SET(CB_FINDSTRING
) | SET(CB_SELECTSTRING
) |
125 SET(CB_GETDROPPEDCONTROLRECT
) | SET(CB_FINDSTRINGEXACT
),
129 SET(LB_ADDSTRING
) | SET(LB_INSERTSTRING
) | SET(LB_GETTEXT
) | SET(LB_SELECTSTRING
) |
130 SET(LB_DIR
) | SET(LB_FINDSTRING
) |
131 SET(LB_GETSELITEMS
) | SET(LB_SETTABSTOPS
) | SET(LB_ADDFILE
) | SET(LB_GETITEMRECT
),
133 SET(LB_FINDSTRINGEXACT
),
139 SET(WM_NEXTMENU
) | SET(WM_SIZING
) | SET(WM_MOVING
) | SET(WM_DEVICECHANGE
),
141 SET(WM_MDICREATE
) | SET(WM_MDIGETACTIVE
) | SET(WM_DROPOBJECT
) |
142 SET(WM_QUERYDROPOBJECT
) | SET(WM_DRAGLOOP
) | SET(WM_DRAGSELECT
) | SET(WM_DRAGMOVE
),
156 SET(WM_ASKCBFORMATNAME
)
159 /* flags for messages that contain Unicode strings */
160 static const unsigned int message_unicode_flags
[] =
163 SET(WM_CREATE
) | SET(WM_SETTEXT
) | SET(WM_GETTEXT
) | SET(WM_GETTEXTLENGTH
) |
164 SET(WM_WININICHANGE
) | SET(WM_DEVMODECHANGE
),
176 SET(EM_REPLACESEL
) | SET(EM_GETLINE
) | SET(EM_SETPASSWORDCHAR
),
180 SET(WM_CHAR
) | SET(WM_DEADCHAR
) | SET(WM_SYSCHAR
) | SET(WM_SYSDEADCHAR
),
184 SET(CB_ADDSTRING
) | SET(CB_DIR
) | SET(CB_GETLBTEXT
) | SET(CB_GETLBTEXTLEN
) |
185 SET(CB_INSERTSTRING
) | SET(CB_FINDSTRING
) | SET(CB_SELECTSTRING
) | SET(CB_FINDSTRINGEXACT
),
189 SET(LB_ADDSTRING
) | SET(LB_INSERTSTRING
) | SET(LB_GETTEXT
) | SET(LB_GETTEXTLEN
) |
190 SET(LB_SELECTSTRING
) | SET(LB_DIR
) | SET(LB_FINDSTRING
) | SET(LB_ADDFILE
),
192 SET(LB_FINDSTRINGEXACT
),
214 SET(WM_PAINTCLIPBOARD
) | SET(WM_SIZECLIPBOARD
) | SET(WM_ASKCBFORMATNAME
)
217 /* check whether a given message type includes pointers */
218 static inline int is_pointer_message( UINT message
)
220 if (message
>= 8*sizeof(message_pointer_flags
)) return FALSE
;
221 return (message_pointer_flags
[message
/ 32] & SET(message
)) != 0;
224 /* check whether a given message type contains Unicode (or ASCII) chars */
225 static inline int is_unicode_message( UINT message
)
227 if (message
>= 8*sizeof(message_unicode_flags
)) return FALSE
;
228 return (message_unicode_flags
[message
/ 32] & SET(message
)) != 0;
233 /* add a data field to a packed message */
234 static inline void push_data( struct packed_message
*data
, const void *ptr
, size_t size
)
236 data
->data
[data
->count
] = ptr
;
237 data
->size
[data
->count
] = size
;
241 /* add a string to a packed message */
242 static inline void push_string( struct packed_message
*data
, LPCWSTR str
)
244 push_data( data
, str
, (strlenW(str
) + 1) * sizeof(WCHAR
) );
247 /* retrieve a pointer to data from a packed message and increment the buffer pointer */
248 static inline void *get_data( void **buffer
, size_t size
)
251 *buffer
= (char *)*buffer
+ size
;
255 /* make sure that the buffer contains a valid null-terminated Unicode string */
256 static inline BOOL
check_string( LPCWSTR str
, size_t size
)
258 for (size
/= sizeof(WCHAR
); size
; size
--, str
++)
259 if (!*str
) return TRUE
;
263 /* make sure that there is space for 'size' bytes in buffer, growing it if needed */
264 static inline void *get_buffer_space( void **buffer
, size_t size
)
270 if (!(ret
= HeapReAlloc( GetProcessHeap(), 0, *buffer
, size
)))
271 HeapFree( GetProcessHeap(), 0, *buffer
);
273 else ret
= HeapAlloc( GetProcessHeap(), 0, size
);
279 /* check whether a combobox expects strings or ids in CB_ADDSTRING/CB_INSERTSTRING */
280 static inline BOOL
combobox_has_strings( HWND hwnd
)
282 DWORD style
= GetWindowLongA( hwnd
, GWL_STYLE
);
283 return (!(style
& (CBS_OWNERDRAWFIXED
| CBS_OWNERDRAWVARIABLE
)) || (style
& CBS_HASSTRINGS
));
286 /* check whether a listbox expects strings or ids in LB_ADDSTRING/LB_INSERTSTRING */
287 static inline BOOL
listbox_has_strings( HWND hwnd
)
289 DWORD style
= GetWindowLongA( hwnd
, GWL_STYLE
);
290 return (!(style
& (LBS_OWNERDRAWFIXED
| LBS_OWNERDRAWVARIABLE
)) || (style
& LBS_HASSTRINGS
));
293 /* check whether message is in the range of keyboard messages */
294 static inline BOOL
is_keyboard_message( UINT message
)
296 return (message
>= WM_KEYFIRST
&& message
<= WM_KEYLAST
);
299 /* check whether message is in the range of mouse messages */
300 static inline BOOL
is_mouse_message( UINT message
)
302 return ((message
>= WM_NCMOUSEFIRST
&& message
<= WM_NCMOUSELAST
) ||
303 (message
>= WM_MOUSEFIRST
&& message
<= WM_MOUSELAST
));
306 /* check whether message matches the specified hwnd filter */
307 static inline BOOL
check_hwnd_filter( const MSG
*msg
, HWND hwnd_filter
)
309 if (!hwnd_filter
|| hwnd_filter
== GetDesktopWindow()) return TRUE
;
310 return (msg
->hwnd
== hwnd_filter
|| IsChild( hwnd_filter
, msg
->hwnd
));
313 /* check for pending WM_CHAR message with DBCS trailing byte */
314 static inline BOOL
get_pending_wmchar( MSG
*msg
, UINT first
, UINT last
, BOOL remove
)
316 struct wm_char_mapping_data
*data
= get_user_thread_info()->wmchar_data
;
318 if (!data
|| !data
->get_msg
.message
) return FALSE
;
319 if ((first
|| last
) && (first
> WM_CHAR
|| last
< WM_CHAR
)) return FALSE
;
320 if (!msg
) return FALSE
;
321 *msg
= data
->get_msg
;
322 if (remove
) data
->get_msg
.message
= 0;
326 /***********************************************************************
327 * broadcast_message_callback
329 * Helper callback for broadcasting messages.
331 static BOOL CALLBACK
broadcast_message_callback( HWND hwnd
, LPARAM lparam
)
333 struct send_message_info
*info
= (struct send_message_info
*)lparam
;
334 if (!(GetWindowLongW( hwnd
, GWL_STYLE
) & (WS_POPUP
|WS_CAPTION
))) return TRUE
;
338 SendMessageTimeoutW( hwnd
, info
->msg
, info
->wparam
, info
->lparam
,
339 info
->flags
, info
->timeout
, NULL
);
342 SendMessageTimeoutA( hwnd
, info
->msg
, info
->wparam
, info
->lparam
,
343 info
->flags
, info
->timeout
, NULL
);
346 SendNotifyMessageW( hwnd
, info
->msg
, info
->wparam
, info
->lparam
);
349 SendMessageCallbackW( hwnd
, info
->msg
, info
->wparam
, info
->lparam
,
350 info
->callback
, info
->data
);
353 PostMessageW( hwnd
, info
->msg
, info
->wparam
, info
->lparam
);
356 ERR( "bad type %d\n", info
->type
);
363 /***********************************************************************
366 * Convert the wparam of an ASCII message to Unicode.
368 BOOL
map_wparam_AtoW( UINT message
, WPARAM
*wparam
, enum wm_char_mapping mapping
)
377 /* WM_CHAR is magic: a DBCS char can be sent/posted as two consecutive WM_CHAR
378 * messages, in which case the first char is stored, and the conversion
379 * to Unicode only takes place once the second char is sent/posted.
381 if (mapping
!= WMCHAR_MAP_NOMAPPING
)
383 struct wm_char_mapping_data
*data
= get_user_thread_info()->wmchar_data
;
384 BYTE low
= LOBYTE(*wparam
);
389 ch
[1] = HIBYTE(*wparam
);
390 RtlMultiByteToUnicodeN( wch
, sizeof(wch
), NULL
, ch
, 2 );
391 TRACE( "map %02x,%02x -> %04x mapping %u\n", (BYTE
)ch
[0], (BYTE
)ch
[1], wch
[0], mapping
);
392 if (data
) data
->lead_byte
[mapping
] = 0;
394 else if (data
&& data
->lead_byte
[mapping
])
396 ch
[0] = data
->lead_byte
[mapping
];
398 RtlMultiByteToUnicodeN( wch
, sizeof(wch
), NULL
, ch
, 2 );
399 TRACE( "map stored %02x,%02x -> %04x mapping %u\n", (BYTE
)ch
[0], (BYTE
)ch
[1], wch
[0], mapping
);
400 data
->lead_byte
[mapping
] = 0;
402 else if (!IsDBCSLeadByte( low
))
405 RtlMultiByteToUnicodeN( wch
, sizeof(wch
), NULL
, ch
, 1 );
406 TRACE( "map %02x -> %04x\n", (BYTE
)ch
[0], wch
[0] );
407 if (data
) data
->lead_byte
[mapping
] = 0;
409 else /* store it and wait for trail byte */
413 if (!(data
= HeapAlloc( GetProcessHeap(), HEAP_ZERO_MEMORY
, sizeof(*data
) )))
415 get_user_thread_info()->wmchar_data
= data
;
417 TRACE( "storing lead byte %02x mapping %u\n", low
, mapping
);
418 data
->lead_byte
[mapping
] = low
;
421 *wparam
= MAKEWPARAM(wch
[0], wch
[1]);
424 /* else fall through */
426 case EM_SETPASSWORDCHAR
:
431 ch
[0] = LOBYTE(*wparam
);
432 ch
[1] = HIBYTE(*wparam
);
433 RtlMultiByteToUnicodeN( wch
, sizeof(wch
), NULL
, ch
, 2 );
434 *wparam
= MAKEWPARAM(wch
[0], wch
[1]);
437 ch
[0] = HIBYTE(*wparam
);
438 ch
[1] = LOBYTE(*wparam
);
439 if (ch
[0]) RtlMultiByteToUnicodeN( wch
, sizeof(wch
[0]), NULL
, ch
, 2 );
440 else RtlMultiByteToUnicodeN( wch
, sizeof(wch
[0]), NULL
, ch
+ 1, 1 );
441 *wparam
= MAKEWPARAM(wch
[0], HIWORD(*wparam
));
448 /***********************************************************************
451 * Convert the wparam of a Unicode message to ASCII.
453 static void map_wparam_WtoA( MSG
*msg
, BOOL remove
)
462 if (!HIWORD(msg
->wParam
))
464 wch
[0] = LOWORD(msg
->wParam
);
466 RtlUnicodeToMultiByteN( (LPSTR
)ch
, 2, &len
, wch
, sizeof(wch
[0]) );
467 if (len
== 2) /* DBCS char */
469 struct wm_char_mapping_data
*data
= get_user_thread_info()->wmchar_data
;
472 if (!(data
= HeapAlloc( GetProcessHeap(), HEAP_ZERO_MEMORY
, sizeof(*data
) ))) return;
473 get_user_thread_info()->wmchar_data
= data
;
477 data
->get_msg
= *msg
;
478 data
->get_msg
.wParam
= ch
[1];
484 /* else fall through */
486 case EM_SETPASSWORDCHAR
:
491 wch
[0] = LOWORD(msg
->wParam
);
492 wch
[1] = HIWORD(msg
->wParam
);
494 RtlUnicodeToMultiByteN( (LPSTR
)ch
, 2, NULL
, wch
, sizeof(wch
) );
495 msg
->wParam
= MAKEWPARAM( ch
[0] | (ch
[1] << 8), 0 );
498 wch
[0] = LOWORD(msg
->wParam
);
500 RtlUnicodeToMultiByteN( (LPSTR
)ch
, 2, &len
, wch
, sizeof(wch
[0]) );
502 msg
->wParam
= MAKEWPARAM( (ch
[0] << 8) | ch
[1], HIWORD(msg
->wParam
) );
504 msg
->wParam
= MAKEWPARAM( ch
[0], HIWORD(msg
->wParam
) );
510 /***********************************************************************
513 * Pack a message for sending to another process.
514 * Return the size of the data we expect in the message reply.
515 * Set data->count to -1 if there is an error.
517 static size_t pack_message( HWND hwnd
, UINT message
, WPARAM wparam
, LPARAM lparam
,
518 struct packed_message
*data
)
526 CREATESTRUCTW
*cs
= (CREATESTRUCTW
*)lparam
;
527 push_data( data
, cs
, sizeof(*cs
) );
528 if (HIWORD(cs
->lpszName
)) push_string( data
, cs
->lpszName
);
529 if (HIWORD(cs
->lpszClass
)) push_string( data
, cs
->lpszClass
);
533 case WM_ASKCBFORMATNAME
:
534 return wparam
* sizeof(WCHAR
);
535 case WM_WININICHANGE
:
536 if (lparam
) push_string(data
, (LPWSTR
)lparam
);
539 case WM_DEVMODECHANGE
:
544 push_string( data
, (LPWSTR
)lparam
);
546 case WM_GETMINMAXINFO
:
547 push_data( data
, (MINMAXINFO
*)lparam
, sizeof(MINMAXINFO
) );
548 return sizeof(MINMAXINFO
);
550 push_data( data
, (DRAWITEMSTRUCT
*)lparam
, sizeof(DRAWITEMSTRUCT
) );
553 push_data( data
, (MEASUREITEMSTRUCT
*)lparam
, sizeof(MEASUREITEMSTRUCT
) );
554 return sizeof(MEASUREITEMSTRUCT
);
556 push_data( data
, (DELETEITEMSTRUCT
*)lparam
, sizeof(DELETEITEMSTRUCT
) );
559 push_data( data
, (COMPAREITEMSTRUCT
*)lparam
, sizeof(COMPAREITEMSTRUCT
) );
561 case WM_WINDOWPOSCHANGING
:
562 case WM_WINDOWPOSCHANGED
:
563 push_data( data
, (WINDOWPOS
*)lparam
, sizeof(WINDOWPOS
) );
564 return sizeof(WINDOWPOS
);
567 COPYDATASTRUCT
*cp
= (COPYDATASTRUCT
*)lparam
;
568 push_data( data
, cp
, sizeof(*cp
) );
569 if (cp
->lpData
) push_data( data
, cp
->lpData
, cp
->cbData
);
573 /* WM_NOTIFY cannot be sent across processes (MSDN) */
577 push_data( data
, (HELPINFO
*)lparam
, sizeof(HELPINFO
) );
579 case WM_STYLECHANGING
:
580 case WM_STYLECHANGED
:
581 push_data( data
, (STYLESTRUCT
*)lparam
, sizeof(STYLESTRUCT
) );
586 push_data( data
, (RECT
*)lparam
, sizeof(RECT
) );
591 NCCALCSIZE_PARAMS
*nc
= (NCCALCSIZE_PARAMS
*)lparam
;
592 push_data( data
, nc
, sizeof(*nc
) );
593 push_data( data
, nc
->lppos
, sizeof(*nc
->lppos
) );
594 return sizeof(*nc
) + sizeof(*nc
->lppos
);
597 if (lparam
) push_data( data
, (MSG
*)lparam
, sizeof(MSG
) );
599 case SBM_SETSCROLLINFO
:
600 push_data( data
, (SCROLLINFO
*)lparam
, sizeof(SCROLLINFO
) );
602 case SBM_GETSCROLLINFO
:
603 push_data( data
, (SCROLLINFO
*)lparam
, sizeof(SCROLLINFO
) );
604 return sizeof(SCROLLINFO
);
605 case SBM_GETSCROLLBARINFO
:
607 const SCROLLBARINFO
*info
= (const SCROLLBARINFO
*)lparam
;
608 size_t size
= min( info
->cbSize
, sizeof(SCROLLBARINFO
) );
609 push_data( data
, info
, size
);
617 if (wparam
) size
+= sizeof(DWORD
);
618 if (lparam
) size
+= sizeof(DWORD
);
623 case CB_GETDROPPEDCONTROLRECT
:
627 push_data( data
, (RECT
*)lparam
, sizeof(RECT
) );
631 WORD
*pw
= (WORD
*)lparam
;
632 push_data( data
, pw
, sizeof(*pw
) );
633 return *pw
* sizeof(WCHAR
);
637 if (wparam
) push_data( data
, (UINT
*)lparam
, sizeof(UINT
) * wparam
);
640 case CB_INSERTSTRING
:
642 case CB_FINDSTRINGEXACT
:
643 case CB_SELECTSTRING
:
644 if (combobox_has_strings( hwnd
)) push_string( data
, (LPWSTR
)lparam
);
647 if (!combobox_has_strings( hwnd
)) return sizeof(ULONG_PTR
);
648 return (SendMessageW( hwnd
, CB_GETLBTEXTLEN
, wparam
, 0 ) + 1) * sizeof(WCHAR
);
650 case LB_INSERTSTRING
:
652 case LB_FINDSTRINGEXACT
:
653 case LB_SELECTSTRING
:
654 if (listbox_has_strings( hwnd
)) push_string( data
, (LPWSTR
)lparam
);
657 if (!listbox_has_strings( hwnd
)) return sizeof(ULONG_PTR
);
658 return (SendMessageW( hwnd
, LB_GETTEXTLEN
, wparam
, 0 ) + 1) * sizeof(WCHAR
);
660 return wparam
* sizeof(UINT
);
662 push_data( data
, (MDINEXTMENU
*)lparam
, sizeof(MDINEXTMENU
) );
663 return sizeof(MDINEXTMENU
);
666 push_data( data
, (RECT
*)lparam
, sizeof(RECT
) );
670 MDICREATESTRUCTW
*cs
= (MDICREATESTRUCTW
*)lparam
;
671 push_data( data
, cs
, sizeof(*cs
) );
672 if (HIWORD(cs
->szTitle
)) push_string( data
, cs
->szTitle
);
673 if (HIWORD(cs
->szClass
)) push_string( data
, cs
->szClass
);
676 case WM_MDIGETACTIVE
:
677 if (lparam
) return sizeof(BOOL
);
679 case WM_DEVICECHANGE
:
681 DEV_BROADCAST_HDR
*header
= (DEV_BROADCAST_HDR
*)lparam
;
682 push_data( data
, header
, header
->dbch_size
);
685 case WM_WINE_SETWINDOWPOS
:
686 push_data( data
, (WINDOWPOS
*)lparam
, sizeof(WINDOWPOS
) );
688 case WM_WINE_KEYBOARD_LL_HOOK
:
690 struct hook_extra_info
*h_extra
= (struct hook_extra_info
*)lparam
;
691 push_data( data
, h_extra
, sizeof(*h_extra
) );
692 push_data( data
, (LPVOID
)h_extra
->lparam
, sizeof(KBDLLHOOKSTRUCT
) );
695 case WM_WINE_MOUSE_LL_HOOK
:
697 struct hook_extra_info
*h_extra
= (struct hook_extra_info
*)lparam
;
698 push_data( data
, h_extra
, sizeof(*h_extra
) );
699 push_data( data
, (LPVOID
)h_extra
->lparam
, sizeof(MSLLHOOKSTRUCT
) );
703 if (wparam
<= 1) return 0;
704 FIXME( "WM_NCPAINT hdc packing not supported yet\n" );
708 if (!wparam
) return 0;
711 /* these contain an HFONT */
714 /* these contain an HDC */
716 case WM_ICONERASEBKGND
:
717 case WM_CTLCOLORMSGBOX
:
718 case WM_CTLCOLOREDIT
:
719 case WM_CTLCOLORLISTBOX
:
722 case WM_CTLCOLORSCROLLBAR
:
723 case WM_CTLCOLORSTATIC
:
726 /* these contain an HGLOBAL */
727 case WM_PAINTCLIPBOARD
:
728 case WM_SIZECLIPBOARD
:
729 /* these contain HICON */
732 case WM_QUERYDRAGICON
:
733 case WM_QUERYPARKICON
:
734 /* these contain pointers */
736 case WM_QUERYDROPOBJECT
:
740 FIXME( "msg %x (%s) not supported yet\n", message
, SPY_GetMsgName(message
, hwnd
) );
748 /***********************************************************************
751 * Unpack a message received from another process.
753 static BOOL
unpack_message( HWND hwnd
, UINT message
, WPARAM
*wparam
, LPARAM
*lparam
,
754 void **buffer
, size_t size
)
763 CREATESTRUCTW
*cs
= *buffer
;
764 WCHAR
*str
= (WCHAR
*)(cs
+ 1);
765 if (size
< sizeof(*cs
)) return FALSE
;
767 if (HIWORD(cs
->lpszName
))
769 if (!check_string( str
, size
)) return FALSE
;
771 size
-= (strlenW(str
) + 1) * sizeof(WCHAR
);
772 str
+= strlenW(str
) + 1;
774 if (HIWORD(cs
->lpszClass
))
776 if (!check_string( str
, size
)) return FALSE
;
782 case WM_ASKCBFORMATNAME
:
783 if (!get_buffer_space( buffer
, (*wparam
* sizeof(WCHAR
)) )) return FALSE
;
785 case WM_WININICHANGE
:
786 if (!*lparam
) return TRUE
;
789 case WM_DEVMODECHANGE
:
794 if (!check_string( *buffer
, size
)) return FALSE
;
796 case WM_GETMINMAXINFO
:
797 minsize
= sizeof(MINMAXINFO
);
800 minsize
= sizeof(DRAWITEMSTRUCT
);
803 minsize
= sizeof(MEASUREITEMSTRUCT
);
806 minsize
= sizeof(DELETEITEMSTRUCT
);
809 minsize
= sizeof(COMPAREITEMSTRUCT
);
811 case WM_WINDOWPOSCHANGING
:
812 case WM_WINDOWPOSCHANGED
:
813 case WM_WINE_SETWINDOWPOS
:
814 minsize
= sizeof(WINDOWPOS
);
818 COPYDATASTRUCT
*cp
= *buffer
;
819 if (size
< sizeof(*cp
)) return FALSE
;
822 minsize
= sizeof(*cp
) + cp
->cbData
;
828 /* WM_NOTIFY cannot be sent across processes (MSDN) */
831 minsize
= sizeof(HELPINFO
);
833 case WM_STYLECHANGING
:
834 case WM_STYLECHANGED
:
835 minsize
= sizeof(STYLESTRUCT
);
838 if (!*wparam
) minsize
= sizeof(RECT
);
841 NCCALCSIZE_PARAMS
*nc
= *buffer
;
842 if (size
< sizeof(*nc
) + sizeof(*nc
->lppos
)) return FALSE
;
843 nc
->lppos
= (WINDOWPOS
*)(nc
+ 1);
847 if (!*lparam
) return TRUE
;
848 minsize
= sizeof(MSG
);
850 case SBM_SETSCROLLINFO
:
851 minsize
= sizeof(SCROLLINFO
);
853 case SBM_GETSCROLLINFO
:
854 if (!get_buffer_space( buffer
, sizeof(SCROLLINFO
))) return FALSE
;
856 case SBM_GETSCROLLBARINFO
:
857 if (!get_buffer_space( buffer
, sizeof(SCROLLBARINFO
))) return FALSE
;
862 if (*wparam
|| *lparam
)
864 if (!get_buffer_space( buffer
, 2*sizeof(DWORD
) )) return FALSE
;
865 if (*wparam
) *wparam
= (WPARAM
)*buffer
;
866 if (*lparam
) *lparam
= (LPARAM
)((DWORD
*)*buffer
+ 1);
871 case CB_GETDROPPEDCONTROLRECT
:
872 if (!get_buffer_space( buffer
, sizeof(RECT
) )) return FALSE
;
876 minsize
= sizeof(RECT
);
881 if (size
< sizeof(WORD
)) return FALSE
;
882 len
= *(WORD
*)*buffer
;
883 if (!get_buffer_space( buffer
, (len
+ 1) * sizeof(WCHAR
) )) return FALSE
;
884 *lparam
= (LPARAM
)*buffer
+ sizeof(WORD
); /* don't erase WORD at start of buffer */
889 if (!*wparam
) return TRUE
;
890 minsize
= *wparam
* sizeof(UINT
);
893 case CB_INSERTSTRING
:
895 case CB_FINDSTRINGEXACT
:
896 case CB_SELECTSTRING
:
898 case LB_INSERTSTRING
:
900 case LB_FINDSTRINGEXACT
:
901 case LB_SELECTSTRING
:
902 if (!*buffer
) return TRUE
;
903 if (!check_string( *buffer
, size
)) return FALSE
;
907 size
= sizeof(ULONG_PTR
);
908 if (combobox_has_strings( hwnd
))
909 size
= (SendMessageW( hwnd
, CB_GETLBTEXTLEN
, *wparam
, 0 ) + 1) * sizeof(WCHAR
);
910 if (!get_buffer_space( buffer
, size
)) return FALSE
;
915 size
= sizeof(ULONG_PTR
);
916 if (listbox_has_strings( hwnd
))
917 size
= (SendMessageW( hwnd
, LB_GETTEXTLEN
, *wparam
, 0 ) + 1) * sizeof(WCHAR
);
918 if (!get_buffer_space( buffer
, size
)) return FALSE
;
922 if (!get_buffer_space( buffer
, *wparam
* sizeof(UINT
) )) return FALSE
;
925 minsize
= sizeof(MDINEXTMENU
);
926 if (!get_buffer_space( buffer
, sizeof(MDINEXTMENU
) )) return FALSE
;
930 minsize
= sizeof(RECT
);
931 if (!get_buffer_space( buffer
, sizeof(RECT
) )) return FALSE
;
935 MDICREATESTRUCTW
*cs
= *buffer
;
936 WCHAR
*str
= (WCHAR
*)(cs
+ 1);
937 if (size
< sizeof(*cs
)) return FALSE
;
939 if (HIWORD(cs
->szTitle
))
941 if (!check_string( str
, size
)) return FALSE
;
943 size
-= (strlenW(str
) + 1) * sizeof(WCHAR
);
944 str
+= strlenW(str
) + 1;
946 if (HIWORD(cs
->szClass
))
948 if (!check_string( str
, size
)) return FALSE
;
953 case WM_MDIGETACTIVE
:
954 if (!*lparam
) return TRUE
;
955 if (!get_buffer_space( buffer
, sizeof(BOOL
) )) return FALSE
;
957 case WM_DEVICECHANGE
:
958 minsize
= sizeof(DEV_BROADCAST_HDR
);
960 case WM_WINE_KEYBOARD_LL_HOOK
:
961 case WM_WINE_MOUSE_LL_HOOK
:
963 struct hook_extra_info
*h_extra
= (struct hook_extra_info
*)*buffer
;
965 minsize
= sizeof(struct hook_extra_info
) +
966 (message
== WM_WINE_KEYBOARD_LL_HOOK
? sizeof(KBDLLHOOKSTRUCT
)
967 : sizeof(MSLLHOOKSTRUCT
));
968 if (size
< minsize
) return FALSE
;
969 h_extra
->lparam
= (LPARAM
)(h_extra
+ 1);
973 if (*wparam
<= 1) return TRUE
;
974 FIXME( "WM_NCPAINT hdc unpacking not supported\n" );
977 if (!*wparam
) return TRUE
;
980 /* these contain an HFONT */
983 /* these contain an HDC */
985 case WM_ICONERASEBKGND
:
986 case WM_CTLCOLORMSGBOX
:
987 case WM_CTLCOLOREDIT
:
988 case WM_CTLCOLORLISTBOX
:
991 case WM_CTLCOLORSCROLLBAR
:
992 case WM_CTLCOLORSTATIC
:
995 /* these contain an HGLOBAL */
996 case WM_PAINTCLIPBOARD
:
997 case WM_SIZECLIPBOARD
:
998 /* these contain HICON */
1001 case WM_QUERYDRAGICON
:
1002 case WM_QUERYPARKICON
:
1003 /* these contain pointers */
1005 case WM_QUERYDROPOBJECT
:
1009 FIXME( "msg %x (%s) not supported yet\n", message
, SPY_GetMsgName(message
, hwnd
) );
1013 return TRUE
; /* message doesn't need any unpacking */
1016 /* default exit for most messages: check minsize and store buffer in lparam */
1017 if (size
< minsize
) return FALSE
;
1018 *lparam
= (LPARAM
)*buffer
;
1023 /***********************************************************************
1026 * Pack a reply to a message for sending to another process.
1028 static void pack_reply( HWND hwnd
, UINT message
, WPARAM wparam
, LPARAM lparam
,
1029 LRESULT res
, struct packed_message
*data
)
1036 push_data( data
, (CREATESTRUCTW
*)lparam
, sizeof(CREATESTRUCTW
) );
1041 push_data( data
, (WCHAR
*)lparam
, (res
+ 1) * sizeof(WCHAR
) );
1043 case WM_GETMINMAXINFO
:
1044 push_data( data
, (MINMAXINFO
*)lparam
, sizeof(MINMAXINFO
) );
1046 case WM_MEASUREITEM
:
1047 push_data( data
, (MEASUREITEMSTRUCT
*)lparam
, sizeof(MEASUREITEMSTRUCT
) );
1049 case WM_WINDOWPOSCHANGING
:
1050 case WM_WINDOWPOSCHANGED
:
1051 push_data( data
, (WINDOWPOS
*)lparam
, sizeof(WINDOWPOS
) );
1054 if (lparam
) push_data( data
, (MSG
*)lparam
, sizeof(MSG
) );
1056 case SBM_GETSCROLLINFO
:
1057 push_data( data
, (SCROLLINFO
*)lparam
, sizeof(SCROLLINFO
) );
1060 case LB_GETITEMRECT
:
1061 case CB_GETDROPPEDCONTROLRECT
:
1064 push_data( data
, (RECT
*)lparam
, sizeof(RECT
) );
1068 WORD
*ptr
= (WORD
*)lparam
;
1069 push_data( data
, ptr
, ptr
[-1] * sizeof(WCHAR
) );
1072 case LB_GETSELITEMS
:
1073 push_data( data
, (UINT
*)lparam
, wparam
* sizeof(UINT
) );
1075 case WM_MDIGETACTIVE
:
1076 if (lparam
) push_data( data
, (BOOL
*)lparam
, sizeof(BOOL
) );
1080 push_data( data
, (RECT
*)lparam
, sizeof(RECT
) );
1083 NCCALCSIZE_PARAMS
*nc
= (NCCALCSIZE_PARAMS
*)lparam
;
1084 push_data( data
, nc
, sizeof(*nc
) );
1085 push_data( data
, nc
->lppos
, sizeof(*nc
->lppos
) );
1091 if (wparam
) push_data( data
, (DWORD
*)wparam
, sizeof(DWORD
) );
1092 if (lparam
) push_data( data
, (DWORD
*)lparam
, sizeof(DWORD
) );
1095 push_data( data
, (MDINEXTMENU
*)lparam
, sizeof(MDINEXTMENU
) );
1098 push_data( data
, (MDICREATESTRUCTW
*)lparam
, sizeof(MDICREATESTRUCTW
) );
1100 case WM_ASKCBFORMATNAME
:
1101 push_data( data
, (WCHAR
*)lparam
, (strlenW((WCHAR
*)lparam
) + 1) * sizeof(WCHAR
) );
1107 /***********************************************************************
1110 * Unpack a message reply received from another process.
1112 static void unpack_reply( HWND hwnd
, UINT message
, WPARAM wparam
, LPARAM lparam
,
1113 void *buffer
, size_t size
)
1120 CREATESTRUCTW
*cs
= (CREATESTRUCTW
*)lparam
;
1121 LPCWSTR name
= cs
->lpszName
, class = cs
->lpszClass
;
1122 memcpy( cs
, buffer
, min( sizeof(*cs
), size
));
1123 cs
->lpszName
= name
; /* restore the original pointers */
1124 cs
->lpszClass
= class;
1128 case WM_ASKCBFORMATNAME
:
1129 memcpy( (WCHAR
*)lparam
, buffer
, min( wparam
*sizeof(WCHAR
), size
));
1131 case WM_GETMINMAXINFO
:
1132 memcpy( (MINMAXINFO
*)lparam
, buffer
, min( sizeof(MINMAXINFO
), size
));
1134 case WM_MEASUREITEM
:
1135 memcpy( (MEASUREITEMSTRUCT
*)lparam
, buffer
, min( sizeof(MEASUREITEMSTRUCT
), size
));
1137 case WM_WINDOWPOSCHANGING
:
1138 case WM_WINDOWPOSCHANGED
:
1139 memcpy( (WINDOWPOS
*)lparam
, buffer
, min( sizeof(WINDOWPOS
), size
));
1142 if (lparam
) memcpy( (MSG
*)lparam
, buffer
, min( sizeof(MSG
), size
));
1144 case SBM_GETSCROLLINFO
:
1145 memcpy( (SCROLLINFO
*)lparam
, buffer
, min( sizeof(SCROLLINFO
), size
));
1147 case SBM_GETSCROLLBARINFO
:
1148 memcpy( (SCROLLBARINFO
*)lparam
, buffer
, min( sizeof(SCROLLBARINFO
), size
));
1151 case CB_GETDROPPEDCONTROLRECT
:
1152 case LB_GETITEMRECT
:
1155 memcpy( (RECT
*)lparam
, buffer
, min( sizeof(RECT
), size
));
1158 size
= min( size
, (size_t)*(WORD
*)lparam
);
1159 memcpy( (WCHAR
*)lparam
, buffer
, size
);
1161 case LB_GETSELITEMS
:
1162 memcpy( (UINT
*)lparam
, buffer
, min( wparam
*sizeof(UINT
), size
));
1166 memcpy( (WCHAR
*)lparam
, buffer
, size
);
1169 memcpy( (MDINEXTMENU
*)lparam
, buffer
, min( sizeof(MDINEXTMENU
), size
));
1171 case WM_MDIGETACTIVE
:
1172 if (lparam
) memcpy( (BOOL
*)lparam
, buffer
, min( sizeof(BOOL
), size
));
1176 memcpy( (RECT
*)lparam
, buffer
, min( sizeof(RECT
), size
));
1179 NCCALCSIZE_PARAMS
*nc
= (NCCALCSIZE_PARAMS
*)lparam
;
1180 WINDOWPOS
*wp
= nc
->lppos
;
1181 memcpy( nc
, buffer
, min( sizeof(*nc
), size
));
1182 if (size
> sizeof(*nc
))
1184 size
-= sizeof(*nc
);
1185 memcpy( wp
, (NCCALCSIZE_PARAMS
*)buffer
+ 1, min( sizeof(*wp
), size
));
1187 nc
->lppos
= wp
; /* restore the original pointer */
1195 memcpy( (DWORD
*)wparam
, buffer
, min( sizeof(DWORD
), size
));
1196 if (size
<= sizeof(DWORD
)) break;
1197 size
-= sizeof(DWORD
);
1198 buffer
= (DWORD
*)buffer
+ 1;
1200 if (lparam
) memcpy( (DWORD
*)lparam
, buffer
, min( sizeof(DWORD
), size
));
1204 MDICREATESTRUCTW
*cs
= (MDICREATESTRUCTW
*)lparam
;
1205 LPCWSTR title
= cs
->szTitle
, class = cs
->szClass
;
1206 memcpy( cs
, buffer
, min( sizeof(*cs
), size
));
1207 cs
->szTitle
= title
; /* restore the original pointers */
1208 cs
->szClass
= class;
1212 ERR( "should not happen: unexpected message %x\n", message
);
1218 /***********************************************************************
1221 * Send a reply to a sent message.
1223 static void reply_message( struct received_message_info
*info
, LRESULT result
, BOOL remove
)
1225 struct packed_message data
;
1226 int i
, replied
= info
->flags
& ISMEX_REPLIED
;
1228 if (info
->flags
& ISMEX_NOTIFY
) return; /* notify messages don't get replies */
1229 if (!remove
&& replied
) return; /* replied already */
1232 info
->flags
|= ISMEX_REPLIED
;
1234 if (info
->type
== MSG_OTHER_PROCESS
&& !replied
)
1236 pack_reply( info
->msg
.hwnd
, info
->msg
.message
, info
->msg
.wParam
,
1237 info
->msg
.lParam
, result
, &data
);
1240 SERVER_START_REQ( reply_message
)
1242 req
->result
= result
;
1243 req
->remove
= remove
;
1244 for (i
= 0; i
< data
.count
; i
++) wine_server_add_data( req
, data
.data
[i
], data
.size
[i
] );
1245 wine_server_call( req
);
1251 /***********************************************************************
1252 * handle_internal_message
1254 * Handle an internal Wine message instead of calling the window proc.
1256 static LRESULT
handle_internal_message( HWND hwnd
, UINT msg
, WPARAM wparam
, LPARAM lparam
)
1260 case WM_WINE_DESTROYWINDOW
:
1261 return WIN_DestroyWindow( hwnd
);
1262 case WM_WINE_SETWINDOWPOS
:
1263 if (hwnd
== GetDesktopWindow()) return 0;
1264 return USER_SetWindowPos( (WINDOWPOS
*)lparam
);
1265 case WM_WINE_SHOWWINDOW
:
1266 if (hwnd
== GetDesktopWindow()) return 0;
1267 return ShowWindow( hwnd
, wparam
);
1268 case WM_WINE_SETPARENT
:
1269 if (hwnd
== GetDesktopWindow()) return 0;
1270 return (LRESULT
)SetParent( hwnd
, (HWND
)wparam
);
1271 case WM_WINE_SETWINDOWLONG
:
1272 return WIN_SetWindowLong( hwnd
, (short)LOWORD(wparam
), HIWORD(wparam
), lparam
, TRUE
);
1273 case WM_WINE_ENABLEWINDOW
:
1274 if (hwnd
== GetDesktopWindow()) return 0;
1275 return EnableWindow( hwnd
, wparam
);
1276 case WM_WINE_SETACTIVEWINDOW
:
1277 if (hwnd
== GetDesktopWindow()) return 0;
1278 return (LRESULT
)SetActiveWindow( (HWND
)wparam
);
1279 case WM_WINE_KEYBOARD_LL_HOOK
:
1280 case WM_WINE_MOUSE_LL_HOOK
:
1282 struct hook_extra_info
*h_extra
= (struct hook_extra_info
*)lparam
;
1284 return call_current_hook( h_extra
->handle
, HC_ACTION
, wparam
, h_extra
->lparam
);
1287 if (msg
>= WM_WINE_FIRST_DRIVER_MSG
&& msg
<= WM_WINE_LAST_DRIVER_MSG
)
1288 return USER_Driver
->pWindowMessage( hwnd
, msg
, wparam
, lparam
);
1289 FIXME( "unknown internal message %x\n", msg
);
1294 /* since the WM_DDE_ACK response to a WM_DDE_EXECUTE message should contain the handle
1295 * to the memory handle, we keep track (in the server side) of all pairs of handle
1296 * used (the client passes its value and the content of the memory handle), and
1297 * the server stored both values (the client, and the local one, created after the
1298 * content). When a ACK message is generated, the list of pair is searched for a
1299 * matching pair, so that the client memory handle can be returned.
1302 HGLOBAL client_hMem
;
1303 HGLOBAL server_hMem
;
1306 static struct DDE_pair
* dde_pairs
;
1307 static int dde_num_alloc
;
1308 static int dde_num_used
;
1310 static CRITICAL_SECTION dde_crst
;
1311 static CRITICAL_SECTION_DEBUG critsect_debug
=
1314 { &critsect_debug
.ProcessLocksList
, &critsect_debug
.ProcessLocksList
},
1315 0, 0, { (DWORD_PTR
)(__FILE__
": dde_crst") }
1317 static CRITICAL_SECTION dde_crst
= { &critsect_debug
, -1, 0, 0, 0, 0 };
1319 static BOOL
dde_add_pair(HGLOBAL chm
, HGLOBAL shm
)
1324 EnterCriticalSection(&dde_crst
);
1326 /* now remember the pair of hMem on both sides */
1327 if (dde_num_used
== dde_num_alloc
)
1329 struct DDE_pair
* tmp
;
1331 tmp
= HeapReAlloc( GetProcessHeap(), 0, dde_pairs
,
1332 (dde_num_alloc
+ GROWBY
) * sizeof(struct DDE_pair
));
1334 tmp
= HeapAlloc( GetProcessHeap(), 0,
1335 (dde_num_alloc
+ GROWBY
) * sizeof(struct DDE_pair
));
1339 LeaveCriticalSection(&dde_crst
);
1343 /* zero out newly allocated part */
1344 memset(&dde_pairs
[dde_num_alloc
], 0, GROWBY
* sizeof(struct DDE_pair
));
1345 dde_num_alloc
+= GROWBY
;
1348 for (i
= 0; i
< dde_num_alloc
; i
++)
1350 if (dde_pairs
[i
].server_hMem
== 0)
1352 dde_pairs
[i
].client_hMem
= chm
;
1353 dde_pairs
[i
].server_hMem
= shm
;
1358 LeaveCriticalSection(&dde_crst
);
1362 static HGLOBAL
dde_get_pair(HGLOBAL shm
)
1367 EnterCriticalSection(&dde_crst
);
1368 for (i
= 0; i
< dde_num_alloc
; i
++)
1370 if (dde_pairs
[i
].server_hMem
== shm
)
1372 /* free this pair */
1373 dde_pairs
[i
].server_hMem
= 0;
1375 ret
= dde_pairs
[i
].client_hMem
;
1379 LeaveCriticalSection(&dde_crst
);
1383 /***********************************************************************
1386 * Post a DDE message
1388 static BOOL
post_dde_message( struct packed_message
*data
, const struct send_message_info
*info
)
1392 UINT_PTR uiLo
, uiHi
;
1394 HGLOBAL hunlock
= 0;
1398 if (!UnpackDDElParam( info
->msg
, info
->lparam
, &uiLo
, &uiHi
))
1404 /* DDE messages which don't require packing are:
1413 /* uiHi should contain a hMem from WM_DDE_EXECUTE */
1414 HGLOBAL h
= dde_get_pair( (HANDLE
)uiHi
);
1417 /* send back the value of h on the other side */
1418 push_data( data
, &h
, sizeof(HGLOBAL
) );
1420 TRACE( "send dde-ack %lx %08lx => %p\n", uiLo
, uiHi
, h
);
1425 /* uiHi should contain either an atom or 0 */
1426 TRACE( "send dde-ack %lx atom=%lx\n", uiLo
, uiHi
);
1427 lp
= MAKELONG( uiLo
, uiHi
);
1436 size
= GlobalSize( (HGLOBAL
)uiLo
) ;
1437 if ((info
->msg
== WM_DDE_ADVISE
&& size
< sizeof(DDEADVISE
)) ||
1438 (info
->msg
== WM_DDE_DATA
&& size
< sizeof(DDEDATA
)) ||
1439 (info
->msg
== WM_DDE_POKE
&& size
< sizeof(DDEPOKE
))
1443 else if (info
->msg
!= WM_DDE_DATA
) return FALSE
;
1448 if ((ptr
= GlobalLock( (HGLOBAL
)uiLo
) ))
1450 DDEDATA
*dde_data
= (DDEDATA
*)ptr
;
1451 TRACE("unused %d, fResponse %d, fRelease %d, fDeferUpd %d, fAckReq %d, cfFormat %d\n",
1452 dde_data
->unused
, dde_data
->fResponse
, dde_data
->fRelease
,
1453 dde_data
->reserved
, dde_data
->fAckReq
, dde_data
->cfFormat
);
1454 push_data( data
, ptr
, size
);
1455 hunlock
= (HGLOBAL
)uiLo
;
1458 TRACE( "send ddepack %u %lx\n", size
, uiHi
);
1460 case WM_DDE_EXECUTE
:
1463 if ((ptr
= GlobalLock( (HGLOBAL
)info
->lparam
) ))
1465 push_data(data
, ptr
, GlobalSize( (HGLOBAL
)info
->lparam
));
1466 /* so that the other side can send it back on ACK */
1468 hunlock
= (HGLOBAL
)info
->lparam
;
1473 SERVER_START_REQ( send_message
)
1475 req
->id
= info
->dest_tid
;
1476 req
->type
= info
->type
;
1478 req
->win
= info
->hwnd
;
1479 req
->msg
= info
->msg
;
1480 req
->wparam
= info
->wparam
;
1482 req
->timeout
= TIMEOUT_INFINITE
;
1483 for (i
= 0; i
< data
->count
; i
++)
1484 wine_server_add_data( req
, data
->data
[i
], data
->size
[i
] );
1485 if ((res
= wine_server_call( req
)))
1487 if (res
== STATUS_INVALID_PARAMETER
)
1488 /* FIXME: find a STATUS_ value for this one */
1489 SetLastError( ERROR_INVALID_THREAD_ID
);
1491 SetLastError( RtlNtStatusToDosError(res
) );
1494 FreeDDElParam(info
->msg
, info
->lparam
);
1497 if (hunlock
) GlobalUnlock(hunlock
);
1502 /***********************************************************************
1503 * unpack_dde_message
1505 * Unpack a posted DDE message received from another process.
1507 static BOOL
unpack_dde_message( HWND hwnd
, UINT message
, WPARAM
*wparam
, LPARAM
*lparam
,
1508 void **buffer
, size_t size
)
1510 UINT_PTR uiLo
, uiHi
;
1519 /* hMem is being passed */
1520 if (size
!= sizeof(HGLOBAL
)) return FALSE
;
1521 if (!buffer
|| !*buffer
) return FALSE
;
1523 memcpy( &hMem
, *buffer
, size
);
1524 uiHi
= (UINT_PTR
)hMem
;
1525 TRACE("recv dde-ack %lx mem=%lx[%lx]\n", uiLo
, uiHi
, GlobalSize( hMem
));
1529 uiLo
= LOWORD( *lparam
);
1530 uiHi
= HIWORD( *lparam
);
1531 TRACE("recv dde-ack %lx atom=%lx\n", uiLo
, uiHi
);
1533 *lparam
= PackDDElParam( WM_DDE_ACK
, uiLo
, uiHi
);
1538 if ((!buffer
|| !*buffer
) && message
!= WM_DDE_DATA
) return FALSE
;
1542 if (!(hMem
= GlobalAlloc( GMEM_MOVEABLE
|GMEM_DDESHARE
, size
)))
1544 if ((ptr
= GlobalLock( hMem
)))
1546 memcpy( ptr
, *buffer
, size
);
1547 GlobalUnlock( hMem
);
1555 uiLo
= (UINT_PTR
)hMem
;
1557 *lparam
= PackDDElParam( message
, uiLo
, uiHi
);
1559 case WM_DDE_EXECUTE
:
1562 if (!buffer
|| !*buffer
) return FALSE
;
1563 if (!(hMem
= GlobalAlloc( GMEM_MOVEABLE
|GMEM_DDESHARE
, size
))) return FALSE
;
1564 if ((ptr
= GlobalLock( hMem
)))
1566 memcpy( ptr
, *buffer
, size
);
1567 GlobalUnlock( hMem
);
1568 TRACE( "exec: pairing c=%08lx s=%p\n", *lparam
, hMem
);
1569 if (!dde_add_pair( (HGLOBAL
)*lparam
, hMem
))
1580 } else return FALSE
;
1581 *lparam
= (LPARAM
)hMem
;
1587 /***********************************************************************
1590 * Call a window procedure and the corresponding hooks.
1592 static LRESULT
call_window_proc( HWND hwnd
, UINT msg
, WPARAM wparam
, LPARAM lparam
,
1593 BOOL unicode
, BOOL same_thread
, enum wm_char_mapping mapping
)
1595 struct user_thread_info
*thread_info
= get_user_thread_info();
1598 CWPRETSTRUCT cwpret
;
1600 if (thread_info
->recursion_count
> MAX_SENDMSG_RECURSION
) return 0;
1601 thread_info
->recursion_count
++;
1603 if (msg
& 0x80000000)
1605 result
= handle_internal_message( hwnd
, msg
, wparam
, lparam
);
1609 /* first the WH_CALLWNDPROC hook */
1610 hwnd
= WIN_GetFullHandle( hwnd
);
1611 cwp
.lParam
= lparam
;
1612 cwp
.wParam
= wparam
;
1615 HOOK_CallHooks( WH_CALLWNDPROC
, HC_ACTION
, same_thread
, (LPARAM
)&cwp
, unicode
);
1617 /* now call the window procedure */
1618 if (!WINPROC_call_window( hwnd
, msg
, wparam
, lparam
, &result
, unicode
, mapping
)) goto done
;
1620 /* and finally the WH_CALLWNDPROCRET hook */
1621 cwpret
.lResult
= result
;
1622 cwpret
.lParam
= lparam
;
1623 cwpret
.wParam
= wparam
;
1624 cwpret
.message
= msg
;
1626 HOOK_CallHooks( WH_CALLWNDPROCRET
, HC_ACTION
, same_thread
, (LPARAM
)&cwpret
, unicode
);
1628 thread_info
->recursion_count
--;
1633 /***********************************************************************
1634 * send_parent_notify
1636 * Send a WM_PARENTNOTIFY to all ancestors of the given window, unless
1637 * the window has the WS_EX_NOPARENTNOTIFY style.
1639 static void send_parent_notify( HWND hwnd
, WORD event
, WORD idChild
, POINT pt
)
1641 /* pt has to be in the client coordinates of the parent window */
1642 MapWindowPoints( 0, hwnd
, &pt
, 1 );
1647 if (!(GetWindowLongW( hwnd
, GWL_STYLE
) & WS_CHILD
)) break;
1648 if (GetWindowLongW( hwnd
, GWL_EXSTYLE
) & WS_EX_NOPARENTNOTIFY
) break;
1649 if (!(parent
= GetParent(hwnd
))) break;
1650 if (parent
== GetDesktopWindow()) break;
1651 MapWindowPoints( hwnd
, parent
, &pt
, 1 );
1653 SendMessageW( hwnd
, WM_PARENTNOTIFY
,
1654 MAKEWPARAM( event
, idChild
), MAKELPARAM( pt
.x
, pt
.y
) );
1659 /***********************************************************************
1660 * accept_hardware_message
1662 * Tell the server we have passed the message to the app
1663 * (even though we may end up dropping it later on)
1665 static void accept_hardware_message( UINT hw_id
, BOOL remove
, HWND new_hwnd
)
1667 SERVER_START_REQ( accept_hardware_message
)
1670 req
->remove
= remove
;
1671 req
->new_win
= new_hwnd
;
1672 if (wine_server_call( req
))
1673 FIXME("Failed to reply to MSG_HARDWARE message. Message may not be removed from queue.\n");
1679 /***********************************************************************
1680 * process_keyboard_message
1682 * returns TRUE if the contents of 'msg' should be passed to the application
1684 static BOOL
process_keyboard_message( MSG
*msg
, UINT hw_id
, HWND hwnd_filter
,
1685 UINT first
, UINT last
, BOOL remove
)
1689 if (msg
->message
== WM_KEYDOWN
|| msg
->message
== WM_SYSKEYDOWN
||
1690 msg
->message
== WM_KEYUP
|| msg
->message
== WM_SYSKEYUP
)
1691 switch (msg
->wParam
)
1693 case VK_LSHIFT
: case VK_RSHIFT
:
1694 msg
->wParam
= VK_SHIFT
;
1696 case VK_LCONTROL
: case VK_RCONTROL
:
1697 msg
->wParam
= VK_CONTROL
;
1699 case VK_LMENU
: case VK_RMENU
:
1700 msg
->wParam
= VK_MENU
;
1704 /* FIXME: is this really the right place for this hook? */
1705 event
.message
= msg
->message
;
1706 event
.hwnd
= msg
->hwnd
;
1707 event
.time
= msg
->time
;
1708 event
.paramL
= (msg
->wParam
& 0xFF) | (HIWORD(msg
->lParam
) << 8);
1709 event
.paramH
= msg
->lParam
& 0x7FFF;
1710 if (HIWORD(msg
->lParam
) & 0x0100) event
.paramH
|= 0x8000; /* special_key - bit */
1711 HOOK_CallHooks( WH_JOURNALRECORD
, HC_ACTION
, 0, (LPARAM
)&event
, TRUE
);
1713 /* check message filters */
1714 if (msg
->message
< first
|| msg
->message
> last
) return FALSE
;
1715 if (!check_hwnd_filter( msg
, hwnd_filter
)) return FALSE
;
1719 if((msg
->message
== WM_KEYDOWN
) &&
1720 (msg
->hwnd
!= GetDesktopWindow()))
1722 /* Handle F1 key by sending out WM_HELP message */
1723 if (msg
->wParam
== VK_F1
)
1725 PostMessageW( msg
->hwnd
, WM_KEYF1
, 0, 0 );
1727 else if(msg
->wParam
>= VK_BROWSER_BACK
&&
1728 msg
->wParam
<= VK_LAUNCH_APP2
)
1730 /* FIXME: Process keystate */
1731 SendMessageW(msg
->hwnd
, WM_APPCOMMAND
, (WPARAM
)msg
->hwnd
, MAKELPARAM(0, (FAPPCOMMAND_KEY
| (msg
->wParam
- VK_BROWSER_BACK
+ 1))));
1734 else if (msg
->message
== WM_KEYUP
)
1736 /* Handle VK_APPS key by posting a WM_CONTEXTMENU message */
1737 if (msg
->wParam
== VK_APPS
&& !MENU_IsMenuActive())
1738 PostMessageW(msg
->hwnd
, WM_CONTEXTMENU
, (WPARAM
)msg
->hwnd
, (LPARAM
)-1);
1742 if (HOOK_CallHooks( WH_KEYBOARD
, remove
? HC_ACTION
: HC_NOREMOVE
,
1743 LOWORD(msg
->wParam
), msg
->lParam
, TRUE
))
1745 /* skip this message */
1746 HOOK_CallHooks( WH_CBT
, HCBT_KEYSKIPPED
, LOWORD(msg
->wParam
), msg
->lParam
, TRUE
);
1747 accept_hardware_message( hw_id
, TRUE
, 0 );
1750 accept_hardware_message( hw_id
, remove
, 0 );
1752 if ( msg
->message
== WM_KEYDOWN
|| msg
->message
== WM_KEYUP
)
1753 if ( ImmProcessKey(msg
->hwnd
, GetKeyboardLayout(0), msg
->wParam
, msg
->lParam
, 0) )
1754 msg
->wParam
= VK_PROCESSKEY
;
1760 /***********************************************************************
1761 * process_mouse_message
1763 * returns TRUE if the contents of 'msg' should be passed to the application
1765 static BOOL
process_mouse_message( MSG
*msg
, UINT hw_id
, ULONG_PTR extra_info
, HWND hwnd_filter
,
1766 UINT first
, UINT last
, BOOL remove
)
1775 MOUSEHOOKSTRUCT hook
;
1778 /* find the window to dispatch this mouse message to */
1780 GetGUIThreadInfo( GetCurrentThreadId(), &info
);
1781 if (info
.hwndCapture
)
1784 msg
->hwnd
= info
.hwndCapture
;
1788 msg
->hwnd
= WINPOS_WindowFromPoint( msg
->hwnd
, msg
->pt
, &hittest
);
1791 if (!msg
->hwnd
|| !WIN_IsCurrentThread( msg
->hwnd
))
1793 accept_hardware_message( hw_id
, TRUE
, msg
->hwnd
);
1797 /* FIXME: is this really the right place for this hook? */
1798 event
.message
= msg
->message
;
1799 event
.time
= msg
->time
;
1800 event
.hwnd
= msg
->hwnd
;
1801 event
.paramL
= msg
->pt
.x
;
1802 event
.paramH
= msg
->pt
.y
;
1803 HOOK_CallHooks( WH_JOURNALRECORD
, HC_ACTION
, 0, (LPARAM
)&event
, TRUE
);
1805 if (!check_hwnd_filter( msg
, hwnd_filter
)) return FALSE
;
1808 message
= msg
->message
;
1809 /* Note: windows has no concept of a non-client wheel message */
1810 if (message
!= WM_MOUSEWHEEL
)
1812 if (hittest
!= HTCLIENT
)
1814 message
+= WM_NCMOUSEMOVE
- WM_MOUSEMOVE
;
1815 msg
->wParam
= hittest
;
1819 /* coordinates don't get translated while tracking a menu */
1820 /* FIXME: should differentiate popups and top-level menus */
1821 if (!(info
.flags
& GUI_INMENUMODE
))
1822 ScreenToClient( msg
->hwnd
, &pt
);
1825 msg
->lParam
= MAKELONG( pt
.x
, pt
.y
);
1827 /* translate double clicks */
1829 if ((msg
->message
== WM_LBUTTONDOWN
) ||
1830 (msg
->message
== WM_RBUTTONDOWN
) ||
1831 (msg
->message
== WM_MBUTTONDOWN
) ||
1832 (msg
->message
== WM_XBUTTONDOWN
))
1834 BOOL update
= remove
;
1836 /* translate double clicks -
1837 * note that ...MOUSEMOVEs can slip in between
1838 * ...BUTTONDOWN and ...BUTTONDBLCLK messages */
1840 if ((info
.flags
& (GUI_INMENUMODE
|GUI_INMOVESIZE
)) ||
1841 hittest
!= HTCLIENT
||
1842 (GetClassLongA( msg
->hwnd
, GCL_STYLE
) & CS_DBLCLKS
))
1844 if ((msg
->message
== clk_msg
.message
) &&
1845 (msg
->hwnd
== clk_msg
.hwnd
) &&
1846 (msg
->wParam
== clk_msg
.wParam
) &&
1847 (msg
->time
- clk_msg
.time
< GetDoubleClickTime()) &&
1848 (abs(msg
->pt
.x
- clk_msg
.pt
.x
) < GetSystemMetrics(SM_CXDOUBLECLK
)/2) &&
1849 (abs(msg
->pt
.y
- clk_msg
.pt
.y
) < GetSystemMetrics(SM_CYDOUBLECLK
)/2))
1851 message
+= (WM_LBUTTONDBLCLK
- WM_LBUTTONDOWN
);
1854 clk_msg
.message
= 0; /* clear the double click conditions */
1859 if (message
< first
|| message
> last
) return FALSE
;
1860 /* update static double click conditions */
1861 if (update
) clk_msg
= *msg
;
1865 if (message
< first
|| message
> last
) return FALSE
;
1868 /* message is accepted now (but may still get dropped) */
1871 hook
.hwnd
= msg
->hwnd
;
1872 hook
.wHitTestCode
= hittest
;
1873 hook
.dwExtraInfo
= extra_info
;
1874 if (HOOK_CallHooks( WH_MOUSE
, remove
? HC_ACTION
: HC_NOREMOVE
,
1875 message
, (LPARAM
)&hook
, TRUE
))
1878 hook
.hwnd
= msg
->hwnd
;
1879 hook
.wHitTestCode
= hittest
;
1880 hook
.dwExtraInfo
= extra_info
;
1881 HOOK_CallHooks( WH_CBT
, HCBT_CLICKSKIPPED
, message
, (LPARAM
)&hook
, TRUE
);
1882 accept_hardware_message( hw_id
, TRUE
, 0 );
1886 if ((hittest
== HTERROR
) || (hittest
== HTNOWHERE
))
1888 SendMessageW( msg
->hwnd
, WM_SETCURSOR
, (WPARAM
)msg
->hwnd
,
1889 MAKELONG( hittest
, msg
->message
));
1890 accept_hardware_message( hw_id
, TRUE
, 0 );
1894 accept_hardware_message( hw_id
, remove
, 0 );
1896 if (!remove
|| info
.hwndCapture
)
1898 msg
->message
= message
;
1904 if ((msg
->message
== WM_LBUTTONDOWN
) ||
1905 (msg
->message
== WM_RBUTTONDOWN
) ||
1906 (msg
->message
== WM_MBUTTONDOWN
) ||
1907 (msg
->message
== WM_XBUTTONDOWN
))
1909 /* Send the WM_PARENTNOTIFY,
1910 * note that even for double/nonclient clicks
1911 * notification message is still WM_L/M/RBUTTONDOWN.
1913 send_parent_notify( msg
->hwnd
, msg
->message
, 0, msg
->pt
);
1915 /* Activate the window if needed */
1917 if (msg
->hwnd
!= info
.hwndActive
)
1919 HWND hwndTop
= msg
->hwnd
;
1922 if ((GetWindowLongW( hwndTop
, GWL_STYLE
) & (WS_POPUP
|WS_CHILD
)) != WS_CHILD
) break;
1923 hwndTop
= GetParent( hwndTop
);
1926 if (hwndTop
&& hwndTop
!= GetDesktopWindow())
1928 LONG ret
= SendMessageW( msg
->hwnd
, WM_MOUSEACTIVATE
, (WPARAM
)hwndTop
,
1929 MAKELONG( hittest
, msg
->message
) );
1932 case MA_NOACTIVATEANDEAT
:
1937 case MA_ACTIVATEANDEAT
:
1942 if (!FOCUS_MouseActivate( hwndTop
)) eatMsg
= TRUE
;
1945 WARN( "unknown WM_MOUSEACTIVATE code %d\n", ret
);
1952 /* send the WM_SETCURSOR message */
1954 /* Windows sends the normal mouse message as the message parameter
1955 in the WM_SETCURSOR message even if it's non-client mouse message */
1956 SendMessageW( msg
->hwnd
, WM_SETCURSOR
, (WPARAM
)msg
->hwnd
, MAKELONG( hittest
, msg
->message
));
1958 msg
->message
= message
;
1963 /***********************************************************************
1964 * process_hardware_message
1966 * Process a hardware message; return TRUE if message should be passed on to the app
1968 static BOOL
process_hardware_message( MSG
*msg
, UINT hw_id
, ULONG_PTR extra_info
, HWND hwnd_filter
,
1969 UINT first
, UINT last
, BOOL remove
)
1971 if (is_keyboard_message( msg
->message
))
1972 return process_keyboard_message( msg
, hw_id
, hwnd_filter
, first
, last
, remove
);
1974 if (is_mouse_message( msg
->message
))
1975 return process_mouse_message( msg
, hw_id
, extra_info
, hwnd_filter
, first
, last
, remove
);
1977 ERR( "unknown message type %x\n", msg
->message
);
1982 /***********************************************************************
1983 * call_sendmsg_callback
1985 * Call the callback function of SendMessageCallback.
1987 static inline void call_sendmsg_callback( SENDASYNCPROC callback
, HWND hwnd
, UINT msg
,
1988 ULONG_PTR data
, LRESULT result
)
1990 if (!callback
) return;
1992 if (TRACE_ON(relay
))
1993 DPRINTF( "%04x:Call message callback %p (hwnd=%p,msg=%s,data=%08lx,result=%08lx)\n",
1994 GetCurrentThreadId(), callback
, hwnd
, SPY_GetMsgName( msg
, hwnd
),
1996 callback( hwnd
, msg
, data
, result
);
1997 if (TRACE_ON(relay
))
1998 DPRINTF( "%04x:Ret message callback %p (hwnd=%p,msg=%s,data=%08lx,result=%08lx)\n",
1999 GetCurrentThreadId(), callback
, hwnd
, SPY_GetMsgName( msg
, hwnd
),
2004 /***********************************************************************
2007 * Peek for a message matching the given parameters. Return FALSE if none available.
2008 * All pending sent messages are processed before returning.
2010 static BOOL
peek_message( MSG
*msg
, HWND hwnd
, UINT first
, UINT last
, UINT flags
)
2013 ULONG_PTR extra_info
= 0;
2014 struct user_thread_info
*thread_info
= get_user_thread_info();
2015 struct received_message_info info
, *old_info
;
2016 unsigned int wake_mask
, changed_mask
= HIWORD(flags
);
2017 unsigned int hw_id
= 0; /* id of previous hardware message */
2019 if (!first
&& !last
) last
= ~0;
2020 if (!changed_mask
) changed_mask
= QS_ALLINPUT
;
2021 wake_mask
= changed_mask
& (QS_SENDMESSAGE
| QS_SMRESULT
);
2026 void *buffer
= NULL
;
2027 size_t size
= 0, buffer_size
= 0;
2029 do /* loop while buffer is too small */
2031 if (buffer_size
&& !(buffer
= HeapAlloc( GetProcessHeap(), 0, buffer_size
)))
2033 SERVER_START_REQ( get_message
)
2036 req
->get_win
= hwnd
;
2037 req
->get_first
= first
;
2038 req
->get_last
= last
;
2040 req
->wake_mask
= wake_mask
;
2041 req
->changed_mask
= changed_mask
;
2042 if (buffer_size
) wine_server_set_reply( req
, buffer
, buffer_size
);
2043 if (!(res
= wine_server_call( req
)))
2045 size
= wine_server_reply_size( reply
);
2046 info
.type
= reply
->type
;
2047 info
.msg
.hwnd
= reply
->win
;
2048 info
.msg
.message
= reply
->msg
;
2049 info
.msg
.wParam
= reply
->wparam
;
2050 info
.msg
.lParam
= reply
->lparam
;
2051 info
.msg
.time
= reply
->time
;
2052 info
.msg
.pt
.x
= reply
->x
;
2053 info
.msg
.pt
.y
= reply
->y
;
2054 hw_id
= reply
->hw_id
;
2055 extra_info
= reply
->info
;
2056 thread_info
->active_hooks
= reply
->active_hooks
;
2060 HeapFree( GetProcessHeap(), 0, buffer
);
2061 buffer_size
= reply
->total
;
2065 } while (res
== STATUS_BUFFER_OVERFLOW
);
2067 if (res
) return FALSE
;
2069 TRACE( "got type %d msg %x (%s) hwnd %p wp %lx lp %lx\n",
2070 info
.type
, info
.msg
.message
,
2071 (info
.type
== MSG_WINEVENT
) ? "MSG_WINEVENT" : SPY_GetMsgName(info
.msg
.message
, info
.msg
.hwnd
),
2072 info
.msg
.hwnd
, info
.msg
.wParam
, info
.msg
.lParam
);
2078 info
.flags
= ISMEX_SEND
;
2081 info
.flags
= ISMEX_NOTIFY
;
2084 info
.flags
= ISMEX_CALLBACK
;
2086 case MSG_CALLBACK_RESULT
:
2087 if (size
>= sizeof(struct callback_msg_data
))
2089 const struct callback_msg_data
*data
= (const struct callback_msg_data
*)buffer
;
2090 call_sendmsg_callback( data
->callback
, info
.msg
.hwnd
,
2091 info
.msg
.message
, data
->data
, data
->result
);
2095 if (size
>= sizeof(struct winevent_msg_data
))
2097 WINEVENTPROC hook_proc
;
2098 const struct winevent_msg_data
*data
= (const struct winevent_msg_data
*)buffer
;
2100 hook_proc
= data
->hook_proc
;
2101 size
-= sizeof(*data
);
2104 WCHAR module
[MAX_PATH
];
2106 size
= min( size
, (MAX_PATH
- 1) * sizeof(WCHAR
) );
2107 memcpy( module
, buffer
, size
);
2108 module
[size
/ sizeof(WCHAR
)] = 0;
2109 if (!(hook_proc
= get_hook_proc( hook_proc
, module
)))
2111 ERR( "invalid winevent hook module name %s\n", debugstr_w(module
) );
2116 if (TRACE_ON(relay
))
2117 DPRINTF( "%04x:Call winevent proc %p (hook=%p,event=%x,hwnd=%p,object_id=%lx,child_id=%lx,tid=%04x,time=%x)\n",
2118 GetCurrentThreadId(), hook_proc
,
2119 data
->hook
, info
.msg
.message
, info
.msg
.hwnd
, info
.msg
.wParam
,
2120 info
.msg
.lParam
, data
->tid
, info
.msg
.time
);
2122 hook_proc( data
->hook
, info
.msg
.message
, info
.msg
.hwnd
, info
.msg
.wParam
,
2123 info
.msg
.lParam
, data
->tid
, info
.msg
.time
);
2125 if (TRACE_ON(relay
))
2126 DPRINTF( "%04x:Ret winevent proc %p (hook=%p,event=%x,hwnd=%p,object_id=%lx,child_id=%lx,tid=%04x,time=%x)\n",
2127 GetCurrentThreadId(), hook_proc
,
2128 data
->hook
, info
.msg
.message
, info
.msg
.hwnd
, info
.msg
.wParam
,
2129 info
.msg
.lParam
, data
->tid
, info
.msg
.time
);
2132 case MSG_OTHER_PROCESS
:
2133 info
.flags
= ISMEX_SEND
;
2134 if (!unpack_message( info
.msg
.hwnd
, info
.msg
.message
, &info
.msg
.wParam
,
2135 &info
.msg
.lParam
, &buffer
, size
))
2138 reply_message( &info
, 0, TRUE
);
2143 if (!process_hardware_message( &info
.msg
, hw_id
, extra_info
,
2144 hwnd
, first
, last
, flags
& PM_REMOVE
))
2146 TRACE("dropping msg %x\n", info
.msg
.message
);
2147 goto next
; /* ignore it */
2149 thread_info
->GetMessagePosVal
= MAKELONG( info
.msg
.pt
.x
, info
.msg
.pt
.y
);
2152 thread_info
->GetMessageExtraInfoVal
= extra_info
;
2153 if (info
.msg
.message
>= WM_DDE_FIRST
&& info
.msg
.message
<= WM_DDE_LAST
)
2155 if (!unpack_dde_message( info
.msg
.hwnd
, info
.msg
.message
, &info
.msg
.wParam
,
2156 &info
.msg
.lParam
, &buffer
, size
))
2157 goto next
; /* ignore it */
2160 HeapFree( GetProcessHeap(), 0, buffer
);
2164 /* if we get here, we have a sent message; call the window procedure */
2165 old_info
= thread_info
->receive_info
;
2166 thread_info
->receive_info
= &info
;
2167 result
= call_window_proc( info
.msg
.hwnd
, info
.msg
.message
, info
.msg
.wParam
,
2168 info
.msg
.lParam
, (info
.type
!= MSG_ASCII
), FALSE
,
2169 WMCHAR_MAP_RECVMESSAGE
);
2170 reply_message( &info
, result
, TRUE
);
2171 thread_info
->receive_info
= old_info
;
2173 /* if some PM_QS* flags were specified, only handle sent messages from now on */
2174 if (HIWORD(flags
)) flags
= PM_QS_SENDMESSAGE
| LOWORD(flags
);
2176 HeapFree( GetProcessHeap(), 0, buffer
);
2181 /***********************************************************************
2182 * process_sent_messages
2184 * Process all pending sent messages.
2186 static inline void process_sent_messages(void)
2189 peek_message( &msg
, 0, 0, 0, PM_REMOVE
| PM_QS_SENDMESSAGE
);
2193 /***********************************************************************
2194 * get_server_queue_handle
2196 * Get a handle to the server message queue for the current thread.
2198 static HANDLE
get_server_queue_handle(void)
2200 struct user_thread_info
*thread_info
= get_user_thread_info();
2203 if (!(ret
= thread_info
->server_queue
))
2205 SERVER_START_REQ( get_msg_queue
)
2207 wine_server_call( req
);
2208 ret
= reply
->handle
;
2211 thread_info
->server_queue
= ret
;
2212 if (!ret
) ERR( "Cannot get server thread queue\n" );
2218 /***********************************************************************
2219 * wait_message_reply
2221 * Wait until a sent message gets replied to.
2223 static void wait_message_reply( UINT flags
)
2225 HANDLE server_queue
= get_server_queue_handle();
2229 unsigned int wake_bits
= 0;
2232 SERVER_START_REQ( set_queue_mask
)
2234 req
->wake_mask
= QS_SMRESULT
| ((flags
& SMTO_BLOCK
) ? 0 : QS_SENDMESSAGE
);
2235 req
->changed_mask
= req
->wake_mask
;
2237 if (!wine_server_call( req
))
2238 wake_bits
= reply
->wake_bits
;
2242 if (wake_bits
& QS_SMRESULT
) return; /* got a result */
2243 if (wake_bits
& QS_SENDMESSAGE
)
2245 /* Process the sent message immediately */
2246 process_sent_messages();
2250 /* now wait for it */
2252 ReleaseThunkLock( &dwlc
);
2253 res
= USER_Driver
->pMsgWaitForMultipleObjectsEx( 1, &server_queue
,
2254 INFINITE
, QS_SENDMESSAGE
, 0 );
2255 if (dwlc
) RestoreThunkLock( dwlc
);
2259 /***********************************************************************
2260 * put_message_in_queue
2262 * Put a sent message into the destination queue.
2263 * For inter-process message, reply_size is set to expected size of reply data.
2265 static BOOL
put_message_in_queue( const struct send_message_info
*info
, size_t *reply_size
)
2267 struct packed_message data
;
2268 message_data_t msg_data
;
2271 timeout_t timeout
= TIMEOUT_INFINITE
;
2273 /* Check for INFINITE timeout for compatibility with Win9x,
2274 * although Windows >= NT does not do so
2276 if (info
->type
!= MSG_NOTIFY
&&
2277 info
->type
!= MSG_CALLBACK
&&
2278 info
->type
!= MSG_POSTED
&&
2280 info
->timeout
!= INFINITE
)
2282 /* timeout is signed despite the prototype */
2283 timeout
= (timeout_t
)max( 0, (int)info
->timeout
) * -10000;
2287 if (info
->type
== MSG_OTHER_PROCESS
)
2289 *reply_size
= pack_message( info
->hwnd
, info
->msg
, info
->wparam
, info
->lparam
, &data
);
2290 if (data
.count
== -1)
2292 WARN( "cannot pack message %x\n", info
->msg
);
2296 else if (info
->type
== MSG_CALLBACK
)
2298 msg_data
.callback
.callback
= info
->callback
;
2299 msg_data
.callback
.data
= info
->data
;
2300 msg_data
.callback
.result
= 0;
2301 data
.data
[0] = &msg_data
;
2302 data
.size
[0] = sizeof(msg_data
.callback
);
2305 else if (info
->type
== MSG_POSTED
&& info
->msg
>= WM_DDE_FIRST
&& info
->msg
<= WM_DDE_LAST
)
2307 return post_dde_message( &data
, info
);
2310 SERVER_START_REQ( send_message
)
2312 req
->id
= info
->dest_tid
;
2313 req
->type
= info
->type
;
2315 req
->win
= info
->hwnd
;
2316 req
->msg
= info
->msg
;
2317 req
->wparam
= info
->wparam
;
2318 req
->lparam
= info
->lparam
;
2319 req
->timeout
= timeout
;
2321 if (info
->flags
& SMTO_ABORTIFHUNG
) req
->flags
|= SEND_MSG_ABORT_IF_HUNG
;
2322 for (i
= 0; i
< data
.count
; i
++) wine_server_add_data( req
, data
.data
[i
], data
.size
[i
] );
2323 if ((res
= wine_server_call( req
)))
2325 if (res
== STATUS_INVALID_PARAMETER
)
2326 /* FIXME: find a STATUS_ value for this one */
2327 SetLastError( ERROR_INVALID_THREAD_ID
);
2329 SetLastError( RtlNtStatusToDosError(res
) );
2337 /***********************************************************************
2340 * Retrieve a message reply from the server.
2342 static LRESULT
retrieve_reply( const struct send_message_info
*info
,
2343 size_t reply_size
, LRESULT
*result
)
2346 void *reply_data
= NULL
;
2350 if (!(reply_data
= HeapAlloc( GetProcessHeap(), 0, reply_size
)))
2352 WARN( "no memory for reply, will be truncated\n" );
2356 SERVER_START_REQ( get_message_reply
)
2359 if (reply_size
) wine_server_set_reply( req
, reply_data
, reply_size
);
2360 if (!(status
= wine_server_call( req
))) *result
= reply
->result
;
2361 reply_size
= wine_server_reply_size( reply
);
2364 if (!status
&& reply_size
)
2365 unpack_reply( info
->hwnd
, info
->msg
, info
->wparam
, info
->lparam
, reply_data
, reply_size
);
2367 HeapFree( GetProcessHeap(), 0, reply_data
);
2369 TRACE( "hwnd %p msg %x (%s) wp %lx lp %lx got reply %lx (err=%d)\n",
2370 info
->hwnd
, info
->msg
, SPY_GetMsgName(info
->msg
, info
->hwnd
), info
->wparam
,
2371 info
->lparam
, *result
, status
);
2373 /* MSDN states that last error is 0 on timeout, but at least NT4 returns ERROR_TIMEOUT */
2374 if (status
) SetLastError( RtlNtStatusToDosError(status
) );
2379 /***********************************************************************
2380 * send_inter_thread_message
2382 static LRESULT
send_inter_thread_message( const struct send_message_info
*info
, LRESULT
*res_ptr
)
2384 size_t reply_size
= 0;
2386 TRACE( "hwnd %p msg %x (%s) wp %lx lp %lx\n",
2387 info
->hwnd
, info
->msg
, SPY_GetMsgName(info
->msg
, info
->hwnd
), info
->wparam
, info
->lparam
);
2389 USER_CheckNotLock();
2391 if (!put_message_in_queue( info
, &reply_size
)) return 0;
2393 /* there's no reply to wait for on notify/callback messages */
2394 if (info
->type
== MSG_NOTIFY
|| info
->type
== MSG_CALLBACK
) return 1;
2396 wait_message_reply( info
->flags
);
2397 return retrieve_reply( info
, reply_size
, res_ptr
);
2401 /***********************************************************************
2402 * send_inter_thread_callback
2404 static LRESULT
send_inter_thread_callback( HWND hwnd
, UINT msg
, WPARAM wp
, LPARAM lp
,
2405 LRESULT
*result
, void *arg
)
2407 struct send_message_info
*info
= arg
;
2412 return send_inter_thread_message( info
, result
);
2416 /***********************************************************************
2419 * Backend implementation of the various SendMessage functions.
2421 static BOOL
send_message( struct send_message_info
*info
, DWORD_PTR
*res_ptr
, BOOL unicode
)
2427 if (is_broadcast(info
->hwnd
))
2429 EnumWindows( broadcast_message_callback
, (LPARAM
)info
);
2430 if (res_ptr
) *res_ptr
= 1;
2434 if (!(info
->dest_tid
= GetWindowThreadProcessId( info
->hwnd
, &dest_pid
))) return FALSE
;
2436 if (USER_IsExitingThread( info
->dest_tid
)) return FALSE
;
2438 SPY_EnterMessage( SPY_SENDMESSAGE
, info
->hwnd
, info
->msg
, info
->wparam
, info
->lparam
);
2440 if (info
->dest_tid
== GetCurrentThreadId())
2442 result
= call_window_proc( info
->hwnd
, info
->msg
, info
->wparam
, info
->lparam
,
2443 unicode
, TRUE
, info
->wm_char
);
2444 if (info
->type
== MSG_CALLBACK
)
2445 call_sendmsg_callback( info
->callback
, info
->hwnd
, info
->msg
, info
->data
, result
);
2450 if (dest_pid
!= GetCurrentProcessId() && (info
->type
== MSG_ASCII
|| info
->type
== MSG_UNICODE
))
2451 info
->type
= MSG_OTHER_PROCESS
;
2453 /* MSG_ASCII can be sent unconverted except for WM_CHAR; everything else needs to be Unicode */
2454 if (!unicode
&& is_unicode_message( info
->msg
) &&
2455 (info
->type
!= MSG_ASCII
|| info
->msg
== WM_CHAR
))
2456 ret
= WINPROC_CallProcAtoW( send_inter_thread_callback
, info
->hwnd
, info
->msg
,
2457 info
->wparam
, info
->lparam
, &result
, info
, info
->wm_char
);
2459 ret
= send_inter_thread_message( info
, &result
);
2462 SPY_ExitMessage( SPY_RESULT_OK
, info
->hwnd
, info
->msg
, result
, info
->wparam
, info
->lparam
);
2463 if (ret
&& res_ptr
) *res_ptr
= result
;
2468 /***********************************************************************
2469 * MSG_SendInternalMessageTimeout
2471 * Same as SendMessageTimeoutW but sends the message to a specific thread
2472 * without requiring a window handle. Only works for internal Wine messages.
2474 LRESULT
MSG_SendInternalMessageTimeout( DWORD dest_pid
, DWORD dest_tid
,
2475 UINT msg
, WPARAM wparam
, LPARAM lparam
,
2476 UINT flags
, UINT timeout
, PDWORD_PTR res_ptr
)
2478 struct send_message_info info
;
2479 LRESULT ret
, result
;
2481 assert( msg
& 0x80000000 ); /* must be an internal Wine message */
2483 info
.type
= MSG_UNICODE
;
2484 info
.dest_tid
= dest_tid
;
2487 info
.wparam
= wparam
;
2488 info
.lparam
= lparam
;
2490 info
.timeout
= timeout
;
2492 if (USER_IsExitingThread( dest_tid
)) return 0;
2494 if (dest_tid
== GetCurrentThreadId())
2496 result
= handle_internal_message( 0, msg
, wparam
, lparam
);
2501 if (dest_pid
!= GetCurrentProcessId()) info
.type
= MSG_OTHER_PROCESS
;
2502 ret
= send_inter_thread_message( &info
, &result
);
2504 if (ret
&& res_ptr
) *res_ptr
= result
;
2509 /***********************************************************************
2510 * SendMessageTimeoutW (USER32.@)
2512 LRESULT WINAPI
SendMessageTimeoutW( HWND hwnd
, UINT msg
, WPARAM wparam
, LPARAM lparam
,
2513 UINT flags
, UINT timeout
, PDWORD_PTR res_ptr
)
2515 struct send_message_info info
;
2517 info
.type
= MSG_UNICODE
;
2520 info
.wparam
= wparam
;
2521 info
.lparam
= lparam
;
2523 info
.timeout
= timeout
;
2525 return send_message( &info
, res_ptr
, TRUE
);
2528 /***********************************************************************
2529 * SendMessageTimeoutA (USER32.@)
2531 LRESULT WINAPI
SendMessageTimeoutA( HWND hwnd
, UINT msg
, WPARAM wparam
, LPARAM lparam
,
2532 UINT flags
, UINT timeout
, PDWORD_PTR res_ptr
)
2534 struct send_message_info info
;
2536 info
.type
= MSG_ASCII
;
2539 info
.wparam
= wparam
;
2540 info
.lparam
= lparam
;
2542 info
.timeout
= timeout
;
2543 info
.wm_char
= WMCHAR_MAP_SENDMESSAGETIMEOUT
;
2545 return send_message( &info
, res_ptr
, FALSE
);
2549 /***********************************************************************
2550 * SendMessageW (USER32.@)
2552 LRESULT WINAPI
SendMessageW( HWND hwnd
, UINT msg
, WPARAM wparam
, LPARAM lparam
)
2555 struct send_message_info info
;
2557 info
.type
= MSG_UNICODE
;
2560 info
.wparam
= wparam
;
2561 info
.lparam
= lparam
;
2562 info
.flags
= SMTO_NORMAL
;
2565 send_message( &info
, &res
, TRUE
);
2570 /***********************************************************************
2571 * SendMessageA (USER32.@)
2573 LRESULT WINAPI
SendMessageA( HWND hwnd
, UINT msg
, WPARAM wparam
, LPARAM lparam
)
2576 struct send_message_info info
;
2578 info
.type
= MSG_ASCII
;
2581 info
.wparam
= wparam
;
2582 info
.lparam
= lparam
;
2583 info
.flags
= SMTO_NORMAL
;
2585 info
.wm_char
= WMCHAR_MAP_SENDMESSAGE
;
2587 send_message( &info
, &res
, FALSE
);
2592 /***********************************************************************
2593 * SendNotifyMessageA (USER32.@)
2595 BOOL WINAPI
SendNotifyMessageA( HWND hwnd
, UINT msg
, WPARAM wparam
, LPARAM lparam
)
2597 struct send_message_info info
;
2599 if (is_pointer_message(msg
))
2601 SetLastError( ERROR_MESSAGE_SYNC_ONLY
);
2605 info
.type
= MSG_NOTIFY
;
2608 info
.wparam
= wparam
;
2609 info
.lparam
= lparam
;
2611 info
.wm_char
= WMCHAR_MAP_SENDMESSAGETIMEOUT
;
2613 return send_message( &info
, NULL
, FALSE
);
2617 /***********************************************************************
2618 * SendNotifyMessageW (USER32.@)
2620 BOOL WINAPI
SendNotifyMessageW( HWND hwnd
, UINT msg
, WPARAM wparam
, LPARAM lparam
)
2622 struct send_message_info info
;
2624 if (is_pointer_message(msg
))
2626 SetLastError( ERROR_MESSAGE_SYNC_ONLY
);
2630 info
.type
= MSG_NOTIFY
;
2633 info
.wparam
= wparam
;
2634 info
.lparam
= lparam
;
2637 return send_message( &info
, NULL
, TRUE
);
2641 /***********************************************************************
2642 * SendMessageCallbackA (USER32.@)
2644 BOOL WINAPI
SendMessageCallbackA( HWND hwnd
, UINT msg
, WPARAM wparam
, LPARAM lparam
,
2645 SENDASYNCPROC callback
, ULONG_PTR data
)
2647 struct send_message_info info
;
2649 if (is_pointer_message(msg
))
2651 SetLastError( ERROR_MESSAGE_SYNC_ONLY
);
2655 info
.type
= MSG_CALLBACK
;
2658 info
.wparam
= wparam
;
2659 info
.lparam
= lparam
;
2660 info
.callback
= callback
;
2663 info
.wm_char
= WMCHAR_MAP_SENDMESSAGETIMEOUT
;
2665 return send_message( &info
, NULL
, FALSE
);
2669 /***********************************************************************
2670 * SendMessageCallbackW (USER32.@)
2672 BOOL WINAPI
SendMessageCallbackW( HWND hwnd
, UINT msg
, WPARAM wparam
, LPARAM lparam
,
2673 SENDASYNCPROC callback
, ULONG_PTR data
)
2675 struct send_message_info info
;
2677 if (is_pointer_message(msg
))
2679 SetLastError( ERROR_MESSAGE_SYNC_ONLY
);
2683 info
.type
= MSG_CALLBACK
;
2686 info
.wparam
= wparam
;
2687 info
.lparam
= lparam
;
2688 info
.callback
= callback
;
2692 return send_message( &info
, NULL
, TRUE
);
2696 /***********************************************************************
2697 * ReplyMessage (USER32.@)
2699 BOOL WINAPI
ReplyMessage( LRESULT result
)
2701 struct received_message_info
*info
= get_user_thread_info()->receive_info
;
2703 if (!info
) return FALSE
;
2704 reply_message( info
, result
, FALSE
);
2709 /***********************************************************************
2710 * InSendMessage (USER32.@)
2712 BOOL WINAPI
InSendMessage(void)
2714 return (InSendMessageEx(NULL
) & (ISMEX_SEND
|ISMEX_REPLIED
)) == ISMEX_SEND
;
2718 /***********************************************************************
2719 * InSendMessageEx (USER32.@)
2721 DWORD WINAPI
InSendMessageEx( LPVOID reserved
)
2723 struct received_message_info
*info
= get_user_thread_info()->receive_info
;
2725 if (info
) return info
->flags
;
2726 return ISMEX_NOSEND
;
2730 /***********************************************************************
2731 * PostMessageA (USER32.@)
2733 BOOL WINAPI
PostMessageA( HWND hwnd
, UINT msg
, WPARAM wparam
, LPARAM lparam
)
2735 if (!map_wparam_AtoW( msg
, &wparam
, WMCHAR_MAP_POSTMESSAGE
)) return TRUE
;
2736 return PostMessageW( hwnd
, msg
, wparam
, lparam
);
2740 /***********************************************************************
2741 * PostMessageW (USER32.@)
2743 BOOL WINAPI
PostMessageW( HWND hwnd
, UINT msg
, WPARAM wparam
, LPARAM lparam
)
2745 struct send_message_info info
;
2747 if (is_pointer_message( msg
))
2749 SetLastError( ERROR_MESSAGE_SYNC_ONLY
);
2753 TRACE( "hwnd %p msg %x (%s) wp %lx lp %lx\n",
2754 hwnd
, msg
, SPY_GetMsgName(msg
, hwnd
), wparam
, lparam
);
2756 info
.type
= MSG_POSTED
;
2759 info
.wparam
= wparam
;
2760 info
.lparam
= lparam
;
2763 if (is_broadcast(hwnd
))
2765 EnumWindows( broadcast_message_callback
, (LPARAM
)&info
);
2769 if (!hwnd
) return PostThreadMessageW( GetCurrentThreadId(), msg
, wparam
, lparam
);
2771 if (!(info
.dest_tid
= GetWindowThreadProcessId( hwnd
, NULL
))) return FALSE
;
2773 if (USER_IsExitingThread( info
.dest_tid
)) return TRUE
;
2775 return put_message_in_queue( &info
, NULL
);
2779 /**********************************************************************
2780 * PostThreadMessageA (USER32.@)
2782 BOOL WINAPI
PostThreadMessageA( DWORD thread
, UINT msg
, WPARAM wparam
, LPARAM lparam
)
2784 if (!map_wparam_AtoW( msg
, &wparam
, WMCHAR_MAP_POSTMESSAGE
)) return TRUE
;
2785 return PostThreadMessageW( thread
, msg
, wparam
, lparam
);
2789 /**********************************************************************
2790 * PostThreadMessageW (USER32.@)
2792 BOOL WINAPI
PostThreadMessageW( DWORD thread
, UINT msg
, WPARAM wparam
, LPARAM lparam
)
2794 struct send_message_info info
;
2796 if (is_pointer_message( msg
))
2798 SetLastError( ERROR_MESSAGE_SYNC_ONLY
);
2801 if (USER_IsExitingThread( thread
)) return TRUE
;
2803 info
.type
= MSG_POSTED
;
2804 info
.dest_tid
= thread
;
2807 info
.wparam
= wparam
;
2808 info
.lparam
= lparam
;
2810 return put_message_in_queue( &info
, NULL
);
2814 /***********************************************************************
2815 * PostQuitMessage (USER32.@)
2817 * Posts a quit message to the current thread's message queue.
2820 * exit_code [I] Exit code to return from message loop.
2826 * This function is not the same as calling:
2827 *|PostThreadMessage(GetCurrentThreadId(), WM_QUIT, exit_code, 0);
2828 * It instead sets a flag in the message queue that signals it to generate
2829 * a WM_QUIT message when there are no other pending sent or posted messages
2832 void WINAPI
PostQuitMessage( INT exit_code
)
2834 SERVER_START_REQ( post_quit_message
)
2836 req
->exit_code
= exit_code
;
2837 wine_server_call( req
);
2843 /***********************************************************************
2844 * PeekMessageW (USER32.@)
2846 BOOL WINAPI
PeekMessageW( MSG
*msg_out
, HWND hwnd
, UINT first
, UINT last
, UINT flags
)
2848 struct user_thread_info
*thread_info
= get_user_thread_info();
2851 USER_CheckNotLock();
2853 /* check for graphics events */
2854 USER_Driver
->pMsgWaitForMultipleObjectsEx( 0, NULL
, 0, QS_ALLINPUT
, 0 );
2856 hwnd
= WIN_GetFullHandle( hwnd
);
2860 if (!peek_message( &msg
, hwnd
, first
, last
, flags
))
2862 if (!(flags
& PM_NOYIELD
))
2865 ReleaseThunkLock(&count
);
2867 if (count
) RestoreThunkLock(count
);
2871 if (msg
.message
& 0x80000000)
2873 if (!(flags
& PM_REMOVE
))
2875 /* Have to remove the message explicitly.
2876 Do this before handling it, because the message handler may
2877 call PeekMessage again */
2878 peek_message( &msg
, msg
.hwnd
, msg
.message
, msg
.message
, flags
| PM_REMOVE
);
2880 handle_internal_message( msg
.hwnd
, msg
.message
, msg
.wParam
, msg
.lParam
);
2885 thread_info
->GetMessageTimeVal
= msg
.time
;
2886 msg
.pt
.x
= (short)LOWORD( thread_info
->GetMessagePosVal
);
2887 msg
.pt
.y
= (short)HIWORD( thread_info
->GetMessagePosVal
);
2889 HOOK_CallHooks( WH_GETMESSAGE
, HC_ACTION
, flags
& PM_REMOVE
, (LPARAM
)&msg
, TRUE
);
2891 /* copy back our internal safe copy of message data to msg_out.
2892 * msg_out is a variable from the *program*, so it can't be used
2893 * internally as it can get "corrupted" by our use of SendMessage()
2894 * (back to the program) inside the message handling itself. */
2897 SetLastError( ERROR_NOACCESS
);
2905 /***********************************************************************
2906 * PeekMessageA (USER32.@)
2908 BOOL WINAPI
PeekMessageA( MSG
*msg
, HWND hwnd
, UINT first
, UINT last
, UINT flags
)
2910 if (get_pending_wmchar( msg
, first
, last
, (flags
& PM_REMOVE
) )) return TRUE
;
2911 if (!PeekMessageW( msg
, hwnd
, first
, last
, flags
)) return FALSE
;
2912 map_wparam_WtoA( msg
, (flags
& PM_REMOVE
) );
2917 /***********************************************************************
2918 * GetMessageW (USER32.@)
2920 BOOL WINAPI
GetMessageW( MSG
*msg
, HWND hwnd
, UINT first
, UINT last
)
2922 HANDLE server_queue
= get_server_queue_handle();
2923 int mask
= QS_POSTMESSAGE
| QS_SENDMESSAGE
; /* Always selected */
2927 if ((first
<= WM_KEYLAST
) && (last
>= WM_KEYFIRST
)) mask
|= QS_KEY
;
2928 if ( ((first
<= WM_MOUSELAST
) && (last
>= WM_MOUSEFIRST
)) ||
2929 ((first
<= WM_NCMOUSELAST
) && (last
>= WM_NCMOUSEFIRST
)) ) mask
|= QS_MOUSE
;
2930 if ((first
<= WM_TIMER
) && (last
>= WM_TIMER
)) mask
|= QS_TIMER
;
2931 if ((first
<= WM_SYSTIMER
) && (last
>= WM_SYSTIMER
)) mask
|= QS_TIMER
;
2932 if ((first
<= WM_PAINT
) && (last
>= WM_PAINT
)) mask
|= QS_PAINT
;
2934 else mask
= QS_ALLINPUT
;
2936 while (!PeekMessageW( msg
, hwnd
, first
, last
, PM_REMOVE
| PM_NOYIELD
| (mask
<< 16) ))
2940 ReleaseThunkLock( &dwlc
);
2941 USER_Driver
->pMsgWaitForMultipleObjectsEx( 1, &server_queue
, INFINITE
, mask
, 0 );
2942 if (dwlc
) RestoreThunkLock( dwlc
);
2945 return (msg
->message
!= WM_QUIT
);
2949 /***********************************************************************
2950 * GetMessageA (USER32.@)
2952 BOOL WINAPI
GetMessageA( MSG
*msg
, HWND hwnd
, UINT first
, UINT last
)
2954 if (get_pending_wmchar( msg
, first
, last
, TRUE
)) return TRUE
;
2955 GetMessageW( msg
, hwnd
, first
, last
);
2956 map_wparam_WtoA( msg
, TRUE
);
2957 return (msg
->message
!= WM_QUIT
);
2961 /***********************************************************************
2962 * IsDialogMessageA (USER32.@)
2963 * IsDialogMessage (USER32.@)
2965 BOOL WINAPI
IsDialogMessageA( HWND hwndDlg
, LPMSG pmsg
)
2968 map_wparam_AtoW( msg
.message
, &msg
.wParam
, WMCHAR_MAP_NOMAPPING
);
2969 return IsDialogMessageW( hwndDlg
, &msg
);
2973 /***********************************************************************
2974 * TranslateMessage (USER32.@)
2976 * Implementation of TranslateMessage.
2978 * TranslateMessage translates virtual-key messages into character-messages,
2980 * WM_KEYDOWN/WM_KEYUP combinations produce a WM_CHAR or WM_DEADCHAR message.
2981 * ditto replacing WM_* with WM_SYS*
2982 * This produces WM_CHAR messages only for keys mapped to ASCII characters
2983 * by the keyboard driver.
2985 * If the message is WM_KEYDOWN, WM_KEYUP, WM_SYSKEYDOWN, or WM_SYSKEYUP, the
2986 * return value is nonzero, regardless of the translation.
2989 BOOL WINAPI
TranslateMessage( const MSG
*msg
)
2995 if (msg
->message
< WM_KEYFIRST
|| msg
->message
> WM_KEYLAST
) return FALSE
;
2996 if (msg
->message
!= WM_KEYDOWN
&& msg
->message
!= WM_SYSKEYDOWN
) return TRUE
;
2998 TRACE_(key
)("Translating key %s (%04lx), scancode %02x\n",
2999 SPY_GetVKeyName(msg
->wParam
), msg
->wParam
, LOBYTE(HIWORD(msg
->lParam
)));
3001 if ( msg
->wParam
== VK_PROCESSKEY
)
3002 return ImmTranslateMessage(msg
->hwnd
, msg
->message
, msg
->wParam
, msg
->lParam
);
3004 GetKeyboardState( state
);
3005 /* FIXME : should handle ToUnicode yielding 2 */
3006 switch (ToUnicode(msg
->wParam
, HIWORD(msg
->lParam
), state
, wp
, 2, 0))
3009 message
= (msg
->message
== WM_KEYDOWN
) ? WM_CHAR
: WM_SYSCHAR
;
3010 TRACE_(key
)("1 -> PostMessageW(%p,%s,%04x,%08lx)\n",
3011 msg
->hwnd
, SPY_GetMsgName(message
, msg
->hwnd
), wp
[0], msg
->lParam
);
3012 PostMessageW( msg
->hwnd
, message
, wp
[0], msg
->lParam
);
3016 message
= (msg
->message
== WM_KEYDOWN
) ? WM_DEADCHAR
: WM_SYSDEADCHAR
;
3017 TRACE_(key
)("-1 -> PostMessageW(%p,%s,%04x,%08lx)\n",
3018 msg
->hwnd
, SPY_GetMsgName(message
, msg
->hwnd
), wp
[0], msg
->lParam
);
3019 PostMessageW( msg
->hwnd
, message
, wp
[0], msg
->lParam
);
3026 /***********************************************************************
3027 * DispatchMessageA (USER32.@)
3029 * See DispatchMessageW.
3031 LRESULT WINAPI
DispatchMessageA( const MSG
* msg
)
3035 /* Process timer messages */
3036 if ((msg
->message
== WM_TIMER
) || (msg
->message
== WM_SYSTIMER
))
3038 if (msg
->lParam
) return CallWindowProcA( (WNDPROC
)msg
->lParam
, msg
->hwnd
,
3039 msg
->message
, msg
->wParam
, GetTickCount() );
3041 if (!msg
->hwnd
) return 0;
3043 SPY_EnterMessage( SPY_DISPATCHMESSAGE
, msg
->hwnd
, msg
->message
,
3044 msg
->wParam
, msg
->lParam
);
3046 if (!WINPROC_call_window( msg
->hwnd
, msg
->message
, msg
->wParam
, msg
->lParam
,
3047 &retval
, FALSE
, WMCHAR_MAP_DISPATCHMESSAGE
))
3049 if (!IsWindow( msg
->hwnd
)) SetLastError( ERROR_INVALID_WINDOW_HANDLE
);
3050 else SetLastError( ERROR_MESSAGE_SYNC_ONLY
);
3054 SPY_ExitMessage( SPY_RESULT_OK
, msg
->hwnd
, msg
->message
, retval
,
3055 msg
->wParam
, msg
->lParam
);
3057 if (msg
->message
== WM_PAINT
)
3059 /* send a WM_NCPAINT and WM_ERASEBKGND if the non-client area is still invalid */
3060 HRGN hrgn
= CreateRectRgn( 0, 0, 0, 0 );
3061 GetUpdateRgn( msg
->hwnd
, hrgn
, TRUE
);
3062 DeleteObject( hrgn
);
3068 /***********************************************************************
3069 * DispatchMessageW (USER32.@) Process a message
3071 * Process the message specified in the structure *_msg_.
3073 * If the lpMsg parameter points to a WM_TIMER message and the
3074 * parameter of the WM_TIMER message is not NULL, the lParam parameter
3075 * points to the function that is called instead of the window
3078 * The message must be valid.
3082 * DispatchMessage() returns the result of the window procedure invoked.
3089 LRESULT WINAPI
DispatchMessageW( const MSG
* msg
)
3093 /* Process timer messages */
3094 if ((msg
->message
== WM_TIMER
) || (msg
->message
== WM_SYSTIMER
))
3096 if (msg
->lParam
) return CallWindowProcW( (WNDPROC
)msg
->lParam
, msg
->hwnd
,
3097 msg
->message
, msg
->wParam
, GetTickCount() );
3099 if (!msg
->hwnd
) return 0;
3101 SPY_EnterMessage( SPY_DISPATCHMESSAGE
, msg
->hwnd
, msg
->message
,
3102 msg
->wParam
, msg
->lParam
);
3104 if (!WINPROC_call_window( msg
->hwnd
, msg
->message
, msg
->wParam
, msg
->lParam
,
3105 &retval
, TRUE
, WMCHAR_MAP_DISPATCHMESSAGE
))
3107 if (!IsWindow( msg
->hwnd
)) SetLastError( ERROR_INVALID_WINDOW_HANDLE
);
3108 else SetLastError( ERROR_MESSAGE_SYNC_ONLY
);
3112 SPY_ExitMessage( SPY_RESULT_OK
, msg
->hwnd
, msg
->message
, retval
,
3113 msg
->wParam
, msg
->lParam
);
3115 if (msg
->message
== WM_PAINT
)
3117 /* send a WM_NCPAINT and WM_ERASEBKGND if the non-client area is still invalid */
3118 HRGN hrgn
= CreateRectRgn( 0, 0, 0, 0 );
3119 GetUpdateRgn( msg
->hwnd
, hrgn
, TRUE
);
3120 DeleteObject( hrgn
);
3126 /***********************************************************************
3127 * GetMessagePos (USER.119)
3128 * GetMessagePos (USER32.@)
3130 * The GetMessagePos() function returns a long value representing a
3131 * cursor position, in screen coordinates, when the last message
3132 * retrieved by the GetMessage() function occurs. The x-coordinate is
3133 * in the low-order word of the return value, the y-coordinate is in
3134 * the high-order word. The application can use the MAKEPOINT()
3135 * macro to obtain a POINT structure from the return value.
3137 * For the current cursor position, use GetCursorPos().
3141 * Cursor position of last message on success, zero on failure.
3148 DWORD WINAPI
GetMessagePos(void)
3150 return get_user_thread_info()->GetMessagePosVal
;
3154 /***********************************************************************
3155 * GetMessageTime (USER.120)
3156 * GetMessageTime (USER32.@)
3158 * GetMessageTime() returns the message time for the last message
3159 * retrieved by the function. The time is measured in milliseconds with
3160 * the same offset as GetTickCount().
3162 * Since the tick count wraps, this is only useful for moderately short
3163 * relative time comparisons.
3167 * Time of last message on success, zero on failure.
3169 LONG WINAPI
GetMessageTime(void)
3171 return get_user_thread_info()->GetMessageTimeVal
;
3175 /***********************************************************************
3176 * GetMessageExtraInfo (USER.288)
3177 * GetMessageExtraInfo (USER32.@)
3179 LPARAM WINAPI
GetMessageExtraInfo(void)
3181 return get_user_thread_info()->GetMessageExtraInfoVal
;
3185 /***********************************************************************
3186 * SetMessageExtraInfo (USER32.@)
3188 LPARAM WINAPI
SetMessageExtraInfo(LPARAM lParam
)
3190 struct user_thread_info
*thread_info
= get_user_thread_info();
3191 LONG old_value
= thread_info
->GetMessageExtraInfoVal
;
3192 thread_info
->GetMessageExtraInfoVal
= lParam
;
3197 /***********************************************************************
3198 * WaitMessage (USER.112) Suspend thread pending messages
3199 * WaitMessage (USER32.@) Suspend thread pending messages
3201 * WaitMessage() suspends a thread until events appear in the thread's
3204 BOOL WINAPI
WaitMessage(void)
3206 return (MsgWaitForMultipleObjectsEx( 0, NULL
, INFINITE
, QS_ALLINPUT
, 0 ) != WAIT_FAILED
);
3210 /***********************************************************************
3211 * MsgWaitForMultipleObjectsEx (USER32.@)
3213 DWORD WINAPI
MsgWaitForMultipleObjectsEx( DWORD count
, CONST HANDLE
*pHandles
,
3214 DWORD timeout
, DWORD mask
, DWORD flags
)
3216 HANDLE handles
[MAXIMUM_WAIT_OBJECTS
];
3219 if (count
> MAXIMUM_WAIT_OBJECTS
-1)
3221 SetLastError( ERROR_INVALID_PARAMETER
);
3225 /* set the queue mask */
3226 SERVER_START_REQ( set_queue_mask
)
3228 req
->wake_mask
= (flags
& MWMO_INPUTAVAILABLE
) ? mask
: 0;
3229 req
->changed_mask
= mask
;
3231 wine_server_call( req
);
3235 /* add the queue to the handle list */
3236 for (i
= 0; i
< count
; i
++) handles
[i
] = pHandles
[i
];
3237 handles
[count
] = get_server_queue_handle();
3239 ReleaseThunkLock( &lock
);
3240 ret
= USER_Driver
->pMsgWaitForMultipleObjectsEx( count
+1, handles
, timeout
, mask
, flags
);
3241 if (lock
) RestoreThunkLock( lock
);
3246 /***********************************************************************
3247 * MsgWaitForMultipleObjects (USER32.@)
3249 DWORD WINAPI
MsgWaitForMultipleObjects( DWORD count
, CONST HANDLE
*handles
,
3250 BOOL wait_all
, DWORD timeout
, DWORD mask
)
3252 return MsgWaitForMultipleObjectsEx( count
, handles
, timeout
, mask
,
3253 wait_all
? MWMO_WAITALL
: 0 );
3257 /***********************************************************************
3258 * WaitForInputIdle (USER32.@)
3260 DWORD WINAPI
WaitForInputIdle( HANDLE hProcess
, DWORD dwTimeOut
)
3262 DWORD start_time
, elapsed
, ret
;
3265 handles
[0] = hProcess
;
3266 SERVER_START_REQ( get_process_idle_event
)
3268 req
->handle
= hProcess
;
3269 if (!(ret
= wine_server_call_err( req
))) handles
[1] = reply
->event
;
3272 if (ret
) return WAIT_FAILED
; /* error */
3273 if (!handles
[1]) return 0; /* no event to wait on */
3275 start_time
= GetTickCount();
3278 TRACE("waiting for %p\n", handles
[1] );
3281 ret
= MsgWaitForMultipleObjects ( 2, handles
, FALSE
, dwTimeOut
- elapsed
, QS_SENDMESSAGE
);
3286 case WAIT_OBJECT_0
+2:
3287 process_sent_messages();
3291 TRACE("timeout or error\n");
3294 TRACE("finished\n");
3297 if (dwTimeOut
!= INFINITE
)
3299 elapsed
= GetTickCount() - start_time
;
3300 if (elapsed
> dwTimeOut
)
3306 return WAIT_TIMEOUT
;
3310 /***********************************************************************
3311 * UserYield (USER.332)
3313 void WINAPI
UserYield16(void)
3317 /* Handle sent messages */
3318 process_sent_messages();
3321 ReleaseThunkLock(&count
);
3325 RestoreThunkLock(count
);
3326 /* Handle sent messages again */
3327 process_sent_messages();
3332 /***********************************************************************
3333 * RegisterWindowMessageA (USER32.@)
3334 * RegisterWindowMessage (USER.118)
3336 UINT WINAPI
RegisterWindowMessageA( LPCSTR str
)
3338 UINT ret
= GlobalAddAtomA(str
);
3339 TRACE("%s, ret=%x\n", str
, ret
);
3344 /***********************************************************************
3345 * RegisterWindowMessageW (USER32.@)
3347 UINT WINAPI
RegisterWindowMessageW( LPCWSTR str
)
3349 UINT ret
= GlobalAddAtomW(str
);
3350 TRACE("%s ret=%x\n", debugstr_w(str
), ret
);
3354 typedef struct BroadcastParm
3365 static BOOL CALLBACK
bcast_childwindow( HWND hw
, LPARAM lp
)
3367 BroadcastParm
*parm
= (BroadcastParm
*)lp
;
3368 DWORD_PTR retval
= 0;
3371 if (parm
->flags
& BSF_IGNORECURRENTTASK
&& WIN_IsCurrentProcess(hw
))
3373 TRACE("Not telling myself %p\n", hw
);
3377 /* I don't know 100% for sure if this is what Windows does, but it fits the tests */
3378 if (parm
->flags
& BSF_QUERY
)
3380 TRACE("Telling window %p using SendMessageTimeout\n", hw
);
3382 /* Not tested for conflicting flags */
3383 if (parm
->flags
& BSF_FORCEIFHUNG
|| parm
->flags
& BSF_NOHANG
)
3384 lresult
= SendMessageTimeoutW( hw
, parm
->msg
, parm
->wp
, parm
->lp
, SMTO_ABORTIFHUNG
, 2000, &retval
);
3385 else if (parm
->flags
& BSF_NOTIMEOUTIFNOTHUNG
)
3386 lresult
= SendMessageTimeoutW( hw
, parm
->msg
, parm
->wp
, parm
->lp
, SMTO_NOTIMEOUTIFNOTHUNG
, 2000, &retval
);
3388 lresult
= SendMessageTimeoutW( hw
, parm
->msg
, parm
->wp
, parm
->lp
, SMTO_NORMAL
, 2000, &retval
);
3390 if (!lresult
&& GetLastError() == ERROR_TIMEOUT
)
3392 WARN("Timed out!\n");
3393 if (!(parm
->flags
& BSF_FORCEIFHUNG
))
3396 if (retval
== BROADCAST_QUERY_DENY
)
3405 else if (parm
->flags
& BSF_POSTMESSAGE
)
3407 TRACE("Telling window %p using PostMessage\n", hw
);
3408 PostMessageW( hw
, parm
->msg
, parm
->wp
, parm
->lp
);
3412 TRACE("Telling window %p using SendNotifyMessage\n", hw
);
3413 SendNotifyMessageW( hw
, parm
->msg
, parm
->wp
, parm
->lp
);
3419 static BOOL CALLBACK
bcast_desktop( LPWSTR desktop
, LPARAM lp
)
3423 BroadcastParm
*parm
= (BroadcastParm
*)lp
;
3425 TRACE("desktop: %s\n", debugstr_w( desktop
));
3427 hdesktop
= open_winstation_desktop( parm
->winsta
, desktop
, 0, FALSE
, DESKTOP_ENUMERATE
|DESKTOP_WRITEOBJECTS
|STANDARD_RIGHTS_WRITE
);
3430 FIXME("Could not open desktop %s\n", debugstr_w(desktop
));
3434 ret
= EnumDesktopWindows( hdesktop
, bcast_childwindow
, lp
);
3435 CloseDesktop(hdesktop
);
3436 TRACE("-->%d\n", ret
);
3437 return parm
->success
;
3440 static BOOL CALLBACK
bcast_winsta( LPWSTR winsta
, LPARAM lp
)
3443 HWINSTA hwinsta
= OpenWindowStationW( winsta
, FALSE
, WINSTA_ENUMDESKTOPS
);
3444 TRACE("hwinsta: %p/%s/%08x\n", hwinsta
, debugstr_w( winsta
), GetLastError());
3447 ((BroadcastParm
*)lp
)->winsta
= hwinsta
;
3448 ret
= EnumDesktopsW( hwinsta
, bcast_desktop
, lp
);
3449 CloseWindowStation( hwinsta
);
3450 TRACE("-->%d\n", ret
);
3454 /***********************************************************************
3455 * BroadcastSystemMessageA (USER32.@)
3456 * BroadcastSystemMessage (USER32.@)
3458 LONG WINAPI
BroadcastSystemMessageA( DWORD flags
, LPDWORD recipients
, UINT msg
, WPARAM wp
, LPARAM lp
)
3460 return BroadcastSystemMessageExA( flags
, recipients
, msg
, wp
, lp
, NULL
);
3464 /***********************************************************************
3465 * BroadcastSystemMessageW (USER32.@)
3467 LONG WINAPI
BroadcastSystemMessageW( DWORD flags
, LPDWORD recipients
, UINT msg
, WPARAM wp
, LPARAM lp
)
3469 return BroadcastSystemMessageExW( flags
, recipients
, msg
, wp
, lp
, NULL
);
3472 /***********************************************************************
3473 * BroadcastSystemMessageExA (USER32.@)
3475 LONG WINAPI
BroadcastSystemMessageExA( DWORD flags
, LPDWORD recipients
, UINT msg
, WPARAM wp
, LPARAM lp
, PBSMINFO pinfo
)
3477 map_wparam_AtoW( msg
, &wp
, WMCHAR_MAP_NOMAPPING
);
3478 return BroadcastSystemMessageExW( flags
, recipients
, msg
, wp
, lp
, NULL
);
3482 /***********************************************************************
3483 * BroadcastSystemMessageExW (USER32.@)
3485 LONG WINAPI
BroadcastSystemMessageExW( DWORD flags
, LPDWORD recipients
, UINT msg
, WPARAM wp
, LPARAM lp
, PBSMINFO pinfo
)
3488 DWORD recips
= BSM_ALLCOMPONENTS
;
3490 static const DWORD all_flags
= ( BSF_QUERY
| BSF_IGNORECURRENTTASK
| BSF_FLUSHDISK
| BSF_NOHANG
3491 | BSF_POSTMESSAGE
| BSF_FORCEIFHUNG
| BSF_NOTIMEOUTIFNOTHUNG
3492 | BSF_ALLOWSFW
| BSF_SENDNOTIFYMESSAGE
| BSF_RETURNHDESK
| BSF_LUID
);
3494 TRACE("Flags: %08x, recipients: %p(0x%x), msg: %04x, wparam: %08lx, lparam: %08lx\n", flags
, recipients
,
3495 (recipients
? *recipients
: recips
), msg
, wp
, lp
);
3497 if (flags
& ~all_flags
)
3499 SetLastError(ERROR_INVALID_PARAMETER
);
3504 recipients
= &recips
;
3506 if ( pinfo
&& flags
& BSF_QUERY
)
3507 FIXME("Not returning PBSMINFO information yet\n");
3510 parm
.recipients
= recipients
;
3514 parm
.success
= TRUE
;
3516 if (*recipients
& BSM_ALLDESKTOPS
|| *recipients
== BSM_ALLCOMPONENTS
)
3517 ret
= EnumWindowStationsW(bcast_winsta
, (LONG_PTR
)&parm
);
3518 else if (*recipients
& BSM_APPLICATIONS
)
3520 EnumWindows(bcast_childwindow
, (LONG_PTR
)&parm
);
3524 FIXME("Recipients %08x not supported!\n", *recipients
);
3529 /***********************************************************************
3530 * SetMessageQueue (USER32.@)
3532 BOOL WINAPI
SetMessageQueue( INT size
)
3534 /* now obsolete the message queue will be expanded dynamically as necessary */
3539 /***********************************************************************
3540 * MessageBeep (USER32.@)
3542 BOOL WINAPI
MessageBeep( UINT i
)
3545 SystemParametersInfoA( SPI_GETBEEP
, 0, &active
, FALSE
);
3546 if (active
) USER_Driver
->pBeep();
3551 /***********************************************************************
3552 * SetTimer (USER32.@)
3554 UINT_PTR WINAPI
SetTimer( HWND hwnd
, UINT_PTR id
, UINT timeout
, TIMERPROC proc
)
3557 WNDPROC winproc
= 0;
3559 if (proc
) winproc
= WINPROC_AllocProc( (WNDPROC
)proc
, NULL
);
3561 SERVER_START_REQ( set_win_timer
)
3564 req
->msg
= WM_TIMER
;
3566 req
->rate
= max( timeout
, SYS_TIMER_RATE
);
3567 req
->lparam
= (unsigned long)winproc
;
3568 if (!wine_server_call_err( req
))
3571 if (!ret
) ret
= TRUE
;
3577 TRACE("Added %p %lx %p timeout %d\n", hwnd
, id
, winproc
, timeout
);
3582 /***********************************************************************
3583 * SetSystemTimer (USER32.@)
3585 UINT_PTR WINAPI
SetSystemTimer( HWND hwnd
, UINT_PTR id
, UINT timeout
, TIMERPROC proc
)
3588 WNDPROC winproc
= 0;
3590 if (proc
) winproc
= WINPROC_AllocProc( (WNDPROC
)proc
, NULL
);
3592 SERVER_START_REQ( set_win_timer
)
3595 req
->msg
= WM_SYSTIMER
;
3597 req
->rate
= max( timeout
, SYS_TIMER_RATE
);
3598 req
->lparam
= (unsigned long)winproc
;
3599 if (!wine_server_call_err( req
))
3602 if (!ret
) ret
= TRUE
;
3608 TRACE("Added %p %lx %p timeout %d\n", hwnd
, id
, winproc
, timeout
);
3613 /***********************************************************************
3614 * KillTimer (USER32.@)
3616 BOOL WINAPI
KillTimer( HWND hwnd
, UINT_PTR id
)
3620 SERVER_START_REQ( kill_win_timer
)
3623 req
->msg
= WM_TIMER
;
3625 ret
= !wine_server_call_err( req
);
3632 /***********************************************************************
3633 * KillSystemTimer (USER32.@)
3635 BOOL WINAPI
KillSystemTimer( HWND hwnd
, UINT_PTR id
)
3639 SERVER_START_REQ( kill_win_timer
)
3642 req
->msg
= WM_SYSTIMER
;
3644 ret
= !wine_server_call_err( req
);
3651 /**********************************************************************
3652 * GetGUIThreadInfo (USER32.@)
3654 BOOL WINAPI
GetGUIThreadInfo( DWORD id
, GUITHREADINFO
*info
)
3658 SERVER_START_REQ( get_thread_input
)
3661 if ((ret
= !wine_server_call_err( req
)))
3664 info
->hwndActive
= reply
->active
;
3665 info
->hwndFocus
= reply
->focus
;
3666 info
->hwndCapture
= reply
->capture
;
3667 info
->hwndMenuOwner
= reply
->menu_owner
;
3668 info
->hwndMoveSize
= reply
->move_size
;
3669 info
->hwndCaret
= reply
->caret
;
3670 info
->rcCaret
.left
= reply
->rect
.left
;
3671 info
->rcCaret
.top
= reply
->rect
.top
;
3672 info
->rcCaret
.right
= reply
->rect
.right
;
3673 info
->rcCaret
.bottom
= reply
->rect
.bottom
;
3674 if (reply
->menu_owner
) info
->flags
|= GUI_INMENUMODE
;
3675 if (reply
->move_size
) info
->flags
|= GUI_INMOVESIZE
;
3676 if (reply
->caret
) info
->flags
|= GUI_CARETBLINKING
;
3684 /******************************************************************
3685 * IsHungAppWindow (USER32.@)
3688 BOOL WINAPI
IsHungAppWindow( HWND hWnd
)
3692 SERVER_START_REQ( is_window_hung
)
3695 ret
= !wine_server_call_err( req
) && reply
->is_hung
;