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
)
1159 case WM_WINE_DESTROYWINDOW
:
1160 return WIN_DestroyWindow( hwnd
);
1161 case WM_WINE_SETWINDOWPOS
:
1162 if (hwnd
== GetDesktopWindow()) return 0;
1163 return USER_Driver
->pSetWindowPos( (WINDOWPOS
*)lparam
);
1164 case WM_WINE_SHOWWINDOW
:
1165 if (hwnd
== GetDesktopWindow()) return 0;
1166 return ShowWindow( hwnd
, wparam
);
1167 case WM_WINE_SETPARENT
:
1168 if (hwnd
== GetDesktopWindow()) return 0;
1169 return (LRESULT
)SetParent( hwnd
, (HWND
)wparam
);
1170 case WM_WINE_SETWINDOWLONG
:
1171 return (LRESULT
)SetWindowLongW( hwnd
, wparam
, lparam
);
1172 case WM_WINE_ENABLEWINDOW
:
1173 if (hwnd
== GetDesktopWindow()) return 0;
1174 return EnableWindow( hwnd
, wparam
);
1175 case WM_WINE_SETACTIVEWINDOW
:
1176 if (hwnd
== GetDesktopWindow()) return 0;
1177 return (LRESULT
)SetActiveWindow( (HWND
)wparam
);
1178 case WM_WINE_KEYBOARD_LL_HOOK
:
1179 return HOOK_CallHooks( WH_KEYBOARD_LL
, HC_ACTION
, wparam
, lparam
, TRUE
);
1180 case WM_WINE_MOUSE_LL_HOOK
:
1181 return HOOK_CallHooks( WH_MOUSE_LL
, HC_ACTION
, wparam
, lparam
, TRUE
);
1183 if (msg
>= WM_WINE_FIRST_DRIVER_MSG
&& msg
<= WM_WINE_LAST_DRIVER_MSG
)
1184 return USER_Driver
->pWindowMessage( hwnd
, msg
, wparam
, lparam
);
1185 FIXME( "unknown internal message %x\n", msg
);
1190 /* since the WM_DDE_ACK response to a WM_DDE_EXECUTE message should contain the handle
1191 * to the memory handle, we keep track (in the server side) of all pairs of handle
1192 * used (the client passes its value and the content of the memory handle), and
1193 * the server stored both values (the client, and the local one, created after the
1194 * content). When a ACK message is generated, the list of pair is searched for a
1195 * matching pair, so that the client memory handle can be returned.
1198 HGLOBAL client_hMem
;
1199 HGLOBAL server_hMem
;
1202 static struct DDE_pair
* dde_pairs
;
1203 static int dde_num_alloc
;
1204 static int dde_num_used
;
1206 static CRITICAL_SECTION dde_crst
;
1207 static CRITICAL_SECTION_DEBUG critsect_debug
=
1210 { &critsect_debug
.ProcessLocksList
, &critsect_debug
.ProcessLocksList
},
1211 0, 0, { (DWORD_PTR
)(__FILE__
": dde_crst") }
1213 static CRITICAL_SECTION dde_crst
= { &critsect_debug
, -1, 0, 0, 0, 0 };
1215 static BOOL
dde_add_pair(HGLOBAL chm
, HGLOBAL shm
)
1220 EnterCriticalSection(&dde_crst
);
1222 /* now remember the pair of hMem on both sides */
1223 if (dde_num_used
== dde_num_alloc
)
1225 struct DDE_pair
* tmp
;
1227 tmp
= HeapReAlloc( GetProcessHeap(), 0, dde_pairs
,
1228 (dde_num_alloc
+ GROWBY
) * sizeof(struct DDE_pair
));
1230 tmp
= HeapAlloc( GetProcessHeap(), 0,
1231 (dde_num_alloc
+ GROWBY
) * sizeof(struct DDE_pair
));
1235 LeaveCriticalSection(&dde_crst
);
1239 /* zero out newly allocated part */
1240 memset(&dde_pairs
[dde_num_alloc
], 0, GROWBY
* sizeof(struct DDE_pair
));
1241 dde_num_alloc
+= GROWBY
;
1244 for (i
= 0; i
< dde_num_alloc
; i
++)
1246 if (dde_pairs
[i
].server_hMem
== 0)
1248 dde_pairs
[i
].client_hMem
= chm
;
1249 dde_pairs
[i
].server_hMem
= shm
;
1254 LeaveCriticalSection(&dde_crst
);
1258 static HGLOBAL
dde_get_pair(HGLOBAL shm
)
1263 EnterCriticalSection(&dde_crst
);
1264 for (i
= 0; i
< dde_num_alloc
; i
++)
1266 if (dde_pairs
[i
].server_hMem
== shm
)
1268 /* free this pair */
1269 dde_pairs
[i
].server_hMem
= 0;
1271 ret
= dde_pairs
[i
].client_hMem
;
1275 LeaveCriticalSection(&dde_crst
);
1279 /***********************************************************************
1282 * Post a DDE message
1284 static BOOL
post_dde_message( DWORD dest_tid
, struct packed_message
*data
, const struct send_message_info
*info
)
1288 UINT_PTR uiLo
, uiHi
;
1290 HGLOBAL hunlock
= 0;
1294 if (!UnpackDDElParam( info
->msg
, info
->lparam
, &uiLo
, &uiHi
))
1300 /* DDE messages which don't require packing are:
1309 /* uiHi should contain a hMem from WM_DDE_EXECUTE */
1310 HGLOBAL h
= dde_get_pair( (HANDLE
)uiHi
);
1313 /* send back the value of h on the other side */
1314 push_data( data
, &h
, sizeof(HGLOBAL
) );
1316 TRACE( "send dde-ack %x %08x => %p\n", uiLo
, uiHi
, h
);
1321 /* uiHi should contain either an atom or 0 */
1322 TRACE( "send dde-ack %x atom=%x\n", uiLo
, uiHi
);
1323 lp
= MAKELONG( uiLo
, uiHi
);
1332 size
= GlobalSize( (HGLOBAL
)uiLo
) ;
1333 if ((info
->msg
== WM_DDE_ADVISE
&& size
< sizeof(DDEADVISE
)) ||
1334 (info
->msg
== WM_DDE_DATA
&& size
< sizeof(DDEDATA
)) ||
1335 (info
->msg
== WM_DDE_POKE
&& size
< sizeof(DDEPOKE
))
1339 else if (info
->msg
!= WM_DDE_DATA
) return FALSE
;
1344 if ((ptr
= GlobalLock( (HGLOBAL
)uiLo
) ))
1346 DDEDATA
*dde_data
= (DDEDATA
*)ptr
;
1347 TRACE("unused %d, fResponse %d, fRelease %d, fDeferUpd %d, fAckReq %d, cfFormat %d\n",
1348 dde_data
->unused
, dde_data
->fResponse
, dde_data
->fRelease
,
1349 dde_data
->reserved
, dde_data
->fAckReq
, dde_data
->cfFormat
);
1350 push_data( data
, ptr
, size
);
1351 hunlock
= (HGLOBAL
)uiLo
;
1354 TRACE( "send ddepack %u %x\n", size
, uiHi
);
1356 case WM_DDE_EXECUTE
:
1359 if ((ptr
= GlobalLock( (HGLOBAL
)info
->lparam
) ))
1361 push_data(data
, ptr
, GlobalSize( (HGLOBAL
)info
->lparam
));
1362 /* so that the other side can send it back on ACK */
1364 hunlock
= (HGLOBAL
)info
->lparam
;
1369 SERVER_START_REQ( send_message
)
1372 req
->type
= info
->type
;
1374 req
->win
= info
->hwnd
;
1375 req
->msg
= info
->msg
;
1376 req
->wparam
= info
->wparam
;
1378 req
->time
= GetCurrentTime();
1380 for (i
= 0; i
< data
->count
; i
++)
1381 wine_server_add_data( req
, data
->data
[i
], data
->size
[i
] );
1382 if ((res
= wine_server_call( req
)))
1384 if (res
== STATUS_INVALID_PARAMETER
)
1385 /* FIXME: find a STATUS_ value for this one */
1386 SetLastError( ERROR_INVALID_THREAD_ID
);
1388 SetLastError( RtlNtStatusToDosError(res
) );
1391 FreeDDElParam(info
->msg
, info
->lparam
);
1394 if (hunlock
) GlobalUnlock(hunlock
);
1399 /***********************************************************************
1400 * unpack_dde_message
1402 * Unpack a posted DDE message received from another process.
1404 static BOOL
unpack_dde_message( HWND hwnd
, UINT message
, WPARAM
*wparam
, LPARAM
*lparam
,
1405 void **buffer
, size_t size
)
1407 UINT_PTR uiLo
, uiHi
;
1416 /* hMem is being passed */
1417 if (size
!= sizeof(HGLOBAL
)) return FALSE
;
1418 if (!buffer
|| !*buffer
) return FALSE
;
1420 memcpy( &hMem
, *buffer
, size
);
1421 uiHi
= (UINT_PTR
)hMem
;
1422 TRACE("recv dde-ack %x mem=%x[%lx]\n", uiLo
, uiHi
, GlobalSize( hMem
));
1426 uiLo
= LOWORD( *lparam
);
1427 uiHi
= HIWORD( *lparam
);
1428 TRACE("recv dde-ack %x atom=%x\n", uiLo
, uiHi
);
1430 *lparam
= PackDDElParam( WM_DDE_ACK
, uiLo
, uiHi
);
1435 if ((!buffer
|| !*buffer
) && message
!= WM_DDE_DATA
) return FALSE
;
1437 TRACE( "recv ddepack %u %x\n", size
, uiHi
);
1440 if (!(hMem
= GlobalAlloc( GMEM_MOVEABLE
|GMEM_DDESHARE
, size
)))
1442 if ((ptr
= GlobalLock( hMem
)))
1444 memcpy( ptr
, *buffer
, size
);
1445 GlobalUnlock( hMem
);
1453 uiLo
= (UINT_PTR
)hMem
;
1455 *lparam
= PackDDElParam( message
, uiLo
, uiHi
);
1457 case WM_DDE_EXECUTE
:
1460 if (!buffer
|| !*buffer
) return FALSE
;
1461 if (!(hMem
= GlobalAlloc( GMEM_MOVEABLE
|GMEM_DDESHARE
, size
))) return FALSE
;
1462 if ((ptr
= GlobalLock( hMem
)))
1464 memcpy( ptr
, *buffer
, size
);
1465 GlobalUnlock( hMem
);
1466 TRACE( "exec: pairing c=%08lx s=%08lx\n", *lparam
, (DWORD
)hMem
);
1467 if (!dde_add_pair( (HGLOBAL
)*lparam
, hMem
))
1478 } else return FALSE
;
1479 *lparam
= (LPARAM
)hMem
;
1485 /***********************************************************************
1488 * Call a window procedure and the corresponding hooks.
1490 static LRESULT
call_window_proc( HWND hwnd
, UINT msg
, WPARAM wparam
, LPARAM lparam
,
1491 BOOL unicode
, BOOL same_thread
)
1493 struct user_thread_info
*thread_info
= get_user_thread_info();
1497 CWPRETSTRUCT cwpret
;
1499 if (thread_info
->recursion_count
> MAX_SENDMSG_RECURSION
) return 0;
1500 thread_info
->recursion_count
++;
1502 if (msg
& 0x80000000)
1504 result
= handle_internal_message( hwnd
, msg
, wparam
, lparam
);
1508 /* first the WH_CALLWNDPROC hook */
1509 hwnd
= WIN_GetFullHandle( hwnd
);
1510 cwp
.lParam
= lparam
;
1511 cwp
.wParam
= wparam
;
1514 HOOK_CallHooks( WH_CALLWNDPROC
, HC_ACTION
, same_thread
, (LPARAM
)&cwp
, unicode
);
1516 /* now call the window procedure */
1519 if (!(winproc
= (WNDPROC
)GetWindowLongPtrW( hwnd
, GWLP_WNDPROC
))) goto done
;
1520 result
= CallWindowProcW( winproc
, hwnd
, msg
, wparam
, lparam
);
1524 if (!(winproc
= (WNDPROC
)GetWindowLongPtrA( hwnd
, GWLP_WNDPROC
))) goto done
;
1525 result
= CallWindowProcA( winproc
, hwnd
, msg
, wparam
, lparam
);
1528 /* and finally the WH_CALLWNDPROCRET hook */
1529 cwpret
.lResult
= result
;
1530 cwpret
.lParam
= lparam
;
1531 cwpret
.wParam
= wparam
;
1532 cwpret
.message
= msg
;
1534 HOOK_CallHooks( WH_CALLWNDPROCRET
, HC_ACTION
, same_thread
, (LPARAM
)&cwpret
, unicode
);
1536 thread_info
->recursion_count
--;
1541 /***********************************************************************
1542 * send_parent_notify
1544 * Send a WM_PARENTNOTIFY to all ancestors of the given window, unless
1545 * the window has the WS_EX_NOPARENTNOTIFY style.
1547 static void send_parent_notify( HWND hwnd
, WORD event
, WORD idChild
, POINT pt
)
1549 /* pt has to be in the client coordinates of the parent window */
1550 MapWindowPoints( 0, hwnd
, &pt
, 1 );
1555 if (!(GetWindowLongW( hwnd
, GWL_STYLE
) & WS_CHILD
)) break;
1556 if (GetWindowLongW( hwnd
, GWL_EXSTYLE
) & WS_EX_NOPARENTNOTIFY
) break;
1557 if (!(parent
= GetParent(hwnd
))) break;
1558 MapWindowPoints( hwnd
, parent
, &pt
, 1 );
1560 SendMessageW( hwnd
, WM_PARENTNOTIFY
,
1561 MAKEWPARAM( event
, idChild
), MAKELPARAM( pt
.x
, pt
.y
) );
1566 /***********************************************************************
1567 * accept_hardware_message
1569 * Tell the server we have passed the message to the app
1570 * (even though we may end up dropping it later on)
1572 static void accept_hardware_message( UINT hw_id
, BOOL remove
, HWND new_hwnd
)
1574 SERVER_START_REQ( accept_hardware_message
)
1577 req
->remove
= remove
;
1578 req
->new_win
= new_hwnd
;
1579 if (wine_server_call( req
))
1580 FIXME("Failed to reply to MSG_HARDWARE message. Message may not be removed from queue.\n");
1586 /***********************************************************************
1587 * process_keyboard_message
1589 * returns TRUE if the contents of 'msg' should be passed to the application
1591 static BOOL
process_keyboard_message( MSG
*msg
, UINT hw_id
, HWND hwnd_filter
,
1592 UINT first
, UINT last
, BOOL remove
)
1596 /* FIXME: is this really the right place for this hook? */
1597 event
.message
= msg
->message
;
1598 event
.hwnd
= msg
->hwnd
;
1599 event
.time
= msg
->time
;
1600 event
.paramL
= (msg
->wParam
& 0xFF) | (HIWORD(msg
->lParam
) << 8);
1601 event
.paramH
= msg
->lParam
& 0x7FFF;
1602 if (HIWORD(msg
->lParam
) & 0x0100) event
.paramH
|= 0x8000; /* special_key - bit */
1603 HOOK_CallHooks( WH_JOURNALRECORD
, HC_ACTION
, 0, (LPARAM
)&event
, TRUE
);
1605 /* check message filters */
1606 if (msg
->message
< first
|| msg
->message
> last
) return FALSE
;
1607 if (!check_hwnd_filter( msg
, hwnd_filter
)) return FALSE
;
1611 /* Handle F1 key by sending out WM_HELP message */
1612 if ((msg
->message
== WM_KEYUP
) &&
1613 (msg
->wParam
== VK_F1
) &&
1614 (msg
->hwnd
!= GetDesktopWindow()) &&
1615 !MENU_IsMenuActive())
1618 hi
.cbSize
= sizeof(HELPINFO
);
1619 hi
.iContextType
= HELPINFO_WINDOW
;
1620 hi
.iCtrlId
= GetWindowLongPtrA( msg
->hwnd
, GWLP_ID
);
1621 hi
.hItemHandle
= msg
->hwnd
;
1622 hi
.dwContextId
= GetWindowContextHelpId( msg
->hwnd
);
1623 hi
.MousePos
= msg
->pt
;
1624 SendMessageW( msg
->hwnd
, WM_HELP
, 0, (LPARAM
)&hi
);
1628 if (HOOK_CallHooks( WH_KEYBOARD
, remove
? HC_ACTION
: HC_NOREMOVE
,
1629 LOWORD(msg
->wParam
), msg
->lParam
, TRUE
))
1631 /* skip this message */
1632 HOOK_CallHooks( WH_CBT
, HCBT_KEYSKIPPED
, LOWORD(msg
->wParam
), msg
->lParam
, TRUE
);
1633 accept_hardware_message( hw_id
, TRUE
, 0 );
1636 accept_hardware_message( hw_id
, remove
, 0 );
1641 /***********************************************************************
1642 * process_mouse_message
1644 * returns TRUE if the contents of 'msg' should be passed to the application
1646 static BOOL
process_mouse_message( MSG
*msg
, UINT hw_id
, ULONG_PTR extra_info
, HWND hwnd_filter
,
1647 UINT first
, UINT last
, BOOL remove
)
1656 MOUSEHOOKSTRUCT hook
;
1659 /* find the window to dispatch this mouse message to */
1661 GetGUIThreadInfo( GetCurrentThreadId(), &info
);
1662 if (info
.hwndCapture
)
1665 msg
->hwnd
= info
.hwndCapture
;
1669 msg
->hwnd
= WINPOS_WindowFromPoint( msg
->hwnd
, msg
->pt
, &hittest
);
1672 if (!msg
->hwnd
|| !WIN_IsCurrentThread( msg
->hwnd
))
1674 accept_hardware_message( hw_id
, TRUE
, msg
->hwnd
);
1678 /* FIXME: is this really the right place for this hook? */
1679 event
.message
= msg
->message
;
1680 event
.time
= msg
->time
;
1681 event
.hwnd
= msg
->hwnd
;
1682 event
.paramL
= msg
->pt
.x
;
1683 event
.paramH
= msg
->pt
.y
;
1684 HOOK_CallHooks( WH_JOURNALRECORD
, HC_ACTION
, 0, (LPARAM
)&event
, TRUE
);
1686 if (!check_hwnd_filter( msg
, hwnd_filter
)) return FALSE
;
1689 message
= msg
->message
;
1690 /* Note: windows has no concept of a non-client wheel message */
1691 if (message
!= WM_MOUSEWHEEL
)
1693 if (hittest
!= HTCLIENT
)
1695 message
+= WM_NCMOUSEMOVE
- WM_MOUSEMOVE
;
1696 msg
->wParam
= hittest
;
1700 /* coordinates don't get translated while tracking a menu */
1701 /* FIXME: should differentiate popups and top-level menus */
1702 if (!(info
.flags
& GUI_INMENUMODE
))
1703 ScreenToClient( msg
->hwnd
, &pt
);
1706 msg
->lParam
= MAKELONG( pt
.x
, pt
.y
);
1708 /* translate double clicks */
1710 if ((msg
->message
== WM_LBUTTONDOWN
) ||
1711 (msg
->message
== WM_RBUTTONDOWN
) ||
1712 (msg
->message
== WM_MBUTTONDOWN
) ||
1713 (msg
->message
== WM_XBUTTONDOWN
))
1715 BOOL update
= remove
;
1717 /* translate double clicks -
1718 * note that ...MOUSEMOVEs can slip in between
1719 * ...BUTTONDOWN and ...BUTTONDBLCLK messages */
1721 if ((info
.flags
& (GUI_INMENUMODE
|GUI_INMOVESIZE
)) ||
1722 hittest
!= HTCLIENT
||
1723 (GetClassLongA( msg
->hwnd
, GCL_STYLE
) & CS_DBLCLKS
))
1725 if ((msg
->message
== clk_msg
.message
) &&
1726 (msg
->hwnd
== clk_msg
.hwnd
) &&
1727 (msg
->wParam
== clk_msg
.wParam
) &&
1728 (msg
->time
- clk_msg
.time
< GetDoubleClickTime()) &&
1729 (abs(msg
->pt
.x
- clk_msg
.pt
.x
) < GetSystemMetrics(SM_CXDOUBLECLK
)/2) &&
1730 (abs(msg
->pt
.y
- clk_msg
.pt
.y
) < GetSystemMetrics(SM_CYDOUBLECLK
)/2))
1732 message
+= (WM_LBUTTONDBLCLK
- WM_LBUTTONDOWN
);
1735 clk_msg
.message
= 0; /* clear the double click conditions */
1740 if (message
< first
|| message
> last
) return FALSE
;
1741 /* update static double click conditions */
1742 if (update
) clk_msg
= *msg
;
1746 if (message
< first
|| message
> last
) return FALSE
;
1749 /* message is accepted now (but may still get dropped) */
1752 hook
.hwnd
= msg
->hwnd
;
1753 hook
.wHitTestCode
= hittest
;
1754 hook
.dwExtraInfo
= extra_info
;
1755 if (HOOK_CallHooks( WH_MOUSE
, remove
? HC_ACTION
: HC_NOREMOVE
,
1756 message
, (LPARAM
)&hook
, TRUE
))
1759 hook
.hwnd
= msg
->hwnd
;
1760 hook
.wHitTestCode
= hittest
;
1761 hook
.dwExtraInfo
= extra_info
;
1762 HOOK_CallHooks( WH_CBT
, HCBT_CLICKSKIPPED
, message
, (LPARAM
)&hook
, TRUE
);
1763 accept_hardware_message( hw_id
, TRUE
, 0 );
1767 if ((hittest
== HTERROR
) || (hittest
== HTNOWHERE
))
1769 SendMessageW( msg
->hwnd
, WM_SETCURSOR
, (WPARAM
)msg
->hwnd
,
1770 MAKELONG( hittest
, msg
->message
));
1771 accept_hardware_message( hw_id
, TRUE
, 0 );
1775 accept_hardware_message( hw_id
, remove
, 0 );
1777 if (!remove
|| info
.hwndCapture
)
1779 msg
->message
= message
;
1785 if ((msg
->message
== WM_LBUTTONDOWN
) ||
1786 (msg
->message
== WM_RBUTTONDOWN
) ||
1787 (msg
->message
== WM_MBUTTONDOWN
) ||
1788 (msg
->message
== WM_XBUTTONDOWN
))
1790 /* Send the WM_PARENTNOTIFY,
1791 * note that even for double/nonclient clicks
1792 * notification message is still WM_L/M/RBUTTONDOWN.
1794 send_parent_notify( msg
->hwnd
, msg
->message
, 0, msg
->pt
);
1796 /* Activate the window if needed */
1798 if (msg
->hwnd
!= info
.hwndActive
)
1800 HWND hwndTop
= msg
->hwnd
;
1803 if ((GetWindowLongW( hwndTop
, GWL_STYLE
) & (WS_POPUP
|WS_CHILD
)) != WS_CHILD
) break;
1804 hwndTop
= GetParent( hwndTop
);
1807 if (hwndTop
&& hwndTop
!= GetDesktopWindow())
1809 LONG ret
= SendMessageW( msg
->hwnd
, WM_MOUSEACTIVATE
, (WPARAM
)hwndTop
,
1810 MAKELONG( hittest
, msg
->message
) );
1813 case MA_NOACTIVATEANDEAT
:
1818 case MA_ACTIVATEANDEAT
:
1823 if (!FOCUS_MouseActivate( hwndTop
)) eatMsg
= TRUE
;
1826 WARN( "unknown WM_MOUSEACTIVATE code %ld\n", ret
);
1833 /* send the WM_SETCURSOR message */
1835 /* Windows sends the normal mouse message as the message parameter
1836 in the WM_SETCURSOR message even if it's non-client mouse message */
1837 SendMessageW( msg
->hwnd
, WM_SETCURSOR
, (WPARAM
)msg
->hwnd
, MAKELONG( hittest
, msg
->message
));
1839 msg
->message
= message
;
1844 /***********************************************************************
1845 * process_hardware_message
1847 * Process a hardware message; return TRUE if message should be passed on to the app
1849 static BOOL
process_hardware_message( MSG
*msg
, UINT hw_id
, ULONG_PTR extra_info
, HWND hwnd_filter
,
1850 UINT first
, UINT last
, BOOL remove
)
1852 if (is_keyboard_message( msg
->message
))
1853 return process_keyboard_message( msg
, hw_id
, hwnd_filter
, first
, last
, remove
);
1855 if (is_mouse_message( msg
->message
))
1856 return process_mouse_message( msg
, hw_id
, extra_info
, hwnd_filter
, first
, last
, remove
);
1858 ERR( "unknown message type %x\n", msg
->message
);
1863 /***********************************************************************
1864 * call_sendmsg_callback
1866 * Call the callback function of SendMessageCallback.
1868 static inline void call_sendmsg_callback( SENDASYNCPROC callback
, HWND hwnd
, UINT msg
,
1869 ULONG_PTR data
, LRESULT result
)
1871 if (TRACE_ON(relay
))
1872 DPRINTF( "%04lx:Call message callback %p (hwnd=%p,msg=%s,data=%08lx,result=%08lx)\n",
1873 GetCurrentThreadId(), callback
, hwnd
, SPY_GetMsgName( msg
, hwnd
),
1875 callback( hwnd
, msg
, data
, result
);
1876 if (TRACE_ON(relay
))
1877 DPRINTF( "%04lx:Ret message callback %p (hwnd=%p,msg=%s,data=%08lx,result=%08lx)\n",
1878 GetCurrentThreadId(), callback
, hwnd
, SPY_GetMsgName( msg
, hwnd
),
1883 /***********************************************************************
1886 * Retrieve the hook procedure real value for a module-relative proc
1888 static void *get_hook_proc( void *proc
, const WCHAR
*module
)
1892 if (!(mod
= GetModuleHandleW(module
)))
1894 TRACE( "loading %s\n", debugstr_w(module
) );
1895 /* FIXME: the library will never be freed */
1896 if (!(mod
= LoadLibraryW(module
))) return NULL
;
1898 return (char *)mod
+ (ULONG_PTR
)proc
;
1902 /***********************************************************************
1905 * Peek for a message matching the given parameters. Return FALSE if none available.
1906 * All pending sent messages are processed before returning.
1908 static BOOL
peek_message( MSG
*msg
, HWND hwnd
, UINT first
, UINT last
, int flags
)
1911 ULONG_PTR extra_info
= 0;
1912 struct user_thread_info
*thread_info
= get_user_thread_info();
1913 struct received_message_info info
, *old_info
;
1914 unsigned int hw_id
= 0; /* id of previous hardware message */
1916 if (!first
&& !last
) last
= ~0;
1921 void *buffer
= NULL
;
1922 size_t size
= 0, buffer_size
= 0;
1924 do /* loop while buffer is too small */
1926 if (buffer_size
&& !(buffer
= HeapAlloc( GetProcessHeap(), 0, buffer_size
)))
1928 SERVER_START_REQ( get_message
)
1931 req
->get_win
= hwnd
;
1932 req
->get_first
= first
;
1933 req
->get_last
= last
;
1935 if (buffer_size
) wine_server_set_reply( req
, buffer
, buffer_size
);
1936 if (!(res
= wine_server_call( req
)))
1938 size
= wine_server_reply_size( reply
);
1939 info
.type
= reply
->type
;
1940 info
.msg
.hwnd
= reply
->win
;
1941 info
.msg
.message
= reply
->msg
;
1942 info
.msg
.wParam
= reply
->wparam
;
1943 info
.msg
.lParam
= reply
->lparam
;
1944 info
.msg
.time
= reply
->time
;
1945 info
.msg
.pt
.x
= reply
->x
;
1946 info
.msg
.pt
.y
= reply
->y
;
1947 info
.hook
= reply
->hook
;
1948 info
.hook_proc
= reply
->hook_proc
;
1949 hw_id
= reply
->hw_id
;
1950 extra_info
= reply
->info
;
1951 thread_info
->active_hooks
= reply
->active_hooks
;
1955 HeapFree( GetProcessHeap(), 0, buffer
);
1956 buffer_size
= reply
->total
;
1960 } while (res
== STATUS_BUFFER_OVERFLOW
);
1962 if (res
) return FALSE
;
1964 TRACE( "got type %d msg %x (%s) hwnd %p wp %x lp %lx\n",
1965 info
.type
, info
.msg
.message
,
1966 (info
.type
== MSG_WINEVENT
) ? "MSG_WINEVENT" : SPY_GetMsgName(info
.msg
.message
, info
.msg
.hwnd
),
1967 info
.msg
.hwnd
, info
.msg
.wParam
, info
.msg
.lParam
);
1973 info
.flags
= ISMEX_SEND
;
1976 info
.flags
= ISMEX_NOTIFY
;
1979 info
.flags
= ISMEX_CALLBACK
;
1981 case MSG_CALLBACK_RESULT
:
1982 call_sendmsg_callback( (SENDASYNCPROC
)info
.msg
.wParam
, info
.msg
.hwnd
,
1983 info
.msg
.message
, extra_info
, info
.msg
.lParam
);
1988 WCHAR module
[MAX_PATH
];
1989 size
= min( size
, (MAX_PATH
- 1) * sizeof(WCHAR
) );
1990 memcpy( module
, buffer
, size
);
1991 module
[size
/ sizeof(WCHAR
)] = 0;
1992 if (!(info
.hook_proc
= get_hook_proc( info
.hook_proc
, module
)))
1994 ERR( "invalid winevent hook module name %s\n", debugstr_w(module
) );
1998 if (TRACE_ON(relay
))
1999 DPRINTF( "%04lx:Call winevent proc %p (hook=%p,event=%x,hwnd=%p,object_id=%x,child_id=%lx,tid=%04lx,time=%lx)\n",
2000 GetCurrentThreadId(), info
.hook_proc
,
2001 info
.hook
, info
.msg
.message
, info
.msg
.hwnd
, info
.msg
.wParam
,
2002 info
.msg
.lParam
, extra_info
, info
.msg
.time
);
2004 info
.hook_proc( info
.hook
, info
.msg
.message
, info
.msg
.hwnd
, info
.msg
.wParam
,
2005 info
.msg
.lParam
, extra_info
, info
.msg
.time
);
2007 if (TRACE_ON(relay
))
2008 DPRINTF( "%04lx:Ret winevent proc %p (hook=%p,event=%x,hwnd=%p,object_id=%x,child_id=%lx,tid=%04lx,time=%lx)\n",
2009 GetCurrentThreadId(), info
.hook_proc
,
2010 info
.hook
, info
.msg
.message
, info
.msg
.hwnd
, info
.msg
.wParam
,
2011 info
.msg
.lParam
, extra_info
, info
.msg
.time
);
2013 case MSG_OTHER_PROCESS
:
2014 info
.flags
= ISMEX_SEND
;
2015 if (!unpack_message( info
.msg
.hwnd
, info
.msg
.message
, &info
.msg
.wParam
,
2016 &info
.msg
.lParam
, &buffer
, size
))
2018 ERR( "invalid packed message %x (%s) hwnd %p wp %x lp %lx size %d\n",
2019 info
.msg
.message
, SPY_GetMsgName(info
.msg
.message
, info
.msg
.hwnd
), info
.msg
.hwnd
,
2020 info
.msg
.wParam
, info
.msg
.lParam
, size
);
2022 reply_message( &info
, 0, TRUE
);
2027 if (!process_hardware_message( &info
.msg
, hw_id
, extra_info
,
2028 hwnd
, first
, last
, flags
& GET_MSG_REMOVE
))
2030 TRACE("dropping msg %x\n", info
.msg
.message
);
2031 goto next
; /* ignore it */
2033 thread_info
->GetMessagePosVal
= MAKELONG( info
.msg
.pt
.x
, info
.msg
.pt
.y
);
2036 thread_info
->GetMessageExtraInfoVal
= extra_info
;
2037 if (info
.msg
.message
>= WM_DDE_FIRST
&& info
.msg
.message
<= WM_DDE_LAST
)
2039 if (!unpack_dde_message( info
.msg
.hwnd
, info
.msg
.message
, &info
.msg
.wParam
,
2040 &info
.msg
.lParam
, &buffer
, size
))
2042 ERR( "invalid packed dde-message %x (%s) hwnd %p wp %x lp %lx size %d\n",
2043 info
.msg
.message
, SPY_GetMsgName(info
.msg
.message
, info
.msg
.hwnd
),
2044 info
.msg
.hwnd
, info
.msg
.wParam
, info
.msg
.lParam
, size
);
2045 goto next
; /* ignore it */
2049 HeapFree( GetProcessHeap(), 0, buffer
);
2053 /* if we get here, we have a sent message; call the window procedure */
2054 old_info
= thread_info
->receive_info
;
2055 thread_info
->receive_info
= &info
;
2056 result
= call_window_proc( info
.msg
.hwnd
, info
.msg
.message
, info
.msg
.wParam
,
2057 info
.msg
.lParam
, (info
.type
!= MSG_ASCII
), FALSE
);
2058 reply_message( &info
, result
, TRUE
);
2059 thread_info
->receive_info
= old_info
;
2061 HeapFree( GetProcessHeap(), 0, buffer
);
2066 /***********************************************************************
2067 * process_sent_messages
2069 * Process all pending sent messages.
2071 inline static void process_sent_messages(void)
2074 peek_message( &msg
, 0, 0, 0, GET_MSG_REMOVE
| GET_MSG_SENT_ONLY
);
2078 /***********************************************************************
2079 * get_server_queue_handle
2081 * Get a handle to the server message queue for the current thread.
2083 static HANDLE
get_server_queue_handle(void)
2085 struct user_thread_info
*thread_info
= get_user_thread_info();
2088 if (!(ret
= thread_info
->server_queue
))
2090 SERVER_START_REQ( get_msg_queue
)
2092 wine_server_call( req
);
2093 ret
= reply
->handle
;
2096 thread_info
->server_queue
= ret
;
2097 if (!ret
) ERR( "Cannot get server thread queue\n" );
2103 /***********************************************************************
2104 * wait_message_reply
2106 * Wait until a sent message gets replied to.
2108 static void wait_message_reply( UINT flags
)
2110 HANDLE server_queue
= get_server_queue_handle();
2114 unsigned int wake_bits
= 0, changed_bits
= 0;
2117 SERVER_START_REQ( set_queue_mask
)
2119 req
->wake_mask
= QS_SMRESULT
| ((flags
& SMTO_BLOCK
) ? 0 : QS_SENDMESSAGE
);
2120 req
->changed_mask
= req
->wake_mask
;
2122 if (!wine_server_call( req
))
2124 wake_bits
= reply
->wake_bits
;
2125 changed_bits
= reply
->changed_bits
;
2130 if (wake_bits
& QS_SMRESULT
) return; /* got a result */
2131 if (wake_bits
& QS_SENDMESSAGE
)
2133 /* Process the sent message immediately */
2134 process_sent_messages();
2138 /* now wait for it */
2140 ReleaseThunkLock( &dwlc
);
2141 res
= USER_Driver
->pMsgWaitForMultipleObjectsEx( 1, &server_queue
,
2142 INFINITE
, QS_ALLINPUT
, 0 );
2143 if (dwlc
) RestoreThunkLock( dwlc
);
2147 /***********************************************************************
2148 * put_message_in_queue
2150 * Put a sent message into the destination queue.
2151 * For inter-process message, reply_size is set to expected size of reply data.
2153 static BOOL
put_message_in_queue( DWORD dest_tid
, const struct send_message_info
*info
,
2154 size_t *reply_size
)
2156 struct packed_message data
;
2160 /* Check for INFINITE timeout for compatibility with Win9x,
2161 * although Windows >= NT does not do so
2163 if (info
->type
!= MSG_NOTIFY
&&
2164 info
->type
!= MSG_CALLBACK
&&
2165 info
->type
!= MSG_POSTED
&&
2166 info
->timeout
!= INFINITE
)
2167 timeout
= info
->timeout
;
2170 if (info
->type
== MSG_OTHER_PROCESS
)
2172 *reply_size
= pack_message( info
->hwnd
, info
->msg
, info
->wparam
, info
->lparam
, &data
);
2173 if (data
.count
== -1)
2175 WARN( "cannot pack message %x\n", info
->msg
);
2179 else if (info
->type
== MSG_POSTED
&& info
->msg
>= WM_DDE_FIRST
&& info
->msg
<= WM_DDE_LAST
)
2181 return post_dde_message( dest_tid
, &data
, info
);
2184 SERVER_START_REQ( send_message
)
2187 req
->type
= info
->type
;
2189 req
->win
= info
->hwnd
;
2190 req
->msg
= info
->msg
;
2191 req
->wparam
= info
->wparam
;
2192 req
->lparam
= info
->lparam
;
2193 req
->time
= GetCurrentTime();
2194 req
->timeout
= timeout
;
2196 if (info
->type
== MSG_CALLBACK
)
2198 req
->callback
= info
->callback
;
2199 req
->info
= info
->data
;
2202 if (info
->flags
& SMTO_ABORTIFHUNG
) req
->flags
|= SEND_MSG_ABORT_IF_HUNG
;
2203 for (i
= 0; i
< data
.count
; i
++) wine_server_add_data( req
, data
.data
[i
], data
.size
[i
] );
2204 if ((res
= wine_server_call( req
)))
2206 if (res
== STATUS_INVALID_PARAMETER
)
2207 /* FIXME: find a STATUS_ value for this one */
2208 SetLastError( ERROR_INVALID_THREAD_ID
);
2210 SetLastError( RtlNtStatusToDosError(res
) );
2218 /***********************************************************************
2221 * Retrieve a message reply from the server.
2223 static LRESULT
retrieve_reply( const struct send_message_info
*info
,
2224 size_t reply_size
, LRESULT
*result
)
2227 void *reply_data
= NULL
;
2231 if (!(reply_data
= HeapAlloc( GetProcessHeap(), 0, reply_size
)))
2233 WARN( "no memory for reply %d bytes, will be truncated\n", reply_size
);
2237 SERVER_START_REQ( get_message_reply
)
2240 if (reply_size
) wine_server_set_reply( req
, reply_data
, reply_size
);
2241 if (!(status
= wine_server_call( req
))) *result
= reply
->result
;
2242 reply_size
= wine_server_reply_size( reply
);
2245 if (!status
&& reply_size
)
2246 unpack_reply( info
->hwnd
, info
->msg
, info
->wparam
, info
->lparam
, reply_data
, reply_size
);
2248 HeapFree( GetProcessHeap(), 0, reply_data
);
2250 TRACE( "hwnd %p msg %x (%s) wp %x lp %lx got reply %lx (err=%ld)\n",
2251 info
->hwnd
, info
->msg
, SPY_GetMsgName(info
->msg
, info
->hwnd
), info
->wparam
,
2252 info
->lparam
, *result
, status
);
2254 /* MSDN states that last error is 0 on timeout, but at least NT4 returns ERROR_TIMEOUT */
2255 if (status
) SetLastError( RtlNtStatusToDosError(status
) );
2260 /***********************************************************************
2261 * send_inter_thread_message
2263 static LRESULT
send_inter_thread_message( DWORD dest_tid
, const struct send_message_info
*info
,
2266 size_t reply_size
= 0;
2268 TRACE( "hwnd %p msg %x (%s) wp %x lp %lx\n",
2269 info
->hwnd
, info
->msg
, SPY_GetMsgName(info
->msg
, info
->hwnd
), info
->wparam
, info
->lparam
);
2271 USER_CheckNotLock();
2273 if (!put_message_in_queue( dest_tid
, info
, &reply_size
)) return 0;
2275 /* there's no reply to wait for on notify/callback messages */
2276 if (info
->type
== MSG_NOTIFY
|| info
->type
== MSG_CALLBACK
) return 1;
2278 wait_message_reply( info
->flags
);
2279 return retrieve_reply( info
, reply_size
, res_ptr
);
2283 /***********************************************************************
2284 * MSG_SendInternalMessageTimeout
2286 * Same as SendMessageTimeoutW but sends the message to a specific thread
2287 * without requiring a window handle. Only works for internal Wine messages.
2289 LRESULT
MSG_SendInternalMessageTimeout( DWORD dest_pid
, DWORD dest_tid
,
2290 UINT msg
, WPARAM wparam
, LPARAM lparam
,
2291 UINT flags
, UINT timeout
, PDWORD_PTR res_ptr
)
2293 struct send_message_info info
;
2294 LRESULT ret
, result
;
2296 assert( msg
& 0x80000000 ); /* must be an internal Wine message */
2298 info
.type
= MSG_UNICODE
;
2301 info
.wparam
= wparam
;
2302 info
.lparam
= lparam
;
2304 info
.timeout
= timeout
;
2306 if (USER_IsExitingThread( dest_tid
)) return 0;
2308 if (dest_tid
== GetCurrentThreadId())
2310 result
= handle_internal_message( 0, msg
, wparam
, lparam
);
2315 if (dest_pid
!= GetCurrentProcessId()) info
.type
= MSG_OTHER_PROCESS
;
2316 ret
= send_inter_thread_message( dest_tid
, &info
, &result
);
2318 if (ret
&& res_ptr
) *res_ptr
= result
;
2323 /***********************************************************************
2324 * SendMessageTimeoutW (USER32.@)
2326 LRESULT WINAPI
SendMessageTimeoutW( HWND hwnd
, UINT msg
, WPARAM wparam
, LPARAM lparam
,
2327 UINT flags
, UINT timeout
, PDWORD_PTR res_ptr
)
2329 struct send_message_info info
;
2330 DWORD dest_tid
, dest_pid
;
2331 LRESULT ret
, result
;
2333 info
.type
= MSG_UNICODE
;
2336 info
.wparam
= wparam
;
2337 info
.lparam
= lparam
;
2339 info
.timeout
= timeout
;
2341 if (is_broadcast(hwnd
))
2343 EnumWindows( broadcast_message_callback
, (LPARAM
)&info
);
2344 if (res_ptr
) *res_ptr
= 1;
2348 if (!(dest_tid
= GetWindowThreadProcessId( hwnd
, &dest_pid
))) return 0;
2350 if (USER_IsExitingThread( dest_tid
)) return 0;
2352 SPY_EnterMessage( SPY_SENDMESSAGE
, hwnd
, msg
, wparam
, lparam
);
2354 if (dest_tid
== GetCurrentThreadId())
2356 result
= call_window_proc( hwnd
, msg
, wparam
, lparam
, TRUE
, TRUE
);
2361 if (dest_pid
!= GetCurrentProcessId()) info
.type
= MSG_OTHER_PROCESS
;
2362 ret
= send_inter_thread_message( dest_tid
, &info
, &result
);
2365 SPY_ExitMessage( SPY_RESULT_OK
, hwnd
, msg
, result
, wparam
, lparam
);
2366 if (ret
&& res_ptr
) *res_ptr
= result
;
2371 /***********************************************************************
2372 * SendMessageTimeoutA (USER32.@)
2374 LRESULT WINAPI
SendMessageTimeoutA( HWND hwnd
, UINT msg
, WPARAM wparam
, LPARAM lparam
,
2375 UINT flags
, UINT timeout
, PDWORD_PTR res_ptr
)
2377 struct send_message_info info
;
2378 DWORD dest_tid
, dest_pid
;
2379 LRESULT ret
, result
;
2381 info
.type
= MSG_ASCII
;
2384 info
.wparam
= wparam
;
2385 info
.lparam
= lparam
;
2387 info
.timeout
= timeout
;
2389 if (is_broadcast(hwnd
))
2391 EnumWindows( broadcast_message_callback
, (LPARAM
)&info
);
2392 if (res_ptr
) *res_ptr
= 1;
2396 if (!(dest_tid
= GetWindowThreadProcessId( hwnd
, &dest_pid
))) return 0;
2398 if (USER_IsExitingThread( dest_tid
)) return 0;
2400 SPY_EnterMessage( SPY_SENDMESSAGE
, hwnd
, msg
, wparam
, lparam
);
2402 if (dest_tid
== GetCurrentThreadId())
2404 result
= call_window_proc( hwnd
, msg
, wparam
, lparam
, FALSE
, TRUE
);
2407 else if (dest_pid
== GetCurrentProcessId())
2409 ret
= send_inter_thread_message( dest_tid
, &info
, &result
);
2413 /* inter-process message: need to map to Unicode */
2414 info
.type
= MSG_OTHER_PROCESS
;
2415 if (is_unicode_message( info
.msg
))
2417 if (WINPROC_MapMsg32ATo32W( info
.hwnd
, info
.msg
, &info
.wparam
, &info
.lparam
) == -1)
2419 ret
= send_inter_thread_message( dest_tid
, &info
, &result
);
2420 result
= WINPROC_UnmapMsg32ATo32W( info
.hwnd
, info
.msg
, info
.wparam
,
2421 info
.lparam
, result
, NULL
);
2423 else ret
= send_inter_thread_message( dest_tid
, &info
, &result
);
2425 SPY_ExitMessage( SPY_RESULT_OK
, hwnd
, msg
, result
, wparam
, lparam
);
2426 if (ret
&& res_ptr
) *res_ptr
= result
;
2431 /***********************************************************************
2432 * SendMessageW (USER32.@)
2434 LRESULT WINAPI
SendMessageW( HWND hwnd
, UINT msg
, WPARAM wparam
, LPARAM lparam
)
2437 SendMessageTimeoutW( hwnd
, msg
, wparam
, lparam
, SMTO_NORMAL
, 0, &res
);
2442 /***********************************************************************
2443 * SendMessageA (USER32.@)
2445 LRESULT WINAPI
SendMessageA( HWND hwnd
, UINT msg
, WPARAM wparam
, LPARAM lparam
)
2448 SendMessageTimeoutA( hwnd
, msg
, wparam
, lparam
, SMTO_NORMAL
, 0, &res
);
2453 /***********************************************************************
2454 * SendNotifyMessageA (USER32.@)
2456 BOOL WINAPI
SendNotifyMessageA( HWND hwnd
, UINT msg
, WPARAM wparam
, LPARAM lparam
)
2458 return SendNotifyMessageW( hwnd
, msg
, map_wparam_AtoW( msg
, wparam
), lparam
);
2462 /***********************************************************************
2463 * SendNotifyMessageW (USER32.@)
2465 BOOL WINAPI
SendNotifyMessageW( HWND hwnd
, UINT msg
, WPARAM wparam
, LPARAM lparam
)
2467 struct send_message_info info
;
2471 if (is_pointer_message(msg
))
2473 SetLastError( ERROR_MESSAGE_SYNC_ONLY
);
2477 info
.type
= MSG_NOTIFY
;
2480 info
.wparam
= wparam
;
2481 info
.lparam
= lparam
;
2484 if (is_broadcast(hwnd
))
2486 EnumWindows( broadcast_message_callback
, (LPARAM
)&info
);
2490 if (!(dest_tid
= GetWindowThreadProcessId( hwnd
, NULL
))) return FALSE
;
2492 if (USER_IsExitingThread( dest_tid
)) return TRUE
;
2494 if (dest_tid
== GetCurrentThreadId())
2496 call_window_proc( hwnd
, msg
, wparam
, lparam
, TRUE
, TRUE
);
2499 return send_inter_thread_message( dest_tid
, &info
, &result
);
2503 /***********************************************************************
2504 * SendMessageCallbackA (USER32.@)
2506 BOOL WINAPI
SendMessageCallbackA( HWND hwnd
, UINT msg
, WPARAM wparam
, LPARAM lparam
,
2507 SENDASYNCPROC callback
, ULONG_PTR data
)
2509 return SendMessageCallbackW( hwnd
, msg
, map_wparam_AtoW( msg
, wparam
),
2510 lparam
, callback
, data
);
2514 /***********************************************************************
2515 * SendMessageCallbackW (USER32.@)
2517 BOOL WINAPI
SendMessageCallbackW( HWND hwnd
, UINT msg
, WPARAM wparam
, LPARAM lparam
,
2518 SENDASYNCPROC callback
, ULONG_PTR data
)
2520 struct send_message_info info
;
2524 if (is_pointer_message(msg
))
2526 SetLastError( ERROR_MESSAGE_SYNC_ONLY
);
2530 info
.type
= MSG_CALLBACK
;
2533 info
.wparam
= wparam
;
2534 info
.lparam
= lparam
;
2535 info
.callback
= callback
;
2539 if (is_broadcast(hwnd
))
2541 EnumWindows( broadcast_message_callback
, (LPARAM
)&info
);
2545 if (!(dest_tid
= GetWindowThreadProcessId( hwnd
, NULL
))) return FALSE
;
2547 if (USER_IsExitingThread( dest_tid
)) return TRUE
;
2549 if (dest_tid
== GetCurrentThreadId())
2551 result
= call_window_proc( hwnd
, msg
, wparam
, lparam
, TRUE
, TRUE
);
2552 call_sendmsg_callback( callback
, hwnd
, msg
, data
, result
);
2555 FIXME( "callback will not be called\n" );
2556 return send_inter_thread_message( dest_tid
, &info
, &result
);
2560 /***********************************************************************
2561 * ReplyMessage (USER32.@)
2563 BOOL WINAPI
ReplyMessage( LRESULT result
)
2565 struct received_message_info
*info
= get_user_thread_info()->receive_info
;
2567 if (!info
) return FALSE
;
2568 reply_message( info
, result
, FALSE
);
2573 /***********************************************************************
2574 * InSendMessage (USER32.@)
2576 BOOL WINAPI
InSendMessage(void)
2578 return (InSendMessageEx(NULL
) & (ISMEX_SEND
|ISMEX_REPLIED
)) == ISMEX_SEND
;
2582 /***********************************************************************
2583 * InSendMessageEx (USER32.@)
2585 DWORD WINAPI
InSendMessageEx( LPVOID reserved
)
2587 struct received_message_info
*info
= get_user_thread_info()->receive_info
;
2589 if (info
) return info
->flags
;
2590 return ISMEX_NOSEND
;
2594 /***********************************************************************
2595 * PostMessageA (USER32.@)
2597 BOOL WINAPI
PostMessageA( HWND hwnd
, UINT msg
, WPARAM wparam
, LPARAM lparam
)
2599 return PostMessageW( hwnd
, msg
, map_wparam_AtoW( msg
, wparam
), lparam
);
2603 /***********************************************************************
2604 * PostMessageW (USER32.@)
2606 BOOL WINAPI
PostMessageW( HWND hwnd
, UINT msg
, WPARAM wparam
, LPARAM lparam
)
2608 struct send_message_info info
;
2611 if (is_pointer_message( msg
))
2613 SetLastError( ERROR_MESSAGE_SYNC_ONLY
);
2617 TRACE( "hwnd %p msg %x (%s) wp %x lp %lx\n",
2618 hwnd
, msg
, SPY_GetMsgName(msg
, hwnd
), wparam
, lparam
);
2620 info
.type
= MSG_POSTED
;
2623 info
.wparam
= wparam
;
2624 info
.lparam
= lparam
;
2627 if (is_broadcast(hwnd
))
2629 EnumWindows( broadcast_message_callback
, (LPARAM
)&info
);
2633 if (!hwnd
) return PostThreadMessageW( GetCurrentThreadId(), msg
, wparam
, lparam
);
2635 if (!(dest_tid
= GetWindowThreadProcessId( hwnd
, NULL
))) return FALSE
;
2637 if (USER_IsExitingThread( dest_tid
)) return TRUE
;
2639 return put_message_in_queue( dest_tid
, &info
, NULL
);
2643 /**********************************************************************
2644 * PostThreadMessageA (USER32.@)
2646 BOOL WINAPI
PostThreadMessageA( DWORD thread
, UINT msg
, WPARAM wparam
, LPARAM lparam
)
2648 return PostThreadMessageW( thread
, msg
, map_wparam_AtoW( msg
, wparam
), lparam
);
2652 /**********************************************************************
2653 * PostThreadMessageW (USER32.@)
2655 BOOL WINAPI
PostThreadMessageW( DWORD thread
, UINT msg
, WPARAM wparam
, LPARAM lparam
)
2657 struct send_message_info info
;
2659 if (is_pointer_message( msg
))
2661 SetLastError( ERROR_MESSAGE_SYNC_ONLY
);
2664 if (USER_IsExitingThread( thread
)) return TRUE
;
2666 info
.type
= MSG_POSTED
;
2669 info
.wparam
= wparam
;
2670 info
.lparam
= lparam
;
2672 return put_message_in_queue( thread
, &info
, NULL
);
2676 /***********************************************************************
2677 * PostQuitMessage (USER32.@)
2679 * Posts a quit message to the current thread's message queue.
2682 * exit_code [I] Exit code to return from message loop.
2688 * This function is not the same as calling:
2689 *|PostThreadMessage(GetCurrentThreadId(), WM_QUIT, exit_code, 0);
2690 * It instead sets a flag in the message queue that signals it to generate
2691 * a WM_QUIT message when there are no other pending sent or posted messages
2694 void WINAPI
PostQuitMessage( INT exit_code
)
2696 SERVER_START_REQ( post_quit_message
)
2698 req
->exit_code
= exit_code
;
2699 wine_server_call( req
);
2705 /***********************************************************************
2706 * PeekMessageW (USER32.@)
2708 BOOL WINAPI
PeekMessageW( MSG
*msg_out
, HWND hwnd
, UINT first
, UINT last
, UINT flags
)
2710 struct user_thread_info
*thread_info
= get_user_thread_info();
2714 FIXME("PM_QS_xxxx flags (%04x) are not handled\n", flags
>> 16);
2716 USER_CheckNotLock();
2718 /* check for graphics events */
2719 USER_Driver
->pMsgWaitForMultipleObjectsEx( 0, NULL
, 0, QS_ALLINPUT
, 0 );
2721 hwnd
= WIN_GetFullHandle( hwnd
);
2725 if (!peek_message( &msg
, hwnd
, first
, last
, (flags
& PM_REMOVE
) ? GET_MSG_REMOVE
: 0 ))
2727 if (!(flags
& PM_NOYIELD
))
2730 ReleaseThunkLock(&count
);
2732 if (count
) RestoreThunkLock(count
);
2736 if (msg
.message
& 0x80000000)
2738 if (!(flags
& PM_REMOVE
))
2740 /* Have to remove the message explicitly.
2741 Do this before handling it, because the message handler may
2742 call PeekMessage again */
2743 peek_message( &msg
, msg
.hwnd
, msg
.message
, msg
.message
, GET_MSG_REMOVE
);
2745 handle_internal_message( msg
.hwnd
, msg
.message
, msg
.wParam
, msg
.lParam
);
2750 thread_info
->GetMessageTimeVal
= msg
.time
;
2751 msg
.pt
.x
= LOWORD( thread_info
->GetMessagePosVal
);
2752 msg
.pt
.y
= HIWORD( thread_info
->GetMessagePosVal
);
2754 HOOK_CallHooks( WH_GETMESSAGE
, HC_ACTION
, flags
& PM_REMOVE
, (LPARAM
)&msg
, TRUE
);
2756 /* copy back our internal safe copy of message data to msg_out.
2757 * msg_out is a variable from the *program*, so it can't be used
2758 * internally as it can get "corrupted" by our use of SendMessage()
2759 * (back to the program) inside the message handling itself. */
2762 SetLastError( ERROR_NOACCESS
);
2770 /***********************************************************************
2771 * PeekMessageA (USER32.@)
2773 BOOL WINAPI
PeekMessageA( MSG
*msg
, HWND hwnd
, UINT first
, UINT last
, UINT flags
)
2775 BOOL ret
= PeekMessageW( msg
, hwnd
, first
, last
, flags
);
2776 if (ret
) msg
->wParam
= map_wparam_WtoA( msg
->message
, msg
->wParam
);
2781 /***********************************************************************
2782 * GetMessageW (USER32.@)
2784 BOOL WINAPI
GetMessageW( MSG
*msg
, HWND hwnd
, UINT first
, UINT last
)
2786 HANDLE server_queue
= get_server_queue_handle();
2787 int mask
= QS_POSTMESSAGE
| QS_SENDMESSAGE
; /* Always selected */
2791 if ((first
<= WM_KEYLAST
) && (last
>= WM_KEYFIRST
)) mask
|= QS_KEY
;
2792 if ( ((first
<= WM_MOUSELAST
) && (last
>= WM_MOUSEFIRST
)) ||
2793 ((first
<= WM_NCMOUSELAST
) && (last
>= WM_NCMOUSEFIRST
)) ) mask
|= QS_MOUSE
;
2794 if ((first
<= WM_TIMER
) && (last
>= WM_TIMER
)) mask
|= QS_TIMER
;
2795 if ((first
<= WM_SYSTIMER
) && (last
>= WM_SYSTIMER
)) mask
|= QS_TIMER
;
2796 if ((first
<= WM_PAINT
) && (last
>= WM_PAINT
)) mask
|= QS_PAINT
;
2798 else mask
|= QS_MOUSE
| QS_KEY
| QS_TIMER
| QS_PAINT
;
2800 while (!PeekMessageW( msg
, hwnd
, first
, last
, PM_REMOVE
))
2802 /* wait until one of the bits is set */
2803 unsigned int wake_bits
= 0, changed_bits
= 0;
2806 SERVER_START_REQ( set_queue_mask
)
2808 req
->wake_mask
= QS_SENDMESSAGE
;
2809 req
->changed_mask
= mask
;
2811 if (!wine_server_call( req
))
2813 wake_bits
= reply
->wake_bits
;
2814 changed_bits
= reply
->changed_bits
;
2819 if (changed_bits
& mask
) continue;
2820 if (wake_bits
& QS_SENDMESSAGE
) continue;
2822 TRACE( "(%04lx) mask=%08x, bits=%08x, changed=%08x, waiting\n",
2823 GetCurrentThreadId(), mask
, wake_bits
, changed_bits
);
2825 ReleaseThunkLock( &dwlc
);
2826 USER_Driver
->pMsgWaitForMultipleObjectsEx( 1, &server_queue
, INFINITE
, QS_ALLINPUT
, 0 );
2827 if (dwlc
) RestoreThunkLock( dwlc
);
2830 return (msg
->message
!= WM_QUIT
);
2834 /***********************************************************************
2835 * GetMessageA (USER32.@)
2837 BOOL WINAPI
GetMessageA( MSG
*msg
, HWND hwnd
, UINT first
, UINT last
)
2839 GetMessageW( msg
, hwnd
, first
, last
);
2840 msg
->wParam
= map_wparam_WtoA( msg
->message
, msg
->wParam
);
2841 return (msg
->message
!= WM_QUIT
);
2845 /***********************************************************************
2846 * IsDialogMessageA (USER32.@)
2847 * IsDialogMessage (USER32.@)
2849 BOOL WINAPI
IsDialogMessageA( HWND hwndDlg
, LPMSG pmsg
)
2852 msg
.wParam
= map_wparam_AtoW( msg
.message
, msg
.wParam
);
2853 return IsDialogMessageW( hwndDlg
, &msg
);
2857 /***********************************************************************
2858 * TranslateMessage (USER32.@)
2860 * Implementation of TranslateMessage.
2862 * TranslateMessage translates virtual-key messages into character-messages,
2864 * WM_KEYDOWN/WM_KEYUP combinations produce a WM_CHAR or WM_DEADCHAR message.
2865 * ditto replacing WM_* with WM_SYS*
2866 * This produces WM_CHAR messages only for keys mapped to ASCII characters
2867 * by the keyboard driver.
2869 * If the message is WM_KEYDOWN, WM_KEYUP, WM_SYSKEYDOWN, or WM_SYSKEYUP, the
2870 * return value is nonzero, regardless of the translation.
2873 BOOL WINAPI
TranslateMessage( const MSG
*msg
)
2879 if (msg
->message
< WM_KEYFIRST
|| msg
->message
> WM_KEYLAST
) return FALSE
;
2880 if (msg
->message
!= WM_KEYDOWN
&& msg
->message
!= WM_SYSKEYDOWN
) return TRUE
;
2882 TRACE_(key
)("Translating key %s (%04x), scancode %02x\n",
2883 SPY_GetVKeyName(msg
->wParam
), msg
->wParam
, LOBYTE(HIWORD(msg
->lParam
)));
2885 GetKeyboardState( state
);
2886 /* FIXME : should handle ToUnicode yielding 2 */
2887 switch (ToUnicode(msg
->wParam
, HIWORD(msg
->lParam
), state
, wp
, 2, 0))
2890 message
= (msg
->message
== WM_KEYDOWN
) ? WM_CHAR
: WM_SYSCHAR
;
2891 TRACE_(key
)("1 -> PostMessageW(%p,%s,%04x,%08lx)\n",
2892 msg
->hwnd
, SPY_GetMsgName(message
, msg
->hwnd
), wp
[0], msg
->lParam
);
2893 PostMessageW( msg
->hwnd
, message
, wp
[0], msg
->lParam
);
2897 message
= (msg
->message
== WM_KEYDOWN
) ? WM_DEADCHAR
: WM_SYSDEADCHAR
;
2898 TRACE_(key
)("-1 -> PostMessageW(%p,%s,%04x,%08lx)\n",
2899 msg
->hwnd
, SPY_GetMsgName(message
, msg
->hwnd
), wp
[0], msg
->lParam
);
2900 PostMessageW( msg
->hwnd
, message
, wp
[0], msg
->lParam
);
2907 /***********************************************************************
2908 * DispatchMessageA (USER32.@)
2910 * See DispatchMessageW.
2912 LONG WINAPI
DispatchMessageA( const MSG
* msg
)
2918 /* Process timer messages */
2919 if ((msg
->message
== WM_TIMER
) || (msg
->message
== WM_SYSTIMER
))
2921 if (msg
->lParam
) return CallWindowProcA( (WNDPROC
)msg
->lParam
, msg
->hwnd
,
2922 msg
->message
, msg
->wParam
, GetTickCount() );
2925 if (!(wndPtr
= WIN_GetPtr( msg
->hwnd
)))
2927 if (msg
->hwnd
) SetLastError( ERROR_INVALID_WINDOW_HANDLE
);
2930 if (wndPtr
== WND_OTHER_PROCESS
|| wndPtr
== WND_DESKTOP
)
2932 if (IsWindow( msg
->hwnd
)) SetLastError( ERROR_MESSAGE_SYNC_ONLY
);
2933 else SetLastError( ERROR_INVALID_WINDOW_HANDLE
);
2936 if (wndPtr
->tid
!= GetCurrentThreadId())
2938 SetLastError( ERROR_MESSAGE_SYNC_ONLY
);
2939 WIN_ReleasePtr( wndPtr
);
2942 winproc
= wndPtr
->winproc
;
2943 WIN_ReleasePtr( wndPtr
);
2945 SPY_EnterMessage( SPY_DISPATCHMESSAGE
, msg
->hwnd
, msg
->message
,
2946 msg
->wParam
, msg
->lParam
);
2947 retval
= CallWindowProcA( winproc
, msg
->hwnd
, msg
->message
,
2948 msg
->wParam
, msg
->lParam
);
2949 SPY_ExitMessage( SPY_RESULT_OK
, msg
->hwnd
, msg
->message
, retval
,
2950 msg
->wParam
, msg
->lParam
);
2952 if (msg
->message
== WM_PAINT
)
2954 /* send a WM_NCPAINT and WM_ERASEBKGND if the non-client area is still invalid */
2955 HRGN hrgn
= CreateRectRgn( 0, 0, 0, 0 );
2956 GetUpdateRgn( msg
->hwnd
, hrgn
, TRUE
);
2957 DeleteObject( hrgn
);
2963 /***********************************************************************
2964 * DispatchMessageW (USER32.@) Process a message
2966 * Process the message specified in the structure *_msg_.
2968 * If the lpMsg parameter points to a WM_TIMER message and the
2969 * parameter of the WM_TIMER message is not NULL, the lParam parameter
2970 * points to the function that is called instead of the window
2973 * The message must be valid.
2977 * DispatchMessage() returns the result of the window procedure invoked.
2984 LONG WINAPI
DispatchMessageW( const MSG
* msg
)
2990 /* Process timer messages */
2991 if ((msg
->message
== WM_TIMER
) || (msg
->message
== WM_SYSTIMER
))
2993 if (msg
->lParam
) return CallWindowProcW( (WNDPROC
)msg
->lParam
, msg
->hwnd
,
2994 msg
->message
, msg
->wParam
, GetTickCount() );
2997 if (!(wndPtr
= WIN_GetPtr( msg
->hwnd
)))
2999 if (msg
->hwnd
) SetLastError( ERROR_INVALID_WINDOW_HANDLE
);
3002 if (wndPtr
== WND_OTHER_PROCESS
|| wndPtr
== WND_DESKTOP
)
3004 if (IsWindow( msg
->hwnd
)) SetLastError( ERROR_MESSAGE_SYNC_ONLY
);
3005 else SetLastError( ERROR_INVALID_WINDOW_HANDLE
);
3008 if (wndPtr
->tid
!= GetCurrentThreadId())
3010 SetLastError( ERROR_MESSAGE_SYNC_ONLY
);
3011 WIN_ReleasePtr( wndPtr
);
3014 winproc
= wndPtr
->winproc
;
3015 WIN_ReleasePtr( wndPtr
);
3017 SPY_EnterMessage( SPY_DISPATCHMESSAGE
, msg
->hwnd
, msg
->message
,
3018 msg
->wParam
, msg
->lParam
);
3019 retval
= CallWindowProcW( winproc
, msg
->hwnd
, msg
->message
,
3020 msg
->wParam
, msg
->lParam
);
3021 SPY_ExitMessage( SPY_RESULT_OK
, msg
->hwnd
, msg
->message
, retval
,
3022 msg
->wParam
, msg
->lParam
);
3024 if (msg
->message
== WM_PAINT
)
3026 /* send a WM_NCPAINT and WM_ERASEBKGND if the non-client area is still invalid */
3027 HRGN hrgn
= CreateRectRgn( 0, 0, 0, 0 );
3028 GetUpdateRgn( msg
->hwnd
, hrgn
, TRUE
);
3029 DeleteObject( hrgn
);
3035 /***********************************************************************
3036 * GetMessagePos (USER.119)
3037 * GetMessagePos (USER32.@)
3039 * The GetMessagePos() function returns a long value representing a
3040 * cursor position, in screen coordinates, when the last message
3041 * retrieved by the GetMessage() function occurs. The x-coordinate is
3042 * in the low-order word of the return value, the y-coordinate is in
3043 * the high-order word. The application can use the MAKEPOINT()
3044 * macro to obtain a POINT structure from the return value.
3046 * For the current cursor position, use GetCursorPos().
3050 * Cursor position of last message on success, zero on failure.
3057 DWORD WINAPI
GetMessagePos(void)
3059 return get_user_thread_info()->GetMessagePosVal
;
3063 /***********************************************************************
3064 * GetMessageTime (USER.120)
3065 * GetMessageTime (USER32.@)
3067 * GetMessageTime() returns the message time for the last message
3068 * retrieved by the function. The time is measured in milliseconds with
3069 * the same offset as GetTickCount().
3071 * Since the tick count wraps, this is only useful for moderately short
3072 * relative time comparisons.
3076 * Time of last message on success, zero on failure.
3078 LONG WINAPI
GetMessageTime(void)
3080 return get_user_thread_info()->GetMessageTimeVal
;
3084 /***********************************************************************
3085 * GetMessageExtraInfo (USER.288)
3086 * GetMessageExtraInfo (USER32.@)
3088 LPARAM WINAPI
GetMessageExtraInfo(void)
3090 return get_user_thread_info()->GetMessageExtraInfoVal
;
3094 /***********************************************************************
3095 * SetMessageExtraInfo (USER32.@)
3097 LPARAM WINAPI
SetMessageExtraInfo(LPARAM lParam
)
3099 struct user_thread_info
*thread_info
= get_user_thread_info();
3100 LONG old_value
= thread_info
->GetMessageExtraInfoVal
;
3101 thread_info
->GetMessageExtraInfoVal
= lParam
;
3106 /***********************************************************************
3107 * WaitMessage (USER.112) Suspend thread pending messages
3108 * WaitMessage (USER32.@) Suspend thread pending messages
3110 * WaitMessage() suspends a thread until events appear in the thread's
3113 BOOL WINAPI
WaitMessage(void)
3115 return (MsgWaitForMultipleObjectsEx( 0, NULL
, INFINITE
, QS_ALLINPUT
, 0 ) != WAIT_FAILED
);
3119 /***********************************************************************
3120 * MsgWaitForMultipleObjectsEx (USER32.@)
3122 DWORD WINAPI
MsgWaitForMultipleObjectsEx( DWORD count
, CONST HANDLE
*pHandles
,
3123 DWORD timeout
, DWORD mask
, DWORD flags
)
3125 HANDLE handles
[MAXIMUM_WAIT_OBJECTS
];
3128 if (count
> MAXIMUM_WAIT_OBJECTS
-1)
3130 SetLastError( ERROR_INVALID_PARAMETER
);
3134 /* set the queue mask */
3135 SERVER_START_REQ( set_queue_mask
)
3137 req
->wake_mask
= (flags
& MWMO_INPUTAVAILABLE
) ? mask
: 0;
3138 req
->changed_mask
= mask
;
3140 wine_server_call( req
);
3144 /* Add the thread event to the handle list */
3145 for (i
= 0; i
< count
; i
++) handles
[i
] = pHandles
[i
];
3146 handles
[count
] = get_server_queue_handle();
3148 ReleaseThunkLock( &lock
);
3149 ret
= USER_Driver
->pMsgWaitForMultipleObjectsEx( count
+1, handles
, timeout
, mask
, flags
);
3150 if (ret
== count
+1) ret
= count
; /* pretend the msg queue is ready */
3151 if (lock
) RestoreThunkLock( lock
);
3156 /***********************************************************************
3157 * MsgWaitForMultipleObjects (USER32.@)
3159 DWORD WINAPI
MsgWaitForMultipleObjects( DWORD count
, CONST HANDLE
*handles
,
3160 BOOL wait_all
, DWORD timeout
, DWORD mask
)
3162 return MsgWaitForMultipleObjectsEx( count
, handles
, timeout
, mask
,
3163 wait_all
? MWMO_WAITALL
: 0 );
3167 /***********************************************************************
3168 * WaitForInputIdle (USER32.@)
3170 DWORD WINAPI
WaitForInputIdle( HANDLE hProcess
, DWORD dwTimeOut
)
3172 DWORD start_time
, elapsed
, ret
;
3173 HANDLE idle_event
= (HANDLE
)-1;
3175 SERVER_START_REQ( wait_input_idle
)
3177 req
->handle
= hProcess
;
3178 req
->timeout
= dwTimeOut
;
3179 if (!(ret
= wine_server_call_err( req
))) idle_event
= reply
->event
;
3182 if (ret
) return WAIT_FAILED
; /* error */
3183 if (!idle_event
) return 0; /* no event to wait on */
3185 start_time
= GetTickCount();
3188 TRACE("waiting for %p\n", idle_event
);
3191 ret
= MsgWaitForMultipleObjects ( 1, &idle_event
, FALSE
, dwTimeOut
- elapsed
, QS_SENDMESSAGE
);
3194 case WAIT_OBJECT_0
+1:
3195 process_sent_messages();
3199 TRACE("timeout or error\n");
3202 TRACE("finished\n");
3205 if (dwTimeOut
!= INFINITE
)
3207 elapsed
= GetTickCount() - start_time
;
3208 if (elapsed
> dwTimeOut
)
3214 return WAIT_TIMEOUT
;
3218 /***********************************************************************
3219 * UserYield (USER.332)
3221 void WINAPI
UserYield16(void)
3225 /* Handle sent messages */
3226 process_sent_messages();
3229 ReleaseThunkLock(&count
);
3233 RestoreThunkLock(count
);
3234 /* Handle sent messages again */
3235 process_sent_messages();
3240 /***********************************************************************
3241 * RegisterWindowMessageA (USER32.@)
3242 * RegisterWindowMessage (USER.118)
3244 UINT WINAPI
RegisterWindowMessageA( LPCSTR str
)
3246 UINT ret
= GlobalAddAtomA(str
);
3247 TRACE("%s, ret=%x\n", str
, ret
);
3252 /***********************************************************************
3253 * RegisterWindowMessageW (USER32.@)
3255 UINT WINAPI
RegisterWindowMessageW( LPCWSTR str
)
3257 UINT ret
= GlobalAddAtomW(str
);
3258 TRACE("%s ret=%x\n", debugstr_w(str
), ret
);
3263 /***********************************************************************
3264 * BroadcastSystemMessageA (USER32.@)
3265 * BroadcastSystemMessage (USER32.@)
3267 LONG WINAPI
BroadcastSystemMessageA( DWORD flags
, LPDWORD recipients
, UINT msg
, WPARAM wp
, LPARAM lp
)
3269 if ((*recipients
& BSM_APPLICATIONS
) || (*recipients
== BSM_ALLCOMPONENTS
))
3271 FIXME( "(%08lx,%08lx,%08x,%08x,%08lx): semi-stub!\n", flags
, *recipients
, msg
, wp
, lp
);
3272 PostMessageA( HWND_BROADCAST
, msg
, wp
, lp
);
3277 FIXME( "(%08lx,%08lx,%08x,%08x,%08lx): stub!\n", flags
, *recipients
, msg
, wp
, lp
);
3283 /***********************************************************************
3284 * BroadcastSystemMessageW (USER32.@)
3286 LONG WINAPI
BroadcastSystemMessageW( DWORD flags
, LPDWORD recipients
, UINT msg
, WPARAM wp
, LPARAM lp
)
3288 if ((*recipients
& BSM_APPLICATIONS
) || (*recipients
== BSM_ALLCOMPONENTS
))
3290 FIXME( "(%08lx,%08lx,%08x,%08x,%08lx): semi-stub!\n", flags
, *recipients
, msg
, wp
, lp
);
3291 PostMessageW( HWND_BROADCAST
, msg
, wp
, lp
);
3296 FIXME( "(%08lx,%08lx,%08x,%08x,%08lx): stub!\n", flags
, *recipients
, msg
, wp
, lp
);
3302 /***********************************************************************
3303 * SetMessageQueue (USER32.@)
3305 BOOL WINAPI
SetMessageQueue( INT size
)
3307 /* now obsolete the message queue will be expanded dynamically as necessary */
3312 /***********************************************************************
3313 * MessageBeep (USER32.@)
3315 BOOL WINAPI
MessageBeep( UINT i
)
3318 SystemParametersInfoA( SPI_GETBEEP
, 0, &active
, FALSE
);
3319 if (active
) USER_Driver
->pBeep();
3324 /***********************************************************************
3325 * SetTimer (USER32.@)
3327 UINT_PTR WINAPI
SetTimer( HWND hwnd
, UINT_PTR id
, UINT timeout
, TIMERPROC proc
)
3330 WNDPROC winproc
= 0;
3332 if (proc
) winproc
= WINPROC_AllocProc( (WNDPROC
)proc
, WIN_PROC_32A
);
3334 SERVER_START_REQ( set_win_timer
)
3337 req
->msg
= WM_TIMER
;
3339 req
->rate
= max( timeout
, SYS_TIMER_RATE
);
3340 req
->lparam
= (unsigned int)winproc
;
3341 if (!wine_server_call_err( req
))
3344 if (!ret
) ret
= TRUE
;
3350 TRACE("Added %p %x %p timeout %d\n", hwnd
, id
, winproc
, timeout
);
3355 /***********************************************************************
3356 * SetSystemTimer (USER32.@)
3358 UINT_PTR WINAPI
SetSystemTimer( HWND hwnd
, UINT_PTR id
, UINT timeout
, TIMERPROC proc
)
3361 WNDPROC winproc
= 0;
3363 if (proc
) winproc
= WINPROC_AllocProc( (WNDPROC
)proc
, WIN_PROC_32A
);
3365 SERVER_START_REQ( set_win_timer
)
3368 req
->msg
= WM_SYSTIMER
;
3370 req
->rate
= max( timeout
, SYS_TIMER_RATE
);
3371 req
->lparam
= (unsigned int)winproc
;
3372 if (!wine_server_call_err( req
))
3375 if (!ret
) ret
= TRUE
;
3381 TRACE("Added %p %x %p timeout %d\n", hwnd
, id
, winproc
, timeout
);
3386 /***********************************************************************
3387 * KillTimer (USER32.@)
3389 BOOL WINAPI
KillTimer( HWND hwnd
, UINT_PTR id
)
3393 TRACE("%p %d\n", hwnd
, id
);
3395 SERVER_START_REQ( kill_win_timer
)
3398 req
->msg
= WM_TIMER
;
3400 ret
= !wine_server_call_err( req
);
3407 /***********************************************************************
3408 * KillSystemTimer (USER32.@)
3410 BOOL WINAPI
KillSystemTimer( HWND hwnd
, UINT_PTR id
)
3414 TRACE("%p %d\n", hwnd
, id
);
3416 SERVER_START_REQ( kill_win_timer
)
3419 req
->msg
= WM_SYSTIMER
;
3421 ret
= !wine_server_call_err( req
);
3428 /**********************************************************************
3429 * GetGUIThreadInfo (USER32.@)
3431 BOOL WINAPI
GetGUIThreadInfo( DWORD id
, GUITHREADINFO
*info
)
3435 SERVER_START_REQ( get_thread_input
)
3438 if ((ret
= !wine_server_call_err( req
)))
3441 info
->hwndActive
= reply
->active
;
3442 info
->hwndFocus
= reply
->focus
;
3443 info
->hwndCapture
= reply
->capture
;
3444 info
->hwndMenuOwner
= reply
->menu_owner
;
3445 info
->hwndMoveSize
= reply
->move_size
;
3446 info
->hwndCaret
= reply
->caret
;
3447 info
->rcCaret
.left
= reply
->rect
.left
;
3448 info
->rcCaret
.top
= reply
->rect
.top
;
3449 info
->rcCaret
.right
= reply
->rect
.right
;
3450 info
->rcCaret
.bottom
= reply
->rect
.bottom
;
3451 if (reply
->menu_owner
) info
->flags
|= GUI_INMENUMODE
;
3452 if (reply
->move_size
) info
->flags
|= GUI_INMOVESIZE
;
3453 if (reply
->caret
) info
->flags
|= GUI_CARETBLINKING
;
3461 /******************************************************************
3462 * IsHungAppWindow (USER32.@)
3465 BOOL WINAPI
IsHungAppWindow( HWND hWnd
)
3468 return !SendMessageTimeoutA(hWnd
, WM_NULL
, 0, 0, SMTO_ABORTIFHUNG
, 5000, &dwResult
);