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"
32 #include "wine/unicode.h"
33 #include "wine/server.h"
38 #include "wine/debug.h"
40 WINE_DEFAULT_DEBUG_CHANNEL(msg
);
42 #define WM_NCMOUSEFIRST WM_NCMOUSEMOVE
43 #define WM_NCMOUSELAST WM_NCMBUTTONDBLCLK
45 #define MAX_PACK_COUNT 4
47 /* description of the data fields that need to be packed along with a sent message */
51 const void *data
[MAX_PACK_COUNT
];
52 size_t size
[MAX_PACK_COUNT
];
55 /* info about the message currently being received by the current thread */
56 struct received_message_info
58 enum message_type type
;
60 UINT flags
; /* InSendMessageEx return flags */
63 /* structure to group all parameters for sent messages of the various kinds */
64 struct send_message_info
66 enum message_type type
;
71 UINT flags
; /* flags for SendMessageTimeout */
72 UINT timeout
; /* timeout for SendMessageTimeout */
73 SENDASYNCPROC callback
; /* callback function for SendMessageCallback */
74 ULONG_PTR data
; /* callback data */
78 /* flag for messages that contain pointers */
79 /* 32 messages per entry, messages 0..31 map to bits 0..31 */
81 #define SET(msg) (1 << ((msg) & 31))
83 static const unsigned int message_pointer_flags
[] =
86 SET(WM_CREATE
) | SET(WM_SETTEXT
) | SET(WM_GETTEXT
) |
87 SET(WM_WININICHANGE
) | SET(WM_DEVMODECHANGE
),
89 SET(WM_GETMINMAXINFO
) | SET(WM_DRAWITEM
) | SET(WM_MEASUREITEM
) | SET(WM_DELETEITEM
) |
92 SET(WM_WINDOWPOSCHANGING
) | SET(WM_WINDOWPOSCHANGED
) | SET(WM_COPYDATA
) |
93 SET(WM_NOTIFY
) | SET(WM_HELP
),
95 SET(WM_STYLECHANGING
) | SET(WM_STYLECHANGED
),
97 SET(WM_NCCREATE
) | SET(WM_NCCALCSIZE
) | SET(WM_GETDLGCODE
),
99 SET(EM_GETSEL
) | SET(EM_GETRECT
) | SET(EM_SETRECT
) | SET(EM_SETRECTNP
),
101 SET(EM_REPLACESEL
) | SET(EM_GETLINE
) | SET(EM_SETTABSTOPS
),
103 SET(SBM_GETRANGE
) | SET(SBM_SETSCROLLINFO
) | SET(SBM_GETSCROLLINFO
),
109 SET(CB_GETEDITSEL
) | SET(CB_ADDSTRING
) | SET(CB_DIR
) | SET(CB_GETLBTEXT
) |
110 SET(CB_INSERTSTRING
) | SET(CB_FINDSTRING
) | SET(CB_SELECTSTRING
) |
111 SET(CB_GETDROPPEDCONTROLRECT
) | SET(CB_FINDSTRINGEXACT
),
115 SET(LB_ADDSTRING
) | SET(LB_INSERTSTRING
) | SET(LB_GETTEXT
) | SET(LB_SELECTSTRING
) |
116 SET(LB_DIR
) | SET(LB_FINDSTRING
) |
117 SET(LB_GETSELITEMS
) | SET(LB_SETTABSTOPS
) | SET(LB_ADDFILE
) | SET(LB_GETITEMRECT
),
119 SET(LB_FINDSTRINGEXACT
),
125 SET(WM_NEXTMENU
) | SET(WM_SIZING
) | SET(WM_MOVING
) | SET(WM_DEVICECHANGE
),
127 SET(WM_MDICREATE
) | SET(WM_MDIGETACTIVE
) | SET(WM_DROPOBJECT
) |
128 SET(WM_QUERYDROPOBJECT
) | SET(WM_DRAGLOOP
) | SET(WM_DRAGSELECT
) | SET(WM_DRAGMOVE
),
142 SET(WM_ASKCBFORMATNAME
)
145 /* flags for messages that contain Unicode strings */
146 static const unsigned int message_unicode_flags
[] =
149 SET(WM_CREATE
) | SET(WM_SETTEXT
) | SET(WM_GETTEXT
) | SET(WM_GETTEXTLENGTH
) |
150 SET(WM_WININICHANGE
) | SET(WM_DEVMODECHANGE
),
162 SET(EM_REPLACESEL
) | SET(EM_GETLINE
) | SET(EM_SETPASSWORDCHAR
),
166 SET(WM_CHAR
) | SET(WM_DEADCHAR
) | SET(WM_SYSCHAR
) | SET(WM_SYSDEADCHAR
),
170 SET(CB_ADDSTRING
) | SET(CB_DIR
) | SET(CB_GETLBTEXT
) | SET(CB_GETLBTEXTLEN
) |
171 SET(CB_INSERTSTRING
) | SET(CB_FINDSTRING
) | SET(CB_SELECTSTRING
) | SET(CB_FINDSTRINGEXACT
),
175 SET(LB_ADDSTRING
) | SET(LB_INSERTSTRING
) | SET(LB_GETTEXT
) | SET(LB_GETTEXTLEN
) |
176 SET(LB_SELECTSTRING
) | SET(LB_DIR
) | SET(LB_FINDSTRING
) | SET(LB_ADDFILE
),
178 SET(LB_FINDSTRINGEXACT
),
200 SET(WM_PAINTCLIPBOARD
) | SET(WM_SIZECLIPBOARD
) | SET(WM_ASKCBFORMATNAME
)
203 /* check whether a given message type includes pointers */
204 inline static int is_pointer_message( UINT message
)
206 if (message
>= 8*sizeof(message_pointer_flags
)) return FALSE
;
207 return (message_pointer_flags
[message
/ 32] & SET(message
)) != 0;
210 /* check whether a given message type contains Unicode (or ASCII) chars */
211 inline static int is_unicode_message( UINT message
)
213 if (message
>= 8*sizeof(message_unicode_flags
)) return FALSE
;
214 return (message_unicode_flags
[message
/ 32] & SET(message
)) != 0;
219 /* add a data field to a packed message */
220 inline static void push_data( struct packed_message
*data
, const void *ptr
, size_t size
)
222 data
->data
[data
->count
] = ptr
;
223 data
->size
[data
->count
] = size
;
227 /* add a string to a packed message */
228 inline static void push_string( struct packed_message
*data
, LPCWSTR str
)
230 push_data( data
, str
, (strlenW(str
) + 1) * sizeof(WCHAR
) );
233 /* retrieve a pointer to data from a packed message and increment the buffer pointer */
234 inline static void *get_data( void **buffer
, size_t size
)
237 *buffer
= (char *)*buffer
+ size
;
241 /* make sure that the buffer contains a valid null-terminated Unicode string */
242 inline static BOOL
check_string( LPCWSTR str
, size_t size
)
244 for (size
/= sizeof(WCHAR
); size
; size
--, str
++)
245 if (!*str
) return TRUE
;
249 /* make sure that there is space for 'size' bytes in buffer, growing it if needed */
250 inline static void *get_buffer_space( void **buffer
, size_t size
)
253 if (!(ret
= HeapReAlloc( GetProcessHeap(), 0, *buffer
, size
)))
254 HeapFree( GetProcessHeap(), 0, *buffer
);
259 /* retrieve a string pointer from packed data */
260 inline static LPWSTR
get_string( void **buffer
)
262 return get_data( buffer
, (strlenW( (LPWSTR
)*buffer
) + 1) * sizeof(WCHAR
) );
265 /* check whether a combobox expects strings or ids in CB_ADDSTRING/CB_INSERTSTRING */
266 inline static BOOL
combobox_has_strings( HWND hwnd
)
268 DWORD style
= GetWindowLongA( hwnd
, GWL_STYLE
);
269 return (!(style
& (CBS_OWNERDRAWFIXED
| CBS_OWNERDRAWVARIABLE
)) || (style
& CBS_HASSTRINGS
));
272 /* check whether a listbox expects strings or ids in LB_ADDSTRING/LB_INSERTSTRING */
273 inline static BOOL
listbox_has_strings( HWND hwnd
)
275 DWORD style
= GetWindowLongA( hwnd
, GWL_STYLE
);
276 return (!(style
& (LBS_OWNERDRAWFIXED
| LBS_OWNERDRAWVARIABLE
)) || (style
& LBS_HASSTRINGS
));
280 /***********************************************************************
281 * broadcast_message_callback
283 * Helper callback for broadcasting messages.
285 static BOOL CALLBACK
broadcast_message_callback( HWND hwnd
, LPARAM lparam
)
287 struct send_message_info
*info
= (struct send_message_info
*)lparam
;
288 if (!(GetWindowLongW( hwnd
, GWL_STYLE
) & (WS_POPUP
|WS_CAPTION
))) return TRUE
;
292 SendMessageTimeoutW( hwnd
, info
->msg
, info
->wparam
, info
->lparam
,
293 info
->flags
, info
->timeout
, NULL
);
296 SendMessageTimeoutA( hwnd
, info
->msg
, info
->wparam
, info
->lparam
,
297 info
->flags
, info
->timeout
, NULL
);
300 SendNotifyMessageW( hwnd
, info
->msg
, info
->wparam
, info
->lparam
);
303 SendMessageCallbackW( hwnd
, info
->msg
, info
->wparam
, info
->lparam
,
304 info
->callback
, info
->data
);
307 PostMessageW( hwnd
, info
->msg
, info
->wparam
, info
->lparam
);
310 ERR( "bad type %d\n", info
->type
);
317 /***********************************************************************
320 * Convert the wparam of an ASCII message to Unicode.
322 static WPARAM
map_wparam_AtoW( UINT message
, WPARAM wparam
)
327 case EM_SETPASSWORDCHAR
:
334 char ch
= LOWORD(wparam
);
336 MultiByteToWideChar(CP_ACP
, 0, &ch
, 1, &wch
, 1);
337 wparam
= MAKEWPARAM( wch
, HIWORD(wparam
) );
344 ch
[0] = (wparam
>> 8);
345 ch
[1] = (wparam
& 0xff);
346 MultiByteToWideChar(CP_ACP
, 0, ch
, 2, &wch
, 1);
347 wparam
= MAKEWPARAM( wch
, HIWORD(wparam
) );
355 /***********************************************************************
358 * Convert the wparam of a Unicode message to ASCII.
360 static WPARAM
map_wparam_WtoA( UINT message
, WPARAM wparam
)
365 case EM_SETPASSWORDCHAR
:
372 WCHAR wch
= LOWORD(wparam
);
374 WideCharToMultiByte( CP_ACP
, 0, &wch
, 1, &ch
, 1, NULL
, NULL
);
375 wparam
= MAKEWPARAM( ch
, HIWORD(wparam
) );
380 WCHAR wch
= LOWORD(wparam
);
384 WideCharToMultiByte( CP_ACP
, 0, &wch
, 1, ch
, 2, NULL
, NULL
);
385 wparam
= MAKEWPARAM( (ch
[0] << 8) | ch
[1], HIWORD(wparam
) );
393 /***********************************************************************
396 * Pack a message for sending to another process.
397 * Return the size of the data we expect in the message reply.
398 * Set data->count to -1 if there is an error.
400 static size_t pack_message( HWND hwnd
, UINT message
, WPARAM wparam
, LPARAM lparam
,
401 struct packed_message
*data
)
409 CREATESTRUCTW
*cs
= (CREATESTRUCTW
*)lparam
;
410 push_data( data
, cs
, sizeof(*cs
) );
411 if (HIWORD(cs
->lpszName
)) push_string( data
, cs
->lpszName
);
412 if (HIWORD(cs
->lpszClass
)) push_string( data
, cs
->lpszClass
);
416 case WM_ASKCBFORMATNAME
:
417 return wparam
* sizeof(WCHAR
);
418 case WM_WININICHANGE
:
419 if (lparam
) push_string(data
, (LPWSTR
)lparam
);
422 case WM_DEVMODECHANGE
:
427 push_string( data
, (LPWSTR
)lparam
);
429 case WM_GETMINMAXINFO
:
430 push_data( data
, (MINMAXINFO
*)lparam
, sizeof(MINMAXINFO
) );
431 return sizeof(MINMAXINFO
);
433 push_data( data
, (DRAWITEMSTRUCT
*)lparam
, sizeof(DRAWITEMSTRUCT
) );
436 push_data( data
, (MEASUREITEMSTRUCT
*)lparam
, sizeof(MEASUREITEMSTRUCT
) );
437 return sizeof(MEASUREITEMSTRUCT
);
439 push_data( data
, (DELETEITEMSTRUCT
*)lparam
, sizeof(DELETEITEMSTRUCT
) );
442 push_data( data
, (COMPAREITEMSTRUCT
*)lparam
, sizeof(COMPAREITEMSTRUCT
) );
444 case WM_WINDOWPOSCHANGING
:
445 case WM_WINDOWPOSCHANGED
:
446 push_data( data
, (WINDOWPOS
*)lparam
, sizeof(WINDOWPOS
) );
447 return sizeof(WINDOWPOS
);
450 COPYDATASTRUCT
*cp
= (COPYDATASTRUCT
*)lparam
;
451 push_data( data
, cp
, sizeof(*cp
) );
452 if (cp
->lpData
) push_data( data
, cp
->lpData
, cp
->cbData
);
456 /* WM_NOTIFY cannot be sent across processes (MSDN) */
460 push_data( data
, (HELPINFO
*)lparam
, sizeof(HELPINFO
) );
462 case WM_STYLECHANGING
:
463 case WM_STYLECHANGED
:
464 push_data( data
, (STYLESTRUCT
*)lparam
, sizeof(STYLESTRUCT
) );
469 push_data( data
, (RECT
*)lparam
, sizeof(RECT
) );
474 NCCALCSIZE_PARAMS
*nc
= (NCCALCSIZE_PARAMS
*)lparam
;
475 push_data( data
, nc
, sizeof(*nc
) );
476 push_data( data
, nc
->lppos
, sizeof(*nc
->lppos
) );
477 return sizeof(*nc
) + sizeof(*nc
->lppos
);
480 if (lparam
) push_data( data
, (MSG
*)lparam
, sizeof(MSG
) );
482 case SBM_SETSCROLLINFO
:
483 push_data( data
, (SCROLLINFO
*)lparam
, sizeof(SCROLLINFO
) );
485 case SBM_GETSCROLLINFO
:
486 push_data( data
, (SCROLLINFO
*)lparam
, sizeof(SCROLLINFO
) );
487 return sizeof(SCROLLINFO
);
493 if (wparam
) size
+= sizeof(DWORD
);
494 if (lparam
) size
+= sizeof(DWORD
);
499 case CB_GETDROPPEDCONTROLRECT
:
503 push_data( data
, (RECT
*)lparam
, sizeof(RECT
) );
507 WORD
*pw
= (WORD
*)lparam
;
508 push_data( data
, pw
, sizeof(*pw
) );
509 return *pw
* sizeof(WCHAR
);
513 if (wparam
) push_data( data
, (UINT
*)lparam
, sizeof(UINT
) * wparam
);
516 case CB_INSERTSTRING
:
518 case CB_FINDSTRINGEXACT
:
519 case CB_SELECTSTRING
:
520 if (combobox_has_strings( hwnd
)) push_string( data
, (LPWSTR
)lparam
);
523 if (!combobox_has_strings( hwnd
)) return sizeof(ULONG_PTR
);
524 return (SendMessageW( hwnd
, CB_GETLBTEXTLEN
, wparam
, 0 ) + 1) * sizeof(WCHAR
);
526 case LB_INSERTSTRING
:
528 case LB_FINDSTRINGEXACT
:
529 case LB_SELECTSTRING
:
530 if (listbox_has_strings( hwnd
)) push_string( data
, (LPWSTR
)lparam
);
533 if (!listbox_has_strings( hwnd
)) return sizeof(ULONG_PTR
);
534 return (SendMessageW( hwnd
, LB_GETTEXTLEN
, wparam
, 0 ) + 1) * sizeof(WCHAR
);
536 return wparam
* sizeof(UINT
);
538 push_data( data
, (MDINEXTMENU
*)lparam
, sizeof(MDINEXTMENU
) );
539 return sizeof(MDINEXTMENU
);
542 push_data( data
, (RECT
*)lparam
, sizeof(RECT
) );
546 MDICREATESTRUCTW
*cs
= (MDICREATESTRUCTW
*)lparam
;
547 push_data( data
, cs
, sizeof(*cs
) );
548 if (HIWORD(cs
->szTitle
)) push_string( data
, cs
->szTitle
);
549 if (HIWORD(cs
->szClass
)) push_string( data
, cs
->szClass
);
552 case WM_MDIGETACTIVE
:
553 if (lparam
) return sizeof(BOOL
);
555 case WM_WINE_SETWINDOWPOS
:
556 push_data( data
, (WINDOWPOS
*)lparam
, sizeof(WINDOWPOS
) );
558 case WM_WINE_KEYBOARD_LL_HOOK
:
559 push_data( data
, (KBDLLHOOKSTRUCT
*)lparam
, sizeof(KBDLLHOOKSTRUCT
) );
561 case WM_WINE_MOUSE_LL_HOOK
:
562 push_data( data
, (MSLLHOOKSTRUCT
*)lparam
, sizeof(MSLLHOOKSTRUCT
) );
565 /* these contain an HFONT */
568 /* these contain an HDC */
571 case WM_ICONERASEBKGND
:
573 case WM_CTLCOLORMSGBOX
:
574 case WM_CTLCOLOREDIT
:
575 case WM_CTLCOLORLISTBOX
:
578 case WM_CTLCOLORSCROLLBAR
:
579 case WM_CTLCOLORSTATIC
:
582 /* these contain an HGLOBAL */
583 case WM_PAINTCLIPBOARD
:
584 case WM_SIZECLIPBOARD
:
585 /* these contain pointers */
587 case WM_QUERYDROPOBJECT
:
591 case WM_DEVICECHANGE
:
592 FIXME( "msg %x (%s) not supported yet\n", message
, SPY_GetMsgName(message
, hwnd
) );
600 /***********************************************************************
603 * Unpack a message received from another process.
605 static BOOL
unpack_message( HWND hwnd
, UINT message
, WPARAM
*wparam
, LPARAM
*lparam
,
606 void **buffer
, size_t size
)
615 CREATESTRUCTW
*cs
= *buffer
;
616 WCHAR
*str
= (WCHAR
*)(cs
+ 1);
617 if (size
< sizeof(*cs
)) return FALSE
;
619 if (HIWORD(cs
->lpszName
))
621 if (!check_string( str
, size
)) return FALSE
;
623 size
-= (strlenW(str
) + 1) * sizeof(WCHAR
);
624 str
+= strlenW(str
) + 1;
626 if (HIWORD(cs
->lpszClass
))
628 if (!check_string( str
, size
)) return FALSE
;
634 case WM_ASKCBFORMATNAME
:
635 if (!get_buffer_space( buffer
, (*wparam
* sizeof(WCHAR
)) )) return FALSE
;
637 case WM_WININICHANGE
:
638 if (!*lparam
) return TRUE
;
641 case WM_DEVMODECHANGE
:
646 if (!check_string( *buffer
, size
)) return FALSE
;
648 case WM_GETMINMAXINFO
:
649 minsize
= sizeof(MINMAXINFO
);
652 minsize
= sizeof(DRAWITEMSTRUCT
);
655 minsize
= sizeof(MEASUREITEMSTRUCT
);
658 minsize
= sizeof(DELETEITEMSTRUCT
);
661 minsize
= sizeof(COMPAREITEMSTRUCT
);
663 case WM_WINDOWPOSCHANGING
:
664 case WM_WINDOWPOSCHANGED
:
665 case WM_WINE_SETWINDOWPOS
:
666 minsize
= sizeof(WINDOWPOS
);
670 COPYDATASTRUCT
*cp
= *buffer
;
671 if (size
< sizeof(*cp
)) return FALSE
;
674 minsize
= sizeof(*cp
) + cp
->cbData
;
680 /* WM_NOTIFY cannot be sent across processes (MSDN) */
683 minsize
= sizeof(HELPINFO
);
685 case WM_STYLECHANGING
:
686 case WM_STYLECHANGED
:
687 minsize
= sizeof(STYLESTRUCT
);
690 if (!*wparam
) minsize
= sizeof(RECT
);
693 NCCALCSIZE_PARAMS
*nc
= *buffer
;
694 if (size
< sizeof(*nc
) + sizeof(*nc
->lppos
)) return FALSE
;
695 nc
->lppos
= (WINDOWPOS
*)(nc
+ 1);
699 if (!*lparam
) return TRUE
;
700 minsize
= sizeof(MSG
);
702 case SBM_SETSCROLLINFO
:
703 minsize
= sizeof(SCROLLINFO
);
705 case SBM_GETSCROLLINFO
:
706 if (!get_buffer_space( buffer
, sizeof(SCROLLINFO
))) return FALSE
;
711 if (*wparam
|| *lparam
)
713 if (!get_buffer_space( buffer
, 2*sizeof(DWORD
) )) return FALSE
;
714 if (*wparam
) *wparam
= (WPARAM
)*buffer
;
715 if (*lparam
) *lparam
= (LPARAM
)((DWORD
*)*buffer
+ 1);
720 case CB_GETDROPPEDCONTROLRECT
:
721 if (!get_buffer_space( buffer
, sizeof(RECT
) )) return FALSE
;
725 minsize
= sizeof(RECT
);
730 if (size
< sizeof(WORD
)) return FALSE
;
731 len
= *(WORD
*)*buffer
;
732 if (!get_buffer_space( buffer
, (len
+ 1) * sizeof(WCHAR
) )) return FALSE
;
733 *lparam
= (LPARAM
)*buffer
+ sizeof(WORD
); /* don't erase WORD at start of buffer */
738 if (!*wparam
) return TRUE
;
739 minsize
= *wparam
* sizeof(UINT
);
742 case CB_INSERTSTRING
:
744 case CB_FINDSTRINGEXACT
:
745 case CB_SELECTSTRING
:
747 case LB_INSERTSTRING
:
749 case LB_FINDSTRINGEXACT
:
750 case LB_SELECTSTRING
:
751 if (!*buffer
) return TRUE
;
752 if (!check_string( *buffer
, size
)) return FALSE
;
756 size
= sizeof(ULONG_PTR
);
757 if (combobox_has_strings( hwnd
))
758 size
= (SendMessageW( hwnd
, CB_GETLBTEXTLEN
, *wparam
, 0 ) + 1) * sizeof(WCHAR
);
759 if (!get_buffer_space( buffer
, size
)) return FALSE
;
764 size
= sizeof(ULONG_PTR
);
765 if (listbox_has_strings( hwnd
))
766 size
= (SendMessageW( hwnd
, LB_GETTEXTLEN
, *wparam
, 0 ) + 1) * sizeof(WCHAR
);
767 if (!get_buffer_space( buffer
, size
)) return FALSE
;
771 if (!get_buffer_space( buffer
, *wparam
* sizeof(UINT
) )) return FALSE
;
774 minsize
= sizeof(MDINEXTMENU
);
775 if (!get_buffer_space( buffer
, sizeof(MDINEXTMENU
) )) return FALSE
;
779 minsize
= sizeof(RECT
);
780 if (!get_buffer_space( buffer
, sizeof(RECT
) )) return FALSE
;
784 MDICREATESTRUCTW
*cs
= *buffer
;
785 WCHAR
*str
= (WCHAR
*)(cs
+ 1);
786 if (size
< sizeof(*cs
)) return FALSE
;
788 if (HIWORD(cs
->szTitle
))
790 if (!check_string( str
, size
)) return FALSE
;
792 size
-= (strlenW(str
) + 1) * sizeof(WCHAR
);
793 str
+= strlenW(str
) + 1;
795 if (HIWORD(cs
->szClass
))
797 if (!check_string( str
, size
)) return FALSE
;
802 case WM_MDIGETACTIVE
:
803 if (!*lparam
) return TRUE
;
804 if (!get_buffer_space( buffer
, sizeof(BOOL
) )) return FALSE
;
806 case WM_WINE_KEYBOARD_LL_HOOK
:
807 minsize
= sizeof(KBDLLHOOKSTRUCT
);
809 case WM_WINE_MOUSE_LL_HOOK
:
810 minsize
= sizeof(MSLLHOOKSTRUCT
);
813 /* these contain an HFONT */
816 /* these contain an HDC */
819 case WM_ICONERASEBKGND
:
821 case WM_CTLCOLORMSGBOX
:
822 case WM_CTLCOLOREDIT
:
823 case WM_CTLCOLORLISTBOX
:
826 case WM_CTLCOLORSCROLLBAR
:
827 case WM_CTLCOLORSTATIC
:
830 /* these contain an HGLOBAL */
831 case WM_PAINTCLIPBOARD
:
832 case WM_SIZECLIPBOARD
:
833 /* these contain pointers */
835 case WM_QUERYDROPOBJECT
:
839 case WM_DEVICECHANGE
:
840 FIXME( "msg %x (%s) not supported yet\n", message
, SPY_GetMsgName(message
, hwnd
) );
844 return TRUE
; /* message doesn't need any unpacking */
847 /* default exit for most messages: check minsize and store buffer in lparam */
848 if (size
< minsize
) return FALSE
;
849 *lparam
= (LPARAM
)*buffer
;
854 /***********************************************************************
857 * Pack a reply to a message for sending to another process.
859 static void pack_reply( HWND hwnd
, UINT message
, WPARAM wparam
, LPARAM lparam
,
860 LRESULT res
, struct packed_message
*data
)
867 push_data( data
, (CREATESTRUCTW
*)lparam
, sizeof(CREATESTRUCTW
) );
872 push_data( data
, (WCHAR
*)lparam
, (res
+ 1) * sizeof(WCHAR
) );
874 case WM_GETMINMAXINFO
:
875 push_data( data
, (MINMAXINFO
*)lparam
, sizeof(MINMAXINFO
) );
878 push_data( data
, (MEASUREITEMSTRUCT
*)lparam
, sizeof(MEASUREITEMSTRUCT
) );
880 case WM_WINDOWPOSCHANGING
:
881 case WM_WINDOWPOSCHANGED
:
882 push_data( data
, (WINDOWPOS
*)lparam
, sizeof(WINDOWPOS
) );
885 if (lparam
) push_data( data
, (MSG
*)lparam
, sizeof(MSG
) );
887 case SBM_GETSCROLLINFO
:
888 push_data( data
, (SCROLLINFO
*)lparam
, sizeof(SCROLLINFO
) );
892 case CB_GETDROPPEDCONTROLRECT
:
895 push_data( data
, (RECT
*)lparam
, sizeof(RECT
) );
899 WORD
*ptr
= (WORD
*)lparam
;
900 push_data( data
, ptr
, ptr
[-1] * sizeof(WCHAR
) );
904 push_data( data
, (UINT
*)lparam
, wparam
* sizeof(UINT
) );
906 case WM_MDIGETACTIVE
:
907 if (lparam
) push_data( data
, (BOOL
*)lparam
, sizeof(BOOL
) );
911 push_data( data
, (RECT
*)lparam
, sizeof(RECT
) );
914 NCCALCSIZE_PARAMS
*nc
= (NCCALCSIZE_PARAMS
*)lparam
;
915 push_data( data
, nc
, sizeof(*nc
) );
916 push_data( data
, nc
->lppos
, sizeof(*nc
->lppos
) );
922 if (wparam
) push_data( data
, (DWORD
*)wparam
, sizeof(DWORD
) );
923 if (lparam
) push_data( data
, (DWORD
*)lparam
, sizeof(DWORD
) );
926 push_data( data
, (MDINEXTMENU
*)lparam
, sizeof(MDINEXTMENU
) );
929 push_data( data
, (MDICREATESTRUCTW
*)lparam
, sizeof(MDICREATESTRUCTW
) );
931 case WM_ASKCBFORMATNAME
:
932 push_data( data
, (WCHAR
*)lparam
, (strlenW((WCHAR
*)lparam
) + 1) * sizeof(WCHAR
) );
938 /***********************************************************************
941 * Unpack a message reply received from another process.
943 static void unpack_reply( HWND hwnd
, UINT message
, WPARAM wparam
, LPARAM lparam
,
944 void *buffer
, size_t size
)
951 CREATESTRUCTW
*cs
= (CREATESTRUCTW
*)lparam
;
952 LPCWSTR name
= cs
->lpszName
, class = cs
->lpszClass
;
953 memcpy( cs
, buffer
, min( sizeof(*cs
), size
));
954 cs
->lpszName
= name
; /* restore the original pointers */
955 cs
->lpszClass
= class;
959 case WM_ASKCBFORMATNAME
:
960 memcpy( (WCHAR
*)lparam
, buffer
, min( wparam
*sizeof(WCHAR
), size
));
962 case WM_GETMINMAXINFO
:
963 memcpy( (MINMAXINFO
*)lparam
, buffer
, min( sizeof(MINMAXINFO
), size
));
966 memcpy( (MEASUREITEMSTRUCT
*)lparam
, buffer
, min( sizeof(MEASUREITEMSTRUCT
), size
));
968 case WM_WINDOWPOSCHANGING
:
969 case WM_WINDOWPOSCHANGED
:
970 memcpy( (WINDOWPOS
*)lparam
, buffer
, min( sizeof(WINDOWPOS
), size
));
973 if (lparam
) memcpy( (MSG
*)lparam
, buffer
, min( sizeof(MSG
), size
));
975 case SBM_GETSCROLLINFO
:
976 memcpy( (SCROLLINFO
*)lparam
, buffer
, min( sizeof(SCROLLINFO
), size
));
979 case CB_GETDROPPEDCONTROLRECT
:
983 memcpy( (RECT
*)lparam
, buffer
, min( sizeof(RECT
), size
));
986 size
= min( size
, (size_t)*(WORD
*)lparam
);
987 memcpy( (WCHAR
*)lparam
, buffer
, size
);
990 memcpy( (UINT
*)lparam
, buffer
, min( wparam
*sizeof(UINT
), size
));
994 memcpy( (WCHAR
*)lparam
, buffer
, size
);
997 memcpy( (MDINEXTMENU
*)lparam
, buffer
, min( sizeof(MDINEXTMENU
), size
));
999 case WM_MDIGETACTIVE
:
1000 if (lparam
) memcpy( (BOOL
*)lparam
, buffer
, min( sizeof(BOOL
), size
));
1004 memcpy( (RECT
*)lparam
, buffer
, min( sizeof(RECT
), size
));
1007 NCCALCSIZE_PARAMS
*nc
= (NCCALCSIZE_PARAMS
*)lparam
;
1008 WINDOWPOS
*wp
= nc
->lppos
;
1009 memcpy( nc
, buffer
, min( sizeof(*nc
), size
));
1010 if (size
> sizeof(*nc
))
1012 size
-= sizeof(*nc
);
1013 memcpy( wp
, (NCCALCSIZE_PARAMS
*)buffer
+ 1, min( sizeof(*wp
), size
));
1015 nc
->lppos
= wp
; /* restore the original pointer */
1023 memcpy( (DWORD
*)wparam
, buffer
, min( sizeof(DWORD
), size
));
1024 if (size
<= sizeof(DWORD
)) break;
1025 size
-= sizeof(DWORD
);
1026 buffer
= (DWORD
*)buffer
+ 1;
1028 if (lparam
) memcpy( (DWORD
*)lparam
, buffer
, min( sizeof(DWORD
), size
));
1032 MDICREATESTRUCTW
*cs
= (MDICREATESTRUCTW
*)lparam
;
1033 LPCWSTR title
= cs
->szTitle
, class = cs
->szClass
;
1034 memcpy( cs
, buffer
, min( sizeof(*cs
), size
));
1035 cs
->szTitle
= title
; /* restore the original pointers */
1036 cs
->szClass
= class;
1040 ERR( "should not happen: unexpected message %x\n", message
);
1046 /***********************************************************************
1049 * Send a reply to a sent message.
1051 static void reply_message( struct received_message_info
*info
, LRESULT result
, BOOL remove
)
1053 struct packed_message data
;
1054 int i
, replied
= info
->flags
& ISMEX_REPLIED
;
1056 if (info
->flags
& ISMEX_NOTIFY
) return; /* notify messages don't get replies */
1057 if (!remove
&& replied
) return; /* replied already */
1060 info
->flags
|= ISMEX_REPLIED
;
1062 if (info
->type
== MSG_OTHER_PROCESS
&& !replied
)
1064 pack_reply( info
->msg
.hwnd
, info
->msg
.message
, info
->msg
.wParam
,
1065 info
->msg
.lParam
, result
, &data
);
1068 SERVER_START_REQ( reply_message
)
1070 req
->type
= info
->type
;
1071 req
->result
= result
;
1072 req
->remove
= remove
;
1073 for (i
= 0; i
< data
.count
; i
++) wine_server_add_data( req
, data
.data
[i
], data
.size
[i
] );
1074 wine_server_call( req
);
1080 /***********************************************************************
1081 * handle_internal_message
1083 * Handle an internal Wine message instead of calling the window proc.
1085 static LRESULT
handle_internal_message( HWND hwnd
, UINT msg
, WPARAM wparam
, LPARAM lparam
)
1087 if (hwnd
== GetDesktopWindow()) return 0;
1090 case WM_WINE_DESTROYWINDOW
:
1091 return WIN_DestroyWindow( hwnd
);
1092 case WM_WINE_SETWINDOWPOS
:
1093 return USER_Driver
.pSetWindowPos( (WINDOWPOS
*)lparam
);
1094 case WM_WINE_SHOWWINDOW
:
1095 return ShowWindow( hwnd
, wparam
);
1096 case WM_WINE_SETPARENT
:
1097 return (LRESULT
)SetParent( hwnd
, (HWND
)wparam
);
1098 case WM_WINE_SETWINDOWLONG
:
1099 return (LRESULT
)SetWindowLongW( hwnd
, wparam
, lparam
);
1100 case WM_WINE_ENABLEWINDOW
:
1101 return EnableWindow( hwnd
, wparam
);
1102 case WM_WINE_SETACTIVEWINDOW
:
1103 return (LRESULT
)SetActiveWindow( (HWND
)wparam
);
1104 case WM_WINE_KEYBOARD_LL_HOOK
:
1105 return HOOK_CallHooks( WH_KEYBOARD_LL
, HC_ACTION
, wparam
, lparam
, TRUE
);
1106 case WM_WINE_MOUSE_LL_HOOK
:
1107 return HOOK_CallHooks( WH_MOUSE_LL
, HC_ACTION
, wparam
, lparam
, TRUE
);
1109 FIXME( "unknown internal message %x\n", msg
);
1114 /* since the WM_DDE_ACK response to a WM_DDE_EXECUTE message should contain the handle
1115 * to the memory handle, we keep track (in the server side) of all pairs of handle
1116 * used (the client passes its value and the content of the memory handle), and
1117 * the server stored both values (the client, and the local one, created after the
1118 * content). When a ACK message is generated, the list of pair is searched for a
1119 * matching pair, so that the client memory handle can be returned.
1122 HGLOBAL client_hMem
;
1123 HGLOBAL server_hMem
;
1126 static struct DDE_pair
* dde_pairs
;
1127 static int dde_num_alloc
;
1128 static int dde_num_used
;
1129 static CRITICAL_SECTION dde_crst
= CRITICAL_SECTION_INIT("Raw_DDE_CritSect");
1131 static BOOL
dde_add_pair(HGLOBAL chm
, HGLOBAL shm
)
1136 EnterCriticalSection(&dde_crst
);
1138 /* now remember the pair of hMem on both sides */
1139 if (dde_num_used
== dde_num_alloc
)
1141 struct DDE_pair
* tmp
= HeapReAlloc( GetProcessHeap(), 0, dde_pairs
,
1142 (dde_num_alloc
+ GROWBY
) * sizeof(struct DDE_pair
));
1145 LeaveCriticalSection(&dde_crst
);
1149 /* zero out newly allocated part */
1150 memset(&dde_pairs
[dde_num_alloc
], 0, GROWBY
* sizeof(struct DDE_pair
));
1151 dde_num_alloc
+= GROWBY
;
1154 for (i
= 0; i
< dde_num_alloc
; i
++)
1156 if (dde_pairs
[i
].server_hMem
== 0)
1158 dde_pairs
[i
].client_hMem
= chm
;
1159 dde_pairs
[i
].server_hMem
= shm
;
1164 LeaveCriticalSection(&dde_crst
);
1168 static HGLOBAL
dde_get_pair(HGLOBAL shm
)
1173 EnterCriticalSection(&dde_crst
);
1174 for (i
= 0; i
< dde_num_alloc
; i
++)
1176 if (dde_pairs
[i
].server_hMem
== shm
)
1178 /* free this pair */
1179 dde_pairs
[i
].server_hMem
= 0;
1181 ret
= dde_pairs
[i
].client_hMem
;
1185 LeaveCriticalSection(&dde_crst
);
1189 /***********************************************************************
1192 * Post a DDE message
1194 static BOOL
post_dde_message( DWORD dest_tid
, struct packed_message
*data
, const struct send_message_info
*info
)
1200 HGLOBAL hunlock
= 0;
1204 if (!UnpackDDElParam( info
->msg
, info
->lparam
, &uiLo
, &uiHi
))
1210 /* DDE messages which don't require packing are:
1219 /* uiHi should contain a hMem from WM_DDE_EXECUTE */
1220 HGLOBAL h
= dde_get_pair( (HANDLE
)uiHi
);
1223 /* send back the value of h on the other side */
1224 push_data( data
, &h
, sizeof(HGLOBAL
) );
1226 TRACE( "send dde-ack %x %08x => %08lx\n", uiLo
, uiHi
, (DWORD
)h
);
1231 /* uiHi should contain either an atom or 0 */
1232 TRACE( "send dde-ack %x atom=%x\n", uiLo
, uiHi
);
1233 lp
= MAKELONG( uiLo
, uiHi
);
1242 size
= GlobalSize( (HGLOBAL
)uiLo
) ;
1243 if ((info
->msg
== WM_DDE_ADVISE
&& size
< sizeof(DDEADVISE
)) ||
1244 (info
->msg
== WM_DDE_DATA
&& size
< sizeof(DDEDATA
)) ||
1245 (info
->msg
== WM_DDE_POKE
&& size
< sizeof(DDEPOKE
))
1249 else if (info
->msg
!= WM_DDE_DATA
) return FALSE
;
1254 if ((ptr
= GlobalLock( (HGLOBAL
)uiLo
) ))
1256 DDEDATA
*dde_data
= (DDEDATA
*)ptr
;
1257 TRACE("unused %d, fResponse %d, fRelease %d, fDeferUpd %d, fAckReq %d, cfFormat %d\n",
1258 dde_data
->unused
, dde_data
->fResponse
, dde_data
->fRelease
,
1259 dde_data
->reserved
, dde_data
->fAckReq
, dde_data
->cfFormat
);
1260 push_data( data
, ptr
, size
);
1261 hunlock
= (HGLOBAL
)uiLo
;
1264 TRACE( "send ddepack %u %x\n", size
, uiHi
);
1266 case WM_DDE_EXECUTE
:
1269 if ((ptr
= GlobalLock( (HGLOBAL
)info
->lparam
) ))
1271 push_data(data
, ptr
, GlobalSize( (HGLOBAL
)info
->lparam
));
1272 /* so that the other side can send it back on ACK */
1274 hunlock
= (HGLOBAL
)info
->lparam
;
1279 SERVER_START_REQ( send_message
)
1282 req
->type
= info
->type
;
1284 req
->win
= info
->hwnd
;
1285 req
->msg
= info
->msg
;
1286 req
->wparam
= info
->wparam
;
1288 req
->time
= GetCurrentTime();
1290 for (i
= 0; i
< data
->count
; i
++)
1291 wine_server_add_data( req
, data
->data
[i
], data
->size
[i
] );
1292 if ((res
= wine_server_call( req
)))
1294 if (res
== STATUS_INVALID_PARAMETER
)
1295 /* FIXME: find a STATUS_ value for this one */
1296 SetLastError( ERROR_INVALID_THREAD_ID
);
1298 SetLastError( RtlNtStatusToDosError(res
) );
1301 FreeDDElParam(info
->msg
, info
->lparam
);
1304 if (hunlock
) GlobalUnlock(hunlock
);
1309 /***********************************************************************
1310 * unpack_dde_message
1312 * Unpack a posted DDE message received from another process.
1314 static BOOL
unpack_dde_message( HWND hwnd
, UINT message
, WPARAM
*wparam
, LPARAM
*lparam
,
1315 void **buffer
, size_t size
)
1326 /* hMem is being passed */
1327 if (size
!= sizeof(HGLOBAL
)) return FALSE
;
1328 if (!buffer
|| !*buffer
) return FALSE
;
1330 memcpy( &hMem
, *buffer
, size
);
1332 TRACE("recv dde-ack %x mem=%x[%lx]\n", uiLo
, uiHi
, GlobalSize( hMem
));
1336 uiLo
= LOWORD( *lparam
);
1337 uiHi
= HIWORD( *lparam
);
1338 TRACE("recv dde-ack %x atom=%x\n", uiLo
, uiHi
);
1340 *lparam
= PackDDElParam( WM_DDE_ACK
, uiLo
, uiHi
);
1345 if ((!buffer
|| !*buffer
) && message
!= WM_DDE_DATA
) return FALSE
;
1347 TRACE( "recv ddepack %u %x\n", size
, uiHi
);
1350 hMem
= GlobalAlloc( GMEM_MOVEABLE
|GMEM_DDESHARE
, size
);
1351 if (hMem
&& (ptr
= GlobalLock( hMem
)))
1353 memcpy( ptr
, *buffer
, size
);
1354 GlobalUnlock( hMem
);
1360 *lparam
= PackDDElParam( message
, uiLo
, uiHi
);
1362 case WM_DDE_EXECUTE
:
1365 if (!buffer
|| !*buffer
) return FALSE
;
1366 hMem
= GlobalAlloc( GMEM_MOVEABLE
|GMEM_DDESHARE
, size
);
1367 if (hMem
&& (ptr
= GlobalLock( hMem
)))
1369 memcpy( ptr
, *buffer
, size
);
1370 GlobalUnlock( hMem
);
1371 TRACE( "exec: pairing c=%08lx s=%08lx\n", *lparam
, (DWORD
)hMem
);
1372 if (!dde_add_pair( (HGLOBAL
)*lparam
, hMem
))
1378 } else return FALSE
;
1379 *lparam
= (LPARAM
)hMem
;
1385 /***********************************************************************
1388 * Call a window procedure and the corresponding hooks.
1390 static LRESULT
call_window_proc( HWND hwnd
, UINT msg
, WPARAM wparam
, LPARAM lparam
,
1391 BOOL unicode
, BOOL same_thread
)
1396 CWPRETSTRUCT cwpret
;
1397 MESSAGEQUEUE
*queue
= QUEUE_Current();
1399 if (queue
->recursion_count
> MAX_SENDMSG_RECURSION
) return 0;
1400 queue
->recursion_count
++;
1402 if (msg
& 0x80000000)
1404 result
= handle_internal_message( hwnd
, msg
, wparam
, lparam
);
1408 /* first the WH_CALLWNDPROC hook */
1409 hwnd
= WIN_GetFullHandle( hwnd
);
1410 cwp
.lParam
= lparam
;
1411 cwp
.wParam
= wparam
;
1414 HOOK_CallHooks( WH_CALLWNDPROC
, HC_ACTION
, same_thread
, (LPARAM
)&cwp
, unicode
);
1416 /* now call the window procedure */
1419 if (!(winproc
= (WNDPROC
)GetWindowLongW( hwnd
, GWL_WNDPROC
))) goto done
;
1420 result
= CallWindowProcW( winproc
, hwnd
, msg
, wparam
, lparam
);
1424 if (!(winproc
= (WNDPROC
)GetWindowLongA( hwnd
, GWL_WNDPROC
))) goto done
;
1425 result
= CallWindowProcA( winproc
, hwnd
, msg
, wparam
, lparam
);
1428 /* and finally the WH_CALLWNDPROCRET hook */
1429 cwpret
.lResult
= result
;
1430 cwpret
.lParam
= lparam
;
1431 cwpret
.wParam
= wparam
;
1432 cwpret
.message
= msg
;
1434 HOOK_CallHooks( WH_CALLWNDPROCRET
, HC_ACTION
, same_thread
, (LPARAM
)&cwpret
, unicode
);
1436 queue
->recursion_count
--;
1441 /***********************************************************************
1442 * process_hardware_message
1444 * Process a hardware message; return TRUE if message should be passed on to the app
1446 static BOOL
process_hardware_message( MSG
*msg
, ULONG_PTR extra_info
, HWND hwnd
,
1447 UINT first
, UINT last
, BOOL remove
)
1451 if (!MSG_process_raw_hardware_message( msg
, extra_info
, hwnd
, first
, last
, remove
))
1454 ret
= MSG_process_cooked_hardware_message( msg
, extra_info
, remove
);
1456 /* tell the server we have passed it to the app
1457 * (even though we may end up dropping it later on)
1459 SERVER_START_REQ( reply_message
)
1461 req
->type
= MSG_HARDWARE
;
1463 req
->remove
= remove
|| !ret
;
1464 wine_server_call( req
);
1471 /***********************************************************************
1474 * Peek for a message matching the given parameters. Return FALSE if none available.
1475 * All pending sent messages are processed before returning.
1477 BOOL
MSG_peek_message( MSG
*msg
, HWND hwnd
, UINT first
, UINT last
, int flags
)
1480 ULONG_PTR extra_info
= 0;
1481 MESSAGEQUEUE
*queue
= QUEUE_Current();
1482 struct received_message_info info
, *old_info
;
1484 if (!first
&& !last
) last
= ~0;
1489 void *buffer
= NULL
;
1490 size_t size
= 0, buffer_size
= 0;
1492 do /* loop while buffer is too small */
1494 if (buffer_size
&& !(buffer
= HeapAlloc( GetProcessHeap(), 0, buffer_size
)))
1496 SERVER_START_REQ( get_message
)
1499 req
->get_win
= hwnd
;
1500 req
->get_first
= first
;
1501 req
->get_last
= last
;
1502 if (buffer_size
) wine_server_set_reply( req
, buffer
, buffer_size
);
1503 if (!(res
= wine_server_call( req
)))
1505 size
= wine_server_reply_size( reply
);
1506 info
.type
= reply
->type
;
1507 info
.msg
.hwnd
= reply
->win
;
1508 info
.msg
.message
= reply
->msg
;
1509 info
.msg
.wParam
= reply
->wparam
;
1510 info
.msg
.lParam
= reply
->lparam
;
1511 info
.msg
.time
= reply
->time
;
1512 info
.msg
.pt
.x
= reply
->x
;
1513 info
.msg
.pt
.y
= reply
->y
;
1514 extra_info
= reply
->info
;
1518 if (buffer
) HeapFree( GetProcessHeap(), 0, buffer
);
1519 buffer_size
= reply
->total
;
1523 } while (res
== STATUS_BUFFER_OVERFLOW
);
1525 if (res
) return FALSE
;
1527 TRACE( "got type %d msg %x (%s) hwnd %p wp %x lp %lx\n",
1528 info
.type
, info
.msg
.message
, SPY_GetMsgName(info
.msg
.message
, info
.msg
.hwnd
),
1529 info
.msg
.hwnd
, info
.msg
.wParam
, info
.msg
.lParam
);
1535 info
.flags
= ISMEX_SEND
;
1538 info
.flags
= ISMEX_NOTIFY
;
1541 info
.flags
= ISMEX_CALLBACK
;
1543 case MSG_OTHER_PROCESS
:
1544 info
.flags
= ISMEX_SEND
;
1545 if (!unpack_message( info
.msg
.hwnd
, info
.msg
.message
, &info
.msg
.wParam
,
1546 &info
.msg
.lParam
, &buffer
, size
))
1548 ERR( "invalid packed message %x (%s) hwnd %p wp %x lp %lx size %d\n",
1549 info
.msg
.message
, SPY_GetMsgName(info
.msg
.message
, info
.msg
.hwnd
), info
.msg
.hwnd
,
1550 info
.msg
.wParam
, info
.msg
.lParam
, size
);
1552 reply_message( &info
, 0, TRUE
);
1557 if (!process_hardware_message( &info
.msg
, extra_info
,
1558 hwnd
, first
, last
, flags
& GET_MSG_REMOVE
))
1560 TRACE("dropping msg %x\n", info
.msg
.message
);
1561 goto next
; /* ignore it */
1563 queue
->GetMessagePosVal
= MAKELONG( info
.msg
.pt
.x
, info
.msg
.pt
.y
);
1566 queue
->GetMessageExtraInfoVal
= extra_info
;
1567 if (info
.msg
.message
>= WM_DDE_FIRST
&& info
.msg
.message
<= WM_DDE_LAST
)
1569 if (!unpack_dde_message( info
.msg
.hwnd
, info
.msg
.message
, &info
.msg
.wParam
,
1570 &info
.msg
.lParam
, &buffer
, size
))
1572 ERR( "invalid packed dde-message %x (%s) hwnd %p wp %x lp %lx size %d\n",
1573 info
.msg
.message
, SPY_GetMsgName(info
.msg
.message
, info
.msg
.hwnd
),
1574 info
.msg
.hwnd
, info
.msg
.wParam
, info
.msg
.lParam
, size
);
1575 goto next
; /* ignore it */
1579 if (buffer
) HeapFree( GetProcessHeap(), 0, buffer
);
1583 /* if we get here, we have a sent message; call the window procedure */
1584 old_info
= queue
->receive_info
;
1585 queue
->receive_info
= &info
;
1586 result
= call_window_proc( info
.msg
.hwnd
, info
.msg
.message
, info
.msg
.wParam
,
1587 info
.msg
.lParam
, (info
.type
!= MSG_ASCII
), FALSE
);
1588 reply_message( &info
, result
, TRUE
);
1589 queue
->receive_info
= old_info
;
1591 if (buffer
) HeapFree( GetProcessHeap(), 0, buffer
);
1596 /***********************************************************************
1597 * wait_message_reply
1599 * Wait until a sent message gets replied to.
1601 static void wait_message_reply( UINT flags
)
1603 MESSAGEQUEUE
*queue
;
1605 if (!(queue
= QUEUE_Current())) return;
1609 unsigned int wake_bits
= 0, changed_bits
= 0;
1612 SERVER_START_REQ( set_queue_mask
)
1614 req
->wake_mask
= QS_SMRESULT
| ((flags
& SMTO_BLOCK
) ? 0 : QS_SENDMESSAGE
);
1615 req
->changed_mask
= req
->wake_mask
;
1617 if (!wine_server_call( req
))
1619 wake_bits
= reply
->wake_bits
;
1620 changed_bits
= reply
->changed_bits
;
1625 if (wake_bits
& QS_SMRESULT
) return; /* got a result */
1626 if (wake_bits
& QS_SENDMESSAGE
)
1628 /* Process the sent message immediately */
1630 MSG_peek_message( &msg
, 0, 0, 0, GET_MSG_REMOVE
| GET_MSG_SENT_ONLY
);
1634 /* now wait for it */
1636 ReleaseThunkLock( &dwlc
);
1638 if (USER_Driver
.pMsgWaitForMultipleObjectsEx
)
1639 res
= USER_Driver
.pMsgWaitForMultipleObjectsEx( 1, &queue
->server_queue
,
1642 res
= WaitForSingleObject( queue
->server_queue
, INFINITE
);
1644 if (dwlc
) RestoreThunkLock( dwlc
);
1648 /***********************************************************************
1649 * put_message_in_queue
1651 * Put a sent message into the destination queue.
1652 * For inter-process message, reply_size is set to expected size of reply data.
1654 static BOOL
put_message_in_queue( DWORD dest_tid
, const struct send_message_info
*info
,
1655 size_t *reply_size
)
1657 struct packed_message data
;
1659 int i
, timeout
= -1;
1661 if (info
->type
!= MSG_NOTIFY
&&
1662 info
->type
!= MSG_CALLBACK
&&
1663 info
->type
!= MSG_POSTED
&&
1664 info
->timeout
!= INFINITE
)
1665 timeout
= info
->timeout
;
1668 if (info
->type
== MSG_OTHER_PROCESS
)
1670 *reply_size
= pack_message( info
->hwnd
, info
->msg
, info
->wparam
, info
->lparam
, &data
);
1671 if (data
.count
== -1)
1673 WARN( "cannot pack message %x\n", info
->msg
);
1677 else if (info
->type
== MSG_POSTED
&& info
->msg
>= WM_DDE_FIRST
&& info
->msg
<= WM_DDE_LAST
)
1679 return post_dde_message( dest_tid
, &data
, info
);
1682 SERVER_START_REQ( send_message
)
1685 req
->type
= info
->type
;
1687 req
->win
= info
->hwnd
;
1688 req
->msg
= info
->msg
;
1689 req
->wparam
= info
->wparam
;
1690 req
->lparam
= info
->lparam
;
1691 req
->time
= GetCurrentTime();
1692 req
->timeout
= timeout
;
1693 if (info
->flags
& SMTO_ABORTIFHUNG
) req
->flags
|= SEND_MSG_ABORT_IF_HUNG
;
1694 for (i
= 0; i
< data
.count
; i
++) wine_server_add_data( req
, data
.data
[i
], data
.size
[i
] );
1695 if ((res
= wine_server_call( req
)))
1697 if (res
== STATUS_INVALID_PARAMETER
)
1698 /* FIXME: find a STATUS_ value for this one */
1699 SetLastError( ERROR_INVALID_THREAD_ID
);
1701 SetLastError( RtlNtStatusToDosError(res
) );
1709 /***********************************************************************
1712 * Retrieve a message reply from the server.
1714 static LRESULT
retrieve_reply( const struct send_message_info
*info
,
1715 size_t reply_size
, LRESULT
*result
)
1718 void *reply_data
= NULL
;
1722 if (!(reply_data
= HeapAlloc( GetProcessHeap(), 0, reply_size
)))
1724 WARN( "no memory for reply %d bytes, will be truncated\n", reply_size
);
1728 SERVER_START_REQ( get_message_reply
)
1731 if (reply_size
) wine_server_set_reply( req
, reply_data
, reply_size
);
1732 if (!(status
= wine_server_call( req
))) *result
= reply
->result
;
1733 reply_size
= wine_server_reply_size( reply
);
1736 if (!status
&& reply_size
)
1737 unpack_reply( info
->hwnd
, info
->msg
, info
->wparam
, info
->lparam
, reply_data
, reply_size
);
1739 if (reply_data
) HeapFree( GetProcessHeap(), 0, reply_data
);
1741 TRACE( "hwnd %p msg %x (%s) wp %x lp %lx got reply %lx (err=%ld)\n",
1742 info
->hwnd
, info
->msg
, SPY_GetMsgName(info
->msg
, info
->hwnd
), info
->wparam
,
1743 info
->lparam
, *result
, status
);
1745 /* MSDN states that last error is 0 on timeout, but at least NT4 returns ERROR_TIMEOUT */
1746 if (status
) SetLastError( RtlNtStatusToDosError(status
) );
1751 /***********************************************************************
1752 * send_inter_thread_message
1754 static LRESULT
send_inter_thread_message( DWORD dest_tid
, const struct send_message_info
*info
,
1759 size_t reply_size
= 0;
1761 TRACE( "hwnd %p msg %x (%s) wp %x lp %lx\n",
1762 info
->hwnd
, info
->msg
, SPY_GetMsgName(info
->msg
, info
->hwnd
), info
->wparam
, info
->lparam
);
1764 if (!put_message_in_queue( dest_tid
, info
, &reply_size
)) return 0;
1766 /* there's no reply to wait for on notify/callback messages */
1767 if (info
->type
== MSG_NOTIFY
|| info
->type
== MSG_CALLBACK
) return 1;
1769 locks
= WIN_SuspendWndsLock();
1771 wait_message_reply( info
->flags
);
1772 ret
= retrieve_reply( info
, reply_size
, res_ptr
);
1774 WIN_RestoreWndsLock( locks
);
1779 /***********************************************************************
1780 * MSG_SendInternalMessageTimeout
1782 * Same as SendMessageTimeoutW but sends the message to a specific thread
1783 * without requiring a window handle. Only works for internal Wine messages.
1785 LRESULT
MSG_SendInternalMessageTimeout( DWORD dest_pid
, DWORD dest_tid
,
1786 UINT msg
, WPARAM wparam
, LPARAM lparam
,
1787 UINT flags
, UINT timeout
, PDWORD_PTR res_ptr
)
1789 struct send_message_info info
;
1790 LRESULT ret
, result
;
1792 assert( msg
& 0x80000000 ); /* must be an internal Wine message */
1794 info
.type
= MSG_UNICODE
;
1797 info
.wparam
= wparam
;
1798 info
.lparam
= lparam
;
1800 info
.timeout
= timeout
;
1802 if (USER_IsExitingThread( dest_tid
)) return 0;
1804 if (dest_tid
== GetCurrentThreadId())
1806 result
= handle_internal_message( 0, msg
, wparam
, lparam
);
1811 if (dest_pid
!= GetCurrentProcessId()) info
.type
= MSG_OTHER_PROCESS
;
1812 ret
= send_inter_thread_message( dest_tid
, &info
, &result
);
1814 if (ret
&& res_ptr
) *res_ptr
= result
;
1819 /***********************************************************************
1820 * SendMessageTimeoutW (USER32.@)
1822 LRESULT WINAPI
SendMessageTimeoutW( HWND hwnd
, UINT msg
, WPARAM wparam
, LPARAM lparam
,
1823 UINT flags
, UINT timeout
, PDWORD_PTR res_ptr
)
1825 struct send_message_info info
;
1826 DWORD dest_tid
, dest_pid
;
1827 LRESULT ret
, result
;
1829 info
.type
= MSG_UNICODE
;
1832 info
.wparam
= wparam
;
1833 info
.lparam
= lparam
;
1835 info
.timeout
= timeout
;
1837 if (is_broadcast(hwnd
))
1839 EnumWindows( broadcast_message_callback
, (LPARAM
)&info
);
1840 if (res_ptr
) *res_ptr
= 1;
1844 if (!(dest_tid
= GetWindowThreadProcessId( hwnd
, &dest_pid
))) return 0;
1846 if (USER_IsExitingThread( dest_tid
)) return 0;
1848 SPY_EnterMessage( SPY_SENDMESSAGE
, hwnd
, msg
, wparam
, lparam
);
1850 if (dest_tid
== GetCurrentThreadId())
1852 result
= call_window_proc( hwnd
, msg
, wparam
, lparam
, TRUE
, TRUE
);
1857 if (dest_pid
!= GetCurrentProcessId()) info
.type
= MSG_OTHER_PROCESS
;
1858 ret
= send_inter_thread_message( dest_tid
, &info
, &result
);
1861 SPY_ExitMessage( SPY_RESULT_OK
, hwnd
, msg
, result
, wparam
, lparam
);
1862 if (ret
&& res_ptr
) *res_ptr
= result
;
1867 /***********************************************************************
1868 * SendMessageTimeoutA (USER32.@)
1870 LRESULT WINAPI
SendMessageTimeoutA( HWND hwnd
, UINT msg
, WPARAM wparam
, LPARAM lparam
,
1871 UINT flags
, UINT timeout
, PDWORD_PTR res_ptr
)
1873 struct send_message_info info
;
1874 DWORD dest_tid
, dest_pid
;
1875 LRESULT ret
, result
;
1877 info
.type
= MSG_ASCII
;
1880 info
.wparam
= wparam
;
1881 info
.lparam
= lparam
;
1883 info
.timeout
= timeout
;
1885 if (is_broadcast(hwnd
))
1887 EnumWindows( broadcast_message_callback
, (LPARAM
)&info
);
1888 if (res_ptr
) *res_ptr
= 1;
1892 if (!(dest_tid
= GetWindowThreadProcessId( hwnd
, &dest_pid
))) return 0;
1894 if (USER_IsExitingThread( dest_tid
)) return 0;
1896 SPY_EnterMessage( SPY_SENDMESSAGE
, hwnd
, msg
, wparam
, lparam
);
1898 if (dest_tid
== GetCurrentThreadId())
1900 result
= call_window_proc( hwnd
, msg
, wparam
, lparam
, FALSE
, TRUE
);
1903 else if (dest_pid
== GetCurrentProcessId())
1905 ret
= send_inter_thread_message( dest_tid
, &info
, &result
);
1909 /* inter-process message: need to map to Unicode */
1910 info
.type
= MSG_OTHER_PROCESS
;
1911 if (is_unicode_message( info
.msg
))
1913 if (WINPROC_MapMsg32ATo32W( info
.hwnd
, info
.msg
, &info
.wparam
, &info
.lparam
) == -1)
1915 ret
= send_inter_thread_message( dest_tid
, &info
, &result
);
1916 result
= WINPROC_UnmapMsg32ATo32W( info
.hwnd
, info
.msg
, info
.wparam
,
1917 info
.lparam
, result
);
1919 else ret
= send_inter_thread_message( dest_tid
, &info
, &result
);
1921 SPY_ExitMessage( SPY_RESULT_OK
, hwnd
, msg
, result
, wparam
, lparam
);
1922 if (ret
&& res_ptr
) *res_ptr
= result
;
1927 /***********************************************************************
1928 * SendMessageW (USER32.@)
1930 LRESULT WINAPI
SendMessageW( HWND hwnd
, UINT msg
, WPARAM wparam
, LPARAM lparam
)
1933 SendMessageTimeoutW( hwnd
, msg
, wparam
, lparam
, SMTO_NORMAL
, INFINITE
, &res
);
1938 /***********************************************************************
1939 * SendMessageA (USER32.@)
1941 LRESULT WINAPI
SendMessageA( HWND hwnd
, UINT msg
, WPARAM wparam
, LPARAM lparam
)
1944 SendMessageTimeoutA( hwnd
, msg
, wparam
, lparam
, SMTO_NORMAL
, INFINITE
, &res
);
1949 /***********************************************************************
1950 * SendNotifyMessageA (USER32.@)
1952 BOOL WINAPI
SendNotifyMessageA( HWND hwnd
, UINT msg
, WPARAM wparam
, LPARAM lparam
)
1954 return SendNotifyMessageW( hwnd
, msg
, map_wparam_AtoW( msg
, wparam
), lparam
);
1958 /***********************************************************************
1959 * SendNotifyMessageW (USER32.@)
1961 BOOL WINAPI
SendNotifyMessageW( HWND hwnd
, UINT msg
, WPARAM wparam
, LPARAM lparam
)
1963 struct send_message_info info
;
1967 if (is_pointer_message(msg
))
1969 SetLastError(ERROR_INVALID_PARAMETER
);
1973 info
.type
= MSG_NOTIFY
;
1976 info
.wparam
= wparam
;
1977 info
.lparam
= lparam
;
1979 if (is_broadcast(hwnd
))
1981 EnumWindows( broadcast_message_callback
, (LPARAM
)&info
);
1985 if (!(dest_tid
= GetWindowThreadProcessId( hwnd
, NULL
))) return FALSE
;
1987 if (USER_IsExitingThread( dest_tid
)) return TRUE
;
1989 if (dest_tid
== GetCurrentThreadId())
1991 call_window_proc( hwnd
, msg
, wparam
, lparam
, TRUE
, TRUE
);
1994 return send_inter_thread_message( dest_tid
, &info
, &result
);
1998 /***********************************************************************
1999 * SendMessageCallbackA (USER32.@)
2001 BOOL WINAPI
SendMessageCallbackA( HWND hwnd
, UINT msg
, WPARAM wparam
, LPARAM lparam
,
2002 SENDASYNCPROC callback
, ULONG_PTR data
)
2004 return SendMessageCallbackW( hwnd
, msg
, map_wparam_AtoW( msg
, wparam
),
2005 lparam
, callback
, data
);
2009 /***********************************************************************
2010 * SendMessageCallbackW (USER32.@)
2012 BOOL WINAPI
SendMessageCallbackW( HWND hwnd
, UINT msg
, WPARAM wparam
, LPARAM lparam
,
2013 SENDASYNCPROC callback
, ULONG_PTR data
)
2015 struct send_message_info info
;
2019 if (is_pointer_message(msg
))
2021 SetLastError(ERROR_INVALID_PARAMETER
);
2025 info
.type
= MSG_CALLBACK
;
2028 info
.wparam
= wparam
;
2029 info
.lparam
= lparam
;
2030 info
.callback
= callback
;
2033 if (is_broadcast(hwnd
))
2035 EnumWindows( broadcast_message_callback
, (LPARAM
)&info
);
2039 if (!(dest_tid
= GetWindowThreadProcessId( hwnd
, NULL
))) return FALSE
;
2041 if (USER_IsExitingThread( dest_tid
)) return TRUE
;
2043 if (dest_tid
== GetCurrentThreadId())
2045 result
= call_window_proc( hwnd
, msg
, wparam
, lparam
, TRUE
, TRUE
);
2046 callback( hwnd
, msg
, data
, result
);
2049 FIXME( "callback will not be called\n" );
2050 return send_inter_thread_message( dest_tid
, &info
, &result
);
2054 /***********************************************************************
2055 * ReplyMessage (USER32.@)
2057 BOOL WINAPI
ReplyMessage( LRESULT result
)
2059 MESSAGEQUEUE
*queue
= QUEUE_Current();
2060 struct received_message_info
*info
= queue
->receive_info
;
2062 if (!info
) return FALSE
;
2063 reply_message( info
, result
, FALSE
);
2068 /***********************************************************************
2069 * InSendMessage (USER32.@)
2071 BOOL WINAPI
InSendMessage(void)
2073 return (InSendMessageEx(NULL
) & (ISMEX_SEND
|ISMEX_REPLIED
)) == ISMEX_SEND
;
2077 /***********************************************************************
2078 * InSendMessageEx (USER32.@)
2080 DWORD WINAPI
InSendMessageEx( LPVOID reserved
)
2082 MESSAGEQUEUE
*queue
= QUEUE_Current();
2083 struct received_message_info
*info
= queue
->receive_info
;
2085 if (info
) return info
->flags
;
2086 return ISMEX_NOSEND
;
2090 /***********************************************************************
2091 * PostMessageA (USER32.@)
2093 BOOL WINAPI
PostMessageA( HWND hwnd
, UINT msg
, WPARAM wparam
, LPARAM lparam
)
2095 return PostMessageW( hwnd
, msg
, map_wparam_AtoW( msg
, wparam
), lparam
);
2099 /***********************************************************************
2100 * PostMessageW (USER32.@)
2102 BOOL WINAPI
PostMessageW( HWND hwnd
, UINT msg
, WPARAM wparam
, LPARAM lparam
)
2104 struct send_message_info info
;
2107 if (is_pointer_message( msg
))
2109 SetLastError( ERROR_INVALID_PARAMETER
);
2113 TRACE( "hwnd %p msg %x (%s) wp %x lp %lx\n",
2114 hwnd
, msg
, SPY_GetMsgName(msg
, hwnd
), wparam
, lparam
);
2116 info
.type
= MSG_POSTED
;
2119 info
.wparam
= wparam
;
2120 info
.lparam
= lparam
;
2122 if (is_broadcast(hwnd
))
2124 EnumWindows( broadcast_message_callback
, (LPARAM
)&info
);
2128 if (!hwnd
) return PostThreadMessageW( GetCurrentThreadId(), msg
, wparam
, lparam
);
2130 if (!(dest_tid
= GetWindowThreadProcessId( hwnd
, NULL
))) return FALSE
;
2132 if (USER_IsExitingThread( dest_tid
)) return TRUE
;
2134 return put_message_in_queue( dest_tid
, &info
, NULL
);
2138 /**********************************************************************
2139 * PostThreadMessageA (USER32.@)
2141 BOOL WINAPI
PostThreadMessageA( DWORD thread
, UINT msg
, WPARAM wparam
, LPARAM lparam
)
2143 return PostThreadMessageW( thread
, msg
, map_wparam_AtoW( msg
, wparam
), lparam
);
2147 /**********************************************************************
2148 * PostThreadMessageW (USER32.@)
2150 BOOL WINAPI
PostThreadMessageW( DWORD thread
, UINT msg
, WPARAM wparam
, LPARAM lparam
)
2152 struct send_message_info info
;
2154 if (is_pointer_message( msg
))
2156 SetLastError( ERROR_INVALID_PARAMETER
);
2159 if (USER_IsExitingThread( thread
)) return TRUE
;
2161 info
.type
= MSG_POSTED
;
2164 info
.wparam
= wparam
;
2165 info
.lparam
= lparam
;
2166 return put_message_in_queue( thread
, &info
, NULL
);
2170 /***********************************************************************
2171 * PostQuitMessage (USER32.@)
2173 void WINAPI
PostQuitMessage( INT exitCode
)
2175 PostThreadMessageW( GetCurrentThreadId(), WM_QUIT
, exitCode
, 0 );
2179 /***********************************************************************
2180 * PeekMessageW (USER32.@)
2182 BOOL WINAPI
PeekMessageW( MSG
*msg_out
, HWND hwnd
, UINT first
, UINT last
, UINT flags
)
2184 MESSAGEQUEUE
*queue
;
2188 /* check for graphics events */
2189 if (USER_Driver
.pMsgWaitForMultipleObjectsEx
)
2190 USER_Driver
.pMsgWaitForMultipleObjectsEx( 0, NULL
, 0, 0, 0 );
2192 hwnd
= WIN_GetFullHandle( hwnd
);
2193 locks
= WIN_SuspendWndsLock();
2195 if (!MSG_peek_message( &msg
, hwnd
, first
, last
,
2196 (flags
& PM_REMOVE
) ? GET_MSG_REMOVE
: 0 ))
2198 if (!(flags
& PM_NOYIELD
))
2201 ReleaseThunkLock(&count
);
2202 if (count
) RestoreThunkLock(count
);
2204 WIN_RestoreWndsLock( locks
);
2208 WIN_RestoreWndsLock( locks
);
2210 /* need to fill the window handle for WM_PAINT message */
2211 if (msg
.message
== WM_PAINT
)
2213 if (IsIconic( msg
.hwnd
) && GetClassLongA( msg
.hwnd
, GCL_HICON
))
2215 msg
.message
= WM_PAINTICON
;
2218 /* clear internal paint flag */
2219 RedrawWindow( msg
.hwnd
, NULL
, 0, RDW_NOINTERNALPAINT
| RDW_NOCHILDREN
);
2222 if ((queue
= QUEUE_Current()))
2224 queue
->GetMessageTimeVal
= msg
.time
;
2225 msg
.pt
.x
= LOWORD( queue
->GetMessagePosVal
);
2226 msg
.pt
.y
= HIWORD( queue
->GetMessagePosVal
);
2229 HOOK_CallHooks( WH_GETMESSAGE
, HC_ACTION
, flags
& PM_REMOVE
, (LPARAM
)&msg
, TRUE
);
2231 /* copy back our internal safe copy of message data to msg_out.
2232 * msg_out is a variable from the *program*, so it can't be used
2233 * internally as it can get "corrupted" by our use of SendMessage()
2234 * (back to the program) inside the message handling itself. */
2240 /***********************************************************************
2241 * PeekMessageA (USER32.@)
2243 BOOL WINAPI
PeekMessageA( MSG
*msg
, HWND hwnd
, UINT first
, UINT last
, UINT flags
)
2245 BOOL ret
= PeekMessageW( msg
, hwnd
, first
, last
, flags
);
2246 if (ret
) msg
->wParam
= map_wparam_WtoA( msg
->message
, msg
->wParam
);
2251 /***********************************************************************
2252 * GetMessageW (USER32.@)
2254 BOOL WINAPI
GetMessageW( MSG
*msg
, HWND hwnd
, UINT first
, UINT last
)
2256 MESSAGEQUEUE
*queue
= QUEUE_Current();
2259 mask
= QS_POSTMESSAGE
| QS_SENDMESSAGE
; /* Always selected */
2262 if ((first
<= WM_KEYLAST
) && (last
>= WM_KEYFIRST
)) mask
|= QS_KEY
;
2263 if ( ((first
<= WM_MOUSELAST
) && (last
>= WM_MOUSEFIRST
)) ||
2264 ((first
<= WM_NCMOUSELAST
) && (last
>= WM_NCMOUSEFIRST
)) ) mask
|= QS_MOUSE
;
2265 if ((first
<= WM_TIMER
) && (last
>= WM_TIMER
)) mask
|= QS_TIMER
;
2266 if ((first
<= WM_SYSTIMER
) && (last
>= WM_SYSTIMER
)) mask
|= QS_TIMER
;
2267 if ((first
<= WM_PAINT
) && (last
>= WM_PAINT
)) mask
|= QS_PAINT
;
2269 else mask
|= QS_MOUSE
| QS_KEY
| QS_TIMER
| QS_PAINT
;
2271 locks
= WIN_SuspendWndsLock();
2273 while (!PeekMessageW( msg
, hwnd
, first
, last
, PM_REMOVE
))
2275 /* wait until one of the bits is set */
2276 unsigned int wake_bits
= 0, changed_bits
= 0;
2279 SERVER_START_REQ( set_queue_mask
)
2281 req
->wake_mask
= QS_SENDMESSAGE
;
2282 req
->changed_mask
= mask
;
2284 if (!wine_server_call( req
))
2286 wake_bits
= reply
->wake_bits
;
2287 changed_bits
= reply
->changed_bits
;
2292 if (changed_bits
& mask
) continue;
2293 if (wake_bits
& QS_SENDMESSAGE
) continue;
2295 TRACE( "(%04x) mask=%08x, bits=%08x, changed=%08x, waiting\n",
2296 queue
->self
, mask
, wake_bits
, changed_bits
);
2298 ReleaseThunkLock( &dwlc
);
2299 if (USER_Driver
.pMsgWaitForMultipleObjectsEx
)
2300 USER_Driver
.pMsgWaitForMultipleObjectsEx( 1, &queue
->server_queue
, INFINITE
, 0, 0 );
2302 WaitForSingleObject( queue
->server_queue
, INFINITE
);
2303 if (dwlc
) RestoreThunkLock( dwlc
);
2306 WIN_RestoreWndsLock( locks
);
2308 return (msg
->message
!= WM_QUIT
);
2312 /***********************************************************************
2313 * GetMessageA (USER32.@)
2315 BOOL WINAPI
GetMessageA( MSG
*msg
, HWND hwnd
, UINT first
, UINT last
)
2317 GetMessageW( msg
, hwnd
, first
, last
);
2318 msg
->wParam
= map_wparam_WtoA( msg
->message
, msg
->wParam
);
2319 return (msg
->message
!= WM_QUIT
);
2323 /***********************************************************************
2324 * IsDialogMessage (USER32.@)
2325 * IsDialogMessageA (USER32.@)
2327 BOOL WINAPI
IsDialogMessageA( HWND hwndDlg
, LPMSG pmsg
)
2330 msg
.wParam
= map_wparam_AtoW( msg
.message
, msg
.wParam
);
2331 return IsDialogMessageW( hwndDlg
, &msg
);
2335 /***********************************************************************
2336 * SetMessageQueue (USER32.@)
2338 BOOL WINAPI
SetMessageQueue( INT size
)
2340 /* now obsolete the message queue will be expanded dynamically as necessary */
2345 /**********************************************************************
2346 * AttachThreadInput (USER32.@)
2348 * Attaches the input processing mechanism of one thread to that of
2351 BOOL WINAPI
AttachThreadInput( DWORD from
, DWORD to
, BOOL attach
)
2355 SERVER_START_REQ( attach_thread_input
)
2357 req
->tid_from
= from
;
2359 req
->attach
= attach
;
2360 ret
= !wine_server_call_err( req
);
2367 /**********************************************************************
2368 * GetGUIThreadInfo (USER32.@)
2370 BOOL WINAPI
GetGUIThreadInfo( DWORD id
, GUITHREADINFO
*info
)
2374 SERVER_START_REQ( get_thread_input
)
2377 if ((ret
= !wine_server_call_err( req
)))
2380 info
->hwndActive
= reply
->active
;
2381 info
->hwndFocus
= reply
->focus
;
2382 info
->hwndCapture
= reply
->capture
;
2383 info
->hwndMenuOwner
= reply
->menu_owner
;
2384 info
->hwndMoveSize
= reply
->move_size
;
2385 info
->hwndCaret
= reply
->caret
;
2386 info
->rcCaret
.left
= reply
->rect
.left
;
2387 info
->rcCaret
.top
= reply
->rect
.top
;
2388 info
->rcCaret
.right
= reply
->rect
.right
;
2389 info
->rcCaret
.bottom
= reply
->rect
.bottom
;
2390 if (reply
->menu_owner
) info
->flags
|= GUI_INMENUMODE
;
2391 if (reply
->move_size
) info
->flags
|= GUI_INMOVESIZE
;
2392 if (reply
->caret
) info
->flags
|= GUI_CARETBLINKING
;
2400 /**********************************************************************
2401 * GetKeyState (USER32.@)
2403 * An application calls the GetKeyState function in response to a
2404 * keyboard-input message. This function retrieves the state of the key
2405 * at the time the input message was generated.
2407 SHORT WINAPI
GetKeyState(INT vkey
)
2411 SERVER_START_REQ( get_key_state
)
2413 req
->tid
= GetCurrentThreadId();
2415 if (!wine_server_call( req
)) retval
= (signed char)reply
->state
;
2418 TRACE("key (0x%x) -> %x\n", vkey
, retval
);
2423 /**********************************************************************
2424 * GetKeyboardState (USER32.@)
2426 BOOL WINAPI
GetKeyboardState( LPBYTE state
)
2430 TRACE("(%p)\n", state
);
2432 memset( state
, 0, 256 );
2433 SERVER_START_REQ( get_key_state
)
2435 req
->tid
= GetCurrentThreadId();
2437 wine_server_set_reply( req
, state
, 256 );
2438 ret
= !wine_server_call_err( req
);
2445 /**********************************************************************
2446 * SetKeyboardState (USER32.@)
2448 BOOL WINAPI
SetKeyboardState( LPBYTE state
)
2452 TRACE("(%p)\n", state
);
2454 SERVER_START_REQ( set_key_state
)
2456 req
->tid
= GetCurrentThreadId();
2457 wine_server_add_data( req
, state
, 256 );
2458 ret
= !wine_server_call_err( req
);