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 MultiByteToWideChar(CP_ACP
, 0, ch
, 2, &wch
, 1);
351 wparam
= MAKEWPARAM( wch
, HIWORD(wparam
) );
359 /***********************************************************************
362 * Convert the wparam of a Unicode message to ASCII.
364 static WPARAM
map_wparam_WtoA( UINT message
, WPARAM wparam
)
369 case EM_SETPASSWORDCHAR
:
376 WCHAR wch
= LOWORD(wparam
);
378 WideCharToMultiByte( CP_ACP
, 0, &wch
, 1, &ch
, 1, NULL
, NULL
);
379 wparam
= MAKEWPARAM( ch
, HIWORD(wparam
) );
384 WCHAR wch
= LOWORD(wparam
);
388 WideCharToMultiByte( CP_ACP
, 0, &wch
, 1, ch
, 2, NULL
, NULL
);
389 wparam
= MAKEWPARAM( (ch
[0] << 8) | ch
[1], HIWORD(wparam
) );
397 /***********************************************************************
400 * Pack a message for sending to another process.
401 * Return the size of the data we expect in the message reply.
402 * Set data->count to -1 if there is an error.
404 static size_t pack_message( HWND hwnd
, UINT message
, WPARAM wparam
, LPARAM lparam
,
405 struct packed_message
*data
)
413 CREATESTRUCTW
*cs
= (CREATESTRUCTW
*)lparam
;
414 push_data( data
, cs
, sizeof(*cs
) );
415 if (HIWORD(cs
->lpszName
)) push_string( data
, cs
->lpszName
);
416 if (HIWORD(cs
->lpszClass
)) push_string( data
, cs
->lpszClass
);
420 case WM_ASKCBFORMATNAME
:
421 return wparam
* sizeof(WCHAR
);
422 case WM_WININICHANGE
:
423 if (lparam
) push_string(data
, (LPWSTR
)lparam
);
426 case WM_DEVMODECHANGE
:
431 push_string( data
, (LPWSTR
)lparam
);
433 case WM_GETMINMAXINFO
:
434 push_data( data
, (MINMAXINFO
*)lparam
, sizeof(MINMAXINFO
) );
435 return sizeof(MINMAXINFO
);
437 push_data( data
, (DRAWITEMSTRUCT
*)lparam
, sizeof(DRAWITEMSTRUCT
) );
440 push_data( data
, (MEASUREITEMSTRUCT
*)lparam
, sizeof(MEASUREITEMSTRUCT
) );
441 return sizeof(MEASUREITEMSTRUCT
);
443 push_data( data
, (DELETEITEMSTRUCT
*)lparam
, sizeof(DELETEITEMSTRUCT
) );
446 push_data( data
, (COMPAREITEMSTRUCT
*)lparam
, sizeof(COMPAREITEMSTRUCT
) );
448 case WM_WINDOWPOSCHANGING
:
449 case WM_WINDOWPOSCHANGED
:
450 push_data( data
, (WINDOWPOS
*)lparam
, sizeof(WINDOWPOS
) );
451 return sizeof(WINDOWPOS
);
454 COPYDATASTRUCT
*cp
= (COPYDATASTRUCT
*)lparam
;
455 push_data( data
, cp
, sizeof(*cp
) );
456 if (cp
->lpData
) push_data( data
, cp
->lpData
, cp
->cbData
);
460 /* WM_NOTIFY cannot be sent across processes (MSDN) */
464 push_data( data
, (HELPINFO
*)lparam
, sizeof(HELPINFO
) );
466 case WM_STYLECHANGING
:
467 case WM_STYLECHANGED
:
468 push_data( data
, (STYLESTRUCT
*)lparam
, sizeof(STYLESTRUCT
) );
473 push_data( data
, (RECT
*)lparam
, sizeof(RECT
) );
478 NCCALCSIZE_PARAMS
*nc
= (NCCALCSIZE_PARAMS
*)lparam
;
479 push_data( data
, nc
, sizeof(*nc
) );
480 push_data( data
, nc
->lppos
, sizeof(*nc
->lppos
) );
481 return sizeof(*nc
) + sizeof(*nc
->lppos
);
484 if (lparam
) push_data( data
, (MSG
*)lparam
, sizeof(MSG
) );
486 case SBM_SETSCROLLINFO
:
487 push_data( data
, (SCROLLINFO
*)lparam
, sizeof(SCROLLINFO
) );
489 case SBM_GETSCROLLINFO
:
490 push_data( data
, (SCROLLINFO
*)lparam
, sizeof(SCROLLINFO
) );
491 return sizeof(SCROLLINFO
);
497 if (wparam
) size
+= sizeof(DWORD
);
498 if (lparam
) size
+= sizeof(DWORD
);
503 case CB_GETDROPPEDCONTROLRECT
:
507 push_data( data
, (RECT
*)lparam
, sizeof(RECT
) );
511 WORD
*pw
= (WORD
*)lparam
;
512 push_data( data
, pw
, sizeof(*pw
) );
513 return *pw
* sizeof(WCHAR
);
517 if (wparam
) push_data( data
, (UINT
*)lparam
, sizeof(UINT
) * wparam
);
520 case CB_INSERTSTRING
:
522 case CB_FINDSTRINGEXACT
:
523 case CB_SELECTSTRING
:
524 if (combobox_has_strings( hwnd
)) push_string( data
, (LPWSTR
)lparam
);
527 if (!combobox_has_strings( hwnd
)) return sizeof(ULONG_PTR
);
528 return (SendMessageW( hwnd
, CB_GETLBTEXTLEN
, wparam
, 0 ) + 1) * sizeof(WCHAR
);
530 case LB_INSERTSTRING
:
532 case LB_FINDSTRINGEXACT
:
533 case LB_SELECTSTRING
:
534 if (listbox_has_strings( hwnd
)) push_string( data
, (LPWSTR
)lparam
);
537 if (!listbox_has_strings( hwnd
)) return sizeof(ULONG_PTR
);
538 return (SendMessageW( hwnd
, LB_GETTEXTLEN
, wparam
, 0 ) + 1) * sizeof(WCHAR
);
540 return wparam
* sizeof(UINT
);
542 push_data( data
, (MDINEXTMENU
*)lparam
, sizeof(MDINEXTMENU
) );
543 return sizeof(MDINEXTMENU
);
546 push_data( data
, (RECT
*)lparam
, sizeof(RECT
) );
550 MDICREATESTRUCTW
*cs
= (MDICREATESTRUCTW
*)lparam
;
551 push_data( data
, cs
, sizeof(*cs
) );
552 if (HIWORD(cs
->szTitle
)) push_string( data
, cs
->szTitle
);
553 if (HIWORD(cs
->szClass
)) push_string( data
, cs
->szClass
);
556 case WM_MDIGETACTIVE
:
557 if (lparam
) return sizeof(BOOL
);
559 case WM_WINE_SETWINDOWPOS
:
560 push_data( data
, (WINDOWPOS
*)lparam
, sizeof(WINDOWPOS
) );
562 case WM_WINE_KEYBOARD_LL_HOOK
:
563 push_data( data
, (KBDLLHOOKSTRUCT
*)lparam
, sizeof(KBDLLHOOKSTRUCT
) );
565 case WM_WINE_MOUSE_LL_HOOK
:
566 push_data( data
, (MSLLHOOKSTRUCT
*)lparam
, sizeof(MSLLHOOKSTRUCT
) );
569 /* these contain an HFONT */
572 /* these contain an HDC */
575 case WM_ICONERASEBKGND
:
577 case WM_CTLCOLORMSGBOX
:
578 case WM_CTLCOLOREDIT
:
579 case WM_CTLCOLORLISTBOX
:
582 case WM_CTLCOLORSCROLLBAR
:
583 case WM_CTLCOLORSTATIC
:
586 /* these contain an HGLOBAL */
587 case WM_PAINTCLIPBOARD
:
588 case WM_SIZECLIPBOARD
:
589 /* these contain pointers */
591 case WM_QUERYDROPOBJECT
:
595 case WM_DEVICECHANGE
:
596 FIXME( "msg %x (%s) not supported yet\n", message
, SPY_GetMsgName(message
, hwnd
) );
604 /***********************************************************************
607 * Unpack a message received from another process.
609 static BOOL
unpack_message( HWND hwnd
, UINT message
, WPARAM
*wparam
, LPARAM
*lparam
,
610 void **buffer
, size_t size
)
619 CREATESTRUCTW
*cs
= *buffer
;
620 WCHAR
*str
= (WCHAR
*)(cs
+ 1);
621 if (size
< sizeof(*cs
)) return FALSE
;
623 if (HIWORD(cs
->lpszName
))
625 if (!check_string( str
, size
)) return FALSE
;
627 size
-= (strlenW(str
) + 1) * sizeof(WCHAR
);
628 str
+= strlenW(str
) + 1;
630 if (HIWORD(cs
->lpszClass
))
632 if (!check_string( str
, size
)) return FALSE
;
638 case WM_ASKCBFORMATNAME
:
639 if (!get_buffer_space( buffer
, (*wparam
* sizeof(WCHAR
)) )) return FALSE
;
641 case WM_WININICHANGE
:
642 if (!*lparam
) return TRUE
;
645 case WM_DEVMODECHANGE
:
650 if (!check_string( *buffer
, size
)) return FALSE
;
652 case WM_GETMINMAXINFO
:
653 minsize
= sizeof(MINMAXINFO
);
656 minsize
= sizeof(DRAWITEMSTRUCT
);
659 minsize
= sizeof(MEASUREITEMSTRUCT
);
662 minsize
= sizeof(DELETEITEMSTRUCT
);
665 minsize
= sizeof(COMPAREITEMSTRUCT
);
667 case WM_WINDOWPOSCHANGING
:
668 case WM_WINDOWPOSCHANGED
:
669 case WM_WINE_SETWINDOWPOS
:
670 minsize
= sizeof(WINDOWPOS
);
674 COPYDATASTRUCT
*cp
= *buffer
;
675 if (size
< sizeof(*cp
)) return FALSE
;
678 minsize
= sizeof(*cp
) + cp
->cbData
;
684 /* WM_NOTIFY cannot be sent across processes (MSDN) */
687 minsize
= sizeof(HELPINFO
);
689 case WM_STYLECHANGING
:
690 case WM_STYLECHANGED
:
691 minsize
= sizeof(STYLESTRUCT
);
694 if (!*wparam
) minsize
= sizeof(RECT
);
697 NCCALCSIZE_PARAMS
*nc
= *buffer
;
698 if (size
< sizeof(*nc
) + sizeof(*nc
->lppos
)) return FALSE
;
699 nc
->lppos
= (WINDOWPOS
*)(nc
+ 1);
703 if (!*lparam
) return TRUE
;
704 minsize
= sizeof(MSG
);
706 case SBM_SETSCROLLINFO
:
707 minsize
= sizeof(SCROLLINFO
);
709 case SBM_GETSCROLLINFO
:
710 if (!get_buffer_space( buffer
, sizeof(SCROLLINFO
))) return FALSE
;
715 if (*wparam
|| *lparam
)
717 if (!get_buffer_space( buffer
, 2*sizeof(DWORD
) )) return FALSE
;
718 if (*wparam
) *wparam
= (WPARAM
)*buffer
;
719 if (*lparam
) *lparam
= (LPARAM
)((DWORD
*)*buffer
+ 1);
724 case CB_GETDROPPEDCONTROLRECT
:
725 if (!get_buffer_space( buffer
, sizeof(RECT
) )) return FALSE
;
729 minsize
= sizeof(RECT
);
734 if (size
< sizeof(WORD
)) return FALSE
;
735 len
= *(WORD
*)*buffer
;
736 if (!get_buffer_space( buffer
, (len
+ 1) * sizeof(WCHAR
) )) return FALSE
;
737 *lparam
= (LPARAM
)*buffer
+ sizeof(WORD
); /* don't erase WORD at start of buffer */
742 if (!*wparam
) return TRUE
;
743 minsize
= *wparam
* sizeof(UINT
);
746 case CB_INSERTSTRING
:
748 case CB_FINDSTRINGEXACT
:
749 case CB_SELECTSTRING
:
751 case LB_INSERTSTRING
:
753 case LB_FINDSTRINGEXACT
:
754 case LB_SELECTSTRING
:
755 if (!*buffer
) return TRUE
;
756 if (!check_string( *buffer
, size
)) return FALSE
;
760 size
= sizeof(ULONG_PTR
);
761 if (combobox_has_strings( hwnd
))
762 size
= (SendMessageW( hwnd
, CB_GETLBTEXTLEN
, *wparam
, 0 ) + 1) * sizeof(WCHAR
);
763 if (!get_buffer_space( buffer
, size
)) return FALSE
;
768 size
= sizeof(ULONG_PTR
);
769 if (listbox_has_strings( hwnd
))
770 size
= (SendMessageW( hwnd
, LB_GETTEXTLEN
, *wparam
, 0 ) + 1) * sizeof(WCHAR
);
771 if (!get_buffer_space( buffer
, size
)) return FALSE
;
775 if (!get_buffer_space( buffer
, *wparam
* sizeof(UINT
) )) return FALSE
;
778 minsize
= sizeof(MDINEXTMENU
);
779 if (!get_buffer_space( buffer
, sizeof(MDINEXTMENU
) )) return FALSE
;
783 minsize
= sizeof(RECT
);
784 if (!get_buffer_space( buffer
, sizeof(RECT
) )) return FALSE
;
788 MDICREATESTRUCTW
*cs
= *buffer
;
789 WCHAR
*str
= (WCHAR
*)(cs
+ 1);
790 if (size
< sizeof(*cs
)) return FALSE
;
792 if (HIWORD(cs
->szTitle
))
794 if (!check_string( str
, size
)) return FALSE
;
796 size
-= (strlenW(str
) + 1) * sizeof(WCHAR
);
797 str
+= strlenW(str
) + 1;
799 if (HIWORD(cs
->szClass
))
801 if (!check_string( str
, size
)) return FALSE
;
806 case WM_MDIGETACTIVE
:
807 if (!*lparam
) return TRUE
;
808 if (!get_buffer_space( buffer
, sizeof(BOOL
) )) return FALSE
;
810 case WM_WINE_KEYBOARD_LL_HOOK
:
811 minsize
= sizeof(KBDLLHOOKSTRUCT
);
813 case WM_WINE_MOUSE_LL_HOOK
:
814 minsize
= sizeof(MSLLHOOKSTRUCT
);
817 /* these contain an HFONT */
820 /* these contain an HDC */
823 case WM_ICONERASEBKGND
:
825 case WM_CTLCOLORMSGBOX
:
826 case WM_CTLCOLOREDIT
:
827 case WM_CTLCOLORLISTBOX
:
830 case WM_CTLCOLORSCROLLBAR
:
831 case WM_CTLCOLORSTATIC
:
834 /* these contain an HGLOBAL */
835 case WM_PAINTCLIPBOARD
:
836 case WM_SIZECLIPBOARD
:
837 /* these contain pointers */
839 case WM_QUERYDROPOBJECT
:
843 case WM_DEVICECHANGE
:
844 FIXME( "msg %x (%s) not supported yet\n", message
, SPY_GetMsgName(message
, hwnd
) );
848 return TRUE
; /* message doesn't need any unpacking */
851 /* default exit for most messages: check minsize and store buffer in lparam */
852 if (size
< minsize
) return FALSE
;
853 *lparam
= (LPARAM
)*buffer
;
858 /***********************************************************************
861 * Pack a reply to a message for sending to another process.
863 static void pack_reply( HWND hwnd
, UINT message
, WPARAM wparam
, LPARAM lparam
,
864 LRESULT res
, struct packed_message
*data
)
871 push_data( data
, (CREATESTRUCTW
*)lparam
, sizeof(CREATESTRUCTW
) );
876 push_data( data
, (WCHAR
*)lparam
, (res
+ 1) * sizeof(WCHAR
) );
878 case WM_GETMINMAXINFO
:
879 push_data( data
, (MINMAXINFO
*)lparam
, sizeof(MINMAXINFO
) );
882 push_data( data
, (MEASUREITEMSTRUCT
*)lparam
, sizeof(MEASUREITEMSTRUCT
) );
884 case WM_WINDOWPOSCHANGING
:
885 case WM_WINDOWPOSCHANGED
:
886 push_data( data
, (WINDOWPOS
*)lparam
, sizeof(WINDOWPOS
) );
889 if (lparam
) push_data( data
, (MSG
*)lparam
, sizeof(MSG
) );
891 case SBM_GETSCROLLINFO
:
892 push_data( data
, (SCROLLINFO
*)lparam
, sizeof(SCROLLINFO
) );
896 case CB_GETDROPPEDCONTROLRECT
:
899 push_data( data
, (RECT
*)lparam
, sizeof(RECT
) );
903 WORD
*ptr
= (WORD
*)lparam
;
904 push_data( data
, ptr
, ptr
[-1] * sizeof(WCHAR
) );
908 push_data( data
, (UINT
*)lparam
, wparam
* sizeof(UINT
) );
910 case WM_MDIGETACTIVE
:
911 if (lparam
) push_data( data
, (BOOL
*)lparam
, sizeof(BOOL
) );
915 push_data( data
, (RECT
*)lparam
, sizeof(RECT
) );
918 NCCALCSIZE_PARAMS
*nc
= (NCCALCSIZE_PARAMS
*)lparam
;
919 push_data( data
, nc
, sizeof(*nc
) );
920 push_data( data
, nc
->lppos
, sizeof(*nc
->lppos
) );
926 if (wparam
) push_data( data
, (DWORD
*)wparam
, sizeof(DWORD
) );
927 if (lparam
) push_data( data
, (DWORD
*)lparam
, sizeof(DWORD
) );
930 push_data( data
, (MDINEXTMENU
*)lparam
, sizeof(MDINEXTMENU
) );
933 push_data( data
, (MDICREATESTRUCTW
*)lparam
, sizeof(MDICREATESTRUCTW
) );
935 case WM_ASKCBFORMATNAME
:
936 push_data( data
, (WCHAR
*)lparam
, (strlenW((WCHAR
*)lparam
) + 1) * sizeof(WCHAR
) );
942 /***********************************************************************
945 * Unpack a message reply received from another process.
947 static void unpack_reply( HWND hwnd
, UINT message
, WPARAM wparam
, LPARAM lparam
,
948 void *buffer
, size_t size
)
955 CREATESTRUCTW
*cs
= (CREATESTRUCTW
*)lparam
;
956 LPCWSTR name
= cs
->lpszName
, class = cs
->lpszClass
;
957 memcpy( cs
, buffer
, min( sizeof(*cs
), size
));
958 cs
->lpszName
= name
; /* restore the original pointers */
959 cs
->lpszClass
= class;
963 case WM_ASKCBFORMATNAME
:
964 memcpy( (WCHAR
*)lparam
, buffer
, min( wparam
*sizeof(WCHAR
), size
));
966 case WM_GETMINMAXINFO
:
967 memcpy( (MINMAXINFO
*)lparam
, buffer
, min( sizeof(MINMAXINFO
), size
));
970 memcpy( (MEASUREITEMSTRUCT
*)lparam
, buffer
, min( sizeof(MEASUREITEMSTRUCT
), size
));
972 case WM_WINDOWPOSCHANGING
:
973 case WM_WINDOWPOSCHANGED
:
974 memcpy( (WINDOWPOS
*)lparam
, buffer
, min( sizeof(WINDOWPOS
), size
));
977 if (lparam
) memcpy( (MSG
*)lparam
, buffer
, min( sizeof(MSG
), size
));
979 case SBM_GETSCROLLINFO
:
980 memcpy( (SCROLLINFO
*)lparam
, buffer
, min( sizeof(SCROLLINFO
), size
));
983 case CB_GETDROPPEDCONTROLRECT
:
987 memcpy( (RECT
*)lparam
, buffer
, min( sizeof(RECT
), size
));
990 size
= min( size
, (size_t)*(WORD
*)lparam
);
991 memcpy( (WCHAR
*)lparam
, buffer
, size
);
994 memcpy( (UINT
*)lparam
, buffer
, min( wparam
*sizeof(UINT
), size
));
998 memcpy( (WCHAR
*)lparam
, buffer
, size
);
1001 memcpy( (MDINEXTMENU
*)lparam
, buffer
, min( sizeof(MDINEXTMENU
), size
));
1003 case WM_MDIGETACTIVE
:
1004 if (lparam
) memcpy( (BOOL
*)lparam
, buffer
, min( sizeof(BOOL
), size
));
1008 memcpy( (RECT
*)lparam
, buffer
, min( sizeof(RECT
), size
));
1011 NCCALCSIZE_PARAMS
*nc
= (NCCALCSIZE_PARAMS
*)lparam
;
1012 WINDOWPOS
*wp
= nc
->lppos
;
1013 memcpy( nc
, buffer
, min( sizeof(*nc
), size
));
1014 if (size
> sizeof(*nc
))
1016 size
-= sizeof(*nc
);
1017 memcpy( wp
, (NCCALCSIZE_PARAMS
*)buffer
+ 1, min( sizeof(*wp
), size
));
1019 nc
->lppos
= wp
; /* restore the original pointer */
1027 memcpy( (DWORD
*)wparam
, buffer
, min( sizeof(DWORD
), size
));
1028 if (size
<= sizeof(DWORD
)) break;
1029 size
-= sizeof(DWORD
);
1030 buffer
= (DWORD
*)buffer
+ 1;
1032 if (lparam
) memcpy( (DWORD
*)lparam
, buffer
, min( sizeof(DWORD
), size
));
1036 MDICREATESTRUCTW
*cs
= (MDICREATESTRUCTW
*)lparam
;
1037 LPCWSTR title
= cs
->szTitle
, class = cs
->szClass
;
1038 memcpy( cs
, buffer
, min( sizeof(*cs
), size
));
1039 cs
->szTitle
= title
; /* restore the original pointers */
1040 cs
->szClass
= class;
1044 ERR( "should not happen: unexpected message %x\n", message
);
1050 /***********************************************************************
1053 * Send a reply to a sent message.
1055 static void reply_message( struct received_message_info
*info
, LRESULT result
, BOOL remove
)
1057 struct packed_message data
;
1058 int i
, replied
= info
->flags
& ISMEX_REPLIED
;
1060 if (info
->flags
& ISMEX_NOTIFY
) return; /* notify messages don't get replies */
1061 if (!remove
&& replied
) return; /* replied already */
1064 info
->flags
|= ISMEX_REPLIED
;
1066 if (info
->type
== MSG_OTHER_PROCESS
&& !replied
)
1068 pack_reply( info
->msg
.hwnd
, info
->msg
.message
, info
->msg
.wParam
,
1069 info
->msg
.lParam
, result
, &data
);
1072 SERVER_START_REQ( reply_message
)
1074 req
->type
= info
->type
;
1075 req
->result
= result
;
1076 req
->remove
= remove
;
1077 for (i
= 0; i
< data
.count
; i
++) wine_server_add_data( req
, data
.data
[i
], data
.size
[i
] );
1078 wine_server_call( req
);
1084 /***********************************************************************
1085 * handle_internal_message
1087 * Handle an internal Wine message instead of calling the window proc.
1089 static LRESULT
handle_internal_message( HWND hwnd
, UINT msg
, WPARAM wparam
, LPARAM lparam
)
1091 if (hwnd
== GetDesktopWindow()) return 0;
1094 case WM_WINE_DESTROYWINDOW
:
1095 return WIN_DestroyWindow( hwnd
);
1096 case WM_WINE_SETWINDOWPOS
:
1097 return USER_Driver
.pSetWindowPos( (WINDOWPOS
*)lparam
);
1098 case WM_WINE_SHOWWINDOW
:
1099 return ShowWindow( hwnd
, wparam
);
1100 case WM_WINE_SETPARENT
:
1101 return (LRESULT
)SetParent( hwnd
, (HWND
)wparam
);
1102 case WM_WINE_SETWINDOWLONG
:
1103 return (LRESULT
)SetWindowLongW( hwnd
, wparam
, lparam
);
1104 case WM_WINE_ENABLEWINDOW
:
1105 return EnableWindow( hwnd
, wparam
);
1106 case WM_WINE_SETACTIVEWINDOW
:
1107 return (LRESULT
)SetActiveWindow( (HWND
)wparam
);
1108 case WM_WINE_KEYBOARD_LL_HOOK
:
1109 return HOOK_CallHooks( WH_KEYBOARD_LL
, HC_ACTION
, wparam
, lparam
, TRUE
);
1110 case WM_WINE_MOUSE_LL_HOOK
:
1111 return HOOK_CallHooks( WH_MOUSE_LL
, HC_ACTION
, wparam
, lparam
, TRUE
);
1113 FIXME( "unknown internal message %x\n", msg
);
1118 /* since the WM_DDE_ACK response to a WM_DDE_EXECUTE message should contain the handle
1119 * to the memory handle, we keep track (in the server side) of all pairs of handle
1120 * used (the client passes its value and the content of the memory handle), and
1121 * the server stored both values (the client, and the local one, created after the
1122 * content). When a ACK message is generated, the list of pair is searched for a
1123 * matching pair, so that the client memory handle can be returned.
1126 HGLOBAL client_hMem
;
1127 HGLOBAL server_hMem
;
1130 static struct DDE_pair
* dde_pairs
;
1131 static int dde_num_alloc
;
1132 static int dde_num_used
;
1134 static CRITICAL_SECTION dde_crst
;
1135 static CRITICAL_SECTION_DEBUG critsect_debug
=
1138 { &critsect_debug
.ProcessLocksList
, &critsect_debug
.ProcessLocksList
},
1139 0, 0, { 0, (DWORD
)(__FILE__
": dde_crst") }
1141 static CRITICAL_SECTION dde_crst
= { &critsect_debug
, -1, 0, 0, 0, 0 };
1143 static BOOL
dde_add_pair(HGLOBAL chm
, HGLOBAL shm
)
1148 EnterCriticalSection(&dde_crst
);
1150 /* now remember the pair of hMem on both sides */
1151 if (dde_num_used
== dde_num_alloc
)
1153 struct DDE_pair
* tmp
= HeapReAlloc( GetProcessHeap(), 0, dde_pairs
,
1154 (dde_num_alloc
+ GROWBY
) * sizeof(struct DDE_pair
));
1157 LeaveCriticalSection(&dde_crst
);
1161 /* zero out newly allocated part */
1162 memset(&dde_pairs
[dde_num_alloc
], 0, GROWBY
* sizeof(struct DDE_pair
));
1163 dde_num_alloc
+= GROWBY
;
1166 for (i
= 0; i
< dde_num_alloc
; i
++)
1168 if (dde_pairs
[i
].server_hMem
== 0)
1170 dde_pairs
[i
].client_hMem
= chm
;
1171 dde_pairs
[i
].server_hMem
= shm
;
1176 LeaveCriticalSection(&dde_crst
);
1180 static HGLOBAL
dde_get_pair(HGLOBAL shm
)
1185 EnterCriticalSection(&dde_crst
);
1186 for (i
= 0; i
< dde_num_alloc
; i
++)
1188 if (dde_pairs
[i
].server_hMem
== shm
)
1190 /* free this pair */
1191 dde_pairs
[i
].server_hMem
= 0;
1193 ret
= dde_pairs
[i
].client_hMem
;
1197 LeaveCriticalSection(&dde_crst
);
1201 /***********************************************************************
1204 * Post a DDE message
1206 static BOOL
post_dde_message( DWORD dest_tid
, struct packed_message
*data
, const struct send_message_info
*info
)
1212 HGLOBAL hunlock
= 0;
1216 if (!UnpackDDElParam( info
->msg
, info
->lparam
, &uiLo
, &uiHi
))
1222 /* DDE messages which don't require packing are:
1231 /* uiHi should contain a hMem from WM_DDE_EXECUTE */
1232 HGLOBAL h
= dde_get_pair( (HANDLE
)uiHi
);
1235 /* send back the value of h on the other side */
1236 push_data( data
, &h
, sizeof(HGLOBAL
) );
1238 TRACE( "send dde-ack %x %08x => %08lx\n", uiLo
, uiHi
, (DWORD
)h
);
1243 /* uiHi should contain either an atom or 0 */
1244 TRACE( "send dde-ack %x atom=%x\n", uiLo
, uiHi
);
1245 lp
= MAKELONG( uiLo
, uiHi
);
1254 size
= GlobalSize( (HGLOBAL
)uiLo
) ;
1255 if ((info
->msg
== WM_DDE_ADVISE
&& size
< sizeof(DDEADVISE
)) ||
1256 (info
->msg
== WM_DDE_DATA
&& size
< sizeof(DDEDATA
)) ||
1257 (info
->msg
== WM_DDE_POKE
&& size
< sizeof(DDEPOKE
))
1261 else if (info
->msg
!= WM_DDE_DATA
) return FALSE
;
1266 if ((ptr
= GlobalLock( (HGLOBAL
)uiLo
) ))
1268 DDEDATA
*dde_data
= (DDEDATA
*)ptr
;
1269 TRACE("unused %d, fResponse %d, fRelease %d, fDeferUpd %d, fAckReq %d, cfFormat %d\n",
1270 dde_data
->unused
, dde_data
->fResponse
, dde_data
->fRelease
,
1271 dde_data
->reserved
, dde_data
->fAckReq
, dde_data
->cfFormat
);
1272 push_data( data
, ptr
, size
);
1273 hunlock
= (HGLOBAL
)uiLo
;
1276 TRACE( "send ddepack %u %x\n", size
, uiHi
);
1278 case WM_DDE_EXECUTE
:
1281 if ((ptr
= GlobalLock( (HGLOBAL
)info
->lparam
) ))
1283 push_data(data
, ptr
, GlobalSize( (HGLOBAL
)info
->lparam
));
1284 /* so that the other side can send it back on ACK */
1286 hunlock
= (HGLOBAL
)info
->lparam
;
1291 SERVER_START_REQ( send_message
)
1294 req
->type
= info
->type
;
1296 req
->win
= info
->hwnd
;
1297 req
->msg
= info
->msg
;
1298 req
->wparam
= info
->wparam
;
1300 req
->time
= GetCurrentTime();
1302 for (i
= 0; i
< data
->count
; i
++)
1303 wine_server_add_data( req
, data
->data
[i
], data
->size
[i
] );
1304 if ((res
= wine_server_call( req
)))
1306 if (res
== STATUS_INVALID_PARAMETER
)
1307 /* FIXME: find a STATUS_ value for this one */
1308 SetLastError( ERROR_INVALID_THREAD_ID
);
1310 SetLastError( RtlNtStatusToDosError(res
) );
1313 FreeDDElParam(info
->msg
, info
->lparam
);
1316 if (hunlock
) GlobalUnlock(hunlock
);
1321 /***********************************************************************
1322 * unpack_dde_message
1324 * Unpack a posted DDE message received from another process.
1326 static BOOL
unpack_dde_message( HWND hwnd
, UINT message
, WPARAM
*wparam
, LPARAM
*lparam
,
1327 void **buffer
, size_t size
)
1338 /* hMem is being passed */
1339 if (size
!= sizeof(HGLOBAL
)) return FALSE
;
1340 if (!buffer
|| !*buffer
) return FALSE
;
1342 memcpy( &hMem
, *buffer
, size
);
1344 TRACE("recv dde-ack %x mem=%x[%lx]\n", uiLo
, uiHi
, GlobalSize( hMem
));
1348 uiLo
= LOWORD( *lparam
);
1349 uiHi
= HIWORD( *lparam
);
1350 TRACE("recv dde-ack %x atom=%x\n", uiLo
, uiHi
);
1352 *lparam
= PackDDElParam( WM_DDE_ACK
, uiLo
, uiHi
);
1357 if ((!buffer
|| !*buffer
) && message
!= WM_DDE_DATA
) return FALSE
;
1359 TRACE( "recv ddepack %u %x\n", size
, uiHi
);
1362 hMem
= GlobalAlloc( GMEM_MOVEABLE
|GMEM_DDESHARE
, size
);
1363 if (hMem
&& (ptr
= GlobalLock( hMem
)))
1365 memcpy( ptr
, *buffer
, size
);
1366 GlobalUnlock( hMem
);
1372 *lparam
= PackDDElParam( message
, uiLo
, uiHi
);
1374 case WM_DDE_EXECUTE
:
1377 if (!buffer
|| !*buffer
) return FALSE
;
1378 hMem
= GlobalAlloc( GMEM_MOVEABLE
|GMEM_DDESHARE
, size
);
1379 if (hMem
&& (ptr
= GlobalLock( hMem
)))
1381 memcpy( ptr
, *buffer
, size
);
1382 GlobalUnlock( hMem
);
1383 TRACE( "exec: pairing c=%08lx s=%08lx\n", *lparam
, (DWORD
)hMem
);
1384 if (!dde_add_pair( (HGLOBAL
)*lparam
, hMem
))
1390 } else return FALSE
;
1391 *lparam
= (LPARAM
)hMem
;
1397 /***********************************************************************
1400 * Call a window procedure and the corresponding hooks.
1402 static LRESULT
call_window_proc( HWND hwnd
, UINT msg
, WPARAM wparam
, LPARAM lparam
,
1403 BOOL unicode
, BOOL same_thread
)
1408 CWPRETSTRUCT cwpret
;
1409 MESSAGEQUEUE
*queue
= QUEUE_Current();
1411 if (queue
->recursion_count
> MAX_SENDMSG_RECURSION
) return 0;
1412 queue
->recursion_count
++;
1414 if (msg
& 0x80000000)
1416 result
= handle_internal_message( hwnd
, msg
, wparam
, lparam
);
1420 /* first the WH_CALLWNDPROC hook */
1421 hwnd
= WIN_GetFullHandle( hwnd
);
1422 cwp
.lParam
= lparam
;
1423 cwp
.wParam
= wparam
;
1426 HOOK_CallHooks( WH_CALLWNDPROC
, HC_ACTION
, same_thread
, (LPARAM
)&cwp
, unicode
);
1428 /* now call the window procedure */
1431 if (!(winproc
= (WNDPROC
)GetWindowLongW( hwnd
, GWL_WNDPROC
))) goto done
;
1432 result
= CallWindowProcW( winproc
, hwnd
, msg
, wparam
, lparam
);
1436 if (!(winproc
= (WNDPROC
)GetWindowLongA( hwnd
, GWL_WNDPROC
))) goto done
;
1437 result
= CallWindowProcA( winproc
, hwnd
, msg
, wparam
, lparam
);
1440 /* and finally the WH_CALLWNDPROCRET hook */
1441 cwpret
.lResult
= result
;
1442 cwpret
.lParam
= lparam
;
1443 cwpret
.wParam
= wparam
;
1444 cwpret
.message
= msg
;
1446 HOOK_CallHooks( WH_CALLWNDPROCRET
, HC_ACTION
, same_thread
, (LPARAM
)&cwpret
, unicode
);
1448 queue
->recursion_count
--;
1453 /***********************************************************************
1454 * process_hardware_message
1456 * Process a hardware message; return TRUE if message should be passed on to the app
1458 static BOOL
process_hardware_message( MSG
*msg
, ULONG_PTR extra_info
, HWND hwnd
,
1459 UINT first
, UINT last
, BOOL remove
)
1463 if (!MSG_process_raw_hardware_message( msg
, extra_info
, hwnd
, first
, last
, remove
))
1466 ret
= MSG_process_cooked_hardware_message( msg
, extra_info
, remove
);
1468 /* tell the server we have passed it to the app
1469 * (even though we may end up dropping it later on)
1471 SERVER_START_REQ( reply_message
)
1473 req
->type
= MSG_HARDWARE
;
1475 req
->remove
= remove
|| !ret
;
1476 wine_server_call( req
);
1483 /***********************************************************************
1484 * call_sendmsg_callback
1486 * Call the callback function of SendMessageCallback.
1488 static inline void call_sendmsg_callback( SENDASYNCPROC callback
, HWND hwnd
, UINT msg
,
1489 ULONG_PTR data
, LRESULT result
)
1491 if (TRACE_ON(relay
))
1492 DPRINTF( "%04lx:Call message callback %p (hwnd=%p,msg=%s,data=%08lx,result=%08lx)\n",
1493 GetCurrentThreadId(), callback
, hwnd
, SPY_GetMsgName( msg
, hwnd
),
1495 callback( hwnd
, msg
, data
, result
);
1496 if (TRACE_ON(relay
))
1497 DPRINTF( "%04lx:Ret message callback %p (hwnd=%p,msg=%s,data=%08lx,result=%08lx)\n",
1498 GetCurrentThreadId(), callback
, hwnd
, SPY_GetMsgName( msg
, hwnd
),
1503 /***********************************************************************
1506 * Peek for a message matching the given parameters. Return FALSE if none available.
1507 * All pending sent messages are processed before returning.
1509 BOOL
MSG_peek_message( MSG
*msg
, HWND hwnd
, UINT first
, UINT last
, int flags
)
1512 ULONG_PTR extra_info
= 0;
1513 MESSAGEQUEUE
*queue
= QUEUE_Current();
1514 struct received_message_info info
, *old_info
;
1516 if (!first
&& !last
) last
= ~0;
1521 void *buffer
= NULL
;
1522 size_t size
= 0, buffer_size
= 0;
1524 do /* loop while buffer is too small */
1526 if (buffer_size
&& !(buffer
= HeapAlloc( GetProcessHeap(), 0, buffer_size
)))
1528 SERVER_START_REQ( get_message
)
1531 req
->get_win
= hwnd
;
1532 req
->get_first
= first
;
1533 req
->get_last
= last
;
1534 if (buffer_size
) wine_server_set_reply( req
, buffer
, buffer_size
);
1535 if (!(res
= wine_server_call( req
)))
1537 size
= wine_server_reply_size( reply
);
1538 info
.type
= reply
->type
;
1539 info
.msg
.hwnd
= reply
->win
;
1540 info
.msg
.message
= reply
->msg
;
1541 info
.msg
.wParam
= reply
->wparam
;
1542 info
.msg
.lParam
= reply
->lparam
;
1543 info
.msg
.time
= reply
->time
;
1544 info
.msg
.pt
.x
= reply
->x
;
1545 info
.msg
.pt
.y
= reply
->y
;
1546 extra_info
= reply
->info
;
1550 if (buffer
) HeapFree( GetProcessHeap(), 0, buffer
);
1551 buffer_size
= reply
->total
;
1555 } while (res
== STATUS_BUFFER_OVERFLOW
);
1557 if (res
) return FALSE
;
1559 TRACE( "got type %d msg %x (%s) hwnd %p wp %x lp %lx\n",
1560 info
.type
, info
.msg
.message
, SPY_GetMsgName(info
.msg
.message
, info
.msg
.hwnd
),
1561 info
.msg
.hwnd
, info
.msg
.wParam
, info
.msg
.lParam
);
1567 info
.flags
= ISMEX_SEND
;
1570 info
.flags
= ISMEX_NOTIFY
;
1573 info
.flags
= ISMEX_CALLBACK
;
1575 case MSG_CALLBACK_RESULT
:
1576 call_sendmsg_callback( (SENDASYNCPROC
)info
.msg
.wParam
, info
.msg
.hwnd
,
1577 info
.msg
.message
, extra_info
, info
.msg
.lParam
);
1579 case MSG_OTHER_PROCESS
:
1580 info
.flags
= ISMEX_SEND
;
1581 if (!unpack_message( info
.msg
.hwnd
, info
.msg
.message
, &info
.msg
.wParam
,
1582 &info
.msg
.lParam
, &buffer
, size
))
1584 ERR( "invalid packed message %x (%s) hwnd %p wp %x lp %lx size %d\n",
1585 info
.msg
.message
, SPY_GetMsgName(info
.msg
.message
, info
.msg
.hwnd
), info
.msg
.hwnd
,
1586 info
.msg
.wParam
, info
.msg
.lParam
, size
);
1588 reply_message( &info
, 0, TRUE
);
1593 if (!process_hardware_message( &info
.msg
, extra_info
,
1594 hwnd
, first
, last
, flags
& GET_MSG_REMOVE
))
1596 TRACE("dropping msg %x\n", info
.msg
.message
);
1597 goto next
; /* ignore it */
1599 queue
->GetMessagePosVal
= MAKELONG( info
.msg
.pt
.x
, info
.msg
.pt
.y
);
1602 queue
->GetMessageExtraInfoVal
= extra_info
;
1603 if (info
.msg
.message
>= WM_DDE_FIRST
&& info
.msg
.message
<= WM_DDE_LAST
)
1605 if (!unpack_dde_message( info
.msg
.hwnd
, info
.msg
.message
, &info
.msg
.wParam
,
1606 &info
.msg
.lParam
, &buffer
, size
))
1608 ERR( "invalid packed dde-message %x (%s) hwnd %p wp %x lp %lx size %d\n",
1609 info
.msg
.message
, SPY_GetMsgName(info
.msg
.message
, info
.msg
.hwnd
),
1610 info
.msg
.hwnd
, info
.msg
.wParam
, info
.msg
.lParam
, size
);
1611 goto next
; /* ignore it */
1615 if (buffer
) HeapFree( GetProcessHeap(), 0, buffer
);
1619 /* if we get here, we have a sent message; call the window procedure */
1620 old_info
= queue
->receive_info
;
1621 queue
->receive_info
= &info
;
1622 result
= call_window_proc( info
.msg
.hwnd
, info
.msg
.message
, info
.msg
.wParam
,
1623 info
.msg
.lParam
, (info
.type
!= MSG_ASCII
), FALSE
);
1624 reply_message( &info
, result
, TRUE
);
1625 queue
->receive_info
= old_info
;
1627 if (buffer
) HeapFree( GetProcessHeap(), 0, buffer
);
1632 /***********************************************************************
1633 * wait_message_reply
1635 * Wait until a sent message gets replied to.
1637 static void wait_message_reply( UINT flags
)
1639 MESSAGEQUEUE
*queue
;
1641 if (!(queue
= QUEUE_Current())) return;
1645 unsigned int wake_bits
= 0, changed_bits
= 0;
1648 SERVER_START_REQ( set_queue_mask
)
1650 req
->wake_mask
= QS_SMRESULT
| ((flags
& SMTO_BLOCK
) ? 0 : QS_SENDMESSAGE
);
1651 req
->changed_mask
= req
->wake_mask
;
1653 if (!wine_server_call( req
))
1655 wake_bits
= reply
->wake_bits
;
1656 changed_bits
= reply
->changed_bits
;
1661 if (wake_bits
& QS_SMRESULT
) return; /* got a result */
1662 if (wake_bits
& QS_SENDMESSAGE
)
1664 /* Process the sent message immediately */
1666 MSG_peek_message( &msg
, 0, 0, 0, GET_MSG_REMOVE
| GET_MSG_SENT_ONLY
);
1670 /* now wait for it */
1672 ReleaseThunkLock( &dwlc
);
1674 if (USER_Driver
.pMsgWaitForMultipleObjectsEx
)
1675 res
= USER_Driver
.pMsgWaitForMultipleObjectsEx( 1, &queue
->server_queue
,
1678 res
= WaitForSingleObject( queue
->server_queue
, INFINITE
);
1680 if (dwlc
) RestoreThunkLock( dwlc
);
1684 /***********************************************************************
1685 * put_message_in_queue
1687 * Put a sent message into the destination queue.
1688 * For inter-process message, reply_size is set to expected size of reply data.
1690 static BOOL
put_message_in_queue( DWORD dest_tid
, const struct send_message_info
*info
,
1691 size_t *reply_size
)
1693 struct packed_message data
;
1695 int i
, timeout
= -1;
1697 if (info
->type
!= MSG_NOTIFY
&&
1698 info
->type
!= MSG_CALLBACK
&&
1699 info
->type
!= MSG_POSTED
&&
1700 info
->timeout
!= INFINITE
)
1701 timeout
= info
->timeout
;
1704 if (info
->type
== MSG_OTHER_PROCESS
)
1706 *reply_size
= pack_message( info
->hwnd
, info
->msg
, info
->wparam
, info
->lparam
, &data
);
1707 if (data
.count
== -1)
1709 WARN( "cannot pack message %x\n", info
->msg
);
1713 else if (info
->type
== MSG_POSTED
&& info
->msg
>= WM_DDE_FIRST
&& info
->msg
<= WM_DDE_LAST
)
1715 return post_dde_message( dest_tid
, &data
, info
);
1718 SERVER_START_REQ( send_message
)
1721 req
->type
= info
->type
;
1723 req
->win
= info
->hwnd
;
1724 req
->msg
= info
->msg
;
1725 req
->wparam
= info
->wparam
;
1726 req
->lparam
= info
->lparam
;
1727 req
->time
= GetCurrentTime();
1728 req
->timeout
= timeout
;
1730 if (info
->type
== MSG_CALLBACK
)
1732 req
->callback
= info
->callback
;
1733 req
->info
= info
->data
;
1736 if (info
->flags
& SMTO_ABORTIFHUNG
) req
->flags
|= SEND_MSG_ABORT_IF_HUNG
;
1737 for (i
= 0; i
< data
.count
; i
++) wine_server_add_data( req
, data
.data
[i
], data
.size
[i
] );
1738 if ((res
= wine_server_call( req
)))
1740 if (res
== STATUS_INVALID_PARAMETER
)
1741 /* FIXME: find a STATUS_ value for this one */
1742 SetLastError( ERROR_INVALID_THREAD_ID
);
1744 SetLastError( RtlNtStatusToDosError(res
) );
1752 /***********************************************************************
1755 * Retrieve a message reply from the server.
1757 static LRESULT
retrieve_reply( const struct send_message_info
*info
,
1758 size_t reply_size
, LRESULT
*result
)
1761 void *reply_data
= NULL
;
1765 if (!(reply_data
= HeapAlloc( GetProcessHeap(), 0, reply_size
)))
1767 WARN( "no memory for reply %d bytes, will be truncated\n", reply_size
);
1771 SERVER_START_REQ( get_message_reply
)
1774 if (reply_size
) wine_server_set_reply( req
, reply_data
, reply_size
);
1775 if (!(status
= wine_server_call( req
))) *result
= reply
->result
;
1776 reply_size
= wine_server_reply_size( reply
);
1779 if (!status
&& reply_size
)
1780 unpack_reply( info
->hwnd
, info
->msg
, info
->wparam
, info
->lparam
, reply_data
, reply_size
);
1782 if (reply_data
) HeapFree( GetProcessHeap(), 0, reply_data
);
1784 TRACE( "hwnd %p msg %x (%s) wp %x lp %lx got reply %lx (err=%ld)\n",
1785 info
->hwnd
, info
->msg
, SPY_GetMsgName(info
->msg
, info
->hwnd
), info
->wparam
,
1786 info
->lparam
, *result
, status
);
1788 /* MSDN states that last error is 0 on timeout, but at least NT4 returns ERROR_TIMEOUT */
1789 if (status
) SetLastError( RtlNtStatusToDosError(status
) );
1794 /***********************************************************************
1795 * send_inter_thread_message
1797 static LRESULT
send_inter_thread_message( DWORD dest_tid
, const struct send_message_info
*info
,
1802 size_t reply_size
= 0;
1804 TRACE( "hwnd %p msg %x (%s) wp %x lp %lx\n",
1805 info
->hwnd
, info
->msg
, SPY_GetMsgName(info
->msg
, info
->hwnd
), info
->wparam
, info
->lparam
);
1807 if (!put_message_in_queue( dest_tid
, info
, &reply_size
)) return 0;
1809 /* there's no reply to wait for on notify/callback messages */
1810 if (info
->type
== MSG_NOTIFY
|| info
->type
== MSG_CALLBACK
) return 1;
1812 locks
= WIN_SuspendWndsLock();
1814 wait_message_reply( info
->flags
);
1815 ret
= retrieve_reply( info
, reply_size
, res_ptr
);
1817 WIN_RestoreWndsLock( locks
);
1822 /***********************************************************************
1823 * MSG_SendInternalMessageTimeout
1825 * Same as SendMessageTimeoutW but sends the message to a specific thread
1826 * without requiring a window handle. Only works for internal Wine messages.
1828 LRESULT
MSG_SendInternalMessageTimeout( DWORD dest_pid
, DWORD dest_tid
,
1829 UINT msg
, WPARAM wparam
, LPARAM lparam
,
1830 UINT flags
, UINT timeout
, PDWORD_PTR res_ptr
)
1832 struct send_message_info info
;
1833 LRESULT ret
, result
;
1835 assert( msg
& 0x80000000 ); /* must be an internal Wine message */
1837 info
.type
= MSG_UNICODE
;
1840 info
.wparam
= wparam
;
1841 info
.lparam
= lparam
;
1843 info
.timeout
= timeout
;
1845 if (USER_IsExitingThread( dest_tid
)) return 0;
1847 if (dest_tid
== GetCurrentThreadId())
1849 result
= handle_internal_message( 0, msg
, wparam
, lparam
);
1854 if (dest_pid
!= GetCurrentProcessId()) info
.type
= MSG_OTHER_PROCESS
;
1855 ret
= send_inter_thread_message( dest_tid
, &info
, &result
);
1857 if (ret
&& res_ptr
) *res_ptr
= result
;
1862 /***********************************************************************
1863 * SendMessageTimeoutW (USER32.@)
1865 LRESULT WINAPI
SendMessageTimeoutW( HWND hwnd
, UINT msg
, WPARAM wparam
, LPARAM lparam
,
1866 UINT flags
, UINT timeout
, PDWORD_PTR res_ptr
)
1868 struct send_message_info info
;
1869 DWORD dest_tid
, dest_pid
;
1870 LRESULT ret
, result
;
1872 info
.type
= MSG_UNICODE
;
1875 info
.wparam
= wparam
;
1876 info
.lparam
= lparam
;
1878 info
.timeout
= timeout
;
1880 if (is_broadcast(hwnd
))
1882 EnumWindows( broadcast_message_callback
, (LPARAM
)&info
);
1883 if (res_ptr
) *res_ptr
= 1;
1887 if (!(dest_tid
= GetWindowThreadProcessId( hwnd
, &dest_pid
))) return 0;
1889 if (USER_IsExitingThread( dest_tid
)) return 0;
1891 SPY_EnterMessage( SPY_SENDMESSAGE
, hwnd
, msg
, wparam
, lparam
);
1893 if (dest_tid
== GetCurrentThreadId())
1895 result
= call_window_proc( hwnd
, msg
, wparam
, lparam
, TRUE
, TRUE
);
1900 if (dest_pid
!= GetCurrentProcessId()) info
.type
= MSG_OTHER_PROCESS
;
1901 ret
= send_inter_thread_message( dest_tid
, &info
, &result
);
1904 SPY_ExitMessage( SPY_RESULT_OK
, hwnd
, msg
, result
, wparam
, lparam
);
1905 if (ret
&& res_ptr
) *res_ptr
= result
;
1910 /***********************************************************************
1911 * SendMessageTimeoutA (USER32.@)
1913 LRESULT WINAPI
SendMessageTimeoutA( HWND hwnd
, UINT msg
, WPARAM wparam
, LPARAM lparam
,
1914 UINT flags
, UINT timeout
, PDWORD_PTR res_ptr
)
1916 struct send_message_info info
;
1917 DWORD dest_tid
, dest_pid
;
1918 LRESULT ret
, result
;
1920 info
.type
= MSG_ASCII
;
1923 info
.wparam
= wparam
;
1924 info
.lparam
= lparam
;
1926 info
.timeout
= timeout
;
1928 if (is_broadcast(hwnd
))
1930 EnumWindows( broadcast_message_callback
, (LPARAM
)&info
);
1931 if (res_ptr
) *res_ptr
= 1;
1935 if (!(dest_tid
= GetWindowThreadProcessId( hwnd
, &dest_pid
))) return 0;
1937 if (USER_IsExitingThread( dest_tid
)) return 0;
1939 SPY_EnterMessage( SPY_SENDMESSAGE
, hwnd
, msg
, wparam
, lparam
);
1941 if (dest_tid
== GetCurrentThreadId())
1943 result
= call_window_proc( hwnd
, msg
, wparam
, lparam
, FALSE
, TRUE
);
1946 else if (dest_pid
== GetCurrentProcessId())
1948 ret
= send_inter_thread_message( dest_tid
, &info
, &result
);
1952 /* inter-process message: need to map to Unicode */
1953 info
.type
= MSG_OTHER_PROCESS
;
1954 if (is_unicode_message( info
.msg
))
1956 if (WINPROC_MapMsg32ATo32W( info
.hwnd
, info
.msg
, &info
.wparam
, &info
.lparam
) == -1)
1958 ret
= send_inter_thread_message( dest_tid
, &info
, &result
);
1959 result
= WINPROC_UnmapMsg32ATo32W( info
.hwnd
, info
.msg
, info
.wparam
,
1960 info
.lparam
, result
);
1962 else ret
= send_inter_thread_message( dest_tid
, &info
, &result
);
1964 SPY_ExitMessage( SPY_RESULT_OK
, hwnd
, msg
, result
, wparam
, lparam
);
1965 if (ret
&& res_ptr
) *res_ptr
= result
;
1970 /***********************************************************************
1971 * SendMessageW (USER32.@)
1973 LRESULT WINAPI
SendMessageW( HWND hwnd
, UINT msg
, WPARAM wparam
, LPARAM lparam
)
1976 SendMessageTimeoutW( hwnd
, msg
, wparam
, lparam
, SMTO_NORMAL
, INFINITE
, &res
);
1981 /***********************************************************************
1982 * SendMessageA (USER32.@)
1984 LRESULT WINAPI
SendMessageA( HWND hwnd
, UINT msg
, WPARAM wparam
, LPARAM lparam
)
1987 SendMessageTimeoutA( hwnd
, msg
, wparam
, lparam
, SMTO_NORMAL
, INFINITE
, &res
);
1992 /***********************************************************************
1993 * SendNotifyMessageA (USER32.@)
1995 BOOL WINAPI
SendNotifyMessageA( HWND hwnd
, UINT msg
, WPARAM wparam
, LPARAM lparam
)
1997 return SendNotifyMessageW( hwnd
, msg
, map_wparam_AtoW( msg
, wparam
), lparam
);
2001 /***********************************************************************
2002 * SendNotifyMessageW (USER32.@)
2004 BOOL WINAPI
SendNotifyMessageW( HWND hwnd
, UINT msg
, WPARAM wparam
, LPARAM lparam
)
2006 struct send_message_info info
;
2010 if (is_pointer_message(msg
))
2012 SetLastError(ERROR_INVALID_PARAMETER
);
2016 info
.type
= MSG_NOTIFY
;
2019 info
.wparam
= wparam
;
2020 info
.lparam
= lparam
;
2022 if (is_broadcast(hwnd
))
2024 EnumWindows( broadcast_message_callback
, (LPARAM
)&info
);
2028 if (!(dest_tid
= GetWindowThreadProcessId( hwnd
, NULL
))) return FALSE
;
2030 if (USER_IsExitingThread( dest_tid
)) return TRUE
;
2032 if (dest_tid
== GetCurrentThreadId())
2034 call_window_proc( hwnd
, msg
, wparam
, lparam
, TRUE
, TRUE
);
2037 return send_inter_thread_message( dest_tid
, &info
, &result
);
2041 /***********************************************************************
2042 * SendMessageCallbackA (USER32.@)
2044 BOOL WINAPI
SendMessageCallbackA( HWND hwnd
, UINT msg
, WPARAM wparam
, LPARAM lparam
,
2045 SENDASYNCPROC callback
, ULONG_PTR data
)
2047 return SendMessageCallbackW( hwnd
, msg
, map_wparam_AtoW( msg
, wparam
),
2048 lparam
, callback
, data
);
2052 /***********************************************************************
2053 * SendMessageCallbackW (USER32.@)
2055 BOOL WINAPI
SendMessageCallbackW( HWND hwnd
, UINT msg
, WPARAM wparam
, LPARAM lparam
,
2056 SENDASYNCPROC callback
, ULONG_PTR data
)
2058 struct send_message_info info
;
2062 if (is_pointer_message(msg
))
2064 SetLastError(ERROR_INVALID_PARAMETER
);
2068 info
.type
= MSG_CALLBACK
;
2071 info
.wparam
= wparam
;
2072 info
.lparam
= lparam
;
2073 info
.callback
= callback
;
2076 if (is_broadcast(hwnd
))
2078 EnumWindows( broadcast_message_callback
, (LPARAM
)&info
);
2082 if (!(dest_tid
= GetWindowThreadProcessId( hwnd
, NULL
))) return FALSE
;
2084 if (USER_IsExitingThread( dest_tid
)) return TRUE
;
2086 if (dest_tid
== GetCurrentThreadId())
2088 result
= call_window_proc( hwnd
, msg
, wparam
, lparam
, TRUE
, TRUE
);
2089 call_sendmsg_callback( callback
, hwnd
, msg
, data
, result
);
2092 FIXME( "callback will not be called\n" );
2093 return send_inter_thread_message( dest_tid
, &info
, &result
);
2097 /***********************************************************************
2098 * ReplyMessage (USER32.@)
2100 BOOL WINAPI
ReplyMessage( LRESULT result
)
2102 MESSAGEQUEUE
*queue
= QUEUE_Current();
2103 struct received_message_info
*info
= queue
->receive_info
;
2105 if (!info
) return FALSE
;
2106 reply_message( info
, result
, FALSE
);
2111 /***********************************************************************
2112 * InSendMessage (USER32.@)
2114 BOOL WINAPI
InSendMessage(void)
2116 return (InSendMessageEx(NULL
) & (ISMEX_SEND
|ISMEX_REPLIED
)) == ISMEX_SEND
;
2120 /***********************************************************************
2121 * InSendMessageEx (USER32.@)
2123 DWORD WINAPI
InSendMessageEx( LPVOID reserved
)
2125 MESSAGEQUEUE
*queue
= QUEUE_Current();
2126 struct received_message_info
*info
= queue
->receive_info
;
2128 if (info
) return info
->flags
;
2129 return ISMEX_NOSEND
;
2133 /***********************************************************************
2134 * PostMessageA (USER32.@)
2136 BOOL WINAPI
PostMessageA( HWND hwnd
, UINT msg
, WPARAM wparam
, LPARAM lparam
)
2138 return PostMessageW( hwnd
, msg
, map_wparam_AtoW( msg
, wparam
), lparam
);
2142 /***********************************************************************
2143 * PostMessageW (USER32.@)
2145 BOOL WINAPI
PostMessageW( HWND hwnd
, UINT msg
, WPARAM wparam
, LPARAM lparam
)
2147 struct send_message_info info
;
2150 if (is_pointer_message( msg
))
2152 SetLastError( ERROR_INVALID_PARAMETER
);
2156 TRACE( "hwnd %p msg %x (%s) wp %x lp %lx\n",
2157 hwnd
, msg
, SPY_GetMsgName(msg
, hwnd
), wparam
, lparam
);
2159 info
.type
= MSG_POSTED
;
2162 info
.wparam
= wparam
;
2163 info
.lparam
= lparam
;
2165 if (is_broadcast(hwnd
))
2167 EnumWindows( broadcast_message_callback
, (LPARAM
)&info
);
2171 if (!hwnd
) return PostThreadMessageW( GetCurrentThreadId(), msg
, wparam
, lparam
);
2173 if (!(dest_tid
= GetWindowThreadProcessId( hwnd
, NULL
))) return FALSE
;
2175 if (USER_IsExitingThread( dest_tid
)) return TRUE
;
2177 return put_message_in_queue( dest_tid
, &info
, NULL
);
2181 /**********************************************************************
2182 * PostThreadMessageA (USER32.@)
2184 BOOL WINAPI
PostThreadMessageA( DWORD thread
, UINT msg
, WPARAM wparam
, LPARAM lparam
)
2186 return PostThreadMessageW( thread
, msg
, map_wparam_AtoW( msg
, wparam
), lparam
);
2190 /**********************************************************************
2191 * PostThreadMessageW (USER32.@)
2193 BOOL WINAPI
PostThreadMessageW( DWORD thread
, UINT msg
, WPARAM wparam
, LPARAM lparam
)
2195 struct send_message_info info
;
2197 if (is_pointer_message( msg
))
2199 SetLastError( ERROR_INVALID_PARAMETER
);
2202 if (USER_IsExitingThread( thread
)) return TRUE
;
2204 info
.type
= MSG_POSTED
;
2207 info
.wparam
= wparam
;
2208 info
.lparam
= lparam
;
2209 return put_message_in_queue( thread
, &info
, NULL
);
2213 /***********************************************************************
2214 * PostQuitMessage (USER32.@)
2216 void WINAPI
PostQuitMessage( INT exitCode
)
2218 PostThreadMessageW( GetCurrentThreadId(), WM_QUIT
, exitCode
, 0 );
2222 /***********************************************************************
2223 * PeekMessageW (USER32.@)
2225 BOOL WINAPI
PeekMessageW( MSG
*msg_out
, HWND hwnd
, UINT first
, UINT last
, UINT flags
)
2227 MESSAGEQUEUE
*queue
;
2231 /* check for graphics events */
2232 if (USER_Driver
.pMsgWaitForMultipleObjectsEx
)
2233 USER_Driver
.pMsgWaitForMultipleObjectsEx( 0, NULL
, 0, 0, 0 );
2235 hwnd
= WIN_GetFullHandle( hwnd
);
2236 locks
= WIN_SuspendWndsLock();
2238 if (!MSG_peek_message( &msg
, hwnd
, first
, last
,
2239 (flags
& PM_REMOVE
) ? GET_MSG_REMOVE
: 0 ))
2241 if (!(flags
& PM_NOYIELD
))
2244 ReleaseThunkLock(&count
);
2245 if (count
) RestoreThunkLock(count
);
2247 WIN_RestoreWndsLock( locks
);
2251 WIN_RestoreWndsLock( locks
);
2253 /* need to fill the window handle for WM_PAINT message */
2254 if (msg
.message
== WM_PAINT
)
2256 if (IsIconic( msg
.hwnd
) && GetClassLongA( msg
.hwnd
, GCL_HICON
))
2258 msg
.message
= WM_PAINTICON
;
2261 /* clear internal paint flag */
2262 RedrawWindow( msg
.hwnd
, NULL
, 0, RDW_NOINTERNALPAINT
| RDW_NOCHILDREN
);
2265 if ((queue
= QUEUE_Current()))
2267 queue
->GetMessageTimeVal
= msg
.time
;
2268 msg
.pt
.x
= LOWORD( queue
->GetMessagePosVal
);
2269 msg
.pt
.y
= HIWORD( queue
->GetMessagePosVal
);
2272 HOOK_CallHooks( WH_GETMESSAGE
, HC_ACTION
, flags
& PM_REMOVE
, (LPARAM
)&msg
, TRUE
);
2274 /* copy back our internal safe copy of message data to msg_out.
2275 * msg_out is a variable from the *program*, so it can't be used
2276 * internally as it can get "corrupted" by our use of SendMessage()
2277 * (back to the program) inside the message handling itself. */
2283 /***********************************************************************
2284 * PeekMessageA (USER32.@)
2286 BOOL WINAPI
PeekMessageA( MSG
*msg
, HWND hwnd
, UINT first
, UINT last
, UINT flags
)
2288 BOOL ret
= PeekMessageW( msg
, hwnd
, first
, last
, flags
);
2289 if (ret
) msg
->wParam
= map_wparam_WtoA( msg
->message
, msg
->wParam
);
2294 /***********************************************************************
2295 * GetMessageW (USER32.@)
2297 BOOL WINAPI
GetMessageW( MSG
*msg
, HWND hwnd
, UINT first
, UINT last
)
2299 MESSAGEQUEUE
*queue
= QUEUE_Current();
2302 mask
= QS_POSTMESSAGE
| QS_SENDMESSAGE
; /* Always selected */
2305 if ((first
<= WM_KEYLAST
) && (last
>= WM_KEYFIRST
)) mask
|= QS_KEY
;
2306 if ( ((first
<= WM_MOUSELAST
) && (last
>= WM_MOUSEFIRST
)) ||
2307 ((first
<= WM_NCMOUSELAST
) && (last
>= WM_NCMOUSEFIRST
)) ) mask
|= QS_MOUSE
;
2308 if ((first
<= WM_TIMER
) && (last
>= WM_TIMER
)) mask
|= QS_TIMER
;
2309 if ((first
<= WM_SYSTIMER
) && (last
>= WM_SYSTIMER
)) mask
|= QS_TIMER
;
2310 if ((first
<= WM_PAINT
) && (last
>= WM_PAINT
)) mask
|= QS_PAINT
;
2312 else mask
|= QS_MOUSE
| QS_KEY
| QS_TIMER
| QS_PAINT
;
2314 locks
= WIN_SuspendWndsLock();
2316 while (!PeekMessageW( msg
, hwnd
, first
, last
, PM_REMOVE
))
2318 /* wait until one of the bits is set */
2319 unsigned int wake_bits
= 0, changed_bits
= 0;
2322 SERVER_START_REQ( set_queue_mask
)
2324 req
->wake_mask
= QS_SENDMESSAGE
;
2325 req
->changed_mask
= mask
;
2327 if (!wine_server_call( req
))
2329 wake_bits
= reply
->wake_bits
;
2330 changed_bits
= reply
->changed_bits
;
2335 if (changed_bits
& mask
) continue;
2336 if (wake_bits
& QS_SENDMESSAGE
) continue;
2338 TRACE( "(%04x) mask=%08x, bits=%08x, changed=%08x, waiting\n",
2339 queue
->self
, mask
, wake_bits
, changed_bits
);
2341 ReleaseThunkLock( &dwlc
);
2342 if (USER_Driver
.pMsgWaitForMultipleObjectsEx
)
2343 USER_Driver
.pMsgWaitForMultipleObjectsEx( 1, &queue
->server_queue
, INFINITE
, 0, 0 );
2345 WaitForSingleObject( queue
->server_queue
, INFINITE
);
2346 if (dwlc
) RestoreThunkLock( dwlc
);
2349 WIN_RestoreWndsLock( locks
);
2351 return (msg
->message
!= WM_QUIT
);
2355 /***********************************************************************
2356 * GetMessageA (USER32.@)
2358 BOOL WINAPI
GetMessageA( MSG
*msg
, HWND hwnd
, UINT first
, UINT last
)
2360 GetMessageW( msg
, hwnd
, first
, last
);
2361 msg
->wParam
= map_wparam_WtoA( msg
->message
, msg
->wParam
);
2362 return (msg
->message
!= WM_QUIT
);
2366 /***********************************************************************
2367 * IsDialogMessage (USER32.@)
2368 * IsDialogMessageA (USER32.@)
2370 BOOL WINAPI
IsDialogMessageA( HWND hwndDlg
, LPMSG pmsg
)
2373 msg
.wParam
= map_wparam_AtoW( msg
.message
, msg
.wParam
);
2374 return IsDialogMessageW( hwndDlg
, &msg
);
2378 /***********************************************************************
2379 * SetMessageQueue (USER32.@)
2381 BOOL WINAPI
SetMessageQueue( INT size
)
2383 /* now obsolete the message queue will be expanded dynamically as necessary */
2388 /**********************************************************************
2389 * AttachThreadInput (USER32.@)
2391 * Attaches the input processing mechanism of one thread to that of
2394 BOOL WINAPI
AttachThreadInput( DWORD from
, DWORD to
, BOOL attach
)
2398 SERVER_START_REQ( attach_thread_input
)
2400 req
->tid_from
= from
;
2402 req
->attach
= attach
;
2403 ret
= !wine_server_call_err( req
);
2410 /**********************************************************************
2411 * GetGUIThreadInfo (USER32.@)
2413 BOOL WINAPI
GetGUIThreadInfo( DWORD id
, GUITHREADINFO
*info
)
2417 SERVER_START_REQ( get_thread_input
)
2420 if ((ret
= !wine_server_call_err( req
)))
2423 info
->hwndActive
= reply
->active
;
2424 info
->hwndFocus
= reply
->focus
;
2425 info
->hwndCapture
= reply
->capture
;
2426 info
->hwndMenuOwner
= reply
->menu_owner
;
2427 info
->hwndMoveSize
= reply
->move_size
;
2428 info
->hwndCaret
= reply
->caret
;
2429 info
->rcCaret
.left
= reply
->rect
.left
;
2430 info
->rcCaret
.top
= reply
->rect
.top
;
2431 info
->rcCaret
.right
= reply
->rect
.right
;
2432 info
->rcCaret
.bottom
= reply
->rect
.bottom
;
2433 if (reply
->menu_owner
) info
->flags
|= GUI_INMENUMODE
;
2434 if (reply
->move_size
) info
->flags
|= GUI_INMOVESIZE
;
2435 if (reply
->caret
) info
->flags
|= GUI_CARETBLINKING
;
2443 /**********************************************************************
2444 * GetKeyState (USER32.@)
2446 * An application calls the GetKeyState function in response to a
2447 * keyboard-input message. This function retrieves the state of the key
2448 * at the time the input message was generated.
2450 SHORT WINAPI
GetKeyState(INT vkey
)
2454 SERVER_START_REQ( get_key_state
)
2456 req
->tid
= GetCurrentThreadId();
2458 if (!wine_server_call( req
)) retval
= (signed char)reply
->state
;
2461 TRACE("key (0x%x) -> %x\n", vkey
, retval
);
2466 /**********************************************************************
2467 * GetKeyboardState (USER32.@)
2469 BOOL WINAPI
GetKeyboardState( LPBYTE state
)
2473 TRACE("(%p)\n", state
);
2475 memset( state
, 0, 256 );
2476 SERVER_START_REQ( get_key_state
)
2478 req
->tid
= GetCurrentThreadId();
2480 wine_server_set_reply( req
, state
, 256 );
2481 ret
= !wine_server_call_err( req
);
2488 /**********************************************************************
2489 * SetKeyboardState (USER32.@)
2491 BOOL WINAPI
SetKeyboardState( LPBYTE state
)
2495 TRACE("(%p)\n", state
);
2497 SERVER_START_REQ( set_key_state
)
2499 req
->tid
= GetCurrentThreadId();
2500 wine_server_add_data( req
, state
, 256 );
2501 ret
= !wine_server_call_err( req
);