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"
44 #include "wine/debug.h"
46 WINE_DEFAULT_DEBUG_CHANNEL(msg
);
47 WINE_DECLARE_DEBUG_CHANNEL(relay
);
48 WINE_DECLARE_DEBUG_CHANNEL(key
);
50 #define WM_NCMOUSEFIRST WM_NCMOUSEMOVE
51 #define WM_NCMOUSELAST (WM_NCMOUSEFIRST+(WM_MOUSELAST-WM_MOUSEFIRST))
53 #define MAX_PACK_COUNT 4
54 #define MAX_SENDMSG_RECURSION 64
56 #define SYS_TIMER_RATE 55 /* min. timer rate in ms (actually 54.925)*/
58 /* description of the data fields that need to be packed along with a sent message */
62 const void *data
[MAX_PACK_COUNT
];
63 size_t size
[MAX_PACK_COUNT
];
66 /* info about the message currently being received by the current thread */
67 struct received_message_info
69 enum message_type type
;
71 UINT flags
; /* InSendMessageEx return flags */
72 HWINEVENTHOOK hook
; /* winevent hook handle */
73 WINEVENTPROC hook_proc
; /* winevent hook proc address */
76 /* structure to group all parameters for sent messages of the various kinds */
77 struct send_message_info
79 enum message_type type
;
85 UINT flags
; /* flags for SendMessageTimeout */
86 UINT timeout
; /* timeout for SendMessageTimeout */
87 SENDASYNCPROC callback
; /* callback function for SendMessageCallback */
88 ULONG_PTR data
; /* callback data */
92 /* flag for messages that contain pointers */
93 /* 32 messages per entry, messages 0..31 map to bits 0..31 */
95 #define SET(msg) (1 << ((msg) & 31))
97 static const unsigned int message_pointer_flags
[] =
100 SET(WM_CREATE
) | SET(WM_SETTEXT
) | SET(WM_GETTEXT
) |
101 SET(WM_WININICHANGE
) | SET(WM_DEVMODECHANGE
),
103 SET(WM_GETMINMAXINFO
) | SET(WM_DRAWITEM
) | SET(WM_MEASUREITEM
) | SET(WM_DELETEITEM
) |
106 SET(WM_WINDOWPOSCHANGING
) | SET(WM_WINDOWPOSCHANGED
) | SET(WM_COPYDATA
) |
107 SET(WM_NOTIFY
) | SET(WM_HELP
),
109 SET(WM_STYLECHANGING
) | SET(WM_STYLECHANGED
),
111 SET(WM_NCCREATE
) | SET(WM_NCCALCSIZE
) | SET(WM_GETDLGCODE
),
113 SET(EM_GETSEL
) | SET(EM_GETRECT
) | SET(EM_SETRECT
) | SET(EM_SETRECTNP
),
115 SET(EM_REPLACESEL
) | SET(EM_GETLINE
) | SET(EM_SETTABSTOPS
),
117 SET(SBM_GETRANGE
) | SET(SBM_SETSCROLLINFO
) | SET(SBM_GETSCROLLINFO
) | SET(SBM_GETSCROLLBARINFO
),
123 SET(CB_GETEDITSEL
) | SET(CB_ADDSTRING
) | SET(CB_DIR
) | SET(CB_GETLBTEXT
) |
124 SET(CB_INSERTSTRING
) | SET(CB_FINDSTRING
) | SET(CB_SELECTSTRING
) |
125 SET(CB_GETDROPPEDCONTROLRECT
) | SET(CB_FINDSTRINGEXACT
),
129 SET(LB_ADDSTRING
) | SET(LB_INSERTSTRING
) | SET(LB_GETTEXT
) | SET(LB_SELECTSTRING
) |
130 SET(LB_DIR
) | SET(LB_FINDSTRING
) |
131 SET(LB_GETSELITEMS
) | SET(LB_SETTABSTOPS
) | SET(LB_ADDFILE
) | SET(LB_GETITEMRECT
),
133 SET(LB_FINDSTRINGEXACT
),
139 SET(WM_NEXTMENU
) | SET(WM_SIZING
) | SET(WM_MOVING
) | SET(WM_DEVICECHANGE
),
141 SET(WM_MDICREATE
) | SET(WM_MDIGETACTIVE
) | SET(WM_DROPOBJECT
) |
142 SET(WM_QUERYDROPOBJECT
) | SET(WM_DRAGLOOP
) | SET(WM_DRAGSELECT
) | SET(WM_DRAGMOVE
),
156 SET(WM_ASKCBFORMATNAME
)
159 /* flags for messages that contain Unicode strings */
160 static const unsigned int message_unicode_flags
[] =
163 SET(WM_CREATE
) | SET(WM_SETTEXT
) | SET(WM_GETTEXT
) | SET(WM_GETTEXTLENGTH
) |
164 SET(WM_WININICHANGE
) | SET(WM_DEVMODECHANGE
),
176 SET(EM_REPLACESEL
) | SET(EM_GETLINE
) | SET(EM_SETPASSWORDCHAR
),
180 SET(WM_CHAR
) | SET(WM_DEADCHAR
) | SET(WM_SYSCHAR
) | SET(WM_SYSDEADCHAR
),
184 SET(CB_ADDSTRING
) | SET(CB_DIR
) | SET(CB_GETLBTEXT
) | SET(CB_GETLBTEXTLEN
) |
185 SET(CB_INSERTSTRING
) | SET(CB_FINDSTRING
) | SET(CB_SELECTSTRING
) | SET(CB_FINDSTRINGEXACT
),
189 SET(LB_ADDSTRING
) | SET(LB_INSERTSTRING
) | SET(LB_GETTEXT
) | SET(LB_GETTEXTLEN
) |
190 SET(LB_SELECTSTRING
) | SET(LB_DIR
) | SET(LB_FINDSTRING
) | SET(LB_ADDFILE
),
192 SET(LB_FINDSTRINGEXACT
),
214 SET(WM_PAINTCLIPBOARD
) | SET(WM_SIZECLIPBOARD
) | SET(WM_ASKCBFORMATNAME
)
217 /* check whether a given message type includes pointers */
218 inline static int is_pointer_message( UINT message
)
220 if (message
>= 8*sizeof(message_pointer_flags
)) return FALSE
;
221 return (message_pointer_flags
[message
/ 32] & SET(message
)) != 0;
224 /* check whether a given message type contains Unicode (or ASCII) chars */
225 inline static int is_unicode_message( UINT message
)
227 if (message
>= 8*sizeof(message_unicode_flags
)) return FALSE
;
228 return (message_unicode_flags
[message
/ 32] & SET(message
)) != 0;
233 /* add a data field to a packed message */
234 inline static void push_data( struct packed_message
*data
, const void *ptr
, size_t size
)
236 data
->data
[data
->count
] = ptr
;
237 data
->size
[data
->count
] = size
;
241 /* add a string to a packed message */
242 inline static void push_string( struct packed_message
*data
, LPCWSTR str
)
244 push_data( data
, str
, (strlenW(str
) + 1) * sizeof(WCHAR
) );
247 /* retrieve a pointer to data from a packed message and increment the buffer pointer */
248 inline static void *get_data( void **buffer
, size_t size
)
251 *buffer
= (char *)*buffer
+ size
;
255 /* make sure that the buffer contains a valid null-terminated Unicode string */
256 inline static BOOL
check_string( LPCWSTR str
, size_t size
)
258 for (size
/= sizeof(WCHAR
); size
; size
--, str
++)
259 if (!*str
) return TRUE
;
263 /* make sure that there is space for 'size' bytes in buffer, growing it if needed */
264 inline static void *get_buffer_space( void **buffer
, size_t size
)
270 if (!(ret
= HeapReAlloc( GetProcessHeap(), 0, *buffer
, size
)))
271 HeapFree( GetProcessHeap(), 0, *buffer
);
273 else ret
= HeapAlloc( GetProcessHeap(), 0, size
);
279 /* retrieve a string pointer from packed data */
280 inline static LPWSTR
get_string( void **buffer
)
282 return get_data( buffer
, (strlenW( (LPWSTR
)*buffer
) + 1) * sizeof(WCHAR
) );
285 /* check whether a combobox expects strings or ids in CB_ADDSTRING/CB_INSERTSTRING */
286 inline static BOOL
combobox_has_strings( HWND hwnd
)
288 DWORD style
= GetWindowLongA( hwnd
, GWL_STYLE
);
289 return (!(style
& (CBS_OWNERDRAWFIXED
| CBS_OWNERDRAWVARIABLE
)) || (style
& CBS_HASSTRINGS
));
292 /* check whether a listbox expects strings or ids in LB_ADDSTRING/LB_INSERTSTRING */
293 inline static BOOL
listbox_has_strings( HWND hwnd
)
295 DWORD style
= GetWindowLongA( hwnd
, GWL_STYLE
);
296 return (!(style
& (LBS_OWNERDRAWFIXED
| LBS_OWNERDRAWVARIABLE
)) || (style
& LBS_HASSTRINGS
));
299 /* check whether message is in the range of keyboard messages */
300 inline static BOOL
is_keyboard_message( UINT message
)
302 return (message
>= WM_KEYFIRST
&& message
<= WM_KEYLAST
);
305 /* check whether message is in the range of mouse messages */
306 inline static BOOL
is_mouse_message( UINT message
)
308 return ((message
>= WM_NCMOUSEFIRST
&& message
<= WM_NCMOUSELAST
) ||
309 (message
>= WM_MOUSEFIRST
&& message
<= WM_MOUSELAST
));
312 /* check whether message matches the specified hwnd filter */
313 inline static BOOL
check_hwnd_filter( const MSG
*msg
, HWND hwnd_filter
)
315 if (!hwnd_filter
) return TRUE
;
316 return (msg
->hwnd
== hwnd_filter
|| IsChild( hwnd_filter
, msg
->hwnd
));
320 /***********************************************************************
321 * broadcast_message_callback
323 * Helper callback for broadcasting messages.
325 static BOOL CALLBACK
broadcast_message_callback( HWND hwnd
, LPARAM lparam
)
327 struct send_message_info
*info
= (struct send_message_info
*)lparam
;
328 if (!(GetWindowLongW( hwnd
, GWL_STYLE
) & (WS_POPUP
|WS_CAPTION
))) return TRUE
;
332 SendMessageTimeoutW( hwnd
, info
->msg
, info
->wparam
, info
->lparam
,
333 info
->flags
, info
->timeout
, NULL
);
336 SendMessageTimeoutA( hwnd
, info
->msg
, info
->wparam
, info
->lparam
,
337 info
->flags
, info
->timeout
, NULL
);
340 SendNotifyMessageW( hwnd
, info
->msg
, info
->wparam
, info
->lparam
);
343 SendMessageCallbackW( hwnd
, info
->msg
, info
->wparam
, info
->lparam
,
344 info
->callback
, info
->data
);
347 PostMessageW( hwnd
, info
->msg
, info
->wparam
, info
->lparam
);
350 ERR( "bad type %d\n", info
->type
);
357 /***********************************************************************
360 * Convert the wparam of an ASCII message to Unicode.
362 static WPARAM
map_wparam_AtoW( UINT message
, WPARAM wparam
)
367 case EM_SETPASSWORDCHAR
:
376 ch
[0] = (wparam
& 0xff);
377 ch
[1] = (wparam
>> 8);
378 MultiByteToWideChar(CP_ACP
, 0, ch
, 2, wch
, 2);
379 wparam
= MAKEWPARAM(wch
[0], wch
[1]);
386 ch
[0] = (wparam
>> 8);
387 ch
[1] = (wparam
& 0xff);
388 if (ch
[0]) MultiByteToWideChar(CP_ACP
, 0, ch
, 2, &wch
, 1);
389 else MultiByteToWideChar(CP_ACP
, 0, &ch
[1], 1, &wch
, 1);
390 wparam
= MAKEWPARAM( wch
, HIWORD(wparam
) );
398 /***********************************************************************
401 * Convert the wparam of a Unicode message to ASCII.
403 static WPARAM
map_wparam_WtoA( UINT message
, WPARAM wparam
)
408 case EM_SETPASSWORDCHAR
:
417 wch
[0] = LOWORD(wparam
);
418 wch
[1] = HIWORD(wparam
);
419 WideCharToMultiByte( CP_ACP
, 0, wch
, 2, (LPSTR
)ch
, 2, NULL
, NULL
);
420 wparam
= MAKEWPARAM( ch
[0] | (ch
[1] << 8), 0 );
425 WCHAR wch
= LOWORD(wparam
);
428 if (WideCharToMultiByte( CP_ACP
, 0, &wch
, 1, (LPSTR
)ch
, 2, NULL
, NULL
) == 2)
429 wparam
= MAKEWPARAM( (ch
[0] << 8) | ch
[1], HIWORD(wparam
) );
431 wparam
= MAKEWPARAM( ch
[0], HIWORD(wparam
) );
439 /***********************************************************************
442 * Pack a message for sending to another process.
443 * Return the size of the data we expect in the message reply.
444 * Set data->count to -1 if there is an error.
446 static size_t pack_message( HWND hwnd
, UINT message
, WPARAM wparam
, LPARAM lparam
,
447 struct packed_message
*data
)
455 CREATESTRUCTW
*cs
= (CREATESTRUCTW
*)lparam
;
456 push_data( data
, cs
, sizeof(*cs
) );
457 if (HIWORD(cs
->lpszName
)) push_string( data
, cs
->lpszName
);
458 if (HIWORD(cs
->lpszClass
)) push_string( data
, cs
->lpszClass
);
462 case WM_ASKCBFORMATNAME
:
463 return wparam
* sizeof(WCHAR
);
464 case WM_WININICHANGE
:
465 if (lparam
) push_string(data
, (LPWSTR
)lparam
);
468 case WM_DEVMODECHANGE
:
473 push_string( data
, (LPWSTR
)lparam
);
475 case WM_GETMINMAXINFO
:
476 push_data( data
, (MINMAXINFO
*)lparam
, sizeof(MINMAXINFO
) );
477 return sizeof(MINMAXINFO
);
479 push_data( data
, (DRAWITEMSTRUCT
*)lparam
, sizeof(DRAWITEMSTRUCT
) );
482 push_data( data
, (MEASUREITEMSTRUCT
*)lparam
, sizeof(MEASUREITEMSTRUCT
) );
483 return sizeof(MEASUREITEMSTRUCT
);
485 push_data( data
, (DELETEITEMSTRUCT
*)lparam
, sizeof(DELETEITEMSTRUCT
) );
488 push_data( data
, (COMPAREITEMSTRUCT
*)lparam
, sizeof(COMPAREITEMSTRUCT
) );
490 case WM_WINDOWPOSCHANGING
:
491 case WM_WINDOWPOSCHANGED
:
492 push_data( data
, (WINDOWPOS
*)lparam
, sizeof(WINDOWPOS
) );
493 return sizeof(WINDOWPOS
);
496 COPYDATASTRUCT
*cp
= (COPYDATASTRUCT
*)lparam
;
497 push_data( data
, cp
, sizeof(*cp
) );
498 if (cp
->lpData
) push_data( data
, cp
->lpData
, cp
->cbData
);
502 /* WM_NOTIFY cannot be sent across processes (MSDN) */
506 push_data( data
, (HELPINFO
*)lparam
, sizeof(HELPINFO
) );
508 case WM_STYLECHANGING
:
509 case WM_STYLECHANGED
:
510 push_data( data
, (STYLESTRUCT
*)lparam
, sizeof(STYLESTRUCT
) );
515 push_data( data
, (RECT
*)lparam
, sizeof(RECT
) );
520 NCCALCSIZE_PARAMS
*nc
= (NCCALCSIZE_PARAMS
*)lparam
;
521 push_data( data
, nc
, sizeof(*nc
) );
522 push_data( data
, nc
->lppos
, sizeof(*nc
->lppos
) );
523 return sizeof(*nc
) + sizeof(*nc
->lppos
);
526 if (lparam
) push_data( data
, (MSG
*)lparam
, sizeof(MSG
) );
528 case SBM_SETSCROLLINFO
:
529 push_data( data
, (SCROLLINFO
*)lparam
, sizeof(SCROLLINFO
) );
531 case SBM_GETSCROLLINFO
:
532 push_data( data
, (SCROLLINFO
*)lparam
, sizeof(SCROLLINFO
) );
533 return sizeof(SCROLLINFO
);
534 case SBM_GETSCROLLBARINFO
:
536 const SCROLLBARINFO
*info
= (const SCROLLBARINFO
*)lparam
;
537 size_t size
= min( info
->cbSize
, sizeof(SCROLLBARINFO
) );
538 push_data( data
, info
, size
);
546 if (wparam
) size
+= sizeof(DWORD
);
547 if (lparam
) size
+= sizeof(DWORD
);
552 case CB_GETDROPPEDCONTROLRECT
:
556 push_data( data
, (RECT
*)lparam
, sizeof(RECT
) );
560 WORD
*pw
= (WORD
*)lparam
;
561 push_data( data
, pw
, sizeof(*pw
) );
562 return *pw
* sizeof(WCHAR
);
566 if (wparam
) push_data( data
, (UINT
*)lparam
, sizeof(UINT
) * wparam
);
569 case CB_INSERTSTRING
:
571 case CB_FINDSTRINGEXACT
:
572 case CB_SELECTSTRING
:
573 if (combobox_has_strings( hwnd
)) push_string( data
, (LPWSTR
)lparam
);
576 if (!combobox_has_strings( hwnd
)) return sizeof(ULONG_PTR
);
577 return (SendMessageW( hwnd
, CB_GETLBTEXTLEN
, wparam
, 0 ) + 1) * sizeof(WCHAR
);
579 case LB_INSERTSTRING
:
581 case LB_FINDSTRINGEXACT
:
582 case LB_SELECTSTRING
:
583 if (listbox_has_strings( hwnd
)) push_string( data
, (LPWSTR
)lparam
);
586 if (!listbox_has_strings( hwnd
)) return sizeof(ULONG_PTR
);
587 return (SendMessageW( hwnd
, LB_GETTEXTLEN
, wparam
, 0 ) + 1) * sizeof(WCHAR
);
589 return wparam
* sizeof(UINT
);
591 push_data( data
, (MDINEXTMENU
*)lparam
, sizeof(MDINEXTMENU
) );
592 return sizeof(MDINEXTMENU
);
595 push_data( data
, (RECT
*)lparam
, sizeof(RECT
) );
599 MDICREATESTRUCTW
*cs
= (MDICREATESTRUCTW
*)lparam
;
600 push_data( data
, cs
, sizeof(*cs
) );
601 if (HIWORD(cs
->szTitle
)) push_string( data
, cs
->szTitle
);
602 if (HIWORD(cs
->szClass
)) push_string( data
, cs
->szClass
);
605 case WM_MDIGETACTIVE
:
606 if (lparam
) return sizeof(BOOL
);
608 case WM_DEVICECHANGE
:
610 DEV_BROADCAST_HDR
*header
= (DEV_BROADCAST_HDR
*)lparam
;
611 push_data( data
, header
, header
->dbch_size
);
614 case WM_WINE_SETWINDOWPOS
:
615 push_data( data
, (WINDOWPOS
*)lparam
, sizeof(WINDOWPOS
) );
617 case WM_WINE_KEYBOARD_LL_HOOK
:
618 push_data( data
, (KBDLLHOOKSTRUCT
*)lparam
, sizeof(KBDLLHOOKSTRUCT
) );
620 case WM_WINE_MOUSE_LL_HOOK
:
621 push_data( data
, (MSLLHOOKSTRUCT
*)lparam
, sizeof(MSLLHOOKSTRUCT
) );
624 if (wparam
<= 1) return 0;
625 FIXME( "WM_NCPAINT hdc packing not supported yet\n" );
629 if (!wparam
) return 0;
632 /* these contain an HFONT */
635 /* these contain an HDC */
637 case WM_ICONERASEBKGND
:
638 case WM_CTLCOLORMSGBOX
:
639 case WM_CTLCOLOREDIT
:
640 case WM_CTLCOLORLISTBOX
:
643 case WM_CTLCOLORSCROLLBAR
:
644 case WM_CTLCOLORSTATIC
:
647 /* these contain an HGLOBAL */
648 case WM_PAINTCLIPBOARD
:
649 case WM_SIZECLIPBOARD
:
650 /* these contain HICON */
653 case WM_QUERYDRAGICON
:
654 case WM_QUERYPARKICON
:
655 /* these contain pointers */
657 case WM_QUERYDROPOBJECT
:
661 FIXME( "msg %x (%s) not supported yet\n", message
, SPY_GetMsgName(message
, hwnd
) );
669 /***********************************************************************
672 * Unpack a message received from another process.
674 static BOOL
unpack_message( HWND hwnd
, UINT message
, WPARAM
*wparam
, LPARAM
*lparam
,
675 void **buffer
, size_t size
)
684 CREATESTRUCTW
*cs
= *buffer
;
685 WCHAR
*str
= (WCHAR
*)(cs
+ 1);
686 if (size
< sizeof(*cs
)) return FALSE
;
688 if (HIWORD(cs
->lpszName
))
690 if (!check_string( str
, size
)) return FALSE
;
692 size
-= (strlenW(str
) + 1) * sizeof(WCHAR
);
693 str
+= strlenW(str
) + 1;
695 if (HIWORD(cs
->lpszClass
))
697 if (!check_string( str
, size
)) return FALSE
;
703 case WM_ASKCBFORMATNAME
:
704 if (!get_buffer_space( buffer
, (*wparam
* sizeof(WCHAR
)) )) return FALSE
;
706 case WM_WININICHANGE
:
707 if (!*lparam
) return TRUE
;
710 case WM_DEVMODECHANGE
:
715 if (!check_string( *buffer
, size
)) return FALSE
;
717 case WM_GETMINMAXINFO
:
718 minsize
= sizeof(MINMAXINFO
);
721 minsize
= sizeof(DRAWITEMSTRUCT
);
724 minsize
= sizeof(MEASUREITEMSTRUCT
);
727 minsize
= sizeof(DELETEITEMSTRUCT
);
730 minsize
= sizeof(COMPAREITEMSTRUCT
);
732 case WM_WINDOWPOSCHANGING
:
733 case WM_WINDOWPOSCHANGED
:
734 case WM_WINE_SETWINDOWPOS
:
735 minsize
= sizeof(WINDOWPOS
);
739 COPYDATASTRUCT
*cp
= *buffer
;
740 if (size
< sizeof(*cp
)) return FALSE
;
743 minsize
= sizeof(*cp
) + cp
->cbData
;
749 /* WM_NOTIFY cannot be sent across processes (MSDN) */
752 minsize
= sizeof(HELPINFO
);
754 case WM_STYLECHANGING
:
755 case WM_STYLECHANGED
:
756 minsize
= sizeof(STYLESTRUCT
);
759 if (!*wparam
) minsize
= sizeof(RECT
);
762 NCCALCSIZE_PARAMS
*nc
= *buffer
;
763 if (size
< sizeof(*nc
) + sizeof(*nc
->lppos
)) return FALSE
;
764 nc
->lppos
= (WINDOWPOS
*)(nc
+ 1);
768 if (!*lparam
) return TRUE
;
769 minsize
= sizeof(MSG
);
771 case SBM_SETSCROLLINFO
:
772 minsize
= sizeof(SCROLLINFO
);
774 case SBM_GETSCROLLINFO
:
775 if (!get_buffer_space( buffer
, sizeof(SCROLLINFO
))) return FALSE
;
777 case SBM_GETSCROLLBARINFO
:
778 if (!get_buffer_space( buffer
, sizeof(SCROLLBARINFO
))) return FALSE
;
783 if (*wparam
|| *lparam
)
785 if (!get_buffer_space( buffer
, 2*sizeof(DWORD
) )) return FALSE
;
786 if (*wparam
) *wparam
= (WPARAM
)*buffer
;
787 if (*lparam
) *lparam
= (LPARAM
)((DWORD
*)*buffer
+ 1);
792 case CB_GETDROPPEDCONTROLRECT
:
793 if (!get_buffer_space( buffer
, sizeof(RECT
) )) return FALSE
;
797 minsize
= sizeof(RECT
);
802 if (size
< sizeof(WORD
)) return FALSE
;
803 len
= *(WORD
*)*buffer
;
804 if (!get_buffer_space( buffer
, (len
+ 1) * sizeof(WCHAR
) )) return FALSE
;
805 *lparam
= (LPARAM
)*buffer
+ sizeof(WORD
); /* don't erase WORD at start of buffer */
810 if (!*wparam
) return TRUE
;
811 minsize
= *wparam
* sizeof(UINT
);
814 case CB_INSERTSTRING
:
816 case CB_FINDSTRINGEXACT
:
817 case CB_SELECTSTRING
:
819 case LB_INSERTSTRING
:
821 case LB_FINDSTRINGEXACT
:
822 case LB_SELECTSTRING
:
823 if (!*buffer
) return TRUE
;
824 if (!check_string( *buffer
, size
)) return FALSE
;
828 size
= sizeof(ULONG_PTR
);
829 if (combobox_has_strings( hwnd
))
830 size
= (SendMessageW( hwnd
, CB_GETLBTEXTLEN
, *wparam
, 0 ) + 1) * sizeof(WCHAR
);
831 if (!get_buffer_space( buffer
, size
)) return FALSE
;
836 size
= sizeof(ULONG_PTR
);
837 if (listbox_has_strings( hwnd
))
838 size
= (SendMessageW( hwnd
, LB_GETTEXTLEN
, *wparam
, 0 ) + 1) * sizeof(WCHAR
);
839 if (!get_buffer_space( buffer
, size
)) return FALSE
;
843 if (!get_buffer_space( buffer
, *wparam
* sizeof(UINT
) )) return FALSE
;
846 minsize
= sizeof(MDINEXTMENU
);
847 if (!get_buffer_space( buffer
, sizeof(MDINEXTMENU
) )) return FALSE
;
851 minsize
= sizeof(RECT
);
852 if (!get_buffer_space( buffer
, sizeof(RECT
) )) return FALSE
;
856 MDICREATESTRUCTW
*cs
= *buffer
;
857 WCHAR
*str
= (WCHAR
*)(cs
+ 1);
858 if (size
< sizeof(*cs
)) return FALSE
;
860 if (HIWORD(cs
->szTitle
))
862 if (!check_string( str
, size
)) return FALSE
;
864 size
-= (strlenW(str
) + 1) * sizeof(WCHAR
);
865 str
+= strlenW(str
) + 1;
867 if (HIWORD(cs
->szClass
))
869 if (!check_string( str
, size
)) return FALSE
;
874 case WM_MDIGETACTIVE
:
875 if (!*lparam
) return TRUE
;
876 if (!get_buffer_space( buffer
, sizeof(BOOL
) )) return FALSE
;
878 case WM_DEVICECHANGE
:
879 minsize
= sizeof(DEV_BROADCAST_HDR
);
881 case WM_WINE_KEYBOARD_LL_HOOK
:
882 minsize
= sizeof(KBDLLHOOKSTRUCT
);
884 case WM_WINE_MOUSE_LL_HOOK
:
885 minsize
= sizeof(MSLLHOOKSTRUCT
);
888 if (*wparam
<= 1) return TRUE
;
889 FIXME( "WM_NCPAINT hdc unpacking not supported\n" );
892 if (!*wparam
) return TRUE
;
895 /* these contain an HFONT */
898 /* these contain an HDC */
900 case WM_ICONERASEBKGND
:
901 case WM_CTLCOLORMSGBOX
:
902 case WM_CTLCOLOREDIT
:
903 case WM_CTLCOLORLISTBOX
:
906 case WM_CTLCOLORSCROLLBAR
:
907 case WM_CTLCOLORSTATIC
:
910 /* these contain an HGLOBAL */
911 case WM_PAINTCLIPBOARD
:
912 case WM_SIZECLIPBOARD
:
913 /* these contain HICON */
916 case WM_QUERYDRAGICON
:
917 case WM_QUERYPARKICON
:
918 /* these contain pointers */
920 case WM_QUERYDROPOBJECT
:
924 FIXME( "msg %x (%s) not supported yet\n", message
, SPY_GetMsgName(message
, hwnd
) );
928 return TRUE
; /* message doesn't need any unpacking */
931 /* default exit for most messages: check minsize and store buffer in lparam */
932 if (size
< minsize
) return FALSE
;
933 *lparam
= (LPARAM
)*buffer
;
938 /***********************************************************************
941 * Pack a reply to a message for sending to another process.
943 static void pack_reply( HWND hwnd
, UINT message
, WPARAM wparam
, LPARAM lparam
,
944 LRESULT res
, struct packed_message
*data
)
951 push_data( data
, (CREATESTRUCTW
*)lparam
, sizeof(CREATESTRUCTW
) );
956 push_data( data
, (WCHAR
*)lparam
, (res
+ 1) * sizeof(WCHAR
) );
958 case WM_GETMINMAXINFO
:
959 push_data( data
, (MINMAXINFO
*)lparam
, sizeof(MINMAXINFO
) );
962 push_data( data
, (MEASUREITEMSTRUCT
*)lparam
, sizeof(MEASUREITEMSTRUCT
) );
964 case WM_WINDOWPOSCHANGING
:
965 case WM_WINDOWPOSCHANGED
:
966 push_data( data
, (WINDOWPOS
*)lparam
, sizeof(WINDOWPOS
) );
969 if (lparam
) push_data( data
, (MSG
*)lparam
, sizeof(MSG
) );
971 case SBM_GETSCROLLINFO
:
972 push_data( data
, (SCROLLINFO
*)lparam
, sizeof(SCROLLINFO
) );
976 case CB_GETDROPPEDCONTROLRECT
:
979 push_data( data
, (RECT
*)lparam
, sizeof(RECT
) );
983 WORD
*ptr
= (WORD
*)lparam
;
984 push_data( data
, ptr
, ptr
[-1] * sizeof(WCHAR
) );
988 push_data( data
, (UINT
*)lparam
, wparam
* sizeof(UINT
) );
990 case WM_MDIGETACTIVE
:
991 if (lparam
) push_data( data
, (BOOL
*)lparam
, sizeof(BOOL
) );
995 push_data( data
, (RECT
*)lparam
, sizeof(RECT
) );
998 NCCALCSIZE_PARAMS
*nc
= (NCCALCSIZE_PARAMS
*)lparam
;
999 push_data( data
, nc
, sizeof(*nc
) );
1000 push_data( data
, nc
->lppos
, sizeof(*nc
->lppos
) );
1006 if (wparam
) push_data( data
, (DWORD
*)wparam
, sizeof(DWORD
) );
1007 if (lparam
) push_data( data
, (DWORD
*)lparam
, sizeof(DWORD
) );
1010 push_data( data
, (MDINEXTMENU
*)lparam
, sizeof(MDINEXTMENU
) );
1013 push_data( data
, (MDICREATESTRUCTW
*)lparam
, sizeof(MDICREATESTRUCTW
) );
1015 case WM_ASKCBFORMATNAME
:
1016 push_data( data
, (WCHAR
*)lparam
, (strlenW((WCHAR
*)lparam
) + 1) * sizeof(WCHAR
) );
1022 /***********************************************************************
1025 * Unpack a message reply received from another process.
1027 static void unpack_reply( HWND hwnd
, UINT message
, WPARAM wparam
, LPARAM lparam
,
1028 void *buffer
, size_t size
)
1035 CREATESTRUCTW
*cs
= (CREATESTRUCTW
*)lparam
;
1036 LPCWSTR name
= cs
->lpszName
, class = cs
->lpszClass
;
1037 memcpy( cs
, buffer
, min( sizeof(*cs
), size
));
1038 cs
->lpszName
= name
; /* restore the original pointers */
1039 cs
->lpszClass
= class;
1043 case WM_ASKCBFORMATNAME
:
1044 memcpy( (WCHAR
*)lparam
, buffer
, min( wparam
*sizeof(WCHAR
), size
));
1046 case WM_GETMINMAXINFO
:
1047 memcpy( (MINMAXINFO
*)lparam
, buffer
, min( sizeof(MINMAXINFO
), size
));
1049 case WM_MEASUREITEM
:
1050 memcpy( (MEASUREITEMSTRUCT
*)lparam
, buffer
, min( sizeof(MEASUREITEMSTRUCT
), size
));
1052 case WM_WINDOWPOSCHANGING
:
1053 case WM_WINDOWPOSCHANGED
:
1054 memcpy( (WINDOWPOS
*)lparam
, buffer
, min( sizeof(WINDOWPOS
), size
));
1057 if (lparam
) memcpy( (MSG
*)lparam
, buffer
, min( sizeof(MSG
), size
));
1059 case SBM_GETSCROLLINFO
:
1060 memcpy( (SCROLLINFO
*)lparam
, buffer
, min( sizeof(SCROLLINFO
), size
));
1062 case SBM_GETSCROLLBARINFO
:
1063 memcpy( (SCROLLBARINFO
*)lparam
, buffer
, min( sizeof(SCROLLBARINFO
), size
));
1066 case CB_GETDROPPEDCONTROLRECT
:
1067 case LB_GETITEMRECT
:
1070 memcpy( (RECT
*)lparam
, buffer
, min( sizeof(RECT
), size
));
1073 size
= min( size
, (size_t)*(WORD
*)lparam
);
1074 memcpy( (WCHAR
*)lparam
, buffer
, size
);
1076 case LB_GETSELITEMS
:
1077 memcpy( (UINT
*)lparam
, buffer
, min( wparam
*sizeof(UINT
), size
));
1081 memcpy( (WCHAR
*)lparam
, buffer
, size
);
1084 memcpy( (MDINEXTMENU
*)lparam
, buffer
, min( sizeof(MDINEXTMENU
), size
));
1086 case WM_MDIGETACTIVE
:
1087 if (lparam
) memcpy( (BOOL
*)lparam
, buffer
, min( sizeof(BOOL
), size
));
1091 memcpy( (RECT
*)lparam
, buffer
, min( sizeof(RECT
), size
));
1094 NCCALCSIZE_PARAMS
*nc
= (NCCALCSIZE_PARAMS
*)lparam
;
1095 WINDOWPOS
*wp
= nc
->lppos
;
1096 memcpy( nc
, buffer
, min( sizeof(*nc
), size
));
1097 if (size
> sizeof(*nc
))
1099 size
-= sizeof(*nc
);
1100 memcpy( wp
, (NCCALCSIZE_PARAMS
*)buffer
+ 1, min( sizeof(*wp
), size
));
1102 nc
->lppos
= wp
; /* restore the original pointer */
1110 memcpy( (DWORD
*)wparam
, buffer
, min( sizeof(DWORD
), size
));
1111 if (size
<= sizeof(DWORD
)) break;
1112 size
-= sizeof(DWORD
);
1113 buffer
= (DWORD
*)buffer
+ 1;
1115 if (lparam
) memcpy( (DWORD
*)lparam
, buffer
, min( sizeof(DWORD
), size
));
1119 MDICREATESTRUCTW
*cs
= (MDICREATESTRUCTW
*)lparam
;
1120 LPCWSTR title
= cs
->szTitle
, class = cs
->szClass
;
1121 memcpy( cs
, buffer
, min( sizeof(*cs
), size
));
1122 cs
->szTitle
= title
; /* restore the original pointers */
1123 cs
->szClass
= class;
1127 ERR( "should not happen: unexpected message %x\n", message
);
1133 /***********************************************************************
1136 * Send a reply to a sent message.
1138 static void reply_message( struct received_message_info
*info
, LRESULT result
, BOOL remove
)
1140 struct packed_message data
;
1141 int i
, replied
= info
->flags
& ISMEX_REPLIED
;
1143 if (info
->flags
& ISMEX_NOTIFY
) return; /* notify messages don't get replies */
1144 if (!remove
&& replied
) return; /* replied already */
1147 info
->flags
|= ISMEX_REPLIED
;
1149 if (info
->type
== MSG_OTHER_PROCESS
&& !replied
)
1151 pack_reply( info
->msg
.hwnd
, info
->msg
.message
, info
->msg
.wParam
,
1152 info
->msg
.lParam
, result
, &data
);
1155 SERVER_START_REQ( reply_message
)
1157 req
->result
= result
;
1158 req
->remove
= remove
;
1159 for (i
= 0; i
< data
.count
; i
++) wine_server_add_data( req
, data
.data
[i
], data
.size
[i
] );
1160 wine_server_call( req
);
1166 /***********************************************************************
1167 * handle_internal_message
1169 * Handle an internal Wine message instead of calling the window proc.
1171 static LRESULT
handle_internal_message( HWND hwnd
, UINT msg
, WPARAM wparam
, LPARAM lparam
)
1175 case WM_WINE_DESTROYWINDOW
:
1176 return WIN_DestroyWindow( hwnd
);
1177 case WM_WINE_SETWINDOWPOS
:
1178 if (hwnd
== GetDesktopWindow()) return 0;
1179 return USER_Driver
->pSetWindowPos( (WINDOWPOS
*)lparam
);
1180 case WM_WINE_SHOWWINDOW
:
1181 if (hwnd
== GetDesktopWindow()) return 0;
1182 return ShowWindow( hwnd
, wparam
);
1183 case WM_WINE_SETPARENT
:
1184 if (hwnd
== GetDesktopWindow()) return 0;
1185 return (LRESULT
)SetParent( hwnd
, (HWND
)wparam
);
1186 case WM_WINE_SETWINDOWLONG
:
1187 return (LRESULT
)SetWindowLongW( hwnd
, wparam
, lparam
);
1188 case WM_WINE_ENABLEWINDOW
:
1189 if (hwnd
== GetDesktopWindow()) return 0;
1190 return EnableWindow( hwnd
, wparam
);
1191 case WM_WINE_SETACTIVEWINDOW
:
1192 if (hwnd
== GetDesktopWindow()) return 0;
1193 return (LRESULT
)SetActiveWindow( (HWND
)wparam
);
1194 case WM_WINE_KEYBOARD_LL_HOOK
:
1195 return HOOK_CallHooks( WH_KEYBOARD_LL
, HC_ACTION
, wparam
, lparam
, TRUE
);
1196 case WM_WINE_MOUSE_LL_HOOK
:
1197 return HOOK_CallHooks( WH_MOUSE_LL
, HC_ACTION
, wparam
, lparam
, TRUE
);
1199 if (msg
>= WM_WINE_FIRST_DRIVER_MSG
&& msg
<= WM_WINE_LAST_DRIVER_MSG
)
1200 return USER_Driver
->pWindowMessage( hwnd
, msg
, wparam
, lparam
);
1201 FIXME( "unknown internal message %x\n", msg
);
1206 /* since the WM_DDE_ACK response to a WM_DDE_EXECUTE message should contain the handle
1207 * to the memory handle, we keep track (in the server side) of all pairs of handle
1208 * used (the client passes its value and the content of the memory handle), and
1209 * the server stored both values (the client, and the local one, created after the
1210 * content). When a ACK message is generated, the list of pair is searched for a
1211 * matching pair, so that the client memory handle can be returned.
1214 HGLOBAL client_hMem
;
1215 HGLOBAL server_hMem
;
1218 static struct DDE_pair
* dde_pairs
;
1219 static int dde_num_alloc
;
1220 static int dde_num_used
;
1222 static CRITICAL_SECTION dde_crst
;
1223 static CRITICAL_SECTION_DEBUG critsect_debug
=
1226 { &critsect_debug
.ProcessLocksList
, &critsect_debug
.ProcessLocksList
},
1227 0, 0, { (DWORD_PTR
)(__FILE__
": dde_crst") }
1229 static CRITICAL_SECTION dde_crst
= { &critsect_debug
, -1, 0, 0, 0, 0 };
1231 static BOOL
dde_add_pair(HGLOBAL chm
, HGLOBAL shm
)
1236 EnterCriticalSection(&dde_crst
);
1238 /* now remember the pair of hMem on both sides */
1239 if (dde_num_used
== dde_num_alloc
)
1241 struct DDE_pair
* tmp
;
1243 tmp
= HeapReAlloc( GetProcessHeap(), 0, dde_pairs
,
1244 (dde_num_alloc
+ GROWBY
) * sizeof(struct DDE_pair
));
1246 tmp
= HeapAlloc( GetProcessHeap(), 0,
1247 (dde_num_alloc
+ GROWBY
) * sizeof(struct DDE_pair
));
1251 LeaveCriticalSection(&dde_crst
);
1255 /* zero out newly allocated part */
1256 memset(&dde_pairs
[dde_num_alloc
], 0, GROWBY
* sizeof(struct DDE_pair
));
1257 dde_num_alloc
+= GROWBY
;
1260 for (i
= 0; i
< dde_num_alloc
; i
++)
1262 if (dde_pairs
[i
].server_hMem
== 0)
1264 dde_pairs
[i
].client_hMem
= chm
;
1265 dde_pairs
[i
].server_hMem
= shm
;
1270 LeaveCriticalSection(&dde_crst
);
1274 static HGLOBAL
dde_get_pair(HGLOBAL shm
)
1279 EnterCriticalSection(&dde_crst
);
1280 for (i
= 0; i
< dde_num_alloc
; i
++)
1282 if (dde_pairs
[i
].server_hMem
== shm
)
1284 /* free this pair */
1285 dde_pairs
[i
].server_hMem
= 0;
1287 ret
= dde_pairs
[i
].client_hMem
;
1291 LeaveCriticalSection(&dde_crst
);
1295 /***********************************************************************
1298 * Post a DDE message
1300 static BOOL
post_dde_message( struct packed_message
*data
, const struct send_message_info
*info
)
1304 UINT_PTR uiLo
, uiHi
;
1306 HGLOBAL hunlock
= 0;
1310 if (!UnpackDDElParam( info
->msg
, info
->lparam
, &uiLo
, &uiHi
))
1316 /* DDE messages which don't require packing are:
1325 /* uiHi should contain a hMem from WM_DDE_EXECUTE */
1326 HGLOBAL h
= dde_get_pair( (HANDLE
)uiHi
);
1329 /* send back the value of h on the other side */
1330 push_data( data
, &h
, sizeof(HGLOBAL
) );
1332 TRACE( "send dde-ack %x %08x => %p\n", uiLo
, uiHi
, h
);
1337 /* uiHi should contain either an atom or 0 */
1338 TRACE( "send dde-ack %x atom=%x\n", uiLo
, uiHi
);
1339 lp
= MAKELONG( uiLo
, uiHi
);
1348 size
= GlobalSize( (HGLOBAL
)uiLo
) ;
1349 if ((info
->msg
== WM_DDE_ADVISE
&& size
< sizeof(DDEADVISE
)) ||
1350 (info
->msg
== WM_DDE_DATA
&& size
< sizeof(DDEDATA
)) ||
1351 (info
->msg
== WM_DDE_POKE
&& size
< sizeof(DDEPOKE
))
1355 else if (info
->msg
!= WM_DDE_DATA
) return FALSE
;
1360 if ((ptr
= GlobalLock( (HGLOBAL
)uiLo
) ))
1362 DDEDATA
*dde_data
= (DDEDATA
*)ptr
;
1363 TRACE("unused %d, fResponse %d, fRelease %d, fDeferUpd %d, fAckReq %d, cfFormat %d\n",
1364 dde_data
->unused
, dde_data
->fResponse
, dde_data
->fRelease
,
1365 dde_data
->reserved
, dde_data
->fAckReq
, dde_data
->cfFormat
);
1366 push_data( data
, ptr
, size
);
1367 hunlock
= (HGLOBAL
)uiLo
;
1370 TRACE( "send ddepack %u %x\n", size
, uiHi
);
1372 case WM_DDE_EXECUTE
:
1375 if ((ptr
= GlobalLock( (HGLOBAL
)info
->lparam
) ))
1377 push_data(data
, ptr
, GlobalSize( (HGLOBAL
)info
->lparam
));
1378 /* so that the other side can send it back on ACK */
1380 hunlock
= (HGLOBAL
)info
->lparam
;
1385 SERVER_START_REQ( send_message
)
1387 req
->id
= info
->dest_tid
;
1388 req
->type
= info
->type
;
1390 req
->win
= info
->hwnd
;
1391 req
->msg
= info
->msg
;
1392 req
->wparam
= info
->wparam
;
1394 req
->time
= GetCurrentTime();
1396 for (i
= 0; i
< data
->count
; i
++)
1397 wine_server_add_data( req
, data
->data
[i
], data
->size
[i
] );
1398 if ((res
= wine_server_call( req
)))
1400 if (res
== STATUS_INVALID_PARAMETER
)
1401 /* FIXME: find a STATUS_ value for this one */
1402 SetLastError( ERROR_INVALID_THREAD_ID
);
1404 SetLastError( RtlNtStatusToDosError(res
) );
1407 FreeDDElParam(info
->msg
, info
->lparam
);
1410 if (hunlock
) GlobalUnlock(hunlock
);
1415 /***********************************************************************
1416 * unpack_dde_message
1418 * Unpack a posted DDE message received from another process.
1420 static BOOL
unpack_dde_message( HWND hwnd
, UINT message
, WPARAM
*wparam
, LPARAM
*lparam
,
1421 void **buffer
, size_t size
)
1423 UINT_PTR uiLo
, uiHi
;
1432 /* hMem is being passed */
1433 if (size
!= sizeof(HGLOBAL
)) return FALSE
;
1434 if (!buffer
|| !*buffer
) return FALSE
;
1436 memcpy( &hMem
, *buffer
, size
);
1437 uiHi
= (UINT_PTR
)hMem
;
1438 TRACE("recv dde-ack %x mem=%x[%lx]\n", uiLo
, uiHi
, GlobalSize( hMem
));
1442 uiLo
= LOWORD( *lparam
);
1443 uiHi
= HIWORD( *lparam
);
1444 TRACE("recv dde-ack %x atom=%x\n", uiLo
, uiHi
);
1446 *lparam
= PackDDElParam( WM_DDE_ACK
, uiLo
, uiHi
);
1451 if ((!buffer
|| !*buffer
) && message
!= WM_DDE_DATA
) return FALSE
;
1455 if (!(hMem
= GlobalAlloc( GMEM_MOVEABLE
|GMEM_DDESHARE
, size
)))
1457 if ((ptr
= GlobalLock( hMem
)))
1459 memcpy( ptr
, *buffer
, size
);
1460 GlobalUnlock( hMem
);
1468 uiLo
= (UINT_PTR
)hMem
;
1470 *lparam
= PackDDElParam( message
, uiLo
, uiHi
);
1472 case WM_DDE_EXECUTE
:
1475 if (!buffer
|| !*buffer
) return FALSE
;
1476 if (!(hMem
= GlobalAlloc( GMEM_MOVEABLE
|GMEM_DDESHARE
, size
))) return FALSE
;
1477 if ((ptr
= GlobalLock( hMem
)))
1479 memcpy( ptr
, *buffer
, size
);
1480 GlobalUnlock( hMem
);
1481 TRACE( "exec: pairing c=%08lx s=%08lx\n", *lparam
, (DWORD
)hMem
);
1482 if (!dde_add_pair( (HGLOBAL
)*lparam
, hMem
))
1493 } else return FALSE
;
1494 *lparam
= (LPARAM
)hMem
;
1500 /***********************************************************************
1503 * Call a window procedure and the corresponding hooks.
1505 static LRESULT
call_window_proc( HWND hwnd
, UINT msg
, WPARAM wparam
, LPARAM lparam
,
1506 BOOL unicode
, BOOL same_thread
)
1508 struct user_thread_info
*thread_info
= get_user_thread_info();
1512 CWPRETSTRUCT cwpret
;
1514 if (thread_info
->recursion_count
> MAX_SENDMSG_RECURSION
) return 0;
1515 thread_info
->recursion_count
++;
1517 if (msg
& 0x80000000)
1519 result
= handle_internal_message( hwnd
, msg
, wparam
, lparam
);
1523 /* first the WH_CALLWNDPROC hook */
1524 hwnd
= WIN_GetFullHandle( hwnd
);
1525 cwp
.lParam
= lparam
;
1526 cwp
.wParam
= wparam
;
1529 HOOK_CallHooks( WH_CALLWNDPROC
, HC_ACTION
, same_thread
, (LPARAM
)&cwp
, unicode
);
1531 /* now call the window procedure */
1534 if (!(winproc
= (WNDPROC
)GetWindowLongPtrW( hwnd
, GWLP_WNDPROC
))) goto done
;
1535 result
= CallWindowProcW( winproc
, hwnd
, msg
, wparam
, lparam
);
1539 if (!(winproc
= (WNDPROC
)GetWindowLongPtrA( hwnd
, GWLP_WNDPROC
))) goto done
;
1540 result
= CallWindowProcA( winproc
, hwnd
, msg
, wparam
, lparam
);
1543 /* and finally the WH_CALLWNDPROCRET hook */
1544 cwpret
.lResult
= result
;
1545 cwpret
.lParam
= lparam
;
1546 cwpret
.wParam
= wparam
;
1547 cwpret
.message
= msg
;
1549 HOOK_CallHooks( WH_CALLWNDPROCRET
, HC_ACTION
, same_thread
, (LPARAM
)&cwpret
, unicode
);
1551 thread_info
->recursion_count
--;
1556 /***********************************************************************
1557 * send_parent_notify
1559 * Send a WM_PARENTNOTIFY to all ancestors of the given window, unless
1560 * the window has the WS_EX_NOPARENTNOTIFY style.
1562 static void send_parent_notify( HWND hwnd
, WORD event
, WORD idChild
, POINT pt
)
1564 /* pt has to be in the client coordinates of the parent window */
1565 MapWindowPoints( 0, hwnd
, &pt
, 1 );
1570 if (!(GetWindowLongW( hwnd
, GWL_STYLE
) & WS_CHILD
)) break;
1571 if (GetWindowLongW( hwnd
, GWL_EXSTYLE
) & WS_EX_NOPARENTNOTIFY
) break;
1572 if (!(parent
= GetParent(hwnd
))) break;
1573 if (parent
== GetDesktopWindow()) break;
1574 MapWindowPoints( hwnd
, parent
, &pt
, 1 );
1576 SendMessageW( hwnd
, WM_PARENTNOTIFY
,
1577 MAKEWPARAM( event
, idChild
), MAKELPARAM( pt
.x
, pt
.y
) );
1582 /***********************************************************************
1583 * accept_hardware_message
1585 * Tell the server we have passed the message to the app
1586 * (even though we may end up dropping it later on)
1588 static void accept_hardware_message( UINT hw_id
, BOOL remove
, HWND new_hwnd
)
1590 SERVER_START_REQ( accept_hardware_message
)
1593 req
->remove
= remove
;
1594 req
->new_win
= new_hwnd
;
1595 if (wine_server_call( req
))
1596 FIXME("Failed to reply to MSG_HARDWARE message. Message may not be removed from queue.\n");
1602 /***********************************************************************
1603 * process_keyboard_message
1605 * returns TRUE if the contents of 'msg' should be passed to the application
1607 static BOOL
process_keyboard_message( MSG
*msg
, UINT hw_id
, HWND hwnd_filter
,
1608 UINT first
, UINT last
, BOOL remove
)
1612 /* FIXME: is this really the right place for this hook? */
1613 event
.message
= msg
->message
;
1614 event
.hwnd
= msg
->hwnd
;
1615 event
.time
= msg
->time
;
1616 event
.paramL
= (msg
->wParam
& 0xFF) | (HIWORD(msg
->lParam
) << 8);
1617 event
.paramH
= msg
->lParam
& 0x7FFF;
1618 if (HIWORD(msg
->lParam
) & 0x0100) event
.paramH
|= 0x8000; /* special_key - bit */
1619 HOOK_CallHooks( WH_JOURNALRECORD
, HC_ACTION
, 0, (LPARAM
)&event
, TRUE
);
1621 /* check message filters */
1622 if (msg
->message
< first
|| msg
->message
> last
) return FALSE
;
1623 if (!check_hwnd_filter( msg
, hwnd_filter
)) return FALSE
;
1627 /* Handle F1 key by sending out WM_HELP message */
1628 if ((msg
->message
== WM_KEYUP
) &&
1629 (msg
->wParam
== VK_F1
) &&
1630 (msg
->hwnd
!= GetDesktopWindow()) &&
1631 !MENU_IsMenuActive())
1634 hi
.cbSize
= sizeof(HELPINFO
);
1635 hi
.iContextType
= HELPINFO_WINDOW
;
1636 hi
.iCtrlId
= GetWindowLongPtrA( msg
->hwnd
, GWLP_ID
);
1637 hi
.hItemHandle
= msg
->hwnd
;
1638 hi
.dwContextId
= GetWindowContextHelpId( msg
->hwnd
);
1639 hi
.MousePos
= msg
->pt
;
1640 SendMessageW( msg
->hwnd
, WM_HELP
, 0, (LPARAM
)&hi
);
1644 if (HOOK_CallHooks( WH_KEYBOARD
, remove
? HC_ACTION
: HC_NOREMOVE
,
1645 LOWORD(msg
->wParam
), msg
->lParam
, TRUE
))
1647 /* skip this message */
1648 HOOK_CallHooks( WH_CBT
, HCBT_KEYSKIPPED
, LOWORD(msg
->wParam
), msg
->lParam
, TRUE
);
1649 accept_hardware_message( hw_id
, TRUE
, 0 );
1652 accept_hardware_message( hw_id
, remove
, 0 );
1657 /***********************************************************************
1658 * process_mouse_message
1660 * returns TRUE if the contents of 'msg' should be passed to the application
1662 static BOOL
process_mouse_message( MSG
*msg
, UINT hw_id
, ULONG_PTR extra_info
, HWND hwnd_filter
,
1663 UINT first
, UINT last
, BOOL remove
)
1672 MOUSEHOOKSTRUCT hook
;
1675 /* find the window to dispatch this mouse message to */
1677 GetGUIThreadInfo( GetCurrentThreadId(), &info
);
1678 if (info
.hwndCapture
)
1681 msg
->hwnd
= info
.hwndCapture
;
1685 msg
->hwnd
= WINPOS_WindowFromPoint( msg
->hwnd
, msg
->pt
, &hittest
);
1688 if (!msg
->hwnd
|| !WIN_IsCurrentThread( msg
->hwnd
))
1690 accept_hardware_message( hw_id
, TRUE
, msg
->hwnd
);
1694 /* FIXME: is this really the right place for this hook? */
1695 event
.message
= msg
->message
;
1696 event
.time
= msg
->time
;
1697 event
.hwnd
= msg
->hwnd
;
1698 event
.paramL
= msg
->pt
.x
;
1699 event
.paramH
= msg
->pt
.y
;
1700 HOOK_CallHooks( WH_JOURNALRECORD
, HC_ACTION
, 0, (LPARAM
)&event
, TRUE
);
1702 if (!check_hwnd_filter( msg
, hwnd_filter
)) return FALSE
;
1705 message
= msg
->message
;
1706 /* Note: windows has no concept of a non-client wheel message */
1707 if (message
!= WM_MOUSEWHEEL
)
1709 if (hittest
!= HTCLIENT
)
1711 message
+= WM_NCMOUSEMOVE
- WM_MOUSEMOVE
;
1712 msg
->wParam
= hittest
;
1716 /* coordinates don't get translated while tracking a menu */
1717 /* FIXME: should differentiate popups and top-level menus */
1718 if (!(info
.flags
& GUI_INMENUMODE
))
1719 ScreenToClient( msg
->hwnd
, &pt
);
1722 msg
->lParam
= MAKELONG( pt
.x
, pt
.y
);
1724 /* translate double clicks */
1726 if ((msg
->message
== WM_LBUTTONDOWN
) ||
1727 (msg
->message
== WM_RBUTTONDOWN
) ||
1728 (msg
->message
== WM_MBUTTONDOWN
) ||
1729 (msg
->message
== WM_XBUTTONDOWN
))
1731 BOOL update
= remove
;
1733 /* translate double clicks -
1734 * note that ...MOUSEMOVEs can slip in between
1735 * ...BUTTONDOWN and ...BUTTONDBLCLK messages */
1737 if ((info
.flags
& (GUI_INMENUMODE
|GUI_INMOVESIZE
)) ||
1738 hittest
!= HTCLIENT
||
1739 (GetClassLongA( msg
->hwnd
, GCL_STYLE
) & CS_DBLCLKS
))
1741 if ((msg
->message
== clk_msg
.message
) &&
1742 (msg
->hwnd
== clk_msg
.hwnd
) &&
1743 (msg
->wParam
== clk_msg
.wParam
) &&
1744 (msg
->time
- clk_msg
.time
< GetDoubleClickTime()) &&
1745 (abs(msg
->pt
.x
- clk_msg
.pt
.x
) < GetSystemMetrics(SM_CXDOUBLECLK
)/2) &&
1746 (abs(msg
->pt
.y
- clk_msg
.pt
.y
) < GetSystemMetrics(SM_CYDOUBLECLK
)/2))
1748 message
+= (WM_LBUTTONDBLCLK
- WM_LBUTTONDOWN
);
1751 clk_msg
.message
= 0; /* clear the double click conditions */
1756 if (message
< first
|| message
> last
) return FALSE
;
1757 /* update static double click conditions */
1758 if (update
) clk_msg
= *msg
;
1762 if (message
< first
|| message
> last
) return FALSE
;
1765 /* message is accepted now (but may still get dropped) */
1768 hook
.hwnd
= msg
->hwnd
;
1769 hook
.wHitTestCode
= hittest
;
1770 hook
.dwExtraInfo
= extra_info
;
1771 if (HOOK_CallHooks( WH_MOUSE
, remove
? HC_ACTION
: HC_NOREMOVE
,
1772 message
, (LPARAM
)&hook
, TRUE
))
1775 hook
.hwnd
= msg
->hwnd
;
1776 hook
.wHitTestCode
= hittest
;
1777 hook
.dwExtraInfo
= extra_info
;
1778 HOOK_CallHooks( WH_CBT
, HCBT_CLICKSKIPPED
, message
, (LPARAM
)&hook
, TRUE
);
1779 accept_hardware_message( hw_id
, TRUE
, 0 );
1783 if ((hittest
== HTERROR
) || (hittest
== HTNOWHERE
))
1785 SendMessageW( msg
->hwnd
, WM_SETCURSOR
, (WPARAM
)msg
->hwnd
,
1786 MAKELONG( hittest
, msg
->message
));
1787 accept_hardware_message( hw_id
, TRUE
, 0 );
1791 accept_hardware_message( hw_id
, remove
, 0 );
1793 if (!remove
|| info
.hwndCapture
)
1795 msg
->message
= message
;
1801 if ((msg
->message
== WM_LBUTTONDOWN
) ||
1802 (msg
->message
== WM_RBUTTONDOWN
) ||
1803 (msg
->message
== WM_MBUTTONDOWN
) ||
1804 (msg
->message
== WM_XBUTTONDOWN
))
1806 /* Send the WM_PARENTNOTIFY,
1807 * note that even for double/nonclient clicks
1808 * notification message is still WM_L/M/RBUTTONDOWN.
1810 send_parent_notify( msg
->hwnd
, msg
->message
, 0, msg
->pt
);
1812 /* Activate the window if needed */
1814 if (msg
->hwnd
!= info
.hwndActive
)
1816 HWND hwndTop
= msg
->hwnd
;
1819 if ((GetWindowLongW( hwndTop
, GWL_STYLE
) & (WS_POPUP
|WS_CHILD
)) != WS_CHILD
) break;
1820 hwndTop
= GetParent( hwndTop
);
1823 if (hwndTop
&& hwndTop
!= GetDesktopWindow())
1825 LONG ret
= SendMessageW( msg
->hwnd
, WM_MOUSEACTIVATE
, (WPARAM
)hwndTop
,
1826 MAKELONG( hittest
, msg
->message
) );
1829 case MA_NOACTIVATEANDEAT
:
1834 case MA_ACTIVATEANDEAT
:
1839 if (!FOCUS_MouseActivate( hwndTop
)) eatMsg
= TRUE
;
1842 WARN( "unknown WM_MOUSEACTIVATE code %ld\n", ret
);
1849 /* send the WM_SETCURSOR message */
1851 /* Windows sends the normal mouse message as the message parameter
1852 in the WM_SETCURSOR message even if it's non-client mouse message */
1853 SendMessageW( msg
->hwnd
, WM_SETCURSOR
, (WPARAM
)msg
->hwnd
, MAKELONG( hittest
, msg
->message
));
1855 msg
->message
= message
;
1860 /***********************************************************************
1861 * process_hardware_message
1863 * Process a hardware message; return TRUE if message should be passed on to the app
1865 static BOOL
process_hardware_message( MSG
*msg
, UINT hw_id
, ULONG_PTR extra_info
, HWND hwnd_filter
,
1866 UINT first
, UINT last
, BOOL remove
)
1868 if (is_keyboard_message( msg
->message
))
1869 return process_keyboard_message( msg
, hw_id
, hwnd_filter
, first
, last
, remove
);
1871 if (is_mouse_message( msg
->message
))
1872 return process_mouse_message( msg
, hw_id
, extra_info
, hwnd_filter
, first
, last
, remove
);
1874 ERR( "unknown message type %x\n", msg
->message
);
1879 /***********************************************************************
1880 * call_sendmsg_callback
1882 * Call the callback function of SendMessageCallback.
1884 static inline void call_sendmsg_callback( SENDASYNCPROC callback
, HWND hwnd
, UINT msg
,
1885 ULONG_PTR data
, LRESULT result
)
1887 if (TRACE_ON(relay
))
1888 DPRINTF( "%04lx:Call message callback %p (hwnd=%p,msg=%s,data=%08lx,result=%08lx)\n",
1889 GetCurrentThreadId(), callback
, hwnd
, SPY_GetMsgName( msg
, hwnd
),
1891 callback( hwnd
, msg
, data
, result
);
1892 if (TRACE_ON(relay
))
1893 DPRINTF( "%04lx:Ret message callback %p (hwnd=%p,msg=%s,data=%08lx,result=%08lx)\n",
1894 GetCurrentThreadId(), callback
, hwnd
, SPY_GetMsgName( msg
, hwnd
),
1899 /***********************************************************************
1902 * Retrieve the hook procedure real value for a module-relative proc
1904 static void *get_hook_proc( void *proc
, const WCHAR
*module
)
1908 if (!(mod
= GetModuleHandleW(module
)))
1910 TRACE( "loading %s\n", debugstr_w(module
) );
1911 /* FIXME: the library will never be freed */
1912 if (!(mod
= LoadLibraryW(module
))) return NULL
;
1914 return (char *)mod
+ (ULONG_PTR
)proc
;
1918 /***********************************************************************
1921 * Peek for a message matching the given parameters. Return FALSE if none available.
1922 * All pending sent messages are processed before returning.
1924 static BOOL
peek_message( MSG
*msg
, HWND hwnd
, UINT first
, UINT last
, int flags
)
1927 ULONG_PTR extra_info
= 0;
1928 struct user_thread_info
*thread_info
= get_user_thread_info();
1929 struct received_message_info info
, *old_info
;
1930 unsigned int hw_id
= 0; /* id of previous hardware message */
1932 if (!first
&& !last
) last
= ~0;
1937 void *buffer
= NULL
;
1938 size_t size
= 0, buffer_size
= 0;
1940 do /* loop while buffer is too small */
1942 if (buffer_size
&& !(buffer
= HeapAlloc( GetProcessHeap(), 0, buffer_size
)))
1944 SERVER_START_REQ( get_message
)
1947 req
->get_win
= hwnd
;
1948 req
->get_first
= first
;
1949 req
->get_last
= last
;
1951 if (buffer_size
) wine_server_set_reply( req
, buffer
, buffer_size
);
1952 if (!(res
= wine_server_call( req
)))
1954 size
= wine_server_reply_size( reply
);
1955 info
.type
= reply
->type
;
1956 info
.msg
.hwnd
= reply
->win
;
1957 info
.msg
.message
= reply
->msg
;
1958 info
.msg
.wParam
= reply
->wparam
;
1959 info
.msg
.lParam
= reply
->lparam
;
1960 info
.msg
.time
= reply
->time
;
1961 info
.msg
.pt
.x
= reply
->x
;
1962 info
.msg
.pt
.y
= reply
->y
;
1963 info
.hook
= reply
->hook
;
1964 info
.hook_proc
= reply
->hook_proc
;
1965 hw_id
= reply
->hw_id
;
1966 extra_info
= reply
->info
;
1967 thread_info
->active_hooks
= reply
->active_hooks
;
1971 HeapFree( GetProcessHeap(), 0, buffer
);
1972 buffer_size
= reply
->total
;
1976 } while (res
== STATUS_BUFFER_OVERFLOW
);
1978 if (res
) return FALSE
;
1980 TRACE( "got type %d msg %x (%s) hwnd %p wp %x lp %lx\n",
1981 info
.type
, info
.msg
.message
,
1982 (info
.type
== MSG_WINEVENT
) ? "MSG_WINEVENT" : SPY_GetMsgName(info
.msg
.message
, info
.msg
.hwnd
),
1983 info
.msg
.hwnd
, info
.msg
.wParam
, info
.msg
.lParam
);
1989 info
.flags
= ISMEX_SEND
;
1992 info
.flags
= ISMEX_NOTIFY
;
1995 info
.flags
= ISMEX_CALLBACK
;
1997 case MSG_CALLBACK_RESULT
:
1998 call_sendmsg_callback( (SENDASYNCPROC
)info
.msg
.wParam
, info
.msg
.hwnd
,
1999 info
.msg
.message
, extra_info
, info
.msg
.lParam
);
2004 WCHAR module
[MAX_PATH
];
2005 size
= min( size
, (MAX_PATH
- 1) * sizeof(WCHAR
) );
2006 memcpy( module
, buffer
, size
);
2007 module
[size
/ sizeof(WCHAR
)] = 0;
2008 if (!(info
.hook_proc
= get_hook_proc( info
.hook_proc
, module
)))
2010 ERR( "invalid winevent hook module name %s\n", debugstr_w(module
) );
2014 if (TRACE_ON(relay
))
2015 DPRINTF( "%04lx:Call winevent proc %p (hook=%p,event=%x,hwnd=%p,object_id=%x,child_id=%lx,tid=%04lx,time=%lx)\n",
2016 GetCurrentThreadId(), info
.hook_proc
,
2017 info
.hook
, info
.msg
.message
, info
.msg
.hwnd
, info
.msg
.wParam
,
2018 info
.msg
.lParam
, extra_info
, info
.msg
.time
);
2020 info
.hook_proc( info
.hook
, info
.msg
.message
, info
.msg
.hwnd
, info
.msg
.wParam
,
2021 info
.msg
.lParam
, extra_info
, info
.msg
.time
);
2023 if (TRACE_ON(relay
))
2024 DPRINTF( "%04lx:Ret winevent proc %p (hook=%p,event=%x,hwnd=%p,object_id=%x,child_id=%lx,tid=%04lx,time=%lx)\n",
2025 GetCurrentThreadId(), info
.hook_proc
,
2026 info
.hook
, info
.msg
.message
, info
.msg
.hwnd
, info
.msg
.wParam
,
2027 info
.msg
.lParam
, extra_info
, info
.msg
.time
);
2029 case MSG_OTHER_PROCESS
:
2030 info
.flags
= ISMEX_SEND
;
2031 if (!unpack_message( info
.msg
.hwnd
, info
.msg
.message
, &info
.msg
.wParam
,
2032 &info
.msg
.lParam
, &buffer
, size
))
2035 reply_message( &info
, 0, TRUE
);
2040 if (!process_hardware_message( &info
.msg
, hw_id
, extra_info
,
2041 hwnd
, first
, last
, flags
& GET_MSG_REMOVE
))
2043 TRACE("dropping msg %x\n", info
.msg
.message
);
2044 goto next
; /* ignore it */
2046 thread_info
->GetMessagePosVal
= MAKELONG( info
.msg
.pt
.x
, info
.msg
.pt
.y
);
2049 thread_info
->GetMessageExtraInfoVal
= extra_info
;
2050 if (info
.msg
.message
>= WM_DDE_FIRST
&& info
.msg
.message
<= WM_DDE_LAST
)
2052 if (!unpack_dde_message( info
.msg
.hwnd
, info
.msg
.message
, &info
.msg
.wParam
,
2053 &info
.msg
.lParam
, &buffer
, size
))
2054 goto next
; /* ignore it */
2057 HeapFree( GetProcessHeap(), 0, buffer
);
2061 /* if we get here, we have a sent message; call the window procedure */
2062 old_info
= thread_info
->receive_info
;
2063 thread_info
->receive_info
= &info
;
2064 result
= call_window_proc( info
.msg
.hwnd
, info
.msg
.message
, info
.msg
.wParam
,
2065 info
.msg
.lParam
, (info
.type
!= MSG_ASCII
), FALSE
);
2066 reply_message( &info
, result
, TRUE
);
2067 thread_info
->receive_info
= old_info
;
2069 HeapFree( GetProcessHeap(), 0, buffer
);
2074 /***********************************************************************
2075 * process_sent_messages
2077 * Process all pending sent messages.
2079 inline static void process_sent_messages(void)
2082 peek_message( &msg
, 0, 0, 0, GET_MSG_REMOVE
| GET_MSG_SENT_ONLY
);
2086 /***********************************************************************
2087 * get_server_queue_handle
2089 * Get a handle to the server message queue for the current thread.
2091 static HANDLE
get_server_queue_handle(void)
2093 struct user_thread_info
*thread_info
= get_user_thread_info();
2096 if (!(ret
= thread_info
->server_queue
))
2098 SERVER_START_REQ( get_msg_queue
)
2100 wine_server_call( req
);
2101 ret
= reply
->handle
;
2104 thread_info
->server_queue
= ret
;
2105 if (!ret
) ERR( "Cannot get server thread queue\n" );
2111 /***********************************************************************
2112 * wait_message_reply
2114 * Wait until a sent message gets replied to.
2116 static void wait_message_reply( UINT flags
)
2118 HANDLE server_queue
= get_server_queue_handle();
2122 unsigned int wake_bits
= 0, changed_bits
= 0;
2125 SERVER_START_REQ( set_queue_mask
)
2127 req
->wake_mask
= QS_SMRESULT
| ((flags
& SMTO_BLOCK
) ? 0 : QS_SENDMESSAGE
);
2128 req
->changed_mask
= req
->wake_mask
;
2130 if (!wine_server_call( req
))
2132 wake_bits
= reply
->wake_bits
;
2133 changed_bits
= reply
->changed_bits
;
2138 if (wake_bits
& QS_SMRESULT
) return; /* got a result */
2139 if (wake_bits
& QS_SENDMESSAGE
)
2141 /* Process the sent message immediately */
2142 process_sent_messages();
2146 /* now wait for it */
2148 ReleaseThunkLock( &dwlc
);
2149 res
= USER_Driver
->pMsgWaitForMultipleObjectsEx( 1, &server_queue
,
2150 INFINITE
, QS_SENDMESSAGE
, 0 );
2151 if (dwlc
) RestoreThunkLock( dwlc
);
2155 /***********************************************************************
2156 * put_message_in_queue
2158 * Put a sent message into the destination queue.
2159 * For inter-process message, reply_size is set to expected size of reply data.
2161 static BOOL
put_message_in_queue( const struct send_message_info
*info
, size_t *reply_size
)
2163 struct packed_message data
;
2167 /* Check for INFINITE timeout for compatibility with Win9x,
2168 * although Windows >= NT does not do so
2170 if (info
->type
!= MSG_NOTIFY
&&
2171 info
->type
!= MSG_CALLBACK
&&
2172 info
->type
!= MSG_POSTED
&&
2173 info
->timeout
!= INFINITE
)
2174 timeout
= info
->timeout
;
2177 if (info
->type
== MSG_OTHER_PROCESS
)
2179 *reply_size
= pack_message( info
->hwnd
, info
->msg
, info
->wparam
, info
->lparam
, &data
);
2180 if (data
.count
== -1)
2182 WARN( "cannot pack message %x\n", info
->msg
);
2186 else if (info
->type
== MSG_POSTED
&& info
->msg
>= WM_DDE_FIRST
&& info
->msg
<= WM_DDE_LAST
)
2188 return post_dde_message( &data
, info
);
2191 SERVER_START_REQ( send_message
)
2193 req
->id
= info
->dest_tid
;
2194 req
->type
= info
->type
;
2196 req
->win
= info
->hwnd
;
2197 req
->msg
= info
->msg
;
2198 req
->wparam
= info
->wparam
;
2199 req
->lparam
= info
->lparam
;
2200 req
->time
= GetCurrentTime();
2201 req
->timeout
= timeout
;
2203 if (info
->type
== MSG_CALLBACK
)
2205 req
->callback
= info
->callback
;
2206 req
->info
= info
->data
;
2209 if (info
->flags
& SMTO_ABORTIFHUNG
) req
->flags
|= SEND_MSG_ABORT_IF_HUNG
;
2210 for (i
= 0; i
< data
.count
; i
++) wine_server_add_data( req
, data
.data
[i
], data
.size
[i
] );
2211 if ((res
= wine_server_call( req
)))
2213 if (res
== STATUS_INVALID_PARAMETER
)
2214 /* FIXME: find a STATUS_ value for this one */
2215 SetLastError( ERROR_INVALID_THREAD_ID
);
2217 SetLastError( RtlNtStatusToDosError(res
) );
2225 /***********************************************************************
2228 * Retrieve a message reply from the server.
2230 static LRESULT
retrieve_reply( const struct send_message_info
*info
,
2231 size_t reply_size
, LRESULT
*result
)
2234 void *reply_data
= NULL
;
2238 if (!(reply_data
= HeapAlloc( GetProcessHeap(), 0, reply_size
)))
2240 WARN( "no memory for reply, will be truncated\n" );
2244 SERVER_START_REQ( get_message_reply
)
2247 if (reply_size
) wine_server_set_reply( req
, reply_data
, reply_size
);
2248 if (!(status
= wine_server_call( req
))) *result
= reply
->result
;
2249 reply_size
= wine_server_reply_size( reply
);
2252 if (!status
&& reply_size
)
2253 unpack_reply( info
->hwnd
, info
->msg
, info
->wparam
, info
->lparam
, reply_data
, reply_size
);
2255 HeapFree( GetProcessHeap(), 0, reply_data
);
2257 TRACE( "hwnd %p msg %x (%s) wp %x lp %lx got reply %lx (err=%ld)\n",
2258 info
->hwnd
, info
->msg
, SPY_GetMsgName(info
->msg
, info
->hwnd
), info
->wparam
,
2259 info
->lparam
, *result
, status
);
2261 /* MSDN states that last error is 0 on timeout, but at least NT4 returns ERROR_TIMEOUT */
2262 if (status
) SetLastError( RtlNtStatusToDosError(status
) );
2267 /***********************************************************************
2268 * send_inter_thread_message
2270 static LRESULT
send_inter_thread_message( const struct send_message_info
*info
, LRESULT
*res_ptr
)
2272 size_t reply_size
= 0;
2274 TRACE( "hwnd %p msg %x (%s) wp %x lp %lx\n",
2275 info
->hwnd
, info
->msg
, SPY_GetMsgName(info
->msg
, info
->hwnd
), info
->wparam
, info
->lparam
);
2277 USER_CheckNotLock();
2279 if (!put_message_in_queue( info
, &reply_size
)) return 0;
2281 /* there's no reply to wait for on notify/callback messages */
2282 if (info
->type
== MSG_NOTIFY
|| info
->type
== MSG_CALLBACK
) return 1;
2284 wait_message_reply( info
->flags
);
2285 return retrieve_reply( info
, reply_size
, res_ptr
);
2289 /***********************************************************************
2290 * MSG_SendInternalMessageTimeout
2292 * Same as SendMessageTimeoutW but sends the message to a specific thread
2293 * without requiring a window handle. Only works for internal Wine messages.
2295 LRESULT
MSG_SendInternalMessageTimeout( DWORD dest_pid
, DWORD dest_tid
,
2296 UINT msg
, WPARAM wparam
, LPARAM lparam
,
2297 UINT flags
, UINT timeout
, PDWORD_PTR res_ptr
)
2299 struct send_message_info info
;
2300 LRESULT ret
, result
;
2302 assert( msg
& 0x80000000 ); /* must be an internal Wine message */
2304 info
.type
= MSG_UNICODE
;
2305 info
.dest_tid
= dest_tid
;
2308 info
.wparam
= wparam
;
2309 info
.lparam
= lparam
;
2311 info
.timeout
= timeout
;
2313 if (USER_IsExitingThread( dest_tid
)) return 0;
2315 if (dest_tid
== GetCurrentThreadId())
2317 result
= handle_internal_message( 0, msg
, wparam
, lparam
);
2322 if (dest_pid
!= GetCurrentProcessId()) info
.type
= MSG_OTHER_PROCESS
;
2323 ret
= send_inter_thread_message( &info
, &result
);
2325 if (ret
&& res_ptr
) *res_ptr
= result
;
2330 /***********************************************************************
2331 * SendMessageTimeoutW (USER32.@)
2333 LRESULT WINAPI
SendMessageTimeoutW( HWND hwnd
, UINT msg
, WPARAM wparam
, LPARAM lparam
,
2334 UINT flags
, UINT timeout
, PDWORD_PTR res_ptr
)
2336 struct send_message_info info
;
2338 LRESULT ret
, result
;
2340 info
.type
= MSG_UNICODE
;
2343 info
.wparam
= wparam
;
2344 info
.lparam
= lparam
;
2346 info
.timeout
= timeout
;
2348 if (is_broadcast(hwnd
))
2350 EnumWindows( broadcast_message_callback
, (LPARAM
)&info
);
2351 if (res_ptr
) *res_ptr
= 1;
2355 if (!(info
.dest_tid
= GetWindowThreadProcessId( hwnd
, &dest_pid
))) return 0;
2357 if (USER_IsExitingThread( info
.dest_tid
)) return 0;
2359 SPY_EnterMessage( SPY_SENDMESSAGE
, hwnd
, msg
, wparam
, lparam
);
2361 if (info
.dest_tid
== GetCurrentThreadId())
2363 result
= call_window_proc( hwnd
, msg
, wparam
, lparam
, TRUE
, TRUE
);
2368 if (dest_pid
!= GetCurrentProcessId()) info
.type
= MSG_OTHER_PROCESS
;
2369 ret
= send_inter_thread_message( &info
, &result
);
2372 SPY_ExitMessage( SPY_RESULT_OK
, hwnd
, msg
, result
, wparam
, lparam
);
2373 if (ret
&& res_ptr
) *res_ptr
= result
;
2377 static LRESULT
send_inter_thread_callback( HWND hwnd
, UINT msg
, WPARAM wp
, LPARAM lp
,
2378 LRESULT
*result
, void *arg
)
2380 struct send_message_info
*info
= arg
;
2385 return send_inter_thread_message( info
, result
);
2388 /***********************************************************************
2389 * SendMessageTimeoutA (USER32.@)
2391 LRESULT WINAPI
SendMessageTimeoutA( HWND hwnd
, UINT msg
, WPARAM wparam
, LPARAM lparam
,
2392 UINT flags
, UINT timeout
, PDWORD_PTR res_ptr
)
2394 struct send_message_info info
;
2396 LRESULT ret
, result
;
2398 info
.type
= MSG_ASCII
;
2401 info
.wparam
= wparam
;
2402 info
.lparam
= lparam
;
2404 info
.timeout
= timeout
;
2406 if (is_broadcast(hwnd
))
2408 EnumWindows( broadcast_message_callback
, (LPARAM
)&info
);
2409 if (res_ptr
) *res_ptr
= 1;
2413 if (!(info
.dest_tid
= GetWindowThreadProcessId( hwnd
, &dest_pid
))) return 0;
2415 if (USER_IsExitingThread( info
.dest_tid
)) return 0;
2417 SPY_EnterMessage( SPY_SENDMESSAGE
, hwnd
, msg
, wparam
, lparam
);
2419 if (info
.dest_tid
== GetCurrentThreadId())
2421 result
= call_window_proc( hwnd
, msg
, wparam
, lparam
, FALSE
, TRUE
);
2424 else if (dest_pid
== GetCurrentProcessId())
2426 ret
= send_inter_thread_message( &info
, &result
);
2430 /* inter-process message: need to map to Unicode */
2431 info
.type
= MSG_OTHER_PROCESS
;
2432 if (is_unicode_message( info
.msg
))
2433 ret
= WINPROC_CallProcAtoW( send_inter_thread_callback
, info
.hwnd
, info
.msg
,
2434 info
.wparam
, info
.lparam
, &result
, &info
);
2435 else ret
= send_inter_thread_message( &info
, &result
);
2437 SPY_ExitMessage( SPY_RESULT_OK
, hwnd
, msg
, result
, wparam
, lparam
);
2438 if (ret
&& res_ptr
) *res_ptr
= result
;
2443 /***********************************************************************
2444 * SendMessageW (USER32.@)
2446 LRESULT WINAPI
SendMessageW( HWND hwnd
, UINT msg
, WPARAM wparam
, LPARAM lparam
)
2449 SendMessageTimeoutW( hwnd
, msg
, wparam
, lparam
, SMTO_NORMAL
, 0, &res
);
2454 /***********************************************************************
2455 * SendMessageA (USER32.@)
2457 LRESULT WINAPI
SendMessageA( HWND hwnd
, UINT msg
, WPARAM wparam
, LPARAM lparam
)
2460 SendMessageTimeoutA( hwnd
, msg
, wparam
, lparam
, SMTO_NORMAL
, 0, &res
);
2465 /***********************************************************************
2466 * SendNotifyMessageA (USER32.@)
2468 BOOL WINAPI
SendNotifyMessageA( HWND hwnd
, UINT msg
, WPARAM wparam
, LPARAM lparam
)
2470 return SendNotifyMessageW( hwnd
, msg
, map_wparam_AtoW( msg
, wparam
), lparam
);
2474 /***********************************************************************
2475 * SendNotifyMessageW (USER32.@)
2477 BOOL WINAPI
SendNotifyMessageW( HWND hwnd
, UINT msg
, WPARAM wparam
, LPARAM lparam
)
2479 struct send_message_info info
;
2482 if (is_pointer_message(msg
))
2484 SetLastError( ERROR_MESSAGE_SYNC_ONLY
);
2488 info
.type
= MSG_NOTIFY
;
2491 info
.wparam
= wparam
;
2492 info
.lparam
= lparam
;
2495 if (is_broadcast(hwnd
))
2497 EnumWindows( broadcast_message_callback
, (LPARAM
)&info
);
2501 if (!(info
.dest_tid
= GetWindowThreadProcessId( hwnd
, NULL
))) return FALSE
;
2503 if (USER_IsExitingThread( info
.dest_tid
)) return TRUE
;
2505 if (info
.dest_tid
== GetCurrentThreadId())
2507 call_window_proc( hwnd
, msg
, wparam
, lparam
, TRUE
, TRUE
);
2510 return send_inter_thread_message( &info
, &result
);
2514 /***********************************************************************
2515 * SendMessageCallbackA (USER32.@)
2517 BOOL WINAPI
SendMessageCallbackA( HWND hwnd
, UINT msg
, WPARAM wparam
, LPARAM lparam
,
2518 SENDASYNCPROC callback
, ULONG_PTR data
)
2520 return SendMessageCallbackW( hwnd
, msg
, map_wparam_AtoW( msg
, wparam
),
2521 lparam
, callback
, data
);
2525 /***********************************************************************
2526 * SendMessageCallbackW (USER32.@)
2528 BOOL WINAPI
SendMessageCallbackW( HWND hwnd
, UINT msg
, WPARAM wparam
, LPARAM lparam
,
2529 SENDASYNCPROC callback
, ULONG_PTR data
)
2531 struct send_message_info info
;
2534 if (is_pointer_message(msg
))
2536 SetLastError( ERROR_MESSAGE_SYNC_ONLY
);
2540 info
.type
= MSG_CALLBACK
;
2543 info
.wparam
= wparam
;
2544 info
.lparam
= lparam
;
2545 info
.callback
= callback
;
2549 if (is_broadcast(hwnd
))
2551 EnumWindows( broadcast_message_callback
, (LPARAM
)&info
);
2555 if (!(info
.dest_tid
= GetWindowThreadProcessId( hwnd
, NULL
))) return FALSE
;
2557 if (USER_IsExitingThread( info
.dest_tid
)) return TRUE
;
2559 if (info
.dest_tid
== GetCurrentThreadId())
2561 result
= call_window_proc( hwnd
, msg
, wparam
, lparam
, TRUE
, TRUE
);
2562 call_sendmsg_callback( callback
, hwnd
, msg
, data
, result
);
2565 FIXME( "callback will not be called\n" );
2566 return send_inter_thread_message( &info
, &result
);
2570 /***********************************************************************
2571 * ReplyMessage (USER32.@)
2573 BOOL WINAPI
ReplyMessage( LRESULT result
)
2575 struct received_message_info
*info
= get_user_thread_info()->receive_info
;
2577 if (!info
) return FALSE
;
2578 reply_message( info
, result
, FALSE
);
2583 /***********************************************************************
2584 * InSendMessage (USER32.@)
2586 BOOL WINAPI
InSendMessage(void)
2588 return (InSendMessageEx(NULL
) & (ISMEX_SEND
|ISMEX_REPLIED
)) == ISMEX_SEND
;
2592 /***********************************************************************
2593 * InSendMessageEx (USER32.@)
2595 DWORD WINAPI
InSendMessageEx( LPVOID reserved
)
2597 struct received_message_info
*info
= get_user_thread_info()->receive_info
;
2599 if (info
) return info
->flags
;
2600 return ISMEX_NOSEND
;
2604 /***********************************************************************
2605 * PostMessageA (USER32.@)
2607 BOOL WINAPI
PostMessageA( HWND hwnd
, UINT msg
, WPARAM wparam
, LPARAM lparam
)
2609 return PostMessageW( hwnd
, msg
, map_wparam_AtoW( msg
, wparam
), lparam
);
2613 /***********************************************************************
2614 * PostMessageW (USER32.@)
2616 BOOL WINAPI
PostMessageW( HWND hwnd
, UINT msg
, WPARAM wparam
, LPARAM lparam
)
2618 struct send_message_info info
;
2620 if (is_pointer_message( msg
))
2622 SetLastError( ERROR_MESSAGE_SYNC_ONLY
);
2626 TRACE( "hwnd %p msg %x (%s) wp %x lp %lx\n",
2627 hwnd
, msg
, SPY_GetMsgName(msg
, hwnd
), wparam
, lparam
);
2629 info
.type
= MSG_POSTED
;
2632 info
.wparam
= wparam
;
2633 info
.lparam
= lparam
;
2636 if (is_broadcast(hwnd
))
2638 EnumWindows( broadcast_message_callback
, (LPARAM
)&info
);
2642 if (!hwnd
) return PostThreadMessageW( GetCurrentThreadId(), msg
, wparam
, lparam
);
2644 if (!(info
.dest_tid
= GetWindowThreadProcessId( hwnd
, NULL
))) return FALSE
;
2646 if (USER_IsExitingThread( info
.dest_tid
)) return TRUE
;
2648 return put_message_in_queue( &info
, NULL
);
2652 /**********************************************************************
2653 * PostThreadMessageA (USER32.@)
2655 BOOL WINAPI
PostThreadMessageA( DWORD thread
, UINT msg
, WPARAM wparam
, LPARAM lparam
)
2657 return PostThreadMessageW( thread
, msg
, map_wparam_AtoW( msg
, wparam
), lparam
);
2661 /**********************************************************************
2662 * PostThreadMessageW (USER32.@)
2664 BOOL WINAPI
PostThreadMessageW( DWORD thread
, UINT msg
, WPARAM wparam
, LPARAM lparam
)
2666 struct send_message_info info
;
2668 if (is_pointer_message( msg
))
2670 SetLastError( ERROR_MESSAGE_SYNC_ONLY
);
2673 if (USER_IsExitingThread( thread
)) return TRUE
;
2675 info
.type
= MSG_POSTED
;
2676 info
.dest_tid
= thread
;
2679 info
.wparam
= wparam
;
2680 info
.lparam
= lparam
;
2682 return put_message_in_queue( &info
, NULL
);
2686 /***********************************************************************
2687 * PostQuitMessage (USER32.@)
2689 * Posts a quit message to the current thread's message queue.
2692 * exit_code [I] Exit code to return from message loop.
2698 * This function is not the same as calling:
2699 *|PostThreadMessage(GetCurrentThreadId(), WM_QUIT, exit_code, 0);
2700 * It instead sets a flag in the message queue that signals it to generate
2701 * a WM_QUIT message when there are no other pending sent or posted messages
2704 void WINAPI
PostQuitMessage( INT exit_code
)
2706 SERVER_START_REQ( post_quit_message
)
2708 req
->exit_code
= exit_code
;
2709 wine_server_call( req
);
2715 /***********************************************************************
2716 * PeekMessageW (USER32.@)
2718 BOOL WINAPI
PeekMessageW( MSG
*msg_out
, HWND hwnd
, UINT first
, UINT last
, UINT flags
)
2720 struct user_thread_info
*thread_info
= get_user_thread_info();
2724 FIXME("PM_QS_xxxx flags (%04x) are not handled\n", flags
>> 16);
2726 USER_CheckNotLock();
2728 /* check for graphics events */
2729 USER_Driver
->pMsgWaitForMultipleObjectsEx( 0, NULL
, 0, QS_ALLINPUT
, 0 );
2731 hwnd
= WIN_GetFullHandle( hwnd
);
2735 if (!peek_message( &msg
, hwnd
, first
, last
, (flags
& PM_REMOVE
) ? GET_MSG_REMOVE
: 0 ))
2737 if (!(flags
& PM_NOYIELD
))
2740 ReleaseThunkLock(&count
);
2742 if (count
) RestoreThunkLock(count
);
2746 if (msg
.message
& 0x80000000)
2748 if (!(flags
& PM_REMOVE
))
2750 /* Have to remove the message explicitly.
2751 Do this before handling it, because the message handler may
2752 call PeekMessage again */
2753 peek_message( &msg
, msg
.hwnd
, msg
.message
, msg
.message
, GET_MSG_REMOVE
);
2755 handle_internal_message( msg
.hwnd
, msg
.message
, msg
.wParam
, msg
.lParam
);
2760 thread_info
->GetMessageTimeVal
= msg
.time
;
2761 msg
.pt
.x
= LOWORD( thread_info
->GetMessagePosVal
);
2762 msg
.pt
.y
= HIWORD( thread_info
->GetMessagePosVal
);
2764 HOOK_CallHooks( WH_GETMESSAGE
, HC_ACTION
, flags
& PM_REMOVE
, (LPARAM
)&msg
, TRUE
);
2766 /* copy back our internal safe copy of message data to msg_out.
2767 * msg_out is a variable from the *program*, so it can't be used
2768 * internally as it can get "corrupted" by our use of SendMessage()
2769 * (back to the program) inside the message handling itself. */
2772 SetLastError( ERROR_NOACCESS
);
2780 /***********************************************************************
2781 * PeekMessageA (USER32.@)
2783 BOOL WINAPI
PeekMessageA( MSG
*msg
, HWND hwnd
, UINT first
, UINT last
, UINT flags
)
2785 BOOL ret
= PeekMessageW( msg
, hwnd
, first
, last
, flags
);
2786 if (ret
) msg
->wParam
= map_wparam_WtoA( msg
->message
, msg
->wParam
);
2791 /***********************************************************************
2792 * GetMessageW (USER32.@)
2794 BOOL WINAPI
GetMessageW( MSG
*msg
, HWND hwnd
, UINT first
, UINT last
)
2796 HANDLE server_queue
= get_server_queue_handle();
2797 int mask
= QS_POSTMESSAGE
| QS_SENDMESSAGE
; /* Always selected */
2801 if ((first
<= WM_KEYLAST
) && (last
>= WM_KEYFIRST
)) mask
|= QS_KEY
;
2802 if ( ((first
<= WM_MOUSELAST
) && (last
>= WM_MOUSEFIRST
)) ||
2803 ((first
<= WM_NCMOUSELAST
) && (last
>= WM_NCMOUSEFIRST
)) ) mask
|= QS_MOUSE
;
2804 if ((first
<= WM_TIMER
) && (last
>= WM_TIMER
)) mask
|= QS_TIMER
;
2805 if ((first
<= WM_SYSTIMER
) && (last
>= WM_SYSTIMER
)) mask
|= QS_TIMER
;
2806 if ((first
<= WM_PAINT
) && (last
>= WM_PAINT
)) mask
|= QS_PAINT
;
2808 else mask
|= QS_MOUSE
| QS_KEY
| QS_TIMER
| QS_PAINT
;
2810 while (!PeekMessageW( msg
, hwnd
, first
, last
, PM_REMOVE
))
2812 /* wait until one of the bits is set */
2813 unsigned int wake_bits
= 0, changed_bits
= 0;
2816 SERVER_START_REQ( set_queue_mask
)
2818 req
->wake_mask
= QS_SENDMESSAGE
;
2819 req
->changed_mask
= mask
;
2821 if (!wine_server_call( req
))
2823 wake_bits
= reply
->wake_bits
;
2824 changed_bits
= reply
->changed_bits
;
2829 if (changed_bits
& mask
) continue;
2830 if (wake_bits
& QS_SENDMESSAGE
) continue;
2832 TRACE( "(%04lx) mask=%08x, bits=%08x, changed=%08x, waiting\n",
2833 GetCurrentThreadId(), mask
, wake_bits
, changed_bits
);
2835 ReleaseThunkLock( &dwlc
);
2836 USER_Driver
->pMsgWaitForMultipleObjectsEx( 1, &server_queue
, INFINITE
, QS_ALLINPUT
, 0 );
2837 if (dwlc
) RestoreThunkLock( dwlc
);
2840 return (msg
->message
!= WM_QUIT
);
2844 /***********************************************************************
2845 * GetMessageA (USER32.@)
2847 BOOL WINAPI
GetMessageA( MSG
*msg
, HWND hwnd
, UINT first
, UINT last
)
2849 GetMessageW( msg
, hwnd
, first
, last
);
2850 msg
->wParam
= map_wparam_WtoA( msg
->message
, msg
->wParam
);
2851 return (msg
->message
!= WM_QUIT
);
2855 /***********************************************************************
2856 * IsDialogMessageA (USER32.@)
2857 * IsDialogMessage (USER32.@)
2859 BOOL WINAPI
IsDialogMessageA( HWND hwndDlg
, LPMSG pmsg
)
2862 msg
.wParam
= map_wparam_AtoW( msg
.message
, msg
.wParam
);
2863 return IsDialogMessageW( hwndDlg
, &msg
);
2867 /***********************************************************************
2868 * TranslateMessage (USER32.@)
2870 * Implementation of TranslateMessage.
2872 * TranslateMessage translates virtual-key messages into character-messages,
2874 * WM_KEYDOWN/WM_KEYUP combinations produce a WM_CHAR or WM_DEADCHAR message.
2875 * ditto replacing WM_* with WM_SYS*
2876 * This produces WM_CHAR messages only for keys mapped to ASCII characters
2877 * by the keyboard driver.
2879 * If the message is WM_KEYDOWN, WM_KEYUP, WM_SYSKEYDOWN, or WM_SYSKEYUP, the
2880 * return value is nonzero, regardless of the translation.
2883 BOOL WINAPI
TranslateMessage( const MSG
*msg
)
2889 if (msg
->message
< WM_KEYFIRST
|| msg
->message
> WM_KEYLAST
) return FALSE
;
2890 if (msg
->message
!= WM_KEYDOWN
&& msg
->message
!= WM_SYSKEYDOWN
) return TRUE
;
2892 TRACE_(key
)("Translating key %s (%04x), scancode %02x\n",
2893 SPY_GetVKeyName(msg
->wParam
), msg
->wParam
, LOBYTE(HIWORD(msg
->lParam
)));
2895 GetKeyboardState( state
);
2896 /* FIXME : should handle ToUnicode yielding 2 */
2897 switch (ToUnicode(msg
->wParam
, HIWORD(msg
->lParam
), state
, wp
, 2, 0))
2900 message
= (msg
->message
== WM_KEYDOWN
) ? WM_CHAR
: WM_SYSCHAR
;
2901 TRACE_(key
)("1 -> PostMessageW(%p,%s,%04x,%08lx)\n",
2902 msg
->hwnd
, SPY_GetMsgName(message
, msg
->hwnd
), wp
[0], msg
->lParam
);
2903 PostMessageW( msg
->hwnd
, message
, wp
[0], msg
->lParam
);
2907 message
= (msg
->message
== WM_KEYDOWN
) ? WM_DEADCHAR
: WM_SYSDEADCHAR
;
2908 TRACE_(key
)("-1 -> PostMessageW(%p,%s,%04x,%08lx)\n",
2909 msg
->hwnd
, SPY_GetMsgName(message
, msg
->hwnd
), wp
[0], msg
->lParam
);
2910 PostMessageW( msg
->hwnd
, message
, wp
[0], msg
->lParam
);
2917 /***********************************************************************
2918 * DispatchMessageA (USER32.@)
2920 * See DispatchMessageW.
2922 LONG WINAPI
DispatchMessageA( const MSG
* msg
)
2928 /* Process timer messages */
2929 if ((msg
->message
== WM_TIMER
) || (msg
->message
== WM_SYSTIMER
))
2931 if (msg
->lParam
) return CallWindowProcA( (WNDPROC
)msg
->lParam
, msg
->hwnd
,
2932 msg
->message
, msg
->wParam
, GetTickCount() );
2935 if (!(wndPtr
= WIN_GetPtr( msg
->hwnd
)))
2937 if (msg
->hwnd
) SetLastError( ERROR_INVALID_WINDOW_HANDLE
);
2940 if (wndPtr
== WND_OTHER_PROCESS
|| wndPtr
== WND_DESKTOP
)
2942 if (IsWindow( msg
->hwnd
)) SetLastError( ERROR_MESSAGE_SYNC_ONLY
);
2943 else SetLastError( ERROR_INVALID_WINDOW_HANDLE
);
2946 if (wndPtr
->tid
!= GetCurrentThreadId())
2948 SetLastError( ERROR_MESSAGE_SYNC_ONLY
);
2949 WIN_ReleasePtr( wndPtr
);
2952 winproc
= wndPtr
->winproc
;
2953 WIN_ReleasePtr( wndPtr
);
2955 SPY_EnterMessage( SPY_DISPATCHMESSAGE
, msg
->hwnd
, msg
->message
,
2956 msg
->wParam
, msg
->lParam
);
2957 retval
= CallWindowProcA( winproc
, msg
->hwnd
, msg
->message
,
2958 msg
->wParam
, msg
->lParam
);
2959 SPY_ExitMessage( SPY_RESULT_OK
, msg
->hwnd
, msg
->message
, retval
,
2960 msg
->wParam
, msg
->lParam
);
2962 if (msg
->message
== WM_PAINT
)
2964 /* send a WM_NCPAINT and WM_ERASEBKGND if the non-client area is still invalid */
2965 HRGN hrgn
= CreateRectRgn( 0, 0, 0, 0 );
2966 GetUpdateRgn( msg
->hwnd
, hrgn
, TRUE
);
2967 DeleteObject( hrgn
);
2973 /***********************************************************************
2974 * DispatchMessageW (USER32.@) Process a message
2976 * Process the message specified in the structure *_msg_.
2978 * If the lpMsg parameter points to a WM_TIMER message and the
2979 * parameter of the WM_TIMER message is not NULL, the lParam parameter
2980 * points to the function that is called instead of the window
2983 * The message must be valid.
2987 * DispatchMessage() returns the result of the window procedure invoked.
2994 LONG WINAPI
DispatchMessageW( const MSG
* msg
)
3000 /* Process timer messages */
3001 if ((msg
->message
== WM_TIMER
) || (msg
->message
== WM_SYSTIMER
))
3003 if (msg
->lParam
) return CallWindowProcW( (WNDPROC
)msg
->lParam
, msg
->hwnd
,
3004 msg
->message
, msg
->wParam
, GetTickCount() );
3007 if (!(wndPtr
= WIN_GetPtr( msg
->hwnd
)))
3009 if (msg
->hwnd
) SetLastError( ERROR_INVALID_WINDOW_HANDLE
);
3012 if (wndPtr
== WND_OTHER_PROCESS
|| wndPtr
== WND_DESKTOP
)
3014 if (IsWindow( msg
->hwnd
)) SetLastError( ERROR_MESSAGE_SYNC_ONLY
);
3015 else SetLastError( ERROR_INVALID_WINDOW_HANDLE
);
3018 if (wndPtr
->tid
!= GetCurrentThreadId())
3020 SetLastError( ERROR_MESSAGE_SYNC_ONLY
);
3021 WIN_ReleasePtr( wndPtr
);
3024 winproc
= wndPtr
->winproc
;
3025 WIN_ReleasePtr( wndPtr
);
3027 SPY_EnterMessage( SPY_DISPATCHMESSAGE
, msg
->hwnd
, msg
->message
,
3028 msg
->wParam
, msg
->lParam
);
3029 retval
= CallWindowProcW( winproc
, msg
->hwnd
, msg
->message
,
3030 msg
->wParam
, msg
->lParam
);
3031 SPY_ExitMessage( SPY_RESULT_OK
, msg
->hwnd
, msg
->message
, retval
,
3032 msg
->wParam
, msg
->lParam
);
3034 if (msg
->message
== WM_PAINT
)
3036 /* send a WM_NCPAINT and WM_ERASEBKGND if the non-client area is still invalid */
3037 HRGN hrgn
= CreateRectRgn( 0, 0, 0, 0 );
3038 GetUpdateRgn( msg
->hwnd
, hrgn
, TRUE
);
3039 DeleteObject( hrgn
);
3045 /***********************************************************************
3046 * GetMessagePos (USER.119)
3047 * GetMessagePos (USER32.@)
3049 * The GetMessagePos() function returns a long value representing a
3050 * cursor position, in screen coordinates, when the last message
3051 * retrieved by the GetMessage() function occurs. The x-coordinate is
3052 * in the low-order word of the return value, the y-coordinate is in
3053 * the high-order word. The application can use the MAKEPOINT()
3054 * macro to obtain a POINT structure from the return value.
3056 * For the current cursor position, use GetCursorPos().
3060 * Cursor position of last message on success, zero on failure.
3067 DWORD WINAPI
GetMessagePos(void)
3069 return get_user_thread_info()->GetMessagePosVal
;
3073 /***********************************************************************
3074 * GetMessageTime (USER.120)
3075 * GetMessageTime (USER32.@)
3077 * GetMessageTime() returns the message time for the last message
3078 * retrieved by the function. The time is measured in milliseconds with
3079 * the same offset as GetTickCount().
3081 * Since the tick count wraps, this is only useful for moderately short
3082 * relative time comparisons.
3086 * Time of last message on success, zero on failure.
3088 LONG WINAPI
GetMessageTime(void)
3090 return get_user_thread_info()->GetMessageTimeVal
;
3094 /***********************************************************************
3095 * GetMessageExtraInfo (USER.288)
3096 * GetMessageExtraInfo (USER32.@)
3098 LPARAM WINAPI
GetMessageExtraInfo(void)
3100 return get_user_thread_info()->GetMessageExtraInfoVal
;
3104 /***********************************************************************
3105 * SetMessageExtraInfo (USER32.@)
3107 LPARAM WINAPI
SetMessageExtraInfo(LPARAM lParam
)
3109 struct user_thread_info
*thread_info
= get_user_thread_info();
3110 LONG old_value
= thread_info
->GetMessageExtraInfoVal
;
3111 thread_info
->GetMessageExtraInfoVal
= lParam
;
3116 /***********************************************************************
3117 * WaitMessage (USER.112) Suspend thread pending messages
3118 * WaitMessage (USER32.@) Suspend thread pending messages
3120 * WaitMessage() suspends a thread until events appear in the thread's
3123 BOOL WINAPI
WaitMessage(void)
3125 return (MsgWaitForMultipleObjectsEx( 0, NULL
, INFINITE
, QS_ALLINPUT
, 0 ) != WAIT_FAILED
);
3129 /***********************************************************************
3130 * MsgWaitForMultipleObjectsEx (USER32.@)
3132 DWORD WINAPI
MsgWaitForMultipleObjectsEx( DWORD count
, CONST HANDLE
*pHandles
,
3133 DWORD timeout
, DWORD mask
, DWORD flags
)
3135 HANDLE handles
[MAXIMUM_WAIT_OBJECTS
];
3138 if (count
> MAXIMUM_WAIT_OBJECTS
-1)
3140 SetLastError( ERROR_INVALID_PARAMETER
);
3144 /* set the queue mask */
3145 SERVER_START_REQ( set_queue_mask
)
3147 req
->wake_mask
= (flags
& MWMO_INPUTAVAILABLE
) ? mask
: 0;
3148 req
->changed_mask
= mask
;
3150 wine_server_call( req
);
3154 /* Add the thread event to the handle list */
3155 for (i
= 0; i
< count
; i
++) handles
[i
] = pHandles
[i
];
3156 handles
[count
] = get_server_queue_handle();
3158 ReleaseThunkLock( &lock
);
3159 ret
= USER_Driver
->pMsgWaitForMultipleObjectsEx( count
+1, handles
, timeout
, mask
, flags
);
3160 if (ret
== count
+1) ret
= count
; /* pretend the msg queue is ready */
3161 if (lock
) RestoreThunkLock( lock
);
3166 /***********************************************************************
3167 * MsgWaitForMultipleObjects (USER32.@)
3169 DWORD WINAPI
MsgWaitForMultipleObjects( DWORD count
, CONST HANDLE
*handles
,
3170 BOOL wait_all
, DWORD timeout
, DWORD mask
)
3172 return MsgWaitForMultipleObjectsEx( count
, handles
, timeout
, mask
,
3173 wait_all
? MWMO_WAITALL
: 0 );
3177 /***********************************************************************
3178 * WaitForInputIdle (USER32.@)
3180 DWORD WINAPI
WaitForInputIdle( HANDLE hProcess
, DWORD dwTimeOut
)
3182 DWORD start_time
, elapsed
, ret
;
3183 HANDLE idle_event
= (HANDLE
)-1;
3185 SERVER_START_REQ( wait_input_idle
)
3187 req
->handle
= hProcess
;
3188 req
->timeout
= dwTimeOut
;
3189 if (!(ret
= wine_server_call_err( req
))) idle_event
= reply
->event
;
3192 if (ret
) return WAIT_FAILED
; /* error */
3193 if (!idle_event
) return 0; /* no event to wait on */
3195 start_time
= GetTickCount();
3198 TRACE("waiting for %p\n", idle_event
);
3201 ret
= MsgWaitForMultipleObjects ( 1, &idle_event
, FALSE
, dwTimeOut
- elapsed
, QS_SENDMESSAGE
);
3204 case WAIT_OBJECT_0
+1:
3205 process_sent_messages();
3209 TRACE("timeout or error\n");
3212 TRACE("finished\n");
3215 if (dwTimeOut
!= INFINITE
)
3217 elapsed
= GetTickCount() - start_time
;
3218 if (elapsed
> dwTimeOut
)
3224 return WAIT_TIMEOUT
;
3228 /***********************************************************************
3229 * UserYield (USER.332)
3231 void WINAPI
UserYield16(void)
3235 /* Handle sent messages */
3236 process_sent_messages();
3239 ReleaseThunkLock(&count
);
3243 RestoreThunkLock(count
);
3244 /* Handle sent messages again */
3245 process_sent_messages();
3250 /***********************************************************************
3251 * RegisterWindowMessageA (USER32.@)
3252 * RegisterWindowMessage (USER.118)
3254 UINT WINAPI
RegisterWindowMessageA( LPCSTR str
)
3256 UINT ret
= GlobalAddAtomA(str
);
3257 TRACE("%s, ret=%x\n", str
, ret
);
3262 /***********************************************************************
3263 * RegisterWindowMessageW (USER32.@)
3265 UINT WINAPI
RegisterWindowMessageW( LPCWSTR str
)
3267 UINT ret
= GlobalAddAtomW(str
);
3268 TRACE("%s ret=%x\n", debugstr_w(str
), ret
);
3273 /***********************************************************************
3274 * BroadcastSystemMessageA (USER32.@)
3275 * BroadcastSystemMessage (USER32.@)
3277 LONG WINAPI
BroadcastSystemMessageA( DWORD flags
, LPDWORD recipients
, UINT msg
, WPARAM wp
, LPARAM lp
)
3279 if ((*recipients
& BSM_APPLICATIONS
) || (*recipients
== BSM_ALLCOMPONENTS
))
3281 FIXME( "(%08lx,%08lx,%08x,%08x,%08lx): semi-stub!\n", flags
, *recipients
, msg
, wp
, lp
);
3282 PostMessageA( HWND_BROADCAST
, msg
, wp
, lp
);
3287 FIXME( "(%08lx,%08lx,%08x,%08x,%08lx): stub!\n", flags
, *recipients
, msg
, wp
, lp
);
3293 /***********************************************************************
3294 * BroadcastSystemMessageW (USER32.@)
3296 LONG WINAPI
BroadcastSystemMessageW( DWORD flags
, LPDWORD recipients
, UINT msg
, WPARAM wp
, LPARAM lp
)
3298 if ((*recipients
& BSM_APPLICATIONS
) || (*recipients
== BSM_ALLCOMPONENTS
))
3300 FIXME( "(%08lx,%08lx,%08x,%08x,%08lx): semi-stub!\n", flags
, *recipients
, msg
, wp
, lp
);
3301 PostMessageW( HWND_BROADCAST
, msg
, wp
, lp
);
3306 FIXME( "(%08lx,%08lx,%08x,%08x,%08lx): stub!\n", flags
, *recipients
, msg
, wp
, lp
);
3312 /***********************************************************************
3313 * SetMessageQueue (USER32.@)
3315 BOOL WINAPI
SetMessageQueue( INT size
)
3317 /* now obsolete the message queue will be expanded dynamically as necessary */
3322 /***********************************************************************
3323 * MessageBeep (USER32.@)
3325 BOOL WINAPI
MessageBeep( UINT i
)
3328 SystemParametersInfoA( SPI_GETBEEP
, 0, &active
, FALSE
);
3329 if (active
) USER_Driver
->pBeep();
3334 /***********************************************************************
3335 * SetTimer (USER32.@)
3337 UINT_PTR WINAPI
SetTimer( HWND hwnd
, UINT_PTR id
, UINT timeout
, TIMERPROC proc
)
3340 WNDPROC winproc
= 0;
3342 if (proc
) winproc
= WINPROC_AllocProc( (WNDPROC
)proc
, NULL
);
3344 SERVER_START_REQ( set_win_timer
)
3347 req
->msg
= WM_TIMER
;
3349 req
->rate
= max( timeout
, SYS_TIMER_RATE
);
3350 req
->lparam
= (unsigned long)winproc
;
3351 if (!wine_server_call_err( req
))
3354 if (!ret
) ret
= TRUE
;
3360 TRACE("Added %p %x %p timeout %d\n", hwnd
, id
, winproc
, timeout
);
3365 /***********************************************************************
3366 * SetSystemTimer (USER32.@)
3368 UINT_PTR WINAPI
SetSystemTimer( HWND hwnd
, UINT_PTR id
, UINT timeout
, TIMERPROC proc
)
3371 WNDPROC winproc
= 0;
3373 if (proc
) winproc
= WINPROC_AllocProc( (WNDPROC
)proc
, NULL
);
3375 SERVER_START_REQ( set_win_timer
)
3378 req
->msg
= WM_SYSTIMER
;
3380 req
->rate
= max( timeout
, SYS_TIMER_RATE
);
3381 req
->lparam
= (unsigned long)winproc
;
3382 if (!wine_server_call_err( req
))
3385 if (!ret
) ret
= TRUE
;
3391 TRACE("Added %p %x %p timeout %d\n", hwnd
, id
, winproc
, timeout
);
3396 /***********************************************************************
3397 * KillTimer (USER32.@)
3399 BOOL WINAPI
KillTimer( HWND hwnd
, UINT_PTR id
)
3403 TRACE("%p %d\n", hwnd
, id
);
3405 SERVER_START_REQ( kill_win_timer
)
3408 req
->msg
= WM_TIMER
;
3410 ret
= !wine_server_call_err( req
);
3417 /***********************************************************************
3418 * KillSystemTimer (USER32.@)
3420 BOOL WINAPI
KillSystemTimer( HWND hwnd
, UINT_PTR id
)
3424 TRACE("%p %d\n", hwnd
, id
);
3426 SERVER_START_REQ( kill_win_timer
)
3429 req
->msg
= WM_SYSTIMER
;
3431 ret
= !wine_server_call_err( req
);
3438 /**********************************************************************
3439 * GetGUIThreadInfo (USER32.@)
3441 BOOL WINAPI
GetGUIThreadInfo( DWORD id
, GUITHREADINFO
*info
)
3445 SERVER_START_REQ( get_thread_input
)
3448 if ((ret
= !wine_server_call_err( req
)))
3451 info
->hwndActive
= reply
->active
;
3452 info
->hwndFocus
= reply
->focus
;
3453 info
->hwndCapture
= reply
->capture
;
3454 info
->hwndMenuOwner
= reply
->menu_owner
;
3455 info
->hwndMoveSize
= reply
->move_size
;
3456 info
->hwndCaret
= reply
->caret
;
3457 info
->rcCaret
.left
= reply
->rect
.left
;
3458 info
->rcCaret
.top
= reply
->rect
.top
;
3459 info
->rcCaret
.right
= reply
->rect
.right
;
3460 info
->rcCaret
.bottom
= reply
->rect
.bottom
;
3461 if (reply
->menu_owner
) info
->flags
|= GUI_INMENUMODE
;
3462 if (reply
->move_size
) info
->flags
|= GUI_INMOVESIZE
;
3463 if (reply
->caret
) info
->flags
|= GUI_CARETBLINKING
;
3471 /******************************************************************
3472 * IsHungAppWindow (USER32.@)
3475 BOOL WINAPI
IsHungAppWindow( HWND hWnd
)
3478 return !SendMessageTimeoutA(hWnd
, WM_NULL
, 0, 0, SMTO_ABORTIFHUNG
, 5000, &dwResult
);