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 */
71 HWINEVENTHOOK hook
; /* winevent hook handle */
72 WINEVENTPROC hook_proc
; /* winevent hook proc address */
75 /* structure to group all parameters for sent messages of the various kinds */
76 struct send_message_info
78 enum message_type type
;
84 UINT flags
; /* flags for SendMessageTimeout */
85 UINT timeout
; /* timeout for SendMessageTimeout */
86 SENDASYNCPROC callback
; /* callback function for SendMessageCallback */
87 ULONG_PTR data
; /* callback data */
91 /* flag for messages that contain pointers */
92 /* 32 messages per entry, messages 0..31 map to bits 0..31 */
94 #define SET(msg) (1 << ((msg) & 31))
96 static const unsigned int message_pointer_flags
[] =
99 SET(WM_CREATE
) | SET(WM_SETTEXT
) | SET(WM_GETTEXT
) |
100 SET(WM_WININICHANGE
) | SET(WM_DEVMODECHANGE
),
102 SET(WM_GETMINMAXINFO
) | SET(WM_DRAWITEM
) | SET(WM_MEASUREITEM
) | SET(WM_DELETEITEM
) |
105 SET(WM_WINDOWPOSCHANGING
) | SET(WM_WINDOWPOSCHANGED
) | SET(WM_COPYDATA
) |
106 SET(WM_NOTIFY
) | SET(WM_HELP
),
108 SET(WM_STYLECHANGING
) | SET(WM_STYLECHANGED
),
110 SET(WM_NCCREATE
) | SET(WM_NCCALCSIZE
) | SET(WM_GETDLGCODE
),
112 SET(EM_GETSEL
) | SET(EM_GETRECT
) | SET(EM_SETRECT
) | SET(EM_SETRECTNP
),
114 SET(EM_REPLACESEL
) | SET(EM_GETLINE
) | SET(EM_SETTABSTOPS
),
116 SET(SBM_GETRANGE
) | SET(SBM_SETSCROLLINFO
) | SET(SBM_GETSCROLLINFO
) | SET(SBM_GETSCROLLBARINFO
),
122 SET(CB_GETEDITSEL
) | SET(CB_ADDSTRING
) | SET(CB_DIR
) | SET(CB_GETLBTEXT
) |
123 SET(CB_INSERTSTRING
) | SET(CB_FINDSTRING
) | SET(CB_SELECTSTRING
) |
124 SET(CB_GETDROPPEDCONTROLRECT
) | SET(CB_FINDSTRINGEXACT
),
128 SET(LB_ADDSTRING
) | SET(LB_INSERTSTRING
) | SET(LB_GETTEXT
) | SET(LB_SELECTSTRING
) |
129 SET(LB_DIR
) | SET(LB_FINDSTRING
) |
130 SET(LB_GETSELITEMS
) | SET(LB_SETTABSTOPS
) | SET(LB_ADDFILE
) | SET(LB_GETITEMRECT
),
132 SET(LB_FINDSTRINGEXACT
),
138 SET(WM_NEXTMENU
) | SET(WM_SIZING
) | SET(WM_MOVING
) | SET(WM_DEVICECHANGE
),
140 SET(WM_MDICREATE
) | SET(WM_MDIGETACTIVE
) | SET(WM_DROPOBJECT
) |
141 SET(WM_QUERYDROPOBJECT
) | SET(WM_DRAGLOOP
) | SET(WM_DRAGSELECT
) | SET(WM_DRAGMOVE
),
155 SET(WM_ASKCBFORMATNAME
)
158 /* flags for messages that contain Unicode strings */
159 static const unsigned int message_unicode_flags
[] =
162 SET(WM_CREATE
) | SET(WM_SETTEXT
) | SET(WM_GETTEXT
) | SET(WM_GETTEXTLENGTH
) |
163 SET(WM_WININICHANGE
) | SET(WM_DEVMODECHANGE
),
175 SET(EM_REPLACESEL
) | SET(EM_GETLINE
) | SET(EM_SETPASSWORDCHAR
),
179 SET(WM_CHAR
) | SET(WM_DEADCHAR
) | SET(WM_SYSCHAR
) | SET(WM_SYSDEADCHAR
),
183 SET(CB_ADDSTRING
) | SET(CB_DIR
) | SET(CB_GETLBTEXT
) | SET(CB_GETLBTEXTLEN
) |
184 SET(CB_INSERTSTRING
) | SET(CB_FINDSTRING
) | SET(CB_SELECTSTRING
) | SET(CB_FINDSTRINGEXACT
),
188 SET(LB_ADDSTRING
) | SET(LB_INSERTSTRING
) | SET(LB_GETTEXT
) | SET(LB_GETTEXTLEN
) |
189 SET(LB_SELECTSTRING
) | SET(LB_DIR
) | SET(LB_FINDSTRING
) | SET(LB_ADDFILE
),
191 SET(LB_FINDSTRINGEXACT
),
213 SET(WM_PAINTCLIPBOARD
) | SET(WM_SIZECLIPBOARD
) | SET(WM_ASKCBFORMATNAME
)
216 /* check whether a given message type includes pointers */
217 inline static int is_pointer_message( UINT message
)
219 if (message
>= 8*sizeof(message_pointer_flags
)) return FALSE
;
220 return (message_pointer_flags
[message
/ 32] & SET(message
)) != 0;
223 /* check whether a given message type contains Unicode (or ASCII) chars */
224 inline static int is_unicode_message( UINT message
)
226 if (message
>= 8*sizeof(message_unicode_flags
)) return FALSE
;
227 return (message_unicode_flags
[message
/ 32] & SET(message
)) != 0;
232 /* add a data field to a packed message */
233 inline static void push_data( struct packed_message
*data
, const void *ptr
, size_t size
)
235 data
->data
[data
->count
] = ptr
;
236 data
->size
[data
->count
] = size
;
240 /* add a string to a packed message */
241 inline static void push_string( struct packed_message
*data
, LPCWSTR str
)
243 push_data( data
, str
, (strlenW(str
) + 1) * sizeof(WCHAR
) );
246 /* retrieve a pointer to data from a packed message and increment the buffer pointer */
247 inline static void *get_data( void **buffer
, size_t size
)
250 *buffer
= (char *)*buffer
+ size
;
254 /* make sure that the buffer contains a valid null-terminated Unicode string */
255 inline static BOOL
check_string( LPCWSTR str
, size_t size
)
257 for (size
/= sizeof(WCHAR
); size
; size
--, str
++)
258 if (!*str
) return TRUE
;
262 /* make sure that there is space for 'size' bytes in buffer, growing it if needed */
263 inline static void *get_buffer_space( void **buffer
, size_t size
)
269 if (!(ret
= HeapReAlloc( GetProcessHeap(), 0, *buffer
, size
)))
270 HeapFree( GetProcessHeap(), 0, *buffer
);
272 else ret
= HeapAlloc( GetProcessHeap(), 0, size
);
278 /* retrieve a string pointer from packed data */
279 inline static LPWSTR
get_string( void **buffer
)
281 return get_data( buffer
, (strlenW( (LPWSTR
)*buffer
) + 1) * sizeof(WCHAR
) );
284 /* check whether a combobox expects strings or ids in CB_ADDSTRING/CB_INSERTSTRING */
285 inline static BOOL
combobox_has_strings( HWND hwnd
)
287 DWORD style
= GetWindowLongA( hwnd
, GWL_STYLE
);
288 return (!(style
& (CBS_OWNERDRAWFIXED
| CBS_OWNERDRAWVARIABLE
)) || (style
& CBS_HASSTRINGS
));
291 /* check whether a listbox expects strings or ids in LB_ADDSTRING/LB_INSERTSTRING */
292 inline static BOOL
listbox_has_strings( HWND hwnd
)
294 DWORD style
= GetWindowLongA( hwnd
, GWL_STYLE
);
295 return (!(style
& (LBS_OWNERDRAWFIXED
| LBS_OWNERDRAWVARIABLE
)) || (style
& LBS_HASSTRINGS
));
298 /* check whether message is in the range of keyboard messages */
299 inline static BOOL
is_keyboard_message( UINT message
)
301 return (message
>= WM_KEYFIRST
&& message
<= WM_KEYLAST
);
304 /* check whether message is in the range of mouse messages */
305 inline static BOOL
is_mouse_message( UINT message
)
307 return ((message
>= WM_NCMOUSEFIRST
&& message
<= WM_NCMOUSELAST
) ||
308 (message
>= WM_MOUSEFIRST
&& message
<= WM_MOUSELAST
));
311 /* check whether message matches the specified hwnd filter */
312 inline static BOOL
check_hwnd_filter( const MSG
*msg
, HWND hwnd_filter
)
314 if (!hwnd_filter
) return TRUE
;
315 return (msg
->hwnd
== hwnd_filter
|| IsChild( hwnd_filter
, msg
->hwnd
));
319 /***********************************************************************
320 * broadcast_message_callback
322 * Helper callback for broadcasting messages.
324 static BOOL CALLBACK
broadcast_message_callback( HWND hwnd
, LPARAM lparam
)
326 struct send_message_info
*info
= (struct send_message_info
*)lparam
;
327 if (!(GetWindowLongW( hwnd
, GWL_STYLE
) & (WS_POPUP
|WS_CAPTION
))) return TRUE
;
331 SendMessageTimeoutW( hwnd
, info
->msg
, info
->wparam
, info
->lparam
,
332 info
->flags
, info
->timeout
, NULL
);
335 SendMessageTimeoutA( hwnd
, info
->msg
, info
->wparam
, info
->lparam
,
336 info
->flags
, info
->timeout
, NULL
);
339 SendNotifyMessageW( hwnd
, info
->msg
, info
->wparam
, info
->lparam
);
342 SendMessageCallbackW( hwnd
, info
->msg
, info
->wparam
, info
->lparam
,
343 info
->callback
, info
->data
);
346 PostMessageW( hwnd
, info
->msg
, info
->wparam
, info
->lparam
);
349 ERR( "bad type %d\n", info
->type
);
356 /***********************************************************************
359 * Convert the wparam of an ASCII message to Unicode.
361 static WPARAM
map_wparam_AtoW( UINT message
, WPARAM wparam
)
366 case EM_SETPASSWORDCHAR
:
375 ch
[0] = (wparam
& 0xff);
376 ch
[1] = (wparam
>> 8);
377 MultiByteToWideChar(CP_ACP
, 0, ch
, 2, wch
, 2);
378 wparam
= MAKEWPARAM(wch
[0], wch
[1]);
385 ch
[0] = (wparam
>> 8);
386 ch
[1] = (wparam
& 0xff);
387 if (ch
[0]) MultiByteToWideChar(CP_ACP
, 0, ch
, 2, &wch
, 1);
388 else MultiByteToWideChar(CP_ACP
, 0, &ch
[1], 1, &wch
, 1);
389 wparam
= MAKEWPARAM( wch
, HIWORD(wparam
) );
397 /***********************************************************************
400 * Convert the wparam of a Unicode message to ASCII.
402 static WPARAM
map_wparam_WtoA( UINT message
, WPARAM wparam
)
407 case EM_SETPASSWORDCHAR
:
416 wch
[0] = LOWORD(wparam
);
417 wch
[1] = HIWORD(wparam
);
418 WideCharToMultiByte( CP_ACP
, 0, wch
, 2, (LPSTR
)ch
, 2, NULL
, NULL
);
419 wparam
= MAKEWPARAM( ch
[0] | (ch
[1] << 8), 0 );
424 WCHAR wch
= LOWORD(wparam
);
427 if (WideCharToMultiByte( CP_ACP
, 0, &wch
, 1, (LPSTR
)ch
, 2, NULL
, NULL
) == 2)
428 wparam
= MAKEWPARAM( (ch
[0] << 8) | ch
[1], HIWORD(wparam
) );
430 wparam
= MAKEWPARAM( ch
[0], HIWORD(wparam
) );
438 /***********************************************************************
441 * Pack a message for sending to another process.
442 * Return the size of the data we expect in the message reply.
443 * Set data->count to -1 if there is an error.
445 static size_t pack_message( HWND hwnd
, UINT message
, WPARAM wparam
, LPARAM lparam
,
446 struct packed_message
*data
)
454 CREATESTRUCTW
*cs
= (CREATESTRUCTW
*)lparam
;
455 push_data( data
, cs
, sizeof(*cs
) );
456 if (HIWORD(cs
->lpszName
)) push_string( data
, cs
->lpszName
);
457 if (HIWORD(cs
->lpszClass
)) push_string( data
, cs
->lpszClass
);
461 case WM_ASKCBFORMATNAME
:
462 return wparam
* sizeof(WCHAR
);
463 case WM_WININICHANGE
:
464 if (lparam
) push_string(data
, (LPWSTR
)lparam
);
467 case WM_DEVMODECHANGE
:
472 push_string( data
, (LPWSTR
)lparam
);
474 case WM_GETMINMAXINFO
:
475 push_data( data
, (MINMAXINFO
*)lparam
, sizeof(MINMAXINFO
) );
476 return sizeof(MINMAXINFO
);
478 push_data( data
, (DRAWITEMSTRUCT
*)lparam
, sizeof(DRAWITEMSTRUCT
) );
481 push_data( data
, (MEASUREITEMSTRUCT
*)lparam
, sizeof(MEASUREITEMSTRUCT
) );
482 return sizeof(MEASUREITEMSTRUCT
);
484 push_data( data
, (DELETEITEMSTRUCT
*)lparam
, sizeof(DELETEITEMSTRUCT
) );
487 push_data( data
, (COMPAREITEMSTRUCT
*)lparam
, sizeof(COMPAREITEMSTRUCT
) );
489 case WM_WINDOWPOSCHANGING
:
490 case WM_WINDOWPOSCHANGED
:
491 push_data( data
, (WINDOWPOS
*)lparam
, sizeof(WINDOWPOS
) );
492 return sizeof(WINDOWPOS
);
495 COPYDATASTRUCT
*cp
= (COPYDATASTRUCT
*)lparam
;
496 push_data( data
, cp
, sizeof(*cp
) );
497 if (cp
->lpData
) push_data( data
, cp
->lpData
, cp
->cbData
);
501 /* WM_NOTIFY cannot be sent across processes (MSDN) */
505 push_data( data
, (HELPINFO
*)lparam
, sizeof(HELPINFO
) );
507 case WM_STYLECHANGING
:
508 case WM_STYLECHANGED
:
509 push_data( data
, (STYLESTRUCT
*)lparam
, sizeof(STYLESTRUCT
) );
514 push_data( data
, (RECT
*)lparam
, sizeof(RECT
) );
519 NCCALCSIZE_PARAMS
*nc
= (NCCALCSIZE_PARAMS
*)lparam
;
520 push_data( data
, nc
, sizeof(*nc
) );
521 push_data( data
, nc
->lppos
, sizeof(*nc
->lppos
) );
522 return sizeof(*nc
) + sizeof(*nc
->lppos
);
525 if (lparam
) push_data( data
, (MSG
*)lparam
, sizeof(MSG
) );
527 case SBM_SETSCROLLINFO
:
528 push_data( data
, (SCROLLINFO
*)lparam
, sizeof(SCROLLINFO
) );
530 case SBM_GETSCROLLINFO
:
531 push_data( data
, (SCROLLINFO
*)lparam
, sizeof(SCROLLINFO
) );
532 return sizeof(SCROLLINFO
);
533 case SBM_GETSCROLLBARINFO
:
535 const SCROLLBARINFO
*info
= (const SCROLLBARINFO
*)lparam
;
536 size_t size
= min( info
->cbSize
, sizeof(SCROLLBARINFO
) );
537 push_data( data
, info
, size
);
545 if (wparam
) size
+= sizeof(DWORD
);
546 if (lparam
) size
+= sizeof(DWORD
);
551 case CB_GETDROPPEDCONTROLRECT
:
555 push_data( data
, (RECT
*)lparam
, sizeof(RECT
) );
559 WORD
*pw
= (WORD
*)lparam
;
560 push_data( data
, pw
, sizeof(*pw
) );
561 return *pw
* sizeof(WCHAR
);
565 if (wparam
) push_data( data
, (UINT
*)lparam
, sizeof(UINT
) * wparam
);
568 case CB_INSERTSTRING
:
570 case CB_FINDSTRINGEXACT
:
571 case CB_SELECTSTRING
:
572 if (combobox_has_strings( hwnd
)) push_string( data
, (LPWSTR
)lparam
);
575 if (!combobox_has_strings( hwnd
)) return sizeof(ULONG_PTR
);
576 return (SendMessageW( hwnd
, CB_GETLBTEXTLEN
, wparam
, 0 ) + 1) * sizeof(WCHAR
);
578 case LB_INSERTSTRING
:
580 case LB_FINDSTRINGEXACT
:
581 case LB_SELECTSTRING
:
582 if (listbox_has_strings( hwnd
)) push_string( data
, (LPWSTR
)lparam
);
585 if (!listbox_has_strings( hwnd
)) return sizeof(ULONG_PTR
);
586 return (SendMessageW( hwnd
, LB_GETTEXTLEN
, wparam
, 0 ) + 1) * sizeof(WCHAR
);
588 return wparam
* sizeof(UINT
);
590 push_data( data
, (MDINEXTMENU
*)lparam
, sizeof(MDINEXTMENU
) );
591 return sizeof(MDINEXTMENU
);
594 push_data( data
, (RECT
*)lparam
, sizeof(RECT
) );
598 MDICREATESTRUCTW
*cs
= (MDICREATESTRUCTW
*)lparam
;
599 push_data( data
, cs
, sizeof(*cs
) );
600 if (HIWORD(cs
->szTitle
)) push_string( data
, cs
->szTitle
);
601 if (HIWORD(cs
->szClass
)) push_string( data
, cs
->szClass
);
604 case WM_MDIGETACTIVE
:
605 if (lparam
) return sizeof(BOOL
);
607 case WM_DEVICECHANGE
:
609 DEV_BROADCAST_HDR
*header
= (DEV_BROADCAST_HDR
*)lparam
;
610 push_data( data
, header
, header
->dbch_size
);
613 case WM_WINE_SETWINDOWPOS
:
614 push_data( data
, (WINDOWPOS
*)lparam
, sizeof(WINDOWPOS
) );
616 case WM_WINE_KEYBOARD_LL_HOOK
:
617 push_data( data
, (KBDLLHOOKSTRUCT
*)lparam
, sizeof(KBDLLHOOKSTRUCT
) );
619 case WM_WINE_MOUSE_LL_HOOK
:
620 push_data( data
, (MSLLHOOKSTRUCT
*)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 minsize
= sizeof(KBDLLHOOKSTRUCT
);
883 case WM_WINE_MOUSE_LL_HOOK
:
884 minsize
= sizeof(MSLLHOOKSTRUCT
);
887 if (*wparam
<= 1) return TRUE
;
888 FIXME( "WM_NCPAINT hdc unpacking not supported\n" );
891 if (!*wparam
) return TRUE
;
894 /* these contain an HFONT */
897 /* these contain an HDC */
899 case WM_ICONERASEBKGND
:
900 case WM_CTLCOLORMSGBOX
:
901 case WM_CTLCOLOREDIT
:
902 case WM_CTLCOLORLISTBOX
:
905 case WM_CTLCOLORSCROLLBAR
:
906 case WM_CTLCOLORSTATIC
:
909 /* these contain an HGLOBAL */
910 case WM_PAINTCLIPBOARD
:
911 case WM_SIZECLIPBOARD
:
912 /* these contain HICON */
915 case WM_QUERYDRAGICON
:
916 case WM_QUERYPARKICON
:
917 /* these contain pointers */
919 case WM_QUERYDROPOBJECT
:
923 FIXME( "msg %x (%s) not supported yet\n", message
, SPY_GetMsgName(message
, hwnd
) );
927 return TRUE
; /* message doesn't need any unpacking */
930 /* default exit for most messages: check minsize and store buffer in lparam */
931 if (size
< minsize
) return FALSE
;
932 *lparam
= (LPARAM
)*buffer
;
937 /***********************************************************************
940 * Pack a reply to a message for sending to another process.
942 static void pack_reply( HWND hwnd
, UINT message
, WPARAM wparam
, LPARAM lparam
,
943 LRESULT res
, struct packed_message
*data
)
950 push_data( data
, (CREATESTRUCTW
*)lparam
, sizeof(CREATESTRUCTW
) );
955 push_data( data
, (WCHAR
*)lparam
, (res
+ 1) * sizeof(WCHAR
) );
957 case WM_GETMINMAXINFO
:
958 push_data( data
, (MINMAXINFO
*)lparam
, sizeof(MINMAXINFO
) );
961 push_data( data
, (MEASUREITEMSTRUCT
*)lparam
, sizeof(MEASUREITEMSTRUCT
) );
963 case WM_WINDOWPOSCHANGING
:
964 case WM_WINDOWPOSCHANGED
:
965 push_data( data
, (WINDOWPOS
*)lparam
, sizeof(WINDOWPOS
) );
968 if (lparam
) push_data( data
, (MSG
*)lparam
, sizeof(MSG
) );
970 case SBM_GETSCROLLINFO
:
971 push_data( data
, (SCROLLINFO
*)lparam
, sizeof(SCROLLINFO
) );
975 case CB_GETDROPPEDCONTROLRECT
:
978 push_data( data
, (RECT
*)lparam
, sizeof(RECT
) );
982 WORD
*ptr
= (WORD
*)lparam
;
983 push_data( data
, ptr
, ptr
[-1] * sizeof(WCHAR
) );
987 push_data( data
, (UINT
*)lparam
, wparam
* sizeof(UINT
) );
989 case WM_MDIGETACTIVE
:
990 if (lparam
) push_data( data
, (BOOL
*)lparam
, sizeof(BOOL
) );
994 push_data( data
, (RECT
*)lparam
, sizeof(RECT
) );
997 NCCALCSIZE_PARAMS
*nc
= (NCCALCSIZE_PARAMS
*)lparam
;
998 push_data( data
, nc
, sizeof(*nc
) );
999 push_data( data
, nc
->lppos
, sizeof(*nc
->lppos
) );
1005 if (wparam
) push_data( data
, (DWORD
*)wparam
, sizeof(DWORD
) );
1006 if (lparam
) push_data( data
, (DWORD
*)lparam
, sizeof(DWORD
) );
1009 push_data( data
, (MDINEXTMENU
*)lparam
, sizeof(MDINEXTMENU
) );
1012 push_data( data
, (MDICREATESTRUCTW
*)lparam
, sizeof(MDICREATESTRUCTW
) );
1014 case WM_ASKCBFORMATNAME
:
1015 push_data( data
, (WCHAR
*)lparam
, (strlenW((WCHAR
*)lparam
) + 1) * sizeof(WCHAR
) );
1021 /***********************************************************************
1024 * Unpack a message reply received from another process.
1026 static void unpack_reply( HWND hwnd
, UINT message
, WPARAM wparam
, LPARAM lparam
,
1027 void *buffer
, size_t size
)
1034 CREATESTRUCTW
*cs
= (CREATESTRUCTW
*)lparam
;
1035 LPCWSTR name
= cs
->lpszName
, class = cs
->lpszClass
;
1036 memcpy( cs
, buffer
, min( sizeof(*cs
), size
));
1037 cs
->lpszName
= name
; /* restore the original pointers */
1038 cs
->lpszClass
= class;
1042 case WM_ASKCBFORMATNAME
:
1043 memcpy( (WCHAR
*)lparam
, buffer
, min( wparam
*sizeof(WCHAR
), size
));
1045 case WM_GETMINMAXINFO
:
1046 memcpy( (MINMAXINFO
*)lparam
, buffer
, min( sizeof(MINMAXINFO
), size
));
1048 case WM_MEASUREITEM
:
1049 memcpy( (MEASUREITEMSTRUCT
*)lparam
, buffer
, min( sizeof(MEASUREITEMSTRUCT
), size
));
1051 case WM_WINDOWPOSCHANGING
:
1052 case WM_WINDOWPOSCHANGED
:
1053 memcpy( (WINDOWPOS
*)lparam
, buffer
, min( sizeof(WINDOWPOS
), size
));
1056 if (lparam
) memcpy( (MSG
*)lparam
, buffer
, min( sizeof(MSG
), size
));
1058 case SBM_GETSCROLLINFO
:
1059 memcpy( (SCROLLINFO
*)lparam
, buffer
, min( sizeof(SCROLLINFO
), size
));
1061 case SBM_GETSCROLLBARINFO
:
1062 memcpy( (SCROLLBARINFO
*)lparam
, buffer
, min( sizeof(SCROLLBARINFO
), size
));
1065 case CB_GETDROPPEDCONTROLRECT
:
1066 case LB_GETITEMRECT
:
1069 memcpy( (RECT
*)lparam
, buffer
, min( sizeof(RECT
), size
));
1072 size
= min( size
, (size_t)*(WORD
*)lparam
);
1073 memcpy( (WCHAR
*)lparam
, buffer
, size
);
1075 case LB_GETSELITEMS
:
1076 memcpy( (UINT
*)lparam
, buffer
, min( wparam
*sizeof(UINT
), size
));
1080 memcpy( (WCHAR
*)lparam
, buffer
, size
);
1083 memcpy( (MDINEXTMENU
*)lparam
, buffer
, min( sizeof(MDINEXTMENU
), size
));
1085 case WM_MDIGETACTIVE
:
1086 if (lparam
) memcpy( (BOOL
*)lparam
, buffer
, min( sizeof(BOOL
), size
));
1090 memcpy( (RECT
*)lparam
, buffer
, min( sizeof(RECT
), size
));
1093 NCCALCSIZE_PARAMS
*nc
= (NCCALCSIZE_PARAMS
*)lparam
;
1094 WINDOWPOS
*wp
= nc
->lppos
;
1095 memcpy( nc
, buffer
, min( sizeof(*nc
), size
));
1096 if (size
> sizeof(*nc
))
1098 size
-= sizeof(*nc
);
1099 memcpy( wp
, (NCCALCSIZE_PARAMS
*)buffer
+ 1, min( sizeof(*wp
), size
));
1101 nc
->lppos
= wp
; /* restore the original pointer */
1109 memcpy( (DWORD
*)wparam
, buffer
, min( sizeof(DWORD
), size
));
1110 if (size
<= sizeof(DWORD
)) break;
1111 size
-= sizeof(DWORD
);
1112 buffer
= (DWORD
*)buffer
+ 1;
1114 if (lparam
) memcpy( (DWORD
*)lparam
, buffer
, min( sizeof(DWORD
), size
));
1118 MDICREATESTRUCTW
*cs
= (MDICREATESTRUCTW
*)lparam
;
1119 LPCWSTR title
= cs
->szTitle
, class = cs
->szClass
;
1120 memcpy( cs
, buffer
, min( sizeof(*cs
), size
));
1121 cs
->szTitle
= title
; /* restore the original pointers */
1122 cs
->szClass
= class;
1126 ERR( "should not happen: unexpected message %x\n", message
);
1132 /***********************************************************************
1135 * Send a reply to a sent message.
1137 static void reply_message( struct received_message_info
*info
, LRESULT result
, BOOL remove
)
1139 struct packed_message data
;
1140 int i
, replied
= info
->flags
& ISMEX_REPLIED
;
1142 if (info
->flags
& ISMEX_NOTIFY
) return; /* notify messages don't get replies */
1143 if (!remove
&& replied
) return; /* replied already */
1146 info
->flags
|= ISMEX_REPLIED
;
1148 if (info
->type
== MSG_OTHER_PROCESS
&& !replied
)
1150 pack_reply( info
->msg
.hwnd
, info
->msg
.message
, info
->msg
.wParam
,
1151 info
->msg
.lParam
, result
, &data
);
1154 SERVER_START_REQ( reply_message
)
1156 req
->result
= result
;
1157 req
->remove
= remove
;
1158 for (i
= 0; i
< data
.count
; i
++) wine_server_add_data( req
, data
.data
[i
], data
.size
[i
] );
1159 wine_server_call( req
);
1165 /***********************************************************************
1166 * handle_internal_message
1168 * Handle an internal Wine message instead of calling the window proc.
1170 static LRESULT
handle_internal_message( HWND hwnd
, UINT msg
, WPARAM wparam
, LPARAM lparam
)
1174 case WM_WINE_DESTROYWINDOW
:
1175 return WIN_DestroyWindow( hwnd
);
1176 case WM_WINE_SETWINDOWPOS
:
1177 if (hwnd
== GetDesktopWindow()) return 0;
1178 return USER_Driver
->pSetWindowPos( (WINDOWPOS
*)lparam
);
1179 case WM_WINE_SHOWWINDOW
:
1180 if (hwnd
== GetDesktopWindow()) return 0;
1181 return ShowWindow( hwnd
, wparam
);
1182 case WM_WINE_SETPARENT
:
1183 if (hwnd
== GetDesktopWindow()) return 0;
1184 return (LRESULT
)SetParent( hwnd
, (HWND
)wparam
);
1185 case WM_WINE_SETWINDOWLONG
:
1186 return (LRESULT
)SetWindowLongW( hwnd
, wparam
, lparam
);
1187 case WM_WINE_ENABLEWINDOW
:
1188 if (hwnd
== GetDesktopWindow()) return 0;
1189 return EnableWindow( hwnd
, wparam
);
1190 case WM_WINE_SETACTIVEWINDOW
:
1191 if (hwnd
== GetDesktopWindow()) return 0;
1192 return (LRESULT
)SetActiveWindow( (HWND
)wparam
);
1193 case WM_WINE_KEYBOARD_LL_HOOK
:
1194 return HOOK_CallHooks( WH_KEYBOARD_LL
, HC_ACTION
, wparam
, lparam
, TRUE
);
1195 case WM_WINE_MOUSE_LL_HOOK
:
1196 return HOOK_CallHooks( WH_MOUSE_LL
, HC_ACTION
, wparam
, lparam
, TRUE
);
1198 if (msg
>= WM_WINE_FIRST_DRIVER_MSG
&& msg
<= WM_WINE_LAST_DRIVER_MSG
)
1199 return USER_Driver
->pWindowMessage( hwnd
, msg
, wparam
, lparam
);
1200 FIXME( "unknown internal message %x\n", msg
);
1205 /* since the WM_DDE_ACK response to a WM_DDE_EXECUTE message should contain the handle
1206 * to the memory handle, we keep track (in the server side) of all pairs of handle
1207 * used (the client passes its value and the content of the memory handle), and
1208 * the server stored both values (the client, and the local one, created after the
1209 * content). When a ACK message is generated, the list of pair is searched for a
1210 * matching pair, so that the client memory handle can be returned.
1213 HGLOBAL client_hMem
;
1214 HGLOBAL server_hMem
;
1217 static struct DDE_pair
* dde_pairs
;
1218 static int dde_num_alloc
;
1219 static int dde_num_used
;
1221 static CRITICAL_SECTION dde_crst
;
1222 static CRITICAL_SECTION_DEBUG critsect_debug
=
1225 { &critsect_debug
.ProcessLocksList
, &critsect_debug
.ProcessLocksList
},
1226 0, 0, { (DWORD_PTR
)(__FILE__
": dde_crst") }
1228 static CRITICAL_SECTION dde_crst
= { &critsect_debug
, -1, 0, 0, 0, 0 };
1230 static BOOL
dde_add_pair(HGLOBAL chm
, HGLOBAL shm
)
1235 EnterCriticalSection(&dde_crst
);
1237 /* now remember the pair of hMem on both sides */
1238 if (dde_num_used
== dde_num_alloc
)
1240 struct DDE_pair
* tmp
;
1242 tmp
= HeapReAlloc( GetProcessHeap(), 0, dde_pairs
,
1243 (dde_num_alloc
+ GROWBY
) * sizeof(struct DDE_pair
));
1245 tmp
= HeapAlloc( GetProcessHeap(), 0,
1246 (dde_num_alloc
+ GROWBY
) * sizeof(struct DDE_pair
));
1250 LeaveCriticalSection(&dde_crst
);
1254 /* zero out newly allocated part */
1255 memset(&dde_pairs
[dde_num_alloc
], 0, GROWBY
* sizeof(struct DDE_pair
));
1256 dde_num_alloc
+= GROWBY
;
1259 for (i
= 0; i
< dde_num_alloc
; i
++)
1261 if (dde_pairs
[i
].server_hMem
== 0)
1263 dde_pairs
[i
].client_hMem
= chm
;
1264 dde_pairs
[i
].server_hMem
= shm
;
1269 LeaveCriticalSection(&dde_crst
);
1273 static HGLOBAL
dde_get_pair(HGLOBAL shm
)
1278 EnterCriticalSection(&dde_crst
);
1279 for (i
= 0; i
< dde_num_alloc
; i
++)
1281 if (dde_pairs
[i
].server_hMem
== shm
)
1283 /* free this pair */
1284 dde_pairs
[i
].server_hMem
= 0;
1286 ret
= dde_pairs
[i
].client_hMem
;
1290 LeaveCriticalSection(&dde_crst
);
1294 /***********************************************************************
1297 * Post a DDE message
1299 static BOOL
post_dde_message( struct packed_message
*data
, const struct send_message_info
*info
)
1303 UINT_PTR uiLo
, uiHi
;
1305 HGLOBAL hunlock
= 0;
1309 if (!UnpackDDElParam( info
->msg
, info
->lparam
, &uiLo
, &uiHi
))
1315 /* DDE messages which don't require packing are:
1324 /* uiHi should contain a hMem from WM_DDE_EXECUTE */
1325 HGLOBAL h
= dde_get_pair( (HANDLE
)uiHi
);
1328 /* send back the value of h on the other side */
1329 push_data( data
, &h
, sizeof(HGLOBAL
) );
1331 TRACE( "send dde-ack %x %08x => %p\n", uiLo
, uiHi
, h
);
1336 /* uiHi should contain either an atom or 0 */
1337 TRACE( "send dde-ack %x atom=%x\n", uiLo
, uiHi
);
1338 lp
= MAKELONG( uiLo
, uiHi
);
1347 size
= GlobalSize( (HGLOBAL
)uiLo
) ;
1348 if ((info
->msg
== WM_DDE_ADVISE
&& size
< sizeof(DDEADVISE
)) ||
1349 (info
->msg
== WM_DDE_DATA
&& size
< sizeof(DDEDATA
)) ||
1350 (info
->msg
== WM_DDE_POKE
&& size
< sizeof(DDEPOKE
))
1354 else if (info
->msg
!= WM_DDE_DATA
) return FALSE
;
1359 if ((ptr
= GlobalLock( (HGLOBAL
)uiLo
) ))
1361 DDEDATA
*dde_data
= (DDEDATA
*)ptr
;
1362 TRACE("unused %d, fResponse %d, fRelease %d, fDeferUpd %d, fAckReq %d, cfFormat %d\n",
1363 dde_data
->unused
, dde_data
->fResponse
, dde_data
->fRelease
,
1364 dde_data
->reserved
, dde_data
->fAckReq
, dde_data
->cfFormat
);
1365 push_data( data
, ptr
, size
);
1366 hunlock
= (HGLOBAL
)uiLo
;
1369 TRACE( "send ddepack %u %x\n", size
, uiHi
);
1371 case WM_DDE_EXECUTE
:
1374 if ((ptr
= GlobalLock( (HGLOBAL
)info
->lparam
) ))
1376 push_data(data
, ptr
, GlobalSize( (HGLOBAL
)info
->lparam
));
1377 /* so that the other side can send it back on ACK */
1379 hunlock
= (HGLOBAL
)info
->lparam
;
1384 SERVER_START_REQ( send_message
)
1386 req
->id
= info
->dest_tid
;
1387 req
->type
= info
->type
;
1389 req
->win
= info
->hwnd
;
1390 req
->msg
= info
->msg
;
1391 req
->wparam
= info
->wparam
;
1393 req
->time
= GetCurrentTime();
1395 for (i
= 0; i
< data
->count
; i
++)
1396 wine_server_add_data( req
, data
->data
[i
], data
->size
[i
] );
1397 if ((res
= wine_server_call( req
)))
1399 if (res
== STATUS_INVALID_PARAMETER
)
1400 /* FIXME: find a STATUS_ value for this one */
1401 SetLastError( ERROR_INVALID_THREAD_ID
);
1403 SetLastError( RtlNtStatusToDosError(res
) );
1406 FreeDDElParam(info
->msg
, info
->lparam
);
1409 if (hunlock
) GlobalUnlock(hunlock
);
1414 /***********************************************************************
1415 * unpack_dde_message
1417 * Unpack a posted DDE message received from another process.
1419 static BOOL
unpack_dde_message( HWND hwnd
, UINT message
, WPARAM
*wparam
, LPARAM
*lparam
,
1420 void **buffer
, size_t size
)
1422 UINT_PTR uiLo
, uiHi
;
1431 /* hMem is being passed */
1432 if (size
!= sizeof(HGLOBAL
)) return FALSE
;
1433 if (!buffer
|| !*buffer
) return FALSE
;
1435 memcpy( &hMem
, *buffer
, size
);
1436 uiHi
= (UINT_PTR
)hMem
;
1437 TRACE("recv dde-ack %x mem=%x[%lx]\n", uiLo
, uiHi
, GlobalSize( hMem
));
1441 uiLo
= LOWORD( *lparam
);
1442 uiHi
= HIWORD( *lparam
);
1443 TRACE("recv dde-ack %x atom=%x\n", uiLo
, uiHi
);
1445 *lparam
= PackDDElParam( WM_DDE_ACK
, uiLo
, uiHi
);
1450 if ((!buffer
|| !*buffer
) && message
!= WM_DDE_DATA
) return FALSE
;
1454 if (!(hMem
= GlobalAlloc( GMEM_MOVEABLE
|GMEM_DDESHARE
, size
)))
1456 if ((ptr
= GlobalLock( hMem
)))
1458 memcpy( ptr
, *buffer
, size
);
1459 GlobalUnlock( hMem
);
1467 uiLo
= (UINT_PTR
)hMem
;
1469 *lparam
= PackDDElParam( message
, uiLo
, uiHi
);
1471 case WM_DDE_EXECUTE
:
1474 if (!buffer
|| !*buffer
) return FALSE
;
1475 if (!(hMem
= GlobalAlloc( GMEM_MOVEABLE
|GMEM_DDESHARE
, size
))) return FALSE
;
1476 if ((ptr
= GlobalLock( hMem
)))
1478 memcpy( ptr
, *buffer
, size
);
1479 GlobalUnlock( hMem
);
1480 TRACE( "exec: pairing c=%08lx s=%08lx\n", *lparam
, (DWORD
)hMem
);
1481 if (!dde_add_pair( (HGLOBAL
)*lparam
, hMem
))
1492 } else return FALSE
;
1493 *lparam
= (LPARAM
)hMem
;
1499 /***********************************************************************
1502 * Call a window procedure and the corresponding hooks.
1504 static LRESULT
call_window_proc( HWND hwnd
, UINT msg
, WPARAM wparam
, LPARAM lparam
,
1505 BOOL unicode
, BOOL same_thread
)
1507 struct user_thread_info
*thread_info
= get_user_thread_info();
1511 CWPRETSTRUCT cwpret
;
1513 if (thread_info
->recursion_count
> MAX_SENDMSG_RECURSION
) return 0;
1514 thread_info
->recursion_count
++;
1516 if (msg
& 0x80000000)
1518 result
= handle_internal_message( hwnd
, msg
, wparam
, lparam
);
1522 /* first the WH_CALLWNDPROC hook */
1523 hwnd
= WIN_GetFullHandle( hwnd
);
1524 cwp
.lParam
= lparam
;
1525 cwp
.wParam
= wparam
;
1528 HOOK_CallHooks( WH_CALLWNDPROC
, HC_ACTION
, same_thread
, (LPARAM
)&cwp
, unicode
);
1530 /* now call the window procedure */
1533 if (!(winproc
= (WNDPROC
)GetWindowLongPtrW( hwnd
, GWLP_WNDPROC
))) goto done
;
1534 result
= CallWindowProcW( winproc
, hwnd
, msg
, wparam
, lparam
);
1538 if (!(winproc
= (WNDPROC
)GetWindowLongPtrA( hwnd
, GWLP_WNDPROC
))) goto done
;
1539 result
= CallWindowProcA( winproc
, hwnd
, msg
, wparam
, lparam
);
1542 /* and finally the WH_CALLWNDPROCRET hook */
1543 cwpret
.lResult
= result
;
1544 cwpret
.lParam
= lparam
;
1545 cwpret
.wParam
= wparam
;
1546 cwpret
.message
= msg
;
1548 HOOK_CallHooks( WH_CALLWNDPROCRET
, HC_ACTION
, same_thread
, (LPARAM
)&cwpret
, unicode
);
1550 thread_info
->recursion_count
--;
1555 /***********************************************************************
1556 * send_parent_notify
1558 * Send a WM_PARENTNOTIFY to all ancestors of the given window, unless
1559 * the window has the WS_EX_NOPARENTNOTIFY style.
1561 static void send_parent_notify( HWND hwnd
, WORD event
, WORD idChild
, POINT pt
)
1563 /* pt has to be in the client coordinates of the parent window */
1564 MapWindowPoints( 0, hwnd
, &pt
, 1 );
1569 if (!(GetWindowLongW( hwnd
, GWL_STYLE
) & WS_CHILD
)) break;
1570 if (GetWindowLongW( hwnd
, GWL_EXSTYLE
) & WS_EX_NOPARENTNOTIFY
) break;
1571 if (!(parent
= GetParent(hwnd
))) break;
1572 if (parent
== GetDesktopWindow()) break;
1573 MapWindowPoints( hwnd
, parent
, &pt
, 1 );
1575 SendMessageW( hwnd
, WM_PARENTNOTIFY
,
1576 MAKEWPARAM( event
, idChild
), MAKELPARAM( pt
.x
, pt
.y
) );
1581 /***********************************************************************
1582 * accept_hardware_message
1584 * Tell the server we have passed the message to the app
1585 * (even though we may end up dropping it later on)
1587 static void accept_hardware_message( UINT hw_id
, BOOL remove
, HWND new_hwnd
)
1589 SERVER_START_REQ( accept_hardware_message
)
1592 req
->remove
= remove
;
1593 req
->new_win
= new_hwnd
;
1594 if (wine_server_call( req
))
1595 FIXME("Failed to reply to MSG_HARDWARE message. Message may not be removed from queue.\n");
1601 /***********************************************************************
1602 * process_keyboard_message
1604 * returns TRUE if the contents of 'msg' should be passed to the application
1606 static BOOL
process_keyboard_message( MSG
*msg
, UINT hw_id
, HWND hwnd_filter
,
1607 UINT first
, UINT last
, BOOL remove
)
1611 /* FIXME: is this really the right place for this hook? */
1612 event
.message
= msg
->message
;
1613 event
.hwnd
= msg
->hwnd
;
1614 event
.time
= msg
->time
;
1615 event
.paramL
= (msg
->wParam
& 0xFF) | (HIWORD(msg
->lParam
) << 8);
1616 event
.paramH
= msg
->lParam
& 0x7FFF;
1617 if (HIWORD(msg
->lParam
) & 0x0100) event
.paramH
|= 0x8000; /* special_key - bit */
1618 HOOK_CallHooks( WH_JOURNALRECORD
, HC_ACTION
, 0, (LPARAM
)&event
, TRUE
);
1620 /* check message filters */
1621 if (msg
->message
< first
|| msg
->message
> last
) return FALSE
;
1622 if (!check_hwnd_filter( msg
, hwnd_filter
)) return FALSE
;
1626 /* Handle F1 key by sending out WM_HELP message */
1627 if ((msg
->message
== WM_KEYUP
) &&
1628 (msg
->wParam
== VK_F1
) &&
1629 (msg
->hwnd
!= GetDesktopWindow()) &&
1630 !MENU_IsMenuActive())
1633 hi
.cbSize
= sizeof(HELPINFO
);
1634 hi
.iContextType
= HELPINFO_WINDOW
;
1635 hi
.iCtrlId
= GetWindowLongPtrA( msg
->hwnd
, GWLP_ID
);
1636 hi
.hItemHandle
= msg
->hwnd
;
1637 hi
.dwContextId
= GetWindowContextHelpId( msg
->hwnd
);
1638 hi
.MousePos
= msg
->pt
;
1639 SendMessageW( msg
->hwnd
, WM_HELP
, 0, (LPARAM
)&hi
);
1643 if (HOOK_CallHooks( WH_KEYBOARD
, remove
? HC_ACTION
: HC_NOREMOVE
,
1644 LOWORD(msg
->wParam
), msg
->lParam
, TRUE
))
1646 /* skip this message */
1647 HOOK_CallHooks( WH_CBT
, HCBT_KEYSKIPPED
, LOWORD(msg
->wParam
), msg
->lParam
, TRUE
);
1648 accept_hardware_message( hw_id
, TRUE
, 0 );
1651 accept_hardware_message( hw_id
, remove
, 0 );
1656 /***********************************************************************
1657 * process_mouse_message
1659 * returns TRUE if the contents of 'msg' should be passed to the application
1661 static BOOL
process_mouse_message( MSG
*msg
, UINT hw_id
, ULONG_PTR extra_info
, HWND hwnd_filter
,
1662 UINT first
, UINT last
, BOOL remove
)
1671 MOUSEHOOKSTRUCT hook
;
1674 /* find the window to dispatch this mouse message to */
1676 GetGUIThreadInfo( GetCurrentThreadId(), &info
);
1677 if (info
.hwndCapture
)
1680 msg
->hwnd
= info
.hwndCapture
;
1684 msg
->hwnd
= WINPOS_WindowFromPoint( msg
->hwnd
, msg
->pt
, &hittest
);
1687 if (!msg
->hwnd
|| !WIN_IsCurrentThread( msg
->hwnd
))
1689 accept_hardware_message( hw_id
, TRUE
, msg
->hwnd
);
1693 /* FIXME: is this really the right place for this hook? */
1694 event
.message
= msg
->message
;
1695 event
.time
= msg
->time
;
1696 event
.hwnd
= msg
->hwnd
;
1697 event
.paramL
= msg
->pt
.x
;
1698 event
.paramH
= msg
->pt
.y
;
1699 HOOK_CallHooks( WH_JOURNALRECORD
, HC_ACTION
, 0, (LPARAM
)&event
, TRUE
);
1701 if (!check_hwnd_filter( msg
, hwnd_filter
)) return FALSE
;
1704 message
= msg
->message
;
1705 /* Note: windows has no concept of a non-client wheel message */
1706 if (message
!= WM_MOUSEWHEEL
)
1708 if (hittest
!= HTCLIENT
)
1710 message
+= WM_NCMOUSEMOVE
- WM_MOUSEMOVE
;
1711 msg
->wParam
= hittest
;
1715 /* coordinates don't get translated while tracking a menu */
1716 /* FIXME: should differentiate popups and top-level menus */
1717 if (!(info
.flags
& GUI_INMENUMODE
))
1718 ScreenToClient( msg
->hwnd
, &pt
);
1721 msg
->lParam
= MAKELONG( pt
.x
, pt
.y
);
1723 /* translate double clicks */
1725 if ((msg
->message
== WM_LBUTTONDOWN
) ||
1726 (msg
->message
== WM_RBUTTONDOWN
) ||
1727 (msg
->message
== WM_MBUTTONDOWN
) ||
1728 (msg
->message
== WM_XBUTTONDOWN
))
1730 BOOL update
= remove
;
1732 /* translate double clicks -
1733 * note that ...MOUSEMOVEs can slip in between
1734 * ...BUTTONDOWN and ...BUTTONDBLCLK messages */
1736 if ((info
.flags
& (GUI_INMENUMODE
|GUI_INMOVESIZE
)) ||
1737 hittest
!= HTCLIENT
||
1738 (GetClassLongA( msg
->hwnd
, GCL_STYLE
) & CS_DBLCLKS
))
1740 if ((msg
->message
== clk_msg
.message
) &&
1741 (msg
->hwnd
== clk_msg
.hwnd
) &&
1742 (msg
->wParam
== clk_msg
.wParam
) &&
1743 (msg
->time
- clk_msg
.time
< GetDoubleClickTime()) &&
1744 (abs(msg
->pt
.x
- clk_msg
.pt
.x
) < GetSystemMetrics(SM_CXDOUBLECLK
)/2) &&
1745 (abs(msg
->pt
.y
- clk_msg
.pt
.y
) < GetSystemMetrics(SM_CYDOUBLECLK
)/2))
1747 message
+= (WM_LBUTTONDBLCLK
- WM_LBUTTONDOWN
);
1750 clk_msg
.message
= 0; /* clear the double click conditions */
1755 if (message
< first
|| message
> last
) return FALSE
;
1756 /* update static double click conditions */
1757 if (update
) clk_msg
= *msg
;
1761 if (message
< first
|| message
> last
) return FALSE
;
1764 /* message is accepted now (but may still get dropped) */
1767 hook
.hwnd
= msg
->hwnd
;
1768 hook
.wHitTestCode
= hittest
;
1769 hook
.dwExtraInfo
= extra_info
;
1770 if (HOOK_CallHooks( WH_MOUSE
, remove
? HC_ACTION
: HC_NOREMOVE
,
1771 message
, (LPARAM
)&hook
, TRUE
))
1774 hook
.hwnd
= msg
->hwnd
;
1775 hook
.wHitTestCode
= hittest
;
1776 hook
.dwExtraInfo
= extra_info
;
1777 HOOK_CallHooks( WH_CBT
, HCBT_CLICKSKIPPED
, message
, (LPARAM
)&hook
, TRUE
);
1778 accept_hardware_message( hw_id
, TRUE
, 0 );
1782 if ((hittest
== HTERROR
) || (hittest
== HTNOWHERE
))
1784 SendMessageW( msg
->hwnd
, WM_SETCURSOR
, (WPARAM
)msg
->hwnd
,
1785 MAKELONG( hittest
, msg
->message
));
1786 accept_hardware_message( hw_id
, TRUE
, 0 );
1790 accept_hardware_message( hw_id
, remove
, 0 );
1792 if (!remove
|| info
.hwndCapture
)
1794 msg
->message
= message
;
1800 if ((msg
->message
== WM_LBUTTONDOWN
) ||
1801 (msg
->message
== WM_RBUTTONDOWN
) ||
1802 (msg
->message
== WM_MBUTTONDOWN
) ||
1803 (msg
->message
== WM_XBUTTONDOWN
))
1805 /* Send the WM_PARENTNOTIFY,
1806 * note that even for double/nonclient clicks
1807 * notification message is still WM_L/M/RBUTTONDOWN.
1809 send_parent_notify( msg
->hwnd
, msg
->message
, 0, msg
->pt
);
1811 /* Activate the window if needed */
1813 if (msg
->hwnd
!= info
.hwndActive
)
1815 HWND hwndTop
= msg
->hwnd
;
1818 if ((GetWindowLongW( hwndTop
, GWL_STYLE
) & (WS_POPUP
|WS_CHILD
)) != WS_CHILD
) break;
1819 hwndTop
= GetParent( hwndTop
);
1822 if (hwndTop
&& hwndTop
!= GetDesktopWindow())
1824 LONG ret
= SendMessageW( msg
->hwnd
, WM_MOUSEACTIVATE
, (WPARAM
)hwndTop
,
1825 MAKELONG( hittest
, msg
->message
) );
1828 case MA_NOACTIVATEANDEAT
:
1833 case MA_ACTIVATEANDEAT
:
1838 if (!FOCUS_MouseActivate( hwndTop
)) eatMsg
= TRUE
;
1841 WARN( "unknown WM_MOUSEACTIVATE code %ld\n", ret
);
1848 /* send the WM_SETCURSOR message */
1850 /* Windows sends the normal mouse message as the message parameter
1851 in the WM_SETCURSOR message even if it's non-client mouse message */
1852 SendMessageW( msg
->hwnd
, WM_SETCURSOR
, (WPARAM
)msg
->hwnd
, MAKELONG( hittest
, msg
->message
));
1854 msg
->message
= message
;
1859 /***********************************************************************
1860 * process_hardware_message
1862 * Process a hardware message; return TRUE if message should be passed on to the app
1864 static BOOL
process_hardware_message( MSG
*msg
, UINT hw_id
, ULONG_PTR extra_info
, HWND hwnd_filter
,
1865 UINT first
, UINT last
, BOOL remove
)
1867 if (is_keyboard_message( msg
->message
))
1868 return process_keyboard_message( msg
, hw_id
, hwnd_filter
, first
, last
, remove
);
1870 if (is_mouse_message( msg
->message
))
1871 return process_mouse_message( msg
, hw_id
, extra_info
, hwnd_filter
, first
, last
, remove
);
1873 ERR( "unknown message type %x\n", msg
->message
);
1878 /***********************************************************************
1879 * call_sendmsg_callback
1881 * Call the callback function of SendMessageCallback.
1883 static inline void call_sendmsg_callback( SENDASYNCPROC callback
, HWND hwnd
, UINT msg
,
1884 ULONG_PTR data
, LRESULT result
)
1886 if (TRACE_ON(relay
))
1887 DPRINTF( "%04lx:Call message callback %p (hwnd=%p,msg=%s,data=%08lx,result=%08lx)\n",
1888 GetCurrentThreadId(), callback
, hwnd
, SPY_GetMsgName( msg
, hwnd
),
1890 callback( hwnd
, msg
, data
, result
);
1891 if (TRACE_ON(relay
))
1892 DPRINTF( "%04lx:Ret message callback %p (hwnd=%p,msg=%s,data=%08lx,result=%08lx)\n",
1893 GetCurrentThreadId(), callback
, hwnd
, SPY_GetMsgName( msg
, hwnd
),
1898 /***********************************************************************
1901 * Retrieve the hook procedure real value for a module-relative proc
1903 static void *get_hook_proc( void *proc
, const WCHAR
*module
)
1907 if (!(mod
= GetModuleHandleW(module
)))
1909 TRACE( "loading %s\n", debugstr_w(module
) );
1910 /* FIXME: the library will never be freed */
1911 if (!(mod
= LoadLibraryW(module
))) return NULL
;
1913 return (char *)mod
+ (ULONG_PTR
)proc
;
1917 /***********************************************************************
1920 * Peek for a message matching the given parameters. Return FALSE if none available.
1921 * All pending sent messages are processed before returning.
1923 static BOOL
peek_message( MSG
*msg
, HWND hwnd
, UINT first
, UINT last
, int flags
)
1926 ULONG_PTR extra_info
= 0;
1927 struct user_thread_info
*thread_info
= get_user_thread_info();
1928 struct received_message_info info
, *old_info
;
1929 unsigned int hw_id
= 0; /* id of previous hardware message */
1931 if (!first
&& !last
) last
= ~0;
1936 void *buffer
= NULL
;
1937 size_t size
= 0, buffer_size
= 0;
1939 do /* loop while buffer is too small */
1941 if (buffer_size
&& !(buffer
= HeapAlloc( GetProcessHeap(), 0, buffer_size
)))
1943 SERVER_START_REQ( get_message
)
1946 req
->get_win
= hwnd
;
1947 req
->get_first
= first
;
1948 req
->get_last
= last
;
1950 if (buffer_size
) wine_server_set_reply( req
, buffer
, buffer_size
);
1951 if (!(res
= wine_server_call( req
)))
1953 size
= wine_server_reply_size( reply
);
1954 info
.type
= reply
->type
;
1955 info
.msg
.hwnd
= reply
->win
;
1956 info
.msg
.message
= reply
->msg
;
1957 info
.msg
.wParam
= reply
->wparam
;
1958 info
.msg
.lParam
= reply
->lparam
;
1959 info
.msg
.time
= reply
->time
;
1960 info
.msg
.pt
.x
= reply
->x
;
1961 info
.msg
.pt
.y
= reply
->y
;
1962 info
.hook
= reply
->hook
;
1963 info
.hook_proc
= reply
->hook_proc
;
1964 hw_id
= reply
->hw_id
;
1965 extra_info
= reply
->info
;
1966 thread_info
->active_hooks
= reply
->active_hooks
;
1970 HeapFree( GetProcessHeap(), 0, buffer
);
1971 buffer_size
= reply
->total
;
1975 } while (res
== STATUS_BUFFER_OVERFLOW
);
1977 if (res
) return FALSE
;
1979 TRACE( "got type %d msg %x (%s) hwnd %p wp %x lp %lx\n",
1980 info
.type
, info
.msg
.message
,
1981 (info
.type
== MSG_WINEVENT
) ? "MSG_WINEVENT" : SPY_GetMsgName(info
.msg
.message
, info
.msg
.hwnd
),
1982 info
.msg
.hwnd
, info
.msg
.wParam
, info
.msg
.lParam
);
1988 info
.flags
= ISMEX_SEND
;
1991 info
.flags
= ISMEX_NOTIFY
;
1994 info
.flags
= ISMEX_CALLBACK
;
1996 case MSG_CALLBACK_RESULT
:
1997 call_sendmsg_callback( (SENDASYNCPROC
)info
.msg
.wParam
, info
.msg
.hwnd
,
1998 info
.msg
.message
, extra_info
, info
.msg
.lParam
);
2003 WCHAR module
[MAX_PATH
];
2004 size
= min( size
, (MAX_PATH
- 1) * sizeof(WCHAR
) );
2005 memcpy( module
, buffer
, size
);
2006 module
[size
/ sizeof(WCHAR
)] = 0;
2007 if (!(info
.hook_proc
= get_hook_proc( info
.hook_proc
, module
)))
2009 ERR( "invalid winevent hook module name %s\n", debugstr_w(module
) );
2013 if (TRACE_ON(relay
))
2014 DPRINTF( "%04lx:Call winevent proc %p (hook=%p,event=%x,hwnd=%p,object_id=%x,child_id=%lx,tid=%04lx,time=%lx)\n",
2015 GetCurrentThreadId(), info
.hook_proc
,
2016 info
.hook
, info
.msg
.message
, info
.msg
.hwnd
, info
.msg
.wParam
,
2017 info
.msg
.lParam
, extra_info
, info
.msg
.time
);
2019 info
.hook_proc( info
.hook
, info
.msg
.message
, info
.msg
.hwnd
, info
.msg
.wParam
,
2020 info
.msg
.lParam
, extra_info
, info
.msg
.time
);
2022 if (TRACE_ON(relay
))
2023 DPRINTF( "%04lx:Ret winevent proc %p (hook=%p,event=%x,hwnd=%p,object_id=%x,child_id=%lx,tid=%04lx,time=%lx)\n",
2024 GetCurrentThreadId(), info
.hook_proc
,
2025 info
.hook
, info
.msg
.message
, info
.msg
.hwnd
, info
.msg
.wParam
,
2026 info
.msg
.lParam
, extra_info
, info
.msg
.time
);
2028 case MSG_OTHER_PROCESS
:
2029 info
.flags
= ISMEX_SEND
;
2030 if (!unpack_message( info
.msg
.hwnd
, info
.msg
.message
, &info
.msg
.wParam
,
2031 &info
.msg
.lParam
, &buffer
, size
))
2034 reply_message( &info
, 0, TRUE
);
2039 if (!process_hardware_message( &info
.msg
, hw_id
, extra_info
,
2040 hwnd
, first
, last
, flags
& GET_MSG_REMOVE
))
2042 TRACE("dropping msg %x\n", info
.msg
.message
);
2043 goto next
; /* ignore it */
2045 thread_info
->GetMessagePosVal
= MAKELONG( info
.msg
.pt
.x
, info
.msg
.pt
.y
);
2048 thread_info
->GetMessageExtraInfoVal
= extra_info
;
2049 if (info
.msg
.message
>= WM_DDE_FIRST
&& info
.msg
.message
<= WM_DDE_LAST
)
2051 if (!unpack_dde_message( info
.msg
.hwnd
, info
.msg
.message
, &info
.msg
.wParam
,
2052 &info
.msg
.lParam
, &buffer
, size
))
2053 goto next
; /* ignore it */
2056 HeapFree( GetProcessHeap(), 0, buffer
);
2060 /* if we get here, we have a sent message; call the window procedure */
2061 old_info
= thread_info
->receive_info
;
2062 thread_info
->receive_info
= &info
;
2063 result
= call_window_proc( info
.msg
.hwnd
, info
.msg
.message
, info
.msg
.wParam
,
2064 info
.msg
.lParam
, (info
.type
!= MSG_ASCII
), FALSE
);
2065 reply_message( &info
, result
, TRUE
);
2066 thread_info
->receive_info
= old_info
;
2068 HeapFree( GetProcessHeap(), 0, buffer
);
2073 /***********************************************************************
2074 * process_sent_messages
2076 * Process all pending sent messages.
2078 inline static void process_sent_messages(void)
2081 peek_message( &msg
, 0, 0, 0, GET_MSG_REMOVE
| GET_MSG_SENT_ONLY
);
2085 /***********************************************************************
2086 * get_server_queue_handle
2088 * Get a handle to the server message queue for the current thread.
2090 static HANDLE
get_server_queue_handle(void)
2092 struct user_thread_info
*thread_info
= get_user_thread_info();
2095 if (!(ret
= thread_info
->server_queue
))
2097 SERVER_START_REQ( get_msg_queue
)
2099 wine_server_call( req
);
2100 ret
= reply
->handle
;
2103 thread_info
->server_queue
= ret
;
2104 if (!ret
) ERR( "Cannot get server thread queue\n" );
2110 /***********************************************************************
2111 * wait_message_reply
2113 * Wait until a sent message gets replied to.
2115 static void wait_message_reply( UINT flags
)
2117 HANDLE server_queue
= get_server_queue_handle();
2121 unsigned int wake_bits
= 0, changed_bits
= 0;
2124 SERVER_START_REQ( set_queue_mask
)
2126 req
->wake_mask
= QS_SMRESULT
| ((flags
& SMTO_BLOCK
) ? 0 : QS_SENDMESSAGE
);
2127 req
->changed_mask
= req
->wake_mask
;
2129 if (!wine_server_call( req
))
2131 wake_bits
= reply
->wake_bits
;
2132 changed_bits
= reply
->changed_bits
;
2137 if (wake_bits
& QS_SMRESULT
) return; /* got a result */
2138 if (wake_bits
& QS_SENDMESSAGE
)
2140 /* Process the sent message immediately */
2141 process_sent_messages();
2145 /* now wait for it */
2147 ReleaseThunkLock( &dwlc
);
2148 res
= USER_Driver
->pMsgWaitForMultipleObjectsEx( 1, &server_queue
,
2149 INFINITE
, QS_SENDMESSAGE
, 0 );
2150 if (dwlc
) RestoreThunkLock( dwlc
);
2154 /***********************************************************************
2155 * put_message_in_queue
2157 * Put a sent message into the destination queue.
2158 * For inter-process message, reply_size is set to expected size of reply data.
2160 static BOOL
put_message_in_queue( const struct send_message_info
*info
, size_t *reply_size
)
2162 struct packed_message data
;
2166 /* Check for INFINITE timeout for compatibility with Win9x,
2167 * although Windows >= NT does not do so
2169 if (info
->type
!= MSG_NOTIFY
&&
2170 info
->type
!= MSG_CALLBACK
&&
2171 info
->type
!= MSG_POSTED
&&
2172 info
->timeout
!= INFINITE
)
2173 timeout
= info
->timeout
;
2176 if (info
->type
== MSG_OTHER_PROCESS
)
2178 *reply_size
= pack_message( info
->hwnd
, info
->msg
, info
->wparam
, info
->lparam
, &data
);
2179 if (data
.count
== -1)
2181 WARN( "cannot pack message %x\n", info
->msg
);
2185 else if (info
->type
== MSG_POSTED
&& info
->msg
>= WM_DDE_FIRST
&& info
->msg
<= WM_DDE_LAST
)
2187 return post_dde_message( &data
, info
);
2190 SERVER_START_REQ( send_message
)
2192 req
->id
= info
->dest_tid
;
2193 req
->type
= info
->type
;
2195 req
->win
= info
->hwnd
;
2196 req
->msg
= info
->msg
;
2197 req
->wparam
= info
->wparam
;
2198 req
->lparam
= info
->lparam
;
2199 req
->time
= GetCurrentTime();
2200 req
->timeout
= timeout
;
2202 if (info
->type
== MSG_CALLBACK
)
2204 req
->callback
= info
->callback
;
2205 req
->info
= info
->data
;
2208 if (info
->flags
& SMTO_ABORTIFHUNG
) req
->flags
|= SEND_MSG_ABORT_IF_HUNG
;
2209 for (i
= 0; i
< data
.count
; i
++) wine_server_add_data( req
, data
.data
[i
], data
.size
[i
] );
2210 if ((res
= wine_server_call( req
)))
2212 if (res
== STATUS_INVALID_PARAMETER
)
2213 /* FIXME: find a STATUS_ value for this one */
2214 SetLastError( ERROR_INVALID_THREAD_ID
);
2216 SetLastError( RtlNtStatusToDosError(res
) );
2224 /***********************************************************************
2227 * Retrieve a message reply from the server.
2229 static LRESULT
retrieve_reply( const struct send_message_info
*info
,
2230 size_t reply_size
, LRESULT
*result
)
2233 void *reply_data
= NULL
;
2237 if (!(reply_data
= HeapAlloc( GetProcessHeap(), 0, reply_size
)))
2239 WARN( "no memory for reply, will be truncated\n" );
2243 SERVER_START_REQ( get_message_reply
)
2246 if (reply_size
) wine_server_set_reply( req
, reply_data
, reply_size
);
2247 if (!(status
= wine_server_call( req
))) *result
= reply
->result
;
2248 reply_size
= wine_server_reply_size( reply
);
2251 if (!status
&& reply_size
)
2252 unpack_reply( info
->hwnd
, info
->msg
, info
->wparam
, info
->lparam
, reply_data
, reply_size
);
2254 HeapFree( GetProcessHeap(), 0, reply_data
);
2256 TRACE( "hwnd %p msg %x (%s) wp %x lp %lx got reply %lx (err=%ld)\n",
2257 info
->hwnd
, info
->msg
, SPY_GetMsgName(info
->msg
, info
->hwnd
), info
->wparam
,
2258 info
->lparam
, *result
, status
);
2260 /* MSDN states that last error is 0 on timeout, but at least NT4 returns ERROR_TIMEOUT */
2261 if (status
) SetLastError( RtlNtStatusToDosError(status
) );
2266 /***********************************************************************
2267 * send_inter_thread_message
2269 static LRESULT
send_inter_thread_message( const struct send_message_info
*info
, LRESULT
*res_ptr
)
2271 size_t reply_size
= 0;
2273 TRACE( "hwnd %p msg %x (%s) wp %x lp %lx\n",
2274 info
->hwnd
, info
->msg
, SPY_GetMsgName(info
->msg
, info
->hwnd
), info
->wparam
, info
->lparam
);
2276 USER_CheckNotLock();
2278 if (!put_message_in_queue( info
, &reply_size
)) return 0;
2280 /* there's no reply to wait for on notify/callback messages */
2281 if (info
->type
== MSG_NOTIFY
|| info
->type
== MSG_CALLBACK
) return 1;
2283 wait_message_reply( info
->flags
);
2284 return retrieve_reply( info
, reply_size
, res_ptr
);
2288 /***********************************************************************
2289 * MSG_SendInternalMessageTimeout
2291 * Same as SendMessageTimeoutW but sends the message to a specific thread
2292 * without requiring a window handle. Only works for internal Wine messages.
2294 LRESULT
MSG_SendInternalMessageTimeout( DWORD dest_pid
, DWORD dest_tid
,
2295 UINT msg
, WPARAM wparam
, LPARAM lparam
,
2296 UINT flags
, UINT timeout
, PDWORD_PTR res_ptr
)
2298 struct send_message_info info
;
2299 LRESULT ret
, result
;
2301 assert( msg
& 0x80000000 ); /* must be an internal Wine message */
2303 info
.type
= MSG_UNICODE
;
2304 info
.dest_tid
= dest_tid
;
2307 info
.wparam
= wparam
;
2308 info
.lparam
= lparam
;
2310 info
.timeout
= timeout
;
2312 if (USER_IsExitingThread( dest_tid
)) return 0;
2314 if (dest_tid
== GetCurrentThreadId())
2316 result
= handle_internal_message( 0, msg
, wparam
, lparam
);
2321 if (dest_pid
!= GetCurrentProcessId()) info
.type
= MSG_OTHER_PROCESS
;
2322 ret
= send_inter_thread_message( &info
, &result
);
2324 if (ret
&& res_ptr
) *res_ptr
= result
;
2329 /***********************************************************************
2330 * SendMessageTimeoutW (USER32.@)
2332 LRESULT WINAPI
SendMessageTimeoutW( HWND hwnd
, UINT msg
, WPARAM wparam
, LPARAM lparam
,
2333 UINT flags
, UINT timeout
, PDWORD_PTR res_ptr
)
2335 struct send_message_info info
;
2337 LRESULT ret
, result
;
2339 info
.type
= MSG_UNICODE
;
2342 info
.wparam
= wparam
;
2343 info
.lparam
= lparam
;
2345 info
.timeout
= timeout
;
2347 if (is_broadcast(hwnd
))
2349 EnumWindows( broadcast_message_callback
, (LPARAM
)&info
);
2350 if (res_ptr
) *res_ptr
= 1;
2354 if (!(info
.dest_tid
= GetWindowThreadProcessId( hwnd
, &dest_pid
))) return 0;
2356 if (USER_IsExitingThread( info
.dest_tid
)) return 0;
2358 SPY_EnterMessage( SPY_SENDMESSAGE
, hwnd
, msg
, wparam
, lparam
);
2360 if (info
.dest_tid
== GetCurrentThreadId())
2362 result
= call_window_proc( hwnd
, msg
, wparam
, lparam
, TRUE
, TRUE
);
2367 if (dest_pid
!= GetCurrentProcessId()) info
.type
= MSG_OTHER_PROCESS
;
2368 ret
= send_inter_thread_message( &info
, &result
);
2371 SPY_ExitMessage( SPY_RESULT_OK
, hwnd
, msg
, result
, wparam
, lparam
);
2372 if (ret
&& res_ptr
) *res_ptr
= result
;
2376 static LRESULT
send_inter_thread_callback( HWND hwnd
, UINT msg
, WPARAM wp
, LPARAM lp
,
2377 LRESULT
*result
, void *arg
)
2379 struct send_message_info
*info
= arg
;
2384 return send_inter_thread_message( info
, result
);
2387 /***********************************************************************
2388 * SendMessageTimeoutA (USER32.@)
2390 LRESULT WINAPI
SendMessageTimeoutA( HWND hwnd
, UINT msg
, WPARAM wparam
, LPARAM lparam
,
2391 UINT flags
, UINT timeout
, PDWORD_PTR res_ptr
)
2393 struct send_message_info info
;
2395 LRESULT ret
, result
;
2397 info
.type
= MSG_ASCII
;
2400 info
.wparam
= wparam
;
2401 info
.lparam
= lparam
;
2403 info
.timeout
= timeout
;
2405 if (is_broadcast(hwnd
))
2407 EnumWindows( broadcast_message_callback
, (LPARAM
)&info
);
2408 if (res_ptr
) *res_ptr
= 1;
2412 if (!(info
.dest_tid
= GetWindowThreadProcessId( hwnd
, &dest_pid
))) return 0;
2414 if (USER_IsExitingThread( info
.dest_tid
)) return 0;
2416 SPY_EnterMessage( SPY_SENDMESSAGE
, hwnd
, msg
, wparam
, lparam
);
2418 if (info
.dest_tid
== GetCurrentThreadId())
2420 result
= call_window_proc( hwnd
, msg
, wparam
, lparam
, FALSE
, TRUE
);
2423 else if (dest_pid
== GetCurrentProcessId())
2425 ret
= send_inter_thread_message( &info
, &result
);
2429 /* inter-process message: need to map to Unicode */
2430 info
.type
= MSG_OTHER_PROCESS
;
2431 if (is_unicode_message( info
.msg
))
2432 ret
= WINPROC_CallProcAtoW( send_inter_thread_callback
, info
.hwnd
, info
.msg
,
2433 info
.wparam
, info
.lparam
, &result
, &info
);
2434 else ret
= send_inter_thread_message( &info
, &result
);
2436 SPY_ExitMessage( SPY_RESULT_OK
, hwnd
, msg
, result
, wparam
, lparam
);
2437 if (ret
&& res_ptr
) *res_ptr
= result
;
2442 /***********************************************************************
2443 * SendMessageW (USER32.@)
2445 LRESULT WINAPI
SendMessageW( HWND hwnd
, UINT msg
, WPARAM wparam
, LPARAM lparam
)
2448 SendMessageTimeoutW( hwnd
, msg
, wparam
, lparam
, SMTO_NORMAL
, 0, &res
);
2453 /***********************************************************************
2454 * SendMessageA (USER32.@)
2456 LRESULT WINAPI
SendMessageA( HWND hwnd
, UINT msg
, WPARAM wparam
, LPARAM lparam
)
2459 SendMessageTimeoutA( hwnd
, msg
, wparam
, lparam
, SMTO_NORMAL
, 0, &res
);
2464 /***********************************************************************
2465 * SendNotifyMessageA (USER32.@)
2467 BOOL WINAPI
SendNotifyMessageA( HWND hwnd
, UINT msg
, WPARAM wparam
, LPARAM lparam
)
2469 return SendNotifyMessageW( hwnd
, msg
, map_wparam_AtoW( msg
, wparam
), lparam
);
2473 /***********************************************************************
2474 * SendNotifyMessageW (USER32.@)
2476 BOOL WINAPI
SendNotifyMessageW( HWND hwnd
, UINT msg
, WPARAM wparam
, LPARAM lparam
)
2478 struct send_message_info info
;
2481 if (is_pointer_message(msg
))
2483 SetLastError( ERROR_MESSAGE_SYNC_ONLY
);
2487 info
.type
= MSG_NOTIFY
;
2490 info
.wparam
= wparam
;
2491 info
.lparam
= lparam
;
2494 if (is_broadcast(hwnd
))
2496 EnumWindows( broadcast_message_callback
, (LPARAM
)&info
);
2500 if (!(info
.dest_tid
= GetWindowThreadProcessId( hwnd
, NULL
))) return FALSE
;
2502 if (USER_IsExitingThread( info
.dest_tid
)) return TRUE
;
2504 if (info
.dest_tid
== GetCurrentThreadId())
2506 call_window_proc( hwnd
, msg
, wparam
, lparam
, TRUE
, TRUE
);
2509 return send_inter_thread_message( &info
, &result
);
2513 /***********************************************************************
2514 * SendMessageCallbackA (USER32.@)
2516 BOOL WINAPI
SendMessageCallbackA( HWND hwnd
, UINT msg
, WPARAM wparam
, LPARAM lparam
,
2517 SENDASYNCPROC callback
, ULONG_PTR data
)
2519 return SendMessageCallbackW( hwnd
, msg
, map_wparam_AtoW( msg
, wparam
),
2520 lparam
, callback
, data
);
2524 /***********************************************************************
2525 * SendMessageCallbackW (USER32.@)
2527 BOOL WINAPI
SendMessageCallbackW( HWND hwnd
, UINT msg
, WPARAM wparam
, LPARAM lparam
,
2528 SENDASYNCPROC callback
, ULONG_PTR data
)
2530 struct send_message_info info
;
2533 if (is_pointer_message(msg
))
2535 SetLastError( ERROR_MESSAGE_SYNC_ONLY
);
2539 info
.type
= MSG_CALLBACK
;
2542 info
.wparam
= wparam
;
2543 info
.lparam
= lparam
;
2544 info
.callback
= callback
;
2548 if (is_broadcast(hwnd
))
2550 EnumWindows( broadcast_message_callback
, (LPARAM
)&info
);
2554 if (!(info
.dest_tid
= GetWindowThreadProcessId( hwnd
, NULL
))) return FALSE
;
2556 if (USER_IsExitingThread( info
.dest_tid
)) return TRUE
;
2558 if (info
.dest_tid
== GetCurrentThreadId())
2560 result
= call_window_proc( hwnd
, msg
, wparam
, lparam
, TRUE
, TRUE
);
2561 call_sendmsg_callback( callback
, hwnd
, msg
, data
, result
);
2564 FIXME( "callback will not be called\n" );
2565 return send_inter_thread_message( &info
, &result
);
2569 /***********************************************************************
2570 * ReplyMessage (USER32.@)
2572 BOOL WINAPI
ReplyMessage( LRESULT result
)
2574 struct received_message_info
*info
= get_user_thread_info()->receive_info
;
2576 if (!info
) return FALSE
;
2577 reply_message( info
, result
, FALSE
);
2582 /***********************************************************************
2583 * InSendMessage (USER32.@)
2585 BOOL WINAPI
InSendMessage(void)
2587 return (InSendMessageEx(NULL
) & (ISMEX_SEND
|ISMEX_REPLIED
)) == ISMEX_SEND
;
2591 /***********************************************************************
2592 * InSendMessageEx (USER32.@)
2594 DWORD WINAPI
InSendMessageEx( LPVOID reserved
)
2596 struct received_message_info
*info
= get_user_thread_info()->receive_info
;
2598 if (info
) return info
->flags
;
2599 return ISMEX_NOSEND
;
2603 /***********************************************************************
2604 * PostMessageA (USER32.@)
2606 BOOL WINAPI
PostMessageA( HWND hwnd
, UINT msg
, WPARAM wparam
, LPARAM lparam
)
2608 return PostMessageW( hwnd
, msg
, map_wparam_AtoW( msg
, wparam
), lparam
);
2612 /***********************************************************************
2613 * PostMessageW (USER32.@)
2615 BOOL WINAPI
PostMessageW( HWND hwnd
, UINT msg
, WPARAM wparam
, LPARAM lparam
)
2617 struct send_message_info info
;
2619 if (is_pointer_message( msg
))
2621 SetLastError( ERROR_MESSAGE_SYNC_ONLY
);
2625 TRACE( "hwnd %p msg %x (%s) wp %x lp %lx\n",
2626 hwnd
, msg
, SPY_GetMsgName(msg
, hwnd
), wparam
, lparam
);
2628 info
.type
= MSG_POSTED
;
2631 info
.wparam
= wparam
;
2632 info
.lparam
= lparam
;
2635 if (is_broadcast(hwnd
))
2637 EnumWindows( broadcast_message_callback
, (LPARAM
)&info
);
2641 if (!hwnd
) return PostThreadMessageW( GetCurrentThreadId(), msg
, wparam
, lparam
);
2643 if (!(info
.dest_tid
= GetWindowThreadProcessId( hwnd
, NULL
))) return FALSE
;
2645 if (USER_IsExitingThread( info
.dest_tid
)) return TRUE
;
2647 return put_message_in_queue( &info
, NULL
);
2651 /**********************************************************************
2652 * PostThreadMessageA (USER32.@)
2654 BOOL WINAPI
PostThreadMessageA( DWORD thread
, UINT msg
, WPARAM wparam
, LPARAM lparam
)
2656 return PostThreadMessageW( thread
, msg
, map_wparam_AtoW( msg
, wparam
), lparam
);
2660 /**********************************************************************
2661 * PostThreadMessageW (USER32.@)
2663 BOOL WINAPI
PostThreadMessageW( DWORD thread
, UINT msg
, WPARAM wparam
, LPARAM lparam
)
2665 struct send_message_info info
;
2667 if (is_pointer_message( msg
))
2669 SetLastError( ERROR_MESSAGE_SYNC_ONLY
);
2672 if (USER_IsExitingThread( thread
)) return TRUE
;
2674 info
.type
= MSG_POSTED
;
2675 info
.dest_tid
= thread
;
2678 info
.wparam
= wparam
;
2679 info
.lparam
= lparam
;
2681 return put_message_in_queue( &info
, NULL
);
2685 /***********************************************************************
2686 * PostQuitMessage (USER32.@)
2688 * Posts a quit message to the current thread's message queue.
2691 * exit_code [I] Exit code to return from message loop.
2697 * This function is not the same as calling:
2698 *|PostThreadMessage(GetCurrentThreadId(), WM_QUIT, exit_code, 0);
2699 * It instead sets a flag in the message queue that signals it to generate
2700 * a WM_QUIT message when there are no other pending sent or posted messages
2703 void WINAPI
PostQuitMessage( INT exit_code
)
2705 SERVER_START_REQ( post_quit_message
)
2707 req
->exit_code
= exit_code
;
2708 wine_server_call( req
);
2714 /***********************************************************************
2715 * PeekMessageW (USER32.@)
2717 BOOL WINAPI
PeekMessageW( MSG
*msg_out
, HWND hwnd
, UINT first
, UINT last
, UINT flags
)
2719 struct user_thread_info
*thread_info
= get_user_thread_info();
2723 FIXME("PM_QS_xxxx flags (%04x) are not handled\n", flags
>> 16);
2725 USER_CheckNotLock();
2727 /* check for graphics events */
2728 USER_Driver
->pMsgWaitForMultipleObjectsEx( 0, NULL
, 0, QS_ALLINPUT
, 0 );
2730 hwnd
= WIN_GetFullHandle( hwnd
);
2734 if (!peek_message( &msg
, hwnd
, first
, last
, (flags
& PM_REMOVE
) ? GET_MSG_REMOVE
: 0 ))
2736 if (!(flags
& PM_NOYIELD
))
2739 ReleaseThunkLock(&count
);
2741 if (count
) RestoreThunkLock(count
);
2745 if (msg
.message
& 0x80000000)
2747 if (!(flags
& PM_REMOVE
))
2749 /* Have to remove the message explicitly.
2750 Do this before handling it, because the message handler may
2751 call PeekMessage again */
2752 peek_message( &msg
, msg
.hwnd
, msg
.message
, msg
.message
, GET_MSG_REMOVE
);
2754 handle_internal_message( msg
.hwnd
, msg
.message
, msg
.wParam
, msg
.lParam
);
2759 thread_info
->GetMessageTimeVal
= msg
.time
;
2760 msg
.pt
.x
= LOWORD( thread_info
->GetMessagePosVal
);
2761 msg
.pt
.y
= HIWORD( thread_info
->GetMessagePosVal
);
2763 HOOK_CallHooks( WH_GETMESSAGE
, HC_ACTION
, flags
& PM_REMOVE
, (LPARAM
)&msg
, TRUE
);
2765 /* copy back our internal safe copy of message data to msg_out.
2766 * msg_out is a variable from the *program*, so it can't be used
2767 * internally as it can get "corrupted" by our use of SendMessage()
2768 * (back to the program) inside the message handling itself. */
2771 SetLastError( ERROR_NOACCESS
);
2779 /***********************************************************************
2780 * PeekMessageA (USER32.@)
2782 BOOL WINAPI
PeekMessageA( MSG
*msg
, HWND hwnd
, UINT first
, UINT last
, UINT flags
)
2784 BOOL ret
= PeekMessageW( msg
, hwnd
, first
, last
, flags
);
2785 if (ret
) msg
->wParam
= map_wparam_WtoA( msg
->message
, msg
->wParam
);
2790 /***********************************************************************
2791 * GetMessageW (USER32.@)
2793 BOOL WINAPI
GetMessageW( MSG
*msg
, HWND hwnd
, UINT first
, UINT last
)
2795 HANDLE server_queue
= get_server_queue_handle();
2796 int mask
= QS_POSTMESSAGE
| QS_SENDMESSAGE
; /* Always selected */
2800 if ((first
<= WM_KEYLAST
) && (last
>= WM_KEYFIRST
)) mask
|= QS_KEY
;
2801 if ( ((first
<= WM_MOUSELAST
) && (last
>= WM_MOUSEFIRST
)) ||
2802 ((first
<= WM_NCMOUSELAST
) && (last
>= WM_NCMOUSEFIRST
)) ) mask
|= QS_MOUSE
;
2803 if ((first
<= WM_TIMER
) && (last
>= WM_TIMER
)) mask
|= QS_TIMER
;
2804 if ((first
<= WM_SYSTIMER
) && (last
>= WM_SYSTIMER
)) mask
|= QS_TIMER
;
2805 if ((first
<= WM_PAINT
) && (last
>= WM_PAINT
)) mask
|= QS_PAINT
;
2807 else mask
|= QS_MOUSE
| QS_KEY
| QS_TIMER
| QS_PAINT
;
2809 while (!PeekMessageW( msg
, hwnd
, first
, last
, PM_REMOVE
))
2811 /* wait until one of the bits is set */
2812 unsigned int wake_bits
= 0, changed_bits
= 0;
2815 SERVER_START_REQ( set_queue_mask
)
2817 req
->wake_mask
= QS_SENDMESSAGE
;
2818 req
->changed_mask
= mask
;
2820 if (!wine_server_call( req
))
2822 wake_bits
= reply
->wake_bits
;
2823 changed_bits
= reply
->changed_bits
;
2828 if (changed_bits
& mask
) continue;
2829 if (wake_bits
& QS_SENDMESSAGE
) continue;
2831 TRACE( "(%04lx) mask=%08x, bits=%08x, changed=%08x, waiting\n",
2832 GetCurrentThreadId(), mask
, wake_bits
, changed_bits
);
2834 ReleaseThunkLock( &dwlc
);
2835 USER_Driver
->pMsgWaitForMultipleObjectsEx( 1, &server_queue
, INFINITE
, QS_ALLINPUT
, 0 );
2836 if (dwlc
) RestoreThunkLock( dwlc
);
2839 return (msg
->message
!= WM_QUIT
);
2843 /***********************************************************************
2844 * GetMessageA (USER32.@)
2846 BOOL WINAPI
GetMessageA( MSG
*msg
, HWND hwnd
, UINT first
, UINT last
)
2848 GetMessageW( msg
, hwnd
, first
, last
);
2849 msg
->wParam
= map_wparam_WtoA( msg
->message
, msg
->wParam
);
2850 return (msg
->message
!= WM_QUIT
);
2854 /***********************************************************************
2855 * IsDialogMessageA (USER32.@)
2856 * IsDialogMessage (USER32.@)
2858 BOOL WINAPI
IsDialogMessageA( HWND hwndDlg
, LPMSG pmsg
)
2861 msg
.wParam
= map_wparam_AtoW( msg
.message
, msg
.wParam
);
2862 return IsDialogMessageW( hwndDlg
, &msg
);
2866 /***********************************************************************
2867 * TranslateMessage (USER32.@)
2869 * Implementation of TranslateMessage.
2871 * TranslateMessage translates virtual-key messages into character-messages,
2873 * WM_KEYDOWN/WM_KEYUP combinations produce a WM_CHAR or WM_DEADCHAR message.
2874 * ditto replacing WM_* with WM_SYS*
2875 * This produces WM_CHAR messages only for keys mapped to ASCII characters
2876 * by the keyboard driver.
2878 * If the message is WM_KEYDOWN, WM_KEYUP, WM_SYSKEYDOWN, or WM_SYSKEYUP, the
2879 * return value is nonzero, regardless of the translation.
2882 BOOL WINAPI
TranslateMessage( const MSG
*msg
)
2888 if (msg
->message
< WM_KEYFIRST
|| msg
->message
> WM_KEYLAST
) return FALSE
;
2889 if (msg
->message
!= WM_KEYDOWN
&& msg
->message
!= WM_SYSKEYDOWN
) return TRUE
;
2891 TRACE_(key
)("Translating key %s (%04x), scancode %02x\n",
2892 SPY_GetVKeyName(msg
->wParam
), msg
->wParam
, LOBYTE(HIWORD(msg
->lParam
)));
2894 GetKeyboardState( state
);
2895 /* FIXME : should handle ToUnicode yielding 2 */
2896 switch (ToUnicode(msg
->wParam
, HIWORD(msg
->lParam
), state
, wp
, 2, 0))
2899 message
= (msg
->message
== WM_KEYDOWN
) ? WM_CHAR
: WM_SYSCHAR
;
2900 TRACE_(key
)("1 -> PostMessageW(%p,%s,%04x,%08lx)\n",
2901 msg
->hwnd
, SPY_GetMsgName(message
, msg
->hwnd
), wp
[0], msg
->lParam
);
2902 PostMessageW( msg
->hwnd
, message
, wp
[0], msg
->lParam
);
2906 message
= (msg
->message
== WM_KEYDOWN
) ? WM_DEADCHAR
: WM_SYSDEADCHAR
;
2907 TRACE_(key
)("-1 -> PostMessageW(%p,%s,%04x,%08lx)\n",
2908 msg
->hwnd
, SPY_GetMsgName(message
, msg
->hwnd
), wp
[0], msg
->lParam
);
2909 PostMessageW( msg
->hwnd
, message
, wp
[0], msg
->lParam
);
2916 /***********************************************************************
2917 * DispatchMessageA (USER32.@)
2919 * See DispatchMessageW.
2921 LONG WINAPI
DispatchMessageA( const MSG
* msg
)
2927 /* Process timer messages */
2928 if ((msg
->message
== WM_TIMER
) || (msg
->message
== WM_SYSTIMER
))
2930 if (msg
->lParam
) return CallWindowProcA( (WNDPROC
)msg
->lParam
, msg
->hwnd
,
2931 msg
->message
, msg
->wParam
, GetTickCount() );
2934 if (!(wndPtr
= WIN_GetPtr( msg
->hwnd
)))
2936 if (msg
->hwnd
) SetLastError( ERROR_INVALID_WINDOW_HANDLE
);
2939 if (wndPtr
== WND_OTHER_PROCESS
|| wndPtr
== WND_DESKTOP
)
2941 if (IsWindow( msg
->hwnd
)) SetLastError( ERROR_MESSAGE_SYNC_ONLY
);
2942 else SetLastError( ERROR_INVALID_WINDOW_HANDLE
);
2945 if (wndPtr
->tid
!= GetCurrentThreadId())
2947 SetLastError( ERROR_MESSAGE_SYNC_ONLY
);
2948 WIN_ReleasePtr( wndPtr
);
2951 winproc
= wndPtr
->winproc
;
2952 WIN_ReleasePtr( wndPtr
);
2954 SPY_EnterMessage( SPY_DISPATCHMESSAGE
, msg
->hwnd
, msg
->message
,
2955 msg
->wParam
, msg
->lParam
);
2956 retval
= CallWindowProcA( winproc
, msg
->hwnd
, msg
->message
,
2957 msg
->wParam
, msg
->lParam
);
2958 SPY_ExitMessage( SPY_RESULT_OK
, msg
->hwnd
, msg
->message
, retval
,
2959 msg
->wParam
, msg
->lParam
);
2961 if (msg
->message
== WM_PAINT
)
2963 /* send a WM_NCPAINT and WM_ERASEBKGND if the non-client area is still invalid */
2964 HRGN hrgn
= CreateRectRgn( 0, 0, 0, 0 );
2965 GetUpdateRgn( msg
->hwnd
, hrgn
, TRUE
);
2966 DeleteObject( hrgn
);
2972 /***********************************************************************
2973 * DispatchMessageW (USER32.@) Process a message
2975 * Process the message specified in the structure *_msg_.
2977 * If the lpMsg parameter points to a WM_TIMER message and the
2978 * parameter of the WM_TIMER message is not NULL, the lParam parameter
2979 * points to the function that is called instead of the window
2982 * The message must be valid.
2986 * DispatchMessage() returns the result of the window procedure invoked.
2993 LONG WINAPI
DispatchMessageW( const MSG
* msg
)
2999 /* Process timer messages */
3000 if ((msg
->message
== WM_TIMER
) || (msg
->message
== WM_SYSTIMER
))
3002 if (msg
->lParam
) return CallWindowProcW( (WNDPROC
)msg
->lParam
, msg
->hwnd
,
3003 msg
->message
, msg
->wParam
, GetTickCount() );
3006 if (!(wndPtr
= WIN_GetPtr( msg
->hwnd
)))
3008 if (msg
->hwnd
) SetLastError( ERROR_INVALID_WINDOW_HANDLE
);
3011 if (wndPtr
== WND_OTHER_PROCESS
|| wndPtr
== WND_DESKTOP
)
3013 if (IsWindow( msg
->hwnd
)) SetLastError( ERROR_MESSAGE_SYNC_ONLY
);
3014 else SetLastError( ERROR_INVALID_WINDOW_HANDLE
);
3017 if (wndPtr
->tid
!= GetCurrentThreadId())
3019 SetLastError( ERROR_MESSAGE_SYNC_ONLY
);
3020 WIN_ReleasePtr( wndPtr
);
3023 winproc
= wndPtr
->winproc
;
3024 WIN_ReleasePtr( wndPtr
);
3026 SPY_EnterMessage( SPY_DISPATCHMESSAGE
, msg
->hwnd
, msg
->message
,
3027 msg
->wParam
, msg
->lParam
);
3028 retval
= CallWindowProcW( winproc
, msg
->hwnd
, msg
->message
,
3029 msg
->wParam
, msg
->lParam
);
3030 SPY_ExitMessage( SPY_RESULT_OK
, msg
->hwnd
, msg
->message
, retval
,
3031 msg
->wParam
, msg
->lParam
);
3033 if (msg
->message
== WM_PAINT
)
3035 /* send a WM_NCPAINT and WM_ERASEBKGND if the non-client area is still invalid */
3036 HRGN hrgn
= CreateRectRgn( 0, 0, 0, 0 );
3037 GetUpdateRgn( msg
->hwnd
, hrgn
, TRUE
);
3038 DeleteObject( hrgn
);
3044 /***********************************************************************
3045 * GetMessagePos (USER.119)
3046 * GetMessagePos (USER32.@)
3048 * The GetMessagePos() function returns a long value representing a
3049 * cursor position, in screen coordinates, when the last message
3050 * retrieved by the GetMessage() function occurs. The x-coordinate is
3051 * in the low-order word of the return value, the y-coordinate is in
3052 * the high-order word. The application can use the MAKEPOINT()
3053 * macro to obtain a POINT structure from the return value.
3055 * For the current cursor position, use GetCursorPos().
3059 * Cursor position of last message on success, zero on failure.
3066 DWORD WINAPI
GetMessagePos(void)
3068 return get_user_thread_info()->GetMessagePosVal
;
3072 /***********************************************************************
3073 * GetMessageTime (USER.120)
3074 * GetMessageTime (USER32.@)
3076 * GetMessageTime() returns the message time for the last message
3077 * retrieved by the function. The time is measured in milliseconds with
3078 * the same offset as GetTickCount().
3080 * Since the tick count wraps, this is only useful for moderately short
3081 * relative time comparisons.
3085 * Time of last message on success, zero on failure.
3087 LONG WINAPI
GetMessageTime(void)
3089 return get_user_thread_info()->GetMessageTimeVal
;
3093 /***********************************************************************
3094 * GetMessageExtraInfo (USER.288)
3095 * GetMessageExtraInfo (USER32.@)
3097 LPARAM WINAPI
GetMessageExtraInfo(void)
3099 return get_user_thread_info()->GetMessageExtraInfoVal
;
3103 /***********************************************************************
3104 * SetMessageExtraInfo (USER32.@)
3106 LPARAM WINAPI
SetMessageExtraInfo(LPARAM lParam
)
3108 struct user_thread_info
*thread_info
= get_user_thread_info();
3109 LONG old_value
= thread_info
->GetMessageExtraInfoVal
;
3110 thread_info
->GetMessageExtraInfoVal
= lParam
;
3115 /***********************************************************************
3116 * WaitMessage (USER.112) Suspend thread pending messages
3117 * WaitMessage (USER32.@) Suspend thread pending messages
3119 * WaitMessage() suspends a thread until events appear in the thread's
3122 BOOL WINAPI
WaitMessage(void)
3124 return (MsgWaitForMultipleObjectsEx( 0, NULL
, INFINITE
, QS_ALLINPUT
, 0 ) != WAIT_FAILED
);
3128 /***********************************************************************
3129 * MsgWaitForMultipleObjectsEx (USER32.@)
3131 DWORD WINAPI
MsgWaitForMultipleObjectsEx( DWORD count
, CONST HANDLE
*pHandles
,
3132 DWORD timeout
, DWORD mask
, DWORD flags
)
3134 HANDLE handles
[MAXIMUM_WAIT_OBJECTS
];
3137 if (count
> MAXIMUM_WAIT_OBJECTS
-1)
3139 SetLastError( ERROR_INVALID_PARAMETER
);
3143 /* set the queue mask */
3144 SERVER_START_REQ( set_queue_mask
)
3146 req
->wake_mask
= (flags
& MWMO_INPUTAVAILABLE
) ? mask
: 0;
3147 req
->changed_mask
= mask
;
3149 wine_server_call( req
);
3153 /* Add the thread event to the handle list */
3154 for (i
= 0; i
< count
; i
++) handles
[i
] = pHandles
[i
];
3155 handles
[count
] = get_server_queue_handle();
3157 ReleaseThunkLock( &lock
);
3158 ret
= USER_Driver
->pMsgWaitForMultipleObjectsEx( count
+1, handles
, timeout
, mask
, flags
);
3159 if (ret
== count
+1) ret
= count
; /* pretend the msg queue is ready */
3160 if (lock
) RestoreThunkLock( lock
);
3165 /***********************************************************************
3166 * MsgWaitForMultipleObjects (USER32.@)
3168 DWORD WINAPI
MsgWaitForMultipleObjects( DWORD count
, CONST HANDLE
*handles
,
3169 BOOL wait_all
, DWORD timeout
, DWORD mask
)
3171 return MsgWaitForMultipleObjectsEx( count
, handles
, timeout
, mask
,
3172 wait_all
? MWMO_WAITALL
: 0 );
3176 /***********************************************************************
3177 * WaitForInputIdle (USER32.@)
3179 DWORD WINAPI
WaitForInputIdle( HANDLE hProcess
, DWORD dwTimeOut
)
3181 DWORD start_time
, elapsed
, ret
;
3182 HANDLE idle_event
= (HANDLE
)-1;
3184 SERVER_START_REQ( get_process_idle_event
)
3186 req
->handle
= hProcess
;
3187 if (!(ret
= wine_server_call_err( req
))) idle_event
= reply
->event
;
3190 if (ret
) return WAIT_FAILED
; /* error */
3191 if (!idle_event
) return 0; /* no event to wait on */
3193 start_time
= GetTickCount();
3196 TRACE("waiting for %p\n", idle_event
);
3199 ret
= MsgWaitForMultipleObjects ( 1, &idle_event
, FALSE
, dwTimeOut
- elapsed
, QS_SENDMESSAGE
);
3202 case WAIT_OBJECT_0
+1:
3203 process_sent_messages();
3207 TRACE("timeout or error\n");
3210 TRACE("finished\n");
3213 if (dwTimeOut
!= INFINITE
)
3215 elapsed
= GetTickCount() - start_time
;
3216 if (elapsed
> dwTimeOut
)
3222 return WAIT_TIMEOUT
;
3226 /***********************************************************************
3227 * UserYield (USER.332)
3229 void WINAPI
UserYield16(void)
3233 /* Handle sent messages */
3234 process_sent_messages();
3237 ReleaseThunkLock(&count
);
3241 RestoreThunkLock(count
);
3242 /* Handle sent messages again */
3243 process_sent_messages();
3248 /***********************************************************************
3249 * RegisterWindowMessageA (USER32.@)
3250 * RegisterWindowMessage (USER.118)
3252 UINT WINAPI
RegisterWindowMessageA( LPCSTR str
)
3254 UINT ret
= GlobalAddAtomA(str
);
3255 TRACE("%s, ret=%x\n", str
, ret
);
3260 /***********************************************************************
3261 * RegisterWindowMessageW (USER32.@)
3263 UINT WINAPI
RegisterWindowMessageW( LPCWSTR str
)
3265 UINT ret
= GlobalAddAtomW(str
);
3266 TRACE("%s ret=%x\n", debugstr_w(str
), ret
);
3271 /***********************************************************************
3272 * BroadcastSystemMessageA (USER32.@)
3273 * BroadcastSystemMessage (USER32.@)
3275 LONG WINAPI
BroadcastSystemMessageA( DWORD flags
, LPDWORD recipients
, UINT msg
, WPARAM wp
, LPARAM lp
)
3277 if ((*recipients
& BSM_APPLICATIONS
) || (*recipients
== BSM_ALLCOMPONENTS
))
3279 FIXME( "(%08lx,%08lx,%08x,%08x,%08lx): semi-stub!\n", flags
, *recipients
, msg
, wp
, lp
);
3280 PostMessageA( HWND_BROADCAST
, msg
, wp
, lp
);
3285 FIXME( "(%08lx,%08lx,%08x,%08x,%08lx): stub!\n", flags
, *recipients
, msg
, wp
, lp
);
3291 /***********************************************************************
3292 * BroadcastSystemMessageW (USER32.@)
3294 LONG WINAPI
BroadcastSystemMessageW( DWORD flags
, LPDWORD recipients
, UINT msg
, WPARAM wp
, LPARAM lp
)
3296 if ((*recipients
& BSM_APPLICATIONS
) || (*recipients
== BSM_ALLCOMPONENTS
))
3298 FIXME( "(%08lx,%08lx,%08x,%08x,%08lx): semi-stub!\n", flags
, *recipients
, msg
, wp
, lp
);
3299 PostMessageW( HWND_BROADCAST
, msg
, wp
, lp
);
3304 FIXME( "(%08lx,%08lx,%08x,%08x,%08lx): stub!\n", flags
, *recipients
, msg
, wp
, lp
);
3310 /***********************************************************************
3311 * SetMessageQueue (USER32.@)
3313 BOOL WINAPI
SetMessageQueue( INT size
)
3315 /* now obsolete the message queue will be expanded dynamically as necessary */
3320 /***********************************************************************
3321 * MessageBeep (USER32.@)
3323 BOOL WINAPI
MessageBeep( UINT i
)
3326 SystemParametersInfoA( SPI_GETBEEP
, 0, &active
, FALSE
);
3327 if (active
) USER_Driver
->pBeep();
3332 /***********************************************************************
3333 * SetTimer (USER32.@)
3335 UINT_PTR WINAPI
SetTimer( HWND hwnd
, UINT_PTR id
, UINT timeout
, TIMERPROC proc
)
3338 WNDPROC winproc
= 0;
3340 if (proc
) winproc
= WINPROC_AllocProc( (WNDPROC
)proc
, NULL
);
3342 SERVER_START_REQ( set_win_timer
)
3345 req
->msg
= WM_TIMER
;
3347 req
->rate
= max( timeout
, SYS_TIMER_RATE
);
3348 req
->lparam
= (unsigned long)winproc
;
3349 if (!wine_server_call_err( req
))
3352 if (!ret
) ret
= TRUE
;
3358 TRACE("Added %p %x %p timeout %d\n", hwnd
, id
, winproc
, timeout
);
3363 /***********************************************************************
3364 * SetSystemTimer (USER32.@)
3366 UINT_PTR WINAPI
SetSystemTimer( HWND hwnd
, UINT_PTR id
, UINT timeout
, TIMERPROC proc
)
3369 WNDPROC winproc
= 0;
3371 if (proc
) winproc
= WINPROC_AllocProc( (WNDPROC
)proc
, NULL
);
3373 SERVER_START_REQ( set_win_timer
)
3376 req
->msg
= WM_SYSTIMER
;
3378 req
->rate
= max( timeout
, SYS_TIMER_RATE
);
3379 req
->lparam
= (unsigned long)winproc
;
3380 if (!wine_server_call_err( req
))
3383 if (!ret
) ret
= TRUE
;
3389 TRACE("Added %p %x %p timeout %d\n", hwnd
, id
, winproc
, timeout
);
3394 /***********************************************************************
3395 * KillTimer (USER32.@)
3397 BOOL WINAPI
KillTimer( HWND hwnd
, UINT_PTR id
)
3401 TRACE("%p %d\n", hwnd
, id
);
3403 SERVER_START_REQ( kill_win_timer
)
3406 req
->msg
= WM_TIMER
;
3408 ret
= !wine_server_call_err( req
);
3415 /***********************************************************************
3416 * KillSystemTimer (USER32.@)
3418 BOOL WINAPI
KillSystemTimer( HWND hwnd
, UINT_PTR id
)
3422 TRACE("%p %d\n", hwnd
, id
);
3424 SERVER_START_REQ( kill_win_timer
)
3427 req
->msg
= WM_SYSTIMER
;
3429 ret
= !wine_server_call_err( req
);
3436 /**********************************************************************
3437 * GetGUIThreadInfo (USER32.@)
3439 BOOL WINAPI
GetGUIThreadInfo( DWORD id
, GUITHREADINFO
*info
)
3443 SERVER_START_REQ( get_thread_input
)
3446 if ((ret
= !wine_server_call_err( req
)))
3449 info
->hwndActive
= reply
->active
;
3450 info
->hwndFocus
= reply
->focus
;
3451 info
->hwndCapture
= reply
->capture
;
3452 info
->hwndMenuOwner
= reply
->menu_owner
;
3453 info
->hwndMoveSize
= reply
->move_size
;
3454 info
->hwndCaret
= reply
->caret
;
3455 info
->rcCaret
.left
= reply
->rect
.left
;
3456 info
->rcCaret
.top
= reply
->rect
.top
;
3457 info
->rcCaret
.right
= reply
->rect
.right
;
3458 info
->rcCaret
.bottom
= reply
->rect
.bottom
;
3459 if (reply
->menu_owner
) info
->flags
|= GUI_INMENUMODE
;
3460 if (reply
->move_size
) info
->flags
|= GUI_INMOVESIZE
;
3461 if (reply
->caret
) info
->flags
|= GUI_CARETBLINKING
;
3469 /******************************************************************
3470 * IsHungAppWindow (USER32.@)
3473 BOOL WINAPI
IsHungAppWindow( HWND hWnd
)
3476 return !SendMessageTimeoutA(hWnd
, WM_NULL
, 0, 0, SMTO_ABORTIFHUNG
, 5000, &dwResult
);