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"
28 #define WIN32_NO_STATUS
36 #include "wine/unicode.h"
37 #include "wine/server.h"
38 #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
;
83 UINT flags
; /* flags for SendMessageTimeout */
84 UINT timeout
; /* timeout for SendMessageTimeout */
85 SENDASYNCPROC callback
; /* callback function for SendMessageCallback */
86 ULONG_PTR data
; /* callback data */
90 /* flag for messages that contain pointers */
91 /* 32 messages per entry, messages 0..31 map to bits 0..31 */
93 #define SET(msg) (1 << ((msg) & 31))
95 static const unsigned int message_pointer_flags
[] =
98 SET(WM_CREATE
) | SET(WM_SETTEXT
) | SET(WM_GETTEXT
) |
99 SET(WM_WININICHANGE
) | SET(WM_DEVMODECHANGE
),
101 SET(WM_GETMINMAXINFO
) | SET(WM_DRAWITEM
) | SET(WM_MEASUREITEM
) | SET(WM_DELETEITEM
) |
104 SET(WM_WINDOWPOSCHANGING
) | SET(WM_WINDOWPOSCHANGED
) | SET(WM_COPYDATA
) |
105 SET(WM_NOTIFY
) | SET(WM_HELP
),
107 SET(WM_STYLECHANGING
) | SET(WM_STYLECHANGED
),
109 SET(WM_NCCREATE
) | SET(WM_NCCALCSIZE
) | SET(WM_GETDLGCODE
),
111 SET(EM_GETSEL
) | SET(EM_GETRECT
) | SET(EM_SETRECT
) | SET(EM_SETRECTNP
),
113 SET(EM_REPLACESEL
) | SET(EM_GETLINE
) | SET(EM_SETTABSTOPS
),
115 SET(SBM_GETRANGE
) | SET(SBM_SETSCROLLINFO
) | SET(SBM_GETSCROLLINFO
) | SET(SBM_GETSCROLLBARINFO
),
121 SET(CB_GETEDITSEL
) | SET(CB_ADDSTRING
) | SET(CB_DIR
) | SET(CB_GETLBTEXT
) |
122 SET(CB_INSERTSTRING
) | SET(CB_FINDSTRING
) | SET(CB_SELECTSTRING
) |
123 SET(CB_GETDROPPEDCONTROLRECT
) | SET(CB_FINDSTRINGEXACT
),
127 SET(LB_ADDSTRING
) | SET(LB_INSERTSTRING
) | SET(LB_GETTEXT
) | SET(LB_SELECTSTRING
) |
128 SET(LB_DIR
) | SET(LB_FINDSTRING
) |
129 SET(LB_GETSELITEMS
) | SET(LB_SETTABSTOPS
) | SET(LB_ADDFILE
) | SET(LB_GETITEMRECT
),
131 SET(LB_FINDSTRINGEXACT
),
137 SET(WM_NEXTMENU
) | SET(WM_SIZING
) | SET(WM_MOVING
) | SET(WM_DEVICECHANGE
),
139 SET(WM_MDICREATE
) | SET(WM_MDIGETACTIVE
) | SET(WM_DROPOBJECT
) |
140 SET(WM_QUERYDROPOBJECT
) | SET(WM_DRAGLOOP
) | SET(WM_DRAGSELECT
) | SET(WM_DRAGMOVE
),
154 SET(WM_ASKCBFORMATNAME
)
157 /* flags for messages that contain Unicode strings */
158 static const unsigned int message_unicode_flags
[] =
161 SET(WM_CREATE
) | SET(WM_SETTEXT
) | SET(WM_GETTEXT
) | SET(WM_GETTEXTLENGTH
) |
162 SET(WM_WININICHANGE
) | SET(WM_DEVMODECHANGE
),
174 SET(EM_REPLACESEL
) | SET(EM_GETLINE
) | SET(EM_SETPASSWORDCHAR
),
178 SET(WM_CHAR
) | SET(WM_DEADCHAR
) | SET(WM_SYSCHAR
) | SET(WM_SYSDEADCHAR
),
182 SET(CB_ADDSTRING
) | SET(CB_DIR
) | SET(CB_GETLBTEXT
) | SET(CB_GETLBTEXTLEN
) |
183 SET(CB_INSERTSTRING
) | SET(CB_FINDSTRING
) | SET(CB_SELECTSTRING
) | SET(CB_FINDSTRINGEXACT
),
187 SET(LB_ADDSTRING
) | SET(LB_INSERTSTRING
) | SET(LB_GETTEXT
) | SET(LB_GETTEXTLEN
) |
188 SET(LB_SELECTSTRING
) | SET(LB_DIR
) | SET(LB_FINDSTRING
) | SET(LB_ADDFILE
),
190 SET(LB_FINDSTRINGEXACT
),
212 SET(WM_PAINTCLIPBOARD
) | SET(WM_SIZECLIPBOARD
) | SET(WM_ASKCBFORMATNAME
)
215 /* check whether a given message type includes pointers */
216 inline static int is_pointer_message( UINT message
)
218 if (message
>= 8*sizeof(message_pointer_flags
)) return FALSE
;
219 return (message_pointer_flags
[message
/ 32] & SET(message
)) != 0;
222 /* check whether a given message type contains Unicode (or ASCII) chars */
223 inline static int is_unicode_message( UINT message
)
225 if (message
>= 8*sizeof(message_unicode_flags
)) return FALSE
;
226 return (message_unicode_flags
[message
/ 32] & SET(message
)) != 0;
231 /* add a data field to a packed message */
232 inline static void push_data( struct packed_message
*data
, const void *ptr
, size_t size
)
234 data
->data
[data
->count
] = ptr
;
235 data
->size
[data
->count
] = size
;
239 /* add a string to a packed message */
240 inline static void push_string( struct packed_message
*data
, LPCWSTR str
)
242 push_data( data
, str
, (strlenW(str
) + 1) * sizeof(WCHAR
) );
245 /* retrieve a pointer to data from a packed message and increment the buffer pointer */
246 inline static void *get_data( void **buffer
, size_t size
)
249 *buffer
= (char *)*buffer
+ size
;
253 /* make sure that the buffer contains a valid null-terminated Unicode string */
254 inline static BOOL
check_string( LPCWSTR str
, size_t size
)
256 for (size
/= sizeof(WCHAR
); size
; size
--, str
++)
257 if (!*str
) return TRUE
;
261 /* make sure that there is space for 'size' bytes in buffer, growing it if needed */
262 inline static void *get_buffer_space( void **buffer
, size_t size
)
268 if (!(ret
= HeapReAlloc( GetProcessHeap(), 0, *buffer
, size
)))
269 HeapFree( GetProcessHeap(), 0, *buffer
);
271 else ret
= HeapAlloc( GetProcessHeap(), 0, size
);
277 /* retrieve a string pointer from packed data */
278 inline static LPWSTR
get_string( void **buffer
)
280 return get_data( buffer
, (strlenW( (LPWSTR
)*buffer
) + 1) * sizeof(WCHAR
) );
283 /* check whether a combobox expects strings or ids in CB_ADDSTRING/CB_INSERTSTRING */
284 inline static BOOL
combobox_has_strings( HWND hwnd
)
286 DWORD style
= GetWindowLongA( hwnd
, GWL_STYLE
);
287 return (!(style
& (CBS_OWNERDRAWFIXED
| CBS_OWNERDRAWVARIABLE
)) || (style
& CBS_HASSTRINGS
));
290 /* check whether a listbox expects strings or ids in LB_ADDSTRING/LB_INSERTSTRING */
291 inline static BOOL
listbox_has_strings( HWND hwnd
)
293 DWORD style
= GetWindowLongA( hwnd
, GWL_STYLE
);
294 return (!(style
& (LBS_OWNERDRAWFIXED
| LBS_OWNERDRAWVARIABLE
)) || (style
& LBS_HASSTRINGS
));
297 /* check whether message is in the range of keyboard messages */
298 inline static BOOL
is_keyboard_message( UINT message
)
300 return (message
>= WM_KEYFIRST
&& message
<= WM_KEYLAST
);
303 /* check whether message is in the range of mouse messages */
304 inline static BOOL
is_mouse_message( UINT message
)
306 return ((message
>= WM_NCMOUSEFIRST
&& message
<= WM_NCMOUSELAST
) ||
307 (message
>= WM_MOUSEFIRST
&& message
<= WM_MOUSELAST
));
310 /* check whether message matches the specified hwnd filter */
311 inline static BOOL
check_hwnd_filter( const MSG
*msg
, HWND hwnd_filter
)
313 if (!hwnd_filter
) return TRUE
;
314 return (msg
->hwnd
== hwnd_filter
|| IsChild( hwnd_filter
, msg
->hwnd
));
318 /***********************************************************************
319 * broadcast_message_callback
321 * Helper callback for broadcasting messages.
323 static BOOL CALLBACK
broadcast_message_callback( HWND hwnd
, LPARAM lparam
)
325 struct send_message_info
*info
= (struct send_message_info
*)lparam
;
326 if (!(GetWindowLongW( hwnd
, GWL_STYLE
) & (WS_POPUP
|WS_CAPTION
))) return TRUE
;
330 SendMessageTimeoutW( hwnd
, info
->msg
, info
->wparam
, info
->lparam
,
331 info
->flags
, info
->timeout
, NULL
);
334 SendMessageTimeoutA( hwnd
, info
->msg
, info
->wparam
, info
->lparam
,
335 info
->flags
, info
->timeout
, NULL
);
338 SendNotifyMessageW( hwnd
, info
->msg
, info
->wparam
, info
->lparam
);
341 SendMessageCallbackW( hwnd
, info
->msg
, info
->wparam
, info
->lparam
,
342 info
->callback
, info
->data
);
345 PostMessageW( hwnd
, info
->msg
, info
->wparam
, info
->lparam
);
348 ERR( "bad type %d\n", info
->type
);
355 /***********************************************************************
358 * Convert the wparam of an ASCII message to Unicode.
360 static WPARAM
map_wparam_AtoW( UINT message
, WPARAM wparam
)
365 case EM_SETPASSWORDCHAR
:
374 ch
[0] = (wparam
& 0xff);
375 ch
[1] = (wparam
>> 8);
376 MultiByteToWideChar(CP_ACP
, 0, ch
, 2, wch
, 2);
377 wparam
= MAKEWPARAM(wch
[0], wch
[1]);
384 ch
[0] = (wparam
>> 8);
385 ch
[1] = (wparam
& 0xff);
386 if (ch
[0]) MultiByteToWideChar(CP_ACP
, 0, ch
, 2, &wch
, 1);
387 else MultiByteToWideChar(CP_ACP
, 0, &ch
[1], 1, &wch
, 1);
388 wparam
= MAKEWPARAM( wch
, HIWORD(wparam
) );
396 /***********************************************************************
399 * Convert the wparam of a Unicode message to ASCII.
401 static WPARAM
map_wparam_WtoA( UINT message
, WPARAM wparam
)
406 case EM_SETPASSWORDCHAR
:
415 wch
[0] = LOWORD(wparam
);
416 wch
[1] = HIWORD(wparam
);
417 WideCharToMultiByte( CP_ACP
, 0, wch
, 2, (LPSTR
)ch
, 2, NULL
, NULL
);
418 wparam
= MAKEWPARAM( ch
[0] | (ch
[1] << 8), 0 );
423 WCHAR wch
= LOWORD(wparam
);
426 if (WideCharToMultiByte( CP_ACP
, 0, &wch
, 1, (LPSTR
)ch
, 2, NULL
, NULL
) == 2)
427 wparam
= MAKEWPARAM( (ch
[0] << 8) | ch
[1], HIWORD(wparam
) );
429 wparam
= MAKEWPARAM( ch
[0], HIWORD(wparam
) );
437 /***********************************************************************
440 * Pack a message for sending to another process.
441 * Return the size of the data we expect in the message reply.
442 * Set data->count to -1 if there is an error.
444 static size_t pack_message( HWND hwnd
, UINT message
, WPARAM wparam
, LPARAM lparam
,
445 struct packed_message
*data
)
453 CREATESTRUCTW
*cs
= (CREATESTRUCTW
*)lparam
;
454 push_data( data
, cs
, sizeof(*cs
) );
455 if (HIWORD(cs
->lpszName
)) push_string( data
, cs
->lpszName
);
456 if (HIWORD(cs
->lpszClass
)) push_string( data
, cs
->lpszClass
);
460 case WM_ASKCBFORMATNAME
:
461 return wparam
* sizeof(WCHAR
);
462 case WM_WININICHANGE
:
463 if (lparam
) push_string(data
, (LPWSTR
)lparam
);
466 case WM_DEVMODECHANGE
:
471 push_string( data
, (LPWSTR
)lparam
);
473 case WM_GETMINMAXINFO
:
474 push_data( data
, (MINMAXINFO
*)lparam
, sizeof(MINMAXINFO
) );
475 return sizeof(MINMAXINFO
);
477 push_data( data
, (DRAWITEMSTRUCT
*)lparam
, sizeof(DRAWITEMSTRUCT
) );
480 push_data( data
, (MEASUREITEMSTRUCT
*)lparam
, sizeof(MEASUREITEMSTRUCT
) );
481 return sizeof(MEASUREITEMSTRUCT
);
483 push_data( data
, (DELETEITEMSTRUCT
*)lparam
, sizeof(DELETEITEMSTRUCT
) );
486 push_data( data
, (COMPAREITEMSTRUCT
*)lparam
, sizeof(COMPAREITEMSTRUCT
) );
488 case WM_WINDOWPOSCHANGING
:
489 case WM_WINDOWPOSCHANGED
:
490 push_data( data
, (WINDOWPOS
*)lparam
, sizeof(WINDOWPOS
) );
491 return sizeof(WINDOWPOS
);
494 COPYDATASTRUCT
*cp
= (COPYDATASTRUCT
*)lparam
;
495 push_data( data
, cp
, sizeof(*cp
) );
496 if (cp
->lpData
) push_data( data
, cp
->lpData
, cp
->cbData
);
500 /* WM_NOTIFY cannot be sent across processes (MSDN) */
504 push_data( data
, (HELPINFO
*)lparam
, sizeof(HELPINFO
) );
506 case WM_STYLECHANGING
:
507 case WM_STYLECHANGED
:
508 push_data( data
, (STYLESTRUCT
*)lparam
, sizeof(STYLESTRUCT
) );
513 push_data( data
, (RECT
*)lparam
, sizeof(RECT
) );
518 NCCALCSIZE_PARAMS
*nc
= (NCCALCSIZE_PARAMS
*)lparam
;
519 push_data( data
, nc
, sizeof(*nc
) );
520 push_data( data
, nc
->lppos
, sizeof(*nc
->lppos
) );
521 return sizeof(*nc
) + sizeof(*nc
->lppos
);
524 if (lparam
) push_data( data
, (MSG
*)lparam
, sizeof(MSG
) );
526 case SBM_SETSCROLLINFO
:
527 push_data( data
, (SCROLLINFO
*)lparam
, sizeof(SCROLLINFO
) );
529 case SBM_GETSCROLLINFO
:
530 push_data( data
, (SCROLLINFO
*)lparam
, sizeof(SCROLLINFO
) );
531 return sizeof(SCROLLINFO
);
532 case SBM_GETSCROLLBARINFO
:
534 const SCROLLBARINFO
*info
= (const SCROLLBARINFO
*)lparam
;
535 size_t size
= min( info
->cbSize
, sizeof(SCROLLBARINFO
) );
536 push_data( data
, info
, size
);
544 if (wparam
) size
+= sizeof(DWORD
);
545 if (lparam
) size
+= sizeof(DWORD
);
550 case CB_GETDROPPEDCONTROLRECT
:
554 push_data( data
, (RECT
*)lparam
, sizeof(RECT
) );
558 WORD
*pw
= (WORD
*)lparam
;
559 push_data( data
, pw
, sizeof(*pw
) );
560 return *pw
* sizeof(WCHAR
);
564 if (wparam
) push_data( data
, (UINT
*)lparam
, sizeof(UINT
) * wparam
);
567 case CB_INSERTSTRING
:
569 case CB_FINDSTRINGEXACT
:
570 case CB_SELECTSTRING
:
571 if (combobox_has_strings( hwnd
)) push_string( data
, (LPWSTR
)lparam
);
574 if (!combobox_has_strings( hwnd
)) return sizeof(ULONG_PTR
);
575 return (SendMessageW( hwnd
, CB_GETLBTEXTLEN
, wparam
, 0 ) + 1) * sizeof(WCHAR
);
577 case LB_INSERTSTRING
:
579 case LB_FINDSTRINGEXACT
:
580 case LB_SELECTSTRING
:
581 if (listbox_has_strings( hwnd
)) push_string( data
, (LPWSTR
)lparam
);
584 if (!listbox_has_strings( hwnd
)) return sizeof(ULONG_PTR
);
585 return (SendMessageW( hwnd
, LB_GETTEXTLEN
, wparam
, 0 ) + 1) * sizeof(WCHAR
);
587 return wparam
* sizeof(UINT
);
589 push_data( data
, (MDINEXTMENU
*)lparam
, sizeof(MDINEXTMENU
) );
590 return sizeof(MDINEXTMENU
);
593 push_data( data
, (RECT
*)lparam
, sizeof(RECT
) );
597 MDICREATESTRUCTW
*cs
= (MDICREATESTRUCTW
*)lparam
;
598 push_data( data
, cs
, sizeof(*cs
) );
599 if (HIWORD(cs
->szTitle
)) push_string( data
, cs
->szTitle
);
600 if (HIWORD(cs
->szClass
)) push_string( data
, cs
->szClass
);
603 case WM_MDIGETACTIVE
:
604 if (lparam
) return sizeof(BOOL
);
606 case WM_WINE_SETWINDOWPOS
:
607 push_data( data
, (WINDOWPOS
*)lparam
, sizeof(WINDOWPOS
) );
609 case WM_WINE_KEYBOARD_LL_HOOK
:
610 push_data( data
, (KBDLLHOOKSTRUCT
*)lparam
, sizeof(KBDLLHOOKSTRUCT
) );
612 case WM_WINE_MOUSE_LL_HOOK
:
613 push_data( data
, (MSLLHOOKSTRUCT
*)lparam
, sizeof(MSLLHOOKSTRUCT
) );
616 if (!wparam
) return 0;
619 /* these contain an HFONT */
622 /* these contain an HDC */
624 case WM_ICONERASEBKGND
:
626 case WM_CTLCOLORMSGBOX
:
627 case WM_CTLCOLOREDIT
:
628 case WM_CTLCOLORLISTBOX
:
631 case WM_CTLCOLORSCROLLBAR
:
632 case WM_CTLCOLORSTATIC
:
635 /* these contain an HGLOBAL */
636 case WM_PAINTCLIPBOARD
:
637 case WM_SIZECLIPBOARD
:
638 /* these contain HICON */
641 case WM_QUERYDRAGICON
:
642 case WM_QUERYPARKICON
:
643 /* these contain pointers */
645 case WM_QUERYDROPOBJECT
:
649 case WM_DEVICECHANGE
:
650 FIXME( "msg %x (%s) not supported yet\n", message
, SPY_GetMsgName(message
, hwnd
) );
658 /***********************************************************************
661 * Unpack a message received from another process.
663 static BOOL
unpack_message( HWND hwnd
, UINT message
, WPARAM
*wparam
, LPARAM
*lparam
,
664 void **buffer
, size_t size
)
673 CREATESTRUCTW
*cs
= *buffer
;
674 WCHAR
*str
= (WCHAR
*)(cs
+ 1);
675 if (size
< sizeof(*cs
)) return FALSE
;
677 if (HIWORD(cs
->lpszName
))
679 if (!check_string( str
, size
)) return FALSE
;
681 size
-= (strlenW(str
) + 1) * sizeof(WCHAR
);
682 str
+= strlenW(str
) + 1;
684 if (HIWORD(cs
->lpszClass
))
686 if (!check_string( str
, size
)) return FALSE
;
692 case WM_ASKCBFORMATNAME
:
693 if (!get_buffer_space( buffer
, (*wparam
* sizeof(WCHAR
)) )) return FALSE
;
695 case WM_WININICHANGE
:
696 if (!*lparam
) return TRUE
;
699 case WM_DEVMODECHANGE
:
704 if (!check_string( *buffer
, size
)) return FALSE
;
706 case WM_GETMINMAXINFO
:
707 minsize
= sizeof(MINMAXINFO
);
710 minsize
= sizeof(DRAWITEMSTRUCT
);
713 minsize
= sizeof(MEASUREITEMSTRUCT
);
716 minsize
= sizeof(DELETEITEMSTRUCT
);
719 minsize
= sizeof(COMPAREITEMSTRUCT
);
721 case WM_WINDOWPOSCHANGING
:
722 case WM_WINDOWPOSCHANGED
:
723 case WM_WINE_SETWINDOWPOS
:
724 minsize
= sizeof(WINDOWPOS
);
728 COPYDATASTRUCT
*cp
= *buffer
;
729 if (size
< sizeof(*cp
)) return FALSE
;
732 minsize
= sizeof(*cp
) + cp
->cbData
;
738 /* WM_NOTIFY cannot be sent across processes (MSDN) */
741 minsize
= sizeof(HELPINFO
);
743 case WM_STYLECHANGING
:
744 case WM_STYLECHANGED
:
745 minsize
= sizeof(STYLESTRUCT
);
748 if (!*wparam
) minsize
= sizeof(RECT
);
751 NCCALCSIZE_PARAMS
*nc
= *buffer
;
752 if (size
< sizeof(*nc
) + sizeof(*nc
->lppos
)) return FALSE
;
753 nc
->lppos
= (WINDOWPOS
*)(nc
+ 1);
757 if (!*lparam
) return TRUE
;
758 minsize
= sizeof(MSG
);
760 case SBM_SETSCROLLINFO
:
761 minsize
= sizeof(SCROLLINFO
);
763 case SBM_GETSCROLLINFO
:
764 if (!get_buffer_space( buffer
, sizeof(SCROLLINFO
))) return FALSE
;
766 case SBM_GETSCROLLBARINFO
:
767 if (!get_buffer_space( buffer
, sizeof(SCROLLBARINFO
))) return FALSE
;
772 if (*wparam
|| *lparam
)
774 if (!get_buffer_space( buffer
, 2*sizeof(DWORD
) )) return FALSE
;
775 if (*wparam
) *wparam
= (WPARAM
)*buffer
;
776 if (*lparam
) *lparam
= (LPARAM
)((DWORD
*)*buffer
+ 1);
781 case CB_GETDROPPEDCONTROLRECT
:
782 if (!get_buffer_space( buffer
, sizeof(RECT
) )) return FALSE
;
786 minsize
= sizeof(RECT
);
791 if (size
< sizeof(WORD
)) return FALSE
;
792 len
= *(WORD
*)*buffer
;
793 if (!get_buffer_space( buffer
, (len
+ 1) * sizeof(WCHAR
) )) return FALSE
;
794 *lparam
= (LPARAM
)*buffer
+ sizeof(WORD
); /* don't erase WORD at start of buffer */
799 if (!*wparam
) return TRUE
;
800 minsize
= *wparam
* sizeof(UINT
);
803 case CB_INSERTSTRING
:
805 case CB_FINDSTRINGEXACT
:
806 case CB_SELECTSTRING
:
808 case LB_INSERTSTRING
:
810 case LB_FINDSTRINGEXACT
:
811 case LB_SELECTSTRING
:
812 if (!*buffer
) return TRUE
;
813 if (!check_string( *buffer
, size
)) return FALSE
;
817 size
= sizeof(ULONG_PTR
);
818 if (combobox_has_strings( hwnd
))
819 size
= (SendMessageW( hwnd
, CB_GETLBTEXTLEN
, *wparam
, 0 ) + 1) * sizeof(WCHAR
);
820 if (!get_buffer_space( buffer
, size
)) return FALSE
;
825 size
= sizeof(ULONG_PTR
);
826 if (listbox_has_strings( hwnd
))
827 size
= (SendMessageW( hwnd
, LB_GETTEXTLEN
, *wparam
, 0 ) + 1) * sizeof(WCHAR
);
828 if (!get_buffer_space( buffer
, size
)) return FALSE
;
832 if (!get_buffer_space( buffer
, *wparam
* sizeof(UINT
) )) return FALSE
;
835 minsize
= sizeof(MDINEXTMENU
);
836 if (!get_buffer_space( buffer
, sizeof(MDINEXTMENU
) )) return FALSE
;
840 minsize
= sizeof(RECT
);
841 if (!get_buffer_space( buffer
, sizeof(RECT
) )) return FALSE
;
845 MDICREATESTRUCTW
*cs
= *buffer
;
846 WCHAR
*str
= (WCHAR
*)(cs
+ 1);
847 if (size
< sizeof(*cs
)) return FALSE
;
849 if (HIWORD(cs
->szTitle
))
851 if (!check_string( str
, size
)) return FALSE
;
853 size
-= (strlenW(str
) + 1) * sizeof(WCHAR
);
854 str
+= strlenW(str
) + 1;
856 if (HIWORD(cs
->szClass
))
858 if (!check_string( str
, size
)) return FALSE
;
863 case WM_MDIGETACTIVE
:
864 if (!*lparam
) return TRUE
;
865 if (!get_buffer_space( buffer
, sizeof(BOOL
) )) return FALSE
;
867 case WM_WINE_KEYBOARD_LL_HOOK
:
868 minsize
= sizeof(KBDLLHOOKSTRUCT
);
870 case WM_WINE_MOUSE_LL_HOOK
:
871 minsize
= sizeof(MSLLHOOKSTRUCT
);
874 if (!*wparam
) return TRUE
;
877 /* these contain an HFONT */
880 /* these contain an HDC */
882 case WM_ICONERASEBKGND
:
884 case WM_CTLCOLORMSGBOX
:
885 case WM_CTLCOLOREDIT
:
886 case WM_CTLCOLORLISTBOX
:
889 case WM_CTLCOLORSCROLLBAR
:
890 case WM_CTLCOLORSTATIC
:
893 /* these contain an HGLOBAL */
894 case WM_PAINTCLIPBOARD
:
895 case WM_SIZECLIPBOARD
:
896 /* these contain HICON */
899 case WM_QUERYDRAGICON
:
900 case WM_QUERYPARKICON
:
901 /* these contain pointers */
903 case WM_QUERYDROPOBJECT
:
907 case WM_DEVICECHANGE
:
908 FIXME( "msg %x (%s) not supported yet\n", message
, SPY_GetMsgName(message
, hwnd
) );
912 return TRUE
; /* message doesn't need any unpacking */
915 /* default exit for most messages: check minsize and store buffer in lparam */
916 if (size
< minsize
) return FALSE
;
917 *lparam
= (LPARAM
)*buffer
;
922 /***********************************************************************
925 * Pack a reply to a message for sending to another process.
927 static void pack_reply( HWND hwnd
, UINT message
, WPARAM wparam
, LPARAM lparam
,
928 LRESULT res
, struct packed_message
*data
)
935 push_data( data
, (CREATESTRUCTW
*)lparam
, sizeof(CREATESTRUCTW
) );
940 push_data( data
, (WCHAR
*)lparam
, (res
+ 1) * sizeof(WCHAR
) );
942 case WM_GETMINMAXINFO
:
943 push_data( data
, (MINMAXINFO
*)lparam
, sizeof(MINMAXINFO
) );
946 push_data( data
, (MEASUREITEMSTRUCT
*)lparam
, sizeof(MEASUREITEMSTRUCT
) );
948 case WM_WINDOWPOSCHANGING
:
949 case WM_WINDOWPOSCHANGED
:
950 push_data( data
, (WINDOWPOS
*)lparam
, sizeof(WINDOWPOS
) );
953 if (lparam
) push_data( data
, (MSG
*)lparam
, sizeof(MSG
) );
955 case SBM_GETSCROLLINFO
:
956 push_data( data
, (SCROLLINFO
*)lparam
, sizeof(SCROLLINFO
) );
960 case CB_GETDROPPEDCONTROLRECT
:
963 push_data( data
, (RECT
*)lparam
, sizeof(RECT
) );
967 WORD
*ptr
= (WORD
*)lparam
;
968 push_data( data
, ptr
, ptr
[-1] * sizeof(WCHAR
) );
972 push_data( data
, (UINT
*)lparam
, wparam
* sizeof(UINT
) );
974 case WM_MDIGETACTIVE
:
975 if (lparam
) push_data( data
, (BOOL
*)lparam
, sizeof(BOOL
) );
979 push_data( data
, (RECT
*)lparam
, sizeof(RECT
) );
982 NCCALCSIZE_PARAMS
*nc
= (NCCALCSIZE_PARAMS
*)lparam
;
983 push_data( data
, nc
, sizeof(*nc
) );
984 push_data( data
, nc
->lppos
, sizeof(*nc
->lppos
) );
990 if (wparam
) push_data( data
, (DWORD
*)wparam
, sizeof(DWORD
) );
991 if (lparam
) push_data( data
, (DWORD
*)lparam
, sizeof(DWORD
) );
994 push_data( data
, (MDINEXTMENU
*)lparam
, sizeof(MDINEXTMENU
) );
997 push_data( data
, (MDICREATESTRUCTW
*)lparam
, sizeof(MDICREATESTRUCTW
) );
999 case WM_ASKCBFORMATNAME
:
1000 push_data( data
, (WCHAR
*)lparam
, (strlenW((WCHAR
*)lparam
) + 1) * sizeof(WCHAR
) );
1006 /***********************************************************************
1009 * Unpack a message reply received from another process.
1011 static void unpack_reply( HWND hwnd
, UINT message
, WPARAM wparam
, LPARAM lparam
,
1012 void *buffer
, size_t size
)
1019 CREATESTRUCTW
*cs
= (CREATESTRUCTW
*)lparam
;
1020 LPCWSTR name
= cs
->lpszName
, class = cs
->lpszClass
;
1021 memcpy( cs
, buffer
, min( sizeof(*cs
), size
));
1022 cs
->lpszName
= name
; /* restore the original pointers */
1023 cs
->lpszClass
= class;
1027 case WM_ASKCBFORMATNAME
:
1028 memcpy( (WCHAR
*)lparam
, buffer
, min( wparam
*sizeof(WCHAR
), size
));
1030 case WM_GETMINMAXINFO
:
1031 memcpy( (MINMAXINFO
*)lparam
, buffer
, min( sizeof(MINMAXINFO
), size
));
1033 case WM_MEASUREITEM
:
1034 memcpy( (MEASUREITEMSTRUCT
*)lparam
, buffer
, min( sizeof(MEASUREITEMSTRUCT
), size
));
1036 case WM_WINDOWPOSCHANGING
:
1037 case WM_WINDOWPOSCHANGED
:
1038 memcpy( (WINDOWPOS
*)lparam
, buffer
, min( sizeof(WINDOWPOS
), size
));
1041 if (lparam
) memcpy( (MSG
*)lparam
, buffer
, min( sizeof(MSG
), size
));
1043 case SBM_GETSCROLLINFO
:
1044 memcpy( (SCROLLINFO
*)lparam
, buffer
, min( sizeof(SCROLLINFO
), size
));
1046 case SBM_GETSCROLLBARINFO
:
1047 memcpy( (SCROLLBARINFO
*)lparam
, buffer
, min( sizeof(SCROLLBARINFO
), size
));
1050 case CB_GETDROPPEDCONTROLRECT
:
1051 case LB_GETITEMRECT
:
1054 memcpy( (RECT
*)lparam
, buffer
, min( sizeof(RECT
), size
));
1057 size
= min( size
, (size_t)*(WORD
*)lparam
);
1058 memcpy( (WCHAR
*)lparam
, buffer
, size
);
1060 case LB_GETSELITEMS
:
1061 memcpy( (UINT
*)lparam
, buffer
, min( wparam
*sizeof(UINT
), size
));
1065 memcpy( (WCHAR
*)lparam
, buffer
, size
);
1068 memcpy( (MDINEXTMENU
*)lparam
, buffer
, min( sizeof(MDINEXTMENU
), size
));
1070 case WM_MDIGETACTIVE
:
1071 if (lparam
) memcpy( (BOOL
*)lparam
, buffer
, min( sizeof(BOOL
), size
));
1075 memcpy( (RECT
*)lparam
, buffer
, min( sizeof(RECT
), size
));
1078 NCCALCSIZE_PARAMS
*nc
= (NCCALCSIZE_PARAMS
*)lparam
;
1079 WINDOWPOS
*wp
= nc
->lppos
;
1080 memcpy( nc
, buffer
, min( sizeof(*nc
), size
));
1081 if (size
> sizeof(*nc
))
1083 size
-= sizeof(*nc
);
1084 memcpy( wp
, (NCCALCSIZE_PARAMS
*)buffer
+ 1, min( sizeof(*wp
), size
));
1086 nc
->lppos
= wp
; /* restore the original pointer */
1094 memcpy( (DWORD
*)wparam
, buffer
, min( sizeof(DWORD
), size
));
1095 if (size
<= sizeof(DWORD
)) break;
1096 size
-= sizeof(DWORD
);
1097 buffer
= (DWORD
*)buffer
+ 1;
1099 if (lparam
) memcpy( (DWORD
*)lparam
, buffer
, min( sizeof(DWORD
), size
));
1103 MDICREATESTRUCTW
*cs
= (MDICREATESTRUCTW
*)lparam
;
1104 LPCWSTR title
= cs
->szTitle
, class = cs
->szClass
;
1105 memcpy( cs
, buffer
, min( sizeof(*cs
), size
));
1106 cs
->szTitle
= title
; /* restore the original pointers */
1107 cs
->szClass
= class;
1111 ERR( "should not happen: unexpected message %x\n", message
);
1117 /***********************************************************************
1120 * Send a reply to a sent message.
1122 static void reply_message( struct received_message_info
*info
, LRESULT result
, BOOL remove
)
1124 struct packed_message data
;
1125 int i
, replied
= info
->flags
& ISMEX_REPLIED
;
1127 if (info
->flags
& ISMEX_NOTIFY
) return; /* notify messages don't get replies */
1128 if (!remove
&& replied
) return; /* replied already */
1131 info
->flags
|= ISMEX_REPLIED
;
1133 if (info
->type
== MSG_OTHER_PROCESS
&& !replied
)
1135 pack_reply( info
->msg
.hwnd
, info
->msg
.message
, info
->msg
.wParam
,
1136 info
->msg
.lParam
, result
, &data
);
1139 SERVER_START_REQ( reply_message
)
1141 req
->result
= result
;
1142 req
->remove
= remove
;
1143 for (i
= 0; i
< data
.count
; i
++) wine_server_add_data( req
, data
.data
[i
], data
.size
[i
] );
1144 wine_server_call( req
);
1150 /***********************************************************************
1151 * handle_internal_message
1153 * Handle an internal Wine message instead of calling the window proc.
1155 static LRESULT
handle_internal_message( HWND hwnd
, UINT msg
, WPARAM wparam
, LPARAM lparam
)
1157 if (hwnd
== GetDesktopWindow()) return 0;
1160 case WM_WINE_DESTROYWINDOW
:
1161 return WIN_DestroyWindow( hwnd
);
1162 case WM_WINE_SETWINDOWPOS
:
1163 return USER_Driver
->pSetWindowPos( (WINDOWPOS
*)lparam
);
1164 case WM_WINE_SHOWWINDOW
:
1165 return ShowWindow( hwnd
, wparam
);
1166 case WM_WINE_SETPARENT
:
1167 return (LRESULT
)SetParent( hwnd
, (HWND
)wparam
);
1168 case WM_WINE_SETWINDOWLONG
:
1169 return (LRESULT
)SetWindowLongW( hwnd
, wparam
, lparam
);
1170 case WM_WINE_ENABLEWINDOW
:
1171 return EnableWindow( hwnd
, wparam
);
1172 case WM_WINE_SETACTIVEWINDOW
:
1173 return (LRESULT
)SetActiveWindow( (HWND
)wparam
);
1174 case WM_WINE_KEYBOARD_LL_HOOK
:
1175 return HOOK_CallHooks( WH_KEYBOARD_LL
, HC_ACTION
, wparam
, lparam
, TRUE
);
1176 case WM_WINE_MOUSE_LL_HOOK
:
1177 return HOOK_CallHooks( WH_MOUSE_LL
, HC_ACTION
, wparam
, lparam
, TRUE
);
1179 if (msg
>= WM_WINE_FIRST_DRIVER_MSG
&& msg
<= WM_WINE_LAST_DRIVER_MSG
)
1180 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, { (DWORD_PTR
)(__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
)
1284 UINT_PTR uiLo
, uiHi
;
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 => %p\n", uiLo
, uiHi
, 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
)
1403 UINT_PTR uiLo
, uiHi
;
1412 /* hMem is being passed */
1413 if (size
!= sizeof(HGLOBAL
)) return FALSE
;
1414 if (!buffer
|| !*buffer
) return FALSE
;
1416 memcpy( &hMem
, *buffer
, size
);
1417 uiHi
= (UINT_PTR
)hMem
;
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
);
1449 uiLo
= (UINT_PTR
)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 */
1657 GetGUIThreadInfo( GetCurrentThreadId(), &info
);
1658 if (info
.hwndCapture
)
1661 msg
->hwnd
= info
.hwndCapture
;
1665 msg
->hwnd
= WINPOS_WindowFromPoint( msg
->hwnd
, msg
->pt
, &hittest
);
1668 if (!msg
->hwnd
|| !WIN_IsCurrentThread( msg
->hwnd
))
1670 accept_hardware_message( hw_id
, TRUE
, msg
->hwnd
);
1674 /* FIXME: is this really the right place for this hook? */
1675 event
.message
= msg
->message
;
1676 event
.time
= msg
->time
;
1677 event
.hwnd
= msg
->hwnd
;
1678 event
.paramL
= msg
->pt
.x
;
1679 event
.paramH
= msg
->pt
.y
;
1680 HOOK_CallHooks( WH_JOURNALRECORD
, HC_ACTION
, 0, (LPARAM
)&event
, TRUE
);
1682 if (!check_hwnd_filter( msg
, hwnd_filter
)) return FALSE
;
1685 message
= msg
->message
;
1686 /* Note: windows has no concept of a non-client wheel message */
1687 if (message
!= WM_MOUSEWHEEL
)
1689 if (hittest
!= HTCLIENT
)
1691 message
+= WM_NCMOUSEMOVE
- WM_MOUSEMOVE
;
1692 msg
->wParam
= hittest
;
1696 /* coordinates don't get translated while tracking a menu */
1697 /* FIXME: should differentiate popups and top-level menus */
1698 if (!(info
.flags
& GUI_INMENUMODE
))
1699 ScreenToClient( msg
->hwnd
, &pt
);
1702 msg
->lParam
= MAKELONG( pt
.x
, pt
.y
);
1704 /* translate double clicks */
1706 if ((msg
->message
== WM_LBUTTONDOWN
) ||
1707 (msg
->message
== WM_RBUTTONDOWN
) ||
1708 (msg
->message
== WM_MBUTTONDOWN
) ||
1709 (msg
->message
== WM_XBUTTONDOWN
))
1711 BOOL update
= remove
;
1713 /* translate double clicks -
1714 * note that ...MOUSEMOVEs can slip in between
1715 * ...BUTTONDOWN and ...BUTTONDBLCLK messages */
1717 if ((info
.flags
& (GUI_INMENUMODE
|GUI_INMOVESIZE
)) ||
1718 hittest
!= HTCLIENT
||
1719 (GetClassLongA( msg
->hwnd
, GCL_STYLE
) & CS_DBLCLKS
))
1721 if ((msg
->message
== clk_msg
.message
) &&
1722 (msg
->hwnd
== clk_msg
.hwnd
) &&
1723 (msg
->wParam
== clk_msg
.wParam
) &&
1724 (msg
->time
- clk_msg
.time
< GetDoubleClickTime()) &&
1725 (abs(msg
->pt
.x
- clk_msg
.pt
.x
) < GetSystemMetrics(SM_CXDOUBLECLK
)/2) &&
1726 (abs(msg
->pt
.y
- clk_msg
.pt
.y
) < GetSystemMetrics(SM_CYDOUBLECLK
)/2))
1728 message
+= (WM_LBUTTONDBLCLK
- WM_LBUTTONDOWN
);
1731 clk_msg
.message
= 0; /* clear the double click conditions */
1736 if (message
< first
|| message
> last
) return FALSE
;
1737 /* update static double click conditions */
1738 if (update
) clk_msg
= *msg
;
1742 if (message
< first
|| message
> last
) return FALSE
;
1745 /* message is accepted now (but may still get dropped) */
1748 hook
.hwnd
= msg
->hwnd
;
1749 hook
.wHitTestCode
= hittest
;
1750 hook
.dwExtraInfo
= extra_info
;
1751 if (HOOK_CallHooks( WH_MOUSE
, remove
? HC_ACTION
: HC_NOREMOVE
,
1752 message
, (LPARAM
)&hook
, TRUE
))
1755 hook
.hwnd
= msg
->hwnd
;
1756 hook
.wHitTestCode
= hittest
;
1757 hook
.dwExtraInfo
= extra_info
;
1758 HOOK_CallHooks( WH_CBT
, HCBT_CLICKSKIPPED
, message
, (LPARAM
)&hook
, TRUE
);
1759 accept_hardware_message( hw_id
, TRUE
, 0 );
1763 if ((hittest
== HTERROR
) || (hittest
== HTNOWHERE
))
1765 SendMessageW( msg
->hwnd
, WM_SETCURSOR
, (WPARAM
)msg
->hwnd
,
1766 MAKELONG( hittest
, msg
->message
));
1767 accept_hardware_message( hw_id
, TRUE
, 0 );
1771 accept_hardware_message( hw_id
, remove
, 0 );
1773 if (!remove
|| info
.hwndCapture
)
1775 msg
->message
= message
;
1781 if ((msg
->message
== WM_LBUTTONDOWN
) ||
1782 (msg
->message
== WM_RBUTTONDOWN
) ||
1783 (msg
->message
== WM_MBUTTONDOWN
) ||
1784 (msg
->message
== WM_XBUTTONDOWN
))
1786 /* Send the WM_PARENTNOTIFY,
1787 * note that even for double/nonclient clicks
1788 * notification message is still WM_L/M/RBUTTONDOWN.
1790 send_parent_notify( msg
->hwnd
, msg
->message
, 0, msg
->pt
);
1792 /* Activate the window if needed */
1794 if (msg
->hwnd
!= info
.hwndActive
)
1796 HWND hwndTop
= msg
->hwnd
;
1799 if ((GetWindowLongW( hwndTop
, GWL_STYLE
) & (WS_POPUP
|WS_CHILD
)) != WS_CHILD
) break;
1800 hwndTop
= GetParent( hwndTop
);
1803 if (hwndTop
&& hwndTop
!= GetDesktopWindow())
1805 LONG ret
= SendMessageW( msg
->hwnd
, WM_MOUSEACTIVATE
, (WPARAM
)hwndTop
,
1806 MAKELONG( hittest
, msg
->message
) );
1809 case MA_NOACTIVATEANDEAT
:
1814 case MA_ACTIVATEANDEAT
:
1819 if (!FOCUS_MouseActivate( hwndTop
)) eatMsg
= TRUE
;
1822 WARN( "unknown WM_MOUSEACTIVATE code %ld\n", ret
);
1829 /* send the WM_SETCURSOR message */
1831 /* Windows sends the normal mouse message as the message parameter
1832 in the WM_SETCURSOR message even if it's non-client mouse message */
1833 SendMessageW( msg
->hwnd
, WM_SETCURSOR
, (WPARAM
)msg
->hwnd
, MAKELONG( hittest
, msg
->message
));
1835 msg
->message
= message
;
1840 /***********************************************************************
1841 * process_hardware_message
1843 * Process a hardware message; return TRUE if message should be passed on to the app
1845 static BOOL
process_hardware_message( MSG
*msg
, UINT hw_id
, ULONG_PTR extra_info
, HWND hwnd_filter
,
1846 UINT first
, UINT last
, BOOL remove
)
1848 if (is_keyboard_message( msg
->message
))
1849 return process_keyboard_message( msg
, hw_id
, hwnd_filter
, first
, last
, remove
);
1851 if (is_mouse_message( msg
->message
))
1852 return process_mouse_message( msg
, hw_id
, extra_info
, hwnd_filter
, first
, last
, remove
);
1854 ERR( "unknown message type %x\n", msg
->message
);
1859 /***********************************************************************
1860 * call_sendmsg_callback
1862 * Call the callback function of SendMessageCallback.
1864 static inline void call_sendmsg_callback( SENDASYNCPROC callback
, HWND hwnd
, UINT msg
,
1865 ULONG_PTR data
, LRESULT result
)
1867 if (TRACE_ON(relay
))
1868 DPRINTF( "%04lx:Call message callback %p (hwnd=%p,msg=%s,data=%08lx,result=%08lx)\n",
1869 GetCurrentThreadId(), callback
, hwnd
, SPY_GetMsgName( msg
, hwnd
),
1871 callback( hwnd
, msg
, data
, result
);
1872 if (TRACE_ON(relay
))
1873 DPRINTF( "%04lx:Ret message callback %p (hwnd=%p,msg=%s,data=%08lx,result=%08lx)\n",
1874 GetCurrentThreadId(), callback
, hwnd
, SPY_GetMsgName( msg
, hwnd
),
1879 /***********************************************************************
1882 * Retrieve the hook procedure real value for a module-relative proc
1884 static void *get_hook_proc( void *proc
, const WCHAR
*module
)
1888 if (!(mod
= GetModuleHandleW(module
)))
1890 TRACE( "loading %s\n", debugstr_w(module
) );
1891 /* FIXME: the library will never be freed */
1892 if (!(mod
= LoadLibraryW(module
))) return NULL
;
1894 return (char *)mod
+ (ULONG_PTR
)proc
;
1898 /***********************************************************************
1901 * Peek for a message matching the given parameters. Return FALSE if none available.
1902 * All pending sent messages are processed before returning.
1904 static BOOL
peek_message( MSG
*msg
, HWND hwnd
, UINT first
, UINT last
, int flags
)
1907 ULONG_PTR extra_info
= 0;
1908 struct user_thread_info
*thread_info
= get_user_thread_info();
1909 struct received_message_info info
, *old_info
;
1910 unsigned int hw_id
= 0; /* id of previous hardware message */
1912 if (!first
&& !last
) last
= ~0;
1917 void *buffer
= NULL
;
1918 size_t size
= 0, buffer_size
= 0;
1920 do /* loop while buffer is too small */
1922 if (buffer_size
&& !(buffer
= HeapAlloc( GetProcessHeap(), 0, buffer_size
)))
1924 SERVER_START_REQ( get_message
)
1927 req
->get_win
= hwnd
;
1928 req
->get_first
= first
;
1929 req
->get_last
= last
;
1931 if (buffer_size
) wine_server_set_reply( req
, buffer
, buffer_size
);
1932 if (!(res
= wine_server_call( req
)))
1934 size
= wine_server_reply_size( reply
);
1935 info
.type
= reply
->type
;
1936 info
.msg
.hwnd
= reply
->win
;
1937 info
.msg
.message
= reply
->msg
;
1938 info
.msg
.wParam
= reply
->wparam
;
1939 info
.msg
.lParam
= reply
->lparam
;
1940 info
.msg
.time
= reply
->time
;
1941 info
.msg
.pt
.x
= reply
->x
;
1942 info
.msg
.pt
.y
= reply
->y
;
1943 info
.hook
= reply
->hook
;
1944 info
.hook_proc
= reply
->hook_proc
;
1945 hw_id
= reply
->hw_id
;
1946 extra_info
= reply
->info
;
1947 thread_info
->active_hooks
= reply
->active_hooks
;
1951 HeapFree( GetProcessHeap(), 0, buffer
);
1952 buffer_size
= reply
->total
;
1956 } while (res
== STATUS_BUFFER_OVERFLOW
);
1958 if (res
) return FALSE
;
1960 TRACE( "got type %d msg %x (%s) hwnd %p wp %x lp %lx\n",
1961 info
.type
, info
.msg
.message
,
1962 (info
.type
== MSG_WINEVENT
) ? "MSG_WINEVENT" : SPY_GetMsgName(info
.msg
.message
, info
.msg
.hwnd
),
1963 info
.msg
.hwnd
, info
.msg
.wParam
, info
.msg
.lParam
);
1969 info
.flags
= ISMEX_SEND
;
1972 info
.flags
= ISMEX_NOTIFY
;
1975 info
.flags
= ISMEX_CALLBACK
;
1977 case MSG_CALLBACK_RESULT
:
1978 call_sendmsg_callback( (SENDASYNCPROC
)info
.msg
.wParam
, info
.msg
.hwnd
,
1979 info
.msg
.message
, extra_info
, info
.msg
.lParam
);
1984 WCHAR module
[MAX_PATH
];
1985 size
= min( size
, (MAX_PATH
- 1) * sizeof(WCHAR
) );
1986 memcpy( module
, buffer
, size
);
1987 module
[size
/ sizeof(WCHAR
)] = 0;
1988 if (!(info
.hook_proc
= get_hook_proc( info
.hook_proc
, module
)))
1990 ERR( "invalid winevent hook module name %s\n", debugstr_w(module
) );
1994 if (TRACE_ON(relay
))
1995 DPRINTF( "%04lx:Call winevent proc %p (hook=%p,event=%x,hwnd=%p,object_id=%x,child_id=%lx,tid=%04lx,time=%lx)\n",
1996 GetCurrentThreadId(), info
.hook_proc
,
1997 info
.hook
, info
.msg
.message
, info
.msg
.hwnd
, info
.msg
.wParam
,
1998 info
.msg
.lParam
, extra_info
, info
.msg
.time
);
2000 info
.hook_proc( info
.hook
, info
.msg
.message
, info
.msg
.hwnd
, info
.msg
.wParam
,
2001 info
.msg
.lParam
, extra_info
, info
.msg
.time
);
2003 if (TRACE_ON(relay
))
2004 DPRINTF( "%04lx:Ret winevent proc %p (hook=%p,event=%x,hwnd=%p,object_id=%x,child_id=%lx,tid=%04lx,time=%lx)\n",
2005 GetCurrentThreadId(), info
.hook_proc
,
2006 info
.hook
, info
.msg
.message
, info
.msg
.hwnd
, info
.msg
.wParam
,
2007 info
.msg
.lParam
, extra_info
, info
.msg
.time
);
2009 case MSG_OTHER_PROCESS
:
2010 info
.flags
= ISMEX_SEND
;
2011 if (!unpack_message( info
.msg
.hwnd
, info
.msg
.message
, &info
.msg
.wParam
,
2012 &info
.msg
.lParam
, &buffer
, size
))
2014 ERR( "invalid packed message %x (%s) hwnd %p wp %x lp %lx size %d\n",
2015 info
.msg
.message
, SPY_GetMsgName(info
.msg
.message
, info
.msg
.hwnd
), info
.msg
.hwnd
,
2016 info
.msg
.wParam
, info
.msg
.lParam
, size
);
2018 reply_message( &info
, 0, TRUE
);
2023 if (!process_hardware_message( &info
.msg
, hw_id
, extra_info
,
2024 hwnd
, first
, last
, flags
& GET_MSG_REMOVE
))
2026 TRACE("dropping msg %x\n", info
.msg
.message
);
2027 goto next
; /* ignore it */
2029 thread_info
->GetMessagePosVal
= MAKELONG( info
.msg
.pt
.x
, info
.msg
.pt
.y
);
2032 thread_info
->GetMessageExtraInfoVal
= extra_info
;
2033 if (info
.msg
.message
>= WM_DDE_FIRST
&& info
.msg
.message
<= WM_DDE_LAST
)
2035 if (!unpack_dde_message( info
.msg
.hwnd
, info
.msg
.message
, &info
.msg
.wParam
,
2036 &info
.msg
.lParam
, &buffer
, size
))
2038 ERR( "invalid packed dde-message %x (%s) hwnd %p wp %x lp %lx size %d\n",
2039 info
.msg
.message
, SPY_GetMsgName(info
.msg
.message
, info
.msg
.hwnd
),
2040 info
.msg
.hwnd
, info
.msg
.wParam
, info
.msg
.lParam
, size
);
2041 goto next
; /* ignore it */
2045 HeapFree( GetProcessHeap(), 0, buffer
);
2049 /* if we get here, we have a sent message; call the window procedure */
2050 old_info
= thread_info
->receive_info
;
2051 thread_info
->receive_info
= &info
;
2052 result
= call_window_proc( info
.msg
.hwnd
, info
.msg
.message
, info
.msg
.wParam
,
2053 info
.msg
.lParam
, (info
.type
!= MSG_ASCII
), FALSE
);
2054 reply_message( &info
, result
, TRUE
);
2055 thread_info
->receive_info
= old_info
;
2057 HeapFree( GetProcessHeap(), 0, buffer
);
2062 /***********************************************************************
2063 * process_sent_messages
2065 * Process all pending sent messages.
2067 inline static void process_sent_messages(void)
2070 peek_message( &msg
, 0, 0, 0, GET_MSG_REMOVE
| GET_MSG_SENT_ONLY
);
2074 /***********************************************************************
2075 * get_server_queue_handle
2077 * Get a handle to the server message queue for the current thread.
2079 static HANDLE
get_server_queue_handle(void)
2081 struct user_thread_info
*thread_info
= get_user_thread_info();
2084 if (!(ret
= thread_info
->server_queue
))
2086 SERVER_START_REQ( get_msg_queue
)
2088 wine_server_call( req
);
2089 ret
= reply
->handle
;
2092 thread_info
->server_queue
= ret
;
2093 if (!ret
) ERR( "Cannot get server thread queue\n" );
2099 /***********************************************************************
2100 * wait_message_reply
2102 * Wait until a sent message gets replied to.
2104 static void wait_message_reply( UINT flags
)
2106 HANDLE server_queue
= get_server_queue_handle();
2110 unsigned int wake_bits
= 0, changed_bits
= 0;
2113 SERVER_START_REQ( set_queue_mask
)
2115 req
->wake_mask
= QS_SMRESULT
| ((flags
& SMTO_BLOCK
) ? 0 : QS_SENDMESSAGE
);
2116 req
->changed_mask
= req
->wake_mask
;
2118 if (!wine_server_call( req
))
2120 wake_bits
= reply
->wake_bits
;
2121 changed_bits
= reply
->changed_bits
;
2126 if (wake_bits
& QS_SMRESULT
) return; /* got a result */
2127 if (wake_bits
& QS_SENDMESSAGE
)
2129 /* Process the sent message immediately */
2130 process_sent_messages();
2134 /* now wait for it */
2136 ReleaseThunkLock( &dwlc
);
2137 res
= USER_Driver
->pMsgWaitForMultipleObjectsEx( 1, &server_queue
,
2138 INFINITE
, QS_ALLINPUT
, 0 );
2139 if (dwlc
) RestoreThunkLock( dwlc
);
2143 /***********************************************************************
2144 * put_message_in_queue
2146 * Put a sent message into the destination queue.
2147 * For inter-process message, reply_size is set to expected size of reply data.
2149 static BOOL
put_message_in_queue( DWORD dest_tid
, const struct send_message_info
*info
,
2150 size_t *reply_size
)
2152 struct packed_message data
;
2156 /* Check for INFINITE timeout for compatibility with Win9x,
2157 * although Windows >= NT does not do so
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
, NULL
);
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
, 0, &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
, 0, &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 * Posts a quit message to the current thread's message queue.
2678 * exit_code [I] Exit code to return from message loop.
2684 * This function is not the same as calling:
2685 *|PostThreadMessage(GetCurrentThreadId(), WM_QUIT, exit_code, 0);
2686 * It instead sets a flag in the message queue that signals it to generate
2687 * a WM_QUIT message when there are no other pending sent or posted messages
2690 void WINAPI
PostQuitMessage( INT exit_code
)
2692 SERVER_START_REQ( post_quit_message
)
2694 req
->exit_code
= exit_code
;
2695 wine_server_call( req
);
2701 /***********************************************************************
2702 * PeekMessageW (USER32.@)
2704 BOOL WINAPI
PeekMessageW( MSG
*msg_out
, HWND hwnd
, UINT first
, UINT last
, UINT flags
)
2706 struct user_thread_info
*thread_info
= get_user_thread_info();
2710 FIXME("PM_QS_xxxx flags (%04x) are not handled\n", flags
>> 16);
2712 USER_CheckNotLock();
2714 /* check for graphics events */
2715 USER_Driver
->pMsgWaitForMultipleObjectsEx( 0, NULL
, 0, QS_ALLINPUT
, 0 );
2717 hwnd
= WIN_GetFullHandle( hwnd
);
2721 if (!peek_message( &msg
, hwnd
, first
, last
, (flags
& PM_REMOVE
) ? GET_MSG_REMOVE
: 0 ))
2723 if (!(flags
& PM_NOYIELD
))
2726 ReleaseThunkLock(&count
);
2728 if (count
) RestoreThunkLock(count
);
2732 if (msg
.message
& 0x80000000)
2734 if (!(flags
& PM_REMOVE
))
2736 /* Have to remove the message explicitly.
2737 Do this before handling it, because the message handler may
2738 call PeekMessage again */
2739 peek_message( &msg
, msg
.hwnd
, msg
.message
, msg
.message
, GET_MSG_REMOVE
);
2741 handle_internal_message( msg
.hwnd
, msg
.message
, msg
.wParam
, msg
.lParam
);
2746 thread_info
->GetMessageTimeVal
= msg
.time
;
2747 msg
.pt
.x
= LOWORD( thread_info
->GetMessagePosVal
);
2748 msg
.pt
.y
= HIWORD( thread_info
->GetMessagePosVal
);
2750 HOOK_CallHooks( WH_GETMESSAGE
, HC_ACTION
, flags
& PM_REMOVE
, (LPARAM
)&msg
, TRUE
);
2752 /* copy back our internal safe copy of message data to msg_out.
2753 * msg_out is a variable from the *program*, so it can't be used
2754 * internally as it can get "corrupted" by our use of SendMessage()
2755 * (back to the program) inside the message handling itself. */
2758 SetLastError( ERROR_NOACCESS
);
2766 /***********************************************************************
2767 * PeekMessageA (USER32.@)
2769 BOOL WINAPI
PeekMessageA( MSG
*msg
, HWND hwnd
, UINT first
, UINT last
, UINT flags
)
2771 BOOL ret
= PeekMessageW( msg
, hwnd
, first
, last
, flags
);
2772 if (ret
) msg
->wParam
= map_wparam_WtoA( msg
->message
, msg
->wParam
);
2777 /***********************************************************************
2778 * GetMessageW (USER32.@)
2780 BOOL WINAPI
GetMessageW( MSG
*msg
, HWND hwnd
, UINT first
, UINT last
)
2782 HANDLE server_queue
= get_server_queue_handle();
2783 int mask
= QS_POSTMESSAGE
| QS_SENDMESSAGE
; /* Always selected */
2787 if ((first
<= WM_KEYLAST
) && (last
>= WM_KEYFIRST
)) mask
|= QS_KEY
;
2788 if ( ((first
<= WM_MOUSELAST
) && (last
>= WM_MOUSEFIRST
)) ||
2789 ((first
<= WM_NCMOUSELAST
) && (last
>= WM_NCMOUSEFIRST
)) ) mask
|= QS_MOUSE
;
2790 if ((first
<= WM_TIMER
) && (last
>= WM_TIMER
)) mask
|= QS_TIMER
;
2791 if ((first
<= WM_SYSTIMER
) && (last
>= WM_SYSTIMER
)) mask
|= QS_TIMER
;
2792 if ((first
<= WM_PAINT
) && (last
>= WM_PAINT
)) mask
|= QS_PAINT
;
2794 else mask
|= QS_MOUSE
| QS_KEY
| QS_TIMER
| QS_PAINT
;
2796 while (!PeekMessageW( msg
, hwnd
, first
, last
, PM_REMOVE
))
2798 /* wait until one of the bits is set */
2799 unsigned int wake_bits
= 0, changed_bits
= 0;
2802 SERVER_START_REQ( set_queue_mask
)
2804 req
->wake_mask
= QS_SENDMESSAGE
;
2805 req
->changed_mask
= mask
;
2807 if (!wine_server_call( req
))
2809 wake_bits
= reply
->wake_bits
;
2810 changed_bits
= reply
->changed_bits
;
2815 if (changed_bits
& mask
) continue;
2816 if (wake_bits
& QS_SENDMESSAGE
) continue;
2818 TRACE( "(%04lx) mask=%08x, bits=%08x, changed=%08x, waiting\n",
2819 GetCurrentThreadId(), mask
, wake_bits
, changed_bits
);
2821 ReleaseThunkLock( &dwlc
);
2822 USER_Driver
->pMsgWaitForMultipleObjectsEx( 1, &server_queue
, INFINITE
, QS_ALLINPUT
, 0 );
2823 if (dwlc
) RestoreThunkLock( dwlc
);
2826 return (msg
->message
!= WM_QUIT
);
2830 /***********************************************************************
2831 * GetMessageA (USER32.@)
2833 BOOL WINAPI
GetMessageA( MSG
*msg
, HWND hwnd
, UINT first
, UINT last
)
2835 GetMessageW( msg
, hwnd
, first
, last
);
2836 msg
->wParam
= map_wparam_WtoA( msg
->message
, msg
->wParam
);
2837 return (msg
->message
!= WM_QUIT
);
2841 /***********************************************************************
2842 * IsDialogMessageA (USER32.@)
2843 * IsDialogMessage (USER32.@)
2845 BOOL WINAPI
IsDialogMessageA( HWND hwndDlg
, LPMSG pmsg
)
2848 msg
.wParam
= map_wparam_AtoW( msg
.message
, msg
.wParam
);
2849 return IsDialogMessageW( hwndDlg
, &msg
);
2853 /***********************************************************************
2854 * TranslateMessage (USER32.@)
2856 * Implementation of TranslateMessage.
2858 * TranslateMessage translates virtual-key messages into character-messages,
2860 * WM_KEYDOWN/WM_KEYUP combinations produce a WM_CHAR or WM_DEADCHAR message.
2861 * ditto replacing WM_* with WM_SYS*
2862 * This produces WM_CHAR messages only for keys mapped to ASCII characters
2863 * by the keyboard driver.
2865 * If the message is WM_KEYDOWN, WM_KEYUP, WM_SYSKEYDOWN, or WM_SYSKEYUP, the
2866 * return value is nonzero, regardless of the translation.
2869 BOOL WINAPI
TranslateMessage( const MSG
*msg
)
2875 if (msg
->message
< WM_KEYFIRST
|| msg
->message
> WM_KEYLAST
) return FALSE
;
2876 if (msg
->message
!= WM_KEYDOWN
&& msg
->message
!= WM_SYSKEYDOWN
) return TRUE
;
2878 TRACE_(key
)("Translating key %s (%04x), scancode %02x\n",
2879 SPY_GetVKeyName(msg
->wParam
), msg
->wParam
, LOBYTE(HIWORD(msg
->lParam
)));
2881 GetKeyboardState( state
);
2882 /* FIXME : should handle ToUnicode yielding 2 */
2883 switch (ToUnicode(msg
->wParam
, HIWORD(msg
->lParam
), state
, wp
, 2, 0))
2886 message
= (msg
->message
== WM_KEYDOWN
) ? WM_CHAR
: WM_SYSCHAR
;
2887 TRACE_(key
)("1 -> PostMessageW(%p,%s,%04x,%08lx)\n",
2888 msg
->hwnd
, SPY_GetMsgName(message
, msg
->hwnd
), wp
[0], msg
->lParam
);
2889 PostMessageW( msg
->hwnd
, message
, wp
[0], msg
->lParam
);
2893 message
= (msg
->message
== WM_KEYDOWN
) ? WM_DEADCHAR
: WM_SYSDEADCHAR
;
2894 TRACE_(key
)("-1 -> PostMessageW(%p,%s,%04x,%08lx)\n",
2895 msg
->hwnd
, SPY_GetMsgName(message
, msg
->hwnd
), wp
[0], msg
->lParam
);
2896 PostMessageW( msg
->hwnd
, message
, wp
[0], msg
->lParam
);
2903 /***********************************************************************
2904 * DispatchMessageA (USER32.@)
2906 * See DispatchMessageW.
2908 LONG WINAPI
DispatchMessageA( const MSG
* msg
)
2914 /* Process timer messages */
2915 if ((msg
->message
== WM_TIMER
) || (msg
->message
== WM_SYSTIMER
))
2917 if (msg
->lParam
) return CallWindowProcA( (WNDPROC
)msg
->lParam
, msg
->hwnd
,
2918 msg
->message
, msg
->wParam
, GetTickCount() );
2921 if (!(wndPtr
= WIN_GetPtr( msg
->hwnd
)))
2923 if (msg
->hwnd
) SetLastError( ERROR_INVALID_WINDOW_HANDLE
);
2926 if (wndPtr
== WND_OTHER_PROCESS
|| wndPtr
== WND_DESKTOP
)
2928 if (IsWindow( msg
->hwnd
)) SetLastError( ERROR_MESSAGE_SYNC_ONLY
);
2929 else SetLastError( ERROR_INVALID_WINDOW_HANDLE
);
2932 if (wndPtr
->tid
!= GetCurrentThreadId())
2934 SetLastError( ERROR_MESSAGE_SYNC_ONLY
);
2935 WIN_ReleasePtr( wndPtr
);
2938 winproc
= wndPtr
->winproc
;
2939 WIN_ReleasePtr( wndPtr
);
2941 SPY_EnterMessage( SPY_DISPATCHMESSAGE
, msg
->hwnd
, msg
->message
,
2942 msg
->wParam
, msg
->lParam
);
2943 retval
= CallWindowProcA( winproc
, msg
->hwnd
, msg
->message
,
2944 msg
->wParam
, msg
->lParam
);
2945 SPY_ExitMessage( SPY_RESULT_OK
, msg
->hwnd
, msg
->message
, retval
,
2946 msg
->wParam
, msg
->lParam
);
2948 if (msg
->message
== WM_PAINT
)
2950 /* send a WM_NCPAINT and WM_ERASEBKGND if the non-client area is still invalid */
2951 HRGN hrgn
= CreateRectRgn( 0, 0, 0, 0 );
2952 GetUpdateRgn( msg
->hwnd
, hrgn
, TRUE
);
2953 DeleteObject( hrgn
);
2959 /***********************************************************************
2960 * DispatchMessageW (USER32.@) Process a message
2962 * Process the message specified in the structure *_msg_.
2964 * If the lpMsg parameter points to a WM_TIMER message and the
2965 * parameter of the WM_TIMER message is not NULL, the lParam parameter
2966 * points to the function that is called instead of the window
2969 * The message must be valid.
2973 * DispatchMessage() returns the result of the window procedure invoked.
2980 LONG WINAPI
DispatchMessageW( const MSG
* msg
)
2986 /* Process timer messages */
2987 if ((msg
->message
== WM_TIMER
) || (msg
->message
== WM_SYSTIMER
))
2989 if (msg
->lParam
) return CallWindowProcW( (WNDPROC
)msg
->lParam
, msg
->hwnd
,
2990 msg
->message
, msg
->wParam
, GetTickCount() );
2993 if (!(wndPtr
= WIN_GetPtr( msg
->hwnd
)))
2995 if (msg
->hwnd
) SetLastError( ERROR_INVALID_WINDOW_HANDLE
);
2998 if (wndPtr
== WND_OTHER_PROCESS
|| wndPtr
== WND_DESKTOP
)
3000 if (IsWindow( msg
->hwnd
)) SetLastError( ERROR_MESSAGE_SYNC_ONLY
);
3001 else SetLastError( ERROR_INVALID_WINDOW_HANDLE
);
3004 if (wndPtr
->tid
!= GetCurrentThreadId())
3006 SetLastError( ERROR_MESSAGE_SYNC_ONLY
);
3007 WIN_ReleasePtr( wndPtr
);
3010 winproc
= wndPtr
->winproc
;
3011 WIN_ReleasePtr( wndPtr
);
3013 SPY_EnterMessage( SPY_DISPATCHMESSAGE
, msg
->hwnd
, msg
->message
,
3014 msg
->wParam
, msg
->lParam
);
3015 retval
= CallWindowProcW( winproc
, msg
->hwnd
, msg
->message
,
3016 msg
->wParam
, msg
->lParam
);
3017 SPY_ExitMessage( SPY_RESULT_OK
, msg
->hwnd
, msg
->message
, retval
,
3018 msg
->wParam
, msg
->lParam
);
3020 if (msg
->message
== WM_PAINT
)
3022 /* send a WM_NCPAINT and WM_ERASEBKGND if the non-client area is still invalid */
3023 HRGN hrgn
= CreateRectRgn( 0, 0, 0, 0 );
3024 GetUpdateRgn( msg
->hwnd
, hrgn
, TRUE
);
3025 DeleteObject( hrgn
);
3031 /***********************************************************************
3032 * GetMessagePos (USER.119)
3033 * GetMessagePos (USER32.@)
3035 * The GetMessagePos() function returns a long value representing a
3036 * cursor position, in screen coordinates, when the last message
3037 * retrieved by the GetMessage() function occurs. The x-coordinate is
3038 * in the low-order word of the return value, the y-coordinate is in
3039 * the high-order word. The application can use the MAKEPOINT()
3040 * macro to obtain a POINT structure from the return value.
3042 * For the current cursor position, use GetCursorPos().
3046 * Cursor position of last message on success, zero on failure.
3053 DWORD WINAPI
GetMessagePos(void)
3055 return get_user_thread_info()->GetMessagePosVal
;
3059 /***********************************************************************
3060 * GetMessageTime (USER.120)
3061 * GetMessageTime (USER32.@)
3063 * GetMessageTime() returns the message time for the last message
3064 * retrieved by the function. The time is measured in milliseconds with
3065 * the same offset as GetTickCount().
3067 * Since the tick count wraps, this is only useful for moderately short
3068 * relative time comparisons.
3072 * Time of last message on success, zero on failure.
3074 LONG WINAPI
GetMessageTime(void)
3076 return get_user_thread_info()->GetMessageTimeVal
;
3080 /***********************************************************************
3081 * GetMessageExtraInfo (USER.288)
3082 * GetMessageExtraInfo (USER32.@)
3084 LPARAM WINAPI
GetMessageExtraInfo(void)
3086 return get_user_thread_info()->GetMessageExtraInfoVal
;
3090 /***********************************************************************
3091 * SetMessageExtraInfo (USER32.@)
3093 LPARAM WINAPI
SetMessageExtraInfo(LPARAM lParam
)
3095 struct user_thread_info
*thread_info
= get_user_thread_info();
3096 LONG old_value
= thread_info
->GetMessageExtraInfoVal
;
3097 thread_info
->GetMessageExtraInfoVal
= lParam
;
3102 /***********************************************************************
3103 * WaitMessage (USER.112) Suspend thread pending messages
3104 * WaitMessage (USER32.@) Suspend thread pending messages
3106 * WaitMessage() suspends a thread until events appear in the thread's
3109 BOOL WINAPI
WaitMessage(void)
3111 return (MsgWaitForMultipleObjectsEx( 0, NULL
, INFINITE
, QS_ALLINPUT
, 0 ) != WAIT_FAILED
);
3115 /***********************************************************************
3116 * MsgWaitForMultipleObjectsEx (USER32.@)
3118 DWORD WINAPI
MsgWaitForMultipleObjectsEx( DWORD count
, CONST HANDLE
*pHandles
,
3119 DWORD timeout
, DWORD mask
, DWORD flags
)
3121 HANDLE handles
[MAXIMUM_WAIT_OBJECTS
];
3124 if (count
> MAXIMUM_WAIT_OBJECTS
-1)
3126 SetLastError( ERROR_INVALID_PARAMETER
);
3130 /* set the queue mask */
3131 SERVER_START_REQ( set_queue_mask
)
3133 req
->wake_mask
= (flags
& MWMO_INPUTAVAILABLE
) ? mask
: 0;
3134 req
->changed_mask
= mask
;
3136 wine_server_call( req
);
3140 /* Add the thread event to the handle list */
3141 for (i
= 0; i
< count
; i
++) handles
[i
] = pHandles
[i
];
3142 handles
[count
] = get_server_queue_handle();
3144 ReleaseThunkLock( &lock
);
3145 ret
= USER_Driver
->pMsgWaitForMultipleObjectsEx( count
+1, handles
, timeout
, mask
, flags
);
3146 if (ret
== count
+1) ret
= count
; /* pretend the msg queue is ready */
3147 if (lock
) RestoreThunkLock( lock
);
3152 /***********************************************************************
3153 * MsgWaitForMultipleObjects (USER32.@)
3155 DWORD WINAPI
MsgWaitForMultipleObjects( DWORD count
, CONST HANDLE
*handles
,
3156 BOOL wait_all
, DWORD timeout
, DWORD mask
)
3158 return MsgWaitForMultipleObjectsEx( count
, handles
, timeout
, mask
,
3159 wait_all
? MWMO_WAITALL
: 0 );
3163 /***********************************************************************
3164 * WaitForInputIdle (USER32.@)
3166 DWORD WINAPI
WaitForInputIdle( HANDLE hProcess
, DWORD dwTimeOut
)
3168 DWORD start_time
, elapsed
, ret
;
3169 HANDLE idle_event
= (HANDLE
)-1;
3171 SERVER_START_REQ( wait_input_idle
)
3173 req
->handle
= hProcess
;
3174 req
->timeout
= dwTimeOut
;
3175 if (!(ret
= wine_server_call_err( req
))) idle_event
= reply
->event
;
3178 if (ret
) return WAIT_FAILED
; /* error */
3179 if (!idle_event
) return 0; /* no event to wait on */
3181 start_time
= GetTickCount();
3184 TRACE("waiting for %p\n", idle_event
);
3187 ret
= MsgWaitForMultipleObjects ( 1, &idle_event
, FALSE
, dwTimeOut
- elapsed
, QS_SENDMESSAGE
);
3190 case WAIT_OBJECT_0
+1:
3191 process_sent_messages();
3195 TRACE("timeout or error\n");
3198 TRACE("finished\n");
3201 if (dwTimeOut
!= INFINITE
)
3203 elapsed
= GetTickCount() - start_time
;
3204 if (elapsed
> dwTimeOut
)
3210 return WAIT_TIMEOUT
;
3214 /***********************************************************************
3215 * UserYield (USER.332)
3217 void WINAPI
UserYield16(void)
3221 /* Handle sent messages */
3222 process_sent_messages();
3225 ReleaseThunkLock(&count
);
3229 RestoreThunkLock(count
);
3230 /* Handle sent messages again */
3231 process_sent_messages();
3236 /***********************************************************************
3237 * RegisterWindowMessageA (USER32.@)
3238 * RegisterWindowMessage (USER.118)
3240 UINT WINAPI
RegisterWindowMessageA( LPCSTR str
)
3242 UINT ret
= GlobalAddAtomA(str
);
3243 TRACE("%s, ret=%x\n", str
, ret
);
3248 /***********************************************************************
3249 * RegisterWindowMessageW (USER32.@)
3251 UINT WINAPI
RegisterWindowMessageW( LPCWSTR str
)
3253 UINT ret
= GlobalAddAtomW(str
);
3254 TRACE("%s ret=%x\n", debugstr_w(str
), ret
);
3259 /***********************************************************************
3260 * BroadcastSystemMessageA (USER32.@)
3261 * BroadcastSystemMessage (USER32.@)
3263 LONG WINAPI
BroadcastSystemMessageA( DWORD flags
, LPDWORD recipients
, UINT msg
, WPARAM wp
, LPARAM lp
)
3265 if ((*recipients
& BSM_APPLICATIONS
) || (*recipients
== BSM_ALLCOMPONENTS
))
3267 FIXME( "(%08lx,%08lx,%08x,%08x,%08lx): semi-stub!\n", flags
, *recipients
, msg
, wp
, lp
);
3268 PostMessageA( HWND_BROADCAST
, msg
, wp
, lp
);
3273 FIXME( "(%08lx,%08lx,%08x,%08x,%08lx): stub!\n", flags
, *recipients
, msg
, wp
, lp
);
3279 /***********************************************************************
3280 * BroadcastSystemMessageW (USER32.@)
3282 LONG WINAPI
BroadcastSystemMessageW( DWORD flags
, LPDWORD recipients
, UINT msg
, WPARAM wp
, LPARAM lp
)
3284 if ((*recipients
& BSM_APPLICATIONS
) || (*recipients
== BSM_ALLCOMPONENTS
))
3286 FIXME( "(%08lx,%08lx,%08x,%08x,%08lx): semi-stub!\n", flags
, *recipients
, msg
, wp
, lp
);
3287 PostMessageW( HWND_BROADCAST
, msg
, wp
, lp
);
3292 FIXME( "(%08lx,%08lx,%08x,%08x,%08lx): stub!\n", flags
, *recipients
, msg
, wp
, lp
);
3298 /***********************************************************************
3299 * SetMessageQueue (USER32.@)
3301 BOOL WINAPI
SetMessageQueue( INT size
)
3303 /* now obsolete the message queue will be expanded dynamically as necessary */
3308 /***********************************************************************
3309 * MessageBeep (USER32.@)
3311 BOOL WINAPI
MessageBeep( UINT i
)
3314 SystemParametersInfoA( SPI_GETBEEP
, 0, &active
, FALSE
);
3315 if (active
) USER_Driver
->pBeep();
3320 /***********************************************************************
3321 * SetTimer (USER32.@)
3323 UINT_PTR WINAPI
SetTimer( HWND hwnd
, UINT_PTR id
, UINT timeout
, TIMERPROC proc
)
3326 WNDPROC winproc
= 0;
3328 if (proc
) winproc
= WINPROC_AllocProc( (WNDPROC
)proc
, WIN_PROC_32A
);
3330 SERVER_START_REQ( set_win_timer
)
3333 req
->msg
= WM_TIMER
;
3335 req
->rate
= max( timeout
, SYS_TIMER_RATE
);
3336 req
->lparam
= (unsigned int)winproc
;
3337 if (!wine_server_call_err( req
))
3340 if (!ret
) ret
= TRUE
;
3346 TRACE("Added %p %x %p timeout %d\n", hwnd
, id
, winproc
, timeout
);
3351 /***********************************************************************
3352 * SetSystemTimer (USER32.@)
3354 UINT_PTR WINAPI
SetSystemTimer( HWND hwnd
, UINT_PTR id
, UINT timeout
, TIMERPROC proc
)
3357 WNDPROC winproc
= 0;
3359 if (proc
) winproc
= WINPROC_AllocProc( (WNDPROC
)proc
, WIN_PROC_32A
);
3361 SERVER_START_REQ( set_win_timer
)
3364 req
->msg
= WM_SYSTIMER
;
3366 req
->rate
= max( timeout
, SYS_TIMER_RATE
);
3367 req
->lparam
= (unsigned int)winproc
;
3368 if (!wine_server_call_err( req
))
3371 if (!ret
) ret
= TRUE
;
3377 TRACE("Added %p %x %p timeout %d\n", hwnd
, id
, winproc
, timeout
);
3382 /***********************************************************************
3383 * KillTimer (USER32.@)
3385 BOOL WINAPI
KillTimer( HWND hwnd
, UINT_PTR id
)
3389 TRACE("%p %d\n", hwnd
, id
);
3391 SERVER_START_REQ( kill_win_timer
)
3394 req
->msg
= WM_TIMER
;
3396 ret
= !wine_server_call_err( req
);
3403 /***********************************************************************
3404 * KillSystemTimer (USER32.@)
3406 BOOL WINAPI
KillSystemTimer( HWND hwnd
, UINT_PTR id
)
3410 TRACE("%p %d\n", hwnd
, id
);
3412 SERVER_START_REQ( kill_win_timer
)
3415 req
->msg
= WM_SYSTIMER
;
3417 ret
= !wine_server_call_err( req
);
3424 /**********************************************************************
3425 * GetGUIThreadInfo (USER32.@)
3427 BOOL WINAPI
GetGUIThreadInfo( DWORD id
, GUITHREADINFO
*info
)
3431 SERVER_START_REQ( get_thread_input
)
3434 if ((ret
= !wine_server_call_err( req
)))
3437 info
->hwndActive
= reply
->active
;
3438 info
->hwndFocus
= reply
->focus
;
3439 info
->hwndCapture
= reply
->capture
;
3440 info
->hwndMenuOwner
= reply
->menu_owner
;
3441 info
->hwndMoveSize
= reply
->move_size
;
3442 info
->hwndCaret
= reply
->caret
;
3443 info
->rcCaret
.left
= reply
->rect
.left
;
3444 info
->rcCaret
.top
= reply
->rect
.top
;
3445 info
->rcCaret
.right
= reply
->rect
.right
;
3446 info
->rcCaret
.bottom
= reply
->rect
.bottom
;
3447 if (reply
->menu_owner
) info
->flags
|= GUI_INMENUMODE
;
3448 if (reply
->move_size
) info
->flags
|= GUI_INMOVESIZE
;
3449 if (reply
->caret
) info
->flags
|= GUI_CARETBLINKING
;
3457 /******************************************************************
3458 * IsHungAppWindow (USER32.@)
3461 BOOL WINAPI
IsHungAppWindow( HWND hWnd
)
3464 return !SendMessageTimeoutA(hWnd
, WM_NULL
, 0, 0, SMTO_ABORTIFHUNG
, 5000, &dwResult
);