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 /* make sure that the buffer contains a valid null-terminated Unicode string */
248 static inline BOOL
check_string( LPCWSTR str
, size_t size
)
250 for (size
/= sizeof(WCHAR
); size
; size
--, str
++)
251 if (!*str
) return TRUE
;
255 /* make sure that there is space for 'size' bytes in buffer, growing it if needed */
256 static inline void *get_buffer_space( void **buffer
, size_t size
)
262 if (!(ret
= HeapReAlloc( GetProcessHeap(), 0, *buffer
, size
)))
263 HeapFree( GetProcessHeap(), 0, *buffer
);
265 else ret
= HeapAlloc( GetProcessHeap(), 0, size
);
271 /* check whether a combobox expects strings or ids in CB_ADDSTRING/CB_INSERTSTRING */
272 static inline BOOL
combobox_has_strings( HWND hwnd
)
274 DWORD style
= GetWindowLongA( hwnd
, GWL_STYLE
);
275 return (!(style
& (CBS_OWNERDRAWFIXED
| CBS_OWNERDRAWVARIABLE
)) || (style
& CBS_HASSTRINGS
));
278 /* check whether a listbox expects strings or ids in LB_ADDSTRING/LB_INSERTSTRING */
279 static inline BOOL
listbox_has_strings( HWND hwnd
)
281 DWORD style
= GetWindowLongA( hwnd
, GWL_STYLE
);
282 return (!(style
& (LBS_OWNERDRAWFIXED
| LBS_OWNERDRAWVARIABLE
)) || (style
& LBS_HASSTRINGS
));
285 /* check whether message is in the range of keyboard messages */
286 static inline BOOL
is_keyboard_message( UINT message
)
288 return (message
>= WM_KEYFIRST
&& message
<= WM_KEYLAST
);
291 /* check whether message is in the range of mouse messages */
292 static inline BOOL
is_mouse_message( UINT message
)
294 return ((message
>= WM_NCMOUSEFIRST
&& message
<= WM_NCMOUSELAST
) ||
295 (message
>= WM_MOUSEFIRST
&& message
<= WM_MOUSELAST
));
298 /* check whether message matches the specified hwnd filter */
299 static inline BOOL
check_hwnd_filter( const MSG
*msg
, HWND hwnd_filter
)
301 if (!hwnd_filter
|| hwnd_filter
== GetDesktopWindow()) return TRUE
;
302 return (msg
->hwnd
== hwnd_filter
|| IsChild( hwnd_filter
, msg
->hwnd
));
305 /* check for pending WM_CHAR message with DBCS trailing byte */
306 static inline BOOL
get_pending_wmchar( MSG
*msg
, UINT first
, UINT last
, BOOL remove
)
308 struct wm_char_mapping_data
*data
= get_user_thread_info()->wmchar_data
;
310 if (!data
|| !data
->get_msg
.message
) return FALSE
;
311 if ((first
|| last
) && (first
> WM_CHAR
|| last
< WM_CHAR
)) return FALSE
;
312 if (!msg
) return FALSE
;
313 *msg
= data
->get_msg
;
314 if (remove
) data
->get_msg
.message
= 0;
318 /***********************************************************************
319 * broadcast_message_callback
321 * Helper callback for broadcasting messages.
323 static BOOL CALLBACK
broadcast_message_callback( HWND hwnd
, LPARAM lparam
)
325 struct send_message_info
*info
= (struct send_message_info
*)lparam
;
326 if (!(GetWindowLongW( hwnd
, GWL_STYLE
) & (WS_POPUP
|WS_CAPTION
))) return TRUE
;
330 SendMessageTimeoutW( hwnd
, info
->msg
, info
->wparam
, info
->lparam
,
331 info
->flags
, info
->timeout
, NULL
);
334 SendMessageTimeoutA( hwnd
, info
->msg
, info
->wparam
, info
->lparam
,
335 info
->flags
, info
->timeout
, NULL
);
338 SendNotifyMessageW( hwnd
, info
->msg
, info
->wparam
, info
->lparam
);
341 SendMessageCallbackW( hwnd
, info
->msg
, info
->wparam
, info
->lparam
,
342 info
->callback
, info
->data
);
345 PostMessageW( hwnd
, info
->msg
, info
->wparam
, info
->lparam
);
348 ERR( "bad type %d\n", info
->type
);
355 /***********************************************************************
358 * Convert the wparam of an ASCII message to Unicode.
360 BOOL
map_wparam_AtoW( UINT message
, WPARAM
*wparam
, enum wm_char_mapping mapping
)
369 /* WM_CHAR is magic: a DBCS char can be sent/posted as two consecutive WM_CHAR
370 * messages, in which case the first char is stored, and the conversion
371 * to Unicode only takes place once the second char is sent/posted.
373 if (mapping
!= WMCHAR_MAP_NOMAPPING
)
375 struct wm_char_mapping_data
*data
= get_user_thread_info()->wmchar_data
;
376 BYTE low
= LOBYTE(*wparam
);
381 ch
[1] = HIBYTE(*wparam
);
382 RtlMultiByteToUnicodeN( wch
, sizeof(wch
), NULL
, ch
, 2 );
383 TRACE( "map %02x,%02x -> %04x mapping %u\n", (BYTE
)ch
[0], (BYTE
)ch
[1], wch
[0], mapping
);
384 if (data
) data
->lead_byte
[mapping
] = 0;
386 else if (data
&& data
->lead_byte
[mapping
])
388 ch
[0] = data
->lead_byte
[mapping
];
390 RtlMultiByteToUnicodeN( wch
, sizeof(wch
), NULL
, ch
, 2 );
391 TRACE( "map stored %02x,%02x -> %04x mapping %u\n", (BYTE
)ch
[0], (BYTE
)ch
[1], wch
[0], mapping
);
392 data
->lead_byte
[mapping
] = 0;
394 else if (!IsDBCSLeadByte( low
))
397 RtlMultiByteToUnicodeN( wch
, sizeof(wch
), NULL
, ch
, 1 );
398 TRACE( "map %02x -> %04x\n", (BYTE
)ch
[0], wch
[0] );
399 if (data
) data
->lead_byte
[mapping
] = 0;
401 else /* store it and wait for trail byte */
405 if (!(data
= HeapAlloc( GetProcessHeap(), HEAP_ZERO_MEMORY
, sizeof(*data
) )))
407 get_user_thread_info()->wmchar_data
= data
;
409 TRACE( "storing lead byte %02x mapping %u\n", low
, mapping
);
410 data
->lead_byte
[mapping
] = low
;
413 *wparam
= MAKEWPARAM(wch
[0], wch
[1]);
416 /* else fall through */
418 case EM_SETPASSWORDCHAR
:
423 ch
[0] = LOBYTE(*wparam
);
424 ch
[1] = HIBYTE(*wparam
);
425 RtlMultiByteToUnicodeN( wch
, sizeof(wch
), NULL
, ch
, 2 );
426 *wparam
= MAKEWPARAM(wch
[0], wch
[1]);
429 ch
[0] = HIBYTE(*wparam
);
430 ch
[1] = LOBYTE(*wparam
);
431 if (ch
[0]) RtlMultiByteToUnicodeN( wch
, sizeof(wch
[0]), NULL
, ch
, 2 );
432 else RtlMultiByteToUnicodeN( wch
, sizeof(wch
[0]), NULL
, ch
+ 1, 1 );
433 *wparam
= MAKEWPARAM(wch
[0], HIWORD(*wparam
));
440 /***********************************************************************
443 * Convert the wparam of a Unicode message to ASCII.
445 static void map_wparam_WtoA( MSG
*msg
, BOOL remove
)
454 if (!HIWORD(msg
->wParam
))
456 wch
[0] = LOWORD(msg
->wParam
);
458 RtlUnicodeToMultiByteN( (LPSTR
)ch
, 2, &len
, wch
, sizeof(wch
[0]) );
459 if (len
== 2) /* DBCS char */
461 struct wm_char_mapping_data
*data
= get_user_thread_info()->wmchar_data
;
464 if (!(data
= HeapAlloc( GetProcessHeap(), HEAP_ZERO_MEMORY
, sizeof(*data
) ))) return;
465 get_user_thread_info()->wmchar_data
= data
;
469 data
->get_msg
= *msg
;
470 data
->get_msg
.wParam
= ch
[1];
476 /* else fall through */
478 case EM_SETPASSWORDCHAR
:
483 wch
[0] = LOWORD(msg
->wParam
);
484 wch
[1] = HIWORD(msg
->wParam
);
486 RtlUnicodeToMultiByteN( (LPSTR
)ch
, 2, NULL
, wch
, sizeof(wch
) );
487 msg
->wParam
= MAKEWPARAM( ch
[0] | (ch
[1] << 8), 0 );
490 wch
[0] = LOWORD(msg
->wParam
);
492 RtlUnicodeToMultiByteN( (LPSTR
)ch
, 2, &len
, wch
, sizeof(wch
[0]) );
494 msg
->wParam
= MAKEWPARAM( (ch
[0] << 8) | ch
[1], HIWORD(msg
->wParam
) );
496 msg
->wParam
= MAKEWPARAM( ch
[0], HIWORD(msg
->wParam
) );
502 /***********************************************************************
505 * Pack a message for sending to another process.
506 * Return the size of the data we expect in the message reply.
507 * Set data->count to -1 if there is an error.
509 static size_t pack_message( HWND hwnd
, UINT message
, WPARAM wparam
, LPARAM lparam
,
510 struct packed_message
*data
)
518 CREATESTRUCTW
*cs
= (CREATESTRUCTW
*)lparam
;
519 push_data( data
, cs
, sizeof(*cs
) );
520 if (HIWORD(cs
->lpszName
)) push_string( data
, cs
->lpszName
);
521 if (HIWORD(cs
->lpszClass
)) push_string( data
, cs
->lpszClass
);
525 case WM_ASKCBFORMATNAME
:
526 return wparam
* sizeof(WCHAR
);
527 case WM_WININICHANGE
:
528 if (lparam
) push_string(data
, (LPWSTR
)lparam
);
531 case WM_DEVMODECHANGE
:
536 push_string( data
, (LPWSTR
)lparam
);
538 case WM_GETMINMAXINFO
:
539 push_data( data
, (MINMAXINFO
*)lparam
, sizeof(MINMAXINFO
) );
540 return sizeof(MINMAXINFO
);
542 push_data( data
, (DRAWITEMSTRUCT
*)lparam
, sizeof(DRAWITEMSTRUCT
) );
545 push_data( data
, (MEASUREITEMSTRUCT
*)lparam
, sizeof(MEASUREITEMSTRUCT
) );
546 return sizeof(MEASUREITEMSTRUCT
);
548 push_data( data
, (DELETEITEMSTRUCT
*)lparam
, sizeof(DELETEITEMSTRUCT
) );
551 push_data( data
, (COMPAREITEMSTRUCT
*)lparam
, sizeof(COMPAREITEMSTRUCT
) );
553 case WM_WINDOWPOSCHANGING
:
554 case WM_WINDOWPOSCHANGED
:
555 push_data( data
, (WINDOWPOS
*)lparam
, sizeof(WINDOWPOS
) );
556 return sizeof(WINDOWPOS
);
559 COPYDATASTRUCT
*cp
= (COPYDATASTRUCT
*)lparam
;
560 push_data( data
, cp
, sizeof(*cp
) );
561 if (cp
->lpData
) push_data( data
, cp
->lpData
, cp
->cbData
);
565 /* WM_NOTIFY cannot be sent across processes (MSDN) */
569 push_data( data
, (HELPINFO
*)lparam
, sizeof(HELPINFO
) );
571 case WM_STYLECHANGING
:
572 case WM_STYLECHANGED
:
573 push_data( data
, (STYLESTRUCT
*)lparam
, sizeof(STYLESTRUCT
) );
578 push_data( data
, (RECT
*)lparam
, sizeof(RECT
) );
583 NCCALCSIZE_PARAMS
*nc
= (NCCALCSIZE_PARAMS
*)lparam
;
584 push_data( data
, nc
, sizeof(*nc
) );
585 push_data( data
, nc
->lppos
, sizeof(*nc
->lppos
) );
586 return sizeof(*nc
) + sizeof(*nc
->lppos
);
589 if (lparam
) push_data( data
, (MSG
*)lparam
, sizeof(MSG
) );
591 case SBM_SETSCROLLINFO
:
592 push_data( data
, (SCROLLINFO
*)lparam
, sizeof(SCROLLINFO
) );
594 case SBM_GETSCROLLINFO
:
595 push_data( data
, (SCROLLINFO
*)lparam
, sizeof(SCROLLINFO
) );
596 return sizeof(SCROLLINFO
);
597 case SBM_GETSCROLLBARINFO
:
599 const SCROLLBARINFO
*info
= (const SCROLLBARINFO
*)lparam
;
600 size_t size
= min( info
->cbSize
, sizeof(SCROLLBARINFO
) );
601 push_data( data
, info
, size
);
609 if (wparam
) size
+= sizeof(DWORD
);
610 if (lparam
) size
+= sizeof(DWORD
);
615 case CB_GETDROPPEDCONTROLRECT
:
619 push_data( data
, (RECT
*)lparam
, sizeof(RECT
) );
623 WORD
*pw
= (WORD
*)lparam
;
624 push_data( data
, pw
, sizeof(*pw
) );
625 return *pw
* sizeof(WCHAR
);
629 if (wparam
) push_data( data
, (UINT
*)lparam
, sizeof(UINT
) * wparam
);
632 case CB_INSERTSTRING
:
634 case CB_FINDSTRINGEXACT
:
635 case CB_SELECTSTRING
:
636 if (combobox_has_strings( hwnd
)) push_string( data
, (LPWSTR
)lparam
);
639 if (!combobox_has_strings( hwnd
)) return sizeof(ULONG_PTR
);
640 return (SendMessageW( hwnd
, CB_GETLBTEXTLEN
, wparam
, 0 ) + 1) * sizeof(WCHAR
);
642 case LB_INSERTSTRING
:
644 case LB_FINDSTRINGEXACT
:
645 case LB_SELECTSTRING
:
646 if (listbox_has_strings( hwnd
)) push_string( data
, (LPWSTR
)lparam
);
649 if (!listbox_has_strings( hwnd
)) return sizeof(ULONG_PTR
);
650 return (SendMessageW( hwnd
, LB_GETTEXTLEN
, wparam
, 0 ) + 1) * sizeof(WCHAR
);
652 return wparam
* sizeof(UINT
);
654 push_data( data
, (MDINEXTMENU
*)lparam
, sizeof(MDINEXTMENU
) );
655 return sizeof(MDINEXTMENU
);
658 push_data( data
, (RECT
*)lparam
, sizeof(RECT
) );
662 MDICREATESTRUCTW
*cs
= (MDICREATESTRUCTW
*)lparam
;
663 push_data( data
, cs
, sizeof(*cs
) );
664 if (HIWORD(cs
->szTitle
)) push_string( data
, cs
->szTitle
);
665 if (HIWORD(cs
->szClass
)) push_string( data
, cs
->szClass
);
668 case WM_MDIGETACTIVE
:
669 if (lparam
) return sizeof(BOOL
);
671 case WM_DEVICECHANGE
:
673 DEV_BROADCAST_HDR
*header
= (DEV_BROADCAST_HDR
*)lparam
;
674 push_data( data
, header
, header
->dbch_size
);
677 case WM_WINE_SETWINDOWPOS
:
678 push_data( data
, (WINDOWPOS
*)lparam
, sizeof(WINDOWPOS
) );
680 case WM_WINE_KEYBOARD_LL_HOOK
:
682 struct hook_extra_info
*h_extra
= (struct hook_extra_info
*)lparam
;
683 push_data( data
, h_extra
, sizeof(*h_extra
) );
684 push_data( data
, (LPVOID
)h_extra
->lparam
, sizeof(KBDLLHOOKSTRUCT
) );
687 case WM_WINE_MOUSE_LL_HOOK
:
689 struct hook_extra_info
*h_extra
= (struct hook_extra_info
*)lparam
;
690 push_data( data
, h_extra
, sizeof(*h_extra
) );
691 push_data( data
, (LPVOID
)h_extra
->lparam
, sizeof(MSLLHOOKSTRUCT
) );
695 if (wparam
<= 1) return 0;
696 FIXME( "WM_NCPAINT hdc packing not supported yet\n" );
700 if (!wparam
) return 0;
703 /* these contain an HFONT */
706 /* these contain an HDC */
708 case WM_ICONERASEBKGND
:
709 case WM_CTLCOLORMSGBOX
:
710 case WM_CTLCOLOREDIT
:
711 case WM_CTLCOLORLISTBOX
:
714 case WM_CTLCOLORSCROLLBAR
:
715 case WM_CTLCOLORSTATIC
:
718 /* these contain an HGLOBAL */
719 case WM_PAINTCLIPBOARD
:
720 case WM_SIZECLIPBOARD
:
721 /* these contain HICON */
724 case WM_QUERYDRAGICON
:
725 case WM_QUERYPARKICON
:
726 /* these contain pointers */
728 case WM_QUERYDROPOBJECT
:
732 FIXME( "msg %x (%s) not supported yet\n", message
, SPY_GetMsgName(message
, hwnd
) );
740 /***********************************************************************
743 * Unpack a message received from another process.
745 static BOOL
unpack_message( HWND hwnd
, UINT message
, WPARAM
*wparam
, LPARAM
*lparam
,
746 void **buffer
, size_t size
)
755 CREATESTRUCTW
*cs
= *buffer
;
756 WCHAR
*str
= (WCHAR
*)(cs
+ 1);
757 if (size
< sizeof(*cs
)) return FALSE
;
759 if (HIWORD(cs
->lpszName
))
761 if (!check_string( str
, size
)) return FALSE
;
763 size
-= (strlenW(str
) + 1) * sizeof(WCHAR
);
764 str
+= strlenW(str
) + 1;
766 if (HIWORD(cs
->lpszClass
))
768 if (!check_string( str
, size
)) return FALSE
;
774 case WM_ASKCBFORMATNAME
:
775 if (!get_buffer_space( buffer
, (*wparam
* sizeof(WCHAR
)) )) return FALSE
;
777 case WM_WININICHANGE
:
778 if (!*lparam
) return TRUE
;
781 case WM_DEVMODECHANGE
:
786 if (!check_string( *buffer
, size
)) return FALSE
;
788 case WM_GETMINMAXINFO
:
789 minsize
= sizeof(MINMAXINFO
);
792 minsize
= sizeof(DRAWITEMSTRUCT
);
795 minsize
= sizeof(MEASUREITEMSTRUCT
);
798 minsize
= sizeof(DELETEITEMSTRUCT
);
801 minsize
= sizeof(COMPAREITEMSTRUCT
);
803 case WM_WINDOWPOSCHANGING
:
804 case WM_WINDOWPOSCHANGED
:
805 case WM_WINE_SETWINDOWPOS
:
806 minsize
= sizeof(WINDOWPOS
);
810 COPYDATASTRUCT
*cp
= *buffer
;
811 if (size
< sizeof(*cp
)) return FALSE
;
814 minsize
= sizeof(*cp
) + cp
->cbData
;
820 /* WM_NOTIFY cannot be sent across processes (MSDN) */
823 minsize
= sizeof(HELPINFO
);
825 case WM_STYLECHANGING
:
826 case WM_STYLECHANGED
:
827 minsize
= sizeof(STYLESTRUCT
);
830 if (!*wparam
) minsize
= sizeof(RECT
);
833 NCCALCSIZE_PARAMS
*nc
= *buffer
;
834 if (size
< sizeof(*nc
) + sizeof(*nc
->lppos
)) return FALSE
;
835 nc
->lppos
= (WINDOWPOS
*)(nc
+ 1);
839 if (!*lparam
) return TRUE
;
840 minsize
= sizeof(MSG
);
842 case SBM_SETSCROLLINFO
:
843 minsize
= sizeof(SCROLLINFO
);
845 case SBM_GETSCROLLINFO
:
846 if (!get_buffer_space( buffer
, sizeof(SCROLLINFO
))) return FALSE
;
848 case SBM_GETSCROLLBARINFO
:
849 if (!get_buffer_space( buffer
, sizeof(SCROLLBARINFO
))) return FALSE
;
854 if (*wparam
|| *lparam
)
856 if (!get_buffer_space( buffer
, 2*sizeof(DWORD
) )) return FALSE
;
857 if (*wparam
) *wparam
= (WPARAM
)*buffer
;
858 if (*lparam
) *lparam
= (LPARAM
)((DWORD
*)*buffer
+ 1);
863 case CB_GETDROPPEDCONTROLRECT
:
864 if (!get_buffer_space( buffer
, sizeof(RECT
) )) return FALSE
;
868 minsize
= sizeof(RECT
);
873 if (size
< sizeof(WORD
)) return FALSE
;
874 len
= *(WORD
*)*buffer
;
875 if (!get_buffer_space( buffer
, (len
+ 1) * sizeof(WCHAR
) )) return FALSE
;
876 *lparam
= (LPARAM
)*buffer
+ sizeof(WORD
); /* don't erase WORD at start of buffer */
881 if (!*wparam
) return TRUE
;
882 minsize
= *wparam
* sizeof(UINT
);
885 case CB_INSERTSTRING
:
887 case CB_FINDSTRINGEXACT
:
888 case CB_SELECTSTRING
:
890 case LB_INSERTSTRING
:
892 case LB_FINDSTRINGEXACT
:
893 case LB_SELECTSTRING
:
894 if (!*buffer
) return TRUE
;
895 if (!check_string( *buffer
, size
)) return FALSE
;
899 size
= sizeof(ULONG_PTR
);
900 if (combobox_has_strings( hwnd
))
901 size
= (SendMessageW( hwnd
, CB_GETLBTEXTLEN
, *wparam
, 0 ) + 1) * sizeof(WCHAR
);
902 if (!get_buffer_space( buffer
, size
)) return FALSE
;
907 size
= sizeof(ULONG_PTR
);
908 if (listbox_has_strings( hwnd
))
909 size
= (SendMessageW( hwnd
, LB_GETTEXTLEN
, *wparam
, 0 ) + 1) * sizeof(WCHAR
);
910 if (!get_buffer_space( buffer
, size
)) return FALSE
;
914 if (!get_buffer_space( buffer
, *wparam
* sizeof(UINT
) )) return FALSE
;
917 minsize
= sizeof(MDINEXTMENU
);
918 if (!get_buffer_space( buffer
, sizeof(MDINEXTMENU
) )) return FALSE
;
922 minsize
= sizeof(RECT
);
923 if (!get_buffer_space( buffer
, sizeof(RECT
) )) return FALSE
;
927 MDICREATESTRUCTW
*cs
= *buffer
;
928 WCHAR
*str
= (WCHAR
*)(cs
+ 1);
929 if (size
< sizeof(*cs
)) return FALSE
;
931 if (HIWORD(cs
->szTitle
))
933 if (!check_string( str
, size
)) return FALSE
;
935 size
-= (strlenW(str
) + 1) * sizeof(WCHAR
);
936 str
+= strlenW(str
) + 1;
938 if (HIWORD(cs
->szClass
))
940 if (!check_string( str
, size
)) return FALSE
;
945 case WM_MDIGETACTIVE
:
946 if (!*lparam
) return TRUE
;
947 if (!get_buffer_space( buffer
, sizeof(BOOL
) )) return FALSE
;
949 case WM_DEVICECHANGE
:
950 minsize
= sizeof(DEV_BROADCAST_HDR
);
952 case WM_WINE_KEYBOARD_LL_HOOK
:
953 case WM_WINE_MOUSE_LL_HOOK
:
955 struct hook_extra_info
*h_extra
= (struct hook_extra_info
*)*buffer
;
957 minsize
= sizeof(struct hook_extra_info
) +
958 (message
== WM_WINE_KEYBOARD_LL_HOOK
? sizeof(KBDLLHOOKSTRUCT
)
959 : sizeof(MSLLHOOKSTRUCT
));
960 if (size
< minsize
) return FALSE
;
961 h_extra
->lparam
= (LPARAM
)(h_extra
+ 1);
965 if (*wparam
<= 1) return TRUE
;
966 FIXME( "WM_NCPAINT hdc unpacking not supported\n" );
969 if (!*wparam
) return TRUE
;
972 /* these contain an HFONT */
975 /* these contain an HDC */
977 case WM_ICONERASEBKGND
:
978 case WM_CTLCOLORMSGBOX
:
979 case WM_CTLCOLOREDIT
:
980 case WM_CTLCOLORLISTBOX
:
983 case WM_CTLCOLORSCROLLBAR
:
984 case WM_CTLCOLORSTATIC
:
987 /* these contain an HGLOBAL */
988 case WM_PAINTCLIPBOARD
:
989 case WM_SIZECLIPBOARD
:
990 /* these contain HICON */
993 case WM_QUERYDRAGICON
:
994 case WM_QUERYPARKICON
:
995 /* these contain pointers */
997 case WM_QUERYDROPOBJECT
:
1001 FIXME( "msg %x (%s) not supported yet\n", message
, SPY_GetMsgName(message
, hwnd
) );
1005 return TRUE
; /* message doesn't need any unpacking */
1008 /* default exit for most messages: check minsize and store buffer in lparam */
1009 if (size
< minsize
) return FALSE
;
1010 *lparam
= (LPARAM
)*buffer
;
1015 /***********************************************************************
1018 * Pack a reply to a message for sending to another process.
1020 static void pack_reply( HWND hwnd
, UINT message
, WPARAM wparam
, LPARAM lparam
,
1021 LRESULT res
, struct packed_message
*data
)
1028 push_data( data
, (CREATESTRUCTW
*)lparam
, sizeof(CREATESTRUCTW
) );
1033 push_data( data
, (WCHAR
*)lparam
, (res
+ 1) * sizeof(WCHAR
) );
1035 case WM_GETMINMAXINFO
:
1036 push_data( data
, (MINMAXINFO
*)lparam
, sizeof(MINMAXINFO
) );
1038 case WM_MEASUREITEM
:
1039 push_data( data
, (MEASUREITEMSTRUCT
*)lparam
, sizeof(MEASUREITEMSTRUCT
) );
1041 case WM_WINDOWPOSCHANGING
:
1042 case WM_WINDOWPOSCHANGED
:
1043 push_data( data
, (WINDOWPOS
*)lparam
, sizeof(WINDOWPOS
) );
1046 if (lparam
) push_data( data
, (MSG
*)lparam
, sizeof(MSG
) );
1048 case SBM_GETSCROLLINFO
:
1049 push_data( data
, (SCROLLINFO
*)lparam
, sizeof(SCROLLINFO
) );
1052 case LB_GETITEMRECT
:
1053 case CB_GETDROPPEDCONTROLRECT
:
1056 push_data( data
, (RECT
*)lparam
, sizeof(RECT
) );
1060 WORD
*ptr
= (WORD
*)lparam
;
1061 push_data( data
, ptr
, ptr
[-1] * sizeof(WCHAR
) );
1064 case LB_GETSELITEMS
:
1065 push_data( data
, (UINT
*)lparam
, wparam
* sizeof(UINT
) );
1067 case WM_MDIGETACTIVE
:
1068 if (lparam
) push_data( data
, (BOOL
*)lparam
, sizeof(BOOL
) );
1072 push_data( data
, (RECT
*)lparam
, sizeof(RECT
) );
1075 NCCALCSIZE_PARAMS
*nc
= (NCCALCSIZE_PARAMS
*)lparam
;
1076 push_data( data
, nc
, sizeof(*nc
) );
1077 push_data( data
, nc
->lppos
, sizeof(*nc
->lppos
) );
1083 if (wparam
) push_data( data
, (DWORD
*)wparam
, sizeof(DWORD
) );
1084 if (lparam
) push_data( data
, (DWORD
*)lparam
, sizeof(DWORD
) );
1087 push_data( data
, (MDINEXTMENU
*)lparam
, sizeof(MDINEXTMENU
) );
1090 push_data( data
, (MDICREATESTRUCTW
*)lparam
, sizeof(MDICREATESTRUCTW
) );
1092 case WM_ASKCBFORMATNAME
:
1093 push_data( data
, (WCHAR
*)lparam
, (strlenW((WCHAR
*)lparam
) + 1) * sizeof(WCHAR
) );
1099 /***********************************************************************
1102 * Unpack a message reply received from another process.
1104 static void unpack_reply( HWND hwnd
, UINT message
, WPARAM wparam
, LPARAM lparam
,
1105 void *buffer
, size_t size
)
1112 CREATESTRUCTW
*cs
= (CREATESTRUCTW
*)lparam
;
1113 LPCWSTR name
= cs
->lpszName
, class = cs
->lpszClass
;
1114 memcpy( cs
, buffer
, min( sizeof(*cs
), size
));
1115 cs
->lpszName
= name
; /* restore the original pointers */
1116 cs
->lpszClass
= class;
1120 case WM_ASKCBFORMATNAME
:
1121 memcpy( (WCHAR
*)lparam
, buffer
, min( wparam
*sizeof(WCHAR
), size
));
1123 case WM_GETMINMAXINFO
:
1124 memcpy( (MINMAXINFO
*)lparam
, buffer
, min( sizeof(MINMAXINFO
), size
));
1126 case WM_MEASUREITEM
:
1127 memcpy( (MEASUREITEMSTRUCT
*)lparam
, buffer
, min( sizeof(MEASUREITEMSTRUCT
), size
));
1129 case WM_WINDOWPOSCHANGING
:
1130 case WM_WINDOWPOSCHANGED
:
1131 memcpy( (WINDOWPOS
*)lparam
, buffer
, min( sizeof(WINDOWPOS
), size
));
1134 if (lparam
) memcpy( (MSG
*)lparam
, buffer
, min( sizeof(MSG
), size
));
1136 case SBM_GETSCROLLINFO
:
1137 memcpy( (SCROLLINFO
*)lparam
, buffer
, min( sizeof(SCROLLINFO
), size
));
1139 case SBM_GETSCROLLBARINFO
:
1140 memcpy( (SCROLLBARINFO
*)lparam
, buffer
, min( sizeof(SCROLLBARINFO
), size
));
1143 case CB_GETDROPPEDCONTROLRECT
:
1144 case LB_GETITEMRECT
:
1147 memcpy( (RECT
*)lparam
, buffer
, min( sizeof(RECT
), size
));
1150 size
= min( size
, (size_t)*(WORD
*)lparam
);
1151 memcpy( (WCHAR
*)lparam
, buffer
, size
);
1153 case LB_GETSELITEMS
:
1154 memcpy( (UINT
*)lparam
, buffer
, min( wparam
*sizeof(UINT
), size
));
1158 memcpy( (WCHAR
*)lparam
, buffer
, size
);
1161 memcpy( (MDINEXTMENU
*)lparam
, buffer
, min( sizeof(MDINEXTMENU
), size
));
1163 case WM_MDIGETACTIVE
:
1164 if (lparam
) memcpy( (BOOL
*)lparam
, buffer
, min( sizeof(BOOL
), size
));
1168 memcpy( (RECT
*)lparam
, buffer
, min( sizeof(RECT
), size
));
1171 NCCALCSIZE_PARAMS
*nc
= (NCCALCSIZE_PARAMS
*)lparam
;
1172 WINDOWPOS
*wp
= nc
->lppos
;
1173 memcpy( nc
, buffer
, min( sizeof(*nc
), size
));
1174 if (size
> sizeof(*nc
))
1176 size
-= sizeof(*nc
);
1177 memcpy( wp
, (NCCALCSIZE_PARAMS
*)buffer
+ 1, min( sizeof(*wp
), size
));
1179 nc
->lppos
= wp
; /* restore the original pointer */
1187 memcpy( (DWORD
*)wparam
, buffer
, min( sizeof(DWORD
), size
));
1188 if (size
<= sizeof(DWORD
)) break;
1189 size
-= sizeof(DWORD
);
1190 buffer
= (DWORD
*)buffer
+ 1;
1192 if (lparam
) memcpy( (DWORD
*)lparam
, buffer
, min( sizeof(DWORD
), size
));
1196 MDICREATESTRUCTW
*cs
= (MDICREATESTRUCTW
*)lparam
;
1197 LPCWSTR title
= cs
->szTitle
, class = cs
->szClass
;
1198 memcpy( cs
, buffer
, min( sizeof(*cs
), size
));
1199 cs
->szTitle
= title
; /* restore the original pointers */
1200 cs
->szClass
= class;
1204 ERR( "should not happen: unexpected message %x\n", message
);
1210 /***********************************************************************
1213 * Send a reply to a sent message.
1215 static void reply_message( struct received_message_info
*info
, LRESULT result
, BOOL remove
)
1217 struct packed_message data
;
1218 int i
, replied
= info
->flags
& ISMEX_REPLIED
;
1220 if (info
->flags
& ISMEX_NOTIFY
) return; /* notify messages don't get replies */
1221 if (!remove
&& replied
) return; /* replied already */
1224 info
->flags
|= ISMEX_REPLIED
;
1226 if (info
->type
== MSG_OTHER_PROCESS
&& !replied
)
1228 pack_reply( info
->msg
.hwnd
, info
->msg
.message
, info
->msg
.wParam
,
1229 info
->msg
.lParam
, result
, &data
);
1232 SERVER_START_REQ( reply_message
)
1234 req
->result
= result
;
1235 req
->remove
= remove
;
1236 for (i
= 0; i
< data
.count
; i
++) wine_server_add_data( req
, data
.data
[i
], data
.size
[i
] );
1237 wine_server_call( req
);
1243 /***********************************************************************
1244 * handle_internal_message
1246 * Handle an internal Wine message instead of calling the window proc.
1248 static LRESULT
handle_internal_message( HWND hwnd
, UINT msg
, WPARAM wparam
, LPARAM lparam
)
1252 case WM_WINE_DESTROYWINDOW
:
1253 return WIN_DestroyWindow( hwnd
);
1254 case WM_WINE_SETWINDOWPOS
:
1255 if (hwnd
== GetDesktopWindow()) return 0;
1256 return USER_SetWindowPos( (WINDOWPOS
*)lparam
);
1257 case WM_WINE_SHOWWINDOW
:
1258 if (hwnd
== GetDesktopWindow()) return 0;
1259 return ShowWindow( hwnd
, wparam
);
1260 case WM_WINE_SETPARENT
:
1261 if (hwnd
== GetDesktopWindow()) return 0;
1262 return (LRESULT
)SetParent( hwnd
, (HWND
)wparam
);
1263 case WM_WINE_SETWINDOWLONG
:
1264 return WIN_SetWindowLong( hwnd
, (short)LOWORD(wparam
), HIWORD(wparam
), lparam
, TRUE
);
1265 case WM_WINE_ENABLEWINDOW
:
1266 if (hwnd
== GetDesktopWindow()) return 0;
1267 return EnableWindow( hwnd
, wparam
);
1268 case WM_WINE_SETACTIVEWINDOW
:
1269 if (hwnd
== GetDesktopWindow()) return 0;
1270 return (LRESULT
)SetActiveWindow( (HWND
)wparam
);
1271 case WM_WINE_KEYBOARD_LL_HOOK
:
1272 case WM_WINE_MOUSE_LL_HOOK
:
1274 struct hook_extra_info
*h_extra
= (struct hook_extra_info
*)lparam
;
1276 return call_current_hook( h_extra
->handle
, HC_ACTION
, wparam
, h_extra
->lparam
);
1279 if (msg
>= WM_WINE_FIRST_DRIVER_MSG
&& msg
<= WM_WINE_LAST_DRIVER_MSG
)
1280 return USER_Driver
->pWindowMessage( hwnd
, msg
, wparam
, lparam
);
1281 FIXME( "unknown internal message %x\n", msg
);
1286 /* since the WM_DDE_ACK response to a WM_DDE_EXECUTE message should contain the handle
1287 * to the memory handle, we keep track (in the server side) of all pairs of handle
1288 * used (the client passes its value and the content of the memory handle), and
1289 * the server stored both values (the client, and the local one, created after the
1290 * content). When a ACK message is generated, the list of pair is searched for a
1291 * matching pair, so that the client memory handle can be returned.
1294 HGLOBAL client_hMem
;
1295 HGLOBAL server_hMem
;
1298 static struct DDE_pair
* dde_pairs
;
1299 static int dde_num_alloc
;
1300 static int dde_num_used
;
1302 static CRITICAL_SECTION dde_crst
;
1303 static CRITICAL_SECTION_DEBUG critsect_debug
=
1306 { &critsect_debug
.ProcessLocksList
, &critsect_debug
.ProcessLocksList
},
1307 0, 0, { (DWORD_PTR
)(__FILE__
": dde_crst") }
1309 static CRITICAL_SECTION dde_crst
= { &critsect_debug
, -1, 0, 0, 0, 0 };
1311 static BOOL
dde_add_pair(HGLOBAL chm
, HGLOBAL shm
)
1316 EnterCriticalSection(&dde_crst
);
1318 /* now remember the pair of hMem on both sides */
1319 if (dde_num_used
== dde_num_alloc
)
1321 struct DDE_pair
* tmp
;
1323 tmp
= HeapReAlloc( GetProcessHeap(), 0, dde_pairs
,
1324 (dde_num_alloc
+ GROWBY
) * sizeof(struct DDE_pair
));
1326 tmp
= HeapAlloc( GetProcessHeap(), 0,
1327 (dde_num_alloc
+ GROWBY
) * sizeof(struct DDE_pair
));
1331 LeaveCriticalSection(&dde_crst
);
1335 /* zero out newly allocated part */
1336 memset(&dde_pairs
[dde_num_alloc
], 0, GROWBY
* sizeof(struct DDE_pair
));
1337 dde_num_alloc
+= GROWBY
;
1340 for (i
= 0; i
< dde_num_alloc
; i
++)
1342 if (dde_pairs
[i
].server_hMem
== 0)
1344 dde_pairs
[i
].client_hMem
= chm
;
1345 dde_pairs
[i
].server_hMem
= shm
;
1350 LeaveCriticalSection(&dde_crst
);
1354 static HGLOBAL
dde_get_pair(HGLOBAL shm
)
1359 EnterCriticalSection(&dde_crst
);
1360 for (i
= 0; i
< dde_num_alloc
; i
++)
1362 if (dde_pairs
[i
].server_hMem
== shm
)
1364 /* free this pair */
1365 dde_pairs
[i
].server_hMem
= 0;
1367 ret
= dde_pairs
[i
].client_hMem
;
1371 LeaveCriticalSection(&dde_crst
);
1375 /***********************************************************************
1378 * Post a DDE message
1380 static BOOL
post_dde_message( struct packed_message
*data
, const struct send_message_info
*info
)
1384 UINT_PTR uiLo
, uiHi
;
1386 HGLOBAL hunlock
= 0;
1390 if (!UnpackDDElParam( info
->msg
, info
->lparam
, &uiLo
, &uiHi
))
1396 /* DDE messages which don't require packing are:
1405 /* uiHi should contain a hMem from WM_DDE_EXECUTE */
1406 HGLOBAL h
= dde_get_pair( (HANDLE
)uiHi
);
1409 /* send back the value of h on the other side */
1410 push_data( data
, &h
, sizeof(HGLOBAL
) );
1412 TRACE( "send dde-ack %lx %08lx => %p\n", uiLo
, uiHi
, h
);
1417 /* uiHi should contain either an atom or 0 */
1418 TRACE( "send dde-ack %lx atom=%lx\n", uiLo
, uiHi
);
1419 lp
= MAKELONG( uiLo
, uiHi
);
1428 size
= GlobalSize( (HGLOBAL
)uiLo
) ;
1429 if ((info
->msg
== WM_DDE_ADVISE
&& size
< sizeof(DDEADVISE
)) ||
1430 (info
->msg
== WM_DDE_DATA
&& size
< sizeof(DDEDATA
)) ||
1431 (info
->msg
== WM_DDE_POKE
&& size
< sizeof(DDEPOKE
))
1435 else if (info
->msg
!= WM_DDE_DATA
) return FALSE
;
1440 if ((ptr
= GlobalLock( (HGLOBAL
)uiLo
) ))
1442 DDEDATA
*dde_data
= (DDEDATA
*)ptr
;
1443 TRACE("unused %d, fResponse %d, fRelease %d, fDeferUpd %d, fAckReq %d, cfFormat %d\n",
1444 dde_data
->unused
, dde_data
->fResponse
, dde_data
->fRelease
,
1445 dde_data
->reserved
, dde_data
->fAckReq
, dde_data
->cfFormat
);
1446 push_data( data
, ptr
, size
);
1447 hunlock
= (HGLOBAL
)uiLo
;
1450 TRACE( "send ddepack %u %lx\n", size
, uiHi
);
1452 case WM_DDE_EXECUTE
:
1455 if ((ptr
= GlobalLock( (HGLOBAL
)info
->lparam
) ))
1457 push_data(data
, ptr
, GlobalSize( (HGLOBAL
)info
->lparam
));
1458 /* so that the other side can send it back on ACK */
1460 hunlock
= (HGLOBAL
)info
->lparam
;
1465 SERVER_START_REQ( send_message
)
1467 req
->id
= info
->dest_tid
;
1468 req
->type
= info
->type
;
1470 req
->win
= info
->hwnd
;
1471 req
->msg
= info
->msg
;
1472 req
->wparam
= info
->wparam
;
1474 req
->timeout
= TIMEOUT_INFINITE
;
1475 for (i
= 0; i
< data
->count
; i
++)
1476 wine_server_add_data( req
, data
->data
[i
], data
->size
[i
] );
1477 if ((res
= wine_server_call( req
)))
1479 if (res
== STATUS_INVALID_PARAMETER
)
1480 /* FIXME: find a STATUS_ value for this one */
1481 SetLastError( ERROR_INVALID_THREAD_ID
);
1483 SetLastError( RtlNtStatusToDosError(res
) );
1486 FreeDDElParam(info
->msg
, info
->lparam
);
1489 if (hunlock
) GlobalUnlock(hunlock
);
1494 /***********************************************************************
1495 * unpack_dde_message
1497 * Unpack a posted DDE message received from another process.
1499 static BOOL
unpack_dde_message( HWND hwnd
, UINT message
, WPARAM
*wparam
, LPARAM
*lparam
,
1500 void **buffer
, size_t size
)
1502 UINT_PTR uiLo
, uiHi
;
1511 /* hMem is being passed */
1512 if (size
!= sizeof(HGLOBAL
)) return FALSE
;
1513 if (!buffer
|| !*buffer
) return FALSE
;
1515 memcpy( &hMem
, *buffer
, size
);
1516 uiHi
= (UINT_PTR
)hMem
;
1517 TRACE("recv dde-ack %lx mem=%lx[%lx]\n", uiLo
, uiHi
, GlobalSize( hMem
));
1521 uiLo
= LOWORD( *lparam
);
1522 uiHi
= HIWORD( *lparam
);
1523 TRACE("recv dde-ack %lx atom=%lx\n", uiLo
, uiHi
);
1525 *lparam
= PackDDElParam( WM_DDE_ACK
, uiLo
, uiHi
);
1530 if ((!buffer
|| !*buffer
) && message
!= WM_DDE_DATA
) return FALSE
;
1534 if (!(hMem
= GlobalAlloc( GMEM_MOVEABLE
|GMEM_DDESHARE
, size
)))
1536 if ((ptr
= GlobalLock( hMem
)))
1538 memcpy( ptr
, *buffer
, size
);
1539 GlobalUnlock( hMem
);
1547 uiLo
= (UINT_PTR
)hMem
;
1549 *lparam
= PackDDElParam( message
, uiLo
, uiHi
);
1551 case WM_DDE_EXECUTE
:
1554 if (!buffer
|| !*buffer
) return FALSE
;
1555 if (!(hMem
= GlobalAlloc( GMEM_MOVEABLE
|GMEM_DDESHARE
, size
))) return FALSE
;
1556 if ((ptr
= GlobalLock( hMem
)))
1558 memcpy( ptr
, *buffer
, size
);
1559 GlobalUnlock( hMem
);
1560 TRACE( "exec: pairing c=%08lx s=%p\n", *lparam
, hMem
);
1561 if (!dde_add_pair( (HGLOBAL
)*lparam
, hMem
))
1572 } else return FALSE
;
1573 *lparam
= (LPARAM
)hMem
;
1579 /***********************************************************************
1582 * Call a window procedure and the corresponding hooks.
1584 static LRESULT
call_window_proc( HWND hwnd
, UINT msg
, WPARAM wparam
, LPARAM lparam
,
1585 BOOL unicode
, BOOL same_thread
, enum wm_char_mapping mapping
)
1587 struct user_thread_info
*thread_info
= get_user_thread_info();
1590 CWPRETSTRUCT cwpret
;
1592 if (thread_info
->recursion_count
> MAX_SENDMSG_RECURSION
) return 0;
1593 thread_info
->recursion_count
++;
1595 if (msg
& 0x80000000)
1597 result
= handle_internal_message( hwnd
, msg
, wparam
, lparam
);
1601 /* first the WH_CALLWNDPROC hook */
1602 hwnd
= WIN_GetFullHandle( hwnd
);
1603 cwp
.lParam
= lparam
;
1604 cwp
.wParam
= wparam
;
1607 HOOK_CallHooks( WH_CALLWNDPROC
, HC_ACTION
, same_thread
, (LPARAM
)&cwp
, unicode
);
1609 /* now call the window procedure */
1610 if (!WINPROC_call_window( hwnd
, msg
, wparam
, lparam
, &result
, unicode
, mapping
)) goto done
;
1612 /* and finally the WH_CALLWNDPROCRET hook */
1613 cwpret
.lResult
= result
;
1614 cwpret
.lParam
= lparam
;
1615 cwpret
.wParam
= wparam
;
1616 cwpret
.message
= msg
;
1618 HOOK_CallHooks( WH_CALLWNDPROCRET
, HC_ACTION
, same_thread
, (LPARAM
)&cwpret
, unicode
);
1620 thread_info
->recursion_count
--;
1625 /***********************************************************************
1626 * send_parent_notify
1628 * Send a WM_PARENTNOTIFY to all ancestors of the given window, unless
1629 * the window has the WS_EX_NOPARENTNOTIFY style.
1631 static void send_parent_notify( HWND hwnd
, WORD event
, WORD idChild
, POINT pt
)
1633 /* pt has to be in the client coordinates of the parent window */
1634 MapWindowPoints( 0, hwnd
, &pt
, 1 );
1639 if (!(GetWindowLongW( hwnd
, GWL_STYLE
) & WS_CHILD
)) break;
1640 if (GetWindowLongW( hwnd
, GWL_EXSTYLE
) & WS_EX_NOPARENTNOTIFY
) break;
1641 if (!(parent
= GetParent(hwnd
))) break;
1642 if (parent
== GetDesktopWindow()) break;
1643 MapWindowPoints( hwnd
, parent
, &pt
, 1 );
1645 SendMessageW( hwnd
, WM_PARENTNOTIFY
,
1646 MAKEWPARAM( event
, idChild
), MAKELPARAM( pt
.x
, pt
.y
) );
1651 /***********************************************************************
1652 * accept_hardware_message
1654 * Tell the server we have passed the message to the app
1655 * (even though we may end up dropping it later on)
1657 static void accept_hardware_message( UINT hw_id
, BOOL remove
, HWND new_hwnd
)
1659 SERVER_START_REQ( accept_hardware_message
)
1662 req
->remove
= remove
;
1663 req
->new_win
= new_hwnd
;
1664 if (wine_server_call( req
))
1665 FIXME("Failed to reply to MSG_HARDWARE message. Message may not be removed from queue.\n");
1671 /***********************************************************************
1672 * process_keyboard_message
1674 * returns TRUE if the contents of 'msg' should be passed to the application
1676 static BOOL
process_keyboard_message( MSG
*msg
, UINT hw_id
, HWND hwnd_filter
,
1677 UINT first
, UINT last
, BOOL remove
)
1681 if (msg
->message
== WM_KEYDOWN
|| msg
->message
== WM_SYSKEYDOWN
||
1682 msg
->message
== WM_KEYUP
|| msg
->message
== WM_SYSKEYUP
)
1683 switch (msg
->wParam
)
1685 case VK_LSHIFT
: case VK_RSHIFT
:
1686 msg
->wParam
= VK_SHIFT
;
1688 case VK_LCONTROL
: case VK_RCONTROL
:
1689 msg
->wParam
= VK_CONTROL
;
1691 case VK_LMENU
: case VK_RMENU
:
1692 msg
->wParam
= VK_MENU
;
1696 /* FIXME: is this really the right place for this hook? */
1697 event
.message
= msg
->message
;
1698 event
.hwnd
= msg
->hwnd
;
1699 event
.time
= msg
->time
;
1700 event
.paramL
= (msg
->wParam
& 0xFF) | (HIWORD(msg
->lParam
) << 8);
1701 event
.paramH
= msg
->lParam
& 0x7FFF;
1702 if (HIWORD(msg
->lParam
) & 0x0100) event
.paramH
|= 0x8000; /* special_key - bit */
1703 HOOK_CallHooks( WH_JOURNALRECORD
, HC_ACTION
, 0, (LPARAM
)&event
, TRUE
);
1705 /* check message filters */
1706 if (msg
->message
< first
|| msg
->message
> last
) return FALSE
;
1707 if (!check_hwnd_filter( msg
, hwnd_filter
)) return FALSE
;
1711 if((msg
->message
== WM_KEYDOWN
) &&
1712 (msg
->hwnd
!= GetDesktopWindow()))
1714 /* Handle F1 key by sending out WM_HELP message */
1715 if (msg
->wParam
== VK_F1
)
1717 PostMessageW( msg
->hwnd
, WM_KEYF1
, 0, 0 );
1719 else if(msg
->wParam
>= VK_BROWSER_BACK
&&
1720 msg
->wParam
<= VK_LAUNCH_APP2
)
1722 /* FIXME: Process keystate */
1723 SendMessageW(msg
->hwnd
, WM_APPCOMMAND
, (WPARAM
)msg
->hwnd
, MAKELPARAM(0, (FAPPCOMMAND_KEY
| (msg
->wParam
- VK_BROWSER_BACK
+ 1))));
1726 else if (msg
->message
== WM_KEYUP
)
1728 /* Handle VK_APPS key by posting a WM_CONTEXTMENU message */
1729 if (msg
->wParam
== VK_APPS
&& !MENU_IsMenuActive())
1730 PostMessageW(msg
->hwnd
, WM_CONTEXTMENU
, (WPARAM
)msg
->hwnd
, (LPARAM
)-1);
1734 if (HOOK_CallHooks( WH_KEYBOARD
, remove
? HC_ACTION
: HC_NOREMOVE
,
1735 LOWORD(msg
->wParam
), msg
->lParam
, TRUE
))
1737 /* skip this message */
1738 HOOK_CallHooks( WH_CBT
, HCBT_KEYSKIPPED
, LOWORD(msg
->wParam
), msg
->lParam
, TRUE
);
1739 accept_hardware_message( hw_id
, TRUE
, 0 );
1742 accept_hardware_message( hw_id
, remove
, 0 );
1744 if ( msg
->message
== WM_KEYDOWN
|| msg
->message
== WM_KEYUP
)
1745 if ( ImmProcessKey(msg
->hwnd
, GetKeyboardLayout(0), msg
->wParam
, msg
->lParam
, 0) )
1746 msg
->wParam
= VK_PROCESSKEY
;
1752 /***********************************************************************
1753 * process_mouse_message
1755 * returns TRUE if the contents of 'msg' should be passed to the application
1757 static BOOL
process_mouse_message( MSG
*msg
, UINT hw_id
, ULONG_PTR extra_info
, HWND hwnd_filter
,
1758 UINT first
, UINT last
, BOOL remove
)
1767 MOUSEHOOKSTRUCT hook
;
1770 /* find the window to dispatch this mouse message to */
1772 GetGUIThreadInfo( GetCurrentThreadId(), &info
);
1773 if (info
.hwndCapture
)
1776 msg
->hwnd
= info
.hwndCapture
;
1780 msg
->hwnd
= WINPOS_WindowFromPoint( msg
->hwnd
, msg
->pt
, &hittest
);
1783 if (!msg
->hwnd
|| !WIN_IsCurrentThread( msg
->hwnd
))
1785 accept_hardware_message( hw_id
, TRUE
, msg
->hwnd
);
1789 /* FIXME: is this really the right place for this hook? */
1790 event
.message
= msg
->message
;
1791 event
.time
= msg
->time
;
1792 event
.hwnd
= msg
->hwnd
;
1793 event
.paramL
= msg
->pt
.x
;
1794 event
.paramH
= msg
->pt
.y
;
1795 HOOK_CallHooks( WH_JOURNALRECORD
, HC_ACTION
, 0, (LPARAM
)&event
, TRUE
);
1797 if (!check_hwnd_filter( msg
, hwnd_filter
)) return FALSE
;
1800 message
= msg
->message
;
1801 /* Note: windows has no concept of a non-client wheel message */
1802 if (message
!= WM_MOUSEWHEEL
)
1804 if (hittest
!= HTCLIENT
)
1806 message
+= WM_NCMOUSEMOVE
- WM_MOUSEMOVE
;
1807 msg
->wParam
= hittest
;
1811 /* coordinates don't get translated while tracking a menu */
1812 /* FIXME: should differentiate popups and top-level menus */
1813 if (!(info
.flags
& GUI_INMENUMODE
))
1814 ScreenToClient( msg
->hwnd
, &pt
);
1817 msg
->lParam
= MAKELONG( pt
.x
, pt
.y
);
1819 /* translate double clicks */
1821 if ((msg
->message
== WM_LBUTTONDOWN
) ||
1822 (msg
->message
== WM_RBUTTONDOWN
) ||
1823 (msg
->message
== WM_MBUTTONDOWN
) ||
1824 (msg
->message
== WM_XBUTTONDOWN
))
1826 BOOL update
= remove
;
1828 /* translate double clicks -
1829 * note that ...MOUSEMOVEs can slip in between
1830 * ...BUTTONDOWN and ...BUTTONDBLCLK messages */
1832 if ((info
.flags
& (GUI_INMENUMODE
|GUI_INMOVESIZE
)) ||
1833 hittest
!= HTCLIENT
||
1834 (GetClassLongA( msg
->hwnd
, GCL_STYLE
) & CS_DBLCLKS
))
1836 if ((msg
->message
== clk_msg
.message
) &&
1837 (msg
->hwnd
== clk_msg
.hwnd
) &&
1838 (msg
->wParam
== clk_msg
.wParam
) &&
1839 (msg
->time
- clk_msg
.time
< GetDoubleClickTime()) &&
1840 (abs(msg
->pt
.x
- clk_msg
.pt
.x
) < GetSystemMetrics(SM_CXDOUBLECLK
)/2) &&
1841 (abs(msg
->pt
.y
- clk_msg
.pt
.y
) < GetSystemMetrics(SM_CYDOUBLECLK
)/2))
1843 message
+= (WM_LBUTTONDBLCLK
- WM_LBUTTONDOWN
);
1846 clk_msg
.message
= 0; /* clear the double click conditions */
1851 if (message
< first
|| message
> last
) return FALSE
;
1852 /* update static double click conditions */
1853 if (update
) clk_msg
= *msg
;
1857 if (message
< first
|| message
> last
) return FALSE
;
1860 /* message is accepted now (but may still get dropped) */
1863 hook
.hwnd
= msg
->hwnd
;
1864 hook
.wHitTestCode
= hittest
;
1865 hook
.dwExtraInfo
= extra_info
;
1866 if (HOOK_CallHooks( WH_MOUSE
, remove
? HC_ACTION
: HC_NOREMOVE
,
1867 message
, (LPARAM
)&hook
, TRUE
))
1870 hook
.hwnd
= msg
->hwnd
;
1871 hook
.wHitTestCode
= hittest
;
1872 hook
.dwExtraInfo
= extra_info
;
1873 HOOK_CallHooks( WH_CBT
, HCBT_CLICKSKIPPED
, message
, (LPARAM
)&hook
, TRUE
);
1874 accept_hardware_message( hw_id
, TRUE
, 0 );
1878 if ((hittest
== HTERROR
) || (hittest
== HTNOWHERE
))
1880 SendMessageW( msg
->hwnd
, WM_SETCURSOR
, (WPARAM
)msg
->hwnd
,
1881 MAKELONG( hittest
, msg
->message
));
1882 accept_hardware_message( hw_id
, TRUE
, 0 );
1886 accept_hardware_message( hw_id
, remove
, 0 );
1888 if (!remove
|| info
.hwndCapture
)
1890 msg
->message
= message
;
1896 if ((msg
->message
== WM_LBUTTONDOWN
) ||
1897 (msg
->message
== WM_RBUTTONDOWN
) ||
1898 (msg
->message
== WM_MBUTTONDOWN
) ||
1899 (msg
->message
== WM_XBUTTONDOWN
))
1901 /* Send the WM_PARENTNOTIFY,
1902 * note that even for double/nonclient clicks
1903 * notification message is still WM_L/M/RBUTTONDOWN.
1905 send_parent_notify( msg
->hwnd
, msg
->message
, 0, msg
->pt
);
1907 /* Activate the window if needed */
1909 if (msg
->hwnd
!= info
.hwndActive
)
1911 HWND hwndTop
= msg
->hwnd
;
1914 if ((GetWindowLongW( hwndTop
, GWL_STYLE
) & (WS_POPUP
|WS_CHILD
)) != WS_CHILD
) break;
1915 hwndTop
= GetParent( hwndTop
);
1918 if (hwndTop
&& hwndTop
!= GetDesktopWindow())
1920 LONG ret
= SendMessageW( msg
->hwnd
, WM_MOUSEACTIVATE
, (WPARAM
)hwndTop
,
1921 MAKELONG( hittest
, msg
->message
) );
1924 case MA_NOACTIVATEANDEAT
:
1929 case MA_ACTIVATEANDEAT
:
1934 if (!FOCUS_MouseActivate( hwndTop
)) eatMsg
= TRUE
;
1937 WARN( "unknown WM_MOUSEACTIVATE code %d\n", ret
);
1944 /* send the WM_SETCURSOR message */
1946 /* Windows sends the normal mouse message as the message parameter
1947 in the WM_SETCURSOR message even if it's non-client mouse message */
1948 SendMessageW( msg
->hwnd
, WM_SETCURSOR
, (WPARAM
)msg
->hwnd
, MAKELONG( hittest
, msg
->message
));
1950 msg
->message
= message
;
1955 /***********************************************************************
1956 * process_hardware_message
1958 * Process a hardware message; return TRUE if message should be passed on to the app
1960 static BOOL
process_hardware_message( MSG
*msg
, UINT hw_id
, ULONG_PTR extra_info
, HWND hwnd_filter
,
1961 UINT first
, UINT last
, BOOL remove
)
1963 if (is_keyboard_message( msg
->message
))
1964 return process_keyboard_message( msg
, hw_id
, hwnd_filter
, first
, last
, remove
);
1966 if (is_mouse_message( msg
->message
))
1967 return process_mouse_message( msg
, hw_id
, extra_info
, hwnd_filter
, first
, last
, remove
);
1969 ERR( "unknown message type %x\n", msg
->message
);
1974 /***********************************************************************
1975 * call_sendmsg_callback
1977 * Call the callback function of SendMessageCallback.
1979 static inline void call_sendmsg_callback( SENDASYNCPROC callback
, HWND hwnd
, UINT msg
,
1980 ULONG_PTR data
, LRESULT result
)
1982 if (!callback
) return;
1984 if (TRACE_ON(relay
))
1985 DPRINTF( "%04x:Call message callback %p (hwnd=%p,msg=%s,data=%08lx,result=%08lx)\n",
1986 GetCurrentThreadId(), callback
, hwnd
, SPY_GetMsgName( msg
, hwnd
),
1988 callback( hwnd
, msg
, data
, result
);
1989 if (TRACE_ON(relay
))
1990 DPRINTF( "%04x:Ret message callback %p (hwnd=%p,msg=%s,data=%08lx,result=%08lx)\n",
1991 GetCurrentThreadId(), callback
, hwnd
, SPY_GetMsgName( msg
, hwnd
),
1996 /***********************************************************************
1999 * Peek for a message matching the given parameters. Return FALSE if none available.
2000 * All pending sent messages are processed before returning.
2002 static BOOL
peek_message( MSG
*msg
, HWND hwnd
, UINT first
, UINT last
, UINT flags
)
2005 ULONG_PTR extra_info
= 0;
2006 struct user_thread_info
*thread_info
= get_user_thread_info();
2007 struct received_message_info info
, *old_info
;
2008 unsigned int wake_mask
, changed_mask
= HIWORD(flags
);
2009 unsigned int hw_id
= 0; /* id of previous hardware message */
2011 if (!first
&& !last
) last
= ~0;
2012 if (!changed_mask
) changed_mask
= QS_ALLINPUT
;
2013 wake_mask
= changed_mask
& (QS_SENDMESSAGE
| QS_SMRESULT
);
2018 void *buffer
= NULL
;
2019 size_t size
= 0, buffer_size
= 0;
2021 do /* loop while buffer is too small */
2023 if (buffer_size
&& !(buffer
= HeapAlloc( GetProcessHeap(), 0, buffer_size
)))
2025 SERVER_START_REQ( get_message
)
2028 req
->get_win
= hwnd
;
2029 req
->get_first
= first
;
2030 req
->get_last
= last
;
2032 req
->wake_mask
= wake_mask
;
2033 req
->changed_mask
= changed_mask
;
2034 if (buffer_size
) wine_server_set_reply( req
, buffer
, buffer_size
);
2035 if (!(res
= wine_server_call( req
)))
2037 size
= wine_server_reply_size( reply
);
2038 info
.type
= reply
->type
;
2039 info
.msg
.hwnd
= reply
->win
;
2040 info
.msg
.message
= reply
->msg
;
2041 info
.msg
.wParam
= reply
->wparam
;
2042 info
.msg
.lParam
= reply
->lparam
;
2043 info
.msg
.time
= reply
->time
;
2044 info
.msg
.pt
.x
= reply
->x
;
2045 info
.msg
.pt
.y
= reply
->y
;
2046 hw_id
= reply
->hw_id
;
2047 extra_info
= reply
->info
;
2048 thread_info
->active_hooks
= reply
->active_hooks
;
2052 HeapFree( GetProcessHeap(), 0, buffer
);
2053 buffer_size
= reply
->total
;
2057 } while (res
== STATUS_BUFFER_OVERFLOW
);
2059 if (res
) return FALSE
;
2061 TRACE( "got type %d msg %x (%s) hwnd %p wp %lx lp %lx\n",
2062 info
.type
, info
.msg
.message
,
2063 (info
.type
== MSG_WINEVENT
) ? "MSG_WINEVENT" : SPY_GetMsgName(info
.msg
.message
, info
.msg
.hwnd
),
2064 info
.msg
.hwnd
, info
.msg
.wParam
, info
.msg
.lParam
);
2070 info
.flags
= ISMEX_SEND
;
2073 info
.flags
= ISMEX_NOTIFY
;
2076 info
.flags
= ISMEX_CALLBACK
;
2078 case MSG_CALLBACK_RESULT
:
2079 if (size
>= sizeof(struct callback_msg_data
))
2081 const struct callback_msg_data
*data
= (const struct callback_msg_data
*)buffer
;
2082 call_sendmsg_callback( data
->callback
, info
.msg
.hwnd
,
2083 info
.msg
.message
, data
->data
, data
->result
);
2087 if (size
>= sizeof(struct winevent_msg_data
))
2089 WINEVENTPROC hook_proc
;
2090 const struct winevent_msg_data
*data
= (const struct winevent_msg_data
*)buffer
;
2092 hook_proc
= data
->hook_proc
;
2093 size
-= sizeof(*data
);
2096 WCHAR module
[MAX_PATH
];
2098 size
= min( size
, (MAX_PATH
- 1) * sizeof(WCHAR
) );
2099 memcpy( module
, buffer
, size
);
2100 module
[size
/ sizeof(WCHAR
)] = 0;
2101 if (!(hook_proc
= get_hook_proc( hook_proc
, module
)))
2103 ERR( "invalid winevent hook module name %s\n", debugstr_w(module
) );
2108 if (TRACE_ON(relay
))
2109 DPRINTF( "%04x:Call winevent proc %p (hook=%p,event=%x,hwnd=%p,object_id=%lx,child_id=%lx,tid=%04x,time=%x)\n",
2110 GetCurrentThreadId(), hook_proc
,
2111 data
->hook
, info
.msg
.message
, info
.msg
.hwnd
, info
.msg
.wParam
,
2112 info
.msg
.lParam
, data
->tid
, info
.msg
.time
);
2114 hook_proc( data
->hook
, info
.msg
.message
, info
.msg
.hwnd
, info
.msg
.wParam
,
2115 info
.msg
.lParam
, data
->tid
, info
.msg
.time
);
2117 if (TRACE_ON(relay
))
2118 DPRINTF( "%04x:Ret winevent proc %p (hook=%p,event=%x,hwnd=%p,object_id=%lx,child_id=%lx,tid=%04x,time=%x)\n",
2119 GetCurrentThreadId(), hook_proc
,
2120 data
->hook
, info
.msg
.message
, info
.msg
.hwnd
, info
.msg
.wParam
,
2121 info
.msg
.lParam
, data
->tid
, info
.msg
.time
);
2124 case MSG_OTHER_PROCESS
:
2125 info
.flags
= ISMEX_SEND
;
2126 if (!unpack_message( info
.msg
.hwnd
, info
.msg
.message
, &info
.msg
.wParam
,
2127 &info
.msg
.lParam
, &buffer
, size
))
2130 reply_message( &info
, 0, TRUE
);
2135 if (!process_hardware_message( &info
.msg
, hw_id
, extra_info
,
2136 hwnd
, first
, last
, flags
& PM_REMOVE
))
2138 TRACE("dropping msg %x\n", info
.msg
.message
);
2139 goto next
; /* ignore it */
2141 thread_info
->GetMessagePosVal
= MAKELONG( info
.msg
.pt
.x
, info
.msg
.pt
.y
);
2144 thread_info
->GetMessageExtraInfoVal
= extra_info
;
2145 if (info
.msg
.message
>= WM_DDE_FIRST
&& info
.msg
.message
<= WM_DDE_LAST
)
2147 if (!unpack_dde_message( info
.msg
.hwnd
, info
.msg
.message
, &info
.msg
.wParam
,
2148 &info
.msg
.lParam
, &buffer
, size
))
2149 goto next
; /* ignore it */
2152 HeapFree( GetProcessHeap(), 0, buffer
);
2156 /* if we get here, we have a sent message; call the window procedure */
2157 old_info
= thread_info
->receive_info
;
2158 thread_info
->receive_info
= &info
;
2159 result
= call_window_proc( info
.msg
.hwnd
, info
.msg
.message
, info
.msg
.wParam
,
2160 info
.msg
.lParam
, (info
.type
!= MSG_ASCII
), FALSE
,
2161 WMCHAR_MAP_RECVMESSAGE
);
2162 reply_message( &info
, result
, TRUE
);
2163 thread_info
->receive_info
= old_info
;
2165 /* if some PM_QS* flags were specified, only handle sent messages from now on */
2166 if (HIWORD(flags
)) flags
= PM_QS_SENDMESSAGE
| LOWORD(flags
);
2168 HeapFree( GetProcessHeap(), 0, buffer
);
2173 /***********************************************************************
2174 * process_sent_messages
2176 * Process all pending sent messages.
2178 static inline void process_sent_messages(void)
2181 peek_message( &msg
, 0, 0, 0, PM_REMOVE
| PM_QS_SENDMESSAGE
);
2185 /***********************************************************************
2186 * get_server_queue_handle
2188 * Get a handle to the server message queue for the current thread.
2190 static HANDLE
get_server_queue_handle(void)
2192 struct user_thread_info
*thread_info
= get_user_thread_info();
2195 if (!(ret
= thread_info
->server_queue
))
2197 SERVER_START_REQ( get_msg_queue
)
2199 wine_server_call( req
);
2200 ret
= reply
->handle
;
2203 thread_info
->server_queue
= ret
;
2204 if (!ret
) ERR( "Cannot get server thread queue\n" );
2210 /***********************************************************************
2211 * wait_message_reply
2213 * Wait until a sent message gets replied to.
2215 static void wait_message_reply( UINT flags
)
2217 HANDLE server_queue
= get_server_queue_handle();
2221 unsigned int wake_bits
= 0;
2224 SERVER_START_REQ( set_queue_mask
)
2226 req
->wake_mask
= QS_SMRESULT
| ((flags
& SMTO_BLOCK
) ? 0 : QS_SENDMESSAGE
);
2227 req
->changed_mask
= req
->wake_mask
;
2229 if (!wine_server_call( req
))
2230 wake_bits
= reply
->wake_bits
;
2234 if (wake_bits
& QS_SMRESULT
) return; /* got a result */
2235 if (wake_bits
& QS_SENDMESSAGE
)
2237 /* Process the sent message immediately */
2238 process_sent_messages();
2242 /* now wait for it */
2244 ReleaseThunkLock( &dwlc
);
2245 res
= USER_Driver
->pMsgWaitForMultipleObjectsEx( 1, &server_queue
,
2246 INFINITE
, QS_SENDMESSAGE
, 0 );
2247 if (dwlc
) RestoreThunkLock( dwlc
);
2251 /***********************************************************************
2252 * put_message_in_queue
2254 * Put a sent message into the destination queue.
2255 * For inter-process message, reply_size is set to expected size of reply data.
2257 static BOOL
put_message_in_queue( const struct send_message_info
*info
, size_t *reply_size
)
2259 struct packed_message data
;
2260 message_data_t msg_data
;
2263 timeout_t timeout
= TIMEOUT_INFINITE
;
2265 /* Check for INFINITE timeout for compatibility with Win9x,
2266 * although Windows >= NT does not do so
2268 if (info
->type
!= MSG_NOTIFY
&&
2269 info
->type
!= MSG_CALLBACK
&&
2270 info
->type
!= MSG_POSTED
&&
2272 info
->timeout
!= INFINITE
)
2274 /* timeout is signed despite the prototype */
2275 timeout
= (timeout_t
)max( 0, (int)info
->timeout
) * -10000;
2279 if (info
->type
== MSG_OTHER_PROCESS
)
2281 *reply_size
= pack_message( info
->hwnd
, info
->msg
, info
->wparam
, info
->lparam
, &data
);
2282 if (data
.count
== -1)
2284 WARN( "cannot pack message %x\n", info
->msg
);
2288 else if (info
->type
== MSG_CALLBACK
)
2290 msg_data
.callback
.callback
= info
->callback
;
2291 msg_data
.callback
.data
= info
->data
;
2292 msg_data
.callback
.result
= 0;
2293 data
.data
[0] = &msg_data
;
2294 data
.size
[0] = sizeof(msg_data
.callback
);
2297 else if (info
->type
== MSG_POSTED
&& info
->msg
>= WM_DDE_FIRST
&& info
->msg
<= WM_DDE_LAST
)
2299 return post_dde_message( &data
, info
);
2302 SERVER_START_REQ( send_message
)
2304 req
->id
= info
->dest_tid
;
2305 req
->type
= info
->type
;
2307 req
->win
= info
->hwnd
;
2308 req
->msg
= info
->msg
;
2309 req
->wparam
= info
->wparam
;
2310 req
->lparam
= info
->lparam
;
2311 req
->timeout
= timeout
;
2313 if (info
->flags
& SMTO_ABORTIFHUNG
) req
->flags
|= SEND_MSG_ABORT_IF_HUNG
;
2314 for (i
= 0; i
< data
.count
; i
++) wine_server_add_data( req
, data
.data
[i
], data
.size
[i
] );
2315 if ((res
= wine_server_call( req
)))
2317 if (res
== STATUS_INVALID_PARAMETER
)
2318 /* FIXME: find a STATUS_ value for this one */
2319 SetLastError( ERROR_INVALID_THREAD_ID
);
2321 SetLastError( RtlNtStatusToDosError(res
) );
2329 /***********************************************************************
2332 * Retrieve a message reply from the server.
2334 static LRESULT
retrieve_reply( const struct send_message_info
*info
,
2335 size_t reply_size
, LRESULT
*result
)
2338 void *reply_data
= NULL
;
2342 if (!(reply_data
= HeapAlloc( GetProcessHeap(), 0, reply_size
)))
2344 WARN( "no memory for reply, will be truncated\n" );
2348 SERVER_START_REQ( get_message_reply
)
2351 if (reply_size
) wine_server_set_reply( req
, reply_data
, reply_size
);
2352 if (!(status
= wine_server_call( req
))) *result
= reply
->result
;
2353 reply_size
= wine_server_reply_size( reply
);
2356 if (!status
&& reply_size
)
2357 unpack_reply( info
->hwnd
, info
->msg
, info
->wparam
, info
->lparam
, reply_data
, reply_size
);
2359 HeapFree( GetProcessHeap(), 0, reply_data
);
2361 TRACE( "hwnd %p msg %x (%s) wp %lx lp %lx got reply %lx (err=%d)\n",
2362 info
->hwnd
, info
->msg
, SPY_GetMsgName(info
->msg
, info
->hwnd
), info
->wparam
,
2363 info
->lparam
, *result
, status
);
2365 /* MSDN states that last error is 0 on timeout, but at least NT4 returns ERROR_TIMEOUT */
2366 if (status
) SetLastError( RtlNtStatusToDosError(status
) );
2371 /***********************************************************************
2372 * send_inter_thread_message
2374 static LRESULT
send_inter_thread_message( const struct send_message_info
*info
, LRESULT
*res_ptr
)
2376 size_t reply_size
= 0;
2378 TRACE( "hwnd %p msg %x (%s) wp %lx lp %lx\n",
2379 info
->hwnd
, info
->msg
, SPY_GetMsgName(info
->msg
, info
->hwnd
), info
->wparam
, info
->lparam
);
2381 USER_CheckNotLock();
2383 if (!put_message_in_queue( info
, &reply_size
)) return 0;
2385 /* there's no reply to wait for on notify/callback messages */
2386 if (info
->type
== MSG_NOTIFY
|| info
->type
== MSG_CALLBACK
) return 1;
2388 wait_message_reply( info
->flags
);
2389 return retrieve_reply( info
, reply_size
, res_ptr
);
2393 /***********************************************************************
2394 * send_inter_thread_callback
2396 static LRESULT
send_inter_thread_callback( HWND hwnd
, UINT msg
, WPARAM wp
, LPARAM lp
,
2397 LRESULT
*result
, void *arg
)
2399 struct send_message_info
*info
= arg
;
2404 return send_inter_thread_message( info
, result
);
2408 /***********************************************************************
2411 * Backend implementation of the various SendMessage functions.
2413 static BOOL
send_message( struct send_message_info
*info
, DWORD_PTR
*res_ptr
, BOOL unicode
)
2419 if (is_broadcast(info
->hwnd
))
2421 EnumWindows( broadcast_message_callback
, (LPARAM
)info
);
2422 if (res_ptr
) *res_ptr
= 1;
2426 if (!(info
->dest_tid
= GetWindowThreadProcessId( info
->hwnd
, &dest_pid
))) return FALSE
;
2428 if (USER_IsExitingThread( info
->dest_tid
)) return FALSE
;
2430 SPY_EnterMessage( SPY_SENDMESSAGE
, info
->hwnd
, info
->msg
, info
->wparam
, info
->lparam
);
2432 if (info
->dest_tid
== GetCurrentThreadId())
2434 result
= call_window_proc( info
->hwnd
, info
->msg
, info
->wparam
, info
->lparam
,
2435 unicode
, TRUE
, info
->wm_char
);
2436 if (info
->type
== MSG_CALLBACK
)
2437 call_sendmsg_callback( info
->callback
, info
->hwnd
, info
->msg
, info
->data
, result
);
2442 if (dest_pid
!= GetCurrentProcessId() && (info
->type
== MSG_ASCII
|| info
->type
== MSG_UNICODE
))
2443 info
->type
= MSG_OTHER_PROCESS
;
2445 /* MSG_ASCII can be sent unconverted except for WM_CHAR; everything else needs to be Unicode */
2446 if (!unicode
&& is_unicode_message( info
->msg
) &&
2447 (info
->type
!= MSG_ASCII
|| info
->msg
== WM_CHAR
))
2448 ret
= WINPROC_CallProcAtoW( send_inter_thread_callback
, info
->hwnd
, info
->msg
,
2449 info
->wparam
, info
->lparam
, &result
, info
, info
->wm_char
);
2451 ret
= send_inter_thread_message( info
, &result
);
2454 SPY_ExitMessage( SPY_RESULT_OK
, info
->hwnd
, info
->msg
, result
, info
->wparam
, info
->lparam
);
2455 if (ret
&& res_ptr
) *res_ptr
= result
;
2460 /***********************************************************************
2461 * MSG_SendInternalMessageTimeout
2463 * Same as SendMessageTimeoutW but sends the message to a specific thread
2464 * without requiring a window handle. Only works for internal Wine messages.
2466 LRESULT
MSG_SendInternalMessageTimeout( DWORD dest_pid
, DWORD dest_tid
,
2467 UINT msg
, WPARAM wparam
, LPARAM lparam
,
2468 UINT flags
, UINT timeout
, PDWORD_PTR res_ptr
)
2470 struct send_message_info info
;
2471 LRESULT ret
, result
;
2473 assert( msg
& 0x80000000 ); /* must be an internal Wine message */
2475 info
.type
= MSG_UNICODE
;
2476 info
.dest_tid
= dest_tid
;
2479 info
.wparam
= wparam
;
2480 info
.lparam
= lparam
;
2482 info
.timeout
= timeout
;
2484 if (USER_IsExitingThread( dest_tid
)) return 0;
2486 if (dest_tid
== GetCurrentThreadId())
2488 result
= handle_internal_message( 0, msg
, wparam
, lparam
);
2493 if (dest_pid
!= GetCurrentProcessId()) info
.type
= MSG_OTHER_PROCESS
;
2494 ret
= send_inter_thread_message( &info
, &result
);
2496 if (ret
&& res_ptr
) *res_ptr
= result
;
2501 /***********************************************************************
2502 * SendMessageTimeoutW (USER32.@)
2504 LRESULT WINAPI
SendMessageTimeoutW( HWND hwnd
, UINT msg
, WPARAM wparam
, LPARAM lparam
,
2505 UINT flags
, UINT timeout
, PDWORD_PTR res_ptr
)
2507 struct send_message_info info
;
2509 info
.type
= MSG_UNICODE
;
2512 info
.wparam
= wparam
;
2513 info
.lparam
= lparam
;
2515 info
.timeout
= timeout
;
2517 return send_message( &info
, res_ptr
, TRUE
);
2520 /***********************************************************************
2521 * SendMessageTimeoutA (USER32.@)
2523 LRESULT WINAPI
SendMessageTimeoutA( HWND hwnd
, UINT msg
, WPARAM wparam
, LPARAM lparam
,
2524 UINT flags
, UINT timeout
, PDWORD_PTR res_ptr
)
2526 struct send_message_info info
;
2528 info
.type
= MSG_ASCII
;
2531 info
.wparam
= wparam
;
2532 info
.lparam
= lparam
;
2534 info
.timeout
= timeout
;
2535 info
.wm_char
= WMCHAR_MAP_SENDMESSAGETIMEOUT
;
2537 return send_message( &info
, res_ptr
, FALSE
);
2541 /***********************************************************************
2542 * SendMessageW (USER32.@)
2544 LRESULT WINAPI
SendMessageW( HWND hwnd
, UINT msg
, WPARAM wparam
, LPARAM lparam
)
2547 struct send_message_info info
;
2549 info
.type
= MSG_UNICODE
;
2552 info
.wparam
= wparam
;
2553 info
.lparam
= lparam
;
2554 info
.flags
= SMTO_NORMAL
;
2557 send_message( &info
, &res
, TRUE
);
2562 /***********************************************************************
2563 * SendMessageA (USER32.@)
2565 LRESULT WINAPI
SendMessageA( HWND hwnd
, UINT msg
, WPARAM wparam
, LPARAM lparam
)
2568 struct send_message_info info
;
2570 info
.type
= MSG_ASCII
;
2573 info
.wparam
= wparam
;
2574 info
.lparam
= lparam
;
2575 info
.flags
= SMTO_NORMAL
;
2577 info
.wm_char
= WMCHAR_MAP_SENDMESSAGE
;
2579 send_message( &info
, &res
, FALSE
);
2584 /***********************************************************************
2585 * SendNotifyMessageA (USER32.@)
2587 BOOL WINAPI
SendNotifyMessageA( HWND hwnd
, UINT msg
, WPARAM wparam
, LPARAM lparam
)
2589 struct send_message_info info
;
2591 if (is_pointer_message(msg
))
2593 SetLastError( ERROR_MESSAGE_SYNC_ONLY
);
2597 info
.type
= MSG_NOTIFY
;
2600 info
.wparam
= wparam
;
2601 info
.lparam
= lparam
;
2603 info
.wm_char
= WMCHAR_MAP_SENDMESSAGETIMEOUT
;
2605 return send_message( &info
, NULL
, FALSE
);
2609 /***********************************************************************
2610 * SendNotifyMessageW (USER32.@)
2612 BOOL WINAPI
SendNotifyMessageW( HWND hwnd
, UINT msg
, WPARAM wparam
, LPARAM lparam
)
2614 struct send_message_info info
;
2616 if (is_pointer_message(msg
))
2618 SetLastError( ERROR_MESSAGE_SYNC_ONLY
);
2622 info
.type
= MSG_NOTIFY
;
2625 info
.wparam
= wparam
;
2626 info
.lparam
= lparam
;
2629 return send_message( &info
, NULL
, TRUE
);
2633 /***********************************************************************
2634 * SendMessageCallbackA (USER32.@)
2636 BOOL WINAPI
SendMessageCallbackA( HWND hwnd
, UINT msg
, WPARAM wparam
, LPARAM lparam
,
2637 SENDASYNCPROC callback
, ULONG_PTR data
)
2639 struct send_message_info info
;
2641 if (is_pointer_message(msg
))
2643 SetLastError( ERROR_MESSAGE_SYNC_ONLY
);
2647 info
.type
= MSG_CALLBACK
;
2650 info
.wparam
= wparam
;
2651 info
.lparam
= lparam
;
2652 info
.callback
= callback
;
2655 info
.wm_char
= WMCHAR_MAP_SENDMESSAGETIMEOUT
;
2657 return send_message( &info
, NULL
, FALSE
);
2661 /***********************************************************************
2662 * SendMessageCallbackW (USER32.@)
2664 BOOL WINAPI
SendMessageCallbackW( HWND hwnd
, UINT msg
, WPARAM wparam
, LPARAM lparam
,
2665 SENDASYNCPROC callback
, ULONG_PTR data
)
2667 struct send_message_info info
;
2669 if (is_pointer_message(msg
))
2671 SetLastError( ERROR_MESSAGE_SYNC_ONLY
);
2675 info
.type
= MSG_CALLBACK
;
2678 info
.wparam
= wparam
;
2679 info
.lparam
= lparam
;
2680 info
.callback
= callback
;
2684 return send_message( &info
, NULL
, TRUE
);
2688 /***********************************************************************
2689 * ReplyMessage (USER32.@)
2691 BOOL WINAPI
ReplyMessage( LRESULT result
)
2693 struct received_message_info
*info
= get_user_thread_info()->receive_info
;
2695 if (!info
) return FALSE
;
2696 reply_message( info
, result
, FALSE
);
2701 /***********************************************************************
2702 * InSendMessage (USER32.@)
2704 BOOL WINAPI
InSendMessage(void)
2706 return (InSendMessageEx(NULL
) & (ISMEX_SEND
|ISMEX_REPLIED
)) == ISMEX_SEND
;
2710 /***********************************************************************
2711 * InSendMessageEx (USER32.@)
2713 DWORD WINAPI
InSendMessageEx( LPVOID reserved
)
2715 struct received_message_info
*info
= get_user_thread_info()->receive_info
;
2717 if (info
) return info
->flags
;
2718 return ISMEX_NOSEND
;
2722 /***********************************************************************
2723 * PostMessageA (USER32.@)
2725 BOOL WINAPI
PostMessageA( HWND hwnd
, UINT msg
, WPARAM wparam
, LPARAM lparam
)
2727 if (!map_wparam_AtoW( msg
, &wparam
, WMCHAR_MAP_POSTMESSAGE
)) return TRUE
;
2728 return PostMessageW( hwnd
, msg
, wparam
, lparam
);
2732 /***********************************************************************
2733 * PostMessageW (USER32.@)
2735 BOOL WINAPI
PostMessageW( HWND hwnd
, UINT msg
, WPARAM wparam
, LPARAM lparam
)
2737 struct send_message_info info
;
2739 if (is_pointer_message( msg
))
2741 SetLastError( ERROR_MESSAGE_SYNC_ONLY
);
2745 TRACE( "hwnd %p msg %x (%s) wp %lx lp %lx\n",
2746 hwnd
, msg
, SPY_GetMsgName(msg
, hwnd
), wparam
, lparam
);
2748 info
.type
= MSG_POSTED
;
2751 info
.wparam
= wparam
;
2752 info
.lparam
= lparam
;
2755 if (is_broadcast(hwnd
))
2757 EnumWindows( broadcast_message_callback
, (LPARAM
)&info
);
2761 if (!hwnd
) return PostThreadMessageW( GetCurrentThreadId(), msg
, wparam
, lparam
);
2763 if (!(info
.dest_tid
= GetWindowThreadProcessId( hwnd
, NULL
))) return FALSE
;
2765 if (USER_IsExitingThread( info
.dest_tid
)) return TRUE
;
2767 return put_message_in_queue( &info
, NULL
);
2771 /**********************************************************************
2772 * PostThreadMessageA (USER32.@)
2774 BOOL WINAPI
PostThreadMessageA( DWORD thread
, UINT msg
, WPARAM wparam
, LPARAM lparam
)
2776 if (!map_wparam_AtoW( msg
, &wparam
, WMCHAR_MAP_POSTMESSAGE
)) return TRUE
;
2777 return PostThreadMessageW( thread
, msg
, wparam
, lparam
);
2781 /**********************************************************************
2782 * PostThreadMessageW (USER32.@)
2784 BOOL WINAPI
PostThreadMessageW( DWORD thread
, UINT msg
, WPARAM wparam
, LPARAM lparam
)
2786 struct send_message_info info
;
2788 if (is_pointer_message( msg
))
2790 SetLastError( ERROR_MESSAGE_SYNC_ONLY
);
2793 if (USER_IsExitingThread( thread
)) return TRUE
;
2795 info
.type
= MSG_POSTED
;
2796 info
.dest_tid
= thread
;
2799 info
.wparam
= wparam
;
2800 info
.lparam
= lparam
;
2802 return put_message_in_queue( &info
, NULL
);
2806 /***********************************************************************
2807 * PostQuitMessage (USER32.@)
2809 * Posts a quit message to the current thread's message queue.
2812 * exit_code [I] Exit code to return from message loop.
2818 * This function is not the same as calling:
2819 *|PostThreadMessage(GetCurrentThreadId(), WM_QUIT, exit_code, 0);
2820 * It instead sets a flag in the message queue that signals it to generate
2821 * a WM_QUIT message when there are no other pending sent or posted messages
2824 void WINAPI
PostQuitMessage( INT exit_code
)
2826 SERVER_START_REQ( post_quit_message
)
2828 req
->exit_code
= exit_code
;
2829 wine_server_call( req
);
2835 /***********************************************************************
2836 * PeekMessageW (USER32.@)
2838 BOOL WINAPI
PeekMessageW( MSG
*msg_out
, HWND hwnd
, UINT first
, UINT last
, UINT flags
)
2840 struct user_thread_info
*thread_info
= get_user_thread_info();
2843 USER_CheckNotLock();
2845 /* check for graphics events */
2846 USER_Driver
->pMsgWaitForMultipleObjectsEx( 0, NULL
, 0, QS_ALLINPUT
, 0 );
2848 hwnd
= WIN_GetFullHandle( hwnd
);
2852 if (!peek_message( &msg
, hwnd
, first
, last
, flags
))
2854 if (!(flags
& PM_NOYIELD
))
2857 ReleaseThunkLock(&count
);
2859 if (count
) RestoreThunkLock(count
);
2863 if (msg
.message
& 0x80000000)
2865 if (!(flags
& PM_REMOVE
))
2867 /* Have to remove the message explicitly.
2868 Do this before handling it, because the message handler may
2869 call PeekMessage again */
2870 peek_message( &msg
, msg
.hwnd
, msg
.message
, msg
.message
, flags
| PM_REMOVE
);
2872 handle_internal_message( msg
.hwnd
, msg
.message
, msg
.wParam
, msg
.lParam
);
2877 thread_info
->GetMessageTimeVal
= msg
.time
;
2878 msg
.pt
.x
= (short)LOWORD( thread_info
->GetMessagePosVal
);
2879 msg
.pt
.y
= (short)HIWORD( thread_info
->GetMessagePosVal
);
2881 HOOK_CallHooks( WH_GETMESSAGE
, HC_ACTION
, flags
& PM_REMOVE
, (LPARAM
)&msg
, TRUE
);
2883 /* copy back our internal safe copy of message data to msg_out.
2884 * msg_out is a variable from the *program*, so it can't be used
2885 * internally as it can get "corrupted" by our use of SendMessage()
2886 * (back to the program) inside the message handling itself. */
2889 SetLastError( ERROR_NOACCESS
);
2897 /***********************************************************************
2898 * PeekMessageA (USER32.@)
2900 BOOL WINAPI
PeekMessageA( MSG
*msg
, HWND hwnd
, UINT first
, UINT last
, UINT flags
)
2902 if (get_pending_wmchar( msg
, first
, last
, (flags
& PM_REMOVE
) )) return TRUE
;
2903 if (!PeekMessageW( msg
, hwnd
, first
, last
, flags
)) return FALSE
;
2904 map_wparam_WtoA( msg
, (flags
& PM_REMOVE
) );
2909 /***********************************************************************
2910 * GetMessageW (USER32.@)
2912 BOOL WINAPI
GetMessageW( MSG
*msg
, HWND hwnd
, UINT first
, UINT last
)
2914 HANDLE server_queue
= get_server_queue_handle();
2915 int mask
= QS_POSTMESSAGE
| QS_SENDMESSAGE
; /* Always selected */
2919 if ((first
<= WM_KEYLAST
) && (last
>= WM_KEYFIRST
)) mask
|= QS_KEY
;
2920 if ( ((first
<= WM_MOUSELAST
) && (last
>= WM_MOUSEFIRST
)) ||
2921 ((first
<= WM_NCMOUSELAST
) && (last
>= WM_NCMOUSEFIRST
)) ) mask
|= QS_MOUSE
;
2922 if ((first
<= WM_TIMER
) && (last
>= WM_TIMER
)) mask
|= QS_TIMER
;
2923 if ((first
<= WM_SYSTIMER
) && (last
>= WM_SYSTIMER
)) mask
|= QS_TIMER
;
2924 if ((first
<= WM_PAINT
) && (last
>= WM_PAINT
)) mask
|= QS_PAINT
;
2926 else mask
= QS_ALLINPUT
;
2928 while (!PeekMessageW( msg
, hwnd
, first
, last
, PM_REMOVE
| PM_NOYIELD
| (mask
<< 16) ))
2932 ReleaseThunkLock( &dwlc
);
2933 USER_Driver
->pMsgWaitForMultipleObjectsEx( 1, &server_queue
, INFINITE
, mask
, 0 );
2934 if (dwlc
) RestoreThunkLock( dwlc
);
2937 return (msg
->message
!= WM_QUIT
);
2941 /***********************************************************************
2942 * GetMessageA (USER32.@)
2944 BOOL WINAPI
GetMessageA( MSG
*msg
, HWND hwnd
, UINT first
, UINT last
)
2946 if (get_pending_wmchar( msg
, first
, last
, TRUE
)) return TRUE
;
2947 GetMessageW( msg
, hwnd
, first
, last
);
2948 map_wparam_WtoA( msg
, TRUE
);
2949 return (msg
->message
!= WM_QUIT
);
2953 /***********************************************************************
2954 * IsDialogMessageA (USER32.@)
2955 * IsDialogMessage (USER32.@)
2957 BOOL WINAPI
IsDialogMessageA( HWND hwndDlg
, LPMSG pmsg
)
2960 map_wparam_AtoW( msg
.message
, &msg
.wParam
, WMCHAR_MAP_NOMAPPING
);
2961 return IsDialogMessageW( hwndDlg
, &msg
);
2965 /***********************************************************************
2966 * TranslateMessage (USER32.@)
2968 * Implementation of TranslateMessage.
2970 * TranslateMessage translates virtual-key messages into character-messages,
2972 * WM_KEYDOWN/WM_KEYUP combinations produce a WM_CHAR or WM_DEADCHAR message.
2973 * ditto replacing WM_* with WM_SYS*
2974 * This produces WM_CHAR messages only for keys mapped to ASCII characters
2975 * by the keyboard driver.
2977 * If the message is WM_KEYDOWN, WM_KEYUP, WM_SYSKEYDOWN, or WM_SYSKEYUP, the
2978 * return value is nonzero, regardless of the translation.
2981 BOOL WINAPI
TranslateMessage( const MSG
*msg
)
2987 if (msg
->message
< WM_KEYFIRST
|| msg
->message
> WM_KEYLAST
) return FALSE
;
2988 if (msg
->message
!= WM_KEYDOWN
&& msg
->message
!= WM_SYSKEYDOWN
) return TRUE
;
2990 TRACE_(key
)("Translating key %s (%04lx), scancode %02x\n",
2991 SPY_GetVKeyName(msg
->wParam
), msg
->wParam
, LOBYTE(HIWORD(msg
->lParam
)));
2993 if ( msg
->wParam
== VK_PROCESSKEY
)
2994 return ImmTranslateMessage(msg
->hwnd
, msg
->message
, msg
->wParam
, msg
->lParam
);
2996 GetKeyboardState( state
);
2997 /* FIXME : should handle ToUnicode yielding 2 */
2998 switch (ToUnicode(msg
->wParam
, HIWORD(msg
->lParam
), state
, wp
, 2, 0))
3001 message
= (msg
->message
== WM_KEYDOWN
) ? WM_CHAR
: WM_SYSCHAR
;
3002 TRACE_(key
)("1 -> PostMessageW(%p,%s,%04x,%08lx)\n",
3003 msg
->hwnd
, SPY_GetMsgName(message
, msg
->hwnd
), wp
[0], msg
->lParam
);
3004 PostMessageW( msg
->hwnd
, message
, wp
[0], msg
->lParam
);
3008 message
= (msg
->message
== WM_KEYDOWN
) ? WM_DEADCHAR
: WM_SYSDEADCHAR
;
3009 TRACE_(key
)("-1 -> PostMessageW(%p,%s,%04x,%08lx)\n",
3010 msg
->hwnd
, SPY_GetMsgName(message
, msg
->hwnd
), wp
[0], msg
->lParam
);
3011 PostMessageW( msg
->hwnd
, message
, wp
[0], msg
->lParam
);
3018 /***********************************************************************
3019 * DispatchMessageA (USER32.@)
3021 * See DispatchMessageW.
3023 LRESULT WINAPI
DispatchMessageA( const MSG
* msg
)
3027 /* Process timer messages */
3028 if ((msg
->message
== WM_TIMER
) || (msg
->message
== WM_SYSTIMER
))
3030 if (msg
->lParam
) return CallWindowProcA( (WNDPROC
)msg
->lParam
, msg
->hwnd
,
3031 msg
->message
, msg
->wParam
, GetTickCount() );
3033 if (!msg
->hwnd
) return 0;
3035 SPY_EnterMessage( SPY_DISPATCHMESSAGE
, msg
->hwnd
, msg
->message
,
3036 msg
->wParam
, msg
->lParam
);
3038 if (!WINPROC_call_window( msg
->hwnd
, msg
->message
, msg
->wParam
, msg
->lParam
,
3039 &retval
, FALSE
, WMCHAR_MAP_DISPATCHMESSAGE
))
3041 if (!IsWindow( msg
->hwnd
)) SetLastError( ERROR_INVALID_WINDOW_HANDLE
);
3042 else SetLastError( ERROR_MESSAGE_SYNC_ONLY
);
3046 SPY_ExitMessage( SPY_RESULT_OK
, msg
->hwnd
, msg
->message
, retval
,
3047 msg
->wParam
, msg
->lParam
);
3049 if (msg
->message
== WM_PAINT
)
3051 /* send a WM_NCPAINT and WM_ERASEBKGND if the non-client area is still invalid */
3052 HRGN hrgn
= CreateRectRgn( 0, 0, 0, 0 );
3053 GetUpdateRgn( msg
->hwnd
, hrgn
, TRUE
);
3054 DeleteObject( hrgn
);
3060 /***********************************************************************
3061 * DispatchMessageW (USER32.@) Process a message
3063 * Process the message specified in the structure *_msg_.
3065 * If the lpMsg parameter points to a WM_TIMER message and the
3066 * parameter of the WM_TIMER message is not NULL, the lParam parameter
3067 * points to the function that is called instead of the window
3070 * The message must be valid.
3074 * DispatchMessage() returns the result of the window procedure invoked.
3081 LRESULT WINAPI
DispatchMessageW( const MSG
* msg
)
3085 /* Process timer messages */
3086 if ((msg
->message
== WM_TIMER
) || (msg
->message
== WM_SYSTIMER
))
3088 if (msg
->lParam
) return CallWindowProcW( (WNDPROC
)msg
->lParam
, msg
->hwnd
,
3089 msg
->message
, msg
->wParam
, GetTickCount() );
3091 if (!msg
->hwnd
) return 0;
3093 SPY_EnterMessage( SPY_DISPATCHMESSAGE
, msg
->hwnd
, msg
->message
,
3094 msg
->wParam
, msg
->lParam
);
3096 if (!WINPROC_call_window( msg
->hwnd
, msg
->message
, msg
->wParam
, msg
->lParam
,
3097 &retval
, TRUE
, WMCHAR_MAP_DISPATCHMESSAGE
))
3099 if (!IsWindow( msg
->hwnd
)) SetLastError( ERROR_INVALID_WINDOW_HANDLE
);
3100 else SetLastError( ERROR_MESSAGE_SYNC_ONLY
);
3104 SPY_ExitMessage( SPY_RESULT_OK
, msg
->hwnd
, msg
->message
, retval
,
3105 msg
->wParam
, msg
->lParam
);
3107 if (msg
->message
== WM_PAINT
)
3109 /* send a WM_NCPAINT and WM_ERASEBKGND if the non-client area is still invalid */
3110 HRGN hrgn
= CreateRectRgn( 0, 0, 0, 0 );
3111 GetUpdateRgn( msg
->hwnd
, hrgn
, TRUE
);
3112 DeleteObject( hrgn
);
3118 /***********************************************************************
3119 * GetMessagePos (USER.119)
3120 * GetMessagePos (USER32.@)
3122 * The GetMessagePos() function returns a long value representing a
3123 * cursor position, in screen coordinates, when the last message
3124 * retrieved by the GetMessage() function occurs. The x-coordinate is
3125 * in the low-order word of the return value, the y-coordinate is in
3126 * the high-order word. The application can use the MAKEPOINT()
3127 * macro to obtain a POINT structure from the return value.
3129 * For the current cursor position, use GetCursorPos().
3133 * Cursor position of last message on success, zero on failure.
3140 DWORD WINAPI
GetMessagePos(void)
3142 return get_user_thread_info()->GetMessagePosVal
;
3146 /***********************************************************************
3147 * GetMessageTime (USER.120)
3148 * GetMessageTime (USER32.@)
3150 * GetMessageTime() returns the message time for the last message
3151 * retrieved by the function. The time is measured in milliseconds with
3152 * the same offset as GetTickCount().
3154 * Since the tick count wraps, this is only useful for moderately short
3155 * relative time comparisons.
3159 * Time of last message on success, zero on failure.
3161 LONG WINAPI
GetMessageTime(void)
3163 return get_user_thread_info()->GetMessageTimeVal
;
3167 /***********************************************************************
3168 * GetMessageExtraInfo (USER.288)
3169 * GetMessageExtraInfo (USER32.@)
3171 LPARAM WINAPI
GetMessageExtraInfo(void)
3173 return get_user_thread_info()->GetMessageExtraInfoVal
;
3177 /***********************************************************************
3178 * SetMessageExtraInfo (USER32.@)
3180 LPARAM WINAPI
SetMessageExtraInfo(LPARAM lParam
)
3182 struct user_thread_info
*thread_info
= get_user_thread_info();
3183 LONG old_value
= thread_info
->GetMessageExtraInfoVal
;
3184 thread_info
->GetMessageExtraInfoVal
= lParam
;
3189 /***********************************************************************
3190 * WaitMessage (USER.112) Suspend thread pending messages
3191 * WaitMessage (USER32.@) Suspend thread pending messages
3193 * WaitMessage() suspends a thread until events appear in the thread's
3196 BOOL WINAPI
WaitMessage(void)
3198 return (MsgWaitForMultipleObjectsEx( 0, NULL
, INFINITE
, QS_ALLINPUT
, 0 ) != WAIT_FAILED
);
3202 /***********************************************************************
3203 * MsgWaitForMultipleObjectsEx (USER32.@)
3205 DWORD WINAPI
MsgWaitForMultipleObjectsEx( DWORD count
, CONST HANDLE
*pHandles
,
3206 DWORD timeout
, DWORD mask
, DWORD flags
)
3208 HANDLE handles
[MAXIMUM_WAIT_OBJECTS
];
3211 if (count
> MAXIMUM_WAIT_OBJECTS
-1)
3213 SetLastError( ERROR_INVALID_PARAMETER
);
3217 /* set the queue mask */
3218 SERVER_START_REQ( set_queue_mask
)
3220 req
->wake_mask
= (flags
& MWMO_INPUTAVAILABLE
) ? mask
: 0;
3221 req
->changed_mask
= mask
;
3223 wine_server_call( req
);
3227 /* add the queue to the handle list */
3228 for (i
= 0; i
< count
; i
++) handles
[i
] = pHandles
[i
];
3229 handles
[count
] = get_server_queue_handle();
3231 ReleaseThunkLock( &lock
);
3232 ret
= USER_Driver
->pMsgWaitForMultipleObjectsEx( count
+1, handles
, timeout
, mask
, flags
);
3233 if (lock
) RestoreThunkLock( lock
);
3238 /***********************************************************************
3239 * MsgWaitForMultipleObjects (USER32.@)
3241 DWORD WINAPI
MsgWaitForMultipleObjects( DWORD count
, CONST HANDLE
*handles
,
3242 BOOL wait_all
, DWORD timeout
, DWORD mask
)
3244 return MsgWaitForMultipleObjectsEx( count
, handles
, timeout
, mask
,
3245 wait_all
? MWMO_WAITALL
: 0 );
3249 /***********************************************************************
3250 * WaitForInputIdle (USER32.@)
3252 DWORD WINAPI
WaitForInputIdle( HANDLE hProcess
, DWORD dwTimeOut
)
3254 DWORD start_time
, elapsed
, ret
;
3257 handles
[0] = hProcess
;
3258 SERVER_START_REQ( get_process_idle_event
)
3260 req
->handle
= hProcess
;
3261 if (!(ret
= wine_server_call_err( req
))) handles
[1] = reply
->event
;
3264 if (ret
) return WAIT_FAILED
; /* error */
3265 if (!handles
[1]) return 0; /* no event to wait on */
3267 start_time
= GetTickCount();
3270 TRACE("waiting for %p\n", handles
[1] );
3273 ret
= MsgWaitForMultipleObjects ( 2, handles
, FALSE
, dwTimeOut
- elapsed
, QS_SENDMESSAGE
);
3278 case WAIT_OBJECT_0
+2:
3279 process_sent_messages();
3283 TRACE("timeout or error\n");
3286 TRACE("finished\n");
3289 if (dwTimeOut
!= INFINITE
)
3291 elapsed
= GetTickCount() - start_time
;
3292 if (elapsed
> dwTimeOut
)
3298 return WAIT_TIMEOUT
;
3302 /***********************************************************************
3303 * UserYield (USER.332)
3305 void WINAPI
UserYield16(void)
3309 /* Handle sent messages */
3310 process_sent_messages();
3313 ReleaseThunkLock(&count
);
3317 RestoreThunkLock(count
);
3318 /* Handle sent messages again */
3319 process_sent_messages();
3324 /***********************************************************************
3325 * RegisterWindowMessageA (USER32.@)
3326 * RegisterWindowMessage (USER.118)
3328 UINT WINAPI
RegisterWindowMessageA( LPCSTR str
)
3330 UINT ret
= GlobalAddAtomA(str
);
3331 TRACE("%s, ret=%x\n", str
, ret
);
3336 /***********************************************************************
3337 * RegisterWindowMessageW (USER32.@)
3339 UINT WINAPI
RegisterWindowMessageW( LPCWSTR str
)
3341 UINT ret
= GlobalAddAtomW(str
);
3342 TRACE("%s ret=%x\n", debugstr_w(str
), ret
);
3346 typedef struct BroadcastParm
3357 static BOOL CALLBACK
bcast_childwindow( HWND hw
, LPARAM lp
)
3359 BroadcastParm
*parm
= (BroadcastParm
*)lp
;
3360 DWORD_PTR retval
= 0;
3363 if (parm
->flags
& BSF_IGNORECURRENTTASK
&& WIN_IsCurrentProcess(hw
))
3365 TRACE("Not telling myself %p\n", hw
);
3369 /* I don't know 100% for sure if this is what Windows does, but it fits the tests */
3370 if (parm
->flags
& BSF_QUERY
)
3372 TRACE("Telling window %p using SendMessageTimeout\n", hw
);
3374 /* Not tested for conflicting flags */
3375 if (parm
->flags
& BSF_FORCEIFHUNG
|| parm
->flags
& BSF_NOHANG
)
3376 lresult
= SendMessageTimeoutW( hw
, parm
->msg
, parm
->wp
, parm
->lp
, SMTO_ABORTIFHUNG
, 2000, &retval
);
3377 else if (parm
->flags
& BSF_NOTIMEOUTIFNOTHUNG
)
3378 lresult
= SendMessageTimeoutW( hw
, parm
->msg
, parm
->wp
, parm
->lp
, SMTO_NOTIMEOUTIFNOTHUNG
, 2000, &retval
);
3380 lresult
= SendMessageTimeoutW( hw
, parm
->msg
, parm
->wp
, parm
->lp
, SMTO_NORMAL
, 2000, &retval
);
3382 if (!lresult
&& GetLastError() == ERROR_TIMEOUT
)
3384 WARN("Timed out!\n");
3385 if (!(parm
->flags
& BSF_FORCEIFHUNG
))
3388 if (retval
== BROADCAST_QUERY_DENY
)
3397 else if (parm
->flags
& BSF_POSTMESSAGE
)
3399 TRACE("Telling window %p using PostMessage\n", hw
);
3400 PostMessageW( hw
, parm
->msg
, parm
->wp
, parm
->lp
);
3404 TRACE("Telling window %p using SendNotifyMessage\n", hw
);
3405 SendNotifyMessageW( hw
, parm
->msg
, parm
->wp
, parm
->lp
);
3411 static BOOL CALLBACK
bcast_desktop( LPWSTR desktop
, LPARAM lp
)
3415 BroadcastParm
*parm
= (BroadcastParm
*)lp
;
3417 TRACE("desktop: %s\n", debugstr_w( desktop
));
3419 hdesktop
= open_winstation_desktop( parm
->winsta
, desktop
, 0, FALSE
, DESKTOP_ENUMERATE
|DESKTOP_WRITEOBJECTS
|STANDARD_RIGHTS_WRITE
);
3422 FIXME("Could not open desktop %s\n", debugstr_w(desktop
));
3426 ret
= EnumDesktopWindows( hdesktop
, bcast_childwindow
, lp
);
3427 CloseDesktop(hdesktop
);
3428 TRACE("-->%d\n", ret
);
3429 return parm
->success
;
3432 static BOOL CALLBACK
bcast_winsta( LPWSTR winsta
, LPARAM lp
)
3435 HWINSTA hwinsta
= OpenWindowStationW( winsta
, FALSE
, WINSTA_ENUMDESKTOPS
);
3436 TRACE("hwinsta: %p/%s/%08x\n", hwinsta
, debugstr_w( winsta
), GetLastError());
3439 ((BroadcastParm
*)lp
)->winsta
= hwinsta
;
3440 ret
= EnumDesktopsW( hwinsta
, bcast_desktop
, lp
);
3441 CloseWindowStation( hwinsta
);
3442 TRACE("-->%d\n", ret
);
3446 /***********************************************************************
3447 * BroadcastSystemMessageA (USER32.@)
3448 * BroadcastSystemMessage (USER32.@)
3450 LONG WINAPI
BroadcastSystemMessageA( DWORD flags
, LPDWORD recipients
, UINT msg
, WPARAM wp
, LPARAM lp
)
3452 return BroadcastSystemMessageExA( flags
, recipients
, msg
, wp
, lp
, NULL
);
3456 /***********************************************************************
3457 * BroadcastSystemMessageW (USER32.@)
3459 LONG WINAPI
BroadcastSystemMessageW( DWORD flags
, LPDWORD recipients
, UINT msg
, WPARAM wp
, LPARAM lp
)
3461 return BroadcastSystemMessageExW( flags
, recipients
, msg
, wp
, lp
, NULL
);
3464 /***********************************************************************
3465 * BroadcastSystemMessageExA (USER32.@)
3467 LONG WINAPI
BroadcastSystemMessageExA( DWORD flags
, LPDWORD recipients
, UINT msg
, WPARAM wp
, LPARAM lp
, PBSMINFO pinfo
)
3469 map_wparam_AtoW( msg
, &wp
, WMCHAR_MAP_NOMAPPING
);
3470 return BroadcastSystemMessageExW( flags
, recipients
, msg
, wp
, lp
, NULL
);
3474 /***********************************************************************
3475 * BroadcastSystemMessageExW (USER32.@)
3477 LONG WINAPI
BroadcastSystemMessageExW( DWORD flags
, LPDWORD recipients
, UINT msg
, WPARAM wp
, LPARAM lp
, PBSMINFO pinfo
)
3480 DWORD recips
= BSM_ALLCOMPONENTS
;
3482 static const DWORD all_flags
= ( BSF_QUERY
| BSF_IGNORECURRENTTASK
| BSF_FLUSHDISK
| BSF_NOHANG
3483 | BSF_POSTMESSAGE
| BSF_FORCEIFHUNG
| BSF_NOTIMEOUTIFNOTHUNG
3484 | BSF_ALLOWSFW
| BSF_SENDNOTIFYMESSAGE
| BSF_RETURNHDESK
| BSF_LUID
);
3486 TRACE("Flags: %08x, recipients: %p(0x%x), msg: %04x, wparam: %08lx, lparam: %08lx\n", flags
, recipients
,
3487 (recipients
? *recipients
: recips
), msg
, wp
, lp
);
3489 if (flags
& ~all_flags
)
3491 SetLastError(ERROR_INVALID_PARAMETER
);
3496 recipients
= &recips
;
3498 if ( pinfo
&& flags
& BSF_QUERY
)
3499 FIXME("Not returning PBSMINFO information yet\n");
3502 parm
.recipients
= recipients
;
3506 parm
.success
= TRUE
;
3508 if (*recipients
& BSM_ALLDESKTOPS
|| *recipients
== BSM_ALLCOMPONENTS
)
3509 ret
= EnumWindowStationsW(bcast_winsta
, (LONG_PTR
)&parm
);
3510 else if (*recipients
& BSM_APPLICATIONS
)
3512 EnumWindows(bcast_childwindow
, (LONG_PTR
)&parm
);
3516 FIXME("Recipients %08x not supported!\n", *recipients
);
3521 /***********************************************************************
3522 * SetMessageQueue (USER32.@)
3524 BOOL WINAPI
SetMessageQueue( INT size
)
3526 /* now obsolete the message queue will be expanded dynamically as necessary */
3531 /***********************************************************************
3532 * MessageBeep (USER32.@)
3534 BOOL WINAPI
MessageBeep( UINT i
)
3537 SystemParametersInfoA( SPI_GETBEEP
, 0, &active
, FALSE
);
3538 if (active
) USER_Driver
->pBeep();
3543 /***********************************************************************
3544 * SetTimer (USER32.@)
3546 UINT_PTR WINAPI
SetTimer( HWND hwnd
, UINT_PTR id
, UINT timeout
, TIMERPROC proc
)
3549 WNDPROC winproc
= 0;
3551 if (proc
) winproc
= WINPROC_AllocProc( (WNDPROC
)proc
, NULL
);
3553 SERVER_START_REQ( set_win_timer
)
3556 req
->msg
= WM_TIMER
;
3558 req
->rate
= max( timeout
, SYS_TIMER_RATE
);
3559 req
->lparam
= (unsigned long)winproc
;
3560 if (!wine_server_call_err( req
))
3563 if (!ret
) ret
= TRUE
;
3569 TRACE("Added %p %lx %p timeout %d\n", hwnd
, id
, winproc
, timeout
);
3574 /***********************************************************************
3575 * SetSystemTimer (USER32.@)
3577 UINT_PTR WINAPI
SetSystemTimer( HWND hwnd
, UINT_PTR id
, UINT timeout
, TIMERPROC proc
)
3580 WNDPROC winproc
= 0;
3582 if (proc
) winproc
= WINPROC_AllocProc( (WNDPROC
)proc
, NULL
);
3584 SERVER_START_REQ( set_win_timer
)
3587 req
->msg
= WM_SYSTIMER
;
3589 req
->rate
= max( timeout
, SYS_TIMER_RATE
);
3590 req
->lparam
= (unsigned long)winproc
;
3591 if (!wine_server_call_err( req
))
3594 if (!ret
) ret
= TRUE
;
3600 TRACE("Added %p %lx %p timeout %d\n", hwnd
, id
, winproc
, timeout
);
3605 /***********************************************************************
3606 * KillTimer (USER32.@)
3608 BOOL WINAPI
KillTimer( HWND hwnd
, UINT_PTR id
)
3612 SERVER_START_REQ( kill_win_timer
)
3615 req
->msg
= WM_TIMER
;
3617 ret
= !wine_server_call_err( req
);
3624 /***********************************************************************
3625 * KillSystemTimer (USER32.@)
3627 BOOL WINAPI
KillSystemTimer( HWND hwnd
, UINT_PTR id
)
3631 SERVER_START_REQ( kill_win_timer
)
3634 req
->msg
= WM_SYSTIMER
;
3636 ret
= !wine_server_call_err( req
);
3643 /**********************************************************************
3644 * GetGUIThreadInfo (USER32.@)
3646 BOOL WINAPI
GetGUIThreadInfo( DWORD id
, GUITHREADINFO
*info
)
3650 SERVER_START_REQ( get_thread_input
)
3653 if ((ret
= !wine_server_call_err( req
)))
3656 info
->hwndActive
= reply
->active
;
3657 info
->hwndFocus
= reply
->focus
;
3658 info
->hwndCapture
= reply
->capture
;
3659 info
->hwndMenuOwner
= reply
->menu_owner
;
3660 info
->hwndMoveSize
= reply
->move_size
;
3661 info
->hwndCaret
= reply
->caret
;
3662 info
->rcCaret
.left
= reply
->rect
.left
;
3663 info
->rcCaret
.top
= reply
->rect
.top
;
3664 info
->rcCaret
.right
= reply
->rect
.right
;
3665 info
->rcCaret
.bottom
= reply
->rect
.bottom
;
3666 if (reply
->menu_owner
) info
->flags
|= GUI_INMENUMODE
;
3667 if (reply
->move_size
) info
->flags
|= GUI_INMOVESIZE
;
3668 if (reply
->caret
) info
->flags
|= GUI_CARETBLINKING
;
3676 /******************************************************************
3677 * IsHungAppWindow (USER32.@)
3680 BOOL WINAPI
IsHungAppWindow( HWND hWnd
)
3684 SERVER_START_REQ( is_window_hung
)
3687 ret
= !wine_server_call_err( req
) && reply
->is_hung
;