2 * Window messaging support
4 * Copyright 2001 Alexandre Julliard
6 * This library is free software; you can redistribute it and/or
7 * modify it under the terms of the GNU Lesser General Public
8 * License as published by the Free Software Foundation; either
9 * version 2.1 of the License, or (at your option) any later version.
11 * This library is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 * Lesser General Public License for more details.
16 * You should have received a copy of the GNU Lesser General Public
17 * License along with this library; if not, write to the Free Software
18 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
22 #include "wine/port.h"
35 #include "wine/unicode.h"
36 #include "wine/server.h"
41 #include "wine/debug.h"
43 WINE_DEFAULT_DEBUG_CHANNEL(msg
);
44 WINE_DECLARE_DEBUG_CHANNEL(relay
);
46 #define WM_NCMOUSEFIRST WM_NCMOUSEMOVE
47 #define WM_NCMOUSELAST WM_NCMBUTTONDBLCLK
49 #define MAX_PACK_COUNT 4
51 /* description of the data fields that need to be packed along with a sent message */
55 const void *data
[MAX_PACK_COUNT
];
56 size_t size
[MAX_PACK_COUNT
];
59 /* info about the message currently being received by the current thread */
60 struct received_message_info
62 enum message_type type
;
64 UINT flags
; /* InSendMessageEx return flags */
67 /* structure to group all parameters for sent messages of the various kinds */
68 struct send_message_info
70 enum message_type type
;
75 UINT flags
; /* flags for SendMessageTimeout */
76 UINT timeout
; /* timeout for SendMessageTimeout */
77 SENDASYNCPROC callback
; /* callback function for SendMessageCallback */
78 ULONG_PTR data
; /* callback data */
82 /* flag for messages that contain pointers */
83 /* 32 messages per entry, messages 0..31 map to bits 0..31 */
85 #define SET(msg) (1 << ((msg) & 31))
87 static const unsigned int message_pointer_flags
[] =
90 SET(WM_CREATE
) | SET(WM_SETTEXT
) | SET(WM_GETTEXT
) |
91 SET(WM_WININICHANGE
) | SET(WM_DEVMODECHANGE
),
93 SET(WM_GETMINMAXINFO
) | SET(WM_DRAWITEM
) | SET(WM_MEASUREITEM
) | SET(WM_DELETEITEM
) |
96 SET(WM_WINDOWPOSCHANGING
) | SET(WM_WINDOWPOSCHANGED
) | SET(WM_COPYDATA
) |
97 SET(WM_NOTIFY
) | SET(WM_HELP
),
99 SET(WM_STYLECHANGING
) | SET(WM_STYLECHANGED
),
101 SET(WM_NCCREATE
) | SET(WM_NCCALCSIZE
) | SET(WM_GETDLGCODE
),
103 SET(EM_GETSEL
) | SET(EM_GETRECT
) | SET(EM_SETRECT
) | SET(EM_SETRECTNP
),
105 SET(EM_REPLACESEL
) | SET(EM_GETLINE
) | SET(EM_SETTABSTOPS
),
107 SET(SBM_GETRANGE
) | SET(SBM_SETSCROLLINFO
) | SET(SBM_GETSCROLLINFO
),
113 SET(CB_GETEDITSEL
) | SET(CB_ADDSTRING
) | SET(CB_DIR
) | SET(CB_GETLBTEXT
) |
114 SET(CB_INSERTSTRING
) | SET(CB_FINDSTRING
) | SET(CB_SELECTSTRING
) |
115 SET(CB_GETDROPPEDCONTROLRECT
) | SET(CB_FINDSTRINGEXACT
),
119 SET(LB_ADDSTRING
) | SET(LB_INSERTSTRING
) | SET(LB_GETTEXT
) | SET(LB_SELECTSTRING
) |
120 SET(LB_DIR
) | SET(LB_FINDSTRING
) |
121 SET(LB_GETSELITEMS
) | SET(LB_SETTABSTOPS
) | SET(LB_ADDFILE
) | SET(LB_GETITEMRECT
),
123 SET(LB_FINDSTRINGEXACT
),
129 SET(WM_NEXTMENU
) | SET(WM_SIZING
) | SET(WM_MOVING
) | SET(WM_DEVICECHANGE
),
131 SET(WM_MDICREATE
) | SET(WM_MDIGETACTIVE
) | SET(WM_DROPOBJECT
) |
132 SET(WM_QUERYDROPOBJECT
) | SET(WM_DRAGLOOP
) | SET(WM_DRAGSELECT
) | SET(WM_DRAGMOVE
),
146 SET(WM_ASKCBFORMATNAME
)
149 /* flags for messages that contain Unicode strings */
150 static const unsigned int message_unicode_flags
[] =
153 SET(WM_CREATE
) | SET(WM_SETTEXT
) | SET(WM_GETTEXT
) | SET(WM_GETTEXTLENGTH
) |
154 SET(WM_WININICHANGE
) | SET(WM_DEVMODECHANGE
),
166 SET(EM_REPLACESEL
) | SET(EM_GETLINE
) | SET(EM_SETPASSWORDCHAR
),
170 SET(WM_CHAR
) | SET(WM_DEADCHAR
) | SET(WM_SYSCHAR
) | SET(WM_SYSDEADCHAR
),
174 SET(CB_ADDSTRING
) | SET(CB_DIR
) | SET(CB_GETLBTEXT
) | SET(CB_GETLBTEXTLEN
) |
175 SET(CB_INSERTSTRING
) | SET(CB_FINDSTRING
) | SET(CB_SELECTSTRING
) | SET(CB_FINDSTRINGEXACT
),
179 SET(LB_ADDSTRING
) | SET(LB_INSERTSTRING
) | SET(LB_GETTEXT
) | SET(LB_GETTEXTLEN
) |
180 SET(LB_SELECTSTRING
) | SET(LB_DIR
) | SET(LB_FINDSTRING
) | SET(LB_ADDFILE
),
182 SET(LB_FINDSTRINGEXACT
),
204 SET(WM_PAINTCLIPBOARD
) | SET(WM_SIZECLIPBOARD
) | SET(WM_ASKCBFORMATNAME
)
207 /* check whether a given message type includes pointers */
208 inline static int is_pointer_message( UINT message
)
210 if (message
>= 8*sizeof(message_pointer_flags
)) return FALSE
;
211 return (message_pointer_flags
[message
/ 32] & SET(message
)) != 0;
214 /* check whether a given message type contains Unicode (or ASCII) chars */
215 inline static int is_unicode_message( UINT message
)
217 if (message
>= 8*sizeof(message_unicode_flags
)) return FALSE
;
218 return (message_unicode_flags
[message
/ 32] & SET(message
)) != 0;
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
));
284 /***********************************************************************
285 * broadcast_message_callback
287 * Helper callback for broadcasting messages.
289 static BOOL CALLBACK
broadcast_message_callback( HWND hwnd
, LPARAM lparam
)
291 struct send_message_info
*info
= (struct send_message_info
*)lparam
;
292 if (!(GetWindowLongW( hwnd
, GWL_STYLE
) & (WS_POPUP
|WS_CAPTION
))) return TRUE
;
296 SendMessageTimeoutW( hwnd
, info
->msg
, info
->wparam
, info
->lparam
,
297 info
->flags
, info
->timeout
, NULL
);
300 SendMessageTimeoutA( hwnd
, info
->msg
, info
->wparam
, info
->lparam
,
301 info
->flags
, info
->timeout
, NULL
);
304 SendNotifyMessageW( hwnd
, info
->msg
, info
->wparam
, info
->lparam
);
307 SendMessageCallbackW( hwnd
, info
->msg
, info
->wparam
, info
->lparam
,
308 info
->callback
, info
->data
);
311 PostMessageW( hwnd
, info
->msg
, info
->wparam
, info
->lparam
);
314 ERR( "bad type %d\n", info
->type
);
321 /***********************************************************************
324 * Convert the wparam of an ASCII message to Unicode.
326 static WPARAM
map_wparam_AtoW( UINT message
, WPARAM wparam
)
331 case EM_SETPASSWORDCHAR
:
338 char ch
= LOWORD(wparam
);
340 MultiByteToWideChar(CP_ACP
, 0, &ch
, 1, &wch
, 1);
341 wparam
= MAKEWPARAM( wch
, HIWORD(wparam
) );
348 ch
[0] = (wparam
>> 8);
349 ch
[1] = (wparam
& 0xff);
350 if (ch
[0]) MultiByteToWideChar(CP_ACP
, 0, ch
, 2, &wch
, 1);
351 else MultiByteToWideChar(CP_ACP
, 0, &ch
[1], 1, &wch
, 1);
352 wparam
= MAKEWPARAM( wch
, HIWORD(wparam
) );
360 /***********************************************************************
363 * Convert the wparam of a Unicode message to ASCII.
365 static WPARAM
map_wparam_WtoA( UINT message
, WPARAM wparam
)
370 case EM_SETPASSWORDCHAR
:
377 WCHAR wch
= LOWORD(wparam
);
379 WideCharToMultiByte( CP_ACP
, 0, &wch
, 1, &ch
, 1, NULL
, NULL
);
380 wparam
= MAKEWPARAM( ch
, HIWORD(wparam
) );
385 WCHAR wch
= LOWORD(wparam
);
388 if (WideCharToMultiByte( CP_ACP
, 0, &wch
, 1, ch
, 2, NULL
, NULL
) == 2)
389 wparam
= MAKEWPARAM( (ch
[0] << 8) | ch
[1], HIWORD(wparam
) );
391 wparam
= MAKEWPARAM( ch
[0], HIWORD(wparam
) );
399 /***********************************************************************
402 * Pack a message for sending to another process.
403 * Return the size of the data we expect in the message reply.
404 * Set data->count to -1 if there is an error.
406 static size_t pack_message( HWND hwnd
, UINT message
, WPARAM wparam
, LPARAM lparam
,
407 struct packed_message
*data
)
415 CREATESTRUCTW
*cs
= (CREATESTRUCTW
*)lparam
;
416 push_data( data
, cs
, sizeof(*cs
) );
417 if (HIWORD(cs
->lpszName
)) push_string( data
, cs
->lpszName
);
418 if (HIWORD(cs
->lpszClass
)) push_string( data
, cs
->lpszClass
);
422 case WM_ASKCBFORMATNAME
:
423 return wparam
* sizeof(WCHAR
);
424 case WM_WININICHANGE
:
425 if (lparam
) push_string(data
, (LPWSTR
)lparam
);
428 case WM_DEVMODECHANGE
:
433 push_string( data
, (LPWSTR
)lparam
);
435 case WM_GETMINMAXINFO
:
436 push_data( data
, (MINMAXINFO
*)lparam
, sizeof(MINMAXINFO
) );
437 return sizeof(MINMAXINFO
);
439 push_data( data
, (DRAWITEMSTRUCT
*)lparam
, sizeof(DRAWITEMSTRUCT
) );
442 push_data( data
, (MEASUREITEMSTRUCT
*)lparam
, sizeof(MEASUREITEMSTRUCT
) );
443 return sizeof(MEASUREITEMSTRUCT
);
445 push_data( data
, (DELETEITEMSTRUCT
*)lparam
, sizeof(DELETEITEMSTRUCT
) );
448 push_data( data
, (COMPAREITEMSTRUCT
*)lparam
, sizeof(COMPAREITEMSTRUCT
) );
450 case WM_WINDOWPOSCHANGING
:
451 case WM_WINDOWPOSCHANGED
:
452 push_data( data
, (WINDOWPOS
*)lparam
, sizeof(WINDOWPOS
) );
453 return sizeof(WINDOWPOS
);
456 COPYDATASTRUCT
*cp
= (COPYDATASTRUCT
*)lparam
;
457 push_data( data
, cp
, sizeof(*cp
) );
458 if (cp
->lpData
) push_data( data
, cp
->lpData
, cp
->cbData
);
462 /* WM_NOTIFY cannot be sent across processes (MSDN) */
466 push_data( data
, (HELPINFO
*)lparam
, sizeof(HELPINFO
) );
468 case WM_STYLECHANGING
:
469 case WM_STYLECHANGED
:
470 push_data( data
, (STYLESTRUCT
*)lparam
, sizeof(STYLESTRUCT
) );
475 push_data( data
, (RECT
*)lparam
, sizeof(RECT
) );
480 NCCALCSIZE_PARAMS
*nc
= (NCCALCSIZE_PARAMS
*)lparam
;
481 push_data( data
, nc
, sizeof(*nc
) );
482 push_data( data
, nc
->lppos
, sizeof(*nc
->lppos
) );
483 return sizeof(*nc
) + sizeof(*nc
->lppos
);
486 if (lparam
) push_data( data
, (MSG
*)lparam
, sizeof(MSG
) );
488 case SBM_SETSCROLLINFO
:
489 push_data( data
, (SCROLLINFO
*)lparam
, sizeof(SCROLLINFO
) );
491 case SBM_GETSCROLLINFO
:
492 push_data( data
, (SCROLLINFO
*)lparam
, sizeof(SCROLLINFO
) );
493 return sizeof(SCROLLINFO
);
499 if (wparam
) size
+= sizeof(DWORD
);
500 if (lparam
) size
+= sizeof(DWORD
);
505 case CB_GETDROPPEDCONTROLRECT
:
509 push_data( data
, (RECT
*)lparam
, sizeof(RECT
) );
513 WORD
*pw
= (WORD
*)lparam
;
514 push_data( data
, pw
, sizeof(*pw
) );
515 return *pw
* sizeof(WCHAR
);
519 if (wparam
) push_data( data
, (UINT
*)lparam
, sizeof(UINT
) * wparam
);
522 case CB_INSERTSTRING
:
524 case CB_FINDSTRINGEXACT
:
525 case CB_SELECTSTRING
:
526 if (combobox_has_strings( hwnd
)) push_string( data
, (LPWSTR
)lparam
);
529 if (!combobox_has_strings( hwnd
)) return sizeof(ULONG_PTR
);
530 return (SendMessageW( hwnd
, CB_GETLBTEXTLEN
, wparam
, 0 ) + 1) * sizeof(WCHAR
);
532 case LB_INSERTSTRING
:
534 case LB_FINDSTRINGEXACT
:
535 case LB_SELECTSTRING
:
536 if (listbox_has_strings( hwnd
)) push_string( data
, (LPWSTR
)lparam
);
539 if (!listbox_has_strings( hwnd
)) return sizeof(ULONG_PTR
);
540 return (SendMessageW( hwnd
, LB_GETTEXTLEN
, wparam
, 0 ) + 1) * sizeof(WCHAR
);
542 return wparam
* sizeof(UINT
);
544 push_data( data
, (MDINEXTMENU
*)lparam
, sizeof(MDINEXTMENU
) );
545 return sizeof(MDINEXTMENU
);
548 push_data( data
, (RECT
*)lparam
, sizeof(RECT
) );
552 MDICREATESTRUCTW
*cs
= (MDICREATESTRUCTW
*)lparam
;
553 push_data( data
, cs
, sizeof(*cs
) );
554 if (HIWORD(cs
->szTitle
)) push_string( data
, cs
->szTitle
);
555 if (HIWORD(cs
->szClass
)) push_string( data
, cs
->szClass
);
558 case WM_MDIGETACTIVE
:
559 if (lparam
) return sizeof(BOOL
);
561 case WM_WINE_SETWINDOWPOS
:
562 push_data( data
, (WINDOWPOS
*)lparam
, sizeof(WINDOWPOS
) );
564 case WM_WINE_KEYBOARD_LL_HOOK
:
565 push_data( data
, (KBDLLHOOKSTRUCT
*)lparam
, sizeof(KBDLLHOOKSTRUCT
) );
567 case WM_WINE_MOUSE_LL_HOOK
:
568 push_data( data
, (MSLLHOOKSTRUCT
*)lparam
, sizeof(MSLLHOOKSTRUCT
) );
571 /* these contain an HFONT */
574 /* these contain an HDC */
577 case WM_ICONERASEBKGND
:
579 case WM_CTLCOLORMSGBOX
:
580 case WM_CTLCOLOREDIT
:
581 case WM_CTLCOLORLISTBOX
:
584 case WM_CTLCOLORSCROLLBAR
:
585 case WM_CTLCOLORSTATIC
:
588 /* these contain an HGLOBAL */
589 case WM_PAINTCLIPBOARD
:
590 case WM_SIZECLIPBOARD
:
591 /* these contain HICON */
594 case WM_QUERYDRAGICON
:
595 case WM_QUERYPARKICON
:
596 /* these contain pointers */
598 case WM_QUERYDROPOBJECT
:
602 case WM_DEVICECHANGE
:
603 FIXME( "msg %x (%s) not supported yet\n", message
, SPY_GetMsgName(message
, hwnd
) );
611 /***********************************************************************
614 * Unpack a message received from another process.
616 static BOOL
unpack_message( HWND hwnd
, UINT message
, WPARAM
*wparam
, LPARAM
*lparam
,
617 void **buffer
, size_t size
)
626 CREATESTRUCTW
*cs
= *buffer
;
627 WCHAR
*str
= (WCHAR
*)(cs
+ 1);
628 if (size
< sizeof(*cs
)) return FALSE
;
630 if (HIWORD(cs
->lpszName
))
632 if (!check_string( str
, size
)) return FALSE
;
634 size
-= (strlenW(str
) + 1) * sizeof(WCHAR
);
635 str
+= strlenW(str
) + 1;
637 if (HIWORD(cs
->lpszClass
))
639 if (!check_string( str
, size
)) return FALSE
;
645 case WM_ASKCBFORMATNAME
:
646 if (!get_buffer_space( buffer
, (*wparam
* sizeof(WCHAR
)) )) return FALSE
;
648 case WM_WININICHANGE
:
649 if (!*lparam
) return TRUE
;
652 case WM_DEVMODECHANGE
:
657 if (!check_string( *buffer
, size
)) return FALSE
;
659 case WM_GETMINMAXINFO
:
660 minsize
= sizeof(MINMAXINFO
);
663 minsize
= sizeof(DRAWITEMSTRUCT
);
666 minsize
= sizeof(MEASUREITEMSTRUCT
);
669 minsize
= sizeof(DELETEITEMSTRUCT
);
672 minsize
= sizeof(COMPAREITEMSTRUCT
);
674 case WM_WINDOWPOSCHANGING
:
675 case WM_WINDOWPOSCHANGED
:
676 case WM_WINE_SETWINDOWPOS
:
677 minsize
= sizeof(WINDOWPOS
);
681 COPYDATASTRUCT
*cp
= *buffer
;
682 if (size
< sizeof(*cp
)) return FALSE
;
685 minsize
= sizeof(*cp
) + cp
->cbData
;
691 /* WM_NOTIFY cannot be sent across processes (MSDN) */
694 minsize
= sizeof(HELPINFO
);
696 case WM_STYLECHANGING
:
697 case WM_STYLECHANGED
:
698 minsize
= sizeof(STYLESTRUCT
);
701 if (!*wparam
) minsize
= sizeof(RECT
);
704 NCCALCSIZE_PARAMS
*nc
= *buffer
;
705 if (size
< sizeof(*nc
) + sizeof(*nc
->lppos
)) return FALSE
;
706 nc
->lppos
= (WINDOWPOS
*)(nc
+ 1);
710 if (!*lparam
) return TRUE
;
711 minsize
= sizeof(MSG
);
713 case SBM_SETSCROLLINFO
:
714 minsize
= sizeof(SCROLLINFO
);
716 case SBM_GETSCROLLINFO
:
717 if (!get_buffer_space( buffer
, sizeof(SCROLLINFO
))) return FALSE
;
722 if (*wparam
|| *lparam
)
724 if (!get_buffer_space( buffer
, 2*sizeof(DWORD
) )) return FALSE
;
725 if (*wparam
) *wparam
= (WPARAM
)*buffer
;
726 if (*lparam
) *lparam
= (LPARAM
)((DWORD
*)*buffer
+ 1);
731 case CB_GETDROPPEDCONTROLRECT
:
732 if (!get_buffer_space( buffer
, sizeof(RECT
) )) return FALSE
;
736 minsize
= sizeof(RECT
);
741 if (size
< sizeof(WORD
)) return FALSE
;
742 len
= *(WORD
*)*buffer
;
743 if (!get_buffer_space( buffer
, (len
+ 1) * sizeof(WCHAR
) )) return FALSE
;
744 *lparam
= (LPARAM
)*buffer
+ sizeof(WORD
); /* don't erase WORD at start of buffer */
749 if (!*wparam
) return TRUE
;
750 minsize
= *wparam
* sizeof(UINT
);
753 case CB_INSERTSTRING
:
755 case CB_FINDSTRINGEXACT
:
756 case CB_SELECTSTRING
:
758 case LB_INSERTSTRING
:
760 case LB_FINDSTRINGEXACT
:
761 case LB_SELECTSTRING
:
762 if (!*buffer
) return TRUE
;
763 if (!check_string( *buffer
, size
)) return FALSE
;
767 size
= sizeof(ULONG_PTR
);
768 if (combobox_has_strings( hwnd
))
769 size
= (SendMessageW( hwnd
, CB_GETLBTEXTLEN
, *wparam
, 0 ) + 1) * sizeof(WCHAR
);
770 if (!get_buffer_space( buffer
, size
)) return FALSE
;
775 size
= sizeof(ULONG_PTR
);
776 if (listbox_has_strings( hwnd
))
777 size
= (SendMessageW( hwnd
, LB_GETTEXTLEN
, *wparam
, 0 ) + 1) * sizeof(WCHAR
);
778 if (!get_buffer_space( buffer
, size
)) return FALSE
;
782 if (!get_buffer_space( buffer
, *wparam
* sizeof(UINT
) )) return FALSE
;
785 minsize
= sizeof(MDINEXTMENU
);
786 if (!get_buffer_space( buffer
, sizeof(MDINEXTMENU
) )) return FALSE
;
790 minsize
= sizeof(RECT
);
791 if (!get_buffer_space( buffer
, sizeof(RECT
) )) return FALSE
;
795 MDICREATESTRUCTW
*cs
= *buffer
;
796 WCHAR
*str
= (WCHAR
*)(cs
+ 1);
797 if (size
< sizeof(*cs
)) return FALSE
;
799 if (HIWORD(cs
->szTitle
))
801 if (!check_string( str
, size
)) return FALSE
;
803 size
-= (strlenW(str
) + 1) * sizeof(WCHAR
);
804 str
+= strlenW(str
) + 1;
806 if (HIWORD(cs
->szClass
))
808 if (!check_string( str
, size
)) return FALSE
;
813 case WM_MDIGETACTIVE
:
814 if (!*lparam
) return TRUE
;
815 if (!get_buffer_space( buffer
, sizeof(BOOL
) )) return FALSE
;
817 case WM_WINE_KEYBOARD_LL_HOOK
:
818 minsize
= sizeof(KBDLLHOOKSTRUCT
);
820 case WM_WINE_MOUSE_LL_HOOK
:
821 minsize
= sizeof(MSLLHOOKSTRUCT
);
824 /* these contain an HFONT */
827 /* these contain an HDC */
830 case WM_ICONERASEBKGND
:
832 case WM_CTLCOLORMSGBOX
:
833 case WM_CTLCOLOREDIT
:
834 case WM_CTLCOLORLISTBOX
:
837 case WM_CTLCOLORSCROLLBAR
:
838 case WM_CTLCOLORSTATIC
:
841 /* these contain an HGLOBAL */
842 case WM_PAINTCLIPBOARD
:
843 case WM_SIZECLIPBOARD
:
844 /* these contain HICON */
847 case WM_QUERYDRAGICON
:
848 case WM_QUERYPARKICON
:
849 /* these contain pointers */
851 case WM_QUERYDROPOBJECT
:
855 case WM_DEVICECHANGE
:
856 FIXME( "msg %x (%s) not supported yet\n", message
, SPY_GetMsgName(message
, hwnd
) );
860 return TRUE
; /* message doesn't need any unpacking */
863 /* default exit for most messages: check minsize and store buffer in lparam */
864 if (size
< minsize
) return FALSE
;
865 *lparam
= (LPARAM
)*buffer
;
870 /***********************************************************************
873 * Pack a reply to a message for sending to another process.
875 static void pack_reply( HWND hwnd
, UINT message
, WPARAM wparam
, LPARAM lparam
,
876 LRESULT res
, struct packed_message
*data
)
883 push_data( data
, (CREATESTRUCTW
*)lparam
, sizeof(CREATESTRUCTW
) );
888 push_data( data
, (WCHAR
*)lparam
, (res
+ 1) * sizeof(WCHAR
) );
890 case WM_GETMINMAXINFO
:
891 push_data( data
, (MINMAXINFO
*)lparam
, sizeof(MINMAXINFO
) );
894 push_data( data
, (MEASUREITEMSTRUCT
*)lparam
, sizeof(MEASUREITEMSTRUCT
) );
896 case WM_WINDOWPOSCHANGING
:
897 case WM_WINDOWPOSCHANGED
:
898 push_data( data
, (WINDOWPOS
*)lparam
, sizeof(WINDOWPOS
) );
901 if (lparam
) push_data( data
, (MSG
*)lparam
, sizeof(MSG
) );
903 case SBM_GETSCROLLINFO
:
904 push_data( data
, (SCROLLINFO
*)lparam
, sizeof(SCROLLINFO
) );
908 case CB_GETDROPPEDCONTROLRECT
:
911 push_data( data
, (RECT
*)lparam
, sizeof(RECT
) );
915 WORD
*ptr
= (WORD
*)lparam
;
916 push_data( data
, ptr
, ptr
[-1] * sizeof(WCHAR
) );
920 push_data( data
, (UINT
*)lparam
, wparam
* sizeof(UINT
) );
922 case WM_MDIGETACTIVE
:
923 if (lparam
) push_data( data
, (BOOL
*)lparam
, sizeof(BOOL
) );
927 push_data( data
, (RECT
*)lparam
, sizeof(RECT
) );
930 NCCALCSIZE_PARAMS
*nc
= (NCCALCSIZE_PARAMS
*)lparam
;
931 push_data( data
, nc
, sizeof(*nc
) );
932 push_data( data
, nc
->lppos
, sizeof(*nc
->lppos
) );
938 if (wparam
) push_data( data
, (DWORD
*)wparam
, sizeof(DWORD
) );
939 if (lparam
) push_data( data
, (DWORD
*)lparam
, sizeof(DWORD
) );
942 push_data( data
, (MDINEXTMENU
*)lparam
, sizeof(MDINEXTMENU
) );
945 push_data( data
, (MDICREATESTRUCTW
*)lparam
, sizeof(MDICREATESTRUCTW
) );
947 case WM_ASKCBFORMATNAME
:
948 push_data( data
, (WCHAR
*)lparam
, (strlenW((WCHAR
*)lparam
) + 1) * sizeof(WCHAR
) );
954 /***********************************************************************
957 * Unpack a message reply received from another process.
959 static void unpack_reply( HWND hwnd
, UINT message
, WPARAM wparam
, LPARAM lparam
,
960 void *buffer
, size_t size
)
967 CREATESTRUCTW
*cs
= (CREATESTRUCTW
*)lparam
;
968 LPCWSTR name
= cs
->lpszName
, class = cs
->lpszClass
;
969 memcpy( cs
, buffer
, min( sizeof(*cs
), size
));
970 cs
->lpszName
= name
; /* restore the original pointers */
971 cs
->lpszClass
= class;
975 case WM_ASKCBFORMATNAME
:
976 memcpy( (WCHAR
*)lparam
, buffer
, min( wparam
*sizeof(WCHAR
), size
));
978 case WM_GETMINMAXINFO
:
979 memcpy( (MINMAXINFO
*)lparam
, buffer
, min( sizeof(MINMAXINFO
), size
));
982 memcpy( (MEASUREITEMSTRUCT
*)lparam
, buffer
, min( sizeof(MEASUREITEMSTRUCT
), size
));
984 case WM_WINDOWPOSCHANGING
:
985 case WM_WINDOWPOSCHANGED
:
986 memcpy( (WINDOWPOS
*)lparam
, buffer
, min( sizeof(WINDOWPOS
), size
));
989 if (lparam
) memcpy( (MSG
*)lparam
, buffer
, min( sizeof(MSG
), size
));
991 case SBM_GETSCROLLINFO
:
992 memcpy( (SCROLLINFO
*)lparam
, buffer
, min( sizeof(SCROLLINFO
), size
));
995 case CB_GETDROPPEDCONTROLRECT
:
999 memcpy( (RECT
*)lparam
, buffer
, min( sizeof(RECT
), size
));
1002 size
= min( size
, (size_t)*(WORD
*)lparam
);
1003 memcpy( (WCHAR
*)lparam
, buffer
, size
);
1005 case LB_GETSELITEMS
:
1006 memcpy( (UINT
*)lparam
, buffer
, min( wparam
*sizeof(UINT
), size
));
1010 memcpy( (WCHAR
*)lparam
, buffer
, size
);
1013 memcpy( (MDINEXTMENU
*)lparam
, buffer
, min( sizeof(MDINEXTMENU
), size
));
1015 case WM_MDIGETACTIVE
:
1016 if (lparam
) memcpy( (BOOL
*)lparam
, buffer
, min( sizeof(BOOL
), size
));
1020 memcpy( (RECT
*)lparam
, buffer
, min( sizeof(RECT
), size
));
1023 NCCALCSIZE_PARAMS
*nc
= (NCCALCSIZE_PARAMS
*)lparam
;
1024 WINDOWPOS
*wp
= nc
->lppos
;
1025 memcpy( nc
, buffer
, min( sizeof(*nc
), size
));
1026 if (size
> sizeof(*nc
))
1028 size
-= sizeof(*nc
);
1029 memcpy( wp
, (NCCALCSIZE_PARAMS
*)buffer
+ 1, min( sizeof(*wp
), size
));
1031 nc
->lppos
= wp
; /* restore the original pointer */
1039 memcpy( (DWORD
*)wparam
, buffer
, min( sizeof(DWORD
), size
));
1040 if (size
<= sizeof(DWORD
)) break;
1041 size
-= sizeof(DWORD
);
1042 buffer
= (DWORD
*)buffer
+ 1;
1044 if (lparam
) memcpy( (DWORD
*)lparam
, buffer
, min( sizeof(DWORD
), size
));
1048 MDICREATESTRUCTW
*cs
= (MDICREATESTRUCTW
*)lparam
;
1049 LPCWSTR title
= cs
->szTitle
, class = cs
->szClass
;
1050 memcpy( cs
, buffer
, min( sizeof(*cs
), size
));
1051 cs
->szTitle
= title
; /* restore the original pointers */
1052 cs
->szClass
= class;
1056 ERR( "should not happen: unexpected message %x\n", message
);
1062 /***********************************************************************
1065 * Send a reply to a sent message.
1067 static void reply_message( struct received_message_info
*info
, LRESULT result
, BOOL remove
)
1069 struct packed_message data
;
1070 int i
, replied
= info
->flags
& ISMEX_REPLIED
;
1072 if (info
->flags
& ISMEX_NOTIFY
) return; /* notify messages don't get replies */
1073 if (!remove
&& replied
) return; /* replied already */
1076 info
->flags
|= ISMEX_REPLIED
;
1078 if (info
->type
== MSG_OTHER_PROCESS
&& !replied
)
1080 pack_reply( info
->msg
.hwnd
, info
->msg
.message
, info
->msg
.wParam
,
1081 info
->msg
.lParam
, result
, &data
);
1084 SERVER_START_REQ( reply_message
)
1086 req
->type
= info
->type
;
1087 req
->result
= result
;
1088 req
->remove
= remove
;
1089 for (i
= 0; i
< data
.count
; i
++) wine_server_add_data( req
, data
.data
[i
], data
.size
[i
] );
1090 wine_server_call( req
);
1096 /***********************************************************************
1097 * handle_internal_message
1099 * Handle an internal Wine message instead of calling the window proc.
1101 static LRESULT
handle_internal_message( HWND hwnd
, UINT msg
, WPARAM wparam
, LPARAM lparam
)
1103 if (hwnd
== GetDesktopWindow()) return 0;
1106 case WM_WINE_DESTROYWINDOW
:
1107 return WIN_DestroyWindow( hwnd
);
1108 case WM_WINE_SETWINDOWPOS
:
1109 return USER_Driver
.pSetWindowPos( (WINDOWPOS
*)lparam
);
1110 case WM_WINE_SHOWWINDOW
:
1111 return ShowWindow( hwnd
, wparam
);
1112 case WM_WINE_SETPARENT
:
1113 return (LRESULT
)SetParent( hwnd
, (HWND
)wparam
);
1114 case WM_WINE_SETWINDOWLONG
:
1115 return (LRESULT
)SetWindowLongW( hwnd
, wparam
, lparam
);
1116 case WM_WINE_ENABLEWINDOW
:
1117 return EnableWindow( hwnd
, wparam
);
1118 case WM_WINE_SETACTIVEWINDOW
:
1119 return (LRESULT
)SetActiveWindow( (HWND
)wparam
);
1120 case WM_WINE_KEYBOARD_LL_HOOK
:
1121 return HOOK_CallHooks( WH_KEYBOARD_LL
, HC_ACTION
, wparam
, lparam
, TRUE
);
1122 case WM_WINE_MOUSE_LL_HOOK
:
1123 return HOOK_CallHooks( WH_MOUSE_LL
, HC_ACTION
, wparam
, lparam
, TRUE
);
1125 FIXME( "unknown internal message %x\n", msg
);
1130 /* since the WM_DDE_ACK response to a WM_DDE_EXECUTE message should contain the handle
1131 * to the memory handle, we keep track (in the server side) of all pairs of handle
1132 * used (the client passes its value and the content of the memory handle), and
1133 * the server stored both values (the client, and the local one, created after the
1134 * content). When a ACK message is generated, the list of pair is searched for a
1135 * matching pair, so that the client memory handle can be returned.
1138 HGLOBAL client_hMem
;
1139 HGLOBAL server_hMem
;
1142 static struct DDE_pair
* dde_pairs
;
1143 static int dde_num_alloc
;
1144 static int dde_num_used
;
1146 static CRITICAL_SECTION dde_crst
;
1147 static CRITICAL_SECTION_DEBUG critsect_debug
=
1150 { &critsect_debug
.ProcessLocksList
, &critsect_debug
.ProcessLocksList
},
1151 0, 0, { 0, (DWORD
)(__FILE__
": dde_crst") }
1153 static CRITICAL_SECTION dde_crst
= { &critsect_debug
, -1, 0, 0, 0, 0 };
1155 static BOOL
dde_add_pair(HGLOBAL chm
, HGLOBAL shm
)
1160 EnterCriticalSection(&dde_crst
);
1162 /* now remember the pair of hMem on both sides */
1163 if (dde_num_used
== dde_num_alloc
)
1165 struct DDE_pair
* tmp
;
1167 tmp
= HeapReAlloc( GetProcessHeap(), 0, dde_pairs
,
1168 (dde_num_alloc
+ GROWBY
) * sizeof(struct DDE_pair
));
1170 tmp
= HeapAlloc( GetProcessHeap(), 0,
1171 (dde_num_alloc
+ GROWBY
) * sizeof(struct DDE_pair
));
1175 LeaveCriticalSection(&dde_crst
);
1179 /* zero out newly allocated part */
1180 memset(&dde_pairs
[dde_num_alloc
], 0, GROWBY
* sizeof(struct DDE_pair
));
1181 dde_num_alloc
+= GROWBY
;
1184 for (i
= 0; i
< dde_num_alloc
; i
++)
1186 if (dde_pairs
[i
].server_hMem
== 0)
1188 dde_pairs
[i
].client_hMem
= chm
;
1189 dde_pairs
[i
].server_hMem
= shm
;
1194 LeaveCriticalSection(&dde_crst
);
1198 static HGLOBAL
dde_get_pair(HGLOBAL shm
)
1203 EnterCriticalSection(&dde_crst
);
1204 for (i
= 0; i
< dde_num_alloc
; i
++)
1206 if (dde_pairs
[i
].server_hMem
== shm
)
1208 /* free this pair */
1209 dde_pairs
[i
].server_hMem
= 0;
1211 ret
= dde_pairs
[i
].client_hMem
;
1215 LeaveCriticalSection(&dde_crst
);
1219 /***********************************************************************
1222 * Post a DDE message
1224 static BOOL
post_dde_message( DWORD dest_tid
, struct packed_message
*data
, const struct send_message_info
*info
)
1230 HGLOBAL hunlock
= 0;
1234 if (!UnpackDDElParam( info
->msg
, info
->lparam
, &uiLo
, &uiHi
))
1240 /* DDE messages which don't require packing are:
1249 /* uiHi should contain a hMem from WM_DDE_EXECUTE */
1250 HGLOBAL h
= dde_get_pair( (HANDLE
)uiHi
);
1253 /* send back the value of h on the other side */
1254 push_data( data
, &h
, sizeof(HGLOBAL
) );
1256 TRACE( "send dde-ack %x %08x => %08lx\n", uiLo
, uiHi
, (DWORD
)h
);
1261 /* uiHi should contain either an atom or 0 */
1262 TRACE( "send dde-ack %x atom=%x\n", uiLo
, uiHi
);
1263 lp
= MAKELONG( uiLo
, uiHi
);
1272 size
= GlobalSize( (HGLOBAL
)uiLo
) ;
1273 if ((info
->msg
== WM_DDE_ADVISE
&& size
< sizeof(DDEADVISE
)) ||
1274 (info
->msg
== WM_DDE_DATA
&& size
< sizeof(DDEDATA
)) ||
1275 (info
->msg
== WM_DDE_POKE
&& size
< sizeof(DDEPOKE
))
1279 else if (info
->msg
!= WM_DDE_DATA
) return FALSE
;
1284 if ((ptr
= GlobalLock( (HGLOBAL
)uiLo
) ))
1286 DDEDATA
*dde_data
= (DDEDATA
*)ptr
;
1287 TRACE("unused %d, fResponse %d, fRelease %d, fDeferUpd %d, fAckReq %d, cfFormat %d\n",
1288 dde_data
->unused
, dde_data
->fResponse
, dde_data
->fRelease
,
1289 dde_data
->reserved
, dde_data
->fAckReq
, dde_data
->cfFormat
);
1290 push_data( data
, ptr
, size
);
1291 hunlock
= (HGLOBAL
)uiLo
;
1294 TRACE( "send ddepack %u %x\n", size
, uiHi
);
1296 case WM_DDE_EXECUTE
:
1299 if ((ptr
= GlobalLock( (HGLOBAL
)info
->lparam
) ))
1301 push_data(data
, ptr
, GlobalSize( (HGLOBAL
)info
->lparam
));
1302 /* so that the other side can send it back on ACK */
1304 hunlock
= (HGLOBAL
)info
->lparam
;
1309 SERVER_START_REQ( send_message
)
1312 req
->type
= info
->type
;
1314 req
->win
= info
->hwnd
;
1315 req
->msg
= info
->msg
;
1316 req
->wparam
= info
->wparam
;
1318 req
->time
= GetCurrentTime();
1320 for (i
= 0; i
< data
->count
; i
++)
1321 wine_server_add_data( req
, data
->data
[i
], data
->size
[i
] );
1322 if ((res
= wine_server_call( req
)))
1324 if (res
== STATUS_INVALID_PARAMETER
)
1325 /* FIXME: find a STATUS_ value for this one */
1326 SetLastError( ERROR_INVALID_THREAD_ID
);
1328 SetLastError( RtlNtStatusToDosError(res
) );
1331 FreeDDElParam(info
->msg
, info
->lparam
);
1334 if (hunlock
) GlobalUnlock(hunlock
);
1339 /***********************************************************************
1340 * unpack_dde_message
1342 * Unpack a posted DDE message received from another process.
1344 static BOOL
unpack_dde_message( HWND hwnd
, UINT message
, WPARAM
*wparam
, LPARAM
*lparam
,
1345 void **buffer
, size_t size
)
1356 /* hMem is being passed */
1357 if (size
!= sizeof(HGLOBAL
)) return FALSE
;
1358 if (!buffer
|| !*buffer
) return FALSE
;
1360 memcpy( &hMem
, *buffer
, size
);
1362 TRACE("recv dde-ack %x mem=%x[%lx]\n", uiLo
, uiHi
, GlobalSize( hMem
));
1366 uiLo
= LOWORD( *lparam
);
1367 uiHi
= HIWORD( *lparam
);
1368 TRACE("recv dde-ack %x atom=%x\n", uiLo
, uiHi
);
1370 *lparam
= PackDDElParam( WM_DDE_ACK
, uiLo
, uiHi
);
1375 if ((!buffer
|| !*buffer
) && message
!= WM_DDE_DATA
) return FALSE
;
1377 TRACE( "recv ddepack %u %x\n", size
, uiHi
);
1380 hMem
= GlobalAlloc( GMEM_MOVEABLE
|GMEM_DDESHARE
, size
);
1381 if (hMem
&& (ptr
= GlobalLock( hMem
)))
1383 memcpy( ptr
, *buffer
, size
);
1384 GlobalUnlock( hMem
);
1390 *lparam
= PackDDElParam( message
, uiLo
, uiHi
);
1392 case WM_DDE_EXECUTE
:
1395 if (!buffer
|| !*buffer
) return FALSE
;
1396 hMem
= GlobalAlloc( GMEM_MOVEABLE
|GMEM_DDESHARE
, size
);
1397 if (hMem
&& (ptr
= GlobalLock( hMem
)))
1399 memcpy( ptr
, *buffer
, size
);
1400 GlobalUnlock( hMem
);
1401 TRACE( "exec: pairing c=%08lx s=%08lx\n", *lparam
, (DWORD
)hMem
);
1402 if (!dde_add_pair( (HGLOBAL
)*lparam
, hMem
))
1408 } else return FALSE
;
1409 *lparam
= (LPARAM
)hMem
;
1415 /***********************************************************************
1418 * Call a window procedure and the corresponding hooks.
1420 static LRESULT
call_window_proc( HWND hwnd
, UINT msg
, WPARAM wparam
, LPARAM lparam
,
1421 BOOL unicode
, BOOL same_thread
)
1426 CWPRETSTRUCT cwpret
;
1427 MESSAGEQUEUE
*queue
= QUEUE_Current();
1429 if (queue
->recursion_count
> MAX_SENDMSG_RECURSION
) return 0;
1430 queue
->recursion_count
++;
1432 if (msg
& 0x80000000)
1434 result
= handle_internal_message( hwnd
, msg
, wparam
, lparam
);
1438 /* first the WH_CALLWNDPROC hook */
1439 hwnd
= WIN_GetFullHandle( hwnd
);
1440 cwp
.lParam
= lparam
;
1441 cwp
.wParam
= wparam
;
1444 HOOK_CallHooks( WH_CALLWNDPROC
, HC_ACTION
, same_thread
, (LPARAM
)&cwp
, unicode
);
1446 /* now call the window procedure */
1449 if (!(winproc
= (WNDPROC
)GetWindowLongW( hwnd
, GWL_WNDPROC
))) goto done
;
1450 result
= CallWindowProcW( winproc
, hwnd
, msg
, wparam
, lparam
);
1454 if (!(winproc
= (WNDPROC
)GetWindowLongA( hwnd
, GWL_WNDPROC
))) goto done
;
1455 result
= CallWindowProcA( winproc
, hwnd
, msg
, wparam
, lparam
);
1458 /* and finally the WH_CALLWNDPROCRET hook */
1459 cwpret
.lResult
= result
;
1460 cwpret
.lParam
= lparam
;
1461 cwpret
.wParam
= wparam
;
1462 cwpret
.message
= msg
;
1464 HOOK_CallHooks( WH_CALLWNDPROCRET
, HC_ACTION
, same_thread
, (LPARAM
)&cwpret
, unicode
);
1466 queue
->recursion_count
--;
1471 /***********************************************************************
1472 * process_hardware_message
1474 * Process a hardware message; return TRUE if message should be passed on to the app
1476 static BOOL
process_hardware_message( MSG
*msg
, ULONG_PTR extra_info
, HWND hwnd
,
1477 UINT first
, UINT last
, BOOL remove
)
1481 if (!MSG_process_raw_hardware_message( msg
, extra_info
, hwnd
, first
, last
, remove
))
1484 ret
= MSG_process_cooked_hardware_message( msg
, extra_info
, remove
);
1486 /* tell the server we have passed it to the app
1487 * (even though we may end up dropping it later on)
1489 SERVER_START_REQ( reply_message
)
1491 req
->type
= MSG_HARDWARE
;
1493 req
->remove
= remove
|| !ret
;
1494 wine_server_call( req
);
1501 /***********************************************************************
1502 * call_sendmsg_callback
1504 * Call the callback function of SendMessageCallback.
1506 static inline void call_sendmsg_callback( SENDASYNCPROC callback
, HWND hwnd
, UINT msg
,
1507 ULONG_PTR data
, LRESULT result
)
1509 if (TRACE_ON(relay
))
1510 DPRINTF( "%04lx:Call message callback %p (hwnd=%p,msg=%s,data=%08lx,result=%08lx)\n",
1511 GetCurrentThreadId(), callback
, hwnd
, SPY_GetMsgName( msg
, hwnd
),
1513 callback( hwnd
, msg
, data
, result
);
1514 if (TRACE_ON(relay
))
1515 DPRINTF( "%04lx:Ret message callback %p (hwnd=%p,msg=%s,data=%08lx,result=%08lx)\n",
1516 GetCurrentThreadId(), callback
, hwnd
, SPY_GetMsgName( msg
, hwnd
),
1521 /***********************************************************************
1524 * Peek for a message matching the given parameters. Return FALSE if none available.
1525 * All pending sent messages are processed before returning.
1527 BOOL
MSG_peek_message( MSG
*msg
, HWND hwnd
, UINT first
, UINT last
, int flags
)
1530 ULONG_PTR extra_info
= 0;
1531 MESSAGEQUEUE
*queue
= QUEUE_Current();
1532 struct received_message_info info
, *old_info
;
1534 if (!first
&& !last
) last
= ~0;
1539 void *buffer
= NULL
;
1540 size_t size
= 0, buffer_size
= 0;
1542 do /* loop while buffer is too small */
1544 if (buffer_size
&& !(buffer
= HeapAlloc( GetProcessHeap(), 0, buffer_size
)))
1546 SERVER_START_REQ( get_message
)
1549 req
->get_win
= hwnd
;
1550 req
->get_first
= first
;
1551 req
->get_last
= last
;
1552 if (buffer_size
) wine_server_set_reply( req
, buffer
, buffer_size
);
1553 if (!(res
= wine_server_call( req
)))
1555 size
= wine_server_reply_size( reply
);
1556 info
.type
= reply
->type
;
1557 info
.msg
.hwnd
= reply
->win
;
1558 info
.msg
.message
= reply
->msg
;
1559 info
.msg
.wParam
= reply
->wparam
;
1560 info
.msg
.lParam
= reply
->lparam
;
1561 info
.msg
.time
= reply
->time
;
1562 info
.msg
.pt
.x
= reply
->x
;
1563 info
.msg
.pt
.y
= reply
->y
;
1564 extra_info
= reply
->info
;
1568 if (buffer
) HeapFree( GetProcessHeap(), 0, buffer
);
1569 buffer_size
= reply
->total
;
1573 } while (res
== STATUS_BUFFER_OVERFLOW
);
1575 if (res
) return FALSE
;
1577 TRACE( "got type %d msg %x (%s) hwnd %p wp %x lp %lx\n",
1578 info
.type
, info
.msg
.message
, SPY_GetMsgName(info
.msg
.message
, info
.msg
.hwnd
),
1579 info
.msg
.hwnd
, info
.msg
.wParam
, info
.msg
.lParam
);
1585 info
.flags
= ISMEX_SEND
;
1588 info
.flags
= ISMEX_NOTIFY
;
1591 info
.flags
= ISMEX_CALLBACK
;
1593 case MSG_CALLBACK_RESULT
:
1594 call_sendmsg_callback( (SENDASYNCPROC
)info
.msg
.wParam
, info
.msg
.hwnd
,
1595 info
.msg
.message
, extra_info
, info
.msg
.lParam
);
1597 case MSG_OTHER_PROCESS
:
1598 info
.flags
= ISMEX_SEND
;
1599 if (!unpack_message( info
.msg
.hwnd
, info
.msg
.message
, &info
.msg
.wParam
,
1600 &info
.msg
.lParam
, &buffer
, size
))
1602 ERR( "invalid packed message %x (%s) hwnd %p wp %x lp %lx size %d\n",
1603 info
.msg
.message
, SPY_GetMsgName(info
.msg
.message
, info
.msg
.hwnd
), info
.msg
.hwnd
,
1604 info
.msg
.wParam
, info
.msg
.lParam
, size
);
1606 reply_message( &info
, 0, TRUE
);
1611 if (!process_hardware_message( &info
.msg
, extra_info
,
1612 hwnd
, first
, last
, flags
& GET_MSG_REMOVE
))
1614 TRACE("dropping msg %x\n", info
.msg
.message
);
1615 goto next
; /* ignore it */
1617 queue
->GetMessagePosVal
= MAKELONG( info
.msg
.pt
.x
, info
.msg
.pt
.y
);
1620 queue
->GetMessageExtraInfoVal
= extra_info
;
1621 if (info
.msg
.message
>= WM_DDE_FIRST
&& info
.msg
.message
<= WM_DDE_LAST
)
1623 if (!unpack_dde_message( info
.msg
.hwnd
, info
.msg
.message
, &info
.msg
.wParam
,
1624 &info
.msg
.lParam
, &buffer
, size
))
1626 ERR( "invalid packed dde-message %x (%s) hwnd %p wp %x lp %lx size %d\n",
1627 info
.msg
.message
, SPY_GetMsgName(info
.msg
.message
, info
.msg
.hwnd
),
1628 info
.msg
.hwnd
, info
.msg
.wParam
, info
.msg
.lParam
, size
);
1629 goto next
; /* ignore it */
1633 if (buffer
) HeapFree( GetProcessHeap(), 0, buffer
);
1637 /* if we get here, we have a sent message; call the window procedure */
1638 old_info
= queue
->receive_info
;
1639 queue
->receive_info
= &info
;
1640 result
= call_window_proc( info
.msg
.hwnd
, info
.msg
.message
, info
.msg
.wParam
,
1641 info
.msg
.lParam
, (info
.type
!= MSG_ASCII
), FALSE
);
1642 reply_message( &info
, result
, TRUE
);
1643 queue
->receive_info
= old_info
;
1645 if (buffer
) HeapFree( GetProcessHeap(), 0, buffer
);
1650 /***********************************************************************
1651 * wait_message_reply
1653 * Wait until a sent message gets replied to.
1655 static void wait_message_reply( UINT flags
)
1657 MESSAGEQUEUE
*queue
;
1659 if (!(queue
= QUEUE_Current())) return;
1663 unsigned int wake_bits
= 0, changed_bits
= 0;
1666 SERVER_START_REQ( set_queue_mask
)
1668 req
->wake_mask
= QS_SMRESULT
| ((flags
& SMTO_BLOCK
) ? 0 : QS_SENDMESSAGE
);
1669 req
->changed_mask
= req
->wake_mask
;
1671 if (!wine_server_call( req
))
1673 wake_bits
= reply
->wake_bits
;
1674 changed_bits
= reply
->changed_bits
;
1679 if (wake_bits
& QS_SMRESULT
) return; /* got a result */
1680 if (wake_bits
& QS_SENDMESSAGE
)
1682 /* Process the sent message immediately */
1684 MSG_peek_message( &msg
, 0, 0, 0, GET_MSG_REMOVE
| GET_MSG_SENT_ONLY
);
1688 /* now wait for it */
1690 ReleaseThunkLock( &dwlc
);
1692 if (USER_Driver
.pMsgWaitForMultipleObjectsEx
)
1693 res
= USER_Driver
.pMsgWaitForMultipleObjectsEx( 1, &queue
->server_queue
,
1696 res
= WaitForSingleObject( queue
->server_queue
, INFINITE
);
1698 if (dwlc
) RestoreThunkLock( dwlc
);
1702 /***********************************************************************
1703 * put_message_in_queue
1705 * Put a sent message into the destination queue.
1706 * For inter-process message, reply_size is set to expected size of reply data.
1708 static BOOL
put_message_in_queue( DWORD dest_tid
, const struct send_message_info
*info
,
1709 size_t *reply_size
)
1711 struct packed_message data
;
1713 int i
, timeout
= -1;
1715 if (info
->type
!= MSG_NOTIFY
&&
1716 info
->type
!= MSG_CALLBACK
&&
1717 info
->type
!= MSG_POSTED
&&
1718 info
->timeout
!= INFINITE
)
1719 timeout
= info
->timeout
;
1722 if (info
->type
== MSG_OTHER_PROCESS
)
1724 *reply_size
= pack_message( info
->hwnd
, info
->msg
, info
->wparam
, info
->lparam
, &data
);
1725 if (data
.count
== -1)
1727 WARN( "cannot pack message %x\n", info
->msg
);
1731 else if (info
->type
== MSG_POSTED
&& info
->msg
>= WM_DDE_FIRST
&& info
->msg
<= WM_DDE_LAST
)
1733 return post_dde_message( dest_tid
, &data
, info
);
1736 SERVER_START_REQ( send_message
)
1739 req
->type
= info
->type
;
1741 req
->win
= info
->hwnd
;
1742 req
->msg
= info
->msg
;
1743 req
->wparam
= info
->wparam
;
1744 req
->lparam
= info
->lparam
;
1745 req
->time
= GetCurrentTime();
1746 req
->timeout
= timeout
;
1748 if (info
->type
== MSG_CALLBACK
)
1750 req
->callback
= info
->callback
;
1751 req
->info
= info
->data
;
1754 if (info
->flags
& SMTO_ABORTIFHUNG
) req
->flags
|= SEND_MSG_ABORT_IF_HUNG
;
1755 for (i
= 0; i
< data
.count
; i
++) wine_server_add_data( req
, data
.data
[i
], data
.size
[i
] );
1756 if ((res
= wine_server_call( req
)))
1758 if (res
== STATUS_INVALID_PARAMETER
)
1759 /* FIXME: find a STATUS_ value for this one */
1760 SetLastError( ERROR_INVALID_THREAD_ID
);
1762 SetLastError( RtlNtStatusToDosError(res
) );
1770 /***********************************************************************
1773 * Retrieve a message reply from the server.
1775 static LRESULT
retrieve_reply( const struct send_message_info
*info
,
1776 size_t reply_size
, LRESULT
*result
)
1779 void *reply_data
= NULL
;
1783 if (!(reply_data
= HeapAlloc( GetProcessHeap(), 0, reply_size
)))
1785 WARN( "no memory for reply %d bytes, will be truncated\n", reply_size
);
1789 SERVER_START_REQ( get_message_reply
)
1792 if (reply_size
) wine_server_set_reply( req
, reply_data
, reply_size
);
1793 if (!(status
= wine_server_call( req
))) *result
= reply
->result
;
1794 reply_size
= wine_server_reply_size( reply
);
1797 if (!status
&& reply_size
)
1798 unpack_reply( info
->hwnd
, info
->msg
, info
->wparam
, info
->lparam
, reply_data
, reply_size
);
1800 if (reply_data
) HeapFree( GetProcessHeap(), 0, reply_data
);
1802 TRACE( "hwnd %p msg %x (%s) wp %x lp %lx got reply %lx (err=%ld)\n",
1803 info
->hwnd
, info
->msg
, SPY_GetMsgName(info
->msg
, info
->hwnd
), info
->wparam
,
1804 info
->lparam
, *result
, status
);
1806 /* MSDN states that last error is 0 on timeout, but at least NT4 returns ERROR_TIMEOUT */
1807 if (status
) SetLastError( RtlNtStatusToDosError(status
) );
1812 /***********************************************************************
1813 * send_inter_thread_message
1815 static LRESULT
send_inter_thread_message( DWORD dest_tid
, const struct send_message_info
*info
,
1820 size_t reply_size
= 0;
1822 TRACE( "hwnd %p msg %x (%s) wp %x lp %lx\n",
1823 info
->hwnd
, info
->msg
, SPY_GetMsgName(info
->msg
, info
->hwnd
), info
->wparam
, info
->lparam
);
1825 if (!put_message_in_queue( dest_tid
, info
, &reply_size
)) return 0;
1827 /* there's no reply to wait for on notify/callback messages */
1828 if (info
->type
== MSG_NOTIFY
|| info
->type
== MSG_CALLBACK
) return 1;
1830 locks
= WIN_SuspendWndsLock();
1832 wait_message_reply( info
->flags
);
1833 ret
= retrieve_reply( info
, reply_size
, res_ptr
);
1835 WIN_RestoreWndsLock( locks
);
1840 /***********************************************************************
1841 * MSG_SendInternalMessageTimeout
1843 * Same as SendMessageTimeoutW but sends the message to a specific thread
1844 * without requiring a window handle. Only works for internal Wine messages.
1846 LRESULT
MSG_SendInternalMessageTimeout( DWORD dest_pid
, DWORD dest_tid
,
1847 UINT msg
, WPARAM wparam
, LPARAM lparam
,
1848 UINT flags
, UINT timeout
, PDWORD_PTR res_ptr
)
1850 struct send_message_info info
;
1851 LRESULT ret
, result
;
1853 assert( msg
& 0x80000000 ); /* must be an internal Wine message */
1855 info
.type
= MSG_UNICODE
;
1858 info
.wparam
= wparam
;
1859 info
.lparam
= lparam
;
1861 info
.timeout
= timeout
;
1863 if (USER_IsExitingThread( dest_tid
)) return 0;
1865 if (dest_tid
== GetCurrentThreadId())
1867 result
= handle_internal_message( 0, msg
, wparam
, lparam
);
1872 if (dest_pid
!= GetCurrentProcessId()) info
.type
= MSG_OTHER_PROCESS
;
1873 ret
= send_inter_thread_message( dest_tid
, &info
, &result
);
1875 if (ret
&& res_ptr
) *res_ptr
= result
;
1880 /***********************************************************************
1881 * SendMessageTimeoutW (USER32.@)
1883 LRESULT WINAPI
SendMessageTimeoutW( HWND hwnd
, UINT msg
, WPARAM wparam
, LPARAM lparam
,
1884 UINT flags
, UINT timeout
, PDWORD_PTR res_ptr
)
1886 struct send_message_info info
;
1887 DWORD dest_tid
, dest_pid
;
1888 LRESULT ret
, result
;
1890 info
.type
= MSG_UNICODE
;
1893 info
.wparam
= wparam
;
1894 info
.lparam
= lparam
;
1896 info
.timeout
= timeout
;
1898 if (is_broadcast(hwnd
))
1900 EnumWindows( broadcast_message_callback
, (LPARAM
)&info
);
1901 if (res_ptr
) *res_ptr
= 1;
1905 if (!(dest_tid
= GetWindowThreadProcessId( hwnd
, &dest_pid
))) return 0;
1907 if (USER_IsExitingThread( dest_tid
)) return 0;
1909 SPY_EnterMessage( SPY_SENDMESSAGE
, hwnd
, msg
, wparam
, lparam
);
1911 if (dest_tid
== GetCurrentThreadId())
1913 result
= call_window_proc( hwnd
, msg
, wparam
, lparam
, TRUE
, TRUE
);
1918 if (dest_pid
!= GetCurrentProcessId()) info
.type
= MSG_OTHER_PROCESS
;
1919 ret
= send_inter_thread_message( dest_tid
, &info
, &result
);
1922 SPY_ExitMessage( SPY_RESULT_OK
, hwnd
, msg
, result
, wparam
, lparam
);
1923 if (ret
&& res_ptr
) *res_ptr
= result
;
1928 /***********************************************************************
1929 * SendMessageTimeoutA (USER32.@)
1931 LRESULT WINAPI
SendMessageTimeoutA( HWND hwnd
, UINT msg
, WPARAM wparam
, LPARAM lparam
,
1932 UINT flags
, UINT timeout
, PDWORD_PTR res_ptr
)
1934 struct send_message_info info
;
1935 DWORD dest_tid
, dest_pid
;
1936 LRESULT ret
, result
;
1938 info
.type
= MSG_ASCII
;
1941 info
.wparam
= wparam
;
1942 info
.lparam
= lparam
;
1944 info
.timeout
= timeout
;
1946 if (is_broadcast(hwnd
))
1948 EnumWindows( broadcast_message_callback
, (LPARAM
)&info
);
1949 if (res_ptr
) *res_ptr
= 1;
1953 if (!(dest_tid
= GetWindowThreadProcessId( hwnd
, &dest_pid
))) return 0;
1955 if (USER_IsExitingThread( dest_tid
)) return 0;
1957 SPY_EnterMessage( SPY_SENDMESSAGE
, hwnd
, msg
, wparam
, lparam
);
1959 if (dest_tid
== GetCurrentThreadId())
1961 result
= call_window_proc( hwnd
, msg
, wparam
, lparam
, FALSE
, TRUE
);
1964 else if (dest_pid
== GetCurrentProcessId())
1966 ret
= send_inter_thread_message( dest_tid
, &info
, &result
);
1970 /* inter-process message: need to map to Unicode */
1971 info
.type
= MSG_OTHER_PROCESS
;
1972 if (is_unicode_message( info
.msg
))
1974 if (WINPROC_MapMsg32ATo32W( info
.hwnd
, info
.msg
, &info
.wparam
, &info
.lparam
) == -1)
1976 ret
= send_inter_thread_message( dest_tid
, &info
, &result
);
1977 result
= WINPROC_UnmapMsg32ATo32W( info
.hwnd
, info
.msg
, info
.wparam
,
1978 info
.lparam
, result
);
1980 else ret
= send_inter_thread_message( dest_tid
, &info
, &result
);
1982 SPY_ExitMessage( SPY_RESULT_OK
, hwnd
, msg
, result
, wparam
, lparam
);
1983 if (ret
&& res_ptr
) *res_ptr
= result
;
1988 /***********************************************************************
1989 * SendMessageW (USER32.@)
1991 LRESULT WINAPI
SendMessageW( HWND hwnd
, UINT msg
, WPARAM wparam
, LPARAM lparam
)
1994 SendMessageTimeoutW( hwnd
, msg
, wparam
, lparam
, SMTO_NORMAL
, INFINITE
, &res
);
1999 /***********************************************************************
2000 * SendMessageA (USER32.@)
2002 LRESULT WINAPI
SendMessageA( HWND hwnd
, UINT msg
, WPARAM wparam
, LPARAM lparam
)
2005 SendMessageTimeoutA( hwnd
, msg
, wparam
, lparam
, SMTO_NORMAL
, INFINITE
, &res
);
2010 /***********************************************************************
2011 * SendNotifyMessageA (USER32.@)
2013 BOOL WINAPI
SendNotifyMessageA( HWND hwnd
, UINT msg
, WPARAM wparam
, LPARAM lparam
)
2015 return SendNotifyMessageW( hwnd
, msg
, map_wparam_AtoW( msg
, wparam
), lparam
);
2019 /***********************************************************************
2020 * SendNotifyMessageW (USER32.@)
2022 BOOL WINAPI
SendNotifyMessageW( HWND hwnd
, UINT msg
, WPARAM wparam
, LPARAM lparam
)
2024 struct send_message_info info
;
2028 if (is_pointer_message(msg
))
2030 SetLastError(ERROR_INVALID_PARAMETER
);
2034 info
.type
= MSG_NOTIFY
;
2037 info
.wparam
= wparam
;
2038 info
.lparam
= lparam
;
2041 if (is_broadcast(hwnd
))
2043 EnumWindows( broadcast_message_callback
, (LPARAM
)&info
);
2047 if (!(dest_tid
= GetWindowThreadProcessId( hwnd
, NULL
))) return FALSE
;
2049 if (USER_IsExitingThread( dest_tid
)) return TRUE
;
2051 if (dest_tid
== GetCurrentThreadId())
2053 call_window_proc( hwnd
, msg
, wparam
, lparam
, TRUE
, TRUE
);
2056 return send_inter_thread_message( dest_tid
, &info
, &result
);
2060 /***********************************************************************
2061 * SendMessageCallbackA (USER32.@)
2063 BOOL WINAPI
SendMessageCallbackA( HWND hwnd
, UINT msg
, WPARAM wparam
, LPARAM lparam
,
2064 SENDASYNCPROC callback
, ULONG_PTR data
)
2066 return SendMessageCallbackW( hwnd
, msg
, map_wparam_AtoW( msg
, wparam
),
2067 lparam
, callback
, data
);
2071 /***********************************************************************
2072 * SendMessageCallbackW (USER32.@)
2074 BOOL WINAPI
SendMessageCallbackW( HWND hwnd
, UINT msg
, WPARAM wparam
, LPARAM lparam
,
2075 SENDASYNCPROC callback
, ULONG_PTR data
)
2077 struct send_message_info info
;
2081 if (is_pointer_message(msg
))
2083 SetLastError(ERROR_INVALID_PARAMETER
);
2087 info
.type
= MSG_CALLBACK
;
2090 info
.wparam
= wparam
;
2091 info
.lparam
= lparam
;
2092 info
.callback
= callback
;
2096 if (is_broadcast(hwnd
))
2098 EnumWindows( broadcast_message_callback
, (LPARAM
)&info
);
2102 if (!(dest_tid
= GetWindowThreadProcessId( hwnd
, NULL
))) return FALSE
;
2104 if (USER_IsExitingThread( dest_tid
)) return TRUE
;
2106 if (dest_tid
== GetCurrentThreadId())
2108 result
= call_window_proc( hwnd
, msg
, wparam
, lparam
, TRUE
, TRUE
);
2109 call_sendmsg_callback( callback
, hwnd
, msg
, data
, result
);
2112 FIXME( "callback will not be called\n" );
2113 return send_inter_thread_message( dest_tid
, &info
, &result
);
2117 /***********************************************************************
2118 * ReplyMessage (USER32.@)
2120 BOOL WINAPI
ReplyMessage( LRESULT result
)
2122 MESSAGEQUEUE
*queue
= QUEUE_Current();
2123 struct received_message_info
*info
= queue
->receive_info
;
2125 if (!info
) return FALSE
;
2126 reply_message( info
, result
, FALSE
);
2131 /***********************************************************************
2132 * InSendMessage (USER32.@)
2134 BOOL WINAPI
InSendMessage(void)
2136 return (InSendMessageEx(NULL
) & (ISMEX_SEND
|ISMEX_REPLIED
)) == ISMEX_SEND
;
2140 /***********************************************************************
2141 * InSendMessageEx (USER32.@)
2143 DWORD WINAPI
InSendMessageEx( LPVOID reserved
)
2145 MESSAGEQUEUE
*queue
= QUEUE_Current();
2146 struct received_message_info
*info
= queue
->receive_info
;
2148 if (info
) return info
->flags
;
2149 return ISMEX_NOSEND
;
2153 /***********************************************************************
2154 * PostMessageA (USER32.@)
2156 BOOL WINAPI
PostMessageA( HWND hwnd
, UINT msg
, WPARAM wparam
, LPARAM lparam
)
2158 return PostMessageW( hwnd
, msg
, map_wparam_AtoW( msg
, wparam
), lparam
);
2162 /***********************************************************************
2163 * PostMessageW (USER32.@)
2165 BOOL WINAPI
PostMessageW( HWND hwnd
, UINT msg
, WPARAM wparam
, LPARAM lparam
)
2167 struct send_message_info info
;
2170 if (is_pointer_message( msg
))
2172 SetLastError( ERROR_INVALID_PARAMETER
);
2176 TRACE( "hwnd %p msg %x (%s) wp %x lp %lx\n",
2177 hwnd
, msg
, SPY_GetMsgName(msg
, hwnd
), wparam
, lparam
);
2179 info
.type
= MSG_POSTED
;
2182 info
.wparam
= wparam
;
2183 info
.lparam
= lparam
;
2186 if (is_broadcast(hwnd
))
2188 EnumWindows( broadcast_message_callback
, (LPARAM
)&info
);
2192 if (!hwnd
) return PostThreadMessageW( GetCurrentThreadId(), msg
, wparam
, lparam
);
2194 if (!(dest_tid
= GetWindowThreadProcessId( hwnd
, NULL
))) return FALSE
;
2196 if (USER_IsExitingThread( dest_tid
)) return TRUE
;
2198 return put_message_in_queue( dest_tid
, &info
, NULL
);
2202 /**********************************************************************
2203 * PostThreadMessageA (USER32.@)
2205 BOOL WINAPI
PostThreadMessageA( DWORD thread
, UINT msg
, WPARAM wparam
, LPARAM lparam
)
2207 return PostThreadMessageW( thread
, msg
, map_wparam_AtoW( msg
, wparam
), lparam
);
2211 /**********************************************************************
2212 * PostThreadMessageW (USER32.@)
2214 BOOL WINAPI
PostThreadMessageW( DWORD thread
, UINT msg
, WPARAM wparam
, LPARAM lparam
)
2216 struct send_message_info info
;
2218 if (is_pointer_message( msg
))
2220 SetLastError( ERROR_INVALID_PARAMETER
);
2223 if (USER_IsExitingThread( thread
)) return TRUE
;
2225 info
.type
= MSG_POSTED
;
2228 info
.wparam
= wparam
;
2229 info
.lparam
= lparam
;
2231 return put_message_in_queue( thread
, &info
, NULL
);
2235 /***********************************************************************
2236 * PostQuitMessage (USER32.@)
2238 void WINAPI
PostQuitMessage( INT exitCode
)
2240 PostThreadMessageW( GetCurrentThreadId(), WM_QUIT
, exitCode
, 0 );
2244 /***********************************************************************
2245 * PeekMessageW (USER32.@)
2247 BOOL WINAPI
PeekMessageW( MSG
*msg_out
, HWND hwnd
, UINT first
, UINT last
, UINT flags
)
2249 MESSAGEQUEUE
*queue
;
2253 /* check for graphics events */
2254 if (USER_Driver
.pMsgWaitForMultipleObjectsEx
)
2255 USER_Driver
.pMsgWaitForMultipleObjectsEx( 0, NULL
, 0, 0, 0 );
2257 hwnd
= WIN_GetFullHandle( hwnd
);
2258 locks
= WIN_SuspendWndsLock();
2260 if (!MSG_peek_message( &msg
, hwnd
, first
, last
,
2261 (flags
& PM_REMOVE
) ? GET_MSG_REMOVE
: 0 ))
2263 if (!(flags
& PM_NOYIELD
))
2266 ReleaseThunkLock(&count
);
2267 if (count
) RestoreThunkLock(count
);
2269 WIN_RestoreWndsLock( locks
);
2273 WIN_RestoreWndsLock( locks
);
2275 /* need to fill the window handle for WM_PAINT message */
2276 if (msg
.message
== WM_PAINT
)
2278 if (IsIconic( msg
.hwnd
) && GetClassLongA( msg
.hwnd
, GCL_HICON
))
2280 msg
.message
= WM_PAINTICON
;
2283 /* clear internal paint flag */
2284 RedrawWindow( msg
.hwnd
, NULL
, 0, RDW_NOINTERNALPAINT
| RDW_NOCHILDREN
);
2287 if ((queue
= QUEUE_Current()))
2289 queue
->GetMessageTimeVal
= msg
.time
;
2290 msg
.pt
.x
= LOWORD( queue
->GetMessagePosVal
);
2291 msg
.pt
.y
= HIWORD( queue
->GetMessagePosVal
);
2294 HOOK_CallHooks( WH_GETMESSAGE
, HC_ACTION
, flags
& PM_REMOVE
, (LPARAM
)&msg
, TRUE
);
2296 /* copy back our internal safe copy of message data to msg_out.
2297 * msg_out is a variable from the *program*, so it can't be used
2298 * internally as it can get "corrupted" by our use of SendMessage()
2299 * (back to the program) inside the message handling itself. */
2305 /***********************************************************************
2306 * PeekMessageA (USER32.@)
2308 BOOL WINAPI
PeekMessageA( MSG
*msg
, HWND hwnd
, UINT first
, UINT last
, UINT flags
)
2310 BOOL ret
= PeekMessageW( msg
, hwnd
, first
, last
, flags
);
2311 if (ret
) msg
->wParam
= map_wparam_WtoA( msg
->message
, msg
->wParam
);
2316 /***********************************************************************
2317 * GetMessageW (USER32.@)
2319 BOOL WINAPI
GetMessageW( MSG
*msg
, HWND hwnd
, UINT first
, UINT last
)
2321 MESSAGEQUEUE
*queue
= QUEUE_Current();
2324 mask
= QS_POSTMESSAGE
| QS_SENDMESSAGE
; /* Always selected */
2327 if ((first
<= WM_KEYLAST
) && (last
>= WM_KEYFIRST
)) mask
|= QS_KEY
;
2328 if ( ((first
<= WM_MOUSELAST
) && (last
>= WM_MOUSEFIRST
)) ||
2329 ((first
<= WM_NCMOUSELAST
) && (last
>= WM_NCMOUSEFIRST
)) ) mask
|= QS_MOUSE
;
2330 if ((first
<= WM_TIMER
) && (last
>= WM_TIMER
)) mask
|= QS_TIMER
;
2331 if ((first
<= WM_SYSTIMER
) && (last
>= WM_SYSTIMER
)) mask
|= QS_TIMER
;
2332 if ((first
<= WM_PAINT
) && (last
>= WM_PAINT
)) mask
|= QS_PAINT
;
2334 else mask
|= QS_MOUSE
| QS_KEY
| QS_TIMER
| QS_PAINT
;
2336 locks
= WIN_SuspendWndsLock();
2338 while (!PeekMessageW( msg
, hwnd
, first
, last
, PM_REMOVE
))
2340 /* wait until one of the bits is set */
2341 unsigned int wake_bits
= 0, changed_bits
= 0;
2344 SERVER_START_REQ( set_queue_mask
)
2346 req
->wake_mask
= QS_SENDMESSAGE
;
2347 req
->changed_mask
= mask
;
2349 if (!wine_server_call( req
))
2351 wake_bits
= reply
->wake_bits
;
2352 changed_bits
= reply
->changed_bits
;
2357 if (changed_bits
& mask
) continue;
2358 if (wake_bits
& QS_SENDMESSAGE
) continue;
2360 TRACE( "(%04x) mask=%08x, bits=%08x, changed=%08x, waiting\n",
2361 queue
->self
, mask
, wake_bits
, changed_bits
);
2363 ReleaseThunkLock( &dwlc
);
2364 if (USER_Driver
.pMsgWaitForMultipleObjectsEx
)
2365 USER_Driver
.pMsgWaitForMultipleObjectsEx( 1, &queue
->server_queue
, INFINITE
, 0, 0 );
2367 WaitForSingleObject( queue
->server_queue
, INFINITE
);
2368 if (dwlc
) RestoreThunkLock( dwlc
);
2371 WIN_RestoreWndsLock( locks
);
2373 return (msg
->message
!= WM_QUIT
);
2377 /***********************************************************************
2378 * GetMessageA (USER32.@)
2380 BOOL WINAPI
GetMessageA( MSG
*msg
, HWND hwnd
, UINT first
, UINT last
)
2382 GetMessageW( msg
, hwnd
, first
, last
);
2383 msg
->wParam
= map_wparam_WtoA( msg
->message
, msg
->wParam
);
2384 return (msg
->message
!= WM_QUIT
);
2388 /***********************************************************************
2389 * IsDialogMessage (USER32.@)
2390 * IsDialogMessageA (USER32.@)
2392 BOOL WINAPI
IsDialogMessageA( HWND hwndDlg
, LPMSG pmsg
)
2395 msg
.wParam
= map_wparam_AtoW( msg
.message
, msg
.wParam
);
2396 return IsDialogMessageW( hwndDlg
, &msg
);
2400 /***********************************************************************
2401 * SetMessageQueue (USER32.@)
2403 BOOL WINAPI
SetMessageQueue( INT size
)
2405 /* now obsolete the message queue will be expanded dynamically as necessary */
2410 /**********************************************************************
2411 * AttachThreadInput (USER32.@)
2413 * Attaches the input processing mechanism of one thread to that of
2416 BOOL WINAPI
AttachThreadInput( DWORD from
, DWORD to
, BOOL attach
)
2420 SERVER_START_REQ( attach_thread_input
)
2422 req
->tid_from
= from
;
2424 req
->attach
= attach
;
2425 ret
= !wine_server_call_err( req
);
2432 /**********************************************************************
2433 * GetGUIThreadInfo (USER32.@)
2435 BOOL WINAPI
GetGUIThreadInfo( DWORD id
, GUITHREADINFO
*info
)
2439 SERVER_START_REQ( get_thread_input
)
2442 if ((ret
= !wine_server_call_err( req
)))
2445 info
->hwndActive
= reply
->active
;
2446 info
->hwndFocus
= reply
->focus
;
2447 info
->hwndCapture
= reply
->capture
;
2448 info
->hwndMenuOwner
= reply
->menu_owner
;
2449 info
->hwndMoveSize
= reply
->move_size
;
2450 info
->hwndCaret
= reply
->caret
;
2451 info
->rcCaret
.left
= reply
->rect
.left
;
2452 info
->rcCaret
.top
= reply
->rect
.top
;
2453 info
->rcCaret
.right
= reply
->rect
.right
;
2454 info
->rcCaret
.bottom
= reply
->rect
.bottom
;
2455 if (reply
->menu_owner
) info
->flags
|= GUI_INMENUMODE
;
2456 if (reply
->move_size
) info
->flags
|= GUI_INMOVESIZE
;
2457 if (reply
->caret
) info
->flags
|= GUI_CARETBLINKING
;
2465 /**********************************************************************
2466 * GetKeyState (USER32.@)
2468 * An application calls the GetKeyState function in response to a
2469 * keyboard-input message. This function retrieves the state of the key
2470 * at the time the input message was generated.
2472 SHORT WINAPI
GetKeyState(INT vkey
)
2476 SERVER_START_REQ( get_key_state
)
2478 req
->tid
= GetCurrentThreadId();
2480 if (!wine_server_call( req
)) retval
= (signed char)reply
->state
;
2483 TRACE("key (0x%x) -> %x\n", vkey
, retval
);
2488 /**********************************************************************
2489 * GetKeyboardState (USER32.@)
2491 BOOL WINAPI
GetKeyboardState( LPBYTE state
)
2495 TRACE("(%p)\n", state
);
2497 memset( state
, 0, 256 );
2498 SERVER_START_REQ( get_key_state
)
2500 req
->tid
= GetCurrentThreadId();
2502 wine_server_set_reply( req
, state
, 256 );
2503 ret
= !wine_server_call_err( req
);
2510 /**********************************************************************
2511 * SetKeyboardState (USER32.@)
2513 BOOL WINAPI
SetKeyboardState( LPBYTE state
)
2517 TRACE("(%p)\n", state
);
2519 SERVER_START_REQ( set_key_state
)
2521 req
->tid
= GetCurrentThreadId();
2522 wine_server_add_data( req
, state
, 256 );
2523 ret
= !wine_server_call_err( req
);
2529 /******************************************************************
2530 * IsHungAppWindow (USER32.@)
2533 BOOL WINAPI
IsHungAppWindow( HWND hWnd
)
2536 return !SendMessageTimeoutA(hWnd
, WM_NULL
, 0, 0, SMTO_ABORTIFHUNG
, 5000, &dwResult
);