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 /* check whether a combobox expects strings or ids in CB_ADDSTRING/CB_INSERTSTRING */
277 inline static BOOL
combobox_has_strings( HWND hwnd
)
279 DWORD style
= GetWindowLongA( hwnd
, GWL_STYLE
);
280 return (!(style
& (CBS_OWNERDRAWFIXED
| CBS_OWNERDRAWVARIABLE
)) || (style
& CBS_HASSTRINGS
));
283 /* check whether a listbox expects strings or ids in LB_ADDSTRING/LB_INSERTSTRING */
284 inline static BOOL
listbox_has_strings( HWND hwnd
)
286 DWORD style
= GetWindowLongA( hwnd
, GWL_STYLE
);
287 return (!(style
& (LBS_OWNERDRAWFIXED
| LBS_OWNERDRAWVARIABLE
)) || (style
& LBS_HASSTRINGS
));
290 /* check whether message is in the range of keyboard messages */
291 inline static BOOL
is_keyboard_message( UINT message
)
293 return (message
>= WM_KEYFIRST
&& message
<= WM_KEYLAST
);
296 /* check whether message is in the range of mouse messages */
297 inline static BOOL
is_mouse_message( UINT message
)
299 return ((message
>= WM_NCMOUSEFIRST
&& message
<= WM_NCMOUSELAST
) ||
300 (message
>= WM_MOUSEFIRST
&& message
<= WM_MOUSELAST
));
303 /* check whether message matches the specified hwnd filter */
304 inline static BOOL
check_hwnd_filter( const MSG
*msg
, HWND hwnd_filter
)
306 if (!hwnd_filter
) return TRUE
;
307 return (msg
->hwnd
== hwnd_filter
|| IsChild( hwnd_filter
, msg
->hwnd
));
311 /***********************************************************************
312 * broadcast_message_callback
314 * Helper callback for broadcasting messages.
316 static BOOL CALLBACK
broadcast_message_callback( HWND hwnd
, LPARAM lparam
)
318 struct send_message_info
*info
= (struct send_message_info
*)lparam
;
319 if (!(GetWindowLongW( hwnd
, GWL_STYLE
) & (WS_POPUP
|WS_CAPTION
))) return TRUE
;
323 SendMessageTimeoutW( hwnd
, info
->msg
, info
->wparam
, info
->lparam
,
324 info
->flags
, info
->timeout
, NULL
);
327 SendMessageTimeoutA( hwnd
, info
->msg
, info
->wparam
, info
->lparam
,
328 info
->flags
, info
->timeout
, NULL
);
331 SendNotifyMessageW( hwnd
, info
->msg
, info
->wparam
, info
->lparam
);
334 SendMessageCallbackW( hwnd
, info
->msg
, info
->wparam
, info
->lparam
,
335 info
->callback
, info
->data
);
338 PostMessageW( hwnd
, info
->msg
, info
->wparam
, info
->lparam
);
341 ERR( "bad type %d\n", info
->type
);
348 /***********************************************************************
351 * Convert the wparam of an ASCII message to Unicode.
353 static WPARAM
map_wparam_AtoW( UINT message
, WPARAM wparam
)
358 case EM_SETPASSWORDCHAR
:
367 ch
[0] = (wparam
& 0xff);
368 ch
[1] = (wparam
>> 8);
369 MultiByteToWideChar(CP_ACP
, 0, ch
, 2, wch
, 2);
370 wparam
= MAKEWPARAM(wch
[0], wch
[1]);
377 ch
[0] = (wparam
>> 8);
378 ch
[1] = (wparam
& 0xff);
379 if (ch
[0]) MultiByteToWideChar(CP_ACP
, 0, ch
, 2, &wch
, 1);
380 else MultiByteToWideChar(CP_ACP
, 0, &ch
[1], 1, &wch
, 1);
381 wparam
= MAKEWPARAM( wch
, HIWORD(wparam
) );
389 /***********************************************************************
392 * Convert the wparam of a Unicode message to ASCII.
394 static WPARAM
map_wparam_WtoA( UINT message
, WPARAM wparam
)
399 case EM_SETPASSWORDCHAR
:
408 wch
[0] = LOWORD(wparam
);
409 wch
[1] = HIWORD(wparam
);
410 WideCharToMultiByte( CP_ACP
, 0, wch
, 2, (LPSTR
)ch
, 2, NULL
, NULL
);
411 wparam
= MAKEWPARAM( ch
[0] | (ch
[1] << 8), 0 );
416 WCHAR wch
= LOWORD(wparam
);
419 if (WideCharToMultiByte( CP_ACP
, 0, &wch
, 1, (LPSTR
)ch
, 2, NULL
, NULL
) == 2)
420 wparam
= MAKEWPARAM( (ch
[0] << 8) | ch
[1], HIWORD(wparam
) );
422 wparam
= MAKEWPARAM( ch
[0], HIWORD(wparam
) );
430 /***********************************************************************
433 * Pack a message for sending to another process.
434 * Return the size of the data we expect in the message reply.
435 * Set data->count to -1 if there is an error.
437 static size_t pack_message( HWND hwnd
, UINT message
, WPARAM wparam
, LPARAM lparam
,
438 struct packed_message
*data
)
446 CREATESTRUCTW
*cs
= (CREATESTRUCTW
*)lparam
;
447 push_data( data
, cs
, sizeof(*cs
) );
448 if (HIWORD(cs
->lpszName
)) push_string( data
, cs
->lpszName
);
449 if (HIWORD(cs
->lpszClass
)) push_string( data
, cs
->lpszClass
);
453 case WM_ASKCBFORMATNAME
:
454 return wparam
* sizeof(WCHAR
);
455 case WM_WININICHANGE
:
456 if (lparam
) push_string(data
, (LPWSTR
)lparam
);
459 case WM_DEVMODECHANGE
:
464 push_string( data
, (LPWSTR
)lparam
);
466 case WM_GETMINMAXINFO
:
467 push_data( data
, (MINMAXINFO
*)lparam
, sizeof(MINMAXINFO
) );
468 return sizeof(MINMAXINFO
);
470 push_data( data
, (DRAWITEMSTRUCT
*)lparam
, sizeof(DRAWITEMSTRUCT
) );
473 push_data( data
, (MEASUREITEMSTRUCT
*)lparam
, sizeof(MEASUREITEMSTRUCT
) );
474 return sizeof(MEASUREITEMSTRUCT
);
476 push_data( data
, (DELETEITEMSTRUCT
*)lparam
, sizeof(DELETEITEMSTRUCT
) );
479 push_data( data
, (COMPAREITEMSTRUCT
*)lparam
, sizeof(COMPAREITEMSTRUCT
) );
481 case WM_WINDOWPOSCHANGING
:
482 case WM_WINDOWPOSCHANGED
:
483 push_data( data
, (WINDOWPOS
*)lparam
, sizeof(WINDOWPOS
) );
484 return sizeof(WINDOWPOS
);
487 COPYDATASTRUCT
*cp
= (COPYDATASTRUCT
*)lparam
;
488 push_data( data
, cp
, sizeof(*cp
) );
489 if (cp
->lpData
) push_data( data
, cp
->lpData
, cp
->cbData
);
493 /* WM_NOTIFY cannot be sent across processes (MSDN) */
497 push_data( data
, (HELPINFO
*)lparam
, sizeof(HELPINFO
) );
499 case WM_STYLECHANGING
:
500 case WM_STYLECHANGED
:
501 push_data( data
, (STYLESTRUCT
*)lparam
, sizeof(STYLESTRUCT
) );
506 push_data( data
, (RECT
*)lparam
, sizeof(RECT
) );
511 NCCALCSIZE_PARAMS
*nc
= (NCCALCSIZE_PARAMS
*)lparam
;
512 push_data( data
, nc
, sizeof(*nc
) );
513 push_data( data
, nc
->lppos
, sizeof(*nc
->lppos
) );
514 return sizeof(*nc
) + sizeof(*nc
->lppos
);
517 if (lparam
) push_data( data
, (MSG
*)lparam
, sizeof(MSG
) );
519 case SBM_SETSCROLLINFO
:
520 push_data( data
, (SCROLLINFO
*)lparam
, sizeof(SCROLLINFO
) );
522 case SBM_GETSCROLLINFO
:
523 push_data( data
, (SCROLLINFO
*)lparam
, sizeof(SCROLLINFO
) );
524 return sizeof(SCROLLINFO
);
525 case SBM_GETSCROLLBARINFO
:
527 const SCROLLBARINFO
*info
= (const SCROLLBARINFO
*)lparam
;
528 size_t size
= min( info
->cbSize
, sizeof(SCROLLBARINFO
) );
529 push_data( data
, info
, size
);
537 if (wparam
) size
+= sizeof(DWORD
);
538 if (lparam
) size
+= sizeof(DWORD
);
543 case CB_GETDROPPEDCONTROLRECT
:
547 push_data( data
, (RECT
*)lparam
, sizeof(RECT
) );
551 WORD
*pw
= (WORD
*)lparam
;
552 push_data( data
, pw
, sizeof(*pw
) );
553 return *pw
* sizeof(WCHAR
);
557 if (wparam
) push_data( data
, (UINT
*)lparam
, sizeof(UINT
) * wparam
);
560 case CB_INSERTSTRING
:
562 case CB_FINDSTRINGEXACT
:
563 case CB_SELECTSTRING
:
564 if (combobox_has_strings( hwnd
)) push_string( data
, (LPWSTR
)lparam
);
567 if (!combobox_has_strings( hwnd
)) return sizeof(ULONG_PTR
);
568 return (SendMessageW( hwnd
, CB_GETLBTEXTLEN
, wparam
, 0 ) + 1) * sizeof(WCHAR
);
570 case LB_INSERTSTRING
:
572 case LB_FINDSTRINGEXACT
:
573 case LB_SELECTSTRING
:
574 if (listbox_has_strings( hwnd
)) push_string( data
, (LPWSTR
)lparam
);
577 if (!listbox_has_strings( hwnd
)) return sizeof(ULONG_PTR
);
578 return (SendMessageW( hwnd
, LB_GETTEXTLEN
, wparam
, 0 ) + 1) * sizeof(WCHAR
);
580 return wparam
* sizeof(UINT
);
582 push_data( data
, (MDINEXTMENU
*)lparam
, sizeof(MDINEXTMENU
) );
583 return sizeof(MDINEXTMENU
);
586 push_data( data
, (RECT
*)lparam
, sizeof(RECT
) );
590 MDICREATESTRUCTW
*cs
= (MDICREATESTRUCTW
*)lparam
;
591 push_data( data
, cs
, sizeof(*cs
) );
592 if (HIWORD(cs
->szTitle
)) push_string( data
, cs
->szTitle
);
593 if (HIWORD(cs
->szClass
)) push_string( data
, cs
->szClass
);
596 case WM_MDIGETACTIVE
:
597 if (lparam
) return sizeof(BOOL
);
599 case WM_DEVICECHANGE
:
601 DEV_BROADCAST_HDR
*header
= (DEV_BROADCAST_HDR
*)lparam
;
602 push_data( data
, header
, header
->dbch_size
);
605 case WM_WINE_SETWINDOWPOS
:
606 push_data( data
, (WINDOWPOS
*)lparam
, sizeof(WINDOWPOS
) );
608 case WM_WINE_KEYBOARD_LL_HOOK
:
610 struct hook_extra_info
*h_extra
= (struct hook_extra_info
*)lparam
;
611 push_data( data
, h_extra
, sizeof(*h_extra
) );
612 push_data( data
, (LPVOID
)h_extra
->lparam
, sizeof(KBDLLHOOKSTRUCT
) );
615 case WM_WINE_MOUSE_LL_HOOK
:
617 struct hook_extra_info
*h_extra
= (struct hook_extra_info
*)lparam
;
618 push_data( data
, h_extra
, sizeof(*h_extra
) );
619 push_data( data
, (LPVOID
)h_extra
->lparam
, sizeof(MSLLHOOKSTRUCT
) );
623 if (wparam
<= 1) return 0;
624 FIXME( "WM_NCPAINT hdc packing not supported yet\n" );
628 if (!wparam
) return 0;
631 /* these contain an HFONT */
634 /* these contain an HDC */
636 case WM_ICONERASEBKGND
:
637 case WM_CTLCOLORMSGBOX
:
638 case WM_CTLCOLOREDIT
:
639 case WM_CTLCOLORLISTBOX
:
642 case WM_CTLCOLORSCROLLBAR
:
643 case WM_CTLCOLORSTATIC
:
646 /* these contain an HGLOBAL */
647 case WM_PAINTCLIPBOARD
:
648 case WM_SIZECLIPBOARD
:
649 /* these contain HICON */
652 case WM_QUERYDRAGICON
:
653 case WM_QUERYPARKICON
:
654 /* these contain pointers */
656 case WM_QUERYDROPOBJECT
:
660 FIXME( "msg %x (%s) not supported yet\n", message
, SPY_GetMsgName(message
, hwnd
) );
668 /***********************************************************************
671 * Unpack a message received from another process.
673 static BOOL
unpack_message( HWND hwnd
, UINT message
, WPARAM
*wparam
, LPARAM
*lparam
,
674 void **buffer
, size_t size
)
683 CREATESTRUCTW
*cs
= *buffer
;
684 WCHAR
*str
= (WCHAR
*)(cs
+ 1);
685 if (size
< sizeof(*cs
)) return FALSE
;
687 if (HIWORD(cs
->lpszName
))
689 if (!check_string( str
, size
)) return FALSE
;
691 size
-= (strlenW(str
) + 1) * sizeof(WCHAR
);
692 str
+= strlenW(str
) + 1;
694 if (HIWORD(cs
->lpszClass
))
696 if (!check_string( str
, size
)) return FALSE
;
702 case WM_ASKCBFORMATNAME
:
703 if (!get_buffer_space( buffer
, (*wparam
* sizeof(WCHAR
)) )) return FALSE
;
705 case WM_WININICHANGE
:
706 if (!*lparam
) return TRUE
;
709 case WM_DEVMODECHANGE
:
714 if (!check_string( *buffer
, size
)) return FALSE
;
716 case WM_GETMINMAXINFO
:
717 minsize
= sizeof(MINMAXINFO
);
720 minsize
= sizeof(DRAWITEMSTRUCT
);
723 minsize
= sizeof(MEASUREITEMSTRUCT
);
726 minsize
= sizeof(DELETEITEMSTRUCT
);
729 minsize
= sizeof(COMPAREITEMSTRUCT
);
731 case WM_WINDOWPOSCHANGING
:
732 case WM_WINDOWPOSCHANGED
:
733 case WM_WINE_SETWINDOWPOS
:
734 minsize
= sizeof(WINDOWPOS
);
738 COPYDATASTRUCT
*cp
= *buffer
;
739 if (size
< sizeof(*cp
)) return FALSE
;
742 minsize
= sizeof(*cp
) + cp
->cbData
;
748 /* WM_NOTIFY cannot be sent across processes (MSDN) */
751 minsize
= sizeof(HELPINFO
);
753 case WM_STYLECHANGING
:
754 case WM_STYLECHANGED
:
755 minsize
= sizeof(STYLESTRUCT
);
758 if (!*wparam
) minsize
= sizeof(RECT
);
761 NCCALCSIZE_PARAMS
*nc
= *buffer
;
762 if (size
< sizeof(*nc
) + sizeof(*nc
->lppos
)) return FALSE
;
763 nc
->lppos
= (WINDOWPOS
*)(nc
+ 1);
767 if (!*lparam
) return TRUE
;
768 minsize
= sizeof(MSG
);
770 case SBM_SETSCROLLINFO
:
771 minsize
= sizeof(SCROLLINFO
);
773 case SBM_GETSCROLLINFO
:
774 if (!get_buffer_space( buffer
, sizeof(SCROLLINFO
))) return FALSE
;
776 case SBM_GETSCROLLBARINFO
:
777 if (!get_buffer_space( buffer
, sizeof(SCROLLBARINFO
))) return FALSE
;
782 if (*wparam
|| *lparam
)
784 if (!get_buffer_space( buffer
, 2*sizeof(DWORD
) )) return FALSE
;
785 if (*wparam
) *wparam
= (WPARAM
)*buffer
;
786 if (*lparam
) *lparam
= (LPARAM
)((DWORD
*)*buffer
+ 1);
791 case CB_GETDROPPEDCONTROLRECT
:
792 if (!get_buffer_space( buffer
, sizeof(RECT
) )) return FALSE
;
796 minsize
= sizeof(RECT
);
801 if (size
< sizeof(WORD
)) return FALSE
;
802 len
= *(WORD
*)*buffer
;
803 if (!get_buffer_space( buffer
, (len
+ 1) * sizeof(WCHAR
) )) return FALSE
;
804 *lparam
= (LPARAM
)*buffer
+ sizeof(WORD
); /* don't erase WORD at start of buffer */
809 if (!*wparam
) return TRUE
;
810 minsize
= *wparam
* sizeof(UINT
);
813 case CB_INSERTSTRING
:
815 case CB_FINDSTRINGEXACT
:
816 case CB_SELECTSTRING
:
818 case LB_INSERTSTRING
:
820 case LB_FINDSTRINGEXACT
:
821 case LB_SELECTSTRING
:
822 if (!*buffer
) return TRUE
;
823 if (!check_string( *buffer
, size
)) return FALSE
;
827 size
= sizeof(ULONG_PTR
);
828 if (combobox_has_strings( hwnd
))
829 size
= (SendMessageW( hwnd
, CB_GETLBTEXTLEN
, *wparam
, 0 ) + 1) * sizeof(WCHAR
);
830 if (!get_buffer_space( buffer
, size
)) return FALSE
;
835 size
= sizeof(ULONG_PTR
);
836 if (listbox_has_strings( hwnd
))
837 size
= (SendMessageW( hwnd
, LB_GETTEXTLEN
, *wparam
, 0 ) + 1) * sizeof(WCHAR
);
838 if (!get_buffer_space( buffer
, size
)) return FALSE
;
842 if (!get_buffer_space( buffer
, *wparam
* sizeof(UINT
) )) return FALSE
;
845 minsize
= sizeof(MDINEXTMENU
);
846 if (!get_buffer_space( buffer
, sizeof(MDINEXTMENU
) )) return FALSE
;
850 minsize
= sizeof(RECT
);
851 if (!get_buffer_space( buffer
, sizeof(RECT
) )) return FALSE
;
855 MDICREATESTRUCTW
*cs
= *buffer
;
856 WCHAR
*str
= (WCHAR
*)(cs
+ 1);
857 if (size
< sizeof(*cs
)) return FALSE
;
859 if (HIWORD(cs
->szTitle
))
861 if (!check_string( str
, size
)) return FALSE
;
863 size
-= (strlenW(str
) + 1) * sizeof(WCHAR
);
864 str
+= strlenW(str
) + 1;
866 if (HIWORD(cs
->szClass
))
868 if (!check_string( str
, size
)) return FALSE
;
873 case WM_MDIGETACTIVE
:
874 if (!*lparam
) return TRUE
;
875 if (!get_buffer_space( buffer
, sizeof(BOOL
) )) return FALSE
;
877 case WM_DEVICECHANGE
:
878 minsize
= sizeof(DEV_BROADCAST_HDR
);
880 case WM_WINE_KEYBOARD_LL_HOOK
:
881 case WM_WINE_MOUSE_LL_HOOK
:
883 struct hook_extra_info
*h_extra
= (struct hook_extra_info
*)*buffer
;
885 minsize
= sizeof(struct hook_extra_info
) +
886 (message
== WM_WINE_KEYBOARD_LL_HOOK
? sizeof(KBDLLHOOKSTRUCT
)
887 : sizeof(MSLLHOOKSTRUCT
));
888 if (size
< minsize
) return FALSE
;
889 h_extra
->lparam
= (LPARAM
)(h_extra
+ 1);
893 if (*wparam
<= 1) return TRUE
;
894 FIXME( "WM_NCPAINT hdc unpacking not supported\n" );
897 if (!*wparam
) return TRUE
;
900 /* these contain an HFONT */
903 /* these contain an HDC */
905 case WM_ICONERASEBKGND
:
906 case WM_CTLCOLORMSGBOX
:
907 case WM_CTLCOLOREDIT
:
908 case WM_CTLCOLORLISTBOX
:
911 case WM_CTLCOLORSCROLLBAR
:
912 case WM_CTLCOLORSTATIC
:
915 /* these contain an HGLOBAL */
916 case WM_PAINTCLIPBOARD
:
917 case WM_SIZECLIPBOARD
:
918 /* these contain HICON */
921 case WM_QUERYDRAGICON
:
922 case WM_QUERYPARKICON
:
923 /* these contain pointers */
925 case WM_QUERYDROPOBJECT
:
929 FIXME( "msg %x (%s) not supported yet\n", message
, SPY_GetMsgName(message
, hwnd
) );
933 return TRUE
; /* message doesn't need any unpacking */
936 /* default exit for most messages: check minsize and store buffer in lparam */
937 if (size
< minsize
) return FALSE
;
938 *lparam
= (LPARAM
)*buffer
;
943 /***********************************************************************
946 * Pack a reply to a message for sending to another process.
948 static void pack_reply( HWND hwnd
, UINT message
, WPARAM wparam
, LPARAM lparam
,
949 LRESULT res
, struct packed_message
*data
)
956 push_data( data
, (CREATESTRUCTW
*)lparam
, sizeof(CREATESTRUCTW
) );
961 push_data( data
, (WCHAR
*)lparam
, (res
+ 1) * sizeof(WCHAR
) );
963 case WM_GETMINMAXINFO
:
964 push_data( data
, (MINMAXINFO
*)lparam
, sizeof(MINMAXINFO
) );
967 push_data( data
, (MEASUREITEMSTRUCT
*)lparam
, sizeof(MEASUREITEMSTRUCT
) );
969 case WM_WINDOWPOSCHANGING
:
970 case WM_WINDOWPOSCHANGED
:
971 push_data( data
, (WINDOWPOS
*)lparam
, sizeof(WINDOWPOS
) );
974 if (lparam
) push_data( data
, (MSG
*)lparam
, sizeof(MSG
) );
976 case SBM_GETSCROLLINFO
:
977 push_data( data
, (SCROLLINFO
*)lparam
, sizeof(SCROLLINFO
) );
981 case CB_GETDROPPEDCONTROLRECT
:
984 push_data( data
, (RECT
*)lparam
, sizeof(RECT
) );
988 WORD
*ptr
= (WORD
*)lparam
;
989 push_data( data
, ptr
, ptr
[-1] * sizeof(WCHAR
) );
993 push_data( data
, (UINT
*)lparam
, wparam
* sizeof(UINT
) );
995 case WM_MDIGETACTIVE
:
996 if (lparam
) push_data( data
, (BOOL
*)lparam
, sizeof(BOOL
) );
1000 push_data( data
, (RECT
*)lparam
, sizeof(RECT
) );
1003 NCCALCSIZE_PARAMS
*nc
= (NCCALCSIZE_PARAMS
*)lparam
;
1004 push_data( data
, nc
, sizeof(*nc
) );
1005 push_data( data
, nc
->lppos
, sizeof(*nc
->lppos
) );
1011 if (wparam
) push_data( data
, (DWORD
*)wparam
, sizeof(DWORD
) );
1012 if (lparam
) push_data( data
, (DWORD
*)lparam
, sizeof(DWORD
) );
1015 push_data( data
, (MDINEXTMENU
*)lparam
, sizeof(MDINEXTMENU
) );
1018 push_data( data
, (MDICREATESTRUCTW
*)lparam
, sizeof(MDICREATESTRUCTW
) );
1020 case WM_ASKCBFORMATNAME
:
1021 push_data( data
, (WCHAR
*)lparam
, (strlenW((WCHAR
*)lparam
) + 1) * sizeof(WCHAR
) );
1027 /***********************************************************************
1030 * Unpack a message reply received from another process.
1032 static void unpack_reply( HWND hwnd
, UINT message
, WPARAM wparam
, LPARAM lparam
,
1033 void *buffer
, size_t size
)
1040 CREATESTRUCTW
*cs
= (CREATESTRUCTW
*)lparam
;
1041 LPCWSTR name
= cs
->lpszName
, class = cs
->lpszClass
;
1042 memcpy( cs
, buffer
, min( sizeof(*cs
), size
));
1043 cs
->lpszName
= name
; /* restore the original pointers */
1044 cs
->lpszClass
= class;
1048 case WM_ASKCBFORMATNAME
:
1049 memcpy( (WCHAR
*)lparam
, buffer
, min( wparam
*sizeof(WCHAR
), size
));
1051 case WM_GETMINMAXINFO
:
1052 memcpy( (MINMAXINFO
*)lparam
, buffer
, min( sizeof(MINMAXINFO
), size
));
1054 case WM_MEASUREITEM
:
1055 memcpy( (MEASUREITEMSTRUCT
*)lparam
, buffer
, min( sizeof(MEASUREITEMSTRUCT
), size
));
1057 case WM_WINDOWPOSCHANGING
:
1058 case WM_WINDOWPOSCHANGED
:
1059 memcpy( (WINDOWPOS
*)lparam
, buffer
, min( sizeof(WINDOWPOS
), size
));
1062 if (lparam
) memcpy( (MSG
*)lparam
, buffer
, min( sizeof(MSG
), size
));
1064 case SBM_GETSCROLLINFO
:
1065 memcpy( (SCROLLINFO
*)lparam
, buffer
, min( sizeof(SCROLLINFO
), size
));
1067 case SBM_GETSCROLLBARINFO
:
1068 memcpy( (SCROLLBARINFO
*)lparam
, buffer
, min( sizeof(SCROLLBARINFO
), size
));
1071 case CB_GETDROPPEDCONTROLRECT
:
1072 case LB_GETITEMRECT
:
1075 memcpy( (RECT
*)lparam
, buffer
, min( sizeof(RECT
), size
));
1078 size
= min( size
, (size_t)*(WORD
*)lparam
);
1079 memcpy( (WCHAR
*)lparam
, buffer
, size
);
1081 case LB_GETSELITEMS
:
1082 memcpy( (UINT
*)lparam
, buffer
, min( wparam
*sizeof(UINT
), size
));
1086 memcpy( (WCHAR
*)lparam
, buffer
, size
);
1089 memcpy( (MDINEXTMENU
*)lparam
, buffer
, min( sizeof(MDINEXTMENU
), size
));
1091 case WM_MDIGETACTIVE
:
1092 if (lparam
) memcpy( (BOOL
*)lparam
, buffer
, min( sizeof(BOOL
), size
));
1096 memcpy( (RECT
*)lparam
, buffer
, min( sizeof(RECT
), size
));
1099 NCCALCSIZE_PARAMS
*nc
= (NCCALCSIZE_PARAMS
*)lparam
;
1100 WINDOWPOS
*wp
= nc
->lppos
;
1101 memcpy( nc
, buffer
, min( sizeof(*nc
), size
));
1102 if (size
> sizeof(*nc
))
1104 size
-= sizeof(*nc
);
1105 memcpy( wp
, (NCCALCSIZE_PARAMS
*)buffer
+ 1, min( sizeof(*wp
), size
));
1107 nc
->lppos
= wp
; /* restore the original pointer */
1115 memcpy( (DWORD
*)wparam
, buffer
, min( sizeof(DWORD
), size
));
1116 if (size
<= sizeof(DWORD
)) break;
1117 size
-= sizeof(DWORD
);
1118 buffer
= (DWORD
*)buffer
+ 1;
1120 if (lparam
) memcpy( (DWORD
*)lparam
, buffer
, min( sizeof(DWORD
), size
));
1124 MDICREATESTRUCTW
*cs
= (MDICREATESTRUCTW
*)lparam
;
1125 LPCWSTR title
= cs
->szTitle
, class = cs
->szClass
;
1126 memcpy( cs
, buffer
, min( sizeof(*cs
), size
));
1127 cs
->szTitle
= title
; /* restore the original pointers */
1128 cs
->szClass
= class;
1132 ERR( "should not happen: unexpected message %x\n", message
);
1138 /***********************************************************************
1141 * Send a reply to a sent message.
1143 static void reply_message( struct received_message_info
*info
, LRESULT result
, BOOL remove
)
1145 struct packed_message data
;
1146 int i
, replied
= info
->flags
& ISMEX_REPLIED
;
1148 if (info
->flags
& ISMEX_NOTIFY
) return; /* notify messages don't get replies */
1149 if (!remove
&& replied
) return; /* replied already */
1152 info
->flags
|= ISMEX_REPLIED
;
1154 if (info
->type
== MSG_OTHER_PROCESS
&& !replied
)
1156 pack_reply( info
->msg
.hwnd
, info
->msg
.message
, info
->msg
.wParam
,
1157 info
->msg
.lParam
, result
, &data
);
1160 SERVER_START_REQ( reply_message
)
1162 req
->result
= result
;
1163 req
->remove
= remove
;
1164 for (i
= 0; i
< data
.count
; i
++) wine_server_add_data( req
, data
.data
[i
], data
.size
[i
] );
1165 wine_server_call( req
);
1171 /***********************************************************************
1172 * handle_internal_message
1174 * Handle an internal Wine message instead of calling the window proc.
1176 static LRESULT
handle_internal_message( HWND hwnd
, UINT msg
, WPARAM wparam
, LPARAM lparam
)
1180 case WM_WINE_DESTROYWINDOW
:
1181 return WIN_DestroyWindow( hwnd
);
1182 case WM_WINE_SETWINDOWPOS
:
1183 if (hwnd
== GetDesktopWindow()) return 0;
1184 return USER_SetWindowPos( (WINDOWPOS
*)lparam
);
1185 case WM_WINE_SHOWWINDOW
:
1186 if (hwnd
== GetDesktopWindow()) return 0;
1187 return ShowWindow( hwnd
, wparam
);
1188 case WM_WINE_SETPARENT
:
1189 if (hwnd
== GetDesktopWindow()) return 0;
1190 return (LRESULT
)SetParent( hwnd
, (HWND
)wparam
);
1191 case WM_WINE_SETWINDOWLONG
:
1192 return WIN_SetWindowLong( hwnd
, (short)LOWORD(wparam
), HIWORD(wparam
), lparam
, TRUE
);
1193 case WM_WINE_ENABLEWINDOW
:
1194 if (hwnd
== GetDesktopWindow()) return 0;
1195 return EnableWindow( hwnd
, wparam
);
1196 case WM_WINE_SETACTIVEWINDOW
:
1197 if (hwnd
== GetDesktopWindow()) return 0;
1198 return (LRESULT
)SetActiveWindow( (HWND
)wparam
);
1199 case WM_WINE_KEYBOARD_LL_HOOK
:
1200 case WM_WINE_MOUSE_LL_HOOK
:
1202 struct hook_extra_info
*h_extra
= (struct hook_extra_info
*)lparam
;
1204 return call_current_hook( h_extra
->handle
, HC_ACTION
, wparam
, h_extra
->lparam
);
1207 if (msg
>= WM_WINE_FIRST_DRIVER_MSG
&& msg
<= WM_WINE_LAST_DRIVER_MSG
)
1208 return USER_Driver
->pWindowMessage( hwnd
, msg
, wparam
, lparam
);
1209 FIXME( "unknown internal message %x\n", msg
);
1214 /* since the WM_DDE_ACK response to a WM_DDE_EXECUTE message should contain the handle
1215 * to the memory handle, we keep track (in the server side) of all pairs of handle
1216 * used (the client passes its value and the content of the memory handle), and
1217 * the server stored both values (the client, and the local one, created after the
1218 * content). When a ACK message is generated, the list of pair is searched for a
1219 * matching pair, so that the client memory handle can be returned.
1222 HGLOBAL client_hMem
;
1223 HGLOBAL server_hMem
;
1226 static struct DDE_pair
* dde_pairs
;
1227 static int dde_num_alloc
;
1228 static int dde_num_used
;
1230 static CRITICAL_SECTION dde_crst
;
1231 static CRITICAL_SECTION_DEBUG critsect_debug
=
1234 { &critsect_debug
.ProcessLocksList
, &critsect_debug
.ProcessLocksList
},
1235 0, 0, { (DWORD_PTR
)(__FILE__
": dde_crst") }
1237 static CRITICAL_SECTION dde_crst
= { &critsect_debug
, -1, 0, 0, 0, 0 };
1239 static BOOL
dde_add_pair(HGLOBAL chm
, HGLOBAL shm
)
1244 EnterCriticalSection(&dde_crst
);
1246 /* now remember the pair of hMem on both sides */
1247 if (dde_num_used
== dde_num_alloc
)
1249 struct DDE_pair
* tmp
;
1251 tmp
= HeapReAlloc( GetProcessHeap(), 0, dde_pairs
,
1252 (dde_num_alloc
+ GROWBY
) * sizeof(struct DDE_pair
));
1254 tmp
= HeapAlloc( GetProcessHeap(), 0,
1255 (dde_num_alloc
+ GROWBY
) * sizeof(struct DDE_pair
));
1259 LeaveCriticalSection(&dde_crst
);
1263 /* zero out newly allocated part */
1264 memset(&dde_pairs
[dde_num_alloc
], 0, GROWBY
* sizeof(struct DDE_pair
));
1265 dde_num_alloc
+= GROWBY
;
1268 for (i
= 0; i
< dde_num_alloc
; i
++)
1270 if (dde_pairs
[i
].server_hMem
== 0)
1272 dde_pairs
[i
].client_hMem
= chm
;
1273 dde_pairs
[i
].server_hMem
= shm
;
1278 LeaveCriticalSection(&dde_crst
);
1282 static HGLOBAL
dde_get_pair(HGLOBAL shm
)
1287 EnterCriticalSection(&dde_crst
);
1288 for (i
= 0; i
< dde_num_alloc
; i
++)
1290 if (dde_pairs
[i
].server_hMem
== shm
)
1292 /* free this pair */
1293 dde_pairs
[i
].server_hMem
= 0;
1295 ret
= dde_pairs
[i
].client_hMem
;
1299 LeaveCriticalSection(&dde_crst
);
1303 /***********************************************************************
1306 * Post a DDE message
1308 static BOOL
post_dde_message( struct packed_message
*data
, const struct send_message_info
*info
)
1312 UINT_PTR uiLo
, uiHi
;
1314 HGLOBAL hunlock
= 0;
1318 if (!UnpackDDElParam( info
->msg
, info
->lparam
, &uiLo
, &uiHi
))
1324 /* DDE messages which don't require packing are:
1333 /* uiHi should contain a hMem from WM_DDE_EXECUTE */
1334 HGLOBAL h
= dde_get_pair( (HANDLE
)uiHi
);
1337 /* send back the value of h on the other side */
1338 push_data( data
, &h
, sizeof(HGLOBAL
) );
1340 TRACE( "send dde-ack %x %08x => %p\n", uiLo
, uiHi
, h
);
1345 /* uiHi should contain either an atom or 0 */
1346 TRACE( "send dde-ack %x atom=%x\n", uiLo
, uiHi
);
1347 lp
= MAKELONG( uiLo
, uiHi
);
1356 size
= GlobalSize( (HGLOBAL
)uiLo
) ;
1357 if ((info
->msg
== WM_DDE_ADVISE
&& size
< sizeof(DDEADVISE
)) ||
1358 (info
->msg
== WM_DDE_DATA
&& size
< sizeof(DDEDATA
)) ||
1359 (info
->msg
== WM_DDE_POKE
&& size
< sizeof(DDEPOKE
))
1363 else if (info
->msg
!= WM_DDE_DATA
) return FALSE
;
1368 if ((ptr
= GlobalLock( (HGLOBAL
)uiLo
) ))
1370 DDEDATA
*dde_data
= (DDEDATA
*)ptr
;
1371 TRACE("unused %d, fResponse %d, fRelease %d, fDeferUpd %d, fAckReq %d, cfFormat %d\n",
1372 dde_data
->unused
, dde_data
->fResponse
, dde_data
->fRelease
,
1373 dde_data
->reserved
, dde_data
->fAckReq
, dde_data
->cfFormat
);
1374 push_data( data
, ptr
, size
);
1375 hunlock
= (HGLOBAL
)uiLo
;
1378 TRACE( "send ddepack %u %x\n", size
, uiHi
);
1380 case WM_DDE_EXECUTE
:
1383 if ((ptr
= GlobalLock( (HGLOBAL
)info
->lparam
) ))
1385 push_data(data
, ptr
, GlobalSize( (HGLOBAL
)info
->lparam
));
1386 /* so that the other side can send it back on ACK */
1388 hunlock
= (HGLOBAL
)info
->lparam
;
1393 SERVER_START_REQ( send_message
)
1395 req
->id
= info
->dest_tid
;
1396 req
->type
= info
->type
;
1398 req
->win
= info
->hwnd
;
1399 req
->msg
= info
->msg
;
1400 req
->wparam
= info
->wparam
;
1403 for (i
= 0; i
< data
->count
; i
++)
1404 wine_server_add_data( req
, data
->data
[i
], data
->size
[i
] );
1405 if ((res
= wine_server_call( req
)))
1407 if (res
== STATUS_INVALID_PARAMETER
)
1408 /* FIXME: find a STATUS_ value for this one */
1409 SetLastError( ERROR_INVALID_THREAD_ID
);
1411 SetLastError( RtlNtStatusToDosError(res
) );
1414 FreeDDElParam(info
->msg
, info
->lparam
);
1417 if (hunlock
) GlobalUnlock(hunlock
);
1422 /***********************************************************************
1423 * unpack_dde_message
1425 * Unpack a posted DDE message received from another process.
1427 static BOOL
unpack_dde_message( HWND hwnd
, UINT message
, WPARAM
*wparam
, LPARAM
*lparam
,
1428 void **buffer
, size_t size
)
1430 UINT_PTR uiLo
, uiHi
;
1439 /* hMem is being passed */
1440 if (size
!= sizeof(HGLOBAL
)) return FALSE
;
1441 if (!buffer
|| !*buffer
) return FALSE
;
1443 memcpy( &hMem
, *buffer
, size
);
1444 uiHi
= (UINT_PTR
)hMem
;
1445 TRACE("recv dde-ack %x mem=%x[%lx]\n", uiLo
, uiHi
, GlobalSize( hMem
));
1449 uiLo
= LOWORD( *lparam
);
1450 uiHi
= HIWORD( *lparam
);
1451 TRACE("recv dde-ack %x atom=%x\n", uiLo
, uiHi
);
1453 *lparam
= PackDDElParam( WM_DDE_ACK
, uiLo
, uiHi
);
1458 if ((!buffer
|| !*buffer
) && message
!= WM_DDE_DATA
) return FALSE
;
1462 if (!(hMem
= GlobalAlloc( GMEM_MOVEABLE
|GMEM_DDESHARE
, size
)))
1464 if ((ptr
= GlobalLock( hMem
)))
1466 memcpy( ptr
, *buffer
, size
);
1467 GlobalUnlock( hMem
);
1475 uiLo
= (UINT_PTR
)hMem
;
1477 *lparam
= PackDDElParam( message
, uiLo
, uiHi
);
1479 case WM_DDE_EXECUTE
:
1482 if (!buffer
|| !*buffer
) return FALSE
;
1483 if (!(hMem
= GlobalAlloc( GMEM_MOVEABLE
|GMEM_DDESHARE
, size
))) return FALSE
;
1484 if ((ptr
= GlobalLock( hMem
)))
1486 memcpy( ptr
, *buffer
, size
);
1487 GlobalUnlock( hMem
);
1488 TRACE( "exec: pairing c=%08lx s=%08x\n", *lparam
, (DWORD
)hMem
);
1489 if (!dde_add_pair( (HGLOBAL
)*lparam
, hMem
))
1500 } else return FALSE
;
1501 *lparam
= (LPARAM
)hMem
;
1507 /***********************************************************************
1510 * Call a window procedure and the corresponding hooks.
1512 static LRESULT
call_window_proc( HWND hwnd
, UINT msg
, WPARAM wparam
, LPARAM lparam
,
1513 BOOL unicode
, BOOL same_thread
)
1515 struct user_thread_info
*thread_info
= get_user_thread_info();
1519 CWPRETSTRUCT cwpret
;
1521 if (thread_info
->recursion_count
> MAX_SENDMSG_RECURSION
) return 0;
1522 thread_info
->recursion_count
++;
1524 if (msg
& 0x80000000)
1526 result
= handle_internal_message( hwnd
, msg
, wparam
, lparam
);
1530 /* first the WH_CALLWNDPROC hook */
1531 hwnd
= WIN_GetFullHandle( hwnd
);
1532 cwp
.lParam
= lparam
;
1533 cwp
.wParam
= wparam
;
1536 HOOK_CallHooks( WH_CALLWNDPROC
, HC_ACTION
, same_thread
, (LPARAM
)&cwp
, unicode
);
1538 /* now call the window procedure */
1541 if (!(winproc
= (WNDPROC
)GetWindowLongPtrW( hwnd
, GWLP_WNDPROC
))) goto done
;
1542 result
= CallWindowProcW( winproc
, hwnd
, msg
, wparam
, lparam
);
1546 if (!(winproc
= (WNDPROC
)GetWindowLongPtrA( hwnd
, GWLP_WNDPROC
))) goto done
;
1547 result
= CallWindowProcA( winproc
, hwnd
, msg
, wparam
, lparam
);
1550 /* and finally the WH_CALLWNDPROCRET hook */
1551 cwpret
.lResult
= result
;
1552 cwpret
.lParam
= lparam
;
1553 cwpret
.wParam
= wparam
;
1554 cwpret
.message
= msg
;
1556 HOOK_CallHooks( WH_CALLWNDPROCRET
, HC_ACTION
, same_thread
, (LPARAM
)&cwpret
, unicode
);
1558 thread_info
->recursion_count
--;
1563 /***********************************************************************
1564 * send_parent_notify
1566 * Send a WM_PARENTNOTIFY to all ancestors of the given window, unless
1567 * the window has the WS_EX_NOPARENTNOTIFY style.
1569 static void send_parent_notify( HWND hwnd
, WORD event
, WORD idChild
, POINT pt
)
1571 /* pt has to be in the client coordinates of the parent window */
1572 MapWindowPoints( 0, hwnd
, &pt
, 1 );
1577 if (!(GetWindowLongW( hwnd
, GWL_STYLE
) & WS_CHILD
)) break;
1578 if (GetWindowLongW( hwnd
, GWL_EXSTYLE
) & WS_EX_NOPARENTNOTIFY
) break;
1579 if (!(parent
= GetParent(hwnd
))) break;
1580 if (parent
== GetDesktopWindow()) break;
1581 MapWindowPoints( hwnd
, parent
, &pt
, 1 );
1583 SendMessageW( hwnd
, WM_PARENTNOTIFY
,
1584 MAKEWPARAM( event
, idChild
), MAKELPARAM( pt
.x
, pt
.y
) );
1589 /***********************************************************************
1590 * accept_hardware_message
1592 * Tell the server we have passed the message to the app
1593 * (even though we may end up dropping it later on)
1595 static void accept_hardware_message( UINT hw_id
, BOOL remove
, HWND new_hwnd
)
1597 SERVER_START_REQ( accept_hardware_message
)
1600 req
->remove
= remove
;
1601 req
->new_win
= new_hwnd
;
1602 if (wine_server_call( req
))
1603 FIXME("Failed to reply to MSG_HARDWARE message. Message may not be removed from queue.\n");
1609 /***********************************************************************
1610 * process_keyboard_message
1612 * returns TRUE if the contents of 'msg' should be passed to the application
1614 static BOOL
process_keyboard_message( MSG
*msg
, UINT hw_id
, HWND hwnd_filter
,
1615 UINT first
, UINT last
, BOOL remove
)
1619 /* FIXME: is this really the right place for this hook? */
1620 event
.message
= msg
->message
;
1621 event
.hwnd
= msg
->hwnd
;
1622 event
.time
= msg
->time
;
1623 event
.paramL
= (msg
->wParam
& 0xFF) | (HIWORD(msg
->lParam
) << 8);
1624 event
.paramH
= msg
->lParam
& 0x7FFF;
1625 if (HIWORD(msg
->lParam
) & 0x0100) event
.paramH
|= 0x8000; /* special_key - bit */
1626 HOOK_CallHooks( WH_JOURNALRECORD
, HC_ACTION
, 0, (LPARAM
)&event
, TRUE
);
1628 /* check message filters */
1629 if (msg
->message
< first
|| msg
->message
> last
) return FALSE
;
1630 if (!check_hwnd_filter( msg
, hwnd_filter
)) return FALSE
;
1634 if((msg
->message
== WM_KEYDOWN
) &&
1635 (msg
->hwnd
!= GetDesktopWindow()))
1637 /* Handle F1 key by sending out WM_HELP message */
1638 if(msg
->wParam
== VK_F1
&&
1639 !MENU_IsMenuActive())
1642 hi
.cbSize
= sizeof(HELPINFO
);
1643 hi
.iContextType
= HELPINFO_WINDOW
;
1644 hi
.iCtrlId
= GetWindowLongPtrA( msg
->hwnd
, GWLP_ID
);
1645 hi
.hItemHandle
= msg
->hwnd
;
1646 hi
.dwContextId
= GetWindowContextHelpId( msg
->hwnd
);
1647 hi
.MousePos
= msg
->pt
;
1648 SendMessageW( msg
->hwnd
, WM_HELP
, 0, (LPARAM
)&hi
);
1650 else if(msg
->wParam
>= VK_BROWSER_BACK
&&
1651 msg
->wParam
<= VK_LAUNCH_APP2
)
1653 /* FIXME: Process keystate */
1654 SendMessageW(msg
->hwnd
, WM_APPCOMMAND
, (WPARAM
)msg
->hwnd
, MAKELPARAM(0, (FAPPCOMMAND_KEY
| (msg
->wParam
- VK_BROWSER_BACK
+ 1))));
1657 else if (msg
->message
== WM_KEYUP
)
1659 /* Handle VK_APPS key by posting a WM_CONTEXTMENU message */
1660 if (msg
->wParam
== VK_APPS
&& !MENU_IsMenuActive())
1661 PostMessageW(msg
->hwnd
, WM_CONTEXTMENU
, (WPARAM
)msg
->hwnd
, (LPARAM
)-1);
1665 if (HOOK_CallHooks( WH_KEYBOARD
, remove
? HC_ACTION
: HC_NOREMOVE
,
1666 LOWORD(msg
->wParam
), msg
->lParam
, TRUE
))
1668 /* skip this message */
1669 HOOK_CallHooks( WH_CBT
, HCBT_KEYSKIPPED
, LOWORD(msg
->wParam
), msg
->lParam
, TRUE
);
1670 accept_hardware_message( hw_id
, TRUE
, 0 );
1673 accept_hardware_message( hw_id
, remove
, 0 );
1678 /***********************************************************************
1679 * process_mouse_message
1681 * returns TRUE if the contents of 'msg' should be passed to the application
1683 static BOOL
process_mouse_message( MSG
*msg
, UINT hw_id
, ULONG_PTR extra_info
, HWND hwnd_filter
,
1684 UINT first
, UINT last
, BOOL remove
)
1693 MOUSEHOOKSTRUCT hook
;
1696 /* find the window to dispatch this mouse message to */
1698 GetGUIThreadInfo( GetCurrentThreadId(), &info
);
1699 if (info
.hwndCapture
)
1702 msg
->hwnd
= info
.hwndCapture
;
1706 msg
->hwnd
= WINPOS_WindowFromPoint( msg
->hwnd
, msg
->pt
, &hittest
);
1709 if (!msg
->hwnd
|| !WIN_IsCurrentThread( msg
->hwnd
))
1711 accept_hardware_message( hw_id
, TRUE
, msg
->hwnd
);
1715 /* FIXME: is this really the right place for this hook? */
1716 event
.message
= msg
->message
;
1717 event
.time
= msg
->time
;
1718 event
.hwnd
= msg
->hwnd
;
1719 event
.paramL
= msg
->pt
.x
;
1720 event
.paramH
= msg
->pt
.y
;
1721 HOOK_CallHooks( WH_JOURNALRECORD
, HC_ACTION
, 0, (LPARAM
)&event
, TRUE
);
1723 if (!check_hwnd_filter( msg
, hwnd_filter
)) return FALSE
;
1726 message
= msg
->message
;
1727 /* Note: windows has no concept of a non-client wheel message */
1728 if (message
!= WM_MOUSEWHEEL
)
1730 if (hittest
!= HTCLIENT
)
1732 message
+= WM_NCMOUSEMOVE
- WM_MOUSEMOVE
;
1733 msg
->wParam
= hittest
;
1737 /* coordinates don't get translated while tracking a menu */
1738 /* FIXME: should differentiate popups and top-level menus */
1739 if (!(info
.flags
& GUI_INMENUMODE
))
1740 ScreenToClient( msg
->hwnd
, &pt
);
1743 msg
->lParam
= MAKELONG( pt
.x
, pt
.y
);
1745 /* translate double clicks */
1747 if ((msg
->message
== WM_LBUTTONDOWN
) ||
1748 (msg
->message
== WM_RBUTTONDOWN
) ||
1749 (msg
->message
== WM_MBUTTONDOWN
) ||
1750 (msg
->message
== WM_XBUTTONDOWN
))
1752 BOOL update
= remove
;
1754 /* translate double clicks -
1755 * note that ...MOUSEMOVEs can slip in between
1756 * ...BUTTONDOWN and ...BUTTONDBLCLK messages */
1758 if ((info
.flags
& (GUI_INMENUMODE
|GUI_INMOVESIZE
)) ||
1759 hittest
!= HTCLIENT
||
1760 (GetClassLongA( msg
->hwnd
, GCL_STYLE
) & CS_DBLCLKS
))
1762 if ((msg
->message
== clk_msg
.message
) &&
1763 (msg
->hwnd
== clk_msg
.hwnd
) &&
1764 (msg
->wParam
== clk_msg
.wParam
) &&
1765 (msg
->time
- clk_msg
.time
< GetDoubleClickTime()) &&
1766 (abs(msg
->pt
.x
- clk_msg
.pt
.x
) < GetSystemMetrics(SM_CXDOUBLECLK
)/2) &&
1767 (abs(msg
->pt
.y
- clk_msg
.pt
.y
) < GetSystemMetrics(SM_CYDOUBLECLK
)/2))
1769 message
+= (WM_LBUTTONDBLCLK
- WM_LBUTTONDOWN
);
1772 clk_msg
.message
= 0; /* clear the double click conditions */
1777 if (message
< first
|| message
> last
) return FALSE
;
1778 /* update static double click conditions */
1779 if (update
) clk_msg
= *msg
;
1783 if (message
< first
|| message
> last
) return FALSE
;
1786 /* message is accepted now (but may still get dropped) */
1789 hook
.hwnd
= msg
->hwnd
;
1790 hook
.wHitTestCode
= hittest
;
1791 hook
.dwExtraInfo
= extra_info
;
1792 if (HOOK_CallHooks( WH_MOUSE
, remove
? HC_ACTION
: HC_NOREMOVE
,
1793 message
, (LPARAM
)&hook
, TRUE
))
1796 hook
.hwnd
= msg
->hwnd
;
1797 hook
.wHitTestCode
= hittest
;
1798 hook
.dwExtraInfo
= extra_info
;
1799 HOOK_CallHooks( WH_CBT
, HCBT_CLICKSKIPPED
, message
, (LPARAM
)&hook
, TRUE
);
1800 accept_hardware_message( hw_id
, TRUE
, 0 );
1804 if ((hittest
== HTERROR
) || (hittest
== HTNOWHERE
))
1806 SendMessageW( msg
->hwnd
, WM_SETCURSOR
, (WPARAM
)msg
->hwnd
,
1807 MAKELONG( hittest
, msg
->message
));
1808 accept_hardware_message( hw_id
, TRUE
, 0 );
1812 accept_hardware_message( hw_id
, remove
, 0 );
1814 if (!remove
|| info
.hwndCapture
)
1816 msg
->message
= message
;
1822 if ((msg
->message
== WM_LBUTTONDOWN
) ||
1823 (msg
->message
== WM_RBUTTONDOWN
) ||
1824 (msg
->message
== WM_MBUTTONDOWN
) ||
1825 (msg
->message
== WM_XBUTTONDOWN
))
1827 /* Send the WM_PARENTNOTIFY,
1828 * note that even for double/nonclient clicks
1829 * notification message is still WM_L/M/RBUTTONDOWN.
1831 send_parent_notify( msg
->hwnd
, msg
->message
, 0, msg
->pt
);
1833 /* Activate the window if needed */
1835 if (msg
->hwnd
!= info
.hwndActive
)
1837 HWND hwndTop
= msg
->hwnd
;
1840 if ((GetWindowLongW( hwndTop
, GWL_STYLE
) & (WS_POPUP
|WS_CHILD
)) != WS_CHILD
) break;
1841 hwndTop
= GetParent( hwndTop
);
1844 if (hwndTop
&& hwndTop
!= GetDesktopWindow())
1846 LONG ret
= SendMessageW( msg
->hwnd
, WM_MOUSEACTIVATE
, (WPARAM
)hwndTop
,
1847 MAKELONG( hittest
, msg
->message
) );
1850 case MA_NOACTIVATEANDEAT
:
1855 case MA_ACTIVATEANDEAT
:
1860 if (!FOCUS_MouseActivate( hwndTop
)) eatMsg
= TRUE
;
1863 WARN( "unknown WM_MOUSEACTIVATE code %d\n", ret
);
1870 /* send the WM_SETCURSOR message */
1872 /* Windows sends the normal mouse message as the message parameter
1873 in the WM_SETCURSOR message even if it's non-client mouse message */
1874 SendMessageW( msg
->hwnd
, WM_SETCURSOR
, (WPARAM
)msg
->hwnd
, MAKELONG( hittest
, msg
->message
));
1876 msg
->message
= message
;
1881 /***********************************************************************
1882 * process_hardware_message
1884 * Process a hardware message; return TRUE if message should be passed on to the app
1886 static BOOL
process_hardware_message( MSG
*msg
, UINT hw_id
, ULONG_PTR extra_info
, HWND hwnd_filter
,
1887 UINT first
, UINT last
, BOOL remove
)
1889 if (is_keyboard_message( msg
->message
))
1890 return process_keyboard_message( msg
, hw_id
, hwnd_filter
, first
, last
, remove
);
1892 if (is_mouse_message( msg
->message
))
1893 return process_mouse_message( msg
, hw_id
, extra_info
, hwnd_filter
, first
, last
, remove
);
1895 ERR( "unknown message type %x\n", msg
->message
);
1900 /***********************************************************************
1901 * call_sendmsg_callback
1903 * Call the callback function of SendMessageCallback.
1905 static inline void call_sendmsg_callback( SENDASYNCPROC callback
, HWND hwnd
, UINT msg
,
1906 ULONG_PTR data
, LRESULT result
)
1908 if (TRACE_ON(relay
))
1909 DPRINTF( "%04x:Call message callback %p (hwnd=%p,msg=%s,data=%08lx,result=%08lx)\n",
1910 GetCurrentThreadId(), callback
, hwnd
, SPY_GetMsgName( msg
, hwnd
),
1912 callback( hwnd
, msg
, data
, result
);
1913 if (TRACE_ON(relay
))
1914 DPRINTF( "%04x:Ret message callback %p (hwnd=%p,msg=%s,data=%08lx,result=%08lx)\n",
1915 GetCurrentThreadId(), callback
, hwnd
, SPY_GetMsgName( msg
, hwnd
),
1920 /***********************************************************************
1923 * Retrieve the hook procedure real value for a module-relative proc
1925 static void *get_hook_proc( void *proc
, const WCHAR
*module
)
1929 if (!(mod
= GetModuleHandleW(module
)))
1931 TRACE( "loading %s\n", debugstr_w(module
) );
1932 /* FIXME: the library will never be freed */
1933 if (!(mod
= LoadLibraryW(module
))) return NULL
;
1935 return (char *)mod
+ (ULONG_PTR
)proc
;
1939 /***********************************************************************
1942 * Peek for a message matching the given parameters. Return FALSE if none available.
1943 * All pending sent messages are processed before returning.
1945 static BOOL
peek_message( MSG
*msg
, HWND hwnd
, UINT first
, UINT last
, int flags
)
1948 ULONG_PTR extra_info
= 0;
1949 struct user_thread_info
*thread_info
= get_user_thread_info();
1950 struct received_message_info info
, *old_info
;
1951 unsigned int hw_id
= 0; /* id of previous hardware message */
1953 if (!first
&& !last
) last
= ~0;
1958 void *buffer
= NULL
;
1959 size_t size
= 0, buffer_size
= 0;
1961 do /* loop while buffer is too small */
1963 if (buffer_size
&& !(buffer
= HeapAlloc( GetProcessHeap(), 0, buffer_size
)))
1965 SERVER_START_REQ( get_message
)
1968 req
->get_win
= hwnd
;
1969 req
->get_first
= first
;
1970 req
->get_last
= last
;
1972 if (buffer_size
) wine_server_set_reply( req
, buffer
, buffer_size
);
1973 if (!(res
= wine_server_call( req
)))
1975 size
= wine_server_reply_size( reply
);
1976 info
.type
= reply
->type
;
1977 info
.msg
.hwnd
= reply
->win
;
1978 info
.msg
.message
= reply
->msg
;
1979 info
.msg
.wParam
= reply
->wparam
;
1980 info
.msg
.lParam
= reply
->lparam
;
1981 info
.msg
.time
= reply
->time
;
1982 info
.msg
.pt
.x
= reply
->x
;
1983 info
.msg
.pt
.y
= reply
->y
;
1984 hw_id
= reply
->hw_id
;
1985 extra_info
= reply
->info
;
1986 thread_info
->active_hooks
= reply
->active_hooks
;
1990 HeapFree( GetProcessHeap(), 0, buffer
);
1991 buffer_size
= reply
->total
;
1995 } while (res
== STATUS_BUFFER_OVERFLOW
);
1997 if (res
) return FALSE
;
1999 TRACE( "got type %d msg %x (%s) hwnd %p wp %x lp %lx\n",
2000 info
.type
, info
.msg
.message
,
2001 (info
.type
== MSG_WINEVENT
) ? "MSG_WINEVENT" : SPY_GetMsgName(info
.msg
.message
, info
.msg
.hwnd
),
2002 info
.msg
.hwnd
, info
.msg
.wParam
, info
.msg
.lParam
);
2008 info
.flags
= ISMEX_SEND
;
2011 info
.flags
= ISMEX_NOTIFY
;
2014 info
.flags
= ISMEX_CALLBACK
;
2016 case MSG_CALLBACK_RESULT
:
2017 if (size
>= sizeof(struct callback_msg_data
))
2019 const struct callback_msg_data
*data
= (const struct callback_msg_data
*)buffer
;
2020 call_sendmsg_callback( data
->callback
, info
.msg
.hwnd
,
2021 info
.msg
.message
, data
->data
, data
->result
);
2025 if (size
>= sizeof(struct winevent_msg_data
))
2027 WINEVENTPROC hook_proc
;
2028 const struct winevent_msg_data
*data
= (const struct winevent_msg_data
*)buffer
;
2030 hook_proc
= data
->hook_proc
;
2031 size
-= sizeof(*data
);
2034 WCHAR module
[MAX_PATH
];
2036 size
= min( size
, (MAX_PATH
- 1) * sizeof(WCHAR
) );
2037 memcpy( module
, buffer
, size
);
2038 module
[size
/ sizeof(WCHAR
)] = 0;
2039 if (!(hook_proc
= get_hook_proc( hook_proc
, module
)))
2041 ERR( "invalid winevent hook module name %s\n", debugstr_w(module
) );
2046 if (TRACE_ON(relay
))
2047 DPRINTF( "%04x:Call winevent proc %p (hook=%p,event=%x,hwnd=%p,object_id=%x,child_id=%lx,tid=%04x,time=%x)\n",
2048 GetCurrentThreadId(), hook_proc
,
2049 data
->hook
, info
.msg
.message
, info
.msg
.hwnd
, info
.msg
.wParam
,
2050 info
.msg
.lParam
, data
->tid
, info
.msg
.time
);
2052 hook_proc( data
->hook
, info
.msg
.message
, info
.msg
.hwnd
, info
.msg
.wParam
,
2053 info
.msg
.lParam
, data
->tid
, info
.msg
.time
);
2055 if (TRACE_ON(relay
))
2056 DPRINTF( "%04x:Ret winevent proc %p (hook=%p,event=%x,hwnd=%p,object_id=%x,child_id=%lx,tid=%04x,time=%x)\n",
2057 GetCurrentThreadId(), hook_proc
,
2058 data
->hook
, info
.msg
.message
, info
.msg
.hwnd
, info
.msg
.wParam
,
2059 info
.msg
.lParam
, data
->tid
, info
.msg
.time
);
2062 case MSG_OTHER_PROCESS
:
2063 info
.flags
= ISMEX_SEND
;
2064 if (!unpack_message( info
.msg
.hwnd
, info
.msg
.message
, &info
.msg
.wParam
,
2065 &info
.msg
.lParam
, &buffer
, size
))
2068 reply_message( &info
, 0, TRUE
);
2073 if (!process_hardware_message( &info
.msg
, hw_id
, extra_info
,
2074 hwnd
, first
, last
, flags
& GET_MSG_REMOVE
))
2076 TRACE("dropping msg %x\n", info
.msg
.message
);
2077 goto next
; /* ignore it */
2079 thread_info
->GetMessagePosVal
= MAKELONG( info
.msg
.pt
.x
, info
.msg
.pt
.y
);
2082 thread_info
->GetMessageExtraInfoVal
= extra_info
;
2083 if (info
.msg
.message
>= WM_DDE_FIRST
&& info
.msg
.message
<= WM_DDE_LAST
)
2085 if (!unpack_dde_message( info
.msg
.hwnd
, info
.msg
.message
, &info
.msg
.wParam
,
2086 &info
.msg
.lParam
, &buffer
, size
))
2087 goto next
; /* ignore it */
2090 HeapFree( GetProcessHeap(), 0, buffer
);
2094 /* if we get here, we have a sent message; call the window procedure */
2095 old_info
= thread_info
->receive_info
;
2096 thread_info
->receive_info
= &info
;
2097 result
= call_window_proc( info
.msg
.hwnd
, info
.msg
.message
, info
.msg
.wParam
,
2098 info
.msg
.lParam
, (info
.type
!= MSG_ASCII
), FALSE
);
2099 reply_message( &info
, result
, TRUE
);
2100 thread_info
->receive_info
= old_info
;
2102 HeapFree( GetProcessHeap(), 0, buffer
);
2107 /***********************************************************************
2108 * process_sent_messages
2110 * Process all pending sent messages.
2112 inline static void process_sent_messages(void)
2115 peek_message( &msg
, 0, 0, 0, GET_MSG_REMOVE
| GET_MSG_SENT_ONLY
);
2119 /***********************************************************************
2120 * get_server_queue_handle
2122 * Get a handle to the server message queue for the current thread.
2124 static HANDLE
get_server_queue_handle(void)
2126 struct user_thread_info
*thread_info
= get_user_thread_info();
2129 if (!(ret
= thread_info
->server_queue
))
2131 SERVER_START_REQ( get_msg_queue
)
2133 wine_server_call( req
);
2134 ret
= reply
->handle
;
2137 thread_info
->server_queue
= ret
;
2138 if (!ret
) ERR( "Cannot get server thread queue\n" );
2144 /***********************************************************************
2145 * wait_message_reply
2147 * Wait until a sent message gets replied to.
2149 static void wait_message_reply( UINT flags
)
2151 HANDLE server_queue
= get_server_queue_handle();
2155 unsigned int wake_bits
= 0, changed_bits
= 0;
2158 SERVER_START_REQ( set_queue_mask
)
2160 req
->wake_mask
= QS_SMRESULT
| ((flags
& SMTO_BLOCK
) ? 0 : QS_SENDMESSAGE
);
2161 req
->changed_mask
= req
->wake_mask
;
2163 if (!wine_server_call( req
))
2165 wake_bits
= reply
->wake_bits
;
2166 changed_bits
= reply
->changed_bits
;
2171 if (wake_bits
& QS_SMRESULT
) return; /* got a result */
2172 if (wake_bits
& QS_SENDMESSAGE
)
2174 /* Process the sent message immediately */
2175 process_sent_messages();
2179 /* now wait for it */
2181 ReleaseThunkLock( &dwlc
);
2182 res
= USER_Driver
->pMsgWaitForMultipleObjectsEx( 1, &server_queue
,
2183 INFINITE
, QS_SENDMESSAGE
, 0 );
2184 if (dwlc
) RestoreThunkLock( dwlc
);
2188 /***********************************************************************
2189 * put_message_in_queue
2191 * Put a sent message into the destination queue.
2192 * For inter-process message, reply_size is set to expected size of reply data.
2194 static BOOL
put_message_in_queue( const struct send_message_info
*info
, size_t *reply_size
)
2196 struct packed_message data
;
2197 message_data_t msg_data
;
2201 /* Check for INFINITE timeout for compatibility with Win9x,
2202 * although Windows >= NT does not do so
2204 if (info
->type
!= MSG_NOTIFY
&&
2205 info
->type
!= MSG_CALLBACK
&&
2206 info
->type
!= MSG_POSTED
&&
2207 info
->timeout
!= INFINITE
)
2208 timeout
= info
->timeout
;
2211 if (info
->type
== MSG_OTHER_PROCESS
)
2213 *reply_size
= pack_message( info
->hwnd
, info
->msg
, info
->wparam
, info
->lparam
, &data
);
2214 if (data
.count
== -1)
2216 WARN( "cannot pack message %x\n", info
->msg
);
2220 else if (info
->type
== MSG_CALLBACK
)
2222 msg_data
.callback
.callback
= info
->callback
;
2223 msg_data
.callback
.data
= info
->data
;
2224 msg_data
.callback
.result
= 0;
2225 data
.data
[0] = &msg_data
;
2226 data
.size
[0] = sizeof(msg_data
.callback
);
2229 else if (info
->type
== MSG_POSTED
&& info
->msg
>= WM_DDE_FIRST
&& info
->msg
<= WM_DDE_LAST
)
2231 return post_dde_message( &data
, info
);
2234 SERVER_START_REQ( send_message
)
2236 req
->id
= info
->dest_tid
;
2237 req
->type
= info
->type
;
2239 req
->win
= info
->hwnd
;
2240 req
->msg
= info
->msg
;
2241 req
->wparam
= info
->wparam
;
2242 req
->lparam
= info
->lparam
;
2243 req
->timeout
= timeout
;
2245 if (info
->flags
& SMTO_ABORTIFHUNG
) req
->flags
|= SEND_MSG_ABORT_IF_HUNG
;
2246 for (i
= 0; i
< data
.count
; i
++) wine_server_add_data( req
, data
.data
[i
], data
.size
[i
] );
2247 if ((res
= wine_server_call( req
)))
2249 if (res
== STATUS_INVALID_PARAMETER
)
2250 /* FIXME: find a STATUS_ value for this one */
2251 SetLastError( ERROR_INVALID_THREAD_ID
);
2253 SetLastError( RtlNtStatusToDosError(res
) );
2261 /***********************************************************************
2264 * Retrieve a message reply from the server.
2266 static LRESULT
retrieve_reply( const struct send_message_info
*info
,
2267 size_t reply_size
, LRESULT
*result
)
2270 void *reply_data
= NULL
;
2274 if (!(reply_data
= HeapAlloc( GetProcessHeap(), 0, reply_size
)))
2276 WARN( "no memory for reply, will be truncated\n" );
2280 SERVER_START_REQ( get_message_reply
)
2283 if (reply_size
) wine_server_set_reply( req
, reply_data
, reply_size
);
2284 if (!(status
= wine_server_call( req
))) *result
= reply
->result
;
2285 reply_size
= wine_server_reply_size( reply
);
2288 if (!status
&& reply_size
)
2289 unpack_reply( info
->hwnd
, info
->msg
, info
->wparam
, info
->lparam
, reply_data
, reply_size
);
2291 HeapFree( GetProcessHeap(), 0, reply_data
);
2293 TRACE( "hwnd %p msg %x (%s) wp %x lp %lx got reply %lx (err=%d)\n",
2294 info
->hwnd
, info
->msg
, SPY_GetMsgName(info
->msg
, info
->hwnd
), info
->wparam
,
2295 info
->lparam
, *result
, status
);
2297 /* MSDN states that last error is 0 on timeout, but at least NT4 returns ERROR_TIMEOUT */
2298 if (status
) SetLastError( RtlNtStatusToDosError(status
) );
2303 /***********************************************************************
2304 * send_inter_thread_message
2306 static LRESULT
send_inter_thread_message( const struct send_message_info
*info
, LRESULT
*res_ptr
)
2308 size_t reply_size
= 0;
2310 TRACE( "hwnd %p msg %x (%s) wp %x lp %lx\n",
2311 info
->hwnd
, info
->msg
, SPY_GetMsgName(info
->msg
, info
->hwnd
), info
->wparam
, info
->lparam
);
2313 USER_CheckNotLock();
2315 if (!put_message_in_queue( info
, &reply_size
)) return 0;
2317 /* there's no reply to wait for on notify/callback messages */
2318 if (info
->type
== MSG_NOTIFY
|| info
->type
== MSG_CALLBACK
) return 1;
2320 wait_message_reply( info
->flags
);
2321 return retrieve_reply( info
, reply_size
, res_ptr
);
2325 /***********************************************************************
2326 * MSG_SendInternalMessageTimeout
2328 * Same as SendMessageTimeoutW but sends the message to a specific thread
2329 * without requiring a window handle. Only works for internal Wine messages.
2331 LRESULT
MSG_SendInternalMessageTimeout( DWORD dest_pid
, DWORD dest_tid
,
2332 UINT msg
, WPARAM wparam
, LPARAM lparam
,
2333 UINT flags
, UINT timeout
, PDWORD_PTR res_ptr
)
2335 struct send_message_info info
;
2336 LRESULT ret
, result
;
2338 assert( msg
& 0x80000000 ); /* must be an internal Wine message */
2340 info
.type
= MSG_UNICODE
;
2341 info
.dest_tid
= dest_tid
;
2344 info
.wparam
= wparam
;
2345 info
.lparam
= lparam
;
2347 info
.timeout
= timeout
;
2349 if (USER_IsExitingThread( dest_tid
)) return 0;
2351 if (dest_tid
== GetCurrentThreadId())
2353 result
= handle_internal_message( 0, msg
, wparam
, lparam
);
2358 if (dest_pid
!= GetCurrentProcessId()) info
.type
= MSG_OTHER_PROCESS
;
2359 ret
= send_inter_thread_message( &info
, &result
);
2361 if (ret
&& res_ptr
) *res_ptr
= result
;
2366 /***********************************************************************
2367 * SendMessageTimeoutW (USER32.@)
2369 LRESULT WINAPI
SendMessageTimeoutW( HWND hwnd
, UINT msg
, WPARAM wparam
, LPARAM lparam
,
2370 UINT flags
, UINT timeout
, PDWORD_PTR res_ptr
)
2372 struct send_message_info info
;
2374 LRESULT ret
, result
;
2376 info
.type
= MSG_UNICODE
;
2379 info
.wparam
= wparam
;
2380 info
.lparam
= lparam
;
2382 info
.timeout
= timeout
;
2384 if (is_broadcast(hwnd
))
2386 EnumWindows( broadcast_message_callback
, (LPARAM
)&info
);
2387 if (res_ptr
) *res_ptr
= 1;
2391 if (!(info
.dest_tid
= GetWindowThreadProcessId( hwnd
, &dest_pid
))) return 0;
2393 if (USER_IsExitingThread( info
.dest_tid
)) return 0;
2395 SPY_EnterMessage( SPY_SENDMESSAGE
, hwnd
, msg
, wparam
, lparam
);
2397 if (info
.dest_tid
== GetCurrentThreadId())
2399 result
= call_window_proc( hwnd
, msg
, wparam
, lparam
, TRUE
, TRUE
);
2404 if (dest_pid
!= GetCurrentProcessId()) info
.type
= MSG_OTHER_PROCESS
;
2405 ret
= send_inter_thread_message( &info
, &result
);
2408 SPY_ExitMessage( SPY_RESULT_OK
, hwnd
, msg
, result
, wparam
, lparam
);
2409 if (ret
&& res_ptr
) *res_ptr
= result
;
2413 static LRESULT
send_inter_thread_callback( HWND hwnd
, UINT msg
, WPARAM wp
, LPARAM lp
,
2414 LRESULT
*result
, void *arg
)
2416 struct send_message_info
*info
= arg
;
2421 return send_inter_thread_message( info
, result
);
2424 /***********************************************************************
2425 * SendMessageTimeoutA (USER32.@)
2427 LRESULT WINAPI
SendMessageTimeoutA( HWND hwnd
, UINT msg
, WPARAM wparam
, LPARAM lparam
,
2428 UINT flags
, UINT timeout
, PDWORD_PTR res_ptr
)
2430 struct send_message_info info
;
2432 LRESULT ret
, result
;
2434 info
.type
= MSG_ASCII
;
2437 info
.wparam
= wparam
;
2438 info
.lparam
= lparam
;
2440 info
.timeout
= timeout
;
2442 if (is_broadcast(hwnd
))
2444 EnumWindows( broadcast_message_callback
, (LPARAM
)&info
);
2445 if (res_ptr
) *res_ptr
= 1;
2449 if (!(info
.dest_tid
= GetWindowThreadProcessId( hwnd
, &dest_pid
))) return 0;
2451 if (USER_IsExitingThread( info
.dest_tid
)) return 0;
2453 SPY_EnterMessage( SPY_SENDMESSAGE
, hwnd
, msg
, wparam
, lparam
);
2455 if (info
.dest_tid
== GetCurrentThreadId())
2457 result
= call_window_proc( hwnd
, msg
, wparam
, lparam
, FALSE
, TRUE
);
2460 else if (dest_pid
== GetCurrentProcessId())
2462 ret
= send_inter_thread_message( &info
, &result
);
2466 /* inter-process message: need to map to Unicode */
2467 info
.type
= MSG_OTHER_PROCESS
;
2468 if (is_unicode_message( info
.msg
))
2469 ret
= WINPROC_CallProcAtoW( send_inter_thread_callback
, info
.hwnd
, info
.msg
,
2470 info
.wparam
, info
.lparam
, &result
, &info
);
2471 else ret
= send_inter_thread_message( &info
, &result
);
2473 SPY_ExitMessage( SPY_RESULT_OK
, hwnd
, msg
, result
, wparam
, lparam
);
2474 if (ret
&& res_ptr
) *res_ptr
= result
;
2479 /***********************************************************************
2480 * SendMessageW (USER32.@)
2482 LRESULT WINAPI
SendMessageW( HWND hwnd
, UINT msg
, WPARAM wparam
, LPARAM lparam
)
2485 SendMessageTimeoutW( hwnd
, msg
, wparam
, lparam
, SMTO_NORMAL
, 0, &res
);
2490 /***********************************************************************
2491 * SendMessageA (USER32.@)
2493 LRESULT WINAPI
SendMessageA( HWND hwnd
, UINT msg
, WPARAM wparam
, LPARAM lparam
)
2496 SendMessageTimeoutA( hwnd
, msg
, wparam
, lparam
, SMTO_NORMAL
, 0, &res
);
2501 /***********************************************************************
2502 * SendNotifyMessageA (USER32.@)
2504 BOOL WINAPI
SendNotifyMessageA( HWND hwnd
, UINT msg
, WPARAM wparam
, LPARAM lparam
)
2506 return SendNotifyMessageW( hwnd
, msg
, map_wparam_AtoW( msg
, wparam
), lparam
);
2510 /***********************************************************************
2511 * SendNotifyMessageW (USER32.@)
2513 BOOL WINAPI
SendNotifyMessageW( HWND hwnd
, UINT msg
, WPARAM wparam
, LPARAM lparam
)
2515 struct send_message_info info
;
2518 if (is_pointer_message(msg
))
2520 SetLastError( ERROR_MESSAGE_SYNC_ONLY
);
2524 info
.type
= MSG_NOTIFY
;
2527 info
.wparam
= wparam
;
2528 info
.lparam
= lparam
;
2531 if (is_broadcast(hwnd
))
2533 EnumWindows( broadcast_message_callback
, (LPARAM
)&info
);
2537 if (!(info
.dest_tid
= GetWindowThreadProcessId( hwnd
, NULL
))) return FALSE
;
2539 if (USER_IsExitingThread( info
.dest_tid
)) return TRUE
;
2541 if (info
.dest_tid
== GetCurrentThreadId())
2543 call_window_proc( hwnd
, msg
, wparam
, lparam
, TRUE
, TRUE
);
2546 return send_inter_thread_message( &info
, &result
);
2550 /***********************************************************************
2551 * SendMessageCallbackA (USER32.@)
2553 BOOL WINAPI
SendMessageCallbackA( HWND hwnd
, UINT msg
, WPARAM wparam
, LPARAM lparam
,
2554 SENDASYNCPROC callback
, ULONG_PTR data
)
2556 return SendMessageCallbackW( hwnd
, msg
, map_wparam_AtoW( msg
, wparam
),
2557 lparam
, callback
, data
);
2561 /***********************************************************************
2562 * SendMessageCallbackW (USER32.@)
2564 BOOL WINAPI
SendMessageCallbackW( HWND hwnd
, UINT msg
, WPARAM wparam
, LPARAM lparam
,
2565 SENDASYNCPROC callback
, ULONG_PTR data
)
2567 struct send_message_info info
;
2570 if (is_pointer_message(msg
))
2572 SetLastError( ERROR_MESSAGE_SYNC_ONLY
);
2576 info
.type
= MSG_CALLBACK
;
2579 info
.wparam
= wparam
;
2580 info
.lparam
= lparam
;
2581 info
.callback
= callback
;
2585 if (is_broadcast(hwnd
))
2587 EnumWindows( broadcast_message_callback
, (LPARAM
)&info
);
2591 if (!(info
.dest_tid
= GetWindowThreadProcessId( hwnd
, NULL
))) return FALSE
;
2593 if (USER_IsExitingThread( info
.dest_tid
)) return TRUE
;
2595 if (info
.dest_tid
== GetCurrentThreadId())
2597 result
= call_window_proc( hwnd
, msg
, wparam
, lparam
, TRUE
, TRUE
);
2598 call_sendmsg_callback( callback
, hwnd
, msg
, data
, result
);
2601 return send_inter_thread_message( &info
, &result
);
2605 /***********************************************************************
2606 * ReplyMessage (USER32.@)
2608 BOOL WINAPI
ReplyMessage( LRESULT result
)
2610 struct received_message_info
*info
= get_user_thread_info()->receive_info
;
2612 if (!info
) return FALSE
;
2613 reply_message( info
, result
, FALSE
);
2618 /***********************************************************************
2619 * InSendMessage (USER32.@)
2621 BOOL WINAPI
InSendMessage(void)
2623 return (InSendMessageEx(NULL
) & (ISMEX_SEND
|ISMEX_REPLIED
)) == ISMEX_SEND
;
2627 /***********************************************************************
2628 * InSendMessageEx (USER32.@)
2630 DWORD WINAPI
InSendMessageEx( LPVOID reserved
)
2632 struct received_message_info
*info
= get_user_thread_info()->receive_info
;
2634 if (info
) return info
->flags
;
2635 return ISMEX_NOSEND
;
2639 /***********************************************************************
2640 * PostMessageA (USER32.@)
2642 BOOL WINAPI
PostMessageA( HWND hwnd
, UINT msg
, WPARAM wparam
, LPARAM lparam
)
2644 return PostMessageW( hwnd
, msg
, map_wparam_AtoW( msg
, wparam
), lparam
);
2648 /***********************************************************************
2649 * PostMessageW (USER32.@)
2651 BOOL WINAPI
PostMessageW( HWND hwnd
, UINT msg
, WPARAM wparam
, LPARAM lparam
)
2653 struct send_message_info info
;
2655 if (is_pointer_message( msg
))
2657 SetLastError( ERROR_MESSAGE_SYNC_ONLY
);
2661 TRACE( "hwnd %p msg %x (%s) wp %x lp %lx\n",
2662 hwnd
, msg
, SPY_GetMsgName(msg
, hwnd
), wparam
, lparam
);
2664 info
.type
= MSG_POSTED
;
2667 info
.wparam
= wparam
;
2668 info
.lparam
= lparam
;
2671 if (is_broadcast(hwnd
))
2673 EnumWindows( broadcast_message_callback
, (LPARAM
)&info
);
2677 if (!hwnd
) return PostThreadMessageW( GetCurrentThreadId(), msg
, wparam
, lparam
);
2679 if (!(info
.dest_tid
= GetWindowThreadProcessId( hwnd
, NULL
))) return FALSE
;
2681 if (USER_IsExitingThread( info
.dest_tid
)) return TRUE
;
2683 return put_message_in_queue( &info
, NULL
);
2687 /**********************************************************************
2688 * PostThreadMessageA (USER32.@)
2690 BOOL WINAPI
PostThreadMessageA( DWORD thread
, UINT msg
, WPARAM wparam
, LPARAM lparam
)
2692 return PostThreadMessageW( thread
, msg
, map_wparam_AtoW( msg
, wparam
), lparam
);
2696 /**********************************************************************
2697 * PostThreadMessageW (USER32.@)
2699 BOOL WINAPI
PostThreadMessageW( DWORD thread
, UINT msg
, WPARAM wparam
, LPARAM lparam
)
2701 struct send_message_info info
;
2703 if (is_pointer_message( msg
))
2705 SetLastError( ERROR_MESSAGE_SYNC_ONLY
);
2708 if (USER_IsExitingThread( thread
)) return TRUE
;
2710 info
.type
= MSG_POSTED
;
2711 info
.dest_tid
= thread
;
2714 info
.wparam
= wparam
;
2715 info
.lparam
= lparam
;
2717 return put_message_in_queue( &info
, NULL
);
2721 /***********************************************************************
2722 * PostQuitMessage (USER32.@)
2724 * Posts a quit message to the current thread's message queue.
2727 * exit_code [I] Exit code to return from message loop.
2733 * This function is not the same as calling:
2734 *|PostThreadMessage(GetCurrentThreadId(), WM_QUIT, exit_code, 0);
2735 * It instead sets a flag in the message queue that signals it to generate
2736 * a WM_QUIT message when there are no other pending sent or posted messages
2739 void WINAPI
PostQuitMessage( INT exit_code
)
2741 SERVER_START_REQ( post_quit_message
)
2743 req
->exit_code
= exit_code
;
2744 wine_server_call( req
);
2750 /***********************************************************************
2751 * PeekMessageW (USER32.@)
2753 BOOL WINAPI
PeekMessageW( MSG
*msg_out
, HWND hwnd
, UINT first
, UINT last
, UINT flags
)
2755 struct user_thread_info
*thread_info
= get_user_thread_info();
2759 FIXME("PM_QS_xxxx flags (%04x) are not handled\n", flags
>> 16);
2761 USER_CheckNotLock();
2763 /* check for graphics events */
2764 USER_Driver
->pMsgWaitForMultipleObjectsEx( 0, NULL
, 0, QS_ALLINPUT
, 0 );
2766 hwnd
= WIN_GetFullHandle( hwnd
);
2770 if (!peek_message( &msg
, hwnd
, first
, last
, (flags
& PM_REMOVE
) ? GET_MSG_REMOVE
: 0 ))
2772 if (!(flags
& PM_NOYIELD
))
2775 ReleaseThunkLock(&count
);
2777 if (count
) RestoreThunkLock(count
);
2781 if (msg
.message
& 0x80000000)
2783 if (!(flags
& PM_REMOVE
))
2785 /* Have to remove the message explicitly.
2786 Do this before handling it, because the message handler may
2787 call PeekMessage again */
2788 peek_message( &msg
, msg
.hwnd
, msg
.message
, msg
.message
, GET_MSG_REMOVE
);
2790 handle_internal_message( msg
.hwnd
, msg
.message
, msg
.wParam
, msg
.lParam
);
2795 thread_info
->GetMessageTimeVal
= msg
.time
;
2796 msg
.pt
.x
= (short)LOWORD( thread_info
->GetMessagePosVal
);
2797 msg
.pt
.y
= (short)HIWORD( thread_info
->GetMessagePosVal
);
2799 HOOK_CallHooks( WH_GETMESSAGE
, HC_ACTION
, flags
& PM_REMOVE
, (LPARAM
)&msg
, TRUE
);
2801 /* copy back our internal safe copy of message data to msg_out.
2802 * msg_out is a variable from the *program*, so it can't be used
2803 * internally as it can get "corrupted" by our use of SendMessage()
2804 * (back to the program) inside the message handling itself. */
2807 SetLastError( ERROR_NOACCESS
);
2815 /***********************************************************************
2816 * PeekMessageA (USER32.@)
2818 BOOL WINAPI
PeekMessageA( MSG
*msg
, HWND hwnd
, UINT first
, UINT last
, UINT flags
)
2820 BOOL ret
= PeekMessageW( msg
, hwnd
, first
, last
, flags
);
2821 if (ret
) msg
->wParam
= map_wparam_WtoA( msg
->message
, msg
->wParam
);
2826 /***********************************************************************
2827 * GetMessageW (USER32.@)
2829 BOOL WINAPI
GetMessageW( MSG
*msg
, HWND hwnd
, UINT first
, UINT last
)
2831 HANDLE server_queue
= get_server_queue_handle();
2832 int mask
= QS_POSTMESSAGE
| QS_SENDMESSAGE
; /* Always selected */
2836 if ((first
<= WM_KEYLAST
) && (last
>= WM_KEYFIRST
)) mask
|= QS_KEY
;
2837 if ( ((first
<= WM_MOUSELAST
) && (last
>= WM_MOUSEFIRST
)) ||
2838 ((first
<= WM_NCMOUSELAST
) && (last
>= WM_NCMOUSEFIRST
)) ) mask
|= QS_MOUSE
;
2839 if ((first
<= WM_TIMER
) && (last
>= WM_TIMER
)) mask
|= QS_TIMER
;
2840 if ((first
<= WM_SYSTIMER
) && (last
>= WM_SYSTIMER
)) mask
|= QS_TIMER
;
2841 if ((first
<= WM_PAINT
) && (last
>= WM_PAINT
)) mask
|= QS_PAINT
;
2843 else mask
|= QS_MOUSE
| QS_KEY
| QS_TIMER
| QS_PAINT
;
2845 while (!PeekMessageW( msg
, hwnd
, first
, last
, PM_REMOVE
))
2847 /* wait until one of the bits is set */
2848 unsigned int wake_bits
= 0, changed_bits
= 0;
2851 SERVER_START_REQ( set_queue_mask
)
2853 req
->wake_mask
= QS_SENDMESSAGE
;
2854 req
->changed_mask
= mask
;
2856 if (!wine_server_call( req
))
2858 wake_bits
= reply
->wake_bits
;
2859 changed_bits
= reply
->changed_bits
;
2864 if (changed_bits
& mask
) continue;
2865 if (wake_bits
& QS_SENDMESSAGE
) continue;
2867 TRACE( "(%04x) mask=%08x, bits=%08x, changed=%08x, waiting\n",
2868 GetCurrentThreadId(), mask
, wake_bits
, changed_bits
);
2870 ReleaseThunkLock( &dwlc
);
2871 USER_Driver
->pMsgWaitForMultipleObjectsEx( 1, &server_queue
, INFINITE
, QS_ALLINPUT
, 0 );
2872 if (dwlc
) RestoreThunkLock( dwlc
);
2875 return (msg
->message
!= WM_QUIT
);
2879 /***********************************************************************
2880 * GetMessageA (USER32.@)
2882 BOOL WINAPI
GetMessageA( MSG
*msg
, HWND hwnd
, UINT first
, UINT last
)
2884 GetMessageW( msg
, hwnd
, first
, last
);
2885 msg
->wParam
= map_wparam_WtoA( msg
->message
, msg
->wParam
);
2886 return (msg
->message
!= WM_QUIT
);
2890 /***********************************************************************
2891 * IsDialogMessageA (USER32.@)
2892 * IsDialogMessage (USER32.@)
2894 BOOL WINAPI
IsDialogMessageA( HWND hwndDlg
, LPMSG pmsg
)
2897 msg
.wParam
= map_wparam_AtoW( msg
.message
, msg
.wParam
);
2898 return IsDialogMessageW( hwndDlg
, &msg
);
2902 /***********************************************************************
2903 * TranslateMessage (USER32.@)
2905 * Implementation of TranslateMessage.
2907 * TranslateMessage translates virtual-key messages into character-messages,
2909 * WM_KEYDOWN/WM_KEYUP combinations produce a WM_CHAR or WM_DEADCHAR message.
2910 * ditto replacing WM_* with WM_SYS*
2911 * This produces WM_CHAR messages only for keys mapped to ASCII characters
2912 * by the keyboard driver.
2914 * If the message is WM_KEYDOWN, WM_KEYUP, WM_SYSKEYDOWN, or WM_SYSKEYUP, the
2915 * return value is nonzero, regardless of the translation.
2918 BOOL WINAPI
TranslateMessage( const MSG
*msg
)
2924 if (msg
->message
< WM_KEYFIRST
|| msg
->message
> WM_KEYLAST
) return FALSE
;
2925 if (msg
->message
!= WM_KEYDOWN
&& msg
->message
!= WM_SYSKEYDOWN
) return TRUE
;
2927 TRACE_(key
)("Translating key %s (%04x), scancode %02x\n",
2928 SPY_GetVKeyName(msg
->wParam
), msg
->wParam
, LOBYTE(HIWORD(msg
->lParam
)));
2930 GetKeyboardState( state
);
2931 /* FIXME : should handle ToUnicode yielding 2 */
2932 switch (ToUnicode(msg
->wParam
, HIWORD(msg
->lParam
), state
, wp
, 2, 0))
2935 message
= (msg
->message
== WM_KEYDOWN
) ? WM_CHAR
: WM_SYSCHAR
;
2936 TRACE_(key
)("1 -> PostMessageW(%p,%s,%04x,%08lx)\n",
2937 msg
->hwnd
, SPY_GetMsgName(message
, msg
->hwnd
), wp
[0], msg
->lParam
);
2938 PostMessageW( msg
->hwnd
, message
, wp
[0], msg
->lParam
);
2942 message
= (msg
->message
== WM_KEYDOWN
) ? WM_DEADCHAR
: WM_SYSDEADCHAR
;
2943 TRACE_(key
)("-1 -> PostMessageW(%p,%s,%04x,%08lx)\n",
2944 msg
->hwnd
, SPY_GetMsgName(message
, msg
->hwnd
), wp
[0], msg
->lParam
);
2945 PostMessageW( msg
->hwnd
, message
, wp
[0], msg
->lParam
);
2952 /***********************************************************************
2953 * DispatchMessageA (USER32.@)
2955 * See DispatchMessageW.
2957 LONG WINAPI
DispatchMessageA( const MSG
* msg
)
2963 /* Process timer messages */
2964 if ((msg
->message
== WM_TIMER
) || (msg
->message
== WM_SYSTIMER
))
2966 if (msg
->lParam
) return CallWindowProcA( (WNDPROC
)msg
->lParam
, msg
->hwnd
,
2967 msg
->message
, msg
->wParam
, GetTickCount() );
2970 if (!(wndPtr
= WIN_GetPtr( msg
->hwnd
)))
2972 if (msg
->hwnd
) SetLastError( ERROR_INVALID_WINDOW_HANDLE
);
2975 if (wndPtr
== WND_OTHER_PROCESS
|| wndPtr
== WND_DESKTOP
)
2977 if (IsWindow( msg
->hwnd
)) SetLastError( ERROR_MESSAGE_SYNC_ONLY
);
2978 else SetLastError( ERROR_INVALID_WINDOW_HANDLE
);
2981 if (wndPtr
->tid
!= GetCurrentThreadId())
2983 SetLastError( ERROR_MESSAGE_SYNC_ONLY
);
2984 WIN_ReleasePtr( wndPtr
);
2987 winproc
= wndPtr
->winproc
;
2988 WIN_ReleasePtr( wndPtr
);
2990 SPY_EnterMessage( SPY_DISPATCHMESSAGE
, msg
->hwnd
, msg
->message
,
2991 msg
->wParam
, msg
->lParam
);
2992 retval
= CallWindowProcA( winproc
, msg
->hwnd
, msg
->message
,
2993 msg
->wParam
, msg
->lParam
);
2994 SPY_ExitMessage( SPY_RESULT_OK
, msg
->hwnd
, msg
->message
, retval
,
2995 msg
->wParam
, msg
->lParam
);
2997 if (msg
->message
== WM_PAINT
)
2999 /* send a WM_NCPAINT and WM_ERASEBKGND if the non-client area is still invalid */
3000 HRGN hrgn
= CreateRectRgn( 0, 0, 0, 0 );
3001 GetUpdateRgn( msg
->hwnd
, hrgn
, TRUE
);
3002 DeleteObject( hrgn
);
3008 /***********************************************************************
3009 * DispatchMessageW (USER32.@) Process a message
3011 * Process the message specified in the structure *_msg_.
3013 * If the lpMsg parameter points to a WM_TIMER message and the
3014 * parameter of the WM_TIMER message is not NULL, the lParam parameter
3015 * points to the function that is called instead of the window
3018 * The message must be valid.
3022 * DispatchMessage() returns the result of the window procedure invoked.
3029 LONG WINAPI
DispatchMessageW( const MSG
* msg
)
3035 /* Process timer messages */
3036 if ((msg
->message
== WM_TIMER
) || (msg
->message
== WM_SYSTIMER
))
3038 if (msg
->lParam
) return CallWindowProcW( (WNDPROC
)msg
->lParam
, msg
->hwnd
,
3039 msg
->message
, msg
->wParam
, GetTickCount() );
3042 if (!(wndPtr
= WIN_GetPtr( msg
->hwnd
)))
3044 if (msg
->hwnd
) SetLastError( ERROR_INVALID_WINDOW_HANDLE
);
3047 if (wndPtr
== WND_OTHER_PROCESS
|| wndPtr
== WND_DESKTOP
)
3049 if (IsWindow( msg
->hwnd
)) SetLastError( ERROR_MESSAGE_SYNC_ONLY
);
3050 else SetLastError( ERROR_INVALID_WINDOW_HANDLE
);
3053 if (wndPtr
->tid
!= GetCurrentThreadId())
3055 SetLastError( ERROR_MESSAGE_SYNC_ONLY
);
3056 WIN_ReleasePtr( wndPtr
);
3059 winproc
= wndPtr
->winproc
;
3060 WIN_ReleasePtr( wndPtr
);
3062 SPY_EnterMessage( SPY_DISPATCHMESSAGE
, msg
->hwnd
, msg
->message
,
3063 msg
->wParam
, msg
->lParam
);
3064 retval
= CallWindowProcW( winproc
, msg
->hwnd
, msg
->message
,
3065 msg
->wParam
, msg
->lParam
);
3066 SPY_ExitMessage( SPY_RESULT_OK
, msg
->hwnd
, msg
->message
, retval
,
3067 msg
->wParam
, msg
->lParam
);
3069 if (msg
->message
== WM_PAINT
)
3071 /* send a WM_NCPAINT and WM_ERASEBKGND if the non-client area is still invalid */
3072 HRGN hrgn
= CreateRectRgn( 0, 0, 0, 0 );
3073 GetUpdateRgn( msg
->hwnd
, hrgn
, TRUE
);
3074 DeleteObject( hrgn
);
3080 /***********************************************************************
3081 * GetMessagePos (USER.119)
3082 * GetMessagePos (USER32.@)
3084 * The GetMessagePos() function returns a long value representing a
3085 * cursor position, in screen coordinates, when the last message
3086 * retrieved by the GetMessage() function occurs. The x-coordinate is
3087 * in the low-order word of the return value, the y-coordinate is in
3088 * the high-order word. The application can use the MAKEPOINT()
3089 * macro to obtain a POINT structure from the return value.
3091 * For the current cursor position, use GetCursorPos().
3095 * Cursor position of last message on success, zero on failure.
3102 DWORD WINAPI
GetMessagePos(void)
3104 return get_user_thread_info()->GetMessagePosVal
;
3108 /***********************************************************************
3109 * GetMessageTime (USER.120)
3110 * GetMessageTime (USER32.@)
3112 * GetMessageTime() returns the message time for the last message
3113 * retrieved by the function. The time is measured in milliseconds with
3114 * the same offset as GetTickCount().
3116 * Since the tick count wraps, this is only useful for moderately short
3117 * relative time comparisons.
3121 * Time of last message on success, zero on failure.
3123 LONG WINAPI
GetMessageTime(void)
3125 return get_user_thread_info()->GetMessageTimeVal
;
3129 /***********************************************************************
3130 * GetMessageExtraInfo (USER.288)
3131 * GetMessageExtraInfo (USER32.@)
3133 LPARAM WINAPI
GetMessageExtraInfo(void)
3135 return get_user_thread_info()->GetMessageExtraInfoVal
;
3139 /***********************************************************************
3140 * SetMessageExtraInfo (USER32.@)
3142 LPARAM WINAPI
SetMessageExtraInfo(LPARAM lParam
)
3144 struct user_thread_info
*thread_info
= get_user_thread_info();
3145 LONG old_value
= thread_info
->GetMessageExtraInfoVal
;
3146 thread_info
->GetMessageExtraInfoVal
= lParam
;
3151 /***********************************************************************
3152 * WaitMessage (USER.112) Suspend thread pending messages
3153 * WaitMessage (USER32.@) Suspend thread pending messages
3155 * WaitMessage() suspends a thread until events appear in the thread's
3158 BOOL WINAPI
WaitMessage(void)
3160 return (MsgWaitForMultipleObjectsEx( 0, NULL
, INFINITE
, QS_ALLINPUT
, 0 ) != WAIT_FAILED
);
3164 /***********************************************************************
3165 * MsgWaitForMultipleObjectsEx (USER32.@)
3167 DWORD WINAPI
MsgWaitForMultipleObjectsEx( DWORD count
, CONST HANDLE
*pHandles
,
3168 DWORD timeout
, DWORD mask
, DWORD flags
)
3170 HANDLE handles
[MAXIMUM_WAIT_OBJECTS
];
3173 if (count
> MAXIMUM_WAIT_OBJECTS
-1)
3175 SetLastError( ERROR_INVALID_PARAMETER
);
3179 /* set the queue mask */
3180 SERVER_START_REQ( set_queue_mask
)
3182 req
->wake_mask
= (flags
& MWMO_INPUTAVAILABLE
) ? mask
: 0;
3183 req
->changed_mask
= mask
;
3185 wine_server_call( req
);
3189 /* Add the thread event to the handle list */
3190 for (i
= 0; i
< count
; i
++) handles
[i
] = pHandles
[i
];
3191 handles
[count
] = get_server_queue_handle();
3193 ReleaseThunkLock( &lock
);
3194 ret
= USER_Driver
->pMsgWaitForMultipleObjectsEx( count
+1, handles
, timeout
, mask
, flags
);
3195 if (ret
== count
+1) ret
= count
; /* pretend the msg queue is ready */
3196 if (lock
) RestoreThunkLock( lock
);
3201 /***********************************************************************
3202 * MsgWaitForMultipleObjects (USER32.@)
3204 DWORD WINAPI
MsgWaitForMultipleObjects( DWORD count
, CONST HANDLE
*handles
,
3205 BOOL wait_all
, DWORD timeout
, DWORD mask
)
3207 return MsgWaitForMultipleObjectsEx( count
, handles
, timeout
, mask
,
3208 wait_all
? MWMO_WAITALL
: 0 );
3212 /***********************************************************************
3213 * WaitForInputIdle (USER32.@)
3215 DWORD WINAPI
WaitForInputIdle( HANDLE hProcess
, DWORD dwTimeOut
)
3217 DWORD start_time
, elapsed
, ret
;
3220 handles
[0] = hProcess
;
3221 SERVER_START_REQ( get_process_idle_event
)
3223 req
->handle
= hProcess
;
3224 if (!(ret
= wine_server_call_err( req
))) handles
[1] = reply
->event
;
3227 if (ret
) return WAIT_FAILED
; /* error */
3228 if (!handles
[1]) return 0; /* no event to wait on */
3230 start_time
= GetTickCount();
3233 TRACE("waiting for %p\n", handles
[1] );
3236 ret
= MsgWaitForMultipleObjects ( 2, handles
, FALSE
, dwTimeOut
- elapsed
, QS_SENDMESSAGE
);
3241 case WAIT_OBJECT_0
+2:
3242 process_sent_messages();
3246 TRACE("timeout or error\n");
3249 TRACE("finished\n");
3252 if (dwTimeOut
!= INFINITE
)
3254 elapsed
= GetTickCount() - start_time
;
3255 if (elapsed
> dwTimeOut
)
3261 return WAIT_TIMEOUT
;
3265 /***********************************************************************
3266 * UserYield (USER.332)
3268 void WINAPI
UserYield16(void)
3272 /* Handle sent messages */
3273 process_sent_messages();
3276 ReleaseThunkLock(&count
);
3280 RestoreThunkLock(count
);
3281 /* Handle sent messages again */
3282 process_sent_messages();
3287 /***********************************************************************
3288 * RegisterWindowMessageA (USER32.@)
3289 * RegisterWindowMessage (USER.118)
3291 UINT WINAPI
RegisterWindowMessageA( LPCSTR str
)
3293 UINT ret
= GlobalAddAtomA(str
);
3294 TRACE("%s, ret=%x\n", str
, ret
);
3299 /***********************************************************************
3300 * RegisterWindowMessageW (USER32.@)
3302 UINT WINAPI
RegisterWindowMessageW( LPCWSTR str
)
3304 UINT ret
= GlobalAddAtomW(str
);
3305 TRACE("%s ret=%x\n", debugstr_w(str
), ret
);
3310 /***********************************************************************
3311 * BroadcastSystemMessageA (USER32.@)
3312 * BroadcastSystemMessage (USER32.@)
3314 LONG WINAPI
BroadcastSystemMessageA( DWORD flags
, LPDWORD recipients
, UINT msg
, WPARAM wp
, LPARAM lp
)
3316 if ((*recipients
& BSM_APPLICATIONS
) || (*recipients
== BSM_ALLCOMPONENTS
))
3318 FIXME( "(%08x,%08x,%08x,%08x,%08lx): semi-stub!\n", flags
, *recipients
, msg
, wp
, lp
);
3319 PostMessageA( HWND_BROADCAST
, msg
, wp
, lp
);
3324 FIXME( "(%08x,%08x,%08x,%08x,%08lx): stub!\n", flags
, *recipients
, msg
, wp
, lp
);
3330 /***********************************************************************
3331 * BroadcastSystemMessageW (USER32.@)
3333 LONG WINAPI
BroadcastSystemMessageW( DWORD flags
, LPDWORD recipients
, UINT msg
, WPARAM wp
, LPARAM lp
)
3335 if ((*recipients
& BSM_APPLICATIONS
) || (*recipients
== BSM_ALLCOMPONENTS
))
3337 FIXME( "(%08x,%08x,%08x,%08x,%08lx): semi-stub!\n", flags
, *recipients
, msg
, wp
, lp
);
3338 PostMessageW( HWND_BROADCAST
, msg
, wp
, lp
);
3343 FIXME( "(%08x,%08x,%08x,%08x,%08lx): stub!\n", flags
, *recipients
, msg
, wp
, lp
);
3349 /***********************************************************************
3350 * SetMessageQueue (USER32.@)
3352 BOOL WINAPI
SetMessageQueue( INT size
)
3354 /* now obsolete the message queue will be expanded dynamically as necessary */
3359 /***********************************************************************
3360 * MessageBeep (USER32.@)
3362 BOOL WINAPI
MessageBeep( UINT i
)
3365 SystemParametersInfoA( SPI_GETBEEP
, 0, &active
, FALSE
);
3366 if (active
) USER_Driver
->pBeep();
3371 /***********************************************************************
3372 * SetTimer (USER32.@)
3374 UINT_PTR WINAPI
SetTimer( HWND hwnd
, UINT_PTR id
, UINT timeout
, TIMERPROC proc
)
3377 WNDPROC winproc
= 0;
3379 if (proc
) winproc
= WINPROC_AllocProc( (WNDPROC
)proc
, NULL
);
3381 SERVER_START_REQ( set_win_timer
)
3384 req
->msg
= WM_TIMER
;
3386 req
->rate
= max( timeout
, SYS_TIMER_RATE
);
3387 req
->lparam
= (unsigned long)winproc
;
3388 if (!wine_server_call_err( req
))
3391 if (!ret
) ret
= TRUE
;
3397 TRACE("Added %p %x %p timeout %d\n", hwnd
, id
, winproc
, timeout
);
3402 /***********************************************************************
3403 * SetSystemTimer (USER32.@)
3405 UINT_PTR WINAPI
SetSystemTimer( HWND hwnd
, UINT_PTR id
, UINT timeout
, TIMERPROC proc
)
3408 WNDPROC winproc
= 0;
3410 if (proc
) winproc
= WINPROC_AllocProc( (WNDPROC
)proc
, NULL
);
3412 SERVER_START_REQ( set_win_timer
)
3415 req
->msg
= WM_SYSTIMER
;
3417 req
->rate
= max( timeout
, SYS_TIMER_RATE
);
3418 req
->lparam
= (unsigned long)winproc
;
3419 if (!wine_server_call_err( req
))
3422 if (!ret
) ret
= TRUE
;
3428 TRACE("Added %p %x %p timeout %d\n", hwnd
, id
, winproc
, timeout
);
3433 /***********************************************************************
3434 * KillTimer (USER32.@)
3436 BOOL WINAPI
KillTimer( HWND hwnd
, UINT_PTR id
)
3440 TRACE("%p %d\n", hwnd
, id
);
3442 SERVER_START_REQ( kill_win_timer
)
3445 req
->msg
= WM_TIMER
;
3447 ret
= !wine_server_call_err( req
);
3454 /***********************************************************************
3455 * KillSystemTimer (USER32.@)
3457 BOOL WINAPI
KillSystemTimer( HWND hwnd
, UINT_PTR id
)
3461 TRACE("%p %d\n", hwnd
, id
);
3463 SERVER_START_REQ( kill_win_timer
)
3466 req
->msg
= WM_SYSTIMER
;
3468 ret
= !wine_server_call_err( req
);
3475 /**********************************************************************
3476 * GetGUIThreadInfo (USER32.@)
3478 BOOL WINAPI
GetGUIThreadInfo( DWORD id
, GUITHREADINFO
*info
)
3482 SERVER_START_REQ( get_thread_input
)
3485 if ((ret
= !wine_server_call_err( req
)))
3488 info
->hwndActive
= reply
->active
;
3489 info
->hwndFocus
= reply
->focus
;
3490 info
->hwndCapture
= reply
->capture
;
3491 info
->hwndMenuOwner
= reply
->menu_owner
;
3492 info
->hwndMoveSize
= reply
->move_size
;
3493 info
->hwndCaret
= reply
->caret
;
3494 info
->rcCaret
.left
= reply
->rect
.left
;
3495 info
->rcCaret
.top
= reply
->rect
.top
;
3496 info
->rcCaret
.right
= reply
->rect
.right
;
3497 info
->rcCaret
.bottom
= reply
->rect
.bottom
;
3498 if (reply
->menu_owner
) info
->flags
|= GUI_INMENUMODE
;
3499 if (reply
->move_size
) info
->flags
|= GUI_INMOVESIZE
;
3500 if (reply
->caret
) info
->flags
|= GUI_CARETBLINKING
;
3508 /******************************************************************
3509 * IsHungAppWindow (USER32.@)
3512 BOOL WINAPI
IsHungAppWindow( HWND hWnd
)
3515 return !SendMessageTimeoutA(hWnd
, WM_NULL
, 0, 0, SMTO_ABORTIFHUNG
, 5000, &dwResult
);