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., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
22 #include "wine/port.h"
28 #define WIN32_NO_STATUS
37 #include "wine/unicode.h"
38 #include "wine/server.h"
39 #include "user_private.h"
43 #include "wine/debug.h"
45 WINE_DEFAULT_DEBUG_CHANNEL(msg
);
46 WINE_DECLARE_DEBUG_CHANNEL(relay
);
47 WINE_DECLARE_DEBUG_CHANNEL(key
);
49 #define WM_NCMOUSEFIRST WM_NCMOUSEMOVE
50 #define WM_NCMOUSELAST (WM_NCMOUSEFIRST+(WM_MOUSELAST-WM_MOUSEFIRST))
52 #define MAX_PACK_COUNT 4
53 #define MAX_SENDMSG_RECURSION 64
55 #define SYS_TIMER_RATE 55 /* min. timer rate in ms (actually 54.925)*/
57 /* description of the data fields that need to be packed along with a sent message */
61 const void *data
[MAX_PACK_COUNT
];
62 size_t size
[MAX_PACK_COUNT
];
65 /* info about the message currently being received by the current thread */
66 struct received_message_info
68 enum message_type type
;
70 UINT flags
; /* InSendMessageEx return flags */
73 /* structure to group all parameters for sent messages of the various kinds */
74 struct send_message_info
76 enum message_type type
;
82 UINT flags
; /* flags for SendMessageTimeout */
83 UINT timeout
; /* timeout for SendMessageTimeout */
84 SENDASYNCPROC callback
; /* callback function for SendMessageCallback */
85 ULONG_PTR data
; /* callback data */
89 /* flag for messages that contain pointers */
90 /* 32 messages per entry, messages 0..31 map to bits 0..31 */
92 #define SET(msg) (1 << ((msg) & 31))
94 static const unsigned int message_pointer_flags
[] =
97 SET(WM_CREATE
) | SET(WM_SETTEXT
) | SET(WM_GETTEXT
) |
98 SET(WM_WININICHANGE
) | SET(WM_DEVMODECHANGE
),
100 SET(WM_GETMINMAXINFO
) | SET(WM_DRAWITEM
) | SET(WM_MEASUREITEM
) | SET(WM_DELETEITEM
) |
103 SET(WM_WINDOWPOSCHANGING
) | SET(WM_WINDOWPOSCHANGED
) | SET(WM_COPYDATA
) |
104 SET(WM_NOTIFY
) | SET(WM_HELP
),
106 SET(WM_STYLECHANGING
) | SET(WM_STYLECHANGED
),
108 SET(WM_NCCREATE
) | SET(WM_NCCALCSIZE
) | SET(WM_GETDLGCODE
),
110 SET(EM_GETSEL
) | SET(EM_GETRECT
) | SET(EM_SETRECT
) | SET(EM_SETRECTNP
),
112 SET(EM_REPLACESEL
) | SET(EM_GETLINE
) | SET(EM_SETTABSTOPS
),
114 SET(SBM_GETRANGE
) | SET(SBM_SETSCROLLINFO
) | SET(SBM_GETSCROLLINFO
) | SET(SBM_GETSCROLLBARINFO
),
120 SET(CB_GETEDITSEL
) | SET(CB_ADDSTRING
) | SET(CB_DIR
) | SET(CB_GETLBTEXT
) |
121 SET(CB_INSERTSTRING
) | SET(CB_FINDSTRING
) | SET(CB_SELECTSTRING
) |
122 SET(CB_GETDROPPEDCONTROLRECT
) | SET(CB_FINDSTRINGEXACT
),
126 SET(LB_ADDSTRING
) | SET(LB_INSERTSTRING
) | SET(LB_GETTEXT
) | SET(LB_SELECTSTRING
) |
127 SET(LB_DIR
) | SET(LB_FINDSTRING
) |
128 SET(LB_GETSELITEMS
) | SET(LB_SETTABSTOPS
) | SET(LB_ADDFILE
) | SET(LB_GETITEMRECT
),
130 SET(LB_FINDSTRINGEXACT
),
136 SET(WM_NEXTMENU
) | SET(WM_SIZING
) | SET(WM_MOVING
) | SET(WM_DEVICECHANGE
),
138 SET(WM_MDICREATE
) | SET(WM_MDIGETACTIVE
) | SET(WM_DROPOBJECT
) |
139 SET(WM_QUERYDROPOBJECT
) | SET(WM_DRAGLOOP
) | SET(WM_DRAGSELECT
) | SET(WM_DRAGMOVE
),
153 SET(WM_ASKCBFORMATNAME
)
156 /* flags for messages that contain Unicode strings */
157 static const unsigned int message_unicode_flags
[] =
160 SET(WM_CREATE
) | SET(WM_SETTEXT
) | SET(WM_GETTEXT
) | SET(WM_GETTEXTLENGTH
) |
161 SET(WM_WININICHANGE
) | SET(WM_DEVMODECHANGE
),
173 SET(EM_REPLACESEL
) | SET(EM_GETLINE
) | SET(EM_SETPASSWORDCHAR
),
177 SET(WM_CHAR
) | SET(WM_DEADCHAR
) | SET(WM_SYSCHAR
) | SET(WM_SYSDEADCHAR
),
181 SET(CB_ADDSTRING
) | SET(CB_DIR
) | SET(CB_GETLBTEXT
) | SET(CB_GETLBTEXTLEN
) |
182 SET(CB_INSERTSTRING
) | SET(CB_FINDSTRING
) | SET(CB_SELECTSTRING
) | SET(CB_FINDSTRINGEXACT
),
186 SET(LB_ADDSTRING
) | SET(LB_INSERTSTRING
) | SET(LB_GETTEXT
) | SET(LB_GETTEXTLEN
) |
187 SET(LB_SELECTSTRING
) | SET(LB_DIR
) | SET(LB_FINDSTRING
) | SET(LB_ADDFILE
),
189 SET(LB_FINDSTRINGEXACT
),
211 SET(WM_PAINTCLIPBOARD
) | SET(WM_SIZECLIPBOARD
) | SET(WM_ASKCBFORMATNAME
)
214 /* check whether a given message type includes pointers */
215 inline static int is_pointer_message( UINT message
)
217 if (message
>= 8*sizeof(message_pointer_flags
)) return FALSE
;
218 return (message_pointer_flags
[message
/ 32] & SET(message
)) != 0;
221 /* check whether a given message type contains Unicode (or ASCII) chars */
222 inline static int is_unicode_message( UINT message
)
224 if (message
>= 8*sizeof(message_unicode_flags
)) return FALSE
;
225 return (message_unicode_flags
[message
/ 32] & SET(message
)) != 0;
230 /* add a data field to a packed message */
231 inline static void push_data( struct packed_message
*data
, const void *ptr
, size_t size
)
233 data
->data
[data
->count
] = ptr
;
234 data
->size
[data
->count
] = size
;
238 /* add a string to a packed message */
239 inline static void push_string( struct packed_message
*data
, LPCWSTR str
)
241 push_data( data
, str
, (strlenW(str
) + 1) * sizeof(WCHAR
) );
244 /* retrieve a pointer to data from a packed message and increment the buffer pointer */
245 inline static void *get_data( void **buffer
, size_t size
)
248 *buffer
= (char *)*buffer
+ size
;
252 /* make sure that the buffer contains a valid null-terminated Unicode string */
253 inline static BOOL
check_string( LPCWSTR str
, size_t size
)
255 for (size
/= sizeof(WCHAR
); size
; size
--, str
++)
256 if (!*str
) return TRUE
;
260 /* make sure that there is space for 'size' bytes in buffer, growing it if needed */
261 inline static void *get_buffer_space( void **buffer
, size_t size
)
267 if (!(ret
= HeapReAlloc( GetProcessHeap(), 0, *buffer
, size
)))
268 HeapFree( GetProcessHeap(), 0, *buffer
);
270 else ret
= HeapAlloc( GetProcessHeap(), 0, size
);
276 /* retrieve a string pointer from packed data */
277 inline static LPWSTR
get_string( void **buffer
)
279 return get_data( buffer
, (strlenW( (LPWSTR
)*buffer
) + 1) * sizeof(WCHAR
) );
282 /* check whether a combobox expects strings or ids in CB_ADDSTRING/CB_INSERTSTRING */
283 inline static BOOL
combobox_has_strings( HWND hwnd
)
285 DWORD style
= GetWindowLongA( hwnd
, GWL_STYLE
);
286 return (!(style
& (CBS_OWNERDRAWFIXED
| CBS_OWNERDRAWVARIABLE
)) || (style
& CBS_HASSTRINGS
));
289 /* check whether a listbox expects strings or ids in LB_ADDSTRING/LB_INSERTSTRING */
290 inline static BOOL
listbox_has_strings( HWND hwnd
)
292 DWORD style
= GetWindowLongA( hwnd
, GWL_STYLE
);
293 return (!(style
& (LBS_OWNERDRAWFIXED
| LBS_OWNERDRAWVARIABLE
)) || (style
& LBS_HASSTRINGS
));
296 /* check whether message is in the range of keyboard messages */
297 inline static BOOL
is_keyboard_message( UINT message
)
299 return (message
>= WM_KEYFIRST
&& message
<= WM_KEYLAST
);
302 /* check whether message is in the range of mouse messages */
303 inline static BOOL
is_mouse_message( UINT message
)
305 return ((message
>= WM_NCMOUSEFIRST
&& message
<= WM_NCMOUSELAST
) ||
306 (message
>= WM_MOUSEFIRST
&& message
<= WM_MOUSELAST
));
309 /* check whether message matches the specified hwnd filter */
310 inline static BOOL
check_hwnd_filter( const MSG
*msg
, HWND hwnd_filter
)
312 if (!hwnd_filter
) return TRUE
;
313 return (msg
->hwnd
== hwnd_filter
|| IsChild( hwnd_filter
, msg
->hwnd
));
317 /***********************************************************************
318 * broadcast_message_callback
320 * Helper callback for broadcasting messages.
322 static BOOL CALLBACK
broadcast_message_callback( HWND hwnd
, LPARAM lparam
)
324 struct send_message_info
*info
= (struct send_message_info
*)lparam
;
325 if (!(GetWindowLongW( hwnd
, GWL_STYLE
) & (WS_POPUP
|WS_CAPTION
))) return TRUE
;
329 SendMessageTimeoutW( hwnd
, info
->msg
, info
->wparam
, info
->lparam
,
330 info
->flags
, info
->timeout
, NULL
);
333 SendMessageTimeoutA( hwnd
, info
->msg
, info
->wparam
, info
->lparam
,
334 info
->flags
, info
->timeout
, NULL
);
337 SendNotifyMessageW( hwnd
, info
->msg
, info
->wparam
, info
->lparam
);
340 SendMessageCallbackW( hwnd
, info
->msg
, info
->wparam
, info
->lparam
,
341 info
->callback
, info
->data
);
344 PostMessageW( hwnd
, info
->msg
, info
->wparam
, info
->lparam
);
347 ERR( "bad type %d\n", info
->type
);
354 /***********************************************************************
357 * Convert the wparam of an ASCII message to Unicode.
359 static WPARAM
map_wparam_AtoW( UINT message
, WPARAM wparam
)
364 case EM_SETPASSWORDCHAR
:
373 ch
[0] = (wparam
& 0xff);
374 ch
[1] = (wparam
>> 8);
375 MultiByteToWideChar(CP_ACP
, 0, ch
, 2, wch
, 2);
376 wparam
= MAKEWPARAM(wch
[0], wch
[1]);
383 ch
[0] = (wparam
>> 8);
384 ch
[1] = (wparam
& 0xff);
385 if (ch
[0]) MultiByteToWideChar(CP_ACP
, 0, ch
, 2, &wch
, 1);
386 else MultiByteToWideChar(CP_ACP
, 0, &ch
[1], 1, &wch
, 1);
387 wparam
= MAKEWPARAM( wch
, HIWORD(wparam
) );
395 /***********************************************************************
398 * Convert the wparam of a Unicode message to ASCII.
400 static WPARAM
map_wparam_WtoA( UINT message
, WPARAM wparam
)
405 case EM_SETPASSWORDCHAR
:
414 wch
[0] = LOWORD(wparam
);
415 wch
[1] = HIWORD(wparam
);
416 WideCharToMultiByte( CP_ACP
, 0, wch
, 2, (LPSTR
)ch
, 2, NULL
, NULL
);
417 wparam
= MAKEWPARAM( ch
[0] | (ch
[1] << 8), 0 );
422 WCHAR wch
= LOWORD(wparam
);
425 if (WideCharToMultiByte( CP_ACP
, 0, &wch
, 1, (LPSTR
)ch
, 2, NULL
, NULL
) == 2)
426 wparam
= MAKEWPARAM( (ch
[0] << 8) | ch
[1], HIWORD(wparam
) );
428 wparam
= MAKEWPARAM( ch
[0], HIWORD(wparam
) );
436 /***********************************************************************
439 * Pack a message for sending to another process.
440 * Return the size of the data we expect in the message reply.
441 * Set data->count to -1 if there is an error.
443 static size_t pack_message( HWND hwnd
, UINT message
, WPARAM wparam
, LPARAM lparam
,
444 struct packed_message
*data
)
452 CREATESTRUCTW
*cs
= (CREATESTRUCTW
*)lparam
;
453 push_data( data
, cs
, sizeof(*cs
) );
454 if (HIWORD(cs
->lpszName
)) push_string( data
, cs
->lpszName
);
455 if (HIWORD(cs
->lpszClass
)) push_string( data
, cs
->lpszClass
);
459 case WM_ASKCBFORMATNAME
:
460 return wparam
* sizeof(WCHAR
);
461 case WM_WININICHANGE
:
462 if (lparam
) push_string(data
, (LPWSTR
)lparam
);
465 case WM_DEVMODECHANGE
:
470 push_string( data
, (LPWSTR
)lparam
);
472 case WM_GETMINMAXINFO
:
473 push_data( data
, (MINMAXINFO
*)lparam
, sizeof(MINMAXINFO
) );
474 return sizeof(MINMAXINFO
);
476 push_data( data
, (DRAWITEMSTRUCT
*)lparam
, sizeof(DRAWITEMSTRUCT
) );
479 push_data( data
, (MEASUREITEMSTRUCT
*)lparam
, sizeof(MEASUREITEMSTRUCT
) );
480 return sizeof(MEASUREITEMSTRUCT
);
482 push_data( data
, (DELETEITEMSTRUCT
*)lparam
, sizeof(DELETEITEMSTRUCT
) );
485 push_data( data
, (COMPAREITEMSTRUCT
*)lparam
, sizeof(COMPAREITEMSTRUCT
) );
487 case WM_WINDOWPOSCHANGING
:
488 case WM_WINDOWPOSCHANGED
:
489 push_data( data
, (WINDOWPOS
*)lparam
, sizeof(WINDOWPOS
) );
490 return sizeof(WINDOWPOS
);
493 COPYDATASTRUCT
*cp
= (COPYDATASTRUCT
*)lparam
;
494 push_data( data
, cp
, sizeof(*cp
) );
495 if (cp
->lpData
) push_data( data
, cp
->lpData
, cp
->cbData
);
499 /* WM_NOTIFY cannot be sent across processes (MSDN) */
503 push_data( data
, (HELPINFO
*)lparam
, sizeof(HELPINFO
) );
505 case WM_STYLECHANGING
:
506 case WM_STYLECHANGED
:
507 push_data( data
, (STYLESTRUCT
*)lparam
, sizeof(STYLESTRUCT
) );
512 push_data( data
, (RECT
*)lparam
, sizeof(RECT
) );
517 NCCALCSIZE_PARAMS
*nc
= (NCCALCSIZE_PARAMS
*)lparam
;
518 push_data( data
, nc
, sizeof(*nc
) );
519 push_data( data
, nc
->lppos
, sizeof(*nc
->lppos
) );
520 return sizeof(*nc
) + sizeof(*nc
->lppos
);
523 if (lparam
) push_data( data
, (MSG
*)lparam
, sizeof(MSG
) );
525 case SBM_SETSCROLLINFO
:
526 push_data( data
, (SCROLLINFO
*)lparam
, sizeof(SCROLLINFO
) );
528 case SBM_GETSCROLLINFO
:
529 push_data( data
, (SCROLLINFO
*)lparam
, sizeof(SCROLLINFO
) );
530 return sizeof(SCROLLINFO
);
531 case SBM_GETSCROLLBARINFO
:
533 const SCROLLBARINFO
*info
= (const SCROLLBARINFO
*)lparam
;
534 size_t size
= min( info
->cbSize
, sizeof(SCROLLBARINFO
) );
535 push_data( data
, info
, size
);
543 if (wparam
) size
+= sizeof(DWORD
);
544 if (lparam
) size
+= sizeof(DWORD
);
549 case CB_GETDROPPEDCONTROLRECT
:
553 push_data( data
, (RECT
*)lparam
, sizeof(RECT
) );
557 WORD
*pw
= (WORD
*)lparam
;
558 push_data( data
, pw
, sizeof(*pw
) );
559 return *pw
* sizeof(WCHAR
);
563 if (wparam
) push_data( data
, (UINT
*)lparam
, sizeof(UINT
) * wparam
);
566 case CB_INSERTSTRING
:
568 case CB_FINDSTRINGEXACT
:
569 case CB_SELECTSTRING
:
570 if (combobox_has_strings( hwnd
)) push_string( data
, (LPWSTR
)lparam
);
573 if (!combobox_has_strings( hwnd
)) return sizeof(ULONG_PTR
);
574 return (SendMessageW( hwnd
, CB_GETLBTEXTLEN
, wparam
, 0 ) + 1) * sizeof(WCHAR
);
576 case LB_INSERTSTRING
:
578 case LB_FINDSTRINGEXACT
:
579 case LB_SELECTSTRING
:
580 if (listbox_has_strings( hwnd
)) push_string( data
, (LPWSTR
)lparam
);
583 if (!listbox_has_strings( hwnd
)) return sizeof(ULONG_PTR
);
584 return (SendMessageW( hwnd
, LB_GETTEXTLEN
, wparam
, 0 ) + 1) * sizeof(WCHAR
);
586 return wparam
* sizeof(UINT
);
588 push_data( data
, (MDINEXTMENU
*)lparam
, sizeof(MDINEXTMENU
) );
589 return sizeof(MDINEXTMENU
);
592 push_data( data
, (RECT
*)lparam
, sizeof(RECT
) );
596 MDICREATESTRUCTW
*cs
= (MDICREATESTRUCTW
*)lparam
;
597 push_data( data
, cs
, sizeof(*cs
) );
598 if (HIWORD(cs
->szTitle
)) push_string( data
, cs
->szTitle
);
599 if (HIWORD(cs
->szClass
)) push_string( data
, cs
->szClass
);
602 case WM_MDIGETACTIVE
:
603 if (lparam
) return sizeof(BOOL
);
605 case WM_DEVICECHANGE
:
607 DEV_BROADCAST_HDR
*header
= (DEV_BROADCAST_HDR
*)lparam
;
608 push_data( data
, header
, header
->dbch_size
);
611 case WM_WINE_SETWINDOWPOS
:
612 push_data( data
, (WINDOWPOS
*)lparam
, sizeof(WINDOWPOS
) );
614 case WM_WINE_KEYBOARD_LL_HOOK
:
616 struct hook_extra_info
*h_extra
= (struct hook_extra_info
*)lparam
;
617 push_data( data
, h_extra
, sizeof(*h_extra
) );
618 push_data( data
, (LPVOID
)h_extra
->lparam
, sizeof(KBDLLHOOKSTRUCT
) );
621 case WM_WINE_MOUSE_LL_HOOK
:
623 struct hook_extra_info
*h_extra
= (struct hook_extra_info
*)lparam
;
624 push_data( data
, h_extra
, sizeof(*h_extra
) );
625 push_data( data
, (LPVOID
)h_extra
->lparam
, sizeof(MSLLHOOKSTRUCT
) );
629 if (wparam
<= 1) return 0;
630 FIXME( "WM_NCPAINT hdc packing not supported yet\n" );
634 if (!wparam
) return 0;
637 /* these contain an HFONT */
640 /* these contain an HDC */
642 case WM_ICONERASEBKGND
:
643 case WM_CTLCOLORMSGBOX
:
644 case WM_CTLCOLOREDIT
:
645 case WM_CTLCOLORLISTBOX
:
648 case WM_CTLCOLORSCROLLBAR
:
649 case WM_CTLCOLORSTATIC
:
652 /* these contain an HGLOBAL */
653 case WM_PAINTCLIPBOARD
:
654 case WM_SIZECLIPBOARD
:
655 /* these contain HICON */
658 case WM_QUERYDRAGICON
:
659 case WM_QUERYPARKICON
:
660 /* these contain pointers */
662 case WM_QUERYDROPOBJECT
:
666 FIXME( "msg %x (%s) not supported yet\n", message
, SPY_GetMsgName(message
, hwnd
) );
674 /***********************************************************************
677 * Unpack a message received from another process.
679 static BOOL
unpack_message( HWND hwnd
, UINT message
, WPARAM
*wparam
, LPARAM
*lparam
,
680 void **buffer
, size_t size
)
689 CREATESTRUCTW
*cs
= *buffer
;
690 WCHAR
*str
= (WCHAR
*)(cs
+ 1);
691 if (size
< sizeof(*cs
)) return FALSE
;
693 if (HIWORD(cs
->lpszName
))
695 if (!check_string( str
, size
)) return FALSE
;
697 size
-= (strlenW(str
) + 1) * sizeof(WCHAR
);
698 str
+= strlenW(str
) + 1;
700 if (HIWORD(cs
->lpszClass
))
702 if (!check_string( str
, size
)) return FALSE
;
708 case WM_ASKCBFORMATNAME
:
709 if (!get_buffer_space( buffer
, (*wparam
* sizeof(WCHAR
)) )) return FALSE
;
711 case WM_WININICHANGE
:
712 if (!*lparam
) return TRUE
;
715 case WM_DEVMODECHANGE
:
720 if (!check_string( *buffer
, size
)) return FALSE
;
722 case WM_GETMINMAXINFO
:
723 minsize
= sizeof(MINMAXINFO
);
726 minsize
= sizeof(DRAWITEMSTRUCT
);
729 minsize
= sizeof(MEASUREITEMSTRUCT
);
732 minsize
= sizeof(DELETEITEMSTRUCT
);
735 minsize
= sizeof(COMPAREITEMSTRUCT
);
737 case WM_WINDOWPOSCHANGING
:
738 case WM_WINDOWPOSCHANGED
:
739 case WM_WINE_SETWINDOWPOS
:
740 minsize
= sizeof(WINDOWPOS
);
744 COPYDATASTRUCT
*cp
= *buffer
;
745 if (size
< sizeof(*cp
)) return FALSE
;
748 minsize
= sizeof(*cp
) + cp
->cbData
;
754 /* WM_NOTIFY cannot be sent across processes (MSDN) */
757 minsize
= sizeof(HELPINFO
);
759 case WM_STYLECHANGING
:
760 case WM_STYLECHANGED
:
761 minsize
= sizeof(STYLESTRUCT
);
764 if (!*wparam
) minsize
= sizeof(RECT
);
767 NCCALCSIZE_PARAMS
*nc
= *buffer
;
768 if (size
< sizeof(*nc
) + sizeof(*nc
->lppos
)) return FALSE
;
769 nc
->lppos
= (WINDOWPOS
*)(nc
+ 1);
773 if (!*lparam
) return TRUE
;
774 minsize
= sizeof(MSG
);
776 case SBM_SETSCROLLINFO
:
777 minsize
= sizeof(SCROLLINFO
);
779 case SBM_GETSCROLLINFO
:
780 if (!get_buffer_space( buffer
, sizeof(SCROLLINFO
))) return FALSE
;
782 case SBM_GETSCROLLBARINFO
:
783 if (!get_buffer_space( buffer
, sizeof(SCROLLBARINFO
))) return FALSE
;
788 if (*wparam
|| *lparam
)
790 if (!get_buffer_space( buffer
, 2*sizeof(DWORD
) )) return FALSE
;
791 if (*wparam
) *wparam
= (WPARAM
)*buffer
;
792 if (*lparam
) *lparam
= (LPARAM
)((DWORD
*)*buffer
+ 1);
797 case CB_GETDROPPEDCONTROLRECT
:
798 if (!get_buffer_space( buffer
, sizeof(RECT
) )) return FALSE
;
802 minsize
= sizeof(RECT
);
807 if (size
< sizeof(WORD
)) return FALSE
;
808 len
= *(WORD
*)*buffer
;
809 if (!get_buffer_space( buffer
, (len
+ 1) * sizeof(WCHAR
) )) return FALSE
;
810 *lparam
= (LPARAM
)*buffer
+ sizeof(WORD
); /* don't erase WORD at start of buffer */
815 if (!*wparam
) return TRUE
;
816 minsize
= *wparam
* sizeof(UINT
);
819 case CB_INSERTSTRING
:
821 case CB_FINDSTRINGEXACT
:
822 case CB_SELECTSTRING
:
824 case LB_INSERTSTRING
:
826 case LB_FINDSTRINGEXACT
:
827 case LB_SELECTSTRING
:
828 if (!*buffer
) return TRUE
;
829 if (!check_string( *buffer
, size
)) return FALSE
;
833 size
= sizeof(ULONG_PTR
);
834 if (combobox_has_strings( hwnd
))
835 size
= (SendMessageW( hwnd
, CB_GETLBTEXTLEN
, *wparam
, 0 ) + 1) * sizeof(WCHAR
);
836 if (!get_buffer_space( buffer
, size
)) return FALSE
;
841 size
= sizeof(ULONG_PTR
);
842 if (listbox_has_strings( hwnd
))
843 size
= (SendMessageW( hwnd
, LB_GETTEXTLEN
, *wparam
, 0 ) + 1) * sizeof(WCHAR
);
844 if (!get_buffer_space( buffer
, size
)) return FALSE
;
848 if (!get_buffer_space( buffer
, *wparam
* sizeof(UINT
) )) return FALSE
;
851 minsize
= sizeof(MDINEXTMENU
);
852 if (!get_buffer_space( buffer
, sizeof(MDINEXTMENU
) )) return FALSE
;
856 minsize
= sizeof(RECT
);
857 if (!get_buffer_space( buffer
, sizeof(RECT
) )) return FALSE
;
861 MDICREATESTRUCTW
*cs
= *buffer
;
862 WCHAR
*str
= (WCHAR
*)(cs
+ 1);
863 if (size
< sizeof(*cs
)) return FALSE
;
865 if (HIWORD(cs
->szTitle
))
867 if (!check_string( str
, size
)) return FALSE
;
869 size
-= (strlenW(str
) + 1) * sizeof(WCHAR
);
870 str
+= strlenW(str
) + 1;
872 if (HIWORD(cs
->szClass
))
874 if (!check_string( str
, size
)) return FALSE
;
879 case WM_MDIGETACTIVE
:
880 if (!*lparam
) return TRUE
;
881 if (!get_buffer_space( buffer
, sizeof(BOOL
) )) return FALSE
;
883 case WM_DEVICECHANGE
:
884 minsize
= sizeof(DEV_BROADCAST_HDR
);
886 case WM_WINE_KEYBOARD_LL_HOOK
:
887 case WM_WINE_MOUSE_LL_HOOK
:
889 struct hook_extra_info
*h_extra
= (struct hook_extra_info
*)*buffer
;
891 minsize
= sizeof(struct hook_extra_info
) +
892 (message
== WM_WINE_KEYBOARD_LL_HOOK
? sizeof(KBDLLHOOKSTRUCT
)
893 : sizeof(MSLLHOOKSTRUCT
));
894 if (size
< minsize
) return FALSE
;
895 h_extra
->lparam
= (LPARAM
)(h_extra
+ 1);
899 if (*wparam
<= 1) return TRUE
;
900 FIXME( "WM_NCPAINT hdc unpacking not supported\n" );
903 if (!*wparam
) return TRUE
;
906 /* these contain an HFONT */
909 /* these contain an HDC */
911 case WM_ICONERASEBKGND
:
912 case WM_CTLCOLORMSGBOX
:
913 case WM_CTLCOLOREDIT
:
914 case WM_CTLCOLORLISTBOX
:
917 case WM_CTLCOLORSCROLLBAR
:
918 case WM_CTLCOLORSTATIC
:
921 /* these contain an HGLOBAL */
922 case WM_PAINTCLIPBOARD
:
923 case WM_SIZECLIPBOARD
:
924 /* these contain HICON */
927 case WM_QUERYDRAGICON
:
928 case WM_QUERYPARKICON
:
929 /* these contain pointers */
931 case WM_QUERYDROPOBJECT
:
935 FIXME( "msg %x (%s) not supported yet\n", message
, SPY_GetMsgName(message
, hwnd
) );
939 return TRUE
; /* message doesn't need any unpacking */
942 /* default exit for most messages: check minsize and store buffer in lparam */
943 if (size
< minsize
) return FALSE
;
944 *lparam
= (LPARAM
)*buffer
;
949 /***********************************************************************
952 * Pack a reply to a message for sending to another process.
954 static void pack_reply( HWND hwnd
, UINT message
, WPARAM wparam
, LPARAM lparam
,
955 LRESULT res
, struct packed_message
*data
)
962 push_data( data
, (CREATESTRUCTW
*)lparam
, sizeof(CREATESTRUCTW
) );
967 push_data( data
, (WCHAR
*)lparam
, (res
+ 1) * sizeof(WCHAR
) );
969 case WM_GETMINMAXINFO
:
970 push_data( data
, (MINMAXINFO
*)lparam
, sizeof(MINMAXINFO
) );
973 push_data( data
, (MEASUREITEMSTRUCT
*)lparam
, sizeof(MEASUREITEMSTRUCT
) );
975 case WM_WINDOWPOSCHANGING
:
976 case WM_WINDOWPOSCHANGED
:
977 push_data( data
, (WINDOWPOS
*)lparam
, sizeof(WINDOWPOS
) );
980 if (lparam
) push_data( data
, (MSG
*)lparam
, sizeof(MSG
) );
982 case SBM_GETSCROLLINFO
:
983 push_data( data
, (SCROLLINFO
*)lparam
, sizeof(SCROLLINFO
) );
987 case CB_GETDROPPEDCONTROLRECT
:
990 push_data( data
, (RECT
*)lparam
, sizeof(RECT
) );
994 WORD
*ptr
= (WORD
*)lparam
;
995 push_data( data
, ptr
, ptr
[-1] * sizeof(WCHAR
) );
999 push_data( data
, (UINT
*)lparam
, wparam
* sizeof(UINT
) );
1001 case WM_MDIGETACTIVE
:
1002 if (lparam
) push_data( data
, (BOOL
*)lparam
, sizeof(BOOL
) );
1006 push_data( data
, (RECT
*)lparam
, sizeof(RECT
) );
1009 NCCALCSIZE_PARAMS
*nc
= (NCCALCSIZE_PARAMS
*)lparam
;
1010 push_data( data
, nc
, sizeof(*nc
) );
1011 push_data( data
, nc
->lppos
, sizeof(*nc
->lppos
) );
1017 if (wparam
) push_data( data
, (DWORD
*)wparam
, sizeof(DWORD
) );
1018 if (lparam
) push_data( data
, (DWORD
*)lparam
, sizeof(DWORD
) );
1021 push_data( data
, (MDINEXTMENU
*)lparam
, sizeof(MDINEXTMENU
) );
1024 push_data( data
, (MDICREATESTRUCTW
*)lparam
, sizeof(MDICREATESTRUCTW
) );
1026 case WM_ASKCBFORMATNAME
:
1027 push_data( data
, (WCHAR
*)lparam
, (strlenW((WCHAR
*)lparam
) + 1) * sizeof(WCHAR
) );
1033 /***********************************************************************
1036 * Unpack a message reply received from another process.
1038 static void unpack_reply( HWND hwnd
, UINT message
, WPARAM wparam
, LPARAM lparam
,
1039 void *buffer
, size_t size
)
1046 CREATESTRUCTW
*cs
= (CREATESTRUCTW
*)lparam
;
1047 LPCWSTR name
= cs
->lpszName
, class = cs
->lpszClass
;
1048 memcpy( cs
, buffer
, min( sizeof(*cs
), size
));
1049 cs
->lpszName
= name
; /* restore the original pointers */
1050 cs
->lpszClass
= class;
1054 case WM_ASKCBFORMATNAME
:
1055 memcpy( (WCHAR
*)lparam
, buffer
, min( wparam
*sizeof(WCHAR
), size
));
1057 case WM_GETMINMAXINFO
:
1058 memcpy( (MINMAXINFO
*)lparam
, buffer
, min( sizeof(MINMAXINFO
), size
));
1060 case WM_MEASUREITEM
:
1061 memcpy( (MEASUREITEMSTRUCT
*)lparam
, buffer
, min( sizeof(MEASUREITEMSTRUCT
), size
));
1063 case WM_WINDOWPOSCHANGING
:
1064 case WM_WINDOWPOSCHANGED
:
1065 memcpy( (WINDOWPOS
*)lparam
, buffer
, min( sizeof(WINDOWPOS
), size
));
1068 if (lparam
) memcpy( (MSG
*)lparam
, buffer
, min( sizeof(MSG
), size
));
1070 case SBM_GETSCROLLINFO
:
1071 memcpy( (SCROLLINFO
*)lparam
, buffer
, min( sizeof(SCROLLINFO
), size
));
1073 case SBM_GETSCROLLBARINFO
:
1074 memcpy( (SCROLLBARINFO
*)lparam
, buffer
, min( sizeof(SCROLLBARINFO
), size
));
1077 case CB_GETDROPPEDCONTROLRECT
:
1078 case LB_GETITEMRECT
:
1081 memcpy( (RECT
*)lparam
, buffer
, min( sizeof(RECT
), size
));
1084 size
= min( size
, (size_t)*(WORD
*)lparam
);
1085 memcpy( (WCHAR
*)lparam
, buffer
, size
);
1087 case LB_GETSELITEMS
:
1088 memcpy( (UINT
*)lparam
, buffer
, min( wparam
*sizeof(UINT
), size
));
1092 memcpy( (WCHAR
*)lparam
, buffer
, size
);
1095 memcpy( (MDINEXTMENU
*)lparam
, buffer
, min( sizeof(MDINEXTMENU
), size
));
1097 case WM_MDIGETACTIVE
:
1098 if (lparam
) memcpy( (BOOL
*)lparam
, buffer
, min( sizeof(BOOL
), size
));
1102 memcpy( (RECT
*)lparam
, buffer
, min( sizeof(RECT
), size
));
1105 NCCALCSIZE_PARAMS
*nc
= (NCCALCSIZE_PARAMS
*)lparam
;
1106 WINDOWPOS
*wp
= nc
->lppos
;
1107 memcpy( nc
, buffer
, min( sizeof(*nc
), size
));
1108 if (size
> sizeof(*nc
))
1110 size
-= sizeof(*nc
);
1111 memcpy( wp
, (NCCALCSIZE_PARAMS
*)buffer
+ 1, min( sizeof(*wp
), size
));
1113 nc
->lppos
= wp
; /* restore the original pointer */
1121 memcpy( (DWORD
*)wparam
, buffer
, min( sizeof(DWORD
), size
));
1122 if (size
<= sizeof(DWORD
)) break;
1123 size
-= sizeof(DWORD
);
1124 buffer
= (DWORD
*)buffer
+ 1;
1126 if (lparam
) memcpy( (DWORD
*)lparam
, buffer
, min( sizeof(DWORD
), size
));
1130 MDICREATESTRUCTW
*cs
= (MDICREATESTRUCTW
*)lparam
;
1131 LPCWSTR title
= cs
->szTitle
, class = cs
->szClass
;
1132 memcpy( cs
, buffer
, min( sizeof(*cs
), size
));
1133 cs
->szTitle
= title
; /* restore the original pointers */
1134 cs
->szClass
= class;
1138 ERR( "should not happen: unexpected message %x\n", message
);
1144 /***********************************************************************
1147 * Send a reply to a sent message.
1149 static void reply_message( struct received_message_info
*info
, LRESULT result
, BOOL remove
)
1151 struct packed_message data
;
1152 int i
, replied
= info
->flags
& ISMEX_REPLIED
;
1154 if (info
->flags
& ISMEX_NOTIFY
) return; /* notify messages don't get replies */
1155 if (!remove
&& replied
) return; /* replied already */
1158 info
->flags
|= ISMEX_REPLIED
;
1160 if (info
->type
== MSG_OTHER_PROCESS
&& !replied
)
1162 pack_reply( info
->msg
.hwnd
, info
->msg
.message
, info
->msg
.wParam
,
1163 info
->msg
.lParam
, result
, &data
);
1166 SERVER_START_REQ( reply_message
)
1168 req
->result
= result
;
1169 req
->remove
= remove
;
1170 for (i
= 0; i
< data
.count
; i
++) wine_server_add_data( req
, data
.data
[i
], data
.size
[i
] );
1171 wine_server_call( req
);
1177 /***********************************************************************
1178 * handle_internal_message
1180 * Handle an internal Wine message instead of calling the window proc.
1182 static LRESULT
handle_internal_message( HWND hwnd
, UINT msg
, WPARAM wparam
, LPARAM lparam
)
1186 case WM_WINE_DESTROYWINDOW
:
1187 return WIN_DestroyWindow( hwnd
);
1188 case WM_WINE_SETWINDOWPOS
:
1189 if (hwnd
== GetDesktopWindow()) return 0;
1190 return USER_SetWindowPos( (WINDOWPOS
*)lparam
);
1191 case WM_WINE_SHOWWINDOW
:
1192 if (hwnd
== GetDesktopWindow()) return 0;
1193 return ShowWindow( hwnd
, wparam
);
1194 case WM_WINE_SETPARENT
:
1195 if (hwnd
== GetDesktopWindow()) return 0;
1196 return (LRESULT
)SetParent( hwnd
, (HWND
)wparam
);
1197 case WM_WINE_SETWINDOWLONG
:
1198 return WIN_SetWindowLong( hwnd
, (short)LOWORD(wparam
), HIWORD(wparam
), lparam
, TRUE
);
1199 case WM_WINE_ENABLEWINDOW
:
1200 if (hwnd
== GetDesktopWindow()) return 0;
1201 return EnableWindow( hwnd
, wparam
);
1202 case WM_WINE_SETACTIVEWINDOW
:
1203 if (hwnd
== GetDesktopWindow()) return 0;
1204 return (LRESULT
)SetActiveWindow( (HWND
)wparam
);
1205 case WM_WINE_KEYBOARD_LL_HOOK
:
1206 case WM_WINE_MOUSE_LL_HOOK
:
1208 struct hook_extra_info
*h_extra
= (struct hook_extra_info
*)lparam
;
1210 return call_current_hook( h_extra
->handle
, HC_ACTION
, wparam
, h_extra
->lparam
);
1213 if (msg
>= WM_WINE_FIRST_DRIVER_MSG
&& msg
<= WM_WINE_LAST_DRIVER_MSG
)
1214 return USER_Driver
->pWindowMessage( hwnd
, msg
, wparam
, lparam
);
1215 FIXME( "unknown internal message %x\n", msg
);
1220 /* since the WM_DDE_ACK response to a WM_DDE_EXECUTE message should contain the handle
1221 * to the memory handle, we keep track (in the server side) of all pairs of handle
1222 * used (the client passes its value and the content of the memory handle), and
1223 * the server stored both values (the client, and the local one, created after the
1224 * content). When a ACK message is generated, the list of pair is searched for a
1225 * matching pair, so that the client memory handle can be returned.
1228 HGLOBAL client_hMem
;
1229 HGLOBAL server_hMem
;
1232 static struct DDE_pair
* dde_pairs
;
1233 static int dde_num_alloc
;
1234 static int dde_num_used
;
1236 static CRITICAL_SECTION dde_crst
;
1237 static CRITICAL_SECTION_DEBUG critsect_debug
=
1240 { &critsect_debug
.ProcessLocksList
, &critsect_debug
.ProcessLocksList
},
1241 0, 0, { (DWORD_PTR
)(__FILE__
": dde_crst") }
1243 static CRITICAL_SECTION dde_crst
= { &critsect_debug
, -1, 0, 0, 0, 0 };
1245 static BOOL
dde_add_pair(HGLOBAL chm
, HGLOBAL shm
)
1250 EnterCriticalSection(&dde_crst
);
1252 /* now remember the pair of hMem on both sides */
1253 if (dde_num_used
== dde_num_alloc
)
1255 struct DDE_pair
* tmp
;
1257 tmp
= HeapReAlloc( GetProcessHeap(), 0, dde_pairs
,
1258 (dde_num_alloc
+ GROWBY
) * sizeof(struct DDE_pair
));
1260 tmp
= HeapAlloc( GetProcessHeap(), 0,
1261 (dde_num_alloc
+ GROWBY
) * sizeof(struct DDE_pair
));
1265 LeaveCriticalSection(&dde_crst
);
1269 /* zero out newly allocated part */
1270 memset(&dde_pairs
[dde_num_alloc
], 0, GROWBY
* sizeof(struct DDE_pair
));
1271 dde_num_alloc
+= GROWBY
;
1274 for (i
= 0; i
< dde_num_alloc
; i
++)
1276 if (dde_pairs
[i
].server_hMem
== 0)
1278 dde_pairs
[i
].client_hMem
= chm
;
1279 dde_pairs
[i
].server_hMem
= shm
;
1284 LeaveCriticalSection(&dde_crst
);
1288 static HGLOBAL
dde_get_pair(HGLOBAL shm
)
1293 EnterCriticalSection(&dde_crst
);
1294 for (i
= 0; i
< dde_num_alloc
; i
++)
1296 if (dde_pairs
[i
].server_hMem
== shm
)
1298 /* free this pair */
1299 dde_pairs
[i
].server_hMem
= 0;
1301 ret
= dde_pairs
[i
].client_hMem
;
1305 LeaveCriticalSection(&dde_crst
);
1309 /***********************************************************************
1312 * Post a DDE message
1314 static BOOL
post_dde_message( struct packed_message
*data
, const struct send_message_info
*info
)
1318 UINT_PTR uiLo
, uiHi
;
1320 HGLOBAL hunlock
= 0;
1324 if (!UnpackDDElParam( info
->msg
, info
->lparam
, &uiLo
, &uiHi
))
1330 /* DDE messages which don't require packing are:
1339 /* uiHi should contain a hMem from WM_DDE_EXECUTE */
1340 HGLOBAL h
= dde_get_pair( (HANDLE
)uiHi
);
1343 /* send back the value of h on the other side */
1344 push_data( data
, &h
, sizeof(HGLOBAL
) );
1346 TRACE( "send dde-ack %x %08x => %p\n", uiLo
, uiHi
, h
);
1351 /* uiHi should contain either an atom or 0 */
1352 TRACE( "send dde-ack %x atom=%x\n", uiLo
, uiHi
);
1353 lp
= MAKELONG( uiLo
, uiHi
);
1362 size
= GlobalSize( (HGLOBAL
)uiLo
) ;
1363 if ((info
->msg
== WM_DDE_ADVISE
&& size
< sizeof(DDEADVISE
)) ||
1364 (info
->msg
== WM_DDE_DATA
&& size
< sizeof(DDEDATA
)) ||
1365 (info
->msg
== WM_DDE_POKE
&& size
< sizeof(DDEPOKE
))
1369 else if (info
->msg
!= WM_DDE_DATA
) return FALSE
;
1374 if ((ptr
= GlobalLock( (HGLOBAL
)uiLo
) ))
1376 DDEDATA
*dde_data
= (DDEDATA
*)ptr
;
1377 TRACE("unused %d, fResponse %d, fRelease %d, fDeferUpd %d, fAckReq %d, cfFormat %d\n",
1378 dde_data
->unused
, dde_data
->fResponse
, dde_data
->fRelease
,
1379 dde_data
->reserved
, dde_data
->fAckReq
, dde_data
->cfFormat
);
1380 push_data( data
, ptr
, size
);
1381 hunlock
= (HGLOBAL
)uiLo
;
1384 TRACE( "send ddepack %u %x\n", size
, uiHi
);
1386 case WM_DDE_EXECUTE
:
1389 if ((ptr
= GlobalLock( (HGLOBAL
)info
->lparam
) ))
1391 push_data(data
, ptr
, GlobalSize( (HGLOBAL
)info
->lparam
));
1392 /* so that the other side can send it back on ACK */
1394 hunlock
= (HGLOBAL
)info
->lparam
;
1399 SERVER_START_REQ( send_message
)
1401 req
->id
= info
->dest_tid
;
1402 req
->type
= info
->type
;
1404 req
->win
= info
->hwnd
;
1405 req
->msg
= info
->msg
;
1406 req
->wparam
= info
->wparam
;
1409 for (i
= 0; i
< data
->count
; i
++)
1410 wine_server_add_data( req
, data
->data
[i
], data
->size
[i
] );
1411 if ((res
= wine_server_call( req
)))
1413 if (res
== STATUS_INVALID_PARAMETER
)
1414 /* FIXME: find a STATUS_ value for this one */
1415 SetLastError( ERROR_INVALID_THREAD_ID
);
1417 SetLastError( RtlNtStatusToDosError(res
) );
1420 FreeDDElParam(info
->msg
, info
->lparam
);
1423 if (hunlock
) GlobalUnlock(hunlock
);
1428 /***********************************************************************
1429 * unpack_dde_message
1431 * Unpack a posted DDE message received from another process.
1433 static BOOL
unpack_dde_message( HWND hwnd
, UINT message
, WPARAM
*wparam
, LPARAM
*lparam
,
1434 void **buffer
, size_t size
)
1436 UINT_PTR uiLo
, uiHi
;
1445 /* hMem is being passed */
1446 if (size
!= sizeof(HGLOBAL
)) return FALSE
;
1447 if (!buffer
|| !*buffer
) return FALSE
;
1449 memcpy( &hMem
, *buffer
, size
);
1450 uiHi
= (UINT_PTR
)hMem
;
1451 TRACE("recv dde-ack %x mem=%x[%lx]\n", uiLo
, uiHi
, GlobalSize( hMem
));
1455 uiLo
= LOWORD( *lparam
);
1456 uiHi
= HIWORD( *lparam
);
1457 TRACE("recv dde-ack %x atom=%x\n", uiLo
, uiHi
);
1459 *lparam
= PackDDElParam( WM_DDE_ACK
, uiLo
, uiHi
);
1464 if ((!buffer
|| !*buffer
) && message
!= WM_DDE_DATA
) return FALSE
;
1468 if (!(hMem
= GlobalAlloc( GMEM_MOVEABLE
|GMEM_DDESHARE
, size
)))
1470 if ((ptr
= GlobalLock( hMem
)))
1472 memcpy( ptr
, *buffer
, size
);
1473 GlobalUnlock( hMem
);
1481 uiLo
= (UINT_PTR
)hMem
;
1483 *lparam
= PackDDElParam( message
, uiLo
, uiHi
);
1485 case WM_DDE_EXECUTE
:
1488 if (!buffer
|| !*buffer
) return FALSE
;
1489 if (!(hMem
= GlobalAlloc( GMEM_MOVEABLE
|GMEM_DDESHARE
, size
))) return FALSE
;
1490 if ((ptr
= GlobalLock( hMem
)))
1492 memcpy( ptr
, *buffer
, size
);
1493 GlobalUnlock( hMem
);
1494 TRACE( "exec: pairing c=%08lx s=%08x\n", *lparam
, (DWORD
)hMem
);
1495 if (!dde_add_pair( (HGLOBAL
)*lparam
, hMem
))
1506 } else return FALSE
;
1507 *lparam
= (LPARAM
)hMem
;
1513 /***********************************************************************
1516 * Call a window procedure and the corresponding hooks.
1518 static LRESULT
call_window_proc( HWND hwnd
, UINT msg
, WPARAM wparam
, LPARAM lparam
,
1519 BOOL unicode
, BOOL same_thread
)
1521 struct user_thread_info
*thread_info
= get_user_thread_info();
1525 CWPRETSTRUCT cwpret
;
1527 if (thread_info
->recursion_count
> MAX_SENDMSG_RECURSION
) return 0;
1528 thread_info
->recursion_count
++;
1530 if (msg
& 0x80000000)
1532 result
= handle_internal_message( hwnd
, msg
, wparam
, lparam
);
1536 /* first the WH_CALLWNDPROC hook */
1537 hwnd
= WIN_GetFullHandle( hwnd
);
1538 cwp
.lParam
= lparam
;
1539 cwp
.wParam
= wparam
;
1542 HOOK_CallHooks( WH_CALLWNDPROC
, HC_ACTION
, same_thread
, (LPARAM
)&cwp
, unicode
);
1544 /* now call the window procedure */
1547 if (!(winproc
= (WNDPROC
)GetWindowLongPtrW( hwnd
, GWLP_WNDPROC
))) goto done
;
1548 result
= CallWindowProcW( winproc
, hwnd
, msg
, wparam
, lparam
);
1552 if (!(winproc
= (WNDPROC
)GetWindowLongPtrA( hwnd
, GWLP_WNDPROC
))) goto done
;
1553 result
= CallWindowProcA( winproc
, hwnd
, msg
, wparam
, lparam
);
1556 /* and finally the WH_CALLWNDPROCRET hook */
1557 cwpret
.lResult
= result
;
1558 cwpret
.lParam
= lparam
;
1559 cwpret
.wParam
= wparam
;
1560 cwpret
.message
= msg
;
1562 HOOK_CallHooks( WH_CALLWNDPROCRET
, HC_ACTION
, same_thread
, (LPARAM
)&cwpret
, unicode
);
1564 thread_info
->recursion_count
--;
1569 /***********************************************************************
1570 * send_parent_notify
1572 * Send a WM_PARENTNOTIFY to all ancestors of the given window, unless
1573 * the window has the WS_EX_NOPARENTNOTIFY style.
1575 static void send_parent_notify( HWND hwnd
, WORD event
, WORD idChild
, POINT pt
)
1577 /* pt has to be in the client coordinates of the parent window */
1578 MapWindowPoints( 0, hwnd
, &pt
, 1 );
1583 if (!(GetWindowLongW( hwnd
, GWL_STYLE
) & WS_CHILD
)) break;
1584 if (GetWindowLongW( hwnd
, GWL_EXSTYLE
) & WS_EX_NOPARENTNOTIFY
) break;
1585 if (!(parent
= GetParent(hwnd
))) break;
1586 if (parent
== GetDesktopWindow()) break;
1587 MapWindowPoints( hwnd
, parent
, &pt
, 1 );
1589 SendMessageW( hwnd
, WM_PARENTNOTIFY
,
1590 MAKEWPARAM( event
, idChild
), MAKELPARAM( pt
.x
, pt
.y
) );
1595 /***********************************************************************
1596 * accept_hardware_message
1598 * Tell the server we have passed the message to the app
1599 * (even though we may end up dropping it later on)
1601 static void accept_hardware_message( UINT hw_id
, BOOL remove
, HWND new_hwnd
)
1603 SERVER_START_REQ( accept_hardware_message
)
1606 req
->remove
= remove
;
1607 req
->new_win
= new_hwnd
;
1608 if (wine_server_call( req
))
1609 FIXME("Failed to reply to MSG_HARDWARE message. Message may not be removed from queue.\n");
1615 /***********************************************************************
1616 * process_keyboard_message
1618 * returns TRUE if the contents of 'msg' should be passed to the application
1620 static BOOL
process_keyboard_message( MSG
*msg
, UINT hw_id
, HWND hwnd_filter
,
1621 UINT first
, UINT last
, BOOL remove
)
1625 /* FIXME: is this really the right place for this hook? */
1626 event
.message
= msg
->message
;
1627 event
.hwnd
= msg
->hwnd
;
1628 event
.time
= msg
->time
;
1629 event
.paramL
= (msg
->wParam
& 0xFF) | (HIWORD(msg
->lParam
) << 8);
1630 event
.paramH
= msg
->lParam
& 0x7FFF;
1631 if (HIWORD(msg
->lParam
) & 0x0100) event
.paramH
|= 0x8000; /* special_key - bit */
1632 HOOK_CallHooks( WH_JOURNALRECORD
, HC_ACTION
, 0, (LPARAM
)&event
, TRUE
);
1634 /* check message filters */
1635 if (msg
->message
< first
|| msg
->message
> last
) return FALSE
;
1636 if (!check_hwnd_filter( msg
, hwnd_filter
)) return FALSE
;
1640 if((msg
->message
== WM_KEYDOWN
) &&
1641 (msg
->hwnd
!= GetDesktopWindow()))
1643 /* Handle F1 key by sending out WM_HELP message */
1644 if(msg
->wParam
== VK_F1
&&
1645 !MENU_IsMenuActive())
1648 hi
.cbSize
= sizeof(HELPINFO
);
1649 hi
.iContextType
= HELPINFO_WINDOW
;
1650 hi
.iCtrlId
= GetWindowLongPtrA( msg
->hwnd
, GWLP_ID
);
1651 hi
.hItemHandle
= msg
->hwnd
;
1652 hi
.dwContextId
= GetWindowContextHelpId( msg
->hwnd
);
1653 hi
.MousePos
= msg
->pt
;
1654 SendMessageW( msg
->hwnd
, WM_HELP
, 0, (LPARAM
)&hi
);
1656 else if(msg
->wParam
>= VK_BROWSER_BACK
&&
1657 msg
->wParam
<= VK_LAUNCH_APP2
)
1659 /* FIXME: Process keystate */
1660 SendMessageW(msg
->hwnd
, WM_APPCOMMAND
, (WPARAM
)msg
->hwnd
, MAKELPARAM(0, (FAPPCOMMAND_KEY
| (msg
->wParam
- VK_BROWSER_BACK
+ 1))));
1663 else if (msg
->message
== WM_KEYUP
)
1665 /* Handle VK_APPS key by posting a WM_CONTEXTMENU message */
1666 if (msg
->wParam
== VK_APPS
&& !MENU_IsMenuActive())
1667 PostMessageW(msg
->hwnd
, WM_CONTEXTMENU
, (WPARAM
)msg
->hwnd
, (LPARAM
)-1);
1671 if (HOOK_CallHooks( WH_KEYBOARD
, remove
? HC_ACTION
: HC_NOREMOVE
,
1672 LOWORD(msg
->wParam
), msg
->lParam
, TRUE
))
1674 /* skip this message */
1675 HOOK_CallHooks( WH_CBT
, HCBT_KEYSKIPPED
, LOWORD(msg
->wParam
), msg
->lParam
, TRUE
);
1676 accept_hardware_message( hw_id
, TRUE
, 0 );
1679 accept_hardware_message( hw_id
, remove
, 0 );
1684 /***********************************************************************
1685 * process_mouse_message
1687 * returns TRUE if the contents of 'msg' should be passed to the application
1689 static BOOL
process_mouse_message( MSG
*msg
, UINT hw_id
, ULONG_PTR extra_info
, HWND hwnd_filter
,
1690 UINT first
, UINT last
, BOOL remove
)
1699 MOUSEHOOKSTRUCT hook
;
1702 /* find the window to dispatch this mouse message to */
1704 GetGUIThreadInfo( GetCurrentThreadId(), &info
);
1705 if (info
.hwndCapture
)
1708 msg
->hwnd
= info
.hwndCapture
;
1712 msg
->hwnd
= WINPOS_WindowFromPoint( msg
->hwnd
, msg
->pt
, &hittest
);
1715 if (!msg
->hwnd
|| !WIN_IsCurrentThread( msg
->hwnd
))
1717 accept_hardware_message( hw_id
, TRUE
, msg
->hwnd
);
1721 /* FIXME: is this really the right place for this hook? */
1722 event
.message
= msg
->message
;
1723 event
.time
= msg
->time
;
1724 event
.hwnd
= msg
->hwnd
;
1725 event
.paramL
= msg
->pt
.x
;
1726 event
.paramH
= msg
->pt
.y
;
1727 HOOK_CallHooks( WH_JOURNALRECORD
, HC_ACTION
, 0, (LPARAM
)&event
, TRUE
);
1729 if (!check_hwnd_filter( msg
, hwnd_filter
)) return FALSE
;
1732 message
= msg
->message
;
1733 /* Note: windows has no concept of a non-client wheel message */
1734 if (message
!= WM_MOUSEWHEEL
)
1736 if (hittest
!= HTCLIENT
)
1738 message
+= WM_NCMOUSEMOVE
- WM_MOUSEMOVE
;
1739 msg
->wParam
= hittest
;
1743 /* coordinates don't get translated while tracking a menu */
1744 /* FIXME: should differentiate popups and top-level menus */
1745 if (!(info
.flags
& GUI_INMENUMODE
))
1746 ScreenToClient( msg
->hwnd
, &pt
);
1749 msg
->lParam
= MAKELONG( pt
.x
, pt
.y
);
1751 /* translate double clicks */
1753 if ((msg
->message
== WM_LBUTTONDOWN
) ||
1754 (msg
->message
== WM_RBUTTONDOWN
) ||
1755 (msg
->message
== WM_MBUTTONDOWN
) ||
1756 (msg
->message
== WM_XBUTTONDOWN
))
1758 BOOL update
= remove
;
1760 /* translate double clicks -
1761 * note that ...MOUSEMOVEs can slip in between
1762 * ...BUTTONDOWN and ...BUTTONDBLCLK messages */
1764 if ((info
.flags
& (GUI_INMENUMODE
|GUI_INMOVESIZE
)) ||
1765 hittest
!= HTCLIENT
||
1766 (GetClassLongA( msg
->hwnd
, GCL_STYLE
) & CS_DBLCLKS
))
1768 if ((msg
->message
== clk_msg
.message
) &&
1769 (msg
->hwnd
== clk_msg
.hwnd
) &&
1770 (msg
->wParam
== clk_msg
.wParam
) &&
1771 (msg
->time
- clk_msg
.time
< GetDoubleClickTime()) &&
1772 (abs(msg
->pt
.x
- clk_msg
.pt
.x
) < GetSystemMetrics(SM_CXDOUBLECLK
)/2) &&
1773 (abs(msg
->pt
.y
- clk_msg
.pt
.y
) < GetSystemMetrics(SM_CYDOUBLECLK
)/2))
1775 message
+= (WM_LBUTTONDBLCLK
- WM_LBUTTONDOWN
);
1778 clk_msg
.message
= 0; /* clear the double click conditions */
1783 if (message
< first
|| message
> last
) return FALSE
;
1784 /* update static double click conditions */
1785 if (update
) clk_msg
= *msg
;
1789 if (message
< first
|| message
> last
) return FALSE
;
1792 /* message is accepted now (but may still get dropped) */
1795 hook
.hwnd
= msg
->hwnd
;
1796 hook
.wHitTestCode
= hittest
;
1797 hook
.dwExtraInfo
= extra_info
;
1798 if (HOOK_CallHooks( WH_MOUSE
, remove
? HC_ACTION
: HC_NOREMOVE
,
1799 message
, (LPARAM
)&hook
, TRUE
))
1802 hook
.hwnd
= msg
->hwnd
;
1803 hook
.wHitTestCode
= hittest
;
1804 hook
.dwExtraInfo
= extra_info
;
1805 HOOK_CallHooks( WH_CBT
, HCBT_CLICKSKIPPED
, message
, (LPARAM
)&hook
, TRUE
);
1806 accept_hardware_message( hw_id
, TRUE
, 0 );
1810 if ((hittest
== HTERROR
) || (hittest
== HTNOWHERE
))
1812 SendMessageW( msg
->hwnd
, WM_SETCURSOR
, (WPARAM
)msg
->hwnd
,
1813 MAKELONG( hittest
, msg
->message
));
1814 accept_hardware_message( hw_id
, TRUE
, 0 );
1818 accept_hardware_message( hw_id
, remove
, 0 );
1820 if (!remove
|| info
.hwndCapture
)
1822 msg
->message
= message
;
1828 if ((msg
->message
== WM_LBUTTONDOWN
) ||
1829 (msg
->message
== WM_RBUTTONDOWN
) ||
1830 (msg
->message
== WM_MBUTTONDOWN
) ||
1831 (msg
->message
== WM_XBUTTONDOWN
))
1833 /* Send the WM_PARENTNOTIFY,
1834 * note that even for double/nonclient clicks
1835 * notification message is still WM_L/M/RBUTTONDOWN.
1837 send_parent_notify( msg
->hwnd
, msg
->message
, 0, msg
->pt
);
1839 /* Activate the window if needed */
1841 if (msg
->hwnd
!= info
.hwndActive
)
1843 HWND hwndTop
= msg
->hwnd
;
1846 if ((GetWindowLongW( hwndTop
, GWL_STYLE
) & (WS_POPUP
|WS_CHILD
)) != WS_CHILD
) break;
1847 hwndTop
= GetParent( hwndTop
);
1850 if (hwndTop
&& hwndTop
!= GetDesktopWindow())
1852 LONG ret
= SendMessageW( msg
->hwnd
, WM_MOUSEACTIVATE
, (WPARAM
)hwndTop
,
1853 MAKELONG( hittest
, msg
->message
) );
1856 case MA_NOACTIVATEANDEAT
:
1861 case MA_ACTIVATEANDEAT
:
1866 if (!FOCUS_MouseActivate( hwndTop
)) eatMsg
= TRUE
;
1869 WARN( "unknown WM_MOUSEACTIVATE code %d\n", ret
);
1876 /* send the WM_SETCURSOR message */
1878 /* Windows sends the normal mouse message as the message parameter
1879 in the WM_SETCURSOR message even if it's non-client mouse message */
1880 SendMessageW( msg
->hwnd
, WM_SETCURSOR
, (WPARAM
)msg
->hwnd
, MAKELONG( hittest
, msg
->message
));
1882 msg
->message
= message
;
1887 /***********************************************************************
1888 * process_hardware_message
1890 * Process a hardware message; return TRUE if message should be passed on to the app
1892 static BOOL
process_hardware_message( MSG
*msg
, UINT hw_id
, ULONG_PTR extra_info
, HWND hwnd_filter
,
1893 UINT first
, UINT last
, BOOL remove
)
1895 if (is_keyboard_message( msg
->message
))
1896 return process_keyboard_message( msg
, hw_id
, hwnd_filter
, first
, last
, remove
);
1898 if (is_mouse_message( msg
->message
))
1899 return process_mouse_message( msg
, hw_id
, extra_info
, hwnd_filter
, first
, last
, remove
);
1901 ERR( "unknown message type %x\n", msg
->message
);
1906 /***********************************************************************
1907 * call_sendmsg_callback
1909 * Call the callback function of SendMessageCallback.
1911 static inline void call_sendmsg_callback( SENDASYNCPROC callback
, HWND hwnd
, UINT msg
,
1912 ULONG_PTR data
, LRESULT result
)
1914 if (TRACE_ON(relay
))
1915 DPRINTF( "%04x:Call message callback %p (hwnd=%p,msg=%s,data=%08lx,result=%08lx)\n",
1916 GetCurrentThreadId(), callback
, hwnd
, SPY_GetMsgName( msg
, hwnd
),
1918 callback( hwnd
, msg
, data
, result
);
1919 if (TRACE_ON(relay
))
1920 DPRINTF( "%04x:Ret message callback %p (hwnd=%p,msg=%s,data=%08lx,result=%08lx)\n",
1921 GetCurrentThreadId(), callback
, hwnd
, SPY_GetMsgName( msg
, hwnd
),
1926 /***********************************************************************
1929 * Retrieve the hook procedure real value for a module-relative proc
1931 static void *get_hook_proc( void *proc
, const WCHAR
*module
)
1935 if (!(mod
= GetModuleHandleW(module
)))
1937 TRACE( "loading %s\n", debugstr_w(module
) );
1938 /* FIXME: the library will never be freed */
1939 if (!(mod
= LoadLibraryW(module
))) return NULL
;
1941 return (char *)mod
+ (ULONG_PTR
)proc
;
1945 /***********************************************************************
1948 * Peek for a message matching the given parameters. Return FALSE if none available.
1949 * All pending sent messages are processed before returning.
1951 static BOOL
peek_message( MSG
*msg
, HWND hwnd
, UINT first
, UINT last
, int flags
)
1954 ULONG_PTR extra_info
= 0;
1955 struct user_thread_info
*thread_info
= get_user_thread_info();
1956 struct received_message_info info
, *old_info
;
1957 unsigned int hw_id
= 0; /* id of previous hardware message */
1959 if (!first
&& !last
) last
= ~0;
1964 void *buffer
= NULL
;
1965 size_t size
= 0, buffer_size
= 0;
1967 do /* loop while buffer is too small */
1969 if (buffer_size
&& !(buffer
= HeapAlloc( GetProcessHeap(), 0, buffer_size
)))
1971 SERVER_START_REQ( get_message
)
1974 req
->get_win
= hwnd
;
1975 req
->get_first
= first
;
1976 req
->get_last
= last
;
1978 if (buffer_size
) wine_server_set_reply( req
, buffer
, buffer_size
);
1979 if (!(res
= wine_server_call( req
)))
1981 size
= wine_server_reply_size( reply
);
1982 info
.type
= reply
->type
;
1983 info
.msg
.hwnd
= reply
->win
;
1984 info
.msg
.message
= reply
->msg
;
1985 info
.msg
.wParam
= reply
->wparam
;
1986 info
.msg
.lParam
= reply
->lparam
;
1987 info
.msg
.time
= reply
->time
;
1988 info
.msg
.pt
.x
= reply
->x
;
1989 info
.msg
.pt
.y
= reply
->y
;
1990 hw_id
= reply
->hw_id
;
1991 extra_info
= reply
->info
;
1992 thread_info
->active_hooks
= reply
->active_hooks
;
1996 HeapFree( GetProcessHeap(), 0, buffer
);
1997 buffer_size
= reply
->total
;
2001 } while (res
== STATUS_BUFFER_OVERFLOW
);
2003 if (res
) return FALSE
;
2005 TRACE( "got type %d msg %x (%s) hwnd %p wp %x lp %lx\n",
2006 info
.type
, info
.msg
.message
,
2007 (info
.type
== MSG_WINEVENT
) ? "MSG_WINEVENT" : SPY_GetMsgName(info
.msg
.message
, info
.msg
.hwnd
),
2008 info
.msg
.hwnd
, info
.msg
.wParam
, info
.msg
.lParam
);
2014 info
.flags
= ISMEX_SEND
;
2017 info
.flags
= ISMEX_NOTIFY
;
2020 info
.flags
= ISMEX_CALLBACK
;
2022 case MSG_CALLBACK_RESULT
:
2023 if (size
>= sizeof(struct callback_msg_data
))
2025 const struct callback_msg_data
*data
= (const struct callback_msg_data
*)buffer
;
2026 call_sendmsg_callback( data
->callback
, info
.msg
.hwnd
,
2027 info
.msg
.message
, data
->data
, data
->result
);
2031 if (size
>= sizeof(struct winevent_msg_data
))
2033 WINEVENTPROC hook_proc
;
2034 const struct winevent_msg_data
*data
= (const struct winevent_msg_data
*)buffer
;
2036 hook_proc
= data
->hook_proc
;
2037 size
-= sizeof(*data
);
2040 WCHAR module
[MAX_PATH
];
2042 size
= min( size
, (MAX_PATH
- 1) * sizeof(WCHAR
) );
2043 memcpy( module
, buffer
, size
);
2044 module
[size
/ sizeof(WCHAR
)] = 0;
2045 if (!(hook_proc
= get_hook_proc( hook_proc
, module
)))
2047 ERR( "invalid winevent hook module name %s\n", debugstr_w(module
) );
2052 if (TRACE_ON(relay
))
2053 DPRINTF( "%04x:Call winevent proc %p (hook=%p,event=%x,hwnd=%p,object_id=%x,child_id=%lx,tid=%04x,time=%x)\n",
2054 GetCurrentThreadId(), hook_proc
,
2055 data
->hook
, info
.msg
.message
, info
.msg
.hwnd
, info
.msg
.wParam
,
2056 info
.msg
.lParam
, data
->tid
, info
.msg
.time
);
2058 hook_proc( data
->hook
, info
.msg
.message
, info
.msg
.hwnd
, info
.msg
.wParam
,
2059 info
.msg
.lParam
, data
->tid
, info
.msg
.time
);
2061 if (TRACE_ON(relay
))
2062 DPRINTF( "%04x:Ret winevent proc %p (hook=%p,event=%x,hwnd=%p,object_id=%x,child_id=%lx,tid=%04x,time=%x)\n",
2063 GetCurrentThreadId(), hook_proc
,
2064 data
->hook
, info
.msg
.message
, info
.msg
.hwnd
, info
.msg
.wParam
,
2065 info
.msg
.lParam
, data
->tid
, info
.msg
.time
);
2068 case MSG_OTHER_PROCESS
:
2069 info
.flags
= ISMEX_SEND
;
2070 if (!unpack_message( info
.msg
.hwnd
, info
.msg
.message
, &info
.msg
.wParam
,
2071 &info
.msg
.lParam
, &buffer
, size
))
2074 reply_message( &info
, 0, TRUE
);
2079 if (!process_hardware_message( &info
.msg
, hw_id
, extra_info
,
2080 hwnd
, first
, last
, flags
& GET_MSG_REMOVE
))
2082 TRACE("dropping msg %x\n", info
.msg
.message
);
2083 goto next
; /* ignore it */
2085 thread_info
->GetMessagePosVal
= MAKELONG( info
.msg
.pt
.x
, info
.msg
.pt
.y
);
2088 thread_info
->GetMessageExtraInfoVal
= extra_info
;
2089 if (info
.msg
.message
>= WM_DDE_FIRST
&& info
.msg
.message
<= WM_DDE_LAST
)
2091 if (!unpack_dde_message( info
.msg
.hwnd
, info
.msg
.message
, &info
.msg
.wParam
,
2092 &info
.msg
.lParam
, &buffer
, size
))
2093 goto next
; /* ignore it */
2096 HeapFree( GetProcessHeap(), 0, buffer
);
2100 /* if we get here, we have a sent message; call the window procedure */
2101 old_info
= thread_info
->receive_info
;
2102 thread_info
->receive_info
= &info
;
2103 result
= call_window_proc( info
.msg
.hwnd
, info
.msg
.message
, info
.msg
.wParam
,
2104 info
.msg
.lParam
, (info
.type
!= MSG_ASCII
), FALSE
);
2105 reply_message( &info
, result
, TRUE
);
2106 thread_info
->receive_info
= old_info
;
2108 HeapFree( GetProcessHeap(), 0, buffer
);
2113 /***********************************************************************
2114 * process_sent_messages
2116 * Process all pending sent messages.
2118 inline static void process_sent_messages(void)
2121 peek_message( &msg
, 0, 0, 0, GET_MSG_REMOVE
| GET_MSG_SENT_ONLY
);
2125 /***********************************************************************
2126 * get_server_queue_handle
2128 * Get a handle to the server message queue for the current thread.
2130 static HANDLE
get_server_queue_handle(void)
2132 struct user_thread_info
*thread_info
= get_user_thread_info();
2135 if (!(ret
= thread_info
->server_queue
))
2137 SERVER_START_REQ( get_msg_queue
)
2139 wine_server_call( req
);
2140 ret
= reply
->handle
;
2143 thread_info
->server_queue
= ret
;
2144 if (!ret
) ERR( "Cannot get server thread queue\n" );
2150 /***********************************************************************
2151 * wait_message_reply
2153 * Wait until a sent message gets replied to.
2155 static void wait_message_reply( UINT flags
)
2157 HANDLE server_queue
= get_server_queue_handle();
2161 unsigned int wake_bits
= 0, changed_bits
= 0;
2164 SERVER_START_REQ( set_queue_mask
)
2166 req
->wake_mask
= QS_SMRESULT
| ((flags
& SMTO_BLOCK
) ? 0 : QS_SENDMESSAGE
);
2167 req
->changed_mask
= req
->wake_mask
;
2169 if (!wine_server_call( req
))
2171 wake_bits
= reply
->wake_bits
;
2172 changed_bits
= reply
->changed_bits
;
2177 if (wake_bits
& QS_SMRESULT
) return; /* got a result */
2178 if (wake_bits
& QS_SENDMESSAGE
)
2180 /* Process the sent message immediately */
2181 process_sent_messages();
2185 /* now wait for it */
2187 ReleaseThunkLock( &dwlc
);
2188 res
= USER_Driver
->pMsgWaitForMultipleObjectsEx( 1, &server_queue
,
2189 INFINITE
, QS_SENDMESSAGE
, 0 );
2190 if (dwlc
) RestoreThunkLock( dwlc
);
2194 /***********************************************************************
2195 * put_message_in_queue
2197 * Put a sent message into the destination queue.
2198 * For inter-process message, reply_size is set to expected size of reply data.
2200 static BOOL
put_message_in_queue( const struct send_message_info
*info
, size_t *reply_size
)
2202 struct packed_message data
;
2203 message_data_t msg_data
;
2207 /* Check for INFINITE timeout for compatibility with Win9x,
2208 * although Windows >= NT does not do so
2210 if (info
->type
!= MSG_NOTIFY
&&
2211 info
->type
!= MSG_CALLBACK
&&
2212 info
->type
!= MSG_POSTED
&&
2213 info
->timeout
!= INFINITE
)
2214 timeout
= info
->timeout
;
2217 if (info
->type
== MSG_OTHER_PROCESS
)
2219 *reply_size
= pack_message( info
->hwnd
, info
->msg
, info
->wparam
, info
->lparam
, &data
);
2220 if (data
.count
== -1)
2222 WARN( "cannot pack message %x\n", info
->msg
);
2226 else if (info
->type
== MSG_CALLBACK
)
2228 msg_data
.callback
.callback
= info
->callback
;
2229 msg_data
.callback
.data
= info
->data
;
2230 msg_data
.callback
.result
= 0;
2231 data
.data
[0] = &msg_data
;
2232 data
.size
[0] = sizeof(msg_data
.callback
);
2235 else if (info
->type
== MSG_POSTED
&& info
->msg
>= WM_DDE_FIRST
&& info
->msg
<= WM_DDE_LAST
)
2237 return post_dde_message( &data
, info
);
2240 SERVER_START_REQ( send_message
)
2242 req
->id
= info
->dest_tid
;
2243 req
->type
= info
->type
;
2245 req
->win
= info
->hwnd
;
2246 req
->msg
= info
->msg
;
2247 req
->wparam
= info
->wparam
;
2248 req
->lparam
= info
->lparam
;
2249 req
->timeout
= timeout
;
2251 if (info
->flags
& SMTO_ABORTIFHUNG
) req
->flags
|= SEND_MSG_ABORT_IF_HUNG
;
2252 for (i
= 0; i
< data
.count
; i
++) wine_server_add_data( req
, data
.data
[i
], data
.size
[i
] );
2253 if ((res
= wine_server_call( req
)))
2255 if (res
== STATUS_INVALID_PARAMETER
)
2256 /* FIXME: find a STATUS_ value for this one */
2257 SetLastError( ERROR_INVALID_THREAD_ID
);
2259 SetLastError( RtlNtStatusToDosError(res
) );
2267 /***********************************************************************
2270 * Retrieve a message reply from the server.
2272 static LRESULT
retrieve_reply( const struct send_message_info
*info
,
2273 size_t reply_size
, LRESULT
*result
)
2276 void *reply_data
= NULL
;
2280 if (!(reply_data
= HeapAlloc( GetProcessHeap(), 0, reply_size
)))
2282 WARN( "no memory for reply, will be truncated\n" );
2286 SERVER_START_REQ( get_message_reply
)
2289 if (reply_size
) wine_server_set_reply( req
, reply_data
, reply_size
);
2290 if (!(status
= wine_server_call( req
))) *result
= reply
->result
;
2291 reply_size
= wine_server_reply_size( reply
);
2294 if (!status
&& reply_size
)
2295 unpack_reply( info
->hwnd
, info
->msg
, info
->wparam
, info
->lparam
, reply_data
, reply_size
);
2297 HeapFree( GetProcessHeap(), 0, reply_data
);
2299 TRACE( "hwnd %p msg %x (%s) wp %x lp %lx got reply %lx (err=%d)\n",
2300 info
->hwnd
, info
->msg
, SPY_GetMsgName(info
->msg
, info
->hwnd
), info
->wparam
,
2301 info
->lparam
, *result
, status
);
2303 /* MSDN states that last error is 0 on timeout, but at least NT4 returns ERROR_TIMEOUT */
2304 if (status
) SetLastError( RtlNtStatusToDosError(status
) );
2309 /***********************************************************************
2310 * send_inter_thread_message
2312 static LRESULT
send_inter_thread_message( const struct send_message_info
*info
, LRESULT
*res_ptr
)
2314 size_t reply_size
= 0;
2316 TRACE( "hwnd %p msg %x (%s) wp %x lp %lx\n",
2317 info
->hwnd
, info
->msg
, SPY_GetMsgName(info
->msg
, info
->hwnd
), info
->wparam
, info
->lparam
);
2319 USER_CheckNotLock();
2321 if (!put_message_in_queue( info
, &reply_size
)) return 0;
2323 /* there's no reply to wait for on notify/callback messages */
2324 if (info
->type
== MSG_NOTIFY
|| info
->type
== MSG_CALLBACK
) return 1;
2326 wait_message_reply( info
->flags
);
2327 return retrieve_reply( info
, reply_size
, res_ptr
);
2331 /***********************************************************************
2332 * MSG_SendInternalMessageTimeout
2334 * Same as SendMessageTimeoutW but sends the message to a specific thread
2335 * without requiring a window handle. Only works for internal Wine messages.
2337 LRESULT
MSG_SendInternalMessageTimeout( DWORD dest_pid
, DWORD dest_tid
,
2338 UINT msg
, WPARAM wparam
, LPARAM lparam
,
2339 UINT flags
, UINT timeout
, PDWORD_PTR res_ptr
)
2341 struct send_message_info info
;
2342 LRESULT ret
, result
;
2344 assert( msg
& 0x80000000 ); /* must be an internal Wine message */
2346 info
.type
= MSG_UNICODE
;
2347 info
.dest_tid
= dest_tid
;
2350 info
.wparam
= wparam
;
2351 info
.lparam
= lparam
;
2353 info
.timeout
= timeout
;
2355 if (USER_IsExitingThread( dest_tid
)) return 0;
2357 if (dest_tid
== GetCurrentThreadId())
2359 result
= handle_internal_message( 0, msg
, wparam
, lparam
);
2364 if (dest_pid
!= GetCurrentProcessId()) info
.type
= MSG_OTHER_PROCESS
;
2365 ret
= send_inter_thread_message( &info
, &result
);
2367 if (ret
&& res_ptr
) *res_ptr
= result
;
2372 /***********************************************************************
2373 * SendMessageTimeoutW (USER32.@)
2375 LRESULT WINAPI
SendMessageTimeoutW( HWND hwnd
, UINT msg
, WPARAM wparam
, LPARAM lparam
,
2376 UINT flags
, UINT timeout
, PDWORD_PTR res_ptr
)
2378 struct send_message_info info
;
2380 LRESULT ret
, result
;
2382 info
.type
= MSG_UNICODE
;
2385 info
.wparam
= wparam
;
2386 info
.lparam
= lparam
;
2388 info
.timeout
= timeout
;
2390 if (is_broadcast(hwnd
))
2392 EnumWindows( broadcast_message_callback
, (LPARAM
)&info
);
2393 if (res_ptr
) *res_ptr
= 1;
2397 if (!(info
.dest_tid
= GetWindowThreadProcessId( hwnd
, &dest_pid
))) return 0;
2399 if (USER_IsExitingThread( info
.dest_tid
)) return 0;
2401 SPY_EnterMessage( SPY_SENDMESSAGE
, hwnd
, msg
, wparam
, lparam
);
2403 if (info
.dest_tid
== GetCurrentThreadId())
2405 result
= call_window_proc( hwnd
, msg
, wparam
, lparam
, TRUE
, TRUE
);
2410 if (dest_pid
!= GetCurrentProcessId()) info
.type
= MSG_OTHER_PROCESS
;
2411 ret
= send_inter_thread_message( &info
, &result
);
2414 SPY_ExitMessage( SPY_RESULT_OK
, hwnd
, msg
, result
, wparam
, lparam
);
2415 if (ret
&& res_ptr
) *res_ptr
= result
;
2419 static LRESULT
send_inter_thread_callback( HWND hwnd
, UINT msg
, WPARAM wp
, LPARAM lp
,
2420 LRESULT
*result
, void *arg
)
2422 struct send_message_info
*info
= arg
;
2427 return send_inter_thread_message( info
, result
);
2430 /***********************************************************************
2431 * SendMessageTimeoutA (USER32.@)
2433 LRESULT WINAPI
SendMessageTimeoutA( HWND hwnd
, UINT msg
, WPARAM wparam
, LPARAM lparam
,
2434 UINT flags
, UINT timeout
, PDWORD_PTR res_ptr
)
2436 struct send_message_info info
;
2438 LRESULT ret
, result
;
2440 info
.type
= MSG_ASCII
;
2443 info
.wparam
= wparam
;
2444 info
.lparam
= lparam
;
2446 info
.timeout
= timeout
;
2448 if (is_broadcast(hwnd
))
2450 EnumWindows( broadcast_message_callback
, (LPARAM
)&info
);
2451 if (res_ptr
) *res_ptr
= 1;
2455 if (!(info
.dest_tid
= GetWindowThreadProcessId( hwnd
, &dest_pid
))) return 0;
2457 if (USER_IsExitingThread( info
.dest_tid
)) return 0;
2459 SPY_EnterMessage( SPY_SENDMESSAGE
, hwnd
, msg
, wparam
, lparam
);
2461 if (info
.dest_tid
== GetCurrentThreadId())
2463 result
= call_window_proc( hwnd
, msg
, wparam
, lparam
, FALSE
, TRUE
);
2466 else if (dest_pid
== GetCurrentProcessId())
2468 ret
= send_inter_thread_message( &info
, &result
);
2472 /* inter-process message: need to map to Unicode */
2473 info
.type
= MSG_OTHER_PROCESS
;
2474 if (is_unicode_message( info
.msg
))
2475 ret
= WINPROC_CallProcAtoW( send_inter_thread_callback
, info
.hwnd
, info
.msg
,
2476 info
.wparam
, info
.lparam
, &result
, &info
);
2477 else ret
= send_inter_thread_message( &info
, &result
);
2479 SPY_ExitMessage( SPY_RESULT_OK
, hwnd
, msg
, result
, wparam
, lparam
);
2480 if (ret
&& res_ptr
) *res_ptr
= result
;
2485 /***********************************************************************
2486 * SendMessageW (USER32.@)
2488 LRESULT WINAPI
SendMessageW( HWND hwnd
, UINT msg
, WPARAM wparam
, LPARAM lparam
)
2491 SendMessageTimeoutW( hwnd
, msg
, wparam
, lparam
, SMTO_NORMAL
, 0, &res
);
2496 /***********************************************************************
2497 * SendMessageA (USER32.@)
2499 LRESULT WINAPI
SendMessageA( HWND hwnd
, UINT msg
, WPARAM wparam
, LPARAM lparam
)
2502 SendMessageTimeoutA( hwnd
, msg
, wparam
, lparam
, SMTO_NORMAL
, 0, &res
);
2507 /***********************************************************************
2508 * SendNotifyMessageA (USER32.@)
2510 BOOL WINAPI
SendNotifyMessageA( HWND hwnd
, UINT msg
, WPARAM wparam
, LPARAM lparam
)
2512 return SendNotifyMessageW( hwnd
, msg
, map_wparam_AtoW( msg
, wparam
), lparam
);
2516 /***********************************************************************
2517 * SendNotifyMessageW (USER32.@)
2519 BOOL WINAPI
SendNotifyMessageW( HWND hwnd
, UINT msg
, WPARAM wparam
, LPARAM lparam
)
2521 struct send_message_info info
;
2524 if (is_pointer_message(msg
))
2526 SetLastError( ERROR_MESSAGE_SYNC_ONLY
);
2530 info
.type
= MSG_NOTIFY
;
2533 info
.wparam
= wparam
;
2534 info
.lparam
= lparam
;
2537 if (is_broadcast(hwnd
))
2539 EnumWindows( broadcast_message_callback
, (LPARAM
)&info
);
2543 if (!(info
.dest_tid
= GetWindowThreadProcessId( hwnd
, NULL
))) return FALSE
;
2545 if (USER_IsExitingThread( info
.dest_tid
)) return TRUE
;
2547 if (info
.dest_tid
== GetCurrentThreadId())
2549 call_window_proc( hwnd
, msg
, wparam
, lparam
, TRUE
, TRUE
);
2552 return send_inter_thread_message( &info
, &result
);
2556 /***********************************************************************
2557 * SendMessageCallbackA (USER32.@)
2559 BOOL WINAPI
SendMessageCallbackA( HWND hwnd
, UINT msg
, WPARAM wparam
, LPARAM lparam
,
2560 SENDASYNCPROC callback
, ULONG_PTR data
)
2562 return SendMessageCallbackW( hwnd
, msg
, map_wparam_AtoW( msg
, wparam
),
2563 lparam
, callback
, data
);
2567 /***********************************************************************
2568 * SendMessageCallbackW (USER32.@)
2570 BOOL WINAPI
SendMessageCallbackW( HWND hwnd
, UINT msg
, WPARAM wparam
, LPARAM lparam
,
2571 SENDASYNCPROC callback
, ULONG_PTR data
)
2573 struct send_message_info info
;
2576 if (is_pointer_message(msg
))
2578 SetLastError( ERROR_MESSAGE_SYNC_ONLY
);
2582 info
.type
= MSG_CALLBACK
;
2585 info
.wparam
= wparam
;
2586 info
.lparam
= lparam
;
2587 info
.callback
= callback
;
2591 if (is_broadcast(hwnd
))
2593 EnumWindows( broadcast_message_callback
, (LPARAM
)&info
);
2597 if (!(info
.dest_tid
= GetWindowThreadProcessId( hwnd
, NULL
))) return FALSE
;
2599 if (USER_IsExitingThread( info
.dest_tid
)) return TRUE
;
2601 if (info
.dest_tid
== GetCurrentThreadId())
2603 result
= call_window_proc( hwnd
, msg
, wparam
, lparam
, TRUE
, TRUE
);
2604 call_sendmsg_callback( callback
, hwnd
, msg
, data
, result
);
2607 return send_inter_thread_message( &info
, &result
);
2611 /***********************************************************************
2612 * ReplyMessage (USER32.@)
2614 BOOL WINAPI
ReplyMessage( LRESULT result
)
2616 struct received_message_info
*info
= get_user_thread_info()->receive_info
;
2618 if (!info
) return FALSE
;
2619 reply_message( info
, result
, FALSE
);
2624 /***********************************************************************
2625 * InSendMessage (USER32.@)
2627 BOOL WINAPI
InSendMessage(void)
2629 return (InSendMessageEx(NULL
) & (ISMEX_SEND
|ISMEX_REPLIED
)) == ISMEX_SEND
;
2633 /***********************************************************************
2634 * InSendMessageEx (USER32.@)
2636 DWORD WINAPI
InSendMessageEx( LPVOID reserved
)
2638 struct received_message_info
*info
= get_user_thread_info()->receive_info
;
2640 if (info
) return info
->flags
;
2641 return ISMEX_NOSEND
;
2645 /***********************************************************************
2646 * PostMessageA (USER32.@)
2648 BOOL WINAPI
PostMessageA( HWND hwnd
, UINT msg
, WPARAM wparam
, LPARAM lparam
)
2650 return PostMessageW( hwnd
, msg
, map_wparam_AtoW( msg
, wparam
), lparam
);
2654 /***********************************************************************
2655 * PostMessageW (USER32.@)
2657 BOOL WINAPI
PostMessageW( HWND hwnd
, UINT msg
, WPARAM wparam
, LPARAM lparam
)
2659 struct send_message_info info
;
2661 if (is_pointer_message( msg
))
2663 SetLastError( ERROR_MESSAGE_SYNC_ONLY
);
2667 TRACE( "hwnd %p msg %x (%s) wp %x lp %lx\n",
2668 hwnd
, msg
, SPY_GetMsgName(msg
, hwnd
), wparam
, lparam
);
2670 info
.type
= MSG_POSTED
;
2673 info
.wparam
= wparam
;
2674 info
.lparam
= lparam
;
2677 if (is_broadcast(hwnd
))
2679 EnumWindows( broadcast_message_callback
, (LPARAM
)&info
);
2683 if (!hwnd
) return PostThreadMessageW( GetCurrentThreadId(), msg
, wparam
, lparam
);
2685 if (!(info
.dest_tid
= GetWindowThreadProcessId( hwnd
, NULL
))) return FALSE
;
2687 if (USER_IsExitingThread( info
.dest_tid
)) return TRUE
;
2689 return put_message_in_queue( &info
, NULL
);
2693 /**********************************************************************
2694 * PostThreadMessageA (USER32.@)
2696 BOOL WINAPI
PostThreadMessageA( DWORD thread
, UINT msg
, WPARAM wparam
, LPARAM lparam
)
2698 return PostThreadMessageW( thread
, msg
, map_wparam_AtoW( msg
, wparam
), lparam
);
2702 /**********************************************************************
2703 * PostThreadMessageW (USER32.@)
2705 BOOL WINAPI
PostThreadMessageW( DWORD thread
, UINT msg
, WPARAM wparam
, LPARAM lparam
)
2707 struct send_message_info info
;
2709 if (is_pointer_message( msg
))
2711 SetLastError( ERROR_MESSAGE_SYNC_ONLY
);
2714 if (USER_IsExitingThread( thread
)) return TRUE
;
2716 info
.type
= MSG_POSTED
;
2717 info
.dest_tid
= thread
;
2720 info
.wparam
= wparam
;
2721 info
.lparam
= lparam
;
2723 return put_message_in_queue( &info
, NULL
);
2727 /***********************************************************************
2728 * PostQuitMessage (USER32.@)
2730 * Posts a quit message to the current thread's message queue.
2733 * exit_code [I] Exit code to return from message loop.
2739 * This function is not the same as calling:
2740 *|PostThreadMessage(GetCurrentThreadId(), WM_QUIT, exit_code, 0);
2741 * It instead sets a flag in the message queue that signals it to generate
2742 * a WM_QUIT message when there are no other pending sent or posted messages
2745 void WINAPI
PostQuitMessage( INT exit_code
)
2747 SERVER_START_REQ( post_quit_message
)
2749 req
->exit_code
= exit_code
;
2750 wine_server_call( req
);
2756 /***********************************************************************
2757 * PeekMessageW (USER32.@)
2759 BOOL WINAPI
PeekMessageW( MSG
*msg_out
, HWND hwnd
, UINT first
, UINT last
, UINT flags
)
2761 struct user_thread_info
*thread_info
= get_user_thread_info();
2765 FIXME("PM_QS_xxxx flags (%04x) are not handled\n", flags
>> 16);
2767 USER_CheckNotLock();
2769 /* check for graphics events */
2770 USER_Driver
->pMsgWaitForMultipleObjectsEx( 0, NULL
, 0, QS_ALLINPUT
, 0 );
2772 hwnd
= WIN_GetFullHandle( hwnd
);
2776 if (!peek_message( &msg
, hwnd
, first
, last
, (flags
& PM_REMOVE
) ? GET_MSG_REMOVE
: 0 ))
2778 if (!(flags
& PM_NOYIELD
))
2781 ReleaseThunkLock(&count
);
2783 if (count
) RestoreThunkLock(count
);
2787 if (msg
.message
& 0x80000000)
2789 if (!(flags
& PM_REMOVE
))
2791 /* Have to remove the message explicitly.
2792 Do this before handling it, because the message handler may
2793 call PeekMessage again */
2794 peek_message( &msg
, msg
.hwnd
, msg
.message
, msg
.message
, GET_MSG_REMOVE
);
2796 handle_internal_message( msg
.hwnd
, msg
.message
, msg
.wParam
, msg
.lParam
);
2801 thread_info
->GetMessageTimeVal
= msg
.time
;
2802 msg
.pt
.x
= (short)LOWORD( thread_info
->GetMessagePosVal
);
2803 msg
.pt
.y
= (short)HIWORD( thread_info
->GetMessagePosVal
);
2805 HOOK_CallHooks( WH_GETMESSAGE
, HC_ACTION
, flags
& PM_REMOVE
, (LPARAM
)&msg
, TRUE
);
2807 /* copy back our internal safe copy of message data to msg_out.
2808 * msg_out is a variable from the *program*, so it can't be used
2809 * internally as it can get "corrupted" by our use of SendMessage()
2810 * (back to the program) inside the message handling itself. */
2813 SetLastError( ERROR_NOACCESS
);
2821 /***********************************************************************
2822 * PeekMessageA (USER32.@)
2824 BOOL WINAPI
PeekMessageA( MSG
*msg
, HWND hwnd
, UINT first
, UINT last
, UINT flags
)
2826 BOOL ret
= PeekMessageW( msg
, hwnd
, first
, last
, flags
);
2827 if (ret
) msg
->wParam
= map_wparam_WtoA( msg
->message
, msg
->wParam
);
2832 /***********************************************************************
2833 * GetMessageW (USER32.@)
2835 BOOL WINAPI
GetMessageW( MSG
*msg
, HWND hwnd
, UINT first
, UINT last
)
2837 HANDLE server_queue
= get_server_queue_handle();
2838 int mask
= QS_POSTMESSAGE
| QS_SENDMESSAGE
; /* Always selected */
2842 if ((first
<= WM_KEYLAST
) && (last
>= WM_KEYFIRST
)) mask
|= QS_KEY
;
2843 if ( ((first
<= WM_MOUSELAST
) && (last
>= WM_MOUSEFIRST
)) ||
2844 ((first
<= WM_NCMOUSELAST
) && (last
>= WM_NCMOUSEFIRST
)) ) mask
|= QS_MOUSE
;
2845 if ((first
<= WM_TIMER
) && (last
>= WM_TIMER
)) mask
|= QS_TIMER
;
2846 if ((first
<= WM_SYSTIMER
) && (last
>= WM_SYSTIMER
)) mask
|= QS_TIMER
;
2847 if ((first
<= WM_PAINT
) && (last
>= WM_PAINT
)) mask
|= QS_PAINT
;
2849 else mask
|= QS_MOUSE
| QS_KEY
| QS_TIMER
| QS_PAINT
;
2851 while (!PeekMessageW( msg
, hwnd
, first
, last
, PM_REMOVE
))
2853 /* wait until one of the bits is set */
2854 unsigned int wake_bits
= 0, changed_bits
= 0;
2857 SERVER_START_REQ( set_queue_mask
)
2859 req
->wake_mask
= QS_SENDMESSAGE
;
2860 req
->changed_mask
= mask
;
2862 if (!wine_server_call( req
))
2864 wake_bits
= reply
->wake_bits
;
2865 changed_bits
= reply
->changed_bits
;
2870 if (changed_bits
& mask
) continue;
2871 if (wake_bits
& QS_SENDMESSAGE
) continue;
2873 TRACE( "(%04x) mask=%08x, bits=%08x, changed=%08x, waiting\n",
2874 GetCurrentThreadId(), mask
, wake_bits
, changed_bits
);
2876 ReleaseThunkLock( &dwlc
);
2877 USER_Driver
->pMsgWaitForMultipleObjectsEx( 1, &server_queue
, INFINITE
, QS_ALLINPUT
, 0 );
2878 if (dwlc
) RestoreThunkLock( dwlc
);
2881 return (msg
->message
!= WM_QUIT
);
2885 /***********************************************************************
2886 * GetMessageA (USER32.@)
2888 BOOL WINAPI
GetMessageA( MSG
*msg
, HWND hwnd
, UINT first
, UINT last
)
2890 GetMessageW( msg
, hwnd
, first
, last
);
2891 msg
->wParam
= map_wparam_WtoA( msg
->message
, msg
->wParam
);
2892 return (msg
->message
!= WM_QUIT
);
2896 /***********************************************************************
2897 * IsDialogMessageA (USER32.@)
2898 * IsDialogMessage (USER32.@)
2900 BOOL WINAPI
IsDialogMessageA( HWND hwndDlg
, LPMSG pmsg
)
2903 msg
.wParam
= map_wparam_AtoW( msg
.message
, msg
.wParam
);
2904 return IsDialogMessageW( hwndDlg
, &msg
);
2908 /***********************************************************************
2909 * TranslateMessage (USER32.@)
2911 * Implementation of TranslateMessage.
2913 * TranslateMessage translates virtual-key messages into character-messages,
2915 * WM_KEYDOWN/WM_KEYUP combinations produce a WM_CHAR or WM_DEADCHAR message.
2916 * ditto replacing WM_* with WM_SYS*
2917 * This produces WM_CHAR messages only for keys mapped to ASCII characters
2918 * by the keyboard driver.
2920 * If the message is WM_KEYDOWN, WM_KEYUP, WM_SYSKEYDOWN, or WM_SYSKEYUP, the
2921 * return value is nonzero, regardless of the translation.
2924 BOOL WINAPI
TranslateMessage( const MSG
*msg
)
2930 if (msg
->message
< WM_KEYFIRST
|| msg
->message
> WM_KEYLAST
) return FALSE
;
2931 if (msg
->message
!= WM_KEYDOWN
&& msg
->message
!= WM_SYSKEYDOWN
) return TRUE
;
2933 TRACE_(key
)("Translating key %s (%04x), scancode %02x\n",
2934 SPY_GetVKeyName(msg
->wParam
), msg
->wParam
, LOBYTE(HIWORD(msg
->lParam
)));
2936 GetKeyboardState( state
);
2937 /* FIXME : should handle ToUnicode yielding 2 */
2938 switch (ToUnicode(msg
->wParam
, HIWORD(msg
->lParam
), state
, wp
, 2, 0))
2941 message
= (msg
->message
== WM_KEYDOWN
) ? WM_CHAR
: WM_SYSCHAR
;
2942 TRACE_(key
)("1 -> PostMessageW(%p,%s,%04x,%08lx)\n",
2943 msg
->hwnd
, SPY_GetMsgName(message
, msg
->hwnd
), wp
[0], msg
->lParam
);
2944 PostMessageW( msg
->hwnd
, message
, wp
[0], msg
->lParam
);
2948 message
= (msg
->message
== WM_KEYDOWN
) ? WM_DEADCHAR
: WM_SYSDEADCHAR
;
2949 TRACE_(key
)("-1 -> PostMessageW(%p,%s,%04x,%08lx)\n",
2950 msg
->hwnd
, SPY_GetMsgName(message
, msg
->hwnd
), wp
[0], msg
->lParam
);
2951 PostMessageW( msg
->hwnd
, message
, wp
[0], msg
->lParam
);
2958 /***********************************************************************
2959 * DispatchMessageA (USER32.@)
2961 * See DispatchMessageW.
2963 LONG WINAPI
DispatchMessageA( const MSG
* msg
)
2969 /* Process timer messages */
2970 if ((msg
->message
== WM_TIMER
) || (msg
->message
== WM_SYSTIMER
))
2972 if (msg
->lParam
) return CallWindowProcA( (WNDPROC
)msg
->lParam
, msg
->hwnd
,
2973 msg
->message
, msg
->wParam
, GetTickCount() );
2976 if (!(wndPtr
= WIN_GetPtr( msg
->hwnd
)))
2978 if (msg
->hwnd
) SetLastError( ERROR_INVALID_WINDOW_HANDLE
);
2981 if (wndPtr
== WND_OTHER_PROCESS
|| wndPtr
== WND_DESKTOP
)
2983 if (IsWindow( msg
->hwnd
)) SetLastError( ERROR_MESSAGE_SYNC_ONLY
);
2984 else SetLastError( ERROR_INVALID_WINDOW_HANDLE
);
2987 if (wndPtr
->tid
!= GetCurrentThreadId())
2989 SetLastError( ERROR_MESSAGE_SYNC_ONLY
);
2990 WIN_ReleasePtr( wndPtr
);
2993 winproc
= wndPtr
->winproc
;
2994 WIN_ReleasePtr( wndPtr
);
2996 SPY_EnterMessage( SPY_DISPATCHMESSAGE
, msg
->hwnd
, msg
->message
,
2997 msg
->wParam
, msg
->lParam
);
2998 retval
= CallWindowProcA( winproc
, msg
->hwnd
, msg
->message
,
2999 msg
->wParam
, msg
->lParam
);
3000 SPY_ExitMessage( SPY_RESULT_OK
, msg
->hwnd
, msg
->message
, retval
,
3001 msg
->wParam
, msg
->lParam
);
3003 if (msg
->message
== WM_PAINT
)
3005 /* send a WM_NCPAINT and WM_ERASEBKGND if the non-client area is still invalid */
3006 HRGN hrgn
= CreateRectRgn( 0, 0, 0, 0 );
3007 GetUpdateRgn( msg
->hwnd
, hrgn
, TRUE
);
3008 DeleteObject( hrgn
);
3014 /***********************************************************************
3015 * DispatchMessageW (USER32.@) Process a message
3017 * Process the message specified in the structure *_msg_.
3019 * If the lpMsg parameter points to a WM_TIMER message and the
3020 * parameter of the WM_TIMER message is not NULL, the lParam parameter
3021 * points to the function that is called instead of the window
3024 * The message must be valid.
3028 * DispatchMessage() returns the result of the window procedure invoked.
3035 LONG WINAPI
DispatchMessageW( const MSG
* msg
)
3041 /* Process timer messages */
3042 if ((msg
->message
== WM_TIMER
) || (msg
->message
== WM_SYSTIMER
))
3044 if (msg
->lParam
) return CallWindowProcW( (WNDPROC
)msg
->lParam
, msg
->hwnd
,
3045 msg
->message
, msg
->wParam
, GetTickCount() );
3048 if (!(wndPtr
= WIN_GetPtr( msg
->hwnd
)))
3050 if (msg
->hwnd
) SetLastError( ERROR_INVALID_WINDOW_HANDLE
);
3053 if (wndPtr
== WND_OTHER_PROCESS
|| wndPtr
== WND_DESKTOP
)
3055 if (IsWindow( msg
->hwnd
)) SetLastError( ERROR_MESSAGE_SYNC_ONLY
);
3056 else SetLastError( ERROR_INVALID_WINDOW_HANDLE
);
3059 if (wndPtr
->tid
!= GetCurrentThreadId())
3061 SetLastError( ERROR_MESSAGE_SYNC_ONLY
);
3062 WIN_ReleasePtr( wndPtr
);
3065 winproc
= wndPtr
->winproc
;
3066 WIN_ReleasePtr( wndPtr
);
3068 SPY_EnterMessage( SPY_DISPATCHMESSAGE
, msg
->hwnd
, msg
->message
,
3069 msg
->wParam
, msg
->lParam
);
3070 retval
= CallWindowProcW( winproc
, msg
->hwnd
, msg
->message
,
3071 msg
->wParam
, msg
->lParam
);
3072 SPY_ExitMessage( SPY_RESULT_OK
, msg
->hwnd
, msg
->message
, retval
,
3073 msg
->wParam
, msg
->lParam
);
3075 if (msg
->message
== WM_PAINT
)
3077 /* send a WM_NCPAINT and WM_ERASEBKGND if the non-client area is still invalid */
3078 HRGN hrgn
= CreateRectRgn( 0, 0, 0, 0 );
3079 GetUpdateRgn( msg
->hwnd
, hrgn
, TRUE
);
3080 DeleteObject( hrgn
);
3086 /***********************************************************************
3087 * GetMessagePos (USER.119)
3088 * GetMessagePos (USER32.@)
3090 * The GetMessagePos() function returns a long value representing a
3091 * cursor position, in screen coordinates, when the last message
3092 * retrieved by the GetMessage() function occurs. The x-coordinate is
3093 * in the low-order word of the return value, the y-coordinate is in
3094 * the high-order word. The application can use the MAKEPOINT()
3095 * macro to obtain a POINT structure from the return value.
3097 * For the current cursor position, use GetCursorPos().
3101 * Cursor position of last message on success, zero on failure.
3108 DWORD WINAPI
GetMessagePos(void)
3110 return get_user_thread_info()->GetMessagePosVal
;
3114 /***********************************************************************
3115 * GetMessageTime (USER.120)
3116 * GetMessageTime (USER32.@)
3118 * GetMessageTime() returns the message time for the last message
3119 * retrieved by the function. The time is measured in milliseconds with
3120 * the same offset as GetTickCount().
3122 * Since the tick count wraps, this is only useful for moderately short
3123 * relative time comparisons.
3127 * Time of last message on success, zero on failure.
3129 LONG WINAPI
GetMessageTime(void)
3131 return get_user_thread_info()->GetMessageTimeVal
;
3135 /***********************************************************************
3136 * GetMessageExtraInfo (USER.288)
3137 * GetMessageExtraInfo (USER32.@)
3139 LPARAM WINAPI
GetMessageExtraInfo(void)
3141 return get_user_thread_info()->GetMessageExtraInfoVal
;
3145 /***********************************************************************
3146 * SetMessageExtraInfo (USER32.@)
3148 LPARAM WINAPI
SetMessageExtraInfo(LPARAM lParam
)
3150 struct user_thread_info
*thread_info
= get_user_thread_info();
3151 LONG old_value
= thread_info
->GetMessageExtraInfoVal
;
3152 thread_info
->GetMessageExtraInfoVal
= lParam
;
3157 /***********************************************************************
3158 * WaitMessage (USER.112) Suspend thread pending messages
3159 * WaitMessage (USER32.@) Suspend thread pending messages
3161 * WaitMessage() suspends a thread until events appear in the thread's
3164 BOOL WINAPI
WaitMessage(void)
3166 return (MsgWaitForMultipleObjectsEx( 0, NULL
, INFINITE
, QS_ALLINPUT
, 0 ) != WAIT_FAILED
);
3170 /***********************************************************************
3171 * MsgWaitForMultipleObjectsEx (USER32.@)
3173 DWORD WINAPI
MsgWaitForMultipleObjectsEx( DWORD count
, CONST HANDLE
*pHandles
,
3174 DWORD timeout
, DWORD mask
, DWORD flags
)
3176 HANDLE handles
[MAXIMUM_WAIT_OBJECTS
];
3179 if (count
> MAXIMUM_WAIT_OBJECTS
-1)
3181 SetLastError( ERROR_INVALID_PARAMETER
);
3185 /* set the queue mask */
3186 SERVER_START_REQ( set_queue_mask
)
3188 req
->wake_mask
= (flags
& MWMO_INPUTAVAILABLE
) ? mask
: 0;
3189 req
->changed_mask
= mask
;
3191 wine_server_call( req
);
3195 /* Add the thread event to the handle list */
3196 for (i
= 0; i
< count
; i
++) handles
[i
] = pHandles
[i
];
3197 handles
[count
] = get_server_queue_handle();
3199 ReleaseThunkLock( &lock
);
3200 ret
= USER_Driver
->pMsgWaitForMultipleObjectsEx( count
+1, handles
, timeout
, mask
, flags
);
3201 if (ret
== count
+1) ret
= count
; /* pretend the msg queue is ready */
3202 if (lock
) RestoreThunkLock( lock
);
3207 /***********************************************************************
3208 * MsgWaitForMultipleObjects (USER32.@)
3210 DWORD WINAPI
MsgWaitForMultipleObjects( DWORD count
, CONST HANDLE
*handles
,
3211 BOOL wait_all
, DWORD timeout
, DWORD mask
)
3213 return MsgWaitForMultipleObjectsEx( count
, handles
, timeout
, mask
,
3214 wait_all
? MWMO_WAITALL
: 0 );
3218 /***********************************************************************
3219 * WaitForInputIdle (USER32.@)
3221 DWORD WINAPI
WaitForInputIdle( HANDLE hProcess
, DWORD dwTimeOut
)
3223 DWORD start_time
, elapsed
, ret
;
3226 handles
[0] = hProcess
;
3227 SERVER_START_REQ( get_process_idle_event
)
3229 req
->handle
= hProcess
;
3230 if (!(ret
= wine_server_call_err( req
))) handles
[1] = reply
->event
;
3233 if (ret
) return WAIT_FAILED
; /* error */
3234 if (!handles
[1]) return 0; /* no event to wait on */
3236 start_time
= GetTickCount();
3239 TRACE("waiting for %p\n", handles
[1] );
3242 ret
= MsgWaitForMultipleObjects ( 2, handles
, FALSE
, dwTimeOut
- elapsed
, QS_SENDMESSAGE
);
3247 case WAIT_OBJECT_0
+2:
3248 process_sent_messages();
3252 TRACE("timeout or error\n");
3255 TRACE("finished\n");
3258 if (dwTimeOut
!= INFINITE
)
3260 elapsed
= GetTickCount() - start_time
;
3261 if (elapsed
> dwTimeOut
)
3267 return WAIT_TIMEOUT
;
3271 /***********************************************************************
3272 * UserYield (USER.332)
3274 void WINAPI
UserYield16(void)
3278 /* Handle sent messages */
3279 process_sent_messages();
3282 ReleaseThunkLock(&count
);
3286 RestoreThunkLock(count
);
3287 /* Handle sent messages again */
3288 process_sent_messages();
3293 /***********************************************************************
3294 * RegisterWindowMessageA (USER32.@)
3295 * RegisterWindowMessage (USER.118)
3297 UINT WINAPI
RegisterWindowMessageA( LPCSTR str
)
3299 UINT ret
= GlobalAddAtomA(str
);
3300 TRACE("%s, ret=%x\n", str
, ret
);
3305 /***********************************************************************
3306 * RegisterWindowMessageW (USER32.@)
3308 UINT WINAPI
RegisterWindowMessageW( LPCWSTR str
)
3310 UINT ret
= GlobalAddAtomW(str
);
3311 TRACE("%s ret=%x\n", debugstr_w(str
), ret
);
3316 /***********************************************************************
3317 * BroadcastSystemMessageA (USER32.@)
3318 * BroadcastSystemMessage (USER32.@)
3320 LONG WINAPI
BroadcastSystemMessageA( DWORD flags
, LPDWORD recipients
, UINT msg
, WPARAM wp
, LPARAM lp
)
3322 if ((*recipients
& BSM_APPLICATIONS
) || (*recipients
== BSM_ALLCOMPONENTS
))
3324 FIXME( "(%08x,%08x,%08x,%08x,%08lx): semi-stub!\n", flags
, *recipients
, msg
, wp
, lp
);
3325 PostMessageA( HWND_BROADCAST
, msg
, wp
, lp
);
3330 FIXME( "(%08x,%08x,%08x,%08x,%08lx): stub!\n", flags
, *recipients
, msg
, wp
, lp
);
3336 /***********************************************************************
3337 * BroadcastSystemMessageW (USER32.@)
3339 LONG WINAPI
BroadcastSystemMessageW( DWORD flags
, LPDWORD recipients
, UINT msg
, WPARAM wp
, LPARAM lp
)
3341 if ((*recipients
& BSM_APPLICATIONS
) || (*recipients
== BSM_ALLCOMPONENTS
))
3343 FIXME( "(%08x,%08x,%08x,%08x,%08lx): semi-stub!\n", flags
, *recipients
, msg
, wp
, lp
);
3344 PostMessageW( HWND_BROADCAST
, msg
, wp
, lp
);
3349 FIXME( "(%08x,%08x,%08x,%08x,%08lx): stub!\n", flags
, *recipients
, msg
, wp
, lp
);
3355 /***********************************************************************
3356 * SetMessageQueue (USER32.@)
3358 BOOL WINAPI
SetMessageQueue( INT size
)
3360 /* now obsolete the message queue will be expanded dynamically as necessary */
3365 /***********************************************************************
3366 * MessageBeep (USER32.@)
3368 BOOL WINAPI
MessageBeep( UINT i
)
3371 SystemParametersInfoA( SPI_GETBEEP
, 0, &active
, FALSE
);
3372 if (active
) USER_Driver
->pBeep();
3377 /***********************************************************************
3378 * SetTimer (USER32.@)
3380 UINT_PTR WINAPI
SetTimer( HWND hwnd
, UINT_PTR id
, UINT timeout
, TIMERPROC proc
)
3383 WNDPROC winproc
= 0;
3385 if (proc
) winproc
= WINPROC_AllocProc( (WNDPROC
)proc
, NULL
);
3387 SERVER_START_REQ( set_win_timer
)
3390 req
->msg
= WM_TIMER
;
3392 req
->rate
= max( timeout
, SYS_TIMER_RATE
);
3393 req
->lparam
= (unsigned long)winproc
;
3394 if (!wine_server_call_err( req
))
3397 if (!ret
) ret
= TRUE
;
3403 TRACE("Added %p %x %p timeout %d\n", hwnd
, id
, winproc
, timeout
);
3408 /***********************************************************************
3409 * SetSystemTimer (USER32.@)
3411 UINT_PTR WINAPI
SetSystemTimer( HWND hwnd
, UINT_PTR id
, UINT timeout
, TIMERPROC proc
)
3414 WNDPROC winproc
= 0;
3416 if (proc
) winproc
= WINPROC_AllocProc( (WNDPROC
)proc
, NULL
);
3418 SERVER_START_REQ( set_win_timer
)
3421 req
->msg
= WM_SYSTIMER
;
3423 req
->rate
= max( timeout
, SYS_TIMER_RATE
);
3424 req
->lparam
= (unsigned long)winproc
;
3425 if (!wine_server_call_err( req
))
3428 if (!ret
) ret
= TRUE
;
3434 TRACE("Added %p %x %p timeout %d\n", hwnd
, id
, winproc
, timeout
);
3439 /***********************************************************************
3440 * KillTimer (USER32.@)
3442 BOOL WINAPI
KillTimer( HWND hwnd
, UINT_PTR id
)
3446 TRACE("%p %d\n", hwnd
, id
);
3448 SERVER_START_REQ( kill_win_timer
)
3451 req
->msg
= WM_TIMER
;
3453 ret
= !wine_server_call_err( req
);
3460 /***********************************************************************
3461 * KillSystemTimer (USER32.@)
3463 BOOL WINAPI
KillSystemTimer( HWND hwnd
, UINT_PTR id
)
3467 TRACE("%p %d\n", hwnd
, id
);
3469 SERVER_START_REQ( kill_win_timer
)
3472 req
->msg
= WM_SYSTIMER
;
3474 ret
= !wine_server_call_err( req
);
3481 /**********************************************************************
3482 * GetGUIThreadInfo (USER32.@)
3484 BOOL WINAPI
GetGUIThreadInfo( DWORD id
, GUITHREADINFO
*info
)
3488 SERVER_START_REQ( get_thread_input
)
3491 if ((ret
= !wine_server_call_err( req
)))
3494 info
->hwndActive
= reply
->active
;
3495 info
->hwndFocus
= reply
->focus
;
3496 info
->hwndCapture
= reply
->capture
;
3497 info
->hwndMenuOwner
= reply
->menu_owner
;
3498 info
->hwndMoveSize
= reply
->move_size
;
3499 info
->hwndCaret
= reply
->caret
;
3500 info
->rcCaret
.left
= reply
->rect
.left
;
3501 info
->rcCaret
.top
= reply
->rect
.top
;
3502 info
->rcCaret
.right
= reply
->rect
.right
;
3503 info
->rcCaret
.bottom
= reply
->rect
.bottom
;
3504 if (reply
->menu_owner
) info
->flags
|= GUI_INMENUMODE
;
3505 if (reply
->move_size
) info
->flags
|= GUI_INMOVESIZE
;
3506 if (reply
->caret
) info
->flags
|= GUI_CARETBLINKING
;
3514 /******************************************************************
3515 * IsHungAppWindow (USER32.@)
3518 BOOL WINAPI
IsHungAppWindow( HWND hWnd
)
3521 return !SendMessageTimeoutA(hWnd
, WM_NULL
, 0, 0, SMTO_ABORTIFHUNG
, 5000, &dwResult
);