2 * Window messaging support
4 * Copyright 2001 Alexandre Julliard
13 #include "wine/unicode.h"
14 #include "wine/server.h"
22 #include "debugtools.h"
24 DEFAULT_DEBUG_CHANNEL(msg
);
26 #define WM_NCMOUSEFIRST WM_NCMOUSEMOVE
27 #define WM_NCMOUSELAST WM_NCMBUTTONDBLCLK
29 #define MAX_PACK_COUNT 4
31 /* description of the data fields that need to be packed along with a sent message */
35 const void *data
[MAX_PACK_COUNT
];
36 size_t size
[MAX_PACK_COUNT
];
39 /* info about the message currently being received by the current thread */
40 struct received_message_info
42 enum message_type type
;
44 UINT flags
; /* InSendMessageEx return flags */
47 /* structure to group all parameters for sent messages of the various kinds */
48 struct send_message_info
50 enum message_type type
;
55 UINT flags
; /* flags for SendMessageTimeout */
56 UINT timeout
; /* timeout for SendMessageTimeout */
57 SENDASYNCPROC callback
; /* callback function for SendMessageCallback */
58 ULONG_PTR data
; /* callback data */
62 /* flag for messages that contain pointers */
63 /* 32 messages per entry, messages 0..31 map to bits 0..31 */
65 #define SET(msg) (1 << ((msg) & 31))
67 static const unsigned int message_pointer_flags
[] =
70 SET(WM_CREATE
) | SET(WM_SETTEXT
) | SET(WM_GETTEXT
) |
71 SET(WM_WININICHANGE
) | SET(WM_DEVMODECHANGE
),
73 SET(WM_GETMINMAXINFO
) | SET(WM_DRAWITEM
) | SET(WM_MEASUREITEM
) | SET(WM_DELETEITEM
) |
76 SET(WM_WINDOWPOSCHANGING
) | SET(WM_WINDOWPOSCHANGED
) | SET(WM_COPYDATA
) |
77 SET(WM_NOTIFY
) | SET(WM_HELP
),
79 SET(WM_STYLECHANGING
) | SET(WM_STYLECHANGED
),
81 SET(WM_NCCREATE
) | SET(WM_NCCALCSIZE
) | SET(WM_GETDLGCODE
),
83 SET(EM_GETSEL
) | SET(EM_GETRECT
) | SET(EM_SETRECT
) | SET(EM_SETRECTNP
),
85 SET(EM_REPLACESEL
) | SET(EM_GETLINE
) | SET(EM_SETTABSTOPS
),
87 SET(SBM_GETRANGE
) | SET(SBM_SETSCROLLINFO
) | SET(SBM_GETSCROLLINFO
),
93 SET(CB_GETEDITSEL
) | SET(CB_ADDSTRING
) | SET(CB_DIR
) | SET(CB_GETLBTEXT
) |
94 SET(CB_INSERTSTRING
) | SET(CB_FINDSTRING
) | SET(CB_SELECTSTRING
) |
95 SET(CB_GETDROPPEDCONTROLRECT
) | SET(CB_FINDSTRINGEXACT
),
99 SET(LB_ADDSTRING
) | SET(LB_INSERTSTRING
) | SET(LB_GETTEXT
) | SET(LB_SELECTSTRING
) |
100 SET(LB_DIR
) | SET(LB_FINDSTRING
) |
101 SET(LB_GETSELITEMS
) | SET(LB_SETTABSTOPS
) | SET(LB_ADDFILE
) | SET(LB_GETITEMRECT
),
103 SET(LB_FINDSTRINGEXACT
),
109 SET(WM_NEXTMENU
) | SET(WM_SIZING
) | SET(WM_MOVING
) | SET(WM_DEVICECHANGE
),
111 SET(WM_MDICREATE
) | SET(WM_MDIGETACTIVE
) | SET(WM_DROPOBJECT
) |
112 SET(WM_QUERYDROPOBJECT
) | SET(WM_DRAGLOOP
) | SET(WM_DRAGSELECT
) | SET(WM_DRAGMOVE
),
126 SET(WM_ASKCBFORMATNAME
)
129 /* flags for messages that contain Unicode strings */
130 static const unsigned int message_unicode_flags
[] =
133 SET(WM_CREATE
) | SET(WM_SETTEXT
) | SET(WM_GETTEXT
) | SET(WM_GETTEXTLENGTH
) |
134 SET(WM_WININICHANGE
) | SET(WM_DEVMODECHANGE
),
146 SET(EM_REPLACESEL
) | SET(EM_GETLINE
) | SET(EM_SETPASSWORDCHAR
),
150 SET(WM_CHAR
) | SET(WM_DEADCHAR
) | SET(WM_SYSCHAR
) | SET(WM_SYSDEADCHAR
),
154 SET(CB_ADDSTRING
) | SET(CB_DIR
) | SET(CB_GETLBTEXT
) | SET(CB_GETLBTEXTLEN
) |
155 SET(CB_INSERTSTRING
) | SET(CB_FINDSTRING
) | SET(CB_SELECTSTRING
) | SET(CB_FINDSTRINGEXACT
),
159 SET(LB_ADDSTRING
) | SET(LB_INSERTSTRING
) | SET(LB_GETTEXT
) | SET(LB_GETTEXTLEN
) |
160 SET(LB_SELECTSTRING
) | SET(LB_DIR
) | SET(LB_FINDSTRING
) | SET(LB_ADDFILE
),
162 SET(LB_FINDSTRINGEXACT
),
184 SET(WM_PAINTCLIPBOARD
) | SET(WM_SIZECLIPBOARD
) | SET(WM_ASKCBFORMATNAME
)
187 /* check whether a given message type includes pointers */
188 inline static int is_pointer_message( UINT message
)
190 if (message
>= 8*sizeof(message_pointer_flags
)) return FALSE
;
191 return (message_pointer_flags
[message
/ 32] & SET(message
)) != 0;
194 /* check whether a given message type contains Unicode (or ASCII) chars */
195 inline static int is_unicode_message( UINT message
)
197 if (message
>= 8*sizeof(message_unicode_flags
)) return FALSE
;
198 return (message_unicode_flags
[message
/ 32] & SET(message
)) != 0;
203 /* compute the total size of the packed data */
204 inline static size_t get_data_total_size( const struct packed_message
*data
)
208 for (i
= 0; i
< data
->count
; i
++) total
+= data
->size
[i
];
212 /* copy all the data of a packed message into a single dest buffer */
213 inline static void copy_all_data( void *dest
, const struct packed_message
*data
)
216 for (i
= 0; i
< data
->count
; i
++)
218 memcpy( dest
, data
->data
[i
], data
->size
[i
] );
219 dest
= (char *)dest
+ data
->size
[i
];
223 /* add a data field to a packed message */
224 inline static void push_data( struct packed_message
*data
, const void *ptr
, size_t size
)
226 data
->data
[data
->count
] = ptr
;
227 data
->size
[data
->count
] = size
;
231 /* add a string to a packed message */
232 inline static void push_string( struct packed_message
*data
, LPCWSTR str
)
234 push_data( data
, str
, (strlenW(str
) + 1) * sizeof(WCHAR
) );
237 /* retrieve a pointer to data from a packed message and increment the buffer pointer */
238 inline static void *get_data( void **buffer
, size_t size
)
241 *buffer
= (char *)*buffer
+ size
;
245 /* make sure that the buffer contains a valid null-terminated Unicode string */
246 inline static BOOL
check_string( LPCWSTR str
, size_t size
)
248 for (size
/= sizeof(WCHAR
); size
; size
--, str
++)
249 if (!*str
) return TRUE
;
253 /* make sure that there is space for 'size' bytes in buffer, growing it if needed */
254 inline static void *get_buffer_space( void **buffer
, size_t size
)
257 if (!(ret
= HeapReAlloc( GetProcessHeap(), 0, *buffer
, size
)))
258 HeapFree( GetProcessHeap(), 0, *buffer
);
263 /* retrieve a string pointer from packed data */
264 inline static LPWSTR
get_string( void **buffer
)
266 return get_data( buffer
, (strlenW( (LPWSTR
)*buffer
) + 1) * sizeof(WCHAR
) );
269 /* check whether a combobox expects strings or ids in CB_ADDSTRING/CB_INSERTSTRING */
270 inline static BOOL
combobox_has_strings( HWND hwnd
)
272 DWORD style
= GetWindowLongA( hwnd
, GWL_STYLE
);
273 return (!(style
& (CBS_OWNERDRAWFIXED
| CBS_OWNERDRAWVARIABLE
)) || (style
& CBS_HASSTRINGS
));
276 /* check whether a listbox expects strings or ids in LB_ADDSTRING/LB_INSERTSTRING */
277 inline static BOOL
listbox_has_strings( HWND hwnd
)
279 DWORD style
= GetWindowLongA( hwnd
, GWL_STYLE
);
280 return (!(style
& (LBS_OWNERDRAWFIXED
| LBS_OWNERDRAWVARIABLE
)) || (style
& LBS_HASSTRINGS
));
283 /* check if hwnd is a broadcast magic handle */
284 inline static BOOL
is_broadcast( HWND hwnd
)
286 return (hwnd
== HWND_BROADCAST
|| hwnd
== HWND_TOPMOST
);
290 /***********************************************************************
291 * broadcast_message_callback
293 * Helper callback for broadcasting messages.
295 static BOOL CALLBACK
broadcast_message_callback( HWND hwnd
, LPARAM lparam
)
297 struct send_message_info
*info
= (struct send_message_info
*)lparam
;
298 if (!(GetWindowLongW( hwnd
, GWL_STYLE
) & (WS_POPUP
|WS_CAPTION
))) return TRUE
;
302 SendMessageTimeoutW( hwnd
, info
->msg
, info
->wparam
, info
->lparam
,
303 info
->flags
, info
->timeout
, NULL
);
306 SendMessageTimeoutA( hwnd
, info
->msg
, info
->wparam
, info
->lparam
,
307 info
->flags
, info
->timeout
, NULL
);
310 SendNotifyMessageW( hwnd
, info
->msg
, info
->wparam
, info
->lparam
);
313 SendMessageCallbackW( hwnd
, info
->msg
, info
->wparam
, info
->lparam
,
314 info
->callback
, info
->data
);
317 PostMessageW( hwnd
, info
->msg
, info
->wparam
, info
->lparam
);
320 ERR( "bad type %d\n", info
->type
);
327 /***********************************************************************
330 * Convert the wparam of an ASCII message to Unicode.
332 static WPARAM
map_wparam_AtoW( UINT message
, WPARAM wparam
)
334 if (message
== WM_CHARTOITEM
||
335 message
== EM_SETPASSWORDCHAR
||
336 message
== WM_CHAR
||
337 message
== WM_DEADCHAR
||
338 message
== WM_SYSCHAR
||
339 message
== WM_SYSDEADCHAR
||
340 message
== WM_MENUCHAR
)
342 char ch
= LOWORD(wparam
);
344 MultiByteToWideChar(CP_ACP
, 0, &ch
, 1, &wch
, 1);
345 wparam
= MAKEWPARAM( wch
, HIWORD(wparam
) );
351 /***********************************************************************
354 * Convert the wparam of a Unicode message to ASCII.
356 static WPARAM
map_wparam_WtoA( UINT message
, WPARAM wparam
)
358 if (message
== WM_CHARTOITEM
||
359 message
== EM_SETPASSWORDCHAR
||
360 message
== WM_CHAR
||
361 message
== WM_DEADCHAR
||
362 message
== WM_SYSCHAR
||
363 message
== WM_SYSDEADCHAR
||
364 message
== WM_MENUCHAR
)
366 WCHAR wch
= LOWORD(wparam
);
368 WideCharToMultiByte( CP_ACP
, 0, &wch
, 1, &ch
, 1, NULL
, NULL
);
369 wparam
= MAKEWPARAM( (unsigned char)ch
, HIWORD(wparam
) );
375 /***********************************************************************
378 * Pack a message for sending to another process.
379 * Return the size of the data we expect in the message reply.
380 * Set data->count to -1 if there is an error.
382 static size_t pack_message( HWND hwnd
, UINT message
, WPARAM wparam
, LPARAM lparam
,
383 struct packed_message
*data
)
391 CREATESTRUCTW
*cs
= (CREATESTRUCTW
*)lparam
;
392 push_data( data
, cs
, sizeof(*cs
) );
393 if (HIWORD(cs
->lpszName
)) push_string( data
, cs
->lpszName
);
394 if (HIWORD(cs
->lpszClass
)) push_string( data
, cs
->lpszClass
);
398 case WM_ASKCBFORMATNAME
:
399 return wparam
* sizeof(WCHAR
);
401 case WM_WININICHANGE
:
402 case WM_DEVMODECHANGE
:
405 case CB_FINDSTRINGEXACT
:
406 case CB_SELECTSTRING
:
410 case LB_FINDSTRINGEXACT
:
411 case LB_SELECTSTRING
:
413 push_string( data
, (LPWSTR
)lparam
);
415 case WM_GETMINMAXINFO
:
416 push_data( data
, (MINMAXINFO
*)lparam
, sizeof(MINMAXINFO
) );
417 return sizeof(MINMAXINFO
);
419 push_data( data
, (DRAWITEMSTRUCT
*)lparam
, sizeof(DRAWITEMSTRUCT
) );
422 push_data( data
, (MEASUREITEMSTRUCT
*)lparam
, sizeof(MEASUREITEMSTRUCT
) );
423 return sizeof(MEASUREITEMSTRUCT
);
425 push_data( data
, (DELETEITEMSTRUCT
*)lparam
, sizeof(DELETEITEMSTRUCT
) );
428 push_data( data
, (COMPAREITEMSTRUCT
*)lparam
, sizeof(COMPAREITEMSTRUCT
) );
430 case WM_WINDOWPOSCHANGING
:
431 case WM_WINDOWPOSCHANGED
:
432 push_data( data
, (WINDOWPOS
*)lparam
, sizeof(WINDOWPOS
) );
433 return sizeof(WINDOWPOS
);
436 COPYDATASTRUCT
*cp
= (COPYDATASTRUCT
*)lparam
;
437 push_data( data
, cp
, sizeof(*cp
) );
438 if (cp
->lpData
) push_data( data
, cp
->lpData
, cp
->cbData
);
442 /* WM_NOTIFY cannot be sent across processes (MSDN) */
446 push_data( data
, (HELPINFO
*)lparam
, sizeof(HELPINFO
) );
448 case WM_STYLECHANGING
:
449 case WM_STYLECHANGED
:
450 push_data( data
, (STYLESTRUCT
*)lparam
, sizeof(STYLESTRUCT
) );
455 push_data( data
, (RECT
*)lparam
, sizeof(RECT
) );
460 NCCALCSIZE_PARAMS
*nc
= (NCCALCSIZE_PARAMS
*)lparam
;
461 push_data( data
, nc
, sizeof(*nc
) );
462 push_data( data
, nc
->lppos
, sizeof(*nc
->lppos
) );
463 return sizeof(*nc
) + sizeof(*nc
->lppos
);
466 if (lparam
) push_data( data
, (MSG
*)lparam
, sizeof(MSG
) );
468 case SBM_SETSCROLLINFO
:
469 push_data( data
, (SCROLLINFO
*)lparam
, sizeof(SCROLLINFO
) );
471 case SBM_GETSCROLLINFO
:
472 push_data( data
, (SCROLLINFO
*)lparam
, sizeof(SCROLLINFO
) );
473 return sizeof(SCROLLINFO
);
479 if (wparam
) size
+= sizeof(DWORD
);
480 if (lparam
) size
+= sizeof(DWORD
);
485 case CB_GETDROPPEDCONTROLRECT
:
489 push_data( data
, (RECT
*)lparam
, sizeof(RECT
) );
493 WORD
*pw
= (WORD
*)lparam
;
494 push_data( data
, pw
, sizeof(*pw
) );
495 return *pw
* sizeof(WCHAR
);
499 if (wparam
) push_data( data
, (UINT
*)lparam
, sizeof(UINT
) * wparam
);
502 case CB_INSERTSTRING
:
503 if (combobox_has_strings( hwnd
)) push_string( data
, (LPWSTR
)lparam
);
506 if (!combobox_has_strings( hwnd
)) return sizeof(ULONG_PTR
);
507 return (SendMessageW( hwnd
, CB_GETLBTEXTLEN
, wparam
, 0 ) + 1) * sizeof(WCHAR
);
509 case LB_INSERTSTRING
:
510 if (listbox_has_strings( hwnd
)) push_string( data
, (LPWSTR
)lparam
);
513 if (!listbox_has_strings( hwnd
)) return sizeof(ULONG_PTR
);
514 return (SendMessageW( hwnd
, LB_GETTEXTLEN
, wparam
, 0 ) + 1) * sizeof(WCHAR
);
516 return wparam
* sizeof(UINT
);
518 push_data( data
, (MDINEXTMENU
*)lparam
, sizeof(MDINEXTMENU
) );
519 return sizeof(MDINEXTMENU
);
522 push_data( data
, (RECT
*)lparam
, sizeof(RECT
) );
526 MDICREATESTRUCTW
*cs
= (MDICREATESTRUCTW
*)lparam
;
527 push_data( data
, cs
, sizeof(*cs
) );
528 if (HIWORD(cs
->szTitle
)) push_string( data
, cs
->szTitle
);
529 if (HIWORD(cs
->szClass
)) push_string( data
, cs
->szClass
);
532 case WM_MDIGETACTIVE
:
533 if (lparam
) return sizeof(BOOL
);
536 /* these contain an HFONT */
539 /* these contain an HDC */
542 case WM_ICONERASEBKGND
:
544 case WM_CTLCOLORMSGBOX
:
545 case WM_CTLCOLOREDIT
:
546 case WM_CTLCOLORLISTBOX
:
549 case WM_CTLCOLORSCROLLBAR
:
550 case WM_CTLCOLORSTATIC
:
553 /* these contain an HGLOBAL */
554 case WM_PAINTCLIPBOARD
:
555 case WM_SIZECLIPBOARD
:
556 case WM_DDE_INITIATE
:
558 case WM_DDE_UNADVISE
:
563 /* these contain pointers */
565 case WM_QUERYDROPOBJECT
:
569 case WM_DEVICECHANGE
:
570 FIXME( "msg %x (%s) not supported yet\n", message
, SPY_GetMsgName(message
, hwnd
) );
578 /***********************************************************************
581 * Unpack a message received from another process.
583 static BOOL
unpack_message( HWND hwnd
, UINT message
, WPARAM
*wparam
, LPARAM
*lparam
,
584 void **buffer
, size_t size
)
593 CREATESTRUCTW
*cs
= *buffer
;
594 WCHAR
*str
= (WCHAR
*)(cs
+ 1);
595 if (size
< sizeof(*cs
)) return FALSE
;
597 if (HIWORD(cs
->lpszName
))
599 if (!check_string( str
, size
)) return FALSE
;
601 size
-= (strlenW(str
) + 1) * sizeof(WCHAR
);
602 str
+= strlenW(str
) + 1;
604 if (HIWORD(cs
->lpszClass
))
606 if (!check_string( str
, size
)) return FALSE
;
612 case WM_ASKCBFORMATNAME
:
613 if (!get_buffer_space( buffer
, (*wparam
* sizeof(WCHAR
)) )) return FALSE
;
616 case WM_WININICHANGE
:
617 case WM_DEVMODECHANGE
:
620 case CB_FINDSTRINGEXACT
:
621 case CB_SELECTSTRING
:
625 case LB_FINDSTRINGEXACT
:
626 case LB_SELECTSTRING
:
628 if (!check_string( *buffer
, size
)) return FALSE
;
630 case WM_GETMINMAXINFO
:
631 minsize
= sizeof(MINMAXINFO
);
634 minsize
= sizeof(DRAWITEMSTRUCT
);
637 minsize
= sizeof(MEASUREITEMSTRUCT
);
640 minsize
= sizeof(DELETEITEMSTRUCT
);
643 minsize
= sizeof(COMPAREITEMSTRUCT
);
645 case WM_WINDOWPOSCHANGING
:
646 case WM_WINDOWPOSCHANGED
:
647 minsize
= sizeof(WINDOWPOS
);
651 COPYDATASTRUCT
*cp
= *buffer
;
652 if (size
< sizeof(*cp
)) return FALSE
;
655 minsize
= sizeof(*cp
) + cp
->cbData
;
661 /* WM_NOTIFY cannot be sent across processes (MSDN) */
664 minsize
= sizeof(HELPINFO
);
666 case WM_STYLECHANGING
:
667 case WM_STYLECHANGED
:
668 minsize
= sizeof(STYLESTRUCT
);
671 if (!*wparam
) minsize
= sizeof(RECT
);
674 NCCALCSIZE_PARAMS
*nc
= *buffer
;
675 if (size
< sizeof(*nc
) + sizeof(*nc
->lppos
)) return FALSE
;
676 nc
->lppos
= (WINDOWPOS
*)(nc
+ 1);
680 if (!*lparam
) return TRUE
;
681 minsize
= sizeof(MSG
);
683 case SBM_SETSCROLLINFO
:
684 minsize
= sizeof(SCROLLINFO
);
686 case SBM_GETSCROLLINFO
:
687 if (!get_buffer_space( buffer
, sizeof(SCROLLINFO
))) return FALSE
;
692 if (*wparam
|| *lparam
)
694 if (!get_buffer_space( buffer
, 2*sizeof(DWORD
) )) return FALSE
;
695 if (*wparam
) *wparam
= (WPARAM
)*buffer
;
696 if (*lparam
) *lparam
= (LPARAM
)((DWORD
*)*buffer
+ 1);
701 case CB_GETDROPPEDCONTROLRECT
:
702 if (!get_buffer_space( buffer
, sizeof(RECT
) )) return FALSE
;
706 minsize
= sizeof(RECT
);
711 if (size
< sizeof(WORD
)) return FALSE
;
712 len
= *(WORD
*)*buffer
;
713 if (!get_buffer_space( buffer
, (len
+ 1) * sizeof(WCHAR
) )) return FALSE
;
714 *lparam
= (LPARAM
)*buffer
+ sizeof(WORD
); /* don't erase WORD at start of buffer */
719 if (!*wparam
) return TRUE
;
720 minsize
= *wparam
* sizeof(UINT
);
723 case CB_INSERTSTRING
:
725 case LB_INSERTSTRING
:
726 if (!*buffer
) return TRUE
;
727 if (!check_string( *buffer
, size
)) return FALSE
;
731 size
= sizeof(ULONG_PTR
);
732 if (combobox_has_strings( hwnd
))
733 size
= (SendMessageW( hwnd
, CB_GETLBTEXTLEN
, *wparam
, 0 ) + 1) * sizeof(WCHAR
);
734 if (!get_buffer_space( buffer
, size
)) return FALSE
;
739 size
= sizeof(ULONG_PTR
);
740 if (listbox_has_strings( hwnd
))
741 size
= (SendMessageW( hwnd
, LB_GETTEXTLEN
, *wparam
, 0 ) + 1) * sizeof(WCHAR
);
742 if (!get_buffer_space( buffer
, size
)) return FALSE
;
746 if (!get_buffer_space( buffer
, *wparam
* sizeof(UINT
) )) return FALSE
;
749 minsize
= sizeof(MDINEXTMENU
);
750 if (!get_buffer_space( buffer
, sizeof(MDINEXTMENU
) )) return FALSE
;
754 minsize
= sizeof(RECT
);
755 if (!get_buffer_space( buffer
, sizeof(RECT
) )) return FALSE
;
759 MDICREATESTRUCTW
*cs
= *buffer
;
760 WCHAR
*str
= (WCHAR
*)(cs
+ 1);
761 if (size
< sizeof(*cs
)) return FALSE
;
763 if (HIWORD(cs
->szTitle
))
765 if (!check_string( str
, size
)) return FALSE
;
767 size
-= (strlenW(str
) + 1) * sizeof(WCHAR
);
768 str
+= strlenW(str
) + 1;
770 if (HIWORD(cs
->szClass
))
772 if (!check_string( str
, size
)) return FALSE
;
777 case WM_MDIGETACTIVE
:
778 if (!*lparam
) return TRUE
;
779 if (!get_buffer_space( buffer
, sizeof(BOOL
) )) return FALSE
;
782 /* these contain an HFONT */
785 /* these contain an HDC */
788 case WM_ICONERASEBKGND
:
790 case WM_CTLCOLORMSGBOX
:
791 case WM_CTLCOLOREDIT
:
792 case WM_CTLCOLORLISTBOX
:
795 case WM_CTLCOLORSCROLLBAR
:
796 case WM_CTLCOLORSTATIC
:
799 /* these contain an HGLOBAL */
800 case WM_PAINTCLIPBOARD
:
801 case WM_SIZECLIPBOARD
:
802 case WM_DDE_INITIATE
:
804 case WM_DDE_UNADVISE
:
809 /* these contain pointers */
811 case WM_QUERYDROPOBJECT
:
815 case WM_DEVICECHANGE
:
816 FIXME( "msg %x (%s) not supported yet\n", message
, SPY_GetMsgName(message
, hwnd
) );
820 return TRUE
; /* message doesn't need any unpacking */
823 /* default exit for most messages: check minsize and store buffer in lparam */
824 if (size
< minsize
) return FALSE
;
825 *lparam
= (LPARAM
)*buffer
;
830 /***********************************************************************
833 * Pack a reply to a message for sending to another process.
835 static void pack_reply( HWND hwnd
, UINT message
, WPARAM wparam
, LPARAM lparam
,
836 LRESULT res
, struct packed_message
*data
)
843 push_data( data
, (CREATESTRUCTW
*)lparam
, sizeof(CREATESTRUCTW
) );
848 push_data( data
, (WCHAR
*)lparam
, (res
+ 1) * sizeof(WCHAR
) );
850 case WM_GETMINMAXINFO
:
851 push_data( data
, (MINMAXINFO
*)lparam
, sizeof(MINMAXINFO
) );
854 push_data( data
, (MEASUREITEMSTRUCT
*)lparam
, sizeof(MEASUREITEMSTRUCT
) );
856 case WM_WINDOWPOSCHANGING
:
857 case WM_WINDOWPOSCHANGED
:
858 push_data( data
, (WINDOWPOS
*)lparam
, sizeof(WINDOWPOS
) );
861 if (lparam
) push_data( data
, (MSG
*)lparam
, sizeof(MSG
) );
863 case SBM_GETSCROLLINFO
:
864 push_data( data
, (SCROLLINFO
*)lparam
, sizeof(SCROLLINFO
) );
868 case CB_GETDROPPEDCONTROLRECT
:
871 push_data( data
, (RECT
*)lparam
, sizeof(RECT
) );
875 WORD
*ptr
= (WORD
*)lparam
;
876 push_data( data
, ptr
, ptr
[-1] * sizeof(WCHAR
) );
880 push_data( data
, (UINT
*)lparam
, wparam
* sizeof(UINT
) );
882 case WM_MDIGETACTIVE
:
883 if (lparam
) push_data( data
, (BOOL
*)lparam
, sizeof(BOOL
) );
887 push_data( data
, (RECT
*)lparam
, sizeof(RECT
) );
890 NCCALCSIZE_PARAMS
*nc
= (NCCALCSIZE_PARAMS
*)lparam
;
891 push_data( data
, nc
, sizeof(*nc
) );
892 push_data( data
, nc
->lppos
, sizeof(*nc
->lppos
) );
898 if (wparam
) push_data( data
, (DWORD
*)wparam
, sizeof(DWORD
) );
899 if (lparam
) push_data( data
, (DWORD
*)lparam
, sizeof(DWORD
) );
902 push_data( data
, (MDINEXTMENU
*)lparam
, sizeof(MDINEXTMENU
) );
905 push_data( data
, (MDICREATESTRUCTW
*)lparam
, sizeof(MDICREATESTRUCTW
) );
907 case WM_ASKCBFORMATNAME
:
908 push_data( data
, (WCHAR
*)lparam
, (strlenW((WCHAR
*)lparam
) + 1) * sizeof(WCHAR
) );
914 /***********************************************************************
917 * Unpack a message reply received from another process.
919 static void unpack_reply( HWND hwnd
, UINT message
, WPARAM wparam
, LPARAM lparam
,
920 void *buffer
, size_t size
)
927 CREATESTRUCTW
*cs
= (CREATESTRUCTW
*)lparam
;
928 LPCWSTR name
= cs
->lpszName
, class = cs
->lpszClass
;
929 memcpy( cs
, buffer
, min( sizeof(*cs
), size
));
930 cs
->lpszName
= name
; /* restore the original pointers */
931 cs
->lpszClass
= class;
935 case WM_ASKCBFORMATNAME
:
936 memcpy( (WCHAR
*)lparam
, buffer
, min( wparam
*sizeof(WCHAR
), size
));
938 case WM_GETMINMAXINFO
:
939 memcpy( (MINMAXINFO
*)lparam
, buffer
, min( sizeof(MINMAXINFO
), size
));
942 memcpy( (MEASUREITEMSTRUCT
*)lparam
, buffer
, min( sizeof(MEASUREITEMSTRUCT
), size
));
944 case WM_WINDOWPOSCHANGING
:
945 case WM_WINDOWPOSCHANGED
:
946 memcpy( (WINDOWPOS
*)lparam
, buffer
, min( sizeof(WINDOWPOS
), size
));
949 if (lparam
) memcpy( (MSG
*)lparam
, buffer
, min( sizeof(MSG
), size
));
951 case SBM_GETSCROLLINFO
:
952 memcpy( (SCROLLINFO
*)lparam
, buffer
, min( sizeof(SCROLLINFO
), size
));
955 case CB_GETDROPPEDCONTROLRECT
:
959 memcpy( (RECT
*)lparam
, buffer
, min( sizeof(RECT
), size
));
962 size
= min( size
, *(WORD
*)lparam
);
963 memcpy( (WCHAR
*)lparam
, buffer
, size
);
966 memcpy( (UINT
*)lparam
, buffer
, min( wparam
*sizeof(UINT
), size
));
970 memcpy( (WCHAR
*)lparam
, buffer
, size
);
973 memcpy( (MDINEXTMENU
*)lparam
, buffer
, min( sizeof(MDINEXTMENU
), size
));
975 case WM_MDIGETACTIVE
:
976 if (lparam
) memcpy( (BOOL
*)lparam
, buffer
, min( sizeof(BOOL
), size
));
980 memcpy( (RECT
*)lparam
, buffer
, min( sizeof(RECT
), size
));
983 NCCALCSIZE_PARAMS
*nc
= (NCCALCSIZE_PARAMS
*)lparam
;
984 WINDOWPOS
*wp
= nc
->lppos
;
985 memcpy( nc
, buffer
, min( sizeof(*nc
), size
));
986 if (size
> sizeof(*nc
))
989 memcpy( wp
, (NCCALCSIZE_PARAMS
*)buffer
+ 1, min( sizeof(*wp
), size
));
991 nc
->lppos
= wp
; /* restore the original pointer */
999 memcpy( (DWORD
*)wparam
, buffer
, min( sizeof(DWORD
), size
));
1000 if (size
<= sizeof(DWORD
)) break;
1001 size
-= sizeof(DWORD
);
1002 buffer
= (DWORD
*)buffer
+ 1;
1004 if (lparam
) memcpy( (DWORD
*)lparam
, buffer
, min( sizeof(DWORD
), size
));
1008 MDICREATESTRUCTW
*cs
= (MDICREATESTRUCTW
*)lparam
;
1009 LPCWSTR title
= cs
->szTitle
, class = cs
->szClass
;
1010 memcpy( cs
, buffer
, min( sizeof(*cs
), size
));
1011 cs
->szTitle
= title
; /* restore the original pointers */
1012 cs
->szClass
= class;
1016 ERR( "should not happen: unexpected message %x\n", message
);
1022 /***********************************************************************
1025 * Send a reply to a sent message.
1027 static void reply_message( struct received_message_info
*info
, LRESULT result
, BOOL remove
)
1029 struct packed_message data
;
1030 int replied
= info
->flags
& ISMEX_REPLIED
;
1032 if (info
->flags
& ISMEX_NOTIFY
) return; /* notify messages don't get replies */
1033 if (!remove
&& replied
) return; /* replied already */
1036 info
->flags
|= ISMEX_REPLIED
;
1038 if (info
->type
== MSG_OTHER_PROCESS
&& !replied
)
1040 pack_reply( info
->msg
.hwnd
, info
->msg
.message
, info
->msg
.wParam
,
1041 info
->msg
.lParam
, result
, &data
);
1044 size_t total
= get_data_total_size( &data
);
1046 if (total
> REQUEST_MAX_VAR_SIZE
)
1048 FIXME( "inter-process msg data size %d not supported yet, expect trouble\n",
1050 total
= REQUEST_MAX_VAR_SIZE
;
1053 SERVER_START_VAR_REQ( reply_message
, total
)
1055 req
->result
= result
;
1056 req
->remove
= remove
;
1057 copy_all_data( server_data_ptr(req
), &data
);
1065 SERVER_START_REQ( reply_message
)
1067 req
->result
= result
;
1068 req
->remove
= remove
;
1075 /***********************************************************************
1078 * Call a window procedure and the corresponding hooks.
1080 static LRESULT
call_window_proc( HWND hwnd
, UINT msg
, WPARAM wparam
, LPARAM lparam
, BOOL unicode
)
1085 /* FIXME: should check for exiting queue */
1087 /* first the WH_CALLWNDPROC hook */
1088 if (HOOK_IsHooked( WH_CALLWNDPROC
))
1091 cwp
.lParam
= lparam
;
1092 cwp
.wParam
= wparam
;
1094 cwp
.hwnd
= WIN_GetFullHandle( hwnd
);
1095 if (unicode
) HOOK_CallHooksW( WH_CALLWNDPROC
, HC_ACTION
, 1, (LPARAM
)&cwp
);
1096 else HOOK_CallHooksA( WH_CALLWNDPROC
, HC_ACTION
, 1, (LPARAM
)&cwp
);
1097 lparam
= cwp
.lParam
;
1098 wparam
= cwp
.wParam
;
1103 /* now call the window procedure */
1106 if (!(winproc
= (WNDPROC
)GetWindowLongW( hwnd
, GWL_WNDPROC
))) return 0;
1107 result
= CallWindowProcW( winproc
, hwnd
, msg
, wparam
, lparam
);
1111 if (!(winproc
= (WNDPROC
)GetWindowLongA( hwnd
, GWL_WNDPROC
))) return 0;
1112 result
= CallWindowProcA( winproc
, hwnd
, msg
, wparam
, lparam
);
1115 /* and finally the WH_CALLWNDPROCRET hook */
1116 if (HOOK_IsHooked( WH_CALLWNDPROCRET
))
1119 cwp
.lResult
= result
;
1120 cwp
.lParam
= lparam
;
1121 cwp
.wParam
= wparam
;
1123 cwp
.hwnd
= WIN_GetFullHandle( hwnd
);
1124 if (unicode
) HOOK_CallHooksW( WH_CALLWNDPROCRET
, HC_ACTION
, 1, (LPARAM
)&cwp
);
1125 else HOOK_CallHooksA( WH_CALLWNDPROCRET
, HC_ACTION
, 1, (LPARAM
)&cwp
);
1131 /***********************************************************************
1134 * Peek for a message matching the given parameters. Return FALSE if none available.
1135 * All pending sent messages are processed before returning.
1137 BOOL
MSG_peek_message( MSG
*msg
, HWND hwnd
, UINT first
, UINT last
, int flags
)
1141 ULONG_PTR extra_info
= 0;
1142 MESSAGEQUEUE
*queue
= QUEUE_Current();
1143 struct received_message_info info
, *old_info
;
1145 if (!first
&& !last
) last
= ~0;
1149 void *buffer
= NULL
;
1152 SERVER_START_VAR_REQ( get_message
, REQUEST_MAX_VAR_SIZE
)
1155 req
->get_win
= hwnd
;
1156 req
->get_first
= first
;
1157 req
->get_last
= last
;
1158 if ((ret
= !SERVER_CALL()))
1160 info
.type
= req
->type
;
1161 info
.msg
.hwnd
= req
->win
;
1162 info
.msg
.message
= req
->msg
;
1163 info
.msg
.wParam
= req
->wparam
;
1164 info
.msg
.lParam
= req
->lparam
;
1165 info
.msg
.time
= req
->time
;
1166 info
.msg
.pt
.x
= req
->x
;
1167 info
.msg
.pt
.y
= req
->y
;
1168 extra_info
= req
->info
;
1170 if ((size
= server_data_size(req
)))
1172 if (!(buffer
= HeapAlloc( GetProcessHeap(), 0, size
)))
1174 ERR("out of memory for message data\n");
1177 else memcpy( buffer
, server_data_ptr(req
), size
);
1183 if (!ret
) return FALSE
; /* no message available */
1185 TRACE( "got type %d msg %x hwnd %x wp %x lp %lx\n",
1186 info
.type
, info
.msg
.message
, info
.msg
.hwnd
, info
.msg
.wParam
, info
.msg
.lParam
);
1192 info
.flags
= ISMEX_SEND
;
1195 info
.flags
= ISMEX_NOTIFY
;
1198 info
.flags
= ISMEX_CALLBACK
;
1200 case MSG_OTHER_PROCESS
:
1201 info
.flags
= ISMEX_SEND
;
1202 if (!unpack_message( info
.msg
.hwnd
, info
.msg
.message
, &info
.msg
.wParam
,
1203 &info
.msg
.lParam
, &buffer
, size
))
1205 ERR( "invalid packed message %x (%s) hwnd %x wp %x lp %lx size %d\n",
1206 info
.msg
.message
, SPY_GetMsgName(info
.msg
.message
, info
.msg
.hwnd
), info
.msg
.hwnd
,
1207 info
.msg
.wParam
, info
.msg
.lParam
, size
);
1209 reply_message( &info
, 0, TRUE
);
1215 case MSG_HARDWARE_RAW
:
1216 if (!MSG_process_raw_hardware_message( &info
.msg
, extra_info
,
1217 hwnd
, first
, last
, flags
& GET_MSG_REMOVE
))
1220 case MSG_HARDWARE_COOKED
:
1221 if (!MSG_process_cooked_hardware_message( &info
.msg
, flags
& GET_MSG_REMOVE
))
1223 flags
|= GET_MSG_REMOVE_LAST
;
1226 queue
->GetMessageExtraInfoVal
= extra_info
;
1230 /* if we get here, we have a sent message; call the window procedure */
1231 old_info
= queue
->receive_info
;
1232 queue
->receive_info
= &info
;
1233 result
= call_window_proc( info
.msg
.hwnd
, info
.msg
.message
, info
.msg
.wParam
,
1234 info
.msg
.lParam
, (info
.type
!= MSG_ASCII
) );
1235 reply_message( &info
, result
, TRUE
);
1236 queue
->receive_info
= old_info
;
1238 if (buffer
) HeapFree( GetProcessHeap(), 0, buffer
);
1247 /***********************************************************************
1248 * wait_message_reply
1250 * Wait until a sent message gets replied to.
1252 static void wait_message_reply( UINT flags
)
1254 MESSAGEQUEUE
*queue
;
1256 if (!(queue
= QUEUE_Current())) return;
1260 unsigned int wake_bits
= 0, changed_bits
= 0;
1263 SERVER_START_REQ( set_queue_mask
)
1265 req
->wake_mask
= (flags
& SMTO_BLOCK
) ? 0 : QS_SENDMESSAGE
;
1266 req
->changed_mask
= QS_SMRESULT
| req
->wake_mask
;
1270 wake_bits
= req
->wake_bits
;
1271 changed_bits
= req
->changed_bits
;
1276 if (changed_bits
& QS_SMRESULT
) return; /* got a result */
1277 if (wake_bits
& QS_SENDMESSAGE
)
1279 /* Process the sent message immediately */
1281 MSG_peek_message( &msg
, 0, 0, 0, GET_MSG_REMOVE
| GET_MSG_SENT_ONLY
);
1285 /* now wait for it */
1287 ReleaseThunkLock( &dwlc
);
1289 if (USER_Driver
.pMsgWaitForMultipleObjectsEx
)
1290 res
= USER_Driver
.pMsgWaitForMultipleObjectsEx( 1, &queue
->server_queue
,
1293 res
= WaitForSingleObject( queue
->server_queue
, INFINITE
);
1295 if (dwlc
) RestoreThunkLock( dwlc
);
1299 /***********************************************************************
1300 * put_message_in_queue
1302 * Put a sent message into the destination queue.
1303 * For inter-process message, reply_size is set to expected size of reply data.
1305 static BOOL
put_message_in_queue( DWORD dest_tid
, const struct send_message_info
*info
,
1306 size_t *reply_size
)
1311 /* FIXME: should check for exiting queue */
1313 if (info
->type
!= MSG_NOTIFY
&&
1314 info
->type
!= MSG_CALLBACK
&&
1315 info
->type
!= MSG_POSTED
&&
1316 info
->timeout
!= INFINITE
)
1317 timeout
= info
->timeout
;
1319 if (info
->type
== MSG_OTHER_PROCESS
)
1321 struct packed_message data
;
1322 *reply_size
= pack_message( info
->hwnd
, info
->msg
, info
->wparam
, info
->lparam
, &data
);
1324 if (data
.count
== -1)
1326 WARN( "cannot pack message %x\n", info
->msg
);
1330 if (data
.size
[0]) /* need to send extra data along with the message */
1332 size_t total
= get_data_total_size( &data
);
1334 if (total
> REQUEST_MAX_VAR_SIZE
)
1336 FIXME( "inter-process msg data size %d not supported yet, expect trouble\n",
1338 total
= REQUEST_MAX_VAR_SIZE
;
1341 SERVER_START_VAR_REQ( send_message
, total
)
1343 req
->id
= (void *)dest_tid
;
1344 req
->type
= MSG_OTHER_PROCESS
;
1345 req
->win
= info
->hwnd
;
1346 req
->msg
= info
->msg
;
1347 req
->wparam
= info
->wparam
;
1348 req
->lparam
= info
->lparam
;
1349 req
->time
= GetCurrentTime();
1350 req
->timeout
= timeout
;
1351 copy_all_data( server_data_ptr(req
), &data
);
1352 res
= SERVER_CALL();
1359 /* no extra data, or not inter-process message */
1360 SERVER_START_REQ( send_message
)
1362 req
->id
= (void *)dest_tid
;
1363 req
->type
= info
->type
;
1364 req
->win
= info
->hwnd
;
1365 req
->msg
= info
->msg
;
1366 req
->wparam
= info
->wparam
;
1367 req
->lparam
= info
->lparam
;
1368 req
->time
= GetCurrentTime();
1369 req
->timeout
= timeout
;
1370 res
= SERVER_CALL();
1377 if (res
== STATUS_INVALID_PARAMETER
)
1378 /* FIXME: find a STATUS_ value for this one */
1379 SetLastError( ERROR_INVALID_THREAD_ID
);
1381 SetLastError( RtlNtStatusToDosError(res
) );
1387 /***********************************************************************
1390 * Retrieve a message reply from the server.
1392 static LRESULT
retrieve_reply( const struct send_message_info
*info
,
1393 size_t reply_size
, LRESULT
*result
)
1399 if (reply_size
> REQUEST_MAX_VAR_SIZE
)
1401 WARN( "reply_size %d too large, reply may be truncated\n", reply_size
);
1402 reply_size
= REQUEST_MAX_VAR_SIZE
;
1404 SERVER_START_VAR_REQ( get_message_reply
, reply_size
)
1407 if (!(status
= SERVER_CALL()))
1409 *result
= req
->result
;
1410 unpack_reply( info
->hwnd
, info
->msg
, info
->wparam
, info
->lparam
,
1411 server_data_ptr(req
), server_data_size(req
) );
1418 SERVER_START_REQ( get_message_reply
)
1421 if (!(status
= SERVER_CALL())) *result
= req
->result
;
1426 TRACE( "hwnd %x msg %x (%s) wp %x lp %lx got reply %lx (err=%ld)\n",
1427 info
->hwnd
, info
->msg
, SPY_GetMsgName(info
->msg
, info
->hwnd
), info
->wparam
,
1428 info
->lparam
, *result
, status
);
1430 if (!status
) return 1;
1431 if (status
== STATUS_TIMEOUT
) SetLastError(0); /* timeout */
1432 else SetLastError( RtlNtStatusToDosError(status
) );
1437 /***********************************************************************
1438 * send_inter_thread_message
1440 static LRESULT
send_inter_thread_message( DWORD dest_tid
, const struct send_message_info
*info
,
1445 size_t reply_size
= 0;
1447 TRACE( "hwnd %x msg %x (%s) wp %x lp %lx\n",
1448 info
->hwnd
, info
->msg
, SPY_GetMsgName(info
->msg
, info
->hwnd
), info
->wparam
, info
->lparam
);
1450 if (!put_message_in_queue( dest_tid
, info
, &reply_size
)) return 0;
1452 /* there's no reply to wait for on notify/callback messages */
1453 if (info
->type
== MSG_NOTIFY
|| info
->type
== MSG_CALLBACK
) return 1;
1455 locks
= WIN_SuspendWndsLock();
1457 wait_message_reply( info
->flags
);
1458 ret
= retrieve_reply( info
, reply_size
, res_ptr
);
1460 WIN_RestoreWndsLock( locks
);
1465 /***********************************************************************
1466 * SendMessageTimeoutW (USER32.@)
1468 LRESULT WINAPI
SendMessageTimeoutW( HWND hwnd
, UINT msg
, WPARAM wparam
, LPARAM lparam
,
1469 UINT flags
, UINT timeout
, LPDWORD res_ptr
)
1471 struct send_message_info info
;
1472 DWORD dest_tid
, dest_pid
;
1473 LRESULT ret
, result
;
1475 info
.type
= MSG_UNICODE
;
1478 info
.wparam
= wparam
;
1479 info
.lparam
= lparam
;
1481 info
.timeout
= timeout
;
1483 if (is_broadcast(hwnd
))
1485 EnumWindows( broadcast_message_callback
, (LPARAM
)&info
);
1486 if (res_ptr
) *res_ptr
= 1;
1490 SPY_EnterMessage( SPY_SENDMESSAGE
, hwnd
, msg
, wparam
, lparam
);
1492 dest_tid
= GetWindowThreadProcessId( hwnd
, &dest_pid
);
1494 if (dest_tid
== GetCurrentThreadId())
1496 result
= call_window_proc( hwnd
, msg
, wparam
, lparam
, TRUE
);
1501 if (dest_pid
!= GetCurrentProcessId()) info
.type
= MSG_OTHER_PROCESS
;
1502 ret
= send_inter_thread_message( dest_tid
, &info
, &result
);
1505 SPY_ExitMessage( SPY_RESULT_OK
, hwnd
, msg
, result
, wparam
, lparam
);
1506 if (ret
&& res_ptr
) *res_ptr
= result
;
1511 /***********************************************************************
1512 * SendMessageTimeoutA (USER32.@)
1514 LRESULT WINAPI
SendMessageTimeoutA( HWND hwnd
, UINT msg
, WPARAM wparam
, LPARAM lparam
,
1515 UINT flags
, UINT timeout
, LPDWORD res_ptr
)
1517 struct send_message_info info
;
1518 DWORD dest_tid
, dest_pid
;
1519 LRESULT ret
, result
;
1521 info
.type
= MSG_ASCII
;
1524 info
.wparam
= wparam
;
1525 info
.lparam
= lparam
;
1527 info
.timeout
= timeout
;
1529 if (is_broadcast(hwnd
))
1531 EnumWindows( broadcast_message_callback
, (LPARAM
)&info
);
1532 if (res_ptr
) *res_ptr
= 1;
1536 SPY_EnterMessage( SPY_SENDMESSAGE
, hwnd
, msg
, wparam
, lparam
);
1538 dest_tid
= GetWindowThreadProcessId( hwnd
, &dest_pid
);
1540 if (dest_tid
== GetCurrentThreadId())
1542 result
= call_window_proc( hwnd
, msg
, wparam
, lparam
, FALSE
);
1545 else if (dest_pid
== GetCurrentProcessId())
1547 ret
= send_inter_thread_message( dest_tid
, &info
, &result
);
1551 /* inter-process message: need to map to Unicode */
1552 info
.type
= MSG_OTHER_PROCESS
;
1553 if (is_unicode_message( info
.msg
))
1555 if (WINPROC_MapMsg32ATo32W( info
.hwnd
, info
.msg
, &info
.wparam
, &info
.lparam
) == -1)
1557 ret
= send_inter_thread_message( dest_tid
, &info
, &result
);
1558 result
= WINPROC_UnmapMsg32ATo32W( info
.hwnd
, info
.msg
, info
.wparam
,
1559 info
.lparam
, result
);
1561 else ret
= send_inter_thread_message( dest_tid
, &info
, &result
);
1563 SPY_ExitMessage( SPY_RESULT_OK
, hwnd
, msg
, result
, wparam
, lparam
);
1564 if (ret
&& res_ptr
) *res_ptr
= result
;
1569 /***********************************************************************
1570 * SendMessageW (USER32.@)
1572 LRESULT WINAPI
SendMessageW( HWND hwnd
, UINT msg
, WPARAM wparam
, LPARAM lparam
)
1575 SendMessageTimeoutW( hwnd
, msg
, wparam
, lparam
, SMTO_NORMAL
, INFINITE
, &res
);
1580 /***********************************************************************
1581 * SendMessageA (USER32.@)
1583 LRESULT WINAPI
SendMessageA( HWND hwnd
, UINT msg
, WPARAM wparam
, LPARAM lparam
)
1586 SendMessageTimeoutA( hwnd
, msg
, wparam
, lparam
, SMTO_NORMAL
, INFINITE
, &res
);
1591 /***********************************************************************
1592 * SendNotifyMessageA (USER32.@)
1594 BOOL WINAPI
SendNotifyMessageA( HWND hwnd
, UINT msg
, WPARAM wparam
, LPARAM lparam
)
1596 return SendNotifyMessageW( hwnd
, msg
, map_wparam_AtoW( msg
, wparam
), lparam
);
1600 /***********************************************************************
1601 * SendNotifyMessageW (USER32.@)
1603 BOOL WINAPI
SendNotifyMessageW( HWND hwnd
, UINT msg
, WPARAM wparam
, LPARAM lparam
)
1605 struct send_message_info info
;
1609 if (is_pointer_message(msg
))
1611 SetLastError(ERROR_INVALID_PARAMETER
);
1615 info
.type
= MSG_NOTIFY
;
1618 info
.wparam
= wparam
;
1619 info
.lparam
= lparam
;
1621 if (is_broadcast(hwnd
))
1623 EnumWindows( broadcast_message_callback
, (LPARAM
)&info
);
1627 dest_tid
= GetWindowThreadProcessId( hwnd
, NULL
);
1629 if (dest_tid
== GetCurrentThreadId())
1631 call_window_proc( hwnd
, msg
, wparam
, lparam
, TRUE
);
1634 return send_inter_thread_message( dest_tid
, &info
, &result
);
1638 /***********************************************************************
1639 * SendMessageCallbackA (USER32.@)
1641 BOOL WINAPI
SendMessageCallbackA( HWND hwnd
, UINT msg
, WPARAM wparam
, LPARAM lparam
,
1642 SENDASYNCPROC callback
, ULONG_PTR data
)
1644 return SendMessageCallbackW( hwnd
, msg
, map_wparam_AtoW( msg
, wparam
),
1645 lparam
, callback
, data
);
1649 /***********************************************************************
1650 * SendMessageCallbackW (USER32.@)
1652 BOOL WINAPI
SendMessageCallbackW( HWND hwnd
, UINT msg
, WPARAM wparam
, LPARAM lparam
,
1653 SENDASYNCPROC callback
, ULONG_PTR data
)
1655 struct send_message_info info
;
1659 if (is_pointer_message(msg
))
1661 SetLastError(ERROR_INVALID_PARAMETER
);
1665 info
.type
= MSG_CALLBACK
;
1668 info
.wparam
= wparam
;
1669 info
.lparam
= lparam
;
1670 info
.callback
= callback
;
1673 if (is_broadcast(hwnd
))
1675 EnumWindows( broadcast_message_callback
, (LPARAM
)&info
);
1679 dest_tid
= GetWindowThreadProcessId( hwnd
, NULL
);
1681 if (dest_tid
== GetCurrentThreadId())
1683 result
= call_window_proc( hwnd
, msg
, wparam
, lparam
, TRUE
);
1684 callback( hwnd
, msg
, data
, result
);
1687 FIXME( "callback will not be called\n" );
1688 return send_inter_thread_message( dest_tid
, &info
, &result
);
1692 /***********************************************************************
1693 * ReplyMessage (USER32.@)
1695 BOOL WINAPI
ReplyMessage( LRESULT result
)
1697 MESSAGEQUEUE
*queue
= QUEUE_Current();
1698 struct received_message_info
*info
= queue
->receive_info
;
1700 if (!info
) return FALSE
;
1701 reply_message( info
, result
, FALSE
);
1706 /***********************************************************************
1707 * InSendMessage (USER32.@)
1709 BOOL WINAPI
InSendMessage(void)
1711 return (InSendMessageEx(NULL
) & (ISMEX_SEND
|ISMEX_REPLIED
)) == ISMEX_SEND
;
1715 /***********************************************************************
1716 * InSendMessageEx (USER32.@)
1718 DWORD WINAPI
InSendMessageEx( LPVOID reserved
)
1720 MESSAGEQUEUE
*queue
= QUEUE_Current();
1721 struct received_message_info
*info
= queue
->receive_info
;
1723 if (info
) return info
->flags
;
1724 return ISMEX_NOSEND
;
1728 /***********************************************************************
1729 * PostMessageA (USER32.@)
1731 BOOL WINAPI
PostMessageA( HWND hwnd
, UINT msg
, WPARAM wparam
, LPARAM lparam
)
1733 return PostMessageW( hwnd
, msg
, map_wparam_AtoW( msg
, wparam
), lparam
);
1737 /***********************************************************************
1738 * PostMessageW (USER32.@)
1740 BOOL WINAPI
PostMessageW( HWND hwnd
, UINT msg
, WPARAM wparam
, LPARAM lparam
)
1742 struct send_message_info info
;
1744 if (is_pointer_message( msg
))
1746 SetLastError( ERROR_INVALID_PARAMETER
);
1750 info
.type
= MSG_POSTED
;
1753 info
.wparam
= wparam
;
1754 info
.lparam
= lparam
;
1756 if (is_broadcast(hwnd
))
1758 EnumWindows( broadcast_message_callback
, (LPARAM
)&info
);
1761 return put_message_in_queue( GetWindowThreadProcessId( hwnd
, NULL
), &info
, NULL
);
1765 /**********************************************************************
1766 * PostThreadMessageA (USER32.@)
1768 BOOL WINAPI
PostThreadMessageA( DWORD thread
, UINT msg
, WPARAM wparam
, LPARAM lparam
)
1770 return PostThreadMessageW( thread
, msg
, map_wparam_AtoW( msg
, wparam
), lparam
);
1774 /**********************************************************************
1775 * PostThreadMessageW (USER32.@)
1777 BOOL WINAPI
PostThreadMessageW( DWORD thread
, UINT msg
, WPARAM wparam
, LPARAM lparam
)
1779 struct send_message_info info
;
1781 if (is_pointer_message( msg
))
1783 SetLastError( ERROR_INVALID_PARAMETER
);
1787 info
.type
= MSG_POSTED
;
1790 info
.wparam
= wparam
;
1791 info
.lparam
= lparam
;
1792 return put_message_in_queue( thread
, &info
, NULL
);
1796 /***********************************************************************
1797 * PostQuitMessage (USER32.@)
1799 void WINAPI
PostQuitMessage( INT exitCode
)
1801 PostThreadMessageW( GetCurrentThreadId(), WM_QUIT
, exitCode
, 0 );
1805 /***********************************************************************
1806 * PeekMessageW (USER32.@)
1808 BOOL WINAPI
PeekMessageW( MSG
*msg_out
, HWND hwnd
, UINT first
, UINT last
, UINT flags
)
1810 MESSAGEQUEUE
*queue
;
1814 /* check for graphics events */
1815 if (USER_Driver
.pMsgWaitForMultipleObjectsEx
)
1816 USER_Driver
.pMsgWaitForMultipleObjectsEx( 0, NULL
, 0, 0, 0 );
1818 hwnd
= WIN_GetFullHandle( hwnd
);
1819 locks
= WIN_SuspendWndsLock();
1821 if (!MSG_peek_message( &msg
, hwnd
, first
, last
,
1822 (flags
& PM_REMOVE
) ? GET_MSG_REMOVE
: 0 ))
1824 /* FIXME: should be done before checking for hw events */
1825 MSG_JournalPlayBackMsg();
1827 if (!(flags
& PM_NOYIELD
))
1830 ReleaseThunkLock(&count
);
1831 if (count
) RestoreThunkLock(count
);
1833 WIN_RestoreWndsLock( locks
);
1837 WIN_RestoreWndsLock( locks
);
1839 /* need to fill the window handle for WM_PAINT message */
1840 if (msg
.message
== WM_PAINT
)
1842 if (!(msg
.hwnd
= WIN_FindWinToRepaint( hwnd
))) return FALSE
;
1844 if (IsIconic( msg
.hwnd
) && GetClassLongA( msg
.hwnd
, GCL_HICON
))
1846 msg
.message
= WM_PAINTICON
;
1850 /* check hwnd filter */
1851 if (hwnd
&& msg
.hwnd
!= hwnd
&& !IsChild( hwnd
, msg
.hwnd
)) return FALSE
;
1853 /* clear internal paint flag */
1854 RedrawWindow( msg
.hwnd
, NULL
, 0, RDW_NOINTERNALPAINT
| RDW_NOCHILDREN
);
1857 if ((queue
= QUEUE_Current()))
1859 queue
->GetMessageTimeVal
= msg
.time
;
1860 queue
->GetMessagePosVal
= MAKELONG( msg
.pt
.x
, msg
.pt
.y
);
1863 HOOK_CallHooksW( WH_GETMESSAGE
, HC_ACTION
, flags
& PM_REMOVE
, (LPARAM
)&msg
);
1865 /* copy back our internal safe copy of message data to msg_out.
1866 * msg_out is a variable from the *program*, so it can't be used
1867 * internally as it can get "corrupted" by our use of SendMessage()
1868 * (back to the program) inside the message handling itself. */
1874 /***********************************************************************
1875 * PeekMessageA (USER32.@)
1877 BOOL WINAPI
PeekMessageA( MSG
*msg
, HWND hwnd
, UINT first
, UINT last
, UINT flags
)
1879 BOOL ret
= PeekMessageW( msg
, hwnd
, first
, last
, flags
);
1880 if (ret
) msg
->wParam
= map_wparam_WtoA( msg
->message
, msg
->wParam
);
1885 /***********************************************************************
1886 * GetMessageW (USER32.@)
1888 BOOL WINAPI
GetMessageW( MSG
*msg
, HWND hwnd
, UINT first
, UINT last
)
1890 MESSAGEQUEUE
*queue
= QUEUE_Current();
1893 mask
= QS_POSTMESSAGE
| QS_SENDMESSAGE
; /* Always selected */
1896 if ((first
<= WM_KEYLAST
) && (last
>= WM_KEYFIRST
)) mask
|= QS_KEY
;
1897 if ( ((first
<= WM_MOUSELAST
) && (last
>= WM_MOUSEFIRST
)) ||
1898 ((first
<= WM_NCMOUSELAST
) && (last
>= WM_NCMOUSEFIRST
)) ) mask
|= QS_MOUSE
;
1899 if ((first
<= WM_TIMER
) && (last
>= WM_TIMER
)) mask
|= QS_TIMER
;
1900 if ((first
<= WM_SYSTIMER
) && (last
>= WM_SYSTIMER
)) mask
|= QS_TIMER
;
1901 if ((first
<= WM_PAINT
) && (last
>= WM_PAINT
)) mask
|= QS_PAINT
;
1903 else mask
|= QS_MOUSE
| QS_KEY
| QS_TIMER
| QS_PAINT
;
1905 locks
= WIN_SuspendWndsLock();
1907 while (!PeekMessageW( msg
, hwnd
, first
, last
, PM_REMOVE
))
1909 /* wait until one of the bits is set */
1910 unsigned int wake_bits
= 0, changed_bits
= 0;
1913 SERVER_START_REQ( set_queue_mask
)
1915 req
->wake_mask
= QS_SENDMESSAGE
;
1916 req
->changed_mask
= mask
;
1920 wake_bits
= req
->wake_bits
;
1921 changed_bits
= req
->changed_bits
;
1926 if (changed_bits
& mask
) continue;
1927 if (wake_bits
& QS_SENDMESSAGE
) continue;
1929 TRACE( "(%04x) mask=%08x, bits=%08x, changed=%08x, waiting\n",
1930 queue
->self
, mask
, wake_bits
, changed_bits
);
1932 ReleaseThunkLock( &dwlc
);
1933 if (USER_Driver
.pMsgWaitForMultipleObjectsEx
)
1934 USER_Driver
.pMsgWaitForMultipleObjectsEx( 1, &queue
->server_queue
, INFINITE
, 0, 0 );
1936 WaitForSingleObject( queue
->server_queue
, INFINITE
);
1937 if (dwlc
) RestoreThunkLock( dwlc
);
1940 WIN_RestoreWndsLock( locks
);
1942 return (msg
->message
!= WM_QUIT
);
1946 /***********************************************************************
1947 * GetMessageA (USER32.@)
1949 BOOL WINAPI
GetMessageA( MSG
*msg
, HWND hwnd
, UINT first
, UINT last
)
1951 GetMessageW( msg
, hwnd
, first
, last
);
1952 msg
->wParam
= map_wparam_WtoA( msg
->message
, msg
->wParam
);
1953 return (msg
->message
!= WM_QUIT
);
1957 /***********************************************************************
1958 * SetMessageQueue (USER32.@)
1960 BOOL WINAPI
SetMessageQueue( INT size
)
1962 /* now obsolete the message queue will be expanded dynamically as necessary */