2 * Window messaging support
4 * Copyright 2001 Alexandre Julliard
6 * This library is free software; you can redistribute it and/or
7 * modify it under the terms of the GNU Lesser General Public
8 * License as published by the Free Software Foundation; either
9 * version 2.1 of the License, or (at your option) any later version.
11 * This library is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 * Lesser General Public License for more details.
16 * You should have received a copy of the GNU Lesser General Public
17 * License along with this library; if not, write to the Free Software
18 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
22 #include "wine/port.h"
35 #include "wine/unicode.h"
36 #include "wine/server.h"
37 #include "user_private.h"
42 #include "wine/debug.h"
44 WINE_DEFAULT_DEBUG_CHANNEL(msg
);
45 WINE_DECLARE_DEBUG_CHANNEL(relay
);
46 WINE_DECLARE_DEBUG_CHANNEL(key
);
48 #define WM_NCMOUSEFIRST WM_NCMOUSEMOVE
49 #define WM_NCMOUSELAST (WM_NCMOUSEFIRST+(WM_MOUSELAST-WM_MOUSEFIRST))
51 #define MAX_PACK_COUNT 4
52 #define MAX_SENDMSG_RECURSION 64
54 #define SYS_TIMER_RATE 55 /* min. timer rate in ms (actually 54.925)*/
56 /* description of the data fields that need to be packed along with a sent message */
60 const void *data
[MAX_PACK_COUNT
];
61 size_t size
[MAX_PACK_COUNT
];
64 /* info about the message currently being received by the current thread */
65 struct received_message_info
67 enum message_type type
;
69 UINT flags
; /* InSendMessageEx return flags */
70 HWINEVENTHOOK hook
; /* winevent hook handle */
71 WINEVENTPROC hook_proc
; /* winevent hook proc address */
74 /* structure to group all parameters for sent messages of the various kinds */
75 struct send_message_info
77 enum message_type type
;
82 UINT flags
; /* flags for SendMessageTimeout */
83 UINT timeout
; /* timeout for SendMessageTimeout */
84 SENDASYNCPROC callback
; /* callback function for SendMessageCallback */
85 ULONG_PTR data
; /* callback data */
89 /* flag for messages that contain pointers */
90 /* 32 messages per entry, messages 0..31 map to bits 0..31 */
92 #define SET(msg) (1 << ((msg) & 31))
94 static const unsigned int message_pointer_flags
[] =
97 SET(WM_CREATE
) | SET(WM_SETTEXT
) | SET(WM_GETTEXT
) |
98 SET(WM_WININICHANGE
) | SET(WM_DEVMODECHANGE
),
100 SET(WM_GETMINMAXINFO
) | SET(WM_DRAWITEM
) | SET(WM_MEASUREITEM
) | SET(WM_DELETEITEM
) |
103 SET(WM_WINDOWPOSCHANGING
) | SET(WM_WINDOWPOSCHANGED
) | SET(WM_COPYDATA
) |
104 SET(WM_NOTIFY
) | SET(WM_HELP
),
106 SET(WM_STYLECHANGING
) | SET(WM_STYLECHANGED
),
108 SET(WM_NCCREATE
) | SET(WM_NCCALCSIZE
) | SET(WM_GETDLGCODE
),
110 SET(EM_GETSEL
) | SET(EM_GETRECT
) | SET(EM_SETRECT
) | SET(EM_SETRECTNP
),
112 SET(EM_REPLACESEL
) | SET(EM_GETLINE
) | SET(EM_SETTABSTOPS
),
114 SET(SBM_GETRANGE
) | SET(SBM_SETSCROLLINFO
) | SET(SBM_GETSCROLLINFO
) | SET(SBM_GETSCROLLBARINFO
),
120 SET(CB_GETEDITSEL
) | SET(CB_ADDSTRING
) | SET(CB_DIR
) | SET(CB_GETLBTEXT
) |
121 SET(CB_INSERTSTRING
) | SET(CB_FINDSTRING
) | SET(CB_SELECTSTRING
) |
122 SET(CB_GETDROPPEDCONTROLRECT
) | SET(CB_FINDSTRINGEXACT
),
126 SET(LB_ADDSTRING
) | SET(LB_INSERTSTRING
) | SET(LB_GETTEXT
) | SET(LB_SELECTSTRING
) |
127 SET(LB_DIR
) | SET(LB_FINDSTRING
) |
128 SET(LB_GETSELITEMS
) | SET(LB_SETTABSTOPS
) | SET(LB_ADDFILE
) | SET(LB_GETITEMRECT
),
130 SET(LB_FINDSTRINGEXACT
),
136 SET(WM_NEXTMENU
) | SET(WM_SIZING
) | SET(WM_MOVING
) | SET(WM_DEVICECHANGE
),
138 SET(WM_MDICREATE
) | SET(WM_MDIGETACTIVE
) | SET(WM_DROPOBJECT
) |
139 SET(WM_QUERYDROPOBJECT
) | SET(WM_DRAGLOOP
) | SET(WM_DRAGSELECT
) | SET(WM_DRAGMOVE
),
153 SET(WM_ASKCBFORMATNAME
)
156 /* flags for messages that contain Unicode strings */
157 static const unsigned int message_unicode_flags
[] =
160 SET(WM_CREATE
) | SET(WM_SETTEXT
) | SET(WM_GETTEXT
) | SET(WM_GETTEXTLENGTH
) |
161 SET(WM_WININICHANGE
) | SET(WM_DEVMODECHANGE
),
173 SET(EM_REPLACESEL
) | SET(EM_GETLINE
) | SET(EM_SETPASSWORDCHAR
),
177 SET(WM_CHAR
) | SET(WM_DEADCHAR
) | SET(WM_SYSCHAR
) | SET(WM_SYSDEADCHAR
),
181 SET(CB_ADDSTRING
) | SET(CB_DIR
) | SET(CB_GETLBTEXT
) | SET(CB_GETLBTEXTLEN
) |
182 SET(CB_INSERTSTRING
) | SET(CB_FINDSTRING
) | SET(CB_SELECTSTRING
) | SET(CB_FINDSTRINGEXACT
),
186 SET(LB_ADDSTRING
) | SET(LB_INSERTSTRING
) | SET(LB_GETTEXT
) | SET(LB_GETTEXTLEN
) |
187 SET(LB_SELECTSTRING
) | SET(LB_DIR
) | SET(LB_FINDSTRING
) | SET(LB_ADDFILE
),
189 SET(LB_FINDSTRINGEXACT
),
211 SET(WM_PAINTCLIPBOARD
) | SET(WM_SIZECLIPBOARD
) | SET(WM_ASKCBFORMATNAME
)
214 /* check whether a given message type includes pointers */
215 inline static int is_pointer_message( UINT message
)
217 if (message
>= 8*sizeof(message_pointer_flags
)) return FALSE
;
218 return (message_pointer_flags
[message
/ 32] & SET(message
)) != 0;
221 /* check whether a given message type contains Unicode (or ASCII) chars */
222 inline static int is_unicode_message( UINT message
)
224 if (message
>= 8*sizeof(message_unicode_flags
)) return FALSE
;
225 return (message_unicode_flags
[message
/ 32] & SET(message
)) != 0;
230 /* add a data field to a packed message */
231 inline static void push_data( struct packed_message
*data
, const void *ptr
, size_t size
)
233 data
->data
[data
->count
] = ptr
;
234 data
->size
[data
->count
] = size
;
238 /* add a string to a packed message */
239 inline static void push_string( struct packed_message
*data
, LPCWSTR str
)
241 push_data( data
, str
, (strlenW(str
) + 1) * sizeof(WCHAR
) );
244 /* retrieve a pointer to data from a packed message and increment the buffer pointer */
245 inline static void *get_data( void **buffer
, size_t size
)
248 *buffer
= (char *)*buffer
+ size
;
252 /* make sure that the buffer contains a valid null-terminated Unicode string */
253 inline static BOOL
check_string( LPCWSTR str
, size_t size
)
255 for (size
/= sizeof(WCHAR
); size
; size
--, str
++)
256 if (!*str
) return TRUE
;
260 /* make sure that there is space for 'size' bytes in buffer, growing it if needed */
261 inline static void *get_buffer_space( void **buffer
, size_t size
)
267 if (!(ret
= HeapReAlloc( GetProcessHeap(), 0, *buffer
, size
)))
268 HeapFree( GetProcessHeap(), 0, *buffer
);
270 else ret
= HeapAlloc( GetProcessHeap(), 0, size
);
276 /* retrieve a string pointer from packed data */
277 inline static LPWSTR
get_string( void **buffer
)
279 return get_data( buffer
, (strlenW( (LPWSTR
)*buffer
) + 1) * sizeof(WCHAR
) );
282 /* check whether a combobox expects strings or ids in CB_ADDSTRING/CB_INSERTSTRING */
283 inline static BOOL
combobox_has_strings( HWND hwnd
)
285 DWORD style
= GetWindowLongA( hwnd
, GWL_STYLE
);
286 return (!(style
& (CBS_OWNERDRAWFIXED
| CBS_OWNERDRAWVARIABLE
)) || (style
& CBS_HASSTRINGS
));
289 /* check whether a listbox expects strings or ids in LB_ADDSTRING/LB_INSERTSTRING */
290 inline static BOOL
listbox_has_strings( HWND hwnd
)
292 DWORD style
= GetWindowLongA( hwnd
, GWL_STYLE
);
293 return (!(style
& (LBS_OWNERDRAWFIXED
| LBS_OWNERDRAWVARIABLE
)) || (style
& LBS_HASSTRINGS
));
296 /* check whether message is in the range of keyboard messages */
297 inline static BOOL
is_keyboard_message( UINT message
)
299 return (message
>= WM_KEYFIRST
&& message
<= WM_KEYLAST
);
302 /* check whether message is in the range of mouse messages */
303 inline static BOOL
is_mouse_message( UINT message
)
305 return ((message
>= WM_NCMOUSEFIRST
&& message
<= WM_NCMOUSELAST
) ||
306 (message
>= WM_MOUSEFIRST
&& message
<= WM_MOUSELAST
));
309 /* check whether message matches the specified hwnd filter */
310 inline static BOOL
check_hwnd_filter( const MSG
*msg
, HWND hwnd_filter
)
312 if (!hwnd_filter
) return TRUE
;
313 return (msg
->hwnd
== hwnd_filter
|| IsChild( hwnd_filter
, msg
->hwnd
));
317 /***********************************************************************
318 * broadcast_message_callback
320 * Helper callback for broadcasting messages.
322 static BOOL CALLBACK
broadcast_message_callback( HWND hwnd
, LPARAM lparam
)
324 struct send_message_info
*info
= (struct send_message_info
*)lparam
;
325 if (!(GetWindowLongW( hwnd
, GWL_STYLE
) & (WS_POPUP
|WS_CAPTION
))) return TRUE
;
329 SendMessageTimeoutW( hwnd
, info
->msg
, info
->wparam
, info
->lparam
,
330 info
->flags
, info
->timeout
, NULL
);
333 SendMessageTimeoutA( hwnd
, info
->msg
, info
->wparam
, info
->lparam
,
334 info
->flags
, info
->timeout
, NULL
);
337 SendNotifyMessageW( hwnd
, info
->msg
, info
->wparam
, info
->lparam
);
340 SendMessageCallbackW( hwnd
, info
->msg
, info
->wparam
, info
->lparam
,
341 info
->callback
, info
->data
);
344 PostMessageW( hwnd
, info
->msg
, info
->wparam
, info
->lparam
);
347 ERR( "bad type %d\n", info
->type
);
354 /***********************************************************************
357 * Convert the wparam of an ASCII message to Unicode.
359 static WPARAM
map_wparam_AtoW( UINT message
, WPARAM wparam
)
364 case EM_SETPASSWORDCHAR
:
373 ch
[0] = (wparam
& 0xff);
374 ch
[1] = (wparam
>> 8);
375 MultiByteToWideChar(CP_ACP
, 0, ch
, 2, wch
, 2);
376 wparam
= MAKEWPARAM(wch
[0], wch
[1]);
383 ch
[0] = (wparam
>> 8);
384 ch
[1] = (wparam
& 0xff);
385 if (ch
[0]) MultiByteToWideChar(CP_ACP
, 0, ch
, 2, &wch
, 1);
386 else MultiByteToWideChar(CP_ACP
, 0, &ch
[1], 1, &wch
, 1);
387 wparam
= MAKEWPARAM( wch
, HIWORD(wparam
) );
395 /***********************************************************************
398 * Convert the wparam of a Unicode message to ASCII.
400 static WPARAM
map_wparam_WtoA( UINT message
, WPARAM wparam
)
405 case EM_SETPASSWORDCHAR
:
414 wch
[0] = LOWORD(wparam
);
415 wch
[1] = HIWORD(wparam
);
416 WideCharToMultiByte( CP_ACP
, 0, wch
, 2, (LPSTR
)ch
, 2, NULL
, NULL
);
417 wparam
= MAKEWPARAM( ch
[0] | (ch
[1] << 8), 0 );
422 WCHAR wch
= LOWORD(wparam
);
425 if (WideCharToMultiByte( CP_ACP
, 0, &wch
, 1, (LPSTR
)ch
, 2, NULL
, NULL
) == 2)
426 wparam
= MAKEWPARAM( (ch
[0] << 8) | ch
[1], HIWORD(wparam
) );
428 wparam
= MAKEWPARAM( ch
[0], HIWORD(wparam
) );
436 /***********************************************************************
439 * Pack a message for sending to another process.
440 * Return the size of the data we expect in the message reply.
441 * Set data->count to -1 if there is an error.
443 static size_t pack_message( HWND hwnd
, UINT message
, WPARAM wparam
, LPARAM lparam
,
444 struct packed_message
*data
)
452 CREATESTRUCTW
*cs
= (CREATESTRUCTW
*)lparam
;
453 push_data( data
, cs
, sizeof(*cs
) );
454 if (HIWORD(cs
->lpszName
)) push_string( data
, cs
->lpszName
);
455 if (HIWORD(cs
->lpszClass
)) push_string( data
, cs
->lpszClass
);
459 case WM_ASKCBFORMATNAME
:
460 return wparam
* sizeof(WCHAR
);
461 case WM_WININICHANGE
:
462 if (lparam
) push_string(data
, (LPWSTR
)lparam
);
465 case WM_DEVMODECHANGE
:
470 push_string( data
, (LPWSTR
)lparam
);
472 case WM_GETMINMAXINFO
:
473 push_data( data
, (MINMAXINFO
*)lparam
, sizeof(MINMAXINFO
) );
474 return sizeof(MINMAXINFO
);
476 push_data( data
, (DRAWITEMSTRUCT
*)lparam
, sizeof(DRAWITEMSTRUCT
) );
479 push_data( data
, (MEASUREITEMSTRUCT
*)lparam
, sizeof(MEASUREITEMSTRUCT
) );
480 return sizeof(MEASUREITEMSTRUCT
);
482 push_data( data
, (DELETEITEMSTRUCT
*)lparam
, sizeof(DELETEITEMSTRUCT
) );
485 push_data( data
, (COMPAREITEMSTRUCT
*)lparam
, sizeof(COMPAREITEMSTRUCT
) );
487 case WM_WINDOWPOSCHANGING
:
488 case WM_WINDOWPOSCHANGED
:
489 push_data( data
, (WINDOWPOS
*)lparam
, sizeof(WINDOWPOS
) );
490 return sizeof(WINDOWPOS
);
493 COPYDATASTRUCT
*cp
= (COPYDATASTRUCT
*)lparam
;
494 push_data( data
, cp
, sizeof(*cp
) );
495 if (cp
->lpData
) push_data( data
, cp
->lpData
, cp
->cbData
);
499 /* WM_NOTIFY cannot be sent across processes (MSDN) */
503 push_data( data
, (HELPINFO
*)lparam
, sizeof(HELPINFO
) );
505 case WM_STYLECHANGING
:
506 case WM_STYLECHANGED
:
507 push_data( data
, (STYLESTRUCT
*)lparam
, sizeof(STYLESTRUCT
) );
512 push_data( data
, (RECT
*)lparam
, sizeof(RECT
) );
517 NCCALCSIZE_PARAMS
*nc
= (NCCALCSIZE_PARAMS
*)lparam
;
518 push_data( data
, nc
, sizeof(*nc
) );
519 push_data( data
, nc
->lppos
, sizeof(*nc
->lppos
) );
520 return sizeof(*nc
) + sizeof(*nc
->lppos
);
523 if (lparam
) push_data( data
, (MSG
*)lparam
, sizeof(MSG
) );
525 case SBM_SETSCROLLINFO
:
526 push_data( data
, (SCROLLINFO
*)lparam
, sizeof(SCROLLINFO
) );
528 case SBM_GETSCROLLINFO
:
529 push_data( data
, (SCROLLINFO
*)lparam
, sizeof(SCROLLINFO
) );
530 return sizeof(SCROLLINFO
);
531 case SBM_GETSCROLLBARINFO
:
533 const SCROLLBARINFO
*info
= (const SCROLLBARINFO
*)lparam
;
534 size_t size
= min( info
->cbSize
, sizeof(SCROLLBARINFO
) );
535 push_data( data
, info
, size
);
543 if (wparam
) size
+= sizeof(DWORD
);
544 if (lparam
) size
+= sizeof(DWORD
);
549 case CB_GETDROPPEDCONTROLRECT
:
553 push_data( data
, (RECT
*)lparam
, sizeof(RECT
) );
557 WORD
*pw
= (WORD
*)lparam
;
558 push_data( data
, pw
, sizeof(*pw
) );
559 return *pw
* sizeof(WCHAR
);
563 if (wparam
) push_data( data
, (UINT
*)lparam
, sizeof(UINT
) * wparam
);
566 case CB_INSERTSTRING
:
568 case CB_FINDSTRINGEXACT
:
569 case CB_SELECTSTRING
:
570 if (combobox_has_strings( hwnd
)) push_string( data
, (LPWSTR
)lparam
);
573 if (!combobox_has_strings( hwnd
)) return sizeof(ULONG_PTR
);
574 return (SendMessageW( hwnd
, CB_GETLBTEXTLEN
, wparam
, 0 ) + 1) * sizeof(WCHAR
);
576 case LB_INSERTSTRING
:
578 case LB_FINDSTRINGEXACT
:
579 case LB_SELECTSTRING
:
580 if (listbox_has_strings( hwnd
)) push_string( data
, (LPWSTR
)lparam
);
583 if (!listbox_has_strings( hwnd
)) return sizeof(ULONG_PTR
);
584 return (SendMessageW( hwnd
, LB_GETTEXTLEN
, wparam
, 0 ) + 1) * sizeof(WCHAR
);
586 return wparam
* sizeof(UINT
);
588 push_data( data
, (MDINEXTMENU
*)lparam
, sizeof(MDINEXTMENU
) );
589 return sizeof(MDINEXTMENU
);
592 push_data( data
, (RECT
*)lparam
, sizeof(RECT
) );
596 MDICREATESTRUCTW
*cs
= (MDICREATESTRUCTW
*)lparam
;
597 push_data( data
, cs
, sizeof(*cs
) );
598 if (HIWORD(cs
->szTitle
)) push_string( data
, cs
->szTitle
);
599 if (HIWORD(cs
->szClass
)) push_string( data
, cs
->szClass
);
602 case WM_MDIGETACTIVE
:
603 if (lparam
) return sizeof(BOOL
);
605 case WM_WINE_SETWINDOWPOS
:
606 push_data( data
, (WINDOWPOS
*)lparam
, sizeof(WINDOWPOS
) );
608 case WM_WINE_KEYBOARD_LL_HOOK
:
609 push_data( data
, (KBDLLHOOKSTRUCT
*)lparam
, sizeof(KBDLLHOOKSTRUCT
) );
611 case WM_WINE_MOUSE_LL_HOOK
:
612 push_data( data
, (MSLLHOOKSTRUCT
*)lparam
, sizeof(MSLLHOOKSTRUCT
) );
615 if (!wparam
) return 0;
618 /* these contain an HFONT */
621 /* these contain an HDC */
623 case WM_ICONERASEBKGND
:
625 case WM_CTLCOLORMSGBOX
:
626 case WM_CTLCOLOREDIT
:
627 case WM_CTLCOLORLISTBOX
:
630 case WM_CTLCOLORSCROLLBAR
:
631 case WM_CTLCOLORSTATIC
:
634 /* these contain an HGLOBAL */
635 case WM_PAINTCLIPBOARD
:
636 case WM_SIZECLIPBOARD
:
637 /* these contain HICON */
640 case WM_QUERYDRAGICON
:
641 case WM_QUERYPARKICON
:
642 /* these contain pointers */
644 case WM_QUERYDROPOBJECT
:
648 case WM_DEVICECHANGE
:
649 FIXME( "msg %x (%s) not supported yet\n", message
, SPY_GetMsgName(message
, hwnd
) );
657 /***********************************************************************
660 * Unpack a message received from another process.
662 static BOOL
unpack_message( HWND hwnd
, UINT message
, WPARAM
*wparam
, LPARAM
*lparam
,
663 void **buffer
, size_t size
)
672 CREATESTRUCTW
*cs
= *buffer
;
673 WCHAR
*str
= (WCHAR
*)(cs
+ 1);
674 if (size
< sizeof(*cs
)) return FALSE
;
676 if (HIWORD(cs
->lpszName
))
678 if (!check_string( str
, size
)) return FALSE
;
680 size
-= (strlenW(str
) + 1) * sizeof(WCHAR
);
681 str
+= strlenW(str
) + 1;
683 if (HIWORD(cs
->lpszClass
))
685 if (!check_string( str
, size
)) return FALSE
;
691 case WM_ASKCBFORMATNAME
:
692 if (!get_buffer_space( buffer
, (*wparam
* sizeof(WCHAR
)) )) return FALSE
;
694 case WM_WININICHANGE
:
695 if (!*lparam
) return TRUE
;
698 case WM_DEVMODECHANGE
:
703 if (!check_string( *buffer
, size
)) return FALSE
;
705 case WM_GETMINMAXINFO
:
706 minsize
= sizeof(MINMAXINFO
);
709 minsize
= sizeof(DRAWITEMSTRUCT
);
712 minsize
= sizeof(MEASUREITEMSTRUCT
);
715 minsize
= sizeof(DELETEITEMSTRUCT
);
718 minsize
= sizeof(COMPAREITEMSTRUCT
);
720 case WM_WINDOWPOSCHANGING
:
721 case WM_WINDOWPOSCHANGED
:
722 case WM_WINE_SETWINDOWPOS
:
723 minsize
= sizeof(WINDOWPOS
);
727 COPYDATASTRUCT
*cp
= *buffer
;
728 if (size
< sizeof(*cp
)) return FALSE
;
731 minsize
= sizeof(*cp
) + cp
->cbData
;
737 /* WM_NOTIFY cannot be sent across processes (MSDN) */
740 minsize
= sizeof(HELPINFO
);
742 case WM_STYLECHANGING
:
743 case WM_STYLECHANGED
:
744 minsize
= sizeof(STYLESTRUCT
);
747 if (!*wparam
) minsize
= sizeof(RECT
);
750 NCCALCSIZE_PARAMS
*nc
= *buffer
;
751 if (size
< sizeof(*nc
) + sizeof(*nc
->lppos
)) return FALSE
;
752 nc
->lppos
= (WINDOWPOS
*)(nc
+ 1);
756 if (!*lparam
) return TRUE
;
757 minsize
= sizeof(MSG
);
759 case SBM_SETSCROLLINFO
:
760 minsize
= sizeof(SCROLLINFO
);
762 case SBM_GETSCROLLINFO
:
763 if (!get_buffer_space( buffer
, sizeof(SCROLLINFO
))) return FALSE
;
765 case SBM_GETSCROLLBARINFO
:
766 if (!get_buffer_space( buffer
, sizeof(SCROLLBARINFO
))) return FALSE
;
771 if (*wparam
|| *lparam
)
773 if (!get_buffer_space( buffer
, 2*sizeof(DWORD
) )) return FALSE
;
774 if (*wparam
) *wparam
= (WPARAM
)*buffer
;
775 if (*lparam
) *lparam
= (LPARAM
)((DWORD
*)*buffer
+ 1);
780 case CB_GETDROPPEDCONTROLRECT
:
781 if (!get_buffer_space( buffer
, sizeof(RECT
) )) return FALSE
;
785 minsize
= sizeof(RECT
);
790 if (size
< sizeof(WORD
)) return FALSE
;
791 len
= *(WORD
*)*buffer
;
792 if (!get_buffer_space( buffer
, (len
+ 1) * sizeof(WCHAR
) )) return FALSE
;
793 *lparam
= (LPARAM
)*buffer
+ sizeof(WORD
); /* don't erase WORD at start of buffer */
798 if (!*wparam
) return TRUE
;
799 minsize
= *wparam
* sizeof(UINT
);
802 case CB_INSERTSTRING
:
804 case CB_FINDSTRINGEXACT
:
805 case CB_SELECTSTRING
:
807 case LB_INSERTSTRING
:
809 case LB_FINDSTRINGEXACT
:
810 case LB_SELECTSTRING
:
811 if (!*buffer
) return TRUE
;
812 if (!check_string( *buffer
, size
)) return FALSE
;
816 size
= sizeof(ULONG_PTR
);
817 if (combobox_has_strings( hwnd
))
818 size
= (SendMessageW( hwnd
, CB_GETLBTEXTLEN
, *wparam
, 0 ) + 1) * sizeof(WCHAR
);
819 if (!get_buffer_space( buffer
, size
)) return FALSE
;
824 size
= sizeof(ULONG_PTR
);
825 if (listbox_has_strings( hwnd
))
826 size
= (SendMessageW( hwnd
, LB_GETTEXTLEN
, *wparam
, 0 ) + 1) * sizeof(WCHAR
);
827 if (!get_buffer_space( buffer
, size
)) return FALSE
;
831 if (!get_buffer_space( buffer
, *wparam
* sizeof(UINT
) )) return FALSE
;
834 minsize
= sizeof(MDINEXTMENU
);
835 if (!get_buffer_space( buffer
, sizeof(MDINEXTMENU
) )) return FALSE
;
839 minsize
= sizeof(RECT
);
840 if (!get_buffer_space( buffer
, sizeof(RECT
) )) return FALSE
;
844 MDICREATESTRUCTW
*cs
= *buffer
;
845 WCHAR
*str
= (WCHAR
*)(cs
+ 1);
846 if (size
< sizeof(*cs
)) return FALSE
;
848 if (HIWORD(cs
->szTitle
))
850 if (!check_string( str
, size
)) return FALSE
;
852 size
-= (strlenW(str
) + 1) * sizeof(WCHAR
);
853 str
+= strlenW(str
) + 1;
855 if (HIWORD(cs
->szClass
))
857 if (!check_string( str
, size
)) return FALSE
;
862 case WM_MDIGETACTIVE
:
863 if (!*lparam
) return TRUE
;
864 if (!get_buffer_space( buffer
, sizeof(BOOL
) )) return FALSE
;
866 case WM_WINE_KEYBOARD_LL_HOOK
:
867 minsize
= sizeof(KBDLLHOOKSTRUCT
);
869 case WM_WINE_MOUSE_LL_HOOK
:
870 minsize
= sizeof(MSLLHOOKSTRUCT
);
873 if (!*wparam
) return TRUE
;
876 /* these contain an HFONT */
879 /* these contain an HDC */
881 case WM_ICONERASEBKGND
:
883 case WM_CTLCOLORMSGBOX
:
884 case WM_CTLCOLOREDIT
:
885 case WM_CTLCOLORLISTBOX
:
888 case WM_CTLCOLORSCROLLBAR
:
889 case WM_CTLCOLORSTATIC
:
892 /* these contain an HGLOBAL */
893 case WM_PAINTCLIPBOARD
:
894 case WM_SIZECLIPBOARD
:
895 /* these contain HICON */
898 case WM_QUERYDRAGICON
:
899 case WM_QUERYPARKICON
:
900 /* these contain pointers */
902 case WM_QUERYDROPOBJECT
:
906 case WM_DEVICECHANGE
:
907 FIXME( "msg %x (%s) not supported yet\n", message
, SPY_GetMsgName(message
, hwnd
) );
911 return TRUE
; /* message doesn't need any unpacking */
914 /* default exit for most messages: check minsize and store buffer in lparam */
915 if (size
< minsize
) return FALSE
;
916 *lparam
= (LPARAM
)*buffer
;
921 /***********************************************************************
924 * Pack a reply to a message for sending to another process.
926 static void pack_reply( HWND hwnd
, UINT message
, WPARAM wparam
, LPARAM lparam
,
927 LRESULT res
, struct packed_message
*data
)
934 push_data( data
, (CREATESTRUCTW
*)lparam
, sizeof(CREATESTRUCTW
) );
939 push_data( data
, (WCHAR
*)lparam
, (res
+ 1) * sizeof(WCHAR
) );
941 case WM_GETMINMAXINFO
:
942 push_data( data
, (MINMAXINFO
*)lparam
, sizeof(MINMAXINFO
) );
945 push_data( data
, (MEASUREITEMSTRUCT
*)lparam
, sizeof(MEASUREITEMSTRUCT
) );
947 case WM_WINDOWPOSCHANGING
:
948 case WM_WINDOWPOSCHANGED
:
949 push_data( data
, (WINDOWPOS
*)lparam
, sizeof(WINDOWPOS
) );
952 if (lparam
) push_data( data
, (MSG
*)lparam
, sizeof(MSG
) );
954 case SBM_GETSCROLLINFO
:
955 push_data( data
, (SCROLLINFO
*)lparam
, sizeof(SCROLLINFO
) );
959 case CB_GETDROPPEDCONTROLRECT
:
962 push_data( data
, (RECT
*)lparam
, sizeof(RECT
) );
966 WORD
*ptr
= (WORD
*)lparam
;
967 push_data( data
, ptr
, ptr
[-1] * sizeof(WCHAR
) );
971 push_data( data
, (UINT
*)lparam
, wparam
* sizeof(UINT
) );
973 case WM_MDIGETACTIVE
:
974 if (lparam
) push_data( data
, (BOOL
*)lparam
, sizeof(BOOL
) );
978 push_data( data
, (RECT
*)lparam
, sizeof(RECT
) );
981 NCCALCSIZE_PARAMS
*nc
= (NCCALCSIZE_PARAMS
*)lparam
;
982 push_data( data
, nc
, sizeof(*nc
) );
983 push_data( data
, nc
->lppos
, sizeof(*nc
->lppos
) );
989 if (wparam
) push_data( data
, (DWORD
*)wparam
, sizeof(DWORD
) );
990 if (lparam
) push_data( data
, (DWORD
*)lparam
, sizeof(DWORD
) );
993 push_data( data
, (MDINEXTMENU
*)lparam
, sizeof(MDINEXTMENU
) );
996 push_data( data
, (MDICREATESTRUCTW
*)lparam
, sizeof(MDICREATESTRUCTW
) );
998 case WM_ASKCBFORMATNAME
:
999 push_data( data
, (WCHAR
*)lparam
, (strlenW((WCHAR
*)lparam
) + 1) * sizeof(WCHAR
) );
1005 /***********************************************************************
1008 * Unpack a message reply received from another process.
1010 static void unpack_reply( HWND hwnd
, UINT message
, WPARAM wparam
, LPARAM lparam
,
1011 void *buffer
, size_t size
)
1018 CREATESTRUCTW
*cs
= (CREATESTRUCTW
*)lparam
;
1019 LPCWSTR name
= cs
->lpszName
, class = cs
->lpszClass
;
1020 memcpy( cs
, buffer
, min( sizeof(*cs
), size
));
1021 cs
->lpszName
= name
; /* restore the original pointers */
1022 cs
->lpszClass
= class;
1026 case WM_ASKCBFORMATNAME
:
1027 memcpy( (WCHAR
*)lparam
, buffer
, min( wparam
*sizeof(WCHAR
), size
));
1029 case WM_GETMINMAXINFO
:
1030 memcpy( (MINMAXINFO
*)lparam
, buffer
, min( sizeof(MINMAXINFO
), size
));
1032 case WM_MEASUREITEM
:
1033 memcpy( (MEASUREITEMSTRUCT
*)lparam
, buffer
, min( sizeof(MEASUREITEMSTRUCT
), size
));
1035 case WM_WINDOWPOSCHANGING
:
1036 case WM_WINDOWPOSCHANGED
:
1037 memcpy( (WINDOWPOS
*)lparam
, buffer
, min( sizeof(WINDOWPOS
), size
));
1040 if (lparam
) memcpy( (MSG
*)lparam
, buffer
, min( sizeof(MSG
), size
));
1042 case SBM_GETSCROLLINFO
:
1043 memcpy( (SCROLLINFO
*)lparam
, buffer
, min( sizeof(SCROLLINFO
), size
));
1045 case SBM_GETSCROLLBARINFO
:
1046 memcpy( (SCROLLBARINFO
*)lparam
, buffer
, min( sizeof(SCROLLBARINFO
), size
));
1049 case CB_GETDROPPEDCONTROLRECT
:
1050 case LB_GETITEMRECT
:
1053 memcpy( (RECT
*)lparam
, buffer
, min( sizeof(RECT
), size
));
1056 size
= min( size
, (size_t)*(WORD
*)lparam
);
1057 memcpy( (WCHAR
*)lparam
, buffer
, size
);
1059 case LB_GETSELITEMS
:
1060 memcpy( (UINT
*)lparam
, buffer
, min( wparam
*sizeof(UINT
), size
));
1064 memcpy( (WCHAR
*)lparam
, buffer
, size
);
1067 memcpy( (MDINEXTMENU
*)lparam
, buffer
, min( sizeof(MDINEXTMENU
), size
));
1069 case WM_MDIGETACTIVE
:
1070 if (lparam
) memcpy( (BOOL
*)lparam
, buffer
, min( sizeof(BOOL
), size
));
1074 memcpy( (RECT
*)lparam
, buffer
, min( sizeof(RECT
), size
));
1077 NCCALCSIZE_PARAMS
*nc
= (NCCALCSIZE_PARAMS
*)lparam
;
1078 WINDOWPOS
*wp
= nc
->lppos
;
1079 memcpy( nc
, buffer
, min( sizeof(*nc
), size
));
1080 if (size
> sizeof(*nc
))
1082 size
-= sizeof(*nc
);
1083 memcpy( wp
, (NCCALCSIZE_PARAMS
*)buffer
+ 1, min( sizeof(*wp
), size
));
1085 nc
->lppos
= wp
; /* restore the original pointer */
1093 memcpy( (DWORD
*)wparam
, buffer
, min( sizeof(DWORD
), size
));
1094 if (size
<= sizeof(DWORD
)) break;
1095 size
-= sizeof(DWORD
);
1096 buffer
= (DWORD
*)buffer
+ 1;
1098 if (lparam
) memcpy( (DWORD
*)lparam
, buffer
, min( sizeof(DWORD
), size
));
1102 MDICREATESTRUCTW
*cs
= (MDICREATESTRUCTW
*)lparam
;
1103 LPCWSTR title
= cs
->szTitle
, class = cs
->szClass
;
1104 memcpy( cs
, buffer
, min( sizeof(*cs
), size
));
1105 cs
->szTitle
= title
; /* restore the original pointers */
1106 cs
->szClass
= class;
1110 ERR( "should not happen: unexpected message %x\n", message
);
1116 /***********************************************************************
1119 * Send a reply to a sent message.
1121 static void reply_message( struct received_message_info
*info
, LRESULT result
, BOOL remove
)
1123 struct packed_message data
;
1124 int i
, replied
= info
->flags
& ISMEX_REPLIED
;
1126 if (info
->flags
& ISMEX_NOTIFY
) return; /* notify messages don't get replies */
1127 if (!remove
&& replied
) return; /* replied already */
1130 info
->flags
|= ISMEX_REPLIED
;
1132 if (info
->type
== MSG_OTHER_PROCESS
&& !replied
)
1134 pack_reply( info
->msg
.hwnd
, info
->msg
.message
, info
->msg
.wParam
,
1135 info
->msg
.lParam
, result
, &data
);
1138 SERVER_START_REQ( reply_message
)
1140 req
->result
= result
;
1141 req
->remove
= remove
;
1142 for (i
= 0; i
< data
.count
; i
++) wine_server_add_data( req
, data
.data
[i
], data
.size
[i
] );
1143 wine_server_call( req
);
1149 /***********************************************************************
1150 * handle_internal_message
1152 * Handle an internal Wine message instead of calling the window proc.
1154 static LRESULT
handle_internal_message( HWND hwnd
, UINT msg
, WPARAM wparam
, LPARAM lparam
)
1156 if (hwnd
== GetDesktopWindow()) return 0;
1159 case WM_WINE_DESTROYWINDOW
:
1160 return WIN_DestroyWindow( hwnd
);
1161 case WM_WINE_SETWINDOWPOS
:
1162 return USER_Driver
->pSetWindowPos( (WINDOWPOS
*)lparam
);
1163 case WM_WINE_SHOWWINDOW
:
1164 return ShowWindow( hwnd
, wparam
);
1165 case WM_WINE_SETPARENT
:
1166 return (LRESULT
)SetParent( hwnd
, (HWND
)wparam
);
1167 case WM_WINE_SETWINDOWLONG
:
1168 return (LRESULT
)SetWindowLongW( hwnd
, wparam
, lparam
);
1169 case WM_WINE_ENABLEWINDOW
:
1170 return EnableWindow( hwnd
, wparam
);
1171 case WM_WINE_SETACTIVEWINDOW
:
1172 return (LRESULT
)SetActiveWindow( (HWND
)wparam
);
1173 case WM_WINE_KEYBOARD_LL_HOOK
:
1174 return HOOK_CallHooks( WH_KEYBOARD_LL
, HC_ACTION
, wparam
, lparam
, TRUE
);
1175 case WM_WINE_MOUSE_LL_HOOK
:
1176 return HOOK_CallHooks( WH_MOUSE_LL
, HC_ACTION
, wparam
, lparam
, TRUE
);
1178 if (msg
>= WM_WINE_FIRST_DRIVER_MSG
&& msg
<= WM_WINE_LAST_DRIVER_MSG
)
1179 return USER_Driver
->pWindowMessage( hwnd
, msg
, wparam
, lparam
);
1180 FIXME( "unknown internal message %x\n", msg
);
1185 /* since the WM_DDE_ACK response to a WM_DDE_EXECUTE message should contain the handle
1186 * to the memory handle, we keep track (in the server side) of all pairs of handle
1187 * used (the client passes its value and the content of the memory handle), and
1188 * the server stored both values (the client, and the local one, created after the
1189 * content). When a ACK message is generated, the list of pair is searched for a
1190 * matching pair, so that the client memory handle can be returned.
1193 HGLOBAL client_hMem
;
1194 HGLOBAL server_hMem
;
1197 static struct DDE_pair
* dde_pairs
;
1198 static int dde_num_alloc
;
1199 static int dde_num_used
;
1201 static CRITICAL_SECTION dde_crst
;
1202 static CRITICAL_SECTION_DEBUG critsect_debug
=
1205 { &critsect_debug
.ProcessLocksList
, &critsect_debug
.ProcessLocksList
},
1206 0, 0, { (DWORD_PTR
)(__FILE__
": dde_crst") }
1208 static CRITICAL_SECTION dde_crst
= { &critsect_debug
, -1, 0, 0, 0, 0 };
1210 static BOOL
dde_add_pair(HGLOBAL chm
, HGLOBAL shm
)
1215 EnterCriticalSection(&dde_crst
);
1217 /* now remember the pair of hMem on both sides */
1218 if (dde_num_used
== dde_num_alloc
)
1220 struct DDE_pair
* tmp
;
1222 tmp
= HeapReAlloc( GetProcessHeap(), 0, dde_pairs
,
1223 (dde_num_alloc
+ GROWBY
) * sizeof(struct DDE_pair
));
1225 tmp
= HeapAlloc( GetProcessHeap(), 0,
1226 (dde_num_alloc
+ GROWBY
) * sizeof(struct DDE_pair
));
1230 LeaveCriticalSection(&dde_crst
);
1234 /* zero out newly allocated part */
1235 memset(&dde_pairs
[dde_num_alloc
], 0, GROWBY
* sizeof(struct DDE_pair
));
1236 dde_num_alloc
+= GROWBY
;
1239 for (i
= 0; i
< dde_num_alloc
; i
++)
1241 if (dde_pairs
[i
].server_hMem
== 0)
1243 dde_pairs
[i
].client_hMem
= chm
;
1244 dde_pairs
[i
].server_hMem
= shm
;
1249 LeaveCriticalSection(&dde_crst
);
1253 static HGLOBAL
dde_get_pair(HGLOBAL shm
)
1258 EnterCriticalSection(&dde_crst
);
1259 for (i
= 0; i
< dde_num_alloc
; i
++)
1261 if (dde_pairs
[i
].server_hMem
== shm
)
1263 /* free this pair */
1264 dde_pairs
[i
].server_hMem
= 0;
1266 ret
= dde_pairs
[i
].client_hMem
;
1270 LeaveCriticalSection(&dde_crst
);
1274 /***********************************************************************
1277 * Post a DDE message
1279 static BOOL
post_dde_message( DWORD dest_tid
, struct packed_message
*data
, const struct send_message_info
*info
)
1283 UINT_PTR uiLo
, uiHi
;
1285 HGLOBAL hunlock
= 0;
1289 if (!UnpackDDElParam( info
->msg
, info
->lparam
, &uiLo
, &uiHi
))
1295 /* DDE messages which don't require packing are:
1304 /* uiHi should contain a hMem from WM_DDE_EXECUTE */
1305 HGLOBAL h
= dde_get_pair( (HANDLE
)uiHi
);
1308 /* send back the value of h on the other side */
1309 push_data( data
, &h
, sizeof(HGLOBAL
) );
1311 TRACE( "send dde-ack %x %08x => %p\n", uiLo
, uiHi
, h
);
1316 /* uiHi should contain either an atom or 0 */
1317 TRACE( "send dde-ack %x atom=%x\n", uiLo
, uiHi
);
1318 lp
= MAKELONG( uiLo
, uiHi
);
1327 size
= GlobalSize( (HGLOBAL
)uiLo
) ;
1328 if ((info
->msg
== WM_DDE_ADVISE
&& size
< sizeof(DDEADVISE
)) ||
1329 (info
->msg
== WM_DDE_DATA
&& size
< sizeof(DDEDATA
)) ||
1330 (info
->msg
== WM_DDE_POKE
&& size
< sizeof(DDEPOKE
))
1334 else if (info
->msg
!= WM_DDE_DATA
) return FALSE
;
1339 if ((ptr
= GlobalLock( (HGLOBAL
)uiLo
) ))
1341 DDEDATA
*dde_data
= (DDEDATA
*)ptr
;
1342 TRACE("unused %d, fResponse %d, fRelease %d, fDeferUpd %d, fAckReq %d, cfFormat %d\n",
1343 dde_data
->unused
, dde_data
->fResponse
, dde_data
->fRelease
,
1344 dde_data
->reserved
, dde_data
->fAckReq
, dde_data
->cfFormat
);
1345 push_data( data
, ptr
, size
);
1346 hunlock
= (HGLOBAL
)uiLo
;
1349 TRACE( "send ddepack %u %x\n", size
, uiHi
);
1351 case WM_DDE_EXECUTE
:
1354 if ((ptr
= GlobalLock( (HGLOBAL
)info
->lparam
) ))
1356 push_data(data
, ptr
, GlobalSize( (HGLOBAL
)info
->lparam
));
1357 /* so that the other side can send it back on ACK */
1359 hunlock
= (HGLOBAL
)info
->lparam
;
1364 SERVER_START_REQ( send_message
)
1367 req
->type
= info
->type
;
1369 req
->win
= info
->hwnd
;
1370 req
->msg
= info
->msg
;
1371 req
->wparam
= info
->wparam
;
1373 req
->time
= GetCurrentTime();
1375 for (i
= 0; i
< data
->count
; i
++)
1376 wine_server_add_data( req
, data
->data
[i
], data
->size
[i
] );
1377 if ((res
= wine_server_call( req
)))
1379 if (res
== STATUS_INVALID_PARAMETER
)
1380 /* FIXME: find a STATUS_ value for this one */
1381 SetLastError( ERROR_INVALID_THREAD_ID
);
1383 SetLastError( RtlNtStatusToDosError(res
) );
1386 FreeDDElParam(info
->msg
, info
->lparam
);
1389 if (hunlock
) GlobalUnlock(hunlock
);
1394 /***********************************************************************
1395 * unpack_dde_message
1397 * Unpack a posted DDE message received from another process.
1399 static BOOL
unpack_dde_message( HWND hwnd
, UINT message
, WPARAM
*wparam
, LPARAM
*lparam
,
1400 void **buffer
, size_t size
)
1402 UINT_PTR uiLo
, uiHi
;
1411 /* hMem is being passed */
1412 if (size
!= sizeof(HGLOBAL
)) return FALSE
;
1413 if (!buffer
|| !*buffer
) return FALSE
;
1415 memcpy( &hMem
, *buffer
, size
);
1416 uiHi
= (UINT_PTR
)hMem
;
1417 TRACE("recv dde-ack %x mem=%x[%lx]\n", uiLo
, uiHi
, GlobalSize( hMem
));
1421 uiLo
= LOWORD( *lparam
);
1422 uiHi
= HIWORD( *lparam
);
1423 TRACE("recv dde-ack %x atom=%x\n", uiLo
, uiHi
);
1425 *lparam
= PackDDElParam( WM_DDE_ACK
, uiLo
, uiHi
);
1430 if ((!buffer
|| !*buffer
) && message
!= WM_DDE_DATA
) return FALSE
;
1432 TRACE( "recv ddepack %u %x\n", size
, uiHi
);
1435 if (!(hMem
= GlobalAlloc( GMEM_MOVEABLE
|GMEM_DDESHARE
, size
)))
1437 if ((ptr
= GlobalLock( hMem
)))
1439 memcpy( ptr
, *buffer
, size
);
1440 GlobalUnlock( hMem
);
1448 uiLo
= (UINT_PTR
)hMem
;
1450 *lparam
= PackDDElParam( message
, uiLo
, uiHi
);
1452 case WM_DDE_EXECUTE
:
1455 if (!buffer
|| !*buffer
) return FALSE
;
1456 if (!(hMem
= GlobalAlloc( GMEM_MOVEABLE
|GMEM_DDESHARE
, size
))) return FALSE
;
1457 if ((ptr
= GlobalLock( hMem
)))
1459 memcpy( ptr
, *buffer
, size
);
1460 GlobalUnlock( hMem
);
1461 TRACE( "exec: pairing c=%08lx s=%08lx\n", *lparam
, (DWORD
)hMem
);
1462 if (!dde_add_pair( (HGLOBAL
)*lparam
, hMem
))
1473 } else return FALSE
;
1474 *lparam
= (LPARAM
)hMem
;
1480 /***********************************************************************
1483 * Call a window procedure and the corresponding hooks.
1485 static LRESULT
call_window_proc( HWND hwnd
, UINT msg
, WPARAM wparam
, LPARAM lparam
,
1486 BOOL unicode
, BOOL same_thread
)
1488 struct user_thread_info
*thread_info
= get_user_thread_info();
1492 CWPRETSTRUCT cwpret
;
1494 if (thread_info
->recursion_count
> MAX_SENDMSG_RECURSION
) return 0;
1495 thread_info
->recursion_count
++;
1497 if (msg
& 0x80000000)
1499 result
= handle_internal_message( hwnd
, msg
, wparam
, lparam
);
1503 /* first the WH_CALLWNDPROC hook */
1504 hwnd
= WIN_GetFullHandle( hwnd
);
1505 cwp
.lParam
= lparam
;
1506 cwp
.wParam
= wparam
;
1509 HOOK_CallHooks( WH_CALLWNDPROC
, HC_ACTION
, same_thread
, (LPARAM
)&cwp
, unicode
);
1511 /* now call the window procedure */
1514 if (!(winproc
= (WNDPROC
)GetWindowLongPtrW( hwnd
, GWLP_WNDPROC
))) goto done
;
1515 result
= CallWindowProcW( winproc
, hwnd
, msg
, wparam
, lparam
);
1519 if (!(winproc
= (WNDPROC
)GetWindowLongPtrA( hwnd
, GWLP_WNDPROC
))) goto done
;
1520 result
= CallWindowProcA( winproc
, hwnd
, msg
, wparam
, lparam
);
1523 /* and finally the WH_CALLWNDPROCRET hook */
1524 cwpret
.lResult
= result
;
1525 cwpret
.lParam
= lparam
;
1526 cwpret
.wParam
= wparam
;
1527 cwpret
.message
= msg
;
1529 HOOK_CallHooks( WH_CALLWNDPROCRET
, HC_ACTION
, same_thread
, (LPARAM
)&cwpret
, unicode
);
1531 thread_info
->recursion_count
--;
1536 /***********************************************************************
1537 * send_parent_notify
1539 * Send a WM_PARENTNOTIFY to all ancestors of the given window, unless
1540 * the window has the WS_EX_NOPARENTNOTIFY style.
1542 static void send_parent_notify( HWND hwnd
, WORD event
, WORD idChild
, POINT pt
)
1544 /* pt has to be in the client coordinates of the parent window */
1545 MapWindowPoints( 0, hwnd
, &pt
, 1 );
1550 if (!(GetWindowLongW( hwnd
, GWL_STYLE
) & WS_CHILD
)) break;
1551 if (GetWindowLongW( hwnd
, GWL_EXSTYLE
) & WS_EX_NOPARENTNOTIFY
) break;
1552 if (!(parent
= GetParent(hwnd
))) break;
1553 MapWindowPoints( hwnd
, parent
, &pt
, 1 );
1555 SendMessageW( hwnd
, WM_PARENTNOTIFY
,
1556 MAKEWPARAM( event
, idChild
), MAKELPARAM( pt
.x
, pt
.y
) );
1561 /***********************************************************************
1562 * accept_hardware_message
1564 * Tell the server we have passed the message to the app
1565 * (even though we may end up dropping it later on)
1567 static void accept_hardware_message( UINT hw_id
, BOOL remove
, HWND new_hwnd
)
1569 SERVER_START_REQ( accept_hardware_message
)
1572 req
->remove
= remove
;
1573 req
->new_win
= new_hwnd
;
1574 if (wine_server_call( req
))
1575 FIXME("Failed to reply to MSG_HARDWARE message. Message may not be removed from queue.\n");
1581 /***********************************************************************
1582 * process_keyboard_message
1584 * returns TRUE if the contents of 'msg' should be passed to the application
1586 static BOOL
process_keyboard_message( MSG
*msg
, UINT hw_id
, HWND hwnd_filter
,
1587 UINT first
, UINT last
, BOOL remove
)
1591 /* FIXME: is this really the right place for this hook? */
1592 event
.message
= msg
->message
;
1593 event
.hwnd
= msg
->hwnd
;
1594 event
.time
= msg
->time
;
1595 event
.paramL
= (msg
->wParam
& 0xFF) | (HIWORD(msg
->lParam
) << 8);
1596 event
.paramH
= msg
->lParam
& 0x7FFF;
1597 if (HIWORD(msg
->lParam
) & 0x0100) event
.paramH
|= 0x8000; /* special_key - bit */
1598 HOOK_CallHooks( WH_JOURNALRECORD
, HC_ACTION
, 0, (LPARAM
)&event
, TRUE
);
1600 /* check message filters */
1601 if (msg
->message
< first
|| msg
->message
> last
) return FALSE
;
1602 if (!check_hwnd_filter( msg
, hwnd_filter
)) return FALSE
;
1606 /* Handle F1 key by sending out WM_HELP message */
1607 if ((msg
->message
== WM_KEYUP
) &&
1608 (msg
->wParam
== VK_F1
) &&
1609 (msg
->hwnd
!= GetDesktopWindow()) &&
1610 !MENU_IsMenuActive())
1613 hi
.cbSize
= sizeof(HELPINFO
);
1614 hi
.iContextType
= HELPINFO_WINDOW
;
1615 hi
.iCtrlId
= GetWindowLongPtrA( msg
->hwnd
, GWLP_ID
);
1616 hi
.hItemHandle
= msg
->hwnd
;
1617 hi
.dwContextId
= GetWindowContextHelpId( msg
->hwnd
);
1618 hi
.MousePos
= msg
->pt
;
1619 SendMessageW( msg
->hwnd
, WM_HELP
, 0, (LPARAM
)&hi
);
1623 if (HOOK_CallHooks( WH_KEYBOARD
, remove
? HC_ACTION
: HC_NOREMOVE
,
1624 LOWORD(msg
->wParam
), msg
->lParam
, TRUE
))
1626 /* skip this message */
1627 HOOK_CallHooks( WH_CBT
, HCBT_KEYSKIPPED
, LOWORD(msg
->wParam
), msg
->lParam
, TRUE
);
1628 accept_hardware_message( hw_id
, TRUE
, 0 );
1631 accept_hardware_message( hw_id
, remove
, 0 );
1636 /***********************************************************************
1637 * process_mouse_message
1639 * returns TRUE if the contents of 'msg' should be passed to the application
1641 static BOOL
process_mouse_message( MSG
*msg
, UINT hw_id
, ULONG_PTR extra_info
, HWND hwnd_filter
,
1642 UINT first
, UINT last
, BOOL remove
)
1651 MOUSEHOOKSTRUCT hook
;
1654 /* find the window to dispatch this mouse message to */
1656 GetGUIThreadInfo( GetCurrentThreadId(), &info
);
1657 if (info
.hwndCapture
)
1660 msg
->hwnd
= info
.hwndCapture
;
1664 msg
->hwnd
= WINPOS_WindowFromPoint( msg
->hwnd
, msg
->pt
, &hittest
);
1667 if (!msg
->hwnd
|| !WIN_IsCurrentThread( msg
->hwnd
))
1669 accept_hardware_message( hw_id
, TRUE
, msg
->hwnd
);
1673 /* FIXME: is this really the right place for this hook? */
1674 event
.message
= msg
->message
;
1675 event
.time
= msg
->time
;
1676 event
.hwnd
= msg
->hwnd
;
1677 event
.paramL
= msg
->pt
.x
;
1678 event
.paramH
= msg
->pt
.y
;
1679 HOOK_CallHooks( WH_JOURNALRECORD
, HC_ACTION
, 0, (LPARAM
)&event
, TRUE
);
1681 if (!check_hwnd_filter( msg
, hwnd_filter
)) return FALSE
;
1684 message
= msg
->message
;
1685 /* Note: windows has no concept of a non-client wheel message */
1686 if (message
!= WM_MOUSEWHEEL
)
1688 if (hittest
!= HTCLIENT
)
1690 message
+= WM_NCMOUSEMOVE
- WM_MOUSEMOVE
;
1691 msg
->wParam
= hittest
;
1695 /* coordinates don't get translated while tracking a menu */
1696 /* FIXME: should differentiate popups and top-level menus */
1697 if (!(info
.flags
& GUI_INMENUMODE
))
1698 ScreenToClient( msg
->hwnd
, &pt
);
1701 msg
->lParam
= MAKELONG( pt
.x
, pt
.y
);
1703 /* translate double clicks */
1705 if ((msg
->message
== WM_LBUTTONDOWN
) ||
1706 (msg
->message
== WM_RBUTTONDOWN
) ||
1707 (msg
->message
== WM_MBUTTONDOWN
) ||
1708 (msg
->message
== WM_XBUTTONDOWN
))
1710 BOOL update
= remove
;
1712 /* translate double clicks -
1713 * note that ...MOUSEMOVEs can slip in between
1714 * ...BUTTONDOWN and ...BUTTONDBLCLK messages */
1716 if ((info
.flags
& (GUI_INMENUMODE
|GUI_INMOVESIZE
)) ||
1717 hittest
!= HTCLIENT
||
1718 (GetClassLongA( msg
->hwnd
, GCL_STYLE
) & CS_DBLCLKS
))
1720 if ((msg
->message
== clk_msg
.message
) &&
1721 (msg
->hwnd
== clk_msg
.hwnd
) &&
1722 (msg
->wParam
== clk_msg
.wParam
) &&
1723 (msg
->time
- clk_msg
.time
< GetDoubleClickTime()) &&
1724 (abs(msg
->pt
.x
- clk_msg
.pt
.x
) < GetSystemMetrics(SM_CXDOUBLECLK
)/2) &&
1725 (abs(msg
->pt
.y
- clk_msg
.pt
.y
) < GetSystemMetrics(SM_CYDOUBLECLK
)/2))
1727 message
+= (WM_LBUTTONDBLCLK
- WM_LBUTTONDOWN
);
1730 clk_msg
.message
= 0; /* clear the double click conditions */
1735 if (message
< first
|| message
> last
) return FALSE
;
1736 /* update static double click conditions */
1737 if (update
) clk_msg
= *msg
;
1741 if (message
< first
|| message
> last
) return FALSE
;
1744 /* message is accepted now (but may still get dropped) */
1747 hook
.hwnd
= msg
->hwnd
;
1748 hook
.wHitTestCode
= hittest
;
1749 hook
.dwExtraInfo
= extra_info
;
1750 if (HOOK_CallHooks( WH_MOUSE
, remove
? HC_ACTION
: HC_NOREMOVE
,
1751 message
, (LPARAM
)&hook
, TRUE
))
1754 hook
.hwnd
= msg
->hwnd
;
1755 hook
.wHitTestCode
= hittest
;
1756 hook
.dwExtraInfo
= extra_info
;
1757 HOOK_CallHooks( WH_CBT
, HCBT_CLICKSKIPPED
, message
, (LPARAM
)&hook
, TRUE
);
1758 accept_hardware_message( hw_id
, TRUE
, 0 );
1762 if ((hittest
== HTERROR
) || (hittest
== HTNOWHERE
))
1764 SendMessageW( msg
->hwnd
, WM_SETCURSOR
, (WPARAM
)msg
->hwnd
,
1765 MAKELONG( hittest
, msg
->message
));
1766 accept_hardware_message( hw_id
, TRUE
, 0 );
1770 accept_hardware_message( hw_id
, remove
, 0 );
1772 if (!remove
|| info
.hwndCapture
)
1774 msg
->message
= message
;
1780 if ((msg
->message
== WM_LBUTTONDOWN
) ||
1781 (msg
->message
== WM_RBUTTONDOWN
) ||
1782 (msg
->message
== WM_MBUTTONDOWN
) ||
1783 (msg
->message
== WM_XBUTTONDOWN
))
1785 /* Send the WM_PARENTNOTIFY,
1786 * note that even for double/nonclient clicks
1787 * notification message is still WM_L/M/RBUTTONDOWN.
1789 send_parent_notify( msg
->hwnd
, msg
->message
, 0, msg
->pt
);
1791 /* Activate the window if needed */
1793 if (msg
->hwnd
!= info
.hwndActive
)
1795 HWND hwndTop
= msg
->hwnd
;
1798 if ((GetWindowLongW( hwndTop
, GWL_STYLE
) & (WS_POPUP
|WS_CHILD
)) != WS_CHILD
) break;
1799 hwndTop
= GetParent( hwndTop
);
1802 if (hwndTop
&& hwndTop
!= GetDesktopWindow())
1804 LONG ret
= SendMessageW( msg
->hwnd
, WM_MOUSEACTIVATE
, (WPARAM
)hwndTop
,
1805 MAKELONG( hittest
, msg
->message
) );
1808 case MA_NOACTIVATEANDEAT
:
1813 case MA_ACTIVATEANDEAT
:
1818 if (!FOCUS_MouseActivate( hwndTop
)) eatMsg
= TRUE
;
1821 WARN( "unknown WM_MOUSEACTIVATE code %ld\n", ret
);
1828 /* send the WM_SETCURSOR message */
1830 /* Windows sends the normal mouse message as the message parameter
1831 in the WM_SETCURSOR message even if it's non-client mouse message */
1832 SendMessageW( msg
->hwnd
, WM_SETCURSOR
, (WPARAM
)msg
->hwnd
, MAKELONG( hittest
, msg
->message
));
1834 msg
->message
= message
;
1839 /***********************************************************************
1840 * process_hardware_message
1842 * Process a hardware message; return TRUE if message should be passed on to the app
1844 static BOOL
process_hardware_message( MSG
*msg
, UINT hw_id
, ULONG_PTR extra_info
, HWND hwnd_filter
,
1845 UINT first
, UINT last
, BOOL remove
)
1847 if (is_keyboard_message( msg
->message
))
1848 return process_keyboard_message( msg
, hw_id
, hwnd_filter
, first
, last
, remove
);
1850 if (is_mouse_message( msg
->message
))
1851 return process_mouse_message( msg
, hw_id
, extra_info
, hwnd_filter
, first
, last
, remove
);
1853 ERR( "unknown message type %x\n", msg
->message
);
1858 /***********************************************************************
1859 * call_sendmsg_callback
1861 * Call the callback function of SendMessageCallback.
1863 static inline void call_sendmsg_callback( SENDASYNCPROC callback
, HWND hwnd
, UINT msg
,
1864 ULONG_PTR data
, LRESULT result
)
1866 if (TRACE_ON(relay
))
1867 DPRINTF( "%04lx:Call message callback %p (hwnd=%p,msg=%s,data=%08lx,result=%08lx)\n",
1868 GetCurrentThreadId(), callback
, hwnd
, SPY_GetMsgName( msg
, hwnd
),
1870 callback( hwnd
, msg
, data
, result
);
1871 if (TRACE_ON(relay
))
1872 DPRINTF( "%04lx:Ret message callback %p (hwnd=%p,msg=%s,data=%08lx,result=%08lx)\n",
1873 GetCurrentThreadId(), callback
, hwnd
, SPY_GetMsgName( msg
, hwnd
),
1878 /***********************************************************************
1881 * Retrieve the hook procedure real value for a module-relative proc
1883 static void *get_hook_proc( void *proc
, const WCHAR
*module
)
1887 if (!(mod
= GetModuleHandleW(module
)))
1889 TRACE( "loading %s\n", debugstr_w(module
) );
1890 /* FIXME: the library will never be freed */
1891 if (!(mod
= LoadLibraryW(module
))) return NULL
;
1893 return (char *)mod
+ (ULONG_PTR
)proc
;
1897 /***********************************************************************
1900 * Peek for a message matching the given parameters. Return FALSE if none available.
1901 * All pending sent messages are processed before returning.
1903 static BOOL
peek_message( MSG
*msg
, HWND hwnd
, UINT first
, UINT last
, int flags
)
1906 ULONG_PTR extra_info
= 0;
1907 struct user_thread_info
*thread_info
= get_user_thread_info();
1908 struct received_message_info info
, *old_info
;
1909 unsigned int hw_id
= 0; /* id of previous hardware message */
1911 if (!first
&& !last
) last
= ~0;
1916 void *buffer
= NULL
;
1917 size_t size
= 0, buffer_size
= 0;
1919 do /* loop while buffer is too small */
1921 if (buffer_size
&& !(buffer
= HeapAlloc( GetProcessHeap(), 0, buffer_size
)))
1923 SERVER_START_REQ( get_message
)
1926 req
->get_win
= hwnd
;
1927 req
->get_first
= first
;
1928 req
->get_last
= last
;
1930 if (buffer_size
) wine_server_set_reply( req
, buffer
, buffer_size
);
1931 if (!(res
= wine_server_call( req
)))
1933 size
= wine_server_reply_size( reply
);
1934 info
.type
= reply
->type
;
1935 info
.msg
.hwnd
= reply
->win
;
1936 info
.msg
.message
= reply
->msg
;
1937 info
.msg
.wParam
= reply
->wparam
;
1938 info
.msg
.lParam
= reply
->lparam
;
1939 info
.msg
.time
= reply
->time
;
1940 info
.msg
.pt
.x
= reply
->x
;
1941 info
.msg
.pt
.y
= reply
->y
;
1942 info
.hook
= reply
->hook
;
1943 info
.hook_proc
= reply
->hook_proc
;
1944 hw_id
= reply
->hw_id
;
1945 extra_info
= reply
->info
;
1946 thread_info
->active_hooks
= reply
->active_hooks
;
1950 HeapFree( GetProcessHeap(), 0, buffer
);
1951 buffer_size
= reply
->total
;
1955 } while (res
== STATUS_BUFFER_OVERFLOW
);
1957 if (res
) return FALSE
;
1959 TRACE( "got type %d msg %x (%s) hwnd %p wp %x lp %lx\n",
1960 info
.type
, info
.msg
.message
,
1961 (info
.type
== MSG_WINEVENT
) ? "MSG_WINEVENT" : SPY_GetMsgName(info
.msg
.message
, info
.msg
.hwnd
),
1962 info
.msg
.hwnd
, info
.msg
.wParam
, info
.msg
.lParam
);
1968 info
.flags
= ISMEX_SEND
;
1971 info
.flags
= ISMEX_NOTIFY
;
1974 info
.flags
= ISMEX_CALLBACK
;
1976 case MSG_CALLBACK_RESULT
:
1977 call_sendmsg_callback( (SENDASYNCPROC
)info
.msg
.wParam
, info
.msg
.hwnd
,
1978 info
.msg
.message
, extra_info
, info
.msg
.lParam
);
1983 WCHAR module
[MAX_PATH
];
1984 size
= min( size
, (MAX_PATH
- 1) * sizeof(WCHAR
) );
1985 memcpy( module
, buffer
, size
);
1986 module
[size
/ sizeof(WCHAR
)] = 0;
1987 if (!(info
.hook_proc
= get_hook_proc( info
.hook_proc
, module
)))
1989 ERR( "invalid winevent hook module name %s\n", debugstr_w(module
) );
1993 if (TRACE_ON(relay
))
1994 DPRINTF( "%04lx:Call winevent proc %p (hook=%p,event=%x,hwnd=%p,object_id=%x,child_id=%lx,tid=%04lx,time=%lx)\n",
1995 GetCurrentThreadId(), info
.hook_proc
,
1996 info
.hook
, info
.msg
.message
, info
.msg
.hwnd
, info
.msg
.wParam
,
1997 info
.msg
.lParam
, extra_info
, info
.msg
.time
);
1999 info
.hook_proc( info
.hook
, info
.msg
.message
, info
.msg
.hwnd
, info
.msg
.wParam
,
2000 info
.msg
.lParam
, extra_info
, info
.msg
.time
);
2002 if (TRACE_ON(relay
))
2003 DPRINTF( "%04lx:Ret winevent proc %p (hook=%p,event=%x,hwnd=%p,object_id=%x,child_id=%lx,tid=%04lx,time=%lx)\n",
2004 GetCurrentThreadId(), info
.hook_proc
,
2005 info
.hook
, info
.msg
.message
, info
.msg
.hwnd
, info
.msg
.wParam
,
2006 info
.msg
.lParam
, extra_info
, info
.msg
.time
);
2008 case MSG_OTHER_PROCESS
:
2009 info
.flags
= ISMEX_SEND
;
2010 if (!unpack_message( info
.msg
.hwnd
, info
.msg
.message
, &info
.msg
.wParam
,
2011 &info
.msg
.lParam
, &buffer
, size
))
2013 ERR( "invalid packed message %x (%s) hwnd %p wp %x lp %lx size %d\n",
2014 info
.msg
.message
, SPY_GetMsgName(info
.msg
.message
, info
.msg
.hwnd
), info
.msg
.hwnd
,
2015 info
.msg
.wParam
, info
.msg
.lParam
, size
);
2017 reply_message( &info
, 0, TRUE
);
2022 if (!process_hardware_message( &info
.msg
, hw_id
, extra_info
,
2023 hwnd
, first
, last
, flags
& GET_MSG_REMOVE
))
2025 TRACE("dropping msg %x\n", info
.msg
.message
);
2026 goto next
; /* ignore it */
2028 thread_info
->GetMessagePosVal
= MAKELONG( info
.msg
.pt
.x
, info
.msg
.pt
.y
);
2031 thread_info
->GetMessageExtraInfoVal
= extra_info
;
2032 if (info
.msg
.message
>= WM_DDE_FIRST
&& info
.msg
.message
<= WM_DDE_LAST
)
2034 if (!unpack_dde_message( info
.msg
.hwnd
, info
.msg
.message
, &info
.msg
.wParam
,
2035 &info
.msg
.lParam
, &buffer
, size
))
2037 ERR( "invalid packed dde-message %x (%s) hwnd %p wp %x lp %lx size %d\n",
2038 info
.msg
.message
, SPY_GetMsgName(info
.msg
.message
, info
.msg
.hwnd
),
2039 info
.msg
.hwnd
, info
.msg
.wParam
, info
.msg
.lParam
, size
);
2040 goto next
; /* ignore it */
2044 HeapFree( GetProcessHeap(), 0, buffer
);
2048 /* if we get here, we have a sent message; call the window procedure */
2049 old_info
= thread_info
->receive_info
;
2050 thread_info
->receive_info
= &info
;
2051 result
= call_window_proc( info
.msg
.hwnd
, info
.msg
.message
, info
.msg
.wParam
,
2052 info
.msg
.lParam
, (info
.type
!= MSG_ASCII
), FALSE
);
2053 reply_message( &info
, result
, TRUE
);
2054 thread_info
->receive_info
= old_info
;
2056 HeapFree( GetProcessHeap(), 0, buffer
);
2061 /***********************************************************************
2062 * process_sent_messages
2064 * Process all pending sent messages.
2066 inline static void process_sent_messages(void)
2069 peek_message( &msg
, 0, 0, 0, GET_MSG_REMOVE
| GET_MSG_SENT_ONLY
);
2073 /***********************************************************************
2074 * get_server_queue_handle
2076 * Get a handle to the server message queue for the current thread.
2078 static HANDLE
get_server_queue_handle(void)
2080 struct user_thread_info
*thread_info
= get_user_thread_info();
2083 if (!(ret
= thread_info
->server_queue
))
2085 SERVER_START_REQ( get_msg_queue
)
2087 wine_server_call( req
);
2088 ret
= reply
->handle
;
2091 thread_info
->server_queue
= ret
;
2092 if (!ret
) ERR( "Cannot get server thread queue\n" );
2098 /***********************************************************************
2099 * wait_message_reply
2101 * Wait until a sent message gets replied to.
2103 static void wait_message_reply( UINT flags
)
2105 HANDLE server_queue
= get_server_queue_handle();
2109 unsigned int wake_bits
= 0, changed_bits
= 0;
2112 SERVER_START_REQ( set_queue_mask
)
2114 req
->wake_mask
= QS_SMRESULT
| ((flags
& SMTO_BLOCK
) ? 0 : QS_SENDMESSAGE
);
2115 req
->changed_mask
= req
->wake_mask
;
2117 if (!wine_server_call( req
))
2119 wake_bits
= reply
->wake_bits
;
2120 changed_bits
= reply
->changed_bits
;
2125 if (wake_bits
& QS_SMRESULT
) return; /* got a result */
2126 if (wake_bits
& QS_SENDMESSAGE
)
2128 /* Process the sent message immediately */
2129 process_sent_messages();
2133 /* now wait for it */
2135 ReleaseThunkLock( &dwlc
);
2136 res
= USER_Driver
->pMsgWaitForMultipleObjectsEx( 1, &server_queue
,
2137 INFINITE
, QS_ALLINPUT
, 0 );
2138 if (dwlc
) RestoreThunkLock( dwlc
);
2142 /***********************************************************************
2143 * put_message_in_queue
2145 * Put a sent message into the destination queue.
2146 * For inter-process message, reply_size is set to expected size of reply data.
2148 static BOOL
put_message_in_queue( DWORD dest_tid
, const struct send_message_info
*info
,
2149 size_t *reply_size
)
2151 struct packed_message data
;
2153 int i
, timeout
= -1;
2155 if (info
->type
!= MSG_NOTIFY
&&
2156 info
->type
!= MSG_CALLBACK
&&
2157 info
->type
!= MSG_POSTED
&&
2158 info
->timeout
!= INFINITE
)
2159 timeout
= info
->timeout
;
2162 if (info
->type
== MSG_OTHER_PROCESS
)
2164 *reply_size
= pack_message( info
->hwnd
, info
->msg
, info
->wparam
, info
->lparam
, &data
);
2165 if (data
.count
== -1)
2167 WARN( "cannot pack message %x\n", info
->msg
);
2171 else if (info
->type
== MSG_POSTED
&& info
->msg
>= WM_DDE_FIRST
&& info
->msg
<= WM_DDE_LAST
)
2173 return post_dde_message( dest_tid
, &data
, info
);
2176 SERVER_START_REQ( send_message
)
2179 req
->type
= info
->type
;
2181 req
->win
= info
->hwnd
;
2182 req
->msg
= info
->msg
;
2183 req
->wparam
= info
->wparam
;
2184 req
->lparam
= info
->lparam
;
2185 req
->time
= GetCurrentTime();
2186 req
->timeout
= timeout
;
2188 if (info
->type
== MSG_CALLBACK
)
2190 req
->callback
= info
->callback
;
2191 req
->info
= info
->data
;
2194 if (info
->flags
& SMTO_ABORTIFHUNG
) req
->flags
|= SEND_MSG_ABORT_IF_HUNG
;
2195 for (i
= 0; i
< data
.count
; i
++) wine_server_add_data( req
, data
.data
[i
], data
.size
[i
] );
2196 if ((res
= wine_server_call( req
)))
2198 if (res
== STATUS_INVALID_PARAMETER
)
2199 /* FIXME: find a STATUS_ value for this one */
2200 SetLastError( ERROR_INVALID_THREAD_ID
);
2202 SetLastError( RtlNtStatusToDosError(res
) );
2210 /***********************************************************************
2213 * Retrieve a message reply from the server.
2215 static LRESULT
retrieve_reply( const struct send_message_info
*info
,
2216 size_t reply_size
, LRESULT
*result
)
2219 void *reply_data
= NULL
;
2223 if (!(reply_data
= HeapAlloc( GetProcessHeap(), 0, reply_size
)))
2225 WARN( "no memory for reply %d bytes, will be truncated\n", reply_size
);
2229 SERVER_START_REQ( get_message_reply
)
2232 if (reply_size
) wine_server_set_reply( req
, reply_data
, reply_size
);
2233 if (!(status
= wine_server_call( req
))) *result
= reply
->result
;
2234 reply_size
= wine_server_reply_size( reply
);
2237 if (!status
&& reply_size
)
2238 unpack_reply( info
->hwnd
, info
->msg
, info
->wparam
, info
->lparam
, reply_data
, reply_size
);
2240 HeapFree( GetProcessHeap(), 0, reply_data
);
2242 TRACE( "hwnd %p msg %x (%s) wp %x lp %lx got reply %lx (err=%ld)\n",
2243 info
->hwnd
, info
->msg
, SPY_GetMsgName(info
->msg
, info
->hwnd
), info
->wparam
,
2244 info
->lparam
, *result
, status
);
2246 /* MSDN states that last error is 0 on timeout, but at least NT4 returns ERROR_TIMEOUT */
2247 if (status
) SetLastError( RtlNtStatusToDosError(status
) );
2252 /***********************************************************************
2253 * send_inter_thread_message
2255 static LRESULT
send_inter_thread_message( DWORD dest_tid
, const struct send_message_info
*info
,
2258 size_t reply_size
= 0;
2260 TRACE( "hwnd %p msg %x (%s) wp %x lp %lx\n",
2261 info
->hwnd
, info
->msg
, SPY_GetMsgName(info
->msg
, info
->hwnd
), info
->wparam
, info
->lparam
);
2263 USER_CheckNotLock();
2265 if (!put_message_in_queue( dest_tid
, info
, &reply_size
)) return 0;
2267 /* there's no reply to wait for on notify/callback messages */
2268 if (info
->type
== MSG_NOTIFY
|| info
->type
== MSG_CALLBACK
) return 1;
2270 wait_message_reply( info
->flags
);
2271 return retrieve_reply( info
, reply_size
, res_ptr
);
2275 /***********************************************************************
2276 * MSG_SendInternalMessageTimeout
2278 * Same as SendMessageTimeoutW but sends the message to a specific thread
2279 * without requiring a window handle. Only works for internal Wine messages.
2281 LRESULT
MSG_SendInternalMessageTimeout( DWORD dest_pid
, DWORD dest_tid
,
2282 UINT msg
, WPARAM wparam
, LPARAM lparam
,
2283 UINT flags
, UINT timeout
, PDWORD_PTR res_ptr
)
2285 struct send_message_info info
;
2286 LRESULT ret
, result
;
2288 assert( msg
& 0x80000000 ); /* must be an internal Wine message */
2290 info
.type
= MSG_UNICODE
;
2293 info
.wparam
= wparam
;
2294 info
.lparam
= lparam
;
2296 info
.timeout
= timeout
;
2298 if (USER_IsExitingThread( dest_tid
)) return 0;
2300 if (dest_tid
== GetCurrentThreadId())
2302 result
= handle_internal_message( 0, msg
, wparam
, lparam
);
2307 if (dest_pid
!= GetCurrentProcessId()) info
.type
= MSG_OTHER_PROCESS
;
2308 ret
= send_inter_thread_message( dest_tid
, &info
, &result
);
2310 if (ret
&& res_ptr
) *res_ptr
= result
;
2315 /***********************************************************************
2316 * SendMessageTimeoutW (USER32.@)
2318 LRESULT WINAPI
SendMessageTimeoutW( HWND hwnd
, UINT msg
, WPARAM wparam
, LPARAM lparam
,
2319 UINT flags
, UINT timeout
, PDWORD_PTR res_ptr
)
2321 struct send_message_info info
;
2322 DWORD dest_tid
, dest_pid
;
2323 LRESULT ret
, result
;
2325 info
.type
= MSG_UNICODE
;
2328 info
.wparam
= wparam
;
2329 info
.lparam
= lparam
;
2331 info
.timeout
= timeout
;
2333 if (is_broadcast(hwnd
))
2335 EnumWindows( broadcast_message_callback
, (LPARAM
)&info
);
2336 if (res_ptr
) *res_ptr
= 1;
2340 if (!(dest_tid
= GetWindowThreadProcessId( hwnd
, &dest_pid
))) return 0;
2342 if (USER_IsExitingThread( dest_tid
)) return 0;
2344 SPY_EnterMessage( SPY_SENDMESSAGE
, hwnd
, msg
, wparam
, lparam
);
2346 if (dest_tid
== GetCurrentThreadId())
2348 result
= call_window_proc( hwnd
, msg
, wparam
, lparam
, TRUE
, TRUE
);
2353 if (dest_pid
!= GetCurrentProcessId()) info
.type
= MSG_OTHER_PROCESS
;
2354 ret
= send_inter_thread_message( dest_tid
, &info
, &result
);
2357 SPY_ExitMessage( SPY_RESULT_OK
, hwnd
, msg
, result
, wparam
, lparam
);
2358 if (ret
&& res_ptr
) *res_ptr
= result
;
2363 /***********************************************************************
2364 * SendMessageTimeoutA (USER32.@)
2366 LRESULT WINAPI
SendMessageTimeoutA( HWND hwnd
, UINT msg
, WPARAM wparam
, LPARAM lparam
,
2367 UINT flags
, UINT timeout
, PDWORD_PTR res_ptr
)
2369 struct send_message_info info
;
2370 DWORD dest_tid
, dest_pid
;
2371 LRESULT ret
, result
;
2373 info
.type
= MSG_ASCII
;
2376 info
.wparam
= wparam
;
2377 info
.lparam
= lparam
;
2379 info
.timeout
= timeout
;
2381 if (is_broadcast(hwnd
))
2383 EnumWindows( broadcast_message_callback
, (LPARAM
)&info
);
2384 if (res_ptr
) *res_ptr
= 1;
2388 if (!(dest_tid
= GetWindowThreadProcessId( hwnd
, &dest_pid
))) return 0;
2390 if (USER_IsExitingThread( dest_tid
)) return 0;
2392 SPY_EnterMessage( SPY_SENDMESSAGE
, hwnd
, msg
, wparam
, lparam
);
2394 if (dest_tid
== GetCurrentThreadId())
2396 result
= call_window_proc( hwnd
, msg
, wparam
, lparam
, FALSE
, TRUE
);
2399 else if (dest_pid
== GetCurrentProcessId())
2401 ret
= send_inter_thread_message( dest_tid
, &info
, &result
);
2405 /* inter-process message: need to map to Unicode */
2406 info
.type
= MSG_OTHER_PROCESS
;
2407 if (is_unicode_message( info
.msg
))
2409 if (WINPROC_MapMsg32ATo32W( info
.hwnd
, info
.msg
, &info
.wparam
, &info
.lparam
) == -1)
2411 ret
= send_inter_thread_message( dest_tid
, &info
, &result
);
2412 result
= WINPROC_UnmapMsg32ATo32W( info
.hwnd
, info
.msg
, info
.wparam
,
2413 info
.lparam
, result
);
2415 else ret
= send_inter_thread_message( dest_tid
, &info
, &result
);
2417 SPY_ExitMessage( SPY_RESULT_OK
, hwnd
, msg
, result
, wparam
, lparam
);
2418 if (ret
&& res_ptr
) *res_ptr
= result
;
2423 /***********************************************************************
2424 * SendMessageW (USER32.@)
2426 LRESULT WINAPI
SendMessageW( HWND hwnd
, UINT msg
, WPARAM wparam
, LPARAM lparam
)
2429 SendMessageTimeoutW( hwnd
, msg
, wparam
, lparam
, SMTO_NORMAL
, 0, &res
);
2434 /***********************************************************************
2435 * SendMessageA (USER32.@)
2437 LRESULT WINAPI
SendMessageA( HWND hwnd
, UINT msg
, WPARAM wparam
, LPARAM lparam
)
2440 SendMessageTimeoutA( hwnd
, msg
, wparam
, lparam
, SMTO_NORMAL
, 0, &res
);
2445 /***********************************************************************
2446 * SendNotifyMessageA (USER32.@)
2448 BOOL WINAPI
SendNotifyMessageA( HWND hwnd
, UINT msg
, WPARAM wparam
, LPARAM lparam
)
2450 return SendNotifyMessageW( hwnd
, msg
, map_wparam_AtoW( msg
, wparam
), lparam
);
2454 /***********************************************************************
2455 * SendNotifyMessageW (USER32.@)
2457 BOOL WINAPI
SendNotifyMessageW( HWND hwnd
, UINT msg
, WPARAM wparam
, LPARAM lparam
)
2459 struct send_message_info info
;
2463 if (is_pointer_message(msg
))
2465 SetLastError( ERROR_MESSAGE_SYNC_ONLY
);
2469 info
.type
= MSG_NOTIFY
;
2472 info
.wparam
= wparam
;
2473 info
.lparam
= lparam
;
2476 if (is_broadcast(hwnd
))
2478 EnumWindows( broadcast_message_callback
, (LPARAM
)&info
);
2482 if (!(dest_tid
= GetWindowThreadProcessId( hwnd
, NULL
))) return FALSE
;
2484 if (USER_IsExitingThread( dest_tid
)) return TRUE
;
2486 if (dest_tid
== GetCurrentThreadId())
2488 call_window_proc( hwnd
, msg
, wparam
, lparam
, TRUE
, TRUE
);
2491 return send_inter_thread_message( dest_tid
, &info
, &result
);
2495 /***********************************************************************
2496 * SendMessageCallbackA (USER32.@)
2498 BOOL WINAPI
SendMessageCallbackA( HWND hwnd
, UINT msg
, WPARAM wparam
, LPARAM lparam
,
2499 SENDASYNCPROC callback
, ULONG_PTR data
)
2501 return SendMessageCallbackW( hwnd
, msg
, map_wparam_AtoW( msg
, wparam
),
2502 lparam
, callback
, data
);
2506 /***********************************************************************
2507 * SendMessageCallbackW (USER32.@)
2509 BOOL WINAPI
SendMessageCallbackW( HWND hwnd
, UINT msg
, WPARAM wparam
, LPARAM lparam
,
2510 SENDASYNCPROC callback
, ULONG_PTR data
)
2512 struct send_message_info info
;
2516 if (is_pointer_message(msg
))
2518 SetLastError( ERROR_MESSAGE_SYNC_ONLY
);
2522 info
.type
= MSG_CALLBACK
;
2525 info
.wparam
= wparam
;
2526 info
.lparam
= lparam
;
2527 info
.callback
= callback
;
2531 if (is_broadcast(hwnd
))
2533 EnumWindows( broadcast_message_callback
, (LPARAM
)&info
);
2537 if (!(dest_tid
= GetWindowThreadProcessId( hwnd
, NULL
))) return FALSE
;
2539 if (USER_IsExitingThread( dest_tid
)) return TRUE
;
2541 if (dest_tid
== GetCurrentThreadId())
2543 result
= call_window_proc( hwnd
, msg
, wparam
, lparam
, TRUE
, TRUE
);
2544 call_sendmsg_callback( callback
, hwnd
, msg
, data
, result
);
2547 FIXME( "callback will not be called\n" );
2548 return send_inter_thread_message( dest_tid
, &info
, &result
);
2552 /***********************************************************************
2553 * ReplyMessage (USER32.@)
2555 BOOL WINAPI
ReplyMessage( LRESULT result
)
2557 struct received_message_info
*info
= get_user_thread_info()->receive_info
;
2559 if (!info
) return FALSE
;
2560 reply_message( info
, result
, FALSE
);
2565 /***********************************************************************
2566 * InSendMessage (USER32.@)
2568 BOOL WINAPI
InSendMessage(void)
2570 return (InSendMessageEx(NULL
) & (ISMEX_SEND
|ISMEX_REPLIED
)) == ISMEX_SEND
;
2574 /***********************************************************************
2575 * InSendMessageEx (USER32.@)
2577 DWORD WINAPI
InSendMessageEx( LPVOID reserved
)
2579 struct received_message_info
*info
= get_user_thread_info()->receive_info
;
2581 if (info
) return info
->flags
;
2582 return ISMEX_NOSEND
;
2586 /***********************************************************************
2587 * PostMessageA (USER32.@)
2589 BOOL WINAPI
PostMessageA( HWND hwnd
, UINT msg
, WPARAM wparam
, LPARAM lparam
)
2591 return PostMessageW( hwnd
, msg
, map_wparam_AtoW( msg
, wparam
), lparam
);
2595 /***********************************************************************
2596 * PostMessageW (USER32.@)
2598 BOOL WINAPI
PostMessageW( HWND hwnd
, UINT msg
, WPARAM wparam
, LPARAM lparam
)
2600 struct send_message_info info
;
2603 if (is_pointer_message( msg
))
2605 SetLastError( ERROR_MESSAGE_SYNC_ONLY
);
2609 TRACE( "hwnd %p msg %x (%s) wp %x lp %lx\n",
2610 hwnd
, msg
, SPY_GetMsgName(msg
, hwnd
), wparam
, lparam
);
2612 info
.type
= MSG_POSTED
;
2615 info
.wparam
= wparam
;
2616 info
.lparam
= lparam
;
2619 if (is_broadcast(hwnd
))
2621 EnumWindows( broadcast_message_callback
, (LPARAM
)&info
);
2625 if (!hwnd
) return PostThreadMessageW( GetCurrentThreadId(), msg
, wparam
, lparam
);
2627 if (!(dest_tid
= GetWindowThreadProcessId( hwnd
, NULL
))) return FALSE
;
2629 if (USER_IsExitingThread( dest_tid
)) return TRUE
;
2631 return put_message_in_queue( dest_tid
, &info
, NULL
);
2635 /**********************************************************************
2636 * PostThreadMessageA (USER32.@)
2638 BOOL WINAPI
PostThreadMessageA( DWORD thread
, UINT msg
, WPARAM wparam
, LPARAM lparam
)
2640 return PostThreadMessageW( thread
, msg
, map_wparam_AtoW( msg
, wparam
), lparam
);
2644 /**********************************************************************
2645 * PostThreadMessageW (USER32.@)
2647 BOOL WINAPI
PostThreadMessageW( DWORD thread
, UINT msg
, WPARAM wparam
, LPARAM lparam
)
2649 struct send_message_info info
;
2651 if (is_pointer_message( msg
))
2653 SetLastError( ERROR_MESSAGE_SYNC_ONLY
);
2656 if (USER_IsExitingThread( thread
)) return TRUE
;
2658 info
.type
= MSG_POSTED
;
2661 info
.wparam
= wparam
;
2662 info
.lparam
= lparam
;
2664 return put_message_in_queue( thread
, &info
, NULL
);
2668 /***********************************************************************
2669 * PostQuitMessage (USER32.@)
2671 void WINAPI
PostQuitMessage( INT exitCode
)
2673 PostThreadMessageW( GetCurrentThreadId(), WM_QUIT
, exitCode
, 0 );
2677 /***********************************************************************
2678 * PeekMessageW (USER32.@)
2680 BOOL WINAPI
PeekMessageW( MSG
*msg_out
, HWND hwnd
, UINT first
, UINT last
, UINT flags
)
2682 struct user_thread_info
*thread_info
= get_user_thread_info();
2685 USER_CheckNotLock();
2687 /* check for graphics events */
2688 USER_Driver
->pMsgWaitForMultipleObjectsEx( 0, NULL
, 0, QS_ALLINPUT
, 0 );
2690 hwnd
= WIN_GetFullHandle( hwnd
);
2694 if (!peek_message( &msg
, hwnd
, first
, last
, (flags
& PM_REMOVE
) ? GET_MSG_REMOVE
: 0 ))
2696 if (!(flags
& PM_NOYIELD
))
2699 ReleaseThunkLock(&count
);
2701 if (count
) RestoreThunkLock(count
);
2705 if (msg
.message
& 0x80000000)
2707 handle_internal_message( msg
.hwnd
, msg
.message
, msg
.wParam
, msg
.lParam
);
2708 if (!(flags
& PM_REMOVE
)) /* have to remove it explicitly */
2709 peek_message( &msg
, msg
.hwnd
, msg
.message
, msg
.message
, GET_MSG_REMOVE
);
2714 thread_info
->GetMessageTimeVal
= msg
.time
;
2715 msg
.pt
.x
= LOWORD( thread_info
->GetMessagePosVal
);
2716 msg
.pt
.y
= HIWORD( thread_info
->GetMessagePosVal
);
2718 HOOK_CallHooks( WH_GETMESSAGE
, HC_ACTION
, flags
& PM_REMOVE
, (LPARAM
)&msg
, TRUE
);
2720 /* copy back our internal safe copy of message data to msg_out.
2721 * msg_out is a variable from the *program*, so it can't be used
2722 * internally as it can get "corrupted" by our use of SendMessage()
2723 * (back to the program) inside the message handling itself. */
2726 SetLastError( ERROR_NOACCESS
);
2734 /***********************************************************************
2735 * PeekMessageA (USER32.@)
2737 BOOL WINAPI
PeekMessageA( MSG
*msg
, HWND hwnd
, UINT first
, UINT last
, UINT flags
)
2739 BOOL ret
= PeekMessageW( msg
, hwnd
, first
, last
, flags
);
2740 if (ret
) msg
->wParam
= map_wparam_WtoA( msg
->message
, msg
->wParam
);
2745 /***********************************************************************
2746 * GetMessageW (USER32.@)
2748 BOOL WINAPI
GetMessageW( MSG
*msg
, HWND hwnd
, UINT first
, UINT last
)
2750 HANDLE server_queue
= get_server_queue_handle();
2751 int mask
= QS_POSTMESSAGE
| QS_SENDMESSAGE
; /* Always selected */
2755 if ((first
<= WM_KEYLAST
) && (last
>= WM_KEYFIRST
)) mask
|= QS_KEY
;
2756 if ( ((first
<= WM_MOUSELAST
) && (last
>= WM_MOUSEFIRST
)) ||
2757 ((first
<= WM_NCMOUSELAST
) && (last
>= WM_NCMOUSEFIRST
)) ) mask
|= QS_MOUSE
;
2758 if ((first
<= WM_TIMER
) && (last
>= WM_TIMER
)) mask
|= QS_TIMER
;
2759 if ((first
<= WM_SYSTIMER
) && (last
>= WM_SYSTIMER
)) mask
|= QS_TIMER
;
2760 if ((first
<= WM_PAINT
) && (last
>= WM_PAINT
)) mask
|= QS_PAINT
;
2762 else mask
|= QS_MOUSE
| QS_KEY
| QS_TIMER
| QS_PAINT
;
2764 while (!PeekMessageW( msg
, hwnd
, first
, last
, PM_REMOVE
))
2766 /* wait until one of the bits is set */
2767 unsigned int wake_bits
= 0, changed_bits
= 0;
2770 SERVER_START_REQ( set_queue_mask
)
2772 req
->wake_mask
= QS_SENDMESSAGE
;
2773 req
->changed_mask
= mask
;
2775 if (!wine_server_call( req
))
2777 wake_bits
= reply
->wake_bits
;
2778 changed_bits
= reply
->changed_bits
;
2783 if (changed_bits
& mask
) continue;
2784 if (wake_bits
& QS_SENDMESSAGE
) continue;
2786 TRACE( "(%04lx) mask=%08x, bits=%08x, changed=%08x, waiting\n",
2787 GetCurrentThreadId(), mask
, wake_bits
, changed_bits
);
2789 ReleaseThunkLock( &dwlc
);
2790 USER_Driver
->pMsgWaitForMultipleObjectsEx( 1, &server_queue
, INFINITE
, QS_ALLINPUT
, 0 );
2791 if (dwlc
) RestoreThunkLock( dwlc
);
2794 return (msg
->message
!= WM_QUIT
);
2798 /***********************************************************************
2799 * GetMessageA (USER32.@)
2801 BOOL WINAPI
GetMessageA( MSG
*msg
, HWND hwnd
, UINT first
, UINT last
)
2803 GetMessageW( msg
, hwnd
, first
, last
);
2804 msg
->wParam
= map_wparam_WtoA( msg
->message
, msg
->wParam
);
2805 return (msg
->message
!= WM_QUIT
);
2809 /***********************************************************************
2810 * IsDialogMessage (USER32.@)
2811 * IsDialogMessageA (USER32.@)
2813 BOOL WINAPI
IsDialogMessageA( HWND hwndDlg
, LPMSG pmsg
)
2816 msg
.wParam
= map_wparam_AtoW( msg
.message
, msg
.wParam
);
2817 return IsDialogMessageW( hwndDlg
, &msg
);
2821 /***********************************************************************
2822 * TranslateMessage (USER32.@)
2824 * Implementation of TranslateMessage.
2826 * TranslateMessage translates virtual-key messages into character-messages,
2828 * WM_KEYDOWN/WM_KEYUP combinations produce a WM_CHAR or WM_DEADCHAR message.
2829 * ditto replacing WM_* with WM_SYS*
2830 * This produces WM_CHAR messages only for keys mapped to ASCII characters
2831 * by the keyboard driver.
2833 * If the message is WM_KEYDOWN, WM_KEYUP, WM_SYSKEYDOWN, or WM_SYSKEYUP, the
2834 * return value is nonzero, regardless of the translation.
2837 BOOL WINAPI
TranslateMessage( const MSG
*msg
)
2843 if (msg
->message
< WM_KEYFIRST
|| msg
->message
> WM_KEYLAST
) return FALSE
;
2844 if (msg
->message
!= WM_KEYDOWN
&& msg
->message
!= WM_SYSKEYDOWN
) return TRUE
;
2846 TRACE_(key
)("Translating key %s (%04x), scancode %02x\n",
2847 SPY_GetVKeyName(msg
->wParam
), msg
->wParam
, LOBYTE(HIWORD(msg
->lParam
)));
2849 GetKeyboardState( state
);
2850 /* FIXME : should handle ToUnicode yielding 2 */
2851 switch (ToUnicode(msg
->wParam
, HIWORD(msg
->lParam
), state
, wp
, 2, 0))
2854 message
= (msg
->message
== WM_KEYDOWN
) ? WM_CHAR
: WM_SYSCHAR
;
2855 TRACE_(key
)("1 -> PostMessageW(%p,%s,%04x,%08lx)\n",
2856 msg
->hwnd
, SPY_GetMsgName(message
, msg
->hwnd
), wp
[0], msg
->lParam
);
2857 PostMessageW( msg
->hwnd
, message
, wp
[0], msg
->lParam
);
2861 message
= (msg
->message
== WM_KEYDOWN
) ? WM_DEADCHAR
: WM_SYSDEADCHAR
;
2862 TRACE_(key
)("-1 -> PostMessageW(%p,%s,%04x,%08lx)\n",
2863 msg
->hwnd
, SPY_GetMsgName(message
, msg
->hwnd
), wp
[0], msg
->lParam
);
2864 PostMessageW( msg
->hwnd
, message
, wp
[0], msg
->lParam
);
2871 /***********************************************************************
2872 * DispatchMessageA (USER32.@)
2874 LONG WINAPI
DispatchMessageA( const MSG
* msg
)
2880 /* Process timer messages */
2881 if ((msg
->message
== WM_TIMER
) || (msg
->message
== WM_SYSTIMER
))
2883 if (msg
->lParam
) return CallWindowProcA( (WNDPROC
)msg
->lParam
, msg
->hwnd
,
2884 msg
->message
, msg
->wParam
, GetTickCount() );
2887 if (!(wndPtr
= WIN_GetPtr( msg
->hwnd
)))
2889 if (msg
->hwnd
) SetLastError( ERROR_INVALID_WINDOW_HANDLE
);
2892 if (wndPtr
== WND_OTHER_PROCESS
|| wndPtr
== WND_DESKTOP
)
2894 if (IsWindow( msg
->hwnd
)) SetLastError( ERROR_MESSAGE_SYNC_ONLY
);
2895 else SetLastError( ERROR_INVALID_WINDOW_HANDLE
);
2898 if (wndPtr
->tid
!= GetCurrentThreadId())
2900 SetLastError( ERROR_MESSAGE_SYNC_ONLY
);
2901 WIN_ReleasePtr( wndPtr
);
2904 winproc
= wndPtr
->winproc
;
2905 WIN_ReleasePtr( wndPtr
);
2907 SPY_EnterMessage( SPY_DISPATCHMESSAGE
, msg
->hwnd
, msg
->message
,
2908 msg
->wParam
, msg
->lParam
);
2909 retval
= CallWindowProcA( winproc
, msg
->hwnd
, msg
->message
,
2910 msg
->wParam
, msg
->lParam
);
2911 SPY_ExitMessage( SPY_RESULT_OK
, msg
->hwnd
, msg
->message
, retval
,
2912 msg
->wParam
, msg
->lParam
);
2914 if (msg
->message
== WM_PAINT
)
2916 /* send a WM_NCPAINT and WM_ERASEBKGND if the non-client area is still invalid */
2917 HRGN hrgn
= CreateRectRgn( 0, 0, 0, 0 );
2918 GetUpdateRgn( msg
->hwnd
, hrgn
, TRUE
);
2919 DeleteObject( hrgn
);
2925 /***********************************************************************
2926 * DispatchMessageW (USER32.@) Process a message
2928 * Process the message specified in the structure *_msg_.
2930 * If the lpMsg parameter points to a WM_TIMER message and the
2931 * parameter of the WM_TIMER message is not NULL, the lParam parameter
2932 * points to the function that is called instead of the window
2935 * The message must be valid.
2939 * DispatchMessage() returns the result of the window procedure invoked.
2946 LONG WINAPI
DispatchMessageW( const MSG
* msg
)
2952 /* Process timer messages */
2953 if ((msg
->message
== WM_TIMER
) || (msg
->message
== WM_SYSTIMER
))
2955 if (msg
->lParam
) return CallWindowProcW( (WNDPROC
)msg
->lParam
, msg
->hwnd
,
2956 msg
->message
, msg
->wParam
, GetTickCount() );
2959 if (!(wndPtr
= WIN_GetPtr( msg
->hwnd
)))
2961 if (msg
->hwnd
) SetLastError( ERROR_INVALID_WINDOW_HANDLE
);
2964 if (wndPtr
== WND_OTHER_PROCESS
|| wndPtr
== WND_DESKTOP
)
2966 if (IsWindow( msg
->hwnd
)) SetLastError( ERROR_MESSAGE_SYNC_ONLY
);
2967 else SetLastError( ERROR_INVALID_WINDOW_HANDLE
);
2970 if (wndPtr
->tid
!= GetCurrentThreadId())
2972 SetLastError( ERROR_MESSAGE_SYNC_ONLY
);
2973 WIN_ReleasePtr( wndPtr
);
2976 winproc
= wndPtr
->winproc
;
2977 WIN_ReleasePtr( wndPtr
);
2979 SPY_EnterMessage( SPY_DISPATCHMESSAGE
, msg
->hwnd
, msg
->message
,
2980 msg
->wParam
, msg
->lParam
);
2981 retval
= CallWindowProcW( winproc
, msg
->hwnd
, msg
->message
,
2982 msg
->wParam
, msg
->lParam
);
2983 SPY_ExitMessage( SPY_RESULT_OK
, msg
->hwnd
, msg
->message
, retval
,
2984 msg
->wParam
, msg
->lParam
);
2986 if (msg
->message
== WM_PAINT
)
2988 /* send a WM_NCPAINT and WM_ERASEBKGND if the non-client area is still invalid */
2989 HRGN hrgn
= CreateRectRgn( 0, 0, 0, 0 );
2990 GetUpdateRgn( msg
->hwnd
, hrgn
, TRUE
);
2991 DeleteObject( hrgn
);
2997 /***********************************************************************
2998 * GetMessagePos (USER.119)
2999 * GetMessagePos (USER32.@)
3001 * The GetMessagePos() function returns a long value representing a
3002 * cursor position, in screen coordinates, when the last message
3003 * retrieved by the GetMessage() function occurs. The x-coordinate is
3004 * in the low-order word of the return value, the y-coordinate is in
3005 * the high-order word. The application can use the MAKEPOINT()
3006 * macro to obtain a POINT structure from the return value.
3008 * For the current cursor position, use GetCursorPos().
3012 * Cursor position of last message on success, zero on failure.
3019 DWORD WINAPI
GetMessagePos(void)
3021 return get_user_thread_info()->GetMessagePosVal
;
3025 /***********************************************************************
3026 * GetMessageTime (USER.120)
3027 * GetMessageTime (USER32.@)
3029 * GetMessageTime() returns the message time for the last message
3030 * retrieved by the function. The time is measured in milliseconds with
3031 * the same offset as GetTickCount().
3033 * Since the tick count wraps, this is only useful for moderately short
3034 * relative time comparisons.
3038 * Time of last message on success, zero on failure.
3040 LONG WINAPI
GetMessageTime(void)
3042 return get_user_thread_info()->GetMessageTimeVal
;
3046 /***********************************************************************
3047 * GetMessageExtraInfo (USER.288)
3048 * GetMessageExtraInfo (USER32.@)
3050 LPARAM WINAPI
GetMessageExtraInfo(void)
3052 return get_user_thread_info()->GetMessageExtraInfoVal
;
3056 /***********************************************************************
3057 * SetMessageExtraInfo (USER32.@)
3059 LPARAM WINAPI
SetMessageExtraInfo(LPARAM lParam
)
3061 struct user_thread_info
*thread_info
= get_user_thread_info();
3062 LONG old_value
= thread_info
->GetMessageExtraInfoVal
;
3063 thread_info
->GetMessageExtraInfoVal
= lParam
;
3068 /***********************************************************************
3069 * WaitMessage (USER.112) Suspend thread pending messages
3070 * WaitMessage (USER32.@) Suspend thread pending messages
3072 * WaitMessage() suspends a thread until events appear in the thread's
3075 BOOL WINAPI
WaitMessage(void)
3077 return (MsgWaitForMultipleObjectsEx( 0, NULL
, INFINITE
, QS_ALLINPUT
, 0 ) != WAIT_FAILED
);
3081 /***********************************************************************
3082 * MsgWaitForMultipleObjectsEx (USER32.@)
3084 DWORD WINAPI
MsgWaitForMultipleObjectsEx( DWORD count
, CONST HANDLE
*pHandles
,
3085 DWORD timeout
, DWORD mask
, DWORD flags
)
3087 HANDLE handles
[MAXIMUM_WAIT_OBJECTS
];
3090 if (count
> MAXIMUM_WAIT_OBJECTS
-1)
3092 SetLastError( ERROR_INVALID_PARAMETER
);
3096 /* set the queue mask */
3097 SERVER_START_REQ( set_queue_mask
)
3099 req
->wake_mask
= (flags
& MWMO_INPUTAVAILABLE
) ? mask
: 0;
3100 req
->changed_mask
= mask
;
3102 wine_server_call( req
);
3106 /* Add the thread event to the handle list */
3107 for (i
= 0; i
< count
; i
++) handles
[i
] = pHandles
[i
];
3108 handles
[count
] = get_server_queue_handle();
3110 ReleaseThunkLock( &lock
);
3111 ret
= USER_Driver
->pMsgWaitForMultipleObjectsEx( count
+1, handles
, timeout
, mask
, flags
);
3112 if (ret
== count
+1) ret
= count
; /* pretend the msg queue is ready */
3113 if (lock
) RestoreThunkLock( lock
);
3118 /***********************************************************************
3119 * MsgWaitForMultipleObjects (USER32.@)
3121 DWORD WINAPI
MsgWaitForMultipleObjects( DWORD count
, CONST HANDLE
*handles
,
3122 BOOL wait_all
, DWORD timeout
, DWORD mask
)
3124 return MsgWaitForMultipleObjectsEx( count
, handles
, timeout
, mask
,
3125 wait_all
? MWMO_WAITALL
: 0 );
3129 /***********************************************************************
3130 * WaitForInputIdle (USER32.@)
3132 DWORD WINAPI
WaitForInputIdle( HANDLE hProcess
, DWORD dwTimeOut
)
3134 DWORD start_time
, elapsed
, ret
;
3135 HANDLE idle_event
= (HANDLE
)-1;
3137 SERVER_START_REQ( wait_input_idle
)
3139 req
->handle
= hProcess
;
3140 req
->timeout
= dwTimeOut
;
3141 if (!(ret
= wine_server_call_err( req
))) idle_event
= reply
->event
;
3144 if (ret
) return WAIT_FAILED
; /* error */
3145 if (!idle_event
) return 0; /* no event to wait on */
3147 start_time
= GetTickCount();
3150 TRACE("waiting for %p\n", idle_event
);
3153 ret
= MsgWaitForMultipleObjects ( 1, &idle_event
, FALSE
, dwTimeOut
- elapsed
, QS_SENDMESSAGE
);
3156 case WAIT_OBJECT_0
+1:
3157 process_sent_messages();
3161 TRACE("timeout or error\n");
3164 TRACE("finished\n");
3167 if (dwTimeOut
!= INFINITE
)
3169 elapsed
= GetTickCount() - start_time
;
3170 if (elapsed
> dwTimeOut
)
3176 return WAIT_TIMEOUT
;
3180 /***********************************************************************
3181 * UserYield (USER.332)
3183 void WINAPI
UserYield16(void)
3187 /* Handle sent messages */
3188 process_sent_messages();
3191 ReleaseThunkLock(&count
);
3195 RestoreThunkLock(count
);
3196 /* Handle sent messages again */
3197 process_sent_messages();
3202 /***********************************************************************
3203 * RegisterWindowMessage (USER.118)
3204 * RegisterWindowMessageA (USER32.@)
3206 UINT WINAPI
RegisterWindowMessageA( LPCSTR str
)
3208 UINT ret
= GlobalAddAtomA(str
);
3209 TRACE("%s, ret=%x\n", str
, ret
);
3214 /***********************************************************************
3215 * RegisterWindowMessageW (USER32.@)
3217 UINT WINAPI
RegisterWindowMessageW( LPCWSTR str
)
3219 UINT ret
= GlobalAddAtomW(str
);
3220 TRACE("%s ret=%x\n", debugstr_w(str
), ret
);
3225 /***********************************************************************
3226 * BroadcastSystemMessage (USER32.@)
3227 * BroadcastSystemMessageA (USER32.@)
3229 LONG WINAPI
BroadcastSystemMessageA( DWORD flags
, LPDWORD recipients
, UINT msg
, WPARAM wp
, LPARAM lp
)
3231 if ((*recipients
& BSM_APPLICATIONS
) || (*recipients
== BSM_ALLCOMPONENTS
))
3233 FIXME( "(%08lx,%08lx,%08x,%08x,%08lx): semi-stub!\n", flags
, *recipients
, msg
, wp
, lp
);
3234 PostMessageA( HWND_BROADCAST
, msg
, wp
, lp
);
3239 FIXME( "(%08lx,%08lx,%08x,%08x,%08lx): stub!\n", flags
, *recipients
, msg
, wp
, lp
);
3245 /***********************************************************************
3246 * BroadcastSystemMessageW (USER32.@)
3248 LONG WINAPI
BroadcastSystemMessageW( DWORD flags
, LPDWORD recipients
, UINT msg
, WPARAM wp
, LPARAM lp
)
3250 if ((*recipients
& BSM_APPLICATIONS
) || (*recipients
== BSM_ALLCOMPONENTS
))
3252 FIXME( "(%08lx,%08lx,%08x,%08x,%08lx): semi-stub!\n", flags
, *recipients
, msg
, wp
, lp
);
3253 PostMessageW( HWND_BROADCAST
, msg
, wp
, lp
);
3258 FIXME( "(%08lx,%08lx,%08x,%08x,%08lx): stub!\n", flags
, *recipients
, msg
, wp
, lp
);
3264 /***********************************************************************
3265 * SetMessageQueue (USER32.@)
3267 BOOL WINAPI
SetMessageQueue( INT size
)
3269 /* now obsolete the message queue will be expanded dynamically as necessary */
3274 /***********************************************************************
3275 * MessageBeep (USER32.@)
3277 BOOL WINAPI
MessageBeep( UINT i
)
3280 SystemParametersInfoA( SPI_GETBEEP
, 0, &active
, FALSE
);
3281 if (active
) USER_Driver
->pBeep();
3286 /***********************************************************************
3287 * SetTimer (USER32.@)
3289 UINT_PTR WINAPI
SetTimer( HWND hwnd
, UINT_PTR id
, UINT timeout
, TIMERPROC proc
)
3292 WNDPROC winproc
= 0;
3294 if (proc
) winproc
= WINPROC_AllocProc( (WNDPROC
)proc
, WIN_PROC_32A
);
3296 SERVER_START_REQ( set_win_timer
)
3299 req
->msg
= WM_TIMER
;
3301 req
->rate
= max( timeout
, SYS_TIMER_RATE
);
3302 req
->lparam
= (unsigned int)winproc
;
3303 if (!wine_server_call_err( req
))
3306 if (!ret
) ret
= TRUE
;
3312 TRACE("Added %p %x %p timeout %d\n", hwnd
, id
, winproc
, timeout
);
3317 /***********************************************************************
3318 * SetSystemTimer (USER32.@)
3320 UINT_PTR WINAPI
SetSystemTimer( HWND hwnd
, UINT_PTR id
, UINT timeout
, TIMERPROC proc
)
3323 WNDPROC winproc
= 0;
3325 if (proc
) winproc
= WINPROC_AllocProc( (WNDPROC
)proc
, WIN_PROC_32A
);
3327 SERVER_START_REQ( set_win_timer
)
3330 req
->msg
= WM_SYSTIMER
;
3332 req
->rate
= max( timeout
, SYS_TIMER_RATE
);
3333 req
->lparam
= (unsigned int)winproc
;
3334 if (!wine_server_call_err( req
))
3337 if (!ret
) ret
= TRUE
;
3343 TRACE("Added %p %x %p timeout %d\n", hwnd
, id
, winproc
, timeout
);
3348 /***********************************************************************
3349 * KillTimer (USER32.@)
3351 BOOL WINAPI
KillTimer( HWND hwnd
, UINT_PTR id
)
3355 TRACE("%p %d\n", hwnd
, id
);
3357 SERVER_START_REQ( kill_win_timer
)
3360 req
->msg
= WM_TIMER
;
3362 ret
= !wine_server_call_err( req
);
3369 /***********************************************************************
3370 * KillSystemTimer (USER32.@)
3372 BOOL WINAPI
KillSystemTimer( HWND hwnd
, UINT_PTR id
)
3376 TRACE("%p %d\n", hwnd
, id
);
3378 SERVER_START_REQ( kill_win_timer
)
3381 req
->msg
= WM_SYSTIMER
;
3383 ret
= !wine_server_call_err( req
);
3390 /**********************************************************************
3391 * GetGUIThreadInfo (USER32.@)
3393 BOOL WINAPI
GetGUIThreadInfo( DWORD id
, GUITHREADINFO
*info
)
3397 SERVER_START_REQ( get_thread_input
)
3400 if ((ret
= !wine_server_call_err( req
)))
3403 info
->hwndActive
= reply
->active
;
3404 info
->hwndFocus
= reply
->focus
;
3405 info
->hwndCapture
= reply
->capture
;
3406 info
->hwndMenuOwner
= reply
->menu_owner
;
3407 info
->hwndMoveSize
= reply
->move_size
;
3408 info
->hwndCaret
= reply
->caret
;
3409 info
->rcCaret
.left
= reply
->rect
.left
;
3410 info
->rcCaret
.top
= reply
->rect
.top
;
3411 info
->rcCaret
.right
= reply
->rect
.right
;
3412 info
->rcCaret
.bottom
= reply
->rect
.bottom
;
3413 if (reply
->menu_owner
) info
->flags
|= GUI_INMENUMODE
;
3414 if (reply
->move_size
) info
->flags
|= GUI_INMOVESIZE
;
3415 if (reply
->caret
) info
->flags
|= GUI_CARETBLINKING
;
3423 /******************************************************************
3424 * IsHungAppWindow (USER32.@)
3427 BOOL WINAPI
IsHungAppWindow( HWND hWnd
)
3430 return !SendMessageTimeoutA(hWnd
, WM_NULL
, 0, 0, SMTO_ABORTIFHUNG
, 5000, &dwResult
);