2 * Window messaging support
4 * Copyright 2001 Alexandre Julliard
6 * This library is free software; you can redistribute it and/or
7 * modify it under the terms of the GNU Lesser General Public
8 * License as published by the Free Software Foundation; either
9 * version 2.1 of the License, or (at your option) any later version.
11 * This library is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 * Lesser General Public License for more details.
16 * You should have received a copy of the GNU Lesser General Public
17 * License along with this library; if not, write to the Free Software
18 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
22 #include "wine/port.h"
35 #include "wine/unicode.h"
36 #include "wine/server.h"
37 #include "user_private.h"
42 #include "wine/debug.h"
44 WINE_DEFAULT_DEBUG_CHANNEL(msg
);
45 WINE_DECLARE_DEBUG_CHANNEL(relay
);
46 WINE_DECLARE_DEBUG_CHANNEL(key
);
48 #define WM_NCMOUSEFIRST WM_NCMOUSEMOVE
49 #define WM_NCMOUSELAST (WM_NCMOUSEFIRST+(WM_MOUSELAST-WM_MOUSEFIRST))
51 #define MAX_PACK_COUNT 4
52 #define MAX_SENDMSG_RECURSION 64
54 #define SYS_TIMER_RATE 55 /* min. timer rate in ms (actually 54.925)*/
56 /* description of the data fields that need to be packed along with a sent message */
60 const void *data
[MAX_PACK_COUNT
];
61 size_t size
[MAX_PACK_COUNT
];
64 /* info about the message currently being received by the current thread */
65 struct received_message_info
67 enum message_type type
;
69 UINT flags
; /* InSendMessageEx return flags */
70 HWINEVENTHOOK hook
; /* winevent hook handle */
71 WINEVENTPROC hook_proc
; /* winevent hook proc address */
74 /* structure to group all parameters for sent messages of the various kinds */
75 struct send_message_info
77 enum message_type type
;
82 UINT flags
; /* flags for SendMessageTimeout */
83 UINT timeout
; /* timeout for SendMessageTimeout */
84 SENDASYNCPROC callback
; /* callback function for SendMessageCallback */
85 ULONG_PTR data
; /* callback data */
89 /* flag for messages that contain pointers */
90 /* 32 messages per entry, messages 0..31 map to bits 0..31 */
92 #define SET(msg) (1 << ((msg) & 31))
94 static const unsigned int message_pointer_flags
[] =
97 SET(WM_CREATE
) | SET(WM_SETTEXT
) | SET(WM_GETTEXT
) |
98 SET(WM_WININICHANGE
) | SET(WM_DEVMODECHANGE
),
100 SET(WM_GETMINMAXINFO
) | SET(WM_DRAWITEM
) | SET(WM_MEASUREITEM
) | SET(WM_DELETEITEM
) |
103 SET(WM_WINDOWPOSCHANGING
) | SET(WM_WINDOWPOSCHANGED
) | SET(WM_COPYDATA
) |
104 SET(WM_NOTIFY
) | SET(WM_HELP
),
106 SET(WM_STYLECHANGING
) | SET(WM_STYLECHANGED
),
108 SET(WM_NCCREATE
) | SET(WM_NCCALCSIZE
) | SET(WM_GETDLGCODE
),
110 SET(EM_GETSEL
) | SET(EM_GETRECT
) | SET(EM_SETRECT
) | SET(EM_SETRECTNP
),
112 SET(EM_REPLACESEL
) | SET(EM_GETLINE
) | SET(EM_SETTABSTOPS
),
114 SET(SBM_GETRANGE
) | SET(SBM_SETSCROLLINFO
) | SET(SBM_GETSCROLLINFO
) | SET(SBM_GETSCROLLBARINFO
),
120 SET(CB_GETEDITSEL
) | SET(CB_ADDSTRING
) | SET(CB_DIR
) | SET(CB_GETLBTEXT
) |
121 SET(CB_INSERTSTRING
) | SET(CB_FINDSTRING
) | SET(CB_SELECTSTRING
) |
122 SET(CB_GETDROPPEDCONTROLRECT
) | SET(CB_FINDSTRINGEXACT
),
126 SET(LB_ADDSTRING
) | SET(LB_INSERTSTRING
) | SET(LB_GETTEXT
) | SET(LB_SELECTSTRING
) |
127 SET(LB_DIR
) | SET(LB_FINDSTRING
) |
128 SET(LB_GETSELITEMS
) | SET(LB_SETTABSTOPS
) | SET(LB_ADDFILE
) | SET(LB_GETITEMRECT
),
130 SET(LB_FINDSTRINGEXACT
),
136 SET(WM_NEXTMENU
) | SET(WM_SIZING
) | SET(WM_MOVING
) | SET(WM_DEVICECHANGE
),
138 SET(WM_MDICREATE
) | SET(WM_MDIGETACTIVE
) | SET(WM_DROPOBJECT
) |
139 SET(WM_QUERYDROPOBJECT
) | SET(WM_DRAGLOOP
) | SET(WM_DRAGSELECT
) | SET(WM_DRAGMOVE
),
153 SET(WM_ASKCBFORMATNAME
)
156 /* flags for messages that contain Unicode strings */
157 static const unsigned int message_unicode_flags
[] =
160 SET(WM_CREATE
) | SET(WM_SETTEXT
) | SET(WM_GETTEXT
) | SET(WM_GETTEXTLENGTH
) |
161 SET(WM_WININICHANGE
) | SET(WM_DEVMODECHANGE
),
173 SET(EM_REPLACESEL
) | SET(EM_GETLINE
) | SET(EM_SETPASSWORDCHAR
),
177 SET(WM_CHAR
) | SET(WM_DEADCHAR
) | SET(WM_SYSCHAR
) | SET(WM_SYSDEADCHAR
),
181 SET(CB_ADDSTRING
) | SET(CB_DIR
) | SET(CB_GETLBTEXT
) | SET(CB_GETLBTEXTLEN
) |
182 SET(CB_INSERTSTRING
) | SET(CB_FINDSTRING
) | SET(CB_SELECTSTRING
) | SET(CB_FINDSTRINGEXACT
),
186 SET(LB_ADDSTRING
) | SET(LB_INSERTSTRING
) | SET(LB_GETTEXT
) | SET(LB_GETTEXTLEN
) |
187 SET(LB_SELECTSTRING
) | SET(LB_DIR
) | SET(LB_FINDSTRING
) | SET(LB_ADDFILE
),
189 SET(LB_FINDSTRINGEXACT
),
211 SET(WM_PAINTCLIPBOARD
) | SET(WM_SIZECLIPBOARD
) | SET(WM_ASKCBFORMATNAME
)
214 /* check whether a given message type includes pointers */
215 inline static int is_pointer_message( UINT message
)
217 if (message
>= 8*sizeof(message_pointer_flags
)) return FALSE
;
218 return (message_pointer_flags
[message
/ 32] & SET(message
)) != 0;
221 /* check whether a given message type contains Unicode (or ASCII) chars */
222 inline static int is_unicode_message( UINT message
)
224 if (message
>= 8*sizeof(message_unicode_flags
)) return FALSE
;
225 return (message_unicode_flags
[message
/ 32] & SET(message
)) != 0;
230 /* add a data field to a packed message */
231 inline static void push_data( struct packed_message
*data
, const void *ptr
, size_t size
)
233 data
->data
[data
->count
] = ptr
;
234 data
->size
[data
->count
] = size
;
238 /* add a string to a packed message */
239 inline static void push_string( struct packed_message
*data
, LPCWSTR str
)
241 push_data( data
, str
, (strlenW(str
) + 1) * sizeof(WCHAR
) );
244 /* retrieve a pointer to data from a packed message and increment the buffer pointer */
245 inline static void *get_data( void **buffer
, size_t size
)
248 *buffer
= (char *)*buffer
+ size
;
252 /* make sure that the buffer contains a valid null-terminated Unicode string */
253 inline static BOOL
check_string( LPCWSTR str
, size_t size
)
255 for (size
/= sizeof(WCHAR
); size
; size
--, str
++)
256 if (!*str
) return TRUE
;
260 /* make sure that there is space for 'size' bytes in buffer, growing it if needed */
261 inline static void *get_buffer_space( void **buffer
, size_t size
)
267 if (!(ret
= HeapReAlloc( GetProcessHeap(), 0, *buffer
, size
)))
268 HeapFree( GetProcessHeap(), 0, *buffer
);
270 else ret
= HeapAlloc( GetProcessHeap(), 0, size
);
276 /* retrieve a string pointer from packed data */
277 inline static LPWSTR
get_string( void **buffer
)
279 return get_data( buffer
, (strlenW( (LPWSTR
)*buffer
) + 1) * sizeof(WCHAR
) );
282 /* check whether a combobox expects strings or ids in CB_ADDSTRING/CB_INSERTSTRING */
283 inline static BOOL
combobox_has_strings( HWND hwnd
)
285 DWORD style
= GetWindowLongA( hwnd
, GWL_STYLE
);
286 return (!(style
& (CBS_OWNERDRAWFIXED
| CBS_OWNERDRAWVARIABLE
)) || (style
& CBS_HASSTRINGS
));
289 /* check whether a listbox expects strings or ids in LB_ADDSTRING/LB_INSERTSTRING */
290 inline static BOOL
listbox_has_strings( HWND hwnd
)
292 DWORD style
= GetWindowLongA( hwnd
, GWL_STYLE
);
293 return (!(style
& (LBS_OWNERDRAWFIXED
| LBS_OWNERDRAWVARIABLE
)) || (style
& LBS_HASSTRINGS
));
296 /* check whether message is in the range of keyboard messages */
297 inline static BOOL
is_keyboard_message( UINT message
)
299 return (message
>= WM_KEYFIRST
&& message
<= WM_KEYLAST
);
302 /* check whether message is in the range of mouse messages */
303 inline static BOOL
is_mouse_message( UINT message
)
305 return ((message
>= WM_NCMOUSEFIRST
&& message
<= WM_NCMOUSELAST
) ||
306 (message
>= WM_MOUSEFIRST
&& message
<= WM_MOUSELAST
));
309 /* check whether message matches the specified hwnd filter */
310 inline static BOOL
check_hwnd_filter( const MSG
*msg
, HWND hwnd_filter
)
312 if (!hwnd_filter
) return TRUE
;
313 return (msg
->hwnd
== hwnd_filter
|| IsChild( hwnd_filter
, msg
->hwnd
));
317 /***********************************************************************
318 * broadcast_message_callback
320 * Helper callback for broadcasting messages.
322 static BOOL CALLBACK
broadcast_message_callback( HWND hwnd
, LPARAM lparam
)
324 struct send_message_info
*info
= (struct send_message_info
*)lparam
;
325 if (!(GetWindowLongW( hwnd
, GWL_STYLE
) & (WS_POPUP
|WS_CAPTION
))) return TRUE
;
329 SendMessageTimeoutW( hwnd
, info
->msg
, info
->wparam
, info
->lparam
,
330 info
->flags
, info
->timeout
, NULL
);
333 SendMessageTimeoutA( hwnd
, info
->msg
, info
->wparam
, info
->lparam
,
334 info
->flags
, info
->timeout
, NULL
);
337 SendNotifyMessageW( hwnd
, info
->msg
, info
->wparam
, info
->lparam
);
340 SendMessageCallbackW( hwnd
, info
->msg
, info
->wparam
, info
->lparam
,
341 info
->callback
, info
->data
);
344 PostMessageW( hwnd
, info
->msg
, info
->wparam
, info
->lparam
);
347 ERR( "bad type %d\n", info
->type
);
354 /***********************************************************************
357 * Convert the wparam of an ASCII message to Unicode.
359 static WPARAM
map_wparam_AtoW( UINT message
, WPARAM wparam
)
364 case EM_SETPASSWORDCHAR
:
371 char ch
= LOWORD(wparam
);
373 MultiByteToWideChar(CP_ACP
, 0, &ch
, 1, &wch
, 1);
374 wparam
= MAKEWPARAM( wch
, HIWORD(wparam
) );
381 ch
[0] = (wparam
>> 8);
382 ch
[1] = (wparam
& 0xff);
383 if (ch
[0]) MultiByteToWideChar(CP_ACP
, 0, ch
, 2, &wch
, 1);
384 else MultiByteToWideChar(CP_ACP
, 0, &ch
[1], 1, &wch
, 1);
385 wparam
= MAKEWPARAM( wch
, HIWORD(wparam
) );
393 /***********************************************************************
396 * Convert the wparam of a Unicode message to ASCII.
398 static WPARAM
map_wparam_WtoA( UINT message
, WPARAM wparam
)
403 case EM_SETPASSWORDCHAR
:
410 WCHAR wch
= LOWORD(wparam
);
412 WideCharToMultiByte( CP_ACP
, 0, &wch
, 1, &ch
, 1, NULL
, NULL
);
413 wparam
= MAKEWPARAM( ch
, HIWORD(wparam
) );
418 WCHAR wch
= LOWORD(wparam
);
421 if (WideCharToMultiByte( CP_ACP
, 0, &wch
, 1, ch
, 2, NULL
, NULL
) == 2)
422 wparam
= MAKEWPARAM( (ch
[0] << 8) | ch
[1], HIWORD(wparam
) );
424 wparam
= MAKEWPARAM( ch
[0], HIWORD(wparam
) );
432 /***********************************************************************
435 * Pack a message for sending to another process.
436 * Return the size of the data we expect in the message reply.
437 * Set data->count to -1 if there is an error.
439 static size_t pack_message( HWND hwnd
, UINT message
, WPARAM wparam
, LPARAM lparam
,
440 struct packed_message
*data
)
448 CREATESTRUCTW
*cs
= (CREATESTRUCTW
*)lparam
;
449 push_data( data
, cs
, sizeof(*cs
) );
450 if (HIWORD(cs
->lpszName
)) push_string( data
, cs
->lpszName
);
451 if (HIWORD(cs
->lpszClass
)) push_string( data
, cs
->lpszClass
);
455 case WM_ASKCBFORMATNAME
:
456 return wparam
* sizeof(WCHAR
);
457 case WM_WININICHANGE
:
458 if (lparam
) push_string(data
, (LPWSTR
)lparam
);
461 case WM_DEVMODECHANGE
:
466 push_string( data
, (LPWSTR
)lparam
);
468 case WM_GETMINMAXINFO
:
469 push_data( data
, (MINMAXINFO
*)lparam
, sizeof(MINMAXINFO
) );
470 return sizeof(MINMAXINFO
);
472 push_data( data
, (DRAWITEMSTRUCT
*)lparam
, sizeof(DRAWITEMSTRUCT
) );
475 push_data( data
, (MEASUREITEMSTRUCT
*)lparam
, sizeof(MEASUREITEMSTRUCT
) );
476 return sizeof(MEASUREITEMSTRUCT
);
478 push_data( data
, (DELETEITEMSTRUCT
*)lparam
, sizeof(DELETEITEMSTRUCT
) );
481 push_data( data
, (COMPAREITEMSTRUCT
*)lparam
, sizeof(COMPAREITEMSTRUCT
) );
483 case WM_WINDOWPOSCHANGING
:
484 case WM_WINDOWPOSCHANGED
:
485 push_data( data
, (WINDOWPOS
*)lparam
, sizeof(WINDOWPOS
) );
486 return sizeof(WINDOWPOS
);
489 COPYDATASTRUCT
*cp
= (COPYDATASTRUCT
*)lparam
;
490 push_data( data
, cp
, sizeof(*cp
) );
491 if (cp
->lpData
) push_data( data
, cp
->lpData
, cp
->cbData
);
495 /* WM_NOTIFY cannot be sent across processes (MSDN) */
499 push_data( data
, (HELPINFO
*)lparam
, sizeof(HELPINFO
) );
501 case WM_STYLECHANGING
:
502 case WM_STYLECHANGED
:
503 push_data( data
, (STYLESTRUCT
*)lparam
, sizeof(STYLESTRUCT
) );
508 push_data( data
, (RECT
*)lparam
, sizeof(RECT
) );
513 NCCALCSIZE_PARAMS
*nc
= (NCCALCSIZE_PARAMS
*)lparam
;
514 push_data( data
, nc
, sizeof(*nc
) );
515 push_data( data
, nc
->lppos
, sizeof(*nc
->lppos
) );
516 return sizeof(*nc
) + sizeof(*nc
->lppos
);
519 if (lparam
) push_data( data
, (MSG
*)lparam
, sizeof(MSG
) );
521 case SBM_SETSCROLLINFO
:
522 push_data( data
, (SCROLLINFO
*)lparam
, sizeof(SCROLLINFO
) );
524 case SBM_GETSCROLLINFO
:
525 push_data( data
, (SCROLLINFO
*)lparam
, sizeof(SCROLLINFO
) );
526 return sizeof(SCROLLINFO
);
527 case SBM_GETSCROLLBARINFO
:
529 const SCROLLBARINFO
*info
= (const SCROLLBARINFO
*)lparam
;
530 size_t size
= min( info
->cbSize
, sizeof(SCROLLBARINFO
) );
531 push_data( data
, info
, size
);
539 if (wparam
) size
+= sizeof(DWORD
);
540 if (lparam
) size
+= sizeof(DWORD
);
545 case CB_GETDROPPEDCONTROLRECT
:
549 push_data( data
, (RECT
*)lparam
, sizeof(RECT
) );
553 WORD
*pw
= (WORD
*)lparam
;
554 push_data( data
, pw
, sizeof(*pw
) );
555 return *pw
* sizeof(WCHAR
);
559 if (wparam
) push_data( data
, (UINT
*)lparam
, sizeof(UINT
) * wparam
);
562 case CB_INSERTSTRING
:
564 case CB_FINDSTRINGEXACT
:
565 case CB_SELECTSTRING
:
566 if (combobox_has_strings( hwnd
)) push_string( data
, (LPWSTR
)lparam
);
569 if (!combobox_has_strings( hwnd
)) return sizeof(ULONG_PTR
);
570 return (SendMessageW( hwnd
, CB_GETLBTEXTLEN
, wparam
, 0 ) + 1) * sizeof(WCHAR
);
572 case LB_INSERTSTRING
:
574 case LB_FINDSTRINGEXACT
:
575 case LB_SELECTSTRING
:
576 if (listbox_has_strings( hwnd
)) push_string( data
, (LPWSTR
)lparam
);
579 if (!listbox_has_strings( hwnd
)) return sizeof(ULONG_PTR
);
580 return (SendMessageW( hwnd
, LB_GETTEXTLEN
, wparam
, 0 ) + 1) * sizeof(WCHAR
);
582 return wparam
* sizeof(UINT
);
584 push_data( data
, (MDINEXTMENU
*)lparam
, sizeof(MDINEXTMENU
) );
585 return sizeof(MDINEXTMENU
);
588 push_data( data
, (RECT
*)lparam
, sizeof(RECT
) );
592 MDICREATESTRUCTW
*cs
= (MDICREATESTRUCTW
*)lparam
;
593 push_data( data
, cs
, sizeof(*cs
) );
594 if (HIWORD(cs
->szTitle
)) push_string( data
, cs
->szTitle
);
595 if (HIWORD(cs
->szClass
)) push_string( data
, cs
->szClass
);
598 case WM_MDIGETACTIVE
:
599 if (lparam
) return sizeof(BOOL
);
601 case WM_WINE_SETWINDOWPOS
:
602 push_data( data
, (WINDOWPOS
*)lparam
, sizeof(WINDOWPOS
) );
604 case WM_WINE_KEYBOARD_LL_HOOK
:
605 push_data( data
, (KBDLLHOOKSTRUCT
*)lparam
, sizeof(KBDLLHOOKSTRUCT
) );
607 case WM_WINE_MOUSE_LL_HOOK
:
608 push_data( data
, (MSLLHOOKSTRUCT
*)lparam
, sizeof(MSLLHOOKSTRUCT
) );
611 if (!wparam
) return 0;
614 /* these contain an HFONT */
617 /* these contain an HDC */
619 case WM_ICONERASEBKGND
:
621 case WM_CTLCOLORMSGBOX
:
622 case WM_CTLCOLOREDIT
:
623 case WM_CTLCOLORLISTBOX
:
626 case WM_CTLCOLORSCROLLBAR
:
627 case WM_CTLCOLORSTATIC
:
630 /* these contain an HGLOBAL */
631 case WM_PAINTCLIPBOARD
:
632 case WM_SIZECLIPBOARD
:
633 /* these contain HICON */
636 case WM_QUERYDRAGICON
:
637 case WM_QUERYPARKICON
:
638 /* these contain pointers */
640 case WM_QUERYDROPOBJECT
:
644 case WM_DEVICECHANGE
:
645 FIXME( "msg %x (%s) not supported yet\n", message
, SPY_GetMsgName(message
, hwnd
) );
653 /***********************************************************************
656 * Unpack a message received from another process.
658 static BOOL
unpack_message( HWND hwnd
, UINT message
, WPARAM
*wparam
, LPARAM
*lparam
,
659 void **buffer
, size_t size
)
668 CREATESTRUCTW
*cs
= *buffer
;
669 WCHAR
*str
= (WCHAR
*)(cs
+ 1);
670 if (size
< sizeof(*cs
)) return FALSE
;
672 if (HIWORD(cs
->lpszName
))
674 if (!check_string( str
, size
)) return FALSE
;
676 size
-= (strlenW(str
) + 1) * sizeof(WCHAR
);
677 str
+= strlenW(str
) + 1;
679 if (HIWORD(cs
->lpszClass
))
681 if (!check_string( str
, size
)) return FALSE
;
687 case WM_ASKCBFORMATNAME
:
688 if (!get_buffer_space( buffer
, (*wparam
* sizeof(WCHAR
)) )) return FALSE
;
690 case WM_WININICHANGE
:
691 if (!*lparam
) return TRUE
;
694 case WM_DEVMODECHANGE
:
699 if (!check_string( *buffer
, size
)) return FALSE
;
701 case WM_GETMINMAXINFO
:
702 minsize
= sizeof(MINMAXINFO
);
705 minsize
= sizeof(DRAWITEMSTRUCT
);
708 minsize
= sizeof(MEASUREITEMSTRUCT
);
711 minsize
= sizeof(DELETEITEMSTRUCT
);
714 minsize
= sizeof(COMPAREITEMSTRUCT
);
716 case WM_WINDOWPOSCHANGING
:
717 case WM_WINDOWPOSCHANGED
:
718 case WM_WINE_SETWINDOWPOS
:
719 minsize
= sizeof(WINDOWPOS
);
723 COPYDATASTRUCT
*cp
= *buffer
;
724 if (size
< sizeof(*cp
)) return FALSE
;
727 minsize
= sizeof(*cp
) + cp
->cbData
;
733 /* WM_NOTIFY cannot be sent across processes (MSDN) */
736 minsize
= sizeof(HELPINFO
);
738 case WM_STYLECHANGING
:
739 case WM_STYLECHANGED
:
740 minsize
= sizeof(STYLESTRUCT
);
743 if (!*wparam
) minsize
= sizeof(RECT
);
746 NCCALCSIZE_PARAMS
*nc
= *buffer
;
747 if (size
< sizeof(*nc
) + sizeof(*nc
->lppos
)) return FALSE
;
748 nc
->lppos
= (WINDOWPOS
*)(nc
+ 1);
752 if (!*lparam
) return TRUE
;
753 minsize
= sizeof(MSG
);
755 case SBM_SETSCROLLINFO
:
756 minsize
= sizeof(SCROLLINFO
);
758 case SBM_GETSCROLLINFO
:
759 if (!get_buffer_space( buffer
, sizeof(SCROLLINFO
))) return FALSE
;
761 case SBM_GETSCROLLBARINFO
:
762 if (!get_buffer_space( buffer
, sizeof(SCROLLBARINFO
))) return FALSE
;
767 if (*wparam
|| *lparam
)
769 if (!get_buffer_space( buffer
, 2*sizeof(DWORD
) )) return FALSE
;
770 if (*wparam
) *wparam
= (WPARAM
)*buffer
;
771 if (*lparam
) *lparam
= (LPARAM
)((DWORD
*)*buffer
+ 1);
776 case CB_GETDROPPEDCONTROLRECT
:
777 if (!get_buffer_space( buffer
, sizeof(RECT
) )) return FALSE
;
781 minsize
= sizeof(RECT
);
786 if (size
< sizeof(WORD
)) return FALSE
;
787 len
= *(WORD
*)*buffer
;
788 if (!get_buffer_space( buffer
, (len
+ 1) * sizeof(WCHAR
) )) return FALSE
;
789 *lparam
= (LPARAM
)*buffer
+ sizeof(WORD
); /* don't erase WORD at start of buffer */
794 if (!*wparam
) return TRUE
;
795 minsize
= *wparam
* sizeof(UINT
);
798 case CB_INSERTSTRING
:
800 case CB_FINDSTRINGEXACT
:
801 case CB_SELECTSTRING
:
803 case LB_INSERTSTRING
:
805 case LB_FINDSTRINGEXACT
:
806 case LB_SELECTSTRING
:
807 if (!*buffer
) return TRUE
;
808 if (!check_string( *buffer
, size
)) return FALSE
;
812 size
= sizeof(ULONG_PTR
);
813 if (combobox_has_strings( hwnd
))
814 size
= (SendMessageW( hwnd
, CB_GETLBTEXTLEN
, *wparam
, 0 ) + 1) * sizeof(WCHAR
);
815 if (!get_buffer_space( buffer
, size
)) return FALSE
;
820 size
= sizeof(ULONG_PTR
);
821 if (listbox_has_strings( hwnd
))
822 size
= (SendMessageW( hwnd
, LB_GETTEXTLEN
, *wparam
, 0 ) + 1) * sizeof(WCHAR
);
823 if (!get_buffer_space( buffer
, size
)) return FALSE
;
827 if (!get_buffer_space( buffer
, *wparam
* sizeof(UINT
) )) return FALSE
;
830 minsize
= sizeof(MDINEXTMENU
);
831 if (!get_buffer_space( buffer
, sizeof(MDINEXTMENU
) )) return FALSE
;
835 minsize
= sizeof(RECT
);
836 if (!get_buffer_space( buffer
, sizeof(RECT
) )) return FALSE
;
840 MDICREATESTRUCTW
*cs
= *buffer
;
841 WCHAR
*str
= (WCHAR
*)(cs
+ 1);
842 if (size
< sizeof(*cs
)) return FALSE
;
844 if (HIWORD(cs
->szTitle
))
846 if (!check_string( str
, size
)) return FALSE
;
848 size
-= (strlenW(str
) + 1) * sizeof(WCHAR
);
849 str
+= strlenW(str
) + 1;
851 if (HIWORD(cs
->szClass
))
853 if (!check_string( str
, size
)) return FALSE
;
858 case WM_MDIGETACTIVE
:
859 if (!*lparam
) return TRUE
;
860 if (!get_buffer_space( buffer
, sizeof(BOOL
) )) return FALSE
;
862 case WM_WINE_KEYBOARD_LL_HOOK
:
863 minsize
= sizeof(KBDLLHOOKSTRUCT
);
865 case WM_WINE_MOUSE_LL_HOOK
:
866 minsize
= sizeof(MSLLHOOKSTRUCT
);
869 if (!*wparam
) return TRUE
;
872 /* these contain an HFONT */
875 /* these contain an HDC */
877 case WM_ICONERASEBKGND
:
879 case WM_CTLCOLORMSGBOX
:
880 case WM_CTLCOLOREDIT
:
881 case WM_CTLCOLORLISTBOX
:
884 case WM_CTLCOLORSCROLLBAR
:
885 case WM_CTLCOLORSTATIC
:
888 /* these contain an HGLOBAL */
889 case WM_PAINTCLIPBOARD
:
890 case WM_SIZECLIPBOARD
:
891 /* these contain HICON */
894 case WM_QUERYDRAGICON
:
895 case WM_QUERYPARKICON
:
896 /* these contain pointers */
898 case WM_QUERYDROPOBJECT
:
902 case WM_DEVICECHANGE
:
903 FIXME( "msg %x (%s) not supported yet\n", message
, SPY_GetMsgName(message
, hwnd
) );
907 return TRUE
; /* message doesn't need any unpacking */
910 /* default exit for most messages: check minsize and store buffer in lparam */
911 if (size
< minsize
) return FALSE
;
912 *lparam
= (LPARAM
)*buffer
;
917 /***********************************************************************
920 * Pack a reply to a message for sending to another process.
922 static void pack_reply( HWND hwnd
, UINT message
, WPARAM wparam
, LPARAM lparam
,
923 LRESULT res
, struct packed_message
*data
)
930 push_data( data
, (CREATESTRUCTW
*)lparam
, sizeof(CREATESTRUCTW
) );
935 push_data( data
, (WCHAR
*)lparam
, (res
+ 1) * sizeof(WCHAR
) );
937 case WM_GETMINMAXINFO
:
938 push_data( data
, (MINMAXINFO
*)lparam
, sizeof(MINMAXINFO
) );
941 push_data( data
, (MEASUREITEMSTRUCT
*)lparam
, sizeof(MEASUREITEMSTRUCT
) );
943 case WM_WINDOWPOSCHANGING
:
944 case WM_WINDOWPOSCHANGED
:
945 push_data( data
, (WINDOWPOS
*)lparam
, sizeof(WINDOWPOS
) );
948 if (lparam
) push_data( data
, (MSG
*)lparam
, sizeof(MSG
) );
950 case SBM_GETSCROLLINFO
:
951 push_data( data
, (SCROLLINFO
*)lparam
, sizeof(SCROLLINFO
) );
955 case CB_GETDROPPEDCONTROLRECT
:
958 push_data( data
, (RECT
*)lparam
, sizeof(RECT
) );
962 WORD
*ptr
= (WORD
*)lparam
;
963 push_data( data
, ptr
, ptr
[-1] * sizeof(WCHAR
) );
967 push_data( data
, (UINT
*)lparam
, wparam
* sizeof(UINT
) );
969 case WM_MDIGETACTIVE
:
970 if (lparam
) push_data( data
, (BOOL
*)lparam
, sizeof(BOOL
) );
974 push_data( data
, (RECT
*)lparam
, sizeof(RECT
) );
977 NCCALCSIZE_PARAMS
*nc
= (NCCALCSIZE_PARAMS
*)lparam
;
978 push_data( data
, nc
, sizeof(*nc
) );
979 push_data( data
, nc
->lppos
, sizeof(*nc
->lppos
) );
985 if (wparam
) push_data( data
, (DWORD
*)wparam
, sizeof(DWORD
) );
986 if (lparam
) push_data( data
, (DWORD
*)lparam
, sizeof(DWORD
) );
989 push_data( data
, (MDINEXTMENU
*)lparam
, sizeof(MDINEXTMENU
) );
992 push_data( data
, (MDICREATESTRUCTW
*)lparam
, sizeof(MDICREATESTRUCTW
) );
994 case WM_ASKCBFORMATNAME
:
995 push_data( data
, (WCHAR
*)lparam
, (strlenW((WCHAR
*)lparam
) + 1) * sizeof(WCHAR
) );
1001 /***********************************************************************
1004 * Unpack a message reply received from another process.
1006 static void unpack_reply( HWND hwnd
, UINT message
, WPARAM wparam
, LPARAM lparam
,
1007 void *buffer
, size_t size
)
1014 CREATESTRUCTW
*cs
= (CREATESTRUCTW
*)lparam
;
1015 LPCWSTR name
= cs
->lpszName
, class = cs
->lpszClass
;
1016 memcpy( cs
, buffer
, min( sizeof(*cs
), size
));
1017 cs
->lpszName
= name
; /* restore the original pointers */
1018 cs
->lpszClass
= class;
1022 case WM_ASKCBFORMATNAME
:
1023 memcpy( (WCHAR
*)lparam
, buffer
, min( wparam
*sizeof(WCHAR
), size
));
1025 case WM_GETMINMAXINFO
:
1026 memcpy( (MINMAXINFO
*)lparam
, buffer
, min( sizeof(MINMAXINFO
), size
));
1028 case WM_MEASUREITEM
:
1029 memcpy( (MEASUREITEMSTRUCT
*)lparam
, buffer
, min( sizeof(MEASUREITEMSTRUCT
), size
));
1031 case WM_WINDOWPOSCHANGING
:
1032 case WM_WINDOWPOSCHANGED
:
1033 memcpy( (WINDOWPOS
*)lparam
, buffer
, min( sizeof(WINDOWPOS
), size
));
1036 if (lparam
) memcpy( (MSG
*)lparam
, buffer
, min( sizeof(MSG
), size
));
1038 case SBM_GETSCROLLINFO
:
1039 memcpy( (SCROLLINFO
*)lparam
, buffer
, min( sizeof(SCROLLINFO
), size
));
1041 case SBM_GETSCROLLBARINFO
:
1042 memcpy( (SCROLLBARINFO
*)lparam
, buffer
, min( sizeof(SCROLLBARINFO
), size
));
1045 case CB_GETDROPPEDCONTROLRECT
:
1046 case LB_GETITEMRECT
:
1049 memcpy( (RECT
*)lparam
, buffer
, min( sizeof(RECT
), size
));
1052 size
= min( size
, (size_t)*(WORD
*)lparam
);
1053 memcpy( (WCHAR
*)lparam
, buffer
, size
);
1055 case LB_GETSELITEMS
:
1056 memcpy( (UINT
*)lparam
, buffer
, min( wparam
*sizeof(UINT
), size
));
1060 memcpy( (WCHAR
*)lparam
, buffer
, size
);
1063 memcpy( (MDINEXTMENU
*)lparam
, buffer
, min( sizeof(MDINEXTMENU
), size
));
1065 case WM_MDIGETACTIVE
:
1066 if (lparam
) memcpy( (BOOL
*)lparam
, buffer
, min( sizeof(BOOL
), size
));
1070 memcpy( (RECT
*)lparam
, buffer
, min( sizeof(RECT
), size
));
1073 NCCALCSIZE_PARAMS
*nc
= (NCCALCSIZE_PARAMS
*)lparam
;
1074 WINDOWPOS
*wp
= nc
->lppos
;
1075 memcpy( nc
, buffer
, min( sizeof(*nc
), size
));
1076 if (size
> sizeof(*nc
))
1078 size
-= sizeof(*nc
);
1079 memcpy( wp
, (NCCALCSIZE_PARAMS
*)buffer
+ 1, min( sizeof(*wp
), size
));
1081 nc
->lppos
= wp
; /* restore the original pointer */
1089 memcpy( (DWORD
*)wparam
, buffer
, min( sizeof(DWORD
), size
));
1090 if (size
<= sizeof(DWORD
)) break;
1091 size
-= sizeof(DWORD
);
1092 buffer
= (DWORD
*)buffer
+ 1;
1094 if (lparam
) memcpy( (DWORD
*)lparam
, buffer
, min( sizeof(DWORD
), size
));
1098 MDICREATESTRUCTW
*cs
= (MDICREATESTRUCTW
*)lparam
;
1099 LPCWSTR title
= cs
->szTitle
, class = cs
->szClass
;
1100 memcpy( cs
, buffer
, min( sizeof(*cs
), size
));
1101 cs
->szTitle
= title
; /* restore the original pointers */
1102 cs
->szClass
= class;
1106 ERR( "should not happen: unexpected message %x\n", message
);
1112 /***********************************************************************
1115 * Send a reply to a sent message.
1117 static void reply_message( struct received_message_info
*info
, LRESULT result
, BOOL remove
)
1119 struct packed_message data
;
1120 int i
, replied
= info
->flags
& ISMEX_REPLIED
;
1122 if (info
->flags
& ISMEX_NOTIFY
) return; /* notify messages don't get replies */
1123 if (!remove
&& replied
) return; /* replied already */
1126 info
->flags
|= ISMEX_REPLIED
;
1128 if (info
->type
== MSG_OTHER_PROCESS
&& !replied
)
1130 pack_reply( info
->msg
.hwnd
, info
->msg
.message
, info
->msg
.wParam
,
1131 info
->msg
.lParam
, result
, &data
);
1134 SERVER_START_REQ( reply_message
)
1136 req
->result
= result
;
1137 req
->remove
= remove
;
1138 for (i
= 0; i
< data
.count
; i
++) wine_server_add_data( req
, data
.data
[i
], data
.size
[i
] );
1139 wine_server_call( req
);
1145 /***********************************************************************
1146 * handle_internal_message
1148 * Handle an internal Wine message instead of calling the window proc.
1150 static LRESULT
handle_internal_message( HWND hwnd
, UINT msg
, WPARAM wparam
, LPARAM lparam
)
1152 if (hwnd
== GetDesktopWindow()) return 0;
1155 case WM_WINE_DESTROYWINDOW
:
1156 return WIN_DestroyWindow( hwnd
);
1157 case WM_WINE_SETWINDOWPOS
:
1158 if (USER_Driver
.pSetWindowPos
)
1159 return USER_Driver
.pSetWindowPos( (WINDOWPOS
*)lparam
);
1161 case WM_WINE_SHOWWINDOW
:
1162 return ShowWindow( hwnd
, wparam
);
1163 case WM_WINE_SETPARENT
:
1164 return (LRESULT
)SetParent( hwnd
, (HWND
)wparam
);
1165 case WM_WINE_SETWINDOWLONG
:
1166 return (LRESULT
)SetWindowLongW( hwnd
, wparam
, lparam
);
1167 case WM_WINE_ENABLEWINDOW
:
1168 return EnableWindow( hwnd
, wparam
);
1169 case WM_WINE_SETACTIVEWINDOW
:
1170 return (LRESULT
)SetActiveWindow( (HWND
)wparam
);
1171 case WM_WINE_KEYBOARD_LL_HOOK
:
1172 return HOOK_CallHooks( WH_KEYBOARD_LL
, HC_ACTION
, wparam
, lparam
, TRUE
);
1173 case WM_WINE_MOUSE_LL_HOOK
:
1174 return HOOK_CallHooks( WH_MOUSE_LL
, HC_ACTION
, wparam
, lparam
, TRUE
);
1176 if (msg
>= WM_WINE_FIRST_DRIVER_MSG
&& msg
<= WM_WINE_LAST_DRIVER_MSG
)
1178 if (!USER_Driver
.pWindowMessage
) return 0;
1179 return USER_Driver
.pWindowMessage( hwnd
, msg
, wparam
, lparam
);
1181 FIXME( "unknown internal message %x\n", msg
);
1186 /* since the WM_DDE_ACK response to a WM_DDE_EXECUTE message should contain the handle
1187 * to the memory handle, we keep track (in the server side) of all pairs of handle
1188 * used (the client passes its value and the content of the memory handle), and
1189 * the server stored both values (the client, and the local one, created after the
1190 * content). When a ACK message is generated, the list of pair is searched for a
1191 * matching pair, so that the client memory handle can be returned.
1194 HGLOBAL client_hMem
;
1195 HGLOBAL server_hMem
;
1198 static struct DDE_pair
* dde_pairs
;
1199 static int dde_num_alloc
;
1200 static int dde_num_used
;
1202 static CRITICAL_SECTION dde_crst
;
1203 static CRITICAL_SECTION_DEBUG critsect_debug
=
1206 { &critsect_debug
.ProcessLocksList
, &critsect_debug
.ProcessLocksList
},
1207 0, 0, { 0, (DWORD
)(__FILE__
": dde_crst") }
1209 static CRITICAL_SECTION dde_crst
= { &critsect_debug
, -1, 0, 0, 0, 0 };
1211 static BOOL
dde_add_pair(HGLOBAL chm
, HGLOBAL shm
)
1216 EnterCriticalSection(&dde_crst
);
1218 /* now remember the pair of hMem on both sides */
1219 if (dde_num_used
== dde_num_alloc
)
1221 struct DDE_pair
* tmp
;
1223 tmp
= HeapReAlloc( GetProcessHeap(), 0, dde_pairs
,
1224 (dde_num_alloc
+ GROWBY
) * sizeof(struct DDE_pair
));
1226 tmp
= HeapAlloc( GetProcessHeap(), 0,
1227 (dde_num_alloc
+ GROWBY
) * sizeof(struct DDE_pair
));
1231 LeaveCriticalSection(&dde_crst
);
1235 /* zero out newly allocated part */
1236 memset(&dde_pairs
[dde_num_alloc
], 0, GROWBY
* sizeof(struct DDE_pair
));
1237 dde_num_alloc
+= GROWBY
;
1240 for (i
= 0; i
< dde_num_alloc
; i
++)
1242 if (dde_pairs
[i
].server_hMem
== 0)
1244 dde_pairs
[i
].client_hMem
= chm
;
1245 dde_pairs
[i
].server_hMem
= shm
;
1250 LeaveCriticalSection(&dde_crst
);
1254 static HGLOBAL
dde_get_pair(HGLOBAL shm
)
1259 EnterCriticalSection(&dde_crst
);
1260 for (i
= 0; i
< dde_num_alloc
; i
++)
1262 if (dde_pairs
[i
].server_hMem
== shm
)
1264 /* free this pair */
1265 dde_pairs
[i
].server_hMem
= 0;
1267 ret
= dde_pairs
[i
].client_hMem
;
1271 LeaveCriticalSection(&dde_crst
);
1275 /***********************************************************************
1278 * Post a DDE message
1280 static BOOL
post_dde_message( DWORD dest_tid
, struct packed_message
*data
, const struct send_message_info
*info
)
1286 HGLOBAL hunlock
= 0;
1290 if (!UnpackDDElParam( info
->msg
, info
->lparam
, &uiLo
, &uiHi
))
1296 /* DDE messages which don't require packing are:
1305 /* uiHi should contain a hMem from WM_DDE_EXECUTE */
1306 HGLOBAL h
= dde_get_pair( (HANDLE
)uiHi
);
1309 /* send back the value of h on the other side */
1310 push_data( data
, &h
, sizeof(HGLOBAL
) );
1312 TRACE( "send dde-ack %x %08x => %08lx\n", uiLo
, uiHi
, (DWORD
)h
);
1317 /* uiHi should contain either an atom or 0 */
1318 TRACE( "send dde-ack %x atom=%x\n", uiLo
, uiHi
);
1319 lp
= MAKELONG( uiLo
, uiHi
);
1328 size
= GlobalSize( (HGLOBAL
)uiLo
) ;
1329 if ((info
->msg
== WM_DDE_ADVISE
&& size
< sizeof(DDEADVISE
)) ||
1330 (info
->msg
== WM_DDE_DATA
&& size
< sizeof(DDEDATA
)) ||
1331 (info
->msg
== WM_DDE_POKE
&& size
< sizeof(DDEPOKE
))
1335 else if (info
->msg
!= WM_DDE_DATA
) return FALSE
;
1340 if ((ptr
= GlobalLock( (HGLOBAL
)uiLo
) ))
1342 DDEDATA
*dde_data
= (DDEDATA
*)ptr
;
1343 TRACE("unused %d, fResponse %d, fRelease %d, fDeferUpd %d, fAckReq %d, cfFormat %d\n",
1344 dde_data
->unused
, dde_data
->fResponse
, dde_data
->fRelease
,
1345 dde_data
->reserved
, dde_data
->fAckReq
, dde_data
->cfFormat
);
1346 push_data( data
, ptr
, size
);
1347 hunlock
= (HGLOBAL
)uiLo
;
1350 TRACE( "send ddepack %u %x\n", size
, uiHi
);
1352 case WM_DDE_EXECUTE
:
1355 if ((ptr
= GlobalLock( (HGLOBAL
)info
->lparam
) ))
1357 push_data(data
, ptr
, GlobalSize( (HGLOBAL
)info
->lparam
));
1358 /* so that the other side can send it back on ACK */
1360 hunlock
= (HGLOBAL
)info
->lparam
;
1365 SERVER_START_REQ( send_message
)
1368 req
->type
= info
->type
;
1370 req
->win
= info
->hwnd
;
1371 req
->msg
= info
->msg
;
1372 req
->wparam
= info
->wparam
;
1374 req
->time
= GetCurrentTime();
1376 for (i
= 0; i
< data
->count
; i
++)
1377 wine_server_add_data( req
, data
->data
[i
], data
->size
[i
] );
1378 if ((res
= wine_server_call( req
)))
1380 if (res
== STATUS_INVALID_PARAMETER
)
1381 /* FIXME: find a STATUS_ value for this one */
1382 SetLastError( ERROR_INVALID_THREAD_ID
);
1384 SetLastError( RtlNtStatusToDosError(res
) );
1387 FreeDDElParam(info
->msg
, info
->lparam
);
1390 if (hunlock
) GlobalUnlock(hunlock
);
1395 /***********************************************************************
1396 * unpack_dde_message
1398 * Unpack a posted DDE message received from another process.
1400 static BOOL
unpack_dde_message( HWND hwnd
, UINT message
, WPARAM
*wparam
, LPARAM
*lparam
,
1401 void **buffer
, size_t size
)
1412 /* hMem is being passed */
1413 if (size
!= sizeof(HGLOBAL
)) return FALSE
;
1414 if (!buffer
|| !*buffer
) return FALSE
;
1416 memcpy( &hMem
, *buffer
, size
);
1418 TRACE("recv dde-ack %x mem=%x[%lx]\n", uiLo
, uiHi
, GlobalSize( hMem
));
1422 uiLo
= LOWORD( *lparam
);
1423 uiHi
= HIWORD( *lparam
);
1424 TRACE("recv dde-ack %x atom=%x\n", uiLo
, uiHi
);
1426 *lparam
= PackDDElParam( WM_DDE_ACK
, uiLo
, uiHi
);
1431 if ((!buffer
|| !*buffer
) && message
!= WM_DDE_DATA
) return FALSE
;
1433 TRACE( "recv ddepack %u %x\n", size
, uiHi
);
1436 if (!(hMem
= GlobalAlloc( GMEM_MOVEABLE
|GMEM_DDESHARE
, size
)))
1438 if ((ptr
= GlobalLock( hMem
)))
1440 memcpy( ptr
, *buffer
, size
);
1441 GlobalUnlock( hMem
);
1451 *lparam
= PackDDElParam( message
, uiLo
, uiHi
);
1453 case WM_DDE_EXECUTE
:
1456 if (!buffer
|| !*buffer
) return FALSE
;
1457 if (!(hMem
= GlobalAlloc( GMEM_MOVEABLE
|GMEM_DDESHARE
, size
))) return FALSE
;
1458 if ((ptr
= GlobalLock( hMem
)))
1460 memcpy( ptr
, *buffer
, size
);
1461 GlobalUnlock( hMem
);
1462 TRACE( "exec: pairing c=%08lx s=%08lx\n", *lparam
, (DWORD
)hMem
);
1463 if (!dde_add_pair( (HGLOBAL
)*lparam
, hMem
))
1474 } else return FALSE
;
1475 *lparam
= (LPARAM
)hMem
;
1481 /***********************************************************************
1484 * Call a window procedure and the corresponding hooks.
1486 static LRESULT
call_window_proc( HWND hwnd
, UINT msg
, WPARAM wparam
, LPARAM lparam
,
1487 BOOL unicode
, BOOL same_thread
)
1489 struct user_thread_info
*thread_info
= get_user_thread_info();
1493 CWPRETSTRUCT cwpret
;
1495 if (thread_info
->recursion_count
> MAX_SENDMSG_RECURSION
) return 0;
1496 thread_info
->recursion_count
++;
1498 if (msg
& 0x80000000)
1500 result
= handle_internal_message( hwnd
, msg
, wparam
, lparam
);
1504 /* first the WH_CALLWNDPROC hook */
1505 hwnd
= WIN_GetFullHandle( hwnd
);
1506 cwp
.lParam
= lparam
;
1507 cwp
.wParam
= wparam
;
1510 HOOK_CallHooks( WH_CALLWNDPROC
, HC_ACTION
, same_thread
, (LPARAM
)&cwp
, unicode
);
1512 /* now call the window procedure */
1515 if (!(winproc
= (WNDPROC
)GetWindowLongPtrW( hwnd
, GWLP_WNDPROC
))) goto done
;
1516 result
= CallWindowProcW( winproc
, hwnd
, msg
, wparam
, lparam
);
1520 if (!(winproc
= (WNDPROC
)GetWindowLongPtrA( hwnd
, GWLP_WNDPROC
))) goto done
;
1521 result
= CallWindowProcA( winproc
, hwnd
, msg
, wparam
, lparam
);
1524 /* and finally the WH_CALLWNDPROCRET hook */
1525 cwpret
.lResult
= result
;
1526 cwpret
.lParam
= lparam
;
1527 cwpret
.wParam
= wparam
;
1528 cwpret
.message
= msg
;
1530 HOOK_CallHooks( WH_CALLWNDPROCRET
, HC_ACTION
, same_thread
, (LPARAM
)&cwpret
, unicode
);
1532 thread_info
->recursion_count
--;
1537 /***********************************************************************
1538 * send_parent_notify
1540 * Send a WM_PARENTNOTIFY to all ancestors of the given window, unless
1541 * the window has the WS_EX_NOPARENTNOTIFY style.
1543 static void send_parent_notify( HWND hwnd
, WORD event
, WORD idChild
, POINT pt
)
1545 /* pt has to be in the client coordinates of the parent window */
1546 MapWindowPoints( 0, hwnd
, &pt
, 1 );
1551 if (!(GetWindowLongW( hwnd
, GWL_STYLE
) & WS_CHILD
)) break;
1552 if (GetWindowLongW( hwnd
, GWL_EXSTYLE
) & WS_EX_NOPARENTNOTIFY
) break;
1553 if (!(parent
= GetParent(hwnd
))) break;
1554 MapWindowPoints( hwnd
, parent
, &pt
, 1 );
1556 SendMessageW( hwnd
, WM_PARENTNOTIFY
,
1557 MAKEWPARAM( event
, idChild
), MAKELPARAM( pt
.x
, pt
.y
) );
1562 /***********************************************************************
1563 * accept_hardware_message
1565 * Tell the server we have passed the message to the app
1566 * (even though we may end up dropping it later on)
1568 static void accept_hardware_message( UINT hw_id
, BOOL remove
, HWND new_hwnd
)
1570 SERVER_START_REQ( accept_hardware_message
)
1573 req
->remove
= remove
;
1574 req
->new_win
= new_hwnd
;
1575 if (wine_server_call( req
))
1576 FIXME("Failed to reply to MSG_HARDWARE message. Message may not be removed from queue.\n");
1582 /***********************************************************************
1583 * process_keyboard_message
1585 * returns TRUE if the contents of 'msg' should be passed to the application
1587 static BOOL
process_keyboard_message( MSG
*msg
, UINT hw_id
, HWND hwnd_filter
,
1588 UINT first
, UINT last
, BOOL remove
)
1592 /* FIXME: is this really the right place for this hook? */
1593 event
.message
= msg
->message
;
1594 event
.hwnd
= msg
->hwnd
;
1595 event
.time
= msg
->time
;
1596 event
.paramL
= (msg
->wParam
& 0xFF) | (HIWORD(msg
->lParam
) << 8);
1597 event
.paramH
= msg
->lParam
& 0x7FFF;
1598 if (HIWORD(msg
->lParam
) & 0x0100) event
.paramH
|= 0x8000; /* special_key - bit */
1599 HOOK_CallHooks( WH_JOURNALRECORD
, HC_ACTION
, 0, (LPARAM
)&event
, TRUE
);
1601 /* check message filters */
1602 if (msg
->message
< first
|| msg
->message
> last
) return FALSE
;
1603 if (!check_hwnd_filter( msg
, hwnd_filter
)) return FALSE
;
1607 /* Handle F1 key by sending out WM_HELP message */
1608 if ((msg
->message
== WM_KEYUP
) &&
1609 (msg
->wParam
== VK_F1
) &&
1610 (msg
->hwnd
!= GetDesktopWindow()) &&
1611 !MENU_IsMenuActive())
1614 hi
.cbSize
= sizeof(HELPINFO
);
1615 hi
.iContextType
= HELPINFO_WINDOW
;
1616 hi
.iCtrlId
= GetWindowLongPtrA( msg
->hwnd
, GWLP_ID
);
1617 hi
.hItemHandle
= msg
->hwnd
;
1618 hi
.dwContextId
= GetWindowContextHelpId( msg
->hwnd
);
1619 hi
.MousePos
= msg
->pt
;
1620 SendMessageW( msg
->hwnd
, WM_HELP
, 0, (LPARAM
)&hi
);
1624 if (HOOK_CallHooks( WH_KEYBOARD
, remove
? HC_ACTION
: HC_NOREMOVE
,
1625 LOWORD(msg
->wParam
), msg
->lParam
, TRUE
))
1627 /* skip this message */
1628 HOOK_CallHooks( WH_CBT
, HCBT_KEYSKIPPED
, LOWORD(msg
->wParam
), msg
->lParam
, TRUE
);
1629 accept_hardware_message( hw_id
, TRUE
, 0 );
1632 accept_hardware_message( hw_id
, remove
, 0 );
1637 /***********************************************************************
1638 * process_mouse_message
1640 * returns TRUE if the contents of 'msg' should be passed to the application
1642 static BOOL
process_mouse_message( MSG
*msg
, UINT hw_id
, ULONG_PTR extra_info
, HWND hwnd_filter
,
1643 UINT first
, UINT last
, BOOL remove
)
1652 MOUSEHOOKSTRUCT hook
;
1655 /* find the window to dispatch this mouse message to */
1658 GetGUIThreadInfo( GetCurrentThreadId(), &info
);
1659 if (!(msg
->hwnd
= info
.hwndCapture
))
1661 HWND hWndScope
= msg
->hwnd
;
1662 /* If no capture HWND, find window which contains the mouse position.
1663 * Also find the position of the cursor hot spot (hittest) */
1664 if (!IsWindow(hWndScope
)) hWndScope
= 0;
1665 if (!(msg
->hwnd
= WINPOS_WindowFromPoint( hWndScope
, msg
->pt
, &hittest
)))
1666 msg
->hwnd
= GetDesktopWindow();
1669 if (!WIN_IsCurrentThread( msg
->hwnd
))
1671 accept_hardware_message( hw_id
, FALSE
, msg
->hwnd
);
1675 /* FIXME: is this really the right place for this hook? */
1676 event
.message
= msg
->message
;
1677 event
.time
= msg
->time
;
1678 event
.hwnd
= msg
->hwnd
;
1679 event
.paramL
= msg
->pt
.x
;
1680 event
.paramH
= msg
->pt
.y
;
1681 HOOK_CallHooks( WH_JOURNALRECORD
, HC_ACTION
, 0, (LPARAM
)&event
, TRUE
);
1683 if (!check_hwnd_filter( msg
, hwnd_filter
)) return FALSE
;
1686 message
= msg
->message
;
1687 /* Note: windows has no concept of a non-client wheel message */
1688 if (message
!= WM_MOUSEWHEEL
)
1690 if (hittest
!= HTCLIENT
)
1692 message
+= WM_NCMOUSEMOVE
- WM_MOUSEMOVE
;
1693 msg
->wParam
= hittest
;
1697 /* coordinates don't get translated while tracking a menu */
1698 /* FIXME: should differentiate popups and top-level menus */
1699 if (!(info
.flags
& GUI_INMENUMODE
))
1700 ScreenToClient( msg
->hwnd
, &pt
);
1703 msg
->lParam
= MAKELONG( pt
.x
, pt
.y
);
1705 /* translate double clicks */
1707 if ((msg
->message
== WM_LBUTTONDOWN
) ||
1708 (msg
->message
== WM_RBUTTONDOWN
) ||
1709 (msg
->message
== WM_MBUTTONDOWN
) ||
1710 (msg
->message
== WM_XBUTTONDOWN
))
1712 BOOL update
= remove
;
1714 /* translate double clicks -
1715 * note that ...MOUSEMOVEs can slip in between
1716 * ...BUTTONDOWN and ...BUTTONDBLCLK messages */
1718 if ((info
.flags
& (GUI_INMENUMODE
|GUI_INMOVESIZE
)) ||
1719 hittest
!= HTCLIENT
||
1720 (GetClassLongA( msg
->hwnd
, GCL_STYLE
) & CS_DBLCLKS
))
1722 if ((msg
->message
== clk_msg
.message
) &&
1723 (msg
->hwnd
== clk_msg
.hwnd
) &&
1724 (msg
->wParam
== clk_msg
.wParam
) &&
1725 (msg
->time
- clk_msg
.time
< GetDoubleClickTime()) &&
1726 (abs(msg
->pt
.x
- clk_msg
.pt
.x
) < GetSystemMetrics(SM_CXDOUBLECLK
)/2) &&
1727 (abs(msg
->pt
.y
- clk_msg
.pt
.y
) < GetSystemMetrics(SM_CYDOUBLECLK
)/2))
1729 message
+= (WM_LBUTTONDBLCLK
- WM_LBUTTONDOWN
);
1730 clk_msg
.message
= 0; /* clear the double click conditions */
1734 if (message
< first
|| message
> last
) return FALSE
;
1735 /* update static double click conditions */
1736 if (update
) clk_msg
= *msg
;
1740 if (message
< first
|| message
> last
) return FALSE
;
1743 /* message is accepted now (but may still get dropped) */
1746 hook
.hwnd
= msg
->hwnd
;
1747 hook
.wHitTestCode
= hittest
;
1748 hook
.dwExtraInfo
= extra_info
;
1749 if (HOOK_CallHooks( WH_MOUSE
, remove
? HC_ACTION
: HC_NOREMOVE
,
1750 message
, (LPARAM
)&hook
, TRUE
))
1753 hook
.hwnd
= msg
->hwnd
;
1754 hook
.wHitTestCode
= hittest
;
1755 hook
.dwExtraInfo
= extra_info
;
1756 HOOK_CallHooks( WH_CBT
, HCBT_CLICKSKIPPED
, message
, (LPARAM
)&hook
, TRUE
);
1757 accept_hardware_message( hw_id
, TRUE
, 0 );
1761 if ((hittest
== HTERROR
) || (hittest
== HTNOWHERE
))
1763 SendMessageW( msg
->hwnd
, WM_SETCURSOR
, (WPARAM
)msg
->hwnd
,
1764 MAKELONG( hittest
, msg
->message
));
1765 accept_hardware_message( hw_id
, TRUE
, 0 );
1769 accept_hardware_message( hw_id
, remove
, 0 );
1771 if (!remove
|| info
.hwndCapture
)
1773 msg
->message
= message
;
1779 if ((msg
->message
== WM_LBUTTONDOWN
) ||
1780 (msg
->message
== WM_RBUTTONDOWN
) ||
1781 (msg
->message
== WM_MBUTTONDOWN
) ||
1782 (msg
->message
== WM_XBUTTONDOWN
))
1784 /* Send the WM_PARENTNOTIFY,
1785 * note that even for double/nonclient clicks
1786 * notification message is still WM_L/M/RBUTTONDOWN.
1788 send_parent_notify( msg
->hwnd
, msg
->message
, 0, msg
->pt
);
1790 /* Activate the window if needed */
1792 if (msg
->hwnd
!= info
.hwndActive
)
1794 HWND hwndTop
= msg
->hwnd
;
1797 if ((GetWindowLongW( hwndTop
, GWL_STYLE
) & (WS_POPUP
|WS_CHILD
)) != WS_CHILD
) break;
1798 hwndTop
= GetParent( hwndTop
);
1801 if (hwndTop
&& hwndTop
!= GetDesktopWindow())
1803 LONG ret
= SendMessageW( msg
->hwnd
, WM_MOUSEACTIVATE
, (WPARAM
)hwndTop
,
1804 MAKELONG( hittest
, msg
->message
) );
1807 case MA_NOACTIVATEANDEAT
:
1812 case MA_ACTIVATEANDEAT
:
1817 if (!FOCUS_MouseActivate( hwndTop
)) eatMsg
= TRUE
;
1820 WARN( "unknown WM_MOUSEACTIVATE code %ld\n", ret
);
1827 /* send the WM_SETCURSOR message */
1829 /* Windows sends the normal mouse message as the message parameter
1830 in the WM_SETCURSOR message even if it's non-client mouse message */
1831 SendMessageW( msg
->hwnd
, WM_SETCURSOR
, (WPARAM
)msg
->hwnd
, MAKELONG( hittest
, msg
->message
));
1833 msg
->message
= message
;
1838 /***********************************************************************
1839 * process_hardware_message
1841 * Process a hardware message; return TRUE if message should be passed on to the app
1843 static BOOL
process_hardware_message( MSG
*msg
, UINT hw_id
, ULONG_PTR extra_info
, HWND hwnd_filter
,
1844 UINT first
, UINT last
, BOOL remove
)
1846 if (is_keyboard_message( msg
->message
))
1847 return process_keyboard_message( msg
, hw_id
, hwnd_filter
, first
, last
, remove
);
1849 if (is_mouse_message( msg
->message
))
1850 return process_mouse_message( msg
, hw_id
, extra_info
, hwnd_filter
, first
, last
, remove
);
1852 ERR( "unknown message type %x\n", msg
->message
);
1857 /***********************************************************************
1858 * call_sendmsg_callback
1860 * Call the callback function of SendMessageCallback.
1862 static inline void call_sendmsg_callback( SENDASYNCPROC callback
, HWND hwnd
, UINT msg
,
1863 ULONG_PTR data
, LRESULT result
)
1865 if (TRACE_ON(relay
))
1866 DPRINTF( "%04lx:Call message callback %p (hwnd=%p,msg=%s,data=%08lx,result=%08lx)\n",
1867 GetCurrentThreadId(), callback
, hwnd
, SPY_GetMsgName( msg
, hwnd
),
1869 callback( hwnd
, msg
, data
, result
);
1870 if (TRACE_ON(relay
))
1871 DPRINTF( "%04lx:Ret message callback %p (hwnd=%p,msg=%s,data=%08lx,result=%08lx)\n",
1872 GetCurrentThreadId(), callback
, hwnd
, SPY_GetMsgName( msg
, hwnd
),
1877 /***********************************************************************
1880 * Retrieve the hook procedure real value for a module-relative proc
1882 static void *get_hook_proc( void *proc
, const WCHAR
*module
)
1886 if (!(mod
= GetModuleHandleW(module
)))
1888 TRACE( "loading %s\n", debugstr_w(module
) );
1889 /* FIXME: the library will never be freed */
1890 if (!(mod
= LoadLibraryW(module
))) return NULL
;
1892 return (char *)mod
+ (ULONG_PTR
)proc
;
1896 /***********************************************************************
1899 * Peek for a message matching the given parameters. Return FALSE if none available.
1900 * All pending sent messages are processed before returning.
1902 static BOOL
peek_message( MSG
*msg
, HWND hwnd
, UINT first
, UINT last
, int flags
)
1905 ULONG_PTR extra_info
= 0;
1906 struct user_thread_info
*thread_info
= get_user_thread_info();
1907 struct received_message_info info
, *old_info
;
1908 unsigned int hw_id
= 0; /* id of previous hardware message */
1910 if (!first
&& !last
) last
= ~0;
1915 void *buffer
= NULL
;
1916 size_t size
= 0, buffer_size
= 0;
1918 do /* loop while buffer is too small */
1920 if (buffer_size
&& !(buffer
= HeapAlloc( GetProcessHeap(), 0, buffer_size
)))
1922 SERVER_START_REQ( get_message
)
1925 req
->get_win
= hwnd
;
1926 req
->get_first
= first
;
1927 req
->get_last
= last
;
1929 if (buffer_size
) wine_server_set_reply( req
, buffer
, buffer_size
);
1930 if (!(res
= wine_server_call( req
)))
1932 size
= wine_server_reply_size( reply
);
1933 info
.type
= reply
->type
;
1934 info
.msg
.hwnd
= reply
->win
;
1935 info
.msg
.message
= reply
->msg
;
1936 info
.msg
.wParam
= reply
->wparam
;
1937 info
.msg
.lParam
= reply
->lparam
;
1938 info
.msg
.time
= reply
->time
;
1939 info
.msg
.pt
.x
= reply
->x
;
1940 info
.msg
.pt
.y
= reply
->y
;
1941 info
.hook
= reply
->hook
;
1942 info
.hook_proc
= reply
->hook_proc
;
1943 hw_id
= reply
->hw_id
;
1944 extra_info
= reply
->info
;
1945 thread_info
->active_hooks
= reply
->active_hooks
;
1949 HeapFree( GetProcessHeap(), 0, buffer
);
1950 buffer_size
= reply
->total
;
1954 } while (res
== STATUS_BUFFER_OVERFLOW
);
1956 if (res
) return FALSE
;
1958 TRACE( "got type %d msg %x (%s) hwnd %p wp %x lp %lx\n",
1959 info
.type
, info
.msg
.message
,
1960 (info
.type
== MSG_WINEVENT
) ? "MSG_WINEVENT" : SPY_GetMsgName(info
.msg
.message
, info
.msg
.hwnd
),
1961 info
.msg
.hwnd
, info
.msg
.wParam
, info
.msg
.lParam
);
1967 info
.flags
= ISMEX_SEND
;
1970 info
.flags
= ISMEX_NOTIFY
;
1973 info
.flags
= ISMEX_CALLBACK
;
1975 case MSG_CALLBACK_RESULT
:
1976 call_sendmsg_callback( (SENDASYNCPROC
)info
.msg
.wParam
, info
.msg
.hwnd
,
1977 info
.msg
.message
, extra_info
, info
.msg
.lParam
);
1982 WCHAR module
[MAX_PATH
];
1983 size
= min( size
, (MAX_PATH
- 1) * sizeof(WCHAR
) );
1984 memcpy( module
, buffer
, size
);
1985 module
[size
/ sizeof(WCHAR
)] = 0;
1986 if (!(info
.hook_proc
= get_hook_proc( info
.hook_proc
, module
)))
1988 ERR( "invalid winevent hook module name %s\n", debugstr_w(module
) );
1992 if (TRACE_ON(relay
))
1993 DPRINTF( "%04lx:Call winevent proc %p (hook=%p,event=%x,hwnd=%p,object_id=%x,child_id=%lx,tid=%04lx,time=%lx)\n",
1994 GetCurrentThreadId(), info
.hook_proc
,
1995 info
.hook
, info
.msg
.message
, info
.msg
.hwnd
, info
.msg
.wParam
,
1996 info
.msg
.lParam
, extra_info
, info
.msg
.time
);
1998 info
.hook_proc( info
.hook
, info
.msg
.message
, info
.msg
.hwnd
, info
.msg
.wParam
,
1999 info
.msg
.lParam
, extra_info
, info
.msg
.time
);
2001 if (TRACE_ON(relay
))
2002 DPRINTF( "%04lx:Ret winevent proc %p (hook=%p,event=%x,hwnd=%p,object_id=%x,child_id=%lx,tid=%04lx,time=%lx)\n",
2003 GetCurrentThreadId(), info
.hook_proc
,
2004 info
.hook
, info
.msg
.message
, info
.msg
.hwnd
, info
.msg
.wParam
,
2005 info
.msg
.lParam
, extra_info
, info
.msg
.time
);
2007 case MSG_OTHER_PROCESS
:
2008 info
.flags
= ISMEX_SEND
;
2009 if (!unpack_message( info
.msg
.hwnd
, info
.msg
.message
, &info
.msg
.wParam
,
2010 &info
.msg
.lParam
, &buffer
, size
))
2012 ERR( "invalid packed message %x (%s) hwnd %p wp %x lp %lx size %d\n",
2013 info
.msg
.message
, SPY_GetMsgName(info
.msg
.message
, info
.msg
.hwnd
), info
.msg
.hwnd
,
2014 info
.msg
.wParam
, info
.msg
.lParam
, size
);
2016 reply_message( &info
, 0, TRUE
);
2021 if (!process_hardware_message( &info
.msg
, hw_id
, extra_info
,
2022 hwnd
, first
, last
, flags
& GET_MSG_REMOVE
))
2024 TRACE("dropping msg %x\n", info
.msg
.message
);
2025 goto next
; /* ignore it */
2027 thread_info
->GetMessagePosVal
= MAKELONG( info
.msg
.pt
.x
, info
.msg
.pt
.y
);
2030 thread_info
->GetMessageExtraInfoVal
= extra_info
;
2031 if (info
.msg
.message
>= WM_DDE_FIRST
&& info
.msg
.message
<= WM_DDE_LAST
)
2033 if (!unpack_dde_message( info
.msg
.hwnd
, info
.msg
.message
, &info
.msg
.wParam
,
2034 &info
.msg
.lParam
, &buffer
, size
))
2036 ERR( "invalid packed dde-message %x (%s) hwnd %p wp %x lp %lx size %d\n",
2037 info
.msg
.message
, SPY_GetMsgName(info
.msg
.message
, info
.msg
.hwnd
),
2038 info
.msg
.hwnd
, info
.msg
.wParam
, info
.msg
.lParam
, size
);
2039 goto next
; /* ignore it */
2043 HeapFree( GetProcessHeap(), 0, buffer
);
2047 /* if we get here, we have a sent message; call the window procedure */
2048 old_info
= thread_info
->receive_info
;
2049 thread_info
->receive_info
= &info
;
2050 result
= call_window_proc( info
.msg
.hwnd
, info
.msg
.message
, info
.msg
.wParam
,
2051 info
.msg
.lParam
, (info
.type
!= MSG_ASCII
), FALSE
);
2052 reply_message( &info
, result
, TRUE
);
2053 thread_info
->receive_info
= old_info
;
2055 HeapFree( GetProcessHeap(), 0, buffer
);
2060 /***********************************************************************
2061 * process_sent_messages
2063 * Process all pending sent messages.
2065 inline static void process_sent_messages(void)
2068 peek_message( &msg
, 0, 0, 0, GET_MSG_REMOVE
| GET_MSG_SENT_ONLY
);
2072 /***********************************************************************
2073 * get_server_queue_handle
2075 * Get a handle to the server message queue for the current thread.
2077 static HANDLE
get_server_queue_handle(void)
2079 struct user_thread_info
*thread_info
= get_user_thread_info();
2082 if (!(ret
= thread_info
->server_queue
))
2084 SERVER_START_REQ( get_msg_queue
)
2086 wine_server_call( req
);
2087 ret
= reply
->handle
;
2090 thread_info
->server_queue
= ret
;
2091 if (!ret
) ERR( "Cannot get server thread queue\n" );
2097 /***********************************************************************
2098 * wait_message_reply
2100 * Wait until a sent message gets replied to.
2102 static void wait_message_reply( UINT flags
)
2104 HANDLE server_queue
= get_server_queue_handle();
2108 unsigned int wake_bits
= 0, changed_bits
= 0;
2111 SERVER_START_REQ( set_queue_mask
)
2113 req
->wake_mask
= QS_SMRESULT
| ((flags
& SMTO_BLOCK
) ? 0 : QS_SENDMESSAGE
);
2114 req
->changed_mask
= req
->wake_mask
;
2116 if (!wine_server_call( req
))
2118 wake_bits
= reply
->wake_bits
;
2119 changed_bits
= reply
->changed_bits
;
2124 if (wake_bits
& QS_SMRESULT
) return; /* got a result */
2125 if (wake_bits
& QS_SENDMESSAGE
)
2127 /* Process the sent message immediately */
2128 process_sent_messages();
2132 /* now wait for it */
2134 ReleaseThunkLock( &dwlc
);
2136 if (USER_Driver
.pMsgWaitForMultipleObjectsEx
)
2137 res
= USER_Driver
.pMsgWaitForMultipleObjectsEx( 1, &server_queue
,
2138 INFINITE
, QS_ALLINPUT
, 0 );
2140 res
= WaitForSingleObject( server_queue
, INFINITE
);
2142 if (dwlc
) RestoreThunkLock( dwlc
);
2146 /***********************************************************************
2147 * put_message_in_queue
2149 * Put a sent message into the destination queue.
2150 * For inter-process message, reply_size is set to expected size of reply data.
2152 static BOOL
put_message_in_queue( DWORD dest_tid
, const struct send_message_info
*info
,
2153 size_t *reply_size
)
2155 struct packed_message data
;
2157 int i
, timeout
= -1;
2159 if (info
->type
!= MSG_NOTIFY
&&
2160 info
->type
!= MSG_CALLBACK
&&
2161 info
->type
!= MSG_POSTED
&&
2162 info
->timeout
!= INFINITE
)
2163 timeout
= info
->timeout
;
2166 if (info
->type
== MSG_OTHER_PROCESS
)
2168 *reply_size
= pack_message( info
->hwnd
, info
->msg
, info
->wparam
, info
->lparam
, &data
);
2169 if (data
.count
== -1)
2171 WARN( "cannot pack message %x\n", info
->msg
);
2175 else if (info
->type
== MSG_POSTED
&& info
->msg
>= WM_DDE_FIRST
&& info
->msg
<= WM_DDE_LAST
)
2177 return post_dde_message( dest_tid
, &data
, info
);
2180 SERVER_START_REQ( send_message
)
2183 req
->type
= info
->type
;
2185 req
->win
= info
->hwnd
;
2186 req
->msg
= info
->msg
;
2187 req
->wparam
= info
->wparam
;
2188 req
->lparam
= info
->lparam
;
2189 req
->time
= GetCurrentTime();
2190 req
->timeout
= timeout
;
2192 if (info
->type
== MSG_CALLBACK
)
2194 req
->callback
= info
->callback
;
2195 req
->info
= info
->data
;
2198 if (info
->flags
& SMTO_ABORTIFHUNG
) req
->flags
|= SEND_MSG_ABORT_IF_HUNG
;
2199 for (i
= 0; i
< data
.count
; i
++) wine_server_add_data( req
, data
.data
[i
], data
.size
[i
] );
2200 if ((res
= wine_server_call( req
)))
2202 if (res
== STATUS_INVALID_PARAMETER
)
2203 /* FIXME: find a STATUS_ value for this one */
2204 SetLastError( ERROR_INVALID_THREAD_ID
);
2206 SetLastError( RtlNtStatusToDosError(res
) );
2214 /***********************************************************************
2217 * Retrieve a message reply from the server.
2219 static LRESULT
retrieve_reply( const struct send_message_info
*info
,
2220 size_t reply_size
, LRESULT
*result
)
2223 void *reply_data
= NULL
;
2227 if (!(reply_data
= HeapAlloc( GetProcessHeap(), 0, reply_size
)))
2229 WARN( "no memory for reply %d bytes, will be truncated\n", reply_size
);
2233 SERVER_START_REQ( get_message_reply
)
2236 if (reply_size
) wine_server_set_reply( req
, reply_data
, reply_size
);
2237 if (!(status
= wine_server_call( req
))) *result
= reply
->result
;
2238 reply_size
= wine_server_reply_size( reply
);
2241 if (!status
&& reply_size
)
2242 unpack_reply( info
->hwnd
, info
->msg
, info
->wparam
, info
->lparam
, reply_data
, reply_size
);
2244 HeapFree( GetProcessHeap(), 0, reply_data
);
2246 TRACE( "hwnd %p msg %x (%s) wp %x lp %lx got reply %lx (err=%ld)\n",
2247 info
->hwnd
, info
->msg
, SPY_GetMsgName(info
->msg
, info
->hwnd
), info
->wparam
,
2248 info
->lparam
, *result
, status
);
2250 /* MSDN states that last error is 0 on timeout, but at least NT4 returns ERROR_TIMEOUT */
2251 if (status
) SetLastError( RtlNtStatusToDosError(status
) );
2256 /***********************************************************************
2257 * send_inter_thread_message
2259 static LRESULT
send_inter_thread_message( DWORD dest_tid
, const struct send_message_info
*info
,
2262 size_t reply_size
= 0;
2264 TRACE( "hwnd %p msg %x (%s) wp %x lp %lx\n",
2265 info
->hwnd
, info
->msg
, SPY_GetMsgName(info
->msg
, info
->hwnd
), info
->wparam
, info
->lparam
);
2267 USER_CheckNotLock();
2269 if (!put_message_in_queue( dest_tid
, info
, &reply_size
)) return 0;
2271 /* there's no reply to wait for on notify/callback messages */
2272 if (info
->type
== MSG_NOTIFY
|| info
->type
== MSG_CALLBACK
) return 1;
2274 wait_message_reply( info
->flags
);
2275 return retrieve_reply( info
, reply_size
, res_ptr
);
2279 /***********************************************************************
2280 * MSG_SendInternalMessageTimeout
2282 * Same as SendMessageTimeoutW but sends the message to a specific thread
2283 * without requiring a window handle. Only works for internal Wine messages.
2285 LRESULT
MSG_SendInternalMessageTimeout( DWORD dest_pid
, DWORD dest_tid
,
2286 UINT msg
, WPARAM wparam
, LPARAM lparam
,
2287 UINT flags
, UINT timeout
, PDWORD_PTR res_ptr
)
2289 struct send_message_info info
;
2290 LRESULT ret
, result
;
2292 assert( msg
& 0x80000000 ); /* must be an internal Wine message */
2294 info
.type
= MSG_UNICODE
;
2297 info
.wparam
= wparam
;
2298 info
.lparam
= lparam
;
2300 info
.timeout
= timeout
;
2302 if (USER_IsExitingThread( dest_tid
)) return 0;
2304 if (dest_tid
== GetCurrentThreadId())
2306 result
= handle_internal_message( 0, msg
, wparam
, lparam
);
2311 if (dest_pid
!= GetCurrentProcessId()) info
.type
= MSG_OTHER_PROCESS
;
2312 ret
= send_inter_thread_message( dest_tid
, &info
, &result
);
2314 if (ret
&& res_ptr
) *res_ptr
= result
;
2319 /***********************************************************************
2320 * SendMessageTimeoutW (USER32.@)
2322 LRESULT WINAPI
SendMessageTimeoutW( HWND hwnd
, UINT msg
, WPARAM wparam
, LPARAM lparam
,
2323 UINT flags
, UINT timeout
, PDWORD_PTR res_ptr
)
2325 struct send_message_info info
;
2326 DWORD dest_tid
, dest_pid
;
2327 LRESULT ret
, result
;
2329 info
.type
= MSG_UNICODE
;
2332 info
.wparam
= wparam
;
2333 info
.lparam
= lparam
;
2335 info
.timeout
= timeout
;
2337 if (is_broadcast(hwnd
))
2339 EnumWindows( broadcast_message_callback
, (LPARAM
)&info
);
2340 if (res_ptr
) *res_ptr
= 1;
2344 if (!(dest_tid
= GetWindowThreadProcessId( hwnd
, &dest_pid
))) return 0;
2346 if (USER_IsExitingThread( dest_tid
)) return 0;
2348 SPY_EnterMessage( SPY_SENDMESSAGE
, hwnd
, msg
, wparam
, lparam
);
2350 if (dest_tid
== GetCurrentThreadId())
2352 result
= call_window_proc( hwnd
, msg
, wparam
, lparam
, TRUE
, TRUE
);
2357 if (dest_pid
!= GetCurrentProcessId()) info
.type
= MSG_OTHER_PROCESS
;
2358 ret
= send_inter_thread_message( dest_tid
, &info
, &result
);
2361 SPY_ExitMessage( SPY_RESULT_OK
, hwnd
, msg
, result
, wparam
, lparam
);
2362 if (ret
&& res_ptr
) *res_ptr
= result
;
2367 /***********************************************************************
2368 * SendMessageTimeoutA (USER32.@)
2370 LRESULT WINAPI
SendMessageTimeoutA( HWND hwnd
, UINT msg
, WPARAM wparam
, LPARAM lparam
,
2371 UINT flags
, UINT timeout
, PDWORD_PTR res_ptr
)
2373 struct send_message_info info
;
2374 DWORD dest_tid
, dest_pid
;
2375 LRESULT ret
, result
;
2377 info
.type
= MSG_ASCII
;
2380 info
.wparam
= wparam
;
2381 info
.lparam
= lparam
;
2383 info
.timeout
= timeout
;
2385 if (is_broadcast(hwnd
))
2387 EnumWindows( broadcast_message_callback
, (LPARAM
)&info
);
2388 if (res_ptr
) *res_ptr
= 1;
2392 if (!(dest_tid
= GetWindowThreadProcessId( hwnd
, &dest_pid
))) return 0;
2394 if (USER_IsExitingThread( dest_tid
)) return 0;
2396 SPY_EnterMessage( SPY_SENDMESSAGE
, hwnd
, msg
, wparam
, lparam
);
2398 if (dest_tid
== GetCurrentThreadId())
2400 result
= call_window_proc( hwnd
, msg
, wparam
, lparam
, FALSE
, TRUE
);
2403 else if (dest_pid
== GetCurrentProcessId())
2405 ret
= send_inter_thread_message( dest_tid
, &info
, &result
);
2409 /* inter-process message: need to map to Unicode */
2410 info
.type
= MSG_OTHER_PROCESS
;
2411 if (is_unicode_message( info
.msg
))
2413 if (WINPROC_MapMsg32ATo32W( info
.hwnd
, info
.msg
, &info
.wparam
, &info
.lparam
) == -1)
2415 ret
= send_inter_thread_message( dest_tid
, &info
, &result
);
2416 result
= WINPROC_UnmapMsg32ATo32W( info
.hwnd
, info
.msg
, info
.wparam
,
2417 info
.lparam
, result
);
2419 else ret
= send_inter_thread_message( dest_tid
, &info
, &result
);
2421 SPY_ExitMessage( SPY_RESULT_OK
, hwnd
, msg
, result
, wparam
, lparam
);
2422 if (ret
&& res_ptr
) *res_ptr
= result
;
2427 /***********************************************************************
2428 * SendMessageW (USER32.@)
2430 LRESULT WINAPI
SendMessageW( HWND hwnd
, UINT msg
, WPARAM wparam
, LPARAM lparam
)
2433 SendMessageTimeoutW( hwnd
, msg
, wparam
, lparam
, SMTO_NORMAL
, INFINITE
, &res
);
2438 /***********************************************************************
2439 * SendMessageA (USER32.@)
2441 LRESULT WINAPI
SendMessageA( HWND hwnd
, UINT msg
, WPARAM wparam
, LPARAM lparam
)
2444 SendMessageTimeoutA( hwnd
, msg
, wparam
, lparam
, SMTO_NORMAL
, INFINITE
, &res
);
2449 /***********************************************************************
2450 * SendNotifyMessageA (USER32.@)
2452 BOOL WINAPI
SendNotifyMessageA( HWND hwnd
, UINT msg
, WPARAM wparam
, LPARAM lparam
)
2454 return SendNotifyMessageW( hwnd
, msg
, map_wparam_AtoW( msg
, wparam
), lparam
);
2458 /***********************************************************************
2459 * SendNotifyMessageW (USER32.@)
2461 BOOL WINAPI
SendNotifyMessageW( HWND hwnd
, UINT msg
, WPARAM wparam
, LPARAM lparam
)
2463 struct send_message_info info
;
2467 if (is_pointer_message(msg
))
2469 SetLastError( ERROR_MESSAGE_SYNC_ONLY
);
2473 info
.type
= MSG_NOTIFY
;
2476 info
.wparam
= wparam
;
2477 info
.lparam
= lparam
;
2480 if (is_broadcast(hwnd
))
2482 EnumWindows( broadcast_message_callback
, (LPARAM
)&info
);
2486 if (!(dest_tid
= GetWindowThreadProcessId( hwnd
, NULL
))) return FALSE
;
2488 if (USER_IsExitingThread( dest_tid
)) return TRUE
;
2490 if (dest_tid
== GetCurrentThreadId())
2492 call_window_proc( hwnd
, msg
, wparam
, lparam
, TRUE
, TRUE
);
2495 return send_inter_thread_message( dest_tid
, &info
, &result
);
2499 /***********************************************************************
2500 * SendMessageCallbackA (USER32.@)
2502 BOOL WINAPI
SendMessageCallbackA( HWND hwnd
, UINT msg
, WPARAM wparam
, LPARAM lparam
,
2503 SENDASYNCPROC callback
, ULONG_PTR data
)
2505 return SendMessageCallbackW( hwnd
, msg
, map_wparam_AtoW( msg
, wparam
),
2506 lparam
, callback
, data
);
2510 /***********************************************************************
2511 * SendMessageCallbackW (USER32.@)
2513 BOOL WINAPI
SendMessageCallbackW( HWND hwnd
, UINT msg
, WPARAM wparam
, LPARAM lparam
,
2514 SENDASYNCPROC callback
, ULONG_PTR data
)
2516 struct send_message_info info
;
2520 if (is_pointer_message(msg
))
2522 SetLastError( ERROR_MESSAGE_SYNC_ONLY
);
2526 info
.type
= MSG_CALLBACK
;
2529 info
.wparam
= wparam
;
2530 info
.lparam
= lparam
;
2531 info
.callback
= callback
;
2535 if (is_broadcast(hwnd
))
2537 EnumWindows( broadcast_message_callback
, (LPARAM
)&info
);
2541 if (!(dest_tid
= GetWindowThreadProcessId( hwnd
, NULL
))) return FALSE
;
2543 if (USER_IsExitingThread( dest_tid
)) return TRUE
;
2545 if (dest_tid
== GetCurrentThreadId())
2547 result
= call_window_proc( hwnd
, msg
, wparam
, lparam
, TRUE
, TRUE
);
2548 call_sendmsg_callback( callback
, hwnd
, msg
, data
, result
);
2551 FIXME( "callback will not be called\n" );
2552 return send_inter_thread_message( dest_tid
, &info
, &result
);
2556 /***********************************************************************
2557 * ReplyMessage (USER32.@)
2559 BOOL WINAPI
ReplyMessage( LRESULT result
)
2561 struct received_message_info
*info
= get_user_thread_info()->receive_info
;
2563 if (!info
) return FALSE
;
2564 reply_message( info
, result
, FALSE
);
2569 /***********************************************************************
2570 * InSendMessage (USER32.@)
2572 BOOL WINAPI
InSendMessage(void)
2574 return (InSendMessageEx(NULL
) & (ISMEX_SEND
|ISMEX_REPLIED
)) == ISMEX_SEND
;
2578 /***********************************************************************
2579 * InSendMessageEx (USER32.@)
2581 DWORD WINAPI
InSendMessageEx( LPVOID reserved
)
2583 struct received_message_info
*info
= get_user_thread_info()->receive_info
;
2585 if (info
) return info
->flags
;
2586 return ISMEX_NOSEND
;
2590 /***********************************************************************
2591 * PostMessageA (USER32.@)
2593 BOOL WINAPI
PostMessageA( HWND hwnd
, UINT msg
, WPARAM wparam
, LPARAM lparam
)
2595 return PostMessageW( hwnd
, msg
, map_wparam_AtoW( msg
, wparam
), lparam
);
2599 /***********************************************************************
2600 * PostMessageW (USER32.@)
2602 BOOL WINAPI
PostMessageW( HWND hwnd
, UINT msg
, WPARAM wparam
, LPARAM lparam
)
2604 struct send_message_info info
;
2607 if (is_pointer_message( msg
))
2609 SetLastError( ERROR_MESSAGE_SYNC_ONLY
);
2613 TRACE( "hwnd %p msg %x (%s) wp %x lp %lx\n",
2614 hwnd
, msg
, SPY_GetMsgName(msg
, hwnd
), wparam
, lparam
);
2616 info
.type
= MSG_POSTED
;
2619 info
.wparam
= wparam
;
2620 info
.lparam
= lparam
;
2623 if (is_broadcast(hwnd
))
2625 EnumWindows( broadcast_message_callback
, (LPARAM
)&info
);
2629 if (!hwnd
) return PostThreadMessageW( GetCurrentThreadId(), msg
, wparam
, lparam
);
2631 if (!(dest_tid
= GetWindowThreadProcessId( hwnd
, NULL
))) return FALSE
;
2633 if (USER_IsExitingThread( dest_tid
)) return TRUE
;
2635 return put_message_in_queue( dest_tid
, &info
, NULL
);
2639 /**********************************************************************
2640 * PostThreadMessageA (USER32.@)
2642 BOOL WINAPI
PostThreadMessageA( DWORD thread
, UINT msg
, WPARAM wparam
, LPARAM lparam
)
2644 return PostThreadMessageW( thread
, msg
, map_wparam_AtoW( msg
, wparam
), lparam
);
2648 /**********************************************************************
2649 * PostThreadMessageW (USER32.@)
2651 BOOL WINAPI
PostThreadMessageW( DWORD thread
, UINT msg
, WPARAM wparam
, LPARAM lparam
)
2653 struct send_message_info info
;
2655 if (is_pointer_message( msg
))
2657 SetLastError( ERROR_MESSAGE_SYNC_ONLY
);
2660 if (USER_IsExitingThread( thread
)) return TRUE
;
2662 info
.type
= MSG_POSTED
;
2665 info
.wparam
= wparam
;
2666 info
.lparam
= lparam
;
2668 return put_message_in_queue( thread
, &info
, NULL
);
2672 /***********************************************************************
2673 * PostQuitMessage (USER32.@)
2675 void WINAPI
PostQuitMessage( INT exitCode
)
2677 PostThreadMessageW( GetCurrentThreadId(), WM_QUIT
, exitCode
, 0 );
2681 /***********************************************************************
2682 * PeekMessageW (USER32.@)
2684 BOOL WINAPI
PeekMessageW( MSG
*msg_out
, HWND hwnd
, UINT first
, UINT last
, UINT flags
)
2686 struct user_thread_info
*thread_info
= get_user_thread_info();
2689 USER_CheckNotLock();
2691 /* check for graphics events */
2692 if (USER_Driver
.pMsgWaitForMultipleObjectsEx
)
2693 USER_Driver
.pMsgWaitForMultipleObjectsEx( 0, NULL
, 0, QS_ALLINPUT
, 0 );
2695 hwnd
= WIN_GetFullHandle( hwnd
);
2699 if (!peek_message( &msg
, hwnd
, first
, last
, (flags
& PM_REMOVE
) ? GET_MSG_REMOVE
: 0 ))
2701 if (!(flags
& PM_NOYIELD
))
2704 ReleaseThunkLock(&count
);
2706 if (count
) RestoreThunkLock(count
);
2710 if (msg
.message
& 0x80000000)
2712 handle_internal_message( msg
.hwnd
, msg
.message
, msg
.wParam
, msg
.lParam
);
2713 if (!(flags
& PM_REMOVE
)) /* have to remove it explicitly */
2714 peek_message( &msg
, msg
.hwnd
, msg
.message
, msg
.message
, GET_MSG_REMOVE
);
2719 thread_info
->GetMessageTimeVal
= msg
.time
;
2720 msg
.pt
.x
= LOWORD( thread_info
->GetMessagePosVal
);
2721 msg
.pt
.y
= HIWORD( thread_info
->GetMessagePosVal
);
2723 HOOK_CallHooks( WH_GETMESSAGE
, HC_ACTION
, flags
& PM_REMOVE
, (LPARAM
)&msg
, TRUE
);
2725 /* copy back our internal safe copy of message data to msg_out.
2726 * msg_out is a variable from the *program*, so it can't be used
2727 * internally as it can get "corrupted" by our use of SendMessage()
2728 * (back to the program) inside the message handling itself. */
2731 SetLastError( ERROR_NOACCESS
);
2739 /***********************************************************************
2740 * PeekMessageA (USER32.@)
2742 BOOL WINAPI
PeekMessageA( MSG
*msg
, HWND hwnd
, UINT first
, UINT last
, UINT flags
)
2744 BOOL ret
= PeekMessageW( msg
, hwnd
, first
, last
, flags
);
2745 if (ret
) msg
->wParam
= map_wparam_WtoA( msg
->message
, msg
->wParam
);
2750 /***********************************************************************
2751 * GetMessageW (USER32.@)
2753 BOOL WINAPI
GetMessageW( MSG
*msg
, HWND hwnd
, UINT first
, UINT last
)
2755 HANDLE server_queue
= get_server_queue_handle();
2756 int mask
= QS_POSTMESSAGE
| QS_SENDMESSAGE
; /* Always selected */
2760 if ((first
<= WM_KEYLAST
) && (last
>= WM_KEYFIRST
)) mask
|= QS_KEY
;
2761 if ( ((first
<= WM_MOUSELAST
) && (last
>= WM_MOUSEFIRST
)) ||
2762 ((first
<= WM_NCMOUSELAST
) && (last
>= WM_NCMOUSEFIRST
)) ) mask
|= QS_MOUSE
;
2763 if ((first
<= WM_TIMER
) && (last
>= WM_TIMER
)) mask
|= QS_TIMER
;
2764 if ((first
<= WM_SYSTIMER
) && (last
>= WM_SYSTIMER
)) mask
|= QS_TIMER
;
2765 if ((first
<= WM_PAINT
) && (last
>= WM_PAINT
)) mask
|= QS_PAINT
;
2767 else mask
|= QS_MOUSE
| QS_KEY
| QS_TIMER
| QS_PAINT
;
2769 while (!PeekMessageW( msg
, hwnd
, first
, last
, PM_REMOVE
))
2771 /* wait until one of the bits is set */
2772 unsigned int wake_bits
= 0, changed_bits
= 0;
2775 SERVER_START_REQ( set_queue_mask
)
2777 req
->wake_mask
= QS_SENDMESSAGE
;
2778 req
->changed_mask
= mask
;
2780 if (!wine_server_call( req
))
2782 wake_bits
= reply
->wake_bits
;
2783 changed_bits
= reply
->changed_bits
;
2788 if (changed_bits
& mask
) continue;
2789 if (wake_bits
& QS_SENDMESSAGE
) continue;
2791 TRACE( "(%04lx) mask=%08x, bits=%08x, changed=%08x, waiting\n",
2792 GetCurrentThreadId(), mask
, wake_bits
, changed_bits
);
2794 ReleaseThunkLock( &dwlc
);
2795 if (USER_Driver
.pMsgWaitForMultipleObjectsEx
)
2796 USER_Driver
.pMsgWaitForMultipleObjectsEx( 1, &server_queue
, INFINITE
,
2799 WaitForSingleObject( server_queue
, INFINITE
);
2800 if (dwlc
) RestoreThunkLock( dwlc
);
2803 return (msg
->message
!= WM_QUIT
);
2807 /***********************************************************************
2808 * GetMessageA (USER32.@)
2810 BOOL WINAPI
GetMessageA( MSG
*msg
, HWND hwnd
, UINT first
, UINT last
)
2812 GetMessageW( msg
, hwnd
, first
, last
);
2813 msg
->wParam
= map_wparam_WtoA( msg
->message
, msg
->wParam
);
2814 return (msg
->message
!= WM_QUIT
);
2818 /***********************************************************************
2819 * IsDialogMessage (USER32.@)
2820 * IsDialogMessageA (USER32.@)
2822 BOOL WINAPI
IsDialogMessageA( HWND hwndDlg
, LPMSG pmsg
)
2825 msg
.wParam
= map_wparam_AtoW( msg
.message
, msg
.wParam
);
2826 return IsDialogMessageW( hwndDlg
, &msg
);
2830 /***********************************************************************
2831 * TranslateMessage (USER32.@)
2833 * Implementation of TranslateMessage.
2835 * TranslateMessage translates virtual-key messages into character-messages,
2837 * WM_KEYDOWN/WM_KEYUP combinations produce a WM_CHAR or WM_DEADCHAR message.
2838 * ditto replacing WM_* with WM_SYS*
2839 * This produces WM_CHAR messages only for keys mapped to ASCII characters
2840 * by the keyboard driver.
2842 * If the message is WM_KEYDOWN, WM_KEYUP, WM_SYSKEYDOWN, or WM_SYSKEYUP, the
2843 * return value is nonzero, regardless of the translation.
2846 BOOL WINAPI
TranslateMessage( const MSG
*msg
)
2852 if (msg
->message
< WM_KEYFIRST
|| msg
->message
> WM_KEYLAST
) return FALSE
;
2853 if (msg
->message
!= WM_KEYDOWN
&& msg
->message
!= WM_SYSKEYDOWN
) return TRUE
;
2855 TRACE_(key
)("Translating key %s (%04x), scancode %02x\n",
2856 SPY_GetVKeyName(msg
->wParam
), msg
->wParam
, LOBYTE(HIWORD(msg
->lParam
)));
2858 GetKeyboardState( state
);
2859 /* FIXME : should handle ToUnicode yielding 2 */
2860 switch (ToUnicode(msg
->wParam
, HIWORD(msg
->lParam
), state
, wp
, 2, 0))
2863 message
= (msg
->message
== WM_KEYDOWN
) ? WM_CHAR
: WM_SYSCHAR
;
2864 TRACE_(key
)("1 -> PostMessageW(%p,%s,%04x,%08lx)\n",
2865 msg
->hwnd
, SPY_GetMsgName(message
, msg
->hwnd
), wp
[0], msg
->lParam
);
2866 PostMessageW( msg
->hwnd
, message
, wp
[0], msg
->lParam
);
2870 message
= (msg
->message
== WM_KEYDOWN
) ? WM_DEADCHAR
: WM_SYSDEADCHAR
;
2871 TRACE_(key
)("-1 -> PostMessageW(%p,%s,%04x,%08lx)\n",
2872 msg
->hwnd
, SPY_GetMsgName(message
, msg
->hwnd
), wp
[0], msg
->lParam
);
2873 PostMessageW( msg
->hwnd
, message
, wp
[0], msg
->lParam
);
2880 /***********************************************************************
2881 * DispatchMessageA (USER32.@)
2883 LONG WINAPI
DispatchMessageA( const MSG
* msg
)
2889 /* Process timer messages */
2890 if ((msg
->message
== WM_TIMER
) || (msg
->message
== WM_SYSTIMER
))
2892 if (msg
->lParam
) return CallWindowProcA( (WNDPROC
)msg
->lParam
, msg
->hwnd
,
2893 msg
->message
, msg
->wParam
, GetTickCount() );
2896 if (!(wndPtr
= WIN_GetPtr( msg
->hwnd
)))
2898 if (msg
->hwnd
) SetLastError( ERROR_INVALID_WINDOW_HANDLE
);
2901 if (wndPtr
== WND_OTHER_PROCESS
|| wndPtr
== WND_DESKTOP
)
2903 if (IsWindow( msg
->hwnd
)) SetLastError( ERROR_MESSAGE_SYNC_ONLY
);
2904 else SetLastError( ERROR_INVALID_WINDOW_HANDLE
);
2907 if (wndPtr
->tid
!= GetCurrentThreadId())
2909 SetLastError( ERROR_MESSAGE_SYNC_ONLY
);
2910 WIN_ReleasePtr( wndPtr
);
2913 winproc
= wndPtr
->winproc
;
2914 WIN_ReleasePtr( wndPtr
);
2916 SPY_EnterMessage( SPY_DISPATCHMESSAGE
, msg
->hwnd
, msg
->message
,
2917 msg
->wParam
, msg
->lParam
);
2918 retval
= CallWindowProcA( winproc
, msg
->hwnd
, msg
->message
,
2919 msg
->wParam
, msg
->lParam
);
2920 SPY_ExitMessage( SPY_RESULT_OK
, msg
->hwnd
, msg
->message
, retval
,
2921 msg
->wParam
, msg
->lParam
);
2923 if (msg
->message
== WM_PAINT
)
2925 /* send a WM_NCPAINT and WM_ERASEBKGND if the non-client area is still invalid */
2926 HRGN hrgn
= CreateRectRgn( 0, 0, 0, 0 );
2927 GetUpdateRgn( msg
->hwnd
, hrgn
, TRUE
);
2928 DeleteObject( hrgn
);
2934 /***********************************************************************
2935 * DispatchMessageW (USER32.@) Process a message
2937 * Process the message specified in the structure *_msg_.
2939 * If the lpMsg parameter points to a WM_TIMER message and the
2940 * parameter of the WM_TIMER message is not NULL, the lParam parameter
2941 * points to the function that is called instead of the window
2944 * The message must be valid.
2948 * DispatchMessage() returns the result of the window procedure invoked.
2955 LONG WINAPI
DispatchMessageW( const MSG
* msg
)
2961 /* Process timer messages */
2962 if ((msg
->message
== WM_TIMER
) || (msg
->message
== WM_SYSTIMER
))
2964 if (msg
->lParam
) return CallWindowProcW( (WNDPROC
)msg
->lParam
, msg
->hwnd
,
2965 msg
->message
, msg
->wParam
, GetTickCount() );
2968 if (!(wndPtr
= WIN_GetPtr( msg
->hwnd
)))
2970 if (msg
->hwnd
) SetLastError( ERROR_INVALID_WINDOW_HANDLE
);
2973 if (wndPtr
== WND_OTHER_PROCESS
|| wndPtr
== WND_DESKTOP
)
2975 if (IsWindow( msg
->hwnd
)) SetLastError( ERROR_MESSAGE_SYNC_ONLY
);
2976 else SetLastError( ERROR_INVALID_WINDOW_HANDLE
);
2979 if (wndPtr
->tid
!= GetCurrentThreadId())
2981 SetLastError( ERROR_MESSAGE_SYNC_ONLY
);
2982 WIN_ReleasePtr( wndPtr
);
2985 winproc
= wndPtr
->winproc
;
2986 WIN_ReleasePtr( wndPtr
);
2988 SPY_EnterMessage( SPY_DISPATCHMESSAGE
, msg
->hwnd
, msg
->message
,
2989 msg
->wParam
, msg
->lParam
);
2990 retval
= CallWindowProcW( winproc
, msg
->hwnd
, msg
->message
,
2991 msg
->wParam
, msg
->lParam
);
2992 SPY_ExitMessage( SPY_RESULT_OK
, msg
->hwnd
, msg
->message
, retval
,
2993 msg
->wParam
, msg
->lParam
);
2995 if (msg
->message
== WM_PAINT
)
2997 /* send a WM_NCPAINT and WM_ERASEBKGND if the non-client area is still invalid */
2998 HRGN hrgn
= CreateRectRgn( 0, 0, 0, 0 );
2999 GetUpdateRgn( msg
->hwnd
, hrgn
, TRUE
);
3000 DeleteObject( hrgn
);
3006 /***********************************************************************
3007 * GetMessagePos (USER.119)
3008 * GetMessagePos (USER32.@)
3010 * The GetMessagePos() function returns a long value representing a
3011 * cursor position, in screen coordinates, when the last message
3012 * retrieved by the GetMessage() function occurs. The x-coordinate is
3013 * in the low-order word of the return value, the y-coordinate is in
3014 * the high-order word. The application can use the MAKEPOINT()
3015 * macro to obtain a POINT structure from the return value.
3017 * For the current cursor position, use GetCursorPos().
3021 * Cursor position of last message on success, zero on failure.
3028 DWORD WINAPI
GetMessagePos(void)
3030 return get_user_thread_info()->GetMessagePosVal
;
3034 /***********************************************************************
3035 * GetMessageTime (USER.120)
3036 * GetMessageTime (USER32.@)
3038 * GetMessageTime() returns the message time for the last message
3039 * retrieved by the function. The time is measured in milliseconds with
3040 * the same offset as GetTickCount().
3042 * Since the tick count wraps, this is only useful for moderately short
3043 * relative time comparisons.
3047 * Time of last message on success, zero on failure.
3049 LONG WINAPI
GetMessageTime(void)
3051 return get_user_thread_info()->GetMessageTimeVal
;
3055 /***********************************************************************
3056 * GetMessageExtraInfo (USER.288)
3057 * GetMessageExtraInfo (USER32.@)
3059 LPARAM WINAPI
GetMessageExtraInfo(void)
3061 return get_user_thread_info()->GetMessageExtraInfoVal
;
3065 /***********************************************************************
3066 * SetMessageExtraInfo (USER32.@)
3068 LPARAM WINAPI
SetMessageExtraInfo(LPARAM lParam
)
3070 struct user_thread_info
*thread_info
= get_user_thread_info();
3071 LONG old_value
= thread_info
->GetMessageExtraInfoVal
;
3072 thread_info
->GetMessageExtraInfoVal
= lParam
;
3077 /***********************************************************************
3078 * WaitMessage (USER.112) Suspend thread pending messages
3079 * WaitMessage (USER32.@) Suspend thread pending messages
3081 * WaitMessage() suspends a thread until events appear in the thread's
3084 BOOL WINAPI
WaitMessage(void)
3086 return (MsgWaitForMultipleObjectsEx( 0, NULL
, INFINITE
, QS_ALLINPUT
, 0 ) != WAIT_FAILED
);
3090 /***********************************************************************
3091 * MsgWaitForMultipleObjectsEx (USER32.@)
3093 DWORD WINAPI
MsgWaitForMultipleObjectsEx( DWORD count
, CONST HANDLE
*pHandles
,
3094 DWORD timeout
, DWORD mask
, DWORD flags
)
3096 HANDLE handles
[MAXIMUM_WAIT_OBJECTS
];
3099 if (count
> MAXIMUM_WAIT_OBJECTS
-1)
3101 SetLastError( ERROR_INVALID_PARAMETER
);
3105 /* set the queue mask */
3106 SERVER_START_REQ( set_queue_mask
)
3108 req
->wake_mask
= (flags
& MWMO_INPUTAVAILABLE
) ? mask
: 0;
3109 req
->changed_mask
= mask
;
3111 wine_server_call( req
);
3115 /* Add the thread event to the handle list */
3116 for (i
= 0; i
< count
; i
++) handles
[i
] = pHandles
[i
];
3117 handles
[count
] = get_server_queue_handle();
3119 ReleaseThunkLock( &lock
);
3120 if (USER_Driver
.pMsgWaitForMultipleObjectsEx
)
3122 ret
= USER_Driver
.pMsgWaitForMultipleObjectsEx( count
+1, handles
, timeout
, mask
, flags
);
3123 if (ret
== count
+1) ret
= count
; /* pretend the msg queue is ready */
3126 ret
= WaitForMultipleObjectsEx( count
+1, handles
, flags
& MWMO_WAITALL
,
3127 timeout
, flags
& MWMO_ALERTABLE
);
3128 if (lock
) RestoreThunkLock( lock
);
3133 /***********************************************************************
3134 * MsgWaitForMultipleObjects (USER32.@)
3136 DWORD WINAPI
MsgWaitForMultipleObjects( DWORD count
, CONST HANDLE
*handles
,
3137 BOOL wait_all
, DWORD timeout
, DWORD mask
)
3139 return MsgWaitForMultipleObjectsEx( count
, handles
, timeout
, mask
,
3140 wait_all
? MWMO_WAITALL
: 0 );
3144 /***********************************************************************
3145 * WaitForInputIdle (USER32.@)
3147 DWORD WINAPI
WaitForInputIdle( HANDLE hProcess
, DWORD dwTimeOut
)
3149 DWORD start_time
, elapsed
, ret
;
3150 HANDLE idle_event
= (HANDLE
)-1;
3152 SERVER_START_REQ( wait_input_idle
)
3154 req
->handle
= hProcess
;
3155 req
->timeout
= dwTimeOut
;
3156 if (!(ret
= wine_server_call_err( req
))) idle_event
= reply
->event
;
3159 if (ret
) return WAIT_FAILED
; /* error */
3160 if (!idle_event
) return 0; /* no event to wait on */
3162 start_time
= GetTickCount();
3165 TRACE("waiting for %p\n", idle_event
);
3168 ret
= MsgWaitForMultipleObjects ( 1, &idle_event
, FALSE
, dwTimeOut
- elapsed
, QS_SENDMESSAGE
);
3171 case WAIT_OBJECT_0
+1:
3172 process_sent_messages();
3176 TRACE("timeout or error\n");
3179 TRACE("finished\n");
3182 if (dwTimeOut
!= INFINITE
)
3184 elapsed
= GetTickCount() - start_time
;
3185 if (elapsed
> dwTimeOut
)
3191 return WAIT_TIMEOUT
;
3195 /***********************************************************************
3196 * UserYield (USER.332)
3198 void WINAPI
UserYield16(void)
3202 /* Handle sent messages */
3203 process_sent_messages();
3206 ReleaseThunkLock(&count
);
3210 RestoreThunkLock(count
);
3211 /* Handle sent messages again */
3212 process_sent_messages();
3217 /***********************************************************************
3218 * RegisterWindowMessage (USER.118)
3219 * RegisterWindowMessageA (USER32.@)
3221 WORD WINAPI
RegisterWindowMessageA( LPCSTR str
)
3223 TRACE("%s\n", str
);
3224 return GlobalAddAtomA( str
);
3228 /***********************************************************************
3229 * RegisterWindowMessageW (USER32.@)
3231 WORD WINAPI
RegisterWindowMessageW( LPCWSTR str
)
3233 TRACE("%p\n", str
);
3234 return GlobalAddAtomW( str
);
3238 /***********************************************************************
3239 * BroadcastSystemMessage (USER32.@)
3240 * BroadcastSystemMessageA (USER32.@)
3242 LONG WINAPI
BroadcastSystemMessageA( DWORD flags
, LPDWORD recipients
, UINT msg
, WPARAM wp
, LPARAM lp
)
3244 if ((*recipients
& BSM_APPLICATIONS
) || (*recipients
== BSM_ALLCOMPONENTS
))
3246 FIXME( "(%08lx,%08lx,%08x,%08x,%08lx): semi-stub!\n", flags
, *recipients
, msg
, wp
, lp
);
3247 PostMessageA( HWND_BROADCAST
, msg
, wp
, lp
);
3252 FIXME( "(%08lx,%08lx,%08x,%08x,%08lx): stub!\n", flags
, *recipients
, msg
, wp
, lp
);
3258 /***********************************************************************
3259 * BroadcastSystemMessageW (USER32.@)
3261 LONG WINAPI
BroadcastSystemMessageW( DWORD flags
, LPDWORD recipients
, UINT msg
, WPARAM wp
, LPARAM lp
)
3263 if ((*recipients
& BSM_APPLICATIONS
) || (*recipients
== BSM_ALLCOMPONENTS
))
3265 FIXME( "(%08lx,%08lx,%08x,%08x,%08lx): semi-stub!\n", flags
, *recipients
, msg
, wp
, lp
);
3266 PostMessageW( HWND_BROADCAST
, msg
, wp
, lp
);
3271 FIXME( "(%08lx,%08lx,%08x,%08x,%08lx): stub!\n", flags
, *recipients
, msg
, wp
, lp
);
3277 /***********************************************************************
3278 * SetMessageQueue (USER32.@)
3280 BOOL WINAPI
SetMessageQueue( INT size
)
3282 /* now obsolete the message queue will be expanded dynamically as necessary */
3287 /***********************************************************************
3288 * MessageBeep (USER32.@)
3290 BOOL WINAPI
MessageBeep( UINT i
)
3293 SystemParametersInfoA( SPI_GETBEEP
, 0, &active
, FALSE
);
3294 if (active
&& USER_Driver
.pBeep
) USER_Driver
.pBeep();
3299 /***********************************************************************
3300 * SetTimer (USER32.@)
3302 UINT_PTR WINAPI
SetTimer( HWND hwnd
, UINT_PTR id
, UINT timeout
, TIMERPROC proc
)
3305 WNDPROC winproc
= 0;
3307 if (proc
) winproc
= WINPROC_AllocProc( (WNDPROC
)proc
, WIN_PROC_32A
);
3309 SERVER_START_REQ( set_win_timer
)
3312 req
->msg
= WM_TIMER
;
3314 req
->rate
= max( timeout
, SYS_TIMER_RATE
);
3315 req
->lparam
= (unsigned int)winproc
;
3316 if (!wine_server_call_err( req
))
3319 if (!ret
) ret
= TRUE
;
3325 TRACE("Added %p %x %p timeout %d\n", hwnd
, id
, winproc
, timeout
);
3330 /***********************************************************************
3331 * SetSystemTimer (USER32.@)
3333 UINT_PTR WINAPI
SetSystemTimer( HWND hwnd
, UINT_PTR id
, UINT timeout
, TIMERPROC proc
)
3336 WNDPROC winproc
= 0;
3338 if (proc
) winproc
= WINPROC_AllocProc( (WNDPROC
)proc
, WIN_PROC_32A
);
3340 SERVER_START_REQ( set_win_timer
)
3343 req
->msg
= WM_SYSTIMER
;
3345 req
->rate
= max( timeout
, SYS_TIMER_RATE
);
3346 req
->lparam
= (unsigned int)winproc
;
3347 if (!wine_server_call_err( req
))
3350 if (!ret
) ret
= TRUE
;
3356 TRACE("Added %p %x %p timeout %d\n", hwnd
, id
, winproc
, timeout
);
3361 /***********************************************************************
3362 * KillTimer (USER32.@)
3364 BOOL WINAPI
KillTimer( HWND hwnd
, UINT_PTR id
)
3368 TRACE("%p %d\n", hwnd
, id
);
3370 SERVER_START_REQ( kill_win_timer
)
3373 req
->msg
= WM_TIMER
;
3375 ret
= !wine_server_call_err( req
);
3382 /***********************************************************************
3383 * KillSystemTimer (USER32.@)
3385 BOOL WINAPI
KillSystemTimer( HWND hwnd
, UINT_PTR id
)
3389 TRACE("%p %d\n", hwnd
, id
);
3391 SERVER_START_REQ( kill_win_timer
)
3394 req
->msg
= WM_SYSTIMER
;
3396 ret
= !wine_server_call_err( req
);
3403 /**********************************************************************
3404 * GetGUIThreadInfo (USER32.@)
3406 BOOL WINAPI
GetGUIThreadInfo( DWORD id
, GUITHREADINFO
*info
)
3410 SERVER_START_REQ( get_thread_input
)
3413 if ((ret
= !wine_server_call_err( req
)))
3416 info
->hwndActive
= reply
->active
;
3417 info
->hwndFocus
= reply
->focus
;
3418 info
->hwndCapture
= reply
->capture
;
3419 info
->hwndMenuOwner
= reply
->menu_owner
;
3420 info
->hwndMoveSize
= reply
->move_size
;
3421 info
->hwndCaret
= reply
->caret
;
3422 info
->rcCaret
.left
= reply
->rect
.left
;
3423 info
->rcCaret
.top
= reply
->rect
.top
;
3424 info
->rcCaret
.right
= reply
->rect
.right
;
3425 info
->rcCaret
.bottom
= reply
->rect
.bottom
;
3426 if (reply
->menu_owner
) info
->flags
|= GUI_INMENUMODE
;
3427 if (reply
->move_size
) info
->flags
|= GUI_INMOVESIZE
;
3428 if (reply
->caret
) info
->flags
|= GUI_CARETBLINKING
;
3436 /******************************************************************
3437 * IsHungAppWindow (USER32.@)
3440 BOOL WINAPI
IsHungAppWindow( HWND hWnd
)
3443 return !SendMessageTimeoutA(hWnd
, WM_NULL
, 0, 0, SMTO_ABORTIFHUNG
, 5000, &dwResult
);